@substrat-run/kernel 0.204.0 → 0.206.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.
Files changed (48) hide show
  1. package/dist/connection-landings.d.ts +52 -2
  2. package/dist/connection-landings.d.ts.map +1 -1
  3. package/dist/connection-landings.js +72 -6
  4. package/dist/connection-landings.js.map +1 -1
  5. package/dist/cost-rollup.d.ts +186 -0
  6. package/dist/cost-rollup.d.ts.map +1 -0
  7. package/dist/cost-rollup.js +475 -0
  8. package/dist/cost-rollup.js.map +1 -0
  9. package/dist/index.d.ts +9 -4
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +8 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/markup-schedule.d.ts +51 -0
  14. package/dist/markup-schedule.d.ts.map +1 -0
  15. package/dist/markup-schedule.js +70 -0
  16. package/dist/markup-schedule.js.map +1 -0
  17. package/dist/model-usage.d.ts +8 -1
  18. package/dist/model-usage.d.ts.map +1 -1
  19. package/dist/model-usage.js +38 -19
  20. package/dist/model-usage.js.map +1 -1
  21. package/dist/module-erasure.d.ts +17 -0
  22. package/dist/module-erasure.d.ts.map +1 -1
  23. package/dist/module-erasure.js +18 -3
  24. package/dist/module-erasure.js.map +1 -1
  25. package/dist/platform-sweep.d.ts +86 -5
  26. package/dist/platform-sweep.d.ts.map +1 -1
  27. package/dist/platform-sweep.js +180 -19
  28. package/dist/platform-sweep.js.map +1 -1
  29. package/dist/scope-host.d.ts +82 -4
  30. package/dist/scope-host.d.ts.map +1 -1
  31. package/dist/scope-host.js.map +1 -1
  32. package/dist/scope-work-bindings.d.ts +19 -0
  33. package/dist/scope-work-bindings.d.ts.map +1 -0
  34. package/dist/scope-work-bindings.js +17 -0
  35. package/dist/scope-work-bindings.js.map +1 -0
  36. package/dist/snapshot-retention.d.ts +19 -0
  37. package/dist/snapshot-retention.d.ts.map +1 -0
  38. package/dist/snapshot-retention.js +21 -0
  39. package/dist/snapshot-retention.js.map +1 -0
  40. package/dist/subject-access.d.ts +38 -0
  41. package/dist/subject-access.d.ts.map +1 -0
  42. package/dist/subject-access.js +123 -0
  43. package/dist/subject-access.js.map +1 -0
  44. package/dist/timeline.d.ts +12 -0
  45. package/dist/timeline.d.ts.map +1 -1
  46. package/dist/timeline.js +19 -0
  47. package/dist/timeline.js.map +1 -1
  48. package/package.json +2 -2
