@kubb/plugin-vue-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-Bxe1EuWf.js → components-B79Gljyl.js} +176 -214
- package/dist/components-B79Gljyl.js.map +1 -0
- package/dist/{components-BwFPMwK7.cjs → components-D3xIZ9FA.cjs} +178 -216
- package/dist/components-D3xIZ9FA.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-BSN6A0ED.cjs → generators-BTtcGtUY.cjs} +91 -137
- package/dist/generators-BTtcGtUY.cjs.map +1 -0
- package/dist/{generators-D9TUvYRN.js → generators-D95ddIFV.js} +93 -139
- package/dist/generators-D95ddIFV.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +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-HHnnlEhK.d.ts → types-CwabLiFK.d.ts} +10 -14
- package/package.json +10 -17
- package/src/components/InfiniteQuery.tsx +3 -3
- package/src/components/InfiniteQueryOptions.tsx +24 -27
- package/src/components/Mutation.tsx +3 -3
- package/src/components/Query.tsx +3 -3
- package/src/components/QueryOptions.tsx +6 -27
- package/src/generators/infiniteQueryGenerator.tsx +5 -9
- package/src/generators/mutationGenerator.tsx +8 -9
- package/src/generators/queryGenerator.tsx +5 -9
- package/src/plugin.ts +4 -4
- package/src/resolvers/resolverVueQuery.ts +2 -2
- package/src/types.ts +9 -13
- package/src/utils.ts +1 -0
- package/dist/components-BwFPMwK7.cjs.map +0 -1
- package/dist/components-Bxe1EuWf.js.map +0 -1
- package/dist/generators-BSN6A0ED.cjs.map +0 -1
- package/dist/generators-D9TUvYRN.js.map +0 -1
- package/extension.yaml +0 -1248
|
@@ -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$7 = 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: [] });
|
|
@@ -461,13 +382,73 @@ function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
|
461
382
|
//#endregion
|
|
462
383
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
463
384
|
/**
|
|
464
|
-
*
|
|
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
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Returns `'zod'` when response-direction parsing is enabled.
|
|
410
|
+
* The string shorthand `'zod'` also enables response parsing.
|
|
411
|
+
*/
|
|
412
|
+
function resolveResponseParser(parser) {
|
|
413
|
+
if (!parser) return null;
|
|
414
|
+
if (parser === "zod") return "zod";
|
|
415
|
+
return parser.response ?? null;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
419
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
420
|
+
*/
|
|
421
|
+
function resolveRequestParser(parser) {
|
|
422
|
+
if (!parser) return null;
|
|
423
|
+
if (parser === "zod") return "zod";
|
|
424
|
+
return parser.request ?? null;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Returns `'zod'` when query-params parsing is enabled.
|
|
428
|
+
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
429
|
+
*/
|
|
430
|
+
function resolveQueryParamsParser(parser) {
|
|
431
|
+
if (!parser || parser === "zod") return null;
|
|
432
|
+
return parser.request ?? null;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
436
|
+
*
|
|
437
|
+
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
438
|
+
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
439
|
+
* - `parser: { response: 'zod' }`: response name only.
|
|
440
|
+
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
465
441
|
*
|
|
466
|
-
* Returns an empty array when no resolver is provided or
|
|
442
|
+
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
467
443
|
*/
|
|
468
|
-
function resolveZodSchemaNames(node, zodResolver) {
|
|
469
|
-
if (!zodResolver) return [];
|
|
470
|
-
|
|
444
|
+
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
445
|
+
if (!zodResolver || !parser) return [];
|
|
446
|
+
const { query: queryParams } = getOperationParameters(node);
|
|
447
|
+
return [
|
|
448
|
+
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
449
|
+
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
450
|
+
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
451
|
+
].filter((n) => Boolean(n));
|
|
471
452
|
}
|
|
472
453
|
/**
|
|
473
454
|
* Resolve the type for a single path parameter.
|
|
@@ -625,13 +606,13 @@ function markParamsOptional(paramsNode, names) {
|
|
|
625
606
|
functionPrinter({ mode: "declaration" });
|
|
626
607
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
627
608
|
if (!node.path) return [];
|
|
628
|
-
const path = new URLPath(node.path, { casing });
|
|
629
609
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
630
610
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
631
611
|
return [
|
|
632
|
-
|
|
612
|
+
Url.toObject(node.path, {
|
|
633
613
|
type: "path",
|
|
634
|
-
stringify: true
|
|
614
|
+
stringify: true,
|
|
615
|
+
casing
|
|
635
616
|
}),
|
|
636
617
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
637
618
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -723,28 +704,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
723
704
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
724
705
|
const callPrinter$4 = functionPrinter({ mode: "call" });
|
|
725
706
|
function getQueryOptionsParams(node, options) {
|
|
726
|
-
|
|
727
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
728
|
-
return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
|
|
729
|
-
paramsType,
|
|
730
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
731
|
-
paramsCasing,
|
|
732
|
-
resolver,
|
|
733
|
-
extraParams: [ast.createFunctionParameter({
|
|
734
|
-
name: "config",
|
|
735
|
-
type: ast.createParamsType({
|
|
736
|
-
variant: "reference",
|
|
737
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
738
|
-
}),
|
|
739
|
-
default: "{}"
|
|
740
|
-
})]
|
|
741
|
-
}), (name) => name === "config");
|
|
707
|
+
return wrapWithMaybeRefOrGetter(buildQueryOptionsParams(node, options), (name) => name === "config");
|
|
742
708
|
}
|
|
743
709
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
744
710
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
745
711
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
746
712
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
747
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
713
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
748
714
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
749
715
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
750
716
|
pathParamsType,
|
|
@@ -772,8 +738,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
772
738
|
params: paramsSignature,
|
|
773
739
|
children: `
|
|
774
740
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
775
|
-
return queryOptions<${TData}, ${TError}, ${TData}>({
|
|
776
|
-
${enabledText}
|
|
741
|
+
return queryOptions<${TData}, ${TError}, ${TData}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
777
742
|
queryKey,
|
|
778
743
|
queryFn: async ({ signal }) => {
|
|
779
744
|
return ${clientName}(${addToValueCalls$1(clientCallStr, enabledNames)})
|
|
@@ -814,7 +779,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
814
779
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
815
780
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
816
781
|
const errorNames = resolveErrorNames(node, resolver);
|
|
817
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
782
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
818
783
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
819
784
|
const optionsParam = ast.createFunctionParameter({
|
|
820
785
|
name: "options",
|
|
@@ -845,7 +810,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
845
810
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
846
811
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
847
812
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
848
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
813
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
849
814
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
850
815
|
const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
|
|
851
816
|
const generics = [
|
|
@@ -910,7 +875,7 @@ const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
|
910
875
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
911
876
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
912
877
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
913
|
-
const queryFnDataType = dataReturnType === "data" ? responseName :
|
|
878
|
+
const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
914
879
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
915
880
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
916
881
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -956,11 +921,10 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
956
921
|
getNextPageParamExpr,
|
|
957
922
|
getPreviousPageParamExpr
|
|
958
923
|
].filter(Boolean);
|
|
959
|
-
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
} as ${queryParamsTypeName}` : "";
|
|
924
|
+
const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
|
|
925
|
+
...(params ?? {}),
|
|
926
|
+
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
927
|
+
} as ${queryParamsTypeName}` : "";
|
|
964
928
|
if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
|
|
965
929
|
name,
|
|
966
930
|
isExportable: true,
|
|
@@ -970,16 +934,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
970
934
|
export: true,
|
|
971
935
|
params: paramsSignature,
|
|
972
936
|
children: `
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
})
|
|
937
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
938
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
939
|
+
queryKey,
|
|
940
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
941
|
+
${infiniteOverrideParams}
|
|
942
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
943
|
+
},
|
|
944
|
+
${queryOptionsArr.join(",\n ")}
|
|
945
|
+
})
|
|
983
946
|
`
|
|
984
947
|
})
|
|
985
948
|
});
|
|
@@ -992,15 +955,14 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
992
955
|
export: true,
|
|
993
956
|
params: paramsSignature,
|
|
994
957
|
children: `
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
})
|
|
958
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
959
|
+
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
|
|
960
|
+
queryKey,
|
|
961
|
+
queryFn: async ({ signal }) => {
|
|
962
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
963
|
+
},
|
|
964
|
+
${queryOptionsArr.join(",\n ")}
|
|
965
|
+
})
|
|
1004
966
|
`
|
|
1005
967
|
})
|
|
1006
968
|
});
|
|
@@ -1036,7 +998,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1036
998
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1037
999
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1038
1000
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1039
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1001
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1040
1002
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1041
1003
|
const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
|
|
1042
1004
|
paramsCasing,
|
|
@@ -1064,7 +1026,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1064
1026
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1065
1027
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1066
1028
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1067
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1029
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1068
1030
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1069
1031
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1070
1032
|
paramsCasing,
|
|
@@ -1138,7 +1100,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1138
1100
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1139
1101
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1140
1102
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1141
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1103
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
1142
1104
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1143
1105
|
const optionsParam = ast.createFunctionParameter({
|
|
1144
1106
|
name: "options",
|
|
@@ -1169,7 +1131,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1169
1131
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1170
1132
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1171
1133
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1172
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
1134
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
1173
1135
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1174
1136
|
const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
|
|
1175
1137
|
const generics = [
|
|
@@ -1230,4 +1192,4 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1230
1192
|
//#endregion
|
|
1231
1193
|
export { QueryOptions as a, resolveZodSchemaNames as c, getOperationParameters as d, operationFileEntry as f, InfiniteQuery as i, MutationKey as l, camelCase as m, Mutation as n, QueryKey as o, resolveOperationTypeNames as p, InfiniteQueryOptions as r, queryKeyTransformer as s, Query as t, mutationKeyTransformer as u };
|
|
1232
1194
|
|
|
1233
|
-
//# sourceMappingURL=components-
|
|
1195
|
+
//# sourceMappingURL=components-B79Gljyl.js.map
|