@navios/react-query 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +142 -41
- package/dist/src/client/declare-client.d.mts.map +1 -1
- package/dist/src/mutation/make-hook.d.mts +3 -1
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/index.cjs +412 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +961 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +961 -34
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +389 -350
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/project.json +2 -2
- package/src/__tests__/declare-client.spec.mts +2 -2
- package/src/__tests__/make-mutation.spec.mts +10 -9
- package/src/client/declare-client.mts +28 -6
- package/src/mutation/make-hook.mts +3 -11
- package/{tsup.config.mts → tsdown.config.mts} +4 -3
- package/dist/src/declare-client.d.mts +0 -31
- package/dist/src/declare-client.d.mts.map +0 -1
- package/dist/src/make-infinite-query-options.d.mts +0 -13
- package/dist/src/make-infinite-query-options.d.mts.map +0 -1
- package/dist/src/make-mutation.d.mts +0 -15
- package/dist/src/make-mutation.d.mts.map +0 -1
- package/dist/src/make-query-options.d.mts +0 -15
- package/dist/src/make-query-options.d.mts.map +0 -1
- package/dist/src/types/client-endpoint-helper.d.mts +0 -8
- package/dist/src/types/client-endpoint-helper.d.mts.map +0 -1
- package/dist/src/types/client-instance.d.mts +0 -211
- package/dist/src/types/client-instance.d.mts.map +0 -1
- package/dist/src/types/index.d.mts +0 -8
- package/dist/src/types/index.d.mts.map +0 -1
- package/dist/src/types/mutation-args.d.mts +0 -10
- package/dist/src/types/mutation-args.d.mts.map +0 -1
- package/dist/src/types/mutation-helpers.d.mts +0 -10
- package/dist/src/types/mutation-helpers.d.mts.map +0 -1
- package/dist/src/types/query-args.d.mts +0 -8
- package/dist/src/types/query-args.d.mts.map +0 -1
- package/dist/src/types/query-helpers.d.mts +0 -14
- package/dist/src/types/query-helpers.d.mts.map +0 -1
- package/dist/src/types/query-url-params-args.d.mts +0 -5
- package/dist/src/types/query-url-params-args.d.mts.map +0 -1
- package/dist/src/types.d.mts +0 -49
- package/dist/src/types.d.mts.map +0 -1
- package/dist/src/utils/mutation-key.creator.d.mts +0 -39
- package/dist/src/utils/mutation-key.creator.d.mts.map +0 -1
- package/dist/src/utils/query-key-creator.d.mts +0 -24
- package/dist/src/utils/query-key-creator.d.mts.map +0 -1
- package/lib/_tsup-dts-rollup.d.mts +0 -1097
- package/lib/_tsup-dts-rollup.d.ts +0 -1097
- package/lib/index.d.ts +0 -34
- package/lib/index.js +0 -375
- package/lib/index.js.map +0 -1
package/lib/index.mjs
CHANGED
|
@@ -1,366 +1,405 @@
|
|
|
1
|
-
import { bindUrlParams } from
|
|
2
|
-
import {
|
|
1
|
+
import { bindUrlParams } from "@navios/builder";
|
|
2
|
+
import { infiniteQueryOptions, queryOptions, useInfiniteQuery, useIsMutating, useMutation, useQuery, useSuspenseInfiniteQuery, useSuspenseQuery } from "@tanstack/react-query";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/query/key-creator.mts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a query key generator for a given endpoint configuration.
|
|
7
|
+
*
|
|
8
|
+
* The returned object provides methods to generate query keys that can be used
|
|
9
|
+
* with TanStack Query for caching, invalidation, and data tagging.
|
|
10
|
+
*
|
|
11
|
+
* @param config - The endpoint configuration
|
|
12
|
+
* @param options - Query parameters including processResponse and key prefix/suffix
|
|
13
|
+
* @param isInfinite - Whether this is for an infinite query
|
|
14
|
+
* @returns An object with methods to generate query keys
|
|
15
|
+
*/
|
|
5
16
|
function createQueryKey(config, options, _isInfinite) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(part) => part.startsWith("$") ? (
|
|
31
|
-
// @ts-expect-error TS2339 We know that the urlParams are defined only if the url has params
|
|
32
|
-
params.urlParams[part.slice(1)].toString()
|
|
33
|
-
) : part
|
|
34
|
-
),
|
|
35
|
-
...options.keySuffix ?? []
|
|
36
|
-
];
|
|
37
|
-
},
|
|
38
|
-
bindToUrl: (params) => {
|
|
39
|
-
return bindUrlParams(url, params ?? {});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
17
|
+
const url = config.url;
|
|
18
|
+
const urlParts = url.split("/").filter(Boolean);
|
|
19
|
+
return {
|
|
20
|
+
template: urlParts,
|
|
21
|
+
dataTag: (params) => {
|
|
22
|
+
const queryParams = params && "querySchema" in config && "params" in params ? config.querySchema?.parse(params.params) : [];
|
|
23
|
+
return [
|
|
24
|
+
...options.keyPrefix ?? [],
|
|
25
|
+
...urlParts.map((part) => part.startsWith("$") ? params.urlParams[part.slice(1)].toString() : part),
|
|
26
|
+
...options.keySuffix ?? [],
|
|
27
|
+
queryParams ?? []
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
filterKey: (params) => {
|
|
31
|
+
return [
|
|
32
|
+
...options.keyPrefix ?? [],
|
|
33
|
+
...urlParts.map((part) => part.startsWith("$") ? params.urlParams[part.slice(1)].toString() : part),
|
|
34
|
+
...options.keySuffix ?? []
|
|
35
|
+
];
|
|
36
|
+
},
|
|
37
|
+
bindToUrl: (params) => {
|
|
38
|
+
return bindUrlParams(url, params ?? {});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
/** @deprecated Use createQueryKey instead */
|
|
43
|
+
const queryKeyCreator = createQueryKey;
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/query/make-options.mts
|
|
47
|
+
/**
|
|
48
|
+
* Creates query options for a given endpoint.
|
|
49
|
+
*
|
|
50
|
+
* Returns a function that generates TanStack Query options when called with params.
|
|
51
|
+
* The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)
|
|
52
|
+
*
|
|
53
|
+
* @param endpoint - The navios endpoint to create query options for
|
|
54
|
+
* @param options - Query configuration including processResponse
|
|
55
|
+
* @param baseQuery - Optional base query options to merge
|
|
56
|
+
* @returns A function that generates query options with attached helpers
|
|
57
|
+
*/
|
|
44
58
|
function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
exact: false
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
return result;
|
|
59
|
+
const config = endpoint.config;
|
|
60
|
+
const queryKey = createQueryKey(config, options, false);
|
|
61
|
+
const processResponse = options.processResponse;
|
|
62
|
+
const result = (params) => {
|
|
63
|
+
return queryOptions({
|
|
64
|
+
queryKey: queryKey.dataTag(params),
|
|
65
|
+
queryFn: async ({ signal }) => {
|
|
66
|
+
let result$1;
|
|
67
|
+
try {
|
|
68
|
+
result$1 = await endpoint({
|
|
69
|
+
signal,
|
|
70
|
+
...params
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (options.onFail) options.onFail(err);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
return processResponse(result$1);
|
|
77
|
+
},
|
|
78
|
+
...baseQuery
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
result.queryKey = queryKey;
|
|
82
|
+
result.use = (params) => {
|
|
83
|
+
return useQuery(result(params));
|
|
84
|
+
};
|
|
85
|
+
result.useSuspense = (params) => {
|
|
86
|
+
return useSuspenseQuery(result(params));
|
|
87
|
+
};
|
|
88
|
+
result.invalidate = (queryClient, params) => {
|
|
89
|
+
return queryClient.invalidateQueries({ queryKey: result.queryKey.dataTag(params) });
|
|
90
|
+
};
|
|
91
|
+
result.invalidateAll = (queryClient, params) => {
|
|
92
|
+
return queryClient.invalidateQueries({
|
|
93
|
+
queryKey: result.queryKey.filterKey(params),
|
|
94
|
+
exact: false
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return result;
|
|
88
98
|
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/query/make-infinite-options.mts
|
|
102
|
+
/**
|
|
103
|
+
* Creates infinite query options for a given endpoint.
|
|
104
|
+
*
|
|
105
|
+
* Returns a function that generates TanStack Query infinite options when called with params.
|
|
106
|
+
* The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)
|
|
107
|
+
*
|
|
108
|
+
* @param endpoint - The navios endpoint to create infinite query options for
|
|
109
|
+
* @param options - Infinite query configuration including processResponse and pagination params
|
|
110
|
+
* @param baseQuery - Optional base query options to merge
|
|
111
|
+
* @returns A function that generates infinite query options with attached helpers
|
|
112
|
+
*/
|
|
89
113
|
function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
queryKey: res.queryKey.filterKey(params),
|
|
137
|
-
exact: false
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
return res;
|
|
114
|
+
const config = endpoint.config;
|
|
115
|
+
const queryKey = createQueryKey(config, options, true);
|
|
116
|
+
const processResponse = options.processResponse;
|
|
117
|
+
const res = (params) => {
|
|
118
|
+
return infiniteQueryOptions({
|
|
119
|
+
queryKey: queryKey.dataTag(params),
|
|
120
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
121
|
+
let result;
|
|
122
|
+
try {
|
|
123
|
+
result = await endpoint({
|
|
124
|
+
signal,
|
|
125
|
+
urlParams: params.urlParams,
|
|
126
|
+
params: {
|
|
127
|
+
..."params" in params ? params.params : {},
|
|
128
|
+
...pageParam
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (options.onFail) options.onFail(err);
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
return processResponse(result);
|
|
136
|
+
},
|
|
137
|
+
getNextPageParam: options.getNextPageParam,
|
|
138
|
+
getPreviousPageParam: options.getPreviousPageParam,
|
|
139
|
+
initialPageParam: options.initialPageParam ?? config.querySchema.parse("params" in params ? params.params : {}),
|
|
140
|
+
...baseQuery
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
res.queryKey = queryKey;
|
|
144
|
+
res.use = (params) => {
|
|
145
|
+
return useInfiniteQuery(res(params));
|
|
146
|
+
};
|
|
147
|
+
res.useSuspense = (params) => {
|
|
148
|
+
return useSuspenseInfiniteQuery(res(params));
|
|
149
|
+
};
|
|
150
|
+
res.invalidate = (queryClient, params) => {
|
|
151
|
+
return queryClient.invalidateQueries({ queryKey: res.queryKey.dataTag(params) });
|
|
152
|
+
};
|
|
153
|
+
res.invalidateAll = (queryClient, params) => {
|
|
154
|
+
return queryClient.invalidateQueries({
|
|
155
|
+
queryKey: res.queryKey.filterKey(params),
|
|
156
|
+
exact: false
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
return res;
|
|
141
160
|
}
|
|
142
161
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/mutation/key-creator.mts
|
|
164
|
+
/**
|
|
165
|
+
* Creates a mutation key generator for a given endpoint configuration.
|
|
166
|
+
*
|
|
167
|
+
* @param config - The endpoint configuration
|
|
168
|
+
* @param options - Optional query parameters with a default `processResponse` function
|
|
169
|
+
* @returns A function that generates mutation keys
|
|
170
|
+
*
|
|
171
|
+
* @example Basic usage:
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const createMutationKey = createMutationKey(endpoint.config);
|
|
174
|
+
* const mutationKey = createMutationKey({ urlParams: { id: 123 } });
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example Advanced usage with processResponse:
|
|
178
|
+
* ```ts
|
|
179
|
+
* const createMutationKey = createMutationKey(endpoint.config, {
|
|
180
|
+
* processResponse: (data) => {
|
|
181
|
+
* if (!data.success) {
|
|
182
|
+
* throw new Error(data.message);
|
|
183
|
+
* }
|
|
184
|
+
* return data.data;
|
|
185
|
+
* },
|
|
186
|
+
* });
|
|
187
|
+
* // We create a mutation that will be shared across the project for all passed userId
|
|
188
|
+
* const mutationKey = createMutationKey({ urlParams: { projectId: 123, userId: 'wildcard' } });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
function createMutationKey(config, options = { processResponse: (data) => data }) {
|
|
192
|
+
const queryKey = createQueryKey(config, options, false);
|
|
193
|
+
return (params) => {
|
|
194
|
+
return queryKey.filterKey(params);
|
|
195
|
+
};
|
|
151
196
|
}
|
|
152
|
-
|
|
197
|
+
/** @deprecated Use createMutationKey instead */
|
|
198
|
+
const mutationKeyCreator = createMutationKey;
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/mutation/make-hook.mts
|
|
202
|
+
/**
|
|
203
|
+
* Creates a mutation hook for a given endpoint.
|
|
204
|
+
*
|
|
205
|
+
* Returns a function that when called returns a TanStack Query mutation result.
|
|
206
|
+
* The returned function also has helper methods attached (mutationKey, useIsMutating).
|
|
207
|
+
*
|
|
208
|
+
* @param endpoint - The navios endpoint to create a mutation hook for
|
|
209
|
+
* @param options - Mutation configuration including processResponse and callbacks
|
|
210
|
+
* @returns A hook function that returns mutation result with attached helpers
|
|
211
|
+
*/
|
|
153
212
|
function makeMutation(endpoint, options) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
} : void 0,
|
|
207
|
-
onSettled: onSettled ? (data, error, variables, onMutateResult, context) => {
|
|
208
|
-
return onSettled(data, error, variables, {
|
|
209
|
-
...ownContext,
|
|
210
|
-
...context,
|
|
211
|
-
onMutateResult
|
|
212
|
-
});
|
|
213
|
-
} : void 0
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
result.useIsMutating = (keyParams) => {
|
|
217
|
-
if (!options.useKey) {
|
|
218
|
-
throw new Error(
|
|
219
|
-
"useIsMutating can only be used when useKey is set to true"
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
const isMutating = useIsMutating({
|
|
223
|
-
mutationKey: mutationKey({
|
|
224
|
-
urlParams: keyParams
|
|
225
|
-
})
|
|
226
|
-
});
|
|
227
|
-
return isMutating > 0;
|
|
228
|
-
};
|
|
229
|
-
result.mutationKey = mutationKey;
|
|
230
|
-
return result;
|
|
213
|
+
const config = endpoint.config;
|
|
214
|
+
const mutationKey = createMutationKey(config, {
|
|
215
|
+
...options,
|
|
216
|
+
processResponse: options.processResponse ?? ((data) => data)
|
|
217
|
+
});
|
|
218
|
+
const result = (keyParams) => {
|
|
219
|
+
const { useKey, useContext, onMutate, onError, onSuccess, onSettled, keyPrefix: _keyPrefix, keySuffix: _keySuffix, processResponse, ...rest } = options;
|
|
220
|
+
const ownContext = useContext?.() ?? {};
|
|
221
|
+
return useMutation({
|
|
222
|
+
...rest,
|
|
223
|
+
mutationKey: useKey ? mutationKey(keyParams) : void 0,
|
|
224
|
+
scope: useKey ? { id: JSON.stringify(mutationKey(keyParams)) } : void 0,
|
|
225
|
+
async mutationFn(params) {
|
|
226
|
+
const response = await endpoint(params);
|
|
227
|
+
return processResponse ? processResponse(response) : response;
|
|
228
|
+
},
|
|
229
|
+
onSuccess: onSuccess ? (data, variables, onMutateResult, context) => {
|
|
230
|
+
return onSuccess?.(data, variables, {
|
|
231
|
+
...ownContext,
|
|
232
|
+
...context,
|
|
233
|
+
onMutateResult
|
|
234
|
+
});
|
|
235
|
+
} : void 0,
|
|
236
|
+
onError: onError ? (err, variables, onMutateResult, context) => {
|
|
237
|
+
return onError?.(err, variables, {
|
|
238
|
+
onMutateResult,
|
|
239
|
+
...ownContext,
|
|
240
|
+
...context
|
|
241
|
+
});
|
|
242
|
+
} : void 0,
|
|
243
|
+
onMutate: onMutate ? (variables, context) => {
|
|
244
|
+
return onMutate(variables, {
|
|
245
|
+
...ownContext,
|
|
246
|
+
...context
|
|
247
|
+
});
|
|
248
|
+
} : void 0,
|
|
249
|
+
onSettled: onSettled ? (data, error, variables, onMutateResult, context) => {
|
|
250
|
+
return onSettled(data, error, variables, {
|
|
251
|
+
...ownContext,
|
|
252
|
+
...context,
|
|
253
|
+
onMutateResult
|
|
254
|
+
});
|
|
255
|
+
} : void 0
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
result.useIsMutating = (keyParams) => {
|
|
259
|
+
if (!options.useKey) throw new Error("useIsMutating can only be used when useKey is set to true");
|
|
260
|
+
return useIsMutating({ mutationKey: mutationKey({ urlParams: keyParams }) }) > 0;
|
|
261
|
+
};
|
|
262
|
+
result.mutationKey = mutationKey;
|
|
263
|
+
return result;
|
|
231
264
|
}
|
|
232
265
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/client/declare-client.mts
|
|
268
|
+
/**
|
|
269
|
+
* Creates a client instance for making type-safe queries and mutations.
|
|
270
|
+
*
|
|
271
|
+
* @param options - Client configuration including the API builder and defaults
|
|
272
|
+
* @returns A client instance with query, infiniteQuery, and mutation methods
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const api = createBuilder({ baseUrl: '/api' });
|
|
277
|
+
* const client = declareClient({ api });
|
|
278
|
+
*
|
|
279
|
+
* const getUser = client.query({
|
|
280
|
+
* method: 'GET',
|
|
281
|
+
* url: '/users/$id',
|
|
282
|
+
* responseSchema: UserSchema,
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // In a component
|
|
286
|
+
* const { data } = useSuspenseQuery(getUser({ urlParams: { id: '123' } }));
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
function declareClient({ api, defaults = {} }) {
|
|
290
|
+
function query(config) {
|
|
291
|
+
const endpoint = api.declareEndpoint({
|
|
292
|
+
method: config.method,
|
|
293
|
+
url: config.url,
|
|
294
|
+
querySchema: config.querySchema,
|
|
295
|
+
requestSchema: config.requestSchema,
|
|
296
|
+
responseSchema: config.responseSchema
|
|
297
|
+
});
|
|
298
|
+
const queryOptions$1 = makeQueryOptions(endpoint, {
|
|
299
|
+
...defaults,
|
|
300
|
+
processResponse: config.processResponse ?? ((data) => data)
|
|
301
|
+
});
|
|
302
|
+
queryOptions$1.endpoint = endpoint;
|
|
303
|
+
return queryOptions$1;
|
|
304
|
+
}
|
|
305
|
+
function queryFromEndpoint(endpoint, options) {
|
|
306
|
+
return makeQueryOptions(endpoint, {
|
|
307
|
+
...defaults,
|
|
308
|
+
processResponse: options?.processResponse ?? ((data) => data)
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function infiniteQuery(config) {
|
|
312
|
+
const endpoint = api.declareEndpoint({
|
|
313
|
+
method: config.method,
|
|
314
|
+
url: config.url,
|
|
315
|
+
querySchema: config.querySchema,
|
|
316
|
+
requestSchema: config.requestSchema,
|
|
317
|
+
responseSchema: config.responseSchema
|
|
318
|
+
});
|
|
319
|
+
const infiniteQueryOptions$1 = makeInfiniteQueryOptions(endpoint, {
|
|
320
|
+
...defaults,
|
|
321
|
+
processResponse: config.processResponse ?? ((data) => data),
|
|
322
|
+
getNextPageParam: config.getNextPageParam,
|
|
323
|
+
getPreviousPageParam: config.getPreviousPageParam,
|
|
324
|
+
initialPageParam: config.initialPageParam
|
|
325
|
+
});
|
|
326
|
+
infiniteQueryOptions$1.endpoint = endpoint;
|
|
327
|
+
return infiniteQueryOptions$1;
|
|
328
|
+
}
|
|
329
|
+
function infiniteQueryFromEndpoint(endpoint, options) {
|
|
330
|
+
return makeInfiniteQueryOptions(endpoint, {
|
|
331
|
+
...defaults,
|
|
332
|
+
processResponse: options?.processResponse ?? ((data) => data),
|
|
333
|
+
getNextPageParam: options.getNextPageParam,
|
|
334
|
+
getPreviousPageParam: options?.getPreviousPageParam,
|
|
335
|
+
initialPageParam: options?.initialPageParam
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function mutation(config) {
|
|
339
|
+
const endpoint = api.declareEndpoint({
|
|
340
|
+
method: config.method,
|
|
341
|
+
url: config.url,
|
|
342
|
+
querySchema: config.querySchema,
|
|
343
|
+
requestSchema: config.requestSchema,
|
|
344
|
+
responseSchema: config.responseSchema
|
|
345
|
+
});
|
|
346
|
+
const useMutation$1 = makeMutation(endpoint, {
|
|
347
|
+
processResponse: config.processResponse ?? ((data) => data),
|
|
348
|
+
useContext: config.useContext,
|
|
349
|
+
onSuccess: config.onSuccess,
|
|
350
|
+
onError: config.onError,
|
|
351
|
+
useKey: config.useKey,
|
|
352
|
+
meta: config.meta,
|
|
353
|
+
...defaults
|
|
354
|
+
});
|
|
355
|
+
useMutation$1.endpoint = endpoint;
|
|
356
|
+
return useMutation$1;
|
|
357
|
+
}
|
|
358
|
+
function mutationFromEndpoint(endpoint, options) {
|
|
359
|
+
return makeMutation(endpoint, {
|
|
360
|
+
processResponse: options?.processResponse,
|
|
361
|
+
useContext: options?.useContext,
|
|
362
|
+
onMutate: options?.onMutate,
|
|
363
|
+
onSuccess: options?.onSuccess,
|
|
364
|
+
onError: options?.onError,
|
|
365
|
+
onSettled: options?.onSettled,
|
|
366
|
+
useKey: options?.useKey,
|
|
367
|
+
meta: options?.meta,
|
|
368
|
+
...defaults
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function multipartMutation(config) {
|
|
372
|
+
const endpoint = api.declareMultipart({
|
|
373
|
+
method: config.method,
|
|
374
|
+
url: config.url,
|
|
375
|
+
querySchema: config.querySchema,
|
|
376
|
+
requestSchema: config.requestSchema,
|
|
377
|
+
responseSchema: config.responseSchema
|
|
378
|
+
});
|
|
379
|
+
const useMutation$1 = makeMutation(endpoint, {
|
|
380
|
+
processResponse: config.processResponse ?? ((data) => data),
|
|
381
|
+
useContext: config.useContext,
|
|
382
|
+
onSuccess: config.onSuccess,
|
|
383
|
+
onError: config.onError,
|
|
384
|
+
onMutate: config.onMutate,
|
|
385
|
+
onSettled: config.onSettled,
|
|
386
|
+
useKey: config.useKey,
|
|
387
|
+
...defaults
|
|
388
|
+
});
|
|
389
|
+
useMutation$1.endpoint = endpoint;
|
|
390
|
+
return useMutation$1;
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
query,
|
|
394
|
+
queryFromEndpoint,
|
|
395
|
+
infiniteQuery,
|
|
396
|
+
infiniteQueryFromEndpoint,
|
|
397
|
+
mutation,
|
|
398
|
+
mutationFromEndpoint,
|
|
399
|
+
multipartMutation
|
|
400
|
+
};
|
|
362
401
|
}
|
|
363
402
|
|
|
403
|
+
//#endregion
|
|
364
404
|
export { createMutationKey, createQueryKey, declareClient, makeInfiniteQueryOptions, makeMutation, makeQueryOptions, mutationKeyCreator, queryKeyCreator };
|
|
365
|
-
//# sourceMappingURL=index.mjs.map
|
|
366
405
|
//# sourceMappingURL=index.mjs.map
|