@celljs/core 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/browser/application/frontend-application-state.d.ts +4 -0
- package/esm/browser/application/frontend-application-state.js +14 -0
- package/esm/browser/application/frontend-application-state.js.map +1 -0
- package/esm/browser/application/frontend-application.d.ts +30 -0
- package/esm/browser/application/frontend-application.js +142 -0
- package/esm/browser/application/frontend-application.js.map +1 -0
- package/esm/browser/application/index.d.ts +2 -0
- package/esm/browser/application/index.js +3 -0
- package/esm/browser/application/index.js.map +1 -0
- package/esm/browser/browser.d.ts +22 -0
- package/esm/browser/browser.js +48 -0
- package/esm/browser/browser.js.map +1 -0
- package/esm/browser/index.d.ts +3 -0
- package/esm/browser/index.js +4 -0
- package/esm/browser/index.js.map +1 -0
- package/esm/browser/shell/application-shell.d.ts +4 -0
- package/esm/browser/shell/application-shell.js +18 -0
- package/esm/browser/shell/application-shell.js.map +1 -0
- package/esm/browser/shell/index.d.ts +2 -0
- package/esm/browser/shell/index.js +3 -0
- package/esm/browser/shell/index.js.map +1 -0
- package/esm/browser/shell/shell-protocol.d.ts +4 -0
- package/esm/browser/shell/shell-protocol.js +2 -0
- package/esm/browser/shell/shell-protocol.js.map +1 -0
- package/esm/browser/static-module.d.ts +3 -0
- package/esm/browser/static-module.js +4 -0
- package/esm/browser/static-module.js.map +1 -0
- package/esm/common/annotation/aspect.d.ts +7 -0
- package/esm/common/annotation/aspect.js +10 -0
- package/esm/common/annotation/aspect.js.map +1 -0
- package/esm/common/annotation/autowired-provider.d.ts +7 -0
- package/esm/common/annotation/autowired-provider.js +25 -0
- package/esm/common/annotation/autowired-provider.js.map +1 -0
- package/esm/common/annotation/autowired.d.ts +22 -0
- package/esm/common/annotation/autowired.js +48 -0
- package/esm/common/annotation/autowired.js.map +1 -0
- package/esm/common/annotation/component.d.ts +57 -0
- package/esm/common/annotation/component.js +71 -0
- package/esm/common/annotation/component.js.map +1 -0
- package/esm/common/annotation/constant.d.ts +8 -0
- package/esm/common/annotation/constant.js +12 -0
- package/esm/common/annotation/constant.js.map +1 -0
- package/esm/common/annotation/decorate.d.ts +1 -0
- package/esm/common/annotation/decorate.js +2 -0
- package/esm/common/annotation/decorate.js.map +1 -0
- package/esm/common/annotation/detached/autowired-provider.d.ts +2 -0
- package/esm/common/annotation/detached/autowired-provider.js +12 -0
- package/esm/common/annotation/detached/autowired-provider.js.map +1 -0
- package/esm/common/annotation/detached/autowired.d.ts +2 -0
- package/esm/common/annotation/detached/autowired.js +9 -0
- package/esm/common/annotation/detached/autowired.js.map +1 -0
- package/esm/common/annotation/detached/index.d.ts +3 -0
- package/esm/common/annotation/detached/index.js +4 -0
- package/esm/common/annotation/detached/index.js.map +1 -0
- package/esm/common/annotation/detached/value.d.ts +2 -0
- package/esm/common/annotation/detached/value.js +9 -0
- package/esm/common/annotation/detached/value.js.map +1 -0
- package/esm/common/annotation/index.d.ts +17 -0
- package/esm/common/annotation/index.js +18 -0
- package/esm/common/annotation/index.js.map +1 -0
- package/esm/common/annotation/inject.d.ts +1 -0
- package/esm/common/annotation/inject.js +2 -0
- package/esm/common/annotation/inject.js.map +1 -0
- package/esm/common/annotation/injectable.d.ts +1 -0
- package/esm/common/annotation/injectable.js +2 -0
- package/esm/common/annotation/injectable.js.map +1 -0
- package/esm/common/annotation/named.d.ts +1 -0
- package/esm/common/annotation/named.js +2 -0
- package/esm/common/annotation/named.js.map +1 -0
- package/esm/common/annotation/optional.d.ts +1 -0
- package/esm/common/annotation/optional.js +2 -0
- package/esm/common/annotation/optional.js.map +1 -0
- package/esm/common/annotation/post-construct.d.ts +1 -0
- package/esm/common/annotation/post-construct.js +2 -0
- package/esm/common/annotation/post-construct.js.map +1 -0
- package/esm/common/annotation/pre-destroy.d.ts +1 -0
- package/esm/common/annotation/pre-destroy.js +2 -0
- package/esm/common/annotation/pre-destroy.js.map +1 -0
- package/esm/common/annotation/service.d.ts +4 -0
- package/esm/common/annotation/service.js +14 -0
- package/esm/common/annotation/service.js.map +1 -0
- package/esm/common/annotation/tagged.d.ts +1 -0
- package/esm/common/annotation/tagged.js +2 -0
- package/esm/common/annotation/tagged.js.map +1 -0
- package/esm/common/annotation/target-name.d.ts +1 -0
- package/esm/common/annotation/target-name.js +2 -0
- package/esm/common/annotation/target-name.js.map +1 -0
- package/esm/common/annotation/unmanaged.d.ts +1 -0
- package/esm/common/annotation/unmanaged.js +2 -0
- package/esm/common/annotation/unmanaged.js.map +1 -0
- package/esm/common/annotation/value.d.ts +15 -0
- package/esm/common/annotation/value.js +50 -0
- package/esm/common/annotation/value.js.map +1 -0
- package/esm/common/aop/aop-protocol.d.ts +38 -0
- package/esm/common/aop/aop-protocol.js +8 -0
- package/esm/common/aop/aop-protocol.js.map +1 -0
- package/esm/common/aop/aop-proxy-factory.d.ts +6 -0
- package/esm/common/aop/aop-proxy-factory.js +67 -0
- package/esm/common/aop/aop-proxy-factory.js.map +1 -0
- package/esm/common/aop/class-filter.d.ts +6 -0
- package/esm/common/aop/class-filter.js +28 -0
- package/esm/common/aop/class-filter.js.map +1 -0
- package/esm/common/aop/index.d.ts +3 -0
- package/esm/common/aop/index.js +4 -0
- package/esm/common/aop/index.js.map +1 -0
- package/esm/common/application/application-entry.d.ts +1 -0
- package/esm/common/application/application-entry.js +23 -0
- package/esm/common/application/application-entry.js.map +1 -0
- package/esm/common/application/application-error.d.ts +20 -0
- package/esm/common/application/application-error.js +44 -0
- package/esm/common/application/application-error.js.map +1 -0
- package/esm/common/application/application-factory.d.ts +8 -0
- package/esm/common/application/application-factory.js +19 -0
- package/esm/common/application/application-factory.js.map +1 -0
- package/esm/common/application/application-protocol.d.ts +52 -0
- package/esm/common/application/application-protocol.js +103 -0
- package/esm/common/application/application-protocol.js.map +1 -0
- package/esm/common/application/application-state.d.ts +3 -0
- package/esm/common/application/application-state.js +15 -0
- package/esm/common/application/application-state.js.map +1 -0
- package/esm/common/application/application.d.ts +6 -0
- package/esm/common/application/application.js +31 -0
- package/esm/common/application/application.js.map +1 -0
- package/esm/common/application/index.d.ts +2 -0
- package/esm/common/application/index.js +3 -0
- package/esm/common/application/index.js.map +1 -0
- package/esm/common/config/config-protocol.d.ts +4 -0
- package/esm/common/config/config-protocol.js +2 -0
- package/esm/common/config/config-protocol.js.map +1 -0
- package/esm/common/config/config-provider.d.ts +6 -0
- package/esm/common/config/config-provider.js +26 -0
- package/esm/common/config/config-provider.js.map +1 -0
- package/esm/common/config/config-util.d.ts +4 -0
- package/esm/common/config/config-util.js +16 -0
- package/esm/common/config/config-util.js.map +1 -0
- package/esm/common/config/dynamic-config.d.ts +3 -0
- package/esm/common/config/dynamic-config.js +3 -0
- package/esm/common/config/dynamic-config.js.map +1 -0
- package/esm/common/config/index.d.ts +3 -0
- package/esm/common/config/index.js +4 -0
- package/esm/common/config/index.js.map +1 -0
- package/esm/common/constants.d.ts +5 -0
- package/esm/common/constants.js +6 -0
- package/esm/common/constants.js.map +1 -0
- package/esm/common/container/auto-bind.d.ts +3 -0
- package/esm/common/container/auto-bind.js +98 -0
- package/esm/common/container/auto-bind.js.map +1 -0
- package/esm/common/container/container-factory.d.ts +4 -0
- package/esm/common/container/container-factory.js +9 -0
- package/esm/common/container/container-factory.js.map +1 -0
- package/esm/common/container/container-provider.d.ts +6 -0
- package/esm/common/container/container-provider.js +23 -0
- package/esm/common/container/container-provider.js.map +1 -0
- package/esm/common/container/container-util.d.ts +9 -0
- package/esm/common/container/container-util.js +29 -0
- package/esm/common/container/container-util.js.map +1 -0
- package/esm/common/container/dynamic-container.d.ts +2 -0
- package/esm/common/container/dynamic-container.js +4 -0
- package/esm/common/container/dynamic-container.js.map +1 -0
- package/esm/common/container/index.d.ts +8 -0
- package/esm/common/container/index.js +6 -0
- package/esm/common/container/index.js.map +1 -0
- package/esm/common/container/scope.d.ts +5 -0
- package/esm/common/container/scope.js +7 -0
- package/esm/common/container/scope.js.map +1 -0
- package/esm/common/el/core-context-initializer.d.ts +6 -0
- package/esm/common/el/core-context-initializer.js +36 -0
- package/esm/common/el/core-context-initializer.js.map +1 -0
- package/esm/common/el/expression-compiler.d.ts +19 -0
- package/esm/common/el/expression-compiler.js +187 -0
- package/esm/common/el/expression-compiler.js.map +1 -0
- package/esm/common/el/expression-context-provider.d.ts +9 -0
- package/esm/common/el/expression-context-provider.js +43 -0
- package/esm/common/el/expression-context-provider.js.map +1 -0
- package/esm/common/el/expression-handler.d.ts +11 -0
- package/esm/common/el/expression-handler.js +95 -0
- package/esm/common/el/expression-handler.js.map +1 -0
- package/esm/common/el/expression-protocol.d.ts +32 -0
- package/esm/common/el/expression-protocol.js +6 -0
- package/esm/common/el/expression-protocol.js.map +1 -0
- package/esm/common/el/index.d.ts +6 -0
- package/esm/common/el/index.js +7 -0
- package/esm/common/el/index.js.map +1 -0
- package/esm/common/el/jexl-engine-provider.d.ts +5 -0
- package/esm/common/el/jexl-engine-provider.js +22 -0
- package/esm/common/el/jexl-engine-provider.js.map +1 -0
- package/esm/common/error/custom-error.d.ts +26 -0
- package/esm/common/error/custom-error.js +40 -0
- package/esm/common/error/custom-error.js.map +1 -0
- package/esm/common/error/error-protocol.d.ts +3 -0
- package/esm/common/error/error-protocol.js +2 -0
- package/esm/common/error/error-protocol.js.map +1 -0
- package/esm/common/error/illegal-argument-error.d.ts +3 -0
- package/esm/common/error/illegal-argument-error.js +4 -0
- package/esm/common/error/illegal-argument-error.js.map +1 -0
- package/esm/common/error/illegal-state-error.d.ts +3 -0
- package/esm/common/error/illegal-state-error.js +4 -0
- package/esm/common/error/illegal-state-error.js.map +1 -0
- package/esm/common/error/index.d.ts +5 -0
- package/esm/common/error/index.js +6 -0
- package/esm/common/error/index.js.map +1 -0
- package/esm/common/error/invalid-mime-type-error.d.ts +5 -0
- package/esm/common/error/invalid-mime-type-error.js +8 -0
- package/esm/common/error/invalid-mime-type-error.js.map +1 -0
- package/esm/common/index.d.ts +12 -0
- package/esm/common/index.js +13 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/logger/abstract-logger.d.ts +18 -0
- package/esm/common/logger/abstract-logger.js +69 -0
- package/esm/common/logger/abstract-logger.js.map +1 -0
- package/esm/common/logger/index.d.ts +4 -0
- package/esm/common/logger/index.js +5 -0
- package/esm/common/logger/index.js.map +1 -0
- package/esm/common/logger/logger-protocol.d.ts +30 -0
- package/esm/common/logger/logger-protocol.js +8 -0
- package/esm/common/logger/logger-protocol.js.map +1 -0
- package/esm/common/logger/logger-service.d.ts +4 -0
- package/esm/common/logger/logger-service.js +18 -0
- package/esm/common/logger/logger-service.js.map +1 -0
- package/esm/common/logger/logger.d.ts +7 -0
- package/esm/common/logger/logger.js +35 -0
- package/esm/common/logger/logger.js.map +1 -0
- package/esm/common/provider/component-filter-registry.d.ts +11 -0
- package/esm/common/provider/component-filter-registry.js +66 -0
- package/esm/common/provider/component-filter-registry.js.map +1 -0
- package/esm/common/provider/index.d.ts +5 -0
- package/esm/common/provider/index.js +6 -0
- package/esm/common/provider/index.js.map +1 -0
- package/esm/common/provider/provider-creator.d.ts +6 -0
- package/esm/common/provider/provider-creator.js +19 -0
- package/esm/common/provider/provider-creator.js.map +1 -0
- package/esm/common/provider/provider-protocol.d.ts +48 -0
- package/esm/common/provider/provider-protocol.js +5 -0
- package/esm/common/provider/provider-protocol.js.map +1 -0
- package/esm/common/provider/provider-util.d.ts +5 -0
- package/esm/common/provider/provider-util.js +10 -0
- package/esm/common/provider/provider-util.js.map +1 -0
- package/esm/common/provider/provider.d.ts +13 -0
- package/esm/common/provider/provider.js +54 -0
- package/esm/common/provider/provider.js.map +1 -0
- package/esm/common/static-module.d.ts +3 -0
- package/esm/common/static-module.js +9 -0
- package/esm/common/static-module.js.map +1 -0
- package/esm/common/test/index.d.ts +1 -0
- package/esm/common/test/index.js +2 -0
- package/esm/common/test/index.js.map +1 -0
- package/esm/common/test/mock-logger.d.ts +14 -0
- package/esm/common/test/mock-logger.js +41 -0
- package/esm/common/test/mock-logger.js.map +1 -0
- package/esm/common/test/test-module.d.ts +2 -0
- package/esm/common/test/test-module.js +12 -0
- package/esm/common/test/test-module.js.map +1 -0
- package/esm/common/utils/annotation-util.d.ts +4 -0
- package/esm/common/utils/annotation-util.js +24 -0
- package/esm/common/utils/annotation-util.js.map +1 -0
- package/esm/common/utils/assert.d.ts +173 -0
- package/esm/common/utils/assert.js +283 -0
- package/esm/common/utils/assert.js.map +1 -0
- package/esm/common/utils/async.d.ts +367 -0
- package/esm/common/utils/async.js +935 -0
- package/esm/common/utils/async.js.map +1 -0
- package/esm/common/utils/byte-util.d.ts +11 -0
- package/esm/common/utils/byte-util.js +75 -0
- package/esm/common/utils/byte-util.js.map +1 -0
- package/esm/common/utils/cancellation.d.ts +21 -0
- package/esm/common/utils/cancellation.js +89 -0
- package/esm/common/utils/cancellation.js.map +1 -0
- package/esm/common/utils/class-util.d.ts +2 -0
- package/esm/common/utils/class-util.js +19 -0
- package/esm/common/utils/class-util.js.map +1 -0
- package/esm/common/utils/disposable.d.ts +29 -0
- package/esm/common/utils/disposable.js +78 -0
- package/esm/common/utils/disposable.js.map +1 -0
- package/esm/common/utils/emitter.d.ts +63 -0
- package/esm/common/utils/emitter.js +221 -0
- package/esm/common/utils/emitter.js.map +1 -0
- package/esm/common/utils/error-util.d.ts +19 -0
- package/esm/common/utils/error-util.js +35 -0
- package/esm/common/utils/error-util.js.map +1 -0
- package/esm/common/utils/event.d.ts +40 -0
- package/esm/common/utils/event.js +90 -0
- package/esm/common/utils/event.js.map +1 -0
- package/esm/common/utils/global-util.d.ts +1 -0
- package/esm/common/utils/global-util.js +16 -0
- package/esm/common/utils/global-util.js.map +1 -0
- package/esm/common/utils/index.d.ts +21 -0
- package/esm/common/utils/index.js +22 -0
- package/esm/common/utils/index.js.map +1 -0
- package/esm/common/utils/metadata-util.d.ts +1 -0
- package/esm/common/utils/metadata-util.js +25 -0
- package/esm/common/utils/metadata-util.js.map +1 -0
- package/esm/common/utils/mime-type-util.d.ts +36 -0
- package/esm/common/utils/mime-type-util.js +168 -0
- package/esm/common/utils/mime-type-util.js.map +1 -0
- package/esm/common/utils/mime-type.d.ts +36 -0
- package/esm/common/utils/mime-type.js +284 -0
- package/esm/common/utils/mime-type.js.map +1 -0
- package/esm/common/utils/os.d.ts +19 -0
- package/esm/common/utils/os.js +46 -0
- package/esm/common/utils/os.js.map +1 -0
- package/esm/common/utils/prioritizeable.d.ts +17 -0
- package/esm/common/utils/prioritizeable.js +38 -0
- package/esm/common/utils/prioritizeable.js.map +1 -0
- package/esm/common/utils/promise-util.d.ts +5 -0
- package/esm/common/utils/promise-util.js +9 -0
- package/esm/common/utils/promise-util.js.map +1 -0
- package/esm/common/utils/proxy-util.d.ts +4 -0
- package/esm/common/utils/proxy-util.js +34 -0
- package/esm/common/utils/proxy-util.js.map +1 -0
- package/esm/common/utils/types.d.ts +16 -0
- package/esm/common/utils/types.js +2 -0
- package/esm/common/utils/types.js.map +1 -0
- package/esm/common/utils/url-util.d.ts +3 -0
- package/esm/common/utils/url-util.js +56 -0
- package/esm/common/utils/url-util.js.map +1 -0
- package/esm/common/utils/uuid.d.ts +2 -0
- package/esm/common/utils/uuid.js +61 -0
- package/esm/common/utils/uuid.js.map +1 -0
- package/esm/node/application/backend-application-state.d.ts +4 -0
- package/esm/node/application/backend-application-state.js +14 -0
- package/esm/node/application/backend-application-state.js.map +1 -0
- package/esm/node/application/backend-application.d.ts +10 -0
- package/esm/node/application/backend-application.js +52 -0
- package/esm/node/application/backend-application.js.map +1 -0
- package/esm/node/application/index.d.ts +2 -0
- package/esm/node/application/index.js +3 -0
- package/esm/node/application/index.js.map +1 -0
- package/esm/node/constants.d.ts +15 -0
- package/esm/node/constants.js +16 -0
- package/esm/node/constants.js.map +1 -0
- package/esm/node/context/context.d.ts +15 -0
- package/esm/node/context/context.js +58 -0
- package/esm/node/context/context.js.map +1 -0
- package/esm/node/context/index.d.ts +1 -0
- package/esm/node/context/index.js +2 -0
- package/esm/node/context/index.js.map +1 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +4 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/static-module.d.ts +3 -0
- package/esm/node/static-module.js +4 -0
- package/esm/node/static-module.js.map +1 -0
- package/esm/node/utils/crc.d.ts +1 -0
- package/esm/node/utils/crc.js +7 -0
- package/esm/node/utils/crc.js.map +1 -0
- package/esm/node/utils/index.d.ts +1 -0
- package/esm/node/utils/index.js +2 -0
- package/esm/node/utils/index.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/common/application/application-factory.d.ts +1 -0
- package/lib/common/application/application-factory.d.ts.map +1 -1
- package/lib/common/application/application-factory.js +1 -1
- package/lib/common/application/application-factory.js.map +1 -1
- package/package.json +124 -4
- package/src/common/application/application-factory.ts +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { IllegalStateError } from '../error/illegal-state-error.js';
|
|
2
|
+
import { getSuperClasses } from './class-util.js';
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
/* eslint-disable no-null/no-null */
|
|
5
|
+
export class Assert {
|
|
6
|
+
/**
|
|
7
|
+
* Assert a boolean expression, throwing an `IllegalStateError`
|
|
8
|
+
* if the expression evaluates to `false`.
|
|
9
|
+
* @param expression a boolean expression
|
|
10
|
+
* @param message the exception message to use if the assertion fails
|
|
11
|
+
* @throws IllegalStateError if `expression` is `false`
|
|
12
|
+
* @example
|
|
13
|
+
* Assert.state(id === undefined, "The id property must not already be initialized");
|
|
14
|
+
* Assert.state(entity.getId() === undefined,
|
|
15
|
+
* () => "ID for entity " + entity.getName() + " must not already be initialized");
|
|
16
|
+
*/
|
|
17
|
+
static state(expression, message) {
|
|
18
|
+
if (!expression) {
|
|
19
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Assert a boolean expression, throwing an `IllegalStateError`
|
|
24
|
+
* if the expression evaluates to `false`.
|
|
25
|
+
* @param expression a boolean expression
|
|
26
|
+
* @param message the exception message to use if the assertion fails
|
|
27
|
+
* @throws IllegalStateError if `expression` is `false`
|
|
28
|
+
* @example
|
|
29
|
+
* Assert.isTrue(i > 0, "The value must be greater than zero");
|
|
30
|
+
* Assert.isTrue(i > 0, () => "The value '" + i + "' must be greater than zero");
|
|
31
|
+
*/
|
|
32
|
+
static isTrue(expression, message) {
|
|
33
|
+
if (!expression) {
|
|
34
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Assert that an object is `undefined`.
|
|
39
|
+
* @param object the object to check
|
|
40
|
+
* @param message the exception message to use if the assertion fails
|
|
41
|
+
* @throws IllegalStateError if the object is not `undefined`
|
|
42
|
+
* @example
|
|
43
|
+
* Assert.isNull(value, "The value must be null");
|
|
44
|
+
* Assert.isNull(value, () => "The value '" + value + "' must be null");
|
|
45
|
+
*/
|
|
46
|
+
static isNull(object, message) {
|
|
47
|
+
if (object !== undefined || object !== null) {
|
|
48
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Assert that an object is not `undefined`.
|
|
53
|
+
* @param object the object to check
|
|
54
|
+
* @param message the exception message to use if the assertion fails
|
|
55
|
+
* @throws IllegalStateError if the object is `undefined`
|
|
56
|
+
* @example
|
|
57
|
+
* Assert.notNull(clazz, "The class must not be null");
|
|
58
|
+
* Assert.notNull(entity.getId(),
|
|
59
|
+
* () => "ID for entity " + entity.getName() + " must not be null");
|
|
60
|
+
*/
|
|
61
|
+
static notNull(object, message) {
|
|
62
|
+
if (object === undefined || object === null) {
|
|
63
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Assert that the given String is not empty; that is,
|
|
68
|
+
* it must not be `undefined` and not the empty String.
|
|
69
|
+
* @param text the String to check
|
|
70
|
+
* @param message the exception message to use if the assertion fails
|
|
71
|
+
* @throws IllegalStateError if the text is empty
|
|
72
|
+
* @example
|
|
73
|
+
* Assert.hasLength(name, "Name must not be empty");
|
|
74
|
+
* Assert.hasLength(name, () => "Name for account '" + account.getId() + "' must not be empty");
|
|
75
|
+
*/
|
|
76
|
+
static hasLength(text, message) {
|
|
77
|
+
if (!text || text.length === 0) {
|
|
78
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Assert that the given String contains valid text content; that is, it must not
|
|
83
|
+
* be `undefined` and must contain at least one non-whitespace character.
|
|
84
|
+
* @param text the String to check
|
|
85
|
+
* @param message the exception message to use if the assertion fails
|
|
86
|
+
* @throws IllegalStateError if the text does not contain valid text content
|
|
87
|
+
* @example
|
|
88
|
+
* Assert.hasText(account.getName(), "Name must not be empty");
|
|
89
|
+
* Assert.hasText(account.getName(),
|
|
90
|
+
* () => "Name for account '" + account.getId() + "' must not be empty");
|
|
91
|
+
*/
|
|
92
|
+
static hasText(text, message) {
|
|
93
|
+
if (!text || text.trim().length === 0) {
|
|
94
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Assert that the given text does not contain the given substring.
|
|
99
|
+
* @param textToSearch the text to search
|
|
100
|
+
* @param substring the substring to find within the text
|
|
101
|
+
* @param message the exception message to use if the assertion fails
|
|
102
|
+
* @throws IllegalStateError if the text contains the substring
|
|
103
|
+
* @example
|
|
104
|
+
* Assert.doesNotContain(name, forbidden, "Name must not contain '" + forbidden + "'");
|
|
105
|
+
* Assert.doesNotContain(name, forbidden,
|
|
106
|
+
* () => "Name must not contain '" + forbidden + "'");
|
|
107
|
+
*/
|
|
108
|
+
static doesNotContain(textToSearch, substring, message) {
|
|
109
|
+
if (textToSearch && substring && textToSearch.includes(substring)) {
|
|
110
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Assert that an array contains elements; that is, it must not be
|
|
115
|
+
* `undefined` and must contain at least one element.
|
|
116
|
+
* @param array the array to check
|
|
117
|
+
* @param message the exception message to use if the assertion fails
|
|
118
|
+
* @throws IllegalStateError if the object array is `undefined` or contains no elements
|
|
119
|
+
* @example
|
|
120
|
+
* Assert.notEmpty(array, "The array must contain elements");
|
|
121
|
+
* Assert.notEmpty(array, () => "The " + arrayType + " array must contain elements");
|
|
122
|
+
*/
|
|
123
|
+
static notEmpty(array, message) {
|
|
124
|
+
if (!array || array.length === 0) {
|
|
125
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Assert that an array contains no `undefined` elements.
|
|
130
|
+
* <p>Note: Does not complain if the array is empty!
|
|
131
|
+
* @param array the array to check
|
|
132
|
+
* @param message the exception message to use if the assertion fails
|
|
133
|
+
* @throws IllegalStateError if the object array contains a `undefined` element
|
|
134
|
+
* @example
|
|
135
|
+
* Assert.noNullElements(array, "The array must contain non-null elements");
|
|
136
|
+
* Assert.noNullElements(array, () => "The " + arrayType + " array must contain non-null elements");
|
|
137
|
+
*/
|
|
138
|
+
static noNullElements(array, message) {
|
|
139
|
+
if (array) {
|
|
140
|
+
for (const element of array) {
|
|
141
|
+
if (element === undefined || element === null) {
|
|
142
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Assert that a collection contains elements; that is, it must not be
|
|
149
|
+
* `undefined` and must contain at least one element.
|
|
150
|
+
* @param collection the collection to check
|
|
151
|
+
* @param message the exception message to use if the assertion fails
|
|
152
|
+
* @throws IllegalStateError if the collection is `undefined` or
|
|
153
|
+
* contains no elements
|
|
154
|
+
* @example
|
|
155
|
+
* Assert.notEmpty(collection, "Collection must contain elements");
|
|
156
|
+
* Assert.notEmpty(collection, () => "The " + collectionType + " collection must contain elements");
|
|
157
|
+
*/
|
|
158
|
+
static notEmptyCollection(collection, message) {
|
|
159
|
+
if (!collection || collection.length === 0) {
|
|
160
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Assert that a collection contains no `undefined` elements.
|
|
165
|
+
* <p>Note: Does not complain if the collection is empty!
|
|
166
|
+
* @param collection the collection to check
|
|
167
|
+
* @param message the exception message to use if the assertion fails
|
|
168
|
+
* @throws IllegalStateError if the collection contains a `undefined`
|
|
169
|
+
* @example
|
|
170
|
+
* Assert.noNullElements(collection, "Collection must contain non-null elements");
|
|
171
|
+
* Assert.noNullElements(collection, () => "The " + collectionName + " must contain non-null elements");
|
|
172
|
+
*/
|
|
173
|
+
static noNullElementsCollection(collection, message) {
|
|
174
|
+
if (collection) {
|
|
175
|
+
for (const element of collection) {
|
|
176
|
+
if (element === undefined || element === null) {
|
|
177
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Assert that a Map contains entries; that is, it must not be `undefined`
|
|
184
|
+
* and must contain at least one entry.
|
|
185
|
+
* @param map the map to check
|
|
186
|
+
* @param message the exception message to use if the assertion fails
|
|
187
|
+
* @throws IllegalStateError if the map is `undefined` or contains no entries
|
|
188
|
+
* @example
|
|
189
|
+
* Assert.notEmpty(map, "The map must contain entries");
|
|
190
|
+
* Assert.notEmpty(map, () => "The " + mapType + " map must contain entries");
|
|
191
|
+
*/
|
|
192
|
+
static notEmptyMap(map, message) {
|
|
193
|
+
if (!map || map.size === 0) {
|
|
194
|
+
throw new IllegalStateError(this.resolveMessage(message));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Assert that the provided object is an instance of the provided class.
|
|
199
|
+
* @param type the type to check against
|
|
200
|
+
* @param obj the object to check
|
|
201
|
+
* @param message a message which will be prepended to provide further context.
|
|
202
|
+
* If it is empty or ends in ":" or ";" or "," or ".", a full exception message
|
|
203
|
+
* will be appended. If it ends in a space, the name of the offending object's
|
|
204
|
+
* type will be appended. In any other case, a ":" with a space and the name
|
|
205
|
+
* of the offending object's type will be appended.
|
|
206
|
+
* @throws IllegalStateError if the object is not an instance of type
|
|
207
|
+
* @example
|
|
208
|
+
* Assert.instanceOf(Foo, foo, "Foo expected");
|
|
209
|
+
* Assert.instanceOf(Foo, foo, () => "Processing " + Foo.name + ":");
|
|
210
|
+
* Assert.instanceOf(Foo, foo);
|
|
211
|
+
*/
|
|
212
|
+
static isInstanceOf(type, obj, message) {
|
|
213
|
+
this.notNull(type, 'Type to check against must not be null');
|
|
214
|
+
if (!(obj instanceof type)) {
|
|
215
|
+
this.instanceCheckFailed(type, obj, this.resolveMessage(message));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Assert that `superType.isAssignableFrom(subType)` is `true`.
|
|
220
|
+
* @param superType the supertype to check against
|
|
221
|
+
* @param subType the subtype to check
|
|
222
|
+
* @param message a message which will be prepended to provide further context.
|
|
223
|
+
* If it is empty or ends in ":" or ";" or "," or ".", a full exception message
|
|
224
|
+
* will be appended. If it ends in a space, the name of the offending subtype
|
|
225
|
+
* will be appended. In any other case, a ":" with a space and the name of the
|
|
226
|
+
* offending subtype will be appended.
|
|
227
|
+
* @throws IllegalStateError if the classes are not assignable
|
|
228
|
+
* @example
|
|
229
|
+
* Assert.isAssignable(Number, myClass, "Number expected");
|
|
230
|
+
* Assert.isAssignable(Number, myClass, () => "Processing " + myAttributeName + ":");
|
|
231
|
+
*/
|
|
232
|
+
static isAssignable(superType, subType, message) {
|
|
233
|
+
this.notNull(superType, 'Supertype to check against must not be null');
|
|
234
|
+
if (subType === undefined || !getSuperClasses(subType).includes(superType)) {
|
|
235
|
+
this.assignableCheckFailed(superType, subType, this.resolveMessage(message));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
static instanceCheckFailed(type, obj, msg) {
|
|
239
|
+
const className = (obj !== undefined ? obj.constructor.name : 'undefined');
|
|
240
|
+
let result = '';
|
|
241
|
+
let defaultMessage = true;
|
|
242
|
+
if (msg && msg.length > 0) {
|
|
243
|
+
if (this.endsWithSeparator(msg)) {
|
|
244
|
+
result = msg + ' ';
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
result = this.messageWithTypeName(msg, className);
|
|
248
|
+
defaultMessage = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (defaultMessage) {
|
|
252
|
+
result = result + (`Object of class [${className}] must be an instance of ${type}`);
|
|
253
|
+
}
|
|
254
|
+
throw new IllegalStateError(result);
|
|
255
|
+
}
|
|
256
|
+
static assignableCheckFailed(superType, subType, msg) {
|
|
257
|
+
let result = '';
|
|
258
|
+
let defaultMessage = true;
|
|
259
|
+
if (msg && msg.length > 0) {
|
|
260
|
+
if (this.endsWithSeparator(msg)) {
|
|
261
|
+
result = msg + ' ';
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
result = this.messageWithTypeName(msg, subType);
|
|
265
|
+
defaultMessage = false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (defaultMessage) {
|
|
269
|
+
result = result + (`${subType} is not assignable to ${superType}`);
|
|
270
|
+
}
|
|
271
|
+
throw new IllegalStateError(result);
|
|
272
|
+
}
|
|
273
|
+
static endsWithSeparator(msg) {
|
|
274
|
+
return (msg.endsWith(':') || msg.endsWith(';') || msg.endsWith(',') || msg.endsWith('.'));
|
|
275
|
+
}
|
|
276
|
+
static messageWithTypeName(msg, typeName) {
|
|
277
|
+
return msg + (msg.endsWith(' ') ? '' : ': ') + ('name' in typeName) ? typeName.name : typeName;
|
|
278
|
+
}
|
|
279
|
+
static resolveMessage(message) {
|
|
280
|
+
return typeof message === 'function' ? message() : message;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../src/common/utils/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,uDAAuD;AACvD,oCAAoC;AAEpC,MAAM,OAAgB,MAAM;IACxB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAC,UAAmB,EAAE,OAAgC;QAC9D,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CAAC,UAAmB,EAAE,OAAgC;QAC/D,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CAAC,MAAW,EAAE,OAAgC;QACvD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,OAAO,CAAC,MAAe,EAAE,OAAgC;QAC5D,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,S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iC;QAC3D,OAAO,OAAO,OAAO,KAAK,UAAU,CAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAChE,CAAC;CACJ"}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { CancellationToken } from './cancellation.js';
|
|
2
|
+
import { Disposable } from './disposable.js';
|
|
3
|
+
import { Event } from './event.js';
|
|
4
|
+
interface Thenable<T> {
|
|
5
|
+
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
|
|
6
|
+
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
|
|
7
|
+
}
|
|
8
|
+
export declare function isThenable<T>(obj: unknown): obj is Promise<T>;
|
|
9
|
+
export interface CancelablePromise<T> extends Promise<T> {
|
|
10
|
+
cancel(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A function to allow a promise resolution to be delayed by a number of milliseconds. Usage is as follows:
|
|
14
|
+
*
|
|
15
|
+
* `const stringValue = await myPromise.then(delay(600)).then(value => value.toString());`
|
|
16
|
+
*
|
|
17
|
+
* @param ms the number of millisecond to delay
|
|
18
|
+
* @returns a function that returns a promise that returns the given value, but delayed
|
|
19
|
+
*/
|
|
20
|
+
export declare function delay<T>(ms: number): (value: T) => Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a promise that will resolve after a given delay.
|
|
23
|
+
* @param ms the number of milliseconds to wait
|
|
24
|
+
*/
|
|
25
|
+
export declare function wait(ms: number): Promise<void>;
|
|
26
|
+
export declare function waitForEvent<T>(event: Event<T>, ms: number, thisArg?: any, disposables?: Disposable[]): Promise<T>;
|
|
27
|
+
export declare function createCancelablePromise<T>(callback: (token: CancellationToken) => Promise<T>): CancelablePromise<T>;
|
|
28
|
+
export declare function raceCancellation<T>(promise: Promise<T>, token: CancellationToken): Promise<T | undefined>;
|
|
29
|
+
export declare function raceCancellation<T>(promise: Promise<T>, token: CancellationToken, defaultValue: T): Promise<T>;
|
|
30
|
+
export declare function raceCancellationError<T>(promise: Promise<T>, token: CancellationToken): Promise<T>;
|
|
31
|
+
export declare function raceCancellablePromises<T>(cancellablePromises: CancelablePromise<T>[]): Promise<T>;
|
|
32
|
+
export declare function raceTimeout<T>(promise: Promise<T>, timeout: number, onTimeout?: () => void): Promise<T | undefined>;
|
|
33
|
+
export declare function asPromise<T>(callback: () => T | Thenable<T>): Promise<T>;
|
|
34
|
+
export interface ITask<T> {
|
|
35
|
+
(): T;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A helper to prevent accumulation of sequential async tasks.
|
|
39
|
+
*
|
|
40
|
+
* Imagine a mail man with the sole task of delivering letters. As soon as
|
|
41
|
+
* a letter submitted for delivery, he drives to the destination, delivers it
|
|
42
|
+
* and returns to his base. Imagine that during the trip, N more letters were submitted.
|
|
43
|
+
* When the mail man returns, he picks those N letters and delivers them all in a
|
|
44
|
+
* single trip. Even though N+1 submissions occurred, only 2 deliveries were made.
|
|
45
|
+
*
|
|
46
|
+
* The throttler implements this via the queue() method, by providing it a task
|
|
47
|
+
* factory. Following the example:
|
|
48
|
+
*
|
|
49
|
+
* const throttler = new Throttler();
|
|
50
|
+
* const letters = [];
|
|
51
|
+
*
|
|
52
|
+
* function deliver() {
|
|
53
|
+
* const lettersToDeliver = letters;
|
|
54
|
+
* letters = [];
|
|
55
|
+
* return makeTheTrip(lettersToDeliver);
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* function onLetterReceived(l) {
|
|
59
|
+
* letters.push(l);
|
|
60
|
+
* throttler.queue(deliver);
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
export declare class Throttler {
|
|
64
|
+
private activePromise;
|
|
65
|
+
private queuedPromise;
|
|
66
|
+
private queuedPromiseFactory;
|
|
67
|
+
constructor();
|
|
68
|
+
queue<T>(promiseFactory: ITask<Promise<T>>): Promise<T>;
|
|
69
|
+
}
|
|
70
|
+
export declare class Sequencer {
|
|
71
|
+
private current;
|
|
72
|
+
queue<T>(promiseTask: ITask<Promise<T>>): Promise<T>;
|
|
73
|
+
}
|
|
74
|
+
export declare class SequencerByKey<TKey> {
|
|
75
|
+
private promiseMap;
|
|
76
|
+
queue<T>(key: TKey, promiseTask: ITask<Promise<T>>): Promise<T>;
|
|
77
|
+
}
|
|
78
|
+
/** Can be passed into the Delayed to defer using a microtask */
|
|
79
|
+
export declare const MicrotaskDelay: unique symbol;
|
|
80
|
+
/**
|
|
81
|
+
* A helper to delay (debounce) execution of a task that is being requested often.
|
|
82
|
+
*
|
|
83
|
+
* Following the throttler, now imagine the mail man wants to optimize the number of
|
|
84
|
+
* trips proactively. The trip itself can be long, so he decides not to make the trip
|
|
85
|
+
* as soon as a letter is submitted. Instead he waits a while, in case more
|
|
86
|
+
* letters are submitted. After said waiting period, if no letters were submitted, he
|
|
87
|
+
* decides to make the trip. Imagine that N more letters were submitted after the first
|
|
88
|
+
* one, all within a short period of time between each other. Even though N+1
|
|
89
|
+
* submissions occurred, only 1 delivery was made.
|
|
90
|
+
*
|
|
91
|
+
* The delayer offers this behavior via the trigger() method, into which both the task
|
|
92
|
+
* to be executed and the waiting period (delay) must be passed in as arguments. Following
|
|
93
|
+
* the example:
|
|
94
|
+
*
|
|
95
|
+
* const delayer = new Delayer(WAITING_PERIOD);
|
|
96
|
+
* const letters = [];
|
|
97
|
+
*
|
|
98
|
+
* function letterReceived(l) {
|
|
99
|
+
* letters.push(l);
|
|
100
|
+
* delayer.trigger(() => { return makeTheTrip(); });
|
|
101
|
+
* }
|
|
102
|
+
*/
|
|
103
|
+
export declare class Delayer<T> implements Disposable {
|
|
104
|
+
defaultDelay: number | typeof MicrotaskDelay;
|
|
105
|
+
private deferred;
|
|
106
|
+
private completionPromise;
|
|
107
|
+
private doResolve;
|
|
108
|
+
private doReject;
|
|
109
|
+
private task;
|
|
110
|
+
constructor(defaultDelay: number | typeof MicrotaskDelay);
|
|
111
|
+
trigger(task: ITask<T | Promise<T>>, delay?: number | typeof MicrotaskDelay): Promise<T>;
|
|
112
|
+
isTriggered(): boolean;
|
|
113
|
+
cancel(): void;
|
|
114
|
+
private cancelTimeout;
|
|
115
|
+
dispose(): void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A helper to delay execution of a task that is being requested often, while
|
|
119
|
+
* preventing accumulation of consecutive executions, while the task runs.
|
|
120
|
+
*
|
|
121
|
+
* The mail man is clever and waits for a certain amount of time, before going
|
|
122
|
+
* out to deliver letters. While the mail man is going out, more letters arrive
|
|
123
|
+
* and can only be delivered once he is back. Once he is back the mail man will
|
|
124
|
+
* do one more trip to deliver the letters that have accumulated while he was out.
|
|
125
|
+
*/
|
|
126
|
+
export declare class ThrottledDelayer<T> {
|
|
127
|
+
private delayer;
|
|
128
|
+
private throttler;
|
|
129
|
+
constructor(defaultDelay: number);
|
|
130
|
+
trigger(promiseFactory: ITask<Promise<T>>, delay?: number): Promise<T>;
|
|
131
|
+
isTriggered(): boolean;
|
|
132
|
+
cancel(): void;
|
|
133
|
+
dispose(): void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A barrier that is initially closed and then becomes opened permanently.
|
|
137
|
+
*/
|
|
138
|
+
export declare class Barrier {
|
|
139
|
+
private _isOpen;
|
|
140
|
+
private _promise;
|
|
141
|
+
private _completePromise;
|
|
142
|
+
constructor();
|
|
143
|
+
isOpen(): boolean;
|
|
144
|
+
open(): void;
|
|
145
|
+
wait(): Promise<boolean>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A barrier that is initially closed and then becomes opened permanently after a certain period of
|
|
149
|
+
* time or when open is called explicitly
|
|
150
|
+
*/
|
|
151
|
+
export declare class AutoOpenBarrier extends Barrier {
|
|
152
|
+
private readonly _timeout;
|
|
153
|
+
constructor(autoOpenTimeMs: number);
|
|
154
|
+
open(): void;
|
|
155
|
+
}
|
|
156
|
+
export declare function timeout(millis: number): CancelablePromise<void>;
|
|
157
|
+
export declare function timeout(millis: number, token: CancellationToken): Promise<void>;
|
|
158
|
+
export declare function disposableTimeout(handler: () => void, timeout?: number): Disposable;
|
|
159
|
+
/**
|
|
160
|
+
* Runs the provided list of promise factories in sequential order. The returned
|
|
161
|
+
* promise will complete to an array of results from each promise.
|
|
162
|
+
*/
|
|
163
|
+
export declare function sequence<T>(promiseFactories: ITask<Promise<T>>[]): Promise<T[]>;
|
|
164
|
+
export declare function first<T>(promiseFactories: ITask<Promise<T>>[], shouldStop?: (t: T) => boolean, defaultValue?: T | undefined): Promise<T | undefined>;
|
|
165
|
+
/**
|
|
166
|
+
* Returns the result of the first promise that matches the "shouldStop",
|
|
167
|
+
* running all promises in parallel. Supports cancelable promises.
|
|
168
|
+
*/
|
|
169
|
+
export declare function firstParallel<T>(promiseList: Promise<T>[], shouldStop?: (t: T) => boolean, defaultValue?: T | undefined): Promise<T | undefined>;
|
|
170
|
+
export declare function firstParallel<T, R extends T>(promiseList: Promise<T>[], shouldStop: (t: T) => t is R, defaultValue?: R | undefined): Promise<R | undefined>;
|
|
171
|
+
export interface ILimiter<T> {
|
|
172
|
+
readonly size: number;
|
|
173
|
+
queue(factory: ITask<Promise<T>>): Promise<T>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A helper to queue N promises and run them all with a max degree of parallelism. The helper
|
|
177
|
+
* ensures that at any time no more than M promises are running at the same time.
|
|
178
|
+
*/
|
|
179
|
+
export declare class Limiter<T> implements ILimiter<T> {
|
|
180
|
+
private _size;
|
|
181
|
+
private runningPromises;
|
|
182
|
+
private readonly maxDegreeOfParalellism;
|
|
183
|
+
private readonly outstandingPromises;
|
|
184
|
+
private readonly _onDrained;
|
|
185
|
+
constructor(maxDegreeOfParalellism: number);
|
|
186
|
+
/**
|
|
187
|
+
* An event that fires when every promise in the queue
|
|
188
|
+
* has started to execute. In other words: no work is
|
|
189
|
+
* pending to be scheduled.
|
|
190
|
+
*
|
|
191
|
+
* This is NOT an event that signals when all promises
|
|
192
|
+
* have finished though.
|
|
193
|
+
*/
|
|
194
|
+
get onDrained(): Event<void>;
|
|
195
|
+
get size(): number;
|
|
196
|
+
queue(factory: ITask<Promise<T>>): Promise<T>;
|
|
197
|
+
private consume;
|
|
198
|
+
private consumed;
|
|
199
|
+
dispose(): void;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A queue is handles one promise at a time and guarantees that at any time only one promise is executing.
|
|
203
|
+
*/
|
|
204
|
+
export declare class Queue<T> extends Limiter<T> {
|
|
205
|
+
constructor();
|
|
206
|
+
}
|
|
207
|
+
export declare class TimeoutTimer implements Disposable {
|
|
208
|
+
private _token;
|
|
209
|
+
constructor();
|
|
210
|
+
constructor(runner: () => void, timeout: number);
|
|
211
|
+
dispose(): void;
|
|
212
|
+
cancel(): void;
|
|
213
|
+
cancelAndSet(runner: () => void, timeout: number): void;
|
|
214
|
+
setIfNotSet(runner: () => void, timeout: number): void;
|
|
215
|
+
}
|
|
216
|
+
export declare class IntervalTimer implements Disposable {
|
|
217
|
+
private _token;
|
|
218
|
+
constructor();
|
|
219
|
+
dispose(): void;
|
|
220
|
+
cancel(): void;
|
|
221
|
+
cancelAndSet(runner: () => void, interval: number): void;
|
|
222
|
+
}
|
|
223
|
+
export declare class RunOnceScheduler {
|
|
224
|
+
protected runner: ((...args: unknown[]) => void) | undefined;
|
|
225
|
+
private timeoutToken;
|
|
226
|
+
private timeout;
|
|
227
|
+
private timeoutHandler;
|
|
228
|
+
constructor(runner: (...args: any[]) => void, delay: number);
|
|
229
|
+
/**
|
|
230
|
+
* Dispose RunOnceScheduler
|
|
231
|
+
*/
|
|
232
|
+
dispose(): void;
|
|
233
|
+
/**
|
|
234
|
+
* Cancel current scheduled runner (if any).
|
|
235
|
+
*/
|
|
236
|
+
cancel(): void;
|
|
237
|
+
/**
|
|
238
|
+
* Cancel previous runner (if any) & schedule a new runner.
|
|
239
|
+
*/
|
|
240
|
+
schedule(delay?: number): void;
|
|
241
|
+
get delay(): number;
|
|
242
|
+
set delay(value: number);
|
|
243
|
+
/**
|
|
244
|
+
* Returns true if scheduled.
|
|
245
|
+
*/
|
|
246
|
+
isScheduled(): boolean;
|
|
247
|
+
private onTimeout;
|
|
248
|
+
protected doRun(): void;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Same as `RunOnceScheduler`, but doesn't count the time spent in sleep mode.
|
|
252
|
+
* > **NOTE**: Only offers 1s resolution.
|
|
253
|
+
*
|
|
254
|
+
* When calling `setTimeout` with 3hrs, and putting the computer immediately to sleep
|
|
255
|
+
* for 8hrs, `setTimeout` will fire **as soon as the computer wakes from sleep**. But
|
|
256
|
+
* this scheduler will execute 3hrs **after waking the computer from sleep**.
|
|
257
|
+
*/
|
|
258
|
+
export declare class ProcessTimeRunOnceScheduler {
|
|
259
|
+
private runner;
|
|
260
|
+
private timeout;
|
|
261
|
+
private counter;
|
|
262
|
+
private intervalToken;
|
|
263
|
+
private intervalHandler;
|
|
264
|
+
constructor(runner: () => void, delay: number);
|
|
265
|
+
dispose(): void;
|
|
266
|
+
cancel(): void;
|
|
267
|
+
/**
|
|
268
|
+
* Cancel previous runner (if any) & schedule a new runner.
|
|
269
|
+
*/
|
|
270
|
+
schedule(delay?: number): void;
|
|
271
|
+
/**
|
|
272
|
+
* Returns true if scheduled.
|
|
273
|
+
*/
|
|
274
|
+
isScheduled(): boolean;
|
|
275
|
+
private onInterval;
|
|
276
|
+
}
|
|
277
|
+
export declare class RunOnceWorker<T> extends RunOnceScheduler {
|
|
278
|
+
private units;
|
|
279
|
+
constructor(runner: (units: T[]) => void, timeout: number);
|
|
280
|
+
work(unit: T): void;
|
|
281
|
+
protected doRun(): void;
|
|
282
|
+
dispose(): void;
|
|
283
|
+
}
|
|
284
|
+
export interface IThrottledWorkerOptions {
|
|
285
|
+
/**
|
|
286
|
+
* maximum of units the worker will pass onto handler at once
|
|
287
|
+
*/
|
|
288
|
+
maxWorkChunkSize: number;
|
|
289
|
+
/**
|
|
290
|
+
* maximum of units the worker will keep in memory for processing
|
|
291
|
+
*/
|
|
292
|
+
maxBufferedWork: number | undefined;
|
|
293
|
+
/**
|
|
294
|
+
* delay before processing the next round of chunks when chunk size exceeds limits
|
|
295
|
+
*/
|
|
296
|
+
throttleDelay: number;
|
|
297
|
+
}
|
|
298
|
+
export declare function retry<T>(task: ITask<Promise<T>>, delay: number, retries: number): Promise<T>;
|
|
299
|
+
export interface ITaskSequentializerWithPendingTask {
|
|
300
|
+
readonly pending: Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
export declare class TaskSequentializer {
|
|
303
|
+
private _pending?;
|
|
304
|
+
private _next?;
|
|
305
|
+
hasPending(taskId?: number): this is ITaskSequentializerWithPendingTask;
|
|
306
|
+
get pending(): Promise<void> | undefined;
|
|
307
|
+
cancelPending(): void;
|
|
308
|
+
setPending(taskId: number, promise: Promise<void>, onCancel?: () => void): Promise<void>;
|
|
309
|
+
private donePending;
|
|
310
|
+
private triggerNext;
|
|
311
|
+
setNext(run: () => Promise<void>): Promise<void>;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The `IntervalCounter` allows to count the number
|
|
315
|
+
* of calls to `increment()` over a duration of
|
|
316
|
+
* `interval`. This utility can be used to conditionally
|
|
317
|
+
* throttle a frequent task when a certain threshold
|
|
318
|
+
* is reached.
|
|
319
|
+
*/
|
|
320
|
+
export declare class IntervalCounter {
|
|
321
|
+
private readonly interval;
|
|
322
|
+
private readonly nowFn;
|
|
323
|
+
private lastIncrementTime;
|
|
324
|
+
private value;
|
|
325
|
+
constructor(interval: number, nowFn?: () => number);
|
|
326
|
+
increment(): number;
|
|
327
|
+
}
|
|
328
|
+
export type ValueCallback<T = unknown> = (value: T | Promise<T>) => void;
|
|
329
|
+
/**
|
|
330
|
+
* Creates a promise whose resolution or rejection can be controlled imperatively.
|
|
331
|
+
*/
|
|
332
|
+
export declare class DeferredPromise<T> {
|
|
333
|
+
private completeCallback;
|
|
334
|
+
private errorCallback;
|
|
335
|
+
private rejected;
|
|
336
|
+
private resolved;
|
|
337
|
+
get isRejected(): boolean;
|
|
338
|
+
get isResolved(): boolean;
|
|
339
|
+
get isSettled(): boolean;
|
|
340
|
+
p: Promise<T>;
|
|
341
|
+
constructor();
|
|
342
|
+
complete(value: T): Promise<void>;
|
|
343
|
+
error(err: unknown): Promise<void>;
|
|
344
|
+
cancel(): void;
|
|
345
|
+
}
|
|
346
|
+
export declare namespace Promises {
|
|
347
|
+
/**
|
|
348
|
+
* A drop-in replacement for `Promise.all` with the only difference
|
|
349
|
+
* that the method awaits every promise to either fulfill or reject.
|
|
350
|
+
*
|
|
351
|
+
* Similar to `Promise.all`, only the first error will be returned
|
|
352
|
+
* if any.
|
|
353
|
+
*/
|
|
354
|
+
function settled<T>(promises: Promise<T>[]): Promise<T[]>;
|
|
355
|
+
/**
|
|
356
|
+
* A helper to create a new `Promise<T>` with a body that is a promise
|
|
357
|
+
* itself. By default, an error that raises from the async body will
|
|
358
|
+
* end up as a unhandled rejection, so this utility properly awaits the
|
|
359
|
+
* body and rejects the promise as a normal promise does without async
|
|
360
|
+
* body.
|
|
361
|
+
*
|
|
362
|
+
* This method should only be used in rare cases where otherwise `async`
|
|
363
|
+
* cannot be used (e.g. when callbacks are involved that require this).
|
|
364
|
+
*/
|
|
365
|
+
function withAsyncBody<T, E = Error>(bodyFn: (resolve: (value: T) => unknown, reject: (error: E) => unknown) => Promise<unknown>): Promise<T>;
|
|
366
|
+
}
|
|
367
|
+
export {};
|