@codefast/di 0.3.14 → 0.3.16-canary.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 +10 -0
- package/README.md +173 -109
- package/dist/binding-scope.d.mts +2 -0
- package/dist/binding-scope.mjs +2 -0
- package/dist/binding-select.d.mts +4 -0
- package/dist/binding-select.mjs +4 -0
- package/dist/binding.d.mts +68 -1
- package/dist/binding.mjs +12 -0
- package/dist/constraints.d.mts +24 -0
- package/dist/constraints.mjs +24 -0
- package/dist/constructor-type.d.mts +4 -0
- package/dist/container.d.mts +9 -0
- package/dist/container.mjs +3 -0
- package/dist/decorators/inject.d.mts +24 -0
- package/dist/decorators/inject.mjs +15 -0
- package/dist/decorators/injectable.d.mts +12 -0
- package/dist/decorators/injectable.mjs +6 -0
- package/dist/decorators/lifecycle-decorators.d.mts +6 -0
- package/dist/decorators/lifecycle-decorators.mjs +6 -0
- package/dist/dependency-graph.d.mts +15 -0
- package/dist/dependency-graph.mjs +3 -0
- package/dist/environment.d.mts +15 -0
- package/dist/environment.mjs +12 -0
- package/dist/errors.d.mts +51 -0
- package/dist/errors.mjs +48 -0
- package/dist/graph-adapters/cytoscape.d.mts +12 -0
- package/dist/graph-adapters/cytoscape.mjs +3 -0
- package/dist/graph-adapters/dot.d.mts +3 -0
- package/dist/graph-adapters/dot.mjs +3 -0
- package/dist/graph-adapters/reactflow.d.mts +12 -0
- package/dist/graph-adapters/reactflow.mjs +3 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/inspector.d.mts +9 -0
- package/dist/inspector.mjs +3 -0
- package/dist/lifecycle.d.mts +3 -0
- package/dist/lifecycle.mjs +3 -0
- package/dist/metadata/metadata-keys.d.mts +18 -0
- package/dist/metadata/metadata-keys.mjs +18 -0
- package/dist/metadata/metadata-reader-token.d.mts +3 -0
- package/dist/metadata/metadata-reader-token.mjs +3 -0
- package/dist/metadata/metadata-types.d.mts +17 -1
- package/dist/metadata/symbol-metadata-reader.d.mts +6 -0
- package/dist/metadata/symbol-metadata-reader.mjs +6 -0
- package/dist/module.d.mts +24 -0
- package/dist/module.mjs +12 -0
- package/dist/registry.d.mts +7 -0
- package/dist/registry.mjs +44 -0
- package/dist/resolve-options.d.mts +4 -0
- package/dist/resolve-options.mjs +4 -0
- package/dist/resolver.d.mts +3 -0
- package/dist/resolver.mjs +15 -12
- package/dist/scope.d.mts +3 -0
- package/dist/scope.mjs +3 -0
- package/dist/token.d.mts +12 -0
- package/dist/token.mjs +9 -0
- package/dist/types.d.mts +35 -1
- package/package.json +3 -4
package/dist/module.d.mts
CHANGED
|
@@ -5,34 +5,58 @@ import { BindToBuilder } from "./binding.mjs";
|
|
|
5
5
|
//#region src/module.d.ts
|
|
6
6
|
declare const SYNC_MODULE_BRAND: unique symbol;
|
|
7
7
|
declare const ASYNC_MODULE_BRAND: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* @since 0.3.16-canary.0
|
|
10
|
+
*/
|
|
8
11
|
interface SyncModule {
|
|
9
12
|
readonly name: string;
|
|
10
13
|
readonly [SYNC_MODULE_BRAND]: true;
|
|
11
14
|
readonly _setup: (builder: ModuleBuilder) => void;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
18
|
+
*/
|
|
13
19
|
interface AsyncModule {
|
|
14
20
|
readonly name: string;
|
|
15
21
|
readonly [ASYNC_MODULE_BRAND]: true;
|
|
16
22
|
readonly _setup: (builder: AsyncModuleBuilder) => Promise<void>;
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.3.16-canary.0
|
|
26
|
+
*/
|
|
18
27
|
interface ModuleBuilder {
|
|
19
28
|
bind<const Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
20
29
|
import(...modules: SyncModule[]): void;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @since 0.3.16-canary.0
|
|
33
|
+
*/
|
|
22
34
|
interface AsyncModuleBuilder {
|
|
23
35
|
bind<const Value>(token: Token<Value> | Constructor<Value>): BindToBuilder<Value>;
|
|
24
36
|
import(...modules: Array<SyncModule | AsyncModule>): void;
|
|
25
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @since 0.3.16-canary.0
|
|
40
|
+
*/
|
|
26
41
|
declare const SyncModule: {
|
|
27
42
|
create(name: string, setup: (builder: ModuleBuilder) => void): SyncModule;
|
|
28
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* @since 0.3.16-canary.0
|
|
46
|
+
*/
|
|
29
47
|
declare const AsyncModule: {
|
|
30
48
|
create(name: string, setup: (builder: AsyncModuleBuilder) => Promise<void>): AsyncModule;
|
|
31
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* @since 0.3.16-canary.0
|
|
52
|
+
*/
|
|
32
53
|
declare const Module: {
|
|
33
54
|
create(name: string, setup: (builder: ModuleBuilder) => void): SyncModule;
|
|
34
55
|
createAsync(name: string, setup: (builder: AsyncModuleBuilder) => Promise<void>): AsyncModule;
|
|
35
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* @since 0.3.16-canary.0
|
|
59
|
+
*/
|
|
36
60
|
declare function isSyncModule(m: SyncModule | AsyncModule): m is SyncModule;
|
|
37
61
|
//#endregion
|
|
38
62
|
export { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule };
|
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/module.ts
|
|
2
2
|
const SYNC_MODULE_BRAND = Symbol("di:sync-module");
|
|
3
3
|
const ASYNC_MODULE_BRAND = Symbol("di:async-module");
|
|
4
|
+
/**
|
|
5
|
+
* @since 0.3.16-canary.0
|
|
6
|
+
*/
|
|
4
7
|
const SyncModule = { create(name, setup) {
|
|
5
8
|
return {
|
|
6
9
|
name,
|
|
@@ -8,6 +11,9 @@ const SyncModule = { create(name, setup) {
|
|
|
8
11
|
_setup: setup
|
|
9
12
|
};
|
|
10
13
|
} };
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.3.16-canary.0
|
|
16
|
+
*/
|
|
11
17
|
const AsyncModule = { create(name, setup) {
|
|
12
18
|
return {
|
|
13
19
|
name,
|
|
@@ -15,6 +21,9 @@ const AsyncModule = { create(name, setup) {
|
|
|
15
21
|
_setup: setup
|
|
16
22
|
};
|
|
17
23
|
} };
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.3.16-canary.0
|
|
26
|
+
*/
|
|
18
27
|
const Module = {
|
|
19
28
|
create(name, setup) {
|
|
20
29
|
return SyncModule.create(name, setup);
|
|
@@ -23,6 +32,9 @@ const Module = {
|
|
|
23
32
|
return AsyncModule.create(name, setup);
|
|
24
33
|
}
|
|
25
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* @since 0.3.16-canary.0
|
|
37
|
+
*/
|
|
26
38
|
function isSyncModule(m) {
|
|
27
39
|
return m[SYNC_MODULE_BRAND] === true;
|
|
28
40
|
}
|
package/dist/registry.d.mts
CHANGED
|
@@ -4,11 +4,15 @@ import { BindingIdentifier } from "./types.mjs";
|
|
|
4
4
|
import { Binding } from "./binding.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/registry.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.3.16-canary.0
|
|
9
|
+
*/
|
|
7
10
|
declare class BindingRegistry {
|
|
8
11
|
private readonly _bindings;
|
|
9
12
|
private readonly _byId;
|
|
10
13
|
private readonly _simpleNamed;
|
|
11
14
|
private readonly _fastDefault;
|
|
15
|
+
private readonly _simpleTagged;
|
|
12
16
|
/** Add or replace binding using slot-aware last-wins. */
|
|
13
17
|
add(binding: Binding): void;
|
|
14
18
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
@@ -26,9 +30,12 @@ declare class BindingRegistry {
|
|
|
26
30
|
/** Remove all bindings. Returns all removed. */
|
|
27
31
|
clear(): readonly Binding[];
|
|
28
32
|
getSimpleNamed(token: Token<unknown> | Constructor, name: string): Binding | undefined;
|
|
33
|
+
getSimpleTagged(token: Token<unknown> | Constructor, tagKey: string, tagValue: unknown): Binding | undefined;
|
|
29
34
|
getFastDefault(token: Token<unknown> | Constructor): Binding | undefined;
|
|
30
35
|
/** Summarize available slot strings for a token (for error messages). */
|
|
31
36
|
availableSlotStrings(t: Token<unknown> | Constructor): string[];
|
|
37
|
+
private _indexSimpleTaggedBinding;
|
|
38
|
+
private _deindexSimpleTaggedBinding;
|
|
32
39
|
private _isPurePredicateBinding;
|
|
33
40
|
private _indexSimpleNamedBinding;
|
|
34
41
|
private _deindexSimpleNamedBinding;
|
package/dist/registry.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { slotKeyEquals } from "./binding.mjs";
|
|
2
2
|
//#region src/registry.ts
|
|
3
|
+
/**
|
|
4
|
+
* @since 0.3.16-canary.0
|
|
5
|
+
*/
|
|
3
6
|
var BindingRegistry = class {
|
|
4
7
|
_bindings = /* @__PURE__ */ new Map();
|
|
5
8
|
_byId = /* @__PURE__ */ new Map();
|
|
6
9
|
_simpleNamed = /* @__PURE__ */ new Map();
|
|
7
10
|
_fastDefault = /* @__PURE__ */ new Map();
|
|
11
|
+
_simpleTagged = /* @__PURE__ */ new Map();
|
|
8
12
|
/** Add or replace binding using slot-aware last-wins. */
|
|
9
13
|
add(binding) {
|
|
10
14
|
const key = binding.token;
|
|
@@ -24,6 +28,7 @@ var BindingRegistry = class {
|
|
|
24
28
|
list.push(binding);
|
|
25
29
|
this._byId.set(binding.id, binding);
|
|
26
30
|
this._indexSimpleNamedBinding(key, binding);
|
|
31
|
+
this._indexSimpleTaggedBinding(key, binding);
|
|
27
32
|
this._refreshFastDefaultForToken(key);
|
|
28
33
|
}
|
|
29
34
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
@@ -32,6 +37,7 @@ var BindingRegistry = class {
|
|
|
32
37
|
const list = this._bindings.get(key) ?? [];
|
|
33
38
|
this._bindings.delete(key);
|
|
34
39
|
this._simpleNamed.delete(key);
|
|
40
|
+
this._simpleTagged.delete(key);
|
|
35
41
|
this._fastDefault.delete(key);
|
|
36
42
|
for (const b of list) this._byId.delete(b.id);
|
|
37
43
|
return list;
|
|
@@ -47,9 +53,11 @@ var BindingRegistry = class {
|
|
|
47
53
|
const idx = list.findIndex((b) => b.id === id);
|
|
48
54
|
if (idx !== -1) list.splice(idx, 1);
|
|
49
55
|
this._deindexSimpleNamedBinding(key, binding);
|
|
56
|
+
this._deindexSimpleTaggedBinding(key, binding);
|
|
50
57
|
if (list.length === 0) {
|
|
51
58
|
this._bindings.delete(key);
|
|
52
59
|
this._simpleNamed.delete(key);
|
|
60
|
+
this._simpleTagged.delete(key);
|
|
53
61
|
this._fastDefault.delete(key);
|
|
54
62
|
} else this._refreshFastDefaultForToken(key);
|
|
55
63
|
}
|
|
@@ -81,12 +89,16 @@ var BindingRegistry = class {
|
|
|
81
89
|
this._bindings.clear();
|
|
82
90
|
this._byId.clear();
|
|
83
91
|
this._simpleNamed.clear();
|
|
92
|
+
this._simpleTagged.clear();
|
|
84
93
|
this._fastDefault.clear();
|
|
85
94
|
return all;
|
|
86
95
|
}
|
|
87
96
|
getSimpleNamed(token, name) {
|
|
88
97
|
return this._simpleNamed.get(token)?.get(name);
|
|
89
98
|
}
|
|
99
|
+
getSimpleTagged(token, tagKey, tagValue) {
|
|
100
|
+
return this._simpleTagged.get(token)?.get(tagKey)?.get(tagValue);
|
|
101
|
+
}
|
|
90
102
|
getFastDefault(token) {
|
|
91
103
|
return this._fastDefault.get(token);
|
|
92
104
|
}
|
|
@@ -101,6 +113,38 @@ var BindingRegistry = class {
|
|
|
101
113
|
return parts.join(",");
|
|
102
114
|
});
|
|
103
115
|
}
|
|
116
|
+
_indexSimpleTaggedBinding(tokenKeyValue, binding) {
|
|
117
|
+
const slot = binding.slot;
|
|
118
|
+
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
119
|
+
const [tagKey, tagValue] = slot.tags[0];
|
|
120
|
+
let byTagKey = this._simpleTagged.get(tokenKeyValue);
|
|
121
|
+
if (byTagKey === void 0) {
|
|
122
|
+
byTagKey = /* @__PURE__ */ new Map();
|
|
123
|
+
this._simpleTagged.set(tokenKeyValue, byTagKey);
|
|
124
|
+
}
|
|
125
|
+
let byTagValue = byTagKey.get(tagKey);
|
|
126
|
+
if (byTagValue === void 0) {
|
|
127
|
+
byTagValue = /* @__PURE__ */ new Map();
|
|
128
|
+
byTagKey.set(tagKey, byTagValue);
|
|
129
|
+
}
|
|
130
|
+
byTagValue.set(tagValue, binding);
|
|
131
|
+
}
|
|
132
|
+
_deindexSimpleTaggedBinding(tokenKeyValue, binding) {
|
|
133
|
+
const slot = binding.slot;
|
|
134
|
+
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
135
|
+
const [tagKey, tagValue] = slot.tags[0];
|
|
136
|
+
const byTagKey = this._simpleTagged.get(tokenKeyValue);
|
|
137
|
+
if (byTagKey === void 0) return;
|
|
138
|
+
const byTagValue = byTagKey.get(tagKey);
|
|
139
|
+
if (byTagValue === void 0) return;
|
|
140
|
+
if (byTagValue.get(tagValue)?.id === binding.id) {
|
|
141
|
+
byTagValue.delete(tagValue);
|
|
142
|
+
if (byTagValue.size === 0) {
|
|
143
|
+
byTagKey.delete(tagKey);
|
|
144
|
+
if (byTagKey.size === 0) this._simpleTagged.delete(tokenKeyValue);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
104
148
|
_isPurePredicateBinding(binding) {
|
|
105
149
|
const slot = binding.slot;
|
|
106
150
|
const hasPredicate = binding.predicate !== void 0;
|
|
@@ -5,6 +5,8 @@ import { SlotKey } from "./binding.mjs";
|
|
|
5
5
|
/**
|
|
6
6
|
* Builds a {@link ResolveOptions} safe for `exactOptionalPropertyTypes`:
|
|
7
7
|
* omits keys instead of assigning `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.3.16-canary.0
|
|
8
10
|
*/
|
|
9
11
|
declare function injectableSlotToResolveOptions(slot: {
|
|
10
12
|
readonly name?: string;
|
|
@@ -12,6 +14,8 @@ declare function injectableSlotToResolveOptions(slot: {
|
|
|
12
14
|
}): ResolveOptions | undefined;
|
|
13
15
|
/**
|
|
14
16
|
* Hint from a binding {@link SlotKey} (tags may be empty; omits when nothing to match).
|
|
17
|
+
*
|
|
18
|
+
* @since 0.3.16-canary.0
|
|
15
19
|
*/
|
|
16
20
|
declare function slotKeyToResolveOptions(slot: SlotKey): ResolveOptions | undefined;
|
|
17
21
|
//#endregion
|
package/dist/resolve-options.mjs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Builds a {@link ResolveOptions} safe for `exactOptionalPropertyTypes`:
|
|
4
4
|
* omits keys instead of assigning `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.3.16-canary.0
|
|
5
7
|
*/
|
|
6
8
|
function injectableSlotToResolveOptions(slot) {
|
|
7
9
|
const options = {};
|
|
@@ -11,6 +13,8 @@ function injectableSlotToResolveOptions(slot) {
|
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Hint from a binding {@link SlotKey} (tags may be empty; omits when nothing to match).
|
|
16
|
+
*
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
14
18
|
*/
|
|
15
19
|
function slotKeyToResolveOptions(slot) {
|
|
16
20
|
const options = {};
|
package/dist/resolver.d.mts
CHANGED
|
@@ -8,6 +8,9 @@ import { Container } from "./container.mjs";
|
|
|
8
8
|
import { LifecycleManager } from "./lifecycle.mjs";
|
|
9
9
|
|
|
10
10
|
//#region src/resolver.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.3.16-canary.0
|
|
13
|
+
*/
|
|
11
14
|
declare class DependencyResolver {
|
|
12
15
|
private readonly _registry;
|
|
13
16
|
private readonly _scope;
|
package/dist/resolver.mjs
CHANGED
|
@@ -15,6 +15,9 @@ const ROOT_CONSTRAINT_CONTEXT = {
|
|
|
15
15
|
ancestors: EMPTY_FRAME_LIST,
|
|
16
16
|
currentResolveHint: void 0
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* @since 0.3.16-canary.0
|
|
20
|
+
*/
|
|
18
21
|
var DependencyResolver = class {
|
|
19
22
|
_frameByBindingId = /* @__PURE__ */ new Map();
|
|
20
23
|
_syncResolutionContextPool = [];
|
|
@@ -54,6 +57,14 @@ var DependencyResolver = class {
|
|
|
54
57
|
owner: this
|
|
55
58
|
};
|
|
56
59
|
}
|
|
60
|
+
if (hint !== void 0 && hint.name === void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 1) {
|
|
61
|
+
const [tagKey, tagValue] = hint.tags[0];
|
|
62
|
+
const tagged = this._registry.getSimpleTagged(token, tagKey, tagValue);
|
|
63
|
+
if (tagged !== void 0) return {
|
|
64
|
+
binding: tagged,
|
|
65
|
+
owner: this
|
|
66
|
+
};
|
|
67
|
+
}
|
|
57
68
|
const bindings = this._registry.getAll(token);
|
|
58
69
|
if (bindings.length > 0) {
|
|
59
70
|
if (bindings.length === 1) {
|
|
@@ -233,12 +244,8 @@ var DependencyResolver = class {
|
|
|
233
244
|
return resolved;
|
|
234
245
|
}
|
|
235
246
|
resolveOptional(token, hint, resolutionPath, materializationStack) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} catch (e) {
|
|
239
|
-
if (e instanceof TokenNotBoundError || e instanceof NoMatchingBindingError) return;
|
|
240
|
-
throw e;
|
|
241
|
-
}
|
|
247
|
+
if (this._findBinding(token, hint, resolutionPath, materializationStack) === void 0) return;
|
|
248
|
+
return this.resolve(token, hint, resolutionPath, materializationStack);
|
|
242
249
|
}
|
|
243
250
|
resolveAll(token, hint, resolutionPath, materializationStack) {
|
|
244
251
|
if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
|
|
@@ -424,12 +431,8 @@ var DependencyResolver = class {
|
|
|
424
431
|
return Promise.all(pending);
|
|
425
432
|
}
|
|
426
433
|
async resolveOptionalAsync(token, hint, resolutionPath, materializationStack) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
} catch (e) {
|
|
430
|
-
if (e instanceof TokenNotBoundError || e instanceof NoMatchingBindingError) return;
|
|
431
|
-
throw e;
|
|
432
|
-
}
|
|
434
|
+
if (this._findBinding(token, hint, resolutionPath, materializationStack) === void 0) return;
|
|
435
|
+
return this.resolveAsync(token, hint, resolutionPath, materializationStack);
|
|
433
436
|
}
|
|
434
437
|
async resolveAllAsync(token, hint, resolutionPath, materializationStack) {
|
|
435
438
|
if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
|
package/dist/scope.d.mts
CHANGED
package/dist/scope.mjs
CHANGED
package/dist/token.d.mts
CHANGED
|
@@ -2,12 +2,24 @@ import { Constructor } from "./constructor-type.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/token.d.ts
|
|
4
4
|
declare const TOKEN_BRAND: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.3.16-canary.0
|
|
7
|
+
*/
|
|
5
8
|
interface Token<Value> {
|
|
6
9
|
readonly name: string;
|
|
7
10
|
readonly [TOKEN_BRAND]: Value;
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* @since 0.3.16-canary.0
|
|
14
|
+
*/
|
|
9
15
|
declare function token<Value>(name: string): Token<Value>;
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
18
|
+
*/
|
|
10
19
|
declare function tokenName(t: Token<unknown> | Constructor): string;
|
|
20
|
+
/**
|
|
21
|
+
* @since 0.3.16-canary.0
|
|
22
|
+
*/
|
|
11
23
|
declare function isToken(value: unknown): value is Token<unknown>;
|
|
12
24
|
//#endregion
|
|
13
25
|
export { Token, isToken, token, tokenName };
|
package/dist/token.mjs
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
//#region src/token.ts
|
|
2
|
+
/**
|
|
3
|
+
* @since 0.3.16-canary.0
|
|
4
|
+
*/
|
|
2
5
|
function token(name) {
|
|
3
6
|
return { name };
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @since 0.3.16-canary.0
|
|
10
|
+
*/
|
|
5
11
|
function tokenName(t) {
|
|
6
12
|
if (typeof t === "function") return t.name;
|
|
7
13
|
return t.name;
|
|
8
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.3.16-canary.0
|
|
17
|
+
*/
|
|
9
18
|
function isToken(value) {
|
|
10
19
|
return typeof value === "object" && value !== null && "name" in value && typeof value["name"] === "string" && typeof value !== "function";
|
|
11
20
|
}
|
package/dist/types.d.mts
CHANGED
|
@@ -2,21 +2,46 @@ import { Constructor } from "./constructor-type.mjs";
|
|
|
2
2
|
import { Token } from "./token.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Token or class constructor used as a binding / injection / resolve key.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.3.16-canary.0
|
|
9
|
+
*/
|
|
6
10
|
type DependencyKey = Token<unknown> | Constructor;
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.3.16-canary.0
|
|
13
|
+
*/
|
|
7
14
|
type BindingScope = "singleton" | "transient" | "scoped";
|
|
8
15
|
declare const BINDING_ID_BRAND: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.16-canary.0
|
|
18
|
+
*/
|
|
9
19
|
type BindingIdentifier = string & {
|
|
10
20
|
readonly [BINDING_ID_BRAND]: true;
|
|
11
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.3.16-canary.0
|
|
24
|
+
*/
|
|
12
25
|
type BindingKind = "class" | "dynamic" | "dynamic-async" | "resolved" | "resolved-async" | "constant" | "alias";
|
|
26
|
+
/**
|
|
27
|
+
* @since 0.3.16-canary.0
|
|
28
|
+
*/
|
|
13
29
|
type ActivationHandler<Value> = (ctx: ResolutionContext, instance: Value) => Value | Promise<Value>;
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.3.16-canary.0
|
|
32
|
+
*/
|
|
14
33
|
type DeactivationHandler<Value> = (instance: Value) => void | Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.3.16-canary.0
|
|
36
|
+
*/
|
|
15
37
|
interface ResolveOptions {
|
|
16
38
|
name?: string;
|
|
17
39
|
tag?: readonly [tag: string, value: unknown];
|
|
18
40
|
tags?: ReadonlyArray<readonly [tag: string, value: unknown]>;
|
|
19
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @since 0.3.16-canary.0
|
|
44
|
+
*/
|
|
20
45
|
interface MaterializationFrame {
|
|
21
46
|
readonly tokenName: string;
|
|
22
47
|
readonly scope: BindingScope;
|
|
@@ -27,6 +52,9 @@ interface MaterializationFrame {
|
|
|
27
52
|
readonly tags: ReadonlyArray<readonly [tag: string, value: unknown]>;
|
|
28
53
|
};
|
|
29
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* @since 0.3.16-canary.0
|
|
57
|
+
*/
|
|
30
58
|
interface ConstraintContext {
|
|
31
59
|
readonly resolutionPath: readonly string[];
|
|
32
60
|
readonly materializationStack: readonly MaterializationFrame[];
|
|
@@ -34,6 +62,9 @@ interface ConstraintContext {
|
|
|
34
62
|
readonly ancestors: readonly MaterializationFrame[];
|
|
35
63
|
readonly currentResolveHint: ResolveOptions | undefined;
|
|
36
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* @since 0.3.16-canary.0
|
|
67
|
+
*/
|
|
37
68
|
interface ResolutionContext {
|
|
38
69
|
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value;
|
|
39
70
|
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value>;
|
|
@@ -43,6 +74,9 @@ interface ResolutionContext {
|
|
|
43
74
|
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value[]>;
|
|
44
75
|
readonly graph: ConstraintContext;
|
|
45
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* @since 0.3.16-canary.0
|
|
79
|
+
*/
|
|
46
80
|
type TokenValue<Type> = Type extends Token<infer Value> ? Value : Type extends Constructor<infer Value> ? Value : never;
|
|
47
81
|
//#endregion
|
|
48
82
|
export { ActivationHandler, BindingIdentifier, BindingKind, BindingScope, ConstraintContext, type Constructor, DeactivationHandler, DependencyKey, MaterializationFrame, ResolutionContext, ResolveOptions, TokenValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codefast/di",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16-canary.0",
|
|
4
4
|
"description": "Lightweight dependency injection primitives for Codefast",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codefast",
|
|
@@ -171,13 +171,13 @@
|
|
|
171
171
|
},
|
|
172
172
|
"devDependencies": {
|
|
173
173
|
"@types/node": "^25.6.0",
|
|
174
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
174
|
+
"@typescript/native-preview": "7.0.0-dev.20260504.1",
|
|
175
175
|
"@vitest/coverage-v8": "^4.1.5",
|
|
176
176
|
"expect-type": "^1.3.0",
|
|
177
177
|
"typescript": "^6.0.3",
|
|
178
178
|
"unplugin-swc": "^1.5.9",
|
|
179
179
|
"vitest": "^4.1.5",
|
|
180
|
-
"@codefast/typescript-config": "0.3.
|
|
180
|
+
"@codefast/typescript-config": "0.3.16-canary.0"
|
|
181
181
|
},
|
|
182
182
|
"engines": {
|
|
183
183
|
"node": ">=22.0.0"
|
|
@@ -187,7 +187,6 @@
|
|
|
187
187
|
"check-types": "tsgo --noEmit",
|
|
188
188
|
"clean": "rm -rf dist",
|
|
189
189
|
"examples": "for file in examples/*/*.ts; do echo \"=== Running $file ===\"; tsx \"$file\"; echo \"\n\" || exit 1; done",
|
|
190
|
-
"bench": "vitest bench --run",
|
|
191
190
|
"test": "vitest run",
|
|
192
191
|
"test:coverage": "vitest run --coverage",
|
|
193
192
|
"test:watch": "vitest"
|