@tstdl/base 0.93.22 → 0.93.23

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.
@@ -110,7 +110,7 @@ let Application = Application_1 = class Application {
110
110
  async runModules(modules) {
111
111
  const promises = modules.map(async (module) => {
112
112
  try {
113
- this.#logger.info(`Starting module ${module.name}`);
113
+ this.#logger.info(`Starting module ${module.name}.`);
114
114
  await runInInjectionContext(this.#injector, async () => await module.run());
115
115
  this.#logger.info(`Module ${module.name} stopped.`);
116
116
  }
@@ -126,7 +126,7 @@ let Application = Application_1 = class Application {
126
126
  if (module.state == ModuleState.Stopped) {
127
127
  return;
128
128
  }
129
- this.#logger.info(`Stopping module ${module.name}`);
129
+ this.#logger.info(`Stopping module ${module.name}.`);
130
130
  try {
131
131
  await module.stop();
132
132
  }
@@ -171,7 +171,7 @@ export class Injector {
171
171
  }
172
172
  resolve(token, argument, options = {}) {
173
173
  const context = newInternalResolveContext();
174
- const value = this._resolve(token, argument, options, context, ResolveChain.startWith(token));
174
+ const value = this._resolve(token, argument, options, context, ResolveChain.startWith(this, token));
175
175
  try {
176
176
  postProcess(context);
177
177
  context.$done.resolve();
@@ -187,7 +187,7 @@ export class Injector {
187
187
  }
188
188
  resolveAll(token, argument, options = {}) {
189
189
  const context = newInternalResolveContext();
190
- const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(token));
190
+ const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(this, token));
191
191
  try {
192
192
  postProcess(context);
193
193
  context.$done.resolve();
@@ -218,7 +218,7 @@ export class Injector {
218
218
  }
219
219
  async resolveAsync(token, argument, options = {}) {
220
220
  const context = newInternalResolveContext();
221
- const value = this._resolve(token, argument, options, context, ResolveChain.startWith(token));
221
+ const value = this._resolve(token, argument, options, context, ResolveChain.startWith(this, token));
222
222
  try {
223
223
  await postProcessAsync(context);
224
224
  context.$done.resolve();
@@ -234,7 +234,7 @@ export class Injector {
234
234
  }
235
235
  async resolveAllAsync(token, argument, options = {}) {
236
236
  const context = newInternalResolveContext();
237
- const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(token));
237
+ const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(this, token));
238
238
  try {
239
239
  await postProcessAsync(context);
240
240
  context.$done.resolve();
@@ -265,8 +265,8 @@ export class Injector {
265
265
  }
266
266
  _resolveManyTokens(tokens, context) {
267
267
  return tokens.map((token) => (isArray(token)
268
- ? this._resolve(token[0], token[1], token[2] ?? {}, context, ResolveChain.startWith(token[0]))
269
- : this._resolve(token, undefined, {}, context, ResolveChain.startWith(token))));
268
+ ? this._resolve(token[0], token[1], token[2] ?? {}, context, ResolveChain.startWith(this, token[0]))
269
+ : this._resolve(token, undefined, {}, context, ResolveChain.startWith(this, token))));
270
270
  }
271
271
  _resolve(token, argument, options, context, chain) {
272
272
  this.assertNotDisposed();
@@ -416,9 +416,9 @@ export class Injector {
416
416
  const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
417
417
  injectionContext.argument = arg;
418
418
  if (provider.resolveAll == true) {
419
- return this._resolveAll(innerToken, arg, options, context, chain.addToken(innerToken));
419
+ return this._resolveAll(innerToken, arg, options, context, chain.addToken(this, innerToken));
420
420
  }
421
- result = { value: this._resolve(innerToken, arg, options, context, chain.addToken(innerToken)) };
421
+ result = { value: this._resolve(innerToken, arg, options, context, chain.addToken(this, innerToken)) };
422
422
  }
423
423
  else if (isFactoryProvider(provider)) {
424
424
  const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
@@ -440,7 +440,7 @@ export class Injector {
440
440
  }
441
441
  }
442
442
  resolveClassInjection(resolutionTag, context, constructor, metadata, resolveArgument, chain) {
443
- const getChain = (injectToken) => chain.addParameter(constructor, metadata.index, injectToken);
443
+ const getChain = (injectToken) => chain.addParameter(this, constructor, metadata.index, injectToken);
444
444
  const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
445
445
  const injectToken = (injectMetadata.injectToken ?? metadata.type);
446
446
  if (isDefined(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || isDefined(resolveArgument) || isUndefined(injectToken))) {
@@ -460,7 +460,7 @@ export class Injector {
460
460
  return resolved;
461
461
  }
462
462
  resolveInjection(token, argument, options, context, injectIndex, chain) {
463
- return this._resolve(token, argument, options, context, chain.addInject(token, injectIndex));
463
+ return this._resolve(token, argument, options, context, chain.addInject(this, token, injectIndex));
464
464
  }
465
465
  async resolveInjectionAsync(token, argument, options, context, injectIndex, chain) {
466
466
  const value = this.resolveInjection(token, argument, options, context, injectIndex, chain);
@@ -468,7 +468,7 @@ export class Injector {
468
468
  return value;
469
469
  }
470
470
  resolveInjectionAll(token, argument, options, context, injectIndex, chain) {
471
- return this._resolveAll(token, argument, options, context, chain.addInject(token, injectIndex));
471
+ return this._resolveAll(token, argument, options, context, chain.addInject(this, token, injectIndex));
472
472
  }
473
473
  async resolveInjectionAllAsync(token, argument, options, context, injectIndex, chain) {
474
474
  const values = this.resolveInjectionAll(token, argument, options, context, injectIndex, chain);
@@ -477,8 +477,8 @@ export class Injector {
477
477
  }
478
478
  getResolveContext(resolutionTag, resolveContext, chain) {
479
479
  return {
480
- resolve: (token, argument, options) => this._resolve(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
481
- resolveAll: (token, argument, options) => this._resolveAll(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
480
+ resolve: (token, argument, options) => this._resolve(token, argument, options ?? {}, resolveContext, chain.addToken(this, token)),
481
+ resolveAll: (token, argument, options) => this._resolveAll(token, argument, options ?? {}, resolveContext, chain.addToken(this, token)),
482
482
  cancellationSignal: this.#disposeToken,
483
483
  addDisposeHandler: this.#addDisposeHandler,
484
484
  get data() {
@@ -1,6 +1,8 @@
1
1
  import type { AbstractConstructor } from '../types/index.js';
2
+ import type { Injector } from './injector.js';
2
3
  import type { InjectionToken } from './token.js';
3
4
  export type ResolveChainNodeBase<Type extends string> = {
5
+ injector: Injector;
4
6
  type: Type;
5
7
  forwardRef?: true;
6
8
  };
@@ -23,11 +25,11 @@ export declare class ResolveChain {
23
25
  get length(): number;
24
26
  /** @deprecated for internal use only */
25
27
  constructor(nodes: ResolveChainNode[]);
26
- static startWith(token: InjectionToken): ResolveChain;
27
- addToken(token: InjectionToken): ResolveChain;
28
- addInject(token: InjectionToken, index: number): ResolveChain;
29
- addParameter(constructor: AbstractConstructor, index: number, token: InjectionToken): ResolveChain;
30
- addProperty(constructor: AbstractConstructor, property: PropertyKey, token: InjectionToken): ResolveChain;
28
+ static startWith(injector: Injector, token: InjectionToken): ResolveChain;
29
+ addToken(injector: Injector, token: InjectionToken): ResolveChain;
30
+ addInject(injector: Injector, token: InjectionToken, index: number): ResolveChain;
31
+ addParameter(injector: Injector, constructor: AbstractConstructor, index: number, token: InjectionToken): ResolveChain;
32
+ addProperty(injector: Injector, constructor: AbstractConstructor, property: PropertyKey, token: InjectionToken): ResolveChain;
31
33
  markAsForwardRef(forwardToken: InjectionToken): ResolveChain;
32
34
  format(truncate?: number): string;
33
35
  truncate(tokenCount: number): ResolveChain;
@@ -10,24 +10,24 @@ export class ResolveChain {
10
10
  constructor(nodes) {
11
11
  this.nodes = nodes;
12
12
  }
13
- static startWith(token) {
13
+ static startWith(injector, token) {
14
14
  const chain = new ResolveChain([]);
15
- return chain.addToken(token);
15
+ return chain.addToken(injector, token);
16
16
  }
17
- addToken(token) {
18
- const node = { type: 'token', token };
17
+ addToken(injector, token) {
18
+ const node = { injector, type: 'token', token };
19
19
  return new ResolveChain([...this.nodes, node]);
20
20
  }
21
- addInject(token, index) {
22
- const node = { type: 'inject', token, index };
21
+ addInject(injector, token, index) {
22
+ const node = { injector, type: 'inject', token, index };
23
23
  return new ResolveChain([...this.nodes, node]);
24
24
  }
25
- addParameter(constructor, index, token) {
26
- const node = { type: 'parameter', constructor, index, token };
25
+ addParameter(injector, constructor, index, token) {
26
+ const node = { injector, type: 'parameter', constructor, index, token };
27
27
  return new ResolveChain([...this.nodes, node]);
28
28
  }
29
- addProperty(constructor, property, token) {
30
- const node = { type: 'property', constructor, property, token };
29
+ addProperty(injector, constructor, property, token) {
30
+ const node = { injector, type: 'property', constructor, property, token };
31
31
  return new ResolveChain([...this.nodes, node]);
32
32
  }
33
33
  markAsForwardRef(forwardToken) {
@@ -41,16 +41,18 @@ export class ResolveChain {
41
41
  if (chain.length < this.length) {
42
42
  chainString += '\n [...]';
43
43
  }
44
+ const longestInjectorName = Math.max(...chain.nodes.map((node) => node.injector.name.length));
44
45
  for (const node of chain.nodes) {
46
+ const paddedInjectorName = node.injector.name.padStart(longestInjectorName);
45
47
  const tokenName = getTokenName(node.token);
46
48
  const forwardRefPrefix = node.forwardRef ? 'ForwardRef::' : '';
47
49
  switch (node.type) {
48
50
  case 'token':
49
- chainString += `\n -> ${forwardRefPrefix}${tokenName}`;
51
+ chainString += `\n ${paddedInjectorName} -> ${forwardRefPrefix}${tokenName}`;
50
52
  break;
51
53
  case 'inject':
52
54
  chainString += ` => inject(${forwardRefPrefix}${tokenName}) [${node.index + 1}]`;
53
- chainString += `\n -> ${tokenName}`;
55
+ chainString += `\n ${paddedInjectorName} -> ${tokenName}`;
54
56
  break;
55
57
  case 'parameter':
56
58
  const metadata = reflectionRegistry.getMetadata(node.constructor);
@@ -58,12 +60,12 @@ export class ResolveChain {
58
60
  const suffix = ', _'.repeat(assertDefinedPass(metadata?.parameters, `missing parameters metadata for ${node.constructor.name}`).length - node.index - 1);
59
61
  chainString += `(${prefix}${forwardRefPrefix}${tokenName}${suffix})`;
60
62
  // chainString += `\n ${' '.repeat(1 + node.constructor.name.length + forwardRefPrefix.length + prefix.length + (tokenName.length / 2))}↓`;
61
- chainString += `\n -> ${tokenName}`;
63
+ chainString += `\n ${paddedInjectorName} -> ${tokenName}`;
62
64
  break;
63
65
  case 'property':
64
66
  const constructorName = getTokenName(node.constructor);
65
67
  const key = getPropertyKeyString(node.property);
66
- chainString += `\n -> ${constructorName}[${key}]: ${forwardRefPrefix}${tokenName}`;
68
+ chainString += `\n ${paddedInjectorName} -> ${constructorName}[${key}]: ${forwardRefPrefix}${tokenName}`;
67
69
  break;
68
70
  default:
69
71
  throw new Error(`unknown chain node type ${node.type}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.22",
3
+ "version": "0.93.23",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/test6.js CHANGED
@@ -6,10 +6,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Application } from './application/application.js';
8
8
  import { provideModule, provideSignalHandler } from './application/providers.js';
9
+ import { NotImplementedError } from './errors/not-implemented.error.js';
9
10
  import { Singleton } from './injector/decorators.js';
10
11
  import { inject } from './injector/index.js';
11
12
  import { injectionToken } from './injector/token.js';
12
13
  import { PrettyPrintLogFormatter, provideConsoleLogTransport } from './logger/index.js';
14
+ import { _throw } from './utils/throw.js';
13
15
  const MY_INTEGER = injectionToken('MyInteger');
14
16
  // current method
15
17
  let Foo = class Foo {
@@ -18,7 +20,7 @@ let Foo = class Foo {
18
20
  Foo = __decorate([
19
21
  Singleton({
20
22
  providers: [
21
- { provide: MY_INTEGER, useValue: 42 },
23
+ { provide: MY_INTEGER, useFactory: () => _throw(new NotImplementedError()) },
22
24
  ],
23
25
  })
24
26
  ], Foo);