TypeSchema/TS: introduce SnapshotProfileTypeSchema for the TS writer - #158
Merged
Conversation
ryukzak
force-pushed
the
ts/snapshot-profile-type-schema
branch
from
May 12, 2026 12:27
fc8eb12 to
5f2cd68
Compare
ryukzak
force-pushed
the
ts/snapshot-profile-type-schema
branch
from
May 12, 2026 13:32
5f2cd68 to
b9849aa
Compare
ryukzak
force-pushed
the
ts/snapshot-profile-type-schema
branch
2 times, most recently
from
May 20, 2026 09:12
0bdbbf1 to
5c8b5f9
Compare
…e index Adds a writer-ready profile representation alongside the raw ProfileTypeSchema. Snapshots are flattened (fields merged across the hierarchy, extensions consolidated) and discriminated by `identifier.kind === "profile-snapshot"`. Type additions: - SnapshotProfileIdentifier in the Identifier union. - SnapshotProfileTypeSchema in the TypeSchema union. - Guards: isSnapshotProfileIdentifier, isSnapshotProfileTypeSchema. - Helper: snapshotIdentifier(id) — ProfileIdentifier → SnapshotProfileIdentifier. - Export PrimitiveTypeSchema (was implicitly public via TypeSchema; the resolve overload signature now needs the name directly). Index integration in mkTypeSchemaIndex: - New `snapshotIndex` (parallel to nestedIndex) holds pre-built snapshots. - Snapshots are eagerly built for every well-formed profile during index construction. Profiles whose hierarchy lacks a non-profile ancestor are skipped structurally via tryHierarchy + guard checks, so direct flatProfile callers still see the original exception path. - New `collectSnapshotProfiles()` returns all built snapshots. - `resolve` and `resolveType` route SnapshotProfileIdentifier (kind "profile-snapshot") to the snapshot store. - Both functions are now overloaded — passing a specific identifier variant (Resource, Profile, Snapshot, Binding, ValueSet, Logical, Primitive, ComplexType; plus Nested for resolveType) narrows the return type without a cast. Implementation uses a named callable type (ResolveFn/ResolveTypeFn) to avoid circular type inference through TypeSchemaIndex. - findLastSpecialization uses guard-based filter (skips both profile and profile-snapshot variants) so it composes when called via findLastSpecializationByIdentifier on a snapshot identifier. - entityTree includes the "profile-snapshot" bucket so EntityTree stays exhaustive over Identifier["kind"]. Tree-shake short-circuit: - treeShakeTypeSchema returns snapshots untouched (they're derived data; they never reach tree shaking in practice, but the typed switch needs to acknowledge them).
Pipes snapshots from the index through the writer end-to-end. - writer.generate() now collects via tsIndex.collectSnapshotProfiles(). - generateResourceModule dispatches on isSnapshotProfileTypeSchema; the inline `tsIndex.resolve(...)` call inside the profile branch is gone — the iterated schema is already the snapshot. - generateFhirPackageIndexFile and the per-package filter use isSnapshotProfileTypeSchema. - generateProfileIndexFile signature takes SnapshotProfileTypeSchema[]. - resolveExtensionProfile resolves the snapshot via the overloaded resolve() — no cast — and returns it as `snapshot` on ExtensionProfileInfo (replacing the previous `flatProfile` field). - All profile-generation helpers (factory info, slice defs, extension methods, validation, slice setters/getters) take `snapshot: SnapshotProfileTypeSchema` instead of `flatProfile: ProfileTypeSchema`. - Name helpers (tsProfileModuleName/FileName/ClassName) narrow to SnapshotProfileTypeSchema. tsProfileModuleName switches to findLastSpecializationByIdentifier so it no longer depends on the TypeSchema union. Drive-by: biome --write trimmed a redundant `!!canonicalUrl` (already inside an `&&` chain).
ryukzak
force-pushed
the
ts/snapshot-profile-type-schema
branch
from
May 20, 2026 14:08
5c8b5f9 to
943a04d
Compare
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.
First PR in a sequence that moves profile method derivation from the TS writer into TypeSchema. This one only sets up the seam — no behavior change, output byte-identical.
New type
SnapshotProfileTypeSchemainsrc/typeschema/types.ts— a writer-ready profile shape with flat fields and merged extensions, taggedsnapshotKind: "snapshot". Not part of theTypeSchemaunion (writer-internal value).isSnapshotProfileTypeSchemaguard.New builder
src/typeschema/profile-snapshot.tsexportsmkProfileSnapshot(tsIndex, profile). Today it wrapstsIndex.flatProfile()and tags the result; future PRs move method-derivation logic (factory info, slice defs, validation expressions) here.TS writer migration
writer.ts:generateResourceModulebuilds the snapshot once per profile viamkProfileSnapshotinstead of callingtsIndex.flatProfileinline.flatProfile: ProfileTypeSchemaparameters acrossprofile.ts/profile-slices.ts/profile-extensions.ts/profile-validation.tsbecomesnapshot: SnapshotProfileTypeSchema.ExtensionProfileInfo.flatProfile→.snapshot.tsProfileClassName/tsProfileModuleName/tsProfileModuleFileNamewidened to a structural{ identifier: ProfileIdentifier }so they accept both raw profiles (used ingenerateProfileIndexFile) and snapshots.tsProfileModuleNamenow usesfindLastSpecializationByIdentifierinstead offindLastSpecialization, dropping its dependency on theTypeSchemaunion.Verification
bun run typecheckcleanbunx biome checkclean (only pre-existing warnings)bun test257/257 pass