@adimm/x-injection 1.1.6 → 1.2.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.ts CHANGED
@@ -164,8 +164,9 @@ declare const GlobalContainer: Container;
164
164
  declare class ProviderModule implements IProviderModule {
165
165
  isDisposed: boolean;
166
166
  readonly identifier: ModuleIdentifier;
167
- isMarkedAsGlobal: boolean;
168
- protected isAppModule: boolean;
167
+ isGlobal: boolean;
168
+ protected isAppModule: IProviderModuleNaked['isAppModule'];
169
+ protected instantiatedFromDefinition: IProviderModuleNaked['instantiatedFromDefinition'];
169
170
  protected container: Container;
170
171
  protected defaultScope: IProviderModuleNaked['defaultScope'];
171
172
  protected onReady: IProviderModuleNaked['onReady'];
@@ -323,8 +324,11 @@ declare class GlobalAppModule extends ProviderModule implements IAppModule {
323
324
  private isLoaded;
324
325
  constructor();
325
326
  register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
327
+ lazyImport(...modules: ProviderModuleOrDefinition[]): void;
326
328
  toNaked(): IAppModule & IProviderModuleNaked;
327
329
  dispose(): Promise<void>;
330
+ /** **Internally used, do not use!** */
331
+ _importWithoutSecondaryImportCheck(...modules: ProviderModuleOrDefinition[]): void;
328
332
  private checkIfRegisteredModulesHaveGlobalMark;
329
333
  }
330
334
  /**
@@ -377,12 +381,14 @@ declare class ProviderModuleDefinition implements IProviderModuleDefinition {
377
381
  providers: IProviderModuleDefinition['providers'];
378
382
  exports: IProviderModuleDefinition['exports'];
379
383
  defaultScope: IProviderModuleDefinition['defaultScope'];
380
- markAsGlobal: IProviderModuleDefinition['markAsGlobal'];
384
+ isGlobal: IProviderModuleDefinition['isGlobal'];
381
385
  onReady: IProviderModuleDefinition['onReady'];
382
386
  onDispose: IProviderModuleDefinition['onDispose'];
383
387
  constructor(moduleOptions: ProviderModuleOptions);
384
388
  getDefinition(): ProviderModuleOptions;
389
+ clone(definition?: Partial<ProviderModuleOptions>): IProviderModuleDefinition;
385
390
  toString(): string;
391
+ private checkIfShouldBeAddedToTheGlobalRegister;
386
392
  }
387
393
 
388
394
  interface ProviderModuleOptions {
@@ -406,17 +412,17 @@ interface ProviderModuleOptions {
406
412
  */
407
413
  defaultScope?: InjectionScope;
408
414
  /**
409
- * This option is only a _marker_, per se it doesn't do anything
410
- * apart from marking this module as `global`.
411
415
  * When a module is marked as `global`, it means that it is expected to be _imported_ into the `AppModule`.
412
416
  *
417
+ * **Note:** _Importing a `global` module into a `scoped` module will automatically import it into the `AppModule` rather than the scoped module itself!_
418
+ *
413
419
  * Expect an exception to be thrown:
414
420
  * - If a `module` marked as global is **not** imported into the `AppModule`.
415
421
  * - If a `module` **not** marked as global _is_ imported into the `AppModule`
416
422
  *
417
423
  * Defaults to `false`.
418
424
  */
419
- markAsGlobal?: boolean;
425
+ isGlobal?: boolean;
420
426
  /**
421
427
  * Callback which will be invoked once the module container has been initialized
422
428
  * and the providers resolved.
@@ -435,6 +441,7 @@ interface ProviderModuleOptions {
435
441
  }
436
442
  interface ProviderModuleOptionsInternal {
437
443
  isAppModule?: boolean;
444
+ instantiatedFromDefinition?: boolean;
438
445
  isDisposed?: boolean;
439
446
  /** Can be used to manually provide the {@link IAppModule} instance. */
440
447
  appModule?: () => GlobalAppModule;
@@ -466,6 +473,24 @@ type OnDisposeOptions = RequireAtLeastOne<{
466
473
  interface IProviderModuleDefinition extends ProviderModuleOptions {
467
474
  /** Returns the {@link ProviderModuleOptions | definition}. */
468
475
  getDefinition(): ProviderModuleOptions;
476
+ /**
477
+ * Can be used to _clone_ the instance of this {@link IProviderModuleDefinition | ModuleDefinition}.
478
+ *
479
+ * @param definition Optionally you can overwrite the definition of the clone before being returned.
480
+ *
481
+ * ```ts
482
+ * const CarModuleDefinition = new ProviderModuleDefinition({
483
+ * identifier: 'CarModuleDefinition',
484
+ * providers: [CarService],
485
+ * });
486
+ *
487
+ * const CarModuleDefinitionMocked = CarModuleDefinition.clone({
488
+ * identifier: 'CarModuleDefinitionMocked',
489
+ * providers: [{ provide: CarService, useClass: CarServiceMocked }]
490
+ * });
491
+ * ```
492
+ */
493
+ clone(definition?: Partial<ProviderModuleOptions>): IProviderModuleDefinition;
469
494
  /** Returns the {@link ProviderModuleOptions.identifier | identifier}. */
470
495
  toString(): string;
471
496
  }
@@ -478,10 +503,10 @@ interface IProviderModuleDefinition extends ProviderModuleOptions {
478
503
  declare class ProviderModuleUtils {
479
504
  /** The low-level InversifyJS {@link Container} owned by {@link ProviderModuleUtils.module | module}. */
480
505
  get container(): Container;
506
+ readonly appModule: GlobalAppModule;
481
507
  /** The parent {@link IProviderModule | ProviderModule} of `this` instance. */
482
508
  readonly module: IProviderModule;
483
509
  readonly moduleNaked: IProviderModuleNaked;
484
- private readonly appModule;
485
510
  constructor(module: IProviderModule, internalOptions: ProviderModuleOptionsInternal);
486
511
  /**
487
512
  * Low-level method which can be used to manually register _(bind)_ a new {@link provider} into the {@link ProviderModuleUtils.module | module} container.
@@ -509,8 +534,10 @@ declare class ProviderModuleUtils {
509
534
 
510
535
  /** Can be used to publicly expose internal properties and methods of an {@link IProviderModule} instance. */
511
536
  interface IProviderModuleNaked extends IProviderModule {
512
- /** It'll be true when the current module is the global `AppModule`. */
537
+ /** It'll be `true` when the current module is the global `AppModule`. */
513
538
  readonly isAppModule: boolean;
539
+ /** It'll be `true` when the `module` has been instantiated from a `ProviderModuleDefinition` instance. */
540
+ readonly instantiatedFromDefinition: boolean;
514
541
  /** The low-level `InversifyJS` {@link https://inversify.io/docs/api/container/ | container} instance. */
515
542
  readonly container: Container;
516
543
  /** The default injection scope of this module. */
@@ -704,8 +731,8 @@ type OnUnbindEffects = {
704
731
  interface IProviderModule {
705
732
  /** The module unique ID. */
706
733
  readonly identifier: ModuleIdentifier;
707
- /** See {@link ProviderModuleOptions.markAsGlobal}. */
708
- readonly isMarkedAsGlobal: ProviderModuleOptions['markAsGlobal'];
734
+ /** See {@link ProviderModuleOptions.isGlobal}. */
735
+ readonly isGlobal: ProviderModuleOptions['isGlobal'];
709
736
  readonly isDisposed: boolean;
710
737
  /**
711
738
  * Can be used to retrieve a resolved `dependency` from the module container.
@@ -770,13 +797,13 @@ type ProviderModuleGetManyParam<T> = {
770
797
  isOptional?: boolean;
771
798
  };
772
799
 
773
- interface IAppModule extends Except<IProviderModule, 'isMarkedAsGlobal'> {
800
+ interface IAppModule extends Except<IProviderModule, 'isGlobal'> {
774
801
  readonly _strict: AppModuleOptions['_strict'];
775
802
  /** Must be invoked _(only once during the application lifecycle)_ in order to provide the {@link options} to the module. */
776
803
  register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
777
804
  toNaked(): IAppModule & IProviderModuleNaked;
778
805
  }
779
- interface AppModuleOptions extends Except<InternalInitOptions, 'appModule' | 'markAsGlobal' | 'exports' | 'isDisposed'> {
806
+ interface AppModuleOptions extends Except<InternalInitOptions, 'appModule' | 'isGlobal' | 'exports' | 'isDisposed'> {
780
807
  /**
781
808
  * When set to `true` it'll enforce an opinionated set of rules
782
809
  * which _can help_ in avoiding common pitfalls which may otherwise produce
@@ -784,7 +811,7 @@ interface AppModuleOptions extends Except<InternalInitOptions, 'appModule' | 'ma
784
811
  *
785
812
  * **Note:** _Do not open an `issue` if a bug or edge-case is caused by having the `strict` property disabled!_
786
813
  *
787
- * - `markAsGlobal`: Will not be enforced anymore.
814
+ * - `isGlobal`: Will not be enforced anymore.
788
815
  *
789
816
  * Defaults to `true`.
790
817
  */
@@ -820,25 +847,25 @@ declare class InjectionError extends Error {
820
847
  /** Exception which indicates that there is a generic error with an instance of {@link IProviderModule}. */
821
848
  declare class InjectionProviderModuleError extends Error {
822
849
  name: string;
823
- constructor(module: IProviderModule, message: string);
850
+ constructor(module: ProviderModuleOrDefinition, message: string);
824
851
  }
825
852
 
826
853
  /** Exception which indicates an invokation of a disposed module. */
827
854
  declare class InjectionProviderModuleDisposedError extends InjectionProviderModuleError {
828
855
  name: string;
829
- constructor(module: IProviderModule);
856
+ constructor(module: ProviderModuleOrDefinition);
830
857
  }
831
858
 
832
859
  /** Exception which indicates that a module has been initialized without an `identifier`. */
833
860
  declare class InjectionProviderModuleMissingIdentifierError extends InjectionProviderModuleError {
834
861
  name: string;
835
- constructor(module: IProviderModule);
862
+ constructor(module: ProviderModuleOrDefinition);
836
863
  }
837
864
 
838
- /** Exception which indicates an error with regards to the `markAsGlobal` option. */
865
+ /** Exception which indicates an error with regards to the `isGlobal` option. */
839
866
  declare class InjectionProviderModuleGlobalMarkError extends InjectionProviderModuleError {
840
867
  name: string;
841
- constructor(module: IProviderModule, message: string);
868
+ constructor(module: ProviderModuleOrDefinition, message: string);
842
869
  }
843
870
 
844
871
  declare function injectionScopeToBindingScope(injectionScope: InjectionScope): BindingScope;