@jam-overture/loom 0.2.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/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/data/adapter.d.ts +9 -1
- package/dist/data/adapter.js +2 -0
- package/dist/data/resolve.d.ts +1 -1
- 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/render/addressed.d.ts +35 -0
- package/dist/render/addressed.js +79 -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 +2 -0
- package/dist/render/index.js +2 -0
- package/dist/render/render.d.ts +11 -0
- package/dist/render/render.js +192 -46
- package/dist/render/request.d.ts +8 -1
- package/dist/render/request.js +1 -0
- package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
- package/dist/runtime/auto-apply-ceiling.js +66 -0
- package/dist/runtime/gate.js +69 -10
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/nesting.d.ts +13 -1
- package/dist/runtime/nesting.js +41 -24
- package/dist/runtime/policy-change.js +8 -2
- package/dist/runtime/policy-log.d.ts +5 -5
- package/dist/runtime/policy.d.ts +8 -6
- package/dist/runtime/policy.js +5 -2
- package/dist/runtime/repointing.js +0 -0
- package/dist/sdk/definition.d.ts +65 -6
- package/dist/sdk/definition.js +44 -0
- package/dist/sdk/registry.d.ts +17 -1
- package/dist/sdk/registry.js +39 -0
- 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/agenda.d.ts +585 -0
- package/dist/signals/agenda.js +295 -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/broadcast.d.ts +25 -15
- package/dist/signals/broadcast.js +209 -36
- package/dist/signals/collect.d.ts +137 -43
- package/dist/signals/collect.js +103 -36
- package/dist/signals/conversion.d.ts +348 -0
- package/dist/signals/conversion.js +235 -0
- package/dist/signals/correlated.contract.d.ts +24 -0
- package/dist/signals/correlated.contract.js +94 -0
- package/dist/signals/counters.d.ts +51 -0
- package/dist/signals/counters.js +58 -0
- package/dist/signals/deployment-change.d.ts +28 -4
- package/dist/signals/deployment-change.js +57 -16
- package/dist/signals/deployment.d.ts +18 -5
- package/dist/signals/deployment.js +37 -11
- package/dist/signals/door.d.ts +34 -12
- package/dist/signals/door.js +37 -13
- package/dist/signals/expire.d.ts +192 -0
- package/dist/signals/expire.js +213 -0
- package/dist/signals/frontier.d.ts +268 -0
- package/dist/signals/frontier.js +145 -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 +60 -0
- package/dist/signals/funnel.js +35 -20
- package/dist/signals/health.d.ts +201 -4
- package/dist/signals/health.js +214 -2
- package/dist/signals/index.d.ts +19 -0
- package/dist/signals/index.js +19 -0
- 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 +112 -9
- package/dist/signals/kept.contract.d.ts +22 -0
- package/dist/signals/kept.contract.js +111 -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-reach-change.d.ts +10 -0
- package/dist/signals/library-reach-change.js +11 -3
- 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.js +2 -6
- package/dist/signals/memory.js +142 -1
- package/dist/signals/migrate.d.ts +6 -5
- package/dist/signals/migrate.js +150 -6
- package/dist/signals/notice.d.ts +88 -33
- package/dist/signals/notice.js +38 -16
- package/dist/signals/part-pace.d.ts +378 -0
- package/dist/signals/part-pace.js +333 -0
- package/dist/signals/parts.d.ts +25 -15
- package/dist/signals/parts.js +32 -73
- package/dist/signals/postgres.js +400 -26
- package/dist/signals/region.d.ts +1 -1
- package/dist/signals/retention.d.ts +43 -21
- package/dist/signals/retention.js +25 -8
- package/dist/signals/rhythm.d.ts +302 -0
- package/dist/signals/rhythm.js +262 -0
- package/dist/signals/rollup.d.ts +127 -1
- package/dist/signals/rollup.js +211 -24
- package/dist/signals/schema.d.ts +640 -3
- package/dist/signals/schema.js +239 -3
- package/dist/signals/silences.d.ts +310 -11
- package/dist/signals/silences.js +243 -0
- package/dist/signals/subtrees.d.ts +123 -0
- package/dist/signals/subtrees.js +102 -0
- package/dist/signals/tally.d.ts +125 -4
- 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-funnels.d.ts +88 -0
- package/dist/signals/window-funnels.js +47 -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 +11 -0
- package/dist/store/index.js +11 -0
- package/dist/store/migrate.d.ts +26 -0
- package/dist/store/migrate.js +64 -0
- package/dist/store/postgres-audience.d.ts +14 -0
- package/dist/store/postgres-audience.js +272 -0
- package/dist/store/postgres.d.ts +1 -0
- package/dist/store/postgres.js +1 -0
- package/dist/store/schema.d.ts +312 -0
- package/dist/store/schema.js +77 -0
- package/dist/store/source.d.ts +57 -1
- package/dist/store/source.js +65 -1
- package/dist/submit/resolve.d.ts +1 -1
- package/dist/telemetry/index.d.ts +1 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/journal.d.ts +32 -0
- package/dist/telemetry/memory.js +10 -1
- package/dist/telemetry/postgres.js +18 -2
- package/dist/telemetry/window.d.ts +135 -0
- package/dist/telemetry/window.js +101 -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 +1 -0
- package/dist/testing/contracts.js +1 -0
- package/dist/testing/journal-contract.js +158 -5
- package/dist/theme/contrast.d.ts +19 -14
- package/dist/theme/contrast.js +181 -17
- package/dist/tree/apply.js +13 -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/package.json +39 -96
- package/dist/runtime/inverse-interpreter.d.ts +0 -90
- package/dist/runtime/inverse-interpreter.js +0 -56
|
@@ -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
|
@@ -13,18 +13,29 @@
|
|
|
13
13
|
* speaks for — it is a column on the reader tables and a field a sender may
|
|
14
14
|
* set — but it is an id a host has to be able to *name*, and the alternative
|
|
15
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.
|
|
16
21
|
*/
|
|
17
22
|
export * from "../application/application.js";
|
|
18
23
|
export * from "../application/memory.js";
|
|
19
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";
|
|
20
29
|
export * from "../project/project.js";
|
|
21
30
|
export * from "../project/memory.js";
|
|
22
31
|
export * from "../project/closing.js";
|
|
23
32
|
export * from "../project/store.js";
|
|
24
33
|
export * from "../application/store.js";
|
|
25
34
|
export * from "./attribution.js";
|
|
35
|
+
export * from "./cache.js";
|
|
26
36
|
export * from "./driver.js";
|
|
27
37
|
export * from "./errors.js";
|
|
38
|
+
export * from "./history.js";
|
|
28
39
|
export * from "./memory.js";
|
|
29
40
|
export * from "./replay.js";
|
|
30
41
|
export * from "./reseed.js";
|
package/dist/store/index.js
CHANGED
|
@@ -13,18 +13,29 @@
|
|
|
13
13
|
* speaks for — it is a column on the reader tables and a field a sender may
|
|
14
14
|
* set — but it is an id a host has to be able to *name*, and the alternative
|
|
15
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.
|
|
16
21
|
*/
|
|
17
22
|
export * from "../application/application.js";
|
|
18
23
|
export * from "../application/memory.js";
|
|
19
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";
|
|
20
29
|
export * from "../project/project.js";
|
|
21
30
|
export * from "../project/memory.js";
|
|
22
31
|
export * from "../project/closing.js";
|
|
23
32
|
export * from "../project/store.js";
|
|
24
33
|
export * from "../application/store.js";
|
|
25
34
|
export * from "./attribution.js";
|
|
35
|
+
export * from "./cache.js";
|
|
26
36
|
export * from "./driver.js";
|
|
27
37
|
export * from "./errors.js";
|
|
38
|
+
export * from "./history.js";
|
|
28
39
|
export * from "./memory.js";
|
|
29
40
|
export * from "./replay.js";
|
|
30
41
|
export * from "./reseed.js";
|
package/dist/store/migrate.d.ts
CHANGED
|
@@ -99,6 +99,25 @@ export declare const PROJECT_STORE_DDL: readonly string[];
|
|
|
99
99
|
* list called schema.
|
|
100
100
|
*/
|
|
101
101
|
export declare const APPLICATION_ID_MIGRATION: readonly string[];
|
|
102
|
+
/**
|
|
103
|
+
* The tables a page's audience rules and its per-audience forms are kept in
|
|
104
|
+
* (0263).
|
|
105
|
+
*
|
|
106
|
+
* Its own list for the reason the other four are theirs: a deployment serving
|
|
107
|
+
* one form of every page has no reason to carry either table, and nothing else
|
|
108
|
+
* here reads them. A host adds them by adding its `ensure` call on purpose.
|
|
109
|
+
*
|
|
110
|
+
* **No backfill and no migration of anything.** Both tables are new, nothing
|
|
111
|
+
* was ever stored in another shape, and a page with no rows in either is served
|
|
112
|
+
* exactly as it is today — the base tree, which is what `audiencesFor` answers
|
|
113
|
+
* for an empty rule list.
|
|
114
|
+
*
|
|
115
|
+
* No index beyond the keys. Both reads are a seek on the key's own prefix: the
|
|
116
|
+
* rules' head is the newest revision under `(application_id, tree_id)`, which
|
|
117
|
+
* the primary key already orders, and a page's forms are a range under the same
|
|
118
|
+
* prefix. An index here would be a second copy of the key.
|
|
119
|
+
*/
|
|
120
|
+
export declare const AUDIENCE_OVERLAY_DDL: readonly string[];
|
|
102
121
|
export declare const ensureTreeStoreSchema: (db: LoomDatabase) => Promise<void>;
|
|
103
122
|
/**
|
|
104
123
|
* Creates the hold table if it is absent. Idempotent on the same terms.
|
|
@@ -131,4 +150,11 @@ export declare const ensureProjectStoreSchema: (db: LoomDatabase) => Promise<voi
|
|
|
131
150
|
* one that was never on the old value.
|
|
132
151
|
*/
|
|
133
152
|
export declare const migrateApplicationIds: (db: LoomDatabase) => Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Creates the audience dimension's two tables if they are absent. Idempotent,
|
|
155
|
+
* and separate for the reason the other four are: a deployment that wants to
|
|
156
|
+
* serve one page to more than one audience gets the tables by adding this call
|
|
157
|
+
* on purpose.
|
|
158
|
+
*/
|
|
159
|
+
export declare const ensureAudienceOverlaySchema: (db: LoomDatabase) => Promise<void>;
|
|
134
160
|
//# sourceMappingURL=migrate.d.ts.map
|
package/dist/store/migrate.js
CHANGED
|
@@ -322,6 +322,61 @@ export const APPLICATION_ID_MIGRATION = [
|
|
|
322
322
|
END IF;
|
|
323
323
|
END
|
|
324
324
|
$$`);
|
|
325
|
+
/**
|
|
326
|
+
* The tables a page's audience rules and its per-audience forms are kept in
|
|
327
|
+
* (0263).
|
|
328
|
+
*
|
|
329
|
+
* Its own list for the reason the other four are theirs: a deployment serving
|
|
330
|
+
* one form of every page has no reason to carry either table, and nothing else
|
|
331
|
+
* here reads them. A host adds them by adding its `ensure` call on purpose.
|
|
332
|
+
*
|
|
333
|
+
* **No backfill and no migration of anything.** Both tables are new, nothing
|
|
334
|
+
* was ever stored in another shape, and a page with no rows in either is served
|
|
335
|
+
* exactly as it is today — the base tree, which is what `audiencesFor` answers
|
|
336
|
+
* for an empty rule list.
|
|
337
|
+
*
|
|
338
|
+
* No index beyond the keys. Both reads are a seek on the key's own prefix: the
|
|
339
|
+
* rules' head is the newest revision under `(application_id, tree_id)`, which
|
|
340
|
+
* the primary key already orders, and a page's forms are a range under the same
|
|
341
|
+
* prefix. An index here would be a second copy of the key.
|
|
342
|
+
*/
|
|
343
|
+
export const AUDIENCE_OVERLAY_DDL = [
|
|
344
|
+
`CREATE TABLE IF NOT EXISTS loom_audience_rules (
|
|
345
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
346
|
+
tree_id text NOT NULL,
|
|
347
|
+
revision integer NOT NULL,
|
|
348
|
+
rules jsonb NOT NULL,
|
|
349
|
+
actor text NOT NULL,
|
|
350
|
+
recorded_at text NOT NULL,
|
|
351
|
+
PRIMARY KEY (application_id, tree_id, revision)
|
|
352
|
+
)`,
|
|
353
|
+
`CREATE TABLE IF NOT EXISTS loom_audience_forms (
|
|
354
|
+
application_id text NOT NULL DEFAULT 'app_default',
|
|
355
|
+
tree_id text NOT NULL,
|
|
356
|
+
audience_id text NOT NULL,
|
|
357
|
+
delta jsonb NOT NULL,
|
|
358
|
+
base_revision integer NOT NULL,
|
|
359
|
+
actor text NOT NULL,
|
|
360
|
+
authored_at text NOT NULL,
|
|
361
|
+
withdrawn_by text,
|
|
362
|
+
withdrawn_at text,
|
|
363
|
+
PRIMARY KEY (application_id, tree_id, audience_id)
|
|
364
|
+
)`,
|
|
365
|
+
/**
|
|
366
|
+
* For a database that already has the table, on the terms the `answered_by`
|
|
367
|
+
* statement above sets out.
|
|
368
|
+
*
|
|
369
|
+
* Nullable with no default and no backfill: `NULL` is *this form is the one
|
|
370
|
+
* its audience is served*, which every row written before these columns is.
|
|
371
|
+
* There is no earlier spelling of *withdrawn* to carry across, because until
|
|
372
|
+
* now a form could not be taken out of service at all (0403).
|
|
373
|
+
*/
|
|
374
|
+
`ALTER TABLE loom_audience_forms ADD COLUMN IF NOT EXISTS withdrawn_by text`,
|
|
375
|
+
`ALTER TABLE loom_audience_forms ADD COLUMN IF NOT EXISTS withdrawn_at text`,
|
|
376
|
+
/** Locked on creation for the reason the tree store's tables are — see above. */
|
|
377
|
+
`ALTER TABLE loom_audience_rules ENABLE ROW LEVEL SECURITY`,
|
|
378
|
+
`ALTER TABLE loom_audience_forms ENABLE ROW LEVEL SECURITY`,
|
|
379
|
+
];
|
|
325
380
|
export const ensureTreeStoreSchema = async (db) => {
|
|
326
381
|
await runStatements(db, TREE_STORE_DDL);
|
|
327
382
|
};
|
|
@@ -366,6 +421,15 @@ export const ensureProjectStoreSchema = async (db) => {
|
|
|
366
421
|
export const migrateApplicationIds = async (db) => {
|
|
367
422
|
await runStatements(db, APPLICATION_ID_MIGRATION);
|
|
368
423
|
};
|
|
424
|
+
/**
|
|
425
|
+
* Creates the audience dimension's two tables if they are absent. Idempotent,
|
|
426
|
+
* and separate for the reason the other four are: a deployment that wants to
|
|
427
|
+
* serve one page to more than one audience gets the tables by adding this call
|
|
428
|
+
* on purpose.
|
|
429
|
+
*/
|
|
430
|
+
export const ensureAudienceOverlaySchema = async (db) => {
|
|
431
|
+
await runStatements(db, AUDIENCE_OVERLAY_DDL);
|
|
432
|
+
};
|
|
369
433
|
const runStatements = async (db, statements) => {
|
|
370
434
|
for (const statement of statements) {
|
|
371
435
|
await db.execute(sql.raw(statement));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type StoreScope } from "../application/application.js";
|
|
2
|
+
import { type AudienceOverlayStore } from "../audience/overlay-store.js";
|
|
3
|
+
import type { LoomDatabase } from "./database.js";
|
|
4
|
+
/**
|
|
5
|
+
* Every query is filtered by the application this handle speaks for (0260), and
|
|
6
|
+
* every write sets it.
|
|
7
|
+
*
|
|
8
|
+
* Without it a page's rules would be read across applications, and two
|
|
9
|
+
* deployments that happened to name their trees alike would serve each other's
|
|
10
|
+
* forms — which is the one thing a dimension that decides *who sees what* cannot
|
|
11
|
+
* get wrong.
|
|
12
|
+
*/
|
|
13
|
+
export declare const postgresAudienceOverlayStore: (db: LoomDatabase, scope?: StoreScope) => AudienceOverlayStore;
|
|
14
|
+
//# sourceMappingURL=postgres-audience.d.ts.map
|