@navios/di-react 0.1.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/LICENSE +7 -0
- package/README.md +176 -0
- package/lib/_tsup-dts-rollup.d.mts +304 -0
- package/lib/_tsup-dts-rollup.d.ts +304 -0
- package/lib/index.d.mts +18 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +405 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +392 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +44 -0
- package/project.json +61 -0
- package/src/hooks/__tests__/use-container.spec.mts +52 -0
- package/src/hooks/__tests__/use-invalidate.spec.mts +216 -0
- package/src/hooks/__tests__/use-optional-service.spec.mts +233 -0
- package/src/hooks/__tests__/use-service.spec.mts +212 -0
- package/src/hooks/__tests__/use-suspense-service.spec.mts +286 -0
- package/src/hooks/index.mts +8 -0
- package/src/hooks/use-container.mts +13 -0
- package/src/hooks/use-invalidate.mts +122 -0
- package/src/hooks/use-optional-service.mts +259 -0
- package/src/hooks/use-scope.mts +26 -0
- package/src/hooks/use-service.mts +201 -0
- package/src/hooks/use-suspense-service.mts +222 -0
- package/src/index.mts +8 -0
- package/src/providers/__tests__/scope-provider.spec.mts +280 -0
- package/src/providers/container-provider.mts +22 -0
- package/src/providers/context.mts +5 -0
- package/src/providers/index.mts +5 -0
- package/src/providers/scope-provider.mts +88 -0
- package/src/types.mts +21 -0
- package/tsconfig.json +13 -0
- package/tsup.config.mts +13 -0
- package/vitest.config.mts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Oleksandr Hanzha
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# @navios/di-react
|
|
2
|
+
|
|
3
|
+
React integration for `@navios/di` dependency injection container.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @navios/di-react @navios/di react
|
|
9
|
+
# or
|
|
10
|
+
yarn add @navios/di-react @navios/di react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Setting up the Provider
|
|
16
|
+
|
|
17
|
+
Wrap your application with `ContainerProvider` and pass a `Container` instance:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { Container } from '@navios/di'
|
|
21
|
+
import { ContainerProvider } from '@navios/di-react'
|
|
22
|
+
|
|
23
|
+
const container = new Container()
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<ContainerProvider container={container}>
|
|
28
|
+
<YourApp />
|
|
29
|
+
</ContainerProvider>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### useContainer
|
|
35
|
+
|
|
36
|
+
Access the container directly:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { useContainer } from '@navios/di-react'
|
|
40
|
+
|
|
41
|
+
function MyComponent() {
|
|
42
|
+
const container = useContainer()
|
|
43
|
+
|
|
44
|
+
// Use container methods directly
|
|
45
|
+
const handleClick = async () => {
|
|
46
|
+
const service = await container.get(MyService)
|
|
47
|
+
service.doSomething()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return <button onClick={handleClick}>Do Something</button>
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### useService
|
|
55
|
+
|
|
56
|
+
Fetch a service with loading/error states. Automatically re-fetches when the service is invalidated:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { useService } from '@navios/di-react'
|
|
60
|
+
import { MyService } from './services/my-service'
|
|
61
|
+
|
|
62
|
+
function MyComponent() {
|
|
63
|
+
const { data, isLoading, isError, error, refetch } = useService(MyService)
|
|
64
|
+
|
|
65
|
+
if (isLoading) return <div>Loading...</div>
|
|
66
|
+
if (isError) return <div>Error: {error?.message}</div>
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<p>{data.someValue}</p>
|
|
71
|
+
<button onClick={refetch}>Refresh</button>
|
|
72
|
+
</div>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
With injection tokens and arguments:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { InjectionToken } from '@navios/di'
|
|
81
|
+
import { useService } from '@navios/di-react'
|
|
82
|
+
import { z } from 'zod'
|
|
83
|
+
|
|
84
|
+
const UserToken = InjectionToken.create<User, typeof UserSchema>(
|
|
85
|
+
'User',
|
|
86
|
+
z.object({ userId: z.string() })
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
function UserProfile({ userId }: { userId: string }) {
|
|
90
|
+
const { data: user, isLoading } = useService(UserToken, { userId })
|
|
91
|
+
|
|
92
|
+
if (isLoading) return <div>Loading...</div>
|
|
93
|
+
|
|
94
|
+
return <div>{user.name}</div>
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### useSuspenseService
|
|
99
|
+
|
|
100
|
+
Use with React Suspense for a cleaner loading experience. Also subscribes to service invalidation:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import { Suspense } from 'react'
|
|
104
|
+
import { useSuspenseService } from '@navios/di-react'
|
|
105
|
+
import { MyService } from './services/my-service'
|
|
106
|
+
|
|
107
|
+
function MyComponent() {
|
|
108
|
+
const service = useSuspenseService(MyService)
|
|
109
|
+
|
|
110
|
+
return <div>{service.someValue}</div>
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function App() {
|
|
114
|
+
return (
|
|
115
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
116
|
+
<MyComponent />
|
|
117
|
+
</Suspense>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## API Reference
|
|
123
|
+
|
|
124
|
+
### ContainerProvider
|
|
125
|
+
|
|
126
|
+
| Prop | Type | Description |
|
|
127
|
+
|------|------|-------------|
|
|
128
|
+
| `container` | `Container` | The DI container instance |
|
|
129
|
+
| `children` | `ReactNode` | Child components |
|
|
130
|
+
|
|
131
|
+
### useContainer
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
function useContainer(): Container
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Returns the container from context. Throws if used outside of `ContainerProvider`.
|
|
138
|
+
|
|
139
|
+
### useService
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
function useService<T>(token: ClassType | InjectionToken<T>, args?: unknown): UseServiceResult<T>
|
|
143
|
+
|
|
144
|
+
interface UseServiceResult<T> {
|
|
145
|
+
data: T | undefined
|
|
146
|
+
error: Error | undefined
|
|
147
|
+
isLoading: boolean
|
|
148
|
+
isSuccess: boolean
|
|
149
|
+
isError: boolean
|
|
150
|
+
refetch: () => void
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Fetches a service asynchronously and subscribes to invalidation events. When the service is invalidated, it automatically re-fetches.
|
|
155
|
+
|
|
156
|
+
### useSuspenseService
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
function useSuspenseService<T>(token: ClassType | InjectionToken<T>, args?: unknown): T
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Fetches a service using React Suspense. Throws a promise during loading and the resolved value on success. Subscribes to invalidation events and triggers re-render when the service is invalidated.
|
|
163
|
+
|
|
164
|
+
## Service Invalidation
|
|
165
|
+
|
|
166
|
+
Both `useService` and `useSuspenseService` subscribe to the service's invalidation events via the DI container's event bus. When a service is invalidated (e.g., via `container.invalidate(service)`), the hooks will automatically:
|
|
167
|
+
|
|
168
|
+
1. Clear the cached instance
|
|
169
|
+
2. Re-fetch the service
|
|
170
|
+
3. Update the component with the new instance
|
|
171
|
+
|
|
172
|
+
This enables reactive updates when services change.
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT
|
|
@@ -0,0 +1,304 @@
|
|
|
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 { FunctionComponentElement } from 'react';
|
|
8
|
+
import type { InjectionToken } from '@navios/di';
|
|
9
|
+
import type { InjectionTokenSchemaType } from '@navios/di';
|
|
10
|
+
import { ProviderProps } 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): FunctionComponentElement<ProviderProps<Container | null>>;
|
|
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): FunctionComponentElement<ProviderProps<string | null>>;
|
|
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 { }
|