Schema Introspection api - #148
Merged
Merged
Conversation
…azy, opaque, option, string, struct, union, and var-opaque implementations
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
There was a problem hiding this comment.
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
*Schemaintrospection interfaces for compound schema kinds and updates factories to return those interfaces. - Exports a closed
AnySchemaunion intended forswitch (schema.kind)-based walkers, plus exports of the new schema types fromsrc/index.ts. - Makes
opaque/varOpaque/stringlength 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.
quietbits
approved these changes
Jul 7, 2026
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.
Export a typed introspection surface so external walkers don't depend on unchecked casts
The stellar-sdk JSON walker (SEP-0051
toJson/fromJson) currentlyre-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.
*Schemainterface per parameterized kind (StructSchema,UnionSchema,ArraySchema,FixedArraySchema,OptionSchema,LazySchema,OpaqueSchema,VarOpaqueSchema,StringSchema;kind: 'enum'added toEnumSchema), each extendingXdrType<T>withkindnarrowed to its literal. Factories return these types, so
Color.entriesand
Tagged.casestypecheck with no casts. The exposure mirrors constructorinputs, so it adds essentially no new representation commitment.
AnySchema— a closed union of all built-in schema shapes. Walkers castonce at the entry;
switch (schema.kind)then genuinely narrows each branch(and gives exhaustiveness checking — the compiler catches a missing kind).
Custom
BaseTypesubclasses are documented as outside the closed union.opaque/varOpaque/stringlengths madereadonlypublic (walkers needthem; previously
private).proof that the external walker can be written against public API alone.