@navios/react-query 0.7.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +171 -1
- package/README.md +152 -4
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/client/declare-client.mts.html +1264 -0
- package/coverage/client/index.html +116 -0
- package/coverage/clover.xml +160 -0
- package/coverage/coverage-final.json +8 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +146 -0
- package/coverage/mutation/index.html +131 -0
- package/coverage/mutation/key-creator.mts.html +277 -0
- package/coverage/mutation/make-hook.mts.html +952 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/query/index.html +161 -0
- package/coverage/query/key-creator.mts.html +415 -0
- package/coverage/query/make-infinite-options.mts.html +601 -0
- package/coverage/query/make-options.mts.html +838 -0
- package/coverage/query/prefetch.mts.html +1063 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/src/__tests__/errorSchema.spec.d.mts +2 -0
- package/dist/src/__tests__/errorSchema.spec.d.mts.map +1 -0
- package/dist/src/__tests__/prefetch.spec.d.mts +2 -0
- package/dist/src/__tests__/prefetch.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 +40 -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 +172 -0
- package/dist/src/mutation/optimistic.d.mts.map +1 -0
- package/dist/src/mutation/types.d.mts +41 -20
- 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 +25 -18
- package/dist/src/query/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/index.cjs +451 -28
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1019 -600
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +1016 -597
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +447 -29
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/declare-client.spec.mts +229 -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/__tests__/prefetch.spec.mts +310 -0
- 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 +344 -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 +67 -3
- package/src/mutation/index.mts +1 -0
- package/src/mutation/make-hook.mts +171 -63
- package/src/mutation/optimistic.mts +300 -0
- package/src/mutation/types.mts +87 -30
- 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 +56 -17
- package/src/client/__type-tests__/client-instance.spec-d.mts +0 -852
package/src/query/types.mts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AnyEndpointConfig,
|
|
3
3
|
BaseEndpointConfig,
|
|
4
|
+
EndpointOptions,
|
|
4
5
|
HttpMethod,
|
|
6
|
+
InferEndpointReturn,
|
|
7
|
+
RequestArgs,
|
|
8
|
+
Simplify,
|
|
5
9
|
UrlHasParams,
|
|
6
10
|
UrlParams,
|
|
7
|
-
Util_FlatObject,
|
|
8
11
|
} from '@navios/builder'
|
|
9
12
|
import type {
|
|
10
13
|
DataTag,
|
|
@@ -15,33 +18,59 @@ import type {
|
|
|
15
18
|
} from '@tanstack/react-query'
|
|
16
19
|
import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
17
20
|
|
|
18
|
-
import type { Split } from '../common/types.mjs'
|
|
21
|
+
import type { ComputeResponseInput, Split } from '../common/types.mjs'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Helper type to extract the result type from processResponse.
|
|
25
|
+
*/
|
|
26
|
+
export type QueryResult<
|
|
27
|
+
Options extends EndpointOptions,
|
|
28
|
+
UseDiscriminator extends boolean = false,
|
|
29
|
+
> = Options extends {
|
|
30
|
+
processResponse: (data: any) => infer Result
|
|
31
|
+
}
|
|
32
|
+
? Result
|
|
33
|
+
: InferEndpointReturn<Options, UseDiscriminator>
|
|
19
34
|
|
|
20
35
|
/**
|
|
21
36
|
* Arguments for query functions based on URL params and query schema.
|
|
37
|
+
* Uses RequestArgs from builder for consistency.
|
|
22
38
|
*/
|
|
23
39
|
export type QueryArgs<
|
|
24
40
|
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> } : {})
|
|
41
|
+
QuerySchema extends ZodObject | undefined = undefined,
|
|
42
|
+
RequestSchema extends ZodType | undefined = undefined,
|
|
43
|
+
> = RequestArgs<Url, QuerySchema, RequestSchema>
|
|
30
44
|
|
|
31
45
|
/**
|
|
32
46
|
* Arguments containing only URL params (for invalidateAll operations).
|
|
33
47
|
*/
|
|
34
48
|
export type QueryUrlParamsArgs<Url extends string = string> =
|
|
35
|
-
UrlHasParams<Url> extends true
|
|
49
|
+
UrlHasParams<Url> extends true
|
|
50
|
+
? { urlParams: UrlParams<Url> }
|
|
51
|
+
: {} | undefined
|
|
36
52
|
|
|
37
53
|
/**
|
|
38
54
|
* Base parameters for query configuration.
|
|
55
|
+
*
|
|
56
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
57
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
39
58
|
*/
|
|
40
|
-
export type QueryParams<
|
|
59
|
+
export type QueryParams<
|
|
60
|
+
Config extends AnyEndpointConfig,
|
|
61
|
+
Res = any,
|
|
62
|
+
UseDiscriminator extends boolean = false,
|
|
63
|
+
> = {
|
|
41
64
|
keyPrefix?: string[]
|
|
42
65
|
keySuffix?: string[]
|
|
43
66
|
onFail?: (err: unknown) => void
|
|
44
|
-
processResponse: (
|
|
67
|
+
processResponse: (
|
|
68
|
+
data: ComputeResponseInput<
|
|
69
|
+
UseDiscriminator,
|
|
70
|
+
Config['responseSchema'],
|
|
71
|
+
Config['errorSchema']
|
|
72
|
+
>,
|
|
73
|
+
) => Res
|
|
45
74
|
}
|
|
46
75
|
|
|
47
76
|
/**
|
|
@@ -88,31 +117,41 @@ export type QueryHelpers<
|
|
|
88
117
|
> = {
|
|
89
118
|
queryKey: QueryKeyCreatorResult<QuerySchema, Url, Result, IsInfinite>
|
|
90
119
|
use: (
|
|
91
|
-
params:
|
|
120
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
92
121
|
) => UseQueryResult<Result, Error>
|
|
93
122
|
useSuspense: (
|
|
94
|
-
params:
|
|
123
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
95
124
|
) => UseSuspenseQueryResult<Result, Error>
|
|
96
125
|
invalidate: (
|
|
97
126
|
queryClient: QueryClient,
|
|
98
|
-
params:
|
|
127
|
+
params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>,
|
|
99
128
|
) => () => Promise<void>
|
|
100
129
|
invalidateAll: (
|
|
101
130
|
queryClient: QueryClient,
|
|
102
|
-
params:
|
|
131
|
+
params: Simplify<QueryUrlParamsArgs<Url>>,
|
|
103
132
|
) => () => Promise<void>
|
|
104
133
|
}
|
|
105
134
|
|
|
106
135
|
/**
|
|
107
136
|
* Options for infinite query configuration.
|
|
137
|
+
*
|
|
138
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
139
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
108
140
|
*/
|
|
109
141
|
export type InfiniteQueryOptions<
|
|
110
142
|
Config extends BaseEndpointConfig<HttpMethod, string, ZodObject>,
|
|
111
143
|
Res = any,
|
|
144
|
+
UseDiscriminator extends boolean = false,
|
|
112
145
|
> = {
|
|
113
146
|
keyPrefix?: string[]
|
|
114
147
|
keySuffix?: string[]
|
|
115
|
-
processResponse: (
|
|
148
|
+
processResponse: (
|
|
149
|
+
data: ComputeResponseInput<
|
|
150
|
+
UseDiscriminator,
|
|
151
|
+
Config['responseSchema'],
|
|
152
|
+
Config['errorSchema']
|
|
153
|
+
>,
|
|
154
|
+
) => Res
|
|
116
155
|
onFail?: (err: unknown) => void
|
|
117
156
|
getNextPageParam: (
|
|
118
157
|
lastPage: Res,
|
|
@@ -138,8 +177,8 @@ export type InfiniteQueryOptions<
|
|
|
138
177
|
/** @deprecated Use QueryArgs instead */
|
|
139
178
|
export type ClientQueryArgs<
|
|
140
179
|
Url extends string = string,
|
|
141
|
-
QuerySchema = ZodObject,
|
|
142
|
-
RequestSchema = undefined,
|
|
180
|
+
QuerySchema extends ZodObject = ZodObject,
|
|
181
|
+
RequestSchema extends ZodType | undefined = undefined,
|
|
143
182
|
> = QueryArgs<Url, QuerySchema, RequestSchema>
|
|
144
183
|
|
|
145
184
|
/** @deprecated Use QueryUrlParamsArgs instead */
|