@kubb/plugin-react-query 5.0.0-beta.42 → 5.0.0-beta.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-IArDg-DO.js → components-DL0Cai7l.js} +211 -255
- package/dist/components-DL0Cai7l.js.map +1 -0
- package/dist/{components-DQAYLQW0.cjs → components-yMQOuFmI.cjs} +215 -259
- package/dist/components-yMQOuFmI.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-B86BJkmW.js → generators-BG-Vcvfg.js} +151 -231
- package/dist/generators-BG-Vcvfg.js.map +1 -0
- package/dist/{generators-BqGaMUH6.cjs → generators-zGKP8yII.cjs} +149 -229
- package/dist/generators-zGKP8yII.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +35 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/dist/{types-Dh4HNR9K.d.ts → types-X7D0NSvJ.d.ts} +11 -15
- package/package.json +10 -17
- package/src/components/InfiniteQuery.tsx +4 -5
- package/src/components/InfiniteQueryOptions.tsx +24 -27
- package/src/components/Mutation.tsx +5 -6
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +5 -6
- package/src/components/QueryOptions.tsx +6 -25
- package/src/components/SuspenseInfiniteQuery.tsx +4 -5
- package/src/components/SuspenseInfiniteQueryOptions.tsx +24 -25
- package/src/components/SuspenseQuery.tsx +5 -6
- package/src/generators/customHookOptionsFileGenerator.tsx +2 -2
- package/src/generators/hookOptionsGenerator.tsx +2 -2
- package/src/generators/infiniteQueryGenerator.tsx +5 -9
- package/src/generators/mutationGenerator.tsx +8 -9
- package/src/generators/queryGenerator.tsx +5 -9
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +5 -9
- package/src/generators/suspenseQueryGenerator.tsx +5 -9
- package/src/plugin.ts +4 -4
- package/src/resolvers/resolverReactQuery.ts +2 -2
- package/src/types.ts +9 -13
- package/src/utils.ts +1 -0
- package/dist/components-DQAYLQW0.cjs.map +0 -1
- package/dist/components-IArDg-DO.js.map +0 -1
- package/dist/generators-B86BJkmW.js.map +0 -1
- package/dist/generators-BqGaMUH6.cjs.map +0 -1
- package/extension.yaml +0 -1484
|
@@ -3,6 +3,7 @@ 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 // null
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
get params() {
|
|
240
|
-
return this.toParamsObject();
|
|
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,50 +216,6 @@ 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
|
-
const result = 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
|
-
return `\`${prefix ?? ""}${result}\``;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
284
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
285
|
-
* Returns `undefined` when no path parameters are found.
|
|
286
|
-
*
|
|
287
|
-
* @example
|
|
288
|
-
* ```ts
|
|
289
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
290
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
291
|
-
* ```
|
|
292
|
-
*/
|
|
293
|
-
toParamsObject(replacer) {
|
|
294
|
-
const params = {};
|
|
295
|
-
this.#eachParam((_raw, param) => {
|
|
296
|
-
const key = replacer ? replacer(param) : param;
|
|
297
|
-
params[key] = key;
|
|
298
|
-
});
|
|
299
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
300
|
-
}
|
|
301
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```ts
|
|
305
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
toURLPath() {
|
|
309
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
310
|
-
}
|
|
311
219
|
};
|
|
312
220
|
//#endregion
|
|
313
221
|
//#region ../../internals/shared/src/operation.ts
|
|
@@ -333,7 +241,7 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
333
241
|
function getOperationLink(node, link) {
|
|
334
242
|
if (!link) return null;
|
|
335
243
|
if (typeof link === "function") return link(node) ?? null;
|
|
336
|
-
if (link === "urlPath") return node.path ? `{@link ${
|
|
244
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
337
245
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
338
246
|
}
|
|
339
247
|
function getContentTypeInfo(node) {
|
|
@@ -399,6 +307,19 @@ function resolveSuccessNames(node, resolver) {
|
|
|
399
307
|
function resolveStatusCodeNames(node, resolver) {
|
|
400
308
|
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
401
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
|
+
}
|
|
402
323
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
403
324
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
404
325
|
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
@@ -434,9 +355,9 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
434
355
|
//#endregion
|
|
435
356
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
436
357
|
const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
|
|
437
|
-
const mutationKeyTransformer = ({ node
|
|
358
|
+
const mutationKeyTransformer = ({ node }) => {
|
|
438
359
|
if (!node.path) return [];
|
|
439
|
-
return [`{ url: '${
|
|
360
|
+
return [`{ url: '${Url.toPath(node.path)}' }`];
|
|
440
361
|
};
|
|
441
362
|
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
442
363
|
const paramsNode = ast.createFunctionParameters({ params: [] });
|
|
@@ -460,6 +381,30 @@ function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
|
460
381
|
}
|
|
461
382
|
//#endregion
|
|
462
383
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
384
|
+
/**
|
|
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`.
|
|
389
|
+
*/
|
|
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
|
+
}
|
|
463
408
|
function matchesPattern(node, ov) {
|
|
464
409
|
const { type, pattern } = ov;
|
|
465
410
|
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
@@ -483,13 +428,49 @@ function resolveOperationOverrides(node, override) {
|
|
|
483
428
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
484
429
|
}
|
|
485
430
|
/**
|
|
486
|
-
*
|
|
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;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
487
458
|
*
|
|
488
|
-
*
|
|
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.
|
|
489
465
|
*/
|
|
490
|
-
function resolveZodSchemaNames(node, zodResolver) {
|
|
491
|
-
if (!zodResolver) return [];
|
|
492
|
-
|
|
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));
|
|
493
474
|
}
|
|
494
475
|
/**
|
|
495
476
|
* Resolve the type for a single path parameter.
|
|
@@ -669,13 +650,13 @@ function injectNonNullAssertions(callStr, names) {
|
|
|
669
650
|
const declarationPrinter$9 = functionPrinter({ mode: "declaration" });
|
|
670
651
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
671
652
|
if (!node.path) return [];
|
|
672
|
-
const path = new URLPath(node.path, { casing });
|
|
673
653
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
674
654
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
675
655
|
return [
|
|
676
|
-
|
|
656
|
+
Url.toObject(node.path, {
|
|
677
657
|
type: "path",
|
|
678
|
-
stringify: true
|
|
658
|
+
stringify: true,
|
|
659
|
+
casing
|
|
679
660
|
}),
|
|
680
661
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
681
662
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -718,28 +699,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
718
699
|
const declarationPrinter$8 = functionPrinter({ mode: "declaration" });
|
|
719
700
|
const callPrinter$8 = functionPrinter({ mode: "call" });
|
|
720
701
|
function getQueryOptionsParams(node, options) {
|
|
721
|
-
|
|
722
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
723
|
-
return ast.createOperationParams(node, {
|
|
724
|
-
paramsType,
|
|
725
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
726
|
-
paramsCasing,
|
|
727
|
-
resolver,
|
|
728
|
-
extraParams: [ast.createFunctionParameter({
|
|
729
|
-
name: "config",
|
|
730
|
-
type: ast.createParamsType({
|
|
731
|
-
variant: "reference",
|
|
732
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
733
|
-
}),
|
|
734
|
-
default: "{}"
|
|
735
|
-
})]
|
|
736
|
-
});
|
|
702
|
+
return buildQueryOptionsParams(node, options);
|
|
737
703
|
}
|
|
738
704
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
739
705
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
740
706
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
741
707
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
742
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
708
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
743
709
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
744
710
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
745
711
|
pathParamsType,
|
|
@@ -768,8 +734,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
768
734
|
params: paramsSignature,
|
|
769
735
|
children: `
|
|
770
736
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
771
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
772
|
-
${enabledText}
|
|
737
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({${enabledText ? `\n ${enabledText}` : ""}
|
|
773
738
|
queryKey,
|
|
774
739
|
queryFn: async ({ signal }) => {
|
|
775
740
|
return ${clientName}(${clientCallStr})
|
|
@@ -809,7 +774,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
809
774
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
810
775
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
811
776
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
812
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
777
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
813
778
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
814
779
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
815
780
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -868,11 +833,10 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
868
833
|
children: `
|
|
869
834
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
870
835
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
871
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
872
|
-
${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}' })` : ""}
|
|
873
837
|
|
|
874
838
|
const query = useInfiniteQuery({
|
|
875
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
839
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
876
840
|
...resolvedOptions,
|
|
877
841
|
queryKey,
|
|
878
842
|
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -891,7 +855,7 @@ const callPrinter$6 = functionPrinter({ mode: "call" });
|
|
|
891
855
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
892
856
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
893
857
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
894
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
858
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
895
859
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
896
860
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
897
861
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -937,11 +901,10 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
937
901
|
getNextPageParamExpr,
|
|
938
902
|
getPreviousPageParamExpr
|
|
939
903
|
].filter(Boolean);
|
|
940
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
} as ${queryParamsTypeName}` : "";
|
|
904
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
905
|
+
...(params ?? {}),
|
|
906
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
907
|
+
} as ${queryParamsTypeName}` : "";
|
|
945
908
|
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
946
909
|
name,
|
|
947
910
|
isExportable: true,
|
|
@@ -951,16 +914,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
951
914
|
export: true,
|
|
952
915
|
params: paramsSignature,
|
|
953
916
|
children: `
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
})
|
|
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
|
+
})
|
|
964
926
|
`
|
|
965
927
|
})
|
|
966
928
|
});
|
|
@@ -973,15 +935,14 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
973
935
|
export: true,
|
|
974
936
|
params: paramsSignature,
|
|
975
937
|
children: `
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
})
|
|
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
|
+
})
|
|
985
946
|
`
|
|
986
947
|
})
|
|
987
948
|
});
|
|
@@ -1004,7 +965,7 @@ function buildMutationConfigParamsNode(node, resolver) {
|
|
|
1004
965
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
1005
966
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1006
967
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1007
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
968
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1008
969
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1009
970
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1010
971
|
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
@@ -1071,7 +1032,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1071
1032
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1072
1033
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1073
1034
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1074
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1035
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1075
1036
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1076
1037
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1077
1038
|
paramsCasing,
|
|
@@ -1100,7 +1061,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1100
1061
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1101
1062
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1102
1063
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1103
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1064
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1104
1065
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1105
1066
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1106
1067
|
paramsCasing,
|
|
@@ -1137,11 +1098,10 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1137
1098
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1138
1099
|
const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
|
|
1139
1100
|
|
|
1140
|
-
const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}
|
|
1141
|
-
${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}>` : ""}
|
|
1142
1102
|
|
|
1143
1103
|
return useMutation<${generics}>({
|
|
1144
|
-
...baseOptions,${customOptions ? "\n...customOptions," : ""}
|
|
1104
|
+
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
1145
1105
|
mutationKey,
|
|
1146
1106
|
...mutationOptions,
|
|
1147
1107
|
}, queryClient) as ${returnType}
|
|
@@ -1159,7 +1119,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1159
1119
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1160
1120
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1161
1121
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1162
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1122
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1163
1123
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1164
1124
|
const optionsParam = ast.createFunctionParameter({
|
|
1165
1125
|
name: "options",
|
|
@@ -1190,7 +1150,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1190
1150
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1191
1151
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1192
1152
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1193
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1153
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1194
1154
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1195
1155
|
const generics = [
|
|
1196
1156
|
`TData = ${TData}`,
|
|
@@ -1233,11 +1193,10 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1233
1193
|
children: `
|
|
1234
1194
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1235
1195
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1236
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1237
|
-
${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}' })` : ""}
|
|
1238
1197
|
|
|
1239
1198
|
const query = useQuery({
|
|
1240
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1199
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1241
1200
|
...resolvedOptions,
|
|
1242
1201
|
queryKey,
|
|
1243
1202
|
} as unknown as QueryObserverOptions, queryClient) as ${returnType}
|
|
@@ -1279,7 +1238,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1279
1238
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1280
1239
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1281
1240
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1282
|
-
const responseType = dataReturnType === "data" ? responseName :
|
|
1241
|
+
const responseType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1283
1242
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1284
1243
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
1285
1244
|
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
@@ -1337,11 +1296,10 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1337
1296
|
children: `
|
|
1338
1297
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1339
1298
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1340
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1341
|
-
${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}' })` : ""}
|
|
1342
1300
|
|
|
1343
1301
|
const query = useSuspenseInfiniteQuery({
|
|
1344
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1302
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1345
1303
|
...resolvedOptions,
|
|
1346
1304
|
queryKey,
|
|
1347
1305
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|
|
@@ -1360,7 +1318,7 @@ const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
|
1360
1318
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1361
1319
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1362
1320
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1363
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
1321
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1364
1322
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1365
1323
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1366
1324
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1404,11 +1362,10 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1404
1362
|
getNextPageParamExpr,
|
|
1405
1363
|
getPreviousPageParamExpr
|
|
1406
1364
|
].filter(Boolean);
|
|
1407
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
} as ${queryParamsTypeName}` : "";
|
|
1365
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
1366
|
+
...(params ?? {}),
|
|
1367
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1368
|
+
} as ${queryParamsTypeName}` : "";
|
|
1412
1369
|
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
1413
1370
|
name,
|
|
1414
1371
|
isExportable: true,
|
|
@@ -1418,15 +1375,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1418
1375
|
export: true,
|
|
1419
1376
|
params: paramsSignature,
|
|
1420
1377
|
children: `
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
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
|
+
})
|
|
1430
1387
|
`
|
|
1431
1388
|
})
|
|
1432
1389
|
});
|
|
@@ -1439,14 +1396,14 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1439
1396
|
export: true,
|
|
1440
1397
|
params: paramsSignature,
|
|
1441
1398
|
children: `
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
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
|
+
})
|
|
1450
1407
|
`
|
|
1451
1408
|
})
|
|
1452
1409
|
});
|
|
@@ -1461,7 +1418,7 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1461
1418
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1462
1419
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1463
1420
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1464
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1421
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1465
1422
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1466
1423
|
const optionsParam = ast.createFunctionParameter({
|
|
1467
1424
|
name: "options",
|
|
@@ -1491,7 +1448,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1491
1448
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1492
1449
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1493
1450
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1494
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1451
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1495
1452
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1496
1453
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1497
1454
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
@@ -1529,11 +1486,10 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1529
1486
|
children: `
|
|
1530
1487
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1531
1488
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1532
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
1533
|
-
${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}' })` : ""}
|
|
1534
1490
|
|
|
1535
1491
|
const query = useSuspenseQuery({
|
|
1536
|
-
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
|
|
1492
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n ...customOptions," : ""}
|
|
1537
1493
|
...resolvedOptions,
|
|
1538
1494
|
queryKey,
|
|
1539
1495
|
} as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
|
|
@@ -1548,4 +1504,4 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1548
1504
|
//#endregion
|
|
1549
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 };
|
|
1550
1506
|
|
|
1551
|
-
//# sourceMappingURL=components-
|
|
1507
|
+
//# sourceMappingURL=components-DL0Cai7l.js.map
|