@tstdl/base 0.93.24 → 0.93.26

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/audit/auditor.js CHANGED
@@ -233,7 +233,7 @@ Auditor = Auditor_1 = __decorate([
233
233
  Injectable({
234
234
  providers: [
235
235
  provide(EntityRepositoryConfig, { useValue: { schema: 'audit' } }),
236
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(AuditModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
236
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(AuditModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
237
237
  ],
238
238
  })
239
239
  ], Auditor);
@@ -630,7 +630,7 @@ AuthenticationService = AuthenticationService_1 = __decorate([
630
630
  Singleton({
631
631
  providers: [
632
632
  provide(EntityRepositoryConfig, { useValue: { schema: 'authentication' } }),
633
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(AuthenticationModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
633
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(AuthenticationModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
634
634
  ],
635
635
  })
636
636
  ], AuthenticationService);
@@ -3,7 +3,7 @@ import { provide } from '../../../injector/injector.js';
3
3
  import { factoryProvider } from '../../../injector/provider.js';
4
4
  import { DatabaseConfig } from '../../../orm/server/index.js';
5
5
  import { DocumentManagementConfiguration } from '../module.js';
6
- export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }));
6
+ export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }));
7
7
  export const documentManagementDatabaseConfigProvider = provide(DatabaseConfig, documentManagementDatabaseConfigFactoryProvider);
