ts-ioc-container 72.0.0 → 72.2.0

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 (235) hide show
  1. package/AGENTS.md +179 -0
  2. package/README.md +94 -0
  3. package/cjm/container/Container.js +2 -2
  4. package/cjm/container/EmptyContainer.js +17 -15
  5. package/cjm/errors/ArgumentNotFoundError.js +1 -0
  6. package/cjm/errors/CannonSingletonApplyTwiceError.js +2 -14
  7. package/cjm/errors/CannotApplySingletonTwiceError.js +18 -0
  8. package/cjm/errors/ContainerDisposedError.js +1 -0
  9. package/cjm/errors/ContainerError.js +1 -0
  10. package/cjm/errors/ContainerNotFoundError.js +1 -0
  11. package/cjm/errors/DependencyMissingKeyError.js +1 -0
  12. package/cjm/errors/DependencyNotFoundError.js +1 -0
  13. package/cjm/errors/MethodNotImplementedError.js +1 -0
  14. package/cjm/errors/ProviderDisposedError.js +1 -0
  15. package/cjm/errors/TypedEventDisposedError.js +1 -0
  16. package/cjm/errors/UnsupportedTokenTypeError.js +1 -0
  17. package/cjm/index.js +8 -3
  18. package/cjm/metadata/class.js +3 -1
  19. package/cjm/metadata/method.js +3 -1
  20. package/cjm/metadata/parameter.js +7 -1
  21. package/cjm/provider/Provider.js +6 -6
  22. package/cjm/registration/Registration.js +2 -2
  23. package/cjm/token/ConstantToken.js +4 -4
  24. package/cjm/token/FunctionToken.js +1 -1
  25. package/cjm/token/GroupInstanceToken.js +4 -4
  26. package/cjm/token/toToken.js +1 -1
  27. package/cjm/utils/TypedEvent.js +1 -1
  28. package/cjm/utils/array.js +1 -1
  29. package/esm/container/Container.js +2 -2
  30. package/esm/container/EmptyContainer.js +17 -15
  31. package/esm/errors/ArgumentNotFoundError.js +1 -0
  32. package/esm/errors/CannonSingletonApplyTwiceError.js +2 -13
  33. package/esm/errors/CannotApplySingletonTwiceError.js +14 -0
  34. package/esm/errors/ContainerDisposedError.js +1 -0
  35. package/esm/errors/ContainerError.js +1 -0
  36. package/esm/errors/ContainerNotFoundError.js +1 -0
  37. package/esm/errors/DependencyMissingKeyError.js +1 -0
  38. package/esm/errors/DependencyNotFoundError.js +1 -0
  39. package/esm/errors/MethodNotImplementedError.js +1 -0
  40. package/esm/errors/ProviderDisposedError.js +1 -0
  41. package/esm/errors/TypedEventDisposedError.js +1 -0
  42. package/esm/errors/UnsupportedTokenTypeError.js +1 -0
  43. package/esm/index.js +4 -3
  44. package/esm/metadata/class.js +1 -0
  45. package/esm/metadata/method.js +1 -0
  46. package/esm/metadata/parameter.js +5 -0
  47. package/esm/provider/Provider.js +6 -6
  48. package/esm/registration/Registration.js +2 -2
  49. package/esm/token/ConstantToken.js +4 -4
  50. package/esm/token/FunctionToken.js +1 -1
  51. package/esm/token/GroupInstanceToken.js +4 -4
  52. package/esm/token/toToken.js +1 -1
  53. package/esm/utils/TypedEvent.js +1 -1
  54. package/esm/utils/array.js +1 -1
  55. package/lib/ExecutionContext.ts +6 -0
  56. package/lib/container/AliasMap.ts +30 -0
  57. package/lib/container/AutoResolveModule.ts +24 -0
  58. package/lib/container/Container.ts +311 -0
  59. package/lib/container/EmptyContainer.ts +166 -0
  60. package/lib/container/IContainer.ts +156 -0
  61. package/lib/errors/ArgumentNotFoundError.ts +13 -0
  62. package/lib/errors/CannonSingletonApplyTwiceError.ts +6 -0
  63. package/lib/errors/CannotApplySingletonTwiceError.ts +22 -0
  64. package/lib/errors/ContainerDisposedError.ts +13 -0
  65. package/lib/errors/ContainerError.ts +15 -0
  66. package/lib/errors/ContainerNotFoundError.ts +13 -0
  67. package/lib/errors/DependencyMissingKeyError.ts +13 -0
  68. package/lib/errors/DependencyNotFoundError.ts +13 -0
  69. package/lib/errors/MethodNotImplementedError.ts +13 -0
  70. package/lib/errors/ProviderDisposedError.ts +22 -0
  71. package/lib/errors/TypedEventDisposedError.ts +22 -0
  72. package/lib/errors/UnsupportedTokenTypeError.ts +13 -0
  73. package/lib/hooks/HookCollector.ts +109 -0
  74. package/lib/hooks/HookContext.ts +85 -0
  75. package/lib/hooks/combinators.ts +51 -0
  76. package/lib/hooks/hook.ts +89 -0
  77. package/lib/hooks/injectProp.ts +14 -0
  78. package/lib/index.ts +181 -0
  79. package/lib/injector/IInjector.ts +88 -0
  80. package/lib/injector/MetadataInjector.ts +100 -0
  81. package/lib/injector/ProxyInjector.ts +31 -0
  82. package/lib/injector/SimpleInjector.ts +20 -0
  83. package/lib/metadata/class.ts +50 -0
  84. package/lib/metadata/method.ts +47 -0
  85. package/lib/metadata/parameter.ts +60 -0
  86. package/lib/metadata/target.ts +25 -0
  87. package/lib/provider/IProvider.ts +65 -0
  88. package/lib/provider/Provider.ts +174 -0
  89. package/lib/registration/IRegistration.ts +235 -0
  90. package/lib/registration/Registration.ts +122 -0
  91. package/lib/select.ts +33 -0
  92. package/lib/token/BindToken.ts +13 -0
  93. package/lib/token/ClassToken.ts +72 -0
  94. package/lib/token/ConstantToken.ts +50 -0
  95. package/lib/token/FunctionToken.ts +79 -0
  96. package/lib/token/GroupAliasToken.ts +92 -0
  97. package/lib/token/GroupInstanceToken.ts +70 -0
  98. package/lib/token/InjectionToken.ts +46 -0
  99. package/lib/token/SingleAliasToken.ts +84 -0
  100. package/lib/token/SingleToken.ts +93 -0
  101. package/lib/token/toToken.ts +46 -0
  102. package/lib/utils/ProxyRegistry.ts +149 -0
  103. package/lib/utils/TypedEvent.ts +96 -0
  104. package/lib/utils/array.ts +28 -0
  105. package/lib/utils/basic.ts +34 -0
  106. package/lib/utils/debounce.ts +18 -0
  107. package/lib/utils/errorHandler.ts +34 -0
  108. package/lib/utils/fp.ts +86 -0
  109. package/lib/utils/getConstructorChain.ts +17 -0
  110. package/lib/utils/memoize.ts +24 -0
  111. package/lib/utils/once.ts +24 -0
  112. package/lib/utils/shallowCache.ts +22 -0
  113. package/lib/utils/task.ts +33 -0
  114. package/lib/utils/throttle.ts +17 -0
  115. package/package.json +5 -3
  116. package/typings/ExecutionContext.d.ts +2 -0
  117. package/typings/ExecutionContext.d.ts.map +1 -0
  118. package/typings/container/AliasMap.d.ts +1 -0
  119. package/typings/container/AliasMap.d.ts.map +1 -0
  120. package/typings/container/AutoResolveModule.d.ts +16 -0
  121. package/typings/container/AutoResolveModule.d.ts.map +1 -0
  122. package/typings/container/Container.d.ts +60 -0
  123. package/typings/container/Container.d.ts.map +1 -0
  124. package/typings/container/EmptyContainer.d.ts +51 -0
  125. package/typings/container/EmptyContainer.d.ts.map +1 -0
  126. package/typings/container/IContainer.d.ts +75 -0
  127. package/typings/container/IContainer.d.ts.map +1 -0
  128. package/typings/errors/ArgumentNotFoundError.d.ts +3 -0
  129. package/typings/errors/ArgumentNotFoundError.d.ts.map +1 -0
  130. package/typings/errors/CannonSingletonApplyTwiceError.d.ts +6 -6
  131. package/typings/errors/CannonSingletonApplyTwiceError.d.ts.map +1 -0
  132. package/typings/errors/CannotApplySingletonTwiceError.d.ts +12 -0
  133. package/typings/errors/CannotApplySingletonTwiceError.d.ts.map +1 -0
  134. package/typings/errors/ContainerDisposedError.d.ts +3 -0
  135. package/typings/errors/ContainerDisposedError.d.ts.map +1 -0
  136. package/typings/errors/ContainerError.d.ts +7 -0
  137. package/typings/errors/ContainerError.d.ts.map +1 -0
  138. package/typings/errors/ContainerNotFoundError.d.ts +3 -0
  139. package/typings/errors/ContainerNotFoundError.d.ts.map +1 -0
  140. package/typings/errors/DependencyMissingKeyError.d.ts +3 -0
  141. package/typings/errors/DependencyMissingKeyError.d.ts.map +1 -0
  142. package/typings/errors/DependencyNotFoundError.d.ts +3 -0
  143. package/typings/errors/DependencyNotFoundError.d.ts.map +1 -0
  144. package/typings/errors/MethodNotImplementedError.d.ts +3 -0
  145. package/typings/errors/MethodNotImplementedError.d.ts.map +1 -0
  146. package/typings/errors/ProviderDisposedError.d.ts +6 -0
  147. package/typings/errors/ProviderDisposedError.d.ts.map +1 -0
  148. package/typings/errors/TypedEventDisposedError.d.ts +6 -0
  149. package/typings/errors/TypedEventDisposedError.d.ts.map +1 -0
  150. package/typings/errors/UnsupportedTokenTypeError.d.ts +3 -0
  151. package/typings/errors/UnsupportedTokenTypeError.d.ts.map +1 -0
  152. package/typings/hooks/HookCollector.d.ts +36 -0
  153. package/typings/hooks/HookCollector.d.ts.map +1 -0
  154. package/typings/hooks/HookContext.d.ts +10 -0
  155. package/typings/hooks/HookContext.d.ts.map +1 -0
  156. package/typings/hooks/combinators.d.ts +23 -0
  157. package/typings/hooks/combinators.d.ts.map +1 -0
  158. package/typings/hooks/hook.d.ts +39 -0
  159. package/typings/hooks/hook.d.ts.map +1 -0
  160. package/typings/hooks/injectProp.d.ts +9 -0
  161. package/typings/hooks/injectProp.d.ts.map +1 -0
  162. package/typings/index.d.ts +5 -3
  163. package/typings/index.d.ts.map +1 -0
  164. package/typings/injector/IInjector.d.ts +32 -0
  165. package/typings/injector/IInjector.d.ts.map +1 -0
  166. package/typings/injector/MetadataInjector.d.ts +58 -0
  167. package/typings/injector/MetadataInjector.d.ts.map +1 -0
  168. package/typings/injector/ProxyInjector.d.ts +13 -0
  169. package/typings/injector/ProxyInjector.d.ts.map +1 -0
  170. package/typings/injector/SimpleInjector.d.ts +13 -0
  171. package/typings/injector/SimpleInjector.d.ts.map +1 -0
  172. package/typings/metadata/class.d.ts +28 -0
  173. package/typings/metadata/class.d.ts.map +1 -0
  174. package/typings/metadata/method.d.ts +25 -0
  175. package/typings/metadata/method.d.ts.map +1 -0
  176. package/typings/metadata/parameter.d.ts +22 -0
  177. package/typings/metadata/parameter.d.ts.map +1 -0
  178. package/typings/metadata/target.d.ts +19 -0
  179. package/typings/metadata/target.d.ts.map +1 -0
  180. package/typings/provider/IProvider.d.ts +25 -0
  181. package/typings/provider/IProvider.d.ts.map +1 -0
  182. package/typings/provider/Provider.d.ts +30 -0
  183. package/typings/provider/Provider.d.ts.map +1 -0
  184. package/typings/registration/IRegistration.d.ts +137 -0
  185. package/typings/registration/IRegistration.d.ts.map +1 -0
  186. package/typings/registration/Registration.d.ts +23 -0
  187. package/typings/registration/Registration.d.ts.map +1 -0
  188. package/typings/select.d.ts +15 -0
  189. package/typings/select.d.ts.map +1 -0
  190. package/typings/token/BindToken.d.ts +3 -0
  191. package/typings/token/BindToken.d.ts.map +1 -0
  192. package/typings/token/ClassToken.d.ts +2 -0
  193. package/typings/token/ClassToken.d.ts.map +1 -0
  194. package/typings/token/ConstantToken.d.ts +14 -0
  195. package/typings/token/ConstantToken.d.ts.map +1 -0
  196. package/typings/token/FunctionToken.d.ts +10 -0
  197. package/typings/token/FunctionToken.d.ts.map +1 -0
  198. package/typings/token/GroupAliasToken.d.ts +14 -0
  199. package/typings/token/GroupAliasToken.d.ts.map +1 -0
  200. package/typings/token/GroupInstanceToken.d.ts +19 -0
  201. package/typings/token/GroupInstanceToken.d.ts.map +1 -0
  202. package/typings/token/InjectionToken.d.ts +8 -0
  203. package/typings/token/InjectionToken.d.ts.map +1 -0
  204. package/typings/token/SingleAliasToken.d.ts +6 -0
  205. package/typings/token/SingleAliasToken.d.ts.map +1 -0
  206. package/typings/token/SingleToken.d.ts +18 -0
  207. package/typings/token/SingleToken.d.ts.map +1 -0
  208. package/typings/token/toToken.d.ts +12 -0
  209. package/typings/token/toToken.d.ts.map +1 -0
  210. package/typings/utils/ProxyRegistry.d.ts +63 -0
  211. package/typings/utils/ProxyRegistry.d.ts.map +1 -0
  212. package/typings/utils/TypedEvent.d.ts +42 -0
  213. package/typings/utils/TypedEvent.d.ts.map +1 -0
  214. package/typings/utils/array.d.ts +7 -0
  215. package/typings/utils/array.d.ts.map +1 -0
  216. package/typings/utils/basic.d.ts +12 -0
  217. package/typings/utils/basic.d.ts.map +1 -0
  218. package/typings/utils/debounce.d.ts +2 -0
  219. package/typings/utils/debounce.d.ts.map +1 -0
  220. package/typings/utils/errorHandler.d.ts +4 -0
  221. package/typings/utils/errorHandler.d.ts.map +1 -0
  222. package/typings/utils/fp.d.ts +8 -0
  223. package/typings/utils/fp.d.ts.map +1 -0
  224. package/typings/utils/getConstructorChain.d.ts +9 -0
  225. package/typings/utils/getConstructorChain.d.ts.map +1 -0
  226. package/typings/utils/memoize.d.ts +10 -0
  227. package/typings/utils/memoize.d.ts.map +1 -0
  228. package/typings/utils/once.d.ts +2 -0
  229. package/typings/utils/once.d.ts.map +1 -0
  230. package/typings/utils/shallowCache.d.ts +2 -0
  231. package/typings/utils/shallowCache.d.ts.map +1 -0
  232. package/typings/utils/task.d.ts +13 -0
  233. package/typings/utils/task.d.ts.map +1 -0
  234. package/typings/utils/throttle.d.ts +2 -0
  235. package/typings/utils/throttle.d.ts.map +1 -0
