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