@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
package/injector/injector.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
2
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
3
2
|
import type { OneOrMany, Record, TypedOmit } from '../types.js';
|
|
4
3
|
import type { ResolveArgument } from './interfaces.js';
|
|
5
4
|
import { type Provider } from './provider.js';
|
|
@@ -17,9 +16,11 @@ export type GetRegistrationOptions = {
|
|
|
17
16
|
skipSelf?: boolean;
|
|
18
17
|
onlySelf?: boolean;
|
|
19
18
|
};
|
|
19
|
+
export type AddDisposeHandler = (handler: Disposable | AsyncDisposable | (() => any)) => void;
|
|
20
20
|
export declare class Injector implements AsyncDisposable {
|
|
21
21
|
#private;
|
|
22
22
|
readonly name: string;
|
|
23
|
+
get disposed(): boolean;
|
|
23
24
|
constructor(name: string, parent?: Injector | null);
|
|
24
25
|
/**
|
|
25
26
|
* Globally register a provider for a token
|
|
@@ -36,7 +37,7 @@ export declare class Injector implements AsyncDisposable {
|
|
|
36
37
|
*/
|
|
37
38
|
static registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): void;
|
|
38
39
|
dispose(): Promise<void>;
|
|
39
|
-
[
|
|
40
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
40
41
|
fork(name: string): Injector;
|
|
41
42
|
/**
|
|
42
43
|
* Register a provider for a token
|
|
@@ -87,5 +88,7 @@ export declare class Injector implements AsyncDisposable {
|
|
|
87
88
|
private resolveInjectionAll;
|
|
88
89
|
private resolveInjectionAllAsync;
|
|
89
90
|
private getResolveContext;
|
|
91
|
+
private getAfterResolveContext;
|
|
90
92
|
private getInjectionContext;
|
|
93
|
+
private assertNotDisposed;
|
|
91
94
|
}
|
package/injector/injector.js
CHANGED
|
@@ -23,11 +23,11 @@ __export(injector_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(injector_exports);
|
|
24
24
|
var import_circular_buffer = require("../data-structures/circular-buffer.js");
|
|
25
25
|
var import_multi_key_map = require("../data-structures/multi-key-map.js");
|
|
26
|
-
var import_async_disposer = require("../disposable/async-disposer.js");
|
|
27
26
|
var import_disposable = require("../disposable/disposable.js");
|
|
28
27
|
var import_deferred_promise = require("../promise/deferred-promise.js");
|
|
29
28
|
var import_registry = require("../reflection/registry.js");
|
|
30
29
|
var import_array = require("../utils/array/array.js");
|
|
30
|
+
var import_cancellation = require("../cancellation/index.js");
|
|
31
31
|
var import_factory_map = require("../utils/factory-map.js");
|
|
32
32
|
var import_forward_ref = require("../utils/object/forward-ref.js");
|
|
33
33
|
var import_object = require("../utils/object/object.js");
|
|
@@ -43,14 +43,29 @@ class Injector {
|
|
|
43
43
|
static #globalRegistrations = /* @__PURE__ */ new Map();
|
|
44
44
|
#parent;
|
|
45
45
|
#children = [];
|
|
46
|
-
#
|
|
46
|
+
#disposeToken = new import_cancellation.CancellationToken();
|
|
47
|
+
#disposableStack = new AsyncDisposableStack();
|
|
47
48
|
#registrations = /* @__PURE__ */ new Map();
|
|
48
49
|
#injectorScopedResolutions = new import_multi_key_map.MultiKeyMap();
|
|
50
|
+
#addDisposeHandler;
|
|
49
51
|
name;
|
|
52
|
+
get disposed() {
|
|
53
|
+
return this.#disposableStack.disposed;
|
|
54
|
+
}
|
|
50
55
|
constructor(name, parent = null) {
|
|
51
56
|
this.name = name;
|
|
52
57
|
this.#parent = parent;
|
|
53
58
|
this.register(Injector, { useValue: this });
|
|
59
|
+
this.register(import_cancellation.CancellationSignal, { useValue: this.#disposeToken.signal });
|
|
60
|
+
this.#addDisposeHandler = (handler) => {
|
|
61
|
+
if ((0, import_disposable.isSyncOrAsyncDisposable)(handler)) {
|
|
62
|
+
this.#disposableStack.use(handler);
|
|
63
|
+
} else {
|
|
64
|
+
this.#disposableStack.defer(handler);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.#disposableStack.defer(() => this.#registrations.clear());
|
|
68
|
+
this.#disposableStack.defer(() => this.#injectorScopedResolutions.clear());
|
|
54
69
|
}
|
|
55
70
|
/**
|
|
56
71
|
* Globally register a provider for a token
|
|
@@ -78,15 +93,16 @@ class Injector {
|
|
|
78
93
|
Injector.register(token, providers, { ...options, lifecycle: "singleton" });
|
|
79
94
|
}
|
|
80
95
|
async dispose() {
|
|
81
|
-
|
|
96
|
+
this.#disposeToken.set();
|
|
97
|
+
await this.#disposableStack.disposeAsync();
|
|
82
98
|
}
|
|
83
|
-
async [
|
|
99
|
+
async [Symbol.asyncDispose]() {
|
|
84
100
|
await this.dispose();
|
|
85
101
|
}
|
|
86
102
|
fork(name) {
|
|
87
103
|
const child = new Injector(name, this);
|
|
88
104
|
this.#children.push(child);
|
|
89
|
-
this.#
|
|
105
|
+
this.#disposableStack.use(child);
|
|
90
106
|
return child;
|
|
91
107
|
}
|
|
92
108
|
/**
|
|
@@ -96,6 +112,7 @@ class Injector {
|
|
|
96
112
|
* @param options registration options
|
|
97
113
|
*/
|
|
98
114
|
register(token, providers, options = {}) {
|
|
115
|
+
this.assertNotDisposed();
|
|
99
116
|
for (const provider of (0, import_array.toArray)(providers)) {
|
|
100
117
|
const registration = {
|
|
101
118
|
token,
|
|
@@ -184,6 +201,7 @@ class Injector {
|
|
|
184
201
|
return values;
|
|
185
202
|
}
|
|
186
203
|
_resolve(token, argument, options, context, chain) {
|
|
204
|
+
this.assertNotDisposed();
|
|
187
205
|
if ((0, import_type_guards.isUndefined)(token)) {
|
|
188
206
|
throw new import_resolve_error.ResolveError("Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.", chain);
|
|
189
207
|
}
|
|
@@ -201,6 +219,7 @@ class Injector {
|
|
|
201
219
|
return this._resolveRegistration(singleRegistration, argument, options, context, chain);
|
|
202
220
|
}
|
|
203
221
|
_resolveAll(token, argument, options, context, chain) {
|
|
222
|
+
this.assertNotDisposed();
|
|
204
223
|
if ((0, import_type_guards.isUndefined)(token)) {
|
|
205
224
|
throw new import_resolve_error.ResolveError("Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.", chain);
|
|
206
225
|
}
|
|
@@ -237,7 +256,14 @@ class Injector {
|
|
|
237
256
|
return registration.resolutions.get(argumentIdentity);
|
|
238
257
|
}
|
|
239
258
|
const value = this._resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain);
|
|
240
|
-
const resolution = {
|
|
259
|
+
const resolution = {
|
|
260
|
+
tag: resolutionTag,
|
|
261
|
+
registration,
|
|
262
|
+
value,
|
|
263
|
+
argument: injectionContext.argument,
|
|
264
|
+
afterResolveContext: this.getAfterResolveContext(resolutionTag, context),
|
|
265
|
+
chain
|
|
266
|
+
};
|
|
241
267
|
context.resolutions.push(resolution);
|
|
242
268
|
if (resolutionScoped) {
|
|
243
269
|
context.resolutionScopedResolutions.setFlat(token, argumentIdentity, resolution);
|
|
@@ -293,7 +319,7 @@ class Injector {
|
|
|
293
319
|
throw new Error("Unsupported provider.");
|
|
294
320
|
}
|
|
295
321
|
if ((0, import_disposable.isDisposable)(result.value) || (0, import_disposable.isAsyncDisposable)(result.value)) {
|
|
296
|
-
this.#
|
|
322
|
+
this.#disposableStack.use(result.value);
|
|
297
323
|
}
|
|
298
324
|
return result.value;
|
|
299
325
|
} finally {
|
|
@@ -363,9 +389,20 @@ class Injector {
|
|
|
363
389
|
const context = {
|
|
364
390
|
resolve: (token, argument, options) => this._resolve(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
|
|
365
391
|
resolveAll: (token, argument, options) => this._resolveAll(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
392
|
+
cancellationSignal: this.#disposeToken,
|
|
393
|
+
addDisposeHandler: this.#addDisposeHandler,
|
|
394
|
+
get data() {
|
|
395
|
+
return resolveContext.resolutionContextData.get(resolutionTag);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
return context;
|
|
399
|
+
}
|
|
400
|
+
getAfterResolveContext(resolutionTag, resolveContext) {
|
|
401
|
+
const context = {
|
|
402
|
+
cancellationSignal: this.#disposeToken,
|
|
403
|
+
addDisposeHandler: this.#addDisposeHandler,
|
|
404
|
+
get data() {
|
|
405
|
+
return resolveContext.resolutionContextData.get(resolutionTag);
|
|
369
406
|
}
|
|
370
407
|
};
|
|
371
408
|
return context;
|
|
@@ -381,6 +418,11 @@ class Injector {
|
|
|
381
418
|
};
|
|
382
419
|
return context;
|
|
383
420
|
}
|
|
421
|
+
assertNotDisposed() {
|
|
422
|
+
if (this.disposed) {
|
|
423
|
+
throw new Error("Injector is disposed.");
|
|
424
|
+
}
|
|
425
|
+
}
|
|
384
426
|
}
|
|
385
427
|
function addRegistration(registrations, registration) {
|
|
386
428
|
if ((0, import_provider.isClassProvider)(registration.provider)) {
|
|
@@ -408,7 +450,7 @@ function newInternalResolveContext() {
|
|
|
408
450
|
resolving: /* @__PURE__ */ new Set(),
|
|
409
451
|
resolutionScopedResolutions: new import_multi_key_map.MultiKeyMap(),
|
|
410
452
|
resolutions: [],
|
|
411
|
-
|
|
453
|
+
resolutionContextData: new import_factory_map.FactoryMap(() => ({})),
|
|
412
454
|
forwardRefQueue: new import_circular_buffer.CircularBuffer(),
|
|
413
455
|
forwardRefs: /* @__PURE__ */ new Set(),
|
|
414
456
|
$done: new import_deferred_promise.DeferredPromise()
|
|
@@ -421,18 +463,15 @@ function postProcess(context) {
|
|
|
421
463
|
derefForwardRefs(context);
|
|
422
464
|
for (const resolution of context.resolutions) {
|
|
423
465
|
if ((0, import_type_guards.isFunction)(resolution.value?.[import_interfaces.afterResolve])) {
|
|
424
|
-
const
|
|
425
|
-
const returnValue = resolution.value[import_interfaces.afterResolve](resolution.argument, resolutionContext);
|
|
466
|
+
const returnValue = resolution.value[import_interfaces.afterResolve](resolution.argument, resolution.afterResolveContext);
|
|
426
467
|
throwOnPromise(returnValue, "[afterResolve]", resolution.chain);
|
|
427
468
|
}
|
|
428
469
|
if ((0, import_provider.isProviderWithInitializer)(resolution.registration.provider)) {
|
|
429
|
-
const
|
|
430
|
-
const returnValue = resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolutionContext);
|
|
470
|
+
const returnValue = resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolution.afterResolveContext);
|
|
431
471
|
throwOnPromise(returnValue, "provider afterResolve handler", resolution.chain);
|
|
432
472
|
}
|
|
433
473
|
if ((0, import_type_guards.isDefined)(resolution.registration.options.afterResolve)) {
|
|
434
|
-
const
|
|
435
|
-
const returnValue = resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolutionContext);
|
|
474
|
+
const returnValue = resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolution.afterResolveContext);
|
|
436
475
|
throwOnPromise(returnValue, "registration afterResolve handler", resolution.chain);
|
|
437
476
|
}
|
|
438
477
|
}
|
|
@@ -444,16 +483,13 @@ async function postProcessAsync(context) {
|
|
|
444
483
|
derefForwardRefs(context);
|
|
445
484
|
for (const resolution of context.resolutions) {
|
|
446
485
|
if ((0, import_type_guards.isFunction)(resolution.value?.[import_interfaces.afterResolve])) {
|
|
447
|
-
|
|
448
|
-
await resolution.value[import_interfaces.afterResolve](resolution.argument, resolutionContext);
|
|
486
|
+
await resolution.value[import_interfaces.afterResolve](resolution.argument, resolution.afterResolveContext);
|
|
449
487
|
}
|
|
450
488
|
if ((0, import_provider.isProviderWithInitializer)(resolution.registration.provider)) {
|
|
451
|
-
|
|
452
|
-
await resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolutionContext);
|
|
489
|
+
await resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolution.afterResolveContext);
|
|
453
490
|
}
|
|
454
491
|
if ((0, import_type_guards.isDefined)(resolution.registration.options.afterResolve)) {
|
|
455
|
-
|
|
456
|
-
await resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolutionContext);
|
|
492
|
+
await resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolution.afterResolveContext);
|
|
457
493
|
}
|
|
458
494
|
}
|
|
459
495
|
}
|
package/injector/interfaces.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { Record, Type } from '../types.js';
|
|
2
2
|
import type { ArgumentedInjectionToken, InjectionTokenArgument, ReifyingInjectionToken } from './token.js';
|
|
3
|
+
import type { AfterResolveContext } from './types.js';
|
|
3
4
|
export declare const resolveArgumentType: unique symbol;
|
|
4
5
|
export declare const afterResolve: unique symbol;
|
|
5
6
|
export type ResolveArgumentType = typeof resolveArgumentType;
|
|
6
7
|
export type ResolveArgument<T, Fallback = undefined> = undefined | (T extends Resolvable<infer U> ? U : T extends Type<Resolvable<infer U>> ? U : T extends (ArgumentedInjectionToken<any, any> | ReifyingInjectionToken) ? InjectionTokenArgument<T> : Fallback);
|
|
7
|
-
export interface Resolvable<A = unknown,
|
|
8
|
+
export interface Resolvable<A = unknown, D extends Record = Record> extends Partial<AfterResolve<A, D>> {
|
|
8
9
|
/**
|
|
9
10
|
* type of resolve argument
|
|
10
11
|
* @deprecated only used for type inference
|
|
11
12
|
*/
|
|
12
13
|
readonly [resolveArgumentType]: A;
|
|
13
14
|
}
|
|
14
|
-
export interface AfterResolve<A = unknown,
|
|
15
|
-
[afterResolve](argument: A, context:
|
|
15
|
+
export interface AfterResolve<A = unknown, D extends Record = Record> {
|
|
16
|
+
[afterResolve](argument: A, context: AfterResolveContext<D>): void | Promise<void>;
|
|
16
17
|
}
|
package/injector/provider.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { Constructor, Record, TypedOmit } from '../types.js';
|
|
2
2
|
import type { ResolveArgument } from './interfaces.js';
|
|
3
3
|
import type { InjectionToken } from './token.js';
|
|
4
|
-
import type { ResolveContext } from './types.js';
|
|
5
|
-
export type Factory<T, A = any,
|
|
4
|
+
import type { AfterResolveContext, ResolveContext } from './types.js';
|
|
5
|
+
export type Factory<T, A = any, D extends Record = Record> = (argument: ResolveArgument<T, A>, context: ResolveContext<D>) => T;
|
|
6
6
|
export type ProviderWithArgument<T, A> = {
|
|
7
7
|
defaultArgument?: ResolveArgument<T, A>;
|
|
8
8
|
defaultArgumentProvider?: () => ResolveArgument<T, A>;
|
|
9
9
|
};
|
|
10
|
-
export type ProviderWithInitializer<T, A,
|
|
11
|
-
afterResolve?: (value: T, argument: A, context:
|
|
10
|
+
export type ProviderWithInitializer<T, A, D extends Record> = {
|
|
11
|
+
afterResolve?: (value: T, argument: A, context: AfterResolveContext<D>) => void | Promise<void>;
|
|
12
12
|
};
|
|
13
|
-
export type Provider<T = any, A = any,
|
|
14
|
-
export type ClassProvider<T = any, A = any,
|
|
13
|
+
export type Provider<T = any, A = any, D extends Record = Record> = ClassProvider<T, A, D> | ValueProvider<T> | TokenProvider<T, A, D> | FactoryProvider<T, A, D>;
|
|
14
|
+
export type ClassProvider<T = any, A = any, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & {
|
|
15
15
|
useClass: Constructor<T>;
|
|
16
16
|
};
|
|
17
17
|
export type ValueProvider<T = any> = {
|
|
18
18
|
useValue: T;
|
|
19
19
|
};
|
|
20
|
-
export type TokenProvider<T = any, A = any,
|
|
20
|
+
export type TokenProvider<T = any, A = any, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & ({
|
|
21
21
|
useToken: InjectionToken<T, A>;
|
|
22
22
|
useTokenProvider?: undefined;
|
|
23
23
|
} | {
|
|
@@ -29,13 +29,13 @@ export type TokenProvider<T = any, A = any, C extends Record = Record> = Provide
|
|
|
29
29
|
*/
|
|
30
30
|
resolveAll?: boolean;
|
|
31
31
|
};
|
|
32
|
-
export type FactoryProvider<T = any, A = unknown,
|
|
33
|
-
useFactory: Factory<T, A,
|
|
32
|
+
export type FactoryProvider<T = any, A = unknown, D extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, D> & {
|
|
33
|
+
useFactory: Factory<T, A, D>;
|
|
34
34
|
};
|
|
35
|
-
export declare function classProvider<T, A,
|
|
35
|
+
export declare function classProvider<T, A, D extends Record>(constructor: Constructor<T>, options?: TypedOmit<ClassProvider<T, A, D>, 'useClass'>): ClassProvider<T, A, D>;
|
|
36
36
|
export declare function valueProvider<T>(value: T, options?: TypedOmit<ValueProvider<T>, 'useValue'>): ValueProvider<T>;
|
|
37
|
-
export declare function tokenProvider<T, A,
|
|
38
|
-
export declare function factoryProvider<T, A,
|
|
37
|
+
export declare function tokenProvider<T, A, D extends Record>(token: InjectionToken<T, A>, options?: TypedOmit<TokenProvider<T, A, D>, 'useToken' | 'useTokenProvider'>): TokenProvider<T>;
|
|
38
|
+
export declare function factoryProvider<T, A, D extends Record>(factory: Factory<T, A, D>, options?: TypedOmit<FactoryProvider<T, A, D>, 'useFactory'>): FactoryProvider<T, A, D>;
|
|
39
39
|
export declare function isClassProvider<T, A>(value: Provider<T, A>): value is ClassProvider<T, A>;
|
|
40
40
|
export declare function isClassProvider<T, A>(value: unknown): value is ClassProvider<T, A>;
|
|
41
41
|
export declare function isValueProvider<T>(value: Provider<T>): value is ValueProvider<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomError } from '../error/custom.error.js';
|
|
2
|
-
import { ResolveChain } from './resolve-chain.js';
|
|
2
|
+
import type { ResolveChain } from './resolve-chain.js';
|
|
3
3
|
export declare class ResolveError extends CustomError {
|
|
4
4
|
constructor(message: string, chain: ResolveChain, cause?: Error);
|
|
5
5
|
}
|
package/injector/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/index.js';
|
|
1
2
|
import type { AsyncDisposeHandler } from '../disposable/async-disposer.js';
|
|
2
3
|
import type { Record } from '../types.js';
|
|
3
4
|
import type { Injector } from './injector.js';
|
|
@@ -10,12 +11,18 @@ import type { InjectionToken } from './token.js';
|
|
|
10
11
|
* singleton: one resolution at injector where token is registered
|
|
11
12
|
*/
|
|
12
13
|
export type Lifecycle = 'transient' | 'resolution' | 'injector' | 'singleton';
|
|
13
|
-
export type ResolveContext<
|
|
14
|
-
|
|
14
|
+
export type ResolveContext<D extends Record> = Pick<Injector, 'resolve' | 'resolveAll'> & {
|
|
15
|
+
readonly data: ResolveContextData<D>;
|
|
16
|
+
readonly cancellationSignal: CancellationSignal;
|
|
17
|
+
addDisposeHandler(handler: AsyncDisposeHandler): void;
|
|
18
|
+
};
|
|
19
|
+
export type AfterResolveContext<D extends Record> = {
|
|
20
|
+
readonly data: ResolveContextData<D>;
|
|
21
|
+
readonly cancellationSignal: CancellationSignal;
|
|
15
22
|
addDisposeHandler(handler: AsyncDisposeHandler): void;
|
|
16
23
|
};
|
|
17
24
|
export type Mapper<T = any, U = unknown> = (value: T) => U;
|
|
18
|
-
export type ArgumentProvider<T = unknown,
|
|
25
|
+
export type ArgumentProvider<T = unknown, D extends Record = Record> = (context: ResolveContext<D>) => T;
|
|
19
26
|
export type ForwardRefInjectionToken<T = any, A = any> = Exclude<InjectionToken<T, A>, Function> | (() => InjectionToken<T, A>);
|
|
20
27
|
export type ResolveOptions = {
|
|
21
28
|
optional?: boolean;
|
|
@@ -25,13 +32,13 @@ export type ResolveOptions = {
|
|
|
25
32
|
/**
|
|
26
33
|
* data to store between different stages like resolve and afterResolve
|
|
27
34
|
*/
|
|
28
|
-
export type
|
|
29
|
-
export type RegistrationOptions<T, A = unknown,
|
|
35
|
+
export type ResolveContextData<T extends Record> = T;
|
|
36
|
+
export type RegistrationOptions<T, A = unknown, D extends Record = Record> = {
|
|
30
37
|
lifecycle?: Lifecycle;
|
|
31
38
|
/** Default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
32
39
|
defaultArgument?: ResolveArgument<T, A>;
|
|
33
40
|
/** Default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
34
|
-
defaultArgumentProvider?: ArgumentProvider<ResolveArgument<T, A>,
|
|
41
|
+
defaultArgumentProvider?: ArgumentProvider<ResolveArgument<T, A>, D>;
|
|
35
42
|
/**
|
|
36
43
|
* Value to distinguish scoped and singleton instances based on argument
|
|
37
44
|
* by default it uses strict equality (===) on the original argument,
|
|
@@ -43,7 +50,9 @@ export type RegistrationOptions<T, A = unknown, C extends Record = Record> = {
|
|
|
43
50
|
*/
|
|
44
51
|
argumentIdentityProvider?: Mapper<ResolveArgument<T, A>>;
|
|
45
52
|
/** Function which gets called after a resolve */
|
|
46
|
-
afterResolve?: (instance: T, argument: ResolveArgument<T, A>, context:
|
|
53
|
+
afterResolve?: (instance: T, argument: ResolveArgument<T, A>, context: AfterResolveContext<D>) => any;
|
|
47
54
|
/** Whether multiple values can be resolved or not (used with {@link Injector.resolveAll}). If false, previous registrations are removed */
|
|
48
55
|
multi?: boolean;
|
|
56
|
+
/** custom metadata */
|
|
57
|
+
metadata?: Record;
|
|
49
58
|
};
|
package/lock/mongo/lock.js
CHANGED
|
@@ -21,11 +21,11 @@ __export(lock_exports, {
|
|
|
21
21
|
MongoLock: () => MongoLock
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(lock_exports);
|
|
24
|
+
var import_cancellation = require("../../cancellation/index.js");
|
|
24
25
|
var import_decorators = require("../../injector/decorators.js");
|
|
25
26
|
var import_lock = require("../../lock/index.js");
|
|
26
27
|
var import_logger = require("../../logger/index.js");
|
|
27
28
|
var import_alphabet = require("../../utils/alphabet.js");
|
|
28
|
-
var import_cancellation_token = require("../../utils/cancellation-token.js");
|
|
29
29
|
var import_date_time = require("../../utils/date-time.js");
|
|
30
30
|
var import_random = require("../../utils/random.js");
|
|
31
31
|
var import_timer = require("../../utils/timer.js");
|
|
@@ -78,7 +78,7 @@ let MongoLock = class MongoLock2 extends import_lock.Lock {
|
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
let expiration = result;
|
|
81
|
-
const releaseToken = new
|
|
81
|
+
const releaseToken = new import_cancellation.CancellationToken();
|
|
82
82
|
const controller = {
|
|
83
83
|
get lost() {
|
|
84
84
|
return (0, import_date_time.currentTimestamp)() >= expiration.valueOf();
|
package/lock/web/web-lock.js
CHANGED
|
@@ -21,9 +21,9 @@ __export(web_lock_exports, {
|
|
|
21
21
|
WebLock: () => WebLock
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(web_lock_exports);
|
|
24
|
+
var import_cancellation = require("../../cancellation/index.js");
|
|
24
25
|
var import_injector = require("../../injector/index.js");
|
|
25
26
|
var import_deferred_promise = require("../../promise/deferred-promise.js");
|
|
26
|
-
var import_cancellation_token = require("../../utils/cancellation-token.js");
|
|
27
27
|
var import_type_guards = require("../../utils/type-guards.js");
|
|
28
28
|
var import_rxjs = require("rxjs");
|
|
29
29
|
var import_lock = require("../lock.js");
|
|
@@ -55,7 +55,7 @@ let WebLock = class WebLock2 extends import_lock.Lock {
|
|
|
55
55
|
releasePromise.resolve();
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
-
const timeoutToken = (0, import_type_guards.isDefined)(timeout) && timeout > 0 ?
|
|
58
|
+
const timeoutToken = (0, import_type_guards.isDefined)(timeout) && timeout > 0 ? import_cancellation.CancellationToken.from((0, import_rxjs.timer)(timeout).pipe((0, import_rxjs.map)(() => true))) : void 0;
|
|
59
59
|
void navigator.locks.request(this.resource, {
|
|
60
60
|
signal: (0, import_type_guards.isDefined)(timeoutToken) ? timeoutToken.asAbortSignal() : void 0,
|
|
61
61
|
ifAvailable: (0, import_type_guards.isDefined)(timeout) && timeout <= 0
|
package/logger/console/logger.js
CHANGED
|
@@ -79,9 +79,9 @@ ConsoleLogger = ConsoleLogger_1 = __decorate([
|
|
|
79
79
|
provider: {
|
|
80
80
|
useFactory: (argument, context) => {
|
|
81
81
|
if ((0, import_type_guards.isObject)(argument)) {
|
|
82
|
-
return new
|
|
82
|
+
return new ConsoleLogger(argument.level ?? context.resolve(import_level.LogLevel), argument.module, argument.prefix);
|
|
83
83
|
}
|
|
84
|
-
return new
|
|
84
|
+
return new ConsoleLogger(context.resolve(import_level.LogLevel), argument, void 0);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Logger } from '../logger/index.js';
|
|
2
1
|
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { Logger } from '../logger/index.js';
|
|
3
|
+
import { CancellationToken } from '../cancellation/token.js';
|
|
3
4
|
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
|
-
import { CancellationToken } from '../utils/cancellation-token.js';
|
|
5
5
|
import { MessageBus } from './message-bus.js';
|
|
6
6
|
export declare abstract class MessageBusBase<T> extends MessageBus<T> {
|
|
7
7
|
private readonly logger;
|
|
@@ -22,8 +22,8 @@ __export(message_bus_base_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(message_bus_base_exports);
|
|
24
24
|
var import_rxjs = require("rxjs");
|
|
25
|
+
var import_token = require("../cancellation/token.js");
|
|
25
26
|
var import_disposable = require("../disposable/disposable.js");
|
|
26
|
-
var import_cancellation_token = require("../utils/cancellation-token.js");
|
|
27
27
|
var import_message_bus = require("./message-bus.js");
|
|
28
28
|
class MessageBusBase extends import_message_bus.MessageBus {
|
|
29
29
|
logger;
|
|
@@ -35,7 +35,7 @@ class MessageBusBase extends import_message_bus.MessageBus {
|
|
|
35
35
|
super();
|
|
36
36
|
this.logger = logger;
|
|
37
37
|
this.publishSubject = new import_rxjs.Subject();
|
|
38
|
-
this.disposeToken = new
|
|
38
|
+
this.disposeToken = new import_token.CancellationToken();
|
|
39
39
|
this.messages$ = (0, import_rxjs.defer)(() => this._messages$).pipe((0, import_rxjs.takeUntil)(this.disposeToken.set$), (0, import_rxjs.share)());
|
|
40
40
|
this.allMessages$ = (0, import_rxjs.merge)(this.messages$, this.publishSubject);
|
|
41
41
|
}
|
package/migration/migrator.js
CHANGED
|
@@ -21,11 +21,11 @@ __export(migrator_exports, {
|
|
|
21
21
|
Migrator: () => Migrator
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(migrator_exports);
|
|
24
|
+
var import_cancellation = require("../cancellation/index.js");
|
|
24
25
|
var import_injector = require("../injector/index.js");
|
|
25
26
|
var import_lock = require("../lock/index.js");
|
|
26
27
|
var import_logger = require("../logger/index.js");
|
|
27
28
|
var import_array = require("../utils/array/array.js");
|
|
28
|
-
var import_cancellation_token = require("../utils/cancellation-token.js");
|
|
29
29
|
var import_comparison = require("../utils/comparison.js");
|
|
30
30
|
var import_math = require("../utils/math.js");
|
|
31
31
|
var import_timer = require("../utils/timer.js");
|
|
@@ -68,7 +68,7 @@ let Migrator = class Migrator2 {
|
|
|
68
68
|
const { result } = await lock.use(3e4, true, async () => {
|
|
69
69
|
const results = [];
|
|
70
70
|
while (true) {
|
|
71
|
-
const restartToken = new
|
|
71
|
+
const restartToken = new import_cancellation.CancellationToken();
|
|
72
72
|
const control = {
|
|
73
73
|
restart: () => restartToken.set()
|
|
74
74
|
};
|
package/module/module-base.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/index.js';
|
|
2
|
+
import { CancellationToken } from '../cancellation/index.js';
|
|
1
3
|
import type { StringMap } from '../types.js';
|
|
2
|
-
import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
|
|
3
|
-
import { CancellationToken } from '../utils/cancellation-token.js';
|
|
4
4
|
import type { Module, ModuleMetric } from './module.js';
|
|
5
5
|
import { ModuleState } from './module.js';
|
|
6
6
|
export declare abstract class ModuleBase implements Module {
|
|
@@ -14,5 +14,5 @@ export declare abstract class ModuleBase implements Module {
|
|
|
14
14
|
constructor(name: string);
|
|
15
15
|
run(): Promise<void>;
|
|
16
16
|
stop(): Promise<void>;
|
|
17
|
-
protected abstract _run(
|
|
17
|
+
protected abstract _run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
18
18
|
}
|
package/module/module-base.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(module_base_exports, {
|
|
|
21
21
|
ModuleBase: () => ModuleBase
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(module_base_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_cancellation = require("../cancellation/index.js");
|
|
25
25
|
var import_module = require("./module.js");
|
|
26
26
|
class ModuleBase {
|
|
27
27
|
runPromise;
|
|
@@ -38,7 +38,7 @@ class ModuleBase {
|
|
|
38
38
|
this.name = name;
|
|
39
39
|
this.runPromise = Promise.resolve();
|
|
40
40
|
this._state = import_module.ModuleState.Stopped;
|
|
41
|
-
this.cancellationToken = new
|
|
41
|
+
this.cancellationToken = new import_cancellation.CancellationToken();
|
|
42
42
|
}
|
|
43
43
|
async run() {
|
|
44
44
|
if (this._state != import_module.ModuleState.Stopped) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/index.js';
|
|
2
2
|
import type { MetricAggregation, MetricAggregationOptions } from '../utils/moving-metric.js';
|
|
3
3
|
import { MovingMetric } from '../utils/moving-metric.js';
|
|
4
4
|
import type { ModuleMetric } from './module.js';
|
|
@@ -24,6 +24,6 @@ export declare class ModuleMetricReporter {
|
|
|
24
24
|
metric: ModuleMetric;
|
|
25
25
|
reports: MetricReport<MetricAggregation>[];
|
|
26
26
|
}[]): void;
|
|
27
|
-
run(
|
|
27
|
+
run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
28
28
|
private updateNameLengths;
|
|
29
29
|
}
|
|
@@ -51,9 +51,9 @@ class ModuleMetricReporter {
|
|
|
51
51
|
this.metricGroups.push({ groupName, registrations });
|
|
52
52
|
this.updateNameLengths();
|
|
53
53
|
}
|
|
54
|
-
async run(
|
|
54
|
+
async run(cancellationSignal) {
|
|
55
55
|
let counter = 0;
|
|
56
|
-
while (
|
|
56
|
+
while (cancellationSignal.isUnset) {
|
|
57
57
|
for (const { registrations } of this.metricGroups) {
|
|
58
58
|
for (const { metric, moving } of registrations) {
|
|
59
59
|
moving.add(metric.getValue());
|
|
@@ -71,7 +71,7 @@ class ModuleMetricReporter {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
await (0, import_timing.cancelableTimeout)(this.sampleInterval,
|
|
74
|
+
await (0, import_timing.cancelableTimeout)(this.sampleInterval, cancellationSignal);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
updateNameLengths() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Module } from '../module.js';
|
|
1
|
+
import type { CancellationSignal } from '../../cancellation/index.js';
|
|
3
2
|
import { ModuleBase } from '../module-base.js';
|
|
4
|
-
|
|
3
|
+
import type { Module } from '../module.js';
|
|
4
|
+
export type FunctionModuleFunction = (cancellationToken: CancellationSignal) => void | Promise<void>;
|
|
5
5
|
export declare class FunctionModule extends ModuleBase implements Module {
|
|
6
6
|
private readonly fn;
|
|
7
7
|
readonly metrics: {};
|
|
8
8
|
constructor(fn: FunctionModuleFunction, name?: string);
|
|
9
|
-
protected _run(
|
|
9
|
+
protected _run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../../cancellation/index.js';
|
|
1
2
|
import type { Resolvable } from '../../injector/interfaces.js';
|
|
2
3
|
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
3
|
-
import type { ReadonlyCancellationToken } from '../../utils/cancellation-token.js';
|
|
4
4
|
import { ModuleBase } from '../module-base.js';
|
|
5
5
|
import type { Module } from '../module.js';
|
|
6
6
|
import { ModuleMetricType } from '../module.js';
|
|
@@ -23,6 +23,6 @@ export declare class WebServerModule extends ModuleBase implements Module, Resol
|
|
|
23
23
|
readonly [resolveArgumentType]: WebServerModuleConfiguration;
|
|
24
24
|
constructor();
|
|
25
25
|
initialize(): void;
|
|
26
|
-
protected _run(
|
|
26
|
+
protected _run(cancellationSignal: CancellationSignal): Promise<void>;
|
|
27
27
|
}
|
|
28
28
|
export declare function configureWebServerModule(config?: Partial<WebServerModuleConfiguration>): void;
|
|
@@ -72,10 +72,10 @@ let WebServerModule = class WebServerModule2 extends import_module_base.ModuleBa
|
|
|
72
72
|
this.apiGateway.registerApi((0, import_server.getApiControllerDefinition)(controller), controller);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
async _run(
|
|
75
|
+
async _run(cancellationSignal) {
|
|
76
76
|
this.initialize();
|
|
77
77
|
await this.httpServer.listen(this.config.port);
|
|
78
|
-
const closePromise =
|
|
78
|
+
const closePromise = cancellationSignal.$set.then(async () => {
|
|
79
79
|
await this.httpServer[import_disposable.disposeAsync]();
|
|
80
80
|
});
|
|
81
81
|
for await (const context of this.httpServer) {
|