@@ -3,19 +3,61 @@ import type { ArgsFn, DecorateFn, GetCacheKey, IProvider, ProviderHook, ScopeAcc
3
3
  import { BindToken } from '../token/BindToken.js';
4
4
  import { MapFn } from '../utils/fp.js';
5
5
  import { type constructor } from '../utils/basic.js';
6
+ /**
7
+ * Decides whether a registration is copied into a scope when that scope is
8
+ * created (or when the registration is added). `prev` is the result of the
9
+ * rules before it, so rules chain. Set with {@link scope} or `registration.when(...)`.
10
+ *
11
+ * @example
12
+ * const onlyRequest: ScopeMatchRule = (s) => s.hasTag('request');
13
+ */
6
14
  export type ScopeMatchRule = (s: IContainer, prev: boolean) => boolean;
15
+ /**
16
+ * A provider transform usable in both places: `registration.pipe(...)` calls
17
+ * `mapProvider`, `@register(...)` calls `mapRegistration`. Build one with
18
+ * {@link registerPipe}; `singleton()`, `lazy()`, `scopeAccess()` etc. are all pipes.
19
+ */
7
20
  export interface ProviderPipe<T = unknown> {
8
21
  mapProvider(p: IProvider<T>): IProvider<T>;
9
22
  mapRegistration(r: IRegistration<T>): IRegistration<T>;
10
23
  }
24
+ /** Narrows `obj` to a {@link ProviderPipe}. */
11
25
  export declare const isProviderPipe: <T>(obj: unknown) => obj is ProviderPipe<T>;
26
+ /**
27
+ * Turns a provider transform into a {@link ProviderPipe}, so it works both in
28
+ * `@register(...)` and in `registration.pipe(...)`.
29
+ *
30
+ * @example
31
+ * const cached = <T>() => registerPipe<T>((p) => p.singleton());
32
+ *
33
+ * @register(bindTo('Cache'), cached())
34
+ * class Cache {}
35
+ */
12
36
  export declare const registerPipe: <T>(mapProvider: (p: IProvider<T>) => IProvider<T>) => ProviderPipe<T>;
37
+ /**
38
+ * Anything that can name a binding key: a raw key, or a token that knows how to bind itself.
39
+ */
13
40
  export type Bindable<T = any> = DependencyKey | BindToken<T>;
41
+ /** Normalizes a {@link Bindable}: a raw key becomes a `SingleToken`, a token is returned as is. */
14
42
  export declare const toBindToken: <T>(target: Bindable<T>) => BindToken<T>;
43
+ /**
44
+ * Everything accepted at provider level - by `IRegistration.pipe(...)`.
45
+ */
15
46
  export type ProviderMapper<T = any> = MapFn<IProvider<T>> | ProviderPipe<T>;
47
+ /** Normalizes a {@link ProviderMapper} to a plain provider transform. */
16
48
  export declare const toProviderFn: <T>(mapper: ProviderMapper<T>) => MapFn<IProvider<T>>;
49
+ /**
50
+ * Everything accepted at registration level - by `@register(...)`.
51
+ */
17
52
  export type RegistrationMapper<T = any> = MapFn<IRegistration<T>> | ProviderPipe<T> | Bindable<T>;
53
+ /** Normalizes a {@link RegistrationMapper} to a plain registration transform (a `Bindable` becomes `bindTo(...)`). */
18
54
  export declare const toRegistrationFn: <T>(mapper: RegistrationMapper<T>) => MapFn<IRegistration<T>>;
55
+ /**
56
+ * A recipe for putting one provider into matching scopes. Created with
57
+ * `Registration.fromClass` / `fromValue` / `fromFn` / `fromKey` and added with
58
+ * `container.addRegistration(...)`; `applyTo(scope)` registers the provider
59
+ * when the scope rules match.
60
+ */
19
61
  export interface IRegistration<T = any> extends IContainerModule {
20
62
  getKeyOrFail(): DependencyKey;
21
63
  when(...predicates: ScopeMatchRule[]): this;
@@ -24,16 +66,111 @@ export interface IRegistration<T = any> extends IContainerModule {
24
66
  pipe(...mappers: ProviderMapper<T>[]): this;
25
67
  bindToAlias(alias: DependencyKey): this;
26
68
  }
69
+ /** The dependency type `T` of an `IRegistration<T>`. */
27
70
  export type ReturnTypeOfRegistration<T> = T extends IRegistration<infer R> ? R : never;
71
+ /** Reads the registration transforms written on a class by {@link register}. */
28
72
  export declare const getTransformers: (Target: constructor<unknown>) => MapFn<IRegistration<any>>[];
73
+ /**
74
+ * Class decorator that configures how `Registration.fromClass(Target)` registers
75
+ * the class: binding keys, scope rules and provider pipes. A bare key or token
76
+ * is shorthand for `bindTo(...)`. Without a key the class name is used.
77
+ *
78
+ * @example
79
+ * @register(bindTo(ILoggerToken), scope((s) => s.hasTag('application')), singleton())
80
+ * class Logger implements ILogger {}
81
+ *
82
+ * container.addRegistration(Registration.fromClass(Logger));
83
+ */
29
84
  export declare const register: (...mappers: RegistrationMapper[]) => ClassDecorator;
85
+ /**
86
+ * Binds a registration to one or more keys or tokens. A `SingleToken` binds its
87
+ * key; an alias token (`toSingleAlias`, `toGroupAlias`) adds an alias.
88
+ *
89
+ * @example
90
+ * @register(bindTo(ILoggerToken))
91
+ * class Logger {}
92
+ *
93
+ * @example
94
+ * Registration.fromValue(config).bindTo('Config');
95
+ */
30
96
  export declare const bindTo: (...tokens: Bindable[]) => MapFn<IRegistration>;
97
+ /**
98
+ * Limits which scopes a registration is copied into. Without it, a registration
99
+ * lands in every scope, so a `singleton()` becomes one instance per scope.
100
+ *
101
+ * @example
102
+ * @register(bindTo('Repo'), scope((s) => s.hasTag('request')))
103
+ * class Repo {}
104
+ */
31
105
  export declare const scope: (...rules: ScopeMatchRule[]) => MapFn<IRegistration>;
106
+ /**
107
+ * Appends fixed values after the runtime args handed to the provider.
108
+ *
109
+ * @example
110
+ * @register(bindTo('Client'), appendArgs('https://api.example.com'))
111
+ * class Client {
112
+ * constructor(@inject(arg(0)) readonly baseUrl: string) {}
113
+ * }
114
+ */
32
115
  export declare const appendArgs: <T>(...extraArgs: unknown[]) => ProviderPipe<T>;
116
+ /**
117
+ * Appends values computed at resolve time after the runtime args.
118
+ *
119
+ * @example
120
+ * @register(bindTo('Client'), appendArgsFn(({ scope }) => [scope.resolve('API_URL')]))
121
+ * class Client {}
122
+ */
33
123
  export declare const appendArgsFn: <T>(fn: ArgsFn) => ProviderPipe<T>;
124
+ /**
125
+ * Controls from which scopes the provider may be resolved (unlike {@link scope},
126
+ * which controls where it is registered). A denied lookup falls through to the parent.
127
+ *
128
+ * @example
129
+ * @register(bindTo('Admin'), scopeAccess(({ invocationScope }) => invocationScope.hasTag('admin')))
130
+ * class AdminService {}
131
+ */
34
132
  export declare const scopeAccess: <T>(rule: ScopeAccessRule) => ProviderPipe<T>;
133
+ /**
134
+ * Resolves the dependency as a proxy that constructs the real instance on first
135
+ * member access.
136
+ *
137
+ * @example
138
+ * @register(bindTo('Heavy'), lazy())
139
+ * class HeavyService {}
140
+ */
35
141
  export declare const lazy: <T>() => ProviderPipe<T>;
142
+ /**
143
+ * Marks the provider for eager resolution when the scope is set up; needs
144
+ * `container.useModule(new AutoResolveModule())`.
145
+ */
36
146
  export declare const autoResolve: <T>() => ProviderPipe<T>;
147
+ /**
148
+ * Wraps or replaces the resolved dependency. Order relative to `lazy()` decides
149
+ * whether the proxy or the real instance is decorated.
150
+ *
151
+ * @example
152
+ * @register(bindTo('Api'), decorate((api, scope) => new LoggingApi(api)))
153
+ * class Api {}
154
+ */
37
155
  export declare const decorate: (...fns: DecorateFn[]) => ProviderPipe<unknown>;
156
+ /**
157
+ * Caches the dependency per provider, which means per scope the registration
158
+ * was copied into (combine with {@link scope}). `getCacheKey` receives the
159
+ * runtime args and caches one instance per distinct key.
160
+ *
161
+ * @example
162
+ * @register(bindTo('Db'), scope((s) => s.hasTag('application')), singleton())
163
+ * class Db {}
164
+ *
165
+ * @example
166
+ * // one instance per tenant id passed as the first runtime arg
167
+ * @register(bindTo('TenantDb'), singleton(([tenantId]) => String(tenantId)))
168
+ * class TenantDb {}
169
+ */
38
170
  export declare const singleton: <T = unknown>(getCacheKey?: GetCacheKey) => ProviderPipe<T>;
171
+ /**
172
+ * Registration-level form of `IProvider.onResolved`: attaches provider hooks to
173
+ * the piped registration's provider.
174
+ */
39
175
  export declare const onResolve: <T = unknown>(...hooks: ProviderHook[]) => ProviderPipe<T>;
176
+ //# sourceMappingURL=IRegistration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IRegistration.d.ts","sourceRoot":"","sources":["../../lib/registration/IRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAmB,MAAM,yBAAyB,CAAC;AACtH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;AAEvE;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAE3C,eAAe,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;CACxD;AAED,+CAA+C;AAC/C,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,KAAK,OAAO,KAAG,GAAG,IAAI,YAAY,CAAC,CAAC,CACL,CAAC;AAElE;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAG,YAAY,CAAC,CAAC,CAG7F,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG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,EAAE,oBAAmD,CAAC"}
@@ -2,6 +2,22 @@ import { DependencyKey, IContainer } from '../container/IContainer.js';
2
2
  import type { IProvider, ResolveDependency } from '../provider/IProvider.js';
3
3
  import { type Bindable, type IRegistration, type ProviderMapper, type ScopeMatchRule } from './IRegistration.js';
4
4
  import { type constructor } from '../utils/basic.js';
5
+ /**
6
+ * Builds registrations for `container.addRegistration(...)`. Usually imported as
7
+ * `Registration as R`.
8
+ *
9
+ * - `R.fromClass(Class)` - reads the class's `@register(...)` config; the key
10
+ * defaults to the class name.
11
+ * - `R.fromValue(value).bindTo('Key')` - a constant.
12
+ * - `R.fromFn(({ scope, args }) => ...).bindTo('Key')` - a factory.
13
+ * - `R.fromKey('Other').bindTo('Key')` - an alias of another key.
14
+ *
15
+ * @example
16
+ * container
17
+ * .addRegistration(R.fromClass(Logger))
18
+ * .addRegistration(R.fromValue('https://api.example.com').bindTo('API_URL'))
19
+ * .addRegistration(R.fromFn(({ scope }) => new Client(scope.resolve('API_URL'))).bindTo('Client'));
20
+ */
5
21
  export declare class Registration<T = any> implements IRegistration<T> {
6
22
  private createProvider;
7
23
  key?: DependencyKey | undefined;
@@ -21,6 +37,13 @@ export declare class Registration<T = any> implements IRegistration<T> {
21
37
  when(...predicates: ScopeMatchRule[]): this;
22
38
  bindTo(key: Bindable): this;
23
39
  private matchScope;
40
+ /**
41
+ * @throws {DependencyMissingKeyError} when the registration matches the scope but has no binding key.
42
+ */
24
43
  applyTo(container: IContainer): void;
44
+ /**
45
+ * @throws {DependencyMissingKeyError} when no binding key has been set for this registration.
46
+ */
25
47
  getKeyOrFail(): DependencyKey;
26
48
  }
49
+ //# sourceMappingURL=Registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registration.d.ts","sourceRoot":"","sources":["../../lib/registration/Registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,E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3B,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAepC;;OAEG;IACH,YAAY,IAAI,aAAa;CAQ9B"}
@@ -1,6 +1,20 @@
1
1
  import { type CreateScopeOptions } from './container/IContainer.js';
2
2
  import { FunctionToken } from './token/FunctionToken.js';
3
3
  import { GroupInstanceToken, InstancePredicate } from './token/GroupInstanceToken.js';
4
+ /**
5
+ * Shortcuts for common tokens.
6
+ *
7
+ * - `select.token(x)` - `toToken(x)`
8
+ * - `select.alias('Key')` - a {@link GroupAliasToken}
9
+ * - `select.instances(predicate)` - instances already created in the scope
10
+ * - `select.scope.current` - the resolving scope itself
11
+ * - `select.scope.create({ tags })` - a new child scope
12
+ *
13
+ * @example
14
+ * class Handler {
15
+ * constructor(@inject(by(select.scope.current)) private scope: IContainer) {}
16
+ * }
17
+ */
4
18
  export declare const select: {
5
19
  alias: <T>(token: import("./container/IContainer.js").DependencyKey) => import("./token/GroupAliasToken.js").GroupAliasToken<T>;
6
20
  token: <T = any>(token: import("./token/toToken.js").Injectable<T>) => import(".").InjectionToken<T>;
@@ -10,3 +24,4 @@ export declare const select: {
10
24
  create: (options: CreateScopeOptions) => FunctionToken<import("./container/IContainer.js").IContainer>;
11
25
  };
12
26
  };
27
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../lib/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGnF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM;;;4BAKM,iBAAiB;;;0BAKpB,kBAAkB;;CAEvC,CAAC"}
@@ -1,5 +1,8 @@
1
1
  import { IRegistration } from '../registration/IRegistration.js';
2
+ /** A token that can bind a registration to itself (a key or an alias). */
2
3
  export interface BindToken<T = any> {
3
4
  bindTo(r: IRegistration<T>): void;
4
5
  }
6
+ /** Narrows `token` to a {@link BindToken}. */
5
7
  export declare function isBindToken(token: unknown): token is BindToken;
8
+ //# sourceMappingURL=BindToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BindToken.d.ts","sourceRoot":"","sources":["../../lib/token/BindToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9D,0EAA0E;AAC1E,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,GAAG;IAChC,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACnC;AAED,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D"}
@@ -2,6 +2,7 @@ import { IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
3
  import { type constructor, Serializable } from '../utils/basic.js';
4
4
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
5
+ /** A token for a class: resolves it through the scope's injector. `toToken(Class)` creates one. */
5
6
  export declare class ClassToken<T = any> extends InjectionToken<T> implements Serializable {
6
7
  private readonly target;
7
8
  private readonly _getArgsFn;
@@ -19,3 +20,4 @@ export declare class ClassToken<T = any> extends InjectionToken<T> implements Se
19
20
  addTags(...tags: string[]): ClassToken<T>;
20
21
  toString(): string;
21
22
  }
23
+ //# sourceMappingURL=ClassToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassToken.d.ts","sourceRoot":"","sources":["../../lib/token/ClassToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/D,mGAAmG;AACnG,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAK9E,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGf,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACvC,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC;IAOnE,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;IAS1B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE;IASvC,IAAI;IAQJ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;IAQzC,QAAQ,IAAI,MAAM;CAGnB"}
@@ -1,15 +1,29 @@
1
1
  import type { IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
3
  import { Serializable } from '../utils/basic.js';
4
+ /** A token that always resolves to a fixed value. It takes no args and cannot be lazy. */
4
5
  export declare class ConstantToken<T = any> extends InjectionToken<T> implements Serializable {
5
6
  private readonly token;
6
7
  constructor(token: T, { tags }?: {
7
8
  tags?: string[];
8
9
  });
9
10
  resolve(s: IContainer): T;
11
+ /**
12
+ * @throws {MethodNotImplementedError} always — a constant token cannot receive static args.
13
+ */
10
14
  args(...deps: unknown[]): InjectionToken<T>;
15
+ /**
16
+ * @throws {MethodNotImplementedError} always — a constant token cannot receive resolved args.
17
+ */
11
18
  argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<T>;
19
+ /**
20
+ * @throws {MethodNotImplementedError} always — a constant token cannot be made lazy.
21
+ */
12
22
  lazy(): InjectionToken<T>;
13
23
  addTags(...tags: string[]): ConstantToken<T>;
24
+ /**
25
+ * @throws {MethodNotImplementedError} always — a constant token has no underlying key.
26
+ */
14
27
  toString(): string;
15
28
  }
29
+ //# sourceMappingURL=ConstantToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConstantToken.d.ts","sourceRoot":"","sources":["../../lib/token/ConstantToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,0FAA0F;AAC1F,qBAAa,aAAa,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAEjF,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,CAAC,EACzB,EAAE,IAAS,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAKzC,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC;IAIzB;;OAEG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAI3C;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAIlE;;OAEG;IACH,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAIzB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAI5C;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -3,6 +3,12 @@ import { InjectionToken } from './InjectionToken.js';
3
3
  import { InjectFn } from '../hooks/hook.js';
4
4
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
5
5
  import { Serializable } from '../utils/basic.js';
6
+ /**
7
+ * A token that resolves by calling an `InjectFn` with the resolution context.
8
+ *
9
+ * @example
10
+ * const CurrentScope = new FunctionToken(({ scope }) => scope);
11
+ */
6
12
  export declare class FunctionToken<T = any> extends InjectionToken<T> implements Serializable {
7
13
  private readonly fn;
8
14
  private readonly _getArgsFn;
@@ -17,5 +23,9 @@ export declare class FunctionToken<T = any> extends InjectionToken<T> implements
17
23
  argsFn(fn: (s: IContainer) => unknown[]): InjectionToken<T>;
18
24
  lazy(): InjectionToken<T>;
19
25
  addTags(...tags: string[]): FunctionToken<T>;
26
+ /**
27
+ * @throws {MethodNotImplementedError} always — a function token has no underlying key.
28
+ */
20
29
  toString(): string;
21
30
  }
31
+ //# sourceMappingURL=FunctionToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionToken.d.ts","sourceRoot":"","sources":["../../lib/token/FunctionToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,qBAAa,aAAa,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAKjF,OAAO,CAAC,QAAQ,CAAC,EAAE;IAJrB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGf,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,EAChC,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC;IAQnE,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAS9C,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAS3D,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAQzB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAQ5C;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -4,6 +4,18 @@ import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { BindToken } from './BindToken.js';
5
5
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
6
6
  import { Serializable } from '../utils/basic.js';
7
+ /**
8
+ * A token for every dependency registered under an alias. As a `bindTo(...)`
9
+ * target it adds the alias; resolving returns all matches as an array.
10
+ *
11
+ * @example
12
+ * const IMiddlewareToken = toGroupAlias<IMiddleware>('IMiddleware');
13
+ *
14
+ * @register(bindTo(IMiddlewareToken))
15
+ * class Auth implements IMiddleware {}
16
+ *
17
+ * IMiddlewareToken.resolve(scope); // IMiddleware[]
18
+ */
7
19
  export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implements BindToken<T>, Serializable {
8
20
  readonly token: DependencyKey;
9
21
  private readonly _getArgsFn;
@@ -22,4 +34,6 @@ export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implem
22
34
  addTags(...tags: string[]): GroupAliasToken<T>;
23
35
  toString(): string;
24
36
  }
37
+ /** Creates a {@link GroupAliasToken} for `token`. */
25
38
  export declare const toGroupAlias: <T>(token: DependencyKey) => GroupAliasToken<T>;
39
+ //# sourceMappingURL=GroupAliasToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupAliasToken.d.ts","sourceRoot":"","sources":["../../lib/token/GroupAliasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,EAAE,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY;IAKnG,QAAQ,CAAC,KAAK,EAAE,aAAa;IAJ/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGvB,KAAK,EAAE,aAAa,EAC7B,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,IACxB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC,EAAE;IAOrE,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;IAI1B,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;IAS1B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE;IASvC,IAAI;IAQJ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;IAQ9C,QAAQ,IAAI,MAAM;CAGnB;AAED,qDAAqD;AACrD,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,OAAO,aAAa,uBAAkC,CAAC"}
@@ -1,7 +1,12 @@
1
1
  import { InjectionToken } from './InjectionToken.js';
2
2
  import type { IContainer } from '../container/IContainer.js';
3
3
  import { Instance, Serializable } from '../utils/basic.js';
4
+ /** Selects instances for a {@link GroupInstanceToken}. */
4
5
  export type InstancePredicate = (dep: unknown) => boolean;
6
+ /**
7
+ * Resolves the instances already created in a scope (and, by default, its
8
+ * child scopes) that match a predicate. Created by `select.instances(...)`.
9
+ */
5
10
  export declare class GroupInstanceToken extends InjectionToken<Instance[]> implements Serializable {
6
11
  private predicate;
7
12
  private isCascade;
@@ -10,11 +15,25 @@ export declare class GroupInstanceToken extends InjectionToken<Instance[]> imple
10
15
  isCascade?: boolean;
11
16
  });
12
17
  select<R>(fn: (target: Instance) => R): (s: IContainer) => R[];
18
+ /**
19
+ * @throws {MethodNotImplementedError} always — a group instance token cannot receive static args.
20
+ */
13
21
  args(...deps: unknown[]): this;
22
+ /**
23
+ * @throws {MethodNotImplementedError} always — a group instance token cannot receive resolved args.
24
+ */
14
25
  argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<Instance[]>;
26
+ /**
27
+ * @throws {MethodNotImplementedError} always — a group instance token cannot be made lazy.
28
+ */
15
29
  lazy(): InjectionToken<Instance[]>;
30
+ /** Whether instances of child scopes are included (default `true`). */
16
31
  cascade(isTrue: boolean): this;
17
32
  resolve(c: IContainer): Instance[];
18
33
  addTags(...tags: string[]): GroupInstanceToken;
34
+ /**
35
+ * @throws {MethodNotImplementedError} always — a group instance token has no underlying key.
36
+ */
19
37
  toString(): string;
20
38
  }
39
+ //# sourceMappingURL=GroupInstanceToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupInstanceToken.d.ts","sourceRoot":"","sources":["../../lib/token/GroupInstanceToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAExD,0DAA0D;AAC1D,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;AAE1D;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,QAAQ,EAAE,CAAE,YAAW,YAAY;IAItF,OAAO,CAAC,SAAS;IAHnB,OAAO,CAAC,SAAS,CAAU;gBAGjB,SAAS,EAAE,iBAAiB,EACpC,EAAE,IAAS,EAAE,SAAgB,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO;IAMhF,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,QAAQ,KAAK,CAAC,IAC3B,GAAG,UAAU;IAGvB;;OAEG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;IAI3E;;OAEG;IACH,IAAI,IAAI,cAAc,CAAC,QAAQ,EAAE,CAAC;IAIlC,uEAAuE;IACvE,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAK9B,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,QAAQ,EAAE;IAIlC,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,kBAAkB;IAI9C;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -1,6 +1,12 @@
1
1
  import { type IContainer, type Tag } from '../container/IContainer.js';
2
2
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
3
+ /**
4
+ * The default `getArgsFn` of every token: the runtime `args` a token is
5
+ * resolved with reach the provider as they are, and `token.args(...)` /
6
+ * `token.argsFn(...)` append after them.
7
+ */
3
8
  export declare const forwardArgs: ArgsFn;
9
+ /** Base class of every token: something resolvable from a scope that can be specialized with args, lazy and tags. */
4
10
  export declare abstract class InjectionToken<T = any> {
5
11
  private readonly tags;
6
12
  protected constructor(tags?: Tag[]);
@@ -12,4 +18,6 @@ export declare abstract class InjectionToken<T = any> {
12
18
  hasTag(tag: Tag): boolean;
13
19
  protected getTags(): Tag[];
14
20
  }
21
+ /** Narrows `target` to an {@link InjectionToken}. */
15
22
  export declare function isInjectionToken<T = any>(target: unknown): target is InjectionToken<T>;
23
+ //# sourceMappingURL=InjectionToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InjectionToken.d.ts","sourceRoot":"","sources":["../../lib/token/InjectionToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,GAAG,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG/D;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAgC,CAAC;AAE3D,qHAAqH;AACrH,8BAAsB,cAAc,CAAC,CAAC,GAAG,GAAG;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;IAEhC,SAAS,aAAa,IAAI,GAAE,GAAG,EAAO;IAItC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,CAAC;IAC5D,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAC3E,QAAQ,CAAC,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAEnD,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAIzB,SAAS,CAAC,OAAO,IAAI,GAAG,EAAE;CAG3B;AAED,qDAAqD;AACrD,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,CAUtF"}
@@ -4,6 +4,10 @@ import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { BindToken } from './BindToken.js';
5
5
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
6
6
  import { Serializable } from '../utils/basic.js';
7
+ /**
8
+ * Like {@link GroupAliasToken}, but resolves exactly one dependency registered
9
+ * under the alias, and throws `DependencyNotFoundError` when there is none.
10
+ */
7
11
  export declare class SingleAliasToken<T = any> extends InjectionToken<T> implements BindToken<T>, Serializable {
8
12
  readonly token: DependencyKey;
9
13
  private readonly _getArgsFn;
@@ -22,4 +26,6 @@ export declare class SingleAliasToken<T = any> extends InjectionToken<T> impleme
22
26
  addTags(...tags: string[]): SingleAliasToken<T>;
23
27
  toString(): string;
24
28
  }
29
+ /** Creates a {@link SingleAliasToken} for `token`. */
25
30
  export declare const toSingleAlias: <T>(token: DependencyKey) => SingleAliasToken<T>;
31
+ //# sourceMappingURL=SingleAliasToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SingleAliasToken.d.ts","sourceRoot":"","sources":["../../lib/token/SingleAliasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,qBAAa,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY;IAKlG,QAAQ,CAAC,KAAK,EAAE,aAAa;IAJ/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGvB,KAAK,EAAE,aAAa,EAC7B,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC;IAOnE,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;IAI1B,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;IAS1B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE;IASvC,IAAI;IAQJ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAQ/C,QAAQ,IAAI,MAAM;CAGnB;AAED,sDAAsD;AACtD,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,aAAa,wBAAmC,CAAC"}
@@ -3,6 +3,23 @@ import { InjectionToken } from './InjectionToken.js';
3
3
  import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { ArgsFn, ResolveOptions } from '../provider/IProvider.js';
5
5
  import { Serializable } from '../utils/basic.js';
6
+ /**
7
+ * A typed handle for one dependency key - the usual way to name a dependency.
8
+ * `args(...)`, `argsFn(...)` and `lazy()` return a new token and never change
9
+ * this one, so one token can be specialized per injection site.
10
+ *
11
+ * @example
12
+ * const ILoggerToken = new SingleToken<ILogger>('ILogger');
13
+ *
14
+ * @register(bindTo(ILoggerToken))
15
+ * class Logger implements ILogger {}
16
+ *
17
+ * class App {
18
+ * constructor(@inject(by(ILoggerToken)) logger: ILogger) {}
19
+ * }
20
+ * ILoggerToken.resolve(scope);
21
+ * ILoggerToken.args('prefix').lazy().resolve(scope);
22
+ */
6
23
  export declare class SingleToken<T = any> extends InjectionToken<T> implements Serializable {
7
24
  token: DependencyKey;
8
25
  private readonly _getArgsFn;
@@ -21,3 +38,4 @@ export declare class SingleToken<T = any> extends InjectionToken<T> implements S
21
38
  addTags(...tags: string[]): SingleToken<T>;
22
39
  toString(): string;
23
40
  }
41
+ //# sourceMappingURL=SingleToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SingleToken.d.ts","sourceRoot":"","sources":["../../lib/token/SingleToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAE,YAAW,YAAY;IAKxE,KAAK,EAAE,aAAa;IAJ7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGzB,KAAK,EAAE,aAAa,EAC3B,EACE,SAAuB,EACvB,MAAc,EACd,IAAS,GACV,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAOnE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IACpB,GAAG,UAAU;IAGvB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAS,EAAE,IAAI,EAAE,GAAE,cAAmB,GAAG,CAAC;IAOnE,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;IAI1B,IAAI,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;IAS1B,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,EAAE;IASvC,IAAI;IAQJ,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;IAQ1C,QAAQ,IAAI,MAAM;CAGnB"}
@@ -2,6 +2,18 @@ import { DependencyKey } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
3
  import { InjectFn } from '../hooks/hook.js';
4
4
  import { type constructor } from '../utils/basic.js';
5
+ /** Anything `toToken(...)` turns into a token: a token, a key, a class or an `InjectFn`. */
5
6
  export type Injectable<T = any> = InjectFn<T> | InjectionToken<T> | DependencyKey | constructor<T>;
7
+ /**
8
+ * @throws {UnsupportedTokenTypeError} when `token` is not an `InjectionToken`, a `DependencyKey`, a constructor, or a function.
9
+ */
6
10
  export declare const toToken: <T = any>(token: Injectable<T>) => InjectionToken<T>;
11
+ /**
12
+ * Wraps a runtime argument so it can be resolved uniformly: an `InjectionToken`
13
+ * is returned as-is, anything else becomes a `ConstantToken` of itself. The
14
+ * library never applies it to the args list - a call site that wants
15
+ * "resolve tokens, pass literals through" does so explicitly, e.g.
16
+ * `@inject(({ scope, args = [] }) => argToToken(args[0]).resolve(scope))`.
17
+ */
7
18
  export declare const argToToken: <T = unknown>(v: T) => InjectionToken<T>;
19
+ //# sourceMappingURL=toToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toToken.d.ts","sourceRoot":"","sources":["../../lib/token/toToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,yBAAyB,CAAC;AAKzE,OAAO,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,WAAW,EAAM,MAAM,gBAAgB,CAAC;AAGtD,4FAA4F;AAC5F,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnG;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,GAAG,GAAG,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAoBvE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,KAAG,cAAc,CAAC,CAAC,CAAwD,CAAC"}
@@ -1,20 +1,83 @@
1
+ /**
2
+ * The proxy operations the library depends on. Depend on this rather than on
3
+ * {@link ProxyRegistry} itself, so a caller can substitute its own
4
+ * implementation - the concrete registry is a singleton and cannot be
5
+ * constructed a second time.
6
+ */
1
7
  export interface IProxyRegistry {
8
+ /**
9
+ * Returns the real object behind `value`, unwrapping proxies stacked to any
10
+ * depth. A value that is not a proxy is returned as is.
11
+ *
12
+ * The library calls this itself wherever a proxy would give the wrong answer -
13
+ * every read of class metadata (see `resolveConstructor`, `getHooks`,
14
+ * `resolveArgs`) and every identity check against a tracked instance (see
15
+ * `IContainer.hasInstance`). Pass the container's own values to those APIs as
16
+ * they come; unwrapping by hand is for code that needs the real object for its
17
+ * own reasons.
18
+ */
2
19
  unwrap<T extends object>(value: T): T;
3
20
  createProxy<T extends object>(target: T, handler?: ProxyHandler<T>): T;
21
+ /**
22
+ * Creates a proxy that resolves its target on first access and caches it.
23
+ */
4
24
  createLazyProxy<T extends object>(resolveInstance: () => T): T;
25
+ /**
26
+ * Wraps `resolveInstance` in a lazy proxy when `isLazy`, otherwise calls it
27
+ * right away.
28
+ */
5
29
  toLazyIf<T extends object>(resolveInstance: () => T, isLazy?: boolean): T;
6
30
  }
31
+ /**
32
+ * Creates proxies and tracks them, so a proxy can be traced back to the real
33
+ * object it stands for. The library's own {@link IProxyRegistry}.
34
+ *
35
+ * Process-wide singleton: a proxy created anywhere must be unwrappable
36
+ * everywhere, and the registry holds no configuration that would justify a
37
+ * second instance. Obtain it with {@link ProxyRegistry.getInstance}.
38
+ *
39
+ * Entries are held weakly - a proxy that becomes unreachable is collected along
40
+ * with its state.
41
+ */
7
42
  export declare class ProxyRegistry implements IProxyRegistry {
8
43
  private static instance?;
9
44
  private readonly states;
10
45
  private constructor();
11
46
  static getInstance(): ProxyRegistry;
47
+ /**
48
+ * Returns the real object behind `value`, unwrapping proxies stacked to any
49
+ * depth. A value that is not a proxy is returned as is.
50
+ */
12
51
  unwrap<T extends object>(value: T): T;
13
52
  createProxy<T extends object>(target: T, handler?: ProxyHandler<T>): T;
53
+ /**
54
+ * Creates a proxy that resolves its target on first access and caches it.
55
+ * The target is unwrapped on resolution, so wrapping a lazy proxy in another
56
+ * lazy proxy never stacks beyond one level.
57
+ */
14
58
  createLazyProxy<T extends object>(resolveInstance: () => T): T;
59
+ /**
60
+ * Wraps `resolveInstance` in a lazy proxy when `isLazy`, otherwise calls it
61
+ * right away.
62
+ */
15
63
  toLazyIf<T extends object>(resolveInstance: () => T, isLazy?: boolean): T;
16
64
  private isProxy;
17
65
  private getTarget;
18
66
  private register;
19
67
  }
68
+ /**
69
+ * The real object behind `value`, unwrapping proxies stacked to any depth. A
70
+ * value that is not a proxy is returned as is.
71
+ *
72
+ * A shortcut for `ProxyRegistry.getInstance().unwrap(value)` - the registry is a
73
+ * process-wide singleton, so unwrapping never needs an instance of its own. The
74
+ * library already unwraps wherever a proxy would give the wrong answer (reading
75
+ * class metadata, and `IContainer.hasInstance`), so reach for this only when
76
+ * your own code needs the real object - an identity check of your own, or
77
+ * bypassing a lazy proxy on purpose.
78
+ *
79
+ * Note that unwrapping a lazy proxy resolves its target, which is the point:
80
+ * there is no real object to hand back until it does.
81
+ */
20
82
  export declare const unwrapProxy: <T extends object>(value: T) => T;
83
+ //# sourceMappingURL=ProxyRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProxyRegistry.d.ts","sourceRoot":"","sources":["../../lib/utils/ProxyRegistry.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