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