Skip to content

TypeSchema: store slicing separately from fields#203

Merged
ryukzak merged 2 commits into
mainfrom
typeschema-slicing-refactor
Jul 24, 2026
Merged

TypeSchema: store slicing separately from fields#203
ryukzak merged 2 commits into
mainfrom
typeschema-slicing-refactor

Conversation

@ryukzak

@ryukzak ryukzak commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

First of a two-PR sequence restructuring how TypeSchema stores and processes slice information.

  • Store slicing separately from fields: slicing: Record<fieldName, FieldSlicing> at schema level (specializations, profiles, snapshots, nested types); fields describe the data shape, slicing is an independent constraint layer. Keyed by element name, so choice declarations/instances and regular fields are covered uniformly.
  • flatProfile merges slicing maps leaf-wins per field (mirroring the field merge); tree shaking prunes slicing entries for removed fields.
  • Own slicing vocabulary: SliceDiscriminator + inline rules union replace FS.FHIRSchemaDiscriminator/FS.SlicingRules; the repeated type-discriminator checks collapse into the isTypeDiscriminated predicate.

Generated TS/Python output is byte-identical; only the serialized TypeSchema shape changes:

// before
"fields": {
  "category": { "type": ..., "array": true, "slicing": { "discriminator": [...], "slices": {...} } }
}

// after
"fields":  { "category": { "type": ..., "array": true } },
"slicing": { "category": { "discriminator": [...], "slices": {...} } }

Follow-up PR (branch typeschema-slice-derived-facts, stacked on this one): precomputed derived slice facts on FieldSlice (effectiveRequired, constrainedChoice, autoStub, resourceType), deduplicating the TS/Python writer collectors and fixing the divergences that duplication produced.

@ryukzak
ryukzak force-pushed the typeschema-slicing-refactor branch from be5f1be to 095dde1 Compare July 24, 2026 13:27
@ryukzak ryukzak changed the title TypeSchema: restructure slice representation TypeSchema: store slicing separately from fields Jul 24, 2026
@ryukzak
ryukzak marked this pull request as ready for review July 24, 2026 13:33
ryukzak added 2 commits July 24, 2026 17:52
Slicing moves from RegularField/ChoiceFieldInstance into a schema-level
'slicing: Record<fieldName, FieldSlicing>' on specializations, profiles,
snapshots and nested types. Fields describe the data shape; slicing is an
independent constraint layer keyed by element name, so choice declarations,
choice instances and regular fields are covered uniformly. flatProfile merges
slicing maps leaf-wins per field (mirroring the field merge) and tree shaking
prunes slicing entries for removed fields.

Also redefine the slicing vocabulary locally instead of borrowing fhirschema
types: SliceDiscriminator and inline rules union replace FS.FHIRSchemaDiscriminator
and FS.SlicingRules, and the repeated 'discriminator.some(type === "type")'
checks collapse into the isTypeDiscriminated predicate.

Generated TS/Python output is byte-identical.
@ryukzak
ryukzak force-pushed the typeschema-slicing-refactor branch from 095dde1 to 8940186 Compare July 24, 2026 13:56
@ryukzak
ryukzak merged commit 4aac75a into main Jul 24, 2026
35 checks passed
@ryukzak
ryukzak deleted the typeschema-slicing-refactor branch July 24, 2026 13:59
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