@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/dist/index.d.cts
CHANGED
|
@@ -540,6 +540,19 @@ declare function Qualifier(name: string): ParameterDecorator;
|
|
|
540
540
|
* - Anything else: `<unknown token>` (defensive — should never happen)
|
|
541
541
|
*/
|
|
542
542
|
declare function describeToken(token: Token): string;
|
|
543
|
+
/**
|
|
544
|
+
* Renders a constructor's name for a diagnostic, falling back when it has none.
|
|
545
|
+
*
|
|
546
|
+
* `??` is WRONG here and was used at four call sites until 2026-09-01. An
|
|
547
|
+
* anonymous class does not have an absent `name` — it has `""`, and `"" ?? x` is
|
|
548
|
+
* `""`. So the fallbacks never fired, and a consumer who passed a class
|
|
549
|
+
* expression read `Class has no @Module() decorator.`: two spaces where the
|
|
550
|
+
* identity should be, and nothing at all to search the codebase for.
|
|
551
|
+
*
|
|
552
|
+
* `describeToken` above had the check right (`name.length > 0`) and the other
|
|
553
|
+
* sites drifted from it, so the knowledge lives in one place now.
|
|
554
|
+
*/
|
|
555
|
+
declare function describeClassName(target: unknown, fallback: string): string;
|
|
543
556
|
/**
|
|
544
557
|
* Thrown when `resolve()` / `resolveAsync()` is asked for a token that
|
|
545
558
|
* was never registered.
|
|
@@ -742,4 +755,4 @@ declare class CyclicModuleImportError extends Error {
|
|
|
742
755
|
constructor(cycle: ReadonlyArray<string>);
|
|
743
756
|
}
|
|
744
757
|
|
|
745
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeToken };
|
|
758
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -540,6 +540,19 @@ declare function Qualifier(name: string): ParameterDecorator;
|
|
|
540
540
|
* - Anything else: `<unknown token>` (defensive — should never happen)
|
|
541
541
|
*/
|
|
542
542
|
declare function describeToken(token: Token): string;
|
|
543
|
+
/**
|
|
544
|
+
* Renders a constructor's name for a diagnostic, falling back when it has none.
|
|
545
|
+
*
|
|
546
|
+
* `??` is WRONG here and was used at four call sites until 2026-09-01. An
|
|
547
|
+
* anonymous class does not have an absent `name` — it has `""`, and `"" ?? x` is
|
|
548
|
+
* `""`. So the fallbacks never fired, and a consumer who passed a class
|
|
549
|
+
* expression read `Class has no @Module() decorator.`: two spaces where the
|
|
550
|
+
* identity should be, and nothing at all to search the codebase for.
|
|
551
|
+
*
|
|
552
|
+
* `describeToken` above had the check right (`name.length > 0`) and the other
|
|
553
|
+
* sites drifted from it, so the knowledge lives in one place now.
|
|
554
|
+
*/
|
|
555
|
+
declare function describeClassName(target: unknown, fallback: string): string;
|
|
543
556
|
/**
|
|
544
557
|
* Thrown when `resolve()` / `resolveAsync()` is asked for a token that
|
|
545
558
|
* was never registered.
|
|
@@ -742,4 +755,4 @@ declare class CyclicModuleImportError extends Error {
|
|
|
742
755
|
constructor(cycle: ReadonlyArray<string>);
|
|
743
756
|
}
|
|
744
757
|
|
|
745
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeToken };
|
|
758
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,11 @@ function describeToken(token) {
|
|
|
14
14
|
return "<unknown token>";
|
|
15
15
|
}
|
|
16
16
|
__name(describeToken, "describeToken");
|
|
17
|
+
function describeClassName(target, fallback) {
|
|
18
|
+
const name = target?.name;
|
|
19
|
+
return typeof name === "string" && name.length > 0 ? name : fallback;
|
|
20
|
+
}
|
|
21
|
+
__name(describeClassName, "describeClassName");
|
|
17
22
|
var TokenNotFoundError = class extends Error {
|
|
18
23
|
static {
|
|
19
24
|
__name(this, "TokenNotFoundError");
|
|
@@ -75,7 +80,7 @@ var MissingInjectableError = class extends Error {
|
|
|
75
80
|
target;
|
|
76
81
|
name = "MissingInjectableError";
|
|
77
82
|
constructor(target) {
|
|
78
|
-
super(`Class ${target
|
|
83
|
+
super(`Class ${describeClassName(target, "<anonymous>")} has no @Injectable() decorator. Add @Injectable() above the class declaration before registering it.`), this.target = target;
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
var ContainerDisposedError = class extends Error {
|
|
@@ -118,14 +123,15 @@ function findCycles(snapshot) {
|
|
|
118
123
|
const cycles = [];
|
|
119
124
|
const seenCycles = /* @__PURE__ */ new Set();
|
|
120
125
|
const visited = /* @__PURE__ */ new Set();
|
|
126
|
+
const tokenIds = /* @__PURE__ */ new Map();
|
|
121
127
|
for (const node of snapshot.nodes) {
|
|
122
128
|
if (visited.has(node.token)) continue;
|
|
123
|
-
iterativeDfs(node.token, adjacency, visited, cycles, seenCycles);
|
|
129
|
+
iterativeDfs(node.token, adjacency, visited, cycles, seenCycles, tokenIds);
|
|
124
130
|
}
|
|
125
131
|
return cycles;
|
|
126
132
|
}
|
|
127
133
|
__name(findCycles, "findCycles");
|
|
128
|
-
function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
134
|
+
function iterativeDfs(root, adjacency, visited, out, seenCycles, tokenIds) {
|
|
129
135
|
const stack = [];
|
|
130
136
|
const onPath = /* @__PURE__ */ new Set();
|
|
131
137
|
const pathOrder = [];
|
|
@@ -158,7 +164,7 @@ function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
|
158
164
|
...pathOrder.slice(cycleStart),
|
|
159
165
|
neighbor
|
|
160
166
|
];
|
|
161
|
-
const key = canonicalCycleKey(cycle);
|
|
167
|
+
const key = canonicalCycleKey(cycle, tokenIds);
|
|
162
168
|
if (!seenCycles.has(key)) {
|
|
163
169
|
seenCycles.add(key);
|
|
164
170
|
out.push(cycle);
|
|
@@ -169,26 +175,27 @@ function iterativeDfs(root, adjacency, visited, out, seenCycles) {
|
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
177
|
__name(iterativeDfs, "iterativeDfs");
|
|
172
|
-
function canonicalCycleKey(cycle) {
|
|
173
|
-
const
|
|
178
|
+
function canonicalCycleKey(cycle, tokenIds) {
|
|
179
|
+
const ids = cycle.map((token) => {
|
|
180
|
+
let id = tokenIds.get(token);
|
|
181
|
+
if (id === void 0) {
|
|
182
|
+
id = tokenIds.size;
|
|
183
|
+
tokenIds.set(token, id);
|
|
184
|
+
}
|
|
185
|
+
return id;
|
|
186
|
+
});
|
|
174
187
|
let minIndex = 0;
|
|
175
|
-
for (let i = 1; i <
|
|
176
|
-
if (
|
|
188
|
+
for (let i = 1; i < ids.length; i += 1) {
|
|
189
|
+
if (ids[i] < ids[minIndex]) {
|
|
177
190
|
minIndex = i;
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
return [
|
|
181
|
-
...
|
|
182
|
-
...
|
|
194
|
+
...ids.slice(minIndex),
|
|
195
|
+
...ids.slice(0, minIndex)
|
|
183
196
|
].join("\u2192");
|
|
184
197
|
}
|
|
185
198
|
__name(canonicalCycleKey, "canonicalCycleKey");
|
|
186
|
-
function stringifyToken(token) {
|
|
187
|
-
if (typeof token === "string") return `s:${token}`;
|
|
188
|
-
if (typeof token === "function") return `c:${token.name ?? "<anon>"}`;
|
|
189
|
-
return "u:<unknown>";
|
|
190
|
-
}
|
|
191
|
-
__name(stringifyToken, "stringifyToken");
|
|
192
199
|
|
|
193
200
|
// src/internal/metadata.ts
|
|
194
201
|
var METADATA_KEYS = {
|
|
@@ -333,7 +340,7 @@ var InvalidModuleError = class extends Error {
|
|
|
333
340
|
target;
|
|
334
341
|
name = "InvalidModuleError";
|
|
335
342
|
constructor(target) {
|
|
336
|
-
super(`Class ${target
|
|
343
|
+
super(`Class ${describeClassName(target, "<anonymous>")} has no @Module() decorator. Add @Module({ providers: [...], imports: [...], exports: [...] }) above the class declaration.`), this.target = target;
|
|
337
344
|
}
|
|
338
345
|
};
|
|
339
346
|
var InvalidExportError = class extends Error {
|
|
@@ -778,7 +785,7 @@ var Container = class {
|
|
|
778
785
|
*/
|
|
779
786
|
handlePrimitiveParam(target, paramType, index, isOptional) {
|
|
780
787
|
if (isOptional) return void 0;
|
|
781
|
-
throw new TypeError(`Class ${target.name} has a primitive/interface constructor parameter at index ${index} (emitted as ${paramType
|
|
788
|
+
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.`);
|
|
782
789
|
}
|
|
783
790
|
/**
|
|
784
791
|
* Attempt sync resolution. Returns `{ args }` on success, `{ needsAsync: true }`
|
|
@@ -1135,6 +1142,6 @@ function Qualifier(name) {
|
|
|
1135
1142
|
}
|
|
1136
1143
|
__name(Qualifier, "Qualifier");
|
|
1137
1144
|
|
|
1138
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, Container, ContainerDisposedError, ContainerFrozenError, CyclicDependencyError, CyclicModuleImportError, Inject, Injectable, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, Optional, PostConstruct, PreDestroy, Primary, Qualifier, ReflectMetadataMissingError, Scope, ScopeViolationError, TokenNotFoundError, describeToken };
|
|
1145
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, Container, ContainerDisposedError, ContainerFrozenError, CyclicDependencyError, CyclicModuleImportError, Inject, Injectable, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, Optional, PostConstruct, PreDestroy, Primary, Qualifier, ReflectMetadataMissingError, Scope, ScopeViolationError, TokenNotFoundError, describeClassName, describeToken };
|
|
1139
1146
|
//# sourceMappingURL=index.js.map
|
|
1140
1147
|
//# sourceMappingURL=index.js.map
|