@navios/di-react 0.1.1 → 0.2.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/README.md +609 -28
- package/lib/index.d.mts +297 -18
- package/lib/index.d.mts.map +1 -0
- package/lib/index.d.ts +297 -18
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +536 -335
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +533 -334
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
- package/project.json +2 -2
- package/src/hooks/__tests__/use-service.spec.mts +1 -1
- package/src/hooks/index.mts +8 -2
- package/src/hooks/use-container.mts +47 -2
- package/src/hooks/use-invalidate.mts +3 -3
- package/src/hooks/use-optional-service.mts +59 -34
- package/src/hooks/use-scope.mts +66 -5
- package/src/hooks/use-service.mts +44 -18
- package/src/hooks/use-suspense-service.mts +48 -29
- package/src/providers/__tests__/scope-provider.spec.mts +84 -1
- package/src/providers/context.mts +11 -1
- package/src/providers/index.mts +2 -2
- package/src/providers/scope-provider.mts +34 -22
- package/{tsup.config.mts → tsdown.config.mts} +4 -3
- package/lib/_tsup-dts-rollup.d.mts +0 -304
- package/lib/_tsup-dts-rollup.d.ts +0 -304
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import type { BoundInjectionToken } from '@navios/di';
|
|
2
|
-
import type { ClassType } from '@navios/di';
|
|
3
|
-
import { Container } from '@navios/di';
|
|
4
|
-
import { Context } from 'react';
|
|
5
|
-
import type { Factorable } from '@navios/di';
|
|
6
|
-
import type { FactoryInjectionToken } from '@navios/di';
|
|
7
|
-
import type { InjectionToken } from '@navios/di';
|
|
8
|
-
import type { InjectionTokenSchemaType } from '@navios/di';
|
|
9
|
-
import { JSXElementConstructor } from 'react';
|
|
10
|
-
import { ReactElement } from 'react';
|
|
11
|
-
import type { ReactNode } from 'react';
|
|
12
|
-
import type { z } from 'zod/v4';
|
|
13
|
-
import type { ZodType } from 'zod/v4';
|
|
14
|
-
|
|
15
|
-
declare const ContainerContext: Context<Container | null>;
|
|
16
|
-
export { ContainerContext }
|
|
17
|
-
export { ContainerContext as ContainerContext_alias_1 }
|
|
18
|
-
export { ContainerContext as ContainerContext_alias_2 }
|
|
19
|
-
|
|
20
|
-
declare function ContainerProvider({ container, children, }: ContainerProviderProps): ReactElement<unknown, string | JSXElementConstructor<any>>;
|
|
21
|
-
export { ContainerProvider }
|
|
22
|
-
export { ContainerProvider as ContainerProvider_alias_1 }
|
|
23
|
-
export { ContainerProvider as ContainerProvider_alias_2 }
|
|
24
|
-
|
|
25
|
-
declare interface ContainerProviderProps {
|
|
26
|
-
container: Container;
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
}
|
|
29
|
-
export { ContainerProviderProps }
|
|
30
|
-
export { ContainerProviderProps as ContainerProviderProps_alias_1 }
|
|
31
|
-
export { ContainerProviderProps as ContainerProviderProps_alias_2 }
|
|
32
|
-
|
|
33
|
-
declare type InvalidatableToken = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
34
|
-
|
|
35
|
-
declare type Join<T extends any[], Delimiter extends string> = T extends [] ? '' : T extends [infer First extends string | number | symbol] ? First extends string | number ? `${First}` : never : T extends [
|
|
36
|
-
infer First extends string | number | symbol,
|
|
37
|
-
...infer Rest extends any[]
|
|
38
|
-
] ? First extends string | number ? `${First}${Delimiter}${Join<Rest, Delimiter>}` : never : '';
|
|
39
|
-
export { Join }
|
|
40
|
-
export { Join as Join_alias_1 }
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Context for the current scope ID.
|
|
44
|
-
* This allows nested components to access the current request scope.
|
|
45
|
-
*/
|
|
46
|
-
declare const ScopeContext: Context<string | null>;
|
|
47
|
-
export { ScopeContext }
|
|
48
|
-
export { ScopeContext as ScopeContext_alias_1 }
|
|
49
|
-
export { ScopeContext as ScopeContext_alias_2 }
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* ScopeProvider creates a new request scope for dependency injection.
|
|
53
|
-
*
|
|
54
|
-
* Services with `scope: 'Request'` will be instantiated once per ScopeProvider
|
|
55
|
-
* and shared among all components within that provider.
|
|
56
|
-
*
|
|
57
|
-
* This is useful for:
|
|
58
|
-
* - Table rows that need isolated state
|
|
59
|
-
* - Modal dialogs with their own service instances
|
|
60
|
-
* - Multi-tenant scenarios
|
|
61
|
-
* - Any case where you need isolated service instances
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```tsx
|
|
65
|
-
* // Each row gets its own RowStateService instance
|
|
66
|
-
* {rows.map(row => (
|
|
67
|
-
* <ScopeProvider key={row.id} scopeId={row.id}>
|
|
68
|
-
* <TableRow data={row} />
|
|
69
|
-
* </ScopeProvider>
|
|
70
|
-
* ))}
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function ScopeProvider({ scopeId, metadata, priority, children, }: ScopeProviderProps): ReactElement<unknown, string | JSXElementConstructor<any>>;
|
|
74
|
-
export { ScopeProvider }
|
|
75
|
-
export { ScopeProvider as ScopeProvider_alias_1 }
|
|
76
|
-
export { ScopeProvider as ScopeProvider_alias_2 }
|
|
77
|
-
|
|
78
|
-
declare interface ScopeProviderProps {
|
|
79
|
-
/**
|
|
80
|
-
* Optional explicit scope ID. If not provided, a unique ID will be generated.
|
|
81
|
-
* Useful when you need to reference the scope externally.
|
|
82
|
-
*/
|
|
83
|
-
scopeId?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Optional metadata to attach to the request context.
|
|
86
|
-
* Can be used to pass data like user info, request headers, etc.
|
|
87
|
-
*/
|
|
88
|
-
metadata?: Record<string, unknown>;
|
|
89
|
-
/**
|
|
90
|
-
* Priority for service resolution. Higher priority scopes take precedence.
|
|
91
|
-
* @default 100
|
|
92
|
-
*/
|
|
93
|
-
priority?: number;
|
|
94
|
-
children: ReactNode;
|
|
95
|
-
}
|
|
96
|
-
export { ScopeProviderProps }
|
|
97
|
-
export { ScopeProviderProps as ScopeProviderProps_alias_1 }
|
|
98
|
-
export { ScopeProviderProps as ScopeProviderProps_alias_2 }
|
|
99
|
-
|
|
100
|
-
declare type UnionToArray<T> = UnionToArrayImpl<T, never>;
|
|
101
|
-
export { UnionToArray }
|
|
102
|
-
export { UnionToArray as UnionToArray_alias_1 }
|
|
103
|
-
|
|
104
|
-
declare type UnionToArrayImpl<T, L extends any[]> = T extends any ? UnionToArrayImpl<Exclude<T, T>, [...L, T]> : L;
|
|
105
|
-
|
|
106
|
-
declare function useContainer(): Container;
|
|
107
|
-
export { useContainer }
|
|
108
|
-
export { useContainer as useContainer_alias_1 }
|
|
109
|
-
export { useContainer as useContainer_alias_2 }
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Hook that returns a function to invalidate a service by its token.
|
|
113
|
-
*
|
|
114
|
-
* When called, this will:
|
|
115
|
-
* 1. Destroy the current service instance
|
|
116
|
-
* 2. Trigger re-fetch in all components using useService/useSuspenseService for that token
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```tsx
|
|
120
|
-
* function UserProfile() {
|
|
121
|
-
* const { data: user } = useService(UserService)
|
|
122
|
-
* const invalidateUser = useInvalidate(UserService)
|
|
123
|
-
*
|
|
124
|
-
* const handleRefresh = () => {
|
|
125
|
-
* invalidateUser() // All components using UserService will re-fetch
|
|
126
|
-
* }
|
|
127
|
-
*
|
|
128
|
-
* return (
|
|
129
|
-
* <div>
|
|
130
|
-
* <span>{user?.name}</span>
|
|
131
|
-
* <button onClick={handleRefresh}>Refresh</button>
|
|
132
|
-
* </div>
|
|
133
|
-
* )
|
|
134
|
-
* }
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
declare function useInvalidate<T extends InvalidatableToken>(token: T): () => Promise<void>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Hook that returns a function to invalidate a service by its token with args.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```tsx
|
|
144
|
-
* function UserProfile({ userId }: { userId: string }) {
|
|
145
|
-
* const args = useMemo(() => ({ userId }), [userId])
|
|
146
|
-
* const { data: user } = useService(UserToken, args)
|
|
147
|
-
* const invalidateUser = useInvalidate(UserToken, args)
|
|
148
|
-
*
|
|
149
|
-
* return (
|
|
150
|
-
* <div>
|
|
151
|
-
* <span>{user?.name}</span>
|
|
152
|
-
* <button onClick={() => invalidateUser()}>Refresh</button>
|
|
153
|
-
* </div>
|
|
154
|
-
* )
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
declare function useInvalidate<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: S extends undefined ? never : unknown): () => Promise<void>;
|
|
159
|
-
export { useInvalidate }
|
|
160
|
-
export { useInvalidate as useInvalidate_alias_1 }
|
|
161
|
-
export { useInvalidate as useInvalidate_alias_2 }
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Hook that returns a function to invalidate a service instance directly.
|
|
165
|
-
*
|
|
166
|
-
* This is useful when you have the service instance and want to invalidate it
|
|
167
|
-
* without knowing its token.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```tsx
|
|
171
|
-
* function UserProfile() {
|
|
172
|
-
* const { data: user } = useService(UserService)
|
|
173
|
-
* const invalidateInstance = useInvalidateInstance()
|
|
174
|
-
*
|
|
175
|
-
* const handleRefresh = () => {
|
|
176
|
-
* if (user) {
|
|
177
|
-
* invalidateInstance(user)
|
|
178
|
-
* }
|
|
179
|
-
* }
|
|
180
|
-
*
|
|
181
|
-
* return (
|
|
182
|
-
* <div>
|
|
183
|
-
* <span>{user?.name}</span>
|
|
184
|
-
* <button onClick={handleRefresh}>Refresh</button>
|
|
185
|
-
* </div>
|
|
186
|
-
* )
|
|
187
|
-
* }
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
declare function useInvalidateInstance(): (instance: unknown) => Promise<void>;
|
|
191
|
-
export { useInvalidateInstance }
|
|
192
|
-
export { useInvalidateInstance as useInvalidateInstance_alias_1 }
|
|
193
|
-
export { useInvalidateInstance as useInvalidateInstance_alias_2 }
|
|
194
|
-
|
|
195
|
-
declare function useOptionalService<T extends ClassType>(token: T): UseOptionalServiceResult<InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>>;
|
|
196
|
-
|
|
197
|
-
declare function useOptionalService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): UseOptionalServiceResult<T>;
|
|
198
|
-
|
|
199
|
-
declare function useOptionalService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? UseOptionalServiceResult<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
200
|
-
|
|
201
|
-
declare function useOptionalService<T>(token: InjectionToken<T, undefined>): UseOptionalServiceResult<T>;
|
|
202
|
-
|
|
203
|
-
declare function useOptionalService<T>(token: BoundInjectionToken<T, any>): UseOptionalServiceResult<T>;
|
|
204
|
-
|
|
205
|
-
declare function useOptionalService<T>(token: FactoryInjectionToken<T, any>): UseOptionalServiceResult<T>;
|
|
206
|
-
export { useOptionalService }
|
|
207
|
-
export { useOptionalService as useOptionalService_alias_1 }
|
|
208
|
-
export { useOptionalService as useOptionalService_alias_2 }
|
|
209
|
-
|
|
210
|
-
declare interface UseOptionalServiceResult<T> {
|
|
211
|
-
/**
|
|
212
|
-
* The service instance if found and loaded successfully, otherwise undefined.
|
|
213
|
-
*/
|
|
214
|
-
data: T | undefined;
|
|
215
|
-
/**
|
|
216
|
-
* Error that occurred during loading (excludes "not found" which is not an error).
|
|
217
|
-
*/
|
|
218
|
-
error: Error | undefined;
|
|
219
|
-
/**
|
|
220
|
-
* True while the service is being loaded.
|
|
221
|
-
*/
|
|
222
|
-
isLoading: boolean;
|
|
223
|
-
/**
|
|
224
|
-
* True if the service was loaded successfully.
|
|
225
|
-
*/
|
|
226
|
-
isSuccess: boolean;
|
|
227
|
-
/**
|
|
228
|
-
* True if the service was not found (not registered in the container).
|
|
229
|
-
*/
|
|
230
|
-
isNotFound: boolean;
|
|
231
|
-
/**
|
|
232
|
-
* True if an error occurred during loading.
|
|
233
|
-
*/
|
|
234
|
-
isError: boolean;
|
|
235
|
-
/**
|
|
236
|
-
* Function to manually re-fetch the service.
|
|
237
|
-
*/
|
|
238
|
-
refetch: () => void;
|
|
239
|
-
}
|
|
240
|
-
export { UseOptionalServiceResult }
|
|
241
|
-
export { UseOptionalServiceResult as UseOptionalServiceResult_alias_1 }
|
|
242
|
-
export { UseOptionalServiceResult as UseOptionalServiceResult_alias_2 }
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Hook to get the current scope ID.
|
|
246
|
-
* Returns null if not inside a ScopeProvider.
|
|
247
|
-
*/
|
|
248
|
-
declare function useScope(): string | null;
|
|
249
|
-
export { useScope }
|
|
250
|
-
export { useScope as useScope_alias_1 }
|
|
251
|
-
export { useScope as useScope_alias_2 }
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Hook to get the current scope ID, throwing if not inside a ScopeProvider.
|
|
255
|
-
* Use this when your component requires a scope to function correctly.
|
|
256
|
-
*/
|
|
257
|
-
declare function useScopeOrThrow(): string;
|
|
258
|
-
export { useScopeOrThrow }
|
|
259
|
-
export { useScopeOrThrow as useScopeOrThrow_alias_1 }
|
|
260
|
-
export { useScopeOrThrow as useScopeOrThrow_alias_2 }
|
|
261
|
-
|
|
262
|
-
declare function useService<T extends ClassType>(token: T): UseServiceResult<InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>>;
|
|
263
|
-
|
|
264
|
-
declare function useService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): UseServiceResult<T>;
|
|
265
|
-
|
|
266
|
-
declare function useService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? UseServiceResult<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
267
|
-
|
|
268
|
-
declare function useService<T>(token: InjectionToken<T, undefined>): UseServiceResult<T>;
|
|
269
|
-
|
|
270
|
-
declare function useService<T>(token: BoundInjectionToken<T, any>): UseServiceResult<T>;
|
|
271
|
-
|
|
272
|
-
declare function useService<T>(token: FactoryInjectionToken<T, any>): UseServiceResult<T>;
|
|
273
|
-
export { useService }
|
|
274
|
-
export { useService as useService_alias_1 }
|
|
275
|
-
export { useService as useService_alias_2 }
|
|
276
|
-
|
|
277
|
-
declare interface UseServiceResult<T> {
|
|
278
|
-
data: T | undefined;
|
|
279
|
-
error: Error | undefined;
|
|
280
|
-
isLoading: boolean;
|
|
281
|
-
isSuccess: boolean;
|
|
282
|
-
isError: boolean;
|
|
283
|
-
refetch: () => void;
|
|
284
|
-
}
|
|
285
|
-
export { UseServiceResult }
|
|
286
|
-
export { UseServiceResult as UseServiceResult_alias_1 }
|
|
287
|
-
export { UseServiceResult as UseServiceResult_alias_2 }
|
|
288
|
-
|
|
289
|
-
declare function useSuspenseService<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
|
|
290
|
-
|
|
291
|
-
declare function useSuspenseService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
292
|
-
|
|
293
|
-
declare function useSuspenseService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? T : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
294
|
-
|
|
295
|
-
declare function useSuspenseService<T>(token: InjectionToken<T, undefined>): T;
|
|
296
|
-
|
|
297
|
-
declare function useSuspenseService<T>(token: BoundInjectionToken<T, any>): T;
|
|
298
|
-
|
|
299
|
-
declare function useSuspenseService<T>(token: FactoryInjectionToken<T, any>): T;
|
|
300
|
-
export { useSuspenseService }
|
|
301
|
-
export { useSuspenseService as useSuspenseService_alias_1 }
|
|
302
|
-
export { useSuspenseService as useSuspenseService_alias_2 }
|
|
303
|
-
|
|
304
|
-
export { }
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import type { BoundInjectionToken } from '@navios/di';
|
|
2
|
-
import type { ClassType } from '@navios/di';
|
|
3
|
-
import { Container } from '@navios/di';
|
|
4
|
-
import { Context } from 'react';
|
|
5
|
-
import type { Factorable } from '@navios/di';
|
|
6
|
-
import type { FactoryInjectionToken } from '@navios/di';
|
|
7
|
-
import type { InjectionToken } from '@navios/di';
|
|
8
|
-
import type { InjectionTokenSchemaType } from '@navios/di';
|
|
9
|
-
import { JSXElementConstructor } from 'react';
|
|
10
|
-
import { ReactElement } from 'react';
|
|
11
|
-
import type { ReactNode } from 'react';
|
|
12
|
-
import type { z } from 'zod/v4';
|
|
13
|
-
import type { ZodType } from 'zod/v4';
|
|
14
|
-
|
|
15
|
-
declare const ContainerContext: Context<Container | null>;
|
|
16
|
-
export { ContainerContext }
|
|
17
|
-
export { ContainerContext as ContainerContext_alias_1 }
|
|
18
|
-
export { ContainerContext as ContainerContext_alias_2 }
|
|
19
|
-
|
|
20
|
-
declare function ContainerProvider({ container, children, }: ContainerProviderProps): ReactElement<unknown, string | JSXElementConstructor<any>>;
|
|
21
|
-
export { ContainerProvider }
|
|
22
|
-
export { ContainerProvider as ContainerProvider_alias_1 }
|
|
23
|
-
export { ContainerProvider as ContainerProvider_alias_2 }
|
|
24
|
-
|
|
25
|
-
declare interface ContainerProviderProps {
|
|
26
|
-
container: Container;
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
}
|
|
29
|
-
export { ContainerProviderProps }
|
|
30
|
-
export { ContainerProviderProps as ContainerProviderProps_alias_1 }
|
|
31
|
-
export { ContainerProviderProps as ContainerProviderProps_alias_2 }
|
|
32
|
-
|
|
33
|
-
declare type InvalidatableToken = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
34
|
-
|
|
35
|
-
declare type Join<T extends any[], Delimiter extends string> = T extends [] ? '' : T extends [infer First extends string | number | symbol] ? First extends string | number ? `${First}` : never : T extends [
|
|
36
|
-
infer First extends string | number | symbol,
|
|
37
|
-
...infer Rest extends any[]
|
|
38
|
-
] ? First extends string | number ? `${First}${Delimiter}${Join<Rest, Delimiter>}` : never : '';
|
|
39
|
-
export { Join }
|
|
40
|
-
export { Join as Join_alias_1 }
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Context for the current scope ID.
|
|
44
|
-
* This allows nested components to access the current request scope.
|
|
45
|
-
*/
|
|
46
|
-
declare const ScopeContext: Context<string | null>;
|
|
47
|
-
export { ScopeContext }
|
|
48
|
-
export { ScopeContext as ScopeContext_alias_1 }
|
|
49
|
-
export { ScopeContext as ScopeContext_alias_2 }
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* ScopeProvider creates a new request scope for dependency injection.
|
|
53
|
-
*
|
|
54
|
-
* Services with `scope: 'Request'` will be instantiated once per ScopeProvider
|
|
55
|
-
* and shared among all components within that provider.
|
|
56
|
-
*
|
|
57
|
-
* This is useful for:
|
|
58
|
-
* - Table rows that need isolated state
|
|
59
|
-
* - Modal dialogs with their own service instances
|
|
60
|
-
* - Multi-tenant scenarios
|
|
61
|
-
* - Any case where you need isolated service instances
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```tsx
|
|
65
|
-
* // Each row gets its own RowStateService instance
|
|
66
|
-
* {rows.map(row => (
|
|
67
|
-
* <ScopeProvider key={row.id} scopeId={row.id}>
|
|
68
|
-
* <TableRow data={row} />
|
|
69
|
-
* </ScopeProvider>
|
|
70
|
-
* ))}
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function ScopeProvider({ scopeId, metadata, priority, children, }: ScopeProviderProps): ReactElement<unknown, string | JSXElementConstructor<any>>;
|
|
74
|
-
export { ScopeProvider }
|
|
75
|
-
export { ScopeProvider as ScopeProvider_alias_1 }
|
|
76
|
-
export { ScopeProvider as ScopeProvider_alias_2 }
|
|
77
|
-
|
|
78
|
-
declare interface ScopeProviderProps {
|
|
79
|
-
/**
|
|
80
|
-
* Optional explicit scope ID. If not provided, a unique ID will be generated.
|
|
81
|
-
* Useful when you need to reference the scope externally.
|
|
82
|
-
*/
|
|
83
|
-
scopeId?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Optional metadata to attach to the request context.
|
|
86
|
-
* Can be used to pass data like user info, request headers, etc.
|
|
87
|
-
*/
|
|
88
|
-
metadata?: Record<string, unknown>;
|
|
89
|
-
/**
|
|
90
|
-
* Priority for service resolution. Higher priority scopes take precedence.
|
|
91
|
-
* @default 100
|
|
92
|
-
*/
|
|
93
|
-
priority?: number;
|
|
94
|
-
children: ReactNode;
|
|
95
|
-
}
|
|
96
|
-
export { ScopeProviderProps }
|
|
97
|
-
export { ScopeProviderProps as ScopeProviderProps_alias_1 }
|
|
98
|
-
export { ScopeProviderProps as ScopeProviderProps_alias_2 }
|
|
99
|
-
|
|
100
|
-
declare type UnionToArray<T> = UnionToArrayImpl<T, never>;
|
|
101
|
-
export { UnionToArray }
|
|
102
|
-
export { UnionToArray as UnionToArray_alias_1 }
|
|
103
|
-
|
|
104
|
-
declare type UnionToArrayImpl<T, L extends any[]> = T extends any ? UnionToArrayImpl<Exclude<T, T>, [...L, T]> : L;
|
|
105
|
-
|
|
106
|
-
declare function useContainer(): Container;
|
|
107
|
-
export { useContainer }
|
|
108
|
-
export { useContainer as useContainer_alias_1 }
|
|
109
|
-
export { useContainer as useContainer_alias_2 }
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Hook that returns a function to invalidate a service by its token.
|
|
113
|
-
*
|
|
114
|
-
* When called, this will:
|
|
115
|
-
* 1. Destroy the current service instance
|
|
116
|
-
* 2. Trigger re-fetch in all components using useService/useSuspenseService for that token
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```tsx
|
|
120
|
-
* function UserProfile() {
|
|
121
|
-
* const { data: user } = useService(UserService)
|
|
122
|
-
* const invalidateUser = useInvalidate(UserService)
|
|
123
|
-
*
|
|
124
|
-
* const handleRefresh = () => {
|
|
125
|
-
* invalidateUser() // All components using UserService will re-fetch
|
|
126
|
-
* }
|
|
127
|
-
*
|
|
128
|
-
* return (
|
|
129
|
-
* <div>
|
|
130
|
-
* <span>{user?.name}</span>
|
|
131
|
-
* <button onClick={handleRefresh}>Refresh</button>
|
|
132
|
-
* </div>
|
|
133
|
-
* )
|
|
134
|
-
* }
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
declare function useInvalidate<T extends InvalidatableToken>(token: T): () => Promise<void>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Hook that returns a function to invalidate a service by its token with args.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```tsx
|
|
144
|
-
* function UserProfile({ userId }: { userId: string }) {
|
|
145
|
-
* const args = useMemo(() => ({ userId }), [userId])
|
|
146
|
-
* const { data: user } = useService(UserToken, args)
|
|
147
|
-
* const invalidateUser = useInvalidate(UserToken, args)
|
|
148
|
-
*
|
|
149
|
-
* return (
|
|
150
|
-
* <div>
|
|
151
|
-
* <span>{user?.name}</span>
|
|
152
|
-
* <button onClick={() => invalidateUser()}>Refresh</button>
|
|
153
|
-
* </div>
|
|
154
|
-
* )
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
declare function useInvalidate<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: S extends undefined ? never : unknown): () => Promise<void>;
|
|
159
|
-
export { useInvalidate }
|
|
160
|
-
export { useInvalidate as useInvalidate_alias_1 }
|
|
161
|
-
export { useInvalidate as useInvalidate_alias_2 }
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Hook that returns a function to invalidate a service instance directly.
|
|
165
|
-
*
|
|
166
|
-
* This is useful when you have the service instance and want to invalidate it
|
|
167
|
-
* without knowing its token.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```tsx
|
|
171
|
-
* function UserProfile() {
|
|
172
|
-
* const { data: user } = useService(UserService)
|
|
173
|
-
* const invalidateInstance = useInvalidateInstance()
|
|
174
|
-
*
|
|
175
|
-
* const handleRefresh = () => {
|
|
176
|
-
* if (user) {
|
|
177
|
-
* invalidateInstance(user)
|
|
178
|
-
* }
|
|
179
|
-
* }
|
|
180
|
-
*
|
|
181
|
-
* return (
|
|
182
|
-
* <div>
|
|
183
|
-
* <span>{user?.name}</span>
|
|
184
|
-
* <button onClick={handleRefresh}>Refresh</button>
|
|
185
|
-
* </div>
|
|
186
|
-
* )
|
|
187
|
-
* }
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
declare function useInvalidateInstance(): (instance: unknown) => Promise<void>;
|
|
191
|
-
export { useInvalidateInstance }
|
|
192
|
-
export { useInvalidateInstance as useInvalidateInstance_alias_1 }
|
|
193
|
-
export { useInvalidateInstance as useInvalidateInstance_alias_2 }
|
|
194
|
-
|
|
195
|
-
declare function useOptionalService<T extends ClassType>(token: T): UseOptionalServiceResult<InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>>;
|
|
196
|
-
|
|
197
|
-
declare function useOptionalService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): UseOptionalServiceResult<T>;
|
|
198
|
-
|
|
199
|
-
declare function useOptionalService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? UseOptionalServiceResult<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
200
|
-
|
|
201
|
-
declare function useOptionalService<T>(token: InjectionToken<T, undefined>): UseOptionalServiceResult<T>;
|
|
202
|
-
|
|
203
|
-
declare function useOptionalService<T>(token: BoundInjectionToken<T, any>): UseOptionalServiceResult<T>;
|
|
204
|
-
|
|
205
|
-
declare function useOptionalService<T>(token: FactoryInjectionToken<T, any>): UseOptionalServiceResult<T>;
|
|
206
|
-
export { useOptionalService }
|
|
207
|
-
export { useOptionalService as useOptionalService_alias_1 }
|
|
208
|
-
export { useOptionalService as useOptionalService_alias_2 }
|
|
209
|
-
|
|
210
|
-
declare interface UseOptionalServiceResult<T> {
|
|
211
|
-
/**
|
|
212
|
-
* The service instance if found and loaded successfully, otherwise undefined.
|
|
213
|
-
*/
|
|
214
|
-
data: T | undefined;
|
|
215
|
-
/**
|
|
216
|
-
* Error that occurred during loading (excludes "not found" which is not an error).
|
|
217
|
-
*/
|
|
218
|
-
error: Error | undefined;
|
|
219
|
-
/**
|
|
220
|
-
* True while the service is being loaded.
|
|
221
|
-
*/
|
|
222
|
-
isLoading: boolean;
|
|
223
|
-
/**
|
|
224
|
-
* True if the service was loaded successfully.
|
|
225
|
-
*/
|
|
226
|
-
isSuccess: boolean;
|
|
227
|
-
/**
|
|
228
|
-
* True if the service was not found (not registered in the container).
|
|
229
|
-
*/
|
|
230
|
-
isNotFound: boolean;
|
|
231
|
-
/**
|
|
232
|
-
* True if an error occurred during loading.
|
|
233
|
-
*/
|
|
234
|
-
isError: boolean;
|
|
235
|
-
/**
|
|
236
|
-
* Function to manually re-fetch the service.
|
|
237
|
-
*/
|
|
238
|
-
refetch: () => void;
|
|
239
|
-
}
|
|
240
|
-
export { UseOptionalServiceResult }
|
|
241
|
-
export { UseOptionalServiceResult as UseOptionalServiceResult_alias_1 }
|
|
242
|
-
export { UseOptionalServiceResult as UseOptionalServiceResult_alias_2 }
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Hook to get the current scope ID.
|
|
246
|
-
* Returns null if not inside a ScopeProvider.
|
|
247
|
-
*/
|
|
248
|
-
declare function useScope(): string | null;
|
|
249
|
-
export { useScope }
|
|
250
|
-
export { useScope as useScope_alias_1 }
|
|
251
|
-
export { useScope as useScope_alias_2 }
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Hook to get the current scope ID, throwing if not inside a ScopeProvider.
|
|
255
|
-
* Use this when your component requires a scope to function correctly.
|
|
256
|
-
*/
|
|
257
|
-
declare function useScopeOrThrow(): string;
|
|
258
|
-
export { useScopeOrThrow }
|
|
259
|
-
export { useScopeOrThrow as useScopeOrThrow_alias_1 }
|
|
260
|
-
export { useScopeOrThrow as useScopeOrThrow_alias_2 }
|
|
261
|
-
|
|
262
|
-
declare function useService<T extends ClassType>(token: T): UseServiceResult<InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>>;
|
|
263
|
-
|
|
264
|
-
declare function useService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): UseServiceResult<T>;
|
|
265
|
-
|
|
266
|
-
declare function useService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? UseServiceResult<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
267
|
-
|
|
268
|
-
declare function useService<T>(token: InjectionToken<T, undefined>): UseServiceResult<T>;
|
|
269
|
-
|
|
270
|
-
declare function useService<T>(token: BoundInjectionToken<T, any>): UseServiceResult<T>;
|
|
271
|
-
|
|
272
|
-
declare function useService<T>(token: FactoryInjectionToken<T, any>): UseServiceResult<T>;
|
|
273
|
-
export { useService }
|
|
274
|
-
export { useService as useService_alias_1 }
|
|
275
|
-
export { useService as useService_alias_2 }
|
|
276
|
-
|
|
277
|
-
declare interface UseServiceResult<T> {
|
|
278
|
-
data: T | undefined;
|
|
279
|
-
error: Error | undefined;
|
|
280
|
-
isLoading: boolean;
|
|
281
|
-
isSuccess: boolean;
|
|
282
|
-
isError: boolean;
|
|
283
|
-
refetch: () => void;
|
|
284
|
-
}
|
|
285
|
-
export { UseServiceResult }
|
|
286
|
-
export { UseServiceResult as UseServiceResult_alias_1 }
|
|
287
|
-
export { UseServiceResult as UseServiceResult_alias_2 }
|
|
288
|
-
|
|
289
|
-
declare function useSuspenseService<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
|
|
290
|
-
|
|
291
|
-
declare function useSuspenseService<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
292
|
-
|
|
293
|
-
declare function useSuspenseService<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? T : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
294
|
-
|
|
295
|
-
declare function useSuspenseService<T>(token: InjectionToken<T, undefined>): T;
|
|
296
|
-
|
|
297
|
-
declare function useSuspenseService<T>(token: BoundInjectionToken<T, any>): T;
|
|
298
|
-
|
|
299
|
-
declare function useSuspenseService<T>(token: FactoryInjectionToken<T, any>): T;
|
|
300
|
-
export { useSuspenseService }
|
|
301
|
-
export { useSuspenseService as useSuspenseService_alias_1 }
|
|
302
|
-
export { useSuspenseService as useSuspenseService_alias_2 }
|
|
303
|
-
|
|
304
|
-
export { }
|