@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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pin a reader carries, and the version of a page it asks for.
|
|
3
|
+
*
|
|
4
|
+
* A reader's first page view under a window pins them to the project's live
|
|
5
|
+
* pages as they stood at that moment, and every page they read until the window
|
|
6
|
+
* runs out is drawn as it stood then (0383 clause 2). This is the whole of that
|
|
7
|
+
* in the customer's server: a number read out of a request's `Cookie` header, a
|
|
8
|
+
* version chosen against what the last pull held, and the `Set-Cookie` value a
|
|
9
|
+
* reader with no pin is given.
|
|
10
|
+
*
|
|
11
|
+
* **Nothing here reaches Loom, and nothing here is a reader id.** The pin is
|
|
12
|
+
* the number the project's live pages stood at when the reader first arrived,
|
|
13
|
+
* so every reader who arrived between the same two changes carries the same
|
|
14
|
+
* value (0383 clause 3). It goes on no signal and no pull (0146, 0262): the
|
|
15
|
+
* door is asked for the project's pages, never for this reader's.
|
|
16
|
+
*
|
|
17
|
+
* **A pin the server cannot resolve reads the newest live page**, and a server
|
|
18
|
+
* holding nothing renders the page as built (0383 clause 5). Every refusal in
|
|
19
|
+
* this file is that sentence — freshness is what fails, never the page.
|
|
20
|
+
*/
|
|
21
|
+
import type { TreeId } from "../ids.js";
|
|
22
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
23
|
+
/**
|
|
24
|
+
* One version of a page a pin can still be served.
|
|
25
|
+
*
|
|
26
|
+
* `until` is the number the change that replaced this version became live at,
|
|
27
|
+
* so this version is what a pin *below* that number asks for.
|
|
28
|
+
*/
|
|
29
|
+
export type HeldVersion = {
|
|
30
|
+
readonly until: number;
|
|
31
|
+
readonly tree: LoomTree;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* How long this project holds its readers, and what a pin needs to be
|
|
35
|
+
* resolved — the door's `window`, as the pull read it.
|
|
36
|
+
*
|
|
37
|
+
* **The numbers are milliseconds** (when each state of the pages was made), so
|
|
38
|
+
* they only ever increase and they do not go up by one. Everything here
|
|
39
|
+
* compares them and nothing counts them.
|
|
40
|
+
*/
|
|
41
|
+
export type ReadersHeld = {
|
|
42
|
+
/** How long a reader keeps the pages they first saw. */
|
|
43
|
+
readonly ms: number;
|
|
44
|
+
/** The number below which a pin reads the newest pages: a snapshot or a revert raised it. */
|
|
45
|
+
readonly floor: number;
|
|
46
|
+
/** What the pages stand at now, which is what a new reader is pinned to. */
|
|
47
|
+
readonly number: number;
|
|
48
|
+
/** Each page's versions a pin can still be served, by the page's own id. */
|
|
49
|
+
readonly held: ReadonlyMap<TreeId, readonly HeldVersion[]>;
|
|
50
|
+
};
|
|
51
|
+
export type LiveWindow = {
|
|
52
|
+
readonly ms: 0;
|
|
53
|
+
} | ReadersHeld;
|
|
54
|
+
/**
|
|
55
|
+
* Readers are not held: every page view reads the newest live page, no cookie
|
|
56
|
+
* is set, and nothing is kept on a reader's device.
|
|
57
|
+
*
|
|
58
|
+
* This is the default a project has until somebody chooses otherwise (0383
|
|
59
|
+
* clause 1), what a server holds before its first pull, and what a door from
|
|
60
|
+
* before the window answers.
|
|
61
|
+
*/
|
|
62
|
+
export declare const WINDOW_OFF: LiveWindow;
|
|
63
|
+
/** The cookie the pin is kept in, first-party, on the customer's own domain. */
|
|
64
|
+
export declare const PIN_COOKIE = "loom_pin";
|
|
65
|
+
/**
|
|
66
|
+
* The pin in a request's `Cookie` header, or `undefined` for a reader who has
|
|
67
|
+
* no usable one.
|
|
68
|
+
*
|
|
69
|
+
* **This asks one question and it is a syntactic one: is there a whole number
|
|
70
|
+
* under our name?** Whether that number can be resolved against the window the
|
|
71
|
+
* last pull brought is `livePageOf`'s question, and the two are deliberately
|
|
72
|
+
* apart — a pin from before the floor is a reader who *has* a pin and must not
|
|
73
|
+
* be given a new one (0383 clause 3), while a cookie holding something that is
|
|
74
|
+
* not a number is a reader who has none and gets one. Answering both here would
|
|
75
|
+
* make those one answer, and they are opposite acts.
|
|
76
|
+
*
|
|
77
|
+
* A header carrying our name twice is read as its first value. A browser sends
|
|
78
|
+
* one for a cookie set at `Path=/`, and two would have no single reading.
|
|
79
|
+
*
|
|
80
|
+
* **Only a value this file could have written is read**: digits, no sign, no
|
|
81
|
+
* point, no exponent, no leading zero. `Number` would read `1e3` as 1,000 and
|
|
82
|
+
* an empty string as `0` — and `0` is a pin below every floor rather than the
|
|
83
|
+
* absence of one, which is the difference between serving this reader the
|
|
84
|
+
* newest page and giving them a pin they never had. A cookie under our name
|
|
85
|
+
* holding anything else was not set by `pinCookieFor`, so its reader has no pin
|
|
86
|
+
* and gets one.
|
|
87
|
+
*/
|
|
88
|
+
export declare const pinIn: (cookies: string | null | undefined) => number | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The version of this page to draw for a reader carrying this pin, or
|
|
91
|
+
* `undefined` where the pin asks for the newest live page.
|
|
92
|
+
*
|
|
93
|
+
* The four pins that read the newest are the four 0383 clause 5 names: no
|
|
94
|
+
* window set, a pin below the floor (so a snapshot from the site or an accepted
|
|
95
|
+
* revert has overtaken it — clause 4), a pin above the number the pages stand
|
|
96
|
+
* at, and a page this pin was never held a version of.
|
|
97
|
+
*
|
|
98
|
+
* **The version served is the one with the earliest `until` after the pin**,
|
|
99
|
+
* rather than the first in the list. The door answers them oldest first and
|
|
100
|
+
* both readings agree on an ordered list; reading the order would make a
|
|
101
|
+
* reader's page depend on it, and the cost of a list that arrived out of order
|
|
102
|
+
* is a reader served a *newer* page than they were pinned to, which is the one
|
|
103
|
+
* flip this record exists to remove.
|
|
104
|
+
*/
|
|
105
|
+
export declare const heldVersionFor: (window: LiveWindow, page: TreeId, pin: number | undefined) => LoomTree | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* The `Set-Cookie` value for this reader, or `undefined` to set none.
|
|
108
|
+
*
|
|
109
|
+
* **A reader who has a pin is never given another one** (0383 clause 3). A
|
|
110
|
+
* cookie renewed on every visit would hold a daily reader on one version for
|
|
111
|
+
* ever, so the expiry is set once, at first sight, and never extended. Nothing
|
|
112
|
+
* is set while the window is *Off*, which is every project that has not chosen
|
|
113
|
+
* one.
|
|
114
|
+
*
|
|
115
|
+
* **The expiry is `Max-Age` and there is no clock in this function.** Both are
|
|
116
|
+
* one choice: `Max-Age` is counted from when the reader's browser receives the
|
|
117
|
+
* response, which is first sight exactly, so the window cannot be lengthened or
|
|
118
|
+
* shortened by the server's clock drifting from the reader's — which is what
|
|
119
|
+
* `Expires` is compared against. It also makes this a pure function of what the
|
|
120
|
+
* last pull brought, with no `now` to be wrong about.
|
|
121
|
+
*
|
|
122
|
+
* A window under a second rounds to no cookie rather than to `Max-Age=0`: both
|
|
123
|
+
* hold the reader for no time at all, and a cookie that is dead on arrival is
|
|
124
|
+
* a thing somebody has to explain.
|
|
125
|
+
*/
|
|
126
|
+
export declare const pinCookieFor: (held: {
|
|
127
|
+
readonly window: LiveWindow;
|
|
128
|
+
}, pin: number | undefined) => string | undefined;
|
|
129
|
+
//# sourceMappingURL=window.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pin a reader carries, and the version of a page it asks for.
|
|
3
|
+
*
|
|
4
|
+
* A reader's first page view under a window pins them to the project's live
|
|
5
|
+
* pages as they stood at that moment, and every page they read until the window
|
|
6
|
+
* runs out is drawn as it stood then (0383 clause 2). This is the whole of that
|
|
7
|
+
* in the customer's server: a number read out of a request's `Cookie` header, a
|
|
8
|
+
* version chosen against what the last pull held, and the `Set-Cookie` value a
|
|
9
|
+
* reader with no pin is given.
|
|
10
|
+
*
|
|
11
|
+
* **Nothing here reaches Loom, and nothing here is a reader id.** The pin is
|
|
12
|
+
* the number the project's live pages stood at when the reader first arrived,
|
|
13
|
+
* so every reader who arrived between the same two changes carries the same
|
|
14
|
+
* value (0383 clause 3). It goes on no signal and no pull (0146, 0262): the
|
|
15
|
+
* door is asked for the project's pages, never for this reader's.
|
|
16
|
+
*
|
|
17
|
+
* **A pin the server cannot resolve reads the newest live page**, and a server
|
|
18
|
+
* holding nothing renders the page as built (0383 clause 5). Every refusal in
|
|
19
|
+
* this file is that sentence — freshness is what fails, never the page.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Whether this project holds its readers at all.
|
|
23
|
+
*
|
|
24
|
+
* A predicate rather than `window.ms === 0` at each use: `ms` is a length on
|
|
25
|
+
* one side of the union and the literal `0` on the other, so a comparison does
|
|
26
|
+
* not narrow it and every reader of this file would have to know that.
|
|
27
|
+
*/
|
|
28
|
+
const holdsReaders = (window) => window.ms !== 0;
|
|
29
|
+
/**
|
|
30
|
+
* Readers are not held: every page view reads the newest live page, no cookie
|
|
31
|
+
* is set, and nothing is kept on a reader's device.
|
|
32
|
+
*
|
|
33
|
+
* This is the default a project has until somebody chooses otherwise (0383
|
|
34
|
+
* clause 1), what a server holds before its first pull, and what a door from
|
|
35
|
+
* before the window answers.
|
|
36
|
+
*/
|
|
37
|
+
export const WINDOW_OFF = { ms: 0 };
|
|
38
|
+
/** The cookie the pin is kept in, first-party, on the customer's own domain. */
|
|
39
|
+
export const PIN_COOKIE = "loom_pin";
|
|
40
|
+
/** The one spelling of a pin: what `pinCookieFor` writes, and nothing else. */
|
|
41
|
+
const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
|
|
42
|
+
/**
|
|
43
|
+
* The pin in a request's `Cookie` header, or `undefined` for a reader who has
|
|
44
|
+
* no usable one.
|
|
45
|
+
*
|
|
46
|
+
* **This asks one question and it is a syntactic one: is there a whole number
|
|
47
|
+
* under our name?** Whether that number can be resolved against the window the
|
|
48
|
+
* last pull brought is `livePageOf`'s question, and the two are deliberately
|
|
49
|
+
* apart — a pin from before the floor is a reader who *has* a pin and must not
|
|
50
|
+
* be given a new one (0383 clause 3), while a cookie holding something that is
|
|
51
|
+
* not a number is a reader who has none and gets one. Answering both here would
|
|
52
|
+
* make those one answer, and they are opposite acts.
|
|
53
|
+
*
|
|
54
|
+
* A header carrying our name twice is read as its first value. A browser sends
|
|
55
|
+
* one for a cookie set at `Path=/`, and two would have no single reading.
|
|
56
|
+
*
|
|
57
|
+
* **Only a value this file could have written is read**: digits, no sign, no
|
|
58
|
+
* point, no exponent, no leading zero. `Number` would read `1e3` as 1,000 and
|
|
59
|
+
* an empty string as `0` — and `0` is a pin below every floor rather than the
|
|
60
|
+
* absence of one, which is the difference between serving this reader the
|
|
61
|
+
* newest page and giving them a pin they never had. A cookie under our name
|
|
62
|
+
* holding anything else was not set by `pinCookieFor`, so its reader has no pin
|
|
63
|
+
* and gets one.
|
|
64
|
+
*/
|
|
65
|
+
export const pinIn = (cookies) => {
|
|
66
|
+
if (cookies === undefined || cookies === null)
|
|
67
|
+
return undefined;
|
|
68
|
+
const value = cookies
|
|
69
|
+
.split(";")
|
|
70
|
+
.map((pair) => pair.trim())
|
|
71
|
+
.find((pair) => pair.startsWith(`${PIN_COOKIE}=`))
|
|
72
|
+
?.slice(PIN_COOKIE.length + 1);
|
|
73
|
+
if (value === undefined || !DECIMAL.test(value))
|
|
74
|
+
return undefined;
|
|
75
|
+
const pin = Number(value);
|
|
76
|
+
return Number.isSafeInteger(pin) ? pin : undefined;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The version of this page to draw for a reader carrying this pin, or
|
|
80
|
+
* `undefined` where the pin asks for the newest live page.
|
|
81
|
+
*
|
|
82
|
+
* The four pins that read the newest are the four 0383 clause 5 names: no
|
|
83
|
+
* window set, a pin below the floor (so a snapshot from the site or an accepted
|
|
84
|
+
* revert has overtaken it — clause 4), a pin above the number the pages stand
|
|
85
|
+
* at, and a page this pin was never held a version of.
|
|
86
|
+
*
|
|
87
|
+
* **The version served is the one with the earliest `until` after the pin**,
|
|
88
|
+
* rather than the first in the list. The door answers them oldest first and
|
|
89
|
+
* both readings agree on an ordered list; reading the order would make a
|
|
90
|
+
* reader's page depend on it, and the cost of a list that arrived out of order
|
|
91
|
+
* is a reader served a *newer* page than they were pinned to, which is the one
|
|
92
|
+
* flip this record exists to remove.
|
|
93
|
+
*/
|
|
94
|
+
export const heldVersionFor = (window, page, pin) => {
|
|
95
|
+
if (pin === undefined || !holdsReaders(window))
|
|
96
|
+
return undefined;
|
|
97
|
+
if (!Number.isSafeInteger(pin) || pin < window.floor || pin > window.number)
|
|
98
|
+
return undefined;
|
|
99
|
+
return (window.held.get(page) ?? [])
|
|
100
|
+
.filter((version) => version.until > pin)
|
|
101
|
+
.reduce((earliest, version) => earliest === undefined || version.until < earliest.until ? version : earliest, undefined)?.tree;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The `Set-Cookie` value for this reader, or `undefined` to set none.
|
|
105
|
+
*
|
|
106
|
+
* **A reader who has a pin is never given another one** (0383 clause 3). A
|
|
107
|
+
* cookie renewed on every visit would hold a daily reader on one version for
|
|
108
|
+
* ever, so the expiry is set once, at first sight, and never extended. Nothing
|
|
109
|
+
* is set while the window is *Off*, which is every project that has not chosen
|
|
110
|
+
* one.
|
|
111
|
+
*
|
|
112
|
+
* **The expiry is `Max-Age` and there is no clock in this function.** Both are
|
|
113
|
+
* one choice: `Max-Age` is counted from when the reader's browser receives the
|
|
114
|
+
* response, which is first sight exactly, so the window cannot be lengthened or
|
|
115
|
+
* shortened by the server's clock drifting from the reader's — which is what
|
|
116
|
+
* `Expires` is compared against. It also makes this a pure function of what the
|
|
117
|
+
* last pull brought, with no `now` to be wrong about.
|
|
118
|
+
*
|
|
119
|
+
* A window under a second rounds to no cookie rather than to `Max-Age=0`: both
|
|
120
|
+
* hold the reader for no time at all, and a cookie that is dead on arrival is
|
|
121
|
+
* a thing somebody has to explain.
|
|
122
|
+
*/
|
|
123
|
+
export const pinCookieFor = (held, pin) => {
|
|
124
|
+
const { window } = held;
|
|
125
|
+
if (pin !== undefined || !holdsReaders(window))
|
|
126
|
+
return undefined;
|
|
127
|
+
const seconds = Math.floor(window.ms / 1000);
|
|
128
|
+
return seconds < 1
|
|
129
|
+
? undefined
|
|
130
|
+
: `${PIN_COOKIE}=${window.number}; Max-Age=${seconds}; Path=/; HttpOnly; Secure; SameSite=Lax`;
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=window.js.map
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three things a partial update can say about one field, and the one place
|
|
3
|
+
* they are spelled.
|
|
4
|
+
*
|
|
5
|
+
* A store's update method takes the fields a caller wants changed and leaves
|
|
6
|
+
* the rest alone, which is the right shape and leaves one thing unsayable. If
|
|
7
|
+
* an absent field means *leave it alone*, nothing means *remove it* — so a
|
|
8
|
+
* record with an optional field could be given one and never have it taken
|
|
9
|
+
* away. The field that found this was an application's host: a person who
|
|
10
|
+
* empties the box on a settings screen and presses save means *I do not have a
|
|
11
|
+
* host any more*, and the only call available said nothing about the host at
|
|
12
|
+
* all, which renames nothing and reports success.
|
|
13
|
+
*
|
|
14
|
+
* So a patch field carries three states rather than two: a value sets it,
|
|
15
|
+
* `null` clears it, and absent still leaves it alone. `null` rather than an
|
|
16
|
+
* empty string, because an empty string is a value the schemas go on refusing —
|
|
17
|
+
* one spelling of nothing per field is the point, and a second would have every
|
|
18
|
+
* store deciding for itself which of the two it honoured.
|
|
19
|
+
*
|
|
20
|
+
* Clearing **removes the key** rather than setting it to `undefined`. The
|
|
21
|
+
* schemas these patches are parsed against are strict and spell an absent field
|
|
22
|
+
* optional, so a key holding `undefined` is not what a record that never had
|
|
23
|
+
* the field looks like, and the two must not be told apart by which route they
|
|
24
|
+
* arrived by.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* One field of a patch: a value to set, or `null` to clear it.
|
|
28
|
+
*
|
|
29
|
+
* Absent is the third state and is not spelled here, because it is the
|
|
30
|
+
* property's own optionality rather than anything this type can say. A field
|
|
31
|
+
* typed `host?: Patch<string>` reads as all three.
|
|
32
|
+
*/
|
|
33
|
+
export type Patch<T> = T | null;
|
|
34
|
+
/**
|
|
35
|
+
* A partial update over `T`: every field optional, and every one clearable.
|
|
36
|
+
*
|
|
37
|
+
* `| undefined` is written out rather than left to the `?`, so that a caller
|
|
38
|
+
* may pass a field it has read as absent instead of having to build the object
|
|
39
|
+
* by spreading around it.
|
|
40
|
+
*/
|
|
41
|
+
export type PatchOf<T> = {
|
|
42
|
+
readonly [K in keyof T]?: Patch<NonNullable<T[K]>> | undefined;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* `subject` with every field the patch mentions applied, and nothing else
|
|
46
|
+
* touched.
|
|
47
|
+
*
|
|
48
|
+
* The result is a new object; the subject is not modified. It is not validated
|
|
49
|
+
* either — a caller parses what comes back against the schema that owns the
|
|
50
|
+
* record, which is what keeps two stores agreeing about what a thing is rather
|
|
51
|
+
* than about what fits in a column.
|
|
52
|
+
*/
|
|
53
|
+
export declare const applyPatch: <T extends object>(subject: T, patch: PatchOf<T>) => T;
|
|
54
|
+
//# sourceMappingURL=patch.d.ts.map
|
package/dist/patch.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three things a partial update can say about one field, and the one place
|
|
3
|
+
* they are spelled.
|
|
4
|
+
*
|
|
5
|
+
* A store's update method takes the fields a caller wants changed and leaves
|
|
6
|
+
* the rest alone, which is the right shape and leaves one thing unsayable. If
|
|
7
|
+
* an absent field means *leave it alone*, nothing means *remove it* — so a
|
|
8
|
+
* record with an optional field could be given one and never have it taken
|
|
9
|
+
* away. The field that found this was an application's host: a person who
|
|
10
|
+
* empties the box on a settings screen and presses save means *I do not have a
|
|
11
|
+
* host any more*, and the only call available said nothing about the host at
|
|
12
|
+
* all, which renames nothing and reports success.
|
|
13
|
+
*
|
|
14
|
+
* So a patch field carries three states rather than two: a value sets it,
|
|
15
|
+
* `null` clears it, and absent still leaves it alone. `null` rather than an
|
|
16
|
+
* empty string, because an empty string is a value the schemas go on refusing —
|
|
17
|
+
* one spelling of nothing per field is the point, and a second would have every
|
|
18
|
+
* store deciding for itself which of the two it honoured.
|
|
19
|
+
*
|
|
20
|
+
* Clearing **removes the key** rather than setting it to `undefined`. The
|
|
21
|
+
* schemas these patches are parsed against are strict and spell an absent field
|
|
22
|
+
* optional, so a key holding `undefined` is not what a record that never had
|
|
23
|
+
* the field looks like, and the two must not be told apart by which route they
|
|
24
|
+
* arrived by.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* `subject` with every field the patch mentions applied, and nothing else
|
|
28
|
+
* touched.
|
|
29
|
+
*
|
|
30
|
+
* The result is a new object; the subject is not modified. It is not validated
|
|
31
|
+
* either — a caller parses what comes back against the schema that owns the
|
|
32
|
+
* record, which is what keeps two stores agreeing about what a thing is rather
|
|
33
|
+
* than about what fits in a column.
|
|
34
|
+
*/
|
|
35
|
+
export const applyPatch = (subject, patch) => Object.entries(patch).reduce((applied, [field, change]) => {
|
|
36
|
+
if (change === undefined)
|
|
37
|
+
return applied;
|
|
38
|
+
if (change === null) {
|
|
39
|
+
const { [field]: _cleared, ...kept } = applied;
|
|
40
|
+
return kept;
|
|
41
|
+
}
|
|
42
|
+
return { ...applied, [field]: change };
|
|
43
|
+
}, { ...subject });
|
|
44
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ApplicationStore } from "../application/store.js";
|
|
2
|
+
import { type Result } from "../result.js";
|
|
3
|
+
import type { ProjectId } from "./project.js";
|
|
4
|
+
import { type ProjectStore, type ProjectStoreError } from "./store.js";
|
|
5
|
+
/**
|
|
6
|
+
* Closing a project, and the applications it holds.
|
|
7
|
+
*
|
|
8
|
+
* **Above the two stores rather than inside either**
|
|
9
|
+
* ([0289](../../decisions/0289-a-project-is-closed-rather-than-deleted-and-closing-is-a-column-and-a-filter.md)).
|
|
10
|
+
* A project store that reached into an application store to finish its own
|
|
11
|
+
* write would be the coupling both are shaped to avoid — nothing is stored
|
|
12
|
+
* *under* a project, which is why they are two stores and not one.
|
|
13
|
+
*
|
|
14
|
+
* ## What it is instead of
|
|
15
|
+
*
|
|
16
|
+
* A delete, which three stores refuse and
|
|
17
|
+
* [0268](../../decisions/0268-a-page-is-put-back-by-proposing-the-change-that-puts-it-back-and-a-store-never-deletes.md)
|
|
18
|
+
* argued: a project's rows are its applications' trees, revisions, holds and
|
|
19
|
+
* policy history, and removing them destroys the account of what changed that
|
|
20
|
+
* Loom exists to keep. A delete would have cascaded through all of it. This
|
|
21
|
+
* cascades too, and reversibly.
|
|
22
|
+
*/
|
|
23
|
+
export type ClosingError = ProjectStoreError
|
|
24
|
+
/**
|
|
25
|
+
* The project closed and an application under it did not.
|
|
26
|
+
*
|
|
27
|
+
* Reported rather than swallowed, and **the project stays closed**: a partial
|
|
28
|
+
* close is recoverable by running it again, where rolling the project back
|
|
29
|
+
* open would make the failure invisible and leave somebody believing their
|
|
30
|
+
* project is still collecting when most of it has stopped.
|
|
31
|
+
*/
|
|
32
|
+
| {
|
|
33
|
+
readonly code: "partly-closed";
|
|
34
|
+
readonly projectId: ProjectId;
|
|
35
|
+
readonly detail: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const describeClosingError: (error: ClosingError) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Close the project, then every application in it.
|
|
40
|
+
*
|
|
41
|
+
* **The project first.** If it fails there is nothing to undo, and the
|
|
42
|
+
* applications are still reachable through a project that is still open —
|
|
43
|
+
* which is the state the caller started in. The other order would close
|
|
44
|
+
* applications under a project that then refused to close, leaving a live
|
|
45
|
+
* project full of stopped applications and no record of why.
|
|
46
|
+
*
|
|
47
|
+
* Idempotent, because both `close` calls are: running it again after a partial
|
|
48
|
+
* failure closes what is left and moves nothing that already closed.
|
|
49
|
+
*/
|
|
50
|
+
export declare const closeProject: (projects: ProjectStore, applications: ApplicationStore, projectId: ProjectId, at: string) => Promise<Result<undefined, ClosingError>>;
|
|
51
|
+
//# sourceMappingURL=closing.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { err, ok } from "../result.js";
|
|
2
|
+
import { describeProjectStoreError } from "./store.js";
|
|
3
|
+
export const describeClosingError = (error) => error.code === "partly-closed"
|
|
4
|
+
? `project ${error.projectId} was closed and an application in it was not: ${error.detail}`
|
|
5
|
+
: describeProjectStoreError(error);
|
|
6
|
+
/**
|
|
7
|
+
* Why a listing or a close failed, in one string.
|
|
8
|
+
*
|
|
9
|
+
* `ApplicationStoreError` carries a detail on one member and an id on two, so
|
|
10
|
+
* there is no field common to all of them — the code is the part every member
|
|
11
|
+
* has, and it is what a caller of this can act on.
|
|
12
|
+
*/
|
|
13
|
+
const detailOf = (error) => "detail" in error ? error.detail : error.code;
|
|
14
|
+
/**
|
|
15
|
+
* Close the project, then every application in it.
|
|
16
|
+
*
|
|
17
|
+
* **The project first.** If it fails there is nothing to undo, and the
|
|
18
|
+
* applications are still reachable through a project that is still open —
|
|
19
|
+
* which is the state the caller started in. The other order would close
|
|
20
|
+
* applications under a project that then refused to close, leaving a live
|
|
21
|
+
* project full of stopped applications and no record of why.
|
|
22
|
+
*
|
|
23
|
+
* Idempotent, because both `close` calls are: running it again after a partial
|
|
24
|
+
* failure closes what is left and moves nothing that already closed.
|
|
25
|
+
*/
|
|
26
|
+
export const closeProject = async (projects, applications, projectId, at) => {
|
|
27
|
+
const closed = await projects.close(projectId, at);
|
|
28
|
+
if (!closed.ok)
|
|
29
|
+
return err(closed.error);
|
|
30
|
+
/**
|
|
31
|
+
* Every application, open or closed, rather than the open ones: the listing
|
|
32
|
+
* is a separate read and a row that closed between the two would otherwise
|
|
33
|
+
* be missed. `close` leaves an already-closed one exactly as it was.
|
|
34
|
+
*/
|
|
35
|
+
const held = await applications.list({ closed: "all" });
|
|
36
|
+
if (!held.ok) {
|
|
37
|
+
return err({ code: "partly-closed", projectId, detail: detailOf(held.error) });
|
|
38
|
+
}
|
|
39
|
+
for (const application of held.value) {
|
|
40
|
+
if (application.projectId !== projectId)
|
|
41
|
+
continue;
|
|
42
|
+
const stopped = await applications.close(application.applicationId, at);
|
|
43
|
+
if (!stopped.ok) {
|
|
44
|
+
return err({
|
|
45
|
+
code: "partly-closed",
|
|
46
|
+
projectId,
|
|
47
|
+
detail: `${application.applicationId}: ${detailOf(stopped.error)}`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return ok(undefined);
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=closing.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Project } from "./project.js";
|
|
2
|
+
import { type ProjectStore } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* A `ProjectStore` in a `Map`, for a test and for a deployment with no database.
|
|
5
|
+
*
|
|
6
|
+
* The counterpart to `memoryStore`, and it carries the same warning: a `Map`
|
|
7
|
+
* keeps nothing across a process, so on the serverless hosts §3 targets it
|
|
8
|
+
* keeps nothing at all. What it is honestly for is the suite, a lesson, and the
|
|
9
|
+
* first run of an project that has not been given a `DATABASE_URL` yet —
|
|
10
|
+
* where seeing one project called *your project* beats seeing an error.
|
|
11
|
+
*
|
|
12
|
+
* The listing sorts, and the first draft of this file did not — its comment
|
|
13
|
+
* claimed insertion order "happens to be oldest first", which confuses the
|
|
14
|
+
* order rows were *written* with the order they were *created*. A project
|
|
15
|
+
* recorded today with yesterday's `createdAt` is ordinary: it is what importing
|
|
16
|
+
* one, or seeding the default beside projects that already exist, produces. The
|
|
17
|
+
* shared contract writes three out of order and caught it.
|
|
18
|
+
*/
|
|
19
|
+
export declare const memoryProjectStore: (seed?: readonly Project[]) => ProjectStore;
|
|
20
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { applyPatch } from "../patch.js";
|
|
2
|
+
import { err, ok } from "../result.js";
|
|
3
|
+
import { projectSchema } from "./project.js";
|
|
4
|
+
import { matchesListing } from "./store.js";
|
|
5
|
+
/**
|
|
6
|
+
* A `ProjectStore` in a `Map`, for a test and for a deployment with no database.
|
|
7
|
+
*
|
|
8
|
+
* The counterpart to `memoryStore`, and it carries the same warning: a `Map`
|
|
9
|
+
* keeps nothing across a process, so on the serverless hosts §3 targets it
|
|
10
|
+
* keeps nothing at all. What it is honestly for is the suite, a lesson, and the
|
|
11
|
+
* first run of an project that has not been given a `DATABASE_URL` yet —
|
|
12
|
+
* where seeing one project called *your project* beats seeing an error.
|
|
13
|
+
*
|
|
14
|
+
* The listing sorts, and the first draft of this file did not — its comment
|
|
15
|
+
* claimed insertion order "happens to be oldest first", which confuses the
|
|
16
|
+
* order rows were *written* with the order they were *created*. A project
|
|
17
|
+
* recorded today with yesterday's `createdAt` is ordinary: it is what importing
|
|
18
|
+
* one, or seeding the default beside projects that already exist, produces. The
|
|
19
|
+
* shared contract writes three out of order and caught it.
|
|
20
|
+
*/
|
|
21
|
+
export const memoryProjectStore = (seed = []) => {
|
|
22
|
+
const projects = new Map(seed.map((project) => [project.projectId, project]));
|
|
23
|
+
const read = (projectId) => {
|
|
24
|
+
const found = projects.get(projectId);
|
|
25
|
+
return found === undefined ? err({ code: "not-found", projectId }) : ok(found);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
create: async (project) => {
|
|
29
|
+
if (projects.has(project.projectId)) {
|
|
30
|
+
return err({ code: "already-exists", projectId: project.projectId });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The partial unique index Postgres carries, by hand (0292). Without it
|
|
34
|
+
* the two stores disagree about whether a repository can be claimed
|
|
35
|
+
* twice — and the one that admits it is the one `pnpm dev` runs on, so
|
|
36
|
+
* the disagreement would be found in production.
|
|
37
|
+
*/
|
|
38
|
+
if (project.repository !== undefined &&
|
|
39
|
+
[...projects.values()].some((held) => held.repository === project.repository)) {
|
|
40
|
+
return err({ code: "repository-taken", repository: project.repository });
|
|
41
|
+
}
|
|
42
|
+
projects.set(project.projectId, project);
|
|
43
|
+
return ok(project);
|
|
44
|
+
},
|
|
45
|
+
get: async (projectId) => read(projectId),
|
|
46
|
+
list: async (listing) => ok([...projects.values()]
|
|
47
|
+
.filter((project) => matchesListing(project.closedAt, listing))
|
|
48
|
+
.sort((left, right) => left.createdAt.localeCompare(right.createdAt))),
|
|
49
|
+
rename: async (projectId, to) => {
|
|
50
|
+
const found = read(projectId);
|
|
51
|
+
if (!found.ok)
|
|
52
|
+
return found;
|
|
53
|
+
/**
|
|
54
|
+
* Parsed rather than spread, so a name this store would accept and the
|
|
55
|
+
* database would refuse cannot be told apart by which one you used. The
|
|
56
|
+
* two stores agree about what a project is because they both ask
|
|
57
|
+
* `projectSchema`, and they agree about what a patch means because they
|
|
58
|
+
* both apply it with `applyPatch`.
|
|
59
|
+
*
|
|
60
|
+
* Nothing here is clearable, and that is a property of the record rather
|
|
61
|
+
* than of this call: a project is an id, a name and a date, and all three
|
|
62
|
+
* are required. The first optional field it gains is clearable on the day
|
|
63
|
+
* it is added, with no second spelling of nothing to invent.
|
|
64
|
+
*/
|
|
65
|
+
const next = projectSchema.safeParse(applyPatch(found.value, to));
|
|
66
|
+
if (!next.success) {
|
|
67
|
+
return err({ code: "unreadable", projectId, detail: next.error.issues[0]?.message ?? "invalid" });
|
|
68
|
+
}
|
|
69
|
+
projects.set(projectId, next.data);
|
|
70
|
+
return ok(next.data);
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Idempotent, and the instant does not move (0289): pressing the button
|
|
74
|
+
* twice must not change the answer to *when did this stop*.
|
|
75
|
+
*/
|
|
76
|
+
close: async (projectId, at) => {
|
|
77
|
+
const found = read(projectId);
|
|
78
|
+
if (!found.ok)
|
|
79
|
+
return found;
|
|
80
|
+
if (found.value.closedAt !== undefined)
|
|
81
|
+
return ok(found.value);
|
|
82
|
+
const next = { ...found.value, closedAt: at };
|
|
83
|
+
projects.set(projectId, next);
|
|
84
|
+
return ok(next);
|
|
85
|
+
},
|
|
86
|
+
reopen: async (projectId) => {
|
|
87
|
+
const found = read(projectId);
|
|
88
|
+
if (!found.ok)
|
|
89
|
+
return found;
|
|
90
|
+
/** Spelled as a removal rather than `closedAt: undefined`, which a strict parse refuses. */
|
|
91
|
+
const { closedAt: _was, ...open } = found.value;
|
|
92
|
+
projects.set(projectId, open);
|
|
93
|
+
return ok(open);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=memory.js.map
|