dependencyItem.d.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { DependencyIdentifier } from './dependencyIdentifier';
  2. import { Self, SkipSelf } from './dependencyLookUp';
  3. import { Many, Optional } from './dependencyQuantity';
  4. import { WithNew } from './dependencyWithNew';
  5. export interface Ctor<T> {
  6. new (...args: any[]): T;
  7. name: string;
  8. }
  9. export declare function isCtor<T>(thing: unknown): thing is Ctor<T>;
  10. export interface DependencyItemHooks<T> {
  11. onInstantiation?: (instance: T) => void;
  12. }
  13. export interface ClassDependencyItem<T> extends DependencyItemHooks<T> {
  14. useClass: Ctor<T>;
  15. lazy?: boolean;
  16. }
  17. export declare function isClassDependencyItem<T>(thing: unknown): thing is ClassDependencyItem<T>;
  18. export type FactoryDepModifier = typeof Self | typeof SkipSelf | typeof Optional | typeof Many | typeof WithNew;
  19. export type FactoryDep<T> = [...FactoryDepModifier[], DependencyIdentifier<T>] | DependencyIdentifier<T>;
  20. export interface FactoryDependencyItem<T> extends DependencyItemHooks<T> {
  21. useFactory: (...deps: any[]) => T;
  22. dynamic?: true;
  23. deps?: FactoryDep<any>[];
  24. }
  25. export declare function isFactoryDependencyItem<T>(thing: unknown): thing is FactoryDependencyItem<T>;
  26. export interface ValueDependencyItem<T> extends DependencyItemHooks<T> {
  27. useValue: T;
  28. }
  29. export declare function isValueDependencyItem<T>(thing: unknown): thing is ValueDependencyItem<T>;
  30. /**
  31. * Reuse an existing dependency. You can consider it as an alias to another dependency.
  32. */
  33. export interface ExistingDependencyItem<T> extends DependencyItemHooks<T> {
  34. /**
  35. * The identifier of the existing dependency.
  36. */
  37. useExisting: DependencyIdentifier<T>;
  38. }
  39. export declare function isExistingDependencyItem<T>(thing: unknown): thing is ExistingDependencyItem<T>;
  40. export interface AsyncDependencyItem<T> extends DependencyItemHooks<T> {
  41. useAsync: () => Promise<T | Ctor<T> | [DependencyIdentifier<T>, SyncDependencyItem<T>]>;
  42. }
  43. export declare function isAsyncDependencyItem<T>(thing: unknown): thing is AsyncDependencyItem<T>;
  44. export declare const AsyncHookSymbol: unique symbol;
  45. export interface AsyncHook<T> {
  46. __symbol: typeof AsyncHookSymbol;
  47. whenReady(): Promise<T>;
  48. }
  49. export declare function isAsyncHook<T>(thing: unknown): thing is AsyncHook<T>;
  50. export type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ExistingDependencyItem<T> | ValueDependencyItem<T>;
  51. export type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>;
  52. export declare function prettyPrintIdentifier<T>(id: DependencyIdentifier<T>): string;