@kubb/plugin-react-query 5.0.0-beta.42 → 5.0.0-beta.64
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-DQAYLQW0.cjs → components-B0j2b6y8.cjs} +298 -416
- package/dist/components-B0j2b6y8.cjs.map +1 -0
- package/dist/{components-IArDg-DO.js → components-Ds-e_nnK.js} +294 -412
- package/dist/components-Ds-e_nnK.js.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-BqGaMUH6.cjs → generators-CU6zfet7.cjs} +149 -229
- package/dist/generators-CU6zfet7.cjs.map +1 -0
- package/dist/{generators-B86BJkmW.js → generators-nnZhtlrk.js} +151 -231
- package/dist/generators-nnZhtlrk.js.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 +41 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-Dh4HNR9K.d.ts → types-ANQXv7Gr.d.ts} +13 -17
- package/package.json +10 -18
- 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
- package/src/components/InfiniteQuery.tsx +0 -167
- package/src/components/InfiniteQueryOptions.tsx +0 -169
- package/src/components/Mutation.tsx +0 -123
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/MutationOptions.tsx +0 -104
- package/src/components/Query.tsx +0 -125
- package/src/components/QueryKey.tsx +0 -1
- package/src/components/QueryOptions.tsx +0 -104
- package/src/components/SuspenseInfiniteQuery.tsx +0 -162
- package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -163
- package/src/components/SuspenseQuery.tsx +0 -120
- package/src/components/index.ts +0 -11
- package/src/generators/customHookOptionsFileGenerator.tsx +0 -90
- package/src/generators/hookOptionsGenerator.tsx +0 -129
- package/src/generators/index.ts +0 -7
- package/src/generators/infiniteQueryGenerator.tsx +0 -200
- package/src/generators/mutationGenerator.tsx +0 -173
- package/src/generators/queryGenerator.tsx +0 -185
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -209
- package/src/generators/suspenseQueryGenerator.tsx +0 -188
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -203
- package/src/resolvers/resolverReactQuery.ts +0 -118
- package/src/types.ts +0 -365
- package/src/utils.ts +0 -17
|
@@ -25,6 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
27
|
let _kubb_core = require("@kubb/core");
|
|
28
|
+
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
28
29
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
29
30
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
30
31
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
@@ -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) {
|
|
@@ -395,7 +303,7 @@ function buildOperationComments(node, options = {}) {
|
|
|
395
303
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
396
304
|
}
|
|
397
305
|
function getOperationParameters(node, options = {}) {
|
|
398
|
-
const params =
|
|
306
|
+
const params = (0, _kubb_ast_utils.caseParams)(node.parameters, options.paramsCasing);
|
|
399
307
|
return {
|
|
400
308
|
path: params.filter((param) => param.in === "path"),
|
|
401
309
|
query: params.filter((param) => param.in === "query"),
|
|
@@ -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,12 +380,12 @@ 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
|
-
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
388
|
+
const paramsNode = _kubb_core.ast.factory.createFunctionParameters({ params: [] });
|
|
468
389
|
const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
|
|
469
390
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
470
391
|
node,
|
|
@@ -485,6 +406,35 @@ function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
|
485
406
|
}
|
|
486
407
|
//#endregion
|
|
487
408
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
409
|
+
/**
|
|
410
|
+
* Returns the `TypeLiteral` members of a destructured group parameter, or `null`
|
|
411
|
+
* for a plain named parameter.
|
|
412
|
+
*/
|
|
413
|
+
function groupMembers(param) {
|
|
414
|
+
if (typeof param.name === "string") return null;
|
|
415
|
+
return param.type && typeof param.type !== "string" && param.type.kind === "TypeLiteral" ? param.type.members : [];
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Builds the shared `(…params, config = {})` parameter list for a TanStack
|
|
419
|
+
* query-options function. The trailing `config` parameter is typed as a partial
|
|
420
|
+
* `RequestConfig` with an optional `client`. Framework plugins wrap the result
|
|
421
|
+
* when needed, for example vue-query applies `MaybeRefOrGetter`.
|
|
422
|
+
*/
|
|
423
|
+
function buildQueryOptionsParams(node, options) {
|
|
424
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
425
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
426
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
427
|
+
paramsType,
|
|
428
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
429
|
+
paramsCasing,
|
|
430
|
+
resolver,
|
|
431
|
+
extraParams: [_kubb_core.ast.factory.createFunctionParameter({
|
|
432
|
+
name: "config",
|
|
433
|
+
type: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
434
|
+
default: "{}"
|
|
435
|
+
})]
|
|
436
|
+
});
|
|
437
|
+
}
|
|
488
438
|
function matchesPattern(node, ov) {
|
|
489
439
|
const { type, pattern } = ov;
|
|
490
440
|
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
@@ -508,116 +458,97 @@ function resolveOperationOverrides(node, override) {
|
|
|
508
458
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
509
459
|
}
|
|
510
460
|
/**
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
461
|
+
* Returns `'zod'` when response-direction parsing is enabled.
|
|
462
|
+
* The string shorthand `'zod'` also enables response parsing.
|
|
514
463
|
*/
|
|
515
|
-
function
|
|
516
|
-
if (!
|
|
517
|
-
|
|
464
|
+
function resolveResponseParser(parser) {
|
|
465
|
+
if (!parser) return null;
|
|
466
|
+
if (parser === "zod") return "zod";
|
|
467
|
+
return parser.response ?? null;
|
|
518
468
|
}
|
|
519
469
|
/**
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
* - When the resolver's group name differs from the individual param name
|
|
523
|
-
* (e.g. kubbV4) → `GroupName['paramName']` (member access).
|
|
524
|
-
* - When they match (v5 default) → `TypeName` (direct reference).
|
|
470
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
471
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
525
472
|
*/
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
variant: "member",
|
|
531
|
-
base: groupName,
|
|
532
|
-
key: param.name
|
|
533
|
-
});
|
|
534
|
-
return _kubb_core.ast.createParamsType({
|
|
535
|
-
variant: "reference",
|
|
536
|
-
name: individualName
|
|
537
|
-
});
|
|
473
|
+
function resolveRequestParser(parser) {
|
|
474
|
+
if (!parser) return null;
|
|
475
|
+
if (parser === "zod") return "zod";
|
|
476
|
+
return parser.request ?? null;
|
|
538
477
|
}
|
|
539
478
|
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
* equals the individual param name (no real group).
|
|
479
|
+
* Returns `'zod'` when query-params parsing is enabled.
|
|
480
|
+
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
543
481
|
*/
|
|
544
|
-
function
|
|
545
|
-
if (!
|
|
546
|
-
|
|
547
|
-
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
548
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
549
|
-
return {
|
|
550
|
-
type: _kubb_core.ast.createParamsType({
|
|
551
|
-
variant: "reference",
|
|
552
|
-
name: groupName
|
|
553
|
-
}),
|
|
554
|
-
optional: params.every((p) => !p.required)
|
|
555
|
-
};
|
|
482
|
+
function resolveQueryParamsParser(parser) {
|
|
483
|
+
if (!parser || parser === "zod") return null;
|
|
484
|
+
return parser.request ?? null;
|
|
556
485
|
}
|
|
557
486
|
/**
|
|
558
|
-
*
|
|
487
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
488
|
+
*
|
|
489
|
+
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
490
|
+
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
491
|
+
* - `parser: { response: 'zod' }`: response name only.
|
|
492
|
+
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
493
|
+
*
|
|
494
|
+
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
559
495
|
*/
|
|
560
|
-
function
|
|
561
|
-
if (
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
name: p.name,
|
|
569
|
-
type: _kubb_core.ast.createParamsType({
|
|
570
|
-
variant: "reference",
|
|
571
|
-
name: resolver.resolveParamName(node, p)
|
|
572
|
-
}),
|
|
573
|
-
optional: !p.required
|
|
574
|
-
}));
|
|
575
|
-
return [_kubb_core.ast.createFunctionParameter({
|
|
576
|
-
name,
|
|
577
|
-
type: _kubb_core.ast.createParamsType({
|
|
578
|
-
variant: "struct",
|
|
579
|
-
properties: structProps
|
|
580
|
-
}),
|
|
581
|
-
optional: params.every((p) => !p.required)
|
|
582
|
-
})];
|
|
583
|
-
}
|
|
584
|
-
return [];
|
|
496
|
+
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
497
|
+
if (!zodResolver || !parser) return [];
|
|
498
|
+
const { query: queryParams } = getOperationParameters(node);
|
|
499
|
+
return [
|
|
500
|
+
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
501
|
+
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
502
|
+
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
503
|
+
].filter((n) => Boolean(n));
|
|
585
504
|
}
|
|
586
505
|
/**
|
|
587
506
|
* Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
|
|
588
507
|
*/
|
|
589
508
|
function buildQueryKeyParams(node, options) {
|
|
590
509
|
const { pathParamsType, paramsCasing, resolver } = options;
|
|
591
|
-
const casedParams =
|
|
510
|
+
const casedParams = (0, _kubb_ast_utils.caseParams)(node.parameters, paramsCasing);
|
|
592
511
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
593
512
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
594
|
-
const queryGroupType =
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
513
|
+
const queryGroupType = (0, _kubb_ast_utils.resolveGroupType)({
|
|
514
|
+
node,
|
|
515
|
+
params: queryParams,
|
|
516
|
+
group: "query",
|
|
517
|
+
resolver
|
|
518
|
+
});
|
|
519
|
+
const bodyType = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
599
520
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
600
521
|
const params = [];
|
|
601
522
|
if (pathParams.length) {
|
|
602
|
-
const pathChildren = pathParams.map((p) =>
|
|
523
|
+
const pathChildren = pathParams.map((p) => ({
|
|
603
524
|
name: p.name,
|
|
604
|
-
type:
|
|
525
|
+
type: (0, _kubb_ast_utils.resolveParamType)({
|
|
526
|
+
node,
|
|
527
|
+
param: p,
|
|
528
|
+
resolver
|
|
529
|
+
}),
|
|
605
530
|
optional: !p.required
|
|
606
531
|
}));
|
|
607
|
-
params.push({
|
|
608
|
-
kind: "ParameterGroup",
|
|
532
|
+
if (pathParamsType === "object") params.push(_kubb_core.ast.factory.createFunctionParameter({
|
|
609
533
|
properties: pathChildren,
|
|
610
|
-
inline: pathParamsType === "inline",
|
|
611
534
|
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
612
|
-
});
|
|
535
|
+
}));
|
|
536
|
+
else params.push(...pathChildren.map((child) => _kubb_core.ast.factory.createFunctionParameter(child)));
|
|
613
537
|
}
|
|
614
|
-
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
538
|
+
if (bodyType) params.push(_kubb_core.ast.factory.createFunctionParameter({
|
|
615
539
|
name: "data",
|
|
616
540
|
type: bodyType,
|
|
617
541
|
optional: !bodyRequired
|
|
618
542
|
}));
|
|
619
|
-
params.push(...
|
|
620
|
-
|
|
543
|
+
params.push(...(0, _kubb_ast_utils.buildGroupParam)({
|
|
544
|
+
name: "params",
|
|
545
|
+
node,
|
|
546
|
+
params: queryParams,
|
|
547
|
+
groupType: queryGroupType,
|
|
548
|
+
resolver,
|
|
549
|
+
wrapType: (type) => type
|
|
550
|
+
}));
|
|
551
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params });
|
|
621
552
|
}
|
|
622
553
|
/**
|
|
623
554
|
* Collect the names of the required params (no default) that drive the `enabled`
|
|
@@ -626,12 +557,11 @@ function buildQueryKeyParams(node, options) {
|
|
|
626
557
|
*/
|
|
627
558
|
function getEnabledParamNames(paramsNode) {
|
|
628
559
|
const required = [];
|
|
629
|
-
for (const param of paramsNode.params)
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
560
|
+
for (const param of paramsNode.params) {
|
|
561
|
+
const members = groupMembers(param);
|
|
562
|
+
if (members) {
|
|
563
|
+
for (const member of members) if (!member.optional) required.push(member.name);
|
|
564
|
+
} else if (typeof param.name === "string" && !param.optional && param.default === void 0) required.push(param.name);
|
|
635
565
|
}
|
|
636
566
|
return required;
|
|
637
567
|
}
|
|
@@ -647,27 +577,25 @@ function markParamsOptional(paramsNode, names) {
|
|
|
647
577
|
if (names.length === 0) return paramsNode;
|
|
648
578
|
const nameSet = new Set(names);
|
|
649
579
|
const params = paramsNode.params.map((param) => {
|
|
650
|
-
|
|
651
|
-
|
|
580
|
+
const members = groupMembers(param);
|
|
581
|
+
if (members) {
|
|
582
|
+
const next = members.map((member) => nameSet.has(member.name) ? {
|
|
583
|
+
...member,
|
|
584
|
+
optional: true
|
|
585
|
+
} : member);
|
|
652
586
|
return {
|
|
653
|
-
...
|
|
654
|
-
|
|
655
|
-
name: child.name,
|
|
656
|
-
type: child.type,
|
|
657
|
-
rest: child.rest,
|
|
658
|
-
optional: true
|
|
659
|
-
}) : child)
|
|
587
|
+
...param,
|
|
588
|
+
type: _kubb_core.ast.factory.createTypeLiteral({ members: next })
|
|
660
589
|
};
|
|
661
590
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
rest: fp.rest,
|
|
591
|
+
return typeof param.name === "string" && nameSet.has(param.name) ? _kubb_core.ast.factory.createFunctionParameter({
|
|
592
|
+
name: param.name,
|
|
593
|
+
type: param.type,
|
|
594
|
+
rest: param.rest,
|
|
667
595
|
optional: true
|
|
668
|
-
}) :
|
|
596
|
+
}) : param;
|
|
669
597
|
});
|
|
670
|
-
return _kubb_core.ast.createFunctionParameters({ params });
|
|
598
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params });
|
|
671
599
|
}
|
|
672
600
|
/**
|
|
673
601
|
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
@@ -694,13 +622,13 @@ function injectNonNullAssertions(callStr, names) {
|
|
|
694
622
|
const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
695
623
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
696
624
|
if (!node.path) return [];
|
|
697
|
-
const path = new URLPath(node.path, { casing });
|
|
698
625
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
699
626
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
700
627
|
return [
|
|
701
|
-
|
|
628
|
+
Url.toObject(node.path, {
|
|
702
629
|
type: "path",
|
|
703
|
-
stringify: true
|
|
630
|
+
stringify: true,
|
|
631
|
+
casing
|
|
704
632
|
}),
|
|
705
633
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
706
634
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -743,28 +671,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
743
671
|
const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
744
672
|
const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
745
673
|
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
|
-
});
|
|
674
|
+
return buildQueryOptionsParams(node, options);
|
|
762
675
|
}
|
|
763
676
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
764
677
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
765
678
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
766
679
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
767
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
680
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
768
681
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
769
682
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
770
683
|
pathParamsType,
|
|
@@ -793,8 +706,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
793
706
|
params: paramsSignature,
|
|
794
707
|
children: `
|
|
795
708
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
796
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
797
|
-
${enabledText}
|
|
709
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
|
|
798
710
|
queryKey,
|
|
799
711
|
queryFn: async ({ signal }) => {
|
|
800
712
|
return ${clientName}(${clientCallStr})
|
|
@@ -811,18 +723,15 @@ const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
811
723
|
function buildInfiniteQueryParamsNode(node, options) {
|
|
812
724
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
813
725
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
814
|
-
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
726
|
+
const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
|
|
815
727
|
name: "options",
|
|
816
|
-
type:
|
|
817
|
-
variant: "reference",
|
|
818
|
-
name: `{
|
|
728
|
+
type: `{
|
|
819
729
|
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
820
730
|
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
|
|
821
|
-
}
|
|
822
|
-
}),
|
|
731
|
+
}`,
|
|
823
732
|
default: "{}"
|
|
824
733
|
});
|
|
825
|
-
return
|
|
734
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
826
735
|
paramsType,
|
|
827
736
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
828
737
|
paramsCasing,
|
|
@@ -834,7 +743,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
834
743
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
835
744
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
836
745
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
837
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
746
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
838
747
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
839
748
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
840
749
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -893,11 +802,10 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
893
802
|
children: `
|
|
894
803
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
895
804
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
896
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
897
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
805
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
898
806
|
|
|
899
807
|
const query = useInfiniteQuery({
|
|
900
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
808
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
901
809
|
...resolvedOptions,
|
|
902
810
|
queryKey,
|
|
903
811
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -916,7 +824,7 @@ const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
916
824
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
917
825
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
918
826
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
919
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
827
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
920
828
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
921
829
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
922
830
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -950,8 +858,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
950
858
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
951
859
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
952
860
|
if (hasNewParams) {
|
|
953
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
954
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
861
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
862
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
955
863
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
956
864
|
}
|
|
957
865
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -962,11 +870,10 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
962
870
|
getNextPageParamExpr,
|
|
963
871
|
getPreviousPageParamExpr
|
|
964
872
|
].filter(Boolean);
|
|
965
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
} as ${queryParamsTypeName}` : "";
|
|
873
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
874
|
+
...(params ?? {}),
|
|
875
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
876
|
+
} as ${queryParamsTypeName}` : "";
|
|
970
877
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
971
878
|
name,
|
|
972
879
|
isExportable: true,
|
|
@@ -976,16 +883,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
976
883
|
export: true,
|
|
977
884
|
params: paramsSignature,
|
|
978
885
|
children: `
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
})
|
|
886
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
887
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
888
|
+
queryKey,
|
|
889
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
890
|
+
${infiniteOverrideParams}
|
|
891
|
+
return ${clientName}(${clientCallStr})
|
|
892
|
+
},
|
|
893
|
+
${queryOptionsArr.join(",\n ")}
|
|
894
|
+
})
|
|
989
895
|
`
|
|
990
896
|
})
|
|
991
897
|
});
|
|
@@ -998,15 +904,14 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
998
904
|
export: true,
|
|
999
905
|
params: paramsSignature,
|
|
1000
906
|
children: `
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
})
|
|
907
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
908
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
909
|
+
queryKey,
|
|
910
|
+
queryFn: async ({ signal }) => {
|
|
911
|
+
return ${clientName}(${clientCallStr})
|
|
912
|
+
},
|
|
913
|
+
${queryOptionsArr.join(",\n ")}
|
|
914
|
+
})
|
|
1010
915
|
`
|
|
1011
916
|
})
|
|
1012
917
|
});
|
|
@@ -1015,26 +920,23 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1015
920
|
//#region src/components/MutationOptions.tsx
|
|
1016
921
|
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1017
922
|
const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1018
|
-
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "
|
|
923
|
+
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1019
924
|
function buildMutationConfigParamsNode(node, resolver) {
|
|
1020
|
-
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
925
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params: [_kubb_core.ast.factory.createFunctionParameter({
|
|
1021
926
|
name: "config",
|
|
1022
|
-
type:
|
|
1023
|
-
variant: "reference",
|
|
1024
|
-
name: buildRequestConfigType(node, resolver)
|
|
1025
|
-
}),
|
|
927
|
+
type: buildRequestConfigType(node, resolver),
|
|
1026
928
|
default: "{}"
|
|
1027
929
|
})] });
|
|
1028
930
|
}
|
|
1029
931
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
1030
932
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1031
933
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1032
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
934
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1033
935
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1034
936
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1035
937
|
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
1036
938
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
1037
|
-
const mutationArgParamsNode =
|
|
939
|
+
const mutationArgParamsNode = (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1038
940
|
paramsType: "inline",
|
|
1039
941
|
pathParamsType: "inline",
|
|
1040
942
|
paramsCasing,
|
|
@@ -1043,17 +945,14 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
1043
945
|
const hasMutationParams = mutationArgParamsNode.params.length > 0;
|
|
1044
946
|
const TRequest = hasMutationParams ? declarationPrinter$5.print(mutationArgParamsNode) ?? "" : "";
|
|
1045
947
|
const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
|
|
1046
|
-
const clientCallParamsNode =
|
|
948
|
+
const clientCallParamsNode = (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1047
949
|
paramsType,
|
|
1048
950
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1049
951
|
paramsCasing,
|
|
1050
952
|
resolver: tsResolver,
|
|
1051
|
-
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
953
|
+
extraParams: [_kubb_core.ast.factory.createFunctionParameter({
|
|
1052
954
|
name: "config",
|
|
1053
|
-
type:
|
|
1054
|
-
variant: "reference",
|
|
1055
|
-
name: buildRequestConfigType(node, tsResolver)
|
|
1056
|
-
}),
|
|
955
|
+
type: buildRequestConfigType(node, tsResolver),
|
|
1057
956
|
default: "{}"
|
|
1058
957
|
})]
|
|
1059
958
|
});
|
|
@@ -1084,7 +983,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
1084
983
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1085
984
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1086
985
|
function createMutationArgParams(node, options) {
|
|
1087
|
-
return
|
|
986
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1088
987
|
paramsType: "inline",
|
|
1089
988
|
pathParamsType: "inline",
|
|
1090
989
|
paramsCasing: options.paramsCasing,
|
|
@@ -1096,7 +995,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1096
995
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1097
996
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1098
997
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1099
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
998
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1100
999
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1101
1000
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1102
1001
|
paramsCasing,
|
|
@@ -1109,15 +1008,12 @@ function buildMutationParamsNode(node, options) {
|
|
|
1109
1008
|
TRequest ? `{${TRequest}}` : "undefined",
|
|
1110
1009
|
"TContext"
|
|
1111
1010
|
].join(", ");
|
|
1112
|
-
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
1011
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params: [_kubb_core.ast.factory.createFunctionParameter({
|
|
1113
1012
|
name: "options",
|
|
1114
|
-
type:
|
|
1115
|
-
variant: "reference",
|
|
1116
|
-
name: `{
|
|
1013
|
+
type: `{
|
|
1117
1014
|
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
1118
1015
|
client?: ${buildRequestConfigType(node, resolver)},
|
|
1119
|
-
}
|
|
1120
|
-
}),
|
|
1016
|
+
}`,
|
|
1121
1017
|
default: "{}"
|
|
1122
1018
|
})] });
|
|
1123
1019
|
}
|
|
@@ -1125,7 +1021,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1125
1021
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1126
1022
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1127
1023
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1128
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1024
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1129
1025
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1130
1026
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1131
1027
|
paramsCasing,
|
|
@@ -1162,11 +1058,10 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1162
1058
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1163
1059
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
1164
1060
|
|
|
1165
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
1166
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1061
|
+
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1167
1062
|
|
|
1168
1063
|
return useMutation<${generics}>({
|
|
1169
|
-
...baseOptions,${customOptions ? "\n...customOptions," : ""}
|
|
1064
|
+
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
1170
1065
|
mutationKey,
|
|
1171
1066
|
...mutationOptions,
|
|
1172
1067
|
}, queryClient) as ${returnType}
|
|
@@ -1184,26 +1079,23 @@ function buildQueryParamsNode(node, options) {
|
|
|
1184
1079
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1185
1080
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1186
1081
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1187
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1082
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1188
1083
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1189
|
-
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1084
|
+
const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
|
|
1190
1085
|
name: "options",
|
|
1191
|
-
type:
|
|
1192
|
-
variant: "reference",
|
|
1193
|
-
name: `{
|
|
1086
|
+
type: `{
|
|
1194
1087
|
query?: Partial<QueryObserverOptions<${[
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1088
|
+
TData,
|
|
1089
|
+
TError,
|
|
1090
|
+
"TData",
|
|
1091
|
+
"TQueryData",
|
|
1092
|
+
"TQueryKey"
|
|
1093
|
+
].join(", ")}>> & { client?: QueryClient },
|
|
1201
1094
|
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
|
|
1202
|
-
}
|
|
1203
|
-
}),
|
|
1095
|
+
}`,
|
|
1204
1096
|
default: "{}"
|
|
1205
1097
|
});
|
|
1206
|
-
return
|
|
1098
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1207
1099
|
paramsType,
|
|
1208
1100
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1209
1101
|
paramsCasing,
|
|
@@ -1215,7 +1107,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1215
1107
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1216
1108
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1217
1109
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1218
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1110
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1219
1111
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1220
1112
|
const generics = [
|
|
1221
1113
|
`TData = ${TData}`,
|
|
@@ -1258,11 +1150,10 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1258
1150
|
children: `
|
|
1259
1151
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1260
1152
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1261
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1262
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1153
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1263
1154
|
|
|
1264
1155
|
const query = useQuery({
|
|
1265
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1156
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1266
1157
|
...resolvedOptions,
|
|
1267
1158
|
queryKey,
|
|
1268
1159
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1281,18 +1172,15 @@ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
1281
1172
|
function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
1282
1173
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
1283
1174
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1284
|
-
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1175
|
+
const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
|
|
1285
1176
|
name: "options",
|
|
1286
|
-
type:
|
|
1287
|
-
variant: "reference",
|
|
1288
|
-
name: `{
|
|
1177
|
+
type: `{
|
|
1289
1178
|
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
1290
1179
|
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
|
|
1291
|
-
}
|
|
1292
|
-
}),
|
|
1180
|
+
}`,
|
|
1293
1181
|
default: "{}"
|
|
1294
1182
|
});
|
|
1295
|
-
return
|
|
1183
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1296
1184
|
paramsType,
|
|
1297
1185
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1298
1186
|
paramsCasing,
|
|
@@ -1304,7 +1192,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1304
1192
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1305
1193
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1306
1194
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1307
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
1195
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1308
1196
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1309
1197
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1310
1198
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -1362,11 +1250,10 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1362
1250
|
children: `
|
|
1363
1251
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1364
1252
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1365
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1366
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1253
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1367
1254
|
|
|
1368
1255
|
const query = useSuspenseInfiniteQuery({
|
|
1369
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1256
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1370
1257
|
...resolvedOptions,
|
|
1371
1258
|
queryKey,
|
|
1372
1259
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1385,7 +1272,7 @@ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
1385
1272
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1386
1273
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1387
1274
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1388
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
1275
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1389
1276
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1390
1277
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1391
1278
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1417,8 +1304,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1417
1304
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1418
1305
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1419
1306
|
if (hasNewParams) {
|
|
1420
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1421
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1307
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
1308
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
1422
1309
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1423
1310
|
}
|
|
1424
1311
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1429,11 +1316,10 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1429
1316
|
getNextPageParamExpr,
|
|
1430
1317
|
getPreviousPageParamExpr
|
|
1431
1318
|
].filter(Boolean);
|
|
1432
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
} as ${queryParamsTypeName}` : "";
|
|
1319
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
1320
|
+
...(params ?? {}),
|
|
1321
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1322
|
+
} as ${queryParamsTypeName}` : "";
|
|
1437
1323
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1438
1324
|
name,
|
|
1439
1325
|
isExportable: true,
|
|
@@ -1443,15 +1329,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1443
1329
|
export: true,
|
|
1444
1330
|
params: paramsSignature,
|
|
1445
1331
|
children: `
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1332
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1333
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1334
|
+
queryKey,
|
|
1335
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
1336
|
+
${infiniteOverrideParams}
|
|
1337
|
+
return ${clientName}(${clientCallStr})
|
|
1338
|
+
},
|
|
1339
|
+
${queryOptionsArr.join(",\n ")}
|
|
1340
|
+
})
|
|
1455
1341
|
`
|
|
1456
1342
|
})
|
|
1457
1343
|
});
|
|
@@ -1464,14 +1350,14 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1464
1350
|
export: true,
|
|
1465
1351
|
params: paramsSignature,
|
|
1466
1352
|
children: `
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1353
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1354
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1355
|
+
queryKey,
|
|
1356
|
+
queryFn: async ({ signal }) => {
|
|
1357
|
+
return ${clientName}(${clientCallStr})
|
|
1358
|
+
},
|
|
1359
|
+
${queryOptionsArr.join(",\n ")}
|
|
1360
|
+
})
|
|
1475
1361
|
`
|
|
1476
1362
|
})
|
|
1477
1363
|
});
|
|
@@ -1486,25 +1372,22 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1486
1372
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1487
1373
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1488
1374
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1489
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1375
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1490
1376
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1491
|
-
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1377
|
+
const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
|
|
1492
1378
|
name: "options",
|
|
1493
|
-
type:
|
|
1494
|
-
variant: "reference",
|
|
1495
|
-
name: `{
|
|
1379
|
+
type: `{
|
|
1496
1380
|
query?: Partial<UseSuspenseQueryOptions<${[
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1381
|
+
TData,
|
|
1382
|
+
TError,
|
|
1383
|
+
"TData",
|
|
1384
|
+
"TQueryKey"
|
|
1385
|
+
].join(", ")}>> & { client?: QueryClient },
|
|
1502
1386
|
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
|
|
1503
|
-
}
|
|
1504
|
-
}),
|
|
1387
|
+
}`,
|
|
1505
1388
|
default: "{}"
|
|
1506
1389
|
});
|
|
1507
|
-
return
|
|
1390
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
1508
1391
|
paramsType,
|
|
1509
1392
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1510
1393
|
paramsCasing,
|
|
@@ -1516,7 +1399,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1516
1399
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1517
1400
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1518
1401
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1519
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1402
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1520
1403
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1521
1404
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1522
1405
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
@@ -1554,11 +1437,10 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1554
1437
|
children: `
|
|
1555
1438
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1556
1439
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1557
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1558
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1440
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1559
1441
|
|
|
1560
1442
|
const query = useSuspenseQuery({
|
|
1561
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1443
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1562
1444
|
...resolvedOptions,
|
|
1563
1445
|
queryKey,
|
|
1564
1446
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -1698,4 +1580,4 @@ Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
|
1698
1580
|
}
|
|
1699
1581
|
});
|
|
1700
1582
|
|
|
1701
|
-
//# sourceMappingURL=components-
|
|
1583
|
+
//# sourceMappingURL=components-B0j2b6y8.cjs.map
|