@aws/lsp-codewhisperer 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/node_modules/@amzn/codewhisperer-streaming/package.json +4 -4
- package/node_modules/@aws/lsp-fqn/out/common/commonFqnWorkerPool.js +12 -25
- package/node_modules/@aws/lsp-fqn/out/common/commonFqnWorkerPool.js.map +1 -1
- package/node_modules/@aws/lsp-fqn/out/common/fqnExtractor.js +1 -2
- package/node_modules/@aws/lsp-fqn/out/common/fqnExtractor.js.map +1 -1
- package/node_modules/@aws/lsp-fqn/package.json +1 -1
- package/node_modules/@aws/lsp-fqn/tsconfig.tsbuildinfo +1 -1
- package/out/client/streamingClient/codewhispererStreamingClient.d.ts +5 -0
- package/out/client/streamingClient/codewhispererStreamingClient.js +25 -0
- package/out/client/streamingClient/codewhispererStreamingClient.js.map +1 -0
- package/out/client/token/bearer-token-service.json +55 -2
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/index.js.map +1 -1
- package/out/language-server/chat/chatController.js +104 -108
- package/out/language-server/chat/chatController.js.map +1 -1
- package/out/language-server/chat/chatController.test.js +16 -1
- package/out/language-server/chat/chatController.test.js.map +1 -1
- package/out/language-server/chat/chatEventParser.js +28 -34
- package/out/language-server/chat/chatEventParser.js.map +1 -1
- package/out/language-server/chat/chatSessionManagementService.js +22 -36
- package/out/language-server/chat/chatSessionManagementService.js.map +1 -1
- package/out/language-server/chat/chatSessionService.js +24 -37
- package/out/language-server/chat/chatSessionService.js.map +1 -1
- package/out/language-server/chat/constants.d.ts +2 -0
- package/out/language-server/chat/constants.js +32 -0
- package/out/language-server/chat/constants.js.map +1 -0
- package/out/language-server/chat/contexts/documentContext.js +11 -24
- package/out/language-server/chat/contexts/documentContext.js.map +1 -1
- package/out/language-server/chat/contexts/documentFqnExtractor.js +67 -78
- package/out/language-server/chat/contexts/documentFqnExtractor.js.map +1 -1
- package/out/language-server/chat/contexts/triggerContext.js +32 -44
- package/out/language-server/chat/contexts/triggerContext.js.map +1 -1
- package/out/language-server/chat/quickActions.d.ts +0 -1
- package/out/language-server/chat/quickActions.js +1 -28
- package/out/language-server/chat/quickActions.js.map +1 -1
- package/out/language-server/chat/telemetry/chatTelemetryController.js +114 -126
- package/out/language-server/chat/telemetry/chatTelemetryController.js.map +1 -1
- package/out/language-server/chat/utils.d.ts +6 -0
- package/out/language-server/chat/utils.js +60 -0
- package/out/language-server/chat/utils.js.map +1 -0
- package/out/language-server/codeWhispererService.js +13 -11
- package/out/language-server/codeWhispererService.js.map +1 -1
- package/out/language-server/constants.d.ts +3 -0
- package/out/language-server/constants.js +7 -0
- package/out/language-server/constants.js.map +1 -0
- package/out/language-server/dependencyGraph/csharpDependencyGraph.js +2 -2
- package/out/language-server/dependencyGraph/csharpDependencyGraph.js.map +1 -1
- package/out/language-server/dependencyGraph/dependencyGraph.js +12 -9
- package/out/language-server/dependencyGraph/dependencyGraph.js.map +1 -1
- package/out/language-server/dependencyGraph/gitIgnoreFilter.js +1 -0
- package/out/language-server/dependencyGraph/gitIgnoreFilter.js.map +1 -1
- package/out/language-server/netTransform/artifactManager.d.ts +29 -0
- package/out/language-server/netTransform/artifactManager.js +191 -0
- package/out/language-server/netTransform/artifactManager.js.map +1 -0
- package/out/language-server/netTransform/converter.d.ts +7 -0
- package/out/language-server/netTransform/converter.js +88 -0
- package/out/language-server/netTransform/converter.js.map +1 -0
- package/out/language-server/netTransform/metrics.d.ts +17 -0
- package/out/language-server/netTransform/metrics.js +222 -0
- package/out/language-server/netTransform/metrics.js.map +1 -0
- package/out/language-server/netTransform/models.d.ts +84 -0
- package/out/language-server/netTransform/models.js +12 -0
- package/out/language-server/netTransform/models.js.map +1 -0
- package/out/language-server/netTransform/resources/SupportedProjects.d.ts +2 -0
- package/out/language-server/netTransform/resources/SupportedProjects.js +26 -0
- package/out/language-server/netTransform/resources/SupportedProjects.js.map +1 -0
- package/out/language-server/netTransform/tests/converter.test.d.ts +1 -0
- package/out/language-server/netTransform/tests/converter.test.js +151 -0
- package/out/language-server/netTransform/tests/converter.test.js.map +1 -0
- package/out/language-server/netTransform/tests/mockData.d.ts +21 -0
- package/out/language-server/netTransform/tests/mockData.js +60 -0
- package/out/language-server/netTransform/tests/mockData.js.map +1 -0
- package/out/language-server/netTransform/tests/transformHandler.test.d.ts +1 -0
- package/out/language-server/netTransform/tests/transformHandler.test.js +242 -0
- package/out/language-server/netTransform/tests/transformHandler.test.js.map +1 -0
- package/out/language-server/netTransform/tests/validation.test.d.ts +1 -0
- package/out/language-server/netTransform/tests/validation.test.js +80 -0
- package/out/language-server/netTransform/tests/validation.test.js.map +1 -0
- package/out/language-server/netTransform/transformHandler.d.ts +27 -0
- package/out/language-server/netTransform/transformHandler.js +315 -0
- package/out/language-server/netTransform/transformHandler.js.map +1 -0
- package/out/language-server/netTransform/validation.d.ts +9 -0
- package/out/language-server/netTransform/validation.js +79 -0
- package/out/language-server/netTransform/validation.js.map +1 -0
- package/out/language-server/netTransformServer.d.ts +5 -6
- package/out/language-server/netTransformServer.js +149 -15
- package/out/language-server/netTransformServer.js.map +1 -1
- package/out/language-server/proxy-server.d.ts +1 -0
- package/out/language-server/proxy-server.js +16 -1
- package/out/language-server/proxy-server.js.map +1 -1
- package/out/language-server/securityScan/securityScanDiagnosticsProvider.js +10 -6
- package/out/language-server/securityScan/securityScanDiagnosticsProvider.js.map +1 -1
- package/out/language-server/securityScan/securityScanHandler.js +4 -0
- package/out/language-server/securityScan/securityScanHandler.js.map +1 -1
- package/out/language-server/session/sessionManager.js +35 -15
- package/out/language-server/session/sessionManager.js.map +1 -1
- package/out/language-server/telemetry/codeDiffTracker.js +69 -80
- package/out/language-server/telemetry/codeDiffTracker.js.map +1 -1
- package/out/language-server/telemetry/codePercentage.js +3 -0
- package/out/language-server/telemetry/codePercentage.js.map +1 -1
- package/out/language-server/telemetry/metric.js +8 -21
- package/out/language-server/telemetry/metric.js.map +1 -1
- package/out/language-server/telemetry/types.d.ts +38 -0
- package/out/language-server/telemetry/types.js.map +1 -1
- package/out/language-server/utils.d.ts +2 -5
- package/out/language-server/utils.js +25 -49
- package/out/language-server/utils.js.map +1 -1
- package/package.json +5 -2
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/HISTORY.md +0 -395
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/LICENSE +0 -201
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/README.md +0 -530
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/worker.js +0 -288
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/worker.js.map +0 -1
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/worker.min.js +0 -2
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/worker.min.js.map +0 -1
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/workerpool.js +0 -1737
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/workerpool.js.map +0 -1
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/workerpool.min.js +0 -3
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/workerpool.min.js.LICENSE.txt +0 -24
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/dist/workerpool.min.js.map +0 -1
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/package.json +0 -57
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/Pool.js +0 -476
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/Promise.js +0 -293
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/WorkerHandler.js +0 -547
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/debug-port-allocator.js +0 -28
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/environment.js +0 -30
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/generated/embeddedWorker.js +0 -6
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/header.js +0 -24
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/index.js +0 -60
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/requireFoolWebpack.js +0 -8
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/transfer.js +0 -12
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/types.js +0 -46
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/validateOptions.js +0 -51
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/src/worker.js +0 -256
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/Pool.d.ts +0 -130
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/Promise.d.ts +0 -125
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/WorkerHandler.d.ts +0 -89
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/debug-port-allocator.d.ts +0 -8
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/environment.d.ts +0 -4
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/generated/embeddedWorker.d.ts +0 -2
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/index.d.ts +0 -43
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/transfer.d.ts +0 -19
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/types.d.ts +0 -99
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/validateOptions.d.ts +0 -4
- package/node_modules/@aws/lsp-fqn/node_modules/workerpool/types/worker.d.ts +0 -8
- package/node_modules/@smithy/eventstream-serde-config-resolver/LICENSE +0 -201
- package/node_modules/@smithy/eventstream-serde-config-resolver/README.md +0 -10
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-cjs/EventStreamSerdeConfig.js +0 -1
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-cjs/index.js +0 -37
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-es/EventStreamSerdeConfig.js +0 -4
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-es/index.js +0 -1
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-types/EventStreamSerdeConfig.d.ts +0 -24
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-types/index.d.ts +0 -4
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-types/ts3.4/EventStreamSerdeConfig.d.ts +0 -24
- package/node_modules/@smithy/eventstream-serde-config-resolver/dist-types/ts3.4/index.d.ts +0 -4
- package/node_modules/@smithy/eventstream-serde-config-resolver/package.json +0 -61
- package/node_modules/bowser/CHANGELOG.md +0 -218
- package/node_modules/bowser/LICENSE +0 -39
- package/node_modules/bowser/README.md +0 -179
- package/node_modules/bowser/bundled.js +0 -1
- package/node_modules/bowser/es5.js +0 -1
- package/node_modules/bowser/index.d.ts +0 -250
- package/node_modules/bowser/package.json +0 -83
- package/node_modules/bowser/src/bowser.js +0 -77
- package/node_modules/bowser/src/constants.js +0 -116
- package/node_modules/bowser/src/parser-browsers.js +0 -700
- package/node_modules/bowser/src/parser-engines.js +0 -120
- package/node_modules/bowser/src/parser-os.js +0 -199
- package/node_modules/bowser/src/parser-platforms.js +0 -266
- package/node_modules/bowser/src/parser.js +0 -496
- package/node_modules/bowser/src/utils.js +0 -309
- package/node_modules/tslib/CopyrightNotice.txt +0 -15
- package/node_modules/tslib/LICENSE.txt +0 -12
- package/node_modules/tslib/README.md +0 -164
- package/node_modules/tslib/SECURITY.md +0 -41
- package/node_modules/tslib/modules/index.d.ts +0 -37
- package/node_modules/tslib/modules/index.js +0 -68
- package/node_modules/tslib/modules/package.json +0 -3
- package/node_modules/tslib/package.json +0 -47
- package/node_modules/tslib/tslib.d.ts +0 -453
- package/node_modules/tslib/tslib.es6.html +0 -1
- package/node_modules/tslib/tslib.es6.js +0 -374
- package/node_modules/tslib/tslib.es6.mjs +0 -373
- package/node_modules/tslib/tslib.html +0 -1
- package/node_modules/tslib/tslib.js +0 -424
- package/node_modules/uuid/CHANGELOG.md +0 -274
- package/node_modules/uuid/CONTRIBUTING.md +0 -18
- package/node_modules/uuid/LICENSE.md +0 -9
- package/node_modules/uuid/README.md +0 -466
- package/node_modules/uuid/dist/bin/uuid +0 -2
- package/node_modules/uuid/dist/commonjs-browser/index.js +0 -79
- package/node_modules/uuid/dist/commonjs-browser/md5.js +0 -223
- package/node_modules/uuid/dist/commonjs-browser/native.js +0 -11
- package/node_modules/uuid/dist/commonjs-browser/nil.js +0 -8
- package/node_modules/uuid/dist/commonjs-browser/parse.js +0 -45
- package/node_modules/uuid/dist/commonjs-browser/regex.js +0 -8
- package/node_modules/uuid/dist/commonjs-browser/rng.js +0 -25
- package/node_modules/uuid/dist/commonjs-browser/sha1.js +0 -104
- package/node_modules/uuid/dist/commonjs-browser/stringify.js +0 -44
- package/node_modules/uuid/dist/commonjs-browser/v1.js +0 -107
- package/node_modules/uuid/dist/commonjs-browser/v3.js +0 -16
- package/node_modules/uuid/dist/commonjs-browser/v35.js +0 -80
- package/node_modules/uuid/dist/commonjs-browser/v4.js +0 -43
- package/node_modules/uuid/dist/commonjs-browser/v5.js +0 -16
- package/node_modules/uuid/dist/commonjs-browser/validate.js +0 -17
- package/node_modules/uuid/dist/commonjs-browser/version.js +0 -21
- package/node_modules/uuid/dist/esm-browser/index.js +0 -9
- package/node_modules/uuid/dist/esm-browser/md5.js +0 -215
- package/node_modules/uuid/dist/esm-browser/native.js +0 -4
- package/node_modules/uuid/dist/esm-browser/nil.js +0 -1
- package/node_modules/uuid/dist/esm-browser/parse.js +0 -35
- package/node_modules/uuid/dist/esm-browser/regex.js +0 -1
- package/node_modules/uuid/dist/esm-browser/rng.js +0 -18
- package/node_modules/uuid/dist/esm-browser/sha1.js +0 -96
- package/node_modules/uuid/dist/esm-browser/stringify.js +0 -33
- package/node_modules/uuid/dist/esm-browser/v1.js +0 -95
- package/node_modules/uuid/dist/esm-browser/v3.js +0 -4
- package/node_modules/uuid/dist/esm-browser/v35.js +0 -66
- package/node_modules/uuid/dist/esm-browser/v4.js +0 -29
- package/node_modules/uuid/dist/esm-browser/v5.js +0 -4
- package/node_modules/uuid/dist/esm-browser/validate.js +0 -7
- package/node_modules/uuid/dist/esm-browser/version.js +0 -11
- package/node_modules/uuid/dist/esm-node/index.js +0 -9
- package/node_modules/uuid/dist/esm-node/md5.js +0 -13
- package/node_modules/uuid/dist/esm-node/native.js +0 -4
- package/node_modules/uuid/dist/esm-node/nil.js +0 -1
- package/node_modules/uuid/dist/esm-node/parse.js +0 -35
- package/node_modules/uuid/dist/esm-node/regex.js +0 -1
- package/node_modules/uuid/dist/esm-node/rng.js +0 -12
- package/node_modules/uuid/dist/esm-node/sha1.js +0 -13
- package/node_modules/uuid/dist/esm-node/stringify.js +0 -33
- package/node_modules/uuid/dist/esm-node/v1.js +0 -95
- package/node_modules/uuid/dist/esm-node/v3.js +0 -4
- package/node_modules/uuid/dist/esm-node/v35.js +0 -66
- package/node_modules/uuid/dist/esm-node/v4.js +0 -29
- package/node_modules/uuid/dist/esm-node/v5.js +0 -4
- package/node_modules/uuid/dist/esm-node/validate.js +0 -7
- package/node_modules/uuid/dist/esm-node/version.js +0 -11
- package/node_modules/uuid/dist/index.js +0 -79
- package/node_modules/uuid/dist/md5-browser.js +0 -223
- package/node_modules/uuid/dist/md5.js +0 -23
- package/node_modules/uuid/dist/native-browser.js +0 -11
- package/node_modules/uuid/dist/native.js +0 -15
- package/node_modules/uuid/dist/nil.js +0 -8
- package/node_modules/uuid/dist/parse.js +0 -45
- package/node_modules/uuid/dist/regex.js +0 -8
- package/node_modules/uuid/dist/rng-browser.js +0 -25
- package/node_modules/uuid/dist/rng.js +0 -24
- package/node_modules/uuid/dist/sha1-browser.js +0 -104
- package/node_modules/uuid/dist/sha1.js +0 -23
- package/node_modules/uuid/dist/stringify.js +0 -44
- package/node_modules/uuid/dist/uuid-bin.js +0 -85
- package/node_modules/uuid/dist/v1.js +0 -107
- package/node_modules/uuid/dist/v3.js +0 -16
- package/node_modules/uuid/dist/v35.js +0 -80
- package/node_modules/uuid/dist/v4.js +0 -43
- package/node_modules/uuid/dist/v5.js +0 -16
- package/node_modules/uuid/dist/validate.js +0 -17
- package/node_modules/uuid/dist/version.js +0 -21
- package/node_modules/uuid/package.json +0 -135
- package/node_modules/uuid/wrapper.mjs +0 -10
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
var {Promise} = require('./Promise');
|
|
2
|
-
var WorkerHandler = require('./WorkerHandler');
|
|
3
|
-
var environment = require('./environment');
|
|
4
|
-
var DebugPortAllocator = require('./debug-port-allocator');
|
|
5
|
-
var DEBUG_PORT_ALLOCATOR = new DebugPortAllocator();
|
|
6
|
-
/**
|
|
7
|
-
* A pool to manage workers, which can be created using the function workerpool.pool.
|
|
8
|
-
*
|
|
9
|
-
* @param {String} [script] Optional worker script
|
|
10
|
-
* @param {import('./types.js').WorkerPoolOptions} [options] See docs
|
|
11
|
-
* @constructor
|
|
12
|
-
*/
|
|
13
|
-
function Pool(script, options) {
|
|
14
|
-
if (typeof script === 'string') {
|
|
15
|
-
/** @readonly */
|
|
16
|
-
this.script = script || null;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.script = null;
|
|
20
|
-
options = script;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** @private */
|
|
24
|
-
this.workers = []; // queue with all workers
|
|
25
|
-
/** @private */
|
|
26
|
-
this.tasks = []; // queue with tasks awaiting execution
|
|
27
|
-
|
|
28
|
-
options = options || {};
|
|
29
|
-
|
|
30
|
-
/** @readonly */
|
|
31
|
-
this.forkArgs = Object.freeze(options.forkArgs || []);
|
|
32
|
-
/** @readonly */
|
|
33
|
-
this.forkOpts = Object.freeze(options.forkOpts || {});
|
|
34
|
-
/** @readonly */
|
|
35
|
-
this.workerOpts = Object.freeze(options.workerOpts || {});
|
|
36
|
-
/** @readonly */
|
|
37
|
-
this.workerThreadOpts = Object.freeze(options.workerThreadOpts || {})
|
|
38
|
-
/** @private */
|
|
39
|
-
this.debugPortStart = (options.debugPortStart || 43210);
|
|
40
|
-
/** @readonly @deprecated */
|
|
41
|
-
this.nodeWorker = options.nodeWorker;
|
|
42
|
-
/** @readonly
|
|
43
|
-
* @type {'auto' | 'web' | 'process' | 'thread'}
|
|
44
|
-
*/
|
|
45
|
-
this.workerType = options.workerType || options.nodeWorker || 'auto'
|
|
46
|
-
/** @readonly */
|
|
47
|
-
this.maxQueueSize = options.maxQueueSize || Infinity;
|
|
48
|
-
/** @readonly */
|
|
49
|
-
this.workerTerminateTimeout = options.workerTerminateTimeout || 1000;
|
|
50
|
-
|
|
51
|
-
/** @readonly */
|
|
52
|
-
this.onCreateWorker = options.onCreateWorker || (() => null);
|
|
53
|
-
/** @readonly */
|
|
54
|
-
this.onTerminateWorker = options.onTerminateWorker || (() => null);
|
|
55
|
-
|
|
56
|
-
/** @readonly */
|
|
57
|
-
this.emitStdStreams = options.emitStdStreams || false
|
|
58
|
-
|
|
59
|
-
// configuration
|
|
60
|
-
if (options && 'maxWorkers' in options) {
|
|
61
|
-
validateMaxWorkers(options.maxWorkers);
|
|
62
|
-
/** @readonly */
|
|
63
|
-
this.maxWorkers = options.maxWorkers;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (options && 'minWorkers' in options) {
|
|
70
|
-
if(options.minWorkers === 'max') {
|
|
71
|
-
/** @readonly */
|
|
72
|
-
this.minWorkers = this.maxWorkers;
|
|
73
|
-
} else {
|
|
74
|
-
validateMinWorkers(options.minWorkers);
|
|
75
|
-
this.minWorkers = options.minWorkers;
|
|
76
|
-
this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers); // in case minWorkers is higher than maxWorkers
|
|
77
|
-
}
|
|
78
|
-
this._ensureMinWorkers();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @private */
|
|
82
|
-
this._boundNext = this._next.bind(this);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (this.workerType === 'thread') {
|
|
86
|
-
WorkerHandler.ensureWorkerThreads();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Execute a function on a worker.
|
|
93
|
-
*
|
|
94
|
-
* Example usage:
|
|
95
|
-
*
|
|
96
|
-
* var pool = new Pool()
|
|
97
|
-
*
|
|
98
|
-
* // call a function available on the worker
|
|
99
|
-
* pool.exec('fibonacci', [6])
|
|
100
|
-
*
|
|
101
|
-
* // offload a function
|
|
102
|
-
* function add(a, b) {
|
|
103
|
-
* return a + b
|
|
104
|
-
* };
|
|
105
|
-
* pool.exec(add, [2, 4])
|
|
106
|
-
* .then(function (result) {
|
|
107
|
-
* console.log(result); // outputs 6
|
|
108
|
-
* })
|
|
109
|
-
* .catch(function(error) {
|
|
110
|
-
* console.log(error);
|
|
111
|
-
* });
|
|
112
|
-
* @template { (...args: any[]) => any } T
|
|
113
|
-
* @param {String | T} method Function name or function.
|
|
114
|
-
* If `method` is a string, the corresponding
|
|
115
|
-
* method on the worker will be executed
|
|
116
|
-
* If `method` is a Function, the function
|
|
117
|
-
* will be stringified and executed via the
|
|
118
|
-
* workers built-in function `run(fn, args)`.
|
|
119
|
-
* @param {Parameters<T> | null} [params] Function arguments applied when calling the function
|
|
120
|
-
* @param {import('./types.js').ExecOptions} [options] Options
|
|
121
|
-
* @return {Promise<ReturnType<T>>}
|
|
122
|
-
*/
|
|
123
|
-
Pool.prototype.exec = function (method, params, options) {
|
|
124
|
-
// validate type of arguments
|
|
125
|
-
if (params && !Array.isArray(params)) {
|
|
126
|
-
throw new TypeError('Array expected as argument "params"');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (typeof method === 'string') {
|
|
130
|
-
var resolver = Promise.defer();
|
|
131
|
-
|
|
132
|
-
if (this.tasks.length >= this.maxQueueSize) {
|
|
133
|
-
throw new Error('Max queue size of ' + this.maxQueueSize + ' reached');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// add a new task to the queue
|
|
137
|
-
var tasks = this.tasks;
|
|
138
|
-
var task = {
|
|
139
|
-
method: method,
|
|
140
|
-
params: params,
|
|
141
|
-
resolver: resolver,
|
|
142
|
-
timeout: null,
|
|
143
|
-
options: options
|
|
144
|
-
};
|
|
145
|
-
tasks.push(task);
|
|
146
|
-
|
|
147
|
-
// replace the timeout method of the Promise with our own,
|
|
148
|
-
// which starts the timer as soon as the task is actually started
|
|
149
|
-
var originalTimeout = resolver.promise.timeout;
|
|
150
|
-
resolver.promise.timeout = function timeout (delay) {
|
|
151
|
-
if (tasks.indexOf(task) !== -1) {
|
|
152
|
-
// task is still queued -> start the timer later on
|
|
153
|
-
task.timeout = delay;
|
|
154
|
-
return resolver.promise;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// task is already being executed -> start timer immediately
|
|
158
|
-
return originalTimeout.call(resolver.promise, delay);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// trigger task execution
|
|
163
|
-
this._next();
|
|
164
|
-
|
|
165
|
-
return resolver.promise;
|
|
166
|
-
}
|
|
167
|
-
else if (typeof method === 'function') {
|
|
168
|
-
// send stringified function and function arguments to worker
|
|
169
|
-
return this.exec('run', [String(method), params], options);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new TypeError('Function or string expected as argument "method"');
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Create a proxy for current worker. Returns an object containing all
|
|
178
|
-
* methods available on the worker. All methods return promises resolving the methods result.
|
|
179
|
-
* @template { { [k: string]: (...args: any[]) => any } } T
|
|
180
|
-
* @return {Promise<import('./types.js').Proxy<T>, Error>} Returns a promise which resolves with a proxy object
|
|
181
|
-
*/
|
|
182
|
-
Pool.prototype.proxy = function () {
|
|
183
|
-
if (arguments.length > 0) {
|
|
184
|
-
throw new Error('No arguments expected');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
var pool = this;
|
|
188
|
-
return this.exec('methods')
|
|
189
|
-
.then(function (methods) {
|
|
190
|
-
var proxy = {};
|
|
191
|
-
|
|
192
|
-
methods.forEach(function (method) {
|
|
193
|
-
proxy[method] = function () {
|
|
194
|
-
return pool.exec(method, Array.prototype.slice.call(arguments));
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
return proxy;
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Creates new array with the results of calling a provided callback function
|
|
204
|
-
* on every element in this array.
|
|
205
|
-
* @param {Array} array
|
|
206
|
-
* @param {function} callback Function taking two arguments:
|
|
207
|
-
* `callback(currentValue, index)`
|
|
208
|
-
* @return {Promise.<Array>} Returns a promise which resolves with an Array
|
|
209
|
-
* containing the results of the callback function
|
|
210
|
-
* executed for each of the array elements.
|
|
211
|
-
*/
|
|
212
|
-
/* TODO: implement map
|
|
213
|
-
Pool.prototype.map = function (array, callback) {
|
|
214
|
-
};
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Grab the first task from the queue, find a free worker, and assign the
|
|
219
|
-
* worker to the task.
|
|
220
|
-
* @private
|
|
221
|
-
*/
|
|
222
|
-
Pool.prototype._next = function () {
|
|
223
|
-
if (this.tasks.length > 0) {
|
|
224
|
-
// there are tasks in the queue
|
|
225
|
-
|
|
226
|
-
// find an available worker
|
|
227
|
-
var worker = this._getWorker();
|
|
228
|
-
if (worker) {
|
|
229
|
-
// get the first task from the queue
|
|
230
|
-
var me = this;
|
|
231
|
-
var task = this.tasks.shift();
|
|
232
|
-
|
|
233
|
-
// check if the task is still pending (and not cancelled -> promise rejected)
|
|
234
|
-
if (task.resolver.promise.pending) {
|
|
235
|
-
// send the request to the worker
|
|
236
|
-
var promise = worker.exec(task.method, task.params, task.resolver, task.options)
|
|
237
|
-
.then(me._boundNext)
|
|
238
|
-
.catch(function () {
|
|
239
|
-
// if the worker crashed and terminated, remove it from the pool
|
|
240
|
-
if (worker.terminated) {
|
|
241
|
-
return me._removeWorker(worker);
|
|
242
|
-
}
|
|
243
|
-
}).then(function() {
|
|
244
|
-
me._next(); // trigger next task in the queue
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// start queued timer now
|
|
248
|
-
if (typeof task.timeout === 'number') {
|
|
249
|
-
promise.timeout(task.timeout);
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
// The task taken was already complete (either rejected or resolved), so just trigger next task in the queue
|
|
253
|
-
me._next();
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Get an available worker. If no worker is available and the maximum number
|
|
261
|
-
* of workers isn't yet reached, a new worker will be created and returned.
|
|
262
|
-
* If no worker is available and the maximum number of workers is reached,
|
|
263
|
-
* null will be returned.
|
|
264
|
-
*
|
|
265
|
-
* @return {WorkerHandler | null} worker
|
|
266
|
-
* @private
|
|
267
|
-
*/
|
|
268
|
-
Pool.prototype._getWorker = function() {
|
|
269
|
-
// find a non-busy worker
|
|
270
|
-
var workers = this.workers;
|
|
271
|
-
for (var i = 0; i < workers.length; i++) {
|
|
272
|
-
var worker = workers[i];
|
|
273
|
-
if (worker.busy() === false) {
|
|
274
|
-
return worker;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (workers.length < this.maxWorkers) {
|
|
279
|
-
// create a new worker
|
|
280
|
-
worker = this._createWorkerHandler();
|
|
281
|
-
workers.push(worker);
|
|
282
|
-
return worker;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return null;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Remove a worker from the pool.
|
|
290
|
-
* Attempts to terminate worker if not already terminated, and ensures the minimum
|
|
291
|
-
* pool size is met.
|
|
292
|
-
* @param {WorkerHandler} worker
|
|
293
|
-
* @return {Promise<WorkerHandler>}
|
|
294
|
-
* @private
|
|
295
|
-
*/
|
|
296
|
-
Pool.prototype._removeWorker = function(worker) {
|
|
297
|
-
var me = this;
|
|
298
|
-
|
|
299
|
-
DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
|
|
300
|
-
// _removeWorker will call this, but we need it to be removed synchronously
|
|
301
|
-
this._removeWorkerFromList(worker);
|
|
302
|
-
// If minWorkers set, spin up new workers to replace the crashed ones
|
|
303
|
-
this._ensureMinWorkers();
|
|
304
|
-
// terminate the worker (if not already terminated)
|
|
305
|
-
return new Promise(function(resolve, reject) {
|
|
306
|
-
worker.terminate(false, function(err) {
|
|
307
|
-
me.onTerminateWorker({
|
|
308
|
-
forkArgs: worker.forkArgs,
|
|
309
|
-
forkOpts: worker.forkOpts,
|
|
310
|
-
workerThreadOpts: worker.workerThreadOpts,
|
|
311
|
-
script: worker.script
|
|
312
|
-
});
|
|
313
|
-
if (err) {
|
|
314
|
-
reject(err);
|
|
315
|
-
} else {
|
|
316
|
-
resolve(worker);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Remove a worker from the pool list.
|
|
324
|
-
* @param {WorkerHandler} worker
|
|
325
|
-
* @private
|
|
326
|
-
*/
|
|
327
|
-
Pool.prototype._removeWorkerFromList = function(worker) {
|
|
328
|
-
// remove from the list with workers
|
|
329
|
-
var index = this.workers.indexOf(worker);
|
|
330
|
-
if (index !== -1) {
|
|
331
|
-
this.workers.splice(index, 1);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Close all active workers. Tasks currently being executed will be finished first.
|
|
337
|
-
* @param {boolean} [force=false] If false (default), the workers are terminated
|
|
338
|
-
* after finishing all tasks currently in
|
|
339
|
-
* progress. If true, the workers will be
|
|
340
|
-
* terminated immediately.
|
|
341
|
-
* @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected
|
|
342
|
-
* after timeout if worker process has not been terminated.
|
|
343
|
-
* @return {Promise.<void, Error>}
|
|
344
|
-
*/
|
|
345
|
-
Pool.prototype.terminate = function (force, timeout) {
|
|
346
|
-
var me = this;
|
|
347
|
-
|
|
348
|
-
// cancel any pending tasks
|
|
349
|
-
this.tasks.forEach(function (task) {
|
|
350
|
-
task.resolver.reject(new Error('Pool terminated'));
|
|
351
|
-
});
|
|
352
|
-
this.tasks.length = 0;
|
|
353
|
-
|
|
354
|
-
var f = function (worker) {
|
|
355
|
-
DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
|
|
356
|
-
this._removeWorkerFromList(worker);
|
|
357
|
-
};
|
|
358
|
-
var removeWorker = f.bind(this);
|
|
359
|
-
|
|
360
|
-
var promises = [];
|
|
361
|
-
var workers = this.workers.slice();
|
|
362
|
-
workers.forEach(function (worker) {
|
|
363
|
-
var termPromise = worker.terminateAndNotify(force, timeout)
|
|
364
|
-
.then(removeWorker)
|
|
365
|
-
.always(function() {
|
|
366
|
-
me.onTerminateWorker({
|
|
367
|
-
forkArgs: worker.forkArgs,
|
|
368
|
-
forkOpts: worker.forkOpts,
|
|
369
|
-
workerThreadOpts: worker.workerThreadOpts,
|
|
370
|
-
script: worker.script
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
promises.push(termPromise);
|
|
374
|
-
});
|
|
375
|
-
return Promise.all(promises);
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Retrieve statistics on tasks and workers.
|
|
380
|
-
* @return {{totalWorkers: number, busyWorkers: number, idleWorkers: number, pendingTasks: number, activeTasks: number}} Returns an object with statistics
|
|
381
|
-
*/
|
|
382
|
-
Pool.prototype.stats = function () {
|
|
383
|
-
var totalWorkers = this.workers.length;
|
|
384
|
-
var busyWorkers = this.workers.filter(function (worker) {
|
|
385
|
-
return worker.busy();
|
|
386
|
-
}).length;
|
|
387
|
-
|
|
388
|
-
return {
|
|
389
|
-
totalWorkers: totalWorkers,
|
|
390
|
-
busyWorkers: busyWorkers,
|
|
391
|
-
idleWorkers: totalWorkers - busyWorkers,
|
|
392
|
-
|
|
393
|
-
pendingTasks: this.tasks.length,
|
|
394
|
-
activeTasks: busyWorkers
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Ensures that a minimum of minWorkers is up and running
|
|
400
|
-
* @private
|
|
401
|
-
*/
|
|
402
|
-
Pool.prototype._ensureMinWorkers = function() {
|
|
403
|
-
if (this.minWorkers) {
|
|
404
|
-
for(var i = this.workers.length; i < this.minWorkers; i++) {
|
|
405
|
-
this.workers.push(this._createWorkerHandler());
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Helper function to create a new WorkerHandler and pass all options.
|
|
412
|
-
* @return {WorkerHandler}
|
|
413
|
-
* @private
|
|
414
|
-
*/
|
|
415
|
-
Pool.prototype._createWorkerHandler = function () {
|
|
416
|
-
const overriddenParams = this.onCreateWorker({
|
|
417
|
-
forkArgs: this.forkArgs,
|
|
418
|
-
forkOpts: this.forkOpts,
|
|
419
|
-
workerOpts: this.workerOpts,
|
|
420
|
-
workerThreadOpts: this.workerThreadOpts,
|
|
421
|
-
script: this.script
|
|
422
|
-
}) || {};
|
|
423
|
-
|
|
424
|
-
return new WorkerHandler(overriddenParams.script || this.script, {
|
|
425
|
-
forkArgs: overriddenParams.forkArgs || this.forkArgs,
|
|
426
|
-
forkOpts: overriddenParams.forkOpts || this.forkOpts,
|
|
427
|
-
workerOpts: overriddenParams.workerOpts || this.workerOpts,
|
|
428
|
-
workerThreadOpts: overriddenParams.workerThreadOpts || this.workerThreadOpts,
|
|
429
|
-
debugPort: DEBUG_PORT_ALLOCATOR.nextAvailableStartingAt(this.debugPortStart),
|
|
430
|
-
workerType: this.workerType,
|
|
431
|
-
workerTerminateTimeout: this.workerTerminateTimeout,
|
|
432
|
-
emitStdStreams: this.emitStdStreams,
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Ensure that the maxWorkers option is an integer >= 1
|
|
438
|
-
* @param {*} maxWorkers
|
|
439
|
-
* @returns {boolean} returns true maxWorkers has a valid value
|
|
440
|
-
*/
|
|
441
|
-
function validateMaxWorkers(maxWorkers) {
|
|
442
|
-
if (!isNumber(maxWorkers) || !isInteger(maxWorkers) || maxWorkers < 1) {
|
|
443
|
-
throw new TypeError('Option maxWorkers must be an integer number >= 1');
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Ensure that the minWorkers option is an integer >= 0
|
|
449
|
-
* @param {*} minWorkers
|
|
450
|
-
* @returns {boolean} returns true when minWorkers has a valid value
|
|
451
|
-
*/
|
|
452
|
-
function validateMinWorkers(minWorkers) {
|
|
453
|
-
if (!isNumber(minWorkers) || !isInteger(minWorkers) || minWorkers < 0) {
|
|
454
|
-
throw new TypeError('Option minWorkers must be an integer number >= 0');
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Test whether a variable is a number
|
|
460
|
-
* @param {*} value
|
|
461
|
-
* @returns {boolean} returns true when value is a number
|
|
462
|
-
*/
|
|
463
|
-
function isNumber(value) {
|
|
464
|
-
return typeof value === 'number';
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Test whether a number is an integer
|
|
469
|
-
* @param {number} value
|
|
470
|
-
* @returns {boolean} Returns true if value is an integer
|
|
471
|
-
*/
|
|
472
|
-
function isInteger(value) {
|
|
473
|
-
return Math.round(value) == value;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
module.exports = Pool;
|