8
8
  export function DocumentManagementSingleton() {
9
9
  return Singleton({ providers: [documentManagementDatabaseConfigProvider] });
@@ -22,7 +22,7 @@ export type Registration<T = any, A = any> = GlobalRegistration<T, A> & {
22
22
  resolutions: Map<any, T>;
23
23
  };
24
24
  export type GetRegistrationOptions = {
25
- skipSelf?: boolean;
25
+ skipSelf?: boolean | number;
26
26
  onlySelf?: boolean;
27
27
  };
28
28
  export type ResolveManyArrayItem<T, A> = [token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>];
@@ -38,7 +38,7 @@ export declare class Injector implements AsyncDisposable {
38
38
  #private;
39
39
  readonly id: number;
40
40
  readonly name: string;
41
- readonly nameWithId: string;
41
+ get parent(): Injector | null;
42
42
  get disposed(): boolean;
43
43
  constructor(name: string, parent?: Injector | null);
44
44
  /**
@@ -31,13 +31,14 @@ export class Injector {
31
31
  #addDisposeHandler;
32
32
  id = _id++;
33
33
  name;
34
- nameWithId;
34
+ get parent() {
35
+ return this.#parent;
36
+ }
35
37
  get disposed() {
36
38
  return this.#disposableStack.disposed;
37
39
  }
38
40
  constructor(name, parent = null) {
39
41
  this.name = name;
40
- this.nameWithId = `${name}#${this.id}`;
41
42
  this.#parent = parent;
42
43
  this.register(Injector, { useValue: this });
43
44
  this.register(CancellationSignal, { useValue: this.#disposeToken.signal });
@@ -149,8 +150,9 @@ export class Injector {
149
150
  this.register(globalRegistration.token, globalRegistration.provider, globalRegistration.options);
150
151
  }
151
152
  }
152
- if (options?.skipSelf == true) {
153
- return this.#parent?.tryGetRegistration(token, { ...options, skipSelf: false });
153
+ const skipSelf = Number(options?.skipSelf ?? 0);
154
+ if (skipSelf > 0) {
155
+ return this.#parent?.tryGetRegistration(token, { ...options, skipSelf: skipSelf - 1 });
154
156
  }
155
157
  const ownRegistration = this.#registrations.get(token);
156
158
  if (isDefined(ownRegistration)) {
@@ -274,11 +276,12 @@ export class Injector {
274
276
  }
275
277
  _resolve(token, argument, options, context, chain) {
276
278
  this.assertNotDisposed();
277
- if (options.skipSelf == true) {
279
+ const skipSelf = Number(options.skipSelf ?? 0);
280
+ if (skipSelf > 0) {
278
281
  if (isNull(this.#parent) && (options.optional != true)) {
279
282
  throw new ResolveError(`No parent injector available.`, chain);
280
283
  }
281
- return this.#parent?._resolve(token, argument, { ...options, skipSelf: false }, context, chain);
284
+ return this.#parent?._resolve(token, argument, { ...options, skipSelf: skipSelf - 1 }, context, chain);
282
285
  }
283
286
  if (isDefined(options.forwardRef) && (options.forwardRef != false)) {
284
287
  assert(options.optional != true, 'ForwardRef does not support optional without resolveAll/injectAll as undefined is not forwardable.');
@@ -306,11 +309,12 @@ export class Injector {
306
309
  }
307
310
  _resolveAll(token, argument, options, context, chain) {
308
311
  this.assertNotDisposed();
309
- if (options.skipSelf == true) {
312
+ const skipSelf = Number(options.skipSelf ?? 0);
313
+ if (skipSelf > 0) {
310
314
  if (isNull(this.#parent) && (options.optional != true)) {
311
315
  throw new ResolveError(`No parent injector available.`, chain);
312
316
  }
313
- return this.#parent?._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain) ?? [];
317
+ return this.#parent?._resolveAll(token, argument, { ...options, skipSelf: skipSelf - 1 }, context, chain) ?? [];
314
318
  }
315
319
  if (isDefined(options.forwardRef) && (options.forwardRef != false)) {
316
320
  const forwardToken = isFunction(options.forwardRef) ? options.forwardRef() : token;
@@ -322,22 +326,18 @@ export class Injector {
322
326
  if (isUndefined(token)) {
323
327
  throw new ResolveError('Token is undefined. This might be due to a circular dependency. Consider using an alias or forwardRef.', chain);
324
328
  }
325
- const ownValues = [];
326
- const parentValues = [];
327
- const registration = this.tryGetRegistration(token, options);
329
+ const registration = this.tryGetRegistration(token);
328
330
  if (isDefined(registration)) {
329
331
  const registrations = isArray(registration) ? registration : [registration];
330
- const resolved = registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
331
- ownValues.push(...resolved);
332
+ return registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
332
333
  }
333
334
  if ((options.onlySelf != true) && isNotNull(this.#parent)) {
334
- parentValues.push(...this.#parent._resolveAll(token, argument, options, context, chain));
335
+ return this.#parent._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain);
335
336
  }
336
- const allValues = [...ownValues, ...parentValues];
337
- if ((allValues.length == 0) && (options.optional != true)) {
338
- throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
337
+ if (options.optional == true) {
338
+ return [];
339
339
  }
340
- return allValues;
340
+ throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
341
341
  }
342
342
  _resolveRegistration(registration, argument, options, context, chain) {
343
343
  checkOverflow(chain, context);
@@ -362,7 +362,7 @@ export class Injector {
362
362
  }
363
363
  // A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
364
364
  const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
365
- const injector = needsNewScope ? this.fork(`[${getTokenName(token)}]ResolutionInjector`) : this;
365
+ const injector = needsNewScope ? this.fork(`[${getTokenName(token)}]Injector`) : this;
366
366
  for (const nestedProvider of providers) {
367
367
  injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
368
368
  }
@@ -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.nameWithId.length));
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) {
@@ -26,7 +26,7 @@ export type ArgumentProvider<T = unknown, D extends Record = Record> = (context:
26
26
  export type ForwardRefInjectionToken<T = any, A = any> = Exclude<InjectionToken<T, A>, Function> | (() => InjectionToken<T, A>);
27
27
  export type ResolveOptions<T, A> = {
28
28
  optional?: boolean;
29
- skipSelf?: boolean;
29
+ skipSelf?: boolean | number;
30
30
  onlySelf?: boolean;
31
31
  /** If defined, resolve the token using ForwardRef strategy instead of resolving the token directly can be used to circumvent circular dependency problems */
32
32
  forwardRef?: boolean | ForwardRefInjectionToken<T, A>;
@@ -57,7 +57,7 @@ PostgresKeyValueStore = __decorate([
57
57
  Singleton({
58
58
  providers: [
59
59
  provide(EntityRepositoryConfig, { useValue: { schema: 'key_value_store' } }),
60
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresKeyValueStoreModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
60
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresKeyValueStoreModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
61
61
  ],
62
62
  })
63
63
  ], PostgresKeyValueStore);
@@ -21,7 +21,7 @@ PostgresLockProvider = __decorate([
21
21
  Singleton({
22
22
  providers: [
23
23
  provide(EntityRepositoryConfig, { useValue: { schema: 'lock' } }),
24
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresLockModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
24
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresLockModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
25
25
  ],
26
26
  })
27
27
  ], PostgresLockProvider);
@@ -60,7 +60,7 @@ MailService = __decorate([
60
60
  Singleton({
61
61
  providers: [
62
62
  provide(EntityRepositoryConfig, { useValue: { schema: 'mail' } }),
63
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
63
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
64
64
  ],
65
65
  })
66
66
  ], MailService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.24",
3
+ "version": "0.93.26",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -157,7 +157,7 @@ PostgresQueue = __decorate([
157
157
  argumentIdentityProvider: JSON.stringify,
158
158
  providers: [
159
159
  provide(EntityRepositoryConfig, { useValue: { schema: 'queue' } }),
160
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
160
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
161
161
  ],
162
162
  })
163
163
  ], PostgresQueue);