@jam-overture/loom 0.1.0 → 0.3.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/README.md +3 -1
- package/dist/application/application.d.ts +109 -0
- package/dist/application/application.js +97 -0
- package/dist/application/memory.d.ts +20 -0
- package/dist/application/memory.js +79 -0
- package/dist/application/store.d.ts +101 -0
- package/dist/application/store.js +25 -0
- package/dist/audience/audience.d.ts +36 -0
- package/dist/audience/audience.js +41 -0
- package/dist/audience/compose.d.ts +112 -0
- package/dist/audience/compose.js +134 -0
- package/dist/audience/memory.d.ts +14 -0
- package/dist/audience/memory.js +71 -0
- package/dist/audience/overlay-store.d.ts +343 -0
- package/dist/audience/overlay-store.js +217 -0
- package/dist/audience/rule.d.ts +121 -0
- package/dist/audience/rule.js +78 -0
- package/dist/cli/index.d.ts +3 -4
- package/dist/cli/index.js +3 -4
- package/dist/cli/templates.js +19 -0
- package/dist/data/adapter.d.ts +9 -1
- package/dist/data/adapter.js +2 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +23 -1
- package/dist/data/resolve.d.ts +31 -4
- package/dist/data/resolve.js +11 -3
- package/dist/ids.d.ts +10 -0
- package/dist/ids.js +11 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpretation/anthropic.d.ts +1 -1
- package/dist/interpretation/anthropic.js +2 -22
- package/dist/interpretation/client.d.ts +1 -1
- package/dist/interpretation/materialize.js +67 -22
- package/dist/interpretation/openai-compatible.d.ts +36 -0
- package/dist/interpretation/openai-compatible.js +79 -0
- package/dist/interpretation/status.d.ts +19 -0
- package/dist/interpretation/status.js +26 -0
- package/dist/live/index.d.ts +73 -0
- package/dist/live/index.js +73 -0
- package/dist/live/pages.d.ts +187 -0
- package/dist/live/pages.js +161 -0
- package/dist/live/pull.d.ts +147 -0
- package/dist/live/pull.js +398 -0
- package/dist/live/pulling.d.ts +79 -0
- package/dist/live/pulling.js +117 -0
- package/dist/live/window.d.ts +129 -0
- package/dist/live/window.js +132 -0
- package/dist/patch.d.ts +54 -0
- package/dist/patch.js +44 -0
- package/dist/project/closing.d.ts +51 -0
- package/dist/project/closing.js +53 -0
- package/dist/project/memory.d.ts +20 -0
- package/dist/project/memory.js +97 -0
- package/dist/project/project.d.ts +90 -0
- package/dist/project/project.js +91 -0
- package/dist/project/store.d.ts +135 -0
- package/dist/project/store.js +41 -0
- package/dist/registered.d.ts +64 -0
- package/dist/registered.js +118 -0
- package/dist/render/addressed.d.ts +35 -0
- package/dist/render/addressed.js +79 -0
- package/dist/render/behaviour-adjust.d.ts +11 -19
- package/dist/render/behaviour-adjust.js +75 -21
- package/dist/render/behaviour-present.d.ts +8 -0
- package/dist/render/behaviour-present.js +57 -6
- package/dist/render/behaviour.d.ts +98 -17
- package/dist/render/behaviour.js +91 -26
- package/dist/render/control-name.d.ts +68 -0
- package/dist/render/control-name.js +37 -0
- package/dist/render/diagnostics.d.ts +72 -0
- package/dist/render/diagnostics.js +7 -0
- package/dist/render/document-theme.d.ts +70 -0
- package/dist/render/document-theme.js +139 -0
- package/dist/render/editable.d.ts +15 -1
- package/dist/render/editable.js +13 -1
- package/dist/render/expected.d.ts +98 -0
- package/dist/render/expected.js +88 -0
- package/dist/render/index.d.ts +4 -0
- package/dist/render/index.js +4 -0
- package/dist/render/reads.d.ts +11 -0
- package/dist/render/reads.js +12 -1
- package/dist/render/render.d.ts +11 -0
- package/dist/render/render.js +294 -53
- package/dist/render/request.d.ts +8 -1
- package/dist/render/request.js +1 -0
- package/dist/render/slots.d.ts +52 -0
- package/dist/render/slots.js +24 -0
- package/dist/render/theme.d.ts +54 -1
- package/dist/render/theme.js +23 -1
- package/dist/render/unshown.d.ts +152 -0
- package/dist/render/unshown.js +80 -0
- package/dist/runtime/analysis.d.ts +94 -9
- package/dist/runtime/analysis.js +54 -9
- package/dist/runtime/assessment.d.ts +36 -2
- package/dist/runtime/assessment.js +27 -2
- package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
- package/dist/runtime/auto-apply-ceiling.js +66 -0
- package/dist/runtime/checks.d.ts +148 -0
- package/dist/runtime/checks.js +112 -0
- package/dist/runtime/disposition.d.ts +96 -0
- package/dist/runtime/disposition.js +46 -0
- package/dist/runtime/gate.js +91 -10
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/irreversibility.d.ts +64 -0
- package/dist/runtime/irreversibility.js +45 -0
- package/dist/runtime/nesting.d.ts +13 -1
- package/dist/runtime/nesting.js +41 -24
- package/dist/runtime/pipeline.d.ts +43 -0
- package/dist/runtime/pipeline.js +10 -2
- package/dist/runtime/policy-change.d.ts +93 -0
- package/dist/runtime/policy-change.js +305 -0
- package/dist/runtime/policy-log.d.ts +406 -0
- package/dist/runtime/policy-log.js +285 -0
- package/dist/runtime/policy.d.ts +8 -6
- package/dist/runtime/policy.js +5 -2
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +11 -9
- package/dist/runtime/stakes.d.ts +129 -1
- package/dist/runtime/stakes.js +240 -26
- package/dist/runtime/vocabulary.d.ts +164 -7
- package/dist/runtime/vocabulary.js +181 -8
- package/dist/sdk/audit.d.ts +174 -3
- package/dist/sdk/audit.js +176 -17
- package/dist/sdk/catalogue.d.ts +9 -1
- package/dist/sdk/conformance.d.ts +37 -3
- package/dist/sdk/conformance.js +25 -4
- package/dist/sdk/definition.d.ts +129 -5
- package/dist/sdk/definition.js +66 -0
- package/dist/sdk/registry.d.ts +45 -2
- package/dist/sdk/registry.js +102 -1
- package/dist/signals/acted.contract.d.ts +21 -0
- package/dist/signals/acted.contract.js +236 -0
- package/dist/signals/acted.d.ts +359 -0
- package/dist/signals/acted.js +135 -0
- package/dist/signals/action-change.d.ts +507 -0
- package/dist/signals/action-change.js +265 -0
- package/dist/signals/action.d.ts +331 -0
- package/dist/signals/action.js +182 -0
- package/dist/signals/agenda.d.ts +585 -0
- package/dist/signals/agenda.js +295 -0
- package/dist/signals/applied-window.contract.d.ts +23 -0
- package/dist/signals/applied-window.contract.js +160 -0
- package/dist/signals/arrivals.contract.d.ts +21 -0
- package/dist/signals/arrivals.contract.js +180 -0
- package/dist/signals/arrivals.d.ts +375 -0
- package/dist/signals/arrivals.js +254 -0
- package/dist/signals/arriving.d.ts +210 -0
- package/dist/signals/arriving.js +133 -0
- package/dist/signals/audiences.d.ts +528 -0
- package/dist/signals/audiences.js +255 -0
- package/dist/signals/broadcast.d.ts +33 -17
- package/dist/signals/broadcast.js +255 -32
- package/dist/signals/change.d.ts +378 -0
- package/dist/signals/change.js +327 -0
- package/dist/signals/collect.d.ts +169 -34
- package/dist/signals/collect.js +186 -38
- package/dist/signals/conversion.d.ts +348 -0
- package/dist/signals/conversion.js +235 -0
- package/dist/signals/copy-change.d.ts +553 -0
- package/dist/signals/copy-change.js +377 -0
- package/dist/signals/copy.d.ts +337 -0
- package/dist/signals/copy.js +211 -0
- package/dist/signals/correlated.contract.d.ts +24 -0
- package/dist/signals/correlated.contract.js +94 -0
- package/dist/signals/counters.d.ts +97 -0
- package/dist/signals/counters.js +160 -0
- package/dist/signals/deliver.d.ts +23 -4
- package/dist/signals/deliver.js +34 -6
- package/dist/signals/deployment-change.d.ts +395 -0
- package/dist/signals/deployment-change.js +309 -0
- package/dist/signals/deployment.d.ts +278 -0
- package/dist/signals/deployment.js +178 -0
- package/dist/signals/door.d.ts +114 -0
- package/dist/signals/door.js +77 -0
- package/dist/signals/expire.d.ts +192 -0
- package/dist/signals/expire.js +213 -0
- package/dist/signals/fold.d.ts +10 -0
- package/dist/signals/fold.js +5 -1
- package/dist/signals/form-action.d.ts +302 -0
- package/dist/signals/form-action.js +169 -0
- package/dist/signals/form-copy.d.ts +523 -0
- package/dist/signals/form-copy.js +346 -0
- package/dist/signals/forms.d.ts +247 -0
- package/dist/signals/forms.js +147 -0
- package/dist/signals/frontier.d.ts +268 -0
- package/dist/signals/frontier.js +145 -0
- package/dist/signals/funnel-change.d.ts +548 -0
- package/dist/signals/funnel-change.js +361 -0
- package/dist/signals/funnel-hours.contract.d.ts +21 -0
- package/dist/signals/funnel-hours.contract.js +221 -0
- package/dist/signals/funnel-hours.d.ts +293 -0
- package/dist/signals/funnel-hours.js +99 -0
- package/dist/signals/funnel.d.ts +592 -0
- package/dist/signals/funnel.js +231 -0
- package/dist/signals/health.d.ts +694 -0
- package/dist/signals/health.js +573 -0
- package/dist/signals/index.d.ts +60 -0
- package/dist/signals/index.js +60 -0
- package/dist/signals/ingest.d.ts +56 -1
- package/dist/signals/ingest.js +91 -1
- package/dist/signals/inside.d.ts +190 -0
- package/dist/signals/inside.js +263 -0
- package/dist/signals/join.d.ts +56 -0
- package/dist/signals/join.js +60 -0
- package/dist/signals/journal.d.ts +123 -9
- package/dist/signals/kept.contract.d.ts +22 -0
- package/dist/signals/kept.contract.js +111 -0
- package/dist/signals/kinds.d.ts +8 -6
- package/dist/signals/kinds.js +14 -6
- package/dist/signals/library-action.d.ts +430 -0
- package/dist/signals/library-action.js +336 -0
- package/dist/signals/library-agenda-change.d.ts +324 -0
- package/dist/signals/library-agenda-change.js +199 -0
- package/dist/signals/library-agenda.d.ts +258 -0
- package/dist/signals/library-agenda.js +167 -0
- package/dist/signals/library-change.d.ts +477 -0
- package/dist/signals/library-change.js +335 -0
- package/dist/signals/library-copy-change.d.ts +498 -0
- package/dist/signals/library-copy-change.js +476 -0
- package/dist/signals/library-pace.d.ts +319 -0
- package/dist/signals/library-pace.js +305 -0
- package/dist/signals/library-reach-change.d.ts +646 -0
- package/dist/signals/library-reach-change.js +542 -0
- package/dist/signals/library-reach.d.ts +377 -0
- package/dist/signals/library-reach.js +227 -0
- package/dist/signals/library-senders-change.d.ts +457 -0
- package/dist/signals/library-senders-change.js +367 -0
- package/dist/signals/library-senders-reach-change.d.ts +486 -0
- package/dist/signals/library-senders-reach-change.js +538 -0
- package/dist/signals/library-senders-reach.d.ts +340 -0
- package/dist/signals/library-senders-reach.js +252 -0
- package/dist/signals/library-senders.d.ts +271 -0
- package/dist/signals/library-senders.js +180 -0
- package/dist/signals/library-word-reach-change.d.ts +567 -0
- package/dist/signals/library-word-reach-change.js +564 -0
- package/dist/signals/library.d.ts +306 -0
- package/dist/signals/library.js +178 -0
- package/dist/signals/memory.d.ts +9 -0
- package/dist/signals/memory.js +246 -14
- package/dist/signals/migrate.d.ts +20 -4
- package/dist/signals/migrate.js +269 -8
- package/dist/signals/notice.d.ts +389 -0
- package/dist/signals/notice.js +250 -0
- package/dist/signals/pace-change.d.ts +501 -0
- package/dist/signals/pace-change.js +310 -0
- package/dist/signals/pace.d.ts +296 -0
- package/dist/signals/pace.js +291 -0
- package/dist/signals/page-views.d.ts +365 -0
- package/dist/signals/page-views.js +218 -0
- package/dist/signals/part-pace.d.ts +378 -0
- package/dist/signals/part-pace.js +333 -0
- package/dist/signals/parts.d.ts +354 -0
- package/dist/signals/parts.js +232 -0
- package/dist/signals/postgres.d.ts +16 -2
- package/dist/signals/postgres.js +753 -76
- package/dist/signals/progress.d.ts +212 -0
- package/dist/signals/progress.js +150 -0
- package/dist/signals/ratios.d.ts +108 -0
- package/dist/signals/ratios.js +40 -0
- package/dist/signals/reach.d.ts +309 -0
- package/dist/signals/reach.js +93 -0
- package/dist/signals/readable.d.ts +34 -0
- package/dist/signals/readable.js +34 -0
- package/dist/signals/readership.d.ts +381 -0
- package/dist/signals/readership.js +308 -0
- package/dist/signals/region-pages.d.ts +173 -0
- package/dist/signals/region-pages.js +62 -0
- package/dist/signals/region.d.ts +287 -0
- package/dist/signals/region.js +198 -0
- package/dist/signals/retention.d.ts +163 -0
- package/dist/signals/retention.js +75 -0
- package/dist/signals/rhythm.d.ts +302 -0
- package/dist/signals/rhythm.js +262 -0
- package/dist/signals/rollup.d.ts +194 -4
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +1069 -1
- package/dist/signals/schema.js +393 -3
- package/dist/signals/signal.d.ts +237 -11
- package/dist/signals/signal.js +70 -10
- package/dist/signals/silence-census.d.ts +205 -0
- package/dist/signals/silence-census.js +87 -0
- package/dist/signals/silences.d.ts +1147 -0
- package/dist/signals/silences.js +996 -0
- package/dist/signals/subtrees.d.ts +123 -0
- package/dist/signals/subtrees.js +102 -0
- package/dist/signals/tally.d.ts +262 -12
- package/dist/signals/unread.d.ts +292 -0
- package/dist/signals/unread.js +137 -0
- package/dist/signals/window-agenda.d.ts +276 -0
- package/dist/signals/window-agenda.js +83 -0
- package/dist/signals/window-figures.d.ts +148 -0
- package/dist/signals/window-figures.js +42 -0
- package/dist/signals/window-funnels.d.ts +88 -0
- package/dist/signals/window-funnels.js +47 -0
- package/dist/signals/window.d.ts +866 -0
- package/dist/signals/window.js +693 -0
- package/dist/signals/words.d.ts +24 -0
- package/dist/signals/words.js +24 -0
- package/dist/store/cache.d.ts +101 -0
- package/dist/store/cache.js +149 -0
- package/dist/store/history.d.ts +82 -0
- package/dist/store/history.js +36 -0
- package/dist/store/index.d.ts +30 -0
- package/dist/store/index.js +30 -0
- package/dist/store/memory.d.ts +2 -1
- package/dist/store/memory.js +48 -12
- package/dist/store/migrate.d.ts +106 -0
- package/dist/store/migrate.js +323 -7
- package/dist/store/postgres-applications.d.ts +4 -0
- package/dist/store/postgres-applications.js +197 -0
- package/dist/store/postgres-audience.d.ts +14 -0
- package/dist/store/postgres-audience.js +272 -0
- package/dist/store/postgres-holds.d.ts +10 -1
- package/dist/store/postgres-holds.js +116 -101
- package/dist/store/postgres-policy-log.d.ts +14 -0
- package/dist/store/postgres-policy-log.js +240 -0
- package/dist/store/postgres-projects.d.ts +4 -0
- package/dist/store/postgres-projects.js +217 -0
- package/dist/store/postgres.d.ts +17 -1
- package/dist/store/postgres.js +60 -9
- package/dist/store/replay.d.ts +102 -1
- package/dist/store/replay.js +190 -19
- package/dist/store/reseed.d.ts +238 -0
- package/dist/store/reseed.js +308 -0
- package/dist/store/schema.d.ts +762 -2
- package/dist/store/schema.js +218 -5
- package/dist/store/source.d.ts +57 -1
- package/dist/store/source.js +65 -1
- package/dist/store/store.d.ts +29 -6
- package/dist/submit/resolve.d.ts +1 -1
- package/dist/submit/resolve.js +2 -1
- package/dist/telemetry/calibration.d.ts +25 -0
- package/dist/telemetry/calibration.js +27 -1
- package/dist/telemetry/event.d.ts +391 -33
- package/dist/telemetry/event.js +84 -20
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/journal.d.ts +104 -3
- package/dist/telemetry/journal.js +9 -0
- package/dist/telemetry/lookup.d.ts +27 -0
- package/dist/telemetry/lookup.js +18 -0
- package/dist/telemetry/memory.js +33 -1
- package/dist/telemetry/migrate.js +22 -1
- package/dist/telemetry/postgres.d.ts +10 -1
- package/dist/telemetry/postgres.js +188 -90
- package/dist/telemetry/remeasure.d.ts +78 -0
- package/dist/telemetry/remeasure.js +83 -0
- package/dist/telemetry/retention.d.ts +2 -2
- package/dist/telemetry/schema.d.ts +17 -0
- package/dist/telemetry/schema.js +27 -1
- package/dist/telemetry/sink.d.ts +2 -2
- package/dist/telemetry/window.d.ts +135 -0
- package/dist/telemetry/window.js +101 -0
- package/dist/testing/application-contract.d.ts +14 -0
- package/dist/testing/application-contract.js +270 -0
- package/dist/testing/audience-overlay-contract.d.ts +31 -0
- package/dist/testing/audience-overlay-contract.js +354 -0
- package/dist/testing/contracts.d.ts +13 -7
- package/dist/testing/contracts.js +13 -7
- package/dist/testing/definitions.d.ts +78 -0
- package/dist/testing/definitions.js +134 -9
- package/dist/testing/doubles.d.ts +103 -0
- package/dist/testing/doubles.js +143 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/journal-contract.js +297 -6
- package/dist/testing/model-contract.d.ts +110 -0
- package/dist/testing/model-contract.js +150 -0
- package/dist/testing/policy-log-contract.d.ts +26 -0
- package/dist/testing/policy-log-contract.js +344 -0
- package/dist/testing/project-contract.d.ts +14 -0
- package/dist/testing/project-contract.js +266 -0
- package/dist/testing/reader-signal-contract.d.ts +27 -2
- package/dist/testing/reader-signal-contract.js +475 -5
- package/dist/testing/store-contract.d.ts +7 -1
- package/dist/testing/store-contract.js +84 -3
- package/dist/theme/apply.d.ts +20 -1
- package/dist/theme/apply.js +5 -3
- package/dist/theme/contrast.d.ts +19 -14
- package/dist/theme/contrast.js +181 -17
- package/dist/theme/derive.d.ts +22 -0
- package/dist/theme/derive.js +54 -1
- package/dist/theme/library.js +1 -1
- package/dist/theme/measure.d.ts +34 -0
- package/dist/theme/measure.js +30 -1
- package/dist/theme/palettes.js +7 -7
- package/dist/theme/ramp.d.ts +64 -0
- package/dist/theme/ramp.js +114 -0
- package/dist/theme/registry.d.ts +9 -0
- package/dist/theme/registry.js +11 -1
- package/dist/theme/separation.d.ts +97 -3
- package/dist/theme/separation.js +75 -0
- package/dist/tree/apply.js +13 -0
- package/dist/tree/compare.d.ts +9 -0
- package/dist/tree/compare.js +18 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +24 -12
- package/dist/tree/navigation.d.ts +5 -0
- package/dist/tree/navigation.js +32 -10
- package/dist/tree/outline.d.ts +7 -0
- package/dist/tree/outline.js +9 -5
- package/dist/write/computed.d.ts +60 -0
- package/dist/write/computed.js +61 -0
- package/dist/write/held.d.ts +59 -0
- package/dist/write/index.d.ts +5 -2
- package/dist/write/index.js +5 -2
- package/dist/write/reseed.d.ts +151 -0
- package/dist/write/reseed.js +184 -0
- package/dist/write/revert.js +2 -16
- package/package.json +25 -3
- package/dist/runtime/inverse-interpreter.d.ts +0 -90
- package/dist/runtime/inverse-interpreter.js +0 -56
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { and, asc, eq, isNull } from "drizzle-orm";
|
|
2
|
+
import { applyPatch } from "../patch.js";
|
|
3
|
+
import { projectSchema } from "../project/project.js";
|
|
4
|
+
import { matchesListing } from "../project/store.js";
|
|
5
|
+
import { err, ok } from "../result.js";
|
|
6
|
+
import { isUniqueViolation, unavailable } from "./driver.js";
|
|
7
|
+
import { loomProjects } from "./schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* The projects a deployment has, backed by Postgres (0022).
|
|
10
|
+
*
|
|
11
|
+
* The one store here that is not scoped by a project, for the obvious reason:
|
|
12
|
+
* it holds them. Every other store takes a `StoreScope` and filters on it; this
|
|
13
|
+
* one is what that scope's id refers to, so a handle for it would have nothing
|
|
14
|
+
* to be scoped by.
|
|
15
|
+
*
|
|
16
|
+
* Like the others, the database handle is injected rather than opened here —
|
|
17
|
+
* choosing a driver, a pooler and a connection lifetime belongs to the host,
|
|
18
|
+
* and injecting it is what lets the tests run this exact code against an
|
|
19
|
+
* embedded Postgres rather than against a double that agrees with them.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A row on the way out, checked rather than cast.
|
|
23
|
+
*
|
|
24
|
+
* `closed_at` is the one nullable column, and it comes out **absent rather than
|
|
25
|
+
* `null`** so that *this is open* has one spelling rather than two for every
|
|
26
|
+
* caller to check (0289, and 0274 made the same choice about `folded_at`).
|
|
27
|
+
*/
|
|
28
|
+
const toProject = (row) => {
|
|
29
|
+
const parsed = projectSchema.safeParse({
|
|
30
|
+
projectId: row.projectId,
|
|
31
|
+
name: row.name,
|
|
32
|
+
createdAt: row.createdAt,
|
|
33
|
+
...(row.repository === null ? {} : { repository: row.repository }),
|
|
34
|
+
...(row.closedAt === null ? {} : { closedAt: row.closedAt }),
|
|
35
|
+
});
|
|
36
|
+
return parsed.success
|
|
37
|
+
? ok(parsed.data)
|
|
38
|
+
: err({
|
|
39
|
+
code: "unreadable",
|
|
40
|
+
projectId: row.projectId,
|
|
41
|
+
detail: parsed.error.issues[0]?.message ?? "invalid",
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export const postgresProjectStore = (db) => ({
|
|
45
|
+
create: async (project) => {
|
|
46
|
+
try {
|
|
47
|
+
await db.insert(loomProjects).values({
|
|
48
|
+
projectId: project.projectId,
|
|
49
|
+
name: project.name,
|
|
50
|
+
createdAt: project.createdAt,
|
|
51
|
+
repository: project.repository ?? null,
|
|
52
|
+
});
|
|
53
|
+
return ok(project);
|
|
54
|
+
}
|
|
55
|
+
catch (cause) {
|
|
56
|
+
/**
|
|
57
|
+
* The key is what makes *already taken* a fact the database establishes
|
|
58
|
+
* rather than a check this code races against — the same argument the
|
|
59
|
+
* hold store makes about its primary key, and it matters more here: the
|
|
60
|
+
* loser of a race between two people registering the same project would
|
|
61
|
+
* otherwise silently take ownership of the winner's rows.
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Two unique constraints can raise this now: the primary key, and the
|
|
65
|
+
* partial index on `repository` (0292).
|
|
66
|
+
*
|
|
67
|
+
* Which one is **asked** rather than guessed. Deciding from what the
|
|
68
|
+
* caller passed would misreport an id collision as a taken repository
|
|
69
|
+
* whenever both were set, and parsing the driver's message is not
|
|
70
|
+
* portable across the two drivers this runs on. The extra read happens
|
|
71
|
+
* only on the error path, where one more round trip costs nothing.
|
|
72
|
+
*/
|
|
73
|
+
if (isUniqueViolation(cause)) {
|
|
74
|
+
const existing = await db
|
|
75
|
+
.select({ projectId: loomProjects.projectId })
|
|
76
|
+
.from(loomProjects)
|
|
77
|
+
.where(eq(loomProjects.projectId, project.projectId))
|
|
78
|
+
.limit(1);
|
|
79
|
+
if (existing[0] !== undefined) {
|
|
80
|
+
return err({ code: "already-exists", projectId: project.projectId });
|
|
81
|
+
}
|
|
82
|
+
return project.repository === undefined
|
|
83
|
+
? err({ code: "already-exists", projectId: project.projectId })
|
|
84
|
+
: err({ code: "repository-taken", repository: project.repository });
|
|
85
|
+
}
|
|
86
|
+
return err(unavailable(cause, `could not create project ${project.projectId}`));
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
get: async (projectId) => {
|
|
90
|
+
try {
|
|
91
|
+
const rows = await db
|
|
92
|
+
.select()
|
|
93
|
+
.from(loomProjects)
|
|
94
|
+
.where(eq(loomProjects.projectId, projectId))
|
|
95
|
+
.limit(1);
|
|
96
|
+
const row = rows[0];
|
|
97
|
+
return row === undefined ? err({ code: "not-found", projectId }) : toProject(row);
|
|
98
|
+
}
|
|
99
|
+
catch (cause) {
|
|
100
|
+
return err(unavailable(cause, `could not read project ${projectId}`));
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
list: async (listing) => {
|
|
104
|
+
try {
|
|
105
|
+
/**
|
|
106
|
+
* Ordered in the statement rather than after it, so the order is the
|
|
107
|
+
* database's job and an index can serve it. `created_at` is an ISO string,
|
|
108
|
+
* which sorts lexicographically into chronological order — that is the
|
|
109
|
+
* property the format is chosen for, and `projectSchema` requires it.
|
|
110
|
+
*/
|
|
111
|
+
const rows = await db.select().from(loomProjects).orderBy(asc(loomProjects.createdAt));
|
|
112
|
+
const projects = [];
|
|
113
|
+
for (const row of rows) {
|
|
114
|
+
const project = toProject(row);
|
|
115
|
+
if (!project.ok)
|
|
116
|
+
return project;
|
|
117
|
+
/**
|
|
118
|
+
* Filtered here rather than in the statement, so that the one rule
|
|
119
|
+
* about what `closed` means is the one function both stores call. A
|
|
120
|
+
* `WHERE` would be a second copy of a three-case rule.
|
|
121
|
+
*/
|
|
122
|
+
if (matchesListing(project.value.closedAt, listing))
|
|
123
|
+
projects.push(project.value);
|
|
124
|
+
}
|
|
125
|
+
return ok(projects);
|
|
126
|
+
}
|
|
127
|
+
catch (cause) {
|
|
128
|
+
return err(unavailable(cause, "could not list projects"));
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* Read, merge, parse, write — rather than setting the columns given.
|
|
133
|
+
*
|
|
134
|
+
* The first draft set them directly, and the shared contract caught what that
|
|
135
|
+
* costs: `text` accepts an empty string and `projectSchema` does not, so a
|
|
136
|
+
* rename to `""` was written happily and then could not be read back at all.
|
|
137
|
+
* The row was corrupt, and the store that had refused the same call was the
|
|
138
|
+
* one in a `Map`. Parsing the merged project is what makes the two stores
|
|
139
|
+
* agree about what a project is, rather than about what fits in a column.
|
|
140
|
+
*
|
|
141
|
+
* The read and the write are not in one transaction, which is a real race and
|
|
142
|
+
* an acceptable one: two people renaming one project at the same instant get
|
|
143
|
+
* last-write-wins on a display name. Nothing downstream keys on it.
|
|
144
|
+
*/
|
|
145
|
+
rename: async (projectId, to) => {
|
|
146
|
+
try {
|
|
147
|
+
const rows = await db
|
|
148
|
+
.select()
|
|
149
|
+
.from(loomProjects)
|
|
150
|
+
.where(eq(loomProjects.projectId, projectId))
|
|
151
|
+
.limit(1);
|
|
152
|
+
const row = rows[0];
|
|
153
|
+
if (row === undefined)
|
|
154
|
+
return err({ code: "not-found", projectId });
|
|
155
|
+
const current = toProject(row);
|
|
156
|
+
if (!current.ok)
|
|
157
|
+
return current;
|
|
158
|
+
const next = projectSchema.safeParse(applyPatch(current.value, to));
|
|
159
|
+
if (!next.success) {
|
|
160
|
+
return err({
|
|
161
|
+
code: "unreadable",
|
|
162
|
+
projectId,
|
|
163
|
+
detail: next.error.issues[0]?.message ?? "invalid",
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
await db
|
|
167
|
+
.update(loomProjects)
|
|
168
|
+
.set({ name: next.data.name })
|
|
169
|
+
.where(eq(loomProjects.projectId, projectId));
|
|
170
|
+
return ok(next.data);
|
|
171
|
+
}
|
|
172
|
+
catch (cause) {
|
|
173
|
+
return err(unavailable(cause, `could not rename project ${projectId}`));
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Idempotent in the statement: the `WHERE` refuses a row that is already
|
|
178
|
+
* closed, so the instant cannot move because somebody pressed twice (0289).
|
|
179
|
+
*/
|
|
180
|
+
close: async (projectId, at) => {
|
|
181
|
+
try {
|
|
182
|
+
await db
|
|
183
|
+
.update(loomProjects)
|
|
184
|
+
.set({ closedAt: at })
|
|
185
|
+
.where(and(eq(loomProjects.projectId, projectId), isNull(loomProjects.closedAt)));
|
|
186
|
+
const rows = await db
|
|
187
|
+
.select()
|
|
188
|
+
.from(loomProjects)
|
|
189
|
+
.where(eq(loomProjects.projectId, projectId))
|
|
190
|
+
.limit(1);
|
|
191
|
+
const row = rows[0];
|
|
192
|
+
return row === undefined ? err({ code: "not-found", projectId }) : toProject(row);
|
|
193
|
+
}
|
|
194
|
+
catch (cause) {
|
|
195
|
+
return err(unavailable(cause, `could not close project ${projectId}`));
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
reopen: async (projectId) => {
|
|
199
|
+
try {
|
|
200
|
+
await db
|
|
201
|
+
.update(loomProjects)
|
|
202
|
+
.set({ closedAt: null })
|
|
203
|
+
.where(eq(loomProjects.projectId, projectId));
|
|
204
|
+
const rows = await db
|
|
205
|
+
.select()
|
|
206
|
+
.from(loomProjects)
|
|
207
|
+
.where(eq(loomProjects.projectId, projectId))
|
|
208
|
+
.limit(1);
|
|
209
|
+
const row = rows[0];
|
|
210
|
+
return row === undefined ? err({ code: "not-found", projectId }) : toProject(row);
|
|
211
|
+
}
|
|
212
|
+
catch (cause) {
|
|
213
|
+
return err(unavailable(cause, `could not reopen project ${projectId}`));
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=postgres-projects.js.map
|
package/dist/store/postgres.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import { type StoreScope } from "../application/application.js";
|
|
1
2
|
import type { LoomDatabase } from "./database.js";
|
|
2
3
|
import { type TreeStore } from "./store.js";
|
|
3
4
|
export * from "./database.js";
|
|
4
5
|
export * from "./migrate.js";
|
|
6
|
+
export * from "./postgres-audience.js";
|
|
5
7
|
export * from "./postgres-holds.js";
|
|
8
|
+
export * from "./postgres-policy-log.js";
|
|
9
|
+
export * from "./postgres-applications.js";
|
|
10
|
+
export * from "./postgres-projects.js";
|
|
6
11
|
export * from "./schema.js";
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Every query below is filtered by the project this handle speaks for (0260),
|
|
14
|
+
* and every write sets it. There is no path through this module that reads or
|
|
15
|
+
* writes a row belonging to another project, which is the one property a
|
|
16
|
+
* governance surface cannot get wrong (0220): *a hold listing that spanned two
|
|
17
|
+
* apps would put one app's changes in another's queue.*
|
|
18
|
+
*
|
|
19
|
+
* The scope is a constructor argument rather than a parameter on each method,
|
|
20
|
+
* so no signature in `@jam-overture/loom/store` changed and spanning two
|
|
21
|
+
* projects is unexpressible rather than merely forbidden.
|
|
22
|
+
*/
|
|
23
|
+
export declare const postgresTreeStore: (db: LoomDatabase, scope?: StoreScope) => TreeStore;
|
|
8
24
|
//# sourceMappingURL=postgres.d.ts.map
|
package/dist/store/postgres.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { and, asc, desc, eq, gt, lt } from "drizzle-orm";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { DEFAULT_APPLICATION_ID } from "../application/application.js";
|
|
3
4
|
import { proposalIdSchema, treeIdSchema } from "../ids.js";
|
|
4
5
|
import { cursorPosition, pageEnds } from "../paging.js";
|
|
5
6
|
import { provenanceSchema } from "../runtime/proposal.js";
|
|
@@ -12,7 +13,11 @@ import { loomRevisions, loomTrees } from "./schema.js";
|
|
|
12
13
|
import { anchorBound, anchorResumes, clampListingLimit, clampRevisionLimit, } from "./store.js";
|
|
13
14
|
export * from "./database.js";
|
|
14
15
|
export * from "./migrate.js";
|
|
16
|
+
export * from "./postgres-audience.js";
|
|
15
17
|
export * from "./postgres-holds.js";
|
|
18
|
+
export * from "./postgres-policy-log.js";
|
|
19
|
+
export * from "./postgres-applications.js";
|
|
20
|
+
export * from "./postgres-projects.js";
|
|
16
21
|
export * from "./schema.js";
|
|
17
22
|
/**
|
|
18
23
|
* The store, backed by Postgres (0022).
|
|
@@ -40,6 +45,15 @@ const parseStored = (document, treeId) => {
|
|
|
40
45
|
detail: `stored tree ${treeId} did not parse: ${parsed.error.code}`,
|
|
41
46
|
});
|
|
42
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* What the log's stamp has to be to be read back.
|
|
50
|
+
*
|
|
51
|
+
* Named and shared because two reads now depend on it — a revision page and a
|
|
52
|
+
* tree listing's `changedAt` — and a column holding text is a column two
|
|
53
|
+
* readers could disagree about. One schema is what stops a listing publishing a
|
|
54
|
+
* string the revision it came from would have refused.
|
|
55
|
+
*/
|
|
56
|
+
const appliedAtSchema = z.string().datetime();
|
|
43
57
|
/**
|
|
44
58
|
* A log row, validated on the way out. The delta and the provenance were stored
|
|
45
59
|
* as JSON by whatever version of the code was running at the time, so reading
|
|
@@ -52,7 +66,7 @@ const storedRevisionSchema = z.object({
|
|
|
52
66
|
proposalId: proposalIdSchema,
|
|
53
67
|
delta: treeDeltaSchema,
|
|
54
68
|
provenance: provenanceSchema,
|
|
55
|
-
appliedAt:
|
|
69
|
+
appliedAt: appliedAtSchema,
|
|
56
70
|
/** Null on every row written before the column existed (0029), and on every change nobody had to allow. */
|
|
57
71
|
answeredBy: z.string().nullable().optional(),
|
|
58
72
|
});
|
|
@@ -74,12 +88,26 @@ const toStoredRevision = (row) => {
|
|
|
74
88
|
const entry = rest;
|
|
75
89
|
return answeredBy === null || answeredBy === undefined ? entry : { ...entry, answeredBy };
|
|
76
90
|
};
|
|
77
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Every query below is filtered by the project this handle speaks for (0260),
|
|
93
|
+
* and every write sets it. There is no path through this module that reads or
|
|
94
|
+
* writes a row belonging to another project, which is the one property a
|
|
95
|
+
* governance surface cannot get wrong (0220): *a hold listing that spanned two
|
|
96
|
+
* apps would put one app's changes in another's queue.*
|
|
97
|
+
*
|
|
98
|
+
* The scope is a constructor argument rather than a parameter on each method,
|
|
99
|
+
* so no signature in `@jam-overture/loom/store` changed and spanning two
|
|
100
|
+
* projects is unexpressible rather than merely forbidden.
|
|
101
|
+
*/
|
|
102
|
+
export const postgresTreeStore = (db, scope = {}) => {
|
|
103
|
+
const project = scope.application ?? DEFAULT_APPLICATION_ID;
|
|
104
|
+
/** Every read starts here, so a query cannot forget the project by omission. */
|
|
105
|
+
const mine = (treeId) => and(eq(loomTrees.applicationId, project), eq(loomTrees.treeId, treeId));
|
|
78
106
|
const readHead = async (treeId) => {
|
|
79
107
|
const rows = await db
|
|
80
108
|
.select({ document: loomTrees.document })
|
|
81
109
|
.from(loomTrees)
|
|
82
|
-
.where(
|
|
110
|
+
.where(mine(treeId))
|
|
83
111
|
.limit(1);
|
|
84
112
|
const row = rows[0];
|
|
85
113
|
return row === undefined
|
|
@@ -90,6 +118,7 @@ export const postgresTreeStore = (db) => {
|
|
|
90
118
|
create: async (tree) => {
|
|
91
119
|
try {
|
|
92
120
|
await db.insert(loomTrees).values({
|
|
121
|
+
applicationId: project,
|
|
93
122
|
treeId: tree.treeId,
|
|
94
123
|
revision: tree.revision,
|
|
95
124
|
document: tree,
|
|
@@ -120,7 +149,7 @@ export const postgresTreeStore = (db) => {
|
|
|
120
149
|
const present = await db
|
|
121
150
|
.select({ treeId: loomTrees.treeId, revision: loomTrees.revision })
|
|
122
151
|
.from(loomTrees)
|
|
123
|
-
.where(
|
|
152
|
+
.where(mine(treeId))
|
|
124
153
|
.limit(1);
|
|
125
154
|
/** "No tree" and "a tree with no changes" are different answers. */
|
|
126
155
|
const head = present[0];
|
|
@@ -135,7 +164,7 @@ export const postgresTreeStore = (db) => {
|
|
|
135
164
|
const rows = await db
|
|
136
165
|
.select()
|
|
137
166
|
.from(loomRevisions)
|
|
138
|
-
.where(and(eq(loomRevisions.treeId, treeId), from === undefined
|
|
167
|
+
.where(and(eq(loomRevisions.applicationId, project), eq(loomRevisions.treeId, treeId), from === undefined
|
|
139
168
|
? undefined
|
|
140
169
|
: direction === "older"
|
|
141
170
|
? lt(loomRevisions.revision, from)
|
|
@@ -170,9 +199,22 @@ export const postgresTreeStore = (db) => {
|
|
|
170
199
|
const limit = clampListingLimit(request?.limit);
|
|
171
200
|
try {
|
|
172
201
|
const rows = await db
|
|
173
|
-
.select({
|
|
202
|
+
.select({
|
|
203
|
+
treeId: loomTrees.treeId,
|
|
204
|
+
revision: loomTrees.revision,
|
|
205
|
+
changedAt: loomRevisions.appliedAt,
|
|
206
|
+
})
|
|
174
207
|
.from(loomTrees)
|
|
175
|
-
|
|
208
|
+
/*
|
|
209
|
+
* The whole of the log's primary key, so this is a point lookup per
|
|
210
|
+
* listed tree rather than a scan: the row it finds is the one whose
|
|
211
|
+
* revision the snapshot is currently at, which is the newest entry by
|
|
212
|
+
* 0026's density. `leftJoin` rather than `innerJoin` because a tree at
|
|
213
|
+
* revision 0 has no entry at all, and an inner join would drop it from
|
|
214
|
+
* the listing — turning a missing stamp into a missing page.
|
|
215
|
+
*/
|
|
216
|
+
.leftJoin(loomRevisions, and(eq(loomRevisions.applicationId, loomTrees.applicationId), eq(loomRevisions.treeId, loomTrees.treeId), eq(loomRevisions.revision, loomTrees.revision)))
|
|
217
|
+
.where(and(eq(loomTrees.applicationId, project), request?.cursor === undefined ? undefined : gt(loomTrees.treeId, request.cursor)))
|
|
176
218
|
.orderBy(asc(loomTrees.treeId))
|
|
177
219
|
/** One extra row answers "is there another page" without a count. */
|
|
178
220
|
.limit(limit + 1);
|
|
@@ -182,6 +224,14 @@ export const postgresTreeStore = (db) => {
|
|
|
182
224
|
trees: page.map((row) => ({
|
|
183
225
|
treeId: treeIdSchema.parse(row.treeId),
|
|
184
226
|
revision: row.revision,
|
|
227
|
+
/*
|
|
228
|
+
* Parsed rather than trusted, for the reason every other column
|
|
229
|
+
* read here is: the contract publishes this as a timestamp, and a
|
|
230
|
+
* column holding text can hold anything a writer put in it.
|
|
231
|
+
*/
|
|
232
|
+
...(row.changedAt === null
|
|
233
|
+
? {}
|
|
234
|
+
: { changedAt: appliedAtSchema.parse(row.changedAt) }),
|
|
185
235
|
})),
|
|
186
236
|
cursor: rows.length > limit && last !== undefined ? last.treeId : null,
|
|
187
237
|
};
|
|
@@ -204,7 +254,7 @@ export const postgresTreeStore = (db) => {
|
|
|
204
254
|
const rows = await tx
|
|
205
255
|
.select({ document: loomTrees.document })
|
|
206
256
|
.from(loomTrees)
|
|
207
|
-
.where(
|
|
257
|
+
.where(mine(treeId))
|
|
208
258
|
.for("update")
|
|
209
259
|
.limit(1);
|
|
210
260
|
const row = rows[0];
|
|
@@ -226,6 +276,7 @@ export const postgresTreeStore = (db) => {
|
|
|
226
276
|
return err({ code: "delta-rejected", treeId, error: applied.error });
|
|
227
277
|
}
|
|
228
278
|
await tx.insert(loomRevisions).values({
|
|
279
|
+
applicationId: project,
|
|
229
280
|
treeId,
|
|
230
281
|
revision: applied.value.revision,
|
|
231
282
|
proposalId: request.proposalId,
|
|
@@ -237,7 +288,7 @@ export const postgresTreeStore = (db) => {
|
|
|
237
288
|
await tx
|
|
238
289
|
.update(loomTrees)
|
|
239
290
|
.set({ revision: applied.value.revision, document: applied.value })
|
|
240
|
-
.where(and(
|
|
291
|
+
.where(and(mine(treeId), eq(loomTrees.revision, snapshot.value.revision)));
|
|
241
292
|
return ok(applied.value);
|
|
242
293
|
});
|
|
243
294
|
}
|
package/dist/store/replay.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { LoomTree } from "../tree/tree.js";
|
|
|
5
5
|
import type { StoreError } from "./errors.js";
|
|
6
6
|
import type { StoredRevision, TreeReader } from "./store.js";
|
|
7
7
|
/**
|
|
8
|
-
* Replay, and the
|
|
8
|
+
* Replay: folding the log, and the two questions a fold answers.
|
|
9
9
|
*
|
|
10
10
|
* The snapshot is what gets read; the log is what gets trusted. Those two only
|
|
11
11
|
* stay the same thing if folding the log still produces the snapshot — and that
|
|
@@ -17,6 +17,13 @@ import type { StoredRevision, TreeReader } from "./store.js";
|
|
|
17
17
|
* A pure event-sourced design cannot detect that: the fold is the read, so a
|
|
18
18
|
* drifted fold is simply the new truth. With a snapshot, replay becomes a check
|
|
19
19
|
* rather than a dependency — which is the argument for keeping both.
|
|
20
|
+
*
|
|
21
|
+
* The second question is what the tree *was*. A store answers for one revision,
|
|
22
|
+
* the head, because that is the one it materialises; every earlier revision is
|
|
23
|
+
* in the log and reachable only by folding to it. `auditSnapshot` folds to the
|
|
24
|
+
* end to compare; `treeAt` folds to a revision a caller names and stops. One
|
|
25
|
+
* walk, bounded at both ends: it opens at the seed's own position and closes at
|
|
26
|
+
* the last revision anybody asked for.
|
|
20
27
|
*/
|
|
21
28
|
export type ReplayMismatch = {
|
|
22
29
|
readonly code: "delta-rejected";
|
|
@@ -91,4 +98,98 @@ export type SnapshotAudit = {
|
|
|
91
98
|
* it is trying to check.
|
|
92
99
|
*/
|
|
93
100
|
export declare const auditSnapshot: (store: TreeReader, treeId: TreeId, seed: LoomTree) => Promise<Result<SnapshotAudit, StoreError>>;
|
|
101
|
+
/**
|
|
102
|
+
* One revision of one tree, and the seed to reach it from.
|
|
103
|
+
*
|
|
104
|
+
* The seed is the same parameter `auditSnapshot` and `planRevert` take, for the
|
|
105
|
+
* same reason and with the same consequence: a caller that cannot supply one
|
|
106
|
+
* cannot read a past revision at all. Usually revision 0; a host that
|
|
107
|
+
* checkpoints may supply a later one (0028), and then everything before the
|
|
108
|
+
* checkpoint is out of range rather than silently wrong.
|
|
109
|
+
*/
|
|
110
|
+
export type TreeAtTarget = {
|
|
111
|
+
readonly treeId: TreeId;
|
|
112
|
+
readonly revision: number;
|
|
113
|
+
readonly seed: LoomTree;
|
|
114
|
+
};
|
|
115
|
+
/** The same question asked about several revisions of one tree, in one read. */
|
|
116
|
+
export type TreeAtTargets = {
|
|
117
|
+
readonly treeId: TreeId;
|
|
118
|
+
readonly revisions: readonly number[];
|
|
119
|
+
readonly seed: LoomTree;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* The tree as it was, or why the log cannot say.
|
|
123
|
+
*
|
|
124
|
+
* A `StoreError` means the log could not be read. Everything else is an answer
|
|
125
|
+
* about the revision, which is why the obstacles are values rather than errors:
|
|
126
|
+
* "that revision is before the checkpoint you handed me" is a fact about the
|
|
127
|
+
* span, not a failure.
|
|
128
|
+
*/
|
|
129
|
+
export type TreeAtRevision =
|
|
130
|
+
/**
|
|
131
|
+
* The fold reached the named revision. `replayed.tree.revision` equals the
|
|
132
|
+
* revision asked for, and `replayed.idHistory` is the tenancy of every id from
|
|
133
|
+
* the seed up to it — which is the half a caller reading counters by node id
|
|
134
|
+
* needs, because an id that returned in between names two different nodes
|
|
135
|
+
* either side of the comparison (0038).
|
|
136
|
+
*/
|
|
137
|
+
{
|
|
138
|
+
readonly outcome: "replayed";
|
|
139
|
+
readonly revision: number;
|
|
140
|
+
readonly replayed: ReplayedTree;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Not a revision this seed and this log can reach: before the seed, after the
|
|
144
|
+
* head, or not an integer — revisions are dense integers (0026) and nothing
|
|
145
|
+
* lies between two of them, so a fractional one is not a position the log has.
|
|
146
|
+
*
|
|
147
|
+
* `earliest` is the seed's own revision rather than one past it, which is the
|
|
148
|
+
* one place this differs from a revert's span: the tree at the seed is the
|
|
149
|
+
* seed, and a revision cannot be undone by inverting a delta the seed already
|
|
150
|
+
* contains.
|
|
151
|
+
*/
|
|
152
|
+
| {
|
|
153
|
+
readonly outcome: "out-of-range";
|
|
154
|
+
readonly revision: number;
|
|
155
|
+
readonly earliest: number;
|
|
156
|
+
readonly headRevision: number;
|
|
157
|
+
} | {
|
|
158
|
+
readonly outcome: "unreplayable";
|
|
159
|
+
readonly revision: number;
|
|
160
|
+
readonly mismatch: ReplayMismatch;
|
|
161
|
+
};
|
|
162
|
+
export declare const describeTreeAt: (answer: TreeAtRevision) => string;
|
|
163
|
+
/**
|
|
164
|
+
* The tree as it was at a chosen revision.
|
|
165
|
+
*
|
|
166
|
+
* A store materialises one revision — the head — because §3 renders per request
|
|
167
|
+
* and a fold per render is not affordable. Every earlier revision is in the log
|
|
168
|
+
* and nowhere else, so this is the fold, stopped where the caller said rather
|
|
169
|
+
* than at the end.
|
|
170
|
+
*
|
|
171
|
+
* It exists because a reading keyed to a revision needs the tree *of* that
|
|
172
|
+
* revision: reader counters are keyed by tree and revision deliberately (0147),
|
|
173
|
+
* and laying one revision's counters over another revision's tree makes most
|
|
174
|
+
* parts read "nobody got there" while every number stays plausible. The
|
|
175
|
+
* workaround — page `revisions()` and fold from the seed in the consumer — is
|
|
176
|
+
* the same walk with the stopping condition moved somewhere nothing tests it,
|
|
177
|
+
* and a consumer that gets it slightly wrong produces the one failure this
|
|
178
|
+
* reading can have that looks exactly like success.
|
|
179
|
+
*/
|
|
180
|
+
export declare const treeAt: (reader: TreeReader, target: TreeAtTarget) => Promise<Result<TreeAtRevision, StoreError>>;
|
|
181
|
+
/**
|
|
182
|
+
* The same answers for several revisions, from one read of the log.
|
|
183
|
+
*
|
|
184
|
+
* Each answer is exactly what `treeAt` would have produced for that revision on
|
|
185
|
+
* its own — the batch changes what it costs to ask, never what the answer is.
|
|
186
|
+
* Two revisions is the case it exists for: a before-and-after reading is one
|
|
187
|
+
* revision against another, and asking twice would fold the shared prefix twice
|
|
188
|
+
* and read the head twice, against a log that is still being appended to.
|
|
189
|
+
*
|
|
190
|
+
* Revisions are keyed rather than positional so a caller can ask about the ones
|
|
191
|
+
* it is comparing and read the answers back by revision; asking twice about one
|
|
192
|
+
* revision costs nothing and answers once.
|
|
193
|
+
*/
|
|
194
|
+
export declare const treesAt: (reader: TreeReader, targets: TreeAtTargets) => Promise<Result<ReadonlyMap<number, TreeAtRevision>, StoreError>>;
|
|
94
195
|
//# sourceMappingURL=replay.d.ts.map
|