@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +714 -2
- package/dist/cache/index.d.ts +191 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +361 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/canonical/jcs.d.ts +78 -0
- package/dist/canonical/jcs.d.ts.map +1 -0
- package/dist/canonical/jcs.js +500 -0
- package/dist/canonical/jcs.js.map +1 -0
- package/dist/canonical/restricted-json.d.ts +7 -0
- package/dist/canonical/restricted-json.d.ts.map +1 -0
- package/dist/canonical/restricted-json.js +318 -0
- package/dist/canonical/restricted-json.js.map +1 -0
- package/dist/canonical/restricted-value.d.ts +59 -0
- package/dist/canonical/restricted-value.d.ts.map +1 -0
- package/dist/canonical/restricted-value.js +156 -0
- package/dist/canonical/restricted-value.js.map +1 -0
- package/dist/canonical/restricted.d.ts +85 -0
- package/dist/canonical/restricted.d.ts.map +1 -0
- package/dist/canonical/restricted.js +163 -0
- package/dist/canonical/restricted.js.map +1 -0
- package/dist/canonical/signature.d.ts +38 -0
- package/dist/canonical/signature.d.ts.map +1 -0
- package/dist/canonical/signature.js +47 -0
- package/dist/canonical/signature.js.map +1 -0
- package/dist/eval/access/delivery.d.ts +63 -0
- package/dist/eval/access/delivery.d.ts.map +1 -0
- package/dist/eval/access/delivery.js +98 -0
- package/dist/eval/access/delivery.js.map +1 -0
- package/dist/eval/access/overlay.d.ts +72 -0
- package/dist/eval/access/overlay.d.ts.map +1 -0
- package/dist/eval/access/overlay.js +402 -0
- package/dist/eval/access/overlay.js.map +1 -0
- package/dist/eval/access/projection.d.ts +159 -0
- package/dist/eval/access/projection.d.ts.map +1 -0
- package/dist/eval/access/projection.js +211 -0
- package/dist/eval/access/projection.js.map +1 -0
- package/dist/eval/access/window.d.ts +128 -0
- package/dist/eval/access/window.d.ts.map +1 -0
- package/dist/eval/access/window.js +254 -0
- package/dist/eval/access/window.js.map +1 -0
- package/dist/eval/access/write.d.ts +113 -0
- package/dist/eval/access/write.d.ts.map +1 -0
- package/dist/eval/access/write.js +119 -0
- package/dist/eval/access/write.js.map +1 -0
- package/dist/eval/addressing.d.ts +131 -0
- package/dist/eval/addressing.d.ts.map +1 -0
- package/dist/eval/addressing.js +270 -0
- package/dist/eval/addressing.js.map +1 -0
- package/dist/eval/budget.d.ts +143 -0
- package/dist/eval/budget.d.ts.map +1 -0
- package/dist/eval/budget.js +387 -0
- package/dist/eval/budget.js.map +1 -0
- package/dist/eval/computed.d.ts +46 -0
- package/dist/eval/computed.d.ts.map +1 -0
- package/dist/eval/computed.js +89 -0
- package/dist/eval/computed.js.map +1 -0
- package/dist/eval/denials.d.ts +64 -0
- package/dist/eval/denials.d.ts.map +1 -0
- package/dist/eval/denials.js +87 -0
- package/dist/eval/denials.js.map +1 -0
- package/dist/eval/engine/cancellation.d.ts +12 -0
- package/dist/eval/engine/cancellation.d.ts.map +1 -0
- package/dist/eval/engine/cancellation.js +56 -0
- package/dist/eval/engine/cancellation.js.map +1 -0
- package/dist/eval/engine/delta.d.ts +104 -0
- package/dist/eval/engine/delta.d.ts.map +1 -0
- package/dist/eval/engine/delta.js +466 -0
- package/dist/eval/engine/delta.js.map +1 -0
- package/dist/eval/engine/deps.d.ts +136 -0
- package/dist/eval/engine/deps.d.ts.map +1 -0
- package/dist/eval/engine/deps.js +345 -0
- package/dist/eval/engine/deps.js.map +1 -0
- package/dist/eval/engine/identity.d.ts +128 -0
- package/dist/eval/engine/identity.d.ts.map +1 -0
- package/dist/eval/engine/identity.js +398 -0
- package/dist/eval/engine/identity.js.map +1 -0
- package/dist/eval/engine/index.d.ts +200 -0
- package/dist/eval/engine/index.d.ts.map +1 -0
- package/dist/eval/engine/index.js +1242 -0
- package/dist/eval/engine/index.js.map +1 -0
- package/dist/eval/engine/measurement.d.ts +23 -0
- package/dist/eval/engine/measurement.d.ts.map +1 -0
- package/dist/eval/engine/measurement.js +42 -0
- package/dist/eval/engine/measurement.js.map +1 -0
- package/dist/eval/engine/naive.d.ts +19 -0
- package/dist/eval/engine/naive.d.ts.map +1 -0
- package/dist/eval/engine/naive.js +59 -0
- package/dist/eval/engine/naive.js.map +1 -0
- package/dist/eval/engine/ops.d.ts +214 -0
- package/dist/eval/engine/ops.d.ts.map +1 -0
- package/dist/eval/engine/ops.js +1422 -0
- package/dist/eval/engine/ops.js.map +1 -0
- package/dist/eval/engine/patches.d.ts +40 -0
- package/dist/eval/engine/patches.d.ts.map +1 -0
- package/dist/eval/engine/patches.js +125 -0
- package/dist/eval/engine/patches.js.map +1 -0
- package/dist/eval/engine/ports.d.ts +71 -0
- package/dist/eval/engine/ports.d.ts.map +1 -0
- package/dist/eval/engine/ports.js +2 -0
- package/dist/eval/engine/ports.js.map +1 -0
- package/dist/eval/engine/session.d.ts +116 -0
- package/dist/eval/engine/session.d.ts.map +1 -0
- package/dist/eval/engine/session.js +653 -0
- package/dist/eval/engine/session.js.map +1 -0
- package/dist/eval/engine/snapshot.d.ts +97 -0
- package/dist/eval/engine/snapshot.d.ts.map +1 -0
- package/dist/eval/engine/snapshot.js +221 -0
- package/dist/eval/engine/snapshot.js.map +1 -0
- package/dist/eval/engine/subscriptions.d.ts +47 -0
- package/dist/eval/engine/subscriptions.d.ts.map +1 -0
- package/dist/eval/engine/subscriptions.js +103 -0
- package/dist/eval/engine/subscriptions.js.map +1 -0
- package/dist/eval/engine/trace.d.ts +77 -0
- package/dist/eval/engine/trace.d.ts.map +1 -0
- package/dist/eval/engine/trace.js +140 -0
- package/dist/eval/engine/trace.js.map +1 -0
- package/dist/eval/error-diagnostic.d.ts +26 -0
- package/dist/eval/error-diagnostic.d.ts.map +1 -0
- package/dist/eval/error-diagnostic.js +63 -0
- package/dist/eval/error-diagnostic.js.map +1 -0
- package/dist/eval/evaluate-expr.d.ts +44 -0
- package/dist/eval/evaluate-expr.d.ts.map +1 -0
- package/dist/eval/evaluate-expr.js +149 -0
- package/dist/eval/evaluate-expr.js.map +1 -0
- package/dist/eval/evaluate.d.ts +282 -0
- package/dist/eval/evaluate.d.ts.map +1 -0
- package/dist/eval/evaluate.js +391 -0
- package/dist/eval/evaluate.js.map +1 -0
- package/dist/eval/evolution/relocate.d.ts +72 -0
- package/dist/eval/evolution/relocate.d.ts.map +1 -0
- package/dist/eval/evolution/relocate.js +427 -0
- package/dist/eval/evolution/relocate.js.map +1 -0
- package/dist/eval/evolution/select.d.ts +11 -0
- package/dist/eval/evolution/select.d.ts.map +1 -0
- package/dist/eval/evolution/select.js +53 -0
- package/dist/eval/evolution/select.js.map +1 -0
- package/dist/eval/evolution/upcast.d.ts +13 -0
- package/dist/eval/evolution/upcast.d.ts.map +1 -0
- package/dist/eval/evolution/upcast.js +88 -0
- package/dist/eval/evolution/upcast.js.map +1 -0
- package/dist/eval/expr/aggregates.d.ts +75 -0
- package/dist/eval/expr/aggregates.d.ts.map +1 -0
- package/dist/eval/expr/aggregates.js +991 -0
- package/dist/eval/expr/aggregates.js.map +1 -0
- package/dist/eval/expr/arithmetic.d.ts +26 -0
- package/dist/eval/expr/arithmetic.d.ts.map +1 -0
- package/dist/eval/expr/arithmetic.js +387 -0
- package/dist/eval/expr/arithmetic.js.map +1 -0
- package/dist/eval/expr/between.d.ts +17 -0
- package/dist/eval/expr/between.d.ts.map +1 -0
- package/dist/eval/expr/between.js +46 -0
- package/dist/eval/expr/between.js.map +1 -0
- package/dist/eval/expr/binder.d.ts +96 -0
- package/dist/eval/expr/binder.d.ts.map +1 -0
- package/dist/eval/expr/binder.js +253 -0
- package/dist/eval/expr/binder.js.map +1 -0
- package/dist/eval/expr/call-dispatch.d.ts +28 -0
- package/dist/eval/expr/call-dispatch.d.ts.map +1 -0
- package/dist/eval/expr/call-dispatch.js +114 -0
- package/dist/eval/expr/call-dispatch.js.map +1 -0
- package/dist/eval/expr/collections.d.ts +20 -0
- package/dist/eval/expr/collections.d.ts.map +1 -0
- package/dist/eval/expr/collections.js +66 -0
- package/dist/eval/expr/collections.js.map +1 -0
- package/dist/eval/expr/compare.d.ts +36 -0
- package/dist/eval/expr/compare.d.ts.map +1 -0
- package/dist/eval/expr/compare.js +115 -0
- package/dist/eval/expr/compare.js.map +1 -0
- package/dist/eval/expr/datasets.d.ts +28 -0
- package/dist/eval/expr/datasets.d.ts.map +1 -0
- package/dist/eval/expr/datasets.js +304 -0
- package/dist/eval/expr/datasets.js.map +1 -0
- package/dist/eval/expr/digest.d.ts +23 -0
- package/dist/eval/expr/digest.d.ts.map +1 -0
- package/dist/eval/expr/digest.js +89 -0
- package/dist/eval/expr/digest.js.map +1 -0
- package/dist/eval/expr/domains.d.ts +19 -0
- package/dist/eval/expr/domains.d.ts.map +1 -0
- package/dist/eval/expr/domains.js +18 -0
- package/dist/eval/expr/domains.js.map +1 -0
- package/dist/eval/expr/host.d.ts +152 -0
- package/dist/eval/expr/host.d.ts.map +1 -0
- package/dist/eval/expr/host.js +36 -0
- package/dist/eval/expr/host.js.map +1 -0
- package/dist/eval/expr/lists.d.ts +24 -0
- package/dist/eval/expr/lists.d.ts.map +1 -0
- package/dist/eval/expr/lists.js +155 -0
- package/dist/eval/expr/lists.js.map +1 -0
- package/dist/eval/expr/member.d.ts +15 -0
- package/dist/eval/expr/member.d.ts.map +1 -0
- package/dist/eval/expr/member.js +32 -0
- package/dist/eval/expr/member.js.map +1 -0
- package/dist/eval/expr/money-ops.d.ts +10 -0
- package/dist/eval/expr/money-ops.d.ts.map +1 -0
- package/dist/eval/expr/money-ops.js +17 -0
- package/dist/eval/expr/money-ops.js.map +1 -0
- package/dist/eval/expr/operands.d.ts +27 -0
- package/dist/eval/expr/operands.d.ts.map +1 -0
- package/dist/eval/expr/operands.js +167 -0
- package/dist/eval/expr/operands.js.map +1 -0
- package/dist/eval/expr/presence.d.ts +27 -0
- package/dist/eval/expr/presence.d.ts.map +1 -0
- package/dist/eval/expr/presence.js +140 -0
- package/dist/eval/expr/presence.js.map +1 -0
- package/dist/eval/expr/records.d.ts +22 -0
- package/dist/eval/expr/records.d.ts.map +1 -0
- package/dist/eval/expr/records.js +101 -0
- package/dist/eval/expr/records.js.map +1 -0
- package/dist/eval/expr/rule-refs.d.ts +25 -0
- package/dist/eval/expr/rule-refs.d.ts.map +1 -0
- package/dist/eval/expr/rule-refs.js +60 -0
- package/dist/eval/expr/rule-refs.js.map +1 -0
- package/dist/eval/expr/sequences.d.ts +26 -0
- package/dist/eval/expr/sequences.d.ts.map +1 -0
- package/dist/eval/expr/sequences.js +151 -0
- package/dist/eval/expr/sequences.js.map +1 -0
- package/dist/eval/expr/value.d.ts +99 -0
- package/dist/eval/expr/value.d.ts.map +1 -0
- package/dist/eval/expr/value.js +14 -0
- package/dist/eval/expr/value.js.map +1 -0
- package/dist/eval/expression.d.ts +142 -0
- package/dist/eval/expression.d.ts.map +1 -0
- package/dist/eval/expression.js +446 -0
- package/dist/eval/expression.js.map +1 -0
- package/dist/eval/firing.d.ts +68 -0
- package/dist/eval/firing.d.ts.map +1 -0
- package/dist/eval/firing.js +222 -0
- package/dist/eval/firing.js.map +1 -0
- package/dist/eval/gate.d.ts +110 -0
- package/dist/eval/gate.d.ts.map +1 -0
- package/dist/eval/gate.js +278 -0
- package/dist/eval/gate.js.map +1 -0
- package/dist/eval/layout-visibility.d.ts +18 -0
- package/dist/eval/layout-visibility.d.ts.map +1 -0
- package/dist/eval/layout-visibility.js +61 -0
- package/dist/eval/layout-visibility.js.map +1 -0
- package/dist/eval/option-availability.d.ts +26 -0
- package/dist/eval/option-availability.d.ts.map +1 -0
- package/dist/eval/option-availability.js +580 -0
- package/dist/eval/option-availability.js.map +1 -0
- package/dist/eval/options-boundary.d.ts +15 -0
- package/dist/eval/options-boundary.d.ts.map +1 -0
- package/dist/eval/options-boundary.js +40 -0
- package/dist/eval/options-boundary.js.map +1 -0
- package/dist/eval/options.d.ts +99 -0
- package/dist/eval/options.d.ts.map +1 -0
- package/dist/eval/options.js +96 -0
- package/dist/eval/options.js.map +1 -0
- package/dist/eval/overrides.d.ts +116 -0
- package/dist/eval/overrides.d.ts.map +1 -0
- package/dist/eval/overrides.js +176 -0
- package/dist/eval/overrides.js.map +1 -0
- package/dist/eval/paths.d.ts +25 -0
- package/dist/eval/paths.d.ts.map +1 -0
- package/dist/eval/paths.js +47 -0
- package/dist/eval/paths.js.map +1 -0
- package/dist/eval/presentation-reads.d.ts +20 -0
- package/dist/eval/presentation-reads.d.ts.map +1 -0
- package/dist/eval/presentation-reads.js +2 -0
- package/dist/eval/presentation-reads.js.map +1 -0
- package/dist/eval/presentation.d.ts +122 -0
- package/dist/eval/presentation.d.ts.map +1 -0
- package/dist/eval/presentation.js +255 -0
- package/dist/eval/presentation.js.map +1 -0
- package/dist/eval/reader/context-value.d.ts +41 -0
- package/dist/eval/reader/context-value.d.ts.map +1 -0
- package/dist/eval/reader/context-value.js +129 -0
- package/dist/eval/reader/context-value.js.map +1 -0
- package/dist/eval/reader/covered.d.ts +53 -0
- package/dist/eval/reader/covered.d.ts.map +1 -0
- package/dist/eval/reader/covered.js +139 -0
- package/dist/eval/reader/covered.js.map +1 -0
- package/dist/eval/reader/declarations.d.ts +182 -0
- package/dist/eval/reader/declarations.d.ts.map +1 -0
- package/dist/eval/reader/declarations.js +153 -0
- package/dist/eval/reader/declarations.js.map +1 -0
- package/dist/eval/reader/member-access.d.ts +87 -0
- package/dist/eval/reader/member-access.d.ts.map +1 -0
- package/dist/eval/reader/member-access.js +212 -0
- package/dist/eval/reader/member-access.js.map +1 -0
- package/dist/eval/reader/memo.d.ts +34 -0
- package/dist/eval/reader/memo.d.ts.map +1 -0
- package/dist/eval/reader/memo.js +67 -0
- package/dist/eval/reader/memo.js.map +1 -0
- package/dist/eval/reader/overlay.d.ts +74 -0
- package/dist/eval/reader/overlay.d.ts.map +1 -0
- package/dist/eval/reader/overlay.js +365 -0
- package/dist/eval/reader/overlay.js.map +1 -0
- package/dist/eval/reader/questions.d.ts +37 -0
- package/dist/eval/reader/questions.d.ts.map +1 -0
- package/dist/eval/reader/questions.js +78 -0
- package/dist/eval/reader/questions.js.map +1 -0
- package/dist/eval/reader/resolve.d.ts +84 -0
- package/dist/eval/reader/resolve.d.ts.map +1 -0
- package/dist/eval/reader/resolve.js +310 -0
- package/dist/eval/reader/resolve.js.map +1 -0
- package/dist/eval/reader/value-read.d.ts +50 -0
- package/dist/eval/reader/value-read.d.ts.map +1 -0
- package/dist/eval/reader/value-read.js +133 -0
- package/dist/eval/reader/value-read.js.map +1 -0
- package/dist/eval/reader/withheld.d.ts +48 -0
- package/dist/eval/reader/withheld.d.ts.map +1 -0
- package/dist/eval/reader/withheld.js +108 -0
- package/dist/eval/reader/withheld.js.map +1 -0
- package/dist/eval/reader-paths.d.ts +24 -0
- package/dist/eval/reader-paths.d.ts.map +1 -0
- package/dist/eval/reader-paths.js +23 -0
- package/dist/eval/reader-paths.js.map +1 -0
- package/dist/eval/reader.d.ts +281 -0
- package/dist/eval/reader.d.ts.map +1 -0
- package/dist/eval/reader.js +560 -0
- package/dist/eval/reader.js.map +1 -0
- package/dist/eval/receipt.d.ts +37 -0
- package/dist/eval/receipt.d.ts.map +1 -0
- package/dist/eval/receipt.js +222 -0
- package/dist/eval/receipt.js.map +1 -0
- package/dist/eval/report/assemble.d.ts +84 -0
- package/dist/eval/report/assemble.d.ts.map +1 -0
- package/dist/eval/report/assemble.js +277 -0
- package/dist/eval/report/assemble.js.map +1 -0
- package/dist/eval/report/fold.d.ts +18 -0
- package/dist/eval/report/fold.d.ts.map +1 -0
- package/dist/eval/report/fold.js +58 -0
- package/dist/eval/report/fold.js.map +1 -0
- package/dist/eval/rule/alternatives.d.ts +23 -0
- package/dist/eval/rule/alternatives.d.ts.map +1 -0
- package/dist/eval/rule/alternatives.js +46 -0
- package/dist/eval/rule/alternatives.js.map +1 -0
- package/dist/eval/rule/behaviour.d.ts +47 -0
- package/dist/eval/rule/behaviour.d.ts.map +1 -0
- package/dist/eval/rule/behaviour.js +249 -0
- package/dist/eval/rule/behaviour.js.map +1 -0
- package/dist/eval/rule/compute.d.ts +46 -0
- package/dist/eval/rule/compute.d.ts.map +1 -0
- package/dist/eval/rule/compute.js +158 -0
- package/dist/eval/rule/compute.js.map +1 -0
- package/dist/eval/rule/create-state.d.ts +42 -0
- package/dist/eval/rule/create-state.d.ts.map +1 -0
- package/dist/eval/rule/create-state.js +134 -0
- package/dist/eval/rule/create-state.js.map +1 -0
- package/dist/eval/rule/diagnostics.d.ts +24 -0
- package/dist/eval/rule/diagnostics.d.ts.map +1 -0
- package/dist/eval/rule/diagnostics.js +45 -0
- package/dist/eval/rule/diagnostics.js.map +1 -0
- package/dist/eval/rule/execution.d.ts +24 -0
- package/dist/eval/rule/execution.d.ts.map +1 -0
- package/dist/eval/rule/execution.js +495 -0
- package/dist/eval/rule/execution.js.map +1 -0
- package/dist/eval/rule/gate.d.ts +12 -0
- package/dist/eval/rule/gate.d.ts.map +1 -0
- package/dist/eval/rule/gate.js +34 -0
- package/dist/eval/rule/gate.js.map +1 -0
- package/dist/eval/rule/item.d.ts +11 -0
- package/dist/eval/rule/item.d.ts.map +1 -0
- package/dist/eval/rule/item.js +265 -0
- package/dist/eval/rule/item.js.map +1 -0
- package/dist/eval/rule/prepare.d.ts +64 -0
- package/dist/eval/rule/prepare.d.ts.map +1 -0
- package/dist/eval/rule/prepare.js +131 -0
- package/dist/eval/rule/prepare.js.map +1 -0
- package/dist/eval/rule/result.d.ts +97 -0
- package/dist/eval/rule/result.d.ts.map +1 -0
- package/dist/eval/rule/result.js +347 -0
- package/dist/eval/rule/result.js.map +1 -0
- package/dist/eval/rule/runner.d.ts +128 -0
- package/dist/eval/rule/runner.d.ts.map +1 -0
- package/dist/eval/rule/runner.js +296 -0
- package/dist/eval/rule/runner.js.map +1 -0
- package/dist/eval/rule/screen.d.ts +32 -0
- package/dist/eval/rule/screen.d.ts.map +1 -0
- package/dist/eval/rule/screen.js +73 -0
- package/dist/eval/rule/screen.js.map +1 -0
- package/dist/eval/rule/state.d.ts +137 -0
- package/dist/eval/rule/state.d.ts.map +1 -0
- package/dist/eval/rule/state.js +2 -0
- package/dist/eval/rule/state.js.map +1 -0
- package/dist/eval/rule/steps.d.ts +44 -0
- package/dist/eval/rule/steps.d.ts.map +1 -0
- package/dist/eval/rule/steps.js +367 -0
- package/dist/eval/rule/steps.js.map +1 -0
- package/dist/eval/rule/visibility.d.ts +18 -0
- package/dist/eval/rule/visibility.d.ts.map +1 -0
- package/dist/eval/rule/visibility.js +79 -0
- package/dist/eval/rule/visibility.js.map +1 -0
- package/dist/eval/seal.d.ts +74 -0
- package/dist/eval/seal.d.ts.map +1 -0
- package/dist/eval/seal.js +154 -0
- package/dist/eval/seal.js.map +1 -0
- package/dist/eval/signature-coverage.d.ts +19 -0
- package/dist/eval/signature-coverage.d.ts.map +1 -0
- package/dist/eval/signature-coverage.js +160 -0
- package/dist/eval/signature-coverage.js.map +1 -0
- package/dist/eval/state/derive.d.ts +72 -0
- package/dist/eval/state/derive.d.ts.map +1 -0
- package/dist/eval/state/derive.js +61 -0
- package/dist/eval/state/derive.js.map +1 -0
- package/dist/eval/state/describe.d.ts +18 -0
- package/dist/eval/state/describe.d.ts.map +1 -0
- package/dist/eval/state/describe.js +19 -0
- package/dist/eval/state/describe.js.map +1 -0
- package/dist/eval/state/field-state.d.ts +471 -0
- package/dist/eval/state/field-state.d.ts.map +1 -0
- package/dist/eval/state/field-state.js +1604 -0
- package/dist/eval/state/field-state.js.map +1 -0
- package/dist/eval/state/measurement.d.ts +136 -0
- package/dist/eval/state/measurement.d.ts.map +1 -0
- package/dist/eval/state/measurement.js +209 -0
- package/dist/eval/state/measurement.js.map +1 -0
- package/dist/eval/state/options.d.ts +21 -0
- package/dist/eval/state/options.d.ts.map +1 -0
- package/dist/eval/state/options.js +3 -0
- package/dist/eval/state/options.js.map +1 -0
- package/dist/eval/state/readiness.d.ts +400 -0
- package/dist/eval/state/readiness.d.ts.map +1 -0
- package/dist/eval/state/readiness.js +1067 -0
- package/dist/eval/state/readiness.js.map +1 -0
- package/dist/eval/state/snapshot.d.ts +130 -0
- package/dist/eval/state/snapshot.d.ts.map +1 -0
- package/dist/eval/state/snapshot.js +35 -0
- package/dist/eval/state/snapshot.js.map +1 -0
- package/dist/eval/state/unavailable-options.d.ts +54 -0
- package/dist/eval/state/unavailable-options.d.ts.map +1 -0
- package/dist/eval/state/unavailable-options.js +82 -0
- package/dist/eval/state/unavailable-options.js.map +1 -0
- package/dist/eval/state/value-state.d.ts +38 -0
- package/dist/eval/state/value-state.d.ts.map +1 -0
- package/dist/eval/state/value-state.js +52 -0
- package/dist/eval/state/value-state.js.map +1 -0
- package/dist/eval/submission/admission.d.ts +50 -0
- package/dist/eval/submission/admission.d.ts.map +1 -0
- package/dist/eval/submission/admission.js +174 -0
- package/dist/eval/submission/admission.js.map +1 -0
- package/dist/eval/submission/authority.d.ts +71 -0
- package/dist/eval/submission/authority.d.ts.map +1 -0
- package/dist/eval/submission/authority.js +118 -0
- package/dist/eval/submission/authority.js.map +1 -0
- package/dist/eval/submission/datasets.d.ts +28 -0
- package/dist/eval/submission/datasets.d.ts.map +1 -0
- package/dist/eval/submission/datasets.js +109 -0
- package/dist/eval/submission/datasets.js.map +1 -0
- package/dist/eval/submission/index.d.ts +15 -0
- package/dist/eval/submission/index.d.ts.map +1 -0
- package/dist/eval/submission/index.js +13 -0
- package/dist/eval/submission/index.js.map +1 -0
- package/dist/eval/submission/refusals.d.ts +103 -0
- package/dist/eval/submission/refusals.d.ts.map +1 -0
- package/dist/eval/submission/refusals.js +15 -0
- package/dist/eval/submission/refusals.js.map +1 -0
- package/dist/eval/submission/signatures.d.ts +7 -0
- package/dist/eval/submission/signatures.d.ts.map +1 -0
- package/dist/eval/submission/signatures.js +215 -0
- package/dist/eval/submission/signatures.js.map +1 -0
- package/dist/eval/submission/writes.d.ts +51 -0
- package/dist/eval/submission/writes.d.ts.map +1 -0
- package/dist/eval/submission/writes.js +203 -0
- package/dist/eval/submission/writes.js.map +1 -0
- package/dist/eval/submission.d.ts +53 -0
- package/dist/eval/submission.d.ts.map +1 -0
- package/dist/eval/submission.js +521 -0
- package/dist/eval/submission.js.map +1 -0
- package/dist/eval/suggestions-to-engine.d.ts +18 -0
- package/dist/eval/suggestions-to-engine.d.ts.map +1 -0
- package/dist/eval/suggestions-to-engine.js +40 -0
- package/dist/eval/suggestions-to-engine.js.map +1 -0
- package/dist/eval/suggestions.d.ts +17 -0
- package/dist/eval/suggestions.d.ts.map +1 -0
- package/dist/eval/suggestions.js +314 -0
- package/dist/eval/suggestions.js.map +1 -0
- package/dist/eval/undecided.d.ts +64 -0
- package/dist/eval/undecided.d.ts.map +1 -0
- package/dist/eval/undecided.js +101 -0
- package/dist/eval/undecided.js.map +1 -0
- package/dist/eval/verdict.d.ts +66 -0
- package/dist/eval/verdict.d.ts.map +1 -0
- package/dist/eval/verdict.js +106 -0
- package/dist/eval/verdict.js.map +1 -0
- package/dist/eval/verify-signature.d.ts +78 -0
- package/dist/eval/verify-signature.d.ts.map +1 -0
- package/dist/eval/verify-signature.js +185 -0
- package/dist/eval/verify-signature.js.map +1 -0
- package/dist/eval/version-dispatch.d.ts +38 -0
- package/dist/eval/version-dispatch.d.ts.map +1 -0
- package/dist/eval/version-dispatch.js +61 -0
- package/dist/eval/version-dispatch.js.map +1 -0
- package/dist/eval/visibility.d.ts +33 -0
- package/dist/eval/visibility.d.ts.map +1 -0
- package/dist/eval/visibility.js +83 -0
- package/dist/eval/visibility.js.map +1 -0
- package/dist/evaluate.d.ts +24 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +18 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/expr/builtin-docs.d.ts +51 -0
- package/dist/expr/builtin-docs.d.ts.map +1 -0
- package/dist/expr/builtin-docs.js +874 -0
- package/dist/expr/builtin-docs.js.map +1 -0
- package/dist/expr/builtins.d.ts +50 -0
- package/dist/expr/builtins.d.ts.map +1 -0
- package/dist/expr/builtins.js +966 -0
- package/dist/expr/builtins.js.map +1 -0
- package/dist/expr/decimal-precision.d.ts +39 -0
- package/dist/expr/decimal-precision.d.ts.map +1 -0
- package/dist/expr/decimal-precision.js +62 -0
- package/dist/expr/decimal-precision.js.map +1 -0
- package/dist/expr/decimal.d.ts +172 -0
- package/dist/expr/decimal.d.ts.map +1 -0
- package/dist/expr/decimal.js +782 -0
- package/dist/expr/decimal.js.map +1 -0
- package/dist/expr/deprecations.d.ts +34 -0
- package/dist/expr/deprecations.d.ts.map +1 -0
- package/dist/expr/deprecations.js +17 -0
- package/dist/expr/deprecations.js.map +1 -0
- package/dist/expr/diagnostics.d.ts +21 -0
- package/dist/expr/diagnostics.d.ts.map +1 -0
- package/dist/expr/diagnostics.js +231 -0
- package/dist/expr/diagnostics.js.map +1 -0
- package/dist/expr/direction.d.ts +30 -0
- package/dist/expr/direction.d.ts.map +1 -0
- package/dist/expr/direction.js +77 -0
- package/dist/expr/direction.js.map +1 -0
- package/dist/expr/example-expression.d.ts +62 -0
- package/dist/expr/example-expression.d.ts.map +1 -0
- package/dist/expr/example-expression.js +670 -0
- package/dist/expr/example-expression.js.map +1 -0
- package/dist/expr/instant.d.ts +49 -0
- package/dist/expr/instant.d.ts.map +1 -0
- package/dist/expr/instant.js +111 -0
- package/dist/expr/instant.js.map +1 -0
- package/dist/expr/logic.d.ts +17 -0
- package/dist/expr/logic.d.ts.map +1 -0
- package/dist/expr/logic.js +65 -0
- package/dist/expr/logic.js.map +1 -0
- package/dist/expr/messages.d.ts +45 -0
- package/dist/expr/messages.d.ts.map +1 -0
- package/dist/expr/messages.js +280 -0
- package/dist/expr/messages.js.map +1 -0
- package/dist/expr/money.d.ts +38 -0
- package/dist/expr/money.d.ts.map +1 -0
- package/dist/expr/money.js +127 -0
- package/dist/expr/money.js.map +1 -0
- package/dist/expr/ordering.d.ts +56 -0
- package/dist/expr/ordering.d.ts.map +1 -0
- package/dist/expr/ordering.js +167 -0
- package/dist/expr/ordering.js.map +1 -0
- package/dist/expr/pattern.d.ts +44 -0
- package/dist/expr/pattern.d.ts.map +1 -0
- package/dist/expr/pattern.js +458 -0
- package/dist/expr/pattern.js.map +1 -0
- package/dist/expr/plain-date.d.ts +90 -0
- package/dist/expr/plain-date.d.ts.map +1 -0
- package/dist/expr/plain-date.js +230 -0
- package/dist/expr/plain-date.js.map +1 -0
- package/dist/expr/plural-categories.d.ts +8 -0
- package/dist/expr/plural-categories.d.ts.map +1 -0
- package/dist/expr/plural-categories.js +15 -0
- package/dist/expr/plural-categories.js.map +1 -0
- package/dist/expr/plural-keys.d.ts +39 -0
- package/dist/expr/plural-keys.d.ts.map +1 -0
- package/dist/expr/plural-keys.js +46 -0
- package/dist/expr/plural-keys.js.map +1 -0
- package/dist/expr/plural.d.ts +33 -0
- package/dist/expr/plural.d.ts.map +1 -0
- package/dist/expr/plural.js +50 -0
- package/dist/expr/plural.js.map +1 -0
- package/dist/expr/quantity.d.ts +31 -0
- package/dist/expr/quantity.d.ts.map +1 -0
- package/dist/expr/quantity.js +83 -0
- package/dist/expr/quantity.js.map +1 -0
- package/dist/expr/reduce.d.ts +50 -0
- package/dist/expr/reduce.d.ts.map +1 -0
- package/dist/expr/reduce.js +236 -0
- package/dist/expr/reduce.js.map +1 -0
- package/dist/expr/regex.d.ts +108 -0
- package/dist/expr/regex.d.ts.map +1 -0
- package/dist/expr/regex.js +1207 -0
- package/dist/expr/regex.js.map +1 -0
- package/dist/expr/select-locale.d.ts +67 -0
- package/dist/expr/select-locale.d.ts.map +1 -0
- package/dist/expr/select-locale.js +219 -0
- package/dist/expr/select-locale.js.map +1 -0
- package/dist/expr/sequences.d.ts +123 -0
- package/dist/expr/sequences.d.ts.map +1 -0
- package/dist/expr/sequences.js +234 -0
- package/dist/expr/sequences.js.map +1 -0
- package/dist/expr/strings.d.ts +50 -0
- package/dist/expr/strings.d.ts.map +1 -0
- package/dist/expr/strings.js +184 -0
- package/dist/expr/strings.js.map +1 -0
- package/dist/expr/validation.d.ts +32 -0
- package/dist/expr/validation.d.ts.map +1 -0
- package/dist/expr/validation.js +182 -0
- package/dist/expr/validation.js.map +1 -0
- package/dist/graph/freeze.d.ts +4 -0
- package/dist/graph/freeze.d.ts.map +1 -0
- package/dist/graph/freeze.js +52 -0
- package/dist/graph/freeze.js.map +1 -0
- package/dist/graph/index.d.ts +15 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/inspect.d.ts +76 -0
- package/dist/graph/inspect.d.ts.map +1 -0
- package/dist/graph/inspect.js +263 -0
- package/dist/graph/inspect.js.map +1 -0
- package/dist/graph/read-walk.d.ts +101 -0
- package/dist/graph/read-walk.d.ts.map +1 -0
- package/dist/graph/read-walk.js +358 -0
- package/dist/graph/read-walk.js.map +1 -0
- package/dist/graph/record-index.d.ts +24 -0
- package/dist/graph/record-index.d.ts.map +1 -0
- package/dist/graph/record-index.js +35 -0
- package/dist/graph/record-index.js.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/lookup/digest.d.ts +51 -0
- package/dist/lookup/digest.d.ts.map +1 -0
- package/dist/lookup/digest.js +46 -0
- package/dist/lookup/digest.js.map +1 -0
- package/dist/lookup/index.d.ts +28 -0
- package/dist/lookup/index.d.ts.map +1 -0
- package/dist/lookup/index.js +27 -0
- package/dist/lookup/index.js.map +1 -0
- package/dist/lookup/install.d.ts +48 -0
- package/dist/lookup/install.d.ts.map +1 -0
- package/dist/lookup/install.js +315 -0
- package/dist/lookup/install.js.map +1 -0
- package/dist/lookup/pass.d.ts +55 -0
- package/dist/lookup/pass.d.ts.map +1 -0
- package/dist/lookup/pass.js +212 -0
- package/dist/lookup/pass.js.map +1 -0
- package/dist/lookup/pins.d.ts +34 -0
- package/dist/lookup/pins.d.ts.map +1 -0
- package/dist/lookup/pins.js +39 -0
- package/dist/lookup/pins.js.map +1 -0
- package/dist/lookup/provenance.d.ts +23 -0
- package/dist/lookup/provenance.d.ts.map +1 -0
- package/dist/lookup/provenance.js +78 -0
- package/dist/lookup/provenance.js.map +1 -0
- package/dist/lookup/readiness.d.ts +13 -0
- package/dist/lookup/readiness.d.ts.map +1 -0
- package/dist/lookup/readiness.js +57 -0
- package/dist/lookup/readiness.js.map +1 -0
- package/dist/lookup/resolve.d.ts +24 -0
- package/dist/lookup/resolve.d.ts.map +1 -0
- package/dist/lookup/resolve.js +201 -0
- package/dist/lookup/resolve.js.map +1 -0
- package/dist/lookup/store.d.ts +41 -0
- package/dist/lookup/store.d.ts.map +1 -0
- package/dist/lookup/store.js +74 -0
- package/dist/lookup/store.js.map +1 -0
- package/dist/model/access.d.ts +200 -0
- package/dist/model/access.d.ts.map +1 -0
- package/dist/model/access.js +125 -0
- package/dist/model/access.js.map +1 -0
- package/dist/model/artifact-members.d.ts +3 -0
- package/dist/model/artifact-members.d.ts.map +1 -0
- package/dist/model/artifact-members.js +38 -0
- package/dist/model/artifact-members.js.map +1 -0
- package/dist/model/composition.d.ts +47 -0
- package/dist/model/composition.d.ts.map +1 -0
- package/dist/model/composition.js +66 -0
- package/dist/model/composition.js.map +1 -0
- package/dist/model/domain.d.ts +51 -0
- package/dist/model/domain.d.ts.map +1 -0
- package/dist/model/domain.js +75 -0
- package/dist/model/domain.js.map +1 -0
- package/dist/model/duration.d.ts +31 -0
- package/dist/model/duration.d.ts.map +1 -0
- package/dist/model/duration.js +136 -0
- package/dist/model/duration.js.map +1 -0
- package/dist/model/errors.d.ts +58 -0
- package/dist/model/errors.d.ts.map +1 -0
- package/dist/model/errors.js +81 -0
- package/dist/model/errors.js.map +1 -0
- package/dist/model/evolution.d.ts +177 -0
- package/dist/model/evolution.d.ts.map +1 -0
- package/dist/model/evolution.js +5 -0
- package/dist/model/evolution.js.map +1 -0
- package/dist/model/expr-children.d.ts +15 -0
- package/dist/model/expr-children.d.ts.map +1 -0
- package/dist/model/expr-children.js +45 -0
- package/dist/model/expr-children.js.map +1 -0
- package/dist/model/guards.d.ts +9 -0
- package/dist/model/guards.d.ts.map +1 -0
- package/dist/model/guards.js +11 -0
- package/dist/model/guards.js.map +1 -0
- package/dist/model/input.d.ts +42 -0
- package/dist/model/input.d.ts.map +1 -0
- package/dist/model/input.js +26 -0
- package/dist/model/input.js.map +1 -0
- package/dist/model/integer.d.ts +14 -0
- package/dist/model/integer.d.ts.map +1 -0
- package/dist/model/integer.js +16 -0
- package/dist/model/integer.js.map +1 -0
- package/dist/model/intrinsic.d.ts +18 -0
- package/dist/model/intrinsic.d.ts.map +1 -0
- package/dist/model/intrinsic.js +21 -0
- package/dist/model/intrinsic.js.map +1 -0
- package/dist/model/layout.d.ts +129 -0
- package/dist/model/layout.d.ts.map +1 -0
- package/dist/model/layout.js +2 -0
- package/dist/model/layout.js.map +1 -0
- package/dist/model/media.d.ts +33 -0
- package/dist/model/media.d.ts.map +1 -0
- package/dist/model/media.js +86 -0
- package/dist/model/media.js.map +1 -0
- package/dist/model/members.generated.d.ts +11 -0
- package/dist/model/members.generated.d.ts.map +1 -0
- package/dist/model/members.generated.js +71 -0
- package/dist/model/members.generated.js.map +1 -0
- package/dist/model/row-address.d.ts +27 -0
- package/dist/model/row-address.d.ts.map +1 -0
- package/dist/model/row-address.js +146 -0
- package/dist/model/row-address.js.map +1 -0
- package/dist/model/schema.d.ts +108 -0
- package/dist/model/schema.d.ts.map +1 -0
- package/dist/model/schema.js +2 -0
- package/dist/model/schema.js.map +1 -0
- package/dist/model/shape.d.ts +193 -0
- package/dist/model/shape.d.ts.map +1 -0
- package/dist/model/shape.js +2 -0
- package/dist/model/shape.js.map +1 -0
- package/dist/model/time.d.ts +61 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +110 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/types.d.ts +1329 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +424 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/values.d.ts +91 -0
- package/dist/model/values.d.ts.map +1 -0
- package/dist/model/values.js +195 -0
- package/dist/model/values.js.map +1 -0
- package/dist/model/wire.d.ts +356 -0
- package/dist/model/wire.d.ts.map +1 -0
- package/dist/model/wire.js +1504 -0
- package/dist/model/wire.js.map +1 -0
- package/dist/offline/index.d.ts +374 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +422 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +42 -0
- package/dist/testing.js.map +1 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +116 -0
- package/dist/version.js.map +1 -0
- package/package.json +98 -3
|
@@ -0,0 +1,1504 @@
|
|
|
1
|
+
import { canonicalizeRestricted, copyRestricted } from '../canonical/jcs.js';
|
|
2
|
+
import { objectShapeViolation, hasUnpairedSurrogate, prototypeOf, setOwn, } from '../canonical/restricted.js';
|
|
3
|
+
import { asDecimalString, asWireDecimalString, compareDecimalTexts } from '../expr/decimal.js';
|
|
4
|
+
import { parseInstant } from '../expr/instant.js';
|
|
5
|
+
import { toMoneyValue } from '../expr/money.js';
|
|
6
|
+
import { toWireQuantityValue } from '../expr/quantity.js';
|
|
7
|
+
import { parsePlainDate, parseWirePlainDate } from '../expr/plain-date.js';
|
|
8
|
+
import { compareCodePoints } from '../expr/strings.js';
|
|
9
|
+
import { parseClockTime } from './time.js';
|
|
10
|
+
import { toDurationValue } from './duration.js';
|
|
11
|
+
import { intrinsicMembers, isIntrinsicPrimitive } from './intrinsic.js';
|
|
12
|
+
import { INTRINSIC_MEMBERS } from './members.generated.js';
|
|
13
|
+
import { AxiomError, LateBoundTypeMismatch } from './errors.js';
|
|
14
|
+
import { isRecord } from './guards.js';
|
|
15
|
+
import { isSafeInteger } from './integer.js';
|
|
16
|
+
import { valueDomainOf } from './domain.js';
|
|
17
|
+
import { ARTIFACT_ROOT_MEMBERS } from './artifact-members.js';
|
|
18
|
+
import { compositionMemberOutside, isCompositionReport } from './composition.js';
|
|
19
|
+
import { AXIOM_VERSION, compareVersions, isVersionText } from '../version.js';
|
|
20
|
+
import { asAccessVersion, toAccessOverlay } from './access.js';
|
|
21
|
+
import { evaluationInputOf, parsedAccessOf } from './input.js';
|
|
22
|
+
import { CODE_PATTERN, COUNTRY_CODE_PATTERN, IDENTIFIER_PATTERN, isReservedContextRoot, isTier, MIME_TYPE_PATTERN, SHA256_HEX_PATTERN, TIERS, } from './types.js';
|
|
23
|
+
/** The tier names as one refusal states them, derived from the vocabulary tuple. */
|
|
24
|
+
const TIER_CHOICES = TIERS.map((tier) => `"${tier}"`).join(' or ');
|
|
25
|
+
function refuse(path, message) {
|
|
26
|
+
throw new AxiomError('ENGINE_ERROR', message, path);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The reader's declaration of one value domain.
|
|
30
|
+
*
|
|
31
|
+
* The domain is already the one derivation the compiler types and the reader validates
|
|
32
|
+
* (`model/domain.ts`), so this only narrows it into the `WireDeclaration` shape. A duration's
|
|
33
|
+
* unit arrives as `minutes` when the declaration omitted it, and a quantity's scale as `0`,
|
|
34
|
+
* because `valueDomainOf` applies the reader's defaults rather than leaving them to each call.
|
|
35
|
+
*/
|
|
36
|
+
export function wireDeclarationOfDomain(domain) {
|
|
37
|
+
return {
|
|
38
|
+
primitive: domain.primitive,
|
|
39
|
+
...(domain.currency === undefined ? {} : { currency: domain.currency }),
|
|
40
|
+
...(domain.scale === undefined ? {} : { scale: domain.scale }),
|
|
41
|
+
...(domain.units === undefined ? {} : { units: domain.units }),
|
|
42
|
+
...(domain.unit === undefined ? {} : { unit: domain.unit }),
|
|
43
|
+
...(domain.fields === undefined ? {} : { fields: domain.fields }),
|
|
44
|
+
...(domain.items === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: {
|
|
47
|
+
items: {
|
|
48
|
+
primitive: domain.items.primitive,
|
|
49
|
+
...(domain.items.currency === undefined ? {} : { currency: domain.items.currency }),
|
|
50
|
+
...(domain.items.scale === undefined ? {} : { scale: domain.items.scale }),
|
|
51
|
+
...(domain.items.units === undefined ? {} : { units: domain.items.units }),
|
|
52
|
+
...(domain.items.unit === undefined ? {} : { unit: domain.items.unit }),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The declaration a value of `field` is read against.
|
|
59
|
+
*
|
|
60
|
+
* A record's members come from its nested `fields`; a scalar array's item domain comes from
|
|
61
|
+
* `items`. Both the type checker and the reader reach this one derivation, so a declaration
|
|
62
|
+
* the compiler types is the declaration the boundary validates.
|
|
63
|
+
*/
|
|
64
|
+
export function wireDeclarationOf(field) {
|
|
65
|
+
const declaration = wireDeclarationOfDomain(valueDomainOf(field));
|
|
66
|
+
// An item domain with no declared key is the array's identity: the canonical item value.
|
|
67
|
+
return field.items === undefined || field.rowKey !== undefined
|
|
68
|
+
? declaration
|
|
69
|
+
: { ...declaration, valueIdentity: true };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The declaration a dataset column's values are read against, `[DATA-1.2.2]`.
|
|
73
|
+
*
|
|
74
|
+
* A column states the same domain members a field does: a `quantity` column may declare the
|
|
75
|
+
* `units` it admits and the fractional `scale` its values are held to. This is the one
|
|
76
|
+
* derivation the installer and the dataset compiler read, so a cell the compiler admits is a
|
|
77
|
+
* cell the store installs. A column of another primitive carries none of them.
|
|
78
|
+
*/
|
|
79
|
+
export function wireDeclarationOfColumn(column) {
|
|
80
|
+
return wireDeclarationOfDomain({
|
|
81
|
+
primitive: column.primitive,
|
|
82
|
+
...(column.units === undefined ? {} : { units: column.units }),
|
|
83
|
+
...(column.scale === undefined ? {} : { scale: column.scale }),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* How a read descends one level into a value.
|
|
88
|
+
*
|
|
89
|
+
* A record's own member comes from its declaration; an intrinsic value's member comes from the
|
|
90
|
+
* registry generated out of the published metaschema (`model/intrinsic.ts`). Both the static
|
|
91
|
+
* checker and the reader descend with this one function, so the member a document type-checks is
|
|
92
|
+
* the member a value is read as.
|
|
93
|
+
* A primitive with neither has no member, which is what makes an undeclared member read a
|
|
94
|
+
* compile error rather than an absent value.
|
|
95
|
+
*/
|
|
96
|
+
export function memberOf(field, member) {
|
|
97
|
+
const members = field.fields ??
|
|
98
|
+
intrinsicMembers(field.primitive) ??
|
|
99
|
+
// A value read through a comprehension binder is declared on the array's *element*:
|
|
100
|
+
// `r.minor` over `f_prices` is attributed to `f_prices.minor`, and `walkFieldPath`
|
|
101
|
+
// resolves that declaration here so the binder keeps the element member's declared
|
|
102
|
+
// domain. No source path may descend an array — the compiler refuses that before it asks
|
|
103
|
+
// this function (`EXPR-3.1.3`) — so this arm answers the binder's declaration, never a
|
|
104
|
+
// readable array path.
|
|
105
|
+
(field.primitive === 'array' && field.items !== undefined
|
|
106
|
+
? intrinsicMembers(field.items.primitive)
|
|
107
|
+
: undefined) ??
|
|
108
|
+
[];
|
|
109
|
+
return members.find((candidate) => candidate.fieldId === member);
|
|
110
|
+
}
|
|
111
|
+
function expectText(value, path, what) {
|
|
112
|
+
if (typeof value !== 'string')
|
|
113
|
+
refuse(path, `${what} must be text`);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
function expectRecord(value, path, what) {
|
|
117
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
118
|
+
refuse(path, `${what} must be an object`);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
/** Refuses an undeclared member and a missing required one: both shapes are closed. */
|
|
123
|
+
function checkMembers(value, path, required, optional) {
|
|
124
|
+
for (const key of Object.keys(value)) {
|
|
125
|
+
if (!required.includes(key) && !optional.includes(key)) {
|
|
126
|
+
refuse(path, `undeclared member ${JSON.stringify(key)}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const key of required) {
|
|
130
|
+
if (!Object.hasOwn(value, key))
|
|
131
|
+
refuse(path, `missing required member ${JSON.stringify(key)}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function checkIdentifier(value, path, what) {
|
|
135
|
+
const text = expectText(value, path, what);
|
|
136
|
+
if (!IDENTIFIER_PATTERN.test(text))
|
|
137
|
+
refuse(path, `${what} must be a lower-case identifier`);
|
|
138
|
+
return text;
|
|
139
|
+
}
|
|
140
|
+
function checkCode(value, path, what) {
|
|
141
|
+
const text = expectText(value, path, what);
|
|
142
|
+
if (!CODE_PATTERN.test(text))
|
|
143
|
+
refuse(path, `${what} must be an upper-case code`);
|
|
144
|
+
return text;
|
|
145
|
+
}
|
|
146
|
+
function checkGeo(value, path) {
|
|
147
|
+
const geo = expectRecord(value, path, 'media_ref.geo');
|
|
148
|
+
checkMembers(geo, path, ['lat', 'lon', 'accuracyM'], []);
|
|
149
|
+
for (const key of ['lat', 'lon', 'accuracyM']) {
|
|
150
|
+
asWireDecimalString(expectText(geo[key], `${path}.${key}`, `geo.${key}`), `${path}.${key}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** The closed `media_ref` shape. */
|
|
154
|
+
function checkMediaRef(value, path) {
|
|
155
|
+
const media = expectRecord(value, path, 'media_ref');
|
|
156
|
+
checkMembers(media, path, ['id', 'sha256', 'mime', 'byteSize', 'tags', 'status'], ['capturedAt', 'geo', 'source']);
|
|
157
|
+
checkIdentifier(media['id'], `${path}.id`, 'media_ref.id');
|
|
158
|
+
const sha256 = expectText(media['sha256'], `${path}.sha256`, 'media_ref.sha256');
|
|
159
|
+
if (!SHA256_HEX_PATTERN.test(sha256))
|
|
160
|
+
refuse(`${path}.sha256`, 'sha256 must be lower-case hex');
|
|
161
|
+
const mime = expectText(media['mime'], `${path}.mime`, 'media_ref.mime');
|
|
162
|
+
if (!MIME_TYPE_PATTERN.test(mime))
|
|
163
|
+
refuse(`${path}.mime`, 'mime must be a media type');
|
|
164
|
+
const byteSize = media['byteSize'];
|
|
165
|
+
if (typeof byteSize !== 'number' || !Number.isSafeInteger(byteSize) || byteSize < 0) {
|
|
166
|
+
refuse(`${path}.byteSize`, 'byteSize must be a non-negative integer');
|
|
167
|
+
}
|
|
168
|
+
if (media['capturedAt'] !== undefined) {
|
|
169
|
+
parseInstant(expectText(media['capturedAt'], `${path}.capturedAt`, 'capturedAt'), `${path}.capturedAt`);
|
|
170
|
+
}
|
|
171
|
+
if (media['geo'] !== undefined)
|
|
172
|
+
checkGeo(media['geo'], `${path}.geo`);
|
|
173
|
+
if (media['source'] !== undefined)
|
|
174
|
+
checkCode(media['source'], `${path}.source`, 'source');
|
|
175
|
+
checkCode(media['status'], `${path}.status`, 'status');
|
|
176
|
+
const tags = media['tags'];
|
|
177
|
+
if (!Array.isArray(tags))
|
|
178
|
+
refuse(`${path}.tags`, 'tags must be a list');
|
|
179
|
+
const seen = new Set();
|
|
180
|
+
tags.forEach((tag, index) => {
|
|
181
|
+
const text = expectText(tag, `${path}.tags[${String(index)}]`, 'tag');
|
|
182
|
+
if (text === '')
|
|
183
|
+
refuse(`${path}.tags[${String(index)}]`, 'tag must not be empty');
|
|
184
|
+
if (seen.has(text))
|
|
185
|
+
refuse(`${path}.tags[${String(index)}]`, 'tags must be distinct');
|
|
186
|
+
seen.add(text);
|
|
187
|
+
});
|
|
188
|
+
return media;
|
|
189
|
+
}
|
|
190
|
+
const SIGNATURE_MEMBERS = [
|
|
191
|
+
'id',
|
|
192
|
+
'mediaRefId',
|
|
193
|
+
'signerRole',
|
|
194
|
+
'signedAt',
|
|
195
|
+
'schemaVersion',
|
|
196
|
+
'coveredTargets',
|
|
197
|
+
'dataHash',
|
|
198
|
+
'status',
|
|
199
|
+
];
|
|
200
|
+
/** The closed `signature_ref` shape. */
|
|
201
|
+
function checkSignatureRef(value, path) {
|
|
202
|
+
const signature = expectRecord(value, path, 'signature_ref');
|
|
203
|
+
checkMembers(signature, path, SIGNATURE_MEMBERS, []);
|
|
204
|
+
checkIdentifier(signature['id'], `${path}.id`, 'signature_ref.id');
|
|
205
|
+
checkIdentifier(signature['mediaRefId'], `${path}.mediaRefId`, 'signature_ref.mediaRefId');
|
|
206
|
+
checkCode(signature['signerRole'], `${path}.signerRole`, 'signerRole');
|
|
207
|
+
parseInstant(expectText(signature['signedAt'], `${path}.signedAt`, 'signedAt'), `${path}.signedAt`);
|
|
208
|
+
const schemaVersion = signature['schemaVersion'];
|
|
209
|
+
if (typeof schemaVersion !== 'number' ||
|
|
210
|
+
!Number.isSafeInteger(schemaVersion) ||
|
|
211
|
+
schemaVersion < 1) {
|
|
212
|
+
refuse(`${path}.schemaVersion`, 'schemaVersion must be a positive integer');
|
|
213
|
+
}
|
|
214
|
+
const dataHash = expectText(signature['dataHash'], `${path}.dataHash`, 'signature_ref.dataHash');
|
|
215
|
+
if (!SHA256_HEX_PATTERN.test(dataHash))
|
|
216
|
+
refuse(`${path}.dataHash`, 'dataHash must be lower-case hex');
|
|
217
|
+
checkCode(signature['status'], `${path}.status`, 'status');
|
|
218
|
+
const targets = signature['coveredTargets'];
|
|
219
|
+
validateCoveredTargets(targets, `${path}.coveredTargets`);
|
|
220
|
+
return signature;
|
|
221
|
+
}
|
|
222
|
+
/** Validates a `signature_ref.coveredTargets` array against the closed `coveredTarget` shape. */
|
|
223
|
+
function validateCoveredTargets(targets, path) {
|
|
224
|
+
if (!Array.isArray(targets) || targets.length === 0) {
|
|
225
|
+
refuse(path, 'a signature must cover at least one target');
|
|
226
|
+
}
|
|
227
|
+
targets.forEach((target, index) => {
|
|
228
|
+
const at = `${path}[${String(index)}]`;
|
|
229
|
+
const ref = expectRecord(target, at, 'covered target');
|
|
230
|
+
checkMembers(ref, at, ['fieldId'], ['rowKey']);
|
|
231
|
+
checkIdentifier(ref['fieldId'], `${at}.fieldId`, 'coveredTarget.fieldId');
|
|
232
|
+
checkRowKey(ref['rowKey'], `${at}.rowKey`);
|
|
233
|
+
});
|
|
234
|
+
return targets;
|
|
235
|
+
}
|
|
236
|
+
/** Copies and validates a `signature_ref.coveredTargets` member value read through a path. */
|
|
237
|
+
export function toCoveredTargetsWireValue(value, path) {
|
|
238
|
+
const copied = copyRestricted(value, path);
|
|
239
|
+
if (copied === null)
|
|
240
|
+
return null;
|
|
241
|
+
return validateCoveredTargets(copied, path);
|
|
242
|
+
}
|
|
243
|
+
/** The closed `timeslot` shape, including the `start < end` clause. */
|
|
244
|
+
function checkTimeslot(value, path) {
|
|
245
|
+
const slot = expectRecord(value, path, 'timeslot');
|
|
246
|
+
checkMembers(slot, path, ['slotId', 'localDate', 'start', 'end'], []);
|
|
247
|
+
const slotId = expectText(slot['slotId'], `${path}.slotId`, 'timeslot.slotId');
|
|
248
|
+
if (slotId === '')
|
|
249
|
+
refuse(`${path}.slotId`, 'timeslot.slotId must not be empty');
|
|
250
|
+
parseWirePlainDate(expectText(slot['localDate'], `${path}.localDate`, 'timeslot.localDate'), `${path}.localDate`);
|
|
251
|
+
const start = parseInstant(expectText(slot['start'], `${path}.start`, 'timeslot.start'), `${path}.start`);
|
|
252
|
+
const end = parseInstant(expectText(slot['end'], `${path}.end`, 'timeslot.end'), `${path}.end`);
|
|
253
|
+
// A canonical instant is fixed-width UTC text, so the lexical order is the chronological
|
|
254
|
+
// order and the range needs no timezone database to decide.
|
|
255
|
+
if (start >= end)
|
|
256
|
+
refuse(`${path}.start`, 'timeslot.start must be before timeslot.end');
|
|
257
|
+
return slot;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The closed `duration` shape checked against the declared unit, `MODEL-2.1.24`.
|
|
261
|
+
*
|
|
262
|
+
* The amount and unit rules are `toDurationValue`'s, so the wire path is the declaration check
|
|
263
|
+
* rather than a second shape walk. When the declaration states a unit it is the value's unit: a
|
|
264
|
+
* different one is refused, never converted.
|
|
265
|
+
*/
|
|
266
|
+
function checkDuration(value, path, declaration) {
|
|
267
|
+
const duration = toDurationValue(value, path);
|
|
268
|
+
if (declaration.unit !== undefined && declaration.unit !== duration.unit) {
|
|
269
|
+
refuse(`${path}.unit`, `duration unit ${duration.unit} disagrees with the declared ${declaration.unit}; v1 defines no unit conversion`);
|
|
270
|
+
}
|
|
271
|
+
return { amount: duration.amount, unit: duration.unit };
|
|
272
|
+
}
|
|
273
|
+
/** One present address member: text, and non-empty because the shape states a line. */
|
|
274
|
+
function addressMember(address, path, member) {
|
|
275
|
+
const text = expectText(address[member], `${path}.${member}`, `address.${member}`);
|
|
276
|
+
if (text === '')
|
|
277
|
+
refuse(`${path}.${member}`, `address.${member} must not be empty`);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* The closed `address` shape, `MODEL-2.1.25`.
|
|
281
|
+
*
|
|
282
|
+
* Structural only: two required lines and two optional ones, a non-empty city and postal code,
|
|
283
|
+
* and an upper-case ISO alpha-2 country. Axiom validates no world postal format and no
|
|
284
|
+
* subdivision vocabulary; the host does.
|
|
285
|
+
*/
|
|
286
|
+
function checkAddress(value, path) {
|
|
287
|
+
const address = expectRecord(value, path, 'address');
|
|
288
|
+
checkMembers(address, path, ['line1', 'city', 'postalCode', 'country'], ['line2', 'region']);
|
|
289
|
+
for (const member of ['line1', 'line2', 'city', 'region', 'postalCode']) {
|
|
290
|
+
if (address[member] === undefined)
|
|
291
|
+
continue;
|
|
292
|
+
addressMember(address, path, member);
|
|
293
|
+
}
|
|
294
|
+
const country = expectText(address['country'], `${path}.country`, 'address.country');
|
|
295
|
+
if (!COUNTRY_CODE_PATTERN.test(country)) {
|
|
296
|
+
refuse(`${path}.country`, 'address.country must be an upper-case ISO alpha-2 code');
|
|
297
|
+
}
|
|
298
|
+
return address;
|
|
299
|
+
}
|
|
300
|
+
/** One coordinate member as canonical decimal text, range-checked against `low`/`high`. */
|
|
301
|
+
function coordinateMember(coordinate, path, member, low, high) {
|
|
302
|
+
const text = asWireDecimalString(expectText(coordinate[member], `${path}.${member}`, `coordinate.${member}`), `${path}.${member}`);
|
|
303
|
+
if (compareDecimalTexts(text, asDecimalString(low), `${path}.${member}`) < 0) {
|
|
304
|
+
refuse(`${path}.${member}`, `coordinate.${member} must be at least ${low}`);
|
|
305
|
+
}
|
|
306
|
+
if (compareDecimalTexts(text, asDecimalString(high), `${path}.${member}`) > 0) {
|
|
307
|
+
refuse(`${path}.${member}`, `coordinate.${member} must be at most ${high}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* The closed `coordinate` shape, `MODEL-2.1.26`.
|
|
312
|
+
*
|
|
313
|
+
* Latitude and longitude are canonical decimal text in their geographic ranges; `accuracy` is an
|
|
314
|
+
* optional non-negative radius in metres. v1 computes no distance and resolves no place from a
|
|
315
|
+
* coordinate, and a coordinate is not a media capture's `geo` member.
|
|
316
|
+
*/
|
|
317
|
+
function checkCoordinate(value, path) {
|
|
318
|
+
const coordinate = expectRecord(value, path, 'coordinate');
|
|
319
|
+
checkMembers(coordinate, path, ['latitude', 'longitude'], ['accuracy']);
|
|
320
|
+
coordinateMember(coordinate, path, 'latitude', '-90', '90');
|
|
321
|
+
coordinateMember(coordinate, path, 'longitude', '-180', '180');
|
|
322
|
+
if (coordinate['accuracy'] !== undefined) {
|
|
323
|
+
const accuracy = asWireDecimalString(expectText(coordinate['accuracy'], `${path}.accuracy`, 'coordinate.accuracy'), `${path}.accuracy`);
|
|
324
|
+
if (compareDecimalTexts(accuracy, asDecimalString('0'), `${path}.accuracy`) < 0) {
|
|
325
|
+
refuse(`${path}.accuracy`, 'coordinate.accuracy must be at least 0');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return coordinate;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The one row spelling the wire contract reserves for the symbolic row, `RULES-6.1.2`.
|
|
332
|
+
*
|
|
333
|
+
* A report's row-key position excludes this literal, because the same bytes name the row an
|
|
334
|
+
* item-scoped owner judged. The symbol is admitted only by `suggestedRef` and `removeRow`, the
|
|
335
|
+
* two compiled members that state it; everywhere else it names no row.
|
|
336
|
+
*/
|
|
337
|
+
export const RESERVED_ROW_KEY = 'current';
|
|
338
|
+
/** A row key on the wire is the natural key's canonical value or a host-assigned id. */
|
|
339
|
+
function checkRowKey(raw, path) {
|
|
340
|
+
if (raw === undefined)
|
|
341
|
+
return undefined;
|
|
342
|
+
const key = rowKeyOfWire(raw);
|
|
343
|
+
if (key !== undefined)
|
|
344
|
+
return key;
|
|
345
|
+
// The refusal names the rule that failed, so the four spellings keep their own sentences even
|
|
346
|
+
// though one predicate answers all of them.
|
|
347
|
+
if (typeof raw === 'string') {
|
|
348
|
+
if (raw === '') {
|
|
349
|
+
return refuse(path, 'rowKey must be a non-empty string or a safe integer');
|
|
350
|
+
}
|
|
351
|
+
// The report's row-key position excludes the exact spelling `current` for the same reason:
|
|
352
|
+
// the word is the symbolic row `RULES-6.1.2` states, so a report cannot also carry it as a
|
|
353
|
+
// literal key. The spelling is case-sensitive: `Current` stays a lawful key.
|
|
354
|
+
if (raw === RESERVED_ROW_KEY) {
|
|
355
|
+
return refuse(path, "rowKey must not be the reserved spelling `current`, which names the row an item-scoped owner judged; state the row's literal key");
|
|
356
|
+
}
|
|
357
|
+
// Well-formed UTF-16 is the other half of that contract: a lone surrogate has no UTF-8 form,
|
|
358
|
+
// so the restricted reader would refuse the report that carried it.
|
|
359
|
+
if (hasUnpairedSurrogate(raw)) {
|
|
360
|
+
return refuse(path, 'rowKey must not carry an unpaired surrogate');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return refuse(path, 'rowKey must be a non-empty string or a safe integer');
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* The row key one wire spelling names once every row-key rule has been applied.
|
|
367
|
+
*
|
|
368
|
+
* A row key is a canonical safe integer (so `-0` is refused) or a non-empty string that is not
|
|
369
|
+
* the reserved `current` and carries no unpaired surrogate. `checkRowKey`, `rowKeyValue` and
|
|
370
|
+
* `assignedRowKeyOf` each map this one answer to their own refusal surface, so the three cannot
|
|
371
|
+
* drift about which spellings a row key admits.
|
|
372
|
+
*/
|
|
373
|
+
export function rowKeyOfWire(raw) {
|
|
374
|
+
if (typeof raw === 'number')
|
|
375
|
+
return isSafeInteger(raw) ? raw : undefined;
|
|
376
|
+
if (typeof raw === 'string' &&
|
|
377
|
+
raw !== '' &&
|
|
378
|
+
raw !== RESERVED_ROW_KEY &&
|
|
379
|
+
!hasUnpairedSurrogate(raw)) {
|
|
380
|
+
return raw;
|
|
381
|
+
}
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
/** A row key a resolved value must already be: never coerced from another spelling. */
|
|
385
|
+
export function rowKeyValue(raw) {
|
|
386
|
+
return rowKeyOfWire(raw);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* A row key's identity token: the integer `7` and the text `"7"` are two
|
|
390
|
+
* different keys, so the token carries the wire type as well as the digits.
|
|
391
|
+
*/
|
|
392
|
+
export function rowKeyToken(key) {
|
|
393
|
+
return `${typeof key}:${String(key)}`;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The member index of one record declaration, built once for the declaration list.
|
|
397
|
+
*
|
|
398
|
+
* A compiled artifact is immutable once parsed — the contract the reader's prepared index
|
|
399
|
+
* relies on and `prepareSchema` freezes into place — so the member list a declaration carries
|
|
400
|
+
* is a stable key. Rebuilding the map for every row of every array was per-row work on a
|
|
401
|
+
* structure that cannot change.
|
|
402
|
+
*/
|
|
403
|
+
const MEMBER_INDEXES = new WeakMap();
|
|
404
|
+
function memberIndexOf(fields) {
|
|
405
|
+
const cached = MEMBER_INDEXES.get(fields);
|
|
406
|
+
if (cached !== undefined)
|
|
407
|
+
return cached;
|
|
408
|
+
const index = new Map(fields.map((field) => [field.fieldId, field]));
|
|
409
|
+
MEMBER_INDEXES.set(fields, index);
|
|
410
|
+
return index;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* The member-name rule the published wire contract states for a record no declaration closes.
|
|
414
|
+
*
|
|
415
|
+
* A `record` declaration that names no members is the only shape a `record` context root can
|
|
416
|
+
* have (`contextRoot` in the metaschema has no `fields` member), so the host supplies a whole
|
|
417
|
+
* external object. `copyRestricted` cannot close that object, but `spec/metaschema/schema.v1.json`
|
|
418
|
+
* `$defs/wireValue` still constrains a record's member names to the identifier grammar, and a
|
|
419
|
+
* rule may carry the value into a report's `value` or `params`, which reuse the same pattern.
|
|
420
|
+
* Admitting a name outside it would let the runtime seal a report its own published report
|
|
421
|
+
* contract refuses. The walk descends because a nested object is a wire value in turn, so the
|
|
422
|
+
* same rule applies at every depth.
|
|
423
|
+
*/
|
|
424
|
+
function checkOpenRecordMembers(value, path) {
|
|
425
|
+
if (Array.isArray(value)) {
|
|
426
|
+
const items = value;
|
|
427
|
+
items.forEach((item, index) => {
|
|
428
|
+
checkOpenRecordMembers(item, `${path}[${String(index)}]`);
|
|
429
|
+
});
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (!isRecord(value))
|
|
433
|
+
return;
|
|
434
|
+
const entries = Object.entries(value);
|
|
435
|
+
const outsideGrammar = entries.find(([key]) => !IDENTIFIER_PATTERN.test(key));
|
|
436
|
+
if (outsideGrammar === undefined) {
|
|
437
|
+
for (const [key, member] of entries)
|
|
438
|
+
checkOpenRecordMembers(member, `${path}.${key}`);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
// The member-name pattern is the *generic* object arm of the published union, and a value whose
|
|
442
|
+
// members are one of the union's own object shapes is admitted by that shape's arm instead:
|
|
443
|
+
// `media_ref`, `signature_ref`, `timeslot` and `address` spell members such as `byteSize` and
|
|
444
|
+
// `postalCode`, which the pattern excludes. The generated registry states each shape's members,
|
|
445
|
+
// so the shape is recognised rather than guessed, and its own reader validates the value — so
|
|
446
|
+
// a malformed `media_ref` keeps its precise refusal instead of being reported as a member name
|
|
447
|
+
// the generic arm happens to exclude.
|
|
448
|
+
const shape = innerShapeOf(entries);
|
|
449
|
+
if (shape !== undefined) {
|
|
450
|
+
checkDeclaration(value, path, { primitive: shape }, 'check');
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const [key] = outsideGrammar;
|
|
454
|
+
refuse(`${path}.${key}`, `open record member ${JSON.stringify(key)} is not a lower-case identifier; key the record with names matching ${String(IDENTIFIER_PATTERN)}, or declare its members in \`fields\` so the artifact states their names`);
|
|
455
|
+
}
|
|
456
|
+
/** The primitives whose value is one of the published union's own object arms. */
|
|
457
|
+
const INNER_SHAPE_PRIMITIVES = Object.keys(INTRINSIC_MEMBERS).filter(isIntrinsicPrimitive);
|
|
458
|
+
/** Each inner shape's member names, from the registry generated out of the published metaschema. */
|
|
459
|
+
const INNER_SHAPE_MEMBERS = new Map(INNER_SHAPE_PRIMITIVES.flatMap((primitive) => {
|
|
460
|
+
const members = intrinsicMembers(primitive);
|
|
461
|
+
return members === undefined
|
|
462
|
+
? []
|
|
463
|
+
: [[primitive, new Set(members.map((field) => field.fieldId))]];
|
|
464
|
+
}));
|
|
465
|
+
/**
|
|
466
|
+
* The inner shape an object's members name, or `undefined` when it is a generic record.
|
|
467
|
+
*
|
|
468
|
+
* A shape is recognised by its member names, which are the published `$defs`' own, so an object
|
|
469
|
+
* with a member outside every shape is a generic record and is judged by the name rule above.
|
|
470
|
+
*/
|
|
471
|
+
function innerShapeOf(entries) {
|
|
472
|
+
return INNER_SHAPE_PRIMITIVES.find((primitive) => {
|
|
473
|
+
const members = INNER_SHAPE_MEMBERS.get(primitive);
|
|
474
|
+
return members !== undefined && entries.every(([key]) => members.has(key));
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function checkRecord(value, path, fields, identityMode) {
|
|
478
|
+
const record = expectRecord(value, path, 'record');
|
|
479
|
+
if (fields === undefined) {
|
|
480
|
+
checkOpenRecordMembers(record, path);
|
|
481
|
+
return record;
|
|
482
|
+
}
|
|
483
|
+
const members = memberIndexOf(fields);
|
|
484
|
+
const checked = {};
|
|
485
|
+
for (const [key, member] of Object.entries(record)) {
|
|
486
|
+
const declared = members.get(key);
|
|
487
|
+
if (declared === undefined)
|
|
488
|
+
refuse(path, `undeclared member ${JSON.stringify(key)}`);
|
|
489
|
+
// A member named `__proto__` is a legal declared name in a hand-written artifact; a plain
|
|
490
|
+
// assignment would run the inherited accessor and drop the value (or adopt an object as the
|
|
491
|
+
// record's prototype), so every untrusted key is written as an own data property.
|
|
492
|
+
setOwn(checked, key, readWireValue(member, `${path}.${key}`, wireDeclarationOf(declared), identityMode));
|
|
493
|
+
}
|
|
494
|
+
return checked;
|
|
495
|
+
}
|
|
496
|
+
function checkArray(value, path, itemFields, itemDomain, valueIdentity, identityMode) {
|
|
497
|
+
if (!Array.isArray(value))
|
|
498
|
+
refuse(path, 'array value must be a list');
|
|
499
|
+
const items = value;
|
|
500
|
+
if (itemDomain !== undefined) {
|
|
501
|
+
const checked = items.map((item, index) => readWireValue(item, `${path}[${String(index)}]`, itemDomain, 'check'));
|
|
502
|
+
if (valueIdentity && identityMode === 'check')
|
|
503
|
+
refuseDuplicateItems(checked, path);
|
|
504
|
+
return checked;
|
|
505
|
+
}
|
|
506
|
+
return items.map((item, index) => {
|
|
507
|
+
const at = `${path}[${String(index)}]`;
|
|
508
|
+
if (itemFields !== undefined)
|
|
509
|
+
return checkRecord(item, at, itemFields, 'check');
|
|
510
|
+
// An untyped wire array still holds wire values: without a declared item shape, each record
|
|
511
|
+
// is open and its member names follow the same published grammar as an open record root.
|
|
512
|
+
checkOpenRecordMembers(item, at);
|
|
513
|
+
return item;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* A money value checked against the field's declared `(currency, scale)`.
|
|
518
|
+
*
|
|
519
|
+
* The declaration and the value must agree exactly: a `NZD` amount in an `AUD`-declared field
|
|
520
|
+
* is an authoring defect, not a conversion, so it is refused at the value's path. A declaration
|
|
521
|
+
* that names neither leaves the value self-describing, which is what a dataset column is.
|
|
522
|
+
*/
|
|
523
|
+
function checkMoney(value, path, declaration) {
|
|
524
|
+
const money = toMoneyValue(value, path);
|
|
525
|
+
const { currency, scale } = declaration;
|
|
526
|
+
if (currency !== undefined && money.currency !== currency) {
|
|
527
|
+
refuse(path, `money currency ${money.currency} disagrees with the declared ${currency}`);
|
|
528
|
+
}
|
|
529
|
+
if (scale !== undefined && money.scale !== scale) {
|
|
530
|
+
refuse(path, `money scale ${String(money.scale)} disagrees with the declared ${String(scale)}`);
|
|
531
|
+
}
|
|
532
|
+
return money;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* A quantity value checked against the field's declared unit domain and scale, `MODEL-2.1.21`.
|
|
536
|
+
*
|
|
537
|
+
* The shape, member set, unit code and canonical decimal are `readQuantity`'s, through the
|
|
538
|
+
* wire-safe constructor, so this is the declaration check rather than a second copy of the shape
|
|
539
|
+
* rules. The declaration and the value must agree: a unit the field does not admit is refused
|
|
540
|
+
* rather than converted, because v1 defines no conversion, and a value with more fractional
|
|
541
|
+
* digits than the declared scale is refused rather than rounded, because rounding is the
|
|
542
|
+
* author's explicit `round(q.value, …)` and never a hidden default.
|
|
543
|
+
*/
|
|
544
|
+
function checkQuantity(value, path, declaration) {
|
|
545
|
+
const quantity = toWireQuantityValue(value, path);
|
|
546
|
+
const units = declaration.units;
|
|
547
|
+
if (units !== undefined && !units.includes(quantity.unit)) {
|
|
548
|
+
refuse(`${path}.unit`, `quantity unit ${quantity.unit} is not one of the declared units ${units.join(', ')}`);
|
|
549
|
+
}
|
|
550
|
+
const scale = declaration.scale ?? 0;
|
|
551
|
+
const dot = quantity.value.indexOf('.');
|
|
552
|
+
const fraction = dot < 0 ? 0 : quantity.value.length - dot - 1;
|
|
553
|
+
if (fraction > scale) {
|
|
554
|
+
refuse(`${path}.value`, `quantity value has ${String(fraction)} fractional digits; the declaration admits at most ${String(scale)}`);
|
|
555
|
+
}
|
|
556
|
+
return { value: quantity.value, unit: quantity.unit };
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Refuses two equal items of a value-identified array.
|
|
560
|
+
*
|
|
561
|
+
* The item value *is* the row's identity, so an array holding one value twice names two rows
|
|
562
|
+
* with one identity. `null` is the authored empty value rather than a code, so it is not one.
|
|
563
|
+
*/
|
|
564
|
+
function refuseDuplicateItems(items, path) {
|
|
565
|
+
const seen = new Set();
|
|
566
|
+
items.forEach((item, index) => {
|
|
567
|
+
if (item === null)
|
|
568
|
+
return;
|
|
569
|
+
// Canonical text covers record items as well as scalars, and the wire type is part of
|
|
570
|
+
// the token, so `7` and `"7"` are two values, not one.
|
|
571
|
+
const token = `${typeof item}:${canonicalizeRestricted(item)}`;
|
|
572
|
+
if (!seen.has(token)) {
|
|
573
|
+
seen.add(token);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
refuse(`${path}[${String(index)}]`, 'a value-identified array holds each value at most once');
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The domain a value actually carries, as the late-bound diagnostic names it.
|
|
581
|
+
*
|
|
582
|
+
* Only the distinction the boundary needs is made: a safe integer is `integer`, any other
|
|
583
|
+
* finite number is `decimal`, and a record-shaped measurement keeps its own name. The value is
|
|
584
|
+
* never inspected beyond its shape, so a refusal cannot echo what the host supplied.
|
|
585
|
+
*/
|
|
586
|
+
function receivedDomainOf(value) {
|
|
587
|
+
if (value === null)
|
|
588
|
+
return 'null';
|
|
589
|
+
switch (typeof value) {
|
|
590
|
+
case 'string':
|
|
591
|
+
return 'string';
|
|
592
|
+
case 'boolean':
|
|
593
|
+
return 'boolean';
|
|
594
|
+
case 'number':
|
|
595
|
+
return Number.isSafeInteger(value) ? 'integer' : 'decimal';
|
|
596
|
+
case 'object':
|
|
597
|
+
if (Array.isArray(value))
|
|
598
|
+
return 'array';
|
|
599
|
+
if (isRecord(value)) {
|
|
600
|
+
const minor = Reflect.get(value, 'minor');
|
|
601
|
+
const currency = Reflect.get(value, 'currency');
|
|
602
|
+
const scale = Reflect.get(value, 'scale');
|
|
603
|
+
if (typeof minor === 'string' &&
|
|
604
|
+
typeof currency === 'string' &&
|
|
605
|
+
typeof scale === 'number') {
|
|
606
|
+
return 'money';
|
|
607
|
+
}
|
|
608
|
+
const amount = Reflect.get(value, 'value');
|
|
609
|
+
const unit = Reflect.get(value, 'unit');
|
|
610
|
+
if (typeof amount === 'string' && typeof unit === 'string')
|
|
611
|
+
return 'quantity';
|
|
612
|
+
const wholeAmount = Reflect.get(value, 'amount');
|
|
613
|
+
if (typeof wholeAmount === 'number' && typeof unit === 'string')
|
|
614
|
+
return 'duration';
|
|
615
|
+
return 'record';
|
|
616
|
+
}
|
|
617
|
+
return 'unknown';
|
|
618
|
+
default:
|
|
619
|
+
return 'unknown';
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/** How a declaration's domain reads in the late-bound diagnostic. */
|
|
623
|
+
function declaredDomainOf(declaration) {
|
|
624
|
+
switch (declaration.primitive) {
|
|
625
|
+
case 'money':
|
|
626
|
+
return declaration.currency === undefined || declaration.scale === undefined
|
|
627
|
+
? 'money'
|
|
628
|
+
: `money<${declaration.currency}, ${String(declaration.scale)}>`;
|
|
629
|
+
case 'quantity':
|
|
630
|
+
return declaration.units === undefined
|
|
631
|
+
? 'quantity'
|
|
632
|
+
: `quantity<${declaration.units.join('|')}>`;
|
|
633
|
+
case 'duration':
|
|
634
|
+
return declaration.unit === undefined ? 'duration' : `duration<${declaration.unit}>`;
|
|
635
|
+
default:
|
|
636
|
+
return declaration.primitive;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/** Whether text is decimal-looking, canonical or not, so a non-canonical spelling stays its own refusal. */
|
|
640
|
+
const DECIMAL_LOOKING = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/u;
|
|
641
|
+
/**
|
|
642
|
+
* Whether a value is grossly outside the shape a declaration states.
|
|
643
|
+
*
|
|
644
|
+
* This is the check that distinguishes a host supplying the wrong domain from a value of the
|
|
645
|
+
* right domain with a wrong spelling: `42` for a `string` is the former, `"1.50"` for a
|
|
646
|
+
* `decimal` is the latter and keeps its canonical-spelling refusal. A declaration that admits
|
|
647
|
+
* every string shape (`date`, `instant`, `time`) is not judged beyond text here for exactly
|
|
648
|
+
* that reason: the calendar or clock check remains the specific refusal it already was.
|
|
649
|
+
*/
|
|
650
|
+
function outsideDeclaredShape(value, declaration) {
|
|
651
|
+
if (value === null)
|
|
652
|
+
return false;
|
|
653
|
+
switch (declaration.primitive) {
|
|
654
|
+
case 'string':
|
|
655
|
+
return typeof value !== 'string';
|
|
656
|
+
case 'boolean':
|
|
657
|
+
return typeof value !== 'boolean';
|
|
658
|
+
case 'integer':
|
|
659
|
+
return typeof value !== 'number';
|
|
660
|
+
case 'decimal':
|
|
661
|
+
return !(typeof value === 'number' ||
|
|
662
|
+
(typeof value === 'string' && DECIMAL_LOOKING.test(value)));
|
|
663
|
+
case 'date':
|
|
664
|
+
case 'instant':
|
|
665
|
+
case 'time':
|
|
666
|
+
return typeof value !== 'string';
|
|
667
|
+
case 'record':
|
|
668
|
+
case 'money':
|
|
669
|
+
case 'quantity':
|
|
670
|
+
case 'duration':
|
|
671
|
+
case 'address':
|
|
672
|
+
case 'coordinate':
|
|
673
|
+
case 'media_ref':
|
|
674
|
+
case 'signature_ref':
|
|
675
|
+
case 'timeslot':
|
|
676
|
+
return !isRecord(value);
|
|
677
|
+
case 'array':
|
|
678
|
+
return !Array.isArray(value);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/** Refuses a declaration outside this build's primitive vocabulary at the value being read. */
|
|
682
|
+
function refuseUnsupportedPrimitive(path, primitive) {
|
|
683
|
+
return refuse(path, `the artifact declares the primitive ${spellArtifactMember(primitive)}, which this runtime does not implement; recompile the artifact with this release, or state a primitive \`spec/semantics/model-v1.md\` section 2 defines`);
|
|
684
|
+
}
|
|
685
|
+
function checkDeclaration(value, path, declaration, identityMode) {
|
|
686
|
+
if (value === null) {
|
|
687
|
+
// Null is the empty value of every primitive this build implements, not evidence that an
|
|
688
|
+
// unknown declaration is readable. Prove the vocabulary before taking that fast path.
|
|
689
|
+
switch (declaration.primitive) {
|
|
690
|
+
case 'string':
|
|
691
|
+
case 'boolean':
|
|
692
|
+
case 'integer':
|
|
693
|
+
case 'decimal':
|
|
694
|
+
case 'date':
|
|
695
|
+
case 'instant':
|
|
696
|
+
case 'time':
|
|
697
|
+
case 'money':
|
|
698
|
+
case 'quantity':
|
|
699
|
+
case 'duration':
|
|
700
|
+
case 'address':
|
|
701
|
+
case 'coordinate':
|
|
702
|
+
case 'media_ref':
|
|
703
|
+
case 'signature_ref':
|
|
704
|
+
case 'timeslot':
|
|
705
|
+
case 'record':
|
|
706
|
+
case 'array':
|
|
707
|
+
return null;
|
|
708
|
+
default:
|
|
709
|
+
return refuseUnsupportedPrimitive(path, declaration.primitive);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
switch (declaration.primitive) {
|
|
713
|
+
case 'string':
|
|
714
|
+
return expectText(value, path, 'string value');
|
|
715
|
+
case 'boolean':
|
|
716
|
+
if (typeof value !== 'boolean')
|
|
717
|
+
refuse(path, 'boolean value must be true or false');
|
|
718
|
+
return value;
|
|
719
|
+
case 'integer':
|
|
720
|
+
if (typeof value !== 'number' || !isSafeInteger(value)) {
|
|
721
|
+
refuse(path, 'integer value must be a safe integer');
|
|
722
|
+
}
|
|
723
|
+
return value;
|
|
724
|
+
case 'decimal':
|
|
725
|
+
return asWireDecimalString(expectText(value, path, 'decimal value'), path);
|
|
726
|
+
case 'date': {
|
|
727
|
+
const text = expectText(value, path, 'date value');
|
|
728
|
+
parseWirePlainDate(text, path);
|
|
729
|
+
return text;
|
|
730
|
+
}
|
|
731
|
+
case 'instant':
|
|
732
|
+
return parseInstant(expectText(value, path, 'instant value'), path);
|
|
733
|
+
case 'time': {
|
|
734
|
+
const text = expectText(value, path, 'time value');
|
|
735
|
+
parseClockTime(text, path);
|
|
736
|
+
return text;
|
|
737
|
+
}
|
|
738
|
+
case 'money':
|
|
739
|
+
return checkMoney(value, path, declaration);
|
|
740
|
+
case 'quantity':
|
|
741
|
+
return checkQuantity(value, path, declaration);
|
|
742
|
+
case 'duration':
|
|
743
|
+
return checkDuration(value, path, declaration);
|
|
744
|
+
case 'address':
|
|
745
|
+
return checkAddress(value, path);
|
|
746
|
+
case 'coordinate':
|
|
747
|
+
return checkCoordinate(value, path);
|
|
748
|
+
case 'media_ref':
|
|
749
|
+
return checkMediaRef(value, path);
|
|
750
|
+
case 'signature_ref':
|
|
751
|
+
return checkSignatureRef(value, path);
|
|
752
|
+
case 'timeslot':
|
|
753
|
+
return checkTimeslot(value, path);
|
|
754
|
+
case 'record':
|
|
755
|
+
return checkRecord(value, path, declaration.fields, identityMode);
|
|
756
|
+
case 'array':
|
|
757
|
+
return checkArray(value, path, declaration.fields, declaration.items, declaration.valueIdentity === true, identityMode);
|
|
758
|
+
default: {
|
|
759
|
+
// Every member of `Primitive` has an arm above, so the only declaration that reaches this
|
|
760
|
+
// arm names a primitive this build does not implement: a retained artifact compiled by a
|
|
761
|
+
// release whose vocabulary differs, or storage written by hand. Refusing it at the value's
|
|
762
|
+
// own path is what keeps an unreadable member out of the record — a member stored as
|
|
763
|
+
// `undefined` is indistinguishable from a decided empty value, and a report would say
|
|
764
|
+
// `PASS` over a value nobody wrote. The `never` proof makes a primitive added to the union
|
|
765
|
+
// fail typecheck until it has an arm.
|
|
766
|
+
const unsupported = declaration.primitive;
|
|
767
|
+
return refuseUnsupportedPrimitive(path, unsupported);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Reads `raw` as a canonical value of `declaration`'s domain, or refuses it with the
|
|
773
|
+
* path and the cause. The returned value is a plain canonical copy, so a value the
|
|
774
|
+
* engine accepted can always be hashed and reported unchanged.
|
|
775
|
+
*/
|
|
776
|
+
function readWireValue(raw, path, declaration, identityMode) {
|
|
777
|
+
wireValidationCount += 1;
|
|
778
|
+
return checkDeclaration(copyRestricted(raw, path), path, declaration, identityMode);
|
|
779
|
+
}
|
|
780
|
+
export function toWireValue(raw, path, declaration) {
|
|
781
|
+
return readWireValue(raw, path, declaration, 'check');
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Reads a value a host supplies into a typed slot: a context root, a dataset column or an
|
|
785
|
+
* option domain.
|
|
786
|
+
*
|
|
787
|
+
* A value whose domain is not the declared one is the host's bug, so it earns the catchable
|
|
788
|
+
* `LATE_BOUND_TYPE_MISMATCH` with both domains instead of the generic wire refusal. The check
|
|
789
|
+
* is the top-level shape only: a value of the right domain with a wrong spelling keeps the
|
|
790
|
+
* specific canonical, date or measurement refusal it already had.
|
|
791
|
+
*/
|
|
792
|
+
export function toHostWireValue(raw, path, declaration) {
|
|
793
|
+
if (outsideDeclaredShape(raw, declaration)) {
|
|
794
|
+
throw new LateBoundTypeMismatch(path, declaredDomainOf(declaration), receivedDomainOf(raw));
|
|
795
|
+
}
|
|
796
|
+
return toWireValue(raw, path, declaration);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Reads a session boundary, leaving value-identity duplicates outside other arrays to
|
|
800
|
+
* `SessionIdentity`, which returns the structured `ROW_KEY_DUPLICATE` and offending key. Rows
|
|
801
|
+
* inside another array still check locally because v1 has no composite session key for them.
|
|
802
|
+
*/
|
|
803
|
+
export function toSessionWireValue(raw, path, declaration) {
|
|
804
|
+
return readWireValue(raw, path, declaration, 'defer');
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* The wire values this process has validated.
|
|
808
|
+
*
|
|
809
|
+
* A measurement hook, never an input: no decision reads it. Like
|
|
810
|
+
* `restrictedCanonicalizations`, it exists so a benchmark and a counted budget test can state how
|
|
811
|
+
* much of a pass re-derives a value the record already holds, instead of asserting a wall-clock
|
|
812
|
+
* duration, which is not a property of the code. Its reader is published on
|
|
813
|
+
* `@azx-pbc/axiom-runtime/testing`; the host doors state no counter.
|
|
814
|
+
*/
|
|
815
|
+
let wireValidationCount = 0;
|
|
816
|
+
/** The number of canonical wire values validated since the process started. */
|
|
817
|
+
export function wireValidations() {
|
|
818
|
+
return wireValidationCount;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* A host-supplied reference (`redacted`, `sessionWrites`), validated so a report cannot be
|
|
822
|
+
* built from a member the artifact never declared.
|
|
823
|
+
*/
|
|
824
|
+
export function toFieldRef(raw, path) {
|
|
825
|
+
const ref = expectRecord(raw, path, 'field reference');
|
|
826
|
+
checkMembers(ref, path, ['fieldId'], ['rowKey']);
|
|
827
|
+
const fieldId = checkIdentifier(ref['fieldId'], `${path}.fieldId`, 'fieldId');
|
|
828
|
+
const rowKey = checkRowKey(ref['rowKey'], `${path}.rowKey`);
|
|
829
|
+
return rowKey === undefined ? { fieldId } : { fieldId, rowKey };
|
|
830
|
+
}
|
|
831
|
+
/** A host-supplied access entry. */
|
|
832
|
+
export function toAccessEntry(raw, path) {
|
|
833
|
+
const entry = expectRecord(raw, path, 'access entry');
|
|
834
|
+
checkMembers(entry, path, ['fieldId', 'access'], ['rowKey']);
|
|
835
|
+
const fieldId = checkIdentifier(entry['fieldId'], `${path}.fieldId`, 'fieldId');
|
|
836
|
+
const rowKey = checkRowKey(entry['rowKey'], `${path}.rowKey`);
|
|
837
|
+
const ref = rowKey === undefined ? { fieldId } : { fieldId, rowKey };
|
|
838
|
+
const access = entry['access'];
|
|
839
|
+
switch (access) {
|
|
840
|
+
case 'read_write':
|
|
841
|
+
case 'read_only':
|
|
842
|
+
case 'write_only':
|
|
843
|
+
case 'masked':
|
|
844
|
+
case 'hidden':
|
|
845
|
+
return { ...ref, access };
|
|
846
|
+
default:
|
|
847
|
+
return refuse(path, 'access must be one of read_write, read_only, write_only, masked, hidden');
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* A host-supplied gate override, read into the closed `GateOverride` shape.
|
|
852
|
+
*
|
|
853
|
+
* Axiom never approves an override: the record arrives from the host's approval step, so it
|
|
854
|
+
* is read here like any other untrusted input — undeclared members, a missing one, a hash that
|
|
855
|
+
* is not a digest, and an actor that is empty or not well-formed text are each refused with the
|
|
856
|
+
* path that names them. An approval-state member is undeclared, so a record that states one is
|
|
857
|
+
* refused rather than read as the engine's verdict. The value returned is this reader's own
|
|
858
|
+
* frozen record, so a host that keeps writing to its copy cannot rewrite a decision a report
|
|
859
|
+
* already binds.
|
|
860
|
+
*/
|
|
861
|
+
export function toGateOverride(raw, path) {
|
|
862
|
+
const record = expectRecord(raw, path, 'a gate override');
|
|
863
|
+
checkMembers(record, path, ['gateId', 'actor', 'reasonCode', 'inputHash', 'ruleHash', 'behaviorHash'], []);
|
|
864
|
+
const gateId = checkIdentifier(record['gateId'], `${path}.gateId`, 'gateId');
|
|
865
|
+
const actor = checkActor(record['actor'], `${path}.actor`);
|
|
866
|
+
const reasonCode = checkCode(record['reasonCode'], `${path}.reasonCode`, 'reasonCode');
|
|
867
|
+
const inputHash = checkDigest(record['inputHash'], `${path}.inputHash`, 'inputHash');
|
|
868
|
+
const ruleHash = checkDigest(record['ruleHash'], `${path}.ruleHash`, 'ruleHash');
|
|
869
|
+
const behaviorHash = checkDigest(record['behaviorHash'], `${path}.behaviorHash`, 'behaviorHash');
|
|
870
|
+
return Object.freeze({
|
|
871
|
+
gateId,
|
|
872
|
+
actor,
|
|
873
|
+
reasonCode,
|
|
874
|
+
inputHash,
|
|
875
|
+
ruleHash,
|
|
876
|
+
behaviorHash,
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
/** Text that names the human an approval came from: non-empty and well-formed UTF-16. */
|
|
880
|
+
function checkActor(value, path) {
|
|
881
|
+
const text = expectText(value, path, 'actor');
|
|
882
|
+
if (text.trim() === '')
|
|
883
|
+
refuse(path, 'actor must not be empty');
|
|
884
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
885
|
+
const code = text.charCodeAt(index);
|
|
886
|
+
if (code < 0xd800 || code > 0xdfff)
|
|
887
|
+
continue;
|
|
888
|
+
const next = text.charCodeAt(index + 1);
|
|
889
|
+
const paired = code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff;
|
|
890
|
+
if (!paired)
|
|
891
|
+
refuse(path, 'actor must not carry an unpaired surrogate');
|
|
892
|
+
index += 1;
|
|
893
|
+
}
|
|
894
|
+
return text;
|
|
895
|
+
}
|
|
896
|
+
/** A SHA-256 digest as the report and the approval both spell it. */
|
|
897
|
+
function checkDigest(value, path, what) {
|
|
898
|
+
const text = expectText(value, path, what);
|
|
899
|
+
if (!SHA256_HEX_PATTERN.test(text))
|
|
900
|
+
refuse(path, `${what} must be a lower-case SHA-256 digest`);
|
|
901
|
+
return text;
|
|
902
|
+
}
|
|
903
|
+
/** Each member of a host-supplied list, read by the same rules a single entry is. */
|
|
904
|
+
function toList(value, path, what, read) {
|
|
905
|
+
if (!Array.isArray(value))
|
|
906
|
+
refuse(path, `${what} must be an array`);
|
|
907
|
+
const items = value;
|
|
908
|
+
return items.map((item, index) => read(item, `${path}[${String(index)}]`));
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Refuses an access overlay and a flattened projection supplied together.
|
|
912
|
+
*
|
|
913
|
+
* The two are alternatives rather than a precedence order, so a call that states both has one
|
|
914
|
+
* stale answer and no reader can tell which. The access window states the same refusal at the
|
|
915
|
+
* same path, so a caller that reaches either boundary sees one fault with one spelling.
|
|
916
|
+
*/
|
|
917
|
+
function refuseAccessPair(overlay, access, path) {
|
|
918
|
+
if (overlay !== undefined && access !== undefined) {
|
|
919
|
+
refuse(path, 'an evaluation supplies either an access overlay or a flattened access projection, never both');
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Reads a request document into the evaluator's input contract. A host that
|
|
924
|
+
* stores or replays a projection — a corpus vector, a persisted record — hands over the same
|
|
925
|
+
* closed shape the evaluator validates at its own boundary, so the reader composes those
|
|
926
|
+
* checks instead of stating a second, weaker set that could drift from them.
|
|
927
|
+
*
|
|
928
|
+
* This reader admits every member the projection can carry, including the host's access answer
|
|
929
|
+
* and the server's context. It is therefore for a *stored or constructed* record, not for an
|
|
930
|
+
* untrusted body: `toSubmissionInput` is the door a client's request crosses, and it refuses
|
|
931
|
+
* those members by name.
|
|
932
|
+
*/
|
|
933
|
+
export function toEvaluationInput(value) {
|
|
934
|
+
const source = expectRecord(value, '$', 'an evaluation input');
|
|
935
|
+
checkMembers(source, '$', ['values'], ['context', 'overlay', 'access', 'redacted', 'sessionWrites']);
|
|
936
|
+
const context = source['context'];
|
|
937
|
+
const overlay = source['overlay'];
|
|
938
|
+
const access = source['access'];
|
|
939
|
+
const redacted = source['redacted'];
|
|
940
|
+
const sessionWrites = source['sessionWrites'];
|
|
941
|
+
// The pair is refused before either is parsed: a TypeScript caller cannot state it, so this is
|
|
942
|
+
// the JavaScript caller's refusal.
|
|
943
|
+
refuseAccessPair(overlay, access, '$.access');
|
|
944
|
+
const parsedOverlay = overlay === undefined ? undefined : toAccessOverlay(overlay, '$.overlay');
|
|
945
|
+
const parsedAccess = access === undefined ? undefined : toList(access, '$.access', 'access', toAccessEntry);
|
|
946
|
+
return evaluationInputOf({
|
|
947
|
+
values: expectRecord(source['values'], '$.values', 'values'),
|
|
948
|
+
...(context === undefined ? {} : { context: expectRecord(context, '$.context', 'context') }),
|
|
949
|
+
...(redacted === undefined
|
|
950
|
+
? {}
|
|
951
|
+
: { redacted: toList(redacted, '$.redacted', 'redacted', toFieldRef) }),
|
|
952
|
+
...(sessionWrites === undefined
|
|
953
|
+
? {}
|
|
954
|
+
: { sessionWrites: toList(sessionWrites, '$.sessionWrites', 'sessionWrites', toFieldRef) }),
|
|
955
|
+
}, parsedAccessOf(parsedOverlay, parsedAccess));
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* The members only the host may state about a submission, named so the refusal names them.
|
|
959
|
+
*
|
|
960
|
+
* A generic "undeclared member" would leave a host debugging why a client's overlay was ignored
|
|
961
|
+
* when the right answer is that a client may never send one.
|
|
962
|
+
*/
|
|
963
|
+
const HOST_ONLY_SUBMISSION_MEMBERS = [
|
|
964
|
+
'context',
|
|
965
|
+
'overlay',
|
|
966
|
+
'access',
|
|
967
|
+
'redacted',
|
|
968
|
+
'sessionWrites',
|
|
969
|
+
];
|
|
970
|
+
/**
|
|
971
|
+
* The authority is the typed value the host already holds, but JavaScript can pass anything.
|
|
972
|
+
* Every member read below assumes an object, and `Object.hasOwn` on `null` is a bare `TypeError`,
|
|
973
|
+
* so the door refuses a non-object with the member it names.
|
|
974
|
+
*/
|
|
975
|
+
function expectAuthority(authority) {
|
|
976
|
+
if (!isRecord(authority))
|
|
977
|
+
refuse('authority', 'a submission authority must be an object');
|
|
978
|
+
return authority;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Every member `SubmissionAuthority` states, beside the one it refuses by name.
|
|
982
|
+
*
|
|
983
|
+
* The set is read by the boundary reader, so a JavaScript caller's stale or misspelt member is
|
|
984
|
+
* refused rather than ignored — the authority decides what the door may trust, and an unread
|
|
985
|
+
* member is a trust the caller believes it stated.
|
|
986
|
+
*/
|
|
987
|
+
const AUTHORITY_MEMBERS = new Set([
|
|
988
|
+
'context',
|
|
989
|
+
'overlay',
|
|
990
|
+
'access',
|
|
991
|
+
'redacted',
|
|
992
|
+
'sessionWrites',
|
|
993
|
+
'heldValues',
|
|
994
|
+
'lookup',
|
|
995
|
+
'values',
|
|
996
|
+
]);
|
|
997
|
+
/**
|
|
998
|
+
* Reads the body of an untrusted submission, and the authority only its host may state.
|
|
999
|
+
*
|
|
1000
|
+
* A submission body is the record and nothing else. The access overlay, the hydrated context,
|
|
1001
|
+
* the withheld references and the session's own writes decide the questions the record is
|
|
1002
|
+
* judged by; reading them from the same untrusted document would let the caller state both the
|
|
1003
|
+
* record and the answer. So the body is closed to those five members — each refused by name
|
|
1004
|
+
* with its path — and the host passes them as the second argument, where they are already the
|
|
1005
|
+
* typed value it holds rather than something a caller could have written.
|
|
1006
|
+
*
|
|
1007
|
+
* `values` is the one member the body carries, and it is still untrusted: the door applies
|
|
1008
|
+
* `toEvaluationRecord` against the artifact after this reader returns, so a value the wire
|
|
1009
|
+
* cannot carry is refused at `$.values.<fieldId>` exactly as the export refuses it. The
|
|
1010
|
+
* authority may not state `values` — it is the record, not a host answer — and a JavaScript
|
|
1011
|
+
* caller that supplies it is refused at `authority.values` rather than silently getting the
|
|
1012
|
+
* body's record.
|
|
1013
|
+
*
|
|
1014
|
+
* A host that holds a stored projection rather than an HTTP body reads it through
|
|
1015
|
+
* `toEvaluationInput`, which admits every member because a stored projection is not an
|
|
1016
|
+
* authority claim by an untrusted caller.
|
|
1017
|
+
*/
|
|
1018
|
+
export function toSubmissionInput(value, authority = {}) {
|
|
1019
|
+
const source = expectRecord(value, '$', 'a submission body');
|
|
1020
|
+
for (const member of HOST_ONLY_SUBMISSION_MEMBERS) {
|
|
1021
|
+
if (Object.hasOwn(source, member)) {
|
|
1022
|
+
refuse(`$.${member}`, `\`${member}\` is the host's answer about this submission, never a member of its body`);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
checkMembers(source, '$', ['values'], []);
|
|
1026
|
+
const host = expectAuthority(authority);
|
|
1027
|
+
// The authority is a closed shape too. Reading a member it does not state is how a typo
|
|
1028
|
+
// (`heldValue`, `redact`) becomes a host fact the door silently ignores; naming it here makes
|
|
1029
|
+
// the caller's own path the repair.
|
|
1030
|
+
for (const key of Object.keys(host)) {
|
|
1031
|
+
if (!AUTHORITY_MEMBERS.has(key)) {
|
|
1032
|
+
refuse('authority', `undeclared member ${JSON.stringify(key)}`);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
// `values` is the one member a *host* cannot state about a submission: the record travels in
|
|
1036
|
+
// the body, and reading a second record from here would answer with values the caller did not
|
|
1037
|
+
// submit. The type refuses it, but a JavaScript caller can still build the member, so the door
|
|
1038
|
+
// refuses it by name rather than destructuring it away.
|
|
1039
|
+
if (Object.hasOwn(host, 'values')) {
|
|
1040
|
+
refuse('authority.values', '`values` is the submission record, never a member of the authority; this door reads the record from the body alone');
|
|
1041
|
+
}
|
|
1042
|
+
if (host.heldValues !== undefined) {
|
|
1043
|
+
expectRecord(host.heldValues, 'authority.heldValues', 'heldValues');
|
|
1044
|
+
}
|
|
1045
|
+
const { context, overlay, access, redacted, sessionWrites } = host;
|
|
1046
|
+
refuseAccessPair(overlay, access, 'authority.access');
|
|
1047
|
+
const parsedOverlay = overlay === undefined ? undefined : toAccessOverlay(overlay, 'authority.overlay');
|
|
1048
|
+
const parsedAccess = access === undefined ? undefined : toList(access, 'authority.access', 'access', toAccessEntry);
|
|
1049
|
+
// The authority is read by the same readers as a stored projection, and each one builds a
|
|
1050
|
+
// fresh list or record: the success arm promises the input the report was decided from, so a
|
|
1051
|
+
// host that keeps writing to the value it passed must not rewrite that input underneath the
|
|
1052
|
+
// report — and a JavaScript caller's malformed authority is refused at `authority.<member>`
|
|
1053
|
+
// rather than reaching the evaluator as a typed value it never checked.
|
|
1054
|
+
return evaluationInputOf({
|
|
1055
|
+
values: expectRecord(source['values'], '$.values', 'values'),
|
|
1056
|
+
...(context === undefined
|
|
1057
|
+
? {}
|
|
1058
|
+
: { context: expectRecord(context, 'authority.context', 'context') }),
|
|
1059
|
+
...(redacted === undefined
|
|
1060
|
+
? {}
|
|
1061
|
+
: { redacted: toList(redacted, 'authority.redacted', 'redacted', toFieldRef) }),
|
|
1062
|
+
...(sessionWrites === undefined
|
|
1063
|
+
? {}
|
|
1064
|
+
: {
|
|
1065
|
+
sessionWrites: toList(sessionWrites, 'authority.sessionWrites', 'sessionWrites', toFieldRef),
|
|
1066
|
+
}),
|
|
1067
|
+
}, parsedAccessOf(parsedOverlay, parsedAccess));
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* The four methods a resolution port must answer, `LookupPort` in `model/types.ts`.
|
|
1071
|
+
*
|
|
1072
|
+
* The type is erased where the library ships, so a JavaScript host's port is a plain object
|
|
1073
|
+
* until something calls it. Naming the members here lets the door refuse the partial port
|
|
1074
|
+
* rather than letting the first `lookup` call fail with `port.resolve is not a function` deep
|
|
1075
|
+
* inside a rule.
|
|
1076
|
+
*/
|
|
1077
|
+
const LOOKUP_PORT_METHODS = ['contains', 'resolve', 'decide', 'decideKeys'];
|
|
1078
|
+
/**
|
|
1079
|
+
* Reads a host's resolution port, refusing a partial one before any rule can call it.
|
|
1080
|
+
*
|
|
1081
|
+
* Every required member is checked, and the optional `columns` capability is checked when it is
|
|
1082
|
+
* stated: a port is a behaviour the host holds, so the value is returned untouched (identity is
|
|
1083
|
+
* what makes a per-pass memo and an outcome's `env` name the same store), while a missing or
|
|
1084
|
+
* non-callable member is refused with its own path. Members are read through the prototype, so a
|
|
1085
|
+
* class instance such as `MemoryLookupStore` is admitted exactly as an object literal is.
|
|
1086
|
+
*
|
|
1087
|
+
* The cast is the one fact TypeScript cannot state: the member checks in this function are the
|
|
1088
|
+
* proof that the value answers the interface, and rebuilding the object would break identity.
|
|
1089
|
+
*/
|
|
1090
|
+
export function toLookupPort(value, path = '$.lookup') {
|
|
1091
|
+
// A function is callable *and* may carry members, so it is a structurally valid port too; the
|
|
1092
|
+
// type does not refuse one, and this reader must not invent a refusal the type does not state.
|
|
1093
|
+
if ((typeof value !== 'object' && typeof value !== 'function') ||
|
|
1094
|
+
value === null ||
|
|
1095
|
+
Array.isArray(value)) {
|
|
1096
|
+
refuse(path, 'a lookup port must be an object');
|
|
1097
|
+
}
|
|
1098
|
+
const port = value;
|
|
1099
|
+
for (const member of LOOKUP_PORT_METHODS) {
|
|
1100
|
+
if (typeof Reflect.get(port, member) !== 'function') {
|
|
1101
|
+
refuse(`${path}.${member}`, `a lookup port must implement ${member}()`);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const columns = Reflect.get(port, 'columns');
|
|
1105
|
+
if (columns !== undefined && typeof columns !== 'function') {
|
|
1106
|
+
refuse(`${path}.columns`, 'a lookup port states columns() as a function or omits it');
|
|
1107
|
+
}
|
|
1108
|
+
return port;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Reads the tier and overlay version an evaluation runs under, and carries the host's table port.
|
|
1112
|
+
*
|
|
1113
|
+
* `accessVersion` is bounded like the report member it becomes, so a value the report could not
|
|
1114
|
+
* carry is refused here rather than after the evaluation has run. The document is the environment
|
|
1115
|
+
* as JSON, so a `lookup` member in it is refused like any other undeclared member: a resolution
|
|
1116
|
+
* port is a behaviour, not a value a document can state. A host that holds one passes it as the
|
|
1117
|
+
* second argument, and this reader carries that exact object into the environment, where the
|
|
1118
|
+
* evaluator and the outcome's `env` read the same port.
|
|
1119
|
+
*
|
|
1120
|
+
* The port is read through `toLookupPort` first: a partial object is refused at
|
|
1121
|
+
* `<lookupPath>.<member>` here, at the door, instead of failing inside the first rule that
|
|
1122
|
+
* resolves a table. `lookupPath` names where the caller supplied it — the environment member for
|
|
1123
|
+
* a direct call, `authority.lookup` for a submission's host facts.
|
|
1124
|
+
*/
|
|
1125
|
+
export function toEvaluationEnv(value, lookup, lookupPath = '$.lookup') {
|
|
1126
|
+
const source = expectRecord(value, '$', 'an evaluation environment');
|
|
1127
|
+
checkMembers(source, '$', [], ['tier', 'accessVersion', 'capabilities', 'recordDate']);
|
|
1128
|
+
const tier = source['tier'];
|
|
1129
|
+
if (tier !== undefined && !isTier(tier)) {
|
|
1130
|
+
refuse('$.tier', `tier must be ${TIER_CHOICES}`);
|
|
1131
|
+
}
|
|
1132
|
+
const accessVersion = source['accessVersion'];
|
|
1133
|
+
const boundedVersion = accessVersion === undefined ? undefined : asAccessVersion(accessVersion);
|
|
1134
|
+
const capabilities = source['capabilities'];
|
|
1135
|
+
const recordDate = source['recordDate'];
|
|
1136
|
+
if (recordDate !== undefined) {
|
|
1137
|
+
if (typeof recordDate !== 'string')
|
|
1138
|
+
refuse('$.recordDate', 'recordDate must be a string');
|
|
1139
|
+
// The same civil-date parse the data-bound lookup path uses: a date the table cannot
|
|
1140
|
+
// resolve is refused at the boundary rather than at the first `in_set` call.
|
|
1141
|
+
parsePlainDate(recordDate, '$.recordDate');
|
|
1142
|
+
}
|
|
1143
|
+
return {
|
|
1144
|
+
...(tier === undefined ? {} : { tier }),
|
|
1145
|
+
...(boundedVersion === undefined ? {} : { accessVersion: boundedVersion }),
|
|
1146
|
+
...(capabilities === undefined
|
|
1147
|
+
? {}
|
|
1148
|
+
: { capabilities: toList(capabilities, '$.capabilities', 'capabilities', expectTextItem) }),
|
|
1149
|
+
...(recordDate === undefined ? {} : { recordDate }),
|
|
1150
|
+
...(lookup === undefined ? {} : { lookup: toLookupPort(lookup, lookupPath) }),
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
/** A list member read as text, so a capability flag is never a coerced value. */
|
|
1154
|
+
function expectTextItem(value, path) {
|
|
1155
|
+
return expectText(value, path, 'a capability name');
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* The data form of one boundary error.
|
|
1159
|
+
*
|
|
1160
|
+
* `AxiomError.message` is `"<detail> at <path>"` (and the bare detail when the path is empty),
|
|
1161
|
+
* so the suffix is stripped rather than the message being re-parsed: a detail that itself ends
|
|
1162
|
+
* in ` at …` is left alone because the suffix removed is exactly the one the constructor added.
|
|
1163
|
+
*/
|
|
1164
|
+
export function refusalOf(error) {
|
|
1165
|
+
const suffix = error.path === '' ? '' : ` at ${error.path}`;
|
|
1166
|
+
const detail = suffix !== '' && error.message.endsWith(suffix)
|
|
1167
|
+
? error.message.slice(0, error.message.length - suffix.length)
|
|
1168
|
+
: error.message;
|
|
1169
|
+
return { code: error.code, path: error.path, detail };
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Reads a record's members against the artifact's declarations, for an untrusted submission.
|
|
1173
|
+
*
|
|
1174
|
+
* Every declared field the record holds is validated by the same reader the evaluator and the
|
|
1175
|
+
* submission projection use (`toWireValue`), at `$.values.<fieldId>`, so a body the export would
|
|
1176
|
+
* refuse is refused here with the same code and the same path. Two decisions are worth stating:
|
|
1177
|
+
*
|
|
1178
|
+
* - A member the artifact does not declare is refused. The record is the form's data, not a bag
|
|
1179
|
+
* a caller may extend, and a value nothing can read is exactly the evidence a boundary exists
|
|
1180
|
+
* to reject. (A record that predates a schema version belongs to `upcastRecord`, which names
|
|
1181
|
+
* the version it reads, and never to this door.)
|
|
1182
|
+
* - A field the record does not hold is left absent rather than invented, so "not carried" and
|
|
1183
|
+
* "carried as empty" stay the two different facts the model states.
|
|
1184
|
+
*/
|
|
1185
|
+
export function toEvaluationRecord(compiled, values, path = '$.values') {
|
|
1186
|
+
const declarations = new Map(compiled.fields.map((field) => [field.fieldId, field]));
|
|
1187
|
+
const checked = {};
|
|
1188
|
+
for (const [fieldId, value] of Object.entries(values)) {
|
|
1189
|
+
const declaration = declarations.get(fieldId);
|
|
1190
|
+
const at = `${path}.${fieldId}`;
|
|
1191
|
+
if (declaration === undefined) {
|
|
1192
|
+
refuse(at, `the artifact declares no field \`${fieldId}\`; a submission carries the fields this artifact declares`);
|
|
1193
|
+
}
|
|
1194
|
+
setOwn(checked, fieldId, toWireValue(value, at, wireDeclarationOf(declaration)));
|
|
1195
|
+
}
|
|
1196
|
+
return checked;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* The key a context record supplies a declared root by: its path without the `context.` prefix.
|
|
1200
|
+
*
|
|
1201
|
+
* The reader indexes a declared root by that stripped path (`eval/reader/declarations.ts`), and a
|
|
1202
|
+
* record supplies it under exactly that key; the two must agree or a correct document reads as
|
|
1203
|
+
* absent. The engine's own context reader strips the same prefix, so this is the same rule.
|
|
1204
|
+
*/
|
|
1205
|
+
function contextRootKey(path) {
|
|
1206
|
+
return path.replace(/^context\./, '');
|
|
1207
|
+
}
|
|
1208
|
+
/** The declared root keys a context record may carry, in code-point order. */
|
|
1209
|
+
function declaredContextKeys(compiled) {
|
|
1210
|
+
const keys = new Set();
|
|
1211
|
+
for (const root of compiled.context?.roots ?? []) {
|
|
1212
|
+
const key = contextRootKey(root.path);
|
|
1213
|
+
// A reserved root is supplied by the environment, and the reader's index lets the reserved
|
|
1214
|
+
// entry win over a declaration the compiler would never have emitted. A record carrying one
|
|
1215
|
+
// is refused by name below rather than silently ignored.
|
|
1216
|
+
if (!isReservedContextRoot(key))
|
|
1217
|
+
keys.add(key);
|
|
1218
|
+
}
|
|
1219
|
+
return [...keys].sort(compareCodePoints);
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Why one undeclared context key is not a declared root, naming the root it probably meant.
|
|
1223
|
+
*
|
|
1224
|
+
* The reported defect is a record keyed `policy` for a declared root `policy.exposure_cap`: the
|
|
1225
|
+
* reader looks up the whole path, so the nested value supplied nothing and every rule that read
|
|
1226
|
+
* the root reported `UNKNOWN` with no cause. The nested case therefore names the declared path
|
|
1227
|
+
* and says how a record supplies it, so the fix is in the message rather than in a re-read.
|
|
1228
|
+
*/
|
|
1229
|
+
function undeclaredContextDetail(key, declared) {
|
|
1230
|
+
const nested = declared.filter((root) => root.startsWith(`${key}.`));
|
|
1231
|
+
const only = nested[0];
|
|
1232
|
+
if (only !== undefined) {
|
|
1233
|
+
const names = nested.map((root) => `\`${root}\``).join(', ');
|
|
1234
|
+
return `the artifact declares ${names}; a context record keys a root by its whole path, so supply ${JSON.stringify(only)} as a key rather than nesting \`${key}\``;
|
|
1235
|
+
}
|
|
1236
|
+
if (declared.length === 0) {
|
|
1237
|
+
return `the artifact declares no context root, so a context record cannot supply \`${key}\``;
|
|
1238
|
+
}
|
|
1239
|
+
return `the artifact declares no context root \`${key}\`; a context record carries only the roots this artifact declares`;
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Reads a declared context record against the roots an artifact declares, `toEvaluationContext()`.
|
|
1243
|
+
*
|
|
1244
|
+
* A context record is a flat map from a declared root's path, without the `context.` prefix, to
|
|
1245
|
+
* its value. A host that supplies the value nested under the path's first segment (`{ policy: {
|
|
1246
|
+
* exposure_cap: 5000000 } }` for a root `policy.exposure_cap`) supplies no value the engine can
|
|
1247
|
+
* read: the reader looks the whole path up as one key, finds nothing, and a required root then
|
|
1248
|
+
* reads `UNKNOWN` — a state indistinguishable from "the connector has not answered yet". Every
|
|
1249
|
+
* rule that read it, and every gate that folded those rules, became `UNKNOWN` with no diagnostic
|
|
1250
|
+
* naming the cause. This reader refuses the undeclared key by name, at `$.context.<key>`, with
|
|
1251
|
+
* the declared root the key probably meant.
|
|
1252
|
+
*
|
|
1253
|
+
* **A declared root that is absent is not refused.** `CTX-2.1.4` defines that answer: a required
|
|
1254
|
+
* root the host has not supplied reads `UNKNOWN`, an optional one reads absent, and the report
|
|
1255
|
+
* names the rules that depend on it (`inspectDeps` names the roots). That is a definite answer
|
|
1256
|
+
* for an intermediate state — a connector may legitimately answer later — and refusing it would
|
|
1257
|
+
* break incremental hydration. The two states are now distinguishable: a wrong *shape* is a
|
|
1258
|
+
* refusal at the boundary, while a root the host has not supplied yet is the `UNKNOWN` verdict
|
|
1259
|
+
* the contract promises.
|
|
1260
|
+
*
|
|
1261
|
+
* A reserved root (`record_date`, `schema_version`) is supplied by the environment, so a record
|
|
1262
|
+
* that states one is refused rather than silently ignored. The record is copied, so a caller that
|
|
1263
|
+
* keeps writing to the object it passed cannot change the context the evaluation reads.
|
|
1264
|
+
*
|
|
1265
|
+
* `path` names the door the record arrived on. A submission's context travels on `authority`, not
|
|
1266
|
+
* on the body, so a refusal that said `$.context` would point at a member the caller never sent.
|
|
1267
|
+
*/
|
|
1268
|
+
export function toEvaluationContext(compiled, value, path = '$.context') {
|
|
1269
|
+
if (value === undefined)
|
|
1270
|
+
return undefined;
|
|
1271
|
+
const source = expectRecord(value, path, 'context');
|
|
1272
|
+
const declared = declaredContextKeys(compiled);
|
|
1273
|
+
const known = new Set(declared);
|
|
1274
|
+
const checked = {};
|
|
1275
|
+
for (const [key, entry] of Object.entries(source)) {
|
|
1276
|
+
if (isReservedContextRoot(key)) {
|
|
1277
|
+
refuse(`${path}.${key}`, `\`${key}\` is supplied by the environment, never by a context record`);
|
|
1278
|
+
}
|
|
1279
|
+
if (!known.has(key))
|
|
1280
|
+
refuse(`${path}.${key}`, undeclaredContextDetail(key, declared));
|
|
1281
|
+
setOwn(checked, key, entry);
|
|
1282
|
+
}
|
|
1283
|
+
return checked;
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* The lists an evaluation entry walks before it decides anything, and the noun a refusal names
|
|
1287
|
+
* one of their entries by.
|
|
1288
|
+
*/
|
|
1289
|
+
const ARTIFACT_MEMBER_LISTS = [
|
|
1290
|
+
['fields', 'field'],
|
|
1291
|
+
['rules', 'rule'],
|
|
1292
|
+
['layout', 'layout'],
|
|
1293
|
+
['datasets', 'dataset'],
|
|
1294
|
+
];
|
|
1295
|
+
/** A refusal from the artifact receipt, stated as data with the member it names. */
|
|
1296
|
+
function artifactRefusal(path, detail) {
|
|
1297
|
+
return { code: 'ENGINE_ERROR', path, detail };
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* How a refusal spells the scalar it read, without repeating a structure.
|
|
1301
|
+
*
|
|
1302
|
+
* `JSON.stringify` would run a `toJSON` the artifact carries and would throw on a cycle, which is
|
|
1303
|
+
* a second untrusted-code path inside the check that exists to refuse untrusted artifacts. A
|
|
1304
|
+
* scalar is spelled as JSON so `"2"` stays distinct from `2`; anything else is named by class,
|
|
1305
|
+
* which is all an operator needs to know the storage is wrong.
|
|
1306
|
+
*/
|
|
1307
|
+
function spellArtifactMember(value) {
|
|
1308
|
+
switch (typeof value) {
|
|
1309
|
+
case 'string':
|
|
1310
|
+
return JSON.stringify(value);
|
|
1311
|
+
case 'number':
|
|
1312
|
+
case 'boolean':
|
|
1313
|
+
case 'bigint':
|
|
1314
|
+
return String(value);
|
|
1315
|
+
case 'undefined':
|
|
1316
|
+
return 'nothing';
|
|
1317
|
+
case 'object':
|
|
1318
|
+
return value === null ? 'null' : Array.isArray(value) ? 'a list' : 'an object';
|
|
1319
|
+
case 'function':
|
|
1320
|
+
case 'symbol':
|
|
1321
|
+
return `a ${typeof value}`;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* An own member of an artifact, read as data.
|
|
1326
|
+
*
|
|
1327
|
+
* `Object.hasOwn` is the existence test, so a member installed on a prototype is never read as
|
|
1328
|
+
* the document's own, and the plain-object check that runs first means the value read afterwards
|
|
1329
|
+
* is a data property rather than an accessor.
|
|
1330
|
+
*/
|
|
1331
|
+
function ownArtifactMember(artifact, member) {
|
|
1332
|
+
return Object.hasOwn(artifact, member) ? Reflect.get(artifact, member) : undefined;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* The receipt an artifact document must satisfy, or `undefined` when it does.
|
|
1336
|
+
*
|
|
1337
|
+
* The checks are the ones every evaluation entry already applies through
|
|
1338
|
+
* `assertArtifactReceipt` (`eval/receipt.ts`): the root is an object, the one version this build
|
|
1339
|
+
* implements is stated, the identifier and version are present, every list an entry walks is a
|
|
1340
|
+
* list of objects, and the two enumerated root members name a member of their vocabulary. The
|
|
1341
|
+
* evaluator's copy throws because its caller is a programmer error; this copy returns the facts
|
|
1342
|
+
* because its caller rehydrated a document it did not construct.
|
|
1343
|
+
*/
|
|
1344
|
+
function artifactProblems(value) {
|
|
1345
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
1346
|
+
return artifactRefusal('$', 'the artifact is not an object');
|
|
1347
|
+
}
|
|
1348
|
+
// A document is data. A class instance, a synthetic prototype or a prototype-less record is
|
|
1349
|
+
// still readable, but only the last two are documents: an inherited member would let a value
|
|
1350
|
+
// the loader never read decide a receipt fact.
|
|
1351
|
+
const prototype = prototypeOf(value);
|
|
1352
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1353
|
+
return artifactRefusal('$', 'the artifact is not a plain object');
|
|
1354
|
+
}
|
|
1355
|
+
// The restricted profile's own object rule: a symbol key, an accessor or a non-enumerable
|
|
1356
|
+
// member is outside a document, and an own callable `toJSON` makes the value code rather than
|
|
1357
|
+
// data. Asking the one function the canonical copier asks keeps the two boundaries in step.
|
|
1358
|
+
const shape = objectShapeViolation(value);
|
|
1359
|
+
if (shape !== undefined)
|
|
1360
|
+
return artifactRefusal('$', `the artifact carries ${shape}`);
|
|
1361
|
+
const artifact = value;
|
|
1362
|
+
const exprVersion = ownArtifactMember(artifact, 'exprVersion');
|
|
1363
|
+
if (exprVersion !== 1) {
|
|
1364
|
+
return artifactRefusal('$.exprVersion', exprVersion === undefined
|
|
1365
|
+
? 'the artifact states no exprVersion; this runtime implements 1'
|
|
1366
|
+
: `the artifact states exprVersion ${spellArtifactMember(exprVersion)}; this runtime implements 1`);
|
|
1367
|
+
}
|
|
1368
|
+
if (typeof ownArtifactMember(artifact, 'schemaId') !== 'string') {
|
|
1369
|
+
return artifactRefusal('$.schemaId', 'the artifact states no schemaId');
|
|
1370
|
+
}
|
|
1371
|
+
const schemaVersion = ownArtifactMember(artifact, 'schemaVersion');
|
|
1372
|
+
if (typeof schemaVersion !== 'number' || !Number.isSafeInteger(schemaVersion)) {
|
|
1373
|
+
return artifactRefusal('$.schemaVersion', 'the artifact states no integer schemaVersion');
|
|
1374
|
+
}
|
|
1375
|
+
// A zero or negative edition is not one any compiler can emit. Reading it as the edition the
|
|
1376
|
+
// report names would make the answer claim a `schemaVersion` no authority ever issued.
|
|
1377
|
+
if (schemaVersion < 1) {
|
|
1378
|
+
return artifactRefusal('$.schemaVersion', `the artifact states schemaVersion ${spellArtifactMember(schemaVersion)}; this runtime reads a positive safe integer`);
|
|
1379
|
+
}
|
|
1380
|
+
// The artifact is closed, and the runtime proves it rather than trusting the compiler's
|
|
1381
|
+
// metaschema: an unknown root member may be behaviour a later release added, and evaluating
|
|
1382
|
+
// around it would answer a question the artifact did not ask.
|
|
1383
|
+
const knownMembers = new Set(ARTIFACT_ROOT_MEMBERS);
|
|
1384
|
+
for (const member of Object.keys(artifact)) {
|
|
1385
|
+
if (knownMembers.has(member))
|
|
1386
|
+
continue;
|
|
1387
|
+
return artifactRefusal(`$.${member}`, `the artifact carries ${spellArtifactMember(member)}, which exprVersion 1 does not declare`);
|
|
1388
|
+
}
|
|
1389
|
+
// The producer stamp answers package skew. An artifact produced by a newer release may carry
|
|
1390
|
+
// members or semantics this build does not implement, so it is refused with both versions
|
|
1391
|
+
// named instead of evaluated against the members that happen to be recognised.
|
|
1392
|
+
const producerVersion = ownArtifactMember(artifact, 'producerVersion');
|
|
1393
|
+
if (producerVersion !== undefined) {
|
|
1394
|
+
if (typeof producerVersion !== 'string' || !isVersionText(producerVersion)) {
|
|
1395
|
+
return artifactRefusal('$.producerVersion', `the artifact states producerVersion ${spellArtifactMember(producerVersion)}; this runtime reads a release version`);
|
|
1396
|
+
}
|
|
1397
|
+
// Both sides were just proven versions: `isVersionText` above, and `AXIOM_VERSION` is a
|
|
1398
|
+
// literal this module imports. `compareVersions` returns `undefined` only when a side does
|
|
1399
|
+
// not parse, so that arm is unreachable here; treating it as "not newer" would fail open on
|
|
1400
|
+
// a violated invariant, so it throws instead.
|
|
1401
|
+
const precedence = compareVersions(producerVersion, AXIOM_VERSION);
|
|
1402
|
+
if (precedence === undefined) {
|
|
1403
|
+
throw new AxiomError('ENGINE_ERROR', `producerVersion ${producerVersion} or this runtime's ${AXIOM_VERSION} is not a release version; both were just checked, so this is a violated invariant`, '$.producerVersion');
|
|
1404
|
+
}
|
|
1405
|
+
if (precedence > 0) {
|
|
1406
|
+
return artifactRefusal('$.producerVersion', `the artifact was produced by Axiom ${producerVersion}, which is newer than this runtime's ${AXIOM_VERSION}; this runtime cannot evaluate it`);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
const fields = ownArtifactMember(artifact, 'fields');
|
|
1410
|
+
if (!Array.isArray(fields)) {
|
|
1411
|
+
return artifactRefusal('$.fields', 'the artifact states no field list');
|
|
1412
|
+
}
|
|
1413
|
+
for (const [member, entry] of ARTIFACT_MEMBER_LISTS) {
|
|
1414
|
+
const list = member === 'fields' ? fields : ownArtifactMember(artifact, member);
|
|
1415
|
+
if (list === undefined)
|
|
1416
|
+
continue;
|
|
1417
|
+
if (!Array.isArray(list)) {
|
|
1418
|
+
return artifactRefusal(`$.${member}`, `the artifact states ${member} as ${spellArtifactMember(list)}; this runtime reads a list`);
|
|
1419
|
+
}
|
|
1420
|
+
for (const [index, item] of list.entries()) {
|
|
1421
|
+
if (isRecord(item))
|
|
1422
|
+
continue;
|
|
1423
|
+
return artifactRefusal(`$.${member}[${String(index)}]`, `the artifact states a ${entry} entry that is ${spellArtifactMember(item)}; this runtime reads an object`);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
// The tier-pairing refusal reads the target to tell a device artifact from a server one, so a
|
|
1427
|
+
// misspelling must be refused rather than silently read as the server default — whose
|
|
1428
|
+
// server-tier rules would then be credited from stubs.
|
|
1429
|
+
const target = ownArtifactMember(artifact, 'target');
|
|
1430
|
+
if (target !== undefined && !isTier(target)) {
|
|
1431
|
+
return artifactRefusal('$.target', `the artifact states a target outside the two tiers: ${spellArtifactMember(target)}`);
|
|
1432
|
+
}
|
|
1433
|
+
// Every hiding decision compares this member to `exclude`, so a misspelling would be read as
|
|
1434
|
+
// `preserve` and a hidden value the author meant to drop would travel in the submission.
|
|
1435
|
+
const onHide = ownArtifactMember(artifact, 'onHide');
|
|
1436
|
+
if (onHide !== undefined && onHide !== 'preserve' && onHide !== 'exclude') {
|
|
1437
|
+
return artifactRefusal('$.onHide', `the artifact states onHide ${spellArtifactMember(onHide)}; this runtime implements "preserve" or "exclude"`);
|
|
1438
|
+
}
|
|
1439
|
+
// The composition is copied into every report verbatim, so a malformed one would seal a
|
|
1440
|
+
// version report the artifact never meant. It is checked before evaluation rather than at
|
|
1441
|
+
// assembly, where a report cannot refuse.
|
|
1442
|
+
const composition = ownArtifactMember(artifact, 'composition');
|
|
1443
|
+
if (composition !== undefined && !isCompositionReport(composition)) {
|
|
1444
|
+
const outside = isRecord(composition) ? compositionMemberOutside(composition) : undefined;
|
|
1445
|
+
return artifactRefusal('$.composition', outside === undefined
|
|
1446
|
+
? 'the artifact states a composition that is not an ordered list of named overlay editions'
|
|
1447
|
+
: `the artifact states composition member \`${outside}\`, which the composition contract does not declare`);
|
|
1448
|
+
}
|
|
1449
|
+
return undefined;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Reads a rehydrated artifact into the runtime's own contract, `readArtifact()`.
|
|
1453
|
+
*
|
|
1454
|
+
* This is the door for a document a loader parsed — `JSON.parse(...)`, a fixture module, a store
|
|
1455
|
+
* that kept bytes — and it is the one place a value becomes a `CompiledSchema` without a cast in
|
|
1456
|
+
* the host. A tagged outcome rather than a throw, because rehydrating storage is an expected
|
|
1457
|
+
* failure: a host that gets `ok: false` renders or discards one document, and one that gets an
|
|
1458
|
+
* exception has no branch for it.
|
|
1459
|
+
*
|
|
1460
|
+
* **What it proves.** The facts this runtime's own entries depend on before they read an
|
|
1461
|
+
* artifact — the same receipt `assertArtifactReceipt` applies in `eval/receipt.ts`: the root is a
|
|
1462
|
+
* plain object, `exprVersion` is the one version this build implements, `schemaId` is text,
|
|
1463
|
+
* `schemaVersion` is a safe integer, `fields` is present as a list, every list an entry walks
|
|
1464
|
+
* (`fields`, `rules`, `layout`, `datasets`) is a list of objects, `target` names a tier and
|
|
1465
|
+
* `onHide` names a hiding policy when the document states them. A value an accessor, symbol key,
|
|
1466
|
+
* non-enumerable member, `toJSON` method or foreign prototype makes a document only by
|
|
1467
|
+
* inheritance is refused with the same words, and never by running its code. The success arm
|
|
1468
|
+
* carries the value it was given rather than a copy, so the digest a host pinned still covers it.
|
|
1469
|
+
*
|
|
1470
|
+
* **What it does not prove.** The compiler's closed-document validation, and nothing here claims
|
|
1471
|
+
* to. A field's primitive, a rule's expression, a layout node's text and a message's nodes are
|
|
1472
|
+
* the metaschema's, which the runtime cannot run without pulling the compiler onto a device; a
|
|
1473
|
+
* re-validating copy here would be a second metaschema that drifts. Those nested declarations are
|
|
1474
|
+
* bound to what the compiler emitted by the artifact's digest when the host admits the document
|
|
1475
|
+
* through its cache door (`verifyArtifactHash`, `admitOfflineArtifact`), and re-derived by each
|
|
1476
|
+
* contract downstream. **An unknown root member is refused.** The runtime carries the closed root
|
|
1477
|
+
* list (`ARTIFACT_ROOT_MEMBERS` in `model/artifact-members.ts`, typed against `CompiledSchema`),
|
|
1478
|
+
* because the type is erased at run time and a member a later release added to change behaviour
|
|
1479
|
+
* would otherwise be ignored: that is a wrong answer rather than a diagnosable refusal. The list
|
|
1480
|
+
* is the runtime's own copy of the root contract, not the compiler's metaschema; a root member
|
|
1481
|
+
* added to one and not the other fails typecheck or its contract test.
|
|
1482
|
+
*/
|
|
1483
|
+
export function readArtifact(value) {
|
|
1484
|
+
let refusal;
|
|
1485
|
+
try {
|
|
1486
|
+
refusal = artifactProblems(value);
|
|
1487
|
+
}
|
|
1488
|
+
catch {
|
|
1489
|
+
// A document is data. An object whose own traps throw — a `Proxy`, an exotic host object —
|
|
1490
|
+
// is not one this runtime can read, and a rehydration door answers that as data rather than
|
|
1491
|
+
// letting a value the caller handed in escape as an exception.
|
|
1492
|
+
return {
|
|
1493
|
+
ok: false,
|
|
1494
|
+
refusal: artifactRefusal('$', 'the artifact is not a value this runtime can read'),
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
if (refusal !== undefined)
|
|
1498
|
+
return { ok: false, refusal };
|
|
1499
|
+
// The receipt facts above are what `CompiledSchema` promises this runtime. The assertion
|
|
1500
|
+
// records that proof; it is the one place a rehydrated document becomes the type, and it says
|
|
1501
|
+
// nothing about the nested declarations the receipt leaves to the compiler and the digest.
|
|
1502
|
+
return { ok: true, artifact: value };
|
|
1503
|
+
}
|
|
1504
|
+
//# sourceMappingURL=wire.js.map
|