@navios/di 0.6.1 → 0.7.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/lib/browser/index.d.mts +5 -84
  3. package/lib/browser/index.d.mts.map +1 -1
  4. package/lib/browser/index.mjs +103 -484
  5. package/lib/browser/index.mjs.map +1 -1
  6. package/lib/{testing-DIaIRiJz.cjs → container-BCv3XS6m.cjs} +63 -459
  7. package/lib/container-BCv3XS6m.cjs.map +1 -0
  8. package/lib/{testing-BG_fa9TJ.mjs → container-Bv6PZZLJ.mjs} +63 -446
  9. package/lib/container-Bv6PZZLJ.mjs.map +1 -0
  10. package/lib/{index-DW3K5sOX.d.cts → container-CXDYDJSM.d.mts} +7 -62
  11. package/lib/container-CXDYDJSM.d.mts.map +1 -0
  12. package/lib/{index-7jfWsiG4.d.mts → container-b6mDUdGq.d.cts} +2 -67
  13. package/lib/container-b6mDUdGq.d.cts.map +1 -0
  14. package/lib/index.cjs +44 -52
  15. package/lib/index.cjs.map +1 -1
  16. package/lib/index.d.cts +6 -25
  17. package/lib/index.d.cts.map +1 -1
  18. package/lib/index.d.mts +6 -25
  19. package/lib/index.d.mts.map +1 -1
  20. package/lib/index.mjs +2 -2
  21. package/lib/testing/index.cjs +343 -4
  22. package/lib/testing/index.cjs.map +1 -0
  23. package/lib/testing/index.d.cts +65 -2
  24. package/lib/testing/index.d.cts.map +1 -0
  25. package/lib/testing/index.d.mts +65 -2
  26. package/lib/testing/index.d.mts.map +1 -0
  27. package/lib/testing/index.mjs +341 -2
  28. package/lib/testing/index.mjs.map +1 -0
  29. package/package.json +1 -1
  30. package/src/__tests__/async-local-storage.browser.spec.mts +18 -92
  31. package/src/__tests__/container.spec.mts +93 -0
  32. package/src/__tests__/e2e.browser.spec.mts +7 -15
  33. package/src/__tests__/library-findings.spec.mts +23 -21
  34. package/src/browser.mts +4 -9
  35. package/src/container/scoped-container.mts +14 -8
  36. package/src/index.mts +5 -8
  37. package/src/internal/context/async-local-storage.browser.mts +19 -0
  38. package/src/internal/context/async-local-storage.mts +46 -98
  39. package/src/internal/context/async-local-storage.types.mts +7 -0
  40. package/src/internal/context/resolution-context.mts +23 -5
  41. package/src/internal/context/sync-local-storage.mts +3 -1
  42. package/src/internal/core/instance-resolver.mts +8 -1
  43. package/src/internal/lifecycle/circular-detector.mts +15 -0
  44. package/tsdown.config.mts +12 -1
  45. package/vitest.config.mts +25 -3
  46. package/lib/index-7jfWsiG4.d.mts.map +0 -1
  47. package/lib/index-DW3K5sOX.d.cts.map +0 -1
  48. package/lib/testing-BG_fa9TJ.mjs.map +0 -1
  49. package/lib/testing-DIaIRiJz.cjs.map +0 -1
@@ -1,3 +1,4 @@
1
+ let node_async_hooks = require("node:async_hooks");
1
2
 
2
3
  //#region src/enums/injectable-scope.enum.mts
3
4
  let InjectableScope = /* @__PURE__ */ function(InjectableScope$1) {
@@ -195,96 +196,31 @@ var DIError = class DIError extends Error {
195
196
  }
196
197
  };
197
198
 
