@kubb/plugin-vue-query 5.7.0-canary.20261025T201031 → 5.7.1
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/index.cjs +319 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -17
- package/dist/index.d.ts +1 -17
- package/dist/index.js +318 -129
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
1
|
+
import { Diagnostics, Resolver, Url, addGenerator, ast, camelCase, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
4
4
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
5
5
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
//#region ../../internals/shared/src/operation.ts
|
|
7
|
+
// ../../internals/shared/src/operation.ts
|
|
9
8
|
/**
|
|
10
9
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
11
10
|
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
@@ -74,6 +73,24 @@ function getContentTypeInfo(node) {
|
|
|
74
73
|
function getResponseContentTypeInfo(node) {
|
|
75
74
|
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
76
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Reads the single base content type of an operation's primary success response, lowercased and
|
|
78
|
+
* stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or
|
|
79
|
+
* more than one content type, since neither case has a single type to act on.
|
|
80
|
+
*/
|
|
81
|
+
function getPrimarySuccessContentType(node) {
|
|
82
|
+
const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? [];
|
|
83
|
+
if (contentTypes.length !== 1) return void 0;
|
|
84
|
+
return contentTypes[0].split(";")[0].trim().toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether an operation streams its primary success response as Server-Sent Events
|
|
88
|
+
* (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
|
|
89
|
+
* one-shot `RequestResult`.
|
|
90
|
+
*/
|
|
91
|
+
function isEventStream(node) {
|
|
92
|
+
return getPrimarySuccessContentType(node) === "text/event-stream";
|
|
93
|
+
}
|
|
77
94
|
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
78
95
|
function buildRequestConfigType(node) {
|
|
79
96
|
const request = getContentTypeInfo(node);
|
|
@@ -165,6 +182,22 @@ function getOperationParameters(node) {
|
|
|
165
182
|
operationParameterGroupsByNode.set(node, groups);
|
|
166
183
|
return groups;
|
|
167
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Builds the combined `{ body, path, query, headers }` options object schema for an operation,
|
|
187
|
+
* referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
|
|
188
|
+
* `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
|
|
189
|
+
* shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
|
|
190
|
+
* printer to emit `z.object(…)` rather than a record.
|
|
191
|
+
*/
|
|
192
|
+
function hasRequestContentTypeChoice(node) {
|
|
193
|
+
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
|
|
197
|
+
*/
|
|
198
|
+
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
199
|
+
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
200
|
+
}
|
|
168
201
|
function getStatusCodeNumber(statusCode) {
|
|
169
202
|
const code = Number(statusCode);
|
|
170
203
|
return Number.isNaN(code) ? null : code;
|
|
@@ -195,88 +228,184 @@ function resolveSuccessNames(node, resolver) {
|
|
|
195
228
|
function resolveStatusCodeNames(node, resolver) {
|
|
196
229
|
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
197
230
|
}
|
|
198
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Lists the type names an operation's types file declares, computed once per resolver and `options` so every
|
|
233
|
+
* dependent reads the same list.
|
|
234
|
+
*/
|
|
199
235
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
...responseStatusNames
|
|
222
|
-
] : [
|
|
223
|
-
...paramNames,
|
|
224
|
-
...bodyAndResponseNames,
|
|
225
|
-
...responseStatusNames
|
|
226
|
-
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
227
|
-
byResolver.set(cacheKey, result);
|
|
228
|
-
return result;
|
|
236
|
+
const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
|
|
237
|
+
return resolver.memo(`operationTypeNames:${key}`, () => {
|
|
238
|
+
const { path, query, header } = getOperationParameters(node);
|
|
239
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
240
|
+
const exclude = new Set(options.exclude ?? []);
|
|
241
|
+
const paramNames = options.includeParams === false ? [] : [
|
|
242
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
243
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
244
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
245
|
+
];
|
|
246
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
247
|
+
return (options.order === "body-response-first" ? [
|
|
248
|
+
...bodyAndResponseNames,
|
|
249
|
+
...paramNames,
|
|
250
|
+
...responseStatusNames
|
|
251
|
+
] : [
|
|
252
|
+
...paramNames,
|
|
253
|
+
...bodyAndResponseNames,
|
|
254
|
+
...responseStatusNames
|
|
255
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
256
|
+
});
|
|
229
257
|
}
|
|
230
|
-
|
|
231
|
-
//#region ../../internals/utils/src/casing.ts
|
|
258
|
+
// ../../internals/utils/src/casing.ts
|
|
232
259
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* and capitalizes each word according to `pascal`.
|
|
260
|
+
* Uppercases only the first character of `text`, leaving the rest untouched.
|
|
261
|
+
* Unlike `pascalCase` it never re-splits word boundaries or strips characters.
|
|
236
262
|
*
|
|
237
|
-
*
|
|
263
|
+
* @example
|
|
264
|
+
* `capitalize('getPetById') // 'GetPetById'`
|
|
238
265
|
*/
|
|
239
|
-
function
|
|
240
|
-
return text.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
function capitalize(text) {
|
|
267
|
+
return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
268
|
+
}
|
|
269
|
+
// ../../internals/utils/src/reserved.ts
|
|
270
|
+
/**
|
|
271
|
+
* JavaScript and Java reserved words.
|
|
272
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
273
|
+
*/
|
|
274
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
275
|
+
"abstract",
|
|
276
|
+
"arguments",
|
|
277
|
+
"await",
|
|
278
|
+
"boolean",
|
|
279
|
+
"break",
|
|
280
|
+
"byte",
|
|
281
|
+
"case",
|
|
282
|
+
"catch",
|
|
283
|
+
"char",
|
|
284
|
+
"class",
|
|
285
|
+
"const",
|
|
286
|
+
"continue",
|
|
287
|
+
"debugger",
|
|
288
|
+
"default",
|
|
289
|
+
"delete",
|
|
290
|
+
"do",
|
|
291
|
+
"double",
|
|
292
|
+
"else",
|
|
293
|
+
"enum",
|
|
294
|
+
"eval",
|
|
295
|
+
"export",
|
|
296
|
+
"extends",
|
|
297
|
+
"false",
|
|
298
|
+
"final",
|
|
299
|
+
"finally",
|
|
300
|
+
"float",
|
|
301
|
+
"for",
|
|
302
|
+
"function",
|
|
303
|
+
"goto",
|
|
304
|
+
"if",
|
|
305
|
+
"implements",
|
|
306
|
+
"import",
|
|
307
|
+
"in",
|
|
308
|
+
"instanceof",
|
|
309
|
+
"int",
|
|
310
|
+
"interface",
|
|
311
|
+
"let",
|
|
312
|
+
"long",
|
|
313
|
+
"native",
|
|
314
|
+
"new",
|
|
315
|
+
"null",
|
|
316
|
+
"package",
|
|
317
|
+
"private",
|
|
318
|
+
"protected",
|
|
319
|
+
"public",
|
|
320
|
+
"return",
|
|
321
|
+
"short",
|
|
322
|
+
"static",
|
|
323
|
+
"super",
|
|
324
|
+
"switch",
|
|
325
|
+
"synchronized",
|
|
326
|
+
"this",
|
|
327
|
+
"throw",
|
|
328
|
+
"throws",
|
|
329
|
+
"transient",
|
|
330
|
+
"true",
|
|
331
|
+
"try",
|
|
332
|
+
"typeof",
|
|
333
|
+
"var",
|
|
334
|
+
"void",
|
|
335
|
+
"volatile",
|
|
336
|
+
"while",
|
|
337
|
+
"with",
|
|
338
|
+
"yield",
|
|
339
|
+
"Array",
|
|
340
|
+
"Date",
|
|
341
|
+
"hasOwnProperty",
|
|
342
|
+
"Infinity",
|
|
343
|
+
"isFinite",
|
|
344
|
+
"isNaN",
|
|
345
|
+
"isPrototypeOf",
|
|
346
|
+
"length",
|
|
347
|
+
"Math",
|
|
348
|
+
"name",
|
|
349
|
+
"NaN",
|
|
350
|
+
"Number",
|
|
351
|
+
"Object",
|
|
352
|
+
"prototype",
|
|
353
|
+
"String",
|
|
354
|
+
"toString",
|
|
355
|
+
"undefined",
|
|
356
|
+
"valueOf"
|
|
357
|
+
]);
|
|
358
|
+
/**
|
|
359
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* isValidVarName('status') // true
|
|
364
|
+
* isValidVarName('class') // false (reserved word)
|
|
365
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
function isValidVarName(name) {
|
|
369
|
+
if (!name || reservedWords.has(name)) return false;
|
|
370
|
+
return isIdentifier(name);
|
|
255
371
|
}
|
|
256
372
|
/**
|
|
257
|
-
*
|
|
373
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
374
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
258
375
|
*
|
|
259
|
-
*
|
|
260
|
-
* `
|
|
376
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
377
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
378
|
+
* variable, type, or function names.
|
|
261
379
|
*
|
|
262
|
-
* @example
|
|
263
|
-
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* ensureValidVarName('409') // '_409'
|
|
383
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
384
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
385
|
+
* ensureValidVarName('class') // '_class'
|
|
386
|
+
* ```
|
|
264
387
|
*/
|
|
265
|
-
function
|
|
266
|
-
|
|
388
|
+
function ensureValidVarName(name) {
|
|
389
|
+
if (!name || isValidVarName(name)) return name;
|
|
390
|
+
return `_${name}`;
|
|
267
391
|
}
|
|
268
392
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
393
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
394
|
+
*
|
|
395
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
396
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
397
|
+
* deciding whether an object key needs quoting.
|
|
271
398
|
*
|
|
272
399
|
* @example
|
|
273
|
-
*
|
|
400
|
+
* ```ts
|
|
401
|
+
* isIdentifier('name') // true
|
|
402
|
+
* isIdentifier('x-total')// false
|
|
403
|
+
* ```
|
|
274
404
|
*/
|
|
275
|
-
function
|
|
276
|
-
return
|
|
405
|
+
function isIdentifier(name) {
|
|
406
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
277
407
|
}
|
|
278
|
-
|
|
279
|
-
//#region ../../internals/utils/src/strings.ts
|
|
408
|
+
// ../../internals/utils/src/strings.ts
|
|
280
409
|
/**
|
|
281
410
|
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
282
411
|
* `accessor`. Returns `null` for an empty path.
|
|
@@ -292,8 +421,32 @@ function getNestedAccessor(param, accessor) {
|
|
|
292
421
|
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
293
422
|
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
294
423
|
}
|
|
295
|
-
|
|
296
|
-
|
|
424
|
+
// ../../internals/shared/src/resolver.ts
|
|
425
|
+
/**
|
|
426
|
+
* The shared top-level `name` of the operation plugins, computed once per operation name and build.
|
|
427
|
+
*/
|
|
428
|
+
function resolveOperationName(name) {
|
|
429
|
+
return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)));
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
433
|
+
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
434
|
+
* name. Leave `scope` empty for the operation's own declaration.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
function operationKey(node, ...scope) {
|
|
442
|
+
return [
|
|
443
|
+
"operation",
|
|
444
|
+
node.method,
|
|
445
|
+
node.path,
|
|
446
|
+
...scope.map(String)
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
// ../../internals/shared/src/group.ts
|
|
297
450
|
/**
|
|
298
451
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
299
452
|
* shared default naming so every plugin groups output consistently:
|
|
@@ -323,17 +476,14 @@ function createGroupConfig(group) {
|
|
|
323
476
|
name: group.name ? group.name : defaultName
|
|
324
477
|
};
|
|
325
478
|
}
|
|
326
|
-
|
|
327
|
-
//#region kubb-extension.json
|
|
479
|
+
// kubb-extension.json
|
|
328
480
|
var compatibility = {
|
|
329
|
-
"kubb": ">=5.
|
|
481
|
+
"kubb": ">=5.14.6",
|
|
330
482
|
"node": ">=22.22"
|
|
331
483
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
//#endregion
|
|
336
|
-
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
484
|
+
// package.json
|
|
485
|
+
var version = "5.7.1";
|
|
486
|
+
// ../../internals/client/src/resolveOperationTypes.ts
|
|
337
487
|
/**
|
|
338
488
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
339
489
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -343,6 +493,7 @@ function toZodTypeResolver(resolver) {
|
|
|
343
493
|
return {
|
|
344
494
|
...resolver,
|
|
345
495
|
file: resolver.file.bind(resolver),
|
|
496
|
+
memo: (key, compute) => resolver.memo(`zodTypes:${key}`, compute),
|
|
346
497
|
param: {
|
|
347
498
|
name: (node, p) => type(resolver.param.name(node, p)),
|
|
348
499
|
path: (node, p) => type(resolver.param.path(node, p)),
|
|
@@ -399,8 +550,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
399
550
|
group: pluginZod.options.group ?? void 0
|
|
400
551
|
};
|
|
401
552
|
}
|
|
402
|
-
|
|
403
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
553
|
+
// ../../internals/client/src/resolveClient.ts
|
|
404
554
|
/**
|
|
405
555
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
406
556
|
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
@@ -510,8 +660,7 @@ function resolveContractClient(options) {
|
|
|
510
660
|
}
|
|
511
661
|
return resolved;
|
|
512
662
|
}
|
|
513
|
-
|
|
514
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
663
|
+
// ../../internals/client/src/resolveClientOperation.ts
|
|
515
664
|
function isRelativeImport(importPath) {
|
|
516
665
|
return importPath.startsWith(".");
|
|
517
666
|
}
|
|
@@ -558,8 +707,12 @@ function resolveClientOperation(options) {
|
|
|
558
707
|
group: operationOptions.group ?? void 0
|
|
559
708
|
});
|
|
560
709
|
const { importPath } = operationOptions;
|
|
710
|
+
const name = resolver.name(node.operationId);
|
|
561
711
|
return {
|
|
562
|
-
name: resolver.
|
|
712
|
+
name: resolver.resolveName({
|
|
713
|
+
key: operationKey(node),
|
|
714
|
+
name
|
|
715
|
+
}),
|
|
563
716
|
path: file.path,
|
|
564
717
|
clientPath: importPath === void 0 ? path.resolve(root, ".kubb/client.ts") : resolveImportPath({
|
|
565
718
|
importPath,
|
|
@@ -570,8 +723,7 @@ function resolveClientOperation(options) {
|
|
|
570
723
|
};
|
|
571
724
|
});
|
|
572
725
|
}
|
|
573
|
-
|
|
574
|
-
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
726
|
+
// ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
575
727
|
/**
|
|
576
728
|
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
577
729
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
@@ -660,8 +812,7 @@ function HookFile({ hook, imports, children }) {
|
|
|
660
812
|
]
|
|
661
813
|
});
|
|
662
814
|
}
|
|
663
|
-
|
|
664
|
-
//#region ../../internals/tanstack-query/src/utils.ts
|
|
815
|
+
// ../../internals/tanstack-query/src/utils.ts
|
|
665
816
|
/**
|
|
666
817
|
* The grouped request options, ordered for both the destructured signature and the
|
|
667
818
|
* call passed to the underlying client.
|
|
@@ -697,7 +848,7 @@ function maybeRefOrGetter(type) {
|
|
|
697
848
|
* `MaybeRefOrGetter` per group.
|
|
698
849
|
*/
|
|
699
850
|
function buildGroupedRequestParam(node, options) {
|
|
700
|
-
const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
|
|
851
|
+
const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
|
|
701
852
|
const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
|
|
702
853
|
const names = keys.filter((key) => groups[key]);
|
|
703
854
|
if (names.length === 0) return null;
|
|
@@ -709,6 +860,11 @@ function buildGroupedRequestParam(node, options) {
|
|
|
709
860
|
};
|
|
710
861
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
711
862
|
const optionsName = resolver.response.options(node);
|
|
863
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return createFunctionParameter({
|
|
864
|
+
name: "variables",
|
|
865
|
+
type: optionsName,
|
|
866
|
+
optional: false
|
|
867
|
+
});
|
|
712
868
|
const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
|
|
713
869
|
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
714
870
|
if (memberTypeWrapper) {
|
|
@@ -766,14 +922,17 @@ function buildQueryOptionsParams(node, options) {
|
|
|
766
922
|
* ```
|
|
767
923
|
*/
|
|
768
924
|
function buildClientCall(node, options) {
|
|
769
|
-
const { clientName, signal = false, unwrapName } = options;
|
|
925
|
+
const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
|
|
770
926
|
const { groups } = getRequestGroupOptionality(node);
|
|
771
|
-
|
|
927
|
+
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
928
|
+
const args = [
|
|
772
929
|
"...config",
|
|
773
|
-
...
|
|
930
|
+
...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
|
|
774
931
|
signal ? "signal: config.signal ?? signal" : null,
|
|
775
932
|
"throwOnError: true"
|
|
776
|
-
].filter((part) => part !== null)
|
|
933
|
+
].filter((part) => part !== null);
|
|
934
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
|
|
935
|
+
return `${clientName}({ ${args.join(", ")} })`;
|
|
777
936
|
}
|
|
778
937
|
/**
|
|
779
938
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
@@ -869,9 +1028,14 @@ function resolveMutationConfig(mutation, options) {
|
|
|
869
1028
|
/**
|
|
870
1029
|
* Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
|
|
871
1030
|
* Disabled query and mutation configs do not claim operations, and a method already claimed by an
|
|
872
|
-
* enabled query config never counts as a mutation.
|
|
1031
|
+
* enabled query config never counts as a mutation. Event streams are consumed through the client
|
|
1032
|
+
* directly, so they do not generate query or mutation hooks.
|
|
873
1033
|
*/
|
|
874
1034
|
function classifyOperation(node, { query, mutation }) {
|
|
1035
|
+
if (isEventStream(node)) return {
|
|
1036
|
+
isQuery: false,
|
|
1037
|
+
isMutation: false
|
|
1038
|
+
};
|
|
875
1039
|
const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
876
1040
|
const queryMethods = new Set(query ? query.methods : []);
|
|
877
1041
|
return {
|
|
@@ -980,8 +1144,7 @@ function buildHookParams(node, options) {
|
|
|
980
1144
|
function resolveMutationRequestType(node, resolver) {
|
|
981
1145
|
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
982
1146
|
}
|
|
983
|
-
|
|
984
|
-
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1147
|
+
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
985
1148
|
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
986
1149
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
987
1150
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
@@ -1057,8 +1220,7 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1057
1220
|
})
|
|
1058
1221
|
});
|
|
1059
1222
|
}
|
|
1060
|
-
|
|
1061
|
-
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
1223
|
+
// ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
1062
1224
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
1063
1225
|
/**
|
|
1064
1226
|
* Default `mutationKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -1105,8 +1267,7 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1105
1267
|
})
|
|
1106
1268
|
})] });
|
|
1107
1269
|
}
|
|
1108
|
-
|
|
1109
|
-
//#region ../../internals/tanstack-query/src/resolver.ts
|
|
1270
|
+
// ../../internals/tanstack-query/src/resolver.ts
|
|
1110
1271
|
/**
|
|
1111
1272
|
* Builds the shared query namespace for a variant. Spread the result into
|
|
1112
1273
|
* `createResolver` once per variant the plugin supports.
|
|
@@ -1122,19 +1283,39 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1122
1283
|
function createQueryResolver(variant = "") {
|
|
1123
1284
|
return {
|
|
1124
1285
|
name(node) {
|
|
1125
|
-
|
|
1286
|
+
const name = `use${capitalize(this.name(node.operationId))}${variant}`;
|
|
1287
|
+
return this.resolveName({
|
|
1288
|
+
key: operationKey(node, "query", variant, "name"),
|
|
1289
|
+
name
|
|
1290
|
+
});
|
|
1126
1291
|
},
|
|
1127
1292
|
optionsName(node) {
|
|
1128
|
-
|
|
1293
|
+
const name = `${this.name(node.operationId)}${variant}QueryOptions`;
|
|
1294
|
+
return this.resolveName({
|
|
1295
|
+
key: operationKey(node, "query", variant, "optionsName"),
|
|
1296
|
+
name
|
|
1297
|
+
});
|
|
1129
1298
|
},
|
|
1130
1299
|
keyName(node) {
|
|
1131
|
-
|
|
1300
|
+
const name = `${this.name(node.operationId)}${variant}QueryKey`;
|
|
1301
|
+
return this.resolveName({
|
|
1302
|
+
key: operationKey(node, "query", variant, "keyName"),
|
|
1303
|
+
name
|
|
1304
|
+
});
|
|
1132
1305
|
},
|
|
1133
1306
|
keyTypeName(node) {
|
|
1134
|
-
|
|
1307
|
+
const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
|
|
1308
|
+
return this.resolveName({
|
|
1309
|
+
key: operationKey(node, "query", variant, "keyTypeName"),
|
|
1310
|
+
name
|
|
1311
|
+
});
|
|
1135
1312
|
},
|
|
1136
1313
|
clientName(node) {
|
|
1137
|
-
|
|
1314
|
+
const name = `${this.name(node.operationId)}${variant}`;
|
|
1315
|
+
return this.resolveName({
|
|
1316
|
+
key: operationKey(node, "query", variant, "clientName"),
|
|
1317
|
+
name
|
|
1318
|
+
});
|
|
1138
1319
|
}
|
|
1139
1320
|
};
|
|
1140
1321
|
}
|
|
@@ -1151,15 +1332,22 @@ function createQueryResolver(variant = "") {
|
|
|
1151
1332
|
function createMutationResolver() {
|
|
1152
1333
|
return {
|
|
1153
1334
|
name(node) {
|
|
1154
|
-
|
|
1335
|
+
const name = `use${capitalize(this.name(node.operationId))}`;
|
|
1336
|
+
return this.resolveName({
|
|
1337
|
+
key: operationKey(node, "mutation", "name"),
|
|
1338
|
+
name
|
|
1339
|
+
});
|
|
1155
1340
|
},
|
|
1156
1341
|
keyName(node) {
|
|
1157
|
-
|
|
1342
|
+
const name = `${this.name(node.operationId)}MutationKey`;
|
|
1343
|
+
return this.resolveName({
|
|
1344
|
+
key: operationKey(node, "mutation", "keyName"),
|
|
1345
|
+
name
|
|
1346
|
+
});
|
|
1158
1347
|
}
|
|
1159
1348
|
};
|
|
1160
1349
|
}
|
|
1161
|
-
|
|
1162
|
-
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
1350
|
+
// ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
1163
1351
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
1164
1352
|
/**
|
|
1165
1353
|
* Default `queryKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -1217,8 +1405,7 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1217
1405
|
})
|
|
1218
1406
|
})] });
|
|
1219
1407
|
}
|
|
1220
|
-
|
|
1221
|
-
//#region src/components/QueryOptions.tsx
|
|
1408
|
+
// src/components/QueryOptions.tsx
|
|
1222
1409
|
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
1223
1410
|
const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
1224
1411
|
function getQueryOptionsParams(node, options) {
|
|
@@ -1261,8 +1448,7 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1261
1448
|
})
|
|
1262
1449
|
});
|
|
1263
1450
|
}
|
|
1264
|
-
|
|
1265
|
-
//#region src/components/Query.tsx
|
|
1451
|
+
// src/components/Query.tsx
|
|
1266
1452
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1267
1453
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1268
1454
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite }) {
|
|
@@ -1345,8 +1531,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1345
1531
|
})
|
|
1346
1532
|
});
|
|
1347
1533
|
}
|
|
1348
|
-
|
|
1349
|
-
//#region src/generators/infiniteQueryGenerator.tsx
|
|
1534
|
+
// src/generators/infiniteQueryGenerator.tsx
|
|
1350
1535
|
/**
|
|
1351
1536
|
* Built-in generator for `useInfiniteQuery` composables. Enabled when
|
|
1352
1537
|
* `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
@@ -1479,8 +1664,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1479
1664
|
});
|
|
1480
1665
|
}
|
|
1481
1666
|
});
|
|
1482
|
-
|
|
1483
|
-
//#region src/components/Mutation.tsx
|
|
1667
|
+
// src/components/Mutation.tsx
|
|
1484
1668
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1485
1669
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1486
1670
|
function buildMutationParamsNode(node, options) {
|
|
@@ -1502,7 +1686,10 @@ function buildMutationParamsNode(node, options) {
|
|
|
1502
1686
|
}
|
|
1503
1687
|
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1504
1688
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1505
|
-
const groupedParam = buildGroupedRequestParam(node, {
|
|
1689
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
1690
|
+
resolver: tsResolver,
|
|
1691
|
+
withContentType: true
|
|
1692
|
+
});
|
|
1506
1693
|
const hasMutationParams = groupedParam !== null;
|
|
1507
1694
|
const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
1508
1695
|
const argBindingStr = hasMutationParams ? callPrinter.print(groupedParamsNode) ?? "" : "";
|
|
@@ -1510,6 +1697,8 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnT
|
|
|
1510
1697
|
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1511
1698
|
clientName,
|
|
1512
1699
|
signal: false,
|
|
1700
|
+
withContentType: true,
|
|
1701
|
+
returnType,
|
|
1513
1702
|
unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
|
|
1514
1703
|
}), { returnType });
|
|
1515
1704
|
const generics = [
|
|
@@ -1546,8 +1735,7 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnT
|
|
|
1546
1735
|
})
|
|
1547
1736
|
});
|
|
1548
1737
|
}
|
|
1549
|
-
|
|
1550
|
-
//#region src/generators/mutationGenerator.tsx
|
|
1738
|
+
// src/generators/mutationGenerator.tsx
|
|
1551
1739
|
/**
|
|
1552
1740
|
* Built-in generator for `useMutation` composables. Emits one
|
|
1553
1741
|
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
@@ -1621,8 +1809,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1621
1809
|
});
|
|
1622
1810
|
}
|
|
1623
1811
|
});
|
|
1624
|
-
|
|
1625
|
-
//#region src/generators/queryGenerator.tsx
|
|
1812
|
+
// src/generators/queryGenerator.tsx
|
|
1626
1813
|
/**
|
|
1627
1814
|
* Built-in generator for `useQuery` composables. Emits one `useFooQuery`
|
|
1628
1815
|
* composable per GET and QUERY operation (configurable via `query.methods`) plus the
|
|
@@ -1723,14 +1910,13 @@ const queryGenerator = defineGenerator({
|
|
|
1723
1910
|
});
|
|
1724
1911
|
}
|
|
1725
1912
|
});
|
|
1726
|
-
|
|
1727
|
-
//#region src/resolvers/resolverVueQuery.ts
|
|
1913
|
+
// src/resolvers/resolverVueQuery.ts
|
|
1728
1914
|
/**
|
|
1729
1915
|
* Default resolver used by `@kubb/plugin-vue-query`. Decides the names and
|
|
1730
1916
|
* file paths for every generated TanStack Query composable (`useFoo`,
|
|
1731
1917
|
* `useFooInfinite`) and its companion helpers.
|
|
1732
1918
|
*
|
|
1733
|
-
* The `default` helpers are supplied by `createResolver`. Functions
|
|
1919
|
+
* The `default` helpers are supplied by `createResolver`. Functions use safe camelCase identifiers;
|
|
1734
1920
|
* composables get the `use` prefix. Operation-specific naming is grouped under the `query`,
|
|
1735
1921
|
* `infiniteQuery`, and `mutation` namespaces.
|
|
1736
1922
|
*
|
|
@@ -1745,17 +1931,21 @@ const queryGenerator = defineGenerator({
|
|
|
1745
1931
|
*/
|
|
1746
1932
|
const resolverVueQuery = createResolver({
|
|
1747
1933
|
pluginName: "plugin-vue-query",
|
|
1934
|
+
name: resolveOperationName,
|
|
1748
1935
|
query: createQueryResolver(),
|
|
1749
1936
|
infiniteQuery: createQueryResolver("Infinite"),
|
|
1750
1937
|
mutation: {
|
|
1751
1938
|
...createMutationResolver(),
|
|
1752
1939
|
typeName(node) {
|
|
1753
|
-
|
|
1940
|
+
const name = capitalize(this.name(node.operationId));
|
|
1941
|
+
return this.resolveName({
|
|
1942
|
+
key: operationKey(node, "mutation", "typeName"),
|
|
1943
|
+
name
|
|
1944
|
+
});
|
|
1754
1945
|
}
|
|
1755
1946
|
}
|
|
1756
1947
|
});
|
|
1757
|
-
|
|
1758
|
-
//#region src/plugin.ts
|
|
1948
|
+
// src/plugin.ts
|
|
1759
1949
|
/**
|
|
1760
1950
|
* Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups
|
|
1761
1951
|
* and cross-plugin dependency references.
|
|
@@ -1823,7 +2013,6 @@ const pluginVueQuery = defineExtension({
|
|
|
1823
2013
|
};
|
|
1824
2014
|
}
|
|
1825
2015
|
});
|
|
1826
|
-
//#endregion
|
|
1827
2016
|
export { pluginVueQuery as default, pluginVueQuery, definePageParam, mutationKeyTransformer, pluginVueQueryName, queryKeyTransformer, resolverVueQuery };
|
|
1828
2017
|
|
|
1829
2018
|
//# sourceMappingURL=index.js.map
|