@tstdl/base 0.85.26 → 0.86.0-beta10

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.
Files changed (225) hide show
  1. package/_container/decorators.d.ts +76 -0
  2. package/_container/decorators.js +110 -0
  3. package/_container/index.d.ts +10 -0
  4. package/_container/index.js +27 -0
  5. package/_container/interfaces.d.ts +16 -0
  6. package/_container/interfaces.js +26 -0
  7. package/_container/token.d.ts +18 -0
  8. package/_container/token.js +41 -0
  9. package/api/client/client.d.ts +2 -2
  10. package/api/client/client.js +5 -3
  11. package/api/server/api-controller.d.ts +2 -2
  12. package/api/server/api-controller.js +5 -4
  13. package/api/server/api-request-token.provider.js +2 -2
  14. package/api/server/gateway.d.ts +5 -6
  15. package/api/server/gateway.js +25 -12
  16. package/api/server/module.js +4 -4
  17. package/api/server/tokens.d.ts +4 -1
  18. package/api/server/tokens.js +8 -2
  19. package/application/application.d.ts +13 -10
  20. package/application/application.js +38 -45
  21. package/authentication/client/api.client.js +3 -3
  22. package/authentication/client/authentication.service.d.ts +4 -4
  23. package/authentication/client/authentication.service.js +20 -21
  24. package/authentication/client/http-client.middleware.d.ts +3 -5
  25. package/authentication/client/http-client.middleware.js +3 -12
  26. package/authentication/client/module.d.ts +2 -1
  27. package/authentication/client/module.js +15 -7
  28. package/authentication/client/tokens.d.ts +2 -2
  29. package/authentication/client/tokens.js +5 -4
  30. package/authentication/server/authentication-api-request-token.provider.js +2 -2
  31. package/authentication/server/authentication-secret-requirements.validator.js +2 -2
  32. package/authentication/server/authentication.service.d.ts +2 -2
  33. package/authentication/server/authentication.service.js +9 -9
  34. package/authentication/server/module.d.ts +2 -1
  35. package/authentication/server/module.js +8 -7
  36. package/authentication/server/mongo/mongo-authentication-credentials.repository.d.ts +3 -3
  37. package/authentication/server/mongo/mongo-authentication-credentials.repository.js +4 -4
  38. package/authentication/server/mongo/mongo-authentication-session.repository.d.ts +3 -3
  39. package/authentication/server/mongo/mongo-authentication-session.repository.js +4 -4
  40. package/browser/browser-context-controller.d.ts +4 -4
  41. package/browser/browser-context-controller.js +15 -9
  42. package/browser/browser-controller.d.ts +12 -5
  43. package/browser/browser-controller.js +24 -10
  44. package/browser/browser.service.d.ts +12 -6
  45. package/browser/browser.service.js +13 -10
  46. package/browser/module.js +2 -2
  47. package/container/decorators.d.ts +2 -76
  48. package/container/decorators.js +12 -88
  49. package/container/index.d.ts +0 -7
  50. package/container/index.js +0 -7
  51. package/container/interfaces.d.ts +2 -16
  52. package/container/interfaces.js +3 -4
  53. package/container/token.d.ts +2 -18
  54. package/container/token.js +4 -19
  55. package/core.d.ts +4 -2
  56. package/core.js +15 -8
  57. package/database/mongo/classes.d.ts +5 -5
  58. package/database/mongo/classes.js +5 -4
  59. package/database/mongo/module.js +24 -16
  60. package/database/mongo/mongo-entity-repository.d.ts +2 -2
  61. package/database/mongo/mongo-entity-repository.js +2 -2
  62. package/disposable/async-disposer.d.ts +4 -4
  63. package/distributed-loop/distributed-loop.d.ts +3 -3
  64. package/distributed-loop/distributed-loop.js +3 -3
  65. package/distributed-loop/provider.js +2 -2
  66. package/examples/api/authentication.js +17 -10
  67. package/examples/api/basic-overview.js +4 -5
  68. package/examples/api/custom-authentication.js +9 -6
  69. package/examples/api/streaming.js +5 -5
  70. package/examples/browser/basic.js +5 -5
  71. package/examples/http/client.js +6 -4
  72. package/examples/mail/basic.js +9 -4
  73. package/examples/pdf/basic.js +9 -5
  74. package/examples/template/basic.js +8 -6
  75. package/function/log.js +1 -1
  76. package/http/client/adapters/undici-http-client.adapter.js +7 -6
  77. package/http/client/http-client-options.d.ts +0 -5
  78. package/http/client/http-client-options.js +0 -4
  79. package/http/client/http-client.d.ts +5 -8
  80. package/http/client/http-client.js +10 -7
  81. package/http/client/middleware.d.ts +6 -0
  82. package/http/client/middleware.js +16 -0
  83. package/http/client/module.d.ts +6 -1
  84. package/http/client/module.js +10 -5
  85. package/http/client/tokens.d.ts +2 -0
  86. package/http/client/tokens.js +25 -0
  87. package/http/server/node/module.js +2 -2
  88. package/http/server/node/node-http-server.d.ts +1 -4
  89. package/http/server/node/node-http-server.js +3 -7
  90. package/image-service/imgproxy/imgproxy-image-service.d.ts +6 -8
  91. package/image-service/imgproxy/imgproxy-image-service.js +17 -16
  92. package/injector/decorators.d.ts +12 -6
  93. package/injector/decorators.js +14 -0
  94. package/injector/index.d.ts +11 -0
  95. package/injector/index.js +28 -0
  96. package/injector/inject.d.ts +6 -1
  97. package/injector/inject.js +14 -2
  98. package/injector/injector.d.ts +14 -34
  99. package/injector/injector.js +91 -48
  100. package/injector/interfaces.d.ts +7 -5
  101. package/injector/provider.d.ts +19 -14
  102. package/injector/token.d.ts +10 -3
  103. package/injector/token.js +1 -1
  104. package/injector/type-info.d.ts +2 -0
  105. package/injector/types.d.ts +13 -7
  106. package/key-value-store/key-value.store.d.ts +3 -3
  107. package/key-value-store/key-value.store.js +1 -1
  108. package/key-value-store/mongo/module.js +4 -4
  109. package/key-value-store/mongo/mongo-key-value-store.provider.js +2 -2
  110. package/key-value-store/mongo/mongo-key-value.repository.d.ts +3 -3
  111. package/key-value-store/mongo/mongo-key-value.repository.js +4 -4
  112. package/key-value-store/mongo/mongo-key-value.store.js +3 -3
  113. package/key-value-store/mongo/tokens.d.ts +1 -1
  114. package/key-value-store/mongo/tokens.js +1 -1
  115. package/lock/lock.d.ts +3 -2
  116. package/lock/lock.js +1 -0
  117. package/lock/mongo/lock.js +4 -4
  118. package/lock/mongo/module.js +3 -3
  119. package/lock/mongo/mongo-lock-repository.d.ts +3 -3
  120. package/lock/mongo/mongo-lock-repository.js +3 -3
  121. package/lock/mongo/provider.js +5 -5
  122. package/lock/provider.d.ts +3 -2
  123. package/lock/provider.js +1 -0
  124. package/lock/web/module.js +3 -3
  125. package/lock/web/web-lock.js +2 -2
  126. package/lock/web/web-lock.provider.js +3 -3
  127. package/logger/console/logger.js +2 -2
  128. package/logger/logger.d.ts +3 -2
  129. package/logger/logger.js +1 -0
  130. package/mail/clients/nodemailer.mail-client.js +6 -5
  131. package/mail/mail.client.d.ts +3 -2
  132. package/mail/mail.client.js +1 -0
  133. package/mail/mail.service.js +7 -7
  134. package/mail/module.js +5 -5
  135. package/mail/repositories/mongo-mail-log.repository.d.ts +3 -3
  136. package/mail/repositories/mongo-mail-log.repository.js +3 -3
  137. package/mail/tokens.d.ts +1 -1
  138. package/mail/tokens.js +2 -2
  139. package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js +3 -3
  140. package/message-bus/broadcast-channel/broadcast-channel-message-bus.d.ts +1 -1
  141. package/message-bus/broadcast-channel/broadcast-channel-message-bus.js +3 -3
  142. package/message-bus/broadcast-channel/module.js +3 -3
  143. package/message-bus/local/local-message-bus-provider.js +4 -4
  144. package/message-bus/local/local-message-bus.d.ts +1 -1
  145. package/message-bus/local/local-message-bus.js +3 -3
  146. package/message-bus/local/module.js +3 -3
  147. package/message-bus/message-bus.d.ts +3 -3
  148. package/message-bus/message-bus.js +1 -0
  149. package/migration/index.d.ts +1 -1
  150. package/migration/index.js +1 -1
  151. package/migration/migrator.js +4 -4
  152. package/migration/mongo/migration-state-repository.d.ts +3 -3
  153. package/migration/mongo/migration-state-repository.js +4 -4
  154. package/migration/mongo/module.js +2 -2
  155. package/module/modules/web-server.module.d.ts +5 -10
  156. package/module/modules/web-server.module.js +16 -36
  157. package/notification/notification.service.js +2 -2
  158. package/object-storage/object-storage.d.ts +3 -3
  159. package/object-storage/object-storage.js +1 -0
  160. package/object-storage/s3/s3.object-storage-provider.js +6 -5
  161. package/object-storage/s3/s3.object-storage.d.ts +2 -2
  162. package/object-storage/s3/s3.object-storage.js +4 -4
  163. package/openid-connect/cached-oidc-configuration.service.js +3 -3
  164. package/openid-connect/index.d.ts +1 -1
  165. package/openid-connect/index.js +3 -3
  166. package/openid-connect/mongo-oidc-state.repository.d.ts +3 -3
  167. package/openid-connect/mongo-oidc-state.repository.js +6 -5
  168. package/openid-connect/oidc-configuration.service.js +2 -2
  169. package/openid-connect/oidc.service.js +4 -4
  170. package/package.json +1 -1
  171. package/pdf/pdf.service.d.ts +3 -3
  172. package/pdf/pdf.service.js +5 -5
  173. package/process-shutdown.d.ts +2 -2
  174. package/process-shutdown.js +6 -8
  175. package/queue/mongo/mongo-job.repository.d.ts +3 -3
  176. package/queue/mongo/mongo-job.repository.js +4 -4
  177. package/queue/mongo/queue.js +4 -4
  178. package/queue/mongo/queue.provider.d.ts +3 -3
  179. package/queue/mongo/queue.provider.js +8 -6
  180. package/queue/queue.d.ts +3 -3
  181. package/queue/queue.js +1 -1
  182. package/search-index/elastic/config.d.ts +3 -3
  183. package/search-index/elastic/config.js +4 -3
  184. package/search-index/elastic/module.d.ts +1 -3
  185. package/search-index/elastic/module.js +21 -18
  186. package/search-index/elastic/search-index.d.ts +2 -2
  187. package/search-index/elastic/search-index.js +2 -2
  188. package/templates/module.d.ts +2 -2
  189. package/templates/module.js +12 -26
  190. package/templates/providers/file.template-provider.d.ts +3 -3
  191. package/templates/providers/file.template-provider.js +5 -4
  192. package/templates/providers/memory.template-provider.js +2 -2
  193. package/templates/renderers/handlebars.template-renderer.js +2 -2
  194. package/templates/renderers/jsx.template-renderer.js +2 -2
  195. package/templates/renderers/mjml.template-renderer.js +3 -3
  196. package/templates/renderers/string.template-renderer.js +2 -2
  197. package/templates/resolvers/file.template-resolver.d.ts +3 -3
  198. package/templates/resolvers/file.template-resolver.js +6 -5
  199. package/templates/resolvers/jsx.template-resolver.js +2 -2
  200. package/templates/resolvers/string.template-resolver.js +2 -2
  201. package/templates/template-renderer.provider.js +3 -3
  202. package/templates/template-resolver.provider.js +3 -3
  203. package/templates/template.service.js +4 -4
  204. package/templates/tokens.d.ts +2 -2
  205. package/templates/tokens.js +3 -3
  206. package/text/dynamic-text.model.js +3 -4
  207. package/text/localization.service.js +3 -3
  208. package/theme/theme-service.d.ts +1 -1
  209. package/theme/theme-service.js +7 -6
  210. package/tokens.d.ts +1 -1
  211. package/tokens.js +2 -2
  212. /package/{container → _container}/container.d.ts +0 -0
  213. /package/{container → _container}/container.js +0 -0
  214. /package/{container → _container}/provider.d.ts +0 -0
  215. /package/{container → _container}/provider.js +0 -0
  216. /package/{container → _container}/resolve-chain.d.ts +0 -0
  217. /package/{container → _container}/resolve-chain.js +0 -0
  218. /package/{container → _container}/resolve.error.d.ts +0 -0
  219. /package/{container → _container}/resolve.error.js +0 -0
  220. /package/{container → _container}/type-info.d.ts +0 -0
  221. /package/{container → _container}/type-info.js +0 -0
  222. /package/{container → _container}/types.d.ts +0 -0
  223. /package/{container → _container}/types.js +0 -0
  224. /package/{container → _container}/utils.d.ts +0 -0
  225. /package/{container → _container}/utils.js +0 -0
