Skip to content

TS: Add type discriminator support for slicing - #108

Merged
ryukzak merged 7 commits into
mainfrom
resolve-collisions
Mar 18, 2026
Merged

TS: Add type discriminator support for slicing#108
ryukzak merged 7 commits into
mainfrom
resolve-collisions

Conversation

@ryukzak

@ryukzak ryukzak commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator
  • Support type discriminator in slicing — match slices by resourceType field
    • field-builder.ts: compute { resource: { resourceType: "<Type>" } } match pattern from FHIR type discriminator path and element type
    • profile-slices.ts: add typeDiscriminator flag to SliceDef; type-discriminated getters return items via as cast (no stripMatchKeys)
    • profile.ts: skip match-field omission in flat input types and stripMatchKeys import for type discriminator slices
  • Update slices design doc: type discriminator status → Partial

Generated profile before (no type discriminator support — slices silently ignored):

// No PatientEntry/OrganizationEntry getters/setters generated

Generated profile after (ExampleTypedBundle with Bundle.entry sliced by resource type):

export type ExampleTypedBundle_Entry_PatientEntrySliceFlat = BundleEntry;
export type ExampleTypedBundle_Entry_OrganizationEntrySliceFlat = BundleEntry;

export class ExampleTypedBundleProfile {
    setPatientEntry(input?: ... | BundleEntry): this { ... }
    getPatientEntry(mode?: 'flat' | 'raw'): ... | undefined { ... }
    setOrganizationEntry(input?: ... | BundleEntry): this { ... }
    getOrganizationEntry(mode?: 'flat' | 'raw'): ... | undefined { ... }
}

Example & tests

  • Add ExampleTypedBundle StructureDefinition with Patient/Organization entry slices
  • Add profile-typed-bundle.test.ts demo covering create, set/get, validation, fluent chaining
  • Add snapshot test for type-discriminated profile codegen output
  • Deduplicate test StructureDefinitions (point at examples/ instead of test/assets/)
  • Add Patient and Organization to local-package-folder tree shake
  • Add test-local-package-folder-example target to Makefile

@ryukzak
ryukzak force-pushed the resolve-collisions branch from 75be3df to 2f37b58 Compare March 18, 2026 15:56
@ryukzak ryukzak changed the title TypeSchema/TS: Add collision resolution and type discriminator slicing TypeSchema/TS: Add collision resolution, type discriminator slicing, and choice narrowing Mar 18, 2026
ryukzak added 7 commits March 18, 2026 17:01
Compute resourceType-based match for type discriminators so slices
discriminated by resource type (e.g. Bundle.entry by resource) generate
getter/setter methods. Type-discriminated getters return items as-is
(no stripMatchKeys) and input types don't Omit match fields.
… SDs

Point local-package test at examples/local-package-folder/structure-definitions
instead of maintaining a separate copy in test/assets.
Add SD, demo test, and tsconfig for local-package-folder example.
Add test-local-package-folder-example make target with typecheck.
@ryukzak
ryukzak force-pushed the resolve-collisions branch from 2f37b58 to 7c47c68 Compare March 18, 2026 16:02
@ryukzak ryukzak changed the title TypeSchema/TS: Add collision resolution, type discriminator slicing, and choice narrowing TS: Add type discriminator support for slicing Mar 18, 2026
@ryukzak
ryukzak merged commit ef0656f into main Mar 18, 2026
31 checks passed
@ryukzak
ryukzak deleted the resolve-collisions branch March 18, 2026 16:08
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