@tstdl/base 0.86.1 → 0.87.1
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 -9
- package/authentication/client/authentication.service.js +3 -3
- package/cancellation/index.d.ts +1 -0
- package/cancellation/index.js +18 -0
- package/{utils/cancellation-token.d.ts → cancellation/token.d.ts} +33 -41
- package/{utils/cancellation-token.js → cancellation/token.js} +93 -49
- package/core.d.ts +6 -3
- package/core.js +12 -6
- package/data-structures/circular-buffer.d.ts +4 -4
- package/data-structures/circular-buffer.js +10 -10
- package/database/mongo/module.js +2 -2
- package/disposable/async-disposer.d.ts +4 -4
- package/disposable/async-disposer.js +6 -6
- 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.js +5 -5
- package/injector/types.d.ts +3 -3
- package/lock/mongo/lock.js +2 -2
- package/lock/web/web-lock.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 +4 -4
- package/process-shutdown.d.ts +4 -2
- package/process-shutdown.js +15 -5
- 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 +2 -2
- package/signals/to-signal-2.d.ts +6 -4
- package/utils/async-iterable-helpers/buffer.js +2 -2
- package/utils/async-iterable-helpers/metadata.d.ts +0 -2
- package/utils/async-iterable-helpers/metadata.js +1 -3
- package/utils/async-iterable-helpers/observable-iterable.js +3 -3
- package/utils/async-iterable-helpers/skip.js +2 -2
- package/utils/async-iterable-helpers/take-until.d.ts +2 -2
- package/utils/async-iterable-helpers/take-until.js +7 -7
- package/utils/async-iterable-helpers/take.js +17 -1
- 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
|
@@ -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 });
|
|
@@ -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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './token.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
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,66 +32,63 @@ export type ConnectConfig = {
|
|
|
31
32
|
*/
|
|
32
33
|
once?: boolean;
|
|
33
34
|
};
|
|
34
|
-
export declare
|
|
35
|
-
|
|
36
|
-
* Returns whether this token set.
|
|
37
|
-
*/
|
|
38
|
-
abstract readonly isSet: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Returns whether this token unset.
|
|
41
|
-
*/
|
|
42
|
-
abstract 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
|
*/
|
|
46
|
-
|
|
40
|
+
readonly state$: Observable<boolean>;
|
|
47
41
|
/**
|
|
48
42
|
* Observable which emits when this token is set.
|
|
49
43
|
*/
|
|
50
|
-
|
|
44
|
+
readonly set$: Observable<undefined>;
|
|
51
45
|
/**
|
|
52
46
|
* Observable which emits when this token is unset.
|
|
53
47
|
*/
|
|
54
|
-
|
|
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
|
*/
|
|
70
|
-
|
|
74
|
+
asAbortSignal(): AbortSignal;
|
|
71
75
|
/**
|
|
72
76
|
* Create a new token and connect it to this instance.
|
|
73
77
|
* @see {@link connect}
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
|
83
87
|
}
|
|
84
|
-
export declare class CancellationToken extends
|
|
88
|
+
export declare class CancellationToken extends CancellationSignal {
|
|
85
89
|
#private;
|
|
86
|
-
|
|
87
|
-
readonly
|
|
88
|
-
readonly unset$: Observable<undefined>;
|
|
89
|
-
get isSet(): boolean;
|
|
90
|
-
get isUnset(): boolean;
|
|
91
|
-
get $set(): Promise<void>;
|
|
92
|
-
get $unset(): Promise<void>;
|
|
93
|
-
get $state(): Promise<boolean>;
|
|
90
|
+
/** Signal for this token */
|
|
91
|
+
readonly signal: CancellationSignal;
|
|
94
92
|
/**
|
|
95
93
|
* @param initialState which state to initialze this token to
|
|
96
94
|
* - `false`: unset
|
|
@@ -111,15 +109,11 @@ export declare class CancellationToken extends ReadonlyCancellationToken {
|
|
|
111
109
|
* @param observable observable to subscribe. Takes emitted value as state if type is boolean otherwise sets state to true.
|
|
112
110
|
*/
|
|
113
111
|
static from(source: Observable<boolean>, config?: ConnectConfig): CancellationToken;
|
|
114
|
-
|
|
115
|
-
asAbortSignal(): AbortSignal;
|
|
116
|
-
asReadonly(): ReadonlyCancellationToken;
|
|
117
|
-
createChild(config?: ConnectConfig): CancellationToken;
|
|
118
|
-
connect(child: CancellationToken, config?: ConnectConfig): void;
|
|
112
|
+
static connect(state$: Observable<boolean>, target: CancellationToken, config?: ConnectConfig): void;
|
|
119
113
|
/**
|
|
120
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.
|
|
121
115
|
*/
|
|
122
|
-
inherit(parent:
|
|
116
|
+
inherit(parent: CancellationToken | CancellationSignal, config?: ConnectConfig): this;
|
|
123
117
|
/**
|
|
124
118
|
* Set this token.
|
|
125
119
|
*/
|
|
@@ -142,6 +136,4 @@ export declare class CancellationToken extends ReadonlyCancellationToken {
|
|
|
142
136
|
* Keep in mind that *active* awaits (promise) on this token will throw.
|
|
143
137
|
*/
|
|
144
138
|
complete(): void;
|
|
145
|
-
then<TResult>(onfulfilled?: ((value: void) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TResult>;
|
|
146
|
-
subscribe(observer: Partial<Observer<void>>): Subscription;
|
|
147
139
|
}
|
|
@@ -16,38 +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(
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
var token_exports = {};
|
|
20
|
+
__export(token_exports, {
|
|
21
|
+
CancellationSignal: () => CancellationSignal,
|
|
22
|
+
CancellationToken: () => CancellationToken
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(token_exports);
|
|
25
25
|
var import_rxjs = require("rxjs");
|
|
26
26
|
var import_noop = require("../rxjs/noop.js");
|
|
27
|
-
var import_noop2 = require("
|
|
28
|
-
var import_type_guards = require("
|
|
29
|
-
class
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
*/
|
|
34
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
|
+
*/
|
|
35
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)));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns a promise which is resolved when this token is set.
|
|
51
|
+
*/
|
|
52
|
+
get $set() {
|
|
53
|
+
return (0, import_rxjs.firstValueFrom)(this.set$);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a promise which is resolved when this token is unset.
|
|
57
|
+
*/
|
|
58
|
+
get $unset() {
|
|
59
|
+
return (0, import_rxjs.firstValueFrom)(this.unset$);
|
|
60
|
+
}
|
|
61
|
+
get state() {
|
|
62
|
+
return this.#stateSubject.value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether this token is set.
|
|
66
|
+
*/
|
|
36
67
|
get isSet() {
|
|
37
68
|
return this.#stateSubject.value;
|
|
38
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether this token is unset.
|
|
72
|
+
*/
|
|
39
73
|
get isUnset() {
|
|
40
74
|
return !this.#stateSubject.value;
|
|
41
75
|
}
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
constructor(stateSubject) {
|
|
77
|
+
this.#stateSubject = stateSubject;
|
|
44
78
|
}
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
86
|
}
|
|
48
|
-
|
|
49
|
-
|
|
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;
|
|
50
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;
|
|
51
115
|
/**
|
|
52
116
|
* @param initialState which state to initialze this token to
|
|
53
117
|
* - `false`: unset
|
|
@@ -55,8 +119,10 @@ class CancellationToken extends ReadonlyCancellationToken {
|
|
|
55
119
|
* @default false
|
|
56
120
|
*/
|
|
57
121
|
constructor(initialState = false) {
|
|
58
|
-
|
|
59
|
-
|
|
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);
|
|
60
126
|
}
|
|
61
127
|
static from(source, config) {
|
|
62
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));
|
|
@@ -64,10 +130,10 @@ class CancellationToken extends ReadonlyCancellationToken {
|
|
|
64
130
|
CancellationToken.connect(source$, token, config);
|
|
65
131
|
return token;
|
|
66
132
|
}
|
|
67
|
-
static connect(
|
|
133
|
+
static connect(state$, target, config = {}) {
|
|
68
134
|
const { set = true, unset = true, complete = true, error = true, immediate = true, once = false } = config;
|
|
69
|
-
const
|
|
70
|
-
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({
|
|
71
137
|
next: (state) => target.setState(state),
|
|
72
138
|
error: error ? (errorValue) => target.error(errorValue) : import_noop2.noop,
|
|
73
139
|
complete: complete ? () => target.complete() : import_noop2.noop
|
|
@@ -77,40 +143,25 @@ class CancellationToken extends ReadonlyCancellationToken {
|
|
|
77
143
|
complete: () => subscription.unsubscribe()
|
|
78
144
|
});
|
|
79
145
|
}
|
|
80
|
-
asAbortSignal() {
|
|
81
|
-
const abortController = new AbortController();
|
|
82
|
-
this.set$.pipe((0, import_rxjs.first)()).subscribe(() => abortController.abort());
|
|
83
|
-
return abortController.signal;
|
|
84
|
-
}
|
|
85
|
-
asReadonly() {
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
createChild(config) {
|
|
89
|
-
const child = new CancellationToken();
|
|
90
|
-
this.connect(child, config);
|
|
91
|
-
return child;
|
|
92
|
-
}
|
|
93
|
-
connect(child, config) {
|
|
94
|
-
CancellationToken.connect(this.state$, child, config);
|
|
95
|
-
}
|
|
96
146
|
/**
|
|
97
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.
|
|
98
148
|
*/
|
|
99
149
|
inherit(parent, config) {
|
|
100
|
-
|
|
150
|
+
const state$ = (parent instanceof CancellationToken ? parent.signal : parent).state$;
|
|
151
|
+
CancellationToken.connect(state$, this, config);
|
|
101
152
|
return this;
|
|
102
153
|
}
|
|
103
154
|
/**
|
|
104
155
|
* Set this token.
|
|
105
156
|
*/
|
|
106
157
|
set() {
|
|
107
|
-
this
|
|
158
|
+
this.setState(true);
|
|
108
159
|
}
|
|
109
160
|
/**
|
|
110
161
|
* Unset this token.
|
|
111
162
|
*/
|
|
112
163
|
unset() {
|
|
113
|
-
this
|
|
164
|
+
this.setState(false);
|
|
114
165
|
}
|
|
115
166
|
/**
|
|
116
167
|
* Set the state.
|
|
@@ -132,11 +183,4 @@ class CancellationToken extends ReadonlyCancellationToken {
|
|
|
132
183
|
complete() {
|
|
133
184
|
this.#stateSubject.complete();
|
|
134
185
|
}
|
|
135
|
-
async then(onfulfilled) {
|
|
136
|
-
await this.$set;
|
|
137
|
-
return onfulfilled?.();
|
|
138
|
-
}
|
|
139
|
-
subscribe(observer) {
|
|
140
|
-
return this.set$.subscribe(observer);
|
|
141
|
-
}
|
|
142
186
|
}
|
package/core.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import type { CancellationSignal } from './cancellation/token.js';
|
|
1
2
|
import { Injector } from './injector/injector.js';
|
|
2
3
|
import type { InjectionToken } from './injector/token.js';
|
|
3
4
|
import type { LoggerArgument } from './logger/index.js';
|
|
4
5
|
import { LogLevel, Logger } from './logger/index.js';
|
|
5
|
-
import type { ReadonlyCancellationToken } from './utils/cancellation-token.js';
|
|
6
6
|
export declare const CORE_LOGGER: InjectionToken<Logger, never>;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Should be avoided. Use `Application` scoped injector instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getGlobalInjector(): Injector;
|
|
8
11
|
export declare function isDevMode(): boolean;
|
|
9
12
|
export declare function isProdMode(): boolean;
|
|
10
13
|
export declare function enableProdMode(): void;
|
|
11
|
-
export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger,
|
|
14
|
+
export declare function connect(name: string, connectFunction: (() => Promise<any>), logger: Logger, cancellationSignal: CancellationSignal, maxTries?: number): Promise<void>;
|
|
12
15
|
export type CoreConfiguration = {
|
|
13
16
|
production?: boolean;
|
|
14
17
|
logger?: InjectionToken<Logger, LoggerArgument>;
|
package/core.js
CHANGED
|
@@ -22,9 +22,9 @@ __export(core_exports, {
|
|
|
22
22
|
configureTstdl: () => configureTstdl,
|
|
23
23
|
connect: () => connect,
|
|
24
24
|
enableProdMode: () => enableProdMode,
|
|
25
|
+
getGlobalInjector: () => getGlobalInjector,
|
|
25
26
|
isDevMode: () => isDevMode,
|
|
26
|
-
isProdMode: () => isProdMode
|
|
27
|
-
rootInjector: () => rootInjector
|
|
27
|
+
isProdMode: () => isProdMode
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(core_exports);
|
|
30
30
|
var import_injector = require("./injector/injector.js");
|
|
@@ -35,8 +35,14 @@ var import_process_shutdown = require("./process-shutdown.js");
|
|
|
35
35
|
var import_timing = require("./utils/timing.js");
|
|
36
36
|
var import_type_guards = require("./utils/type-guards.js");
|
|
37
37
|
const CORE_LOGGER = (0, import_token.injectionToken)("core logger");
|
|
38
|
-
|
|
38
|
+
let globalInjector;
|
|
39
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
|
+
}
|
|
40
46
|
function isDevMode() {
|
|
41
47
|
return _isDevMode;
|
|
42
48
|
}
|
|
@@ -46,10 +52,10 @@ function isProdMode() {
|
|
|
46
52
|
function enableProdMode() {
|
|
47
53
|
_isDevMode = false;
|
|
48
54
|
}
|
|
49
|
-
async function connect(name, connectFunction, logger,
|
|
55
|
+
async function connect(name, connectFunction, logger, cancellationSignal, maxTries = 5) {
|
|
50
56
|
let triesLeft = maxTries;
|
|
51
57
|
let success = false;
|
|
52
|
-
while (!success &&
|
|
58
|
+
while (!success && cancellationSignal.isUnset && triesLeft-- > 0) {
|
|
53
59
|
try {
|
|
54
60
|
logger.verbose(`connecting to ${name}...`);
|
|
55
61
|
await connectFunction();
|
|
@@ -70,7 +76,7 @@ function configureTstdl(config = {}) {
|
|
|
70
76
|
if (config.production == true) {
|
|
71
77
|
enableProdMode();
|
|
72
78
|
}
|
|
73
|
-
const logger =
|
|
79
|
+
const logger = getGlobalInjector().resolve(CORE_LOGGER);
|
|
74
80
|
(0, import_process_shutdown.setProcessShutdownLogger)(logger);
|
|
75
81
|
(0, import_process_shutdown.initializeSignals)();
|
|
76
82
|
import_injector.Injector.register(import_logger2.Logger, { useToken: config.logger ?? import_logger.ConsoleLogger });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
3
|
import { Collection } from './collection.js';
|
|
4
4
|
export declare class CircularBuffer<T> extends Collection<T, CircularBuffer<T>> {
|
|
@@ -45,11 +45,11 @@ export declare class CircularBuffer<T> extends Collection<T, CircularBuffer<T>>
|
|
|
45
45
|
consume(): IterableIterator<T>;
|
|
46
46
|
/**
|
|
47
47
|
* yields all items from the buffer, removes them and waits fore more
|
|
48
|
-
* @param
|
|
49
|
-
* @param yieldOutstandingItems whether to yield all outstanding items or exit immdiately when {@link
|
|
48
|
+
* @param cancellationSignal token to cancel iteration
|
|
49
|
+
* @param yieldOutstandingItems whether to yield all outstanding items or exit immdiately when {@link cancellationSignal} is set
|
|
50
50
|
* @returns
|
|
51
51
|
*/
|
|
52
|
-
consumeAsync(
|
|
52
|
+
consumeAsync(cancellationSignal?: CancellationSignal, yieldOutstandingItems?: boolean): AsyncIterable<T>;
|
|
53
53
|
protected _clear(): void;
|
|
54
54
|
private increaseBufferSizeIfNeeded;
|
|
55
55
|
private resize;
|
|
@@ -21,7 +21,7 @@ __export(circular_buffer_exports, {
|
|
|
21
21
|
CircularBuffer: () => CircularBuffer
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(circular_buffer_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_token = require("../cancellation/token.js");
|
|
25
25
|
var import_type_guards = require("../utils/type-guards.js");
|
|
26
26
|
var import_rxjs = require("rxjs");
|
|
27
27
|
var import_collection = require("./collection.js");
|
|
@@ -133,7 +133,7 @@ class CircularBuffer extends import_collection.Collection {
|
|
|
133
133
|
}
|
|
134
134
|
clone(newMaxBufferSize = this.maxBufferSize) {
|
|
135
135
|
if ((0, import_type_guards.isDefined)(newMaxBufferSize) && newMaxBufferSize < this.size) {
|
|
136
|
-
throw new Error("newSize must be equal or larger to current size");
|
|
136
|
+
throw new Error("newSize must be equal or larger to current size.");
|
|
137
137
|
}
|
|
138
138
|
const cloned = new CircularBuffer(newMaxBufferSize);
|
|
139
139
|
cloned.addMany(this);
|
|
@@ -147,7 +147,7 @@ class CircularBuffer extends import_collection.Collection {
|
|
|
147
147
|
try {
|
|
148
148
|
for (let i = 0; i < size; i++) {
|
|
149
149
|
if (modified) {
|
|
150
|
-
throw new Error("
|
|
150
|
+
throw new Error("Buffer was modified while being iterated.");
|
|
151
151
|
}
|
|
152
152
|
yield this.backingArray[readIndex];
|
|
153
153
|
readIndex = (readIndex + 1) % this.bufferSize;
|
|
@@ -164,19 +164,19 @@ class CircularBuffer extends import_collection.Collection {
|
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
166
|
* yields all items from the buffer, removes them and waits fore more
|
|
167
|
-
* @param
|
|
168
|
-
* @param yieldOutstandingItems whether to yield all outstanding items or exit immdiately when {@link
|
|
167
|
+
* @param cancellationSignal token to cancel iteration
|
|
168
|
+
* @param yieldOutstandingItems whether to yield all outstanding items or exit immdiately when {@link cancellationSignal} is set
|
|
169
169
|
* @returns
|
|
170
170
|
*/
|
|
171
|
-
async *consumeAsync(
|
|
171
|
+
async *consumeAsync(cancellationSignal = new import_token.CancellationToken(), yieldOutstandingItems = true) {
|
|
172
172
|
while (true) {
|
|
173
173
|
if (this.isEmpty) {
|
|
174
|
-
await (0, import_rxjs.firstValueFrom)((0, import_rxjs.race)([this.onItems$,
|
|
174
|
+
await (0, import_rxjs.firstValueFrom)((0, import_rxjs.race)([this.onItems$, cancellationSignal]));
|
|
175
175
|
}
|
|
176
|
-
while (this.size > 0 && (
|
|
176
|
+
while (this.size > 0 && (cancellationSignal.isUnset || yieldOutstandingItems)) {
|
|
177
177
|
yield this.tryRemove();
|
|
178
178
|
}
|
|
179
|
-
if (
|
|
179
|
+
if (cancellationSignal.isSet) {
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -198,7 +198,7 @@ class CircularBuffer extends import_collection.Collection {
|
|
|
198
198
|
}
|
|
199
199
|
resize(size) {
|
|
200
200
|
if (size < this.size) {
|
|
201
|
-
throw new Error("
|
|
201
|
+
throw new Error("Buffer has more items than it would have capacity after resize.");
|
|
202
202
|
}
|
|
203
203
|
let newBackingArray;
|
|
204
204
|
if (this.size > 0) {
|
package/database/mongo/module.js
CHANGED
|
@@ -49,8 +49,8 @@ import_injector.Injector.registerSingleton(import_classes.MongoClient, {
|
|
|
49
49
|
context.data.url = url;
|
|
50
50
|
return client;
|
|
51
51
|
},
|
|
52
|
-
async afterResolve(client, _argument, {
|
|
53
|
-
await (0, import_core.connect)(`mongo at ${url}`, async () => client.connect(), logger,
|
|
52
|
+
async afterResolve(client, _argument, { cancellationSignal, data: { url, logger } }) {
|
|
53
|
+
await (0, import_core.connect)(`mongo at ${url}`, async () => client.connect(), logger, cancellationSignal);
|
|
54
54
|
}
|
|
55
55
|
}, {
|
|
56
56
|
defaultArgumentProvider: () => mongoModuleConfig.defaultConnection,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { CancellationToken } from '../
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
|
+
import { CancellationToken } from '../cancellation/token.js';
|
|
3
3
|
import type { AsyncDisposable, Disposable } from './disposable.js';
|
|
4
4
|
declare const deferrerToken: unique symbol;
|
|
5
5
|
export type AsyncDisposeTaskFunction = () => any;
|
|
@@ -13,8 +13,8 @@ export type Deferrer = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare class AsyncDisposer implements AsyncDisposable, AsyncDisposableStack {
|
|
15
15
|
#private;
|
|
16
|
-
get
|
|
17
|
-
get
|
|
16
|
+
get disposingSignal(): CancellationSignal;
|
|
17
|
+
get disposedSignal(): CancellationSignal;
|
|
18
18
|
get disposing(): boolean;
|
|
19
19
|
get disposed(): boolean;
|
|
20
20
|
readonly [Symbol.toStringTag] = "AsyncDisposable";
|