@adimm/x-injection 0.5.2 → 0.6.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/README.md +76 -0
- package/dist/index.cjs +176 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +468 -441
- package/dist/index.d.ts +468 -441
- package/dist/index.js +158 -123
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -106,7 +106,8 @@ declare class ProviderModuleUtils {
|
|
|
106
106
|
/** The parent {@link IProviderModule | ProviderModule} of `this` instance. */
|
|
107
107
|
readonly module: IProviderModule;
|
|
108
108
|
readonly moduleNaked: IProviderModuleNaked;
|
|
109
|
-
|
|
109
|
+
private readonly appModule;
|
|
110
|
+
constructor(module: IProviderModule, internalOptions: ProviderModuleOptionsInternal);
|
|
110
111
|
/**
|
|
111
112
|
* Low-level method which can be used to manually register _(bind)_ a new {@link provider} into the {@link ProviderModuleUtils.module | module} container.
|
|
112
113
|
*
|
|
@@ -118,6 +119,7 @@ declare class ProviderModuleUtils {
|
|
|
118
119
|
* @returns `true` when the {@link provider} has been bound otherwhise `false`.
|
|
119
120
|
*/
|
|
120
121
|
bindToContainer<T>(provider: DependencyProvider<T>, defaultScope: InjectionScope): boolean;
|
|
122
|
+
private checkIfShouldBeImportedIntoAppModule;
|
|
121
123
|
private bindSelfTokenToContainer;
|
|
122
124
|
private bindClassTokenToContainer;
|
|
123
125
|
private bindValueTokenToContainer;
|
|
@@ -330,567 +332,592 @@ interface IProviderModuleNaked extends IProviderModule {
|
|
|
330
332
|
}
|
|
331
333
|
type LazyInitOptions = Except<ProviderModuleOptions & ProviderModuleOptionsInternal, 'identifier' | 'isAppModule'>;
|
|
332
334
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
335
|
+
/**
|
|
336
|
+
* The low-level App Container.
|
|
337
|
+
*
|
|
338
|
+
* **Internally used, please use the `AppModule` to interact with it.**
|
|
339
|
+
*/
|
|
340
|
+
declare const GlobalContainer: Container;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Modules are highly recommended as an effective way to organize your components.
|
|
344
|
+
* For most applications, you'll likely have multiple modules, each encapsulating a closely related set of capabilities.
|
|
345
|
+
*
|
|
346
|
+
* _See {@link ProviderModuleOptions | ProviderModuleOptions}_.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const EngineModule = new ProviderModule({
|
|
351
|
+
* identifier: Symbol('EngineModule'),
|
|
352
|
+
* providers: [EngineService],
|
|
353
|
+
* exports: [EngineService]
|
|
354
|
+
* });
|
|
355
|
+
*
|
|
356
|
+
* const DashboardModule = new ProviderModule({
|
|
357
|
+
* identifier: Symbol('DashboardModule'),
|
|
358
|
+
* providers: [DashboardService],
|
|
359
|
+
* exports: [DashboardService]
|
|
360
|
+
* });
|
|
361
|
+
*
|
|
362
|
+
* const CarModule = new ProviderModule({
|
|
363
|
+
* identifier: Symbol('CarModule'),
|
|
364
|
+
* imports: [EngineModule, DashboardModule],
|
|
365
|
+
* providers: [CarService],
|
|
366
|
+
* exports: [CarService]
|
|
367
|
+
* });
|
|
368
|
+
*
|
|
369
|
+
* // Run-time class replacement:
|
|
370
|
+
* const RedCarModule = new ProviderModule({
|
|
371
|
+
* identifier: Symbol('RedCarModule'),
|
|
372
|
+
* imports: [CarModule],
|
|
373
|
+
* providers: [
|
|
374
|
+
* {
|
|
375
|
+
* provide: CarService,
|
|
376
|
+
* useClass: RedCarService,
|
|
377
|
+
* }
|
|
378
|
+
* ],
|
|
379
|
+
* });
|
|
380
|
+
*
|
|
381
|
+
* // Run-time factory example:
|
|
382
|
+
* const BlackCarModule = new ProviderModule({
|
|
383
|
+
* identifier: Symbol('BlackCarModule'),
|
|
384
|
+
* imports: [CarModule],
|
|
385
|
+
* providers: [
|
|
386
|
+
* {
|
|
387
|
+
* provide: CarService,
|
|
388
|
+
* useFactory: (carService: CarService) => {
|
|
389
|
+
* carService.setColor('black');
|
|
390
|
+
*
|
|
391
|
+
* return carService;
|
|
392
|
+
* },
|
|
393
|
+
* inject: [CarService]
|
|
394
|
+
* }
|
|
395
|
+
* ],
|
|
396
|
+
* });
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
declare class ProviderModule implements IProviderModule {
|
|
400
|
+
readonly identifier: symbol;
|
|
401
|
+
readonly isMarkedAsGlobal: boolean;
|
|
402
|
+
readonly isDisposed: boolean;
|
|
403
|
+
protected readonly isAppModule: boolean;
|
|
404
|
+
protected readonly container: Container;
|
|
405
|
+
protected readonly defaultScope: IProviderModuleNaked['defaultScope'];
|
|
406
|
+
protected readonly dynamicExports: IProviderModuleNaked['dynamicExports'];
|
|
407
|
+
protected readonly onReady: IProviderModuleNaked['onReady'];
|
|
408
|
+
protected readonly onDispose: IProviderModuleNaked['onDispose'];
|
|
409
|
+
protected readonly importedProvidersMap: IProviderModuleNaked['importedProvidersMap'];
|
|
410
|
+
protected readonly moduleUtils: IProviderModuleNaked['moduleUtils'];
|
|
411
|
+
protected readonly imports: IProviderModuleNaked['imports'];
|
|
412
|
+
protected readonly providers: IProviderModuleNaked['providers'];
|
|
413
|
+
protected readonly importedProviders: IProviderModuleNaked['importedProviders'];
|
|
414
|
+
protected readonly exports: IProviderModuleNaked['exports'];
|
|
415
|
+
private readonly registeredBindingSideEffects;
|
|
416
|
+
constructor({ identifier, imports, providers, exports, defaultScope, markAsGlobal, dynamicExports, onReady, onDispose, ..._internalParams }: ProviderModuleOptions);
|
|
417
|
+
get<T>(provider: ProviderToken<T>, isOptional?: boolean): T;
|
|
418
|
+
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
|
|
419
|
+
onActivationEvent<T>(provider: ProviderToken<T>, cb: BindingActivation<T>): void;
|
|
420
|
+
onDeactivationEvent<T>(provider: ProviderToken<T>, cb: BindingDeactivation<T>): void;
|
|
421
|
+
toNaked(): IProviderModuleNaked;
|
|
422
|
+
clone(options?: CloneParams): IProviderModule;
|
|
423
|
+
toString(): string;
|
|
424
|
+
private setIdentifier;
|
|
425
|
+
private prepareContainer;
|
|
426
|
+
private injectImportedModules;
|
|
427
|
+
private injectProviders;
|
|
428
|
+
private registerBindingSideEffect;
|
|
429
|
+
private invokeRegisteredBindingSideEffects;
|
|
430
|
+
private removeRegisteredBindingSideEffects;
|
|
431
|
+
private shouldThrowWhenModuleDynamicExportsDontMatchTheStaticExports;
|
|
432
|
+
private shouldThrowIfDisposed;
|
|
340
433
|
/**
|
|
341
|
-
*
|
|
342
|
-
* are provided by this module and should be available in other modules which import this module.
|
|
434
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
343
435
|
*
|
|
344
|
-
*
|
|
436
|
+
* See {@link IProviderModuleNaked._dispose}.
|
|
345
437
|
*/
|
|
346
|
-
|
|
438
|
+
protected _dispose(): Promise<void>;
|
|
347
439
|
/**
|
|
348
|
-
*
|
|
349
|
-
* array should actually be exported into the importing module.
|
|
350
|
-
*
|
|
351
|
-
* **Note:** _Static {@link ProviderModuleOptions.exports | exports} should always be preferred as their static nature implies predictibility._
|
|
352
|
-
* _This is for advanced use cases only, and most probably you may never need to use a dynamic export!_
|
|
353
|
-
*
|
|
354
|
-
* To keep in mind in order to avoid nasty bugs:
|
|
355
|
-
* - You **must always** return only the providers/modules declared into the static {@link ProviderModuleOptions.exports | exports} array.
|
|
356
|
-
* - You **can** return _less_ providers/modules as long as they are still part of the static {@link ProviderModuleOptions.exports | exports} array.
|
|
357
|
-
* - You **cannot** return _more_ providers/modules than the static {@link ProviderModuleOptions.exports | exports} array!
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* ```ts
|
|
361
|
-
* {
|
|
362
|
-
* exports: [ConfigModule, UserModule, PaymentService, ReviewService],
|
|
363
|
-
* dynamicExports: (importerModule, moduleExports) => {
|
|
364
|
-
* const shouldExportOnlyTheServices = true;
|
|
365
|
-
*
|
|
366
|
-
* if (shouldExportOnlyTheServices === false) return moduleExports;
|
|
367
|
-
*
|
|
368
|
-
* return moduleExports.flatMap((ex) => {
|
|
369
|
-
* // With `flatMap` we can map and filter out elements
|
|
370
|
-
* // from the sequence at the same time
|
|
371
|
-
* // by returning an empty array.
|
|
372
|
-
* return ex instanceof ProviderModule ? [] : ex;
|
|
373
|
-
* });
|
|
374
|
-
* }
|
|
375
|
-
* }
|
|
376
|
-
*
|
|
377
|
-
* // Or
|
|
378
|
-
*
|
|
379
|
-
* {
|
|
380
|
-
* exports: [ConfigModule, UserModule, PaymentService, ReviewService],
|
|
381
|
-
* dynamicExports: (importerModule, moduleExports) => {
|
|
382
|
-
* // We export all the providers only when the importer module is not the `BULLIED_MODULE`.
|
|
383
|
-
* if (importerModule.toNaked().name !== 'BULLIED_MODULE') return moduleExports;
|
|
384
|
-
*
|
|
385
|
-
* return [ConfigModule];
|
|
386
|
-
* }
|
|
387
|
-
* }
|
|
440
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
388
441
|
*
|
|
389
|
-
*
|
|
442
|
+
* See {@link IProviderModuleNaked._lazyInit}.
|
|
390
443
|
*/
|
|
391
|
-
dynamicExports
|
|
444
|
+
protected _lazyInit({ markAsGlobal, imports, providers, exports, defaultScope, dynamicExports, onReady, onDispose, ..._internalParams }: LazyInitOptions): IProviderModule;
|
|
392
445
|
/**
|
|
393
|
-
*
|
|
446
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
394
447
|
*
|
|
395
|
-
*
|
|
448
|
+
* See {@link IProviderModuleNaked._getImportedModules}.
|
|
396
449
|
*/
|
|
397
|
-
|
|
450
|
+
protected _getImportedModules(): IProviderModuleNaked[];
|
|
398
451
|
/**
|
|
399
|
-
*
|
|
400
|
-
* and the providers resolved.
|
|
401
|
-
*
|
|
402
|
-
* **This happens only once, when the {@link IProviderModule | ProviderModule} has been bootstrapped!**
|
|
452
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
403
453
|
*
|
|
404
|
-
*
|
|
454
|
+
* See {@link IProviderModuleNaked._getProviders}.
|
|
405
455
|
*/
|
|
406
|
-
|
|
456
|
+
protected _getProviders(): DependencyProvider[];
|
|
407
457
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* **The method will be invoked right _before_ the clean-up process.**
|
|
458
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
411
459
|
*
|
|
412
|
-
*
|
|
460
|
+
* See {@link IProviderModuleNaked._getExportableModulesAndProviders}.
|
|
413
461
|
*/
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
interface ProviderModuleOptionsInternal {
|
|
417
|
-
isAppModule?: boolean;
|
|
418
|
-
isDisposed?: boolean;
|
|
419
|
-
/** Can be used to manually provide a {@link Container} instance. */
|
|
420
|
-
container?: () => Container;
|
|
421
|
-
/** Can be used to override all the _imported_ providers _before_ the binding process. */
|
|
422
|
-
importedProvidersMap?: (
|
|
423
|
-
/** The current imported {@link DependencyProvider | provider} altered to use the module from where was imported for resolution. */
|
|
424
|
-
factorizedProvider: DependencyProvider<any>,
|
|
425
|
-
/** The current imported {@link DependencyProvider | provider}. */
|
|
426
|
-
provider: DependencyProvider<any>,
|
|
427
|
-
/** The {@link IProviderModule | module} from where the {@link DependencyProvider | provider} originated. */
|
|
428
|
-
module: IProviderModule) => DependencyProvider<any>;
|
|
429
|
-
}
|
|
430
|
-
type StaticExports = (ProviderToken | IProviderModule)[];
|
|
431
|
-
type DynamicExports = (
|
|
432
|
-
/** The {@link IProviderModule} which is importing this module. */
|
|
433
|
-
importerModule: IProviderModule,
|
|
434
|
-
/** The {@link ProviderModuleOptions.exports | exports} array of this module. */
|
|
435
|
-
moduleExports: StaticExports) => StaticExports;
|
|
436
|
-
|
|
437
|
-
interface IProviderModule {
|
|
438
|
-
/** The module unique ID. */
|
|
439
|
-
readonly identifier: symbol;
|
|
440
|
-
readonly isDisposed: boolean;
|
|
462
|
+
protected _getExportableModulesAndProviders(): StaticExports;
|
|
441
463
|
/**
|
|
442
|
-
*
|
|
464
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
443
465
|
*
|
|
444
|
-
*
|
|
445
|
-
* @param isOptional When set to `false` _(default)_ an exception will be thrown when the {@link provider} isn't bound.
|
|
446
|
-
* @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.
|
|
466
|
+
* See {@link IProviderModuleNaked._onBind}.
|
|
447
467
|
*/
|
|
448
|
-
|
|
468
|
+
protected _onBind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
|
|
449
469
|
/**
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* @param deps Either one or more {@link ProviderToken}.
|
|
453
|
-
* @returns Tuple containing the {@link D | dependencies}.
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```ts
|
|
457
|
-
* // When ProviderTokens are supplied, TS auto-inference works as expected.
|
|
458
|
-
* // `car` will infer the `Car` type, `engine` the `Engine` type and `dashboard` the `Dashboard` type.
|
|
459
|
-
* const [car, engine, dashboard] = AppModule.getMany(
|
|
460
|
-
* Car,
|
|
461
|
-
* Engine,
|
|
462
|
-
* { provider: Dashboard, isOptional: true }
|
|
463
|
-
* );
|
|
470
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
464
471
|
*
|
|
465
|
-
*
|
|
466
|
-
* const [configService, userService] = AppModule.getMany<[typeof ConfigService, typeof UserService]>('CONFIG_SERVICE', UserService);
|
|
467
|
-
* // Now the `configService` is of type `ConfigService` and the `userService` is of type `UserService`.
|
|
468
|
-
* ```
|
|
472
|
+
* See {@link IProviderModuleNaked._onRebind}.
|
|
469
473
|
*/
|
|
470
|
-
|
|
474
|
+
protected _onRebind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
|
|
471
475
|
/**
|
|
472
|
-
*
|
|
476
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
473
477
|
*
|
|
474
|
-
* See {@link
|
|
478
|
+
* See {@link IProviderModuleNaked._onUnbind}.
|
|
475
479
|
*/
|
|
476
|
-
|
|
480
|
+
protected _onUnbind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
|
|
477
481
|
/**
|
|
478
|
-
*
|
|
482
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
479
483
|
*
|
|
480
|
-
* See {@link
|
|
484
|
+
* See {@link IProviderModuleNaked._overwriteContainer}.
|
|
481
485
|
*/
|
|
482
|
-
|
|
486
|
+
protected _overwriteContainer(cb: () => Container): void;
|
|
483
487
|
/**
|
|
484
|
-
*
|
|
488
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
485
489
|
*
|
|
486
|
-
*
|
|
490
|
+
* See {@link IProviderModuleNaked.__bind}.
|
|
487
491
|
*/
|
|
488
|
-
|
|
492
|
+
protected __bind<T>(provider: ProviderToken<T>): BindToFluentSyntax<T>;
|
|
489
493
|
/**
|
|
490
|
-
*
|
|
494
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
491
495
|
*
|
|
492
|
-
*
|
|
493
|
-
* _And also the new module will still refrain values by reference to its parent module because of_
|
|
494
|
-
* _JS limitation in deeply/truly cloning an instance._
|
|
495
|
-
*
|
|
496
|
-
* @param options See {@link CloneParams}.
|
|
496
|
+
* See {@link IProviderModuleNaked.__get}.
|
|
497
497
|
*/
|
|
498
|
-
|
|
499
|
-
/** Returns the {@link IProviderModule.identifier} `symbol` description. */
|
|
500
|
-
toString(): string;
|
|
501
|
-
}
|
|
502
|
-
type ProviderModuleGetManySignature<Tokens extends (ProviderModuleGetManyParam<any> | ProviderToken)[]> = {
|
|
503
|
-
[K in keyof Tokens]: Tokens[K] extends ProviderModuleGetManyParam<infer U> ? U : Tokens[K] extends ProviderToken<infer T> ? T : Tokens[K] extends ProviderIdentifier<infer I> ? I : never;
|
|
504
|
-
};
|
|
505
|
-
type ProviderModuleGetManyParam<T> = {
|
|
506
|
-
/** The {@link ProviderToken}. */
|
|
507
|
-
provider: ProviderToken<T>;
|
|
508
|
-
/** When set to `false` _(default)_ an exception will be thrown when the {@link ProviderModuleGetManyParam.provider | provider} isn't bound. */
|
|
509
|
-
isOptional?: boolean;
|
|
510
|
-
};
|
|
511
|
-
interface CloneParams {
|
|
512
|
-
/** Can be used to override all the providers _before_ the binding process. */
|
|
513
|
-
providersMap?: (
|
|
514
|
-
/** The current {@link DependencyProvider | provider}. */
|
|
515
|
-
provider: DependencyProvider<any>,
|
|
516
|
-
/** The {@link IProviderModule | module} from where the {@link DependencyProvider | provider} originated. */
|
|
517
|
-
module: IProviderModule) => DependencyProvider<any>;
|
|
518
|
-
/** Can be used to override all the _imported_ providers _before_ the binding process. */
|
|
519
|
-
importedProvidersMap?: ProviderModuleOptionsInternal['importedProvidersMap'];
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
interface IAppModule extends IProviderModule {
|
|
523
|
-
/** Must be invoked _(only once during the application lifecycle)_ in order to provide the {@link options} to the module. */
|
|
524
|
-
register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
|
|
525
|
-
toNaked(): IAppModule & IProviderModuleNaked;
|
|
526
|
-
}
|
|
527
|
-
type AppModuleOptions = Except<LazyInitOptions, 'exports' | 'dynamicExports'>;
|
|
528
|
-
|
|
529
|
-
/** See {@link https://inversify.io/docs/api/decorator/#inject} for more details. */
|
|
530
|
-
declare function Inject(provider: ProviderToken): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
531
|
-
|
|
532
|
-
/** See {@link https://inversify.io/docs/api/decorator/#multiinject} for more details. */
|
|
533
|
-
declare function MultiInject(provider: ProviderToken): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
534
|
-
|
|
535
|
-
/** See {@link https://inversify.io/docs/api/decorator/#injectfrombase} for more details. */
|
|
536
|
-
declare function InjectFromBase(options?: Parameters<typeof injectFromBase>[0]): ClassDecorator;
|
|
537
|
-
|
|
538
|
-
/** See {@link https://inversify.io/docs/api/decorator/#named} for more details. */
|
|
539
|
-
declare function Named(name: MetadataName): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
540
|
-
|
|
541
|
-
/** See {@link https://inversify.io/docs/api/decorator/#optional} for more details. */
|
|
542
|
-
declare function Optional(): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
543
|
-
|
|
544
|
-
/** See {@link https://inversify.io/docs/api/decorator/#postconstruct} for more details. */
|
|
545
|
-
declare function PostConstruct(): MethodDecorator;
|
|
546
|
-
|
|
547
|
-
/** See {@link https://inversify.io/docs/api/decorator/#predestroy} for more details. */
|
|
548
|
-
declare function PreDestroy(): MethodDecorator;
|
|
549
|
-
|
|
550
|
-
/** See {@link https://inversify.io/docs/api/decorator/#tagged} for more details. */
|
|
551
|
-
declare function Tagged(key: MetadataTag, value: unknown): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
552
|
-
|
|
553
|
-
/** See {@link https://inversify.io/docs/api/decorator/#unmanaged} for more details. */
|
|
554
|
-
declare function Unmanaged(): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
555
|
-
|
|
556
|
-
/** Exception which indicates that there is a generic error. */
|
|
557
|
-
declare class InjectionError extends Error {
|
|
558
|
-
name: string;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/** Exception which indicates that there is a generic error with an instance of {@link IProviderModule}. */
|
|
562
|
-
declare class InjectionProviderModuleError extends Error {
|
|
563
|
-
name: string;
|
|
564
|
-
constructor(module: IProviderModule, message: string);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/** Exception which indicates an invokation of a disposed module. */
|
|
568
|
-
declare class InjectionProviderModuleDisposedError extends InjectionProviderModuleError {
|
|
569
|
-
name: string;
|
|
570
|
-
constructor(module: IProviderModule);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* Exception which indicates that an instance of {@link IProviderModule}
|
|
575
|
-
* imports another module which dynamically exports its providers/modules and
|
|
576
|
-
* is trying to dynamically export more or different providers/modules than the
|
|
577
|
-
* ones declared into its static exports.
|
|
578
|
-
*/
|
|
579
|
-
declare class InjectionDynamicExportsOutOfRange extends InjectionProviderModuleError {
|
|
580
|
-
name: string;
|
|
581
|
-
constructor(module: IProviderModule);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/** Exception which indicates that a module has been initialized without an `identifier`. */
|
|
585
|
-
declare class InjectionProviderModuleMissingIdentifierError extends InjectionProviderModuleError {
|
|
586
|
-
name: string;
|
|
587
|
-
constructor(module: IProviderModule);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
declare function injectionScopeToBindingScope(injectionScope: InjectionScope): BindingScope;
|
|
591
|
-
declare function bindingScopeToInjectionScope(bindingScope: BindingScope): InjectionScope;
|
|
592
|
-
|
|
593
|
-
declare namespace ProviderTokenHelpers {
|
|
594
|
-
function isClassToken<T>(provider: ProviderToken<T>): provider is ProviderClassToken<T>;
|
|
595
|
-
function isValueToken<T>(provider: ProviderToken<T>): provider is ProviderValueToken<T>;
|
|
596
|
-
function isFactoryToken<T>(provider: ProviderToken<T>): provider is ProviderFactoryToken<T>;
|
|
597
|
-
function isProviderIdentifier<T = any>(value: any): value is ProviderIdentifier<T>;
|
|
598
|
-
function toServiceIdentifier<T = any>(provider: ProviderToken<T>): ServiceIdentifier<T>;
|
|
599
|
-
function toServiceIdentifiers(providers: ProviderToken[]): ServiceIdentifier<unknown>[];
|
|
600
|
-
function toDependencyProviderWithOptions<T extends DependencyProvider<any>>(original: T, override?: Partial<T>): T;
|
|
498
|
+
protected __get<T>(provider: ProviderToken<T>, options?: GetOptions): T;
|
|
601
499
|
/**
|
|
602
|
-
*
|
|
603
|
-
* 1. From the `ProviderToken.scope`
|
|
604
|
-
* 2. From the class `@Injectable(scope)` decorator
|
|
605
|
-
* 3. From the `ProviderModule` default scope.
|
|
500
|
+
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
606
501
|
*
|
|
607
|
-
*
|
|
608
|
-
* @param moduleDefaultScope The module default scope.
|
|
502
|
+
* See {@link IProviderModuleNaked.__getAsync}.
|
|
609
503
|
*/
|
|
610
|
-
|
|
611
|
-
function tryGetProviderOptions<T>(provider: ProviderToken<T>): (ProviderOptions<T> & ProviderScopeOption) | undefined;
|
|
612
|
-
function tryGetScopeFromProvider(provider: ProviderToken): InjectionScope | undefined;
|
|
613
|
-
function tryGetDecoratorScopeFromClass<T = any>(provider: ProviderToken<T>): InjectionScope | undefined;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
declare namespace ProviderModuleHelpers {
|
|
617
|
-
function buildInternalConstructorParams(params: ProviderModuleOptions & ProviderModuleOptionsInternal): ProviderModuleOptions;
|
|
618
|
-
function isDynamicExport(exporter: StaticExports | DynamicExports): exporter is DynamicExports;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
declare function isPlainObject(o: any): o is object;
|
|
622
|
-
|
|
623
|
-
declare function isClass(v: any): boolean;
|
|
624
|
-
|
|
625
|
-
declare function isFunction(v: any): boolean;
|
|
626
|
-
|
|
627
|
-
declare function isClassOrFunction(value: any): value is Function | Class<any>;
|
|
628
|
-
|
|
629
|
-
/**
|
|
630
|
-
* The low-level App Container.
|
|
631
|
-
*
|
|
632
|
-
* **Internally used, please use the `AppModule` to interact with it.**
|
|
633
|
-
*/
|
|
634
|
-
declare const GlobalContainer: Container;
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* Modules are highly recommended as an effective way to organize your components.
|
|
638
|
-
* For most applications, you'll likely have multiple modules, each encapsulating a closely related set of capabilities.
|
|
639
|
-
*
|
|
640
|
-
* _See {@link ProviderModuleOptions | ProviderModuleOptions}_.
|
|
641
|
-
*
|
|
642
|
-
* @example
|
|
643
|
-
* ```ts
|
|
644
|
-
* const EngineModule = new ProviderModule({
|
|
645
|
-
* identifier: Symbol('EngineModule'),
|
|
646
|
-
* providers: [EngineService],
|
|
647
|
-
* exports: [EngineService]
|
|
648
|
-
* });
|
|
649
|
-
*
|
|
650
|
-
* const DashboardModule = new ProviderModule({
|
|
651
|
-
* identifier: Symbol('DashboardModule'),
|
|
652
|
-
* providers: [DashboardService],
|
|
653
|
-
* exports: [DashboardService]
|
|
654
|
-
* });
|
|
655
|
-
*
|
|
656
|
-
* const CarModule = new ProviderModule({
|
|
657
|
-
* identifier: Symbol('CarModule'),
|
|
658
|
-
* imports: [EngineModule, DashboardModule],
|
|
659
|
-
* providers: [CarService],
|
|
660
|
-
* exports: [CarService]
|
|
661
|
-
* });
|
|
662
|
-
*
|
|
663
|
-
* // Run-time class replacement:
|
|
664
|
-
* const RedCarModule = new ProviderModule({
|
|
665
|
-
* identifier: Symbol('RedCarModule'),
|
|
666
|
-
* imports: [CarModule],
|
|
667
|
-
* providers: [
|
|
668
|
-
* {
|
|
669
|
-
* provide: CarService,
|
|
670
|
-
* useClass: RedCarService,
|
|
671
|
-
* }
|
|
672
|
-
* ],
|
|
673
|
-
* });
|
|
674
|
-
*
|
|
675
|
-
* // Run-time factory example:
|
|
676
|
-
* const BlackCarModule = new ProviderModule({
|
|
677
|
-
* identifier: Symbol('BlackCarModule'),
|
|
678
|
-
* imports: [CarModule],
|
|
679
|
-
* providers: [
|
|
680
|
-
* {
|
|
681
|
-
* provide: CarService,
|
|
682
|
-
* useFactory: (carService: CarService) => {
|
|
683
|
-
* carService.setColor('black');
|
|
684
|
-
*
|
|
685
|
-
* return carService;
|
|
686
|
-
* },
|
|
687
|
-
* inject: [CarService]
|
|
688
|
-
* }
|
|
689
|
-
* ],
|
|
690
|
-
* });
|
|
691
|
-
* ```
|
|
692
|
-
*/
|
|
693
|
-
declare class ProviderModule implements IProviderModule {
|
|
694
|
-
readonly identifier: symbol;
|
|
695
|
-
readonly isDisposed: boolean;
|
|
696
|
-
protected readonly isAppModule: boolean;
|
|
697
|
-
protected readonly container: Container;
|
|
698
|
-
protected readonly defaultScope: IProviderModuleNaked['defaultScope'];
|
|
699
|
-
protected readonly dynamicExports: IProviderModuleNaked['dynamicExports'];
|
|
700
|
-
protected readonly onReady: IProviderModuleNaked['onReady'];
|
|
701
|
-
protected readonly onDispose: IProviderModuleNaked['onDispose'];
|
|
702
|
-
protected readonly importedProvidersMap: IProviderModuleNaked['importedProvidersMap'];
|
|
703
|
-
protected readonly moduleUtils: IProviderModuleNaked['moduleUtils'];
|
|
704
|
-
protected readonly imports: IProviderModuleNaked['imports'];
|
|
705
|
-
protected readonly providers: IProviderModuleNaked['providers'];
|
|
706
|
-
protected readonly importedProviders: IProviderModuleNaked['importedProviders'];
|
|
707
|
-
protected readonly exports: IProviderModuleNaked['exports'];
|
|
708
|
-
private readonly registeredBindingSideEffects;
|
|
709
|
-
constructor({ identifier, imports, providers, exports, defaultScope, dynamicExports, onReady, onDispose, ..._internalParams }: ProviderModuleOptions);
|
|
710
|
-
get<T>(provider: ProviderToken<T>, isOptional?: boolean): T;
|
|
711
|
-
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
|
|
712
|
-
onActivationEvent<T>(provider: ProviderToken<T>, cb: BindingActivation<T>): void;
|
|
713
|
-
onDeactivationEvent<T>(provider: ProviderToken<T>, cb: BindingDeactivation<T>): void;
|
|
714
|
-
toNaked(): IProviderModuleNaked;
|
|
715
|
-
clone(options?: CloneParams): IProviderModule;
|
|
716
|
-
toString(): string;
|
|
717
|
-
private setIdentifier;
|
|
718
|
-
private prepareContainer;
|
|
719
|
-
private injectImportedModules;
|
|
720
|
-
private injectProviders;
|
|
721
|
-
private registerBindingSideEffect;
|
|
722
|
-
private invokeRegisteredBindingSideEffects;
|
|
723
|
-
private removeRegisteredBindingSideEffects;
|
|
724
|
-
private shouldThrowWhenModuleDynamicExportsDontMatchTheStaticExports;
|
|
725
|
-
private shouldThrowIfDisposed;
|
|
504
|
+
protected __getAsync<T>(provider: ProviderToken<T>, options?: GetOptions): Promise<T>;
|
|
726
505
|
/**
|
|
727
506
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
728
507
|
*
|
|
729
|
-
* See {@link IProviderModuleNaked.
|
|
508
|
+
* See {@link IProviderModuleNaked.__getAll}.
|
|
730
509
|
*/
|
|
731
|
-
protected
|
|
510
|
+
protected __getAll<T>(provider: ProviderToken<T>, options?: GetOptions): T[];
|
|
732
511
|
/**
|
|
733
512
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
734
513
|
*
|
|
735
|
-
* See {@link IProviderModuleNaked.
|
|
514
|
+
* See {@link IProviderModuleNaked.__getAllAsync}.
|
|
736
515
|
*/
|
|
737
|
-
protected
|
|
516
|
+
protected __getAllAsync<T>(provider: ProviderToken<T>, options?: GetOptions): Promise<T[]>;
|
|
738
517
|
/**
|
|
739
518
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
740
519
|
*
|
|
741
|
-
* See {@link IProviderModuleNaked.
|
|
520
|
+
* See {@link IProviderModuleNaked.__isBound}.
|
|
742
521
|
*/
|
|
743
|
-
protected
|
|
522
|
+
protected __isBound(provider: ProviderToken, options?: IsBoundOptions): boolean;
|
|
744
523
|
/**
|
|
745
524
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
746
525
|
*
|
|
747
|
-
* See {@link IProviderModuleNaked.
|
|
526
|
+
* See {@link IProviderModuleNaked.__isCurrentBound}.
|
|
748
527
|
*/
|
|
749
|
-
protected
|
|
528
|
+
protected __isCurrentBound(provider: ProviderToken, options?: IsBoundOptions): boolean;
|
|
750
529
|
/**
|
|
751
530
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
752
531
|
*
|
|
753
|
-
* See {@link IProviderModuleNaked.
|
|
532
|
+
* See {@link IProviderModuleNaked.__takeSnapshot}.
|
|
754
533
|
*/
|
|
755
|
-
protected
|
|
534
|
+
protected __takeSnapshot(): void;
|
|
756
535
|
/**
|
|
757
536
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
758
537
|
*
|
|
759
|
-
* See {@link IProviderModuleNaked.
|
|
538
|
+
* See {@link IProviderModuleNaked.__restoreSnapshot}.
|
|
760
539
|
*/
|
|
761
|
-
protected
|
|
540
|
+
protected __restoreSnapshot(): void;
|
|
762
541
|
/**
|
|
763
542
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
764
543
|
*
|
|
765
|
-
* See {@link IProviderModuleNaked.
|
|
544
|
+
* See {@link IProviderModuleNaked.__rebind}.
|
|
766
545
|
*/
|
|
767
|
-
protected
|
|
546
|
+
protected __rebind<T>(provider: ProviderToken<T>): Promise<BindToFluentSyntax<T>>;
|
|
768
547
|
/**
|
|
769
548
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
770
549
|
*
|
|
771
|
-
* See {@link IProviderModuleNaked.
|
|
550
|
+
* See {@link IProviderModuleNaked.__rebindSync}.
|
|
772
551
|
*/
|
|
773
|
-
protected
|
|
552
|
+
protected __rebindSync<T>(provider: ProviderToken<T>): BindToFluentSyntax<T>;
|
|
774
553
|
/**
|
|
775
554
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
776
555
|
*
|
|
777
|
-
* See {@link IProviderModuleNaked.
|
|
556
|
+
* See {@link IProviderModuleNaked.__unbind}.
|
|
778
557
|
*/
|
|
779
|
-
protected
|
|
558
|
+
protected __unbind(provider: ProviderToken): Promise<void>;
|
|
780
559
|
/**
|
|
781
560
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
782
561
|
*
|
|
783
|
-
* See {@link IProviderModuleNaked.
|
|
562
|
+
* See {@link IProviderModuleNaked.__unbindSync}.
|
|
784
563
|
*/
|
|
785
|
-
protected
|
|
564
|
+
protected __unbindSync(provider: ProviderToken): void;
|
|
786
565
|
/**
|
|
787
566
|
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
788
567
|
*
|
|
789
|
-
* See {@link IProviderModuleNaked.
|
|
568
|
+
* See {@link IProviderModuleNaked.__unbindAll}.
|
|
790
569
|
*/
|
|
791
|
-
protected
|
|
570
|
+
protected __unbindAll(): Promise<void>;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Class of the {@link AppModule} instance.
|
|
575
|
+
*
|
|
576
|
+
* **You shouldn't initialize a new instance of this class, please use the {@link AppModule} instance!**
|
|
577
|
+
*/
|
|
578
|
+
declare class GlobalAppModule extends ProviderModule implements IAppModule {
|
|
579
|
+
isMarkedAsGlobal: boolean;
|
|
580
|
+
private nakedModule;
|
|
581
|
+
private isLoaded;
|
|
582
|
+
constructor();
|
|
583
|
+
register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
|
|
584
|
+
toNaked(): IAppModule & IProviderModuleNaked;
|
|
585
|
+
protected _dispose(): Promise<void>;
|
|
586
|
+
private checkIfImportsHaveGlobalMark;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Special instance of {@link ProviderModule} which acts as the global module of your application in which you can inject any provider
|
|
590
|
+
* which must be available through your entire application.
|
|
591
|
+
*
|
|
592
|
+
* The registered providers will automatically be available inside all the modules.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```ts
|
|
596
|
+
* // The `register` method must be invoked only once during your application life cycle!
|
|
597
|
+
* AppModule.register({
|
|
598
|
+
* imports: [ConfigModule, ApiModule, UserModule, DatabaseModule],
|
|
599
|
+
* providers: [DummyService],
|
|
600
|
+
* });
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
declare const AppModule: GlobalAppModule;
|
|
604
|
+
|
|
605
|
+
interface ProviderModuleOptions {
|
|
606
|
+
/** The module unique ID. */
|
|
607
|
+
identifier: symbol;
|
|
608
|
+
/** The list of imported {@link IProviderModule | modules} that export the {@link Provider | providers} which are required in this module. */
|
|
609
|
+
imports?: IProviderModule[];
|
|
610
|
+
/** The {@link DependencyProvider | providers} that will be instantiated by the container and that may be shared at least across this module. */
|
|
611
|
+
providers?: DependencyProvider[];
|
|
792
612
|
/**
|
|
793
|
-
*
|
|
613
|
+
* The subset of {@link ProviderToken | providers} or {@link IProviderModule | modules} that
|
|
614
|
+
* are provided by this module and should be available in other modules which import this module.
|
|
794
615
|
*
|
|
795
|
-
*
|
|
616
|
+
* _Check also the {@link dynamicExports} property._
|
|
796
617
|
*/
|
|
797
|
-
|
|
618
|
+
exports?: StaticExports;
|
|
798
619
|
/**
|
|
799
|
-
*
|
|
620
|
+
* The default {@link InjectionScope} to be used when a {@link ProviderToken} does not have a defined `scope`.
|
|
800
621
|
*
|
|
801
|
-
*
|
|
622
|
+
* Defaults to {@link InjectionScope.Singleton}.
|
|
802
623
|
*/
|
|
803
|
-
|
|
624
|
+
defaultScope?: InjectionScope;
|
|
804
625
|
/**
|
|
805
|
-
*
|
|
626
|
+
* This option is only a _marker_, per se it doesn't do anything
|
|
627
|
+
* apart from marking this module as `global`.
|
|
628
|
+
* When a module is marked as `global`, it means that it is expected to be _imported_ into the `AppModule`.
|
|
806
629
|
*
|
|
807
|
-
*
|
|
630
|
+
* Expect an exception to be thrown:
|
|
631
|
+
* - If a `module` marked as global is **not** imported into the `AppModule`.
|
|
632
|
+
* - If a `module` **not** marked as global _is_ imported into the `AppModule`
|
|
633
|
+
*
|
|
634
|
+
* Defaults to `false`.
|
|
808
635
|
*/
|
|
809
|
-
|
|
636
|
+
markAsGlobal?: true;
|
|
810
637
|
/**
|
|
811
|
-
*
|
|
638
|
+
* When provided, can be used to control which providers from the {@link ProviderModuleOptions.exports | exports}
|
|
639
|
+
* array should actually be exported into the importing module.
|
|
640
|
+
*
|
|
641
|
+
* **Note:** _Static {@link ProviderModuleOptions.exports | exports} should always be preferred as their static nature implies predictibility._
|
|
642
|
+
* _This is for advanced use cases only, and most probably you may never need to use a dynamic export!_
|
|
643
|
+
*
|
|
644
|
+
* To keep in mind in order to avoid nasty bugs:
|
|
645
|
+
* - You **must always** return only the providers/modules declared into the static {@link ProviderModuleOptions.exports | exports} array.
|
|
646
|
+
* - You **can** return _less_ providers/modules as long as they are still part of the static {@link ProviderModuleOptions.exports | exports} array.
|
|
647
|
+
* - You **cannot** return _more_ providers/modules than the static {@link ProviderModuleOptions.exports | exports} array!
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* {
|
|
652
|
+
* exports: [ConfigModule, UserModule, PaymentService, ReviewService],
|
|
653
|
+
* dynamicExports: (importerModule, moduleExports) => {
|
|
654
|
+
* const shouldExportOnlyTheServices = true;
|
|
655
|
+
*
|
|
656
|
+
* if (shouldExportOnlyTheServices === false) return moduleExports;
|
|
657
|
+
*
|
|
658
|
+
* return moduleExports.flatMap((ex) => {
|
|
659
|
+
* // With `flatMap` we can map and filter out elements
|
|
660
|
+
* // from the sequence at the same time
|
|
661
|
+
* // by returning an empty array.
|
|
662
|
+
* return ex instanceof ProviderModule ? [] : ex;
|
|
663
|
+
* });
|
|
664
|
+
* }
|
|
665
|
+
* }
|
|
666
|
+
*
|
|
667
|
+
* // Or
|
|
668
|
+
*
|
|
669
|
+
* {
|
|
670
|
+
* exports: [ConfigModule, UserModule, PaymentService, ReviewService],
|
|
671
|
+
* dynamicExports: (importerModule, moduleExports) => {
|
|
672
|
+
* // We export all the providers only when the importer module is not the `BULLIED_MODULE`.
|
|
673
|
+
* if (importerModule.toNaked().name !== 'BULLIED_MODULE') return moduleExports;
|
|
674
|
+
*
|
|
675
|
+
* return [ConfigModule];
|
|
676
|
+
* }
|
|
677
|
+
* }
|
|
812
678
|
*
|
|
813
|
-
*
|
|
679
|
+
* ```
|
|
814
680
|
*/
|
|
815
|
-
|
|
681
|
+
dynamicExports?: DynamicExports;
|
|
816
682
|
/**
|
|
817
|
-
*
|
|
683
|
+
* Callback which will be invoked once the module container has been initialized
|
|
684
|
+
* and the providers resolved.
|
|
818
685
|
*
|
|
819
|
-
*
|
|
686
|
+
* **This happens only once, when the {@link IProviderModule | ProviderModule} has been bootstrapped!**
|
|
687
|
+
*
|
|
688
|
+
* @param module The instance of the {@link IProviderModule | module}.
|
|
820
689
|
*/
|
|
821
|
-
|
|
690
|
+
onReady?: (module: IProviderModule) => Promise<void>;
|
|
822
691
|
/**
|
|
823
|
-
*
|
|
692
|
+
* Callback which will be invoked whenever the internal module dispose method is invoked.
|
|
824
693
|
*
|
|
825
|
-
*
|
|
694
|
+
* **The method will be invoked right _before_ the clean-up process.**
|
|
695
|
+
*
|
|
696
|
+
* @param module The instance of the {@link IProviderModule | module}.
|
|
826
697
|
*/
|
|
827
|
-
|
|
698
|
+
onDispose?: (module: IProviderModule) => Promise<void>;
|
|
699
|
+
}
|
|
700
|
+
interface ProviderModuleOptionsInternal {
|
|
701
|
+
isAppModule?: boolean;
|
|
702
|
+
isDisposed?: boolean;
|
|
703
|
+
/** Can be used to manually provide the {@link IAppModule} instance. */
|
|
704
|
+
appModule?: () => GlobalAppModule;
|
|
705
|
+
/** Can be used to manually provide a {@link Container} instance. */
|
|
706
|
+
container?: () => Container;
|
|
707
|
+
/** Can be used to override all the _imported_ providers _before_ the binding process. */
|
|
708
|
+
importedProvidersMap?: (
|
|
709
|
+
/** The current imported {@link DependencyProvider | provider} altered to use the module from where was imported for resolution. */
|
|
710
|
+
factorizedProvider: DependencyProvider<any>,
|
|
711
|
+
/** The current imported {@link DependencyProvider | provider}. */
|
|
712
|
+
provider: DependencyProvider<any>,
|
|
713
|
+
/** The {@link IProviderModule | module} from where the {@link DependencyProvider | provider} originated. */
|
|
714
|
+
module: IProviderModule) => DependencyProvider<any>;
|
|
715
|
+
}
|
|
716
|
+
type StaticExports = (ProviderToken | IProviderModule)[];
|
|
717
|
+
type DynamicExports = (
|
|
718
|
+
/** The {@link IProviderModule} which is importing this module. */
|
|
719
|
+
importerModule: IProviderModule,
|
|
720
|
+
/** The {@link ProviderModuleOptions.exports | exports} array of this module. */
|
|
721
|
+
moduleExports: StaticExports) => StaticExports;
|
|
722
|
+
|
|
723
|
+
interface IProviderModule {
|
|
724
|
+
/** The module unique ID. */
|
|
725
|
+
readonly identifier: symbol;
|
|
726
|
+
/** See {@link ProviderModuleOptions.markAsGlobal}. */
|
|
727
|
+
readonly isMarkedAsGlobal: boolean;
|
|
728
|
+
readonly isDisposed: boolean;
|
|
828
729
|
/**
|
|
829
|
-
*
|
|
730
|
+
* Can be used to retrieve a resolved `dependency` from the module container.
|
|
830
731
|
*
|
|
831
|
-
*
|
|
732
|
+
* @param provider The {@link ProviderToken}.
|
|
733
|
+
* @param isOptional When set to `false` _(default)_ an exception will be thrown when the {@link provider} isn't bound.
|
|
734
|
+
* @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.
|
|
832
735
|
*/
|
|
833
|
-
|
|
736
|
+
get<T>(provider: ProviderToken<T>, isOptional?: boolean): T;
|
|
834
737
|
/**
|
|
835
|
-
*
|
|
738
|
+
* Can be used to retrieve many resolved `dependencies` from the module container at once.
|
|
836
739
|
*
|
|
837
|
-
*
|
|
740
|
+
* @param deps Either one or more {@link ProviderToken}.
|
|
741
|
+
* @returns Tuple containing the {@link D | dependencies}.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```ts
|
|
745
|
+
* // When ProviderTokens are supplied, TS auto-inference works as expected.
|
|
746
|
+
* // `car` will infer the `Car` type, `engine` the `Engine` type and `dashboard` the `Dashboard` type.
|
|
747
|
+
* const [car, engine, dashboard] = AppModule.getMany(
|
|
748
|
+
* Car,
|
|
749
|
+
* Engine,
|
|
750
|
+
* { provider: Dashboard, isOptional: true }
|
|
751
|
+
* );
|
|
752
|
+
*
|
|
753
|
+
* // When auto-inference is not possible, you can manually cast the types.
|
|
754
|
+
* const [configService, userService] = AppModule.getMany<[typeof ConfigService, typeof UserService]>('CONFIG_SERVICE', UserService);
|
|
755
|
+
* // Now the `configService` is of type `ConfigService` and the `userService` is of type `UserService`.
|
|
756
|
+
* ```
|
|
838
757
|
*/
|
|
839
|
-
|
|
758
|
+
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
|
|
840
759
|
/**
|
|
841
|
-
*
|
|
760
|
+
* Adds an activation handler for the {@link provider}.
|
|
842
761
|
*
|
|
843
|
-
* See {@link
|
|
762
|
+
* See {@link https://inversify.io/docs/api/container/#onactivation} for more details.
|
|
844
763
|
*/
|
|
845
|
-
|
|
764
|
+
onActivationEvent<T>(provider: ProviderToken<T>, cb: BindingActivation<T>): void;
|
|
846
765
|
/**
|
|
847
|
-
*
|
|
766
|
+
* Adds a deactivation handler for the {@link provider}.
|
|
848
767
|
*
|
|
849
|
-
* See {@link
|
|
768
|
+
* See {@link https://inversify.io/docs/api/container/#ondeactivation} for more details.
|
|
850
769
|
*/
|
|
851
|
-
|
|
770
|
+
onDeactivationEvent<T>(provider: ProviderToken<T>, cb: BindingDeactivation<T>): void;
|
|
852
771
|
/**
|
|
853
|
-
*
|
|
772
|
+
* Casts the current module type to the {@link IProviderModuleNaked} type.
|
|
854
773
|
*
|
|
855
|
-
*
|
|
774
|
+
* **Internally used and for testing purposes!**
|
|
856
775
|
*/
|
|
857
|
-
|
|
776
|
+
toNaked(): IProviderModuleNaked;
|
|
858
777
|
/**
|
|
859
|
-
*
|
|
778
|
+
* Can be used to create a new instance of the current {@link IProviderModule | module}.
|
|
860
779
|
*
|
|
861
|
-
*
|
|
780
|
+
* **Note:** _All the providers will be registered again within the new module!_
|
|
781
|
+
* _And also the new module will still refrain values by reference to its parent module because of_
|
|
782
|
+
* _JS limitation in deeply/truly cloning an instance._
|
|
783
|
+
*
|
|
784
|
+
* @param options See {@link CloneParams}.
|
|
862
785
|
*/
|
|
863
|
-
|
|
786
|
+
clone(options?: CloneParams): IProviderModule;
|
|
787
|
+
/** Returns the {@link IProviderModule.identifier} `symbol` description. */
|
|
788
|
+
toString(): string;
|
|
789
|
+
}
|
|
790
|
+
type ProviderModuleGetManySignature<Tokens extends (ProviderModuleGetManyParam<any> | ProviderToken)[]> = {
|
|
791
|
+
[K in keyof Tokens]: Tokens[K] extends ProviderModuleGetManyParam<infer U> ? U : Tokens[K] extends ProviderToken<infer T> ? T : Tokens[K] extends ProviderIdentifier<infer I> ? I : never;
|
|
792
|
+
};
|
|
793
|
+
type ProviderModuleGetManyParam<T> = {
|
|
794
|
+
/** The {@link ProviderToken}. */
|
|
795
|
+
provider: ProviderToken<T>;
|
|
796
|
+
/** When set to `false` _(default)_ an exception will be thrown when the {@link ProviderModuleGetManyParam.provider | provider} isn't bound. */
|
|
797
|
+
isOptional?: boolean;
|
|
798
|
+
};
|
|
799
|
+
interface CloneParams {
|
|
800
|
+
/** Can be used to override all the providers _before_ the binding process. */
|
|
801
|
+
providersMap?: (
|
|
802
|
+
/** The current {@link DependencyProvider | provider}. */
|
|
803
|
+
provider: DependencyProvider<any>,
|
|
804
|
+
/** The {@link IProviderModule | module} from where the {@link DependencyProvider | provider} originated. */
|
|
805
|
+
module: IProviderModule) => DependencyProvider<any>;
|
|
806
|
+
/** Can be used to override all the _imported_ providers _before_ the binding process. */
|
|
807
|
+
importedProvidersMap?: ProviderModuleOptionsInternal['importedProvidersMap'];
|
|
864
808
|
}
|
|
865
809
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
*
|
|
869
|
-
* **You shouldn't initialize a new instance of this class, please use the {@link AppModule} instance!**
|
|
870
|
-
*/
|
|
871
|
-
declare class GlobalAppModule extends ProviderModule implements IAppModule {
|
|
872
|
-
private nakedModule;
|
|
873
|
-
private isLoaded;
|
|
874
|
-
constructor();
|
|
810
|
+
interface IAppModule extends Except<IProviderModule, 'isMarkedAsGlobal'> {
|
|
811
|
+
/** Must be invoked _(only once during the application lifecycle)_ in order to provide the {@link options} to the module. */
|
|
875
812
|
register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
|
|
876
813
|
toNaked(): IAppModule & IProviderModuleNaked;
|
|
877
|
-
protected _dispose(): Promise<void>;
|
|
878
814
|
}
|
|
815
|
+
type AppModuleOptions = Except<LazyInitOptions, 'exports' | 'dynamicExports'>;
|
|
816
|
+
|
|
817
|
+
/** See {@link https://inversify.io/docs/api/decorator/#inject} for more details. */
|
|
818
|
+
declare function Inject(provider: ProviderToken): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
819
|
+
|
|
820
|
+
/** See {@link https://inversify.io/docs/api/decorator/#multiinject} for more details. */
|
|
821
|
+
declare function MultiInject(provider: ProviderToken): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
822
|
+
|
|
823
|
+
/** See {@link https://inversify.io/docs/api/decorator/#injectfrombase} for more details. */
|
|
824
|
+
declare function InjectFromBase(options?: Parameters<typeof injectFromBase>[0]): ClassDecorator;
|
|
825
|
+
|
|
826
|
+
/** See {@link https://inversify.io/docs/api/decorator/#named} for more details. */
|
|
827
|
+
declare function Named(name: MetadataName): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
828
|
+
|
|
829
|
+
/** See {@link https://inversify.io/docs/api/decorator/#optional} for more details. */
|
|
830
|
+
declare function Optional(): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
831
|
+
|
|
832
|
+
/** See {@link https://inversify.io/docs/api/decorator/#postconstruct} for more details. */
|
|
833
|
+
declare function PostConstruct(): MethodDecorator;
|
|
834
|
+
|
|
835
|
+
/** See {@link https://inversify.io/docs/api/decorator/#predestroy} for more details. */
|
|
836
|
+
declare function PreDestroy(): MethodDecorator;
|
|
837
|
+
|
|
838
|
+
/** See {@link https://inversify.io/docs/api/decorator/#tagged} for more details. */
|
|
839
|
+
declare function Tagged(key: MetadataTag, value: unknown): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
840
|
+
|
|
841
|
+
/** See {@link https://inversify.io/docs/api/decorator/#unmanaged} for more details. */
|
|
842
|
+
declare function Unmanaged(): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
843
|
+
|
|
844
|
+
/** Exception which indicates that there is a generic error. */
|
|
845
|
+
declare class InjectionError extends Error {
|
|
846
|
+
name: string;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** Exception which indicates that there is a generic error with an instance of {@link IProviderModule}. */
|
|
850
|
+
declare class InjectionProviderModuleError extends Error {
|
|
851
|
+
name: string;
|
|
852
|
+
constructor(module: IProviderModule, message: string);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** Exception which indicates an invokation of a disposed module. */
|
|
856
|
+
declare class InjectionProviderModuleDisposedError extends InjectionProviderModuleError {
|
|
857
|
+
name: string;
|
|
858
|
+
constructor(module: IProviderModule);
|
|
859
|
+
}
|
|
860
|
+
|
|
879
861
|
/**
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
* @example
|
|
886
|
-
* ```ts
|
|
887
|
-
* // The `register` method must be invoked only once during your application life cycle!
|
|
888
|
-
* AppModule.register({
|
|
889
|
-
* imports: [ConfigModule, ApiModule, UserModule, DatabaseModule],
|
|
890
|
-
* providers: [DummyService],
|
|
891
|
-
* });
|
|
892
|
-
* ```
|
|
862
|
+
* Exception which indicates that an instance of {@link IProviderModule}
|
|
863
|
+
* imports another module which dynamically exports its providers/modules and
|
|
864
|
+
* is trying to dynamically export more or different providers/modules than the
|
|
865
|
+
* ones declared into its static exports.
|
|
893
866
|
*/
|
|
894
|
-
declare
|
|
867
|
+
declare class InjectionDynamicExportsOutOfRange extends InjectionProviderModuleError {
|
|
868
|
+
name: string;
|
|
869
|
+
constructor(module: IProviderModule);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** Exception which indicates that a module has been initialized without an `identifier`. */
|
|
873
|
+
declare class InjectionProviderModuleMissingIdentifierError extends InjectionProviderModuleError {
|
|
874
|
+
name: string;
|
|
875
|
+
constructor(module: IProviderModule);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/** Exception which indicates an error with regards to the `markAsGlobal` option. */
|
|
879
|
+
declare class InjectionProviderModuleGlobalMarkError extends InjectionProviderModuleError {
|
|
880
|
+
name: string;
|
|
881
|
+
constructor(module: IProviderModule, message: string);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
declare function injectionScopeToBindingScope(injectionScope: InjectionScope): BindingScope;
|
|
885
|
+
declare function bindingScopeToInjectionScope(bindingScope: BindingScope): InjectionScope;
|
|
886
|
+
|
|
887
|
+
declare namespace ProviderTokenHelpers {
|
|
888
|
+
function isClassToken<T>(provider: ProviderToken<T>): provider is ProviderClassToken<T>;
|
|
889
|
+
function isValueToken<T>(provider: ProviderToken<T>): provider is ProviderValueToken<T>;
|
|
890
|
+
function isFactoryToken<T>(provider: ProviderToken<T>): provider is ProviderFactoryToken<T>;
|
|
891
|
+
function isProviderIdentifier<T = any>(value: any): value is ProviderIdentifier<T>;
|
|
892
|
+
function toServiceIdentifier<T = any>(provider: ProviderToken<T>): ServiceIdentifier<T>;
|
|
893
|
+
function toServiceIdentifiers(providers: ProviderToken[]): ServiceIdentifier<unknown>[];
|
|
894
|
+
function toDependencyProviderWithOptions<T extends DependencyProvider<any>>(original: T, override?: Partial<T>): T;
|
|
895
|
+
/**
|
|
896
|
+
* The priority order is as follows:
|
|
897
|
+
* 1. From the `ProviderToken.scope`
|
|
898
|
+
* 2. From the class `@Injectable(scope)` decorator
|
|
899
|
+
* 3. From the `ProviderModule` default scope.
|
|
900
|
+
*
|
|
901
|
+
* @param provider The {@link ProviderToken}.
|
|
902
|
+
* @param moduleDefaultScope The module default scope.
|
|
903
|
+
*/
|
|
904
|
+
function getInjectionScopeByPriority(provider: ProviderToken, moduleDefaultScope: InjectionScope): InjectionScope;
|
|
905
|
+
function tryGetProviderOptions<T>(provider: ProviderToken<T>): (ProviderOptions<T> & ProviderScopeOption) | undefined;
|
|
906
|
+
function tryGetScopeFromProvider(provider: ProviderToken): InjectionScope | undefined;
|
|
907
|
+
function tryGetDecoratorScopeFromClass<T = any>(provider: ProviderToken<T>): InjectionScope | undefined;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
declare namespace ProviderModuleHelpers {
|
|
911
|
+
function buildInternalConstructorParams(params: ProviderModuleOptions & ProviderModuleOptionsInternal): ProviderModuleOptions;
|
|
912
|
+
function isDynamicExport(exporter: StaticExports | DynamicExports): exporter is DynamicExports;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
declare function isPlainObject(o: any): o is object;
|
|
916
|
+
|
|
917
|
+
declare function isClass(v: any): boolean;
|
|
918
|
+
|
|
919
|
+
declare function isFunction(v: any): boolean;
|
|
920
|
+
|
|
921
|
+
declare function isClassOrFunction(value: any): value is Function | Class<any>;
|
|
895
922
|
|
|
896
|
-
export { AppModule, type AppModuleOptions, type CloneParams, type DependencyProvider, type DynamicExports, GLOBAL_APP_MODULE_ID, GlobalAppModule, GlobalContainer, type IAppModule, type IProviderModule, type IProviderModuleNaked, Inject, InjectFromBase, Injectable, InjectionDynamicExportsOutOfRange, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionScope, type LazyInitOptions, MultiInject, Named, type OnEvent, Optional, PostConstruct, PreDestroy, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, type ProviderModuleGetManyParam, type ProviderModuleGetManySignature, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, type StaticExports, Tagged, Unmanaged, bindingScopeToInjectionScope, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
|
|
923
|
+
export { AppModule, type AppModuleOptions, type CloneParams, type DependencyProvider, type DynamicExports, GLOBAL_APP_MODULE_ID, GlobalAppModule, GlobalContainer, type IAppModule, type IProviderModule, type IProviderModuleNaked, Inject, InjectFromBase, Injectable, InjectionDynamicExportsOutOfRange, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleGlobalMarkError, InjectionProviderModuleMissingIdentifierError, InjectionScope, type LazyInitOptions, MultiInject, Named, type OnEvent, Optional, PostConstruct, PreDestroy, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, type ProviderModuleGetManyParam, type ProviderModuleGetManySignature, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, type StaticExports, Tagged, Unmanaged, bindingScopeToInjectionScope, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
|