@broberg/db-sdk 0.3.0 → 0.4.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/README.md +30 -0
- package/dist/chunk-ONXYOFVT.js +124 -0
- package/dist/chunk-ONXYOFVT.js.map +1 -0
- package/dist/index.js +8 -117
- package/dist/index.js.map +1 -1
- package/dist/switchable/index.d.ts +59 -4
- package/dist/switchable/index.js +211 -11
- package/dist/switchable/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,6 +278,36 @@ providers is another `GuardDeps`.
|
|
|
278
278
|
The CI workflow for the guard, the replication setup and the runbook are a
|
|
279
279
|
Discovery playbook, not package code.
|
|
280
280
|
|
|
281
|
+
### 0.4.0 — at a real shop's size (components-F085.7, measured by VN Leker)
|
|
282
|
+
|
|
283
|
+
Measured against VN Leker's own off-prod pair (two PG17 servers, logical
|
|
284
|
+
replication, 308,153 rows, two machines writing through the switch):
|
|
285
|
+
|
|
286
|
+
| | 0.3.0 | 0.4.0 |
|
|
287
|
+
|---|---|---|
|
|
288
|
+
| queries held, switch to the reserve | 23,800 ms (aborted by the safety net) | **26 ms** |
|
|
289
|
+
| queries held, the way home | not reached | **612 ms** |
|
|
290
|
+
| acked writes lost / failed | — | 0 / 0 (3,240 writes) |
|
|
291
|
+
|
|
292
|
+
- **The baseline is no longer read under the hold.** `freezeBaseline` fixes the
|
|
293
|
+
reserve's instant with a REPEATABLE READ snapshot on a connection of its own
|
|
294
|
+
(milliseconds) and reads the rows through it after release. Until it is
|
|
295
|
+
written, `baselineAt` is null, so a way home cannot start on an old one.
|
|
296
|
+
- **The second pass home compares only what changed** since the first pass
|
|
297
|
+
began (`reconcile({ since: reserveHorizon(...) })`): rows whose `xmin` is at
|
|
298
|
+
or above the horizon, and deletes found by counting per table. Tables
|
|
299
|
+
without a primary key are still compared in full.
|
|
300
|
+
- **Identity columns.** The way home writes `GENERATED ALWAYS AS IDENTITY`
|
|
301
|
+
columns with `OVERRIDING SYSTEM VALUE` and leaves stored generated columns to
|
|
302
|
+
Postgres. **Sequences** are not replicated, so `syncSequences` moves every
|
|
303
|
+
identity/serial sequence on the side that starts taking writes up to its
|
|
304
|
+
column's max — under the hold, never backwards.
|
|
305
|
+
- **Behaviour change — pool size.** `createClient({ backend: 'postgres' })`
|
|
306
|
+
without `max` now gets the driver's default of **10** connections, as this
|
|
307
|
+
README always said. Until 0.3.0 it silently got ONE (`max: undefined` reached
|
|
308
|
+
postgres.js as «set»). If your database caps connections, pass `max`.
|
|
309
|
+
`freezeBaseline` refuses a pool of one with a reason instead of hanging.
|
|
310
|
+
|
|
281
311
|
## Migrating from 0.1.x
|
|
282
312
|
|
|
283
313
|
`createClient()` used to return `@libsql/client`'s own `Client`. It now returns
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/backends/pg.ts
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
function parts(stmt) {
|
|
4
|
+
if (typeof stmt === "string") return [stmt, []];
|
|
5
|
+
return [stmt.sql, [...stmt.args ?? []]];
|
|
6
|
+
}
|
|
7
|
+
function toResult(res) {
|
|
8
|
+
const r = Array.isArray(res) ? res[res.length - 1] : res;
|
|
9
|
+
const columns = (r.fields ?? []).map((f) => f.name);
|
|
10
|
+
const rows = (r.rows ?? []).map((x) => ({ ...x }));
|
|
11
|
+
const isRead = r.command === "SELECT";
|
|
12
|
+
return { rows, columns, rowsAffected: isRead ? 0 : r.rowCount ?? 0 };
|
|
13
|
+
}
|
|
14
|
+
function loadPool(url, max) {
|
|
15
|
+
let pg;
|
|
16
|
+
try {
|
|
17
|
+
pg = createRequire(import.meta.url)("pg");
|
|
18
|
+
} catch {
|
|
19
|
+
throw new Error("@broberg/db-sdk: backend 'pg' needs the 'pg' package \u2014 npm i pg (or pass your own `pool`)");
|
|
20
|
+
}
|
|
21
|
+
return new pg.Pool({ connectionString: url, max });
|
|
22
|
+
}
|
|
23
|
+
function pgClient(cfg) {
|
|
24
|
+
let pool;
|
|
25
|
+
if (cfg.pool) pool = cfg.pool;
|
|
26
|
+
else {
|
|
27
|
+
const url = cfg.url ?? process.env.DATABASE_URL;
|
|
28
|
+
if (!url) throw new Error("@broberg/db-sdk: missing database url \u2014 set DATABASE_URL, pass url, or pass your own pool");
|
|
29
|
+
pool = loadPool(url, cfg.max);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
transport: "postgres",
|
|
33
|
+
raw: pool,
|
|
34
|
+
async execute(stmt) {
|
|
35
|
+
const [text, args] = parts(stmt);
|
|
36
|
+
return toResult(await pool.query(text, args));
|
|
37
|
+
},
|
|
38
|
+
async batch(stmts) {
|
|
39
|
+
const client = await pool.connect();
|
|
40
|
+
try {
|
|
41
|
+
await client.query("begin");
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const s of stmts) {
|
|
44
|
+
const [text, args] = parts(s);
|
|
45
|
+
out.push(toResult(await client.query(text, args)));
|
|
46
|
+
}
|
|
47
|
+
await client.query("commit");
|
|
48
|
+
return out;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
try {
|
|
51
|
+
await client.query("rollback");
|
|
52
|
+
} catch (rb) {
|
|
53
|
+
e.rollbackError = rb;
|
|
54
|
+
}
|
|
55
|
+
throw e;
|
|
56
|
+
} finally {
|
|
57
|
+
client.release();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async close() {
|
|
61
|
+
if (!pool.ended) await pool.end();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/backends/postgres.ts
|
|
67
|
+
import postgres from "postgres";
|
|
68
|
+
var PG_OPTIONS = { prepare: false };
|
|
69
|
+
function toResult2(res) {
|
|
70
|
+
const columns = (res.columns ?? []).map((c) => c.name);
|
|
71
|
+
const rows = Array.from(res, (r) => ({ ...r }));
|
|
72
|
+
const isRead = res.command === "SELECT";
|
|
73
|
+
return { rows, columns, rowsAffected: isRead ? 0 : res.count ?? 0 };
|
|
74
|
+
}
|
|
75
|
+
function parts2(stmt) {
|
|
76
|
+
if (typeof stmt === "string") return [stmt, []];
|
|
77
|
+
return [stmt.sql, [...stmt.args ?? []]];
|
|
78
|
+
}
|
|
79
|
+
function run(sql, stmt) {
|
|
80
|
+
const [text, args] = parts2(stmt);
|
|
81
|
+
return sql.unsafe(text, args, PG_OPTIONS);
|
|
82
|
+
}
|
|
83
|
+
function postgresClient(cfg) {
|
|
84
|
+
const url = cfg.url ?? process.env.DATABASE_URL;
|
|
85
|
+
if (!url) {
|
|
86
|
+
throw new Error("@broberg/db-sdk: missing database url \u2014 set DATABASE_URL or pass it explicitly");
|
|
87
|
+
}
|
|
88
|
+
const raw = postgres(url, { ...PG_OPTIONS, ...cfg.max !== void 0 ? { max: cfg.max } : {}, onnotice: () => {
|
|
89
|
+
} });
|
|
90
|
+
return {
|
|
91
|
+
transport: "postgres",
|
|
92
|
+
raw,
|
|
93
|
+
async execute(stmt) {
|
|
94
|
+
return toResult2(await run(raw, stmt));
|
|
95
|
+
},
|
|
96
|
+
// Postgres has no write-lock-up-front mode, so both BatchModes begin a
|
|
97
|
+
// plain transaction and the mode argument is not read.
|
|
98
|
+
async batch(stmts) {
|
|
99
|
+
const results = await raw.begin(async (tx) => {
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const s of stmts) out.push(toResult2(await run(tx, s)));
|
|
102
|
+
return out;
|
|
103
|
+
});
|
|
104
|
+
return results;
|
|
105
|
+
},
|
|
106
|
+
async close() {
|
|
107
|
+
await raw.end();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function postgresVersion(raw) {
|
|
112
|
+
const [row] = await raw.unsafe("show server_version", [], PG_OPTIONS);
|
|
113
|
+
return String(row?.server_version ?? "unknown");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
toResult,
|
|
118
|
+
pgClient,
|
|
119
|
+
PG_OPTIONS,
|
|
120
|
+
toResult2,
|
|
121
|
+
postgresClient,
|
|
122
|
+
postgresVersion
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=chunk-ONXYOFVT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backends/pg.ts","../src/backends/postgres.ts"],"sourcesContent":["/**\n * node-postgres (`pg`) transport for @broberg/db-sdk (components-F085.6).\n *\n * Why a second Postgres driver: some apps cannot move — BID runs Better Auth,\n * whose kysely dialect takes a `pg.Pool` (it recognises one by `connect`). The\n * facade is the same as the postgres.js transport: same SQL dialect ($1), same\n * DbResult shape, `transport: 'postgres'`. `pg` is an OPTIONAL peer dependency:\n * it is loaded only when `backend: 'pg'` is asked for with a `url` — pass your\n * own `pool` and this file never imports it.\n */\nimport { createRequire } from 'node:module';\nimport type { Pool, PoolClient, QueryResult } from 'pg';\nimport type { DbClient, DbResult, PgConfig, Row, Statement } from '../types';\n\nfunction parts(stmt: Statement): [string, unknown[]] {\n if (typeof stmt === 'string') return [stmt, []];\n return [stmt.sql, [...(stmt.args ?? [])]];\n}\n\nexport function toResult(res: QueryResult | QueryResult[]): DbResult {\n // A multi-statement string answers an array; the facade reports the last, like a single statement.\n const r = Array.isArray(res) ? res[res.length - 1]! : res;\n const columns = (r.fields ?? []).map((f) => f.name);\n const rows = (r.rows ?? []).map((x) => ({ ...(x as Row) }));\n const isRead = r.command === 'SELECT';\n return { rows, columns, rowsAffected: isRead ? 0 : (r.rowCount ?? 0) };\n}\n\nfunction loadPool(url: string, max?: number): Pool {\n let pg: { Pool: new (cfg: { connectionString: string; max?: number }) => Pool };\n try {\n pg = createRequire(import.meta.url)('pg');\n } catch {\n throw new Error(\"@broberg/db-sdk: backend 'pg' needs the 'pg' package — npm i pg (or pass your own `pool`)\");\n }\n return new pg.Pool({ connectionString: url, max });\n}\n\nexport function pgClient(cfg: PgConfig): DbClient<Pool> {\n let pool: Pool;\n if (cfg.pool) pool = cfg.pool;\n else {\n const url = cfg.url ?? process.env.DATABASE_URL;\n if (!url) throw new Error('@broberg/db-sdk: missing database url — set DATABASE_URL, pass url, or pass your own pool');\n pool = loadPool(url, cfg.max);\n }\n return {\n transport: 'postgres',\n raw: pool,\n async execute(stmt) {\n const [text, args] = parts(stmt);\n return toResult(await pool.query(text, args));\n },\n async batch(stmts) {\n const client: PoolClient = await pool.connect();\n try {\n await client.query('begin');\n const out: DbResult[] = [];\n for (const s of stmts) {\n const [text, args] = parts(s);\n out.push(toResult(await client.query(text, args)));\n }\n await client.query('commit');\n return out;\n } catch (e) {\n // The original error is what the caller needs; a failed rollback is\n // reported alongside it rather than replacing it.\n try {\n await client.query('rollback');\n } catch (rb) {\n (e as Error & { rollbackError?: unknown }).rollbackError = rb;\n }\n throw e;\n } finally {\n client.release();\n }\n },\n async close() {\n if (!(pool as Pool & { ended?: boolean }).ended) await pool.end();\n },\n };\n}\n","/** PostgreSQL transport for @broberg/db-sdk — Supabase included. */\nimport postgres from 'postgres';\nimport type { Sql, TransactionSql } from 'postgres';\nimport type { DbClient, DbResult, PostgresConfig, Row, Statement } from '../types';\n\n/**\n * Prepared statements are OFF, deliberately, and a test fails if they come back.\n *\n * Supabase's connection pooler in transaction mode (port 6543) hands each\n * transaction to whichever server connection is free, so a statement prepared\n * on one is missing on the next. postgres.js prepares by default. With it on,\n * everything passes against a local Postgres and fails against Supabase —\n * green until production.\n */\nexport const PG_OPTIONS = { prepare: false } as const;\n\ntype PgResult = Awaited<ReturnType<Sql['unsafe']>>;\n\nexport function toResult(res: PgResult): DbResult {\n const columns = (res.columns ?? []).map((c) => c.name);\n const rows = Array.from(res, (r) => ({ ...(r as Row) }));\n // count is the command's row count; for a SELECT that is rows returned, which\n // the facade does not call \"affected\".\n const isRead = res.command === 'SELECT';\n return { rows, columns, rowsAffected: isRead ? 0 : (res.count ?? 0) };\n}\n\nfunction parts(stmt: Statement): [string, unknown[]] {\n if (typeof stmt === 'string') return [stmt, []];\n return [stmt.sql, [...(stmt.args ?? [])]];\n}\n\nfunction run(sql: Sql | TransactionSql, stmt: Statement): Promise<PgResult> {\n const [text, args] = parts(stmt);\n return sql.unsafe(text, args as never[], PG_OPTIONS);\n}\n\nexport function postgresClient(cfg: PostgresConfig): DbClient<Sql> {\n const url = cfg.url ?? process.env.DATABASE_URL;\n if (!url) {\n throw new Error('@broberg/db-sdk: missing database url — set DATABASE_URL or pass it explicitly');\n }\n // F085.7: `max` only when given. postgres.js reads an option by `k in o`, so\n // `max: undefined` was a pool of ONE connection (Array(undefined) has length\n // 1), not the driver's documented 10 — measured on vn-leker's switch, where\n // a reserved connection then left nothing for any other query.\n const raw = postgres(url, { ...PG_OPTIONS, ...(cfg.max !== undefined ? { max: cfg.max } : {}), onnotice: () => {} });\n return {\n transport: 'postgres',\n raw,\n async execute(stmt) {\n return toResult(await run(raw, stmt));\n },\n // Postgres has no write-lock-up-front mode, so both BatchModes begin a\n // plain transaction and the mode argument is not read.\n async batch(stmts) {\n const results = await raw.begin(async (tx) => {\n const out: DbResult[] = [];\n for (const s of stmts) out.push(toResult(await run(tx, s)));\n return out;\n });\n return results as DbResult[];\n },\n async close() {\n await raw.end();\n },\n };\n}\n\nexport async function postgresVersion(raw: Sql): Promise<string> {\n const [row] = await raw.unsafe('show server_version', [], PG_OPTIONS);\n return String((row as Row | undefined)?.server_version ?? 'unknown');\n}\n"],"mappings":";AAUA,SAAS,qBAAqB;AAI9B,SAAS,MAAM,MAAsC;AACnD,MAAI,OAAO,SAAS,SAAU,QAAO,CAAC,MAAM,CAAC,CAAC;AAC9C,SAAO,CAAC,KAAK,KAAK,CAAC,GAAI,KAAK,QAAQ,CAAC,CAAE,CAAC;AAC1C;AAEO,SAAS,SAAS,KAA4C;AAEnE,QAAM,IAAI,MAAM,QAAQ,GAAG,IAAI,IAAI,IAAI,SAAS,CAAC,IAAK;AACtD,QAAM,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI;AAClD,QAAM,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,OA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AAA;AAAA;AAAA,IAGA,MAAM,MAAM,OAAO;AACjB,YAAM,UAAU,MAAM,IAAI,MAAM,OAAO,OAAO;AAC5C,cAAM,MAAkB,CAAC;AACzB,mBAAW,KAAK,MAAO,KAAI,KAAKA,UAAS,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC;AAC1D,eAAO;AAAA,MACT,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,MAAM,QAAQ;AACZ,YAAM,IAAI,IAAI;AAAA,IAChB;AAAA,EACF;AACF;AAEA,eAAsB,gBAAgB,KAA2B;AAC/D,QAAM,CAAC,GAAG,IAAI,MAAM,IAAI,OAAO,uBAAuB,CAAC,GAAG,UAAU;AACpE,SAAO,OAAQ,KAAyB,kBAAkB,SAAS;AACrE;","names":["toResult","parts"]}
|
package/dist/index.js
CHANGED
|
@@ -1,67 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function toResult(res) {
|
|
8
|
-
const r = Array.isArray(res) ? res[res.length - 1] : res;
|
|
9
|
-
const columns = (r.fields ?? []).map((f) => f.name);
|
|
10
|
-
const rows = (r.rows ?? []).map((x) => ({ ...x }));
|
|
11
|
-
const isRead = r.command === "SELECT";
|
|
12
|
-
return { rows, columns, rowsAffected: isRead ? 0 : r.rowCount ?? 0 };
|
|
13
|
-
}
|
|
14
|
-
function loadPool(url, max) {
|
|
15
|
-
let pg;
|
|
16
|
-
try {
|
|
17
|
-
pg = createRequire(import.meta.url)("pg");
|
|
18
|
-
} catch {
|
|
19
|
-
throw new Error("@broberg/db-sdk: backend 'pg' needs the 'pg' package \u2014 npm i pg (or pass your own `pool`)");
|
|
20
|
-
}
|
|
21
|
-
return new pg.Pool({ connectionString: url, max });
|
|
22
|
-
}
|
|
23
|
-
function pgClient(cfg) {
|
|
24
|
-
let pool;
|
|
25
|
-
if (cfg.pool) pool = cfg.pool;
|
|
26
|
-
else {
|
|
27
|
-
const url = cfg.url ?? process.env.DATABASE_URL;
|
|
28
|
-
if (!url) throw new Error("@broberg/db-sdk: missing database url \u2014 set DATABASE_URL, pass url, or pass your own pool");
|
|
29
|
-
pool = loadPool(url, cfg.max);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
transport: "postgres",
|
|
33
|
-
raw: pool,
|
|
34
|
-
async execute(stmt) {
|
|
35
|
-
const [text, args] = parts(stmt);
|
|
36
|
-
return toResult(await pool.query(text, args));
|
|
37
|
-
},
|
|
38
|
-
async batch(stmts) {
|
|
39
|
-
const client = await pool.connect();
|
|
40
|
-
try {
|
|
41
|
-
await client.query("begin");
|
|
42
|
-
const out = [];
|
|
43
|
-
for (const s of stmts) {
|
|
44
|
-
const [text, args] = parts(s);
|
|
45
|
-
out.push(toResult(await client.query(text, args)));
|
|
46
|
-
}
|
|
47
|
-
await client.query("commit");
|
|
48
|
-
return out;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
try {
|
|
51
|
-
await client.query("rollback");
|
|
52
|
-
} catch (rb) {
|
|
53
|
-
e.rollbackError = rb;
|
|
54
|
-
}
|
|
55
|
-
throw e;
|
|
56
|
-
} finally {
|
|
57
|
-
client.release();
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
async close() {
|
|
61
|
-
if (!pool.ended) await pool.end();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
pgClient,
|
|
3
|
+
postgresClient,
|
|
4
|
+
postgresVersion
|
|
5
|
+
} from "./chunk-ONXYOFVT.js";
|
|
65
6
|
|
|
66
7
|
// src/backends/libsql.ts
|
|
67
8
|
import { createClient as createLibsqlClient } from "@libsql/client";
|
|
@@ -75,7 +16,7 @@ function toLibsql(stmt) {
|
|
|
75
16
|
if (typeof stmt === "string") return stmt;
|
|
76
17
|
return { sql: stmt.sql, args: stmt.args ?? [] };
|
|
77
18
|
}
|
|
78
|
-
function
|
|
19
|
+
function toResult(rs) {
|
|
79
20
|
const rows = rs.rows.map((r) => {
|
|
80
21
|
const row = {};
|
|
81
22
|
rs.columns.forEach((c, i) => {
|
|
@@ -90,11 +31,11 @@ function wrap(raw) {
|
|
|
90
31
|
transport: "libsql",
|
|
91
32
|
raw,
|
|
92
33
|
async execute(stmt) {
|
|
93
|
-
return
|
|
34
|
+
return toResult(await raw.execute(toLibsql(stmt)));
|
|
94
35
|
},
|
|
95
36
|
async batch(stmts, mode = "deferred") {
|
|
96
37
|
const results = await raw.batch(stmts.map(toLibsql), mode);
|
|
97
|
-
return results.map(
|
|
38
|
+
return results.map(toResult);
|
|
98
39
|
},
|
|
99
40
|
async close() {
|
|
100
41
|
raw.close();
|
|
@@ -127,56 +68,6 @@ async function libsqlVersion(raw) {
|
|
|
127
68
|
return String(res.rows[0]?.v ?? "unknown");
|
|
128
69
|
}
|
|
129
70
|
|
|
130
|
-
// src/backends/postgres.ts
|
|
131
|
-
import postgres from "postgres";
|
|
132
|
-
var PG_OPTIONS = { prepare: false };
|
|
133
|
-
function toResult3(res) {
|
|
134
|
-
const columns = (res.columns ?? []).map((c) => c.name);
|
|
135
|
-
const rows = Array.from(res, (r) => ({ ...r }));
|
|
136
|
-
const isRead = res.command === "SELECT";
|
|
137
|
-
return { rows, columns, rowsAffected: isRead ? 0 : res.count ?? 0 };
|
|
138
|
-
}
|
|
139
|
-
function parts2(stmt) {
|
|
140
|
-
if (typeof stmt === "string") return [stmt, []];
|
|
141
|
-
return [stmt.sql, [...stmt.args ?? []]];
|
|
142
|
-
}
|
|
143
|
-
function run(sql, stmt) {
|
|
144
|
-
const [text, args] = parts2(stmt);
|
|
145
|
-
return sql.unsafe(text, args, PG_OPTIONS);
|
|
146
|
-
}
|
|
147
|
-
function postgresClient(cfg) {
|
|
148
|
-
const url = cfg.url ?? process.env.DATABASE_URL;
|
|
149
|
-
if (!url) {
|
|
150
|
-
throw new Error("@broberg/db-sdk: missing database url \u2014 set DATABASE_URL or pass it explicitly");
|
|
151
|
-
}
|
|
152
|
-
const raw = postgres(url, { ...PG_OPTIONS, max: cfg.max, onnotice: () => {
|
|
153
|
-
} });
|
|
154
|
-
return {
|
|
155
|
-
transport: "postgres",
|
|
156
|
-
raw,
|
|
157
|
-
async execute(stmt) {
|
|
158
|
-
return toResult3(await run(raw, stmt));
|
|
159
|
-
},
|
|
160
|
-
// Postgres has no write-lock-up-front mode, so both BatchModes begin a
|
|
161
|
-
// plain transaction and the mode argument is not read.
|
|
162
|
-
async batch(stmts) {
|
|
163
|
-
const results = await raw.begin(async (tx) => {
|
|
164
|
-
const out = [];
|
|
165
|
-
for (const s of stmts) out.push(toResult3(await run(tx, s)));
|
|
166
|
-
return out;
|
|
167
|
-
});
|
|
168
|
-
return results;
|
|
169
|
-
},
|
|
170
|
-
async close() {
|
|
171
|
-
await raw.end();
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
async function postgresVersion(raw) {
|
|
176
|
-
const [row] = await raw.unsafe("show server_version", [], PG_OPTIONS);
|
|
177
|
-
return String(row?.server_version ?? "unknown");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
71
|
// src/index.ts
|
|
181
72
|
function createClient(cfg = {}) {
|
|
182
73
|
const backend = cfg.backend ?? "libsql";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/backends/pg.ts","../src/backends/libsql.ts","../src/backends/postgres.ts","../src/index.ts"],"sourcesContent":["/**\n * node-postgres (`pg`) transport for @broberg/db-sdk (components-F085.6).\n *\n * Why a second Postgres driver: some apps cannot move — BID runs Better Auth,\n * whose kysely dialect takes a `pg.Pool` (it recognises one by `connect`). The\n * facade is the same as the postgres.js transport: same SQL dialect ($1), same\n * DbResult shape, `transport: 'postgres'`. `pg` is an OPTIONAL peer dependency:\n * it is loaded only when `backend: 'pg'` is asked for with a `url` — pass your\n * own `pool` and this file never imports it.\n */\nimport { createRequire } from 'node:module';\nimport type { Pool, PoolClient, QueryResult } from 'pg';\nimport type { DbClient, DbResult, PgConfig, Row, Statement } from '../types';\n\nfunction parts(stmt: Statement): [string, unknown[]] {\n if (typeof stmt === 'string') return [stmt, []];\n return [stmt.sql, [...(stmt.args ?? [])]];\n}\n\nfunction toResult(res: QueryResult | QueryResult[]): DbResult {\n // A multi-statement string answers an array; the facade reports the last, like a single statement.\n const r = Array.isArray(res) ? res[res.length - 1]! : res;\n const columns = (r.fields ?? []).map((f) => f.name);\n const rows = (r.rows ?? []).map((x) => ({ ...(x as Row) }));\n const isRead = r.command === 'SELECT';\n return { rows, columns, rowsAffected: isRead ? 0 : (r.rowCount ?? 0) };\n}\n\nfunction loadPool(url: string, max?: number): Pool {\n let pg: { Pool: new (cfg: { connectionString: string; max?: number }) => Pool };\n try {\n pg = createRequire(import.meta.url)('pg');\n } catch {\n throw new Error(\"@broberg/db-sdk: backend 'pg' needs the 'pg' package — npm i pg (or pass your own `pool`)\");\n }\n return new pg.Pool({ connectionString: url, max });\n}\n\nexport function pgClient(cfg: PgConfig): DbClient<Pool> {\n let pool: Pool;\n if (cfg.pool) pool = cfg.pool;\n else {\n const url = cfg.url ?? process.env.DATABASE_URL;\n if (!url) throw new Error('@broberg/db-sdk: missing database url — set DATABASE_URL, pass url, or pass your own pool');\n pool = loadPool(url, cfg.max);\n }\n return {\n transport: 'postgres',\n raw: pool,\n async execute(stmt) {\n const [text, args] = parts(stmt);\n return toResult(await pool.query(text, args));\n },\n async batch(stmts) {\n const client: PoolClient = await pool.connect();\n try {\n await client.query('begin');\n const out: DbResult[] = [];\n for (const s of stmts) {\n const [text, args] = parts(s);\n out.push(toResult(await client.query(text, args)));\n }\n await client.query('commit');\n return out;\n } catch (e) {\n // The original error is what the caller needs; a failed rollback is\n // reported alongside it rather than replacing it.\n try {\n await client.query('rollback');\n } catch (rb) {\n (e as Error & { rollbackError?: unknown }).rollbackError = rb;\n }\n throw e;\n } finally {\n client.release();\n }\n },\n async close() {\n if (!(pool as Pool & { ended?: boolean }).ended) await pool.end();\n },\n };\n}\n","/** libSQL / Turso transport for @broberg/db-sdk. */\nimport { createClient as createLibsqlClient } from '@libsql/client';\nimport type { Client as LibsqlClient, InStatement, InValue, ResultSet } from '@libsql/client';\nimport type { BatchMode, DbClient, DbResult, LibsqlConfig, ReplicaClient, ReplicaConfig, Row, Statement } from '../types';\n\nfunction requireUrl(url: string | undefined, what: string): string {\n if (!url) {\n throw new Error(`@broberg/db-sdk: missing ${what} — set TURSO_DATABASE_URL or pass it explicitly`);\n }\n return url;\n}\n\nfunction toLibsql(stmt: Statement): InStatement {\n if (typeof stmt === 'string') return stmt;\n return { sql: stmt.sql, args: (stmt.args ?? []) as InValue[] };\n}\n\n/** libSQL rows are array-like objects; the facade hands out plain objects. */\nfunction toResult(rs: ResultSet): DbResult {\n const rows: Row[] = rs.rows.map((r) => {\n const row: Row = {};\n rs.columns.forEach((c, i) => {\n row[c] = r[i];\n });\n return row;\n });\n return { rows, columns: [...rs.columns], rowsAffected: rs.rowsAffected };\n}\n\nfunction wrap(raw: LibsqlClient): DbClient<LibsqlClient> {\n return {\n transport: 'libsql',\n raw,\n async execute(stmt) {\n return toResult(await raw.execute(toLibsql(stmt)));\n },\n async batch(stmts, mode: BatchMode = 'deferred') {\n const results = await raw.batch(stmts.map(toLibsql), mode);\n return results.map(toResult);\n },\n async close() {\n raw.close();\n },\n };\n}\n\n/** Remote libSQL/Turso client. */\nexport function libsqlClient(cfg: LibsqlConfig): DbClient<LibsqlClient> {\n const url = requireUrl(cfg.url ?? process.env.TURSO_DATABASE_URL, 'database url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n return wrap(createLibsqlClient({ url, authToken }));\n}\n\n/** Embedded replica: a local SQLite file kept in sync with the remote primary. */\nexport function libsqlReplica(cfg: ReplicaConfig): ReplicaClient {\n const syncUrl = requireUrl(cfg.syncUrl ?? process.env.TURSO_DATABASE_URL, 'sync url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n const raw = createLibsqlClient({\n url: `file:${cfg.path}`,\n syncUrl,\n authToken,\n syncInterval: cfg.syncIntervalSeconds,\n });\n return {\n ...wrap(raw),\n async sync() {\n await raw.sync();\n },\n };\n}\n\nexport async function libsqlVersion(raw: LibsqlClient): Promise<string> {\n const res = await raw.execute('select sqlite_version() as v');\n return String(res.rows[0]?.v ?? 'unknown');\n}\n","/** PostgreSQL transport for @broberg/db-sdk — Supabase included. */\nimport postgres from 'postgres';\nimport type { Sql, TransactionSql } from 'postgres';\nimport type { DbClient, DbResult, PostgresConfig, Row, Statement } from '../types';\n\n/**\n * Prepared statements are OFF, deliberately, and a test fails if they come back.\n *\n * Supabase's connection pooler in transaction mode (port 6543) hands each\n * transaction to whichever server connection is free, so a statement prepared\n * on one is missing on the next. postgres.js prepares by default. With it on,\n * everything passes against a local Postgres and fails against Supabase —\n * green until production.\n */\nexport const PG_OPTIONS = { prepare: false } as const;\n\ntype PgResult = Awaited<ReturnType<Sql['unsafe']>>;\n\nfunction toResult(res: PgResult): DbResult {\n const columns = (res.columns ?? []).map((c) => c.name);\n const rows = Array.from(res, (r) => ({ ...(r as Row) }));\n // count is the command's row count; for a SELECT that is rows returned, which\n // the facade does not call \"affected\".\n const isRead = res.command === 'SELECT';\n return { rows, columns, rowsAffected: isRead ? 0 : (res.count ?? 0) };\n}\n\nfunction parts(stmt: Statement): [string, unknown[]] {\n if (typeof stmt === 'string') return [stmt, []];\n return [stmt.sql, [...(stmt.args ?? [])]];\n}\n\nfunction run(sql: Sql | TransactionSql, stmt: Statement): Promise<PgResult> {\n const [text, args] = parts(stmt);\n return sql.unsafe(text, args as never[], PG_OPTIONS);\n}\n\nexport function postgresClient(cfg: PostgresConfig): DbClient<Sql> {\n const url = cfg.url ?? process.env.DATABASE_URL;\n if (!url) {\n throw new Error('@broberg/db-sdk: missing database url — set DATABASE_URL or pass it explicitly');\n }\n const raw = postgres(url, { ...PG_OPTIONS, max: cfg.max, onnotice: () => {} });\n return {\n transport: 'postgres',\n raw,\n async execute(stmt) {\n return toResult(await run(raw, stmt));\n },\n // Postgres has no write-lock-up-front mode, so both BatchModes begin a\n // plain transaction and the mode argument is not read.\n async batch(stmts) {\n const results = await raw.begin(async (tx) => {\n const out: DbResult[] = [];\n for (const s of stmts) out.push(toResult(await run(tx, s)));\n return out;\n });\n return results as DbResult[];\n },\n async close() {\n await raw.end();\n },\n };\n}\n\nexport async function postgresVersion(raw: Sql): Promise<string> {\n const [row] = await raw.unsafe('show server_version', [], PG_OPTIONS);\n return String((row as Row | undefined)?.server_version ?? 'unknown');\n}\n","/**\n * @broberg/db-sdk — the broberg.ai fleet's shared database client.\n *\n * One facade over two transports: libSQL/Turso and PostgreSQL (Supabase\n * included). `createClient` returns the same `DbClient` from both, so switching\n * transport is a config change at the call to `createClient` — for the\n * CONNECTION. The SQL itself is passed through untouched: libSQL takes `?`,\n * Postgres takes `$1`, and the facade does not translate between them.\n *\n * Intentionally THIN: a client, an embedded-replica client (libSQL only), and a\n * health probe. ORM, schema and migrations stay in the consumer.\n */\nimport type { LibsqlClient, Sql } from './types';\nimport type { DbClient, Health, LibsqlConfig, PgConfig, PostgresConfig, ReplicaClient, ReplicaConfig } from './types';\nimport type { Pool as PgPool } from 'pg';\nimport { pgClient } from './backends/pg';\nimport { libsqlClient, libsqlReplica, libsqlVersion } from './backends/libsql';\nimport { postgresClient, postgresVersion } from './backends/postgres';\n\nexport type {\n BatchMode,\n Client,\n DbClient,\n DbConfig,\n DbResult,\n Health,\n LibsqlClient,\n LibsqlConfig,\n PgConfig,\n PostgresConfig,\n ReplicaClient,\n ReplicaConfig,\n Row,\n Sql,\n Statement,\n Transport,\n} from './types';\n\n/**\n * Create a client against a REMOTE database.\n *\n * - libSQL/Turso (default): reads `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN`.\n * - `{ backend: 'postgres' }`: reads `DATABASE_URL`.\n */\nexport function createClient(cfg?: LibsqlConfig): DbClient<LibsqlClient>;\nexport function createClient(cfg: PostgresConfig): DbClient<Sql>;\nexport function createClient(cfg: PgConfig): DbClient<PgPool>;\nexport function createClient(cfg: LibsqlConfig | PostgresConfig | PgConfig = {}): DbClient<LibsqlClient> | DbClient<Sql> | DbClient<PgPool> {\n const backend: string = cfg.backend ?? 'libsql';\n if (cfg.backend === 'postgres') return postgresClient(cfg);\n if (cfg.backend === 'pg') return pgClient(cfg);\n if (cfg.backend === undefined || cfg.backend === 'libsql') return libsqlClient(cfg);\n throw new Error(`@broberg/db-sdk: unknown backend '${backend}' — expected 'libsql', 'postgres' or 'pg'`);\n}\n\n/**\n * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with a remote\n * Turso primary. Reads hit the local file; writes forward to the primary;\n * `sync()` (or `syncIntervalSeconds`) pulls the latest. libSQL only — there is\n * no Postgres counterpart, and the config type says so.\n */\nexport function createReplica(cfg: ReplicaConfig): ReplicaClient {\n const backend: string = cfg.backend ?? 'libsql';\n if (backend !== 'libsql') {\n throw new Error(`@broberg/db-sdk: embedded replicas are libSQL-only, got backend '${backend}'`);\n }\n return libsqlReplica(cfg);\n}\n\n/**\n * Liveness + version probe. Asks the transport itself and reports which one\n * answered — read `transport` here rather than inferring it from your config.\n * Throws if the database cannot be reached.\n */\nexport async function health(client: DbClient): Promise<Health> {\n if (client.transport === 'postgres') {\n if (typeof client.raw !== 'function') {\n // pg.Pool (an object) rather than postgres.js (a tagged-template function).\n const r = await client.execute('show server_version');\n return { ok: true, transport: 'postgres', version: String(r.rows[0]?.server_version ?? 'unknown') };\n }\n return { ok: true, transport: 'postgres', version: await postgresVersion(client.raw as Sql) };\n }\n return { ok: true, transport: 'libsql', version: await libsqlVersion(client.raw as LibsqlClient) };\n}\n"],"mappings":";AAUA,SAAS,qBAAqB;AAI9B,SAAS,MAAM,MAAsC;AACnD,MAAI,OAAO,SAAS,SAAU,QAAO,CAAC,MAAM,CAAC,CAAC;AAC9C,SAAO,CAAC,KAAK,KAAK,CAAC,GAAI,KAAK,QAAQ,CAAC,CAAE,CAAC;AAC1C;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AY,WAAY,QAAO,eAAe,GAAG;AACzD,MAAI,IAAI,YAAY,KAAM,QAAO,SAAS,GAAG;AAC7C,MAAI,IAAI,YAAY,UAAa,IAAI,YAAY,SAAU,QAAO,aAAa,GAAG;AAClF,QAAM,IAAI,MAAM,qCAAqC,OAAO,gDAA2C;AACzG;AAQO,SAAS,cAAc,KAAmC;AAC/D,QAAM,UAAkB,IAAI,WAAW;AACvC,MAAI,YAAY,UAAU;AACxB,UAAM,IAAI,MAAM,oEAAoE,OAAO,GAAG;AAAA,EAChG;AACA,SAAO,cAAc,GAAG;AAC1B;AAOA,eAAsB,OAAO,QAAmC;AAC9D,MAAI,OAAO,cAAc,YAAY;AACnC,QAAI,OAAO,OAAO,QAAQ,YAAY;AAEpC,YAAM,IAAI,MAAM,OAAO,QAAQ,qBAAqB;AACpD,aAAO,EAAE,IAAI,MAAM,WAAW,YAAY,SAAS,OAAO,EAAE,KAAK,CAAC,GAAG,kBAAkB,SAAS,EAAE;AAAA,IACpG;AACA,WAAO,EAAE,IAAI,MAAM,WAAW,YAAY,SAAS,MAAM,gBAAgB,OAAO,GAAU,EAAE;AAAA,EAC9F;AACA,SAAO,EAAE,IAAI,MAAM,WAAW,UAAU,SAAS,MAAM,cAAc,OAAO,GAAmB,EAAE;AACnG;","names":["toResult","toResult","parts"]}
|
|
1
|
+
{"version":3,"sources":["../src/backends/libsql.ts","../src/index.ts"],"sourcesContent":["/** libSQL / Turso transport for @broberg/db-sdk. */\nimport { createClient as createLibsqlClient } from '@libsql/client';\nimport type { Client as LibsqlClient, InStatement, InValue, ResultSet } from '@libsql/client';\nimport type { BatchMode, DbClient, DbResult, LibsqlConfig, ReplicaClient, ReplicaConfig, Row, Statement } from '../types';\n\nfunction requireUrl(url: string | undefined, what: string): string {\n if (!url) {\n throw new Error(`@broberg/db-sdk: missing ${what} — set TURSO_DATABASE_URL or pass it explicitly`);\n }\n return url;\n}\n\nfunction toLibsql(stmt: Statement): InStatement {\n if (typeof stmt === 'string') return stmt;\n return { sql: stmt.sql, args: (stmt.args ?? []) as InValue[] };\n}\n\n/** libSQL rows are array-like objects; the facade hands out plain objects. */\nfunction toResult(rs: ResultSet): DbResult {\n const rows: Row[] = rs.rows.map((r) => {\n const row: Row = {};\n rs.columns.forEach((c, i) => {\n row[c] = r[i];\n });\n return row;\n });\n return { rows, columns: [...rs.columns], rowsAffected: rs.rowsAffected };\n}\n\nfunction wrap(raw: LibsqlClient): DbClient<LibsqlClient> {\n return {\n transport: 'libsql',\n raw,\n async execute(stmt) {\n return toResult(await raw.execute(toLibsql(stmt)));\n },\n async batch(stmts, mode: BatchMode = 'deferred') {\n const results = await raw.batch(stmts.map(toLibsql), mode);\n return results.map(toResult);\n },\n async close() {\n raw.close();\n },\n };\n}\n\n/** Remote libSQL/Turso client. */\nexport function libsqlClient(cfg: LibsqlConfig): DbClient<LibsqlClient> {\n const url = requireUrl(cfg.url ?? process.env.TURSO_DATABASE_URL, 'database url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n return wrap(createLibsqlClient({ url, authToken }));\n}\n\n/** Embedded replica: a local SQLite file kept in sync with the remote primary. */\nexport function libsqlReplica(cfg: ReplicaConfig): ReplicaClient {\n const syncUrl = requireUrl(cfg.syncUrl ?? process.env.TURSO_DATABASE_URL, 'sync url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n const raw = createLibsqlClient({\n url: `file:${cfg.path}`,\n syncUrl,\n authToken,\n syncInterval: cfg.syncIntervalSeconds,\n });\n return {\n ...wrap(raw),\n async sync() {\n await raw.sync();\n },\n };\n}\n\nexport async function libsqlVersion(raw: LibsqlClient): Promise<string> {\n const res = await raw.execute('select sqlite_version() as v');\n return String(res.rows[0]?.v ?? 'unknown');\n}\n","/**\n * @broberg/db-sdk — the broberg.ai fleet's shared database client.\n *\n * One facade over two transports: libSQL/Turso and PostgreSQL (Supabase\n * included). `createClient` returns the same `DbClient` from both, so switching\n * transport is a config change at the call to `createClient` — for the\n * CONNECTION. The SQL itself is passed through untouched: libSQL takes `?`,\n * Postgres takes `$1`, and the facade does not translate between them.\n *\n * Intentionally THIN: a client, an embedded-replica client (libSQL only), and a\n * health probe. ORM, schema and migrations stay in the consumer.\n */\nimport type { LibsqlClient, Sql } from './types';\nimport type { DbClient, Health, LibsqlConfig, PgConfig, PostgresConfig, ReplicaClient, ReplicaConfig } from './types';\nimport type { Pool as PgPool } from 'pg';\nimport { pgClient } from './backends/pg';\nimport { libsqlClient, libsqlReplica, libsqlVersion } from './backends/libsql';\nimport { postgresClient, postgresVersion } from './backends/postgres';\n\nexport type {\n BatchMode,\n Client,\n DbClient,\n DbConfig,\n DbResult,\n Health,\n LibsqlClient,\n LibsqlConfig,\n PgConfig,\n PostgresConfig,\n ReplicaClient,\n ReplicaConfig,\n Row,\n Sql,\n Statement,\n Transport,\n} from './types';\n\n/**\n * Create a client against a REMOTE database.\n *\n * - libSQL/Turso (default): reads `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN`.\n * - `{ backend: 'postgres' }`: reads `DATABASE_URL`.\n */\nexport function createClient(cfg?: LibsqlConfig): DbClient<LibsqlClient>;\nexport function createClient(cfg: PostgresConfig): DbClient<Sql>;\nexport function createClient(cfg: PgConfig): DbClient<PgPool>;\nexport function createClient(cfg: LibsqlConfig | PostgresConfig | PgConfig = {}): DbClient<LibsqlClient> | DbClient<Sql> | DbClient<PgPool> {\n const backend: string = cfg.backend ?? 'libsql';\n if (cfg.backend === 'postgres') return postgresClient(cfg);\n if (cfg.backend === 'pg') return pgClient(cfg);\n if (cfg.backend === undefined || cfg.backend === 'libsql') return libsqlClient(cfg);\n throw new Error(`@broberg/db-sdk: unknown backend '${backend}' — expected 'libsql', 'postgres' or 'pg'`);\n}\n\n/**\n * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with a remote\n * Turso primary. Reads hit the local file; writes forward to the primary;\n * `sync()` (or `syncIntervalSeconds`) pulls the latest. libSQL only — there is\n * no Postgres counterpart, and the config type says so.\n */\nexport function createReplica(cfg: ReplicaConfig): ReplicaClient {\n const backend: string = cfg.backend ?? 'libsql';\n if (backend !== 'libsql') {\n throw new Error(`@broberg/db-sdk: embedded replicas are libSQL-only, got backend '${backend}'`);\n }\n return libsqlReplica(cfg);\n}\n\n/**\n * Liveness + version probe. Asks the transport itself and reports which one\n * answered — read `transport` here rather than inferring it from your config.\n * Throws if the database cannot be reached.\n */\nexport async function health(client: DbClient): Promise<Health> {\n if (client.transport === 'postgres') {\n if (typeof client.raw !== 'function') {\n // pg.Pool (an object) rather than postgres.js (a tagged-template function).\n const r = await client.execute('show server_version');\n return { ok: true, transport: 'postgres', version: String(r.rows[0]?.server_version ?? 'unknown') };\n }\n return { ok: true, transport: 'postgres', version: await postgresVersion(client.raw as Sql) };\n }\n return { ok: true, transport: 'libsql', version: await libsqlVersion(client.raw as LibsqlClient) };\n}\n"],"mappings":";;;;;;;AACA,SAAS,gBAAgB,0BAA0B;AAInD,SAAS,WAAW,KAAyB,MAAsB;AACjE,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,4BAA4B,IAAI,sDAAiD;AAAA,EACnG;AACA,SAAO;AACT;AAEA,SAAS,SAAS,MAA8B;AAC9C,MAAI,OAAO,SAAS,SAAU,QAAO;AACrC,SAAO,EAAE,KAAK,KAAK,KAAK,MAAO,KAAK,QAAQ,CAAC,EAAgB;AAC/D;AAGA,SAAS,SAAS,IAAyB;AACzC,QAAM,OAAc,GAAG,KAAK,IAAI,CAAC,MAAM;AACrC,UAAM,MAAW,CAAC;AAClB,OAAG,QAAQ,QAAQ,CAAC,GAAG,MAAM;AAC3B,UAAI,CAAC,IAAI,EAAE,CAAC;AAAA,IACd,CAAC;AACD,WAAO;AAAA,EACT,CAAC;AACD,SAAO,EAAE,MAAM,SAAS,CAAC,GAAG,GAAG,OAAO,GAAG,cAAc,GAAG,aAAa;AACzE;AAEA,SAAS,KAAK,KAA2C;AACvD,SAAO;AAAA,IACL,WAAW;AAAA,IACX;AAAA,IAC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AAI,YAAY,SAAU,QAAO,aAAa,GAAG;AAClF,QAAM,IAAI,MAAM,qCAAqC,OAAO,gDAA2C;AACzG;AAQO,SAAS,cAAc,KAAmC;AAC/D,QAAM,UAAkB,IAAI,WAAW;AACvC,MAAI,YAAY,UAAU;AACxB,UAAM,IAAI,MAAM,oEAAoE,OAAO,GAAG;AAAA,EAChG;AACA,SAAO,cAAc,GAAG;AAC1B;AAOA,eAAsB,OAAO,QAAmC;AAC9D,MAAI,OAAO,cAAc,YAAY;AACnC,QAAI,OAAO,OAAO,QAAQ,YAAY;AAEpC,YAAM,IAAI,MAAM,OAAO,QAAQ,qBAAqB;AACpD,aAAO,EAAE,IAAI,MAAM,WAAW,YAAY,SAAS,OAAO,EAAE,KAAK,CAAC,GAAG,kBAAkB,SAAS,EAAE;AAAA,IACpG;AACA,WAAO,EAAE,IAAI,MAAM,WAAW,YAAY,SAAS,MAAM,gBAAgB,OAAO,GAAU,EAAE;AAAA,EAC9F;AACA,SAAO,EAAE,IAAI,MAAM,WAAW,UAAU,SAAS,MAAM,cAAc,OAAO,GAAmB,EAAE;AACnG;","names":[]}
|
|
@@ -177,8 +177,9 @@ declare function unfencedTables(db: Pg$1, o?: FenceOptions): Promise<string[]>;
|
|
|
177
177
|
*
|
|
178
178
|
* ── THREE STATES PER ROW ─────────────────────────────────────────────────
|
|
179
179
|
*
|
|
180
|
-
* B the baseline at the switch to the reserve —
|
|
181
|
-
* held, just after the subscription was disabled
|
|
180
|
+
* B the baseline at the switch to the reserve — its INSTANT fixed while
|
|
181
|
+
* every machine held, just after the subscription was disabled, and its
|
|
182
|
+
* rows read after release through that snapshot (`freezeBaseline`, F085.7)
|
|
182
183
|
* R the reserve now
|
|
183
184
|
* P the primary now
|
|
184
185
|
*
|
|
@@ -214,10 +215,23 @@ declare const RECONCILE_DEFAULTS: {
|
|
|
214
215
|
readonly schema: "dbSwitch";
|
|
215
216
|
readonly bypass: "db_sdk.fence_bypass";
|
|
216
217
|
};
|
|
217
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Take the baseline B on the reserve, reading every row NOW. Kept for callers
|
|
220
|
+
* of 0.3.0; the switch itself uses `freezeBaseline`, which does not read the
|
|
221
|
+
* rows while customers wait (F085.7). Returns the row count.
|
|
222
|
+
*/
|
|
218
223
|
declare function captureBaseline(reserve: Pg, o?: ReconcileOptions): Promise<number>;
|
|
219
224
|
/** Is there a baseline — and when was it taken (epoch ms)? */
|
|
220
225
|
declare function baselineAt(reserve: Pg, o?: ReconcileOptions): Promise<number | null>;
|
|
226
|
+
/** Where the reserve's transactions stood when a pass started — see `reconcile`'s `since`. */
|
|
227
|
+
interface Horizon {
|
|
228
|
+
/** The oldest transaction the pass could not see, as a 32-bit xid (what a row's `xmin` holds). */
|
|
229
|
+
xmin: string;
|
|
230
|
+
/** The current xid at the same moment, 32-bit — to notice a wraparound in between. */
|
|
231
|
+
at: string;
|
|
232
|
+
}
|
|
233
|
+
/** Read the reserve's horizon. Take it BEFORE a pass: every row written after it has an xmin at or above it. */
|
|
234
|
+
declare function reserveHorizon(reserve: Pg): Promise<Horizon>;
|
|
221
235
|
interface Conflict {
|
|
222
236
|
table: string;
|
|
223
237
|
key: string;
|
|
@@ -249,7 +263,48 @@ interface Plan {
|
|
|
249
263
|
declare function reconcile(reserve: Pg, primary: Pg, opts: {
|
|
250
264
|
apply: boolean;
|
|
251
265
|
skipConflicts?: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* F085.7 — compare only what the reserve changed since this horizon
|
|
268
|
+
* (`reserveHorizon`, taken before an earlier full pass). For the second
|
|
269
|
+
* pass under the hold: at VN's size a full compare took 19.5 s there.
|
|
270
|
+
* Tables without a primary key are still compared in full. Falls back to
|
|
271
|
+
* a full compare if the transaction counter wrapped in between.
|
|
272
|
+
*/
|
|
273
|
+
since?: Horizon;
|
|
252
274
|
} & ReconcileOptions): Promise<Plan>;
|
|
275
|
+
/**
|
|
276
|
+
* Move every identity/serial sequence in the current schema up to the column's
|
|
277
|
+
* max (F085.7). Logical replication copies ROWS, not sequences: the reserve's
|
|
278
|
+
* sequences stand where they stood when it was created, and after the way home
|
|
279
|
+
* the primary's stand behind the ids the reserve handed out. The side that
|
|
280
|
+
* starts taking writes must not hand out an id that is already used — call
|
|
281
|
+
* this on it while every machine still holds. Never moves a sequence back.
|
|
282
|
+
* Returns the columns it checked, as `table.column`.
|
|
283
|
+
*/
|
|
284
|
+
declare function syncSequences(db: Pg): Promise<string[]>;
|
|
285
|
+
/** A baseline whose instant is fixed, and whose rows are read later. */
|
|
286
|
+
interface FrozenBaseline {
|
|
287
|
+
/** Read the rows as they were at the freeze, write the baseline, release the connection. Returns the row count. */
|
|
288
|
+
finish(): Promise<number>;
|
|
289
|
+
/** Give up: roll back, release the connection, leave no baseline. */
|
|
290
|
+
cancel(): Promise<void>;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Fix the baseline's INSTANT without reading it (F085.7). At VN's size
|
|
294
|
+
* (308,176 rows) reading the baseline under the hold kept customers waiting
|
|
295
|
+
* 3.5–5.8 s. The baseline only has to be the reserve as it was at the switch:
|
|
296
|
+
* a REPEATABLE READ transaction on a connection of its own takes its snapshot
|
|
297
|
+
* at its first statement — milliseconds — and keeps seeing exactly that while
|
|
298
|
+
* the app writes. `finish()` reads the fingerprints through it after release.
|
|
299
|
+
*
|
|
300
|
+
* The old baseline is dropped here, so until `finish()` has written the new
|
|
301
|
+
* one `baselineAt` is null and the way home refuses rather than compare
|
|
302
|
+
* against a baseline from an earlier switch.
|
|
303
|
+
*
|
|
304
|
+
* Needs the client's raw driver (postgres.js or a pg.Pool) for the dedicated
|
|
305
|
+
* connection; both transports of this package qualify.
|
|
306
|
+
*/
|
|
307
|
+
declare function freezeBaseline(reserve: Pick<DbClient<any>, 'execute' | 'batch' | 'raw'>, o?: ReconcileOptions): Promise<FrozenBaseline>;
|
|
253
308
|
|
|
254
309
|
/** A Postgres client from either driver (postgres.js or pg, components-F085.6). */
|
|
255
310
|
type AnyPg = DbClient<any>;
|
|
@@ -503,4 +558,4 @@ declare function liveDeps(env: {
|
|
|
503
558
|
supabaseRef: string;
|
|
504
559
|
}): GuardDeps;
|
|
505
560
|
|
|
506
|
-
export { type Conflict, type EmergencyDecision, FENCE_DEFAULTS, FENCE_ERRCODE, type FenceOptions, type FenceState, type GuardDeps, type GuardOptions, type GuardResult, HOLD_MAX_MS, HOLD_MIN_MS, type HoldResult, MIGRATION_FAILED, type Machine, type MachineAnswer, type OrchestrateOptions, type Outcome, type Plan, RECONCILE_DEFAULTS, RESERVE_ALARM_AFTER_MS, RESERVE_DEFAULTS, type ReconcileOptions, type ReserveIncident, type ReserveReason, type ReserveThresholds, type ReserveVerdict, type ReserveWatchState, type Restrictions, type SlotReading, type SwitchControlOptions, type SwitchableClient, type Target, type TargetSpec, baselineAt, captureBaseline, createSwitchControl, createSwitchable, emergencyGate, fenceState, httpMachine, installFence, judgeReserve, liveDeps, noteReserveMigration, orchestrateSwitch, readReserveSlot, reconcile, reserveHealth, runGuard, setFence, switchToken, unfencedTables, watchReserve };
|
|
561
|
+
export { type Conflict, type EmergencyDecision, FENCE_DEFAULTS, FENCE_ERRCODE, type FenceOptions, type FenceState, type FrozenBaseline, type GuardDeps, type GuardOptions, type GuardResult, HOLD_MAX_MS, HOLD_MIN_MS, type HoldResult, type Horizon, MIGRATION_FAILED, type Machine, type MachineAnswer, type OrchestrateOptions, type Outcome, type Plan, RECONCILE_DEFAULTS, RESERVE_ALARM_AFTER_MS, RESERVE_DEFAULTS, type ReconcileOptions, type ReserveIncident, type ReserveReason, type ReserveThresholds, type ReserveVerdict, type ReserveWatchState, type Restrictions, type SlotReading, type SwitchControlOptions, type SwitchableClient, type Target, type TargetSpec, baselineAt, captureBaseline, createSwitchControl, createSwitchable, emergencyGate, fenceState, freezeBaseline, httpMachine, installFence, judgeReserve, liveDeps, noteReserveMigration, orchestrateSwitch, readReserveSlot, reconcile, reserveHealth, reserveHorizon, runGuard, setFence, switchToken, syncSequences, unfencedTables, watchReserve };
|