@adimm/x-injection 2.1.2 → 3.0.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/dist/index.d.cts CHANGED
@@ -140,8 +140,6 @@ declare enum DefinitionEventType {
140
140
  /** See {@link https://inversify.io/docs/api/decorator/#injectable} for more details. */
141
141
  declare function Injectable(scope?: InjectionScope): ClassDecorator;
142
142
 
143
- type AsyncMethod<T = void> = () => Promise<T>;
144
-
145
143
  type ProviderToken<T = any> = ProviderIdentifier<T> | DependencyProvider<T>;
146
144
  type DependencyProvider<T = any> = Class<T> | Function | ProviderClassToken<T> | ProviderValueToken<T> | ProviderFactoryToken<T>;
147
145
  type ProviderClassToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
@@ -274,19 +272,6 @@ interface IDynamicModuleDefinition {
274
272
  * @param addToExports When set to `true` it'll also `export` the {@link moduleOrBlueprint}. _(defaults to `false`)_
275
273
  */
276
274
  addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
277
- /**
278
- * Can be used to _lazily_ `import` a new {@link module} into the current {@link IProviderModule | Module}.
279
- *
280
- * **Note:** _This is useful when you want to lazy import a module from within another file._
281
- *
282
- * ```ts
283
- * addImportLazy(async () => import('./lazy.module'));
284
- * ```
285
- *
286
- * @param lazyCb An `async` callback which will resolve the {@link IProviderModule | Module} to be imported.
287
- * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
288
- */
289
- addImportLazy(lazyCb: AsyncMethod<IProviderModule>, addToExports?: boolean): Promise<void>;
290
275
  /**
291
276
  * Can be used to `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
292
277
  *
@@ -294,24 +279,11 @@ interface IDynamicModuleDefinition {
294
279
  * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
295
280
  */
296
281
  addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
297
- /**
298
- * Can be used to _lazily_ `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
299
- *
300
- * **Note:** _This is useful when you want to lazy import a provider from within another file._
301
- *
302
- * ```ts
303
- * addImportLazy(async () => import('./lazy.provider'));
304
- * ```
305
- *
306
- * @param lazyCb An `async` callback which will resolve the {@link DependencyProvider | Provider} to add.
307
- * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
308
- */
309
- addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
310
282
  /**
311
283
  * Can be used to remove an `import` from the _current_ {@link IProviderModule | Module}.
312
284
  * It'll also automatically remove it from the `exports` definition.
313
285
  *
314
- * **Note:** _You can always add it back with the {@link addImport} or {@link addImportLazy} methods._
286
+ * **Note:** _You can always add it back with the {@link addImport} method._
315
287
  *
316
288
  * @param moduleOrId Either the `module` reference itself or its `id`.
317
289
  */
@@ -320,7 +292,7 @@ interface IDynamicModuleDefinition {
320
292
  * Can be used to remove a `provider` from the _current_ {@link IProviderModule | Module}'s `container`.
321
293
  * It'll also automatically remove it from the `exports` definition.
322
294
  *
323
- * **Note:** _You can always add it back with the {@link addProvider} or {@link addProviderLazy} methods._
295
+ * **Note:** _You can always add it back with the {@link addProvider} method._
324
296
  *
325
297
  * @param providerOrIdentifier Either the `provider` reference itself or its `{ provide }` property value.
326
298
  */
@@ -352,9 +324,7 @@ declare class DynamicModuleDefinition implements IDynamicModuleDefinition {
352
324
  private importedModuleSubscriptions;
353
325
  constructor(providerModule: ProviderModule);
354
326
  addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
355
- addImportLazy(lazyCb: AsyncMethod<ProviderModule>, addToExports?: boolean): Promise<void>;
356
327
  addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
357
- addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
358
328
  removeImport(moduleOrId: IProviderModule | ModuleIdentifier): boolean;
359
329
  removeProvider<T>(providerOrIdentifier: DependencyProvider<T> | ProviderIdentifier<T>): boolean;
360
330
  removeFromExports(exportDefinition: ExportDefinition): boolean;
@@ -366,6 +336,7 @@ declare class DynamicModuleDefinition implements IDynamicModuleDefinition {
366
336
  private createImportedModuleContainer;
367
337
  private subscribeToImportedModuleEvents;
368
338
  private unsubscribeFromImportedModuleEvents;
339
+ private applyMiddlewareGuard;
369
340
  }
370
341
 
371
342
  interface IMiddlewaresManager {
@@ -380,6 +351,9 @@ declare class MiddlewaresManager implements IMiddlewaresManager {
380
351
  constructor(providerModule: ProviderModule);
381
352
  add<T extends MiddlewareType>(type: MiddlewareType, cb: AddMiddlewareCallbackType<T>): void;
382
353
  applyMiddlewares<T>(type: MiddlewareType, ...args: any[]): T;
354
+ private applyChainMiddleware;
355
+ private applyReduceMiddleware;
356
+ private applyBooleanMiddleware;
383
357
  clear(): void;
384
358
  dispose(): void;
385
359
  }
@@ -686,6 +660,52 @@ declare class ProviderModule implements IProviderModule {
686
660
  private throwIfDisposed;
687
661
  }
688
662
 
663
+ /**
664
+ * Base class for creating OOP-style modules with composition pattern.
665
+ *
666
+ * Provides a clean separation between your custom module logic and the `DI` container
667
+ * by exposing all {@link ProviderModule} functionality through the `module` property.
668
+ *
669
+ * This avoids naming conflicts between your methods and {@link ProviderModule} methods.
670
+ *
671
+ * ```ts
672
+ * Injectable()
673
+ * class UserService {
674
+ * get(id: string) {
675
+ * // ... get logic
676
+ * }
677
+ * }
678
+ *
679
+ * class AuthModule extends ProviderModuleClass {
680
+ * constructor() {
681
+ * super({
682
+ * id: 'AuthModule',
683
+ * providers: [UserService],
684
+ * exports: [UserService],
685
+ * });
686
+ * }
687
+ *
688
+ * // Your custom methods - no conflicts with the `ProviderModule` class methods
689
+ * authenticateUser(userId: string) {
690
+ * const userService = this.module.get(UserService);
691
+ *
692
+ * return userService.get(userId);
693
+ * }
694
+ * }
695
+ *
696
+ * const authModule = new AuthModule();
697
+ * authModule.authenticateUser('123');
698
+ * ```
699
+ */
700
+ declare class ProviderModuleClass {
701
+ /**
702
+ * The underlying {@link ProviderModule} instance.
703
+ * Access all `DI` container methods through this property.
704
+ */
705
+ readonly module: IProviderModule;
706
+ constructor(options: ProviderModuleOptions);
707
+ }
708
+
689
709
  /**
690
710
  * The `root` {@link IProviderModule} of your application.
691
711
  *
@@ -717,16 +737,12 @@ declare function MultiInject(provider: ProviderToken): MethodDecorator & Paramet
717
737
 
718
738
  /** See {@link https://inversify.io/docs/api/decorator/#injectfrombase} for more details. */
719
739
  declare function InjectFromBase(options?: Parameters<typeof injectFromBase>[0]): ClassDecorator;
720
-
721
740
  /** See {@link https://inversify.io/docs/api/decorator/#named} for more details. */
722
741
  declare function Named(name: MetadataName): MethodDecorator & ParameterDecorator & PropertyDecorator;
723
-
724
742
  /** See {@link https://inversify.io/docs/api/decorator/#optional} for more details. */
725
743
  declare function Optional(): MethodDecorator & ParameterDecorator & PropertyDecorator;
726
-
727
744
  /** See {@link https://inversify.io/docs/api/decorator/#tagged} for more details. */
728
745
  declare function Tagged(key: MetadataTag, value: unknown): MethodDecorator & ParameterDecorator & PropertyDecorator;
729
-
730
746
  /** See {@link https://inversify.io/docs/api/decorator/#unmanaged} for more details. */
731
747
  declare function Unmanaged(): MethodDecorator & ParameterDecorator & PropertyDecorator;
732
748
 
@@ -792,7 +808,6 @@ declare namespace ProviderTokenHelpers {
792
808
  function tryGetScopeFromProvider(provider: ProviderToken): InjectionScope | undefined;
793
809
  function tryGetDecoratorScopeFromClass<T = any>(provider: ProviderToken<T>): InjectionScope | undefined;
794
810
  }
795
-
796
811
  declare namespace ProviderModuleHelpers {
797
812
  function isModule(value: any): value is IProviderModule;
798
813
  function isBlueprint(value: any): value is ProviderModuleBlueprint;
@@ -802,13 +817,9 @@ declare namespace ProviderModuleHelpers {
802
817
  }
803
818
 
804
819
  declare function isPlainObject(o: any): o is object;
805
-
806
820
  declare function isClass(v: any): boolean;
807
-
808
- declare function isFunction(v: any): boolean;
809
-
810
821
  declare function isClassOrFunction(value: any): value is Function | Class<any>;
811
822
 
812
823
  declare function deepClone<T>(obj: T): T;
813
824
 
814
- export { AppModule, DefinitionEventType, type DependencyProvider, type ExportDefinition, type ExportsDefinition, type ExportsDefinitionOptimized, IProviderModule, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionProviderModuleMissingProviderError, InjectionProviderModuleUnknownProviderError, InjectionScope, MiddlewareType, type ModuleOrBlueprint, MultiInject, Named, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, ProviderModuleBlueprint, type ProviderModuleGetManyParam, type ProviderModuleGetManyReturn, type ProviderModuleGetReturn, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, Tagged, Unmanaged, bindingScopeToInjectionScope, deepClone, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
825
+ export { AppModule, DefinitionEventType, type DependencyProvider, type ExportDefinition, type ExportsDefinition, type ExportsDefinitionOptimized, IProviderModule, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionProviderModuleMissingProviderError, InjectionProviderModuleUnknownProviderError, InjectionScope, MiddlewareType, type ModuleOrBlueprint, MultiInject, Named, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, ProviderModuleBlueprint, ProviderModuleClass, type ProviderModuleGetManyParam, type ProviderModuleGetManyReturn, type ProviderModuleGetReturn, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, Tagged, Unmanaged, bindingScopeToInjectionScope, deepClone, injectionScopeToBindingScope, isClass, isClassOrFunction, isPlainObject };
package/dist/index.d.ts CHANGED
@@ -140,8 +140,6 @@ declare enum DefinitionEventType {
140
140
  /** See {@link https://inversify.io/docs/api/decorator/#injectable} for more details. */
141
141
  declare function Injectable(scope?: InjectionScope): ClassDecorator;
142
142
 
143
- type AsyncMethod<T = void> = () => Promise<T>;
144
-
145
143
  type ProviderToken<T = any> = ProviderIdentifier<T> | DependencyProvider<T>;
146
144
  type DependencyProvider<T = any> = Class<T> | Function | ProviderClassToken<T> | ProviderValueToken<T> | ProviderFactoryToken<T>;
147
145
  type ProviderClassToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
@@ -274,19 +272,6 @@ interface IDynamicModuleDefinition {
274
272
  * @param addToExports When set to `true` it'll also `export` the {@link moduleOrBlueprint}. _(defaults to `false`)_
275
273
  */
276
274
  addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
277
- /**
278
- * Can be used to _lazily_ `import` a new {@link module} into the current {@link IProviderModule | Module}.
279
- *
280
- * **Note:** _This is useful when you want to lazy import a module from within another file._
281
- *
282
- * ```ts
283
- * addImportLazy(async () => import('./lazy.module'));
284
- * ```
285
- *
286
- * @param lazyCb An `async` callback which will resolve the {@link IProviderModule | Module} to be imported.
287
- * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
288
- */
289
- addImportLazy(lazyCb: AsyncMethod<IProviderModule>, addToExports?: boolean): Promise<void>;
290
275
  /**
291
276
  * Can be used to `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
292
277
  *
@@ -294,24 +279,11 @@ interface IDynamicModuleDefinition {
294
279
  * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
295
280
  */
296
281
  addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
297
- /**
298
- * Can be used to _lazily_ `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
299
- *
300
- * **Note:** _This is useful when you want to lazy import a provider from within another file._
301
- *
302
- * ```ts
303
- * addImportLazy(async () => import('./lazy.provider'));
304
- * ```
305
- *
306
- * @param lazyCb An `async` callback which will resolve the {@link DependencyProvider | Provider} to add.
307
- * @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
308
- */
309
- addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
310
282
  /**
311
283
  * Can be used to remove an `import` from the _current_ {@link IProviderModule | Module}.
312
284
  * It'll also automatically remove it from the `exports` definition.
313
285
  *
314
- * **Note:** _You can always add it back with the {@link addImport} or {@link addImportLazy} methods._
286
+ * **Note:** _You can always add it back with the {@link addImport} method._
315
287
  *
316
288
  * @param moduleOrId Either the `module` reference itself or its `id`.
317
289
  */
@@ -320,7 +292,7 @@ interface IDynamicModuleDefinition {
320
292
  * Can be used to remove a `provider` from the _current_ {@link IProviderModule | Module}'s `container`.
321
293
  * It'll also automatically remove it from the `exports` definition.
322
294
  *
323
- * **Note:** _You can always add it back with the {@link addProvider} or {@link addProviderLazy} methods._
295
+ * **Note:** _You can always add it back with the {@link addProvider} method._
324
296
  *
325
297
  * @param providerOrIdentifier Either the `provider` reference itself or its `{ provide }` property value.
326
298
  */
@@ -352,9 +324,7 @@ declare class DynamicModuleDefinition implements IDynamicModuleDefinition {
352
324
  private importedModuleSubscriptions;
353
325
  constructor(providerModule: ProviderModule);
354
326
  addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
355
- addImportLazy(lazyCb: AsyncMethod<ProviderModule>, addToExports?: boolean): Promise<void>;
356
327
  addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
357
- addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
358
328
  removeImport(moduleOrId: IProviderModule | ModuleIdentifier): boolean;
359
329
  removeProvider<T>(providerOrIdentifier: DependencyProvider<T> | ProviderIdentifier<T>): boolean;
360
330
  removeFromExports(exportDefinition: ExportDefinition): boolean;
@@ -366,6 +336,7 @@ declare class DynamicModuleDefinition implements IDynamicModuleDefinition {
366
336
  private createImportedModuleContainer;
367
337
  private subscribeToImportedModuleEvents;
368
338
  private unsubscribeFromImportedModuleEvents;
339
+ private applyMiddlewareGuard;
369
340
  }
370
341
 
371
342
  interface IMiddlewaresManager {
@@ -380,6 +351,9 @@ declare class MiddlewaresManager implements IMiddlewaresManager {
380
351
  constructor(providerModule: ProviderModule);
381
352
  add<T extends MiddlewareType>(type: MiddlewareType, cb: AddMiddlewareCallbackType<T>): void;
382
353
  applyMiddlewares<T>(type: MiddlewareType, ...args: any[]): T;
354
+ private applyChainMiddleware;
355
+ private applyReduceMiddleware;
356
+ private applyBooleanMiddleware;
383
357
  clear(): void;
384
358
  dispose(): void;
385
359
  }
@@ -686,6 +660,52 @@ declare class ProviderModule implements IProviderModule {
686
660
  private throwIfDisposed;
687
661
  }
688
662
 
663
+ /**
664
+ * Base class for creating OOP-style modules with composition pattern.
665
+ *
666
+ * Provides a clean separation between your custom module logic and the `DI` container
667
+ * by exposing all {@link ProviderModule} functionality through the `module` property.
668
+ *
669
+ * This avoids naming conflicts between your methods and {@link ProviderModule} methods.
670
+ *
671
+ * ```ts
672
+ * Injectable()
673
+ * class UserService {
674
+ * get(id: string) {
675
+ * // ... get logic
676
+ * }
677
+ * }
678
+ *
679
+ * class AuthModule extends ProviderModuleClass {
680
+ * constructor() {
681
+ * super({
682
+ * id: 'AuthModule',
683
+ * providers: [UserService],
684
+ * exports: [UserService],
685
+ * });
686
+ * }
687
+ *
688
+ * // Your custom methods - no conflicts with the `ProviderModule` class methods
689
+ * authenticateUser(userId: string) {
690
+ * const userService = this.module.get(UserService);
691
+ *
692
+ * return userService.get(userId);
693
+ * }
694
+ * }
695
+ *
696
+ * const authModule = new AuthModule();
697
+ * authModule.authenticateUser('123');
698
+ * ```
699
+ */
700
+ declare class ProviderModuleClass {
701
+ /**
702
+ * The underlying {@link ProviderModule} instance.
703
+ * Access all `DI` container methods through this property.
704
+ */
705
+ readonly module: IProviderModule;
706
+ constructor(options: ProviderModuleOptions);
707
+ }
708
+
689
709
  /**
690
710
  * The `root` {@link IProviderModule} of your application.
691
711
  *
@@ -717,16 +737,12 @@ declare function MultiInject(provider: ProviderToken): MethodDecorator & Paramet
717
737
 
718
738
  /** See {@link https://inversify.io/docs/api/decorator/#injectfrombase} for more details. */
719
739
  declare function InjectFromBase(options?: Parameters<typeof injectFromBase>[0]): ClassDecorator;
720
-
721
740
  /** See {@link https://inversify.io/docs/api/decorator/#named} for more details. */
722
741
  declare function Named(name: MetadataName): MethodDecorator & ParameterDecorator & PropertyDecorator;
723
-
724
742
  /** See {@link https://inversify.io/docs/api/decorator/#optional} for more details. */
725
743
  declare function Optional(): MethodDecorator & ParameterDecorator & PropertyDecorator;
726
-
727
744
  /** See {@link https://inversify.io/docs/api/decorator/#tagged} for more details. */
728
745
  declare function Tagged(key: MetadataTag, value: unknown): MethodDecorator & ParameterDecorator & PropertyDecorator;
729
-
730
746
  /** See {@link https://inversify.io/docs/api/decorator/#unmanaged} for more details. */
731
747
  declare function Unmanaged(): MethodDecorator & ParameterDecorator & PropertyDecorator;
732
748
 
@@ -792,7 +808,6 @@ declare namespace ProviderTokenHelpers {
792
808
  function tryGetScopeFromProvider(provider: ProviderToken): InjectionScope | undefined;
793
809
  function tryGetDecoratorScopeFromClass<T = any>(provider: ProviderToken<T>): InjectionScope | undefined;
794
810
  }
795
-
796
811
  declare namespace ProviderModuleHelpers {
797
812
  function isModule(value: any): value is IProviderModule;
798
813
  function isBlueprint(value: any): value is ProviderModuleBlueprint;
@@ -802,13 +817,9 @@ declare namespace ProviderModuleHelpers {
802
817
  }
803
818
 
804
819
  declare function isPlainObject(o: any): o is object;
805
-
806
820
  declare function isClass(v: any): boolean;
807
-
808
- declare function isFunction(v: any): boolean;
809
-
810
821
  declare function isClassOrFunction(value: any): value is Function | Class<any>;
811
822
 
812
823
  declare function deepClone<T>(obj: T): T;
813
824
 
814
- export { AppModule, DefinitionEventType, type DependencyProvider, type ExportDefinition, type ExportsDefinition, type ExportsDefinitionOptimized, IProviderModule, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionProviderModuleMissingProviderError, InjectionProviderModuleUnknownProviderError, InjectionScope, MiddlewareType, type ModuleOrBlueprint, MultiInject, Named, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, ProviderModuleBlueprint, type ProviderModuleGetManyParam, type ProviderModuleGetManyReturn, type ProviderModuleGetReturn, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, Tagged, Unmanaged, bindingScopeToInjectionScope, deepClone, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
825
+ export { AppModule, DefinitionEventType, type DependencyProvider, type ExportDefinition, type ExportsDefinition, type ExportsDefinitionOptimized, IProviderModule, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionProviderModuleMissingProviderError, InjectionProviderModuleUnknownProviderError, InjectionScope, MiddlewareType, type ModuleOrBlueprint, MultiInject, Named, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, ProviderModuleBlueprint, ProviderModuleClass, type ProviderModuleGetManyParam, type ProviderModuleGetManyReturn, type ProviderModuleGetReturn, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, Tagged, Unmanaged, bindingScopeToInjectionScope, deepClone, injectionScopeToBindingScope, isClass, isClassOrFunction, isPlainObject };