T0038a — Public API: model-aware options
Part of the roadmap. Phase 1 · wave 7 · size M.
- Depends on: T0018, T0019, T0024b, T0025, T0039
- Area:
area:core - Tier hint:
risk:high: new public option types and exports, so the core tier with a second reviewer from the other vendor. - Parallel with: T0038b, T0038c, T0038d
- Parent: T0038, split on 2026-11-12.
Goal
Model-aware evaluation and analysis through the public API: the model, inputType and lenient compile options of the T0038 sketch. evaluate(patient, 'Patient.deceased', { model: r4 }) then navigates with the FHIR model (T0018), and compile('name.given1', { model: r4, inputType: 'Patient' }) reports the unknown element when the expression is compiled (T0024a).
Scope
src/api/public-api.ts:CompileOptionsgains three options, whichanalyze(),compile()andevaluate()all take:model?: ModelProvider: any provider, sor4,r5andr6need no version-specific API.inputType?: string | readonly string[]: the type of the input, or the types it may have, for model-aware analysis and, with one name, for the evaluation of an input that does not name its type (#224); needsmodel.lenient?: LenientOptions, withchoiceSuffix?: boolean(ADR-0012).
- Option validation, each failure
eval/invalid-argument:model: an object with anamespacethat is a non-empty string other thanSystem(#60), a stringversion, and the six methods ofModelProvider.inputType: a string or a non-empty array of strings, and only withmodel.lenient: an object whose only option is a booleanchoiceSuffix. Any other key is rejected, so a future relaxation is never a silent no-op.
src/index.tsexports theLenientOptionstype.- Tests through the public entry point with the real
r4,r5andr6providers: typed navigation of a choice element and of a primitive with extensions, analysis withinputTypeincluding a case where the versions differ,lenient.choiceSuffix, strict mode with a model, and every validation error. Type tests for the new options. - Packed consumers:
scripts/check-public-api.tsandscripts/check-release-packages.tsevaluate withr4,r5andr6in the Node, TypeScript and Vite consumers. The type checks that said public model-aware evaluation did not exist are replaced by ones that it does. - Documentation: a guide section on FHIR models (R4, R5, and R6 as the pinned draft with its known gaps and no conformance number), the core README, and the READMEs of
@callis/fhir-r4,@callis/fhir-r5and@callis/fhir-r6. The guide's TypeScript examples run in CI, so the snippet check accepts imports from the model and unit packages. Aminorchangeset for@callis/core.
Not in scope: the evaluation options hooks, signal, concurrency, now and limits (T0038b), typed output (T0038d) and the functions option (#222).
Design notes
- The facade validates the options and passes them to the internal API (
api/compile.ts), which implements them since T0018 and T0024. The internal API keeps working without the checks; the conformance runner uses it until T0038e. - The model is not wrapped, unlike the unit system:
ModelProvideris synchronous, pure and precomputed by contract, and its methods run on the navigation hot path. The facade checks its shape once per compilation. - An
inputTypearray is copied after it is checked, so analysis reads exactly the names that were checked. A type name that the model does not define is asemantic/unknown-typeerror from the analysis, not an invalid option. inputTypewas first the type of the input for analysis only, as in the internal API, so an input that did not say its type, such as a barePeriodobject, was evaluated as untyped JSON (T0018). By the owner's decision on #224 (2026-11-21), before the option was first published, evaluation uses it too, so the two agree: with one type name, an input that does not name its own type is evaluated as a value of that type, andstart > @2019on{ start: '2020-01-01' }withinputType: 'Period'is true. An input that names its own type keeps it, and several names leave it untyped (spec notes).- An empty
inputTypearray is rejected rather than read as no type, so a later meaning for it stays open.lenientwithoutmodelis accepted and has no effect, so one options object can serve evaluations with and without a model.
Acceptance criteria
From the parent:
- The public
modeloption evaluates withr4,r5andr6in the type tests and in the packed Node and Vite consumers. The guide and READMEs label R6 as the pinned draft, list its known gaps and publish no R6 conformance number. - #60: a model whose namespace is
Systemor empty is rejected witheval/invalid-argument. No future option is accepted as a silent no-op. - The guide examples for the model options are executed in CI.
- publint, attw, the zero-dependency check and the size budget all pass.
And for this child:
- Through the public API,
Observation.value.ofType(Quantity)and a FHIR primitive with an extension evaluate as with the internal API,Observation.triggeredByoninputType: 'Observation'issemantic/unknown-elementunder R4 only, andObservation.valueQuantitycompiles only withlenient: { choiceSuffix: true }.