@tstdl/base 0.86.0 → 0.87.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/application/application.d.ts +3 -3
- package/application/application.js +9 -10
- package/authentication/client/authentication.service.js +3 -3
- package/browser/browser-context-controller.d.ts +2 -2
- package/browser/browser-context-controller.js +6 -7
- package/browser/browser-controller.js +6 -7
- package/cancellation/index.d.ts +1 -0
- package/{global-this.js → cancellation/index.js} +4 -23
- package/{utils/cancellation-token.d.ts → cancellation/token.d.ts} +31 -37
- package/{utils/cancellation-token.js → cancellation/token.js} +100 -55
- package/core.d.ts +6 -5
- package/core.js +12 -13
- package/data-structures/circular-buffer.d.ts +4 -4
- package/data-structures/circular-buffer.js +10 -10
- package/database/mongo/module.js +8 -8
- package/disposable/async-disposer.d.ts +12 -11
- package/disposable/async-disposer.js +53 -27
- package/disposable/disposable.d.ts +5 -4
- package/disposable/disposable.js +9 -5
- package/distributed-loop/distributed-loop.d.ts +4 -4
- package/distributed-loop/distributed-loop.js +6 -6
- package/enumerable/async-enumerable.d.ts +2 -2
- package/enumerable/async-enumerable.js +2 -2
- package/enumerable/enumerable.d.ts +2 -2
- package/enumerable/enumerable.js +2 -2
- package/examples/api/streaming.js +3 -3
- package/http/client/adapters/undici-http-client.adapter.js +1 -1
- package/http/client/http-client-request.d.ts +5 -5
- package/http/client/http-client-request.js +9 -9
- package/http/server/node/node-http-server.js +2 -2
- package/injector/injector.d.ts +5 -2
- package/injector/injector.js +59 -23
- package/injector/interfaces.d.ts +4 -3
- package/injector/provider.d.ts +12 -12
- package/injector/resolve.error.d.ts +1 -1
- package/injector/types.d.ts +16 -7
- package/lock/mongo/lock.js +2 -2
- package/lock/web/web-lock.js +2 -2
- package/logger/console/logger.js +2 -2
- package/message-bus/message-bus-base.d.ts +2 -2
- package/message-bus/message-bus-base.js +2 -2
- package/migration/migrator.js +2 -2
- package/module/module-base.d.ts +3 -3
- package/module/module-base.js +2 -2
- package/module/module-metric-reporter.d.ts +2 -2
- package/module/module-metric-reporter.js +3 -3
- package/module/modules/function.module.d.ts +4 -4
- package/module/modules/function.module.js +2 -2
- package/module/modules/web-server.module.d.ts +2 -2
- package/module/modules/web-server.module.js +2 -2
- package/package.json +9 -8
- package/polyfills.d.ts +159 -0
- package/polyfills.js +2 -0
- package/process-shutdown.d.ts +4 -2
- package/process-shutdown.js +15 -5
- package/queue/mongo/mongo-job.repository.js +3 -4
- package/queue/mongo/queue.d.ts +5 -5
- package/queue/mongo/queue.js +7 -7
- package/queue/queue.d.ts +3 -3
- package/search-index/elastic/module.js +4 -4
- package/signals/to-signal-2.d.ts +6 -4
- package/tsconfig.json +1 -1
- package/utils/async-iterable-helpers/buffer.js +2 -2
- package/utils/async-iterable-helpers/observable-iterable.js +3 -3
- package/utils/async-iterable-helpers/take-until.d.ts +2 -2
- package/utils/async-iterable-helpers/take-until.js +7 -7
- package/utils/backoff.d.ts +7 -7
- package/utils/backoff.js +7 -7
- package/utils/event-loop.d.ts +2 -2
- package/utils/event-loop.js +2 -2
- package/utils/feedable-async-iterable.js +3 -3
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/iterable-helpers/take-until.d.ts +2 -2
- package/utils/iterable-helpers/take-until.js +2 -2
- package/utils/patch-worker.d.ts +1 -1
- package/utils/patch-worker.js +2 -2
- package/utils/periodic-reporter.js +2 -2
- package/utils/timing.d.ts +3 -3
- package/utils/timing.js +5 -5
- package/global-this.d.ts +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
1
2
|
import type { Resolvable } from '../injector/interfaces.js';
|
|
2
3
|
import { resolveArgumentType } from '../injector/interfaces.js';
|
|
3
4
|
import type { LoggerArgument } from '../logger/index.js';
|
|
4
5
|
import type { Module } from '../module/module.js';
|
|
5
6
|
import type { FunctionModuleFunction } from '../module/modules/function.module.js';
|
|
6
7
|
import type { OneOrMany, Type } from '../types.js';
|
|
7
|
-
import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
|
|
8
8
|
export type BootstrapFn = () => void | Promise<void>;
|
|
9
9
|
export type RunOptions = {
|
|
10
10
|
bootstrap?: BootstrapFn;
|
|
@@ -14,8 +14,8 @@ export declare class Application implements Resolvable<LoggerArgument> {
|
|
|
14
14
|
static _instance: Application | undefined;
|
|
15
15
|
private static get instance();
|
|
16
16
|
readonly [resolveArgumentType]: string;
|
|
17
|
-
get
|
|
18
|
-
static get
|
|
17
|
+
get shutdownSignal(): CancellationSignal;
|
|
18
|
+
static get shutdownSignal(): CancellationSignal;
|
|
19
19
|
static registerModule(moduleType: Type<Module>): void;
|
|
20
20
|
static registerModuleFunction(fn: FunctionModuleFunction): void;
|
|
21
21
|
static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
|
|
@@ -53,8 +53,8 @@ let Application = class Application2 {
|
|
|
53
53
|
static _instance;
|
|
54
54
|
static get instance() {
|
|
55
55
|
if ((0, import_type_guards.isUndefined)(this._instance)) {
|
|
56
|
-
this._instance = import_core.
|
|
57
|
-
this._instance.#shutdownToken = import_process_shutdown.
|
|
56
|
+
this._instance = (0, import_core.getGlobalInjector)().resolve(Application_1, "App");
|
|
57
|
+
this._instance.#shutdownToken = (0, import_process_shutdown.getShutdownToken)();
|
|
58
58
|
}
|
|
59
59
|
return this._instance;
|
|
60
60
|
}
|
|
@@ -63,12 +63,12 @@ let Application = class Application2 {
|
|
|
63
63
|
#logger = this.#injector.resolve(import_logger.Logger, this.#name);
|
|
64
64
|
#moduleTypesAndInstances = /* @__PURE__ */ new Set();
|
|
65
65
|
#shutdownPromise = new import_deferred_promise.DeferredPromise();
|
|
66
|
-
#shutdownToken = import_process_shutdown.
|
|
67
|
-
get
|
|
68
|
-
return this.#shutdownToken.
|
|
66
|
+
#shutdownToken = (0, import_process_shutdown.getShutdownSignal)().createChild();
|
|
67
|
+
get shutdownSignal() {
|
|
68
|
+
return this.#shutdownToken.signal;
|
|
69
69
|
}
|
|
70
|
-
static get
|
|
71
|
-
return Application_1.instance.
|
|
70
|
+
static get shutdownSignal() {
|
|
71
|
+
return Application_1.instance.shutdownSignal;
|
|
72
72
|
}
|
|
73
73
|
static registerModule(moduleType) {
|
|
74
74
|
Application_1.instance.registerModule(moduleType);
|
|
@@ -105,7 +105,7 @@ let Application = class Application2 {
|
|
|
105
105
|
await this.#shutdownPromise;
|
|
106
106
|
}
|
|
107
107
|
requestShutdown() {
|
|
108
|
-
if (this.
|
|
108
|
+
if (this.shutdownSignal.isSet) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
this.#shutdownToken.set();
|
|
@@ -128,7 +128,7 @@ let Application = class Application2 {
|
|
|
128
128
|
try {
|
|
129
129
|
await Promise.race([
|
|
130
130
|
this.runModules(modules),
|
|
131
|
-
this.
|
|
131
|
+
this.shutdownSignal
|
|
132
132
|
]);
|
|
133
133
|
} catch (error) {
|
|
134
134
|
this.#logger.error(error, { includeRest: true, includeStack: true });
|
|
@@ -137,7 +137,6 @@ let Application = class Application2 {
|
|
|
137
137
|
this.#logger.info("Shutting down");
|
|
138
138
|
await this.stopModules(modules);
|
|
139
139
|
await this.#injector.dispose();
|
|
140
|
-
await (0, import_core.disposeInstances)();
|
|
141
140
|
this.#logger.info("Bye");
|
|
142
141
|
}
|
|
143
142
|
this.#shutdownPromise.resolve();
|
|
@@ -22,6 +22,7 @@ __export(authentication_service_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(authentication_service_exports);
|
|
24
24
|
var import_rxjs = require("rxjs");
|
|
25
|
+
var import_token = require("../../cancellation/token.js");
|
|
25
26
|
var import_disposable = require("../../disposable/index.js");
|
|
26
27
|
var import_bad_request_error = require("../../error/bad-request.error.js");
|
|
27
28
|
var import_forbidden_error = require("../../error/forbidden.error.js");
|
|
@@ -34,7 +35,6 @@ var import_lock = require("../../lock/index.js");
|
|
|
34
35
|
var import_logger = require("../../logger/index.js");
|
|
35
36
|
var import_message_bus = require("../../message-bus/index.js");
|
|
36
37
|
var import_api = require("../../signals/api.js");
|
|
37
|
-
var import_cancellation_token = require("../../utils/cancellation-token.js");
|
|
38
38
|
var import_date_time = require("../../utils/date-time.js");
|
|
39
39
|
var import_timing = require("../../utils/timing.js");
|
|
40
40
|
var import_type_guards = require("../../utils/type-guards.js");
|
|
@@ -124,9 +124,9 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
124
124
|
if ((0, import_type_guards.isUndefined)(this.authenticationData)) {
|
|
125
125
|
this.authenticationData = initialAuthenticationData;
|
|
126
126
|
}
|
|
127
|
-
this.disposeToken = new
|
|
127
|
+
this.disposeToken = new import_token.CancellationToken();
|
|
128
128
|
this.errorSubject = new import_rxjs.Subject();
|
|
129
|
-
this.forceRefreshToken = new
|
|
129
|
+
this.forceRefreshToken = new import_token.CancellationToken();
|
|
130
130
|
this.error$ = this.errorSubject.asObservable();
|
|
131
131
|
this.loggedOut$ = loggedOutBus.allMessages$;
|
|
132
132
|
}
|
|
@@ -5,7 +5,7 @@ import type { Resolvable } from '../injector/interfaces.js';
|
|
|
5
5
|
import { resolveArgumentType } from '../injector/interfaces.js';
|
|
6
6
|
import type { Logger } from '../logger/logger.js';
|
|
7
7
|
import type { Record } from '../types.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Tagged } from 'type-fest';
|
|
9
9
|
import type { NewBrowserContextOptions } from './browser-controller.js';
|
|
10
10
|
import type { PageControllerOptions } from './page-controller.js';
|
|
11
11
|
import { PageController } from './page-controller.js';
|
|
@@ -16,7 +16,7 @@ export type NewPageOptions = {
|
|
|
16
16
|
extraHttpHeaders?: Record<string, string>;
|
|
17
17
|
controllerOptions?: PageControllerOptions;
|
|
18
18
|
};
|
|
19
|
-
export type BrowserContextState =
|
|
19
|
+
export type BrowserContextState = Tagged<Record<string | number, unknown>, 'BrowserContextState'>;
|
|
20
20
|
export type BrowserContextControllerArgument = NewBrowserContextOptions;
|
|
21
21
|
export declare class BrowserContextController implements AsyncDisposable, Resolvable<BrowserContextControllerArgument> {
|
|
22
22
|
/** @deprecated should be avoided */
|
|
@@ -43,8 +43,7 @@ var __metadata = function(k, v) {
|
|
|
43
43
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
44
44
|
return Reflect.metadata(k, v);
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
let BrowserContextController = BrowserContextController_1 = class BrowserContextController2 {
|
|
46
|
+
let BrowserContextController = class BrowserContextController2 {
|
|
48
47
|
/** @deprecated should be avoided */
|
|
49
48
|
context;
|
|
50
49
|
options;
|
|
@@ -95,15 +94,15 @@ let BrowserContextController = BrowserContextController_1 = class BrowserContext
|
|
|
95
94
|
(0, import_utils.attachLogger)(this.context, logger);
|
|
96
95
|
}
|
|
97
96
|
};
|
|
98
|
-
BrowserContextController =
|
|
97
|
+
BrowserContextController = __decorate([
|
|
99
98
|
(0, import_decorators.Injectable)({
|
|
100
99
|
provider: {
|
|
101
100
|
useFactory: (_, context) => {
|
|
102
|
-
context.
|
|
103
|
-
return new
|
|
101
|
+
context.data.browserController = context.resolve(import_browser_controller.BrowserController);
|
|
102
|
+
return new BrowserContextController(null);
|
|
104
103
|
},
|
|
105
|
-
async afterResolve(value, argument,
|
|
106
|
-
const { context: browserContext, controllerOptions } = await
|
|
104
|
+
async afterResolve(value, argument, { data: { browserController } }) {
|
|
105
|
+
const { context: browserContext, controllerOptions } = await browserController.newRawContext(argument);
|
|
107
106
|
value.context = browserContext;
|
|
108
107
|
value.options = controllerOptions;
|
|
109
108
|
}
|
|
@@ -44,8 +44,7 @@ var __metadata = function(k, v) {
|
|
|
44
44
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
45
45
|
return Reflect.metadata(k, v);
|
|
46
46
|
};
|
|
47
|
-
|
|
48
|
-
let BrowserController = BrowserController_1 = class BrowserController2 {
|
|
47
|
+
let BrowserController = class BrowserController2 {
|
|
49
48
|
/** @deprecated should be avoided */
|
|
50
49
|
browser;
|
|
51
50
|
options;
|
|
@@ -103,15 +102,15 @@ let BrowserController = BrowserController_1 = class BrowserController2 {
|
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
104
|
};
|
|
106
|
-
BrowserController =
|
|
105
|
+
BrowserController = __decorate([
|
|
107
106
|
(0, import_decorators.Injectable)({
|
|
108
107
|
provider: {
|
|
109
108
|
useFactory: (_argument, context) => {
|
|
110
|
-
context.
|
|
111
|
-
return new
|
|
109
|
+
context.data.browserService = (0, import_inject.inject)(import_browser_service.BrowserService);
|
|
110
|
+
return new BrowserController(null);
|
|
112
111
|
},
|
|
113
|
-
async afterResolve(value, argument,
|
|
114
|
-
const { browser, controllerOptions } = await
|
|
112
|
+
async afterResolve(value, argument, { data: { browserService } }) {
|
|
113
|
+
const { browser, controllerOptions } = await browserService.newRawBrowser(argument);
|
|
115
114
|
value.browser = browser;
|
|
116
115
|
value.options = controllerOptions;
|
|
117
116
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './token.js';
|
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,23 +11,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
11
|
}
|
|
16
12
|
return to;
|
|
17
13
|
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(global_this_exports);
|
|
24
|
-
function ensureGlobalThis() {
|
|
25
|
-
if (typeof globalThis === "object") {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
Object.defineProperty(Object.prototype, "__magic__", {
|
|
29
|
-
get() {
|
|
30
|
-
return this;
|
|
31
|
-
},
|
|
32
|
-
configurable: true
|
|
33
|
-
// this makes it possible to `delete` the getter later.
|
|
34
|
-
});
|
|
35
|
-
__magic__.globalThis = __magic__;
|
|
36
|
-
delete Object.prototype["__magic__"];
|
|
37
|
-
}
|
|
16
|
+
var cancellation_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(cancellation_exports);
|
|
18
|
+
__reExport(cancellation_exports, require("./token.js"), module.exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Observable, Observer, Subscribable,
|
|
1
|
+
import type { Observable, Observer, Subscribable, Unsubscribable } from 'rxjs';
|
|
2
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
3
|
export type ConnectConfig = {
|
|
3
4
|
/**
|
|
4
5
|
* Propagate parent set to child.
|
|
@@ -31,15 +32,8 @@ export type ConnectConfig = {
|
|
|
31
32
|
*/
|
|
32
33
|
once?: boolean;
|
|
33
34
|
};
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
* Returns whether this token set.
|
|
37
|
-
*/
|
|
38
|
-
readonly isSet: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Returns whether this token unset.
|
|
41
|
-
*/
|
|
42
|
-
readonly isUnset: boolean;
|
|
35
|
+
export declare class CancellationSignal implements PromiseLike<void>, Subscribable<void> {
|
|
36
|
+
#private;
|
|
43
37
|
/**
|
|
44
38
|
* Observable which emits the current state and every state change.
|
|
45
39
|
*/
|
|
@@ -47,23 +41,33 @@ export interface ReadonlyCancellationToken extends PromiseLike<void>, Subscribab
|
|
|
47
41
|
/**
|
|
48
42
|
* Observable which emits when this token is set.
|
|
49
43
|
*/
|
|
50
|
-
readonly set$: Observable<
|
|
44
|
+
readonly set$: Observable<undefined>;
|
|
51
45
|
/**
|
|
52
46
|
* Observable which emits when this token is unset.
|
|
53
47
|
*/
|
|
54
|
-
readonly unset$: Observable<
|
|
48
|
+
readonly unset$: Observable<undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a promise which is resolved when this token changes its state.
|
|
51
|
+
*/
|
|
52
|
+
get $state(): Promise<boolean>;
|
|
55
53
|
/**
|
|
56
54
|
* Returns a promise which is resolved when this token is set.
|
|
57
55
|
*/
|
|
58
|
-
|
|
56
|
+
get $set(): Promise<void>;
|
|
59
57
|
/**
|
|
60
58
|
* Returns a promise which is resolved when this token is unset.
|
|
61
59
|
*/
|
|
62
|
-
|
|
60
|
+
get $unset(): Promise<void>;
|
|
61
|
+
get state(): boolean;
|
|
63
62
|
/**
|
|
64
|
-
*
|
|
63
|
+
* Whether this token is set.
|
|
65
64
|
*/
|
|
66
|
-
|
|
65
|
+
get isSet(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Whether this token is unset.
|
|
68
|
+
*/
|
|
69
|
+
get isUnset(): boolean;
|
|
70
|
+
constructor(stateSubject: BehaviorSubject<boolean>);
|
|
67
71
|
/**
|
|
68
72
|
* Returns an AbortSignal.
|
|
69
73
|
*/
|
|
@@ -74,21 +78,17 @@ export interface ReadonlyCancellationToken extends PromiseLike<void>, Subscribab
|
|
|
74
78
|
*/
|
|
75
79
|
createChild(config?: ConnectConfig): CancellationToken;
|
|
76
80
|
/**
|
|
77
|
-
* Propagate events from this instance to
|
|
78
|
-
* @param
|
|
81
|
+
* Propagate events from this instance to `target`. Events from the `target` are *not* propagated to this instance.
|
|
82
|
+
* @param target receiver to connect
|
|
79
83
|
*/
|
|
80
|
-
connect(
|
|
84
|
+
connect(target: CancellationToken, config?: ConnectConfig): void;
|
|
85
|
+
then<TResult>(onfulfilled?: ((value: void) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TResult>;
|
|
86
|
+
subscribe(observer: Partial<Observer<void>>): Unsubscribable;
|
|
81
87
|
}
|
|
82
|
-
export declare class CancellationToken
|
|
83
|
-
private
|
|
84
|
-
|
|
85
|
-
readonly
|
|
86
|
-
readonly unset$: Observable<void>;
|
|
87
|
-
get isSet(): boolean;
|
|
88
|
-
get isUnset(): boolean;
|
|
89
|
-
get $set(): Promise<void>;
|
|
90
|
-
get $unset(): Promise<void>;
|
|
91
|
-
get $state(): Promise<boolean>;
|
|
88
|
+
export declare class CancellationToken extends CancellationSignal {
|
|
89
|
+
#private;
|
|
90
|
+
/** Signal for this token */
|
|
91
|
+
readonly signal: CancellationSignal;
|
|
92
92
|
/**
|
|
93
93
|
* @param initialState which state to initialze this token to
|
|
94
94
|
* - `false`: unset
|
|
@@ -109,15 +109,11 @@ export declare class CancellationToken implements ReadonlyCancellationToken {
|
|
|
109
109
|
* @param observable observable to subscribe. Takes emitted value as state if type is boolean otherwise sets state to true.
|
|
110
110
|
*/
|
|
111
111
|
static from(source: Observable<boolean>, config?: ConnectConfig): CancellationToken;
|
|
112
|
-
|
|
113
|
-
asAbortSignal(): AbortSignal;
|
|
114
|
-
asReadonly(): ReadonlyCancellationToken;
|
|
115
|
-
createChild(config?: ConnectConfig): CancellationToken;
|
|
116
|
-
connect(child: CancellationToken, config?: ConnectConfig): void;
|
|
112
|
+
static connect(state$: Observable<boolean>, target: CancellationToken, config?: ConnectConfig): void;
|
|
117
113
|
/**
|
|
118
114
|
* Become a child of the provided parent. Events from the parent are propagated to this token. Events from this token are *not* propagated to the parent.
|
|
119
115
|
*/
|
|
120
|
-
inherit(parent:
|
|
116
|
+
inherit(parent: CancellationToken | CancellationSignal, config?: ConnectConfig): this;
|
|
121
117
|
/**
|
|
122
118
|
* Set this token.
|
|
123
119
|
*/
|
|
@@ -140,6 +136,4 @@ export declare class CancellationToken implements ReadonlyCancellationToken {
|
|
|
140
136
|
* Keep in mind that *active* awaits (promise) on this token will throw.
|
|
141
137
|
*/
|
|
142
138
|
complete(): void;
|
|
143
|
-
then<TResult>(onfulfilled?: ((value: void) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TResult>;
|
|
144
|
-
subscribe(observer: Partial<Observer<void>>): Subscription;
|
|
145
139
|
}
|
|
@@ -16,35 +16,102 @@ var __copyProps = (to, from2, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var token_exports = {};
|
|
20
|
+
__export(token_exports, {
|
|
21
|
+
CancellationSignal: () => CancellationSignal,
|
|
21
22
|
CancellationToken: () => CancellationToken
|
|
22
23
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
var import_noop = require("../rxjs/noop.js");
|
|
24
|
+
module.exports = __toCommonJS(token_exports);
|
|
25
25
|
var import_rxjs = require("rxjs");
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
var import_noop = require("../rxjs/noop.js");
|
|
27
|
+
var import_noop2 = require("../utils/noop.js");
|
|
28
|
+
var import_type_guards = require("../utils/type-guards.js");
|
|
29
|
+
class CancellationSignal {
|
|
30
|
+
#stateSubject;
|
|
31
|
+
/**
|
|
32
|
+
* Observable which emits the current state and every state change.
|
|
33
|
+
*/
|
|
34
|
+
state$ = (0, import_rxjs.defer)(() => this.#stateSubject);
|
|
35
|
+
/**
|
|
36
|
+
* Observable which emits when this token is set.
|
|
37
|
+
*/
|
|
38
|
+
set$ = this.state$.pipe((0, import_rxjs.filter)((state) => state), (0, import_rxjs.map)(() => void 0));
|
|
39
|
+
/**
|
|
40
|
+
* Observable which emits when this token is unset.
|
|
41
|
+
*/
|
|
42
|
+
unset$ = this.state$.pipe((0, import_rxjs.filter)((state) => !state), (0, import_rxjs.map)(() => void 0));
|
|
43
|
+
/**
|
|
44
|
+
* Returns a promise which is resolved when this token changes its state.
|
|
45
|
+
*/
|
|
46
|
+
get $state() {
|
|
47
|
+
return (0, import_rxjs.firstValueFrom)(this.state$.pipe((0, import_rxjs.skip)(1)));
|
|
38
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns a promise which is resolved when this token is set.
|
|
51
|
+
*/
|
|
39
52
|
get $set() {
|
|
40
53
|
return (0, import_rxjs.firstValueFrom)(this.set$);
|
|
41
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a promise which is resolved when this token is unset.
|
|
57
|
+
*/
|
|
42
58
|
get $unset() {
|
|
43
59
|
return (0, import_rxjs.firstValueFrom)(this.unset$);
|
|
44
60
|
}
|
|
45
|
-
get
|
|
46
|
-
return
|
|
61
|
+
get state() {
|
|
62
|
+
return this.#stateSubject.value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether this token is set.
|
|
66
|
+
*/
|
|
67
|
+
get isSet() {
|
|
68
|
+
return this.#stateSubject.value;
|
|
47
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether this token is unset.
|
|
72
|
+
*/
|
|
73
|
+
get isUnset() {
|
|
74
|
+
return !this.#stateSubject.value;
|
|
75
|
+
}
|
|
76
|
+
constructor(stateSubject) {
|
|
77
|
+
this.#stateSubject = stateSubject;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns an AbortSignal.
|
|
81
|
+
*/
|
|
82
|
+
asAbortSignal() {
|
|
83
|
+
const abortController = new AbortController();
|
|
84
|
+
this.set$.pipe((0, import_rxjs.first)()).subscribe(() => abortController.abort());
|
|
85
|
+
return abortController.signal;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a new token and connect it to this instance.
|
|
89
|
+
* @see {@link connect}
|
|
90
|
+
*/
|
|
91
|
+
createChild(config) {
|
|
92
|
+
const child = new CancellationToken();
|
|
93
|
+
this.connect(child, config);
|
|
94
|
+
return child;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Propagate events from this instance to `target`. Events from the `target` are *not* propagated to this instance.
|
|
98
|
+
* @param target receiver to connect
|
|
99
|
+
*/
|
|
100
|
+
connect(target, config) {
|
|
101
|
+
CancellationToken.connect(this.state$, target, config);
|
|
102
|
+
}
|
|
103
|
+
async then(onfulfilled) {
|
|
104
|
+
await this.$set;
|
|
105
|
+
return onfulfilled?.();
|
|
106
|
+
}
|
|
107
|
+
subscribe(observer) {
|
|
108
|
+
return this.set$.subscribe(observer);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
class CancellationToken extends CancellationSignal {
|
|
112
|
+
#stateSubject;
|
|
113
|
+
/** Signal for this token */
|
|
114
|
+
signal;
|
|
48
115
|
/**
|
|
49
116
|
* @param initialState which state to initialze this token to
|
|
50
117
|
* - `false`: unset
|
|
@@ -52,10 +119,10 @@ class CancellationToken {
|
|
|
52
119
|
* @default false
|
|
53
120
|
*/
|
|
54
121
|
constructor(initialState = false) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this
|
|
58
|
-
this.
|
|
122
|
+
const stateSubject = new import_rxjs.BehaviorSubject(initialState);
|
|
123
|
+
super(stateSubject);
|
|
124
|
+
this.#stateSubject = new import_rxjs.BehaviorSubject(initialState);
|
|
125
|
+
this.signal = new CancellationSignal(this.#stateSubject);
|
|
59
126
|
}
|
|
60
127
|
static from(source, config) {
|
|
61
128
|
const source$ = source instanceof AbortSignal ? (0, import_rxjs.fromEvent)(source, "abort", () => true) : (0, import_rxjs.isObservable)(source) ? source.pipe((0, import_rxjs.map)((state) => (0, import_type_guards.isBoolean)(state) ? state : true)) : (0, import_rxjs.from)(source).pipe((0, import_rxjs.map)(() => true));
|
|
@@ -63,65 +130,50 @@ class CancellationToken {
|
|
|
63
130
|
CancellationToken.connect(source$, token, config);
|
|
64
131
|
return token;
|
|
65
132
|
}
|
|
66
|
-
static connect(
|
|
133
|
+
static connect(state$, target, config = {}) {
|
|
67
134
|
const { set = true, unset = true, complete = true, error = true, immediate = true, once = false } = config;
|
|
68
|
-
const
|
|
69
|
-
const subscription =
|
|
135
|
+
const stateObservable = state$.pipe(immediate ? (0, import_noop.noopOperator)() : (0, import_rxjs.skip)(1), set && unset ? (0, import_noop.noopOperator)() : set ? (0, import_rxjs.filter)((state) => state) : unset ? (0, import_rxjs.filter)((state) => !state) : (0, import_rxjs.filter)(() => false), once ? (0, import_rxjs.take)(1) : (0, import_noop.noopOperator)());
|
|
136
|
+
const subscription = stateObservable.subscribe({
|
|
70
137
|
next: (state) => target.setState(state),
|
|
71
138
|
error: error ? (errorValue) => target.error(errorValue) : import_noop2.noop,
|
|
72
139
|
complete: complete ? () => target.complete() : import_noop2.noop
|
|
73
140
|
});
|
|
74
|
-
target
|
|
141
|
+
target.#stateSubject.subscribe({
|
|
75
142
|
error: () => subscription.unsubscribe(),
|
|
76
143
|
complete: () => subscription.unsubscribe()
|
|
77
144
|
});
|
|
78
145
|
}
|
|
79
|
-
asAbortSignal() {
|
|
80
|
-
const abortController = new AbortController();
|
|
81
|
-
this.set$.pipe((0, import_rxjs.first)()).subscribe(() => abortController.abort());
|
|
82
|
-
return abortController.signal;
|
|
83
|
-
}
|
|
84
|
-
asReadonly() {
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
createChild(config) {
|
|
88
|
-
const child = new CancellationToken();
|
|
89
|
-
this.connect(child, config);
|
|
90
|
-
return child;
|
|
91
|
-
}
|
|
92
|
-
connect(child, config) {
|
|
93
|
-
CancellationToken.connect(this.state$, child, config);
|
|
94
|
-
}
|
|
95
146
|
/**
|
|
96
147
|
* Become a child of the provided parent. Events from the parent are propagated to this token. Events from this token are *not* propagated to the parent.
|
|
97
148
|
*/
|
|
98
149
|
inherit(parent, config) {
|
|
99
|
-
|
|
150
|
+
const state$ = (parent instanceof CancellationToken ? parent.signal : parent).state$;
|
|
151
|
+
CancellationToken.connect(state$, this, config);
|
|
100
152
|
return this;
|
|
101
153
|
}
|
|
102
154
|
/**
|
|
103
155
|
* Set this token.
|
|
104
156
|
*/
|
|
105
157
|
set() {
|
|
106
|
-
this.
|
|
158
|
+
this.setState(true);
|
|
107
159
|
}
|
|
108
160
|
/**
|
|
109
161
|
* Unset this token.
|
|
110
162
|
*/
|
|
111
163
|
unset() {
|
|
112
|
-
this.
|
|
164
|
+
this.setState(false);
|
|
113
165
|
}
|
|
114
166
|
/**
|
|
115
167
|
* Set the state.
|
|
116
168
|
*/
|
|
117
169
|
setState(state) {
|
|
118
|
-
this
|
|
170
|
+
this.#stateSubject.next(state);
|
|
119
171
|
}
|
|
120
172
|
/**
|
|
121
173
|
* Errors the token.
|
|
122
174
|
*/
|
|
123
175
|
error(error) {
|
|
124
|
-
this
|
|
176
|
+
this.#stateSubject.error(error);
|
|
125
177
|
}
|
|
126
178
|
/**
|
|
127
179
|
* Clean up subscriptions.
|
|
@@ -129,13 +181,6 @@ class CancellationToken {
|
|
|
129
181
|
* Keep in mind that *active* awaits (promise) on this token will throw.
|
|
130
182
|
*/
|
|
131
183
|
complete() {
|
|
132
|
-
this
|
|
133
|
-
}
|
|
134
|
-
async then(onfulfilled) {
|
|
135
|
-
await this.$set;
|
|
136
|
-
return onfulfilled?.();
|
|
137
|
-
}
|
|
138
|
-
subscribe(observer) {
|
|
139
|
-
return this.set$.subscribe(observer);
|
|
184
|
+
this.#stateSubject.complete();
|
|
140
185
|
}
|
|
141
186
|
}
|
package/core.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CancellationSignal } from './cancellation/token.js';
|
|
2
2
|
import { Injector } from './injector/injector.js';
|
|
3
3
|
import type { InjectionToken } from './injector/token.js';
|
|
4
4
|
import type { LoggerArgument } from './logger/index.js';
|
|
5
5
|
import { LogLevel, Logger } from './logger/index.js';
|
|
6
6
|
export declare const CORE_LOGGER: InjectionToken<Logger, never>;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Should be avoided. Use `Application` scoped injector instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getGlobalInjector(): Injector;
|
|
9
11
|
export declare function isDevMode(): boolean;
|
|
10
12
|
export declare function isProdMode(): boolean;
|
|
11
13
|
export declare function enableProdMode(): void;
|
|
12
|
-
export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger, maxTries?: number): Promise<void>;
|
|
13
|
-
export declare function disposeInstances(): Promise<void>;
|
|
14
|
+
export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger, cancellationSignal: CancellationSignal, maxTries?: number): Promise<void>;
|
|
14
15
|
export type CoreConfiguration = {
|
|
15
16
|
production?: boolean;
|
|
16
17
|
logger?: InjectionToken<Logger, LoggerArgument>;
|
package/core.js
CHANGED
|
@@ -21,15 +21,12 @@ __export(core_exports, {
|
|
|
21
21
|
CORE_LOGGER: () => CORE_LOGGER,
|
|
22
22
|
configureTstdl: () => configureTstdl,
|
|
23
23
|
connect: () => connect,
|
|
24
|
-
disposeInstances: () => disposeInstances,
|
|
25
|
-
disposer: () => disposer,
|
|
26
24
|
enableProdMode: () => enableProdMode,
|
|
25
|
+
getGlobalInjector: () => getGlobalInjector,
|
|
27
26
|
isDevMode: () => isDevMode,
|
|
28
|
-
isProdMode: () => isProdMode
|
|
29
|
-
rootInjector: () => rootInjector
|
|
27
|
+
isProdMode: () => isProdMode
|
|
30
28
|
});
|
|
31
29
|
module.exports = __toCommonJS(core_exports);
|
|
32
|
-
var import_async_disposer = require("./disposable/async-disposer.js");
|
|
33
30
|
var import_injector = require("./injector/injector.js");
|
|
34
31
|
var import_token = require("./injector/token.js");
|
|
35
32
|
var import_logger = require("./logger/console/logger.js");
|
|
@@ -38,9 +35,14 @@ var import_process_shutdown = require("./process-shutdown.js");
|
|
|
38
35
|
var import_timing = require("./utils/timing.js");
|
|
39
36
|
var import_type_guards = require("./utils/type-guards.js");
|
|
40
37
|
const CORE_LOGGER = (0, import_token.injectionToken)("core logger");
|
|
41
|
-
|
|
42
|
-
const disposer = new import_async_disposer.AsyncDisposer();
|
|
38
|
+
let globalInjector;
|
|
43
39
|
let _isDevMode = true;
|
|
40
|
+
function getGlobalInjector() {
|
|
41
|
+
if ((0, import_type_guards.isUndefined)(globalInjector)) {
|
|
42
|
+
globalInjector = new import_injector.Injector("GlobalInjector");
|
|
43
|
+
}
|
|
44
|
+
return globalInjector;
|
|
45
|
+
}
|
|
44
46
|
function isDevMode() {
|
|
45
47
|
return _isDevMode;
|
|
46
48
|
}
|
|
@@ -50,10 +52,10 @@ function isProdMode() {
|
|
|
50
52
|
function enableProdMode() {
|
|
51
53
|
_isDevMode = false;
|
|
52
54
|
}
|
|
53
|
-
async function connect(name, connectFunction, logger, maxTries = 5) {
|
|
55
|
+
async function connect(name, connectFunction, logger, cancellationSignal, maxTries = 5) {
|
|
54
56
|
let triesLeft = maxTries;
|
|
55
57
|
let success = false;
|
|
56
|
-
while (!success &&
|
|
58
|
+
while (!success && cancellationSignal.isUnset && triesLeft-- > 0) {
|
|
57
59
|
try {
|
|
58
60
|
logger.verbose(`connecting to ${name}...`);
|
|
59
61
|
await connectFunction();
|
|
@@ -69,15 +71,12 @@ async function connect(name, connectFunction, logger, maxTries = 5) {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
async function disposeInstances() {
|
|
73
|
-
await disposer.dispose();
|
|
74
|
-
}
|
|
75
74
|
let coreLogPrefix;
|
|
76
75
|
function configureTstdl(config = {}) {
|
|
77
76
|
if (config.production == true) {
|
|
78
77
|
enableProdMode();
|
|
79
78
|
}
|
|
80
|
-
const logger =
|
|
79
|
+
const logger = getGlobalInjector().resolve(CORE_LOGGER);
|
|
81
80
|
(0, import_process_shutdown.setProcessShutdownLogger)(logger);
|
|
82
81
|
(0, import_process_shutdown.initializeSignals)();
|
|
83
82
|
import_injector.Injector.register(import_logger2.Logger, { useToken: config.logger ?? import_logger.ConsoleLogger });
|