@prisma-next/sql-runtime 0.3.0-dev.7 → 0.3.0-dev.71
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/LICENSE +201 -0
- package/README.md +137 -26
- package/dist/exports-BhZqJPVb.mjs +771 -0
- package/dist/exports-BhZqJPVb.mjs.map +1 -0
- package/dist/index-D59jqEKF.d.mts +159 -0
- package/dist/index-D59jqEKF.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/test/utils.d.mts +82 -0
- package/dist/test/utils.d.mts.map +1 -0
- package/dist/test/utils.mjs +212 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +32 -25
- package/src/codecs/decoding.ts +84 -3
- package/src/codecs/encoding.ts +15 -2
- package/src/codecs/json-schema-validation.ts +61 -0
- package/src/exports/index.ts +14 -6
- package/src/lower-sql-plan.ts +8 -8
- package/src/plugins/lints.ts +204 -0
- package/src/sql-context.ts +385 -98
- package/src/sql-family-adapter.ts +9 -5
- package/src/sql-marker.ts +2 -2
- package/src/sql-runtime.ts +131 -31
- package/test/async-iterable-result.test.ts +42 -34
- package/test/context.types.test-d.ts +68 -0
- package/test/execution-stack.test.ts +166 -0
- package/test/json-schema-validation.test.ts +653 -0
- package/test/lints.test.ts +330 -0
- package/test/parameterized-types.test.ts +539 -0
- package/test/sql-context.test.ts +292 -117
- package/test/sql-family-adapter.test.ts +7 -6
- package/test/sql-runtime.test.ts +218 -30
- package/test/utils.ts +80 -51
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js +0 -137863
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js.map +0 -1
- package/dist/amcheck-24VY6X5V.js +0 -13
- package/dist/amcheck-24VY6X5V.js.map +0 -1
- package/dist/bloom-VS74NLHT.js +0 -13
- package/dist/bloom-VS74NLHT.js.map +0 -1
- package/dist/btree_gin-WBC4EAAI.js +0 -13
- package/dist/btree_gin-WBC4EAAI.js.map +0 -1
- package/dist/btree_gist-UNC6QD3M.js +0 -13
- package/dist/btree_gist-UNC6QD3M.js.map +0 -1
- package/dist/chunk-3KTOEDFX.js +0 -49
- package/dist/chunk-3KTOEDFX.js.map +0 -1
- package/dist/chunk-47DZBRQC.js +0 -1280
- package/dist/chunk-47DZBRQC.js.map +0 -1
- package/dist/chunk-52N6AFZM.js +0 -133
- package/dist/chunk-52N6AFZM.js.map +0 -1
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-7D4SUZUM.js.map +0 -1
- package/dist/chunk-C6I3V3DM.js +0 -455
- package/dist/chunk-C6I3V3DM.js.map +0 -1
- package/dist/chunk-ECWIHLAT.js +0 -37
- package/dist/chunk-ECWIHLAT.js.map +0 -1
- package/dist/chunk-EI626SDC.js +0 -105
- package/dist/chunk-EI626SDC.js.map +0 -1
- package/dist/chunk-UKKOYUGL.js +0 -578
- package/dist/chunk-UKKOYUGL.js.map +0 -1
- package/dist/chunk-XPLNMXQV.js +0 -1537
- package/dist/chunk-XPLNMXQV.js.map +0 -1
- package/dist/citext-T7MXGUY7.js +0 -13
- package/dist/citext-T7MXGUY7.js.map +0 -1
- package/dist/client-5FENX6AW.js +0 -299
- package/dist/client-5FENX6AW.js.map +0 -1
- package/dist/cube-TFDQBZCI.js +0 -13
- package/dist/cube-TFDQBZCI.js.map +0 -1
- package/dist/dict_int-AEUOPGWP.js +0 -13
- package/dist/dict_int-AEUOPGWP.js.map +0 -1
- package/dist/dict_xsyn-DAAYX3FL.js +0 -13
- package/dist/dict_xsyn-DAAYX3FL.js.map +0 -1
- package/dist/dist-AQ3LWXOX.js +0 -570
- package/dist/dist-AQ3LWXOX.js.map +0 -1
- package/dist/dist-LBVX6BJW.js +0 -189
- package/dist/dist-LBVX6BJW.js.map +0 -1
- package/dist/dist-WLKUVDN2.js +0 -5127
- package/dist/dist-WLKUVDN2.js.map +0 -1
- package/dist/earthdistance-KIGTF4LE.js +0 -13
- package/dist/earthdistance-KIGTF4LE.js.map +0 -1
- package/dist/file_fdw-5N55UP6I.js +0 -13
- package/dist/file_fdw-5N55UP6I.js.map +0 -1
- package/dist/fuzzystrmatch-KN3YWBFP.js +0 -13
- package/dist/fuzzystrmatch-KN3YWBFP.js.map +0 -1
- package/dist/hstore-YX726NKN.js +0 -13
- package/dist/hstore-YX726NKN.js.map +0 -1
- package/dist/http-exception-FZY2H4OF.js +0 -8
- package/dist/http-exception-FZY2H4OF.js.map +0 -1
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -1
- package/dist/intarray-NKVXNO2D.js +0 -13
- package/dist/intarray-NKVXNO2D.js.map +0 -1
- package/dist/isn-FTEMJGEV.js +0 -13
- package/dist/isn-FTEMJGEV.js.map +0 -1
- package/dist/lo-DB7L4NGI.js +0 -13
- package/dist/lo-DB7L4NGI.js.map +0 -1
- package/dist/logger-WQ7SHNDD.js +0 -68
- package/dist/logger-WQ7SHNDD.js.map +0 -1
- package/dist/ltree-Z32TZT6W.js +0 -13
- package/dist/ltree-Z32TZT6W.js.map +0 -1
- package/dist/nodefs-NM46ACH7.js +0 -31
- package/dist/nodefs-NM46ACH7.js.map +0 -1
- package/dist/opfs-ahp-NJO33LVZ.js +0 -332
- package/dist/opfs-ahp-NJO33LVZ.js.map +0 -1
- package/dist/pageinspect-YP3IZR4X.js +0 -13
- package/dist/pageinspect-YP3IZR4X.js.map +0 -1
- package/dist/pg_buffercache-7TD5J2FB.js +0 -13
- package/dist/pg_buffercache-7TD5J2FB.js.map +0 -1
- package/dist/pg_dump-SG4KYBUB.js +0 -2492
- package/dist/pg_dump-SG4KYBUB.js.map +0 -1
- package/dist/pg_freespacemap-DZDNCPZK.js +0 -13
- package/dist/pg_freespacemap-DZDNCPZK.js.map +0 -1
- package/dist/pg_surgery-J2MUEWEP.js +0 -13
- package/dist/pg_surgery-J2MUEWEP.js.map +0 -1
- package/dist/pg_trgm-7VNQOYS6.js +0 -13
- package/dist/pg_trgm-7VNQOYS6.js.map +0 -1
- package/dist/pg_visibility-TTSIPHFL.js +0 -13
- package/dist/pg_visibility-TTSIPHFL.js.map +0 -1
- package/dist/pg_walinspect-KPFHSHRJ.js +0 -13
- package/dist/pg_walinspect-KPFHSHRJ.js.map +0 -1
- package/dist/proxy-signals-GUDAMDHV.js +0 -39
- package/dist/proxy-signals-GUDAMDHV.js.map +0 -1
- package/dist/seg-IYVDLE4O.js +0 -13
- package/dist/seg-IYVDLE4O.js.map +0 -1
- package/dist/src/codecs/decoding.d.ts +0 -4
- package/dist/src/codecs/decoding.d.ts.map +0 -1
- package/dist/src/codecs/encoding.d.ts +0 -5
- package/dist/src/codecs/encoding.d.ts.map +0 -1
- package/dist/src/codecs/validation.d.ts +0 -6
- package/dist/src/codecs/validation.d.ts.map +0 -1
- package/dist/src/exports/index.d.ts +0 -11
- package/dist/src/exports/index.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lower-sql-plan.d.ts +0 -15
- package/dist/src/lower-sql-plan.d.ts.map +0 -1
- package/dist/src/sql-context.d.ts +0 -65
- package/dist/src/sql-context.d.ts.map +0 -1
- package/dist/src/sql-family-adapter.d.ts +0 -10
- package/dist/src/sql-family-adapter.d.ts.map +0 -1
- package/dist/src/sql-marker.d.ts +0 -22
- package/dist/src/sql-marker.d.ts.map +0 -1
- package/dist/src/sql-runtime.d.ts +0 -25
- package/dist/src/sql-runtime.d.ts.map +0 -1
- package/dist/tablefunc-EF4RCS7S.js +0 -13
- package/dist/tablefunc-EF4RCS7S.js.map +0 -1
- package/dist/tcn-3VT5BQYW.js +0 -13
- package/dist/tcn-3VT5BQYW.js.map +0 -1
- package/dist/test/utils.d.ts +0 -59
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -24634
- package/dist/test/utils.js.map +0 -1
- package/dist/tiny-CW6F4GX6.js +0 -10
- package/dist/tiny-CW6F4GX6.js.map +0 -1
- package/dist/tsm_system_rows-ES7KNUQH.js +0 -13
- package/dist/tsm_system_rows-ES7KNUQH.js.map +0 -1
- package/dist/tsm_system_time-76WEIMBG.js +0 -13
- package/dist/tsm_system_time-76WEIMBG.js.map +0 -1
- package/dist/unaccent-7RYF3R64.js +0 -13
- package/dist/unaccent-7RYF3R64.js.map +0 -1
- package/dist/utility-Q5A254LJ-J4HTKZPT.js +0 -347
- package/dist/utility-Q5A254LJ-J4HTKZPT.js.map +0 -1
- package/dist/uuid_ossp-4ETE4FPE.js +0 -13
- package/dist/uuid_ossp-4ETE4FPE.js.map +0 -1
- package/dist/vector-74GPNV7V.js +0 -13
- package/dist/vector-74GPNV7V.js.map +0 -1
- package/src/index.ts +0 -1
package/dist/dist-LBVX6BJW.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import "./chunk-7D4SUZUM.js";
|
|
2
|
-
|
|
3
|
-
// ../../../node_modules/.pnpm/@electric-sql+pglite-socket@0.0.19_@electric-sql+pglite@0.3.14/node_modules/@electric-sql/pglite-socket/dist/chunk-F6KLIXM7.js
|
|
4
|
-
import { createServer as u } from "net";
|
|
5
|
-
var g = 6e4;
|
|
6
|
-
var a = class a2 extends EventTarget {
|
|
7
|
-
constructor(e) {
|
|
8
|
-
super();
|
|
9
|
-
this.socket = null;
|
|
10
|
-
this.active = false;
|
|
11
|
-
this.db = e.db, this.closeOnDetach = e.closeOnDetach ?? false, this.inspect = e.inspect ?? false, this.debug = e.debug ?? false, this.id = a2.nextHandlerId++, this.log("constructor: created new handler");
|
|
12
|
-
}
|
|
13
|
-
get handlerId() {
|
|
14
|
-
return this.id;
|
|
15
|
-
}
|
|
16
|
-
log(e, ...t) {
|
|
17
|
-
this.debug && console.log(`[PGLiteSocketHandler#${this.id}] ${e}`, ...t);
|
|
18
|
-
}
|
|
19
|
-
async attach(e) {
|
|
20
|
-
if (this.log(`attach: attaching socket from ${e.remoteAddress}:${e.remotePort}`), this.socket) throw new Error("Socket already attached");
|
|
21
|
-
return this.socket = e, this.active = true, this.log("attach: waiting for PGlite to be ready"), await this.db.waitReady, this.log("attach: acquiring exclusive lock on PGlite instance"), await new Promise((t) => {
|
|
22
|
-
this.db.runExclusive(() => (t(), new Promise((i, n) => {
|
|
23
|
-
this.resolveLock = i, this.rejectLock = n;
|
|
24
|
-
})));
|
|
25
|
-
}), this.log("attach: setting up socket event handlers"), e.on("data", async (t) => {
|
|
26
|
-
try {
|
|
27
|
-
let i = await this.handleData(t);
|
|
28
|
-
this.log(`socket on data sent: ${i} bytes`);
|
|
29
|
-
} catch (i) {
|
|
30
|
-
this.log("socket on data error: ", i);
|
|
31
|
-
}
|
|
32
|
-
}), e.on("error", (t) => this.handleError(t)), e.on("close", () => this.handleClose()), this;
|
|
33
|
-
}
|
|
34
|
-
detach(e) {
|
|
35
|
-
return this.log(`detach: detaching socket, close=${e ?? this.closeOnDetach}`), this.socket ? (this.socket.removeAllListeners("data"), this.socket.removeAllListeners("error"), this.socket.removeAllListeners("close"), (e ?? this.closeOnDetach) && this.socket.writable && (this.log("detach: closing socket"), this.socket.end(), this.socket.destroy()), this.log("detach: releasing exclusive lock on PGlite instance"), this.resolveLock?.(), this.socket = null, this.active = false, this) : (this.log("detach: no socket attached, nothing to do"), this);
|
|
36
|
-
}
|
|
37
|
-
get isAttached() {
|
|
38
|
-
return this.socket !== null;
|
|
39
|
-
}
|
|
40
|
-
async handleData(e) {
|
|
41
|
-
if (!this.socket || !this.active) return this.log("handleData: no active socket, ignoring data"), new Promise((t, i) => i("no active socket"));
|
|
42
|
-
this.log(`handleData: received ${e.length} bytes`), this.inspectData("incoming", e);
|
|
43
|
-
try {
|
|
44
|
-
this.log("handleData: sending data to PGlite for processing");
|
|
45
|
-
let t = await this.db.execProtocolRaw(new Uint8Array(e));
|
|
46
|
-
if (this.log(`handleData: received ${t.length} bytes from PGlite`), this.inspectData("outgoing", t), this.socket && this.socket.writable && this.active) {
|
|
47
|
-
if (t.length <= 0) return this.log("handleData: cowardly refusing to send empty packet"), new Promise((n, o) => o("no data"));
|
|
48
|
-
let i = new Promise((n, o) => {
|
|
49
|
-
this.log("handleData: writing response to socket"), this.socket ? this.socket.write(Buffer.from(t), (r) => {
|
|
50
|
-
r ? o(`Error while writing to the socket ${r.toString()}`) : n(t.length);
|
|
51
|
-
}) : o("No socket");
|
|
52
|
-
});
|
|
53
|
-
return this.dispatchEvent(new CustomEvent("data", { detail: { incoming: e.length, outgoing: t.length } })), i;
|
|
54
|
-
} else return this.log("handleData: socket no longer writable or active, discarding response"), new Promise((i, n) => n("No socket, not active or not writeable"));
|
|
55
|
-
} catch (t) {
|
|
56
|
-
return this.log("handleData: error processing data:", t), this.handleError(t), new Promise((i, n) => n(`Error while processing data ${t.toString()}`));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
handleError(e) {
|
|
60
|
-
this.log("handleError:", e), this.dispatchEvent(new CustomEvent("error", { detail: e })), this.log("handleError: rejecting exclusive lock on PGlite instance"), this.rejectLock?.(e), this.resolveLock = void 0, this.rejectLock = void 0, this.detach(true);
|
|
61
|
-
}
|
|
62
|
-
handleClose() {
|
|
63
|
-
this.log("handleClose: socket closed"), this.dispatchEvent(new CustomEvent("close")), this.detach(false);
|
|
64
|
-
}
|
|
65
|
-
inspectData(e, t) {
|
|
66
|
-
if (this.inspect) {
|
|
67
|
-
console.log("-".repeat(75)), console.log(e === "incoming" ? "-> incoming" : "<- outgoing", t.length, "bytes");
|
|
68
|
-
for (let i = 0; i < t.length; i += 16) {
|
|
69
|
-
let n = Math.min(16, t.length - i), o = "";
|
|
70
|
-
for (let s = 0; s < 16; s++) if (s < n) {
|
|
71
|
-
let c = t[i + s];
|
|
72
|
-
o += c.toString(16).padStart(2, "0") + " ";
|
|
73
|
-
} else o += " ";
|
|
74
|
-
let r = "";
|
|
75
|
-
for (let s = 0; s < n; s++) {
|
|
76
|
-
let c = t[i + s];
|
|
77
|
-
r += c >= 32 && c <= 126 ? String.fromCharCode(c) : ".";
|
|
78
|
-
}
|
|
79
|
-
console.log(`${i.toString(16).padStart(8, "0")} ${o} ${r}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
a.nextHandlerId = 1;
|
|
85
|
-
var h = a;
|
|
86
|
-
var l = class extends EventTarget {
|
|
87
|
-
constructor(e) {
|
|
88
|
-
super();
|
|
89
|
-
this.server = null;
|
|
90
|
-
this.active = false;
|
|
91
|
-
this.activeHandler = null;
|
|
92
|
-
this.connectionQueue = [];
|
|
93
|
-
this.handlerCount = 0;
|
|
94
|
-
this.db = e.db, e.path ? this.path = e.path : (typeof e.port == "number" ? this.port = e.port ?? e.port : this.port = 5432, this.host = e.host || "127.0.0.1"), this.inspect = e.inspect ?? false, this.debug = e.debug ?? false, this.connectionQueueTimeout = e.connectionQueueTimeout ?? g, this.log(`constructor: created server on ${this.host}:${this.port}`), this.log(`constructor: connection queue timeout: ${this.connectionQueueTimeout}ms`);
|
|
95
|
-
}
|
|
96
|
-
log(e, ...t) {
|
|
97
|
-
this.debug && console.log(`[PGLiteSocketServer] ${e}`, ...t);
|
|
98
|
-
}
|
|
99
|
-
async start() {
|
|
100
|
-
if (this.log(`start: starting server on ${this.getServerConn()}`), this.server) throw new Error("Socket server already started");
|
|
101
|
-
return this.active = true, this.server = u((e) => this.handleConnection(e)), new Promise((e, t) => {
|
|
102
|
-
if (!this.server) return t(new Error("Server not initialized"));
|
|
103
|
-
if (this.server.on("error", (i) => {
|
|
104
|
-
this.log("start: server error:", i), this.dispatchEvent(new CustomEvent("error", { detail: i })), t(i);
|
|
105
|
-
}), this.path) this.server.listen(this.path, () => {
|
|
106
|
-
this.log(`start: server listening on ${this.getServerConn()}`), this.dispatchEvent(new CustomEvent("listening", { detail: { path: this.path } })), e();
|
|
107
|
-
});
|
|
108
|
-
else {
|
|
109
|
-
let i = this.server;
|
|
110
|
-
i.listen(this.port, this.host, () => {
|
|
111
|
-
let n = i.address();
|
|
112
|
-
if (n === null || typeof n != "object") throw Error("Expected address info");
|
|
113
|
-
this.port = n.port, this.log(`start: server listening on ${this.getServerConn()}`), this.dispatchEvent(new CustomEvent("listening", { detail: { port: this.port, host: this.host } })), e();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
getServerConn() {
|
|
119
|
-
return this.path ? this.path : `${this.host}:${this.port}`;
|
|
120
|
-
}
|
|
121
|
-
async stop() {
|
|
122
|
-
return this.log("stop: stopping server"), this.active = false, this.log(`stop: clearing connection queue (${this.connectionQueue.length} connections)`), this.connectionQueue.forEach((e) => {
|
|
123
|
-
clearTimeout(e.timeoutId), e.socket.writable && (this.log(`stop: closing queued connection from ${e.clientInfo.clientAddress}:${e.clientInfo.clientPort}`), e.socket.end());
|
|
124
|
-
}), this.connectionQueue = [], this.activeHandler && (this.log(`stop: detaching active handler #${this.activeHandlerId}`), this.activeHandler.detach(true), this.activeHandler = null), this.server ? new Promise((e) => {
|
|
125
|
-
if (!this.server) return e();
|
|
126
|
-
this.server.close(() => {
|
|
127
|
-
this.log("stop: server closed"), this.server = null, this.dispatchEvent(new CustomEvent("close")), e();
|
|
128
|
-
});
|
|
129
|
-
}) : (this.log("stop: server not running, nothing to do"), Promise.resolve());
|
|
130
|
-
}
|
|
131
|
-
get activeHandlerId() {
|
|
132
|
-
return this.activeHandler?.handlerId ?? null;
|
|
133
|
-
}
|
|
134
|
-
async handleConnection(e) {
|
|
135
|
-
let t = { clientAddress: e.remoteAddress || "unknown", clientPort: e.remotePort || 0 };
|
|
136
|
-
if (this.log(`handleConnection: new connection from ${t.clientAddress}:${t.clientPort}`), !this.active) {
|
|
137
|
-
this.log("handleConnection: server not active, closing connection"), e.end();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (!this.activeHandler || !this.activeHandler.isAttached) {
|
|
141
|
-
this.log("handleConnection: no active handler, attaching socket directly"), this.dispatchEvent(new CustomEvent("connection", { detail: t })), await this.attachSocketToNewHandler(e, t);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.log(`handleConnection: active handler #${this.activeHandlerId} exists, queueing connection`), this.enqueueConnection(e, t);
|
|
145
|
-
}
|
|
146
|
-
enqueueConnection(e, t) {
|
|
147
|
-
this.log(`enqueueConnection: queueing connection from ${t.clientAddress}:${t.clientPort}, timeout: ${this.connectionQueueTimeout}ms`);
|
|
148
|
-
let i = setTimeout(() => {
|
|
149
|
-
this.log(`enqueueConnection: timeout for connection from ${t.clientAddress}:${t.clientPort}`), this.connectionQueue = this.connectionQueue.filter((n) => n.socket !== e), e.writable && (this.log("enqueueConnection: closing timed out connection"), e.end()), this.dispatchEvent(new CustomEvent("queueTimeout", { detail: { ...t, queueSize: this.connectionQueue.length } }));
|
|
150
|
-
}, this.connectionQueueTimeout);
|
|
151
|
-
this.connectionQueue.push({ socket: e, clientInfo: t, timeoutId: i }), this.log(`enqueueConnection: connection queued, queue size: ${this.connectionQueue.length}`), this.dispatchEvent(new CustomEvent("queuedConnection", { detail: { ...t, queueSize: this.connectionQueue.length } }));
|
|
152
|
-
}
|
|
153
|
-
processNextInQueue() {
|
|
154
|
-
if (this.log(`processNextInQueue: processing next connection, queue size: ${this.connectionQueue.length}`), this.connectionQueue.length === 0 || !this.active) {
|
|
155
|
-
this.log("processNextInQueue: no connections in queue or server not active, nothing to do");
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
let e = this.connectionQueue.shift();
|
|
159
|
-
if (e) {
|
|
160
|
-
if (this.log(`processNextInQueue: processing connection from ${e.clientInfo.clientAddress}:${e.clientInfo.clientPort}`), clearTimeout(e.timeoutId), !e.socket.writable) {
|
|
161
|
-
this.log("processNextInQueue: socket no longer writable, skipping to next connection"), this.processNextInQueue();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
this.attachSocketToNewHandler(e.socket, e.clientInfo).catch((t) => {
|
|
165
|
-
this.log("processNextInQueue: error attaching socket:", t), this.dispatchEvent(new CustomEvent("error", { detail: t })), this.processNextInQueue();
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async attachSocketToNewHandler(e, t) {
|
|
170
|
-
this.handlerCount++, this.log(`attachSocketToNewHandler: creating new handler for ${t.clientAddress}:${t.clientPort} (handler #${this.handlerCount})`);
|
|
171
|
-
let i = new h({ db: this.db, closeOnDetach: true, inspect: this.inspect, debug: this.debug });
|
|
172
|
-
i.addEventListener("error", (n) => {
|
|
173
|
-
this.log(`handler #${i.handlerId}: error from handler:`, n.detail), this.dispatchEvent(new CustomEvent("error", { detail: n.detail }));
|
|
174
|
-
}), i.addEventListener("close", () => {
|
|
175
|
-
this.log(`handler #${i.handlerId}: closed`), this.activeHandler === i && (this.log(`handler #${i.handlerId}: was active handler, processing next connection in queue`), this.activeHandler = null, this.processNextInQueue());
|
|
176
|
-
});
|
|
177
|
-
try {
|
|
178
|
-
this.activeHandler = i, this.log(`handler #${i.handlerId}: attaching socket`), await i.attach(e), this.dispatchEvent(new CustomEvent("connection", { detail: t }));
|
|
179
|
-
} catch (n) {
|
|
180
|
-
throw this.log(`handler #${i.handlerId}: error attaching socket:`, n), this.activeHandler = null, e.writable && e.end(), n;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
export {
|
|
185
|
-
g as CONNECTION_QUEUE_TIMEOUT,
|
|
186
|
-
h as PGLiteSocketHandler,
|
|
187
|
-
l as PGLiteSocketServer
|
|
188
|
-
};
|
|
189
|
-
//# sourceMappingURL=dist-LBVX6BJW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../node_modules/.pnpm/@electric-sql+pglite-socket@0.0.19_@electric-sql+pglite@0.3.14/node_modules/@electric-sql/pglite-socket/src/index.ts"],"sourcesContent":["import type { PGlite } from '@electric-sql/pglite'\nimport { createServer, Server, Socket } from 'net'\n\n// Connection queue timeout in milliseconds\nexport const CONNECTION_QUEUE_TIMEOUT = 60000 // 60 seconds\n\n/**\n * Options for creating a PGLiteSocketHandler\n */\nexport interface PGLiteSocketHandlerOptions {\n /** The PGlite database instance */\n db: PGlite\n /** Whether to close the socket when detached (default: false) */\n closeOnDetach?: boolean\n /** Print the incoming and outgoing data to the console in hex and ascii */\n inspect?: boolean\n /** Enable debug logging of method calls */\n debug?: boolean\n}\n\n/**\n * Low-level handler for a single socket connection to PGLite\n * Handles the raw protocol communication between a socket and PGLite\n */\nexport class PGLiteSocketHandler extends EventTarget {\n readonly db: PGlite\n private socket: Socket | null = null\n private active = false\n private closeOnDetach: boolean\n private resolveLock?: () => void\n private rejectLock?: (err: Error) => void\n private inspect: boolean\n private debug: boolean\n private readonly id: number\n\n // Static counter for generating unique handler IDs\n private static nextHandlerId = 1\n\n /**\n * Create a new PGLiteSocketHandler\n * @param options Options for the handler\n */\n constructor(options: PGLiteSocketHandlerOptions) {\n super()\n this.db = options.db\n this.closeOnDetach = options.closeOnDetach ?? false\n this.inspect = options.inspect ?? false\n this.debug = options.debug ?? false\n this.id = PGLiteSocketHandler.nextHandlerId++\n\n this.log('constructor: created new handler')\n }\n\n /**\n * Get the unique ID of this handler\n */\n public get handlerId(): number {\n return this.id\n }\n\n /**\n * Log a message if debug is enabled\n * @private\n */\n private log(message: string, ...args: any[]): void {\n if (this.debug) {\n console.log(`[PGLiteSocketHandler#${this.id}] ${message}`, ...args)\n }\n }\n\n /**\n * Attach a socket to this handler\n * @param socket The socket to attach\n * @returns this handler instance\n * @throws Error if a socket is already attached\n */\n public async attach(socket: Socket): Promise<PGLiteSocketHandler> {\n this.log(\n `attach: attaching socket from ${socket.remoteAddress}:${socket.remotePort}`,\n )\n\n if (this.socket) {\n throw new Error('Socket already attached')\n }\n\n this.socket = socket\n this.active = true\n\n // Ensure the PGlite instance is ready\n this.log(`attach: waiting for PGlite to be ready`)\n await this.db.waitReady\n\n // Hold the lock on the PGlite instance\n this.log(`attach: acquiring exclusive lock on PGlite instance`)\n await new Promise<void>((resolve) => {\n this.db.runExclusive(() => {\n // Ensure we have the lock on the PGlite instance\n resolve()\n\n // Use a promise to hold the lock on the PGlite instance\n // this can be resolved or rejected by the handler to release the lock\n return new Promise<void>((resolveLock, rejectLock) => {\n this.resolveLock = resolveLock\n this.rejectLock = rejectLock\n })\n })\n })\n\n // Setup event handlers\n this.log(`attach: setting up socket event handlers`)\n socket.on('data', async (data) => {\n try {\n const result = await this.handleData(data)\n this.log(`socket on data sent: ${result} bytes`)\n } catch (err) {\n this.log('socket on data error: ', err)\n }\n })\n socket.on('error', (err) => this.handleError(err))\n socket.on('close', () => this.handleClose())\n\n return this\n }\n\n /**\n * Detach the current socket from this handler\n * @param close Whether to close the socket when detaching (overrides constructor option)\n * @returns this handler instance\n */\n public detach(close?: boolean): PGLiteSocketHandler {\n this.log(`detach: detaching socket, close=${close ?? this.closeOnDetach}`)\n\n if (!this.socket) {\n this.log(`detach: no socket attached, nothing to do`)\n return this\n }\n\n // Remove all listeners\n this.socket.removeAllListeners('data')\n this.socket.removeAllListeners('error')\n this.socket.removeAllListeners('close')\n\n // Close the socket if requested\n if (close ?? this.closeOnDetach) {\n if (this.socket.writable) {\n this.log(`detach: closing socket`)\n this.socket.end()\n this.socket.destroy()\n }\n }\n\n // Release the lock on the PGlite instance\n this.log(`detach: releasing exclusive lock on PGlite instance`)\n this.resolveLock?.()\n\n this.socket = null\n this.active = false\n return this\n }\n\n /**\n * Check if a socket is currently attached\n */\n public get isAttached(): boolean {\n return this.socket !== null\n }\n\n /**\n * Handle incoming data from the socket\n */\n private async handleData(data: Buffer): Promise<number> {\n if (!this.socket || !this.active) {\n this.log(`handleData: no active socket, ignoring data`)\n return new Promise((_, reject) => reject(`no active socket`))\n }\n\n this.log(`handleData: received ${data.length} bytes`)\n\n // Print the incoming data to the console\n this.inspectData('incoming', data)\n\n try {\n // Process the raw protocol data\n this.log(`handleData: sending data to PGlite for processing`)\n const result = await this.db.execProtocolRaw(new Uint8Array(data))\n\n this.log(`handleData: received ${result.length} bytes from PGlite`)\n\n // Print the outgoing data to the console\n this.inspectData('outgoing', result)\n\n // Send the result back if the socket is still connected\n if (this.socket && this.socket.writable && this.active) {\n if (result.length <= 0) {\n this.log(`handleData: cowardly refusing to send empty packet`)\n return new Promise((_, reject) => reject('no data'))\n }\n\n const promise = new Promise<number>((resolve, reject) => {\n this.log(`handleData: writing response to socket`)\n if (this.socket) {\n this.socket.write(Buffer.from(result), (err?: Error) => {\n if (err) {\n reject(`Error while writing to the socket ${err.toString()}`)\n } else {\n resolve(result.length)\n }\n })\n } else {\n reject(`No socket`)\n }\n })\n\n // Emit data event with byte sizes\n this.dispatchEvent(\n new CustomEvent('data', {\n detail: { incoming: data.length, outgoing: result.length },\n }),\n )\n return promise\n } else {\n this.log(\n `handleData: socket no longer writable or active, discarding response`,\n )\n return new Promise((_, reject) =>\n reject(`No socket, not active or not writeable`),\n )\n }\n } catch (err) {\n this.log(`handleData: error processing data:`, err)\n this.handleError(err as Error)\n return new Promise((_, reject) =>\n reject(`Error while processing data ${(err as Error).toString()}`),\n )\n }\n }\n\n /**\n * Handle errors from the socket\n */\n private handleError(err: Error): void {\n this.log(`handleError:`, err)\n\n // Emit error event\n this.dispatchEvent(new CustomEvent('error', { detail: err }))\n\n // Reject the lock on the PGlite instance\n this.log(`handleError: rejecting exclusive lock on PGlite instance`)\n this.rejectLock?.(err)\n this.resolveLock = undefined\n this.rejectLock = undefined\n\n // Close the connection on error\n this.detach(true)\n }\n\n /**\n * Handle socket close event\n */\n private handleClose(): void {\n this.log(`handleClose: socket closed`)\n\n this.dispatchEvent(new CustomEvent('close'))\n this.detach(false) // Already closed, just clean up\n }\n\n /**\n * Print data in hex and ascii to the console\n */\n private inspectData(\n direction: 'incoming' | 'outgoing',\n data: Buffer | Uint8Array,\n ): void {\n if (!this.inspect) return\n console.log('-'.repeat(75))\n if (direction === 'incoming') {\n console.log('-> incoming', data.length, 'bytes')\n } else {\n console.log('<- outgoing', data.length, 'bytes')\n }\n\n // Process 16 bytes per line\n for (let offset = 0; offset < data.length; offset += 16) {\n // Calculate current chunk size (may be less than 16 for the last chunk)\n const chunkSize = Math.min(16, data.length - offset)\n\n // Build the hex representation\n let hexPart = ''\n for (let i = 0; i < 16; i++) {\n if (i < chunkSize) {\n const byte = data[offset + i]\n hexPart += byte.toString(16).padStart(2, '0') + ' '\n } else {\n hexPart += ' ' // 3 spaces for missing bytes\n }\n }\n\n // Build the ASCII representation\n let asciiPart = ''\n for (let i = 0; i < chunkSize; i++) {\n const byte = data[offset + i]\n // Use printable characters (32-126), replace others with a dot\n asciiPart += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : '.'\n }\n\n // Print the line with offset in hex, hex values, and ASCII representation\n console.log(\n `${offset.toString(16).padStart(8, '0')} ${hexPart} ${asciiPart}`,\n )\n }\n }\n}\n\n/**\n * Represents a queued connection with timeout\n */\ninterface QueuedConnection {\n socket: Socket\n clientInfo: {\n clientAddress: string\n clientPort: number\n }\n timeoutId: NodeJS.Timeout\n}\n\n/**\n * Options for creating a PGLiteSocketServer\n */\nexport interface PGLiteSocketServerOptions {\n /** The PGlite database instance */\n db: PGlite\n /** The port to listen on (default: 5432) */\n port?: number\n /** The host to bind to (default: 127.0.0.1) */\n host?: string\n /** Unix socket path to bind to (default: undefined). If specified, takes precedence over host:port */\n path?: string\n /** Print the incoming and outgoing data to the console in hex and ascii */\n inspect?: boolean\n /** Connection queue timeout in milliseconds (default: 10000) */\n connectionQueueTimeout?: number\n /** Enable debug logging of method calls */\n debug?: boolean\n}\n\n/**\n * High-level server that manages socket connections to PGLite\n * Creates and manages a TCP server and handles client connections\n */\nexport class PGLiteSocketServer extends EventTarget {\n readonly db: PGlite\n private server: Server | null = null\n private port?: number\n private host?: string\n private path?: string\n private active = false\n private inspect: boolean\n private debug: boolean\n private connectionQueueTimeout: number\n private activeHandler: PGLiteSocketHandler | null = null\n private connectionQueue: QueuedConnection[] = []\n private handlerCount: number = 0\n\n /**\n * Create a new PGLiteSocketServer\n * @param options Options for the server\n */\n constructor(options: PGLiteSocketServerOptions) {\n super()\n this.db = options.db\n if (options.path) {\n this.path = options.path\n } else {\n if (typeof options.port === 'number') {\n // Keep port undefined on port 0, will be set by the OS when we start the server.\n this.port = options.port ?? options.port\n } else {\n this.port = 5432\n }\n this.host = options.host || '127.0.0.1'\n }\n this.inspect = options.inspect ?? false\n this.debug = options.debug ?? false\n this.connectionQueueTimeout =\n options.connectionQueueTimeout ?? CONNECTION_QUEUE_TIMEOUT\n\n this.log(`constructor: created server on ${this.host}:${this.port}`)\n this.log(\n `constructor: connection queue timeout: ${this.connectionQueueTimeout}ms`,\n )\n }\n\n /**\n * Log a message if debug is enabled\n * @private\n */\n private log(message: string, ...args: any[]): void {\n if (this.debug) {\n console.log(`[PGLiteSocketServer] ${message}`, ...args)\n }\n }\n\n /**\n * Start the socket server\n * @returns Promise that resolves when the server is listening\n */\n public async start(): Promise<void> {\n this.log(`start: starting server on ${this.getServerConn()}`)\n\n if (this.server) {\n throw new Error('Socket server already started')\n }\n\n this.active = true\n this.server = createServer((socket) => this.handleConnection(socket))\n\n return new Promise<void>((resolve, reject) => {\n if (!this.server) return reject(new Error('Server not initialized'))\n\n this.server.on('error', (err) => {\n this.log(`start: server error:`, err)\n this.dispatchEvent(new CustomEvent('error', { detail: err }))\n reject(err)\n })\n\n if (this.path) {\n this.server.listen(this.path, () => {\n this.log(`start: server listening on ${this.getServerConn()}`)\n this.dispatchEvent(\n new CustomEvent('listening', {\n detail: { path: this.path },\n }),\n )\n resolve()\n })\n } else {\n const server = this.server\n server.listen(this.port, this.host, () => {\n const address = server.address()\n // We are not using pipes, so return type should be AddressInfo\n if (address === null || typeof address !== 'object') {\n throw Error('Expected address info')\n }\n // Assign the new port number\n this.port = address.port\n this.log(`start: server listening on ${this.getServerConn()}`)\n this.dispatchEvent(\n new CustomEvent('listening', {\n detail: { port: this.port, host: this.host },\n }),\n )\n resolve()\n })\n }\n })\n }\n\n public getServerConn(): string {\n if (this.path) return this.path\n return `${this.host}:${this.port}`\n }\n\n /**\n * Stop the socket server\n * @returns Promise that resolves when the server is closed\n */\n public async stop(): Promise<void> {\n this.log(`stop: stopping server`)\n\n this.active = false\n\n // Clear connection queue\n this.log(\n `stop: clearing connection queue (${this.connectionQueue.length} connections)`,\n )\n\n this.connectionQueue.forEach((queuedConn) => {\n clearTimeout(queuedConn.timeoutId)\n if (queuedConn.socket.writable) {\n this.log(\n `stop: closing queued connection from ${queuedConn.clientInfo.clientAddress}:${queuedConn.clientInfo.clientPort}`,\n )\n queuedConn.socket.end()\n }\n })\n this.connectionQueue = []\n\n // Detach active handler if exists\n if (this.activeHandler) {\n this.log(`stop: detaching active handler #${this.activeHandlerId}`)\n this.activeHandler.detach(true)\n this.activeHandler = null\n }\n\n if (!this.server) {\n this.log(`stop: server not running, nothing to do`)\n return Promise.resolve()\n }\n\n return new Promise<void>((resolve) => {\n if (!this.server) return resolve()\n\n this.server.close(() => {\n this.log(`stop: server closed`)\n this.server = null\n this.dispatchEvent(new CustomEvent('close'))\n resolve()\n })\n })\n }\n\n /**\n * Get the active handler ID, or null if no active handler\n */\n private get activeHandlerId(): number | null {\n return this.activeHandler?.handlerId ?? null\n }\n\n /**\n * Handle a new client connection\n */\n private async handleConnection(socket: Socket): Promise<void> {\n const clientInfo = {\n clientAddress: socket.remoteAddress || 'unknown',\n clientPort: socket.remotePort || 0,\n }\n\n this.log(\n `handleConnection: new connection from ${clientInfo.clientAddress}:${clientInfo.clientPort}`,\n )\n\n // If server is not active, close the connection immediately\n if (!this.active) {\n this.log(`handleConnection: server not active, closing connection`)\n socket.end()\n return\n }\n\n // If we don't have an active handler or it's not attached, we can use this connection immediately\n if (!this.activeHandler || !this.activeHandler.isAttached) {\n this.log(`handleConnection: no active handler, attaching socket directly`)\n this.dispatchEvent(new CustomEvent('connection', { detail: clientInfo }))\n await this.attachSocketToNewHandler(socket, clientInfo)\n return\n }\n\n // Otherwise, queue the connection\n this.log(\n `handleConnection: active handler #${this.activeHandlerId} exists, queueing connection`,\n )\n this.enqueueConnection(socket, clientInfo)\n }\n\n /**\n * Add a connection to the queue\n */\n private enqueueConnection(\n socket: Socket,\n clientInfo: { clientAddress: string; clientPort: number },\n ): void {\n this.log(\n `enqueueConnection: queueing connection from ${clientInfo.clientAddress}:${clientInfo.clientPort}, timeout: ${this.connectionQueueTimeout}ms`,\n )\n\n // Set a timeout for this queued connection\n const timeoutId = setTimeout(() => {\n this.log(\n `enqueueConnection: timeout for connection from ${clientInfo.clientAddress}:${clientInfo.clientPort}`,\n )\n\n // Remove from queue\n this.connectionQueue = this.connectionQueue.filter(\n (queuedConn) => queuedConn.socket !== socket,\n )\n\n // End the connection if it's still open\n if (socket.writable) {\n this.log(`enqueueConnection: closing timed out connection`)\n socket.end()\n }\n\n this.dispatchEvent(\n new CustomEvent('queueTimeout', {\n detail: { ...clientInfo, queueSize: this.connectionQueue.length },\n }),\n )\n }, this.connectionQueueTimeout)\n\n // Add to queue\n this.connectionQueue.push({ socket, clientInfo, timeoutId })\n\n this.log(\n `enqueueConnection: connection queued, queue size: ${this.connectionQueue.length}`,\n )\n\n this.dispatchEvent(\n new CustomEvent('queuedConnection', {\n detail: { ...clientInfo, queueSize: this.connectionQueue.length },\n }),\n )\n }\n\n /**\n * Process the next connection in the queue\n */\n private processNextInQueue(): void {\n this.log(\n `processNextInQueue: processing next connection, queue size: ${this.connectionQueue.length}`,\n )\n\n // No connections in queue or server not active\n if (this.connectionQueue.length === 0 || !this.active) {\n this.log(\n `processNextInQueue: no connections in queue or server not active, nothing to do`,\n )\n return\n }\n\n // Get the next connection\n const nextConn = this.connectionQueue.shift()\n if (!nextConn) return\n\n this.log(\n `processNextInQueue: processing connection from ${nextConn.clientInfo.clientAddress}:${nextConn.clientInfo.clientPort}`,\n )\n\n // Clear the timeout\n clearTimeout(nextConn.timeoutId)\n\n // Check if the socket is still valid\n if (!nextConn.socket.writable) {\n this.log(\n `processNextInQueue: socket no longer writable, skipping to next connection`,\n )\n // Socket closed while waiting, process next in queue\n this.processNextInQueue()\n return\n }\n\n // Attach this socket to a new handler\n this.attachSocketToNewHandler(nextConn.socket, nextConn.clientInfo).catch(\n (err) => {\n this.log(`processNextInQueue: error attaching socket:`, err)\n this.dispatchEvent(new CustomEvent('error', { detail: err }))\n // Try the next connection\n this.processNextInQueue()\n },\n )\n }\n\n /**\n * Attach a socket to a new handler\n */\n private async attachSocketToNewHandler(\n socket: Socket,\n clientInfo: { clientAddress: string; clientPort: number },\n ): Promise<void> {\n this.handlerCount++\n\n this.log(\n `attachSocketToNewHandler: creating new handler for ${clientInfo.clientAddress}:${clientInfo.clientPort} (handler #${this.handlerCount})`,\n )\n\n // Create a new handler for this connection\n const handler = new PGLiteSocketHandler({\n db: this.db,\n closeOnDetach: true,\n inspect: this.inspect,\n debug: this.debug,\n })\n\n // Forward error events from the handler\n handler.addEventListener('error', (event) => {\n this.log(\n `handler #${handler.handlerId}: error from handler:`,\n (event as CustomEvent<Error>).detail,\n )\n this.dispatchEvent(\n new CustomEvent('error', {\n detail: (event as CustomEvent<Error>).detail,\n }),\n )\n })\n\n // Handle close event to process next queued connection\n handler.addEventListener('close', () => {\n this.log(`handler #${handler.handlerId}: closed`)\n\n // If this is our active handler, clear it\n if (this.activeHandler === handler) {\n this.log(\n `handler #${handler.handlerId}: was active handler, processing next connection in queue`,\n )\n this.activeHandler = null\n // Process next connection in queue\n this.processNextInQueue()\n }\n })\n\n try {\n // Set as active handler\n this.activeHandler = handler\n\n this.log(`handler #${handler.handlerId}: attaching socket`)\n\n // Attach the socket to the handler\n await handler.attach(socket)\n\n this.dispatchEvent(new CustomEvent('connection', { detail: clientInfo }))\n } catch (err) {\n // If there was an error attaching, clean up\n this.log(`handler #${handler.handlerId}: error attaching socket:`, err)\n this.activeHandler = null\n if (socket.writable) {\n socket.end()\n }\n throw err\n }\n }\n}\n"],"mappings":";;;AACA,SAAS,gBAAAA,SAAoC;AAGtC,IAAMC,IAA2B;AAAjC,IAoBMC,IAAN,MAAMA,WAA4B,YAAY;EAkBnD,YAAYC,GAAqC;AAC/C,UAAM;AAjBR,SAAQ,SAAwB;AAChC,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K,IAAI,+CAA+CA,CAAG,GAC3D,KAAK,cAAc,IAAI,YAAY,SAAS,EAAE,QAAQA,EAAI,CAAC,CAAC,GAE5D,KAAK,mBAAmB;MAC1B,CACF;IAAA;EACF;EAKA,MAAc,yBACZN,GACAuB,GACe;AACf,SAAK,gBAEL,KAAK,IACH,sDAAsDA,EAAW,aAAa,IAAIA,EAAW,UAAU,cAAc,KAAK,YAAY,GACxI;AAGA,QAAMG,IAAU,IAAIR,EAAoB,EACtC,IAAI,KAAK,IACT,eAAe,MACf,SAAS,KAAK,SACd,OAAO,KAAK,MACd,CAAC;AAGDQ,MAAQ,iBAAiB,SAAUC,OAAU;AAC3C,WAAK,IACH,YAAYD,EAAQ,SAAS,yBAC5BC,EAA6B,MAChC,GACA,KAAK,cACH,IAAI,YAAY,SAAS,EACvB,QAASA,EAA6B,OACxC,CAAC,CACH;IACF,CAAC,GAGDD,EAAQ,iBAAiB,SAAS,MAAM;AACtC,WAAK,IAAI,YAAYA,EAAQ,SAAS,UAAU,GAG5C,KAAK,kBAAkBA,MACzB,KAAK,IACH,YAAYA,EAAQ,SAAS,2DAC/B,GACA,KAAK,gBAAgB,MAErB,KAAK,mBAAmB;IAE5B,CAAC;AAED,QAAI;AAEF,WAAK,gBAAgBA,GAErB,KAAK,IAAI,YAAYA,EAAQ,SAAS,oBAAoB,GAG1D,MAAMA,EAAQ,OAAO1B,CAAM,GAE3B,KAAK,cAAc,IAAI,YAAY,cAAc,EAAE,QAAQuB,EAAW,CAAC,CAAC;IAC1E,SAASjB,GAAK;AAEZ,YAAA,KAAK,IAAI,YAAYoB,EAAQ,SAAS,6BAA6BpB,CAAG,GACtE,KAAK,gBAAgB,MACjBN,EAAO,YACTA,EAAO,IAAI,GAEPM;IACR;EACF;AACF;","names":["createServer","CONNECTION_QUEUE_TIMEOUT","_PGLiteSocketHandler","options","message","args","socket","resolve","resolveLock","rejectLock","data","result","err","close","_","reject","promise","direction","offset","chunkSize","hexPart","i","byte","asciiPart","PGLiteSocketHandler","PGLiteSocketServer","server","address","queuedConn","clientInfo","timeoutId","nextConn","handler","event"]}
|