@fabrika/auth-core 0.9.0-cloudflare.1 → 0.9.0-cloudflare.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/contract-canonical.ts +1 -1
- package/src/contract.ts +5 -3
- package/src/framework-variables.ts +6 -0
- package/src/index.ts +1 -0
- package/src/managed-environment.ts +4 -0
- package/src/ops.ts +1217 -3
- package/src/public-egress.ts +166 -0
- package/types/src/contract.d.ts +5 -3
- package/types/src/framework-variables.d.ts +6 -1
- package/types/src/index.d.ts +1 -0
- package/types/src/managed-environment.d.ts +1 -1
- package/types/src/ops.d.ts +463 -2
- package/types/src/public-egress.d.ts +31 -0
package/types/src/ops.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const OPS_METHOD = "POST";
|
|
|
12
12
|
/** The one content type the composed row admits. */
|
|
13
13
|
export declare const OPS_CONTENT_TYPE = "application/json";
|
|
14
14
|
/** The operations the object serves, each at `opsPath(operation)`. */
|
|
15
|
-
export declare const OPS_OPERATIONS: readonly ["inspect", "state", "migrate"];
|
|
15
|
+
export declare const OPS_OPERATIONS: readonly ["inspect", "state", "migrate", "export", "import", "restore", "timers"];
|
|
16
16
|
export type OpsOperation = (typeof OPS_OPERATIONS)[number];
|
|
17
17
|
export declare function opsPath(operation: OpsOperation): string;
|
|
18
18
|
/** The operation a request path names, or `null` for any other path, which gets `opsRefusal()`. */
|
|
@@ -124,7 +124,7 @@ export interface OpsScheduler {
|
|
|
124
124
|
/** The current alarm, or `null` when none is set. */
|
|
125
125
|
readonly alarm: string | null;
|
|
126
126
|
}
|
|
127
|
-
/** A job's last run and its outcome
|
|
127
|
+
/** A job's last run and its outcome: a contract job, or a framework job such as `fabrika-file-sweep`. */
|
|
128
128
|
export interface OpsJob {
|
|
129
129
|
readonly job: string;
|
|
130
130
|
readonly lastStatus: 'succeeded' | 'failed' | null;
|
|
@@ -179,3 +179,464 @@ export declare function parseOpsStaleRefusal(body: unknown): OpsStaleRefusal | n
|
|
|
179
179
|
export declare function parseOpsMigrateAck(body: unknown): OpsMigrateAck | null;
|
|
180
180
|
export declare function parseOpsView(body: unknown): OpsView | null;
|
|
181
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The declared form of public egress: every public host, over HTTPS or HTTP, on its default port. */
|
|
2
|
+
export declare const PUBLIC_EGRESS = "public";
|
|
3
|
+
export type PublicEgress = typeof PUBLIC_EGRESS;
|
|
4
|
+
/** What a site declares in `egress`: its exact HTTPS origins, sorted, or every public host (a cron job only). */
|
|
5
|
+
export type DeclaredEgress = readonly string[] | PublicEgress;
|
|
6
|
+
/**
|
|
7
|
+
* The name suffixes public egress refuses, each with every name under it: local and special-use names (RFC 6761,
|
|
8
|
+
* RFC 6762, RFC 8375, RFC 9476), the names private networks conventionally use (`.internal` holds Google's metadata
|
|
9
|
+
* host and Control's own `operations.internal`), and the platform subdomains an installation is served on beside its
|
|
10
|
+
* own domains: Cloudflare's `workers.dev`, where its Workers have their default routes, and Zerops' `zerops.app`, where
|
|
11
|
+
* its proxies, Control and IAM have their subdomains (a namespace proxy's `proxy-…-8080.<region>.zerops.app`), with the
|
|
12
|
+
* `zerops` suffix of a Zerops project's private network. Control knows no list of those subdomains, so every one is
|
|
13
|
+
* refused, another installation's too.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PUBLIC_EGRESS_REFUSED_SUFFIXES: readonly ["localhost", "local", "internal", "intranet", "lan", "home", "corp", "private", "arpa", "test", "invalid", "example", "onion", "alt", "zerops", "zerops.app", "workers.dev"];
|
|
16
|
+
/** A host name without its trailing dots, lowercased: the form every comparison here uses. */
|
|
17
|
+
export declare function normalizedHost(hostname: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Why public egress refuses `url`, or `null` when the URL alone admits it: a scheme other than `https:` and `http:`, a
|
|
20
|
+
* port other than the scheme's default, an IP literal, a name of one label, a name under a refused suffix, or one of
|
|
21
|
+
* `refusedHosts` (normalized names). A host it admits may still resolve to a private address, which only a runtime that
|
|
22
|
+
* resolves names refuses.
|
|
23
|
+
*/
|
|
24
|
+
export declare function publicEgressRefusal(url: URL, refusedHosts?: ReadonlySet<string>): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Whether `address` (an IPv4 or IPv6 address, as a resolver answers it) is a public unicast address: not private,
|
|
27
|
+
* loopback, link-local (which holds the cloud metadata address 169.254.169.254), shared, multicast, reserved,
|
|
28
|
+
* documentation, or an IPv6 form that embeds or tunnels an IPv4 address it cannot vouch for. A text that is no address
|
|
29
|
+
* is not public.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isPublicAddress(address: string): boolean;
|