@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,126 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
import { listTables, tableExists } from "../kernel/index.js";
|
|
5
|
+
import { MIGRATION_ID, MigrationChecksumError, UnknownAppliedMigrationError, } from "./step.js";
|
|
6
|
+
function ledgerFor(kernel, options) {
|
|
7
|
+
const table = options.ledgerTable;
|
|
8
|
+
if (typeof table !== "string" || table.length === 0)
|
|
9
|
+
throw new Error("runMigrations: options.ledgerTable is required");
|
|
10
|
+
const { schema } = options;
|
|
11
|
+
if (schema !== undefined && kernel.dialect !== "postgres")
|
|
12
|
+
throw new Error(`a migration ledger schema ('${schema}') needs Postgres, not ${kernel.dialect}`);
|
|
13
|
+
const store = kernel;
|
|
14
|
+
return {
|
|
15
|
+
table,
|
|
16
|
+
schema,
|
|
17
|
+
lockKey: schema === undefined ? table : `${schema}.${table}`,
|
|
18
|
+
run: (fn) => store.run((db) => fn(schema === undefined ? db : db.withSchema(schema))),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Throws on duplicate, unordered or malformed ids and on a checksum that is not sha256 hex. */
|
|
22
|
+
export function assertValidSteps(steps) {
|
|
23
|
+
let previous = "";
|
|
24
|
+
for (const step of steps) {
|
|
25
|
+
if (!MIGRATION_ID.test(step.id))
|
|
26
|
+
throw new Error(`migration id '${step.id}' is not NNNN_snake_name`);
|
|
27
|
+
if (step.id <= previous)
|
|
28
|
+
throw new Error(`migration '${step.id}' is out of order or duplicated (after '${previous}')`);
|
|
29
|
+
if (!/^[0-9a-f]{64}$/.test(step.checksum))
|
|
30
|
+
throw new Error(`migration '${step.id}' has no sha256 checksum`);
|
|
31
|
+
previous = step.id;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Inside the step's transaction, under the lock: two Postgres sessions racing `CREATE TABLE IF NOT
|
|
35
|
+
* EXISTS` can otherwise still collide. Created with the first step, so a backup a step takes in
|
|
36
|
+
* `prepare` is the database exactly as it was. */
|
|
37
|
+
async function ensureLedger(kernel, ledger) {
|
|
38
|
+
if (ledger.schema !== undefined)
|
|
39
|
+
await kernel.run((db) => db.schema.createSchema(ledger.schema).ifNotExists().execute());
|
|
40
|
+
await ledger.run((db) => db.schema
|
|
41
|
+
.createTable(ledger.table)
|
|
42
|
+
.ifNotExists()
|
|
43
|
+
.addColumn("id", "text", (column) => column.primaryKey())
|
|
44
|
+
.addColumn("checksum", "text", (column) => column.notNull())
|
|
45
|
+
.addColumn("applied_at", "text", (column) => column.notNull())
|
|
46
|
+
.execute());
|
|
47
|
+
}
|
|
48
|
+
async function readLedger(ledger) {
|
|
49
|
+
return ledger.run((db) => db.selectFrom(ledger.table).selectAll().orderBy("id").execute());
|
|
50
|
+
}
|
|
51
|
+
function verifyRecorded(rows, steps, appName) {
|
|
52
|
+
const known = new Map(steps.map((step) => [step.id, step]));
|
|
53
|
+
const unknown = rows.filter((row) => !known.has(row.id)).map((row) => row.id);
|
|
54
|
+
if (unknown.length > 0)
|
|
55
|
+
throw new UnknownAppliedMigrationError(unknown, appName);
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const step = known.get(row.id);
|
|
58
|
+
if (row.checksum !== step.checksum)
|
|
59
|
+
throw new MigrationChecksumError(row.id, row.checksum, step.checksum);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Applies every pending step of `steps`, in order, to `kernel`'s database.
|
|
64
|
+
*
|
|
65
|
+
* @param options.ledgerTable the ledger table (required).
|
|
66
|
+
* @param options.backupPath where an existing database is copied before the first pending step.
|
|
67
|
+
* @throws UnknownAppliedMigrationError / MigrationChecksumError before applying anything; whatever a
|
|
68
|
+
* step throws (its transaction is rolled back, later steps are not attempted).
|
|
69
|
+
*/
|
|
70
|
+
export async function runMigrations(kernel, steps, options) {
|
|
71
|
+
assertValidSteps(steps);
|
|
72
|
+
kernel.require("interactiveTransactions");
|
|
73
|
+
const ledger = ledgerFor(kernel, options);
|
|
74
|
+
const recorded = (await ledgerExists(kernel, ledger)) ? await readLedger(ledger) : [];
|
|
75
|
+
verifyRecorded(recorded, steps, options.appName);
|
|
76
|
+
const report = { applied: [], alreadyApplied: recorded.map((row) => row.id), notes: [] };
|
|
77
|
+
const note = (message) => {
|
|
78
|
+
report.notes.push(message);
|
|
79
|
+
};
|
|
80
|
+
const context = options.backupPath === undefined ? { note } : { backupPath: options.backupPath, note };
|
|
81
|
+
const done = new Set(report.alreadyApplied);
|
|
82
|
+
let backedUp = false;
|
|
83
|
+
for (const step of steps) {
|
|
84
|
+
if (done.has(step.id))
|
|
85
|
+
continue;
|
|
86
|
+
if (!backedUp)
|
|
87
|
+
await backUpBeforeChange(kernel, context);
|
|
88
|
+
backedUp = true;
|
|
89
|
+
await step.prepare?.(kernel, context);
|
|
90
|
+
const applied = await kernel.transaction(async () => {
|
|
91
|
+
await kernel.lockKey(ledger.lockKey);
|
|
92
|
+
await ensureLedger(kernel, ledger);
|
|
93
|
+
const row = await ledger.run((db) => db.selectFrom(ledger.table).selectAll().where("id", "=", step.id).executeTakeFirst());
|
|
94
|
+
if (row !== undefined) {
|
|
95
|
+
verifyRecorded([row], steps, options.appName);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
await step.up(kernel, context);
|
|
99
|
+
await ledger.run((db) => db.insertInto(ledger.table).values({ id: step.id, checksum: step.checksum, applied_at: new Date().toISOString() }).execute());
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
(applied ? report.applied : report.alreadyApplied).push(step.id);
|
|
103
|
+
}
|
|
104
|
+
return report;
|
|
105
|
+
}
|
|
106
|
+
/** The pre-change copy (see the file header). Outside any transaction: a backup cannot run inside one. */
|
|
107
|
+
async function backUpBeforeChange(kernel, context) {
|
|
108
|
+
const target = context.backupPath;
|
|
109
|
+
if (target === undefined || !kernel.capabilities.backup || (await listTables(kernel)).length === 0)
|
|
110
|
+
return;
|
|
111
|
+
// The folder is made only when a copy is taken, so a run with nothing to copy leaves none behind.
|
|
112
|
+
fs.mkdirSync(path.dirname(path.resolve(target)), { recursive: true });
|
|
113
|
+
await kernel.backupTo(target);
|
|
114
|
+
context.note(`backed up the database to ${target} before migrating it`);
|
|
115
|
+
}
|
|
116
|
+
async function ledgerExists(kernel, ledger) {
|
|
117
|
+
if (ledger.schema === undefined)
|
|
118
|
+
return tableExists(kernel, ledger.table);
|
|
119
|
+
const [row] = await kernel.query(sql `SELECT to_regclass(${`${ledger.schema}.${ledger.table}`})::text AS found`);
|
|
120
|
+
return row?.found != null;
|
|
121
|
+
}
|
|
122
|
+
/** True when `kernel`'s database has the ledger `ledgerTable` (it has been through {@link runMigrations}). */
|
|
123
|
+
export async function hasLedger(kernel, ledgerTable) {
|
|
124
|
+
return tableExists(kernel, ledgerTable);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { StorageKernel } from "../kernel/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file What a migration step is. Steps form ONE ordered history for every dialect; the runner
|
|
4
|
+
* (`runner.ts`) applies each pending one in its own transaction and records it in the consumer's
|
|
5
|
+
* ledger table.
|
|
6
|
+
*/
|
|
7
|
+
/** `NNNN_snake_name`. Ordered by the number; never renamed or reused once shipped. */
|
|
8
|
+
export declare const MIGRATION_ID: RegExp;
|
|
9
|
+
export interface MigrationContext {
|
|
10
|
+
/** Where the runner copied (or would copy) the database before the first pending step; the caller decides. */
|
|
11
|
+
readonly backupPath?: string;
|
|
12
|
+
/** Something worth telling the operator (a backup taken, a legacy tail applied). */
|
|
13
|
+
note(message: string): void;
|
|
14
|
+
}
|
|
15
|
+
export interface MigrationStep {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
/** sha256 hex of what the step does, pinned by the consumer (a test re-derives it with `sourceChecksum`). */
|
|
18
|
+
readonly checksum: string;
|
|
19
|
+
/** Runs OUTSIDE the transaction, only when the step is pending (backups: they cannot run inside one). */
|
|
20
|
+
prepare?(kernel: StorageKernel<unknown>, context: MigrationContext): Promise<void>;
|
|
21
|
+
/** Runs inside the step's transaction, after the runner holds the migration lock. */
|
|
22
|
+
up(kernel: StorageKernel<unknown>, context: MigrationContext): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** An applied step's recorded checksum differs from this runtime's: the step was edited after shipping. */
|
|
25
|
+
export declare class MigrationChecksumError extends Error {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly recorded: string;
|
|
28
|
+
readonly expected: string;
|
|
29
|
+
constructor(id: string, recorded: string, expected: string);
|
|
30
|
+
}
|
|
31
|
+
/** The database records steps this runtime does not have: it was migrated by a newer version of the app. */
|
|
32
|
+
export declare class UnknownAppliedMigrationError extends Error {
|
|
33
|
+
readonly ids: readonly string[];
|
|
34
|
+
/** @param appName names the app in the message ("a newer <appName>"); default "version". */
|
|
35
|
+
constructor(ids: readonly string[], appName?: string);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=step.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file What a migration step is. Steps form ONE ordered history for every dialect; the runner
|
|
3
|
+
* (`runner.ts`) applies each pending one in its own transaction and records it in the consumer's
|
|
4
|
+
* ledger table.
|
|
5
|
+
*/
|
|
6
|
+
/** `NNNN_snake_name`. Ordered by the number; never renamed or reused once shipped. */
|
|
7
|
+
export const MIGRATION_ID = /^\d{4}_[a-z0-9_]+$/;
|
|
8
|
+
/** An applied step's recorded checksum differs from this runtime's: the step was edited after shipping. */
|
|
9
|
+
export class MigrationChecksumError extends Error {
|
|
10
|
+
id;
|
|
11
|
+
recorded;
|
|
12
|
+
expected;
|
|
13
|
+
constructor(id, recorded, expected) {
|
|
14
|
+
super(`migration ${id} was applied with checksum ${recorded}, but this runtime's ${id} has ${expected}; an applied migration must never change`);
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.recorded = recorded;
|
|
17
|
+
this.expected = expected;
|
|
18
|
+
this.name = "MigrationChecksumError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The database records steps this runtime does not have: it was migrated by a newer version of the app. */
|
|
22
|
+
export class UnknownAppliedMigrationError extends Error {
|
|
23
|
+
ids;
|
|
24
|
+
/** @param appName names the app in the message ("a newer <appName>"); default "version". */
|
|
25
|
+
constructor(ids, appName) {
|
|
26
|
+
super(`the database has migrations this runtime does not know (${ids.join(", ")}); it was upgraded by a newer ${appName ?? "version"} — run that version`);
|
|
27
|
+
this.ids = ids;
|
|
28
|
+
this.name = "UnknownAppliedMigrationError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=step.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { type Dialect, type Driver, type Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from "kysely";
|
|
3
|
+
export declare class PgliteDialect implements Dialect {
|
|
4
|
+
private readonly client;
|
|
5
|
+
constructor(client: PGlite);
|
|
6
|
+
createAdapter(): PostgresAdapter;
|
|
7
|
+
createDriver(): Driver;
|
|
8
|
+
createQueryCompiler(): PostgresQueryCompiler;
|
|
9
|
+
createIntrospector(db: Kysely<unknown>): PostgresIntrospector;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CompiledQuery, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* @file A Kysely dialect over one PGlite instance: Kysely's own Postgres adapter, compiler and
|
|
4
|
+
* introspector, plus a driver that runs compiled queries through `PGlite#query`.
|
|
5
|
+
*
|
|
6
|
+
* Written here rather than taken from npm (2026-09-28): `kysely-pglite-dialect` 1.3.1 declares
|
|
7
|
+
* `@electric-sql/pglite` peer `^0.2 || ^0.3 || ^0.4` (this package pins 0.5.8), is one maintainer, and is
|
|
8
|
+
* ~11 KB of the same few lines; `kysely-pglite` was last published 2024. This file is that driver,
|
|
9
|
+
* sized to what the kernel needs and nothing else.
|
|
10
|
+
*
|
|
11
|
+
* PGlite is ONE connection. The driver hands it out one holder at a time (a transaction holds it
|
|
12
|
+
* from `BEGIN` to `COMMIT`), so a statement from outside can never land inside someone else's
|
|
13
|
+
* transaction. The kernel's turn lock already orders callers; this keeps the dialect correct on its
|
|
14
|
+
* own too.
|
|
15
|
+
*/
|
|
16
|
+
class PgliteConnection {
|
|
17
|
+
client;
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
async executeQuery(compiled) {
|
|
22
|
+
const result = await this.client.query(compiled.sql, [...compiled.parameters]);
|
|
23
|
+
return {
|
|
24
|
+
rows: result.rows,
|
|
25
|
+
...(result.affectedRows !== undefined ? { numAffectedRows: BigInt(result.affectedRows) } : {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line require-yield -- the interface requires a generator; PGlite has no cursor API here
|
|
29
|
+
async *streamQuery() {
|
|
30
|
+
throw new Error("streaming queries are not supported on PGlite");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class PgliteDriver {
|
|
34
|
+
client;
|
|
35
|
+
connection;
|
|
36
|
+
holder = Promise.resolve();
|
|
37
|
+
releaseHolder;
|
|
38
|
+
constructor(client) {
|
|
39
|
+
this.client = client;
|
|
40
|
+
this.connection = new PgliteConnection(client);
|
|
41
|
+
}
|
|
42
|
+
async init() {
|
|
43
|
+
await this.client.waitReady;
|
|
44
|
+
}
|
|
45
|
+
async acquireConnection() {
|
|
46
|
+
const previous = this.holder;
|
|
47
|
+
let release;
|
|
48
|
+
this.holder = new Promise((resolve) => (release = resolve));
|
|
49
|
+
await previous;
|
|
50
|
+
this.releaseHolder = release;
|
|
51
|
+
return this.connection;
|
|
52
|
+
}
|
|
53
|
+
async releaseConnection() {
|
|
54
|
+
const release = this.releaseHolder;
|
|
55
|
+
this.releaseHolder = undefined;
|
|
56
|
+
release?.();
|
|
57
|
+
}
|
|
58
|
+
async beginTransaction(connection) {
|
|
59
|
+
await connection.executeQuery(CompiledQuery.raw("BEGIN"));
|
|
60
|
+
}
|
|
61
|
+
async commitTransaction(connection) {
|
|
62
|
+
await connection.executeQuery(CompiledQuery.raw("COMMIT"));
|
|
63
|
+
}
|
|
64
|
+
async rollbackTransaction(connection) {
|
|
65
|
+
await connection.executeQuery(CompiledQuery.raw("ROLLBACK"));
|
|
66
|
+
}
|
|
67
|
+
/** The PGlite instance belongs to whoever opened it (the kernel closes it). */
|
|
68
|
+
async destroy() { }
|
|
69
|
+
}
|
|
70
|
+
export class PgliteDialect {
|
|
71
|
+
client;
|
|
72
|
+
constructor(client) {
|
|
73
|
+
this.client = client;
|
|
74
|
+
}
|
|
75
|
+
createAdapter() {
|
|
76
|
+
return new PostgresAdapter();
|
|
77
|
+
}
|
|
78
|
+
createDriver() {
|
|
79
|
+
return new PgliteDriver(this.client);
|
|
80
|
+
}
|
|
81
|
+
createQueryCompiler() {
|
|
82
|
+
return new PostgresQueryCompiler();
|
|
83
|
+
}
|
|
84
|
+
createIntrospector(db) {
|
|
85
|
+
return new PostgresIntrospector(db);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { type StorageKernel } from "../kernel/index.js";
|
|
3
|
+
import type { PgliteClass } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file The PGlite driver: one in-process Postgres (WASM) per data directory, behind the same
|
|
6
|
+
* Kysely query bodies as every other driver.
|
|
7
|
+
*
|
|
8
|
+
* PGlite holds one connection: a repo that kept using the base handle inside a transaction would
|
|
9
|
+
* wait on itself forever. The kernel's transaction scope hands the open transaction to every
|
|
10
|
+
* `run()` inside it, which is what makes that safe.
|
|
11
|
+
*
|
|
12
|
+
* Only ONE process may open a data dir; to share one, run an owner (`startPgliteOwner`) and connect
|
|
13
|
+
* through its socket.
|
|
14
|
+
*/
|
|
15
|
+
export type PgKernel<DB> = StorageKernel<DB>;
|
|
16
|
+
/**
|
|
17
|
+
* Opens (and on first use creates) a PGlite database. Synchronous so it fits the synchronous
|
|
18
|
+
* composition root; the async setup runs behind `ready`, which every kernel call awaits.
|
|
19
|
+
*
|
|
20
|
+
* @param required.PGlite the consumer's `PGlite` class (this package never imports it).
|
|
21
|
+
* @param optional.dataDir absent = in-memory (tests).
|
|
22
|
+
* @param optional.prepare runs once after open, before any call (e.g. schema creation).
|
|
23
|
+
*/
|
|
24
|
+
export declare function openPgliteKernel<DB>(required: {
|
|
25
|
+
PGlite: PgliteClass;
|
|
26
|
+
}, optional?: {
|
|
27
|
+
dataDir?: string;
|
|
28
|
+
prepare?: (client: PGlite) => Promise<void>;
|
|
29
|
+
}): PgKernel<DB>;
|
|
30
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import { Kysely } from "kysely";
|
|
4
|
+
import { buildKernel, PG_PARSERS, postgresLockKey } from "../kernel/index.js";
|
|
5
|
+
import { PgliteDialect } from "./dialect.js";
|
|
6
|
+
/**
|
|
7
|
+
* Opens (and on first use creates) a PGlite database. Synchronous so it fits the synchronous
|
|
8
|
+
* composition root; the async setup runs behind `ready`, which every kernel call awaits.
|
|
9
|
+
*
|
|
10
|
+
* @param required.PGlite the consumer's `PGlite` class (this package never imports it).
|
|
11
|
+
* @param optional.dataDir absent = in-memory (tests).
|
|
12
|
+
* @param optional.prepare runs once after open, before any call (e.g. schema creation).
|
|
13
|
+
*/
|
|
14
|
+
export function openPgliteKernel(required, optional = {}) {
|
|
15
|
+
if (optional.dataDir !== undefined)
|
|
16
|
+
mkdirSync(optional.dataDir, { recursive: true });
|
|
17
|
+
// One options object: PGlite drops the second argument when the first (dataDir) is undefined.
|
|
18
|
+
const client = new required.PGlite({ ...(optional.dataDir === undefined ? {} : { dataDir: optional.dataDir }), parsers: PG_PARSERS });
|
|
19
|
+
const base = new Kysely({ dialect: new PgliteDialect(client) });
|
|
20
|
+
const ready = (async () => {
|
|
21
|
+
await client.waitReady;
|
|
22
|
+
await optional.prepare?.(client);
|
|
23
|
+
})();
|
|
24
|
+
// Surfaced by every call that awaits `ready`; this only stops an unhandled-rejection crash when
|
|
25
|
+
// nothing has called in yet.
|
|
26
|
+
ready.catch(() => { });
|
|
27
|
+
return buildKernel({
|
|
28
|
+
dialect: "postgres",
|
|
29
|
+
transport: "pglite",
|
|
30
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: true },
|
|
31
|
+
ready,
|
|
32
|
+
base,
|
|
33
|
+
oneConnection: true,
|
|
34
|
+
begin: (body) => base.transaction().execute((tx) => body(tx)),
|
|
35
|
+
lockKey: postgresLockKey,
|
|
36
|
+
async backup(destPath) {
|
|
37
|
+
const dump = await client.dumpDataDir("none");
|
|
38
|
+
await writeFile(destPath, Buffer.from(await dump.arrayBuffer()));
|
|
39
|
+
},
|
|
40
|
+
async close() {
|
|
41
|
+
await ready.catch(() => { });
|
|
42
|
+
await client.close();
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** PGlite ownership and socket serving. The consumer supplies its PGlite class. */
|
|
2
|
+
export { startPgliteOwner, runningPgliteOwner, acquireOwnerLock, defaultPgliteSocketDir, assertSocketPathFits, ensurePrivateDir, PgliteOwnerLockedError, PGLITE_LOW_MEMORY_SETTINGS, pgliteLowMemoryStartParams, type PgliteOwner } from "./owner.js";
|
|
3
|
+
export { PgliteSocketServer, errorResponseFrame, type PgliteSocketServerOptions } from "./socket-server.js";
|
|
4
|
+
export type { PgliteClass } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** PGlite ownership and socket serving. The consumer supplies its PGlite class. */
|
|
2
|
+
export { startPgliteOwner, runningPgliteOwner, acquireOwnerLock, defaultPgliteSocketDir, assertSocketPathFits, ensurePrivateDir, PgliteOwnerLockedError, PGLITE_LOW_MEMORY_SETTINGS, pgliteLowMemoryStartParams } from "./owner.js";
|
|
3
|
+
export { PgliteSocketServer, errorResponseFrame } from "./socket-server.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { type StorageKernel, type StorageOps } from "../kernel/index.js";
|
|
3
|
+
import type { PgliteClass } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file The storage ops for PGlite: an in-process kernel (`openPgliteKernel`), or a socket client
|
|
6
|
+
* whose owner runs in this process. The copy is a data-dir dump restored into a new data dir;
|
|
7
|
+
* compacting is `VACUUM` + `CHECKPOINT`, then a read-back of the consumer's migration ledger. A
|
|
8
|
+
* socket client reaches the dump only through its owner's exclusive window ({@link PgliteExclusive});
|
|
9
|
+
* without one, use `@jini-ai/db/postgres`'s `postgresOps`, which refuses the copy.
|
|
10
|
+
*/
|
|
11
|
+
/** A PGlite owner's exclusive window (`PgliteOwner.runExclusive`): the one way to dump a served data dir. */
|
|
12
|
+
export interface PgliteExclusive {
|
|
13
|
+
runExclusive<T>(fn: (db: PGlite) => Promise<T>): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
/** What restoring a dump needs: the consumer's `PGlite` class and the owner lock file to drop from the copy. */
|
|
16
|
+
export interface PgliteRestore {
|
|
17
|
+
readonly PGlite: PgliteClass;
|
|
18
|
+
/** The owner's pid lock file name; the dump carries the source owner's lock, the copy has no owner yet. */
|
|
19
|
+
readonly ownerLockFileName?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The ops for a PGlite kernel. Must be used outside a transaction (Postgres cannot `VACUUM` inside one).
|
|
23
|
+
*
|
|
24
|
+
* @param required.ledgerTable the migration ledger the compaction reads back (no default).
|
|
25
|
+
* @param optional.pgliteOwner the owner serving the data dir `kernel` is a socket client of.
|
|
26
|
+
* @throws {Error} a kernel that is neither in-process PGlite nor a socket client given its owner.
|
|
27
|
+
* @complexity each op is one full pass over the data dir, O(size).
|
|
28
|
+
*/
|
|
29
|
+
export declare function pgliteOps<DB>(kernel: StorageKernel<DB>, required: PgliteRestore & {
|
|
30
|
+
ledgerTable: string;
|
|
31
|
+
}, optional?: {
|
|
32
|
+
pgliteOwner?: PgliteExclusive;
|
|
33
|
+
}): StorageOps;
|
|
34
|
+
/**
|
|
35
|
+
* `copyTo` for a PGlite data dir served by `owner` (in this process): the dump is taken inside the
|
|
36
|
+
* owner's exclusive window, then restored into `targetPath` (which must not exist).
|
|
37
|
+
*/
|
|
38
|
+
export declare function copyServedPgliteTo(owner: PgliteExclusive, targetPath: string, required: PgliteRestore): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, rmSync } from "node:fs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { sql } from "kysely";
|
|
6
|
+
import { outsideTransactionOf, verifyLedgerReadBack, } from "../kernel/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* The ops for a PGlite kernel. Must be used outside a transaction (Postgres cannot `VACUUM` inside one).
|
|
9
|
+
*
|
|
10
|
+
* @param required.ledgerTable the migration ledger the compaction reads back (no default).
|
|
11
|
+
* @param optional.pgliteOwner the owner serving the data dir `kernel` is a socket client of.
|
|
12
|
+
* @throws {Error} a kernel that is neither in-process PGlite nor a socket client given its owner.
|
|
13
|
+
* @complexity each op is one full pass over the data dir, O(size).
|
|
14
|
+
*/
|
|
15
|
+
export function pgliteOps(kernel, required, optional = {}) {
|
|
16
|
+
const owner = optional.pgliteOwner;
|
|
17
|
+
const ownedSocket = kernel.transport === "pglite-socket" && owner !== undefined;
|
|
18
|
+
if (kernel.transport !== "pglite" && !ownedSocket) {
|
|
19
|
+
throw new Error(`pgliteOps: a ${kernel.transport} kernel is not PGlite in this process (a socket client needs pgliteOwner)`);
|
|
20
|
+
}
|
|
21
|
+
const outsideTransaction = outsideTransactionOf(kernel);
|
|
22
|
+
return {
|
|
23
|
+
async copyTo(targetPath) {
|
|
24
|
+
outsideTransaction("copyTo");
|
|
25
|
+
if (owner !== undefined)
|
|
26
|
+
return copyServedPgliteTo(owner, targetPath, required);
|
|
27
|
+
await restoreDataDir(targetPath, required, async () => {
|
|
28
|
+
const tarball = `${targetPath}.${randomUUID()}.tar`;
|
|
29
|
+
try {
|
|
30
|
+
await kernel.backupTo(tarball);
|
|
31
|
+
return new Blob([await readFile(tarball)]);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
rmSync(tarball, { force: true });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async compactAndVerify() {
|
|
39
|
+
outsideTransaction("compactAndVerify");
|
|
40
|
+
if (owner !== undefined) {
|
|
41
|
+
// Two calls: a multi-statement string runs as one implicit transaction, which VACUUM refuses.
|
|
42
|
+
await owner.runExclusive(async (db) => {
|
|
43
|
+
await db.exec("VACUUM");
|
|
44
|
+
await db.exec("CHECKPOINT");
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
await kernel.execute(sql `VACUUM`);
|
|
49
|
+
await kernel.execute(sql `CHECKPOINT`);
|
|
50
|
+
}
|
|
51
|
+
await verifyLedgerReadBack(kernel, required.ledgerTable);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* `copyTo` for a PGlite data dir served by `owner` (in this process): the dump is taken inside the
|
|
57
|
+
* owner's exclusive window, then restored into `targetPath` (which must not exist).
|
|
58
|
+
*/
|
|
59
|
+
export async function copyServedPgliteTo(owner, targetPath, required) {
|
|
60
|
+
await restoreDataDir(targetPath, required, () => owner.runExclusive((db) => db.dumpDataDir("none")));
|
|
61
|
+
}
|
|
62
|
+
/** Restores `dump()` into a new PGlite data dir at `targetPath`; removes a partial dir on failure. */
|
|
63
|
+
async function restoreDataDir(targetPath, required, dump) {
|
|
64
|
+
if (existsSync(targetPath))
|
|
65
|
+
throw new Error(`storage op copyTo: ${targetPath} already exists`);
|
|
66
|
+
const data = await dump();
|
|
67
|
+
try {
|
|
68
|
+
const restored = await required.PGlite.create({ dataDir: targetPath, loadDataDir: data });
|
|
69
|
+
await restored.close();
|
|
70
|
+
if (required.ownerLockFileName !== undefined)
|
|
71
|
+
rmSync(join(targetPath, required.ownerLockFileName), { force: true });
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
rmSync(targetPath, { recursive: true, force: true });
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ops.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import type { PgliteClass } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The PGlite OWNER: the one process that opens a PGlite data dir and serves it on a private
|
|
5
|
+
* Unix socket, so several processes share one database as ordinary Postgres clients
|
|
6
|
+
* (`@jini-ai/db/kernel/postgres`'s `openPgliteSocketKernel`).
|
|
7
|
+
*
|
|
8
|
+
* The consumer passes its own `PGlite` class (this package never imports `@electric-sql/pglite`)
|
|
9
|
+
* and names its lock file and run directory, so two apps never share either.
|
|
10
|
+
*
|
|
11
|
+
* - One owner per data dir: a pid lock file inside it. A second owner for the same dir — another
|
|
12
|
+
* process or this one — is refused; a lock left by a dead pid (kill -9) is taken over. Different
|
|
13
|
+
* data dirs run side by side.
|
|
14
|
+
* - The socket lives in a short private runtime dir (0700, socket 0600), never the site dir: macOS
|
|
15
|
+
* caps a socket path at 103 bytes. Never TCP.
|
|
16
|
+
* - Low-memory Postgres settings (~110-120 MB steady instead of ~245 MB). Expect a
|
|
17
|
+
* 400-700 MB peak for ~10 s after open while V8 tiers up the WASM; that is not a leak.
|
|
18
|
+
* - While serving, the owner reaches the database only through {@link PgliteOwner.runExclusive}
|
|
19
|
+
* (or as a socket client like everyone else).
|
|
20
|
+
*/
|
|
21
|
+
/** The low-memory settings added to `PGlite.defaultStartParams` (`initialMemory` stays at its 128 MB minimum). */
|
|
22
|
+
export declare const PGLITE_LOW_MEMORY_SETTINGS: readonly string[];
|
|
23
|
+
/** `PGlite.defaultStartParams` plus {@link PGLITE_LOW_MEMORY_SETTINGS}, for the consumer's `PGlite` class. */
|
|
24
|
+
export declare function pgliteLowMemoryStartParams(pglite: Pick<PgliteClass, "defaultStartParams">): string[];
|
|
25
|
+
export interface PgliteOwner {
|
|
26
|
+
readonly socketPath: string;
|
|
27
|
+
/** Directory to give a Postgres client as `host`. */
|
|
28
|
+
readonly socketDir: string;
|
|
29
|
+
/** Runs `fn` alone on the database: after any open client transaction, before the next client message. */
|
|
30
|
+
runExclusive<T>(fn: (db: PGlite) => Promise<T>): Promise<T>;
|
|
31
|
+
/** Stops serving (open client transactions roll back), closes PGlite, removes the socket, releases the lock. */
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare class PgliteOwnerLockedError extends Error {
|
|
35
|
+
readonly dataDir: string;
|
|
36
|
+
/** Undefined while the other starter's lock has no pid in it yet. */
|
|
37
|
+
readonly pid: number | undefined;
|
|
38
|
+
constructor(dataDir: string,
|
|
39
|
+
/** Undefined while the other starter's lock has no pid in it yet. */
|
|
40
|
+
pid: number | undefined);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The owner THIS process runs for `dataDir`, if any: how an in-process caller (duplicating the site
|
|
44
|
+
* it serves) reaches {@link PgliteOwner.runExclusive} without a second open.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runningPgliteOwner(dataDir: string): PgliteOwner | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Where the owner of `dataDir` puts its socket: `~/.<runDirName>/run/<key>/`, or
|
|
49
|
+
* `/tmp/<runDirName>-<uid>/<key>/` when the home path is too long for a socket.
|
|
50
|
+
*
|
|
51
|
+
* @param required.runDirName the consumer's own directory name (e.g. its app name), so two apps'
|
|
52
|
+
* sockets never share a directory. A plain name: no slash, no leading dot.
|
|
53
|
+
*/
|
|
54
|
+
export declare function defaultPgliteSocketDir(required: {
|
|
55
|
+
dataDir: string;
|
|
56
|
+
runDirName: string;
|
|
57
|
+
}, optional?: {
|
|
58
|
+
home?: string;
|
|
59
|
+
}): string;
|
|
60
|
+
/** Throws unless `socketPath` fits in `sun_path`. */
|
|
61
|
+
export declare function assertSocketPathFits(socketPath: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Creates `dir` (and missing parents) owner-only, and refuses one that is a symlink or belongs to
|
|
64
|
+
* another user (a pre-created `/tmp/<app>-<uid>` would otherwise let that user reach the socket).
|
|
65
|
+
*
|
|
66
|
+
* @param optional.privateParent also create-or-check `dir`'s parent, refusing one that is not a
|
|
67
|
+
* 0700 non-symlink directory of ours (else its owner could swap `dir` for their own). Default:
|
|
68
|
+
* on when the parent sits directly in `/tmp` (the `/tmp/<app>-<uid>` fallback).
|
|
69
|
+
*/
|
|
70
|
+
export declare function ensurePrivateDir(dir: string, optional?: {
|
|
71
|
+
privateParent?: boolean;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* Takes the data dir's owner lock: created atomically with our pid in it. A lock whose pid is dead
|
|
75
|
+
* (or that has had no pid for {@link EMPTY_LOCK_STALE_MS}) is taken over; a live one — including
|
|
76
|
+
* this process's own — or a fresh one with no pid yet refuses. Returns an idempotent release
|
|
77
|
+
* function that only removes the inode acquired by this call.
|
|
78
|
+
* @complexity O(L) time/space for L bytes in a pid file; at most five acquisition attempts.
|
|
79
|
+
*/
|
|
80
|
+
export declare function acquireOwnerLock(required: {
|
|
81
|
+
dataDir: string;
|
|
82
|
+
lockFileName: string;
|
|
83
|
+
}): () => void;
|
|
84
|
+
/**
|
|
85
|
+
* Opens `dataDir` (creating it on first use — initdb takes several seconds) and serves it on a
|
|
86
|
+
* private Unix socket.
|
|
87
|
+
*
|
|
88
|
+
* @param required.PGlite the consumer's `PGlite` class (pin `@electric-sql/pglite` 0.5.8: the socket
|
|
89
|
+
* server's ReadyForQuery filter is written against it).
|
|
90
|
+
* @param required.lockFileName the pid lock file kept inside `dataDir` (e.g. `myapp-owner.pid`).
|
|
91
|
+
* @param required.runDirName names the default socket dir; see {@link defaultPgliteSocketDir}.
|
|
92
|
+
* @param optional.socketDir default {@link defaultPgliteSocketDir}.
|
|
93
|
+
* @param optional.idleInTransactionTimeoutMs default 30 s; see `PgliteSocketServer`.
|
|
94
|
+
* @throws PgliteOwnerLockedError when another live owner holds `dataDir`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function startPgliteOwner(required: {
|
|
97
|
+
dataDir: string;
|
|
98
|
+
PGlite: PgliteClass;
|
|
99
|
+
lockFileName: string;
|
|
100
|
+
runDirName: string;
|
|
101
|
+
}, optional?: {
|
|
102
|
+
socketDir?: string;
|
|
103
|
+
idleInTransactionTimeoutMs?: number;
|
|
104
|
+
maxConnections?: number;
|
|
105
|
+
log?: (message: string) => void;
|
|
106
|
+
}): Promise<PgliteOwner>;
|
|
107
|
+
//# sourceMappingURL=owner.d.ts.map
|