@codefast/di 0.3.14-canary.0 → 0.3.14-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 +28 -0
- package/README.md +54 -29
- package/dist/binding-scope.d.mts +11 -0
- package/dist/binding-scope.mjs +19 -0
- package/dist/binding-select.d.mts +8 -26
- package/dist/binding-select.mjs +56 -49
- package/dist/binding.d.mts +107 -327
- package/dist/binding.mjs +19 -324
- package/dist/constraints.d.mts +11 -29
- package/dist/constraints.mjs +32 -36
- package/dist/constructor-type.d.mts +17 -0
- package/dist/constructor-type.mjs +1 -0
- package/dist/container.d.mts +44 -128
- package/dist/container.mjs +664 -433
- package/dist/decorators/inject.d.mts +19 -50
- package/dist/decorators/inject.mjs +131 -93
- package/dist/decorators/injectable.d.mts +16 -37
- package/dist/decorators/injectable.mjs +47 -66
- package/dist/decorators/lifecycle-decorators.d.mts +2 -22
- package/dist/decorators/lifecycle-decorators.mjs +81 -37
- package/dist/dependency-graph.d.mts +24 -54
- package/dist/dependency-graph.mjs +51 -153
- package/dist/environment.d.mts +38 -12
- package/dist/environment.mjs +82 -16
- package/dist/errors.d.mts +69 -188
- package/dist/errors.mjs +92 -219
- package/dist/graph-adapters/cytoscape.d.mts +24 -0
- package/dist/graph-adapters/cytoscape.mjs +23 -0
- package/dist/graph-adapters/dot.d.mts +6 -0
- package/dist/graph-adapters/dot.mjs +17 -0
- package/dist/graph-adapters/reactflow.d.mts +29 -0
- package/dist/graph-adapters/reactflow.mjs +29 -0
- package/dist/graph-adapters/types.d.mts +2 -0
- package/dist/graph-adapters/types.mjs +1 -0
- package/dist/index.d.mts +16 -9
- package/dist/index.mjs +8 -5
- package/dist/inspector.d.mts +34 -95
- package/dist/inspector.mjs +57 -256
- package/dist/lifecycle.d.mts +20 -53
- package/dist/lifecycle.mjs +129 -99
- package/dist/metadata/metadata-keys.d.mts +9 -26
- package/dist/metadata/metadata-keys.mjs +7 -28
- package/dist/metadata/metadata-reader-token.d.mts +7 -0
- package/dist/metadata/metadata-reader-token.mjs +5 -0
- package/dist/metadata/metadata-types.d.mts +22 -71
- package/dist/metadata/symbol-metadata-reader.d.mts +10 -26
- package/dist/metadata/symbol-metadata-reader.mjs +32 -45
- package/dist/module.d.mts +30 -84
- package/dist/module.mjs +26 -72
- package/dist/registry.d.mts +32 -63
- package/dist/registry.mjs +131 -82
- package/dist/resolve-options.d.mts +18 -0
- package/dist/resolve-options.mjs +22 -0
- package/dist/resolver.d.mts +67 -190
- package/dist/resolver.mjs +715 -424
- package/dist/scope.d.mts +19 -102
- package/dist/scope.mjs +37 -192
- package/dist/token.d.mts +8 -22
- package/dist/token.mjs +9 -11
- package/dist/types.d.mts +48 -0
- package/dist/types.mjs +1 -0
- package/package.json +52 -14
- package/dist/metadata/param-registry.d.mts +0 -16
- package/dist/metadata/param-registry.mjs +0 -31
- package/dist/scope-validation.d.mts +0 -21
- package/dist/scope-validation.mjs +0 -35
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
//#region src/metadata/param-registry.ts
|
|
2
|
-
/**
|
|
3
|
-
* WeakMap keyed by constructor → pending parameter metadata.
|
|
4
|
-
* Entries are populated by legacy parameter decorators that fire *before* the
|
|
5
|
-
* `@injectable()` class decorator runs, and consumed (via {@link takePendingMap})
|
|
6
|
-
* by the class decorator to merge into the final {@link ConstructorMetadata}.
|
|
7
|
-
*/
|
|
8
|
-
const pendingByConstructor = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
/**
|
|
10
|
-
* Returns the pending `ParamMetadata` map for `implementationClass`, creating it on first access.
|
|
11
|
-
* Used by legacy parameter decorators that fire before the class decorator runs.
|
|
12
|
-
*/
|
|
13
|
-
function getOrCreatePendingMap(implementationClass) {
|
|
14
|
-
let map = pendingByConstructor.get(implementationClass);
|
|
15
|
-
if (!map) {
|
|
16
|
-
map = /* @__PURE__ */ new Map();
|
|
17
|
-
pendingByConstructor.set(implementationClass, map);
|
|
18
|
-
}
|
|
19
|
-
return map;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Removes and returns the pending map for `implementationClass` (transfer of ownership).
|
|
23
|
-
* Returns `undefined` if no pending entries exist.
|
|
24
|
-
*/
|
|
25
|
-
function takePendingMap(implementationClass) {
|
|
26
|
-
const map = pendingByConstructor.get(implementationClass);
|
|
27
|
-
if (map) pendingByConstructor.delete(implementationClass);
|
|
28
|
-
return map;
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { getOrCreatePendingMap, takePendingMap };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { RegistryKey } from "./registry.mjs";
|
|
2
|
-
import { Binding } from "./binding.mjs";
|
|
3
|
-
import { MetadataReader } from "./metadata/metadata-types.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/scope-validation.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Walks every binding in the registry and throws {@link ScopeViolationError} on the first
|
|
8
|
-
* captive-dependency violation found **along a direct static edge**: for each binding, only
|
|
9
|
-
* targets returned by {@link listResolvedDependencies} are considered (not a full recursive
|
|
10
|
-
* graph walk). Constant bindings are exempt.
|
|
11
|
-
*
|
|
12
|
-
* Called by {@link Container.validate} and automatically after each `load()` in non-production
|
|
13
|
-
* environments.
|
|
14
|
-
*/
|
|
15
|
-
declare function validateScopeRules(context: {
|
|
16
|
-
collectAllRegistryKeys(): readonly RegistryKey[];
|
|
17
|
-
lookupBindings(key: RegistryKey): readonly Binding<unknown>[] | undefined;
|
|
18
|
-
getMetadataReader(): MetadataReader | undefined;
|
|
19
|
-
}): void;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { validateScopeRules };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ScopeViolationError } from "./errors.mjs";
|
|
2
|
-
import { registryKeyLabel } from "./binding-select.mjs";
|
|
3
|
-
import { listResolvedDependencies } from "./dependency-graph.mjs";
|
|
4
|
-
//#region src/scope-validation.ts
|
|
5
|
-
/**
|
|
6
|
-
* Walks every binding in the registry and throws {@link ScopeViolationError} on the first
|
|
7
|
-
* captive-dependency violation found **along a direct static edge**: for each binding, only
|
|
8
|
-
* targets returned by {@link listResolvedDependencies} are considered (not a full recursive
|
|
9
|
-
* graph walk). Constant bindings are exempt.
|
|
10
|
-
*
|
|
11
|
-
* Called by {@link Container.validate} and automatically after each `load()` in non-production
|
|
12
|
-
* environments.
|
|
13
|
-
*/
|
|
14
|
-
function validateScopeRules(context) {
|
|
15
|
-
const reader = context.getMetadataReader();
|
|
16
|
-
const lookupBindings = (key) => context.lookupBindings(key);
|
|
17
|
-
for (const registryKey of context.collectAllRegistryKeys()) {
|
|
18
|
-
const bindings = lookupBindings(registryKey);
|
|
19
|
-
if (bindings === void 0 || bindings.length === 0) continue;
|
|
20
|
-
for (const consumer of bindings) {
|
|
21
|
-
const deps = listResolvedDependencies(consumer, lookupBindings, reader, [registryKeyLabel(registryKey)]);
|
|
22
|
-
for (const dep of deps) if (consumer.scope === "singleton" && dep.binding.kind !== "constant" && (dep.binding.scope === "transient" || dep.binding.scope === "scoped")) throw new ScopeViolationError({
|
|
23
|
-
consumerBindingId: consumer.id,
|
|
24
|
-
consumerKind: consumer.kind,
|
|
25
|
-
consumerScope: consumer.scope,
|
|
26
|
-
dependencyBindingId: dep.binding.id,
|
|
27
|
-
dependencyKind: dep.binding.kind,
|
|
28
|
-
dependencyScope: dep.binding.scope,
|
|
29
|
-
resolutionPath: dep.path
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { validateScopeRules };
|