@tstdl/base 0.93.24 → 0.93.25
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/injector/injector.d.ts +0 -1
- package/injector/injector.js +7 -13
- package/injector/resolve-chain.js +2 -3
- package/package.json +1 -1
package/injector/injector.d.ts
CHANGED
package/injector/injector.js
CHANGED
|
@@ -31,13 +31,11 @@ export class Injector {
|
|
|
31
31
|
#addDisposeHandler;
|
|
32
32
|
id = _id++;
|
|
33
33
|
name;
|
|
34
|
-
nameWithId;
|
|
35
34
|
get disposed() {
|
|
36
35
|
return this.#disposableStack.disposed;
|
|
37
36
|
}
|
|
38
37
|
constructor(name, parent = null) {
|
|
39
38
|
this.name = name;
|
|
40
|
-
this.nameWithId = `${name}#${this.id}`;
|
|
41
39
|
this.#parent = parent;
|
|
42
40
|
this.register(Injector, { useValue: this });
|
|
43
41
|
this.register(CancellationSignal, { useValue: this.#disposeToken.signal });
|
|
@@ -322,22 +320,18 @@ export class Injector {
|
|
|
322
320
|
if (isUndefined(token)) {
|
|
323
321
|
throw new ResolveError('Token is undefined. This might be due to a circular dependency. Consider using an alias or forwardRef.', chain);
|
|
324
322
|
}
|
|
325
|
-
const
|
|
326
|
-
const parentValues = [];
|
|
327
|
-
const registration = this.tryGetRegistration(token, options);
|
|
323
|
+
const registration = this.tryGetRegistration(token);
|
|
328
324
|
if (isDefined(registration)) {
|
|
329
325
|
const registrations = isArray(registration) ? registration : [registration];
|
|
330
|
-
|
|
331
|
-
ownValues.push(...resolved);
|
|
326
|
+
return registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
|
|
332
327
|
}
|
|
333
328
|
if ((options.onlySelf != true) && isNotNull(this.#parent)) {
|
|
334
|
-
|
|
329
|
+
return this.#parent._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain);
|
|
335
330
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
331
|
+
if (options.optional == true) {
|
|
332
|
+
return [];
|
|
339
333
|
}
|
|
340
|
-
|
|
334
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
341
335
|
}
|
|
342
336
|
_resolveRegistration(registration, argument, options, context, chain) {
|
|
343
337
|
checkOverflow(chain, context);
|
|
@@ -362,7 +356,7 @@ export class Injector {
|
|
|
362
356
|
}
|
|
363
357
|
// A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
|
|
364
358
|
const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
|
|
365
|
-
const injector = needsNewScope ? this.fork(`[${getTokenName(token)}]
|
|
359
|
+
const injector = needsNewScope ? this.fork(`[${getTokenName(token)}]Injector`) : this;
|
|
366
360
|
for (const nestedProvider of providers) {
|
|
367
361
|
injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
368
362
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { reflectionRegistry } from '../reflection/index.js';
|
|
2
2
|
import { assertDefinedPass, isDefined } from '../utils/type-guards.js';
|
|
3
|
-
import { start } from 'repl';
|
|
4
3
|
import { getTokenName } from './token.js';
|
|
5
4
|
export class ResolveChain {
|
|
6
5
|
nodes;
|
|
@@ -42,13 +41,13 @@ export class ResolveChain {
|
|
|
42
41
|
if (chain.length < this.length) {
|
|
43
42
|
chainString += '\n [...]';
|
|
44
43
|
}
|
|
45
|
-
const longestInjectorName = Math.max(...chain.nodes.map((node) => (node.type == 'ellipsis') ? 0 : node.injector.
|
|
44
|
+
const longestInjectorName = Math.max(...chain.nodes.map((node) => (node.type == 'ellipsis') ? 0 : `${node.injector.name}#${node.injector.id}`.length));
|
|
46
45
|
for (const node of chain.nodes) {
|
|
47
46
|
if (node.type == 'ellipsis') {
|
|
48
47
|
chainString += `\n ${'[...]'.padStart(longestInjectorName)}`;
|
|
49
48
|
continue;
|
|
50
49
|
}
|
|
51
|
-
const paddedInjectorName = node.injector.name.padStart(longestInjectorName);
|
|
50
|
+
const paddedInjectorName = `${node.injector.name}#${node.injector.id}`.padStart(longestInjectorName);
|
|
52
51
|
const tokenName = getTokenName(node.token);
|
|
53
52
|
const forwardRefPrefix = node.forwardRef ? 'ForwardRef::' : '';
|
|
54
53
|
switch (node.type) {
|