lightning-pool 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/{AbortError.js → abort-error.js} +0 -0
- package/cjs/index.js +4 -4
- package/cjs/{PoolOptions.js → pool-options.js} +0 -0
- package/cjs/{PoolRequest.js → pool-request.js} +0 -0
- package/cjs/{Pool.js → pool.js} +9 -9
- package/cjs/{ResourceItem.js → resource-item.js} +0 -0
- package/esm/{AbortError.d.ts → abort-error.d.ts} +0 -0
- package/esm/{AbortError.js → abort-error.js} +0 -0
- package/esm/index.d.ts +3 -3
- package/esm/index.js +3 -3
- package/esm/{PoolOptions.d.ts → pool-options.d.ts} +1 -1
- package/esm/{PoolOptions.js → pool-options.js} +0 -0
- package/esm/{PoolRequest.d.ts → pool-request.d.ts} +1 -1
- package/esm/{PoolRequest.js → pool-request.js} +0 -0
- package/esm/{Pool.d.ts → pool.d.ts} +2 -2
- package/esm/{Pool.js → pool.js} +4 -4
- package/esm/{ResourceItem.d.ts → resource-item.d.ts} +0 -0
- package/esm/{ResourceItem.js → resource-item.js} +0 -0
- package/package.json +15 -14
|
File without changes
|
package/cjs/index.js
CHANGED
|
@@ -15,11 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createPool = void 0;
|
|
18
|
-
const
|
|
18
|
+
const pool_js_1 = require("./pool.js");
|
|
19
19
|
__exportStar(require("./definitions.js"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./pool.js"), exports);
|
|
21
|
+
__exportStar(require("./abort-error.js"), exports);
|
|
22
22
|
function createPool(factory, config) {
|
|
23
|
-
return new
|
|
23
|
+
return new pool_js_1.Pool(factory, config);
|
|
24
24
|
}
|
|
25
25
|
exports.createPool = createPool;
|
|
File without changes
|
|
File without changes
|
package/cjs/{Pool.js → pool.js}
RENAMED
|
@@ -7,11 +7,11 @@ exports.Pool = void 0;
|
|
|
7
7
|
const doublylinked_1 = __importDefault(require("doublylinked"));
|
|
8
8
|
const events_1 = require("events");
|
|
9
9
|
const putil_promisify_1 = __importDefault(require("putil-promisify"));
|
|
10
|
-
const
|
|
10
|
+
const abort_error_js_1 = require("./abort-error.js");
|
|
11
11
|
const definitions_js_1 = require("./definitions.js");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const pool_options_js_1 = require("./pool-options.js");
|
|
13
|
+
const pool_request_js_1 = require("./pool-request.js");
|
|
14
|
+
const resource_item_js_1 = require("./resource-item.js");
|
|
15
15
|
class Pool extends events_1.EventEmitter {
|
|
16
16
|
constructor(factory, config) {
|
|
17
17
|
super();
|
|
@@ -32,7 +32,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
32
32
|
throw new TypeError('factory.validate can be a function');
|
|
33
33
|
if (factory.reset && typeof factory.reset !== 'function')
|
|
34
34
|
throw new TypeError('factory.reset can be a function');
|
|
35
|
-
const opts = this._options = new
|
|
35
|
+
const opts = this._options = new pool_options_js_1.PoolOptions(this);
|
|
36
36
|
opts.on('change', (prop, val) => {
|
|
37
37
|
if (prop === 'houseKeepInterval')
|
|
38
38
|
this._setHouseKeep(val);
|
|
@@ -162,7 +162,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
162
162
|
}
|
|
163
163
|
if (this.options.maxQueue && this.pending >= this.options.maxQueue)
|
|
164
164
|
return callback(new Error('Pool queue is full'));
|
|
165
|
-
this._requestQueue.push(new
|
|
165
|
+
this._requestQueue.push(new pool_request_js_1.PoolRequest(this, callback));
|
|
166
166
|
this._processNextRequest();
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -294,7 +294,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
294
294
|
tries,
|
|
295
295
|
maxRetries: this.options.acquireMaxRetries
|
|
296
296
|
});
|
|
297
|
-
if (err instanceof
|
|
297
|
+
if (err instanceof abort_error_js_1.AbortError || tries >= maxRetries) {
|
|
298
298
|
this._creating--;
|
|
299
299
|
return callback && callback(err);
|
|
300
300
|
}
|
|
@@ -304,7 +304,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
304
304
|
if (this._allResources.has(obj))
|
|
305
305
|
return callback &&
|
|
306
306
|
callback(new Error('Factory error. Resource already in pool'));
|
|
307
|
-
const item = new
|
|
307
|
+
const item = new resource_item_js_1.ResourceItem(obj);
|
|
308
308
|
this._itemSetIdle(item);
|
|
309
309
|
this._allResources.set(obj, item);
|
|
310
310
|
if (callback)
|
|
@@ -316,7 +316,7 @@ class Pool extends events_1.EventEmitter {
|
|
|
316
316
|
const o = this._factory.create({ tries, maxRetries });
|
|
317
317
|
/* istanbul ignore next */
|
|
318
318
|
if (!o)
|
|
319
|
-
return handleCallback(new
|
|
319
|
+
return handleCallback(new abort_error_js_1.AbortError('Factory returned no resource'));
|
|
320
320
|
putil_promisify_1.default.await(o, handleCallback);
|
|
321
321
|
}
|
|
322
322
|
catch (e) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PoolConfiguration, PoolFactory } from './definitions.js';
|
|
2
|
-
import { Pool } from './
|
|
2
|
+
import { Pool } from './pool.js';
|
|
3
3
|
export * from './definitions.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
4
|
+
export * from './pool.js';
|
|
5
|
+
export * from './abort-error.js';
|
|
6
6
|
export declare function createPool<T = any>(factory: PoolFactory<T>, config?: PoolConfiguration): Pool<T>;
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Pool } from './
|
|
1
|
+
import { Pool } from './pool.js';
|
|
2
2
|
export * from './definitions.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './pool.js';
|
|
4
|
+
export * from './abort-error.js';
|
|
5
5
|
export function createPool(factory, config) {
|
|
6
6
|
return new Pool(factory, config);
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { PoolConfiguration } from './definitions.js';
|
|
4
|
-
import { Pool } from './
|
|
4
|
+
import { Pool } from './pool.js';
|
|
5
5
|
export declare class PoolOptions extends EventEmitter {
|
|
6
6
|
readonly pool: Pool;
|
|
7
7
|
private _acquireMaxRetries;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { Callback, PoolConfiguration, PoolFactory, PoolState } from './definitions.js';
|
|
4
|
-
import { PoolOptions } from './
|
|
4
|
+
import { PoolOptions } from './pool-options.js';
|
|
5
5
|
export declare class Pool<T = any> extends EventEmitter {
|
|
6
6
|
private readonly _options;
|
|
7
7
|
private readonly _factory;
|
|
@@ -66,7 +66,7 @@ export declare class Pool<T = any> extends EventEmitter {
|
|
|
66
66
|
/**
|
|
67
67
|
* Releases an allocated `resource` and let it back to pool.
|
|
68
68
|
*/
|
|
69
|
-
release(resource: T, callback?: Callback):
|
|
69
|
+
release(resource: T, callback?: Callback): void;
|
|
70
70
|
/**
|
|
71
71
|
* Async version of release().
|
|
72
72
|
*/
|
package/esm/{Pool.js → pool.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import DoublyLinked from 'doublylinked';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import promisify from 'putil-promisify';
|
|
4
|
-
import { AbortError } from './
|
|
4
|
+
import { AbortError } from './abort-error.js';
|
|
5
5
|
import { PoolState, ResourceState } from './definitions.js';
|
|
6
|
-
import { PoolOptions } from './
|
|
7
|
-
import { PoolRequest } from './
|
|
8
|
-
import { ResourceItem } from './
|
|
6
|
+
import { PoolOptions } from './pool-options.js';
|
|
7
|
+
import { PoolRequest } from './pool-request.js';
|
|
8
|
+
import { ResourceItem } from './resource-item.js';
|
|
9
9
|
export class Pool extends EventEmitter {
|
|
10
10
|
constructor(factory, config) {
|
|
11
11
|
super();
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightning-pool",
|
|
3
3
|
"description": "Fastest generic Pool written with TypeScript",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"author": "Panates Ltd.",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -19,32 +19,33 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@babel/eslint-parser": "^7.19.1",
|
|
22
|
-
"@types/jest": "^29.
|
|
23
|
-
"@types/node": "^18.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
25
|
-
"@typescript-eslint/parser": "^5.
|
|
26
|
-
"dotenv": "^16.0.
|
|
27
|
-
"eslint": "^8.
|
|
22
|
+
"@types/jest": "^29.1.2",
|
|
23
|
+
"@types/node": "^18.8.5",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
25
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
26
|
+
"dotenv": "^16.0.3",
|
|
27
|
+
"eslint": "^8.25.0",
|
|
28
28
|
"eslint-config-google": "^0.14.0",
|
|
29
29
|
"eslint-plugin-import": "^2.26.0",
|
|
30
30
|
"eslint-plugin-security": "^1.5.0",
|
|
31
31
|
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
32
32
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
33
|
-
"jest": "^29.0
|
|
33
|
+
"jest": "^29.2.0",
|
|
34
34
|
"npm-run-path": "^5.1.0",
|
|
35
35
|
"ts-cleanup": "^0.2.5",
|
|
36
|
-
"ts-jest": "^29.0.
|
|
37
|
-
"ts-loader": "^9.
|
|
36
|
+
"ts-jest": "^29.0.3",
|
|
37
|
+
"ts-loader": "^9.4.1",
|
|
38
38
|
"ts-node": "^10.9.1",
|
|
39
39
|
"tsconfig-paths": "^4.1.0",
|
|
40
|
-
"typescript": "^4.8.
|
|
40
|
+
"typescript": "^4.8.4"
|
|
41
41
|
},
|
|
42
42
|
"type": "module",
|
|
43
|
-
"main": "cjs/index.js",
|
|
44
|
-
"module": "esm/index.js",
|
|
45
43
|
"types": "esm/index.d.ts",
|
|
46
44
|
"exports": {
|
|
47
|
-
".":
|
|
45
|
+
".": {
|
|
46
|
+
"require": "./cjs/index.js",
|
|
47
|
+
"default": "./esm/index.js"
|
|
48
|
+
},
|
|
48
49
|
"./cjs": "./cjs/index.js",
|
|
49
50
|
"./esm": "./esm/index.js"
|
|
50
51
|
},
|