@kubb/plugin-react-query 5.0.0-beta.4 → 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/README.md +38 -91
- package/dist/{components-DTGLu4UV.js → components-DL0Cai7l.js} +570 -514
- package/dist/components-DL0Cai7l.js.map +1 -0
- package/dist/{components-dAKJEn9b.cjs → components-yMQOuFmI.cjs} +600 -514
- package/dist/components-yMQOuFmI.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +5 -77
- package/dist/components.js +1 -1
- package/dist/{generators-C_fbcjpG.js → generators-BG-Vcvfg.js} +444 -597
- package/dist/generators-BG-Vcvfg.js.map +1 -0
- package/dist/{generators-CWEQsdO9.cjs → generators-zGKP8yII.cjs} +442 -595
- package/dist/generators-zGKP8yII.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +49 -10
- package/dist/generators.js +1 -1
- package/dist/index.cjs +201 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +203 -30
- package/dist/index.js.map +1 -1
- package/dist/types-X7D0NSvJ.d.ts +396 -0
- package/package.json +18 -27
- package/src/components/InfiniteQuery.tsx +27 -17
- package/src/components/InfiniteQueryOptions.tsx +60 -81
- package/src/components/Mutation.tsx +39 -20
- package/src/components/MutationOptions.tsx +15 -14
- package/src/components/Query.tsx +18 -15
- package/src/components/QueryOptions.tsx +20 -56
- package/src/components/SuspenseInfiniteQuery.tsx +22 -17
- package/src/components/SuspenseInfiniteQueryOptions.tsx +51 -76
- package/src/components/SuspenseQuery.tsx +13 -15
- package/src/generators/customHookOptionsFileGenerator.tsx +16 -12
- package/src/generators/hookOptionsGenerator.tsx +42 -49
- package/src/generators/infiniteQueryGenerator.tsx +55 -80
- package/src/generators/mutationGenerator.tsx +54 -66
- package/src/generators/queryGenerator.tsx +52 -65
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +50 -67
- package/src/generators/suspenseQueryGenerator.tsx +54 -78
- package/src/plugin.ts +47 -33
- package/src/resolvers/resolverReactQuery.ts +104 -8
- package/src/types.ts +202 -68
- package/src/utils.ts +11 -33
- package/dist/components-DTGLu4UV.js.map +0 -1
- package/dist/components-dAKJEn9b.cjs.map +0 -1
- package/dist/generators-CWEQsdO9.cjs.map +0 -1
- package/dist/generators-C_fbcjpG.js.map +0 -1
- package/dist/types-DfaFRSBf.d.ts +0 -284
- package/extension.yaml +0 -938
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -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 // undefined
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
get params() {
|
|
265
|
-
return this.getParams();
|
|
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,64 +241,153 @@ 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
|
-
return `\`${prefix}${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
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
308
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
309
|
-
* Returns `undefined` when no path parameters are found.
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
314
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
getParams(replacer) {
|
|
318
|
-
const params = {};
|
|
319
|
-
this.#eachParam((_raw, param) => {
|
|
320
|
-
const key = replacer ? replacer(param) : param;
|
|
321
|
-
params[key] = key;
|
|
322
|
-
});
|
|
323
|
-
return Object.keys(params).length > 0 ? params : void 0;
|
|
324
|
-
}
|
|
325
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
326
|
-
*
|
|
327
|
-
* @example
|
|
328
|
-
* ```ts
|
|
329
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
toURLPath() {
|
|
333
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
334
|
-
}
|
|
335
244
|
};
|
|
336
245
|
//#endregion
|
|
246
|
+
//#region ../../internals/shared/src/operation.ts
|
|
247
|
+
/**
|
|
248
|
+
* Builds the `ResolverFileParams` every operation generator passes to
|
|
249
|
+
* `resolver.resolveFile`: a file named `name`, tagged by the operation's first
|
|
250
|
+
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
251
|
+
* that was repeated at dozens of call sites across the client and query plugins.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
function operationFileEntry(node, name, extname = ".ts") {
|
|
259
|
+
return {
|
|
260
|
+
name,
|
|
261
|
+
extname,
|
|
262
|
+
tag: node.tags[0] ?? "default",
|
|
263
|
+
path: node.path
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function getOperationLink(node, link) {
|
|
267
|
+
if (!link) return null;
|
|
268
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
269
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
270
|
+
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
271
|
+
}
|
|
272
|
+
function getContentTypeInfo(node) {
|
|
273
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
274
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
275
|
+
return {
|
|
276
|
+
contentTypes,
|
|
277
|
+
isMultipleContentTypes,
|
|
278
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
279
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
280
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function buildRequestConfigType(node, resolver) {
|
|
284
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
285
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
286
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
287
|
+
}
|
|
288
|
+
function buildOperationComments(node, options = {}) {
|
|
289
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
290
|
+
const linkComment = getOperationLink(node, link);
|
|
291
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
292
|
+
node.description && `@description ${node.description}`,
|
|
293
|
+
node.summary && `@summary ${node.summary}`,
|
|
294
|
+
linkComment,
|
|
295
|
+
node.deprecated && "@deprecated"
|
|
296
|
+
] : [
|
|
297
|
+
node.description && `@description ${node.description}`,
|
|
298
|
+
node.summary && `@summary ${node.summary}`,
|
|
299
|
+
node.deprecated && "@deprecated",
|
|
300
|
+
linkComment
|
|
301
|
+
]).filter((comment) => Boolean(comment));
|
|
302
|
+
if (!splitLines) return filteredComments;
|
|
303
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
304
|
+
}
|
|
305
|
+
function getOperationParameters(node, options = {}) {
|
|
306
|
+
const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
|
|
307
|
+
return {
|
|
308
|
+
path: params.filter((param) => param.in === "path"),
|
|
309
|
+
query: params.filter((param) => param.in === "query"),
|
|
310
|
+
header: params.filter((param) => param.in === "header"),
|
|
311
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function getStatusCodeNumber(statusCode) {
|
|
315
|
+
const code = Number(statusCode);
|
|
316
|
+
return Number.isNaN(code) ? null : code;
|
|
317
|
+
}
|
|
318
|
+
function isSuccessStatusCode(statusCode) {
|
|
319
|
+
const code = getStatusCodeNumber(statusCode);
|
|
320
|
+
return code !== null && code >= 200 && code < 300;
|
|
321
|
+
}
|
|
322
|
+
function isErrorStatusCode(statusCode) {
|
|
323
|
+
const code = getStatusCodeNumber(statusCode);
|
|
324
|
+
return code !== null && code >= 400;
|
|
325
|
+
}
|
|
326
|
+
function resolveErrorNames(node, resolver) {
|
|
327
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
328
|
+
}
|
|
329
|
+
function resolveSuccessNames(node, resolver) {
|
|
330
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
331
|
+
}
|
|
332
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
333
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
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
|
+
}
|
|
348
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
349
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
350
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
351
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
352
|
+
if (byResolver) {
|
|
353
|
+
const cached = byResolver.get(cacheKey);
|
|
354
|
+
if (cached) return cached;
|
|
355
|
+
} else {
|
|
356
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
357
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
358
|
+
}
|
|
359
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
360
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
361
|
+
const exclude = new Set(options.exclude ?? []);
|
|
362
|
+
const paramNames = [
|
|
363
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
364
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
365
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
366
|
+
];
|
|
367
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
368
|
+
const result = (options.order === "body-response-first" ? [
|
|
369
|
+
...bodyAndResponseNames,
|
|
370
|
+
...paramNames,
|
|
371
|
+
...responseStatusNames
|
|
372
|
+
] : [
|
|
373
|
+
...paramNames,
|
|
374
|
+
...bodyAndResponseNames,
|
|
375
|
+
...responseStatusNames
|
|
376
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
377
|
+
byResolver.set(cacheKey, result);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
337
381
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
338
382
|
const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}, "getTransformer");
|
|
346
|
-
function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1 }) {
|
|
347
|
-
const paramsNode = getParams$6();
|
|
383
|
+
const mutationKeyTransformer = ({ node }) => {
|
|
384
|
+
if (!node.path) return [];
|
|
385
|
+
return [`{ url: '${Url.toPath(node.path)}' }`];
|
|
386
|
+
};
|
|
387
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
388
|
+
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
348
389
|
const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
|
|
349
|
-
const keys = transformer({
|
|
390
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
350
391
|
node,
|
|
351
392
|
casing: paramsCasing
|
|
352
393
|
});
|
|
@@ -363,28 +404,98 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
363
404
|
})
|
|
364
405
|
});
|
|
365
406
|
}
|
|
366
|
-
MutationKey.getParams = getParams$6;
|
|
367
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
368
407
|
//#endregion
|
|
369
408
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
370
409
|
/**
|
|
371
|
-
*
|
|
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`.
|
|
372
414
|
*/
|
|
373
|
-
function
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
+
}
|
|
433
|
+
function matchesPattern(node, ov) {
|
|
434
|
+
const { type, pattern } = ov;
|
|
435
|
+
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
436
|
+
if (type === "operationId") return matches(node.operationId);
|
|
437
|
+
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
438
|
+
if (type === "path") return node.path !== void 0 && matches(node.path);
|
|
439
|
+
if (type === "method") return node.method !== void 0 && matches(node.method);
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Resolves per-operation overrides (first matching override wins).
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* const opts = resolveOperationOverrides(node, override)
|
|
448
|
+
* const queryOpts = 'query' in opts ? opts.query : defaultQuery
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
function resolveOperationOverrides(node, override) {
|
|
452
|
+
if (!override) return {};
|
|
453
|
+
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
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;
|
|
380
463
|
}
|
|
381
464
|
/**
|
|
382
|
-
*
|
|
465
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
466
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
383
467
|
*/
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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.
|
|
483
|
+
*
|
|
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.
|
|
490
|
+
*/
|
|
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));
|
|
388
499
|
}
|
|
389
500
|
/**
|
|
390
501
|
* Resolve the type for a single path parameter.
|
|
@@ -408,30 +519,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
408
519
|
}
|
|
409
520
|
/**
|
|
410
521
|
* Derive a query-params group type from the resolver.
|
|
411
|
-
* Returns `
|
|
522
|
+
* Returns `null` when no query params exist or when the group name
|
|
412
523
|
* equals the individual param name (no real group).
|
|
413
524
|
*/
|
|
414
525
|
function resolveQueryGroupType(node, params, resolver) {
|
|
415
|
-
if (!params.length) return
|
|
526
|
+
if (!params.length) return null;
|
|
416
527
|
const firstParam = params[0];
|
|
417
528
|
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
418
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return
|
|
419
|
-
return {
|
|
420
|
-
type: _kubb_core.ast.createParamsType({
|
|
421
|
-
variant: "reference",
|
|
422
|
-
name: groupName
|
|
423
|
-
}),
|
|
424
|
-
optional: params.every((p) => !p.required)
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Derive a header-params group type from the resolver.
|
|
429
|
-
*/
|
|
430
|
-
function resolveHeaderGroupType(node, params, resolver) {
|
|
431
|
-
if (!params.length) return void 0;
|
|
432
|
-
const firstParam = params[0];
|
|
433
|
-
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
434
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
529
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
435
530
|
return {
|
|
436
531
|
type: _kubb_core.ast.createParamsType({
|
|
437
532
|
variant: "reference",
|
|
@@ -481,7 +576,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
576
|
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
482
577
|
variant: "reference",
|
|
483
578
|
name: resolver.resolveDataName(node)
|
|
484
|
-
}) :
|
|
579
|
+
}) : null;
|
|
485
580
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
486
581
|
const params = [];
|
|
487
582
|
if (pathParams.length) {
|
|
@@ -506,66 +601,101 @@ function buildQueryKeyParams(node, options) {
|
|
|
506
601
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
507
602
|
}
|
|
508
603
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
604
|
+
* Collect the names of the required params (no default) that drive the `enabled`
|
|
605
|
+
* guard. These are exactly the params that should be made optional in the
|
|
606
|
+
* generated signatures so callers can pass `undefined` to reach the disabled state.
|
|
511
607
|
*/
|
|
512
|
-
function
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
608
|
+
function getEnabledParamNames(paramsNode) {
|
|
609
|
+
const required = [];
|
|
610
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
611
|
+
const group = param;
|
|
612
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
613
|
+
} else {
|
|
614
|
+
const fp = param;
|
|
615
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
616
|
+
}
|
|
617
|
+
return required;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Return a copy of `paramsNode` with the named params marked optional.
|
|
621
|
+
*
|
|
622
|
+
* Used to align signatures with the `enabled` guard: the guard already disables
|
|
623
|
+
* the query while a param is falsy, so the param should accept `undefined`. The
|
|
624
|
+
* change is type-only — the `queryFn` keeps calling the client with a non-null
|
|
625
|
+
* assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
|
|
626
|
+
*/
|
|
627
|
+
function markParamsOptional(paramsNode, names) {
|
|
628
|
+
if (names.length === 0) return paramsNode;
|
|
629
|
+
const nameSet = new Set(names);
|
|
630
|
+
const params = paramsNode.params.map((param) => {
|
|
631
|
+
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
632
|
+
const group = param;
|
|
633
|
+
return {
|
|
634
|
+
...group,
|
|
635
|
+
properties: group.properties.map((child) => nameSet.has(child.name) ? _kubb_core.ast.createFunctionParameter({
|
|
636
|
+
name: child.name,
|
|
637
|
+
type: child.type,
|
|
638
|
+
rest: child.rest,
|
|
639
|
+
optional: true
|
|
640
|
+
}) : child)
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
const fp = param;
|
|
644
|
+
return nameSet.has(fp.name) ? _kubb_core.ast.createFunctionParameter({
|
|
645
|
+
name: fp.name,
|
|
646
|
+
type: fp.type,
|
|
647
|
+
rest: fp.rest,
|
|
648
|
+
optional: true
|
|
649
|
+
}) : fp;
|
|
650
|
+
});
|
|
538
651
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
539
652
|
}
|
|
653
|
+
/**
|
|
654
|
+
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
655
|
+
* string. Bridges the type gap created by `markParamsOptional` while keeping the
|
|
656
|
+
* runtime identical (the `!` is erased at compile time).
|
|
657
|
+
*
|
|
658
|
+
* Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
|
|
659
|
+
* standalone identifiers (`params` → `params!`).
|
|
660
|
+
*/
|
|
661
|
+
function injectNonNullAssertions(callStr, names) {
|
|
662
|
+
if (names.length === 0) return callStr;
|
|
663
|
+
const nameSet = new Set(names);
|
|
664
|
+
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
665
|
+
if (inner.includes(":") || inner.includes("...")) return match;
|
|
666
|
+
const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
|
|
667
|
+
if (!keys.some((k) => nameSet.has(k))) return match;
|
|
668
|
+
return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
|
|
669
|
+
});
|
|
670
|
+
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
|
|
671
|
+
return result;
|
|
672
|
+
}
|
|
540
673
|
//#endregion
|
|
541
674
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
542
675
|
const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
__name(getParams$5, "getParams");
|
|
548
|
-
const getTransformer = ({ node, casing }) => {
|
|
549
|
-
const path = new URLPath(node.path, { casing });
|
|
550
|
-
const hasQueryParams = node.parameters.some((p) => p.in === "query");
|
|
676
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
677
|
+
if (!node.path) return [];
|
|
678
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
551
679
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
552
680
|
return [
|
|
553
|
-
|
|
681
|
+
Url.toObject(node.path, {
|
|
554
682
|
type: "path",
|
|
555
|
-
stringify: true
|
|
683
|
+
stringify: true,
|
|
684
|
+
casing
|
|
556
685
|
}),
|
|
557
|
-
hasQueryParams ? "...(params ? [params] : [])" :
|
|
558
|
-
hasRequestBody ? "...(data ? [data] : [])" :
|
|
686
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
687
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
559
688
|
].filter(Boolean);
|
|
560
689
|
};
|
|
561
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer
|
|
562
|
-
const
|
|
690
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
691
|
+
const baseParamsNode = buildQueryKeyParams(node, {
|
|
563
692
|
pathParamsType,
|
|
564
693
|
paramsCasing,
|
|
565
694
|
resolver: tsResolver
|
|
566
695
|
});
|
|
696
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
|
|
567
697
|
const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
|
|
568
|
-
const keys = transformer({
|
|
698
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
569
699
|
node,
|
|
570
700
|
casing: paramsCasing
|
|
571
701
|
});
|
|
@@ -589,84 +719,36 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
589
719
|
})
|
|
590
720
|
})] });
|
|
591
721
|
}
|
|
592
|
-
QueryKey.getParams = getParams$5;
|
|
593
|
-
QueryKey.getTransformer = getTransformer;
|
|
594
|
-
QueryKey.callPrinter = callPrinter$9;
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region src/utils.ts
|
|
597
|
-
function transformName(name, type, transformers) {
|
|
598
|
-
return transformers?.name?.(name, type) || name;
|
|
599
|
-
}
|
|
600
|
-
function matchesPattern(node, ov) {
|
|
601
|
-
const { type, pattern } = ov;
|
|
602
|
-
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
603
|
-
if (type === "operationId") return matches(node.operationId);
|
|
604
|
-
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
605
|
-
if (type === "path") return matches(node.path);
|
|
606
|
-
if (type === "method") return matches(node.method);
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Resolves per-operation overrides (first matching override wins), mirroring v4 OperationGenerator.getOptions().
|
|
611
|
-
*/
|
|
612
|
-
function resolveOperationOverrides(node, override) {
|
|
613
|
-
if (!override) return {};
|
|
614
|
-
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
615
|
-
}
|
|
616
722
|
//#endregion
|
|
617
723
|
//#region src/components/QueryOptions.tsx
|
|
618
724
|
const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
619
725
|
const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
620
726
|
function getQueryOptionsParams(node, options) {
|
|
621
|
-
|
|
622
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
623
|
-
return _kubb_core.ast.createOperationParams(node, {
|
|
624
|
-
paramsType,
|
|
625
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
626
|
-
paramsCasing,
|
|
627
|
-
resolver,
|
|
628
|
-
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
629
|
-
name: "config",
|
|
630
|
-
type: _kubb_core.ast.createParamsType({
|
|
631
|
-
variant: "reference",
|
|
632
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
633
|
-
}),
|
|
634
|
-
default: "{}"
|
|
635
|
-
})]
|
|
636
|
-
});
|
|
727
|
+
return buildQueryOptionsParams(node, options);
|
|
637
728
|
}
|
|
638
|
-
function
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
const group = param;
|
|
642
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
643
|
-
} else {
|
|
644
|
-
const fp = param;
|
|
645
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
646
|
-
}
|
|
647
|
-
return required.join(" && ");
|
|
648
|
-
}
|
|
649
|
-
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
650
|
-
const responseName = tsResolver.resolveResponseName(node);
|
|
729
|
+
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
730
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
731
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
651
732
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
652
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
733
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
653
734
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
654
|
-
const
|
|
655
|
-
paramsType,
|
|
656
|
-
paramsCasing,
|
|
657
|
-
pathParamsType,
|
|
658
|
-
resolver: tsResolver
|
|
659
|
-
});
|
|
660
|
-
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
661
|
-
const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
662
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
735
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
663
736
|
pathParamsType,
|
|
664
737
|
paramsCasing,
|
|
665
738
|
resolver: tsResolver
|
|
666
739
|
});
|
|
667
740
|
const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
|
|
668
|
-
const
|
|
669
|
-
const
|
|
741
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
742
|
+
const optionalNames = suspense ? [] : enabledNames;
|
|
743
|
+
const enabledText = suspense ? "" : enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
744
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
745
|
+
paramsType,
|
|
746
|
+
paramsCasing,
|
|
747
|
+
pathParamsType,
|
|
748
|
+
resolver: tsResolver
|
|
749
|
+
}), optionalNames);
|
|
750
|
+
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
751
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), optionalNames);
|
|
670
752
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
671
753
|
name,
|
|
672
754
|
isExportable: true,
|
|
@@ -677,8 +759,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
677
759
|
params: paramsSignature,
|
|
678
760
|
children: `
|
|
679
761
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
680
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
681
|
-
${enabledText}
|
|
762
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
|
|
682
763
|
queryKey,
|
|
683
764
|
queryFn: async ({ signal }) => {
|
|
684
765
|
return ${clientName}(${clientCallStr})
|
|
@@ -688,14 +769,13 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
688
769
|
})
|
|
689
770
|
});
|
|
690
771
|
}
|
|
691
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
692
772
|
//#endregion
|
|
693
773
|
//#region src/components/InfiniteQuery.tsx
|
|
694
774
|
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
695
775
|
const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
696
|
-
function
|
|
776
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
697
777
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
698
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
778
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
699
779
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
700
780
|
name: "options",
|
|
701
781
|
type: _kubb_core.ast.createParamsType({
|
|
@@ -715,23 +795,23 @@ function getParams$4(node, options) {
|
|
|
715
795
|
extraParams: [optionsParam]
|
|
716
796
|
});
|
|
717
797
|
}
|
|
718
|
-
__name(getParams$4, "getParams");
|
|
719
798
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
720
|
-
const
|
|
799
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
800
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
721
801
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
722
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
802
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
723
803
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
724
804
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
725
805
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
726
806
|
const parts = initialPageParam.split(" as ");
|
|
727
807
|
return parts[parts.length - 1] ?? "unknown";
|
|
728
808
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
729
|
-
const rawQueryParams = node
|
|
809
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
730
810
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
731
811
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
732
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
733
|
-
})() :
|
|
734
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
812
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
813
|
+
})() : null;
|
|
814
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
735
815
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
736
816
|
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
737
817
|
const generics = [
|
|
@@ -741,12 +821,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
741
821
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
742
822
|
`TPageParam = ${pageParamType}`
|
|
743
823
|
];
|
|
744
|
-
const queryKeyParamsNode =
|
|
824
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
745
825
|
pathParamsType,
|
|
746
826
|
paramsCasing,
|
|
747
827
|
resolver: tsResolver
|
|
748
828
|
});
|
|
749
829
|
const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
|
|
830
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
750
831
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
751
832
|
paramsType,
|
|
752
833
|
paramsCasing,
|
|
@@ -754,14 +835,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
754
835
|
resolver: tsResolver
|
|
755
836
|
});
|
|
756
837
|
const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
|
|
757
|
-
const paramsNode =
|
|
838
|
+
const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
|
|
758
839
|
paramsType,
|
|
759
840
|
paramsCasing,
|
|
760
841
|
pathParamsType,
|
|
761
842
|
dataReturnType,
|
|
762
843
|
resolver: tsResolver,
|
|
763
844
|
pageParamGeneric: "TPageParam"
|
|
764
|
-
});
|
|
845
|
+
}), enabledNames);
|
|
765
846
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
766
847
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
767
848
|
name,
|
|
@@ -773,15 +854,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
773
854
|
generics: generics.join(", "),
|
|
774
855
|
params: paramsSignature,
|
|
775
856
|
returnType: void 0,
|
|
776
|
-
JSDoc: { comments:
|
|
857
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
777
858
|
children: `
|
|
778
859
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
779
860
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
780
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
781
|
-
${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}' })` : ""}
|
|
782
862
|
|
|
783
863
|
const query = useInfiniteQuery({
|
|
784
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
864
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
785
865
|
...resolvedOptions,
|
|
786
866
|
queryKey,
|
|
787
867
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -793,14 +873,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
793
873
|
})
|
|
794
874
|
});
|
|
795
875
|
}
|
|
796
|
-
InfiniteQuery.getParams = getParams$4;
|
|
797
876
|
//#endregion
|
|
798
877
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
799
878
|
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
800
879
|
const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
801
880
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
802
|
-
const
|
|
803
|
-
const
|
|
881
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
882
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
883
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
804
884
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
805
885
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
806
886
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -808,59 +888,48 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
808
888
|
const parts = initialPageParam.split(" as ");
|
|
809
889
|
return parts[parts.length - 1] ?? "unknown";
|
|
810
890
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
811
|
-
const rawQueryParams = node
|
|
891
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
812
892
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
813
893
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
814
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
815
|
-
})() :
|
|
816
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
894
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
895
|
+
})() : null;
|
|
896
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
817
897
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
818
|
-
const
|
|
819
|
-
paramsType,
|
|
820
|
-
paramsCasing,
|
|
821
|
-
pathParamsType,
|
|
822
|
-
resolver: tsResolver
|
|
823
|
-
});
|
|
824
|
-
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
825
|
-
const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
826
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
898
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
827
899
|
pathParamsType,
|
|
828
900
|
paramsCasing,
|
|
829
901
|
resolver: tsResolver
|
|
830
902
|
});
|
|
831
903
|
const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
|
|
832
|
-
const
|
|
833
|
-
const enabledText =
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
904
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
905
|
+
const enabledText = enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
906
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
907
|
+
paramsType,
|
|
908
|
+
paramsCasing,
|
|
909
|
+
pathParamsType,
|
|
910
|
+
resolver: tsResolver
|
|
911
|
+
}), enabledNames);
|
|
912
|
+
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
913
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), enabledNames);
|
|
914
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
915
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
916
|
+
if (hasNewParams) {
|
|
917
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
918
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
919
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
845
920
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
} else {
|
|
850
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
851
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
852
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
853
|
-
}
|
|
921
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
922
|
+
return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
|
|
923
|
+
})();
|
|
854
924
|
const queryOptionsArr = [
|
|
855
925
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
856
926
|
getNextPageParamExpr,
|
|
857
927
|
getPreviousPageParamExpr
|
|
858
928
|
].filter(Boolean);
|
|
859
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
} as ${queryParamsTypeName}` : "";
|
|
929
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
930
|
+
...(params ?? {}),
|
|
931
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
932
|
+
} as ${queryParamsTypeName}` : "";
|
|
864
933
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
865
934
|
name,
|
|
866
935
|
isExportable: true,
|
|
@@ -870,16 +939,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
870
939
|
export: true,
|
|
871
940
|
params: paramsSignature,
|
|
872
941
|
children: `
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
})
|
|
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
|
+
})
|
|
883
951
|
`
|
|
884
952
|
})
|
|
885
953
|
});
|
|
@@ -892,44 +960,44 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
892
960
|
export: true,
|
|
893
961
|
params: paramsSignature,
|
|
894
962
|
children: `
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
})
|
|
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
|
+
})
|
|
904
971
|
`
|
|
905
972
|
})
|
|
906
973
|
});
|
|
907
974
|
}
|
|
908
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
909
975
|
//#endregion
|
|
910
976
|
//#region src/components/MutationOptions.tsx
|
|
911
977
|
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
912
978
|
const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
913
979
|
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
914
|
-
function
|
|
915
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
980
|
+
function buildMutationConfigParamsNode(node, resolver) {
|
|
916
981
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
917
982
|
name: "config",
|
|
918
983
|
type: _kubb_core.ast.createParamsType({
|
|
919
984
|
variant: "reference",
|
|
920
|
-
name:
|
|
985
|
+
name: buildRequestConfigType(node, resolver)
|
|
921
986
|
}),
|
|
922
987
|
default: "{}"
|
|
923
988
|
})] });
|
|
924
989
|
}
|
|
925
990
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
926
|
-
const
|
|
927
|
-
const
|
|
991
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
992
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
993
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
928
994
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
929
995
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
930
|
-
const configParamsNode =
|
|
996
|
+
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
931
997
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
932
|
-
const mutationArgParamsNode =
|
|
998
|
+
const mutationArgParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
999
|
+
paramsType: "inline",
|
|
1000
|
+
pathParamsType: "inline",
|
|
933
1001
|
paramsCasing,
|
|
934
1002
|
resolver: tsResolver
|
|
935
1003
|
});
|
|
@@ -945,7 +1013,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
945
1013
|
name: "config",
|
|
946
1014
|
type: _kubb_core.ast.createParamsType({
|
|
947
1015
|
variant: "reference",
|
|
948
|
-
name: node
|
|
1016
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
949
1017
|
}),
|
|
950
1018
|
default: "{}"
|
|
951
1019
|
})]
|
|
@@ -962,7 +1030,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
962
1030
|
generics: ["TContext = unknown"],
|
|
963
1031
|
children: `
|
|
964
1032
|
const mutationKey = ${mutationKeyName}()
|
|
965
|
-
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "
|
|
1033
|
+
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "undefined"}, TContext>({
|
|
966
1034
|
mutationKey,
|
|
967
1035
|
mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
|
|
968
1036
|
return ${clientName}(${clientCallStr})
|
|
@@ -972,19 +1040,26 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
972
1040
|
})
|
|
973
1041
|
});
|
|
974
1042
|
}
|
|
975
|
-
MutationOptions.getParams = getConfigParam;
|
|
976
1043
|
//#endregion
|
|
977
1044
|
//#region src/components/Mutation.tsx
|
|
978
1045
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
979
1046
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
980
|
-
function
|
|
1047
|
+
function createMutationArgParams(node, options) {
|
|
1048
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
1049
|
+
paramsType: "inline",
|
|
1050
|
+
pathParamsType: "inline",
|
|
1051
|
+
paramsCasing: options.paramsCasing,
|
|
1052
|
+
resolver: options.resolver
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
function buildMutationParamsNode(node, options) {
|
|
981
1056
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
982
|
-
const
|
|
983
|
-
const
|
|
1057
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1058
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
984
1059
|
const errorNames = resolveErrorNames(node, resolver);
|
|
985
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1060
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
986
1061
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
987
|
-
const mutationArgParamsNode =
|
|
1062
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
988
1063
|
paramsCasing,
|
|
989
1064
|
resolver
|
|
990
1065
|
});
|
|
@@ -992,7 +1067,7 @@ function getParams$3(node, options) {
|
|
|
992
1067
|
const generics = [
|
|
993
1068
|
TData,
|
|
994
1069
|
TError,
|
|
995
|
-
TRequest ? `{${TRequest}}` : "
|
|
1070
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
996
1071
|
"TContext"
|
|
997
1072
|
].join(", ");
|
|
998
1073
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
@@ -1001,19 +1076,19 @@ function getParams$3(node, options) {
|
|
|
1001
1076
|
variant: "reference",
|
|
1002
1077
|
name: `{
|
|
1003
1078
|
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
1004
|
-
client?: ${
|
|
1079
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
1005
1080
|
}`
|
|
1006
1081
|
}),
|
|
1007
1082
|
default: "{}"
|
|
1008
1083
|
})] });
|
|
1009
1084
|
}
|
|
1010
|
-
__name(getParams$3, "getParams");
|
|
1011
1085
|
function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1012
|
-
const
|
|
1086
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1087
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1013
1088
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1014
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1089
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1015
1090
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1016
|
-
const mutationArgParamsNode =
|
|
1091
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1017
1092
|
paramsCasing,
|
|
1018
1093
|
resolver: tsResolver
|
|
1019
1094
|
});
|
|
@@ -1021,13 +1096,13 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1021
1096
|
const generics = [
|
|
1022
1097
|
TData,
|
|
1023
1098
|
TError,
|
|
1024
|
-
TRequest ? `{${TRequest}}` : "
|
|
1099
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1025
1100
|
"TContext"
|
|
1026
1101
|
].join(", ");
|
|
1027
1102
|
const returnType = `UseMutationResult<${generics}>`;
|
|
1028
|
-
const mutationOptionsConfigNode =
|
|
1103
|
+
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
1029
1104
|
const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
|
|
1030
|
-
const paramsNode =
|
|
1105
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1031
1106
|
paramsCasing,
|
|
1032
1107
|
dataReturnType,
|
|
1033
1108
|
resolver: tsResolver
|
|
@@ -1041,18 +1116,17 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1041
1116
|
name,
|
|
1042
1117
|
export: true,
|
|
1043
1118
|
params: paramsSignature,
|
|
1044
|
-
JSDoc: { comments:
|
|
1119
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1045
1120
|
generics: ["TContext"],
|
|
1046
1121
|
children: `
|
|
1047
1122
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
1048
1123
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1049
1124
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
1050
1125
|
|
|
1051
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
1052
|
-
${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}>` : ""}
|
|
1053
1127
|
|
|
1054
1128
|
return useMutation<${generics}>({
|
|
1055
|
-
...baseOptions,${customOptions ? "\n...customOptions," : ""}
|
|
1129
|
+
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
1056
1130
|
mutationKey,
|
|
1057
1131
|
...mutationOptions,
|
|
1058
1132
|
}, queryClient) as ${returnType}
|
|
@@ -1060,17 +1134,17 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1060
1134
|
})
|
|
1061
1135
|
});
|
|
1062
1136
|
}
|
|
1063
|
-
Mutation.getParams = getParams$3;
|
|
1064
1137
|
//#endregion
|
|
1065
1138
|
//#region src/components/Query.tsx
|
|
1066
1139
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1067
1140
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1068
|
-
function
|
|
1141
|
+
function buildQueryParamsNode(node, options) {
|
|
1069
1142
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1070
|
-
const
|
|
1071
|
-
const
|
|
1143
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1144
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1145
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1072
1146
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1073
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1147
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1074
1148
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1075
1149
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1076
1150
|
name: "options",
|
|
@@ -1097,23 +1171,24 @@ function getParams$2(node, options) {
|
|
|
1097
1171
|
extraParams: [optionsParam]
|
|
1098
1172
|
});
|
|
1099
1173
|
}
|
|
1100
|
-
__name(getParams$2, "getParams");
|
|
1101
1174
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1102
|
-
const
|
|
1175
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1176
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1103
1177
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1104
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1178
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1105
1179
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1106
1180
|
const generics = [
|
|
1107
1181
|
`TData = ${TData}`,
|
|
1108
1182
|
`TQueryData = ${TData}`,
|
|
1109
1183
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1110
1184
|
];
|
|
1111
|
-
const queryKeyParamsNode =
|
|
1185
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1112
1186
|
pathParamsType,
|
|
1113
1187
|
paramsCasing,
|
|
1114
1188
|
resolver: tsResolver
|
|
1115
1189
|
});
|
|
1116
1190
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
1191
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
1117
1192
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
1118
1193
|
paramsType,
|
|
1119
1194
|
paramsCasing,
|
|
@@ -1121,13 +1196,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1121
1196
|
resolver: tsResolver
|
|
1122
1197
|
});
|
|
1123
1198
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
1124
|
-
const paramsNode =
|
|
1199
|
+
const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
|
|
1125
1200
|
paramsType,
|
|
1126
1201
|
paramsCasing,
|
|
1127
1202
|
pathParamsType,
|
|
1128
1203
|
dataReturnType,
|
|
1129
1204
|
resolver: tsResolver
|
|
1130
|
-
});
|
|
1205
|
+
}), enabledNames);
|
|
1131
1206
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
1132
1207
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1133
1208
|
name,
|
|
@@ -1139,15 +1214,14 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1139
1214
|
generics: generics.join(", "),
|
|
1140
1215
|
params: paramsSignature,
|
|
1141
1216
|
returnType: void 0,
|
|
1142
|
-
JSDoc: { comments:
|
|
1217
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1143
1218
|
children: `
|
|
1144
1219
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1145
1220
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1146
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1147
|
-
${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}' })` : ""}
|
|
1148
1222
|
|
|
1149
1223
|
const query = useQuery({
|
|
1150
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1224
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1151
1225
|
...resolvedOptions,
|
|
1152
1226
|
queryKey,
|
|
1153
1227
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1159,14 +1233,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1159
1233
|
})
|
|
1160
1234
|
});
|
|
1161
1235
|
}
|
|
1162
|
-
Query.getParams = getParams$2;
|
|
1163
1236
|
//#endregion
|
|
1164
1237
|
//#region src/components/SuspenseInfiniteQuery.tsx
|
|
1165
1238
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1166
1239
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1167
|
-
function
|
|
1240
|
+
function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
1168
1241
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
1169
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
1242
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1170
1243
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1171
1244
|
name: "options",
|
|
1172
1245
|
type: _kubb_core.ast.createParamsType({
|
|
@@ -1186,23 +1259,23 @@ function getParams$1(node, options) {
|
|
|
1186
1259
|
extraParams: [optionsParam]
|
|
1187
1260
|
});
|
|
1188
1261
|
}
|
|
1189
|
-
__name(getParams$1, "getParams");
|
|
1190
1262
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1191
|
-
const
|
|
1263
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1264
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1192
1265
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1193
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
1266
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1194
1267
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1195
1268
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1196
1269
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
1197
1270
|
const parts = initialPageParam.split(" as ");
|
|
1198
1271
|
return parts[parts.length - 1] ?? "unknown";
|
|
1199
1272
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1200
|
-
const rawQueryParams = node
|
|
1273
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1201
1274
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1202
1275
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1203
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1204
|
-
})() :
|
|
1205
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1276
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1277
|
+
})() : null;
|
|
1278
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1206
1279
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1207
1280
|
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1208
1281
|
const generics = [
|
|
@@ -1212,7 +1285,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1212
1285
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1213
1286
|
`TPageParam = ${pageParamType}`
|
|
1214
1287
|
];
|
|
1215
|
-
const queryKeyParamsNode =
|
|
1288
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1216
1289
|
pathParamsType,
|
|
1217
1290
|
paramsCasing,
|
|
1218
1291
|
resolver: tsResolver
|
|
@@ -1225,7 +1298,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1225
1298
|
resolver: tsResolver
|
|
1226
1299
|
});
|
|
1227
1300
|
const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
|
|
1228
|
-
const paramsNode =
|
|
1301
|
+
const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
|
|
1229
1302
|
paramsType,
|
|
1230
1303
|
paramsCasing,
|
|
1231
1304
|
pathParamsType,
|
|
@@ -1244,15 +1317,14 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1244
1317
|
generics: generics.join(", "),
|
|
1245
1318
|
params: paramsSignature,
|
|
1246
1319
|
returnType: void 0,
|
|
1247
|
-
JSDoc: { comments:
|
|
1320
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1248
1321
|
children: `
|
|
1249
1322
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1250
1323
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1251
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1252
|
-
${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}' })` : ""}
|
|
1253
1325
|
|
|
1254
1326
|
const query = useSuspenseInfiniteQuery({
|
|
1255
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1327
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1256
1328
|
...resolvedOptions,
|
|
1257
1329
|
queryKey,
|
|
1258
1330
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1264,14 +1336,14 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1264
1336
|
})
|
|
1265
1337
|
});
|
|
1266
1338
|
}
|
|
1267
|
-
SuspenseInfiniteQuery.getParams = getParams$1;
|
|
1268
1339
|
//#endregion
|
|
1269
1340
|
//#region src/components/SuspenseInfiniteQueryOptions.tsx
|
|
1270
1341
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1271
1342
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1272
1343
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1273
|
-
const
|
|
1274
|
-
const
|
|
1344
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1345
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1346
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1275
1347
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1276
1348
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1277
1349
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1279,12 +1351,12 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1279
1351
|
const parts = initialPageParam.split(" as ");
|
|
1280
1352
|
return parts[parts.length - 1] ?? "unknown";
|
|
1281
1353
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1282
|
-
const rawQueryParams = node
|
|
1354
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1283
1355
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1284
1356
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1285
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1286
|
-
})() :
|
|
1287
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1357
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1358
|
+
})() : null;
|
|
1359
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1288
1360
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1289
1361
|
const paramsNode = getQueryOptionsParams(node, {
|
|
1290
1362
|
paramsType,
|
|
@@ -1294,44 +1366,31 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1294
1366
|
});
|
|
1295
1367
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1296
1368
|
const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
1297
|
-
const queryKeyParamsNode =
|
|
1369
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1298
1370
|
pathParamsType,
|
|
1299
1371
|
paramsCasing,
|
|
1300
1372
|
resolver: tsResolver
|
|
1301
1373
|
});
|
|
1302
1374
|
const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
|
|
1303
|
-
const
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
if (nextParam) {
|
|
1310
|
-
const accessor = getNestedAccessor(nextParam, "lastPage");
|
|
1311
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
1375
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
1376
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1377
|
+
if (hasNewParams) {
|
|
1378
|
+
const nextAccessor = nextParam ? (0, _kubb_ast_utils.getNestedAccessor)(nextParam, "lastPage") : null;
|
|
1379
|
+
const prevAccessor = previousParam ? (0, _kubb_ast_utils.getNestedAccessor)(previousParam, "firstPage") : null;
|
|
1380
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1312
1381
|
}
|
|
1313
|
-
if (
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
} else if (cursorParam) {
|
|
1318
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1319
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1320
|
-
} else {
|
|
1321
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
1322
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
1323
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
1324
|
-
}
|
|
1382
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
1383
|
+
return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
|
|
1384
|
+
})();
|
|
1325
1385
|
const queryOptionsArr = [
|
|
1326
1386
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
1327
1387
|
getNextPageParamExpr,
|
|
1328
1388
|
getPreviousPageParamExpr
|
|
1329
1389
|
].filter(Boolean);
|
|
1330
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
} as ${queryParamsTypeName}` : "";
|
|
1390
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
1391
|
+
...(params ?? {}),
|
|
1392
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1393
|
+
} as ${queryParamsTypeName}` : "";
|
|
1335
1394
|
if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1336
1395
|
name,
|
|
1337
1396
|
isExportable: true,
|
|
@@ -1341,16 +1400,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1341
1400
|
export: true,
|
|
1342
1401
|
params: paramsSignature,
|
|
1343
1402
|
children: `
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
})
|
|
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
|
+
})
|
|
1354
1412
|
`
|
|
1355
1413
|
})
|
|
1356
1414
|
});
|
|
@@ -1363,30 +1421,29 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1363
1421
|
export: true,
|
|
1364
1422
|
params: paramsSignature,
|
|
1365
1423
|
children: `
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
})
|
|
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
|
+
})
|
|
1375
1432
|
`
|
|
1376
1433
|
})
|
|
1377
1434
|
});
|
|
1378
1435
|
}
|
|
1379
|
-
SuspenseInfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1380
1436
|
//#endregion
|
|
1381
1437
|
//#region src/components/SuspenseQuery.tsx
|
|
1382
1438
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1383
1439
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1384
|
-
function
|
|
1440
|
+
function buildSuspenseQueryParamsNode(node, options) {
|
|
1385
1441
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1386
|
-
const
|
|
1387
|
-
const
|
|
1442
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1443
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1444
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1388
1445
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1389
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1446
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1390
1447
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1391
1448
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1392
1449
|
name: "options",
|
|
@@ -1413,12 +1470,13 @@ function getParams(node, options) {
|
|
|
1413
1470
|
});
|
|
1414
1471
|
}
|
|
1415
1472
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1416
|
-
const
|
|
1473
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1474
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1417
1475
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1418
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1476
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1419
1477
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1420
1478
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1421
|
-
const queryKeyParamsNode =
|
|
1479
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1422
1480
|
pathParamsType,
|
|
1423
1481
|
paramsCasing,
|
|
1424
1482
|
resolver: tsResolver
|
|
@@ -1431,7 +1489,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1431
1489
|
resolver: tsResolver
|
|
1432
1490
|
});
|
|
1433
1491
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1434
|
-
const paramsNode =
|
|
1492
|
+
const paramsNode = buildSuspenseQueryParamsNode(node, {
|
|
1435
1493
|
paramsType,
|
|
1436
1494
|
paramsCasing,
|
|
1437
1495
|
pathParamsType,
|
|
@@ -1449,15 +1507,14 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1449
1507
|
generics: generics.join(", "),
|
|
1450
1508
|
params: paramsSignature,
|
|
1451
1509
|
returnType: void 0,
|
|
1452
|
-
JSDoc: { comments:
|
|
1510
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1453
1511
|
children: `
|
|
1454
1512
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1455
1513
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1456
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1457
|
-
${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}' })` : ""}
|
|
1458
1515
|
|
|
1459
1516
|
const query = useSuspenseQuery({
|
|
1460
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1517
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1461
1518
|
...resolvedOptions,
|
|
1462
1519
|
queryKey,
|
|
1463
1520
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -1469,7 +1526,6 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1469
1526
|
})
|
|
1470
1527
|
});
|
|
1471
1528
|
}
|
|
1472
|
-
SuspenseQuery.getParams = getParams;
|
|
1473
1529
|
//#endregion
|
|
1474
1530
|
Object.defineProperty(exports, "InfiniteQuery", {
|
|
1475
1531
|
enumerable: true,
|
|
@@ -1555,17 +1611,47 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
1555
1611
|
return camelCase;
|
|
1556
1612
|
}
|
|
1557
1613
|
});
|
|
1614
|
+
Object.defineProperty(exports, "getOperationParameters", {
|
|
1615
|
+
enumerable: true,
|
|
1616
|
+
get: function() {
|
|
1617
|
+
return getOperationParameters;
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
Object.defineProperty(exports, "mutationKeyTransformer", {
|
|
1621
|
+
enumerable: true,
|
|
1622
|
+
get: function() {
|
|
1623
|
+
return mutationKeyTransformer;
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
Object.defineProperty(exports, "operationFileEntry", {
|
|
1627
|
+
enumerable: true,
|
|
1628
|
+
get: function() {
|
|
1629
|
+
return operationFileEntry;
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
Object.defineProperty(exports, "queryKeyTransformer", {
|
|
1633
|
+
enumerable: true,
|
|
1634
|
+
get: function() {
|
|
1635
|
+
return queryKeyTransformer;
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1558
1638
|
Object.defineProperty(exports, "resolveOperationOverrides", {
|
|
1559
1639
|
enumerable: true,
|
|
1560
1640
|
get: function() {
|
|
1561
1641
|
return resolveOperationOverrides;
|
|
1562
1642
|
}
|
|
1563
1643
|
});
|
|
1564
|
-
Object.defineProperty(exports, "
|
|
1644
|
+
Object.defineProperty(exports, "resolveOperationTypeNames", {
|
|
1645
|
+
enumerable: true,
|
|
1646
|
+
get: function() {
|
|
1647
|
+
return resolveOperationTypeNames;
|
|
1648
|
+
}
|
|
1649
|
+
});
|
|
1650
|
+
Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
1565
1651
|
enumerable: true,
|
|
1566
1652
|
get: function() {
|
|
1567
|
-
return
|
|
1653
|
+
return resolveZodSchemaNames;
|
|
1568
1654
|
}
|
|
1569
1655
|
});
|
|
1570
1656
|
|
|
1571
|
-
//# sourceMappingURL=components-
|
|
1657
|
+
//# sourceMappingURL=components-yMQOuFmI.cjs.map
|