@@ -10,6 +10,7 @@ export type InjectArgumentOptions = {
10
10
  optional?: boolean;
11
11
  };
12
12
  export type InjectionContext = {
13
+ injector: Injector;
13
14
  argument: unknown;
14
15
  inject<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions): T;
15
16
  injectAll<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions): T[];
@@ -62,7 +63,10 @@ export declare function injectAllAsync<T, A>(token: InjectionToken<T, A>, argume
62
63
  export declare function injectArgument<T, R>(_this?: Resolvable<T>, options?: InjectArgumentOptions & {
63
64
  optional: R;
64
65
  }): T | (R extends true ? undefined : never);
65
- export declare function getCurrentInjectionContext(): InjectionContext | null;
66
+ export declare function getCurrentInjectionContext(required: true): InjectionContext;
67
+ export declare function getCurrentInjectionContext(required?: boolean): InjectionContext | null;
68
+ export declare function getCurrentInjector(required: true): Injector;
69
+ export declare function getCurrentInjector(required?: boolean): Injector | null;
66
70
  export declare function setCurrentInjectionContext(context: InjectionContext | null): InjectionContext | null;
67
71
  /**
68
72
  * Runs the given function in the context of the given {@link InjectionContext}.
@@ -72,6 +76,7 @@ export declare function setCurrentInjectionContext(context: InjectionContext | n
72
76
  * @returns the return value of the function, if any
73
77
  */
74
78
  export declare function runInInjectionContext<ReturnT>(injectorOrContext: Injector | InjectionContext, fn: () => ReturnT): ReturnT;
79
+ export declare function isInInjectionContext(): boolean;
75
80
  /**
76
81
  * Asserts that the current stack frame is within an injection context and has access to {@link inject}.
77
82
  *
@@ -20,11 +20,13 @@ var inject_exports = {};
20
20
  __export(inject_exports, {
21
21
  assertInInjectionContext: () => assertInInjectionContext,
22
22
  getCurrentInjectionContext: () => getCurrentInjectionContext,
23
+ getCurrentInjector: () => getCurrentInjector,
23
24
  inject: () => inject,
24
25
  injectAll: () => injectAll,
25
26
  injectAllAsync: () => injectAllAsync,
26
27
  injectArgument: () => injectArgument,
27
28
  injectAsync: () => injectAsync,
29
+ isInInjectionContext: () => isInInjectionContext,
28
30
  runInInjectionContext: () => runInInjectionContext,
29
31
  setCurrentInjectionContext: () => setCurrentInjectionContext
30
32
  });
@@ -56,9 +58,15 @@ function injectArgument(_this, options) {
56
58
  }
57
59
  return argument;
58
60
  }
59
- function getCurrentInjectionContext() {
61
+ function getCurrentInjectionContext(required = false) {
62
+ if (required) {
63
+ assertInInjectionContext(getCurrentInjector);
64
+ }
60
65
  return currentInjectionContext;
61
66
  }
67
+ function getCurrentInjector(required = false) {
68
+ return getCurrentInjectionContext(required)?.injector ?? null;
69
+ }
62
70
  function setCurrentInjectionContext(context) {
63
71
  const previous = currentInjectionContext;
64
72
  currentInjectionContext = context;
@@ -66,6 +74,7 @@ function setCurrentInjectionContext(context) {
66
74
  }
67
75
  function runInInjectionContext(injectorOrContext, fn) {
68
76
  const context = injectorOrContext instanceof import_injector.Injector ? {
77
+ injector: injectorOrContext,
69
78
  argument: void 0,
70
79
  inject(token, argument, options) {
71
80
  return injectorOrContext.resolve(token, argument, options);
@@ -87,8 +96,11 @@ function runInInjectionContext(injectorOrContext, fn) {
87
96
  setCurrentInjectionContext(previousContext);
88
97
  }
89
98
  }
99
+ function isInInjectionContext() {
100
+ return (0, import_type_guards.isNotNull)(currentInjectionContext);
101
+ }
90
102
  function assertInInjectionContext(debugFn) {
91
- if ((0, import_type_guards.isNull)(currentInjectionContext)) {
103
+ if (!isInInjectionContext()) {
92
104
  throw new Error(`${debugFn.name}() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with \`runInInjectionContext\``);
93
105
  }
94
106
  }
@@ -1,31 +1,10 @@
1
- import { CircularBuffer } from '../data-structures/circular-buffer.js';
2
- import { MultiKeyMap } from '../data-structures/multi-key-map.js';
3
- import { DeferredPromise } from '../promise/deferred-promise.js';
4
- import type { TypedOmit } from '../types.js';
5
- import { ForwardRef } from '../utils/object/forward-ref.js';
1
+ import type { AsyncDisposable } from '../disposable/disposable.js';
2
+ import { disposeAsync } from '../disposable/disposable.js';
3
+ import type { OneOrMany, Record, TypedOmit } from '../types.js';
6
4
  import type { ResolveArgument } from './interfaces.js';
7
5
  import { type Provider } from './provider.js';
8
- import { ResolveChain } from './resolve-chain.js';
9
6
  import { type InjectionToken } from './token.js';
10
7
  import type { RegistrationOptions, ResolveOptions } from './types.js';
11
- type InternalResolveContext = {
12
- resolves: number;
13
- /** Currently resolving tokens (for circular dependency detection) */
14
- resolving: Set<InjectionToken>;
15
- /** resolutions for resolution scoped dependencies */
16
- resolutionScopedResolutions: MultiKeyMap<[InjectionToken, unknown], Resolution<any, any>>;
17
- /** all resolutions in this chain for postprocessing */
18
- resolutions: Resolution<any, any>[];
19
- forwardRefQueue: CircularBuffer<(() => void | Promise<void>)>;
20
- forwardRefs: Set<ForwardRef>;
21
- $done: DeferredPromise;
22
- };
23
- type Resolution<T, A> = {
24
- registration: Registration<T>;
25
- value: T;
26
- argument: ResolveArgument<T, A>;
27
- chain: ResolveChain;
28
- };
29
8
  export type GlobalRegistration<T = any, A = any> = {
30
9
  token: InjectionToken<T, A>;
31
10
  provider: Provider<T, A>;
@@ -38,7 +17,7 @@ export type GetRegistrationOptions = {
38
17
  skipSelf?: boolean;
39
18
  onlySelf?: boolean;
40
19
  };
41
- export declare class Injector {
20
+ export declare class Injector implements AsyncDisposable {
42
21
  #private;
43
22
  readonly name: string;
44
23
  constructor(name: string, parent?: Injector | null);
@@ -48,14 +27,16 @@ export declare class Injector {
48
27
  * @param provider provider used to resolve the token
49
28
  * @param options registration options
50
29
  */
51
- static register<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
30
+ static register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>): void;
52
31
  /**
53
32
  * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
54
33
  * @param token token to register
55
34
  * @param provider provider used to resolve the token
56
35
  * @param options registration options
57
36
  */
58
- static registerSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
37
+ static registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): void;
38
+ dispose(): Promise<void>;
39
+ [disposeAsync](): Promise<void>;
59
40
  fork(name: string): Injector;
60
41
  /**
61
42
  * Register a provider for a token
@@ -63,14 +44,14 @@ export declare class Injector {
63
44
  * @param provider provider used to resolve the token
64
45
  * @param options registration options
65
46
  */
66
- register<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
47
+ register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>): void;
67
48
  /**
68
49
  * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
69
50
  * @param token token to register
70
51
  * @param provider provider used to resolve the token
71
52
  * @param options registration options
72
53
  */
73
- registerSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
54
+ registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): void;
74
55
  /**
75
56
  * Check if token has a registered provider
76
57
  * @param token token check
@@ -96,10 +77,10 @@ export declare class Injector {
96
77
  }): Promise<T | undefined>;
97
78
  resolveAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions): Promise<T>;
98
79
  resolveAllAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions): Promise<T[]>;
99
- _resolve<T, A>(token: InjectionToken<T, A>, argument: ResolveArgument<T, A>, options: ResolveOptions, context: InternalResolveContext, chain: ResolveChain): T | undefined;
100
- _resolveAll<T, A>(token: InjectionToken<T, A>, argument: ResolveArgument<T, A>, options: ResolveOptions, context: InternalResolveContext, chain: ResolveChain): T[];
101
- _resolveRegistration<T, A>(registration: Registration<T, A>, argument: ResolveArgument<T, A>, options: ResolveOptions, context: InternalResolveContext, chain: ResolveChain): T;
102
- _resolveProvider<T, A>(registration: Registration<T, A>, resolveArgument: ResolveArgument<T, A>, options: ResolveOptions, context: InternalResolveContext, chain: ResolveChain): T;
80
+ private _resolve;
81
+ private _resolveAll;
82
+ private _resolveRegistration;
83
+ private _resolveProvider;
103
84
  private resolveClassInjection;
104
85
  private resolveInjection;
105
86
  private resolveInjectionAsync;
@@ -108,4 +89,3 @@ export declare class Injector {
108
89
  private getResolveContext;
109
90
  private getInjectionContext;
110
91
  }
111
- export {};
@@ -23,9 +23,12 @@ __export(injector_exports, {
23
23
  module.exports = __toCommonJS(injector_exports);
24
24
  var import_circular_buffer = require("../data-structures/circular-buffer.js");
25
25
  var import_multi_key_map = require("../data-structures/multi-key-map.js");
26
+ var import_async_disposer = require("../disposable/async-disposer.js");
27
+ var import_disposable = require("../disposable/disposable.js");
26
28
  var import_deferred_promise = require("../promise/deferred-promise.js");
27
29
  var import_registry = require("../reflection/registry.js");
28
30
  var import_array = require("../utils/array/array.js");
31
+ var import_factory_map = require("../utils/factory-map.js");
29
32
  var import_forward_ref = require("../utils/object/forward-ref.js");
30
33
  var import_object = require("../utils/object/object.js");
31
34
  var import_type_guards = require("../utils/type-guards.js");
@@ -39,6 +42,8 @@ var import_token = require("./token.js");
39
42
  class Injector {
40
43
  static #globalRegistrations = /* @__PURE__ */ new Map();
