@fabrika/auth-core 0.9.0-dev.1 → 0.9.0-dev.11

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 (44) hide show
  1. package/package.json +4 -3
  2. package/src/contract-canonical.ts +1 -0
  3. package/src/contract.ts +6 -0
  4. package/src/dev-environment.ts +6 -0
  5. package/src/framework-release.ts +2 -0
  6. package/src/framework-variables.ts +9 -0
  7. package/src/index.ts +4 -0
  8. package/src/managed-environment.ts +136 -0
  9. package/src/ops.ts +1933 -0
  10. package/src/rpc.ts +8 -8
  11. package/src/terminal.ts +105 -0
  12. package/src/token.ts +73 -13
  13. package/src/types.ts +5 -2
  14. package/src/wire.ts +6 -0
  15. package/types/src/app-environment.d.ts +24 -0
  16. package/types/src/canonical-path.d.ts +20 -0
  17. package/types/src/contract-canonical.d.ts +19 -0
  18. package/types/src/contract.d.ts +800 -0
  19. package/types/src/dev-environment.d.ts +37 -0
  20. package/types/src/device.d.ts +144 -0
  21. package/types/src/endpoint-digest.d.ts +58 -0
  22. package/types/src/endpoints.d.ts +65 -0
  23. package/types/src/environment.d.ts +58 -0
  24. package/types/src/framework-release.d.ts +2 -0
  25. package/types/src/framework-variables.d.ts +86 -0
  26. package/types/src/index.d.ts +28 -0
  27. package/types/src/installation-endpoint.d.ts +46 -0
  28. package/types/src/json.d.ts +13 -0
  29. package/types/src/locale.d.ts +14 -0
  30. package/types/src/mail.d.ts +67 -0
  31. package/types/src/managed-environment.d.ts +32 -0
  32. package/types/src/membership.d.ts +318 -0
  33. package/types/src/oauth.d.ts +7 -0
  34. package/types/src/ops.d.ts +657 -0
  35. package/types/src/path-segment.d.ts +5 -0
  36. package/types/src/permissions.d.ts +50 -0
  37. package/types/src/requirement.d.ts +24 -0
  38. package/types/src/rpc.d.ts +283 -0
  39. package/types/src/sha256.d.ts +2 -0
  40. package/types/src/terminal.d.ts +72 -0
  41. package/types/src/token.d.ts +240 -0
  42. package/types/src/types.d.ts +196 -0
  43. package/types/src/wire.d.ts +65 -0
  44. package/types/src/workloads.d.ts +25 -0
