@crubal/postgres 0.0.0-stage → 0.4.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 +126 -2
- package/dist/bin/crubal-pg.d.ts +2 -0
- package/dist/bin/crubal-pg.js +115 -0
- package/dist/bin/crubal-pg.js.map +1 -0
- package/dist/src/border.d.ts +126 -0
- package/dist/src/border.js +442 -0
- package/dist/src/border.js.map +1 -0
- package/dist/src/db.d.ts +27 -0
- package/dist/src/db.js +74 -0
- package/dist/src/db.js.map +1 -0
- package/dist/src/definitions.d.ts +25 -0
- package/dist/src/definitions.js +243 -0
- package/dist/src/definitions.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/projector.d.ts +24 -0
- package/dist/src/projector.js +182 -0
- package/dist/src/projector.js.map +1 -0
- package/dist/src/schema.sql +335 -0
- package/dist/src/state.d.ts +16 -0
- package/dist/src/state.js +165 -0
- package/dist/src/state.js.map +1 -0
- package/dist/src/store.d.ts +375 -0
- package/dist/src/store.js +1603 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/working.d.ts +64 -0
- package/dist/src/working.js +315 -0
- package/dist/src/working.js.map +1 -0
- package/package.json +44 -4
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
-- The persistent store's schema (docs/design/store.md). Every table is keyed by owner: a domain, or a
|
|
2
|
+
-- hosted person's domain:ID. The log is the truth; every other table is a cache that `rebuild` gives back
|
|
3
|
+
-- from the log alone. JSON columns hold the spec's JSON form unchanged. `ord` keeps insertion order, so a
|
|
4
|
+
-- state read back lists things in the order the log made them, as the memory store does.
|
|
5
|
+
|
|
6
|
+
create table if not exists schema_version (version text primary key, applied_at timestamptz not null default now());
|
|
7
|
+
|
|
8
|
+
create table if not exists chains (
|
|
9
|
+
owner text not null,
|
|
10
|
+
chain text not null,
|
|
11
|
+
head_seq bigint not null default 0,
|
|
12
|
+
head_hash text,
|
|
13
|
+
primary key (owner, chain)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- Append-only. The one update allowed is redaction (8.5.2); the trigger below refuses every other one.
|
|
17
|
+
create table if not exists log (
|
|
18
|
+
owner text not null,
|
|
19
|
+
chain text not null,
|
|
20
|
+
seq bigint not null,
|
|
21
|
+
log_id text not null,
|
|
22
|
+
prev text,
|
|
23
|
+
hash text not null,
|
|
24
|
+
at text,
|
|
25
|
+
witnessed boolean not null default false,
|
|
26
|
+
entry jsonb not null,
|
|
27
|
+
primary key (owner, chain, seq),
|
|
28
|
+
unique (owner, log_id)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
create table if not exists records (
|
|
32
|
+
owner text not null,
|
|
33
|
+
id text not null,
|
|
34
|
+
ord bigint generated always as identity,
|
|
35
|
+
kind text not null,
|
|
36
|
+
level text not null,
|
|
37
|
+
"of" text,
|
|
38
|
+
within text,
|
|
39
|
+
ancestors text[] not null default '{}',
|
|
40
|
+
status jsonb,
|
|
41
|
+
applied jsonb,
|
|
42
|
+
wears text[] not null default '{}',
|
|
43
|
+
created text,
|
|
44
|
+
updated text,
|
|
45
|
+
doc jsonb not null,
|
|
46
|
+
primary key (owner, id)
|
|
47
|
+
);
|
|
48
|
+
create index if not exists records_level on records (owner, level);
|
|
49
|
+
-- A level's or a kind's rows in log order with a limit, served from the index alone (the probe: a seq scan over a million rows otherwise).
|
|
50
|
+
create index if not exists records_level_ord on records (owner, level, ord);
|
|
51
|
+
create index if not exists records_kind_ord on records (owner, kind, ord);
|
|
52
|
+
create index if not exists records_of on records (owner, "of");
|
|
53
|
+
create index if not exists records_within on records (owner, within);
|
|
54
|
+
create index if not exists records_ancestors on records using gin (ancestors);
|
|
55
|
+
create index if not exists records_values on records using gin ((doc -> 'values'));
|
|
56
|
+
create index if not exists records_kind on records (owner, kind);
|
|
57
|
+
create index if not exists records_wears on records using gin (wears);
|
|
58
|
+
-- The few records holding a suggestion or a held value, for the review queue: without it the question was a
|
|
59
|
+
-- sequential scan of the catalog on every signed-in page (a million rows, 1.3 s, Media Encyclopedia 2026-10-22).
|
|
60
|
+
create index if not exists records_awaiting on records (owner, ord) where (doc ? 'suggestions' or doc ? 'held');
|
|
61
|
+
-- The notifications not yet emailed, for the delivery pass: the kind as a whole grows for ever.
|
|
62
|
+
create index if not exists records_undelivered on records (owner, ord) where kind = 'notification' and not (doc -> 'values' ? 'emailedAt');
|
|
63
|
+
|
|
64
|
+
create table if not exists definitions (
|
|
65
|
+
owner text not null,
|
|
66
|
+
key text not null,
|
|
67
|
+
ord bigint generated always as identity,
|
|
68
|
+
json jsonb not null,
|
|
69
|
+
primary key (owner, key)
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
create table if not exists installed (
|
|
73
|
+
owner text not null,
|
|
74
|
+
ord bigint generated always as identity,
|
|
75
|
+
json jsonb not null,
|
|
76
|
+
primary key (owner, ord)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
-- The bundle of every installed version, whole: the install write names it by hash, and definitions are
|
|
80
|
+
-- rebuilt from it (docs/design/publishing.md).
|
|
81
|
+
create table if not exists bundles (
|
|
82
|
+
owner text not null,
|
|
83
|
+
package text not null,
|
|
84
|
+
version text not null,
|
|
85
|
+
hash text not null,
|
|
86
|
+
json jsonb not null,
|
|
87
|
+
primary key (owner, package, version)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
create table if not exists edges (
|
|
91
|
+
owner text not null,
|
|
92
|
+
edge text not null,
|
|
93
|
+
ord bigint generated always as identity,
|
|
94
|
+
json jsonb not null,
|
|
95
|
+
primary key (owner, edge)
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
create table if not exists bindings (
|
|
99
|
+
owner text not null,
|
|
100
|
+
key text not null,
|
|
101
|
+
ord bigint generated always as identity,
|
|
102
|
+
record text not null,
|
|
103
|
+
primary key (owner, key)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
create table if not exists instructions (
|
|
107
|
+
owner text not null,
|
|
108
|
+
issuer text not null,
|
|
109
|
+
n integer not null,
|
|
110
|
+
ord bigint generated always as identity,
|
|
111
|
+
json jsonb not null,
|
|
112
|
+
primary key (owner, issuer, n)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
create table if not exists review (
|
|
116
|
+
owner text not null,
|
|
117
|
+
ord bigint generated always as identity,
|
|
118
|
+
json jsonb not null,
|
|
119
|
+
primary key (owner, ord)
|
|
120
|
+
);
|
|
121
|
+
create index if not exists review_key on review (owner, (json ->> 'key'));
|
|
122
|
+
|
|
123
|
+
create table if not exists runs (
|
|
124
|
+
owner text not null,
|
|
125
|
+
run text not null,
|
|
126
|
+
ord bigint generated always as identity,
|
|
127
|
+
json jsonb not null,
|
|
128
|
+
primary key (owner, run)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
create table if not exists observations (
|
|
132
|
+
owner text not null,
|
|
133
|
+
ord bigint generated always as identity,
|
|
134
|
+
json jsonb not null,
|
|
135
|
+
primary key (owner, ord)
|
|
136
|
+
);
|
|
137
|
+
create index if not exists observations_on on observations (owner, (json ->> 'on'));
|
|
138
|
+
create index if not exists observations_supports on observations (owner, (json ->> 'supports'));
|
|
139
|
+
|
|
140
|
+
create table if not exists reads (
|
|
141
|
+
owner text not null,
|
|
142
|
+
ord bigint generated always as identity,
|
|
143
|
+
json jsonb not null,
|
|
144
|
+
primary key (owner, ord)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
-- Kept beside the log, never rebuilt from it (9.1): the bytes as received.
|
|
148
|
+
create table if not exists intake (
|
|
149
|
+
owner text not null,
|
|
150
|
+
intake text not null,
|
|
151
|
+
contract text,
|
|
152
|
+
received text,
|
|
153
|
+
"for" text,
|
|
154
|
+
raw bytea,
|
|
155
|
+
sha256 text,
|
|
156
|
+
type text,
|
|
157
|
+
json jsonb not null,
|
|
158
|
+
primary key (owner, intake)
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
-- A send's mapped-out payload, kept beside the log (docs/design/runs.md): the run write holds only its hash,
|
|
162
|
+
-- so the payload can be shown, replayed to the adapter on retry, and erased.
|
|
163
|
+
create table if not exists outtake (
|
|
164
|
+
owner text not null,
|
|
165
|
+
run text not null,
|
|
166
|
+
contract text not null,
|
|
167
|
+
record text,
|
|
168
|
+
key text not null,
|
|
169
|
+
raw bytea not null,
|
|
170
|
+
sha256 text not null,
|
|
171
|
+
primary key (owner, run)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
create table if not exists cursors (
|
|
175
|
+
owner text not null,
|
|
176
|
+
contract text not null,
|
|
177
|
+
view text not null,
|
|
178
|
+
version text not null,
|
|
179
|
+
audience text not null,
|
|
180
|
+
seq bigint not null,
|
|
181
|
+
primary key (owner, contract, view, version, audience)
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
create table if not exists schedules (
|
|
185
|
+
owner text not null,
|
|
186
|
+
contract text not null,
|
|
187
|
+
last_tick text,
|
|
188
|
+
primary key (owner, contract)
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
create table if not exists projections (
|
|
192
|
+
owner text not null,
|
|
193
|
+
view text not null,
|
|
194
|
+
version text not null,
|
|
195
|
+
audience text not null,
|
|
196
|
+
record text not null,
|
|
197
|
+
row jsonb,
|
|
198
|
+
buckets jsonb,
|
|
199
|
+
marks jsonb,
|
|
200
|
+
ancestors text[] not null default '{}',
|
|
201
|
+
sort jsonb,
|
|
202
|
+
pin integer,
|
|
203
|
+
seq bigint not null,
|
|
204
|
+
primary key (owner, view, version, audience, record)
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
create table if not exists projection_stream (
|
|
208
|
+
owner text not null,
|
|
209
|
+
view text not null,
|
|
210
|
+
version text not null,
|
|
211
|
+
audience text not null,
|
|
212
|
+
seq bigint not null,
|
|
213
|
+
json jsonb not null,
|
|
214
|
+
primary key (owner, view, version, audience, seq)
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
-- Where a stream's compaction got to (12.6.2): the seq the pass last looked at, whether the pass reached
|
|
218
|
+
-- the stream's end, and the head it saw there; a stream whose head has not moved since is skipped.
|
|
219
|
+
create table if not exists compaction_cursors (
|
|
220
|
+
owner text not null,
|
|
221
|
+
view text not null,
|
|
222
|
+
version text not null,
|
|
223
|
+
audience text not null,
|
|
224
|
+
seq bigint not null default 0,
|
|
225
|
+
done boolean not null default false,
|
|
226
|
+
head bigint not null default 0,
|
|
227
|
+
primary key (owner, view, version, audience)
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
-- The removals a compaction pass met walking a stream down from its head: a record that left the view has
|
|
231
|
+
-- no stored row, so its earlier entries are superseded by the removal met first. Cleared as a stream's walk starts.
|
|
232
|
+
create table if not exists compaction_removed (
|
|
233
|
+
owner text not null,
|
|
234
|
+
view text not null,
|
|
235
|
+
version text not null,
|
|
236
|
+
audience text not null,
|
|
237
|
+
record text not null,
|
|
238
|
+
seq bigint not null,
|
|
239
|
+
primary key (owner, view, version, audience, record)
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
-- A view published at least once for an audience, and under which version: a view with no rows is
|
|
243
|
+
-- otherwise indistinguishable from one never published, and would rebuild whole on every write.
|
|
244
|
+
create table if not exists published (
|
|
245
|
+
owner text not null,
|
|
246
|
+
view text not null,
|
|
247
|
+
audience text not null,
|
|
248
|
+
version text not null,
|
|
249
|
+
primary key (owner, view, audience)
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
create table if not exists stale (
|
|
253
|
+
owner text not null,
|
|
254
|
+
view text not null,
|
|
255
|
+
record text not null,
|
|
256
|
+
since bigint not null,
|
|
257
|
+
primary key (owner, view, record)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
-- The log never changes except by redaction (8.5.2): a write replaced by its hash, or an entry reduced to
|
|
261
|
+
-- its hash. Anything else is refused here, whatever the caller.
|
|
262
|
+
create or replace function log_only_redaction() returns trigger language plpgsql as $$
|
|
263
|
+
declare
|
|
264
|
+
i integer;
|
|
265
|
+
old_writes jsonb := old.entry -> 'writes';
|
|
266
|
+
new_writes jsonb := new.entry -> 'writes';
|
|
267
|
+
begin
|
|
268
|
+
if tg_op = 'DELETE' then
|
|
269
|
+
raise exception 'the log is append-only: % cannot be deleted', old.log_id;
|
|
270
|
+
end if;
|
|
271
|
+
if new.owner <> old.owner or new.chain <> old.chain or new.seq <> old.seq or new.log_id <> old.log_id
|
|
272
|
+
or new.hash <> old.hash or coalesce(new.prev, '') <> coalesce(old.prev, '') then
|
|
273
|
+
raise exception 'the log is append-only: only a redaction may change %', old.log_id;
|
|
274
|
+
end if;
|
|
275
|
+
-- A whole entry reduced to its hash.
|
|
276
|
+
if new.entry ? 'redacted' then
|
|
277
|
+
if (new.entry - 'log' - 'prev' - 'chain' - 'sig' - 'redacted') <> '{}'::jsonb then
|
|
278
|
+
raise exception 'a redacted entry keeps only log, prev, chain, sig and redacted: %', old.log_id;
|
|
279
|
+
end if;
|
|
280
|
+
return new;
|
|
281
|
+
end if;
|
|
282
|
+
-- Write by write: every write is unchanged or replaced by {"redacted": "sha256:…"}.
|
|
283
|
+
if (new.entry - 'writes') <> (old.entry - 'writes') or jsonb_array_length(new_writes) <> jsonb_array_length(old_writes) then
|
|
284
|
+
raise exception 'the log is append-only: only a write may be redacted in %', old.log_id;
|
|
285
|
+
end if;
|
|
286
|
+
for i in 0 .. jsonb_array_length(old_writes) - 1 loop
|
|
287
|
+
if (new_writes -> i) <> (old_writes -> i) and not (((new_writes -> i) ? 'redacted') and ((new_writes -> i) - 'redacted') = '{}'::jsonb) then
|
|
288
|
+
raise exception 'the log is append-only: write % of % may only be redacted', i, old.log_id;
|
|
289
|
+
end if;
|
|
290
|
+
end loop;
|
|
291
|
+
return new;
|
|
292
|
+
end $$;
|
|
293
|
+
|
|
294
|
+
drop trigger if exists log_only_redaction on log;
|
|
295
|
+
create trigger log_only_redaction before update or delete on log for each row execute function log_only_redaction();
|
|
296
|
+
|
|
297
|
+
insert into schema_version (version) values ('2026-10-15') on conflict do nothing;
|
|
298
|
+
|
|
299
|
+
-- One order across an owner's chain and the chains of the people it hosts (14.1), for a rebuild.
|
|
300
|
+
alter table log add column if not exists ord bigint generated always as identity;
|
|
301
|
+
|
|
302
|
+
-- The platform index reads a caller's edges across owners (14.8, docs/design/host.md).
|
|
303
|
+
create index if not exists edges_who on edges ((json->>'who'));
|
|
304
|
+
|
|
305
|
+
-- A restamp deferred by an install over more records than one batch holds (10.4, 0.3.11): the pin moved in
|
|
306
|
+
-- the install's entry, the records walked afterwards in batches, each its own entry; the walk's progress here.
|
|
307
|
+
create table if not exists restamps (
|
|
308
|
+
owner text not null,
|
|
309
|
+
package text not null,
|
|
310
|
+
version text not null,
|
|
311
|
+
from_version text not null,
|
|
312
|
+
after_ord bigint not null default -1,
|
|
313
|
+
restamped integer not null default 0,
|
|
314
|
+
review integer not null default 0,
|
|
315
|
+
done boolean not null default false,
|
|
316
|
+
started text,
|
|
317
|
+
finished text,
|
|
318
|
+
primary key (owner, package, version)
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
-- Revision 50: the records each entry touches, and how far the index is whole (a log from before it is
|
|
322
|
+
-- indexed a batch at a time by indexTouches).
|
|
323
|
+
create table if not exists log_touches (
|
|
324
|
+
owner text not null,
|
|
325
|
+
chain text not null,
|
|
326
|
+
record text not null,
|
|
327
|
+
seq bigint not null,
|
|
328
|
+
primary key (owner, chain, record, seq)
|
|
329
|
+
);
|
|
330
|
+
create table if not exists log_touch_cursors (
|
|
331
|
+
owner text not null,
|
|
332
|
+
chain text not null,
|
|
333
|
+
seq bigint not null default 0,
|
|
334
|
+
primary key (owner, chain)
|
|
335
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type State } from "@crubal/engine";
|
|
2
|
+
import type { JsonObject, Record } from "@crubal/engine";
|
|
3
|
+
import type { Client } from "./db.ts";
|
|
4
|
+
declare const isObj: (v: unknown) => v is JsonObject;
|
|
5
|
+
export type Row = {
|
|
6
|
+
[column: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
/** A record as the engine holds it, from its row. Absent members stay absent. */
|
|
9
|
+
export declare function recordOf(row: Row): Record;
|
|
10
|
+
/** Read an owner's whole state. Order is the order the log made things, by `ord`. */
|
|
11
|
+
export declare function loadState(client: Client, owner: string): Promise<State>;
|
|
12
|
+
/** Write what changed between two states of one owner: upserts, deletes, and appends to the lists. */
|
|
13
|
+
export declare function persist(client: Client, owner: string, before: State, after: State): Promise<void>;
|
|
14
|
+
/** Forget an owner's state tables (not its log), before a rebuild. */
|
|
15
|
+
export declare function wipeState(client: Client, owner: string): Promise<void>;
|
|
16
|
+
export { isObj };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// state.ts: an owner's state in the tables, read into the engine's State and written back as the diff of
|
|
2
|
+
// two states. The engine's applyEntry is the one meaning of a write; this file only persists its result,
|
|
3
|
+
// so the Postgres store can never apply an entry differently from the memory one.
|
|
4
|
+
import { serialize } from "@crubal/engine";
|
|
5
|
+
import { emptyState } from "@crubal/engine";
|
|
6
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7
|
+
/** A record as the engine holds it, from its row. Absent members stay absent. */
|
|
8
|
+
export function recordOf(row) {
|
|
9
|
+
const doc = (row.doc ?? {});
|
|
10
|
+
// The row's owner is the store's; the record's own owner (a hosted person's, another owner's) is in doc.
|
|
11
|
+
const r = { id: String(row.id), kind: String(row.kind), level: String(row.level), owner: String(doc.owner ?? row.owner), values: (doc.values ?? {}) };
|
|
12
|
+
if (row.of)
|
|
13
|
+
r.of = String(row.of);
|
|
14
|
+
if (row.within)
|
|
15
|
+
r.within = String(row.within);
|
|
16
|
+
if (row.status)
|
|
17
|
+
r.status = row.status;
|
|
18
|
+
if (row.applied)
|
|
19
|
+
r.applied = row.applied;
|
|
20
|
+
if (Array.isArray(row.wears) && row.wears.length)
|
|
21
|
+
r.wears = row.wears.map(String);
|
|
22
|
+
if (row.created)
|
|
23
|
+
r.created = String(row.created);
|
|
24
|
+
if (row.updated)
|
|
25
|
+
r.updated = String(row.updated);
|
|
26
|
+
const extra = r;
|
|
27
|
+
for (const m of ["parts", "sources", "alternatives", "suggestions", "held", "carriers"])
|
|
28
|
+
if (doc[m] !== undefined)
|
|
29
|
+
extra[m] = doc[m];
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
/** The members of a record that live in `doc`, not in a column. */
|
|
33
|
+
function docOf(r) {
|
|
34
|
+
const x = r;
|
|
35
|
+
const doc = { owner: r.owner, values: r.values };
|
|
36
|
+
for (const m of ["parts", "sources", "alternatives", "suggestions", "held", "carriers"])
|
|
37
|
+
if (x[m] !== undefined)
|
|
38
|
+
doc[m] = x[m];
|
|
39
|
+
return doc;
|
|
40
|
+
}
|
|
41
|
+
/** Every record up a record's `within` chain (14.2), nearest first. */
|
|
42
|
+
function ancestorsOf(records, r) {
|
|
43
|
+
const out = [];
|
|
44
|
+
const seen = new Set([r.id]);
|
|
45
|
+
let cur = r.within;
|
|
46
|
+
while (cur && !seen.has(cur)) {
|
|
47
|
+
out.push(cur);
|
|
48
|
+
seen.add(cur);
|
|
49
|
+
cur = records.get(cur)?.within;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** Read an owner's whole state. Order is the order the log made things, by `ord`. */
|
|
54
|
+
export async function loadState(client, owner) {
|
|
55
|
+
const state = emptyState();
|
|
56
|
+
const q = async (sql) => (await client.query(sql, [owner])).rows;
|
|
57
|
+
for (const row of await q("select * from records where owner = $1 order by ord"))
|
|
58
|
+
state.records.set(String(row.id), recordOf(row));
|
|
59
|
+
for (const row of await q("select edge, json from edges where owner = $1 order by ord"))
|
|
60
|
+
state.edges.set(String(row.edge), row.json);
|
|
61
|
+
for (const row of await q("select key, record from bindings where owner = $1 order by ord"))
|
|
62
|
+
state.bindings.set(String(row.key), String(row.record));
|
|
63
|
+
for (const row of await q("select issuer, json from instructions where owner = $1 order by issuer, n")) {
|
|
64
|
+
const issuer = String(row.issuer);
|
|
65
|
+
state.instructions.set(issuer, [...(state.instructions.get(issuer) ?? []), row.json]);
|
|
66
|
+
}
|
|
67
|
+
for (const row of await q("select json from observations where owner = $1 order by ord"))
|
|
68
|
+
state.observations.push(row.json);
|
|
69
|
+
for (const row of await q("select json from review where owner = $1 order by ord"))
|
|
70
|
+
state.reviews.push(row.json);
|
|
71
|
+
for (const row of await q("select run, json from runs where owner = $1 order by ord"))
|
|
72
|
+
state.runs.set(String(row.run), row.json);
|
|
73
|
+
for (const row of await q("select json from installed where owner = $1 order by ord"))
|
|
74
|
+
state.installed.push(row.json);
|
|
75
|
+
for (const row of await q("select json from reads where owner = $1 order by ord"))
|
|
76
|
+
state.reads.push(row.json);
|
|
77
|
+
for (const row of await q("select key, json from definitions where owner = $1 order by ord"))
|
|
78
|
+
state.definitions.set(String(row.key), row.json);
|
|
79
|
+
return state;
|
|
80
|
+
}
|
|
81
|
+
/** How many records one upsert statement carries. */
|
|
82
|
+
const PERSIST_BATCH = 500;
|
|
83
|
+
/** Write what changed between two states of one owner: upserts, deletes, and appends to the lists. */
|
|
84
|
+
export async function persist(client, owner, before, after) {
|
|
85
|
+
const changed = (a, b) => serialize((a ?? null)) !== serialize((b ?? null));
|
|
86
|
+
const beforeRecords = new Map(Map.prototype.entries.call(before.records));
|
|
87
|
+
// The changed records go in batches, one statement each (0.3.59): a statement per record made a commit of 500
|
|
88
|
+
// records 500 round trips inside its transaction, and from a client far from the database that held the
|
|
89
|
+
// transaction (and the locks it took) for minutes (the commons seed, 2026-11-04). Log order is kept: the rows
|
|
90
|
+
// go in the order the state holds them, `ord` taken in that order.
|
|
91
|
+
const rows = [];
|
|
92
|
+
for (const [id, r] of Map.prototype.entries.call(after.records)) {
|
|
93
|
+
const was = beforeRecords.get(id);
|
|
94
|
+
const ancestors = ancestorsOf(after.records, r);
|
|
95
|
+
const wasAncestors = was ? ancestorsOf(beforeRecords, was) : undefined;
|
|
96
|
+
if (was && !changed(was, r) && !changed(wasAncestors, ancestors))
|
|
97
|
+
continue;
|
|
98
|
+
rows.push({
|
|
99
|
+
id,
|
|
100
|
+
kind: r.kind,
|
|
101
|
+
level: r.level,
|
|
102
|
+
of: r.of ?? null,
|
|
103
|
+
within: r.within ?? null,
|
|
104
|
+
ancestors,
|
|
105
|
+
...(r.status !== undefined && r.status !== null ? { status: r.status } : {}),
|
|
106
|
+
...(r.applied !== undefined && r.applied !== null ? { applied: r.applied } : {}),
|
|
107
|
+
wears: r.wears ?? [],
|
|
108
|
+
created: r.created ?? null,
|
|
109
|
+
updated: r.updated ?? null,
|
|
110
|
+
doc: docOf(r),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
for (let i = 0; i < rows.length; i += PERSIST_BATCH) {
|
|
114
|
+
await client.query(`insert into records (owner, id, kind, level, "of", within, ancestors, status, applied, wears, created, updated, doc)
|
|
115
|
+
select $1, e.j ->> 'id', e.j ->> 'kind', e.j ->> 'level', e.j ->> 'of', e.j ->> 'within',
|
|
116
|
+
array(select jsonb_array_elements_text(e.j -> 'ancestors')), e.j -> 'status', e.j -> 'applied',
|
|
117
|
+
array(select jsonb_array_elements_text(e.j -> 'wears')), e.j ->> 'created', e.j ->> 'updated', e.j -> 'doc'
|
|
118
|
+
from jsonb_array_elements($2::jsonb) with ordinality as e(j, n)
|
|
119
|
+
order by e.n
|
|
120
|
+
on conflict (owner, id) do update set kind = excluded.kind, level = excluded.level, "of" = excluded."of", within = excluded.within,
|
|
121
|
+
ancestors = excluded.ancestors, status = excluded.status, applied = excluded.applied, wears = excluded.wears,
|
|
122
|
+
created = excluded.created, updated = excluded.updated, doc = excluded.doc`, [owner, JSON.stringify(rows.slice(i, i + PERSIST_BATCH))]);
|
|
123
|
+
}
|
|
124
|
+
// Plain copies: a working map notes every walk and miss, and persisting is neither.
|
|
125
|
+
const plain = (m) => new Map(Map.prototype.entries.call(m));
|
|
126
|
+
const upsertMap = async (table, keyCol, valCol, wasMap, nowMap, asJson = true) => {
|
|
127
|
+
const was = plain(wasMap);
|
|
128
|
+
const now = plain(nowMap);
|
|
129
|
+
for (const [k, v] of now) {
|
|
130
|
+
if (was.has(k) && !changed(was.get(k), v))
|
|
131
|
+
continue;
|
|
132
|
+
await client.query(`insert into ${table} (owner, ${keyCol}, ${valCol}) values ($1, $2, $3) on conflict (owner, ${keyCol}) do update set ${valCol} = excluded.${valCol}`, [owner, k, asJson ? v : String(v)]);
|
|
133
|
+
}
|
|
134
|
+
for (const k of was.keys())
|
|
135
|
+
if (!now.has(k))
|
|
136
|
+
await client.query(`delete from ${table} where owner = $1 and ${keyCol} = $2`, [owner, k]);
|
|
137
|
+
};
|
|
138
|
+
await upsertMap("edges", "edge", "json", before.edges, after.edges);
|
|
139
|
+
await upsertMap("bindings", "key", "record", before.bindings, after.bindings, false);
|
|
140
|
+
await upsertMap("runs", "run", "json", before.runs, after.runs);
|
|
141
|
+
await upsertMap("definitions", "key", "json", before.definitions, after.definitions);
|
|
142
|
+
for (const [issuer, list] of after.instructions) {
|
|
143
|
+
const have = before.instructions.get(issuer)?.length ?? 0;
|
|
144
|
+
for (let i = have; i < list.length; i++) {
|
|
145
|
+
const ins = list[i];
|
|
146
|
+
await client.query("insert into instructions (owner, issuer, n, json) values ($1, $2, $3, $4) on conflict do nothing", [owner, issuer, Number(ins.n ?? i + 1), ins]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const appendList = async (table, was, now) => {
|
|
150
|
+
for (const item of now.slice(was.length))
|
|
151
|
+
await client.query(`insert into ${table} (owner, json) values ($1, $2)`, [owner, item]);
|
|
152
|
+
};
|
|
153
|
+
await appendList("observations", before.observations, after.observations);
|
|
154
|
+
await appendList("review", before.reviews, after.reviews);
|
|
155
|
+
await appendList("installed", before.installed, after.installed);
|
|
156
|
+
await appendList("reads", before.reads, after.reads);
|
|
157
|
+
}
|
|
158
|
+
/** Forget an owner's state tables (not its log), before a rebuild. */
|
|
159
|
+
export async function wipeState(client, owner) {
|
|
160
|
+
for (const t of ["records", "edges", "bindings", "instructions", "review", "runs", "observations", "installed", "reads", "definitions"]) {
|
|
161
|
+
await client.query(`delete from ${t} where owner = $1`, [owner]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export { isObj };
|
|
165
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AACA,yGAAyG;AACzG,yGAAyG;AACzG,kFAAkF;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAC;AAIxD,MAAM,KAAK,GAAG,CAAC,CAAU,EAAmB,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAIxG,iFAAiF;AACjF,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAC/B,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAe,CAAC;IAC1C,yGAAyG;IACzG,MAAM,CAAC,GAAW,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAe,EAAE,CAAC;IAC5K,IAAI,GAAG,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClC,IAAI,GAAG,CAAC,MAAM;QAAE,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC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