Skip to content

TypeSchema: collect referenced nested types into SnapshotProfileTypeSchema - #162

Closed
ryukzak wants to merge 1 commit into
ts/snapshot-profile-type-schemafrom
ts/snapshot-collect-nested
Closed

TypeSchema: collect referenced nested types into SnapshotProfileTypeSchema#162
ryukzak wants to merge 1 commit into
ts/snapshot-profile-type-schemafrom
ts/snapshot-collect-nested

Conversation

@ryukzak

@ryukzak ryukzak commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Stacks on #158.

Makes snapshot.nested a closure of every nested type a consumer might reach when reading the snapshot, rather than just the profile's own nested array.

What the walk includes

  • Profile-local nested types — seeded first so they take precedence by URL over inherited copies when constraints exist.
  • Each nested type's fields — transitive nested-in-nested closure (e.g. Patient#contact → `Patient#contact.communication` if referenced).
  • Profile's own constrained fields — anything the profile constrains directly.
  • Base resource's fields — inherited types referenced by base fields matter to consumers that read inherited slots, since `flatProfile` only merges constraint-level fields.

Identities are preserved — same URLs, nested schemas shared by reference, not re-rooted to the profile.

Why now, what it unlocks

No immediate behavior change in the writer — the TS writer still imports nested types via `tsIndex.resolveType` and `tsModulePath`. But future code that reads methods/types from the snapshot directly (the larger plan) no longer needs to round-trip through the index for nested lookups. Snapshots become self-contained.

Tests

Two new tests in `test/unit/typeschema/utils.test.ts`:

  • inherits nested types referenced by inherited fields from the base — verifies the base-resource walk picks up nested types the profile itself never references.
  • prefers profile-local nested over inherited when URLs match — verifies precedence when a profile redefines a nested type with constraints.

Verification

  • `bun run typecheck` clean
  • `bunx biome check` clean (only pre-existing warnings)
  • `bun test` 259/259 (was 257; +2 new)
  • R4 + US Core examples regenerate byte-identical (writer doesn't yet consume `snapshot.nested` directly)

…chema

Builds snapshot.nested by closure rather than just the profile's own
nested array. Walks:

- Profile-local nested types (seeded first — they take precedence by URL
  over inherited copies when constraints exist).
- Each nested type's fields (transitive nested-in-nested closure).
- The profile's own constrained fields.
- The base resource's fields — inherited types referenced by base fields
  matter to consumers that read inherited slots, and flatProfile only
  carries profile-level constraints.

Identities are preserved (same URLs); nested schemas are shared by
reference, not re-rooted to the profile.

Currently sets up data with no immediate consumer — the TS writer still
imports nested types via tsIndex.resolveType — but future code reading
methods/types from the snapshot directly no longer needs to round-trip
through the index for nested lookups.
@ryukzak

ryukzak commented May 20, 2026

Copy link
Copy Markdown
Collaborator Author

Closing — not required. The nested-collection groundwork wasn't unlocking anything concrete yet; we'll revisit if and when consumers actually need self-contained snapshots.

@ryukzak ryukzak closed this May 20, 2026
@ryukzak
ryukzak deleted the ts/snapshot-collect-nested branch May 20, 2026 13:18
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.

1 participant