@tstdl/base 0.86.0-beta9 → 0.86.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.js +0 -1
- 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/core.d.ts +2 -4
- package/core.js +2 -9
- package/database/mongo/module.js +8 -8
- package/disposable/async-disposer.d.ts +8 -7
- package/disposable/async-disposer.js +49 -23
- package/disposable/disposable.d.ts +5 -4
- package/disposable/disposable.js +9 -5
- 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/logger/console/logger.js +2 -2
- package/module/modules/web-server.module.js +0 -2
- package/object-storage/object-storage-provider.d.ts +1 -1
- package/object-storage/s3/s3.object-storage-provider.d.ts +1 -6
- package/object-storage/s3/s3.object-storage-provider.js +2 -12
- package/object-storage/s3/s3.object-storage.js +4 -1
- package/package.json +7 -6
- package/polyfills.d.ts +159 -0
- package/polyfills.js +2 -0
- package/queue/mongo/mongo-job.repository.js +3 -4
- package/search-index/elastic/module.js +4 -4
- package/tsconfig.json +1 -1
- package/utils/cancellation-token.d.ts +19 -17
- package/utils/cancellation-token.js +20 -19
- package/_container/container.d.ts +0 -99
- package/_container/container.js +0 -443
- package/_container/decorators.d.ts +0 -76
- package/_container/decorators.js +0 -110
- package/_container/index.d.ts +0 -10
- package/_container/index.js +0 -27
- package/_container/interfaces.d.ts +0 -16
- package/_container/interfaces.js +0 -26
- package/_container/provider.d.ts +0 -35
- package/_container/provider.js +0 -60
- package/_container/resolve-chain.d.ts +0 -27
- package/_container/resolve-chain.js +0 -105
- package/_container/resolve.error.d.ts +0 -5
- package/_container/resolve.error.js +0 -36
- package/_container/token.d.ts +0 -18
- package/_container/token.js +0 -41
- package/_container/type-info.d.ts +0 -18
- package/_container/type-info.js +0 -16
- package/_container/types.d.ts +0 -9
- package/_container/types.js +0 -16
- package/_container/utils.d.ts +0 -3
- package/_container/utils.js +0 -44
- package/global-this.d.ts +0 -1
- package/global-this.js +0 -37
|
@@ -18,23 +18,26 @@ var __copyProps = (to, from2, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var cancellation_token_exports = {};
|
|
20
20
|
__export(cancellation_token_exports, {
|
|
21
|
-
CancellationToken: () => CancellationToken
|
|
21
|
+
CancellationToken: () => CancellationToken,
|
|
22
|
+
ReadonlyCancellationToken: () => ReadonlyCancellationToken
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(cancellation_token_exports);
|
|
24
|
-
var import_noop = require("../rxjs/noop.js");
|
|
25
25
|
var import_rxjs = require("rxjs");
|
|
26
|
+
var import_noop = require("../rxjs/noop.js");
|
|
26
27
|
var import_noop2 = require("./noop.js");
|
|
27
28
|
var import_type_guards = require("./type-guards.js");
|
|
28
|
-
class
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
class ReadonlyCancellationToken {
|
|
30
|
+
}
|
|
31
|
+
class CancellationToken extends ReadonlyCancellationToken {
|
|
32
|
+
#stateSubject = new import_rxjs.BehaviorSubject(false);
|
|
33
|
+
state$ = this.#stateSubject.pipe((0, import_rxjs.distinctUntilChanged)());
|
|
34
|
+
set$ = this.state$.pipe((0, import_rxjs.filter)((state) => state), (0, import_rxjs.map)(() => void 0));
|
|
35
|
+
unset$ = this.state$.pipe((0, import_rxjs.filter)((state) => !state), (0, import_rxjs.map)(() => void 0));
|
|
33
36
|
get isSet() {
|
|
34
|
-
return this
|
|
37
|
+
return this.#stateSubject.value;
|
|
35
38
|
}
|
|
36
39
|
get isUnset() {
|
|
37
|
-
return !this
|
|
40
|
+
return !this.#stateSubject.value;
|
|
38
41
|
}
|
|
39
42
|
get $set() {
|
|
40
43
|
return (0, import_rxjs.firstValueFrom)(this.set$);
|
|
@@ -52,10 +55,8 @@ class CancellationToken {
|
|
|
52
55
|
* @default false
|
|
53
56
|
*/
|
|
54
57
|
constructor(initialState = false) {
|
|
55
|
-
|
|
56
|
-
this
|
|
57
|
-
this.set$ = this.state$.pipe((0, import_rxjs.filter)((state) => state), (0, import_rxjs.map)(() => void 0));
|
|
58
|
-
this.unset$ = this.state$.pipe((0, import_rxjs.filter)((state) => !state), (0, import_rxjs.map)(() => void 0));
|
|
58
|
+
super();
|
|
59
|
+
this.#stateSubject.next(initialState);
|
|
59
60
|
}
|
|
60
61
|
static from(source, config) {
|
|
61
62
|
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));
|
|
@@ -71,7 +72,7 @@ class CancellationToken {
|
|
|
71
72
|
error: error ? (errorValue) => target.error(errorValue) : import_noop2.noop,
|
|
72
73
|
complete: complete ? () => target.complete() : import_noop2.noop
|
|
73
74
|
});
|
|
74
|
-
target
|
|
75
|
+
target.#stateSubject.subscribe({
|
|
75
76
|
error: () => subscription.unsubscribe(),
|
|
76
77
|
complete: () => subscription.unsubscribe()
|
|
77
78
|
});
|
|
@@ -103,25 +104,25 @@ class CancellationToken {
|
|
|
103
104
|
* Set this token.
|
|
104
105
|
*/
|
|
105
106
|
set() {
|
|
106
|
-
this
|
|
107
|
+
this.#stateSubject.next(true);
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* Unset this token.
|
|
110
111
|
*/
|
|
111
112
|
unset() {
|
|
112
|
-
this
|
|
113
|
+
this.#stateSubject.next(false);
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Set the state.
|
|
116
117
|
*/
|
|
117
118
|
setState(state) {
|
|
118
|
-
this
|
|
119
|
+
this.#stateSubject.next(state);
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
121
122
|
* Errors the token.
|
|
122
123
|
*/
|
|
123
124
|
error(error) {
|
|
124
|
-
this
|
|
125
|
+
this.#stateSubject.error(error);
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
127
128
|
* Clean up subscriptions.
|
|
@@ -129,7 +130,7 @@ class CancellationToken {
|
|
|
129
130
|
* Keep in mind that *active* awaits (promise) on this token will throw.
|
|
130
131
|
*/
|
|
131
132
|
complete() {
|
|
132
|
-
this
|
|
133
|
+
this.#stateSubject.complete();
|
|
133
134
|
}
|
|
134
135
|
async then(onfulfilled) {
|
|
135
136
|
await this.$set;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { Record, TypedOmit } from '../types.js';
|
|
2
|
-
import type { Observable } from 'rxjs';
|
|
3
|
-
import type { Injectable, InjectableArgument } from './interfaces.js';
|
|
4
|
-
import type { Provider } from './provider.js';
|
|
5
|
-
import type { InjectionToken } from './token.js';
|
|
6
|
-
import type { ArgumentProvider, Mapper } from './types.js';
|
|
7
|
-
export declare const injectMetadataSymbol: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
* transient: a new instance will be created with each resolve
|
|
10
|
-
* singleton: each resolve will return the same instance
|
|
11
|
-
* resolution: the same instance will be resolved for each resolution of this dependency during a single resolution chain
|
|
12
|
-
*/
|
|
13
|
-
export type Lifecycle = 'transient' | 'singleton' | 'resolution';
|
|
14
|
-
export type RegistrationOptions<T, A = unknown> = {
|
|
15
|
-
lifecycle?: Lifecycle;
|
|
16
|
-
/** default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
17
|
-
defaultArgument?: InjectableArgument<T, A>;
|
|
18
|
-
/** default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
19
|
-
defaultArgumentProvider?: ArgumentProvider<InjectableArgument<T, A>>;
|
|
20
|
-
/**
|
|
21
|
-
* value to distinguish scoped and singleton instances based on argument
|
|
22
|
-
* by default it uses strict equality (===) on the original argument,
|
|
23
|
-
* so modifications to argument objects and literal objects in the call
|
|
24
|
-
* may not yield the expected result
|
|
25
|
-
*
|
|
26
|
-
* hint: {@link JSON.stringify} is a simple solution for many use cases,
|
|
27
|
-
* but will fail if properties have different order
|
|
28
|
-
*/
|
|
29
|
-
argumentIdentityProvider?: Mapper<InjectableArgument<T, A> | undefined>;
|
|
30
|
-
/** function which gets called after a resolve */
|
|
31
|
-
initializer?: (instance: T) => any;
|
|
32
|
-
/** custom metadata */
|
|
33
|
-
metadata?: Record;
|
|
34
|
-
};
|
|
35
|
-
export type Registration<T = any, A = any> = {
|
|
36
|
-
token: InjectionToken<T, A>;
|
|
37
|
-
provider: Provider<T, A>;
|
|
38
|
-
options: RegistrationOptions<T, A>;
|
|
39
|
-
instances: Map<any, T>;
|
|
40
|
-
};
|
|
41
|
-
export declare class Container {
|
|
42
|
-
private readonly registrationMap;
|
|
43
|
-
private readonly registrationSubject;
|
|
44
|
-
/** emits on new registration */
|
|
45
|
-
readonly registration$: Observable<Registration>;
|
|
46
|
-
/** all registrations */
|
|
47
|
-
get registrations(): Iterable<Registration>;
|
|
48
|
-
constructor();
|
|
49
|
-
/**
|
|
50
|
-
* register a provider for a token
|
|
51
|
-
* @param token token to register
|
|
52
|
-
* @param provider provider used to resolve the token
|
|
53
|
-
* @param options registration options
|
|
54
|
-
*/
|
|
55
|
-
register<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
|
|
56
|
-
/**
|
|
57
|
-
* register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
58
|
-
* @param token token to register
|
|
59
|
-
* @param provider provider used to resolve the token
|
|
60
|
-
* @param options registration options
|
|
61
|
-
*/
|
|
62
|
-
registerSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
|
|
63
|
-
/**
|
|
64
|
-
* check if token has a registered provider
|
|
65
|
-
* @param token token check
|
|
66
|
-
*/
|
|
67
|
-
hasRegistration(token: InjectionToken): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* get registration
|
|
70
|
-
* @param token token to get registration for
|
|
71
|
-
*/
|
|
72
|
-
getRegistration<T, A>(token: InjectionToken<T, A>): Registration<T, A>;
|
|
73
|
-
/**
|
|
74
|
-
* try to get registration
|
|
75
|
-
* @param token token to get registration for
|
|
76
|
-
*/
|
|
77
|
-
tryGetRegistration<T, A>(token: InjectionToken<T, A>): Registration<T, A> | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* resolve a token
|
|
80
|
-
* @param token token to resolve
|
|
81
|
-
* @param argument argument used for resolving (overrides token and default arguments)
|
|
82
|
-
* @returns
|
|
83
|
-
*/
|
|
84
|
-
resolve<T, A = T extends Injectable<infer AInject> ? AInject : any>(token: InjectionToken<T, A>, argument?: T extends Injectable<infer AInject> ? AInject : A, instances?: [InjectionToken, any][]): T;
|
|
85
|
-
/**
|
|
86
|
-
* resolve a token
|
|
87
|
-
* @param token token to resolve
|
|
88
|
-
* @param argument argument used for resolving (overrides token and default arguments)
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
resolveAsync<T, A = T extends Injectable<infer AInject> ? AInject : any>(token: InjectionToken<T, A>, argument?: T extends Injectable<infer AInject> ? AInject : A, instances?: [InjectionToken, any][]): Promise<T>;
|
|
92
|
-
private _resolve;
|
|
93
|
-
private _resolveAsync;
|
|
94
|
-
private resolveInjection;
|
|
95
|
-
private resolveInjectionAsync;
|
|
96
|
-
private getResolveContext;
|
|
97
|
-
private addInstancesToResolveContext;
|
|
98
|
-
}
|
|
99
|
-
export declare const container: Container;
|
package/_container/container.js
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
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 __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var container_exports = {};
|
|
20
|
-
__export(container_exports, {
|
|
21
|
-
Container: () => Container,
|
|
22
|
-
container: () => container,
|
|
23
|
-
injectMetadataSymbol: () => injectMetadataSymbol
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(container_exports);
|
|
26
|
-
var import_circular_buffer = require("../data-structures/circular-buffer.js");
|
|
27
|
-
var import_multi_key_map = require("../data-structures/multi-key-map.js");
|
|
28
|
-
var import_reflection = require("../reflection/index.js");
|
|
29
|
-
var import_map = require("../utils/async-iterable-helpers/map.js");
|
|
30
|
-
var import_to_array = require("../utils/async-iterable-helpers/to-array.js");
|
|
31
|
-
var import_forward_ref = require("../utils/object/forward-ref.js");
|
|
32
|
-
var import_object = require("../utils/object/object.js");
|
|
33
|
-
var import_type_guards = require("../utils/type-guards.js");
|
|
34
|
-
var import_rxjs = require("rxjs");
|
|
35
|
-
var import_interfaces = require("./interfaces.js");
|
|
36
|
-
var import_provider = require("./provider.js");
|
|
37
|
-
var import_resolve_chain = require("./resolve-chain.js");
|
|
38
|
-
var import_resolve_error = require("./resolve.error.js");
|
|
39
|
-
var import_token = require("./token.js");
|
|
40
|
-
var import_utils = require("./utils.js");
|
|
41
|
-
const injectMetadataSymbol = Symbol("Inject metadata");
|
|
42
|
-
class Container {
|
|
43
|
-
registrationMap;
|
|
44
|
-
registrationSubject;
|
|
45
|
-
/** emits on new registration */
|
|
46
|
-
registration$;
|
|
47
|
-
/** all registrations */
|
|
48
|
-
get registrations() {
|
|
49
|
-
return this.registrationMap.values();
|
|
50
|
-
}
|
|
51
|
-
constructor() {
|
|
52
|
-
this.registrationMap = /* @__PURE__ */ new Map();
|
|
53
|
-
this.registrationSubject = new import_rxjs.Subject();
|
|
54
|
-
this.registration$ = this.registrationSubject.asObservable();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* register a provider for a token
|
|
58
|
-
* @param token token to register
|
|
59
|
-
* @param provider provider used to resolve the token
|
|
60
|
-
* @param options registration options
|
|
61
|
-
*/
|
|
62
|
-
register(token, provider, options = {}) {
|
|
63
|
-
if ((0, import_provider.isClassProvider)(provider) && !(0, import_utils.isStubClass)(provider.useClass)) {
|
|
64
|
-
const injectable = import_reflection.reflectionRegistry.getMetadata(provider.useClass)?.data.has(injectMetadataSymbol) ?? false;
|
|
65
|
-
if (!injectable) {
|
|
66
|
-
throw new Error(`${provider.useClass.name} is not injectable.`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const registration = {
|
|
70
|
-
token,
|
|
71
|
-
provider,
|
|
72
|
-
options,
|
|
73
|
-
instances: /* @__PURE__ */ new Map()
|
|
74
|
-
};
|
|
75
|
-
this.registrationMap.set(token, registration);
|
|
76
|
-
this.registrationSubject.next(registration);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
80
|
-
* @param token token to register
|
|
81
|
-
* @param provider provider used to resolve the token
|
|
82
|
-
* @param options registration options
|
|
83
|
-
*/
|
|
84
|
-
registerSingleton(token, provider, options) {
|
|
85
|
-
this.register(token, provider, { ...options, lifecycle: "singleton" });
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* check if token has a registered provider
|
|
89
|
-
* @param token token check
|
|
90
|
-
*/
|
|
91
|
-
hasRegistration(token) {
|
|
92
|
-
return this.registrationMap.has(token);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* get registration
|
|
96
|
-
* @param token token to get registration for
|
|
97
|
-
*/
|
|
98
|
-
getRegistration(token) {
|
|
99
|
-
const registration = this.registrationMap.get(token);
|
|
100
|
-
if ((0, import_type_guards.isUndefined)(registration)) {
|
|
101
|
-
const tokenName = (0, import_token.getTokenName)(token);
|
|
102
|
-
throw new Error(`No provider for ${tokenName} registered.`);
|
|
103
|
-
}
|
|
104
|
-
return registration;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* try to get registration
|
|
108
|
-
* @param token token to get registration for
|
|
109
|
-
*/
|
|
110
|
-
tryGetRegistration(token) {
|
|
111
|
-
return this.registrationMap.get(token);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* resolve a token
|
|
115
|
-
* @param token token to resolve
|
|
116
|
-
* @param argument argument used for resolving (overrides token and default arguments)
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
resolve(token, argument, instances) {
|
|
120
|
-
const context = {
|
|
121
|
-
isAsync: false,
|
|
122
|
-
resolves: 0,
|
|
123
|
-
forwardRefQueue: new import_circular_buffer.CircularBuffer(),
|
|
124
|
-
resolutions: [],
|
|
125
|
-
forwardRefs: /* @__PURE__ */ new Set(),
|
|
126
|
-
providedInstances: new Map(instances),
|
|
127
|
-
instances: new import_multi_key_map.MultiKeyMap(),
|
|
128
|
-
resolving: new import_multi_key_map.MultiKeyMap()
|
|
129
|
-
};
|
|
130
|
-
return this._resolve(token, false, argument, context, import_resolve_chain.ResolveChain.startWith(token), true);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* resolve a token
|
|
134
|
-
* @param token token to resolve
|
|
135
|
-
* @param argument argument used for resolving (overrides token and default arguments)
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
async resolveAsync(token, argument, instances) {
|
|
139
|
-
const context = {
|
|
140
|
-
isAsync: true,
|
|
141
|
-
resolves: 0,
|
|
142
|
-
forwardRefQueue: new import_circular_buffer.CircularBuffer(),
|
|
143
|
-
resolutions: [],
|
|
144
|
-
forwardRefs: /* @__PURE__ */ new Set(),
|
|
145
|
-
providedInstances: new Map(instances),
|
|
146
|
-
instances: new import_multi_key_map.MultiKeyMap(),
|
|
147
|
-
resolving: new import_multi_key_map.MultiKeyMap()
|
|
148
|
-
};
|
|
149
|
-
return this._resolveAsync(token, false, argument, context, import_resolve_chain.ResolveChain.startWith(token), true);
|
|
150
|
-
}
|
|
151
|
-
// eslint-disable-next-line max-statements, max-lines-per-function, complexity
|
|
152
|
-
_resolve(token, optional, _argument, context, chain, isFirst) {
|
|
153
|
-
if (chain.length > 750 || ++context.resolves > 750) {
|
|
154
|
-
throw new import_resolve_error.ResolveError("Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle instead or @forwardRef().", chain);
|
|
155
|
-
}
|
|
156
|
-
if ((0, import_type_guards.isUndefined)(token)) {
|
|
157
|
-
throw new import_resolve_error.ResolveError("Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.", chain);
|
|
158
|
-
}
|
|
159
|
-
if (context.providedInstances.has(token)) {
|
|
160
|
-
return context.providedInstances.get(token);
|
|
161
|
-
}
|
|
162
|
-
const registration = this.tryGetRegistration(token);
|
|
163
|
-
if ((0, import_type_guards.isUndefined)(registration)) {
|
|
164
|
-
if (optional == true) {
|
|
165
|
-
return void 0;
|
|
166
|
-
}
|
|
167
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
168
|
-
}
|
|
169
|
-
const resolveArgument = _argument ?? registration.options.defaultArgument ?? registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain));
|
|
170
|
-
if ((0, import_type_guards.isPromise)(resolveArgument)) {
|
|
171
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
172
|
-
}
|
|
173
|
-
const argumentIdentity = (0, import_type_guards.isDefined)(registration.options.argumentIdentityProvider) && (registration.options.lifecycle == "resolution" || registration.options.lifecycle == "singleton") ? registration.options.argumentIdentityProvider(resolveArgument) : resolveArgument;
|
|
174
|
-
if ((0, import_type_guards.isPromise)(argumentIdentity)) {
|
|
175
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument identity provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
176
|
-
}
|
|
177
|
-
if (registration.options.lifecycle == "resolution" && context.instances.has([token, argumentIdentity])) {
|
|
178
|
-
return context.instances.get([token, argumentIdentity]);
|
|
179
|
-
}
|
|
180
|
-
if (registration.options.lifecycle == "singleton" && registration.instances.has(argumentIdentity)) {
|
|
181
|
-
return registration.instances.get(argumentIdentity);
|
|
182
|
-
}
|
|
183
|
-
if (context.resolving.has([token, argumentIdentity])) {
|
|
184
|
-
throw new import_resolve_error.ResolveError("Circular dependency to itself detected. Please check your registrations and providers. @forwardRef might be a solution.", chain);
|
|
185
|
-
}
|
|
186
|
-
context.resolving.set([token, argumentIdentity], true);
|
|
187
|
-
let instance;
|
|
188
|
-
if ((0, import_provider.isClassProvider)(registration.provider)) {
|
|
189
|
-
const typeMetadata = import_reflection.reflectionRegistry.getMetadata(registration.provider.useClass);
|
|
190
|
-
if ((0, import_type_guards.isUndefined)(typeMetadata) || !typeMetadata.data.has(injectMetadataSymbol)) {
|
|
191
|
-
throw new import_resolve_error.ResolveError(`${registration.provider.useClass.name} is not injectable.`, chain);
|
|
192
|
-
}
|
|
193
|
-
if ((0, import_utils.isStubClass)(typeMetadata.constructor)) {
|
|
194
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
195
|
-
}
|
|
196
|
-
const parameters = (typeMetadata.parameters ?? []).map((metadata) => this.resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain));
|
|
197
|
-
instance = new typeMetadata.constructor(...parameters);
|
|
198
|
-
for (const [property, metadata] of typeMetadata.properties) {
|
|
199
|
-
if (!metadata.data.has(injectMetadataSymbol)) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
instance[property] = this.resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if ((0, import_provider.isValueProvider)(registration.provider)) {
|
|
206
|
-
instance = registration.provider.useValue;
|
|
207
|
-
}
|
|
208
|
-
if ((0, import_provider.isTokenProvider)(registration.provider)) {
|
|
209
|
-
const arg = resolveArgument ?? registration.provider.argument ?? registration.provider.argumentProvider?.();
|
|
210
|
-
const innerToken = registration.provider.useToken ?? registration.provider.useTokenProvider();
|
|
211
|
-
if ((0, import_type_guards.isPromise)(arg)) {
|
|
212
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
213
|
-
}
|
|
214
|
-
if ((0, import_type_guards.isPromise)(innerToken)) {
|
|
215
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async token provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
216
|
-
}
|
|
217
|
-
instance = this._resolve(innerToken, false, arg, context, chain.addToken(innerToken), false);
|
|
218
|
-
}
|
|
219
|
-
if ((0, import_provider.isFactoryProvider)(registration.provider)) {
|
|
220
|
-
try {
|
|
221
|
-
const result = registration.provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
|
|
222
|
-
if ((0, import_type_guards.isPromise)(result)) {
|
|
223
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async factory provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
224
|
-
}
|
|
225
|
-
instance = result;
|
|
226
|
-
} catch (error) {
|
|
227
|
-
throw new import_resolve_error.ResolveError("Error in factory.", chain, error);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (registration.options.lifecycle == "resolution") {
|
|
231
|
-
context.instances.set([token, argumentIdentity], instance);
|
|
232
|
-
}
|
|
233
|
-
if (registration.options.lifecycle == "singleton") {
|
|
234
|
-
registration.instances.set(argumentIdentity, instance);
|
|
235
|
-
}
|
|
236
|
-
context.resolutions.push({ instance, registration });
|
|
237
|
-
context.resolving.delete([token, argumentIdentity]);
|
|
238
|
-
if (isFirst) {
|
|
239
|
-
for (const fn of context.forwardRefQueue.consume()) {
|
|
240
|
-
fn();
|
|
241
|
-
}
|
|
242
|
-
derefForwardRefs(context);
|
|
243
|
-
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
244
|
-
const resolution = context.resolutions[i];
|
|
245
|
-
if ((0, import_type_guards.isFunction)(resolution.instance?.[import_interfaces.afterResolve])) {
|
|
246
|
-
const returnValue = resolution.instance[import_interfaces.afterResolve]();
|
|
247
|
-
if ((0, import_type_guards.isPromise)(returnValue)) {
|
|
248
|
-
throw new import_resolve_error.ResolveError(`Cannot execute async [afterResolve] for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if ((0, import_type_guards.isDefined)(resolution.registration.options.initializer)) {
|
|
252
|
-
const returnValue = resolution.registration.options.initializer(resolution.instance);
|
|
253
|
-
if ((0, import_type_guards.isPromise)(returnValue)) {
|
|
254
|
-
throw new import_resolve_error.ResolveError(`Cannot execute async initializer for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return instance;
|
|
260
|
-
}
|
|
261
|
-
// eslint-disable-next-line max-statements, max-lines-per-function, complexity
|
|
262
|
-
async _resolveAsync(token, optional, _argument, context, chain, isFirst) {
|
|
263
|
-
if (chain.length > 750 || ++context.resolves > 750) {
|
|
264
|
-
throw new import_resolve_error.ResolveError("Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle instead or @forwardRef().", chain);
|
|
265
|
-
}
|
|
266
|
-
if ((0, import_type_guards.isUndefined)(token)) {
|
|
267
|
-
throw new import_resolve_error.ResolveError("Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.", chain);
|
|
268
|
-
}
|
|
269
|
-
if (context.providedInstances.has(token)) {
|
|
270
|
-
return context.providedInstances.get(token);
|
|
271
|
-
}
|
|
272
|
-
const registration = this.tryGetRegistration(token);
|
|
273
|
-
if ((0, import_type_guards.isUndefined)(registration)) {
|
|
274
|
-
if (optional == true) {
|
|
275
|
-
return void 0;
|
|
276
|
-
}
|
|
277
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
278
|
-
}
|
|
279
|
-
const resolveArgument = _argument ?? registration.options.defaultArgument ?? await registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain));
|
|
280
|
-
const argumentIdentity = (0, import_type_guards.isDefined)(registration.options.argumentIdentityProvider) && (registration.options.lifecycle == "resolution" || registration.options.lifecycle == "singleton") ? await registration.options.argumentIdentityProvider(resolveArgument) : resolveArgument;
|
|
281
|
-
if (registration.options.lifecycle == "resolution" && context.instances.has([token, argumentIdentity])) {
|
|
282
|
-
return context.instances.get([token, argumentIdentity]);
|
|
283
|
-
}
|
|
284
|
-
if (registration.options.lifecycle == "singleton" && registration.instances.has(argumentIdentity)) {
|
|
285
|
-
return registration.instances.get(argumentIdentity);
|
|
286
|
-
}
|
|
287
|
-
if (context.resolving.has([token, argumentIdentity])) {
|
|
288
|
-
throw new import_resolve_error.ResolveError("Circular dependency to itself detected. Please check your registrations and providers. @forwardRef might be a solution.", chain);
|
|
289
|
-
}
|
|
290
|
-
context.resolving.set([token, argumentIdentity], true);
|
|
291
|
-
let instance;
|
|
292
|
-
if ((0, import_provider.isClassProvider)(registration.provider)) {
|
|
293
|
-
const typeMetadata = import_reflection.reflectionRegistry.getMetadata(registration.provider.useClass);
|
|
294
|
-
if ((0, import_type_guards.isUndefined)(typeMetadata) || !typeMetadata.data.has(injectMetadataSymbol)) {
|
|
295
|
-
throw new import_resolve_error.ResolveError(`${registration.provider.useClass.name} is not injectable.`, chain);
|
|
296
|
-
}
|
|
297
|
-
if ((0, import_utils.isStubClass)(typeMetadata.constructor)) {
|
|
298
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
299
|
-
}
|
|
300
|
-
const boxedParameters = await (0, import_to_array.toArrayAsync)((0, import_map.mapAsync)(typeMetadata.parameters ?? [], async (metadata) => this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)));
|
|
301
|
-
const parameters = boxedParameters.map((box) => box.resolved);
|
|
302
|
-
instance = new typeMetadata.constructor(...parameters);
|
|
303
|
-
for (const [property, metadata] of typeMetadata.properties) {
|
|
304
|
-
if (!metadata.data.has(injectMetadataSymbol)) {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
instance[property] = (await this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)).resolved;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
if ((0, import_provider.isValueProvider)(registration.provider)) {
|
|
311
|
-
instance = registration.provider.useValue;
|
|
312
|
-
}
|
|
313
|
-
if ((0, import_provider.isTokenProvider)(registration.provider)) {
|
|
314
|
-
const arg = resolveArgument ?? registration.provider.argument ?? await registration.provider.argumentProvider?.();
|
|
315
|
-
const innerToken = registration.provider.useToken ?? await registration.provider.useTokenProvider();
|
|
316
|
-
instance = await this._resolveAsync(innerToken, false, arg, context, chain.addToken(innerToken), false);
|
|
317
|
-
}
|
|
318
|
-
if ((0, import_provider.isFactoryProvider)(registration.provider)) {
|
|
319
|
-
try {
|
|
320
|
-
instance = await registration.provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
|
|
321
|
-
} catch (error) {
|
|
322
|
-
throw new import_resolve_error.ResolveError("Error in factory.", chain, error);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (registration.options.lifecycle == "resolution") {
|
|
326
|
-
context.instances.set([token, argumentIdentity], instance);
|
|
327
|
-
}
|
|
328
|
-
if (registration.options.lifecycle == "singleton") {
|
|
329
|
-
registration.instances.set(argumentIdentity, instance);
|
|
330
|
-
}
|
|
331
|
-
context.resolutions.push({ instance, registration });
|
|
332
|
-
context.resolving.delete([token, argumentIdentity]);
|
|
333
|
-
if (isFirst) {
|
|
334
|
-
for (const fn of context.forwardRefQueue.consume()) {
|
|
335
|
-
await fn();
|
|
336
|
-
}
|
|
337
|
-
derefForwardRefs(context);
|
|
338
|
-
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
339
|
-
const resolution = context.resolutions[i];
|
|
340
|
-
if ((0, import_type_guards.isFunction)(resolution.instance?.[import_interfaces.afterResolve])) {
|
|
341
|
-
await resolution.instance[import_interfaces.afterResolve]();
|
|
342
|
-
}
|
|
343
|
-
if ((0, import_type_guards.isDefined)(resolution.registration.options.initializer)) {
|
|
344
|
-
await resolution.registration.options.initializer(resolution.instance);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return instance;
|
|
349
|
-
}
|
|
350
|
-
resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain) {
|
|
351
|
-
const getChain = metadata.metadataType == "constructor-parameter" ? (injectToken2) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken2).addToken(injectToken2) : (injectToken2) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken2).addToken(injectToken2);
|
|
352
|
-
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
353
|
-
const injectToken = injectMetadata.injectToken ?? metadata.type;
|
|
354
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || (0, import_type_guards.isDefined)(resolveArgument) || (0, import_type_guards.isUndefined)(injectToken))) {
|
|
355
|
-
const mapped = injectMetadata.injectArgumentMapper(resolveArgument);
|
|
356
|
-
if ((0, import_type_guards.isPromise)(mapped)) {
|
|
357
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument mapper for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
358
|
-
}
|
|
359
|
-
return mapped;
|
|
360
|
-
}
|
|
361
|
-
const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken)));
|
|
362
|
-
if ((0, import_type_guards.isPromise)(parameterResolveArgument)) {
|
|
363
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
364
|
-
}
|
|
365
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.forwardRefToken)) {
|
|
366
|
-
const forwardRef = import_forward_ref.ForwardRef.create();
|
|
367
|
-
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
368
|
-
context.forwardRefQueue.add(() => {
|
|
369
|
-
const forwardToken = (0, import_type_guards.isFunction)(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
370
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.mapper)) {
|
|
371
|
-
throw new import_resolve_error.ResolveError("Cannot use inject mapper with forwardRef.", getChain(forwardToken));
|
|
372
|
-
}
|
|
373
|
-
const resolved2 = this._resolve(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
374
|
-
import_forward_ref.ForwardRef.setRef(forwardRef, resolved2);
|
|
375
|
-
});
|
|
376
|
-
context.forwardRefs.add(forwardRef);
|
|
377
|
-
return forwardRef;
|
|
378
|
-
}
|
|
379
|
-
const resolved = this._resolve(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
380
|
-
return (0, import_type_guards.isDefined)(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved;
|
|
381
|
-
}
|
|
382
|
-
async resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain) {
|
|
383
|
-
const getChain = metadata.metadataType == "constructor-parameter" ? (injectToken2) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken2).addToken(injectToken2) : (injectToken2) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken2).addToken(injectToken2);
|
|
384
|
-
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
385
|
-
const injectToken = injectMetadata.injectToken ?? metadata.type;
|
|
386
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || (0, import_type_guards.isDefined)(resolveArgument) || (0, import_type_guards.isUndefined)(injectToken))) {
|
|
387
|
-
return { resolved: injectMetadata.injectArgumentMapper(resolveArgument) };
|
|
388
|
-
}
|
|
389
|
-
const parameterResolveArgument = await (injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken))));
|
|
390
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.forwardRefToken)) {
|
|
391
|
-
const forwardRef = import_forward_ref.ForwardRef.create();
|
|
392
|
-
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
393
|
-
context.forwardRefQueue.add(async () => {
|
|
394
|
-
const forwardToken = (0, import_type_guards.isFunction)(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
395
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.mapper)) {
|
|
396
|
-
throw new import_resolve_error.ResolveError("Cannot use inject mapper with forwardRef.", getChain(forwardToken));
|
|
397
|
-
}
|
|
398
|
-
const resolved2 = await this._resolveAsync(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
399
|
-
import_forward_ref.ForwardRef.setRef(forwardRef, resolved2);
|
|
400
|
-
});
|
|
401
|
-
context.forwardRefs.add(forwardRef);
|
|
402
|
-
return { resolved: forwardRef };
|
|
403
|
-
}
|
|
404
|
-
const resolved = await this._resolveAsync(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
405
|
-
return { resolved: (0, import_type_guards.isDefined)(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved };
|
|
406
|
-
}
|
|
407
|
-
getResolveContext(resolveContext, chain) {
|
|
408
|
-
const context = {
|
|
409
|
-
isAsync: resolveContext.isAsync,
|
|
410
|
-
resolve: (token, argument, instances) => {
|
|
411
|
-
this.addInstancesToResolveContext(instances, resolveContext);
|
|
412
|
-
return this._resolve(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
413
|
-
},
|
|
414
|
-
resolveAsync: async (token, argument, instances) => {
|
|
415
|
-
this.addInstancesToResolveContext(instances, resolveContext);
|
|
416
|
-
return this._resolveAsync(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
return context;
|
|
420
|
-
}
|
|
421
|
-
addInstancesToResolveContext(instances, resolveContext) {
|
|
422
|
-
if ((0, import_type_guards.isUndefined)(instances)) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
for (const [instanceToken, instance] of instances) {
|
|
426
|
-
resolveContext.providedInstances.set(instanceToken, instance);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function derefForwardRefs(context) {
|
|
431
|
-
for (const resolution of context.resolutions) {
|
|
432
|
-
if (!(typeof resolution.instance == "object")) {
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
for (const [key, value] of (0, import_object.objectEntries)(resolution.instance)) {
|
|
436
|
-
if (!context.forwardRefs.has(value)) {
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
resolution.instance[key] = import_forward_ref.ForwardRef.deref(value);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
const container = new Container();
|