@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,375 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Derived from @electric-sql/pglite-socket 0.2.11 (packages/pglite-socket/src/index.ts),
|
|
3
|
+
* Copyright Electric DB Limited, licensed under the Apache License, Version 2.0 (see
|
|
4
|
+
* `LICENSE.pglite-socket` at the package root). Modified 2026-09-28: see `NOTICE.md` at the
|
|
5
|
+
* package root for every change from upstream.
|
|
6
|
+
*/
|
|
7
|
+
import { createServer } from "node:net";
|
|
8
|
+
/**
|
|
9
|
+
* @file One PGlite served to several processes over a Unix socket, speaking the Postgres wire
|
|
10
|
+
* protocol.
|
|
11
|
+
*
|
|
12
|
+
* PGlite is ONE backend session: every connection's messages go through one queue, one at a time,
|
|
13
|
+
* and while a client has a transaction open only that client's messages run (every other client —
|
|
14
|
+
* even a new connection's startup — waits). Changes from upstream, each covered by
|
|
15
|
+
* `__tests__/pglite-socket-server.test.ts`:
|
|
16
|
+
*
|
|
17
|
+
* 1. ReadyForQuery filter. PGlite 0.5.8 answers an error in an extended-protocol message
|
|
18
|
+
* (Parse/Bind/Execute) with ErrorResponse + ReadyForQuery at once, and the later Sync with a
|
|
19
|
+
* second ReadyForQuery. Postgres sends exactly one, at Sync; the extra one shifts every later
|
|
20
|
+
* answer on that connection by one query. So `Z` frames are dropped from the answer to any typed
|
|
21
|
+
* message except Sync, Query, FunctionCall and CopyDone/CopyFail (which end a simple-protocol
|
|
22
|
+
* exchange). Version-specific: `@electric-sql/pglite` is pinned and a test asserts the pin.
|
|
23
|
+
* 2. No wedge. Upstream returned from the queue loop without clearing its "processing" flag when
|
|
24
|
+
* PGlite threw, and no later message from anyone was ever run. Here the job fails alone.
|
|
25
|
+
* 3. Idle-in-transaction timeout. A client that holds a transaction open without sending anything
|
|
26
|
+
* for `idleInTransactionTimeoutMs` is sent FATAL 25P03 and disconnected; its transaction rolls back.
|
|
27
|
+
* 4. {@link PgliteSocketServer.runExclusive}: the owning process's only way to the database while it
|
|
28
|
+
* serves (a direct `pglite.query` would run inside some client's open transaction: dirty read,
|
|
29
|
+
* lost write). Runs when no client transaction is open; nothing else runs meanwhile.
|
|
30
|
+
* 5. Unix socket only, no TCP; disconnect rollbacks go through the queue; per-connection messages
|
|
31
|
+
* are handled strictly in order; a refused connection gets a protocol ErrorResponse.
|
|
32
|
+
*/
|
|
33
|
+
const SSL_REQUEST_CODE = 80877103;
|
|
34
|
+
const GSSENC_REQUEST_CODE = 80877104;
|
|
35
|
+
const CANCEL_REQUEST_CODE = 80877102;
|
|
36
|
+
const PROTOCOL_3 = 196608;
|
|
37
|
+
/** Typed messages after which PGlite's ReadyForQuery is legitimate: Sync, Query, FunctionCall, CopyDone, CopyFail. */
|
|
38
|
+
const ENDS_EXCHANGE = new Set(["S", "Q", "F", "c", "f"].map((c) => c.charCodeAt(0)));
|
|
39
|
+
const READY_FOR_QUERY = "Z".charCodeAt(0);
|
|
40
|
+
/** The id of work that belongs to no connection ({@link PgliteSocketServer.runExclusive}). */
|
|
41
|
+
const OWNER_JOB = 0;
|
|
42
|
+
/** A Postgres ErrorResponse frame. */
|
|
43
|
+
export function errorResponseFrame(severity, code, message) {
|
|
44
|
+
const field = (tag, value) => Buffer.concat([Buffer.from(tag), Buffer.from(`${value}\0`)]);
|
|
45
|
+
const body = Buffer.concat([field("S", severity), field("V", severity), field("C", code), field("M", message), Buffer.from([0])]);
|
|
46
|
+
const head = Buffer.alloc(5);
|
|
47
|
+
head.write("E", 0);
|
|
48
|
+
head.writeInt32BE(4 + body.length, 1);
|
|
49
|
+
return Buffer.concat([head, body]);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Passes whole frames from PGlite's streamed answer to `emit`, minus ReadyForQuery when `dropReady`.
|
|
53
|
+
* Frames may arrive split across chunks, so a partial frame waits for the rest.
|
|
54
|
+
*/
|
|
55
|
+
function frameFilter(dropReady, emit) {
|
|
56
|
+
let pending = Buffer.alloc(0);
|
|
57
|
+
return {
|
|
58
|
+
push(chunk) {
|
|
59
|
+
if (!dropReady)
|
|
60
|
+
return emit(chunk);
|
|
61
|
+
pending = pending.length === 0 ? Buffer.from(chunk) : Buffer.concat([pending, chunk]);
|
|
62
|
+
const keep = [];
|
|
63
|
+
while (pending.length >= 5) {
|
|
64
|
+
const size = 1 + pending.readInt32BE(1);
|
|
65
|
+
if (pending.length < size)
|
|
66
|
+
break;
|
|
67
|
+
if (pending[0] !== READY_FOR_QUERY)
|
|
68
|
+
keep.push(pending.subarray(0, size));
|
|
69
|
+
pending = pending.subarray(size);
|
|
70
|
+
}
|
|
71
|
+
if (keep.length > 0)
|
|
72
|
+
emit(new Uint8Array(Buffer.concat(keep)));
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Half-closes `socket`, then destroys it: end() alone lets a FATAL frame written just before reach
|
|
78
|
+
* the client, but a client that never closes its side would hold `server.close()` open forever.
|
|
79
|
+
*/
|
|
80
|
+
function endSocket(socket, destroyNow) {
|
|
81
|
+
socket.end();
|
|
82
|
+
if (destroyNow)
|
|
83
|
+
socket.destroy();
|
|
84
|
+
else
|
|
85
|
+
setTimeout(() => socket.destroy(), 1000).unref();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The one queue in front of PGlite. While a transaction is open, only the job owner that opened it
|
|
89
|
+
* is served; everything else waits in arrival order.
|
|
90
|
+
*/
|
|
91
|
+
class PgliteQueue {
|
|
92
|
+
db;
|
|
93
|
+
idleInTransactionTimeoutMs;
|
|
94
|
+
onIdleInTransaction;
|
|
95
|
+
jobs = [];
|
|
96
|
+
draining = false;
|
|
97
|
+
lastOwner = null;
|
|
98
|
+
idleTimer;
|
|
99
|
+
/** Whose idle transaction {@link idleTimer} is counting; a timer already running is not restarted. */
|
|
100
|
+
idleTimerOwner = null;
|
|
101
|
+
idleWaiters = [];
|
|
102
|
+
constructor(db, idleInTransactionTimeoutMs, onIdleInTransaction) {
|
|
103
|
+
this.db = db;
|
|
104
|
+
this.idleInTransactionTimeoutMs = idleInTransactionTimeoutMs;
|
|
105
|
+
this.onIdleInTransaction = onIdleInTransaction;
|
|
106
|
+
}
|
|
107
|
+
enqueue(owner, run) {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
this.jobs.push({ owner, run, resolve, reject });
|
|
110
|
+
void this.drain();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Rejects every queued (not running) job of `owner`. */
|
|
114
|
+
dropQueued(owner, reason) {
|
|
115
|
+
for (let i = this.jobs.length - 1; i >= 0; i -= 1) {
|
|
116
|
+
if (this.jobs[i].owner === owner)
|
|
117
|
+
this.jobs.splice(i, 1)[0].reject(reason);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Rolls back `owner`'s open transaction, as the next job that owner may run. */
|
|
121
|
+
rollbackIfOwned(owner) {
|
|
122
|
+
return this.enqueue(owner, async () => {
|
|
123
|
+
if (this.db.isInTransaction() && this.lastOwner === owner)
|
|
124
|
+
await this.db.exec("ROLLBACK");
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Resolves once nothing is running (queued jobs that wait on a transaction do not count). */
|
|
128
|
+
whenIdle() {
|
|
129
|
+
return this.draining ? new Promise((resolve) => this.idleWaiters.push(resolve)) : Promise.resolve();
|
|
130
|
+
}
|
|
131
|
+
get length() {
|
|
132
|
+
return this.jobs.length;
|
|
133
|
+
}
|
|
134
|
+
next() {
|
|
135
|
+
if (this.db.isInTransaction() && this.lastOwner !== null) {
|
|
136
|
+
const index = this.jobs.findIndex((job) => job.owner === this.lastOwner);
|
|
137
|
+
return index === -1 ? undefined : this.jobs.splice(index, 1)[0];
|
|
138
|
+
}
|
|
139
|
+
return this.jobs.shift();
|
|
140
|
+
}
|
|
141
|
+
async drain() {
|
|
142
|
+
if (this.draining)
|
|
143
|
+
return;
|
|
144
|
+
this.draining = true;
|
|
145
|
+
try {
|
|
146
|
+
for (let job = this.next(); job !== undefined; job = this.next()) {
|
|
147
|
+
this.stopTimer();
|
|
148
|
+
try {
|
|
149
|
+
await job.run();
|
|
150
|
+
job.resolve();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
// Upstream returned here with the loop still marked busy: nothing was ever run again.
|
|
154
|
+
job.reject(error instanceof Error ? error : new Error(String(error)));
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
this.lastOwner = job.owner;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
this.draining = false;
|
|
163
|
+
this.armIdleTimer();
|
|
164
|
+
for (const resolve of this.idleWaiters.splice(0))
|
|
165
|
+
resolve();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
armIdleTimer() {
|
|
169
|
+
if (this.idleInTransactionTimeoutMs <= 0 || !this.db.isInTransaction() || this.lastOwner === null)
|
|
170
|
+
return;
|
|
171
|
+
const owner = this.lastOwner;
|
|
172
|
+
if (this.idleTimerOwner === owner)
|
|
173
|
+
return;
|
|
174
|
+
this.stopTimer();
|
|
175
|
+
this.idleTimerOwner = owner;
|
|
176
|
+
this.idleTimer = setTimeout(() => {
|
|
177
|
+
this.idleTimerOwner = null;
|
|
178
|
+
if (!this.draining && this.db.isInTransaction() && this.lastOwner === owner)
|
|
179
|
+
this.onIdleInTransaction(owner);
|
|
180
|
+
}, this.idleInTransactionTimeoutMs);
|
|
181
|
+
this.idleTimer.unref();
|
|
182
|
+
}
|
|
183
|
+
stopTimer() {
|
|
184
|
+
clearTimeout(this.idleTimer);
|
|
185
|
+
this.idleTimerOwner = null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** One client connection: splits the byte stream into messages and runs them in order. */
|
|
189
|
+
class Connection {
|
|
190
|
+
id;
|
|
191
|
+
socket;
|
|
192
|
+
db;
|
|
193
|
+
queue;
|
|
194
|
+
onClosed;
|
|
195
|
+
buffer = Buffer.alloc(0);
|
|
196
|
+
started = false;
|
|
197
|
+
closed = false;
|
|
198
|
+
/** Every chunk's handling chained, so a connection's messages never interleave with themselves. */
|
|
199
|
+
chain = Promise.resolve();
|
|
200
|
+
constructor(id, socket, db, queue, onClosed) {
|
|
201
|
+
this.id = id;
|
|
202
|
+
this.socket = socket;
|
|
203
|
+
this.db = db;
|
|
204
|
+
this.queue = queue;
|
|
205
|
+
this.onClosed = onClosed;
|
|
206
|
+
socket.setNoDelay(true);
|
|
207
|
+
socket.on("data", (data) => {
|
|
208
|
+
this.chain = this.chain.then(() => this.handle(data)).catch((error) => this.close(error));
|
|
209
|
+
});
|
|
210
|
+
socket.on("error", (error) => this.close(error));
|
|
211
|
+
socket.on("close", () => this.close());
|
|
212
|
+
}
|
|
213
|
+
/** Sends `frame` (an ErrorResponse) if the socket is still writable, then closes the connection. */
|
|
214
|
+
terminate(frame) {
|
|
215
|
+
if (!this.closed && this.socket.writable)
|
|
216
|
+
this.socket.write(frame);
|
|
217
|
+
this.close();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Idempotent: drops this connection's queued messages and rolls back its open transaction.
|
|
221
|
+
* `destroyNow` skips the grace period a just-written FATAL frame needs.
|
|
222
|
+
*/
|
|
223
|
+
close(_reason, destroyNow = false) {
|
|
224
|
+
if (this.closed)
|
|
225
|
+
return;
|
|
226
|
+
this.closed = true;
|
|
227
|
+
const gone = new Error("connection closed");
|
|
228
|
+
this.queue.dropQueued(this.id, gone);
|
|
229
|
+
void this.queue.rollbackIfOwned(this.id).catch(() => { });
|
|
230
|
+
endSocket(this.socket, destroyNow);
|
|
231
|
+
this.onClosed(this);
|
|
232
|
+
}
|
|
233
|
+
async handle(data) {
|
|
234
|
+
if (this.closed)
|
|
235
|
+
return;
|
|
236
|
+
this.buffer = Buffer.concat([this.buffer, data]);
|
|
237
|
+
for (;;) {
|
|
238
|
+
const message = this.nextMessage();
|
|
239
|
+
if (message === undefined)
|
|
240
|
+
return;
|
|
241
|
+
if (message === "skip")
|
|
242
|
+
continue;
|
|
243
|
+
await this.execute(message);
|
|
244
|
+
if (this.closed)
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The next complete message; `"skip"` for a request answered here (SSL/GSS: "no"; cancel:
|
|
250
|
+
* dropped, PGlite has no backend to signal); `undefined` when more bytes are needed.
|
|
251
|
+
*/
|
|
252
|
+
nextMessage() {
|
|
253
|
+
if (!this.started) {
|
|
254
|
+
if (this.buffer.length < 8)
|
|
255
|
+
return undefined;
|
|
256
|
+
const size = this.buffer.readInt32BE(0);
|
|
257
|
+
const code = this.buffer.readInt32BE(4);
|
|
258
|
+
if (this.buffer.length < size)
|
|
259
|
+
return undefined;
|
|
260
|
+
const bytes = this.buffer.subarray(0, size);
|
|
261
|
+
this.buffer = this.buffer.subarray(size);
|
|
262
|
+
if (code === SSL_REQUEST_CODE || code === GSSENC_REQUEST_CODE) {
|
|
263
|
+
this.socket.write("N");
|
|
264
|
+
return "skip";
|
|
265
|
+
}
|
|
266
|
+
if (code === CANCEL_REQUEST_CODE) {
|
|
267
|
+
this.close();
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
if (code !== PROTOCOL_3)
|
|
271
|
+
throw new Error(`unsupported protocol ${code}`);
|
|
272
|
+
this.started = true;
|
|
273
|
+
return { bytes, startup: true };
|
|
274
|
+
}
|
|
275
|
+
if (this.buffer.length < 5)
|
|
276
|
+
return undefined;
|
|
277
|
+
const size = 1 + this.buffer.readInt32BE(1);
|
|
278
|
+
if (this.buffer.length < size)
|
|
279
|
+
return undefined;
|
|
280
|
+
const bytes = this.buffer.subarray(0, size);
|
|
281
|
+
this.buffer = this.buffer.subarray(size);
|
|
282
|
+
return { bytes, startup: false };
|
|
283
|
+
}
|
|
284
|
+
execute(message) {
|
|
285
|
+
const dropReady = !message.startup && !ENDS_EXCHANGE.has(message.bytes[0]);
|
|
286
|
+
const out = frameFilter(dropReady, (data) => {
|
|
287
|
+
if (!this.closed && this.socket.writable)
|
|
288
|
+
this.socket.write(data);
|
|
289
|
+
});
|
|
290
|
+
const bytes = new Uint8Array(message.bytes);
|
|
291
|
+
return this.queue.enqueue(this.id, () => this.db.runExclusive(() => this.db.execProtocolRawStream(bytes, { onRawData: (chunk) => out.push(chunk) })));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export class PgliteSocketServer {
|
|
295
|
+
options;
|
|
296
|
+
server = null;
|
|
297
|
+
connections = new Map();
|
|
298
|
+
queue;
|
|
299
|
+
nextId = 1;
|
|
300
|
+
maxConnections;
|
|
301
|
+
constructor(options) {
|
|
302
|
+
this.options = options;
|
|
303
|
+
this.maxConnections = options.maxConnections ?? 8;
|
|
304
|
+
this.queue = new PgliteQueue(options.db, options.idleInTransactionTimeoutMs ?? 30_000, (id) => {
|
|
305
|
+
options.log?.(`connection #${id} idle in transaction; rolling back`);
|
|
306
|
+
this.connections
|
|
307
|
+
.get(id)
|
|
308
|
+
?.terminate(errorResponseFrame("FATAL", "25P03", "terminating connection due to idle-in-transaction timeout"));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
get path() {
|
|
312
|
+
return this.options.path;
|
|
313
|
+
}
|
|
314
|
+
async start() {
|
|
315
|
+
if (this.server !== null)
|
|
316
|
+
throw new Error("socket server already started");
|
|
317
|
+
await this.options.db.waitReady;
|
|
318
|
+
const server = createServer((socket) => this.accept(socket));
|
|
319
|
+
this.server = server;
|
|
320
|
+
await new Promise((resolve, reject) => {
|
|
321
|
+
server.once("error", reject);
|
|
322
|
+
server.listen(this.options.path, () => {
|
|
323
|
+
server.off("error", reject);
|
|
324
|
+
resolve();
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
server.on("error", (error) => this.options.log?.(`socket server error: ${error.message}`));
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Runs `fn` with the database to itself: after any open client transaction ends, before the next
|
|
331
|
+
* queued client message. `fn` must not leave a transaction open (it is rolled back and this throws).
|
|
332
|
+
*/
|
|
333
|
+
runExclusive(fn) {
|
|
334
|
+
let result;
|
|
335
|
+
const db = this.options.db;
|
|
336
|
+
return this.queue
|
|
337
|
+
.enqueue(OWNER_JOB, async () => {
|
|
338
|
+
try {
|
|
339
|
+
result = await fn(db);
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
if (db.isInTransaction()) {
|
|
343
|
+
await db.exec("ROLLBACK");
|
|
344
|
+
throw new Error("runExclusive(fn) left a transaction open; it was rolled back");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
.then(() => result);
|
|
349
|
+
}
|
|
350
|
+
stats() {
|
|
351
|
+
return { connections: this.connections.size, queued: this.queue.length };
|
|
352
|
+
}
|
|
353
|
+
/** Closes every connection (their transactions roll back) and the listener; waits for running work. */
|
|
354
|
+
async stop() {
|
|
355
|
+
const server = this.server;
|
|
356
|
+
this.server = null;
|
|
357
|
+
for (const connection of [...this.connections.values()])
|
|
358
|
+
connection.close(undefined, true);
|
|
359
|
+
this.queue.stopTimer();
|
|
360
|
+
this.queue.dropQueued(OWNER_JOB, new Error("socket server stopped"));
|
|
361
|
+
if (server !== null)
|
|
362
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
363
|
+
await this.queue.whenIdle();
|
|
364
|
+
}
|
|
365
|
+
accept(socket) {
|
|
366
|
+
if (this.server === null || this.connections.size >= this.maxConnections) {
|
|
367
|
+
socket.write(errorResponseFrame("FATAL", "53300", "sorry, too many clients already"));
|
|
368
|
+
endSocket(socket, false);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const connection = new Connection(this.nextId++, socket, this.options.db, this.queue, (closed) => this.connections.delete(closed.id));
|
|
372
|
+
this.connections.set(connection.id, connection);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=socket-server.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
/**
|
|
3
|
+
* @file The consumer-supplied PGlite class. Type-only: this package never imports
|
|
4
|
+
* `@electric-sql/pglite` at runtime (the consumer passes `PGlite` in), so the one copy that runs is
|
|
5
|
+
* the consumer's own.
|
|
6
|
+
*/
|
|
7
|
+
/** `typeof PGlite` from `@electric-sql/pglite` — pass the class itself: `{ PGlite }`. */
|
|
8
|
+
export type PgliteClass = typeof PGlite;
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type StorageKernel } from "../kernel/index.js";
|
|
2
|
+
import { type PgModule } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The node-postgres driver: a connection POOL to any Postgres server (local, Supabase, Neon).
|
|
5
|
+
* Kysely's own Postgres dialect; each transaction checks out its own connection, so unrelated
|
|
6
|
+
* requests run concurrently (no turn lock) and `lockKey` is what serializes the sequences that
|
|
7
|
+
* must not interleave.
|
|
8
|
+
*
|
|
9
|
+
* This package never imports `pg`: the consumer passes its own module (`import pg from "pg"`).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Opens a pooled kernel on the server at `connectionString`.
|
|
13
|
+
*
|
|
14
|
+
* @param required.pg the consumer's node-postgres module.
|
|
15
|
+
* @param optional.max pool size, default 10.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openPostgresKernel<DB>(required: {
|
|
18
|
+
pg: PgModule;
|
|
19
|
+
connectionString: string;
|
|
20
|
+
}, optional?: {
|
|
21
|
+
max?: number;
|
|
22
|
+
}): StorageKernel<DB>;
|
|
23
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import { buildKernel, PG_PARSERS, postgresLockKey } from "../kernel/index.js";
|
|
3
|
+
import { pgTypesFor } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file The node-postgres driver: a connection POOL to any Postgres server (local, Supabase, Neon).
|
|
6
|
+
* Kysely's own Postgres dialect; each transaction checks out its own connection, so unrelated
|
|
7
|
+
* requests run concurrently (no turn lock) and `lockKey` is what serializes the sequences that
|
|
8
|
+
* must not interleave.
|
|
9
|
+
*
|
|
10
|
+
* This package never imports `pg`: the consumer passes its own module (`import pg from "pg"`).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Opens a pooled kernel on the server at `connectionString`.
|
|
14
|
+
*
|
|
15
|
+
* @param required.pg the consumer's node-postgres module.
|
|
16
|
+
* @param optional.max pool size, default 10.
|
|
17
|
+
*/
|
|
18
|
+
export function openPostgresKernel(required, optional = {}) {
|
|
19
|
+
const pool = new required.pg.Pool({
|
|
20
|
+
connectionString: required.connectionString,
|
|
21
|
+
max: optional.max ?? 10,
|
|
22
|
+
types: pgTypesFor(required.pg, PG_PARSERS),
|
|
23
|
+
});
|
|
24
|
+
// An idle connection dropped by the server (restart, failover, pg_terminate_backend, a pooler's
|
|
25
|
+
// idle cut) is evicted by the pool and reopened on next use; without a listener it would crash the
|
|
26
|
+
// process.
|
|
27
|
+
pool.on("error", (err) => console.warn(`[postgres] idle pool connection dropped: ${err.message}`));
|
|
28
|
+
const base = new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
29
|
+
return buildKernel({
|
|
30
|
+
dialect: "postgres",
|
|
31
|
+
transport: "node-postgres",
|
|
32
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: false },
|
|
33
|
+
ready: Promise.resolve(),
|
|
34
|
+
base,
|
|
35
|
+
oneConnection: false,
|
|
36
|
+
begin: (body) => base.transaction().execute((tx) => body(tx)),
|
|
37
|
+
lockKey: postgresLockKey,
|
|
38
|
+
close: () => base.destroy(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Structural Postgres connection types and per-pool parser policy. No Kysely dependency. */
|
|
2
|
+
export { pgTypesFor, type PgModule, type PgPoolOptions, type PgPool, type PgPoolClient, type PgQueryResult, type PgCursor } from "./types.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StorageKernel, type StorageOps } from "../kernel/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ops for a node-postgres kernel. Must be used outside a transaction.
|
|
4
|
+
*
|
|
5
|
+
* @param required.ledgerTable the migration ledger the compaction reads back (no default).
|
|
6
|
+
* @throws {Error} a kernel of another transport.
|
|
7
|
+
* @complexity `compactAndVerify` is one full `VACUUM` pass, O(size).
|
|
8
|
+
*/
|
|
9
|
+
export declare function postgresOps<DB>(kernel: StorageKernel<DB>, required: {
|
|
10
|
+
ledgerTable: string;
|
|
11
|
+
}): StorageOps;
|
|
12
|
+
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { outsideTransactionOf, StorageOpNotSupportedError, verifyLedgerReadBack, } from "../kernel/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The storage ops for a node-postgres kernel: a Postgres server (`openPostgresKernel`) or a
|
|
5
|
+
* PGlite socket client (`openPgliteSocketKernel`) with no owner in this process. Neither can copy
|
|
6
|
+
* the database as a file; compacting is `VACUUM` (plus `CHECKPOINT` on PGlite) and a read-back of the
|
|
7
|
+
* consumer's migration ledger. A socket client whose owner runs in this process uses
|
|
8
|
+
* `@jini-ai/db/pglite`'s `pgliteOps` instead, which can copy through the owner.
|
|
9
|
+
*/
|
|
10
|
+
/** Why a Postgres server's database is never file-copied. */
|
|
11
|
+
const POSTGRES_COPY_REASON = "a Postgres database is backed up by its provider; use a transfer tool to copy it";
|
|
12
|
+
/** Why a PGlite socket client cannot copy on its own. */
|
|
13
|
+
const SOCKET_COPY_REASON = "a PGlite socket client copies through its owner's exclusive window (use pgliteOps with pgliteOwner)";
|
|
14
|
+
/**
|
|
15
|
+
* The ops for a node-postgres kernel. Must be used outside a transaction.
|
|
16
|
+
*
|
|
17
|
+
* @param required.ledgerTable the migration ledger the compaction reads back (no default).
|
|
18
|
+
* @throws {Error} a kernel of another transport.
|
|
19
|
+
* @complexity `compactAndVerify` is one full `VACUUM` pass, O(size).
|
|
20
|
+
*/
|
|
21
|
+
export function postgresOps(kernel, required) {
|
|
22
|
+
if (kernel.transport !== "node-postgres" && kernel.transport !== "pglite-socket") {
|
|
23
|
+
throw new Error(`postgresOps: a ${kernel.transport} kernel is not a node-postgres connection`);
|
|
24
|
+
}
|
|
25
|
+
const outsideTransaction = outsideTransactionOf(kernel);
|
|
26
|
+
return {
|
|
27
|
+
async copyTo() {
|
|
28
|
+
outsideTransaction("copyTo");
|
|
29
|
+
const reason = kernel.transport === "pglite-socket" ? SOCKET_COPY_REASON : POSTGRES_COPY_REASON;
|
|
30
|
+
throw new StorageOpNotSupportedError("copyTo", kernel.transport, reason);
|
|
31
|
+
},
|
|
32
|
+
async compactAndVerify() {
|
|
33
|
+
outsideTransaction("compactAndVerify");
|
|
34
|
+
if (kernel.transport === "pglite-socket") {
|
|
35
|
+
await kernel.execute(sql `VACUUM`);
|
|
36
|
+
await kernel.execute(sql `CHECKPOINT`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// A hosted server rarely lets an app's role CHECKPOINT; a commit is durable anyway.
|
|
40
|
+
await kernel.execute(sql `VACUUM (ANALYZE)`);
|
|
41
|
+
}
|
|
42
|
+
await verifyLedgerReadBack(kernel, required.ledgerTable);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ops.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type StorageKernel } from "../kernel/index.js";
|
|
2
|
+
import { type PgModule } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file A storage kernel that reaches a PGlite data dir through its owner's Unix socket
|
|
5
|
+
* (`@jini-ai/db/pglite`'s `startPgliteOwner`): node-postgres with ONE connection and the kernel's turn lock, because PGlite
|
|
6
|
+
* is one backend session — a second connection gives no parallelism, and every client's transaction
|
|
7
|
+
* blocks every other client anyway. Every process sharing the data dir uses this.
|
|
8
|
+
*
|
|
9
|
+
* Kernel rules this transport makes hard: no `SET` (only `SET LOCAL`), no temp tables, no named
|
|
10
|
+
* prepared statements, no session advisory locks — all clients share one session, so any of those
|
|
11
|
+
* leaks into the other process. Backup is not offered here; it goes through the owner.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Opens a one-connection kernel on the PGlite owner socket at `socketPath`.
|
|
15
|
+
*
|
|
16
|
+
* @param required.pg the consumer's node-postgres module (`import pg from "pg"`).
|
|
17
|
+
* @throws {Error} a path that does not end in the Postgres socket file name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function openPgliteSocketKernel<DB>(required: {
|
|
20
|
+
pg: PgModule;
|
|
21
|
+
socketPath: string;
|
|
22
|
+
}): StorageKernel<DB>;
|
|
23
|
+
//# sourceMappingURL=pglite-socket.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
3
|
+
import { buildKernel, PG_PARSERS, PGLITE_SOCKET_FILE, postgresLockKey } from "../kernel/index.js";
|
|
4
|
+
import { pgTypesFor } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @file A storage kernel that reaches a PGlite data dir through its owner's Unix socket
|
|
7
|
+
* (`@jini-ai/db/pglite`'s `startPgliteOwner`): node-postgres with ONE connection and the kernel's turn lock, because PGlite
|
|
8
|
+
* is one backend session — a second connection gives no parallelism, and every client's transaction
|
|
9
|
+
* blocks every other client anyway. Every process sharing the data dir uses this.
|
|
10
|
+
*
|
|
11
|
+
* Kernel rules this transport makes hard: no `SET` (only `SET LOCAL`), no temp tables, no named
|
|
12
|
+
* prepared statements, no session advisory locks — all clients share one session, so any of those
|
|
13
|
+
* leaks into the other process. Backup is not offered here; it goes through the owner.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Opens a one-connection kernel on the PGlite owner socket at `socketPath`.
|
|
17
|
+
*
|
|
18
|
+
* @param required.pg the consumer's node-postgres module (`import pg from "pg"`).
|
|
19
|
+
* @throws {Error} a path that does not end in the Postgres socket file name.
|
|
20
|
+
*/
|
|
21
|
+
export function openPgliteSocketKernel(required) {
|
|
22
|
+
if (!required.socketPath.endsWith(`/${PGLITE_SOCKET_FILE}`)) {
|
|
23
|
+
throw new Error(`a PGlite socket path ends in /${PGLITE_SOCKET_FILE}: ${required.socketPath}`);
|
|
24
|
+
}
|
|
25
|
+
const pool = new required.pg.Pool({
|
|
26
|
+
host: dirname(required.socketPath),
|
|
27
|
+
port: 5432,
|
|
28
|
+
user: "postgres",
|
|
29
|
+
database: "postgres",
|
|
30
|
+
max: 1,
|
|
31
|
+
// Keep the one connection: every new one's startup waits behind any open transaction.
|
|
32
|
+
idleTimeoutMillis: 0,
|
|
33
|
+
types: pgTypesFor(required.pg, PG_PARSERS),
|
|
34
|
+
});
|
|
35
|
+
// An idle connection dropped by the owner (restart, idle-in-transaction timeout) is evicted by the
|
|
36
|
+
// pool and reopened on next use; without a listener it would crash the process.
|
|
37
|
+
pool.on("error", () => { });
|
|
38
|
+
const base = new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
39
|
+
return buildKernel({
|
|
40
|
+
dialect: "postgres",
|
|
41
|
+
transport: "pglite-socket",
|
|
42
|
+
capabilities: { interactiveTransactions: true, atomicBatch: true, transactionalDdl: true, backup: false },
|
|
43
|
+
ready: Promise.resolve(),
|
|
44
|
+
base,
|
|
45
|
+
oneConnection: true,
|
|
46
|
+
begin: (body) => base.transaction().execute((tx) => body(tx)),
|
|
47
|
+
lockKey: postgresLockKey,
|
|
48
|
+
close: () => base.destroy(),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=pglite-socket.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The slice of node-postgres (`pg`) this package uses, written structurally: the consumer
|
|
3
|
+
* passes its own `pg` module (`import pg from "pg"`), so this package needs neither `pg` nor its
|
|
4
|
+
* types, and the one copy that runs is the consumer's.
|
|
5
|
+
*/
|
|
6
|
+
/** Pool options this package sets. */
|
|
7
|
+
export interface PgPoolOptions {
|
|
8
|
+
connectionString?: string;
|
|
9
|
+
host?: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
user?: string;
|
|
12
|
+
database?: string;
|
|
13
|
+
max?: number;
|
|
14
|
+
idleTimeoutMillis?: number;
|
|
15
|
+
types?: {
|
|
16
|
+
getTypeParser(oid: number, format?: "text" | "binary"): (value: string) => unknown;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** The result shape used by a Postgres connection; independent of query builders. */
|
|
20
|
+
export interface PgQueryResult<Row> {
|
|
21
|
+
command: "UPDATE" | "DELETE" | "INSERT" | "SELECT" | "MERGE";
|
|
22
|
+
rowCount: number;
|
|
23
|
+
rows: Row[];
|
|
24
|
+
}
|
|
25
|
+
/** A cursor accepted by a Postgres connection. */
|
|
26
|
+
export interface PgCursor<Row> {
|
|
27
|
+
read(rowsCount: number): Promise<Row[]>;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** A checked-out pool connection, described structurally rather than through Kysely. */
|
|
31
|
+
export interface PgPoolClient {
|
|
32
|
+
processID?: number;
|
|
33
|
+
query<Row>(sql: string, parameters: ReadonlyArray<unknown>): Promise<PgQueryResult<Row>>;
|
|
34
|
+
query<Row>(cursor: PgCursor<Row>): PgCursor<Row>;
|
|
35
|
+
release(): void;
|
|
36
|
+
}
|
|
37
|
+
/** The pool operations used by the kernel binding plus the idle-error event. */
|
|
38
|
+
export interface PgPool {
|
|
39
|
+
connect(): Promise<PgPoolClient>;
|
|
40
|
+
end(): Promise<void>;
|
|
41
|
+
options: object;
|
|
42
|
+
on(event: "error", listener: (err: Error) => void): unknown;
|
|
43
|
+
}
|
|
44
|
+
/** The `pg` module's default export: `import pg from "pg"`, passed as `{ pg }`. */
|
|
45
|
+
export interface PgModule {
|
|
46
|
+
readonly Pool: new (options: PgPoolOptions) => PgPool;
|
|
47
|
+
readonly types: {
|
|
48
|
+
getTypeParser(oid: number, format?: "text" | "binary"): (value: never) => unknown;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** node-postgres type parsing aligned with PGlite's (`PG_PARSERS`), for one pool only. */
|
|
52
|
+
export declare function pgTypesFor(pg: PgModule, parsers: Readonly<Record<number, (text: string) => unknown>>): NonNullable<PgPoolOptions["types"]>;
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The slice of node-postgres (`pg`) this package uses, written structurally: the consumer
|
|
3
|
+
* passes its own `pg` module (`import pg from "pg"`), so this package needs neither `pg` nor its
|
|
4
|
+
* types, and the one copy that runs is the consumer's.
|
|
5
|
+
*/
|
|
6
|
+
/** node-postgres type parsing aligned with PGlite's (`PG_PARSERS`), for one pool only. */
|
|
7
|
+
export function pgTypesFor(pg, parsers) {
|
|
8
|
+
return {
|
|
9
|
+
getTypeParser(oid, format) {
|
|
10
|
+
return parsers[oid] ?? pg.types.getTypeParser(oid, format);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.js.map
|