@kubb/plugin-vue-query 5.11.0 → 5.11.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 +243 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -36
- package/dist/index.d.ts +48 -36
- package/dist/index.js +244 -189
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ let _kubb_kit = require("@kubb/kit");
|
|
|
27
27
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
28
28
|
let node_path = require("node:path");
|
|
29
29
|
node_path = __toESM(node_path, 1);
|
|
30
|
+
let _kubb_ast = require("@kubb/ast");
|
|
30
31
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
31
32
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
32
33
|
// kubb-extension.json
|
|
@@ -35,7 +36,7 @@ var compatibility = {
|
|
|
35
36
|
"node": ">=22.22"
|
|
36
37
|
};
|
|
37
38
|
// package.json
|
|
38
|
-
var version = "5.11.
|
|
39
|
+
var version = "5.11.1";
|
|
39
40
|
// ../../internals/client/src/resolveClient.ts
|
|
40
41
|
/**
|
|
41
42
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -149,6 +150,143 @@ function resolveContractClient(options) {
|
|
|
149
150
|
}
|
|
150
151
|
return resolved;
|
|
151
152
|
}
|
|
153
|
+
// ../../internals/ast/src/http/requestBody.ts
|
|
154
|
+
/** The schema of the first request body entry, else `undefined` when the operation takes no body. */
|
|
155
|
+
function getSchema(node) {
|
|
156
|
+
return node.requestBody?.content?.[0]?.schema;
|
|
157
|
+
}
|
|
158
|
+
// ../../internals/ast/src/http/status.ts
|
|
159
|
+
const classByRange = /* @__PURE__ */ new Map([
|
|
160
|
+
["1xx", 1],
|
|
161
|
+
["2xx", 2],
|
|
162
|
+
["3xx", 3],
|
|
163
|
+
["4xx", 4],
|
|
164
|
+
["5xx", 5]
|
|
165
|
+
]);
|
|
166
|
+
/** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
|
|
167
|
+
function statusClass(input) {
|
|
168
|
+
const statusCode = typeof input === "object" ? input.statusCode : input;
|
|
169
|
+
const rangeClass = classByRange.get(String(statusCode));
|
|
170
|
+
if (rangeClass) return rangeClass;
|
|
171
|
+
const code = Number(statusCode);
|
|
172
|
+
return Number.isNaN(code) ? null : Math.floor(code / 100);
|
|
173
|
+
}
|
|
174
|
+
function isSuccess(statusCode) {
|
|
175
|
+
return statusClass(statusCode) === 2;
|
|
176
|
+
}
|
|
177
|
+
function isError(statusCode) {
|
|
178
|
+
const code = statusClass(statusCode);
|
|
179
|
+
return code !== null && code >= 4;
|
|
180
|
+
}
|
|
181
|
+
// ../../internals/ast/src/http/responses.ts
|
|
182
|
+
/** The `4xx` and `5xx` responses, ranges included. */
|
|
183
|
+
function filterError(node) {
|
|
184
|
+
return node.responses.filter((response) => isError(response.statusCode));
|
|
185
|
+
}
|
|
186
|
+
function filterSuccess(node) {
|
|
187
|
+
return node.responses.filter((response) => isSuccess(response.statusCode));
|
|
188
|
+
}
|
|
189
|
+
/** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
|
|
190
|
+
function findPrimary(node) {
|
|
191
|
+
const responses = filterSuccess(node);
|
|
192
|
+
const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
|
|
193
|
+
const candidates = withBody.length ? withBody : responses;
|
|
194
|
+
return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
|
|
195
|
+
}
|
|
196
|
+
// ../../internals/ast/src/http/index.ts
|
|
197
|
+
const isOperation = _kubb_ast.ast.http.isOperation;
|
|
198
|
+
/** Computes once per key; generators visit the same node many times. */
|
|
199
|
+
function cached(store, key, compute) {
|
|
200
|
+
if (!store.has(key)) store.set(key, compute());
|
|
201
|
+
return store.get(key);
|
|
202
|
+
}
|
|
203
|
+
const parametersByNode = /* @__PURE__ */ new WeakMap();
|
|
204
|
+
/** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
|
|
205
|
+
function groupParameters(node) {
|
|
206
|
+
return cached(parametersByNode, node, () => {
|
|
207
|
+
const group = (...locations) => {
|
|
208
|
+
const seen = /* @__PURE__ */ new Set();
|
|
209
|
+
return locations.flatMap((location) => node.parameters.filter((param) => {
|
|
210
|
+
if (param.in !== location || seen.has(param.name)) return false;
|
|
211
|
+
seen.add(param.name);
|
|
212
|
+
return true;
|
|
213
|
+
}));
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
path: group("path"),
|
|
217
|
+
query: group("query", "querystring"),
|
|
218
|
+
header: group("header"),
|
|
219
|
+
cookie: group("cookie")
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
224
|
+
/** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
|
|
225
|
+
function getRequestGroups(node) {
|
|
226
|
+
return cached(requestGroupsByNode, node, () => {
|
|
227
|
+
const { path, query, header, cookie } = groupParameters(node);
|
|
228
|
+
const content = node.requestBody?.content ?? [];
|
|
229
|
+
const body = Boolean(content[0]?.schema);
|
|
230
|
+
const required = {
|
|
231
|
+
path: path.some((param) => param.required),
|
|
232
|
+
query: query.some((param) => param.required),
|
|
233
|
+
headers: header.some((param) => param.required),
|
|
234
|
+
body: body && node.requestBody?.required === true
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
path: path.length > 0,
|
|
238
|
+
query: query.length > 0,
|
|
239
|
+
body,
|
|
240
|
+
headers: header.length > 0,
|
|
241
|
+
cookies: cookie.length > 0,
|
|
242
|
+
required,
|
|
243
|
+
isOptional: !required.path && !required.query && !required.headers && !required.body,
|
|
244
|
+
contentTypes: content.map((entry) => entry.contentType),
|
|
245
|
+
hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// ../../internals/ast/src/mediaType.ts
|
|
250
|
+
const streamMediaTypes = /* @__PURE__ */ new Set([
|
|
251
|
+
"application/jsonl",
|
|
252
|
+
"application/x-ndjson",
|
|
253
|
+
"application/json-seq",
|
|
254
|
+
"text/event-stream"
|
|
255
|
+
]);
|
|
256
|
+
const getBase = _kubb_ast.ast.mediaType.getBase;
|
|
257
|
+
const isJson = _kubb_ast.ast.mediaType.isJson;
|
|
258
|
+
/** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
|
|
259
|
+
function isStream(mediaType) {
|
|
260
|
+
const baseType = getBase(mediaType);
|
|
261
|
+
return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
|
|
262
|
+
}
|
|
263
|
+
const formKinds = {
|
|
264
|
+
"multipart/form-data": "form",
|
|
265
|
+
"application/x-www-form-urlencoded": "urlencoded"
|
|
266
|
+
};
|
|
267
|
+
/** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
|
|
268
|
+
function getKind(entry) {
|
|
269
|
+
const content = typeof entry === "string" ? { contentType: entry } : entry;
|
|
270
|
+
const baseType = getBase(content);
|
|
271
|
+
if (!baseType) return null;
|
|
272
|
+
if (baseType === "text/event-stream") return "eventStream";
|
|
273
|
+
if (content.stream && isStream(content)) return "lineStream";
|
|
274
|
+
if (isJson(baseType)) return "json";
|
|
275
|
+
if (formKinds[baseType]) return formKinds[baseType];
|
|
276
|
+
if (content.schema?.type === "blob") return "binary";
|
|
277
|
+
if (baseType.startsWith("text/")) return "text";
|
|
278
|
+
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
_kubb_ast.ast.schema.applyOptionality;
|
|
282
|
+
_kubb_ast.ast.schema.types;
|
|
283
|
+
const narrow = _kubb_ast.ast.schema.narrow;
|
|
284
|
+
_kubb_ast.ast.schema.find;
|
|
285
|
+
_kubb_ast.ast.schema.getEmbeddedJson;
|
|
286
|
+
const is = _kubb_ast.ast.schema.is;
|
|
287
|
+
const getLiterals = _kubb_ast.ast.schema.getLiterals;
|
|
288
|
+
_kubb_ast.ast.schema.inferDiscriminator;
|
|
289
|
+
const findProperties = _kubb_ast.ast.schema.findProperties;
|
|
152
290
|
// ../../internals/utils/src/reserved.ts
|
|
153
291
|
/**
|
|
154
292
|
* JavaScript and Java reserved words.
|
|
@@ -385,7 +523,7 @@ function resolveOperationFile(options) {
|
|
|
385
523
|
* The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
|
|
386
524
|
*/
|
|
387
525
|
function getOperationRequestLine(node) {
|
|
388
|
-
return
|
|
526
|
+
return isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
|
|
389
527
|
}
|
|
390
528
|
/**
|
|
391
529
|
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
@@ -402,55 +540,52 @@ function buildContentTypeInfo(contentTypes) {
|
|
|
402
540
|
};
|
|
403
541
|
}
|
|
404
542
|
function getContentTypeInfo(node) {
|
|
405
|
-
return buildContentTypeInfo(node
|
|
543
|
+
return buildContentTypeInfo(getRequestGroups(node).contentTypes);
|
|
406
544
|
}
|
|
407
545
|
/**
|
|
408
546
|
* The request-body counterpart for the primary success response: the content types it documents and
|
|
409
547
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
410
548
|
*/
|
|
411
549
|
function getResponseContentTypeInfo(node) {
|
|
412
|
-
return buildContentTypeInfo(
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
*/
|
|
434
|
-
function
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return getEventStream(node) !== null;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Whether a success response offers a stream media type next to other content types. The client returns that variant's
|
|
447
|
-
* body as a `ReadableStream`, so the stream runtime is registered and a hook's data type includes the stream.
|
|
448
|
-
*/
|
|
449
|
-
function hasStreamVariant(node) {
|
|
450
|
-
return _kubb_kit.ast.http.responses.filterSuccess(node).some((response) => {
|
|
451
|
-
const variants = (response.content ?? []).filter((entry) => entry.schema);
|
|
452
|
-
return variants.length > 1 && variants.some((entry) => _kubb_kit.ast.mediaType.isStream(entry));
|
|
550
|
+
return buildContentTypeInfo(findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
|
|
551
|
+
}
|
|
552
|
+
const isText = (schema) => !!schema && is(schema, "text", { follow: ["ref"] });
|
|
553
|
+
function getTextEvents(entry, shape) {
|
|
554
|
+
if (shape === "data") return isText(entry.stream?.schema ?? entry.schema);
|
|
555
|
+
if (shape !== "event" || !entry.stream?.schema) return false;
|
|
556
|
+
const item = _kubb_ast.ref.getSchema(entry.stream.schema);
|
|
557
|
+
const events = narrow(item, "union")?.members ?? [item];
|
|
558
|
+
const propertySchemas = (event, propertyName) => findProperties({
|
|
559
|
+
node: event,
|
|
560
|
+
propertyName
|
|
561
|
+
}).map(({ schema }) => schema);
|
|
562
|
+
const textEvents = events.filter((event) => {
|
|
563
|
+
const dataSchemas = propertySchemas(event, "data");
|
|
564
|
+
return dataSchemas.length > 0 && dataSchemas.every(isText);
|
|
565
|
+
});
|
|
566
|
+
if (textEvents.length === events.length) return events.length > 0;
|
|
567
|
+
const eventNames = textEvents.map((event) => propertySchemas(event, "event").flatMap((schema) => getLiterals(_kubb_ast.ref.getSchema(schema))));
|
|
568
|
+
if (!eventNames.length || eventNames.some((values) => !values.length)) return false;
|
|
569
|
+
return [...new Set(eventNames.flat().map(String))];
|
|
570
|
+
}
|
|
571
|
+
/** How an operation streams its success responses, or `null` when none offers a stream. */
|
|
572
|
+
function getStream(node) {
|
|
573
|
+
const entries = findPrimary(node)?.content ?? [];
|
|
574
|
+
const entry = entries.length === 1 ? entries[0] : void 0;
|
|
575
|
+
const kind = entry ? getKind(entry) : null;
|
|
576
|
+
const shape = kind === "eventStream" ? entry?.stream?.shape ?? "data" : kind === "lineStream" ? "line" : null;
|
|
577
|
+
const hasEventStream = entries.some((item) => getKind(item) === "eventStream" && (entries.length === 1 || !!item.schema));
|
|
578
|
+
const hasVariant = filterSuccess(node).some((response) => {
|
|
579
|
+
const variants = (response.content ?? []).filter((item) => item.schema);
|
|
580
|
+
return variants.length > 1 && variants.some(isStream);
|
|
453
581
|
});
|
|
582
|
+
if (!shape && !hasEventStream && !hasVariant) return null;
|
|
583
|
+
return {
|
|
584
|
+
shape,
|
|
585
|
+
textEvents: entry ? getTextEvents(entry, shape) : false,
|
|
586
|
+
hasEventStream,
|
|
587
|
+
hasVariant
|
|
588
|
+
};
|
|
454
589
|
}
|
|
455
590
|
/**
|
|
456
591
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
@@ -474,7 +609,7 @@ function buildClientOptionType(options = {}) {
|
|
|
474
609
|
* generated call.
|
|
475
610
|
*/
|
|
476
611
|
function buildRequestConfigType(node) {
|
|
477
|
-
if (
|
|
612
|
+
if (getRequestGroups(node).hasContentTypeChoice) return buildClientOptionType({ omit: ["contentType"] });
|
|
478
613
|
const request = getContentTypeInfo(node);
|
|
479
614
|
const response = getResponseContentTypeInfo(node);
|
|
480
615
|
const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
|
|
@@ -489,38 +624,6 @@ const requestGroupOrder = [
|
|
|
489
624
|
"headers",
|
|
490
625
|
"cookies"
|
|
491
626
|
];
|
|
492
|
-
/**
|
|
493
|
-
* Which of the grouped request options an operation carries.
|
|
494
|
-
*/
|
|
495
|
-
function getRequestGroups(node) {
|
|
496
|
-
const { path, query, header, cookie } = _kubb_kit.ast.http.groupParameters(node);
|
|
497
|
-
return {
|
|
498
|
-
path: path.length > 0,
|
|
499
|
-
query: query.length > 0,
|
|
500
|
-
body: Boolean(_kubb_kit.ast.http.requestBody.getSchema(node)),
|
|
501
|
-
headers: header.length > 0,
|
|
502
|
-
cookies: cookie.length > 0
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Resolves which grouped request options an operation carries together with whether each group
|
|
507
|
-
* holds a required member. The grouped parameter stays optional only when nothing inside it is
|
|
508
|
-
* required, matching the generated `RequestConfig` type.
|
|
509
|
-
*/
|
|
510
|
-
function getRequestGroupOptionality(node) {
|
|
511
|
-
const groups = getRequestGroups(node);
|
|
512
|
-
const { path, query, header } = _kubb_kit.ast.http.groupParameters(node);
|
|
513
|
-
const hasRequiredPath = path.some((param) => param.required);
|
|
514
|
-
const hasRequiredQuery = query.some((param) => param.required);
|
|
515
|
-
const hasRequiredHeader = header.some((param) => param.required);
|
|
516
|
-
return {
|
|
517
|
-
groups,
|
|
518
|
-
hasRequiredPath,
|
|
519
|
-
hasRequiredQuery,
|
|
520
|
-
hasRequiredHeader,
|
|
521
|
-
isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true)
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
627
|
function buildOperationComments(node, options = {}) {
|
|
525
628
|
const { splitLines = false } = options;
|
|
526
629
|
const filteredComments = [
|
|
@@ -533,17 +636,11 @@ function buildOperationComments(node, options = {}) {
|
|
|
533
636
|
if (!splitLines) return filteredComments;
|
|
534
637
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
535
638
|
}
|
|
536
|
-
/**
|
|
537
|
-
* Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
|
|
538
|
-
*/
|
|
539
|
-
function hasRequestContentTypeChoice(node) {
|
|
540
|
-
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
541
|
-
}
|
|
542
639
|
function resolveErrorNames(node, resolver) {
|
|
543
|
-
return
|
|
640
|
+
return filterError(node).map((response) => resolver.response.status(node, response.statusCode));
|
|
544
641
|
}
|
|
545
642
|
function resolveSuccessNames(node, resolver) {
|
|
546
|
-
return
|
|
643
|
+
return filterSuccess(node).map((response) => resolver.response.status(node, response.statusCode));
|
|
547
644
|
}
|
|
548
645
|
function resolveStatusCodeNames(node, resolver) {
|
|
549
646
|
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
@@ -555,7 +652,7 @@ function resolveStatusCodeNames(node, resolver) {
|
|
|
555
652
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
556
653
|
const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
|
|
557
654
|
return resolver.memo(`operationTypeNames:${key}`, () => {
|
|
558
|
-
const { path, query, header, cookie } =
|
|
655
|
+
const { path, query, header, cookie } = groupParameters(node);
|
|
559
656
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
560
657
|
const exclude = new Set(options.exclude ?? []);
|
|
561
658
|
const paramNames = options.includeParams === false ? [] : [
|
|
@@ -564,7 +661,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
564
661
|
...header.map((param) => resolver.param.headers(node, param)),
|
|
565
662
|
...cookie.map((param) => resolver.param.cookies(node, param))
|
|
566
663
|
];
|
|
567
|
-
const bodyAndResponseNames = [
|
|
664
|
+
const bodyAndResponseNames = [getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
568
665
|
return (options.order === "body-response-first" ? [
|
|
569
666
|
...bodyAndResponseNames,
|
|
570
667
|
...paramNames,
|
|
@@ -916,19 +1013,19 @@ function maybeRefOrGetter(type) {
|
|
|
916
1013
|
*/
|
|
917
1014
|
function buildGroupedRequestParam(node, options) {
|
|
918
1015
|
const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
|
|
919
|
-
const
|
|
1016
|
+
const groups = getRequestGroups(node);
|
|
920
1017
|
const names = keys.filter((key) => groups[key]);
|
|
921
1018
|
if (names.length === 0) return null;
|
|
922
1019
|
const requiredByGroup = {
|
|
923
|
-
path:
|
|
924
|
-
query:
|
|
1020
|
+
path: groups.required.path,
|
|
1021
|
+
query: groups.required.query,
|
|
925
1022
|
body: groups.body,
|
|
926
|
-
headers:
|
|
1023
|
+
headers: groups.required.headers,
|
|
927
1024
|
cookies: false
|
|
928
1025
|
};
|
|
929
1026
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
930
1027
|
const optionsName = resolver.response.options(node);
|
|
931
|
-
if (withContentType &&
|
|
1028
|
+
if (withContentType && groups.hasContentTypeChoice) return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
932
1029
|
name: "variables",
|
|
933
1030
|
type: optionsName,
|
|
934
1031
|
optional: false
|
|
@@ -992,7 +1089,7 @@ function buildQueryOptionsParams(node, options) {
|
|
|
992
1089
|
*/
|
|
993
1090
|
function buildClientCall(node, options) {
|
|
994
1091
|
const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
|
|
995
|
-
const
|
|
1092
|
+
const groups = getRequestGroups(node);
|
|
996
1093
|
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
997
1094
|
const member = (name) => {
|
|
998
1095
|
const value = unwrapName ? unwrapName(name) : name;
|
|
@@ -1001,7 +1098,7 @@ function buildClientCall(node, options) {
|
|
|
1001
1098
|
};
|
|
1002
1099
|
return `${clientName}({ ${[
|
|
1003
1100
|
"...config",
|
|
1004
|
-
...withContentType &&
|
|
1101
|
+
...withContentType && groups.hasContentTypeChoice ? ["...variables"] : names.map(member),
|
|
1005
1102
|
signal ? "signal: config.signal ?? signal" : null,
|
|
1006
1103
|
"throwOnError: true"
|
|
1007
1104
|
].filter((part) => part !== null).join(", ")} })`;
|
|
@@ -1045,7 +1142,7 @@ function buildResponseTypes(node, resolver, options = {}) {
|
|
|
1045
1142
|
return resolver.memo(`responseTypes:${returnType}:${typedHeaders}:${node.method}\0${node.path}`, () => {
|
|
1046
1143
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1047
1144
|
const bodyName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1048
|
-
const responseName =
|
|
1145
|
+
const responseName = getStream(node)?.hasVariant ? `${bodyName} | ReadableStream<Uint8Array>` : bodyName;
|
|
1049
1146
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1050
1147
|
return {
|
|
1051
1148
|
TData: returnType === "data" ? responseName : buildResultType(node, resolver, typedHeaders),
|
|
@@ -1067,7 +1164,7 @@ function resolveFallbackPageParamType(initialPageParam) {
|
|
|
1067
1164
|
* so callers can reuse it when rewriting the paginated request.
|
|
1068
1165
|
*/
|
|
1069
1166
|
function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
|
|
1070
|
-
const firstQueryParam =
|
|
1167
|
+
const firstQueryParam = groupParameters(node).query[0];
|
|
1071
1168
|
const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
|
|
1072
1169
|
const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
|
|
1073
1170
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
@@ -1118,7 +1215,7 @@ function resolveMutationConfig(mutation, options) {
|
|
|
1118
1215
|
* directly, so they do not generate query or mutation hooks.
|
|
1119
1216
|
*/
|
|
1120
1217
|
function classifyOperation(node, { query, mutation }) {
|
|
1121
|
-
if (
|
|
1218
|
+
if (getStream(node)?.shape) return {
|
|
1122
1219
|
isQuery: false,
|
|
1123
1220
|
isMutation: false
|
|
1124
1221
|
};
|
|
@@ -1170,7 +1267,7 @@ function resolveInfiniteConfig(infinite) {
|
|
|
1170
1267
|
*/
|
|
1171
1268
|
function matchesInfinite(node, infinite) {
|
|
1172
1269
|
if (!infinite.queryParam) return false;
|
|
1173
|
-
return
|
|
1270
|
+
return groupParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
|
|
1174
1271
|
}
|
|
1175
1272
|
/**
|
|
1176
1273
|
* Warning for an infinite hook that falls back to the built-in page params on a response that
|
|
@@ -1178,8 +1275,8 @@ function matchesInfinite(node, infinite) {
|
|
|
1178
1275
|
*/
|
|
1179
1276
|
function getDefaultPageParamsWarning(node, infinite) {
|
|
1180
1277
|
if (!(infinite.getNextPageParam == null && infinite.getPreviousPageParam == null && infinite.nextParam == null && infinite.previousParam == null && !infinite.cursorParam)) return null;
|
|
1181
|
-
const content =
|
|
1182
|
-
let resolved = (content?.find((item) =>
|
|
1278
|
+
const content = findPrimary(node)?.content;
|
|
1279
|
+
let resolved = (content?.find((item) => isJson(item)) ?? content?.[0])?.schema;
|
|
1183
1280
|
while (resolved?.type === "ref" || resolved?.type === "intersection" && resolved.members?.length === 1) resolved = resolved.type === "ref" ? resolved.schema : resolved.members?.[0];
|
|
1184
1281
|
if (!resolved || resolved.type === "array") return null;
|
|
1185
1282
|
return `${node.operationId}: the default infinite page params expect an array response and never end for this one. Set \`infinite.getNextPageParam\` (or \`nextParam\`) to read the next page from the response.`;
|
|
@@ -1234,7 +1331,7 @@ function resolveMutationRequestType(node, resolver) {
|
|
|
1234
1331
|
if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
|
|
1235
1332
|
const optionsName = resolver.response.options(node);
|
|
1236
1333
|
const response = getResponseContentTypeInfo(node);
|
|
1237
|
-
if (!
|
|
1334
|
+
if (!getRequestGroups(node).hasContentTypeChoice || !response.isMultipleContentTypes) return optionsName;
|
|
1238
1335
|
return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
|
|
1239
1336
|
}
|
|
1240
1337
|
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
@@ -1295,26 +1392,20 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1295
1392
|
getNextPageParamExpr,
|
|
1296
1393
|
getPreviousPageParamExpr
|
|
1297
1394
|
].filter(Boolean);
|
|
1298
|
-
|
|
1299
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1395
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1300
1396
|
name,
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
children:
|
|
1304
|
-
name,
|
|
1305
|
-
export: true,
|
|
1306
|
-
params: paramsSignature,
|
|
1307
|
-
children: `
|
|
1397
|
+
export: true,
|
|
1398
|
+
params: paramsSignature,
|
|
1399
|
+
children: `
|
|
1308
1400
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1309
1401
|
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
|
|
1310
1402
|
queryKey,
|
|
1311
|
-
queryFn: async (${
|
|
1403
|
+
queryFn: async (${pageParam ? "{ signal, pageParam }" : "{ signal }"}) => {
|
|
1312
1404
|
${queryFnBody}
|
|
1313
1405
|
},
|
|
1314
1406
|
${queryOptionsArr.join(",\n ")}
|
|
1315
1407
|
})
|
|
1316
1408
|
`
|
|
1317
|
-
})
|
|
1318
1409
|
});
|
|
1319
1410
|
}
|
|
1320
1411
|
// ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
@@ -1341,27 +1432,16 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1341
1432
|
casing: "camelcase",
|
|
1342
1433
|
variant: "mutation"
|
|
1343
1434
|
});
|
|
1344
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.
|
|
1435
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
1345
1436
|
name,
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
singleLine: true,
|
|
1353
|
-
children: `[${keys.join(", ")}] as const`
|
|
1354
|
-
})
|
|
1355
|
-
}), typeName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1437
|
+
export: true,
|
|
1438
|
+
params: paramsSignature,
|
|
1439
|
+
singleLine: true,
|
|
1440
|
+
children: `[${keys.join(", ")}] as const`
|
|
1441
|
+
}), typeName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1442
|
+
export: true,
|
|
1356
1443
|
name: typeName,
|
|
1357
|
-
|
|
1358
|
-
isIndexable: true,
|
|
1359
|
-
isTypeOnly: true,
|
|
1360
|
-
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1361
|
-
export: true,
|
|
1362
|
-
name: typeName,
|
|
1363
|
-
children: `ReturnType<typeof ${name}>`
|
|
1364
|
-
})
|
|
1444
|
+
children: `ReturnType<typeof ${name}>`
|
|
1365
1445
|
})] });
|
|
1366
1446
|
}
|
|
1367
1447
|
// ../../internals/tanstack-query/src/resolver.ts
|
|
@@ -1451,14 +1531,14 @@ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1451
1531
|
*/
|
|
1452
1532
|
const queryKeyTransformer = ({ node, variant }) => {
|
|
1453
1533
|
if (!node.path) return [];
|
|
1454
|
-
const { path, query } =
|
|
1534
|
+
const { path, query } = groupParameters(node);
|
|
1455
1535
|
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
1456
1536
|
const urlFields = [`url: '${_kubb_kit.Url.toPath(node.path)}'`];
|
|
1457
1537
|
if (path.length > 0) urlFields.push("params: path");
|
|
1458
1538
|
if (isInfinite) urlFields.push("infinite: true");
|
|
1459
1539
|
const result = [`{ ${urlFields.join(", ")} }`];
|
|
1460
1540
|
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
1461
|
-
if (
|
|
1541
|
+
if (getSchema(node)) result.push("...(body !== undefined ? [body] : [])");
|
|
1462
1542
|
return result;
|
|
1463
1543
|
};
|
|
1464
1544
|
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
|
|
@@ -1472,27 +1552,16 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1472
1552
|
casing: "camelcase",
|
|
1473
1553
|
variant
|
|
1474
1554
|
});
|
|
1475
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.
|
|
1555
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
1476
1556
|
name,
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
params: paramsSignature,
|
|
1483
|
-
singleLine: true,
|
|
1484
|
-
children: `[${keys.join(", ")}] as const`
|
|
1485
|
-
})
|
|
1486
|
-
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1557
|
+
export: true,
|
|
1558
|
+
params: paramsSignature,
|
|
1559
|
+
singleLine: true,
|
|
1560
|
+
children: `[${keys.join(", ")}] as const`
|
|
1561
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1487
1562
|
name: typeName,
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
isTypeOnly: true,
|
|
1491
|
-
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1492
|
-
name: typeName,
|
|
1493
|
-
export: exportType,
|
|
1494
|
-
children: `ReturnType<typeof ${name}>`
|
|
1495
|
-
})
|
|
1563
|
+
export: exportType,
|
|
1564
|
+
children: `ReturnType<typeof ${name}>`
|
|
1496
1565
|
})] });
|
|
1497
1566
|
}
|
|
1498
1567
|
// src/components/QueryOptions.tsx
|
|
@@ -1524,15 +1593,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
|
|
|
1524
1593
|
clientReturnType,
|
|
1525
1594
|
returnType
|
|
1526
1595
|
});
|
|
1527
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.
|
|
1596
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1528
1597
|
name,
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
children:
|
|
1532
|
-
name,
|
|
1533
|
-
export: true,
|
|
1534
|
-
params: paramsSignature,
|
|
1535
|
-
children: `
|
|
1598
|
+
export: true,
|
|
1599
|
+
params: paramsSignature,
|
|
1600
|
+
children: `
|
|
1536
1601
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1537
1602
|
return queryOptions<${TData}, ${TError}, ${TData}>({
|
|
1538
1603
|
queryKey,
|
|
@@ -1541,7 +1606,6 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
|
|
|
1541
1606
|
},
|
|
1542
1607
|
})
|
|
1543
1608
|
`
|
|
1544
|
-
})
|
|
1545
1609
|
});
|
|
1546
1610
|
}
|
|
1547
1611
|
// src/components/Query.tsx
|
|
@@ -1602,17 +1666,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1602
1666
|
}`
|
|
1603
1667
|
});
|
|
1604
1668
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1605
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.
|
|
1669
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1606
1670
|
name,
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
generics: generics.join(", "),
|
|
1613
|
-
params: paramsSignature,
|
|
1614
|
-
JSDoc: { comments: buildOperationComments(node) },
|
|
1615
|
-
children: `
|
|
1671
|
+
export: true,
|
|
1672
|
+
generics: generics.join(", "),
|
|
1673
|
+
params: paramsSignature,
|
|
1674
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1675
|
+
children: `
|
|
1616
1676
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1617
1677
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
1618
1678
|
const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
@@ -1627,7 +1687,6 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1627
1687
|
|
|
1628
1688
|
return queryResult
|
|
1629
1689
|
`
|
|
1630
|
-
})
|
|
1631
1690
|
});
|
|
1632
1691
|
}
|
|
1633
1692
|
// src/generators/infiniteQueryGenerator.tsx
|
|
@@ -1642,7 +1701,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1642
1701
|
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1643
1702
|
match(node, ctx) {
|
|
1644
1703
|
const operationNode = node;
|
|
1645
|
-
if (!
|
|
1704
|
+
if (!isOperation(operationNode)) return false;
|
|
1646
1705
|
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1647
1706
|
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1648
1707
|
query,
|
|
@@ -1653,7 +1712,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1653
1712
|
return matchesInfinite(operationNode, infiniteOptions);
|
|
1654
1713
|
},
|
|
1655
1714
|
operation(node, ctx) {
|
|
1656
|
-
if (!
|
|
1715
|
+
if (!isOperation(node)) return null;
|
|
1657
1716
|
const { resolver, root } = ctx;
|
|
1658
1717
|
const { output, query, infinite, client, group } = ctx.options;
|
|
1659
1718
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
@@ -1824,17 +1883,13 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1824
1883
|
typedHeaders
|
|
1825
1884
|
});
|
|
1826
1885
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1827
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.
|
|
1886
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1828
1887
|
name,
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
params: paramsSignature,
|
|
1835
|
-
JSDoc: { comments: buildOperationComments(node) },
|
|
1836
|
-
generics: ["TContext"],
|
|
1837
|
-
children: `
|
|
1888
|
+
export: true,
|
|
1889
|
+
params: paramsSignature,
|
|
1890
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1891
|
+
generics: ["TContext"],
|
|
1892
|
+
children: `
|
|
1838
1893
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
1839
1894
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1840
1895
|
const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
|
|
@@ -1847,7 +1902,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1847
1902
|
...mutationOptions
|
|
1848
1903
|
}, queryClient)
|
|
1849
1904
|
`
|
|
1850
|
-
})
|
|
1851
1905
|
});
|
|
1852
1906
|
}
|
|
1853
1907
|
// src/generators/mutationGenerator.tsx
|
|
@@ -1860,7 +1914,7 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1860
1914
|
name: "vue-query-mutation",
|
|
1861
1915
|
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1862
1916
|
operation(node, ctx) {
|
|
1863
|
-
if (!
|
|
1917
|
+
if (!isOperation(node)) return null;
|
|
1864
1918
|
const { resolver, root } = ctx;
|
|
1865
1919
|
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1866
1920
|
const { isMutation } = classifyOperation(node, {
|
|
@@ -1886,7 +1940,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1886
1940
|
contractOp,
|
|
1887
1941
|
returnType: ctx.options.returnType
|
|
1888
1942
|
});
|
|
1889
|
-
const
|
|
1943
|
+
const groups = getRequestGroups(node);
|
|
1944
|
+
const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
|
|
1890
1945
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1891
1946
|
hook,
|
|
1892
1947
|
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [hasRequestGroups && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1935,7 +1990,7 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1935
1990
|
name: "vue-query",
|
|
1936
1991
|
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1937
1992
|
operation(node, ctx) {
|
|
1938
|
-
if (!
|
|
1993
|
+
if (!isOperation(node)) return null;
|
|
1939
1994
|
const { resolver, root } = ctx;
|
|
1940
1995
|
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1941
1996
|
const { isQuery, isMutation } = classifyOperation(node, {
|