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