@kubb/plugin-vue-query 5.13.0 → 5.13.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 +318 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +320 -267
- 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,159 @@ var compatibility = {
|
|
|
36
36
|
"node": ">=22.22"
|
|
37
37
|
};
|
|
38
38
|
// package.json
|
|
39
|
-
var version = "5.13.
|
|
39
|
+
var version = "5.13.1";
|
|
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
|
+
/** Computes once per key; generators visit the same node many times. */
|
|
86
|
+
function cached(store, key, compute) {
|
|
87
|
+
if (!store.has(key)) store.set(key, compute());
|
|
88
|
+
return store.get(key);
|
|
89
|
+
}
|
|
90
|
+
const parametersByNode = /* @__PURE__ */ new WeakMap();
|
|
91
|
+
/** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
|
|
92
|
+
function groupParameters(node) {
|
|
93
|
+
return cached(parametersByNode, node, () => {
|
|
94
|
+
const group = (...locations) => {
|
|
95
|
+
const seen = /* @__PURE__ */ new Set();
|
|
96
|
+
return locations.flatMap((location) => node.parameters.filter((param) => {
|
|
97
|
+
if (param.in !== location || seen.has(param.name)) return false;
|
|
98
|
+
seen.add(param.name);
|
|
99
|
+
return true;
|
|
100
|
+
}));
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
path: group("path"),
|
|
104
|
+
query: group("query", "querystring"),
|
|
105
|
+
header: group("header"),
|
|
106
|
+
cookie: group("cookie")
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
111
|
+
/** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
|
|
112
|
+
function getRequestGroups(node) {
|
|
113
|
+
return cached(requestGroupsByNode, node, () => {
|
|
114
|
+
const { path, query, header, cookie } = groupParameters(node);
|
|
115
|
+
const content = node.requestBody?.content ?? [];
|
|
116
|
+
const body = Boolean(content[0]?.schema);
|
|
117
|
+
const required = {
|
|
118
|
+
path: path.some((param) => param.required),
|
|
119
|
+
query: query.some((param) => param.required),
|
|
120
|
+
headers: header.some((param) => param.required),
|
|
121
|
+
body: body && node.requestBody?.required === true
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
path: path.length > 0,
|
|
125
|
+
query: query.length > 0,
|
|
126
|
+
body,
|
|
127
|
+
headers: header.length > 0,
|
|
128
|
+
cookies: cookie.length > 0,
|
|
129
|
+
required,
|
|
130
|
+
isOptional: !required.path && !required.query && !required.headers && !required.body,
|
|
131
|
+
contentTypes: content.map((entry) => entry.contentType),
|
|
132
|
+
hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// ../../internals/ast/src/imports.ts
|
|
137
|
+
/**
|
|
138
|
+
* Returns the names of `imp`, each marked as a type, for an import that only types use.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```tsx
|
|
142
|
+
* <File.Import names={ast.imports.asType(imp)} path={imp.path} root={file.path} />
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
function asType(imp) {
|
|
146
|
+
return _kubb_ast.file.getNames(imp).map((item) => ({
|
|
147
|
+
...item,
|
|
148
|
+
space: "type"
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
// ../../internals/ast/src/mediaType.ts
|
|
152
|
+
const streamMediaTypes = /* @__PURE__ */ new Set([
|
|
153
|
+
"application/jsonl",
|
|
154
|
+
"application/x-ndjson",
|
|
155
|
+
"application/json-seq",
|
|
156
|
+
"text/event-stream"
|
|
157
|
+
]);
|
|
158
|
+
const getBase = _kubb_ast.ast.mediaType.getBase;
|
|
159
|
+
const isJson = _kubb_ast.ast.mediaType.isJson;
|
|
160
|
+
/** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
|
|
161
|
+
function isStream(mediaType) {
|
|
162
|
+
const baseType = getBase(mediaType);
|
|
163
|
+
return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
|
|
164
|
+
}
|
|
165
|
+
const formKinds = {
|
|
166
|
+
"multipart/form-data": "form",
|
|
167
|
+
"application/x-www-form-urlencoded": "urlencoded"
|
|
168
|
+
};
|
|
169
|
+
/** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
|
|
170
|
+
function getKind(entry) {
|
|
171
|
+
const content = typeof entry === "string" ? { contentType: entry } : entry;
|
|
172
|
+
const baseType = getBase(content);
|
|
173
|
+
if (!baseType) return null;
|
|
174
|
+
if (baseType === "text/event-stream") return "eventStream";
|
|
175
|
+
if (content.stream && isStream(content)) return "lineStream";
|
|
176
|
+
if (isJson(baseType)) return "json";
|
|
177
|
+
if (formKinds[baseType]) return formKinds[baseType];
|
|
178
|
+
if (content.schema?.type === "blob") return "binary";
|
|
179
|
+
if (baseType.startsWith("text/")) return "text";
|
|
180
|
+
if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
_kubb_ast.ast.schema.applyOptionality;
|
|
184
|
+
_kubb_ast.ast.schema.types;
|
|
185
|
+
const narrow = _kubb_ast.ast.schema.narrow;
|
|
186
|
+
_kubb_ast.ast.schema.find;
|
|
187
|
+
_kubb_ast.ast.schema.getEmbeddedJson;
|
|
188
|
+
const is = _kubb_ast.ast.schema.is;
|
|
189
|
+
const getLiterals = _kubb_ast.ast.schema.getLiterals;
|
|
190
|
+
_kubb_ast.ast.schema.inferDiscriminator;
|
|
191
|
+
const findProperties = _kubb_ast.ast.schema.findProperties;
|
|
40
192
|
// ../../internals/client/src/resolveClient.ts
|
|
41
193
|
/**
|
|
42
194
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -198,7 +350,7 @@ function resolveClientOperation({ node, pluginName }) {
|
|
|
198
350
|
}),
|
|
199
351
|
clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
|
|
200
352
|
returnType: operationOptions.returnType ?? "full",
|
|
201
|
-
typedHeaders: importPath === void 0
|
|
353
|
+
typedHeaders: importPath === void 0 || pluginName !== "plugin-client"
|
|
202
354
|
};
|
|
203
355
|
});
|
|
204
356
|
}
|
|
@@ -276,143 +428,6 @@ function resolveOperationTypes() {
|
|
|
276
428
|
};
|
|
277
429
|
});
|
|
278
430
|
}
|
|
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
431
|
// ../../internals/utils/src/reserved.ts
|
|
417
432
|
/**
|
|
418
433
|
* JavaScript and Java reserved words.
|
|
@@ -885,25 +900,30 @@ function HookFile({ hook, imports, children }) {
|
|
|
885
900
|
...file,
|
|
886
901
|
children: [
|
|
887
902
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
888
|
-
|
|
903
|
+
names: [{
|
|
904
|
+
name: contractOp.name,
|
|
905
|
+
space: "value"
|
|
906
|
+
}],
|
|
889
907
|
root: file.path,
|
|
890
908
|
path: contractOp.path
|
|
891
909
|
}),
|
|
892
910
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
893
|
-
|
|
911
|
+
names: [
|
|
894
912
|
"RequestConfig",
|
|
895
913
|
"ResponseErrorConfig",
|
|
896
914
|
resultTypeName
|
|
897
|
-
]
|
|
915
|
+
].map((name) => ({
|
|
916
|
+
name,
|
|
917
|
+
space: "type"
|
|
918
|
+
})),
|
|
898
919
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
899
|
-
path: contractOp.clientPath
|
|
900
|
-
isTypeOnly: true
|
|
920
|
+
path: contractOp.clientPath
|
|
901
921
|
}),
|
|
902
922
|
imports,
|
|
903
923
|
typeImports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
904
|
-
|
|
924
|
+
names: asType(imp),
|
|
905
925
|
root: file.path,
|
|
906
|
-
|
|
926
|
+
path: imp.path
|
|
907
927
|
}, imp.path)),
|
|
908
928
|
children
|
|
909
929
|
]
|
|
@@ -1538,29 +1558,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1538
1558
|
`
|
|
1539
1559
|
});
|
|
1540
1560
|
}
|
|
1541
|
-
// src/
|
|
1561
|
+
// src/templates/infiniteQuery.tsx
|
|
1562
|
+
function matchesInfiniteQuery(node, ctx) {
|
|
1563
|
+
if (!isOperation(node)) return false;
|
|
1564
|
+
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1565
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1566
|
+
query,
|
|
1567
|
+
mutation
|
|
1568
|
+
});
|
|
1569
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1570
|
+
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1571
|
+
return matchesInfinite(node, infiniteOptions);
|
|
1572
|
+
}
|
|
1542
1573
|
/**
|
|
1543
|
-
* Built-in
|
|
1574
|
+
* Built-in template for `useInfiniteQuery` composables. Enabled when
|
|
1544
1575
|
* `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1545
1576
|
* `useFooInfiniteQuery` composable per query operation, wiring the
|
|
1546
1577
|
* configured cursor path into TanStack Query's cursor-based pagination.
|
|
1547
1578
|
*/
|
|
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) {
|
|
1579
|
+
const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
|
|
1580
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1581
|
+
render(node, ctx) {
|
|
1582
|
+
if (!matchesInfiniteQuery(node, ctx)) return null;
|
|
1564
1583
|
if (!isOperation(node)) return null;
|
|
1565
1584
|
const { query, infinite, client } = ctx.options;
|
|
1566
1585
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
@@ -1591,14 +1610,16 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1591
1610
|
const { tsResolver } = hook;
|
|
1592
1611
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1593
1612
|
hook,
|
|
1594
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1595
|
-
|
|
1613
|
+
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, {
|
|
1614
|
+
names: [{
|
|
1615
|
+
name: "toValue",
|
|
1616
|
+
space: "value"
|
|
1617
|
+
}, {
|
|
1618
|
+
name: "MaybeRefOrGetter",
|
|
1619
|
+
space: "type"
|
|
1620
|
+
}],
|
|
1596
1621
|
path: "vue"
|
|
1597
|
-
})
|
|
1598
|
-
name: ["MaybeRefOrGetter"],
|
|
1599
|
-
path: "vue",
|
|
1600
|
-
isTypeOnly: true
|
|
1601
|
-
})] }),
|
|
1622
|
+
}) }),
|
|
1602
1623
|
children: [
|
|
1603
1624
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1604
1625
|
name: queryKeyName,
|
|
@@ -1611,12 +1632,13 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1611
1632
|
exportType: true
|
|
1612
1633
|
}),
|
|
1613
1634
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1635
|
+
names: [{
|
|
1636
|
+
name: "infiniteQueryOptions",
|
|
1637
|
+
space: "value"
|
|
1638
|
+
}, {
|
|
1639
|
+
name: "InfiniteData",
|
|
1640
|
+
space: "type"
|
|
1641
|
+
}],
|
|
1620
1642
|
path: importPath
|
|
1621
1643
|
}),
|
|
1622
1644
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
|
|
@@ -1641,18 +1663,29 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1641
1663
|
unwrapName: (name) => `toValue(${name})`
|
|
1642
1664
|
}),
|
|
1643
1665
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1666
|
+
names: [
|
|
1667
|
+
{
|
|
1668
|
+
name: "useInfiniteQuery",
|
|
1669
|
+
space: "value"
|
|
1670
|
+
},
|
|
1671
|
+
{
|
|
1672
|
+
name: "QueryKey",
|
|
1673
|
+
space: "type"
|
|
1674
|
+
},
|
|
1675
|
+
{
|
|
1676
|
+
name: "QueryClient",
|
|
1677
|
+
space: "type"
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
name: "UseInfiniteQueryOptions",
|
|
1681
|
+
space: "type"
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
name: "UseInfiniteQueryReturnType",
|
|
1685
|
+
space: "type"
|
|
1686
|
+
}
|
|
1653
1687
|
],
|
|
1654
|
-
path: importPath
|
|
1655
|
-
isTypeOnly: true
|
|
1688
|
+
path: importPath
|
|
1656
1689
|
}),
|
|
1657
1690
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
|
|
1658
1691
|
name: queryName,
|
|
@@ -1747,16 +1780,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1747
1780
|
`
|
|
1748
1781
|
});
|
|
1749
1782
|
}
|
|
1750
|
-
// src/
|
|
1783
|
+
// src/templates/mutation.tsx
|
|
1751
1784
|
/**
|
|
1752
|
-
* Built-in
|
|
1785
|
+
* Built-in template for `useMutation` composables. Emits one
|
|
1753
1786
|
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
1754
1787
|
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
1755
1788
|
*/
|
|
1756
|
-
const
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
operation(node, ctx) {
|
|
1789
|
+
const mutationOperation = (0, _kubb_kit.defineTemplate)({
|
|
1790
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1791
|
+
render(node, ctx) {
|
|
1760
1792
|
if (!isOperation(node)) return null;
|
|
1761
1793
|
const { query, mutation, client, hooks } = ctx.options;
|
|
1762
1794
|
const { isMutation } = classifyOperation(node, {
|
|
@@ -1781,52 +1813,58 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1781
1813
|
const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
|
|
1782
1814
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1783
1815
|
hook,
|
|
1784
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1785
|
-
|
|
1816
|
+
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, {
|
|
1817
|
+
names: [...hasRequestGroups ? [{
|
|
1818
|
+
name: "toValue",
|
|
1819
|
+
space: "value"
|
|
1820
|
+
}] : [], {
|
|
1821
|
+
name: "MaybeRefOrGetter",
|
|
1822
|
+
space: "type"
|
|
1823
|
+
}],
|
|
1786
1824
|
path: "vue"
|
|
1787
|
-
})
|
|
1788
|
-
name: ["MaybeRefOrGetter"],
|
|
1789
|
-
path: "vue",
|
|
1790
|
-
isTypeOnly: true
|
|
1791
|
-
})] }),
|
|
1825
|
+
}) }),
|
|
1792
1826
|
children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1793
1827
|
name: mutationKeyName,
|
|
1794
1828
|
node,
|
|
1795
1829
|
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
|
-
|
|
1830
|
+
}), 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, {
|
|
1831
|
+
names: [
|
|
1832
|
+
{
|
|
1833
|
+
name: "useMutation",
|
|
1834
|
+
space: "value"
|
|
1835
|
+
},
|
|
1836
|
+
{
|
|
1837
|
+
name: "MutationObserverOptions",
|
|
1838
|
+
space: "type"
|
|
1839
|
+
},
|
|
1840
|
+
{
|
|
1841
|
+
name: "QueryClient",
|
|
1842
|
+
space: "type"
|
|
1843
|
+
}
|
|
1844
|
+
],
|
|
1845
|
+
path: importPath
|
|
1846
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1847
|
+
name: mutationHookName,
|
|
1848
|
+
clientName: contractOp.name,
|
|
1849
|
+
node,
|
|
1850
|
+
tsResolver: hook.tsResolver,
|
|
1851
|
+
mutationKeyName,
|
|
1852
|
+
clientReturnType: contractOp.returnType,
|
|
1853
|
+
returnType: hook.returnType,
|
|
1854
|
+
typedHeaders: hook.contractOp.typedHeaders
|
|
1855
|
+
})] })]
|
|
1817
1856
|
});
|
|
1818
1857
|
}
|
|
1819
1858
|
});
|
|
1820
|
-
// src/
|
|
1859
|
+
// src/templates/query.tsx
|
|
1821
1860
|
/**
|
|
1822
|
-
* Built-in
|
|
1861
|
+
* Built-in template for `useQuery` composables. Emits one `useFooQuery`
|
|
1823
1862
|
* composable per GET and QUERY operation (configurable via `query.methods`) plus the
|
|
1824
1863
|
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
1825
1864
|
*/
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
operation(node, ctx) {
|
|
1865
|
+
const queryOperation = (0, _kubb_kit.defineTemplate)({
|
|
1866
|
+
kind: _kubb_ast.node.kinds.operation,
|
|
1867
|
+
render(node, ctx) {
|
|
1830
1868
|
if (!isOperation(node)) return null;
|
|
1831
1869
|
const { query, mutation, client, hooks } = ctx.options;
|
|
1832
1870
|
const { isQuery, isMutation } = classifyOperation(node, {
|
|
@@ -1852,14 +1890,16 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1852
1890
|
const { tsResolver } = hook;
|
|
1853
1891
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1854
1892
|
hook,
|
|
1855
|
-
imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.
|
|
1856
|
-
|
|
1893
|
+
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, {
|
|
1894
|
+
names: [{
|
|
1895
|
+
name: "toValue",
|
|
1896
|
+
space: "value"
|
|
1897
|
+
}, {
|
|
1898
|
+
name: "MaybeRefOrGetter",
|
|
1899
|
+
space: "type"
|
|
1900
|
+
}],
|
|
1857
1901
|
path: "vue"
|
|
1858
|
-
})
|
|
1859
|
-
name: ["MaybeRefOrGetter"],
|
|
1860
|
-
path: "vue",
|
|
1861
|
-
isTypeOnly: true
|
|
1862
|
-
})] }),
|
|
1902
|
+
}) }),
|
|
1863
1903
|
children: [
|
|
1864
1904
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1865
1905
|
name: queryKeyName,
|
|
@@ -1872,7 +1912,10 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1872
1912
|
exportType: true
|
|
1873
1913
|
}),
|
|
1874
1914
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1875
|
-
|
|
1915
|
+
names: [{
|
|
1916
|
+
name: "queryOptions",
|
|
1917
|
+
space: "value"
|
|
1918
|
+
}],
|
|
1876
1919
|
path: importPath
|
|
1877
1920
|
}),
|
|
1878
1921
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
@@ -1885,32 +1928,40 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1885
1928
|
returnType: hook.returnType,
|
|
1886
1929
|
typedHeaders: hook.contractOp.typedHeaders
|
|
1887
1930
|
}),
|
|
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
|
-
|
|
1931
|
+
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, {
|
|
1932
|
+
names: [
|
|
1933
|
+
{
|
|
1934
|
+
name: "useQuery",
|
|
1935
|
+
space: "value"
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
name: "QueryKey",
|
|
1939
|
+
space: "type"
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
name: "QueryClient",
|
|
1943
|
+
space: "type"
|
|
1944
|
+
},
|
|
1945
|
+
{
|
|
1946
|
+
name: "UseQueryOptions",
|
|
1947
|
+
space: "type"
|
|
1948
|
+
},
|
|
1949
|
+
{
|
|
1950
|
+
name: "UseQueryReturnType",
|
|
1951
|
+
space: "type"
|
|
1952
|
+
}
|
|
1953
|
+
],
|
|
1954
|
+
path: importPath
|
|
1955
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
|
|
1956
|
+
name: queryName,
|
|
1957
|
+
queryOptionsName,
|
|
1958
|
+
queryKeyName,
|
|
1959
|
+
queryKeyTypeName,
|
|
1960
|
+
node,
|
|
1961
|
+
tsResolver,
|
|
1962
|
+
returnType: hook.returnType,
|
|
1963
|
+
typedHeaders: hook.contractOp.typedHeaders
|
|
1964
|
+
})] })
|
|
1914
1965
|
]
|
|
1915
1966
|
});
|
|
1916
1967
|
}
|
|
@@ -1986,8 +2037,10 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
|
|
|
1986
2037
|
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
|
|
1987
2038
|
const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
|
|
1988
2039
|
(0, _kubb_kit.setResolver)(resolver);
|
|
1989
|
-
|
|
1990
|
-
(0, _kubb_kit.
|
|
2040
|
+
(0, _kubb_kit.addMacro)(...userMacros ?? []);
|
|
2041
|
+
(0, _kubb_kit.addTemplate)(queryOperation);
|
|
2042
|
+
(0, _kubb_kit.addTemplate)(infiniteQueryOperation);
|
|
2043
|
+
(0, _kubb_kit.addTemplate)(mutationOperation);
|
|
1991
2044
|
return {
|
|
1992
2045
|
output,
|
|
1993
2046
|
client: resolveContractClient({
|