41
44
  #parent;
45
+ #children = [];
46
+ #disposer = new import_async_disposer.AsyncDisposer();
42
47
  #registrations = /* @__PURE__ */ new Map();
43
48
  #injectorScopedResolutions = new import_multi_key_map.MultiKeyMap();
44
49
  name;
@@ -53,13 +58,15 @@ class Injector {
53
58
  * @param provider provider used to resolve the token
54
59
  * @param options registration options
55
60
  */
56
- static register(token, provider, options = {}) {
57
- const registration = {
58
- token,
59
- provider,
60
- options
61
- };
62
- addRegistration(Injector.#globalRegistrations, registration);
61
+ static register(token, providers, options = {}) {
62
+ for (const provider of (0, import_array.toArray)(providers)) {
63
+ const registration = {
64
+ token,
65
+ provider,
66
+ options: { multi: (0, import_type_guards.isArray)(providers), ...options }
67
+ };
68
+ addRegistration(Injector.#globalRegistrations, registration);
69
+ }
63
70
  }
64
71
  /**
65
72
  * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
@@ -67,11 +74,20 @@ class Injector {
67
74
  * @param provider provider used to resolve the token
68
75
  * @param options registration options
69
76
  */
70
- static registerSingleton(token, provider, options) {
71
- Injector.register(token, provider, { ...options, lifecycle: "singleton" });
77
+ static registerSingleton(token, providers, options) {
78
+ Injector.register(token, providers, { ...options, lifecycle: "singleton" });
79
+ }
80
+ async dispose() {
81
+ await this.#disposer.dispose();
82
+ }
83
+ async [import_disposable.disposeAsync]() {
84
+ await this.dispose();
72
85
  }
73
86
  fork(name) {
74
- return new Injector(name, this);
87
+ const child = new Injector(name, this);
88
+ this.#children.push(child);
89
+ this.#disposer.add(child);
90
+ return child;
75
91
  }
76
92
  /**
77
93
  * Register a provider for a token
@@ -79,14 +95,16 @@ class Injector {
79
95
  * @param provider provider used to resolve the token
80
96
  * @param options registration options
81
97
  */
82
- register(token, provider, options = {}) {
83
- const registration = {
84
- token,
85
- provider,
86
- options,
87
- resolutions: /* @__PURE__ */ new Map()
88
- };
89
- addRegistration(this.#registrations, registration);
98
+ register(token, providers, options = {}) {
99
+ for (const provider of (0, import_array.toArray)(providers)) {
100
+ const registration = {
101
+ token,
102
+ provider,
103
+ options: { multi: (0, import_type_guards.isArray)(providers), ...options },
104
+ resolutions: /* @__PURE__ */ new Map()
105
+ };
106
+ addRegistration(this.#registrations, registration);
107
+ }
90
108
  }
91
109
  /**
92
110
  * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
@@ -94,8 +112,8 @@ class Injector {
94
112
  * @param provider provider used to resolve the token
95
113
  * @param options registration options
96
114
  */
97
- registerSingleton(token, provider, options) {
98
- this.register(token, provider, { ...options, lifecycle: "singleton" });
115
+ registerSingleton(token, providers, options) {
116
+ this.register(token, providers, { ...options, lifecycle: "singleton" });
99
117
  }
100
118
  /**
101
119
  * Check if token has a registered provider
@@ -203,12 +221,13 @@ class Injector {
203
221
  checkOverflow(chain, context);
204
222
  const injectionContext = this.getInjectionContext(context, argument, chain);
205
223
  const previousInjectionContext = (0, import_inject.setCurrentInjectionContext)(injectionContext);
224
+ const resolutionTag = Symbol();
206
225
  try {
207
226
  const token = registration.token;
208
227
  const resolutionScoped = registration.options.lifecycle == "resolution";
209
228
  const injectorScoped = registration.options.lifecycle == "injector";
210
229
  const singletonScoped = registration.options.lifecycle == "singleton";
211
- const resolveArgument = argument ?? registration.options.defaultArgument ?? registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain));
230
+ const resolveArgument = argument ?? registration.options.defaultArgument ?? registration.options.defaultArgumentProvider?.(this.getResolveContext(resolutionTag, context, chain));
212
231
  const argumentIdentity = resolveArgumentIdentity(registration, resolveArgument);
213
232
  if (resolutionScoped && context.resolutionScopedResolutions.hasFlat(token, argumentIdentity)) {
214
233
  return context.resolutionScopedResolutions.getFlat(token, argumentIdentity).value;
@@ -217,8 +236,8 @@ class Injector {
217
236
  } else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
218
237
  return registration.resolutions.get(argumentIdentity);
219
238
  }
220
- const value = this._resolveProvider(registration, resolveArgument, options, context, chain);
221
- const resolution = { registration, value, argument, chain };
239
+ const value = this._resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain);
240
+ const resolution = { tag: resolutionTag, registration, value, argument: injectionContext.argument, chain };
222
241
  context.resolutions.push(resolution);
223
242
  if (resolutionScoped) {
224
243
  context.resolutionScopedResolutions.setFlat(token, argumentIdentity, resolution);
@@ -234,47 +253,61 @@ class Injector {
234
253
  (0, import_inject.setCurrentInjectionContext)(previousInjectionContext);
235
254
  }
236
255
  }
237
- _resolveProvider(registration, resolveArgument, options, context, chain) {
256
+ _resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain) {
238
257
  try {
239
258
  setResolving(registration.token, context, chain);
240
259
  const provider = registration.provider;
260
+ let result;
241
261
  if ((0, import_provider.isClassProvider)(provider)) {
242
262
  const typeMetadata = import_registry.reflectionRegistry.getMetadata(provider.useClass);
243
263
  const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
244
- if (provider.useClass.length > 0 && ((0, import_type_guards.isUndefined)(typeMetadata) || !typeMetadata.data.has(import_symbols.injectMetadataSymbol))) {
264
+ injectionContext.argument = arg;
265
+ if (provider.useClass.length > 0 && ((0, import_type_guards.isUndefined)(typeMetadata) || !typeMetadata.data.has(import_symbols.injectableMetadataSymbol))) {
245
266
  throw new import_resolve_error.ResolveError(`${provider.useClass.name} has constructor parameters but is not injectable.`, chain);
246
267
  }
247
- const parameters = (typeMetadata?.parameters ?? []).map((metadata) => this.resolveClassInjection(context, provider.useClass, metadata, arg, chain));
248
- return new provider.useClass(...parameters);
268
+ const parameters = (typeMetadata?.parameters ?? []).map((metadata) => this.resolveClassInjection(resolutionTag, context, provider.useClass, metadata, arg, chain));
269
+ result = { value: new provider.useClass(...parameters) };
249
270
  }
250
271
  if ((0, import_provider.isValueProvider)(provider)) {
251
- return provider.useValue;
272
+ result = { value: provider.useValue };
252
273
  }
253
274
  if ((0, import_provider.isTokenProvider)(provider)) {
254
275
  const innerToken = provider.useToken ?? provider.useTokenProvider();
255
276
  const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
256
- return this._resolve(innerToken, arg, options, context, chain.addToken(innerToken));
277
+ injectionContext.argument = arg;
278
+ if (provider.resolveAll == true) {
279
+ return this._resolveAll(innerToken, arg, options, context, chain.addToken(innerToken));
280
+ }
281
+ result = { value: this._resolve(innerToken, arg, options, context, chain.addToken(innerToken)) };
257
282
  }
258
283
  if ((0, import_provider.isFactoryProvider)(provider)) {
259
284
  try {
260
- return provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
285
+ const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
286
+ injectionContext.argument = arg;
287
+ result = { value: provider.useFactory(arg, this.getResolveContext(resolutionTag, context, chain)) };
261
288
  } catch (error) {
262
- throw new import_resolve_error.ResolveError("Error in factory.", chain, error);
289
+ throw new import_resolve_error.ResolveError("Error in provider factory.", chain, error);
263
290
  }
264
291
  }
265
- throw new Error("Unsupported provider.");
292
+ if ((0, import_type_guards.isUndefined)(result)) {
293
+ throw new Error("Unsupported provider.");
294
+ }
295
+ if ((0, import_disposable.isDisposable)(result.value) || (0, import_disposable.isAsyncDisposable)(result.value)) {
296
+ this.#disposer.add(result.value);
297
+ }
298
+ return result.value;
266
299
  } finally {
267
300
  deleteResolving(registration.token, context);
268
301
  }
269
302
  }
270
- resolveClassInjection(context, constructor, metadata, resolveArgument, chain) {
303
+ resolveClassInjection(resolutionTag, context, constructor, metadata, resolveArgument, chain) {
271
304
  const getChain = (injectToken2) => chain.addParameter(constructor, metadata.index, injectToken2).addToken(injectToken2);
272
305
  const injectMetadata = metadata.data.tryGet(import_symbols.injectMetadataSymbol) ?? {};
273
306
  const injectToken = injectMetadata.injectToken ?? metadata.type;
274
307
  if ((0, import_type_guards.isDefined)(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || (0, import_type_guards.isDefined)(resolveArgument) || (0, import_type_guards.isUndefined)(injectToken))) {
275
308
  return injectMetadata.injectArgumentMapper(resolveArgument);
276
309
  }
277
- const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken)));
310
+ const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(resolutionTag, context, getChain(injectToken)));
278
311
  if ((0, import_type_guards.isDefined)(injectMetadata.forwardRefToken)) {
279
312
  const forwardRef = import_forward_ref.ForwardRef.create();
280
313
  const forwardRefToken = injectMetadata.forwardRefToken;
@@ -283,7 +316,7 @@ class Injector {
283
316
  if ((0, import_type_guards.isDefined)(injectMetadata.mapper)) {
284
317
  throw new import_resolve_error.ResolveError("Cannot use inject mapper with forwardRef.", getChain(forwardToken));
285
318
  }
286
- const resolved2 = this._resolve(forwardToken, parameterResolveArgument, { optional: injectMetadata.optional }, context, getChain(forwardToken));
319
+ const resolved2 = this[injectMetadata.resolveAll == true ? "_resolveAll" : "_resolve"](forwardToken, parameterResolveArgument, { optional: injectMetadata.optional }, context, getChain(forwardToken));
287
320
  import_forward_ref.ForwardRef.setRef(forwardRef, resolved2);
288
321
  });
289
322
  context.forwardRefs.add(forwardRef);
@@ -326,15 +359,20 @@ class Injector {
326
359
  await context.$done;
327
360
  return values;
328
361
  }
329
- getResolveContext(resolveContext, chain) {
362
+ getResolveContext(resolutionTag, resolveContext, chain) {
330
363
  const context = {
331
364
  resolve: (token, argument, options) => this._resolve(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
332
- resolveAll: (token, argument, options) => this._resolveAll(token, argument, options ?? {}, resolveContext, chain.addToken(token))
365
+ resolveAll: (token, argument, options) => this._resolveAll(token, argument, options ?? {}, resolveContext, chain.addToken(token)),
366
+ addDisposeHandler: (handler) => this.#disposer.add(handler),
367
+ get context() {
368
+ return resolveContext.resolutionContexts.get(resolutionTag);
369
+ }
333
370
  };
334
371
  return context;
335
372
  }
336
373
  getInjectionContext(resolveContext, resolveArgument, chain) {
337
374
  const context = {
375
+ injector: this,
338
376
  argument: resolveArgument,
339
377
  inject: (token, argument, options) => this.resolveInjection(token, argument, options ?? {}, resolveContext, chain),
340
378
  injectAll: (token, argument, options) => this.resolveInjectionAll(token, argument, options ?? {}, resolveContext, chain),
@@ -370,6 +408,7 @@ function newInternalResolveContext() {
370
408
  resolving: /* @__PURE__ */ new Set(),
371
409
  resolutionScopedResolutions: new import_multi_key_map.MultiKeyMap(),
372
410
  resolutions: [],
411
+ resolutionContexts: new import_factory_map.FactoryMap(() => ({})),
373
412
  forwardRefQueue: new import_circular_buffer.CircularBuffer(),
374
413
  forwardRefs: /* @__PURE__ */ new Set(),
375
414
  $done: new import_deferred_promise.DeferredPromise()
@@ -380,18 +419,20 @@ function postProcess(context) {
380
419
  fn();
381
420
  }
382
421
  derefForwardRefs(context);
383
- for (let i = context.resolutions.length - 1; i >= 0; i--) {
384
- const resolution = context.resolutions[i];
422
+ for (const resolution of context.resolutions) {
385
423
  if ((0, import_type_guards.isFunction)(resolution.value?.[import_interfaces.afterResolve])) {
386
- const returnValue = resolution.value[import_interfaces.afterResolve](resolution.argument);
424
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
425
+ const returnValue = resolution.value[import_interfaces.afterResolve](resolution.argument, resolutionContext);
387
426
  throwOnPromise(returnValue, "[afterResolve]", resolution.chain);
388
427
  }
389
428
  if ((0, import_provider.isProviderWithInitializer)(resolution.registration.provider)) {
390
- const returnValue = resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument);
429
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
430
+ const returnValue = resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolutionContext);
391
431
  throwOnPromise(returnValue, "provider afterResolve handler", resolution.chain);
392
432
  }
393
433
  if ((0, import_type_guards.isDefined)(resolution.registration.options.afterResolve)) {
394
- const returnValue = resolution.registration.options.afterResolve(resolution.value, resolution.argument);
434
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
435
+ const returnValue = resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolutionContext);
395
436
  throwOnPromise(returnValue, "registration afterResolve handler", resolution.chain);
396
437
  }
397
438
  }
@@ -401,16 +442,18 @@ async function postProcessAsync(context) {
401
442
  fn();
402
443
  }
403
444
  derefForwardRefs(context);
404
- for (let i = context.resolutions.length - 1; i >= 0; i--) {
405
- const resolution = context.resolutions[i];
445
+ for (const resolution of context.resolutions) {
406
446
  if ((0, import_type_guards.isFunction)(resolution.value?.[import_interfaces.afterResolve])) {
407
- await resolution.value[import_interfaces.afterResolve](resolution.argument);
447
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
448
+ await resolution.value[import_interfaces.afterResolve](resolution.argument, resolutionContext);
408
449
  }
409
450
  if ((0, import_provider.isProviderWithInitializer)(resolution.registration.provider)) {
410
- await resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument);
451
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
452
+ await resolution.registration.provider.afterResolve?.(resolution.value, resolution.argument, resolutionContext);
411
453
  }
412
454
  if ((0, import_type_guards.isDefined)(resolution.registration.options.afterResolve)) {
413
- await resolution.registration.options.afterResolve(resolution.value, resolution.argument);
455
+ const resolutionContext = context.resolutionContexts.get(resolution.tag);
456
+ await resolution.registration.options.afterResolve(resolution.value, resolution.argument, resolutionContext);
414
457
  }
415
458
  }
416
459
  }
@@ -435,7 +478,7 @@ function throwOnPromise(value, type, chain) {
435
478
  }
436
479
  }
437
480
  function checkOverflow(chain, context) {
438
- if (chain.length > 750 || ++context.resolves > 750) {
481
+ if (chain.length > 100 || ++context.resolves > 7500) {
439
482
  throw new import_resolve_error.ResolveError("Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle or forwardRef instead.", chain);
440
483
  }
441
484
  }
@@ -1,14 +1,16 @@
1
- import type { Type } from '../types.js';
2
- import type { InjectionToken } from './token.js';
1
+ import type { Record, Type } from '../types.js';
2
+ import type { ArgumentedInjectionToken, InjectionTokenArgument, ReifyingInjectionToken } from './token.js';
3
3
  export declare const resolveArgumentType: unique symbol;
4
4
  export declare const afterResolve: unique symbol;
5
5
  export type ResolveArgumentType = typeof resolveArgumentType;
6
- export type ResolveArgument<T, Fallback = undefined> = (T extends Resolvable<infer U> ? U : T extends Type<Resolvable<infer U>> ? U : T extends InjectionToken<infer U, infer A> ? ResolveArgument<U, A> : Fallback) | undefined;
7
- export interface Resolvable<A = unknown> {
6
+ export type ResolveArgument<T, Fallback = undefined> = undefined | (T extends Resolvable<infer U> ? U : T extends Type<Resolvable<infer U>> ? U : T extends (ArgumentedInjectionToken<any, any> | ReifyingInjectionToken) ? InjectionTokenArgument<T> : Fallback);
7
+ export interface Resolvable<A = unknown, C extends Record = Record> extends Partial<AfterResolve<A, C>> {
8
8
  /**
9
9
  * type of resolve argument
10
10
  * @deprecated only used for type inference
11
11
  */
12
12
  readonly [resolveArgumentType]: A;
13
- [afterResolve]?(argument: A): void | Promise<void>;
13
+ }
14
+ export interface AfterResolve<A = unknown, C extends Record = Record> {
15
+ [afterResolve](argument: A, context: C): void | Promise<void>;
14
16
  }
@@ -1,36 +1,41 @@
1
- import type { Constructor, TypedOmit } from '../types.js';
1
+ import type { Constructor, Record, TypedOmit } from '../types.js';
2
2
  import type { ResolveArgument } from './interfaces.js';
3
3
  import type { InjectionToken } from './token.js';
4
4
  import type { ResolveContext } from './types.js';
5
- export type Factory<T, A = any> = (argument: ResolveArgument<T, A>, context: ResolveContext) => T;
5
+ export type Factory<T, A = any, C extends Record = Record> = (argument: ResolveArgument<T, A>, context: ResolveContext<C>) => T;
6
6
  export type ProviderWithArgument<T, A> = {
7
7
  defaultArgument?: ResolveArgument<T, A>;
8
8
  defaultArgumentProvider?: () => ResolveArgument<T, A>;
9
9
  };
10
- export type ProviderWithInitializer<T, A> = {
11
- afterResolve?: (value: T, argument: A) => void | Promise<void>;
10
+ export type ProviderWithInitializer<T, A, C extends Record> = {
11
+ afterResolve?: (value: T, argument: A, context: C) => void | Promise<void>;
12
12
  };
13
- export type Provider<T = any, A = any> = ClassProvider<T> | ValueProvider<T> | TokenProvider<T, A> | FactoryProvider<T, A>;
14
- export type ClassProvider<T = any, A = any> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A> & {
13
+ export type Provider<T = any, A = any, C extends Record = Record> = ClassProvider<T, A, C> | ValueProvider<T> | TokenProvider<T, A, C> | FactoryProvider<T, A, C>;
14
+ export type ClassProvider<T = any, A = any, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & {
15
15
  useClass: Constructor<T>;
16
16
  };
17
17
  export type ValueProvider<T = any> = {
18
18
  useValue: T;
19
19
  };
20
- export type TokenProvider<T = any, A = any> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A> & ({
20
+ export type TokenProvider<T = any, A = any, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & ({
21
21
  useToken: InjectionToken<T, A>;
22
22
  useTokenProvider?: undefined;
23
23
  } | {
24
24
  useToken?: undefined;
25
25
  useTokenProvider: () => InjectionToken<T, A>;
26
- });
27
- export type FactoryProvider<T = any, A = unknown> = {
28
- useFactory: Factory<T, A>;
26
+ }) & {
27
+ /**
28
+ * whether to resolve all providers registered for the token
29
+ */
30
+ resolveAll?: boolean;
29
31
  };
30
- export declare function classProvider<T, A>(constructor: Constructor<T>, options?: TypedOmit<ClassProvider<T, A>, 'useClass'>): ClassProvider<T, A>;
32
+ export type FactoryProvider<T = any, A = unknown, C extends Record = Record> = ProviderWithArgument<T, A> & ProviderWithInitializer<T, A, C> & {
33
+ useFactory: Factory<T, A, C>;
34
+ };
35
+ export declare function classProvider<T, A, C extends Record>(constructor: Constructor<T>, options?: TypedOmit<ClassProvider<T, A, C>, 'useClass'>): ClassProvider<T, A, C>;
31
36
  export declare function valueProvider<T>(value: T, options?: TypedOmit<ValueProvider<T>, 'useValue'>): ValueProvider<T>;
32
- export declare function tokenProvider<T, A>(token: InjectionToken<T, A>, options?: TypedOmit<TokenProvider<T>, 'useToken' | 'useTokenProvider'>): TokenProvider<T>;
33
- export declare function factoryProvider<T, A>(factory: Factory<T, A>, options?: TypedOmit<FactoryProvider<T, A>, 'useFactory'>): FactoryProvider<T, A>;
37
+ export declare function tokenProvider<T, A, C extends Record>(token: InjectionToken<T, A>, options?: TypedOmit<TokenProvider<T, A, C>, 'useToken' | 'useTokenProvider'>): TokenProvider<T>;
38
+ export declare function factoryProvider<T, A, C extends Record>(factory: Factory<T, A, C>, options?: TypedOmit<FactoryProvider<T, A, C>, 'useFactory'>): FactoryProvider<T, A, C>;
34
39
  export declare function isClassProvider<T, A>(value: Provider<T, A>): value is ClassProvider<T, A>;
35
40
  export declare function isClassProvider<T, A>(value: unknown): value is ClassProvider<T, A>;
36
41
  export declare function isValueProvider<T>(value: Provider<T>): value is ValueProvider<T>;
@@ -41,4 +46,4 @@ export declare function isFactoryProvider<T, A>(value: Provider<T, A>): value is
41
46
  export declare function isFactoryProvider<T, A>(value: unknown): value is FactoryProvider<T, A>;
42
47
  export declare function isProvider<T, A>(value: Provider<T, A>): value is Provider<T, A>;
43
48
  export declare function isProvider<T, A>(value: unknown): value is Provider<T, A>;
44
- export declare function isProviderWithInitializer<T, A>(value: Provider<T, A>): value is Extract<Provider<T, A>, ProviderWithInitializer<T, A>>;
49
+ export declare function isProviderWithInitializer<T, A, C extends Record>(value: Provider<T, A, C>): value is Extract<Provider<T, A, C>, ProviderWithInitializer<T, A, C>>;
@@ -2,13 +2,20 @@ import type { AbstractConstructor } from '../types.js';
2
2
  declare const type: unique symbol;
3
3
  declare const argument: unique symbol;
4
4
  export type ArgumentedInjectionToken<T, A> = SimpleInjectionToken<T> & {
5
- [argument]?: A;
5
+ [argument]: A;
6
6
  };
7
7
  export type SimpleInjectionToken<T> = AbstractConstructor<T> | object;
8
8
  export type InjectionToken<T = any, A = any> = SimpleInjectionToken<T> | ArgumentedInjectionToken<T, A> | ReifyingInjectionToken<T, A>;
9
+ export type InjectionTokenArgument<T extends ArgumentedInjectionToken<any, any> | ReifyingInjectionToken> = T[typeof argument];
9
10
  export declare class ReifyingInjectionToken<T = any, A = any> {
10
- private readonly [type];
11
- private readonly [argument];
11
+ /**
12
+ * @deprecated for internal typing
13
+ */
14
+ readonly [type]: T;
15
+ /**
16
+ * @deprecated for internal typing
17
+ */
18
+ readonly [argument]: A;
12
19
  readonly description: string;
13
20
  constructor(description: string);
14
21
  toString(): string;
package/injector/token.js CHANGED
@@ -37,5 +37,5 @@ function injectionToken(description) {
37
37
  return new ReifyingInjectionToken(description);
38
38
  }
39
39
  function getTokenName(token) {
40
- return (0, import_type_guards.isFunction)(token) ? token.name : (0, import_type_guards.isString)(token) ? `"${token}"` : String(token);
40
+ return (0, import_type_guards.isFunction)(token) ? token.name : token instanceof ReifyingInjectionToken ? token.toString() : String(token);
41
41
  }
@@ -7,6 +7,8 @@ export type InjectMetadata = {
7
7
  forwardRefToken?: ForwardRefInjectionToken;
8
8
  /** whether injection is optional if token is not registered. Set by optional decorator */
9
9
  optional?: boolean;
10
+ /** whether injection should resolve all providers */
11
+ resolveAll?: boolean;
10
12
  /** mapper to map resolved value */
11
13
  mapper?: Mapper;
12
14
  /** provider to get resolve argument */