@@ -0,0 +1,475 @@
1
+ import { CONNECTOR_SCRIPT_PREFIX, PLATFORM_SCRIPT_NAMES, SCOPE_STORE_SCRIPT_PREFIX, addDecimal, cloudflareUsageDay, costDay, requestRollupDay, verticalScriptStem, } from '@substrat-run/contracts';
2
+ import { assertRowLimit } from './retention.js';
3
+ import { assertUtcDay, pruneBillingDays, pushDayWindow } from './billing-retention.js';
4
+ /**
5
+ * The daily Cloudflare cost rollup (#3316, #3311), as statements both adapters run against their
6
+ * directory, beside the request rollup (`request-rollup.ts`).
7
+ *
8
+ * Cloudflare's GraphQL Analytics answer for 90 days. This keeps one row per (UTC day, script,
9
+ * scope, Durable Object class, billed dimension), so the history outlives them. The rows are COST
10
+ * INPUTS ONLY: quantities in the analytics' own units, never a price. A markup schedule prices them
11
+ * at read.
12
+ *
13
+ * Attribution happens HERE, in the transaction that records the day, through the directory and
14
+ * never through a script name's prefix: a Durable Object maps to a scope by the object id recorded
15
+ * for it (`_substrat_scope_objects`), and a script to its vertical, version and owner by the
16
+ * `verticals`, `vertical_versions` and `_substrat_vertical_owners` rows. The scheduled pass and the
17
+ * backfill loader hand the same raw day (`CloudflareUsageDay`) to the same code, so a loaded day
18
+ * and a read day cannot be attributed by different rules.
19
+ *
20
+ * `_substrat_cost_day_reads` is the request rollup's day ledger, for the same reason: a day without
21
+ * a successful read has no rows to say anything with. Empty strings stand for "none" in the key
22
+ * columns (`scope_id`, `object_class`, `object_id`), which a primary key cannot hold as NULL.
23
+ *
24
+ * Every per-object row keeps its object id, so a day read before its scopes' ids were recorded
25
+ * (a pass that ran before a vertical could answer, a loaded snapshot) is attributed when they are:
26
+ * recording an id re-attributes that object's `unmapped` and `unknown` rows in the same transaction.
27
+ *
28
+ * `_substrat_scope_objects` is the directory's record of each scope's Durable Object id: the hex id
29
+ * Cloudflare reports, which is `SCOPE.idFromName(scopeId)` inside the script that holds the scope's
30
+ * data and cannot be computed anywhere else. It keeps the scope's tenant, vertical and kind beside
31
+ * the id, so an object stays attributable after its scope is reaped. `_substrat_scope_object_reads`
32
+ * holds the last failed attempt per (scope, script), so a deployment that predates the read is
33
+ * asked again a day later, not every pass.
34
+ */
35
+ export const COST_ROLLUP_DDL = `
36
+ CREATE TABLE IF NOT EXISTS _substrat_cost_days (
37
+ day TEXT NOT NULL,
38
+ script TEXT NOT NULL,
39
+ scope_id TEXT NOT NULL,
40
+ object_class TEXT NOT NULL,
41
+ object_id TEXT NOT NULL,
42
+ dimension TEXT NOT NULL,
43
+ attribution TEXT NOT NULL,
44
+ tenant_id TEXT,
45
+ vertical TEXT,
46
+ kind TEXT NOT NULL,
47
+ version_id TEXT,
48
+ preview_tag TEXT,
49
+ quantity TEXT NOT NULL,
50
+ lower TEXT,
51
+ upper TEXT,
52
+ PRIMARY KEY (day, script, scope_id, object_class, object_id, dimension)
53
+ );
54
+ CREATE INDEX IF NOT EXISTS _substrat_cost_days_tenant ON _substrat_cost_days (tenant_id, day);
55
+ CREATE INDEX IF NOT EXISTS _substrat_cost_days_object ON _substrat_cost_days (object_id, attribution);
56
+ CREATE TABLE IF NOT EXISTS _substrat_cost_day_reads (
57
+ day TEXT PRIMARY KEY,
58
+ attempted_at TEXT NOT NULL,
59
+ read_at TEXT,
60
+ row_count INTEGER,
61
+ error TEXT,
62
+ failing_since TEXT,
63
+ failing_count INTEGER
64
+ );
65
+ CREATE TABLE IF NOT EXISTS _substrat_scope_objects (
66
+ object_id TEXT PRIMARY KEY,
67
+ scope_id TEXT NOT NULL,
68
+ tenant_id TEXT NOT NULL,
69
+ script TEXT NOT NULL,
70
+ vertical TEXT NOT NULL,
71
+ kind TEXT NOT NULL,
72
+ version_id TEXT,
73
+ preview_tag TEXT,
74
+ recorded_at TEXT NOT NULL
75
+ );
76
+ CREATE INDEX IF NOT EXISTS _substrat_scope_objects_scope ON _substrat_scope_objects (scope_id, script);
77
+ CREATE TABLE IF NOT EXISTS _substrat_scope_object_reads (
78
+ scope_id TEXT NOT NULL,
79
+ script TEXT NOT NULL,
80
+ attempted_at TEXT NOT NULL,
81
+ error TEXT NOT NULL,
82
+ PRIMARY KEY (scope_id, script)
83
+ );
84
+ `;
85
+ /**
86
+ * How many days back the cost rollup reaches. Cloudflare answers for 90 days ("cannot request data
87
+ * older than 12w6d"); this stays inside them with a margin, so no day is read while it ages out.
88
+ */
89
+ export const COST_ROLLUP_LOOKBACK_DAYS = 85;
90
+ /** The furthest back a lookback may be set: inside the 90 days with a day's margin for the first day's start. */
91
+ export const COST_ROLLUP_MAX_LOOKBACK_DAYS = 88;
92
+ /**
93
+ * How long after a day ends it may be read. The periodic Durable Object dataset is an aggregate
94
+ * Cloudflare writes after the fact, so this waits longer than the request rollup does: the first
95
+ * pass after 03:00 UTC takes the day before.
96
+ */
97
+ export const COST_ROLLUP_SETTLE_MS = 3 * 3_600_000;
98
+ /** How long a day whose read failed waits before it is tried again. */
99
+ export const COST_ROLLUP_RETRY_MS = 3_600_000;
100
+ /** How long one day's read (several GraphQL pages and the namespace list) may take. */
101
+ export const COST_ROLLUP_READ_TIMEOUT_MS = 60_000;
102
+ /** The most days one pass reads. A first pass catches up over several. */
103
+ export const COST_ROLLUP_DAYS_PER_PASS = 3;
104
+ /** How many rows one `pruneCostDays` call deletes, by default. */
105
+ export const COST_ROLLUP_PRUNE_BATCH = 500;
106
+ /** The most rows one `listCostDays` call returns, and its default. */
107
+ export const COST_ROLLUP_LIMIT_MAX = 10_000;
108
+ export const COST_ROLLUP_LIMIT_DEFAULT = 1_000;
109
+ /** How many scopes one pass asks for their object id. Asking wakes no object: it is `idFromName`. */
110
+ export const SCOPE_OBJECTS_PER_PASS = 100;
111
+ /** How long a scope whose object id could not be read waits before it is asked again. */
112
+ export const SCOPE_OBJECT_RETRY_MS = 86_400_000;
113
+ const ULID_SUFFIX = /^(.+)-([0-9a-hjkmnp-tv-z]{26})$/;
114
+ /** Which vertical, version and owner a script is, by the directory alone. */
115
+ function scriptInfoOf(script, dir) {
116
+ const none = { vertical: null, versionId: null, kind: 'live', tenantId: null };
117
+ if (PLATFORM_SCRIPT_NAMES.has(script) || script.startsWith(SCOPE_STORE_SCRIPT_PREFIX) || script.startsWith(CONNECTOR_SCRIPT_PREFIX)) {
118
+ return { attribution: 'platform', ...none };
119
+ }
120
+ let version = dir.versionByScript.get(script);
121
+ if (!version) {
122
+ const m = ULID_SUFFIX.exec(script);
123
+ const byId = m ? dir.versionById.get(m[2].toUpperCase()) : undefined;
124
+ // The id alone is not enough: the stem has to be the version's own vertical's.
125
+ if (byId && verticalScriptStem(byId.slug) === m[1])
126
+ version = byId;
127
+ }
128
+ if (version) {
129
+ return {
130
+ attribution: 'script',
131
+ vertical: version.slug,
132
+ versionId: version.versionId,
133
+ kind: dir.liveScripts.has(script) ? 'live' : 'preview',
134
+ tenantId: dir.ownerBySlug.get(version.slug) ?? null,
135
+ };
136
+ }
137
+ const slug = dir.slugByScript.get(script);
138
+ if (slug !== undefined) {
139
+ return { attribution: 'script', vertical: slug, versionId: null, kind: 'live', tenantId: dir.ownerBySlug.get(slug) ?? null };
140
+ }
141
+ return { attribution: 'unknown', ...none };
142
+ }
143
+ /** A non-negative analytics number as a decimal string, at most 6 places. */
144
+ function decimalOf(n) {
145
+ if (!Number.isFinite(n) || n < 0)
146
+ throw new Error(`a usage figure must be a non-negative number, got ${String(n)}`);
147
+ if (Number.isInteger(n) && n <= Number.MAX_SAFE_INTEGER)
148
+ return String(n);
149
+ const fixed = n.toFixed(6);
150
+ return fixed.includes('.') ? fixed.replace(/0+$/, '').replace(/\.$/, '') : fixed;
151
+ }
152
+ const addBound = (a, b) => (a !== null && b !== null ? addDecimal(a, b) : null);
153
+ /**
154
+ * Attribute one day of raw usage through the directory (#3316). Pure: the rows it returns are what
155
+ * `recordCostDayRows` writes. Rows that land on one key are summed, their intervals too. A figure
156
+ * of zero writes no row: a read day with no row for a dimension had none of it.
157
+ */
158
+ export function attributeCostDay(usage, dir) {
159
+ const byKey = new Map();
160
+ const add = (row, dimension, value, interval) => {
161
+ if (value === 0)
162
+ return;
163
+ const quantity = decimalOf(value);
164
+ const sampled = interval?.lower !== undefined && interval.upper !== undefined;
165
+ const lower = sampled ? decimalOf(Math.max(0, interval.lower)) : null;
166
+ const upper = sampled ? decimalOf(Math.max(0, interval.upper)) : null;
167
+ const key = [row.script, row.scopeId ?? '', row.objectClass ?? '', row.objectId ?? '', dimension].join('\u0000');
168
+ const prior = byKey.get(key);
169
+ if (prior) {
170
+ byKey.set(key, { ...prior, quantity: addDecimal(prior.quantity, quantity), lower: addBound(prior.lower, lower), upper: addBound(prior.upper, upper) });
171
+ }
172
+ else {
173
+ byKey.set(key, { day: usage.day, ...row, dimension, quantity, lower, upper });
174
+ }
175
+ };
176
+ const scriptRow = (script, objectClass) => {
177
+ const info = scriptInfoOf(script, dir);
178
+ return {
179
+ script,
180
+ scopeId: null,
181
+ objectClass,
182
+ objectId: null,
183
+ attribution: info.attribution,
184
+ tenantId: info.tenantId,
185
+ vertical: info.vertical,
186
+ kind: info.kind,
187
+ versionId: info.versionId,
188
+ previewTag: null,
189
+ };
190
+ };
191
+ // Namespace → script and class: Cloudflare's list first, the day's invocations for a namespace
192
+ // the list no longer holds (a reaped per-version script's).
193
+ const namespaces = new Map();
194
+ for (const n of usage.namespaces)
195
+ namespaces.set(n.id, { script: n.script, objectClass: n.class });
196
+ for (const i of usage.doInvocations) {
197
+ const known = namespaces.get(i.namespaceId);
198
+ if (!known)
199
+ namespaces.set(i.namespaceId, { script: i.script, objectClass: null });
200
+ else if (known.script === null)
201
+ namespaces.set(i.namespaceId, { ...known, script: i.script });
202
+ }
203
+ for (const w of usage.workers)
204
+ add(scriptRow(w.script, null), 'worker_cpu_us', w.cpuTimeUs, w);
205
+ for (const i of usage.doInvocations) {
206
+ add(scriptRow(i.script, namespaces.get(i.namespaceId)?.objectClass ?? null), 'do_requests', i.requests, i);
207
+ }
208
+ for (const o of usage.doObjects) {
209
+ const ns = namespaces.get(o.namespaceId);
210
+ const scope = dir.objects.get(o.objectId);
211
+ let row;
212
+ if (scope) {
213
+ row = {
214
+ script: ns?.script ?? scope.script,
215
+ scopeId: scope.scopeId,
216
+ objectClass: ns?.objectClass ?? null,
217
+ objectId: o.objectId,
218
+ attribution: 'scope',
219
+ tenantId: scope.tenantId,
220
+ vertical: scope.vertical,
221
+ kind: scope.kind,
222
+ versionId: scope.versionId,
223
+ previewTag: scope.previewTag,
224
+ };
225
+ }
226
+ else {
227
+ // An object the directory recorded for no scope is reported apart: its script's vertical is a
228
+ // fact, whose it is is not, so it carries no tenant. Its id stays, for when it is recorded.
229
+ const base = scriptRow(ns?.script ?? '', ns?.objectClass ?? null);
230
+ row = { ...base, objectId: o.objectId, attribution: base.attribution === 'script' ? 'unmapped' : base.attribution, tenantId: null };
231
+ }
232
+ add(row, 'do_rows_read', o.rowsRead);
233
+ add(row, 'do_rows_written', o.rowsWritten);
234
+ add(row, 'do_storage_write_units', o.storageWriteUnits);
235
+ add(row, 'do_duration_gb_s', o.duration);
236
+ }
237
+ return [...byKey.values()];
238
+ }
239
+ /**
240
+ * The directory as attribution reads it for `day`: every recorded object, every vertical and
241
+ * version, who owned each slug that day, and which scripts hold live scopes' data. Whole tables,
242
+ * never an `IN` list, so no statement nears a Durable Object's parameter limit.
243
+ */
244
+ export function readCostDirectory(sql, day) {
245
+ const start = `${assertUtcDay('day', day)}T00:00:00.000Z`;
246
+ const end = new Date(Date.parse(start) + 86_400_000).toISOString();
247
+ const objects = new Map();
248
+ for (const r of sql(`SELECT object_id, scope_id, tenant_id, script, vertical, kind, version_id, preview_tag FROM _substrat_scope_objects`, [])) {
249
+ objects.set(r.object_id, {
250
+ scopeId: r.scope_id,
251
+ tenantId: r.tenant_id,
252
+ script: r.script,
253
+ vertical: r.vertical,
254
+ kind: r.kind === 'preview' ? 'preview' : 'live',
255
+ versionId: r.version_id,
256
+ previewTag: r.preview_tag,
257
+ });
258
+ }
259
+ const slugByScript = new Map();
260
+ for (const v of sql('SELECT slug, serving_ref FROM verticals', [])) {
261
+ const stem = verticalScriptStem(v.slug);
262
+ for (const name of [stem, `${stem}-eu`, `${stem}-us`])
263
+ slugByScript.set(name, v.slug);
264
+ if (v.serving_ref)
265
+ slugByScript.set(v.serving_ref, v.slug);
266
+ }
267
+ const versionByScript = new Map();
268
+ const versionById = new Map();
269
+ for (const v of sql('SELECT id, vertical_slug, deployment_ref FROM vertical_versions', [])) {
270
+ const version = { slug: v.vertical_slug, versionId: v.id };
271
+ versionById.set(v.id.toUpperCase(), version);
272
+ if (v.deployment_ref && !slugByScript.has(v.deployment_ref))
273
+ versionByScript.set(v.deployment_ref, version);
274
+ }
275
+ // Each slug's owner on the day: the latest period that overlaps it.
276
+ const ownerBySlug = new Map();
277
+ for (const o of sql(`SELECT slug, owner FROM _substrat_vertical_owners
278
+ WHERE since < ? AND (until IS NULL OR until > ?) ORDER BY since`, [end, start])) {
279
+ ownerBySlug.set(o.slug, o.owner);
280
+ }
281
+ // A slug with no period (a directory older than the history) falls back to who owns it now.
282
+ for (const v of sql('SELECT slug, owner_tenant FROM verticals', [])) {
283
+ if (!ownerBySlug.has(v.slug))
284
+ ownerBySlug.set(v.slug, v.owner_tenant);
285
+ }
286
+ const liveScripts = new Set();
287
+ for (const r of sql(`SELECT DISTINCT COALESCE(s.serving_ref, vv.deployment_ref) AS script
288
+ FROM scopes s LEFT JOIN vertical_versions vv ON vv.id = s.vertical_version_id
289
+ WHERE COALESCE(s.kind, '') <> 'preview'`, [])) {
290
+ if (r.script)
291
+ liveScripts.add(r.script);
292
+ }
293
+ for (const r of sql('SELECT DISTINCT script FROM _substrat_scope_objects WHERE kind = ?', ['live'])) {
294
+ liveScripts.add(r.script);
295
+ }
296
+ return { objects, slugByScript, versionByScript, versionById, ownerBySlug, liveScripts };
297
+ }
298
+ // -- the day ledger -----------------------------------------------------------
299
+ /**
300
+ * Record one attempt. A successful read is attributed through the directory, replaces the day's
301
+ * rows in the caller's transaction, and marks the day read. A failed one records only the attempt:
302
+ * the day's rows and its last successful read stay as they were. The raw day is parsed, and every
303
+ * row it attributes to, before anything is written. Returns how many rows were written.
304
+ */
305
+ export function recordCostDayRows(sql, input) {
306
+ const day = assertUtcDay('day', input.day);
307
+ const attemptedAt = new Date(input.attemptedAt).toISOString();
308
+ if ('error' in input) {
309
+ const count = input.failingCount ?? 1;
310
+ if (!(Number.isInteger(count) && count >= 1)) {
311
+ throw new Error(`failingCount must be a whole number, at least one, got ${String(count)}`);
312
+ }
313
+ sql(`INSERT INTO _substrat_cost_day_reads (day, attempted_at, read_at, row_count, error, failing_since, failing_count)
314
+ VALUES (?, ?, NULL, NULL, ?, ?, ?)
315
+ ON CONFLICT (day) DO UPDATE SET
316
+ attempted_at = excluded.attempted_at, error = excluded.error,
317
+ failing_since = excluded.failing_since, failing_count = excluded.failing_count`, [day, attemptedAt, input.error || 'the read failed', new Date(input.failingSince ?? attemptedAt).toISOString(), count]);
318
+ return 0;
319
+ }
320
+ const usage = cloudflareUsageDay.parse(input.usage);
321
+ if (usage.day !== day)
322
+ throw new Error(`the usage is for ${usage.day}, not ${day}`);
323
+ const rows = attributeCostDay(usage, readCostDirectory(sql, day)).map((r) => costDay.parse(r));
324
+ sql('DELETE FROM _substrat_cost_days WHERE day = ?', [day]);
325
+ for (const r of rows) {
326
+ sql(`INSERT INTO _substrat_cost_days
327
+ (day, script, scope_id, object_class, object_id, dimension, attribution, tenant_id, vertical, kind, version_id, preview_tag, quantity, lower, upper)
328
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
329
+ day,
330
+ r.script,
331
+ r.scopeId ?? '',
332
+ r.objectClass ?? '',
333
+ r.objectId ?? '',
334
+ r.dimension,
335
+ r.attribution,
336
+ r.tenantId,
337
+ r.vertical,
338
+ r.kind,
339
+ r.versionId,
340
+ r.previewTag,
341
+ r.quantity,
342
+ r.lower,
343
+ r.upper,
344
+ ]);
345
+ }
346
+ sql(`INSERT INTO _substrat_cost_day_reads (day, attempted_at, read_at, row_count, error, failing_since, failing_count)
347
+ VALUES (?, ?, ?, ?, NULL, NULL, NULL)
348
+ ON CONFLICT (day) DO UPDATE SET
349
+ attempted_at = excluded.attempted_at, read_at = excluded.read_at, row_count = excluded.row_count,
350
+ error = NULL, failing_since = NULL, failing_count = NULL`, [day, attemptedAt, attemptedAt, rows.length]);
351
+ return rows.length;
352
+ }
353
+ /** Read stored cost rows — see `CostDayFilter`. Every row is parsed on the way out. */
354
+ export function listCostDayRows(sql, filter = {}) {
355
+ const where = [];
356
+ const params = [];
357
+ for (const [column, value] of [
358
+ ['tenant_id', filter.tenantId],
359
+ ['scope_id', filter.scopeId],
360
+ ['vertical', filter.vertical],
361
+ ['attribution', filter.attribution],
362
+ ]) {
363
+ if (value === undefined)
364
+ continue;
365
+ where.push(`${column} = ?`);
366
+ params.push(value);
367
+ }
368
+ pushDayWindow(filter, where, params);
369
+ params.push(Math.min(assertRowLimit('limit', filter.limit ?? COST_ROLLUP_LIMIT_DEFAULT), COST_ROLLUP_LIMIT_MAX));
370
+ const rows = sql(`SELECT day, script, scope_id, object_class, object_id, dimension, attribution, tenant_id, vertical, kind, version_id, preview_tag, quantity, lower, upper
371
+ FROM _substrat_cost_days
372
+ ${where.length ? `WHERE ${where.join(' AND ')}` : ''}
373
+ ORDER BY day, script, scope_id, object_class, object_id, dimension LIMIT ?`, params);
374
+ return rows.map((r) => costDay.parse({
375
+ day: r.day,
376
+ script: r.script,
377
+ scopeId: r.scope_id === '' ? null : r.scope_id,
378
+ objectClass: r.object_class === '' ? null : r.object_class,
379
+ objectId: r.object_id === '' ? null : r.object_id,
380
+ dimension: r.dimension,
381
+ attribution: r.attribution,
382
+ tenantId: r.tenant_id,
383
+ vertical: r.vertical,
384
+ kind: r.kind,
385
+ versionId: r.version_id,
386
+ previewTag: r.preview_tag,
387
+ quantity: r.quantity,
388
+ lower: r.lower,
389
+ upper: r.upper,
390
+ }));
391
+ }
392
+ /** The rollup's record of each day it tried, in day order, in the request rollup's shape (never saturated). */
393
+ export function listCostRollupDayRows(sql, filter = {}) {
394
+ const where = [];
395
+ const params = [];
396
+ pushDayWindow(filter, where, params);
397
+ const rows = sql(`SELECT day, attempted_at, read_at, row_count, error, failing_since, failing_count
398
+ FROM _substrat_cost_day_reads
399
+ ${where.length ? `WHERE ${where.join(' AND ')}` : ''}
400
+ ORDER BY day`, params);
401
+ return rows.map((r) => requestRollupDay.parse({
402
+ day: r.day,
403
+ attemptedAt: r.attempted_at,
404
+ readAt: r.read_at,
405
+ rows: r.row_count,
406
+ error: r.error,
407
+ saturated: false,
408
+ failingSince: r.failing_since,
409
+ failingCount: r.failing_count,
410
+ }));
411
+ }
412
+ /** Delete at most `limit` cost rows past a retention of `months`, as `pruneRequestDayRows` does. */
413
+ export function pruneCostDayRows(sql, nowMs, limit, months) {
414
+ return pruneBillingDays(sql, { rows: '_substrat_cost_days', records: '_substrat_cost_day_reads' }, nowMs, limit, months);
415
+ }
416
+ const OBJECT_ID = /^[0-9a-f]{64}$/;
417
+ /**
418
+ * The scopes whose object id is due, newest first (a preview fork is short-lived and the costliest
419
+ * thing to lose): every scope with a vertical and a data script that has no object recorded for
420
+ * that script, and no failed attempt within `retryMs`. A scope whose data moved to another script
421
+ * is due again, because the new script holds a new object.
422
+ */
423
+ export function scopeObjectsDueRows(sql, input) {
424
+ const retryBefore = new Date(input.nowMs - input.retryMs).toISOString();
425
+ const rows = sql(`SELECT t.* FROM (
426
+ SELECT s.scope_id, s.tenant_id, s.vertical, s.kind, s.slug, s.vertical_version_id, s.serving_ref, s.created_at,
427
+ COALESCE(s.serving_ref, vv.deployment_ref) AS script
428
+ FROM scopes s LEFT JOIN vertical_versions vv ON vv.id = s.vertical_version_id
429
+ WHERE s.vertical IS NOT NULL) t
430
+ WHERE t.script IS NOT NULL
431
+ AND NOT EXISTS (SELECT 1 FROM _substrat_scope_objects o WHERE o.scope_id = t.scope_id AND o.script = t.script)
432
+ AND NOT EXISTS (SELECT 1 FROM _substrat_scope_object_reads r
433
+ WHERE r.scope_id = t.scope_id AND r.script = t.script AND r.attempted_at > ?)
434
+ ORDER BY t.created_at DESC, t.scope_id LIMIT ?`, [retryBefore, assertRowLimit('limit', input.limit)]);
435
+ return rows.map((r) => {
436
+ const preview = r.kind === 'preview';
437
+ return {
438
+ tenantId: r.tenant_id,
439
+ scopeId: r.scope_id,
440
+ script: r.script,
441
+ vertical: r.vertical,
442
+ kind: preview ? 'preview' : 'live',
443
+ versionId: preview || r.serving_ref === null ? r.vertical_version_id : null,
444
+ previewTag: preview ? (r.slug?.split('--').at(-1) || null) : null,
445
+ };
446
+ });
447
+ }
448
+ /**
449
+ * Record one target's answer. An object id replaces whatever the id was recorded as before (the
450
+ * same id is the same object), clears the target's failed attempt, and attributes every cost row
451
+ * already stored for that object that named no scope, so a day read before the id was known is not
452
+ * left without its tenant. A failure records only the attempt, so the target waits `retryMs`. An id
453
+ * that is not Cloudflare's 64-hex shape is refused.
454
+ */
455
+ export function recordScopeObjectRow(sql, input) {
456
+ const attemptedAt = new Date(input.attemptedAt).toISOString();
457
+ if ('error' in input) {
458
+ sql(`INSERT INTO _substrat_scope_object_reads (scope_id, script, attempted_at, error) VALUES (?, ?, ?, ?)
459
+ ON CONFLICT (scope_id, script) DO UPDATE SET attempted_at = excluded.attempted_at, error = excluded.error`, [input.scopeId, input.script, attemptedAt, input.error || 'the read failed']);
460
+ return;
461
+ }
462
+ if (!OBJECT_ID.test(input.objectId)) {
463
+ throw new Error(`a Durable Object id is 64 lowercase hex characters, got ${JSON.stringify(input.objectId)}`);
464
+ }
465
+ sql(`INSERT INTO _substrat_scope_objects (object_id, scope_id, tenant_id, script, vertical, kind, version_id, preview_tag, recorded_at)
466
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
467
+ ON CONFLICT (object_id) DO UPDATE SET
468
+ scope_id = excluded.scope_id, tenant_id = excluded.tenant_id, script = excluded.script, vertical = excluded.vertical,
469
+ kind = excluded.kind, version_id = excluded.version_id, preview_tag = excluded.preview_tag, recorded_at = excluded.recorded_at`, [input.objectId, input.scopeId, input.tenantId, input.script, input.vertical, input.kind, input.versionId, input.previewTag, attemptedAt]);
470
+ sql('DELETE FROM _substrat_scope_object_reads WHERE scope_id = ? AND script = ?', [input.scopeId, input.script]);
471
+ sql(`UPDATE _substrat_cost_days
472
+ SET attribution = 'scope', scope_id = ?, tenant_id = ?, vertical = ?, kind = ?, version_id = ?, preview_tag = ?
473
+ WHERE object_id = ? AND attribution IN ('unmapped', 'unknown')`, [input.scopeId, input.tenantId, input.vertical, input.kind, input.versionId, input.previewTag, input.objectId]);
474
+ }
475
+ //# sourceMappingURL=cost-rollup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-rollup.js","sourceRoot":"","sources":["../src/cost-rollup.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,gBAAgB,EAChB,kBAAkB,GAQnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiD9B,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,iHAAiH;AACjH,MAAM,CAAC,MAAM,6BAA6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,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAC1I,CAAC;IACF,GAAG,CAAC,4EAA4E,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACjH,GAAG,CACD;;qEAEiE,EACjE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAC/G,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -72,12 +72,13 @@ export type { ComposedListQuery, ListDeclaration, ListIndexPlan, ListQueryParams
72
72
  export { moduleMigrations } from './module-migrations.js';
73
73
  export { REGISTERED_MIGRATIONS, registeredMigrationsOf, type RegisteredMigration } from './registered-migrations.js';
74
74
  export { MIGRATION_DIGEST_FENCE_DDL, MIGRATION_DIGEST_MARK_LEGACY, MIGRATIONS_DIGEST_BINDING, assertJournalDumpCoherent, assertMigrationSql, isDerivedMigrationVersion, migrationDigest, migrationDivergence, migrationFailedError, migrationSetDigest, migrationSetDivergence, migrationSteps, planMigrations, type MigrationPlan, type MigrationStep, type PendingMigration, } from './migration-digest.js';
75
+ export { SCOPE_WORK_BINDING, SCOPE_WORK_KIND_BINDING, SCOPE_WORK_VERTICAL_BINDING, type ScopeWorkScriptKind, } from './scope-work-bindings.js';
75
76
  export { canonicalInstant, frozenClock, manualClock } from './clock.js';
76
77
  export type { ManualClock } from './clock.js';
77
78
  export { createUlid, ulid, ulidTime, type UlidMint } from './ulid.js';
78
79
  export { personaPrincipal, seatWorld, seatWorldWith, type SeatWorldInput, type SeatWorldOptions, type SeedWorld, type WorldBuilder, type WorldPersona, type WorldSeat, type WorldSeating, } from './seed-world.js';
79
80
  export { assertReadOnlyQuery } from './read-only-sql.js';
80
- export { guardSpine } from './spine-guard.js';
81
+ export { guardSpine, piecesReproduce } from './spine-guard.js';
81
82
  export { DO_SQL_LIMITS, tooManyResultColumns, tooManyTableColumns, guardSqlLimits, } from './sql-limits.js';
82
83
  export { assertPermissionKey } from './check-key.js';
83
84
  export { assertModuleEnqueueableKind } from './platform-kinds.js';
@@ -88,6 +89,7 @@ export { assertPlatformRequestRoom } from './platform-request-cap.js';
88
89
  export { CANCELLED_JOB_NOTE, DELIVERY_ERROR_REDACTION_SQL, intentPayloadCarriesSubject, PLATFORM_REQUEST_REDACTION_SQL, platformRequestRedactionParams, platformRequestRedactionQuery, REDACTED_DELIVERY_NOTE, REDACTED_INTENT_MARKER, REDACTED_JOB_NOTE, redactSubjectJobRuns, REDACTED_FAILURE_NOTE, redactSubjectScopeText, ISSUE_EXEMPLAR_OWNER_BACKFILL_SQL, issueExemplarOwner, redactSubjectDirectoryText, platformIntentFailureMessage, } from './subject-redaction.js';
89
90
  export type { LegacySubjectRedactionCounts, PlatformRequestRedactionCandidate, RedactionSql, SubjectRedactionCounts, SubjectTextTarget, IssueExemplarOwner, } from './subject-redaction.js';
90
91
  export { eraseSubjectFromModules, isModuleErasureCounts, moduleErasurePlan, moduleRowsErased, SECURE_DELETE_MIN_SQLITE, } from './module-erasure.js';
92
+ export { readSubjectPage } from './subject-access.js';
91
93
  export { TABLE_OWNERS_DDL, assertMigrationLeavesLedgerAlone, recordOwnershipSteps, runMigrationStatements, } from './table-ownership.js';
92
94
  export type { OwnerStore, TableChange, TableStatement, TableStep } from './table-ownership.js';
93
95
  export { blankSqlComments, executableSqlStatements, splitSqlStatements } from './sql-statements.js';
@@ -142,11 +144,12 @@ export { IDEMPOTENCY_DDL, assertIdempotencyKey, idempotencyLookupQuery, idempote
142
144
  export { JOB_RUN_DDL, JOB_RUN_PATCH_SQL, JOB_RUN_CLAIM_SQL, JOB_RUN_RENEW_SQL, JOB_RUN_BEGIN_SQL, JOB_RUN_MISS_SQL, JOB_RUN_MISS_SETTLE_SQL, admissionMissOutcome, JOB_STEP_RECORD_SQL, JOB_LEASE_MS, JOB_LEASE_MIN_MS, JOB_ADMISSION_MISS_MAX, JOB_LEASE_TOO_SHORT_NOTE, admissionBackoffMs, JOB_LEASE_EXPIRED_NOTE, assertLeaseMs, jobRunListLimit, SYSTEM_DOOR_WAIT, JOB_DEFER_MS, JOB_RUN_DUE_AT, jobRunOf, runDueJobRuns, runJobPass, startJobRun, } from './job-run.js';
143
145
  export type { JobDueKey, JobDriveReport, JobHandler, JobPassContext, JobPassOutcome, JobPassResult, JobRun, JobRegistration, JobRunClaim, JobRunFilter, JobRunKey, JobRunPatch, JobRunRow, JobRunStatus, JobRunStore, JobStepRow, StartJobRunInput, } from './job-run.js';
144
146
  export { runPlatformSweep, UNREADABLE_SCOPE_ROWS_NAMED, startPlatformSweeper, StorageReadUnsupported, ScopeNotHeld, PROVISION_RECONCILE_BATCH, CROSS_VERTICAL_CONSUMERS_PER_PASS, ORPHAN_ATTACHMENT_SWEEP_BATCH, ORPHAN_SWEEP_DRY_RUN_WINDOW_MS, runCrossVerticalFrom, registryImportCandidates, crossVerticalHealth, NO_BINDING, } from './platform-sweep.js';
145
- export type { ConnectionBinder, ConnectionLandingOptionsInput, LandingOutcome } from './connection-landings.js';
146
- export { binderOf, onRequestLandingFor } from './connection-landings.js';
147
+ export { PRE_PROMOTE_SNAPSHOT_TTL_MS, prePromoteSnapshotExpiresAt } from './snapshot-retention.js';
148
+ export type { ConnectionBinder, ConnectionLandingOptionsInput, DeclaredLanding, ExclusiveLandings, LandingOutcome } from './connection-landings.js';
149
+ export { binderOf, declaredLandingFor, exclusiveLandingsOf, onRequestLandingFor } from './connection-landings.js';
147
150
  export { SCHEDULE_STATE_DDL, SCHEDULE_STATE_REBUILD, scheduleStateHasKind } from './schedule-state.js';
148
151
  export type { ScheduleSweepReport, ScheduleStateKind } from './schedule-state.js';
149
- export type { AccessLogSink, EventSink, EventDrainReport, EventDrainSkipped, PlatformRequestUnsettleable, AccessLogSweepReport, ConnectorSweeper, ConnectorSweepAnswer, MigrationSweepReport, PlatformSweepOptions, PlatformSweepReport, PlatformSweeperHandle, StartPlatformSweeperOptions, StorageGaugeSweepOptions, StorageGaugeSweepReport, RequestRollupSweepOptions, RequestRollupSweepReport, MeterSnapshotSweepOptions, MeterSnapshotSweepReport, FailingRun, CandidatesHint, CrossVerticalEdge, CrossVerticalOptions, CrossVerticalReach, CrossVerticalReport, ProvisionReconcileReport, OrphanAttachmentOutcome, OrphanAttachmentSweepOptions, OrphanAttachmentSweepReport, } from './platform-sweep.js';
152
+ export type { AccessLogSink, EventSink, EventDrainReport, EventDrainSkipped, PlatformRequestUnsettleable, AccessLogSweepReport, ConnectorSweeper, ConnectorSweepAnswer, MigrationSweepReport, PlatformSweepOptions, PlatformSweepReport, PlatformSweeperHandle, StartPlatformSweeperOptions, StorageGaugeSweepOptions, StorageGaugeSweepReport, RequestRollupSweepOptions, RequestRollupSweepReport, CostRollupSweepOptions, CostRollupSweepReport, ScopeObjectsSweepOptions, ScopeObjectsSweepReport, MeterSnapshotSweepOptions, MeterSnapshotSweepReport, FailingRun, CandidatesHint, CrossVerticalEdge, CrossVerticalOptions, CrossVerticalReach, CrossVerticalReport, ProvisionReconcileReport, OrphanAttachmentOutcome, OrphanAttachmentSweepOptions, OrphanAttachmentSweepReport, } from './platform-sweep.js';
150
153
  export { isPrimaryScope, isPrimaryScopeRow, INERT_SCOPE_REASON, runningVersionOf } from './scope-identity.js';
151
154
  export type { ServingPointer } from './scope-identity.js';
152
155
  export { opsFailureReferenceWhere, withheldOpsFailure, withheldStaffFailure } from './ops-failure-reference.js';
@@ -159,11 +162,13 @@ export { migrationProgress, } from './migration-progress.js';
159
162
  export type { ScopeMigrationState } from './migration-progress.js';
160
163
  export { foldMeterReading } from './meters.js';
161
164
  export { MODEL_USAGE_RETENTION_DAYS, foldModelUsage, type ModelUsageFilter, type ModelUsageInput, type ModelUsageWindow, type ModelUsagePricing, type TenantModelUsageMeterFilter, type TenantModelUsageMeterRow, } from './model-usage.js';
165
+ export { MARKUP_INSERT_SQL, MARKUP_SELECT_FOR_TENANT_SQL, MARKUP_SELECT_SQL, markupRecordValues, markupScheduleOf, newMarkupRow, type MarkupScheduleRecord, } from './markup-schedule.js';
162
166
  export { BUILD_USAGE_RETENTION_DAYS, type BuildUsageInput, type TenantBuildUsageFilter, type TenantBuildUsageRow, } from './build-usage.js';
163
167
  export type { MeterEntitlementInput, MeterInput, MeterScopeInput, MeterTenantInput, } from './meters.js';
164
168
  export { ATTACHMENT_BYTES_SQL, SCOPE_STORAGE_DDL, STORAGE_GAUGE_RETENTION_MONTHS, forgetScopeStorage, listScopeAttachmentStorageRows, retireScopeStorage, listScopeStorageAttemptRows, listScopeStorageRows, listScopeStoreStorageRows, pruneScopeStorageRows, readBoundedTenantStorageGauge, recordScopeStorageRows, type ScopeStorageAttempt, type ScopeStorageFilter, type ScopeStorageReadingInput, STORAGE_HISTORY_LIMIT_MAX, } from './storage-gauge.js';
165
169
  export { BILLING_ROLLUP_RETENTION_MONTHS } from './billing-retention.js';
166
170
  export { REQUEST_ROLLUP_DDL, REQUEST_ROLLUP_LIMIT_DEFAULT, REQUEST_ROLLUP_LIMIT_MAX, RequestRollupSaturated, listRequestDayRows, listRequestRollupDayRows, pruneRequestDayRows, recordRequestDayRows, readRequestMeterDayRows, readTenantRequestMeterRows, type RequestDayCount, type RequestDayFilter, type RequestDayReadInput, type RequestRollupDayFilter, type RequestMeterDayRow, type TenantRequestMeterRow, } from './request-rollup.js';
171
+ export { COST_ROLLUP_DDL, COST_ROLLUP_LIMIT_DEFAULT, COST_ROLLUP_LIMIT_MAX, attributeCostDay, listCostDayRows, listCostRollupDayRows, pruneCostDayRows, readCostDirectory, recordCostDayRows, recordScopeObjectRow, scopeObjectsDueRows, type CostDayFilter, type CostDayReadInput, type CostDirectory, type CostRollupDayFilter, type ScopeObjectReadInput, type ScopeObjectRecord, type ScopeObjectTarget, } from './cost-rollup.js';
167
172
  export { VERTICAL_OWNERS_BACKFILL, VERTICAL_OWNERS_DDL, closeVerticalOwnerRow, listVerticalOwnerRows, openVerticalOwnerRow, verticalOwnerNow, } from './vertical-owners.js';
168
173
  export { METER_DAYS_DDL, METER_DAYS_LIMIT_DEFAULT, METER_DAYS_LIMIT_MAX, listMeterDayRows, listMeterDayTakeRows, pruneMeterDayRows, recordMeterDayRows, type MeterDayFilter, type MeterDayTakeFilter, type MeterDayTakeInput, type MeterDayTakeResult, } from './meter-days.js';
169
174
  export { moduleLog, consoleLogSink, } from './module-log.js';