@kubb/plugin-swr 5.0.0-alpha.9 → 5.0.0-beta.36
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/LICENSE +17 -10
- package/README.md +36 -21
- package/dist/components-BuLagnaM.js +933 -0
- package/dist/components-BuLagnaM.js.map +1 -0
- package/dist/components-CD7ZoS3B.cjs +1029 -0
- package/dist/components-CD7ZoS3B.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +46 -52
- package/dist/components.js +1 -1
- package/dist/generators-DM18y_Qk.cjs +445 -0
- package/dist/generators-DM18y_Qk.cjs.map +1 -0
- package/dist/generators-bnwHiUqJ.js +434 -0
- package/dist/generators-bnwHiUqJ.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -501
- package/dist/generators.js +1 -1
- package/dist/index.cjs +134 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +131 -114
- package/dist/index.js.map +1 -1
- package/dist/types-BoANASs2.d.ts +220 -0
- package/extension.yaml +199 -0
- package/package.json +58 -67
- package/src/components/Mutation.tsx +106 -227
- package/src/components/MutationKey.tsx +25 -1
- package/src/components/Query.tsx +75 -140
- package/src/components/QueryOptions.tsx +46 -95
- package/src/generators/mutationGenerator.tsx +113 -128
- package/src/generators/queryGenerator.tsx +125 -137
- package/src/index.ts +2 -2
- package/src/plugin.ts +117 -170
- package/src/resolvers/resolverSwr.ts +56 -0
- package/src/types.ts +115 -59
- package/src/utils.ts +10 -0
- package/dist/components-DRDGvgXG.js +0 -702
- package/dist/components-DRDGvgXG.js.map +0 -1
- package/dist/components-jd0l9XKn.cjs +0 -780
- package/dist/components-jd0l9XKn.cjs.map +0 -1
- package/dist/generators-CRSl6u2M.js +0 -399
- package/dist/generators-CRSl6u2M.js.map +0 -1
- package/dist/generators-D062obA7.cjs +0 -410
- package/dist/generators-D062obA7.cjs.map +0 -1
- package/dist/types-BIaGRPjD.d.ts +0 -210
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let _kubb_core = require("@kubb/core");
|
|
28
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
29
|
+
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
30
|
+
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
31
|
+
//#region ../../internals/utils/src/casing.ts
|
|
32
|
+
/**
|
|
33
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
34
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
35
|
+
* and capitalizes each word according to `pascal`.
|
|
36
|
+
*
|
|
37
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
38
|
+
*/
|
|
39
|
+
function toCamelOrPascal(text, pascal) {
|
|
40
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
41
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
42
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
43
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
44
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
48
|
+
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
49
|
+
* Segments are joined with `/` to form a file path.
|
|
50
|
+
*
|
|
51
|
+
* Only splits on dots followed by a letter so that version numbers
|
|
52
|
+
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
53
|
+
*/
|
|
54
|
+
function applyToFileParts(text, transformPart) {
|
|
55
|
+
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
56
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts `text` to camelCase.
|
|
60
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
64
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
65
|
+
*/
|
|
66
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
67
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
68
|
+
prefix,
|
|
69
|
+
suffix
|
|
70
|
+
} : {}));
|
|
71
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
75
|
+
/**
|
|
76
|
+
* JavaScript and Java reserved words.
|
|
77
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
78
|
+
*/
|
|
79
|
+
const reservedWords = new Set([
|
|
80
|
+
"abstract",
|
|
81
|
+
"arguments",
|
|
82
|
+
"boolean",
|
|
83
|
+
"break",
|
|
84
|
+
"byte",
|
|
85
|
+
"case",
|
|
86
|
+
"catch",
|
|
87
|
+
"char",
|
|
88
|
+
"class",
|
|
89
|
+
"const",
|
|
90
|
+
"continue",
|
|
91
|
+
"debugger",
|
|
92
|
+
"default",
|
|
93
|
+
"delete",
|
|
94
|
+
"do",
|
|
95
|
+
"double",
|
|
96
|
+
"else",
|
|
97
|
+
"enum",
|
|
98
|
+
"eval",
|
|
99
|
+
"export",
|
|
100
|
+
"extends",
|
|
101
|
+
"false",
|
|
102
|
+
"final",
|
|
103
|
+
"finally",
|
|
104
|
+
"float",
|
|
105
|
+
"for",
|
|
106
|
+
"function",
|
|
107
|
+
"goto",
|
|
108
|
+
"if",
|
|
109
|
+
"implements",
|
|
110
|
+
"import",
|
|
111
|
+
"in",
|
|
112
|
+
"instanceof",
|
|
113
|
+
"int",
|
|
114
|
+
"interface",
|
|
115
|
+
"let",
|
|
116
|
+
"long",
|
|
117
|
+
"native",
|
|
118
|
+
"new",
|
|
119
|
+
"null",
|
|
120
|
+
"package",
|
|
121
|
+
"private",
|
|
122
|
+
"protected",
|
|
123
|
+
"public",
|
|
124
|
+
"return",
|
|
125
|
+
"short",
|
|
126
|
+
"static",
|
|
127
|
+
"super",
|
|
128
|
+
"switch",
|
|
129
|
+
"synchronized",
|
|
130
|
+
"this",
|
|
131
|
+
"throw",
|
|
132
|
+
"throws",
|
|
133
|
+
"transient",
|
|
134
|
+
"true",
|
|
135
|
+
"try",
|
|
136
|
+
"typeof",
|
|
137
|
+
"var",
|
|
138
|
+
"void",
|
|
139
|
+
"volatile",
|
|
140
|
+
"while",
|
|
141
|
+
"with",
|
|
142
|
+
"yield",
|
|
143
|
+
"Array",
|
|
144
|
+
"Date",
|
|
145
|
+
"hasOwnProperty",
|
|
146
|
+
"Infinity",
|
|
147
|
+
"isFinite",
|
|
148
|
+
"isNaN",
|
|
149
|
+
"isPrototypeOf",
|
|
150
|
+
"length",
|
|
151
|
+
"Math",
|
|
152
|
+
"name",
|
|
153
|
+
"NaN",
|
|
154
|
+
"Number",
|
|
155
|
+
"Object",
|
|
156
|
+
"prototype",
|
|
157
|
+
"String",
|
|
158
|
+
"toString",
|
|
159
|
+
"undefined",
|
|
160
|
+
"valueOf"
|
|
161
|
+
]);
|
|
162
|
+
/**
|
|
163
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* isValidVarName('status') // true
|
|
168
|
+
* isValidVarName('class') // false (reserved word)
|
|
169
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
function isValidVarName(name) {
|
|
173
|
+
if (!name || reservedWords.has(name)) return false;
|
|
174
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region ../../internals/utils/src/urlPath.ts
|
|
178
|
+
/**
|
|
179
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const p = new URLPath('/pet/{petId}')
|
|
183
|
+
* p.URL // '/pet/:petId'
|
|
184
|
+
* p.template // '`/pet/${petId}`'
|
|
185
|
+
*/
|
|
186
|
+
var URLPath = class {
|
|
187
|
+
/**
|
|
188
|
+
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
189
|
+
*/
|
|
190
|
+
path;
|
|
191
|
+
#options;
|
|
192
|
+
constructor(path, options = {}) {
|
|
193
|
+
this.path = path;
|
|
194
|
+
this.#options = options;
|
|
195
|
+
}
|
|
196
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
get URL() {
|
|
204
|
+
return this.toURLPath();
|
|
205
|
+
}
|
|
206
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
211
|
+
* new URLPath('/pet/{petId}').isURL // false
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
get isURL() {
|
|
215
|
+
try {
|
|
216
|
+
return !!new URL(this.path).href;
|
|
217
|
+
} catch {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
226
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
227
|
+
*/
|
|
228
|
+
get template() {
|
|
229
|
+
return this.toTemplateString();
|
|
230
|
+
}
|
|
231
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* new URLPath('/pet/{petId}').object
|
|
236
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
get object() {
|
|
240
|
+
return this.toObject();
|
|
241
|
+
}
|
|
242
|
+
/** Returns a map of path parameter names, or `null` when the path has no parameters.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
247
|
+
* new URLPath('/pet').params // null
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
get params() {
|
|
251
|
+
return this.toParamsObject();
|
|
252
|
+
}
|
|
253
|
+
#transformParam(raw) {
|
|
254
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
255
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
259
|
+
*/
|
|
260
|
+
#eachParam(fn) {
|
|
261
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
262
|
+
const raw = match[1];
|
|
263
|
+
fn(raw, this.#transformParam(raw));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
267
|
+
const object = {
|
|
268
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
269
|
+
params: this.toParamsObject()
|
|
270
|
+
};
|
|
271
|
+
if (stringify) {
|
|
272
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
273
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
274
|
+
return `{ url: '${object.url}' }`;
|
|
275
|
+
}
|
|
276
|
+
return object;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
280
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
284
|
+
*/
|
|
285
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
286
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
287
|
+
if (i % 2 === 0) return part;
|
|
288
|
+
const param = this.#transformParam(part);
|
|
289
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
290
|
+
}).join("");
|
|
291
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
295
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
296
|
+
* Returns `undefined` when no path parameters are found.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
301
|
+
* // { petId: 'petId', tagId: 'tagId' }
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
toParamsObject(replacer) {
|
|
305
|
+
const params = {};
|
|
306
|
+
this.#eachParam((_raw, param) => {
|
|
307
|
+
const key = replacer ? replacer(param) : param;
|
|
308
|
+
params[key] = key;
|
|
309
|
+
});
|
|
310
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
311
|
+
}
|
|
312
|
+
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
toURLPath() {
|
|
320
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
325
|
+
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
326
|
+
const mutationKeyTransformer = ({ node, casing }) => {
|
|
327
|
+
if (!node.path) return [];
|
|
328
|
+
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
329
|
+
};
|
|
330
|
+
function MutationKey$1({ name, paramsCasing, node, transformer }) {
|
|
331
|
+
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
332
|
+
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
333
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
334
|
+
node,
|
|
335
|
+
casing: paramsCasing
|
|
336
|
+
});
|
|
337
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
338
|
+
name,
|
|
339
|
+
isExportable: true,
|
|
340
|
+
isIndexable: true,
|
|
341
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
342
|
+
name,
|
|
343
|
+
export: true,
|
|
344
|
+
params: paramsSignature,
|
|
345
|
+
singleLine: true,
|
|
346
|
+
children: `[${keys.join(", ")}] as const`
|
|
347
|
+
})
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
__name(MutationKey$1, "MutationKey");
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../internals/shared/src/operation.ts
|
|
353
|
+
function getOperationLink(node, link) {
|
|
354
|
+
if (!link) return null;
|
|
355
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
356
|
+
if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
|
|
357
|
+
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
358
|
+
}
|
|
359
|
+
function getContentTypeInfo(node) {
|
|
360
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
361
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
362
|
+
return {
|
|
363
|
+
contentTypes,
|
|
364
|
+
isMultipleContentTypes,
|
|
365
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
366
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
367
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function buildRequestConfigType(node, resolver) {
|
|
371
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
372
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
373
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
374
|
+
}
|
|
375
|
+
function buildOperationComments(node, options = {}) {
|
|
376
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
377
|
+
const linkComment = getOperationLink(node, link);
|
|
378
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
379
|
+
node.description && `@description ${node.description}`,
|
|
380
|
+
node.summary && `@summary ${node.summary}`,
|
|
381
|
+
linkComment,
|
|
382
|
+
node.deprecated && "@deprecated"
|
|
383
|
+
] : [
|
|
384
|
+
node.description && `@description ${node.description}`,
|
|
385
|
+
node.summary && `@summary ${node.summary}`,
|
|
386
|
+
node.deprecated && "@deprecated",
|
|
387
|
+
linkComment
|
|
388
|
+
]).filter((comment) => Boolean(comment));
|
|
389
|
+
if (!splitLines) return filteredComments;
|
|
390
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
391
|
+
}
|
|
392
|
+
function getOperationParameters(node, options = {}) {
|
|
393
|
+
const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
|
|
394
|
+
return {
|
|
395
|
+
path: params.filter((param) => param.in === "path"),
|
|
396
|
+
query: params.filter((param) => param.in === "query"),
|
|
397
|
+
header: params.filter((param) => param.in === "header"),
|
|
398
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function getStatusCodeNumber(statusCode) {
|
|
402
|
+
const code = Number(statusCode);
|
|
403
|
+
return Number.isNaN(code) ? null : code;
|
|
404
|
+
}
|
|
405
|
+
function isErrorStatusCode(statusCode) {
|
|
406
|
+
const code = getStatusCodeNumber(statusCode);
|
|
407
|
+
return code !== null && code >= 400;
|
|
408
|
+
}
|
|
409
|
+
function resolveErrorNames(node, resolver) {
|
|
410
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
411
|
+
}
|
|
412
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
413
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
414
|
+
}
|
|
415
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
416
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
417
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
418
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
419
|
+
if (byResolver) {
|
|
420
|
+
const cached = byResolver.get(cacheKey);
|
|
421
|
+
if (cached) return cached;
|
|
422
|
+
} else {
|
|
423
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
424
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
425
|
+
}
|
|
426
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
427
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
428
|
+
const exclude = new Set(options.exclude ?? []);
|
|
429
|
+
const paramNames = [
|
|
430
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
431
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
432
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
433
|
+
];
|
|
434
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
435
|
+
const result = (options.order === "body-response-first" ? [
|
|
436
|
+
...bodyAndResponseNames,
|
|
437
|
+
...paramNames,
|
|
438
|
+
...responseStatusNames
|
|
439
|
+
] : [
|
|
440
|
+
...paramNames,
|
|
441
|
+
...bodyAndResponseNames,
|
|
442
|
+
...responseStatusNames
|
|
443
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
444
|
+
byResolver.set(cacheKey, result);
|
|
445
|
+
return result;
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region ../../internals/tanstack-query/src/utils.ts
|
|
449
|
+
/**
|
|
450
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
451
|
+
*
|
|
452
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
453
|
+
*/
|
|
454
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
455
|
+
if (!zodResolver) return [];
|
|
456
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Resolve the type for a single path parameter.
|
|
460
|
+
*
|
|
461
|
+
* - When the resolver's group name differs from the individual param name
|
|
462
|
+
* (e.g. kubbV4) → `GroupName['paramName']` (member access).
|
|
463
|
+
* - When they match (v5 default) → `TypeName` (direct reference).
|
|
464
|
+
*/
|
|
465
|
+
function resolvePathParamType(node, param, resolver) {
|
|
466
|
+
const individualName = resolver.resolveParamName(node, param);
|
|
467
|
+
const groupName = resolver.resolvePathParamsName(node, param);
|
|
468
|
+
if (groupName !== individualName) return _kubb_core.ast.createParamsType({
|
|
469
|
+
variant: "member",
|
|
470
|
+
base: groupName,
|
|
471
|
+
key: param.name
|
|
472
|
+
});
|
|
473
|
+
return _kubb_core.ast.createParamsType({
|
|
474
|
+
variant: "reference",
|
|
475
|
+
name: individualName
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Derive a query-params group type from the resolver.
|
|
480
|
+
* Returns `null` when no query params exist or when the group name
|
|
481
|
+
* equals the individual param name (no real group).
|
|
482
|
+
*/
|
|
483
|
+
function resolveQueryGroupType(node, params, resolver) {
|
|
484
|
+
if (!params.length) return null;
|
|
485
|
+
const firstParam = params[0];
|
|
486
|
+
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
487
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
488
|
+
return {
|
|
489
|
+
type: _kubb_core.ast.createParamsType({
|
|
490
|
+
variant: "reference",
|
|
491
|
+
name: groupName
|
|
492
|
+
}),
|
|
493
|
+
optional: params.every((p) => !p.required)
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Build a single `FunctionParameterNode` for a query or header group.
|
|
498
|
+
*/
|
|
499
|
+
function buildGroupParam(name, node, params, groupType, resolver) {
|
|
500
|
+
if (groupType) return [_kubb_core.ast.createFunctionParameter({
|
|
501
|
+
name,
|
|
502
|
+
type: groupType.type,
|
|
503
|
+
optional: groupType.optional
|
|
504
|
+
})];
|
|
505
|
+
if (params.length) {
|
|
506
|
+
const structProps = params.map((p) => ({
|
|
507
|
+
name: p.name,
|
|
508
|
+
type: _kubb_core.ast.createParamsType({
|
|
509
|
+
variant: "reference",
|
|
510
|
+
name: resolver.resolveParamName(node, p)
|
|
511
|
+
}),
|
|
512
|
+
optional: !p.required
|
|
513
|
+
}));
|
|
514
|
+
return [_kubb_core.ast.createFunctionParameter({
|
|
515
|
+
name,
|
|
516
|
+
type: _kubb_core.ast.createParamsType({
|
|
517
|
+
variant: "struct",
|
|
518
|
+
properties: structProps
|
|
519
|
+
}),
|
|
520
|
+
optional: params.every((p) => !p.required)
|
|
521
|
+
})];
|
|
522
|
+
}
|
|
523
|
+
return [];
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
|
|
527
|
+
*/
|
|
528
|
+
function buildQueryKeyParams(node, options) {
|
|
529
|
+
const { pathParamsType, paramsCasing, resolver } = options;
|
|
530
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
531
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
532
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
533
|
+
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
534
|
+
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
535
|
+
variant: "reference",
|
|
536
|
+
name: resolver.resolveDataName(node)
|
|
537
|
+
}) : null;
|
|
538
|
+
const bodyRequired = node.requestBody?.required ?? false;
|
|
539
|
+
const params = [];
|
|
540
|
+
if (pathParams.length) {
|
|
541
|
+
const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
|
|
542
|
+
name: p.name,
|
|
543
|
+
type: resolvePathParamType(node, p, resolver),
|
|
544
|
+
optional: !p.required
|
|
545
|
+
}));
|
|
546
|
+
params.push({
|
|
547
|
+
kind: "ParameterGroup",
|
|
548
|
+
properties: pathChildren,
|
|
549
|
+
inline: pathParamsType === "inline",
|
|
550
|
+
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
554
|
+
name: "data",
|
|
555
|
+
type: bodyType,
|
|
556
|
+
optional: !bodyRequired
|
|
557
|
+
}));
|
|
558
|
+
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
559
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Collect the names of the required params (no default) that drive the `enabled`
|
|
563
|
+
* guard. These are exactly the params that should be made optional in the
|
|
564
|
+
* generated signatures so callers can pass `undefined` to reach the disabled state.
|
|
565
|
+
*/
|
|
566
|
+
function getEnabledParamNames(paramsNode) {
|
|
567
|
+
const required = [];
|
|
568
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
569
|
+
const group = param;
|
|
570
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
571
|
+
} else {
|
|
572
|
+
const fp = param;
|
|
573
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
574
|
+
}
|
|
575
|
+
return required;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Return a copy of `paramsNode` with the named params marked optional.
|
|
579
|
+
*
|
|
580
|
+
* Used to align signatures with the `enabled` guard: the guard already disables
|
|
581
|
+
* the query while a param is falsy, so the param should accept `undefined`. The
|
|
582
|
+
* change is type-only — the `queryFn` keeps calling the client with a non-null
|
|
583
|
+
* assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
|
|
584
|
+
*/
|
|
585
|
+
function markParamsOptional(paramsNode, names) {
|
|
586
|
+
if (names.length === 0) return paramsNode;
|
|
587
|
+
const nameSet = new Set(names);
|
|
588
|
+
const params = paramsNode.params.map((param) => {
|
|
589
|
+
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
590
|
+
const group = param;
|
|
591
|
+
return {
|
|
592
|
+
...group,
|
|
593
|
+
properties: group.properties.map((child) => nameSet.has(child.name) ? _kubb_core.ast.createFunctionParameter({
|
|
594
|
+
name: child.name,
|
|
595
|
+
type: child.type,
|
|
596
|
+
rest: child.rest,
|
|
597
|
+
optional: true
|
|
598
|
+
}) : child)
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
const fp = param;
|
|
602
|
+
return nameSet.has(fp.name) ? _kubb_core.ast.createFunctionParameter({
|
|
603
|
+
name: fp.name,
|
|
604
|
+
type: fp.type,
|
|
605
|
+
rest: fp.rest,
|
|
606
|
+
optional: true
|
|
607
|
+
}) : fp;
|
|
608
|
+
});
|
|
609
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
613
|
+
* string. Bridges the type gap created by `markParamsOptional` while keeping the
|
|
614
|
+
* runtime identical (the `!` is erased at compile time).
|
|
615
|
+
*
|
|
616
|
+
* Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
|
|
617
|
+
* standalone identifiers (`params` → `params!`).
|
|
618
|
+
*/
|
|
619
|
+
function injectNonNullAssertions(callStr, names) {
|
|
620
|
+
if (names.length === 0) return callStr;
|
|
621
|
+
const nameSet = new Set(names);
|
|
622
|
+
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
623
|
+
if (inner.includes(":") || inner.includes("...")) return match;
|
|
624
|
+
const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
|
|
625
|
+
if (!keys.some((k) => nameSet.has(k))) return match;
|
|
626
|
+
return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
|
|
627
|
+
});
|
|
628
|
+
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
633
|
+
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
634
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
635
|
+
if (!node.path) return [];
|
|
636
|
+
const path = new URLPath(node.path, { casing });
|
|
637
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
638
|
+
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
639
|
+
return [
|
|
640
|
+
path.toObject({
|
|
641
|
+
type: "path",
|
|
642
|
+
stringify: true
|
|
643
|
+
}),
|
|
644
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
645
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
646
|
+
].filter(Boolean);
|
|
647
|
+
};
|
|
648
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
649
|
+
const baseParamsNode = buildQueryKeyParams(node, {
|
|
650
|
+
pathParamsType,
|
|
651
|
+
paramsCasing,
|
|
652
|
+
resolver: tsResolver
|
|
653
|
+
});
|
|
654
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
|
|
655
|
+
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
656
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
657
|
+
node,
|
|
658
|
+
casing: paramsCasing
|
|
659
|
+
});
|
|
660
|
+
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.File.Source, {
|
|
661
|
+
name,
|
|
662
|
+
isExportable: true,
|
|
663
|
+
isIndexable: true,
|
|
664
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
665
|
+
name,
|
|
666
|
+
export: true,
|
|
667
|
+
params: paramsSignature,
|
|
668
|
+
singleLine: true,
|
|
669
|
+
children: `[${keys.join(", ")}] as const`
|
|
670
|
+
})
|
|
671
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
672
|
+
name: typeName,
|
|
673
|
+
isTypeOnly: true,
|
|
674
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
675
|
+
name: typeName,
|
|
676
|
+
children: `ReturnType<typeof ${name}>`
|
|
677
|
+
})
|
|
678
|
+
})] });
|
|
679
|
+
}
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/components/Mutation.tsx
|
|
682
|
+
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
683
|
+
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
684
|
+
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
685
|
+
function createMutationArgParams(node, options) {
|
|
686
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
687
|
+
paramsType: "inline",
|
|
688
|
+
pathParamsType: "inline",
|
|
689
|
+
paramsCasing: options.paramsCasing,
|
|
690
|
+
resolver: options.resolver
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
function buildMutationParamsNode(node, options) {
|
|
694
|
+
const { dataReturnType, mutationKeyTypeName, mutationArgTypeName, resolver } = options;
|
|
695
|
+
const responseName = resolver.resolveResponseName(node);
|
|
696
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
697
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
698
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
699
|
+
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
700
|
+
name: "options",
|
|
701
|
+
type: _kubb_core.ast.createParamsType({
|
|
702
|
+
variant: "reference",
|
|
703
|
+
name: `{
|
|
704
|
+
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
|
|
705
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
706
|
+
shouldFetch?: boolean,
|
|
707
|
+
}`
|
|
708
|
+
}),
|
|
709
|
+
default: "{}"
|
|
710
|
+
})] });
|
|
711
|
+
}
|
|
712
|
+
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
713
|
+
const responseName = tsResolver.resolveResponseName(node);
|
|
714
|
+
const errorNames = resolveErrorNames(node, tsResolver);
|
|
715
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
716
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
717
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
718
|
+
paramsCasing,
|
|
719
|
+
resolver: tsResolver
|
|
720
|
+
});
|
|
721
|
+
const hasMutationParams = mutationArgParamsNode.params.length > 0;
|
|
722
|
+
const argTypeBody = hasMutationParams ? declarationPrinter$2.print(mutationArgParamsNode) ?? "" : "";
|
|
723
|
+
const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
|
|
724
|
+
const generics = [
|
|
725
|
+
TData,
|
|
726
|
+
TError,
|
|
727
|
+
`${mutationKeyTypeName} | null`,
|
|
728
|
+
mutationArgTypeName
|
|
729
|
+
];
|
|
730
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
731
|
+
paramsCasing,
|
|
732
|
+
dataReturnType,
|
|
733
|
+
mutationKeyTypeName,
|
|
734
|
+
mutationArgTypeName,
|
|
735
|
+
resolver: tsResolver
|
|
736
|
+
});
|
|
737
|
+
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
738
|
+
const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
739
|
+
paramsType,
|
|
740
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
741
|
+
paramsCasing,
|
|
742
|
+
resolver: tsResolver,
|
|
743
|
+
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
744
|
+
name: "config",
|
|
745
|
+
type: _kubb_core.ast.createParamsType({
|
|
746
|
+
variant: "reference",
|
|
747
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
748
|
+
}),
|
|
749
|
+
default: "{}"
|
|
750
|
+
})]
|
|
751
|
+
});
|
|
752
|
+
const clientCallStr = callPrinter$2.print(clientCallParamsNode) ?? "";
|
|
753
|
+
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.File.Source, {
|
|
754
|
+
name: mutationArgTypeName,
|
|
755
|
+
isExportable: true,
|
|
756
|
+
isIndexable: true,
|
|
757
|
+
isTypeOnly: true,
|
|
758
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
759
|
+
name: mutationArgTypeName,
|
|
760
|
+
export: true,
|
|
761
|
+
children: hasMutationParams ? `{ ${argTypeBody} }` : "never"
|
|
762
|
+
})
|
|
763
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
764
|
+
name,
|
|
765
|
+
isExportable: true,
|
|
766
|
+
isIndexable: true,
|
|
767
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
768
|
+
name,
|
|
769
|
+
export: true,
|
|
770
|
+
params: paramsSignature,
|
|
771
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
772
|
+
children: `
|
|
773
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
774
|
+
const mutationKey = ${mutationKeyName}()
|
|
775
|
+
|
|
776
|
+
return useSWRMutation<${generics.join(", ")}>(
|
|
777
|
+
shouldFetch ? mutationKey : null,
|
|
778
|
+
async (_url${hasMutationParams ? `, { arg: { ${argKeysStr} } }` : ""}) => {
|
|
779
|
+
return ${clientName}(${clientCallStr})
|
|
780
|
+
},
|
|
781
|
+
mutationOptions
|
|
782
|
+
)
|
|
783
|
+
`
|
|
784
|
+
})
|
|
785
|
+
})] });
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/components/MutationKey.tsx
|
|
789
|
+
function MutationKey({ name, typeName, node, paramsCasing, pathParamsType, transformer }) {
|
|
790
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(MutationKey$1, {
|
|
791
|
+
name,
|
|
792
|
+
node,
|
|
793
|
+
paramsCasing,
|
|
794
|
+
pathParamsType,
|
|
795
|
+
transformer
|
|
796
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
797
|
+
name: typeName,
|
|
798
|
+
isExportable: true,
|
|
799
|
+
isIndexable: true,
|
|
800
|
+
isTypeOnly: true,
|
|
801
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
802
|
+
export: true,
|
|
803
|
+
name: typeName,
|
|
804
|
+
children: `ReturnType<typeof ${name}>`
|
|
805
|
+
})
|
|
806
|
+
})] });
|
|
807
|
+
}
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/components/QueryOptions.tsx
|
|
810
|
+
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
811
|
+
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
812
|
+
function getQueryOptionsParams(node, options) {
|
|
813
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
814
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
815
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
816
|
+
paramsType,
|
|
817
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
818
|
+
paramsCasing,
|
|
819
|
+
resolver,
|
|
820
|
+
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
821
|
+
name: "config",
|
|
822
|
+
type: _kubb_core.ast.createParamsType({
|
|
823
|
+
variant: "reference",
|
|
824
|
+
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
825
|
+
}),
|
|
826
|
+
default: "{}"
|
|
827
|
+
})]
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
|
|
831
|
+
const enabledNames = getEnabledParamNames(buildQueryKeyParams(node, {
|
|
832
|
+
pathParamsType,
|
|
833
|
+
paramsCasing,
|
|
834
|
+
resolver: tsResolver
|
|
835
|
+
}));
|
|
836
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
837
|
+
paramsType,
|
|
838
|
+
paramsCasing,
|
|
839
|
+
pathParamsType,
|
|
840
|
+
resolver: tsResolver
|
|
841
|
+
}), enabledNames);
|
|
842
|
+
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
843
|
+
const clientCallStr = injectNonNullAssertions(callPrinter$1.print(paramsNode) ?? "", enabledNames);
|
|
844
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
845
|
+
name,
|
|
846
|
+
isExportable: true,
|
|
847
|
+
isIndexable: true,
|
|
848
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
849
|
+
name,
|
|
850
|
+
export: true,
|
|
851
|
+
params: paramsSignature,
|
|
852
|
+
children: `
|
|
853
|
+
return {
|
|
854
|
+
fetcher: async () => {
|
|
855
|
+
return ${clientName}(${clientCallStr})
|
|
856
|
+
},
|
|
857
|
+
}
|
|
858
|
+
`
|
|
859
|
+
})
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/components/Query.tsx
|
|
864
|
+
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
865
|
+
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
866
|
+
function buildQueryParamsNode(node, options) {
|
|
867
|
+
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
868
|
+
const responseName = resolver.resolveResponseName(node);
|
|
869
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
870
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
871
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
872
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
873
|
+
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
874
|
+
name: "options",
|
|
875
|
+
type: _kubb_core.ast.createParamsType({
|
|
876
|
+
variant: "reference",
|
|
877
|
+
name: `{
|
|
878
|
+
query?: SWRConfiguration<${[TData, TError].join(", ")}>,
|
|
879
|
+
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
880
|
+
shouldFetch?: boolean,
|
|
881
|
+
immutable?: boolean
|
|
882
|
+
}`
|
|
883
|
+
}),
|
|
884
|
+
default: "{}"
|
|
885
|
+
});
|
|
886
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
887
|
+
paramsType,
|
|
888
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
889
|
+
paramsCasing,
|
|
890
|
+
resolver,
|
|
891
|
+
extraParams: [optionsParam]
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
895
|
+
const responseName = tsResolver.resolveResponseName(node);
|
|
896
|
+
const errorNames = resolveErrorNames(node, tsResolver);
|
|
897
|
+
const generics = [
|
|
898
|
+
dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`,
|
|
899
|
+
`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
|
|
900
|
+
`${queryKeyTypeName} | null`
|
|
901
|
+
];
|
|
902
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
903
|
+
pathParamsType,
|
|
904
|
+
paramsCasing,
|
|
905
|
+
resolver: tsResolver
|
|
906
|
+
});
|
|
907
|
+
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
908
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
909
|
+
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
910
|
+
paramsType,
|
|
911
|
+
paramsCasing,
|
|
912
|
+
pathParamsType,
|
|
913
|
+
resolver: tsResolver
|
|
914
|
+
});
|
|
915
|
+
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
916
|
+
const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
|
|
917
|
+
paramsType,
|
|
918
|
+
paramsCasing,
|
|
919
|
+
pathParamsType,
|
|
920
|
+
dataReturnType,
|
|
921
|
+
resolver: tsResolver
|
|
922
|
+
}), enabledNames);
|
|
923
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
924
|
+
const shouldFetchExpr = enabledNames.length ? `shouldFetch && !!(${enabledNames.join(" && ")})` : "shouldFetch";
|
|
925
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
926
|
+
name,
|
|
927
|
+
isExportable: true,
|
|
928
|
+
isIndexable: true,
|
|
929
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
930
|
+
name,
|
|
931
|
+
export: true,
|
|
932
|
+
params: paramsSignature,
|
|
933
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
934
|
+
children: `
|
|
935
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
|
|
936
|
+
|
|
937
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
938
|
+
|
|
939
|
+
return useSWR<${generics.join(", ")}>(
|
|
940
|
+
${shouldFetchExpr} ? queryKey : null,
|
|
941
|
+
{
|
|
942
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),
|
|
943
|
+
...(immutable ? {
|
|
944
|
+
revalidateIfStale: false,
|
|
945
|
+
revalidateOnFocus: false,
|
|
946
|
+
revalidateOnReconnect: false
|
|
947
|
+
} : { }),
|
|
948
|
+
...queryOptions,
|
|
949
|
+
}
|
|
950
|
+
)
|
|
951
|
+
`
|
|
952
|
+
})
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
//#endregion
|
|
956
|
+
Object.defineProperty(exports, "Mutation", {
|
|
957
|
+
enumerable: true,
|
|
958
|
+
get: function() {
|
|
959
|
+
return Mutation;
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
Object.defineProperty(exports, "MutationKey", {
|
|
963
|
+
enumerable: true,
|
|
964
|
+
get: function() {
|
|
965
|
+
return MutationKey;
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
Object.defineProperty(exports, "Query", {
|
|
969
|
+
enumerable: true,
|
|
970
|
+
get: function() {
|
|
971
|
+
return Query;
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
Object.defineProperty(exports, "QueryKey", {
|
|
975
|
+
enumerable: true,
|
|
976
|
+
get: function() {
|
|
977
|
+
return QueryKey;
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
Object.defineProperty(exports, "QueryOptions", {
|
|
981
|
+
enumerable: true,
|
|
982
|
+
get: function() {
|
|
983
|
+
return QueryOptions;
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
Object.defineProperty(exports, "__name", {
|
|
987
|
+
enumerable: true,
|
|
988
|
+
get: function() {
|
|
989
|
+
return __name;
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
Object.defineProperty(exports, "__toESM", {
|
|
993
|
+
enumerable: true,
|
|
994
|
+
get: function() {
|
|
995
|
+
return __toESM;
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
Object.defineProperty(exports, "camelCase", {
|
|
999
|
+
enumerable: true,
|
|
1000
|
+
get: function() {
|
|
1001
|
+
return camelCase;
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
Object.defineProperty(exports, "mutationKeyTransformer", {
|
|
1005
|
+
enumerable: true,
|
|
1006
|
+
get: function() {
|
|
1007
|
+
return mutationKeyTransformer;
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
Object.defineProperty(exports, "queryKeyTransformer", {
|
|
1011
|
+
enumerable: true,
|
|
1012
|
+
get: function() {
|
|
1013
|
+
return queryKeyTransformer;
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
Object.defineProperty(exports, "resolveOperationTypeNames", {
|
|
1017
|
+
enumerable: true,
|
|
1018
|
+
get: function() {
|
|
1019
|
+
return resolveOperationTypeNames;
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
1023
|
+
enumerable: true,
|
|
1024
|
+
get: function() {
|
|
1025
|
+
return resolveZodSchemaNames;
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
//# sourceMappingURL=components-CD7ZoS3B.cjs.map
|