@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,94 @@
|
|
|
1
|
+
import type { TreeId } from "../ids.js";
|
|
2
|
+
import { type Result } from "../result.js";
|
|
3
|
+
import { type IdHistory, type IdReturn } from "../tree/identity.js";
|
|
4
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
5
|
+
import type { StoreError } from "./errors.js";
|
|
6
|
+
import type { StoredRevision, TreeReader } from "./store.js";
|
|
7
|
+
/**
|
|
8
|
+
* Replay, and the audit it exists for.
|
|
9
|
+
*
|
|
10
|
+
* The snapshot is what gets read; the log is what gets trusted. Those two only
|
|
11
|
+
* stay the same thing if folding the log still produces the snapshot — and that
|
|
12
|
+
* is not free, because a stored delta encodes assumptions about how `applyDelta`
|
|
13
|
+
* behaves. §1 chose `move` semantics where `index` counts the post-detach child
|
|
14
|
+
* list; every delta ever stored is written in that dialect. Change the dialect
|
|
15
|
+
* and the log stops meaning what it meant.
|
|
16
|
+
*
|
|
17
|
+
* A pure event-sourced design cannot detect that: the fold is the read, so a
|
|
18
|
+
* drifted fold is simply the new truth. With a snapshot, replay becomes a check
|
|
19
|
+
* rather than a dependency — which is the argument for keeping both.
|
|
20
|
+
*/
|
|
21
|
+
export type ReplayMismatch = {
|
|
22
|
+
readonly code: "delta-rejected";
|
|
23
|
+
readonly revision: number;
|
|
24
|
+
readonly detail: string;
|
|
25
|
+
}
|
|
26
|
+
/** A gap or a repeat in the log: revisions must be consecutive from the seed. */
|
|
27
|
+
| {
|
|
28
|
+
readonly code: "revision-gap";
|
|
29
|
+
readonly expected: number;
|
|
30
|
+
readonly found: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A fold, and what the fold saw on the way past.
|
|
34
|
+
*
|
|
35
|
+
* The id history rides along rather than being computed by a second pass. It is
|
|
36
|
+
* derived from consecutive states (0038) and this is the only place that
|
|
37
|
+
* produces them all, so folding twice would mean reading a whole log twice to
|
|
38
|
+
* learn something the first read already went past.
|
|
39
|
+
*/
|
|
40
|
+
export type ReplayedTree = {
|
|
41
|
+
readonly tree: LoomTree;
|
|
42
|
+
readonly idHistory: IdHistory;
|
|
43
|
+
};
|
|
44
|
+
/** A whole log, from a seed the caller can prove is revision 0 (0028). */
|
|
45
|
+
export declare const replayTree: (seed: LoomTree, entries: readonly StoredRevision[]) => Result<ReplayedTree, ReplayMismatch>;
|
|
46
|
+
/**
|
|
47
|
+
* What the fold noticed about ids on the way, whatever the verdict turned out
|
|
48
|
+
* to be.
|
|
49
|
+
*
|
|
50
|
+
* Carried on both replayable outcomes rather than folded into the verdict,
|
|
51
|
+
* because it answers a different question. "Agrees" is about whether the
|
|
52
|
+
* snapshot still matches the log; a recycled id is about whether the log can be
|
|
53
|
+
* read by id at all (0038). A tree can pass the first and fail the second, and
|
|
54
|
+
* an audit that collapsed them would have to call one of those two things by the
|
|
55
|
+
* other's name.
|
|
56
|
+
*/
|
|
57
|
+
export type SnapshotAudit = {
|
|
58
|
+
readonly outcome: "agrees";
|
|
59
|
+
readonly revision: number;
|
|
60
|
+
readonly idReturns: readonly IdReturn[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The fold produced a different tree — the drift this whole module exists for.
|
|
64
|
+
*
|
|
65
|
+
* Both sides are reported, not only the replayed one. The audit read the
|
|
66
|
+
* snapshot to reach this verdict, and a caller that had to read it again to
|
|
67
|
+
* find out *how* they differ would be comparing against a head that may have
|
|
68
|
+
* moved since — so it could describe a divergence that was never the one
|
|
69
|
+
* observed. `compareTrees(stored, replayed)` turns these two into something an
|
|
70
|
+
* operator can act on.
|
|
71
|
+
*/
|
|
72
|
+
| {
|
|
73
|
+
readonly outcome: "diverged";
|
|
74
|
+
readonly revision: number;
|
|
75
|
+
readonly stored: LoomTree;
|
|
76
|
+
readonly replayed: LoomTree;
|
|
77
|
+
readonly idReturns: readonly IdReturn[];
|
|
78
|
+
} | {
|
|
79
|
+
readonly outcome: "unreplayable";
|
|
80
|
+
readonly mismatch: ReplayMismatch;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Folds a tree's log from a known seed and compares the result to the stored
|
|
84
|
+
* snapshot. A host runs this in a test or a scheduled job; nothing on a request
|
|
85
|
+
* path needs it, which is the point.
|
|
86
|
+
*
|
|
87
|
+
* The seed is a parameter rather than something the store keeps, because the
|
|
88
|
+
* honest seed is revision 0 and a store that has been compacted may no longer
|
|
89
|
+
* have it. A caller that cannot supply one cannot audit — which is a real
|
|
90
|
+
* limitation, and a better one than an audit that quietly starts from the answer
|
|
91
|
+
* it is trying to check.
|
|
92
|
+
*/
|
|
93
|
+
export declare const auditSnapshot: (store: TreeReader, treeId: TreeId, seed: LoomTree) => Promise<Result<SnapshotAudit, StoreError>>;
|
|
94
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { err, ok, reduceResult } from "../result.js";
|
|
2
|
+
import { applyDelta } from "../tree/apply.js";
|
|
3
|
+
import { idReturnsIn, seedIdHistory, trackIds } from "../tree/identity.js";
|
|
4
|
+
const replayFrom = (from, entries) => reduceResult(entries, from, (replayed, entry) => {
|
|
5
|
+
if (entry.revision !== replayed.tree.revision + 1) {
|
|
6
|
+
return err({
|
|
7
|
+
code: "revision-gap",
|
|
8
|
+
expected: replayed.tree.revision + 1,
|
|
9
|
+
found: entry.revision,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const applied = applyDelta(replayed.tree, entry.delta);
|
|
13
|
+
return applied.ok
|
|
14
|
+
? ok({
|
|
15
|
+
tree: applied.value,
|
|
16
|
+
idHistory: trackIds(replayed.idHistory, replayed.tree, applied.value),
|
|
17
|
+
})
|
|
18
|
+
: err({ code: "delta-rejected", revision: entry.revision, detail: applied.error.code });
|
|
19
|
+
});
|
|
20
|
+
/** A whole log, from a seed the caller can prove is revision 0 (0028). */
|
|
21
|
+
export const replayTree = (seed, entries) => replayFrom(seedReplay(seed), entries);
|
|
22
|
+
const seedReplay = (seed) => ({
|
|
23
|
+
tree: seed,
|
|
24
|
+
idHistory: seedIdHistory(seed),
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Folds a whole log by walking it forward one page at a time.
|
|
28
|
+
*
|
|
29
|
+
* The log is read in pages (0026), so the only caller that legitimately needs
|
|
30
|
+
* all of it walks it here rather than every caller being handed an unbounded
|
|
31
|
+
* read. Each page is folded into the tree the previous one produced, which is
|
|
32
|
+
* the same fold `replayTree` performs — a page boundary is not a semantic
|
|
33
|
+
* boundary, it is just where the read stopped.
|
|
34
|
+
*
|
|
35
|
+
* `newer` is the contract's "there is more forward of here", so following it
|
|
36
|
+
* until it is `null` visits every entry exactly once.
|
|
37
|
+
*/
|
|
38
|
+
const foldLog = async (store, treeId, from, cursor) => {
|
|
39
|
+
const page = await store.revisions(treeId, cursor === undefined ? {} : { cursor });
|
|
40
|
+
if (!page.ok)
|
|
41
|
+
return page;
|
|
42
|
+
const folded = replayFrom(from, page.value.revisions);
|
|
43
|
+
if (!folded.ok)
|
|
44
|
+
return ok(folded);
|
|
45
|
+
return page.value.newer === null
|
|
46
|
+
? ok(folded)
|
|
47
|
+
: await foldLog(store, treeId, folded.value, page.value.newer);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Folds a tree's log from a known seed and compares the result to the stored
|
|
51
|
+
* snapshot. A host runs this in a test or a scheduled job; nothing on a request
|
|
52
|
+
* path needs it, which is the point.
|
|
53
|
+
*
|
|
54
|
+
* The seed is a parameter rather than something the store keeps, because the
|
|
55
|
+
* honest seed is revision 0 and a store that has been compacted may no longer
|
|
56
|
+
* have it. A caller that cannot supply one cannot audit — which is a real
|
|
57
|
+
* limitation, and a better one than an audit that quietly starts from the answer
|
|
58
|
+
* it is trying to check.
|
|
59
|
+
*/
|
|
60
|
+
export const auditSnapshot = async (store, treeId, seed) => {
|
|
61
|
+
const head = await store.head(treeId);
|
|
62
|
+
if (!head.ok)
|
|
63
|
+
return head;
|
|
64
|
+
const folded = await foldLog(store, treeId, seedReplay(seed));
|
|
65
|
+
if (!folded.ok)
|
|
66
|
+
return folded;
|
|
67
|
+
const replayed = folded.value;
|
|
68
|
+
if (!replayed.ok)
|
|
69
|
+
return ok({ outcome: "unreplayable", mismatch: replayed.error });
|
|
70
|
+
const idReturns = idReturnsIn(replayed.value.idHistory);
|
|
71
|
+
const agrees = JSON.stringify(replayed.value.tree) === JSON.stringify(head.value);
|
|
72
|
+
return ok(agrees
|
|
73
|
+
? { outcome: "agrees", revision: head.value.revision, idReturns }
|
|
74
|
+
: {
|
|
75
|
+
outcome: "diverged",
|
|
76
|
+
revision: head.value.revision,
|
|
77
|
+
stored: head.value,
|
|
78
|
+
replayed: replayed.value.tree,
|
|
79
|
+
idReturns,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { TreeId } from "../ids.js";
|
|
2
|
+
import { type Result } from "../result.js";
|
|
3
|
+
import type { DiscardedWork } from "../runtime/proposal.js";
|
|
4
|
+
import type { TreeOperation } from "../tree/delta.js";
|
|
5
|
+
import type { TreeError } from "../tree/errors.js";
|
|
6
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
7
|
+
import type { StoreError } from "./errors.js";
|
|
8
|
+
import type { ReplayMismatch } from "./replay.js";
|
|
9
|
+
import type { StoredRevision, TreeReader } from "./store.js";
|
|
10
|
+
/**
|
|
11
|
+
* Planning a revert: reading the log to work out what undoing one of its
|
|
12
|
+
* entries would mean, without deciding anything.
|
|
13
|
+
*
|
|
14
|
+
* The plan is computed rather than stored. The inverse of every applied delta
|
|
15
|
+
* already exists at assessment time and is thrown away, and the alternative —
|
|
16
|
+
* writing it onto the revision — would put a derived value in the log beside
|
|
17
|
+
* the value it derives from, where the two can disagree and nothing is checking
|
|
18
|
+
* (0016's argument for the snapshot, applied to a place it does not earn its
|
|
19
|
+
* keep: an inverse is needed rarely, a snapshot on every render).
|
|
20
|
+
*
|
|
21
|
+
* So a revert reads the log forward from a seed, exactly as `auditSnapshot`
|
|
22
|
+
* does, and for exactly the same reason 0028 gives: the tree a delta observed
|
|
23
|
+
* is only recoverable by replaying the entries before it.
|
|
24
|
+
*
|
|
25
|
+
* This module decides nothing about whether the revert *should* happen. It
|
|
26
|
+
* produces the operations, the obstacles, and what the undo would write over;
|
|
27
|
+
* the Gate judges, as it does for any other change.
|
|
28
|
+
*/
|
|
29
|
+
export type RevertPlan = {
|
|
30
|
+
readonly outcome: "revertable";
|
|
31
|
+
readonly target: StoredRevision;
|
|
32
|
+
/**
|
|
33
|
+
* The undo, as operations. They become a delta when something applies
|
|
34
|
+
* them; the id and base revision belong to that delta, not to this plan.
|
|
35
|
+
*/
|
|
36
|
+
readonly operations: readonly TreeOperation[];
|
|
37
|
+
/** The head these operations were planned against. */
|
|
38
|
+
readonly headRevision: number;
|
|
39
|
+
/**
|
|
40
|
+
* Revisions after the target that named a node this undo touches, so
|
|
41
|
+
* applying it writes over what they did. Empty for a clean undo.
|
|
42
|
+
*
|
|
43
|
+
* A property of the plan rather than a verdict about it (0035): the Gate
|
|
44
|
+
* decides what a contested undo is worth, and it decides it from this,
|
|
45
|
+
* carried on the proposal. It travels with the plan because the delta
|
|
46
|
+
* cannot show it — undoing revision 1 looks identical whether or not
|
|
47
|
+
* anyone built on it.
|
|
48
|
+
*/
|
|
49
|
+
readonly discards: readonly DiscardedWork[];
|
|
50
|
+
}
|
|
51
|
+
/** The revision is outside the span this reader and this seed can reach. */
|
|
52
|
+
| {
|
|
53
|
+
readonly outcome: "out-of-range";
|
|
54
|
+
readonly revision: number;
|
|
55
|
+
/** One past the seed: the oldest revision this seed can replay up to. */
|
|
56
|
+
readonly earliest: number;
|
|
57
|
+
readonly headRevision: number;
|
|
58
|
+
} | {
|
|
59
|
+
readonly outcome: "unreplayable";
|
|
60
|
+
readonly mismatch: ReplayMismatch;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The target's delta cannot be inverted against the tree the replay produced.
|
|
64
|
+
* In practice this means the seed is not this tree's history: inversion walks
|
|
65
|
+
* the delta forward as it inverts, so a delta that applied when it was written
|
|
66
|
+
* inverts against the state it was written for.
|
|
67
|
+
*/
|
|
68
|
+
| {
|
|
69
|
+
readonly outcome: "uninvertible";
|
|
70
|
+
readonly revision: number;
|
|
71
|
+
readonly error: TreeError;
|
|
72
|
+
};
|
|
73
|
+
export type UnrevertablePlan = Exclude<RevertPlan, {
|
|
74
|
+
readonly outcome: "revertable";
|
|
75
|
+
}>;
|
|
76
|
+
export declare const describeRevertPlan: (plan: RevertPlan) => string;
|
|
77
|
+
export type RevertTarget = {
|
|
78
|
+
readonly treeId: TreeId;
|
|
79
|
+
/** The revision to undo. Its delta is the one that gets inverted. */
|
|
80
|
+
readonly revision: number;
|
|
81
|
+
/**
|
|
82
|
+
* A tree whose revision precedes the target's, to replay from. Usually
|
|
83
|
+
* revision 0; a host that checkpoints may supply a later one (0028).
|
|
84
|
+
*/
|
|
85
|
+
readonly seed: LoomTree;
|
|
86
|
+
};
|
|
87
|
+
/** The same question asked about several revisions of one tree, in one read. */
|
|
88
|
+
export type RevertTargets = {
|
|
89
|
+
readonly treeId: TreeId;
|
|
90
|
+
readonly revisions: readonly number[];
|
|
91
|
+
readonly seed: LoomTree;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* What undoing a revision would take, or what stands in the way.
|
|
95
|
+
*
|
|
96
|
+
* A `StoreError` means the log could not be read. Everything else is a verdict
|
|
97
|
+
* about the revert itself, which is why the obstacles are values in the plan
|
|
98
|
+
* rather than errors: "this revision was built on since" is an answer, not a
|
|
99
|
+
* failure.
|
|
100
|
+
*/
|
|
101
|
+
export declare const planRevert: (reader: TreeReader, target: RevertTarget) => Promise<Result<RevertPlan, StoreError>>;
|
|
102
|
+
/**
|
|
103
|
+
* The same plans for several revisions, from one read of the log.
|
|
104
|
+
*
|
|
105
|
+
* Each plan is exactly what `planRevert` would have produced for that revision
|
|
106
|
+
* on its own — the batch changes what it costs to ask, never what the answer
|
|
107
|
+
* is. A page of history is the case it exists for: the forward replay is walked
|
|
108
|
+
* once for all of them, and only the head-ward trail, which genuinely differs
|
|
109
|
+
* per target, is tracked per target.
|
|
110
|
+
*
|
|
111
|
+
* Revisions are keyed rather than positional so a caller can ask about the rows
|
|
112
|
+
* it is showing and read the answers back by revision; asking twice about one
|
|
113
|
+
* revision costs nothing and answers once.
|
|
114
|
+
*/
|
|
115
|
+
export declare const planReverts: (reader: TreeReader, targets: RevertTargets) => Promise<Result<ReadonlyMap<number, RevertPlan>, StoreError>>;
|
|
116
|
+
//# sourceMappingURL=revert.d.ts.map
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { ok } from "../result.js";
|
|
2
|
+
import { applyDelta } from "../tree/apply.js";
|
|
3
|
+
import { invertOperations } from "../tree/inverse.js";
|
|
4
|
+
import { namedNodeIds } from "../tree/naming.js";
|
|
5
|
+
export const describeRevertPlan = (plan) => {
|
|
6
|
+
switch (plan.outcome) {
|
|
7
|
+
case "revertable":
|
|
8
|
+
return plan.discards.length === 0
|
|
9
|
+
? `revision ${plan.target.revision} can be undone at head ${plan.headRevision}`
|
|
10
|
+
: `revision ${plan.target.revision} can be undone at head ${plan.headRevision}, discarding what revision${plan.discards.length === 1 ? "" : "s"} ${plan.discards
|
|
11
|
+
.map((discarded) => discarded.revision)
|
|
12
|
+
.join(", ")} did to the nodes it touches`;
|
|
13
|
+
case "out-of-range":
|
|
14
|
+
return `revision ${plan.revision} is outside ${plan.earliest}–${plan.headRevision}`;
|
|
15
|
+
case "unreplayable":
|
|
16
|
+
return plan.mismatch.code === "revision-gap"
|
|
17
|
+
? `the log jumps from ${plan.mismatch.expected - 1} to ${plan.mismatch.found}`
|
|
18
|
+
: `revision ${plan.mismatch.revision} no longer applies: ${plan.mismatch.detail}`;
|
|
19
|
+
case "uninvertible":
|
|
20
|
+
return `revision ${plan.revision} cannot be inverted: ${plan.error.code}`;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The undo's own reach, plus the target delta's.
|
|
25
|
+
*
|
|
26
|
+
* Both halves are needed. The undo of a removal is an insert carrying the whole
|
|
27
|
+
* subtree, so only the inverse names what the removal destroyed; the undo of an
|
|
28
|
+
* insert is a bare remove, so only the original names what was inserted.
|
|
29
|
+
*/
|
|
30
|
+
const reachOf = (target, operations) => new Set([...namedNodeIds(target.delta.operations), ...namedNodeIds(operations)]);
|
|
31
|
+
const withoutRevision = (seeking, revision) => new Set([...seeking].filter((wanted) => wanted !== revision));
|
|
32
|
+
const trailed = (trails, entry) => {
|
|
33
|
+
if (trails.size === 0)
|
|
34
|
+
return trails;
|
|
35
|
+
const named = namedNodeIds(entry.delta.operations);
|
|
36
|
+
return new Map([...trails].map(([revision, trail]) => {
|
|
37
|
+
const overlap = named.filter((nodeId) => trail.named.has(nodeId));
|
|
38
|
+
return [
|
|
39
|
+
revision,
|
|
40
|
+
overlap.length === 0
|
|
41
|
+
? trail
|
|
42
|
+
: {
|
|
43
|
+
...trail,
|
|
44
|
+
discards: [...trail.discards, { revision: entry.revision, nodeIds: overlap }],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
const withTrail = (scan, replay, entry) => {
|
|
50
|
+
const inverted = invertOperations(replay.tree, entry.delta);
|
|
51
|
+
return inverted.ok
|
|
52
|
+
? {
|
|
53
|
+
...scan,
|
|
54
|
+
trails: new Map([
|
|
55
|
+
...scan.trails,
|
|
56
|
+
[
|
|
57
|
+
entry.revision,
|
|
58
|
+
{
|
|
59
|
+
target: entry,
|
|
60
|
+
operations: inverted.value,
|
|
61
|
+
named: reachOf(entry, inverted.value),
|
|
62
|
+
discards: [],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
]),
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
...scan,
|
|
69
|
+
uninvertible: new Map([...scan.uninvertible, [entry.revision, inverted.error]]),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/** Advances the replay past an entry, or records why it cannot go further. */
|
|
73
|
+
const advanced = (scan, replay, entry) => {
|
|
74
|
+
const seeking = withoutRevision(replay.seeking, entry.revision);
|
|
75
|
+
if (seeking.size === 0)
|
|
76
|
+
return { ...scan, replay: null };
|
|
77
|
+
const applied = applyDelta(replay.tree, entry.delta);
|
|
78
|
+
return applied.ok
|
|
79
|
+
? { ...scan, replay: { tree: applied.value, seeking } }
|
|
80
|
+
: {
|
|
81
|
+
...scan,
|
|
82
|
+
replay: null,
|
|
83
|
+
stopped: {
|
|
84
|
+
code: "delta-rejected",
|
|
85
|
+
revision: entry.revision,
|
|
86
|
+
detail: applied.error.code,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const stepScan = (scan, entry) => {
|
|
91
|
+
if (entry.revision !== scan.nextRevision) {
|
|
92
|
+
return {
|
|
93
|
+
...scan,
|
|
94
|
+
halted: { code: "revision-gap", expected: scan.nextRevision, found: entry.revision },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const trailing = {
|
|
98
|
+
...scan,
|
|
99
|
+
nextRevision: entry.revision + 1,
|
|
100
|
+
trails: trailed(scan.trails, entry),
|
|
101
|
+
};
|
|
102
|
+
if (trailing.replay === null)
|
|
103
|
+
return trailing;
|
|
104
|
+
const reached = trailing.replay.seeking.has(entry.revision)
|
|
105
|
+
? withTrail(trailing, trailing.replay, entry)
|
|
106
|
+
: trailing;
|
|
107
|
+
return advanced(reached, trailing.replay, entry);
|
|
108
|
+
};
|
|
109
|
+
/** Nothing left to reach and nothing left to trail: further pages cannot change an answer. */
|
|
110
|
+
const settled = (scan) => scan.halted !== null || (scan.replay === null && scan.trails.size === 0);
|
|
111
|
+
/**
|
|
112
|
+
* Walks the log forward one page at a time, in one pass: replaying up to each
|
|
113
|
+
* named revision, inverting it, then checking everything after it for overlap.
|
|
114
|
+
*
|
|
115
|
+
* One pass rather than three because the three questions are answered at
|
|
116
|
+
* different points of the same sequence, and reading it three times would give
|
|
117
|
+
* three answers about three moments of a log that is still being appended to.
|
|
118
|
+
* One pass for *every* named revision rather than one pass each, because the
|
|
119
|
+
* forward replay a second target needs is the one the first already walked —
|
|
120
|
+
* the reason a page of history costs one read here and `rows × head` when the
|
|
121
|
+
* question is asked a row at a time.
|
|
122
|
+
*
|
|
123
|
+
* Entries at or before the seed are skipped rather than folded — a checkpoint
|
|
124
|
+
* seed already contains them, and a walk that refused them would make the seed
|
|
125
|
+
* parameter useless for anything but revision 0.
|
|
126
|
+
*/
|
|
127
|
+
const scanLog = async (reader, treeId, seedRevision, scan, cursor) => {
|
|
128
|
+
const page = await reader.revisions(treeId, cursor === undefined ? {} : { cursor });
|
|
129
|
+
if (!page.ok)
|
|
130
|
+
return page;
|
|
131
|
+
const walked = page.value.revisions
|
|
132
|
+
.filter((entry) => entry.revision > seedRevision)
|
|
133
|
+
.reduce((current, entry) => (settled(current) ? current : stepScan(current, entry)), scan);
|
|
134
|
+
return page.value.newer === null || settled(walked)
|
|
135
|
+
? ok(walked)
|
|
136
|
+
: await scanLog(reader, treeId, seedRevision, walked, page.value.newer);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Reads head, then walks the log once for every revision worth walking for.
|
|
140
|
+
*
|
|
141
|
+
* A revision outside the span needs no read at all, so a survey asked only
|
|
142
|
+
* about those never opens the log — which is what makes planning one
|
|
143
|
+
* out-of-range revision as cheap in a batch as it is alone.
|
|
144
|
+
*/
|
|
145
|
+
const surveyLog = async (reader, targets) => {
|
|
146
|
+
const head = await reader.head(targets.treeId);
|
|
147
|
+
if (!head.ok)
|
|
148
|
+
return head;
|
|
149
|
+
const earliest = targets.seed.revision + 1;
|
|
150
|
+
const headRevision = head.value.revision;
|
|
151
|
+
const seeking = new Set(targets.revisions.filter((revision) => revision >= earliest && revision <= headRevision));
|
|
152
|
+
const scan = {
|
|
153
|
+
nextRevision: earliest,
|
|
154
|
+
replay: seeking.size === 0 ? null : { tree: targets.seed, seeking },
|
|
155
|
+
trails: new Map(),
|
|
156
|
+
uninvertible: new Map(),
|
|
157
|
+
stopped: null,
|
|
158
|
+
halted: null,
|
|
159
|
+
};
|
|
160
|
+
if (seeking.size === 0)
|
|
161
|
+
return ok({ scan, earliest, headRevision });
|
|
162
|
+
const walked = await scanLog(reader, targets.treeId, targets.seed.revision, scan);
|
|
163
|
+
return walked.ok ? ok({ scan: walked.value, earliest, headRevision }) : walked;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* What one revision's plan is, given a walk that was told to look for it.
|
|
167
|
+
*
|
|
168
|
+
* The order the cases are read in is the order the walk would have met them
|
|
169
|
+
* planning that revision alone, which is what makes a batched plan the same
|
|
170
|
+
* answer as a solitary one: a target that could not be inverted was decided
|
|
171
|
+
* before any later break in the log, a target that was reached is only undone
|
|
172
|
+
* by a break *after* it, and a target that was never reached takes whichever
|
|
173
|
+
* obstacle came first.
|
|
174
|
+
*/
|
|
175
|
+
const planFrom = (context, revision) => {
|
|
176
|
+
const { scan, earliest, headRevision } = context;
|
|
177
|
+
if (revision < earliest || revision > headRevision) {
|
|
178
|
+
return { outcome: "out-of-range", revision, earliest, headRevision };
|
|
179
|
+
}
|
|
180
|
+
const error = scan.uninvertible.get(revision);
|
|
181
|
+
if (error !== undefined)
|
|
182
|
+
return { outcome: "uninvertible", revision, error };
|
|
183
|
+
const trail = scan.trails.get(revision);
|
|
184
|
+
if (trail !== undefined) {
|
|
185
|
+
return scan.halted === null
|
|
186
|
+
? {
|
|
187
|
+
outcome: "revertable",
|
|
188
|
+
target: trail.target,
|
|
189
|
+
operations: trail.operations,
|
|
190
|
+
headRevision,
|
|
191
|
+
discards: trail.discards,
|
|
192
|
+
}
|
|
193
|
+
: { outcome: "unreplayable", mismatch: scan.halted };
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
outcome: "unreplayable",
|
|
197
|
+
mismatch: scan.stopped ??
|
|
198
|
+
scan.halted ?? {
|
|
199
|
+
code: "revision-gap",
|
|
200
|
+
expected: scan.nextRevision,
|
|
201
|
+
found: headRevision,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* What undoing a revision would take, or what stands in the way.
|
|
207
|
+
*
|
|
208
|
+
* A `StoreError` means the log could not be read. Everything else is a verdict
|
|
209
|
+
* about the revert itself, which is why the obstacles are values in the plan
|
|
210
|
+
* rather than errors: "this revision was built on since" is an answer, not a
|
|
211
|
+
* failure.
|
|
212
|
+
*/
|
|
213
|
+
export const planRevert = async (reader, target) => {
|
|
214
|
+
const surveyed = await surveyLog(reader, {
|
|
215
|
+
treeId: target.treeId,
|
|
216
|
+
revisions: [target.revision],
|
|
217
|
+
seed: target.seed,
|
|
218
|
+
});
|
|
219
|
+
return surveyed.ok ? ok(planFrom(surveyed.value, target.revision)) : surveyed;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* The same plans for several revisions, from one read of the log.
|
|
223
|
+
*
|
|
224
|
+
* Each plan is exactly what `planRevert` would have produced for that revision
|
|
225
|
+
* on its own — the batch changes what it costs to ask, never what the answer
|
|
226
|
+
* is. A page of history is the case it exists for: the forward replay is walked
|
|
227
|
+
* once for all of them, and only the head-ward trail, which genuinely differs
|
|
228
|
+
* per target, is tracked per target.
|
|
229
|
+
*
|
|
230
|
+
* Revisions are keyed rather than positional so a caller can ask about the rows
|
|
231
|
+
* it is showing and read the answers back by revision; asking twice about one
|
|
232
|
+
* revision costs nothing and answers once.
|
|
233
|
+
*/
|
|
234
|
+
export const planReverts = async (reader, targets) => {
|
|
235
|
+
const surveyed = await surveyLog(reader, targets);
|
|
236
|
+
if (!surveyed.ok)
|
|
237
|
+
return surveyed;
|
|
238
|
+
return ok(new Map([...new Set(targets.revisions)].map((revision) => [
|
|
239
|
+
revision,
|
|
240
|
+
planFrom(surveyed.value, revision),
|
|
241
|
+
])));
|
|
242
|
+
};
|
|
243
|
+
//# sourceMappingURL=revert.js.map
|