@navios/di 0.6.1 → 0.7.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/lib/browser/index.d.mts +15 -84
  3. package/lib/browser/index.d.mts.map +1 -1
  4. package/lib/browser/index.mjs +121 -484
  5. package/lib/browser/index.mjs.map +1 -1
  6. package/lib/{index-DW3K5sOX.d.cts → container-BuAutHGg.d.mts} +17 -62
  7. package/lib/container-BuAutHGg.d.mts.map +1 -0
  8. package/lib/{testing-DIaIRiJz.cjs → container-DnzgpfBe.cjs} +81 -459
  9. package/lib/container-DnzgpfBe.cjs.map +1 -0
  10. package/lib/{testing-BG_fa9TJ.mjs → container-Pb_Y4Z4x.mjs} +81 -446
  11. package/lib/container-Pb_Y4Z4x.mjs.map +1 -0
  12. package/lib/{index-7jfWsiG4.d.mts → container-oGTgX2iX.d.cts} +12 -67
  13. package/lib/container-oGTgX2iX.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/src/token/registry.mts +21 -0
  45. package/tsdown.config.mts +12 -1
  46. package/vitest.config.mts +25 -3
  47. package/lib/index-7jfWsiG4.d.mts.map +0 -1
  48. package/lib/index-DW3K5sOX.d.cts.map +0 -1
  49. package/lib/testing-BG_fa9TJ.mjs.map +0 -1
  50. package/lib/testing-DIaIRiJz.cjs.map +0 -1
@@ -1,9 +1,5 @@
1
- import { createRequire } from "node:module";
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
2
 
3
- //#region rolldown:runtime
4
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
-
6
- //#endregion
7
3
  //#region src/enums/injectable-scope.enum.mts
