T0038 — Complete the phase-1 public API and documentation
Part of the roadmap. Phase 1 · wave 7 · size L.
- Depends on: T0041, T0042, T0025, T0007, T0010, T0011, T0012, T0013, T0014, T0015, T0016, T0017, T0021, T0023, T0024, T0024b (together they cover all of phase 1)
- Area:
area:core,area:docs,area:tooling - Tier hint: likely
risk:high: the final public API and exports, so the core tier with a second reviewer from the other vendor. - Parallel with: –
- Background: ADR-0009, ADR-0012 (option and output defaults)
Goal
Complete the public API as the remaining phase-1 capabilities land, through later 0.x releases. This preserves the full API design deferred from T0025; it is neither a prerequisite for the first 0.1.0 nor a definition of 1.0. Read T0025 for the initial surface and T0037 for release readiness.
Split
The task touches every public entry point, the conformance runner and the user documentation, far beyond a few hundred hand-written lines for one PR. It was split on 2026-11-12 along the groups of options and outputs in the public API sketch, as CONTRIBUTING asks (#116):
- T0038a: the
model,inputTypeandlenientcompile options, with the model validation of #60. - T0038b:
evaluateAsync()and thehooks,signal,concurrency,nowandlimitsevaluation options, includinglimits.maxCollectionSize. - T0038c:
parse(), AST input, the compiledast, theknownVariablescompile option and the compile cache. - T0038d:
output: 'typed', its overloads and the public typed values. - T0038e: the conformance runner's adapter on the public API.
- T0038f: the README quick start, the guide, the API reference decision, the examples and the per-phase support documentation.
Each child adds its own exports, type tests, packed-consumer checks, guide sections and changeset; T0038f completes the documentation as a whole. This file keeps the scope, the design notes and the acceptance criteria they share; each child lists the criteria it delivers. The task is complete, and #116 closes, when all six have merged. The phase-2 tasks that depend on T0038 wait for all six.
The sketch's functions option, a custom function registry, is in no child: it needs a public contract for function definitions. The owner decided on 2026-11-21 (#222) that it stays internal until T0045 designs that contract. Until then the public API rejects it as an unsupported option.
Scope
The narrowed T0011/T0012 deliver only exists/count/where. Full phase-1 completion still requires T0041/T0042; their omitted functions and limits are not silently dropped or pulled into 0.2.
src/api/:- final
parse,analyze,compile,evaluate,evaluateAsyncwith overloads foroutput: 'typed' - option validation
- an LRU compile cache
- complete
plainandtypedoutput adapters
- final
src/index.ts: exports only the public API and public types.- The conformance runner's evaluator adapter switches from the internal API (T0008) to the public API, so the published surface is what gets measured.
- Type tests (
expectTypeOf) for the public API. - Documentation:
- README quick start
docs/guide.md: model-less use, R4, R5 and R6, units, async hooks, errors, output modes- generated API reference (TypeDoc) or a decision not to generate one
spec-notes.mdcompleted, with the conformance report linked
- An
examples/folder that runs in CI. - Extend the existing release documentation and examples for later 0.x releases; reuse the workflow and owner process in RELEASING.md.
- Validate model options, including rejecting an empty or
Systemnamespace (#60). - FHIR versions (roadmap): the public
modeloption takes anyModelProvider, sor4,r5andr6need no version-specific API. Type tests, documentation examples and the packed release consumers (pnpm check:release) cover all three. The public conformance adapter measures the R4 and R5 suites; for R6 the guide and the R6 README describe the engine-tested coverage on the pinned6.0.0-snapshot1draft and its known gaps, without a pass count. - Public
parse, AST inputs and the compiledastproperty require the parser chain-depth fix #107, with bounded-tree regression tests. Until it is resolved, keep these internal and report this completion task blocked; do not delay T0025 for them.
Design notes
Public API sketch
This is the later target surface, not the initial 0.1 contract. Add each option only with its implemented capability and regression/type tests. Preserve T0025 call shapes and existing exported contracts.
import { compile, evaluate, evaluateAsync, parse } from '@callis/core';import { r4 } from '@callis/fhir-r4';import { ucum } from '@callis/ucum';// One-off evaluation; compiled expressions are cached internallyconst given = evaluate(patient, 'Patient.name.given');// Compile once, evaluate many timesconst isHigh = compile("Observation.value.ofType(Quantity) > 5 'mg/dL'", { model: r4, units: ucum });isHigh.evaluate(observation); // unknown[] (plain output)isHigh.evaluate(observation, { output: 'typed' }); // FhirPathValue[]// Hooks that need I/Oconst names = await evaluateAsync(bundle, 'Bundle.entry.resource.subject.resolve().name', {model: r4,hooks: { resolve: (ref) => client.read(ref) },});// AST for toolingconst ast = parse("name.where(use = 'official').given");
function parse(expression: string, options?: ParseOptions): ExpressionNode;function analyze(expression: string | ExpressionNode, options?: CompileOptions): AnalysisResult;function compile(expression: string | ExpressionNode, options?: CompileOptions): CompiledExpression;function evaluate(input: unknown, expression: string | CompiledExpression, options?: CompileOptions & EvaluateOptions): unknown[];function evaluateAsync(input: unknown, expression: string | CompiledExpression, options?: CompileOptions & EvaluateOptions): Promise<unknown[]>;// Overloads return FhirPathValue[] when `output: 'typed'`.interface CompileOptions {model?: ModelProvider;units?: UnitSystem; // default: minimal built-in unit system// functions: not public (custom function registry); see T0045. Rejected with eval/invalid-argument.inputType?: string; // enables model-aware analysis, e.g. 'Patient'knownVariables?: readonly string[]; // names of %variables, for compile-time checking (values come via EvaluateOptions.variables)strict?: boolean; // N1 §11 strict evaluationlenient?: { choiceSuffix?: boolean };}interface EvaluateOptions {variables?: Record<string, unknown>;resource?: unknown; // overrides %resourcerootResource?: unknown; // overrides %rootResourcehooks?: EvaluationHooks;now?: Date | (() => Date);timezoneOffset?: number | 'local'; // minutes, for values without an offset; default 0 (UTC), 'local' = host offsetoutput?: 'plain' | 'typed';decimalOutput?: 'number' | 'string'; // plain output only; default 'number'limits?: EvaluationLimits; // bounded work; see architecture "Security and robustness"signal?: CancellationSignal; // async only; any AbortSignal fits (T0021)concurrency?: number; // async only}interface EvaluationLimits {maxRepeatItems?: number; // items one repeat() call may produce; finite default chosen in T0042maxCollectionSize?: number; // items in any intermediate collection; finite default}interface CompiledExpression {readonly expression: string;readonly ast: ExpressionNode;evaluate(input: unknown, options?: EvaluateOptions): unknown[];evaluateAsync(input: unknown, options?: EvaluateOptions): Promise<unknown[]>;}
Output modes
plain(default):- Boolean, String and Integer become JavaScript primitives.
- Decimal becomes a
number(or a string withdecimalOutput: 'string'). - Date, DateTime and Time become FHIR-formatted strings (no
@). - Quantity becomes
{ value, unit, system?, code? }. - Model nodes become the underlying JSON. An extension-only primitive comes out as its
_nameobject.
typedreturns Callis values (Decimal,DateTimeValue,Quantity,ModelNodewith type information) without loss.
Compile cache: calling evaluate() with a string uses a bounded LRU cache of compiled expressions. The key is the expression plus the identity of its compile options. Its size is configurable, and it can be turned off.
Stability: 0.1.0 does not freeze the API. Until 1.0, any public API may change in a minor version, including breaking changes, and that includes the interfaces other packages implement, such as ModelProvider. Breaking is a last resort: public API is designed with later tasks in mind, and every breaking change states its reason and the alternatives considered under Interface changes in its PR, and is called out in its changeset (API changes). Deciding what is frozen for 1.0 is a separate item in the roadmap backlog.
Acceptance criteria
- Every phase-1 conformance test passes, or is listed with a reason in
spec-notes.md. - publint, attw, the zero-dependency check and the size budget all pass.
- The README and guide examples are executed in CI.
- Public API conformance matches the internal adapter without losing any baseline entries, including model, strict and async coverage.
- Later 0.x package tarballs install and run in fresh Node and Vite projects; publication remains an owner action.
- #60 option validation and #107 parser-depth prerequisites are covered. No future option is accepted as a silent no-op.
- 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. - Support, limitations and per-phase conformance documentation describe this release; 1.0 scope and criteria remain open.