@kubb/plugin-vue-query 5.13.0 → 5.13.2
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 +315 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +317 -269
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -25,9 +25,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
let _kubb_kit = require("@kubb/kit");
|
|
27
27
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
28
|
+
let _kubb_ast = require("@kubb/ast");
|
|
28
29
|
let node_path = require("node:path");
|
|
29
30
|
node_path = __toESM(node_path, 1);
|
|
30
|
-
let _kubb_ast = require("@kubb/ast");
|
|
31
31
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
32
32
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
33
33
|
// kubb-extension.json
|
|
@@ -36,7 +36,154 @@ var compatibility = {
|
|
|
36
36
|
"node": ">=22.22"
|
|
37
37
|
};
|
|
38
38
|
// package.json
|
|
39
|
-
var version = "5.13.
|
|
39
|
+
var version = "5.13.2";
|
|
40
|
+
// ../../internals/ast/src/http/requestBody.ts
|
|
41
|
+
/** The schema of the first request body entry, else `undefined` when the operation takes no body. */
|
|
42
|
+
function getSchema(node) {
|
|
43
|
+
return node.requestBody?.content?.[0]?.schema;
|
|
44
|
+
}
|
|
45
|
+
// ../../internals/ast/src/http/status.ts
|
|
46
|
+
const classByRange = /* @__PURE__ */ new Map([
|
|
47
|
+
["1xx", 1],
|
|
48
|
+
["2xx", 2],
|
|
49
|
+
["3xx", 3],
|
|
50
|
+
["4xx", 4],
|
|
51
|
+
["5xx", 5]
|
|
52
|
+
]);
|
|
53
|
+
/** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
|
|
54
|
+
function statusClass(input) {
|
|
55
|
+
const statusCode = typeof input === "object" ? input.statusCode : input;
|
|
56
|
+
const rangeClass = classByRange.get(String(statusCode));
|
|
57
|
+
if (rangeClass) return rangeClass;
|
|
58
|
+
const code = Number(statusCode);
|
|
59
|
+
return Number.isNaN(code) ? null : Math.floor(code / 100);
|
|
60
|
+
}
|
|
61
|
+
function isSuccess(statusCode) {
|
|
62
|
+
return statusClass(statusCode) === 2;
|
|
63
|
+
}
|
|
64
|
+
function isError(statusCode) {
|
|
65
|
+
const code = statusClass(statusCode);
|
|
66
|
+
return code !== null && code >= 4;
|
|
67
|
+
}
|
|
68
|
+
// ../../internals/ast/src/http/responses.ts
|
|
69
|
+
/** The `4xx` and `5xx` responses, ranges included. */
|
|
70
|
+
function filterError(node) {
|
|
71
|
+
return node.responses.filter((response) => isError(response.statusCode));
|
|
72
|
+
}
|
|
73
|
+
function filterSuccess(node) {
|
|
74
|
+
return node.responses.filter((response) => isSuccess(response.statusCode));
|
|
75
|
+
}
|
|
76
|
+
/** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
|
|
77
|
+
function findPrimary(node) {
|
|
78
|
+
const responses = filterSuccess(node);
|
|
79
|
+
const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
|
|
80
|
+
const candidates = withBody.length ? withBody : responses;
|
|
81
|
+
return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
|
|
82
|
+
}
|
|
83
|
+
// ../../internals/ast/src/http/index.ts
|
|
84
|
+
const isOperation = _kubb_ast.ast.http.isOperation;
|
|
85
|
+
const parametersByNode = /* @__PURE__ */ new WeakMap();
|
|
86
|
+
/** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
|
|
87
|
+
function groupParameters(node) {
|
|
88
|
+
return (0, _kubb_kit.memo)(parametersByNode, node, () => {
|
|
89
|
+
const group = (...locations) => {
|
|
90
|
+
const seen = /* @__PURE__ */ new Set();
|
|
91
|
+
return locations.flatMap((location) => node.parameters.filter((param) => {
|
|
92
|
+
if (param.in !== location || seen.has(param.name)) return false;
|
|
93
|
+
seen.add(param.name);
|
|
94
|
+
return true;
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
path: group("path"),
|
|
99
|
+
query: group("query", "querystring"),
|
|
100
|
+
header: group("header"),
|
|
101
|
+
cookie: group("cookie")
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
106
|
+
/** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
|
|
107
|
+
function getRequestGroups(node) {
|
|
108
|
+
return (0, _kubb_kit.memo)(requestGroupsByNode, node, () => {
|
|
109
|
+
const { path, query, header, cookie } = groupParameters(node);
|
|
110
|
+
const content = node.requestBody?.content ?? [];
|
|
111
|
+
const body = Boolean(content[0]?.schema);
|
|
112
|
+
const required = {
|
|
113
|
+
path: path.some((param) => param.required),
|
|
114
|
+
query: query.some((param) => param.required),
|
|
115
|
+
headers: header.some((param) => param.required),
|
|
116
|
+
body: body && node.requestBody?.required === true
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
path: path.length > 0,
|
|
120
|
+
query: query.length > 0,
|
|
121
|
+
body,
|
|
122
|
+
headers: header.length > 0,
|
|
123
|
+
cookies: cookie.length > 0,
|
|
124
|
+
required,
|
|
125
|
+
isOptional: !required.path && !required.query && !required.headers && !required.body,
|
|
126
|
+
contentTypes: content.map((entry) => entry.contentType),
|
|
127
|
+
hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// ../../internals/ast/src/imports.ts
|
|
132
|
+
/**
|
|
133
|
+
* Returns the names of `imp`, each marked as a type, for an import that only types use.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* <File.Import names={ast.imports.asType(imp)} path={imp.path} root={file.path} />
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
function asType(imp) {
|
|
141
|
+
return _kubb_ast.file.getNames(imp).map((item) => ({
|
|
142
|
+
...item,
|
|
143
|
+
space: "type"
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
// ../../internals/ast/src/mediaType.ts
|
|
147
|
+
const streamMediaTypes = /* @__PURE__ */ new Set([
|
|
148
|
+
"application/jsonl",
|
|
149
|
+
"application/x-ndjson",
|
|
150
|
+
"application/json-seq",
|
|
151
|
+
"text/event-stream"
|
|
152
|
+
]);
|
|
153
|
+
const getBase = _kubb_ast.ast.mediaType.getBase;
|
|
154
|
+
const isJson = _kubb_ast.ast.mediaType.isJson;
|
|
155
|
+
/** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
|
|
156
|
+
function isStream(mediaType) {
|
|
157
|
+
const baseType = getBase(mediaType);
|
|
158
|
+
return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
|
|
159
|
+
}
|
|
160
|
+
const formKinds = {
|
|
161
|
+
"multipart/form-data": "form",
|
|
162
|
+
"application/x-www-form-urlencoded": "urlencoded"
|
|
163
|
+
};
|
|
164
|
+
/** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
|
|
165
|
+
function getKind(entry) {
|
|
166
|
+
const content = typeof entry === "string" ? { contentType: entry } : entry;
|
|
167
|
+
const baseType = getBase(content);
|
|
168
|
+
if (!baseType) return null;
|
|
169
|
+
if (baseType === "text/event-stream") return "eventStream";
|
|
170
|
+
if (content.stream && isStream(content)) return "lineStream";
|
|
171
|
+
if (isJson(baseType)) return "json";
|
|
172
|
+
if (formKinds[baseType]) return formKinds[baseType];
|
|
173
|
+
if (content.schema?.type === "blob") return "binary";
|
|
174
|
+
if (baseType.startsWith("text/")) return "text";
|
|
175
|
+
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
_kubb_ast.ast.schema.applyOptionality;
|
|
179
|
+
_kubb_ast.ast.schema.types;
|
|
180
|
+
const narrow = _kubb_ast.ast.schema.narrow;
|
|
181
|
+
_kubb_ast.ast.schema.find;
|
|
182
|
+
_kubb_ast.ast.schema.getEmbeddedJson;
|
|
183
|
+
const is = _kubb_ast.ast.schema.is;
|
|
184
|
+
const getLiterals = _kubb_ast.ast.schema.getLiterals;
|
|
185
|
+
_kubb_ast.ast.schema.inferDiscriminator;
|
|
186
|
+
const findProperties = _kubb_ast.ast.schema.findProperties;
|
|
40
187
|
// ../../internals/client/src/resolveClient.ts
|
|
41
188
|
/**
|
|
42
189
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -198,7 +345,7 @@ function resolveClientOperation({ node, pluginName }) {
|
|
|
198
345
|
}),
|
|
199
346
|
clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
|
|
200
347
|
returnType: operationOptions.returnType ?? "full",
|
|
201
|
-
typedHeaders: importPath === void 0
|
|
348
|
+
typedHeaders: importPath === void 0 || pluginName !== "plugin-client"
|
|
202
349
|
};
|
|
203
350
|
});
|
|
204
351
|
}
|
|
@@ -276,143 +423,6 @@ function resolveOperationTypes() {
|
|
|
276
423
|
};
|
|
277
424
|
});
|
|
278
425
|
}
|
|
279
|
-
// ../../internals/ast/src/http/requestBody.ts
|
|
280
|
-
/** The schema of the first request body entry, else `undefined` when the operation takes no body. */
|
|
281
|
-
function getSchema(node) {
|
|
282
|
-
return node.requestBody?.content?.[0]?.schema;
|
|
283
|
-
}
|
|
284
|
-
// ../../internals/ast/src/http/status.ts
|
|
285
|
-
const classByRange = /* @__PURE__ */ new Map([
|
|
286
|
-
["1xx", 1],
|
|
287
|
-
["2xx", 2],
|
|
288
|
-
["3xx", 3],
|
|
289
|
-
["4xx", 4],
|
|
290
|
-
["5xx", 5]
|
|
291
|
-
]);
|
|
292
|
-
/** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
|
|
293
|
-
function statusClass(input) {
|
|
294
|
-
const statusCode = typeof input === "object" ? input.statusCode : input;
|
|
295
|
-
const rangeClass = classByRange.get(String(statusCode));
|
|
296
|
-
if (rangeClass) return rangeClass;
|
|
297
|
-
const code = Number(statusCode);
|
|
298
|
-
return Number.isNaN(code) ? null : Math.floor(code / 100);
|
|
299
|
-
}
|
|
300
|
-
function isSuccess(statusCode) {
|
|
301
|
-
return statusClass(statusCode) === 2;
|
|
302
|
-
}
|
|
303
|
-
function isError(statusCode) {
|
|
304
|
-
const code = statusClass(statusCode);
|
|
305
|
-
return code !== null && code >= 4;
|
|
306
|
-
}
|
|
307
|
-
// ../../internals/ast/src/http/responses.ts
|
|
308
|
-
/** The `4xx` and `5xx` responses, ranges included. */
|
|
309
|
-
function filterError(node) {
|
|
310
|
-
return node.responses.filter((response) => isError(response.statusCode));
|
|
311
|
-
}
|
|
312
|
-
function filterSuccess(node) {
|
|
313
|
-
return node.responses.filter((response) => isSuccess(response.statusCode));
|
|
314
|
-
}
|
|
315
|
-
/** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
|
|
316
|
-
function findPrimary(node) {
|
|
317
|
-
const responses = filterSuccess(node);
|
|
318
|
-
const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
|
|
319
|
-
const candidates = withBody.length ? withBody : responses;
|
|
320
|
-
return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
|
|
321
|
-
}
|
|
322
|
-
// ../../internals/ast/src/http/index.ts
|
|
323
|
-
const isOperation = _kubb_ast.ast.http.isOperation;
|
|
324
|
-
/** Computes once per key; generators visit the same node many times. */
|
|
325
|
-
function cached(store, key, compute) {
|
|
326
|
-
if (!store.has(key)) store.set(key, compute());
|
|
327
|
-
return store.get(key);
|
|
328
|
-
}
|
|
329
|
-
const parametersByNode = /* @__PURE__ */ new WeakMap();
|
|
330
|
-
/** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
|
|
331
|
-
function groupParameters(node) {
|
|
332
|
-
return cached(parametersByNode, node, () => {
|
|
333
|
-
const group = (...locations) => {
|
|
334
|
-
const seen = /* @__PURE__ */ new Set();
|
|
335
|
-
return locations.flatMap((location) => node.parameters.filter((param) => {
|
|
336
|
-
if (param.in !== location || seen.has(param.name)) return false;
|
|
337
|
-
seen.add(param.name);
|
|
338
|
-
return true;
|
|
339
|
-
}));
|
|
340
|
-
};
|
|
341
|
-
return {
|
|
342
|
-
path: group("path"),
|
|
343
|
-
query: group("query", "querystring"),
|
|
344
|
-
header: group("header"),
|
|
345
|
-
cookie: group("cookie")
|
|
346
|
-
};
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
350
|
-
/** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
|
|
351
|
-
function getRequestGroups(node) {
|
|
352
|
-
return cached(requestGroupsByNode, node, () => {
|
|
353
|
-
const { path, query, header, cookie } = groupParameters(node);
|
|
354
|
-
const content = node.requestBody?.content ?? [];
|
|
355
|
-
const body = Boolean(content[0]?.schema);
|
|
356
|
-
const required = {
|
|
357
|
-
path: path.some((param) => param.required),
|
|
358
|
-
query: query.some((param) => param.required),
|
|
359
|
-
headers: header.some((param) => param.required),
|
|
360
|
-
body: body && node.requestBody?.required === true
|
|
361
|
-
};
|
|
362
|
-
return {
|
|
363
|
-
path: path.length > 0,
|
|
364
|
-
query: query.length > 0,
|
|
365
|
-
body,
|
|
366
|
-
headers: header.length > 0,
|
|
367
|
-
cookies: cookie.length > 0,
|
|
368
|
-
required,
|
|
369
|
-
isOptional: !required.path && !required.query && !required.headers && !required.body,
|
|
370
|
-
contentTypes: content.map((entry) => entry.contentType),
|
|
371
|
-
hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
// ../../internals/ast/src/mediaType.ts
|
|
376
|
-
const streamMediaTypes = /* @__PURE__ */ new Set([
|
|
377
|
-
"application/jsonl",
|
|
378
|
-
"application/x-ndjson",
|
|
379
|
-
"application/json-seq",
|
|
380
|
-
"text/event-stream"
|
|
381
|
-
]);
|
|
382
|
-
const getBase = _kubb_ast.ast.mediaType.getBase;
|
|
383
|
-
const isJson = _kubb_ast.ast.mediaType.isJson;
|
|
384
|
-
/** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
|
|
385
|
-
function isStream(mediaType) {
|
|
386
|
-
const baseType = getBase(mediaType);
|
|
387
|
-
return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
|
|
388
|
-
}
|
|
389
|
-
const formKinds = {
|
|
390
|
-
"multipart/form-data": "form",
|
|
391
|
-
"application/x-www-form-urlencoded": "urlencoded"
|
|
392
|
-
};
|
|
393
|
-
/** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
|
|
394
|
-
function getKind(entry) {
|
|
395
|
-
const content = typeof entry === "string" ? { contentType: entry } : entry;
|
|
396
|
-
const baseType = getBase(content);
|
|
397
|
-
if (!baseType) return null;
|
|
398
|
-
if (baseType === "text/event-stream") return "eventStream";
|
|
399
|
-
if (content.stream && isStream(content)) return "lineStream";
|
|
400
|
-
if (isJson(baseType)) return "json";
|
|
401
|
-
if (formKinds[baseType]) return formKinds[baseType];
|
|
402
|
-
if (content.schema?.type === "blob") return "binary";
|
|
403
|
-
if (baseType.startsWith("text/")) return "text";
|
|
404
|
-
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
_kubb_ast.ast.schema.applyOptionality;
|
|
408
|
-
_kubb_ast.ast.schema.types;
|
|
409
|
-
const narrow = _kubb_ast.ast.schema.narrow;
|
|
410
|
-
_kubb_ast.ast.schema.find;
|
|
411
|
-
_kubb_ast.ast.schema.getEmbeddedJson;
|
|
412
|
-
const is = _kubb_ast.ast.schema.is;
|
|
413
|
-
const getLiterals = _kubb_ast.ast.schema.getLiterals;
|
|
414
|
-
_kubb_ast.ast.schema.inferDiscriminator;
|
|
415
|
-
const findProperties = _kubb_ast.ast.schema.findProperties;
|
|
416
426
|
// ../../internals/utils/src/reserved.ts
|
|
417
427
|
/**
|
|
418
428
|
* JavaScript and Java reserved words.
|
|
@@ -885,25 +895,30 @@ function HookFile({ hook, imports, children }) {
|
|
|
885
895
|
...file,
|
|
886
896
|
children: [
|
|
887
897
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
888
|
-
|
|
898
|
+
names: [{
|
|
899
|
+
name: contractOp.name,
|
|
900
|
+
space: "value"
|
|
901
|
+
}],
|
|
889
902
|
root: file.path,
|
|
890
903
|
path: contractOp.path
|
|
891
904
|
}),
|
|
892
905
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
893
|
-
|
|
906
|
+
names: [
|
|
894
907
|
"RequestConfig",
|
|
895
908
|
"ResponseErrorConfig",
|
|
896
909
|
resultTypeName
|
|
897
|
-
]
|
|
910
|
+
].map((name) => ({
|
|
911
|
+
name,
|
|
912
|
+
space: "type"
|
|
913
|
+
})),
|
|
898
914
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
899
|
-
path: contractOp.clientPath
|
|
900
|
-
isTypeOnly: true
|
|
915
|
+
path: contractOp.clientPath
|
|
901
916
|
}),
|
|
902
917
|
imports,
|
|
903
918
|
typeImports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
904
|
-
|
|
919
|
+
names: asType(imp),
|
|
905
920
|
root: file.path,
|
|
906
|
-
|
|
921
|
+
path: imp.path
|
|
907
922
|
}, imp.path)),
|
|
908
923
|
children
|
|
909
924
|
]
|
|
@@ -1344,7 +1359,7 @@ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1344
1359
|
*/
|
|
1345
1360
|
const mutationKeyTransformer = ({ node }) => {
|
|
1346
1361
|
if (!node.path) return [];
|
|
1347
|
-
return [`{ url:
|
|
1362
|
+
return [`{ url: ${_kubb_kit.text.quote(_kubb_kit.Url.toPath(node.path))} }`];
|
|
1348
1363
|
};
|
|
1349
1364
|
function MutationKey({ name, node, transformer, typeName }) {
|
|
1350
1365
|
const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
|
|
@@ -1382,7 +1397,7 @@ const queryKeyTransformer = ({ node, variant }) => {
|
|
|
1382
1397
|
if (!node.path) return [];
|
|
1383
1398
|
const { path, query } = groupParameters(node);
|
|
1384
1399
|
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
1385
|
-
const urlFields = [`url:
|
|
1400
|
+
const urlFields = [`url: ${_kubb_kit.text.quote(_kubb_kit.Url.toPath(node.path))}`];
|
|
1386
1401
|
if (path.length > 0) urlFields.push("params: path");
|
|
1387
1402
|
if (isInfinite) urlFields.push("infinite: true");
|
|
1388
1403
|
const result = [`{ ${urlFields.join(", ")} }`];
|
|
@@ -1538,29 +1553,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1538
1553
|
`
|
|
1539
1554
|
});
|
|
1540
1555
|
}
|
|
1541
|
-
// src/
|
|
1556
|
+
// src/templates/infiniteQuery.tsx
|
|
1557
|
+
function matchesInfiniteQuery(node, ctx) {
|
|
1558
|
+
if (!isOperation(node)) return false;
|
|
1559
|
+
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1560
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1561
|
+
query,
|
|
1562
|
+
mutation
|
|
1563
|
+
});
|
|
1564
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1565
|
+
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1566
|
+
return matchesInfinite(node, infiniteOptions);
|
|
1567
|
+
}
|
|
1542
1568
|
/**
|
|
1543
|
-
* Built-in
|
|
1569
|
+
* Built-in template for `useInfiniteQuery` composables. Enabled when
|
|
1544
1570
|
* `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1545
1571
|
* `useFooInfiniteQuery` composable per query operation, wiring the
|
|
1546
1572
|
* configured cursor path into TanStack Query's cursor-based pagination.
|
|
1547
1573
|
*/
|
|
1548
|
-
const
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
const operationNode = node;
|
|
1553
|
-
if (!isOperation(operationNode)) return false;
|
|
1554
|
-
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1555
|
-
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1556
|
-
query,
|
|
1557
|
-
mutation
|
|
1558
|
-
});
|
|
1559
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1560
|
-
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1561
|
-
return matchesInfinite(operationNode, infiniteOptions);
|
|
1562
|
-
},
|
|
1563
|
-
operation(node, ctx) {
|
|
1574
|
+
const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
|
|
1575
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1576
|
+
render(node, ctx) {
|
|
1577
|
+
if (!matchesInfiniteQuery(node, ctx)) return null;
|
|
1564
1578
|
if (!isOperation(node)) return null;
|
|
1565
1579
|
const { query, infinite, client } = ctx.options;
|
|
1566
1580
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
@@ -1591,14 +1605,16 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1591
1605
|
const { tsResolver } = hook;
|
|
1592
1606
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1593
1607
|
hook,
|
|
1594
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1595
|
-
|
|
1608
|
+
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1609
|
+
names: [{
|
|
1610
|
+
name: "toValue",
|
|
1611
|
+
space: "value"
|
|
1612
|
+
}, {
|
|
1613
|
+
name: "MaybeRefOrGetter",
|
|
1614
|
+
space: "type"
|
|
1615
|
+
}],
|
|
1596
1616
|
path: "vue"
|
|
1597
|
-
})
|
|
1598
|
-
name: ["MaybeRefOrGetter"],
|
|
1599
|
-
path: "vue",
|
|
1600
|
-
isTypeOnly: true
|
|
1601
|
-
})] }),
|
|
1617
|
+
}) }),
|
|
1602
1618
|
children: [
|
|
1603
1619
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1604
1620
|
name: queryKeyName,
|
|
@@ -1611,12 +1627,13 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1611
1627
|
exportType: true
|
|
1612
1628
|
}),
|
|
1613
1629
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1630
|
+
names: [{
|
|
1631
|
+
name: "infiniteQueryOptions",
|
|
1632
|
+
space: "value"
|
|
1633
|
+
}, {
|
|
1634
|
+
name: "InfiniteData",
|
|
1635
|
+
space: "type"
|
|
1636
|
+
}],
|
|
1620
1637
|
path: importPath
|
|
1621
1638
|
}),
|
|
1622
1639
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
|
|
@@ -1641,18 +1658,29 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1641
1658
|
unwrapName: (name) => `toValue(${name})`
|
|
1642
1659
|
}),
|
|
1643
1660
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1661
|
+
names: [
|
|
1662
|
+
{
|
|
1663
|
+
name: "useInfiniteQuery",
|
|
1664
|
+
space: "value"
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
name: "QueryKey",
|
|
1668
|
+
space: "type"
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
name: "QueryClient",
|
|
1672
|
+
space: "type"
|
|
1673
|
+
},
|
|
1674
|
+
{
|
|
1675
|
+
name: "UseInfiniteQueryOptions",
|
|
1676
|
+
space: "type"
|
|
1677
|
+
},
|
|
1678
|
+
{
|
|
1679
|
+
name: "UseInfiniteQueryReturnType",
|
|
1680
|
+
space: "type"
|
|
1681
|
+
}
|
|
1653
1682
|
],
|
|
1654
|
-
path: importPath
|
|
1655
|
-
isTypeOnly: true
|
|
1683
|
+
path: importPath
|
|
1656
1684
|
}),
|
|
1657
1685
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
|
|
1658
1686
|
name: queryName,
|
|
@@ -1747,16 +1775,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1747
1775
|
`
|
|
1748
1776
|
});
|
|
1749
1777
|
}
|
|
1750
|
-
// src/
|
|
1778
|
+
// src/templates/mutation.tsx
|
|
1751
1779
|
/**
|
|
1752
|
-
* Built-in
|
|
1780
|
+
* Built-in template for `useMutation` composables. Emits one
|
|
1753
1781
|
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
1754
1782
|
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
1755
1783
|
*/
|
|
1756
|
-
const
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
operation(node, ctx) {
|
|
1784
|
+
const mutationOperation = (0, _kubb_kit.defineTemplate)({
|
|
1785
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1786
|
+
render(node, ctx) {
|
|
1760
1787
|
if (!isOperation(node)) return null;
|
|
1761
1788
|
const { query, mutation, client, hooks } = ctx.options;
|
|
1762
1789
|
const { isMutation } = classifyOperation(node, {
|
|
@@ -1781,52 +1808,58 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1781
1808
|
const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
|
|
1782
1809
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1783
1810
|
hook,
|
|
1784
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1785
|
-
|
|
1811
|
+
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1812
|
+
names: [...hasRequestGroups ? [{
|
|
1813
|
+
name: "toValue",
|
|
1814
|
+
space: "value"
|
|
1815
|
+
}] : [], {
|
|
1816
|
+
name: "MaybeRefOrGetter",
|
|
1817
|
+
space: "type"
|
|
1818
|
+
}],
|
|
1786
1819
|
path: "vue"
|
|
1787
|
-
})
|
|
1788
|
-
name: ["MaybeRefOrGetter"],
|
|
1789
|
-
path: "vue",
|
|
1790
|
-
isTypeOnly: true
|
|
1791
|
-
})] }),
|
|
1820
|
+
}) }),
|
|
1792
1821
|
children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1793
1822
|
name: mutationKeyName,
|
|
1794
1823
|
node,
|
|
1795
1824
|
transformer: ctx.options.mutationKey
|
|
1796
|
-
}), mutation && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1825
|
+
}), mutation && hooks && /* @__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.File.Import, {
|
|
1826
|
+
names: [
|
|
1827
|
+
{
|
|
1828
|
+
name: "useMutation",
|
|
1829
|
+
space: "value"
|
|
1830
|
+
},
|
|
1831
|
+
{
|
|
1832
|
+
name: "MutationObserverOptions",
|
|
1833
|
+
space: "type"
|
|
1834
|
+
},
|
|
1835
|
+
{
|
|
1836
|
+
name: "QueryClient",
|
|
1837
|
+
space: "type"
|
|
1838
|
+
}
|
|
1839
|
+
],
|
|
1840
|
+
path: importPath
|
|
1841
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1842
|
+
name: mutationHookName,
|
|
1843
|
+
clientName: contractOp.name,
|
|
1844
|
+
node,
|
|
1845
|
+
tsResolver: hook.tsResolver,
|
|
1846
|
+
mutationKeyName,
|
|
1847
|
+
clientReturnType: contractOp.returnType,
|
|
1848
|
+
returnType: hook.returnType,
|
|
1849
|
+
typedHeaders: hook.contractOp.typedHeaders
|
|
1850
|
+
})] })]
|
|
1817
1851
|
});
|
|
1818
1852
|
}
|
|
1819
1853
|
});
|
|
1820
|
-
// src/
|
|
1854
|
+
// src/templates/query.tsx
|
|
1821
1855
|
/**
|
|
1822
|
-
* Built-in
|
|
1856
|
+
* Built-in template for `useQuery` composables. Emits one `useFooQuery`
|
|
1823
1857
|
* composable per GET and QUERY operation (configurable via `query.methods`) plus the
|
|
1824
1858
|
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
1825
1859
|
*/
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
operation(node, ctx) {
|
|
1860
|
+
const queryOperation = (0, _kubb_kit.defineTemplate)({
|
|
1861
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1862
|
+
render(node, ctx) {
|
|
1830
1863
|
if (!isOperation(node)) return null;
|
|
1831
1864
|
const { query, mutation, client, hooks } = ctx.options;
|
|
1832
1865
|
const { isQuery, isMutation } = classifyOperation(node, {
|
|
@@ -1852,14 +1885,16 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1852
1885
|
const { tsResolver } = hook;
|
|
1853
1886
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1854
1887
|
hook,
|
|
1855
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1856
|
-
|
|
1888
|
+
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1889
|
+
names: [{
|
|
1890
|
+
name: "toValue",
|
|
1891
|
+
space: "value"
|
|
1892
|
+
}, {
|
|
1893
|
+
name: "MaybeRefOrGetter",
|
|
1894
|
+
space: "type"
|
|
1895
|
+
}],
|
|
1857
1896
|
path: "vue"
|
|
1858
|
-
})
|
|
1859
|
-
name: ["MaybeRefOrGetter"],
|
|
1860
|
-
path: "vue",
|
|
1861
|
-
isTypeOnly: true
|
|
1862
|
-
})] }),
|
|
1897
|
+
}) }),
|
|
1863
1898
|
children: [
|
|
1864
1899
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1865
1900
|
name: queryKeyName,
|
|
@@ -1872,7 +1907,10 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1872
1907
|
exportType: true
|
|
1873
1908
|
}),
|
|
1874
1909
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1875
|
-
|
|
1910
|
+
names: [{
|
|
1911
|
+
name: "queryOptions",
|
|
1912
|
+
space: "value"
|
|
1913
|
+
}],
|
|
1876
1914
|
path: importPath
|
|
1877
1915
|
}),
|
|
1878
1916
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
@@ -1885,32 +1923,40 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1885
1923
|
returnType: hook.returnType,
|
|
1886
1924
|
typedHeaders: hook.contractOp.typedHeaders
|
|
1887
1925
|
}),
|
|
1888
|
-
query && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
"QueryKey",
|
|
1896
|
-
"
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1926
|
+
query && hooks && /* @__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.File.Import, {
|
|
1927
|
+
names: [
|
|
1928
|
+
{
|
|
1929
|
+
name: "useQuery",
|
|
1930
|
+
space: "value"
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
name: "QueryKey",
|
|
1934
|
+
space: "type"
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
name: "QueryClient",
|
|
1938
|
+
space: "type"
|
|
1939
|
+
},
|
|
1940
|
+
{
|
|
1941
|
+
name: "UseQueryOptions",
|
|
1942
|
+
space: "type"
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
name: "UseQueryReturnType",
|
|
1946
|
+
space: "type"
|
|
1947
|
+
}
|
|
1948
|
+
],
|
|
1949
|
+
path: importPath
|
|
1950
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
|
|
1951
|
+
name: queryName,
|
|
1952
|
+
queryOptionsName,
|
|
1953
|
+
queryKeyName,
|
|
1954
|
+
queryKeyTypeName,
|
|
1955
|
+
node,
|
|
1956
|
+
tsResolver,
|
|
1957
|
+
returnType: hook.returnType,
|
|
1958
|
+
typedHeaders: hook.contractOp.typedHeaders
|
|
1959
|
+
})] })
|
|
1914
1960
|
]
|
|
1915
1961
|
});
|
|
1916
1962
|
}
|
|
@@ -1986,8 +2032,10 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
|
|
|
1986
2032
|
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
|
|
1987
2033
|
const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
|
|
1988
2034
|
(0, _kubb_kit.setResolver)(resolver);
|
|
1989
|
-
|
|
1990
|
-
(0, _kubb_kit.
|
|
2035
|
+
(0, _kubb_kit.addMacro)(...userMacros ?? []);
|
|
2036
|
+
(0, _kubb_kit.addTemplate)(queryOperation);
|
|
2037
|
+
(0, _kubb_kit.addTemplate)(infiniteQueryOperation);
|
|
2038
|
+
(0, _kubb_kit.addTemplate)(mutationOperation);
|
|
1991
2039
|
return {
|
|
1992
2040
|
output,
|
|
1993
2041
|
client: resolveContractClient({
|