8
4
  let InjectableScope = /* @__PURE__ */ function(InjectableScope$1) {
9
5
  /**
@@ -108,6 +104,7 @@ var FactoryInjectionToken = class {
108
104
  //#endregion
109
105
  //#region src/token/registry.mts
110
106
  var Registry = class {
107
+ parent;
111
108
  factories = /* @__PURE__ */ new Map();
112
109
  constructor(parent) {
113
110
  this.parent = parent;
@@ -136,6 +133,23 @@ var Registry = class {
136
133
  delete(token) {
137
134
  this.factories.delete(token.id);
138
135
  }
136
+ /**
137
+ * Updates the scope of an already registered factory.
138
+ * This is useful when you need to dynamically change a service's scope
139
+ * (e.g., when a singleton controller has request-scoped dependencies).
140
+ *
141
+ * @param token The injection token to update
142
+ * @param scope The new scope to set
143
+ * @returns true if the scope was updated, false if the token was not found
144
+ */ updateScope(token, scope) {
145
+ const factory = this.factories.get(token.id);
146
+ if (factory) {
147
+ factory.scope = scope;
148
+ return true;
149
+ }
150
+ if (this.parent) return this.parent.updateScope(token, scope);
151
+ return false;
152
+ }
139
153
  };
140
154
  const globalRegistry = new Registry();
141
155
 
@@ -200,96 +214,31 @@ var DIError = class DIError extends Error {
200
214
  }
201
215
  };
202
216
 
203
- //#endregion
204
- //#region src/internal/context/sync-local-storage.mts
205
- /**
206
- * A synchronous-only polyfill for AsyncLocalStorage.
207
- *
208
- * This provides the same API as Node's AsyncLocalStorage but only works
209
- * for synchronous code paths. It uses a simple stack-based approach.
210
- *
211
- * Limitations:
212
- * - Context does NOT propagate across async boundaries (setTimeout, promises, etc.)
213
- * - Only suitable for environments where DI resolution is synchronous
214
- *
215
- * This is acceptable for browser environments where:
216
- * 1. Constructors are typically synchronous
217
- * 2. Circular dependency detection mainly needs sync tracking
218
- */
219
- var SyncLocalStorage = class {
220
- stack = [];
221
- /**
222
- * Runs a function within the given store context.
223
- * The context is only available synchronously within the function.
224
- */
225
- run(store, fn) {
226
- this.stack.push(store);
227
- try {
228
- return fn();
229
- } finally {
230
- this.stack.pop();
231
- }
232
- }
233
- /**
234
- * Gets the current store value, or undefined if not in a context.
235
- */
236
- getStore() {
237
- return this.stack.length > 0 ? this.stack[this.stack.length - 1] : void 0;
238
- }
239
- /**
240
- * Exits the current context and runs the function without any store.
241
- * This matches AsyncLocalStorage.exit() behavior.
242
- */
243
- exit(fn) {
244
- const savedStack = this.stack;
245
- this.stack = [];
246
- try {
247
- return fn();
248
- } finally {
249
- this.stack = savedStack;
250
- }
251
- }
252
- };
253
-
254
217
  //#endregion
255
218
  //#region src/internal/context/async-local-storage.mts
256
- /**
257
- * Cross-platform AsyncLocalStorage wrapper.
258
- *
259
- * Provides AsyncLocalStorage on Node.js/Bun and falls back to
260
- * a synchronous-only polyfill in browser environments.
261
- */
262
- /**
263
- * Detects if we're running in a Node.js-like environment with async_hooks support.
264
- */ function hasAsyncHooksSupport() {
265
- if (typeof process !== "undefined" && process.versions && process.versions.node) return true;
266
- if (typeof process !== "undefined" && process.versions && "bun" in process.versions) return true;
267
- if (typeof globalThis.Deno !== "undefined") return true;
268
- return false;
269
- }
270
- let AsyncLocalStorageClass = null;
271
- let initialized = false;
272
- let forceSyncMode = false;
273
- /**
274
- * Gets the appropriate AsyncLocalStorage implementation for the current environment.
275
- *
276
- * - On Node.js/Bun/Deno: Returns the native AsyncLocalStorage
277
- * - On browsers: Returns SyncLocalStorage polyfill
278
- */ function getAsyncLocalStorageClass() {
279
- if (initialized) return AsyncLocalStorageClass;
280
- initialized = true;
281
- if (!forceSyncMode && hasAsyncHooksSupport()) try {
282
- AsyncLocalStorageClass = __require("node:async_hooks").AsyncLocalStorage;
283
- } catch {
284
- AsyncLocalStorageClass = SyncLocalStorage;
285
- }
286
- else AsyncLocalStorageClass = SyncLocalStorage;
287
- return AsyncLocalStorageClass;
219
+ const isProduction$1 = process.env.NODE_ENV === "production";
220
+ let loadedModule = null;
221
+ function getModule() {
222
+ if (loadedModule) return loadedModule;
223
+ if (isProduction$1) {
224
+ class NoopLocalStorage {
225
+ run(_store, fn) {
226
+ return fn();
227
+ }
228
+ getStore() {}
229
+ }
230
+ loadedModule = {
231
+ createAsyncLocalStorage: () => new NoopLocalStorage(),
232
+ isUsingNativeAsyncLocalStorage: () => false
233
+ };
234
+ } else loadedModule = {
235
+ createAsyncLocalStorage: () => new AsyncLocalStorage(),
236
+ isUsingNativeAsyncLocalStorage: () => true
237
+ };
238
+ return loadedModule;
288
239
  }
289
- /**
290
- * Creates a new AsyncLocalStorage instance appropriate for the current environment.
291
- */ function createAsyncLocalStorage() {
292
- return new (getAsyncLocalStorageClass())();
240
+ function createAsyncLocalStorage() {
241
+ return getModule().createAsyncLocalStorage();
293
242
  }
294
243
 
295
244
  //#endregion
@@ -300,7 +249,16 @@ let forceSyncMode = false;
300
249
  * This allows tracking which service is being instantiated even across
301
250
  * async boundaries (like when inject() is called inside a constructor).
302
251
  * Essential for circular dependency detection.
303
- */ const resolutionContext = createAsyncLocalStorage();
252
+ *
253
+ * The actual implementation varies by environment:
254
+ * - Production: No-op (returns undefined, run() just calls fn directly)
255
+ * - Development: Real AsyncLocalStorage with full async tracking
256
+ * - Browser: SyncLocalStorage for synchronous-only tracking
257
+ */ let resolutionContext = null;
258
+ function getResolutionContext() {
259
+ if (!resolutionContext) resolutionContext = createAsyncLocalStorage();
260
+ return resolutionContext;
261
+ }
304
262
  /**
305
263
  * Runs a function within a resolution context.
306
264
  *
@@ -311,7 +269,7 @@ let forceSyncMode = false;
311
269
  * @param getHolder Function to retrieve holders by name
312
270
  * @param fn The function to run within the context
313
271
  */ function withResolutionContext(waiterHolder, getHolder, fn) {
314
- return resolutionContext.run({
272
+ return getResolutionContext().run({
315
273
  waiterHolder,
316
274
  getHolder
317
275
  }, fn);
@@ -322,7 +280,7 @@ let forceSyncMode = false;
322
280
  * Returns undefined if we're not inside a resolution context
323
281
  * (e.g., when resolving a top-level service that has no parent).
324
282
  */ function getCurrentResolutionContext() {
325
- return resolutionContext.getStore();
283
+ return getResolutionContext().getStore();
326
284
  }
327
285
  /**
328
286
  * Runs a function outside any resolution context.
@@ -332,7 +290,7 @@ let forceSyncMode = false;
332
290
  *
333
291
  * @param fn The function to run without resolution context
334
292
  */ function withoutResolutionContext(fn) {
335
- return resolutionContext.run(void 0, fn);
293
+ return getResolutionContext().run(void 0, fn);
336
294
  }
337
295
 
338
296
  //#endregion
@@ -469,11 +427,17 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
469
427
  //#endregion
470
428
  //#region src/internal/lifecycle/circular-detector.mts
471
429
  /**
430
+ * Whether we're running in production mode.
431
+ * In production, circular dependency detection is skipped for performance.
432
+ */ const isProduction = process.env.NODE_ENV === "production";
433
+ /**
472
434
  * Detects circular dependencies by analyzing the waitingFor relationships
473
435
  * between service holders.
474
436
  *
475
437
  * Uses BFS to traverse the waitingFor graph starting from a target holder
476
438
  * and checks if following the chain leads back to the waiter, indicating a circular dependency.
439
+ *
440
+ * Note: In production (NODE_ENV === 'production'), detection is skipped for performance.
477
441
  */ var CircularDetector = class {
478
442
  /**
479
443
  * Detects if waiting for `targetName` from `waiterName` would create a cycle.
@@ -481,11 +445,14 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
481
445
  * This works by checking if `targetName` (or any holder in its waitingFor chain)
482
446
  * is currently waiting for `waiterName`. If so, waiting would create a deadlock.
483
447
  *
448
+ * In production mode, this always returns null to skip the BFS traversal overhead.
449
+ *
484
450
  * @param waiterName The name of the holder that wants to wait
485
451
  * @param targetName The name of the holder being waited on
486
452
  * @param getHolder Function to retrieve a holder by name
487
453
  * @returns The cycle path if a cycle is detected, null otherwise
488
454
  */ static detectCycle(waiterName, targetName, getHolder) {
455
+ if (isProduction) return null;
489
456
  const visited = /* @__PURE__ */ new Set();
490
457
  const queue = [{
491
458
  name: targetName,
@@ -926,7 +893,8 @@ var RequestStorage = class {
926
893
  */ async resolveRequestScoped(token, args) {
927
894
  const instanceName = this.parent.getServiceLocator().getInstanceIdentifier(token, args);
928
895
  const existingHolder = this.requestContextHolder.get(instanceName);
929
- if (existingHolder) {
896
+ if (existingHolder) if (existingHolder.status === InstanceStatus.Error) this.requestContextHolder.delete(instanceName);
897
+ else {
930
898
  const [error, readyHolder] = await BaseHolderManager.waitForHolderReady(existingHolder);
931
899
  if (error) throw error;
932
900
  return readyHolder.instance;
@@ -1097,7 +1065,12 @@ var SingletonStorage = class {
1097
1065
  return [void 0, readyResult[1].instance];
1098
1066
  }
1099
1067
  return null;
1100
- default: return [error];
1068
+ default:
1069
+ if (holder) {
1070
+ this.logger?.log(`[InstanceResolver] Removing failed instance ${instanceName} from storage to allow retry`);
1071
+ storage.delete(instanceName);
1072
+ }
1073
+ return null;
1101
1074
  }
1102
1075
  }
1103
1076
  /**
@@ -1894,7 +1867,7 @@ var SingletonStorage = class {
1894
1867
 
1895
1868
  //#endregion
1896
1869
  //#region src/container/container.mts
1897
- function applyDecs2203RFactory$1() {
1870
+ function applyDecs2203RFactory() {
1898
1871
  function createAddInitializerMethod(initializers, decoratorFinishedRef) {
1899
1872
  return function addInitializer(initializer) {
1900
1873
  assertNotFinished(decoratorFinishedRef, "addInitializer");
@@ -2168,18 +2141,18 @@ function applyDecs2203RFactory$1() {
2168
2141
  };
2169
2142
  };
2170
2143
  }
2171
- function _apply_decs_2203_r$1(targetClass, memberDecs, classDecs, parentClass) {
2172
- return (_apply_decs_2203_r$1 = applyDecs2203RFactory$1())(targetClass, memberDecs, classDecs, parentClass);
2144
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
2145
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
2173
2146
  }
2174
- var _dec$1, _initClass$1;
2175
- let _Container$1;
2176
- _dec$1 = Injectable();
2147
+ var _dec, _initClass;
2148
+ let _Container;
2149
+ _dec = Injectable();
2177
2150
  var Container = class {
2178
2151
  registry;
2179
2152
  logger;
2180
2153
  injectors;
2181
2154
  static {
2182
- ({c: [_Container$1, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
2155
+ ({c: [_Container, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
2183
2156
  }
2184
2157
  constructor(registry = globalRegistry, logger = null, injectors = defaultInjectors) {
2185
2158
  this.registry = registry;
@@ -2191,7 +2164,7 @@ var Container = class {
2191
2164
  serviceLocator;
2192
2165
  activeRequestIds = /* @__PURE__ */ new Set();
2193
2166
  registerSelf() {
2194
- const token = getInjectableToken(_Container$1);
2167
+ const token = getInjectableToken(_Container);
2195
2168
  const instanceName = this.serviceLocator.getInstanceIdentifier(token);
2196
2169
  this.serviceLocator.getManager().storeCreatedHolder(instanceName, this, InjectableType.Class, InjectableScope.Singleton);
2197
2170
  }
@@ -2308,349 +2281,11 @@ var Container = class {
2308
2281
  */ clear() {
2309
2282
  return this.serviceLocator.clearAll();
2310
2283
  }
2311
- static {
2312
- _initClass$1();
2313
- }
2314
- };
2315
-
2316
- //#endregion
2317
- //#region src/testing/test-container.mts
2318
- function applyDecs2203RFactory() {
2319
- function createAddInitializerMethod(initializers, decoratorFinishedRef) {
2320
- return function addInitializer(initializer) {
2321
- assertNotFinished(decoratorFinishedRef, "addInitializer");
2322
- assertCallable(initializer, "An initializer");
2323
- initializers.push(initializer);
2324
- };
2325
- }
2326
- function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
2327
- var kindStr;
2328
- switch (kind) {
2329
- case 1:
2330
- kindStr = "accessor";
2331
- break;
2332
- case 2:
2333
- kindStr = "method";
2334
- break;
2335
- case 3:
2336
- kindStr = "getter";
2337
- break;
2338
- case 4:
2339
- kindStr = "setter";
2340
- break;
2341
- default: kindStr = "field";
2342
- }
2343
- var ctx = {
2344
- kind: kindStr,
2345
- name: isPrivate ? "#" + name : name,
2346
- static: isStatic,
2347
- private: isPrivate,
2348
- metadata
2349
- };
2350
- var decoratorFinishedRef = { v: false };
2351
- ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
2352
- var get, set;
2353
- if (kind === 0) if (isPrivate) {
2354
- get = desc.get;
2355
- set = desc.set;
2356
- } else {
2357
- get = function() {
2358
- return this[name];
2359
- };
2360
- set = function(v) {
2361
- this[name] = v;
2362
- };
2363
- }
2364
- else if (kind === 2) get = function() {
2365
- return desc.value;
2366
- };
2367
- else {
2368
- if (kind === 1 || kind === 3) get = function() {
2369
- return desc.get.call(this);
2370
- };
2371
- if (kind === 1 || kind === 4) set = function(v) {
2372
- desc.set.call(this, v);
2373
- };
2374
- }
2375
- ctx.access = get && set ? {
2376
- get,
2377
- set
2378
- } : get ? { get } : { set };
2379
- try {
2380
- return dec(value, ctx);
2381
- } finally {
2382
- decoratorFinishedRef.v = true;
2383
- }
2384
- }
2385
- function assertNotFinished(decoratorFinishedRef, fnName) {
2386
- if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
2387
- }
2388
- function assertCallable(fn, hint) {
2389
- if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
2390
- }
2391
- function assertValidReturnValue(kind, value) {
2392
- var type = typeof value;
2393
- if (kind === 1) {
2394
- if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
2395
- if (value.get !== void 0) assertCallable(value.get, "accessor.get");
2396
- if (value.set !== void 0) assertCallable(value.set, "accessor.set");
2397
- if (value.init !== void 0) assertCallable(value.init, "accessor.init");
2398
- } else if (type !== "function") {
2399
- var hint;
2400
- if (kind === 0) hint = "field";
2401
- else if (kind === 10) hint = "class";
2402
- else hint = "method";
2403
- throw new TypeError(hint + " decorators must return a function or void 0");
2404
- }
2405
- }
2406
- function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
2407
- var decs = decInfo[0];
2408
- var desc, init, value;
2409
- if (isPrivate) if (kind === 0 || kind === 1) desc = {
2410
- get: decInfo[3],
2411
- set: decInfo[4]
2412
- };
2413
- else if (kind === 3) desc = { get: decInfo[3] };
2414
- else if (kind === 4) desc = { set: decInfo[3] };
2415
- else desc = { value: decInfo[3] };
2416
- else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
2417
- if (kind === 1) value = {
2418
- get: desc.get,
2419
- set: desc.set
2420
- };
2421
- else if (kind === 2) value = desc.value;
2422
- else if (kind === 3) value = desc.get;
2423
- else if (kind === 4) value = desc.set;
2424
- var newValue, get, set;
2425
- if (typeof decs === "function") {
2426
- newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2427
- if (newValue !== void 0) {
2428
- assertValidReturnValue(kind, newValue);
2429
- if (kind === 0) init = newValue;
2430
- else if (kind === 1) {
2431
- init = newValue.init;
2432
- get = newValue.get || value.get;
2433
- set = newValue.set || value.set;
2434
- value = {
2435
- get,
2436
- set
2437
- };
2438
- } else value = newValue;
2439
- }
2440
- } else for (var i = decs.length - 1; i >= 0; i--) {
2441
- var dec = decs[i];
2442
- newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
2443
- if (newValue !== void 0) {
2444
- assertValidReturnValue(kind, newValue);
2445
- var newInit;
2446
- if (kind === 0) newInit = newValue;
2447
- else if (kind === 1) {
2448
- newInit = newValue.init;
2449
- get = newValue.get || value.get;
2450
- set = newValue.set || value.set;
2451
- value = {
2452
- get,
2453
- set
2454
- };
2455
- } else value = newValue;
2456
- if (newInit !== void 0) if (init === void 0) init = newInit;
2457
- else if (typeof init === "function") init = [init, newInit];
2458
- else init.push(newInit);
2459
- }
2460
- }
2461
- if (kind === 0 || kind === 1) {
2462
- if (init === void 0) init = function(instance, init$1) {
2463
- return init$1;
2464
- };
2465
- else if (typeof init !== "function") {
2466
- var ownInitializers = init;
2467
- init = function(instance, init$1) {
2468
- var value$1 = init$1;
2469
- for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
2470
- return value$1;
2471
- };
2472
- } else {
2473
- var originalInitializer = init;
2474
- init = function(instance, init$1) {
2475
- return originalInitializer.call(instance, init$1);
2476
- };
2477
- }
2478
- ret.push(init);
2479
- }
2480
- if (kind !== 0) {
2481
- if (kind === 1) {
2482
- desc.get = value.get;
2483
- desc.set = value.set;
2484
- } else if (kind === 2) desc.value = value;
2485
- else if (kind === 3) desc.get = value;
2486
- else if (kind === 4) desc.set = value;
2487
- if (isPrivate) if (kind === 1) {
2488
- ret.push(function(instance, args) {
2489
- return value.get.call(instance, args);
2490
- });
2491
- ret.push(function(instance, args) {
2492
- return value.set.call(instance, args);
2493
- });
2494
- } else if (kind === 2) ret.push(value);
2495
- else ret.push(function(instance, args) {
2496
- return value.call(instance, args);
2497
- });
2498
- else Object.defineProperty(base, name, desc);
2499
- }
2500
- }
2501
- function applyMemberDecs(Class, decInfos, metadata) {
2502
- var ret = [];
2503
- var protoInitializers;
2504
- var staticInitializers;
2505
- var existingProtoNonFields = /* @__PURE__ */ new Map();
2506
- var existingStaticNonFields = /* @__PURE__ */ new Map();
2507
- for (var i = 0; i < decInfos.length; i++) {
2508
- var decInfo = decInfos[i];
2509
- if (!Array.isArray(decInfo)) continue;
2510
- var kind = decInfo[1];
2511
- var name = decInfo[2];
2512
- var isPrivate = decInfo.length > 3;
2513
- var isStatic = kind >= 5;
2514
- var base;
2515
- var initializers;
2516
- if (isStatic) {
2517
- base = Class;
2518
- kind = kind - 5;
2519
- staticInitializers = staticInitializers || [];
2520
- initializers = staticInitializers;
2521
- } else {
2522
- base = Class.prototype;
2523
- protoInitializers = protoInitializers || [];
2524
- initializers = protoInitializers;
2525
- }
2526
- if (kind !== 0 && !isPrivate) {
2527
- var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
2528
- var existingKind = existingNonFields.get(name) || 0;
2529
- 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);
2530
- else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
2531
- else existingNonFields.set(name, true);
2532
- }
2533
- applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
2534
- }
2535
- pushInitializers(ret, protoInitializers);
2536
- pushInitializers(ret, staticInitializers);
2537
- return ret;
2538
- }
2539
- function pushInitializers(ret, initializers) {
2540
- if (initializers) ret.push(function(instance) {
2541
- for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
2542
- return instance;
2543
- });
2544
- }
2545
- function applyClassDecs(targetClass, classDecs, metadata) {
2546
- if (classDecs.length > 0) {
2547
- var initializers = [];
2548
- var newClass = targetClass;
2549
- var name = targetClass.name;
2550
- for (var i = classDecs.length - 1; i >= 0; i--) {
2551
- var decoratorFinishedRef = { v: false };
2552
- try {
2553
- var nextNewClass = classDecs[i](newClass, {
2554
- kind: "class",
2555
- name,
2556
- addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
2557
- metadata
2558
- });
2559
- } finally {
2560
- decoratorFinishedRef.v = true;
2561
- }
2562
- if (nextNewClass !== void 0) {
2563
- assertValidReturnValue(10, nextNewClass);
2564
- newClass = nextNewClass;
2565
- }
2566
- }
2567
- return [defineMetadata(newClass, metadata), function() {
2568
- for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
2569
- }];
2570
- }
2571
- }
2572
- function defineMetadata(Class, metadata) {
2573
- return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
2574
- configurable: true,
2575
- enumerable: true,
2576
- value: metadata
2577
- });
2578
- }
2579
- return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
2580
- if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
2581
- var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
2582
- var e = applyMemberDecs(targetClass, memberDecs, metadata);
2583
- if (!classDecs.length) defineMetadata(targetClass, metadata);
2584
- return {
2585
- e,
2586
- get c() {
2587
- return applyClassDecs(targetClass, classDecs, metadata);
2588
- }
2589
- };
2590
- };
2591
- }
2592
- function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
2593
- return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
2594
- }
2595
- var _dec, _initClass, _Container;
2596
- /**
2597
- * A binding builder for the TestContainer that allows chaining binding operations.
2598
- */ var TestBindingBuilder = class {
2599
- container;
2600
- token;
2601
- constructor(container, token) {
2602
- this.container = container;
2603
- this.token = token;
2604
- }
2605
- /**
2606
- * Binds the token to a specific value.
2607
- * This is useful for testing with mock values or constants.
2608
- * @param value The value to bind to the token
2609
- */ toValue(value) {
2610
- const instanceName = this.container.getServiceLocator().getInstanceIdentifier(this.token);
2611
- this.container.getServiceLocator().getManager().storeCreatedHolder(instanceName, value, InjectableType.Class, InjectableScope.Singleton);
2612
- return this.container;
2613
- }
2614
- /**
2615
- * Binds the token to a class constructor.
2616
- * @param target The class constructor to bind to
2617
- */ toClass(target) {
2618
- this.container["registry"].set(this.token, InjectableScope.Singleton, target, InjectableType.Class);
2619
- return this.container;
2620
- }
2621
- };
2622
- let _TestContainer;
2623
- _dec = Injectable();
2624
- var TestContainer = class extends (_Container = _Container$1) {
2625
- static {
2626
- ({c: [_TestContainer, _initClass]} = _apply_decs_2203_r(this, [], [_dec], _Container));
2627
- }
2628
- constructor(registry = globalRegistry, logger = null, injectors = void 0) {
2629
- super(registry, logger, injectors);
2630
- }
2631
- bind(token) {
2632
- let realToken = token;
2633
- if (typeof token === "function") realToken = getInjectableToken(token);
2634
- return new TestBindingBuilder(this, realToken);
2635
- }
2636
- bindValue(token, value) {
2637
- return this.bind(token).toValue(value);
2638
- }
2639
- bindClass(token, target) {
2640
- return this.bind(token).toClass(target);
2641
- }
2642
- /**
2643
- * Creates a new TestContainer instance with the same configuration.
2644
- * This is useful for creating isolated test containers.
2645
- * @returns A new TestContainer instance
2646
- */ createChild() {
2647
- return new _TestContainer(this.registry, this.logger, this.injectors);
2648
- }
2649
2284
  static {
2650
2285
  _initClass();
2651
2286
  }
2652
2287
  };
2653
2288
 
2654
2289
  //#endregion
2655
- export { withoutResolutionContext as A, InjectableType as B, provideFactoryContext as C, getCurrentResolutionContext as D, getInjectors as E, Registry as F, globalRegistry as I, BoundInjectionToken as L, DIErrorCode as M, Injectable as N, resolutionContext as O, InjectableTokenMeta as P, FactoryInjectionToken as R, optional as S, getInjectableToken as T, InjectableScope as V, InstanceStatus as _, TokenProcessor as a, defaultInjectors as b, Invalidator as c, SingletonStorage as d, ScopedContainer as f, BaseHolderManager as g, createRequestContext as h, ServiceLocator as i, DIError as j, withResolutionContext as k, Instantiator as l, DefaultRequestContext as m, _TestContainer as n, HolderManager as o, RequestStorage as p, _Container$1 as r, LifecycleEventBus as s, TestBindingBuilder as t, InstanceResolver as u, CircularDetector as v, wrapSyncInit as w, inject as x, asyncInject as y, InjectionToken as z };
2656
- //# sourceMappingURL=testing-BG_fa9TJ.mjs.map
2290
+ export { Injectable as A, getInjectableToken as C, withoutResolutionContext as D, withResolutionContext as E, FactoryInjectionToken as F, InjectionToken as I, InjectableType as L, Registry as M, globalRegistry as N, DIError as O, BoundInjectionToken as P, InjectableScope as R, wrapSyncInit as S, getCurrentResolutionContext as T, asyncInject as _, LifecycleEventBus as a, optional as b, InstanceResolver as c, RequestStorage as d, DefaultRequestContext as f, CircularDetector as g, InstanceStatus as h, HolderManager as i, InjectableTokenMeta as j, DIErrorCode as k, SingletonStorage as l, BaseHolderManager as m, ServiceLocator as n, Invalidator as o, createRequestContext as p, TokenProcessor as r, Instantiator as s, _Container as t, ScopedContainer as u, defaultInjectors as v, getInjectors as w, provideFactoryContext as x, inject as y };
2291
+ //# sourceMappingURL=container-Pb_Y4Z4x.mjs.map