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