@aws/lsp-codewhisperer 0.0.9 → 0.0.11
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 +8 -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 +9 -0
- package/out/language-server/netTransform/converter.js +108 -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 +265 -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/@aws-sdk/middleware-recursion-detection/LICENSE +0 -201
- package/node_modules/@aws-sdk/middleware-recursion-detection/README.md +0 -10
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-cjs/index.js +0 -39
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-es/index.js +0 -34
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-types/index.d.ts +0 -18
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-types/ts3.4/index.d.ts +0 -18
- package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +0 -59
- package/node_modules/@aws-sdk/middleware-user-agent/LICENSE +0 -201
- package/node_modules/@aws-sdk/middleware-user-agent/README.md +0 -4
- package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/configurations.js +0 -10
- package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/constants.js +0 -10
- package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/index.js +0 -5
- package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/user-agent-middleware.js +0 -79
- package/node_modules/@aws-sdk/middleware-user-agent/dist-es/configurations.js +0 -6
- package/node_modules/@aws-sdk/middleware-user-agent/dist-es/constants.js +0 -7
- package/node_modules/@aws-sdk/middleware-user-agent/dist-es/index.js +0 -2
- package/node_modules/@aws-sdk/middleware-user-agent/dist-es/user-agent-middleware.js +0 -72
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/configurations.d.ts +0 -31
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/constants.d.ts +0 -7
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/index.d.ts +0 -2
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/ts3.4/configurations.d.ts +0 -17
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/ts3.4/constants.d.ts +0 -7
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/ts3.4/index.d.ts +0 -2
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/ts3.4/user-agent-middleware.d.ts +0 -20
- package/node_modules/@aws-sdk/middleware-user-agent/dist-types/user-agent-middleware.d.ts +0 -17
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +0 -61
- package/node_modules/@aws-sdk/util-locate-window/LICENSE +0 -201
- package/node_modules/@aws-sdk/util-locate-window/README.md +0 -4
- package/node_modules/@aws-sdk/util-locate-window/dist-cjs/index.js +0 -41
- package/node_modules/@aws-sdk/util-locate-window/dist-es/index.js +0 -10
- package/node_modules/@aws-sdk/util-locate-window/dist-types/index.d.ts +0 -6
- package/node_modules/@aws-sdk/util-locate-window/dist-types/ts3.4/index.d.ts +0 -1
- package/node_modules/@aws-sdk/util-locate-window/package.json +0 -52
- 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/@smithy/util-utf8/LICENSE +0 -201
- package/node_modules/@smithy/util-utf8/README.md +0 -4
- package/node_modules/@smithy/util-utf8/dist-cjs/fromUtf8.browser.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-cjs/fromUtf8.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-cjs/index.js +0 -65
- package/node_modules/@smithy/util-utf8/dist-cjs/toUint8Array.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-cjs/toUtf8.browser.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-cjs/toUtf8.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-es/fromUtf8.browser.js +0 -1
- package/node_modules/@smithy/util-utf8/dist-es/fromUtf8.js +0 -5
- package/node_modules/@smithy/util-utf8/dist-es/index.js +0 -3
- package/node_modules/@smithy/util-utf8/dist-es/toUint8Array.js +0 -10
- package/node_modules/@smithy/util-utf8/dist-es/toUtf8.browser.js +0 -9
- package/node_modules/@smithy/util-utf8/dist-es/toUtf8.js +0 -10
- package/node_modules/@smithy/util-utf8/dist-types/fromUtf8.browser.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/fromUtf8.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/index.d.ts +0 -3
- package/node_modules/@smithy/util-utf8/dist-types/toUint8Array.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/toUtf8.browser.d.ts +0 -7
- package/node_modules/@smithy/util-utf8/dist-types/toUtf8.d.ts +0 -7
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/fromUtf8.browser.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/fromUtf8.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/index.d.ts +0 -3
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/toUint8Array.d.ts +0 -1
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/toUtf8.browser.d.ts +0 -7
- package/node_modules/@smithy/util-utf8/dist-types/ts3.4/toUtf8.d.ts +0 -7
- package/node_modules/@smithy/util-utf8/package.json +0 -66
- 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,1737 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* workerpool.js
|
|
3
|
-
* https://github.com/josdejong/workerpool
|
|
4
|
-
*
|
|
5
|
-
* Offload tasks to a pool of workers on node.js and in the browser.
|
|
6
|
-
*
|
|
7
|
-
* @version 9.1.1
|
|
8
|
-
* @date 2024-04-06
|
|
9
|
-
*
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (C) 2014-2022 Jos de Jong <wjosdejong@gmail.com>
|
|
12
|
-
*
|
|
13
|
-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
14
|
-
* use this file except in compliance with the License. You may obtain a copy
|
|
15
|
-
* of the License at
|
|
16
|
-
*
|
|
17
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
21
|
-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
22
|
-
* License for the specific language governing permissions and limitations under
|
|
23
|
-
* the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
(function (global, factory) {
|
|
27
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
28
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
29
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workerpool = {}));
|
|
30
|
-
})(this, (function (exports) { 'use strict';
|
|
31
|
-
|
|
32
|
-
var src = {};
|
|
33
|
-
|
|
34
|
-
var environment = {exports: {}};
|
|
35
|
-
|
|
36
|
-
(function (module) {
|
|
37
|
-
// source: https://github.com/flexdinesh/browser-or-node
|
|
38
|
-
// source: https://github.com/mozilla/pdf.js/blob/7ea0e40e588864cd938d1836ec61f1928d3877d3/src/shared/util.js#L24
|
|
39
|
-
var isNode = function (nodeProcess) {
|
|
40
|
-
return typeof nodeProcess !== 'undefined' && nodeProcess.versions != null && nodeProcess.versions.node != null && nodeProcess + '' === '[object process]';
|
|
41
|
-
};
|
|
42
|
-
module.exports.isNode = isNode;
|
|
43
|
-
|
|
44
|
-
// determines the JavaScript platform: browser or node
|
|
45
|
-
module.exports.platform = typeof process !== 'undefined' && isNode(process) ? 'node' : 'browser';
|
|
46
|
-
|
|
47
|
-
// determines whether the code is running in main thread or not
|
|
48
|
-
// note that in node.js we have to check both worker_thread and child_process
|
|
49
|
-
var worker_threads = module.exports.platform === 'node' && require('worker_threads');
|
|
50
|
-
module.exports.isMainThread = module.exports.platform === 'node' ? (!worker_threads || worker_threads.isMainThread) && !process.connected : typeof Window !== 'undefined';
|
|
51
|
-
|
|
52
|
-
// determines the number of cpus available
|
|
53
|
-
module.exports.cpus = module.exports.platform === 'browser' ? self.navigator.hardwareConcurrency : require('os').cpus().length;
|
|
54
|
-
})(environment);
|
|
55
|
-
var environmentExports = environment.exports;
|
|
56
|
-
|
|
57
|
-
var _Promise$1 = {};
|
|
58
|
-
|
|
59
|
-
var hasRequired_Promise;
|
|
60
|
-
function require_Promise() {
|
|
61
|
-
if (hasRequired_Promise) return _Promise$1;
|
|
62
|
-
hasRequired_Promise = 1;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Promise
|
|
66
|
-
*
|
|
67
|
-
* Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa <trash@rubaxa.org>
|
|
68
|
-
* @template T
|
|
69
|
-
* @template [E=Error]
|
|
70
|
-
* @param {Function} handler Called as handler(resolve: Function, reject: Function)
|
|
71
|
-
* @param {Promise} [parent] Parent promise for propagation of cancel and timeout
|
|
72
|
-
*/
|
|
73
|
-
function Promise(handler, parent) {
|
|
74
|
-
var me = this;
|
|
75
|
-
if (!(this instanceof Promise)) {
|
|
76
|
-
throw new SyntaxError('Constructor must be called with the new operator');
|
|
77
|
-
}
|
|
78
|
-
if (typeof handler !== 'function') {
|
|
79
|
-
throw new SyntaxError('Function parameter handler(resolve, reject) missing');
|
|
80
|
-
}
|
|
81
|
-
var _onSuccess = [];
|
|
82
|
-
var _onFail = [];
|
|
83
|
-
|
|
84
|
-
// status
|
|
85
|
-
/**
|
|
86
|
-
* @readonly
|
|
87
|
-
*/
|
|
88
|
-
this.resolved = false;
|
|
89
|
-
/**
|
|
90
|
-
* @readonly
|
|
91
|
-
*/
|
|
92
|
-
this.rejected = false;
|
|
93
|
-
/**
|
|
94
|
-
* @readonly
|
|
95
|
-
*/
|
|
96
|
-
this.pending = true;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Process onSuccess and onFail callbacks: add them to the queue.
|
|
100
|
-
* Once the promise is resolved, the function _promise is replace.
|
|
101
|
-
* @param {Function} onSuccess
|
|
102
|
-
* @param {Function} onFail
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
105
|
-
var _process = function (onSuccess, onFail) {
|
|
106
|
-
_onSuccess.push(onSuccess);
|
|
107
|
-
_onFail.push(onFail);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Add an onSuccess callback and optionally an onFail callback to the Promise
|
|
112
|
-
* @template TT
|
|
113
|
-
* @template [TE=never]
|
|
114
|
-
* @param {(r: T) => TT | PromiseLike<TT>} onSuccess
|
|
115
|
-
* @param {(r: E) => TE | PromiseLike<TE>} [onFail]
|
|
116
|
-
* @returns {Promise<TT | TE, any>} promise
|
|
117
|
-
*/
|
|
118
|
-
this.then = function (onSuccess, onFail) {
|
|
119
|
-
return new Promise(function (resolve, reject) {
|
|
120
|
-
var s = onSuccess ? _then(onSuccess, resolve, reject) : resolve;
|
|
121
|
-
var f = onFail ? _then(onFail, resolve, reject) : reject;
|
|
122
|
-
_process(s, f);
|
|
123
|
-
}, me);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Resolve the promise
|
|
128
|
-
* @param {*} result
|
|
129
|
-
* @type {Function}
|
|
130
|
-
*/
|
|
131
|
-
var _resolve = function (result) {
|
|
132
|
-
// update status
|
|
133
|
-
me.resolved = true;
|
|
134
|
-
me.rejected = false;
|
|
135
|
-
me.pending = false;
|
|
136
|
-
_onSuccess.forEach(function (fn) {
|
|
137
|
-
fn(result);
|
|
138
|
-
});
|
|
139
|
-
_process = function (onSuccess, onFail) {
|
|
140
|
-
onSuccess(result);
|
|
141
|
-
};
|
|
142
|
-
_resolve = _reject = function () {};
|
|
143
|
-
return me;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Reject the promise
|
|
148
|
-
* @param {Error} error
|
|
149
|
-
* @type {Function}
|
|
150
|
-
*/
|
|
151
|
-
var _reject = function (error) {
|
|
152
|
-
// update status
|
|
153
|
-
me.resolved = false;
|
|
154
|
-
me.rejected = true;
|
|
155
|
-
me.pending = false;
|
|
156
|
-
_onFail.forEach(function (fn) {
|
|
157
|
-
fn(error);
|
|
158
|
-
});
|
|
159
|
-
_process = function (onSuccess, onFail) {
|
|
160
|
-
onFail(error);
|
|
161
|
-
};
|
|
162
|
-
_resolve = _reject = function () {};
|
|
163
|
-
return me;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Cancel the promise. This will reject the promise with a CancellationError
|
|
168
|
-
* @returns {this} self
|
|
169
|
-
*/
|
|
170
|
-
this.cancel = function () {
|
|
171
|
-
if (parent) {
|
|
172
|
-
parent.cancel();
|
|
173
|
-
} else {
|
|
174
|
-
_reject(new CancellationError());
|
|
175
|
-
}
|
|
176
|
-
return me;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Set a timeout for the promise. If the promise is not resolved within
|
|
181
|
-
* the time, the promise will be cancelled and a TimeoutError is thrown.
|
|
182
|
-
* If the promise is resolved in time, the timeout is removed.
|
|
183
|
-
* @param {number} delay Delay in milliseconds
|
|
184
|
-
* @returns {this} self
|
|
185
|
-
*/
|
|
186
|
-
this.timeout = function (delay) {
|
|
187
|
-
if (parent) {
|
|
188
|
-
parent.timeout(delay);
|
|
189
|
-
} else {
|
|
190
|
-
var timer = setTimeout(function () {
|
|
191
|
-
_reject(new TimeoutError('Promise timed out after ' + delay + ' ms'));
|
|
192
|
-
}, delay);
|
|
193
|
-
me.always(function () {
|
|
194
|
-
clearTimeout(timer);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return me;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
// attach handler passing the resolve and reject functions
|
|
201
|
-
handler(function (result) {
|
|
202
|
-
_resolve(result);
|
|
203
|
-
}, function (error) {
|
|
204
|
-
_reject(error);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Execute given callback, then call resolve/reject based on the returned result
|
|
210
|
-
* @param {Function} callback
|
|
211
|
-
* @param {Function} resolve
|
|
212
|
-
* @param {Function} reject
|
|
213
|
-
* @returns {Function}
|
|
214
|
-
* @private
|
|
215
|
-
*/
|
|
216
|
-
function _then(callback, resolve, reject) {
|
|
217
|
-
return function (result) {
|
|
218
|
-
try {
|
|
219
|
-
var res = callback(result);
|
|
220
|
-
if (res && typeof res.then === 'function' && typeof res['catch'] === 'function') {
|
|
221
|
-
// method returned a promise
|
|
222
|
-
res.then(resolve, reject);
|
|
223
|
-
} else {
|
|
224
|
-
resolve(res);
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {
|
|
227
|
-
reject(error);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Add an onFail callback to the Promise
|
|
234
|
-
* @template TT
|
|
235
|
-
* @param {(error: E) => TT | PromiseLike<TT>} onFail
|
|
236
|
-
* @returns {Promise<T | TT>} promise
|
|
237
|
-
*/
|
|
238
|
-
Promise.prototype['catch'] = function (onFail) {
|
|
239
|
-
return this.then(null, onFail);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
// TODO: add support for Promise.catch(Error, callback)
|
|
243
|
-
// TODO: add support for Promise.catch(Error, Error, callback)
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Execute given callback when the promise either resolves or rejects.
|
|
247
|
-
* @template TT
|
|
248
|
-
* @param {() => Promise<TT>} fn
|
|
249
|
-
* @returns {Promise<TT>} promise
|
|
250
|
-
*/
|
|
251
|
-
Promise.prototype.always = function (fn) {
|
|
252
|
-
return this.then(fn, fn);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Create a promise which resolves when all provided promises are resolved,
|
|
257
|
-
* and fails when any of the promises resolves.
|
|
258
|
-
* @param {Promise[]} promises
|
|
259
|
-
* @returns {Promise<any[], any>} promise
|
|
260
|
-
*/
|
|
261
|
-
Promise.all = function (promises) {
|
|
262
|
-
return new Promise(function (resolve, reject) {
|
|
263
|
-
var remaining = promises.length,
|
|
264
|
-
results = [];
|
|
265
|
-
if (remaining) {
|
|
266
|
-
promises.forEach(function (p, i) {
|
|
267
|
-
p.then(function (result) {
|
|
268
|
-
results[i] = result;
|
|
269
|
-
remaining--;
|
|
270
|
-
if (remaining == 0) {
|
|
271
|
-
resolve(results);
|
|
272
|
-
}
|
|
273
|
-
}, function (error) {
|
|
274
|
-
remaining = 0;
|
|
275
|
-
reject(error);
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
} else {
|
|
279
|
-
resolve(results);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Create a promise resolver
|
|
286
|
-
* @returns {{promise: Promise, resolve: Function, reject: Function}} resolver
|
|
287
|
-
*/
|
|
288
|
-
Promise.defer = function () {
|
|
289
|
-
var resolver = {};
|
|
290
|
-
resolver.promise = new Promise(function (resolve, reject) {
|
|
291
|
-
resolver.resolve = resolve;
|
|
292
|
-
resolver.reject = reject;
|
|
293
|
-
});
|
|
294
|
-
return resolver;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Create a cancellation error
|
|
299
|
-
* @param {String} [message]
|
|
300
|
-
* @extends Error
|
|
301
|
-
*/
|
|
302
|
-
function CancellationError(message) {
|
|
303
|
-
this.message = message || 'promise cancelled';
|
|
304
|
-
this.stack = new Error().stack;
|
|
305
|
-
}
|
|
306
|
-
CancellationError.prototype = new Error();
|
|
307
|
-
CancellationError.prototype.constructor = Error;
|
|
308
|
-
CancellationError.prototype.name = 'CancellationError';
|
|
309
|
-
Promise.CancellationError = CancellationError;
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Create a timeout error
|
|
313
|
-
* @param {String} [message]
|
|
314
|
-
* @extends Error
|
|
315
|
-
*/
|
|
316
|
-
function TimeoutError(message) {
|
|
317
|
-
this.message = message || 'timeout exceeded';
|
|
318
|
-
this.stack = new Error().stack;
|
|
319
|
-
}
|
|
320
|
-
TimeoutError.prototype = new Error();
|
|
321
|
-
TimeoutError.prototype.constructor = Error;
|
|
322
|
-
TimeoutError.prototype.name = 'TimeoutError';
|
|
323
|
-
Promise.TimeoutError = TimeoutError;
|
|
324
|
-
_Promise$1.Promise = Promise;
|
|
325
|
-
return _Promise$1;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
var WorkerHandler = {exports: {}};
|
|
329
|
-
|
|
330
|
-
var validateOptions = {};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Validate that the object only contains known option names
|
|
334
|
-
* - Throws an error when unknown options are detected
|
|
335
|
-
* - Throws an error when some of the allowed options are attached
|
|
336
|
-
* @param {Object | undefined} options
|
|
337
|
-
* @param {string[]} allowedOptionNames
|
|
338
|
-
* @param {string} objectName
|
|
339
|
-
* @retrun {Object} Returns the original options
|
|
340
|
-
*/
|
|
341
|
-
var hasRequiredValidateOptions;
|
|
342
|
-
function requireValidateOptions() {
|
|
343
|
-
if (hasRequiredValidateOptions) return validateOptions;
|
|
344
|
-
hasRequiredValidateOptions = 1;
|
|
345
|
-
validateOptions.validateOptions = function validateOptions(options, allowedOptionNames, objectName) {
|
|
346
|
-
if (!options) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
var optionNames = options ? Object.keys(options) : [];
|
|
350
|
-
|
|
351
|
-
// check for unknown properties
|
|
352
|
-
var unknownOptionName = optionNames.find(optionName => !allowedOptionNames.includes(optionName));
|
|
353
|
-
if (unknownOptionName) {
|
|
354
|
-
throw new Error('Object "' + objectName + '" contains an unknown option "' + unknownOptionName + '"');
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// check for inherited properties which are not present on the object itself
|
|
358
|
-
var illegalOptionName = allowedOptionNames.find(allowedOptionName => {
|
|
359
|
-
return Object.prototype[allowedOptionName] && !optionNames.includes(allowedOptionName);
|
|
360
|
-
});
|
|
361
|
-
if (illegalOptionName) {
|
|
362
|
-
throw new Error('Object "' + objectName + '" contains an inherited option "' + illegalOptionName + '" which is ' + 'not defined in the object itself but in its prototype. Only plain objects are allowed. ' + 'Please remove the option from the prototype or override it with a value "undefined".');
|
|
363
|
-
}
|
|
364
|
-
return options;
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
// source: https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker
|
|
368
|
-
validateOptions.workerOptsNames = ['credentials', 'name', 'type'];
|
|
369
|
-
|
|
370
|
-
// source: https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options
|
|
371
|
-
validateOptions.forkOptsNames = ['cwd', 'detached', 'env', 'execPath', 'execArgv', 'gid', 'serialization', 'signal', 'killSignal', 'silent', 'stdio', 'uid', 'windowsVerbatimArguments', 'timeout'];
|
|
372
|
-
|
|
373
|
-
// source: https://nodejs.org/api/worker_threads.html#new-workerfilename-options
|
|
374
|
-
validateOptions.workerThreadOptsNames = ['argv', 'env', 'eval', 'execArgv', 'stdin', 'stdout', 'stderr', 'workerData', 'trackUnmanagedFds', 'transferList', 'resourceLimits', 'name'];
|
|
375
|
-
return validateOptions;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* embeddedWorker.js contains an embedded version of worker.js.
|
|
380
|
-
* This file is automatically generated,
|
|
381
|
-
* changes made in this file will be overwritten.
|
|
382
|
-
*/
|
|
383
|
-
var embeddedWorker;
|
|
384
|
-
var hasRequiredEmbeddedWorker;
|
|
385
|
-
function requireEmbeddedWorker() {
|
|
386
|
-
if (hasRequiredEmbeddedWorker) return embeddedWorker;
|
|
387
|
-
hasRequiredEmbeddedWorker = 1;
|
|
388
|
-
embeddedWorker = "!function(e,n){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=n():\"function\"==typeof define&&define.amd?define(n):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).worker=n()}(this,(function(){\"use strict\";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,\"default\")?e.default:e}var n={};var t=function(e,n){this.message=e,this.transfer=n};return function(e){var n=t,r={exit:function(){}};if(\"undefined\"!=typeof self&&\"function\"==typeof postMessage&&\"function\"==typeof addEventListener)r.on=function(e,n){addEventListener(e,(function(e){n(e.data)}))},r.send=function(e){postMessage(e)};else{if(\"undefined\"==typeof process)throw new Error(\"Script must be executed as a worker\");var o;try{o=require(\"worker_threads\")}catch(e){if(\"object\"!=typeof e||null===e||\"MODULE_NOT_FOUND\"!==e.code)throw e}if(o&&null!==o.parentPort){var i=o.parentPort;r.send=i.postMessage.bind(i),r.on=i.on.bind(i),r.exit=process.exit.bind(process)}else r.on=process.on.bind(process),r.send=function(e){process.send(e)},r.on(\"disconnect\",(function(){process.exit(1)})),r.exit=process.exit.bind(process)}function s(e){return Object.getOwnPropertyNames(e).reduce((function(n,t){return Object.defineProperty(n,t,{value:e[t],enumerable:!0})}),{})}function d(e){return e&&\"function\"==typeof e.then&&\"function\"==typeof e.catch}r.methods={},r.methods.run=function(e,n){var t=new Function(\"return (\"+e+\").apply(null, arguments);\");return t.apply(t,n)},r.methods.methods=function(){return Object.keys(r.methods)},r.terminationHandler=void 0,r.cleanupAndExit=function(e){var n=function(){r.exit(e)};if(!r.terminationHandler)return n();var t=r.terminationHandler(e);d(t)?t.then(n,n):n()};var u=null;r.on(\"message\",(function(e){if(\"__workerpool-terminate__\"===e)return r.cleanupAndExit(0);try{var t=r.methods[e.method];if(!t)throw new Error('Unknown method \"'+e.method+'\"');u=e.id;var o=t.apply(t,e.params);d(o)?o.then((function(t){t instanceof n?r.send({id:e.id,result:t.message,error:null},t.transfer):r.send({id:e.id,result:t,error:null}),u=null})).catch((function(n){r.send({id:e.id,result:null,error:s(n)}),u=null})):(o instanceof n?r.send({id:e.id,result:o.message,error:null},o.transfer):r.send({id:e.id,result:o,error:null}),u=null)}catch(n){r.send({id:e.id,result:null,error:s(n)})}})),r.register=function(e,n){if(e)for(var t in e)e.hasOwnProperty(t)&&(r.methods[t]=e[t]);n&&(r.terminationHandler=n.onTerminate),r.send(\"ready\")},r.emit=function(e){if(u){if(e instanceof n)return void r.send({id:u,isEvent:!0,payload:e.message},e.transfer);r.send({id:u,isEvent:!0,payload:e})}},e.add=r.register,e.emit=r.emit}(n),e(n)}));\n//# sourceMappingURL=worker.min.js.map\n";
|
|
389
|
-
return embeddedWorker;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
var hasRequiredWorkerHandler;
|
|
393
|
-
function requireWorkerHandler() {
|
|
394
|
-
if (hasRequiredWorkerHandler) return WorkerHandler.exports;
|
|
395
|
-
hasRequiredWorkerHandler = 1;
|
|
396
|
-
var {
|
|
397
|
-
Promise
|
|
398
|
-
} = require_Promise();
|
|
399
|
-
var environment = environmentExports;
|
|
400
|
-
const {
|
|
401
|
-
validateOptions,
|
|
402
|
-
forkOptsNames,
|
|
403
|
-
workerThreadOptsNames,
|
|
404
|
-
workerOptsNames
|
|
405
|
-
} = requireValidateOptions();
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Special message sent by parent which causes a child process worker to terminate itself.
|
|
409
|
-
* Not a "message object"; this string is the entire message.
|
|
410
|
-
*/
|
|
411
|
-
var TERMINATE_METHOD_ID = '__workerpool-terminate__';
|
|
412
|
-
function ensureWorkerThreads() {
|
|
413
|
-
var WorkerThreads = tryRequireWorkerThreads();
|
|
414
|
-
if (!WorkerThreads) {
|
|
415
|
-
throw new Error('WorkerPool: workerType = \'thread\' is not supported, Node >= 11.7.0 required');
|
|
416
|
-
}
|
|
417
|
-
return WorkerThreads;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// check whether Worker is supported by the browser
|
|
421
|
-
function ensureWebWorker() {
|
|
422
|
-
// Workaround for a bug in PhantomJS (Or QtWebkit): https://github.com/ariya/phantomjs/issues/14534
|
|
423
|
-
if (typeof Worker !== 'function' && (typeof Worker !== 'object' || typeof Worker.prototype.constructor !== 'function')) {
|
|
424
|
-
throw new Error('WorkerPool: Web Workers not supported');
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function tryRequireWorkerThreads() {
|
|
428
|
-
try {
|
|
429
|
-
return require('worker_threads');
|
|
430
|
-
} catch (error) {
|
|
431
|
-
if (typeof error === 'object' && error !== null && error.code === 'MODULE_NOT_FOUND') {
|
|
432
|
-
// no worker_threads available (old version of node.js)
|
|
433
|
-
return null;
|
|
434
|
-
} else {
|
|
435
|
-
throw error;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// get the default worker script
|
|
441
|
-
function getDefaultWorker() {
|
|
442
|
-
if (environment.platform === 'browser') {
|
|
443
|
-
// test whether the browser supports all features that we need
|
|
444
|
-
if (typeof Blob === 'undefined') {
|
|
445
|
-
throw new Error('Blob not supported by the browser');
|
|
446
|
-
}
|
|
447
|
-
if (!window.URL || typeof window.URL.createObjectURL !== 'function') {
|
|
448
|
-
throw new Error('URL.createObjectURL not supported by the browser');
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// use embedded worker.js
|
|
452
|
-
var blob = new Blob([requireEmbeddedWorker()], {
|
|
453
|
-
type: 'text/javascript'
|
|
454
|
-
});
|
|
455
|
-
return window.URL.createObjectURL(blob);
|
|
456
|
-
} else {
|
|
457
|
-
// use external worker.js in current directory
|
|
458
|
-
return __dirname + '/worker.js';
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
function setupWorker(script, options) {
|
|
462
|
-
if (options.workerType === 'web') {
|
|
463
|
-
// browser only
|
|
464
|
-
ensureWebWorker();
|
|
465
|
-
return setupBrowserWorker(script, options.workerOpts, Worker);
|
|
466
|
-
} else if (options.workerType === 'thread') {
|
|
467
|
-
// node.js only
|
|
468
|
-
WorkerThreads = ensureWorkerThreads();
|
|
469
|
-
return setupWorkerThreadWorker(script, WorkerThreads, options);
|
|
470
|
-
} else if (options.workerType === 'process' || !options.workerType) {
|
|
471
|
-
// node.js only
|
|
472
|
-
return setupProcessWorker(script, resolveForkOptions(options), require('child_process'));
|
|
473
|
-
} else {
|
|
474
|
-
// options.workerType === 'auto' or undefined
|
|
475
|
-
if (environment.platform === 'browser') {
|
|
476
|
-
ensureWebWorker();
|
|
477
|
-
return setupBrowserWorker(script, options.workerOpts, Worker);
|
|
478
|
-
} else {
|
|
479
|
-
// environment.platform === 'node'
|
|
480
|
-
var WorkerThreads = tryRequireWorkerThreads();
|
|
481
|
-
if (WorkerThreads) {
|
|
482
|
-
return setupWorkerThreadWorker(script, WorkerThreads, options);
|
|
483
|
-
} else {
|
|
484
|
-
return setupProcessWorker(script, resolveForkOptions(options), require('child_process'));
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
function setupBrowserWorker(script, workerOpts, Worker) {
|
|
490
|
-
// validate the options right before creating the worker (not when creating the pool)
|
|
491
|
-
validateOptions(workerOpts, workerOptsNames, 'workerOpts');
|
|
492
|
-
|
|
493
|
-
// create the web worker
|
|
494
|
-
var worker = new Worker(script, workerOpts);
|
|
495
|
-
worker.isBrowserWorker = true;
|
|
496
|
-
// add node.js API to the web worker
|
|
497
|
-
worker.on = function (event, callback) {
|
|
498
|
-
this.addEventListener(event, function (message) {
|
|
499
|
-
callback(message.data);
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
worker.send = function (message, transfer) {
|
|
503
|
-
this.postMessage(message, transfer);
|
|
504
|
-
};
|
|
505
|
-
return worker;
|
|
506
|
-
}
|
|
507
|
-
function setupWorkerThreadWorker(script, WorkerThreads, options) {
|
|
508
|
-
// validate the options right before creating the worker thread (not when creating the pool)
|
|
509
|
-
validateOptions(options?.workerThreadOpts, workerThreadOptsNames, 'workerThreadOpts');
|
|
510
|
-
var worker = new WorkerThreads.Worker(script, {
|
|
511
|
-
stdout: options?.emitStdStreams ?? false,
|
|
512
|
-
// pipe worker.STDOUT to process.STDOUT if not requested
|
|
513
|
-
stderr: options?.emitStdStreams ?? false,
|
|
514
|
-
// pipe worker.STDERR to process.STDERR if not requested
|
|
515
|
-
...options?.workerThreadOpts
|
|
516
|
-
});
|
|
517
|
-
worker.isWorkerThread = true;
|
|
518
|
-
worker.send = function (message, transfer) {
|
|
519
|
-
this.postMessage(message, transfer);
|
|
520
|
-
};
|
|
521
|
-
worker.kill = function () {
|
|
522
|
-
this.terminate();
|
|
523
|
-
return true;
|
|
524
|
-
};
|
|
525
|
-
worker.disconnect = function () {
|
|
526
|
-
this.terminate();
|
|
527
|
-
};
|
|
528
|
-
if (options?.emitStdStreams) {
|
|
529
|
-
worker.stdout.on('data', data => worker.emit("stdout", data));
|
|
530
|
-
worker.stderr.on('data', data => worker.emit("stderr", data));
|
|
531
|
-
}
|
|
532
|
-
return worker;
|
|
533
|
-
}
|
|
534
|
-
function setupProcessWorker(script, options, child_process) {
|
|
535
|
-
// validate the options right before creating the child process (not when creating the pool)
|
|
536
|
-
validateOptions(options.forkOpts, forkOptsNames, 'forkOpts');
|
|
537
|
-
|
|
538
|
-
// no WorkerThreads, fallback to sub-process based workers
|
|
539
|
-
var worker = child_process.fork(script, options.forkArgs, options.forkOpts);
|
|
540
|
-
|
|
541
|
-
// ignore transfer argument since it is not supported by process
|
|
542
|
-
var send = worker.send;
|
|
543
|
-
worker.send = function (message) {
|
|
544
|
-
return send.call(worker, message);
|
|
545
|
-
};
|
|
546
|
-
if (options.emitStdStreams) {
|
|
547
|
-
worker.stdout.on('data', data => worker.emit("stdout", data));
|
|
548
|
-
worker.stderr.on('data', data => worker.emit("stderr", data));
|
|
549
|
-
}
|
|
550
|
-
worker.isChildProcess = true;
|
|
551
|
-
return worker;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// add debug flags to child processes if the node inspector is active
|
|
555
|
-
function resolveForkOptions(opts) {
|
|
556
|
-
opts = opts || {};
|
|
557
|
-
var processExecArgv = process.execArgv.join(' ');
|
|
558
|
-
var inspectorActive = processExecArgv.indexOf('--inspect') !== -1;
|
|
559
|
-
var debugBrk = processExecArgv.indexOf('--debug-brk') !== -1;
|
|
560
|
-
var execArgv = [];
|
|
561
|
-
if (inspectorActive) {
|
|
562
|
-
execArgv.push('--inspect=' + opts.debugPort);
|
|
563
|
-
if (debugBrk) {
|
|
564
|
-
execArgv.push('--debug-brk');
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
process.execArgv.forEach(function (arg) {
|
|
568
|
-
if (arg.indexOf('--max-old-space-size') > -1) {
|
|
569
|
-
execArgv.push(arg);
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
return Object.assign({}, opts, {
|
|
573
|
-
forkArgs: opts.forkArgs,
|
|
574
|
-
forkOpts: Object.assign({}, opts.forkOpts, {
|
|
575
|
-
execArgv: (opts.forkOpts && opts.forkOpts.execArgv || []).concat(execArgv),
|
|
576
|
-
stdio: opts.emitStdStreams ? "pipe" : undefined
|
|
577
|
-
})
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Converts a serialized error to Error
|
|
583
|
-
* @param {Object} obj Error that has been serialized and parsed to object
|
|
584
|
-
* @return {Error} The equivalent Error.
|
|
585
|
-
*/
|
|
586
|
-
function objectToError(obj) {
|
|
587
|
-
var temp = new Error('');
|
|
588
|
-
var props = Object.keys(obj);
|
|
589
|
-
for (var i = 0; i < props.length; i++) {
|
|
590
|
-
temp[props[i]] = obj[props[i]];
|
|
591
|
-
}
|
|
592
|
-
return temp;
|
|
593
|
-
}
|
|
594
|
-
function handleEmittedStdPayload(handler, payload) {
|
|
595
|
-
// TODO: refactor if parallel task execution gets added
|
|
596
|
-
if (Object.keys(handler.processing).length !== 1) {
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
var task = Object.values(handler.processing)[0];
|
|
600
|
-
if (task.options && typeof task.options.on === 'function') {
|
|
601
|
-
task.options.on(payload);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* A WorkerHandler controls a single worker. This worker can be a child process
|
|
607
|
-
* on node.js or a WebWorker in a browser environment.
|
|
608
|
-
* @param {String} [script] If no script is provided, a default worker with a
|
|
609
|
-
* function run will be created.
|
|
610
|
-
* @param {import('./types.js').WorkerPoolOptions} [_options] See docs
|
|
611
|
-
* @constructor
|
|
612
|
-
*/
|
|
613
|
-
function WorkerHandler$1(script, _options) {
|
|
614
|
-
var me = this;
|
|
615
|
-
var options = _options || {};
|
|
616
|
-
this.script = script || getDefaultWorker();
|
|
617
|
-
this.worker = setupWorker(this.script, options);
|
|
618
|
-
this.debugPort = options.debugPort;
|
|
619
|
-
this.forkOpts = options.forkOpts;
|
|
620
|
-
this.forkArgs = options.forkArgs;
|
|
621
|
-
this.workerOpts = options.workerOpts;
|
|
622
|
-
this.workerThreadOpts = options.workerThreadOpts;
|
|
623
|
-
this.workerTerminateTimeout = options.workerTerminateTimeout;
|
|
624
|
-
|
|
625
|
-
// The ready message is only sent if the worker.add method is called (And the default script is not used)
|
|
626
|
-
if (!script) {
|
|
627
|
-
this.worker.ready = true;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
// queue for requests that are received before the worker is ready
|
|
631
|
-
this.requestQueue = [];
|
|
632
|
-
this.worker.on("stdout", function (data) {
|
|
633
|
-
handleEmittedStdPayload(me, {
|
|
634
|
-
"stdout": data.toString()
|
|
635
|
-
});
|
|
636
|
-
});
|
|
637
|
-
this.worker.on("stderr", function (data) {
|
|
638
|
-
handleEmittedStdPayload(me, {
|
|
639
|
-
"stderr": data.toString()
|
|
640
|
-
});
|
|
641
|
-
});
|
|
642
|
-
this.worker.on('message', function (response) {
|
|
643
|
-
if (me.terminated) {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
if (typeof response === 'string' && response === 'ready') {
|
|
647
|
-
me.worker.ready = true;
|
|
648
|
-
dispatchQueuedRequests();
|
|
649
|
-
} else {
|
|
650
|
-
// find the task from the processing queue, and run the tasks callback
|
|
651
|
-
var id = response.id;
|
|
652
|
-
var task = me.processing[id];
|
|
653
|
-
if (task !== undefined) {
|
|
654
|
-
if (response.isEvent) {
|
|
655
|
-
if (task.options && typeof task.options.on === 'function') {
|
|
656
|
-
task.options.on(response.payload);
|
|
657
|
-
}
|
|
658
|
-
} else {
|
|
659
|
-
// remove the task from the queue
|
|
660
|
-
delete me.processing[id];
|
|
661
|
-
|
|
662
|
-
// test if we need to terminate
|
|
663
|
-
if (me.terminating === true) {
|
|
664
|
-
// complete worker termination if all tasks are finished
|
|
665
|
-
me.terminate();
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// resolve the task's promise
|
|
669
|
-
if (response.error) {
|
|
670
|
-
task.resolver.reject(objectToError(response.error));
|
|
671
|
-
} else {
|
|
672
|
-
task.resolver.resolve(response.result);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
// reject all running tasks on worker error
|
|
680
|
-
function onError(error) {
|
|
681
|
-
me.terminated = true;
|
|
682
|
-
for (var id in me.processing) {
|
|
683
|
-
if (me.processing[id] !== undefined) {
|
|
684
|
-
me.processing[id].resolver.reject(error);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
me.processing = Object.create(null);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
// send all queued requests to worker
|
|
691
|
-
function dispatchQueuedRequests() {
|
|
692
|
-
for (const request of me.requestQueue.splice(0)) {
|
|
693
|
-
me.worker.send(request.message, request.transfer);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
var worker = this.worker;
|
|
697
|
-
// listen for worker messages error and exit
|
|
698
|
-
this.worker.on('error', onError);
|
|
699
|
-
this.worker.on('exit', function (exitCode, signalCode) {
|
|
700
|
-
var message = 'Workerpool Worker terminated Unexpectedly\n';
|
|
701
|
-
message += ' exitCode: `' + exitCode + '`\n';
|
|
702
|
-
message += ' signalCode: `' + signalCode + '`\n';
|
|
703
|
-
message += ' workerpool.script: `' + me.script + '`\n';
|
|
704
|
-
message += ' spawnArgs: `' + worker.spawnargs + '`\n';
|
|
705
|
-
message += ' spawnfile: `' + worker.spawnfile + '`\n';
|
|
706
|
-
message += ' stdout: `' + worker.stdout + '`\n';
|
|
707
|
-
message += ' stderr: `' + worker.stderr + '`\n';
|
|
708
|
-
onError(new Error(message));
|
|
709
|
-
});
|
|
710
|
-
this.processing = Object.create(null); // queue with tasks currently in progress
|
|
711
|
-
|
|
712
|
-
this.terminating = false;
|
|
713
|
-
this.terminated = false;
|
|
714
|
-
this.cleaning = false;
|
|
715
|
-
this.terminationHandler = null;
|
|
716
|
-
this.lastId = 0;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Get a list with methods available on the worker.
|
|
721
|
-
* @return {Promise.<String[], Error>} methods
|
|
722
|
-
*/
|
|
723
|
-
WorkerHandler$1.prototype.methods = function () {
|
|
724
|
-
return this.exec('methods');
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Execute a method with given parameters on the worker
|
|
729
|
-
* @param {String} method
|
|
730
|
-
* @param {Array} [params]
|
|
731
|
-
* @param {{resolve: Function, reject: Function}} [resolver]
|
|
732
|
-
* @param {import('./types.js').ExecOptions} [options]
|
|
733
|
-
* @return {Promise.<*, Error>} result
|
|
734
|
-
*/
|
|
735
|
-
WorkerHandler$1.prototype.exec = function (method, params, resolver, options) {
|
|
736
|
-
if (!resolver) {
|
|
737
|
-
resolver = Promise.defer();
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// generate a unique id for the task
|
|
741
|
-
var id = ++this.lastId;
|
|
742
|
-
|
|
743
|
-
// register a new task as being in progress
|
|
744
|
-
this.processing[id] = {
|
|
745
|
-
id: id,
|
|
746
|
-
resolver: resolver,
|
|
747
|
-
options: options
|
|
748
|
-
};
|
|
749
|
-
|
|
750
|
-
// build a JSON-RPC request
|
|
751
|
-
var request = {
|
|
752
|
-
message: {
|
|
753
|
-
id: id,
|
|
754
|
-
method: method,
|
|
755
|
-
params: params
|
|
756
|
-
},
|
|
757
|
-
transfer: options && options.transfer
|
|
758
|
-
};
|
|
759
|
-
if (this.terminated) {
|
|
760
|
-
resolver.reject(new Error('Worker is terminated'));
|
|
761
|
-
} else if (this.worker.ready) {
|
|
762
|
-
// send the request to the worker
|
|
763
|
-
this.worker.send(request.message, request.transfer);
|
|
764
|
-
} else {
|
|
765
|
-
this.requestQueue.push(request);
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// on cancellation, force the worker to terminate
|
|
769
|
-
var me = this;
|
|
770
|
-
return resolver.promise.catch(function (error) {
|
|
771
|
-
if (error instanceof Promise.CancellationError || error instanceof Promise.TimeoutError) {
|
|
772
|
-
// remove this task from the queue. It is already rejected (hence this
|
|
773
|
-
// catch event), and else it will be rejected again when terminating
|
|
774
|
-
delete me.processing[id];
|
|
775
|
-
|
|
776
|
-
// terminate worker
|
|
777
|
-
return me.terminateAndNotify(true).then(function () {
|
|
778
|
-
throw error;
|
|
779
|
-
}, function (err) {
|
|
780
|
-
throw err;
|
|
781
|
-
});
|
|
782
|
-
} else {
|
|
783
|
-
throw error;
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Test whether the worker is processing any tasks or cleaning up before termination.
|
|
790
|
-
* @return {boolean} Returns true if the worker is busy
|
|
791
|
-
*/
|
|
792
|
-
WorkerHandler$1.prototype.busy = function () {
|
|
793
|
-
return this.cleaning || Object.keys(this.processing).length > 0;
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Terminate the worker.
|
|
798
|
-
* @param {boolean} [force=false] If false (default), the worker is terminated
|
|
799
|
-
* after finishing all tasks currently in
|
|
800
|
-
* progress. If true, the worker will be
|
|
801
|
-
* terminated immediately.
|
|
802
|
-
* @param {function} [callback=null] If provided, will be called when process terminates.
|
|
803
|
-
*/
|
|
804
|
-
WorkerHandler$1.prototype.terminate = function (force, callback) {
|
|
805
|
-
var me = this;
|
|
806
|
-
if (force) {
|
|
807
|
-
// cancel all tasks in progress
|
|
808
|
-
for (var id in this.processing) {
|
|
809
|
-
if (this.processing[id] !== undefined) {
|
|
810
|
-
this.processing[id].resolver.reject(new Error('Worker terminated'));
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
this.processing = Object.create(null);
|
|
814
|
-
}
|
|
815
|
-
if (typeof callback === 'function') {
|
|
816
|
-
this.terminationHandler = callback;
|
|
817
|
-
}
|
|
818
|
-
if (!this.busy()) {
|
|
819
|
-
// all tasks are finished. kill the worker
|
|
820
|
-
var cleanup = function (err) {
|
|
821
|
-
me.terminated = true;
|
|
822
|
-
me.cleaning = false;
|
|
823
|
-
if (me.worker != null && me.worker.removeAllListeners) {
|
|
824
|
-
// removeAllListeners is only available for child_process
|
|
825
|
-
me.worker.removeAllListeners('message');
|
|
826
|
-
}
|
|
827
|
-
me.worker = null;
|
|
828
|
-
me.terminating = false;
|
|
829
|
-
if (me.terminationHandler) {
|
|
830
|
-
me.terminationHandler(err, me);
|
|
831
|
-
} else if (err) {
|
|
832
|
-
throw err;
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
if (this.worker) {
|
|
836
|
-
if (typeof this.worker.kill === 'function') {
|
|
837
|
-
if (this.worker.killed) {
|
|
838
|
-
cleanup(new Error('worker already killed!'));
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
// child process and worker threads
|
|
843
|
-
var cleanExitTimeout = setTimeout(function () {
|
|
844
|
-
if (me.worker) {
|
|
845
|
-
me.worker.kill();
|
|
846
|
-
}
|
|
847
|
-
}, this.workerTerminateTimeout);
|
|
848
|
-
this.worker.once('exit', function () {
|
|
849
|
-
clearTimeout(cleanExitTimeout);
|
|
850
|
-
if (me.worker) {
|
|
851
|
-
me.worker.killed = true;
|
|
852
|
-
}
|
|
853
|
-
cleanup();
|
|
854
|
-
});
|
|
855
|
-
if (this.worker.ready) {
|
|
856
|
-
this.worker.send(TERMINATE_METHOD_ID);
|
|
857
|
-
} else {
|
|
858
|
-
this.requestQueue.push({
|
|
859
|
-
message: TERMINATE_METHOD_ID
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// mark that the worker is cleaning up resources
|
|
864
|
-
// to prevent new tasks from being executed
|
|
865
|
-
this.cleaning = true;
|
|
866
|
-
return;
|
|
867
|
-
} else if (typeof this.worker.terminate === 'function') {
|
|
868
|
-
this.worker.terminate(); // web worker
|
|
869
|
-
this.worker.killed = true;
|
|
870
|
-
} else {
|
|
871
|
-
throw new Error('Failed to terminate worker');
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
cleanup();
|
|
875
|
-
} else {
|
|
876
|
-
// we can't terminate immediately, there are still tasks being executed
|
|
877
|
-
this.terminating = true;
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
/**
|
|
882
|
-
* Terminate the worker, returning a Promise that resolves when the termination has been done.
|
|
883
|
-
* @param {boolean} [force=false] If false (default), the worker is terminated
|
|
884
|
-
* after finishing all tasks currently in
|
|
885
|
-
* progress. If true, the worker will be
|
|
886
|
-
* terminated immediately.
|
|
887
|
-
* @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected
|
|
888
|
-
* after timeout if worker process has not been terminated.
|
|
889
|
-
* @return {Promise.<WorkerHandler, Error>}
|
|
890
|
-
*/
|
|
891
|
-
WorkerHandler$1.prototype.terminateAndNotify = function (force, timeout) {
|
|
892
|
-
var resolver = Promise.defer();
|
|
893
|
-
if (timeout) {
|
|
894
|
-
resolver.promise.timeout(timeout);
|
|
895
|
-
}
|
|
896
|
-
this.terminate(force, function (err, worker) {
|
|
897
|
-
if (err) {
|
|
898
|
-
resolver.reject(err);
|
|
899
|
-
} else {
|
|
900
|
-
resolver.resolve(worker);
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
return resolver.promise;
|
|
904
|
-
};
|
|
905
|
-
WorkerHandler.exports = WorkerHandler$1;
|
|
906
|
-
WorkerHandler.exports._tryRequireWorkerThreads = tryRequireWorkerThreads;
|
|
907
|
-
WorkerHandler.exports._setupProcessWorker = setupProcessWorker;
|
|
908
|
-
WorkerHandler.exports._setupBrowserWorker = setupBrowserWorker;
|
|
909
|
-
WorkerHandler.exports._setupWorkerThreadWorker = setupWorkerThreadWorker;
|
|
910
|
-
WorkerHandler.exports.ensureWorkerThreads = ensureWorkerThreads;
|
|
911
|
-
return WorkerHandler.exports;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
var debugPortAllocator;
|
|
915
|
-
var hasRequiredDebugPortAllocator;
|
|
916
|
-
function requireDebugPortAllocator() {
|
|
917
|
-
if (hasRequiredDebugPortAllocator) return debugPortAllocator;
|
|
918
|
-
hasRequiredDebugPortAllocator = 1;
|
|
919
|
-
var MAX_PORTS = 65535;
|
|
920
|
-
debugPortAllocator = DebugPortAllocator;
|
|
921
|
-
function DebugPortAllocator() {
|
|
922
|
-
this.ports = Object.create(null);
|
|
923
|
-
this.length = 0;
|
|
924
|
-
}
|
|
925
|
-
DebugPortAllocator.prototype.nextAvailableStartingAt = function (starting) {
|
|
926
|
-
while (this.ports[starting] === true) {
|
|
927
|
-
starting++;
|
|
928
|
-
}
|
|
929
|
-
if (starting >= MAX_PORTS) {
|
|
930
|
-
throw new Error('WorkerPool debug port limit reached: ' + starting + '>= ' + MAX_PORTS);
|
|
931
|
-
}
|
|
932
|
-
this.ports[starting] = true;
|
|
933
|
-
this.length++;
|
|
934
|
-
return starting;
|
|
935
|
-
};
|
|
936
|
-
DebugPortAllocator.prototype.releasePort = function (port) {
|
|
937
|
-
delete this.ports[port];
|
|
938
|
-
this.length--;
|
|
939
|
-
};
|
|
940
|
-
return debugPortAllocator;
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
var Pool_1;
|
|
944
|
-
var hasRequiredPool;
|
|
945
|
-
function requirePool() {
|
|
946
|
-
if (hasRequiredPool) return Pool_1;
|
|
947
|
-
hasRequiredPool = 1;
|
|
948
|
-
var {
|
|
949
|
-
Promise
|
|
950
|
-
} = require_Promise();
|
|
951
|
-
var WorkerHandler = requireWorkerHandler();
|
|
952
|
-
var environment = environmentExports;
|
|
953
|
-
var DebugPortAllocator = requireDebugPortAllocator();
|
|
954
|
-
var DEBUG_PORT_ALLOCATOR = new DebugPortAllocator();
|
|
955
|
-
/**
|
|
956
|
-
* A pool to manage workers, which can be created using the function workerpool.pool.
|
|
957
|
-
*
|
|
958
|
-
* @param {String} [script] Optional worker script
|
|
959
|
-
* @param {import('./types.js').WorkerPoolOptions} [options] See docs
|
|
960
|
-
* @constructor
|
|
961
|
-
*/
|
|
962
|
-
function Pool(script, options) {
|
|
963
|
-
if (typeof script === 'string') {
|
|
964
|
-
/** @readonly */
|
|
965
|
-
this.script = script || null;
|
|
966
|
-
} else {
|
|
967
|
-
this.script = null;
|
|
968
|
-
options = script;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
/** @private */
|
|
972
|
-
this.workers = []; // queue with all workers
|
|
973
|
-
/** @private */
|
|
974
|
-
this.tasks = []; // queue with tasks awaiting execution
|
|
975
|
-
|
|
976
|
-
options = options || {};
|
|
977
|
-
|
|
978
|
-
/** @readonly */
|
|
979
|
-
this.forkArgs = Object.freeze(options.forkArgs || []);
|
|
980
|
-
/** @readonly */
|
|
981
|
-
this.forkOpts = Object.freeze(options.forkOpts || {});
|
|
982
|
-
/** @readonly */
|
|
983
|
-
this.workerOpts = Object.freeze(options.workerOpts || {});
|
|
984
|
-
/** @readonly */
|
|
985
|
-
this.workerThreadOpts = Object.freeze(options.workerThreadOpts || {});
|
|
986
|
-
/** @private */
|
|
987
|
-
this.debugPortStart = options.debugPortStart || 43210;
|
|
988
|
-
/** @readonly @deprecated */
|
|
989
|
-
this.nodeWorker = options.nodeWorker;
|
|
990
|
-
/** @readonly
|
|
991
|
-
* @type {'auto' | 'web' | 'process' | 'thread'}
|
|
992
|
-
*/
|
|
993
|
-
this.workerType = options.workerType || options.nodeWorker || 'auto';
|
|
994
|
-
/** @readonly */
|
|
995
|
-
this.maxQueueSize = options.maxQueueSize || Infinity;
|
|
996
|
-
/** @readonly */
|
|
997
|
-
this.workerTerminateTimeout = options.workerTerminateTimeout || 1000;
|
|
998
|
-
|
|
999
|
-
/** @readonly */
|
|
1000
|
-
this.onCreateWorker = options.onCreateWorker || (() => null);
|
|
1001
|
-
/** @readonly */
|
|
1002
|
-
this.onTerminateWorker = options.onTerminateWorker || (() => null);
|
|
1003
|
-
|
|
1004
|
-
/** @readonly */
|
|
1005
|
-
this.emitStdStreams = options.emitStdStreams || false;
|
|
1006
|
-
|
|
1007
|
-
// configuration
|
|
1008
|
-
if (options && 'maxWorkers' in options) {
|
|
1009
|
-
validateMaxWorkers(options.maxWorkers);
|
|
1010
|
-
/** @readonly */
|
|
1011
|
-
this.maxWorkers = options.maxWorkers;
|
|
1012
|
-
} else {
|
|
1013
|
-
this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);
|
|
1014
|
-
}
|
|
1015
|
-
if (options && 'minWorkers' in options) {
|
|
1016
|
-
if (options.minWorkers === 'max') {
|
|
1017
|
-
/** @readonly */
|
|
1018
|
-
this.minWorkers = this.maxWorkers;
|
|
1019
|
-
} else {
|
|
1020
|
-
validateMinWorkers(options.minWorkers);
|
|
1021
|
-
this.minWorkers = options.minWorkers;
|
|
1022
|
-
this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers); // in case minWorkers is higher than maxWorkers
|
|
1023
|
-
}
|
|
1024
|
-
this._ensureMinWorkers();
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
/** @private */
|
|
1028
|
-
this._boundNext = this._next.bind(this);
|
|
1029
|
-
if (this.workerType === 'thread') {
|
|
1030
|
-
WorkerHandler.ensureWorkerThreads();
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* Execute a function on a worker.
|
|
1036
|
-
*
|
|
1037
|
-
* Example usage:
|
|
1038
|
-
*
|
|
1039
|
-
* var pool = new Pool()
|
|
1040
|
-
*
|
|
1041
|
-
* // call a function available on the worker
|
|
1042
|
-
* pool.exec('fibonacci', [6])
|
|
1043
|
-
*
|
|
1044
|
-
* // offload a function
|
|
1045
|
-
* function add(a, b) {
|
|
1046
|
-
* return a + b
|
|
1047
|
-
* };
|
|
1048
|
-
* pool.exec(add, [2, 4])
|
|
1049
|
-
* .then(function (result) {
|
|
1050
|
-
* console.log(result); // outputs 6
|
|
1051
|
-
* })
|
|
1052
|
-
* .catch(function(error) {
|
|
1053
|
-
* console.log(error);
|
|
1054
|
-
* });
|
|
1055
|
-
* @template { (...args: any[]) => any } T
|
|
1056
|
-
* @param {String | T} method Function name or function.
|
|
1057
|
-
* If `method` is a string, the corresponding
|
|
1058
|
-
* method on the worker will be executed
|
|
1059
|
-
* If `method` is a Function, the function
|
|
1060
|
-
* will be stringified and executed via the
|
|
1061
|
-
* workers built-in function `run(fn, args)`.
|
|
1062
|
-
* @param {Parameters<T> | null} [params] Function arguments applied when calling the function
|
|
1063
|
-
* @param {import('./types.js').ExecOptions} [options] Options
|
|
1064
|
-
* @return {Promise<ReturnType<T>>}
|
|
1065
|
-
*/
|
|
1066
|
-
Pool.prototype.exec = function (method, params, options) {
|
|
1067
|
-
// validate type of arguments
|
|
1068
|
-
if (params && !Array.isArray(params)) {
|
|
1069
|
-
throw new TypeError('Array expected as argument "params"');
|
|
1070
|
-
}
|
|
1071
|
-
if (typeof method === 'string') {
|
|
1072
|
-
var resolver = Promise.defer();
|
|
1073
|
-
if (this.tasks.length >= this.maxQueueSize) {
|
|
1074
|
-
throw new Error('Max queue size of ' + this.maxQueueSize + ' reached');
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// add a new task to the queue
|
|
1078
|
-
var tasks = this.tasks;
|
|
1079
|
-
var task = {
|
|
1080
|
-
method: method,
|
|
1081
|
-
params: params,
|
|
1082
|
-
resolver: resolver,
|
|
1083
|
-
timeout: null,
|
|
1084
|
-
options: options
|
|
1085
|
-
};
|
|
1086
|
-
tasks.push(task);
|
|
1087
|
-
|
|
1088
|
-
// replace the timeout method of the Promise with our own,
|
|
1089
|
-
// which starts the timer as soon as the task is actually started
|
|
1090
|
-
var originalTimeout = resolver.promise.timeout;
|
|
1091
|
-
resolver.promise.timeout = function timeout(delay) {
|
|
1092
|
-
if (tasks.indexOf(task) !== -1) {
|
|
1093
|
-
// task is still queued -> start the timer later on
|
|
1094
|
-
task.timeout = delay;
|
|
1095
|
-
return resolver.promise;
|
|
1096
|
-
} else {
|
|
1097
|
-
// task is already being executed -> start timer immediately
|
|
1098
|
-
return originalTimeout.call(resolver.promise, delay);
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
|
-
// trigger task execution
|
|
1103
|
-
this._next();
|
|
1104
|
-
return resolver.promise;
|
|
1105
|
-
} else if (typeof method === 'function') {
|
|
1106
|
-
// send stringified function and function arguments to worker
|
|
1107
|
-
return this.exec('run', [String(method), params], options);
|
|
1108
|
-
} else {
|
|
1109
|
-
throw new TypeError('Function or string expected as argument "method"');
|
|
1110
|
-
}
|
|
1111
|
-
};
|
|
1112
|
-
|
|
1113
|
-
/**
|
|
1114
|
-
* Create a proxy for current worker. Returns an object containing all
|
|
1115
|
-
* methods available on the worker. All methods return promises resolving the methods result.
|
|
1116
|
-
* @template { { [k: string]: (...args: any[]) => any } } T
|
|
1117
|
-
* @return {Promise<import('./types.js').Proxy<T>, Error>} Returns a promise which resolves with a proxy object
|
|
1118
|
-
*/
|
|
1119
|
-
Pool.prototype.proxy = function () {
|
|
1120
|
-
if (arguments.length > 0) {
|
|
1121
|
-
throw new Error('No arguments expected');
|
|
1122
|
-
}
|
|
1123
|
-
var pool = this;
|
|
1124
|
-
return this.exec('methods').then(function (methods) {
|
|
1125
|
-
var proxy = {};
|
|
1126
|
-
methods.forEach(function (method) {
|
|
1127
|
-
proxy[method] = function () {
|
|
1128
|
-
return pool.exec(method, Array.prototype.slice.call(arguments));
|
|
1129
|
-
};
|
|
1130
|
-
});
|
|
1131
|
-
return proxy;
|
|
1132
|
-
});
|
|
1133
|
-
};
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
* Creates new array with the results of calling a provided callback function
|
|
1137
|
-
* on every element in this array.
|
|
1138
|
-
* @param {Array} array
|
|
1139
|
-
* @param {function} callback Function taking two arguments:
|
|
1140
|
-
* `callback(currentValue, index)`
|
|
1141
|
-
* @return {Promise.<Array>} Returns a promise which resolves with an Array
|
|
1142
|
-
* containing the results of the callback function
|
|
1143
|
-
* executed for each of the array elements.
|
|
1144
|
-
*/
|
|
1145
|
-
/* TODO: implement map
|
|
1146
|
-
Pool.prototype.map = function (array, callback) {
|
|
1147
|
-
};
|
|
1148
|
-
*/
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
* Grab the first task from the queue, find a free worker, and assign the
|
|
1152
|
-
* worker to the task.
|
|
1153
|
-
* @private
|
|
1154
|
-
*/
|
|
1155
|
-
Pool.prototype._next = function () {
|
|
1156
|
-
if (this.tasks.length > 0) {
|
|
1157
|
-
// there are tasks in the queue
|
|
1158
|
-
|
|
1159
|
-
// find an available worker
|
|
1160
|
-
var worker = this._getWorker();
|
|
1161
|
-
if (worker) {
|
|
1162
|
-
// get the first task from the queue
|
|
1163
|
-
var me = this;
|
|
1164
|
-
var task = this.tasks.shift();
|
|
1165
|
-
|
|
1166
|
-
// check if the task is still pending (and not cancelled -> promise rejected)
|
|
1167
|
-
if (task.resolver.promise.pending) {
|
|
1168
|
-
// send the request to the worker
|
|
1169
|
-
var promise = worker.exec(task.method, task.params, task.resolver, task.options).then(me._boundNext).catch(function () {
|
|
1170
|
-
// if the worker crashed and terminated, remove it from the pool
|
|
1171
|
-
if (worker.terminated) {
|
|
1172
|
-
return me._removeWorker(worker);
|
|
1173
|
-
}
|
|
1174
|
-
}).then(function () {
|
|
1175
|
-
me._next(); // trigger next task in the queue
|
|
1176
|
-
});
|
|
1177
|
-
|
|
1178
|
-
// start queued timer now
|
|
1179
|
-
if (typeof task.timeout === 'number') {
|
|
1180
|
-
promise.timeout(task.timeout);
|
|
1181
|
-
}
|
|
1182
|
-
} else {
|
|
1183
|
-
// The task taken was already complete (either rejected or resolved), so just trigger next task in the queue
|
|
1184
|
-
me._next();
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
|
|
1190
|
-
/**
|
|
1191
|
-
* Get an available worker. If no worker is available and the maximum number
|
|
1192
|
-
* of workers isn't yet reached, a new worker will be created and returned.
|
|
1193
|
-
* If no worker is available and the maximum number of workers is reached,
|
|
1194
|
-
* null will be returned.
|
|
1195
|
-
*
|
|
1196
|
-
* @return {WorkerHandler | null} worker
|
|
1197
|
-
* @private
|
|
1198
|
-
*/
|
|
1199
|
-
Pool.prototype._getWorker = function () {
|
|
1200
|
-
// find a non-busy worker
|
|
1201
|
-
var workers = this.workers;
|
|
1202
|
-
for (var i = 0; i < workers.length; i++) {
|
|
1203
|
-
var worker = workers[i];
|
|
1204
|
-
if (worker.busy() === false) {
|
|
1205
|
-
return worker;
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
if (workers.length < this.maxWorkers) {
|
|
1209
|
-
// create a new worker
|
|
1210
|
-
worker = this._createWorkerHandler();
|
|
1211
|
-
workers.push(worker);
|
|
1212
|
-
return worker;
|
|
1213
|
-
}
|
|
1214
|
-
return null;
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* Remove a worker from the pool.
|
|
1219
|
-
* Attempts to terminate worker if not already terminated, and ensures the minimum
|
|
1220
|
-
* pool size is met.
|
|
1221
|
-
* @param {WorkerHandler} worker
|
|
1222
|
-
* @return {Promise<WorkerHandler>}
|
|
1223
|
-
* @private
|
|
1224
|
-
*/
|
|
1225
|
-
Pool.prototype._removeWorker = function (worker) {
|
|
1226
|
-
var me = this;
|
|
1227
|
-
DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
|
|
1228
|
-
// _removeWorker will call this, but we need it to be removed synchronously
|
|
1229
|
-
this._removeWorkerFromList(worker);
|
|
1230
|
-
// If minWorkers set, spin up new workers to replace the crashed ones
|
|
1231
|
-
this._ensureMinWorkers();
|
|
1232
|
-
// terminate the worker (if not already terminated)
|
|
1233
|
-
return new Promise(function (resolve, reject) {
|
|
1234
|
-
worker.terminate(false, function (err) {
|
|
1235
|
-
me.onTerminateWorker({
|
|
1236
|
-
forkArgs: worker.forkArgs,
|
|
1237
|
-
forkOpts: worker.forkOpts,
|
|
1238
|
-
workerThreadOpts: worker.workerThreadOpts,
|
|
1239
|
-
script: worker.script
|
|
1240
|
-
});
|
|
1241
|
-
if (err) {
|
|
1242
|
-
reject(err);
|
|
1243
|
-
} else {
|
|
1244
|
-
resolve(worker);
|
|
1245
|
-
}
|
|
1246
|
-
});
|
|
1247
|
-
});
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* Remove a worker from the pool list.
|
|
1252
|
-
* @param {WorkerHandler} worker
|
|
1253
|
-
* @private
|
|
1254
|
-
*/
|
|
1255
|
-
Pool.prototype._removeWorkerFromList = function (worker) {
|
|
1256
|
-
// remove from the list with workers
|
|
1257
|
-
var index = this.workers.indexOf(worker);
|
|
1258
|
-
if (index !== -1) {
|
|
1259
|
-
this.workers.splice(index, 1);
|
|
1260
|
-
}
|
|
1261
|
-
};
|
|
1262
|
-
|
|
1263
|
-
/**
|
|
1264
|
-
* Close all active workers. Tasks currently being executed will be finished first.
|
|
1265
|
-
* @param {boolean} [force=false] If false (default), the workers are terminated
|
|
1266
|
-
* after finishing all tasks currently in
|
|
1267
|
-
* progress. If true, the workers will be
|
|
1268
|
-
* terminated immediately.
|
|
1269
|
-
* @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected
|
|
1270
|
-
* after timeout if worker process has not been terminated.
|
|
1271
|
-
* @return {Promise.<void, Error>}
|
|
1272
|
-
*/
|
|
1273
|
-
Pool.prototype.terminate = function (force, timeout) {
|
|
1274
|
-
var me = this;
|
|
1275
|
-
|
|
1276
|
-
// cancel any pending tasks
|
|
1277
|
-
this.tasks.forEach(function (task) {
|
|
1278
|
-
task.resolver.reject(new Error('Pool terminated'));
|
|
1279
|
-
});
|
|
1280
|
-
this.tasks.length = 0;
|
|
1281
|
-
var f = function (worker) {
|
|
1282
|
-
DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
|
|
1283
|
-
this._removeWorkerFromList(worker);
|
|
1284
|
-
};
|
|
1285
|
-
var removeWorker = f.bind(this);
|
|
1286
|
-
var promises = [];
|
|
1287
|
-
var workers = this.workers.slice();
|
|
1288
|
-
workers.forEach(function (worker) {
|
|
1289
|
-
var termPromise = worker.terminateAndNotify(force, timeout).then(removeWorker).always(function () {
|
|
1290
|
-
me.onTerminateWorker({
|
|
1291
|
-
forkArgs: worker.forkArgs,
|
|
1292
|
-
forkOpts: worker.forkOpts,
|
|
1293
|
-
workerThreadOpts: worker.workerThreadOpts,
|
|
1294
|
-
script: worker.script
|
|
1295
|
-
});
|
|
1296
|
-
});
|
|
1297
|
-
promises.push(termPromise);
|
|
1298
|
-
});
|
|
1299
|
-
return Promise.all(promises);
|
|
1300
|
-
};
|
|
1301
|
-
|
|
1302
|
-
/**
|
|
1303
|
-
* Retrieve statistics on tasks and workers.
|
|
1304
|
-
* @return {{totalWorkers: number, busyWorkers: number, idleWorkers: number, pendingTasks: number, activeTasks: number}} Returns an object with statistics
|
|
1305
|
-
*/
|
|
1306
|
-
Pool.prototype.stats = function () {
|
|
1307
|
-
var totalWorkers = this.workers.length;
|
|
1308
|
-
var busyWorkers = this.workers.filter(function (worker) {
|
|
1309
|
-
return worker.busy();
|
|
1310
|
-
}).length;
|
|
1311
|
-
return {
|
|
1312
|
-
totalWorkers: totalWorkers,
|
|
1313
|
-
busyWorkers: busyWorkers,
|
|
1314
|
-
idleWorkers: totalWorkers - busyWorkers,
|
|
1315
|
-
pendingTasks: this.tasks.length,
|
|
1316
|
-
activeTasks: busyWorkers
|
|
1317
|
-
};
|
|
1318
|
-
};
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* Ensures that a minimum of minWorkers is up and running
|
|
1322
|
-
* @private
|
|
1323
|
-
*/
|
|
1324
|
-
Pool.prototype._ensureMinWorkers = function () {
|
|
1325
|
-
if (this.minWorkers) {
|
|
1326
|
-
for (var i = this.workers.length; i < this.minWorkers; i++) {
|
|
1327
|
-
this.workers.push(this._createWorkerHandler());
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
|
|
1332
|
-
/**
|
|
1333
|
-
* Helper function to create a new WorkerHandler and pass all options.
|
|
1334
|
-
* @return {WorkerHandler}
|
|
1335
|
-
* @private
|
|
1336
|
-
*/
|
|
1337
|
-
Pool.prototype._createWorkerHandler = function () {
|
|
1338
|
-
const overriddenParams = this.onCreateWorker({
|
|
1339
|
-
forkArgs: this.forkArgs,
|
|
1340
|
-
forkOpts: this.forkOpts,
|
|
1341
|
-
workerOpts: this.workerOpts,
|
|
1342
|
-
workerThreadOpts: this.workerThreadOpts,
|
|
1343
|
-
script: this.script
|
|
1344
|
-
}) || {};
|
|
1345
|
-
return new WorkerHandler(overriddenParams.script || this.script, {
|
|
1346
|
-
forkArgs: overriddenParams.forkArgs || this.forkArgs,
|
|
1347
|
-
forkOpts: overriddenParams.forkOpts || this.forkOpts,
|
|
1348
|
-
workerOpts: overriddenParams.workerOpts || this.workerOpts,
|
|
1349
|
-
workerThreadOpts: overriddenParams.workerThreadOpts || this.workerThreadOpts,
|
|
1350
|
-
debugPort: DEBUG_PORT_ALLOCATOR.nextAvailableStartingAt(this.debugPortStart),
|
|
1351
|
-
workerType: this.workerType,
|
|
1352
|
-
workerTerminateTimeout: this.workerTerminateTimeout,
|
|
1353
|
-
emitStdStreams: this.emitStdStreams
|
|
1354
|
-
});
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
|
-
/**
|
|
1358
|
-
* Ensure that the maxWorkers option is an integer >= 1
|
|
1359
|
-
* @param {*} maxWorkers
|
|
1360
|
-
* @returns {boolean} returns true maxWorkers has a valid value
|
|
1361
|
-
*/
|
|
1362
|
-
function validateMaxWorkers(maxWorkers) {
|
|
1363
|
-
if (!isNumber(maxWorkers) || !isInteger(maxWorkers) || maxWorkers < 1) {
|
|
1364
|
-
throw new TypeError('Option maxWorkers must be an integer number >= 1');
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
/**
|
|
1369
|
-
* Ensure that the minWorkers option is an integer >= 0
|
|
1370
|
-
* @param {*} minWorkers
|
|
1371
|
-
* @returns {boolean} returns true when minWorkers has a valid value
|
|
1372
|
-
*/
|
|
1373
|
-
function validateMinWorkers(minWorkers) {
|
|
1374
|
-
if (!isNumber(minWorkers) || !isInteger(minWorkers) || minWorkers < 0) {
|
|
1375
|
-
throw new TypeError('Option minWorkers must be an integer number >= 0');
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
/**
|
|
1380
|
-
* Test whether a variable is a number
|
|
1381
|
-
* @param {*} value
|
|
1382
|
-
* @returns {boolean} returns true when value is a number
|
|
1383
|
-
*/
|
|
1384
|
-
function isNumber(value) {
|
|
1385
|
-
return typeof value === 'number';
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
/**
|
|
1389
|
-
* Test whether a number is an integer
|
|
1390
|
-
* @param {number} value
|
|
1391
|
-
* @returns {boolean} Returns true if value is an integer
|
|
1392
|
-
*/
|
|
1393
|
-
function isInteger(value) {
|
|
1394
|
-
return Math.round(value) == value;
|
|
1395
|
-
}
|
|
1396
|
-
Pool_1 = Pool;
|
|
1397
|
-
return Pool_1;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
var worker$1 = {};
|
|
1401
|
-
|
|
1402
|
-
/**
|
|
1403
|
-
* The helper class for transferring data from the worker to the main thread.
|
|
1404
|
-
*
|
|
1405
|
-
* @param {Object} message The object to deliver to the main thread.
|
|
1406
|
-
* @param {Object[]} transfer An array of transferable Objects to transfer ownership of.
|
|
1407
|
-
*/
|
|
1408
|
-
var transfer;
|
|
1409
|
-
var hasRequiredTransfer;
|
|
1410
|
-
function requireTransfer() {
|
|
1411
|
-
if (hasRequiredTransfer) return transfer;
|
|
1412
|
-
hasRequiredTransfer = 1;
|
|
1413
|
-
function Transfer(message, transfer) {
|
|
1414
|
-
this.message = message;
|
|
1415
|
-
this.transfer = transfer;
|
|
1416
|
-
}
|
|
1417
|
-
transfer = Transfer;
|
|
1418
|
-
return transfer;
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
/**
|
|
1422
|
-
* worker must be started as a child process or a web worker.
|
|
1423
|
-
* It listens for RPC messages from the parent process.
|
|
1424
|
-
*/
|
|
1425
|
-
var hasRequiredWorker;
|
|
1426
|
-
function requireWorker() {
|
|
1427
|
-
if (hasRequiredWorker) return worker$1;
|
|
1428
|
-
hasRequiredWorker = 1;
|
|
1429
|
-
(function (exports) {
|
|
1430
|
-
var Transfer = requireTransfer();
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
* Special message sent by parent which causes the worker to terminate itself.
|
|
1434
|
-
* Not a "message object"; this string is the entire message.
|
|
1435
|
-
*/
|
|
1436
|
-
var TERMINATE_METHOD_ID = '__workerpool-terminate__';
|
|
1437
|
-
|
|
1438
|
-
// var nodeOSPlatform = require('./environment').nodeOSPlatform;
|
|
1439
|
-
|
|
1440
|
-
// create a worker API for sending and receiving messages which works both on
|
|
1441
|
-
// node.js and in the browser
|
|
1442
|
-
var worker = {
|
|
1443
|
-
exit: function () {}
|
|
1444
|
-
};
|
|
1445
|
-
if (typeof self !== 'undefined' && typeof postMessage === 'function' && typeof addEventListener === 'function') {
|
|
1446
|
-
// worker in the browser
|
|
1447
|
-
worker.on = function (event, callback) {
|
|
1448
|
-
addEventListener(event, function (message) {
|
|
1449
|
-
callback(message.data);
|
|
1450
|
-
});
|
|
1451
|
-
};
|
|
1452
|
-
worker.send = function (message) {
|
|
1453
|
-
postMessage(message);
|
|
1454
|
-
};
|
|
1455
|
-
} else if (typeof process !== 'undefined') {
|
|
1456
|
-
// node.js
|
|
1457
|
-
|
|
1458
|
-
var WorkerThreads;
|
|
1459
|
-
try {
|
|
1460
|
-
WorkerThreads = require('worker_threads');
|
|
1461
|
-
} catch (error) {
|
|
1462
|
-
if (typeof error === 'object' && error !== null && error.code === 'MODULE_NOT_FOUND') ; else {
|
|
1463
|
-
throw error;
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
if (WorkerThreads && /* if there is a parentPort, we are in a WorkerThread */
|
|
1467
|
-
WorkerThreads.parentPort !== null) {
|
|
1468
|
-
var parentPort = WorkerThreads.parentPort;
|
|
1469
|
-
worker.send = parentPort.postMessage.bind(parentPort);
|
|
1470
|
-
worker.on = parentPort.on.bind(parentPort);
|
|
1471
|
-
worker.exit = process.exit.bind(process);
|
|
1472
|
-
} else {
|
|
1473
|
-
worker.on = process.on.bind(process);
|
|
1474
|
-
// ignore transfer argument since it is not supported by process
|
|
1475
|
-
worker.send = function (message) {
|
|
1476
|
-
process.send(message);
|
|
1477
|
-
};
|
|
1478
|
-
// register disconnect handler only for subprocess worker to exit when parent is killed unexpectedly
|
|
1479
|
-
worker.on('disconnect', function () {
|
|
1480
|
-
process.exit(1);
|
|
1481
|
-
});
|
|
1482
|
-
worker.exit = process.exit.bind(process);
|
|
1483
|
-
}
|
|
1484
|
-
} else {
|
|
1485
|
-
throw new Error('Script must be executed as a worker');
|
|
1486
|
-
}
|
|
1487
|
-
function convertError(error) {
|
|
1488
|
-
return Object.getOwnPropertyNames(error).reduce(function (product, name) {
|
|
1489
|
-
return Object.defineProperty(product, name, {
|
|
1490
|
-
value: error[name],
|
|
1491
|
-
enumerable: true
|
|
1492
|
-
});
|
|
1493
|
-
}, {});
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
/**
|
|
1497
|
-
* Test whether a value is a Promise via duck typing.
|
|
1498
|
-
* @param {*} value
|
|
1499
|
-
* @returns {boolean} Returns true when given value is an object
|
|
1500
|
-
* having functions `then` and `catch`.
|
|
1501
|
-
*/
|
|
1502
|
-
function isPromise(value) {
|
|
1503
|
-
return value && typeof value.then === 'function' && typeof value.catch === 'function';
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
// functions available externally
|
|
1507
|
-
worker.methods = {};
|
|
1508
|
-
|
|
1509
|
-
/**
|
|
1510
|
-
* Execute a function with provided arguments
|
|
1511
|
-
* @param {String} fn Stringified function
|
|
1512
|
-
* @param {Array} [args] Function arguments
|
|
1513
|
-
* @returns {*}
|
|
1514
|
-
*/
|
|
1515
|
-
worker.methods.run = function run(fn, args) {
|
|
1516
|
-
var f = new Function('return (' + fn + ').apply(null, arguments);');
|
|
1517
|
-
return f.apply(f, args);
|
|
1518
|
-
};
|
|
1519
|
-
|
|
1520
|
-
/**
|
|
1521
|
-
* Get a list with methods available on this worker
|
|
1522
|
-
* @return {String[]} methods
|
|
1523
|
-
*/
|
|
1524
|
-
worker.methods.methods = function methods() {
|
|
1525
|
-
return Object.keys(worker.methods);
|
|
1526
|
-
};
|
|
1527
|
-
|
|
1528
|
-
/**
|
|
1529
|
-
* Custom handler for when the worker is terminated.
|
|
1530
|
-
*/
|
|
1531
|
-
worker.terminationHandler = undefined;
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* Cleanup and exit the worker.
|
|
1535
|
-
* @param {Number} code
|
|
1536
|
-
* @returns
|
|
1537
|
-
*/
|
|
1538
|
-
worker.cleanupAndExit = function (code) {
|
|
1539
|
-
var _exit = function () {
|
|
1540
|
-
worker.exit(code);
|
|
1541
|
-
};
|
|
1542
|
-
if (!worker.terminationHandler) {
|
|
1543
|
-
return _exit();
|
|
1544
|
-
}
|
|
1545
|
-
var result = worker.terminationHandler(code);
|
|
1546
|
-
if (isPromise(result)) {
|
|
1547
|
-
result.then(_exit, _exit);
|
|
1548
|
-
} else {
|
|
1549
|
-
_exit();
|
|
1550
|
-
}
|
|
1551
|
-
};
|
|
1552
|
-
var currentRequestId = null;
|
|
1553
|
-
worker.on('message', function (request) {
|
|
1554
|
-
if (request === TERMINATE_METHOD_ID) {
|
|
1555
|
-
return worker.cleanupAndExit(0);
|
|
1556
|
-
}
|
|
1557
|
-
try {
|
|
1558
|
-
var method = worker.methods[request.method];
|
|
1559
|
-
if (method) {
|
|
1560
|
-
currentRequestId = request.id;
|
|
1561
|
-
|
|
1562
|
-
// execute the function
|
|
1563
|
-
var result = method.apply(method, request.params);
|
|
1564
|
-
if (isPromise(result)) {
|
|
1565
|
-
// promise returned, resolve this and then return
|
|
1566
|
-
result.then(function (result) {
|
|
1567
|
-
if (result instanceof Transfer) {
|
|
1568
|
-
worker.send({
|
|
1569
|
-
id: request.id,
|
|
1570
|
-
result: result.message,
|
|
1571
|
-
error: null
|
|
1572
|
-
}, result.transfer);
|
|
1573
|
-
} else {
|
|
1574
|
-
worker.send({
|
|
1575
|
-
id: request.id,
|
|
1576
|
-
result: result,
|
|
1577
|
-
error: null
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
currentRequestId = null;
|
|
1581
|
-
}).catch(function (err) {
|
|
1582
|
-
worker.send({
|
|
1583
|
-
id: request.id,
|
|
1584
|
-
result: null,
|
|
1585
|
-
error: convertError(err)
|
|
1586
|
-
});
|
|
1587
|
-
currentRequestId = null;
|
|
1588
|
-
});
|
|
1589
|
-
} else {
|
|
1590
|
-
// immediate result
|
|
1591
|
-
if (result instanceof Transfer) {
|
|
1592
|
-
worker.send({
|
|
1593
|
-
id: request.id,
|
|
1594
|
-
result: result.message,
|
|
1595
|
-
error: null
|
|
1596
|
-
}, result.transfer);
|
|
1597
|
-
} else {
|
|
1598
|
-
worker.send({
|
|
1599
|
-
id: request.id,
|
|
1600
|
-
result: result,
|
|
1601
|
-
error: null
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
currentRequestId = null;
|
|
1605
|
-
}
|
|
1606
|
-
} else {
|
|
1607
|
-
throw new Error('Unknown method "' + request.method + '"');
|
|
1608
|
-
}
|
|
1609
|
-
} catch (err) {
|
|
1610
|
-
worker.send({
|
|
1611
|
-
id: request.id,
|
|
1612
|
-
result: null,
|
|
1613
|
-
error: convertError(err)
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
});
|
|
1617
|
-
|
|
1618
|
-
/**
|
|
1619
|
-
* Register methods to the worker
|
|
1620
|
-
* @param {Object} [methods]
|
|
1621
|
-
* @param {import('./types.js').WorkerRegisterOptions} [options]
|
|
1622
|
-
*/
|
|
1623
|
-
worker.register = function (methods, options) {
|
|
1624
|
-
if (methods) {
|
|
1625
|
-
for (var name in methods) {
|
|
1626
|
-
if (methods.hasOwnProperty(name)) {
|
|
1627
|
-
worker.methods[name] = methods[name];
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
if (options) {
|
|
1632
|
-
worker.terminationHandler = options.onTerminate;
|
|
1633
|
-
}
|
|
1634
|
-
worker.send('ready');
|
|
1635
|
-
};
|
|
1636
|
-
worker.emit = function (payload) {
|
|
1637
|
-
if (currentRequestId) {
|
|
1638
|
-
if (payload instanceof Transfer) {
|
|
1639
|
-
worker.send({
|
|
1640
|
-
id: currentRequestId,
|
|
1641
|
-
isEvent: true,
|
|
1642
|
-
payload: payload.message
|
|
1643
|
-
}, payload.transfer);
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
worker.send({
|
|
1647
|
-
id: currentRequestId,
|
|
1648
|
-
isEvent: true,
|
|
1649
|
-
payload
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1653
|
-
{
|
|
1654
|
-
exports.add = worker.register;
|
|
1655
|
-
exports.emit = worker.emit;
|
|
1656
|
-
}
|
|
1657
|
-
})(worker$1);
|
|
1658
|
-
return worker$1;
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
const {
|
|
1662
|
-
platform,
|
|
1663
|
-
isMainThread,
|
|
1664
|
-
cpus
|
|
1665
|
-
} = environmentExports;
|
|
1666
|
-
|
|
1667
|
-
/** @typedef {import("./Pool")} Pool */
|
|
1668
|
-
/** @typedef {import("./types.js").WorkerPoolOptions} WorkerPoolOptions */
|
|
1669
|
-
/** @typedef {import("./types.js").WorkerRegisterOptions} WorkerRegisterOptions */
|
|
1670
|
-
|
|
1671
|
-
/**
|
|
1672
|
-
* @template { { [k: string]: (...args: any[]) => any } } T
|
|
1673
|
-
* @typedef {import('./types.js').Proxy<T>} Proxy<T>
|
|
1674
|
-
*/
|
|
1675
|
-
|
|
1676
|
-
/**
|
|
1677
|
-
* @overload
|
|
1678
|
-
* Create a new worker pool
|
|
1679
|
-
* @param {WorkerPoolOptions} [script]
|
|
1680
|
-
* @returns {Pool} pool
|
|
1681
|
-
*/
|
|
1682
|
-
/**
|
|
1683
|
-
* @overload
|
|
1684
|
-
* Create a new worker pool
|
|
1685
|
-
* @param {string} [script]
|
|
1686
|
-
* @param {WorkerPoolOptions} [options]
|
|
1687
|
-
* @returns {Pool} pool
|
|
1688
|
-
*/
|
|
1689
|
-
function pool(script, options) {
|
|
1690
|
-
var Pool = requirePool();
|
|
1691
|
-
return new Pool(script, options);
|
|
1692
|
-
}
|
|
1693
|
-
var pool_1 = src.pool = pool;
|
|
1694
|
-
|
|
1695
|
-
/**
|
|
1696
|
-
* Create a worker and optionally register a set of methods to the worker.
|
|
1697
|
-
* @param {{ [k: string]: (...args: any[]) => any }} [methods]
|
|
1698
|
-
* @param {WorkerRegisterOptions} [options]
|
|
1699
|
-
*/
|
|
1700
|
-
function worker(methods, options) {
|
|
1701
|
-
var worker = requireWorker();
|
|
1702
|
-
worker.add(methods, options);
|
|
1703
|
-
}
|
|
1704
|
-
var worker_1 = src.worker = worker;
|
|
1705
|
-
|
|
1706
|
-
/**
|
|
1707
|
-
* Sends an event to the parent worker pool.
|
|
1708
|
-
* @param {any} payload
|
|
1709
|
-
*/
|
|
1710
|
-
function workerEmit(payload) {
|
|
1711
|
-
var worker = requireWorker();
|
|
1712
|
-
worker.emit(payload);
|
|
1713
|
-
}
|
|
1714
|
-
var workerEmit_1 = src.workerEmit = workerEmit;
|
|
1715
|
-
const {
|
|
1716
|
-
Promise: Promise$1
|
|
1717
|
-
} = require_Promise();
|
|
1718
|
-
var _Promise = src.Promise = Promise$1;
|
|
1719
|
-
var Transfer = src.Transfer = requireTransfer();
|
|
1720
|
-
var platform_1 = src.platform = platform;
|
|
1721
|
-
var isMainThread_1 = src.isMainThread = isMainThread;
|
|
1722
|
-
var cpus_1 = src.cpus = cpus;
|
|
1723
|
-
|
|
1724
|
-
exports.Promise = _Promise;
|
|
1725
|
-
exports.Transfer = Transfer;
|
|
1726
|
-
exports.cpus = cpus_1;
|
|
1727
|
-
exports.default = src;
|
|
1728
|
-
exports.isMainThread = isMainThread_1;
|
|
1729
|
-
exports.platform = platform_1;
|
|
1730
|
-
exports.pool = pool_1;
|
|
1731
|
-
exports.worker = worker_1;
|
|
1732
|
-
exports.workerEmit = workerEmit_1;
|
|
1733
|
-
|
|
1734
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1735
|
-
|
|
1736
|
-
}));
|
|
1737
|
-
//# sourceMappingURL=workerpool.js.map
|