@codefast/di 0.3.16-canary.0 → 0.3.16-canary.2
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 +12 -0
- package/README.md +8 -5
- package/dist/binding-select.d.mts +2 -2
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +12 -12
- package/dist/binding.mjs +8 -8
- package/dist/constraints.d.mts +25 -9
- package/dist/constraints.mjs +47 -19
- package/dist/constructor-type.d.mts +2 -2
- package/dist/container.d.mts +6 -6
- package/dist/container.mjs +202 -121
- package/dist/decorators/inject.d.mts +4 -4
- package/dist/decorators/inject.mjs +21 -19
- package/dist/decorators/injectable.d.mts +1 -1
- package/dist/decorators/injectable.mjs +18 -14
- package/dist/decorators/lifecycle-decorators.mjs +3 -0
- package/dist/dependency-graph.d.mts +2 -2
- package/dist/dependency-graph.mjs +13 -13
- package/dist/environment.d.mts +17 -17
- package/dist/environment.mjs +21 -21
- package/dist/errors.d.mts +18 -8
- package/dist/errors.mjs +17 -1
- package/dist/graph-adapters/reactflow.d.mts +2 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +5 -4
- package/dist/inspector.d.mts +2 -3
- package/dist/inspector.mjs +18 -16
- package/dist/lifecycle.d.mts +5 -6
- package/dist/lifecycle.mjs +45 -52
- package/dist/metadata/metadata-keys.d.mts +24 -1
- package/dist/metadata/metadata-keys.mjs +14 -1
- package/dist/metadata/metadata-types.d.mts +5 -5
- package/dist/metadata/symbol-metadata-reader.mjs +31 -24
- package/dist/module.d.mts +2 -2
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +6 -6
- package/dist/registry.mjs +55 -62
- package/dist/resolve-options.d.mts +5 -5
- package/dist/resolve-options.mjs +8 -8
- package/dist/resolver.d.mts +22 -10
- package/dist/resolver.mjs +206 -185
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +12 -8
- package/package.json +15 -8
package/dist/container.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
2
|
-
import { DisposedContainerError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError } from "./errors.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { AsyncModuleLoadError, CircularDependencyError, DisposedContainerError, InternalError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError } from "./errors.mjs";
|
|
3
|
+
import { DEFAULT_BINDING_SLOT, generateBindingId } from "./binding.mjs";
|
|
4
4
|
import { tokenName } from "./token.mjs";
|
|
5
5
|
import { BindingRegistry } from "./registry.mjs";
|
|
6
6
|
import { ScopeManager } from "./scope.mjs";
|
|
7
7
|
import { LifecycleManager } from "./lifecycle.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
9
9
|
import { DependencyResolver } from "./resolver.mjs";
|
|
10
10
|
import { Inspector } from "./inspector.mjs";
|
|
11
11
|
import { buildDependencyGraph } from "./dependency-graph.mjs";
|
|
@@ -53,7 +53,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
53
53
|
}
|
|
54
54
|
_createBindToBuilder(token, moduleRef) {
|
|
55
55
|
const registry = this._registry;
|
|
56
|
-
const commitBinding = (
|
|
56
|
+
const commitBinding = (binding, previousId) => {
|
|
57
57
|
if (previousId !== void 0) {
|
|
58
58
|
registry.removeById(previousId);
|
|
59
59
|
if (moduleRef !== void 0) {
|
|
@@ -64,18 +64,18 @@ var DefaultContainer = class DefaultContainer {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
registry.add(
|
|
67
|
+
registry.add(binding);
|
|
68
68
|
if (moduleRef !== void 0) {
|
|
69
69
|
let ids = this._moduleBindingIds.get(moduleRef);
|
|
70
70
|
if (ids === void 0) {
|
|
71
71
|
ids = [];
|
|
72
72
|
this._moduleBindingIds.set(moduleRef, ids);
|
|
73
73
|
}
|
|
74
|
-
ids.push(
|
|
74
|
+
ids.push(binding.id);
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return binding.id;
|
|
77
77
|
};
|
|
78
|
-
return new
|
|
78
|
+
return new BindingEntry(token, commitBinding);
|
|
79
79
|
}
|
|
80
80
|
unbind(tokenOrId) {
|
|
81
81
|
this._assertNotDisposed();
|
|
@@ -130,8 +130,8 @@ var DefaultContainer = class DefaultContainer {
|
|
|
130
130
|
}
|
|
131
131
|
_getBindingsForTokenOrId(tokenOrId) {
|
|
132
132
|
if (typeof tokenOrId === "string") {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
133
|
+
const binding = this._registry.getById(tokenOrId);
|
|
134
|
+
return binding !== void 0 ? [binding] : [];
|
|
135
135
|
}
|
|
136
136
|
return [...this._registry.getAll(tokenOrId)];
|
|
137
137
|
}
|
|
@@ -141,71 +141,72 @@ var DefaultContainer = class DefaultContainer {
|
|
|
141
141
|
}
|
|
142
142
|
_loadSyncModules(modules) {
|
|
143
143
|
const toLoad = this._collectModuleDeps(modules);
|
|
144
|
-
for (const
|
|
145
|
-
|
|
146
|
-
const
|
|
144
|
+
for (const module of toLoad) {
|
|
145
|
+
if (!isSyncModule(module)) throw new AsyncModuleLoadError(module.name);
|
|
146
|
+
const moduleRef = module;
|
|
147
|
+
const existing = this._moduleRefs.get(moduleRef);
|
|
147
148
|
if (existing !== void 0) {
|
|
148
|
-
this._moduleRefs.set(
|
|
149
|
+
this._moduleRefs.set(moduleRef, existing + 1);
|
|
149
150
|
continue;
|
|
150
151
|
}
|
|
151
|
-
this._moduleRefs.set(
|
|
152
|
-
const builder = this._createModuleBuilder(
|
|
153
|
-
|
|
152
|
+
this._moduleRefs.set(moduleRef, 1);
|
|
153
|
+
const builder = this._createModuleBuilder(moduleRef);
|
|
154
|
+
module._setup(builder);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
_collectModuleDeps(modules) {
|
|
157
158
|
const seen = /* @__PURE__ */ new Set();
|
|
158
159
|
const result = [];
|
|
159
|
-
const visit = (
|
|
160
|
-
const
|
|
161
|
-
if (seen.has(
|
|
162
|
-
seen.add(
|
|
163
|
-
result.push(
|
|
160
|
+
const visit = (module) => {
|
|
161
|
+
const moduleRef = module;
|
|
162
|
+
if (seen.has(moduleRef)) return;
|
|
163
|
+
seen.add(moduleRef);
|
|
164
|
+
result.push(module);
|
|
164
165
|
};
|
|
165
|
-
for (const
|
|
166
|
+
for (const module of modules) visit(module);
|
|
166
167
|
return result;
|
|
167
168
|
}
|
|
168
169
|
async loadAsync(...modules) {
|
|
169
170
|
this._assertNotDisposed();
|
|
170
|
-
for (const
|
|
171
|
+
for (const module of modules) await this._loadOneModuleAsync(module);
|
|
171
172
|
}
|
|
172
|
-
async _loadOneModuleAsync(
|
|
173
|
-
const
|
|
174
|
-
const existing = this._moduleRefs.get(
|
|
173
|
+
async _loadOneModuleAsync(module) {
|
|
174
|
+
const moduleRef = module;
|
|
175
|
+
const existing = this._moduleRefs.get(moduleRef);
|
|
175
176
|
if (existing !== void 0) {
|
|
176
|
-
this._moduleRefs.set(
|
|
177
|
+
this._moduleRefs.set(moduleRef, existing + 1);
|
|
177
178
|
return;
|
|
178
179
|
}
|
|
179
|
-
this._moduleRefs.set(
|
|
180
|
-
if (isSyncModule(
|
|
181
|
-
const builder = this._createModuleBuilder(
|
|
182
|
-
|
|
180
|
+
this._moduleRefs.set(moduleRef, 1);
|
|
181
|
+
if (isSyncModule(module)) {
|
|
182
|
+
const builder = this._createModuleBuilder(moduleRef);
|
|
183
|
+
module._setup(builder);
|
|
183
184
|
} else {
|
|
184
185
|
const importPromises = [];
|
|
185
|
-
const builder = this._createAsyncModuleBuilder(
|
|
186
|
-
await
|
|
186
|
+
const builder = this._createAsyncModuleBuilder(moduleRef, importPromises);
|
|
187
|
+
await module._setup(builder);
|
|
187
188
|
if (importPromises.length > 0) await Promise.all(importPromises);
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
_createModuleBuilder(moduleRef) {
|
|
191
192
|
return {
|
|
192
|
-
bind: (
|
|
193
|
-
import: (...
|
|
194
|
-
this._loadSyncModules(
|
|
193
|
+
bind: (token) => this._createBindToBuilder(token, moduleRef),
|
|
194
|
+
import: (...modules) => {
|
|
195
|
+
this._loadSyncModules(modules);
|
|
195
196
|
}
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
199
|
_createAsyncModuleBuilder(moduleRef, importPromises) {
|
|
199
200
|
return {
|
|
200
|
-
bind: (
|
|
201
|
-
import: (...
|
|
202
|
-
for (const
|
|
201
|
+
bind: (token) => this._createBindToBuilder(token, moduleRef),
|
|
202
|
+
import: (...modules) => {
|
|
203
|
+
for (const module of modules) importPromises.push(this._loadOneModuleAsync(module));
|
|
203
204
|
}
|
|
204
205
|
};
|
|
205
206
|
}
|
|
206
207
|
unload(...modules) {
|
|
207
208
|
this._assertNotDisposed();
|
|
208
|
-
for (const
|
|
209
|
+
for (const module of modules) this._unloadModuleSync(module);
|
|
209
210
|
}
|
|
210
211
|
_unloadModuleSync(ref) {
|
|
211
212
|
const count = this._moduleRefs.get(ref) ?? 0;
|
|
@@ -228,7 +229,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
228
229
|
}
|
|
229
230
|
async unloadAsync(...modules) {
|
|
230
231
|
this._assertNotDisposed();
|
|
231
|
-
for (const
|
|
232
|
+
for (const module of modules) await this._unloadModuleAsync(module);
|
|
232
233
|
}
|
|
233
234
|
async _unloadModuleAsync(ref) {
|
|
234
235
|
const count = this._moduleRefs.get(ref) ?? 0;
|
|
@@ -253,10 +254,10 @@ var DefaultContainer = class DefaultContainer {
|
|
|
253
254
|
this._assertNotDisposed();
|
|
254
255
|
const entries = registry.entries();
|
|
255
256
|
for (const { target, scope } of entries) {
|
|
256
|
-
const
|
|
257
|
-
if (scope === "singleton")
|
|
258
|
-
else if (scope === "scoped")
|
|
259
|
-
else
|
|
257
|
+
const bindingBuilder = this._createBindToBuilder(target).toSelf();
|
|
258
|
+
if (scope === "singleton") bindingBuilder.singleton();
|
|
259
|
+
else if (scope === "scoped") bindingBuilder.scoped();
|
|
260
|
+
else bindingBuilder.transient();
|
|
260
261
|
}
|
|
261
262
|
return entries.length;
|
|
262
263
|
}
|
|
@@ -322,7 +323,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
322
323
|
if (effectiveBindingScope(binding) === "singleton" && !this._scope.hasSingleton(binding.id)) {
|
|
323
324
|
if (binding.predicate !== void 0) continue;
|
|
324
325
|
if (binding.kind === "constant" && binding.onActivation === void 0) continue;
|
|
325
|
-
const slotHint =
|
|
326
|
+
const slotHint = bindingSlotToResolveOptions(binding.slot);
|
|
326
327
|
await this.resolveAsync(binding.token, slotHint);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
@@ -332,43 +333,116 @@ var DefaultContainer = class DefaultContainer {
|
|
|
332
333
|
const reader = this._getMetadataReader();
|
|
333
334
|
const allBindings = this._registry.allBindings();
|
|
334
335
|
for (const binding of allBindings) {
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
if (scope !== "singleton") continue;
|
|
338
|
-
const deps = this._getDepsForBinding(binding, reader);
|
|
339
|
-
for (const dep of deps) this._validateDep(tokenName(binding.token), scope, dep, [tokenName(binding.token)], reader);
|
|
336
|
+
if (!this._isSingletonStaticAnalyzableBinding(binding)) continue;
|
|
337
|
+
this._validateSingletonBindingGraph(binding, reader);
|
|
340
338
|
}
|
|
341
339
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
340
|
+
_isSingletonStaticAnalyzableBinding(binding) {
|
|
341
|
+
if (effectiveBindingScope(binding) !== "singleton") return false;
|
|
342
|
+
return binding.kind === "class" || binding.kind === "resolved" || binding.kind === "resolved-async";
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* DFS over explicit constructor / `toResolved*` dependency edges. Follows `toAlias` chains to the
|
|
346
|
+
* terminal binding for scope checks (SPEC §6.9). Skips `toDynamic*` subtrees (opaque).
|
|
347
|
+
*/
|
|
348
|
+
_validateSingletonBindingGraph(root, reader) {
|
|
349
|
+
const rootName = tokenName(root.token);
|
|
350
|
+
const dfs = (current, pathNames, pathBindingIds) => {
|
|
351
|
+
if (pathBindingIds.has(current.id)) return;
|
|
352
|
+
const extendedPathIds = new Set(pathBindingIds);
|
|
353
|
+
extendedPathIds.add(current.id);
|
|
354
|
+
for (const edge of this._collectStaticDependencyEdges(current, reader)) {
|
|
355
|
+
const { terminal, depTokenName } = edge;
|
|
356
|
+
const depScope = this._validationScopeFromTerminal(terminal);
|
|
357
|
+
if (depScope === "opaque") continue;
|
|
358
|
+
if (depScope === "scoped" || depScope === "transient") throw new ScopeViolationError({
|
|
359
|
+
consumerToken: rootName,
|
|
360
|
+
consumerScope: "singleton",
|
|
361
|
+
dependencyToken: depTokenName,
|
|
362
|
+
dependencyScope: depScope,
|
|
363
|
+
path: [...pathNames, depTokenName]
|
|
351
364
|
});
|
|
365
|
+
if (terminal.kind === "class" || terminal.kind === "resolved" || terminal.kind === "resolved-async") dfs(terminal, [...pathNames, depTokenName], extendedPathIds);
|
|
352
366
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
367
|
+
};
|
|
368
|
+
dfs(root, [rootName], /* @__PURE__ */ new Set());
|
|
369
|
+
}
|
|
370
|
+
_validationScopeFromTerminal(terminal) {
|
|
371
|
+
switch (terminal.kind) {
|
|
372
|
+
case "constant": return "singleton";
|
|
373
|
+
case "dynamic":
|
|
374
|
+
case "dynamic-async": return "opaque";
|
|
375
|
+
case "class":
|
|
376
|
+
case "resolved":
|
|
377
|
+
case "resolved-async": return terminal.scope;
|
|
378
|
+
case "alias": throw new InternalError("validate: expected terminal binding after alias resolution");
|
|
379
|
+
default: return terminal;
|
|
359
380
|
}
|
|
360
|
-
return result;
|
|
361
381
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
382
|
+
_followAliasChainToTerminal(binding, hint) {
|
|
383
|
+
const cyclePath = [];
|
|
384
|
+
const seenAliasIds = /* @__PURE__ */ new Set();
|
|
385
|
+
let current = binding;
|
|
386
|
+
while (current !== void 0 && current.kind === "alias") {
|
|
387
|
+
if (seenAliasIds.has(current.id)) throw new CircularDependencyError(cyclePath);
|
|
388
|
+
seenAliasIds.add(current.id);
|
|
389
|
+
cyclePath.push(tokenName(current.token));
|
|
390
|
+
const nextToken = current.target;
|
|
391
|
+
const next = this._resolver.peekBindingForValidate(nextToken, hint);
|
|
392
|
+
if (next === void 0) return;
|
|
393
|
+
current = next.binding;
|
|
394
|
+
}
|
|
395
|
+
return current;
|
|
396
|
+
}
|
|
397
|
+
_collectStaticDependencyEdges(binding, reader) {
|
|
398
|
+
const edges = [];
|
|
399
|
+
const pushTerminal = (terminal, displayName) => {
|
|
400
|
+
if (terminal === void 0) return;
|
|
401
|
+
edges.push({
|
|
402
|
+
terminal,
|
|
403
|
+
depTokenName: displayName
|
|
370
404
|
});
|
|
405
|
+
};
|
|
406
|
+
if (binding.kind === "class") {
|
|
407
|
+
const meta = reader.getConstructorMetadata(binding.target);
|
|
408
|
+
if (meta === void 0) return edges;
|
|
409
|
+
for (const param of meta.params) {
|
|
410
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
411
|
+
if (param.optional) continue;
|
|
412
|
+
const tokenRef = param.token;
|
|
413
|
+
if (param.multi) {
|
|
414
|
+
const candidates = this._resolver.peekCandidateBindingsForValidate(tokenRef, paramHint);
|
|
415
|
+
for (const cand of candidates) {
|
|
416
|
+
const term = this._followAliasChainToTerminal(cand, paramHint);
|
|
417
|
+
pushTerminal(term, term !== void 0 ? tokenName(term.token) : "");
|
|
418
|
+
}
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const found = paramHint === void 0 ? this._resolver.peekBindingForValidate(tokenRef, void 0) : this._resolver.peekBindingForValidate(tokenRef, paramHint);
|
|
422
|
+
if (found === void 0) continue;
|
|
423
|
+
const term = this._followAliasChainToTerminal(found.binding, paramHint);
|
|
424
|
+
pushTerminal(term, term !== void 0 ? tokenName(term.token) : "");
|
|
425
|
+
}
|
|
426
|
+
return edges;
|
|
371
427
|
}
|
|
428
|
+
if (binding.kind === "resolved" || binding.kind === "resolved-async") for (const dep of binding.deps) {
|
|
429
|
+
const depHint = injectionSlotToResolveOptions(dep);
|
|
430
|
+
if (dep.optional) continue;
|
|
431
|
+
const tokenRef = dep.token;
|
|
432
|
+
if (dep.multi) {
|
|
433
|
+
const candidates = this._resolver.peekCandidateBindingsForValidate(tokenRef, depHint);
|
|
434
|
+
for (const cand of candidates) {
|
|
435
|
+
const term = this._followAliasChainToTerminal(cand, depHint);
|
|
436
|
+
pushTerminal(term, term !== void 0 ? tokenName(term.token) : "");
|
|
437
|
+
}
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const found = depHint === void 0 ? this._resolver.peekBindingForValidate(tokenRef, void 0) : this._resolver.peekBindingForValidate(tokenRef, depHint);
|
|
441
|
+
if (found === void 0) continue;
|
|
442
|
+
const term = this._followAliasChainToTerminal(found.binding, depHint);
|
|
443
|
+
pushTerminal(term, term !== void 0 ? tokenName(term.token) : "");
|
|
444
|
+
}
|
|
445
|
+
return edges;
|
|
372
446
|
}
|
|
373
447
|
has(token, hint) {
|
|
374
448
|
this._assertNotDisposed();
|
|
@@ -394,13 +468,25 @@ var DefaultContainer = class DefaultContainer {
|
|
|
394
468
|
if (this._disposed) throw new DisposedContainerError();
|
|
395
469
|
}
|
|
396
470
|
};
|
|
397
|
-
|
|
471
|
+
function updateSlotTag(slot, tag, value) {
|
|
472
|
+
const existing = [...slot.tags];
|
|
473
|
+
const idx = existing.findIndex(([k]) => k === tag);
|
|
474
|
+
if (idx !== -1) existing[idx] = [tag, value];
|
|
475
|
+
else existing.push([tag, value]);
|
|
476
|
+
return {
|
|
477
|
+
...slot,
|
|
478
|
+
tags: existing
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
var BindingEntry = class {
|
|
482
|
+
_token;
|
|
483
|
+
_commit;
|
|
398
484
|
constructor(_token, _commit) {
|
|
399
485
|
this._token = _token;
|
|
400
486
|
this._commit = _commit;
|
|
401
487
|
}
|
|
402
488
|
to(type) {
|
|
403
|
-
return new
|
|
489
|
+
return new ConstraintBuilder(this._token, {
|
|
404
490
|
kind: "class",
|
|
405
491
|
target: type,
|
|
406
492
|
scope: "transient"
|
|
@@ -408,32 +494,32 @@ var BindToBuilderImpl = class {
|
|
|
408
494
|
}
|
|
409
495
|
toSelf() {
|
|
410
496
|
if (typeof this._token !== "function") throw new Error("toSelf() requires token to be a Constructor");
|
|
411
|
-
return new
|
|
497
|
+
return new ConstraintBuilder(this._token, {
|
|
412
498
|
kind: "class",
|
|
413
499
|
target: this._token,
|
|
414
500
|
scope: "transient"
|
|
415
501
|
}, this._commit);
|
|
416
502
|
}
|
|
417
503
|
toConstantValue(value) {
|
|
418
|
-
return new
|
|
504
|
+
return new ConstantBuilder(this._token, value, this._commit);
|
|
419
505
|
}
|
|
420
506
|
toDynamic(factory) {
|
|
421
|
-
return new
|
|
507
|
+
return new ConstraintBuilder(this._token, {
|
|
422
508
|
kind: "dynamic",
|
|
423
509
|
factory,
|
|
424
510
|
scope: "transient"
|
|
425
511
|
}, this._commit);
|
|
426
512
|
}
|
|
427
513
|
toDynamicAsync(factory) {
|
|
428
|
-
return new
|
|
514
|
+
return new ConstraintBuilder(this._token, {
|
|
429
515
|
kind: "dynamic-async",
|
|
430
516
|
factory,
|
|
431
517
|
scope: "transient"
|
|
432
518
|
}, this._commit);
|
|
433
519
|
}
|
|
434
520
|
toResolved(factory, deps) {
|
|
435
|
-
const normalizedDeps = deps.map((
|
|
436
|
-
return new
|
|
521
|
+
const normalizedDeps = deps.map((dependency) => normalizeToDescriptor(dependency));
|
|
522
|
+
return new ConstraintBuilder(this._token, {
|
|
437
523
|
kind: "resolved",
|
|
438
524
|
factory,
|
|
439
525
|
deps: normalizedDeps,
|
|
@@ -441,8 +527,8 @@ var BindToBuilderImpl = class {
|
|
|
441
527
|
}, this._commit);
|
|
442
528
|
}
|
|
443
529
|
toResolvedAsync(factory, deps) {
|
|
444
|
-
const normalizedDeps = deps.map((
|
|
445
|
-
return new
|
|
530
|
+
const normalizedDeps = deps.map((dependency) => normalizeToDescriptor(dependency));
|
|
531
|
+
return new ConstraintBuilder(this._token, {
|
|
446
532
|
kind: "resolved-async",
|
|
447
533
|
factory,
|
|
448
534
|
deps: normalizedDeps,
|
|
@@ -450,10 +536,13 @@ var BindToBuilderImpl = class {
|
|
|
450
536
|
}, this._commit);
|
|
451
537
|
}
|
|
452
538
|
toAlias(target) {
|
|
453
|
-
return new
|
|
539
|
+
return new AliasBuilder(this._token, target, this._commit);
|
|
454
540
|
}
|
|
455
541
|
};
|
|
456
|
-
var
|
|
542
|
+
var ConstraintBuilder = class {
|
|
543
|
+
_token;
|
|
544
|
+
_partial;
|
|
545
|
+
_commit;
|
|
457
546
|
_slot;
|
|
458
547
|
_predicate;
|
|
459
548
|
_committed;
|
|
@@ -462,7 +551,7 @@ var BindingBuilderImpl = class {
|
|
|
462
551
|
this._partial = _partial;
|
|
463
552
|
this._commit = _commit;
|
|
464
553
|
this._slot = {
|
|
465
|
-
...
|
|
554
|
+
...DEFAULT_BINDING_SLOT,
|
|
466
555
|
tags: []
|
|
467
556
|
};
|
|
468
557
|
this._doCommit();
|
|
@@ -492,14 +581,7 @@ var BindingBuilderImpl = class {
|
|
|
492
581
|
return this;
|
|
493
582
|
}
|
|
494
583
|
whenTagged(tag, value) {
|
|
495
|
-
|
|
496
|
-
const idx = existing.findIndex(([k]) => k === tag);
|
|
497
|
-
if (idx !== -1) existing[idx] = [tag, value];
|
|
498
|
-
else existing.push([tag, value]);
|
|
499
|
-
this._slot = {
|
|
500
|
-
...this._slot,
|
|
501
|
-
tags: existing
|
|
502
|
-
};
|
|
584
|
+
this._slot = updateSlotTag(this._slot, tag, value);
|
|
503
585
|
this._doCommit();
|
|
504
586
|
return this;
|
|
505
587
|
}
|
|
@@ -509,7 +591,7 @@ var BindingBuilderImpl = class {
|
|
|
509
591
|
singleton() {
|
|
510
592
|
const previousId = this._committed;
|
|
511
593
|
this._committed = void 0;
|
|
512
|
-
return new
|
|
594
|
+
return new ScopeBuilder(this._token, {
|
|
513
595
|
...this._partial,
|
|
514
596
|
scope: "singleton"
|
|
515
597
|
}, this._slot, this._predicate, this._commit, "singleton", previousId);
|
|
@@ -517,7 +599,7 @@ var BindingBuilderImpl = class {
|
|
|
517
599
|
transient() {
|
|
518
600
|
const previousId = this._committed;
|
|
519
601
|
this._committed = void 0;
|
|
520
|
-
return new
|
|
602
|
+
return new ScopeBuilder(this._token, {
|
|
521
603
|
...this._partial,
|
|
522
604
|
scope: "transient"
|
|
523
605
|
}, this._slot, this._predicate, this._commit, "transient", previousId);
|
|
@@ -525,7 +607,7 @@ var BindingBuilderImpl = class {
|
|
|
525
607
|
scoped() {
|
|
526
608
|
const previousId = this._committed;
|
|
527
609
|
this._committed = void 0;
|
|
528
|
-
return new
|
|
610
|
+
return new ScopeBuilder(this._token, {
|
|
529
611
|
...this._partial,
|
|
530
612
|
scope: "scoped"
|
|
531
613
|
}, this._slot, this._predicate, this._commit, "scoped", previousId);
|
|
@@ -534,7 +616,14 @@ var BindingBuilderImpl = class {
|
|
|
534
616
|
return this._committed;
|
|
535
617
|
}
|
|
536
618
|
};
|
|
537
|
-
var
|
|
619
|
+
var ScopeBuilder = class {
|
|
620
|
+
_token;
|
|
621
|
+
_partial;
|
|
622
|
+
_slot;
|
|
623
|
+
_predicate;
|
|
624
|
+
_commit;
|
|
625
|
+
_scope;
|
|
626
|
+
_initialPreviousId;
|
|
538
627
|
_onActivation;
|
|
539
628
|
_onDeactivation;
|
|
540
629
|
_committed;
|
|
@@ -575,7 +664,10 @@ var ScopeBuilderImpl = class {
|
|
|
575
664
|
return this._committed;
|
|
576
665
|
}
|
|
577
666
|
};
|
|
578
|
-
var
|
|
667
|
+
var ConstantBuilder = class {
|
|
668
|
+
_token;
|
|
669
|
+
_value;
|
|
670
|
+
_commit;
|
|
579
671
|
_slot;
|
|
580
672
|
_predicate;
|
|
581
673
|
_onActivation;
|
|
@@ -586,7 +678,7 @@ var ConstantBindingBuilderImpl = class {
|
|
|
586
678
|
this._value = _value;
|
|
587
679
|
this._commit = _commit;
|
|
588
680
|
this._slot = {
|
|
589
|
-
...
|
|
681
|
+
...DEFAULT_BINDING_SLOT,
|
|
590
682
|
tags: []
|
|
591
683
|
};
|
|
592
684
|
this._doCommit();
|
|
@@ -620,14 +712,7 @@ var ConstantBindingBuilderImpl = class {
|
|
|
620
712
|
return this;
|
|
621
713
|
}
|
|
622
714
|
whenTagged(tag, value) {
|
|
623
|
-
|
|
624
|
-
const idx = existing.findIndex(([k]) => k === tag);
|
|
625
|
-
if (idx !== -1) existing[idx] = [tag, value];
|
|
626
|
-
else existing.push([tag, value]);
|
|
627
|
-
this._slot = {
|
|
628
|
-
...this._slot,
|
|
629
|
-
tags: existing
|
|
630
|
-
};
|
|
715
|
+
this._slot = updateSlotTag(this._slot, tag, value);
|
|
631
716
|
this._doCommit();
|
|
632
717
|
return this;
|
|
633
718
|
}
|
|
@@ -648,7 +733,10 @@ var ConstantBindingBuilderImpl = class {
|
|
|
648
733
|
return this._committed;
|
|
649
734
|
}
|
|
650
735
|
};
|
|
651
|
-
var
|
|
736
|
+
var AliasBuilder = class {
|
|
737
|
+
_token;
|
|
738
|
+
_target;
|
|
739
|
+
_commit;
|
|
652
740
|
_slot;
|
|
653
741
|
_predicate;
|
|
654
742
|
_committed;
|
|
@@ -657,7 +745,7 @@ var AliasBindingBuilderImpl = class {
|
|
|
657
745
|
this._target = _target;
|
|
658
746
|
this._commit = _commit;
|
|
659
747
|
this._slot = {
|
|
660
|
-
...
|
|
748
|
+
...DEFAULT_BINDING_SLOT,
|
|
661
749
|
tags: []
|
|
662
750
|
};
|
|
663
751
|
this._doCommit();
|
|
@@ -688,14 +776,7 @@ var AliasBindingBuilderImpl = class {
|
|
|
688
776
|
return this;
|
|
689
777
|
}
|
|
690
778
|
whenTagged(tag, value) {
|
|
691
|
-
|
|
692
|
-
const idx = existing.findIndex(([k]) => k === tag);
|
|
693
|
-
if (idx !== -1) existing[idx] = [tag, value];
|
|
694
|
-
else existing.push([tag, value]);
|
|
695
|
-
this._slot = {
|
|
696
|
-
...this._slot,
|
|
697
|
-
tags: existing
|
|
698
|
-
};
|
|
779
|
+
this._slot = updateSlotTag(this._slot, tag, value);
|
|
699
780
|
this._doCommit();
|
|
700
781
|
return this;
|
|
701
782
|
}
|
|
@@ -30,19 +30,19 @@ declare function isInjectionDescriptor(value: unknown): value is InjectionDescri
|
|
|
30
30
|
/**
|
|
31
31
|
* @since 0.3.16-canary.0
|
|
32
32
|
*/
|
|
33
|
-
declare function normalizeToDescriptor(
|
|
33
|
+
declare function normalizeToDescriptor(dependency: InjectableDependency): InjectionDescriptor;
|
|
34
34
|
type ClassAccessorDecorator<This, Value> = (target: ClassAccessorDecoratorTarget<This, Value>, context: ClassAccessorDecoratorContext<This, Value>) => ClassAccessorDecoratorResult<This, Value> | void;
|
|
35
35
|
/**
|
|
36
36
|
* @since 0.3.16-canary.0
|
|
37
37
|
*/
|
|
38
|
-
declare function inject<const Value>(
|
|
38
|
+
declare function inject<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value> & ClassAccessorDecorator<unknown, Value>;
|
|
39
39
|
/**
|
|
40
40
|
* @since 0.3.16-canary.0
|
|
41
41
|
*/
|
|
42
|
-
declare function optional<const Value>(
|
|
42
|
+
declare function optional<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value | undefined>;
|
|
43
43
|
/**
|
|
44
44
|
* @since 0.3.16-canary.0
|
|
45
45
|
*/
|
|
46
|
-
declare function injectAll<const Value>(
|
|
46
|
+
declare function injectAll<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Array<Value>>;
|
|
47
47
|
//#endregion
|
|
48
48
|
export { InjectOptions, InjectableDependency, InjectionDescriptor, inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
|