@navios/di 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/lib/browser/index.d.mts +5 -84
- package/lib/browser/index.d.mts.map +1 -1
- package/lib/browser/index.mjs +103 -484
- package/lib/browser/index.mjs.map +1 -1
- package/lib/{testing-DIaIRiJz.cjs → container-BCv3XS6m.cjs} +63 -459
- package/lib/container-BCv3XS6m.cjs.map +1 -0
- package/lib/{testing-BG_fa9TJ.mjs → container-Bv6PZZLJ.mjs} +63 -446
- package/lib/container-Bv6PZZLJ.mjs.map +1 -0
- package/lib/{index-DW3K5sOX.d.cts → container-CXDYDJSM.d.mts} +7 -62
- package/lib/container-CXDYDJSM.d.mts.map +1 -0
- package/lib/{index-7jfWsiG4.d.mts → container-b6mDUdGq.d.cts} +2 -67
- package/lib/container-b6mDUdGq.d.cts.map +1 -0
- package/lib/index.cjs +44 -52
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +6 -25
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +6 -25
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/testing/index.cjs +343 -4
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +65 -2
- package/lib/testing/index.d.cts.map +1 -0
- package/lib/testing/index.d.mts +65 -2
- package/lib/testing/index.d.mts.map +1 -0
- package/lib/testing/index.mjs +341 -2
- package/lib/testing/index.mjs.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/async-local-storage.browser.spec.mts +18 -92
- package/src/__tests__/container.spec.mts +93 -0
- package/src/__tests__/e2e.browser.spec.mts +7 -15
- package/src/__tests__/library-findings.spec.mts +23 -21
- package/src/browser.mts +4 -9
- package/src/container/scoped-container.mts +14 -8
- package/src/index.mts +5 -8
- package/src/internal/context/async-local-storage.browser.mts +19 -0
- package/src/internal/context/async-local-storage.mts +46 -98
- package/src/internal/context/async-local-storage.types.mts +7 -0
- package/src/internal/context/resolution-context.mts +23 -5
- package/src/internal/context/sync-local-storage.mts +3 -1
- package/src/internal/core/instance-resolver.mts +8 -1
- package/src/internal/lifecycle/circular-detector.mts +15 -0
- package/tsdown.config.mts +12 -1
- package/vitest.config.mts +25 -3
- package/lib/index-7jfWsiG4.d.mts.map +0 -1
- package/lib/index-DW3K5sOX.d.cts.map +0 -1
- package/lib/testing-BG_fa9TJ.mjs.map +0 -1
- package/lib/testing-DIaIRiJz.cjs.map +0 -1
package/lib/browser/index.mjs
CHANGED
|
@@ -1,119 +1,5 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
|
|
3
|
-
//#region rolldown:runtime
|
|
4
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/internal/context/sync-local-storage.mts
|
|
11
|
-
/**
|
|
12
|
-
* A synchronous-only polyfill for AsyncLocalStorage.
|
|
13
|
-
*
|
|
14
|
-
* This provides the same API as Node's AsyncLocalStorage but only works
|
|
15
|
-
* for synchronous code paths. It uses a simple stack-based approach.
|
|
16
|
-
*
|
|
17
|
-
* Limitations:
|
|
18
|
-
* - Context does NOT propagate across async boundaries (setTimeout, promises, etc.)
|
|
19
|
-
* - Only suitable for environments where DI resolution is synchronous
|
|
20
|
-
*
|
|
21
|
-
* This is acceptable for browser environments where:
|
|
22
|
-
* 1. Constructors are typically synchronous
|
|
23
|
-
* 2. Circular dependency detection mainly needs sync tracking
|
|
24
|
-
*/
|
|
25
|
-
var SyncLocalStorage = class {
|
|
26
|
-
stack = [];
|
|
27
|
-
/**
|
|
28
|
-
* Runs a function within the given store context.
|
|
29
|
-
* The context is only available synchronously within the function.
|
|
30
|
-
*/
|
|
31
|
-
run(store, fn) {
|
|
32
|
-
this.stack.push(store);
|
|
33
|
-
try {
|
|
34
|
-
return fn();
|
|
35
|
-
} finally {
|
|
36
|
-
this.stack.pop();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Gets the current store value, or undefined if not in a context.
|
|
41
|
-
*/
|
|
42
|
-
getStore() {
|
|
43
|
-
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : void 0;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Exits the current context and runs the function without any store.
|
|
47
|
-
* This matches AsyncLocalStorage.exit() behavior.
|
|
48
|
-
*/
|
|
49
|
-
exit(fn) {
|
|
50
|
-
const savedStack = this.stack;
|
|
51
|
-
this.stack = [];
|
|
52
|
-
try {
|
|
53
|
-
return fn();
|
|
54
|
-
} finally {
|
|
55
|
-
this.stack = savedStack;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/internal/context/async-local-storage.mts
|
|
62
|
-
/**
|
|
63
|
-
* Cross-platform AsyncLocalStorage wrapper.
|
|
64
|
-
*
|
|
65
|
-
* Provides AsyncLocalStorage on Node.js/Bun and falls back to
|
|
66
|
-
* a synchronous-only polyfill in browser environments.
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* Detects if we're running in a Node.js-like environment with async_hooks support.
|
|
70
|
-
*/ function hasAsyncHooksSupport() {
|
|
71
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) return true;
|
|
72
|
-
if (typeof process !== "undefined" && process.versions && "bun" in process.versions) return true;
|
|
73
|
-
if (typeof globalThis.Deno !== "undefined") return true;
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
let AsyncLocalStorageClass = null;
|
|
77
|
-
let initialized = false;
|
|
78
|
-
let forceSyncMode = false;
|
|
79
|
-
/**
|
|
80
|
-
* Gets the appropriate AsyncLocalStorage implementation for the current environment.
|
|
81
|
-
*
|
|
82
|
-
* - On Node.js/Bun/Deno: Returns the native AsyncLocalStorage
|
|
83
|
-
* - On browsers: Returns SyncLocalStorage polyfill
|
|
84
|
-
*/ function getAsyncLocalStorageClass() {
|
|
85
|
-
if (initialized) return AsyncLocalStorageClass;
|
|
86
|
-
initialized = true;
|
|
87
|
-
if (!forceSyncMode && hasAsyncHooksSupport()) try {
|
|
88
|
-
AsyncLocalStorageClass = __require("node:async_hooks").AsyncLocalStorage;
|
|
89
|
-
} catch {
|
|
90
|
-
AsyncLocalStorageClass = SyncLocalStorage;
|
|
91
|
-
}
|
|
92
|
-
else AsyncLocalStorageClass = SyncLocalStorage;
|
|
93
|
-
return AsyncLocalStorageClass;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Creates a new AsyncLocalStorage instance appropriate for the current environment.
|
|
97
|
-
*/ function createAsyncLocalStorage() {
|
|
98
|
-
return new (getAsyncLocalStorageClass())();
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Testing utilities for forcing specific modes.
|
|
102
|
-
* Only exported for testing purposes.
|
|
103
|
-
*/ const __testing__ = {
|
|
104
|
-
forceSyncMode: () => {
|
|
105
|
-
initialized = false;
|
|
106
|
-
forceSyncMode = true;
|
|
107
|
-
AsyncLocalStorageClass = null;
|
|
108
|
-
},
|
|
109
|
-
reset: () => {
|
|
110
|
-
initialized = false;
|
|
111
|
-
forceSyncMode = false;
|
|
112
|
-
AsyncLocalStorageClass = null;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
3
|
//#region src/enums/injectable-scope.enum.mts
|
|
118
4
|
let InjectableScope = /* @__PURE__ */ function(InjectableScope$1) {
|
|
119
5
|
/**
|
|
@@ -310,6 +196,70 @@ var DIError = class DIError extends Error {
|
|
|
310
196
|
}
|
|
311
197
|
};
|
|
312
198
|
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/internal/context/sync-local-storage.mts
|
|
201
|
+
/**
|
|
202
|
+
* A synchronous-only polyfill for AsyncLocalStorage.
|
|
203
|
+
*
|
|
204
|
+
* This provides the same API as Node's AsyncLocalStorage but only works
|
|
205
|
+
* for synchronous code paths. It uses a simple stack-based approach.
|
|
206
|
+
*
|
|
207
|
+
* Limitations:
|
|
208
|
+
* - Context does NOT propagate across async boundaries (setTimeout, promises, etc.)
|
|
209
|
+
* - Only suitable for environments where DI resolution is synchronous
|
|
210
|
+
*
|
|
211
|
+
* This is acceptable for browser environments where:
|
|
212
|
+
* 1. Constructors are typically synchronous
|
|
213
|
+
* 2. Circular dependency detection mainly needs sync tracking
|
|
214
|
+
*/
|
|
215
|
+
var SyncLocalStorage = class {
|
|
216
|
+
stack = [];
|
|
217
|
+
/**
|
|
218
|
+
* Runs a function within the given store context.
|
|
219
|
+
* The context is only available synchronously within the function.
|
|
220
|
+
*/
|
|
221
|
+
run(store, fn) {
|
|
222
|
+
this.stack.push(store);
|
|
223
|
+
try {
|
|
224
|
+
return fn();
|
|
225
|
+
} finally {
|
|
226
|
+
this.stack.pop();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets the current store value, or undefined if not in a context.
|
|
231
|
+
*/
|
|
232
|
+
getStore() {
|
|
233
|
+
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : void 0;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Exits the current context and runs the function without any store.
|
|
237
|
+
* This matches AsyncLocalStorage.exit() behavior.
|
|
238
|
+
*/
|
|
239
|
+
exit(fn) {
|
|
240
|
+
const savedStack = this.stack;
|
|
241
|
+
this.stack = [];
|
|
242
|
+
try {
|
|
243
|
+
return fn();
|
|
244
|
+
} finally {
|
|
245
|
+
this.stack = savedStack;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/internal/context/async-local-storage.browser.mts
|
|
252
|
+
/**
|
|
253
|
+
* Browser implementation using SyncLocalStorage.
|
|
254
|
+
*
|
|
255
|
+
* This module is used in browser environments where async_hooks is not available.
|
|
256
|
+
* It provides synchronous-only context tracking which is sufficient for
|
|
257
|
+
* browser-based DI resolution.
|
|
258
|
+
*/
|
|
259
|
+
function createAsyncLocalStorage() {
|
|
260
|
+
return new SyncLocalStorage();
|
|
261
|
+
}
|
|
262
|
+
|
|
313
263
|
//#endregion
|
|
314
264
|
//#region src/internal/context/resolution-context.mts
|
|
315
265
|
/**
|
|
@@ -318,7 +268,16 @@ var DIError = class DIError extends Error {
|
|
|
318
268
|
* This allows tracking which service is being instantiated even across
|
|
319
269
|
* async boundaries (like when inject() is called inside a constructor).
|
|
320
270
|
* Essential for circular dependency detection.
|
|
321
|
-
|
|
271
|
+
*
|
|
272
|
+
* The actual implementation varies by environment:
|
|
273
|
+
* - Production: No-op (returns undefined, run() just calls fn directly)
|
|
274
|
+
* - Development: Real AsyncLocalStorage with full async tracking
|
|
275
|
+
* - Browser: SyncLocalStorage for synchronous-only tracking
|
|
276
|
+
*/ let resolutionContext = null;
|
|
277
|
+
function getResolutionContext() {
|
|
278
|
+
if (!resolutionContext) resolutionContext = createAsyncLocalStorage();
|
|
279
|
+
return resolutionContext;
|
|
280
|
+
}
|
|
322
281
|
/**
|
|
323
282
|
* Runs a function within a resolution context.
|
|
324
283
|
*
|
|
@@ -329,7 +288,7 @@ var DIError = class DIError extends Error {
|
|
|
329
288
|
* @param getHolder Function to retrieve holders by name
|
|
330
289
|
* @param fn The function to run within the context
|
|
331
290
|
*/ function withResolutionContext(waiterHolder, getHolder, fn) {
|
|
332
|
-
return
|
|
291
|
+
return getResolutionContext().run({
|
|
333
292
|
waiterHolder,
|
|
334
293
|
getHolder
|
|
335
294
|
}, fn);
|
|
@@ -340,7 +299,7 @@ var DIError = class DIError extends Error {
|
|
|
340
299
|
* Returns undefined if we're not inside a resolution context
|
|
341
300
|
* (e.g., when resolving a top-level service that has no parent).
|
|
342
301
|
*/ function getCurrentResolutionContext() {
|
|
343
|
-
return
|
|
302
|
+
return getResolutionContext().getStore();
|
|
344
303
|
}
|
|
345
304
|
/**
|
|
346
305
|
* Runs a function outside any resolution context.
|
|
@@ -350,7 +309,7 @@ var DIError = class DIError extends Error {
|
|
|
350
309
|
*
|
|
351
310
|
* @param fn The function to run without resolution context
|
|
352
311
|
*/ function withoutResolutionContext(fn) {
|
|
353
|
-
return
|
|
312
|
+
return getResolutionContext().run(void 0, fn);
|
|
354
313
|
}
|
|
355
314
|
|
|
356
315
|
//#endregion
|
|
@@ -492,6 +451,8 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
|
|
|
492
451
|
*
|
|
493
452
|
* Uses BFS to traverse the waitingFor graph starting from a target holder
|
|
494
453
|
* and checks if following the chain leads back to the waiter, indicating a circular dependency.
|
|
454
|
+
*
|
|
455
|
+
* Note: In production (NODE_ENV === 'production'), detection is skipped for performance.
|
|
495
456
|
*/ var CircularDetector = class {
|
|
496
457
|
/**
|
|
497
458
|
* Detects if waiting for `targetName` from `waiterName` would create a cycle.
|
|
@@ -499,6 +460,8 @@ const provideFactoryContext = defaultInjectors.provideFactoryContext;
|
|
|
499
460
|
* This works by checking if `targetName` (or any holder in its waitingFor chain)
|
|
500
461
|
* is currently waiting for `waiterName`. If so, waiting would create a deadlock.
|
|
501
462
|
*
|
|
463
|
+
* In production mode, this always returns null to skip the BFS traversal overhead.
|
|
464
|
+
*
|
|
502
465
|
* @param waiterName The name of the holder that wants to wait
|
|
503
466
|
* @param targetName The name of the holder being waited on
|
|
504
467
|
* @param getHolder Function to retrieve a holder by name
|
|
@@ -944,7 +907,8 @@ var RequestStorage = class {
|
|
|
944
907
|
*/ async resolveRequestScoped(token, args) {
|
|
945
908
|
const instanceName = this.parent.getServiceLocator().getInstanceIdentifier(token, args);
|
|
946
909
|
const existingHolder = this.requestContextHolder.get(instanceName);
|
|
947
|
-
if (existingHolder)
|
|
910
|
+
if (existingHolder) if (existingHolder.status === InstanceStatus.Error) this.requestContextHolder.delete(instanceName);
|
|
911
|
+
else {
|
|
948
912
|
const [error, readyHolder] = await BaseHolderManager.waitForHolderReady(existingHolder);
|
|
949
913
|
if (error) throw error;
|
|
950
914
|
return readyHolder.instance;
|
|
@@ -1115,7 +1079,12 @@ var SingletonStorage = class {
|
|
|
1115
1079
|
return [void 0, readyResult[1].instance];
|
|
1116
1080
|
}
|
|
1117
1081
|
return null;
|
|
1118
|
-
default:
|
|
1082
|
+
default:
|
|
1083
|
+
if (holder) {
|
|
1084
|
+
this.logger?.log(`[InstanceResolver] Removing failed instance ${instanceName} from storage to allow retry`);
|
|
1085
|
+
storage.delete(instanceName);
|
|
1086
|
+
}
|
|
1087
|
+
return null;
|
|
1119
1088
|
}
|
|
1120
1089
|
}
|
|
1121
1090
|
/**
|
|
@@ -1912,7 +1881,7 @@ var SingletonStorage = class {
|
|
|
1912
1881
|
|
|
1913
1882
|
//#endregion
|
|
1914
1883
|
//#region src/container/container.mts
|
|
1915
|
-
function applyDecs2203RFactory$
|
|
1884
|
+
function applyDecs2203RFactory$1() {
|
|
1916
1885
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
1917
1886
|
return function addInitializer(initializer) {
|
|
1918
1887
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -2186,18 +2155,18 @@ function applyDecs2203RFactory$2() {
|
|
|
2186
2155
|
};
|
|
2187
2156
|
};
|
|
2188
2157
|
}
|
|
2189
|
-
function _apply_decs_2203_r$
|
|
2190
|
-
return (_apply_decs_2203_r$
|
|
2158
|
+
function _apply_decs_2203_r$1(targetClass, memberDecs, classDecs, parentClass) {
|
|
2159
|
+
return (_apply_decs_2203_r$1 = applyDecs2203RFactory$1())(targetClass, memberDecs, classDecs, parentClass);
|
|
2191
2160
|
}
|
|
2192
|
-
var _dec$
|
|
2161
|
+
var _dec$1, _initClass$1;
|
|
2193
2162
|
let _Container;
|
|
2194
|
-
_dec$
|
|
2163
|
+
_dec$1 = Injectable();
|
|
2195
2164
|
var Container = class {
|
|
2196
2165
|
registry;
|
|
2197
2166
|
logger;
|
|
2198
2167
|
injectors;
|
|
2199
2168
|
static {
|
|
2200
|
-
({c: [_Container, _initClass$
|
|
2169
|
+
({c: [_Container, _initClass$1]} = _apply_decs_2203_r$1(this, [], [_dec$1]));
|
|
2201
2170
|
}
|
|
2202
2171
|
constructor(registry = globalRegistry, logger = null, injectors = defaultInjectors) {
|
|
2203
2172
|
this.registry = registry;
|
|
@@ -2327,7 +2296,7 @@ var Container = class {
|
|
|
2327
2296
|
return this.serviceLocator.clearAll();
|
|
2328
2297
|
}
|
|
2329
2298
|
static {
|
|
2330
|
-
_initClass$
|
|
2299
|
+
_initClass$1();
|
|
2331
2300
|
}
|
|
2332
2301
|
};
|
|
2333
2302
|
|
|
@@ -2345,7 +2314,7 @@ function Factory({ scope = InjectableScope.Singleton, token, registry = globalRe
|
|
|
2345
2314
|
|
|
2346
2315
|
//#endregion
|
|
2347
2316
|
//#region src/event-emitter.mts
|
|
2348
|
-
function applyDecs2203RFactory
|
|
2317
|
+
function applyDecs2203RFactory() {
|
|
2349
2318
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
2350
2319
|
return function addInitializer(initializer) {
|
|
2351
2320
|
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
@@ -2619,15 +2588,15 @@ function applyDecs2203RFactory$1() {
|
|
|
2619
2588
|
};
|
|
2620
2589
|
};
|
|
2621
2590
|
}
|
|
2622
|
-
function _apply_decs_2203_r
|
|
2623
|
-
return (_apply_decs_2203_r
|
|
2591
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
2592
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
2624
2593
|
}
|
|
2625
|
-
var _dec
|
|
2594
|
+
var _dec, _initClass;
|
|
2626
2595
|
let _EventEmitter;
|
|
2627
|
-
_dec
|
|
2596
|
+
_dec = Injectable({ scope: InjectableScope.Transient });
|
|
2628
2597
|
var EventEmitter = class {
|
|
2629
2598
|
static {
|
|
2630
|
-
({c: [_EventEmitter, _initClass
|
|
2599
|
+
({c: [_EventEmitter, _initClass]} = _apply_decs_2203_r(this, [], [_dec]));
|
|
2631
2600
|
}
|
|
2632
2601
|
listeners = /* @__PURE__ */ new Map();
|
|
2633
2602
|
on(event, listener) {
|
|
@@ -2653,361 +2622,11 @@ var EventEmitter = class {
|
|
|
2653
2622
|
if (!this.listeners.has(event)) return;
|
|
2654
2623
|
return Promise.all(Array.from(this.listeners.get(event)).map((listener) => listener(...args)));
|
|
2655
2624
|
}
|
|
2656
|
-
static {
|
|
2657
|
-
_initClass$1();
|
|
2658
|
-
}
|
|
2659
|
-
};
|
|
2660
|
-
|
|
2661
|
-
//#endregion
|
|
2662
|
-
//#region src/testing/test-container.mts
|
|
2663
|
-
function applyDecs2203RFactory() {
|
|
2664
|
-
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
2665
|
-
return function addInitializer(initializer) {
|
|
2666
|
-
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
2667
|
-
assertCallable(initializer, "An initializer");
|
|
2668
|
-
initializers.push(initializer);
|
|
2669
|
-
};
|
|
2670
|
-
}
|
|
2671
|
-
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
2672
|
-
var kindStr;
|
|
2673
|
-
switch (kind) {
|
|
2674
|
-
case 1:
|
|
2675
|
-
kindStr = "accessor";
|
|
2676
|
-
break;
|
|
2677
|
-
case 2:
|
|
2678
|
-
kindStr = "method";
|
|
2679
|
-
break;
|
|
2680
|
-
case 3:
|
|
2681
|
-
kindStr = "getter";
|
|
2682
|
-
break;
|
|
2683
|
-
case 4:
|
|
2684
|
-
kindStr = "setter";
|
|
2685
|
-
break;
|
|
2686
|
-
default: kindStr = "field";
|
|
2687
|
-
}
|
|
2688
|
-
var ctx = {
|
|
2689
|
-
kind: kindStr,
|
|
2690
|
-
name: isPrivate ? "#" + name : name,
|
|
2691
|
-
static: isStatic,
|
|
2692
|
-
private: isPrivate,
|
|
2693
|
-
metadata
|
|
2694
|
-
};
|
|
2695
|
-
var decoratorFinishedRef = { v: false };
|
|
2696
|
-
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
2697
|
-
var get, set;
|
|
2698
|
-
if (kind === 0) if (isPrivate) {
|
|
2699
|
-
get = desc.get;
|
|
2700
|
-
set = desc.set;
|
|
2701
|
-
} else {
|
|
2702
|
-
get = function() {
|
|
2703
|
-
return this[name];
|
|
2704
|
-
};
|
|
2705
|
-
set = function(v) {
|
|
2706
|
-
this[name] = v;
|
|
2707
|
-
};
|
|
2708
|
-
}
|
|
2709
|
-
else if (kind === 2) get = function() {
|
|
2710
|
-
return desc.value;
|
|
2711
|
-
};
|
|
2712
|
-
else {
|
|
2713
|
-
if (kind === 1 || kind === 3) get = function() {
|
|
2714
|
-
return desc.get.call(this);
|
|
2715
|
-
};
|
|
2716
|
-
if (kind === 1 || kind === 4) set = function(v) {
|
|
2717
|
-
desc.set.call(this, v);
|
|
2718
|
-
};
|
|
2719
|
-
}
|
|
2720
|
-
ctx.access = get && set ? {
|
|
2721
|
-
get,
|
|
2722
|
-
set
|
|
2723
|
-
} : get ? { get } : { set };
|
|
2724
|
-
try {
|
|
2725
|
-
return dec(value, ctx);
|
|
2726
|
-
} finally {
|
|
2727
|
-
decoratorFinishedRef.v = true;
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
2731
|
-
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
2732
|
-
}
|
|
2733
|
-
function assertCallable(fn, hint) {
|
|
2734
|
-
if (typeof fn !== "function") throw new TypeError(hint + " must be a function");
|
|
2735
|
-
}
|
|
2736
|
-
function assertValidReturnValue(kind, value) {
|
|
2737
|
-
var type = typeof value;
|
|
2738
|
-
if (kind === 1) {
|
|
2739
|
-
if (type !== "object" || value === null) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
2740
|
-
if (value.get !== void 0) assertCallable(value.get, "accessor.get");
|
|
2741
|
-
if (value.set !== void 0) assertCallable(value.set, "accessor.set");
|
|
2742
|
-
if (value.init !== void 0) assertCallable(value.init, "accessor.init");
|
|
2743
|
-
} else if (type !== "function") {
|
|
2744
|
-
var hint;
|
|
2745
|
-
if (kind === 0) hint = "field";
|
|
2746
|
-
else if (kind === 10) hint = "class";
|
|
2747
|
-
else hint = "method";
|
|
2748
|
-
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
2752
|
-
var decs = decInfo[0];
|
|
2753
|
-
var desc, init, value;
|
|
2754
|
-
if (isPrivate) if (kind === 0 || kind === 1) desc = {
|
|
2755
|
-
get: decInfo[3],
|
|
2756
|
-
set: decInfo[4]
|
|
2757
|
-
};
|
|
2758
|
-
else if (kind === 3) desc = { get: decInfo[3] };
|
|
2759
|
-
else if (kind === 4) desc = { set: decInfo[3] };
|
|
2760
|
-
else desc = { value: decInfo[3] };
|
|
2761
|
-
else if (kind !== 0) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
2762
|
-
if (kind === 1) value = {
|
|
2763
|
-
get: desc.get,
|
|
2764
|
-
set: desc.set
|
|
2765
|
-
};
|
|
2766
|
-
else if (kind === 2) value = desc.value;
|
|
2767
|
-
else if (kind === 3) value = desc.get;
|
|
2768
|
-
else if (kind === 4) value = desc.set;
|
|
2769
|
-
var newValue, get, set;
|
|
2770
|
-
if (typeof decs === "function") {
|
|
2771
|
-
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
2772
|
-
if (newValue !== void 0) {
|
|
2773
|
-
assertValidReturnValue(kind, newValue);
|
|
2774
|
-
if (kind === 0) init = newValue;
|
|
2775
|
-
else if (kind === 1) {
|
|
2776
|
-
init = newValue.init;
|
|
2777
|
-
get = newValue.get || value.get;
|
|
2778
|
-
set = newValue.set || value.set;
|
|
2779
|
-
value = {
|
|
2780
|
-
get,
|
|
2781
|
-
set
|
|
2782
|
-
};
|
|
2783
|
-
} else value = newValue;
|
|
2784
|
-
}
|
|
2785
|
-
} else for (var i = decs.length - 1; i >= 0; i--) {
|
|
2786
|
-
var dec = decs[i];
|
|
2787
|
-
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
2788
|
-
if (newValue !== void 0) {
|
|
2789
|
-
assertValidReturnValue(kind, newValue);
|
|
2790
|
-
var newInit;
|
|
2791
|
-
if (kind === 0) newInit = newValue;
|
|
2792
|
-
else if (kind === 1) {
|
|
2793
|
-
newInit = newValue.init;
|
|
2794
|
-
get = newValue.get || value.get;
|
|
2795
|
-
set = newValue.set || value.set;
|
|
2796
|
-
value = {
|
|
2797
|
-
get,
|
|
2798
|
-
set
|
|
2799
|
-
};
|
|
2800
|
-
} else value = newValue;
|
|
2801
|
-
if (newInit !== void 0) if (init === void 0) init = newInit;
|
|
2802
|
-
else if (typeof init === "function") init = [init, newInit];
|
|
2803
|
-
else init.push(newInit);
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
if (kind === 0 || kind === 1) {
|
|
2807
|
-
if (init === void 0) init = function(instance, init$1) {
|
|
2808
|
-
return init$1;
|
|
2809
|
-
};
|
|
2810
|
-
else if (typeof init !== "function") {
|
|
2811
|
-
var ownInitializers = init;
|
|
2812
|
-
init = function(instance, init$1) {
|
|
2813
|
-
var value$1 = init$1;
|
|
2814
|
-
for (var i$1 = 0; i$1 < ownInitializers.length; i$1++) value$1 = ownInitializers[i$1].call(instance, value$1);
|
|
2815
|
-
return value$1;
|
|
2816
|
-
};
|
|
2817
|
-
} else {
|
|
2818
|
-
var originalInitializer = init;
|
|
2819
|
-
init = function(instance, init$1) {
|
|
2820
|
-
return originalInitializer.call(instance, init$1);
|
|
2821
|
-
};
|
|
2822
|
-
}
|
|
2823
|
-
ret.push(init);
|
|
2824
|
-
}
|
|
2825
|
-
if (kind !== 0) {
|
|
2826
|
-
if (kind === 1) {
|
|
2827
|
-
desc.get = value.get;
|
|
2828
|
-
desc.set = value.set;
|
|
2829
|
-
} else if (kind === 2) desc.value = value;
|
|
2830
|
-
else if (kind === 3) desc.get = value;
|
|
2831
|
-
else if (kind === 4) desc.set = value;
|
|
2832
|
-
if (isPrivate) if (kind === 1) {
|
|
2833
|
-
ret.push(function(instance, args) {
|
|
2834
|
-
return value.get.call(instance, args);
|
|
2835
|
-
});
|
|
2836
|
-
ret.push(function(instance, args) {
|
|
2837
|
-
return value.set.call(instance, args);
|
|
2838
|
-
});
|
|
2839
|
-
} else if (kind === 2) ret.push(value);
|
|
2840
|
-
else ret.push(function(instance, args) {
|
|
2841
|
-
return value.call(instance, args);
|
|
2842
|
-
});
|
|
2843
|
-
else Object.defineProperty(base, name, desc);
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
function applyMemberDecs(Class, decInfos, metadata) {
|
|
2847
|
-
var ret = [];
|
|
2848
|
-
var protoInitializers;
|
|
2849
|
-
var staticInitializers;
|
|
2850
|
-
var existingProtoNonFields = /* @__PURE__ */ new Map();
|
|
2851
|
-
var existingStaticNonFields = /* @__PURE__ */ new Map();
|
|
2852
|
-
for (var i = 0; i < decInfos.length; i++) {
|
|
2853
|
-
var decInfo = decInfos[i];
|
|
2854
|
-
if (!Array.isArray(decInfo)) continue;
|
|
2855
|
-
var kind = decInfo[1];
|
|
2856
|
-
var name = decInfo[2];
|
|
2857
|
-
var isPrivate = decInfo.length > 3;
|
|
2858
|
-
var isStatic = kind >= 5;
|
|
2859
|
-
var base;
|
|
2860
|
-
var initializers;
|
|
2861
|
-
if (isStatic) {
|
|
2862
|
-
base = Class;
|
|
2863
|
-
kind = kind - 5;
|
|
2864
|
-
staticInitializers = staticInitializers || [];
|
|
2865
|
-
initializers = staticInitializers;
|
|
2866
|
-
} else {
|
|
2867
|
-
base = Class.prototype;
|
|
2868
|
-
protoInitializers = protoInitializers || [];
|
|
2869
|
-
initializers = protoInitializers;
|
|
2870
|
-
}
|
|
2871
|
-
if (kind !== 0 && !isPrivate) {
|
|
2872
|
-
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
2873
|
-
var existingKind = existingNonFields.get(name) || 0;
|
|
2874
|
-
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);
|
|
2875
|
-
else if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
2876
|
-
else existingNonFields.set(name, true);
|
|
2877
|
-
}
|
|
2878
|
-
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
2879
|
-
}
|
|
2880
|
-
pushInitializers(ret, protoInitializers);
|
|
2881
|
-
pushInitializers(ret, staticInitializers);
|
|
2882
|
-
return ret;
|
|
2883
|
-
}
|
|
2884
|
-
function pushInitializers(ret, initializers) {
|
|
2885
|
-
if (initializers) ret.push(function(instance) {
|
|
2886
|
-
for (var i = 0; i < initializers.length; i++) initializers[i].call(instance);
|
|
2887
|
-
return instance;
|
|
2888
|
-
});
|
|
2889
|
-
}
|
|
2890
|
-
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
2891
|
-
if (classDecs.length > 0) {
|
|
2892
|
-
var initializers = [];
|
|
2893
|
-
var newClass = targetClass;
|
|
2894
|
-
var name = targetClass.name;
|
|
2895
|
-
for (var i = classDecs.length - 1; i >= 0; i--) {
|
|
2896
|
-
var decoratorFinishedRef = { v: false };
|
|
2897
|
-
try {
|
|
2898
|
-
var nextNewClass = classDecs[i](newClass, {
|
|
2899
|
-
kind: "class",
|
|
2900
|
-
name,
|
|
2901
|
-
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
2902
|
-
metadata
|
|
2903
|
-
});
|
|
2904
|
-
} finally {
|
|
2905
|
-
decoratorFinishedRef.v = true;
|
|
2906
|
-
}
|
|
2907
|
-
if (nextNewClass !== void 0) {
|
|
2908
|
-
assertValidReturnValue(10, nextNewClass);
|
|
2909
|
-
newClass = nextNewClass;
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
return [defineMetadata(newClass, metadata), function() {
|
|
2913
|
-
for (var i$1 = 0; i$1 < initializers.length; i$1++) initializers[i$1].call(newClass);
|
|
2914
|
-
}];
|
|
2915
|
-
}
|
|
2916
|
-
}
|
|
2917
|
-
function defineMetadata(Class, metadata) {
|
|
2918
|
-
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
2919
|
-
configurable: true,
|
|
2920
|
-
enumerable: true,
|
|
2921
|
-
value: metadata
|
|
2922
|
-
});
|
|
2923
|
-
}
|
|
2924
|
-
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
2925
|
-
if (parentClass !== void 0) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
2926
|
-
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
2927
|
-
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
2928
|
-
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
2929
|
-
return {
|
|
2930
|
-
e,
|
|
2931
|
-
get c() {
|
|
2932
|
-
return applyClassDecs(targetClass, classDecs, metadata);
|
|
2933
|
-
}
|
|
2934
|
-
};
|
|
2935
|
-
};
|
|
2936
|
-
}
|
|
2937
|
-
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
2938
|
-
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
2939
|
-
}
|
|
2940
|
-
var _dec, _initClass, _Container$1;
|
|
2941
|
-
/**
|
|
2942
|
-
* A binding builder for the TestContainer that allows chaining binding operations.
|
|
2943
|
-
*/ var TestBindingBuilder = class {
|
|
2944
|
-
container;
|
|
2945
|
-
token;
|
|
2946
|
-
constructor(container, token) {
|
|
2947
|
-
this.container = container;
|
|
2948
|
-
this.token = token;
|
|
2949
|
-
}
|
|
2950
|
-
/**
|
|
2951
|
-
* Binds the token to a specific value.
|
|
2952
|
-
* This is useful for testing with mock values or constants.
|
|
2953
|
-
* @param value The value to bind to the token
|
|
2954
|
-
*/ toValue(value) {
|
|
2955
|
-
const instanceName = this.container.getServiceLocator().getInstanceIdentifier(this.token);
|
|
2956
|
-
this.container.getServiceLocator().getManager().storeCreatedHolder(instanceName, value, InjectableType.Class, InjectableScope.Singleton);
|
|
2957
|
-
return this.container;
|
|
2958
|
-
}
|
|
2959
|
-
/**
|
|
2960
|
-
* Binds the token to a class constructor.
|
|
2961
|
-
* @param target The class constructor to bind to
|
|
2962
|
-
*/ toClass(target) {
|
|
2963
|
-
this.container["registry"].set(this.token, InjectableScope.Singleton, target, InjectableType.Class);
|
|
2964
|
-
return this.container;
|
|
2965
|
-
}
|
|
2966
|
-
};
|
|
2967
|
-
let _TestContainer;
|
|
2968
|
-
_dec = Injectable();
|
|
2969
|
-
var TestContainer = class extends (_Container$1 = _Container) {
|
|
2970
|
-
static {
|
|
2971
|
-
({c: [_TestContainer, _initClass]} = _apply_decs_2203_r(this, [], [_dec], _Container$1));
|
|
2972
|
-
}
|
|
2973
|
-
constructor(registry = globalRegistry, logger = null, injectors = void 0) {
|
|
2974
|
-
super(registry, logger, injectors);
|
|
2975
|
-
}
|
|
2976
|
-
bind(token) {
|
|
2977
|
-
let realToken = token;
|
|
2978
|
-
if (typeof token === "function") realToken = getInjectableToken(token);
|
|
2979
|
-
return new TestBindingBuilder(this, realToken);
|
|
2980
|
-
}
|
|
2981
|
-
bindValue(token, value) {
|
|
2982
|
-
return this.bind(token).toValue(value);
|
|
2983
|
-
}
|
|
2984
|
-
bindClass(token, target) {
|
|
2985
|
-
return this.bind(token).toClass(target);
|
|
2986
|
-
}
|
|
2987
|
-
/**
|
|
2988
|
-
* Creates a new TestContainer instance with the same configuration.
|
|
2989
|
-
* This is useful for creating isolated test containers.
|
|
2990
|
-
* @returns A new TestContainer instance
|
|
2991
|
-
*/ createChild() {
|
|
2992
|
-
return new _TestContainer(this.registry, this.logger, this.injectors);
|
|
2993
|
-
}
|
|
2994
2625
|
static {
|
|
2995
2626
|
_initClass();
|
|
2996
2627
|
}
|
|
2997
2628
|
};
|
|
2998
2629
|
|
|
2999
2630
|
//#endregion
|
|
3000
|
-
|
|
3001
|
-
/**
|
|
3002
|
-
* Browser-specific entry point for @navios/di.
|
|
3003
|
-
*
|
|
3004
|
-
* This entry point forces the use of SyncLocalStorage instead of
|
|
3005
|
-
* Node's AsyncLocalStorage, making it safe for browser environments.
|
|
3006
|
-
*
|
|
3007
|
-
* The browser build is automatically selected by bundlers that respect
|
|
3008
|
-
* the "browser" condition in package.json exports.
|
|
3009
|
-
*/ __testing__.forceSyncMode();
|
|
3010
|
-
|
|
3011
|
-
//#endregion
|
|
3012
|
-
export { BaseHolderManager, BoundInjectionToken, CircularDetector, _Container as Container, DIError, DIErrorCode, DefaultRequestContext, _EventEmitter as EventEmitter, Factory, FactoryInjectionToken, HolderManager, Injectable, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceResolver, InstanceStatus, Instantiator, Invalidator, LifecycleEventBus, Registry, RequestStorage, ScopedContainer, ServiceLocator, SingletonStorage, TestBindingBuilder, _TestContainer as TestContainer, TokenProcessor, asyncInject, createRequestContext, defaultInjectors, getCurrentResolutionContext, getInjectableToken, getInjectors, globalRegistry, inject, optional, provideFactoryContext, resolutionContext, withResolutionContext, withoutResolutionContext, wrapSyncInit };
|
|
2631
|
+
export { BaseHolderManager, BoundInjectionToken, CircularDetector, _Container as Container, DIError, DIErrorCode, DefaultRequestContext, _EventEmitter as EventEmitter, Factory, FactoryInjectionToken, HolderManager, Injectable, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InstanceResolver, InstanceStatus, Instantiator, Invalidator, LifecycleEventBus, Registry, RequestStorage, ScopedContainer, ServiceLocator, SingletonStorage, TokenProcessor, asyncInject, createRequestContext, defaultInjectors, getCurrentResolutionContext, getInjectableToken, getInjectors, globalRegistry, inject, optional, provideFactoryContext, withResolutionContext, withoutResolutionContext, wrapSyncInit };
|
|
3013
2632
|
//# sourceMappingURL=index.mjs.map
|