198
- //#endregion
199
- //#region src/internal/context/sync-local-storage.mts
200
- /**
201
- * A synchronous-only polyfill for AsyncLocalStorage.
202
- *
203
- * This provides the same API as Node's AsyncLocalStorage but only works
204
- * for synchronous code paths. It uses a simple stack-based approach.
205
- *
206
- * Limitations:
207
- * - Context does NOT propagate across async boundaries (setTimeout, promises, etc.)
208
- * - Only suitable for environments where DI resolution is synchronous
209
- *
210
- * This is acceptable for browser environments where:
211
- * 1. Constructors are typically synchronous
212
- * 2. Circular dependency detection mainly needs sync tracking
213
- */
214
- var SyncLocalStorage = class {
215
- stack = [];
216
- /**
217
- * Runs a function within the given store context.
218
- * The context is only available synchronously within the function.
219
- */
220
- run(store, fn) {
221
- this.stack.push(store);
222
- try {
223
- return fn();
224
- } finally {
225
- this.stack.pop();
226
- }
227
- }
228
- /**
229
- * Gets the current store value, or undefined if not in a context.
230
- */
231
- getStore() {
232
- return this.stack.length > 0 ? this.stack[this.stack.length - 1] : void 0;
233
- }
234
- /**
235
- * Exits the current context and runs the function without any store.
236
- * This matches AsyncLocalStorage.exit() behavior.
237
- */
238
- exit(fn) {
239
- const savedStack = this.stack;
240
- this.stack = [];
241
- try {
242
- return fn();
243
- } finally {
244
- this.stack = savedStack;
245
- }
246
- }
247
- };
248
-
249
199
  //#endregion
250
200
  //#region src/internal/context/async-local-storage.mts
