@codefast/di 0.10.0 → 0.11.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.
- package/CHANGELOG.md +293 -0
- package/README.md +71 -7
- package/dist/ambient/active-container.d.ts +13 -11
- package/dist/ambient/active-container.js +8 -6
- package/dist/container/binding-builders.d.ts +25 -7
- package/dist/container/binding-builders.js +110 -42
- package/dist/container/container.d.ts +8 -8
- package/dist/container/container.js +244 -67
- package/dist/core/binding-declaration.d.ts +120 -0
- package/dist/core/binding-declaration.js +186 -0
- package/dist/core/binding-scope.d.ts +2 -2
- package/dist/core/binding.d.ts +61 -9
- package/dist/core/binding.js +49 -2
- package/dist/core/constraint-requirement.d.ts +1 -1
- package/dist/core/module.d.ts +10 -7
- package/dist/core/module.js +17 -3
- package/dist/core/registry.d.ts +17 -13
- package/dist/core/registry.js +155 -59
- package/dist/core/state-epoch.d.ts +18 -1
- package/dist/core/state-epoch.js +17 -0
- package/dist/core/tag.js +1 -1
- package/dist/core/token.d.ts +1 -1
- package/dist/core/types.d.ts +5 -5
- package/dist/decorators/decorator-metadata.d.ts +9 -0
- package/dist/decorators/decorator-metadata.js +20 -0
- package/dist/decorators/inject.d.ts +3 -3
- package/dist/decorators/inject.js +7 -6
- package/dist/decorators/injectable.d.ts +2 -2
- package/dist/decorators/injectable.js +5 -3
- package/dist/decorators/lifecycle-decorators.js +9 -3
- package/dist/errors/errors.d.ts +85 -14
- package/dist/errors/errors.js +100 -20
- package/dist/index.d.ts +37 -35
- package/dist/index.js +20 -19
- package/dist/injection/descriptor.d.ts +3 -3
- package/dist/injection/descriptor.js +3 -7
- package/dist/injection/resolve-options.d.ts +3 -3
- package/dist/injection/resolve-options.js +7 -5
- package/dist/introspection/dependency-graph.d.ts +10 -5
- package/dist/introspection/dependency-graph.js +51 -28
- package/dist/introspection/graph-adapters/cytoscape.d.ts +1 -1
- package/dist/introspection/graph-adapters/dot.d.ts +1 -1
- package/dist/introspection/graph-adapters/mermaid.d.ts +1 -1
- package/dist/introspection/graph-adapters/reactflow.d.ts +1 -1
- package/dist/introspection/graph-adapters/reactflow.js +6 -4
- package/dist/introspection/inspector.d.ts +4 -4
- package/dist/introspection/inspector.js +9 -12
- package/dist/lifecycle/lifecycle-manager.d.ts +4 -4
- package/dist/lifecycle/lifecycle-manager.js +18 -6
- package/dist/lifecycle/scope-manager.d.ts +2 -2
- package/dist/lifecycle/scope-manager.js +31 -13
- package/dist/metadata/metadata-reader-token.d.ts +2 -2
- package/dist/metadata/metadata-reader-token.js +1 -1
- package/dist/metadata/metadata-types.d.ts +3 -3
- package/dist/metadata/symbol-metadata-reader.d.ts +3 -3
- package/dist/metadata/symbol-metadata-reader.js +1 -1
- package/dist/metadata/verifying-metadata-reader.d.ts +5 -4
- package/dist/metadata/verifying-metadata-reader.js +30 -8
- package/dist/resolution/async-fan-out.d.ts +12 -0
- package/dist/resolution/async-fan-out.js +26 -0
- package/dist/resolution/cache/activation-need.d.ts +4 -5
- package/dist/resolution/cache/activation-need.js +11 -18
- package/dist/resolution/cache/binding-lookup-cache.d.ts +5 -12
- package/dist/resolution/cache/binding-lookup-cache.js +32 -19
- package/dist/resolution/cache/class-introspector.d.ts +16 -5
- package/dist/resolution/cache/class-introspector.js +73 -56
- package/dist/resolution/context.d.ts +17 -25
- package/dist/resolution/context.js +47 -56
- package/dist/resolution/path/resolution-path.d.ts +48 -13
- package/dist/resolution/path/resolution-path.js +90 -39
- package/dist/resolution/plan/instantiation-plan.d.ts +5 -5
- package/dist/resolution/plan/instantiation-plan.js +66 -26
- package/dist/resolution/plan/plan-codegen.d.ts +10 -7
- package/dist/resolution/plan/plan-codegen.js +62 -34
- package/dist/resolution/resolver.d.ts +16 -17
- package/dist/resolution/resolver.js +316 -273
- package/dist/resolution/select/binding-select.d.ts +6 -5
- package/dist/resolution/select/binding-select.js +5 -4
- package/dist/resolution/select/constraints.d.ts +3 -3
- package/dist/resolution/select/constraints.js +4 -4
- package/package.json +14 -2
package/dist/errors/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ConstraintRequirement } from "
|
|
2
|
-
import type { BindingIdentifier, BindingScope, ResolveOptions } from "
|
|
1
|
+
import type { ConstraintRequirement } from "#core/constraint-requirement";
|
|
2
|
+
import type { BindingIdentifier, BindingScope, ResolveOptions } from "#core/types";
|
|
3
3
|
/**
|
|
4
4
|
* Base class for every error the library throws, each carrying a machine-readable `code`.
|
|
5
5
|
*
|
|
@@ -7,7 +7,7 @@ import type { BindingIdentifier, BindingScope, ResolveOptions } from "#/core/typ
|
|
|
7
7
|
*/
|
|
8
8
|
export declare abstract class DiError extends Error {
|
|
9
9
|
abstract readonly code: string;
|
|
10
|
-
|
|
10
|
+
abstract readonly name: string;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* An internal assertion failure — a library bug, never caller misuse.
|
|
@@ -15,6 +15,7 @@ export declare abstract class DiError extends Error {
|
|
|
15
15
|
* @since 0.3.16-canary.0
|
|
16
16
|
*/
|
|
17
17
|
export declare class InternalError extends DiError {
|
|
18
|
+
readonly name = "InternalError";
|
|
18
19
|
readonly code = "INTERNAL_ERROR";
|
|
19
20
|
constructor(message: string);
|
|
20
21
|
}
|
|
@@ -24,6 +25,7 @@ export declare class InternalError extends DiError {
|
|
|
24
25
|
* @since 0.3.16-canary.0
|
|
25
26
|
*/
|
|
26
27
|
export declare class TokenNotBoundError extends DiError {
|
|
28
|
+
readonly name = "TokenNotBoundError";
|
|
27
29
|
readonly code = "TOKEN_NOT_BOUND";
|
|
28
30
|
readonly tokenName: string;
|
|
29
31
|
constructor(tokenName: string);
|
|
@@ -34,6 +36,7 @@ export declare class TokenNotBoundError extends DiError {
|
|
|
34
36
|
* @since 0.3.16-canary.0
|
|
35
37
|
*/
|
|
36
38
|
export declare class NoMatchingBindingError extends DiError {
|
|
39
|
+
readonly name = "NoMatchingBindingError";
|
|
37
40
|
readonly code = "NO_MATCHING_BINDING";
|
|
38
41
|
readonly tokenName: string;
|
|
39
42
|
readonly options: ResolveOptions;
|
|
@@ -46,6 +49,7 @@ export declare class NoMatchingBindingError extends DiError {
|
|
|
46
49
|
* @since 0.3.16-canary.0
|
|
47
50
|
*/
|
|
48
51
|
export declare class AmbiguousBindingError extends DiError {
|
|
52
|
+
readonly name = "AmbiguousBindingError";
|
|
49
53
|
readonly code = "AMBIGUOUS_BINDING";
|
|
50
54
|
readonly tokenName: string;
|
|
51
55
|
readonly candidateIds: ReadonlyArray<BindingIdentifier>;
|
|
@@ -57,6 +61,7 @@ export declare class AmbiguousBindingError extends DiError {
|
|
|
57
61
|
* @since 0.3.16-canary.0
|
|
58
62
|
*/
|
|
59
63
|
export declare class CircularDependencyError extends DiError {
|
|
64
|
+
readonly name = "CircularDependencyError";
|
|
60
65
|
readonly code = "CIRCULAR_DEPENDENCY";
|
|
61
66
|
readonly cycle: Array<string>;
|
|
62
67
|
constructor(cycle: Array<string>);
|
|
@@ -67,6 +72,7 @@ export declare class CircularDependencyError extends DiError {
|
|
|
67
72
|
* @since 0.3.16-canary.0
|
|
68
73
|
*/
|
|
69
74
|
export declare class AsyncResolutionError extends DiError {
|
|
75
|
+
readonly name = "AsyncResolutionError";
|
|
70
76
|
readonly code = "ASYNC_RESOLUTION";
|
|
71
77
|
/** The token the caller asked for — what `resolveAsync` has to be called with. */
|
|
72
78
|
readonly tokenName: string;
|
|
@@ -80,6 +86,7 @@ export declare class AsyncResolutionError extends DiError {
|
|
|
80
86
|
* @since 0.3.16-canary.0
|
|
81
87
|
*/
|
|
82
88
|
export declare class AsyncDeactivationError extends DiError {
|
|
89
|
+
readonly name = "AsyncDeactivationError";
|
|
83
90
|
readonly code = "ASYNC_DEACTIVATION";
|
|
84
91
|
readonly tokenName: string;
|
|
85
92
|
constructor(tokenName: string);
|
|
@@ -102,6 +109,7 @@ export interface ScopeViolationDetails {
|
|
|
102
109
|
* @since 0.3.16-canary.0
|
|
103
110
|
*/
|
|
104
111
|
export declare class ScopeViolationError extends DiError {
|
|
112
|
+
readonly name = "ScopeViolationError";
|
|
105
113
|
readonly code = "SCOPE_VIOLATION";
|
|
106
114
|
readonly details: ScopeViolationDetails;
|
|
107
115
|
constructor(details: ScopeViolationDetails);
|
|
@@ -116,6 +124,7 @@ export declare class ScopeViolationError extends DiError {
|
|
|
116
124
|
* @since 0.6.0
|
|
117
125
|
*/
|
|
118
126
|
export declare class EmptyTagCriteriaError extends DiError {
|
|
127
|
+
readonly name = "EmptyTagCriteriaError";
|
|
119
128
|
readonly code = "EMPTY_TAG_CRITERIA";
|
|
120
129
|
readonly helperName: string;
|
|
121
130
|
constructor(helperName: string);
|
|
@@ -130,6 +139,7 @@ export declare class EmptyTagCriteriaError extends DiError {
|
|
|
130
139
|
* @since 0.6.0
|
|
131
140
|
*/
|
|
132
141
|
export declare class UnreachableConstraintError extends DiError {
|
|
142
|
+
readonly name = "UnreachableConstraintError";
|
|
133
143
|
readonly code = "UNREACHABLE_CONSTRAINT";
|
|
134
144
|
readonly tokenName: string;
|
|
135
145
|
readonly requiredName: string;
|
|
@@ -148,10 +158,13 @@ export declare class UnreachableConstraintError extends DiError {
|
|
|
148
158
|
* @since 0.6.0
|
|
149
159
|
*/
|
|
150
160
|
export declare class UnreachableLifecycleHookError extends DiError {
|
|
161
|
+
readonly name = "UnreachableLifecycleHookError";
|
|
151
162
|
readonly code = "UNREACHABLE_LIFECYCLE_HOOK";
|
|
152
163
|
readonly tokenName: string;
|
|
153
164
|
readonly phase: "onActivation" | "onDeactivation";
|
|
154
|
-
|
|
165
|
+
/** Nothing binds the token, or — for a deactivation hook — every binding it has is transient or scoped. */
|
|
166
|
+
readonly reason: "unbound" | "no-deactivatable-binding";
|
|
167
|
+
constructor(tokenName: string, phase: "onActivation" | "onDeactivation", reason?: "unbound" | "no-deactivatable-binding");
|
|
155
168
|
}
|
|
156
169
|
/**
|
|
157
170
|
* A {@link MetadataReader} described a class with something the container cannot use.
|
|
@@ -163,6 +176,7 @@ export declare class UnreachableLifecycleHookError extends DiError {
|
|
|
163
176
|
* @since 0.6.0
|
|
164
177
|
*/
|
|
165
178
|
export declare class InvalidMetadataError extends DiError {
|
|
179
|
+
readonly name = "InvalidMetadataError";
|
|
166
180
|
readonly code = "INVALID_METADATA";
|
|
167
181
|
readonly targetName: string;
|
|
168
182
|
readonly reason: string;
|
|
@@ -174,9 +188,13 @@ export declare class InvalidMetadataError extends DiError {
|
|
|
174
188
|
* @since 0.3.16-canary.0
|
|
175
189
|
*/
|
|
176
190
|
export declare class MissingMetadataError extends DiError {
|
|
191
|
+
readonly name = "MissingMetadataError";
|
|
177
192
|
readonly code = "MISSING_METADATA";
|
|
178
193
|
readonly targetName: string;
|
|
179
|
-
constructor(targetName: string
|
|
194
|
+
constructor(targetName: string, inheritedFrom?: {
|
|
195
|
+
readonly baseName: string;
|
|
196
|
+
readonly dependencyCount: number;
|
|
197
|
+
});
|
|
180
198
|
}
|
|
181
199
|
/**
|
|
182
200
|
* A sync `load()` given a module that needs async setup.
|
|
@@ -184,6 +202,7 @@ export declare class MissingMetadataError extends DiError {
|
|
|
184
202
|
* @since 0.3.16-canary.0
|
|
185
203
|
*/
|
|
186
204
|
export declare class AsyncModuleLoadError extends DiError {
|
|
205
|
+
readonly name = "AsyncModuleLoadError";
|
|
187
206
|
readonly code = "ASYNC_MODULE_LOAD";
|
|
188
207
|
readonly moduleName: string;
|
|
189
208
|
constructor(moduleName: string);
|
|
@@ -194,6 +213,7 @@ export declare class AsyncModuleLoadError extends DiError {
|
|
|
194
213
|
* @since 0.3.16-canary.0
|
|
195
214
|
*/
|
|
196
215
|
export declare class SyncDisposalNotSupportedError extends DiError {
|
|
216
|
+
readonly name = "SyncDisposalNotSupportedError";
|
|
197
217
|
readonly code = "SYNC_DISPOSAL_NOT_SUPPORTED";
|
|
198
218
|
constructor();
|
|
199
219
|
}
|
|
@@ -203,6 +223,7 @@ export declare class SyncDisposalNotSupportedError extends DiError {
|
|
|
203
223
|
* @since 0.3.16-canary.0
|
|
204
224
|
*/
|
|
205
225
|
export declare class MissingScopeContextError extends DiError {
|
|
226
|
+
readonly name = "MissingScopeContextError";
|
|
206
227
|
readonly code = "MISSING_SCOPE_CONTEXT";
|
|
207
228
|
readonly tokenName: string;
|
|
208
229
|
constructor(tokenName: string);
|
|
@@ -217,21 +238,13 @@ export declare class MissingScopeContextError extends DiError {
|
|
|
217
238
|
* @since 0.3.16-canary.0
|
|
218
239
|
*/
|
|
219
240
|
export declare class MissingContainerContextError extends DiError {
|
|
241
|
+
readonly name = "MissingContainerContextError";
|
|
220
242
|
readonly code = "MISSING_CONTAINER_CONTEXT";
|
|
221
243
|
/** The class being constructed, or `undefined` when it has no readable name. */
|
|
222
244
|
readonly className: string | undefined;
|
|
223
245
|
readonly accessorName: string | symbol;
|
|
224
246
|
constructor(className: string | undefined, accessorName: string | symbol);
|
|
225
247
|
}
|
|
226
|
-
/**
|
|
227
|
-
* A fluent chain was refined before a `to*()` call gave it a binding to refine.
|
|
228
|
-
*
|
|
229
|
-
* @remarks The builder types make this unreachable from TypeScript — `bind()` returns
|
|
230
|
-
* `BindToBuilder`, which exposes only `to*()`. It exists for JavaScript callers and for anyone who
|
|
231
|
-
* casts past the types, so the misuse fails loudly instead of mutating nothing.
|
|
232
|
-
*
|
|
233
|
-
* @since 0.5.0-canary.8
|
|
234
|
-
*/
|
|
235
248
|
/**
|
|
236
249
|
* A second `to*()` on a chain that already registered its binding.
|
|
237
250
|
*
|
|
@@ -241,6 +254,7 @@ export declare class MissingContainerContextError extends DiError {
|
|
|
241
254
|
* @since 0.10.0
|
|
242
255
|
*/
|
|
243
256
|
export declare class ChainAlreadyRegisteredError extends DiError {
|
|
257
|
+
readonly name = "ChainAlreadyRegisteredError";
|
|
244
258
|
readonly code = "CHAIN_ALREADY_REGISTERED";
|
|
245
259
|
readonly tokenName: string;
|
|
246
260
|
constructor(tokenName: string);
|
|
@@ -254,14 +268,22 @@ export declare class ChainAlreadyRegisteredError extends DiError {
|
|
|
254
268
|
* @since 0.10.0
|
|
255
269
|
*/
|
|
256
270
|
export declare class ManyBindingSlotError extends DiError {
|
|
271
|
+
readonly name = "ManyBindingSlotError";
|
|
257
272
|
readonly code = "MANY_BINDING_SLOT";
|
|
258
273
|
readonly tokenName: string;
|
|
259
274
|
constructor(tokenName: string);
|
|
260
275
|
}
|
|
261
276
|
/**
|
|
277
|
+
* A fluent chain was refined before a `to*()` call gave it a binding to refine.
|
|
278
|
+
*
|
|
279
|
+
* @remarks The builder types make this unreachable from TypeScript — `bind()` returns
|
|
280
|
+
* `BindToBuilder`, which exposes only `to*()`. It exists for JavaScript callers and for anyone who
|
|
281
|
+
* casts past the types, so the misuse fails loudly instead of mutating nothing.
|
|
282
|
+
*
|
|
262
283
|
* @since 0.10.0
|
|
263
284
|
*/
|
|
264
285
|
export declare class ChainNotRegisteredError extends DiError {
|
|
286
|
+
readonly name = "ChainNotRegisteredError";
|
|
265
287
|
readonly code = "CHAIN_NOT_REGISTERED";
|
|
266
288
|
readonly tokenName: string;
|
|
267
289
|
constructor(tokenName: string);
|
|
@@ -272,6 +294,7 @@ export declare class ChainNotRegisteredError extends DiError {
|
|
|
272
294
|
* @since 0.3.16-canary.0
|
|
273
295
|
*/
|
|
274
296
|
export declare class RebindUnboundTokenError extends DiError {
|
|
297
|
+
readonly name = "RebindUnboundTokenError";
|
|
275
298
|
readonly code = "REBIND_UNBOUND_TOKEN";
|
|
276
299
|
readonly tokenName: string;
|
|
277
300
|
constructor(tokenName: string);
|
|
@@ -282,6 +305,7 @@ export declare class RebindUnboundTokenError extends DiError {
|
|
|
282
305
|
* @since 0.5.0-canary.9
|
|
283
306
|
*/
|
|
284
307
|
export declare class SelfBindingRequiresClassError extends DiError {
|
|
308
|
+
readonly name = "SelfBindingRequiresClassError";
|
|
285
309
|
readonly code = "SELF_BINDING_REQUIRES_CLASS";
|
|
286
310
|
readonly tokenName: string;
|
|
287
311
|
constructor(tokenName: string);
|
|
@@ -296,17 +320,63 @@ export declare class SelfBindingRequiresClassError extends DiError {
|
|
|
296
320
|
* @since 0.6.0
|
|
297
321
|
*/
|
|
298
322
|
export declare class StaticMemberDecoratorError extends DiError {
|
|
323
|
+
readonly name = "StaticMemberDecoratorError";
|
|
299
324
|
readonly code = "STATIC_MEMBER_DECORATOR";
|
|
300
325
|
readonly decoratorName: string;
|
|
301
326
|
readonly memberName: string;
|
|
302
327
|
constructor(decoratorName: string, memberName: string);
|
|
303
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* A `@postConstruct` or `@preDestroy` on a method whose key is a symbol, which the lifecycle reader cannot name.
|
|
331
|
+
*
|
|
332
|
+
* @remarks Reported at decoration rather than at resolve, so the error points at the declaration
|
|
333
|
+
* instead of a `MetadataReader` the caller never configured.
|
|
334
|
+
*
|
|
335
|
+
* @since 0.11.0
|
|
336
|
+
*/
|
|
337
|
+
export declare class SymbolKeyedLifecycleError extends DiError {
|
|
338
|
+
readonly name = "SymbolKeyedLifecycleError";
|
|
339
|
+
readonly code = "SYMBOL_KEYED_LIFECYCLE";
|
|
340
|
+
readonly decoratorName: string;
|
|
341
|
+
readonly memberName: string;
|
|
342
|
+
constructor(decoratorName: string, memberName: string);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* A decorator handed no metadata object, because the runtime has no `Symbol.metadata` to key one by.
|
|
346
|
+
*
|
|
347
|
+
* @remarks TypeScript compiles `context.metadata` to `undefined` when `Symbol.metadata` is missing, so
|
|
348
|
+
* the fix is installing it before any decorated class is defined — the key this library reads.
|
|
349
|
+
*
|
|
350
|
+
* @since 0.11.0
|
|
351
|
+
*/
|
|
352
|
+
export declare class MissingDecoratorMetadataError extends DiError {
|
|
353
|
+
readonly name = "MissingDecoratorMetadataError";
|
|
354
|
+
readonly code = "MISSING_DECORATOR_METADATA";
|
|
355
|
+
readonly decoratorName: string;
|
|
356
|
+
constructor(decoratorName: string);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* A `binding()` definition no chain could spell: no strategy, several, or a key its strategy does not allow.
|
|
360
|
+
*
|
|
361
|
+
* @remarks Raised where the declaration is written, for callers the compiler cannot reach, so a
|
|
362
|
+
* declared module that was built can always be loaded.
|
|
363
|
+
*
|
|
364
|
+
* @since 0.11.0
|
|
365
|
+
*/
|
|
366
|
+
export declare class InvalidBindingDeclarationError extends DiError {
|
|
367
|
+
readonly name = "InvalidBindingDeclarationError";
|
|
368
|
+
readonly code = "INVALID_BINDING_DECLARATION";
|
|
369
|
+
readonly tokenName: string;
|
|
370
|
+
readonly reason: string;
|
|
371
|
+
constructor(tokenName: string, reason: string);
|
|
372
|
+
}
|
|
304
373
|
/**
|
|
305
374
|
* An operation attempted on a container that has already been disposed.
|
|
306
375
|
*
|
|
307
376
|
* @since 0.3.16-canary.0
|
|
308
377
|
*/
|
|
309
378
|
export declare class DisposedContainerError extends DiError {
|
|
379
|
+
readonly name = "DisposedContainerError";
|
|
310
380
|
readonly code = "DISPOSED_CONTAINER";
|
|
311
381
|
constructor();
|
|
312
382
|
}
|
|
@@ -316,6 +386,7 @@ export declare class DisposedContainerError extends DiError {
|
|
|
316
386
|
* @since 0.3.16-canary.0
|
|
317
387
|
*/
|
|
318
388
|
export declare class AsyncActivationError extends DiError {
|
|
389
|
+
readonly name = "AsyncActivationError";
|
|
319
390
|
readonly code = "ASYNC_ACTIVATION";
|
|
320
391
|
readonly tokenName: string;
|
|
321
392
|
readonly hookKind: "postConstruct" | "onActivation";
|
package/dist/errors/errors.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { slotName } from "
|
|
1
|
+
import { slotName } from "#core/tag";
|
|
2
2
|
/**
|
|
3
3
|
* Base class for every error the library throws, each carrying a machine-readable `code`.
|
|
4
4
|
*
|
|
5
5
|
* @since 0.3.16-canary.0
|
|
6
6
|
*/
|
|
7
7
|
export class DiError extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = this.constructor.name;
|
|
11
|
-
}
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* An internal assertion failure — a library bug, never caller misuse.
|
|
@@ -16,6 +12,7 @@ export class DiError extends Error {
|
|
|
16
12
|
* @since 0.3.16-canary.0
|
|
17
13
|
*/
|
|
18
14
|
export class InternalError extends DiError {
|
|
15
|
+
name = "InternalError";
|
|
19
16
|
code = "INTERNAL_ERROR";
|
|
20
17
|
constructor(message) {
|
|
21
18
|
super(message);
|
|
@@ -27,6 +24,7 @@ export class InternalError extends DiError {
|
|
|
27
24
|
* @since 0.3.16-canary.0
|
|
28
25
|
*/
|
|
29
26
|
export class TokenNotBoundError extends DiError {
|
|
27
|
+
name = "TokenNotBoundError";
|
|
30
28
|
code = "TOKEN_NOT_BOUND";
|
|
31
29
|
tokenName;
|
|
32
30
|
constructor(tokenName) {
|
|
@@ -75,6 +73,7 @@ function describeResolveOptions(options) {
|
|
|
75
73
|
* @since 0.3.16-canary.0
|
|
76
74
|
*/
|
|
77
75
|
export class NoMatchingBindingError extends DiError {
|
|
76
|
+
name = "NoMatchingBindingError";
|
|
78
77
|
code = "NO_MATCHING_BINDING";
|
|
79
78
|
tokenName;
|
|
80
79
|
options;
|
|
@@ -94,6 +93,7 @@ export class NoMatchingBindingError extends DiError {
|
|
|
94
93
|
* @since 0.3.16-canary.0
|
|
95
94
|
*/
|
|
96
95
|
export class AmbiguousBindingError extends DiError {
|
|
96
|
+
name = "AmbiguousBindingError";
|
|
97
97
|
code = "AMBIGUOUS_BINDING";
|
|
98
98
|
tokenName;
|
|
99
99
|
candidateIds;
|
|
@@ -109,6 +109,7 @@ export class AmbiguousBindingError extends DiError {
|
|
|
109
109
|
* @since 0.3.16-canary.0
|
|
110
110
|
*/
|
|
111
111
|
export class CircularDependencyError extends DiError {
|
|
112
|
+
name = "CircularDependencyError";
|
|
112
113
|
code = "CIRCULAR_DEPENDENCY";
|
|
113
114
|
cycle;
|
|
114
115
|
constructor(cycle) {
|
|
@@ -122,6 +123,7 @@ export class CircularDependencyError extends DiError {
|
|
|
122
123
|
* @since 0.3.16-canary.0
|
|
123
124
|
*/
|
|
124
125
|
export class AsyncResolutionError extends DiError {
|
|
126
|
+
name = "AsyncResolutionError";
|
|
125
127
|
code = "ASYNC_RESOLUTION";
|
|
126
128
|
/** The token the caller asked for — what `resolveAsync` has to be called with. */
|
|
127
129
|
tokenName;
|
|
@@ -141,6 +143,7 @@ export class AsyncResolutionError extends DiError {
|
|
|
141
143
|
* @since 0.3.16-canary.0
|
|
142
144
|
*/
|
|
143
145
|
export class AsyncDeactivationError extends DiError {
|
|
146
|
+
name = "AsyncDeactivationError";
|
|
144
147
|
code = "ASYNC_DEACTIVATION";
|
|
145
148
|
tokenName;
|
|
146
149
|
constructor(tokenName) {
|
|
@@ -154,6 +157,7 @@ export class AsyncDeactivationError extends DiError {
|
|
|
154
157
|
* @since 0.3.16-canary.0
|
|
155
158
|
*/
|
|
156
159
|
export class ScopeViolationError extends DiError {
|
|
160
|
+
name = "ScopeViolationError";
|
|
157
161
|
code = "SCOPE_VIOLATION";
|
|
158
162
|
details;
|
|
159
163
|
constructor(details) {
|
|
@@ -171,6 +175,7 @@ export class ScopeViolationError extends DiError {
|
|
|
171
175
|
* @since 0.6.0
|
|
172
176
|
*/
|
|
173
177
|
export class EmptyTagCriteriaError extends DiError {
|
|
178
|
+
name = "EmptyTagCriteriaError";
|
|
174
179
|
code = "EMPTY_TAG_CRITERIA";
|
|
175
180
|
helperName;
|
|
176
181
|
constructor(helperName) {
|
|
@@ -188,6 +193,7 @@ export class EmptyTagCriteriaError extends DiError {
|
|
|
188
193
|
* @since 0.6.0
|
|
189
194
|
*/
|
|
190
195
|
export class UnreachableConstraintError extends DiError {
|
|
196
|
+
name = "UnreachableConstraintError";
|
|
191
197
|
code = "UNREACHABLE_CONSTRAINT";
|
|
192
198
|
tokenName;
|
|
193
199
|
requiredName;
|
|
@@ -215,13 +221,19 @@ export class UnreachableConstraintError extends DiError {
|
|
|
215
221
|
* @since 0.6.0
|
|
216
222
|
*/
|
|
217
223
|
export class UnreachableLifecycleHookError extends DiError {
|
|
224
|
+
name = "UnreachableLifecycleHookError";
|
|
218
225
|
code = "UNREACHABLE_LIFECYCLE_HOOK";
|
|
219
226
|
tokenName;
|
|
220
227
|
phase;
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
/** Nothing binds the token, or — for a deactivation hook — every binding it has is transient or scoped. */
|
|
229
|
+
reason;
|
|
230
|
+
constructor(tokenName, phase, reason = "unbound") {
|
|
231
|
+
super(reason === "unbound"
|
|
232
|
+
? `${phase}() is registered for '${tokenName}', which nothing is bound to in this container or its ancestors, so the hook can never run. Bind the token, or — if '${tokenName}' is a class you bound as an implementation via .to(${tokenName}) — register the hook against the token you bound instead.`
|
|
233
|
+
: `${phase}() is registered for '${tokenName}', whose every binding in this container and its ancestors is transient or scoped, so the hook can never run: only a singleton or a constant is deactivated. Make one of its bindings a singleton, or drop the hook.`);
|
|
223
234
|
this.tokenName = tokenName;
|
|
224
235
|
this.phase = phase;
|
|
236
|
+
this.reason = reason;
|
|
225
237
|
}
|
|
226
238
|
}
|
|
227
239
|
/**
|
|
@@ -234,6 +246,7 @@ export class UnreachableLifecycleHookError extends DiError {
|
|
|
234
246
|
* @since 0.6.0
|
|
235
247
|
*/
|
|
236
248
|
export class InvalidMetadataError extends DiError {
|
|
249
|
+
name = "InvalidMetadataError";
|
|
237
250
|
code = "INVALID_METADATA";
|
|
238
251
|
targetName;
|
|
239
252
|
reason;
|
|
@@ -249,10 +262,13 @@ export class InvalidMetadataError extends DiError {
|
|
|
249
262
|
* @since 0.3.16-canary.0
|
|
250
263
|
*/
|
|
251
264
|
export class MissingMetadataError extends DiError {
|
|
265
|
+
name = "MissingMetadataError";
|
|
252
266
|
code = "MISSING_METADATA";
|
|
253
267
|
targetName;
|
|
254
|
-
constructor(targetName) {
|
|
255
|
-
super(
|
|
268
|
+
constructor(targetName, inheritedFrom) {
|
|
269
|
+
super(inheritedFrom === undefined
|
|
270
|
+
? `Class '${targetName}' is missing @injectable() decorator. Add @injectable([...deps]) or use toDynamic()/toResolved() instead.`
|
|
271
|
+
: `Class '${targetName}' inherits ${String(inheritedFrom.dependencyCount)} declared constructor ${inheritedFrom.dependencyCount === 1 ? "dependency" : "dependencies"} from '${inheritedFrom.baseName}' but declares none of its own. Add @injectable([...deps]) to '${targetName}' — @injectable([]) if it takes none — or bind it with toDynamic()/toResolved().`);
|
|
256
272
|
this.targetName = targetName;
|
|
257
273
|
}
|
|
258
274
|
}
|
|
@@ -262,6 +278,7 @@ export class MissingMetadataError extends DiError {
|
|
|
262
278
|
* @since 0.3.16-canary.0
|
|
263
279
|
*/
|
|
264
280
|
export class AsyncModuleLoadError extends DiError {
|
|
281
|
+
name = "AsyncModuleLoadError";
|
|
265
282
|
code = "ASYNC_MODULE_LOAD";
|
|
266
283
|
moduleName;
|
|
267
284
|
constructor(moduleName) {
|
|
@@ -275,6 +292,7 @@ export class AsyncModuleLoadError extends DiError {
|
|
|
275
292
|
* @since 0.3.16-canary.0
|
|
276
293
|
*/
|
|
277
294
|
export class SyncDisposalNotSupportedError extends DiError {
|
|
295
|
+
name = "SyncDisposalNotSupportedError";
|
|
278
296
|
code = "SYNC_DISPOSAL_NOT_SUPPORTED";
|
|
279
297
|
constructor() {
|
|
280
298
|
super("Container cannot be disposed synchronously because onDeactivation handlers may be async. Use `await using` or call container.dispose() explicitly.");
|
|
@@ -286,6 +304,7 @@ export class SyncDisposalNotSupportedError extends DiError {
|
|
|
286
304
|
* @since 0.3.16-canary.0
|
|
287
305
|
*/
|
|
288
306
|
export class MissingScopeContextError extends DiError {
|
|
307
|
+
name = "MissingScopeContextError";
|
|
289
308
|
code = "MISSING_SCOPE_CONTEXT";
|
|
290
309
|
tokenName;
|
|
291
310
|
constructor(tokenName) {
|
|
@@ -303,6 +322,7 @@ export class MissingScopeContextError extends DiError {
|
|
|
303
322
|
* @since 0.3.16-canary.0
|
|
304
323
|
*/
|
|
305
324
|
export class MissingContainerContextError extends DiError {
|
|
325
|
+
name = "MissingContainerContextError";
|
|
306
326
|
code = "MISSING_CONTAINER_CONTEXT";
|
|
307
327
|
/** The class being constructed, or `undefined` when it has no readable name. */
|
|
308
328
|
className;
|
|
@@ -310,21 +330,12 @@ export class MissingContainerContextError extends DiError {
|
|
|
310
330
|
constructor(className, accessorName) {
|
|
311
331
|
const accessor = `@inject accessor '${String(accessorName)}'`;
|
|
312
332
|
super(className === undefined
|
|
313
|
-
? `An ${accessor} was initialized outside a container context. Resolve its class through a container, or open a context with runWithContainer().`
|
|
314
|
-
: `Class '${className}' has an ${accessor} but was constructed outside a container context. Resolve it via container.resolve(${className}), or open a context with runWithContainer().`);
|
|
333
|
+
? `An ${accessor} was initialized outside a container context. Resolve its class through a container, or open a synchronous context with runWithContainer() (the context does not survive an await).`
|
|
334
|
+
: `Class '${className}' has an ${accessor} but was constructed outside a container context. Resolve it via container.resolve(${className}), or open a synchronous context with runWithContainer() (the context does not survive an await).`);
|
|
315
335
|
this.className = className;
|
|
316
336
|
this.accessorName = accessorName;
|
|
317
337
|
}
|
|
318
338
|
}
|
|
319
|
-
/**
|
|
320
|
-
* A fluent chain was refined before a `to*()` call gave it a binding to refine.
|
|
321
|
-
*
|
|
322
|
-
* @remarks The builder types make this unreachable from TypeScript — `bind()` returns
|
|
323
|
-
* `BindToBuilder`, which exposes only `to*()`. It exists for JavaScript callers and for anyone who
|
|
324
|
-
* casts past the types, so the misuse fails loudly instead of mutating nothing.
|
|
325
|
-
*
|
|
326
|
-
* @since 0.5.0-canary.8
|
|
327
|
-
*/
|
|
328
339
|
/**
|
|
329
340
|
* A second `to*()` on a chain that already registered its binding.
|
|
330
341
|
*
|
|
@@ -334,6 +345,7 @@ export class MissingContainerContextError extends DiError {
|
|
|
334
345
|
* @since 0.10.0
|
|
335
346
|
*/
|
|
336
347
|
export class ChainAlreadyRegisteredError extends DiError {
|
|
348
|
+
name = "ChainAlreadyRegisteredError";
|
|
337
349
|
code = "CHAIN_ALREADY_REGISTERED";
|
|
338
350
|
tokenName;
|
|
339
351
|
constructor(tokenName) {
|
|
@@ -350,6 +362,7 @@ export class ChainAlreadyRegisteredError extends DiError {
|
|
|
350
362
|
* @since 0.10.0
|
|
351
363
|
*/
|
|
352
364
|
export class ManyBindingSlotError extends DiError {
|
|
365
|
+
name = "ManyBindingSlotError";
|
|
353
366
|
code = "MANY_BINDING_SLOT";
|
|
354
367
|
tokenName;
|
|
355
368
|
constructor(tokenName) {
|
|
@@ -358,9 +371,16 @@ export class ManyBindingSlotError extends DiError {
|
|
|
358
371
|
}
|
|
359
372
|
}
|
|
360
373
|
/**
|
|
374
|
+
* A fluent chain was refined before a `to*()` call gave it a binding to refine.
|
|
375
|
+
*
|
|
376
|
+
* @remarks The builder types make this unreachable from TypeScript — `bind()` returns
|
|
377
|
+
* `BindToBuilder`, which exposes only `to*()`. It exists for JavaScript callers and for anyone who
|
|
378
|
+
* casts past the types, so the misuse fails loudly instead of mutating nothing.
|
|
379
|
+
*
|
|
361
380
|
* @since 0.10.0
|
|
362
381
|
*/
|
|
363
382
|
export class ChainNotRegisteredError extends DiError {
|
|
383
|
+
name = "ChainNotRegisteredError";
|
|
364
384
|
code = "CHAIN_NOT_REGISTERED";
|
|
365
385
|
tokenName;
|
|
366
386
|
constructor(tokenName) {
|
|
@@ -374,6 +394,7 @@ export class ChainNotRegisteredError extends DiError {
|
|
|
374
394
|
* @since 0.3.16-canary.0
|
|
375
395
|
*/
|
|
376
396
|
export class RebindUnboundTokenError extends DiError {
|
|
397
|
+
name = "RebindUnboundTokenError";
|
|
377
398
|
code = "REBIND_UNBOUND_TOKEN";
|
|
378
399
|
tokenName;
|
|
379
400
|
constructor(tokenName) {
|
|
@@ -387,6 +408,7 @@ export class RebindUnboundTokenError extends DiError {
|
|
|
387
408
|
* @since 0.5.0-canary.9
|
|
388
409
|
*/
|
|
389
410
|
export class SelfBindingRequiresClassError extends DiError {
|
|
411
|
+
name = "SelfBindingRequiresClassError";
|
|
390
412
|
code = "SELF_BINDING_REQUIRES_CLASS";
|
|
391
413
|
tokenName;
|
|
392
414
|
constructor(tokenName) {
|
|
@@ -404,6 +426,7 @@ export class SelfBindingRequiresClassError extends DiError {
|
|
|
404
426
|
* @since 0.6.0
|
|
405
427
|
*/
|
|
406
428
|
export class StaticMemberDecoratorError extends DiError {
|
|
429
|
+
name = "StaticMemberDecoratorError";
|
|
407
430
|
code = "STATIC_MEMBER_DECORATOR";
|
|
408
431
|
decoratorName;
|
|
409
432
|
memberName;
|
|
@@ -413,12 +436,68 @@ export class StaticMemberDecoratorError extends DiError {
|
|
|
413
436
|
this.memberName = memberName;
|
|
414
437
|
}
|
|
415
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* A `@postConstruct` or `@preDestroy` on a method whose key is a symbol, which the lifecycle reader cannot name.
|
|
441
|
+
*
|
|
442
|
+
* @remarks Reported at decoration rather than at resolve, so the error points at the declaration
|
|
443
|
+
* instead of a `MetadataReader` the caller never configured.
|
|
444
|
+
*
|
|
445
|
+
* @since 0.11.0
|
|
446
|
+
*/
|
|
447
|
+
export class SymbolKeyedLifecycleError extends DiError {
|
|
448
|
+
name = "SymbolKeyedLifecycleError";
|
|
449
|
+
code = "SYMBOL_KEYED_LIFECYCLE";
|
|
450
|
+
decoratorName;
|
|
451
|
+
memberName;
|
|
452
|
+
constructor(decoratorName, memberName) {
|
|
453
|
+
super(`@${decoratorName}() does not support a symbol-keyed method ('${memberName}'). Give the lifecycle method a string name.`);
|
|
454
|
+
this.decoratorName = decoratorName;
|
|
455
|
+
this.memberName = memberName;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* A decorator handed no metadata object, because the runtime has no `Symbol.metadata` to key one by.
|
|
460
|
+
*
|
|
461
|
+
* @remarks TypeScript compiles `context.metadata` to `undefined` when `Symbol.metadata` is missing, so
|
|
462
|
+
* the fix is installing it before any decorated class is defined — the key this library reads.
|
|
463
|
+
*
|
|
464
|
+
* @since 0.11.0
|
|
465
|
+
*/
|
|
466
|
+
export class MissingDecoratorMetadataError extends DiError {
|
|
467
|
+
name = "MissingDecoratorMetadataError";
|
|
468
|
+
code = "MISSING_DECORATOR_METADATA";
|
|
469
|
+
decoratorName;
|
|
470
|
+
constructor(decoratorName) {
|
|
471
|
+
super(`@${decoratorName}() received no decorator metadata: this runtime has no Symbol.metadata. Install it before any decorated class is defined, e.g. in a module imported first: (Symbol as { metadata?: symbol }).metadata ??= Symbol.for("Symbol.metadata");`);
|
|
472
|
+
this.decoratorName = decoratorName;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* A `binding()` definition no chain could spell: no strategy, several, or a key its strategy does not allow.
|
|
477
|
+
*
|
|
478
|
+
* @remarks Raised where the declaration is written, for callers the compiler cannot reach, so a
|
|
479
|
+
* declared module that was built can always be loaded.
|
|
480
|
+
*
|
|
481
|
+
* @since 0.11.0
|
|
482
|
+
*/
|
|
483
|
+
export class InvalidBindingDeclarationError extends DiError {
|
|
484
|
+
name = "InvalidBindingDeclarationError";
|
|
485
|
+
code = "INVALID_BINDING_DECLARATION";
|
|
486
|
+
tokenName;
|
|
487
|
+
reason;
|
|
488
|
+
constructor(tokenName, reason) {
|
|
489
|
+
super(`Invalid binding declaration for '${tokenName}': ${reason}.`);
|
|
490
|
+
this.tokenName = tokenName;
|
|
491
|
+
this.reason = reason;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
416
494
|
/**
|
|
417
495
|
* An operation attempted on a container that has already been disposed.
|
|
418
496
|
*
|
|
419
497
|
* @since 0.3.16-canary.0
|
|
420
498
|
*/
|
|
421
499
|
export class DisposedContainerError extends DiError {
|
|
500
|
+
name = "DisposedContainerError";
|
|
422
501
|
code = "DISPOSED_CONTAINER";
|
|
423
502
|
constructor() {
|
|
424
503
|
super("Cannot perform operations on a disposed container.");
|
|
@@ -430,6 +509,7 @@ export class DisposedContainerError extends DiError {
|
|
|
430
509
|
* @since 0.3.16-canary.0
|
|
431
510
|
*/
|
|
432
511
|
export class AsyncActivationError extends DiError {
|
|
512
|
+
name = "AsyncActivationError";
|
|
433
513
|
code = "ASYNC_ACTIVATION";
|
|
434
514
|
tokenName;
|
|
435
515
|
hookKind;
|