@jam-overture/loom 0.1.0
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 +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { everyMemberOf } from "../closed-set.js";
|
|
2
|
+
import { err, ok } from "../result.js";
|
|
3
|
+
import { describeInterpretationError } from "../runtime/interpreter.js";
|
|
4
|
+
import { narrator } from "../runtime/narration.js";
|
|
5
|
+
import { composeChange, confirmChange } from "../runtime/pipeline.js";
|
|
6
|
+
import { describeStoreError } from "../store/errors.js";
|
|
7
|
+
import { describeTreeError } from "../tree/errors.js";
|
|
8
|
+
import { describeHoldError } from "./held.js";
|
|
9
|
+
/**
|
|
10
|
+
* Every way a write can end, in the order the runtime reaches them.
|
|
11
|
+
*
|
|
12
|
+
* A `switch` over an outcome is exhaustive without this and always was. What
|
|
13
|
+
* needs a list is everything that walks the endings instead of reacting to one:
|
|
14
|
+
* a page that tells a host what it has to handle, a dashboard that wants a
|
|
15
|
+
* bucket per ending to exist before the first request arrives, a conformance
|
|
16
|
+
* check written against the write path. Each of those otherwise keeps its own
|
|
17
|
+
* copy, and a copy is a list that is silently wrong the day an eighth ending
|
|
18
|
+
* lands.
|
|
19
|
+
*
|
|
20
|
+
* The order is the order a request meets them rather than an order of severity:
|
|
21
|
+
* the two endings a healthy deployment produces, then the refusal, then the four
|
|
22
|
+
* ways a request fails to become a change at all.
|
|
23
|
+
*/
|
|
24
|
+
export const WRITE_OUTCOME_KINDS = everyMemberOf()([
|
|
25
|
+
"committed",
|
|
26
|
+
"held",
|
|
27
|
+
"refused",
|
|
28
|
+
"not-interpreted",
|
|
29
|
+
"not-applicable",
|
|
30
|
+
"not-written",
|
|
31
|
+
"not-answerable",
|
|
32
|
+
]);
|
|
33
|
+
export const describeWriteOutcome = (outcome) => {
|
|
34
|
+
switch (outcome.kind) {
|
|
35
|
+
case "committed":
|
|
36
|
+
return `applied at revision ${outcome.tree.revision}`;
|
|
37
|
+
case "held":
|
|
38
|
+
return `held for confirmation: ${outcome.held.disposition.reason.detail}`;
|
|
39
|
+
case "refused":
|
|
40
|
+
return outcome.repairFailure === undefined
|
|
41
|
+
? `refused: ${outcome.disposition.reason.detail}`
|
|
42
|
+
: `refused: ${outcome.disposition.reason.detail} — asked for something smaller, and ${describeInterpretationError(outcome.repairFailure)}`;
|
|
43
|
+
case "not-interpreted":
|
|
44
|
+
return describeInterpretationError(outcome.error);
|
|
45
|
+
case "not-applicable":
|
|
46
|
+
return `the proposal did not apply: ${describeTreeError(outcome.error)}`;
|
|
47
|
+
case "not-written":
|
|
48
|
+
return describeStoreError(outcome.error);
|
|
49
|
+
case "not-answerable":
|
|
50
|
+
return describeHoldError(outcome.error);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Reads head and refuses an intent that names a revision head has moved past.
|
|
55
|
+
*
|
|
56
|
+
* The check is here rather than left to `append` for two reasons. It saves a
|
|
57
|
+
* model call that could only produce a delta destined to be refused; and it
|
|
58
|
+
* means the interpreter is never handed a tree the asker was not looking at,
|
|
59
|
+
* which is the same rule the interpreter already follows about revisions.
|
|
60
|
+
*/
|
|
61
|
+
const readWritableHead = async (path, intent) => {
|
|
62
|
+
const head = await path.store.head(intent.treeId);
|
|
63
|
+
if (!head.ok)
|
|
64
|
+
return head;
|
|
65
|
+
if (head.value.revision !== intent.baseRevision) {
|
|
66
|
+
return err({
|
|
67
|
+
code: "revision-conflict",
|
|
68
|
+
treeId: intent.treeId,
|
|
69
|
+
expected: intent.baseRevision,
|
|
70
|
+
found: head.value.revision,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return ok(head.value);
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Persists a change the Gate accepted and the tree took.
|
|
77
|
+
*
|
|
78
|
+
* The tree returned is the store's, not the one the pipeline applied in memory:
|
|
79
|
+
* they agree, and when they ever do not, the log is the one that is right.
|
|
80
|
+
*/
|
|
81
|
+
const persist = async (path, narrate, intent, commit) => {
|
|
82
|
+
const { proposal, disposition, inverse } = commit;
|
|
83
|
+
const appended = await path.store.append(intent.treeId, {
|
|
84
|
+
proposalId: proposal.proposalId,
|
|
85
|
+
delta: proposal.delta,
|
|
86
|
+
provenance: proposal.provenance,
|
|
87
|
+
appliedAt: path.runtime.clock.now(),
|
|
88
|
+
...(commit.answeredBy === undefined ? {} : { answeredBy: commit.answeredBy }),
|
|
89
|
+
});
|
|
90
|
+
if (!appended.ok) {
|
|
91
|
+
narrate({ type: "commit-failed", proposalId: proposal.proposalId, error: appended.error });
|
|
92
|
+
return { kind: "not-written", error: appended.error };
|
|
93
|
+
}
|
|
94
|
+
narrate({
|
|
95
|
+
type: "change-committed",
|
|
96
|
+
proposalId: proposal.proposalId,
|
|
97
|
+
revision: appended.value.revision,
|
|
98
|
+
});
|
|
99
|
+
return { kind: "committed", tree: appended.value, proposal, disposition, inverse };
|
|
100
|
+
};
|
|
101
|
+
const takeIntoCustody = async (path, narrate, intent, proposal, disposition) => {
|
|
102
|
+
const held = await path.holds.hold({
|
|
103
|
+
proposalId: proposal.proposalId,
|
|
104
|
+
treeId: intent.treeId,
|
|
105
|
+
baseRevision: intent.baseRevision,
|
|
106
|
+
intent,
|
|
107
|
+
proposal,
|
|
108
|
+
disposition,
|
|
109
|
+
heldAt: path.runtime.clock.now(),
|
|
110
|
+
});
|
|
111
|
+
if (!held.ok) {
|
|
112
|
+
narrate({
|
|
113
|
+
type: "hold-failed",
|
|
114
|
+
proposalId: proposal.proposalId,
|
|
115
|
+
detail: describeHoldError(held.error),
|
|
116
|
+
});
|
|
117
|
+
return { kind: "not-answerable", error: held.error };
|
|
118
|
+
}
|
|
119
|
+
narrate({ type: "proposal-held", proposalId: proposal.proposalId });
|
|
120
|
+
return { kind: "held", held: held.value };
|
|
121
|
+
};
|
|
122
|
+
export const commitIntent = async (path, intent) => {
|
|
123
|
+
const narrate = narrator(path.runtime.events, path.runtime.clock, intent.treeId);
|
|
124
|
+
const head = await readWritableHead(path, intent);
|
|
125
|
+
if (!head.ok) {
|
|
126
|
+
narrate({ type: "intent-not-writable", intent, error: head.error });
|
|
127
|
+
return { kind: "not-written", error: head.error };
|
|
128
|
+
}
|
|
129
|
+
const outcome = await composeChange(path.runtime, head.value, intent);
|
|
130
|
+
switch (outcome.kind) {
|
|
131
|
+
case "applied":
|
|
132
|
+
return persist(path, narrate, intent, {
|
|
133
|
+
proposal: outcome.assessment.proposal,
|
|
134
|
+
disposition: outcome.disposition,
|
|
135
|
+
inverse: outcome.inverse,
|
|
136
|
+
});
|
|
137
|
+
case "awaiting-confirmation":
|
|
138
|
+
return takeIntoCustody(path, narrate, intent, outcome.assessment.proposal, outcome.disposition);
|
|
139
|
+
case "rejected":
|
|
140
|
+
return {
|
|
141
|
+
kind: "refused",
|
|
142
|
+
proposal: outcome.assessment.proposal,
|
|
143
|
+
disposition: outcome.disposition,
|
|
144
|
+
...(outcome.repairFailure === undefined ? {} : { repairFailure: outcome.repairFailure }),
|
|
145
|
+
};
|
|
146
|
+
case "not-interpreted":
|
|
147
|
+
return { kind: "not-interpreted", error: outcome.error };
|
|
148
|
+
case "not-applicable":
|
|
149
|
+
return { kind: "not-applicable", proposal: outcome.proposal, error: outcome.error };
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Answers a held proposal with yes.
|
|
154
|
+
*
|
|
155
|
+
* A hold names a revision, so a hold whose tree has moved on can never apply
|
|
156
|
+
* again — it is not stale pending a retry, it is dead. Confirming one therefore
|
|
157
|
+
* releases it and reports the conflict, rather than leaving a proposal in the
|
|
158
|
+
* queue that will refuse every time it is answered.
|
|
159
|
+
*
|
|
160
|
+
* The Gate runs again on the way through (`confirmChange`), against the tree as
|
|
161
|
+
* it stands. A human saying yes is permission to proceed, not permission to skip
|
|
162
|
+
* the check.
|
|
163
|
+
*/
|
|
164
|
+
export const confirmHeld = async (path, answer) => {
|
|
165
|
+
const { proposalId } = answer;
|
|
166
|
+
const found = await path.holds.get(proposalId);
|
|
167
|
+
if (!found.ok)
|
|
168
|
+
return { kind: "not-answerable", error: found.error };
|
|
169
|
+
const { intent, proposal } = found.value;
|
|
170
|
+
const narrate = narrator(path.runtime.events, path.runtime.clock, intent.treeId);
|
|
171
|
+
const head = await path.store.head(intent.treeId);
|
|
172
|
+
if (!head.ok)
|
|
173
|
+
return { kind: "not-written", error: head.error };
|
|
174
|
+
if (head.value.revision !== found.value.baseRevision) {
|
|
175
|
+
/** Dead rather than stale, so custody ends here whatever the caller does next. */
|
|
176
|
+
await path.holds.release(proposalId);
|
|
177
|
+
const error = {
|
|
178
|
+
code: "revision-conflict",
|
|
179
|
+
treeId: intent.treeId,
|
|
180
|
+
expected: found.value.baseRevision,
|
|
181
|
+
found: head.value.revision,
|
|
182
|
+
};
|
|
183
|
+
narrate({ type: "commit-failed", proposalId, error });
|
|
184
|
+
return { kind: "not-written", error };
|
|
185
|
+
}
|
|
186
|
+
/** The take is what makes answering happen exactly once, so it precedes the apply. */
|
|
187
|
+
const released = await path.holds.release(proposalId);
|
|
188
|
+
if (!released.ok)
|
|
189
|
+
return { kind: "not-answerable", error: released.error };
|
|
190
|
+
narrate({
|
|
191
|
+
type: "hold-confirmed",
|
|
192
|
+
proposalId,
|
|
193
|
+
...(answer.actor === undefined ? {} : { actor: answer.actor }),
|
|
194
|
+
});
|
|
195
|
+
const outcome = confirmChange(path.runtime, head.value, proposal, intent);
|
|
196
|
+
switch (outcome.kind) {
|
|
197
|
+
case "applied":
|
|
198
|
+
/**
|
|
199
|
+
* The one place `answeredBy` is set. It is the same actor the
|
|
200
|
+
* `hold-confirmed` event carries, taken from the same `ProposalAnswer`, so
|
|
201
|
+
* the two records cannot disagree about who allowed this (0029).
|
|
202
|
+
*/
|
|
203
|
+
return persist(path, narrate, intent, {
|
|
204
|
+
proposal,
|
|
205
|
+
disposition: outcome.disposition,
|
|
206
|
+
inverse: outcome.inverse,
|
|
207
|
+
...(answer.actor === undefined ? {} : { answeredBy: answer.actor }),
|
|
208
|
+
});
|
|
209
|
+
case "rejected":
|
|
210
|
+
return { kind: "refused", proposal, disposition: outcome.disposition };
|
|
211
|
+
case "not-applicable":
|
|
212
|
+
return { kind: "not-applicable", proposal: outcome.proposal, error: outcome.error };
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Answers a held proposal with no.
|
|
217
|
+
*
|
|
218
|
+
* The most informative thing a reviewer does, from §6's point of view: the Gate
|
|
219
|
+
* was willing to offer this change and a human did not want it, which is the
|
|
220
|
+
* only signal that distinguishes a policy that is too permissive from one that
|
|
221
|
+
* is calibrated.
|
|
222
|
+
*/
|
|
223
|
+
export const discardHeld = async (path, answer) => {
|
|
224
|
+
const released = await path.holds.release(answer.proposalId);
|
|
225
|
+
if (!released.ok)
|
|
226
|
+
return released;
|
|
227
|
+
narrator(path.runtime.events, path.runtime.clock, released.value.treeId)({
|
|
228
|
+
type: "hold-discarded",
|
|
229
|
+
proposalId: answer.proposalId,
|
|
230
|
+
...(answer.actor === undefined ? {} : { actor: answer.actor }),
|
|
231
|
+
});
|
|
232
|
+
return released;
|
|
233
|
+
};
|
|
234
|
+
//# sourceMappingURL=commit.js.map
|