@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.5
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 +1210 -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,280 @@
|
|
|
1
|
+
import { assertNever, AxiomError } from '../model/errors.js';
|
|
2
|
+
import { MAX_DECIMAL_EXPONENT } from './decimal.js';
|
|
3
|
+
import { cardinalCategory } from './plural.js';
|
|
4
|
+
import { catalogueEntry, resolveSchemaLocale } from './select-locale.js';
|
|
5
|
+
export { cardinalCategory } from './plural.js';
|
|
6
|
+
/** A parameter by name, from the message's own arguments only. */
|
|
7
|
+
function paramOf(params, name) {
|
|
8
|
+
// A catalogued message is data, so `params[name]` must not walk a prototype: an argument
|
|
9
|
+
// called `constructor` would otherwise resolve to a function and be rendered as text.
|
|
10
|
+
return Object.hasOwn(params, name) ? params[name] : undefined;
|
|
11
|
+
}
|
|
12
|
+
function decimalText(value, name) {
|
|
13
|
+
if (typeof value === 'number') {
|
|
14
|
+
if (!Number.isFinite(value)) {
|
|
15
|
+
throw new AxiomError('ENGINE_ERROR', `message argument \`${name}\` must be a finite number; \`Infinity\` and \`NaN\` cannot be rendered`);
|
|
16
|
+
}
|
|
17
|
+
return String(value);
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'string')
|
|
20
|
+
return value;
|
|
21
|
+
throw new AxiomError('ENGINE_ERROR', `message argument \`${name}\` must be text or a decimal; a list, a record or any other value cannot be interpolated`);
|
|
22
|
+
}
|
|
23
|
+
function textParam(value, name) {
|
|
24
|
+
if (typeof value === 'boolean')
|
|
25
|
+
return value ? 'true' : 'false';
|
|
26
|
+
return decimalText(value, name);
|
|
27
|
+
}
|
|
28
|
+
function selectBranch(cases, key) {
|
|
29
|
+
const branch = Object.hasOwn(cases, key) ? cases[key] : cases['other'];
|
|
30
|
+
if (branch === undefined) {
|
|
31
|
+
// Rendering nothing would turn an invalid catalogue into a shorter safety message.
|
|
32
|
+
throw new AxiomError('ENGINE_ERROR', `message branch ${JSON.stringify(key)} has no \`other\``);
|
|
33
|
+
}
|
|
34
|
+
return branch;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The integer amount a count spelling names, when it names one exactly, as comparable text.
|
|
38
|
+
*
|
|
39
|
+
* A plural's `=n` keys are integers, so an exact branch can only match a count whose amount is
|
|
40
|
+
* that integer. ICU compares amounts rather than spellings: the count `1.0` and the key `=1`
|
|
41
|
+
* name one amount even though `1.0` is not canonical decimal text — while the *category* still
|
|
42
|
+
* reads that visible fraction digit (`pl` puts `1.0` in `other`). Digit runs are compared as
|
|
43
|
+
* text so an amount beyond 2^53 keeps every digit, which a numeric compare would round.
|
|
44
|
+
*/
|
|
45
|
+
function integerAmount(text) {
|
|
46
|
+
const match = /^(-?)([0-9]+)(?:\.([0-9]*))?$/.exec(text);
|
|
47
|
+
if (match === null)
|
|
48
|
+
return undefined;
|
|
49
|
+
const [, sign, whole = '', fraction] = match;
|
|
50
|
+
if (fraction !== undefined && /[1-9]/.test(fraction))
|
|
51
|
+
return undefined;
|
|
52
|
+
const digits = whole.replace(/^0+(?=[0-9])/, '');
|
|
53
|
+
// `-0` is the amount zero, so the sign belongs to the digits rather than beside them.
|
|
54
|
+
return digits === '0' ? '0' : `${sign ?? ''}${digits}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The `=n` branch whose amount equals `count`.
|
|
58
|
+
*
|
|
59
|
+
* The key is a spelling, so `=1` and a count of `1.0` name the same amount: compare amounts
|
|
60
|
+
* rather than the text, or an exact branch silently falls through to a category.
|
|
61
|
+
*/
|
|
62
|
+
function exactBranch(cases, count) {
|
|
63
|
+
const direct = Object.hasOwn(cases, `=${count}`) ? cases[`=${count}`] : undefined;
|
|
64
|
+
if (direct !== undefined)
|
|
65
|
+
return direct;
|
|
66
|
+
// A count that names no integer cannot equal an integer key, and a canonical spelling of one
|
|
67
|
+
// it can has already been found above; every remaining match needs the amount compared.
|
|
68
|
+
const amount = integerAmount(count);
|
|
69
|
+
if (amount === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
for (const [key, branch] of Object.entries(cases)) {
|
|
72
|
+
if (!key.startsWith('='))
|
|
73
|
+
continue;
|
|
74
|
+
if (integerAmount(key.slice(1)) === amount)
|
|
75
|
+
return branch;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A message count spelling: the canonical grammar with one difference — the fraction may end in
|
|
81
|
+
* zeros.
|
|
82
|
+
*
|
|
83
|
+
* ICU selects a plural branch from the count's visible fraction digits (`pl` puts `1` in `one`
|
|
84
|
+
* and `1.0` in `other`), so a count is not canonical decimal text and the canonical constructor
|
|
85
|
+
* must not judge it. Nothing else is optional: no leading zeros, no exponent, no bare point, and
|
|
86
|
+
* a sign only on a non-zero amount.
|
|
87
|
+
*/
|
|
88
|
+
const MESSAGE_COUNT_PATTERN = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
|
|
89
|
+
/**
|
|
90
|
+
* Admits a message count, or refuses its spelling.
|
|
91
|
+
*
|
|
92
|
+
* This is the one admission every plural path passes through, before the exact branch and
|
|
93
|
+
* whether or not an offset applies: `01` must not reach `exactBranch`, whose amount comparison
|
|
94
|
+
* would otherwise take `=1`, and `abc` must not be rendered as a keyword count. The width bound
|
|
95
|
+
* is the arithmetic budget `expr/decimal.ts` exports, so a count and an operand cannot disagree
|
|
96
|
+
* about how wide a value the engine carries.
|
|
97
|
+
*/
|
|
98
|
+
function assertMessageCount(count, name) {
|
|
99
|
+
if (!MESSAGE_COUNT_PATTERN.test(count) || /^-0(?:\.0+)?$/.test(count)) {
|
|
100
|
+
throw new AxiomError('ENGINE_ERROR', `not a decimal message count: ${count}`, name, 'not a decimal message count');
|
|
101
|
+
}
|
|
102
|
+
const unsigned = count.startsWith('-') ? count.slice(1) : count;
|
|
103
|
+
const point = unsigned.indexOf('.');
|
|
104
|
+
const whole = point === -1 ? unsigned.length : point;
|
|
105
|
+
const fraction = point === -1 ? 0 : unsigned.length - point - 1;
|
|
106
|
+
if (whole <= MAX_DECIMAL_EXPONENT && fraction <= MAX_DECIMAL_EXPONENT)
|
|
107
|
+
return;
|
|
108
|
+
throw new AxiomError('ENGINE_ERROR', `message count exceeds ${String(MAX_DECIMAL_EXPONENT)} digits before or after the point`, name);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* `count - offset`, in a spelling that keeps the visible fraction digits canonical text drops.
|
|
112
|
+
*
|
|
113
|
+
* `#` renders the count minus the offset and the plural rule selects on it, so `1.0` with
|
|
114
|
+
* `offset:1` must select on and render `0.0` — not canonicalise to `0`, and not throw because
|
|
115
|
+
* `0.0` has a trailing-zero fraction. The subtraction is exact integer arithmetic over the
|
|
116
|
+
* count's own scale, so a count beyond 2^53 keeps every digit. A negative result keeps the
|
|
117
|
+
* fraction width too: `0.5` with `offset:1` is `-0.5`, never a rounded `-1` or a bare `-0`.
|
|
118
|
+
*
|
|
119
|
+
* The count has already been admitted by `assertMessageCount`; this function only subtracts, so
|
|
120
|
+
* admission and subtraction answer from one grammar.
|
|
121
|
+
*/
|
|
122
|
+
function offsetCountText(count, offset, name) {
|
|
123
|
+
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
124
|
+
throw new AxiomError('ENGINE_ERROR', `plural offset is not a non-negative integer: ${String(offset)}`, name);
|
|
125
|
+
}
|
|
126
|
+
const negative = count.startsWith('-');
|
|
127
|
+
const unsigned = negative ? count.slice(1) : count;
|
|
128
|
+
const point = unsigned.indexOf('.');
|
|
129
|
+
const whole = point === -1 ? unsigned : unsigned.slice(0, point);
|
|
130
|
+
const fraction = point === -1 ? '' : unsigned.slice(point + 1);
|
|
131
|
+
const scale = fraction.length;
|
|
132
|
+
const units = BigInt(`${whole}${fraction}`);
|
|
133
|
+
const adjusted = (negative ? -units : units) - BigInt(offset) * 10n ** BigInt(scale);
|
|
134
|
+
const magnitude = (adjusted < 0n ? -adjusted : adjusted).toString().padStart(scale + 1, '0');
|
|
135
|
+
const wholeText = magnitude.slice(0, magnitude.length - scale);
|
|
136
|
+
const fractionText = magnitude.slice(magnitude.length - scale);
|
|
137
|
+
const text = scale === 0 ? wholeText : `${wholeText}.${fractionText}`;
|
|
138
|
+
return adjusted < 0n ? `-${text}` : text;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Refusal for a placeholder whose argument was not supplied.
|
|
142
|
+
*
|
|
143
|
+
* Subclasses `AxiomError` so `detail` keeps the actionable placeholder name while host fallbacks
|
|
144
|
+
* can branch on the structured `reason` discriminator rather than matching prose.
|
|
145
|
+
*/
|
|
146
|
+
class MissingMessageArgumentError extends AxiomError {
|
|
147
|
+
reason = 'missing_message_argument';
|
|
148
|
+
argumentName;
|
|
149
|
+
constructor(name) {
|
|
150
|
+
super('ENGINE_ERROR', `the message uses \`{${name}}\`, but no argument named \`${name}\` was supplied; pass it in the message params`);
|
|
151
|
+
this.argumentName = name;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** The refusal for an absent message argument, keeping the placeholder name in `detail`. */
|
|
155
|
+
function missingArgument(name) {
|
|
156
|
+
return new MissingMessageArgumentError(name);
|
|
157
|
+
}
|
|
158
|
+
function renderNodes(nodes, locale, params, pound) {
|
|
159
|
+
let text = '';
|
|
160
|
+
for (const node of nodes) {
|
|
161
|
+
switch (node.kind) {
|
|
162
|
+
case 'content':
|
|
163
|
+
text += node.value;
|
|
164
|
+
break;
|
|
165
|
+
case 'argument': {
|
|
166
|
+
const value = paramOf(params, node.name);
|
|
167
|
+
if (value === undefined)
|
|
168
|
+
throw missingArgument(node.name);
|
|
169
|
+
text += textParam(value, node.name);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case 'pound':
|
|
173
|
+
if (pound === undefined) {
|
|
174
|
+
throw new AxiomError('ENGINE_ERROR', 'message uses # outside a plural branch');
|
|
175
|
+
}
|
|
176
|
+
text += pound;
|
|
177
|
+
break;
|
|
178
|
+
case 'select': {
|
|
179
|
+
const value = paramOf(params, node.name);
|
|
180
|
+
if (value === undefined)
|
|
181
|
+
throw missingArgument(node.name);
|
|
182
|
+
text += renderNodes(selectBranch(node.cases, textParam(value, node.name)), locale, params, pound);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case 'plural': {
|
|
186
|
+
const value = paramOf(params, node.name);
|
|
187
|
+
if (value === undefined)
|
|
188
|
+
throw missingArgument(node.name);
|
|
189
|
+
const count = decimalText(value, node.name);
|
|
190
|
+
// One admission, before the exact branch and whether or not an offset applies: the
|
|
191
|
+
// exact comparison would otherwise read `01` as the amount one, and a count is not
|
|
192
|
+
// canonical decimal text (`1.0` is a valid count).
|
|
193
|
+
assertMessageCount(count, node.name);
|
|
194
|
+
// ICU MF1: an explicit `=n` key matches the original count, before the offset. Deciding
|
|
195
|
+
// it first is what lets `1.0` take the `=1` branch: the adjusted spelling `0.0` is a
|
|
196
|
+
// visible-fraction count, not canonical decimal text, and must never be validated as
|
|
197
|
+
// such. The keyword branch is then chosen by the plural category of the count minus the
|
|
198
|
+
// offset, which is also what `#` renders.
|
|
199
|
+
const exact = exactBranch(node.cases, count);
|
|
200
|
+
const adjusted = node.offset === 0 ? count : offsetCountText(count, node.offset, node.name);
|
|
201
|
+
const branch = exact ?? node.cases[cardinalCategory(locale, adjusted)] ?? node.cases['other'];
|
|
202
|
+
if (branch === undefined) {
|
|
203
|
+
throw new AxiomError('ENGINE_ERROR', `message plural ${JSON.stringify(node.name)} has no \`other\` branch`);
|
|
204
|
+
}
|
|
205
|
+
text += renderNodes(branch, locale, params, adjusted);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
default:
|
|
209
|
+
assertNever(node);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return text;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The locale a message renders in.
|
|
216
|
+
*
|
|
217
|
+
* A message carries the catalogue key it was compiled for, so a renderer that forwards an
|
|
218
|
+
* entry needs to pass nothing; an AST a host assembled itself carries none and has to be given
|
|
219
|
+
* one. Both at once is a contradiction rather than a preference: the two locales select
|
|
220
|
+
* different plural branches (`pt` puts 0 in `one`, `pt-PT` in `other`), so choosing the
|
|
221
|
+
* caller's would render one locale's text with another's grammar and say nothing about it.
|
|
222
|
+
*/
|
|
223
|
+
function localeOf(message, locale) {
|
|
224
|
+
const carried = message.locale;
|
|
225
|
+
if (carried === undefined) {
|
|
226
|
+
if (locale === undefined) {
|
|
227
|
+
throw new AxiomError('ENGINE_ERROR', 'formatMessage needs a locale: the message carries none, and a host must name the catalogue key it was compiled for');
|
|
228
|
+
}
|
|
229
|
+
return locale;
|
|
230
|
+
}
|
|
231
|
+
if (locale !== undefined && locale !== carried) {
|
|
232
|
+
throw new AxiomError('ENGINE_ERROR', `formatMessage was given locale \`${locale}\` for a message compiled for \`${carried}\`; render the entry's own catalogue key, or compile the text for the locale you mean`);
|
|
233
|
+
}
|
|
234
|
+
return carried;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Renders a compiled message. Parameters are canonical values; a value Axiom cannot format
|
|
238
|
+
* without `Intl` (a money object, a date) is refused, because the host owns display formatting
|
|
239
|
+
* and the engine must not invent one.
|
|
240
|
+
*
|
|
241
|
+
* The locale is the **resolved catalogue key**, never the host's requested tag: `pt` text
|
|
242
|
+
* ruled by `pt-PT` takes the wrong plural branch, and no entry exists under the request. A
|
|
243
|
+
* message compiled from a catalogue states that key, so passing nothing is the route that
|
|
244
|
+
* cannot get it wrong; a locale passed beside a different carried one is refused rather than
|
|
245
|
+
* silently preferred. A host with a preference to resolve calls `formatCatalogueMessage`.
|
|
246
|
+
*/
|
|
247
|
+
export function formatMessage(message, locale, params = {}) {
|
|
248
|
+
return renderNodes(message.nodes, localeOf(message, locale), params, undefined);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Renders the catalogue entry for `key` that `requested` selects.
|
|
252
|
+
*
|
|
253
|
+
* This is the call a renderer should make: it resolves the request to a declared catalogue
|
|
254
|
+
* key and renders that entry with that key, so the text and the plural rules always belong to
|
|
255
|
+
* the same locale. `pt-PT` against a catalogue carrying `pt` renders the `pt` entry under `pt`
|
|
256
|
+
* rules; the requested tag itself is never handed to the formatter.
|
|
257
|
+
*
|
|
258
|
+
* An artifact the compiler produced always answers: every named key resolves, and every
|
|
259
|
+
* declared locale has an entry. A key, locale or entry that is absent is a compiler bug rather
|
|
260
|
+
* than data, so it is refused instead of rendering nothing.
|
|
261
|
+
*/
|
|
262
|
+
export function formatCatalogueMessage(schema, key, requested, params = {}) {
|
|
263
|
+
const entry = catalogueEntry(schema, key);
|
|
264
|
+
if (entry === undefined) {
|
|
265
|
+
throw new AxiomError('ENGINE_ERROR', `message key ${JSON.stringify(key)} is not in the catalogue; a compiled document resolves every message key it names`);
|
|
266
|
+
}
|
|
267
|
+
const resolution = resolveSchemaLocale(schema, requested);
|
|
268
|
+
if (!resolution.ok) {
|
|
269
|
+
throw new AxiomError('ENGINE_ERROR', `no catalogue locale answers ${requested === undefined ? 'the document default' : JSON.stringify(requested)}: ${resolution.reason}`);
|
|
270
|
+
}
|
|
271
|
+
const message = Object.hasOwn(entry, resolution.locale) ? entry[resolution.locale] : undefined;
|
|
272
|
+
if (message === undefined) {
|
|
273
|
+
throw new AxiomError('ENGINE_ERROR', `message ${JSON.stringify(key)} has no \`${resolution.locale}\` entry, and the resolution selected it; a compiled catalogue states every declared locale`);
|
|
274
|
+
}
|
|
275
|
+
if (typeof message === 'string') {
|
|
276
|
+
throw new AxiomError('ENGINE_ERROR', `message ${JSON.stringify(key)} entry \`${resolution.locale}\` is authored source text, not a compiled message; a runtime never parses message text`);
|
|
277
|
+
}
|
|
278
|
+
return formatMessage(message, resolution.locale, params);
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/expr/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA6B/C,kEAAkE;AAClE,SAAS,OAAO,CACd,MAA8C,EAC9C,IAAY;IAEZ,yFAAyF;IACzF,sFAAsF;IACtF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC;AAED,SAAS,WAAW,CAAC,KAAmB,EAAE,IAAY;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,sBAAsB,IAAI,yEAAyE,CACpG,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,IAAI,UA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MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,+BACE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAC7E,KAAK,UAAU,CAAC,MAAM,EAAE,CACzB,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/F,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,WAAW,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,UAAU,CAAC,MAAM,6FAA6F,CAC1J,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,WAAW,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,UAAU,CAAC,MAAM,yFAAyF,CACrJ,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { assertNever, AxiomError } from '../model/errors.js';\nimport type { CompiledMessage, MessageNode } from '../model/types.js';\nimport { MAX_DECIMAL_EXPONENT } from './decimal.js';\nimport { cardinalCategory } from './plural.js';\nimport { catalogueEntry, resolveSchemaLocale } from './select-locale.js';\nimport type { LocaleCatalogue } from './select-locale.js';\n\nexport { cardinalCategory } from './plural.js';\nexport type { PluralCategory } from './plural.js';\n// `resolveSchemaLocale` is not re-exported here: selection reads the artifact and no CLDR data,\n// so the root entry carries it and a rule-only host never reaches this entry for it. A renderer\n// imports the selector from the root door beside the rendering from this one.\nexport type {\n LocaleCatalogue,\n SchemaLocaleMatch,\n SchemaLocaleOptions,\n SchemaLocaleRefusal,\n SchemaLocaleResolution,\n} from './select-locale.js';\n\n/**\n * Message rendering for the compiled ICU MF1 subset, section 6 of the model spec. This module\n * is the runtime's `./messages` entry: the format-only renderer and the cardinal selector a\n * message needs — and nothing that loads the compiler's category lists. `formatCatalogueMessage`\n * selects its entry through `resolveSchemaLocale`, whose public door is the root entry: selection\n * reads the artifact and no CLDR data, so it must not be reachable only through this heavier one.\n *\n * The compiler parses the authored text once with `@messageformat/parser` and emits a\n * data-only AST; this module folds that AST. Plural categories come from `./plural.js`: the\n * vendored CLDR registry is the contract and the only source, so no host locale database is\n * read and a message renders the same text on every target.\n */\n\n/** A value a message argument may interpolate: a canonical scalar. */\nexport type MessageParam = string | number | boolean;\n\n/** A parameter by name, from the message's own arguments only. */\nfunction paramOf(\n params: Readonly<Record<string, MessageParam>>,\n name: string,\n): MessageParam | undefined {\n // A catalogued message is data, so `params[name]` must not walk a prototype: an argument\n // called `constructor` would otherwise resolve to a function and be rendered as text.\n return Object.hasOwn(params, name) ? params[name] : undefined;\n}\n\nfunction decimalText(value: MessageParam, name: string): string {\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message argument \\`${name}\\` must be a finite number; \\`Infinity\\` and \\`NaN\\` cannot be rendered`,\n );\n }\n return String(value);\n }\n if (typeof value === 'string') return value;\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message argument \\`${name}\\` must be text or a decimal; a list, a record or any other value cannot be interpolated`,\n );\n}\n\nfunction textParam(value: MessageParam, name: string): string {\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n return decimalText(value, name);\n}\n\nfunction selectBranch(\n cases: Readonly<Record<string, readonly MessageNode[]>>,\n key: string,\n): readonly MessageNode[] {\n const branch = Object.hasOwn(cases, key) ? cases[key] : cases['other'];\n if (branch === undefined) {\n // Rendering nothing would turn an invalid catalogue into a shorter safety message.\n throw new AxiomError('ENGINE_ERROR', `message branch ${JSON.stringify(key)} has no \\`other\\``);\n }\n return branch;\n}\n\n/**\n * The integer amount a count spelling names, when it names one exactly, as comparable text.\n *\n * A plural's `=n` keys are integers, so an exact branch can only match a count whose amount is\n * that integer. ICU compares amounts rather than spellings: the count `1.0` and the key `=1`\n * name one amount even though `1.0` is not canonical decimal text — while the *category* still\n * reads that visible fraction digit (`pl` puts `1.0` in `other`). Digit runs are compared as\n * text so an amount beyond 2^53 keeps every digit, which a numeric compare would round.\n */\nfunction integerAmount(text: string): string | undefined {\n const match = /^(-?)([0-9]+)(?:\\.([0-9]*))?$/.exec(text);\n if (match === null) return undefined;\n const [, sign, whole = '', fraction] = match;\n if (fraction !== undefined && /[1-9]/.test(fraction)) return undefined;\n const digits = whole.replace(/^0+(?=[0-9])/, '');\n // `-0` is the amount zero, so the sign belongs to the digits rather than beside them.\n return digits === '0' ? '0' : `${sign ?? ''}${digits}`;\n}\n\n/**\n * The `=n` branch whose amount equals `count`.\n *\n * The key is a spelling, so `=1` and a count of `1.0` name the same amount: compare amounts\n * rather than the text, or an exact branch silently falls through to a category.\n */\nfunction exactBranch(\n cases: Readonly<Record<string, readonly MessageNode[]>>,\n count: string,\n): readonly MessageNode[] | undefined {\n const direct = Object.hasOwn(cases, `=${count}`) ? cases[`=${count}`] : undefined;\n if (direct !== undefined) return direct;\n // A count that names no integer cannot equal an integer key, and a canonical spelling of one\n // it can has already been found above; every remaining match needs the amount compared.\n const amount = integerAmount(count);\n if (amount === undefined) return undefined;\n for (const [key, branch] of Object.entries(cases)) {\n if (!key.startsWith('=')) continue;\n if (integerAmount(key.slice(1)) === amount) return branch;\n }\n return undefined;\n}\n\n/**\n * A message count spelling: the canonical grammar with one difference — the fraction may end in\n * zeros.\n *\n * ICU selects a plural branch from the count's visible fraction digits (`pl` puts `1` in `one`\n * and `1.0` in `other`), so a count is not canonical decimal text and the canonical constructor\n * must not judge it. Nothing else is optional: no leading zeros, no exponent, no bare point, and\n * a sign only on a non-zero amount.\n */\nconst MESSAGE_COUNT_PATTERN: RegExp = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$/;\n\n/**\n * Admits a message count, or refuses its spelling.\n *\n * This is the one admission every plural path passes through, before the exact branch and\n * whether or not an offset applies: `01` must not reach `exactBranch`, whose amount comparison\n * would otherwise take `=1`, and `abc` must not be rendered as a keyword count. The width bound\n * is the arithmetic budget `expr/decimal.ts` exports, so a count and an operand cannot disagree\n * about how wide a value the engine carries.\n */\nfunction assertMessageCount(count: string, name: string): void {\n if (!MESSAGE_COUNT_PATTERN.test(count) || /^-0(?:\\.0+)?$/.test(count)) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `not a decimal message count: ${count}`,\n name,\n 'not a decimal message count',\n );\n }\n const unsigned = count.startsWith('-') ? count.slice(1) : count;\n const point = unsigned.indexOf('.');\n const whole = point === -1 ? unsigned.length : point;\n const fraction = point === -1 ? 0 : unsigned.length - point - 1;\n if (whole <= MAX_DECIMAL_EXPONENT && fraction <= MAX_DECIMAL_EXPONENT) return;\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message count exceeds ${String(MAX_DECIMAL_EXPONENT)} digits before or after the point`,\n name,\n );\n}\n\n/**\n * `count - offset`, in a spelling that keeps the visible fraction digits canonical text drops.\n *\n * `#` renders the count minus the offset and the plural rule selects on it, so `1.0` with\n * `offset:1` must select on and render `0.0` — not canonicalise to `0`, and not throw because\n * `0.0` has a trailing-zero fraction. The subtraction is exact integer arithmetic over the\n * count's own scale, so a count beyond 2^53 keeps every digit. A negative result keeps the\n * fraction width too: `0.5` with `offset:1` is `-0.5`, never a rounded `-1` or a bare `-0`.\n *\n * The count has already been admitted by `assertMessageCount`; this function only subtracts, so\n * admission and subtraction answer from one grammar.\n */\nfunction offsetCountText(count: string, offset: number, name: string): string {\n if (!Number.isSafeInteger(offset) || offset < 0) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `plural offset is not a non-negative integer: ${String(offset)}`,\n name,\n );\n }\n const negative = count.startsWith('-');\n const unsigned = negative ? count.slice(1) : count;\n const point = unsigned.indexOf('.');\n const whole = point === -1 ? unsigned : unsigned.slice(0, point);\n const fraction = point === -1 ? '' : unsigned.slice(point + 1);\n const scale = fraction.length;\n const units = BigInt(`${whole}${fraction}`);\n const adjusted = (negative ? -units : units) - BigInt(offset) * 10n ** BigInt(scale);\n const magnitude = (adjusted < 0n ? -adjusted : adjusted).toString().padStart(scale + 1, '0');\n const wholeText = magnitude.slice(0, magnitude.length - scale);\n const fractionText = magnitude.slice(magnitude.length - scale);\n const text = scale === 0 ? wholeText : `${wholeText}.${fractionText}`;\n return adjusted < 0n ? `-${text}` : text;\n}\n\n/**\n * Refusal for a placeholder whose argument was not supplied.\n *\n * Subclasses `AxiomError` so `detail` keeps the actionable placeholder name while host fallbacks\n * can branch on the structured `reason` discriminator rather than matching prose.\n */\nclass MissingMessageArgumentError extends AxiomError {\n readonly reason = 'missing_message_argument' as const;\n readonly argumentName: string;\n\n constructor(name: string) {\n super(\n 'ENGINE_ERROR',\n `the message uses \\`{${name}}\\`, but no argument named \\`${name}\\` was supplied; pass it in the message params`,\n );\n this.argumentName = name;\n }\n}\n\n/** The refusal for an absent message argument, keeping the placeholder name in `detail`. */\nfunction missingArgument(name: string): AxiomError {\n return new MissingMessageArgumentError(name);\n}\n\nfunction renderNodes(\n nodes: readonly MessageNode[],\n locale: string,\n params: Readonly<Record<string, MessageParam>>,\n pound: string | undefined,\n): string {\n let text = '';\n for (const node of nodes) {\n switch (node.kind) {\n case 'content':\n text += node.value;\n break;\n case 'argument': {\n const value = paramOf(params, node.name);\n if (value === undefined) throw missingArgument(node.name);\n text += textParam(value, node.name);\n break;\n }\n case 'pound':\n if (pound === undefined) {\n throw new AxiomError('ENGINE_ERROR', 'message uses # outside a plural branch');\n }\n text += pound;\n break;\n case 'select': {\n const value = paramOf(params, node.name);\n if (value === undefined) throw missingArgument(node.name);\n text += renderNodes(\n selectBranch(node.cases, textParam(value, node.name)),\n locale,\n params,\n pound,\n );\n break;\n }\n case 'plural': {\n const value = paramOf(params, node.name);\n if (value === undefined) throw missingArgument(node.name);\n const count = decimalText(value, node.name);\n // One admission, before the exact branch and whether or not an offset applies: the\n // exact comparison would otherwise read `01` as the amount one, and a count is not\n // canonical decimal text (`1.0` is a valid count).\n assertMessageCount(count, node.name);\n // ICU MF1: an explicit `=n` key matches the original count, before the offset. Deciding\n // it first is what lets `1.0` take the `=1` branch: the adjusted spelling `0.0` is a\n // visible-fraction count, not canonical decimal text, and must never be validated as\n // such. The keyword branch is then chosen by the plural category of the count minus the\n // offset, which is also what `#` renders.\n const exact = exactBranch(node.cases, count);\n const adjusted = node.offset === 0 ? count : offsetCountText(count, node.offset, node.name);\n const branch =\n exact ?? node.cases[cardinalCategory(locale, adjusted)] ?? node.cases['other'];\n if (branch === undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message plural ${JSON.stringify(node.name)} has no \\`other\\` branch`,\n );\n }\n text += renderNodes(branch, locale, params, adjusted);\n break;\n }\n default:\n assertNever(node);\n }\n }\n return text;\n}\n\n/**\n * The locale a message renders in.\n *\n * A message carries the catalogue key it was compiled for, so a renderer that forwards an\n * entry needs to pass nothing; an AST a host assembled itself carries none and has to be given\n * one. Both at once is a contradiction rather than a preference: the two locales select\n * different plural branches (`pt` puts 0 in `one`, `pt-PT` in `other`), so choosing the\n * caller's would render one locale's text with another's grammar and say nothing about it.\n */\nfunction localeOf(message: CompiledMessage, locale: string | undefined): string {\n const carried = message.locale;\n if (carried === undefined) {\n if (locale === undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n 'formatMessage needs a locale: the message carries none, and a host must name the catalogue key it was compiled for',\n );\n }\n return locale;\n }\n if (locale !== undefined && locale !== carried) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `formatMessage was given locale \\`${locale}\\` for a message compiled for \\`${carried}\\`; render the entry's own catalogue key, or compile the text for the locale you mean`,\n );\n }\n return carried;\n}\n\n/**\n * Renders a compiled message. Parameters are canonical values; a value Axiom cannot format\n * without `Intl` (a money object, a date) is refused, because the host owns display formatting\n * and the engine must not invent one.\n *\n * The locale is the **resolved catalogue key**, never the host's requested tag: `pt` text\n * ruled by `pt-PT` takes the wrong plural branch, and no entry exists under the request. A\n * message compiled from a catalogue states that key, so passing nothing is the route that\n * cannot get it wrong; a locale passed beside a different carried one is refused rather than\n * silently preferred. A host with a preference to resolve calls `formatCatalogueMessage`.\n */\nexport function formatMessage(\n message: CompiledMessage,\n locale?: string,\n params: Readonly<Record<string, MessageParam>> = {},\n): string {\n return renderNodes(message.nodes, localeOf(message, locale), params, undefined);\n}\n\n/**\n * Renders the catalogue entry for `key` that `requested` selects.\n *\n * This is the call a renderer should make: it resolves the request to a declared catalogue\n * key and renders that entry with that key, so the text and the plural rules always belong to\n * the same locale. `pt-PT` against a catalogue carrying `pt` renders the `pt` entry under `pt`\n * rules; the requested tag itself is never handed to the formatter.\n *\n * An artifact the compiler produced always answers: every named key resolves, and every\n * declared locale has an entry. A key, locale or entry that is absent is a compiler bug rather\n * than data, so it is refused instead of rendering nothing.\n */\nexport function formatCatalogueMessage(\n schema: LocaleCatalogue,\n key: string,\n requested: string | undefined,\n params: Readonly<Record<string, MessageParam>> = {},\n): string {\n const entry = catalogueEntry(schema, key);\n if (entry === undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message key ${JSON.stringify(key)} is not in the catalogue; a compiled document resolves every message key it names`,\n );\n }\n\n const resolution = resolveSchemaLocale(schema, requested);\n if (!resolution.ok) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `no catalogue locale answers ${\n requested === undefined ? 'the document default' : JSON.stringify(requested)\n }: ${resolution.reason}`,\n );\n }\n\n const message = Object.hasOwn(entry, resolution.locale) ? entry[resolution.locale] : undefined;\n if (message === undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message ${JSON.stringify(key)} has no \\`${resolution.locale}\\` entry, and the resolution selected it; a compiled catalogue states every declared locale`,\n );\n }\n if (typeof message === 'string') {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `message ${JSON.stringify(key)} entry \\`${resolution.locale}\\` is authored source text, not a compiled message; a runtime never parses message text`,\n );\n }\n return formatMessage(message, resolution.locale, params);\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DecimalString, MoneyValue, RoundingMode } from '../model/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a money value from untrusted input. A money value is the
|
|
4
|
+
* object `{ minor, currency, scale }` and nothing else: a JSON number here would be
|
|
5
|
+
* a float inside a canonical value, so it is refused rather than coerced.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toMoneyValue(value: unknown, path?: string): MoneyValue;
|
|
8
|
+
/**
|
|
9
|
+
* `money_minor`: the minor-unit amount as an exact decimal.
|
|
10
|
+
* All money arithmetic happens on this value, never on the amount as a whole.
|
|
11
|
+
*/
|
|
12
|
+
export declare function moneyMinor(money: MoneyValue, path?: string): DecimalString;
|
|
13
|
+
/**
|
|
14
|
+
* `money_from_minor`: the only conversion from a decimal to money.
|
|
15
|
+
* The rounding mode is required, so an amount is never rounded by a hidden default.
|
|
16
|
+
*/
|
|
17
|
+
export declare function moneyFromMinor(minor: DecimalString, currency: string, scale: number, mode: RoundingMode, path?: string): MoneyValue;
|
|
18
|
+
/**
|
|
19
|
+
* `money` ordering: matching currency and scale, exact integer comparison of the minor amounts.
|
|
20
|
+
* Currency and scale are part of the value, so money that spells the same amount differently
|
|
21
|
+
* never compares at all rather than being coerced.
|
|
22
|
+
*/
|
|
23
|
+
export declare function compareMoney(a: MoneyValue, b: MoneyValue, path?: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* The canonical display text of an amount: its minor units placed at its declared scale,
|
|
26
|
+
* with no currency symbol, grouping or trailing zeros beyond the scale.
|
|
27
|
+
*
|
|
28
|
+
* This is the one formatter: `to_string(money)` and the React binding's `renderValueText`
|
|
29
|
+
* both read it, so an amount a rule composes into a message and the amount a control shows
|
|
30
|
+
* are spelled identically. A currency symbol is the host's decision, so the text carries
|
|
31
|
+
* none; `money_currency` names the code when the text needs it.
|
|
32
|
+
*/
|
|
33
|
+
export declare function moneyAmountText(minor: string, scale: number): string | undefined;
|
|
34
|
+
/** The exact minor-unit sum `+` and `sum` fold: matching currency and scale. */
|
|
35
|
+
export declare function moneyAdd(a: MoneyValue, b: MoneyValue, path?: string): MoneyValue;
|
|
36
|
+
/** The exact minor-unit difference `-` folds: matching currency and scale. */
|
|
37
|
+
export declare function moneySub(a: MoneyValue, b: MoneyValue, path?: string): MoneyValue;
|
|
38
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/expr/money.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOjF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAK,GAAG,UAAU,CAyBlE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,SAAK,GAAG,aAAa,CAGtE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,YAAY,EAClB,IAAI,SAAK,GACR,UAAU,CAYZ;AAkCD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,SAAK,GAAG,MAAM,CAO5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUhF;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,SAAK,GAAG,UAAU,CAE5E;AAED,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,SAAK,GAAG,UAAU,CAE5E"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AxiomError } from '../model/errors.js';
|
|
2
|
+
import { CURRENCY_CODE_PATTERN, INTEGER_TEXT_PATTERN } from '../model/types.js';
|
|
3
|
+
import { isRecord } from '../model/guards.js';
|
|
4
|
+
import { asDecimalString, roundDecimal } from './decimal.js';
|
|
5
|
+
const MAX_SCALE = 6;
|
|
6
|
+
/**
|
|
7
|
+
* Reads a money value from untrusted input. A money value is the
|
|
8
|
+
* object `{ minor, currency, scale }` and nothing else: a JSON number here would be
|
|
9
|
+
* a float inside a canonical value, so it is refused rather than coerced.
|
|
10
|
+
*/
|
|
11
|
+
export function toMoneyValue(value, path = '') {
|
|
12
|
+
if (!isRecord(value)) {
|
|
13
|
+
throw new AxiomError('ENGINE_ERROR', 'money must be an object', path);
|
|
14
|
+
}
|
|
15
|
+
const keys = Object.keys(value).sort();
|
|
16
|
+
if (keys.length !== 3 || keys.join(',') !== 'currency,minor,scale') {
|
|
17
|
+
throw new AxiomError('ENGINE_ERROR', 'money must declare exactly minor, currency and scale', path);
|
|
18
|
+
}
|
|
19
|
+
const { minor, currency, scale } = value;
|
|
20
|
+
if (typeof minor !== 'string' || !INTEGER_TEXT_PATTERN.test(minor)) {
|
|
21
|
+
throw new AxiomError('ENGINE_ERROR', 'money minor must be a canonical integer string', path);
|
|
22
|
+
}
|
|
23
|
+
if (typeof currency !== 'string' || !CURRENCY_CODE_PATTERN.test(currency)) {
|
|
24
|
+
throw new AxiomError('ENGINE_ERROR', 'money currency must be three upper-case letters', path);
|
|
25
|
+
}
|
|
26
|
+
if (typeof scale !== 'number' || !Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
27
|
+
throw new AxiomError('ENGINE_ERROR', `money scale must be an integer 0..${MAX_SCALE}`, path);
|
|
28
|
+
}
|
|
29
|
+
// `-0` is the integer zero with a spelling canonical JSON refuses, so it is normalised
|
|
30
|
+
// rather than carried into a value that must hash.
|
|
31
|
+
return { minor, currency, scale: Object.is(scale, -0) ? 0 : scale };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `money_minor`: the minor-unit amount as an exact decimal.
|
|
35
|
+
* All money arithmetic happens on this value, never on the amount as a whole.
|
|
36
|
+
*/
|
|
37
|
+
export function moneyMinor(money, path = '') {
|
|
38
|
+
const value = toMoneyValue(money, path);
|
|
39
|
+
return asDecimalString(value.minor, path);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `money_from_minor`: the only conversion from a decimal to money.
|
|
43
|
+
* The rounding mode is required, so an amount is never rounded by a hidden default.
|
|
44
|
+
*/
|
|
45
|
+
export function moneyFromMinor(minor, currency, scale, mode, path = '') {
|
|
46
|
+
if (!CURRENCY_CODE_PATTERN.test(currency)) {
|
|
47
|
+
throw new AxiomError('ENGINE_ERROR', 'money currency must be three upper-case letters', path);
|
|
48
|
+
}
|
|
49
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
50
|
+
throw new AxiomError('ENGINE_ERROR', `money scale must be an integer 0..${MAX_SCALE}`, path);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
minor: roundDecimal(minor, 0, mode, path),
|
|
54
|
+
currency,
|
|
55
|
+
scale: Object.is(scale, -0) ? 0 : scale,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function assertSameMoney(a, b, path) {
|
|
59
|
+
if (a.currency !== b.currency || a.scale !== b.scale) {
|
|
60
|
+
throw new AxiomError('ENGINE_ERROR', `money operands differ in currency or scale: ${a.currency}/${String(a.scale)} and ${b.currency}/${String(b.scale)}`, path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** A canonical integer string from an exact integer. Zero is never negative. */
|
|
64
|
+
function minorText(units) {
|
|
65
|
+
return asDecimalString(units === 0n ? '0' : units.toString());
|
|
66
|
+
}
|
|
67
|
+
/** Adds or subtracts two money values in minor units once both are known to match. */
|
|
68
|
+
function combineMoney(a, b, subtract, path) {
|
|
69
|
+
const left = toMoneyValue(a, path);
|
|
70
|
+
const right = toMoneyValue(b, path);
|
|
71
|
+
assertSameMoney(left, right, path);
|
|
72
|
+
// A minor amount is an exact integer, so the arithmetic is integer arithmetic. Routing it
|
|
73
|
+
// through the decimal budget refused a long minor the wire accepted.
|
|
74
|
+
const units = subtract
|
|
75
|
+
? BigInt(left.minor) - BigInt(right.minor)
|
|
76
|
+
: BigInt(left.minor) + BigInt(right.minor);
|
|
77
|
+
return {
|
|
78
|
+
minor: minorText(units),
|
|
79
|
+
currency: left.currency,
|
|
80
|
+
scale: left.scale,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* `money` ordering: matching currency and scale, exact integer comparison of the minor amounts.
|
|
85
|
+
* Currency and scale are part of the value, so money that spells the same amount differently
|
|
86
|
+
* never compares at all rather than being coerced.
|
|
87
|
+
*/
|
|
88
|
+
export function compareMoney(a, b, path = '') {
|
|
89
|
+
const left = toMoneyValue(a, path);
|
|
90
|
+
const right = toMoneyValue(b, path);
|
|
91
|
+
assertSameMoney(left, right, path);
|
|
92
|
+
const leftMinor = BigInt(left.minor);
|
|
93
|
+
const rightMinor = BigInt(right.minor);
|
|
94
|
+
return leftMinor < rightMinor ? -1 : leftMinor > rightMinor ? 1 : 0;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The canonical display text of an amount: its minor units placed at its declared scale,
|
|
98
|
+
* with no currency symbol, grouping or trailing zeros beyond the scale.
|
|
99
|
+
*
|
|
100
|
+
* This is the one formatter: `to_string(money)` and the React binding's `renderValueText`
|
|
101
|
+
* both read it, so an amount a rule composes into a message and the amount a control shows
|
|
102
|
+
* are spelled identically. A currency symbol is the host's decision, so the text carries
|
|
103
|
+
* none; `money_currency` names the code when the text needs it.
|
|
104
|
+
*/
|
|
105
|
+
export function moneyAmountText(minor, scale) {
|
|
106
|
+
if (minor === '-0' || !INTEGER_TEXT_PATTERN.test(minor))
|
|
107
|
+
return undefined;
|
|
108
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE)
|
|
109
|
+
return undefined;
|
|
110
|
+
const sign = minor.startsWith('-') ? '-' : '';
|
|
111
|
+
const digits = sign === '' ? minor : minor.slice(1);
|
|
112
|
+
if (scale === 0)
|
|
113
|
+
return `${sign}${digits}`;
|
|
114
|
+
const padded = digits.padStart(scale + 1, '0');
|
|
115
|
+
const whole = padded.slice(0, padded.length - scale);
|
|
116
|
+
const fraction = padded.slice(padded.length - scale);
|
|
117
|
+
return `${sign}${whole}.${fraction}`;
|
|
118
|
+
}
|
|
119
|
+
/** The exact minor-unit sum `+` and `sum` fold: matching currency and scale. */
|
|
120
|
+
export function moneyAdd(a, b, path = '') {
|
|
121
|
+
return combineMoney(a, b, false, path);
|
|
122
|
+
}
|
|
123
|
+
/** The exact minor-unit difference `-` folds: matching currency and scale. */
|
|
124
|
+
export function moneySub(a, b, path = '') {
|
|
125
|
+
return combineMoney(a, b, true, path);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/expr/money.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE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AAE,GAAG,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;IACrD,OAAO,GAAG,IAAI,GAAG,KAAK,IAAI,QAAQ,EAAE,CAAC;AACvC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,QAAQ,CAAC,CAAa,EAAE,CAAa,EAAE,IAAI,GAAG,EAAE;IAC9D,OAAO,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CAAC,CAAa,EAAE,CAAa,EAAE,IAAI,GAAG,EAAE;IAC9D,OAAO,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { AxiomError } from '../model/errors.js';\nimport type { DecimalString, MoneyValue, RoundingMode } from '../model/types.js';\nimport { CURRENCY_CODE_PATTERN, INTEGER_TEXT_PATTERN } from '../model/types.js';\nimport { isRecord } from '../model/guards.js';\nimport { asDecimalString, roundDecimal } from './decimal.js';\n\nconst MAX_SCALE = 6;\n\n/**\n * Reads a money value from untrusted input. A money value is the\n * object `{ minor, currency, scale }` and nothing else: a JSON number here would be\n * a float inside a canonical value, so it is refused rather than coerced.\n */\nexport function toMoneyValue(value: unknown, path = ''): MoneyValue {\n if (!isRecord(value)) {\n throw new AxiomError('ENGINE_ERROR', 'money must be an object', path);\n }\n const keys = Object.keys(value).sort();\n if (keys.length !== 3 || keys.join(',') !== 'currency,minor,scale') {\n throw new AxiomError(\n 'ENGINE_ERROR',\n 'money must declare exactly minor, currency and scale',\n path,\n );\n }\n const { minor, currency, scale } = value;\n if (typeof minor !== 'string' || !INTEGER_TEXT_PATTERN.test(minor)) {\n throw new AxiomError('ENGINE_ERROR', 'money minor must be a canonical integer string', path);\n }\n if (typeof currency !== 'string' || !CURRENCY_CODE_PATTERN.test(currency)) {\n throw new AxiomError('ENGINE_ERROR', 'money currency must be three upper-case letters', path);\n }\n if (typeof scale !== 'number' || !Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {\n throw new AxiomError('ENGINE_ERROR', `money scale must be an integer 0..${MAX_SCALE}`, path);\n }\n // `-0` is the integer zero with a spelling canonical JSON refuses, so it is normalised\n // rather than carried into a value that must hash.\n return { minor, currency, scale: Object.is(scale, -0) ? 0 : scale };\n}\n\n/**\n * `money_minor`: the minor-unit amount as an exact decimal.\n * All money arithmetic happens on this value, never on the amount as a whole.\n */\nexport function moneyMinor(money: MoneyValue, path = ''): DecimalString {\n const value = toMoneyValue(money, path);\n return asDecimalString(value.minor, path);\n}\n\n/**\n * `money_from_minor`: the only conversion from a decimal to money.\n * The rounding mode is required, so an amount is never rounded by a hidden default.\n */\nexport function moneyFromMinor(\n minor: DecimalString,\n currency: string,\n scale: number,\n mode: RoundingMode,\n path = '',\n): MoneyValue {\n if (!CURRENCY_CODE_PATTERN.test(currency)) {\n throw new AxiomError('ENGINE_ERROR', 'money currency must be three upper-case letters', path);\n }\n if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) {\n throw new AxiomError('ENGINE_ERROR', `money scale must be an integer 0..${MAX_SCALE}`, path);\n }\n return {\n minor: roundDecimal(minor, 0, mode, path),\n currency,\n scale: Object.is(scale, -0) ? 0 : scale,\n };\n}\n\nfunction assertSameMoney(a: MoneyValue, b: MoneyValue, path: string): void {\n if (a.currency !== b.currency || a.scale !== b.scale) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `money operands differ in currency or scale: ${a.currency}/${String(a.scale)} and ${b.currency}/${String(b.scale)}`,\n path,\n );\n }\n}\n\n/** A canonical integer string from an exact integer. Zero is never negative. */\nfunction minorText(units: bigint): DecimalString {\n return asDecimalString(units === 0n ? '0' : units.toString());\n}\n\n/** Adds or subtracts two money values in minor units once both are known to match. */\nfunction combineMoney(a: MoneyValue, b: MoneyValue, subtract: boolean, path: string): MoneyValue {\n const left = toMoneyValue(a, path);\n const right = toMoneyValue(b, path);\n assertSameMoney(left, right, path);\n // A minor amount is an exact integer, so the arithmetic is integer arithmetic. Routing it\n // through the decimal budget refused a long minor the wire accepted.\n const units = subtract\n ? BigInt(left.minor) - BigInt(right.minor)\n : BigInt(left.minor) + BigInt(right.minor);\n return {\n minor: minorText(units),\n currency: left.currency,\n scale: left.scale,\n } satisfies MoneyValue;\n}\n\n/**\n * `money` ordering: matching currency and scale, exact integer comparison of the minor amounts.\n * Currency and scale are part of the value, so money that spells the same amount differently\n * never compares at all rather than being coerced.\n */\nexport function compareMoney(a: MoneyValue, b: MoneyValue, path = ''): number {\n const left = toMoneyValue(a, path);\n const right = toMoneyValue(b, path);\n assertSameMoney(left, right, path);\n const leftMinor = BigInt(left.minor);\n const rightMinor = BigInt(right.minor);\n return leftMinor < rightMinor ? -1 : leftMinor > rightMinor ? 1 : 0;\n}\n\n/**\n * The canonical display text of an amount: its minor units placed at its declared scale,\n * with no currency symbol, grouping or trailing zeros beyond the scale.\n *\n * This is the one formatter: `to_string(money)` and the React binding's `renderValueText`\n * both read it, so an amount a rule composes into a message and the amount a control shows\n * are spelled identically. A currency symbol is the host's decision, so the text carries\n * none; `money_currency` names the code when the text needs it.\n */\nexport function moneyAmountText(minor: string, scale: number): string | undefined {\n if (minor === '-0' || !INTEGER_TEXT_PATTERN.test(minor)) return undefined;\n if (!Number.isInteger(scale) || scale < 0 || scale > MAX_SCALE) return undefined;\n const sign = minor.startsWith('-') ? '-' : '';\n const digits = sign === '' ? minor : minor.slice(1);\n if (scale === 0) return `${sign}${digits}`;\n const padded = digits.padStart(scale + 1, '0');\n const whole = padded.slice(0, padded.length - scale);\n const fraction = padded.slice(padded.length - scale);\n return `${sign}${whole}.${fraction}`;\n}\n\n/** The exact minor-unit sum `+` and `sum` fold: matching currency and scale. */\nexport function moneyAdd(a: MoneyValue, b: MoneyValue, path = ''): MoneyValue {\n return combineMoney(a, b, false, path);\n}\n\n/** The exact minor-unit difference `-` folds: matching currency and scale. */\nexport function moneySub(a: MoneyValue, b: MoneyValue, path = ''): MoneyValue {\n return combineMoney(a, b, true, path);\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { LiteralDomain } from '../model/types.js';
|
|
2
|
+
import type { RuntimeValue } from './builtins.js';
|
|
3
|
+
/**
|
|
4
|
+
* The language's canonical order and equality, stated once over a value together with the
|
|
5
|
+
* domain its artifact declares.
|
|
6
|
+
*
|
|
7
|
+
* The compiled evaluator reads both from `EvaluatedValue`; the value-only door (documentation
|
|
8
|
+
* examples, `applyBuiltin`) receives a value and, where the caller knows it, the literal's
|
|
9
|
+
* declared domain. Sharing the comparison is what keeps the two doors from ordering the same
|
|
10
|
+
* pair differently: an untyped `between(decimal "10", decimal "9", decimal "20")` used to
|
|
11
|
+
* compare `"10"` with `"9"` as code points and answer `false`.
|
|
12
|
+
*/
|
|
13
|
+
/** One value and the domain the artifact states for it, if any. */
|
|
14
|
+
export interface DomainedValue {
|
|
15
|
+
readonly value: RuntimeValue;
|
|
16
|
+
readonly domain: LiteralDomain | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The element domains of a list value, when the producer knew them.
|
|
19
|
+
*
|
|
20
|
+
* A list becomes a plain wire array on the way through `if` or `??`, so without this a
|
|
21
|
+
* comparison would lose the declaration its members were read under and compare them by
|
|
22
|
+
* spelling. `EXPR-6.1.3` unifies `list<integer>` with `list<decimal>` to `list<decimal>`, and
|
|
23
|
+
* `EXPR-10.1.1` makes a computed list compare as a written one does, so the members must keep
|
|
24
|
+
* the domain their producer attached rather than fall back to structural equality.
|
|
25
|
+
*/
|
|
26
|
+
readonly elementDomains?: readonly (LiteralDomain | undefined)[];
|
|
27
|
+
}
|
|
28
|
+
/** A value with no stated domain, for a caller that holds only the value. */
|
|
29
|
+
export declare function domained(value: RuntimeValue): DomainedValue;
|
|
30
|
+
/**
|
|
31
|
+
* Domains whose values order by their canonical text (`date`/`instant` are ISO text).
|
|
32
|
+
*
|
|
33
|
+
* Exported because the compiled evaluator's ordered comparison asks the same question; one set
|
|
34
|
+
* is what keeps the two doors from ordering one pair and refusing its twin.
|
|
35
|
+
*/
|
|
36
|
+
export declare const TEXT_ORDERED: ReadonlySet<LiteralDomain>;
|
|
37
|
+
/**
|
|
38
|
+
* The order two domained values share, or `undefined` when the shared domain has none.
|
|
39
|
+
*
|
|
40
|
+
* Numeric operands compare numerically across `integer`/`decimal` (`EXPR-5.1.10`); every other
|
|
41
|
+
* pair needs one stated domain. Two operands with no stated domain fall back to their shapes —
|
|
42
|
+
* numbers numerically and text by code point — which is what the value-only door has to work
|
|
43
|
+
* with, and never a guess that a string is a number.
|
|
44
|
+
*/
|
|
45
|
+
export declare function compareByDomain(left: DomainedValue, right: DomainedValue, path: string): number | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Equality under the rule: numeric across `integer`/`decimal`, never across domains, and
|
|
48
|
+
* money/quantity/duration by value *and* unit. A list compares element by element under the same
|
|
49
|
+
* rule, keeping each member's element domain when the producer attached one.
|
|
50
|
+
*
|
|
51
|
+
* This is the one language equality. `==` and `!=` in the compiled evaluator reach it through
|
|
52
|
+
* `valuesEqual`, and the value-only door reaches it through the sequence algebra, so a money pair
|
|
53
|
+
* cannot be refused by one and answered `FAIL` by the other.
|
|
54
|
+
*/
|
|
55
|
+
export declare function equalByDomain(left: DomainedValue, right: DomainedValue, path: string): boolean;
|
|
56
|
+
//# sourceMappingURL=ordering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ordering.d.ts","sourceRoot":"","sources":["../../src/expr/ordering.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,mBAAmB,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAOlD;;;;;;;;;GASG;AAEH,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;IAC3C;;;;;;;;OAQG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,EAAE,CAAC;CAClE;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAE3D;AAkCD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,aAAa,CAKlD,CAAC;AAwBH;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CA+CpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CA+B9F"}
|