@navios/react-query 0.7.0 → 1.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 +166 -0
- package/README.md +152 -4
- package/dist/src/__tests__/errorSchema.spec.d.mts +2 -0
- package/dist/src/__tests__/errorSchema.spec.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/mutation.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/mutation.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/query.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/query.spec-d.d.mts.map +1 -0
- package/dist/src/client/declare-client.d.mts +15 -8
- package/dist/src/client/declare-client.d.mts.map +1 -1
- package/dist/src/client/types/from-endpoint.d.mts +130 -0
- package/dist/src/client/types/from-endpoint.d.mts.map +1 -0
- package/dist/src/client/types/helpers.d.mts +74 -0
- package/dist/src/client/types/helpers.d.mts.map +1 -0
- package/dist/src/client/types/index.d.mts +21 -0
- package/dist/src/client/types/index.d.mts.map +1 -0
- package/dist/src/client/types/infinite-query.d.mts +61 -0
- package/dist/src/client/types/infinite-query.d.mts.map +1 -0
- package/dist/src/client/types/multipart-mutation.d.mts +98 -0
- package/dist/src/client/types/multipart-mutation.d.mts.map +1 -0
- package/dist/src/client/types/mutation.d.mts +75 -0
- package/dist/src/client/types/mutation.d.mts.map +1 -0
- package/dist/src/client/types/query.d.mts +65 -0
- package/dist/src/client/types/query.d.mts.map +1 -0
- package/dist/src/client/types.d.mts +1 -608
- package/dist/src/client/types.d.mts.map +1 -1
- package/dist/src/common/types.d.mts +30 -3
- package/dist/src/common/types.d.mts.map +1 -1
- package/dist/src/mutation/index.d.mts +1 -0
- package/dist/src/mutation/index.d.mts.map +1 -1
- package/dist/src/mutation/make-hook.d.mts +42 -16
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/src/mutation/optimistic.d.mts +166 -0
- package/dist/src/mutation/optimistic.d.mts.map +1 -0
- package/dist/src/mutation/types.d.mts +51 -19
- package/dist/src/mutation/types.d.mts.map +1 -1
- package/dist/src/query/index.d.mts +1 -0
- package/dist/src/query/index.d.mts.map +1 -1
- package/dist/src/query/key-creator.d.mts.map +1 -1
- package/dist/src/query/make-infinite-options.d.mts +3 -2
- package/dist/src/query/make-infinite-options.d.mts.map +1 -1
- package/dist/src/query/make-options.d.mts +42 -12
- package/dist/src/query/make-options.d.mts.map +1 -1
- package/dist/src/query/prefetch.d.mts +245 -0
- package/dist/src/query/prefetch.d.mts.map +1 -0
- package/dist/src/query/types.d.mts +35 -17
- package/dist/src/query/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/index.cjs +454 -37
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1021 -598
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +1019 -596
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +441 -29
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/declare-client.spec.mts +1 -2
- package/src/__tests__/errorSchema.spec.mts +391 -0
- package/src/__tests__/make-mutation.spec.mts +6 -5
- package/src/__tests__/makeDataTag.spec.mts +2 -1
- package/src/__tests__/makeQueryOptions.spec.mts +2 -1
- package/src/client/__type-tests__/from-endpoint.spec-d.mts +550 -0
- package/src/client/__type-tests__/infinite-query.spec-d.mts +648 -0
- package/src/client/__type-tests__/multipart-mutation.spec-d.mts +725 -0
- package/src/client/__type-tests__/mutation.spec-d.mts +757 -0
- package/src/client/__type-tests__/query.spec-d.mts +701 -0
- package/src/client/declare-client.mts +59 -34
- package/src/client/types/from-endpoint.mts +345 -0
- package/src/client/types/helpers.mts +140 -0
- package/src/client/types/index.mts +26 -0
- package/src/client/types/infinite-query.mts +133 -0
- package/src/client/types/multipart-mutation.mts +264 -0
- package/src/client/types/mutation.mts +176 -0
- package/src/client/types/query.mts +132 -0
- package/src/client/types.mts +1 -1935
- package/src/common/types.mts +48 -3
- package/src/mutation/index.mts +1 -0
- package/src/mutation/make-hook.mts +171 -63
- package/src/mutation/optimistic.mts +294 -0
- package/src/mutation/types.mts +102 -29
- package/src/query/index.mts +1 -0
- package/src/query/key-creator.mts +24 -13
- package/src/query/make-infinite-options.mts +53 -10
- package/src/query/make-options.mts +184 -43
- package/src/query/prefetch.mts +326 -0
- package/src/query/types.mts +76 -16
- package/dist/src/declare-client.d.mts +0 -31
- package/dist/src/declare-client.d.mts.map +0 -1
- package/dist/src/make-infinite-query-options.d.mts +0 -13
- package/dist/src/make-infinite-query-options.d.mts.map +0 -1
- package/dist/src/make-mutation.d.mts +0 -15
- package/dist/src/make-mutation.d.mts.map +0 -1
- package/dist/src/make-query-options.d.mts +0 -15
- package/dist/src/make-query-options.d.mts.map +0 -1
- package/dist/src/types/client-endpoint-helper.d.mts +0 -8
- package/dist/src/types/client-endpoint-helper.d.mts.map +0 -1
- package/dist/src/types/client-instance.d.mts +0 -211
- package/dist/src/types/client-instance.d.mts.map +0 -1
- package/dist/src/types/index.d.mts +0 -8
- package/dist/src/types/index.d.mts.map +0 -1
- package/dist/src/types/mutation-args.d.mts +0 -10
- package/dist/src/types/mutation-args.d.mts.map +0 -1
- package/dist/src/types/mutation-helpers.d.mts +0 -10
- package/dist/src/types/mutation-helpers.d.mts.map +0 -1
- package/dist/src/types/query-args.d.mts +0 -8
- package/dist/src/types/query-args.d.mts.map +0 -1
- package/dist/src/types/query-helpers.d.mts +0 -14
- package/dist/src/types/query-helpers.d.mts.map +0 -1
- package/dist/src/types/query-url-params-args.d.mts +0 -5
- package/dist/src/types/query-url-params-args.d.mts.map +0 -1
- package/dist/src/types.d.mts +0 -49
- package/dist/src/types.d.mts.map +0 -1
- package/dist/src/utils/mutation-key.creator.d.mts +0 -39
- package/dist/src/utils/mutation-key.creator.d.mts.map +0 -1
- package/dist/src/utils/query-key-creator.d.mts +0 -24
- package/dist/src/utils/query-key-creator.d.mts.map +0 -1
- package/src/client/__type-tests__/client-instance.spec-d.mts +0 -852
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FetchQueryOptions,
|
|
3
|
+
QueryClient,
|
|
4
|
+
QueryKey,
|
|
5
|
+
} from '@tanstack/react-query'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type for a query options creator function that returns TanStack Query options.
|
|
9
|
+
*
|
|
10
|
+
* This matches the return type of `client.query()` from the navios react-query client.
|
|
11
|
+
*/
|
|
12
|
+
export type QueryOptionsCreator<TParams, TData, TError = Error> = (
|
|
13
|
+
params: TParams,
|
|
14
|
+
) => FetchQueryOptions<TData, TError, TData, QueryKey>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper utilities for prefetching queries.
|
|
18
|
+
*
|
|
19
|
+
* @template TParams - The query parameters type
|
|
20
|
+
* @template TData - The query data type
|
|
21
|
+
* @template TError - The error type (defaults to Error)
|
|
22
|
+
*/
|
|
23
|
+
export interface PrefetchHelper<TParams, TData, TError = Error> {
|
|
24
|
+
/**
|
|
25
|
+
* Prefetch query data on the server.
|
|
26
|
+
*
|
|
27
|
+
* Use this in server components or getServerSideProps to
|
|
28
|
+
* prefetch data before rendering.
|
|
29
|
+
*
|
|
30
|
+
* @param queryClient - The QueryClient instance
|
|
31
|
+
* @param params - Parameters for the query
|
|
32
|
+
* @returns Promise that resolves when prefetch is complete
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* // In a Next.js Server Component
|
|
37
|
+
* const queryClient = new QueryClient()
|
|
38
|
+
* await prefetch.prefetch(queryClient, { urlParams: { userId: '1' } })
|
|
39
|
+
* return (
|
|
40
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
41
|
+
* <UserProfile userId="1" />
|
|
42
|
+
* </HydrationBoundary>
|
|
43
|
+
* )
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
prefetch: (queryClient: QueryClient, params: TParams) => Promise<void>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Ensure query data exists in cache. Fetches only if not cached.
|
|
50
|
+
*
|
|
51
|
+
* Returns the cached or fetched data.
|
|
52
|
+
*
|
|
53
|
+
* @param queryClient - The QueryClient instance
|
|
54
|
+
* @param params - Parameters for the query
|
|
55
|
+
* @returns Promise that resolves to the query data
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* // Ensure data exists before rendering
|
|
60
|
+
* const userData = await prefetch.ensureData(queryClient, {
|
|
61
|
+
* urlParams: { userId: '1' },
|
|
62
|
+
* })
|
|
63
|
+
* console.log('User:', userData.name)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
ensureData: (queryClient: QueryClient, params: TParams) => Promise<TData>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the query options for a given set of parameters.
|
|
70
|
+
*
|
|
71
|
+
* Useful for advanced use cases or when you need to
|
|
72
|
+
* customize the prefetch behavior.
|
|
73
|
+
*
|
|
74
|
+
* @param params - Parameters for the query
|
|
75
|
+
* @returns The query options object
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* const options = prefetch.getQueryOptions({ urlParams: { userId: '1' } })
|
|
80
|
+
* await queryClient.prefetchQuery({
|
|
81
|
+
* ...options,
|
|
82
|
+
* staleTime: 60000, // Override stale time for prefetch
|
|
83
|
+
* })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
getQueryOptions: (
|
|
87
|
+
params: TParams,
|
|
88
|
+
) => FetchQueryOptions<TData, TError, TData, QueryKey>
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Prefetch multiple queries in parallel.
|
|
92
|
+
*
|
|
93
|
+
* @param queryClient - The QueryClient instance
|
|
94
|
+
* @param paramsList - Array of parameters for multiple queries
|
|
95
|
+
* @returns Promise that resolves when all prefetches complete
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* // Prefetch multiple users in parallel
|
|
100
|
+
* await prefetch.prefetchMany(queryClient, [
|
|
101
|
+
* { urlParams: { userId: '1' } },
|
|
102
|
+
* { urlParams: { userId: '2' } },
|
|
103
|
+
* { urlParams: { userId: '3' } },
|
|
104
|
+
* ])
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
prefetchMany: (
|
|
108
|
+
queryClient: QueryClient,
|
|
109
|
+
paramsList: TParams[],
|
|
110
|
+
) => Promise<void>
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a type-safe prefetch helper for SSR/RSC.
|
|
115
|
+
*
|
|
116
|
+
* This utility wraps a query options creator to provide convenient
|
|
117
|
+
* methods for server-side data fetching and hydration.
|
|
118
|
+
*
|
|
119
|
+
* @param queryOptionsCreator - A function that creates query options (from client.query())
|
|
120
|
+
* @returns A prefetch helper object with prefetch, ensureData, and getQueryOptions methods
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```tsx
|
|
124
|
+
* // 1. Create your query
|
|
125
|
+
* const getUserQuery = client.query({
|
|
126
|
+
* method: 'GET',
|
|
127
|
+
* url: '/users/$userId',
|
|
128
|
+
* responseSchema: userSchema,
|
|
129
|
+
* })
|
|
130
|
+
*
|
|
131
|
+
* // 2. Create prefetch helper
|
|
132
|
+
* const userPrefetch = createPrefetchHelper(getUserQuery)
|
|
133
|
+
*
|
|
134
|
+
* // 3. Use in server component
|
|
135
|
+
* async function UserPage({ userId }: { userId: string }) {
|
|
136
|
+
* const queryClient = new QueryClient()
|
|
137
|
+
*
|
|
138
|
+
* await userPrefetch.prefetch(queryClient, {
|
|
139
|
+
* urlParams: { userId },
|
|
140
|
+
* })
|
|
141
|
+
*
|
|
142
|
+
* return (
|
|
143
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
144
|
+
* <UserProfile userId={userId} />
|
|
145
|
+
* </HydrationBoundary>
|
|
146
|
+
* )
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* // With Next.js App Router
|
|
153
|
+
* import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query'
|
|
154
|
+
* import { createPrefetchHelper } from '@navios/react-query'
|
|
155
|
+
*
|
|
156
|
+
* // Define queries
|
|
157
|
+
* const getPostsQuery = client.query({
|
|
158
|
+
* method: 'GET',
|
|
159
|
+
* url: '/posts',
|
|
160
|
+
* querySchema: z.object({ page: z.number() }),
|
|
161
|
+
* responseSchema: postsSchema,
|
|
162
|
+
* })
|
|
163
|
+
*
|
|
164
|
+
* const postsPrefetch = createPrefetchHelper(getPostsQuery)
|
|
165
|
+
*
|
|
166
|
+
* // Server Component
|
|
167
|
+
* export default async function PostsPage() {
|
|
168
|
+
* const queryClient = new QueryClient()
|
|
169
|
+
*
|
|
170
|
+
* await postsPrefetch.prefetch(queryClient, {
|
|
171
|
+
* params: { page: 1 },
|
|
172
|
+
* })
|
|
173
|
+
*
|
|
174
|
+
* return (
|
|
175
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
176
|
+
* <PostsList />
|
|
177
|
+
* </HydrationBoundary>
|
|
178
|
+
* )
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export function createPrefetchHelper<TParams, TData, TError = Error>(
|
|
183
|
+
queryOptionsCreator: QueryOptionsCreator<TParams, TData, TError>,
|
|
184
|
+
): PrefetchHelper<TParams, TData, TError> {
|
|
185
|
+
return {
|
|
186
|
+
prefetch: async (queryClient: QueryClient, params: TParams) => {
|
|
187
|
+
const options = queryOptionsCreator(params)
|
|
188
|
+
await queryClient.prefetchQuery(options)
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
ensureData: async (queryClient: QueryClient, params: TParams) => {
|
|
192
|
+
const options = queryOptionsCreator(params)
|
|
193
|
+
return queryClient.ensureQueryData(options)
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
getQueryOptions: (params: TParams) => {
|
|
197
|
+
return queryOptionsCreator(params)
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
prefetchMany: async (queryClient: QueryClient, paramsList: TParams[]) => {
|
|
201
|
+
await Promise.all(
|
|
202
|
+
paramsList.map((params) => {
|
|
203
|
+
const options = queryOptionsCreator(params)
|
|
204
|
+
return queryClient.prefetchQuery(options)
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates multiple prefetch helpers from a record of query options creators.
|
|
213
|
+
*
|
|
214
|
+
* Useful when you have multiple queries that need to be prefetched together.
|
|
215
|
+
*
|
|
216
|
+
* @param queries - Record of query options creator functions
|
|
217
|
+
* @returns Record of prefetch helpers with the same keys
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```tsx
|
|
221
|
+
* // Define all your queries
|
|
222
|
+
* const queries = {
|
|
223
|
+
* user: client.query({
|
|
224
|
+
* method: 'GET',
|
|
225
|
+
* url: '/users/$userId',
|
|
226
|
+
* responseSchema: userSchema,
|
|
227
|
+
* }),
|
|
228
|
+
* posts: client.query({
|
|
229
|
+
* method: 'GET',
|
|
230
|
+
* url: '/users/$userId/posts',
|
|
231
|
+
* responseSchema: postsSchema,
|
|
232
|
+
* }),
|
|
233
|
+
* }
|
|
234
|
+
*
|
|
235
|
+
* // Create all prefetch helpers at once
|
|
236
|
+
* const prefetchers = createPrefetchHelpers(queries)
|
|
237
|
+
*
|
|
238
|
+
* // Use in server component
|
|
239
|
+
* async function UserPage({ userId }: { userId: string }) {
|
|
240
|
+
* const queryClient = new QueryClient()
|
|
241
|
+
*
|
|
242
|
+
* await Promise.all([
|
|
243
|
+
* prefetchers.user.prefetch(queryClient, { urlParams: { userId } }),
|
|
244
|
+
* prefetchers.posts.prefetch(queryClient, { urlParams: { userId } }),
|
|
245
|
+
* ])
|
|
246
|
+
*
|
|
247
|
+
* return (
|
|
248
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
249
|
+
* <UserProfileWithPosts userId={userId} />
|
|
250
|
+
* </HydrationBoundary>
|
|
251
|
+
* )
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export function createPrefetchHelpers<
|
|
256
|
+
T extends Record<string, QueryOptionsCreator<any, any, any>>,
|
|
257
|
+
>(
|
|
258
|
+
queries: T,
|
|
259
|
+
): {
|
|
260
|
+
[K in keyof T]: T[K] extends QueryOptionsCreator<
|
|
261
|
+
infer TParams,
|
|
262
|
+
infer TData,
|
|
263
|
+
infer TError
|
|
264
|
+
>
|
|
265
|
+
? PrefetchHelper<TParams, TData, TError>
|
|
266
|
+
: never
|
|
267
|
+
} {
|
|
268
|
+
const result = {} as {
|
|
269
|
+
[K in keyof T]: T[K] extends QueryOptionsCreator<
|
|
270
|
+
infer TParams,
|
|
271
|
+
infer TData,
|
|
272
|
+
infer TError
|
|
273
|
+
>
|
|
274
|
+
? PrefetchHelper<TParams, TData, TError>
|
|
275
|
+
: never
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
for (const key of Object.keys(queries) as Array<keyof T>) {
|
|
279
|
+
// @ts-expect-error - TypeScript can't infer this properly
|
|
280
|
+
result[key] = createPrefetchHelper(queries[key])
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return result
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Prefetch multiple queries from different query creators in parallel.
|
|
288
|
+
*
|
|
289
|
+
* @param queryClient - The QueryClient instance
|
|
290
|
+
* @param prefetches - Array of { helper, params } objects
|
|
291
|
+
* @returns Promise that resolves when all prefetches complete
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```tsx
|
|
295
|
+
* const userPrefetch = createPrefetchHelper(getUserQuery)
|
|
296
|
+
* const postsPrefetch = createPrefetchHelper(getPostsQuery)
|
|
297
|
+
*
|
|
298
|
+
* async function DashboardPage({ userId }: { userId: string }) {
|
|
299
|
+
* const queryClient = new QueryClient()
|
|
300
|
+
*
|
|
301
|
+
* await prefetchAll(queryClient, [
|
|
302
|
+
* { helper: userPrefetch, params: { urlParams: { userId } } },
|
|
303
|
+
* { helper: postsPrefetch, params: { urlParams: { userId }, params: { limit: 10 } } },
|
|
304
|
+
* ])
|
|
305
|
+
*
|
|
306
|
+
* return (
|
|
307
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
308
|
+
* <Dashboard userId={userId} />
|
|
309
|
+
* </HydrationBoundary>
|
|
310
|
+
* )
|
|
311
|
+
* }
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
export async function prefetchAll(
|
|
315
|
+
queryClient: QueryClient,
|
|
316
|
+
prefetches: Array<{
|
|
317
|
+
helper: PrefetchHelper<any, any, any>
|
|
318
|
+
params: unknown
|
|
319
|
+
}>,
|
|
320
|
+
): Promise<void> {
|
|
321
|
+
await Promise.all(
|
|
322
|
+
prefetches.map(({ helper, params }) =>
|
|
323
|
+
helper.prefetch(queryClient, params),
|
|
324
|
+
),
|
|
325
|
+
)
|
|
326
|
+
}
|
package/src/query/types.mts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AnyEndpointConfig,
|
|
3
3
|
BaseEndpointConfig,
|
|
4
|
+
EndpointOptions,
|
|
5
|
+
ErrorSchemaRecord,
|
|
4
6
|
HttpMethod,
|
|
7
|
+
InferEndpointReturn,
|
|
8
|
+
InferErrorSchemaOutput,
|
|
9
|
+
RequestArgs,
|
|
10
|
+
Simplify,
|
|
5
11
|
UrlHasParams,
|
|
6
12
|
UrlParams,
|
|
7
|
-
Util_FlatObject,
|
|
8
13
|
} from '@navios/builder'
|
|
9
14
|
import type {
|
|
10
15
|
DataTag,
|
|
@@ -17,31 +22,76 @@ import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
|
17
22
|
|
|
18
23
|
import type { Split } from '../common/types.mjs'
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Compute the response input type based on discriminator and error schema.
|
|
27
|
+
* When UseDiscriminator=true and errorSchema is present, errors are included as a union.
|
|
28
|
+
* When UseDiscriminator=false, only the success type is returned (errors are thrown).
|
|
29
|
+
*
|
|
30
|
+
* @template UseDiscriminator - Whether to include error types in the response union
|
|
31
|
+
* @template ResponseSchema - The success response schema
|
|
32
|
+
* @template ErrorSchema - The error schema record (optional)
|
|
33
|
+
*/
|
|
34
|
+
type ComputeResponseInput<
|
|
35
|
+
UseDiscriminator extends boolean,
|
|
36
|
+
ResponseSchema extends ZodType,
|
|
37
|
+
ErrorSchema extends ErrorSchemaRecord | undefined,
|
|
38
|
+
> = UseDiscriminator extends true
|
|
39
|
+
? ErrorSchema extends ErrorSchemaRecord
|
|
40
|
+
? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema>
|
|
41
|
+
: z.output<ResponseSchema>
|
|
42
|
+
: z.output<ResponseSchema>
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Helper type to extract the result type from processResponse.
|
|
46
|
+
*/
|
|
47
|
+
export type QueryResult<
|
|
48
|
+
Options extends EndpointOptions,
|
|
49
|
+
UseDiscriminator extends boolean = false,
|
|
50
|
+
> = Options extends {
|
|
51
|
+
processResponse: (data: any) => infer Result
|
|
52
|
+
}
|
|
53
|
+
? Result
|
|
54
|
+
: InferEndpointReturn<Options, UseDiscriminator>
|
|
55
|
+
|
|
20
56
|
/**
|
|
21
57
|
* Arguments for query functions based on URL params and query schema.
|
|
58
|
+
* Uses RequestArgs from builder for consistency.
|
|
22
59
|
*/
|
|
23
60
|
export type QueryArgs<
|
|
24
61
|
Url extends string = string,
|
|
25
|
-
QuerySchema =
|
|
26
|
-
RequestSchema = undefined,
|
|
27
|
-
> =
|
|
28
|
-
(QuerySchema extends ZodObject ? { params: z.input<QuerySchema> } : {}) &
|
|
29
|
-
(RequestSchema extends ZodType ? { data: z.input<RequestSchema> } : {})
|
|
62
|
+
QuerySchema extends ZodObject | undefined = undefined,
|
|
63
|
+
RequestSchema extends ZodType | undefined = undefined,
|
|
64
|
+
> = RequestArgs<Url, QuerySchema, RequestSchema>
|
|
30
65
|
|
|
31
66
|
/**
|
|
32
67
|
* Arguments containing only URL params (for invalidateAll operations).
|
|
33
68
|
*/
|
|
34
69
|
export type QueryUrlParamsArgs<Url extends string = string> =
|
|
35
|
-
UrlHasParams<Url> extends true
|
|
70
|
+
UrlHasParams<Url> extends true
|
|
71
|
+
? { urlParams: UrlParams<Url> }
|
|
72
|
+
: {} | undefined
|
|
36
73
|
|
|
37
74
|
/**
|
|
38
75
|
* Base parameters for query configuration.
|
|
76
|
+
*
|
|
77
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
78
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
39
79
|
*/
|
|
40
|
-
export type QueryParams<
|
|
80
|
+
export type QueryParams<
|
|
81
|
+
Config extends AnyEndpointConfig,
|
|
82
|
+
Res = any,
|
|
83
|
+
UseDiscriminator extends boolean = false,
|
|
84
|
+
> = {
|
|
41
85
|
keyPrefix?: string[]
|
|
42
86
|
keySuffix?: string[]
|
|
43
87
|
onFail?: (err: unknown) => void
|
|
44
|
-
processResponse: (
|
|
88
|
+
processResponse: (
|
|
89
|
+
data: ComputeResponseInput<
|
|
90
|
+
UseDiscriminator,
|
|
91
|
+
Config['responseSchema'],
|
|
92
|
+
Config['errorSchema']
|
|
93
|
+
>,
|
|
94
|
+
) => Res
|
|
45
95
|
}
|
|
46
96
|
|
|
47
97
|
/**
|
|
@@ -88,31 +138,41 @@ export type QueryHelpers<
|
|
|
88
138
|
> = {
|
|
89
139
|
queryKey: QueryKeyCreatorResult<QuerySchema, Url, Result, IsInfinite>
|
|
90
140
|
use: (
|
|
91
|
-
params:
|
|
141
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
92
142
|
) => UseQueryResult<Result, Error>
|
|
93
143
|
useSuspense: (
|
|
94
|
-
params:
|
|
144
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
95
145
|
) => UseSuspenseQueryResult<Result, Error>
|
|
96
146
|
invalidate: (
|
|
97
147
|
queryClient: QueryClient,
|
|
98
|
-
params:
|
|
148
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
99
149
|
) => () => Promise<void>
|
|
100
150
|
invalidateAll: (
|
|
101
151
|
queryClient: QueryClient,
|
|
102
|
-
params:
|
|
152
|
+
params: Simplify<QueryUrlParamsArgs<Url>>,
|
|
103
153
|
) => () => Promise<void>
|
|
104
154
|
}
|
|
105
155
|
|
|
106
156
|
/**
|
|
107
157
|
* Options for infinite query configuration.
|
|
158
|
+
*
|
|
159
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
160
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
108
161
|
*/
|
|
109
162
|
export type InfiniteQueryOptions<
|
|
110
163
|
Config extends BaseEndpointConfig<HttpMethod, string, ZodObject>,
|
|
111
164
|
Res = any,
|
|
165
|
+
UseDiscriminator extends boolean = false,
|
|
112
166
|
> = {
|
|
113
167
|
keyPrefix?: string[]
|
|
114
168
|
keySuffix?: string[]
|
|
115
|
-
processResponse: (
|
|
169
|
+
processResponse: (
|
|
170
|
+
data: ComputeResponseInput<
|
|
171
|
+
UseDiscriminator,
|
|
172
|
+
Config['responseSchema'],
|
|
173
|
+
Config['errorSchema']
|
|
174
|
+
>,
|
|
175
|
+
) => Res
|
|
116
176
|
onFail?: (err: unknown) => void
|
|
117
177
|
getNextPageParam: (
|
|
118
178
|
lastPage: Res,
|
|
@@ -138,8 +198,8 @@ export type InfiniteQueryOptions<
|
|
|
138
198
|
/** @deprecated Use QueryArgs instead */
|
|
139
199
|
export type ClientQueryArgs<
|
|
140
200
|
Url extends string = string,
|
|
141
|
-
QuerySchema = ZodObject,
|
|
142
|
-
RequestSchema = undefined,
|
|
201
|
+
QuerySchema extends ZodObject = ZodObject,
|
|
202
|
+
RequestSchema extends ZodType | undefined = undefined,
|
|
143
203
|
> = QueryArgs<Url, QuerySchema, RequestSchema>
|
|
144
204
|
|
|
145
205
|
/** @deprecated Use QueryUrlParamsArgs instead */
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { HttpMethod, Util_FlatObject } from '@navios/builder';
|
|
2
|
-
import type { InfiniteData, QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type { z, ZodObject, ZodType } from 'zod/v4';
|
|
4
|
-
import type { ClientOptions, ProcessResponseFunction } from './types.mjs';
|
|
5
|
-
import type { ClientInstance, ClientMutationArgs } from './types/index.mjs';
|
|
6
|
-
export interface ClientEndpointDefinition<Method = HttpMethod, Url = string, QuerySchema = unknown, Response = ZodType> {
|
|
7
|
-
method: Method;
|
|
8
|
-
url: Url;
|
|
9
|
-
querySchema?: QuerySchema;
|
|
10
|
-
responseSchema: Response;
|
|
11
|
-
}
|
|
12
|
-
export interface ClientQueryConfig<Method = HttpMethod, Url = string, QuerySchema = ZodObject, Response extends ZodType = ZodType, Result = z.output<Response>> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {
|
|
13
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
14
|
-
}
|
|
15
|
-
export type ClientInfiniteQueryConfig<Method = HttpMethod, Url = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, PageResult = z.output<Response>, Result = InfiniteData<PageResult>> = Required<ClientEndpointDefinition<Method, Url, QuerySchema, Response>> & {
|
|
16
|
-
processResponse?: (data: z.output<Response>) => PageResult;
|
|
17
|
-
select?: (data: InfiniteData<PageResult>) => Result;
|
|
18
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
19
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
20
|
-
initialPageParam?: z.input<QuerySchema>;
|
|
21
|
-
};
|
|
22
|
-
export interface ClientMutationDataConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : ZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends boolean = false> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {
|
|
23
|
-
requestSchema?: RequestSchema;
|
|
24
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
25
|
-
useContext?: () => Context;
|
|
26
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
27
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
28
|
-
useKey?: UseKey;
|
|
29
|
-
}
|
|
30
|
-
export declare function declareClient<Options extends ClientOptions>({ api, defaults, }: Options): ClientInstance;
|
|
31
|
-
//# sourceMappingURL=declare-client.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declare-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AAS,OAAO,GAAG,OAAO,EAClC,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAC9B,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,MAAM,SAAS,OAAO,GAAG,KAAK,CAC9B,SAAQ,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,CAAC;IACpE,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,eAAe,EAAE,uBAAuB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC3D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,CACV,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACrB,SAAS,EAAE,eAAe,CACxB,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,WAAW,CAAC,CACpD,EACD,OAAO,EAAE,OAAO,KACb,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,OAAO,CAAC,EAAE,CACR,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,eAAe,CACxB,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,WAAW,CAAC,CACpD,EACD,OAAO,EAAE,OAAO,KACb,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,aAAa,EAAE,EAC3D,GAAG,EACH,QAAa,GACd,EAAE,OAAO,GAAG,cAAc,CAyJ1B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder';
|
|
2
|
-
import type { InfiniteData, QueryClient, UseInfiniteQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
3
|
-
import type { InfiniteQueryOptions } from './types.mjs';
|
|
4
|
-
import type { ClientQueryArgs } from './types/index.mjs';
|
|
5
|
-
export declare function makeInfiniteQueryOptions<Config extends AnyEndpointConfig, Options extends InfiniteQueryOptions<Config>, BaseQuery extends Omit<UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam' | 'placeholderData' | 'throwOnError'>>(endpoint: AbstractEndpoint<Config>, options: Options, baseQuery?: BaseQuery): {
|
|
6
|
-
(params: ClientQueryArgs): Options["processResponse"] extends (...args: any[]) => infer Result ? UseSuspenseInfiniteQueryOptions<Result, Error, BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<Result>> : never;
|
|
7
|
-
queryKey: import("./utils/query-key-creator.mjs").QueryKeyCreatorResult<Config["querySchema"], Config["url"], Options["processResponse"] extends (...args: any[]) => infer Result ? Result : never, true, import("@navios/builder").UrlHasParams<Config["url"]>>;
|
|
8
|
-
use(params: ClientQueryArgs): import("@tanstack/react-query").UseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<unknown, unknown>, Error>;
|
|
9
|
-
useSuspense(params: ClientQueryArgs): import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<unknown, unknown>, Error>;
|
|
10
|
-
invalidate(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
11
|
-
invalidateAll(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=make-infinite-query-options.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-infinite-query-options.d.mts","sourceRoot":"","sources":["../../src/make-infinite-query-options.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,uBAAuB,CAAA;AAS9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIxD,wBAAgB,wBAAwB,CACtC,MAAM,SAAS,iBAAiB,EAChC,OAAO,SAAS,oBAAoB,CAAC,MAAM,CAAC,EAC5C,SAAS,SAAS,IAAI,CACpB,uBAAuB,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EACzE,UAAU,GACV,SAAS,GACT,kBAAkB,GAClB,kBAAkB,GAClB,iBAAiB,GACjB,cAAc,CACjB,EAED,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAClC,OAAO,EAAE,OAAO,EAChB,SAAS,GAAE,SAA2B;aAO5B,eAAe,GACtB,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,MAAM,GAClE,+BAA+B,CAC7B,MAAM,EACN,KAAK,EACL,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GACnD,CAAC,GACD,YAAY,CAAC,MAAM,CAAC,CACzB,GACD,KAAK;;gBAmCU,eAAe,gGAvCU,GAAG,EAAE,KAAK,MAAM,CAAC;wBA2ClC,eAAe,wGA3CE,GAAG,EAAE,KAAK,MAAM,CAAC;4BA+C9B,WAAW,UAAU,eAAe;+BAOjC,WAAW,UAAU,eAAe;EASvE"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AbstractEndpoint, AnyEndpointConfig, UrlHasParams, UrlParams } from '@navios/builder';
|
|
2
|
-
import type { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import type { z } from 'zod/v4';
|
|
4
|
-
import type { BaseMutationArgs, BaseMutationParams } from './types.mjs';
|
|
5
|
-
export declare function makeMutation<Config extends AnyEndpointConfig, TData = unknown, TVariables extends BaseMutationArgs<Config> = BaseMutationArgs<Config>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false>(endpoint: AbstractEndpoint<Config>, options: BaseMutationParams<Config, TData, TVariables, TResponse, TContext, UseKey>): {
|
|
6
|
-
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, BaseMutationArgs<Config>>;
|
|
7
|
-
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
8
|
-
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
9
|
-
urlParams: UrlParams<Config["url"]>;
|
|
10
|
-
} : {} : never : never) => [Config["url"]] & {
|
|
11
|
-
[dataTagSymbol]: TData | Promise<TData>;
|
|
12
|
-
[dataTagErrorSymbol]: Error;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=make-mutation.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-mutation.d.mts","sourceRoot":"","sources":["../../src/make-mutation.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACV,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAQ/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIvE,wBAAgB,YAAY,CAC1B,MAAM,SAAS,iBAAiB,EAChC,KAAK,GAAG,OAAO,EACf,UAAU,SAAS,gBAAgB,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,EACtE,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAC9C,QAAQ,GAAG,OAAO,EAClB,MAAM,SAAS,OAAO,GAAG,KAAK,EAE9B,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAClC,OAAO,EAAE,kBAAkB,CACzB,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,QAAQ,EACR,MAAM,CACP;gBAMY,MAAM,SAAS,IAAI,GAC1B,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GACtC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GACxB,KAAK,GACP,KAAK,GACR,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;6BAqD/C,MAAM,SAAS,IAAI,GAC1B,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GACtC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GACxB,KAAK,GACP,KAAK,GACR,OAAO;;;;;;;EAgBX"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder';
|
|
2
|
-
import type { DataTag, QueryClient, UseQueryOptions, UseSuspenseQueryOptions } from '@tanstack/react-query';
|
|
3
|
-
import type { BaseQueryArgs, BaseQueryParams } from './types.mjs';
|
|
4
|
-
import type { ClientQueryArgs } from './types/index.mjs';
|
|
5
|
-
type Split<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
|
6
|
-
export declare function makeQueryOptions<Config extends AnyEndpointConfig, Options extends BaseQueryParams<Config>, BaseQuery extends Omit<UseQueryOptions<ReturnType<Options['processResponse']>, Error, any>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam' | 'enabled' | 'throwOnError' | 'placeholderData'>>(endpoint: AbstractEndpoint<Config>, options: Options, baseQuery?: BaseQuery): {
|
|
7
|
-
(params: BaseQueryArgs<Config>): Options["processResponse"] extends (...args: any[]) => infer Result ? UseSuspenseQueryOptions<Result, Error, BaseQuery["select"] extends (...args: any[]) => infer T ? T : Result, DataTag<Split<Config["url"], "/">, Result, Error>> : never;
|
|
8
|
-
queryKey: import("./utils/query-key-creator.mjs").QueryKeyCreatorResult<Config["querySchema"], Config["url"], Options["processResponse"] extends (...args: any[]) => infer Result ? Result : never, false, import("@navios/builder").UrlHasParams<Config["url"]>>;
|
|
9
|
-
use(params: ClientQueryArgs): import("@tanstack/react-query").UseQueryResult<import("@tanstack/react-query").NoInfer<BaseQuery["select"] extends (...args: any[]) => infer T ? T : unknown>, Error>;
|
|
10
|
-
useSuspense(params: ClientQueryArgs): import("@tanstack/react-query").UseSuspenseQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : unknown, Error>;
|
|
11
|
-
invalidate(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
12
|
-
invalidateAll(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=make-query-options.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-query-options.d.mts","sourceRoot":"","sources":["../../src/make-query-options.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,eAAe,EACf,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAI9B,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIxD,KAAK,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,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
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BaseEndpointConfig, EndpointFunctionArgs, HttpMethod, Util_FlatObject } from '@navios/builder';
|
|
2
|
-
import type { z } from 'zod/v4';
|
|
3
|
-
export type ClientEndpointHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, ResponseSchema extends z.ZodType = z.ZodType, QuerySchema = unknown> = {
|
|
4
|
-
endpoint: ((params: Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, RequestSchema>>) => Promise<z.output<ResponseSchema>>) & {
|
|
5
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=client-endpoint-helper.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-endpoint-helper.d.mts","sourceRoot":"","sources":["../../../src/types/client-endpoint-helper.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,MAAM,oBAAoB,CAC9B,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,aAAa,GAAG,OAAO,EACvB,cAAc,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAC5C,WAAW,GAAG,OAAO,IACnB;IACF,QAAQ,EAAE,CAAC,CACT,MAAM,EAAE,eAAe,CACrB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,CACtD,KACE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG;QACxC,MAAM,EAAE,kBAAkB,CACxB,MAAM,EACN,GAAG,EACH,WAAW,EACX,cAAc,EACd,aAAa,CACd,CAAA;KACF,CAAA;CACF,CAAA"}
|