@ingram-tech/nk-db 2.1.3 → 2.3.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 +42 -4
- package/dist/fingerprint-bin.d.ts +3 -0
- package/dist/fingerprint-bin.d.ts.map +1 -0
- package/dist/fingerprint-bin.js +86 -0
- package/dist/fingerprint-bin.js.map +1 -0
- package/dist/fingerprint.d.ts +61 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +201 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/pglite/index.d.ts +12 -2
- package/dist/pglite/index.d.ts.map +1 -1
- package/dist/pglite/index.js +11 -3
- package/dist/pglite/index.js.map +1 -1
- package/dist/pglite/socket-fix.d.ts +8 -0
- package/dist/pglite/socket-fix.d.ts.map +1 -0
- package/dist/pglite/socket-fix.js +177 -0
- package/dist/pglite/socket-fix.js.map +1 -0
- package/dist/pool.d.ts +2 -2
- package/dist/pool.js +4 -4
- package/dist/pool.js.map +1 -1
- package/package.json +9 -4
- package/src/fingerprint-bin.ts +100 -0
- package/src/fingerprint.ts +291 -0
- package/src/pglite/index.ts +20 -3
- package/src/pglite/socket-fix.ts +204 -0
- package/src/pool.ts +4 -4
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ DATABASE_POOL_MAX=5 # optional; keep small on serverless
|
|
|
28
28
|
|
|
29
29
|
TLS is determined by the connection string and the CA cert, never by a flag: a
|
|
30
30
|
local host (`127.0.0.1`/`localhost`) gets no TLS and a `max: 1` pool (the
|
|
31
|
-
PGlite socket
|
|
31
|
+
PGlite socket serves one session; local detection also wins over a pulled
|
|
32
32
|
`DATABASE_POOL_MAX`/`DATABASE_CA_CERT`); with `DATABASE_CA_CERT` set the server
|
|
33
33
|
cert + hostname are verified; otherwise TLS runs without chain verification
|
|
34
34
|
(managed-provider certs aren't in Node's trust store).
|
|
@@ -146,6 +146,37 @@ The same surface is available programmatically:
|
|
|
146
146
|
`runMigrations` / `inspectMigrations` / `baselineMigrations` from
|
|
147
147
|
`@ingram-tech/nk-db/migrate`.
|
|
148
148
|
|
|
149
|
+
### Schema fingerprint (`@ingram-tech/nk-db/fingerprint`, `nk-pg-fingerprint`)
|
|
150
|
+
|
|
151
|
+
A catalog-level fingerprint of a schema, covering what the drizzle snapshot
|
|
152
|
+
cannot model: functions, triggers, policies, RLS flags, grants, ownership,
|
|
153
|
+
`DEFERRABLE` clauses, roles. It is the equivalence gate for squashing a chain
|
|
154
|
+
back to a baseline, and the honest answer to "does the chain reproduce prod":
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
nk-pg-fingerprint chain out/chain.json --migrations drizzle # a fresh in-memory PGlite from the chain
|
|
158
|
+
nk-pg-fingerprint db out/prod.json # DATABASE_URL [+ DATABASE_CA_CERT]
|
|
159
|
+
nk-pg-fingerprint diff out/chain.json out/prod.json # set-wise per key; exit 2 on any difference
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Both fingerprint modes take `--schemas a,b` (default `public`) and
|
|
163
|
+
`--roles r1,r2` (the app roles whose ownership and grants matter; other roles'
|
|
164
|
+
entries are environment noise). Chain mode applies each file whole, in journal
|
|
165
|
+
order, so a pg_dump-derived baseline works (drizzle's migrator would send it
|
|
166
|
+
as one statement), and takes `--dep <folder>` for chains applied first
|
|
167
|
+
(nk-auth's), `--id758` to pre-install the id codec functions, `--ext
|
|
168
|
+
<module>[:<export>]` for PGlite extensions and `--pre "<sql>"` for what the
|
|
169
|
+
server had before the chain ran (`create extension if not exists vector`).
|
|
170
|
+
Run it from the workspace that depends on `@electric-sql/pglite`.
|
|
171
|
+
|
|
172
|
+
Diff set-wise, never with `diff` on the files: identifier collation differs
|
|
173
|
+
between PGlite and a server, so a textual diff is sort noise. Expect a small,
|
|
174
|
+
constant noise floor between a chain and a live database (the app role's
|
|
175
|
+
`rolcanlogin`, the schema owner and ACL grantor, extension views the server
|
|
176
|
+
has); everything else is real drift, fixed with a forward migration, never in
|
|
177
|
+
the baseline. Programmatically: `fingerprintChain`, `fingerprintDatabase`,
|
|
178
|
+
`diffFingerprints`, `formatFingerprintDiff`.
|
|
179
|
+
|
|
149
180
|
## Prefixed ids (`@ingram-tech/nk-db/id`)
|
|
150
181
|
|
|
151
182
|
The codec is the standalone [`id758`](https://github.com/ingram-technologies/id758)
|
|
@@ -269,15 +300,22 @@ Tests use an in-memory instance:
|
|
|
269
300
|
```ts
|
|
270
301
|
import { createTestDb } from "@ingram-tech/nk-db/pglite";
|
|
271
302
|
|
|
272
|
-
// Vitest: fileParallelism:false (
|
|
303
|
+
// Vitest: fileParallelism:false (PGlite is one session).
|
|
273
304
|
const { pool, db, reset, close } = await createTestDb({ migrationsFolder: "drizzle" });
|
|
274
305
|
// beforeEach(reset); afterAll(close);
|
|
275
306
|
```
|
|
276
307
|
|
|
277
308
|
## Gotchas it bakes in
|
|
278
309
|
|
|
279
|
-
- **Local pool is capped at `max:1`** —
|
|
280
|
-
|
|
310
|
+
- **Local pool is capped at `max:1`** — PGlite is one Postgres session. The
|
|
311
|
+
socket accepts up to `maxConnections` (default 20, room for the several pools
|
|
312
|
+
`next dev` creates) but runs one batch at a time, so a bigger pool gains
|
|
313
|
+
nothing.
|
|
314
|
+
- **Never await a second connection inside a transaction.** On PGlite the
|
|
315
|
+
transaction holds the only session, so the second query waits forever; the
|
|
316
|
+
socket logs `nk(pglite): queue stalled …` with the holder's last SQL. Prod
|
|
317
|
+
survives it but pins two connections per request. Do the extra lookup
|
|
318
|
+
before or after the transaction.
|
|
281
319
|
- **`pg.Pool` destroys a connection on a query *error*.** Don't catch unique
|
|
282
320
|
violations as control flow — use `INSERT … ON CONFLICT DO NOTHING RETURNING …`.
|
|
283
321
|
- **`jsonb` params:** `JSON.stringify()` the value and cast `$n::jsonb` (Drizzle's
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint-bin.d.ts","sourceRoot":"","sources":["../src/fingerprint-bin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `nk-pg-fingerprint` bin: the squash / baseline equivalence gate.
|
|
3
|
+
//
|
|
4
|
+
// nk-pg-fingerprint chain out.json [--migrations drizzle] [--dep <folder>]... [--id758]
|
|
5
|
+
// [--ext <module>[:<export>]]... [--pre "<sql>"]...
|
|
6
|
+
// nk-pg-fingerprint db out.json connection from the env contract (DATABASE_URL [+ DATABASE_CA_CERT])
|
|
7
|
+
// nk-pg-fingerprint <postgres://…> out.json an explicit URL
|
|
8
|
+
// nk-pg-fingerprint diff a.json b.json set-wise per key; exit 2 on any difference
|
|
9
|
+
//
|
|
10
|
+
// Both fingerprint modes take --schemas a,b and --roles r1,r2. Run it from the
|
|
11
|
+
// workspace that depends on @electric-sql/pglite (chain mode imports it), via
|
|
12
|
+
// `bun run` so your .env is loaded.
|
|
13
|
+
//
|
|
14
|
+
// Run directly by Node, so the relative import carries a `.js` extension.
|
|
15
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { createRequire } from "node:module";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { diffFingerprints, fingerprintChain, fingerprintDatabase, formatFingerprintDiff, } from "./fingerprint.js";
|
|
19
|
+
const argv = process.argv.slice(2);
|
|
20
|
+
const VALUE_FLAGS = new Set([
|
|
21
|
+
"--migrations",
|
|
22
|
+
"--dep",
|
|
23
|
+
"--ext",
|
|
24
|
+
"--pre",
|
|
25
|
+
"--schemas",
|
|
26
|
+
"--roles",
|
|
27
|
+
]);
|
|
28
|
+
const flag = (name) => argv.includes(name);
|
|
29
|
+
const values = (name) => argv.flatMap((a, i) => (argv[i - 1] === name && !a.startsWith("--") ? [a] : []));
|
|
30
|
+
const value = (name) => values(name)[0];
|
|
31
|
+
const words = argv.filter((a, i) => !a.startsWith("--") &&
|
|
32
|
+
!(argv[i - 1] !== undefined && VALUE_FLAGS.has(argv[i - 1] ?? "")));
|
|
33
|
+
const scope = {
|
|
34
|
+
schemas: value("--schemas")?.split(","),
|
|
35
|
+
roles: value("--roles")?.split(","),
|
|
36
|
+
};
|
|
37
|
+
const usage = () => {
|
|
38
|
+
console.error("usage: nk-pg-fingerprint <chain|db|URL> <out.json> [--migrations drizzle] [--dep folder] [--id758] [--ext module[:export]] [--pre sql] [--schemas a,b] [--roles r1,r2]\n nk-pg-fingerprint diff a.json b.json");
|
|
39
|
+
return process.exit(1);
|
|
40
|
+
};
|
|
41
|
+
const main = async () => {
|
|
42
|
+
const [mode, a, b] = words;
|
|
43
|
+
if (mode === "diff") {
|
|
44
|
+
if (a === undefined || b === undefined)
|
|
45
|
+
return usage();
|
|
46
|
+
const read = (p) => JSON.parse(readFileSync(p, "utf8"));
|
|
47
|
+
const differences = diffFingerprints(read(a), read(b));
|
|
48
|
+
console.log(formatFingerprintDiff(differences, [a, b]));
|
|
49
|
+
process.exit(differences.length === 0 ? 0 : 2);
|
|
50
|
+
}
|
|
51
|
+
if (mode === undefined || a === undefined)
|
|
52
|
+
return usage();
|
|
53
|
+
let fingerprint;
|
|
54
|
+
if (mode === "chain") {
|
|
55
|
+
const req = createRequire(join(process.cwd(), "package.json"));
|
|
56
|
+
const extensions = {};
|
|
57
|
+
for (const spec of values("--ext")) {
|
|
58
|
+
const [mod = "", name = "vector"] = spec.split(":");
|
|
59
|
+
const loaded = (await import(req.resolve(mod)));
|
|
60
|
+
extensions[name] = loaded[name] ?? loaded.default;
|
|
61
|
+
}
|
|
62
|
+
fingerprint = await fingerprintChain({
|
|
63
|
+
...scope,
|
|
64
|
+
migrationsFolder: value("--migrations") ?? "drizzle",
|
|
65
|
+
dependencyMigrations: values("--dep"),
|
|
66
|
+
id758: flag("--id758"),
|
|
67
|
+
extensions,
|
|
68
|
+
pre: values("--pre"),
|
|
69
|
+
resolveFrom: process.cwd(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
fingerprint = await fingerprintDatabase({
|
|
74
|
+
...scope,
|
|
75
|
+
...(mode === "db" ? {} : { connectionString: mode }),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
mkdirSync(dirname(a), { recursive: true });
|
|
79
|
+
writeFileSync(a, `${JSON.stringify(fingerprint, null, "\t")}\n`);
|
|
80
|
+
console.log(`nk-pg-fingerprint: written to ${a}`);
|
|
81
|
+
};
|
|
82
|
+
main().catch((error) => {
|
|
83
|
+
console.error(`nk-pg-fingerprint: ${error instanceof Error ? error.message : String(error)}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=fingerprint-bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint-bin.js","sourceRoot":"","sources":["../src/fingerprint-bin.ts"],"names":[],"mappings":";AACA,uEAAuE;AACvE,EAAE;AACF,0FAA0F;AAC1F,wEAAwE;AACxE,oHAAoH;AACpH,+DAA+D;AAC/D,0FAA0F;AAC1F,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,oCAAoC;AACpC,EAAE;AACF,0EAA0E;AAC1E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC3B,cAAc;IACd,OAAO;IACP,OAAO;IACP,OAAO;IACP,WAAW;IACX,SAAS;CACT,CAAC,CAAC;AACH,MAAM,IAAI,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC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
|
|
4
|
+
/** Schemas to cover. Default `["public"]`. */
|
|
5
|
+
schemas?: string[];
|
|
6
|
+
/**
|
|
7
|
+
* Roles whose ownership and grants matter (the app's RLS roles, a view
|
|
8
|
+
* owner). Ownership and ACL entries of other roles are ignored, because the
|
|
9
|
+
* migration role differs per environment.
|
|
10
|
+
*/
|
|
11
|
+
roles?: string[];
|
|
12
|
+
}
|
|
13
|
+
export type Fingerprint = Record<string, unknown[]>;
|
|
14
|
+
/** The catalog queries, each returning one json value via json_agg with explicit ordering. */
|
|
15
|
+
export declare const fingerprintQueries: (scope?: FingerprintScope) => Record<string, string>;
|
|
16
|
+
export type FingerprintDatabaseOptions = FingerprintScope & CreatePoolConfig & {
|
|
17
|
+
/** Reuse a pool instead of creating one from the connection string. Not ended here. */
|
|
18
|
+
pool?: Pool;
|
|
19
|
+
};
|
|
20
|
+
/** Fingerprint a live database (connection from the env contract, a URL, or a pool). */
|
|
21
|
+
export declare const fingerprintDatabase: (options?: FingerprintDatabaseOptions) => Promise<Fingerprint>;
|
|
22
|
+
export interface FingerprintChainOptions extends FingerprintScope {
|
|
23
|
+
/** The chain to apply. Default `drizzle`. */
|
|
24
|
+
migrationsFolder?: string;
|
|
25
|
+
/** Chains applied before it (nk-auth's `migrations/`), in order. */
|
|
26
|
+
dependencyMigrations?: string[];
|
|
27
|
+
/** Install nk-db's id codec functions first, as `createTestDb` does. Default false. */
|
|
28
|
+
id758?: boolean;
|
|
29
|
+
/** PGlite extensions to load (`{ vector }` from `@electric-sql/pglite-pgvector`). */
|
|
30
|
+
extensions?: Record<string, unknown>;
|
|
31
|
+
/** SQL the server had before the chain ran (`create extension if not exists vector`). */
|
|
32
|
+
pre?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Directory whose `package.json` anchors the `@electric-sql/pglite` import
|
|
35
|
+
* (a site workspace that depends on it). Without it the peer resolves from
|
|
36
|
+
* nk-db's own install, which an isolated linker only satisfies when the
|
|
37
|
+
* depending workspace also lists the peer.
|
|
38
|
+
*/
|
|
39
|
+
resolveFrom?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The `.sql` files of a chain folder in journal order (sorted names without a journal). */
|
|
42
|
+
export declare const chainFiles: (folder: string) => string[];
|
|
43
|
+
/**
|
|
44
|
+
* Fingerprint a fresh in-memory PGlite booted from a chain. Every file is
|
|
45
|
+
* exec'd whole, in journal order: drizzle's migrator sends a file as one
|
|
46
|
+
* query, which a pg_dump-derived baseline (no breakpoints, `DO $$` blocks,
|
|
47
|
+
* `SET LOCAL ROLE`) is not. `@electric-sql/pglite` is the optional peer.
|
|
48
|
+
*/
|
|
49
|
+
export declare const fingerprintChain: (options?: FingerprintChainOptions) => Promise<Fingerprint>;
|
|
50
|
+
export interface FingerprintDifference {
|
|
51
|
+
key: string;
|
|
52
|
+
/** Entries only the first fingerprint has, as canonical JSON. */
|
|
53
|
+
onlyA: string[];
|
|
54
|
+
/** Entries only the second fingerprint has, as canonical JSON. */
|
|
55
|
+
onlyB: string[];
|
|
56
|
+
}
|
|
57
|
+
/** Set-wise, per-key difference between two fingerprints; empty when equivalent. */
|
|
58
|
+
export declare const diffFingerprints: (a: Fingerprint, b: Fingerprint) => FingerprintDifference[];
|
|
59
|
+
/** Human-readable rendering of a diff, `limit` entries per side per key. */
|
|
60
|
+
export declare const formatFingerprintDiff: (differences: FingerprintDifference[], labels?: [string, string], limit?: number) => string;
|
|
61
|
+
//# sourceMappingURL=fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE9D,MAAM,WAAW,gBAAgB;IAChC,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EA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KACZ,qBAAqB,EAWvB,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,gBACpB,qBAAqB,EAAE,WAC5B,CAAC,MAAM,EAAE,MAAM,CAAC,qBAEtB,MAaF,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Catalog-level schema fingerprint: the squash / baseline equivalence gate.
|
|
2
|
+
//
|
|
3
|
+
// A normalized JSON view of everything a schema is made of, including what
|
|
4
|
+
// drizzle's snapshot cannot model (functions, triggers, grants, policies,
|
|
5
|
+
// ownership, DEFERRABLE clauses, roles), so two databases can be diffed
|
|
6
|
+
// structurally. Two sources: a fresh in-memory PGlite booted from a migration
|
|
7
|
+
// chain, or a live database. Diff set-wise per key, never positionally:
|
|
8
|
+
// identifier collation differs between PGlite and a server, so a textual diff
|
|
9
|
+
// is sort noise.
|
|
10
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
import { createPool } from "./pool.js";
|
|
14
|
+
const DEFAULT_SCHEMAS = ["public"];
|
|
15
|
+
const DEFAULT_ROLES = ["anon", "authenticated", "service_role", "authenticator"];
|
|
16
|
+
const quoteList = (values) => `in (${values.map((v) => `'${v.replace(/'/g, "''")}'`).join(",")})`;
|
|
17
|
+
/** The catalog queries, each returning one json value via json_agg with explicit ordering. */
|
|
18
|
+
export const fingerprintQueries = (scope = {}) => {
|
|
19
|
+
const inSchemas = quoteList(scope.schemas ?? DEFAULT_SCHEMAS);
|
|
20
|
+
const inRoles = quoteList(scope.roles ?? DEFAULT_ROLES);
|
|
21
|
+
return {
|
|
22
|
+
schemas: `select coalesce(json_agg(s order by s.nspname), '[]') from (
|
|
23
|
+
select n.nspname, pg_get_userbyid(n.nspowner) as owner,
|
|
24
|
+
coalesce((select json_agg(x order by x) from unnest(n.nspacl::text[]) x), '[]'::json) as acl
|
|
25
|
+
from pg_namespace n where n.nspname ${inSchemas}) s`,
|
|
26
|
+
relowners: `select coalesce(json_agg(o order by o.rel), '[]') from (
|
|
27
|
+
select n.nspname || '.' || cl.relname as rel, cl.relkind::text as kind,
|
|
28
|
+
pg_get_userbyid(cl.relowner) as owner, coalesce(cl.reloptions::text, '') as options
|
|
29
|
+
from pg_class cl join pg_namespace n on n.oid = cl.relnamespace
|
|
30
|
+
where n.nspname ${inSchemas} and cl.relkind in ('r','p','v','m')
|
|
31
|
+
and pg_get_userbyid(cl.relowner) ${inRoles}) o`,
|
|
32
|
+
roles: `select coalesce(json_agg(r order by r.rolname), '[]') from (
|
|
33
|
+
select rolname, rolsuper, rolinherit, rolcanlogin, rolbypassrls from pg_roles where rolname ${inRoles}) r`,
|
|
34
|
+
enums: `select coalesce(json_agg(e order by e.typname, e.sort), '[]') from (
|
|
35
|
+
select t.typname, en.enumsortorder as sort, en.enumlabel
|
|
36
|
+
from pg_type t join pg_namespace n on n.oid = t.typnamespace join pg_enum en on en.enumtypid = t.oid
|
|
37
|
+
where n.nspname ${inSchemas}) e`,
|
|
38
|
+
columns: `select coalesce(json_agg(c order by c.rel, c.col), '[]') from (
|
|
39
|
+
select n.nspname || '.' || cl.relname as rel, a.attname as col,
|
|
40
|
+
format_type(a.atttypid, a.atttypmod) as type, a.attnotnull as notnull,
|
|
41
|
+
pg_get_expr(d.adbin, d.adrelid) as default, a.attidentity as identity, a.attgenerated as generated
|
|
42
|
+
from pg_attribute a join pg_class cl on cl.oid = a.attrelid join pg_namespace n on n.oid = cl.relnamespace
|
|
43
|
+
left join pg_attrdef d on d.adrelid = a.attrelid and d.adnum = a.attnum
|
|
44
|
+
where n.nspname ${inSchemas} and cl.relkind in ('r','p') and a.attnum > 0 and not a.attisdropped) c`,
|
|
45
|
+
constraints: `select coalesce(json_agg(c order by c.rel, c.name), '[]') from (
|
|
46
|
+
select co.conrelid::regclass::text as rel, co.conname as name, pg_get_constraintdef(co.oid) as def
|
|
47
|
+
from pg_constraint co join pg_namespace n on n.oid = co.connamespace where n.nspname ${inSchemas}) c`,
|
|
48
|
+
indexes: `select coalesce(json_agg(i order by i.indexname), '[]') from (
|
|
49
|
+
select schemaname, tablename, indexname, indexdef from pg_indexes where schemaname ${inSchemas}) i`,
|
|
50
|
+
triggers: `select coalesce(json_agg(t order by t.rel, t.name), '[]') from (
|
|
51
|
+
select tg.tgrelid::regclass::text as rel, tg.tgname as name, pg_get_triggerdef(tg.oid) as def
|
|
52
|
+
from pg_trigger tg join pg_class cl on cl.oid = tg.tgrelid join pg_namespace n on n.oid = cl.relnamespace
|
|
53
|
+
where n.nspname ${inSchemas} and not tg.tgisinternal) t`,
|
|
54
|
+
functions: `select coalesce(json_agg(f order by f.schema, f.name, f.args), '[]') from (
|
|
55
|
+
select n.nspname as schema, p.proname as name, pg_get_function_identity_arguments(p.oid) as args,
|
|
56
|
+
pg_get_functiondef(p.oid) as def
|
|
57
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
58
|
+
where n.nspname ${inSchemas} and p.prokind in ('f','p')
|
|
59
|
+
and not exists (select 1 from pg_depend dep where dep.objid = p.oid and dep.deptype = 'e')) f`,
|
|
60
|
+
policies: `select coalesce(json_agg(p order by p.tablename, p.policyname), '[]') from (
|
|
61
|
+
select schemaname, tablename, policyname, permissive, roles::text[] as roles, cmd, qual, with_check
|
|
62
|
+
from pg_policies where schemaname ${inSchemas}) p`,
|
|
63
|
+
rls: `select coalesce(json_agg(r order by r.rel), '[]') from (
|
|
64
|
+
select n.nspname || '.' || cl.relname as rel, cl.relrowsecurity as enabled, cl.relforcerowsecurity as forced
|
|
65
|
+
from pg_class cl join pg_namespace n on n.oid = cl.relnamespace where n.nspname ${inSchemas} and cl.relkind = 'r') r`,
|
|
66
|
+
views: `select coalesce(json_agg(v order by v.schemaname, v.viewname), '[]') from (
|
|
67
|
+
select vw.schemaname, vw.viewname, vw.definition
|
|
68
|
+
from pg_views vw join pg_class cl on cl.relname = vw.viewname
|
|
69
|
+
join pg_namespace n on n.oid = cl.relnamespace and n.nspname = vw.schemaname
|
|
70
|
+
where vw.schemaname ${inSchemas}
|
|
71
|
+
and not exists (select 1 from pg_depend dep where dep.objid = cl.oid and dep.deptype = 'e')) v`,
|
|
72
|
+
sequences: `select coalesce(json_agg(s order by s.sequencename), '[]') from (
|
|
73
|
+
select schemaname, sequencename, data_type::text, start_value, min_value, max_value, increment_by, cycle
|
|
74
|
+
from pg_sequences where schemaname ${inSchemas}) s`,
|
|
75
|
+
// ACLs from pg_class / pg_proc via aclexplode, not information_schema,
|
|
76
|
+
// whose role_*_grants views hide rows whose grantor is not an enabled
|
|
77
|
+
// role for the connecting user. The grantor is environment-specific and
|
|
78
|
+
// omitted.
|
|
79
|
+
table_grants: `select coalesce(json_agg(g order by g.table_schema, g.table_name, g.grantee, g.privilege_type), '[]') from (
|
|
80
|
+
select distinct n.nspname as table_schema, cl.relname as table_name,
|
|
81
|
+
acl.grantee::regrole::text as grantee, acl.privilege_type
|
|
82
|
+
from pg_class cl join pg_namespace n on n.oid = cl.relnamespace, lateral aclexplode(cl.relacl) acl
|
|
83
|
+
where n.nspname ${inSchemas} and cl.relkind in ('r','p','v','m')
|
|
84
|
+
and acl.grantee::regrole::text ${inRoles}) g`,
|
|
85
|
+
routine_grants: `select coalesce(json_agg(g order by g.routine, g.grantee), '[]') from (
|
|
86
|
+
select distinct n.nspname || '.' || p.proname as routine, acl.grantee::regrole::text as grantee, acl.privilege_type
|
|
87
|
+
from pg_proc p join pg_namespace n on n.oid = p.pronamespace, lateral aclexplode(p.proacl) acl
|
|
88
|
+
where n.nspname ${inSchemas} and acl.grantee::regrole::text ${inRoles}) g`,
|
|
89
|
+
default_acls: `select coalesce(json_agg(d order by d.role, d.schema, d.objtype), '[]') from (
|
|
90
|
+
select defaclrole::regrole::text as role, coalesce(defaclnamespace::regnamespace::text, '') as schema,
|
|
91
|
+
defaclobjtype as objtype, defaclacl::text as acl from pg_default_acl) d`,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const collect = async (run, scope) => {
|
|
95
|
+
const out = {};
|
|
96
|
+
for (const [name, sql] of Object.entries(fingerprintQueries(scope))) {
|
|
97
|
+
const value = await run(sql);
|
|
98
|
+
out[name] = Array.isArray(value) ? value : [];
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
const firstColumn = async (db, sql) => {
|
|
103
|
+
const { rows } = await db.query(sql);
|
|
104
|
+
return Object.values(rows[0] ?? {})[0];
|
|
105
|
+
};
|
|
106
|
+
/** Fingerprint a live database (connection from the env contract, a URL, or a pool). */
|
|
107
|
+
export const fingerprintDatabase = async (options = {}) => {
|
|
108
|
+
const pool = options.pool ?? createPool(options);
|
|
109
|
+
try {
|
|
110
|
+
return await collect((sql) => firstColumn(pool, sql), options);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (!options.pool)
|
|
114
|
+
await pool.end();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const loadPglite = async (from) => {
|
|
118
|
+
if (from !== undefined) {
|
|
119
|
+
const req = createRequire(join(resolve(from), "package.json"));
|
|
120
|
+
return (await import(req.resolve("@electric-sql/pglite")));
|
|
121
|
+
}
|
|
122
|
+
return import("@electric-sql/pglite");
|
|
123
|
+
};
|
|
124
|
+
/** The `.sql` files of a chain folder in journal order (sorted names without a journal). */
|
|
125
|
+
export const chainFiles = (folder) => {
|
|
126
|
+
try {
|
|
127
|
+
const journal = JSON.parse(readFileSync(join(folder, "meta", "_journal.json"), "utf8"));
|
|
128
|
+
return journal.entries.map((e) => join(folder, `${e.tag}.sql`));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return readdirSync(folder)
|
|
132
|
+
.filter((f) => f.endsWith(".sql"))
|
|
133
|
+
.sort()
|
|
134
|
+
.map((f) => join(folder, f));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Fingerprint a fresh in-memory PGlite booted from a chain. Every file is
|
|
139
|
+
* exec'd whole, in journal order: drizzle's migrator sends a file as one
|
|
140
|
+
* query, which a pg_dump-derived baseline (no breakpoints, `DO $$` blocks,
|
|
141
|
+
* `SET LOCAL ROLE`) is not. `@electric-sql/pglite` is the optional peer.
|
|
142
|
+
*/
|
|
143
|
+
export const fingerprintChain = async (options = {}) => {
|
|
144
|
+
const { PGlite } = await loadPglite(options.resolveFrom);
|
|
145
|
+
const db = new PGlite({ extensions: (options.extensions ?? {}) });
|
|
146
|
+
try {
|
|
147
|
+
if (options.id758) {
|
|
148
|
+
const { ID758_SQL } = await import("id758/sql");
|
|
149
|
+
await db.exec(ID758_SQL);
|
|
150
|
+
}
|
|
151
|
+
for (const sql of options.pre ?? [])
|
|
152
|
+
await db.exec(sql);
|
|
153
|
+
const folders = [
|
|
154
|
+
...(options.dependencyMigrations ?? []),
|
|
155
|
+
options.migrationsFolder ?? "drizzle",
|
|
156
|
+
].map((f) => resolve(f));
|
|
157
|
+
for (const folder of folders) {
|
|
158
|
+
for (const file of chainFiles(folder)) {
|
|
159
|
+
// PGlite does not persist a session SET across exec calls.
|
|
160
|
+
await db.exec(`set search_path to public;\n${readFileSync(file, "utf8")}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return await collect((sql) => firstColumn(db, sql), options);
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
await db.close();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const canonical = (value) => JSON.stringify(value, (_key, v) => v !== null && typeof v === "object" && !Array.isArray(v)
|
|
170
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a.localeCompare(b)))
|
|
171
|
+
: v);
|
|
172
|
+
/** Set-wise, per-key difference between two fingerprints; empty when equivalent. */
|
|
173
|
+
export const diffFingerprints = (a, b) => {
|
|
174
|
+
const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].sort();
|
|
175
|
+
const out = [];
|
|
176
|
+
for (const key of keys) {
|
|
177
|
+
const sa = new Set((a[key] ?? []).map(canonical));
|
|
178
|
+
const sb = new Set((b[key] ?? []).map(canonical));
|
|
179
|
+
const onlyA = [...sa].filter((x) => !sb.has(x)).sort();
|
|
180
|
+
const onlyB = [...sb].filter((x) => !sa.has(x)).sort();
|
|
181
|
+
if (onlyA.length > 0 || onlyB.length > 0)
|
|
182
|
+
out.push({ key, onlyA, onlyB });
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
};
|
|
186
|
+
/** Human-readable rendering of a diff, `limit` entries per side per key. */
|
|
187
|
+
export const formatFingerprintDiff = (differences, labels = ["a", "b"], limit = 12) => {
|
|
188
|
+
const lines = [];
|
|
189
|
+
let total = 0;
|
|
190
|
+
for (const d of differences) {
|
|
191
|
+
total += d.onlyA.length + d.onlyB.length;
|
|
192
|
+
lines.push(`## ${d.key}: only in ${labels[0]}: ${d.onlyA.length}, only in ${labels[1]}: ${d.onlyB.length}`);
|
|
193
|
+
for (const x of d.onlyA.slice(0, limit))
|
|
194
|
+
lines.push(` - ${x}`);
|
|
195
|
+
for (const x of d.onlyB.slice(0, limit))
|
|
196
|
+
lines.push(` + ${x}`);
|
|
197
|
+
}
|
|
198
|
+
lines.push(`TOTAL DIFFS ${total}`);
|
|
199
|
+
return lines.join("\n");
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,wEAAwE;AACxE,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAC9E,iBAAiB;AACjB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO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C,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC"}
|
package/dist/pglite/index.d.ts
CHANGED
|
@@ -49,6 +49,15 @@ export interface PgliteServerOptions {
|
|
|
49
49
|
* `CREATE EXTENSION` them: PGlite only knows the extensions passed here.
|
|
50
50
|
*/
|
|
51
51
|
extensions?: Extensions;
|
|
52
|
+
/**
|
|
53
|
+
* How many TCP connections the socket accepts. Default `20`. They share
|
|
54
|
+
* PGlite's one session, one message batch at a time (see `socket-fix.ts`),
|
|
55
|
+
* so this buys no parallelism: it is room for every pool `next dev` creates
|
|
56
|
+
* (one per module graph and process) and for a `psql` alongside. At `1`,
|
|
57
|
+
* pglite-socket's own default, the second pool is refused and its query
|
|
58
|
+
* fails with "Connection terminated unexpectedly".
|
|
59
|
+
*/
|
|
60
|
+
maxConnections?: number;
|
|
52
61
|
}
|
|
53
62
|
export interface PgliteServer {
|
|
54
63
|
db: PGlite;
|
|
@@ -61,8 +70,9 @@ export interface PgliteServer {
|
|
|
61
70
|
* Boot PGlite, apply migrations (on a fresh/in-memory db), and expose it over a
|
|
62
71
|
* TCP socket so a normal `pg.Pool` connects via `DATABASE_URL` with no app code
|
|
63
72
|
* changes. Reused by both `startPgliteDev` (persisted) and `createTestDb`
|
|
64
|
-
* (in-memory). The socket
|
|
65
|
-
* at `max: 1`
|
|
73
|
+
* (in-memory). The socket accepts several connections but serves them from one
|
|
74
|
+
* session, one batch at a time, so a pool above `max: 1` gains nothing
|
|
75
|
+
* (createPool caps local hosts at 1).
|
|
66
76
|
*/
|
|
67
77
|
export declare const createPgliteServer: (options?: PgliteServerOptions) => Promise<PgliteServer>;
|
|
68
78
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pglite/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pglite/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAI/B,MAAM,WAAW,mBAAmB;IACnC,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;;;;OASG;IACH,oBAAoB,CAAC,EAAE,KAAK,CAAC;QAC5B,yEAAyE;QACzE,MAAM,EAAE,MAAM,CAAC;QACf;sFAC8E;QAC9E,KAAK,EAAE,MAAM,CAAC;QACd,+CAA+C;QAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IACH;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;+DAC2D;IAC3D,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,kBAAkB,CAAC;IAC3B,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AA2CD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,aACrB,mBAAmB,KAC1B,OAAO,CAAC,YAAY,CA0CtB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,aACjB,mBAAmB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,KACpD,OAAO,CAAC,IAAI,CAgCd,CAAC;AAEF,MAAM,WAAW,MAAM;IACtB,2EAA2E;IAC3E,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,4DAA4D;IAC5D,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,aACf,mBAAmB,KAC1B,OAAO,CAAC,MAAM,CAiBhB,CAAC"}
|
package/dist/pglite/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { PGlite } from "@electric-sql/pglite";
|
|
|
14
14
|
import { PGLiteSocketServer } from "@electric-sql/pglite-socket";
|
|
15
15
|
import { ID758_SQL } from "id758/sql";
|
|
16
16
|
import { resetPublicTables } from "./reset.js";
|
|
17
|
+
import { isolateConnections } from "./socket-fix.js";
|
|
17
18
|
/** Ask the OS for a currently-free TCP port (bind :0, read it back, release).
|
|
18
19
|
* Used so the test harness never collides with a dev Postgres on 5432. */
|
|
19
20
|
const freePort = (host) => new Promise((resolve, reject) => {
|
|
@@ -51,8 +52,9 @@ const applyDependencyMigrations = async (db, chains) => {
|
|
|
51
52
|
* Boot PGlite, apply migrations (on a fresh/in-memory db), and expose it over a
|
|
52
53
|
* TCP socket so a normal `pg.Pool` connects via `DATABASE_URL` with no app code
|
|
53
54
|
* changes. Reused by both `startPgliteDev` (persisted) and `createTestDb`
|
|
54
|
-
* (in-memory). The socket
|
|
55
|
-
* at `max: 1`
|
|
55
|
+
* (in-memory). The socket accepts several connections but serves them from one
|
|
56
|
+
* session, one batch at a time, so a pool above `max: 1` gains nothing
|
|
57
|
+
* (createPool caps local hosts at 1).
|
|
56
58
|
*/
|
|
57
59
|
export const createPgliteServer = async (options = {}) => {
|
|
58
60
|
const host = options.host ?? "127.0.0.1";
|
|
@@ -79,7 +81,13 @@ export const createPgliteServer = async (options = {}) => {
|
|
|
79
81
|
await db.exec(ID758_SQL);
|
|
80
82
|
await applyDependencyMigrations(db, options.dependencyMigrations ?? []);
|
|
81
83
|
await (options.migrate ?? defaultMigrate(migrationsFolder))(db);
|
|
82
|
-
const server = new PGLiteSocketServer({
|
|
84
|
+
const server = new PGLiteSocketServer({
|
|
85
|
+
db,
|
|
86
|
+
host,
|
|
87
|
+
port,
|
|
88
|
+
maxConnections: options.maxConnections ?? 20,
|
|
89
|
+
});
|
|
90
|
+
isolateConnections(server, db);
|
|
83
91
|
await server.start();
|
|
84
92
|
const databaseUrl = `postgresql://postgres:postgres@${host}:${port}/postgres`;
|
|
85
93
|
const stop = async () => {
|
package/dist/pglite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pglite/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iFAAiF;AACjF,uEAAuE;AACvE,iFAAiF;AACjF,sBAAsB;AACtB,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,2CAA2C;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,EAAE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;;;;GAmBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAChC,OAAO,GAAwB,EAAE,EACf,EAAE;IACpB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC;IACzC,MAAM,IAAI,GACT,OAAO,CAAC,IAAI;QACZ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YACjC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,MAAM,kBAAkB,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACnF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,GAAkB,EAAE,CACjC,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAwB,GAAG,CAAC,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,KAAK,IAAmB,EAAE;QACvC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,MAAM,IAAI,EAAE,CAAC;IACd,CAAC,CAAC;IACF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import type { PGLiteSocketServer } from "@electric-sql/pglite-socket";
|
|
3
|
+
/**
|
|
4
|
+
* Patch `server`'s query queue so several connections can share `db` safely.
|
|
5
|
+
* Call before `server.start()`. Returns whether the patch was applied.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isolateConnections: (server: PGLiteSocketServer, db: PGlite) => boolean;
|
|
8
|
+
//# sourceMappingURL=socket-fix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-fix.d.ts","sourceRoot":"","sources":["../../src/pglite/socket-fix.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAmDtE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WAAY,kBAAkB,MAAM,MAAM,KAAG,OA2H3E,CAAC"}
|