251
- /**
252
- * Cross-platform AsyncLocalStorage wrapper.
253
- *
254
- * Provides AsyncLocalStorage on Node.js/Bun and falls back to
255
- * a synchronous-only polyfill in browser environments.
256
- */
257
- /**
258
- * Detects if we're running in a Node.js-like environment with async_hooks support.
259
- */ function hasAsyncHooksSupport() {
260
- if (typeof process !== "undefined" && process.versions && process.versions.node) return true;
261
- if (typeof process !== "undefined" && process.versions && "bun" in process.versions) return true;
262
- if (typeof globalThis.Deno !== "undefined") return true;
263
- return false;
264
- }
265
- let AsyncLocalStorageClass = null;
266
- let initialized = false;
267
- let forceSyncMode = false;
268
- /**
269
- * Gets the appropriate AsyncLocalStorage implementation for the current environment.
270
- *
271
- * - On Node.js/Bun/Deno: Returns the native AsyncLocalStorage
272
- * - On browsers: Returns SyncLocalStorage polyfill
273
- */ function getAsyncLocalStorageClass() {
274
- if (initialized) return AsyncLocalStorageClass;
275
- initialized = true;
276
- if (!forceSyncMode && hasAsyncHooksSupport()) try {
277
- AsyncLocalStorageClass = require("node:async_hooks").AsyncLocalStorage;
278
- } catch {
279
- AsyncLocalStorageClass = SyncLocalStorage;
280
- }
281
- else AsyncLocalStorageClass = SyncLocalStorage;
282
- return AsyncLocalStorageClass;
201
+ const isProduction$1 = process.env.NODE_ENV === "production";
202
+ let loadedModule = null;
203
+ function getModule() {
204
+ if (loadedModule) return loadedModule;
205
+ if (isProduction$1) {
206
+ class NoopLocalStorage {
207
+ run(_store, fn) {
208
+ return fn();
209
+ }
210
+ getStore() {}
211
+ }
212
+ loadedModule = {
213
+ createAsyncLocalStorage: () => new NoopLocalStorage(),
214
+ isUsingNativeAsyncLocalStorage: () => false
215
+ };
216
+ } else loadedModule = {
217
+ createAsyncLocalStorage: () => new node_async_hooks.AsyncLocalStorage(),
218
+ isUsingNativeAsyncLocalStorage: () => true
219
+ };
220
+ return loadedModule;
283
221
  }
284
- /**
285
- * Creates a new AsyncLocalStorage instance appropriate for the current environment.
286
- */ function createAsyncLocalStorage() {
287
- return new (getAsyncLocalStorageClass())();
222
+ function createAsyncLocalStorage() {
223
+ return getModule().createAsyncLocalStorage();
288
224
  }
289
225
 
290
226
  //#endregion
@@ -295,7 +231,16 @@ let forceSyncMode = false;
295
231
  * This allows tracking which service is being instantiated even across
296
232
  * async boundaries (like when inject() is called inside a constructor).
297
233
  * Essential for circular dependency detection.
298
- */ const resolutionContext = createAsyncLocalStorage();
234
+ *
235
+ * The actual implementation varies by environment:
236
+ * - Production: No-op (returns undefined, run() just calls fn directly)
237
+ * - Development: Real AsyncLocalStorage with full async tracking
238
+ * - Browser: SyncLocalStorage for synchronous-only tracking
239
+ */ let resolutionContext = null;
240
+ function getResolutionContext() {
241
+ if (!resolutionContext) resolutionContext = createAsyncLocalStorage();
242
+ return resolutionContext;
243
+ }
299
244
  /**
300
245
  * Runs a function within a resolution context.
301
246
  *
@@ -306,7 +251,7 @@ let forceSyncMode = false;
306
251
  * @param getHolder Function to retrieve holders by name
307
252
  * @param fn The function to run within the context
308
253
  */ function withResolutionContext(waiterHolder, getHolder, fn) {
309
- return resolutionContext.run({
254
+ return getResolutionContext().run({
310
255
  waiterHolder,
311
256
  getHolder
312
257
  }, fn);
@@ -317,7 +262,7 @@ let forceSyncMode = false;
317
262
  * Returns undefined if we're not inside a resolution context
318
263
  * (e.g., when resolving a top-level service that has no parent).
319
264
  */ function getCurrentResolutionContext() {
320
- return resolutionContext.getStore();
265
+ return getResolutionContext().getStore();
321
266
  }
322
267
  /**
323
268
  * Runs a function outside any resolution context.
@@ -327,7 +272,7 @@ let forceSyncMode = false;
327
272
  *
328
273
  * @param fn The function to run without resolution context
329
274
  */ function withoutResolutionContext(fn) {
330
- return resolutionContext.run(void 0, fn);
275
+ return getResolutionContext().run(void 0, fn);
331
276
  }
332
277
 
333
278
  //#endregion
@@ -464,11 +409,17 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
464
409
  //#endregion
465
410
  //#region src/internal/lifecycle/circular-detector.mts
466
411
  /**
412
+ * Whether we're running in production mode.
413
+ * In production, circular dependency detection is skipped for performance.
414
+ */ const isProduction = process.env.NODE_ENV === "production";
415
+ /**
467
416
  * Detects circular dependencies by analyzing the waitingFor relationships
468
417
  * between service holders.
469
418
  *
470
419
  * Uses BFS to traverse the waitingFor graph starting from a target holder
471
420
  * and checks if following the chain leads back to the waiter, indicating a circular dependency.
421
+ *
422
+ * Note: In production (NODE_ENV === 'production'), detection is skipped for performance.
472
423
  */ var CircularDetector = class {
473
424
  /**
474
425
  * Detects if waiting for `targetName` from `waiterName` would create a cycle.
@@ -476,11 +427,14 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
476
427
  * This works by checking if `targetName` (or any holder in its waitingFor chain)
477
428
  * is currently waiting for `waiterName`. If so, waiting would create a deadlock.
478
429
  *
430
+ * In production mode, this always returns null to skip the BFS traversal overhead.
431
+ *
479
432
  * @param waiterName The name of the holder that wants to wait
480
433
  * @param targetName The name of the holder being waited on
481
434
  * @param getHolder Function to retrieve a holder by name
482
435
  * @returns The cycle path if a cycle is detected, null otherwise
483
436
  */ static detectCycle(waiterName, targetName, getHolder) {
437
+ if (isProduction) return null;
484
438
  const visited = /* @__PURE__ */ new Set();
485
439
  const queue = [{
486
440
  name: targetName,
@@ -921,7 +875,8 @@ var RequestStorage = class {
921
875
  */ async resolveRequestScoped(token, args) {
922
876
  const instanceName = this.parent.getServiceLocator().getInstanceIdentifier(token, args);
923
877
  const existingHolder = this.requestContextHolder.get(instanceName);
924
- if (existingHolder) {
878
+ if (existingHolder) if (existingHolder.status === InstanceStatus.Error) this.requestContextHolder.delete(instanceName);
879
+ else {
925
880
  const [error, readyHolder] = await BaseHolderManager.waitForHolderReady(existingHolder);
926
881
  if (error) throw error;
927
882
  return readyHolder.instance;
@@ -1092,7 +1047,12 @@ var SingletonStorage = class {
1092
1047
  return [void 0, readyResult[1].instance];
1093
1048
  }
1094
1049
  return null;
1095
- default: return [error];
1050
+ default:
1051
+ if (holder) {
1052
+ this.logger?.log(`[InstanceResolver] Removing failed instance ${instanceName} from storage to allow retry`);
1053
+ storage.delete(instanceName);
1054
+ }
1055
+ return null;
1096
1056
  }
1097
1057
  }
1098
1058
  /**
@@ -1889,7 +1849,7 @@ var SingletonStorage = class {
1889
1849
 
1890
1850
  //#endregion
1891
1851
  //#region src/container/container.mts
1892
- function applyDecs2203RFactory$1() {
1852
+ function applyDecs2203RFactory() {
1893
1853
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1894
1854
  return function addInitializer(initializer) {
1895
1855
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -2163,18 +2123,18 @@ function applyDecs2203RFactory$1() {
2163
2123
  };
2164
2124
  };
2165
2125
  }
2166
- function _apply_decs_2203_r$1(targetClass, memberDecs, classDecs, parentClass) {
2167
- return (_apply_decs_2203_r$1 = applyDecs2203RFactory$1())(targetClass, memberDecs, classDecs, parentClass);
2126
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
2127
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
2168
2128
  }
2169
- var _dec$1, _initClass$1;
2170
- let _Container$1;
2171
- _dec$1 = Injectable();
2129
+ var _dec, _initClass;
2130
+ let _Container;
2131
+ _dec = Injectable();
2172
2132
  var Container = class {
2173
2133
  registry;
2174
2134
  logger;
2175
2135
  injectors;
2176
2136
  static {
2177
- ({c: [_Container$1, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
2137
+ ({c: [_Container, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
2178
2138
  }
2179
2139
  constructor(registry = globalRegistry, logger = null, injectors = defaultInjectors) {
2180
2140
  this.registry = registry;
@@ -2186,7 +2146,7 @@ var Container = class {
2186
2146
  serviceLocator;
2187
2147
  activeRequestIds = /* @__PURE__ */ new Set();
2188
2148
  registerSelf() {
2189
- const token = getInjectableToken(_Container$1);
2149
+ const token = getInjectableToken(_Container);
2190
2150
  const instanceName = this.serviceLocator.getInstanceIdentifier(token);
2191
2151
  this.serviceLocator.getManager().storeCreatedHolder(instanceName, this, InjectableType.Class, InjectableScope.Singleton);
2192
2152
  }
@@ -2303,344 +2263,6 @@ var Container = class {
2303
2263
  */ clear() {
2304
2264
  return this.serviceLocator.clearAll();
2305
2265
  }
2306
- static {
2307
- _initClass$1();
2308
- }
2309
- };
2310
-
2311
- //#endregion
2312
- //#region src/testing/test-container.mts
2313
- function applyDecs2203RFactory() {
2314
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2315
- return function addInitializer(initializer) {
2316
- assertNotFinished(decoratorFinishedRef, "addInitializer");
2317
- assertCallable(initializer, "An initializer");
2318
- initializers.push(initializer);
2319
- };
2320
- }
2321
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2322
- var kindStr;
2323
- switch (kind) {
2324
- case 1:
2325
- kindStr = "accessor";
2326
- break;
2327
- case 2:
2328
- kindStr = "method";
2329
- break;
2330
- case 3:
2331
- kindStr = "getter";
2332
- break;
2333
- case 4:
2334
- kindStr = "setter";
2335
- break;
2336
- default: kindStr = "field";
2337
- }
2338
- var ctx = {
2339
- kind: kindStr,
2340
- name: isPrivate ? "#" + name : name,
2341
- static: isStatic,
2342
- private: isPrivate,
2343
- metadata
2344
- };
2345
- var decoratorFinishedRef = { v: false };
2346
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2347
- var get, set;
2348
- if (kind === 0) if (isPrivate) {
2349
- get = desc.get;
2350
- set = desc.set;
2351
- } else {
2352
- get = function() {
2353
- return this[name];
2354
- };
2355
- set = function(v) {
2356
- this[name] = v;
2357
- };
2358
- }
2359
- else if (kind === 2) get = function() {
2360
- return desc.value;
2361
- };
2362
- else {
2363
- if (kind === 1 || kind === 3) get = function() {
2364
- return desc.get.call(this);
2365
- };
2366
- if (kind === 1 || kind === 4) set = function(v) {
2367
- desc.set.call(this, v);
2368
- };
2369
- }
2370
- ctx.access = get && set ? {
2371
- get,
2372
- set
2373
- } : get ? { get } : { set };
2374
- try {
2375
- return dec(value, ctx);
2376
- } finally {
2377
- decoratorFinishedRef.v = true;
2378
- }
2379
- }
2380
- function assertNotFinished(decoratorFinishedRef, fnName) {
2381
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2382
- }
2383
- function assertCallable(fn, hint) {
2384
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2385
- }
2386
- function assertValidReturnValue(kind, value) {
2387
- var type = typeof value;
2388
- if (kind === 1) {
2389
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2390
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2391
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2392
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2393
- } else if (type !== "function") {
2394
- var hint;
2395
- if (kind === 0) hint = "field";
2396
- else if (kind === 10) hint = "class";
2397
- else hint = "method";
2398
- throw new TypeError(hint + " decorators must return a function or void 0");
2399
- }
2400
- }
2401
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2402
- var decs = decInfo[0];
2403
- var desc, init, value;
2404
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
2405
- get: decInfo[3],
2406
- set: decInfo[4]
2407
- };
2408
- else if (kind === 3) desc = { get: decInfo[3] };
2409
- else if (kind === 4) desc = { set: decInfo[3] };
2410
- else desc = { value: decInfo[3] };
2411
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2412
- if (kind === 1) value = {
2413
- get: desc.get,
2414
- set: desc.set
2415
- };
2416
- else if (kind === 2) value = desc.value;
2417
- else if (kind === 3) value = desc.get;
2418
- else if (kind === 4) value = desc.set;
2419
- var newValue, get, set;
2420
- if (typeof decs === "function") {
2421
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2422
- if (newValue !== void 0) {
2423
- assertValidReturnValue(kind, newValue);
2424
- if (kind === 0) init = newValue;
2425
- else if (kind === 1) {
2426
- init = newValue.init;
2427
- get = newValue.get || value.get;
2428
- set = newValue.set || value.set;
2429
- value = {
2430
- get,
2431
- set
2432
- };
2433
- } else value = newValue;
2434
- }
2435
- } else for (var i = decs.length - 1; i >= 0; i--) {
2436
- var dec = decs[i];
2437
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2438
- if (newValue !== void 0) {
2439
- assertValidReturnValue(kind, newValue);
2440
- var newInit;
2441
- if (kind === 0) newInit = newValue;
2442
- else if (kind === 1) {
2443
- newInit = newValue.init;
2444
- get = newValue.get || value.get;
2445
- set = newValue.set || value.set;
2446
- value = {
2447
- get,
2448
- set
2449
- };
2450
- } else value = newValue;
2451
- if (newInit !== void 0) if (init === void 0) init = newInit;
2452
- else if (typeof init === "function") init = [init, newInit];
2453
- else init.push(newInit);
2454
- }
2455
- }
2456
- if (kind === 0 || kind === 1) {
2457
- if (init === void 0) init = function(instance, init$1) {
2458
- return init$1;
2459
- };
2460
- else if (typeof init !== "function") {
2461
- var ownInitializers = init;
2462
- init = function(instance, init$1) {
2463
- var value$1 = init$1;
2464
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2465
- return value$1;
2466
- };
2467
- } else {
2468
- var originalInitializer = init;
2469
- init = function(instance, init$1) {
2470
- return originalInitializer.call(instance, init$1);
2471
- };
2472
- }
2473
- ret.push(init);
2474
- }
2475
- if (kind !== 0) {
2476
- if (kind === 1) {
2477
- desc.get = value.get;
2478
- desc.set = value.set;
2479
- } else if (kind === 2) desc.value = value;
2480
- else if (kind === 3) desc.get = value;
2481
- else if (kind === 4) desc.set = value;
2482
- if (isPrivate) if (kind === 1) {
2483
- ret.push(function(instance, args) {
2484
- return value.get.call(instance, args);
2485
- });
2486
- ret.push(function(instance, args) {
2487
- return value.set.call(instance, args);
2488
- });
2489
- } else if (kind === 2) ret.push(value);
2490
- else ret.push(function(instance, args) {
2491
- return value.call(instance, args);
2492
- });
2493
- else Object.defineProperty(base, name, desc);
2494
- }
2495
- }
2496
- function applyMemberDecs(Class, decInfos, metadata) {
2497
- var ret = [];
2498
- var protoInitializers;
2499
- var staticInitializers;
2500
- var existingProtoNonFields = /* @__PURE__ */ new Map();
2501
- var existingStaticNonFields = /* @__PURE__ */ new Map();
2502
- for (var i = 0; i < decInfos.length; i++) {
2503
- var decInfo = decInfos[i];
2504
- if (!Array.isArray(decInfo)) continue;
2505
- var kind = decInfo[1];
2506
- var name = decInfo[2];
2507
- var isPrivate = decInfo.length > 3;
2508
- var isStatic = kind >= 5;
2509
- var base;
2510
- var initializers;
2511
- if (isStatic) {
2512
- base = Class;
2513
- kind = kind - 5;
2514
- staticInitializers = staticInitializers || [];
2515
- initializers = staticInitializers;
2516
- } else {
2517
- base = Class.prototype;
2518
- protoInitializers = protoInitializers || [];
2519
- initializers = protoInitializers;
2520
- }
2521
- if (kind !== 0 && !isPrivate) {
2522
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2523
- var existingKind = existingNonFields.get(name) || 0;
2524
- if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
2525
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2526
- else existingNonFields.set(name, true);
2527
- }
2528
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2529
- }
2530
- pushInitializers(ret, protoInitializers);
2531
- pushInitializers(ret, staticInitializers);
2532
- return ret;
2533
- }
2534
- function pushInitializers(ret, initializers) {
2535
- if (initializers) ret.push(function(instance) {
2536
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2537
- return instance;
2538
- });
2539
- }
2540
- function applyClassDecs(targetClass, classDecs, metadata) {
2541
- if (classDecs.length > 0) {
2542
- var initializers = [];
2543
- var newClass = targetClass;
2544
- var name = targetClass.name;
2545
- for (var i = classDecs.length - 1; i >= 0; i--) {
2546
- var decoratorFinishedRef = { v: false };
2547
- try {
2548
- var nextNewClass = classDecs[i](newClass, {
2549
- kind: "class",
2550
- name,
2551
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2552
- metadata
2553
- });
2554
- } finally {
2555
- decoratorFinishedRef.v = true;
2556
- }
2557
- if (nextNewClass !== void 0) {
2558
- assertValidReturnValue(10, nextNewClass);
2559
- newClass = nextNewClass;
2560
- }
2561
- }
2562
- return [defineMetadata(newClass, metadata), function() {
2563
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2564
- }];
2565
- }
2566
- }
2567
- function defineMetadata(Class, metadata) {
2568
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2569
- configurable: true,
2570
- enumerable: true,
2571
- value: metadata
2572
- });
2573
- }
2574
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2575
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2576
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2577
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
2578
- if (!classDecs.length) defineMetadata(targetClass, metadata);
2579
- return {
2580
- e,
2581
- get c() {
2582
- return applyClassDecs(targetClass, classDecs, metadata);
2583
- }
2584
- };
2585
- };
2586
- }
2587
- function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
2588
- return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
2589
- }
2590
- var _dec, _initClass, _Container;
2591
- /**
2592
- * A binding builder for the TestContainer that allows chaining binding operations.
2593
- */ var TestBindingBuilder = class {
2594
- container;
2595
- token;
2596
- constructor(container, token) {
2597
- this.container = container;
2598
- this.token = token;
2599
- }
2600
- /**
2601
- * Binds the token to a specific value.
2602
- * This is useful for testing with mock values or constants.
2603
- * @param value The value to bind to the token
2604
- */ toValue(value) {
2605
- const instanceName = this.container.getServiceLocator().getInstanceIdentifier(this.token);
2606
- this.container.getServiceLocator().getManager().storeCreatedHolder(instanceName, value, InjectableType.Class, InjectableScope.Singleton);
2607
- return this.container;
2608
- }
2609
- /**
2610
- * Binds the token to a class constructor.
2611
- * @param target The class constructor to bind to
2612
- */ toClass(target) {
2613
- this.container["registry"].set(this.token, InjectableScope.Singleton, target, InjectableType.Class);
2614
- return this.container;
2615
- }
2616
- };
2617
- let _TestContainer;
2618
- _dec = Injectable();
2619
- var TestContainer = class extends (_Container = _Container$1) {
2620
- static {
2621
- ({c: [_TestContainer, _initClass]} = _apply_decs_2203_r(this, [], [_dec], _Container));
2622
- }
2623
- constructor(registry = globalRegistry, logger = null, injectors = void 0) {
2624
- super(registry, logger, injectors);
2625
- }
2626
- bind(token) {
2627
- let realToken = token;
2628
- if (typeof token === "function") realToken = getInjectableToken(token);
2629
- return new TestBindingBuilder(this, realToken);
2630
- }
2631
- bindValue(token, value) {
2632
- return this.bind(token).toValue(value);
2633
- }
2634
- bindClass(token, target) {
2635
- return this.bind(token).toClass(target);
2636
- }
2637
- /**
2638
- * Creates a new TestContainer instance with the same configuration.
2639
- * This is useful for creating isolated test containers.
2640
- * @returns A new TestContainer instance
2641
- */ createChild() {
2642
- return new _TestContainer(this.registry, this.logger, this.injectors);
2643
- }
2644
2266
  static {
2645
2267
  _initClass();
2646
2268
  }
@@ -2785,12 +2407,6 @@ Object.defineProperty(exports, 'SingletonStorage', {
2785
2407
  return SingletonStorage;
2786
2408
  }
2787
2409
  });
2788
- Object.defineProperty(exports, 'TestBindingBuilder', {
2789
- enumerable: true,
2790
- get: function () {
2791
- return TestBindingBuilder;
2792
- }
2793
- });
2794
2410
  Object.defineProperty(exports, 'TokenProcessor', {
2795
2411
  enumerable: true,
2796
2412
  get: function () {
@@ -2800,13 +2416,7 @@ Object.defineProperty(exports, 'TokenProcessor', {
2800
2416
  Object.defineProperty(exports, '_Container', {
2801
2417
  enumerable: true,
2802
2418
  get: function () {
2803
- return _Container$1;
2804
- }
2805
- });
2806
- Object.defineProperty(exports, '_TestContainer', {
2807
- enumerable: true,
2808
- get: function () {
2809
- return _TestContainer;
2419
+ return _Container;
2810
2420
  }
2811
2421
  });
2812
2422
  Object.defineProperty(exports, 'asyncInject', {
@@ -2869,12 +2479,6 @@ Object.defineProperty(exports, 'provideFactoryContext', {
2869
2479
  return provideFactoryContext;
2870
2480
  }
2871
2481
  });
2872
- Object.defineProperty(exports, 'resolutionContext', {
2873
- enumerable: true,
2874
- get: function () {
2875
- return resolutionContext;
2876
- }
2877
- });
2878
2482
  Object.defineProperty(exports, 'withResolutionContext', {
2879
2483
  enumerable: true,
2880
2484
  get: function () {
@@ -2893,4 +2497,4 @@ Object.defineProperty(exports, 'wrapSyncInit', {
2893
2497
  return wrapSyncInit;
2894
2498
  }
2895
2499
  });
2896
- //# sourceMappingURL=testing-DIaIRiJz.cjs.map
2500
+ //# sourceMappingURL=container-BCv3XS6m.cjs.map