Repository navigation
refactor(web_core_v1_0): read component structure from catalog metadata - #11
Closed
louis-bompart wants to merge 2 commits into
Closed
louis-bompart wants to merge 2 commits into
louis-bompart wants to merge 2 commits into
Conversation
Core used to ask the catalog's schema adapter about a component's schema
wherever it needed an answer: child references on every resolve,
property behavior in each binder, declared keys in each payload check,
and the reference map. The adapter had to be present at runtime, and its
answers depended on the schema library's private representation.
`Catalog.getComponentMetadata(name)` now answers those questions from
plain data. A component that ships complete `schemaMetadata` (behavior
and the new `propertyKeys`) is used as is. Otherwise the catalog asks its
adapter's new `describeComponent` once and keeps the result, with the
fields the component does carry taking precedence. The resolver, the
binder, the payload validator, the Lit controller and `componentRefMap`
read that metadata. A catalog whose components carry complete metadata
renders without a schema adapter.
`describeComponent` replaces the adapter's per-call reflection:
`extractRefFields`, `getSchemaBehavior`, `buildComponentRefMap`,
`analyzeChildRefSchema`, the `isChild*` checks and the unused
`extractRefDefName`. Core's `scrapeSchemaBehavior` and
`buildComponentRefMap` exports go with them.
The Zod adapter's `describeZodComponent` reads child references the way
both of its former readings did: the resolver's, by marker and `REF:`
pointer, and the integrity checks', which also accepts a bare definition
name such as `describe('ChildComponentId')`. Where both read a property,
the resolver's kind wins. Before, a property named only by definition was
checked as a child reference but never resolved as one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generator now emits `propertyKeys`, the properties each generated Zod object declares, so every basic catalog component carries complete `schemaMetadata` and the catalog never asks its schema adapter to describe one. A test checks that each component's metadata is complete, and that its child references and property keys match what the Zod adapter derives from the component's schema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Core used to ask the catalog's schema adapter about a component's schema wherever it needed an answer:
The adapter had to be there at runtime, and each answer came from the schema library's internals (
_def.typeNamefor Zod 3).Now the catalog holds that information as plain data:
Catalog.getComponentMetadata(name)returns a component'sCompleteComponentSchemaMetadata: child references, behavior, and the newpropertyKeys.schemaMetadataon the component is used as is.describeComponentonce and keeps the result. Fields the component does carry take precedence.NodeResolver,GenericBinder,PayloadValidator,A2uiControllerandcomponentRefMapnever ask the adapter for structure.Validation is unchanged: core still calls
schema['~standard'].validatedirectly, so error messages come from the schema library.Adapter contract
describeComponentreplaces the per-call reflection members:extractRefFields,getSchemaBehavior,buildComponentRefMap,analyzeChildRefSchema,isChildSchema,isChildListSchemaandisChildOrChildListSchema. It also dropsextractRefDefName, which core never called. Core'sscrapeSchemaBehaviorandbuildComponentRefMapexports go too.What remains is tooling (
parseCatalog,serializeCatalog,generateValidationSchema,linkEntry,retainedDefs,hasCrossDocumentRefs,schemaToJson,cleanSchemaNode), the protocol schema, envelope validation, andgetKnownSchemaKeysfor function arguments.A behavior change to review
The Zod adapter used to read child references two ways:
extractRefFields) recognized Zod markers andREF:pointers.buildComponentRefMap) also recognized bare definition names, such asz.string().describe('ChildComponentId').So a property named only that way was checked for cycles and dangling references, but never resolved as a child.
With a single metadata source,
describeZodComponentcombines both readings, and the resolver's kind wins where both read a property. Such properties now resolve as children. Generated catalogs, including the basic catalog, use markers, so they are unaffected; the parity test below checks that for the basic catalog.Commits
refactor(web_core_v1_0): read component structure from catalog metadata: the core change,describeZodComponent, and removal of the now-unused Zod reflection helpers. The basic catalog still works at this commit: its metadata lackspropertyKeys, so it falls back todescribeComponent.feat(catalog-basic): ship complete component metadata: the generator emitspropertyKeys, and the regenerated file differs only by those arrays. A test checks that every component's metadata is complete and matches what the Zod adapter derives from its schema.Validation
Each commit was built from clean, then linted, format-checked and tested on its own. Lint has no errors, and the warning counts went down slightly.
@a2ui/web_core_v1_0@a2ui/schema-zod@a2ui/catalog-basicNot in this PR
getKnownSchemaKeysunless the function declaresargumentKeys.getProtocolSchema.🤖 Generated with Claude Code