@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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import { ast } from "@kubb/core";
|
|
3
3
|
import { functionPrinter } from "@kubb/plugin-ts";
|
|
4
4
|
import { File, Function, Type } from "@kubb/renderer-jsx";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
6
|
+
import { getNestedAccessor } from "@kubb/ast/utils";
|
|
6
7
|
//#region ../../internals/utils/src/casing.ts
|
|
7
8
|
/**
|
|
8
9
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -14,50 +15,20 @@ import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
|
14
15
|
function toCamelOrPascal(text, pascal) {
|
|
15
16
|
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) => {
|
|
16
17
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
17
|
-
|
|
18
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
18
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
19
19
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
23
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
24
|
-
* Segments are joined with `/` to form a file path.
|
|
25
|
-
*
|
|
26
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
27
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
28
|
-
*/
|
|
29
|
-
function applyToFileParts(text, transformPart) {
|
|
30
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
31
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
22
|
* Converts `text` to camelCase.
|
|
35
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
36
23
|
*
|
|
37
|
-
* @example
|
|
38
|
-
* camelCase('hello-world')
|
|
39
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
40
|
-
*/
|
|
41
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
42
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
43
|
-
prefix,
|
|
44
|
-
suffix
|
|
45
|
-
} : {}));
|
|
46
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region ../../internals/utils/src/object.ts
|
|
50
|
-
/**
|
|
51
|
-
* Converts a dot-notation path or string array into an optional-chaining accessor expression.
|
|
24
|
+
* @example Word boundaries
|
|
25
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
52
26
|
*
|
|
53
|
-
* @example
|
|
54
|
-
*
|
|
55
|
-
* // → "lastPage?.['pagination']?.['next']?.['id']"
|
|
27
|
+
* @example With a prefix
|
|
28
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
56
29
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
60
|
-
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
30
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
31
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
61
32
|
}
|
|
62
33
|
//#endregion
|
|
63
34
|
//#region ../../internals/utils/src/reserved.ts
|
|
@@ -163,99 +134,80 @@ function isValidVarName(name) {
|
|
|
163
134
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
164
135
|
}
|
|
165
136
|
//#endregion
|
|
166
|
-
//#region ../../internals/utils/src/
|
|
137
|
+
//#region ../../internals/utils/src/url.ts
|
|
138
|
+
function transformParam(raw, casing) {
|
|
139
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
140
|
+
return casing === "camelcase" ? camelCase(param) : param;
|
|
141
|
+
}
|
|
142
|
+
function toParamsObject(path, { replacer, casing } = {}) {
|
|
143
|
+
const params = {};
|
|
144
|
+
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
145
|
+
const param = transformParam(match[1], casing);
|
|
146
|
+
const key = replacer ? replacer(param) : param;
|
|
147
|
+
params[key] = key;
|
|
148
|
+
}
|
|
149
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
150
|
+
}
|
|
167
151
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* const p = new URLPath('/pet/{petId}')
|
|
172
|
-
* p.URL // '/pet/:petId'
|
|
173
|
-
* p.template // '`/pet/${petId}`'
|
|
152
|
+
* Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
|
|
174
153
|
*/
|
|
175
|
-
var
|
|
154
|
+
var Url = class Url {
|
|
176
155
|
/**
|
|
177
|
-
*
|
|
178
|
-
*/
|
|
179
|
-
path;
|
|
180
|
-
#options;
|
|
181
|
-
constructor(path, options = {}) {
|
|
182
|
-
this.path = path;
|
|
183
|
-
this.#options = options;
|
|
184
|
-
}
|
|
185
|
-
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
156
|
+
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
186
157
|
*
|
|
187
158
|
* @example
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* ```
|
|
159
|
+
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
160
|
+
* Url.canParse('/pet/{petId}') // false
|
|
191
161
|
*/
|
|
192
|
-
|
|
193
|
-
return
|
|
162
|
+
static canParse(url, base) {
|
|
163
|
+
return URL.canParse(url, base);
|
|
194
164
|
}
|
|
195
|
-
/**
|
|
165
|
+
/**
|
|
166
|
+
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
196
167
|
*
|
|
197
168
|
* @example
|
|
198
|
-
*
|
|
199
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
200
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
201
|
-
* ```
|
|
169
|
+
* Url.toPath('/pet/{petId}') // '/pet/:petId'
|
|
202
170
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return !!new URL(this.path).href;
|
|
206
|
-
} catch {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
171
|
+
static toPath(path) {
|
|
172
|
+
return path.replace(/\{([^}]+)\}/g, ":$1");
|
|
209
173
|
}
|
|
210
174
|
/**
|
|
211
|
-
* Converts
|
|
175
|
+
* Converts an OpenAPI/Swagger path to a TypeScript template literal string.
|
|
176
|
+
* `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
|
|
177
|
+
* and `casing` controls parameter identifier casing.
|
|
212
178
|
*
|
|
213
179
|
* @example
|
|
214
|
-
*
|
|
215
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
216
|
-
*/
|
|
217
|
-
get template() {
|
|
218
|
-
return this.toTemplateString();
|
|
219
|
-
}
|
|
220
|
-
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
180
|
+
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
221
181
|
*
|
|
222
182
|
* @example
|
|
223
|
-
*
|
|
224
|
-
* new URLPath('/pet/{petId}').object
|
|
225
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
226
|
-
* ```
|
|
183
|
+
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
227
184
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
185
|
+
static toTemplateString(path, { prefix, replacer, casing } = {}) {
|
|
186
|
+
const result = path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
187
|
+
if (i % 2 === 0) return part;
|
|
188
|
+
const param = transformParam(part, casing);
|
|
189
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
190
|
+
}).join("");
|
|
191
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
230
192
|
}
|
|
231
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
195
|
+
* expression when `stringify` is set.
|
|
232
196
|
*
|
|
233
197
|
* @example
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* new URLPath('/pet').params // undefined
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
get params() {
|
|
240
|
-
return this.getParams();
|
|
241
|
-
}
|
|
242
|
-
#transformParam(raw) {
|
|
243
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
244
|
-
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
198
|
+
* Url.toObject('/pet/{petId}')
|
|
199
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
248
200
|
*/
|
|
249
|
-
|
|
250
|
-
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
251
|
-
const raw = match[1];
|
|
252
|
-
fn(raw, this.#transformParam(raw));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
201
|
+
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
256
202
|
const object = {
|
|
257
|
-
url: type === "path" ?
|
|
258
|
-
|
|
203
|
+
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
204
|
+
replacer,
|
|
205
|
+
casing
|
|
206
|
+
}),
|
|
207
|
+
params: toParamsObject(path, {
|
|
208
|
+
replacer,
|
|
209
|
+
casing
|
|
210
|
+
})
|
|
259
211
|
};
|
|
260
212
|
if (stringify) {
|
|
261
213
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -264,64 +216,153 @@ var URLPath = class {
|
|
|
264
216
|
}
|
|
265
217
|
return object;
|
|
266
218
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
269
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
273
|
-
*/
|
|
274
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
275
|
-
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
276
|
-
if (i % 2 === 0) return part;
|
|
277
|
-
const param = this.#transformParam(part);
|
|
278
|
-
return `\${${replacer ? replacer(param) : param}}`;
|
|
279
|
-
}).join("")}\``;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
283
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
284
|
-
* Returns `undefined` when no path parameters are found.
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```ts
|
|
288
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
289
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
getParams(replacer) {
|
|
293
|
-
const params = {};
|
|
294
|
-
this.#eachParam((_raw, param) => {
|
|
295
|
-
const key = replacer ? replacer(param) : param;
|
|
296
|
-
params[key] = key;
|
|
297
|
-
});
|
|
298
|
-
return Object.keys(params).length > 0 ? params : void 0;
|
|
299
|
-
}
|
|
300
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
301
|
-
*
|
|
302
|
-
* @example
|
|
303
|
-
* ```ts
|
|
304
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
toURLPath() {
|
|
308
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
309
|
-
}
|
|
310
219
|
};
|
|
311
220
|
//#endregion
|
|
221
|
+
//#region ../../internals/shared/src/operation.ts
|
|
222
|
+
/**
|
|
223
|
+
* Builds the `ResolverFileParams` every operation generator passes to
|
|
224
|
+
* `resolver.resolveFile`: a file named `name`, tagged by the operation's first
|
|
225
|
+
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
226
|
+
* that was repeated at dozens of call sites across the client and query plugins.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
function operationFileEntry(node, name, extname = ".ts") {
|
|
234
|
+
return {
|
|
235
|
+
name,
|
|
236
|
+
extname,
|
|
237
|
+
tag: node.tags[0] ?? "default",
|
|
238
|
+
path: node.path
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function getOperationLink(node, link) {
|
|
242
|
+
if (!link) return null;
|
|
243
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
244
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
245
|
+
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
246
|
+
}
|
|
247
|
+
function getContentTypeInfo(node) {
|
|
248
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
249
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
250
|
+
return {
|
|
251
|
+
contentTypes,
|
|
252
|
+
isMultipleContentTypes,
|
|
253
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
254
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
255
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function buildRequestConfigType(node, resolver) {
|
|
259
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
260
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
261
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
262
|
+
}
|
|
263
|
+
function buildOperationComments(node, options = {}) {
|
|
264
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
265
|
+
const linkComment = getOperationLink(node, link);
|
|
266
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
267
|
+
node.description && `@description ${node.description}`,
|
|
268
|
+
node.summary && `@summary ${node.summary}`,
|
|
269
|
+
linkComment,
|
|
270
|
+
node.deprecated && "@deprecated"
|
|
271
|
+
] : [
|
|
272
|
+
node.description && `@description ${node.description}`,
|
|
273
|
+
node.summary && `@summary ${node.summary}`,
|
|
274
|
+
node.deprecated && "@deprecated",
|
|
275
|
+
linkComment
|
|
276
|
+
]).filter((comment) => Boolean(comment));
|
|
277
|
+
if (!splitLines) return filteredComments;
|
|
278
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
279
|
+
}
|
|
280
|
+
function getOperationParameters(node, options = {}) {
|
|
281
|
+
const params = ast.caseParams(node.parameters, options.paramsCasing);
|
|
282
|
+
return {
|
|
283
|
+
path: params.filter((param) => param.in === "path"),
|
|
284
|
+
query: params.filter((param) => param.in === "query"),
|
|
285
|
+
header: params.filter((param) => param.in === "header"),
|
|
286
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function getStatusCodeNumber(statusCode) {
|
|
290
|
+
const code = Number(statusCode);
|
|
291
|
+
return Number.isNaN(code) ? null : code;
|
|
292
|
+
}
|
|
293
|
+
function isSuccessStatusCode(statusCode) {
|
|
294
|
+
const code = getStatusCodeNumber(statusCode);
|
|
295
|
+
return code !== null && code >= 200 && code < 300;
|
|
296
|
+
}
|
|
297
|
+
function isErrorStatusCode(statusCode) {
|
|
298
|
+
const code = getStatusCodeNumber(statusCode);
|
|
299
|
+
return code !== null && code >= 400;
|
|
300
|
+
}
|
|
301
|
+
function resolveErrorNames(node, resolver) {
|
|
302
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
303
|
+
}
|
|
304
|
+
function resolveSuccessNames(node, resolver) {
|
|
305
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
306
|
+
}
|
|
307
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
308
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Builds the discriminated union type string for `dataReturnType: 'full'` return shapes.
|
|
312
|
+
* Each member is `{ status: N; data: StatusNType; statusText: string }`.
|
|
313
|
+
*/
|
|
314
|
+
function buildStatusUnionType(node, resolver) {
|
|
315
|
+
const members = node.responses.map((r) => {
|
|
316
|
+
const typeName = resolver.resolveResponseStatusName(node, r.statusCode);
|
|
317
|
+
const statusCode = Number.parseInt(r.statusCode, 10);
|
|
318
|
+
return `{ status: ${Number.isNaN(statusCode) ? "number" : String(statusCode)}; data: ${typeName}; statusText: string }`;
|
|
319
|
+
});
|
|
320
|
+
if (members.length === 1) return members[0];
|
|
321
|
+
return `(${members.join(" | ")})`;
|
|
322
|
+
}
|
|
323
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
324
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
325
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
326
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
327
|
+
if (byResolver) {
|
|
328
|
+
const cached = byResolver.get(cacheKey);
|
|
329
|
+
if (cached) return cached;
|
|
330
|
+
} else {
|
|
331
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
332
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
333
|
+
}
|
|
334
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
335
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
336
|
+
const exclude = new Set(options.exclude ?? []);
|
|
337
|
+
const paramNames = [
|
|
338
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
339
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
340
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
341
|
+
];
|
|
342
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
343
|
+
const result = (options.order === "body-response-first" ? [
|
|
344
|
+
...bodyAndResponseNames,
|
|
345
|
+
...paramNames,
|
|
346
|
+
...responseStatusNames
|
|
347
|
+
] : [
|
|
348
|
+
...paramNames,
|
|
349
|
+
...bodyAndResponseNames,
|
|
350
|
+
...responseStatusNames
|
|
351
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
352
|
+
byResolver.set(cacheKey, result);
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
312
356
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
313
357
|
const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}, "getTransformer");
|
|
321
|
-
function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1 }) {
|
|
322
|
-
const paramsNode = getParams$6();
|
|
358
|
+
const mutationKeyTransformer = ({ node }) => {
|
|
359
|
+
if (!node.path) return [];
|
|
360
|
+
return [`{ url: '${Url.toPath(node.path)}' }`];
|
|
361
|
+
};
|
|
362
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
363
|
+
const paramsNode = ast.createFunctionParameters({ params: [] });
|
|
323
364
|
const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
|
|
324
|
-
const keys = transformer({
|
|
365
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
325
366
|
node,
|
|
326
367
|
casing: paramsCasing
|
|
327
368
|
});
|
|
@@ -338,28 +379,98 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
338
379
|
})
|
|
339
380
|
});
|
|
340
381
|
}
|
|
341
|
-
MutationKey.getParams = getParams$6;
|
|
342
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
343
382
|
//#endregion
|
|
344
383
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
345
384
|
/**
|
|
346
|
-
*
|
|
385
|
+
* Builds the shared `(…params, config = {})` parameter list for a TanStack
|
|
386
|
+
* query-options function. The trailing `config` parameter is typed as a partial
|
|
387
|
+
* `RequestConfig` with an optional `client`. Framework plugins wrap the result
|
|
388
|
+
* when needed, for example vue-query applies `MaybeRefOrGetter`.
|
|
347
389
|
*/
|
|
348
|
-
function
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
390
|
+
function buildQueryOptionsParams(node, options) {
|
|
391
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
392
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
393
|
+
return ast.createOperationParams(node, {
|
|
394
|
+
paramsType,
|
|
395
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
396
|
+
paramsCasing,
|
|
397
|
+
resolver,
|
|
398
|
+
extraParams: [ast.createFunctionParameter({
|
|
399
|
+
name: "config",
|
|
400
|
+
type: ast.createParamsType({
|
|
401
|
+
variant: "reference",
|
|
402
|
+
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
403
|
+
}),
|
|
404
|
+
default: "{}"
|
|
405
|
+
})]
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function matchesPattern(node, ov) {
|
|
409
|
+
const { type, pattern } = ov;
|
|
410
|
+
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
411
|
+
if (type === "operationId") return matches(node.operationId);
|
|
412
|
+
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
413
|
+
if (type === "path") return node.path !== void 0 && matches(node.path);
|
|
414
|
+
if (type === "method") return node.method !== void 0 && matches(node.method);
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Resolves per-operation overrides (first matching override wins).
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* const opts = resolveOperationOverrides(node, override)
|
|
423
|
+
* const queryOpts = 'query' in opts ? opts.query : defaultQuery
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
function resolveOperationOverrides(node, override) {
|
|
427
|
+
if (!override) return {};
|
|
428
|
+
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Returns `'zod'` when response-direction parsing is enabled.
|
|
432
|
+
* The string shorthand `'zod'` also enables response parsing.
|
|
433
|
+
*/
|
|
434
|
+
function resolveResponseParser(parser) {
|
|
435
|
+
if (!parser) return null;
|
|
436
|
+
if (parser === "zod") return "zod";
|
|
437
|
+
return parser.response ?? null;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
441
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
442
|
+
*/
|
|
443
|
+
function resolveRequestParser(parser) {
|
|
444
|
+
if (!parser) return null;
|
|
445
|
+
if (parser === "zod") return "zod";
|
|
446
|
+
return parser.request ?? null;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Returns `'zod'` when query-params parsing is enabled.
|
|
450
|
+
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
451
|
+
*/
|
|
452
|
+
function resolveQueryParamsParser(parser) {
|
|
453
|
+
if (!parser || parser === "zod") return null;
|
|
454
|
+
return parser.request ?? null;
|
|
355
455
|
}
|
|
356
456
|
/**
|
|
357
|
-
*
|
|
457
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
458
|
+
*
|
|
459
|
+
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
460
|
+
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
461
|
+
* - `parser: { response: 'zod' }`: response name only.
|
|
462
|
+
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
463
|
+
*
|
|
464
|
+
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
358
465
|
*/
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
466
|
+
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
467
|
+
if (!zodResolver || !parser) return [];
|
|
468
|
+
const { query: queryParams } = getOperationParameters(node);
|
|
469
|
+
return [
|
|
470
|
+
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
471
|
+
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
472
|
+
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
473
|
+
].filter((n) => Boolean(n));
|
|
363
474
|
}
|
|
364
475
|
/**
|
|
365
476
|
* Resolve the type for a single path parameter.
|
|
@@ -383,30 +494,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
383
494
|
}
|
|
384
495
|
/**
|
|
385
496
|
* Derive a query-params group type from the resolver.
|
|
386
|
-
* Returns `
|
|
497
|
+
* Returns `null` when no query params exist or when the group name
|
|
387
498
|
* equals the individual param name (no real group).
|
|
388
499
|
*/
|
|
389
500
|
function resolveQueryGroupType(node, params, resolver) {
|
|
390
|
-
if (!params.length) return
|
|
501
|
+
if (!params.length) return null;
|
|
391
502
|
const firstParam = params[0];
|
|
392
503
|
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
393
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return
|
|
394
|
-
return {
|
|
395
|
-
type: ast.createParamsType({
|
|
396
|
-
variant: "reference",
|
|
397
|
-
name: groupName
|
|
398
|
-
}),
|
|
399
|
-
optional: params.every((p) => !p.required)
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Derive a header-params group type from the resolver.
|
|
404
|
-
*/
|
|
405
|
-
function resolveHeaderGroupType(node, params, resolver) {
|
|
406
|
-
if (!params.length) return void 0;
|
|
407
|
-
const firstParam = params[0];
|
|
408
|
-
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
409
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
504
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
410
505
|
return {
|
|
411
506
|
type: ast.createParamsType({
|
|
412
507
|
variant: "reference",
|
|
@@ -456,7 +551,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
456
551
|
const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
|
|
457
552
|
variant: "reference",
|
|
458
553
|
name: resolver.resolveDataName(node)
|
|
459
|
-
}) :
|
|
554
|
+
}) : null;
|
|
460
555
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
461
556
|
const params = [];
|
|
462
557
|
if (pathParams.length) {
|
|
@@ -481,66 +576,101 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
576
|
return ast.createFunctionParameters({ params });
|
|
482
577
|
}
|
|
483
578
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
579
|
+
* Collect the names of the required params (no default) that drive the `enabled`
|
|
580
|
+
* guard. These are exactly the params that should be made optional in the
|
|
581
|
+
* generated signatures so callers can pass `undefined` to reach the disabled state.
|
|
486
582
|
*/
|
|
487
|
-
function
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
583
|
+
function getEnabledParamNames(paramsNode) {
|
|
584
|
+
const required = [];
|
|
585
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
586
|
+
const group = param;
|
|
587
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
588
|
+
} else {
|
|
589
|
+
const fp = param;
|
|
590
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
591
|
+
}
|
|
592
|
+
return required;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Return a copy of `paramsNode` with the named params marked optional.
|
|
596
|
+
*
|
|
597
|
+
* Used to align signatures with the `enabled` guard: the guard already disables
|
|
598
|
+
* the query while a param is falsy, so the param should accept `undefined`. The
|
|
599
|
+
* change is type-only — the `queryFn` keeps calling the client with a non-null
|
|
600
|
+
* assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
|
|
601
|
+
*/
|
|
602
|
+
function markParamsOptional(paramsNode, names) {
|
|
603
|
+
if (names.length === 0) return paramsNode;
|
|
604
|
+
const nameSet = new Set(names);
|
|
605
|
+
const params = paramsNode.params.map((param) => {
|
|
606
|
+
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
607
|
+
const group = param;
|
|
608
|
+
return {
|
|
609
|
+
...group,
|
|
610
|
+
properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
|
|
611
|
+
name: child.name,
|
|
612
|
+
type: child.type,
|
|
613
|
+
rest: child.rest,
|
|
614
|
+
optional: true
|
|
615
|
+
}) : child)
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
const fp = param;
|
|
619
|
+
return nameSet.has(fp.name) ? ast.createFunctionParameter({
|
|
620
|
+
name: fp.name,
|
|
621
|
+
type: fp.type,
|
|
622
|
+
rest: fp.rest,
|
|
623
|
+
optional: true
|
|
624
|
+
}) : fp;
|
|
625
|
+
});
|
|
513
626
|
return ast.createFunctionParameters({ params });
|
|
514
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
630
|
+
* string. Bridges the type gap created by `markParamsOptional` while keeping the
|
|
631
|
+
* runtime identical (the `!` is erased at compile time).
|
|
632
|
+
*
|
|
633
|
+
* Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
|
|
634
|
+
* standalone identifiers (`params` → `params!`).
|
|
635
|
+
*/
|
|
636
|
+
function injectNonNullAssertions(callStr, names) {
|
|
637
|
+
if (names.length === 0) return callStr;
|
|
638
|
+
const nameSet = new Set(names);
|
|
639
|
+
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
640
|
+
if (inner.includes(":") || inner.includes("...")) return match;
|
|
641
|
+
const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
|
|
642
|
+
if (!keys.some((k) => nameSet.has(k))) return match;
|
|
643
|
+
return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
|
|
644
|
+
});
|
|
645
|
+
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
515
648
|
//#endregion
|
|
516
649
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
517
650
|
const declarationPrinter$9 = functionPrinter({ mode: "declaration" });
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
__name(getParams$5, "getParams");
|
|
523
|
-
const getTransformer = ({ node, casing }) => {
|
|
524
|
-
const path = new URLPath(node.path, { casing });
|
|
525
|
-
const hasQueryParams = node.parameters.some((p) => p.in === "query");
|
|
651
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
652
|
+
if (!node.path) return [];
|
|
653
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
526
654
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
527
655
|
return [
|
|
528
|
-
|
|
656
|
+
Url.toObject(node.path, {
|
|
529
657
|
type: "path",
|
|
530
|
-
stringify: true
|
|
658
|
+
stringify: true,
|
|
659
|
+
casing
|
|
531
660
|
}),
|
|
532
|
-
hasQueryParams ? "...(params ? [params] : [])" :
|
|
533
|
-
hasRequestBody ? "...(data ? [data] : [])" :
|
|
661
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
662
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
534
663
|
].filter(Boolean);
|
|
535
664
|
};
|
|
536
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer
|
|
537
|
-
const
|
|
665
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
666
|
+
const baseParamsNode = buildQueryKeyParams(node, {
|
|
538
667
|
pathParamsType,
|
|
539
668
|
paramsCasing,
|
|
540
669
|
resolver: tsResolver
|
|
541
670
|
});
|
|
671
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
|
|
542
672
|
const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
|
|
543
|
-
const keys = transformer({
|
|
673
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
544
674
|
node,
|
|
545
675
|
casing: paramsCasing
|
|
546
676
|
});
|
|
@@ -564,84 +694,36 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
564
694
|
})
|
|
565
695
|
})] });
|
|
566
696
|
}
|
|
567
|
-
QueryKey.getParams = getParams$5;
|
|
568
|
-
QueryKey.getTransformer = getTransformer;
|
|
569
|
-
QueryKey.callPrinter = callPrinter$9;
|
|
570
|
-
//#endregion
|
|
571
|
-
//#region src/utils.ts
|
|
572
|
-
function transformName(name, type, transformers) {
|
|
573
|
-
return transformers?.name?.(name, type) || name;
|
|
574
|
-
}
|
|
575
|
-
function matchesPattern(node, ov) {
|
|
576
|
-
const { type, pattern } = ov;
|
|
577
|
-
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
578
|
-
if (type === "operationId") return matches(node.operationId);
|
|
579
|
-
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
580
|
-
if (type === "path") return matches(node.path);
|
|
581
|
-
if (type === "method") return matches(node.method);
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Resolves per-operation overrides (first matching override wins), mirroring v4 OperationGenerator.getOptions().
|
|
586
|
-
*/
|
|
587
|
-
function resolveOperationOverrides(node, override) {
|
|
588
|
-
if (!override) return {};
|
|
589
|
-
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
590
|
-
}
|
|
591
697
|
//#endregion
|
|
592
698
|
//#region src/components/QueryOptions.tsx
|
|
593
699
|
const declarationPrinter$8 = functionPrinter({ mode: "declaration" });
|
|
594
700
|
const callPrinter$8 = functionPrinter({ mode: "call" });
|
|
595
701
|
function getQueryOptionsParams(node, options) {
|
|
596
|
-
|
|
597
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
598
|
-
return ast.createOperationParams(node, {
|
|
599
|
-
paramsType,
|
|
600
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
601
|
-
paramsCasing,
|
|
602
|
-
resolver,
|
|
603
|
-
extraParams: [ast.createFunctionParameter({
|
|
604
|
-
name: "config",
|
|
605
|
-
type: ast.createParamsType({
|
|
606
|
-
variant: "reference",
|
|
607
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
608
|
-
}),
|
|
609
|
-
default: "{}"
|
|
610
|
-
})]
|
|
611
|
-
});
|
|
702
|
+
return buildQueryOptionsParams(node, options);
|
|
612
703
|
}
|
|
613
|
-
function
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
const group = param;
|
|
617
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
618
|
-
} else {
|
|
619
|
-
const fp = param;
|
|
620
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
621
|
-
}
|
|
622
|
-
return required.join(" && ");
|
|
623
|
-
}
|
|
624
|
-
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
625
|
-
const responseName = tsResolver.resolveResponseName(node);
|
|
704
|
+
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
705
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
706
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
626
707
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
627
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
708
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
628
709
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
629
|
-
const
|
|
630
|
-
paramsType,
|
|
631
|
-
paramsCasing,
|
|
632
|
-
pathParamsType,
|
|
633
|
-
resolver: tsResolver
|
|
634
|
-
});
|
|
635
|
-
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
636
|
-
const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
637
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
710
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
638
711
|
pathParamsType,
|
|
639
712
|
paramsCasing,
|
|
640
713
|
resolver: tsResolver
|
|
641
714
|
});
|
|
642
715
|
const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
|
|
643
|
-
const
|
|
644
|
-
const
|
|
716
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
717
|
+
const optionalNames = suspense ? [] : enabledNames;
|
|
718
|
+
const enabledText = suspense ? "" : enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
719
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
720
|
+
paramsType,
|
|
721
|
+
paramsCasing,
|
|
722
|
+
pathParamsType,
|
|
723
|
+
resolver: tsResolver
|
|
724
|
+
}), optionalNames);
|
|
725
|
+
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
726
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), optionalNames);
|
|
645
727
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
646
728
|
name,
|
|
647
729
|
isExportable: true,
|
|
@@ -652,8 +734,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
652
734
|
params: paramsSignature,
|
|
653
735
|
children: `
|
|
654
736
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
655
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
656
|
-
${enabledText}
|
|
737
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
|
|
657
738
|
queryKey,
|
|
658
739
|
queryFn: async ({ signal }) => {
|
|
659
740
|
return ${clientName}(${clientCallStr})
|
|
@@ -663,14 +744,13 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
663
744
|
})
|
|
664
745
|
});
|
|
665
746
|
}
|
|
666
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
667
747
|
//#endregion
|
|
668
748
|
//#region src/components/InfiniteQuery.tsx
|
|
669
749
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
670
750
|
const callPrinter$7 = functionPrinter({ mode: "call" });
|
|
671
|
-
function
|
|
751
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
672
752
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
673
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
753
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
674
754
|
const optionsParam = ast.createFunctionParameter({
|
|
675
755
|
name: "options",
|
|
676
756
|
type: ast.createParamsType({
|
|
@@ -690,23 +770,23 @@ function getParams$4(node, options) {
|
|
|
690
770
|
extraParams: [optionsParam]
|
|
691
771
|
});
|
|
692
772
|
}
|
|
693
|
-
__name(getParams$4, "getParams");
|
|
694
773
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
695
|
-
const
|
|
774
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
775
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
696
776
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
697
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
777
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
698
778
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
699
779
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
700
780
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
701
781
|
const parts = initialPageParam.split(" as ");
|
|
702
782
|
return parts[parts.length - 1] ?? "unknown";
|
|
703
783
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
704
|
-
const rawQueryParams = node
|
|
784
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
705
785
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
706
786
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
707
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
708
|
-
})() :
|
|
709
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
787
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
788
|
+
})() : null;
|
|
789
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
710
790
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
711
791
|
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
712
792
|
const generics = [
|
|
@@ -716,12 +796,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
716
796
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
717
797
|
`TPageParam = ${pageParamType}`
|
|
718
798
|
];
|
|
719
|
-
const queryKeyParamsNode =
|
|
799
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
720
800
|
pathParamsType,
|
|
721
801
|
paramsCasing,
|
|
722
802
|
resolver: tsResolver
|
|
723
803
|
});
|
|
724
804
|
const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
|
|
805
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
725
806
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
726
807
|
paramsType,
|
|
727
808
|
paramsCasing,
|
|
@@ -729,14 +810,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
729
810
|
resolver: tsResolver
|
|
730
811
|
});
|
|
731
812
|
const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
|
|
732
|
-
const paramsNode =
|
|
813
|
+
const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
|
|
733
814
|
paramsType,
|
|
734
815
|
paramsCasing,
|
|
735
816
|
pathParamsType,
|
|
736
817
|
dataReturnType,
|
|
737
818
|
resolver: tsResolver,
|
|
738
819
|
pageParamGeneric: "TPageParam"
|
|
739
|
-
});
|
|
820
|
+
}), enabledNames);
|
|
740
821
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
741
822
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
742
823
|
name,
|
|
@@ -748,15 +829,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
748
829
|
generics: generics.join(", "),
|
|
749
830
|
params: paramsSignature,
|
|
750
831
|
returnType: void 0,
|
|
751
|
-
JSDoc: { comments:
|
|
832
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
752
833
|
children: `
|
|
753
834
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
754
835
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
755
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
756
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
836
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
757
837
|
|
|
758
838
|
const query = useInfiniteQuery({
|
|
759
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
839
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
760
840
|
...resolvedOptions,
|
|
761
841
|
queryKey,
|
|
762
842
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -768,14 +848,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
768
848
|
})
|
|
769
849
|
});
|
|
770
850
|
}
|
|
771
|
-
InfiniteQuery.getParams = getParams$4;
|
|
772
851
|
//#endregion
|
|
773
852
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
774
853
|
const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
|
|
775
854
|
const callPrinter$6 = functionPrinter({ mode: "call" });
|
|
776
855
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
777
|
-
const
|
|
778
|
-
const
|
|
856
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
857
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
858
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
779
859
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
780
860
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
781
861
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -783,59 +863,48 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
783
863
|
const parts = initialPageParam.split(" as ");
|
|
784
864
|
return parts[parts.length - 1] ?? "unknown";
|
|
785
865
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
786
|
-
const rawQueryParams = node
|
|
866
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
787
867
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
788
868
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
789
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
790
|
-
})() :
|
|
791
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
869
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
870
|
+
})() : null;
|
|
871
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
792
872
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
793
|
-
const
|
|
794
|
-
paramsType,
|
|
795
|
-
paramsCasing,
|
|
796
|
-
pathParamsType,
|
|
797
|
-
resolver: tsResolver
|
|
798
|
-
});
|
|
799
|
-
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
800
|
-
const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
801
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
873
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
802
874
|
pathParamsType,
|
|
803
875
|
paramsCasing,
|
|
804
876
|
resolver: tsResolver
|
|
805
877
|
});
|
|
806
878
|
const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
|
|
807
|
-
const
|
|
808
|
-
const enabledText =
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
879
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
880
|
+
const enabledText = enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
881
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
882
|
+
paramsType,
|
|
883
|
+
paramsCasing,
|
|
884
|
+
pathParamsType,
|
|
885
|
+
resolver: tsResolver
|
|
886
|
+
}), enabledNames);
|
|
887
|
+
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
888
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), enabledNames);
|
|
889
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
890
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
891
|
+
if (hasNewParams) {
|
|
892
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
893
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
894
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
820
895
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
} else {
|
|
825
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
826
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
827
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
828
|
-
}
|
|
896
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
897
|
+
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"];
|
|
898
|
+
})();
|
|
829
899
|
const queryOptionsArr = [
|
|
830
900
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
831
901
|
getNextPageParamExpr,
|
|
832
902
|
getPreviousPageParamExpr
|
|
833
903
|
].filter(Boolean);
|
|
834
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
} as ${queryParamsTypeName}` : "";
|
|
904
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
905
|
+
...(params ?? {}),
|
|
906
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
907
|
+
} as ${queryParamsTypeName}` : "";
|
|
839
908
|
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
840
909
|
name,
|
|
841
910
|
isExportable: true,
|
|
@@ -845,16 +914,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
845
914
|
export: true,
|
|
846
915
|
params: paramsSignature,
|
|
847
916
|
children: `
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
})
|
|
917
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
918
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
919
|
+
queryKey,
|
|
920
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
921
|
+
${infiniteOverrideParams}
|
|
922
|
+
return ${clientName}(${clientCallStr})
|
|
923
|
+
},
|
|
924
|
+
${queryOptionsArr.join(",\n ")}
|
|
925
|
+
})
|
|
858
926
|
`
|
|
859
927
|
})
|
|
860
928
|
});
|
|
@@ -867,44 +935,44 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
867
935
|
export: true,
|
|
868
936
|
params: paramsSignature,
|
|
869
937
|
children: `
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
})
|
|
938
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
939
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
940
|
+
queryKey,
|
|
941
|
+
queryFn: async ({ signal }) => {
|
|
942
|
+
return ${clientName}(${clientCallStr})
|
|
943
|
+
},
|
|
944
|
+
${queryOptionsArr.join(",\n ")}
|
|
945
|
+
})
|
|
879
946
|
`
|
|
880
947
|
})
|
|
881
948
|
});
|
|
882
949
|
}
|
|
883
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
884
950
|
//#endregion
|
|
885
951
|
//#region src/components/MutationOptions.tsx
|
|
886
952
|
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
887
953
|
const callPrinter$5 = functionPrinter({ mode: "call" });
|
|
888
954
|
const keysPrinter = functionPrinter({ mode: "keys" });
|
|
889
|
-
function
|
|
890
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
955
|
+
function buildMutationConfigParamsNode(node, resolver) {
|
|
891
956
|
return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
892
957
|
name: "config",
|
|
893
958
|
type: ast.createParamsType({
|
|
894
959
|
variant: "reference",
|
|
895
|
-
name:
|
|
960
|
+
name: buildRequestConfigType(node, resolver)
|
|
896
961
|
}),
|
|
897
962
|
default: "{}"
|
|
898
963
|
})] });
|
|
899
964
|
}
|
|
900
965
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
901
|
-
const
|
|
902
|
-
const
|
|
966
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
967
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
968
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
903
969
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
904
970
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
905
|
-
const configParamsNode =
|
|
971
|
+
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
906
972
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
907
|
-
const mutationArgParamsNode =
|
|
973
|
+
const mutationArgParamsNode = ast.createOperationParams(node, {
|
|
974
|
+
paramsType: "inline",
|
|
975
|
+
pathParamsType: "inline",
|
|
908
976
|
paramsCasing,
|
|
909
977
|
resolver: tsResolver
|
|
910
978
|
});
|
|
@@ -920,7 +988,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
920
988
|
name: "config",
|
|
921
989
|
type: ast.createParamsType({
|
|
922
990
|
variant: "reference",
|
|
923
|
-
name: node
|
|
991
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
924
992
|
}),
|
|
925
993
|
default: "{}"
|
|
926
994
|
})]
|
|
@@ -937,7 +1005,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
937
1005
|
generics: ["TContext = unknown"],
|
|
938
1006
|
children: `
|
|
939
1007
|
const mutationKey = ${mutationKeyName}()
|
|
940
|
-
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "
|
|
1008
|
+
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "undefined"}, TContext>({
|
|
941
1009
|
mutationKey,
|
|
942
1010
|
mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
|
|
943
1011
|
return ${clientName}(${clientCallStr})
|
|
@@ -947,19 +1015,26 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
947
1015
|
})
|
|
948
1016
|
});
|
|
949
1017
|
}
|
|
950
|
-
MutationOptions.getParams = getConfigParam;
|
|
951
1018
|
//#endregion
|
|
952
1019
|
//#region src/components/Mutation.tsx
|
|
953
1020
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
954
1021
|
const callPrinter$4 = functionPrinter({ mode: "call" });
|
|
955
|
-
function
|
|
1022
|
+
function createMutationArgParams(node, options) {
|
|
1023
|
+
return ast.createOperationParams(node, {
|
|
1024
|
+
paramsType: "inline",
|
|
1025
|
+
pathParamsType: "inline",
|
|
1026
|
+
paramsCasing: options.paramsCasing,
|
|
1027
|
+
resolver: options.resolver
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
function buildMutationParamsNode(node, options) {
|
|
956
1031
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
957
|
-
const
|
|
958
|
-
const
|
|
1032
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1033
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
959
1034
|
const errorNames = resolveErrorNames(node, resolver);
|
|
960
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1035
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
961
1036
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
962
|
-
const mutationArgParamsNode =
|
|
1037
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
963
1038
|
paramsCasing,
|
|
964
1039
|
resolver
|
|
965
1040
|
});
|
|
@@ -967,7 +1042,7 @@ function getParams$3(node, options) {
|
|
|
967
1042
|
const generics = [
|
|
968
1043
|
TData,
|
|
969
1044
|
TError,
|
|
970
|
-
TRequest ? `{${TRequest}}` : "
|
|
1045
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
971
1046
|
"TContext"
|
|
972
1047
|
].join(", ");
|
|
973
1048
|
return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
@@ -976,19 +1051,19 @@ function getParams$3(node, options) {
|
|
|
976
1051
|
variant: "reference",
|
|
977
1052
|
name: `{
|
|
978
1053
|
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
979
|
-
client?: ${
|
|
1054
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
980
1055
|
}`
|
|
981
1056
|
}),
|
|
982
1057
|
default: "{}"
|
|
983
1058
|
})] });
|
|
984
1059
|
}
|
|
985
|
-
__name(getParams$3, "getParams");
|
|
986
1060
|
function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
|
|
987
|
-
const
|
|
1061
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1062
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
988
1063
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
989
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1064
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
990
1065
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
991
|
-
const mutationArgParamsNode =
|
|
1066
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
992
1067
|
paramsCasing,
|
|
993
1068
|
resolver: tsResolver
|
|
994
1069
|
});
|
|
@@ -996,13 +1071,13 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
996
1071
|
const generics = [
|
|
997
1072
|
TData,
|
|
998
1073
|
TError,
|
|
999
|
-
TRequest ? `{${TRequest}}` : "
|
|
1074
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1000
1075
|
"TContext"
|
|
1001
1076
|
].join(", ");
|
|
1002
1077
|
const returnType = `UseMutationResult<${generics}>`;
|
|
1003
|
-
const mutationOptionsConfigNode =
|
|
1078
|
+
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
1004
1079
|
const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
|
|
1005
|
-
const paramsNode =
|
|
1080
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1006
1081
|
paramsCasing,
|
|
1007
1082
|
dataReturnType,
|
|
1008
1083
|
resolver: tsResolver
|
|
@@ -1016,18 +1091,17 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1016
1091
|
name,
|
|
1017
1092
|
export: true,
|
|
1018
1093
|
params: paramsSignature,
|
|
1019
|
-
JSDoc: { comments:
|
|
1094
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1020
1095
|
generics: ["TContext"],
|
|
1021
1096
|
children: `
|
|
1022
1097
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
1023
1098
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1024
1099
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
1025
1100
|
|
|
1026
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
1027
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1101
|
+
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
|
|
1028
1102
|
|
|
1029
1103
|
return useMutation<${generics}>({
|
|
1030
|
-
...baseOptions,${customOptions ? "\n...customOptions," : ""}
|
|
1104
|
+
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
1031
1105
|
mutationKey,
|
|
1032
1106
|
...mutationOptions,
|
|
1033
1107
|
}, queryClient) as ${returnType}
|
|
@@ -1035,17 +1109,17 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1035
1109
|
})
|
|
1036
1110
|
});
|
|
1037
1111
|
}
|
|
1038
|
-
Mutation.getParams = getParams$3;
|
|
1039
1112
|
//#endregion
|
|
1040
1113
|
//#region src/components/Query.tsx
|
|
1041
1114
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
1042
1115
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
1043
|
-
function
|
|
1116
|
+
function buildQueryParamsNode(node, options) {
|
|
1044
1117
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1045
|
-
const
|
|
1046
|
-
const
|
|
1118
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1119
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1120
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1047
1121
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1048
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1122
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1049
1123
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1050
1124
|
const optionsParam = ast.createFunctionParameter({
|
|
1051
1125
|
name: "options",
|
|
@@ -1072,23 +1146,24 @@ function getParams$2(node, options) {
|
|
|
1072
1146
|
extraParams: [optionsParam]
|
|
1073
1147
|
});
|
|
1074
1148
|
}
|
|
1075
|
-
__name(getParams$2, "getParams");
|
|
1076
1149
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1077
|
-
const
|
|
1150
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1151
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1078
1152
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1079
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1153
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1080
1154
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1081
1155
|
const generics = [
|
|
1082
1156
|
`TData = ${TData}`,
|
|
1083
1157
|
`TQueryData = ${TData}`,
|
|
1084
1158
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1085
1159
|
];
|
|
1086
|
-
const queryKeyParamsNode =
|
|
1160
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1087
1161
|
pathParamsType,
|
|
1088
1162
|
paramsCasing,
|
|
1089
1163
|
resolver: tsResolver
|
|
1090
1164
|
});
|
|
1091
1165
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
1166
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
1092
1167
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
1093
1168
|
paramsType,
|
|
1094
1169
|
paramsCasing,
|
|
@@ -1096,13 +1171,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1096
1171
|
resolver: tsResolver
|
|
1097
1172
|
});
|
|
1098
1173
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
1099
|
-
const paramsNode =
|
|
1174
|
+
const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
|
|
1100
1175
|
paramsType,
|
|
1101
1176
|
paramsCasing,
|
|
1102
1177
|
pathParamsType,
|
|
1103
1178
|
dataReturnType,
|
|
1104
1179
|
resolver: tsResolver
|
|
1105
|
-
});
|
|
1180
|
+
}), enabledNames);
|
|
1106
1181
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
1107
1182
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1108
1183
|
name,
|
|
@@ -1114,15 +1189,14 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1114
1189
|
generics: generics.join(", "),
|
|
1115
1190
|
params: paramsSignature,
|
|
1116
1191
|
returnType: void 0,
|
|
1117
|
-
JSDoc: { comments:
|
|
1192
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1118
1193
|
children: `
|
|
1119
1194
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1120
1195
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1121
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1122
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1196
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1123
1197
|
|
|
1124
1198
|
const query = useQuery({
|
|
1125
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1199
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1126
1200
|
...resolvedOptions,
|
|
1127
1201
|
queryKey,
|
|
1128
1202
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1134,14 +1208,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1134
1208
|
})
|
|
1135
1209
|
});
|
|
1136
1210
|
}
|
|
1137
|
-
Query.getParams = getParams$2;
|
|
1138
1211
|
//#endregion
|
|
1139
1212
|
//#region src/components/SuspenseInfiniteQuery.tsx
|
|
1140
1213
|
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
1141
1214
|
const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
1142
|
-
function
|
|
1215
|
+
function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
1143
1216
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
1144
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
1217
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1145
1218
|
const optionsParam = ast.createFunctionParameter({
|
|
1146
1219
|
name: "options",
|
|
1147
1220
|
type: ast.createParamsType({
|
|
@@ -1161,23 +1234,23 @@ function getParams$1(node, options) {
|
|
|
1161
1234
|
extraParams: [optionsParam]
|
|
1162
1235
|
});
|
|
1163
1236
|
}
|
|
1164
|
-
__name(getParams$1, "getParams");
|
|
1165
1237
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1166
|
-
const
|
|
1238
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1239
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1167
1240
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1168
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
1241
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1169
1242
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1170
1243
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1171
1244
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
1172
1245
|
const parts = initialPageParam.split(" as ");
|
|
1173
1246
|
return parts[parts.length - 1] ?? "unknown";
|
|
1174
1247
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1175
|
-
const rawQueryParams = node
|
|
1248
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1176
1249
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1177
1250
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1178
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1179
|
-
})() :
|
|
1180
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1251
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1252
|
+
})() : null;
|
|
1253
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1181
1254
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1182
1255
|
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1183
1256
|
const generics = [
|
|
@@ -1187,7 +1260,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1187
1260
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1188
1261
|
`TPageParam = ${pageParamType}`
|
|
1189
1262
|
];
|
|
1190
|
-
const queryKeyParamsNode =
|
|
1263
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1191
1264
|
pathParamsType,
|
|
1192
1265
|
paramsCasing,
|
|
1193
1266
|
resolver: tsResolver
|
|
@@ -1200,7 +1273,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1200
1273
|
resolver: tsResolver
|
|
1201
1274
|
});
|
|
1202
1275
|
const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
|
|
1203
|
-
const paramsNode =
|
|
1276
|
+
const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
|
|
1204
1277
|
paramsType,
|
|
1205
1278
|
paramsCasing,
|
|
1206
1279
|
pathParamsType,
|
|
@@ -1219,15 +1292,14 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1219
1292
|
generics: generics.join(", "),
|
|
1220
1293
|
params: paramsSignature,
|
|
1221
1294
|
returnType: void 0,
|
|
1222
|
-
JSDoc: { comments:
|
|
1295
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1223
1296
|
children: `
|
|
1224
1297
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1225
1298
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1226
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1227
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1299
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1228
1300
|
|
|
1229
1301
|
const query = useSuspenseInfiniteQuery({
|
|
1230
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1302
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1231
1303
|
...resolvedOptions,
|
|
1232
1304
|
queryKey,
|
|
1233
1305
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1239,14 +1311,14 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1239
1311
|
})
|
|
1240
1312
|
});
|
|
1241
1313
|
}
|
|
1242
|
-
SuspenseInfiniteQuery.getParams = getParams$1;
|
|
1243
1314
|
//#endregion
|
|
1244
1315
|
//#region src/components/SuspenseInfiniteQueryOptions.tsx
|
|
1245
1316
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1246
1317
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1247
1318
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1248
|
-
const
|
|
1249
|
-
const
|
|
1319
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1320
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1321
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1250
1322
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1251
1323
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1252
1324
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1254,12 +1326,12 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1254
1326
|
const parts = initialPageParam.split(" as ");
|
|
1255
1327
|
return parts[parts.length - 1] ?? "unknown";
|
|
1256
1328
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1257
|
-
const rawQueryParams = node
|
|
1329
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1258
1330
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1259
1331
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1260
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1261
|
-
})() :
|
|
1262
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1332
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1333
|
+
})() : null;
|
|
1334
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1263
1335
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1264
1336
|
const paramsNode = getQueryOptionsParams(node, {
|
|
1265
1337
|
paramsType,
|
|
@@ -1269,44 +1341,31 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1269
1341
|
});
|
|
1270
1342
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1271
1343
|
const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
1272
|
-
const queryKeyParamsNode =
|
|
1344
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1273
1345
|
pathParamsType,
|
|
1274
1346
|
paramsCasing,
|
|
1275
1347
|
resolver: tsResolver
|
|
1276
1348
|
});
|
|
1277
1349
|
const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
|
|
1278
|
-
const
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
if (nextParam) {
|
|
1285
|
-
const accessor = getNestedAccessor(nextParam, "lastPage");
|
|
1286
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
1287
|
-
}
|
|
1288
|
-
if (previousParam) {
|
|
1289
|
-
const accessor = getNestedAccessor(previousParam, "firstPage");
|
|
1290
|
-
if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
|
|
1350
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
1351
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1352
|
+
if (hasNewParams) {
|
|
1353
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1354
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1355
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1291
1356
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
} else {
|
|
1296
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
1297
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
1298
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
1299
|
-
}
|
|
1357
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
1358
|
+
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"];
|
|
1359
|
+
})();
|
|
1300
1360
|
const queryOptionsArr = [
|
|
1301
1361
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
1302
1362
|
getNextPageParamExpr,
|
|
1303
1363
|
getPreviousPageParamExpr
|
|
1304
1364
|
].filter(Boolean);
|
|
1305
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
} as ${queryParamsTypeName}` : "";
|
|
1365
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
1366
|
+
...(params ?? {}),
|
|
1367
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1368
|
+
} as ${queryParamsTypeName}` : "";
|
|
1310
1369
|
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
1311
1370
|
name,
|
|
1312
1371
|
isExportable: true,
|
|
@@ -1316,16 +1375,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1316
1375
|
export: true,
|
|
1317
1376
|
params: paramsSignature,
|
|
1318
1377
|
children: `
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
})
|
|
1378
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1379
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1380
|
+
queryKey,
|
|
1381
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
1382
|
+
${infiniteOverrideParams}
|
|
1383
|
+
return ${clientName}(${clientCallStr})
|
|
1384
|
+
},
|
|
1385
|
+
${queryOptionsArr.join(",\n ")}
|
|
1386
|
+
})
|
|
1329
1387
|
`
|
|
1330
1388
|
})
|
|
1331
1389
|
});
|
|
@@ -1338,30 +1396,29 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1338
1396
|
export: true,
|
|
1339
1397
|
params: paramsSignature,
|
|
1340
1398
|
children: `
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
})
|
|
1399
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1400
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1401
|
+
queryKey,
|
|
1402
|
+
queryFn: async ({ signal }) => {
|
|
1403
|
+
return ${clientName}(${clientCallStr})
|
|
1404
|
+
},
|
|
1405
|
+
${queryOptionsArr.join(",\n ")}
|
|
1406
|
+
})
|
|
1350
1407
|
`
|
|
1351
1408
|
})
|
|
1352
1409
|
});
|
|
1353
1410
|
}
|
|
1354
|
-
SuspenseInfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1355
1411
|
//#endregion
|
|
1356
1412
|
//#region src/components/SuspenseQuery.tsx
|
|
1357
1413
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1358
1414
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1359
|
-
function
|
|
1415
|
+
function buildSuspenseQueryParamsNode(node, options) {
|
|
1360
1416
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1361
|
-
const
|
|
1362
|
-
const
|
|
1417
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1418
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1419
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1363
1420
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1364
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1421
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1365
1422
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1366
1423
|
const optionsParam = ast.createFunctionParameter({
|
|
1367
1424
|
name: "options",
|
|
@@ -1388,12 +1445,13 @@ function getParams(node, options) {
|
|
|
1388
1445
|
});
|
|
1389
1446
|
}
|
|
1390
1447
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1391
|
-
const
|
|
1448
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1449
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1392
1450
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1393
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1451
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1394
1452
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1395
1453
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1396
|
-
const queryKeyParamsNode =
|
|
1454
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1397
1455
|
pathParamsType,
|
|
1398
1456
|
paramsCasing,
|
|
1399
1457
|
resolver: tsResolver
|
|
@@ -1406,7 +1464,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1406
1464
|
resolver: tsResolver
|
|
1407
1465
|
});
|
|
1408
1466
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1409
|
-
const paramsNode =
|
|
1467
|
+
const paramsNode = buildSuspenseQueryParamsNode(node, {
|
|
1410
1468
|
paramsType,
|
|
1411
1469
|
paramsCasing,
|
|
1412
1470
|
pathParamsType,
|
|
@@ -1424,15 +1482,14 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1424
1482
|
generics: generics.join(", "),
|
|
1425
1483
|
params: paramsSignature,
|
|
1426
1484
|
returnType: void 0,
|
|
1427
|
-
JSDoc: { comments:
|
|
1485
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1428
1486
|
children: `
|
|
1429
1487
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1430
1488
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1431
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1432
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1489
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1433
1490
|
|
|
1434
1491
|
const query = useSuspenseQuery({
|
|
1435
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1492
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1436
1493
|
...resolvedOptions,
|
|
1437
1494
|
queryKey,
|
|
1438
1495
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -1444,8 +1501,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1444
1501
|
})
|
|
1445
1502
|
});
|
|
1446
1503
|
}
|
|
1447
|
-
SuspenseQuery.getParams = getParams;
|
|
1448
1504
|
//#endregion
|
|
1449
|
-
export { Mutation as a, InfiniteQuery as c,
|
|
1505
|
+
export { operationFileEntry as _, Mutation as a, InfiniteQuery as c, queryKeyTransformer as d, resolveOperationOverrides as f, getOperationParameters as g, mutationKeyTransformer as h, Query as i, QueryOptions as l, MutationKey as m, SuspenseInfiniteQueryOptions as n, MutationOptions as o, resolveZodSchemaNames as p, SuspenseInfiniteQuery as r, InfiniteQueryOptions as s, SuspenseQuery as t, QueryKey as u, resolveOperationTypeNames as v, camelCase as y };
|
|
1450
1506
|
|
|
1451
|
-
//# sourceMappingURL=components-
|
|
1507
|
+
//# sourceMappingURL=components-DL0Cai7l.js.map
|