@tstdl/base 0.93.18 → 0.93.20

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);
@@ -1,4 +1,3 @@
1
- import type { ProvidersItem } from '../../../injector/injector.js';
2
1
  export declare const documentManagementDatabaseConfigFactoryProvider: import("../../../injector/provider.js").FactoryProvider<unknown, unknown, import("../../../types/types.js").Record>;
3
- export declare const documentManagementDatabaseConfigProvider: ProvidersItem;
2
+ export declare const documentManagementDatabaseConfigProvider: import("../../../injector/injector.js").ProvidersItem<unknown, unknown, import("../../../types/types.js").Record>;
4
3
  export declare function DocumentManagementSingleton(): ClassDecorator;
@@ -1,12 +1,10 @@
1
1
  import { Singleton } from '../../../injector/decorators.js';
2
+ import { provide } from '../../../injector/injector.js';
2
3
  import { factoryProvider } from '../../../injector/provider.js';
3
4
  import { DatabaseConfig } from '../../../orm/server/index.js';
4
5
  import { DocumentManagementConfiguration } from '../module.js';
5
- export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }));
6
- export const documentManagementDatabaseConfigProvider = {
7
- provide: DatabaseConfig,
8
- ...documentManagementDatabaseConfigFactoryProvider,
9
- };
6
+ export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }));
7
+ export const documentManagementDatabaseConfigProvider = provide(DatabaseConfig, documentManagementDatabaseConfigFactoryProvider);
10
8
  export function DocumentManagementSingleton() {
11
9
  return Singleton({ providers: [documentManagementDatabaseConfigProvider] });
12
10
  }
@@ -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>];
@@ -145,14 +145,16 @@ export class Injector {
145
145
  this.register(globalRegistration.token, globalRegistration.provider, globalRegistration.options);
146
146
  }
147
147
  }
148
- if (options?.skipSelf != true) {
149
- const ownRegistration = this.#registrations.get(token);
150
- if (isDefined(ownRegistration)) {
151
- return ownRegistration;
152
- }
148
+ const skipLevels = Number(options?.skipSelf ?? 0);
149
+ if (skipLevels > 0) {
150
+ return this.#parent?.tryGetRegistration(token, { ...options, skipSelf: skipLevels - 1 });
151
+ }
152
+ const ownRegistration = this.#registrations.get(token);
153
+ if (isDefined(ownRegistration)) {
154
+ return ownRegistration;
153
155
  }
154
156
  if (options?.onlySelf != true) {
155
- return this.#parent?.tryGetRegistration(token);
157
+ return this.#parent?.tryGetRegistration(token, options);
156
158
  }
157
159
  return undefined;
158
160
  }
@@ -280,14 +282,11 @@ export class Injector {
280
282
  if (isUndefined(token)) {
281
283
  throw new ResolveError('Token is undefined. This might be due to a circular dependency. Consider using an alias or forwardRef.', chain);
282
284
  }
283
- const registration = (options.skipSelf == true) ? undefined : this.tryGetRegistration(token);
285
+ const registration = this.tryGetRegistration(token, options);
284
286
  if (isDefined(registration)) {
285
287
  const singleRegistration = isArray(registration) ? registration[0] : registration;
286
288
  return this._resolveRegistration(singleRegistration, argument, options, context, chain);
287
289
  }
288
- if (isNotNull(this.#parent) && (options.onlySelf != true)) {
289
- return this.#parent._resolve(token, argument, { ...options, skipSelf: false }, context, chain);
290
- }
291
290
  if (options.optional == true) {
292
291
  return undefined;
293
292
  }
@@ -305,18 +304,24 @@ export class Injector {
305
304
  if (isUndefined(token)) {
306
305
  throw new ResolveError('Token is undefined. This might be due to a circular dependency. Consider using an alias or forwardRef.', chain);
307
306
  }
308
- const registration = (options.skipSelf == true) ? undefined : this.tryGetRegistration(token);
309
- if (isDefined(registration)) {
310
- const registrations = isArray(registration) ? registration : [registration];
311
- return registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
307
+ const ownValues = [];
308
+ const parentValues = [];
309
+ if (options.skipSelf != true) {
310
+ const registration = this.tryGetRegistration(token, { onlySelf: true });
311
+ if (isDefined(registration)) {
312
+ const registrations = isArray(registration) ? registration : [registration];
313
+ const resolved = registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
314
+ ownValues.push(...resolved);
315
+ }
312
316
  }
313
317
  if (isNotNull(this.#parent) && (options.onlySelf != true)) {
314
- return this.#parent._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain);
318
+ parentValues.push(...this.#parent._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain));
315
319
  }
316
- if (options.optional == true) {
317
- return [];
320
+ const allValues = [...ownValues, ...parentValues];
321
+ if ((allValues.length == 0) && (options.optional != true)) {
322
+ throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
318
323
  }
319
- throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
324
+ return allValues;
320
325
  }
321
326
  _resolveRegistration(registration, argument, options, context, chain) {
322
327
  checkOverflow(chain, context);
@@ -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/mail/module.js CHANGED
@@ -31,6 +31,6 @@ export async function migrateMailSchema() {
31
31
  await migrate(database, {
32
32
  migrationsSchema: 'mail',
33
33
  migrationsTable: '_migrations',
34
- migrationsFolder: import.meta.resolve('./drizzle').replace('file://', '')
34
+ migrationsFolder: import.meta.resolve('./drizzle').replace('file://', ''),
35
35
  });
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.18",
3
+ "version": "0.93.20",
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);