Skip to content

Schema Introspection api - #148

Merged
Ryang-21 merged 2 commits into
masterfrom
schema-introspection-api
Jul 7, 2026
Merged

Schema Introspection api#148
Ryang-21 merged 2 commits into
masterfrom
schema-introspection-api

Conversation

@Ryang-21

@Ryang-21 Ryang-21 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Export a typed introspection surface so external walkers don't depend on unchecked casts

The stellar-sdk JSON walker (SEP-0051 toJson/fromJson) currently
re-declares js-xdr's internal shapes as local interfaces and casts into them —
unverified by the compiler, so an internal rename would fail at runtime, not
compile time. This makes the walker surface real, versioned API.

  • One *Schema interface per parameterized kind (StructSchema,
    UnionSchema, ArraySchema, FixedArraySchema, OptionSchema,
    LazySchema, OpaqueSchema, VarOpaqueSchema, StringSchema; kind: 'enum' added to EnumSchema), each extending XdrType<T> with kind
    narrowed to its literal. Factories return these types, so Color.entries
    and Tagged.cases typecheck with no casts. The exposure mirrors constructor
    inputs, so it adds essentially no new representation commitment.
  • AnySchema — a closed union of all built-in schema shapes. Walkers cast
    once at the entry; switch (schema.kind) then genuinely narrows each branch
    (and gives exhaustiveness checking — the compiler catches a missing kind).
    Custom BaseType subclasses are documented as outside the closed union.
  • opaque/varOpaque/string lengths made readonly public (walkers need
    them; previously private).
  • The test suite includes a miniature schema-driven walker as a compile-time
    proof that the external walker can be written against public API alone.

…azy, opaque, option, string, struct, union, and var-opaque implementations
Copilot AI review requested due to automatic review settings July 7, 2026 15:17
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a typed schema-introspection API so external schema walkers (e.g., SEP-0051 JSON to/from) can rely on compiler-checked schema shapes instead of unchecked casts into js-xdr internals.

Changes:

  • Adds *Schema introspection interfaces for compound schema kinds and updates factories to return those interfaces.
  • Exports a closed AnySchema union intended for switch (schema.kind)-based walkers, plus exports of the new schema types from src/index.ts.
  • Makes opaque/varOpaque/string length fields publicly readable and adds a new test demonstrating walker-style consumption.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/unit/introspection.test.ts Adds a schema-driven “walker” test exercising the new introspection surface.
src/types/array.ts Returns ArraySchema and exports the public array introspection interface.
src/types/enum.ts Adds kind: 'enum' to EnumSchema for narrowing.
src/types/fixed-array.ts Returns FixedArraySchema and exports fixed-array introspection interface.
src/types/lazy.ts Returns LazySchema and exports lazy-schema introspection interface.
src/types/opaque.ts Makes length publicly readable and returns OpaqueSchema.
src/types/option.ts Returns OptionSchema and exports option introspection interface.
src/types/string.ts Makes maxLength publicly readable and returns StringSchema.
src/types/struct.ts Returns StructSchema and exports struct introspection interface.
src/types/union.ts Returns UnionSchema and exports union introspection interface.
src/types/var-opaque.ts Makes maxLength publicly readable and returns VarOpaqueSchema.
src/index.ts Re-exports schema interfaces and defines PrimitiveSchema/AnySchema unions for external walkers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ts
@Ryang-21
Ryang-21 merged commit d4a5ada into master Jul 7, 2026
7 checks passed
@Ryang-21
Ryang-21 deleted the schema-introspection-api branch July 7, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants