Skip to content

refactor(web_core): extract shared Zod schema introspection and metadata utilities #2422

Description

@josemontespg

Overview

Several areas within @a2ui/web_core inspect and traverse Zod schemas to classify properties for reactive binding and child lifecycle management:

  1. GenericBinder / scrapeSchemaBehavior (renderers/web_core/src/v0_9/rendering/generic-binder.ts): inspects schemas to build a behavior tree (DYNAMIC, ACTION, STRUCTURAL, CHECKABLE, STATIC).
  2. NodeResolver / extractRefFields (renderers/web_core/src/v0_9/nodes/ref-fields.ts): inspects schemas to classify child component references (single, list, nested).

Currently, both modules independently access private Zod _def internals (typeName, innerType, description, options, shape()) and implement separate unwrapping loops for ZodOptional, ZodNullable, ZodDefault, and ZodEffects.

Goals & Motivation

  • Centralize Zod Introspection: Consolidate schema unwrapping and property reflection into a dedicated utility module (e.g. renderers/web_core/src/v0_9/schema/schema-reflection.ts).
  • Eliminate Raw _def Leaks: Provide clean helper functions (unwrapSchema, getSchemaDescriptions, isZodUnion, isZodObject) so binders and resolvers do not couple to Zod internals.
  • Extend Schema Metadata Stamping: Broaden the a2uiChildRef metadata pattern introduced in PR feat(react): render A2uiSurface through the node layer #2393 (markChildRef / childRefKindOf) to cover Action and Dynamic* schemas (a2uiKind: 'action' | 'dynamic' | 'child-list' | 'component-id'). This completely eliminates fragile string parsing of description pointers (REF:common_types.json#/$defs/...) when inspecting schemas.

Proposed Changes

  1. New Utility Module (schema-reflection.ts):
    • unwrapSchema(schema: z.ZodTypeAny): Recursively unwraps wrappers while aggregating metadata and descriptions.
    • getSchemaKind(schema: z.ZodTypeAny): Resolves stamped A2UI schema kinds.
  2. Refactor Call Sites:
    • Refactor ref-fields.ts to use unwrapSchema.
    • Refactor generic-binder.ts to use unwrapSchema and the shared reflection helpers.
  3. Metadata Enrichment (common-types.ts):
    • Add markSchemaKind to ActionSchema, DynamicValueSchema, DataBindingSchema.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Good request. This is not currently planned, but may become a priority.type: feature/enhancement

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions