@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,1422 @@
|
|
|
1
|
+
import { assertNever, AxiomError } from '../../model/errors.js';
|
|
2
|
+
import { freezeTree } from '../seal.js';
|
|
3
|
+
import { parsePlainDate } from '../../expr/plain-date.js';
|
|
4
|
+
import { isReservedContextRoot, isTier } from '../../model/types.js';
|
|
5
|
+
import { isRecord, isWireValue, sameWireValue, wireMembers } from '../../model/values.js';
|
|
6
|
+
import { rowKeyToken, rowKeyValue, toLookupPort, toSessionWireValue, toHostWireValue, toWireValue, wireDeclarationOf, } from '../../model/wire.js';
|
|
7
|
+
import { checkWrite } from '../access/write.js';
|
|
8
|
+
import { fieldKey } from '../access/projection.js';
|
|
9
|
+
import { indexContextRoots } from '../reader.js';
|
|
10
|
+
import { asAccessVersion, toAccessOverlay } from '../../model/access.js';
|
|
11
|
+
import { prepareSchema } from '../rule/prepare.js';
|
|
12
|
+
import { declarationOf } from '../addressing.js';
|
|
13
|
+
import { applyStructural, rowIndexOf, rowKeysOf, validateArrayIdentity } from './identity.js';
|
|
14
|
+
import { fieldIndex, rowStateOf as rowStateIn, sameData } from './snapshot.js';
|
|
15
|
+
/** Every refusal a session operation can return, named by the tuple a host branches on. */
|
|
16
|
+
export const SESSION_REFUSAL_CODES = [
|
|
17
|
+
'ACCESS_DENIED',
|
|
18
|
+
'DISABLED',
|
|
19
|
+
'ROW_UNADDRESSABLE',
|
|
20
|
+
'INVALID_VALUE',
|
|
21
|
+
'ROW_KEY_DUPLICATE',
|
|
22
|
+
'ROW_KEY_NOT_FOUND',
|
|
23
|
+
'IDENTITY_UNSUPPORTED',
|
|
24
|
+
'ID_FACTORY_REQUIRED',
|
|
25
|
+
'ROW_INDEX_OUT_OF_RANGE',
|
|
26
|
+
'UNKNOWN_CONTEXT_ROOT',
|
|
27
|
+
'STALE_BASIS',
|
|
28
|
+
'DRAIN_BUDGET_EXCEEDED',
|
|
29
|
+
'EMISSION_IN_PROGRESS',
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* The repair a refused session operation names, keyed by the closed code union.
|
|
33
|
+
*
|
|
34
|
+
* A queue can refuse an operation a control issued, so the sentence has to tell the host what
|
|
35
|
+
* to change rather than only that the session declined. It never names a written value.
|
|
36
|
+
*/
|
|
37
|
+
export const SESSION_REFUSAL_REPAIRS = {
|
|
38
|
+
ACCESS_DENIED: 'Grant the reference access, or change the operation origin; a user write cannot target a `signature_ref`, a writer-owned value, or a binding the document does not declare, and a structural operation needs a declared array.',
|
|
39
|
+
DISABLED: 'Enable the control first; one of its `enabled` rules currently fails.',
|
|
40
|
+
ROW_UNADDRESSABLE: 'Name the row with `rowKey`; the value exists once per row.',
|
|
41
|
+
INVALID_VALUE: "Write a value the field's declaration admits, or send ingestion that confirms the value already held.",
|
|
42
|
+
ROW_KEY_DUPLICATE: 'Give each row a unique key; two rows state the same `rowKey`.',
|
|
43
|
+
ROW_KEY_NOT_FOUND: "Address a row that exists; the key is not in the array's current manifest.",
|
|
44
|
+
IDENTITY_UNSUPPORTED: 'Declare an addressing mode the array supports (`natural` or `assigned`), or supply the manifest the session owns.',
|
|
45
|
+
ID_FACTORY_REQUIRED: "Pass an `idFactory` in the engine's `ports` so assigned rows receive ids.",
|
|
46
|
+
ROW_INDEX_OUT_OF_RANGE: "Name an index inside the array's current rows.",
|
|
47
|
+
UNKNOWN_CONTEXT_ROOT: 'Name a root the document declares in `context.roots`, or set it first.',
|
|
48
|
+
STALE_BASIS: 'Re-read the committed state and re-issue the operation; the preview basis is no longer current.',
|
|
49
|
+
DRAIN_BUDGET_EXCEEDED: 'Break the listener write cycle or shorten the cascade; queued writes exceeded the commit drain bound.',
|
|
50
|
+
EMISSION_IN_PROGRESS: 'Move the `hydrate` call outside the listener callback and re-issue it after the emission completes.',
|
|
51
|
+
};
|
|
52
|
+
/** The repair row for one session refusal, total over the closed union. */
|
|
53
|
+
export function sessionRefusalRepair(code) {
|
|
54
|
+
return SESSION_REFUSAL_REPAIRS[code];
|
|
55
|
+
}
|
|
56
|
+
/** Validates and copies `env.capabilities`, refusing non-arrays and non-string entries. */
|
|
57
|
+
function copyCapabilities(value, path) {
|
|
58
|
+
if (!Array.isArray(value)) {
|
|
59
|
+
throw new AxiomError('ENGINE_ERROR', 'capabilities must be an array of strings', path);
|
|
60
|
+
}
|
|
61
|
+
const copied = [];
|
|
62
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
63
|
+
const entry = value[index];
|
|
64
|
+
if (typeof entry !== 'string') {
|
|
65
|
+
throw new AxiomError('ENGINE_ERROR', 'each capability must be a string', `${path}[${String(index)}]`);
|
|
66
|
+
}
|
|
67
|
+
copied.push(entry);
|
|
68
|
+
}
|
|
69
|
+
return copied;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validates and takes ownership of an environment once, copying `capabilities` so later caller
|
|
73
|
+
* mutations or getter re-reads cannot drift from the derived session state.
|
|
74
|
+
*/
|
|
75
|
+
export function copyEnvironment(env) {
|
|
76
|
+
const raw = env;
|
|
77
|
+
if (!isRecord(raw)) {
|
|
78
|
+
throw new AxiomError('ENGINE_ERROR', 'environment must be an object', '$.env');
|
|
79
|
+
}
|
|
80
|
+
const tier = raw['tier'];
|
|
81
|
+
if (tier !== undefined && !isTier(tier)) {
|
|
82
|
+
throw new AxiomError('ENGINE_ERROR', 'tier must be "client" or "server"', '$.env.tier');
|
|
83
|
+
}
|
|
84
|
+
const accessVersion = raw['accessVersion'];
|
|
85
|
+
const checkedAccessVersion = accessVersion === undefined ? undefined : asAccessVersion(accessVersion, '$.env.accessVersion');
|
|
86
|
+
const recordDate = raw['recordDate'];
|
|
87
|
+
if (recordDate !== undefined) {
|
|
88
|
+
if (typeof recordDate !== 'string') {
|
|
89
|
+
throw new AxiomError('ENGINE_ERROR', 'recordDate must be a string', '$.env.recordDate');
|
|
90
|
+
}
|
|
91
|
+
parsePlainDate(recordDate, '$.env.recordDate');
|
|
92
|
+
}
|
|
93
|
+
const capabilities = raw['capabilities'];
|
|
94
|
+
const checkedCapabilities = capabilities === undefined ? undefined : copyCapabilities(capabilities, '$.env.capabilities');
|
|
95
|
+
const lookup = raw['lookup'];
|
|
96
|
+
const checkedLookup = lookup === undefined ? undefined : toLookupPort(lookup, '$.env.lookup');
|
|
97
|
+
return {
|
|
98
|
+
...(tier === undefined ? {} : { tier }),
|
|
99
|
+
...(checkedAccessVersion === undefined ? {} : { accessVersion: checkedAccessVersion }),
|
|
100
|
+
...(recordDate === undefined ? {} : { recordDate }),
|
|
101
|
+
...(checkedCapabilities === undefined ? {} : { capabilities: checkedCapabilities }),
|
|
102
|
+
...(checkedLookup === undefined ? {} : { lookup: checkedLookup }),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Seals the validated operation snapshots produced during staging, so a caller that edits a
|
|
107
|
+
* candidate after a preview cannot make `commit` apply an operation the previewed view never
|
|
108
|
+
* showed.
|
|
109
|
+
*
|
|
110
|
+
* One member is borrowed rather than copied: an environment's `lookup` port, which is a behaviour
|
|
111
|
+
* the engine cannot hold a copy of. Sealing it would make the host's own store immutable in the
|
|
112
|
+
* host's hands — a later write to a field of it fails at a site that never saw the preview — so
|
|
113
|
+
* the walk freezes the environment *around* the port. The port still cannot be swapped for
|
|
114
|
+
* another after the preview, and every member the engine did copy is sealed.
|
|
115
|
+
*/
|
|
116
|
+
export function freezeOperations(operations) {
|
|
117
|
+
for (const operation of operations) {
|
|
118
|
+
if (operation.kind !== 'env') {
|
|
119
|
+
freezeTree(operation);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const { lookup: _borrowed, ...owned } = operation.env;
|
|
123
|
+
freezeTree(owned);
|
|
124
|
+
Object.freeze(operation.env);
|
|
125
|
+
Object.freeze(operation);
|
|
126
|
+
}
|
|
127
|
+
return Object.freeze(operations);
|
|
128
|
+
}
|
|
129
|
+
/** Whether a candidate value matches a validated wire value canonically. */
|
|
130
|
+
function sameOperationValue(left, right) {
|
|
131
|
+
if (left === right)
|
|
132
|
+
return true;
|
|
133
|
+
return isWireValue(right) && sameWireValue(left, right);
|
|
134
|
+
}
|
|
135
|
+
/** Whether a candidate field reference matches a derived operation's reference. */
|
|
136
|
+
function sameRef(left, right) {
|
|
137
|
+
if (!isRecord(right))
|
|
138
|
+
return false;
|
|
139
|
+
return left.fieldId === right['fieldId'] && Object.is(left.rowKey, right['rowKey']);
|
|
140
|
+
}
|
|
141
|
+
/** Whether a candidate environment matches a derived operation's environment, lookup port included. */
|
|
142
|
+
function sameEnv(left, right) {
|
|
143
|
+
if (!isRecord(right))
|
|
144
|
+
return false;
|
|
145
|
+
if (left.tier !== right['tier'])
|
|
146
|
+
return false;
|
|
147
|
+
if (!Object.is(left.accessVersion, right['accessVersion']))
|
|
148
|
+
return false;
|
|
149
|
+
if (left.recordDate !== right['recordDate'])
|
|
150
|
+
return false;
|
|
151
|
+
if (left.lookup !== right['lookup'])
|
|
152
|
+
return false;
|
|
153
|
+
return sameData(left.capabilities, right['capabilities']);
|
|
154
|
+
}
|
|
155
|
+
/** Whether a candidate overlay matches a derived operation's overlay. */
|
|
156
|
+
function sameOverlay(left, right) {
|
|
157
|
+
if (!isRecord(right))
|
|
158
|
+
return false;
|
|
159
|
+
if (!Object.is(left.accessVersion, right['accessVersion']))
|
|
160
|
+
return false;
|
|
161
|
+
if (left.defaultAccess !== right['defaultAccess'])
|
|
162
|
+
return false;
|
|
163
|
+
if (!sameData(left.allowMaskedRead, right['allowMaskedRead']))
|
|
164
|
+
return false;
|
|
165
|
+
return sameData(left.rules, right['rules']);
|
|
166
|
+
}
|
|
167
|
+
/** Whether an incoming operation matches one derived operation canonically. */
|
|
168
|
+
function sameOperation(left, right) {
|
|
169
|
+
if (left === right)
|
|
170
|
+
return true;
|
|
171
|
+
if (!isRecord(right) || left.kind !== right['kind'])
|
|
172
|
+
return false;
|
|
173
|
+
switch (left.kind) {
|
|
174
|
+
case 'value':
|
|
175
|
+
return (left.origin === right['origin'] &&
|
|
176
|
+
sameRef(left.ref, right['ref']) &&
|
|
177
|
+
sameOperationValue(left.value, right['value']));
|
|
178
|
+
case 'null':
|
|
179
|
+
case 'remove':
|
|
180
|
+
return left.origin === right['origin'] && sameRef(left.ref, right['ref']);
|
|
181
|
+
case 'context':
|
|
182
|
+
return left.root === right['root'] && sameOperationValue(left.value, right['value']);
|
|
183
|
+
case 'env':
|
|
184
|
+
return sameEnv(left.env, right['env']);
|
|
185
|
+
case 'access':
|
|
186
|
+
return sameOverlay(left.overlay, right['overlay']);
|
|
187
|
+
case 'append':
|
|
188
|
+
return (left.fieldId === right['fieldId'] &&
|
|
189
|
+
left.origin === right['origin'] &&
|
|
190
|
+
sameOperationValue(left.value, right['value']));
|
|
191
|
+
case 'insert':
|
|
192
|
+
return (left.fieldId === right['fieldId'] &&
|
|
193
|
+
Object.is(left.index, right['index']) &&
|
|
194
|
+
left.origin === right['origin'] &&
|
|
195
|
+
sameOperationValue(left.value, right['value']));
|
|
196
|
+
case 'removeRow':
|
|
197
|
+
return (left.fieldId === right['fieldId'] &&
|
|
198
|
+
Object.is(left.rowKey, right['rowKey']) &&
|
|
199
|
+
left.origin === right['origin']);
|
|
200
|
+
case 'move':
|
|
201
|
+
return (left.fieldId === right['fieldId'] &&
|
|
202
|
+
Object.is(left.rowKey, right['rowKey']) &&
|
|
203
|
+
Object.is(left.toIndex, right['toIndex']) &&
|
|
204
|
+
left.origin === right['origin']);
|
|
205
|
+
default:
|
|
206
|
+
return assertNever(left);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** Whether an incoming operation list matches a derived candidate's canonical operations. */
|
|
210
|
+
export function sameOperations(left, right) {
|
|
211
|
+
if (left === right)
|
|
212
|
+
return true;
|
|
213
|
+
if (!Array.isArray(right) || left.length !== right.length)
|
|
214
|
+
return false;
|
|
215
|
+
return left.every((operation, index) => sameOperation(operation, right[index]));
|
|
216
|
+
}
|
|
217
|
+
const DECLARATIONS = new WeakMap();
|
|
218
|
+
/** Indexes every declared field by where its value lives, once per artifact. */
|
|
219
|
+
function declarationsOf(compiled) {
|
|
220
|
+
const cached = DECLARATIONS.get(compiled);
|
|
221
|
+
if (cached !== undefined)
|
|
222
|
+
return cached;
|
|
223
|
+
const declarations = new Map();
|
|
224
|
+
const visit = (members, containerPath, row) => {
|
|
225
|
+
for (const field of members) {
|
|
226
|
+
if (row !== undefined) {
|
|
227
|
+
declarations.set(field.fieldId, {
|
|
228
|
+
field,
|
|
229
|
+
arrayFieldId: row.arrayFieldId,
|
|
230
|
+
arrayPath: row.path,
|
|
231
|
+
containerPath: [],
|
|
232
|
+
rowSegments: [...row.segments, field.fieldId],
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
declarations.set(field.fieldId, {
|
|
237
|
+
field,
|
|
238
|
+
arrayFieldId: undefined,
|
|
239
|
+
arrayPath: [],
|
|
240
|
+
containerPath: [...containerPath, field.fieldId],
|
|
241
|
+
rowSegments: [],
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const nextContainer = row === undefined ? [...containerPath, field.fieldId] : containerPath;
|
|
245
|
+
const nextRow = field.primitive === 'array'
|
|
246
|
+
? {
|
|
247
|
+
arrayFieldId: field.fieldId,
|
|
248
|
+
path: row === undefined ? [...containerPath, field.fieldId] : [],
|
|
249
|
+
segments: [],
|
|
250
|
+
}
|
|
251
|
+
: row === undefined
|
|
252
|
+
? undefined
|
|
253
|
+
: {
|
|
254
|
+
arrayFieldId: row.arrayFieldId,
|
|
255
|
+
path: row.path,
|
|
256
|
+
segments: [...row.segments, field.fieldId],
|
|
257
|
+
};
|
|
258
|
+
visit(field.fields ?? [], nextContainer, nextRow);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
visit(compiled.fields, [], undefined);
|
|
262
|
+
DECLARATIONS.set(compiled, declarations);
|
|
263
|
+
return declarations;
|
|
264
|
+
}
|
|
265
|
+
/** One field's declaration, refusing an identifier the artifact does not declare. */
|
|
266
|
+
export function declarationFor(compiled, fieldId) {
|
|
267
|
+
const declaration = declarationsOf(compiled).get(fieldId);
|
|
268
|
+
if (declaration === undefined) {
|
|
269
|
+
throw new AxiomError('ENGINE_ERROR', `no field is named ${fieldId}`, fieldId);
|
|
270
|
+
}
|
|
271
|
+
return declaration;
|
|
272
|
+
}
|
|
273
|
+
/** Reads an array through its record containers, never through a root namesake. */
|
|
274
|
+
function readArrayAtPath(values, path) {
|
|
275
|
+
let current = values;
|
|
276
|
+
for (const segment of path) {
|
|
277
|
+
if (!isRecord(current))
|
|
278
|
+
return undefined;
|
|
279
|
+
current = current[segment];
|
|
280
|
+
}
|
|
281
|
+
return Array.isArray(current) ? current : undefined;
|
|
282
|
+
}
|
|
283
|
+
/** Writes an array through its record containers, copying each container on the path. */
|
|
284
|
+
function writeArrayAtPath(values, path, array) {
|
|
285
|
+
const write = (record, depth) => {
|
|
286
|
+
const segment = path[depth];
|
|
287
|
+
if (segment === undefined)
|
|
288
|
+
return record;
|
|
289
|
+
const value = depth === path.length - 1
|
|
290
|
+
? array
|
|
291
|
+
: write(wireMembers(record[segment] ?? null) ?? {}, depth + 1);
|
|
292
|
+
return withMember(record, segment, value);
|
|
293
|
+
};
|
|
294
|
+
return write(values, 0);
|
|
295
|
+
}
|
|
296
|
+
/** The value one declaration holds, for a row member or a record field. */
|
|
297
|
+
function readDeclared(declaration, values, index) {
|
|
298
|
+
if (declaration.arrayFieldId !== undefined) {
|
|
299
|
+
if (index === undefined)
|
|
300
|
+
return undefined;
|
|
301
|
+
const array = readArrayAtPath(values, declaration.arrayPath);
|
|
302
|
+
if (!Array.isArray(array))
|
|
303
|
+
return undefined;
|
|
304
|
+
let cursor = array[index];
|
|
305
|
+
for (const segment of declaration.rowSegments) {
|
|
306
|
+
cursor = wireMembers(cursor ?? null)?.[segment] ?? undefined;
|
|
307
|
+
}
|
|
308
|
+
return cursor;
|
|
309
|
+
}
|
|
310
|
+
let cursor = undefined;
|
|
311
|
+
let container = values;
|
|
312
|
+
for (const [position, segment] of declaration.containerPath.entries()) {
|
|
313
|
+
const next = container[segment];
|
|
314
|
+
if (position === declaration.containerPath.length - 1)
|
|
315
|
+
cursor = next;
|
|
316
|
+
else {
|
|
317
|
+
const members = wireMembers(next ?? null);
|
|
318
|
+
if (members === undefined)
|
|
319
|
+
return undefined;
|
|
320
|
+
container = members;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return cursor;
|
|
324
|
+
}
|
|
325
|
+
/** Sets one member of a record, copying every object on the path. */
|
|
326
|
+
function withMember(record, segment, value) {
|
|
327
|
+
if (value === undefined) {
|
|
328
|
+
const { [segment]: _removed, ...rest } = record;
|
|
329
|
+
return rest;
|
|
330
|
+
}
|
|
331
|
+
return { ...record, [segment]: value };
|
|
332
|
+
}
|
|
333
|
+
/** Writes one declared value, returning the next record. */
|
|
334
|
+
function writeDeclared(declaration, values, index, value) {
|
|
335
|
+
if (declaration.arrayFieldId === undefined) {
|
|
336
|
+
const path = declaration.containerPath;
|
|
337
|
+
const write = (container, depth) => {
|
|
338
|
+
const segment = path[depth];
|
|
339
|
+
if (segment === undefined)
|
|
340
|
+
return container;
|
|
341
|
+
if (depth === path.length - 1)
|
|
342
|
+
return withMember(container, segment, value);
|
|
343
|
+
const child = wireMembers(container[segment] ?? null) ?? {};
|
|
344
|
+
return withMember(container, segment, write(child, depth + 1));
|
|
345
|
+
};
|
|
346
|
+
return write(values, 0);
|
|
347
|
+
}
|
|
348
|
+
const array = readArrayAtPath(values, declaration.arrayPath);
|
|
349
|
+
if (array === undefined || index === undefined)
|
|
350
|
+
return values;
|
|
351
|
+
const nextArray = [...array];
|
|
352
|
+
const row = nextArray[index];
|
|
353
|
+
let nextRow = row;
|
|
354
|
+
const segments = declaration.rowSegments;
|
|
355
|
+
if (segments.length === 1) {
|
|
356
|
+
const member = segments[0] ?? '';
|
|
357
|
+
nextRow = withMember(wireMembers(row ?? null) ?? {}, member, value);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
const write = (container, depth) => {
|
|
361
|
+
const segment = segments[depth];
|
|
362
|
+
if (segment === undefined)
|
|
363
|
+
return container;
|
|
364
|
+
if (depth === segments.length - 1)
|
|
365
|
+
return withMember(container, segment, value);
|
|
366
|
+
const child = wireMembers(container[segment] ?? null) ?? {};
|
|
367
|
+
return withMember(container, segment, write(child, depth + 1));
|
|
368
|
+
};
|
|
369
|
+
nextRow = write(wireMembers(row ?? null) ?? {}, 0);
|
|
370
|
+
}
|
|
371
|
+
nextArray[index] = nextRow;
|
|
372
|
+
return writeArrayAtPath(values, declaration.arrayPath, nextArray);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The row state one row binding names, when the derivation addressed it.
|
|
376
|
+
*
|
|
377
|
+
* The guard asks this for the binding a control was rendered from, and the engine already keeps
|
|
378
|
+
* one row index per frozen entry for the same question (`rowStateOf` in `snapshot.ts`). Reading
|
|
379
|
+
* that index means a write's two lookups share one pass over the rows with every binding read
|
|
380
|
+
* before it, instead of walking the list again for each question.
|
|
381
|
+
*/
|
|
382
|
+
function rowStateOf(field, rowKey) {
|
|
383
|
+
return field === undefined ? undefined : rowStateIn(field, rowKey);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* The derived field entry the guard reads for one reference.
|
|
387
|
+
*
|
|
388
|
+
* A `FormState` is frozen before it is committed, so the one field index the engine keeps per
|
|
389
|
+
* form is a sound and shared answer to "which entry names this field".
|
|
390
|
+
*/
|
|
391
|
+
function fieldStateFor(form, fieldId) {
|
|
392
|
+
return fieldIndex(form).get(fieldId);
|
|
393
|
+
}
|
|
394
|
+
/** The `enabled` answer the control was rendered with, for one binding. */
|
|
395
|
+
function enabledOf(form, ref) {
|
|
396
|
+
const field = fieldStateFor(form, ref.fieldId);
|
|
397
|
+
if (field === undefined)
|
|
398
|
+
return false;
|
|
399
|
+
if (ref.rowKey === undefined)
|
|
400
|
+
return field.enabled;
|
|
401
|
+
return rowStateOf(field, ref.rowKey)?.enabled ?? false;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* The access answer the control was rendered with, for one binding.
|
|
405
|
+
*
|
|
406
|
+
* A row's access is the derivation's own: a container's row rule and, for a member, the
|
|
407
|
+
* member's answer met with it. The window answers a field reference, so asking it about a
|
|
408
|
+
* member's row would state the field's level and report an overlay refusal as `DISABLED`.
|
|
409
|
+
*/
|
|
410
|
+
function accessOf(form, access, ref) {
|
|
411
|
+
if (ref.rowKey === undefined)
|
|
412
|
+
return access.accessFor(ref);
|
|
413
|
+
const row = rowStateOf(fieldStateFor(form, ref.fieldId), ref.rowKey);
|
|
414
|
+
return row?.access ?? access.accessFor(ref);
|
|
415
|
+
}
|
|
416
|
+
/** The first `signature_ref` a value of one field's shape holds, at any depth. */
|
|
417
|
+
function signatureMemberOf(field, value) {
|
|
418
|
+
if (value === undefined)
|
|
419
|
+
return undefined;
|
|
420
|
+
// An array's own value is its rows; a record's is the one value its members are read from.
|
|
421
|
+
for (const held of Array.isArray(value) ? value : [value]) {
|
|
422
|
+
const members = wireMembers(held);
|
|
423
|
+
if (members === undefined)
|
|
424
|
+
continue;
|
|
425
|
+
for (const member of field.fields ?? []) {
|
|
426
|
+
if (!Object.hasOwn(members, member.fieldId))
|
|
427
|
+
continue;
|
|
428
|
+
const memberValue = members[member.fieldId];
|
|
429
|
+
if (memberValue === undefined)
|
|
430
|
+
continue;
|
|
431
|
+
if (member.primitive === 'signature_ref')
|
|
432
|
+
return member;
|
|
433
|
+
const deeper = signatureMemberOf(member, memberValue);
|
|
434
|
+
if (deeper !== undefined)
|
|
435
|
+
return deeper;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return undefined;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* The refusal a user write carries when it would set or drop a nested `signature_ref`.
|
|
442
|
+
*
|
|
443
|
+
* No overlay may make a user write to a signature succeed (`[ACCESS-1.2.4]`): only the host's
|
|
444
|
+
* `system`-origin capture ceremony writes one. A signature is a *member* of the record or array
|
|
445
|
+
* row that holds it, so a container's value is the only way a write reaches it — and a writable
|
|
446
|
+
* container must not be the way around the denial. Both directions count: a value that carries a
|
|
447
|
+
* signature would set one, and a value that omits a signature the record already holds would
|
|
448
|
+
* drop it, the shape a control that never rendered the signature produces. The decision stays
|
|
449
|
+
* `checkWrite`'s, asked about the signature member, so a container write and the signature's own
|
|
450
|
+
* setter cannot disagree; the refusal names the field the caller wrote, because
|
|
451
|
+
* `[ACCESS-1.2.4]` has a refusal name the reference it judged.
|
|
452
|
+
*/
|
|
453
|
+
function signatureRefusal(form, access, field, held, next, ref, origin) {
|
|
454
|
+
if (origin !== 'user')
|
|
455
|
+
return undefined;
|
|
456
|
+
const signature = signatureMemberOf(field, held) ?? signatureMemberOf(field, next);
|
|
457
|
+
if (signature === undefined)
|
|
458
|
+
return undefined;
|
|
459
|
+
const memberRef = ref.rowKey === undefined
|
|
460
|
+
? { fieldId: signature.fieldId }
|
|
461
|
+
: { fieldId: signature.fieldId, rowKey: ref.rowKey };
|
|
462
|
+
// The same predicate the signature field's own setter asks, so one rule decides both.
|
|
463
|
+
const refusal = checkWrite({
|
|
464
|
+
ref: memberRef,
|
|
465
|
+
origin,
|
|
466
|
+
access: accessOf(form, access, memberRef),
|
|
467
|
+
enabled: enabledOf(form, memberRef),
|
|
468
|
+
primitive: 'signature_ref',
|
|
469
|
+
item: false,
|
|
470
|
+
changed: true,
|
|
471
|
+
});
|
|
472
|
+
return refusal === undefined ? undefined : { ...refusalOf(refusal), fieldId: ref.fieldId };
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Checks a whole-array write (or an array inside a record) against every row member's access.
|
|
476
|
+
*
|
|
477
|
+
* Natural-keyed rows are paired by key so reordering or editing a writable sibling while echoing a
|
|
478
|
+
* `read_only` member stays permitted. Unpaired held rows check deletion of restricted members;
|
|
479
|
+
* unpaired incoming rows check writes to restricted members.
|
|
480
|
+
*/
|
|
481
|
+
function checkArrayRows(form, access, field, held, next) {
|
|
482
|
+
const members = field.fields;
|
|
483
|
+
if (members === undefined || members.length === 0)
|
|
484
|
+
return undefined;
|
|
485
|
+
const heldRows = Array.isArray(held) ? held : [];
|
|
486
|
+
const nextRows = Array.isArray(next) ? next : [];
|
|
487
|
+
if (heldRows.length === 0 && nextRows.length === 0)
|
|
488
|
+
return undefined;
|
|
489
|
+
if (field.rowKey?.mode === 'natural' && field.rowKey.fieldId !== undefined) {
|
|
490
|
+
const keyField = field.rowKey.fieldId;
|
|
491
|
+
const heldByToken = new Map();
|
|
492
|
+
const unmatchedHeld = [];
|
|
493
|
+
for (const row of heldRows) {
|
|
494
|
+
const key = rowKeyValue(wireMembers(row)?.[keyField]);
|
|
495
|
+
if (key === undefined) {
|
|
496
|
+
unmatchedHeld.push(row);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const token = rowKeyToken(key);
|
|
500
|
+
if (heldByToken.has(token)) {
|
|
501
|
+
unmatchedHeld.push(row);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
heldByToken.set(token, { key, row });
|
|
505
|
+
}
|
|
506
|
+
for (const row of nextRows) {
|
|
507
|
+
const key = rowKeyValue(wireMembers(row)?.[keyField]);
|
|
508
|
+
const token = key === undefined ? undefined : rowKeyToken(key);
|
|
509
|
+
const paired = token === undefined ? undefined : heldByToken.get(token);
|
|
510
|
+
if (paired !== undefined && token !== undefined) {
|
|
511
|
+
heldByToken.delete(token);
|
|
512
|
+
const refusal = checkRecordMembers(form, access, members, paired.row, row, paired.key);
|
|
513
|
+
if (refusal !== undefined)
|
|
514
|
+
return refusal;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
const refusal = checkRecordMembers(form, access, members, undefined, row, key);
|
|
518
|
+
if (refusal !== undefined)
|
|
519
|
+
return refusal;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
for (const { key, row } of heldByToken.values()) {
|
|
523
|
+
const refusal = checkRecordMembers(form, access, members, row, undefined, key);
|
|
524
|
+
if (refusal !== undefined)
|
|
525
|
+
return refusal;
|
|
526
|
+
}
|
|
527
|
+
for (const row of unmatchedHeld) {
|
|
528
|
+
const refusal = checkRecordMembers(form, access, members, row, undefined, undefined);
|
|
529
|
+
if (refusal !== undefined)
|
|
530
|
+
return refusal;
|
|
531
|
+
}
|
|
532
|
+
return undefined;
|
|
533
|
+
}
|
|
534
|
+
const length = Math.max(heldRows.length, nextRows.length);
|
|
535
|
+
for (let index = 0; index < length; index += 1) {
|
|
536
|
+
const refusal = checkRecordMembers(form, access, members, heldRows[index], nextRows[index], undefined);
|
|
537
|
+
if (refusal !== undefined)
|
|
538
|
+
return refusal;
|
|
539
|
+
}
|
|
540
|
+
return undefined;
|
|
541
|
+
}
|
|
542
|
+
/** Checks every declared member of one record or one array row against its resolved access. */
|
|
543
|
+
function checkRecordMembers(form, access, members, held, next, rowKey) {
|
|
544
|
+
const heldMembers = held === undefined ? undefined : wireMembers(held);
|
|
545
|
+
const nextMembers = next === undefined ? undefined : wireMembers(next);
|
|
546
|
+
if (heldMembers === undefined && nextMembers === undefined)
|
|
547
|
+
return undefined;
|
|
548
|
+
for (const member of members) {
|
|
549
|
+
const heldValue = heldMembers !== undefined && Object.hasOwn(heldMembers, member.fieldId)
|
|
550
|
+
? heldMembers[member.fieldId]
|
|
551
|
+
: undefined;
|
|
552
|
+
const nextValue = nextMembers !== undefined && Object.hasOwn(nextMembers, member.fieldId)
|
|
553
|
+
? nextMembers[member.fieldId]
|
|
554
|
+
: undefined;
|
|
555
|
+
if (heldValue === undefined && nextValue === undefined)
|
|
556
|
+
continue;
|
|
557
|
+
const memberRef = rowKey === undefined ? { fieldId: member.fieldId } : { fieldId: member.fieldId, rowKey };
|
|
558
|
+
const refusal = checkWrite({
|
|
559
|
+
ref: memberRef,
|
|
560
|
+
origin: 'user',
|
|
561
|
+
access: accessOf(form, access, memberRef),
|
|
562
|
+
// Container enabled state is judged on the container itself; a newly appended row has no
|
|
563
|
+
// derived row state in `form` yet, so member access is what this guard enforces.
|
|
564
|
+
enabled: true,
|
|
565
|
+
primitive: member.primitive,
|
|
566
|
+
item: false,
|
|
567
|
+
changed: true,
|
|
568
|
+
});
|
|
569
|
+
if (refusal !== undefined) {
|
|
570
|
+
const sameEcho = heldValue !== undefined &&
|
|
571
|
+
nextValue !== undefined &&
|
|
572
|
+
sameWireValue(heldValue, nextValue) &&
|
|
573
|
+
access.enclosingDelivers(memberRef);
|
|
574
|
+
if (!sameEcho)
|
|
575
|
+
return refusal;
|
|
576
|
+
}
|
|
577
|
+
if (member.fields !== undefined && member.fields.length > 0) {
|
|
578
|
+
const deeper = checkContainerMembers(form, access, member, heldValue, nextValue, member.primitive === 'array' ? undefined : rowKey, false);
|
|
579
|
+
if (deeper !== undefined)
|
|
580
|
+
return deeper;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
/** Whether a container's write reaches a member whose resolved access refuses a user write. */
|
|
586
|
+
function checkContainerMembers(form, access, field, held, next, rowKey, elementOfArray) {
|
|
587
|
+
const members = field.fields;
|
|
588
|
+
if (members === undefined || members.length === 0)
|
|
589
|
+
return undefined;
|
|
590
|
+
if (field.primitive === 'array' && !elementOfArray) {
|
|
591
|
+
return checkArrayRows(form, access, field, held, next);
|
|
592
|
+
}
|
|
593
|
+
return checkRecordMembers(form, access, members, held, next, rowKey);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* The refusal a user write carries when it would write, modify, or delete a declared member
|
|
597
|
+
* whose resolved access denies user writes (`[ACCESS-1.2.1]`).
|
|
598
|
+
*
|
|
599
|
+
* A member is reachable through the record or array row that holds it, so a writable container
|
|
600
|
+
* must not bypass a member's `read_only`, `masked`, or `hidden` answer. Leaving a restricted
|
|
601
|
+
* member untouched does not refuse: a member absent before and after is unchanged, and a
|
|
602
|
+
* deliverable member echoed with the same wire value is unchanged. A withheld member (`masked`,
|
|
603
|
+
* `hidden`, or redacted) is never delivered to the caller, so supplying any value for it is
|
|
604
|
+
* refused even when the value happens to match what the record holds, preventing a container
|
|
605
|
+
* write from probing withheld values.
|
|
606
|
+
*/
|
|
607
|
+
function memberAccessRefusal(form, access, field, held, next, ref, origin, elementOfArray, rowKey = ref.rowKey) {
|
|
608
|
+
if (origin !== 'user')
|
|
609
|
+
return undefined;
|
|
610
|
+
const denied = checkContainerMembers(form, access, field, held, next, rowKey, elementOfArray);
|
|
611
|
+
if (denied === undefined)
|
|
612
|
+
return undefined;
|
|
613
|
+
return {
|
|
614
|
+
outcome: 'refused',
|
|
615
|
+
code: denied.code,
|
|
616
|
+
origin,
|
|
617
|
+
fieldId: ref.fieldId,
|
|
618
|
+
...(ref.rowKey === undefined ? {} : { rowKey: ref.rowKey }),
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
/** The domain one element of an array takes: its item domain, or the row record it holds. */
|
|
622
|
+
function elementDeclarationOf(field) {
|
|
623
|
+
if (field.items !== undefined) {
|
|
624
|
+
return {
|
|
625
|
+
primitive: field.items.primitive,
|
|
626
|
+
...(field.items.currency === undefined ? {} : { currency: field.items.currency }),
|
|
627
|
+
...(field.items.scale === undefined ? {} : { scale: field.items.scale }),
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return { primitive: 'record', fields: field.fields ?? [] };
|
|
631
|
+
}
|
|
632
|
+
/** One element of a scalar or attachment array, by committed position. */
|
|
633
|
+
function arrayElementOf(values, declaration, index) {
|
|
634
|
+
if (index === undefined)
|
|
635
|
+
return undefined;
|
|
636
|
+
return readArrayAtPath(values, declaration.containerPath)?.[index];
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* The value one reference holds in a working state, or `undefined` when it holds none.
|
|
640
|
+
*
|
|
641
|
+
* It is the read the write guard performs before deciding whether an operation changes anything,
|
|
642
|
+
* stated as its own answer so a caller that reports a change set can say which of the user's
|
|
643
|
+
* values a write replaces without staging the batch a second time. A row the array does not
|
|
644
|
+
* address holds nothing: the write that names it is refused elsewhere, and this answer is only
|
|
645
|
+
* ever asked about a batch that committed.
|
|
646
|
+
*/
|
|
647
|
+
export function heldValueOf(compiled, working, ref) {
|
|
648
|
+
const declaration = declarationFor(compiled, ref.fieldId);
|
|
649
|
+
const field = declaration.field;
|
|
650
|
+
const elementOfArray = declaration.arrayFieldId === undefined &&
|
|
651
|
+
field.primitive === 'array' &&
|
|
652
|
+
ref.rowKey !== undefined;
|
|
653
|
+
const arrayFieldId = declaration.arrayFieldId ?? (elementOfArray ? field.fieldId : undefined);
|
|
654
|
+
const index = arrayFieldId === undefined || ref.rowKey === undefined
|
|
655
|
+
? undefined
|
|
656
|
+
: rowIndexOf(compiled, working.identity, working.values, arrayFieldId, ref.rowKey);
|
|
657
|
+
if (arrayFieldId !== undefined && ref.rowKey !== undefined && index === undefined) {
|
|
658
|
+
return undefined;
|
|
659
|
+
}
|
|
660
|
+
return elementOfArray
|
|
661
|
+
? arrayElementOf(working.values, declaration, index)
|
|
662
|
+
: readDeclared(declaration, working.values, index);
|
|
663
|
+
}
|
|
664
|
+
/** Replaces one element of an array, leaving every sibling alone. */
|
|
665
|
+
function writeArrayElement(values, declaration, index, value) {
|
|
666
|
+
const array = readArrayAtPath(values, declaration.containerPath);
|
|
667
|
+
if (array === undefined || index === undefined)
|
|
668
|
+
return values;
|
|
669
|
+
const next = [...array];
|
|
670
|
+
if (value === undefined)
|
|
671
|
+
next.splice(index, 1);
|
|
672
|
+
else
|
|
673
|
+
next[index] = value;
|
|
674
|
+
return writeArrayAtPath(values, declaration.containerPath, next);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* The `INVALID_VALUE` refusal for a value the declaration refused.
|
|
678
|
+
*
|
|
679
|
+
* It names the path it failed at and, when the operation named a field or a context root, that
|
|
680
|
+
* name too: a caller branches on the code and shows the field, and neither the value nor its
|
|
681
|
+
* length is ever spelled.
|
|
682
|
+
*/
|
|
683
|
+
function invalid(error, named = {}) {
|
|
684
|
+
return {
|
|
685
|
+
outcome: 'refused',
|
|
686
|
+
code: 'INVALID_VALUE',
|
|
687
|
+
...named,
|
|
688
|
+
...(error instanceof AxiomError ? { path: error.path } : {}),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* The `write_only` bindings one written value carries, at any depth.
|
|
693
|
+
*
|
|
694
|
+
* A member the written value omits was not written, so its stored value stays withheld rather
|
|
695
|
+
* than being unlocked by a partial record write. Each member is named by the reference its read
|
|
696
|
+
* uses — a record's members by field id, a row's members by the row the write addressed — because
|
|
697
|
+
* an unlock is matched against the binding key it names, and a member unlocked under a wider key
|
|
698
|
+
* than its read is a member the container delivers while the binding withholds it.
|
|
699
|
+
*
|
|
700
|
+
* A value that is a list of rows carries nothing here: its rows are addressed by keys the
|
|
701
|
+
* identity manifest holds, not by the value, so this walk cannot name one and must not fall back
|
|
702
|
+
* to the field-wide key — that would unlock every row of the member, delivering the stored value
|
|
703
|
+
* of the rows the write never carried.
|
|
704
|
+
*/
|
|
705
|
+
function carriedWriteOnly(access, field, value, rowKey) {
|
|
706
|
+
const refs = [];
|
|
707
|
+
const refOf = (member) => rowKey === undefined ? { fieldId: member.fieldId } : { fieldId: member.fieldId, rowKey };
|
|
708
|
+
const visit = (fields, held) => {
|
|
709
|
+
const members = wireMembers(held);
|
|
710
|
+
if (members === undefined)
|
|
711
|
+
return;
|
|
712
|
+
for (const member of fields) {
|
|
713
|
+
if (!Object.hasOwn(members, member.fieldId))
|
|
714
|
+
continue;
|
|
715
|
+
const memberValue = members[member.fieldId];
|
|
716
|
+
if (memberValue === undefined)
|
|
717
|
+
continue;
|
|
718
|
+
if (access.accessFor(refOf(member)) === 'write_only') {
|
|
719
|
+
refs.push(refOf(member));
|
|
720
|
+
}
|
|
721
|
+
if (member.fields !== undefined)
|
|
722
|
+
visit(member.fields, memberValue);
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
visit(field.fields ?? [], value);
|
|
726
|
+
return refs;
|
|
727
|
+
}
|
|
728
|
+
/** One array field's declaration, refusing an identifier that names no array. */
|
|
729
|
+
function arrayDeclaration(compiled, fieldId) {
|
|
730
|
+
const declaration = declarationsOf(compiled).get(fieldId);
|
|
731
|
+
if (declaration === undefined || declaration.field.primitive !== 'array') {
|
|
732
|
+
throw new AxiomError('ENGINE_ERROR', `no array field is named ${fieldId}`, fieldId);
|
|
733
|
+
}
|
|
734
|
+
return declaration.field;
|
|
735
|
+
}
|
|
736
|
+
/** The container-access guard one structural operation passes, `[ACCESS-2.1.6]`. */
|
|
737
|
+
function guardStructure(compiled, access, form, fieldId, origin) {
|
|
738
|
+
const field = arrayDeclaration(compiled, fieldId);
|
|
739
|
+
const refusal = checkWrite({
|
|
740
|
+
ref: { fieldId },
|
|
741
|
+
origin,
|
|
742
|
+
access: access.accessFor({ fieldId }),
|
|
743
|
+
enabled: enabledOf(form, { fieldId }),
|
|
744
|
+
primitive: field.primitive,
|
|
745
|
+
item: false,
|
|
746
|
+
changed: true,
|
|
747
|
+
});
|
|
748
|
+
return refusal === undefined ? undefined : refusalOf(refusal);
|
|
749
|
+
}
|
|
750
|
+
/** The runtime write refusal as the session's own refusal shape, row key type preserved. */
|
|
751
|
+
function refusalOf(refusal) {
|
|
752
|
+
return {
|
|
753
|
+
outcome: 'refused',
|
|
754
|
+
code: refusal.code,
|
|
755
|
+
origin: refusal.origin,
|
|
756
|
+
fieldId: refusal.fieldId,
|
|
757
|
+
// The key names one row, and an integer `7` and a text `"7"` are two rows, so the type
|
|
758
|
+
// travels with the refusal exactly as it does in a patch or a binding key.
|
|
759
|
+
...(refusal.rowKey === undefined ? {} : { rowKey: refusal.rowKey }),
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
/** The session-write reference map with one reference unlocked. */
|
|
763
|
+
function withSessionWrite(writes, ref, origin) {
|
|
764
|
+
if (origin !== 'user' && origin !== 'system')
|
|
765
|
+
return writes;
|
|
766
|
+
const key = fieldKey(ref);
|
|
767
|
+
if (writes.has(key))
|
|
768
|
+
return writes;
|
|
769
|
+
const next = new Map(writes);
|
|
770
|
+
next.set(key, Object.freeze({ ...ref }));
|
|
771
|
+
return next;
|
|
772
|
+
}
|
|
773
|
+
/** Whether one reference names a binding inside the array row whose identity moved. */
|
|
774
|
+
function isRowReference(compiled, ref, arrayFieldId, rowKey) {
|
|
775
|
+
if (ref.rowKey === undefined || rowKeyToken(ref.rowKey) !== rowKeyToken(rowKey))
|
|
776
|
+
return false;
|
|
777
|
+
return (ref.fieldId === arrayFieldId ||
|
|
778
|
+
declarationsOf(compiled).get(ref.fieldId)?.arrayFieldId === arrayFieldId);
|
|
779
|
+
}
|
|
780
|
+
/** Moves every session-write unlock with the row identity it belongs to. */
|
|
781
|
+
function rekeySessionWrites(compiled, writes, arrayFieldId, previousKey, nextKey) {
|
|
782
|
+
if (rowKeyToken(previousKey) === rowKeyToken(nextKey))
|
|
783
|
+
return writes;
|
|
784
|
+
const next = new Map();
|
|
785
|
+
for (const ref of writes.values()) {
|
|
786
|
+
const moved = isRowReference(compiled, ref, arrayFieldId, previousKey)
|
|
787
|
+
? { ...ref, rowKey: nextKey }
|
|
788
|
+
: ref;
|
|
789
|
+
next.set(fieldKey(moved), moved);
|
|
790
|
+
}
|
|
791
|
+
return next;
|
|
792
|
+
}
|
|
793
|
+
/** A removed row's unlocks must not unlock a different row that later reuses its key. */
|
|
794
|
+
function withoutSessionRow(compiled, writes, arrayFieldId, rowKey) {
|
|
795
|
+
const retained = [...writes.values()].filter((ref) => !isRowReference(compiled, ref, arrayFieldId, rowKey));
|
|
796
|
+
if (retained.length === writes.size)
|
|
797
|
+
return writes;
|
|
798
|
+
return new Map(retained.map((ref) => [fieldKey(ref), ref]));
|
|
799
|
+
}
|
|
800
|
+
/** Unlocks the row and member bindings an append or insert wrote in this session. */
|
|
801
|
+
function withSessionRow(compiled, writes, arrayFieldId, rowKey, origin) {
|
|
802
|
+
let next = withSessionWrite(writes, { fieldId: arrayFieldId, rowKey }, origin);
|
|
803
|
+
for (const declaration of declarationsOf(compiled).values()) {
|
|
804
|
+
if (declaration.arrayFieldId !== arrayFieldId)
|
|
805
|
+
continue;
|
|
806
|
+
next = withSessionWrite(next, { fieldId: declaration.field.fieldId, rowKey }, origin);
|
|
807
|
+
}
|
|
808
|
+
return next;
|
|
809
|
+
}
|
|
810
|
+
/** Every addressable array whose identity a value write can change. */
|
|
811
|
+
function arraysWrittenBy(compiled, declaration) {
|
|
812
|
+
if (declaration.arrayFieldId !== undefined)
|
|
813
|
+
return [declaration.arrayFieldId];
|
|
814
|
+
if (declaration.field.primitive === 'array')
|
|
815
|
+
return [declaration.field.fieldId];
|
|
816
|
+
if (declaration.field.primitive !== 'record')
|
|
817
|
+
return [];
|
|
818
|
+
const prefix = declaration.containerPath;
|
|
819
|
+
const arrays = [];
|
|
820
|
+
for (const candidate of declarationsOf(compiled).values()) {
|
|
821
|
+
if (candidate.field.primitive !== 'array' || candidate.arrayFieldId !== undefined)
|
|
822
|
+
continue;
|
|
823
|
+
const path = candidate.containerPath;
|
|
824
|
+
if (path.length >= prefix.length && prefix.every((segment, index) => path[index] === segment)) {
|
|
825
|
+
arrays.push(candidate.field.fieldId);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return arrays;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* The arrays whose row *set* one value write may move.
|
|
832
|
+
*
|
|
833
|
+
* A write to one member of a row changes that row's value, not which rows exist, so it states
|
|
834
|
+
* no membership change and cannot re-evaluate every item rule over the array. Two writes do
|
|
835
|
+
* move it: the member that *is* a row's identity — the natural key, which re-keys the row and
|
|
836
|
+
* therefore every result reported against it — and a write that replaces a container, which
|
|
837
|
+
* may add, remove or reorder rows beneath it.
|
|
838
|
+
*/
|
|
839
|
+
function membershipWritten(compiled, declaration) {
|
|
840
|
+
if (declaration.arrayFieldId !== undefined) {
|
|
841
|
+
const array = declarationsOf(compiled).get(declaration.arrayFieldId)?.field;
|
|
842
|
+
const rekeysRow = array?.rowKey?.mode === 'natural' && array.rowKey.fieldId === declaration.field.fieldId;
|
|
843
|
+
return rekeysRow ? [declaration.arrayFieldId] : [];
|
|
844
|
+
}
|
|
845
|
+
return arraysWrittenBy(compiled, declaration);
|
|
846
|
+
}
|
|
847
|
+
/** A container replacement retires every old row unlock; new rows need their own session writes. */
|
|
848
|
+
function withoutSessionArray(compiled, writes, arrayFieldId) {
|
|
849
|
+
const retained = [...writes.values()].filter((ref) => {
|
|
850
|
+
if (ref.rowKey === undefined)
|
|
851
|
+
return true;
|
|
852
|
+
return !(ref.fieldId === arrayFieldId ||
|
|
853
|
+
declarationsOf(compiled).get(ref.fieldId)?.arrayFieldId === arrayFieldId);
|
|
854
|
+
});
|
|
855
|
+
if (retained.length === writes.size)
|
|
856
|
+
return writes;
|
|
857
|
+
return new Map(retained.map((ref) => [fieldKey(ref), ref]));
|
|
858
|
+
}
|
|
859
|
+
/** Re-keys the write unlocks when a natural member or a value-identified item changes identity. */
|
|
860
|
+
function sessionWritesAfterValue(compiled, writes, declaration, ref, nextValue) {
|
|
861
|
+
if (ref.rowKey === undefined)
|
|
862
|
+
return writes;
|
|
863
|
+
const elementOfArray = declaration.arrayFieldId === undefined && declaration.field.primitive === 'array';
|
|
864
|
+
const arrayFieldId = declaration.arrayFieldId ?? (elementOfArray ? declaration.field.fieldId : undefined);
|
|
865
|
+
if (arrayFieldId === undefined)
|
|
866
|
+
return writes;
|
|
867
|
+
const array = declarationsOf(compiled).get(arrayFieldId)?.field;
|
|
868
|
+
const changesNaturalKey = array?.rowKey?.mode === 'natural' && array.rowKey.fieldId === declaration.field.fieldId;
|
|
869
|
+
const changesValueIdentity = elementOfArray && array?.rowKey === undefined;
|
|
870
|
+
if (!changesNaturalKey && !changesValueIdentity)
|
|
871
|
+
return writes;
|
|
872
|
+
const nextKey = rowKeyValue(nextValue);
|
|
873
|
+
// Identity validation has already refused a write whose new value is not a row key.
|
|
874
|
+
if (nextKey === undefined)
|
|
875
|
+
return writes;
|
|
876
|
+
return rekeySessionWrites(compiled, writes, arrayFieldId, ref.rowKey, nextKey);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Applies one operation to a working state, refusing before it mutates anything.
|
|
880
|
+
*
|
|
881
|
+
* The guard reads the derived state the control was rendered from — the same `enabled` and
|
|
882
|
+
* access answers `getField` reports — so a write the control would not have offered is the
|
|
883
|
+
* write the session refuses. Only the session's own write unlocks a stored `write_only` value.
|
|
884
|
+
*/
|
|
885
|
+
export function applyOperation(compiled, working, form, access, operation) {
|
|
886
|
+
switch (operation.kind) {
|
|
887
|
+
case 'value':
|
|
888
|
+
case 'null':
|
|
889
|
+
case 'remove': {
|
|
890
|
+
const rawRef = operation.ref;
|
|
891
|
+
const ref = rawRef.rowKey === undefined
|
|
892
|
+
? { fieldId: rawRef.fieldId }
|
|
893
|
+
: { fieldId: rawRef.fieldId, rowKey: rawRef.rowKey };
|
|
894
|
+
const declaration = declarationsOf(compiled).get(ref.fieldId);
|
|
895
|
+
if (declaration === undefined) {
|
|
896
|
+
// An operation may be handed to a session whose artifact does not declare its target.
|
|
897
|
+
// That is a caller's refusal to branch on, not a programmer error: no host can address
|
|
898
|
+
// the binding, and no access answer could permit the write.
|
|
899
|
+
return {
|
|
900
|
+
outcome: 'refused',
|
|
901
|
+
code: 'ACCESS_DENIED',
|
|
902
|
+
origin: operation.origin,
|
|
903
|
+
fieldId: ref.fieldId,
|
|
904
|
+
...(ref.rowKey === undefined ? {} : { rowKey: ref.rowKey }),
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
const field = declaration.field;
|
|
908
|
+
// Three places a value can live: a record field, one row's member of a record array, and
|
|
909
|
+
// one element of a scalar or attachment array. Each has its own domain to validate against
|
|
910
|
+
// and its own identity to resolve, and none is written as if it were another.
|
|
911
|
+
// A row reference to an array addresses one element; a field-level reference replaces the
|
|
912
|
+
// container, which is how a control that edits a multiselect or a list writes it.
|
|
913
|
+
const elementOfArray = declaration.arrayFieldId === undefined &&
|
|
914
|
+
field.primitive === 'array' &&
|
|
915
|
+
ref.rowKey !== undefined;
|
|
916
|
+
const arrayFieldId = declaration.arrayFieldId ?? (elementOfArray ? field.fieldId : undefined);
|
|
917
|
+
const index = arrayFieldId === undefined || ref.rowKey === undefined
|
|
918
|
+
? undefined
|
|
919
|
+
: rowIndexOf(compiled, working.identity, working.values, arrayFieldId, ref.rowKey);
|
|
920
|
+
if (arrayFieldId !== undefined && ref.rowKey !== undefined && index === undefined) {
|
|
921
|
+
// An array whose identity does not reconcile has no row to address; refusing it as a
|
|
922
|
+
// missing key would suggest the row exists under another name.
|
|
923
|
+
const keys = rowKeysOf(compiled, working.identity, working.values, arrayFieldId);
|
|
924
|
+
return keys === undefined
|
|
925
|
+
? { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId: arrayFieldId }
|
|
926
|
+
: {
|
|
927
|
+
outcome: 'refused',
|
|
928
|
+
code: 'ROW_KEY_NOT_FOUND',
|
|
929
|
+
fieldId: arrayFieldId,
|
|
930
|
+
rowKey: ref.rowKey,
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
if (elementOfArray && operation.kind === 'remove') {
|
|
934
|
+
// An array element is a row, and a row is removed by the structural operation that
|
|
935
|
+
// moves the manifest with it, never by a value write that would shift its siblings.
|
|
936
|
+
return {
|
|
937
|
+
outcome: 'refused',
|
|
938
|
+
code: 'ROW_UNADDRESSABLE',
|
|
939
|
+
origin: operation.origin,
|
|
940
|
+
fieldId: ref.fieldId,
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
const domain = elementOfArray ? elementDeclarationOf(field) : wireDeclarationOf(field);
|
|
944
|
+
let nextValue;
|
|
945
|
+
let normalizedOperation;
|
|
946
|
+
if (operation.kind === 'value') {
|
|
947
|
+
try {
|
|
948
|
+
const validated = toSessionWireValue(operation.value, `$.values.${ref.fieldId}`, domain);
|
|
949
|
+
nextValue = validated;
|
|
950
|
+
normalizedOperation = {
|
|
951
|
+
kind: 'value',
|
|
952
|
+
ref,
|
|
953
|
+
value: validated,
|
|
954
|
+
origin: operation.origin,
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
catch (error) {
|
|
958
|
+
return invalid(error, { fieldId: ref.fieldId });
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
else if (operation.kind === 'null') {
|
|
962
|
+
try {
|
|
963
|
+
nextValue = toSessionWireValue(null, `$.values.${ref.fieldId}`, domain);
|
|
964
|
+
normalizedOperation = { kind: 'null', ref, origin: operation.origin };
|
|
965
|
+
}
|
|
966
|
+
catch (error) {
|
|
967
|
+
return invalid(error, { fieldId: ref.fieldId });
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
normalizedOperation = { kind: 'remove', ref, origin: operation.origin };
|
|
972
|
+
}
|
|
973
|
+
const held = elementOfArray
|
|
974
|
+
? arrayElementOf(working.values, declaration, index)
|
|
975
|
+
: readDeclared(declaration, working.values, index);
|
|
976
|
+
const changed = nextValue === undefined
|
|
977
|
+
? held !== undefined
|
|
978
|
+
: held === undefined || !sameWireValue(held, nextValue);
|
|
979
|
+
// A writer owns its target: a user write there would be silently replaced by the next
|
|
980
|
+
// pass, so the session refuses it as a write access does not permit. The runtime's
|
|
981
|
+
// predicate judges origin, access and `enabled`; value ownership is the session's fact.
|
|
982
|
+
if (operation.origin === 'user' && prepareSchema(compiled).writerIds.has(ref.fieldId)) {
|
|
983
|
+
return {
|
|
984
|
+
outcome: 'refused',
|
|
985
|
+
code: 'ACCESS_DENIED',
|
|
986
|
+
origin: operation.origin,
|
|
987
|
+
fieldId: ref.fieldId,
|
|
988
|
+
...(ref.rowKey === undefined ? {} : { rowKey: ref.rowKey }),
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
const refusal = checkWrite({
|
|
992
|
+
ref,
|
|
993
|
+
origin: operation.origin,
|
|
994
|
+
access: accessOf(form, access, ref),
|
|
995
|
+
enabled: enabledOf(form, ref),
|
|
996
|
+
primitive: elementOfArray ? (field.items?.primitive ?? field.primitive) : field.primitive,
|
|
997
|
+
// A member of an array, or an element of one, exists once per row: only a row-keyed
|
|
998
|
+
// reference can address it.
|
|
999
|
+
item: declaration.arrayFieldId !== undefined || elementOfArray,
|
|
1000
|
+
changed,
|
|
1001
|
+
});
|
|
1002
|
+
if (refusal !== undefined)
|
|
1003
|
+
return refusalOf(refusal);
|
|
1004
|
+
const signature = signatureRefusal(form, access, field, held, nextValue, ref, operation.origin);
|
|
1005
|
+
if (signature !== undefined)
|
|
1006
|
+
return signature;
|
|
1007
|
+
const memberAccess = memberAccessRefusal(form, access, field, held, nextValue, ref, operation.origin, elementOfArray);
|
|
1008
|
+
if (memberAccess !== undefined)
|
|
1009
|
+
return memberAccess;
|
|
1010
|
+
// A container's value carries the members that hold it, so a record control that writes
|
|
1011
|
+
// its members wrote them in this session too: a `write_only` member the written value
|
|
1012
|
+
// holds must be readable and rule-visible from now on (`[ACCESS-1.3.1]`). A write that
|
|
1013
|
+
// replaces a whole list names no row, so it carries no member of it.
|
|
1014
|
+
let sessionWrites = withSessionWrite(working.sessionWrites, ref, operation.origin);
|
|
1015
|
+
const carriesMembers = field.primitive !== 'array' || ref.rowKey !== undefined;
|
|
1016
|
+
// Whether this write recorded a member it carried. Only a *newly* recorded member makes a
|
|
1017
|
+
// no-op write worth a pass: the rules reading it could not see it before. A container the
|
|
1018
|
+
// device could already read and that carried nothing new changes no fact at all.
|
|
1019
|
+
let carriedUnlock = false;
|
|
1020
|
+
if (nextValue !== undefined && carriesMembers) {
|
|
1021
|
+
for (const carried of carriedWriteOnly(access, field, nextValue, ref.rowKey)) {
|
|
1022
|
+
const next = withSessionWrite(sessionWrites, carried, operation.origin);
|
|
1023
|
+
if (next !== sessionWrites)
|
|
1024
|
+
carriedUnlock = true;
|
|
1025
|
+
sessionWrites = next;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
// A no-op write to a value this device may already read changes nothing; one to a value
|
|
1029
|
+
// the overlay withheld unlocks it for this session, and the rules that read it must see
|
|
1030
|
+
// the newly readable value. A redacted reference this session wrote is unlocked by
|
|
1031
|
+
// `inputOf`, so it also needs the pass a stored `write_only` value gets.
|
|
1032
|
+
const unlocked = sessionWrites !== working.sessionWrites &&
|
|
1033
|
+
(!access.field(ref).readable || carriedUnlock || access.isRedacted(ref));
|
|
1034
|
+
// Writing what committed state already holds evaluates, emits and notifies nothing
|
|
1035
|
+
// (`[ENGINE-4.1.2]`), but the guard above still ran: a user write to a signature is
|
|
1036
|
+
// refused even when it would spell the value already stored. It is still a session
|
|
1037
|
+
// write, so a `write_only` value it names is unlocked from now on, and the rules that
|
|
1038
|
+
// read it must see that.
|
|
1039
|
+
if (!changed) {
|
|
1040
|
+
return {
|
|
1041
|
+
outcome: 'ok',
|
|
1042
|
+
working: { ...working, sessionWrites },
|
|
1043
|
+
operation: normalizedOperation,
|
|
1044
|
+
fields: unlocked ? [ref.fieldId] : [],
|
|
1045
|
+
membership: [],
|
|
1046
|
+
contextRoots: [],
|
|
1047
|
+
everything: false,
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
const values = elementOfArray
|
|
1051
|
+
? writeArrayElement(working.values, declaration, index, nextValue)
|
|
1052
|
+
: writeDeclared(declaration, working.values, index, nextValue);
|
|
1053
|
+
const writtenArrays = arraysWrittenBy(compiled, declaration);
|
|
1054
|
+
// A write that cannot move a row's identity cannot break an array's identity: the row set,
|
|
1055
|
+
// its order and every key member are the ones committed state already reconciled. Only a
|
|
1056
|
+
// re-keying write — the natural key member, or the element that *is* a value-identified
|
|
1057
|
+
// row — or a container replacement, which may add, remove or reorder rows beneath it, makes
|
|
1058
|
+
// the array's addressing a question again. `membershipWritten` is that predicate, so the
|
|
1059
|
+
// write validates exactly the arrays whose identity it can have moved.
|
|
1060
|
+
for (const arrayFieldId of membershipWritten(compiled, declaration)) {
|
|
1061
|
+
// The write is complete on a copy, so every array inside it is re-derived before anything
|
|
1062
|
+
// is assigned. A record container is not a way around duplicate keys or manifest alignment.
|
|
1063
|
+
const identityRefusal = validateArrayIdentity(compiled, working.identity, values, arrayFieldId);
|
|
1064
|
+
if (identityRefusal !== undefined) {
|
|
1065
|
+
return identityRefusalOf(compiled, identityRefusal, (fieldId, rowKey) => identityFieldReadable(access, fieldId, rowKey));
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
let rekeyedWrites = sessionWritesAfterValue(compiled, sessionWrites, declaration, ref, nextValue);
|
|
1069
|
+
if (declaration.arrayFieldId === undefined && field.primitive === 'record') {
|
|
1070
|
+
// There is no positional reconciliation for a replacement container. Retire the old rows'
|
|
1071
|
+
// unlocks rather than letting a removed row's key unlock the value now occupying that key.
|
|
1072
|
+
for (const arrayFieldId of writtenArrays) {
|
|
1073
|
+
rekeyedWrites = withoutSessionArray(compiled, rekeyedWrites, arrayFieldId);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return {
|
|
1077
|
+
outcome: 'ok',
|
|
1078
|
+
working: {
|
|
1079
|
+
...working,
|
|
1080
|
+
values,
|
|
1081
|
+
sessionWrites: rekeyedWrites,
|
|
1082
|
+
},
|
|
1083
|
+
operation: normalizedOperation,
|
|
1084
|
+
fields: [ref.fieldId],
|
|
1085
|
+
membership: membershipWritten(compiled, declaration),
|
|
1086
|
+
contextRoots: [],
|
|
1087
|
+
everything: false,
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
case 'context': {
|
|
1091
|
+
const roots = indexContextRoots(compiled.context?.roots);
|
|
1092
|
+
const root = operation.root.replace(/^context\./, '');
|
|
1093
|
+
if (isReservedContextRoot(root)) {
|
|
1094
|
+
return { outcome: 'refused', code: 'UNKNOWN_CONTEXT_ROOT', root };
|
|
1095
|
+
}
|
|
1096
|
+
const declared = roots.get(root);
|
|
1097
|
+
if (declared === undefined) {
|
|
1098
|
+
return { outcome: 'refused', code: 'UNKNOWN_CONTEXT_ROOT', root };
|
|
1099
|
+
}
|
|
1100
|
+
let value;
|
|
1101
|
+
try {
|
|
1102
|
+
value = toHostWireValue(operation.value, `$.context.${root}`, {
|
|
1103
|
+
primitive: declared.primitive,
|
|
1104
|
+
...(declared.items === undefined ? {} : { items: declared.items }),
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
catch (error) {
|
|
1108
|
+
return invalid(error, { root });
|
|
1109
|
+
}
|
|
1110
|
+
const normalizedOperation = {
|
|
1111
|
+
kind: 'context',
|
|
1112
|
+
root: operation.root,
|
|
1113
|
+
value,
|
|
1114
|
+
};
|
|
1115
|
+
if (Object.hasOwn(working.context, root) &&
|
|
1116
|
+
sameWireValue(working.context[root] ?? null, value)) {
|
|
1117
|
+
return {
|
|
1118
|
+
outcome: 'ok',
|
|
1119
|
+
working,
|
|
1120
|
+
operation: normalizedOperation,
|
|
1121
|
+
fields: [],
|
|
1122
|
+
membership: [],
|
|
1123
|
+
contextRoots: [],
|
|
1124
|
+
everything: false,
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
return {
|
|
1128
|
+
outcome: 'ok',
|
|
1129
|
+
working: {
|
|
1130
|
+
...working,
|
|
1131
|
+
context: { ...working.context, [root]: value },
|
|
1132
|
+
},
|
|
1133
|
+
operation: normalizedOperation,
|
|
1134
|
+
fields: [],
|
|
1135
|
+
membership: [],
|
|
1136
|
+
contextRoots: [root],
|
|
1137
|
+
everything: false,
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
case 'env': {
|
|
1141
|
+
let env;
|
|
1142
|
+
try {
|
|
1143
|
+
env = copyEnvironment(operation.env);
|
|
1144
|
+
}
|
|
1145
|
+
catch (error) {
|
|
1146
|
+
return invalid(error);
|
|
1147
|
+
}
|
|
1148
|
+
const normalizedOperation = { kind: 'env', env };
|
|
1149
|
+
// An environment equal to the committed one (including `lookup` port identity) changes no
|
|
1150
|
+
// fact any rule reads, so it invalidates nothing (`[ENGINE-4.1.2]`).
|
|
1151
|
+
if (sameEnv(env, working.env)) {
|
|
1152
|
+
return {
|
|
1153
|
+
outcome: 'ok',
|
|
1154
|
+
working,
|
|
1155
|
+
operation: normalizedOperation,
|
|
1156
|
+
fields: [],
|
|
1157
|
+
membership: [],
|
|
1158
|
+
contextRoots: [],
|
|
1159
|
+
everything: false,
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
return {
|
|
1163
|
+
outcome: 'ok',
|
|
1164
|
+
working: { ...working, env },
|
|
1165
|
+
operation: normalizedOperation,
|
|
1166
|
+
fields: [],
|
|
1167
|
+
membership: [],
|
|
1168
|
+
contextRoots: [],
|
|
1169
|
+
everything: true,
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
case 'access': {
|
|
1173
|
+
// A session resolves one access source. Replacing a flattened projection with an overlay
|
|
1174
|
+
// would leave two answers for one reference, so the later source is refused rather than
|
|
1175
|
+
// resolved by precedence (`[ACCESS-2.1.1]`).
|
|
1176
|
+
if (working.access !== undefined) {
|
|
1177
|
+
return { outcome: 'refused', code: 'INVALID_VALUE', path: '$.overlay' };
|
|
1178
|
+
}
|
|
1179
|
+
let parsed;
|
|
1180
|
+
try {
|
|
1181
|
+
parsed = toAccessOverlay(operation.overlay, '$.overlay');
|
|
1182
|
+
}
|
|
1183
|
+
catch (error) {
|
|
1184
|
+
return invalid(error);
|
|
1185
|
+
}
|
|
1186
|
+
// The session owns the version: an overlay the host resolved is a new access answer, so
|
|
1187
|
+
// it advances by exactly one and a report can never state a version twice. Two access
|
|
1188
|
+
// operations in one batch advance twice, because each is one new answer.
|
|
1189
|
+
const prior = working.overlay?.accessVersion ?? access.version;
|
|
1190
|
+
if (!Number.isSafeInteger(prior + 1)) {
|
|
1191
|
+
return {
|
|
1192
|
+
outcome: 'refused',
|
|
1193
|
+
code: 'INVALID_VALUE',
|
|
1194
|
+
path: '$.overlay.accessVersion',
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
const next = { ...parsed, accessVersion: prior + 1 };
|
|
1198
|
+
return {
|
|
1199
|
+
outcome: 'ok',
|
|
1200
|
+
working: { ...working, overlay: next },
|
|
1201
|
+
operation: { kind: 'access', overlay: parsed },
|
|
1202
|
+
fields: [],
|
|
1203
|
+
membership: [],
|
|
1204
|
+
contextRoots: [],
|
|
1205
|
+
everything: true,
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
case 'append':
|
|
1209
|
+
case 'insert':
|
|
1210
|
+
case 'removeRow':
|
|
1211
|
+
case 'move': {
|
|
1212
|
+
const declaredArray = declarationsOf(compiled).get(operation.fieldId);
|
|
1213
|
+
if (declaredArray === undefined || declaredArray.field.primitive !== 'array') {
|
|
1214
|
+
return {
|
|
1215
|
+
outcome: 'refused',
|
|
1216
|
+
code: 'ACCESS_DENIED',
|
|
1217
|
+
origin: operation.origin,
|
|
1218
|
+
fieldId: operation.fieldId,
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
const refusal = guardStructure(compiled, access, form, operation.fieldId, operation.origin);
|
|
1222
|
+
if (refusal !== undefined)
|
|
1223
|
+
return refusal;
|
|
1224
|
+
if ((operation.kind === 'removeRow' || operation.kind === 'move') &&
|
|
1225
|
+
operation.origin === 'user' &&
|
|
1226
|
+
rowStateOf(fieldStateFor(form, operation.fieldId), operation.rowKey) === undefined &&
|
|
1227
|
+
rowIndexOf(compiled, working.identity, working.values, operation.fieldId, operation.rowKey) !== undefined) {
|
|
1228
|
+
// The private record may reconcile rows the access answer does not deliver. A user write
|
|
1229
|
+
// may name only the derived view's rows, never resolve a withheld row through that record.
|
|
1230
|
+
return {
|
|
1231
|
+
outcome: 'refused',
|
|
1232
|
+
code: 'ROW_KEY_NOT_FOUND',
|
|
1233
|
+
fieldId: operation.fieldId,
|
|
1234
|
+
rowKey: operation.rowKey,
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
const array = declaredArray.field;
|
|
1238
|
+
let checkedChange;
|
|
1239
|
+
// The item an append or insert would carry, and the row a remove would drop. Both are
|
|
1240
|
+
// container writes that can reach a nested `signature_ref`, so the structural path asks
|
|
1241
|
+
// the same guard the value path does before it mutates anything.
|
|
1242
|
+
let carried;
|
|
1243
|
+
let dropped;
|
|
1244
|
+
let normalizedOperation;
|
|
1245
|
+
if (operation.kind === 'append') {
|
|
1246
|
+
try {
|
|
1247
|
+
carried = toWireValue(operation.value, `$.values.${operation.fieldId}`, elementDeclarationOf(array));
|
|
1248
|
+
checkedChange = { kind: 'append', fieldId: operation.fieldId, value: carried };
|
|
1249
|
+
normalizedOperation = {
|
|
1250
|
+
kind: 'append',
|
|
1251
|
+
fieldId: operation.fieldId,
|
|
1252
|
+
value: carried,
|
|
1253
|
+
origin: operation.origin,
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
catch (error) {
|
|
1257
|
+
return invalid(error, { fieldId: operation.fieldId });
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
else if (operation.kind === 'insert') {
|
|
1261
|
+
try {
|
|
1262
|
+
carried = toWireValue(operation.value, `$.values.${operation.fieldId}`, elementDeclarationOf(array));
|
|
1263
|
+
checkedChange = {
|
|
1264
|
+
kind: 'insert',
|
|
1265
|
+
fieldId: operation.fieldId,
|
|
1266
|
+
index: operation.index,
|
|
1267
|
+
value: carried,
|
|
1268
|
+
};
|
|
1269
|
+
normalizedOperation = {
|
|
1270
|
+
kind: 'insert',
|
|
1271
|
+
fieldId: operation.fieldId,
|
|
1272
|
+
index: operation.index,
|
|
1273
|
+
value: carried,
|
|
1274
|
+
origin: operation.origin,
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
catch (error) {
|
|
1278
|
+
return invalid(error, { fieldId: operation.fieldId });
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
else if (operation.kind === 'removeRow') {
|
|
1282
|
+
checkedChange = { kind: 'remove', fieldId: operation.fieldId, rowKey: operation.rowKey };
|
|
1283
|
+
dropped = arrayElementOf(working.values, declarationFor(compiled, operation.fieldId), rowIndexOf(compiled, working.identity, working.values, operation.fieldId, operation.rowKey));
|
|
1284
|
+
normalizedOperation = {
|
|
1285
|
+
kind: 'removeRow',
|
|
1286
|
+
fieldId: operation.fieldId,
|
|
1287
|
+
rowKey: operation.rowKey,
|
|
1288
|
+
origin: operation.origin,
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
else {
|
|
1292
|
+
checkedChange = {
|
|
1293
|
+
kind: 'move',
|
|
1294
|
+
fieldId: operation.fieldId,
|
|
1295
|
+
rowKey: operation.rowKey,
|
|
1296
|
+
toIndex: operation.toIndex,
|
|
1297
|
+
};
|
|
1298
|
+
normalizedOperation = {
|
|
1299
|
+
kind: 'move',
|
|
1300
|
+
fieldId: operation.fieldId,
|
|
1301
|
+
rowKey: operation.rowKey,
|
|
1302
|
+
toIndex: operation.toIndex,
|
|
1303
|
+
origin: operation.origin,
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
// A user structural operation is a write to every member the row carries, in both
|
|
1307
|
+
// directions: a signature or restricted member on the way in would set one, and a signed or
|
|
1308
|
+
// restricted row on the way out would drop one. `move` changes neither, so it asks nothing.
|
|
1309
|
+
if (checkedChange.kind !== 'move') {
|
|
1310
|
+
const signature = signatureRefusal(form, access, array, dropped, carried, { fieldId: operation.fieldId }, operation.origin);
|
|
1311
|
+
if (signature !== undefined)
|
|
1312
|
+
return signature;
|
|
1313
|
+
const rowKey = checkedChange.kind === 'remove'
|
|
1314
|
+
? checkedChange.rowKey
|
|
1315
|
+
: array.rowKey?.mode === 'natural' &&
|
|
1316
|
+
array.rowKey.fieldId !== undefined &&
|
|
1317
|
+
carried !== undefined
|
|
1318
|
+
? rowKeyValue(wireMembers(carried)?.[array.rowKey.fieldId])
|
|
1319
|
+
: undefined;
|
|
1320
|
+
const memberAccess = memberAccessRefusal(form, access, array, dropped, carried, { fieldId: operation.fieldId }, operation.origin, true, rowKey);
|
|
1321
|
+
if (memberAccess !== undefined)
|
|
1322
|
+
return memberAccess;
|
|
1323
|
+
}
|
|
1324
|
+
const stepped = applyStructural(compiled, working.identity, working.values, checkedChange,
|
|
1325
|
+
// Structural operations mint ids for the new row; open and hydrate refused a session
|
|
1326
|
+
// that declares an assigned array without a factory, so one reaching here has it.
|
|
1327
|
+
working.idFactory ??
|
|
1328
|
+
(() => {
|
|
1329
|
+
throw new AxiomError('ENGINE_ERROR', `a session with an assigned array has no id factory`, 'idFactory');
|
|
1330
|
+
}));
|
|
1331
|
+
if ('outcome' in stepped) {
|
|
1332
|
+
return identityRefusalOf(compiled, stepped, (fieldId, rowKey) => identityFieldReadable(access, fieldId, rowKey));
|
|
1333
|
+
}
|
|
1334
|
+
if (stepped.values === working.values && stepped.identity === working.identity) {
|
|
1335
|
+
return {
|
|
1336
|
+
outcome: 'ok',
|
|
1337
|
+
working,
|
|
1338
|
+
operation: normalizedOperation,
|
|
1339
|
+
fields: [],
|
|
1340
|
+
membership: [],
|
|
1341
|
+
contextRoots: [],
|
|
1342
|
+
everything: false,
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
let sessionWrites = working.sessionWrites;
|
|
1346
|
+
let addedRowKey;
|
|
1347
|
+
if (checkedChange.kind === 'remove') {
|
|
1348
|
+
sessionWrites = withoutSessionRow(compiled, sessionWrites, operation.fieldId, checkedChange.rowKey);
|
|
1349
|
+
}
|
|
1350
|
+
else if (checkedChange.kind === 'append' || checkedChange.kind === 'insert') {
|
|
1351
|
+
const keys = rowKeysOf(compiled, stepped.identity, stepped.values, operation.fieldId);
|
|
1352
|
+
addedRowKey =
|
|
1353
|
+
keys?.[checkedChange.kind === 'append' ? keys.length - 1 : checkedChange.index];
|
|
1354
|
+
if (addedRowKey !== undefined) {
|
|
1355
|
+
sessionWrites = withSessionRow(compiled, sessionWrites, operation.fieldId, addedRowKey, operation.origin);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
// The row this operation gave the array, or the one it took away, with the identity the
|
|
1359
|
+
// array resolves it by. A caller reporting a change set names the row the committed state
|
|
1360
|
+
// will address rather than a position the next structural write can move.
|
|
1361
|
+
const structuralWrite = checkedChange.kind === 'append'
|
|
1362
|
+
? {
|
|
1363
|
+
kind: 'append',
|
|
1364
|
+
fieldId: checkedChange.fieldId,
|
|
1365
|
+
...(addedRowKey === undefined ? {} : { rowKey: addedRowKey }),
|
|
1366
|
+
}
|
|
1367
|
+
: checkedChange.kind === 'remove'
|
|
1368
|
+
? { kind: 'removeRow', fieldId: checkedChange.fieldId, rowKey: checkedChange.rowKey }
|
|
1369
|
+
: undefined;
|
|
1370
|
+
return {
|
|
1371
|
+
outcome: 'ok',
|
|
1372
|
+
working: {
|
|
1373
|
+
...working,
|
|
1374
|
+
values: stepped.values,
|
|
1375
|
+
identity: stepped.identity,
|
|
1376
|
+
sessionWrites,
|
|
1377
|
+
},
|
|
1378
|
+
operation: normalizedOperation,
|
|
1379
|
+
fields: [operation.fieldId],
|
|
1380
|
+
// The rows of this array are exactly what the operation moved, so every item rule over
|
|
1381
|
+
// it re-evaluates: append, insert, remove and move all redefine the row set or its
|
|
1382
|
+
// order, and `$i` is a supported binder.
|
|
1383
|
+
membership: [operation.fieldId],
|
|
1384
|
+
contextRoots: [],
|
|
1385
|
+
everything: false,
|
|
1386
|
+
...(structuralWrite === undefined ? {} : { structuralWrite }),
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
/** Whether the value supplying an identity may be delivered to this caller. */
|
|
1392
|
+
function identityFieldReadable(access, fieldId, rowKey) {
|
|
1393
|
+
return access.enclosingDelivers({ fieldId, rowKey });
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* The session refusal an identity refusal maps to. A duplicate record-derived key is named only
|
|
1397
|
+
* when its value may be delivered; a key the access answer withholds is unsupported instead,
|
|
1398
|
+
* because naming it would disclose the record value in the refusal itself (`ACCESS-7.1.6`).
|
|
1399
|
+
*/
|
|
1400
|
+
export function identityRefusalOf(compiled, refusal, isIdentityReadable) {
|
|
1401
|
+
const { code, fieldId } = refusal;
|
|
1402
|
+
if (code === 'ROW_INDEX_OUT_OF_RANGE') {
|
|
1403
|
+
return { outcome: 'refused', code, fieldId, index: refusal.index };
|
|
1404
|
+
}
|
|
1405
|
+
if (code === 'ROW_KEY_DUPLICATE') {
|
|
1406
|
+
const declaration = declarationOf(compiled, fieldId);
|
|
1407
|
+
const identityFieldId = declaration?.mode === 'natural'
|
|
1408
|
+
? declaration.field.rowKey?.fieldId
|
|
1409
|
+
: declaration?.mode === 'value'
|
|
1410
|
+
? declaration.field.fieldId
|
|
1411
|
+
: undefined;
|
|
1412
|
+
if (identityFieldId !== undefined && !isIdentityReadable(identityFieldId, refusal.rowKey)) {
|
|
1413
|
+
return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
|
|
1414
|
+
}
|
|
1415
|
+
return { outcome: 'refused', code, fieldId, rowKey: refusal.rowKey };
|
|
1416
|
+
}
|
|
1417
|
+
if (code === 'ROW_KEY_NOT_FOUND') {
|
|
1418
|
+
return { outcome: 'refused', code, fieldId, rowKey: refusal.rowKey };
|
|
1419
|
+
}
|
|
1420
|
+
return { outcome: 'refused', code, fieldId };
|
|
1421
|
+
}
|
|
1422
|
+
//# sourceMappingURL=ops.js.map
|