@jini-ai/db 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE.pglite-socket +176 -0
- package/NOTICE.md +27 -0
- package/README.md +210 -0
- package/dist/core/artifact-naming.d.ts +34 -0
- package/dist/core/artifact-naming.js +34 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +10 -0
- package/dist/core/messages.d.ts +43 -0
- package/dist/core/messages.js +26 -0
- package/dist/core/pg-types.d.ts +22 -0
- package/dist/core/pg-types.js +26 -0
- package/dist/core/ports.d.ts +70 -0
- package/dist/core/ports.js +22 -0
- package/dist/core/row-values.d.ts +32 -0
- package/dist/core/row-values.js +42 -0
- package/dist/core/socket.d.ts +8 -0
- package/dist/core/socket.js +8 -0
- package/dist/kernel/dialect.d.ts +83 -0
- package/dist/kernel/dialect.js +191 -0
- package/dist/kernel/index.d.ts +15 -0
- package/dist/kernel/index.js +15 -0
- package/dist/kernel/kernel-core.d.ts +43 -0
- package/dist/kernel/kernel-core.js +98 -0
- package/dist/kernel/ops.d.ts +48 -0
- package/dist/kernel/ops.js +49 -0
- package/dist/kernel/pg-types.d.ts +22 -0
- package/dist/kernel/pg-types.js +26 -0
- package/dist/kernel/pglite/dialect.d.ts +11 -0
- package/dist/kernel/pglite/dialect.js +88 -0
- package/dist/kernel/pglite/driver.d.ts +30 -0
- package/dist/kernel/pglite/driver.js +47 -0
- package/dist/kernel/pglite/index.d.ts +5 -0
- package/dist/kernel/pglite/index.js +5 -0
- package/dist/kernel/pglite/ops.d.ts +39 -0
- package/dist/kernel/pglite/ops.js +78 -0
- package/dist/kernel/port.d.ts +82 -0
- package/dist/kernel/port.js +11 -0
- package/dist/kernel/postgres/driver.d.ts +23 -0
- package/dist/kernel/postgres/driver.js +42 -0
- package/dist/kernel/postgres/index.d.ts +5 -0
- package/dist/kernel/postgres/index.js +5 -0
- package/dist/kernel/postgres/ops.d.ts +12 -0
- package/dist/kernel/postgres/ops.js +46 -0
- package/dist/kernel/postgres/pglite-socket.d.ts +23 -0
- package/dist/kernel/postgres/pglite-socket.js +52 -0
- package/dist/kernel/postgres-lock.d.ts +8 -0
- package/dist/kernel/postgres-lock.js +10 -0
- package/dist/kernel/schema-scope.d.ts +14 -0
- package/dist/kernel/schema-scope.js +20 -0
- package/dist/kernel/schema-shape.d.ts +26 -0
- package/dist/kernel/schema-shape.js +83 -0
- package/dist/kernel/socket.d.ts +8 -0
- package/dist/kernel/socket.js +8 -0
- package/dist/kernel/sqlite/driver.d.ts +71 -0
- package/dist/kernel/sqlite/driver.js +132 -0
- package/dist/kernel/sqlite/index.d.ts +4 -0
- package/dist/kernel/sqlite/index.js +4 -0
- package/dist/kernel/sqlite/ops.d.ts +12 -0
- package/dist/kernel/sqlite/ops.js +40 -0
- package/dist/kernel/store-copy.d.ts +82 -0
- package/dist/kernel/store-copy.js +240 -0
- package/dist/kernel/turn-lock.d.ts +21 -0
- package/dist/kernel/turn-lock.js +42 -0
- package/dist/kernel/typegen.d.ts +13 -0
- package/dist/kernel/typegen.js +76 -0
- package/dist/migrate/checksum.d.ts +11 -0
- package/dist/migrate/checksum.js +14 -0
- package/dist/migrate/index.d.ts +8 -0
- package/dist/migrate/index.js +8 -0
- package/dist/migrate/runner.d.ts +33 -0
- package/dist/migrate/runner.js +126 -0
- package/dist/migrate/step.d.ts +37 -0
- package/dist/migrate/step.js +31 -0
- package/dist/pglite/dialect.d.ts +11 -0
- package/dist/pglite/dialect.js +88 -0
- package/dist/pglite/driver.d.ts +30 -0
- package/dist/pglite/driver.js +46 -0
- package/dist/pglite/index.d.ts +5 -0
- package/dist/pglite/index.js +4 -0
- package/dist/pglite/ops.d.ts +39 -0
- package/dist/pglite/ops.js +78 -0
- package/dist/pglite/owner.d.ts +107 -0
- package/dist/pglite/owner.js +359 -0
- package/dist/pglite/socket-server.d.ts +38 -0
- package/dist/pglite/socket-server.js +375 -0
- package/dist/pglite/types.d.ts +9 -0
- package/dist/pglite/types.js +2 -0
- package/dist/postgres/driver.d.ts +23 -0
- package/dist/postgres/driver.js +41 -0
- package/dist/postgres/index.d.ts +3 -0
- package/dist/postgres/index.js +3 -0
- package/dist/postgres/ops.d.ts +12 -0
- package/dist/postgres/ops.js +46 -0
- package/dist/postgres/pglite-socket.d.ts +23 -0
- package/dist/postgres/pglite-socket.js +51 -0
- package/dist/postgres/types.d.ts +53 -0
- package/dist/postgres/types.js +14 -0
- package/dist/sqlite/db-ops.d.ts +59 -0
- package/dist/sqlite/db-ops.js +82 -0
- package/dist/sqlite/driver.d.ts +71 -0
- package/dist/sqlite/driver.js +132 -0
- package/dist/sqlite/index.d.ts +9 -0
- package/dist/sqlite/index.js +4 -0
- package/dist/sqlite/inspect.d.ts +60 -0
- package/dist/sqlite/inspect.js +153 -0
- package/dist/sqlite/open.d.ts +58 -0
- package/dist/sqlite/open.js +43 -0
- package/dist/sqlite/ops.d.ts +12 -0
- package/dist/sqlite/ops.js +40 -0
- package/dist/sqlite/restore-types.d.ts +42 -0
- package/dist/sqlite/restore-types.js +2 -0
- package/dist/sqlite/sync-types.d.ts +34 -0
- package/dist/sqlite/sync-types.js +2 -0
- package/dist/sqlite/types.d.ts +37 -0
- package/dist/sqlite/types.js +8 -0
- package/dist/tools/database-catalog.d.ts +61 -0
- package/dist/tools/database-catalog.js +201 -0
- package/dist/tools/destination-port.d.ts +27 -0
- package/dist/tools/destination-port.js +2 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/plan-store.d.ts +61 -0
- package/dist/tools/plan-store.js +39 -0
- package/dist/tools/read-tools.d.ts +53 -0
- package/dist/tools/read-tools.js +97 -0
- package/dist/tools/registration.d.ts +18 -0
- package/dist/tools/registration.js +10 -0
- package/dist/tools/restore-points.d.ts +125 -0
- package/dist/tools/restore-points.js +54 -0
- package/dist/tools/surface-port.d.ts +43 -0
- package/dist/tools/surface-port.js +2 -0
- package/dist/tools/timeline.d.ts +63 -0
- package/dist/tools/timeline.js +46 -0
- package/dist/tools/transfer-catalog.d.ts +25 -0
- package/dist/tools/transfer-catalog.js +59 -0
- package/dist/tools/transfer-tools.d.ts +82 -0
- package/dist/tools/transfer-tools.js +346 -0
- package/dist/transfer/copy-engine.d.ts +129 -0
- package/dist/transfer/copy-engine.js +233 -0
- package/dist/transfer/index.d.ts +9 -0
- package/dist/transfer/index.js +9 -0
- package/dist/transfer/internal-ddl.d.ts +23 -0
- package/dist/transfer/internal-ddl.js +119 -0
- package/dist/transfer/plan.d.ts +28 -0
- package/dist/transfer/plan.js +19 -0
- package/dist/transfer/postgres-ddl.d.ts +36 -0
- package/dist/transfer/postgres-ddl.js +16 -0
- package/dist/transfer/postgres-target.d.ts +65 -0
- package/dist/transfer/postgres-target.js +95 -0
- package/dist/transfer/sqlite-source.d.ts +78 -0
- package/dist/transfer/sqlite-source.js +79 -0
- package/dist/transfer/table-catalog.d.ts +44 -0
- package/dist/transfer/table-catalog.js +109 -0
- package/dist/transfer/types.d.ts +47 -0
- package/dist/transfer/types.js +2 -0
- package/package.json +184 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applied when a caller passes no `pragmas`.
|
|
3
|
+
*
|
|
4
|
+
* Measured baseline (better-sqlite3 11.x opened with no pragmas at all): `foreign_keys=1`,
|
|
5
|
+
* `busy_timeout=5000`, `journal_mode='delete'` for a file db and `'memory'` for `:memory:`.
|
|
6
|
+
* So of the three below, **only `journal_mode = WAL` changes behaviour** — the other two restate a
|
|
7
|
+
* default the driver already applies.
|
|
8
|
+
*
|
|
9
|
+
* - `journal_mode = WAL` — the load-bearing one. Readers stop blocking the writer, which is what
|
|
10
|
+
* makes a single-file database viable under a web server's concurrent request load.
|
|
11
|
+
* - `foreign_keys = ON` — raw SQLite defaults this OFF for backwards compatibility and
|
|
12
|
+
* better-sqlite3 turns it back on. Restated so the guarantee survives a driver change rather
|
|
13
|
+
* than being silently inherited.
|
|
14
|
+
* - `busy_timeout = 5000` — a second connection (a plugin's own handle, a migration runner) can
|
|
15
|
+
* transiently hold a write lock; retrying inside the driver beats surfacing SQLITE_BUSY to a
|
|
16
|
+
* request handler with no better recourse than to retry anyway.
|
|
17
|
+
*
|
|
18
|
+
* Consequence worth knowing when writing tests: neither `foreign_keys` nor `busy_timeout` can tell
|
|
19
|
+
* you whether this list ran, because both read the same value if it did not. `journal_mode` on a
|
|
20
|
+
* file-backed database is the only usable probe.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_PRAGMAS = [
|
|
23
|
+
'journal_mode = WAL',
|
|
24
|
+
'foreign_keys = ON',
|
|
25
|
+
'busy_timeout = 5000',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Opens (or creates) a SQLite database and applies pragmas.
|
|
29
|
+
*
|
|
30
|
+
* Returns the exact handle supplied by the injected `open`, preserving its structural type.
|
|
31
|
+
* Recovery runs before opening; pragma policy runs immediately afterwards.
|
|
32
|
+
* @throws Any error from the recovery hook, opener, or pragma application.
|
|
33
|
+
* @complexity O(p) calls for p pragmas; storage costs belong to the injected driver.
|
|
34
|
+
*/
|
|
35
|
+
export function openSqliteConnection(options) {
|
|
36
|
+
options.recover?.(options.filePath);
|
|
37
|
+
const connection = options.open(options.filePath, {});
|
|
38
|
+
for (const pragma of options.pragmas ?? DEFAULT_PRAGMAS) {
|
|
39
|
+
connection.pragma(pragma);
|
|
40
|
+
}
|
|
41
|
+
return connection;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=open.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StorageKernel, type StorageOps } from "../kernel/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The storage ops (`@jini-ai/db/kernel`'s `StorageOps`) for a kernel the sqlite driver built:
|
|
4
|
+
* `VACUUM INTO` for the copy; `VACUUM` + WAL checkpoint + `integrity_check` for compacting. Must be
|
|
5
|
+
* used outside a transaction.
|
|
6
|
+
*
|
|
7
|
+
* @throws {Error} a kernel this driver did not build (no connection to act on); an op called inside
|
|
8
|
+
* a transaction.
|
|
9
|
+
* @complexity each op is one full pass over the database file, O(size).
|
|
10
|
+
*/
|
|
11
|
+
export declare function sqliteOps<DB>(kernel: StorageKernel<DB>): StorageOps;
|
|
12
|
+
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { outsideTransactionOf, StorageOpError } from "../kernel/index.js";
|
|
2
|
+
import { sqliteConnectionOf } from "./driver.js";
|
|
3
|
+
/**
|
|
4
|
+
* The storage ops (`@jini-ai/db/kernel`'s `StorageOps`) for a kernel the sqlite driver built:
|
|
5
|
+
* `VACUUM INTO` for the copy; `VACUUM` + WAL checkpoint + `integrity_check` for compacting. Must be
|
|
6
|
+
* used outside a transaction.
|
|
7
|
+
*
|
|
8
|
+
* @throws {Error} a kernel this driver did not build (no connection to act on); an op called inside
|
|
9
|
+
* a transaction.
|
|
10
|
+
* @complexity each op is one full pass over the database file, O(size).
|
|
11
|
+
*/
|
|
12
|
+
export function sqliteOps(kernel) {
|
|
13
|
+
const client = sqliteConnectionOf(kernel);
|
|
14
|
+
if (client === undefined)
|
|
15
|
+
throw new Error("sqliteOps: this SQLite kernel was not built by the sqlite driver");
|
|
16
|
+
const outsideTransaction = outsideTransactionOf(kernel);
|
|
17
|
+
return {
|
|
18
|
+
async copyTo(targetPath) {
|
|
19
|
+
outsideTransaction("copyTo");
|
|
20
|
+
// Bound parameter: VACUUM INTO takes an expression, so the path is never spliced into SQL.
|
|
21
|
+
client.prepare("VACUUM INTO ?").run(targetPath);
|
|
22
|
+
},
|
|
23
|
+
async compactAndVerify() {
|
|
24
|
+
outsideTransaction("compactAndVerify");
|
|
25
|
+
client.exec("VACUUM");
|
|
26
|
+
// WAL switch and checkpoint BEFORE integrity_check: running the check first on a just-VACUUMed
|
|
27
|
+
// connection reproducibly left a lock that failed the checkpoint with SQLITE_LOCKED.
|
|
28
|
+
client.pragma("journal_mode = WAL");
|
|
29
|
+
const [checkpoint] = client.pragma("wal_checkpoint(TRUNCATE)");
|
|
30
|
+
if (checkpoint === undefined || checkpoint.busy !== 0) {
|
|
31
|
+
throw new StorageOpError(`final WAL checkpoint on ${client.name} reported busy=${checkpoint?.busy}`);
|
|
32
|
+
}
|
|
33
|
+
const [integrity] = client.pragma("integrity_check");
|
|
34
|
+
if (integrity?.integrity_check !== "ok") {
|
|
35
|
+
throw new StorageOpError(`${client.name} failed integrity_check: ${JSON.stringify(integrity)}`);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ops.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SQLite driver type surface. Types only — no runtime declarations, so this module erases
|
|
3
|
+
* entirely at compile time.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here references an ORM. That is the point: a type on this package's public surface must
|
|
6
|
+
* be a plain structural shape, which crosses a
|
|
7
|
+
* package boundary cleanly. See `open.ts`'s module doc for the measured failure that made this a
|
|
8
|
+
* rule rather than a preference.
|
|
9
|
+
*/
|
|
10
|
+
import type { SqliteClient, SqliteOpener } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* A caller-injected hook run against `filePath` BEFORE the connection is opened.
|
|
13
|
+
*
|
|
14
|
+
* Dependency inversion on purpose: recovery policy (replaying a half-applied migration,
|
|
15
|
+
* quarantining a corrupt file) is host knowledge, and a persistence package reaching up into host
|
|
16
|
+
* feature code to fetch it would be a layer-direction violation. The hook is optional, but when
|
|
17
|
+
* supplied it runs for every path, including `:memory:`. A host with file-only recovery must make
|
|
18
|
+
* its hook a no-op for ephemeral connections and hermetic tests, where there is nothing to recover.
|
|
19
|
+
*/
|
|
20
|
+
export type SqliteRecoveryHook = (filePath: string) => void;
|
|
21
|
+
export interface OpenSqliteConnectionOptions<Connection extends SqliteClient = SqliteClient> {
|
|
22
|
+
/** The consumer opens with its own driver copy. */
|
|
23
|
+
readonly open: SqliteOpener<Connection>;
|
|
24
|
+
/** Filesystem path, or `':memory:'` for an ephemeral connection. */
|
|
25
|
+
readonly filePath: string;
|
|
26
|
+
/**
|
|
27
|
+
* Pragma statements applied immediately after open, **replacing** (not extending) the defaults.
|
|
28
|
+
* Pass the full list you want; see `DEFAULT_PRAGMAS` for what you are replacing and why each
|
|
29
|
+
* default is there.
|
|
30
|
+
*/
|
|
31
|
+
readonly pragmas?: readonly string[];
|
|
32
|
+
readonly recover?: SqliteRecoveryHook;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The minimum a caller must supply for restore-point capture: the raw driver's online-backup
|
|
36
|
+
* method and nothing else. Structurally minimal so a host can pass a real connection or a narrow
|
|
37
|
+
* test double, and so this package never needs to name the host's ORM handle type.
|
|
38
|
+
*/
|
|
39
|
+
export type SqliteBackupSource = {
|
|
40
|
+
backup(destination: string): Promise<unknown>;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=restore-types.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Structural synchronous SQLite contract for legacy CRUD; the host owns the driver. */
|
|
2
|
+
import type { SqliteClient, SqliteOpenOptions } from './types.js';
|
|
3
|
+
/** Prepared query preserving typed positional bindings and rows. */
|
|
4
|
+
export interface SqliteSyncStatement<Parameters extends unknown[] = unknown[], Result = unknown> {
|
|
5
|
+
readonly reader: boolean;
|
|
6
|
+
run(...parameters: Parameters): {
|
|
7
|
+
changes: number | bigint;
|
|
8
|
+
lastInsertRowid: number | bigint;
|
|
9
|
+
};
|
|
10
|
+
get(...parameters: Parameters): Result | undefined;
|
|
11
|
+
all(...parameters: Parameters): Result[];
|
|
12
|
+
iterate(...parameters: Parameters): IterableIterator<Result>;
|
|
13
|
+
}
|
|
14
|
+
/** Callable transaction with the driver's explicit lock modes. */
|
|
15
|
+
export interface SqliteSyncTransaction<Args extends unknown[], Result> {
|
|
16
|
+
(...args: Args): Result;
|
|
17
|
+
deferred(...args: Args): Result;
|
|
18
|
+
immediate(...args: Args): Result;
|
|
19
|
+
exclusive(...args: Args): Result;
|
|
20
|
+
}
|
|
21
|
+
/** Separate sync API; the kernel's minimal SqliteClient remains unchanged. */
|
|
22
|
+
export interface SqliteSyncClient extends SqliteClient {
|
|
23
|
+
readonly open: boolean;
|
|
24
|
+
prepare<Parameters extends unknown[] | object = unknown[], Result = unknown>(source: string): Parameters extends unknown[] ? SqliteSyncStatement<Parameters, Result> : SqliteSyncStatement<[Parameters], Result>;
|
|
25
|
+
pragma(source: string, options?: {
|
|
26
|
+
simple?: boolean;
|
|
27
|
+
}): unknown;
|
|
28
|
+
transaction<Args extends unknown[], Result>(body: (...args: Args) => Result): SqliteSyncTransaction<Args, Result>;
|
|
29
|
+
}
|
|
30
|
+
/** Published 0.3.x alias, now structural rather than tied to a driver installation. */
|
|
31
|
+
export type SqliteDb = SqliteSyncClient;
|
|
32
|
+
/** Host acquisition seam, also preserving an actual driver's richer handle type. */
|
|
33
|
+
export type SqliteSyncOpener<Connection extends SqliteSyncClient = SqliteSyncClient> = (file: string, options: SqliteOpenOptions) => Connection;
|
|
34
|
+
//# sourceMappingURL=sync-types.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The slice of a better-sqlite3 connection this package uses, written structurally so the
|
|
3
|
+
* package needs neither better-sqlite3 nor its types: a consumer's own `Database` instance satisfies
|
|
4
|
+
* it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
|
|
5
|
+
* and a linked dev copy of this package's) from becoming two incompatible nominal types.
|
|
6
|
+
*/
|
|
7
|
+
/** A prepared statement, as much of one as the Kysely binding shim and the ops call. */
|
|
8
|
+
export interface SqliteStatement {
|
|
9
|
+
readonly reader: boolean;
|
|
10
|
+
all(...parameters: unknown[]): unknown[];
|
|
11
|
+
run(...parameters: unknown[]): {
|
|
12
|
+
changes: number | bigint;
|
|
13
|
+
lastInsertRowid: number | bigint;
|
|
14
|
+
};
|
|
15
|
+
iterate(...parameters: unknown[]): IterableIterator<unknown>;
|
|
16
|
+
}
|
|
17
|
+
/** A better-sqlite3 `Database`. */
|
|
18
|
+
export interface SqliteClient {
|
|
19
|
+
/** True for `:memory:` and other private in-memory databases. */
|
|
20
|
+
readonly memory: boolean;
|
|
21
|
+
/** The path it was opened with. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly inTransaction: boolean;
|
|
24
|
+
exec(source: string): unknown;
|
|
25
|
+
prepare(source: string): SqliteStatement;
|
|
26
|
+
pragma(source: string): unknown;
|
|
27
|
+
backup(destinationFile: string): Promise<unknown>;
|
|
28
|
+
close(): unknown;
|
|
29
|
+
}
|
|
30
|
+
/** better-sqlite3's constructor options this package passes. */
|
|
31
|
+
export interface SqliteOpenOptions {
|
|
32
|
+
readonly?: boolean;
|
|
33
|
+
fileMustExist?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The consumer's way to open a connection with ITS copy of better-sqlite3: `(p, o) => new Database(p, o)`. */
|
|
36
|
+
export type SqliteOpener<Connection extends SqliteClient = SqliteClient> = (filePath: string, options: SqliteOpenOptions) => Connection;
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The slice of a better-sqlite3 connection this package uses, written structurally so the
|
|
3
|
+
* package needs neither better-sqlite3 nor its types: a consumer's own `Database` instance satisfies
|
|
4
|
+
* it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
|
|
5
|
+
* and a linked dev copy of this package's) from becoming two incompatible nominal types.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file the Database domain's
|
|
3
|
+
* agent-tool catalog, instantiating naming/callability convention.
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* A static, in-process catalog describing every agent-callable tool this domain exposes and the
|
|
7
|
+
* permission/actor-class rule each one carries. Reads are freely agent-callable under
|
|
8
|
+
* `database.read`; the one destructive tool (`database_execute_migrate_forward`) is token-gated,
|
|
9
|
+
* restricted to `confirmer-must-equal-own-delegatedBy`, and asks the human in chat before it runs. Restore is deliberately absent from this
|
|
10
|
+
* catalog — an agent asking to "roll back" only ever reaches a guidance/deep-link tool, never a
|
|
11
|
+
* lever ("Restore is a Recovery tool, not a Database tool").
|
|
12
|
+
*
|
|
13
|
+
* Widened this dispatch (`assistant/tool-registrations.ts`'s wiring pass) with `description` and
|
|
14
|
+
* `inputSchema` — this file previously declared id/sideEffects/authorization only, one layer short
|
|
15
|
+
* of what `tool-registrations.ts` requires to actually publish a tool to the model (mirrors
|
|
16
|
+
* core's `AgentToolDefinition` shape; `inputSchema` stays OPTIONAL, as in
|
|
17
|
+
* `features/content-types/agent-tools.ts`, because 1 of these 9 entries is still declared but
|
|
18
|
+
* deliberately never wired — see `tool-registrations.ts`'s `UNWIRED_DATABASE_TOOL_IDS`:
|
|
19
|
+
* `database_get_restore_guidance` has no envelope-minting function to compose (only the RECEIVING
|
|
20
|
+
* side, `recovery/deep-link.ts`'s `resolveDeepLinkContext`, exists — building one would mean
|
|
21
|
+
* composing a fresh `correlationId`/`restorePointId`/ledger-event lookup on top of a cross-domain
|
|
22
|
+
* envelope format, new backend work well past a wiring pass, not a natural extension of the
|
|
23
|
+
* read-only introspection adapter below).
|
|
24
|
+
*
|
|
25
|
+
* A later dispatch built `features/database/adapter.sqlite.ts` (`DatabaseIntrospectionPort`,
|
|
26
|
+
* composed into `RouteDeps` as `databaseIntrospection` in both `server/deps.ts` and `server/app.ts`)
|
|
27
|
+
* and wired `database_get_health`/`database_get_schema_state`/`content_read.database_pending_migration`
|
|
28
|
+
* against it — see each entry's own comment below and `tool-registrations.ts`'s handlers.
|
|
29
|
+
*
|
|
30
|
+
* How it relates to the project:
|
|
31
|
+
* The server-side tool filter consumes this catalog to decide which tool names an agent
|
|
32
|
+
* session may even see; `authorize` and the confirmation-token gateway
|
|
33
|
+
* (`core/gated-mutations`) enforce the actual permission/actor-class checks at call time — this
|
|
34
|
+
* module only declares the catalog shape, it performs no I/O and no enforcement itself.
|
|
35
|
+
*
|
|
36
|
+
* Shared catalog types (AgentToolSideEffect, AgentToolActorClassRule and AgentToolDefinition)
|
|
37
|
+
* live once in core. JSON Schema for a tool's input is published to the model through
|
|
38
|
+
* ToolDescriptor.inputSchema; the host wiring refuses to publish an entry without one.
|
|
39
|
+
* The property remains optional on the catalog contract: deliberately unwired entries
|
|
40
|
+
* carry no schema because the model never sees them. Adopting core's wider side-effect
|
|
41
|
+
* vocabulary does not change the independently checked risk of any catalog entry.
|
|
42
|
+
*
|
|
43
|
+
* Architectural role:
|
|
44
|
+
* Database tool contracts use the shared core catalog vocabulary; no driver dependencies.
|
|
45
|
+
* See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
46
|
+
*/
|
|
47
|
+
import type { AgentToolDefinition } from "@jini-ai/core";
|
|
48
|
+
import { type DbMessages } from "../core/messages.js";
|
|
49
|
+
/**
|
|
50
|
+
* The Database domain's fixed agent-tool contracts (D4), with fresh host-facing prose.
|
|
51
|
+
* @param _optional.messages Host copy; omitted messages use the neutral defaultDbMessages.
|
|
52
|
+
* @returns Nine definitions with unchanged IDs, permissions, risk and input validation.
|
|
53
|
+
*
|
|
54
|
+
* @complexity O(1) — a fixed, statically-defined list.
|
|
55
|
+
* @overallScore 100
|
|
56
|
+
* See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getDatabaseAgentToolCatalog(_required?: Record<string, never>, _optional?: {
|
|
59
|
+
messages?: DbMessages;
|
|
60
|
+
}): AgentToolDefinition[];
|
|
61
|
+
//# sourceMappingURL=database-catalog.d.ts.map
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file the Database domain's
|
|
3
|
+
* agent-tool catalog, instantiating naming/callability convention.
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* A static, in-process catalog describing every agent-callable tool this domain exposes and the
|
|
7
|
+
* permission/actor-class rule each one carries. Reads are freely agent-callable under
|
|
8
|
+
* `database.read`; the one destructive tool (`database_execute_migrate_forward`) is token-gated,
|
|
9
|
+
* restricted to `confirmer-must-equal-own-delegatedBy`, and asks the human in chat before it runs. Restore is deliberately absent from this
|
|
10
|
+
* catalog — an agent asking to "roll back" only ever reaches a guidance/deep-link tool, never a
|
|
11
|
+
* lever ("Restore is a Recovery tool, not a Database tool").
|
|
12
|
+
*
|
|
13
|
+
* Widened this dispatch (`assistant/tool-registrations.ts`'s wiring pass) with `description` and
|
|
14
|
+
* `inputSchema` — this file previously declared id/sideEffects/authorization only, one layer short
|
|
15
|
+
* of what `tool-registrations.ts` requires to actually publish a tool to the model (mirrors
|
|
16
|
+
* core's `AgentToolDefinition` shape; `inputSchema` stays OPTIONAL, as in
|
|
17
|
+
* `features/content-types/agent-tools.ts`, because 1 of these 9 entries is still declared but
|
|
18
|
+
* deliberately never wired — see `tool-registrations.ts`'s `UNWIRED_DATABASE_TOOL_IDS`:
|
|
19
|
+
* `database_get_restore_guidance` has no envelope-minting function to compose (only the RECEIVING
|
|
20
|
+
* side, `recovery/deep-link.ts`'s `resolveDeepLinkContext`, exists — building one would mean
|
|
21
|
+
* composing a fresh `correlationId`/`restorePointId`/ledger-event lookup on top of a cross-domain
|
|
22
|
+
* envelope format, new backend work well past a wiring pass, not a natural extension of the
|
|
23
|
+
* read-only introspection adapter below).
|
|
24
|
+
*
|
|
25
|
+
* A later dispatch built `features/database/adapter.sqlite.ts` (`DatabaseIntrospectionPort`,
|
|
26
|
+
* composed into `RouteDeps` as `databaseIntrospection` in both `server/deps.ts` and `server/app.ts`)
|
|
27
|
+
* and wired `database_get_health`/`database_get_schema_state`/`content_read.database_pending_migration`
|
|
28
|
+
* against it — see each entry's own comment below and `tool-registrations.ts`'s handlers.
|
|
29
|
+
*
|
|
30
|
+
* How it relates to the project:
|
|
31
|
+
* The server-side tool filter consumes this catalog to decide which tool names an agent
|
|
32
|
+
* session may even see; `authorize` and the confirmation-token gateway
|
|
33
|
+
* (`core/gated-mutations`) enforce the actual permission/actor-class checks at call time — this
|
|
34
|
+
* module only declares the catalog shape, it performs no I/O and no enforcement itself.
|
|
35
|
+
*
|
|
36
|
+
* Shared catalog types (AgentToolSideEffect, AgentToolActorClassRule and AgentToolDefinition)
|
|
37
|
+
* live once in core. JSON Schema for a tool's input is published to the model through
|
|
38
|
+
* ToolDescriptor.inputSchema; the host wiring refuses to publish an entry without one.
|
|
39
|
+
* The property remains optional on the catalog contract: deliberately unwired entries
|
|
40
|
+
* carry no schema because the model never sees them. Adopting core's wider side-effect
|
|
41
|
+
* vocabulary does not change the independently checked risk of any catalog entry.
|
|
42
|
+
*
|
|
43
|
+
* Architectural role:
|
|
44
|
+
* Database tool contracts use the shared core catalog vocabulary; no driver dependencies.
|
|
45
|
+
* See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
46
|
+
*/
|
|
47
|
+
import { defaultDbMessages } from "../core/messages.js";
|
|
48
|
+
/** No arguments — shared by every parameterless read tool in this catalog. */
|
|
49
|
+
const NO_INPUT_SCHEMA = {
|
|
50
|
+
type: "object",
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
required: [],
|
|
53
|
+
properties: {},
|
|
54
|
+
};
|
|
55
|
+
/** `database_query_timeline`'s filter — mirrors `features/database/timeline.ts`'s `getTimeline` filter shape and `routes/admin/database/timeline.ts`'s query-string parsing 1:1. */
|
|
56
|
+
const TIMELINE_QUERY_SCHEMA = {
|
|
57
|
+
type: "object",
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
required: [],
|
|
60
|
+
properties: {
|
|
61
|
+
kind: { type: "string", description: "Filter by ledger row kind (e.g. 'core.migration', 'restore.executed'). Omit for all kinds." },
|
|
62
|
+
outcome: { type: "string", description: "Filter by outcome (e.g. 'success', 'failure'). Omit for all outcomes." },
|
|
63
|
+
fromDate: { type: "string", description: "ISO-8601 inclusive lower bound on createdAt. Omit for no lower bound." },
|
|
64
|
+
toDate: { type: "string", description: "ISO-8601 inclusive upper bound on createdAt. Omit for no upper bound." },
|
|
65
|
+
cursor: { type: "string", description: "Opaque pagination cursor from a previous call's own nextCursor. Omit to start from the newest row." },
|
|
66
|
+
limit: { type: "integer", minimum: 1, maximum: 200, description: "Max rows to return. Server-capped at 200 regardless of what is requested; defaults to 50 when omitted." },
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The Database domain's fixed agent-tool contracts (D4), with fresh host-facing prose.
|
|
71
|
+
* @param _optional.messages Host copy; omitted messages use the neutral defaultDbMessages.
|
|
72
|
+
* @returns Nine definitions with unchanged IDs, permissions, risk and input validation.
|
|
73
|
+
*
|
|
74
|
+
* @complexity O(1) — a fixed, statically-defined list.
|
|
75
|
+
* @overallScore 100
|
|
76
|
+
* See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
77
|
+
*/
|
|
78
|
+
export function getDatabaseAgentToolCatalog(_required = {}, _optional = {}) {
|
|
79
|
+
const messages = _optional.messages ?? defaultDbMessages;
|
|
80
|
+
/** `backup_create_restore_point`'s input. `trigger` is deliberately NOT a model-settable field —
|
|
81
|
+
* every agent-initiated restore point is stamped `trigger:'manual'` server-side regardless of what
|
|
82
|
+
* is asked for, so the ledger's provenance trail cannot be mislabeled (e.g. as `'pre-migration-auto'`,
|
|
83
|
+
* a value that is only ever true when the SYSTEM itself takes the snapshot). */
|
|
84
|
+
const CREATE_RESTORE_POINT_SCHEMA = {
|
|
85
|
+
type: "object",
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
required: [],
|
|
88
|
+
properties: {
|
|
89
|
+
costAck: {
|
|
90
|
+
type: "boolean",
|
|
91
|
+
description:
|
|
92
|
+
// See docs/decisions/DR-001-bounded-operational-timeline.md for the invariant behind this refusal; keep external identifiers out of caller-facing messages.
|
|
93
|
+
messages.restorePointCostAck,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
// WIRED (tool-registrations.ts) against `adapter.sqlite.ts`'s `DatabaseIntrospectionPort.getHealth()`
|
|
100
|
+
// — connectivity + `__drizzle_migrations` readability + drift status, exactly what that
|
|
101
|
+
// method computes. Deliberately does NOT report disk headroom or interrupted-migration state
|
|
102
|
+
// despite this description's own wording — no adapter for either exists yet (disk headroom
|
|
103
|
+
// has no seam anywhere in this codebase; interrupted-migration state lives on
|
|
104
|
+
// `migrationRunsRepo`/`siteStatusRepo`, a separate port this tool does not read), so this
|
|
105
|
+
// stays a minimal, honest subset rather than fabricating fields the description implies.
|
|
106
|
+
name: "database_get_health",
|
|
107
|
+
description: messages.databaseHealth,
|
|
108
|
+
sideEffects: "none",
|
|
109
|
+
authorization: { permission: "database.read" },
|
|
110
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
// WIRED (tool-registrations.ts) against `adapter.sqlite.ts`'s `DatabaseIntrospectionPort.getSchemaState()`,
|
|
114
|
+
// which reads the two real `SchemaSnapshot`s (`.site-meta.json`, `__drizzle_migrations`) this
|
|
115
|
+
// entry's own comment used to say no adapter supplied, and passes them through `drift.ts`'s
|
|
116
|
+
// `getDriftStatus` unchanged.
|
|
117
|
+
name: "database_get_schema_state",
|
|
118
|
+
description: messages.databaseSchemaState,
|
|
119
|
+
sideEffects: "none",
|
|
120
|
+
authorization: { permission: "database.read" },
|
|
121
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
// WIRED (tool-registrations.ts) against `adapter.sqlite.ts`'s `DatabaseIntrospectionPort.listPendingMigrations()`
|
|
125
|
+
// — diffs the bundled `db/drizzle/meta/_journal.json` against `__drizzle_migrations`'s
|
|
126
|
+
// applied rows. Note this is the Drizzle-migration-file sense of "pending", distinct from
|
|
127
|
+
// `migration_runs`'s own in-flight-migration-run tracking (`boot/reconcile-interrupted-migration.ts`).
|
|
128
|
+
name: "database_list_pending_migrations",
|
|
129
|
+
description: messages.databasePendingMigrations,
|
|
130
|
+
sideEffects: "none",
|
|
131
|
+
authorization: { permission: "database.read" },
|
|
132
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "database_query_timeline",
|
|
136
|
+
description: "Returns a filtered, cursor-paginated page of the append-only database ledger (migrations, snapshots, restores, interrupted migrations), newest first.",
|
|
137
|
+
sideEffects: "none",
|
|
138
|
+
authorization: { permission: "database.read" },
|
|
139
|
+
inputSchema: TIMELINE_QUERY_SCHEMA,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "database_list_restore_points",
|
|
143
|
+
description: messages.databaseRestorePoints,
|
|
144
|
+
sideEffects: "none",
|
|
145
|
+
authorization: { permission: "database.read" },
|
|
146
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
// database_plan_migrate_forward is a read : it recomputes and returns a plan,. See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
150
|
+
// never mutates durable state. Verified directly against `core/gated-mutations/gateway.ts`'s
|
|
151
|
+
// `plan()`, which persists nothing — it authorizes, calls `hooks.computePlan()`, and returns
|
|
152
|
+
// the result. Safe to wire despite migrate-forward's overall high-risk classification: the
|
|
153
|
+
// step that actually redeems a plan into a mutation (`confirm()`) can never be reached by an
|
|
154
|
+
// agent principal at all (the gateway's own actor-class rule reserves `confirm()` for a
|
|
155
|
+
// human/api_key caller — ), and no tool in this catalog exposes `confirm`. See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
156
|
+
name: "database_plan_migrate_forward",
|
|
157
|
+
description: messages.databasePlanMigrate,
|
|
158
|
+
sideEffects: "none",
|
|
159
|
+
authorization: { permission: "database.read" },
|
|
160
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
// Asks the human in chat first (2026-09-24): wired with `humanConfirmedToolHandler`, which
|
|
164
|
+
// shows a confirm dialog and, only on the human's own click, confirms as that human and
|
|
165
|
+
// executes as the agent acting for them. A migrate-forward affects every domain at once, so
|
|
166
|
+
// it stays gated; the model never sees or supplies a token.
|
|
167
|
+
name: "database_execute_migrate_forward",
|
|
168
|
+
description: messages.databaseExecuteMigrate,
|
|
169
|
+
sideEffects: "mutates-durable-state",
|
|
170
|
+
authorization: { permission: "database.migrate" },
|
|
171
|
+
inputSchema: NO_INPUT_SCHEMA,
|
|
172
|
+
actorClassRule: "confirmer-must-equal-own-delegatedBy",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
// Canonical wiring lives in `buildDatabaseRegistrations` (tool-registrations.ts) — §6. See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
176
|
+
// names this as "the named tool for the `backup.create` permission" on the Storage/Database
|
|
177
|
+
// domain. `features/recovery/agent-tools.ts` also declares an entry of this same name (a
|
|
178
|
+
// pre-existing cross-domain id collision this dispatch found, not introduced by it); that
|
|
179
|
+
// entry is deliberately left unwired in Recovery's own build function — see its file header.
|
|
180
|
+
name: "backup_create_restore_point",
|
|
181
|
+
description: messages.databaseCreateRestorePoint,
|
|
182
|
+
sideEffects: "mutates-durable-state",
|
|
183
|
+
authorization: { permission: "backup.create" },
|
|
184
|
+
inputSchema: CREATE_RESTORE_POINT_SCHEMA,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
// NOT WIRED (tool-registrations.ts): the rollback hand-off — an agent never gets a restore
|
|
188
|
+
// lever from this domain, only a deep-link routing envelope pointing at the Recovery surface
|
|
189
|
+
//. No envelope-MINTING function exists in this codebase yet (only the receiving. See docs/decisions/DR-001-bounded-operational-timeline.md.
|
|
190
|
+
// side, `recovery/deep-link.ts`'s `resolveDeepLinkContext`, does) and minting one honestly
|
|
191
|
+
// needs a real schema-drift computation this dispatch has no adapter for — see
|
|
192
|
+
// `database_get_schema_state`'s own note. Fabricating a placeholder `drift` value would
|
|
193
|
+
// violate this codebase's own "never fabricate" discipline (`disclosure.ts`'s identical rule).
|
|
194
|
+
name: "database_get_restore_guidance",
|
|
195
|
+
description: messages.databaseRestoreGuidance,
|
|
196
|
+
sideEffects: "none",
|
|
197
|
+
authorization: { permission: "database.read" },
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=database-catalog.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TargetDescription } from "../transfer/postgres-target.js";
|
|
2
|
+
export interface SavedDatabaseDestination {
|
|
3
|
+
readonly connectionString: string;
|
|
4
|
+
readonly description: TargetDescription;
|
|
5
|
+
readonly savedAt: string;
|
|
6
|
+
}
|
|
7
|
+
/** What `database_transfer_status` reports about the last run. Never row data, never the address. */
|
|
8
|
+
export type DatabaseTransferRunSummary = {
|
|
9
|
+
readonly copied: true;
|
|
10
|
+
readonly snapshotAt: string;
|
|
11
|
+
readonly tableCount: number;
|
|
12
|
+
readonly rowCount: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly copied: false;
|
|
15
|
+
readonly snapshotAt: string;
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly message: string;
|
|
18
|
+
};
|
|
19
|
+
export interface DatabaseDestinationStorePort {
|
|
20
|
+
/** @throws {DestinationUnreadableError} When a saved address exists but cannot be opened. */
|
|
21
|
+
get(workspaceId: string): Promise<SavedDatabaseDestination | null>;
|
|
22
|
+
/** Replaces any earlier destination for the workspace, and forgets its last run. */
|
|
23
|
+
save(workspaceId: string, destination: SavedDatabaseDestination): Promise<void>;
|
|
24
|
+
lastRun(workspaceId: string): Promise<DatabaseTransferRunSummary | null>;
|
|
25
|
+
recordRun(workspaceId: string, summary: DatabaseTransferRunSummary): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=destination-port.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Portable database assistant tools use core contracts; no Kysely/driver is loaded here. */
|
|
2
|
+
export * from "./database-catalog.js";
|
|
3
|
+
export { databaseTransferAgentToolCatalog, getDatabaseTransferAgentToolCatalog } from "./transfer-catalog.js";
|
|
4
|
+
export { defaultDbMessages, type DbTransferMessages, type DbMessages } from "../core/messages.js";
|
|
5
|
+
export * from "./read-tools.js";
|
|
6
|
+
export * from "./transfer-tools.js";
|
|
7
|
+
export * from "./timeline.js";
|
|
8
|
+
export * from "./restore-points.js";
|
|
9
|
+
export * from "./plan-store.js";
|
|
10
|
+
export * from "./destination-port.js";
|
|
11
|
+
export type { InputReaders } from "./registration.js";
|
|
12
|
+
export type { TransferSurfacePorts, SurfaceExchange, SurfaceMessage } from "./surface-port.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Portable database assistant tools use core contracts; no Kysely/driver is loaded here. */
|
|
2
|
+
export * from "./database-catalog.js";
|
|
3
|
+
export { databaseTransferAgentToolCatalog, getDatabaseTransferAgentToolCatalog } from "./transfer-catalog.js";
|
|
4
|
+
export { defaultDbMessages } from "../core/messages.js";
|
|
5
|
+
export * from "./read-tools.js";
|
|
6
|
+
export * from "./transfer-tools.js";
|
|
7
|
+
export * from "./timeline.js";
|
|
8
|
+
export * from "./restore-points.js";
|
|
9
|
+
export * from "./plan-store.js";
|
|
10
|
+
export * from "./destination-port.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { TargetDescription } from "../transfer/postgres-target.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file Holds a planned copy between `database_transfer_plan` and `database_transfer_run`: the
|
|
4
|
+
* database snapshot bytes (so the run copies exactly what was planned, "the site as of HH:MM"), the
|
|
5
|
+
* row counts shown to the human, and the connection string. In memory only — a restart drops every
|
|
6
|
+
* plan — single-use, bound to the principal and workspace that made it, and gone after 10 minutes.
|
|
7
|
+
* The connection string lives here and nowhere else, and is never returned by any tool.
|
|
8
|
+
*/
|
|
9
|
+
export interface DatabaseTransferPlanContent {
|
|
10
|
+
readonly connectionString: string;
|
|
11
|
+
readonly destination: TargetDescription;
|
|
12
|
+
/** The earlier copy this one replaces, by its source snapshot time; `null` for a first copy. */
|
|
13
|
+
readonly replaces: string | null;
|
|
14
|
+
readonly snapshot: Buffer;
|
|
15
|
+
/** Immutable bytes of the second, separately captured database. Both captures precede planning. */
|
|
16
|
+
readonly chatSnapshot?: Buffer;
|
|
17
|
+
readonly snapshotAt: string;
|
|
18
|
+
readonly site: string;
|
|
19
|
+
/** The private schema this site's copy goes to, chosen by `inspectTarget` at plan time. */
|
|
20
|
+
readonly schema: string;
|
|
21
|
+
readonly tableCount: number;
|
|
22
|
+
readonly rowCount: number;
|
|
23
|
+
readonly leftOut: readonly {
|
|
24
|
+
readonly table: string;
|
|
25
|
+
readonly rows: number;
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
export interface DatabaseTransferPlan extends DatabaseTransferPlanContent {
|
|
30
|
+
readonly planId: string;
|
|
31
|
+
readonly principalId: string;
|
|
32
|
+
readonly workspaceId: string;
|
|
33
|
+
readonly expiresAtMs: number;
|
|
34
|
+
}
|
|
35
|
+
export type TakeDatabaseTransferPlanResult = {
|
|
36
|
+
ok: true;
|
|
37
|
+
plan: DatabaseTransferPlan;
|
|
38
|
+
} | {
|
|
39
|
+
ok: false;
|
|
40
|
+
code: "PLAN_NOT_FOUND" | "PLAN_EXPIRED";
|
|
41
|
+
};
|
|
42
|
+
export declare class DatabaseTransferPlanStore {
|
|
43
|
+
private readonly plans;
|
|
44
|
+
private readonly now;
|
|
45
|
+
constructor(_required?: Record<string, never>, optional?: {
|
|
46
|
+
now?: () => number;
|
|
47
|
+
});
|
|
48
|
+
/** @complexity O(plans held), at most {@link DEFAULT_MAX_PLANS}. */
|
|
49
|
+
save(input: {
|
|
50
|
+
principalId: string;
|
|
51
|
+
workspaceId: string;
|
|
52
|
+
content: DatabaseTransferPlanContent;
|
|
53
|
+
}, _optional?: {}): DatabaseTransferPlan;
|
|
54
|
+
/** Single-use: a taken plan is gone whether or not it is still valid. */
|
|
55
|
+
take(input: {
|
|
56
|
+
planId: string;
|
|
57
|
+
principalId: string;
|
|
58
|
+
workspaceId: string;
|
|
59
|
+
}, _optional?: {}): TakeDatabaseTransferPlanResult;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=plan-store.d.ts.map
|