@noego/testing 0.2.0 → 0.5.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/dist/index.cjs +171 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -7
- package/dist/index.d.ts +93 -7
- package/dist/index.js +168 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/dist/index.d.cts
CHANGED
|
@@ -130,12 +130,25 @@ declare class WatchRegistry {
|
|
|
130
130
|
private readonly states;
|
|
131
131
|
private readonly nameIndex;
|
|
132
132
|
private readonly entries;
|
|
133
|
+
/** Class-token entries that identity-matched at least one construction. */
|
|
134
|
+
private readonly matchedEntryKeys;
|
|
135
|
+
/** Constructed class tokens that matched NO entry, by display name. */
|
|
136
|
+
private readonly unmatchedConstructedByName;
|
|
133
137
|
addEntry(entry: MethodConfigEntry): void;
|
|
134
138
|
private entryLabel;
|
|
135
139
|
/** Entries applying to a resolving token (exact identity or name match). */
|
|
136
140
|
matchEntries(token: unknown): MethodConfigEntry[];
|
|
137
141
|
state(entryKey: unknown, method: string): MethodState | undefined;
|
|
138
142
|
inspect(token: unknown, method: string): MethodInspection;
|
|
143
|
+
/**
|
|
144
|
+
* Class-token entries that never identity-matched a construction while a
|
|
145
|
+
* DIFFERENT class with the same display name did construct. This is the
|
|
146
|
+
* split-module-registry signature (a test-file class object vs the graph's
|
|
147
|
+
* own load of the same file) — or two genuinely distinct same-named tokens
|
|
148
|
+
* where the configured one never resolved. Either way the configured
|
|
149
|
+
* behavior silently did not apply, which must be loud.
|
|
150
|
+
*/
|
|
151
|
+
private identitySplits;
|
|
139
152
|
/** Repeatable snapshot check of all exact expectations. */
|
|
140
153
|
verify(): void;
|
|
141
154
|
}
|
|
@@ -151,9 +164,21 @@ declare class WatchRegistry {
|
|
|
151
164
|
*/
|
|
152
165
|
|
|
153
166
|
type Token = unknown;
|
|
154
|
-
type ClassLike = new (...args: any[]) => any;
|
|
167
|
+
type ClassLike$1 = new (...args: any[]) => any;
|
|
155
168
|
/** Config maps accept plain objects (string keys) or Maps (exact tokens). */
|
|
156
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Composition input (spec 04 §2). The CANONICAL entry form is an array of
|
|
171
|
+
* tuples — token-first, exact identity:
|
|
172
|
+
*
|
|
173
|
+
* .classes([[ProjectRepository, MemoryProjectRepository]])
|
|
174
|
+
*
|
|
175
|
+
* A `ReadonlyMap<Token, V>` is equivalent (token-keyed). A name-keyed
|
|
176
|
+
* `Record<string, V>` remains accepted as COMPATIBILITY input: string keys
|
|
177
|
+
* resolve against known token display names, fail on unknown names, and
|
|
178
|
+
* fail on ambiguous names (two tokens sharing one display name never
|
|
179
|
+
* collapse into one entry — tokens are identities, names are labels).
|
|
180
|
+
*/
|
|
181
|
+
type ConfigMap<V> = ReadonlyArray<readonly [Token, V]> | ReadonlyMap<Token, V> | Record<string, V>;
|
|
157
182
|
type MethodsConfig = ConfigMap<Record<string, MethodDescriptor> | ReadonlyMap<string, MethodDescriptor>>;
|
|
158
183
|
type UseInput = ApplicationModule | TestIocBuilder;
|
|
159
184
|
type Write = {
|
|
@@ -163,7 +188,7 @@ type Write = {
|
|
|
163
188
|
op: 'classes';
|
|
164
189
|
key: Token;
|
|
165
190
|
byName: boolean;
|
|
166
|
-
implementation: ClassLike;
|
|
191
|
+
implementation: ClassLike$1;
|
|
167
192
|
} | {
|
|
168
193
|
op: 'functions';
|
|
169
194
|
key: Token;
|
|
@@ -180,6 +205,10 @@ type Write = {
|
|
|
180
205
|
byName: boolean;
|
|
181
206
|
methods: ReadonlyMap<string, MethodDescriptor>;
|
|
182
207
|
};
|
|
208
|
+
interface BuildOptions {
|
|
209
|
+
/** Compose production registrations on the fresh root before the seams. */
|
|
210
|
+
prepare?: (root: IContainer) => void | Promise<void>;
|
|
211
|
+
}
|
|
183
212
|
interface TestEnvironment {
|
|
184
213
|
readonly root: IContainer;
|
|
185
214
|
get<T>(token: unknown, params?: any[]): Promise<T> | T;
|
|
@@ -201,15 +230,23 @@ declare class TestIocBuilder {
|
|
|
201
230
|
/** Apply a reusable composition preset: an ApplicationModule or a builder. */
|
|
202
231
|
use(preset: UseInput): TestIocBuilder;
|
|
203
232
|
/** Replace the implementation for IoC class tokens in the built environment. */
|
|
204
|
-
classes(config: ConfigMap<ClassLike>): TestIocBuilder;
|
|
233
|
+
classes(config: ConfigMap<ClassLike$1>): TestIocBuilder;
|
|
205
234
|
/** Replace IoC factory/provider registrations. */
|
|
206
235
|
functions(config: ConfigMap<(...args: any[]) => any>): TestIocBuilder;
|
|
207
236
|
/** Provide/replace IoC value registrations. */
|
|
208
237
|
values(config: ConfigMap<unknown>): TestIocBuilder;
|
|
209
238
|
/** Install method behavior/observation descriptors on IoC-managed instances. */
|
|
210
239
|
methods(config: MethodsConfig): TestIocBuilder;
|
|
211
|
-
/**
|
|
212
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Materialize a fresh, isolated real-IoC environment. Non-consuming.
|
|
242
|
+
*
|
|
243
|
+
* `prepare` runs on the fresh root BEFORE this builder's registrations and
|
|
244
|
+
* the method-control decorator are applied: the place for an application's
|
|
245
|
+
* production composition, so every declared seam shadows what production
|
|
246
|
+
* registered for the same token, and instances constructed later are
|
|
247
|
+
* decorated. Instances `prepare` constructs itself are not decorated.
|
|
248
|
+
*/
|
|
249
|
+
build(options?: BuildOptions): Promise<TestEnvironment>;
|
|
213
250
|
/**
|
|
214
251
|
* Register a class binding. When token === implementation this is a plain
|
|
215
252
|
* class registration. Otherwise an alias factory resolves the implementation
|
|
@@ -268,5 +305,54 @@ declare class UnknownTokenKeyError extends TestingError {
|
|
|
268
305
|
/** Invalid descriptor construction (e.g. test.times(-1)). */
|
|
269
306
|
declare class InvalidDescriptorError extends TestingError {
|
|
270
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* A name-keyed compatibility entry referred to a display name claimed by
|
|
310
|
+
* two or more distinct tokens. Tokens are identities; names are labels —
|
|
311
|
+
* pass the exact token in canonical tuple form instead (spec 04 §5).
|
|
312
|
+
*/
|
|
313
|
+
declare class AmbiguousNameKeyError extends TestingError {
|
|
314
|
+
constructor(name: string, space: string);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* A .methods() class token never matched any constructed instance while a
|
|
318
|
+
* DIFFERENT class with the same display name did construct — the configured
|
|
319
|
+
* behavior silently did not apply. Usual cause: two module registries loaded
|
|
320
|
+
* the same source file (e.g. a vitest test file's import vs a framework
|
|
321
|
+
* harness's native import of the production graph); fix by routing the
|
|
322
|
+
* harness's imports through the caller's registry (testApp:
|
|
323
|
+
* `.importer((p) => import(p))`) or by passing the token the graph actually
|
|
324
|
+
* uses.
|
|
325
|
+
*/
|
|
326
|
+
declare class TokenIdentitySplitError extends TestingError {
|
|
327
|
+
constructor(names: readonly string[]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* `installSeams` — apply the canonical substitution language (classes /
|
|
332
|
+
* values / methods, exact tokens, `test.*` descriptors) to an EXISTING
|
|
333
|
+
* container instead of a fresh `testIoc()` root.
|
|
334
|
+
*
|
|
335
|
+
* This is the seam surface for composed harnesses (application slices,
|
|
336
|
+
* backend harnesses) that own their container construction but must speak
|
|
337
|
+
* the same substitution language as every other tier: one vocabulary, one
|
|
338
|
+
* verify contract, no harness-specific stubbing options.
|
|
339
|
+
*
|
|
340
|
+
* The returned handle carries the same watch registry marker as a
|
|
341
|
+
* `TestEnvironment`, so `test.inspect(handle, Token, 'method')` works
|
|
342
|
+
* unchanged.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
type ClassLike = new (...args: any[]) => any;
|
|
346
|
+
interface SeamsConfig {
|
|
347
|
+
classes?: ConfigMap<ClassLike>;
|
|
348
|
+
values?: ConfigMap<unknown>;
|
|
349
|
+
methods?: MethodsConfig;
|
|
350
|
+
}
|
|
351
|
+
interface InstalledSeams {
|
|
352
|
+
/** Finalize call-count expectations (same semantics as env.verify()). */
|
|
353
|
+
verify(): Promise<void>;
|
|
354
|
+
readonly [ENV_REGISTRY]: WatchRegistry;
|
|
355
|
+
}
|
|
356
|
+
declare function installSeams(root: IContainer, config: SeamsConfig): InstalledSeams;
|
|
271
357
|
|
|
272
|
-
export { type BehaviorDescriptor, CallScriptExhaustedError, type CallsDescriptor, type ConfigMap, ENV_REGISTRY, type ExpectationDescriptor, ExpectationOverflowError, InvalidDescriptorError, type MethodDescriptor, type MethodInspection, MethodNotCallableError, type MethodsConfig, MissingIocSeamError, NonObjectMethodTargetError, type OriginalDescriptor, type RawMethodWrapper, type RecordedCall, type ReturnsDescriptor, type TestEnvironment, TestIocBuilder, TestingError, type ThrowsDescriptor, UnknownTokenKeyError, UnwatchedInspectionError, type UseInput, VerificationError, type WatchDescriptor, test, testIoc };
|
|
358
|
+
export { AmbiguousNameKeyError, type BehaviorDescriptor, CallScriptExhaustedError, type CallsDescriptor, type ConfigMap, ENV_REGISTRY, type ExpectationDescriptor, ExpectationOverflowError, type InstalledSeams, InvalidDescriptorError, type MethodDescriptor, type MethodInspection, MethodNotCallableError, type MethodsConfig, MissingIocSeamError, NonObjectMethodTargetError, type OriginalDescriptor, type RawMethodWrapper, type RecordedCall, type ReturnsDescriptor, type SeamsConfig, type TestEnvironment, TestIocBuilder, TestingError, type ThrowsDescriptor, TokenIdentitySplitError, UnknownTokenKeyError, UnwatchedInspectionError, type UseInput, VerificationError, type WatchDescriptor, installSeams, test, testIoc };
|
package/dist/index.d.ts
CHANGED
|
@@ -130,12 +130,25 @@ declare class WatchRegistry {
|
|
|
130
130
|
private readonly states;
|
|
131
131
|
private readonly nameIndex;
|
|
132
132
|
private readonly entries;
|
|
133
|
+
/** Class-token entries that identity-matched at least one construction. */
|
|
134
|
+
private readonly matchedEntryKeys;
|
|
135
|
+
/** Constructed class tokens that matched NO entry, by display name. */
|
|
136
|
+
private readonly unmatchedConstructedByName;
|
|
133
137
|
addEntry(entry: MethodConfigEntry): void;
|
|
134
138
|
private entryLabel;
|
|
135
139
|
/** Entries applying to a resolving token (exact identity or name match). */
|
|
136
140
|
matchEntries(token: unknown): MethodConfigEntry[];
|
|
137
141
|
state(entryKey: unknown, method: string): MethodState | undefined;
|
|
138
142
|
inspect(token: unknown, method: string): MethodInspection;
|
|
143
|
+
/**
|
|
144
|
+
* Class-token entries that never identity-matched a construction while a
|
|
145
|
+
* DIFFERENT class with the same display name did construct. This is the
|
|
146
|
+
* split-module-registry signature (a test-file class object vs the graph's
|
|
147
|
+
* own load of the same file) — or two genuinely distinct same-named tokens
|
|
148
|
+
* where the configured one never resolved. Either way the configured
|
|
149
|
+
* behavior silently did not apply, which must be loud.
|
|
150
|
+
*/
|
|
151
|
+
private identitySplits;
|
|
139
152
|
/** Repeatable snapshot check of all exact expectations. */
|
|
140
153
|
verify(): void;
|
|
141
154
|
}
|
|
@@ -151,9 +164,21 @@ declare class WatchRegistry {
|
|
|
151
164
|
*/
|
|
152
165
|
|
|
153
166
|
type Token = unknown;
|
|
154
|
-
type ClassLike = new (...args: any[]) => any;
|
|
167
|
+
type ClassLike$1 = new (...args: any[]) => any;
|
|
155
168
|
/** Config maps accept plain objects (string keys) or Maps (exact tokens). */
|
|
156
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Composition input (spec 04 §2). The CANONICAL entry form is an array of
|
|
171
|
+
* tuples — token-first, exact identity:
|
|
172
|
+
*
|
|
173
|
+
* .classes([[ProjectRepository, MemoryProjectRepository]])
|
|
174
|
+
*
|
|
175
|
+
* A `ReadonlyMap<Token, V>` is equivalent (token-keyed). A name-keyed
|
|
176
|
+
* `Record<string, V>` remains accepted as COMPATIBILITY input: string keys
|
|
177
|
+
* resolve against known token display names, fail on unknown names, and
|
|
178
|
+
* fail on ambiguous names (two tokens sharing one display name never
|
|
179
|
+
* collapse into one entry — tokens are identities, names are labels).
|
|
180
|
+
*/
|
|
181
|
+
type ConfigMap<V> = ReadonlyArray<readonly [Token, V]> | ReadonlyMap<Token, V> | Record<string, V>;
|
|
157
182
|
type MethodsConfig = ConfigMap<Record<string, MethodDescriptor> | ReadonlyMap<string, MethodDescriptor>>;
|
|
158
183
|
type UseInput = ApplicationModule | TestIocBuilder;
|
|
159
184
|
type Write = {
|
|
@@ -163,7 +188,7 @@ type Write = {
|
|
|
163
188
|
op: 'classes';
|
|
164
189
|
key: Token;
|
|
165
190
|
byName: boolean;
|
|
166
|
-
implementation: ClassLike;
|
|
191
|
+
implementation: ClassLike$1;
|
|
167
192
|
} | {
|
|
168
193
|
op: 'functions';
|
|
169
194
|
key: Token;
|
|
@@ -180,6 +205,10 @@ type Write = {
|
|
|
180
205
|
byName: boolean;
|
|
181
206
|
methods: ReadonlyMap<string, MethodDescriptor>;
|
|
182
207
|
};
|
|
208
|
+
interface BuildOptions {
|
|
209
|
+
/** Compose production registrations on the fresh root before the seams. */
|
|
210
|
+
prepare?: (root: IContainer) => void | Promise<void>;
|
|
211
|
+
}
|
|
183
212
|
interface TestEnvironment {
|
|
184
213
|
readonly root: IContainer;
|
|
185
214
|
get<T>(token: unknown, params?: any[]): Promise<T> | T;
|
|
@@ -201,15 +230,23 @@ declare class TestIocBuilder {
|
|
|
201
230
|
/** Apply a reusable composition preset: an ApplicationModule or a builder. */
|
|
202
231
|
use(preset: UseInput): TestIocBuilder;
|
|
203
232
|
/** Replace the implementation for IoC class tokens in the built environment. */
|
|
204
|
-
classes(config: ConfigMap<ClassLike>): TestIocBuilder;
|
|
233
|
+
classes(config: ConfigMap<ClassLike$1>): TestIocBuilder;
|
|
205
234
|
/** Replace IoC factory/provider registrations. */
|
|
206
235
|
functions(config: ConfigMap<(...args: any[]) => any>): TestIocBuilder;
|
|
207
236
|
/** Provide/replace IoC value registrations. */
|
|
208
237
|
values(config: ConfigMap<unknown>): TestIocBuilder;
|
|
209
238
|
/** Install method behavior/observation descriptors on IoC-managed instances. */
|
|
210
239
|
methods(config: MethodsConfig): TestIocBuilder;
|
|
211
|
-
/**
|
|
212
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Materialize a fresh, isolated real-IoC environment. Non-consuming.
|
|
242
|
+
*
|
|
243
|
+
* `prepare` runs on the fresh root BEFORE this builder's registrations and
|
|
244
|
+
* the method-control decorator are applied: the place for an application's
|
|
245
|
+
* production composition, so every declared seam shadows what production
|
|
246
|
+
* registered for the same token, and instances constructed later are
|
|
247
|
+
* decorated. Instances `prepare` constructs itself are not decorated.
|
|
248
|
+
*/
|
|
249
|
+
build(options?: BuildOptions): Promise<TestEnvironment>;
|
|
213
250
|
/**
|
|
214
251
|
* Register a class binding. When token === implementation this is a plain
|
|
215
252
|
* class registration. Otherwise an alias factory resolves the implementation
|
|
@@ -268,5 +305,54 @@ declare class UnknownTokenKeyError extends TestingError {
|
|
|
268
305
|
/** Invalid descriptor construction (e.g. test.times(-1)). */
|
|
269
306
|
declare class InvalidDescriptorError extends TestingError {
|
|
270
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* A name-keyed compatibility entry referred to a display name claimed by
|
|
310
|
+
* two or more distinct tokens. Tokens are identities; names are labels —
|
|
311
|
+
* pass the exact token in canonical tuple form instead (spec 04 §5).
|
|
312
|
+
*/
|
|
313
|
+
declare class AmbiguousNameKeyError extends TestingError {
|
|
314
|
+
constructor(name: string, space: string);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* A .methods() class token never matched any constructed instance while a
|
|
318
|
+
* DIFFERENT class with the same display name did construct — the configured
|
|
319
|
+
* behavior silently did not apply. Usual cause: two module registries loaded
|
|
320
|
+
* the same source file (e.g. a vitest test file's import vs a framework
|
|
321
|
+
* harness's native import of the production graph); fix by routing the
|
|
322
|
+
* harness's imports through the caller's registry (testApp:
|
|
323
|
+
* `.importer((p) => import(p))`) or by passing the token the graph actually
|
|
324
|
+
* uses.
|
|
325
|
+
*/
|
|
326
|
+
declare class TokenIdentitySplitError extends TestingError {
|
|
327
|
+
constructor(names: readonly string[]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* `installSeams` — apply the canonical substitution language (classes /
|
|
332
|
+
* values / methods, exact tokens, `test.*` descriptors) to an EXISTING
|
|
333
|
+
* container instead of a fresh `testIoc()` root.
|
|
334
|
+
*
|
|
335
|
+
* This is the seam surface for composed harnesses (application slices,
|
|
336
|
+
* backend harnesses) that own their container construction but must speak
|
|
337
|
+
* the same substitution language as every other tier: one vocabulary, one
|
|
338
|
+
* verify contract, no harness-specific stubbing options.
|
|
339
|
+
*
|
|
340
|
+
* The returned handle carries the same watch registry marker as a
|
|
341
|
+
* `TestEnvironment`, so `test.inspect(handle, Token, 'method')` works
|
|
342
|
+
* unchanged.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
type ClassLike = new (...args: any[]) => any;
|
|
346
|
+
interface SeamsConfig {
|
|
347
|
+
classes?: ConfigMap<ClassLike>;
|
|
348
|
+
values?: ConfigMap<unknown>;
|
|
349
|
+
methods?: MethodsConfig;
|
|
350
|
+
}
|
|
351
|
+
interface InstalledSeams {
|
|
352
|
+
/** Finalize call-count expectations (same semantics as env.verify()). */
|
|
353
|
+
verify(): Promise<void>;
|
|
354
|
+
readonly [ENV_REGISTRY]: WatchRegistry;
|
|
355
|
+
}
|
|
356
|
+
declare function installSeams(root: IContainer, config: SeamsConfig): InstalledSeams;
|
|
271
357
|
|
|
272
|
-
export { type BehaviorDescriptor, CallScriptExhaustedError, type CallsDescriptor, type ConfigMap, ENV_REGISTRY, type ExpectationDescriptor, ExpectationOverflowError, InvalidDescriptorError, type MethodDescriptor, type MethodInspection, MethodNotCallableError, type MethodsConfig, MissingIocSeamError, NonObjectMethodTargetError, type OriginalDescriptor, type RawMethodWrapper, type RecordedCall, type ReturnsDescriptor, type TestEnvironment, TestIocBuilder, TestingError, type ThrowsDescriptor, UnknownTokenKeyError, UnwatchedInspectionError, type UseInput, VerificationError, type WatchDescriptor, test, testIoc };
|
|
358
|
+
export { AmbiguousNameKeyError, type BehaviorDescriptor, CallScriptExhaustedError, type CallsDescriptor, type ConfigMap, ENV_REGISTRY, type ExpectationDescriptor, ExpectationOverflowError, type InstalledSeams, InvalidDescriptorError, type MethodDescriptor, type MethodInspection, MethodNotCallableError, type MethodsConfig, MissingIocSeamError, NonObjectMethodTargetError, type OriginalDescriptor, type RawMethodWrapper, type RecordedCall, type ReturnsDescriptor, type SeamsConfig, type TestEnvironment, TestIocBuilder, TestingError, type ThrowsDescriptor, TokenIdentitySplitError, UnknownTokenKeyError, UnwatchedInspectionError, type UseInput, VerificationError, type WatchDescriptor, installSeams, test, testIoc };
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,22 @@ var UnknownTokenKeyError = class extends TestingError {
|
|
|
73
73
|
};
|
|
74
74
|
var InvalidDescriptorError = class extends TestingError {
|
|
75
75
|
};
|
|
76
|
+
var AmbiguousNameKeyError = class extends TestingError {
|
|
77
|
+
constructor(name, space) {
|
|
78
|
+
super(
|
|
79
|
+
`.${space}() key "${name}" is ambiguous: multiple distinct tokens share that display name. Use the canonical tuple form with the exact token: .${space}([[TheToken, ...]]).`
|
|
80
|
+
);
|
|
81
|
+
this.name = "AmbiguousNameKeyError";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var TokenIdentitySplitError = class extends TestingError {
|
|
85
|
+
constructor(names) {
|
|
86
|
+
super(
|
|
87
|
+
`token identity split: .methods() entr${names.length === 1 ? "y" : "ies"} for ${names.map((name) => `"${name}"`).join(", ")} never matched a constructed instance, but a DIFFERENT class with the same name was constructed. Two module registries have loaded the same class file (test-file import vs harness graph import) \u2014 the configured behavior did not apply. Route the harness's imports through your registry (e.g. testApp .importer((p) => import(p))) or pass the exact token the graph uses.`
|
|
88
|
+
);
|
|
89
|
+
this.name = "TokenIdentitySplitError";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
76
92
|
|
|
77
93
|
// src/descriptors.ts
|
|
78
94
|
var DESCRIPTOR = /* @__PURE__ */ Symbol.for("noego:testing:descriptor");
|
|
@@ -193,6 +209,10 @@ var WatchRegistry = class {
|
|
|
193
209
|
states = /* @__PURE__ */ new Map();
|
|
194
210
|
nameIndex = /* @__PURE__ */ new Map();
|
|
195
211
|
entries = [];
|
|
212
|
+
/** Class-token entries that identity-matched at least one construction. */
|
|
213
|
+
matchedEntryKeys = /* @__PURE__ */ new Set();
|
|
214
|
+
/** Constructed class tokens that matched NO entry, by display name. */
|
|
215
|
+
unmatchedConstructedByName = /* @__PURE__ */ new Map();
|
|
196
216
|
addEntry(entry) {
|
|
197
217
|
this.entries.push(entry);
|
|
198
218
|
const byMethod = /* @__PURE__ */ new Map();
|
|
@@ -212,9 +232,15 @@ var WatchRegistry = class {
|
|
|
212
232
|
/** Entries applying to a resolving token (exact identity or name match). */
|
|
213
233
|
matchEntries(token) {
|
|
214
234
|
const name = typeof token === "function" ? token.name : typeof token === "string" ? token : void 0;
|
|
215
|
-
|
|
235
|
+
const matched = this.entries.filter(
|
|
216
236
|
(entry) => entry.key === token || entry.byName && name !== void 0 && entry.key === name
|
|
217
237
|
);
|
|
238
|
+
if (matched.length) {
|
|
239
|
+
for (const entry of matched) this.matchedEntryKeys.add(entry.key);
|
|
240
|
+
} else if (typeof token === "function" && name) {
|
|
241
|
+
this.unmatchedConstructedByName.set(name, token);
|
|
242
|
+
}
|
|
243
|
+
return matched;
|
|
218
244
|
}
|
|
219
245
|
state(entryKey, method) {
|
|
220
246
|
return this.states.get(entryKey)?.get(method);
|
|
@@ -230,8 +256,34 @@ var WatchRegistry = class {
|
|
|
230
256
|
}
|
|
231
257
|
throw new UnwatchedInspectionError(label, method);
|
|
232
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Class-token entries that never identity-matched a construction while a
|
|
261
|
+
* DIFFERENT class with the same display name did construct. This is the
|
|
262
|
+
* split-module-registry signature (a test-file class object vs the graph's
|
|
263
|
+
* own load of the same file) — or two genuinely distinct same-named tokens
|
|
264
|
+
* where the configured one never resolved. Either way the configured
|
|
265
|
+
* behavior silently did not apply, which must be loud.
|
|
266
|
+
*/
|
|
267
|
+
identitySplits() {
|
|
268
|
+
const splits = [];
|
|
269
|
+
for (const entry of this.entries) {
|
|
270
|
+
if (entry.byName || typeof entry.key !== "function") continue;
|
|
271
|
+
if (this.matchedEntryKeys.has(entry.key)) continue;
|
|
272
|
+
const name = entry.key.name;
|
|
273
|
+
if (!name) continue;
|
|
274
|
+
const constructed = this.unmatchedConstructedByName.get(name);
|
|
275
|
+
if (constructed !== void 0 && constructed !== entry.key) {
|
|
276
|
+
splits.push({ name, entryToken: entry.key });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return splits;
|
|
280
|
+
}
|
|
233
281
|
/** Repeatable snapshot check of all exact expectations. */
|
|
234
282
|
verify() {
|
|
283
|
+
const splits = this.identitySplits();
|
|
284
|
+
if (splits.length) {
|
|
285
|
+
throw new TokenIdentitySplitError(splits.map((split) => split.name));
|
|
286
|
+
}
|
|
235
287
|
const failures = [];
|
|
236
288
|
for (const byMethod of this.states.values()) {
|
|
237
289
|
for (const state of byMethod.values()) {
|
|
@@ -380,7 +432,16 @@ function buildMethodWrapper(target, method, descriptor, state) {
|
|
|
380
432
|
// src/builder.ts
|
|
381
433
|
var COMPONENT_OPTIONS_KEY = /* @__PURE__ */ Symbol.for("ioc:component:options");
|
|
382
434
|
function* configEntries(config) {
|
|
383
|
-
if (config
|
|
435
|
+
if (Array.isArray(config)) {
|
|
436
|
+
for (const entry of config) {
|
|
437
|
+
if (!Array.isArray(entry) || entry.length !== 2) {
|
|
438
|
+
throw new InvalidDescriptorError(
|
|
439
|
+
"canonical composition entries are [token, value] tuples, e.g. .classes([[Token, Impl]])"
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
yield [entry[0], false, entry[1]];
|
|
443
|
+
}
|
|
444
|
+
} else if (config instanceof Map) {
|
|
384
445
|
for (const [key, value] of config) yield [key, false, value];
|
|
385
446
|
} else {
|
|
386
447
|
for (const key of [...Object.getOwnPropertyNames(config), ...Object.getOwnPropertySymbols(config)]) {
|
|
@@ -476,23 +537,40 @@ var TestIocBuilder = class _TestIocBuilder {
|
|
|
476
537
|
}
|
|
477
538
|
return this.derive(writes);
|
|
478
539
|
}
|
|
479
|
-
/**
|
|
480
|
-
|
|
540
|
+
/**
|
|
541
|
+
* Materialize a fresh, isolated real-IoC environment. Non-consuming.
|
|
542
|
+
*
|
|
543
|
+
* `prepare` runs on the fresh root BEFORE this builder's registrations and
|
|
544
|
+
* the method-control decorator are applied: the place for an application's
|
|
545
|
+
* production composition, so every declared seam shadows what production
|
|
546
|
+
* registered for the same token, and instances constructed later are
|
|
547
|
+
* decorated. Instances `prepare` constructs itself are not decorated.
|
|
548
|
+
*/
|
|
549
|
+
async build(options = {}) {
|
|
481
550
|
const root = createContainer();
|
|
482
551
|
if (typeof root.setInstanceDecorator !== "function") {
|
|
483
552
|
throw new MissingIocSeamError();
|
|
484
553
|
}
|
|
554
|
+
await options.prepare?.(root);
|
|
485
555
|
const knownByName = /* @__PURE__ */ new Map();
|
|
556
|
+
const ambiguousNames = /* @__PURE__ */ new Set();
|
|
486
557
|
const knownLifetimes = /* @__PURE__ */ new Map();
|
|
487
558
|
const note = (token, loadAs) => {
|
|
488
|
-
|
|
489
|
-
|
|
559
|
+
const name = typeof token === "function" && token.name ? token.name : typeof token === "string" ? token : null;
|
|
560
|
+
if (name !== null) {
|
|
561
|
+
const existing = knownByName.get(name);
|
|
562
|
+
if (existing !== void 0 && existing !== token) ambiguousNames.add(name);
|
|
563
|
+
knownByName.set(name, token);
|
|
564
|
+
}
|
|
490
565
|
if (loadAs !== void 0) knownLifetimes.set(token, loadAs);
|
|
491
566
|
};
|
|
492
567
|
const effective = /* @__PURE__ */ new Map();
|
|
493
568
|
const methodWrites = [];
|
|
494
569
|
const resolveKey = (key, byName, space) => {
|
|
495
570
|
if (!byName) return key;
|
|
571
|
+
if (ambiguousNames.has(key)) {
|
|
572
|
+
throw new AmbiguousNameKeyError(key, space);
|
|
573
|
+
}
|
|
496
574
|
const known = knownByName.get(key);
|
|
497
575
|
if (known !== void 0) return known;
|
|
498
576
|
if (space === "values" || space === "functions") return key;
|
|
@@ -537,8 +615,13 @@ var TestIocBuilder = class _TestIocBuilder {
|
|
|
537
615
|
space: "class",
|
|
538
616
|
token,
|
|
539
617
|
implementation: write.implementation,
|
|
540
|
-
//
|
|
541
|
-
|
|
618
|
+
// Lifetime priority: the replacement's own @Component scope, then
|
|
619
|
+
// the lifetime the composition already knows for the token, then
|
|
620
|
+
// the TOKEN class's declared @Component scope — a plain stub
|
|
621
|
+
// class replacing a Singleton-scoped production service must not
|
|
622
|
+
// silently degrade to Transient (captive-lifetime validation
|
|
623
|
+
// would reject the production dependents).
|
|
624
|
+
loadAs: componentScope(write.implementation) ?? knownLifetimes.get(token) ?? componentScope(token)
|
|
542
625
|
});
|
|
543
626
|
break;
|
|
544
627
|
}
|
|
@@ -563,6 +646,9 @@ var TestIocBuilder = class _TestIocBuilder {
|
|
|
563
646
|
break;
|
|
564
647
|
}
|
|
565
648
|
case "methods": {
|
|
649
|
+
if (write.byName && ambiguousNames.has(write.key)) {
|
|
650
|
+
throw new AmbiguousNameKeyError(write.key, "methods");
|
|
651
|
+
}
|
|
566
652
|
const token = write.byName && knownByName.has(write.key) ? knownByName.get(write.key) : write.key;
|
|
567
653
|
methodWrites.push({
|
|
568
654
|
key: token,
|
|
@@ -636,7 +722,79 @@ var TestIocBuilder = class _TestIocBuilder {
|
|
|
636
722
|
function testIoc(...inputs) {
|
|
637
723
|
return TestIocBuilder.create(inputs);
|
|
638
724
|
}
|
|
725
|
+
|
|
726
|
+
// src/seams.ts
|
|
727
|
+
import { LoadAs as LoadAs2, SCOPED_CONTAINER as SCOPED_CONTAINER2 } from "@noego/ioc";
|
|
728
|
+
var COMPONENT_OPTIONS_KEY2 = /* @__PURE__ */ Symbol.for("ioc:component:options");
|
|
729
|
+
function componentScope2(cls) {
|
|
730
|
+
const options = typeof Reflect !== "undefined" && Reflect.getMetadata ? Reflect.getMetadata(COMPONENT_OPTIONS_KEY2, cls) : void 0;
|
|
731
|
+
return options?.scope;
|
|
732
|
+
}
|
|
733
|
+
function* tupleEntries(config, space) {
|
|
734
|
+
if (Array.isArray(config)) {
|
|
735
|
+
for (const entry of config) {
|
|
736
|
+
if (!Array.isArray(entry) || entry.length !== 2) {
|
|
737
|
+
throw new InvalidDescriptorError(
|
|
738
|
+
`canonical ${space} entries are [token, value] tuples, e.g. .${space}([[Token, Impl]])`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
yield [entry[0], entry[1]];
|
|
742
|
+
}
|
|
743
|
+
} else if (config instanceof Map) {
|
|
744
|
+
for (const [key, value] of config) yield [key, value];
|
|
745
|
+
} else {
|
|
746
|
+
throw new InvalidDescriptorError(
|
|
747
|
+
`installSeams accepts only exact-token ${space} entries (tuple array or Map); name-keyed records need the composition knowledge only testIoc() has.`
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function registerClassBinding(root, token, implementation) {
|
|
752
|
+
const loadAs = componentScope2(implementation) ?? componentScope2(token) ?? LoadAs2.Singleton;
|
|
753
|
+
root.registerClass(implementation, { loadAs });
|
|
754
|
+
if (token === implementation) return;
|
|
755
|
+
if (loadAs === LoadAs2.Singleton) {
|
|
756
|
+
root.registerFunction(token, () => root.get(implementation), {
|
|
757
|
+
loadAs: LoadAs2.Singleton
|
|
758
|
+
});
|
|
759
|
+
} else {
|
|
760
|
+
root.registerFunction(token, (scope) => scope.get(implementation), {
|
|
761
|
+
loadAs,
|
|
762
|
+
param: [SCOPED_CONTAINER2]
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function installSeams(root, config) {
|
|
767
|
+
if (typeof root.setInstanceDecorator !== "function") {
|
|
768
|
+
throw new MissingIocSeamError();
|
|
769
|
+
}
|
|
770
|
+
for (const [token, implementation] of tupleEntries(config.classes ?? [], "classes")) {
|
|
771
|
+
registerClassBinding(root, token, implementation);
|
|
772
|
+
}
|
|
773
|
+
for (const [token, value] of tupleEntries(config.values ?? [], "values")) {
|
|
774
|
+
root.registerFunction(token, () => value, { loadAs: LoadAs2.Singleton });
|
|
775
|
+
}
|
|
776
|
+
const registry = new WatchRegistry();
|
|
777
|
+
for (const [token, methodsInput] of tupleEntries(config.methods ?? [], "methods")) {
|
|
778
|
+
const methods = /* @__PURE__ */ new Map();
|
|
779
|
+
const entries = methodsInput instanceof Map ? methodsInput.entries() : Object.entries(methodsInput);
|
|
780
|
+
for (const [name, descriptor] of entries) {
|
|
781
|
+
if (typeof descriptor !== "function" && !isDescriptor(descriptor)) {
|
|
782
|
+
throw new InvalidDescriptorError(
|
|
783
|
+
`.methods entry ${tokenLabel(token)}.${name} must be a test.* descriptor or a raw wrapper function.`
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
methods.set(name, descriptor);
|
|
787
|
+
}
|
|
788
|
+
registry.addEntry({ key: token, byName: false, methods });
|
|
789
|
+
}
|
|
790
|
+
root.setInstanceDecorator(createMethodDecorator(registry));
|
|
791
|
+
return {
|
|
792
|
+
verify: async () => registry.verify(),
|
|
793
|
+
[ENV_REGISTRY]: registry
|
|
794
|
+
};
|
|
795
|
+
}
|
|
639
796
|
export {
|
|
797
|
+
AmbiguousNameKeyError,
|
|
640
798
|
CallScriptExhaustedError,
|
|
641
799
|
ENV_REGISTRY,
|
|
642
800
|
ExpectationOverflowError,
|
|
@@ -646,9 +804,11 @@ export {
|
|
|
646
804
|
NonObjectMethodTargetError,
|
|
647
805
|
TestIocBuilder,
|
|
648
806
|
TestingError,
|
|
807
|
+
TokenIdentitySplitError,
|
|
649
808
|
UnknownTokenKeyError,
|
|
650
809
|
UnwatchedInspectionError,
|
|
651
810
|
VerificationError,
|
|
811
|
+
installSeams,
|
|
652
812
|
test,
|
|
653
813
|
testIoc
|
|
654
814
|
};
|