@substrat-run/kernel 0.210.0 → 0.212.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.
@@ -0,0 +1,307 @@
1
+ import type { PlatformActorId } from '@substrat-run/contracts';
2
+ import type { RedactionSql } from './subject-redaction.js';
3
+ import type { HostAdmin } from './scope-host.js';
4
+ /**
5
+ * The directory's outbox to the lake (K-70, tenants × time data leaves the objects; step 2 of
6
+ * docs/rfc/tenant-scale.md §12), as statements both adapters run against their directory.
7
+ *
8
+ * The directory keeps nine data sets that grow with tenants times time: the admin log, the staff
9
+ * access log, ops failures, sweep runs, model and build usage, and the request, cost and meter
10
+ * days. Each is shipped to the lake the way a scope ships its events: a row is written into an
11
+ * outbox in the SAME transaction as the row it records, and a drain ships the outbox in batches
12
+ * and deletes what the sink confirmed. Nothing here prunes a source row. What is shipped stays in
13
+ * the directory exactly as long as it did before; pruning to a window is a later, separate switch.
14
+ *
15
+ * **Captured by trigger, not by the writers.** An `AFTER INSERT` trigger on each captured table
16
+ * (and `AFTER UPDATE` where rows change after they are written) copies the row into the outbox.
17
+ * That keeps the guarantee K-70 asks of the admin log, written atomically with its change and
18
+ * shipped after, without touching any of the writers: whatever transaction wrote the source row
19
+ * wrote its outbox row, or neither. It also means a column added to a source table cannot be
20
+ * forgotten the way #1237's was: the trigger's column list is derived from the table as built
21
+ * (`ensureDirectoryLakeTriggers`), and re-derived whenever it differs.
22
+ *
23
+ * **Off unless switched on, per data set.** The triggers exist only for the data sets whose
24
+ * capture is on (`_substrat_directory_capture`), and are dropped when it is switched off, so a
25
+ * directory with capture off writes exactly what it wrote before this file existed. The two tables
26
+ * below are created empty either way, because a directory restore builds every table it may load
27
+ * from the directory's DDL.
28
+ *
29
+ * **What the lake gets.** Every version of a row the directory wrote while capture was on: an
30
+ * update ships the row again, with a later `captured_at` and `seq`. A delete ships nothing, which
31
+ * is what lets the directory prune a row the lake keeps. So a key's value in the lake is its
32
+ * latest captured version, and an erasure that redacted a row in place (ops failures, sweep runs)
33
+ * reaches the lake as a later version, not as the removal of the earlier one.
34
+ */
35
+ /** One captured data set: its table, its key, and the envelope columns the lake filters on. */
36
+ export interface DirectoryLakeDatasetSpec {
37
+ table: string;
38
+ /** The primary key, in order. One column ships as itself, more as a JSON array. */
39
+ key: readonly string[];
40
+ /** The row's own time: an ISO instant, or a UTC day. */
41
+ at: string;
42
+ tenant: string | null;
43
+ scope: string | null;
44
+ /** The column a reader most often filters on (an action, a method, an operation), or none. */
45
+ kind: string | null;
46
+ actor: string | null;
47
+ /** Whether rows change after they are written, so an update is captured too. */
48
+ updates: boolean;
49
+ /** Bookkeeping columns that are facts about the directory's copy, not the row. */
50
+ notShipped: readonly string[];
51
+ }
52
+ export declare const DIRECTORY_LAKE_DATASETS: {
53
+ readonly admin_log: {
54
+ readonly table: '_substrat_admin_log';
55
+ readonly key: readonly ["id"];
56
+ readonly at: 'at';
57
+ readonly tenant: 'tenant_id';
58
+ readonly scope: 'scope_id';
59
+ readonly kind: 'action';
60
+ readonly actor: 'actor';
61
+ readonly updates: false;
62
+ readonly notShipped: readonly [];
63
+ };
64
+ readonly access_log: {
65
+ readonly table: '_substrat_access_log';
66
+ readonly key: readonly ["id"];
67
+ readonly at: 'at';
68
+ readonly tenant: 'tenant_id';
69
+ readonly scope: 'scope_id';
70
+ readonly kind: 'method';
71
+ readonly actor: 'actor';
72
+ readonly updates: false;
73
+ readonly notShipped: readonly ["drained_at"];
74
+ };
75
+ readonly ops_failures: {
76
+ readonly table: '_substrat_ops_failures';
77
+ readonly key: readonly ["id"];
78
+ readonly at: 'at';
79
+ readonly tenant: 'tenant_id';
80
+ readonly scope: 'scope_id';
81
+ readonly kind: 'operation';
82
+ readonly actor: 'actor';
83
+ readonly updates: true;
84
+ readonly notShipped: readonly [];
85
+ };
86
+ readonly sweep_runs: {
87
+ readonly table: '_substrat_sweep_runs';
88
+ readonly key: readonly ["id"];
89
+ readonly at: 'at';
90
+ readonly tenant: 'tenant_id';
91
+ readonly scope: 'scope_id';
92
+ readonly kind: 'kind';
93
+ readonly actor: null;
94
+ readonly updates: true;
95
+ readonly notShipped: readonly [];
96
+ };
97
+ readonly model_usage: {
98
+ readonly table: '_substrat_model_usage';
99
+ readonly key: readonly ["id"];
100
+ readonly at: 'at';
101
+ readonly tenant: 'tenant_id';
102
+ readonly scope: 'scope_id';
103
+ readonly kind: 'model';
104
+ readonly actor: null;
105
+ readonly updates: false;
106
+ readonly notShipped: readonly [];
107
+ };
108
+ readonly build_usage: {
109
+ readonly table: '_substrat_build_usage';
110
+ readonly key: readonly ["build_id"];
111
+ readonly at: 'at';
112
+ readonly tenant: 'tenant_id';
113
+ readonly scope: null;
114
+ readonly kind: 'vertical';
115
+ readonly actor: null;
116
+ readonly updates: false;
117
+ readonly notShipped: readonly [];
118
+ };
119
+ readonly request_days: {
120
+ readonly table: '_substrat_request_days';
121
+ readonly key: readonly ["day", "tenant_id", "vertical", "scope_id"];
122
+ readonly at: 'day';
123
+ readonly tenant: 'tenant_id';
124
+ readonly scope: 'scope_id';
125
+ readonly kind: 'vertical';
126
+ readonly actor: null;
127
+ readonly updates: true;
128
+ readonly notShipped: readonly [];
129
+ };
130
+ readonly cost_days: {
131
+ readonly table: '_substrat_cost_days';
132
+ readonly key: readonly ["day", "script", "scope_id", "object_class", "object_id", "dimension"];
133
+ readonly at: 'day';
134
+ readonly tenant: 'tenant_id';
135
+ readonly scope: 'scope_id';
136
+ readonly kind: 'dimension';
137
+ readonly actor: null;
138
+ readonly updates: true;
139
+ readonly notShipped: readonly [];
140
+ };
141
+ readonly meter_days: {
142
+ readonly table: '_substrat_meter_days';
143
+ readonly key: readonly ["day", "tenant_id"];
144
+ readonly at: 'day';
145
+ readonly tenant: 'tenant_id';
146
+ readonly scope: null;
147
+ readonly kind: 'status';
148
+ readonly actor: null;
149
+ readonly updates: true;
150
+ readonly notShipped: readonly [];
151
+ };
152
+ };
153
+ export type DirectoryLakeDataset = keyof typeof DIRECTORY_LAKE_DATASETS;
154
+ export declare const DIRECTORY_LAKE_DATASET_NAMES: [DirectoryLakeDataset, ...DirectoryLakeDataset[]];
155
+ export declare const isDirectoryLakeDataset: (name: string) => name is DirectoryLakeDataset;
156
+ /**
157
+ * The outbox and the capture switch. `seq` is AUTOINCREMENT so a number is never handed out twice,
158
+ * even once every row below it has been shipped and deleted: the lake orders a key's versions by it.
159
+ * `row` is the whole source row as a JSON object of its columns, values as stored.
160
+ */
161
+ export declare const DIRECTORY_LAKE_DDL = "\n CREATE TABLE IF NOT EXISTS _substrat_directory_outbox (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n dataset TEXT NOT NULL,\n row_key TEXT NOT NULL,\n tenant_id TEXT,\n scope_id TEXT,\n at TEXT NOT NULL,\n kind TEXT,\n actor TEXT,\n captured_at TEXT NOT NULL,\n row TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS _substrat_directory_capture (\n dataset TEXT PRIMARY KEY,\n since TEXT NOT NULL,\n backfill_until INTEGER NOT NULL DEFAULT 0,\n backfill_after INTEGER NOT NULL DEFAULT 0,\n backfilled_at TEXT\n );\n";
162
+ /** One outbox row, or one backfilled source row in the same shape (`seq` null: it never queued). */
163
+ export interface DirectoryLakeRow {
164
+ seq: number | null;
165
+ dataset: DirectoryLakeDataset;
166
+ rowKey: string;
167
+ tenantId: string | null;
168
+ scopeId: string | null;
169
+ at: string;
170
+ kind: string | null;
171
+ actor: string | null;
172
+ capturedAt: string;
173
+ /** The source row, a JSON object text. */
174
+ row: string;
175
+ }
176
+ /**
177
+ * Which data sets capture, and since when; the highest source rowid when capture began (every row
178
+ * above it was written with the trigger in place, so a backfill stops there); how far a real
179
+ * backfill has shipped (the rowid its next page starts after); and `backfilledAt` once it is done.
180
+ */
181
+ export interface DirectoryLakeCaptureState {
182
+ dataset: DirectoryLakeDataset;
183
+ since: string;
184
+ backfillUntil: number;
185
+ backfillAfter: number;
186
+ backfilledAt: string | null;
187
+ }
188
+ /** What one reconcile of the capture switch changed. */
189
+ export interface DirectoryLakeCaptureResult {
190
+ enabled: DirectoryLakeDataset[];
191
+ disabled: DirectoryLakeDataset[];
192
+ current: DirectoryLakeCaptureState[];
193
+ /** Triggers rebuilt because the table they copy no longer had the columns they named. */
194
+ rebuilt: number;
195
+ }
196
+ /** One page of a backfill: the rows in outbox shape, and the cursor after them. */
197
+ export interface DirectoryLakeBackfillPage {
198
+ dataset: DirectoryLakeDataset;
199
+ rows: DirectoryLakeRow[];
200
+ /** The last source rowid read, to pass as `after` next; null when the page was empty. */
201
+ next: number | null;
202
+ /** Whether the walk reached the table's end with this page. */
203
+ done: boolean;
204
+ }
205
+ /**
206
+ * Where the drained rows go. Injected, like `EventSink`: the control plane binds a Pipelines
207
+ * stream; a self-host may bind nothing, and then keeps capture off.
208
+ *
209
+ * `ship` MUST be durable before it resolves: a resolved ship is what licenses deleting the outbox
210
+ * rows, and a sink that returned early would turn the lake's copy into a claim nobody can check.
211
+ */
212
+ export interface DirectoryLakeSink {
213
+ ship(rows: DirectoryLakeRow[]): Promise<{
214
+ ref: string;
215
+ }>;
216
+ }
217
+ /**
218
+ * The capture triggers a data set needs against the table as it is built now. Spelled as
219
+ * `sqlite_master` keeps it (no IF NOT EXISTS, single spaces), so one in place can be compared
220
+ * with the one this schema needs, text for text.
221
+ */
222
+ export declare function directoryLakeTriggerSql(sql: RedactionSql, dataset: DirectoryLakeDataset): {
223
+ name: string;
224
+ sql: string;
225
+ }[];
226
+ export declare function readDirectoryLakeCapture(sql: RedactionSql): DirectoryLakeCaptureState[];
227
+ /**
228
+ * Every capturing data set's triggers, held to its table as built. Run where a directory is
229
+ * constructed (a deploy that added a column rebuilds the trigger before the first write) and before
230
+ * every drain (a restore drops every table, and its triggers with it). Writes nothing when nothing
231
+ * differs.
232
+ */
233
+ export declare function ensureDirectoryLakeTriggers(sql: RedactionSql): number;
234
+ /**
235
+ * Reconcile the capture switch to `wanted`, in the caller's transaction. A data set switched on
236
+ * gets its triggers and `since = now`; one switched off loses them (its queued rows stay queued and
237
+ * still drain). Switching one back on resets `since` and its backfill mark: the rows written while
238
+ * it was off reached no outbox, so only a new backfill can vouch for them.
239
+ */
240
+ export declare function setDirectoryLakeCapture(sql: RedactionSql, wanted: readonly DirectoryLakeDataset[], now: string): DirectoryLakeCaptureResult;
241
+ /** The oldest `limit` queued rows, in the order they were written. */
242
+ export declare function readDirectoryOutbox(sql: RedactionSql, limit: number): DirectoryLakeRow[];
243
+ /**
244
+ * Delete the queued rows up to and including `upToSeq`, once the sink has confirmed them. `seq`
245
+ * is handed out in write order, so rows queued during the shipment sort after it and stay.
246
+ */
247
+ export declare function ackDirectoryOutbox(sql: RedactionSql, upToSeq: number): number;
248
+ /**
249
+ * One page of the rows a data set already held, in the outbox's shape, read by rowid after
250
+ * `after` and up to the rowid its capture began at (or the table's end, for a data set not
251
+ * capturing, which only a dry run reads). Rows above that were captured by the trigger, so a walk
252
+ * never chases the rows its own receipts write. Writes nothing: the backfill ships a page directly rather than queueing it, because a
253
+ * table's whole history through the outbox would cost the directory two writes a row for nothing.
254
+ * A row also captured by its trigger reaches the lake twice; the lake keeps a key's latest version.
255
+ */
256
+ export declare function readDirectoryLakeBackfill(sql: RedactionSql, dataset: DirectoryLakeDataset, after: number, limit: number): DirectoryLakeBackfillPage;
257
+ /**
258
+ * Record that a real backfill shipped one page of a CAPTURING data set: the page read after
259
+ * `after` and ending at `next`. Refused unless `after` is where the last recorded page ended, so
260
+ * the walk the mark vouches for has no gap, and refused for a data set not capturing (a row
261
+ * written after the walk passed it would then reach no outbox). `done` records `backfilledAt`.
262
+ * Returns the state after the call; writes nothing when the page was already recorded.
263
+ */
264
+ export declare function advanceDirectoryLakeBackfill(sql: RedactionSql, dataset: DirectoryLakeDataset, page: {
265
+ after: number;
266
+ next: number | null;
267
+ done: boolean;
268
+ }, now: string): {
269
+ state: DirectoryLakeCaptureState;
270
+ changed: boolean;
271
+ };
272
+ /**
273
+ * The switch as the control plane's environment spells it: unset, empty or `off` captures
274
+ * nothing; `all` captures every data set; otherwise a comma list of data set names. A name this
275
+ * code does not know is refused rather than ignored, so a typo cannot read as "on".
276
+ */
277
+ export declare function parseDirectoryLakeCapture(value: string | undefined): DirectoryLakeDataset[];
278
+ /**
279
+ * K-70's proposed window: how many days of each captured data set the directory keeps once the
280
+ * prune is switched on, and the boundary a history read splits at (directory after, lake before).
281
+ * 35 days covers a billing period and a dispute. An open choice in K-70; one constant on purpose.
282
+ */
283
+ export declare const DIRECTORY_LAKE_WINDOW_DAYS = 35;
284
+ /** How many outbox rows one batch ships by default, and how many batches one pass may drain. */
285
+ export declare const DIRECTORY_LAKE_BATCH = 500;
286
+ export declare const DIRECTORY_LAKE_BATCHES_PER_PASS = 8;
287
+ export interface DirectoryLakeSweepOptions {
288
+ sink: DirectoryLakeSink;
289
+ /** The data sets that capture. Empty switches capture off; queued rows still drain. */
290
+ capture: readonly DirectoryLakeDataset[];
291
+ batch?: number;
292
+ batchesPerPass?: number;
293
+ }
294
+ export interface DirectoryLakeSweepReport {
295
+ /** What the reconcile changed, or null when the host has no directory outbox. */
296
+ capture: DirectoryLakeCaptureResult | null;
297
+ shipped: number;
298
+ acked: number;
299
+ ref: string | null;
300
+ }
301
+ /**
302
+ * The pass's phase: reconcile the switch, then ship → confirm → delete, batch after batch while
303
+ * each comes back full, up to `batchesPerPass`. A throw anywhere leaves the unconfirmed rows queued,
304
+ * so the next pass ships them again (at least once, never fewer).
305
+ */
306
+ export declare function sweepDirectoryLake(admin: HostAdmin, actor: PlatformActorId, options: DirectoryLakeSweepOptions, out: DirectoryLakeSweepReport): Promise<void>;
307
+ //# sourceMappingURL=directory-lake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory-lake.d.ts","sourceRoot":"","sources":["../src/directory-lake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC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AAE,yBAAyB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAcxD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,oBAAoB,EAAE,CAU3F;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,iBAAiB,CAAC;IACxB,uFAAuF;IACvF,OAAO,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC,iFAAiF;IACjF,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,yBAAyB,EAClC,GAAG,EAAE,wBAAwB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAef"}
@@ -0,0 +1,329 @@
1
+ import { assertRowLimit } from './retention.js';
2
+ export const DIRECTORY_LAKE_DATASETS = {
3
+ admin_log: {
4
+ table: '_substrat_admin_log', key: ['id'], at: 'at', tenant: 'tenant_id', scope: 'scope_id',
5
+ kind: 'action', actor: 'actor', updates: false, notShipped: [],
6
+ },
7
+ // `drained_at` is the access log's own drain to R2 (K-24), stamped by an UPDATE: a fact about
8
+ // that copy, and not a reason to ship the row a second time.
9
+ access_log: {
10
+ table: '_substrat_access_log', key: ['id'], at: 'at', tenant: 'tenant_id', scope: 'scope_id',
11
+ kind: 'method', actor: 'actor', updates: false, notShipped: ['drained_at'],
12
+ },
13
+ // Updated in place by an erasure (`subject-redaction.ts`), so the redacted version ships too.
14
+ ops_failures: {
15
+ table: '_substrat_ops_failures', key: ['id'], at: 'at', tenant: 'tenant_id', scope: 'scope_id',
16
+ kind: 'operation', actor: 'actor', updates: true, notShipped: [],
17
+ },
18
+ sweep_runs: {
19
+ table: '_substrat_sweep_runs', key: ['id'], at: 'at', tenant: 'tenant_id', scope: 'scope_id',
20
+ kind: 'kind', actor: null, updates: true, notShipped: [],
21
+ },
22
+ model_usage: {
23
+ table: '_substrat_model_usage', key: ['id'], at: 'at', tenant: 'tenant_id', scope: 'scope_id',
24
+ kind: 'model', actor: null, updates: false, notShipped: [],
25
+ },
26
+ build_usage: {
27
+ table: '_substrat_build_usage', key: ['build_id'], at: 'at', tenant: 'tenant_id', scope: null,
28
+ kind: 'vertical', actor: null, updates: false, notShipped: [],
29
+ },
30
+ // The three rollups upsert (`ON CONFLICT … DO UPDATE`), and cost days are re-attributed later.
31
+ request_days: {
32
+ table: '_substrat_request_days', key: ['day', 'tenant_id', 'vertical', 'scope_id'], at: 'day',
33
+ tenant: 'tenant_id', scope: 'scope_id', kind: 'vertical', actor: null, updates: true, notShipped: [],
34
+ },
35
+ cost_days: {
36
+ table: '_substrat_cost_days', key: ['day', 'script', 'scope_id', 'object_class', 'object_id', 'dimension'],
37
+ at: 'day', tenant: 'tenant_id', scope: 'scope_id', kind: 'dimension', actor: null, updates: true, notShipped: [],
38
+ },
39
+ meter_days: {
40
+ table: '_substrat_meter_days', key: ['day', 'tenant_id'], at: 'day', tenant: 'tenant_id', scope: null,
41
+ kind: 'status', actor: null, updates: true, notShipped: [],
42
+ },
43
+ };
44
+ export const DIRECTORY_LAKE_DATASET_NAMES = Object.keys(DIRECTORY_LAKE_DATASETS);
45
+ export const isDirectoryLakeDataset = (name) => Object.prototype.hasOwnProperty.call(DIRECTORY_LAKE_DATASETS, name);
46
+ /**
47
+ * The outbox and the capture switch. `seq` is AUTOINCREMENT so a number is never handed out twice,
48
+ * even once every row below it has been shipped and deleted: the lake orders a key's versions by it.
49
+ * `row` is the whole source row as a JSON object of its columns, values as stored.
50
+ */
51
+ export const DIRECTORY_LAKE_DDL = `
52
+ CREATE TABLE IF NOT EXISTS _substrat_directory_outbox (
53
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
54
+ dataset TEXT NOT NULL,
55
+ row_key TEXT NOT NULL,
56
+ tenant_id TEXT,
57
+ scope_id TEXT,
58
+ at TEXT NOT NULL,
59
+ kind TEXT,
60
+ actor TEXT,
61
+ captured_at TEXT NOT NULL,
62
+ row TEXT NOT NULL
63
+ );
64
+ CREATE TABLE IF NOT EXISTS _substrat_directory_capture (
65
+ dataset TEXT PRIMARY KEY,
66
+ since TEXT NOT NULL,
67
+ backfill_until INTEGER NOT NULL DEFAULT 0,
68
+ backfill_after INTEGER NOT NULL DEFAULT 0,
69
+ backfilled_at TEXT
70
+ );
71
+ `;
72
+ const quoteIdent = (name) => `"${name.replaceAll('"', '""')}"`;
73
+ const quoteText = (text) => `'${text.replaceAll("'", "''")}'`;
74
+ const triggerName = (verb, dataset) => `_substrat_directory_capture_${verb}_${dataset}`;
75
+ const CAPTURED_AT = `strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
76
+ function columnsOf(sql, table) {
77
+ return sql(`SELECT name FROM pragma_table_info(?, 'main')`, [table]).map((c) => c.name);
78
+ }
79
+ /** The envelope and the row, as SQL expressions over one row named by `ref` (`NEW`, or the table). */
80
+ function rowExpressions(spec, columns, ref) {
81
+ const col = (c) => `${ref}.${quoteIdent(c)}`;
82
+ const opt = (c) => (c === null ? 'NULL' : col(c));
83
+ const shipped = columns.filter((c) => !spec.notShipped.includes(c));
84
+ return {
85
+ key: spec.key.length === 1 ? `CAST(${col(spec.key[0])} AS TEXT)` : `json_array(${spec.key.map(col).join(', ')})`,
86
+ tenant: opt(spec.tenant),
87
+ scope: opt(spec.scope),
88
+ at: col(spec.at),
89
+ kind: opt(spec.kind),
90
+ actor: opt(spec.actor),
91
+ row: `json_object(${shipped.map((c) => `${quoteText(c)}, ${col(c)}`).join(', ')})`,
92
+ };
93
+ }
94
+ /**
95
+ * The capture triggers a data set needs against the table as it is built now. Spelled as
96
+ * `sqlite_master` keeps it (no IF NOT EXISTS, single spaces), so one in place can be compared
97
+ * with the one this schema needs, text for text.
98
+ */
99
+ export function directoryLakeTriggerSql(sql, dataset) {
100
+ const spec = DIRECTORY_LAKE_DATASETS[dataset];
101
+ const columns = columnsOf(sql, spec.table);
102
+ const required = [...spec.key, spec.at, spec.tenant, spec.scope, spec.kind, spec.actor].filter((c) => c !== null);
103
+ const missing = required.filter((c) => !columns.includes(c));
104
+ if (missing.length > 0) {
105
+ throw new Error(`directory lake: ${spec.table} has no column ${missing.join(', ')}; the ${dataset} capture cannot be built`);
106
+ }
107
+ const e = rowExpressions(spec, columns, 'NEW');
108
+ const body = `INSERT INTO _substrat_directory_outbox (dataset, row_key, tenant_id, scope_id, at, kind, actor, captured_at, row) ` +
109
+ `VALUES (${quoteText(dataset)}, ${e.key}, ${e.tenant}, ${e.scope}, ${e.at}, ${e.kind}, ${e.actor}, ${CAPTURED_AT}, ${e.row});`;
110
+ const on = (verb, event) => {
111
+ const name = triggerName(verb, dataset);
112
+ return { name, sql: `CREATE TRIGGER ${quoteIdent(name)} AFTER ${event} ON ${quoteIdent(spec.table)} BEGIN ${body} END` };
113
+ };
114
+ return spec.updates ? [on('i', 'INSERT'), on('u', 'UPDATE')] : [on('i', 'INSERT')];
115
+ }
116
+ function dropTriggers(sql, dataset) {
117
+ for (const verb of ['i', 'u'])
118
+ sql(`DROP TRIGGER IF EXISTS ${quoteIdent(triggerName(verb, dataset))}`, []);
119
+ }
120
+ /** Build or rebuild one data set's triggers where the ones in place differ. Returns how many it wrote. */
121
+ function ensureTriggers(sql, dataset) {
122
+ let written = 0;
123
+ for (const t of directoryLakeTriggerSql(sql, dataset)) {
124
+ const held = sql(`SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = ?`, [t.name])[0];
125
+ if (held?.sql === t.sql)
126
+ continue;
127
+ sql(`DROP TRIGGER IF EXISTS ${quoteIdent(t.name)}`, []);
128
+ sql(t.sql, []);
129
+ written += 1;
130
+ }
131
+ return written;
132
+ }
133
+ const maxRowid = (sql, dataset) => sql(`SELECT COALESCE(MAX(rowid), 0) AS m FROM ${quoteIdent(DIRECTORY_LAKE_DATASETS[dataset].table)}`, [])[0]?.m ?? 0;
134
+ export function readDirectoryLakeCapture(sql) {
135
+ return sql(`SELECT dataset, since, backfill_until, backfill_after, backfilled_at FROM _substrat_directory_capture ORDER BY dataset`, [])
136
+ .filter((r) => isDirectoryLakeDataset(r.dataset))
137
+ .map((r) => ({
138
+ dataset: r.dataset,
139
+ since: r.since,
140
+ backfillUntil: r.backfill_until,
141
+ backfillAfter: r.backfill_after,
142
+ backfilledAt: r.backfilled_at,
143
+ }));
144
+ }
145
+ /**
146
+ * Every capturing data set's triggers, held to its table as built. Run where a directory is
147
+ * constructed (a deploy that added a column rebuilds the trigger before the first write) and before
148
+ * every drain (a restore drops every table, and its triggers with it). Writes nothing when nothing
149
+ * differs.
150
+ */
151
+ export function ensureDirectoryLakeTriggers(sql) {
152
+ let written = 0;
153
+ for (const { dataset } of readDirectoryLakeCapture(sql))
154
+ written += ensureTriggers(sql, dataset);
155
+ return written;
156
+ }
157
+ /**
158
+ * Reconcile the capture switch to `wanted`, in the caller's transaction. A data set switched on
159
+ * gets its triggers and `since = now`; one switched off loses them (its queued rows stay queued and
160
+ * still drain). Switching one back on resets `since` and its backfill mark: the rows written while
161
+ * it was off reached no outbox, so only a new backfill can vouch for them.
162
+ */
163
+ export function setDirectoryLakeCapture(sql, wanted, now) {
164
+ for (const d of wanted)
165
+ if (!isDirectoryLakeDataset(d))
166
+ throw new Error(`directory lake: no data set named ${String(d)}`);
167
+ const before = new Set(readDirectoryLakeCapture(sql).map((c) => c.dataset));
168
+ const want = new Set(wanted);
169
+ const enabled = [];
170
+ const disabled = [];
171
+ let rebuilt = 0;
172
+ for (const dataset of DIRECTORY_LAKE_DATASET_NAMES) {
173
+ if (want.has(dataset) && !before.has(dataset)) {
174
+ // Read and written in the transaction that creates the triggers: no row lands between them.
175
+ const until = maxRowid(sql, dataset);
176
+ sql(`INSERT INTO _substrat_directory_capture (dataset, since, backfill_until, backfill_after, backfilled_at) VALUES (?, ?, ?, 0, NULL)`, [dataset, now, until]);
177
+ ensureTriggers(sql, dataset);
178
+ enabled.push(dataset);
179
+ }
180
+ else if (!want.has(dataset) && before.has(dataset)) {
181
+ dropTriggers(sql, dataset);
182
+ sql(`DELETE FROM _substrat_directory_capture WHERE dataset = ?`, [dataset]);
183
+ disabled.push(dataset);
184
+ }
185
+ else if (want.has(dataset)) {
186
+ rebuilt += ensureTriggers(sql, dataset);
187
+ }
188
+ else {
189
+ // Off, and recorded off: a trigger left by a half-applied reconcile is dropped anyway.
190
+ dropTriggers(sql, dataset);
191
+ }
192
+ }
193
+ return { enabled, disabled, current: readDirectoryLakeCapture(sql), rebuilt };
194
+ }
195
+ const fromOutbox = (r) => ({
196
+ seq: r.seq,
197
+ dataset: r.dataset,
198
+ rowKey: r.row_key,
199
+ tenantId: r.tenant_id,
200
+ scopeId: r.scope_id,
201
+ at: r.at,
202
+ kind: r.kind,
203
+ actor: r.actor,
204
+ capturedAt: r.captured_at,
205
+ row: r.row,
206
+ });
207
+ /** The oldest `limit` queued rows, in the order they were written. */
208
+ export function readDirectoryOutbox(sql, limit) {
209
+ assertRowLimit('limit', limit);
210
+ return sql(`SELECT seq, dataset, row_key, tenant_id, scope_id, at, kind, actor, captured_at, row
211
+ FROM _substrat_directory_outbox ORDER BY seq LIMIT ?`, [limit]).map(fromOutbox);
212
+ }
213
+ /**
214
+ * Delete the queued rows up to and including `upToSeq`, once the sink has confirmed them. `seq`
215
+ * is handed out in write order, so rows queued during the shipment sort after it and stay.
216
+ */
217
+ export function ackDirectoryOutbox(sql, upToSeq) {
218
+ if (!Number.isSafeInteger(upToSeq) || upToSeq < 0)
219
+ throw new Error(`directory lake: upToSeq must be a whole number, got ${upToSeq}`);
220
+ const n = sql(`SELECT COUNT(*) AS n FROM _substrat_directory_outbox WHERE seq <= ?`, [upToSeq])[0]?.n ?? 0;
221
+ if (n > 0)
222
+ sql(`DELETE FROM _substrat_directory_outbox WHERE seq <= ?`, [upToSeq]);
223
+ return n;
224
+ }
225
+ /**
226
+ * One page of the rows a data set already held, in the outbox's shape, read by rowid after
227
+ * `after` and up to the rowid its capture began at (or the table's end, for a data set not
228
+ * capturing, which only a dry run reads). Rows above that were captured by the trigger, so a walk
229
+ * never chases the rows its own receipts write. Writes nothing: the backfill ships a page directly rather than queueing it, because a
230
+ * table's whole history through the outbox would cost the directory two writes a row for nothing.
231
+ * A row also captured by its trigger reaches the lake twice; the lake keeps a key's latest version.
232
+ */
233
+ export function readDirectoryLakeBackfill(sql, dataset, after, limit) {
234
+ assertRowLimit('limit', limit);
235
+ if (!isDirectoryLakeDataset(dataset))
236
+ throw new Error(`directory lake: no data set named ${String(dataset)}`);
237
+ if (!Number.isSafeInteger(after) || after < 0)
238
+ throw new Error(`directory lake: after must be a whole number, got ${after}`);
239
+ const spec = DIRECTORY_LAKE_DATASETS[dataset];
240
+ const e = rowExpressions(spec, columnsOf(sql, spec.table), 't');
241
+ const until = readDirectoryLakeCapture(sql).find((c) => c.dataset === dataset)?.backfillUntil ?? maxRowid(sql, dataset);
242
+ const rows = sql(`SELECT t.rowid AS rid, ${e.key} AS row_key, ${e.tenant} AS tenant_id, ${e.scope} AS scope_id, ${e.at} AS at,
243
+ ${e.kind} AS kind, ${e.actor} AS actor, ${CAPTURED_AT} AS captured_at, ${e.row} AS row
244
+ FROM ${quoteIdent(spec.table)} t WHERE t.rowid > ? AND t.rowid <= ? ORDER BY t.rowid LIMIT ?`, [after, until, limit]);
245
+ return {
246
+ dataset,
247
+ rows: rows.map(({ rid: _rid, ...r }) => fromOutbox({ ...r, seq: null, dataset })),
248
+ next: rows.length === 0 ? null : rows[rows.length - 1].rid,
249
+ done: rows.length < limit || rows[rows.length - 1].rid >= until,
250
+ };
251
+ }
252
+ /**
253
+ * Record that a real backfill shipped one page of a CAPTURING data set: the page read after
254
+ * `after` and ending at `next`. Refused unless `after` is where the last recorded page ended, so
255
+ * the walk the mark vouches for has no gap, and refused for a data set not capturing (a row
256
+ * written after the walk passed it would then reach no outbox). `done` records `backfilledAt`.
257
+ * Returns the state after the call; writes nothing when the page was already recorded.
258
+ */
259
+ export function advanceDirectoryLakeBackfill(sql, dataset, page, now) {
260
+ const held = readDirectoryLakeCapture(sql).find((c) => c.dataset === dataset);
261
+ if (!held)
262
+ throw new Error(`directory lake: ${dataset} is not capturing, so a backfill of it vouches for nothing`);
263
+ // Once it reached the end, a later page vouches for nothing new: rows written since are captured.
264
+ if (held.backfilledAt !== null)
265
+ return { state: held, changed: false };
266
+ const to = page.next ?? page.after;
267
+ if (page.after !== held.backfillAfter) {
268
+ throw new Error(`directory lake: the ${dataset} backfill resumes after rowid ${held.backfillAfter}, not ${page.after}`);
269
+ }
270
+ if (to < page.after)
271
+ throw new Error(`directory lake: a backfill page cannot end (${to}) before it starts (${page.after})`);
272
+ const backfilledAt = page.done ? now : null;
273
+ if (to === held.backfillAfter && backfilledAt === null)
274
+ return { state: held, changed: false };
275
+ sql(`UPDATE _substrat_directory_capture SET backfill_after = ?, backfilled_at = COALESCE(backfilled_at, ?) WHERE dataset = ?`, [to, backfilledAt, dataset]);
276
+ return { state: readDirectoryLakeCapture(sql).find((c) => c.dataset === dataset), changed: true };
277
+ }
278
+ /**
279
+ * The switch as the control plane's environment spells it: unset, empty or `off` captures
280
+ * nothing; `all` captures every data set; otherwise a comma list of data set names. A name this
281
+ * code does not know is refused rather than ignored, so a typo cannot read as "on".
282
+ */
283
+ export function parseDirectoryLakeCapture(value) {
284
+ const text = (value ?? '').trim();
285
+ if (text === '' || text === 'off')
286
+ return [];
287
+ if (text === 'all')
288
+ return [...DIRECTORY_LAKE_DATASET_NAMES];
289
+ const names = [...new Set(text.split(',').map((s) => s.trim()).filter((s) => s !== ''))];
290
+ const unknown = names.filter((n) => !isDirectoryLakeDataset(n));
291
+ if (unknown.length > 0) {
292
+ throw new Error(`directory lake: unknown data set ${unknown.join(', ')} (known: ${DIRECTORY_LAKE_DATASET_NAMES.join(', ')}, or all, or off)`);
293
+ }
294
+ return names;
295
+ }
296
+ /**
297
+ * K-70's proposed window: how many days of each captured data set the directory keeps once the
298
+ * prune is switched on, and the boundary a history read splits at (directory after, lake before).
299
+ * 35 days covers a billing period and a dispute. An open choice in K-70; one constant on purpose.
300
+ */
301
+ export const DIRECTORY_LAKE_WINDOW_DAYS = 35;
302
+ /** How many outbox rows one batch ships by default, and how many batches one pass may drain. */
303
+ export const DIRECTORY_LAKE_BATCH = 500;
304
+ export const DIRECTORY_LAKE_BATCHES_PER_PASS = 8;
305
+ /**
306
+ * The pass's phase: reconcile the switch, then ship → confirm → delete, batch after batch while
307
+ * each comes back full, up to `batchesPerPass`. A throw anywhere leaves the unconfirmed rows queued,
308
+ * so the next pass ships them again (at least once, never fewer).
309
+ */
310
+ export async function sweepDirectoryLake(admin, actor, options, out) {
311
+ if (!admin.setDirectoryLakeCapture || !admin.directoryOutbox || !admin.ackDirectoryOutbox)
312
+ return;
313
+ const batch = options.batch ?? DIRECTORY_LAKE_BATCH;
314
+ const batches = options.batchesPerPass ?? DIRECTORY_LAKE_BATCHES_PER_PASS;
315
+ assertRowLimit('batch', batch);
316
+ out.capture = await admin.setDirectoryLakeCapture(actor, options.capture);
317
+ for (let i = 0; i < batches; i++) {
318
+ const pending = await admin.directoryOutbox(actor, batch);
319
+ if (pending.length === 0)
320
+ return;
321
+ const { ref } = await options.sink.ship(pending);
322
+ out.shipped += pending.length;
323
+ out.ref = ref;
324
+ out.acked += await admin.ackDirectoryOutbox(actor, pending[pending.length - 1].seq, ref);
325
+ if (pending.length < batch)
326
+ return;
327
+ }
328
+ }
329
+ //# sourceMappingURL=directory-lake.js.map