@navios/react-query 0.1.3 → 0.3.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/dist/src/__tests__/client-type-check.spec.d.mts +2 -0
- package/dist/src/__tests__/client-type-check.spec.d.mts.map +1 -0
- package/dist/src/__tests__/declare-client.spec.d.mts +2 -0
- package/dist/src/__tests__/declare-client.spec.d.mts.map +1 -0
- package/dist/src/__tests__/make-mutation.spec.d.mts +2 -0
- package/dist/src/__tests__/make-mutation.spec.d.mts.map +1 -0
- package/dist/src/__tests__/makeDataTag.spec.d.mts +2 -0
- package/dist/src/__tests__/makeDataTag.spec.d.mts.map +1 -0
- package/dist/src/__tests__/makeInfiniteQueryOptions.spec.d.mts +2 -0
- package/dist/src/__tests__/makeInfiniteQueryOptions.spec.d.mts.map +1 -0
- package/dist/src/__tests__/makeQueryOptions.spec.d.mts +2 -0
- package/dist/src/__tests__/makeQueryOptions.spec.d.mts.map +1 -0
- package/dist/src/declare-client.d.mts +31 -0
- package/dist/src/declare-client.d.mts.map +1 -0
- package/dist/src/index.d.mts +9 -0
- package/dist/src/index.d.mts.map +1 -0
- package/dist/src/make-infinite-query-options.d.mts +13 -0
- package/dist/src/make-infinite-query-options.d.mts.map +1 -0
- package/dist/src/make-mutation.d.mts +15 -0
- package/dist/src/make-mutation.d.mts.map +1 -0
- package/dist/src/make-query-options.d.mts +15 -0
- package/dist/src/make-query-options.d.mts.map +1 -0
- package/dist/src/types/client-endpoint-helper.d.mts +8 -0
- package/dist/src/types/client-endpoint-helper.d.mts.map +1 -0
- package/dist/src/types/client-instance.d.mts +211 -0
- package/dist/src/types/client-instance.d.mts.map +1 -0
- package/dist/src/types/index.d.mts +8 -0
- package/dist/src/types/index.d.mts.map +1 -0
- package/dist/src/types/mutation-args.d.mts +10 -0
- package/dist/src/types/mutation-args.d.mts.map +1 -0
- package/dist/src/types/mutation-helpers.d.mts +10 -0
- package/dist/src/types/mutation-helpers.d.mts.map +1 -0
- package/dist/src/types/query-args.d.mts +8 -0
- package/dist/src/types/query-args.d.mts.map +1 -0
- package/dist/src/types/query-helpers.d.mts +14 -0
- package/dist/src/types/query-helpers.d.mts.map +1 -0
- package/dist/src/types/query-url-params-args.d.mts +5 -0
- package/dist/src/types/query-url-params-args.d.mts.map +1 -0
- package/dist/src/types.d.mts +49 -0
- package/dist/src/types.d.mts.map +1 -0
- package/dist/src/utils/mutation-key.creator.d.mts +39 -0
- package/dist/src/utils/mutation-key.creator.d.mts.map +1 -0
- package/dist/src/utils/query-key-creator.d.mts +24 -0
- package/dist/src/utils/query-key-creator.d.mts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsdown.config.d.mts +3 -0
- package/dist/tsdown.config.d.mts.map +1 -0
- package/dist/tsup.config.d.mts +3 -0
- package/dist/tsup.config.d.mts.map +1 -0
- package/dist/vitest.config.d.mts +3 -0
- package/dist/vitest.config.d.mts.map +1 -0
- package/{dist → lib}/_tsup-dts-rollup.d.mts +10 -10
- package/{dist → lib}/_tsup-dts-rollup.d.ts +10 -10
- package/{dist → lib}/index.js +36 -73
- package/lib/index.js.map +1 -0
- package/{dist → lib}/index.mjs +21 -41
- package/lib/index.mjs.map +1 -0
- package/package.json +11 -12
- package/project.json +53 -0
- package/src/__tests__/client-type-check.spec.mts +1 -1
- package/src/__tests__/declare-client.spec.mts +1 -1
- package/src/__tests__/make-mutation.spec.mts +1 -1
- package/src/__tests__/makeDataTag.spec.mts +1 -1
- package/src/__tests__/makeInfiniteQueryOptions.spec.mts +1 -1
- package/src/__tests__/makeQueryOptions.spec.mts +1 -1
- package/src/declare-client.mts +1 -1
- package/src/make-infinite-query-options.mts +1 -1
- package/src/make-mutation.mts +1 -1
- package/src/make-query-options.mts +1 -1
- package/src/types/client-endpoint-helper.mts +1 -1
- package/src/types/client-instance.mts +1 -1
- package/src/types/mutation-args.mts +1 -1
- package/src/types/mutation-helpers.mts +1 -1
- package/src/types/query-args.mts +1 -1
- package/src/types/query-helpers.mts +1 -1
- package/src/types/query-url-params-args.mts +1 -1
- package/src/types.mts +1 -1
- package/src/utils/mutation-key.creator.mts +5 -1
- package/src/utils/query-key-creator.mts +6 -2
- package/tsconfig.json +16 -0
- package/tsup.config.mts +12 -0
- package/vitest.config.mts +9 -0
- /package/{dist → lib}/index.d.mts +0 -0
- /package/{dist → lib}/index.d.ts +0 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { AbstractEndpoint } from '@navios/
|
|
2
|
-
import type { AnyEndpointConfig } from '@navios/
|
|
1
|
+
import type { AbstractEndpoint } from '@navios/builder';
|
|
2
|
+
import type { AnyEndpointConfig } from '@navios/builder';
|
|
3
3
|
import type { AnyZodObject } from 'zod';
|
|
4
|
-
import type { BaseEndpointConfig } from '@navios/
|
|
5
|
-
import type { BuilderInstance } from '@navios/
|
|
4
|
+
import type { BaseEndpointConfig } from '@navios/builder';
|
|
5
|
+
import type { BuilderInstance } from '@navios/builder';
|
|
6
6
|
import type { DataTag } from '@tanstack/react-query';
|
|
7
|
-
import type { EndpointFunctionArgs } from '@navios/
|
|
8
|
-
import type { HttpMethod } from '@navios/
|
|
7
|
+
import type { EndpointFunctionArgs } from '@navios/builder';
|
|
8
|
+
import type { HttpMethod } from '@navios/builder';
|
|
9
9
|
import type { InfiniteData } from '@tanstack/react-query';
|
|
10
|
-
import type { NaviosZodRequest } from '@navios/
|
|
10
|
+
import type { NaviosZodRequest } from '@navios/builder';
|
|
11
11
|
import { NoInfer as NoInfer_2 } from '@tanstack/react-query';
|
|
12
12
|
import type { QueryClient } from '@tanstack/react-query';
|
|
13
13
|
import { QueryKeyCreatorResult as QueryKeyCreatorResult_2 } from './utils/query-key-creator.mjs';
|
|
14
|
-
import { UrlHasParams } from '@navios/
|
|
15
|
-
import type { UrlParams } from '@navios/
|
|
14
|
+
import { UrlHasParams } from '@navios/builder';
|
|
15
|
+
import type { UrlParams } from '@navios/builder';
|
|
16
16
|
import type { UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
17
17
|
import { UseInfiniteQueryResult } from '@tanstack/react-query';
|
|
18
18
|
import type { UseMutationOptions } from '@tanstack/react-query';
|
|
@@ -23,7 +23,7 @@ import type { UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
|
23
23
|
import { UseSuspenseInfiniteQueryResult } from '@tanstack/react-query';
|
|
24
24
|
import type { UseSuspenseQueryOptions } from '@tanstack/react-query';
|
|
25
25
|
import { UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
26
|
-
import type { Util_FlatObject } from '@navios/
|
|
26
|
+
import type { Util_FlatObject } from '@navios/builder';
|
|
27
27
|
import type { z } from 'zod';
|
|
28
28
|
import type { ZodType } from 'zod';
|
|
29
29
|
|
package/{dist → lib}/index.js
RENAMED
|
@@ -1,36 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
declareClient: () => declareClient,
|
|
24
|
-
makeInfiniteQueryOptions: () => makeInfiniteQueryOptions,
|
|
25
|
-
makeMutation: () => makeMutation,
|
|
26
|
-
makeQueryOptions: () => makeQueryOptions,
|
|
27
|
-
mutationKeyCreator: () => mutationKeyCreator,
|
|
28
|
-
queryKeyCreator: () => queryKeyCreator
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var builder = require('@navios/builder');
|
|
4
|
+
var reactQuery = require('@tanstack/react-query');
|
|
31
5
|
|
|
32
|
-
//
|
|
33
|
-
var import_common = require("@navios/common");
|
|
6
|
+
// src/utils/query-key-creator.mts
|
|
34
7
|
function queryKeyCreator(config, options, isInfinite) {
|
|
35
8
|
const url = config.url;
|
|
36
9
|
const urlParts = url.split("/").filter(Boolean);
|
|
@@ -38,8 +11,7 @@ function queryKeyCreator(config, options, isInfinite) {
|
|
|
38
11
|
template: urlParts,
|
|
39
12
|
// @ts-expect-error We have correct types in return type
|
|
40
13
|
dataTag: (params) => {
|
|
41
|
-
|
|
42
|
-
const queryParams = params && "querySchema" in config && "params" in params ? (_a = config.querySchema) == null ? void 0 : _a.parse(params.params) : [];
|
|
14
|
+
const queryParams = params && "querySchema" in config && "params" in params ? config.querySchema?.parse(params.params) : [];
|
|
43
15
|
return [
|
|
44
16
|
...options.keyPrefix ?? [],
|
|
45
17
|
...urlParts.map(
|
|
@@ -66,29 +38,26 @@ function queryKeyCreator(config, options, isInfinite) {
|
|
|
66
38
|
];
|
|
67
39
|
},
|
|
68
40
|
bindToUrl: (params) => {
|
|
69
|
-
return
|
|
41
|
+
return builder.bindUrlParams(url, params ?? {});
|
|
70
42
|
}
|
|
71
43
|
};
|
|
72
44
|
}
|
|
73
45
|
|
|
74
|
-
//
|
|
46
|
+
// src/utils/mutation-key.creator.mts
|
|
75
47
|
function mutationKeyCreator(config, options = {
|
|
76
48
|
processResponse: (data) => data
|
|
77
49
|
}) {
|
|
78
|
-
const queryKey = queryKeyCreator(config, options
|
|
50
|
+
const queryKey = queryKeyCreator(config, options);
|
|
79
51
|
return (params) => {
|
|
80
52
|
return queryKey.filterKey(params);
|
|
81
53
|
};
|
|
82
54
|
}
|
|
83
|
-
|
|
84
|
-
// packages/react-query/src/make-infinite-query-options.mts
|
|
85
|
-
var import_react_query = require("@tanstack/react-query");
|
|
86
55
|
function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
87
56
|
const config = endpoint.config;
|
|
88
|
-
const queryKey = queryKeyCreator(config, options
|
|
57
|
+
const queryKey = queryKeyCreator(config, options);
|
|
89
58
|
const processResponse = options.processResponse;
|
|
90
59
|
const res = (params) => {
|
|
91
|
-
return
|
|
60
|
+
return reactQuery.infiniteQueryOptions({
|
|
92
61
|
// @ts-expect-error TS2322 We know the type
|
|
93
62
|
queryKey: queryKey.dataTag(params),
|
|
94
63
|
queryFn: async ({ signal, pageParam }) => {
|
|
@@ -118,10 +87,10 @@ function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
118
87
|
};
|
|
119
88
|
res.queryKey = queryKey;
|
|
120
89
|
res.use = (params) => {
|
|
121
|
-
return
|
|
90
|
+
return reactQuery.useInfiniteQuery(res(params));
|
|
122
91
|
};
|
|
123
92
|
res.useSuspense = (params) => {
|
|
124
|
-
return
|
|
93
|
+
return reactQuery.useSuspenseInfiniteQuery(res(params));
|
|
125
94
|
};
|
|
126
95
|
res.invalidate = (queryClient, params) => {
|
|
127
96
|
return queryClient.invalidateQueries({
|
|
@@ -138,14 +107,11 @@ function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
138
107
|
};
|
|
139
108
|
return res;
|
|
140
109
|
}
|
|
141
|
-
|
|
142
|
-
// packages/react-query/src/make-mutation.mts
|
|
143
|
-
var import_react_query2 = require("@tanstack/react-query");
|
|
144
110
|
function makeMutation(endpoint, options) {
|
|
145
111
|
const config = endpoint.config;
|
|
146
112
|
const mutationKey = mutationKeyCreator(config, options);
|
|
147
113
|
const result = (keyParams) => {
|
|
148
|
-
const queryClient =
|
|
114
|
+
const queryClient = reactQuery.useQueryClient();
|
|
149
115
|
const {
|
|
150
116
|
useKey,
|
|
151
117
|
useContext,
|
|
@@ -156,8 +122,8 @@ function makeMutation(endpoint, options) {
|
|
|
156
122
|
processResponse,
|
|
157
123
|
...rest
|
|
158
124
|
} = options;
|
|
159
|
-
const context = useContext
|
|
160
|
-
return
|
|
125
|
+
const context = useContext?.();
|
|
126
|
+
return reactQuery.useMutation(
|
|
161
127
|
{
|
|
162
128
|
...rest,
|
|
163
129
|
mutationKey: useKey ? mutationKey({
|
|
@@ -175,10 +141,10 @@ function makeMutation(endpoint, options) {
|
|
|
175
141
|
return processResponse(response);
|
|
176
142
|
},
|
|
177
143
|
onSuccess: onSuccess ? (data, variables) => {
|
|
178
|
-
return onSuccess
|
|
144
|
+
return onSuccess?.(queryClient, data, variables, context);
|
|
179
145
|
} : void 0,
|
|
180
146
|
onError: onError ? (err, variables) => {
|
|
181
|
-
return onError
|
|
147
|
+
return onError?.(queryClient, err, variables, context);
|
|
182
148
|
} : void 0
|
|
183
149
|
},
|
|
184
150
|
queryClient
|
|
@@ -190,7 +156,7 @@ function makeMutation(endpoint, options) {
|
|
|
190
156
|
"useIsMutating can only be used when useKey is set to true"
|
|
191
157
|
);
|
|
192
158
|
}
|
|
193
|
-
const isMutating =
|
|
159
|
+
const isMutating = reactQuery.useIsMutating({
|
|
194
160
|
mutationKey: mutationKey({
|
|
195
161
|
urlParams: keyParams
|
|
196
162
|
})
|
|
@@ -200,15 +166,12 @@ function makeMutation(endpoint, options) {
|
|
|
200
166
|
result.mutationKey = mutationKey;
|
|
201
167
|
return result;
|
|
202
168
|
}
|
|
203
|
-
|
|
204
|
-
// packages/react-query/src/make-query-options.mts
|
|
205
|
-
var import_react_query3 = require("@tanstack/react-query");
|
|
206
169
|
function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
207
170
|
const config = endpoint.config;
|
|
208
|
-
const queryKey = queryKeyCreator(config, options
|
|
171
|
+
const queryKey = queryKeyCreator(config, options);
|
|
209
172
|
const processResponse = options.processResponse;
|
|
210
173
|
const result = (params) => {
|
|
211
|
-
return
|
|
174
|
+
return reactQuery.queryOptions({
|
|
212
175
|
queryKey: queryKey.dataTag(params),
|
|
213
176
|
queryFn: async ({ signal }) => {
|
|
214
177
|
let result2;
|
|
@@ -230,10 +193,10 @@ function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
230
193
|
};
|
|
231
194
|
result.queryKey = queryKey;
|
|
232
195
|
result.use = (params) => {
|
|
233
|
-
return
|
|
196
|
+
return reactQuery.useQuery(result(params));
|
|
234
197
|
};
|
|
235
198
|
result.useSuspense = (params) => {
|
|
236
|
-
return
|
|
199
|
+
return reactQuery.useSuspenseQuery(result(params));
|
|
237
200
|
};
|
|
238
201
|
result.invalidate = (queryClient, params) => {
|
|
239
202
|
return queryClient.invalidateQueries({
|
|
@@ -251,7 +214,7 @@ function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
251
214
|
return result;
|
|
252
215
|
}
|
|
253
216
|
|
|
254
|
-
//
|
|
217
|
+
// src/declare-client.mts
|
|
255
218
|
function declareClient({
|
|
256
219
|
api,
|
|
257
220
|
defaults = {}
|
|
@@ -274,7 +237,7 @@ function declareClient({
|
|
|
274
237
|
function queryFromEndpoint(endpoint, options) {
|
|
275
238
|
return makeQueryOptions(endpoint, {
|
|
276
239
|
...defaults,
|
|
277
|
-
processResponse:
|
|
240
|
+
processResponse: options?.processResponse ?? ((data) => data)
|
|
278
241
|
});
|
|
279
242
|
}
|
|
280
243
|
function infiniteQuery(config) {
|
|
@@ -298,10 +261,10 @@ function declareClient({
|
|
|
298
261
|
function infiniteQueryFromEndpoint(endpoint, options) {
|
|
299
262
|
return makeInfiniteQueryOptions(endpoint, {
|
|
300
263
|
...defaults,
|
|
301
|
-
processResponse:
|
|
264
|
+
processResponse: options?.processResponse ?? ((data) => data),
|
|
302
265
|
getNextPageParam: options.getNextPageParam,
|
|
303
|
-
getPreviousPageParam: options
|
|
304
|
-
initialPageParam: options
|
|
266
|
+
getPreviousPageParam: options?.getPreviousPageParam,
|
|
267
|
+
initialPageParam: options?.initialPageParam
|
|
305
268
|
});
|
|
306
269
|
}
|
|
307
270
|
function mutation(config) {
|
|
@@ -351,12 +314,12 @@ function declareClient({
|
|
|
351
314
|
mutationFromEndpoint
|
|
352
315
|
};
|
|
353
316
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
317
|
+
|
|
318
|
+
exports.declareClient = declareClient;
|
|
319
|
+
exports.makeInfiniteQueryOptions = makeInfiniteQueryOptions;
|
|
320
|
+
exports.makeMutation = makeMutation;
|
|
321
|
+
exports.makeQueryOptions = makeQueryOptions;
|
|
322
|
+
exports.mutationKeyCreator = mutationKeyCreator;
|
|
323
|
+
exports.queryKeyCreator = queryKeyCreator;
|
|
324
|
+
//# sourceMappingURL=index.js.map
|
|
325
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +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,EAAA,MAAM,WAAW,GAAI,CAAA,KAAA,CAAM,GAAG,CAAA,CAAE,OAAO,OAAO,CAAA;AAC9C,EAAO,OAAA;AAAA,IACL,QAAU,EAAA,QAAA;AAAA;AAAA,IAEV,OAAA,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B,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"]}
|
package/{dist → lib}/index.mjs
RENAMED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { bindUrlParams } from '@navios/builder';
|
|
2
|
+
import { useInfiniteQuery, useSuspenseInfiniteQuery, useIsMutating, useQuery, useSuspenseQuery, infiniteQueryOptions, useQueryClient, useMutation, queryOptions } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
// src/utils/query-key-creator.mts
|
|
3
5
|
function queryKeyCreator(config, options, isInfinite) {
|
|
4
6
|
const url = config.url;
|
|
5
7
|
const urlParts = url.split("/").filter(Boolean);
|
|
@@ -7,8 +9,7 @@ function queryKeyCreator(config, options, isInfinite) {
|
|
|
7
9
|
template: urlParts,
|
|
8
10
|
// @ts-expect-error We have correct types in return type
|
|
9
11
|
dataTag: (params) => {
|
|
10
|
-
|
|
11
|
-
const queryParams = params && "querySchema" in config && "params" in params ? (_a = config.querySchema) == null ? void 0 : _a.parse(params.params) : [];
|
|
12
|
+
const queryParams = params && "querySchema" in config && "params" in params ? config.querySchema?.parse(params.params) : [];
|
|
12
13
|
return [
|
|
13
14
|
...options.keyPrefix ?? [],
|
|
14
15
|
...urlParts.map(
|
|
@@ -40,25 +41,18 @@ function queryKeyCreator(config, options, isInfinite) {
|
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
//
|
|
44
|
+
// src/utils/mutation-key.creator.mts
|
|
44
45
|
function mutationKeyCreator(config, options = {
|
|
45
46
|
processResponse: (data) => data
|
|
46
47
|
}) {
|
|
47
|
-
const queryKey = queryKeyCreator(config, options
|
|
48
|
+
const queryKey = queryKeyCreator(config, options);
|
|
48
49
|
return (params) => {
|
|
49
50
|
return queryKey.filterKey(params);
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
// packages/react-query/src/make-infinite-query-options.mts
|
|
54
|
-
import {
|
|
55
|
-
infiniteQueryOptions,
|
|
56
|
-
useInfiniteQuery,
|
|
57
|
-
useSuspenseInfiniteQuery
|
|
58
|
-
} from "@tanstack/react-query";
|
|
59
53
|
function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
60
54
|
const config = endpoint.config;
|
|
61
|
-
const queryKey = queryKeyCreator(config, options
|
|
55
|
+
const queryKey = queryKeyCreator(config, options);
|
|
62
56
|
const processResponse = options.processResponse;
|
|
63
57
|
const res = (params) => {
|
|
64
58
|
return infiniteQueryOptions({
|
|
@@ -111,13 +105,6 @@ function makeInfiniteQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
111
105
|
};
|
|
112
106
|
return res;
|
|
113
107
|
}
|
|
114
|
-
|
|
115
|
-
// packages/react-query/src/make-mutation.mts
|
|
116
|
-
import {
|
|
117
|
-
useIsMutating,
|
|
118
|
-
useMutation,
|
|
119
|
-
useQueryClient
|
|
120
|
-
} from "@tanstack/react-query";
|
|
121
108
|
function makeMutation(endpoint, options) {
|
|
122
109
|
const config = endpoint.config;
|
|
123
110
|
const mutationKey = mutationKeyCreator(config, options);
|
|
@@ -133,7 +120,7 @@ function makeMutation(endpoint, options) {
|
|
|
133
120
|
processResponse,
|
|
134
121
|
...rest
|
|
135
122
|
} = options;
|
|
136
|
-
const context = useContext
|
|
123
|
+
const context = useContext?.();
|
|
137
124
|
return useMutation(
|
|
138
125
|
{
|
|
139
126
|
...rest,
|
|
@@ -152,10 +139,10 @@ function makeMutation(endpoint, options) {
|
|
|
152
139
|
return processResponse(response);
|
|
153
140
|
},
|
|
154
141
|
onSuccess: onSuccess ? (data, variables) => {
|
|
155
|
-
return onSuccess
|
|
142
|
+
return onSuccess?.(queryClient, data, variables, context);
|
|
156
143
|
} : void 0,
|
|
157
144
|
onError: onError ? (err, variables) => {
|
|
158
|
-
return onError
|
|
145
|
+
return onError?.(queryClient, err, variables, context);
|
|
159
146
|
} : void 0
|
|
160
147
|
},
|
|
161
148
|
queryClient
|
|
@@ -177,12 +164,9 @@ function makeMutation(endpoint, options) {
|
|
|
177
164
|
result.mutationKey = mutationKey;
|
|
178
165
|
return result;
|
|
179
166
|
}
|
|
180
|
-
|
|
181
|
-
// packages/react-query/src/make-query-options.mts
|
|
182
|
-
import { queryOptions, useQuery, useSuspenseQuery } from "@tanstack/react-query";
|
|
183
167
|
function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
184
168
|
const config = endpoint.config;
|
|
185
|
-
const queryKey = queryKeyCreator(config, options
|
|
169
|
+
const queryKey = queryKeyCreator(config, options);
|
|
186
170
|
const processResponse = options.processResponse;
|
|
187
171
|
const result = (params) => {
|
|
188
172
|
return queryOptions({
|
|
@@ -228,7 +212,7 @@ function makeQueryOptions(endpoint, options, baseQuery = {}) {
|
|
|
228
212
|
return result;
|
|
229
213
|
}
|
|
230
214
|
|
|
231
|
-
//
|
|
215
|
+
// src/declare-client.mts
|
|
232
216
|
function declareClient({
|
|
233
217
|
api,
|
|
234
218
|
defaults = {}
|
|
@@ -251,7 +235,7 @@ function declareClient({
|
|
|
251
235
|
function queryFromEndpoint(endpoint, options) {
|
|
252
236
|
return makeQueryOptions(endpoint, {
|
|
253
237
|
...defaults,
|
|
254
|
-
processResponse:
|
|
238
|
+
processResponse: options?.processResponse ?? ((data) => data)
|
|
255
239
|
});
|
|
256
240
|
}
|
|
257
241
|
function infiniteQuery(config) {
|
|
@@ -275,10 +259,10 @@ function declareClient({
|
|
|
275
259
|
function infiniteQueryFromEndpoint(endpoint, options) {
|
|
276
260
|
return makeInfiniteQueryOptions(endpoint, {
|
|
277
261
|
...defaults,
|
|
278
|
-
processResponse:
|
|
262
|
+
processResponse: options?.processResponse ?? ((data) => data),
|
|
279
263
|
getNextPageParam: options.getNextPageParam,
|
|
280
|
-
getPreviousPageParam: options
|
|
281
|
-
initialPageParam: options
|
|
264
|
+
getPreviousPageParam: options?.getPreviousPageParam,
|
|
265
|
+
initialPageParam: options?.initialPageParam
|
|
282
266
|
});
|
|
283
267
|
}
|
|
284
268
|
function mutation(config) {
|
|
@@ -328,11 +312,7 @@ function declareClient({
|
|
|
328
312
|
mutationFromEndpoint
|
|
329
313
|
};
|
|
330
314
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
makeQueryOptions,
|
|
336
|
-
mutationKeyCreator,
|
|
337
|
-
queryKeyCreator
|
|
338
|
-
};
|
|
315
|
+
|
|
316
|
+
export { declareClient, makeInfiniteQueryOptions, makeMutation, makeQueryOptions, mutationKeyCreator, queryKeyCreator };
|
|
317
|
+
//# sourceMappingURL=index.mjs.map
|
|
318
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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-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AA,QAAA,GAAW,IAAI,eAAgB,CAAA;AAAA;AAAA,MAEnC,QAAQ,MAAO,CAAA,MAAA;AAAA,MACf,KAAK,MAAO,CAAA,GAAA;AAAA,MACZ,aAAa,MAAO,CAAA,WAAA;AAAA,MACpB,eAAe,MAAO,CAAA,aAAA;AAAA,MACtB,gBAAgB,MAAO,CAAA;AAAA,KACxB,CAAA;AAED,IAAMC,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.mjs","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navios/react-query",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Oleksandr Hanzha",
|
|
6
6
|
"email": "alex@granted.name"
|
|
@@ -11,29 +11,28 @@
|
|
|
11
11
|
"url": "https://github.com/Arilas/navios.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"typings": "./dist/index.d.ts",
|
|
15
|
-
"main": "./dist/index.js",
|
|
16
|
-
"module": "./dist/index.mjs",
|
|
17
14
|
"peerDependencies": {
|
|
18
|
-
"@navios/
|
|
15
|
+
"@navios/builder": "^0.2.0",
|
|
19
16
|
"@tanstack/react-query": "^5.51.21",
|
|
20
17
|
"zod": "^3.23.8"
|
|
21
18
|
},
|
|
19
|
+
"typings": "./lib/index.d.mts",
|
|
20
|
+
"main": "./lib/index.js",
|
|
21
|
+
"module": "./lib/index.mjs",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"import": {
|
|
25
|
-
"types": "./
|
|
26
|
-
"default": "./
|
|
25
|
+
"types": "./lib/index.d.mts",
|
|
26
|
+
"default": "./lib/index.mjs"
|
|
27
27
|
},
|
|
28
28
|
"require": {
|
|
29
|
-
"types": "./
|
|
30
|
-
"default": "./
|
|
29
|
+
"types": "./lib/index.d.ts",
|
|
30
|
+
"default": "./lib/index.js"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
33
|
-
"./package.json": "./package.json"
|
|
32
|
+
}
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@navios/
|
|
35
|
+
"@navios/builder": "^0.2.0",
|
|
37
36
|
"@tanstack/react-query": "^5.75.7",
|
|
38
37
|
"navios": "^0.5.0",
|
|
39
38
|
"react": "^19.1.0",
|