@fabrika/platform-node 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.
@@ -0,0 +1,11 @@
1
+ /** The Postgres major versions the sets below are generated from. */
2
+ export declare const PG_CATALOG_MAJORS: readonly number[];
3
+ /** Every function name in `pg_catalog`: an application function may not take one, or a call could resolve to the built-in. */
4
+ export declare const PG_CATALOG_FUNCTIONS: ReadonlySet<string>;
5
+ /** Every SQL keyword, of every category: an application function may not take one (`operator`, `position`). */
6
+ export declare const SQL_KEYWORDS: ReadonlySet<string>;
7
+ /** Per major, the names of the sets above that its own catalog lacks. */
8
+ export declare const PG_CATALOG_ABSENT: ReadonlyMap<number, {
9
+ functions: ReadonlySet<string>;
10
+ keywords: ReadonlySet<string>;
11
+ }>;
@@ -0,0 +1,13 @@
1
+ /** One rewritten statement. `count` is exactly how many values `bind()` must supply. */
2
+ export interface RewrittenSql {
3
+ /** Postgres-dialect text: every positional `?` replaced by `$1..$n`, left to right. */
4
+ text: string;
5
+ /** How many placeholders were rewritten. */
6
+ count: number;
7
+ }
8
+ /**
9
+ * Rewrite a `?`-placeholder statement into Postgres `$n` form. Throws on an unterminated string,
10
+ * identifier, dollar-quote or block comment — the statement is malformed and no rewriting of it can
11
+ * be trusted.
12
+ */
13
+ export declare function rewritePlaceholders(sql: string): RewrittenSql;
@@ -0,0 +1,4 @@
1
+ /** A refusal or failure of the runner itself. Its message names no credential; a driver error is its `cause`. */
2
+ export declare class PostgresMigrationError extends Error {
3
+ readonly name = "PostgresMigrationError";
4
+ }
@@ -0,0 +1,63 @@
1
+ import type { SqlDatabase } from '@fabrika/platform';
2
+ import { PostgresMigrationError } from './postgres-migration-error';
3
+ export interface PostgresMigration {
4
+ name: string;
5
+ sql: string;
6
+ }
7
+ export interface PostgresMigrationBundle {
8
+ name: string;
9
+ migrations: readonly PostgresMigration[];
10
+ }
11
+ export interface PostgresMigrationPlan {
12
+ /** Service-scoped ledger table, such as `iam_schema_migrations`; an application's is qualified by its schema. */
13
+ ledgerTable: string;
14
+ /** Service-specific session advisory lock. Keep this stable across runner upgrades. */
15
+ lockKey: number;
16
+ bundles: readonly PostgresMigrationBundle[];
17
+ /** Present only in an application's plan (ADR-0017): its schema, a checksum per migration, and timeouts. */
18
+ application?: PostgresApplicationMigrationSettings;
19
+ }
20
+ export interface PostgresApplicationMigrationSettings {
21
+ /** Created when absent. Each migration runs with it as its only `search_path`. */
22
+ schema: string;
23
+ /** `lock_timeout` of each migration, so a blocked `ALTER` fails the deploy instead of stalling the live version. */
24
+ lockTimeoutMs: number;
25
+ statementTimeoutMs: number;
26
+ /** The framework's own bundle (`fabrika`), which alone may name the framework's `fabrika_*` tables. */
27
+ frameworkBundle?: string;
28
+ /**
29
+ * The application's runtime role. Before the plan runs, the migration role's default privileges are cleared of
30
+ * PUBLIC; after it ran, the runtime role's and PUBLIC's privileges in the schema are reset to the runtime role's DML
31
+ * on every table but the ledger and verified, in one transaction under the migration lock; it never gets DDL.
32
+ */
33
+ runtimeRole?: string;
34
+ /** How long the runner waits for the migration lock; any session may take an advisory lock, so the wait is bounded. */
35
+ advisoryLockTimeoutMs?: number;
36
+ }
37
+ export { PostgresMigrationError };
38
+ export interface ReadPostgresMigrationBundleOptions {
39
+ name: string;
40
+ directory: string;
41
+ files?: readonly string[];
42
+ }
43
+ /** Read one ordered migration bundle from disk. An explicit file list fails closed when a file is absent. */
44
+ export declare function readPostgresMigrationBundle(options: ReadPostgresMigrationBundleOptions): PostgresMigrationBundle;
45
+ /** The generic migrations owned by the long-running Bun runtime. */
46
+ export declare function platformNodePostgresMigrationBundle(files?: readonly string[]): PostgresMigrationBundle;
47
+ /** Validate a complete plan at composition time, before any SQL is executed. */
48
+ export declare function definePostgresMigrationPlan(plan: PostgresMigrationPlan): PostgresMigrationPlan;
49
+ export declare function postgresMigrationIdentity(bundle: string, name: string): string;
50
+ /** Preserve a service wrapper's historical filename-only result while the core uses qualified ids. */
51
+ export declare function postgresMigrationFilenames(identities: readonly string[], bundle: string): string[];
52
+ /**
53
+ * Apply a plan over one Postgres session.
54
+ *
55
+ * The caller must supply a database backed by a single-connection pool. Advisory locks are session
56
+ * state; allowing acquire and release to land on different pooled connections would make the runner
57
+ * appear serialized while providing no serialization at all.
58
+ */
59
+ export declare function applyPostgresMigrations(db: SqlDatabase, input: PostgresMigrationPlan, options?: {
60
+ now?: () => number;
61
+ }): Promise<string[]>;
62
+ /** SHA-256 of the file's text, hex. */
63
+ export declare function migrationChecksum(sql: string): string;
@@ -0,0 +1,37 @@
1
+ import type { SqlDatabase } from '@fabrika/platform';
2
+ /** A provisioning credential that exists for one test run only, and what it created. */
3
+ export interface TestProvisioner {
4
+ /**
5
+ * Connects as `fabrika_tests_<hex>`: CREATEROLE and CREATE on the database, nothing of any application, and a login
6
+ * for `TEST_PROVISIONER_LIFETIME_MINUTES` only.
7
+ */
8
+ readonly url: string;
9
+ /** The provisioners of earlier runs that creating this one dropped. Role names, never a credential. */
10
+ readonly swept: readonly string[];
11
+ /** Drops every role the provisioner created, with everything those roles own, then the provisioner itself. */
12
+ drop(): Promise<void>;
13
+ }
14
+ /**
15
+ * Every grant or revoke on a database changes its one `pg_database` row, and two concurrent changes of that row fail with
16
+ * `tuple concurrently updated`, so each change waits for this transaction-level lock first.
17
+ */
18
+ export declare const DATABASE_GRANT_LOCK_KEY: number;
19
+ /**
20
+ * Grants (or revokes) CREATE on `database` to `role`, serialized with every other run that does so on the same server.
21
+ * Verified afterwards: a grantor that neither owns the database, is a superuser nor holds CREATE WITH GRANT OPTION only
22
+ * gets a WARNING, and the statement changes nothing.
23
+ */
24
+ export declare function changeCreateOnDatabase(admin: SqlDatabase, change: 'grant' | 'revoke', role: string, database: string): Promise<void>;
25
+ /**
26
+ * How long a provisioner can log in (`VALID UNTIL`). A run that a kill stopped before `drop()` leaves its provisioner
27
+ * behind, and nobody knows its password; after this time it also cannot log in, and the next run's sweep drops it. A
28
+ * run makes new connections until it ends, so this is far beyond the longest run.
29
+ */
30
+ export declare const TEST_PROVISIONER_LIFETIME_MINUTES = 15;
31
+ /**
32
+ * Creates a throwaway provisioning credential for code the platform runs but did not write, such as an application's
33
+ * generated tests: it can create the test kit's role families and schemas, and reaches no application's data, because
34
+ * a CREATEROLE role administers only the roles it created. The provisioning credential itself never leaves this process.
35
+ * First it drops the provisioners earlier runs left behind (`sweepTestProvisioners`).
36
+ */
37
+ export declare function createTestProvisioner(provisioningUrl: string): Promise<TestProvisioner>;
@@ -0,0 +1,25 @@
1
+ import type { SqlDatabase } from '@fabrika/platform';
2
+ import { type PostgresMigration, type PostgresMigrationBundle, type PostgresMigrationPlan } from './postgres-migrations';
3
+ export interface PostgresServiceMigrationsConfig {
4
+ /** Stable service-owned bundle name. */
5
+ readonly name: string;
6
+ /** Stable service-owned ledger table. */
7
+ readonly ledgerTable: string;
8
+ /** Stable service advisory lock. */
9
+ readonly lockKey: number;
10
+ readonly directory: string;
11
+ /** Runtime-owned bundles applied before the service schema. */
12
+ readonly dependencies?: readonly PostgresMigrationBundle[];
13
+ }
14
+ export interface PostgresServiceMigrations {
15
+ read(directory?: string): PostgresMigration[];
16
+ plan(migrations?: readonly PostgresMigration[]): PostgresMigrationPlan;
17
+ apply(db: SqlDatabase, migrations?: readonly PostgresMigration[]): Promise<string[]>;
18
+ applyQualified(db: SqlDatabase, migrations?: readonly PostgresMigration[]): Promise<string[]>;
19
+ }
20
+ /**
21
+ * Define the repeated service migration wrapper while keeping service identity and lifecycle local.
22
+ * Bundle names, ledgers, lock ids, and dependency order remain explicit inputs.
23
+ */
24
+ export declare function definePostgresServiceMigrations(config: PostgresServiceMigrationsConfig): PostgresServiceMigrations;
25
+ export declare function postgresMigrationResultMessage(applied: readonly string[]): string;
@@ -0,0 +1,144 @@
1
+ import { type SqlToken } from './migration-sql';
2
+ export declare const isName: (token: SqlToken | undefined) => boolean;
3
+ export declare const isPunct: (token: SqlToken | undefined, char: string) => boolean;
4
+ /** A name as Postgres stores it: an unquoted one with only ASCII folded to lower case, either truncated to 63 bytes. */
5
+ export declare function nameText(token: SqlToken | undefined): string | undefined;
6
+ /** The index past a name at `index`, schema-qualified or not, or `undefined` when no name is there. */
7
+ export declare function afterName(tokens: readonly SqlToken[], index: number): number | undefined;
8
+ /** A possibly schema-qualified object name: `qualifier` is set only when the statement wrote one. */
9
+ export interface ObjectName {
10
+ readonly qualifier: string | undefined;
11
+ readonly name: string;
12
+ }
13
+ /** The name at `index` (`name` or `schema.name`), or `undefined`. */
14
+ export declare function objectNameAt(tokens: readonly SqlToken[], index: number): ObjectName | undefined;
15
+ /** The index past the words `words` at `index`, or `index` itself when they are not all there. */
16
+ export declare function skipWords(tokens: readonly SqlToken[], index: number, ...words: readonly string[]): number;
17
+ /** The token lists between the commas at parenthesis depth 0 of `tokens`. */
18
+ export declare function splitAtCommas(tokens: readonly SqlToken[]): SqlToken[][];
19
+ /** The index of the `)` that closes the `(` at `open`, or `undefined`. */
20
+ export declare function closingParenthesis(tokens: readonly SqlToken[], open: number): number | undefined;
21
+ /** The index of the first word `word` at parenthesis depth 0 at or after `from`, or `undefined`. */
22
+ export declare function wordAtDepthZero(tokens: readonly SqlToken[], word: string, from?: number): number | undefined;
23
+ /**
24
+ * What a statement is, for a refusal to name: its first word, and after `CREATE`, `ALTER` or `DROP` (past `OR
25
+ * REPLACE`) the kind of object. A statement that does not begin with a word is named by its first token.
26
+ */
27
+ export declare function statementKind(tokens: readonly SqlToken[]): string;
28
+ /**
29
+ * The first schema a DDL statement names other than `schema`, `pg_catalog` included: every qualified name counts,
30
+ * since a DDL statement has no table alias to qualify a column with, and so does any unqualified `pg_…` name, which
31
+ * resolves to the catalog (`LIKE pg_authid`, `REFERENCES pg_class`).
32
+ */
33
+ export declare function ddlForeignSchema(tokens: readonly SqlToken[], schema: string): string | undefined;
34
+ /** How a name is used where it stands; `operator` is the operator `OPERATOR(schema.op)` names. */
35
+ export type NameRole = 'relation' | 'call' | 'type' | 'operator' | 'other';
36
+ /** One name of a statement: `qualifier` is the first part of a two- or three-part name. */
37
+ export interface NameReference {
38
+ readonly qualifier: string | undefined;
39
+ readonly name: string;
40
+ readonly parts: number;
41
+ readonly role: NameRole;
42
+ readonly line: number;
43
+ }
44
+ /**
45
+ * Every name of a DML statement, a query or an expression, with its role. A name in a relation position (after
46
+ * `FROM`, `JOIN`, `USING`, `INTO`, `UPDATE`, `TABLE`, `REFERENCES`, or a `,` of a `FROM` list) is a relation; a name
47
+ * that `(` follows is a call, unless it is syntax, a type with a modifier or a CTE's name before its column list
48
+ * (`WITH RECURSIVE tree (id, depth) AS`); a name after `::` or `AS` is a type. A two-part name anywhere else is a
49
+ * column of a table or an alias (`d.note`, `NEW.stage`).
50
+ */
51
+ export declare function nameReferences(read: ReadSql): NameReference[];
52
+ /**
53
+ * The first schema the `references` of a DML statement, a query or a function body (`nameReferences`) reach other
54
+ * than `schema`, `pg_catalog` included: a qualified relation, call or type, or a three-part name. An unqualified
55
+ * relation whose name starts with `pg_` resolves to the catalog and counts as `pg_catalog`.
56
+ */
57
+ export declare function referencedForeignSchema(references: readonly NameReference[], schema: string): string | undefined;
58
+ /**
59
+ * The form of a CTE that a list must take to be read, for a refusal to name: a `CYCLE` mark is a constant, as Postgres
60
+ * requires, never a bound value.
61
+ */
62
+ export declare const CTE_FORM = "name [(columns)] AS [[NOT] MATERIALIZED] (query) [SEARCH {BREADTH | DEPTH} FIRST BY columns SET column] [CYCLE columns SET column [TO constant DEFAULT constant] USING column]";
63
+ /** The CTE lists of a statement, a query or a body. */
64
+ export interface CteLists {
65
+ /** The statement each list ends in, by the index of its `WITH`, wherever that stands: a nested statement is refused there too. */
66
+ readonly terminals: ReadonlyMap<number, SqlToken | undefined>;
67
+ /** The index of each CTE's name in a list whose `WITH` begins a query: a `(` after one opens its column list. */
68
+ readonly names: ReadonlySet<number>;
69
+ /** The line of the first `WITH` that begins a query and whose list does not read as one; the entry refuses it. */
70
+ readonly unread: number | undefined;
71
+ }
72
+ /** A statement of a PL/pgSQL body: the index of its first token, and whether it stands in a declaration section. */
73
+ export interface BodyStatement {
74
+ readonly index: number;
75
+ readonly declaring: boolean;
76
+ }
77
+ /**
78
+ * The tokens of a query, a statement, a clause or an expression, read once with their CTE lists. The name checks take
79
+ * the tokens and their lists as this one value, which only its factories build: its private member makes it nominal,
80
+ * so an object that merely has its fields is none, and a list is never read against tokens it was not read from.
81
+ */
82
+ export declare class ReadSql {
83
+ #private;
84
+ readonly tokens: readonly SqlToken[];
85
+ readonly ctes: CteLists;
86
+ protected constructor(tokens: readonly SqlToken[], ctes: CteLists);
87
+ /** A query or a data-changing statement: a query begins at its first token. */
88
+ static query(tokens: readonly SqlToken[]): ReadSql;
89
+ /** A clause or a condition (a policy's expressions, a rule, a trigger's `WHEN`): a query begins only in parentheses. */
90
+ static clause(tokens: readonly SqlToken[]): ReadSql;
91
+ /** A stored expression, which Postgres lets hold no subquery: no CTE list is read, so every `name (` is a call. */
92
+ static expression(tokens: readonly SqlToken[]): ReadSql;
93
+ }
94
+ /** A function or `DO` body read once: its statements (`bodyOf`), and its CTE lists with a query wherever one begins. */
95
+ export declare class ReadBody extends ReadSql {
96
+ readonly statements: readonly BodyStatement[];
97
+ private constructor();
98
+ static of(tokens: readonly SqlToken[]): ReadBody;
99
+ }
100
+ /**
101
+ * The first nested statement a nested position may not hold: in parentheses (a CTE body, a subquery) and after a
102
+ * CTE list, anything but a query or `INSERT`/`UPDATE`/`DELETE`, whose names the same checks read. `MERGE` among them.
103
+ */
104
+ export declare function nestedStatement(read: ReadSql): {
105
+ readonly statement: string;
106
+ readonly line: number;
107
+ } | undefined;
108
+ /**
109
+ * The first data-changing statement whose target is in parentheses (`UPDATE ONLY (t)`, `DELETE FROM (t)`): the
110
+ * classifier reads a target as the name after the keyword, so it refuses the form rather than read through a group.
111
+ */
112
+ export declare function parenthesizedTarget(tokens: readonly SqlToken[]): {
113
+ readonly statement: string;
114
+ readonly line: number;
115
+ } | undefined;
116
+ /** The relations a DML statement or a query names, in order: what its static text reads or writes. */
117
+ export declare function dmlRelations(read: ReadSql): NameReference[];
118
+ /**
119
+ * Whether a name is the framework's (`fabrika_…`): its tables share the application's schema and hold its secrets,
120
+ * leases and deliveries. Case-insensitive, so a quoted `"FABRIKA_x"` counts too.
121
+ */
122
+ export declare function isFrameworkName(name: string): boolean;
123
+ /** The first framework name among `tokens` that `allowed` does not hold, with its line. */
124
+ export declare function frameworkReference(tokens: readonly SqlToken[], allowed?: ReadonlySet<string>): {
125
+ readonly name: string;
126
+ readonly line: number;
127
+ } | undefined;
128
+ /** `U&"…"`: an identifier whose escapes the lexer does not decode, so a name rule cannot read it. */
129
+ export declare function unicodeIdentifier(tokens: readonly SqlToken[]): {
130
+ readonly line: number;
131
+ } | undefined;
132
+ /** How a call is admitted: `paved` and `reviewed` built-ins, `expression`-only ones, and the migrations' own functions. */
133
+ export type FunctionUse = 'paved' | 'reviewed' | 'declared';
134
+ /**
135
+ * How a call of `call` is admitted, or `undefined` when it is not. A function the migrations declare in `schema` may be
136
+ * called unqualified or qualified with `schema`; a built-in only unqualified, since a qualified one names `pg_catalog`.
137
+ */
138
+ export declare function functionUse(call: NameReference, schema: string, functions: ReadonlySet<string>): FunctionUse | undefined;
139
+ /**
140
+ * The first call among the `references` of a body, a query or a backfill (`nameReferences`) that it may not make: anything but a paved or reviewed
141
+ * built-in, or a function the migrations declare in `schema`. An allowlist, because a built-in such as
142
+ * `query_to_xml`, `dblink` or `lo_import` runs SQL from a string or reaches past the schema, which no name rule sees.
143
+ */
144
+ export declare function refusedCall(references: readonly NameReference[], schema: string, functions: ReadonlySet<string>): NameReference | undefined;
@@ -0,0 +1,51 @@
1
+ import type { SqlDatabase, SqlQueryResult, SqlRunResult, SqlStatement } from '@fabrika/platform';
2
+ /** What a bound value may be. Anything else is a programming error and throws at bind time, as D1 does. */
3
+ export type SqlBindValue = string | number | bigint | boolean | Uint8Array | null;
4
+ /**
5
+ * One prepared statement. IMMUTABLE: `bind()` returns a NEW statement carrying the values and leaves
6
+ * the receiver untouched, which is D1's contract and what call sites rely on when they prepare once
7
+ * and bind in a loop.
8
+ */
9
+ export declare class PostgresStatement implements SqlStatement {
10
+ private readonly sql;
11
+ private readonly text;
12
+ private readonly placeholders;
13
+ private readonly values;
14
+ constructor(sql: Bun.SQL, text: string, placeholders: number, values: readonly SqlBindValue[]);
15
+ bind(...values: unknown[]): SqlStatement;
16
+ first<T = Record<string, unknown>>(): Promise<T | null>;
17
+ all<T = Record<string, unknown>>(): Promise<SqlQueryResult<T>>;
18
+ run(): Promise<SqlRunResult>;
19
+ /** This statement, once every placeholder has its value: a wrong count fails before any connection is taken. */
20
+ bound(): PostgresStatement;
21
+ /**
22
+ * Run this statement on a specific handle — a reserved connection of the pool, or the one `batch()` holds its
23
+ * transaction on. Internal to the package; the port only ever sees `first`/`all`/`run`.
24
+ */
25
+ rows<T>(handle: Bun.SQL): Promise<T[]>;
26
+ }
27
+ /**
28
+ * A Postgres-backed `SqlDatabase`. Rewritten statement text is memoised per SQL string, so the
29
+ * prepare-once/bind-many idiom tokenises each statement exactly once.
30
+ */
31
+ export declare class PostgresDatabase implements SqlDatabase {
32
+ private readonly sql;
33
+ private readonly rewrites;
34
+ constructor(sql: Bun.SQL);
35
+ /**
36
+ * Open a pooled client that prepares no named statement (see the header). The URL is a CREDENTIAL — it is
37
+ * never logged, and never included in an error message raised here.
38
+ */
39
+ static connect(url: string, options?: Omit<Bun.SQL.PostgresOrMySQLOptions, 'url' | 'adapter' | 'prepare'>): PostgresDatabase;
40
+ prepare(sql: string): SqlStatement;
41
+ /**
42
+ * Run every statement in ONE transaction, in order. A throw rolls the whole batch back. The transaction is sent by
43
+ * hand on the reserved connection: Bun 1.3.14's `begin()` on a reserved connection rejects a failed statement twice,
44
+ * once unhandled.
45
+ */
46
+ batch<T = Record<string, unknown>>(statements: SqlStatement[]): Promise<SqlQueryResult<T>[]>;
47
+ /** Close the pool. Waits for in-flight queries unless a timeout is given. */
48
+ close(options?: {
49
+ timeout?: number;
50
+ }): Promise<void>;
51
+ }
@@ -0,0 +1,7 @@
1
+ export { applicationDatabaseSchema } from './application-schema';
2
+ export { FILE_SCAN_COLUMNS, FILE_STATUSES, FILE_TABLE_PREFIX, fileScanAlter, fileScanAlterTable, fileScanIndex, fileStatusCheck, fileTableScanReady, legacyStatusCheckName, } from './file-table-ddl';
3
+ export { classifyMigration, type ClassifyMigrationOptions, classifyMigrations, type DatabaseObject, type DatabaseObjectKind, declaredFunctions, type DeviationKind, type FileAdoption, type ManifestChange, type MigrationClassification, type MigrationDeviation, type MigrationFile, migrationManifest, type MigrationRefusal, type MigrationSetClassification, } from './migration-classify';
4
+ export { lexSql, type SqlToken, sqlTokens, type Statement, statementsOf, topLevelStatements, upperWord } from './migration-sql';
5
+ export { PG_CATALOG_FUNCTIONS, SQL_KEYWORDS } from './pg-catalog-names';
6
+ export { afterName, type BodyStatement, closingParenthesis, CTE_FORM, type CteLists, ddlForeignSchema, dmlRelations, frameworkReference, type FunctionUse, functionUse, isFrameworkName, isPunct, type NameReference, nameReferences, type NameRole, nameText, nestedStatement, objectNameAt, parenthesizedTarget, ReadBody, ReadSql, referencedForeignSchema, refusedCall, skipWords, splitAtCommas, statementKind, unicodeIdentifier, } from './sql-names';
7
+ export { lexSqlite } from './sqlite-sql';
@@ -0,0 +1,11 @@
1
+ import type { SqlToken } from './migration-sql';
2
+ /**
3
+ * The tokens of `sql` as SQLite reads it, and the line of the first string, quoted name or block comment that never
4
+ * closes. `'…'` (with `''`) is a string; `"…"`, `` `…` `` (each with its doubled quote) and `[…]` (no escape) are quoted
5
+ * names; `--` runs to a line feed and `/* *\/` does not nest. There is no `E''` string and no dollar quoting, so a `\`
6
+ * or a `$` is no quote: `E'\'; DROP …` is a string, then a `;`.
7
+ */
8
+ export declare function lexSqlite(sql: string): {
9
+ readonly tokens: SqlToken[];
10
+ readonly unterminated: number | undefined;
11
+ };
@@ -0,0 +1,20 @@
1
+ import type { WaitUntil } from '@fabrika/platform';
2
+ export interface BackgroundTasks {
3
+ /** The port itself. Hand it a promise and forget it; it never throws and never rejects. */
4
+ readonly waitUntil: WaitUntil;
5
+ /** How many supervised promises are still in flight. */
6
+ readonly pending: number;
7
+ /** Settle once every supervised promise has finished, including ones added while draining. */
8
+ drain(): Promise<void>;
9
+ }
10
+ export interface BackgroundTasksOptions {
11
+ /**
12
+ * Called for every rejection instead of the default log. Keep it cheap and non-throwing — a throw
13
+ * here is itself swallowed. NEVER log the error object: it may quote a clone URL with an embedded
14
+ * token.
15
+ */
16
+ onError?: (error: unknown) => void;
17
+ /** Prefix for the default log line, so a process running several of these can tell them apart. */
18
+ label?: string;
19
+ }
20
+ export declare function createBackgroundTasks(options?: BackgroundTasksOptions): BackgroundTasks;