@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,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this subsystem calls a word, in one place.
|
|
3
|
+
*
|
|
4
|
+
* Two readings now cost the same page — the time its words take
|
|
5
|
+
* (`pace.ts`) and how much of what it says got read (`copy.ts`) — and a word
|
|
6
|
+
* is the unit both of them divide by. Two spellings of one rule that agree
|
|
7
|
+
* today is a thing this subsystem has already been bitten by once, in the
|
|
8
|
+
* counter keys the two stores wrote; the remedy there was to publish the rule
|
|
9
|
+
* once and have both sides import it, and this is the same remedy before the
|
|
10
|
+
* same bite.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Words in a run of strings.
|
|
14
|
+
*
|
|
15
|
+
* Whitespace-separated, which is the same rule `sdk/copy.ts` uses to decide a
|
|
16
|
+
* blank value is not a word, and the same one a person counting a paragraph
|
|
17
|
+
* would use. It is wrong for a language that does not put spaces between words,
|
|
18
|
+
* and the handle for that is the costing rate rather than this function: a rate
|
|
19
|
+
* expressed in whatever this calls a word stays internally consistent, and a
|
|
20
|
+
* share of a page's words is unaffected because the same rule is applied to the
|
|
21
|
+
* numerator and the denominator.
|
|
22
|
+
*/
|
|
23
|
+
export declare const countWords: (values: readonly string[]) => number;
|
|
24
|
+
//# sourceMappingURL=words.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this subsystem calls a word, in one place.
|
|
3
|
+
*
|
|
4
|
+
* Two readings now cost the same page — the time its words take
|
|
5
|
+
* (`pace.ts`) and how much of what it says got read (`copy.ts`) — and a word
|
|
6
|
+
* is the unit both of them divide by. Two spellings of one rule that agree
|
|
7
|
+
* today is a thing this subsystem has already been bitten by once, in the
|
|
8
|
+
* counter keys the two stores wrote; the remedy there was to publish the rule
|
|
9
|
+
* once and have both sides import it, and this is the same remedy before the
|
|
10
|
+
* same bite.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Words in a run of strings.
|
|
14
|
+
*
|
|
15
|
+
* Whitespace-separated, which is the same rule `sdk/copy.ts` uses to decide a
|
|
16
|
+
* blank value is not a word, and the same one a person counting a paragraph
|
|
17
|
+
* would use. It is wrong for a language that does not put spaces between words,
|
|
18
|
+
* and the handle for that is the costing rate rather than this function: a rate
|
|
19
|
+
* expressed in whatever this calls a word stays internally consistent, and a
|
|
20
|
+
* share of a page's words is unaffected because the same rule is applied to the
|
|
21
|
+
* numerator and the denominator.
|
|
22
|
+
*/
|
|
23
|
+
export const countWords = (values) => values.reduce((count, value) => count + (value.match(/\S+/g)?.length ?? 0), 0);
|
|
24
|
+
//# sourceMappingURL=words.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serving a stored page without reading its row every time, and being told the
|
|
3
|
+
* moment the row moves.
|
|
4
|
+
*
|
|
5
|
+
* A page the store governs costs one read per reader. A cache over that read is
|
|
6
|
+
* only honest if something clears it when the log grows, because the
|
|
7
|
+
* alternative — a window, a short interval, a build-time copy — serves a
|
|
8
|
+
* revision somebody has already replaced and calls it current. These are the
|
|
9
|
+
* two halves of being told instead: a read-through wrapper over `head`, an
|
|
10
|
+
* invalidating wrapper over `append`, and one tag both derive the same way so
|
|
11
|
+
* that neither can be wrong about which entry belongs to which tree.
|
|
12
|
+
*
|
|
13
|
+
* Neither half knows what the cache is. A host hands in a read-through and a
|
|
14
|
+
* way to invalidate a tag; what sits behind them is its own business, which is
|
|
15
|
+
* what keeps this module free of any framework.
|
|
16
|
+
*/
|
|
17
|
+
import type { TreeId } from "../ids.js";
|
|
18
|
+
import type { TreeStore } from "./store.js";
|
|
19
|
+
/**
|
|
20
|
+
* The tag a cached reading of one tree carries.
|
|
21
|
+
*
|
|
22
|
+
* Derived rather than written down, because the reader and the writer are in
|
|
23
|
+
* different places — on this deployment a public page and a portal action, and
|
|
24
|
+
* on a host's they may be two applications — and a tag spelled twice is a cache
|
|
25
|
+
* that stops being cleared the day one of the two spellings is edited.
|
|
26
|
+
*/
|
|
27
|
+
export declare const treeCacheTag: (treeId: TreeId) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Where a host's cache is reached, and the one obligation on it.
|
|
30
|
+
*
|
|
31
|
+
* `load` produces the value to remember, under `key`, filed against `tags`. A
|
|
32
|
+
* host is free to answer from a previous call with the same `key`, and is
|
|
33
|
+
* expected to drop every entry carrying a tag it is told to invalidate.
|
|
34
|
+
*
|
|
35
|
+
* **A rejecting `load` must not be remembered.** Rejection is the only way this
|
|
36
|
+
* seam can say *do not keep this one*, and it is the only signal a read-through
|
|
37
|
+
* cache is able to honour: by the time there is a value to judge, the cache has
|
|
38
|
+
* been asked for it and a `put` it could decline does not exist. So a read that
|
|
39
|
+
* the store refused is raised rather than returned, and the wrapper below turns
|
|
40
|
+
* it back into the refusal the caller is owed.
|
|
41
|
+
*/
|
|
42
|
+
export interface TreeCache {
|
|
43
|
+
readonly readThrough: (key: readonly string[], tags: readonly string[], load: () => Promise<unknown>) => Promise<unknown>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A handle whose `head` is answered from a cache, and whose other reads are not.
|
|
47
|
+
*
|
|
48
|
+
* ## Why `head` alone
|
|
49
|
+
*
|
|
50
|
+
* It is the read a visitor waits for. A page the store governs is one `head`
|
|
51
|
+
* and a render, so on a surface that serves pages this is the whole of what a
|
|
52
|
+
* cache can recover — and the cost of being wrong about it is bounded by the
|
|
53
|
+
* invalidation below, which is keyed by exactly the tree a `head` names.
|
|
54
|
+
*
|
|
55
|
+
* `revisions` is a history screen, where a reader is asking what happened and
|
|
56
|
+
* is owed the answer as it is now. `list` is the one that could not be cached
|
|
57
|
+
* correctly even if it were worth it: it spans trees, so no tag derived from a
|
|
58
|
+
* tree id can clear it, and a page list that keeps a page somebody has since
|
|
59
|
+
* added is a worse screen than a slow one.
|
|
60
|
+
*
|
|
61
|
+
* ## Writes pass through
|
|
62
|
+
*
|
|
63
|
+
* `create` and `append` are forwarded untouched. Invalidation is a separate
|
|
64
|
+
* wrapper because the two compose in either order and over different handles:
|
|
65
|
+
* on this deployment the writing handle is not the handle a page is read
|
|
66
|
+
* through, and a store that cached its own writes away would still have to be
|
|
67
|
+
* told about everybody else's.
|
|
68
|
+
*/
|
|
69
|
+
export declare const cachingTreeStore: (store: TreeStore, cache: TreeCache) => TreeStore;
|
|
70
|
+
/**
|
|
71
|
+
* A handle that tells a cache the log grew, every time it does.
|
|
72
|
+
*
|
|
73
|
+
* ## Why here rather than on the event stream
|
|
74
|
+
*
|
|
75
|
+
* The runtime narrates a commit, and a host could listen for it. This sits on
|
|
76
|
+
* the store instead, because what a cache has to track is not *a change was
|
|
77
|
+
* accepted* but *this row is not what it was* — and the second is true of every
|
|
78
|
+
* append, including the ones that never went near a composition: a revert, a
|
|
79
|
+
* reseed, a migration, a host's own script. Wrapping the store catches the
|
|
80
|
+
* category; wrapping the runtime catches whichever members of it happen to be
|
|
81
|
+
* proposed.
|
|
82
|
+
*
|
|
83
|
+
* ## `create` is not an invalidation
|
|
84
|
+
*
|
|
85
|
+
* Nothing cached can be wrong about a tree that has just come into existence,
|
|
86
|
+
* because the wrapper above remembers only trees it was handed and a refusal is
|
|
87
|
+
* never remembered. An absent page therefore stays absent for exactly as long
|
|
88
|
+
* as it is absent, and the first reader after a seed reads the row.
|
|
89
|
+
*
|
|
90
|
+
* ## A cache that cannot be told does not lose a write
|
|
91
|
+
*
|
|
92
|
+
* `invalidate` is called after the append succeeded, and a throw from it is
|
|
93
|
+
* contained. The write is already history by then: raising it would report a
|
|
94
|
+
* durable change as a failure, and the caller would be entitled to retry
|
|
95
|
+
* something that has already happened. What the containment costs is a stale
|
|
96
|
+
* entry nobody is told about — so a host whose invalidation can fail should
|
|
97
|
+
* make the failure visible on its own side, where there is something to say
|
|
98
|
+
* about it.
|
|
99
|
+
*/
|
|
100
|
+
export declare const invalidatingTreeStore: (store: TreeStore, invalidate: (tag: string) => void) => TreeStore;
|
|
101
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serving a stored page without reading its row every time, and being told the
|
|
3
|
+
* moment the row moves.
|
|
4
|
+
*
|
|
5
|
+
* A page the store governs costs one read per reader. A cache over that read is
|
|
6
|
+
* only honest if something clears it when the log grows, because the
|
|
7
|
+
* alternative — a window, a short interval, a build-time copy — serves a
|
|
8
|
+
* revision somebody has already replaced and calls it current. These are the
|
|
9
|
+
* two halves of being told instead: a read-through wrapper over `head`, an
|
|
10
|
+
* invalidating wrapper over `append`, and one tag both derive the same way so
|
|
11
|
+
* that neither can be wrong about which entry belongs to which tree.
|
|
12
|
+
*
|
|
13
|
+
* Neither half knows what the cache is. A host hands in a read-through and a
|
|
14
|
+
* way to invalidate a tag; what sits behind them is its own business, which is
|
|
15
|
+
* what keeps this module free of any framework.
|
|
16
|
+
*/
|
|
17
|
+
import { err, ok } from "../result.js";
|
|
18
|
+
import { parseTree } from "../tree/tree.js";
|
|
19
|
+
/**
|
|
20
|
+
* The tag a cached reading of one tree carries.
|
|
21
|
+
*
|
|
22
|
+
* Derived rather than written down, because the reader and the writer are in
|
|
23
|
+
* different places — on this deployment a public page and a portal action, and
|
|
24
|
+
* on a host's they may be two applications — and a tag spelled twice is a cache
|
|
25
|
+
* that stops being cleared the day one of the two spellings is edited.
|
|
26
|
+
*/
|
|
27
|
+
export const treeCacheTag = (treeId) => `loom-tree:${treeId}`;
|
|
28
|
+
const REFUSAL = Symbol("loom.store.cache.refusal");
|
|
29
|
+
const raise = (error) => ({ [REFUSAL]: error });
|
|
30
|
+
const raisedRefusal = (cause) => typeof cause === "object" && cause !== null && REFUSAL in cause
|
|
31
|
+
? cause[REFUSAL]
|
|
32
|
+
: undefined;
|
|
33
|
+
/**
|
|
34
|
+
* A tree that came back from the cache is `unknown` until it is parsed, and it
|
|
35
|
+
* is refused in the same words a stored tree that will not parse is refused.
|
|
36
|
+
*
|
|
37
|
+
* The honesty matters more than it looks. A cached value has been somewhere —
|
|
38
|
+
* at minimum through JSON, possibly through another process — so a wrapper that
|
|
39
|
+
* asserted the type would be the one place in this package where a `LoomTree`
|
|
40
|
+
* is a claim rather than a parse. The taxonomy is not new either: the Postgres
|
|
41
|
+
* store already answers `unavailable` for a row it cannot read back, and a
|
|
42
|
+
* screen that draws one draws the other.
|
|
43
|
+
*/
|
|
44
|
+
const revived = (treeId, cached) => {
|
|
45
|
+
const parsed = parseTree(cached);
|
|
46
|
+
return parsed.ok
|
|
47
|
+
? ok(parsed.value)
|
|
48
|
+
: err({
|
|
49
|
+
code: "unavailable",
|
|
50
|
+
detail: `cached tree ${treeId} did not parse: ${parsed.error.code}`,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const unexpected = (treeId, cause) => ({
|
|
54
|
+
code: "unavailable",
|
|
55
|
+
detail: `reading cached tree ${treeId} threw: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* A handle whose `head` is answered from a cache, and whose other reads are not.
|
|
59
|
+
*
|
|
60
|
+
* ## Why `head` alone
|
|
61
|
+
*
|
|
62
|
+
* It is the read a visitor waits for. A page the store governs is one `head`
|
|
63
|
+
* and a render, so on a surface that serves pages this is the whole of what a
|
|
64
|
+
* cache can recover — and the cost of being wrong about it is bounded by the
|
|
65
|
+
* invalidation below, which is keyed by exactly the tree a `head` names.
|
|
66
|
+
*
|
|
67
|
+
* `revisions` is a history screen, where a reader is asking what happened and
|
|
68
|
+
* is owed the answer as it is now. `list` is the one that could not be cached
|
|
69
|
+
* correctly even if it were worth it: it spans trees, so no tag derived from a
|
|
70
|
+
* tree id can clear it, and a page list that keeps a page somebody has since
|
|
71
|
+
* added is a worse screen than a slow one.
|
|
72
|
+
*
|
|
73
|
+
* ## Writes pass through
|
|
74
|
+
*
|
|
75
|
+
* `create` and `append` are forwarded untouched. Invalidation is a separate
|
|
76
|
+
* wrapper because the two compose in either order and over different handles:
|
|
77
|
+
* on this deployment the writing handle is not the handle a page is read
|
|
78
|
+
* through, and a store that cached its own writes away would still have to be
|
|
79
|
+
* told about everybody else's.
|
|
80
|
+
*/
|
|
81
|
+
export const cachingTreeStore = (store, cache) => ({
|
|
82
|
+
create: (tree) => store.create(tree),
|
|
83
|
+
append: (treeId, request) => store.append(treeId, request),
|
|
84
|
+
revisions: (treeId, request) => store.revisions(treeId, request),
|
|
85
|
+
list: (request) => store.list(request),
|
|
86
|
+
head: async (treeId) => {
|
|
87
|
+
const load = async () => {
|
|
88
|
+
const read = await store.head(treeId);
|
|
89
|
+
if (!read.ok)
|
|
90
|
+
throw raise(read.error);
|
|
91
|
+
return read.value;
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
return revived(treeId, await cache.readThrough([treeId], [treeCacheTag(treeId)], load));
|
|
95
|
+
}
|
|
96
|
+
catch (cause) {
|
|
97
|
+
return err(raisedRefusal(cause) ?? unexpected(treeId, cause));
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* A handle that tells a cache the log grew, every time it does.
|
|
103
|
+
*
|
|
104
|
+
* ## Why here rather than on the event stream
|
|
105
|
+
*
|
|
106
|
+
* The runtime narrates a commit, and a host could listen for it. This sits on
|
|
107
|
+
* the store instead, because what a cache has to track is not *a change was
|
|
108
|
+
* accepted* but *this row is not what it was* — and the second is true of every
|
|
109
|
+
* append, including the ones that never went near a composition: a revert, a
|
|
110
|
+
* reseed, a migration, a host's own script. Wrapping the store catches the
|
|
111
|
+
* category; wrapping the runtime catches whichever members of it happen to be
|
|
112
|
+
* proposed.
|
|
113
|
+
*
|
|
114
|
+
* ## `create` is not an invalidation
|
|
115
|
+
*
|
|
116
|
+
* Nothing cached can be wrong about a tree that has just come into existence,
|
|
117
|
+
* because the wrapper above remembers only trees it was handed and a refusal is
|
|
118
|
+
* never remembered. An absent page therefore stays absent for exactly as long
|
|
119
|
+
* as it is absent, and the first reader after a seed reads the row.
|
|
120
|
+
*
|
|
121
|
+
* ## A cache that cannot be told does not lose a write
|
|
122
|
+
*
|
|
123
|
+
* `invalidate` is called after the append succeeded, and a throw from it is
|
|
124
|
+
* contained. The write is already history by then: raising it would report a
|
|
125
|
+
* durable change as a failure, and the caller would be entitled to retry
|
|
126
|
+
* something that has already happened. What the containment costs is a stale
|
|
127
|
+
* entry nobody is told about — so a host whose invalidation can fail should
|
|
128
|
+
* make the failure visible on its own side, where there is something to say
|
|
129
|
+
* about it.
|
|
130
|
+
*/
|
|
131
|
+
export const invalidatingTreeStore = (store, invalidate) => ({
|
|
132
|
+
create: (tree) => store.create(tree),
|
|
133
|
+
head: (treeId) => store.head(treeId),
|
|
134
|
+
revisions: (treeId, request) => store.revisions(treeId, request),
|
|
135
|
+
list: (request) => store.list(request),
|
|
136
|
+
append: async (treeId, request) => {
|
|
137
|
+
const appended = await store.append(treeId, request);
|
|
138
|
+
if (appended.ok) {
|
|
139
|
+
try {
|
|
140
|
+
invalidate(treeCacheTag(treeId));
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Contained on purpose; the docblock above has the reason.
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return appended;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { TreeId } from "../ids.js";
|
|
2
|
+
import { type Result } from "../result.js";
|
|
3
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
4
|
+
import type { StoreError } from "./errors.js";
|
|
5
|
+
import { type TreeAtRevision } from "./replay.js";
|
|
6
|
+
import type { TreeReader } from "./store.js";
|
|
7
|
+
/**
|
|
8
|
+
* The tree as it was, asked of one handle.
|
|
9
|
+
*
|
|
10
|
+
* Every function in this directory that answers for a past revision —
|
|
11
|
+
* `replayTree`, `treeAt`, `treesAt`, `auditSnapshot`, `planRevert` — takes the
|
|
12
|
+
* seed as a parameter, because 0016 keeps only the head snapshot and a log from
|
|
13
|
+
* revision 1, so revision 0 is the one version a store cannot produce. 0028
|
|
14
|
+
* decided where it comes from instead: **the host**, re-derived from the code
|
|
15
|
+
* that created the tree, which is what makes it evidence rather than a second
|
|
16
|
+
* copy of the data being checked.
|
|
17
|
+
*
|
|
18
|
+
* What 0028 left in one deployment is the *lookup*. `seedFor(treeId)` was the
|
|
19
|
+
* portal's own registry, so a consumer holding a `TreeReader` could not ask for
|
|
20
|
+
* a past revision at all, and the absence of a seed had no published shape — the
|
|
21
|
+
* portal invented `{ kind: "unknown-start" }` for it in `progression.ts` and the
|
|
22
|
+
* next consumer would have invented its own. This joins the two halves: a
|
|
23
|
+
* history is a reader and a seed source, and *"this host cannot prove where this
|
|
24
|
+
* tree started"* is an answer it gives rather than a case each caller discovers.
|
|
25
|
+
*
|
|
26
|
+
* **Nothing here stores a seed, and the schema is untouched.** A stored revision
|
|
27
|
+
* 0 is still the alternative 0028 rejected on scope and this records again.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Where a host's trees started, by id, or `undefined` for a tree it cannot
|
|
31
|
+
* prove the beginning of.
|
|
32
|
+
*
|
|
33
|
+
* Synchronous on purpose, and the reason is 0028's rather than convenience: a
|
|
34
|
+
* seed is evidence only because it is re-derived from the source that built the
|
|
35
|
+
* tree. A lookup that needed IO would be reading a seed back from storage, which
|
|
36
|
+
* is the route 0028 rejected outright — it compares the data with itself.
|
|
37
|
+
*/
|
|
38
|
+
export type SeedSource = (treeId: TreeId) => LoomTree | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* A seed source over a fixed set of trees.
|
|
41
|
+
*
|
|
42
|
+
* Thunks rather than trees: a deployment naming every seed it knows should not
|
|
43
|
+
* build all of them to answer about one, and most calls ask about one. Nothing
|
|
44
|
+
* is cached between calls, so two answers for the same tree are two independent
|
|
45
|
+
* derivations from source — the property the audit depends on.
|
|
46
|
+
*/
|
|
47
|
+
export declare const seedRegistry: (seeds: ReadonlyMap<TreeId, () => LoomTree>) => SeedSource;
|
|
48
|
+
/**
|
|
49
|
+
* The tree as it was, or why not.
|
|
50
|
+
*
|
|
51
|
+
* `unseeded` is the member `TreeAtRevision` has no room for, and it is a
|
|
52
|
+
* statement about the *host* rather than about the log or the revision: the
|
|
53
|
+
* store may hold a perfectly readable history that this deployment cannot fold,
|
|
54
|
+
* because it cannot produce the shape the fold starts from. It costs no read —
|
|
55
|
+
* a history that cannot answer does not touch the log to find that out.
|
|
56
|
+
*/
|
|
57
|
+
export type TreeVersion = TreeAtRevision | {
|
|
58
|
+
readonly outcome: "unseeded";
|
|
59
|
+
readonly treeId: TreeId;
|
|
60
|
+
readonly revision: number;
|
|
61
|
+
};
|
|
62
|
+
/** One sentence per answer, extending `describeTreeAt` with the host's case. */
|
|
63
|
+
export declare const describeTreeVersion: (version: TreeVersion) => string;
|
|
64
|
+
/**
|
|
65
|
+
* A reader and the seeds that make its log foldable.
|
|
66
|
+
*
|
|
67
|
+
* Two methods and not three: `head` is already on the `TreeReader` a caller
|
|
68
|
+
* builds this from, and a history that re-exported it would offer two ways to
|
|
69
|
+
* ask for the current tree — one of which folds the whole log to answer what the
|
|
70
|
+
* snapshot already holds.
|
|
71
|
+
*/
|
|
72
|
+
export type TreeHistory = {
|
|
73
|
+
readonly at: (treeId: TreeId, revision: number) => Promise<Result<TreeVersion, StoreError>>;
|
|
74
|
+
/**
|
|
75
|
+
* The same question about several revisions of one tree, folded once. Keyed by
|
|
76
|
+
* revision, as `treesAt` is, and the two-revision case is what it exists for:
|
|
77
|
+
* a before-and-after reading is one revision against another.
|
|
78
|
+
*/
|
|
79
|
+
readonly atEach: (treeId: TreeId, revisions: readonly number[]) => Promise<Result<ReadonlyMap<number, TreeVersion>, StoreError>>;
|
|
80
|
+
};
|
|
81
|
+
export declare const historyOf: (reader: TreeReader, seeds: SeedSource) => TreeHistory;
|
|
82
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ok } from "../result.js";
|
|
2
|
+
import { describeTreeAt, treeAt, treesAt } from "./replay.js";
|
|
3
|
+
/**
|
|
4
|
+
* A seed source over a fixed set of trees.
|
|
5
|
+
*
|
|
6
|
+
* Thunks rather than trees: a deployment naming every seed it knows should not
|
|
7
|
+
* build all of them to answer about one, and most calls ask about one. Nothing
|
|
8
|
+
* is cached between calls, so two answers for the same tree are two independent
|
|
9
|
+
* derivations from source — the property the audit depends on.
|
|
10
|
+
*/
|
|
11
|
+
export const seedRegistry = (seeds) => {
|
|
12
|
+
return (treeId) => seeds.get(treeId)?.();
|
|
13
|
+
};
|
|
14
|
+
/** One sentence per answer, extending `describeTreeAt` with the host's case. */
|
|
15
|
+
export const describeTreeVersion = (version) => version.outcome === "unseeded"
|
|
16
|
+
? `revision ${version.revision} of ${version.treeId} cannot be replayed: this host has no seed for it`
|
|
17
|
+
: describeTreeAt(version);
|
|
18
|
+
export const historyOf = (reader, seeds) => ({
|
|
19
|
+
at: async (treeId, revision) => {
|
|
20
|
+
const seed = seeds(treeId);
|
|
21
|
+
if (seed === undefined)
|
|
22
|
+
return ok({ outcome: "unseeded", treeId, revision });
|
|
23
|
+
return treeAt(reader, { treeId, revision, seed });
|
|
24
|
+
},
|
|
25
|
+
atEach: async (treeId, revisions) => {
|
|
26
|
+
const seed = seeds(treeId);
|
|
27
|
+
if (seed === undefined) {
|
|
28
|
+
return ok(new Map(revisions.map((revision) => [
|
|
29
|
+
revision,
|
|
30
|
+
{ outcome: "unseeded", treeId, revision },
|
|
31
|
+
])));
|
|
32
|
+
}
|
|
33
|
+
return treesAt(reader, { treeId, revisions, seed });
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=history.js.map
|
package/dist/store/index.d.ts
CHANGED
|
@@ -4,11 +4,41 @@
|
|
|
4
4
|
* A store holds a snapshot and an append-only log beside it, so that any revision
|
|
5
5
|
* can be replayed, attributed, or undone. Two implementations, one contract.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* The project a store speaks for (0260), re-exported here rather than given an
|
|
9
|
+
* entry point of its own: it is the scope every one of these reads sits
|
|
10
|
+
* inside, so a caller that imports a store already needs it.
|
|
11
|
+
*
|
|
12
|
+
* The audience is here on the same terms (0284). It is not a scope a store
|
|
13
|
+
* speaks for — it is a column on the reader tables and a field a sender may
|
|
14
|
+
* set — but it is an id a host has to be able to *name*, and the alternative
|
|
15
|
+
* to naming it here is a host that can read the field and not write one.
|
|
16
|
+
*
|
|
17
|
+
* Its rules and its composition are here for a narrower reason: the thing that
|
|
18
|
+
* composes a page out of a base and the deltas an audience earned is a
|
|
19
|
+
* `TreeSource` over a store (0263), and `source.js` below is where a store
|
|
20
|
+
* becomes one. A host wiring the composing source needs the rule it hands it.
|
|
21
|
+
*/
|
|
22
|
+
export * from "../application/application.js";
|
|
23
|
+
export * from "../application/memory.js";
|
|
24
|
+
export * from "../audience/audience.js";
|
|
25
|
+
export * from "../audience/compose.js";
|
|
26
|
+
export * from "../audience/memory.js";
|
|
27
|
+
export * from "../audience/overlay-store.js";
|
|
28
|
+
export * from "../audience/rule.js";
|
|
29
|
+
export * from "../project/project.js";
|
|
30
|
+
export * from "../project/memory.js";
|
|
31
|
+
export * from "../project/closing.js";
|
|
32
|
+
export * from "../project/store.js";
|
|
33
|
+
export * from "../application/store.js";
|
|
7
34
|
export * from "./attribution.js";
|
|
35
|
+
export * from "./cache.js";
|
|
8
36
|
export * from "./driver.js";
|
|
9
37
|
export * from "./errors.js";
|
|
38
|
+
export * from "./history.js";
|
|
10
39
|
export * from "./memory.js";
|
|
11
40
|
export * from "./replay.js";
|
|
41
|
+
export * from "./reseed.js";
|
|
12
42
|
export * from "./revert.js";
|
|
13
43
|
export * from "./source.js";
|
|
14
44
|
export * from "./store.js";
|
package/dist/store/index.js
CHANGED
|
@@ -4,11 +4,41 @@
|
|
|
4
4
|
* A store holds a snapshot and an append-only log beside it, so that any revision
|
|
5
5
|
* can be replayed, attributed, or undone. Two implementations, one contract.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* The project a store speaks for (0260), re-exported here rather than given an
|
|
9
|
+
* entry point of its own: it is the scope every one of these reads sits
|
|
10
|
+
* inside, so a caller that imports a store already needs it.
|
|
11
|
+
*
|
|
12
|
+
* The audience is here on the same terms (0284). It is not a scope a store
|
|
13
|
+
* speaks for — it is a column on the reader tables and a field a sender may
|
|
14
|
+
* set — but it is an id a host has to be able to *name*, and the alternative
|
|
15
|
+
* to naming it here is a host that can read the field and not write one.
|
|
16
|
+
*
|
|
17
|
+
* Its rules and its composition are here for a narrower reason: the thing that
|
|
18
|
+
* composes a page out of a base and the deltas an audience earned is a
|
|
19
|
+
* `TreeSource` over a store (0263), and `source.js` below is where a store
|
|
20
|
+
* becomes one. A host wiring the composing source needs the rule it hands it.
|
|
21
|
+
*/
|
|
22
|
+
export * from "../application/application.js";
|
|
23
|
+
export * from "../application/memory.js";
|
|
24
|
+
export * from "../audience/audience.js";
|
|
25
|
+
export * from "../audience/compose.js";
|
|
26
|
+
export * from "../audience/memory.js";
|
|
27
|
+
export * from "../audience/overlay-store.js";
|
|
28
|
+
export * from "../audience/rule.js";
|
|
29
|
+
export * from "../project/project.js";
|
|
30
|
+
export * from "../project/memory.js";
|
|
31
|
+
export * from "../project/closing.js";
|
|
32
|
+
export * from "../project/store.js";
|
|
33
|
+
export * from "../application/store.js";
|
|
7
34
|
export * from "./attribution.js";
|
|
35
|
+
export * from "./cache.js";
|
|
8
36
|
export * from "./driver.js";
|
|
9
37
|
export * from "./errors.js";
|
|
38
|
+
export * from "./history.js";
|
|
10
39
|
export * from "./memory.js";
|
|
11
40
|
export * from "./replay.js";
|
|
41
|
+
export * from "./reseed.js";
|
|
12
42
|
export * from "./revert.js";
|
|
13
43
|
export * from "./source.js";
|
|
14
44
|
export * from "./store.js";
|
package/dist/store/memory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StoreScope } from "../application/application.js";
|
|
1
2
|
import { type TreeStore } from "./store.js";
|
|
2
|
-
export declare const memoryTreeStore: () => TreeStore;
|
|
3
|
+
export declare const memoryTreeStore: (scope?: StoreScope) => TreeStore;
|
|
3
4
|
//# sourceMappingURL=memory.d.ts.map
|
package/dist/store/memory.js
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
|
+
import { DEFAULT_APPLICATION_ID } from "../application/application.js";
|
|
1
2
|
import { cursorPosition, pageEnds } from "../paging.js";
|
|
2
3
|
import { err, ok } from "../result.js";
|
|
3
4
|
import { applyDelta } from "../tree/apply.js";
|
|
4
5
|
import { anchorBound, anchorResumes, clampListingLimit, clampRevisionLimit, } from "./store.js";
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The summary, read off the log rather than assembled beside it.
|
|
8
|
+
*
|
|
9
|
+
* `changedAt` is the newest entry's `appliedAt`, and taking it from the log is
|
|
10
|
+
* what makes the contract's promise true here by construction: an empty log is
|
|
11
|
+
* revision 0 and yields no stamp, so the two cannot disagree without `append`
|
|
12
|
+
* having broken the invariant that advances them together.
|
|
13
|
+
*/
|
|
14
|
+
const listingOf = (entry) => {
|
|
15
|
+
const newest = entry.log.at(-1);
|
|
16
|
+
return {
|
|
17
|
+
treeId: entry.snapshot.treeId,
|
|
18
|
+
revision: entry.snapshot.revision,
|
|
19
|
+
...(newest === undefined ? {} : { changedAt: newest.appliedAt }),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const memoryTreeStore = (scope = {}) => {
|
|
23
|
+
const project = scope.application ?? DEFAULT_APPLICATION_ID;
|
|
24
|
+
/*
|
|
25
|
+
* Keyed by project and tree even though a handle only ever sees one project,
|
|
26
|
+
* so that this store means the same thing the Postgres one does: a tree id
|
|
27
|
+
* is unique within a project and says nothing about any other. Without it a
|
|
28
|
+
* test that built one handle and expected two projects would quietly get one.
|
|
29
|
+
*/
|
|
6
30
|
const trees = new Map();
|
|
7
|
-
const
|
|
31
|
+
const keyOf = (treeId) => `${project}\u0000${treeId}`;
|
|
32
|
+
const entryOf = (treeId) => trees.get(keyOf(treeId));
|
|
8
33
|
return {
|
|
9
|
-
create: (tree) => Promise.resolve(trees.has(tree.treeId)
|
|
34
|
+
create: (tree) => Promise.resolve(trees.has(keyOf(tree.treeId))
|
|
10
35
|
? err({ code: "already-exists", treeId: tree.treeId })
|
|
11
36
|
: (() => {
|
|
12
|
-
trees.set(tree.treeId, { snapshot: tree, log: [] });
|
|
37
|
+
trees.set(keyOf(tree.treeId), { snapshot: tree, log: [] });
|
|
13
38
|
return ok(tree);
|
|
14
39
|
})()),
|
|
15
40
|
head: (treeId) => {
|
|
@@ -56,18 +81,29 @@ export const memoryTreeStore = () => {
|
|
|
56
81
|
list: (request) => {
|
|
57
82
|
const limit = clampListingLimit(request?.limit);
|
|
58
83
|
const cursor = request?.cursor;
|
|
59
|
-
|
|
84
|
+
/*
|
|
85
|
+
* Over tree ids rather than over the map's keys, which now carry the
|
|
86
|
+
* project in front of them. A cursor is opaque to whoever holds it, and
|
|
87
|
+
* a key would make it opaque *and* project-specific — so a page token
|
|
88
|
+
* from one handle, replayed against another, would silently return
|
|
89
|
+
* nothing instead of failing. The ids are what the caller was given and
|
|
90
|
+
* are what it gets back.
|
|
91
|
+
*/
|
|
92
|
+
const ids = Array.from(trees.values())
|
|
93
|
+
.map((entry) => entry.snapshot.treeId)
|
|
60
94
|
.sort()
|
|
61
|
-
.filter((
|
|
62
|
-
const page =
|
|
63
|
-
const listings = page.flatMap((
|
|
64
|
-
const entry =
|
|
65
|
-
|
|
95
|
+
.filter((treeId) => cursor === undefined || treeId > cursor);
|
|
96
|
+
const page = ids.slice(0, limit);
|
|
97
|
+
const listings = page.flatMap((treeId) => {
|
|
98
|
+
const entry = entryOf(treeId);
|
|
99
|
+
if (!entry)
|
|
100
|
+
return [];
|
|
101
|
+
return [listingOf(entry)];
|
|
66
102
|
});
|
|
67
103
|
const last = page.at(-1);
|
|
68
104
|
return Promise.resolve(ok({
|
|
69
105
|
trees: listings,
|
|
70
|
-
cursor: last !== undefined &&
|
|
106
|
+
cursor: last !== undefined && ids.length > page.length ? last : null,
|
|
71
107
|
}));
|
|
72
108
|
},
|
|
73
109
|
append: (treeId, request) => {
|
|
@@ -107,7 +143,7 @@ export const memoryTreeStore = () => {
|
|
|
107
143
|
...(request.answeredBy === undefined ? {} : { answeredBy: request.answeredBy }),
|
|
108
144
|
};
|
|
109
145
|
/** One write, so the log and the snapshot cannot be seen disagreeing. */
|
|
110
|
-
trees.set(treeId, { snapshot: applied.value, log: [...entry.log, revision] });
|
|
146
|
+
trees.set(keyOf(treeId), { snapshot: applied.value, log: [...entry.log, revision] });
|
|
111
147
|
return Promise.resolve(ok(applied.value));
|
|
112
148
|
},
|
|
113
149
|
};
|