@navios/di-react 1.0.0-alpha.3 → 2.0.0-alpha.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 -1
- package/README.md +45 -665
- package/lib/index.cjs +573 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +262 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +159 -140
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +371 -381
- package/lib/index.mjs.map +1 -1
- package/package.json +32 -18
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -270
- package/coverage/coverage-final.json +0 -10
- package/coverage/favicon.png +0 -0
- package/coverage/hooks/index.html +0 -191
- package/coverage/hooks/use-container.mts.html +0 -268
- package/coverage/hooks/use-invalidate.mts.html +0 -208
- package/coverage/hooks/use-optional-service.mts.html +0 -910
- package/coverage/hooks/use-scope.mts.html +0 -346
- package/coverage/hooks/use-service.mts.html +0 -760
- package/coverage/hooks/use-suspense-service.mts.html +0 -784
- package/coverage/index.html +0 -131
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/providers/container-provider.mts.html +0 -139
- package/coverage/providers/context.mts.html +0 -130
- package/coverage/providers/index.html +0 -146
- package/coverage/providers/scope-provider.mts.html +0 -355
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/lib/index.d.ts +0 -243
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -582
- package/lib/index.js.map +0 -1
- package/project.json +0 -61
- package/src/hooks/__tests__/use-container.spec.mts +0 -143
- package/src/hooks/__tests__/use-invalidate.spec.mts +0 -80
- package/src/hooks/__tests__/use-optional-service.spec.mts +0 -233
- package/src/hooks/__tests__/use-scope.spec.mts +0 -293
- package/src/hooks/__tests__/use-service.spec.mts +0 -212
- package/src/hooks/__tests__/use-suspense-service.spec.mts +0 -286
- package/src/hooks/index.mts +0 -14
- package/src/hooks/use-container.mts +0 -61
- package/src/hooks/use-invalidate.mts +0 -41
- package/src/hooks/use-optional-service.mts +0 -275
- package/src/hooks/use-scope.mts +0 -87
- package/src/hooks/use-service.mts +0 -225
- package/src/hooks/use-suspense-service.mts +0 -233
- package/src/index.mts +0 -8
- package/src/providers/__tests__/scope-provider.spec.mts +0 -366
- package/src/providers/container-provider.mts +0 -18
- package/src/providers/context.mts +0 -15
- package/src/providers/index.mts +0 -5
- package/src/providers/scope-provider.mts +0 -90
- package/src/types.mts +0 -21
- package/tsconfig.json +0 -13
- package/tsdown.config.mts +0 -14
- package/vitest.config.mts +0 -12
package/lib/index.js
DELETED
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
let react = require("react");
|
|
2
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
-
|
|
4
|
-
//#region src/providers/context.mts
|
|
5
|
-
/**
|
|
6
|
-
* Context for the root Container.
|
|
7
|
-
* This is set by ContainerProvider and provides the base container.
|
|
8
|
-
*/
|
|
9
|
-
const ContainerContext = (0, react.createContext)(null);
|
|
10
|
-
/**
|
|
11
|
-
* Context for the current ScopedContainer (if inside a ScopeProvider).
|
|
12
|
-
* This allows nested components to access request-scoped services.
|
|
13
|
-
*/
|
|
14
|
-
const ScopedContainerContext = (0, react.createContext)(null);
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/providers/container-provider.mts
|
|
18
|
-
function ContainerProvider({ container, children }) {
|
|
19
|
-
return (0, react_jsx_runtime.jsx)(ContainerContext.Provider, {
|
|
20
|
-
value: container,
|
|
21
|
-
children
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/providers/scope-provider.mts
|
|
27
|
-
/**
|
|
28
|
-
* ScopeProvider creates a new request scope for dependency injection.
|
|
29
|
-
*
|
|
30
|
-
* Services with `scope: 'Request'` will be instantiated once per ScopeProvider
|
|
31
|
-
* and shared among all components within that provider.
|
|
32
|
-
*
|
|
33
|
-
* This is useful for:
|
|
34
|
-
* - Table rows that need isolated state
|
|
35
|
-
* - Modal dialogs with their own service instances
|
|
36
|
-
* - Multi-tenant scenarios
|
|
37
|
-
* - Any case where you need isolated service instances
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* // Each row gets its own RowStateService instance
|
|
42
|
-
* {rows.map(row => (
|
|
43
|
-
* <ScopeProvider key={row.id} scopeId={row.id} metadata={{ rowData: row }}>
|
|
44
|
-
* <TableRow />
|
|
45
|
-
* </ScopeProvider>
|
|
46
|
-
* ))}
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
function ScopeProvider({ scopeId, metadata, children }) {
|
|
50
|
-
const container = (0, react.useContext)(ContainerContext);
|
|
51
|
-
if (!container) throw new Error("ScopeProvider must be used within a ContainerProvider");
|
|
52
|
-
const generatedId = (0, react.useId)();
|
|
53
|
-
const effectiveScopeId = scopeId ?? generatedId;
|
|
54
|
-
const scopedContainerRef = (0, react.useRef)(null);
|
|
55
|
-
if (!scopedContainerRef.current) {
|
|
56
|
-
if (!container.hasActiveRequest(effectiveScopeId)) scopedContainerRef.current = container.beginRequest(effectiveScopeId, metadata);
|
|
57
|
-
}
|
|
58
|
-
(0, react.useEffect)(() => {
|
|
59
|
-
const scopedContainer = scopedContainerRef.current;
|
|
60
|
-
return () => {
|
|
61
|
-
if (scopedContainer) scopedContainer.endRequest();
|
|
62
|
-
};
|
|
63
|
-
}, []);
|
|
64
|
-
if (!scopedContainerRef.current) return null;
|
|
65
|
-
return (0, react_jsx_runtime.jsx)(ScopedContainerContext.Provider, {
|
|
66
|
-
value: scopedContainerRef.current,
|
|
67
|
-
children
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/hooks/use-container.mts
|
|
73
|
-
/**
|
|
74
|
-
* Hook to get the current container (ScopedContainer if inside ScopeProvider, otherwise Container).
|
|
75
|
-
*
|
|
76
|
-
* This is the primary hook for accessing the DI container. It automatically
|
|
77
|
-
* returns the correct container based on context:
|
|
78
|
-
* - Inside a ScopeProvider: returns the ScopedContainer for request-scoped services
|
|
79
|
-
* - Outside a ScopeProvider: returns the root Container
|
|
80
|
-
*
|
|
81
|
-
* @returns The current container (ScopedContainer or Container)
|
|
82
|
-
*/
|
|
83
|
-
function useContainer() {
|
|
84
|
-
const scopedContainer = (0, react.useContext)(ScopedContainerContext);
|
|
85
|
-
const container = (0, react.useContext)(ContainerContext);
|
|
86
|
-
if (scopedContainer) return scopedContainer;
|
|
87
|
-
if (!container) throw new Error("useContainer must be used within a ContainerProvider");
|
|
88
|
-
return container;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Hook to get the root Container, regardless of whether we're inside a ScopeProvider.
|
|
92
|
-
*
|
|
93
|
-
* Use this when you need access to the root container specifically,
|
|
94
|
-
* for example to create new request scopes programmatically.
|
|
95
|
-
*
|
|
96
|
-
* @returns The root Container
|
|
97
|
-
*/
|
|
98
|
-
function useRootContainer() {
|
|
99
|
-
const container = (0, react.useContext)(ContainerContext);
|
|
100
|
-
if (!container) throw new Error("useRootContainer must be used within a ContainerProvider");
|
|
101
|
-
return container;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/hooks/use-service.mts
|
|
106
|
-
function serviceReducer(state, action) {
|
|
107
|
-
switch (action.type) {
|
|
108
|
-
case "loading": return { status: "loading" };
|
|
109
|
-
case "success": return {
|
|
110
|
-
status: "success",
|
|
111
|
-
data: action.data
|
|
112
|
-
};
|
|
113
|
-
case "error": return {
|
|
114
|
-
status: "error",
|
|
115
|
-
error: action.error
|
|
116
|
-
};
|
|
117
|
-
case "reset": return { status: "idle" };
|
|
118
|
-
default: return state;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function useService(token, args) {
|
|
122
|
-
const container = useContainer();
|
|
123
|
-
const rootContainer = useRootContainer();
|
|
124
|
-
const initialSyncInstanceRef = (0, react.useRef)(void 0);
|
|
125
|
-
const isFirstRenderRef = (0, react.useRef)(true);
|
|
126
|
-
if (isFirstRenderRef.current) {
|
|
127
|
-
initialSyncInstanceRef.current = container.tryGetSync(token, args);
|
|
128
|
-
isFirstRenderRef.current = false;
|
|
129
|
-
}
|
|
130
|
-
const [state, dispatch] = (0, react.useReducer)(serviceReducer, initialSyncInstanceRef.current ? {
|
|
131
|
-
status: "success",
|
|
132
|
-
data: initialSyncInstanceRef.current
|
|
133
|
-
} : { status: "idle" });
|
|
134
|
-
const instanceNameRef = (0, react.useRef)(null);
|
|
135
|
-
const [refetchCounter, setRefetchCounter] = (0, react.useState)(0);
|
|
136
|
-
if (process.env.NODE_ENV === "development") {
|
|
137
|
-
const argsRef = (0, react.useRef)(args);
|
|
138
|
-
(0, react.useEffect)(() => {
|
|
139
|
-
if (argsRef.current !== args) {
|
|
140
|
-
if (JSON.stringify(argsRef.current) === JSON.stringify(args)) console.warn(`useService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!
|
|
141
|
-
This is likely because you are using a value that is not memoized.
|
|
142
|
-
Please use a memoized value or use a different approach to pass the args.
|
|
143
|
-
Example:
|
|
144
|
-
const args = useMemo(() => ({ userId: '123' }), [])
|
|
145
|
-
return useService(UserToken, args)`);
|
|
146
|
-
argsRef.current = args;
|
|
147
|
-
}
|
|
148
|
-
}, [args]);
|
|
149
|
-
}
|
|
150
|
-
(0, react.useEffect)(() => {
|
|
151
|
-
const eventBus = rootContainer.getEventBus();
|
|
152
|
-
let unsubscribe;
|
|
153
|
-
let isMounted = true;
|
|
154
|
-
const fetchAndSubscribe = async () => {
|
|
155
|
-
try {
|
|
156
|
-
const instance = await container.get(token, args);
|
|
157
|
-
if (!isMounted) return;
|
|
158
|
-
const instanceName = container.calculateInstanceName(token, args);
|
|
159
|
-
if (instanceName) instanceNameRef.current = instanceName;
|
|
160
|
-
dispatch({
|
|
161
|
-
type: "success",
|
|
162
|
-
data: instance
|
|
163
|
-
});
|
|
164
|
-
if (instanceName) unsubscribe = eventBus.on(instanceName, "destroy", () => {
|
|
165
|
-
if (isMounted) {
|
|
166
|
-
dispatch({ type: "loading" });
|
|
167
|
-
fetchAndSubscribe();
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (isMounted) dispatch({
|
|
172
|
-
type: "error",
|
|
173
|
-
error
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
if (initialSyncInstanceRef.current && refetchCounter === 0) {
|
|
178
|
-
const instanceName = container.calculateInstanceName(token, args);
|
|
179
|
-
if (instanceName) {
|
|
180
|
-
instanceNameRef.current = instanceName;
|
|
181
|
-
unsubscribe = eventBus.on(instanceName, "destroy", () => {
|
|
182
|
-
if (isMounted) {
|
|
183
|
-
dispatch({ type: "loading" });
|
|
184
|
-
fetchAndSubscribe();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
dispatch({ type: "loading" });
|
|
190
|
-
fetchAndSubscribe();
|
|
191
|
-
}
|
|
192
|
-
return () => {
|
|
193
|
-
isMounted = false;
|
|
194
|
-
unsubscribe?.();
|
|
195
|
-
};
|
|
196
|
-
}, [
|
|
197
|
-
container,
|
|
198
|
-
rootContainer,
|
|
199
|
-
token,
|
|
200
|
-
args,
|
|
201
|
-
refetchCounter
|
|
202
|
-
]);
|
|
203
|
-
const refetch = (0, react.useCallback)(() => {
|
|
204
|
-
setRefetchCounter((c) => c + 1);
|
|
205
|
-
}, []);
|
|
206
|
-
return {
|
|
207
|
-
data: state.status === "success" ? state.data : void 0,
|
|
208
|
-
error: state.status === "error" ? state.error : void 0,
|
|
209
|
-
isLoading: state.status === "loading",
|
|
210
|
-
isSuccess: state.status === "success",
|
|
211
|
-
isError: state.status === "error",
|
|
212
|
-
refetch
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/hooks/use-suspense-service.mts
|
|
218
|
-
const cacheMap = /* @__PURE__ */ new WeakMap();
|
|
219
|
-
function getCacheKey(token, args) {
|
|
220
|
-
return `${typeof token === "function" ? token.name : token.id || token.token?.id || String(token)}:${JSON.stringify(args ?? null)}`;
|
|
221
|
-
}
|
|
222
|
-
function getCache(container) {
|
|
223
|
-
let cache = cacheMap.get(container);
|
|
224
|
-
if (!cache) {
|
|
225
|
-
cache = /* @__PURE__ */ new Map();
|
|
226
|
-
cacheMap.set(container, cache);
|
|
227
|
-
}
|
|
228
|
-
return cache;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Sets up invalidation subscription for a cache entry if not already subscribed.
|
|
232
|
-
* When the service is destroyed, clears the cache and notifies subscribers.
|
|
233
|
-
*/
|
|
234
|
-
function setupInvalidationSubscription(entry, rootContainer) {
|
|
235
|
-
if (entry.unsubscribe || !entry.instanceName) return;
|
|
236
|
-
entry.unsubscribe = rootContainer.getEventBus().on(entry.instanceName, "destroy", () => {
|
|
237
|
-
entry.result = void 0;
|
|
238
|
-
entry.error = void 0;
|
|
239
|
-
entry.status = "pending";
|
|
240
|
-
entry.promise = null;
|
|
241
|
-
entry.subscribers.forEach((callback) => callback());
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
function useSuspenseService(token, args) {
|
|
245
|
-
const container = useContainer();
|
|
246
|
-
const rootContainer = useRootContainer();
|
|
247
|
-
const cache = getCache(container);
|
|
248
|
-
const cacheKey = getCacheKey(token, args);
|
|
249
|
-
const entryRef = (0, react.useRef)(null);
|
|
250
|
-
if (process.env.NODE_ENV === "development") {
|
|
251
|
-
const argsRef = (0, react.useRef)(args);
|
|
252
|
-
(0, react.useEffect)(() => {
|
|
253
|
-
if (argsRef.current !== args) {
|
|
254
|
-
if (JSON.stringify(argsRef.current) === JSON.stringify(args)) console.warn(`useSuspenseService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!
|
|
255
|
-
This is likely because you are using a value that is not memoized.
|
|
256
|
-
Please use a memoized value or use a different approach to pass the args.
|
|
257
|
-
Example:
|
|
258
|
-
const args = useMemo(() => ({ userId: '123' }), [])
|
|
259
|
-
return useSuspenseService(UserToken, args)`);
|
|
260
|
-
argsRef.current = args;
|
|
261
|
-
}
|
|
262
|
-
}, [args]);
|
|
263
|
-
}
|
|
264
|
-
if (!cache.has(cacheKey)) {
|
|
265
|
-
const syncInstance = container.tryGetSync(token, args);
|
|
266
|
-
const instanceName = container.calculateInstanceName(token, args);
|
|
267
|
-
const entry$1 = {
|
|
268
|
-
promise: null,
|
|
269
|
-
result: syncInstance ?? void 0,
|
|
270
|
-
error: void 0,
|
|
271
|
-
status: syncInstance ? "resolved" : "pending",
|
|
272
|
-
version: 0,
|
|
273
|
-
subscribers: /* @__PURE__ */ new Set(),
|
|
274
|
-
instanceName,
|
|
275
|
-
unsubscribe: void 0
|
|
276
|
-
};
|
|
277
|
-
cache.set(cacheKey, entry$1);
|
|
278
|
-
}
|
|
279
|
-
const entry = cache.get(cacheKey);
|
|
280
|
-
entryRef.current = entry;
|
|
281
|
-
const fetchService = (0, react.useCallback)(() => {
|
|
282
|
-
const currentEntry = entryRef.current;
|
|
283
|
-
if (!currentEntry) return;
|
|
284
|
-
currentEntry.status = "pending";
|
|
285
|
-
currentEntry.version++;
|
|
286
|
-
currentEntry.promise = container.get(token, args).then((instance) => {
|
|
287
|
-
currentEntry.result = instance;
|
|
288
|
-
currentEntry.status = "resolved";
|
|
289
|
-
setupInvalidationSubscription(currentEntry, rootContainer);
|
|
290
|
-
currentEntry.subscribers.forEach((callback) => callback());
|
|
291
|
-
return instance;
|
|
292
|
-
}).catch((error) => {
|
|
293
|
-
currentEntry.error = error;
|
|
294
|
-
currentEntry.status = "rejected";
|
|
295
|
-
throw error;
|
|
296
|
-
});
|
|
297
|
-
return currentEntry.promise;
|
|
298
|
-
}, [
|
|
299
|
-
container,
|
|
300
|
-
rootContainer,
|
|
301
|
-
token,
|
|
302
|
-
args
|
|
303
|
-
]);
|
|
304
|
-
const subscribe = (0, react.useCallback)((callback) => {
|
|
305
|
-
entry.subscribers.add(callback);
|
|
306
|
-
return () => {
|
|
307
|
-
entry.subscribers.delete(callback);
|
|
308
|
-
};
|
|
309
|
-
}, [entry]);
|
|
310
|
-
const getSnapshot = (0, react.useCallback)(() => {
|
|
311
|
-
return `${entry.status}:${entry.version}`;
|
|
312
|
-
}, [entry]);
|
|
313
|
-
(0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
314
|
-
(0, react.useEffect)(() => {
|
|
315
|
-
const currentEntry = entryRef.current;
|
|
316
|
-
if (currentEntry && currentEntry.status === "resolved" && currentEntry.instanceName && !currentEntry.unsubscribe) setupInvalidationSubscription(currentEntry, rootContainer);
|
|
317
|
-
}, [rootContainer, entry]);
|
|
318
|
-
if (entry.status === "pending" && !entry.promise) fetchService();
|
|
319
|
-
if (entry.status === "pending") throw entry.promise;
|
|
320
|
-
if (entry.status === "rejected") throw entry.error;
|
|
321
|
-
return entry.result;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
//#endregion
|
|
325
|
-
//#region src/hooks/use-optional-service.mts
|
|
326
|
-
function optionalServiceReducer(state, action) {
|
|
327
|
-
switch (action.type) {
|
|
328
|
-
case "loading": return { status: "loading" };
|
|
329
|
-
case "success": return {
|
|
330
|
-
status: "success",
|
|
331
|
-
data: action.data
|
|
332
|
-
};
|
|
333
|
-
case "not-found": return { status: "not-found" };
|
|
334
|
-
case "error": return {
|
|
335
|
-
status: "error",
|
|
336
|
-
error: action.error
|
|
337
|
-
};
|
|
338
|
-
case "reset": return { status: "idle" };
|
|
339
|
-
default: return state;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Hook to optionally load a service from the DI container.
|
|
344
|
-
*
|
|
345
|
-
* Unlike useService, this hook does NOT throw an error if the service is not registered.
|
|
346
|
-
* Instead, it returns `isNotFound: true` when the service doesn't exist.
|
|
347
|
-
*
|
|
348
|
-
* This is useful for:
|
|
349
|
-
* - Optional dependencies that may or may not be configured
|
|
350
|
-
* - Feature flags where a service might not be available
|
|
351
|
-
* - Plugins or extensions that are conditionally registered
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* ```tsx
|
|
355
|
-
* function Analytics() {
|
|
356
|
-
* const { data: analytics, isNotFound } = useOptionalService(AnalyticsService)
|
|
357
|
-
*
|
|
358
|
-
* if (isNotFound) {
|
|
359
|
-
* // Analytics service not configured, skip tracking
|
|
360
|
-
* return null
|
|
361
|
-
* }
|
|
362
|
-
*
|
|
363
|
-
* return <AnalyticsTracker service={analytics} />
|
|
364
|
-
* }
|
|
365
|
-
* ```
|
|
366
|
-
*/
|
|
367
|
-
function useOptionalService(token, args) {
|
|
368
|
-
const container = useContainer();
|
|
369
|
-
const rootContainer = useRootContainer();
|
|
370
|
-
const initialSyncInstanceRef = (0, react.useRef)(void 0);
|
|
371
|
-
const isFirstRenderRef = (0, react.useRef)(true);
|
|
372
|
-
if (isFirstRenderRef.current) {
|
|
373
|
-
try {
|
|
374
|
-
initialSyncInstanceRef.current = container.tryGetSync(token, args);
|
|
375
|
-
} catch {}
|
|
376
|
-
isFirstRenderRef.current = false;
|
|
377
|
-
}
|
|
378
|
-
const [state, dispatch] = (0, react.useReducer)(optionalServiceReducer, initialSyncInstanceRef.current ? {
|
|
379
|
-
status: "success",
|
|
380
|
-
data: initialSyncInstanceRef.current
|
|
381
|
-
} : { status: "idle" });
|
|
382
|
-
const instanceNameRef = (0, react.useRef)(null);
|
|
383
|
-
if (process.env.NODE_ENV === "development") {
|
|
384
|
-
const argsRef = (0, react.useRef)(args);
|
|
385
|
-
(0, react.useEffect)(() => {
|
|
386
|
-
if (argsRef.current !== args) {
|
|
387
|
-
if (JSON.stringify(argsRef.current) === JSON.stringify(args)) console.warn(`useOptionalService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!
|
|
388
|
-
This is likely because you are using a value that is not memoized.
|
|
389
|
-
Please use a memoized value or use a different approach to pass the args.
|
|
390
|
-
Example:
|
|
391
|
-
const args = useMemo(() => ({ userId: '123' }), [])
|
|
392
|
-
return useOptionalService(UserToken, args)`);
|
|
393
|
-
argsRef.current = args;
|
|
394
|
-
}
|
|
395
|
-
}, [args]);
|
|
396
|
-
}
|
|
397
|
-
const fetchService = (0, react.useCallback)(async () => {
|
|
398
|
-
dispatch({ type: "loading" });
|
|
399
|
-
try {
|
|
400
|
-
const instance = await container.get(token, args);
|
|
401
|
-
const instanceName = container.calculateInstanceName(token, args);
|
|
402
|
-
if (instanceName) instanceNameRef.current = instanceName;
|
|
403
|
-
dispatch({
|
|
404
|
-
type: "success",
|
|
405
|
-
data: instance
|
|
406
|
-
});
|
|
407
|
-
} catch (error) {
|
|
408
|
-
const err = error;
|
|
409
|
-
const errorMessage = err.message?.toLowerCase() ?? "";
|
|
410
|
-
if (errorMessage.includes("not found") || errorMessage.includes("not registered") || errorMessage.includes("no provider")) dispatch({ type: "not-found" });
|
|
411
|
-
else dispatch({
|
|
412
|
-
type: "error",
|
|
413
|
-
error: err
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}, [
|
|
417
|
-
container,
|
|
418
|
-
token,
|
|
419
|
-
args
|
|
420
|
-
]);
|
|
421
|
-
(0, react.useEffect)(() => {
|
|
422
|
-
const eventBus = rootContainer.getEventBus();
|
|
423
|
-
let unsubscribe;
|
|
424
|
-
if (initialSyncInstanceRef.current) {
|
|
425
|
-
const instanceName = container.calculateInstanceName(token, args);
|
|
426
|
-
if (instanceName) {
|
|
427
|
-
instanceNameRef.current = instanceName;
|
|
428
|
-
unsubscribe = eventBus.on(instanceName, "destroy", () => {
|
|
429
|
-
fetchService();
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
} else {
|
|
433
|
-
fetchService().then(() => {
|
|
434
|
-
if (instanceNameRef.current) unsubscribe = eventBus.on(instanceNameRef.current, "destroy", () => {
|
|
435
|
-
fetchService();
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
return () => {
|
|
439
|
-
unsubscribe?.();
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
return () => {
|
|
443
|
-
unsubscribe?.();
|
|
444
|
-
};
|
|
445
|
-
}, [
|
|
446
|
-
fetchService,
|
|
447
|
-
rootContainer,
|
|
448
|
-
token,
|
|
449
|
-
args
|
|
450
|
-
]);
|
|
451
|
-
return {
|
|
452
|
-
data: state.status === "success" ? state.data : void 0,
|
|
453
|
-
error: state.status === "error" ? state.error : void 0,
|
|
454
|
-
isLoading: state.status === "loading",
|
|
455
|
-
isSuccess: state.status === "success",
|
|
456
|
-
isNotFound: state.status === "not-found",
|
|
457
|
-
isError: state.status === "error",
|
|
458
|
-
refetch: fetchService
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
//#endregion
|
|
463
|
-
//#region src/hooks/use-invalidate.mts
|
|
464
|
-
/**
|
|
465
|
-
* Hook that returns a function to invalidate a service instance directly.
|
|
466
|
-
*
|
|
467
|
-
* This is useful when you have the service instance and want to invalidate it
|
|
468
|
-
* without knowing its token.
|
|
469
|
-
*
|
|
470
|
-
* @example
|
|
471
|
-
* ```tsx
|
|
472
|
-
* function UserProfile() {
|
|
473
|
-
* const { data: user } = useService(UserService)
|
|
474
|
-
* const invalidateInstance = useInvalidateInstance()
|
|
475
|
-
*
|
|
476
|
-
* const handleRefresh = () => {
|
|
477
|
-
* if (user) {
|
|
478
|
-
* invalidateInstance(user)
|
|
479
|
-
* }
|
|
480
|
-
* }
|
|
481
|
-
*
|
|
482
|
-
* return (
|
|
483
|
-
* <div>
|
|
484
|
-
* <span>{user?.name}</span>
|
|
485
|
-
* <button onClick={handleRefresh}>Refresh</button>
|
|
486
|
-
* </div>
|
|
487
|
-
* )
|
|
488
|
-
* }
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
|
-
function useInvalidateInstance() {
|
|
492
|
-
const container = useContainer();
|
|
493
|
-
return (0, react.useCallback)(async (instance) => {
|
|
494
|
-
await container.invalidate(instance);
|
|
495
|
-
}, [container]);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region src/hooks/use-scope.mts
|
|
500
|
-
/**
|
|
501
|
-
* Hook to get the current scope ID.
|
|
502
|
-
* Returns null if not inside a ScopeProvider.
|
|
503
|
-
*/
|
|
504
|
-
function useScope() {
|
|
505
|
-
return (0, react.useContext)(ScopedContainerContext)?.getRequestId() ?? null;
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Hook to get the current scope ID, throwing if not inside a ScopeProvider.
|
|
509
|
-
* Use this when your component requires a scope to function correctly.
|
|
510
|
-
*/
|
|
511
|
-
function useScopeOrThrow() {
|
|
512
|
-
const scopeId = useScope();
|
|
513
|
-
if (scopeId === null) throw new Error("useScopeOrThrow must be used within a ScopeProvider. Wrap your component tree with <ScopeProvider> to create a request scope.");
|
|
514
|
-
return scopeId;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Hook to get the current ScopedContainer.
|
|
518
|
-
* Returns null if not inside a ScopeProvider.
|
|
519
|
-
*
|
|
520
|
-
* Use this to access scope metadata or other ScopedContainer methods.
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```tsx
|
|
524
|
-
* function TableRow() {
|
|
525
|
-
* const scope = useScopedContainer()
|
|
526
|
-
* const rowData = scope?.getMetadata('rowData')
|
|
527
|
-
* // ...
|
|
528
|
-
* }
|
|
529
|
-
* ```
|
|
530
|
-
*/
|
|
531
|
-
function useScopedContainer() {
|
|
532
|
-
return (0, react.useContext)(ScopedContainerContext);
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Hook to get the current ScopedContainer, throwing if not inside a ScopeProvider.
|
|
536
|
-
* Use this when your component requires a scope to function correctly.
|
|
537
|
-
*/
|
|
538
|
-
function useScopedContainerOrThrow() {
|
|
539
|
-
const scopedContainer = useScopedContainer();
|
|
540
|
-
if (scopedContainer === null) throw new Error("useScopedContainerOrThrow must be used within a ScopeProvider. Wrap your component tree with <ScopeProvider> to create a request scope.");
|
|
541
|
-
return scopedContainer;
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Hook to get metadata from the current scope.
|
|
545
|
-
* Returns undefined if not inside a ScopeProvider or if the key doesn't exist.
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* ```tsx
|
|
549
|
-
* // In parent component:
|
|
550
|
-
* <ScopeProvider metadata={{ userId: '123', theme: 'dark' }}>
|
|
551
|
-
* <ChildComponent />
|
|
552
|
-
* </ScopeProvider>
|
|
553
|
-
*
|
|
554
|
-
* // In child component:
|
|
555
|
-
* function ChildComponent() {
|
|
556
|
-
* const userId = useScopeMetadata<string>('userId')
|
|
557
|
-
* const theme = useScopeMetadata<'light' | 'dark'>('theme')
|
|
558
|
-
* // ...
|
|
559
|
-
* }
|
|
560
|
-
* ```
|
|
561
|
-
*/
|
|
562
|
-
function useScopeMetadata(key) {
|
|
563
|
-
return (0, react.useContext)(ScopedContainerContext)?.getMetadata(key);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
//#endregion
|
|
567
|
-
exports.ContainerContext = ContainerContext;
|
|
568
|
-
exports.ContainerProvider = ContainerProvider;
|
|
569
|
-
exports.ScopeProvider = ScopeProvider;
|
|
570
|
-
exports.ScopedContainerContext = ScopedContainerContext;
|
|
571
|
-
exports.useContainer = useContainer;
|
|
572
|
-
exports.useInvalidateInstance = useInvalidateInstance;
|
|
573
|
-
exports.useOptionalService = useOptionalService;
|
|
574
|
-
exports.useRootContainer = useRootContainer;
|
|
575
|
-
exports.useScope = useScope;
|
|
576
|
-
exports.useScopeMetadata = useScopeMetadata;
|
|
577
|
-
exports.useScopeOrThrow = useScopeOrThrow;
|
|
578
|
-
exports.useScopedContainer = useScopedContainer;
|
|
579
|
-
exports.useScopedContainerOrThrow = useScopedContainerOrThrow;
|
|
580
|
-
exports.useService = useService;
|
|
581
|
-
exports.useSuspenseService = useSuspenseService;
|
|
582
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["unsubscribe: (() => void) | undefined","entry: CacheEntry<any>","entry","unsubscribe: (() => void) | undefined"],"sources":["../src/providers/context.mts","../src/providers/container-provider.mts","../src/providers/scope-provider.mts","../src/hooks/use-container.mts","../src/hooks/use-service.mts","../src/hooks/use-suspense-service.mts","../src/hooks/use-optional-service.mts","../src/hooks/use-invalidate.mts","../src/hooks/use-scope.mts"],"sourcesContent":["import { createContext } from 'react'\n\nimport type { Container, ScopedContainer } from '@navios/di'\n\n/**\n * Context for the root Container.\n * This is set by ContainerProvider and provides the base container.\n */\nexport const ContainerContext = createContext<Container | null>(null)\n\n/**\n * Context for the current ScopedContainer (if inside a ScopeProvider).\n * This allows nested components to access request-scoped services.\n */\nexport const ScopedContainerContext = createContext<ScopedContainer | null>(null)\n","import type { Container } from '@navios/di'\nimport type { ReactNode } from 'react'\n\nimport { jsx } from 'react/jsx-runtime'\n\nimport { ContainerContext } from './context.mjs'\n\nexport interface ContainerProviderProps {\n container: Container\n children: ReactNode\n}\n\nexport function ContainerProvider({\n container,\n children,\n}: ContainerProviderProps) {\n return jsx(ContainerContext.Provider, { value: container, children })\n}\n","import type { ScopedContainer } from '@navios/di'\nimport type { ReactNode } from 'react'\n\nimport { useContext, useEffect, useId, useRef } from 'react'\nimport { jsx } from 'react/jsx-runtime'\n\nimport { ContainerContext, ScopedContainerContext } from './context.mjs'\n\nexport interface ScopeProviderProps {\n /**\n * Optional explicit scope ID. If not provided, a unique ID will be generated.\n * Useful when you need to reference the scope externally.\n */\n scopeId?: string\n /**\n * Optional metadata to attach to the request context.\n * Can be used to pass data like user info, request headers, etc.\n */\n metadata?: Record<string, unknown>\n children: ReactNode\n}\n\n/**\n * ScopeProvider creates a new request scope for dependency injection.\n *\n * Services with `scope: 'Request'` will be instantiated once per ScopeProvider\n * and shared among all components within that provider.\n *\n * This is useful for:\n * - Table rows that need isolated state\n * - Modal dialogs with their own service instances\n * - Multi-tenant scenarios\n * - Any case where you need isolated service instances\n *\n * @example\n * ```tsx\n * // Each row gets its own RowStateService instance\n * {rows.map(row => (\n * <ScopeProvider key={row.id} scopeId={row.id} metadata={{ rowData: row }}>\n * <TableRow />\n * </ScopeProvider>\n * ))}\n * ```\n */\nexport function ScopeProvider({\n scopeId,\n metadata,\n children,\n}: ScopeProviderProps) {\n const container = useContext(ContainerContext)\n if (!container) {\n throw new Error('ScopeProvider must be used within a ContainerProvider')\n }\n\n const generatedId = useId()\n const effectiveScopeId = scopeId ?? generatedId\n const scopedContainerRef = useRef<ScopedContainer | null>(null)\n\n // Create ScopedContainer on first render only\n // We use a ref to track initialization to handle React StrictMode double-renders\n if (!scopedContainerRef.current) {\n // Check if this request ID already exists (e.g., from StrictMode double render)\n if (!container.hasActiveRequest(effectiveScopeId)) {\n scopedContainerRef.current = container.beginRequest(\n effectiveScopeId,\n metadata,\n )\n }\n }\n\n // End request context on unmount\n useEffect(() => {\n const scopedContainer = scopedContainerRef.current\n return () => {\n if (scopedContainer) {\n void scopedContainer.endRequest()\n }\n }\n }, [])\n\n // If we don't have a scoped container (shouldn't happen normally), don't render\n if (!scopedContainerRef.current) {\n return null\n }\n\n return jsx(ScopedContainerContext.Provider, {\n value: scopedContainerRef.current,\n children,\n })\n}\n","import type { Container, ScopedContainer } from '@navios/di'\n\nimport { useContext } from 'react'\n\nimport {\n ContainerContext,\n ScopedContainerContext,\n} from '../providers/context.mjs'\n\n/**\n * Hook to get the current container (ScopedContainer if inside ScopeProvider, otherwise Container).\n *\n * This is the primary hook for accessing the DI container. It automatically\n * returns the correct container based on context:\n * - Inside a ScopeProvider: returns the ScopedContainer for request-scoped services\n * - Outside a ScopeProvider: returns the root Container\n *\n * @returns The current container (ScopedContainer or Container)\n */\nexport function useContainer(): Container | ScopedContainer {\n const scopedContainer = useContext(ScopedContainerContext)\n const container = useContext(ContainerContext)\n\n // Prefer scoped container if available (we're inside a ScopeProvider)\n if (scopedContainer) {\n return scopedContainer\n }\n\n if (!container) {\n throw new Error('useContainer must be used within a ContainerProvider')\n }\n\n return container\n}\n\n/**\n * Hook to get the root Container, regardless of whether we're inside a ScopeProvider.\n *\n * Use this when you need access to the root container specifically,\n * for example to create new request scopes programmatically.\n *\n * @returns The root Container\n */\nexport function useRootContainer(): Container {\n const container = useContext(ContainerContext)\n\n if (!container) {\n throw new Error('useRootContainer must be used within a ContainerProvider')\n }\n\n return container\n}\n\n/**\n * Hook to get the current ScopedContainer if inside a ScopeProvider.\n *\n * @returns The ScopedContainer or null if not inside a ScopeProvider\n */\nexport function useScopedContainer(): ScopedContainer | null {\n return useContext(ScopedContainerContext)\n}\n","import type {\n AnyInjectableType,\n BoundInjectionToken,\n ClassType,\n Factorable,\n FactoryInjectionToken,\n InjectionToken,\n InjectionTokenSchemaType,\n} from '@navios/di'\nimport type { z, ZodType } from 'zod/v4'\n\nimport { useCallback, useEffect, useReducer, useRef, useState } from 'react'\n\nimport type { Join, UnionToArray } from '../types.mjs'\n\nimport { useContainer, useRootContainer } from './use-container.mjs'\n\ntype ServiceState<T> =\n | { status: 'idle' }\n | { status: 'loading' }\n | { status: 'success'; data: T }\n | { status: 'error'; error: Error }\n\ntype ServiceAction<T> =\n | { type: 'loading' }\n | { type: 'success'; data: T }\n | { type: 'error'; error: Error }\n | { type: 'reset' }\n\nfunction serviceReducer<T>(\n state: ServiceState<T>,\n action: ServiceAction<T>,\n): ServiceState<T> {\n switch (action.type) {\n case 'loading':\n return { status: 'loading' }\n case 'success':\n return { status: 'success', data: action.data }\n case 'error':\n return { status: 'error', error: action.error }\n case 'reset':\n return { status: 'idle' }\n default:\n return state\n }\n}\n\nexport interface UseServiceResult<T> {\n data: T | undefined\n error: Error | undefined\n isLoading: boolean\n isSuccess: boolean\n isError: boolean\n refetch: () => void\n}\n\n// #1 Simple class\nexport function useService<T extends ClassType>(\n token: T,\n): UseServiceResult<\n InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>\n>\n\n// #2 Token with required Schema\nexport function useService<T, S extends InjectionTokenSchemaType>(\n token: InjectionToken<T, S>,\n args: z.input<S>,\n): UseServiceResult<T>\n\n// #3 Token with optional Schema\nexport function useService<\n T,\n S extends InjectionTokenSchemaType,\n R extends boolean,\n>(\n token: InjectionToken<T, S, R>,\n): R extends false\n ? UseServiceResult<T>\n : S extends ZodType<infer Type>\n ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}`\n : 'Error: Your token requires args'\n\n// #4 Token with no Schema\nexport function useService<T>(\n token: InjectionToken<T, undefined>,\n): UseServiceResult<T>\n\nexport function useService<T>(\n token: BoundInjectionToken<T, any>,\n): UseServiceResult<T>\n\nexport function useService<T>(\n token: FactoryInjectionToken<T, any>,\n): UseServiceResult<T>\n\nexport function useService(\n token:\n | ClassType\n | InjectionToken<any, any>\n | BoundInjectionToken<any, any>\n | FactoryInjectionToken<any, any>,\n args?: unknown,\n): UseServiceResult<any> {\n // useContainer returns ScopedContainer if inside ScopeProvider, otherwise Container\n // This automatically handles request-scoped services correctly\n const container = useContainer()\n const rootContainer = useRootContainer()\n\n // Try to get the instance synchronously first for better performance\n // This avoids the async loading state when the instance is already cached\n // We use a ref to track this so it doesn't cause effect re-runs\n const initialSyncInstanceRef = useRef<any>(undefined)\n const isFirstRenderRef = useRef(true)\n\n if (isFirstRenderRef.current) {\n initialSyncInstanceRef.current = container.tryGetSync(token, args)\n isFirstRenderRef.current = false\n }\n\n const initialState: ServiceState<any> = initialSyncInstanceRef.current\n ? { status: 'success', data: initialSyncInstanceRef.current }\n : { status: 'idle' }\n\n const [state, dispatch] = useReducer(serviceReducer, initialState)\n const instanceNameRef = useRef<string | null>(null)\n const [refetchCounter, setRefetchCounter] = useState(0)\n\n if (process.env.NODE_ENV === 'development') {\n const argsRef = useRef<unknown>(args)\n useEffect(() => {\n if (argsRef.current !== args) {\n if (JSON.stringify(argsRef.current) === JSON.stringify(args)) {\n console.warn(`useService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!\nThis is likely because you are using a value that is not memoized.\nPlease use a memoized value or use a different approach to pass the args.\nExample:\n const args = useMemo(() => ({ userId: '123' }), [])\n return useService(UserToken, args)`)\n }\n argsRef.current = args\n }\n }, [args])\n }\n\n // Subscribe to invalidation events\n useEffect(() => {\n const eventBus = rootContainer.getEventBus()\n let unsubscribe: (() => void) | undefined\n let isMounted = true\n\n // Fetch the service and set up subscription\n const fetchAndSubscribe = async () => {\n try {\n // The container (either ScopedContainer or Container) handles resolution correctly\n const instance = await container.get(\n // @ts-expect-error - token is valid\n token as AnyInjectableType,\n args as any,\n )\n\n if (!isMounted) return\n\n // Get instance name for event subscription\n const instanceName = container.calculateInstanceName(token, args)\n if (instanceName) {\n instanceNameRef.current = instanceName\n }\n\n dispatch({ type: 'success', data: instance })\n\n // Set up subscription after we have the instance\n if (instanceName) {\n unsubscribe = eventBus.on(instanceName, 'destroy', () => {\n // Re-fetch when the service is invalidated\n if (isMounted) {\n dispatch({ type: 'loading' })\n void fetchAndSubscribe()\n }\n })\n }\n } catch (error) {\n if (isMounted) {\n dispatch({ type: 'error', error: error as Error })\n }\n }\n }\n\n // If we already have a sync instance from initial render, just set up subscription\n // Otherwise, fetch async\n const syncInstance = initialSyncInstanceRef.current\n if (syncInstance && refetchCounter === 0) {\n const instanceName = container.calculateInstanceName(token, args)\n if (instanceName) {\n instanceNameRef.current = instanceName\n unsubscribe = eventBus.on(instanceName, 'destroy', () => {\n if (isMounted) {\n dispatch({ type: 'loading' })\n void fetchAndSubscribe()\n }\n })\n }\n } else {\n dispatch({ type: 'loading' })\n void fetchAndSubscribe()\n }\n\n return () => {\n isMounted = false\n unsubscribe?.()\n }\n }, [container, rootContainer, token, args, refetchCounter])\n\n const refetch = useCallback(() => {\n setRefetchCounter((c) => c + 1)\n }, [])\n\n return {\n data: state.status === 'success' ? state.data : undefined,\n error: state.status === 'error' ? state.error : undefined,\n isLoading: state.status === 'loading',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n refetch,\n }\n}\n","import type {\n BoundInjectionToken,\n ClassType,\n Container,\n Factorable,\n FactoryInjectionToken,\n InjectionToken,\n InjectionTokenSchemaType,\n} from '@navios/di'\nimport type { z, ZodType } from 'zod/v4'\n\n\nimport { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'\n\nimport type { Join, UnionToArray } from '../types.mjs'\n\nimport { useContainer, useRootContainer } from './use-container.mjs'\n\n// Cache entry for suspense\ninterface CacheEntry<T> {\n promise: Promise<T> | null\n result: T | undefined\n error: Error | undefined\n status: 'pending' | 'resolved' | 'rejected'\n version: number // Increment on each fetch to track changes\n subscribers: Set<() => void>\n instanceName: string | null\n unsubscribe: (() => void) | undefined\n}\n\n// Global cache for service instances (per container + token + args combination)\nconst cacheMap = new WeakMap<object, Map<string, CacheEntry<any>>>()\n\nfunction getCacheKey(token: any, args: unknown): string {\n const tokenId =\n typeof token === 'function'\n ? token.name\n : token.id || token.token?.id || String(token)\n return `${tokenId}:${JSON.stringify(args ?? null)}`\n}\n\nfunction getCache(container: object): Map<string, CacheEntry<any>> {\n let cache = cacheMap.get(container)\n if (!cache) {\n cache = new Map()\n cacheMap.set(container, cache)\n }\n return cache\n}\n\n/**\n * Sets up invalidation subscription for a cache entry if not already subscribed.\n * When the service is destroyed, clears the cache and notifies subscribers.\n */\nfunction setupInvalidationSubscription(\n entry: CacheEntry<any>,\n rootContainer: Container,\n): void {\n if (entry.unsubscribe || !entry.instanceName) return\n\n const eventBus = rootContainer.getEventBus()\n entry.unsubscribe = eventBus.on(entry.instanceName, 'destroy', () => {\n // Clear cache and notify subscribers to re-fetch\n entry.result = undefined\n entry.error = undefined\n entry.status = 'pending'\n entry.promise = null\n // Notify all subscribers\n entry.subscribers.forEach((callback) => callback())\n })\n}\n\n// #1 Simple class\nexport function useSuspenseService<T extends ClassType>(\n token: T,\n): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>\n\n// #2 Token with required Schema\nexport function useSuspenseService<T, S extends InjectionTokenSchemaType>(\n token: InjectionToken<T, S>,\n args: z.input<S>,\n): T\n\n// #3 Token with optional Schema\nexport function useSuspenseService<\n T,\n S extends InjectionTokenSchemaType,\n R extends boolean,\n>(\n token: InjectionToken<T, S, R>,\n): R extends false\n ? T\n : S extends ZodType<infer Type>\n ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}`\n : 'Error: Your token requires args'\n\n// #4 Token with no Schema\nexport function useSuspenseService<T>(token: InjectionToken<T, undefined>): T\n\nexport function useSuspenseService<T>(token: BoundInjectionToken<T, any>): T\n\nexport function useSuspenseService<T>(token: FactoryInjectionToken<T, any>): T\n\nexport function useSuspenseService(\n token:\n | ClassType\n | InjectionToken<any, any>\n | BoundInjectionToken<any, any>\n | FactoryInjectionToken<any, any>,\n args?: unknown,\n): any {\n // useContainer returns ScopedContainer if inside ScopeProvider, otherwise Container\n const container = useContainer()\n const rootContainer = useRootContainer()\n const cache = getCache(container)\n const cacheKey = getCacheKey(token, args)\n const entryRef = useRef<CacheEntry<any> | null>(null)\n if (process.env.NODE_ENV === 'development') {\n const argsRef = useRef<unknown>(args)\n useEffect(() => {\n if (argsRef.current !== args) {\n if (JSON.stringify(argsRef.current) === JSON.stringify(args)) {\n console.warn(`useSuspenseService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!\nThis is likely because you are using a value that is not memoized.\nPlease use a memoized value or use a different approach to pass the args.\nExample:\n const args = useMemo(() => ({ userId: '123' }), [])\n return useSuspenseService(UserToken, args)`)\n }\n argsRef.current = args\n }\n }, [args])\n }\n\n // Initialize or get cache entry\n if (!cache.has(cacheKey)) {\n // Try to get the instance synchronously first for better performance\n // This avoids suspense when the instance is already cached\n const syncInstance = container.tryGetSync(token, args)\n\n const instanceName = container.calculateInstanceName(token, args)\n const entry: CacheEntry<any> = {\n promise: null,\n result: syncInstance ?? undefined,\n error: undefined,\n status: syncInstance ? 'resolved' : 'pending',\n version: 0,\n subscribers: new Set(),\n instanceName,\n unsubscribe: undefined,\n }\n cache.set(cacheKey, entry)\n }\n\n const entry = cache.get(cacheKey)!\n entryRef.current = entry\n\n // Function to fetch the service\n const fetchService = useCallback(() => {\n const currentEntry = entryRef.current\n if (!currentEntry) return\n\n currentEntry.status = 'pending'\n currentEntry.version++ // Increment version to signal change to useSyncExternalStore\n currentEntry.promise = (container.get as any)(token, args)\n .then((instance: any) => {\n currentEntry.result = instance\n currentEntry.status = 'resolved'\n\n // Subscribe to invalidation events if not already subscribed\n setupInvalidationSubscription(currentEntry, rootContainer)\n\n // Notify subscribers\n currentEntry.subscribers.forEach((callback) => callback())\n return instance\n })\n .catch((error: Error) => {\n currentEntry.error = error\n currentEntry.status = 'rejected'\n throw error\n })\n\n return currentEntry.promise\n }, [container, rootContainer, token, args])\n\n // Subscribe to cache changes\n const subscribe = useCallback(\n (callback: () => void) => {\n entry.subscribers.add(callback)\n return () => {\n entry.subscribers.delete(callback)\n }\n },\n [entry],\n )\n\n // Get snapshot of current state - include version to detect invalidation\n const getSnapshot = useCallback(() => {\n return `${entry.status}:${entry.version}`\n }, [entry])\n\n // Use sync external store to track cache state\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n // Set up subscription for sync instances that don't have one yet\n useEffect(() => {\n const currentEntry = entryRef.current\n if (\n currentEntry &&\n currentEntry.status === 'resolved' &&\n currentEntry.instanceName &&\n !currentEntry.unsubscribe\n ) {\n setupInvalidationSubscription(currentEntry, rootContainer)\n }\n }, [rootContainer, entry])\n\n // Start fetching if not already\n if (entry.status === 'pending' && !entry.promise) {\n fetchService()\n }\n\n // Suspense behavior\n if (entry.status === 'pending') {\n throw entry.promise\n }\n\n if (entry.status === 'rejected') {\n throw entry.error\n }\n\n return entry.result\n}\n","import type {\n AnyInjectableType,\n BoundInjectionToken,\n ClassType,\n Factorable,\n FactoryInjectionToken,\n InjectionToken,\n InjectionTokenSchemaType,\n} from '@navios/di'\nimport type { z, ZodType } from 'zod/v4'\n\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\n\nimport type { Join, UnionToArray } from '../types.mjs'\n\nimport { useContainer, useRootContainer } from './use-container.mjs'\n\ntype OptionalServiceState<T> =\n | { status: 'idle' }\n | { status: 'loading' }\n | { status: 'success'; data: T }\n | { status: 'not-found' }\n | { status: 'error'; error: Error }\n\ntype OptionalServiceAction<T> =\n | { type: 'loading' }\n | { type: 'success'; data: T }\n | { type: 'not-found' }\n | { type: 'error'; error: Error }\n | { type: 'reset' }\n\nfunction optionalServiceReducer<T>(\n state: OptionalServiceState<T>,\n action: OptionalServiceAction<T>,\n): OptionalServiceState<T> {\n switch (action.type) {\n case 'loading':\n return { status: 'loading' }\n case 'success':\n return { status: 'success', data: action.data }\n case 'not-found':\n return { status: 'not-found' }\n case 'error':\n return { status: 'error', error: action.error }\n case 'reset':\n return { status: 'idle' }\n default:\n return state\n }\n}\n\nexport interface UseOptionalServiceResult<T> {\n /**\n * The service instance if found and loaded successfully, otherwise undefined.\n */\n data: T | undefined\n /**\n * Error that occurred during loading (excludes \"not found\" which is not an error).\n */\n error: Error | undefined\n /**\n * True while the service is being loaded.\n */\n isLoading: boolean\n /**\n * True if the service was loaded successfully.\n */\n isSuccess: boolean\n /**\n * True if the service was not found (not registered in the container).\n */\n isNotFound: boolean\n /**\n * True if an error occurred during loading.\n */\n isError: boolean\n /**\n * Function to manually re-fetch the service.\n */\n refetch: () => void\n}\n\n// #1 Simple class\nexport function useOptionalService<T extends ClassType>(\n token: T,\n): UseOptionalServiceResult<\n InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>\n>\n\n// #2 Token with required Schema\nexport function useOptionalService<T, S extends InjectionTokenSchemaType>(\n token: InjectionToken<T, S>,\n args: z.input<S>,\n): UseOptionalServiceResult<T>\n\n// #3 Token with optional Schema\nexport function useOptionalService<\n T,\n S extends InjectionTokenSchemaType,\n R extends boolean,\n>(\n token: InjectionToken<T, S, R>,\n): R extends false\n ? UseOptionalServiceResult<T>\n : S extends ZodType<infer Type>\n ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}`\n : 'Error: Your token requires args'\n\n// #4 Token with no Schema\nexport function useOptionalService<T>(\n token: InjectionToken<T, undefined>,\n): UseOptionalServiceResult<T>\n\nexport function useOptionalService<T>(\n token: BoundInjectionToken<T, any>,\n): UseOptionalServiceResult<T>\n\nexport function useOptionalService<T>(\n token: FactoryInjectionToken<T, any>,\n): UseOptionalServiceResult<T>\n\n/**\n * Hook to optionally load a service from the DI container.\n *\n * Unlike useService, this hook does NOT throw an error if the service is not registered.\n * Instead, it returns `isNotFound: true` when the service doesn't exist.\n *\n * This is useful for:\n * - Optional dependencies that may or may not be configured\n * - Feature flags where a service might not be available\n * - Plugins or extensions that are conditionally registered\n *\n * @example\n * ```tsx\n * function Analytics() {\n * const { data: analytics, isNotFound } = useOptionalService(AnalyticsService)\n *\n * if (isNotFound) {\n * // Analytics service not configured, skip tracking\n * return null\n * }\n *\n * return <AnalyticsTracker service={analytics} />\n * }\n * ```\n */\nexport function useOptionalService(\n token:\n | ClassType\n | InjectionToken<any, any>\n | BoundInjectionToken<any, any>\n | FactoryInjectionToken<any, any>,\n args?: unknown,\n): UseOptionalServiceResult<any> {\n // useContainer returns ScopedContainer if inside ScopeProvider, otherwise Container\n const container = useContainer()\n const rootContainer = useRootContainer()\n\n // Try to get the instance synchronously first for better performance\n // This avoids the async loading state when the instance is already cached\n // We use a ref to track this so it doesn't cause effect re-runs\n const initialSyncInstanceRef = useRef<any>(undefined)\n const isFirstRenderRef = useRef(true)\n\n if (isFirstRenderRef.current) {\n try {\n initialSyncInstanceRef.current = container.tryGetSync(token, args)\n } catch {\n // Service not registered, leave as undefined\n }\n isFirstRenderRef.current = false\n }\n\n const initialState: OptionalServiceState<any> = initialSyncInstanceRef.current\n ? { status: 'success', data: initialSyncInstanceRef.current }\n : { status: 'idle' }\n\n const [state, dispatch] = useReducer(optionalServiceReducer, initialState)\n const instanceNameRef = useRef<string | null>(null)\n\n if (process.env.NODE_ENV === 'development') {\n const argsRef = useRef<unknown>(args)\n useEffect(() => {\n if (argsRef.current !== args) {\n if (JSON.stringify(argsRef.current) === JSON.stringify(args)) {\n console.warn(`useOptionalService called with args that look the same but are different instances: ${JSON.stringify(argsRef.current)} !== ${JSON.stringify(args)}!\nThis is likely because you are using a value that is not memoized.\nPlease use a memoized value or use a different approach to pass the args.\nExample:\n const args = useMemo(() => ({ userId: '123' }), [])\n return useOptionalService(UserToken, args)`)\n }\n argsRef.current = args\n }\n }, [args])\n }\n\n const fetchService = useCallback(async () => {\n dispatch({ type: 'loading' })\n try {\n // Use the container (ScopedContainer or Container) for resolution\n const instance = await container.get(\n // @ts-expect-error - token is valid\n token as AnyInjectableType,\n args as any,\n )\n // Get instance name for event subscription\n const instanceName = container.calculateInstanceName(token, args)\n if (instanceName) {\n instanceNameRef.current = instanceName\n }\n dispatch({ type: 'success', data: instance })\n } catch (error) {\n // Caught exceptions are treated as errors\n const err = error as Error\n const errorMessage = err.message?.toLowerCase() ?? ''\n if (\n errorMessage.includes('not found') ||\n errorMessage.includes('not registered') ||\n errorMessage.includes('no provider')\n ) {\n dispatch({ type: 'not-found' })\n } else {\n dispatch({ type: 'error', error: err })\n }\n }\n }, [container, token, args])\n\n // Subscribe to invalidation events\n useEffect(() => {\n const eventBus = rootContainer.getEventBus()\n let unsubscribe: (() => void) | undefined\n\n // If we already have a sync instance from initial render, just set up subscription\n // Otherwise, fetch async\n const syncInstance = initialSyncInstanceRef.current\n if (syncInstance) {\n const instanceName = container.calculateInstanceName(token, args)\n if (instanceName) {\n instanceNameRef.current = instanceName\n unsubscribe = eventBus.on(instanceName, 'destroy', () => {\n // Re-fetch when the service is invalidated\n void fetchService()\n })\n }\n } else {\n void fetchService().then(() => {\n if (instanceNameRef.current) {\n unsubscribe = eventBus.on(instanceNameRef.current, 'destroy', () => {\n // Re-fetch when the service is invalidated\n void fetchService()\n })\n }\n })\n\n return () => {\n unsubscribe?.()\n }\n }\n\n return () => {\n unsubscribe?.()\n }\n }, [fetchService, rootContainer, token, args])\n\n return {\n data: state.status === 'success' ? state.data : undefined,\n error: state.status === 'error' ? state.error : undefined,\n isLoading: state.status === 'loading',\n isSuccess: state.status === 'success',\n isNotFound: state.status === 'not-found',\n isError: state.status === 'error',\n refetch: fetchService,\n }\n}\n","import { useCallback } from 'react'\n\nimport { useContainer } from './use-container.mjs'\n\n/**\n * Hook that returns a function to invalidate a service instance directly.\n *\n * This is useful when you have the service instance and want to invalidate it\n * without knowing its token.\n *\n * @example\n * ```tsx\n * function UserProfile() {\n * const { data: user } = useService(UserService)\n * const invalidateInstance = useInvalidateInstance()\n *\n * const handleRefresh = () => {\n * if (user) {\n * invalidateInstance(user)\n * }\n * }\n *\n * return (\n * <div>\n * <span>{user?.name}</span>\n * <button onClick={handleRefresh}>Refresh</button>\n * </div>\n * )\n * }\n * ```\n */\nexport function useInvalidateInstance(): (instance: unknown) => Promise<void> {\n const container = useContainer()\n\n return useCallback(\n async (instance: unknown) => {\n await container.invalidate(instance)\n },\n [container],\n )\n}\n","import type { ScopedContainer } from '@navios/di'\n\nimport { useContext } from 'react'\n\nimport { ScopedContainerContext } from '../providers/context.mjs'\n\n/**\n * Hook to get the current scope ID.\n * Returns null if not inside a ScopeProvider.\n */\nexport function useScope(): string | null {\n const scopedContainer = useContext(ScopedContainerContext)\n return scopedContainer?.getRequestId() ?? null\n}\n\n/**\n * Hook to get the current scope ID, throwing if not inside a ScopeProvider.\n * Use this when your component requires a scope to function correctly.\n */\nexport function useScopeOrThrow(): string {\n const scopeId = useScope()\n if (scopeId === null) {\n throw new Error(\n 'useScopeOrThrow must be used within a ScopeProvider. ' +\n 'Wrap your component tree with <ScopeProvider> to create a request scope.',\n )\n }\n return scopeId\n}\n\n/**\n * Hook to get the current ScopedContainer.\n * Returns null if not inside a ScopeProvider.\n *\n * Use this to access scope metadata or other ScopedContainer methods.\n *\n * @example\n * ```tsx\n * function TableRow() {\n * const scope = useScopedContainer()\n * const rowData = scope?.getMetadata('rowData')\n * // ...\n * }\n * ```\n */\nexport function useScopedContainer(): ScopedContainer | null {\n return useContext(ScopedContainerContext)\n}\n\n/**\n * Hook to get the current ScopedContainer, throwing if not inside a ScopeProvider.\n * Use this when your component requires a scope to function correctly.\n */\nexport function useScopedContainerOrThrow(): ScopedContainer {\n const scopedContainer = useScopedContainer()\n if (scopedContainer === null) {\n throw new Error(\n 'useScopedContainerOrThrow must be used within a ScopeProvider. ' +\n 'Wrap your component tree with <ScopeProvider> to create a request scope.',\n )\n }\n return scopedContainer\n}\n\n/**\n * Hook to get metadata from the current scope.\n * Returns undefined if not inside a ScopeProvider or if the key doesn't exist.\n *\n * @example\n * ```tsx\n * // In parent component:\n * <ScopeProvider metadata={{ userId: '123', theme: 'dark' }}>\n * <ChildComponent />\n * </ScopeProvider>\n *\n * // In child component:\n * function ChildComponent() {\n * const userId = useScopeMetadata<string>('userId')\n * const theme = useScopeMetadata<'light' | 'dark'>('theme')\n * // ...\n * }\n * ```\n */\nexport function useScopeMetadata<T = unknown>(key: string): T | undefined {\n const scopedContainer = useContext(ScopedContainerContext)\n return scopedContainer?.getMetadata(key) as T | undefined\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,4CAAmD,KAAK;;;;;AAMrE,MAAa,kDAA+D,KAAK;;;;ACFjF,SAAgB,kBAAkB,EAChC,WACA,YACyB;AACzB,mCAAW,iBAAiB,UAAU;EAAE,OAAO;EAAW;EAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AC4BvE,SAAgB,cAAc,EAC5B,SACA,UACA,YACqB;CACrB,MAAM,kCAAuB,iBAAiB;AAC9C,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,wDAAwD;CAG1E,MAAM,gCAAqB;CAC3B,MAAM,mBAAmB,W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