TypeSchema: kind-key the TypeSchemaIndex slot - #160
Closed
ryukzak wants to merge 1 commit into
Closed
Conversation
Restructures the index from `Record<url, Record<pkg, TypeSchema>>` to `Record<url, Record<pkg, Partial<Record<kind, TypeSchema>>>>` so multiple schemas can co-exist at the same url+package, discriminated by `identifier.kind`. No current consumer benefits — every slot still holds exactly one entry today — but this removes the URL/package collision that would otherwise block storing additional kind variants alongside their base. - append() now keys the slot by identifier.kind; duplicate check moves to the kind-keyed slot. - resolve() and resolveType() look up by id.kind, with a fallback to whatever's at the slot when the requested kind isn't present. The fallback preserves pre-refactor behavior: some IRs (e.g. CDA) declare dependency identifiers with a different `kind` than the actual stored schema, and the old slot-only lookup tolerated that. - resolveByUrl picks the first entry from the slot (single kind today; caller has no kind to disambiguate).
ryukzak
force-pushed
the
ts/index-kind-keyed
branch
from
May 13, 2026 13:27
78d27ad to
1c3e1ab
Compare
Collaborator
Author
|
Closing — the separate `snapshotIndex` approach (in #158) is the better solution after reflection:
Snapshots will live in their own `snapshotIndex` parallel to `nestedIndex`. #158 already implements this. |
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.
Preparatory refactor for the SnapshotProfileTypeSchema work in #158.
Why
Today the index is
Record<url, Record<pkg, TypeSchema>>— one entry per[url, package]slot. The upcoming SnapshotProfileTypeSchema sharesurl+packagewith the rawProfileTypeSchemait's built from (they differ only byidentifier.kind), so both can't live in the same slot. The current snapshot work (#158) sidesteps this with a parallel `snapshotIndex` — workable but adds bookkeeping.This PR makes the slot kind-keyed so any future schema variant sharing url+package can coexist with its base. No current functional benefit; lands as pure preparation.
What
_schemaIndexshape:Record<url, Record<pkg, Partial<Record<kind, TypeSchema>>>>.append()keys writes byidentifier.kind; duplicate check moves to the kind-keyed slot.resolve(id)andresolveType(id)look up byid.kind, with a fallback to whatever's at the slot when the requested kind isn't present. The fallback preserves pre-refactor behavior — some IRs (CDA, specifically) declare dependency identifiers with a differentkindthan the actual stored schema, and the old slot-only lookup tolerated that.resolveByUrlpicks the first entry from the slot (single kind today; the caller has no kind to disambiguate).Verification
bun run typecheckclean.bunx biome checkclean (only pre-existing warnings).bun test257/257 pass.