@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
package/dist/signals/memory.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_AUDIENCE_ID } from "../audience/audience.js";
|
|
1
2
|
import { cursorPosition, pageEnds } from "../paging.js";
|
|
2
3
|
import { ok } from "../result.js";
|
|
3
4
|
import { systemClock } from "../runtime/events.js";
|
|
4
5
|
import { clampReaderSignalLimit, } from "./journal.js";
|
|
6
|
+
import { actedKey, arrivalKey, funnelHourKey, funnelKey, inAudience, pageViewKey, regionKey, tallyKey, } from "./counters.js";
|
|
7
|
+
import { arrivalHoursOf } from "./arrivals.js";
|
|
8
|
+
import { funnelPairKey } from "./funnel.js";
|
|
5
9
|
/**
|
|
6
10
|
* The buffer and the counters, in the process.
|
|
7
11
|
*
|
|
@@ -14,12 +18,30 @@ import { clampReaderSignalLimit, } from "./journal.js";
|
|
|
14
18
|
* against real time.
|
|
15
19
|
*/
|
|
16
20
|
export const memoryReaderSignalJournal = (clock = systemClock) => {
|
|
21
|
+
/**
|
|
22
|
+
* Mutable rows rather than a frozen list, because one field on a stored
|
|
23
|
+
* delivery changes after it is written: the fold's instant (0351). The array
|
|
24
|
+
* is still replaced wholesale on a delete, so the only in-place write in this
|
|
25
|
+
* store is the stamp — which is the same single-column `UPDATE` Postgres
|
|
26
|
+
* makes.
|
|
27
|
+
*/
|
|
17
28
|
let batches = [];
|
|
18
29
|
let nextSeq = 1;
|
|
19
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The opening marker is dropped rather than buffered.
|
|
32
|
+
*
|
|
33
|
+
* It says *a page view began with this delivery*, which is a fact the door
|
|
34
|
+
* uses and rollup has no question about — and a buffer is for what rollup
|
|
35
|
+
* reads. Postgres drops it by storing the columns it knows, so dropping it
|
|
36
|
+
* here is what keeps the two implementations the same buffer rather than two
|
|
37
|
+
* that happen to pass the same tests.
|
|
38
|
+
*/
|
|
39
|
+
const positioned = ({ first: _opening, ...batch }) => ({
|
|
20
40
|
...batch,
|
|
21
41
|
seq: nextSeq++,
|
|
22
42
|
receivedAt: clock.now(),
|
|
43
|
+
/** Resolved on the way in, as the Postgres buffer resolves it (0284). */
|
|
44
|
+
audienceId: batch.audience ?? DEFAULT_AUDIENCE_ID,
|
|
23
45
|
});
|
|
24
46
|
return {
|
|
25
47
|
receive: (received) => {
|
|
@@ -31,6 +53,9 @@ export const memoryReaderSignalJournal = (clock = systemClock) => {
|
|
|
31
53
|
const from = cursorPosition(request?.cursor);
|
|
32
54
|
const direction = request?.direction ?? "newer";
|
|
33
55
|
const matching = batches.filter((batch) => (request?.treeId === undefined || batch.treeId === request.treeId) &&
|
|
56
|
+
(request?.counted === undefined ||
|
|
57
|
+
request.counted === (batch.foldedAt !== undefined)) &&
|
|
58
|
+
(request?.view === undefined || batch.view === request.view) &&
|
|
34
59
|
(from === undefined || (direction === "older" ? batch.seq < from : batch.seq > from)));
|
|
35
60
|
/** A slice rather than a reverse: a page's order never depends on which end it came from. */
|
|
36
61
|
const page = direction === "older" ? matching.slice(-limit) : matching.slice(0, limit);
|
|
@@ -42,6 +67,25 @@ export const memoryReaderSignalJournal = (clock = systemClock) => {
|
|
|
42
67
|
}),
|
|
43
68
|
}));
|
|
44
69
|
},
|
|
70
|
+
/**
|
|
71
|
+
* Stamp the fold's instant on an unstamped prefix (0351).
|
|
72
|
+
*
|
|
73
|
+
* `foldedAt !== undefined` is the guard rather than a position comparison,
|
|
74
|
+
* so the second call over one prefix moves nothing — the property Postgres
|
|
75
|
+
* gets from `folded_at IS NULL` in its `WHERE`, written here so the two
|
|
76
|
+
* implementations are the same operation rather than two that happen to
|
|
77
|
+
* agree on the first call.
|
|
78
|
+
*/
|
|
79
|
+
counted: ({ before, at }) => {
|
|
80
|
+
let counted = 0;
|
|
81
|
+
batches = batches.map((batch) => {
|
|
82
|
+
if (batch.seq >= before || batch.foldedAt !== undefined)
|
|
83
|
+
return batch;
|
|
84
|
+
counted += 1;
|
|
85
|
+
return { ...batch, foldedAt: at };
|
|
86
|
+
});
|
|
87
|
+
return Promise.resolve(ok({ counted }));
|
|
88
|
+
},
|
|
45
89
|
/** `nextSeq` is not rewound, so a cursor held across a prune never resumes inside what it has seen. */
|
|
46
90
|
forget: ({ before }) => {
|
|
47
91
|
const kept = batches.filter((batch) => batch.seq >= before);
|
|
@@ -51,19 +95,52 @@ export const memoryReaderSignalJournal = (clock = systemClock) => {
|
|
|
51
95
|
},
|
|
52
96
|
};
|
|
53
97
|
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const funnelKey = (answer) => `${answer.treeId} ${answer.revision} ${endOf(answer.pair.from)} ${endOf(answer.pair.to)}`;
|
|
57
|
-
const matches = (row, request) => (request?.treeId === undefined || row.treeId === request.treeId) &&
|
|
98
|
+
const matches = (row, request) => (request?.audience === undefined || row.audienceId === request.audience) &&
|
|
99
|
+
(request?.treeId === undefined || row.treeId === request.treeId) &&
|
|
58
100
|
(request?.revision === undefined || row.revision === request.revision);
|
|
59
101
|
export const memoryReaderTallyStore = () => {
|
|
60
102
|
const tallies = new Map();
|
|
61
103
|
const funnels = new Map();
|
|
62
|
-
const
|
|
63
|
-
|
|
104
|
+
const pageViews = new Map();
|
|
105
|
+
const arrivals = new Map();
|
|
106
|
+
const acted = new Map();
|
|
107
|
+
const funnelHours = new Map();
|
|
108
|
+
/**
|
|
109
|
+
* One row written from two sides, so the add is spelled once and told which
|
|
110
|
+
* column it is moving.
|
|
111
|
+
*
|
|
112
|
+
* A row created by either side starts the other column at nought, which is
|
|
113
|
+
* what it is: openings a rollup has not reached yet, or a window of batches
|
|
114
|
+
* whose opening went to an instance that has since gone away.
|
|
115
|
+
*
|
|
116
|
+
* **`foldedAt` is the one field only one of the two writers may touch**
|
|
117
|
+
* (0274). A fold stamps it; a door write carries forward whatever is there,
|
|
118
|
+
* including nothing — which is what makes it able to say that openings have
|
|
119
|
+
* been pending longer than a deployment's schedule allows, where `updatedAt`
|
|
120
|
+
* cannot.
|
|
121
|
+
*/
|
|
122
|
+
const addPageViews = (counts, counted, at, audience) => {
|
|
123
|
+
for (const count of counts) {
|
|
124
|
+
const key = inAudience(audience, pageViewKey(count));
|
|
125
|
+
const existing = pageViews.get(key);
|
|
126
|
+
const foldedAt = counted === "appearances" ? at : existing?.foldedAt;
|
|
127
|
+
pageViews.set(key, {
|
|
128
|
+
audienceId: audience,
|
|
129
|
+
treeId: count.treeId,
|
|
130
|
+
revision: count.revision,
|
|
131
|
+
opened: (existing?.opened ?? 0) + (counted === "opened" ? count.views : 0),
|
|
132
|
+
appearances: (existing?.appearances ?? 0) + (counted === "appearances" ? count.views : 0),
|
|
133
|
+
updatedAt: at,
|
|
134
|
+
...(foldedAt === undefined ? {} : { foldedAt }),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const addTally = (tally, at, audience) => {
|
|
139
|
+
const key = inAudience(audience, tallyKey(tally));
|
|
64
140
|
const existing = tallies.get(key);
|
|
65
141
|
tallies.set(key, {
|
|
66
142
|
...tally,
|
|
143
|
+
audienceId: audience,
|
|
67
144
|
views: (existing?.views ?? 0) + tally.views,
|
|
68
145
|
reached: (existing?.reached ?? 0) + tally.reached,
|
|
69
146
|
engaged: (existing?.engaged ?? 0) + tally.engaged,
|
|
@@ -71,29 +148,184 @@ export const memoryReaderTallyStore = () => {
|
|
|
71
148
|
activations: (existing?.activations ?? 0) + tally.activations,
|
|
72
149
|
opens: (existing?.opens ?? 0) + tally.opens,
|
|
73
150
|
closes: (existing?.closes ?? 0) + tally.closes,
|
|
151
|
+
completions: (existing?.completions ?? 0) + tally.completions,
|
|
152
|
+
updatedAt: at,
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* One part's hour, added — the hourly slice of the four occurrence counters
|
|
157
|
+
* above (`acted.ts`).
|
|
158
|
+
*/
|
|
159
|
+
const addActed = (count, at, audience) => {
|
|
160
|
+
const key = inAudience(audience, actedKey(count));
|
|
161
|
+
const existing = acted.get(key);
|
|
162
|
+
acted.set(key, {
|
|
163
|
+
...count,
|
|
164
|
+
audienceId: audience,
|
|
165
|
+
activations: (existing?.activations ?? 0) + count.activations,
|
|
166
|
+
opens: (existing?.opens ?? 0) + count.opens,
|
|
167
|
+
closes: (existing?.closes ?? 0) + count.closes,
|
|
168
|
+
completions: (existing?.completions ?? 0) + count.completions,
|
|
74
169
|
updatedAt: at,
|
|
75
170
|
});
|
|
76
171
|
};
|
|
77
|
-
|
|
78
|
-
|
|
172
|
+
/**
|
|
173
|
+
* One pair's hour, added — the hourly cut of the two counts on the answer
|
|
174
|
+
* below (`funnel-hours.ts`).
|
|
175
|
+
*/
|
|
176
|
+
const addFunnelHour = (count, at, audience) => {
|
|
177
|
+
const key = inAudience(audience, funnelHourKey(count));
|
|
178
|
+
const existing = funnelHours.get(key);
|
|
179
|
+
funnelHours.set(key, {
|
|
180
|
+
...count,
|
|
181
|
+
audienceId: audience,
|
|
182
|
+
reached: (existing?.reached ?? 0) + count.reached,
|
|
183
|
+
converted: (existing?.converted ?? 0) + count.converted,
|
|
184
|
+
updatedAt: at,
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const addFunnel = (answer, at, audience) => {
|
|
188
|
+
const key = inAudience(audience, funnelKey(answer));
|
|
79
189
|
const existing = funnels.get(key);
|
|
80
190
|
funnels.set(key, {
|
|
81
191
|
...answer,
|
|
192
|
+
audienceId: audience,
|
|
82
193
|
reached: (existing?.reached ?? 0) + answer.reached,
|
|
83
194
|
converted: (existing?.converted ?? 0) + answer.converted,
|
|
84
195
|
updatedAt: at,
|
|
85
196
|
});
|
|
86
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Every audience in one go, which is the whole window (0316).
|
|
200
|
+
*
|
|
201
|
+
* Nothing here can fail, so there is no partial write to roll back and the
|
|
202
|
+
* atomicity `ReaderTallyStore.applyWindow` asks for is free. What the
|
|
203
|
+
* reference implementation is for is the *other* half of that contract: two
|
|
204
|
+
* entries naming one audience are added rather than refused, which is a
|
|
205
|
+
* property Postgres has to be written to have and this gets by construction.
|
|
206
|
+
*/
|
|
207
|
+
const applyWindow = (window, at) => {
|
|
208
|
+
for (const counters of window) {
|
|
209
|
+
const audience = counters.audience ?? DEFAULT_AUDIENCE_ID;
|
|
210
|
+
for (const tally of counters.tallies)
|
|
211
|
+
addTally(tally, at, audience);
|
|
212
|
+
for (const count of counters.acted ?? [])
|
|
213
|
+
addActed(count, at, audience);
|
|
214
|
+
for (const answer of counters.funnels)
|
|
215
|
+
addFunnel(answer, at, audience);
|
|
216
|
+
for (const count of counters.funnelHours ?? [])
|
|
217
|
+
addFunnelHour(count, at, audience);
|
|
218
|
+
addPageViews(counters.appearances ?? [], "appearances", at, audience);
|
|
219
|
+
}
|
|
220
|
+
return Promise.resolve(ok(undefined));
|
|
221
|
+
};
|
|
87
222
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
223
|
+
applyWindow,
|
|
224
|
+
apply: (counters, at, audience = DEFAULT_AUDIENCE_ID) => applyWindow([{ ...counters, audience }], at),
|
|
225
|
+
/**
|
|
226
|
+
* The total and the hour, or neither (`arrivals.ts`).
|
|
227
|
+
*
|
|
228
|
+
* Nothing here can fail once the hour is in hand, so the atomicity the
|
|
229
|
+
* interface promises costs this store nothing — which is exactly why the
|
|
230
|
+
* instant is turned into an hour **first**: the one failure the pair has is
|
|
231
|
+
* an instant that is not one, and a reference implementation that wrote the
|
|
232
|
+
* total and then discovered it would be a reference for the wrong thing.
|
|
233
|
+
*/
|
|
234
|
+
opened: (openings, at, audience = DEFAULT_AUDIENCE_ID) => {
|
|
235
|
+
const hours = arrivalHoursOf(openings, at);
|
|
236
|
+
if (!hours.ok)
|
|
237
|
+
return Promise.resolve(hours);
|
|
238
|
+
addPageViews(openings, "opened", at, audience);
|
|
239
|
+
for (const count of hours.value) {
|
|
240
|
+
const key = inAudience(audience, arrivalKey(count));
|
|
241
|
+
const existing = arrivals.get(key);
|
|
242
|
+
arrivals.set(key, {
|
|
243
|
+
...count,
|
|
244
|
+
audienceId: audience,
|
|
245
|
+
views: (existing?.views ?? 0) + count.views,
|
|
246
|
+
updatedAt: at,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
93
249
|
return Promise.resolve(ok(undefined));
|
|
94
250
|
},
|
|
95
251
|
tallies: (request) => Promise.resolve(ok([...tallies.values()].filter((row) => matches(row, request)))),
|
|
96
252
|
funnels: (request) => Promise.resolve(ok([...funnels.values()].filter((row) => matches(row, request)))),
|
|
253
|
+
pageViews: (request) => Promise.resolve(ok([...pageViews.values()].filter((row) => matches(row, request)))),
|
|
254
|
+
/**
|
|
255
|
+
* The rows in the range, and the first hour the scope has at all.
|
|
256
|
+
*
|
|
257
|
+
* The second figure is taken over the same narrowing without the range,
|
|
258
|
+
* which is the half a caller cannot compute from the first: a range that
|
|
259
|
+
* came back empty is *nobody arrived* or *we were not counting*, and the
|
|
260
|
+
* only way to tell is to look outside the range.
|
|
261
|
+
*/
|
|
262
|
+
arrivals: (request) => {
|
|
263
|
+
const scoped = [...arrivals.values()].filter((row) => matches(row, request));
|
|
264
|
+
const hours = scoped.filter((row) => (request?.from === undefined || row.hour >= request.from) &&
|
|
265
|
+
(request?.to === undefined || row.hour < request.to));
|
|
266
|
+
const begins = scoped.reduce((first, row) => (first === undefined || row.hour < first ? row.hour : first), undefined);
|
|
267
|
+
return Promise.resolve(ok({ hours, ...(begins === undefined ? {} : { begins }) }));
|
|
268
|
+
},
|
|
269
|
+
/**
|
|
270
|
+
* The same two answers as `arrivals`, narrowed to a part as well.
|
|
271
|
+
*
|
|
272
|
+
* The part narrows **both** halves: the first hour a goal was ever counted
|
|
273
|
+
* in is the first hour that part was acted in, not the first hour the
|
|
274
|
+
* deployment counted anything — otherwise a goal made today would report
|
|
275
|
+
* that it has been measured since the deployment started and draw a flat
|
|
276
|
+
* nought back to then.
|
|
277
|
+
*/
|
|
278
|
+
acted: (request) => {
|
|
279
|
+
const scoped = [...acted.values()].filter((row) => matches(row, request) &&
|
|
280
|
+
(request?.nodeId === undefined || row.nodeId === request.nodeId));
|
|
281
|
+
const hours = scoped.filter((row) => (request?.from === undefined || row.hour >= request.from) &&
|
|
282
|
+
(request?.to === undefined || row.hour < request.to));
|
|
283
|
+
const begins = scoped.reduce((first, row) => (first === undefined || row.hour < first ? row.hour : first), undefined);
|
|
284
|
+
return Promise.resolve(ok({ hours, ...(begins === undefined ? {} : { begins }) }));
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* The same two answers, narrowed to one funnel as well.
|
|
288
|
+
*
|
|
289
|
+
* The pair narrows **both** halves, for the reason the part narrows both of
|
|
290
|
+
* `acted`'s: a step set this afternoon must report that it has been
|
|
291
|
+
* measurable since this afternoon, not since the deployment's first reader.
|
|
292
|
+
* The ends are compared by `funnelPairKey`, which is the one rule for what
|
|
293
|
+
* makes two funnel rows the same question.
|
|
294
|
+
*/
|
|
295
|
+
funnelHours: (request) => {
|
|
296
|
+
const asked = request?.pair === undefined ? undefined : funnelPairKey(request.pair);
|
|
297
|
+
const scoped = [...funnelHours.values()].filter((row) => matches(row, request) && (asked === undefined || funnelPairKey(row.pair) === asked));
|
|
298
|
+
const hours = scoped.filter((row) => (request?.from === undefined || row.hour >= request.from) &&
|
|
299
|
+
(request?.to === undefined || row.hour < request.to));
|
|
300
|
+
const begins = scoped.reduce((first, row) => (first === undefined || row.hour < first ? row.hour : first), undefined);
|
|
301
|
+
return Promise.resolve(ok({ hours, ...(begins === undefined ? {} : { begins }) }));
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Where readers were, in the process.
|
|
307
|
+
*
|
|
308
|
+
* Additive like the tallies, and for a sharper reason: every call is one
|
|
309
|
+
* delivery's worth of arrivals, so a store that replaced would report the last
|
|
310
|
+
* reader rather than the readership.
|
|
311
|
+
*/
|
|
312
|
+
export const memoryReaderRegionStore = () => {
|
|
313
|
+
const regions = new Map();
|
|
314
|
+
return {
|
|
315
|
+
count: (counts, at, audience = DEFAULT_AUDIENCE_ID) => {
|
|
316
|
+
for (const count of counts) {
|
|
317
|
+
const key = inAudience(audience, regionKey(count));
|
|
318
|
+
const existing = regions.get(key);
|
|
319
|
+
regions.set(key, {
|
|
320
|
+
...count,
|
|
321
|
+
audienceId: audience,
|
|
322
|
+
views: (existing?.views ?? 0) + count.views,
|
|
323
|
+
updatedAt: at,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return Promise.resolve(ok(undefined));
|
|
327
|
+
},
|
|
328
|
+
regions: (request) => Promise.resolve(ok([...regions.values()].filter((row) => matches(row, request)))),
|
|
97
329
|
};
|
|
98
330
|
};
|
|
99
331
|
//# sourceMappingURL=memory.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LoomDatabase } from "../store/database.js";
|
|
2
2
|
/**
|
|
3
|
-
* Creating the
|
|
3
|
+
* Creating the seven reader-signal tables, with row level security switched on.
|
|
4
4
|
*
|
|
5
5
|
* The same shape as the store's and the journal's migrations, and here for the
|
|
6
6
|
* same reason: a DDL statement that lives in a document is a DDL statement a
|
|
@@ -10,11 +10,27 @@ import type { LoomDatabase } from "../store/database.js";
|
|
|
10
10
|
* Nothing in these tables identifies a reader — that is 0146's whole argument —
|
|
11
11
|
* but the buffer holds view keys, and a view key plus another deployment's rows
|
|
12
12
|
* is the only combination in Loom that could correlate anything across a
|
|
13
|
-
* tenancy boundary. It
|
|
14
|
-
*
|
|
13
|
+
* tenancy boundary. It used to expire within hours and now expires within the
|
|
14
|
+
* window the deployment states, thirty days by default (0349, 0351); the policy
|
|
15
|
+
* never depended on that and now carries more of the weight.
|
|
16
|
+
*
|
|
17
|
+
* Every table is led by `application_id` (0269). The backfill is the column
|
|
18
|
+
* default rather than an `UPDATE`: these seven never carried `project_id`, so
|
|
19
|
+
* there is no earlier spelling to correct the way `APPLICATION_ID_MIGRATION`
|
|
20
|
+
* corrects the store's — rows that predate the column belong to the deployment
|
|
21
|
+
* that wrote them, which is what `app_default` names.
|
|
22
|
+
*
|
|
23
|
+
* Every table then carries `audience_id`, the second migration 0273 owed and
|
|
24
|
+
* [0284](../../decisions/0284-a-signal-names-the-audience-it-was-collected-under-and-the-predicate-stays-in-the-control-plane.md)
|
|
25
|
+
* settles. Backfilled by its default for the stronger version of the same
|
|
26
|
+
* reason: a row written before the dimension existed was collected when there
|
|
27
|
+
* was one form of every page, so `aud_everyone` is what was true of it rather
|
|
28
|
+
* than a value somebody picked. The four counters take it into their keys; the
|
|
29
|
+
* buffer takes the column and keeps its key and its index, because nothing
|
|
30
|
+
* reads the buffer by audience.
|
|
15
31
|
*/
|
|
16
32
|
/**
|
|
17
|
-
* The
|
|
33
|
+
* The seven tables, as statements a host can run.
|
|
18
34
|
*
|
|
19
35
|
* One statement per entry for the same reason the store's DDL is a list: a
|
|
20
36
|
* driver may refuse several commands in a single prepared statement, and
|