lightning-pool 4.13.0 → 4.14.2
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 +6 -293
- package/abort-error.d.ts +11 -0
- package/abort-error.js +11 -0
- package/constants.d.ts +12 -0
- package/constants.js +12 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/package.json +9 -3
- package/pool-options.d.ts +72 -0
- package/pool-options.js +81 -3
- package/pool-request.d.ts +15 -0
- package/pool-request.js +17 -0
- package/pool.d.ts +125 -10
- package/pool.js +156 -19
- package/resource-item.d.ts +10 -0
- package/resource-item.js +10 -0
- package/types.d.ts +124 -0
- package/CHANGELOG.md +0 -436
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
High performance resource pool written with TypeScript.
|
|
11
11
|
|
|
12
|
-
-
|
|
12
|
+
- A fast Resource Pool implementation for JavaScript - see [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for the numbers against [generic-pool](https://github.com/coopernurse/node-pool), or [benchmark/README.md](benchmark/README.md) to reproduce them yourself
|
|
13
13
|
- Advanced configuration options, suits for enterprise level applications
|
|
14
14
|
- Configuration can be changed while pool running
|
|
15
15
|
- Promise based factory supported
|
|
@@ -65,7 +65,7 @@ const client = await pool.acquire();
|
|
|
65
65
|
// Use resource
|
|
66
66
|
await client.query("select * from foo");
|
|
67
67
|
// return object back to pool
|
|
68
|
-
await pool.
|
|
68
|
+
await pool.releaseAsync(client);
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Step 4 - Shutdown pool (optional)
|
|
@@ -78,299 +78,12 @@ await pool.close(5000);
|
|
|
78
78
|
|
|
79
79
|
## Documentation
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
lightning-pool module exports createPool() method and Pool class. Both can be used to instantiate a Pool.
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import {createPool} from 'lightning-pool';
|
|
87
|
-
const pool = createPool(factory, options);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import {Pool} from 'lightning-pool';
|
|
92
|
-
const pool = new Pool(factory, options);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### factory
|
|
96
|
-
|
|
97
|
-
Can be any object/instance with the following properties:
|
|
98
|
-
|
|
99
|
-
- `create` : The function that the `Pool` will call when it needs a new resource. It should return a `Promise<resouce>`.
|
|
100
|
-
- `destroy` : The function that the `Pool` will call when it wants to destroy a `resource`. It should accept first argument as `resource`, where `resource` is whatever factory.create made. It should return a `Promise<>`.
|
|
101
|
-
- `reset` (optional) : The function that the `Pool` will call before any `resource` back to the `Pool`. It should accept first argument as `resource`, where `resource` is whatever factory.create made. It should return a `Promise<>`. `Pool` will destroy and remove the resource from the `Pool` on any error.
|
|
102
|
-
- `validate` (optional) : The function that the `Pool` will call when any resource needs to be validated. It should accept first argument as `resource`, where `resource` is whatever factory.create made. It should return a `Promise<>`. `Pool` will destroy and remove the resource from the `Pool` on any error.
|
|
103
|
-
|
|
104
|
-
#### options
|
|
105
|
-
- `acquireMaxRetries`: Maximum number that `Pool` will try to create a resource before returning the error. (Default 0)
|
|
106
|
-
- `acquireRetryWait`: Time in millis that `Pool` will wait after each tries. (Default 2000)
|
|
107
|
-
- `acquireTimeoutMillis`: Time in millis an acquire call will wait for a resource before timing out. (Default 0 - no limit)
|
|
108
|
-
- `fifo`: If true resources will be allocated first-in-first-out order. resources will be allocated last-in-first-out order. (Default true)
|
|
109
|
-
- `idleTimeoutMillis`: The minimum amount of time in millis that an `resource` may sit idle in the `Pool`. (Default 30000)
|
|
110
|
-
- `houseKeepInterval`: Time period in millis that `Pool` will make a cleanup. (Default 1000)
|
|
111
|
-
- `min`: Minimum number of resources that `Pool` will keep. (Default 0)
|
|
112
|
-
- `minIdle`: Minimum number of resources that `Pool` will keep in idle state. (Default 0)
|
|
113
|
-
- `max`: Maximum number of resources that `Pool` will create. (Default 10)
|
|
114
|
-
- `maxQueue`: Maximum number of request that `Pool` will accept. (Default 1000)
|
|
115
|
-
- `resetOnReturn`: If true `Pool` will call `reset()` function of factory before moving it idle state. (Default true)
|
|
116
|
-
- `validation`: If true `Pool` will call `validation()` function of factory when it needs it. If false, `validation()` never been called. (Default true)
|
|
117
|
-
|
|
118
|
-
### Methods
|
|
119
|
-
|
|
120
|
-
#### Pool.prototype.acquire()
|
|
121
|
-
|
|
122
|
-
Acquires a `resource` from the `Pool` or create a new one.
|
|
123
|
-
|
|
124
|
-
##### Usage
|
|
125
|
-
|
|
126
|
-
`pool.acquire(): Promise<any>`
|
|
127
|
-
|
|
128
|
-
`pool.acquire(factoryCreateOptions: any): Promise<any>`
|
|
129
|
-
|
|
130
|
-
`pool.acquire(callback:Callback): Promise<any>`
|
|
131
|
-
|
|
132
|
-
`pool.acquire(factoryCreateOptions?: any, callback:Callback): Promise<any>`
|
|
133
|
-
|
|
134
|
-
- *Returns*: A Promise
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
var promise = pool.acquire();
|
|
139
|
-
promise.then(resource => {
|
|
140
|
-
// Do what ever you want with resource
|
|
141
|
-
}).catch(err =>{
|
|
142
|
-
// Handle Error
|
|
143
|
-
});
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
#### Pool.prototype.isAcquired()
|
|
147
|
-
|
|
148
|
-
Returns if a resource has been acquired from the `Pool` and not yet released or destroyed.
|
|
149
|
-
|
|
150
|
-
##### Usage
|
|
151
|
-
|
|
152
|
-
`pool.isAcquired(resource)`
|
|
153
|
-
|
|
154
|
-
- `resource`: A previously acquired resource
|
|
155
|
-
- *Returns*: True if the resource is acquired, else False
|
|
156
|
-
|
|
157
|
-
```js
|
|
158
|
-
if (pool.isAcquired(resource)) {
|
|
159
|
-
// Do any thing
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
#### Pool.prototype.includes()
|
|
166
|
-
|
|
167
|
-
Returns if the `Pool` contains a resource
|
|
168
|
-
|
|
169
|
-
##### Usage
|
|
170
|
-
|
|
171
|
-
`pool.includes(resource)`
|
|
172
|
-
|
|
173
|
-
- `resource`: A resource object
|
|
174
|
-
- *Returns*: True if the resource is in the `Pool`, else False
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
if (pool.includes(resource)) {
|
|
178
|
-
// Do any thing
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
#### Pool.prototype.release()
|
|
185
|
-
|
|
186
|
-
Releases an allocated `resource` and let it back to pool.
|
|
187
|
-
|
|
188
|
-
##### Usage
|
|
189
|
-
|
|
190
|
-
`pool.release(resource)`
|
|
191
|
-
|
|
192
|
-
- `resource`: A previously acquired resource
|
|
193
|
-
- *Returns*: undefined
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
pool.release(resource);
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
#### Pool.prototype.destroy()
|
|
203
|
-
|
|
204
|
-
Releases, destroys and removes any `resource` from `Pool`.
|
|
205
|
-
|
|
206
|
-
##### Usage
|
|
207
|
-
|
|
208
|
-
`pool.destroy(resource)`
|
|
209
|
-
|
|
210
|
-
- `resource`: A previously acquired resource
|
|
211
|
-
- *Returns*: undefined
|
|
212
|
-
|
|
213
|
-
```js
|
|
214
|
-
pool.destroy(resource);
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
#### Pool.prototype.start()
|
|
221
|
-
|
|
222
|
-
Starts the `Pool` and begins creating of resources, starts house keeping and any other internal logic.
|
|
223
|
-
|
|
224
|
-
*Note: This method is not need to be called. `Pool` instance will automatically be started when acquire() method is called*
|
|
225
|
-
|
|
226
|
-
##### Usage
|
|
227
|
-
|
|
228
|
-
`pool.start()`
|
|
229
|
-
|
|
230
|
-
- *Returns*: undefined
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
```js
|
|
234
|
-
pool.start();
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
#### Pool.prototype.close()
|
|
240
|
-
|
|
241
|
-
Shuts down the `Pool` and destroys all resources.
|
|
242
|
-
|
|
243
|
-
##### Usage
|
|
244
|
-
|
|
245
|
-
`close(callback: Callback): void;`
|
|
246
|
-
`close(terminateWait: number, callback?: Callback): Promise<void>;`
|
|
247
|
-
`close(force: boolean, callback?: Callback): void;`
|
|
248
|
-
|
|
249
|
-
- `force`: If true, `Pool` will immediately destroy resources instead of waiting to be released
|
|
250
|
-
- `terminateWait`: If specified, `Pool` will wait for active resources to release
|
|
251
|
-
- `callback`: If specified, callback will be called after close. If not specified a promise returns.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
```js
|
|
255
|
-
var promise = pool.close();
|
|
256
|
-
promise.then(() => {
|
|
257
|
-
console.log('Pool has been shut down')
|
|
258
|
-
}).catch(err => {
|
|
259
|
-
console.error(err);
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### Properties
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
- `acquired` (Number): Returns number of acquired resources.
|
|
267
|
-
- `available` (Number): Returns number of idle resources.
|
|
268
|
-
- `creating` (Number): Returns number of resources currently been created.
|
|
269
|
-
- `pending` (Number): Returns number of acquire request waits in the `Pool` queue.
|
|
270
|
-
- `size` (Number): Returns number of total resources.
|
|
271
|
-
- `state` (PoolState): Returns current state of the `Pool`.
|
|
272
|
-
- `options` (PoolOptions): Returns object instance that holds configuration properties
|
|
273
|
-
- `acquireMaxRetries` (Get/Set): Maximum number that `Pool` will try to create a resource before returning the error. (Default 0)
|
|
274
|
-
- `acquireRetryWait` (Get/Set): Time in millis that `Pool` will wait after each tries. (Default 2000)
|
|
275
|
-
- `acquireTimeoutMillis` (Get/Set): Time in millis an acquire call will wait for a resource before timing out. (Default 0 - no limit)
|
|
276
|
-
- `fifo` (Get/Set): If true resources will be allocated first-in-first-out order. resources will be allocated last-in-first-out order. (Default true)
|
|
277
|
-
- `idleTimeoutMillis` (Get/Set): The minimum amount of time in millis that an `resource` may sit idle in the `Pool`. (Default 30000)
|
|
278
|
-
- `houseKeepInterval` (Get/Set): Time period in millis that `Pool` will make a cleanup. (Default 1000)
|
|
279
|
-
- `min` (Get/Set): Minimum number of resources that `Pool` will keep. (Default 0)
|
|
280
|
-
- `minIdle` (Get/Set): Minimum number of resources that `Pool` will keep in idle state. (Default 0)
|
|
281
|
-
- `max` (Get/Set): Maximum number of resources that `Pool` will create. (Default 10)
|
|
282
|
-
- `maxQueue` (Get/Set): Maximum number of request that `Pool` will acceps. (Default 1000)
|
|
283
|
-
- `resetOnReturn` (Get/Set): If true `Pool` will call `reset()` function of factory before moving it idle state. (Default true)
|
|
284
|
-
- `validation` (Get/Set): If true `Pool` will call `validation()` function of factory when it needs it. If false, `validation()` never been called. (Default true)
|
|
285
|
-
|
|
286
|
-
### Events
|
|
287
|
-
|
|
288
|
-
Pool derives from EventEmitter and produce the following events:
|
|
289
|
-
|
|
290
|
-
- `acquire`: Emitted when a resource acquired.
|
|
291
|
-
|
|
292
|
-
```js
|
|
293
|
-
pool.on('acquire', function(resource){
|
|
294
|
-
//....
|
|
295
|
-
})
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
- `create`: Emitted when a new resource is added to the `Pool`.
|
|
299
|
-
```js
|
|
300
|
-
pool.on('create', function(resource){
|
|
301
|
-
//....
|
|
302
|
-
})
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
- `create-error`: Emitted when a factory.create informs any error.
|
|
306
|
-
```js
|
|
307
|
-
pool.on('create-error', function(error){
|
|
308
|
-
//Log stuff maybe
|
|
309
|
-
})
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
- `destroy`: Emitted when a resource is destroyed and removed from the `Pool`.
|
|
313
|
-
- `destroy-error`: Emitted when a factory.destroy informs any error.
|
|
314
|
-
```js
|
|
315
|
-
pool.on('destroy-error', function(error, resource){
|
|
316
|
-
//Log stuff maybe
|
|
317
|
-
})
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
- `return`: Emitted when an acquired resource returns to the `Pool`.
|
|
321
|
-
```js
|
|
322
|
-
pool.on('start', function(resource){
|
|
323
|
-
//...
|
|
324
|
-
})
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
- `start`: Emitted when the `Pool` started.
|
|
329
|
-
```js
|
|
330
|
-
pool.on('start', function(){
|
|
331
|
-
//...
|
|
332
|
-
})
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
- `closing`: Emitted when before closing the `Pool`.
|
|
336
|
-
```js
|
|
337
|
-
pool.on('closing', function(){
|
|
338
|
-
//...
|
|
339
|
-
})
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
- `close`: Emitted when after closing the `Pool`.
|
|
344
|
-
```js
|
|
345
|
-
pool.on('close', function(){
|
|
346
|
-
//...
|
|
347
|
-
})
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
- `validate-error`: Emitted when a factory.validate informs any error.
|
|
351
|
-
```js
|
|
352
|
-
pool.on('validate-error', function(error, resource){
|
|
353
|
-
//Log stuff maybe
|
|
354
|
-
})
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
## PoolState enum
|
|
358
|
-
|
|
359
|
-
Pool.PoolState (Number):
|
|
360
|
-
|
|
361
|
-
- IDLE: 0, // Pool has not been started
|
|
362
|
-
|
|
363
|
-
- STARTED: 1, // Pool has been started
|
|
364
|
-
|
|
365
|
-
- CLOSING: 2, // Pool shutdown in progress
|
|
366
|
-
|
|
367
|
-
- CLOSED: 3 // Pool has been shut down
|
|
368
|
-
|
|
369
|
-
|
|
81
|
+
See [docs/API.md](docs/API.md) for the full API reference - factory/options shape, every method and property,
|
|
82
|
+
emitted events, and the `PoolState`/`ResourceState` enums.
|
|
370
83
|
|
|
371
84
|
## Node Compatibility
|
|
372
85
|
|
|
373
|
-
- node `>=
|
|
86
|
+
- node `>= 22.0`;
|
|
374
87
|
|
|
375
88
|
### License
|
|
376
89
|
[MIT](LICENSE)
|
|
@@ -379,7 +92,7 @@ Pool.PoolState (Number):
|
|
|
379
92
|
[npm-url]: https://npmjs.org/package/lightning-pool
|
|
380
93
|
[ci-test-image]: https://github.com/panates/lightning-pool/actions/workflows/test.yml/badge.svg
|
|
381
94
|
[ci-test-url]: https://github.com/panates/lightning-pool/actions/workflows/test.yml
|
|
382
|
-
[coveralls-image]: https://img.shields.io/coveralls/panates/lightning-pool/
|
|
95
|
+
[coveralls-image]: https://img.shields.io/coveralls/panates/lightning-pool/dev.svg
|
|
383
96
|
[coveralls-url]: https://coveralls.io/r/panates/lightning-pool
|
|
384
97
|
[downloads-image]: https://img.shields.io/npm/dm/lightning-pool.svg
|
|
385
98
|
[downloads-url]: https://npmjs.org/package/lightning-pool
|
package/abort-error.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw (or reject with) this from `PoolFactory.create()` to abort resource
|
|
3
|
+
* creation immediately instead of retrying.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Normally, when `create()` fails, the `Pool` retries up to
|
|
6
|
+
* `PoolConfiguration.acquireMaxRetries` times (waiting `acquireRetryWait`
|
|
7
|
+
* between attempts) before failing the pending `acquire()`. An `AbortError`
|
|
8
|
+
* skips that retry loop entirely and fails the `acquire()` right away -
|
|
9
|
+
* useful for errors that retrying can never fix (e.g. invalid
|
|
10
|
+
* credentials), as opposed to transient ones (e.g. a connection timeout).
|
|
11
|
+
*/
|
|
1
12
|
export declare class AbortError extends Error {
|
|
2
13
|
}
|
package/abort-error.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw (or reject with) this from `PoolFactory.create()` to abort resource
|
|
3
|
+
* creation immediately instead of retrying.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Normally, when `create()` fails, the `Pool` retries up to
|
|
6
|
+
* `PoolConfiguration.acquireMaxRetries` times (waiting `acquireRetryWait`
|
|
7
|
+
* between attempts) before failing the pending `acquire()`. An `AbortError`
|
|
8
|
+
* skips that retry loop entirely and fails the `acquire()` right away -
|
|
9
|
+
* useful for errors that retrying can never fix (e.g. invalid
|
|
10
|
+
* credentials), as opposed to transient ones (e.g. a connection timeout).
|
|
11
|
+
*/
|
|
1
12
|
export class AbortError extends Error {
|
|
2
13
|
}
|
package/constants.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/** Lifecycle state of a `Pool`, exposed as `pool.state`. */
|
|
1
2
|
export declare enum PoolState {
|
|
3
|
+
/** The `Pool` has not been started yet. */
|
|
2
4
|
IDLE = 0,
|
|
5
|
+
/** The `Pool` is running. */
|
|
3
6
|
STARTED = 1,
|
|
7
|
+
/** Shutdown is in progress (`close()`/`closeAsync()` was called). */
|
|
4
8
|
CLOSING = 2,
|
|
9
|
+
/** The `Pool` has fully shut down. Calling `start()` again brings it back to `STARTED`. */
|
|
5
10
|
CLOSED = 3
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* State of an individual pooled resource. Internal bookkeeping, but exposed
|
|
14
|
+
* (mostly useful when inspecting events or writing tests).
|
|
15
|
+
*/
|
|
7
16
|
export declare enum ResourceState {
|
|
17
|
+
/** The resource is idle and available for `acquire()`. */
|
|
8
18
|
IDLE = 0,
|
|
19
|
+
/** The resource is currently acquired by a caller. */
|
|
9
20
|
ACQUIRED = 1,
|
|
21
|
+
/** The resource is being validated (see `PoolConfiguration.validation`) before being handed out. */
|
|
10
22
|
VALIDATION = 2
|
|
11
23
|
}
|
package/constants.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
/** Lifecycle state of a `Pool`, exposed as `pool.state`. */
|
|
1
2
|
export var PoolState;
|
|
2
3
|
(function (PoolState) {
|
|
4
|
+
/** The `Pool` has not been started yet. */
|
|
3
5
|
PoolState[PoolState["IDLE"] = 0] = "IDLE";
|
|
6
|
+
/** The `Pool` is running. */
|
|
4
7
|
PoolState[PoolState["STARTED"] = 1] = "STARTED";
|
|
8
|
+
/** Shutdown is in progress (`close()`/`closeAsync()` was called). */
|
|
5
9
|
PoolState[PoolState["CLOSING"] = 2] = "CLOSING";
|
|
10
|
+
/** The `Pool` has fully shut down. Calling `start()` again brings it back to `STARTED`. */
|
|
6
11
|
PoolState[PoolState["CLOSED"] = 3] = "CLOSED";
|
|
7
12
|
})(PoolState || (PoolState = {}));
|
|
13
|
+
/**
|
|
14
|
+
* State of an individual pooled resource. Internal bookkeeping, but exposed
|
|
15
|
+
* (mostly useful when inspecting events or writing tests).
|
|
16
|
+
*/
|
|
8
17
|
export var ResourceState;
|
|
9
18
|
(function (ResourceState) {
|
|
19
|
+
/** The resource is idle and available for `acquire()`. */
|
|
10
20
|
ResourceState[ResourceState["IDLE"] = 0] = "IDLE";
|
|
21
|
+
/** The resource is currently acquired by a caller. */
|
|
11
22
|
ResourceState[ResourceState["ACQUIRED"] = 1] = "ACQUIRED";
|
|
23
|
+
/** The resource is being validated (see `PoolConfiguration.validation`) before being handed out. */
|
|
12
24
|
ResourceState[ResourceState["VALIDATION"] = 2] = "VALIDATION";
|
|
13
25
|
})(ResourceState || (ResourceState = {}));
|
package/index.d.ts
CHANGED
|
@@ -4,4 +4,12 @@ export * from './abort-error.js';
|
|
|
4
4
|
export * from './constants.js';
|
|
5
5
|
export * from './pool.js';
|
|
6
6
|
export * from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new `Pool`. Equivalent to `new Pool(factory, config)` - a
|
|
9
|
+
* convenience so callers don't need to import the `Pool` class directly.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - The resource type this pool manages.
|
|
12
|
+
* @param factory - Creates, destroys, and (optionally) resets/validates resources.
|
|
13
|
+
* @param config - Initial options; every option can also be changed later via `pool.options`.
|
|
14
|
+
*/
|
|
7
15
|
export declare function createPool<T = any>(factory: PoolFactory<T>, config?: PoolConfiguration): Pool<T>;
|
package/index.js
CHANGED
|
@@ -3,6 +3,14 @@ export * from './abort-error.js';
|
|
|
3
3
|
export * from './constants.js';
|
|
4
4
|
export * from './pool.js';
|
|
5
5
|
export * from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new `Pool`. Equivalent to `new Pool(factory, config)` - a
|
|
8
|
+
* convenience so callers don't need to import the `Pool` class directly.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam T - The resource type this pool manages.
|
|
11
|
+
* @param factory - Creates, destroys, and (optionally) resets/validates resources.
|
|
12
|
+
* @param config - Initial options; every option can also be changed later via `pool.options`.
|
|
13
|
+
*/
|
|
6
14
|
export function createPool(factory, config) {
|
|
7
15
|
return new Pool(factory, config);
|
|
8
16
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightning-pool",
|
|
3
3
|
"description": "Fastest generic Pool written with TypeScript",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.14.2",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"doublylinked": "^2.5.6",
|
|
9
9
|
"putil-promisify": "^1.10.1",
|
|
10
|
-
"tslib": "^2.
|
|
10
|
+
"tslib": "^2.9.1"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"module": "./index.js",
|
|
@@ -19,12 +19,18 @@
|
|
|
19
19
|
},
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
24
27
|
"url": "git+https://github.com/panates/lightning-pool.git"
|
|
25
28
|
},
|
|
26
29
|
"contributors": [
|
|
27
|
-
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
30
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
31
|
+
"Ilker Gurelli <i.gurelli@panates.com>",
|
|
32
|
+
"Onur Tokel <o.tokel@panates.com>",
|
|
33
|
+
"Bircan Yuruk <b.yuruk@panates.com>"
|
|
28
34
|
],
|
|
29
35
|
"keywords": [
|
|
30
36
|
"pool",
|
package/pool-options.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import type { Pool } from './pool.js';
|
|
3
3
|
import type { PoolConfiguration } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Live, mutable configuration for a `Pool`, exposed as `pool.options`. Every
|
|
6
|
+
* property is a get/set pair - assigning one takes effect immediately (e.g.
|
|
7
|
+
* `pool.options.max = 20`) and emits a `'change'` event that `Pool` reacts
|
|
8
|
+
* to (adjusting the housekeeper interval, topping up `min`/`minIdle`, etc.).
|
|
9
|
+
* See `PoolConfiguration` for what each option means; the defaults are the
|
|
10
|
+
* same for both.
|
|
11
|
+
*/
|
|
4
12
|
export declare class PoolOptions extends EventEmitter {
|
|
5
13
|
readonly pool: Pool;
|
|
6
14
|
private _acquireMaxRetries;
|
|
@@ -15,27 +23,91 @@ export declare class PoolOptions extends EventEmitter {
|
|
|
15
23
|
private _maxQueue;
|
|
16
24
|
private _validation;
|
|
17
25
|
constructor(pool: Pool);
|
|
26
|
+
/** @defaultValue `0` - fail on the first error, no retries. */
|
|
18
27
|
get acquireMaxRetries(): number;
|
|
28
|
+
/** Negative values reset to the default instead of being applied. */
|
|
19
29
|
set acquireMaxRetries(val: number);
|
|
30
|
+
/** @defaultValue `2000` (milliseconds) */
|
|
20
31
|
get acquireRetryWait(): number;
|
|
32
|
+
/** Negative values reset to the default instead of being applied. */
|
|
21
33
|
set acquireRetryWait(val: number);
|
|
34
|
+
/** @defaultValue `0` (milliseconds) - no timeout. */
|
|
22
35
|
get acquireTimeoutMillis(): number;
|
|
36
|
+
/** Negative values reset to the default instead of being applied. */
|
|
23
37
|
set acquireTimeoutMillis(val: number);
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, idle resources are handed out first-in-first-out; if
|
|
40
|
+
* `false`, last-in-first-out.
|
|
41
|
+
*
|
|
42
|
+
* @defaultValue `true`
|
|
43
|
+
*/
|
|
24
44
|
get fifo(): boolean;
|
|
25
45
|
set fifo(val: boolean);
|
|
46
|
+
/** @defaultValue `30000` (milliseconds) */
|
|
26
47
|
get idleTimeoutMillis(): number;
|
|
48
|
+
/** Negative values reset to the default instead of being applied. */
|
|
27
49
|
set idleTimeoutMillis(val: number);
|
|
50
|
+
/** @defaultValue `1000` (milliseconds) */
|
|
28
51
|
get houseKeepInterval(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Negative values reset to the default instead of being applied.
|
|
54
|
+
*
|
|
55
|
+
* @remarks Setting this restarts the housekeeper timer on the running
|
|
56
|
+
* `Pool` with the new interval.
|
|
57
|
+
*/
|
|
29
58
|
set houseKeepInterval(val: number);
|
|
59
|
+
/** @defaultValue `0` */
|
|
30
60
|
get min(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Negative values reset to the default instead of being applied.
|
|
63
|
+
*
|
|
64
|
+
* @remarks Raising this above the current `max` also raises `max` to
|
|
65
|
+
* match, since `min` can never exceed `max`. On a running `Pool`, raising
|
|
66
|
+
* `min` triggers creating resources to satisfy the new minimum.
|
|
67
|
+
*/
|
|
31
68
|
set min(val: number);
|
|
69
|
+
/** @defaultValue `0` */
|
|
32
70
|
get minIdle(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Negative values reset to the default instead of being applied.
|
|
73
|
+
*
|
|
74
|
+
* @remarks On a running `Pool`, raising this triggers creating resources
|
|
75
|
+
* to satisfy the new minimum idle count.
|
|
76
|
+
*/
|
|
33
77
|
set minIdle(val: number);
|
|
78
|
+
/** @defaultValue `10` */
|
|
34
79
|
get max(): number;
|
|
80
|
+
/**
|
|
81
|
+
* Negative values reset to the default instead of being applied; `0` or
|
|
82
|
+
* below the current `min` is clamped up to at least `1`/`min`.
|
|
83
|
+
*
|
|
84
|
+
* @remarks Lowering this below the current `min` also lowers `min` to
|
|
85
|
+
* match, since `min` can never exceed `max`.
|
|
86
|
+
*/
|
|
35
87
|
set max(val: number);
|
|
88
|
+
/** @defaultValue `1000` */
|
|
36
89
|
get maxQueue(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Negative values reset to the default instead of being applied;
|
|
92
|
+
* otherwise clamped up to at least `1`.
|
|
93
|
+
*/
|
|
37
94
|
set maxQueue(val: number);
|
|
95
|
+
/**
|
|
96
|
+
* If `true`, a resource is validated via `factory.validate()` before
|
|
97
|
+
* being handed out (when the factory provides one).
|
|
98
|
+
*
|
|
99
|
+
* @defaultValue `true`
|
|
100
|
+
*/
|
|
38
101
|
get validation(): boolean;
|
|
39
102
|
set validation(val: boolean);
|
|
103
|
+
/**
|
|
104
|
+
* Copies every recognized option from `values` onto this instance,
|
|
105
|
+
* emitting a `'change'` event per option (same as assigning each
|
|
106
|
+
* individually). Unknown keys are silently ignored.
|
|
107
|
+
*
|
|
108
|
+
* @param values - A plain `PoolConfiguration` object, or another
|
|
109
|
+
* `PoolOptions` instance to copy settings from (e.g. to clone one pool's
|
|
110
|
+
* configuration onto another).
|
|
111
|
+
*/
|
|
40
112
|
assign(values: PoolConfiguration | PoolOptions): void;
|
|
41
113
|
}
|