@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.
- package/CHANGELOG.md +39 -0
- package/lib/browser/index.d.mts +5 -84
- package/lib/browser/index.d.mts.map +1 -1
- package/lib/browser/index.mjs +103 -484
- package/lib/browser/index.mjs.map +1 -1
- package/lib/{testing-DIaIRiJz.cjs → container-BCv3XS6m.cjs} +63 -459
- package/lib/container-BCv3XS6m.cjs.map +1 -0
- package/lib/{testing-BG_fa9TJ.mjs → container-Bv6PZZLJ.mjs} +63 -446
- package/lib/container-Bv6PZZLJ.mjs.map +1 -0
- package/lib/{index-DW3K5sOX.d.cts → container-CXDYDJSM.d.mts} +7 -62
- package/lib/container-CXDYDJSM.d.mts.map +1 -0
- package/lib/{index-7jfWsiG4.d.mts → container-b6mDUdGq.d.cts} +2 -67
- package/lib/container-b6mDUdGq.d.cts.map +1 -0
- package/lib/index.cjs +44 -52
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +6 -25
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +6 -25
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/testing/index.cjs +343 -4
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +65 -2
- package/lib/testing/index.d.cts.map +1 -0
- package/lib/testing/index.d.mts +65 -2
- package/lib/testing/index.d.mts.map +1 -0
- package/lib/testing/index.mjs +341 -2
- package/lib/testing/index.mjs.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/async-local-storage.browser.spec.mts +18 -92
- package/src/__tests__/container.spec.mts +93 -0
- package/src/__tests__/e2e.browser.spec.mts +7 -15
- package/src/__tests__/library-findings.spec.mts +23 -21
- package/src/browser.mts +4 -9
- package/src/container/scoped-container.mts +14 -8
- package/src/index.mts +5 -8
- package/src/internal/context/async-local-storage.browser.mts +19 -0
- package/src/internal/context/async-local-storage.mts +46 -98
- package/src/internal/context/async-local-storage.types.mts +7 -0
- package/src/internal/context/resolution-context.mts +23 -5
- package/src/internal/context/sync-local-storage.mts +3 -1
- package/src/internal/core/instance-resolver.mts +8 -1
- package/src/internal/lifecycle/circular-detector.mts +15 -0
- package/tsdown.config.mts +12 -1
- package/vitest.config.mts +25 -3
- package/lib/index-7jfWsiG4.d.mts.map +0 -1
- package/lib/index-DW3K5sOX.d.cts.map +0 -1
- package/lib/testing-BG_fa9TJ.mjs.map +0 -1
- package/lib/testing-DIaIRiJz.cjs.map +0 -1
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
/**
|
|
@@ -200,96 +196,31 @@ var DIError = class DIError extends Error {
|
|
|
200
196
|
}
|
|
201
197
|
};
|
|
202
198
|
|
|
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
199
|
//#endregion
|
|
255
200
|
//#region src/internal/context/async-local-storage.mts
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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;
|
|
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 AsyncLocalStorage(),
|
|
218
|
+
isUsingNativeAsyncLocalStorage: () => true
|
|
219
|
+
};
|
|
220
|
+
return loadedModule;
|
|
288
221
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
*/ function createAsyncLocalStorage() {
|
|
292
|
-
return new (getAsyncLocalStorageClass())();
|
|
222
|
+
function createAsyncLocalStorage() {
|
|
223
|
+
return getModule().createAsyncLocalStorage();
|
|
293
224
|
}
|
|
294
225
|
|
|
295
226
|
//#endregion
|
|
@@ -300,7 +231,16 @@ let forceSyncMode = false;
|
|
|
300
231
|
* This allows tracking which service is being instantiated even across
|
|
301
232
|
* async boundaries (like when inject() is called inside a constructor).
|
|
302
233
|
* Essential for circular dependency detection.
|
|
303
|
-
|
|
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
|
+
}
|
|
304
244
|
/**
|
|
305
245
|
* Runs a function within a resolution context.
|
|
306
246
|
*
|
|
@@ -311,7 +251,7 @@ let forceSyncMode = false;
|
|
|
311
251
|
* @param getHolder Function to retrieve holders by name
|
|
312
252
|
* @param fn The function to run within the context
|
|
313
253
|
*/ function withResolutionContext(waiterHolder, getHolder, fn) {
|
|
314
|
-
return
|
|
254
|
+
return getResolutionContext().run({
|
|
315
255
|
waiterHolder,
|
|
316
256
|
getHolder
|
|
317
257
|
}, fn);
|
|
@@ -322,7 +262,7 @@ let forceSyncMode = false;
|
|
|
322
262
|
* Returns undefined if we're not inside a resolution context
|
|
323
263
|
* (e.g., when resolving a top-level service that has no parent).
|
|
324
264
|
*/ function getCurrentResolutionContext() {
|
|
325
|
-
return
|
|
265
|
+
return getResolutionContext().getStore();
|
|
326
266
|
}
|
|
327
267
|
/**
|
|
328
268
|
* Runs a function outside any resolution context.
|
|
@@ -332,7 +272,7 @@ let forceSyncMode = false;
|
|
|
332
272
|
*
|
|
333
273
|
* @param fn The function to run without resolution context
|
|
334
274
|
*/ function withoutResolutionContext(fn) {
|
|
335
|
-
return
|
|
275
|
+
return getResolutionContext().run(void 0, fn);
|
|
336
276
|
}
|
|
337
277
|
|
|
338
278
|
//#endregion
|
|
@@ -469,11 +409,17 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
|
|
|
469
409
|
//#endregion
|
|
470
410
|
//#region src/internal/lifecycle/circular-detector.mts
|
|
471
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
|
+
/**
|
|
472
416
|
* Detects circular dependencies by analyzing the waitingFor relationships
|
|
473
417
|
* between service holders.
|
|
474
418
|
*
|
|
475
419
|
* Uses BFS to traverse the waitingFor graph starting from a target holder
|
|
476
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.
|
|
477
423
|
*/ var CircularDetector = class {
|
|
478
424
|
/**
|
|
479
425
|
* Detects if waiting for `targetName` from `waiterName` would create a cycle.
|
|
@@ -481,11 +427,14 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
|
|
|
481
427
|
* This works by checking if `targetName` (or any holder in its waitingFor chain)
|
|
482
428
|
* is currently waiting for `waiterName`. If so, waiting would create a deadlock.
|
|
483
429
|
*
|
|
430
|
+
* In production mode, this always returns null to skip the BFS traversal overhead.
|
|
431
|
+
*
|
|
484
432
|
* @param waiterName The name of the holder that wants to wait
|
|
485
433
|
* @param targetName The name of the holder being waited on
|
|
486
434
|
* @param getHolder Function to retrieve a holder by name
|
|
487
435
|
* @returns The cycle path if a cycle is detected, null otherwise
|
|
488
436
|
*/ static detectCycle(waiterName, targetName, getHolder) {
|
|
437
|
+
if (isProduction) return null;
|
|
489
438
|
const visited = /* @__PURE__ */ new Set();
|
|
490
439
|
const queue = [{
|
|
491
440
|
name: targetName,
|
|
@@ -926,7 +875,8 @@ var RequestStorage = class {
|
|
|
926
875
|
*/ async resolveRequestScoped(token, args) {
|
|
927
876
|
const instanceName = this.parent.getServiceLocator().getInstanceIdentifier(token, args);
|
|
928
877
|
const existingHolder = this.requestContextHolder.get(instanceName);
|
|
929
|
-
if (existingHolder)
|
|
878
|
+
if (existingHolder) if (existingHolder.status === InstanceStatus.Error) this.requestContextHolder.delete(instanceName);
|
|
879
|
+
else {
|
|
930
880
|
const [error, readyHolder] = await BaseHolderManager.waitForHolderReady(existingHolder);
|
|
931
881
|
if (error) throw error;
|
|
932
882
|
return readyHolder.instance;
|
|
@@ -1097,7 +1047,12 @@ var SingletonStorage = class {
|
|
|
1097
1047
|
return [void 0, readyResult[1].instance];
|
|
1098
1048
|
}
|
|
1099
1049
|
return null;
|
|
1100
|
-
default:
|
|
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;
|
|
1101
1056
|
}
|
|
1102
1057
|
}
|
|
1103
1058
|
/**
|
|
@@ -1894,7 +1849,7 @@ var SingletonStorage = class {
|
|
|
1894
1849
|
|
|
1895
1850
|
//#endregion
|
|
1896
1851
|
//#region src/container/container.mts
|
|
1897
|
-
function applyDecs2203RFactory
|
|
1852
|
+
function applyDecs2203RFactory() {
|
|
1898
1853
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
1899
1854
|
return function addInitializer(initializer) {
|
|
1900
1855
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -2168,18 +2123,18 @@ function applyDecs2203RFactory$1() {
|
|
|
2168
2123
|
};
|
|
2169
2124
|
};
|
|
2170
2125
|
}
|
|
2171
|
-
function _apply_decs_2203_r
|
|
2172
|
-
return (_apply_decs_2203_r
|
|
2126
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
2127
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
2173
2128
|
}
|
|
2174
|
-
var _dec
|
|
2175
|
-
let _Container
|
|
2176
|
-
_dec
|
|
2129
|
+
var _dec, _initClass;
|
|
2130
|
+
let _Container;
|
|
2131
|
+
_dec = Injectable();
|
|
2177
2132
|
var Container = class {
|
|
2178
2133
|
registry;
|
|
2179
2134
|
logger;
|
|
2180
2135
|
injectors;
|
|
2181
2136
|
static {
|
|
2182
|
-
({c: [_Container
|
|
2137
|
+
({c: [_Container, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
|
|
2183
2138
|
}
|
|
2184
2139
|
constructor(registry = globalRegistry, logger = null, injectors = defaultInjectors) {
|
|
2185
2140
|
this.registry = registry;
|
|
@@ -2191,7 +2146,7 @@ var Container = class {
|
|
|
2191
2146
|
serviceLocator;
|
|
2192
2147
|
activeRequestIds = /* @__PURE__ */ new Set();
|
|
2193
2148
|
registerSelf() {
|
|
2194
|
-
const token = getInjectableToken(_Container
|
|
2149
|
+
const token = getInjectableToken(_Container);
|
|
2195
2150
|
const instanceName = this.serviceLocator.getInstanceIdentifier(token);
|
|
2196
2151
|
this.serviceLocator.getManager().storeCreatedHolder(instanceName, this, InjectableType.Class, InjectableScope.Singleton);
|
|
2197
2152
|
}
|
|
@@ -2308,349 +2263,11 @@ var Container = class {
|
|
|
2308
2263
|
*/ clear() {
|
|
2309
2264
|
return this.serviceLocator.clearAll();
|
|
2310
2265
|
}
|
|
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
2266
|
static {
|
|
2650
2267
|
_initClass();
|
|
2651
2268
|
}
|
|
2652
2269
|
};
|
|
2653
2270
|
|
|
2654
2271
|
//#endregion
|
|
2655
|
-
export {
|
|
2656
|
-
//# sourceMappingURL=
|
|
2272
|
+
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 };
|
|
2273
|
+
//# sourceMappingURL=container-Bv6PZZLJ.mjs.map
|