@crubal/postgres 0.0.0-stage → 0.4.1
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,243 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { deserialize, serialize as v8serialize } from "node:v8";
|
|
4
|
+
// definitions.ts: what the engine runs with, built from the store (docs/design/publishing.md): the installed
|
|
5
|
+
// bundles in install order (extended before extending, because a dependency is installed first), then the
|
|
6
|
+
// owner's working package, every `define` write as the member now stands. The publish checks run on the
|
|
7
|
+
// result, so a definition that breaks the set is refused before it is written.
|
|
8
|
+
import { checkActsInForce, checkFlowsInForce, checkPermissions } from "@crubal/engine";
|
|
9
|
+
import { emptyParsed, readBundleOnto } from "@crubal/engine";
|
|
10
|
+
import { checkPackage } from "@crubal/engine";
|
|
11
|
+
import { checkContracts } from "@crubal/engine";
|
|
12
|
+
import { unitsExtensionText } from "@crubal/engine";
|
|
13
|
+
import { extendUnits, resetUnits, unitsTableWith } from "@crubal/engine";
|
|
14
|
+
import { checkRules } from "@crubal/engine";
|
|
15
|
+
import { checkViews } from "@crubal/engine";
|
|
16
|
+
/** The owner's working package as one bundle: the define writes grouped by member kind, in log order. */
|
|
17
|
+
/** The owner's units extension (11.9), from the last `units` define write. */
|
|
18
|
+
export function unitsExtensionOf(definitions) {
|
|
19
|
+
let measures = [];
|
|
20
|
+
for (const d of definitions)
|
|
21
|
+
if (d.units === "extension" && Array.isArray(d.measures))
|
|
22
|
+
measures = d.measures;
|
|
23
|
+
return measures;
|
|
24
|
+
}
|
|
25
|
+
export function workingBundle(owner, definitions) {
|
|
26
|
+
// The member kinds that carry another kind's word come first (a filter names its facet, a view its shape,
|
|
27
|
+
// a contract its kind), so each define is filed under what it is (G11).
|
|
28
|
+
const sections = { filter: "filters", view: "views", contract: "contracts", facet: "facets", class: "classes", rule: "rules", kind: "kinds", shape: "shapes", display: "displays", print: "prints" };
|
|
29
|
+
const b = { crubal: "2", package: "working", version: "working", owner, id: `${owner}/working` };
|
|
30
|
+
// In log order, by member key: a later define of the same member replaces the earlier, a retired one
|
|
31
|
+
// (8.5, 11.4) takes it out, so the working package holds each member once as it now stands.
|
|
32
|
+
const members = new Map();
|
|
33
|
+
for (const d of definitions) {
|
|
34
|
+
const member = Object.keys(sections).find((m) => typeof d[m] === "string");
|
|
35
|
+
if (member) {
|
|
36
|
+
const key = `${member}:${String(d[member])}`;
|
|
37
|
+
if (d.retired === true)
|
|
38
|
+
members.delete(key);
|
|
39
|
+
else
|
|
40
|
+
members.set(key, { section: sections[member], def: d });
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (typeof d.permissions === "string") {
|
|
44
|
+
if (d.retired === true)
|
|
45
|
+
delete b.permissions;
|
|
46
|
+
else
|
|
47
|
+
b.permissions = d;
|
|
48
|
+
}
|
|
49
|
+
if (d.ownership !== undefined)
|
|
50
|
+
b.ownership = d.ownership;
|
|
51
|
+
}
|
|
52
|
+
for (const { section, def } of members.values()) {
|
|
53
|
+
const list = b[section] ?? [];
|
|
54
|
+
list.push(def);
|
|
55
|
+
b[section] = list;
|
|
56
|
+
}
|
|
57
|
+
return b;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parsed definitions shared across stores that hold the same packages and the same working package
|
|
61
|
+
* (brief 18 step 1: a host of a thousand deployments on one package set parses it once, not a thousand
|
|
62
|
+
* times, and keeps one copy). Keyed by the installed versions and a hash of the define writes; a trial
|
|
63
|
+
* (`extra`) is never cached. The object is read-only to its callers, as a store's own cache already was.
|
|
64
|
+
*/
|
|
65
|
+
const parsedShared = new Map();
|
|
66
|
+
const PARSED_SHARED_MAX = 64;
|
|
67
|
+
/**
|
|
68
|
+
* The definitions as built, kept in the store (the speed round, 2026-11-03: every new serverless instance
|
|
69
|
+
* rebuilt a place's definitions by replaying every version ever installed, 245 bundles at Media
|
|
70
|
+
* Encyclopedia, each printed and parsed again). Keyed by what they were built from (the installed versions,
|
|
71
|
+
* the define writes' hash) and by what wrote them (this engine's version, V8's serialization), so a stale
|
|
72
|
+
* or foreign copy is never read: a miss builds as before and keeps the result. Never a trial's.
|
|
73
|
+
*/
|
|
74
|
+
const builtFormat = (() => {
|
|
75
|
+
let dir = new URL(".", import.meta.url);
|
|
76
|
+
for (let i = 0; i < 4; i++) {
|
|
77
|
+
const at = new URL("package.json", dir);
|
|
78
|
+
if (existsSync(at)) {
|
|
79
|
+
const p = JSON.parse(readFileSync(at, "utf8"));
|
|
80
|
+
if (p.name === "@crubal/postgres")
|
|
81
|
+
return `engine ${p.version}|v8 ${process.versions.v8}`;
|
|
82
|
+
}
|
|
83
|
+
dir = new URL("..", dir);
|
|
84
|
+
}
|
|
85
|
+
return `engine ?|v8 ${process.versions.v8}`;
|
|
86
|
+
})();
|
|
87
|
+
let builtTable;
|
|
88
|
+
const builtReady = (client) => {
|
|
89
|
+
builtTable ??= client
|
|
90
|
+
.query("create table if not exists definitions_built (owner text primary key, key text not null, blob bytea not null, at timestamptz not null default now())")
|
|
91
|
+
.then(() => undefined)
|
|
92
|
+
.catch((e) => {
|
|
93
|
+
builtTable = undefined;
|
|
94
|
+
throw e;
|
|
95
|
+
});
|
|
96
|
+
return builtTable;
|
|
97
|
+
};
|
|
98
|
+
/** Run a statement that may fail without harm: inside a transaction behind a savepoint, so a failure never
|
|
99
|
+
* aborts the caller's work; outside one, as it is. */
|
|
100
|
+
async function harmless(client, run) {
|
|
101
|
+
let inside = false;
|
|
102
|
+
try {
|
|
103
|
+
await client.query("savepoint definitions_built");
|
|
104
|
+
inside = true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Not in a transaction: nothing to guard.
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const out = await run();
|
|
111
|
+
if (inside)
|
|
112
|
+
await client.query("release savepoint definitions_built");
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
if (inside)
|
|
117
|
+
await client.query("rollback to savepoint definitions_built").catch(() => undefined);
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function readBuilt(client, owner, key) {
|
|
122
|
+
return harmless(client, async () => {
|
|
123
|
+
await builtReady(client);
|
|
124
|
+
const { rows } = await client.query("select blob from definitions_built where owner = $1 and key = $2", [owner, key]);
|
|
125
|
+
const blob = rows[0]?.blob;
|
|
126
|
+
return blob ? deserialize(blob) : undefined;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function writeBuilt(client, owner, key, parsed) {
|
|
130
|
+
// Kept next time when it fails; a store that can't keep it builds as before.
|
|
131
|
+
await harmless(client, async () => {
|
|
132
|
+
await builtReady(client);
|
|
133
|
+
await client.query("insert into definitions_built (owner, key, blob) values ($1, $2, $3) on conflict (owner) do update set key = excluded.key, blob = excluded.blob, at = now()", [owner, key, v8serialize(parsed)]);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** Each package's latest install alone, in the order of those last installs. Pure. */
|
|
137
|
+
export function latestInstalls(installed) {
|
|
138
|
+
const last = new Map();
|
|
139
|
+
installed.forEach((r, i) => last.set(String(r.json.package), i));
|
|
140
|
+
// A package whose last write is a leaving (11.4, revision 30) is not in force.
|
|
141
|
+
return installed.filter((r, i) => last.get(String(r.json.package)) === i && r.json.left !== true);
|
|
142
|
+
}
|
|
143
|
+
/** The install log without the packages that left (11.4, revision 30): every write of a package whose last write
|
|
144
|
+
* is a leaving is dropped, so a reader of what is in force sees it gone; the raw log is `installLog()`. Pure. */
|
|
145
|
+
export function installsInForce(installed) {
|
|
146
|
+
const last = new Map();
|
|
147
|
+
for (const i of installed)
|
|
148
|
+
last.set(String(i.package), i);
|
|
149
|
+
return installed.filter((i) => last.get(String(i.package))?.left !== true && i.left !== true);
|
|
150
|
+
}
|
|
151
|
+
/** Forget this process's parsed copies (a test standing in for a new instance). */
|
|
152
|
+
export function forgetParsedShared() {
|
|
153
|
+
parsedShared.clear();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Build the definitions in force: installed bundles in order, then the working package. `own` asks for a
|
|
157
|
+
* copy of the caller's own, never the shared one: a dry run or an install reads the next bundle onto what it
|
|
158
|
+
* is given, and read onto the shared object that became every store's definitions until the key changed
|
|
159
|
+
* (a dry run run three times reported its recipe three times, 2026-10-22).
|
|
160
|
+
*/
|
|
161
|
+
export async function definitionsOf(client, owner, extra = [], own = false) {
|
|
162
|
+
const installed = (await client.query("select json from installed where owner = $1 order by ord", [owner])).rows;
|
|
163
|
+
const defs = (await client.query("select json from definitions where owner = $1 order by ord", [owner])).rows;
|
|
164
|
+
const key = extra.length || own ? undefined : `${installed.map((r) => `${r.json.package}/${r.json.version}`).join(",")}|${createHash("sha256").update(JSON.stringify(defs.map((r) => r.json))).digest("hex")}`;
|
|
165
|
+
const shared = key ? parsedShared.get(key) : undefined;
|
|
166
|
+
if (shared) {
|
|
167
|
+
parsedShared.delete(key);
|
|
168
|
+
parsedShared.set(key, shared);
|
|
169
|
+
// The process units table follows the owner read last, for the facet-only readers (see below).
|
|
170
|
+
const measures = shared.units ?? [];
|
|
171
|
+
resetUnits();
|
|
172
|
+
if (measures.length)
|
|
173
|
+
extendUnits(unitsExtensionText(measures));
|
|
174
|
+
return shared;
|
|
175
|
+
}
|
|
176
|
+
// A new instance reads what another built (the speed round): the same installs, the same defines, the
|
|
177
|
+
// same engine.
|
|
178
|
+
const stored = key ? await readBuilt(client, owner, `${builtFormat}|${key}`) : undefined;
|
|
179
|
+
if (stored && key) {
|
|
180
|
+
parsedShared.set(key, stored);
|
|
181
|
+
while (parsedShared.size > PARSED_SHARED_MAX)
|
|
182
|
+
parsedShared.delete(parsedShared.keys().next().value);
|
|
183
|
+
const measures = stored.units ?? [];
|
|
184
|
+
resetUnits();
|
|
185
|
+
if (measures.length)
|
|
186
|
+
extendUnits(unitsExtensionText(measures));
|
|
187
|
+
return stored;
|
|
188
|
+
}
|
|
189
|
+
const base = emptyParsed();
|
|
190
|
+
// The versions in force (the operator's ruling, 2026-11-03: "I don't see any reason it needs all the old
|
|
191
|
+
// versions"): each package's latest install alone, standing where it was last installed, so a later install
|
|
192
|
+
// still wins an overlap as before; the versions it replaced are history, never definitions.
|
|
193
|
+
const current = latestInstalls(installed);
|
|
194
|
+
// Every bundle the installs name, in one read (the speed round, 2026-11-03: a cold build read them one
|
|
195
|
+
// query at a time, 245 at Media Encyclopedia, holding a connection the whole while); applied in the
|
|
196
|
+
// installs' order as before.
|
|
197
|
+
const pairs = [...new Set(current.map((r) => `${String(r.json.package)}\u0000${String(r.json.version)}`))];
|
|
198
|
+
const bundles = new Map();
|
|
199
|
+
if (pairs.length) {
|
|
200
|
+
const { rows } = await client.query("select package, version, json from bundles where owner = $1 and (package, version) in (select * from unnest($2::text[], $3::text[]))", [owner, pairs.map((x) => x.split("\u0000")[0]), pairs.map((x) => x.split("\u0000")[1])]);
|
|
201
|
+
for (const r of rows)
|
|
202
|
+
bundles.set(`${r.package}\u0000${r.version}`, r.json);
|
|
203
|
+
}
|
|
204
|
+
for (const row of current) {
|
|
205
|
+
const w = row.json;
|
|
206
|
+
const bundle = bundles.get(`${String(w.package)}\u0000${String(w.version)}`);
|
|
207
|
+
if (!bundle)
|
|
208
|
+
throw new Error(`${w.package} /${w.version} is installed but its bundle is missing`);
|
|
209
|
+
readBundleOnto(bundle, base);
|
|
210
|
+
}
|
|
211
|
+
// `extra`: define writes not yet committed, so a trial (store.define) is checked as the package would stand.
|
|
212
|
+
const working = [...defs.map((r) => r.json), ...extra];
|
|
213
|
+
if (working.length)
|
|
214
|
+
readBundleOnto(workingBundle(owner, working), base);
|
|
215
|
+
// The units table in force: the standard table plus this owner's extension (one owner per process for now).
|
|
216
|
+
const measures = unitsExtensionOf(working);
|
|
217
|
+
// The units table in force rides on the dictionary (11.9, per owner): the readers that hold a dictionary
|
|
218
|
+
// read it there. The process table is set too, for the few readers that hold a facet alone
|
|
219
|
+
// (checkScalar's unit question); that remaining path still sees the last owner read in this process.
|
|
220
|
+
base.dict.units = unitsTableWith(measures.length ? unitsExtensionText(measures) : undefined);
|
|
221
|
+
resetUnits();
|
|
222
|
+
if (measures.length)
|
|
223
|
+
extendUnits(unitsExtensionText(measures));
|
|
224
|
+
base.units = measures;
|
|
225
|
+
if (key) {
|
|
226
|
+
parsedShared.set(key, base);
|
|
227
|
+
while (parsedShared.size > PARSED_SHARED_MAX)
|
|
228
|
+
parsedShared.delete(parsedShared.keys().next().value);
|
|
229
|
+
await writeBuilt(client, owner, `${builtFormat}|${key}`, base);
|
|
230
|
+
}
|
|
231
|
+
return base;
|
|
232
|
+
}
|
|
233
|
+
/** Every publish check (11.5) over a set of definitions. Throws the first problem. */
|
|
234
|
+
export function checkAll(p) {
|
|
235
|
+
checkPackage(p.dict);
|
|
236
|
+
checkRules(p.rules, p.dict);
|
|
237
|
+
checkContracts(p.contracts, p.dict, "", new Set(p.views.views.keys()));
|
|
238
|
+
checkViews(p.views, p.dict);
|
|
239
|
+
checkPermissions(p.perms, p.dict, new Set(p.contracts.map((c) => c.name)), new Set(p.views.views.keys()));
|
|
240
|
+
checkFlowsInForce(p);
|
|
241
|
+
checkActsInForce(p);
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,6GAA6G;AAC7G,0GAA0G;AAC1G,wGAAwG;AACxG,+EAA+E;AAE/E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAe,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK5C,yGAAyG;AACzG,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,WAAiC;IAChE,IAAI,QAAQ,GAAiB,EAAE,CAAC;IAChC,KAAK,MAAM,CAAC,IA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db.ts";
|
|
2
|
+
export { loadState, persist, wipeState } from "./state.ts";
|
|
3
|
+
export { PgStore, QuorumRefused } from "./store.ts";
|
|
4
|
+
export { entriesSince, markStale, publish, type Projecting } from "./projector.ts";
|
|
5
|
+
export { Needs, settle, WorkingMap, WorkingRecords, workingState } from "./working.ts";
|
|
6
|
+
export { type Adapter, PgBorder, type BorderOptions } from "./border.ts";
|
|
7
|
+
export type { StoreOptions } from "./store.ts";
|
|
8
|
+
export { borderOptions } from "./border.ts";
|
|
9
|
+
export { checkAll, definitionsOf, installsInForce, latestInstalls, unitsExtensionOf, workingBundle } from "./definitions.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { connect, migrate, testSchema, transaction } from "./db.js";
|
|
2
|
+
export { loadState, persist, wipeState } from "./state.js";
|
|
3
|
+
export { PgStore, QuorumRefused } from "./store.js";
|
|
4
|
+
export { entriesSince, markStale, publish } from "./projector.js";
|
|
5
|
+
export { Needs, settle, WorkingMap, WorkingRecords, workingState } from "./working.js";
|
|
6
|
+
export { PgBorder } from "./border.js";
|
|
7
|
+
export { borderOptions } from "./border.js";
|
|
8
|
+
export { checkAll, definitionsOf, installsInForce, latestInstalls, unitsExtensionOf, workingBundle } from "./definitions.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAA0B,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAmB,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAgB,QAAQ,EAAsB,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Permissions } from "@crubal/engine";
|
|
2
|
+
import type { Dictionary } from "@crubal/engine";
|
|
3
|
+
import type { State } from "@crubal/engine";
|
|
4
|
+
import { type StreamEntry, type ViewSet } from "@crubal/engine";
|
|
5
|
+
import type { Client } from "./db.ts";
|
|
6
|
+
/** What a store needs to project: the dictionary, the views, and the permissions for partitioned ones. */
|
|
7
|
+
export type Projecting = {
|
|
8
|
+
dict: Dictionary;
|
|
9
|
+
views: ViewSet;
|
|
10
|
+
perms?: Permissions;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Mark the rows an entry made stale (12.6): for every record it changed, in every view, the rows whose
|
|
14
|
+
* read set the change touched, worked out on the state as it was before the entry.
|
|
15
|
+
*/
|
|
16
|
+
export declare function markStale(client: Client, owner: string, p: Projecting, before: State, after: State, seq: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Publish one view for one audience: rebuild its stale rows (every row the first time, or after a new
|
|
19
|
+
* version), compare them with the projection as stored, append the stream entries, and clear the marks.
|
|
20
|
+
* Returns the entries published.
|
|
21
|
+
*/
|
|
22
|
+
export declare function publish(client: Client, owner: string, p: Projecting, name: string, audience?: string): Promise<StreamEntry[]>;
|
|
23
|
+
/** The stream entries of a view for an audience after `seq`, for an index resuming from its cursor. */
|
|
24
|
+
export declare function entriesSince(client: Client, owner: string, p: Projecting, name: string, seq: number, audience?: string, limit?: number): Promise<StreamEntry[]>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// projector.ts: projections and the projection stream (spec 12.6, docs/design/store.md). A write marks the
|
|
2
|
+
// rows it makes stale inside its own transaction, a row per (view, record); publishing drains those marks
|
|
3
|
+
// outside any write transaction, rebuilds only the marked rows with the engine's Views, upserts the
|
|
4
|
+
// projection and appends one stream entry per row that changed or left, numbered per view and audience.
|
|
5
|
+
import { Access } from "@crubal/engine";
|
|
6
|
+
import { serialize } from "@crubal/engine";
|
|
7
|
+
import { Views } from "@crubal/engine";
|
|
8
|
+
import { Needs, settle, workingState, loadWhole } from "./working.js";
|
|
9
|
+
/**
|
|
10
|
+
* Mark the rows an entry made stale (12.6): for every record it changed, in every view, the rows whose
|
|
11
|
+
* read set the change touched, worked out on the state as it was before the entry.
|
|
12
|
+
*/
|
|
13
|
+
export async function markStale(client, owner, p, before, after, seq) {
|
|
14
|
+
const changed = [];
|
|
15
|
+
const beforeRecords = new Map(Map.prototype.entries.call(before.records));
|
|
16
|
+
for (const [id, r] of Map.prototype.entries.call(after.records)) {
|
|
17
|
+
if (serialize((beforeRecords.get(id) ?? null)) !== serialize(r))
|
|
18
|
+
changed.push(r);
|
|
19
|
+
}
|
|
20
|
+
if (!changed.length)
|
|
21
|
+
return;
|
|
22
|
+
const { out } = await settle(client, owner, before, (s) => {
|
|
23
|
+
const views = new Views(p.dict, p.views, s.records);
|
|
24
|
+
const marks = [];
|
|
25
|
+
for (const name of p.views.views.keys())
|
|
26
|
+
for (const r of changed)
|
|
27
|
+
for (const id of views.staleAfter(name, r))
|
|
28
|
+
marks.push([name, id]);
|
|
29
|
+
return marks;
|
|
30
|
+
});
|
|
31
|
+
// In batches, one statement each (0.3.59): a statement per mark made a commit of 500 records over fifteen
|
|
32
|
+
// views thousands of round trips inside its transaction (the commons seed, 2026-11-04). A mark twice in one
|
|
33
|
+
// batch is one row: an upsert can't touch a row twice in one statement.
|
|
34
|
+
const unique = [...new Map(out.map(([view, record]) => [`${view}\u0000${record}`, [view, record]])).values()];
|
|
35
|
+
for (let i = 0; i < unique.length; i += 2000) {
|
|
36
|
+
const part = unique.slice(i, i + 2000);
|
|
37
|
+
await client.query("insert into stale (owner, view, record, since) select $1, v, r, $4 from unnest($2::text[], $3::text[]) as t(v, r) on conflict (owner, view, record) do update set since = least(stale.since, excluded.since)", [owner, part.map((m) => m[0]), part.map((m) => m[1]), seq]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Publish one view for one audience: rebuild its stale rows (every row the first time, or after a new
|
|
42
|
+
* version), compare them with the projection as stored, append the stream entries, and clear the marks.
|
|
43
|
+
* Returns the entries published.
|
|
44
|
+
*/
|
|
45
|
+
export async function publish(client, owner, p, name, audience) {
|
|
46
|
+
const v = p.views.views.get(name);
|
|
47
|
+
if (!v)
|
|
48
|
+
throw new Error(`no view ${name}`);
|
|
49
|
+
const aud = audience ?? v.show;
|
|
50
|
+
const version = v.version ?? "";
|
|
51
|
+
const projection = version ? `${name} /${version}` : name;
|
|
52
|
+
// One publish of a view at a time, held to the transaction's end: two at once each read the stream's head
|
|
53
|
+
// and numbered their entries from it, and the second to write was refused by the stream's key (a host's
|
|
54
|
+
// project loop beside a page that publishes the view it is about to draw). The one that waited reads the
|
|
55
|
+
// marks after the first has cleared them, and publishes what is left, usually nothing.
|
|
56
|
+
await client.query("select pg_advisory_xact_lock(hashtextextended($1, 0))", [JSON.stringify(["publish", owner, name, aud])]);
|
|
57
|
+
// What is marked and whether the view was ever published come first: a view with nothing stale costs
|
|
58
|
+
// two small queries, never a read of every stored row (ME: fifteen views, thousands of rows each, on
|
|
59
|
+
// every write). Stored rows are read in full only for a first or a reset publish; otherwise the marked ones.
|
|
60
|
+
// Published before, and under which versions: the marker row, or (stores published before 0.1.16 kept
|
|
61
|
+
// no marker) any stored row; an empty view published once is not published again whole.
|
|
62
|
+
const marker = (await client.query("select version from published where owner = $1 and view = $2 and audience = $3", [owner, name, aud])).rows;
|
|
63
|
+
const anyVersion = marker.length ? marker : (await client.query("select distinct version from projections where owner = $1 and view = $2 and audience = $3", [owner, name, aud])).rows;
|
|
64
|
+
const published = anyVersion.length > 0;
|
|
65
|
+
const reset = published && !anyVersion.some((r) => r.version === version);
|
|
66
|
+
const marked = (await client.query("select record from stale where owner = $1 and view = $2 order by record", [owner, name])).rows;
|
|
67
|
+
const full = !published || reset;
|
|
68
|
+
const allMarked = full ? undefined : marked.map((r) => String(r.record));
|
|
69
|
+
if (!full && !allMarked?.length)
|
|
70
|
+
return [];
|
|
71
|
+
// The marked rows are rebuilt in batches under a budget (brief 29, rule 2): a view with 347,000 rows marked
|
|
72
|
+
// by an install was rebuilt in one working set and ran the function out of memory on every tick
|
|
73
|
+
// (Media Encyclopedia, 2026-10-23). Each batch's marks go when its rows are written, so a run that stops at
|
|
74
|
+
// the budget leaves the rest marked for the next; a full publish (first or reset) still goes in one.
|
|
75
|
+
const BATCH = Math.max(1, Number(process.env.CRUBAL_PUBLISH_BATCH ?? "2000"));
|
|
76
|
+
const BUDGET_MS = Number(process.env.CRUBAL_PUBLISH_BUDGET_MS ?? "45000");
|
|
77
|
+
const started = Date.now();
|
|
78
|
+
const all = [];
|
|
79
|
+
const batches = allMarked ? Array.from({ length: Math.ceil(allMarked.length / BATCH) }, (_, i) => allMarked.slice(i * BATCH, (i + 1) * BATCH)) : [undefined];
|
|
80
|
+
for (const [i, only] of batches.entries()) {
|
|
81
|
+
if (i > 0 && Date.now() - started > BUDGET_MS)
|
|
82
|
+
break;
|
|
83
|
+
// Appended one by one: a spread of a whole view's entries (347,000 on a first or reset publish at Media
|
|
84
|
+
// Encyclopedia, 2026-10-27) exceeds the call stack.
|
|
85
|
+
for (const e of await publishSet(client, owner, p, name, aud, version, projection, v, reset && i === 0, full, only))
|
|
86
|
+
all.push(e);
|
|
87
|
+
}
|
|
88
|
+
return all;
|
|
89
|
+
}
|
|
90
|
+
/** One set of a view's rows published: every row when `only` is undefined, else those records. */
|
|
91
|
+
async function publishSet(client, owner, p, name, aud, version, projection, v, reset, full, only) {
|
|
92
|
+
const stored = (full
|
|
93
|
+
? await client.query("select record, row, buckets, sort, pin, seq from projections where owner = $1 and view = $2 and audience = $3 and version = $4 order by seq", [owner, name, aud, version])
|
|
94
|
+
: await client.query("select record, row, buckets, sort, pin, seq from projections where owner = $1 and view = $2 and audience = $3 and version = $4 and record = any($5) order by seq", [owner, name, aud, version, only])).rows;
|
|
95
|
+
// On a reset every row is announced again, whatever was stored: the index drops everything when the
|
|
96
|
+
// reset arrives and keeps only what follows it.
|
|
97
|
+
const last = new Map(reset ? [] : stored.map((r) => [String(r.record), serialize({ row: r.row, buckets: (r.buckets ?? {}), order: { sort: (r.sort ?? []), ...(r.pin ? { pin: Number(r.pin) } : {}) } })]));
|
|
98
|
+
// The rows, on a working set that loads what the view reads.
|
|
99
|
+
const needs = new Needs();
|
|
100
|
+
const base = workingState(needs);
|
|
101
|
+
await loadWhole(client, owner, base);
|
|
102
|
+
const { out: now } = await settle(client, owner, base, (s) => {
|
|
103
|
+
const views = new Views(p.dict, p.views, s.records);
|
|
104
|
+
const access = p.perms ? new Access(p.dict, p.perms, s.records, [...s.edges.values()], owner) : undefined;
|
|
105
|
+
if (access && p.views)
|
|
106
|
+
access.views = p.views;
|
|
107
|
+
const rows = new Map();
|
|
108
|
+
// Every row in one pass: a page at a time selected and counted the whole view once per page.
|
|
109
|
+
for (const row of views.project(name, { audience: aud, all: true, ...(access ? { access } : {}), ...(only ? { only } : {}) }).rows) {
|
|
110
|
+
const rec = s.records.get(String(row.record));
|
|
111
|
+
rows.set(String(row.record), { row, buckets: rec ? views.bucketsFor(v, rec) : {}, ...(rec ? views.sortOf(v, rec) : { sort: [] }) });
|
|
112
|
+
}
|
|
113
|
+
return rows;
|
|
114
|
+
});
|
|
115
|
+
const head = (await client.query("select coalesce(max(seq), 0) as seq from projection_stream where owner = $1 and view = $2 and audience = $3 and version = $4", [owner, name, aud, version])).rows[0];
|
|
116
|
+
// The stream continues from its head under this version: a fresh version starts at 1, and a version
|
|
117
|
+
// come back to (a package reinstalled, a later one retired) continues past what it published before,
|
|
118
|
+
// so an index resuming from its cursor for that version takes the reset and what follows.
|
|
119
|
+
let seq = Number(head.seq);
|
|
120
|
+
const entries = [];
|
|
121
|
+
const upserts = [];
|
|
122
|
+
if (reset)
|
|
123
|
+
await client.query("delete from projections where owner = $1 and view = $2 and audience = $3 and version <> $4", [owner, name, aud, version]);
|
|
124
|
+
for (const [id, { row, buckets, sort, pin }] of now) {
|
|
125
|
+
const s = serialize({ row, buckets, order: { sort, ...(pin ? { pin } : {}) } });
|
|
126
|
+
if (last.get(id) === s)
|
|
127
|
+
continue;
|
|
128
|
+
const e = { projection, audience: aud, seq: ++seq, record: id, row, ...(Object.keys(buckets).length ? { buckets } : {}), ...(sort.length ? { sort } : {}), ...(pin ? { pin } : {}) };
|
|
129
|
+
if (reset && !entries.length)
|
|
130
|
+
e.reset = true;
|
|
131
|
+
entries.push(e);
|
|
132
|
+
upserts.push({ id, row, buckets, sort, ...(pin ? { pin } : {}), seq });
|
|
133
|
+
}
|
|
134
|
+
// Rows that left: every stored row the rebuild didn't give back, among the records rebuilt.
|
|
135
|
+
const gone = full ? [...last.keys()].filter((id) => !now.has(id)) : (only ?? []).filter((id) => last.has(id) && !now.has(id));
|
|
136
|
+
for (const id of gone) {
|
|
137
|
+
const e = { projection, audience: aud, seq: ++seq, record: id, removed: true };
|
|
138
|
+
if (reset && !entries.length)
|
|
139
|
+
e.reset = true;
|
|
140
|
+
entries.push(e);
|
|
141
|
+
}
|
|
142
|
+
// The stream and the rows written in batches, one statement per 500 entries rather than two per row
|
|
143
|
+
// (ME: 9,437 units in one view; the round trips were a third of a full publish).
|
|
144
|
+
for (const batch of chunks(entries, 500)) {
|
|
145
|
+
await client.query("insert into projection_stream (owner, view, version, audience, seq, json) select $1, $2, $3, $4, (e ->> 'seq')::bigint, e from jsonb_array_elements($5::jsonb) as t(e)", [owner, name, version, aud, JSON.stringify(batch)]);
|
|
146
|
+
}
|
|
147
|
+
for (const batch of chunks(upserts, 500)) {
|
|
148
|
+
await client.query(`insert into projections (owner, view, version, audience, record, row, buckets, marks, ancestors, sort, pin, seq)
|
|
149
|
+
select $1, $2, $3, $4, e ->> 'id', e -> 'row', e -> 'buckets', e -> 'row' -> 'marks',
|
|
150
|
+
coalesce(array(select jsonb_array_elements_text(case when jsonb_typeof(e -> 'row' -> 'ancestors') = 'array' then e -> 'row' -> 'ancestors' else '[]'::jsonb end)), '{}'),
|
|
151
|
+
e -> 'sort', (e ->> 'pin')::integer, (e ->> 'seq')::bigint
|
|
152
|
+
from jsonb_array_elements($5::jsonb) as t(e)
|
|
153
|
+
on conflict (owner, view, version, audience, record) do update set row = excluded.row, buckets = excluded.buckets, marks = excluded.marks, ancestors = excluded.ancestors, sort = excluded.sort, pin = excluded.pin, seq = excluded.seq`, [owner, name, version, aud, JSON.stringify(batch)]);
|
|
154
|
+
}
|
|
155
|
+
if (gone.length)
|
|
156
|
+
await client.query("delete from projections where owner = $1 and view = $2 and version = $3 and audience = $4 and record = any($5)", [owner, name, version, aud, gone]);
|
|
157
|
+
if (reset && !entries.length) {
|
|
158
|
+
// A new version with nothing changed still starts its stream: the index must drop the old rows.
|
|
159
|
+
await client.query("delete from projection_stream where owner = $1 and view = $2 and audience = $3 and version <> $4", [owner, name, aud, version]);
|
|
160
|
+
}
|
|
161
|
+
await client.query("insert into published (owner, view, audience, version) values ($1, $2, $3, $4) on conflict (owner, view, audience) do update set version = excluded.version", [owner, name, aud, version]);
|
|
162
|
+
if (only)
|
|
163
|
+
await client.query("delete from stale where owner = $1 and view = $2 and record = any($3)", [owner, name, only]);
|
|
164
|
+
else
|
|
165
|
+
await client.query("delete from stale where owner = $1 and view = $2", [owner, name]);
|
|
166
|
+
return entries;
|
|
167
|
+
}
|
|
168
|
+
/** The stream entries of a view for an audience after `seq`, for an index resuming from its cursor. */
|
|
169
|
+
export async function entriesSince(client, owner, p, name, seq, audience, limit) {
|
|
170
|
+
const v = p.views.views.get(name);
|
|
171
|
+
if (!v)
|
|
172
|
+
throw new Error(`no view ${name}`);
|
|
173
|
+
const rows = (await client.query(`select json from projection_stream where owner = $1 and view = $2 and audience = $3 and version = $4 and seq > $5 order by seq${limit ? ` limit ${Math.max(1, Math.floor(limit))}` : ""}`, [owner, name, audience ?? v.show, v.version ?? "", seq])).rows;
|
|
174
|
+
return rows.map((r) => r.json);
|
|
175
|
+
}
|
|
176
|
+
function chunks(list, size) {
|
|
177
|
+
const out = [];
|
|
178
|
+
for (let i = 0; i < list.length; i += size)
|
|
179
|
+
out.push(list.slice(i, i + size));
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=projector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projector.js","sourceRoot":"","sources":["../../src/projector.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,0GAA0G;AAC1G,oGAAoG;AACpG,wGAAwG;AAExG,OAAO,EAAE,MAAM,EAAoB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,OAAO,EAAoB,KAAK,EAAgB,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOtE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,KAAa,EAAE,CAAa,EAAE,MAAa,EAAE,KAAY,EAAE,GAAW;IACpH,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,aAAa,GAAG,IAAI,GAAG,CAAiB,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAA+B,CAAC,CAAC;IACxH,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAA+B,EAAE,CAAC;QA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