@kubb/plugin-react-query 5.0.0-beta.42 → 5.0.0-beta.56
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/{components-IArDg-DO.js → components-DL0Cai7l.js} +211 -255
- package/dist/components-DL0Cai7l.js.map +1 -0
- package/dist/{components-DQAYLQW0.cjs → components-yMQOuFmI.cjs} +215 -259
- package/dist/components-yMQOuFmI.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-B86BJkmW.js → generators-BG-Vcvfg.js} +151 -231
- package/dist/generators-BG-Vcvfg.js.map +1 -0
- package/dist/{generators-BqGaMUH6.cjs → generators-zGKP8yII.cjs} +149 -229
- package/dist/generators-zGKP8yII.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +35 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/dist/{types-Dh4HNR9K.d.ts → types-X7D0NSvJ.d.ts} +11 -15
- package/package.json +10 -17
- package/src/components/InfiniteQuery.tsx +4 -5
- package/src/components/InfiniteQueryOptions.tsx +24 -27
- package/src/components/Mutation.tsx +5 -6
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +5 -6
- package/src/components/QueryOptions.tsx +6 -25
- package/src/components/SuspenseInfiniteQuery.tsx +4 -5
- package/src/components/SuspenseInfiniteQueryOptions.tsx +24 -25
- package/src/components/SuspenseQuery.tsx +5 -6
- package/src/generators/customHookOptionsFileGenerator.tsx +2 -2
- package/src/generators/hookOptionsGenerator.tsx +2 -2
- package/src/generators/infiniteQueryGenerator.tsx +5 -9
- package/src/generators/mutationGenerator.tsx +8 -9
- package/src/generators/queryGenerator.tsx +5 -9
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +5 -9
- package/src/generators/suspenseQueryGenerator.tsx +5 -9
- package/src/plugin.ts +4 -4
- package/src/resolvers/resolverReactQuery.ts +2 -2
- package/src/types.ts +9 -13
- package/src/utils.ts +1 -0
- package/dist/components-DQAYLQW0.cjs.map +0 -1
- package/dist/components-IArDg-DO.js.map +0 -1
- package/dist/generators-B86BJkmW.js.map +0 -1
- package/dist/generators-BqGaMUH6.cjs.map +0 -1
- package/extension.yaml +0 -1484
|
@@ -28,6 +28,7 @@ let _kubb_core = require("@kubb/core");
|
|
|
28
28
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
29
29
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
30
30
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
31
|
+
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
31
32
|
//#region ../../internals/utils/src/casing.ts
|
|
32
33
|
/**
|
|
33
34
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -39,50 +40,20 @@ let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
|
39
40
|
function toCamelOrPascal(text, pascal) {
|
|
40
41
|
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
41
42
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
42
|
-
|
|
43
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
43
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
44
44
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
48
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
49
|
-
* Segments are joined with `/` to form a file path.
|
|
50
|
-
*
|
|
51
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
52
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
53
|
-
*/
|
|
54
|
-
function applyToFileParts(text, transformPart) {
|
|
55
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
56
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
47
|
* Converts `text` to camelCase.
|
|
60
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
61
48
|
*
|
|
62
|
-
* @example
|
|
63
|
-
* camelCase('hello-world')
|
|
64
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
65
|
-
*/
|
|
66
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
67
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
68
|
-
prefix,
|
|
69
|
-
suffix
|
|
70
|
-
} : {}));
|
|
71
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region ../../internals/utils/src/object.ts
|
|
75
|
-
/**
|
|
76
|
-
* Converts a dot-notation path or string array into an optional-chaining accessor expression.
|
|
49
|
+
* @example Word boundaries
|
|
50
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
77
51
|
*
|
|
78
|
-
* @example
|
|
79
|
-
*
|
|
80
|
-
* // → "lastPage?.['pagination']?.['next']?.['id']"
|
|
52
|
+
* @example With a prefix
|
|
53
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
81
54
|
*/
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
85
|
-
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
55
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
56
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
86
57
|
}
|
|
87
58
|
//#endregion
|
|
88
59
|
//#region ../../internals/utils/src/reserved.ts
|
|
@@ -188,99 +159,80 @@ function isValidVarName(name) {
|
|
|
188
159
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
189
160
|
}
|
|
190
161
|
//#endregion
|
|
191
|
-
//#region ../../internals/utils/src/
|
|
162
|
+
//#region ../../internals/utils/src/url.ts
|
|
163
|
+
function transformParam(raw, casing) {
|
|
164
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
165
|
+
return casing === "camelcase" ? camelCase(param) : param;
|
|
166
|
+
}
|
|
167
|
+
function toParamsObject(path, { replacer, casing } = {}) {
|
|
168
|
+
const params = {};
|
|
169
|
+
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
170
|
+
const param = transformParam(match[1], casing);
|
|
171
|
+
const key = replacer ? replacer(param) : param;
|
|
172
|
+
params[key] = key;
|
|
173
|
+
}
|
|
174
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
175
|
+
}
|
|
192
176
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* const p = new URLPath('/pet/{petId}')
|
|
197
|
-
* p.URL // '/pet/:petId'
|
|
198
|
-
* p.template // '`/pet/${petId}`'
|
|
177
|
+
* Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
|
|
199
178
|
*/
|
|
200
|
-
var
|
|
179
|
+
var Url = class Url {
|
|
201
180
|
/**
|
|
202
|
-
*
|
|
203
|
-
*/
|
|
204
|
-
path;
|
|
205
|
-
#options;
|
|
206
|
-
constructor(path, options = {}) {
|
|
207
|
-
this.path = path;
|
|
208
|
-
this.#options = options;
|
|
209
|
-
}
|
|
210
|
-
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
181
|
+
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
211
182
|
*
|
|
212
183
|
* @example
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* ```
|
|
184
|
+
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
185
|
+
* Url.canParse('/pet/{petId}') // false
|
|
216
186
|
*/
|
|
217
|
-
|
|
218
|
-
return
|
|
187
|
+
static canParse(url, base) {
|
|
188
|
+
return URL.canParse(url, base);
|
|
219
189
|
}
|
|
220
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
221
192
|
*
|
|
222
193
|
* @example
|
|
223
|
-
*
|
|
224
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
225
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
226
|
-
* ```
|
|
194
|
+
* Url.toPath('/pet/{petId}') // '/pet/:petId'
|
|
227
195
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return !!new URL(this.path).href;
|
|
231
|
-
} catch {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
196
|
+
static toPath(path) {
|
|
197
|
+
return path.replace(/\{([^}]+)\}/g, ":$1");
|
|
234
198
|
}
|
|
235
199
|
/**
|
|
236
|
-
* Converts
|
|
200
|
+
* Converts an OpenAPI/Swagger path to a TypeScript template literal string.
|
|
201
|
+
* `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
|
|
202
|
+
* and `casing` controls parameter identifier casing.
|
|
237
203
|
*
|
|
238
204
|
* @example
|
|
239
|
-
*
|
|
240
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
241
|
-
*/
|
|
242
|
-
get template() {
|
|
243
|
-
return this.toTemplateString();
|
|
244
|
-
}
|
|
245
|
-
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
205
|
+
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
246
206
|
*
|
|
247
207
|
* @example
|
|
248
|
-
*
|
|
249
|
-
* new URLPath('/pet/{petId}').object
|
|
250
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
251
|
-
* ```
|
|
208
|
+
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
252
209
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
210
|
+
static toTemplateString(path, { prefix, replacer, casing } = {}) {
|
|
211
|
+
const result = path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
212
|
+
if (i % 2 === 0) return part;
|
|
213
|
+
const param = transformParam(part, casing);
|
|
214
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
215
|
+
}).join("");
|
|
216
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
255
217
|
}
|
|
256
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
220
|
+
* expression when `stringify` is set.
|
|
257
221
|
*
|
|
258
222
|
* @example
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* new URLPath('/pet').params // null
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
get params() {
|
|
265
|
-
return this.toParamsObject();
|
|
266
|
-
}
|
|
267
|
-
#transformParam(raw) {
|
|
268
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
269
|
-
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
223
|
+
* Url.toObject('/pet/{petId}')
|
|
224
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
273
225
|
*/
|
|
274
|
-
|
|
275
|
-
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
276
|
-
const raw = match[1];
|
|
277
|
-
fn(raw, this.#transformParam(raw));
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
226
|
+
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
281
227
|
const object = {
|
|
282
|
-
url: type === "path" ?
|
|
283
|
-
|
|
228
|
+
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
229
|
+
replacer,
|
|
230
|
+
casing
|
|
231
|
+
}),
|
|
232
|
+
params: toParamsObject(path, {
|
|
233
|
+
replacer,
|
|
234
|
+
casing
|
|
235
|
+
})
|
|
284
236
|
};
|
|
285
237
|
if (stringify) {
|
|
286
238
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -289,50 +241,6 @@ var URLPath = class {
|
|
|
289
241
|
}
|
|
290
242
|
return object;
|
|
291
243
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
294
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
298
|
-
*/
|
|
299
|
-
toTemplateString({ prefix, replacer } = {}) {
|
|
300
|
-
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
301
|
-
if (i % 2 === 0) return part;
|
|
302
|
-
const param = this.#transformParam(part);
|
|
303
|
-
return `\${${replacer ? replacer(param) : param}}`;
|
|
304
|
-
}).join("");
|
|
305
|
-
return `\`${prefix ?? ""}${result}\``;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
309
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
310
|
-
* Returns `undefined` when no path parameters are found.
|
|
311
|
-
*
|
|
312
|
-
* @example
|
|
313
|
-
* ```ts
|
|
314
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
315
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
toParamsObject(replacer) {
|
|
319
|
-
const params = {};
|
|
320
|
-
this.#eachParam((_raw, param) => {
|
|
321
|
-
const key = replacer ? replacer(param) : param;
|
|
322
|
-
params[key] = key;
|
|
323
|
-
});
|
|
324
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
325
|
-
}
|
|
326
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* ```ts
|
|
330
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
toURLPath() {
|
|
334
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
335
|
-
}
|
|
336
244
|
};
|
|
337
245
|
//#endregion
|
|
338
246
|
//#region ../../internals/shared/src/operation.ts
|
|
@@ -358,7 +266,7 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
358
266
|
function getOperationLink(node, link) {
|
|
359
267
|
if (!link) return null;
|
|
360
268
|
if (typeof link === "function") return link(node) ?? null;
|
|
361
|
-
if (link === "urlPath") return node.path ? `{@link ${
|
|
269
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
362
270
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
363
271
|
}
|
|
364
272
|
function getContentTypeInfo(node) {
|
|
@@ -424,6 +332,19 @@ function resolveSuccessNames(node, resolver) {
|
|
|
424
332
|
function resolveStatusCodeNames(node, resolver) {
|
|
425
333
|
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
426
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Builds the discriminated union type string for `dataReturnType: 'full'` return shapes.
|
|
337
|
+
* Each member is `{ status: N; data: StatusNType; statusText: string }`.
|
|
338
|
+
*/
|
|
339
|
+
function buildStatusUnionType(node, resolver) {
|
|
340
|
+
const members = node.responses.map((r) => {
|
|
341
|
+
const typeName = resolver.resolveResponseStatusName(node, r.statusCode);
|
|
342
|
+
const statusCode = Number.parseInt(r.statusCode, 10);
|
|
343
|
+
return `{ status: ${Number.isNaN(statusCode) ? "number" : String(statusCode)}; data: ${typeName}; statusText: string }`;
|
|
344
|
+
});
|
|
345
|
+
if (members.length === 1) return members[0];
|
|
346
|
+
return `(${members.join(" | ")})`;
|
|
347
|
+
}
|
|
427
348
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
428
349
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
429
350
|
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
@@ -459,9 +380,9 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
459
380
|
//#endregion
|
|
460
381
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
461
382
|
const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
462
|
-
const mutationKeyTransformer = ({ node
|
|
383
|
+
const mutationKeyTransformer = ({ node }) => {
|
|
463
384
|
if (!node.path) return [];
|
|
464
|
-
return [`{ url: '${
|
|
385
|
+
return [`{ url: '${Url.toPath(node.path)}' }`];
|
|
465
386
|
};
|
|
466
387
|
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
467
388
|
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
@@ -485,6 +406,30 @@ function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
|
485
406
|
}
|
|
486
407
|
//#endregion
|
|
487
408
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
409
|
+
/**
|
|
410
|
+
* Builds the shared `(…params, config = {})` parameter list for a TanStack
|
|
411
|
+
* query-options function. The trailing `config` parameter is typed as a partial
|
|
412
|
+
* `RequestConfig` with an optional `client`. Framework plugins wrap the result
|
|
413
|
+
* when needed, for example vue-query applies `MaybeRefOrGetter`.
|
|
414
|
+
*/
|
|
415
|
+
function buildQueryOptionsParams(node, options) {
|
|
416
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
417
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
418
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
419
|
+
paramsType,
|
|
420
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
421
|
+
paramsCasing,
|
|
422
|
+
resolver,
|
|
423
|
+
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
424
|
+
name: "config",
|
|
425
|
+
type: _kubb_core.ast.createParamsType({
|
|
426
|
+
variant: "reference",
|
|
427
|
+
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
428
|
+
}),
|
|
429
|
+
default: "{}"
|
|
430
|
+
})]
|
|
431
|
+
});
|
|
432
|
+
}
|
|
488
433
|
function matchesPattern(node, ov) {
|
|
489
434
|
const { type, pattern } = ov;
|
|
490
435
|
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
@@ -508,13 +453,49 @@ function resolveOperationOverrides(node, override) {
|
|
|
508
453
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
509
454
|
}
|
|
510
455
|
/**
|
|
511
|
-
*
|
|
456
|
+
* Returns `'zod'` when response-direction parsing is enabled.
|
|
457
|
+
* The string shorthand `'zod'` also enables response parsing.
|
|
458
|
+
*/
|
|
459
|
+
function resolveResponseParser(parser) {
|
|
460
|
+
if (!parser) return null;
|
|
461
|
+
if (parser === "zod") return "zod";
|
|
462
|
+
return parser.response ?? null;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
466
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
467
|
+
*/
|
|
468
|
+
function resolveRequestParser(parser) {
|
|
469
|
+
if (!parser) return null;
|
|
470
|
+
if (parser === "zod") return "zod";
|
|
471
|
+
return parser.request ?? null;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Returns `'zod'` when query-params parsing is enabled.
|
|
475
|
+
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
476
|
+
*/
|
|
477
|
+
function resolveQueryParamsParser(parser) {
|
|
478
|
+
if (!parser || parser === "zod") return null;
|
|
479
|
+
return parser.request ?? null;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
512
483
|
*
|
|
513
|
-
*
|
|
484
|
+
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
485
|
+
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
486
|
+
* - `parser: { response: 'zod' }`: response name only.
|
|
487
|
+
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
488
|
+
*
|
|
489
|
+
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
514
490
|
*/
|
|
515
|
-
function resolveZodSchemaNames(node, zodResolver) {
|
|
516
|
-
if (!zodResolver) return [];
|
|
517
|
-
|
|
491
|
+
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
492
|
+
if (!zodResolver || !parser) return [];
|
|
493
|
+
const { query: queryParams } = getOperationParameters(node);
|
|
494
|
+
return [
|
|
495
|
+
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
496
|
+
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
497
|
+
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
498
|
+
].filter((n) => Boolean(n));
|
|
518
499
|
}
|
|
519
500
|
/**
|
|
520
501
|
* Resolve the type for a single path parameter.
|
|
@@ -694,13 +675,13 @@ function injectNonNullAssertions(callStr, names) {
|
|
|
694
675
|
const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
695
676
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
696
677
|
if (!node.path) return [];
|
|
697
|
-
const path = new URLPath(node.path, { casing });
|
|
698
678
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
699
679
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
700
680
|
return [
|
|
701
|
-
|
|
681
|
+
Url.toObject(node.path, {
|
|
702
682
|
type: "path",
|
|
703
|
-
stringify: true
|
|
683
|
+
stringify: true,
|
|
684
|
+
casing
|
|
704
685
|
}),
|
|
705
686
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
706
687
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -743,28 +724,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
743
724
|
const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
744
725
|
const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
745
726
|
function getQueryOptionsParams(node, options) {
|
|
746
|
-
|
|
747
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
748
|
-
return _kubb_core.ast.createOperationParams(node, {
|
|
749
|
-
paramsType,
|
|
750
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
751
|
-
paramsCasing,
|
|
752
|
-
resolver,
|
|
753
|
-
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
754
|
-
name: "config",
|
|
755
|
-
type: _kubb_core.ast.createParamsType({
|
|
756
|
-
variant: "reference",
|
|
757
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
758
|
-
}),
|
|
759
|
-
default: "{}"
|
|
760
|
-
})]
|
|
761
|
-
});
|
|
727
|
+
return buildQueryOptionsParams(node, options);
|
|
762
728
|
}
|
|
763
729
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
764
730
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
765
731
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
766
732
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
767
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
733
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
768
734
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
769
735
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
770
736
|
pathParamsType,
|
|
@@ -793,8 +759,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
793
759
|
params: paramsSignature,
|
|
794
760
|
children: `
|
|
795
761
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
796
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
797
|
-
${enabledText}
|
|
762
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
|
|
798
763
|
queryKey,
|
|
799
764
|
queryFn: async ({ signal }) => {
|
|
800
765
|
return ${clientName}(${clientCallStr})
|
|
@@ -834,7 +799,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
834
799
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
835
800
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
836
801
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
837
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
802
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
838
803
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
839
804
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
840
805
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -893,11 +858,10 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
893
858
|
children: `
|
|
894
859
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
895
860
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
896
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
897
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
861
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
898
862
|
|
|
899
863
|
const query = useInfiniteQuery({
|
|
900
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
864
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
901
865
|
...resolvedOptions,
|
|
902
866
|
queryKey,
|
|
903
867
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -916,7 +880,7 @@ const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
916
880
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
917
881
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
918
882
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
919
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
883
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
920
884
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
921
885
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
922
886
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -950,8 +914,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
950
914
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
951
915
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
952
916
|
if (hasNewParams) {
|
|
953
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
954
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
917
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
918
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
955
919
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
956
920
|
}
|
|
957
921
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -962,11 +926,10 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
962
926
|
getNextPageParamExpr,
|
|
963
927
|
getPreviousPageParamExpr
|
|
964
928
|
].filter(Boolean);
|
|
965
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
} as ${queryParamsTypeName}` : "";
|
|
929
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
930
|
+
...(params ?? {}),
|
|
931
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
932
|
+
} as ${queryParamsTypeName}` : "";
|
|
970
933
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
971
934
|
name,
|
|
972
935
|
isExportable: true,
|
|
@@ -976,16 +939,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
976
939
|
export: true,
|
|
977
940
|
params: paramsSignature,
|
|
978
941
|
children: `
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
})
|
|
942
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
943
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
944
|
+
queryKey,
|
|
945
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
946
|
+
${infiniteOverrideParams}
|
|
947
|
+
return ${clientName}(${clientCallStr})
|
|
948
|
+
},
|
|
949
|
+
${queryOptionsArr.join(",\n ")}
|
|
950
|
+
})
|
|
989
951
|
`
|
|
990
952
|
})
|
|
991
953
|
});
|
|
@@ -998,15 +960,14 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
998
960
|
export: true,
|
|
999
961
|
params: paramsSignature,
|
|
1000
962
|
children: `
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
})
|
|
963
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
964
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
965
|
+
queryKey,
|
|
966
|
+
queryFn: async ({ signal }) => {
|
|
967
|
+
return ${clientName}(${clientCallStr})
|
|
968
|
+
},
|
|
969
|
+
${queryOptionsArr.join(",\n ")}
|
|
970
|
+
})
|
|
1010
971
|
`
|
|
1011
972
|
})
|
|
1012
973
|
});
|
|
@@ -1029,7 +990,7 @@ function buildMutationConfigParamsNode(node, resolver) {
|
|
|
1029
990
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
1030
991
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1031
992
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1032
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
993
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1033
994
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1034
995
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1035
996
|
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
@@ -1096,7 +1057,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1096
1057
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1097
1058
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1098
1059
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1099
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1060
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1100
1061
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1101
1062
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1102
1063
|
paramsCasing,
|
|
@@ -1125,7 +1086,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1125
1086
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1126
1087
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1127
1088
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1128
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1089
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1129
1090
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1130
1091
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1131
1092
|
paramsCasing,
|
|
@@ -1162,11 +1123,10 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1162
1123
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1163
1124
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
1164
1125
|
|
|
1165
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
1166
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1126
|
+
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1167
1127
|
|
|
1168
1128
|
return useMutation<${generics}>({
|
|
1169
|
-
...baseOptions,${customOptions ? "\n...customOptions," : ""}
|
|
1129
|
+
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
1170
1130
|
mutationKey,
|
|
1171
1131
|
...mutationOptions,
|
|
1172
1132
|
}, queryClient) as ${returnType}
|
|
@@ -1184,7 +1144,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1184
1144
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1185
1145
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1186
1146
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1187
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1147
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1188
1148
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1189
1149
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1190
1150
|
name: "options",
|
|
@@ -1215,7 +1175,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1215
1175
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1216
1176
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1217
1177
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1218
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1178
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1219
1179
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1220
1180
|
const generics = [
|
|
1221
1181
|
`TData = ${TData}`,
|
|
@@ -1258,11 +1218,10 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1258
1218
|
children: `
|
|
1259
1219
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1260
1220
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1261
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1262
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1221
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1263
1222
|
|
|
1264
1223
|
const query = useQuery({
|
|
1265
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1224
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1266
1225
|
...resolvedOptions,
|
|
1267
1226
|
queryKey,
|
|
1268
1227
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1304,7 +1263,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1304
1263
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1305
1264
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1306
1265
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1307
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
1266
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1308
1267
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1309
1268
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1310
1269
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -1362,11 +1321,10 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1362
1321
|
children: `
|
|
1363
1322
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1364
1323
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1365
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1366
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1324
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1367
1325
|
|
|
1368
1326
|
const query = useSuspenseInfiniteQuery({
|
|
1369
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1327
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1370
1328
|
...resolvedOptions,
|
|
1371
1329
|
queryKey,
|
|
1372
1330
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1385,7 +1343,7 @@ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
1385
1343
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1386
1344
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1387
1345
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1388
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
1346
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1389
1347
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1390
1348
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1391
1349
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1417,8 +1375,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1417
1375
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1418
1376
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1419
1377
|
if (hasNewParams) {
|
|
1420
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1421
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1378
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
1379
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
1422
1380
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1423
1381
|
}
|
|
1424
1382
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1429,11 +1387,10 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1429
1387
|
getNextPageParamExpr,
|
|
1430
1388
|
getPreviousPageParamExpr
|
|
1431
1389
|
].filter(Boolean);
|
|
1432
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
} as ${queryParamsTypeName}` : "";
|
|
1390
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
1391
|
+
...(params ?? {}),
|
|
1392
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1393
|
+
} as ${queryParamsTypeName}` : "";
|
|
1437
1394
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1438
1395
|
name,
|
|
1439
1396
|
isExportable: true,
|
|
@@ -1443,15 +1400,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1443
1400
|
export: true,
|
|
1444
1401
|
params: paramsSignature,
|
|
1445
1402
|
children: `
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1403
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1404
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1405
|
+
queryKey,
|
|
1406
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
1407
|
+
${infiniteOverrideParams}
|
|
1408
|
+
return ${clientName}(${clientCallStr})
|
|
1409
|
+
},
|
|
1410
|
+
${queryOptionsArr.join(",\n ")}
|
|
1411
|
+
})
|
|
1455
1412
|
`
|
|
1456
1413
|
})
|
|
1457
1414
|
});
|
|
@@ -1464,14 +1421,14 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1464
1421
|
export: true,
|
|
1465
1422
|
params: paramsSignature,
|
|
1466
1423
|
children: `
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1424
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1425
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1426
|
+
queryKey,
|
|
1427
|
+
queryFn: async ({ signal }) => {
|
|
1428
|
+
return ${clientName}(${clientCallStr})
|
|
1429
|
+
},
|
|
1430
|
+
${queryOptionsArr.join(",\n ")}
|
|
1431
|
+
})
|
|
1475
1432
|
`
|
|
1476
1433
|
})
|
|
1477
1434
|
});
|
|
@@ -1486,7 +1443,7 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1486
1443
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1487
1444
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1488
1445
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1489
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1446
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1490
1447
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1491
1448
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1492
1449
|
name: "options",
|
|
@@ -1516,7 +1473,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1516
1473
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1517
1474
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1518
1475
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1519
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1476
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1520
1477
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1521
1478
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1522
1479
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
@@ -1554,11 +1511,10 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1554
1511
|
children: `
|
|
1555
1512
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1556
1513
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1557
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1558
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1514
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1559
1515
|
|
|
1560
1516
|
const query = useSuspenseQuery({
|
|
1561
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1517
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1562
1518
|
...resolvedOptions,
|
|
1563
1519
|
queryKey,
|
|
1564
1520
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -1698,4 +1654,4 @@ Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
|
1698
1654
|
}
|
|
1699
1655
|
});
|
|
1700
1656
|
|
|
1701
|
-
//# sourceMappingURL=components-
|
|
1657
|
+
//# sourceMappingURL=components-yMQOuFmI.cjs.map
|