feat(swift): add Basic Catalog component schemas and registry - #2377
feat(swift): add Basic Catalog component schemas and registry#2377pinieb wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces validation checks, nested property resolution, typed property accessors, and a pre-configured BasicCatalog containing standard components and functions. Feedback on these changes suggests optimizing performance by converting computed properties (allFunctions and allComponents) to static let constants, coercing .standard properties to .dynamicValue early in resolveProperty when a binding is detected, and removing a redundant object resolution block in SurfaceViewModel.swift.
a1570f3 to
5aea4db
Compare
|
/gemini review - This has been rebased several times, and I think some of your initial comments were on changes in earlier branches. Could you please do a complete review again? |
There was a problem hiding this comment.
Code Review
This pull request introduces the BasicCatalog module, which provides pre-configured catalog instances, 18 standard component API definitions, and basic client-side functions across supported A2UI specification versions. The feedback suggests optimizing allComponents in BasicCatalogComponents by changing it from a computed property to a static let constant to avoid unnecessary allocations.
3f7c35c to
4891f9b
Compare
4891f9b to
0f53b44
Compare
0f53b44 to
b4c423c
Compare
b4c423c to
ea86585
Compare
…eb/a2ui into pr/swift-basic-catalog-core
| /// By conforming ``Catalog`` to `CatalogProtocol`, framework APIs like `MessageProcessor` and `SurfaceViewModel` | ||
| /// can accept `[any CatalogProtocol]` and erase them to ``AnyCatalog`` without requiring generic type parameters | ||
| /// or forcing callers into complex type-erasure acrobatics. | ||
| public protocol CatalogProtocol: Sendable { |
There was a problem hiding this comment.
@jacobsimionato Just wanted to call your attention to this one, since part of #2401 was ditching the CatalogAPI vs Implementation split. This isn't in there to split the Catalog across module boundaries anymore, but instead to support a slightly nicer API surface for clients.
Since MessageProcessor ends up erasing the Catalog types anyways, having this protocol lets clients hand in a heterogenous array of Catalog instances without first having to manually do the type erasure.
In multi-framework scenarios, it takes the call site from MessageProcessor(catalogs: [MyUIKitCatalog.impl.eraseToAnyCatalog(), FancySwiftUICatalog.impl.eraseToAnyCatalog(), SuperPizzazzCustomUIFramework.impl.eraseToAnyCatalog()]) to MessageProcessor(catalogs: [MyUIKitCatalog.impl, FancySwiftUICatalog.impl, SuperPizzazzCustomUIFramework.impl])
There was a problem hiding this comment.
No worries! This solution sounds great to me - the majority of the code still follows the share structure, and this makes it ergonomic with Swift's type system.
jacobsimionato
left a comment
There was a problem hiding this comment.
Thanks for iterating!!
| var functions: [String: any FunctionImplementation] { get } | ||
|
|
||
| /// Converts this catalog to a schema-only representation. | ||
| func eraseToAnyCatalog() -> AnyCatalog |
There was a problem hiding this comment.
I'm not a swift readability expert, but would toAnyCatalog() be a little neater?
| public var api: ComponentAPI { | ||
| ComponentAPI(name: name, schema: schema) | ||
| /// The framework-agnostic API definition (``AnyComponentAPI``). | ||
| public var api: AnyComponentAPI { |
There was a problem hiding this comment.
I think we can remove this now, right? Because the object itself conforms to ComponentApi. You could return self here, but better to just have the callers use self directly I imagine!
Summary
Adds the standard Basic Catalog component schemas and registry to the Swift Core SDK, defining all 18 standard A2UI components and 14 built-in client functions across supported specification versions (v0.9, and v0.9.1).
Key changes
Component schemas (
BasicCatalogComponents.swift):Row,Column,List,Card,Tabs,Modal,DividerText,Image,Icon,Video,AudioPlayerButton,TextField,CheckBox,ChoicePicker,Slider,DateTimeInputBasicCatalogComponents.allComponentsto expose the full list ofComponentAPIdefinitions.Function registry (
BasicFunctions.swift):BasicFunctions.allFunctionsaggregating all 14 standard client-side functions:and,email,formatCurrency,formatDate,formatNumber,formatString,length,not,numeric,openUrl,or,pluralize,regex, andrequired.Catalog factory and constants (
BasicCatalog.swift):themeSchemafor Basic Catalog surfaces.createCataloghelper and preconfigured instances (v09Catalog,v091Catalog,allCatalogs).Verification
Ran the Swift test suite: