Skip to content

Flatten single-variant choice types and optional slice auto-fields - #95

Merged
ryukzak merged 4 commits into
mainfrom
feat/flatten-choice-types
Mar 4, 2026
Merged

Flatten single-variant choice types and optional slice auto-fields#95
ryukzak merged 4 commits into
mainfrom
feat/flatten-choice-types

Conversation

@ryukzak

@ryukzak ryukzak commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • When a slice constrains a polymorphic field (e.g., value[x]) to exactly one variant (e.g., valueQuantity), flatten the API so users write { value: 120, unit: "mmHg" } instead of { valueQuantity: { value: 120, unit: "mmHg" } }
  • Make array fields with required slices (like category, component) into optional create() params — required slice stubs are auto-merged when missing
  • Add wrapSliceChoice and flattenSliceChoice runtime helpers
  • Propagate slice elements through TypeSchema for constrained choice detection

Test plan

  • bun run typecheck && bun run lint && bun test passes
  • Review BP profile API: setSystolicBP({ value: 120, unit: "mmHg" }) works
  • Review create() with empty/partial/full category arrays

🤖 Generated with Claude Code

@ryukzak
ryukzak force-pushed the feat/flatten-choice-types branch from 324a872 to abf69a5 Compare March 4, 2026 16:25
Base automatically changed from feat/preserve-slice-casing to main March 4, 2026 16:28
ryukzak added 4 commits March 4, 2026 17:29
When a slice constrains a polymorphic field (e.g. value[x]) to exactly
one variant (e.g. valueQuantity), the slice API now promotes that
variant's fields directly. Users write `{ value: 120, unit: "mmHg" }`
instead of `{ valueQuantity: { value: 120, unit: "mmHg" } }`.

- Add `elements` to FieldSlice type and propagate from field-builder
- Detect constrained choices by resolving base type's ChoiceFieldDeclaration
- Generate flattened input types (Omit all choice variants & intersect)
- Add wrapSliceChoice/flattenSliceChoice runtime helpers
Fields like category and component that have required slices were
previously hardcoded auto-fields. Now they're optional params in
create() — if the user provides their own values, required slice
stubs are auto-merged when missing instead of being overwritten.
@ryukzak
ryukzak force-pushed the feat/flatten-choice-types branch from abf69a5 to ef6ed7a Compare March 4, 2026 16:29
@ryukzak
ryukzak merged commit 8723239 into main Mar 4, 2026
29 checks passed
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