@@ -0,0 +1,657 @@
1
+ /** Every ops request's path lies under this prefix, on the environment's own domain. */
2
+ export declare const OPS_PREFIX = "/__fabrika/ops/";
3
+ /**
4
+ * The fixed id of the composed row. An authored endpoint id starts with a letter, so no contract can take it. The row's
5
+ * digest is not a constant: proxy-core computes it where every row is digested, from these fields.
6
+ */
7
+ export declare const OPS_ROW_ID = "__fabrika.ops";
8
+ /** The composed row's path. */
9
+ export declare const OPS_ROW_PATH = "/__fabrika/ops/*";
10
+ /** The composed row's method. */
11
+ export declare const OPS_METHOD = "POST";
12
+ /** The one content type the composed row admits. */
13
+ export declare const OPS_CONTENT_TYPE = "application/json";
14
+ /** The operations the object serves, each at `opsPath(operation)`. */
15
+ export declare const OPS_OPERATIONS: readonly ["inspect", "state", "migrate", "export", "import", "restore", "timers"];
16
+ export type OpsOperation = (typeof OPS_OPERATIONS)[number];
17
+ export declare function opsPath(operation: OpsOperation): string;
18
+ /** The operation a request path names, or `null` for any other path, which gets `opsRefusal()`. */
19
+ export declare function parseOpsOperation(path: string): OpsOperation | null;
20
+ /**
21
+ * The one answer inside the prefix to a missing or wrong key, a wrong endpoint header, an unknown operation and a
22
+ * refused object name: the same status, no body and no headers, so none of them tells the caller which it was.
23
+ */
24
+ export declare const OPS_REFUSAL_STATUS = 404;
25
+ export declare function opsRefusal(): Response;
26
+ /** Ops key digests: `sha256:<64 hex>` of each key, joined by `,`; one, or two while a rotation reconciles. */
27
+ export type OpsKeyDigests = readonly [string] | readonly [string, string];
28
+ /** The digest of an ops key, the only form the object holds (`FABRIKA_OPS_KEY_DIGESTS`). */
29
+ export declare function opsKeyDigest(key: string): string;
30
+ /** The value of `FABRIKA_OPS_KEY_DIGESTS`, or `null` unless it holds one or two distinct digests. */
31
+ export declare function parseOpsKeyDigests(value: string): OpsKeyDigests | null;
32
+ /** The value Control writes into `FABRIKA_OPS_KEY_DIGESTS`; throws on a list `parseOpsKeyDigests` would refuse. */
33
+ export declare function formatOpsKeyDigests(digests: OpsKeyDigests): string;
34
+ /** The object of ordinary traffic without `FABRIKA_APPLICATION_OBJECT`, and the only one an ops request may name then. */
35
+ export declare const DEFAULT_APPLICATION_OBJECT = "application";
36
+ /** The most names `FABRIKA_APPLICATION_OBJECTS` holds. */
37
+ export declare const MAX_APPLICATION_OBJECTS = 16;
38
+ export declare function parseApplicationObjectName(value: unknown): string | null;
39
+ /** The object of ordinary traffic, and the objects an ops request may name, which include it. */
40
+ export interface ApplicationObjects {
41
+ readonly object: string;
42
+ readonly objects: readonly string[];
43
+ }
44
+ /**
45
+ * `FABRIKA_APPLICATION_OBJECT` and `FABRIKA_APPLICATION_OBJECTS` (distinct names joined by `,`, 1 to 16, holding the
46
+ * first), or `null`. Without either the object is `application`; a deploy writes both, so one alone is refused.
47
+ */
48
+ export declare function parseApplicationObjects(object: string | undefined, objects: string | undefined): ApplicationObjects | null;
49
+ /** The R2 key, in the environment's bucket, of the maintenance state of `object`. */
50
+ export declare function OPS_STATE_KEY(object: string): string;
51
+ /** The maintenance modes, from the most permissive. */
52
+ export declare const OPS_MODES: readonly ["open", "read-only", "closed", "inspect"];
53
+ export type OpsMode = (typeof OPS_MODES)[number];
54
+ /** A table's row count is capped here: a full count bills every row read. A count at the cap means at least the cap. */
55
+ export declare const OPS_ROW_COUNT_CAP = 100000;
56
+ /** `POST /__fabrika/ops/inspect`: the projection, or with `content` the content-bearing view (`data.content.read`). */
57
+ export interface OpsInspectRequest {
58
+ readonly object: string;
59
+ readonly content: boolean;
60
+ }
61
+ /** `POST /__fabrika/ops/state`: a maintenance transition under a generation Control allocated. */
62
+ export interface OpsStateRequest {
63
+ readonly object: string;
64
+ readonly generation: number;
65
+ readonly mode: OpsMode;
66
+ }
67
+ /** Sent once the state is published and the drain is over; `stillRunning` counts what ran past the drain's bound. */
68
+ export interface OpsStateAck {
69
+ readonly generation: number;
70
+ readonly mode: OpsMode;
71
+ readonly stillRunning: number;
72
+ }
73
+ /** `POST /__fabrika/ops/migrate`: run the pending migrations under the published generation. */
74
+ export interface OpsMigrateRequest {
75
+ readonly object: string;
76
+ readonly generation: number;
77
+ }
78
+ /** The state a transition is judged against: the object's current generation and mode, `null` before the first. */
79
+ export interface OpsPublishedState {
80
+ readonly generation: number;
81
+ readonly mode: OpsMode;
82
+ }
83
+ /**
84
+ * Whether a transition is stale: a lower generation, or the same with another mode. The same generation and mode is a
85
+ * retry, which the object replays.
86
+ */
87
+ export declare function opsTransitionRefused(current: OpsPublishedState | null, request: OpsPublishedState): boolean;
88
+ /** The status of a stale refusal. It is answered only after authentication, so it may say what is published. */
89
+ export declare const OPS_STALE_STATUS = 409;
90
+ /** The body of a stale refusal of a transition or a migration. */
91
+ export interface OpsStaleRefusal {
92
+ readonly refused: 'stale_generation';
93
+ readonly published: OpsPublishedState | null;
94
+ }
95
+ /** One row of the object's migration ledger. */
96
+ export interface OpsMigration {
97
+ readonly bundle: string;
98
+ readonly name: string;
99
+ readonly checksum: string;
100
+ readonly appliedAt: string;
101
+ }
102
+ /** Sent once the migrations ran and the application booted, with the new ledger. */
103
+ export interface OpsMigrateAck {
104
+ readonly generation: number;
105
+ readonly migrations: readonly OpsMigration[];
106
+ }
107
+ export interface OpsMaintenance {
108
+ readonly mode: OpsMode;
109
+ /** `null` while no transition was ever published: the object is `open`. */
110
+ readonly generation: number | null;
111
+ /** Whether R2 holds this state; `false` while its put is pending. */
112
+ readonly published: boolean;
113
+ }
114
+ export interface OpsTableCount {
115
+ readonly name: string;
116
+ /** At most `OPS_ROW_COUNT_CAP`. */
117
+ readonly rows: number;
118
+ }
119
+ export interface OpsDatabase {
120
+ readonly sizeBytes: number;
121
+ readonly tables: readonly OpsTableCount[];
122
+ }
123
+ export interface OpsScheduler {
124
+ /** The current alarm, or `null` when none is set. */
125
+ readonly alarm: string | null;
126
+ }
127
+ /** A job's last run and its outcome: a contract job, or a framework job such as `fabrika-file-sweep`. */
128
+ export interface OpsJob {
129
+ readonly job: string;
130
+ readonly lastStatus: 'succeeded' | 'failed' | null;
131
+ readonly lastStartedAt: string | null;
132
+ readonly lastFinishedAt: string | null;
133
+ readonly lastDurationMs: number | null;
134
+ }
135
+ export type OpsFileStatus = 'pending' | 'quarantined' | 'live' | 'rejected';
136
+ export interface OpsFileCount {
137
+ readonly kind: string;
138
+ readonly status: OpsFileStatus;
139
+ readonly count: number;
140
+ }
141
+ /** A delivery is `claimed` while it holds a lease, `completed` once its handler's transaction cleared it. */
142
+ export interface OpsWebhookCount {
143
+ readonly webhook: string;
144
+ readonly state: 'claimed' | 'completed';
145
+ readonly count: number;
146
+ }
147
+ export interface OpsBootFailure {
148
+ readonly at: string;
149
+ }
150
+ /** The boot failure with the application's error text, which is content. */
151
+ export interface OpsBootFailureContent extends OpsBootFailure {
152
+ readonly message: string;
153
+ readonly stack: string | null;
154
+ }
155
+ /**
156
+ * The allowlisted projection (`data.read`): counts, sizes, timestamps, the identifiers the platform or the contract
157
+ * names, and status codes. Every timestamp is ISO 8601 in UTC with milliseconds.
158
+ */
159
+ export interface OpsView {
160
+ readonly release: string;
161
+ readonly maintenance: OpsMaintenance;
162
+ readonly database: OpsDatabase;
163
+ readonly migrations: readonly OpsMigration[];
164
+ readonly scheduler: OpsScheduler;
165
+ readonly jobs: readonly OpsJob[];
166
+ readonly files: readonly OpsFileCount[];
167
+ readonly webhooks: readonly OpsWebhookCount[];
168
+ readonly bootFailure: OpsBootFailure | null;
169
+ }
170
+ /** The view a `data.content.read` caller gets: the projection, with the application's error text. */
171
+ export interface OpsContentView extends Omit<OpsView, 'bootFailure'> {
172
+ readonly bootFailure: OpsBootFailureContent | null;
173
+ }
174
+ export declare function parseOpsInspectRequest(body: unknown): OpsInspectRequest | null;
175
+ export declare function parseOpsStateRequest(body: unknown): OpsStateRequest | null;
176
+ export declare function parseOpsStateAck(body: unknown): OpsStateAck | null;
177
+ export declare function parseOpsMigrateRequest(body: unknown): OpsMigrateRequest | null;
178
+ export declare function parseOpsStaleRefusal(body: unknown): OpsStaleRefusal | null;
179
+ export declare function parseOpsMigrateAck(body: unknown): OpsMigrateAck | null;
180
+ export declare function parseOpsView(body: unknown): OpsView | null;
181
+ export declare function parseOpsContentView(body: unknown): OpsContentView | null;
182
+ /** The version of the dump format: the value, row and line encodings, the table hash and the manifest. */
183
+ export declare const OPS_DUMP_FORMAT = 1;
184
+ /** The most rows one keyset page reads. */
185
+ export declare const OPS_DUMP_PAGE_ROWS = 1000;
186
+ /**
187
+ * The size of every part of a dump's data object but the last, which is at most this. R2 refuses a multipart upload
188
+ * whose parts differ in size, and a part below 5 MiB; a 2 MB row, its text and blobs as hex, fits one part uncompressed.
189
+ */
190
+ export declare const OPS_DUMP_PART_SIZE: number;
191
+ /**
192
+ * The most bytes one part decompresses to: its lines, each with its newline. An import step holds a part's every form
193
+ * at once (compressed, decompressed, the lines, the values, the bound bytes), so this bounds its memory well inside an
194
+ * isolate's 128 MB.
195
+ */
196
+ export declare const OPS_DUMP_PART_MAX_RAW_BYTES: number;
197
+ /** The most rows one part holds, which bounds the inserts, and the link updates, of one import step. */
198
+ export declare const OPS_DUMP_PART_MAX_ROWS = 50000;
199
+ /** R2's most parts in one multipart upload. */
200
+ export declare const OPS_DUMP_MAX_PARTS = 10000;
201
+ /** The largest manifest a reader accepts, in UTF-8 bytes. */
202
+ export declare const OPS_DUMP_MANIFEST_MAX_BYTES: number;
203
+ /** The object a scheduled backup is rehearsed in. Every deploy at a gated release lists it; nothing serves from it. */
204
+ export declare const OPS_REHEARSAL_OBJECT = "rehearsal";
205
+ /** A dump: the object it was taken from, the id Control gave it (a UUID), and whether it is a consistent backup. */
206
+ export interface OpsDumpRef {
207
+ readonly object: string;
208
+ readonly dump: string;
209
+ readonly consistent: boolean;
210
+ }
211
+ /** The R2 key of a dump's data or manifest: a consistent backup under `__fabrika/backups/`, a diagnostic export under `__fabrika/exports/`. */
212
+ export declare function OPS_DUMP_KEY(ref: OpsDumpRef, file: 'data' | 'manifest'): string;
213
+ /**
214
+ * One stored value, as `typeof()` names it. An integer travels as its decimal text, because workerd reads an int64 into
215
+ * a double; a real travels as the double workerd reads exactly. Text and a blob travel as the upper-case hex of their
216
+ * bytes, so text that is not valid UTF-8 keeps every byte.
217
+ */
218
+ export type OpsDumpValue = null | {
219
+ readonly type: 'integer';
220
+ readonly value: string;
221
+ } | {
222
+ readonly type: 'real';
223
+ readonly value: number;
224
+ } | {
225
+ readonly type: 'text';
226
+ readonly value: string;
227
+ } | {
228
+ readonly type: 'blob';
229
+ readonly value: string;
230
+ };
231
+ /**
232
+ * The two result columns a dump reads for `column`: `typeof()` and the value in the form `readOpsDumpValue` takes, an
233
+ * integer as `CAST(c AS TEXT)`, a real as itself, text as `hex(CAST(c AS BLOB))` and a blob as `hex(c)`.
234
+ */
235
+ export declare function opsDumpColumnProjection(column: string): string;
236
+ /** The value `opsDumpColumnProjection` read. Throws, naming no value, on a pair it would not produce. */
237
+ export declare function readOpsDumpValue(type: unknown, value: unknown): OpsDumpValue;
238
+ /**
239
+ * The most result columns, and the most parameters, one statement of workerd's SQLite takes; a table holds at most as
240
+ * many columns.
241
+ */
242
+ export declare const OPS_SQLITE_MAX_COLUMNS = 100;
243
+ /** The most columns of a table one statement of a page read projects: two result columns each, beside the rowid twice. */
244
+ export declare const OPS_DUMP_READ_COLUMNS: number;
245
+ /** One row of a keyset page: its rowid as decimal text, then the rowid and every column as the dump writes them. */
246
+ export interface OpsDumpPageRow {
247
+ readonly rowid: string;
248
+ readonly values: readonly OpsDumpValue[];
249
+ }
250
+ /** Runs one statement of a page read, with the parameters of the read's condition, and answers its rows. */
251
+ export type OpsDumpPageQuery = (sql: string) => readonly Readonly<Record<string, unknown>>[];
252
+ /**
253
+ * One keyset page of `table`: the first `limit` rows by rowid that `condition` (`WHERE …`, or empty) admits, read the
254
+ * way the producer and the importer's verification both read them. Each column reads as two result columns, so a table
255
+ * wider than `OPS_DUMP_READ_COLUMNS` reads in several statements over the same rows, which the caller runs in one
256
+ * synchronous turn, so no write falls between them. The common table expression names every result column, which an
257
+ * expression alone does not.
258
+ */
259
+ export declare function readOpsDumpPage(query: OpsDumpPageQuery, table: OpsDumpTablePlan, condition: string, limit: number): OpsDumpPageRow[];
260
+ /**
261
+ * The SQL that names a dump's rowid inline, so a row of a table at `OPS_SQLITE_MAX_COLUMNS` binds no more parameters
262
+ * than it has columns. It is the checked decimal text in a string literal, cast as `opsDumpValueBinding` casts it.
263
+ */
264
+ export declare function opsDumpRowidSql(rowid: OpsDumpValue): string;
265
+ /** What a statement binds for one value of a dump. */
266
+ export type OpsDumpParam = string | number | Uint8Array | null;
267
+ /** The SQL expression that writes a value back and the parameter its `?` binds. */
268
+ export interface OpsDumpBinding {
269
+ readonly sql: string;
270
+ readonly param: OpsDumpParam;
271
+ }
272
+ /**
273
+ * How the importer writes a value back, a rowid included, without a double or a JavaScript string in between: an
274
+ * integer as its decimal text through `CAST(? AS INTEGER)`, a real through `CAST(? AS REAL)` (a binder may bind an
275
+ * integral double as an integer), text as its bytes through `CAST(? AS TEXT)`, and a blob as its bytes.
276
+ */
277
+ export declare function opsDumpValueBinding(value: OpsDumpValue): OpsDumpBinding;
278
+ /**
279
+ * The canonical encoding of a row, the text a table hash is computed over: a JSON array (`JSON.stringify`, so no
280
+ * whitespace) of `null` or a tagged string per value, `i:<decimal>`, `r:<shortest round-trip double>`, `t:<HEX>` or
281
+ * `b:<HEX>`. A real keeps `-0`, `Infinity` and `-Infinity`; NaN is never stored. Throws, naming no value, on a value
282
+ * outside these rules.
283
+ */
284
+ export declare function encodeOpsDumpRow(values: readonly OpsDumpValue[]): string;
285
+ /** The values of a row's canonical encoding, or `null` for any other text, a different spelling of the same row included. */
286
+ export declare function decodeOpsDumpRow(text: string): readonly OpsDumpValue[] | null;
287
+ /** One line of a dump's NDJSON: a table's row, which is its rowid, then every column that is not generated. */
288
+ export interface OpsDumpLine {
289
+ readonly table: string;
290
+ readonly row: readonly OpsDumpValue[];
291
+ }
292
+ /** The line `{"table":"<name>","row":<canonical row>}`. Throws on a table name outside the data layer's identifier rule. */
293
+ export declare function encodeOpsDumpLine(line: OpsDumpLine): string;
294
+ /** A line, or `null` for anything `encodeOpsDumpLine` would not write. */
295
+ export declare function decodeOpsDumpLine(text: string): OpsDumpLine | null;
296
+ /** The hash of a table without rows: the SHA-256 of the empty string. */
297
+ export declare const OPS_EMPTY_TABLE_HASH: string;
298
+ /**
299
+ * Folds rows, each in its canonical encoding and in keyset order, into a table's hash. Each row's step is the SHA-256 of
300
+ * the previous hash's hex, a newline and the row, so a table read page by page, across steps, folds to one value.
301
+ */
302
+ export declare function foldOpsTableHash(hash: string, rows: Iterable<string>): string;
303
+ /** A column as `PRAGMA table_xinfo` describes it. */
304
+ export interface OpsDumpSchemaColumn {
305
+ readonly name: string;
306
+ /** The declared type, as written. */
307
+ readonly type: string;
308
+ readonly notNull: boolean;
309
+ /** The column's position in the primary key from 1, `0` outside it. */
310
+ readonly primaryKey: number;
311
+ /** A generated column (`hidden` 2 or 3), which a dump does not carry. */
312
+ readonly generated: boolean;
313
+ }
314
+ /** An index as `PRAGMA index_list` and `PRAGMA index_xinfo` (its key columns) describe it. */
315
+ export interface OpsDumpSchemaIndex {
316
+ readonly unique: boolean;
317
+ readonly origin: 'c' | 'u' | 'pk';
318
+ readonly partial: boolean;
319
+ /** The key columns in order, `null` for an expression. */
320
+ readonly columns: readonly (string | null)[];
321
+ }
322
+ /** A foreign key as `PRAGMA foreign_key_list` describes it, its rows grouped by `id` and ordered by `seq`. */
323
+ export interface OpsDumpSchemaForeignKey {
324
+ readonly parent: string;
325
+ readonly columns: readonly string[];
326
+ /** The parent's columns (`to`), or `null` when the key names the parent's primary key implicitly. */
327
+ readonly references: readonly string[] | null;
328
+ /**
329
+ * Whether the key is `DEFERRABLE INITIALLY DEFERRED`. No PRAGMA reports it: a reader takes it from the table's SQL,
330
+ * and one that cannot tell which key a clause belongs to marks every key of that table.
331
+ */
332
+ readonly initiallyDeferred: boolean;
333
+ }
334
+ /** A table as `PRAGMA table_list` (`type`, `wr`) and the PRAGMAs above describe it. */
335
+ export interface OpsDumpSchemaTable {
336
+ readonly name: string;
337
+ readonly virtual: boolean;
338
+ readonly withoutRowid: boolean;
339
+ /**
340
+ * Every name a `CHECK` constraint of the table's SQL reads, ASCII-lowercase and unquoted (keywords included), so a
341
+ * column it does not list cannot change what a `CHECK` answers. Empty for a table without one; `null` from a reader
342
+ * that cannot tell, which counts as naming every column.
343
+ */
344
+ readonly checkNames: readonly string[] | null;
345
+ readonly columns: readonly OpsDumpSchemaColumn[];
346
+ readonly indexes: readonly OpsDumpSchemaIndex[];
347
+ readonly foreignKeys: readonly OpsDumpSchemaForeignKey[];
348
+ }
349
+ /** Every table a dump holds: `sqlite_schema`'s tables but SQLite's internal ones, `sqlite_sequence` excepted, and `_cf_`'s. */
350
+ export interface OpsDumpSchema {
351
+ readonly tables: readonly OpsDumpSchemaTable[];
352
+ }
353
+ /** How one table is dumped and loaded. */
354
+ export interface OpsDumpTablePlan {
355
+ readonly name: string;
356
+ /** The name that reads the rowid: the `INTEGER PRIMARY KEY` column, else the first of `rowid`, `_rowid_`, `oid` no column takes. */
357
+ readonly keyset: string;
358
+ /** Every column that is not generated, in declaration order: a row is the rowid, then these. */
359
+ readonly columns: readonly string[];
360
+ /** The columns of the foreign keys inside a cycle, which a part writes `NULL` and the link pass sets, in declaration order. */
361
+ readonly deferred: readonly string[];
362
+ }
363
+ /** The tables of a dump in load order: every parent outside a table's own cycle comes before it. */
364
+ export interface OpsDumpPlan {
365
+ readonly tables: readonly OpsDumpTablePlan[];
366
+ }
367
+ /**
368
+ * The one rule both the producer, at export `begin`, and the importer, at import `begin`, apply to a schema: the plan
369
+ * a dump is written and loaded by, or an `unsupported_schema` refusal naming the table. A foreign key whose parent lies
370
+ * in its own table's cycle (the table itself included) is loaded `NULL` and linked once every row is in, so each of its
371
+ * columns must take a temporary `NULL`: nullable, outside the primary key, referenced by no foreign key, named by no
372
+ * `CHECK`, in a table without a `NOT NULL` generated column, a generated column a `CHECK` names, or a partial, expression
373
+ * or generated-column unique index. A `WITHOUT ROWID` or
374
+ * virtual table, a table without a name that reads its rowid, a foreign key to a table outside the dump or without the
375
+ * named key, and a foreign key checked only at commit are refused.
376
+ */
377
+ export declare function planOpsDump(schema: OpsDumpSchema): OpsDumpPlan | OpsDataRefusal;
378
+ /** Where a dump or a verification stands in a table: the last rowid read, and the count and hash folded so far. */
379
+ export interface OpsDumpCursor {
380
+ readonly table: string;
381
+ /** The rowid of the last row read, as decimal text; `null` before the table's first row. */
382
+ readonly after: string | null;
383
+ readonly rows: number;
384
+ readonly hash: string;
385
+ }
386
+ /** A table a dump holds, with its exact row count and its hash. */
387
+ export interface OpsDumpTable {
388
+ readonly name: string;
389
+ readonly rows: number;
390
+ readonly hash: string;
391
+ }
392
+ /** A part of a dump's data object: its number from 1, its size in bytes and the SHA-256 hex of its bytes. */
393
+ export interface OpsDumpPart {
394
+ readonly part: number;
395
+ readonly size: number;
396
+ readonly sha256: string;
397
+ }
398
+ /** A part as R2 accepted it; Control completes the upload with the ETags. */
399
+ export interface OpsUploadedPart extends OpsDumpPart {
400
+ readonly etag: string;
401
+ }
402
+ /** One `sqlite_schema` entry with SQL: an automatic index has none and is not listed. */
403
+ export interface OpsDumpSchemaEntry {
404
+ readonly type: 'table' | 'index' | 'trigger' | 'view';
405
+ readonly name: string;
406
+ readonly table: string;
407
+ readonly sql: string;
408
+ }
409
+ /** `manifest.json`, written beside the data once its upload completed. `tables` is in load order. */
410
+ export interface OpsDumpManifest {
411
+ readonly format: typeof OPS_DUMP_FORMAT;
412
+ readonly dump: string;
413
+ readonly object: string;
414
+ readonly consistent: boolean;
415
+ readonly createdAt: string;
416
+ /** The object's bookmark when the dump began. */
417
+ readonly bookmark: string;
418
+ readonly release: string;
419
+ readonly contractDigest: string;
420
+ readonly ddl: readonly OpsDumpSchemaEntry[];
421
+ readonly migrations: readonly OpsMigration[];
422
+ readonly tables: readonly OpsDumpTable[];
423
+ readonly parts: readonly OpsDumpPart[];
424
+ }
425
+ /**
426
+ * A manifest Control holds or an answer carries; every table's DDL lists it, its parts are whole, and its
427
+ * `JSON.stringify` is at most `OPS_DUMP_MANIFEST_MAX_BYTES` in UTF-8, wherever it came from.
428
+ */
429
+ export declare function parseOpsDumpManifest(body: unknown): OpsDumpManifest | null;
430
+ /** A manifest's text as R2 holds it, refused above `OPS_DUMP_MANIFEST_MAX_BYTES` before it is parsed. */
431
+ export declare function readOpsDumpManifest(text: string): OpsDumpManifest | null;
432
+ /** What every export step names: a consistent backup carries the published generation, a diagnostic export none. */
433
+ export interface OpsExportScope {
434
+ readonly object: string;
435
+ readonly generation: number | null;
436
+ readonly consistent: boolean;
437
+ readonly dump: string;
438
+ }
439
+ /** Starts the multipart upload of the dump's data. */
440
+ export interface OpsExportBegin extends OpsExportScope {
441
+ readonly step: 'begin';
442
+ }
443
+ /** Fills part `part` from `cursor`, `null` only for the first part; a retry replaces the part. */
444
+ export interface OpsExportPart extends OpsExportScope {
445
+ readonly step: 'part';
446
+ readonly uploadId: string;
447
+ readonly part: number;
448
+ readonly cursor: OpsDumpCursor | null;
449
+ }
450
+ /** Completes the upload from the parts and tables Control recorded, and writes the manifest. */
451
+ export interface OpsExportComplete extends OpsExportScope {
452
+ readonly step: 'complete';
453
+ readonly uploadId: string;
454
+ readonly bookmark: string;
455
+ readonly parts: readonly OpsUploadedPart[];
456
+ readonly tables: readonly OpsDumpTable[];
457
+ }
458
+ /** `POST /__fabrika/ops/export`: one step of a dump. */
459
+ export type OpsExportRequest = OpsExportBegin | OpsExportPart | OpsExportComplete;
460
+ export interface OpsExportBeginAck {
461
+ readonly step: 'begin';
462
+ readonly uploadId: string;
463
+ readonly bookmark: string;
464
+ }
465
+ /** The part written, the tables it finished in load order, and where the next part starts: `null` once all is read. */
466
+ export interface OpsExportPartAck {
467
+ readonly step: 'part';
468
+ readonly uploaded: OpsUploadedPart;
469
+ readonly tables: readonly OpsDumpTable[];
470
+ readonly next: OpsDumpCursor | null;
471
+ }
472
+ export interface OpsExportCompleteAck {
473
+ readonly step: 'complete';
474
+ readonly manifest: OpsDumpManifest;
475
+ }
476
+ export declare function parseOpsExportRequest(body: unknown): OpsExportRequest | null;
477
+ export declare function parseOpsExportBeginAck(body: unknown): OpsExportBeginAck | null;
478
+ export declare function parseOpsExportPartAck(body: unknown): OpsExportPartAck | null;
479
+ export declare function parseOpsExportCompleteAck(body: unknown): OpsExportCompleteAck | null;
480
+ /** The consistent backup an import loads: always under `__fabrika/backups/`. */
481
+ export interface OpsDumpSource {
482
+ readonly object: string;
483
+ readonly dump: string;
484
+ }
485
+ /** What every import step names: the fresh target, published `inspect` under the operation's generation, and the backup. */
486
+ export interface OpsImportScope {
487
+ readonly object: string;
488
+ readonly generation: number;
489
+ readonly source: OpsDumpSource;
490
+ }
491
+ /** Verifies the manifest, checks the target is fresh, and migrates it to the manifest's ledger. */
492
+ export interface OpsImportBegin extends OpsImportScope {
493
+ readonly step: 'begin';
494
+ }
495
+ /** Loads part `part`, writing a foreign key the load order cannot satisfy as `NULL`. */
496
+ export interface OpsImportPart extends OpsImportScope {
497
+ readonly step: 'part';
498
+ readonly part: number;
499
+ }
500
+ /** Sets the foreign keys part `part` wrote as `NULL`, once every part is loaded. */
501
+ export interface OpsImportLink extends OpsImportScope {
502
+ readonly step: 'link';
503
+ readonly part: number;
504
+ }
505
+ /** Reads the loaded tables back from `cursor`, `null` at the start, and compares counts and hashes with the manifest. */
506
+ export interface OpsImportVerify extends OpsImportScope {
507
+ readonly step: 'verify';
508
+ readonly cursor: OpsDumpCursor | null;
509
+ }
510
+ /** Clears the import marker once every table verified, so Control may open the object. */
511
+ export interface OpsImportComplete extends OpsImportScope {
512
+ readonly step: 'complete';
513
+ }
514
+ /** Wipes an `inspect` object that holds an import marker and serves no traffic, with `deleteAll()`. */
515
+ export interface OpsImportDiscard {
516
+ readonly step: 'discard';
517
+ readonly object: string;
518
+ readonly generation: number;
519
+ }
520
+ /** `POST /__fabrika/ops/import`: one step of loading a consistent backup into a fresh object. */
521
+ export type OpsImportRequest = OpsImportBegin | OpsImportPart | OpsImportLink | OpsImportVerify | OpsImportComplete | OpsImportDiscard;
522
+ export interface OpsImportBeginAck {
523
+ readonly step: 'begin';
524
+ readonly parts: number;
525
+ }
526
+ /** `deferred` counts the loaded rows whose deferred foreign keys wait for the link pass. */
527
+ export interface OpsImportPartAck {
528
+ readonly step: 'part';
529
+ readonly part: number;
530
+ readonly rows: number;
531
+ readonly deferred: number;
532
+ }
533
+ export interface OpsImportLinkAck {
534
+ readonly step: 'link';
535
+ readonly part: number;
536
+ readonly rows: number;
537
+ }
538
+ /** The tables verified in this step, each matching the manifest, and where the next step starts: `null` once all match. */
539
+ export interface OpsImportVerifyAck {
540
+ readonly step: 'verify';
541
+ readonly tables: readonly OpsDumpTable[];
542
+ readonly next: OpsDumpCursor | null;
543
+ }
544
+ export interface OpsImportCompleteAck {
545
+ readonly step: 'complete';
546
+ readonly source: OpsDumpSource;
547
+ }
548
+ export interface OpsImportDiscardAck {
549
+ readonly step: 'discard';
550
+ }
551
+ export declare function parseOpsImportRequest(body: unknown): OpsImportRequest | null;
552
+ export declare function parseOpsImportBeginAck(body: unknown): OpsImportBeginAck | null;
553
+ export declare function parseOpsImportPartAck(body: unknown): OpsImportPartAck | null;
554
+ export declare function parseOpsImportLinkAck(body: unknown): OpsImportLinkAck | null;
555
+ export declare function parseOpsImportVerifyAck(body: unknown): OpsImportVerifyAck | null;
556
+ export declare function parseOpsImportCompleteAck(body: unknown): OpsImportCompleteAck | null;
557
+ export declare function parseOpsImportDiscardAck(body: unknown): OpsImportDiscardAck | null;
558
+ /**
559
+ * Writes the sentinel (the operation's id) into the object's KV storage, and answers the current bookmark and the
560
+ * bookmark of `at`, which Control records before it arms anything.
561
+ */
562
+ export interface OpsRestorePrepare {
563
+ readonly step: 'prepare';
564
+ readonly object: string;
565
+ readonly generation: number;
566
+ readonly sentinel: string;
567
+ readonly at: string;
568
+ }
569
+ /** Arms the restore of `target` for the next session, answers, then resets the object. */
570
+ export interface OpsRestoreArm {
571
+ readonly step: 'arm';
572
+ readonly object: string;
573
+ readonly generation: number;
574
+ readonly sentinel: string;
575
+ readonly target: string;
576
+ }
577
+ /** Reads, after the reset, whether the sentinel is still there. It writes nothing, so it carries no generation. */
578
+ export interface OpsRestoreVerify {
579
+ readonly step: 'verify';
580
+ readonly object: string;
581
+ readonly sentinel: string;
582
+ }
583
+ /** `POST /__fabrika/ops/restore`: one step of rewinding an `inspect` object that serves no traffic. */
584
+ export type OpsRestoreRequest = OpsRestorePrepare | OpsRestoreArm | OpsRestoreVerify;
585
+ export interface OpsRestorePrepareAck {
586
+ readonly step: 'prepare';
587
+ readonly current: string;
588
+ readonly target: string;
589
+ }
590
+ /** May be lost to the reset; `verify` reconciles. */
591
+ export interface OpsRestoreArmAck {
592
+ readonly step: 'arm';
593
+ readonly undo: string;
594
+ }
595
+ /** A sentinel still present means the restore did not happen. */
596
+ export interface OpsRestoreVerifyAck {
597
+ readonly step: 'verify';
598
+ readonly sentinel: 'present' | 'absent';
599
+ readonly bookmark: string;
600
+ }
601
+ export declare function parseOpsRestoreRequest(body: unknown): OpsRestoreRequest | null;
602
+ export declare function parseOpsRestorePrepareAck(body: unknown): OpsRestorePrepareAck | null;
603
+ export declare function parseOpsRestoreArmAck(body: unknown): OpsRestoreArmAck | null;
604
+ export declare function parseOpsRestoreVerifyAck(body: unknown): OpsRestoreVerifyAck | null;
605
+ /** The most timers one answer lists; the rest are counted in `omitted`. */
606
+ export declare const OPS_TIMERS_CAP = 500;
607
+ /** A timer's stack keeps at most this many frames, the ones nearest the call that registered the work. */
608
+ export declare const OPS_TIMER_STACK_MAX_FRAMES = 20;
609
+ /** A timer's stack is at most this many UTF-8 bytes, cut after it is scrubbed. */
610
+ export declare const OPS_TIMER_STACK_MAX_BYTES: number;
611
+ /** `POST /__fabrika/ops/timers`: reads the tracker, or with `track` switches it on or off first. In memory only. */
612
+ export interface OpsTimersRequest {
613
+ readonly object: string;
614
+ readonly track: boolean | null;
615
+ }
616
+ /** A pending timer or `waitUntil` promise and the stack that registered it, which may name application code: content. */
617
+ export interface OpsTimer {
618
+ readonly kind: 'timeout' | 'interval' | 'waitUntil';
619
+ readonly since: string;
620
+ /** `null` exactly for `waitUntil`. */
621
+ readonly delayMs: number | null;
622
+ readonly stack: string;
623
+ }
624
+ /** The object's live timers, oldest first (`data.content.read`). */
625
+ export interface OpsTimersView {
626
+ readonly tracking: boolean;
627
+ readonly timers: readonly OpsTimer[];
628
+ readonly omitted: number;
629
+ }
630
+ export declare function parseOpsTimersRequest(body: unknown): OpsTimersRequest | null;
631
+ export declare function parseOpsTimersView(body: unknown): OpsTimersView | null;
632
+ /** The status of a data operation's refusal. It is answered only after authentication. */
633
+ export declare const OPS_DATA_REFUSED_STATUS = 422;
634
+ /** Why the object refused an export, import or restore step. */
635
+ export declare const OPS_DATA_REFUSALS: readonly ["wrong_mode", "serving_object", "unsupported_schema", "not_fresh", "no_import", "invalid_manifest", "fuzzy_dump", "part_mismatch", "ledger_mismatch", "schema_mismatch", "verify_mismatch", "bookmark_unavailable", "row_too_large"];
636
+ export type OpsDataRefusalReason = (typeof OPS_DATA_REFUSALS)[number];
637
+ /** The body of a data refusal; `table` names the table at fault, an identifier and never a value. */
638
+ export interface OpsDataRefusal {
639
+ readonly refused: OpsDataRefusalReason;
640
+ readonly table: string | null;
641
+ }
642
+ export declare function parseOpsDataRefusal(body: unknown): OpsDataRefusal | null;
643
+ /**
644
+ * The schema `planOpsDump` reads, from the PRAGMAs workerd admits, of every table a dump holds. An `INITIALLY DEFERRED`
645
+ * clause is read from the table's SQL outside its quotes and comments, and marks every foreign key of its table; the
646
+ * names a `CHECK` reads come from the same SQL (`checkNamesOf`).
647
+ */
648
+ export declare function describeOpsDumpSchema(query: OpsDumpSchemaQuery): OpsDumpSchema;
649
+ /**
650
+ * The names the `CHECK` clauses of a table's `sql` read: every word and quoted identifier between a `CHECK` keyword's
651
+ * parentheses, ASCII-lowercase, keywords and numbers included, so it lists at least every column a `CHECK` reads. A
652
+ * string literal and a comment name nothing; a double-quoted string, which SQLite may read as either, counts as a name.
653
+ * `null` when the text does not scan (an unclosed quote, comment or parenthesis), which counts as naming every column.
654
+ */
655
+ export declare function checkNamesOf(sql: string): string[] | null;
656
+ /** One statement's rows, as a Durable Object's `sql.exec(...).toArray()` or a `bun:sqlite` query answers them. */
657
+ export type OpsDumpSchemaQuery = (sql: string, ...bindings: string[]) => readonly Readonly<Record<string, unknown>>[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The name of a `:name` path segment, or null for any other segment. Every endpoint table, an application's and an
3
+ * installation service's, reads a parameter by this rule: it matches exactly one non-empty segment.
4
+ */
5
+ export declare function parameterName(segment: string): string | null;