@theokit/di 0.2.0 → 0.2.1
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 +50 -1
- package/dist/index.cjs +26 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8e59fec: Name an anonymous class `<anonymous>` in diagnostics instead of rendering nothing.
|
|
8
|
+
|
|
9
|
+
Four call sites wrote a class name as `target.name ?? "<anonymous>"`, and that fallback could never
|
|
10
|
+
fire: an anonymous class has `name === ""`, not an absent one, and `"" ?? x` is `""`. A consumer who
|
|
11
|
+
passed a class expression read `Class has no @Module() decorator.` — two spaces where the identity
|
|
12
|
+
belongs, and nothing to search the codebase for. `MissingInjectableError`, `InvalidModuleError`, the
|
|
13
|
+
`emitted as ...` hint in constructor-parameter diagnostics and the cycle labels in `analyze()` are
|
|
14
|
+
all affected.
|
|
15
|
+
|
|
16
|
+
`describeToken` in the same file had the check right all along (`name.length > 0`); the other sites
|
|
17
|
+
had drifted from it. The knowledge now lives in one exported helper, `describeClassName`.
|
|
18
|
+
|
|
19
|
+
- 452d6ba: `analyze()` no longer drops a cycle when two classes share a name.
|
|
20
|
+
|
|
21
|
+
`findCycles` de-duplicated cycles by the token's RENDERING rather than by the token, so two different
|
|
22
|
+
classes with the same `name` produced the same key and the second cycle was discarded as a duplicate
|
|
23
|
+
of the first. Two files each declaring `class Logger` and `class Service` was enough to trigger it, as
|
|
24
|
+
was any two anonymous classes or any two symbol tokens: `analyze()` reported one cycle, and nothing
|
|
25
|
+
said the other had been dropped. A consumer debugging a cyclic dependency fixed the loop they were
|
|
26
|
+
shown and met the next one on the following run.
|
|
27
|
+
|
|
28
|
+
Cycles are now keyed on an identity table. The rotation that makes the key independent of which node
|
|
29
|
+
the walk entered on is unchanged.
|
|
30
|
+
|
|
3
31
|
All notable changes to `@theokit/di` are documented in this file.
|
|
4
32
|
|
|
5
33
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
@@ -7,6 +35,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
35
|
|
|
8
36
|
## [Unreleased]
|
|
9
37
|
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- `analyze()` no longer drops a cycle when two classes share a name. Cycles were de-duplicated by the
|
|
41
|
+
token's rendering rather than by the token, so two different classes called `Logger` keyed
|
|
42
|
+
identically and the second cycle was discarded as a duplicate of the first — one cycle reported,
|
|
43
|
+
and nothing to say the other existed. Two anonymous classes and two symbol tokens collided the same
|
|
44
|
+
way. The key is built from an identity table now (#59).
|
|
45
|
+
|
|
46
|
+
- An anonymous class in an error message is now named `<anonymous>` instead of nothing at all.
|
|
47
|
+
Four diagnostics rendered a class name as `target.name ?? "<anonymous>"`, and that fallback can
|
|
48
|
+
never fire — an anonymous class has `name === ""`, not an absent one, so `??` passes the empty
|
|
49
|
+
string straight through. A consumer who passed a class expression read `Class has no @Module()
|
|
50
|
+
decorator.`, with two spaces where the identity belongs and nothing to search for. Affects
|
|
51
|
+
`MissingInjectableError`, `InvalidModuleError`, the `emitted as ...` hint in the container's
|
|
52
|
+
parameter diagnostics, and cycle labels in `analyze()` (#57).
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- `describeClassName(target, fallback)` is exported alongside `describeToken`. The four sites above
|
|
57
|
+
had each written their own version of "a class's display name, with a fallback"; `describeToken`
|
|
58
|
+
was the only one that got it right, and now it is the only one that states it (#57).
|
|
59
|
+
|
|
10
60
|
## [0.2.0] - 2026-08-21
|
|
11
61
|
|
|
12
62
|
### Added
|
|
@@ -43,7 +93,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
43
93
|
- `@Primary` and `@Qualifier` documented a resolution priority the container has never had. They record metadata and nothing else, and their JSDoc now says exactly that, with the working alternative alongside. Implementing them means holding several registrations per token — which is the cache key, the cycle-detection node identity and the disposal order — so it is a design decision rather than a missing branch, and it has not been made (#5).
|
|
44
94
|
- The English-only lint gate could not fail on an accented word. It split identifiers with an ASCII-only pattern before testing them for diacritics, so `não` became `n` and `o` and the diacritic tier was unreachable. Both tiers now work, verified by planting an accented identifier and watching the sweep turn red (#7).
|
|
45
95
|
|
|
46
|
-
|
|
47
96
|
## 0.1.1
|
|
48
97
|
|
|
49
98
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -16,6 +16,11 @@ function describeToken(token) {
|
|
|
16
16
|
return "<unknown token>";
|
|
17
17
|
}
|
|
18
18
|
__name(describeToken, "describeToken");
|
|
19
|
+
function describeClassName(target, fallback) {
|
|
20
|
+
const name = target?.name;
|
|
21
|
+
return typeof name === "string" && name.length > 0 ? name : fallback;
|
|
22
|
+
}
|
|
23
|
+
__name(describeClassName, "describeClassName");
|
|
19
24
|
var TokenNotFoundError = class extends Error {
|
|
20
25
|
static {
|
|
21
26
|
__name(this, "TokenNotFoundError");
|
|
@@ -77,7 +82,7 @@ var MissingInjectableError = class extends Error {
|
|
|
77
82
|
target;
|
|
78
83
|
name = "MissingInjectableError";
|
|
79
84
|
constructor(target) {
|
|
80
|
-
super(`Class ${target
|
|
85
|
+
super(`Class ${describeClassName(target, "<anonymous>")} has no @Injectable() decorator. Add @Injectable() above the class declaration before registering it.`), this.target = target;
|
|
81
86
|
}
|
|
82
87
|
};
|
|
83
88
|
var ContainerDisposedError = class extends Error {
|
|
@@ -120,14 +125,15 @@ function findCycles(snapshot) {
|
|
|
120
125
|
const cycles = [];
|
|
121
126
|
const seenCycles = /* @__PURE__ */ new Set();
|
|
122
127
|
const visited = /* @__PURE__ */ new Set();
|
|
128
|
+
const tokenIds = /* @__PURE__ */ new Map();
|
|
123
129
|
for (const node of snapshot.nodes) {
|
|
124
130
|
if (visited.has(node.token)) continue;
|
|
125
|
-
iterativeDfs(node.token, adjacency, visited, cycles, seenCycles);
|
|
131
|
+
iterativeDfs(node.token, adjacency, visited, cycles, seenCycles, tokenIds);
|
|
126
132
|
}
|
|
127
133
|
return cycles;
|
|
128
134
|
}
|
|
129
135
|
__name(findCycles, "findCycles");
|
|
130
|
-
function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
136
|
+
function iterativeDfs(root, adjacency, visited, out, seenCycles, tokenIds) {
|
|
131
137
|
const stack = [];
|
|
132
138
|
const onPath = /* @__PURE__ */ new Set();
|
|
133
139
|
const pathOrder = [];
|
|
@@ -160,7 +166,7 @@ function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
|
160
166
|
...pathOrder.slice(cycleStart),
|
|
161
167
|
neighbor
|
|
162
168
|
];
|
|
163
|
-
const key = canonicalCycleKey(cycle);
|
|
169
|
+
const key = canonicalCycleKey(cycle, tokenIds);
|
|
164
170
|
if (!seenCycles.has(key)) {
|
|
165
171
|
seenCycles.add(key);
|
|
166
172
|
out.push(cycle);
|
|
@@ -171,26 +177,27 @@ function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
179
|
__name(iterativeDfs, "iterativeDfs");
|
|
174
|
-
function canonicalCycleKey(cycle) {
|
|
175
|
-
const
|
|
180
|
+
function canonicalCycleKey(cycle, tokenIds) {
|
|
181
|
+
const ids = cycle.map((token) => {
|
|
182
|
+
let id = tokenIds.get(token);
|
|
183
|
+
if (id === void 0) {
|
|
184
|
+
id = tokenIds.size;
|
|
185
|
+
tokenIds.set(token, id);
|
|
186
|
+
}
|
|
187
|
+
return id;
|
|
188
|
+
});
|
|
176
189
|
let minIndex = 0;
|
|
177
|
-
for (let i = 1; i <
|
|
178
|
-
if (
|
|
190
|
+
for (let i = 1; i < ids.length; i += 1) {
|
|
191
|
+
if (ids[i] < ids[minIndex]) {
|
|
179
192
|
minIndex = i;
|
|
180
193
|
}
|
|
181
194
|
}
|
|
182
195
|
return [
|
|
183
|
-
...
|
|
184
|
-
...
|
|
196
|
+
...ids.slice(minIndex),
|
|
197
|
+
...ids.slice(0, minIndex)
|
|
185
198
|
].join("\u2192");
|
|
186
199
|
}
|
|
187
200
|
__name(canonicalCycleKey, "canonicalCycleKey");
|
|
188
|
-
function stringifyToken(token) {
|
|
189
|
-
if (typeof token === "string") return `s:${token}`;
|
|
190
|
-
if (typeof token === "function") return `c:${token.name ?? "<anon>"}`;
|
|
191
|
-
return "u:<unknown>";
|
|
192
|
-
}
|
|
193
|
-
__name(stringifyToken, "stringifyToken");
|
|
194
201
|
|
|
195
202
|
// src/internal/metadata.ts
|
|
196
203
|
var METADATA_KEYS = {
|
|
@@ -335,7 +342,7 @@ var InvalidModuleError = class extends Error {
|
|
|
335
342
|
target;
|
|
336
343
|
name = "InvalidModuleError";
|
|
337
344
|
constructor(target) {
|
|
338
|
-
super(`Class ${target
|
|
345
|
+
super(`Class ${describeClassName(target, "<anonymous>")} has no @Module() decorator. Add @Module({ providers: [...], imports: [...], exports: [...] }) above the class declaration.`), this.target = target;
|
|
339
346
|
}
|
|
340
347
|
};
|
|
341
348
|
var InvalidExportError = class extends Error {
|
|
@@ -780,7 +787,7 @@ var Container = class {
|
|
|
780
787
|
*/
|
|
781
788
|
handlePrimitiveParam(target, paramType, index, isOptional) {
|
|
782
789
|
if (isOptional) return void 0;
|
|
783
|
-
throw new TypeError(`Class ${target.name} has a primitive/interface constructor parameter at index ${index} (emitted as ${paramType
|
|
790
|
+
throw new TypeError(`Class ${target.name} has a primitive/interface constructor parameter at index ${index} (emitted as ${describeClassName(paramType, "<unknown>")}). Primitives and interfaces cannot be auto-resolved \u2014 use \`@Inject('SOME_STRING_TOKEN')\` to provide an explicit token.`);
|
|
784
791
|
}
|
|
785
792
|
/**
|
|
786
793
|
* Attempt sync resolution. Returns `{ args }` on success, `{ needsAsync: true }`
|
|
@@ -1160,6 +1167,7 @@ exports.ReflectMetadataMissingError = ReflectMetadataMissingError;
|
|
|
1160
1167
|
exports.Scope = Scope;
|
|
1161
1168
|
exports.ScopeViolationError = ScopeViolationError;
|
|
1162
1169
|
exports.TokenNotFoundError = TokenNotFoundError;
|
|
1170
|
+
exports.describeClassName = describeClassName;
|
|
1163
1171
|
exports.describeToken = describeToken;
|
|
1164
1172
|
//# sourceMappingURL=index.cjs.map
|
|
1165
1173
|
//# sourceMappingURL=index.cjs.map
|