@navios/react-query 0.3.0 → 0.5.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 +74 -0
- package/README.md +13 -7
- package/dist/src/client/declare-client.d.mts +70 -0
- package/dist/src/client/declare-client.d.mts.map +1 -0
- package/dist/src/client/index.d.mts +3 -0
- package/dist/src/client/index.d.mts.map +1 -0
- package/dist/src/client/types.d.mts +287 -0
- package/dist/src/client/types.d.mts.map +1 -0
- package/dist/src/common/index.d.mts +2 -0
- package/dist/src/common/index.d.mts.map +1 -0
- package/dist/src/common/types.d.mts +21 -0
- package/dist/src/common/types.d.mts.map +1 -0
- package/dist/src/declare-client.d.mts +4 -4
- package/dist/src/declare-client.d.mts.map +1 -1
- package/dist/src/index.d.mts +13 -8
- package/dist/src/index.d.mts.map +1 -1
- package/dist/src/make-mutation.d.mts +1 -1
- package/dist/src/make-mutation.d.mts.map +1 -1
- package/dist/src/mutation/index.d.mts +4 -0
- package/dist/src/mutation/index.d.mts.map +1 -0
- package/dist/src/mutation/key-creator.d.mts +36 -0
- package/dist/src/mutation/key-creator.d.mts.map +1 -0
- package/dist/src/mutation/make-hook.d.mts +25 -0
- package/dist/src/mutation/make-hook.d.mts.map +1 -0
- package/dist/src/mutation/types.d.mts +50 -0
- package/dist/src/mutation/types.d.mts.map +1 -0
- package/dist/src/query/index.d.mts +5 -0
- package/dist/src/query/index.d.mts.map +1 -0
- package/dist/src/query/key-creator.d.mts +17 -0
- package/dist/src/query/key-creator.d.mts.map +1 -0
- package/dist/src/query/make-infinite-options.d.mts +23 -0
- package/dist/src/query/make-infinite-options.d.mts.map +1 -0
- package/dist/src/query/make-options.d.mts +24 -0
- package/dist/src/query/make-options.d.mts.map +1 -0
- package/dist/src/query/types.d.mts +83 -0
- package/dist/src/query/types.d.mts.map +1 -0
- package/dist/src/types/client-endpoint-helper.d.mts +1 -1
- package/dist/src/types/client-endpoint-helper.d.mts.map +1 -1
- package/dist/src/types/client-instance.d.mts +15 -15
- package/dist/src/types/client-instance.d.mts.map +1 -1
- package/dist/src/types/mutation-args.d.mts +3 -3
- package/dist/src/types/mutation-args.d.mts.map +1 -1
- package/dist/src/types/query-args.d.mts +3 -3
- package/dist/src/types/query-args.d.mts.map +1 -1
- package/dist/src/types/query-helpers.d.mts +2 -2
- package/dist/src/types/query-helpers.d.mts.map +1 -1
- package/dist/src/types.d.mts +4 -4
- package/dist/src/types.d.mts.map +1 -1
- package/dist/src/utils/query-key-creator.d.mts +3 -3
- package/dist/src/utils/query-key-creator.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/_tsup-dts-rollup.d.mts +512 -262
- package/lib/_tsup-dts-rollup.d.ts +512 -262
- package/lib/index.d.mts +26 -19
- package/lib/index.d.ts +26 -19
- package/lib/index.js +92 -66
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +92 -68
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/project.json +9 -1
- package/src/__tests__/client-type-check.spec.mts +2 -2
- package/src/__tests__/declare-client.spec.mts +2 -2
- package/src/__tests__/make-mutation.spec.mts +2 -2
- package/src/__tests__/makeDataTag.spec.mts +2 -2
- package/src/__tests__/makeInfiniteQueryOptions.spec.mts +2 -3
- package/src/__tests__/makeQueryOptions.spec.mts +2 -2
- package/src/{declare-client.mts → client/declare-client.mts} +96 -36
- package/src/client/index.mts +2 -0
- package/src/{types/client-instance.mts → client/types.mts} +442 -160
- package/src/common/index.mts +1 -0
- package/src/common/types.mts +31 -0
- package/src/index.mts +28 -8
- package/src/mutation/index.mts +3 -0
- package/src/mutation/key-creator.mts +64 -0
- package/src/{make-mutation.mts → mutation/make-hook.mts} +20 -9
- package/src/mutation/types.mts +106 -0
- package/src/query/index.mts +4 -0
- package/src/{utils/query-key-creator.mts → query/key-creator.mts} +22 -52
- package/src/{make-infinite-query-options.mts → query/make-infinite-options.mts} +29 -15
- package/src/{make-query-options.mts → query/make-options.mts} +26 -25
- package/src/query/types.mts +163 -0
- package/dist/tsdown.config.d.mts +0 -3
- package/dist/tsdown.config.d.mts.map +0 -1
- package/dist/tsup.config.d.mts +0 -3
- package/dist/tsup.config.d.mts.map +0 -1
- package/dist/vitest.config.d.mts +0 -3
- package/dist/vitest.config.d.mts.map +0 -1
- package/src/types/client-endpoint-helper.mts +0 -29
- package/src/types/index.mts +0 -7
- package/src/types/mutation-args.mts +0 -10
- package/src/types/mutation-helpers.mts +0 -13
- package/src/types/query-args.mts +0 -8
- package/src/types/query-helpers.mts +0 -34
- package/src/types/query-url-params-args.mts +0 -6
- package/src/types.mts +0 -118
- package/src/utils/mutation-key.creator.mts +0 -65
package/lib/index.d.mts
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
export { ClientEndpointHelper } from './_tsup-dts-rollup.mjs';
|
|
2
|
-
export { ClientInstance } from './_tsup-dts-rollup.mjs';
|
|
3
|
-
export { ClientMutationArgs } from './_tsup-dts-rollup.mjs';
|
|
4
|
-
export { MutationHelpers } from './_tsup-dts-rollup.mjs';
|
|
5
|
-
export { ClientQueryArgs } from './_tsup-dts-rollup.mjs';
|
|
6
|
-
export { QueryHelpers } from './_tsup-dts-rollup.mjs';
|
|
7
|
-
export { ClientQueryUrlParamsArgs } from './_tsup-dts-rollup.mjs';
|
|
8
|
-
export { mutationKeyCreator } from './_tsup-dts-rollup.mjs';
|
|
9
|
-
export { queryKeyCreator } from './_tsup-dts-rollup.mjs';
|
|
10
|
-
export { QueryKeyCreatorResult } from './_tsup-dts-rollup.mjs';
|
|
11
|
-
export { declareClient_alias_1 as declareClient } from './_tsup-dts-rollup.mjs';
|
|
12
|
-
export { ClientEndpointDefinition_alias_1 as ClientEndpointDefinition } from './_tsup-dts-rollup.mjs';
|
|
13
|
-
export { ClientQueryConfig_alias_1 as ClientQueryConfig } from './_tsup-dts-rollup.mjs';
|
|
14
|
-
export { ClientInfiniteQueryConfig_alias_1 as ClientInfiniteQueryConfig } from './_tsup-dts-rollup.mjs';
|
|
15
|
-
export { ClientMutationDataConfig_alias_1 as ClientMutationDataConfig } from './_tsup-dts-rollup.mjs';
|
|
16
|
-
export { makeMutation } from './_tsup-dts-rollup.mjs';
|
|
17
|
-
export { makeInfiniteQueryOptions } from './_tsup-dts-rollup.mjs';
|
|
18
1
|
export { makeQueryOptions } from './_tsup-dts-rollup.mjs';
|
|
2
|
+
export { makeInfiniteQueryOptions } from './_tsup-dts-rollup.mjs';
|
|
3
|
+
export { makeMutation } from './_tsup-dts-rollup.mjs';
|
|
4
|
+
export { createQueryKey } from './_tsup-dts-rollup.mjs';
|
|
5
|
+
export { queryKeyCreator } from './_tsup-dts-rollup.mjs';
|
|
6
|
+
export { createMutationKey } from './_tsup-dts-rollup.mjs';
|
|
7
|
+
export { mutationKeyCreator } from './_tsup-dts-rollup.mjs';
|
|
19
8
|
export { Split } from './_tsup-dts-rollup.mjs';
|
|
20
9
|
export { ProcessResponseFunction } from './_tsup-dts-rollup.mjs';
|
|
21
10
|
export { ClientOptions } from './_tsup-dts-rollup.mjs';
|
|
11
|
+
export { QueryArgs } from './_tsup-dts-rollup.mjs';
|
|
12
|
+
export { QueryUrlParamsArgs } from './_tsup-dts-rollup.mjs';
|
|
13
|
+
export { QueryParams } from './_tsup-dts-rollup.mjs';
|
|
14
|
+
export { QueryKeyCreatorResult } from './_tsup-dts-rollup.mjs';
|
|
15
|
+
export { QueryHelpers } from './_tsup-dts-rollup.mjs';
|
|
16
|
+
export { InfiniteQueryOptions } from './_tsup-dts-rollup.mjs';
|
|
17
|
+
export { ClientQueryArgs } from './_tsup-dts-rollup.mjs';
|
|
18
|
+
export { ClientQueryUrlParamsArgs } from './_tsup-dts-rollup.mjs';
|
|
22
19
|
export { BaseQueryParams } from './_tsup-dts-rollup.mjs';
|
|
23
|
-
export { BaseMutationParams } from './_tsup-dts-rollup.mjs';
|
|
24
20
|
export { BaseQueryArgs } from './_tsup-dts-rollup.mjs';
|
|
21
|
+
export { MutationArgs } from './_tsup-dts-rollup.mjs';
|
|
22
|
+
export { MutationHelpers } from './_tsup-dts-rollup.mjs';
|
|
23
|
+
export { MutationParams } from './_tsup-dts-rollup.mjs';
|
|
24
|
+
export { ClientMutationArgs } from './_tsup-dts-rollup.mjs';
|
|
25
|
+
export { BaseMutationParams } from './_tsup-dts-rollup.mjs';
|
|
25
26
|
export { BaseMutationArgs } from './_tsup-dts-rollup.mjs';
|
|
26
|
-
export {
|
|
27
|
+
export { EndpointHelper } from './_tsup-dts-rollup.mjs';
|
|
28
|
+
export { ClientEndpointHelper } from './_tsup-dts-rollup.mjs';
|
|
29
|
+
export { ClientInstance } from './_tsup-dts-rollup.mjs';
|
|
30
|
+
export { declareClient } from './_tsup-dts-rollup.mjs';
|
|
31
|
+
export { QueryConfig } from './_tsup-dts-rollup.mjs';
|
|
32
|
+
export { InfiniteQueryConfig } from './_tsup-dts-rollup.mjs';
|
|
33
|
+
export { MutationConfig } from './_tsup-dts-rollup.mjs';
|
package/lib/index.d.ts
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
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
1
|
export { makeQueryOptions } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { makeInfiniteQueryOptions } from './_tsup-dts-rollup.js';
|
|
3
|
+
export { makeMutation } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { createQueryKey } from './_tsup-dts-rollup.js';
|
|
5
|
+
export { queryKeyCreator } from './_tsup-dts-rollup.js';
|
|
6
|
+
export { createMutationKey } from './_tsup-dts-rollup.js';
|
|
7
|
+
export { mutationKeyCreator } from './_tsup-dts-rollup.js';
|
|
19
8
|
export { Split } from './_tsup-dts-rollup.js';
|
|
20
9
|
export { ProcessResponseFunction } from './_tsup-dts-rollup.js';
|
|
21
10
|
export { ClientOptions } from './_tsup-dts-rollup.js';
|
|
11
|
+
export { QueryArgs } from './_tsup-dts-rollup.js';
|
|
12
|
+
export { QueryUrlParamsArgs } from './_tsup-dts-rollup.js';
|
|
13
|
+
export { QueryParams } from './_tsup-dts-rollup.js';
|
|
14
|
+
export { QueryKeyCreatorResult } from './_tsup-dts-rollup.js';
|
|
15
|
+
export { QueryHelpers } from './_tsup-dts-rollup.js';
|
|
16
|
+
export { InfiniteQueryOptions } from './_tsup-dts-rollup.js';
|
|
17
|
+
export { ClientQueryArgs } from './_tsup-dts-rollup.js';
|
|
18
|
+
export { ClientQueryUrlParamsArgs } from './_tsup-dts-rollup.js';
|
|
22
19
|
export { BaseQueryParams } from './_tsup-dts-rollup.js';
|
|
23
|
-
export { BaseMutationParams } from './_tsup-dts-rollup.js';
|
|
24
20
|
export { BaseQueryArgs } from './_tsup-dts-rollup.js';
|
|
21
|
+
export { MutationArgs } from './_tsup-dts-rollup.js';
|
|
22
|
+
export { MutationHelpers } from './_tsup-dts-rollup.js';
|
|
23
|
+
export { MutationParams } from './_tsup-dts-rollup.js';
|
|
24
|
+
export { ClientMutationArgs } from './_tsup-dts-rollup.js';
|
|
25
|
+
export { BaseMutationParams } from './_tsup-dts-rollup.js';
|
|
25
26
|
export { BaseMutationArgs } from './_tsup-dts-rollup.js';
|
|
26
|
-
export {
|
|
27
|
+
export { EndpointHelper } from './_tsup-dts-rollup.js';
|
|
28
|
+
export { ClientEndpointHelper } from './_tsup-dts-rollup.js';
|
|
29
|
+
export { ClientInstance } from './_tsup-dts-rollup.js';
|
|
30
|
+
export { declareClient } from './_tsup-dts-rollup.js';
|
|
31
|
+
export { QueryConfig } from './_tsup-dts-rollup.js';
|
|
32
|
+
export { InfiniteQueryConfig } from './_tsup-dts-rollup.js';
|
|
33
|
+
export { MutationConfig } from './_tsup-dts-rollup.js';
|
package/lib/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var builder = require('@navios/builder');
|
|
4
4
|
var reactQuery = require('@tanstack/react-query');
|
|
5
5
|
|
|
6
|
-
// src/
|
|
7
|
-
function
|
|
6
|
+
// src/query/key-creator.mts
|
|
7
|
+
function createQueryKey(config, options, _isInfinite) {
|
|
8
8
|
const url = config.url;
|
|
9
9
|
const urlParts = url.split("/").filter(Boolean);
|
|
10
10
|
return {
|
|
@@ -42,23 +42,58 @@ function queryKeyCreator(config, options, isInfinite) {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
var queryKeyCreator = createQueryKey;
|
|
46
|
+
function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
47
|
+
const config = endpoint.config;
|
|
48
|
+
const queryKey = createQueryKey(config, options);
|
|
49
|
+
const processResponse = options.processResponse;
|
|
50
|
+
const result = (params) => {
|
|
51
|
+
return reactQuery.queryOptions({
|
|
52
|
+
queryKey: queryKey.dataTag(params),
|
|
53
|
+
queryFn: async ({ signal }) => {
|
|
54
|
+
let result2;
|
|
55
|
+
try {
|
|
56
|
+
result2 = await endpoint({
|
|
57
|
+
signal,
|
|
58
|
+
...params
|
|
59
|
+
});
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (options.onFail) {
|
|
62
|
+
options.onFail(err);
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
return processResponse(result2);
|
|
67
|
+
},
|
|
68
|
+
...baseQuery
|
|
69
|
+
});
|
|
53
70
|
};
|
|
71
|
+
result.queryKey = queryKey;
|
|
72
|
+
result.use = (params) => {
|
|
73
|
+
return reactQuery.useQuery(result(params));
|
|
74
|
+
};
|
|
75
|
+
result.useSuspense = (params) => {
|
|
76
|
+
return reactQuery.useSuspenseQuery(result(params));
|
|
77
|
+
};
|
|
78
|
+
result.invalidate = (queryClient, params) => {
|
|
79
|
+
return queryClient.invalidateQueries({
|
|
80
|
+
queryKey: result.queryKey.dataTag(params)
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
result.invalidateAll = (queryClient, params) => {
|
|
84
|
+
return queryClient.invalidateQueries({
|
|
85
|
+
queryKey: result.queryKey.filterKey(params),
|
|
86
|
+
exact: false
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
return result;
|
|
54
90
|
}
|
|
55
91
|
function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
56
92
|
const config = endpoint.config;
|
|
57
|
-
const queryKey =
|
|
93
|
+
const queryKey = createQueryKey(config, options);
|
|
58
94
|
const processResponse = options.processResponse;
|
|
59
95
|
const res = (params) => {
|
|
60
96
|
return reactQuery.infiniteQueryOptions({
|
|
61
|
-
// @ts-expect-error TS2322 We know the type
|
|
62
97
|
queryKey: queryKey.dataTag(params),
|
|
63
98
|
queryFn: async ({ signal, pageParam }) => {
|
|
64
99
|
let result;
|
|
@@ -81,6 +116,7 @@ function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
81
116
|
return processResponse(result);
|
|
82
117
|
},
|
|
83
118
|
getNextPageParam: options.getNextPageParam,
|
|
119
|
+
getPreviousPageParam: options.getPreviousPageParam,
|
|
84
120
|
initialPageParam: options.initialPageParam ?? config.querySchema.parse("params" in params ? params.params : {}),
|
|
85
121
|
...baseQuery
|
|
86
122
|
});
|
|
@@ -94,22 +130,31 @@ function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
94
130
|
};
|
|
95
131
|
res.invalidate = (queryClient, params) => {
|
|
96
132
|
return queryClient.invalidateQueries({
|
|
97
|
-
// @ts-expect-error We add additional function to the result
|
|
98
133
|
queryKey: res.queryKey.dataTag(params)
|
|
99
134
|
});
|
|
100
135
|
};
|
|
101
136
|
res.invalidateAll = (queryClient, params) => {
|
|
102
137
|
return queryClient.invalidateQueries({
|
|
103
|
-
// @ts-expect-error We add additional function to the result
|
|
104
138
|
queryKey: res.queryKey.filterKey(params),
|
|
105
139
|
exact: false
|
|
106
140
|
});
|
|
107
141
|
};
|
|
108
142
|
return res;
|
|
109
143
|
}
|
|
144
|
+
|
|
145
|
+
// src/mutation/key-creator.mts
|
|
146
|
+
function createMutationKey(config, options = {
|
|
147
|
+
processResponse: (data) => data
|
|
148
|
+
}) {
|
|
149
|
+
const queryKey = createQueryKey(config, options);
|
|
150
|
+
return (params) => {
|
|
151
|
+
return queryKey.filterKey(params);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
var mutationKeyCreator = createMutationKey;
|
|
110
155
|
function makeMutation(endpoint, options) {
|
|
111
156
|
const config = endpoint.config;
|
|
112
|
-
const mutationKey =
|
|
157
|
+
const mutationKey = createMutationKey(config, options);
|
|
113
158
|
const result = (keyParams) => {
|
|
114
159
|
const queryClient = reactQuery.useQueryClient();
|
|
115
160
|
const {
|
|
@@ -117,8 +162,8 @@ function makeMutation(endpoint, options) {
|
|
|
117
162
|
useContext,
|
|
118
163
|
onError,
|
|
119
164
|
onSuccess,
|
|
120
|
-
keyPrefix,
|
|
121
|
-
keySuffix,
|
|
165
|
+
keyPrefix: _keyPrefix,
|
|
166
|
+
keySuffix: _keySuffix,
|
|
122
167
|
processResponse,
|
|
123
168
|
...rest
|
|
124
169
|
} = options;
|
|
@@ -166,55 +211,8 @@ function makeMutation(endpoint, options) {
|
|
|
166
211
|
result.mutationKey = mutationKey;
|
|
167
212
|
return result;
|
|
168
213
|
}
|
|
169
|
-
function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
170
|
-
const config = endpoint.config;
|
|
171
|
-
const queryKey = queryKeyCreator(config, options);
|
|
172
|
-
const processResponse = options.processResponse;
|
|
173
|
-
const result = (params) => {
|
|
174
|
-
return reactQuery.queryOptions({
|
|
175
|
-
queryKey: queryKey.dataTag(params),
|
|
176
|
-
queryFn: async ({ signal }) => {
|
|
177
|
-
let result2;
|
|
178
|
-
try {
|
|
179
|
-
result2 = await endpoint({
|
|
180
|
-
signal,
|
|
181
|
-
...params
|
|
182
|
-
});
|
|
183
|
-
} catch (err) {
|
|
184
|
-
if (options.onFail) {
|
|
185
|
-
options.onFail(err);
|
|
186
|
-
}
|
|
187
|
-
throw err;
|
|
188
|
-
}
|
|
189
|
-
return processResponse(result2);
|
|
190
|
-
},
|
|
191
|
-
...baseQuery
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
result.queryKey = queryKey;
|
|
195
|
-
result.use = (params) => {
|
|
196
|
-
return reactQuery.useQuery(result(params));
|
|
197
|
-
};
|
|
198
|
-
result.useSuspense = (params) => {
|
|
199
|
-
return reactQuery.useSuspenseQuery(result(params));
|
|
200
|
-
};
|
|
201
|
-
result.invalidate = (queryClient, params) => {
|
|
202
|
-
return queryClient.invalidateQueries({
|
|
203
|
-
// @ts-expect-error We add additional function to the result
|
|
204
|
-
queryKey: result.queryKey.dataTag(params)
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
result.invalidateAll = (queryClient, params) => {
|
|
208
|
-
return queryClient.invalidateQueries({
|
|
209
|
-
// @ts-expect-error We add additional function to the result
|
|
210
|
-
queryKey: result.queryKey.filterKey(params),
|
|
211
|
-
exact: false
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
214
|
|
|
217
|
-
// src/declare-client.mts
|
|
215
|
+
// src/client/declare-client.mts
|
|
218
216
|
function declareClient({
|
|
219
217
|
api,
|
|
220
218
|
defaults = {}
|
|
@@ -225,6 +223,7 @@ function declareClient({
|
|
|
225
223
|
method: config.method,
|
|
226
224
|
url: config.url,
|
|
227
225
|
querySchema: config.querySchema,
|
|
226
|
+
requestSchema: config.requestSchema,
|
|
228
227
|
responseSchema: config.responseSchema
|
|
229
228
|
});
|
|
230
229
|
const queryOptions2 = makeQueryOptions(endpoint, {
|
|
@@ -246,6 +245,7 @@ function declareClient({
|
|
|
246
245
|
method: config.method,
|
|
247
246
|
url: config.url,
|
|
248
247
|
querySchema: config.querySchema,
|
|
248
|
+
requestSchema: config.requestSchema,
|
|
249
249
|
responseSchema: config.responseSchema
|
|
250
250
|
});
|
|
251
251
|
const infiniteQueryOptions2 = makeInfiniteQueryOptions(endpoint, {
|
|
@@ -299,6 +299,28 @@ function declareClient({
|
|
|
299
299
|
...defaults
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
|
+
function multipartMutation(config) {
|
|
303
|
+
const endpoint = api.declareMultipart({
|
|
304
|
+
// @ts-expect-error we accept only specific methods
|
|
305
|
+
method: config.method,
|
|
306
|
+
url: config.url,
|
|
307
|
+
querySchema: config.querySchema,
|
|
308
|
+
requestSchema: config.requestSchema,
|
|
309
|
+
responseSchema: config.responseSchema
|
|
310
|
+
});
|
|
311
|
+
const useMutation2 = makeMutation(endpoint, {
|
|
312
|
+
processResponse: config.processResponse ?? ((data) => data),
|
|
313
|
+
useContext: config.useContext,
|
|
314
|
+
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
315
|
+
onSuccess: config.onSuccess,
|
|
316
|
+
// @ts-expect-error We forgot about the DELETE method in original makeMutation
|
|
317
|
+
onError: config.onError,
|
|
318
|
+
useKey: config.useKey,
|
|
319
|
+
...defaults
|
|
320
|
+
});
|
|
321
|
+
useMutation2.endpoint = endpoint;
|
|
322
|
+
return useMutation2;
|
|
323
|
+
}
|
|
302
324
|
return {
|
|
303
325
|
// @ts-expect-error We simplified types here
|
|
304
326
|
query,
|
|
@@ -311,10 +333,14 @@ function declareClient({
|
|
|
311
333
|
// @ts-expect-error We simplified types here
|
|
312
334
|
mutation,
|
|
313
335
|
// @ts-expect-error We simplified types here
|
|
314
|
-
mutationFromEndpoint
|
|
336
|
+
mutationFromEndpoint,
|
|
337
|
+
// @ts-expect-error We simplified types here
|
|
338
|
+
multipartMutation
|
|
315
339
|
};
|
|
316
340
|
}
|
|
317
341
|
|
|
342
|
+
exports.createMutationKey = createMutationKey;
|
|
343
|
+
exports.createQueryKey = createQueryKey;
|
|
318
344
|
exports.declareClient = declareClient;
|
|
319
345
|
exports.makeInfiniteQueryOptions = makeInfiniteQueryOptions;
|
|
320
346
|
exports.makeMutation = makeMutation;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/query-key-creator.mts","../src/utils/mutation-key.creator.mts","../src/make-infinite-query-options.mts","../src/make-mutation.mts","../src/make-query-options.mts","../src/declare-client.mts"],"names":["bindUrlParams","infiniteQueryOptions","useInfiniteQuery","useSuspenseInfiniteQuery","useQueryClient","useMutation","useIsMutating","queryOptions","result","useQuery","useSuspenseQuery"],"mappings":";;;;;;AAqDO,SAAS,eAAA,CAOd,MACA,EAAA,OAAA,EACA,UASA,EAAA;AACA,EAAA,MAAM,MAAM,MAAO,CAAA,GAAA;AACnB,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A,MACpB,eAAe,MAAO,CAAA,aAAA;AAAA,MACtB,gBAAgB,MAAO,CAAA;AAAA,KACxB,CAAA;AAED,IAAMI,MAAAA,YAAAA,GAAc,aAAa,QAAU,EAAA;AAAA,MACzC,eAAiB,EAAA,MAAA,CAAO,eAAoB,KAAA,CAAC,IAAS,KAAA,IAAA,CAAA;AAAA,MACtD,YAAY,MAAO,CAAA,UAAA;AAAA;AAAA,MAEnB,WAAW,MAAO,CAAA,SAAA;AAAA;AAAA,MAElB,SAAS,MAAO,CAAA,OAAA;AAAA,MAChB,QAAQ,MAAO,CAAA,MAAA;AAAA,MACf,GAAG;AAAA,KACJ,CAAA;AAGD,IAAAA,aAAY,QAAW,GAAA,QAAA;AACvB,IAAOA,OAAAA,YAAAA;AAAA;AAGT,EAAS,SAAA,oBAAA,CACP,UACA,OAgBA,EAAA;AACA,IAAA,OAAO,aAAa,QAAU,EAAA;AAAA,MAC5B,iBAAiB,OAAQ,CAAA,eAAA;AAAA,MACzB,YAAY,OAAQ,CAAA,UAAA;AAAA,MACpB,WAAW,OAAQ,CAAA,SAAA;AAAA;AAAA,MAEnB,SAAS,OAAQ,CAAA,OAAA;AAAA,MACjB,GAAG;AAAA,KACJ,CAAA;AAAA;AAGH,EAAO,OAAA;AAAA;AAAA,IAEL,KAAA;AAAA;AAAA,IAEA,iBAAA;AAAA;AAAA,IAEA,aAAA;AAAA;AAAA,IAEA,yBAAA;AAAA;AAAA,IAEA,QAAA;AAAA;AAAA,IAEA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type {\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { DataTag, InfiniteData } from '@tanstack/react-query'\nimport type { AnyZodObject, z } from 'zod'\n\nimport { bindUrlParams } from '@navios/builder'\n\nimport type { BaseQueryParams } from '../types.mjs'\n\ntype Split<S extends string, D extends string> = string extends S\n ? string[]\n : S extends ''\n ? []\n : S extends `${infer T}${D}${infer U}`\n ? [T, ...Split<U, D>]\n : [S]\n\nexport type QueryKeyCreatorResult<\n QuerySchema = undefined,\n Url extends string = string,\n Result = unknown,\n IsInfinite extends boolean = false,\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n> = {\n template: Split<Url, '/'>\n dataTag: (\n params: (HasParams extends true ? { urlParams: UrlParams<Url> } : {}) &\n (QuerySchema extends AnyZodObject\n ? { params: z.input<QuerySchema> }\n : {}),\n ) => DataTag<\n Split<Url, '/'>,\n IsInfinite extends true ? InfiniteData<Result> : Result,\n Error\n >\n filterKey: (\n params: HasParams extends true ? { urlParams: UrlParams<Url> } : {},\n ) => DataTag<\n Split<Url, '/'>,\n IsInfinite extends true ? InfiniteData<Result> : Result,\n Error\n >\n bindToUrl: (\n params: (HasParams extends true ? { urlParams: UrlParams<Url> } : {}) &\n (QuerySchema extends AnyZodObject\n ? { params: z.infer<QuerySchema> }\n : {}),\n ) => string\n}\n\nexport function queryKeyCreator<\n Config extends AnyEndpointConfig,\n Options extends BaseQueryParams<Config>,\n IsInfinite extends boolean,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options,\n isInfinite: IsInfinite,\n): QueryKeyCreatorResult<\n Config['querySchema'],\n Url,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? Result\n : never,\n IsInfinite,\n HasParams\n> {\n const url = config.url as Url\n const urlParts = url.split('/').filter(Boolean) as Split<Url, '/'>\n return {\n template: urlParts,\n // @ts-expect-error We have correct types in return type\n dataTag: (params) => {\n const queryParams =\n params && 'querySchema' in config && 'params' in params\n ? config.querySchema?.parse(params.params)\n : []\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n queryParams ?? [],\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n // @ts-expect-error We have correct types in return type\n filterKey: (params) => {\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n\n bindToUrl: (params) => {\n return bindUrlParams<Url>(url, params ?? ({} as any))\n },\n }\n}\n","import type {\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { DataTag } from '@tanstack/react-query'\n\nimport type { BaseQueryParams } from '../types.mjs'\n\nimport { queryKeyCreator } from './query-key-creator.mjs'\n\n/**\n * Creates a mutation key for a given endpoint configuration and options.\n *\n * @param {config: Config } config - The endpoint object containing the configuration.\n * @param {Options} [options] - Optional query parameters with a default `processResponse` function that processes the response data.\n *\n * @returns {Object} An object containing the `mutationKey` function.\n *\n * The `mutationKey` function generates a mutation key based on the provided parameters:\n * - If the URL has parameters (`HasParams` is `true`), it expects an object with `urlParams`.\n * - The return type of the `mutationKey` function depends on the `processResponse` function in `options`.\n * If `processResponse` is defined, the return type is a `DataTag` containing the processed result and an error type.\n *\n * @example Example usage:\n * ```typescript\n * const createMutationKey = mutationKeyCreator(endpoint.config);\n * const mutationKey = createMutationKey({ urlParams: { id: 123 } });\n * ```\n *\n * @example Advanced usage:\n * ```ts\n * const createMutationKey = mutationKeyCreator(endpoint.config, {\n * processResponse: (data) => {\n * if (!data.success) {\n * throw new Error(data.message);\n * }\n * return data.data;\n * },\n * });\n * // We create a mutation that will be shared across the project for all passed userId\n * const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });\n */\nexport function mutationKeyCreator<\n Config extends AnyEndpointConfig,\n Options extends BaseQueryParams<Config>,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options = {\n processResponse: (data) => data,\n } as Options,\n): (\n params: HasParams extends true ? { urlParams: UrlParams<Url> } : {},\n) => Options['processResponse'] extends (...args: any[]) => infer Result\n ? DataTag<[Config['url']], Result, Error>\n : never {\n const queryKey = queryKeyCreator(config, options, false)\n\n // @ts-expect-error We have correct types in return type\n return (params) => {\n return queryKey.filterKey(params)\n }\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n UrlParams,\n} from '@navios/builder'\nimport type {\n InfiniteData,\n QueryClient,\n UseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryOptions,\n} from '@tanstack/react-query'\nimport type { z } from 'zod'\n\nimport {\n infiniteQueryOptions,\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport type { InfiniteQueryOptions } from './types.mjs'\nimport type { ClientQueryArgs } from './types/index.mjs'\n\nimport { queryKeyCreator } from './utils/query-key-creator.mjs'\n\nexport function makeInfiniteQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends InfiniteQueryOptions<Config>,\n BaseQuery extends Omit<\n UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'placeholderData'\n | 'throwOnError'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = queryKeyCreator(config, options, true)\n\n const processResponse = options.processResponse\n const res = (\n params: ClientQueryArgs,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseInfiniteQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T\n ? T\n : InfiniteData<Result>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return infiniteQueryOptions({\n // @ts-expect-error TS2322 We know the type\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal, pageParam }) => {\n let result\n try {\n result = await endpoint({\n signal,\n // @ts-expect-error TS2345 We bind the url params only if the url has params\n urlParams: params.urlParams as z.infer<UrlParams<Config['url']>>,\n params: {\n ...('params' in params ? params.params : {}),\n ...(pageParam as z.infer<Config['querySchema']>),\n },\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result)\n },\n getNextPageParam: options.getNextPageParam,\n initialPageParam:\n options.initialPageParam ??\n config.querySchema.parse('params' in params ? params.params : {}),\n ...baseQuery,\n })\n }\n res.queryKey = queryKey\n\n res.use = (params: ClientQueryArgs) => {\n return useInfiniteQuery(res(params))\n }\n\n res.useSuspense = (params: ClientQueryArgs) => {\n return useSuspenseInfiniteQuery(res(params))\n }\n\n res.invalidate = (queryClient: QueryClient, params: ClientQueryArgs) => {\n return queryClient.invalidateQueries({\n // @ts-expect-error We add additional function to the result\n queryKey: res.queryKey.dataTag(params),\n })\n }\n\n res.invalidateAll = (queryClient: QueryClient, params: ClientQueryArgs) => {\n return queryClient.invalidateQueries({\n // @ts-expect-error We add additional function to the result\n queryKey: res.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return res\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { UseMutationResult } from '@tanstack/react-query'\nimport type { z } from 'zod'\n\nimport {\n useIsMutating,\n useMutation,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { BaseMutationArgs, BaseMutationParams } from './types.mjs'\n\nimport { mutationKeyCreator } from './index.mjs'\n\nexport function makeMutation<\n Config extends AnyEndpointConfig,\n TData = unknown,\n TVariables extends BaseMutationArgs<Config> = BaseMutationArgs<Config>,\n TResponse = z.output<Config['responseSchema']>,\n TContext = unknown,\n UseKey extends boolean = false,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: BaseMutationParams<\n Config,\n TData,\n TVariables,\n TResponse,\n TContext,\n UseKey\n >,\n) {\n const config = endpoint.config\n\n const mutationKey = mutationKeyCreator(config, options)\n const result = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): UseMutationResult<TData, Error, BaseMutationArgs<Config>> => {\n const queryClient = useQueryClient()\n const {\n useKey,\n useContext,\n onError,\n onSuccess,\n keyPrefix,\n keySuffix,\n processResponse,\n ...rest\n } = options\n\n const context = useContext?.() as TContext\n\n // @ts-expect-error The types match\n return useMutation(\n {\n ...rest,\n mutationKey: useKey\n ? mutationKey({\n urlParams: keyParams,\n })\n : undefined,\n scope: useKey\n ? {\n id: JSON.stringify(\n mutationKey({\n urlParams: keyParams,\n }),\n ),\n }\n : undefined,\n async mutationFn(params: TVariables) {\n const response = await endpoint(params)\n\n return processResponse(response) as TData\n },\n onSuccess: onSuccess\n ? (data: TData, variables: TVariables) => {\n return onSuccess?.(queryClient, data, variables, context)\n }\n : undefined,\n onError: onError\n ? (err: Error, variables: TVariables) => {\n return onError?.(queryClient, err, variables, context)\n }\n : undefined,\n },\n queryClient,\n )\n }\n result.useIsMutating = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): boolean => {\n if (!options.useKey) {\n throw new Error(\n 'useIsMutating can only be used when useKey is set to true',\n )\n }\n const isMutating = useIsMutating({\n mutationKey: mutationKey({\n urlParams: keyParams,\n }),\n })\n return isMutating > 0\n }\n result.mutationKey = mutationKey\n\n return result\n}\n","import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder'\nimport type {\n DataTag,\n QueryClient,\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from '@tanstack/react-query'\n\nimport { queryOptions, useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport type { BaseQueryArgs, BaseQueryParams } from './types.mjs'\nimport type { ClientQueryArgs } from './types/index.mjs'\n\nimport { queryKeyCreator } from './utils/query-key-creator.mjs'\n\ntype Split<S extends string, D extends string> = string extends S\n ? string[]\n : S extends ''\n ? []\n : S extends `${infer T}${D}${infer U}`\n ? [T, ...Split<U, D>]\n : [S]\n\nexport function makeQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends BaseQueryParams<Config>,\n BaseQuery extends Omit<\n UseQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'enabled'\n | 'throwOnError'\n | 'placeholderData'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n // Let's hack the url to be a string for now\n const queryKey = queryKeyCreator(config, options, false)\n const processResponse = options.processResponse\n\n const result = (\n params: BaseQueryArgs<Config>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T ? T : Result,\n DataTag<Split<Config['url'], '/'>, Result, Error>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return queryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal }) => {\n let result\n try {\n result = await endpoint({\n signal,\n ...params,\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result)\n },\n ...baseQuery,\n })\n }\n result.queryKey = queryKey\n result.use = (params: ClientQueryArgs) => {\n // @ts-expect-error We add additional function to the result\n return useQuery(result(params))\n }\n\n result.useSuspense = (params: ClientQueryArgs) => {\n // @ts-expect-error We add additional function to the result\n return useSuspenseQuery(result(params))\n }\n\n result.invalidate = (queryClient: QueryClient, params: ClientQueryArgs) => {\n return queryClient.invalidateQueries({\n // @ts-expect-error We add additional function to the result\n queryKey: result.queryKey.dataTag(params),\n })\n }\n\n result.invalidateAll = (\n queryClient: QueryClient,\n params: ClientQueryArgs,\n ) => {\n return queryClient.invalidateQueries({\n // @ts-expect-error We add additional function to the result\n queryKey: result.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n HttpMethod,\n Util_FlatObject,\n} from '@navios/builder'\nimport type { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport type { AnyZodObject, z, ZodType } from 'zod'\n\nimport type { ClientOptions, ProcessResponseFunction } from './types.mjs'\nimport type { ClientInstance, ClientMutationArgs } from './types/index.mjs'\n\nimport { makeInfiniteQueryOptions } from './make-infinite-query-options.mjs'\nimport { makeMutation } from './make-mutation.mjs'\nimport { makeQueryOptions } from './make-query-options.mjs'\n\nexport interface ClientEndpointDefinition<\n Method = HttpMethod,\n Url = string,\n QuerySchema = unknown,\n Response = ZodType,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n}\n\nexport interface ClientQueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema = AnyZodObject,\n Response extends ZodType = ZodType,\n Result = z.output<Response>,\n> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {\n processResponse?: (data: z.output<Response>) => Result\n}\n\nexport type ClientInfiniteQueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema extends AnyZodObject = AnyZodObject,\n Response extends ZodType = ZodType,\n PageResult = z.output<Response>,\n Result = InfiniteData<PageResult>,\n> = Required<ClientEndpointDefinition<Method, Url, QuerySchema, Response>> & {\n processResponse?: (data: z.output<Response>) => PageResult\n select?: (data: InfiniteData<PageResult>) => Result\n getNextPageParam: (\n lastPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema> | undefined\n getPreviousPageParam?: (\n firstPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema>\n initialPageParam?: z.input<QuerySchema>\n}\n\nexport interface ClientMutationDataConfig<\n Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' =\n | 'POST'\n | 'PUT'\n | 'PATCH'\n | 'DELETE',\n Url extends string = string,\n RequestSchema = Method extends 'DELETE' ? never : AnyZodObject,\n QuerySchema = unknown,\n Response extends ZodType = ZodType,\n ReqResult = z.output<Response>,\n Result = unknown,\n Context = unknown,\n UseKey extends boolean = false,\n> extends ClientEndpointDefinition<Method, Url, QuerySchema, Response> {\n requestSchema?: RequestSchema\n processResponse: ProcessResponseFunction<Result, ReqResult>\n useContext?: () => Context\n onSuccess?: (\n queryClient: QueryClient,\n data: NoInfer<Result>,\n variables: Util_FlatObject<\n ClientMutationArgs<Url, RequestSchema, QuerySchema>\n >,\n context: Context,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: Util_FlatObject<\n ClientMutationArgs<Url, RequestSchema, QuerySchema>\n >,\n context: Context,\n ) => void | Promise<void>\n useKey?: UseKey\n}\n\nexport function declareClient<Options extends ClientOptions>({\n api,\n defaults = {},\n}: Options): ClientInstance {\n function query(config: ClientQueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n responseSchema: config.responseSchema,\n })\n\n const queryOptions = makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n })\n // @ts-expect-error We attach the endpoint to the queryOptions\n queryOptions.endpoint = endpoint\n return queryOptions\n }\n\n function queryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options?: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n },\n ) {\n return makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n })\n }\n\n function infiniteQuery(config: ClientInfiniteQueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n responseSchema: config.responseSchema,\n })\n const infiniteQueryOptions = makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n getNextPageParam: config.getNextPageParam,\n getPreviousPageParam: config.getPreviousPageParam,\n initialPageParam: config.initialPageParam,\n })\n\n // @ts-expect-error We attach the endpoint to the infiniteQueryOptions\n infiniteQueryOptions.endpoint = endpoint\n return infiniteQueryOptions\n }\n\n function infiniteQueryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n getNextPageParam: (\n lastPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']> | undefined\n getPreviousPageParam?: (\n firstPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']>\n initialPageParam?: z.input<AnyEndpointConfig['querySchema']>\n },\n ) {\n return makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options?.getPreviousPageParam,\n initialPageParam: options?.initialPageParam,\n })\n }\n\n function mutation(config: ClientMutationDataConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n function mutationFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse: ProcessResponseFunction\n useContext?: () => unknown\n onSuccess?: (\n queryClient: QueryClient,\n data: unknown,\n variables: Util_FlatObject<ClientMutationArgs>,\n context: unknown,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: Util_FlatObject<ClientMutationArgs>,\n context: unknown,\n ) => void | Promise<void>\n },\n ) {\n return makeMutation(endpoint, {\n processResponse: options.processResponse,\n useContext: options.useContext,\n onSuccess: options.onSuccess,\n // @ts-expect-error simplify types here\n onError: options.onError,\n ...defaults,\n })\n }\n\n return {\n // @ts-expect-error We simplified types here\n query,\n // @ts-expect-error We simplified types here\n queryFromEndpoint,\n // @ts-expect-error We simplified types here\n infiniteQuery,\n // @ts-expect-error We simplified types here\n infiniteQueryFromEndpoint,\n // @ts-expect-error We simplified types here\n mutation,\n // @ts-expect-error We simplified types here\n mutationFromEndpoint,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/query/key-creator.mts","../src/query/make-options.mts","../src/query/make-infinite-options.mts","../src/mutation/key-creator.mts","../src/mutation/make-hook.mts","../src/client/declare-client.mts"],"names":["bindUrlParams","queryOptions","result","useQuery","useSuspenseQuery","infiniteQueryOptions","useInfiniteQuery","useSuspenseInfiniteQuery","useQueryClient","useMutation","useIsMutating"],"mappings":";;;;;;AAmBO,SAAS,cAAA,CAOd,MAAA,EACA,OAAA,EACA,WAAA,EASA;AACA,EAAA,MAAM,MAAM,MAAA,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AAK,MAAA,CAAO,GAAA;AAAA,MACZ,aAAa,MAAA,CAAO,WAAA;AAAA,MACpB,eAAe,MAAA,CAAO,aAAA;AAAA,MACtB,gBAAgB,MAAA,CAAO;AAAA,KACxB,CAAA;AAED,IAAA,MAAMA,YAAAA,GAAc,aAAa,QAAA,EAAU;AAAA,MACzC,eAAA,EAAiB,MAAA,CAAO,eAAA,KAAoB,CAAC,IAAA,KAAS,IAAA,CAAA;AAAA,MACtD,YAAY,MAAA,CAAO,UAAA;AAAA;AAAA,MAEnB,WAAW,MAAA,CAAO,SAAA;AAAA;AAAA,MAElB,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,GAAG;AAAA,KACJ,CAAA;AAGD,IAAAA,aAAY,QAAA,GAAW,QAAA;AACvB,IAAA,OAAOA,YAAAA;AAAA,EACT;AAEA,EAAA,OAAO;AAAA;AAAA,IAEL,KAAA;AAAA;AAAA,IAEA,iBAAA;AAAA;AAAA,IAEA,aAAA;AAAA;AAAA,IAEA,yBAAA;AAAA;AAAA,IAEA,QAAA;AAAA;AAAA,IAEA,oBAAA;AAAA;AAAA,IAEA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { AnyEndpointConfig, UrlHasParams } from '@navios/builder'\nimport type { DataTag, InfiniteData } from '@tanstack/react-query'\n\nimport { bindUrlParams } from '@navios/builder'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryKeyCreatorResult, QueryParams } from './types.mjs'\n\n/**\n * Creates a query key generator for a given endpoint configuration.\n *\n * The returned object provides methods to generate query keys that can be used\n * with TanStack Query for caching, invalidation, and data tagging.\n *\n * @param config - The endpoint configuration\n * @param options - Query parameters including processResponse and key prefix/suffix\n * @param isInfinite - Whether this is for an infinite query\n * @returns An object with methods to generate query keys\n */\nexport function createQueryKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n IsInfinite extends boolean,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options,\n _isInfinite: IsInfinite,\n): QueryKeyCreatorResult<\n Config['querySchema'],\n Url,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? Result\n : never,\n IsInfinite,\n HasParams\n> {\n const url = config.url as Url\n const urlParts = url.split('/').filter(Boolean) as Split<Url, '/'>\n return {\n template: urlParts,\n // @ts-expect-error We have correct types in return type\n dataTag: (params) => {\n const queryParams =\n params && 'querySchema' in config && 'params' in params\n ? config.querySchema?.parse(params.params)\n : []\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n queryParams ?? [],\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n // @ts-expect-error We have correct types in return type\n filterKey: (params) => {\n return [\n ...(options.keyPrefix ?? []),\n ...urlParts.map((part) =>\n part.startsWith('$')\n ? // @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params\n params.urlParams[part.slice(1)].toString()\n : part,\n ),\n ...(options.keySuffix ?? []),\n ] as unknown as DataTag<\n Split<Url, '/'>,\n Options['processResponse'] extends (...args: any[]) => infer Result\n ? IsInfinite extends true\n ? InfiniteData<Result>\n : Result\n : never,\n Error\n >\n },\n\n bindToUrl: (params) => {\n return bindUrlParams<Url>(url, params ?? ({} as never))\n },\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createQueryKey instead */\nexport const queryKeyCreator = createQueryKey\n","import type { AbstractEndpoint, AnyEndpointConfig } from '@navios/builder'\nimport type {\n DataTag,\n QueryClient,\n UseQueryOptions,\n UseSuspenseQueryOptions,\n} from '@tanstack/react-query'\n\nimport { queryOptions, useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport type { Split } from '../common/types.mjs'\nimport type { QueryArgs, QueryParams } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create query options for\n * @param options - Query configuration including processResponse\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates query options with attached helpers\n */\nexport function makeQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n BaseQuery extends Omit<\n UseQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'enabled'\n | 'throwOnError'\n | 'placeholderData'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, false)\n const processResponse = options.processResponse\n\n const result = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T ? T : Result,\n DataTag<Split<Config['url'], '/'>, Result, Error>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return queryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n ...params,\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n ...baseQuery,\n })\n }\n result.queryKey = queryKey\n result.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useQuery(result(params))\n }\n\n result.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseQuery(result(params))\n }\n\n result.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.dataTag(params),\n })\n }\n\n result.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: result.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n UrlParams,\n} from '@navios/builder'\nimport type {\n InfiniteData,\n QueryClient,\n UseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryOptions,\n} from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n infiniteQueryOptions,\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport type { InfiniteQueryOptions, QueryArgs } from './types.mjs'\n\nimport { createQueryKey } from './key-creator.mjs'\n\n/**\n * Creates infinite query options for a given endpoint.\n *\n * Returns a function that generates TanStack Query infinite options when called with params.\n * The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)\n *\n * @param endpoint - The navios endpoint to create infinite query options for\n * @param options - Infinite query configuration including processResponse and pagination params\n * @param baseQuery - Optional base query options to merge\n * @returns A function that generates infinite query options with attached helpers\n */\nexport function makeInfiniteQueryOptions<\n Config extends AnyEndpointConfig,\n Options extends InfiniteQueryOptions<Config>,\n BaseQuery extends Omit<\n UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>,\n | 'queryKey'\n | 'queryFn'\n | 'getNextPageParam'\n | 'initialPageParam'\n | 'placeholderData'\n | 'throwOnError'\n >,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: Options,\n baseQuery: BaseQuery = {} as BaseQuery,\n) {\n const config = endpoint.config\n const queryKey = createQueryKey(config, options, true)\n\n const processResponse = options.processResponse\n const res = (\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ): Options['processResponse'] extends (...args: any[]) => infer Result\n ? UseSuspenseInfiniteQueryOptions<\n Result,\n Error,\n BaseQuery['select'] extends (...args: any[]) => infer T\n ? T\n : InfiniteData<Result>\n >\n : never => {\n // @ts-expect-error TS2322 We know that the processResponse is defined\n return infiniteQueryOptions({\n queryKey: queryKey.dataTag(params),\n queryFn: async ({ signal, pageParam }): Promise<ReturnType<Options['processResponse']>> => {\n let result\n try {\n result = await endpoint({\n signal,\n // @ts-expect-error TS2345 We bind the url params only if the url has params\n urlParams: params.urlParams as z.infer<UrlParams<Config['url']>>,\n params: {\n ...('params' in params ? params.params : {}),\n ...(pageParam as z.infer<Config['querySchema']>),\n },\n })\n } catch (err) {\n if (options.onFail) {\n options.onFail(err)\n }\n throw err\n }\n\n return processResponse(result) as ReturnType<Options['processResponse']>\n },\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options.getPreviousPageParam,\n initialPageParam:\n options.initialPageParam ??\n config.querySchema.parse('params' in params ? params.params : {}),\n ...baseQuery,\n })\n }\n res.queryKey = queryKey\n\n res.use = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useInfiniteQuery(res(params))\n }\n\n res.useSuspense = (params: QueryArgs<Config['url'], Config['querySchema']>) => {\n return useSuspenseInfiniteQuery(res(params))\n }\n\n res.invalidate = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.dataTag(params),\n })\n }\n\n res.invalidateAll = (\n queryClient: QueryClient,\n params: QueryArgs<Config['url'], Config['querySchema']>,\n ) => {\n return queryClient.invalidateQueries({\n queryKey: res.queryKey.filterKey(params),\n exact: false,\n })\n }\n\n return res\n}\n","import type {\n AnyEndpointConfig,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { DataTag } from '@tanstack/react-query'\n\nimport type { QueryParams } from '../query/types.mjs'\n\nimport { createQueryKey } from '../query/key-creator.mjs'\n\n/**\n * Creates a mutation key generator for a given endpoint configuration.\n *\n * @param config - The endpoint configuration\n * @param options - Optional query parameters with a default `processResponse` function\n * @returns A function that generates mutation keys\n *\n * @example Basic usage:\n * ```typescript\n * const createMutationKey = createMutationKey(endpoint.config);\n * const mutationKey = createMutationKey({ urlParams: { id: 123 } });\n * ```\n *\n * @example Advanced usage with processResponse:\n * ```ts\n * const createMutationKey = createMutationKey(endpoint.config, {\n * processResponse: (data) => {\n * if (!data.success) {\n * throw new Error(data.message);\n * }\n * return data.data;\n * },\n * });\n * // We create a mutation that will be shared across the project for all passed userId\n * const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });\n * ```\n */\nexport function createMutationKey<\n Config extends AnyEndpointConfig,\n Options extends QueryParams<Config>,\n Url extends Config['url'] = Config['url'],\n HasParams extends UrlHasParams<Url> = UrlHasParams<Url>,\n>(\n config: Config,\n options: Options = {\n processResponse: (data) => data,\n } as Options,\n): (\n params: HasParams extends true ? { urlParams: UrlParams<Url> } : {},\n) => Options['processResponse'] extends (...args: unknown[]) => infer Result\n ? DataTag<[Config['url']], Result, Error>\n : never {\n const queryKey = createQueryKey(config, options, false)\n\n // @ts-expect-error We have correct types in return type\n return (params) => {\n return queryKey.filterKey(params)\n }\n}\n\n// Legacy export for backwards compatibility\n/** @deprecated Use createMutationKey instead */\nexport const mutationKeyCreator = createMutationKey\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n NaviosZodRequest,\n UrlHasParams,\n UrlParams,\n} from '@navios/builder'\nimport type { UseMutationResult } from '@tanstack/react-query'\nimport type { z } from 'zod/v4'\n\nimport {\n useIsMutating,\n useMutation,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { MutationParams } from './types.mjs'\n\nimport { createMutationKey } from './key-creator.mjs'\n\n/**\n * Creates a mutation hook for a given endpoint.\n *\n * Returns a function that when called returns a TanStack Query mutation result.\n * The returned function also has helper methods attached (mutationKey, useIsMutating).\n *\n * @param endpoint - The navios endpoint to create a mutation hook for\n * @param options - Mutation configuration including processResponse and callbacks\n * @returns A hook function that returns mutation result with attached helpers\n */\nexport function makeMutation<\n Config extends AnyEndpointConfig,\n TData = unknown,\n TVariables extends NaviosZodRequest<Config> = NaviosZodRequest<Config>,\n TResponse = z.output<Config['responseSchema']>,\n TContext = unknown,\n UseKey extends boolean = false,\n>(\n endpoint: AbstractEndpoint<Config>,\n options: MutationParams<\n Config,\n TData,\n TVariables,\n TResponse,\n TContext,\n UseKey\n >,\n) {\n const config = endpoint.config\n\n const mutationKey = createMutationKey(config, options)\n const result = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): UseMutationResult<TData, Error, NaviosZodRequest<Config>> => {\n const queryClient = useQueryClient()\n const {\n useKey,\n useContext,\n onError,\n onSuccess,\n keyPrefix: _keyPrefix,\n keySuffix: _keySuffix,\n processResponse,\n ...rest\n } = options\n\n const context = useContext?.() as TContext\n\n // @ts-expect-error The types match\n return useMutation(\n {\n ...rest,\n mutationKey: useKey\n ? mutationKey({\n urlParams: keyParams,\n })\n : undefined,\n scope: useKey\n ? {\n id: JSON.stringify(\n mutationKey({\n urlParams: keyParams,\n }),\n ),\n }\n : undefined,\n async mutationFn(params: TVariables) {\n const response = await endpoint(params)\n\n return processResponse(response) as TData\n },\n onSuccess: onSuccess\n ? (data: TData, variables: TVariables) => {\n return onSuccess?.(queryClient, data, variables, context)\n }\n : undefined,\n onError: onError\n ? (err: Error, variables: TVariables) => {\n return onError?.(queryClient, err, variables, context)\n }\n : undefined,\n },\n queryClient,\n )\n }\n result.useIsMutating = (\n keyParams: UseKey extends true\n ? UrlHasParams<Config['url']> extends true\n ? UrlParams<Config['url']>\n : never\n : never,\n ): boolean => {\n if (!options.useKey) {\n throw new Error(\n 'useIsMutating can only be used when useKey is set to true',\n )\n }\n const isMutating = useIsMutating({\n mutationKey: mutationKey({\n urlParams: keyParams,\n }),\n })\n return isMutating > 0\n }\n result.mutationKey = mutationKey\n\n return result\n}\n","import type {\n AbstractEndpoint,\n AnyEndpointConfig,\n HttpMethod,\n} from '@navios/builder'\nimport type { InfiniteData, QueryClient } from '@tanstack/react-query'\nimport type { z, ZodObject, ZodType } from 'zod/v4'\n\nimport type { ClientOptions, ProcessResponseFunction } from '../common/types.mjs'\nimport type { MutationArgs } from '../mutation/types.mjs'\nimport type { ClientInstance } from './types.mjs'\n\nimport { makeMutation } from '../mutation/make-hook.mjs'\nimport { makeInfiniteQueryOptions } from '../query/make-infinite-options.mjs'\nimport { makeQueryOptions } from '../query/make-options.mjs'\n\n/**\n * Configuration for declaring a query endpoint.\n */\nexport interface QueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema = ZodObject,\n Response extends ZodType = ZodType,\n Result = z.output<Response>,\n RequestSchema = unknown,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => Result\n}\n\n/**\n * Configuration for declaring an infinite query endpoint.\n */\nexport type InfiniteQueryConfig<\n Method = HttpMethod,\n Url = string,\n QuerySchema extends ZodObject = ZodObject,\n Response extends ZodType = ZodType,\n PageResult = z.output<Response>,\n Result = InfiniteData<PageResult>,\n RequestSchema = unknown,\n> = {\n method: Method\n url: Url\n querySchema: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse?: (data: z.output<Response>) => PageResult\n select?: (data: InfiniteData<PageResult>) => Result\n getNextPageParam: (\n lastPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema> | undefined\n getPreviousPageParam?: (\n firstPage: PageResult,\n allPages: PageResult[],\n lastPageParam: z.infer<QuerySchema> | undefined,\n allPageParams: z.infer<QuerySchema>[] | undefined,\n ) => z.input<QuerySchema>\n initialPageParam?: z.input<QuerySchema>\n}\n\n/**\n * Configuration for declaring a mutation endpoint.\n */\nexport interface MutationConfig<\n Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' =\n | 'POST'\n | 'PUT'\n | 'PATCH'\n | 'DELETE',\n Url extends string = string,\n RequestSchema = Method extends 'DELETE' ? never : ZodObject,\n QuerySchema = unknown,\n Response extends ZodType = ZodType,\n ReqResult = z.output<Response>,\n Result = unknown,\n Context = unknown,\n UseKey extends boolean = false,\n> {\n method: Method\n url: Url\n querySchema?: QuerySchema\n responseSchema: Response\n requestSchema?: RequestSchema\n processResponse: ProcessResponseFunction<Result, ReqResult>\n useContext?: () => Context\n onSuccess?: (\n queryClient: QueryClient,\n data: NoInfer<Result>,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs<Url, RequestSchema, QuerySchema>,\n context: Context,\n ) => void | Promise<void>\n useKey?: UseKey\n}\n\n/**\n * Creates a client instance for making type-safe queries and mutations.\n *\n * @param options - Client configuration including the API builder and defaults\n * @returns A client instance with query, infiniteQuery, and mutation methods\n *\n * @example\n * ```typescript\n * const api = createBuilder({ baseUrl: '/api' });\n * const client = declareClient({ api });\n *\n * const getUser = client.query({\n * method: 'GET',\n * url: '/users/$id',\n * responseSchema: UserSchema,\n * });\n *\n * // In a component\n * const { data } = useSuspenseQuery(getUser({ urlParams: { id: '123' } }));\n * ```\n */\nexport function declareClient<Options extends ClientOptions>({\n api,\n defaults = {},\n}: Options): ClientInstance {\n function query(config: QueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const queryOptions = makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n })\n // @ts-expect-error We attach the endpoint to the queryOptions\n queryOptions.endpoint = endpoint\n return queryOptions\n }\n\n function queryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options?: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n },\n ) {\n return makeQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n })\n }\n\n function infiniteQuery(config: InfiniteQueryConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n const infiniteQueryOptions = makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: config.processResponse ?? ((data) => data),\n getNextPageParam: config.getNextPageParam,\n getPreviousPageParam: config.getPreviousPageParam,\n initialPageParam: config.initialPageParam,\n })\n\n // @ts-expect-error We attach the endpoint to the infiniteQueryOptions\n infiniteQueryOptions.endpoint = endpoint\n return infiniteQueryOptions\n }\n\n function infiniteQueryFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse?: (\n data: z.output<AnyEndpointConfig['responseSchema']>,\n ) => unknown\n getNextPageParam: (\n lastPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']> | undefined\n getPreviousPageParam?: (\n firstPage: z.infer<AnyEndpointConfig['responseSchema']>,\n allPages: z.infer<AnyEndpointConfig['responseSchema']>[],\n lastPageParam: z.infer<AnyEndpointConfig['querySchema']> | undefined,\n allPageParams: z.infer<AnyEndpointConfig['querySchema']>[] | undefined,\n ) => z.input<AnyEndpointConfig['querySchema']>\n initialPageParam?: z.input<AnyEndpointConfig['querySchema']>\n },\n ) {\n return makeInfiniteQueryOptions(endpoint, {\n ...defaults,\n processResponse: options?.processResponse ?? ((data) => data),\n getNextPageParam: options.getNextPageParam,\n getPreviousPageParam: options?.getPreviousPageParam,\n initialPageParam: options?.initialPageParam,\n })\n }\n\n function mutation(config: MutationConfig) {\n const endpoint = api.declareEndpoint({\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n function mutationFromEndpoint(\n endpoint: AbstractEndpoint<AnyEndpointConfig>,\n options: {\n processResponse: ProcessResponseFunction\n useContext?: () => unknown\n onSuccess?: (\n queryClient: QueryClient,\n data: unknown,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n onError?: (\n queryClient: QueryClient,\n error: Error,\n variables: MutationArgs,\n context: unknown,\n ) => void | Promise<void>\n },\n ) {\n return makeMutation(endpoint, {\n processResponse: options.processResponse,\n useContext: options.useContext,\n onSuccess: options.onSuccess,\n // @ts-expect-error simplify types here\n onError: options.onError,\n ...defaults,\n })\n }\n\n function multipartMutation(config: MutationConfig) {\n const endpoint = api.declareMultipart({\n // @ts-expect-error we accept only specific methods\n method: config.method,\n url: config.url,\n querySchema: config.querySchema,\n requestSchema: config.requestSchema,\n responseSchema: config.responseSchema,\n })\n\n const useMutation = makeMutation(endpoint, {\n processResponse: config.processResponse ?? ((data) => data),\n useContext: config.useContext,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onSuccess: config.onSuccess,\n // @ts-expect-error We forgot about the DELETE method in original makeMutation\n onError: config.onError,\n useKey: config.useKey,\n ...defaults,\n })\n\n // @ts-expect-error We attach the endpoint to the useMutation\n useMutation.endpoint = endpoint\n return useMutation\n }\n\n return {\n // @ts-expect-error We simplified types here\n query,\n // @ts-expect-error We simplified types here\n queryFromEndpoint,\n // @ts-expect-error We simplified types here\n infiniteQuery,\n // @ts-expect-error We simplified types here\n infiniteQueryFromEndpoint,\n // @ts-expect-error We simplified types here\n mutation,\n // @ts-expect-error We simplified types here\n mutationFromEndpoint,\n // @ts-expect-error We simplified types here\n multipartMutation,\n }\n}\n"]}
|