@zvndev/powdb-client 0.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 +309 -0
- package/dist/errors.d.ts +44 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/escape.d.ts +55 -0
- package/dist/escape.d.ts.map +1 -0
- package/dist/escape.js +124 -0
- package/dist/escape.js.map +1 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +515 -0
- package/dist/index.js.map +1 -0
- package/dist/pool.d.ts +124 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +315 -0
- package/dist/pool.js.map +1 -0
- package/dist/protocol.d.ts +59 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +188 -0
- package/dist/protocol.js.map +1 -0
- package/dist/typed.d.ts +50 -0
- package/dist/typed.d.ts.map +1 -0
- package/dist/typed.js +101 -0
- package/dist/typed.js.map +1 -0
- package/package.json +42 -0
- package/src/errors.ts +54 -0
- package/src/escape.ts +141 -0
- package/src/index.ts +652 -0
- package/src/pool.ts +375 -0
- package/src/protocol.ts +218 -0
- package/src/typed.ts +148 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAgB,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,GAGX,MAAM,YAAY,CAAC;AAEpB,yEAAyE;AACzE,MAAM,CAAC,MAAM,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
* // manual acquire/release
|
|
7
|
+
* const c = await pool.acquire();
|
|
8
|
+
* try {
|
|
9
|
+
* await c.query("...");
|
|
10
|
+
* pool.release(c);
|
|
11
|
+
* } catch (err) {
|
|
12
|
+
* // a broken client should NOT be returned to the pool
|
|
13
|
+
* pool.destroy(c);
|
|
14
|
+
* throw err;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* // ...or, preferred, use the scoped helper:
|
|
18
|
+
* const users = await pool.withClient((c) => c.query("Users"));
|
|
19
|
+
*
|
|
20
|
+
* await pool.close();
|
|
21
|
+
*/
|
|
22
|
+
import { Client, type ClientOptions } from "./index.js";
|
|
23
|
+
export interface PoolOptions extends ClientOptions {
|
|
24
|
+
/** Maximum concurrent clients. Default 10. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/** Acquire timeout in ms. Default 30_000. */
|
|
27
|
+
acquireTimeoutMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* How many times to retry `Client.connect` on transient errors
|
|
30
|
+
* (connect_failed / timeout). Auth failures and other non-transient
|
|
31
|
+
* errors are never retried. Default 3. Set to 0 to disable.
|
|
32
|
+
*/
|
|
33
|
+
connectRetries?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Initial backoff (ms) between connect retries. Each subsequent retry
|
|
36
|
+
* doubles the delay up to `connectMaxBackoffMs`. Default 100.
|
|
37
|
+
*/
|
|
38
|
+
connectBackoffMs?: number;
|
|
39
|
+
/** Maximum backoff (ms) between connect retries. Default 2_000. */
|
|
40
|
+
connectMaxBackoffMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Lazy, FIFO connection pool.
|
|
44
|
+
*
|
|
45
|
+
* Semantics:
|
|
46
|
+
* - `acquire` returns an idle client if one exists; otherwise creates a new
|
|
47
|
+
* one up to `max`; otherwise waits until `release`/`destroy` frees a slot
|
|
48
|
+
* (subject to `acquireTimeoutMs`).
|
|
49
|
+
* - `release(c)` puts `c` back in the idle queue unconditionally. **If the
|
|
50
|
+
* caller observed a socket/connection error on `c`, they MUST call
|
|
51
|
+
* `destroy(c)` instead** — the pool cannot safely detect dead sockets.
|
|
52
|
+
* - `destroy(c)` closes `c` and decrements the live count, freeing a slot
|
|
53
|
+
* for a new client to be created.
|
|
54
|
+
* - `withClient(fn)` acquires, runs `fn`, and always destroys on error or
|
|
55
|
+
* releases on success. This is the safe default for most call sites.
|
|
56
|
+
* - `close()` rejects any pending waiters and awaits `close()` on every
|
|
57
|
+
* idle client. Subsequent calls to `acquire` reject immediately.
|
|
58
|
+
*/
|
|
59
|
+
export declare class Pool {
|
|
60
|
+
private readonly opts;
|
|
61
|
+
private readonly max;
|
|
62
|
+
private readonly acquireTimeoutMs;
|
|
63
|
+
private readonly connectRetries;
|
|
64
|
+
private readonly connectBackoffMs;
|
|
65
|
+
private readonly connectMaxBackoffMs;
|
|
66
|
+
private readonly idleClients;
|
|
67
|
+
private readonly waiters;
|
|
68
|
+
/** Clients owned by this pool (idle + checked-out). Used to reject
|
|
69
|
+
* foreign/double-destroyed clients from corrupting the slot accounting. */
|
|
70
|
+
private readonly owned;
|
|
71
|
+
private live;
|
|
72
|
+
private _closed;
|
|
73
|
+
constructor(opts: PoolOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Wraps Client.connect with the pool's configured retry policy. Used by
|
|
76
|
+
* `acquire` and `drainWaiters`.
|
|
77
|
+
*/
|
|
78
|
+
private connect;
|
|
79
|
+
/** Live client count (idle + checked out). */
|
|
80
|
+
get size(): number;
|
|
81
|
+
/** Clients currently sitting in the idle queue. */
|
|
82
|
+
get idle(): number;
|
|
83
|
+
/** `true` once {@link close} has been called. */
|
|
84
|
+
get closed(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Acquire a client from the pool.
|
|
87
|
+
*
|
|
88
|
+
* Resolves with an idle client if one is available, creates a new one if
|
|
89
|
+
* `live < max`, or waits in a FIFO queue. Rejects if `acquireTimeoutMs`
|
|
90
|
+
* elapses, or if the pool is closed.
|
|
91
|
+
*/
|
|
92
|
+
acquire(): Promise<Client>;
|
|
93
|
+
/**
|
|
94
|
+
* Return `c` to the idle queue so subsequent `acquire` calls can hand it
|
|
95
|
+
* out. If the pool is closed, `c` is closed instead.
|
|
96
|
+
*
|
|
97
|
+
* **Do not call this if `c` has experienced a connection error** — use
|
|
98
|
+
* {@link destroy} for that case.
|
|
99
|
+
*/
|
|
100
|
+
release(c: Client): void;
|
|
101
|
+
/**
|
|
102
|
+
* Close `c` and free its slot so a new client can be created on the next
|
|
103
|
+
* `acquire`. Use this when `c` has hit a socket error or is otherwise
|
|
104
|
+
* known-bad.
|
|
105
|
+
*/
|
|
106
|
+
destroy(c: Client): void;
|
|
107
|
+
/**
|
|
108
|
+
* Acquire a client, run `fn`, and either release (on success) or destroy
|
|
109
|
+
* (on error). This is the recommended call site — it makes it impossible
|
|
110
|
+
* to leak a client on an unhandled exception.
|
|
111
|
+
*/
|
|
112
|
+
withClient<T>(fn: (c: Client) => Promise<T>): Promise<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Close the pool. Rejects all pending waiters, awaits `close()` on every
|
|
115
|
+
* idle client, and marks the pool closed. Subsequent `acquire` calls
|
|
116
|
+
* reject immediately.
|
|
117
|
+
*
|
|
118
|
+
* Checked-out clients are NOT tracked — callers that still hold one when
|
|
119
|
+
* `close()` is called are responsible for closing it themselves.
|
|
120
|
+
*/
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
private drainWaiters;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAGxD,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,8CAA8C;IAC9C,GAAG,CAAC,EAAE,MAAM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CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAY9D;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,OAAO,CAAC,YAAY;CA+BrB"}
|
package/dist/pool.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tiny connection pool for the PowDB TypeScript client.
|
|
3
|
+
*
|
|
4
|
+
* const pool = new Pool({ host, port, max: 8 });
|
|
5
|
+
*
|
|
6
|
+
* // manual acquire/release
|
|
7
|
+
* const c = await pool.acquire();
|
|
8
|
+
* try {
|
|
9
|
+
* await c.query("...");
|
|
10
|
+
* pool.release(c);
|
|
11
|
+
* } catch (err) {
|
|
12
|
+
* // a broken client should NOT be returned to the pool
|
|
13
|
+
* pool.destroy(c);
|
|
14
|
+
* throw err;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* // ...or, preferred, use the scoped helper:
|
|
18
|
+
* const users = await pool.withClient((c) => c.query("Users"));
|
|
19
|
+
*
|
|
20
|
+
* await pool.close();
|
|
21
|
+
*/
|
|
22
|
+
import { Client } from "./index.js";
|
|
23
|
+
import { isPowDBError } from "./errors.js";
|
|
24
|
+
/**
|
|
25
|
+
* Is this error worth retrying? Only the transient connect-phase errors
|
|
26
|
+
* are retryable. Auth failures, size violations, aborts, and protocol
|
|
27
|
+
* errors are not — retrying would just fail the same way.
|
|
28
|
+
*/
|
|
29
|
+
function isRetryable(err) {
|
|
30
|
+
if (!isPowDBError(err)) {
|
|
31
|
+
// Raw socket errors surface as generic Error before we wrap them in
|
|
32
|
+
// connect_failed. In practice connect() wraps them, but be defensive.
|
|
33
|
+
return err instanceof Error;
|
|
34
|
+
}
|
|
35
|
+
return err.code === "connect_failed" || err.code === "timeout";
|
|
36
|
+
}
|
|
37
|
+
function sleep(ms) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const t = setTimeout(resolve, ms);
|
|
40
|
+
if (typeof t.unref === "function")
|
|
41
|
+
t.unref();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Connect to the server with bounded retry + exponential backoff. Throws
|
|
46
|
+
* the last error if every attempt fails, or the first error unchanged if
|
|
47
|
+
* it was not retryable.
|
|
48
|
+
*/
|
|
49
|
+
async function connectWithRetry(opts, retries, initialBackoffMs, maxBackoffMs) {
|
|
50
|
+
let lastErr;
|
|
51
|
+
let delay = initialBackoffMs;
|
|
52
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
53
|
+
try {
|
|
54
|
+
return await Client.connect(opts);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
lastErr = err;
|
|
58
|
+
if (!isRetryable(err) || attempt === retries)
|
|
59
|
+
break;
|
|
60
|
+
await sleep(delay);
|
|
61
|
+
delay = Math.min(delay * 2, maxBackoffMs);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw lastErr;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Lazy, FIFO connection pool.
|
|
68
|
+
*
|
|
69
|
+
* Semantics:
|
|
70
|
+
* - `acquire` returns an idle client if one exists; otherwise creates a new
|
|
71
|
+
* one up to `max`; otherwise waits until `release`/`destroy` frees a slot
|
|
72
|
+
* (subject to `acquireTimeoutMs`).
|
|
73
|
+
* - `release(c)` puts `c` back in the idle queue unconditionally. **If the
|
|
74
|
+
* caller observed a socket/connection error on `c`, they MUST call
|
|
75
|
+
* `destroy(c)` instead** — the pool cannot safely detect dead sockets.
|
|
76
|
+
* - `destroy(c)` closes `c` and decrements the live count, freeing a slot
|
|
77
|
+
* for a new client to be created.
|
|
78
|
+
* - `withClient(fn)` acquires, runs `fn`, and always destroys on error or
|
|
79
|
+
* releases on success. This is the safe default for most call sites.
|
|
80
|
+
* - `close()` rejects any pending waiters and awaits `close()` on every
|
|
81
|
+
* idle client. Subsequent calls to `acquire` reject immediately.
|
|
82
|
+
*/
|
|
83
|
+
export class Pool {
|
|
84
|
+
opts;
|
|
85
|
+
max;
|
|
86
|
+
acquireTimeoutMs;
|
|
87
|
+
connectRetries;
|
|
88
|
+
connectBackoffMs;
|
|
89
|
+
connectMaxBackoffMs;
|
|
90
|
+
idleClients = [];
|
|
91
|
+
waiters = [];
|
|
92
|
+
/** Clients owned by this pool (idle + checked-out). Used to reject
|
|
93
|
+
* foreign/double-destroyed clients from corrupting the slot accounting. */
|
|
94
|
+
owned = new Set();
|
|
95
|
+
live = 0;
|
|
96
|
+
_closed = false;
|
|
97
|
+
constructor(opts) {
|
|
98
|
+
const { max = 10, acquireTimeoutMs = 30_000, connectRetries = 3, connectBackoffMs = 100, connectMaxBackoffMs = 2_000, ...clientOpts } = opts;
|
|
99
|
+
if (!Number.isFinite(max) || max < 1) {
|
|
100
|
+
throw new TypeError(`Pool: max must be a positive integer, got ${max}`);
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isFinite(acquireTimeoutMs) || acquireTimeoutMs < 0) {
|
|
103
|
+
throw new TypeError(`Pool: acquireTimeoutMs must be a non-negative number, got ${acquireTimeoutMs}`);
|
|
104
|
+
}
|
|
105
|
+
if (!Number.isFinite(connectRetries) || connectRetries < 0) {
|
|
106
|
+
throw new TypeError(`Pool: connectRetries must be a non-negative integer, got ${connectRetries}`);
|
|
107
|
+
}
|
|
108
|
+
this.opts = clientOpts;
|
|
109
|
+
this.max = max;
|
|
110
|
+
this.acquireTimeoutMs = acquireTimeoutMs;
|
|
111
|
+
this.connectRetries = connectRetries;
|
|
112
|
+
this.connectBackoffMs = connectBackoffMs;
|
|
113
|
+
this.connectMaxBackoffMs = connectMaxBackoffMs;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Wraps Client.connect with the pool's configured retry policy. Used by
|
|
117
|
+
* `acquire` and `drainWaiters`.
|
|
118
|
+
*/
|
|
119
|
+
connect() {
|
|
120
|
+
return connectWithRetry(this.opts, this.connectRetries, this.connectBackoffMs, this.connectMaxBackoffMs);
|
|
121
|
+
}
|
|
122
|
+
/** Live client count (idle + checked out). */
|
|
123
|
+
get size() {
|
|
124
|
+
return this.live;
|
|
125
|
+
}
|
|
126
|
+
/** Clients currently sitting in the idle queue. */
|
|
127
|
+
get idle() {
|
|
128
|
+
return this.idleClients.length;
|
|
129
|
+
}
|
|
130
|
+
/** `true` once {@link close} has been called. */
|
|
131
|
+
get closed() {
|
|
132
|
+
return this._closed;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Acquire a client from the pool.
|
|
136
|
+
*
|
|
137
|
+
* Resolves with an idle client if one is available, creates a new one if
|
|
138
|
+
* `live < max`, or waits in a FIFO queue. Rejects if `acquireTimeoutMs`
|
|
139
|
+
* elapses, or if the pool is closed.
|
|
140
|
+
*/
|
|
141
|
+
async acquire() {
|
|
142
|
+
if (this._closed) {
|
|
143
|
+
throw new Error("pool closed");
|
|
144
|
+
}
|
|
145
|
+
const existing = this.idleClients.shift();
|
|
146
|
+
if (existing !== undefined) {
|
|
147
|
+
return existing;
|
|
148
|
+
}
|
|
149
|
+
if (this.live < this.max) {
|
|
150
|
+
this.live++;
|
|
151
|
+
try {
|
|
152
|
+
const c = await this.connect();
|
|
153
|
+
this.owned.add(c);
|
|
154
|
+
return c;
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
// Creation failed — we never had a live client, so give the slot
|
|
158
|
+
// back and propagate.
|
|
159
|
+
this.live--;
|
|
160
|
+
// A newly-freed slot may let a pending waiter try again... but only
|
|
161
|
+
// via a future release/destroy. To be fair to waiters, schedule a
|
|
162
|
+
// drain here.
|
|
163
|
+
this.drainWaiters();
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
const waiter = {
|
|
169
|
+
resolve,
|
|
170
|
+
reject,
|
|
171
|
+
timer: null,
|
|
172
|
+
};
|
|
173
|
+
if (this.acquireTimeoutMs > 0) {
|
|
174
|
+
waiter.timer = setTimeout(() => {
|
|
175
|
+
const idx = this.waiters.indexOf(waiter);
|
|
176
|
+
if (idx !== -1)
|
|
177
|
+
this.waiters.splice(idx, 1);
|
|
178
|
+
reject(new Error("pool acquire timeout"));
|
|
179
|
+
}, this.acquireTimeoutMs);
|
|
180
|
+
// Don't keep the event loop alive just for the timeout.
|
|
181
|
+
if (typeof waiter.timer.unref === "function")
|
|
182
|
+
waiter.timer.unref();
|
|
183
|
+
}
|
|
184
|
+
this.waiters.push(waiter);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Return `c` to the idle queue so subsequent `acquire` calls can hand it
|
|
189
|
+
* out. If the pool is closed, `c` is closed instead.
|
|
190
|
+
*
|
|
191
|
+
* **Do not call this if `c` has experienced a connection error** — use
|
|
192
|
+
* {@link destroy} for that case.
|
|
193
|
+
*/
|
|
194
|
+
release(c) {
|
|
195
|
+
if (!this.owned.has(c)) {
|
|
196
|
+
// Foreign client or already-destroyed — refuse to touch accounting.
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this._closed) {
|
|
200
|
+
// Pool is gone — just close the client, fire-and-forget.
|
|
201
|
+
this.owned.delete(c);
|
|
202
|
+
if (this.live > 0)
|
|
203
|
+
this.live--;
|
|
204
|
+
void c.close().catch(() => { });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const waiter = this.waiters.shift();
|
|
208
|
+
if (waiter !== undefined) {
|
|
209
|
+
if (waiter.timer !== null)
|
|
210
|
+
clearTimeout(waiter.timer);
|
|
211
|
+
waiter.resolve(c);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.idleClients.push(c);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Close `c` and free its slot so a new client can be created on the next
|
|
218
|
+
* `acquire`. Use this when `c` has hit a socket error or is otherwise
|
|
219
|
+
* known-bad.
|
|
220
|
+
*/
|
|
221
|
+
destroy(c) {
|
|
222
|
+
if (!this.owned.has(c)) {
|
|
223
|
+
// Foreign client or already destroyed — don't touch slot accounting.
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
this.owned.delete(c);
|
|
227
|
+
// Decrement first so any waiter we hand off to can create a fresh one.
|
|
228
|
+
if (this.live > 0)
|
|
229
|
+
this.live--;
|
|
230
|
+
void c.close().catch(() => { });
|
|
231
|
+
if (this._closed)
|
|
232
|
+
return;
|
|
233
|
+
// Drain one waiter if possible — the freed slot lets them create a new
|
|
234
|
+
// connection.
|
|
235
|
+
this.drainWaiters();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Acquire a client, run `fn`, and either release (on success) or destroy
|
|
239
|
+
* (on error). This is the recommended call site — it makes it impossible
|
|
240
|
+
* to leak a client on an unhandled exception.
|
|
241
|
+
*/
|
|
242
|
+
async withClient(fn) {
|
|
243
|
+
const c = await this.acquire();
|
|
244
|
+
try {
|
|
245
|
+
const out = await fn(c);
|
|
246
|
+
this.release(c);
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
this.destroy(c);
|
|
251
|
+
throw err;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Close the pool. Rejects all pending waiters, awaits `close()` on every
|
|
256
|
+
* idle client, and marks the pool closed. Subsequent `acquire` calls
|
|
257
|
+
* reject immediately.
|
|
258
|
+
*
|
|
259
|
+
* Checked-out clients are NOT tracked — callers that still hold one when
|
|
260
|
+
* `close()` is called are responsible for closing it themselves.
|
|
261
|
+
*/
|
|
262
|
+
async close() {
|
|
263
|
+
if (this._closed)
|
|
264
|
+
return;
|
|
265
|
+
this._closed = true;
|
|
266
|
+
// Reject every pending waiter.
|
|
267
|
+
while (this.waiters.length > 0) {
|
|
268
|
+
const w = this.waiters.shift();
|
|
269
|
+
if (w.timer !== null)
|
|
270
|
+
clearTimeout(w.timer);
|
|
271
|
+
w.reject(new Error("pool closed"));
|
|
272
|
+
}
|
|
273
|
+
// Close every idle client.
|
|
274
|
+
const idle = this.idleClients.splice(0, this.idleClients.length);
|
|
275
|
+
for (const c of idle)
|
|
276
|
+
this.owned.delete(c);
|
|
277
|
+
this.live -= idle.length;
|
|
278
|
+
await Promise.all(idle.map((c) => c.close().catch(() => { })));
|
|
279
|
+
}
|
|
280
|
+
// ──────────────────────────────────────────────────────────
|
|
281
|
+
// internals
|
|
282
|
+
// ──────────────────────────────────────────────────────────
|
|
283
|
+
drainWaiters() {
|
|
284
|
+
// If we have headroom AND a waiter, try to create a client for them.
|
|
285
|
+
// (Handles the "acquire failed → slot freed" path cleanly without
|
|
286
|
+
// forcing the caller to re-poll.)
|
|
287
|
+
if (this._closed)
|
|
288
|
+
return;
|
|
289
|
+
while (this.waiters.length > 0 && this.live < this.max) {
|
|
290
|
+
const waiter = this.waiters.shift();
|
|
291
|
+
if (waiter.timer !== null)
|
|
292
|
+
clearTimeout(waiter.timer);
|
|
293
|
+
this.live++;
|
|
294
|
+
this.connect().then((c) => {
|
|
295
|
+
// Pool may have been closed while the connect was in flight.
|
|
296
|
+
// If so, close the freshly-opened client instead of handing it
|
|
297
|
+
// to a waiter that's already been rejected.
|
|
298
|
+
if (this._closed) {
|
|
299
|
+
if (this.live > 0)
|
|
300
|
+
this.live--;
|
|
301
|
+
void c.close().catch(() => { });
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
this.owned.add(c);
|
|
305
|
+
waiter.resolve(c);
|
|
306
|
+
}, (err) => {
|
|
307
|
+
this.live--;
|
|
308
|
+
waiter.reject(err);
|
|
309
|
+
// Keep trying for the next waiter, if any.
|
|
310
|
+
this.drainWaiters();
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["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flags(1)][len(4 LE)][payload]
|
|
5
|
+
* Strings are encoded as [len(4 LE)][utf-8 bytes].
|
|
6
|
+
*
|
|
7
|
+
* This mirrors crates/server/src/protocol.rs — keep them in sync.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MSG_CONNECT = 1;
|
|
10
|
+
export declare const MSG_CONNECT_OK = 2;
|
|
11
|
+
export declare const MSG_QUERY = 3;
|
|
12
|
+
export declare const MSG_RESULT_ROWS = 7;
|
|
13
|
+
export declare const MSG_RESULT_SCALAR = 8;
|
|
14
|
+
export declare const MSG_RESULT_OK = 9;
|
|
15
|
+
export declare const MSG_ERROR = 10;
|
|
16
|
+
export declare const MSG_DISCONNECT = 16;
|
|
17
|
+
/** Maximum payload size accepted from the wire (64 MB). */
|
|
18
|
+
export declare const MAX_PAYLOAD_SIZE: number;
|
|
19
|
+
/** Maximum number of rows allowed in a single result message. */
|
|
20
|
+
export declare const MAX_ROWS = 10000000;
|
|
21
|
+
/** Maximum number of columns allowed in a result set. */
|
|
22
|
+
export declare const MAX_COLUMNS = 4096;
|
|
23
|
+
export type Message = {
|
|
24
|
+
type: "Connect";
|
|
25
|
+
dbName: string;
|
|
26
|
+
password: string | null;
|
|
27
|
+
} | {
|
|
28
|
+
type: "ConnectOk";
|
|
29
|
+
version: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "Query";
|
|
32
|
+
query: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "ResultRows";
|
|
35
|
+
columns: string[];
|
|
36
|
+
rows: string[][];
|
|
37
|
+
} | {
|
|
38
|
+
type: "ResultScalar";
|
|
39
|
+
value: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "ResultOk";
|
|
42
|
+
affected: bigint;
|
|
43
|
+
} | {
|
|
44
|
+
type: "Error";
|
|
45
|
+
message: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "Disconnect";
|
|
48
|
+
};
|
|
49
|
+
export declare function encode(msg: Message): Buffer;
|
|
50
|
+
/**
|
|
51
|
+
* Attempts to parse a single frame from the start of `buf`. Returns the parsed
|
|
52
|
+
* message and the number of bytes consumed, or `null` if the buffer does not
|
|
53
|
+
* yet contain a complete frame.
|
|
54
|
+
*/
|
|
55
|
+
export declare function tryDecode(buf: Buffer): {
|
|
56
|
+
msg: Message;
|
|
57
|
+
consumed: number;
|
|
58
|
+
} | null;
|
|
59
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,cAAc,IAAO,CAAC;AACnC,eAAO,MAAM,SAAS,IAAO,CAAC;AAC9B,eAAO,MAAM,eAAe,IAAO,CAAC;AACpC,eAAO,MAAM,iBAAiB,IAAO,CAAC;AACtC,eAAO,MAAM,aAAa,IAAO,CAAC;AAClC,eAAO,MAAM,SAAS,KAAO,CAAC;AAC9B,eAAO,MAAM,cAAc,KAAO,CAAC;AAInC,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB,QAAmB,CAAC;AAEjD,iEAAiE;AACjE,eAAO,MAAM,QAAQ,WAAa,CAAC;AAEnC,yDAAyD;AACzD,eAAO,MAAM,WAAW,OAAO,CAAC;AAEhC,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;CAAE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