@navios/react-query 0.1.0 → 0.1.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/dist/_tsup-dts-rollup.d.mts +448 -0
- package/dist/_tsup-dts-rollup.d.ts +448 -0
- package/dist/index.d.mts +26 -346
- package/dist/index.d.ts +26 -346
- package/dist/index.js +9 -4
- package/dist/index.mjs +9 -4
- package/package.json +5 -5
- package/src/declare-client.mts +18 -7
- package/src/types/client-endpoint-helper.mts +29 -0
- package/src/types/client-instance.mts +23 -11
- package/src/types/index.mts +1 -0
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,346 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
useContext?: () => TContext;
|
|
29
|
-
onSuccess?: (queryClient: QueryClient, data: TData, variables: TVariables, context: TContext) => void | Promise<void>;
|
|
30
|
-
onError?: (queryClient: QueryClient, err: unknown, variables: TVariables, context: TContext) => void | Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* If true, we will create a mutation key that can be shared across the project.
|
|
33
|
-
*/
|
|
34
|
-
useKey?: UseKey;
|
|
35
|
-
keyPrefix?: UseKey extends true ? UrlHasParams<Config['url']> extends true ? string[] : never : never;
|
|
36
|
-
keySuffix?: UseKey extends true ? UrlHasParams<Config['url']> extends true ? string[] : never : never;
|
|
37
|
-
}
|
|
38
|
-
type BaseQueryArgs<Config extends AnyEndpointConfig> = (UrlHasParams<Config['url']> extends true ? {
|
|
39
|
-
urlParams: UrlParams<Config['url']>;
|
|
40
|
-
} : {}) & (Config['querySchema'] extends AnyZodObject ? {
|
|
41
|
-
params: z.input<Config['querySchema']>;
|
|
42
|
-
} : {});
|
|
43
|
-
type BaseMutationArgs<Config extends AnyEndpointConfig> = NaviosZodRequest<Config>;
|
|
44
|
-
type InfiniteQueryOptions<Config extends BaseEndpointConfig<HttpMethod, string, AnyZodObject>, Res = any> = {
|
|
45
|
-
keyPrefix?: string[];
|
|
46
|
-
keySuffix?: string[];
|
|
47
|
-
processResponse: (data: z.infer<Config['responseSchema']>) => Res;
|
|
48
|
-
onFail?: (err: unknown) => void;
|
|
49
|
-
getNextPageParam: (lastPage: z.infer<Config['responseSchema']>, allPages: z.infer<Config['responseSchema']>[], lastPageParam: z.infer<Config['querySchema']> | undefined, allPageParams: z.infer<Config['querySchema']>[] | undefined) => z.input<Config['querySchema']> | z.infer<Config['querySchema']> | undefined;
|
|
50
|
-
initialPageParam?: z.input<Config['querySchema']> | z.infer<Config['querySchema']>;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
type ClientMutationArgs<Url extends string = string, RequestSchema = unknown, QuerySchema = unknown> = (UrlHasParams<Url> extends true ? {
|
|
54
|
-
urlParams: UrlParams<Url>;
|
|
55
|
-
} : {}) & (RequestSchema extends AnyZodObject ? {
|
|
56
|
-
data: z.input<RequestSchema>;
|
|
57
|
-
} : {}) & (QuerySchema extends AnyZodObject ? {
|
|
58
|
-
params: z.input<QuerySchema>;
|
|
59
|
-
} : {});
|
|
60
|
-
|
|
61
|
-
type MutationHelpers<Url extends string, Result = unknown> = UrlHasParams<Url> extends true ? {
|
|
62
|
-
mutationKey: (params: UrlParams<Url>) => DataTag<[Url], Result, Error>;
|
|
63
|
-
useIsMutating: (keyParams: UrlParams<Url>) => boolean;
|
|
64
|
-
} : {
|
|
65
|
-
mutationKey: () => DataTag<[Url], Result, Error>;
|
|
66
|
-
useIsMutating: () => boolean;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type ClientQueryArgs<Url extends string = string, QuerySchema = AnyZodObject> = (UrlHasParams<Url> extends true ? {
|
|
70
|
-
urlParams: UrlParams<Url>;
|
|
71
|
-
} : {}) & (QuerySchema extends AnyZodObject ? {
|
|
72
|
-
params: z.input<QuerySchema>;
|
|
73
|
-
} : {});
|
|
74
|
-
|
|
75
|
-
type Split$1<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split$1<U, D>] : [S];
|
|
76
|
-
type QueryKeyCreatorResult<QuerySchema = undefined, Url extends string = string, Result = unknown, IsInfinite extends boolean = false, HasParams extends UrlHasParams<Url> = UrlHasParams<Url>> = {
|
|
77
|
-
template: Split$1<Url, '/'>;
|
|
78
|
-
dataTag: (params: (HasParams extends true ? {
|
|
79
|
-
urlParams: UrlParams<Url>;
|
|
80
|
-
} : {}) & (QuerySchema extends AnyZodObject ? {
|
|
81
|
-
params: z.input<QuerySchema>;
|
|
82
|
-
} : {})) => DataTag<Split$1<Url, '/'>, IsInfinite extends true ? InfiniteData<Result> : Result, Error>;
|
|
83
|
-
filterKey: (params: HasParams extends true ? {
|
|
84
|
-
urlParams: UrlParams<Url>;
|
|
85
|
-
} : {}) => DataTag<Split$1<Url, '/'>, IsInfinite extends true ? InfiniteData<Result> : Result, Error>;
|
|
86
|
-
bindToUrl: (params: (HasParams extends true ? {
|
|
87
|
-
urlParams: UrlParams<Url>;
|
|
88
|
-
} : {}) & (QuerySchema extends AnyZodObject ? {
|
|
89
|
-
params: z.infer<QuerySchema>;
|
|
90
|
-
} : {})) => string;
|
|
91
|
-
};
|
|
92
|
-
declare function queryKeyCreator<Config extends AnyEndpointConfig, Options extends BaseQueryParams<Config>, IsInfinite extends boolean, Url extends Config['url'] = Config['url'], HasParams extends UrlHasParams<Url> = UrlHasParams<Url>>(config: Config, options: Options, isInfinite: IsInfinite): QueryKeyCreatorResult<Config['querySchema'], Url, Options['processResponse'] extends (...args: any[]) => infer Result ? Result : never, IsInfinite, HasParams>;
|
|
93
|
-
|
|
94
|
-
type ClientQueryUrlParamsArgs<Url extends string = string> = UrlHasParams<Url> extends true ? {
|
|
95
|
-
urlParams: UrlParams<Url>;
|
|
96
|
-
} : {} | undefined;
|
|
97
|
-
|
|
98
|
-
type QueryHelpers<Url extends string, QuerySchema extends AnyZodObject | undefined = undefined, Result = undefined, IsInfinite extends boolean = false> = {
|
|
99
|
-
queryKey: QueryKeyCreatorResult<QuerySchema, Url, Result, IsInfinite>;
|
|
100
|
-
use: (params: Util_FlatObject<ClientQueryArgs<Url, QuerySchema>>) => UseQueryResult<Result, Error>;
|
|
101
|
-
useSuspense: (params: Util_FlatObject<ClientQueryArgs<Url, QuerySchema>>) => UseSuspenseQueryResult<Result, Error>;
|
|
102
|
-
invalidate: (queryClient: QueryClient, params: Util_FlatObject<ClientQueryArgs<Url, QuerySchema>>) => () => Promise<void>;
|
|
103
|
-
invalidateAll: (queryClient: QueryClient, params: Util_FlatObject<ClientQueryUrlParamsArgs<Url>>) => () => Promise<void>;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
interface ClientInstance {
|
|
107
|
-
query<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, Response extends ZodType = ZodType, Result = z.output<Response>>(config: {
|
|
108
|
-
method: Method;
|
|
109
|
-
url: Url;
|
|
110
|
-
responseSchema: Response;
|
|
111
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
112
|
-
}): ((params: Util_FlatObject<ClientQueryArgs<Url, undefined>>) => UseSuspenseQueryOptions<Result, Error, Result, DataTag<Split$2<Url, '/'>, Result, Error>>) & QueryHelpers<Url, undefined, Result>;
|
|
113
|
-
query<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, Result = z.output<Response>>(config: {
|
|
114
|
-
method: Method;
|
|
115
|
-
url: Url;
|
|
116
|
-
querySchema: QuerySchema;
|
|
117
|
-
responseSchema: Response;
|
|
118
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
119
|
-
}): ((params: Util_FlatObject<ClientQueryArgs<Url, QuerySchema>>) => UseSuspenseQueryOptions<Result, Error, Result, DataTag<Split$2<Url, '/'>, Result, Error>>) & QueryHelpers<Url, QuerySchema, Result>;
|
|
120
|
-
infiniteQuery<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, PageResult = z.output<Response>, Result = InfiniteData<PageResult>>(config: {
|
|
121
|
-
method: Method;
|
|
122
|
-
url: Url;
|
|
123
|
-
querySchema: QuerySchema;
|
|
124
|
-
responseSchema: Response;
|
|
125
|
-
processResponse?: (data: z.output<Response>) => PageResult;
|
|
126
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
127
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
128
|
-
}): ((params: Util_FlatObject<ClientQueryArgs<Url, QuerySchema>>) => UseSuspenseInfiniteQueryOptions<PageResult, Error, Result, PageResult, DataTag<Split$2<Url, '/'>, PageResult, Error>, z.output<QuerySchema>>) & QueryHelpers<Url, QuerySchema, PageResult, true>;
|
|
129
|
-
mutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
130
|
-
method: Method;
|
|
131
|
-
url: Url;
|
|
132
|
-
useKey: UseKey;
|
|
133
|
-
requestSchema: RequestSchema;
|
|
134
|
-
querySchema: QuerySchema;
|
|
135
|
-
responseSchema: Response;
|
|
136
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
137
|
-
useContext?: () => Context;
|
|
138
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
139
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
140
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
141
|
-
urlParams: UrlParams<Url>;
|
|
142
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, RequestSchema, QuerySchema>>) & MutationHelpers<Url, Result>;
|
|
143
|
-
mutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown>(config: {
|
|
144
|
-
method: Method;
|
|
145
|
-
url: Url;
|
|
146
|
-
requestSchema: RequestSchema;
|
|
147
|
-
querySchema: QuerySchema;
|
|
148
|
-
responseSchema: Response;
|
|
149
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
150
|
-
useContext?: () => Context;
|
|
151
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
152
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
153
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
154
|
-
urlParams: UrlParams<Url>;
|
|
155
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, RequestSchema, QuerySchema>>;
|
|
156
|
-
mutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown>(config: {
|
|
157
|
-
method: Method;
|
|
158
|
-
url: Url;
|
|
159
|
-
requestSchema: RequestSchema;
|
|
160
|
-
responseSchema: Response;
|
|
161
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
162
|
-
useContext?: () => Context;
|
|
163
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
164
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
165
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
166
|
-
urlParams: UrlParams<Url>;
|
|
167
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result>;
|
|
168
|
-
mutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
169
|
-
method: Method;
|
|
170
|
-
url: Url;
|
|
171
|
-
useKey: UseKey;
|
|
172
|
-
requestSchema: RequestSchema;
|
|
173
|
-
responseSchema: Response;
|
|
174
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
175
|
-
useContext?: () => Context;
|
|
176
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
177
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, undefined>>, context: Context) => void | Promise<void>;
|
|
178
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
179
|
-
urlParams: UrlParams<Url>;
|
|
180
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, RequestSchema, undefined>>) & MutationHelpers<Url, Result>;
|
|
181
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
182
|
-
method: Method;
|
|
183
|
-
url: Url;
|
|
184
|
-
useKey: UseKey;
|
|
185
|
-
querySchema: QuerySchema;
|
|
186
|
-
responseSchema: Response;
|
|
187
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
188
|
-
useContext?: () => Context;
|
|
189
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
190
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
191
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
192
|
-
urlParams: UrlParams<Url>;
|
|
193
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, undefined, QuerySchema>>) & MutationHelpers<Url, Result>;
|
|
194
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown>(config: {
|
|
195
|
-
method: Method;
|
|
196
|
-
url: Url;
|
|
197
|
-
querySchema: QuerySchema;
|
|
198
|
-
responseSchema: Response;
|
|
199
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
200
|
-
useContext?: () => Context;
|
|
201
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
202
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
203
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
204
|
-
urlParams: UrlParams<Url>;
|
|
205
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, undefined, QuerySchema>>;
|
|
206
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
207
|
-
method: Method;
|
|
208
|
-
url: Url;
|
|
209
|
-
useKey: UseKey;
|
|
210
|
-
responseSchema: Response;
|
|
211
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
212
|
-
useContext?: () => Context;
|
|
213
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
214
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
215
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
216
|
-
urlParams: UrlParams<Url>;
|
|
217
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, undefined, undefined>>) & MutationHelpers<Url, Result>;
|
|
218
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown>(config: {
|
|
219
|
-
method: Method;
|
|
220
|
-
url: Url;
|
|
221
|
-
responseSchema: Response;
|
|
222
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
223
|
-
useContext?: () => Context;
|
|
224
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
225
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, undefined, undefined>>, context: Context) => void | Promise<void>;
|
|
226
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
227
|
-
urlParams: UrlParams<Url>;
|
|
228
|
-
} : {}) => UseMutationResult<Result, Error, ClientMutationArgs<Url, undefined, undefined>>;
|
|
229
|
-
queryFromEndpoint<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, Result = z.output<Response>>(endpoint: any & {
|
|
230
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response>;
|
|
231
|
-
}, options?: {
|
|
232
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
233
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
234
|
-
urlParams: UrlParams<Url>;
|
|
235
|
-
} : {}) => UseSuspenseQueryOptions<Result, Error, Result, DataTag<Split$2<Url, '/'>, Result, Error>> & QueryHelpers<Url, QuerySchema, Result>;
|
|
236
|
-
queryFromEndpoint<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, Response extends ZodType = ZodType, Result = z.output<Response>>(endpoint: any & {
|
|
237
|
-
config: BaseEndpointConfig<Method, Url, undefined, Response>;
|
|
238
|
-
}, options?: {
|
|
239
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
240
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
241
|
-
urlParams: UrlParams<Url>;
|
|
242
|
-
} : {}) => UseSuspenseQueryOptions<Result, Error, Result, DataTag<Split$2<Url, '/'>, Result, Error>> & QueryHelpers<Url, undefined, Result>;
|
|
243
|
-
infiniteQueryFromEndpoint<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, PageResult = z.output<Response>, Result = InfiniteData<PageResult>>(endpoint: any & {
|
|
244
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response>;
|
|
245
|
-
}, options: {
|
|
246
|
-
processResponse?: (data: z.output<Response>) => PageResult;
|
|
247
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
248
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
249
|
-
}): (params: UrlHasParams<Url> extends true ? {
|
|
250
|
-
urlParams: UrlParams<Url>;
|
|
251
|
-
} : {}) => UseSuspenseInfiniteQueryOptions<PageResult, Error, Result, PageResult, DataTag<Split$2<Url, '/'>, PageResult, Error>, z.output<QuerySchema>> & QueryHelpers<Url, QuerySchema, PageResult, true>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Creates a mutation key for a given endpoint configuration and options.
|
|
256
|
-
*
|
|
257
|
-
* @param {config: Config } config - The endpoint object containing the configuration.
|
|
258
|
-
* @param {Options} [options] - Optional query parameters with a default `processResponse` function that processes the response data.
|
|
259
|
-
*
|
|
260
|
-
* @returns {Object} An object containing the `mutationKey` function.
|
|
261
|
-
*
|
|
262
|
-
* The `mutationKey` function generates a mutation key based on the provided parameters:
|
|
263
|
-
* - If the URL has parameters (`HasParams` is `true`), it expects an object with `urlParams`.
|
|
264
|
-
* - The return type of the `mutationKey` function depends on the `processResponse` function in `options`.
|
|
265
|
-
* If `processResponse` is defined, the return type is a `DataTag` containing the processed result and an error type.
|
|
266
|
-
*
|
|
267
|
-
* @example Example usage:
|
|
268
|
-
* ```typescript
|
|
269
|
-
* const createMutationKey = mutationKeyCreator(endpoint.config);
|
|
270
|
-
* const mutationKey = createMutationKey({ urlParams: { id: 123 } });
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* @example Advanced usage:
|
|
274
|
-
* ```ts
|
|
275
|
-
* const createMutationKey = mutationKeyCreator(endpoint.config, {
|
|
276
|
-
* processResponse: (data) => {
|
|
277
|
-
* if (!data.success) {
|
|
278
|
-
* throw new Error(data.message);
|
|
279
|
-
* }
|
|
280
|
-
* return data.data;
|
|
281
|
-
* },
|
|
282
|
-
* });
|
|
283
|
-
* // We create a mutation that will be shared across the project for all passed userId
|
|
284
|
-
* const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });
|
|
285
|
-
*/
|
|
286
|
-
declare function mutationKeyCreator<Config extends AnyEndpointConfig, Options extends BaseQueryParams<Config>, Url extends Config['url'] = Config['url'], HasParams extends UrlHasParams<Url> = UrlHasParams<Url>>(config: Config, options?: Options): (params: HasParams extends true ? {
|
|
287
|
-
urlParams: UrlParams<Url>;
|
|
288
|
-
} : {}) => Options['processResponse'] extends (...args: any[]) => infer Result ? DataTag<[Config['url']], Result, Error> : never;
|
|
289
|
-
|
|
290
|
-
interface ClientEndpoint<Method = HttpMethod, Url = string, QuerySchema = unknown, Response = ZodType> {
|
|
291
|
-
method: Method;
|
|
292
|
-
url: Url;
|
|
293
|
-
querySchema?: QuerySchema;
|
|
294
|
-
responseSchema: Response;
|
|
295
|
-
}
|
|
296
|
-
interface ClientQueryConfig<Method = HttpMethod, Url = string, QuerySchema = AnyZodObject, Response extends ZodType = ZodType, Result = z.output<Response>> extends ClientEndpoint<Method, Url, QuerySchema, Response> {
|
|
297
|
-
processResponse?: (data: z.output<Response>) => Result;
|
|
298
|
-
}
|
|
299
|
-
type ClientInfiniteQueryConfig<Method = HttpMethod, Url = string, QuerySchema extends AnyZodObject = AnyZodObject, Response extends ZodType = ZodType, PageResult = z.output<Response>, Result = InfiniteData<PageResult>> = Required<ClientEndpoint<Method, Url, QuerySchema, Response>> & {
|
|
300
|
-
processResponse?: (data: z.output<Response>) => PageResult;
|
|
301
|
-
select?: (data: InfiniteData<PageResult>) => Result;
|
|
302
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
303
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
304
|
-
initialPageParam?: z.input<QuerySchema>;
|
|
305
|
-
};
|
|
306
|
-
interface ClientMutationDataConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = Method extends 'DELETE' ? never : AnyZodObject, QuerySchema = unknown, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result = unknown, Context = unknown, UseKey extends boolean = false> extends ClientEndpoint<Method, Url, QuerySchema, Response> {
|
|
307
|
-
requestSchema?: RequestSchema;
|
|
308
|
-
processResponse: ProcessResponseFunction<Result, ReqResult>;
|
|
309
|
-
useContext?: () => Context;
|
|
310
|
-
onSuccess?: (queryClient: QueryClient, data: NoInfer<Result>, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
311
|
-
onError?: (queryClient: QueryClient, error: Error, variables: Util_FlatObject<ClientMutationArgs<Url, RequestSchema, QuerySchema>>, context: Context) => void | Promise<void>;
|
|
312
|
-
useKey?: UseKey;
|
|
313
|
-
}
|
|
314
|
-
declare function declareClient<Options extends ClientOptions>({ api, defaults, }: Options): ClientInstance;
|
|
315
|
-
|
|
316
|
-
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>): {
|
|
317
|
-
(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): UseMutationResult<TData, Error, BaseMutationArgs<Config>>;
|
|
318
|
-
useIsMutating(keyParams: UseKey extends true ? UrlHasParams<Config["url"]> extends true ? UrlParams<Config["url"]> : never : never): boolean;
|
|
319
|
-
mutationKey: (params: UrlHasParams<Config["url"]> extends infer T ? T extends UrlHasParams<Config["url"]> ? T extends true ? {
|
|
320
|
-
urlParams: UrlParams<Config["url"]>;
|
|
321
|
-
} : {} : never : never) => [Config["url"]] & {
|
|
322
|
-
[dataTagSymbol]: TData | Promise<TData>;
|
|
323
|
-
[dataTagErrorSymbol]: Error;
|
|
324
|
-
};
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
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): {
|
|
328
|
-
(params: ClientQueryArgs): Options["processResponse"] extends (...args: any[]) => infer Result ? UseSuspenseInfiniteQueryOptions<Result, Error, BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<Result>> : never;
|
|
329
|
-
queryKey: QueryKeyCreatorResult<Config["querySchema"], Config["url"], Options["processResponse"] extends (...args: any[]) => infer Result ? Result : never, true, _navios_common.UrlHasParams<Config["url"]>>;
|
|
330
|
-
use(params: ClientQueryArgs): _tanstack_react_query.UseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<unknown, unknown>, Error>;
|
|
331
|
-
useSuspense(params: ClientQueryArgs): _tanstack_react_query.UseSuspenseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : InfiniteData<unknown, unknown>, Error>;
|
|
332
|
-
invalidate(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
333
|
-
invalidateAll(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
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];
|
|
337
|
-
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): {
|
|
338
|
-
(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;
|
|
339
|
-
queryKey: QueryKeyCreatorResult<Config["querySchema"], Config["url"], Options["processResponse"] extends (...args: any[]) => infer Result ? Result : never, false, _navios_common.UrlHasParams<Config["url"]>>;
|
|
340
|
-
use(params: ClientQueryArgs): _tanstack_react_query.DefinedUseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : unknown, Error>;
|
|
341
|
-
useSuspense(params: ClientQueryArgs): _tanstack_react_query.UseSuspenseInfiniteQueryResult<BaseQuery["select"] extends (...args: any[]) => infer T ? T : unknown, Error>;
|
|
342
|
-
invalidate(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
343
|
-
invalidateAll(queryClient: QueryClient, params: ClientQueryArgs): Promise<void>;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
export { type BaseMutationArgs, type BaseMutationParams, type BaseQueryArgs, type BaseQueryParams, type ClientEndpoint, type ClientInfiniteQueryConfig, type ClientInstance, type ClientMutationArgs, type ClientMutationDataConfig, type ClientOptions, type ClientQueryArgs, type ClientQueryConfig, type ClientQueryUrlParamsArgs, type InfiniteQueryOptions, type MutationHelpers, type ProcessResponseFunction, type QueryHelpers, type QueryKeyCreatorResult, type Split$2 as Split, declareClient, makeInfiniteQueryOptions, makeMutation, makeQueryOptions, mutationKeyCreator, queryKeyCreator };
|
|
1
|
+
export { ClientEndpointHelper } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { ClientInstance } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { ClientMutationArgs } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { MutationHelpers } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { ClientQueryArgs } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { QueryHelpers } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { ClientQueryUrlParamsArgs } from './_tsup-dts-rollup.js';
|
|
8
|
+
export { mutationKeyCreator } from './_tsup-dts-rollup.js';
|
|
9
|
+
export { queryKeyCreator } from './_tsup-dts-rollup.js';
|
|
10
|
+
export { QueryKeyCreatorResult } from './_tsup-dts-rollup.js';
|
|
11
|
+
export { declareClient_alias_1 as declareClient } from './_tsup-dts-rollup.js';
|
|
12
|
+
export { ClientEndpointDefinition_alias_1 as ClientEndpointDefinition } from './_tsup-dts-rollup.js';
|
|
13
|
+
export { ClientQueryConfig_alias_1 as ClientQueryConfig } from './_tsup-dts-rollup.js';
|
|
14
|
+
export { ClientInfiniteQueryConfig_alias_1 as ClientInfiniteQueryConfig } from './_tsup-dts-rollup.js';
|
|
15
|
+
export { ClientMutationDataConfig_alias_1 as ClientMutationDataConfig } from './_tsup-dts-rollup.js';
|
|
16
|
+
export { makeMutation } from './_tsup-dts-rollup.js';
|
|
17
|
+
export { makeInfiniteQueryOptions } from './_tsup-dts-rollup.js';
|
|
18
|
+
export { makeQueryOptions } from './_tsup-dts-rollup.js';
|
|
19
|
+
export { Split } from './_tsup-dts-rollup.js';
|
|
20
|
+
export { ProcessResponseFunction } from './_tsup-dts-rollup.js';
|
|
21
|
+
export { ClientOptions } from './_tsup-dts-rollup.js';
|
|
22
|
+
export { BaseQueryParams } from './_tsup-dts-rollup.js';
|
|
23
|
+
export { BaseMutationParams } from './_tsup-dts-rollup.js';
|
|
24
|
+
export { BaseQueryArgs } from './_tsup-dts-rollup.js';
|
|
25
|
+
export { BaseMutationArgs } from './_tsup-dts-rollup.js';
|
|
26
|
+
export { InfiniteQueryOptions } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -264,10 +264,12 @@ function declareClient({
|
|
|
264
264
|
querySchema: config.querySchema,
|
|
265
265
|
responseSchema: config.responseSchema
|
|
266
266
|
});
|
|
267
|
-
|
|
267
|
+
const queryOptions2 = makeQueryOptions(endpoint, {
|
|
268
268
|
...defaults,
|
|
269
269
|
processResponse: config.processResponse ?? ((data) => data)
|
|
270
270
|
});
|
|
271
|
+
queryOptions2.endpoint = endpoint;
|
|
272
|
+
return queryOptions2;
|
|
271
273
|
}
|
|
272
274
|
function queryFromEndpoint(endpoint, options) {
|
|
273
275
|
return makeQueryOptions(endpoint, {
|
|
@@ -283,13 +285,15 @@ function declareClient({
|
|
|
283
285
|
querySchema: config.querySchema,
|
|
284
286
|
responseSchema: config.responseSchema
|
|
285
287
|
});
|
|
286
|
-
|
|
288
|
+
const infiniteQueryOptions2 = makeInfiniteQueryOptions(endpoint, {
|
|
287
289
|
...defaults,
|
|
288
290
|
processResponse: config.processResponse ?? ((data) => data),
|
|
289
291
|
getNextPageParam: config.getNextPageParam,
|
|
290
292
|
getPreviousPageParam: config.getPreviousPageParam,
|
|
291
293
|
initialPageParam: config.initialPageParam
|
|
292
294
|
});
|
|
295
|
+
infiniteQueryOptions2.endpoint = endpoint;
|
|
296
|
+
return infiniteQueryOptions2;
|
|
293
297
|
}
|
|
294
298
|
function infiniteQueryFromEndpoint(endpoint, options) {
|
|
295
299
|
return makeInfiniteQueryOptions(endpoint, {
|
|
@@ -309,7 +313,7 @@ function declareClient({
|
|
|
309
313
|
requestSchema: config.requestSchema,
|
|
310
314
|
responseSchema: config.responseSchema
|
|
311
315
|
});
|
|
312
|
-
|
|
316
|
+
const useMutation2 = makeMutation(endpoint, {
|
|
313
317
|
processResponse: config.processResponse ?? ((data) => data),
|
|
314
318
|
useContext: config.useContext,
|
|
315
319
|
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
@@ -319,6 +323,8 @@ function declareClient({
|
|
|
319
323
|
useKey: config.useKey,
|
|
320
324
|
...defaults
|
|
321
325
|
});
|
|
326
|
+
useMutation2.endpoint = endpoint;
|
|
327
|
+
return useMutation2;
|
|
322
328
|
}
|
|
323
329
|
return {
|
|
324
330
|
// @ts-expect-error We simplified types here
|
|
@@ -342,4 +348,3 @@ function declareClient({
|
|
|
342
348
|
mutationKeyCreator,
|
|
343
349
|
queryKeyCreator
|
|
344
350
|
});
|
|
345
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -245,10 +245,12 @@ function declareClient({
|
|
|
245
245
|
querySchema: config.querySchema,
|
|
246
246
|
responseSchema: config.responseSchema
|
|
247
247
|
});
|
|
248
|
-
|
|
248
|
+
const queryOptions2 = makeQueryOptions(endpoint, {
|
|
249
249
|
...defaults,
|
|
250
250
|
processResponse: config.processResponse ?? ((data) => data)
|
|
251
251
|
});
|
|
252
|
+
queryOptions2.endpoint = endpoint;
|
|
253
|
+
return queryOptions2;
|
|
252
254
|
}
|
|
253
255
|
function queryFromEndpoint(endpoint, options) {
|
|
254
256
|
return makeQueryOptions(endpoint, {
|
|
@@ -264,13 +266,15 @@ function declareClient({
|
|
|
264
266
|
querySchema: config.querySchema,
|
|
265
267
|
responseSchema: config.responseSchema
|
|
266
268
|
});
|
|
267
|
-
|
|
269
|
+
const infiniteQueryOptions2 = makeInfiniteQueryOptions(endpoint, {
|
|
268
270
|
...defaults,
|
|
269
271
|
processResponse: config.processResponse ?? ((data) => data),
|
|
270
272
|
getNextPageParam: config.getNextPageParam,
|
|
271
273
|
getPreviousPageParam: config.getPreviousPageParam,
|
|
272
274
|
initialPageParam: config.initialPageParam
|
|
273
275
|
});
|
|
276
|
+
infiniteQueryOptions2.endpoint = endpoint;
|
|
277
|
+
return infiniteQueryOptions2;
|
|
274
278
|
}
|
|
275
279
|
function infiniteQueryFromEndpoint(endpoint, options) {
|
|
276
280
|
return makeInfiniteQueryOptions(endpoint, {
|
|
@@ -290,7 +294,7 @@ function declareClient({
|
|
|
290
294
|
requestSchema: config.requestSchema,
|
|
291
295
|
responseSchema: config.responseSchema
|
|
292
296
|
});
|
|
293
|
-
|
|
297
|
+
const useMutation2 = makeMutation(endpoint, {
|
|
294
298
|
processResponse: config.processResponse ?? ((data) => data),
|
|
295
299
|
useContext: config.useContext,
|
|
296
300
|
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
@@ -300,6 +304,8 @@ function declareClient({
|
|
|
300
304
|
useKey: config.useKey,
|
|
301
305
|
...defaults
|
|
302
306
|
});
|
|
307
|
+
useMutation2.endpoint = endpoint;
|
|
308
|
+
return useMutation2;
|
|
303
309
|
}
|
|
304
310
|
return {
|
|
305
311
|
// @ts-expect-error We simplified types here
|
|
@@ -322,4 +328,3 @@ export {
|
|
|
322
328
|
mutationKeyCreator,
|
|
323
329
|
queryKeyCreator
|
|
324
330
|
};
|
|
325
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/react-query",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"main": "./dist/index.js",
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@navios/common": "^0.1.
|
|
18
|
+
"@navios/common": "^0.1.1",
|
|
19
19
|
"@tanstack/react-query": "^5.51.21",
|
|
20
20
|
"zod": "^3.23.8"
|
|
21
21
|
},
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@navios/common": "^0.1.
|
|
37
|
-
"@tanstack/react-query": "^5.75.
|
|
36
|
+
"@navios/common": "^0.1.1",
|
|
37
|
+
"@tanstack/react-query": "^5.75.7",
|
|
38
38
|
"navios": "^0.4.0",
|
|
39
39
|
"react": "^19.1.0",
|
|
40
40
|
"typescript": "^5.8.3",
|
|
41
|
-
"zod": "^3.24.
|
|
41
|
+
"zod": "^3.24.4"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/declare-client.mts
CHANGED
|
@@ -14,7 +14,7 @@ import { makeInfiniteQueryOptions } from './make-infinite-query-options.mjs'
|
|
|
14
14
|
import { makeMutation } from './make-mutation.mjs'
|
|
15
15
|
import { makeQueryOptions } from './make-query-options.mjs'
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface ClientEndpointDefinition<
|
|
18
18
|
Method = HttpMethod,
|
|
19
19
|
Url = string,
|
|
20
20
|
QuerySchema = unknown,
|
|
@@ -32,7 +32,7 @@ export interface ClientQueryConfig<
|
|
|
32
32
|
QuerySchema = AnyZodObject,
|
|
33
33
|
Response extends ZodType = ZodType,
|
|
34
34
|
Result = z.output<Response>,
|
|
35
|
-
> extends
|
|
35
|
+
> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {
|
|
36
36
|
processResponse?: (data: z.output<Response>) => Result
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -43,7 +43,7 @@ export type ClientInfiniteQueryConfig<
|
|
|
43
43
|
Response extends ZodType = ZodType,
|
|
44
44
|
PageResult = z.output<Response>,
|
|
45
45
|
Result = InfiniteData<PageResult>,
|
|
46
|
-
> = Required<
|
|
46
|
+
> = Required<ClientEndpointDefinition<Method, Url, QuerySchema, Response>> & {
|
|
47
47
|
processResponse?: (data: z.output<Response>) => PageResult
|
|
48
48
|
select?: (data: InfiniteData<PageResult>) => Result
|
|
49
49
|
getNextPageParam: (
|
|
@@ -75,7 +75,7 @@ export interface ClientMutationDataConfig<
|
|
|
75
75
|
Result = unknown,
|
|
76
76
|
Context = unknown,
|
|
77
77
|
UseKey extends boolean = false,
|
|
78
|
-
> extends
|
|
78
|
+
> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {
|
|
79
79
|
requestSchema?: RequestSchema
|
|
80
80
|
processResponse: ProcessResponseFunction<Result, ReqResult>
|
|
81
81
|
useContext?: () => Context
|
|
@@ -111,10 +111,13 @@ export function declareClient<Options extends ClientOptions>({
|
|
|
111
111
|
responseSchema: config.responseSchema,
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
const queryOptions = makeQueryOptions(endpoint, {
|
|
115
115
|
...defaults,
|
|
116
116
|
processResponse: config.processResponse ?? ((data) => data),
|
|
117
117
|
})
|
|
118
|
+
// @ts-expect-error We attach the endpoint to the queryOptions
|
|
119
|
+
queryOptions.endpoint = endpoint
|
|
120
|
+
return queryOptions
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
function queryFromEndpoint(
|
|
@@ -139,13 +142,17 @@ export function declareClient<Options extends ClientOptions>({
|
|
|
139
142
|
querySchema: config.querySchema,
|
|
140
143
|
responseSchema: config.responseSchema,
|
|
141
144
|
})
|
|
142
|
-
|
|
145
|
+
const infiniteQueryOptions = makeInfiniteQueryOptions(endpoint, {
|
|
143
146
|
...defaults,
|
|
144
147
|
processResponse: config.processResponse ?? ((data) => data),
|
|
145
148
|
getNextPageParam: config.getNextPageParam,
|
|
146
149
|
getPreviousPageParam: config.getPreviousPageParam,
|
|
147
150
|
initialPageParam: config.initialPageParam,
|
|
148
151
|
})
|
|
152
|
+
|
|
153
|
+
// @ts-expect-error We attach the endpoint to the infiniteQueryOptions
|
|
154
|
+
infiniteQueryOptions.endpoint = endpoint
|
|
155
|
+
return infiniteQueryOptions
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
function infiniteQueryFromEndpoint(
|
|
@@ -188,7 +195,7 @@ export function declareClient<Options extends ClientOptions>({
|
|
|
188
195
|
responseSchema: config.responseSchema,
|
|
189
196
|
})
|
|
190
197
|
|
|
191
|
-
|
|
198
|
+
const useMutation = makeMutation(endpoint, {
|
|
192
199
|
processResponse: config.processResponse ?? ((data) => data),
|
|
193
200
|
useContext: config.useContext,
|
|
194
201
|
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
@@ -198,6 +205,10 @@ export function declareClient<Options extends ClientOptions>({
|
|
|
198
205
|
useKey: config.useKey,
|
|
199
206
|
...defaults,
|
|
200
207
|
})
|
|
208
|
+
|
|
209
|
+
// @ts-expect-error We attach the endpoint to the useMutation
|
|
210
|
+
useMutation.endpoint = endpoint
|
|
211
|
+
return useMutation
|
|
201
212
|
}
|
|
202
213
|
|
|
203
214
|
return {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseEndpointConfig,
|
|
3
|
+
EndpointFunctionArgs,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
Util_FlatObject,
|
|
6
|
+
} from '@navios/common'
|
|
7
|
+
import type { z } from 'zod'
|
|
8
|
+
|
|
9
|
+
export type ClientEndpointHelper<
|
|
10
|
+
Method extends HttpMethod = HttpMethod,
|
|
11
|
+
Url extends string = string,
|
|
12
|
+
RequestSchema = unknown,
|
|
13
|
+
ResponseSchema extends z.ZodType = z.ZodType,
|
|
14
|
+
QuerySchema = unknown,
|
|
15
|
+
> = {
|
|
16
|
+
endpoint: ((
|
|
17
|
+
params: Util_FlatObject<
|
|
18
|
+
EndpointFunctionArgs<Url, QuerySchema, RequestSchema>
|
|
19
|
+
>,
|
|
20
|
+
) => Promise<z.output<ResponseSchema>>) & {
|
|
21
|
+
config: BaseEndpointConfig<
|
|
22
|
+
Method,
|
|
23
|
+
Url,
|
|
24
|
+
QuerySchema,
|
|
25
|
+
ResponseSchema,
|
|
26
|
+
RequestSchema
|
|
27
|
+
>
|
|
28
|
+
}
|
|
29
|
+
}
|