@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,8 +0,0 @@
|
|
|
1
|
-
// source of inspiration: https://github.com/sindresorhus/require-fool-webpack
|
|
2
|
-
var requireFoolWebpack = eval(
|
|
3
|
-
'typeof require !== \'undefined\' ' +
|
|
4
|
-
'? require ' +
|
|
5
|
-
': function (module) { throw new Error(\'Module " + module + " not found.\') }'
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
module.exports = requireFoolWebpack;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The helper class for transferring data from the worker to the main thread.
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} message The object to deliver to the main thread.
|
|
5
|
-
* @param {Object[]} transfer An array of transferable Objects to transfer ownership of.
|
|
6
|
-
*/
|
|
7
|
-
function Transfer(message, transfer) {
|
|
8
|
-
this.message = message;
|
|
9
|
-
this.transfer = transfer;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = Transfer;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} WorkerArg
|
|
3
|
-
* @property {string[]} [forkArgs] The `forkArgs` option of this pool
|
|
4
|
-
* @property {import('child_process').ForkOptions} [forkOpts] The `forkOpts` option of this pool
|
|
5
|
-
* @property {WorkerOptions} [workerOpts] The `workerOpts` option of this pool
|
|
6
|
-
* @property {import('worker_threads').WorkerOptions} [workerThreadOpts] The `workerThreadOpts` option of this pool
|
|
7
|
-
* @property {string} [script] The `script` option of this pool
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {Object} WorkerPoolOptions
|
|
12
|
-
* @property {number | 'max'} [minWorkers] The minimum number of workers that must be initialized and kept available. Setting this to `'max'` will create `maxWorkers` default workers
|
|
13
|
-
* @property {number} [maxWorkers] The default number of maxWorkers is the number of CPU's minus one. When the number of CPU's could not be determined (for example in older browsers), `maxWorkers` is set to 3.
|
|
14
|
-
* @property {number} [maxQueueSize] The maximum number of tasks allowed to be queued. Can be used to prevent running out of memory. If the maximum is exceeded, adding a new task will throw an error. The default value is `Infinity`.
|
|
15
|
-
* @property {'auto' | 'web' | 'process' | 'thread'} [workerType]
|
|
16
|
-
* - In case of `'auto'` (default), workerpool will automatically pick a suitable type of worker: when in a browser environment, `'web'` will be used. When in a node.js environment, `worker_threads` will be used if available (Node.js >= 11.7.0), else `child_process` will be used.
|
|
17
|
-
* - In case of `'web'`, a Web Worker will be used. Only available in a browser environment.
|
|
18
|
-
* - In case of `'process'`, `child_process` will be used. Only available in a node.js environment.
|
|
19
|
-
* - In case of `'thread'`, `worker_threads` will be used. If `worker_threads` are not available, an error is thrown. Only available in a node.js environment.
|
|
20
|
-
* @property {number} [workerTerminateTimeout] The timeout in milliseconds to wait for a worker to clean up it's resources on termination before stopping it forcefully. Default value is `1000`.
|
|
21
|
-
* @property {string[]} [forkArgs] For `process` worker type. An array passed as `args` to [child_process.fork](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
22
|
-
* @property {import('child_process').ForkOptions} [forkOpts] For `process` worker type. An object passed as `options` to [child_process.fork](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options).
|
|
23
|
-
* @property {WorkerOptions} [workerOpts] For `web` worker type. An object passed to the [constructor of the web worker](https://html.spec.whatwg.org/multipage/workers.html#dom-worker). See [WorkerOptions specification](https://html.spec.whatwg.org/multipage/workers.html#workeroptions) for available options.
|
|
24
|
-
* @property {import('worker_threads').WorkerOptions} [workerThreadOpts] Object`. For `worker` worker type. An object passed to [worker_threads.options](https://nodejs.org/api/worker_threads.html#new-workerfilename-options).
|
|
25
|
-
* @property {boolean} [emitStdStreams] Capture stdout and stderr from the worker and emit them via the `stdout` and `stderr` events. Not supported by the `web` worker type.
|
|
26
|
-
* @property { (arg: WorkerArg) => WorkerArg | undefined } [onCreateWorker] A callback that is called whenever a worker is being created. It can be used to allocate resources for each worker for example. Optionally, this callback can return an object containing one or more of the `WorkerArg` properties. The provided properties will be used to override the Pool properties for the worker being created.
|
|
27
|
-
* @property { (arg: WorkerArg) => void } [onTerminateWorker] A callback that is called whenever a worker is being terminated. It can be used to release resources that might have been allocated for this specific worker. The callback is passed as argument an object as described for `onCreateWorker`, with each property sets with the value for the worker being terminated.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {Object} ExecOptions
|
|
32
|
-
* @property {(payload: any) => unknown} [on] An event listener, to handle events sent by the worker for this execution.
|
|
33
|
-
* @property {Object[]} [transfer] A list of transferable objects to send to the worker. Not supported by `process` worker type. See ./examples/transferableObjects.js for usage.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @typedef {Object} WorkerRegisterOptions
|
|
38
|
-
* @property {(code: number | undefined) => PromiseLike<void> | void} [onTerminate] A callback that is called whenever a worker is being terminated. It can be used to release resources that might have been allocated for this specific worker. The difference with pool's `onTerminateWorker` is that this callback runs in the worker context, while onTerminateWorker is executed on the main thread.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @template { { [k: string]: (...args: any[]) => any } } T
|
|
43
|
-
* @typedef {{ [M in keyof T]: (...args: Parameters<T[M]>) => import('./Promise.js').Promise<ReturnType<T[M]>>; }} Proxy<T>
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
module.exports = {}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate that the object only contains known option names
|
|
3
|
-
* - Throws an error when unknown options are detected
|
|
4
|
-
* - Throws an error when some of the allowed options are attached
|
|
5
|
-
* @param {Object | undefined} options
|
|
6
|
-
* @param {string[]} allowedOptionNames
|
|
7
|
-
* @param {string} objectName
|
|
8
|
-
* @retrun {Object} Returns the original options
|
|
9
|
-
*/
|
|
10
|
-
exports.validateOptions = function validateOptions(options, allowedOptionNames, objectName) {
|
|
11
|
-
if (!options) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
var optionNames = options ? Object.keys(options) : []
|
|
16
|
-
|
|
17
|
-
// check for unknown properties
|
|
18
|
-
var unknownOptionName = optionNames.find(optionName => !allowedOptionNames.includes(optionName))
|
|
19
|
-
if (unknownOptionName) {
|
|
20
|
-
throw new Error('Object "' + objectName + '" contains an unknown option "' + unknownOptionName + '"')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// check for inherited properties which are not present on the object itself
|
|
24
|
-
var illegalOptionName = allowedOptionNames.find(allowedOptionName => {
|
|
25
|
-
return Object.prototype[allowedOptionName] && !optionNames.includes(allowedOptionName)
|
|
26
|
-
})
|
|
27
|
-
if (illegalOptionName) {
|
|
28
|
-
throw new Error('Object "' + objectName + '" contains an inherited option "' + illegalOptionName + '" which is ' +
|
|
29
|
-
'not defined in the object itself but in its prototype. Only plain objects are allowed. ' +
|
|
30
|
-
'Please remove the option from the prototype or override it with a value "undefined".')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return options
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// source: https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker
|
|
37
|
-
exports.workerOptsNames = [
|
|
38
|
-
'credentials', 'name', 'type' ]
|
|
39
|
-
|
|
40
|
-
// source: https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options
|
|
41
|
-
exports.forkOptsNames = [
|
|
42
|
-
'cwd', 'detached', 'env', 'execPath', 'execArgv', 'gid', 'serialization',
|
|
43
|
-
'signal', 'killSignal', 'silent', 'stdio', 'uid', 'windowsVerbatimArguments',
|
|
44
|
-
'timeout'
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
// source: https://nodejs.org/api/worker_threads.html#new-workerfilename-options
|
|
48
|
-
exports.workerThreadOptsNames = [
|
|
49
|
-
'argv', 'env', 'eval', 'execArgv', 'stdin', 'stdout', 'stderr', 'workerData',
|
|
50
|
-
'trackUnmanagedFds', 'transferList', 'resourceLimits', 'name'
|
|
51
|
-
]
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* worker must be started as a child process or a web worker.
|
|
3
|
-
* It listens for RPC messages from the parent process.
|
|
4
|
-
*/
|
|
5
|
-
var Transfer = require('./transfer');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Special message sent by parent which causes the worker to terminate itself.
|
|
9
|
-
* Not a "message object"; this string is the entire message.
|
|
10
|
-
*/
|
|
11
|
-
var TERMINATE_METHOD_ID = '__workerpool-terminate__';
|
|
12
|
-
|
|
13
|
-
// var nodeOSPlatform = require('./environment').nodeOSPlatform;
|
|
14
|
-
|
|
15
|
-
// create a worker API for sending and receiving messages which works both on
|
|
16
|
-
// node.js and in the browser
|
|
17
|
-
var worker = {
|
|
18
|
-
exit: function() {}
|
|
19
|
-
};
|
|
20
|
-
if (typeof self !== 'undefined' && typeof postMessage === 'function' && typeof addEventListener === 'function') {
|
|
21
|
-
// worker in the browser
|
|
22
|
-
worker.on = function (event, callback) {
|
|
23
|
-
addEventListener(event, function (message) {
|
|
24
|
-
callback(message.data);
|
|
25
|
-
})
|
|
26
|
-
};
|
|
27
|
-
worker.send = function (message) {
|
|
28
|
-
postMessage(message);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
else if (typeof process !== 'undefined') {
|
|
32
|
-
// node.js
|
|
33
|
-
|
|
34
|
-
var WorkerThreads;
|
|
35
|
-
try {
|
|
36
|
-
WorkerThreads = require('worker_threads');
|
|
37
|
-
} catch(error) {
|
|
38
|
-
if (typeof error === 'object' && error !== null && error.code === 'MODULE_NOT_FOUND') {
|
|
39
|
-
// no worker_threads, fallback to sub-process based workers
|
|
40
|
-
} else {
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (WorkerThreads &&
|
|
46
|
-
/* if there is a parentPort, we are in a WorkerThread */
|
|
47
|
-
WorkerThreads.parentPort !== null) {
|
|
48
|
-
var parentPort = WorkerThreads.parentPort;
|
|
49
|
-
worker.send = parentPort.postMessage.bind(parentPort);
|
|
50
|
-
worker.on = parentPort.on.bind(parentPort);
|
|
51
|
-
worker.exit = process.exit.bind(process);
|
|
52
|
-
} else {
|
|
53
|
-
worker.on = process.on.bind(process);
|
|
54
|
-
// ignore transfer argument since it is not supported by process
|
|
55
|
-
worker.send = function (message) {
|
|
56
|
-
process.send(message);
|
|
57
|
-
};
|
|
58
|
-
// register disconnect handler only for subprocess worker to exit when parent is killed unexpectedly
|
|
59
|
-
worker.on('disconnect', function () {
|
|
60
|
-
process.exit(1);
|
|
61
|
-
});
|
|
62
|
-
worker.exit = process.exit.bind(process);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
throw new Error('Script must be executed as a worker');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function convertError(error) {
|
|
70
|
-
return Object.getOwnPropertyNames(error).reduce(function(product, name) {
|
|
71
|
-
return Object.defineProperty(product, name, {
|
|
72
|
-
value: error[name],
|
|
73
|
-
enumerable: true
|
|
74
|
-
});
|
|
75
|
-
}, {});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Test whether a value is a Promise via duck typing.
|
|
80
|
-
* @param {*} value
|
|
81
|
-
* @returns {boolean} Returns true when given value is an object
|
|
82
|
-
* having functions `then` and `catch`.
|
|
83
|
-
*/
|
|
84
|
-
function isPromise(value) {
|
|
85
|
-
return value && (typeof value.then === 'function') && (typeof value.catch === 'function');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// functions available externally
|
|
89
|
-
worker.methods = {};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Execute a function with provided arguments
|
|
93
|
-
* @param {String} fn Stringified function
|
|
94
|
-
* @param {Array} [args] Function arguments
|
|
95
|
-
* @returns {*}
|
|
96
|
-
*/
|
|
97
|
-
worker.methods.run = function run(fn, args) {
|
|
98
|
-
var f = new Function('return (' + fn + ').apply(null, arguments);');
|
|
99
|
-
return f.apply(f, args);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Get a list with methods available on this worker
|
|
104
|
-
* @return {String[]} methods
|
|
105
|
-
*/
|
|
106
|
-
worker.methods.methods = function methods() {
|
|
107
|
-
return Object.keys(worker.methods);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Custom handler for when the worker is terminated.
|
|
112
|
-
*/
|
|
113
|
-
worker.terminationHandler = undefined;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Cleanup and exit the worker.
|
|
117
|
-
* @param {Number} code
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
worker.cleanupAndExit = function(code) {
|
|
121
|
-
var _exit = function() {
|
|
122
|
-
worker.exit(code);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if(!worker.terminationHandler) {
|
|
126
|
-
return _exit();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var result = worker.terminationHandler(code);
|
|
130
|
-
if (isPromise(result)) {
|
|
131
|
-
result.then(_exit, _exit);
|
|
132
|
-
} else {
|
|
133
|
-
_exit();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var currentRequestId = null;
|
|
138
|
-
|
|
139
|
-
worker.on('message', function (request) {
|
|
140
|
-
if (request === TERMINATE_METHOD_ID) {
|
|
141
|
-
return worker.cleanupAndExit(0);
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
var method = worker.methods[request.method];
|
|
145
|
-
|
|
146
|
-
if (method) {
|
|
147
|
-
currentRequestId = request.id;
|
|
148
|
-
|
|
149
|
-
// execute the function
|
|
150
|
-
var result = method.apply(method, request.params);
|
|
151
|
-
|
|
152
|
-
if (isPromise(result)) {
|
|
153
|
-
// promise returned, resolve this and then return
|
|
154
|
-
result
|
|
155
|
-
.then(function (result) {
|
|
156
|
-
if (result instanceof Transfer) {
|
|
157
|
-
worker.send({
|
|
158
|
-
id: request.id,
|
|
159
|
-
result: result.message,
|
|
160
|
-
error: null
|
|
161
|
-
}, result.transfer);
|
|
162
|
-
} else {
|
|
163
|
-
worker.send({
|
|
164
|
-
id: request.id,
|
|
165
|
-
result: result,
|
|
166
|
-
error: null
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
currentRequestId = null;
|
|
170
|
-
})
|
|
171
|
-
.catch(function (err) {
|
|
172
|
-
worker.send({
|
|
173
|
-
id: request.id,
|
|
174
|
-
result: null,
|
|
175
|
-
error: convertError(err)
|
|
176
|
-
});
|
|
177
|
-
currentRequestId = null;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
// immediate result
|
|
182
|
-
if (result instanceof Transfer) {
|
|
183
|
-
worker.send({
|
|
184
|
-
id: request.id,
|
|
185
|
-
result: result.message,
|
|
186
|
-
error: null
|
|
187
|
-
}, result.transfer);
|
|
188
|
-
} else {
|
|
189
|
-
worker.send({
|
|
190
|
-
id: request.id,
|
|
191
|
-
result: result,
|
|
192
|
-
error: null
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
currentRequestId = null;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
throw new Error('Unknown method "' + request.method + '"');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
catch (err) {
|
|
204
|
-
worker.send({
|
|
205
|
-
id: request.id,
|
|
206
|
-
result: null,
|
|
207
|
-
error: convertError(err)
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Register methods to the worker
|
|
214
|
-
* @param {Object} [methods]
|
|
215
|
-
* @param {import('./types.js').WorkerRegisterOptions} [options]
|
|
216
|
-
*/
|
|
217
|
-
worker.register = function (methods, options) {
|
|
218
|
-
|
|
219
|
-
if (methods) {
|
|
220
|
-
for (var name in methods) {
|
|
221
|
-
if (methods.hasOwnProperty(name)) {
|
|
222
|
-
worker.methods[name] = methods[name];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (options) {
|
|
228
|
-
worker.terminationHandler = options.onTerminate;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
worker.send('ready');
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
worker.emit = function (payload) {
|
|
235
|
-
if (currentRequestId) {
|
|
236
|
-
if (payload instanceof Transfer) {
|
|
237
|
-
worker.send({
|
|
238
|
-
id: currentRequestId,
|
|
239
|
-
isEvent: true,
|
|
240
|
-
payload: payload.message
|
|
241
|
-
}, payload.transfer);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
worker.send({
|
|
246
|
-
id: currentRequestId,
|
|
247
|
-
isEvent: true,
|
|
248
|
-
payload
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
if (typeof exports !== 'undefined') {
|
|
254
|
-
exports.add = worker.register;
|
|
255
|
-
exports.emit = worker.emit;
|
|
256
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
export = Pool;
|
|
4
|
-
/**
|
|
5
|
-
* A pool to manage workers, which can be created using the function workerpool.pool.
|
|
6
|
-
*
|
|
7
|
-
* @param {String} [script] Optional worker script
|
|
8
|
-
* @param {import('./types.js').WorkerPoolOptions} [options] See docs
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
declare function Pool(script?: string | undefined, options?: import("./types.js").WorkerPoolOptions | undefined): void;
|
|
12
|
-
declare class Pool {
|
|
13
|
-
/**
|
|
14
|
-
* A pool to manage workers, which can be created using the function workerpool.pool.
|
|
15
|
-
*
|
|
16
|
-
* @param {String} [script] Optional worker script
|
|
17
|
-
* @param {import('./types.js').WorkerPoolOptions} [options] See docs
|
|
18
|
-
* @constructor
|
|
19
|
-
*/
|
|
20
|
-
constructor(script?: string | undefined, options?: import("./types.js").WorkerPoolOptions | undefined);
|
|
21
|
-
/** @readonly */
|
|
22
|
-
readonly script: string | null;
|
|
23
|
-
/** @private */
|
|
24
|
-
private workers;
|
|
25
|
-
/** @private */
|
|
26
|
-
private tasks;
|
|
27
|
-
/** @readonly */
|
|
28
|
-
readonly forkArgs: readonly string[];
|
|
29
|
-
/** @readonly */
|
|
30
|
-
readonly forkOpts: Readonly<import("child_process").ForkOptions>;
|
|
31
|
-
/** @readonly */
|
|
32
|
-
readonly workerOpts: Readonly<WorkerOptions>;
|
|
33
|
-
/** @readonly */
|
|
34
|
-
readonly workerThreadOpts: Readonly<import("worker_threads").WorkerOptions>;
|
|
35
|
-
/** @private */
|
|
36
|
-
private debugPortStart;
|
|
37
|
-
/** @readonly @deprecated */
|
|
38
|
-
readonly nodeWorker: any;
|
|
39
|
-
/** @readonly
|
|
40
|
-
* @type {'auto' | 'web' | 'process' | 'thread'}
|
|
41
|
-
*/
|
|
42
|
-
readonly workerType: 'auto' | 'web' | 'process' | 'thread';
|
|
43
|
-
/** @readonly */
|
|
44
|
-
readonly maxQueueSize: number;
|
|
45
|
-
/** @readonly */
|
|
46
|
-
readonly workerTerminateTimeout: number;
|
|
47
|
-
/** @readonly */
|
|
48
|
-
readonly onCreateWorker: ((arg: import("./types.js").WorkerArg) => import("./types.js").WorkerArg | undefined) | (() => null);
|
|
49
|
-
/** @readonly */
|
|
50
|
-
readonly onTerminateWorker: (arg: import("./types.js").WorkerArg) => void;
|
|
51
|
-
/** @readonly */
|
|
52
|
-
readonly emitStdStreams: boolean;
|
|
53
|
-
/** @readonly */
|
|
54
|
-
readonly maxWorkers: number | undefined;
|
|
55
|
-
/** @readonly */
|
|
56
|
-
readonly minWorkers: number | undefined;
|
|
57
|
-
/** @private */
|
|
58
|
-
private _boundNext;
|
|
59
|
-
/**
|
|
60
|
-
* Execute a function on a worker.
|
|
61
|
-
*
|
|
62
|
-
* Example usage:
|
|
63
|
-
*
|
|
64
|
-
* var pool = new Pool()
|
|
65
|
-
*
|
|
66
|
-
* // call a function available on the worker
|
|
67
|
-
* pool.exec('fibonacci', [6])
|
|
68
|
-
*
|
|
69
|
-
* // offload a function
|
|
70
|
-
* function add(a, b) {
|
|
71
|
-
* return a + b
|
|
72
|
-
* };
|
|
73
|
-
* pool.exec(add, [2, 4])
|
|
74
|
-
* .then(function (result) {
|
|
75
|
-
* console.log(result); // outputs 6
|
|
76
|
-
* })
|
|
77
|
-
* .catch(function(error) {
|
|
78
|
-
* console.log(error);
|
|
79
|
-
* });
|
|
80
|
-
* @template { (...args: any[]) => any } T
|
|
81
|
-
* @param {String | T} method Function name or function.
|
|
82
|
-
* If `method` is a string, the corresponding
|
|
83
|
-
* method on the worker will be executed
|
|
84
|
-
* If `method` is a Function, the function
|
|
85
|
-
* will be stringified and executed via the
|
|
86
|
-
* workers built-in function `run(fn, args)`.
|
|
87
|
-
* @param {Parameters<T> | null} [params] Function arguments applied when calling the function
|
|
88
|
-
* @param {import('./types.js').ExecOptions} [options] Options
|
|
89
|
-
* @return {Promise<ReturnType<T>>}
|
|
90
|
-
*/
|
|
91
|
-
exec<T extends (...args: any[]) => any>(method: string | T, params?: Parameters<T> | null | undefined, options?: import("./types.js").ExecOptions | undefined): Promise<ReturnType<T>, Error>;
|
|
92
|
-
/**
|
|
93
|
-
* Create a proxy for current worker. Returns an object containing all
|
|
94
|
-
* methods available on the worker. All methods return promises resolving the methods result.
|
|
95
|
-
* @template { { [k: string]: (...args: any[]) => any } } T
|
|
96
|
-
* @return {Promise<import('./types.js').Proxy<T>, Error>} Returns a promise which resolves with a proxy object
|
|
97
|
-
*/
|
|
98
|
-
proxy<T_1 extends {
|
|
99
|
-
[k: string]: (...args: any[]) => any;
|
|
100
|
-
}>(...args: any[]): Promise<import("./types.js").Proxy<T_1>, Error>;
|
|
101
|
-
private _next;
|
|
102
|
-
private _getWorker;
|
|
103
|
-
private _removeWorker;
|
|
104
|
-
private _removeWorkerFromList;
|
|
105
|
-
/**
|
|
106
|
-
* Close all active workers. Tasks currently being executed will be finished first.
|
|
107
|
-
* @param {boolean} [force=false] If false (default), the workers are terminated
|
|
108
|
-
* after finishing all tasks currently in
|
|
109
|
-
* progress. If true, the workers will be
|
|
110
|
-
* terminated immediately.
|
|
111
|
-
* @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected
|
|
112
|
-
* after timeout if worker process has not been terminated.
|
|
113
|
-
* @return {Promise.<void, Error>}
|
|
114
|
-
*/
|
|
115
|
-
terminate(force?: boolean | undefined, timeout?: number | undefined): Promise<void, Error>;
|
|
116
|
-
/**
|
|
117
|
-
* Retrieve statistics on tasks and workers.
|
|
118
|
-
* @return {{totalWorkers: number, busyWorkers: number, idleWorkers: number, pendingTasks: number, activeTasks: number}} Returns an object with statistics
|
|
119
|
-
*/
|
|
120
|
-
stats(): {
|
|
121
|
-
totalWorkers: number;
|
|
122
|
-
busyWorkers: number;
|
|
123
|
-
idleWorkers: number;
|
|
124
|
-
pendingTasks: number;
|
|
125
|
-
activeTasks: number;
|
|
126
|
-
};
|
|
127
|
-
private _ensureMinWorkers;
|
|
128
|
-
private _createWorkerHandler;
|
|
129
|
-
}
|
|
130
|
-
import { Promise } from "./Promise";
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Promise
|
|
3
|
-
*
|
|
4
|
-
* Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa <trash@rubaxa.org>
|
|
5
|
-
* @template T
|
|
6
|
-
* @template [E=Error]
|
|
7
|
-
* @param {Function} handler Called as handler(resolve: Function, reject: Function)
|
|
8
|
-
* @param {Promise} [parent] Parent promise for propagation of cancel and timeout
|
|
9
|
-
*/
|
|
10
|
-
export function Promise<T, E = Error>(handler: Function, parent?: Promise<any, Error> | undefined): void;
|
|
11
|
-
export class Promise<T, E = Error> {
|
|
12
|
-
/**
|
|
13
|
-
* Promise
|
|
14
|
-
*
|
|
15
|
-
* Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa <trash@rubaxa.org>
|
|
16
|
-
* @template T
|
|
17
|
-
* @template [E=Error]
|
|
18
|
-
* @param {Function} handler Called as handler(resolve: Function, reject: Function)
|
|
19
|
-
* @param {Promise} [parent] Parent promise for propagation of cancel and timeout
|
|
20
|
-
*/
|
|
21
|
-
constructor(handler: Function, parent?: Promise<any, Error> | undefined);
|
|
22
|
-
/**
|
|
23
|
-
* @readonly
|
|
24
|
-
*/
|
|
25
|
-
readonly resolved: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* @readonly
|
|
28
|
-
*/
|
|
29
|
-
readonly rejected: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* @readonly
|
|
32
|
-
*/
|
|
33
|
-
readonly pending: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Add an onSuccess callback and optionally an onFail callback to the Promise
|
|
36
|
-
* @template TT
|
|
37
|
-
* @template [TE=never]
|
|
38
|
-
* @param {(r: T) => TT | PromiseLike<TT>} onSuccess
|
|
39
|
-
* @param {(r: E) => TE | PromiseLike<TE>} [onFail]
|
|
40
|
-
* @returns {Promise<TT | TE, any>} promise
|
|
41
|
-
*/
|
|
42
|
-
then: <TT, TE = never>(onSuccess: (r: T) => TT | PromiseLike<TT>, onFail?: ((r: E) => TE | PromiseLike<TE>) | undefined) => Promise<TT | TE, any>;
|
|
43
|
-
/**
|
|
44
|
-
* Cancel the promise. This will reject the promise with a CancellationError
|
|
45
|
-
* @returns {this} self
|
|
46
|
-
*/
|
|
47
|
-
cancel: () => this;
|
|
48
|
-
/**
|
|
49
|
-
* Set a timeout for the promise. If the promise is not resolved within
|
|
50
|
-
* the time, the promise will be cancelled and a TimeoutError is thrown.
|
|
51
|
-
* If the promise is resolved in time, the timeout is removed.
|
|
52
|
-
* @param {number} delay Delay in milliseconds
|
|
53
|
-
* @returns {this} self
|
|
54
|
-
*/
|
|
55
|
-
timeout: (delay: number) => this;
|
|
56
|
-
/**
|
|
57
|
-
* Add an onFail callback to the Promise
|
|
58
|
-
* @template TT
|
|
59
|
-
* @param {(error: E) => TT | PromiseLike<TT>} onFail
|
|
60
|
-
* @returns {Promise<T | TT>} promise
|
|
61
|
-
*/
|
|
62
|
-
catch<TT_1>(onFail: (error: E) => TT_1 | PromiseLike<TT_1>): Promise<T | TT_1, Error>;
|
|
63
|
-
/**
|
|
64
|
-
* Execute given callback when the promise either resolves or rejects.
|
|
65
|
-
* @template TT
|
|
66
|
-
* @param {() => Promise<TT>} fn
|
|
67
|
-
* @returns {Promise<TT>} promise
|
|
68
|
-
*/
|
|
69
|
-
always<TT_2>(fn: () => Promise<TT_2, Error>): Promise<TT_2, Error>;
|
|
70
|
-
}
|
|
71
|
-
export namespace Promise {
|
|
72
|
-
/**
|
|
73
|
-
* Create a promise which resolves when all provided promises are resolved,
|
|
74
|
-
* and fails when any of the promises resolves.
|
|
75
|
-
* @param {Promise[]} promises
|
|
76
|
-
* @returns {Promise<any[], any>} promise
|
|
77
|
-
*/
|
|
78
|
-
export function all(promises: Promise<any, Error>[]): Promise<any[], any>;
|
|
79
|
-
/**
|
|
80
|
-
* Create a promise resolver
|
|
81
|
-
* @returns {{promise: Promise, resolve: Function, reject: Function}} resolver
|
|
82
|
-
*/
|
|
83
|
-
export function defer(): {
|
|
84
|
-
promise: Promise<any, Error>;
|
|
85
|
-
resolve: Function;
|
|
86
|
-
reject: Function;
|
|
87
|
-
};
|
|
88
|
-
export { CancellationError };
|
|
89
|
-
export { TimeoutError };
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Create a cancellation error
|
|
93
|
-
* @param {String} [message]
|
|
94
|
-
* @extends Error
|
|
95
|
-
*/
|
|
96
|
-
declare function CancellationError(message?: string | undefined): void;
|
|
97
|
-
declare class CancellationError {
|
|
98
|
-
/**
|
|
99
|
-
* Create a cancellation error
|
|
100
|
-
* @param {String} [message]
|
|
101
|
-
* @extends Error
|
|
102
|
-
*/
|
|
103
|
-
constructor(message?: string | undefined);
|
|
104
|
-
message: string;
|
|
105
|
-
stack: string | undefined;
|
|
106
|
-
name: string;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Create a timeout error
|
|
110
|
-
* @param {String} [message]
|
|
111
|
-
* @extends Error
|
|
112
|
-
*/
|
|
113
|
-
declare function TimeoutError(message?: string | undefined): void;
|
|
114
|
-
declare class TimeoutError {
|
|
115
|
-
/**
|
|
116
|
-
* Create a timeout error
|
|
117
|
-
* @param {String} [message]
|
|
118
|
-
* @extends Error
|
|
119
|
-
*/
|
|
120
|
-
constructor(message?: string | undefined);
|
|
121
|
-
message: string;
|
|
122
|
-
stack: string | undefined;
|
|
123
|
-
name: string;
|
|
124
|
-
}
|
|
125
|
-
export {};
|