@kubb/plugin-swr 5.0.0-alpha.33 → 5.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-BJSzUg7M.cjs +955 -0
- package/dist/components-BJSzUg7M.cjs.map +1 -0
- package/dist/components-JQ2KRFCa.js +877 -0
- package/dist/components-JQ2KRFCa.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +77 -37
- package/dist/components.js +1 -1
- package/dist/generators-17ulS9mu.cjs +537 -0
- package/dist/generators-17ulS9mu.cjs.map +1 -0
- package/dist/generators-Cl7nr-FB.js +526 -0
- package/dist/generators-Cl7nr-FB.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -4
- package/dist/generators.js +1 -1
- package/dist/index.cjs +132 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.js +132 -110
- package/dist/index.js.map +1 -1
- package/dist/{types-BVDtH9S7.d.ts → types-FA5mH9Ch.d.ts} +46 -90
- package/package.json +7 -11
- package/src/components/Mutation.tsx +165 -170
- package/src/components/MutationKey.tsx +50 -1
- package/src/components/Query.tsx +122 -126
- package/src/components/QueryKey.tsx +65 -1
- package/src/components/QueryOptions.tsx +38 -93
- package/src/generators/mutationGenerator.tsx +194 -117
- package/src/generators/queryGenerator.tsx +205 -139
- package/src/plugin.ts +117 -152
- package/src/resolvers/resolverSwr.ts +26 -0
- package/src/resolvers/resolverSwrLegacy.ts +17 -0
- package/src/types.ts +55 -18
- package/src/utils.ts +209 -0
- package/dist/components-DaCTPplv.js +0 -756
- package/dist/components-DaCTPplv.js.map +0 -1
- package/dist/components-Qs8_faOt.cjs +0 -834
- package/dist/components-Qs8_faOt.cjs.map +0 -1
- package/dist/generators-0YayIrse.js +0 -400
- package/dist/generators-0YayIrse.js.map +0 -1
- package/dist/generators-Bd4rCa3l.cjs +0 -411
- package/dist/generators-Bd4rCa3l.cjs.map +0 -1
|
@@ -0,0 +1,955 @@
|
|
|
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
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* isValidVarName('status') // true
|
|
81
|
+
* isValidVarName('class') // false (reserved word)
|
|
82
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function isValidVarName(name) {
|
|
86
|
+
try {
|
|
87
|
+
new Function(`var ${name}`);
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region ../../internals/utils/src/urlPath.ts
|
|
95
|
+
/**
|
|
96
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const p = new URLPath('/pet/{petId}')
|
|
100
|
+
* p.URL // '/pet/:petId'
|
|
101
|
+
* p.template // '`/pet/${petId}`'
|
|
102
|
+
*/
|
|
103
|
+
var URLPath = class {
|
|
104
|
+
/**
|
|
105
|
+
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
106
|
+
*/
|
|
107
|
+
path;
|
|
108
|
+
#options;
|
|
109
|
+
constructor(path, options = {}) {
|
|
110
|
+
this.path = path;
|
|
111
|
+
this.#options = options;
|
|
112
|
+
}
|
|
113
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
get URL() {
|
|
121
|
+
return this.toURLPath();
|
|
122
|
+
}
|
|
123
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
128
|
+
* new URLPath('/pet/{petId}').isURL // false
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
get isURL() {
|
|
132
|
+
try {
|
|
133
|
+
return !!new URL(this.path).href;
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
143
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
144
|
+
*/
|
|
145
|
+
get template() {
|
|
146
|
+
return this.toTemplateString();
|
|
147
|
+
}
|
|
148
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* new URLPath('/pet/{petId}').object
|
|
153
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
get object() {
|
|
157
|
+
return this.toObject();
|
|
158
|
+
}
|
|
159
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
164
|
+
* new URLPath('/pet').params // undefined
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
get params() {
|
|
168
|
+
return this.getParams();
|
|
169
|
+
}
|
|
170
|
+
#transformParam(raw) {
|
|
171
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
172
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
176
|
+
*/
|
|
177
|
+
#eachParam(fn) {
|
|
178
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
179
|
+
const raw = match[1];
|
|
180
|
+
fn(raw, this.#transformParam(raw));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
184
|
+
const object = {
|
|
185
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
186
|
+
params: this.getParams()
|
|
187
|
+
};
|
|
188
|
+
if (stringify) {
|
|
189
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
190
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
191
|
+
return `{ url: '${object.url}' }`;
|
|
192
|
+
}
|
|
193
|
+
return object;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
197
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
201
|
+
*/
|
|
202
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
203
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
204
|
+
if (i % 2 === 0) return part;
|
|
205
|
+
const param = this.#transformParam(part);
|
|
206
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
207
|
+
}).join("")}\``;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
211
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
212
|
+
* Returns `undefined` when no path parameters are found.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
217
|
+
* // { petId: 'petId', tagId: 'tagId' }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
getParams(replacer) {
|
|
221
|
+
const params = {};
|
|
222
|
+
this.#eachParam((_raw, param) => {
|
|
223
|
+
const key = replacer ? replacer(param) : param;
|
|
224
|
+
params[key] = key;
|
|
225
|
+
});
|
|
226
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
227
|
+
}
|
|
228
|
+
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
toURLPath() {
|
|
236
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/utils.ts
|
|
241
|
+
/**
|
|
242
|
+
* Apply the user-provided `transformers.name` function (if any) to a resolved name.
|
|
243
|
+
* Mirrors the old `createPlugin` `resolveName` lifecycle that applied transformers
|
|
244
|
+
* after resolving the full name (base + suffix).
|
|
245
|
+
*/
|
|
246
|
+
function transformName(name, type, transformers) {
|
|
247
|
+
return transformers?.name?.(name, type) || name;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Build JSDoc comment lines from an OperationNode.
|
|
251
|
+
*/
|
|
252
|
+
function getComments(node) {
|
|
253
|
+
return [
|
|
254
|
+
node.description && `@description ${node.description}`,
|
|
255
|
+
node.summary && `@summary ${node.summary}`,
|
|
256
|
+
node.deprecated && "@deprecated",
|
|
257
|
+
`{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`
|
|
258
|
+
].filter((x) => Boolean(x));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Resolve error type names from operation responses.
|
|
262
|
+
*/
|
|
263
|
+
function resolveErrorNames(node, tsResolver) {
|
|
264
|
+
return node.responses.filter((r) => {
|
|
265
|
+
return Number.parseInt(r.statusCode, 10) >= 400 || r.statusCode === "default";
|
|
266
|
+
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Resolve the type for a single path parameter.
|
|
270
|
+
*
|
|
271
|
+
* - When the resolver's group name differs from the individual param name
|
|
272
|
+
* (e.g. kubbV4) → `GroupName['paramName']` (member access).
|
|
273
|
+
* - When they match (v5 default) → `TypeName` (direct reference).
|
|
274
|
+
*/
|
|
275
|
+
function resolvePathParamType(node, param, resolver) {
|
|
276
|
+
const individualName = resolver.resolveParamName(node, param);
|
|
277
|
+
const groupName = resolver.resolvePathParamsName(node, param);
|
|
278
|
+
if (groupName !== individualName) return _kubb_core.ast.createParamsType({
|
|
279
|
+
variant: "member",
|
|
280
|
+
base: groupName,
|
|
281
|
+
key: param.name
|
|
282
|
+
});
|
|
283
|
+
return _kubb_core.ast.createParamsType({
|
|
284
|
+
variant: "reference",
|
|
285
|
+
name: individualName
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Derive a query-params group type from the resolver.
|
|
290
|
+
* Returns `undefined` when no query params exist or when the group name
|
|
291
|
+
* equals the individual param name (no real group).
|
|
292
|
+
*/
|
|
293
|
+
function resolveQueryGroupType(node, params, resolver) {
|
|
294
|
+
if (!params.length) return void 0;
|
|
295
|
+
const firstParam = params[0];
|
|
296
|
+
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
297
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
298
|
+
return {
|
|
299
|
+
type: _kubb_core.ast.createParamsType({
|
|
300
|
+
variant: "reference",
|
|
301
|
+
name: groupName
|
|
302
|
+
}),
|
|
303
|
+
optional: params.every((p) => !p.required)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Derive a header-params group type from the resolver.
|
|
308
|
+
*/
|
|
309
|
+
function resolveHeaderGroupType(node, params, resolver) {
|
|
310
|
+
if (!params.length) return void 0;
|
|
311
|
+
const firstParam = params[0];
|
|
312
|
+
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
313
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
314
|
+
return {
|
|
315
|
+
type: _kubb_core.ast.createParamsType({
|
|
316
|
+
variant: "reference",
|
|
317
|
+
name: groupName
|
|
318
|
+
}),
|
|
319
|
+
optional: params.every((p) => !p.required)
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Build a single `FunctionParameterNode` for a query or header group.
|
|
324
|
+
*/
|
|
325
|
+
function buildGroupParam(name, node, params, groupType, resolver) {
|
|
326
|
+
if (groupType) return [_kubb_core.ast.createFunctionParameter({
|
|
327
|
+
name,
|
|
328
|
+
type: groupType.type,
|
|
329
|
+
optional: groupType.optional
|
|
330
|
+
})];
|
|
331
|
+
if (params.length) {
|
|
332
|
+
const structProps = params.map((p) => ({
|
|
333
|
+
name: p.name,
|
|
334
|
+
type: _kubb_core.ast.createParamsType({
|
|
335
|
+
variant: "reference",
|
|
336
|
+
name: resolver.resolveParamName(node, p)
|
|
337
|
+
}),
|
|
338
|
+
optional: !p.required
|
|
339
|
+
}));
|
|
340
|
+
return [_kubb_core.ast.createFunctionParameter({
|
|
341
|
+
name,
|
|
342
|
+
type: _kubb_core.ast.createParamsType({
|
|
343
|
+
variant: "struct",
|
|
344
|
+
properties: structProps
|
|
345
|
+
}),
|
|
346
|
+
optional: params.every((p) => !p.required)
|
|
347
|
+
})];
|
|
348
|
+
}
|
|
349
|
+
return [];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
|
|
353
|
+
*/
|
|
354
|
+
function buildQueryKeyParams(node, options) {
|
|
355
|
+
const { pathParamsType, paramsCasing, resolver } = options;
|
|
356
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
357
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
358
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
359
|
+
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
360
|
+
const bodyType = node.requestBody?.schema ? _kubb_core.ast.createParamsType({
|
|
361
|
+
variant: "reference",
|
|
362
|
+
name: resolver.resolveDataName(node)
|
|
363
|
+
}) : void 0;
|
|
364
|
+
const bodyRequired = node.requestBody?.required ?? false;
|
|
365
|
+
const params = [];
|
|
366
|
+
if (pathParams.length) {
|
|
367
|
+
const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
|
|
368
|
+
name: p.name,
|
|
369
|
+
type: resolvePathParamType(node, p, resolver),
|
|
370
|
+
optional: !p.required
|
|
371
|
+
}));
|
|
372
|
+
params.push({
|
|
373
|
+
kind: "ParameterGroup",
|
|
374
|
+
properties: pathChildren,
|
|
375
|
+
inline: pathParamsType === "inline",
|
|
376
|
+
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
380
|
+
name: "data",
|
|
381
|
+
type: bodyType,
|
|
382
|
+
optional: !bodyRequired
|
|
383
|
+
}));
|
|
384
|
+
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
385
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Build mutation arg params for paramsToTrigger mode.
|
|
389
|
+
* Contains pathParams + data + queryParams + headers (all flattened, for type alias).
|
|
390
|
+
*/
|
|
391
|
+
function buildMutationArgParams(node, options) {
|
|
392
|
+
const { paramsCasing, resolver } = options;
|
|
393
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
394
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
395
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
396
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
397
|
+
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
398
|
+
const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
|
|
399
|
+
const bodyType = node.requestBody?.schema ? _kubb_core.ast.createParamsType({
|
|
400
|
+
variant: "reference",
|
|
401
|
+
name: resolver.resolveDataName(node)
|
|
402
|
+
}) : void 0;
|
|
403
|
+
const bodyRequired = node.requestBody?.required ?? false;
|
|
404
|
+
const params = [];
|
|
405
|
+
for (const p of pathParams) params.push(_kubb_core.ast.createFunctionParameter({
|
|
406
|
+
name: p.name,
|
|
407
|
+
type: resolvePathParamType(node, p, resolver),
|
|
408
|
+
optional: !p.required
|
|
409
|
+
}));
|
|
410
|
+
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
411
|
+
name: "data",
|
|
412
|
+
type: bodyType,
|
|
413
|
+
optional: !bodyRequired
|
|
414
|
+
}));
|
|
415
|
+
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
416
|
+
params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
|
|
417
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
418
|
+
}
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/components/Mutation.tsx
|
|
421
|
+
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
422
|
+
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
423
|
+
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
424
|
+
/**
|
|
425
|
+
* Default mutation hook params (paramsToTrigger=false):
|
|
426
|
+
* pathParams + queryParams + headers + options (NO data — it comes via useSWRMutation arg)
|
|
427
|
+
*/
|
|
428
|
+
function getParams$3(node, options) {
|
|
429
|
+
const { paramsCasing, pathParamsType, dataReturnType, resolver, mutationKeyTypeName } = options;
|
|
430
|
+
const responseName = resolver.resolveResponseName(node);
|
|
431
|
+
const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
|
|
432
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
433
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
434
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
435
|
+
const TExtraArg = requestName || "never";
|
|
436
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
437
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
438
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
439
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
440
|
+
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
441
|
+
const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
|
|
442
|
+
const params = [];
|
|
443
|
+
if (pathParams.length) {
|
|
444
|
+
const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
|
|
445
|
+
name: p.name,
|
|
446
|
+
type: resolvePathParamType(node, p, resolver),
|
|
447
|
+
optional: !p.required
|
|
448
|
+
}));
|
|
449
|
+
params.push({
|
|
450
|
+
kind: "ParameterGroup",
|
|
451
|
+
properties: pathChildren,
|
|
452
|
+
inline: pathParamsType === "inline",
|
|
453
|
+
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
457
|
+
params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
|
|
458
|
+
params.push(_kubb_core.ast.createFunctionParameter({
|
|
459
|
+
name: "options",
|
|
460
|
+
type: _kubb_core.ast.createParamsType({
|
|
461
|
+
variant: "reference",
|
|
462
|
+
name: `{
|
|
463
|
+
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${TExtraArg}> & { throwOnError?: boolean },
|
|
464
|
+
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
465
|
+
shouldFetch?: boolean,
|
|
466
|
+
}`
|
|
467
|
+
}),
|
|
468
|
+
default: "{}"
|
|
469
|
+
}));
|
|
470
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
471
|
+
}
|
|
472
|
+
__name(getParams$3, "getParams");
|
|
473
|
+
/**
|
|
474
|
+
* Trigger-mode params (paramsToTrigger=true): just `options`
|
|
475
|
+
*/
|
|
476
|
+
function getTriggerParams(node, options) {
|
|
477
|
+
const { dataReturnType, resolver, mutationKeyTypeName, mutationArgTypeName } = options;
|
|
478
|
+
const responseName = resolver.resolveResponseName(node);
|
|
479
|
+
const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
|
|
480
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
481
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
482
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
483
|
+
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
484
|
+
name: "options",
|
|
485
|
+
type: _kubb_core.ast.createParamsType({
|
|
486
|
+
variant: "reference",
|
|
487
|
+
name: `{
|
|
488
|
+
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
|
|
489
|
+
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
490
|
+
shouldFetch?: boolean,
|
|
491
|
+
}`
|
|
492
|
+
}),
|
|
493
|
+
default: "{}"
|
|
494
|
+
})] });
|
|
495
|
+
}
|
|
496
|
+
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, paramsToTrigger = false }) {
|
|
497
|
+
const responseName = tsResolver.resolveResponseName(node);
|
|
498
|
+
const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
|
|
499
|
+
const errorNames = resolveErrorNames(node, tsResolver);
|
|
500
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
501
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
502
|
+
const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
503
|
+
paramsType,
|
|
504
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
505
|
+
paramsCasing,
|
|
506
|
+
resolver: tsResolver,
|
|
507
|
+
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
508
|
+
name: "config",
|
|
509
|
+
type: _kubb_core.ast.createParamsType({
|
|
510
|
+
variant: "reference",
|
|
511
|
+
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
512
|
+
}),
|
|
513
|
+
default: "{}"
|
|
514
|
+
})]
|
|
515
|
+
});
|
|
516
|
+
const clientCallStr = callPrinter$3.print(clientCallParamsNode) ?? "";
|
|
517
|
+
if (paramsToTrigger) {
|
|
518
|
+
const mutationArgTypeName = `${mutationKeyTypeName.replace("MutationKey", "")}MutationArg`;
|
|
519
|
+
const mutationArgParamsNode = buildMutationArgParams(node, {
|
|
520
|
+
paramsCasing,
|
|
521
|
+
resolver: tsResolver
|
|
522
|
+
});
|
|
523
|
+
const hasMutationParams = mutationArgParamsNode.params.length > 0;
|
|
524
|
+
const mutationArgDeclaration = hasMutationParams ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
|
|
525
|
+
const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
|
|
526
|
+
const paramsNode = getTriggerParams(node, {
|
|
527
|
+
dataReturnType,
|
|
528
|
+
resolver: tsResolver,
|
|
529
|
+
mutationKeyTypeName,
|
|
530
|
+
mutationArgTypeName
|
|
531
|
+
});
|
|
532
|
+
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
533
|
+
const generics = [
|
|
534
|
+
TData,
|
|
535
|
+
TError,
|
|
536
|
+
`${mutationKeyTypeName} | null`,
|
|
537
|
+
mutationArgTypeName
|
|
538
|
+
].filter(Boolean);
|
|
539
|
+
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, {
|
|
540
|
+
name: mutationArgTypeName,
|
|
541
|
+
isExportable: true,
|
|
542
|
+
isIndexable: true,
|
|
543
|
+
isTypeOnly: true,
|
|
544
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
545
|
+
name: mutationArgTypeName,
|
|
546
|
+
export: true,
|
|
547
|
+
children: hasMutationParams ? `{${mutationArgDeclaration}}` : "never"
|
|
548
|
+
})
|
|
549
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
550
|
+
name,
|
|
551
|
+
isExportable: true,
|
|
552
|
+
isIndexable: true,
|
|
553
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
554
|
+
name,
|
|
555
|
+
export: true,
|
|
556
|
+
params: paramsSignature,
|
|
557
|
+
JSDoc: { comments: getComments(node) },
|
|
558
|
+
children: `
|
|
559
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
560
|
+
const mutationKey = ${mutationKeyName}()
|
|
561
|
+
|
|
562
|
+
return useSWRMutation<${generics.join(", ")}>(
|
|
563
|
+
shouldFetch ? mutationKey : null,
|
|
564
|
+
async (_url${hasMutationParams ? `, { arg: { ${argKeysStr} } }` : ""}) => {
|
|
565
|
+
return ${clientName}(${clientCallStr})
|
|
566
|
+
},
|
|
567
|
+
mutationOptions
|
|
568
|
+
)
|
|
569
|
+
`
|
|
570
|
+
})
|
|
571
|
+
})] });
|
|
572
|
+
}
|
|
573
|
+
const generics = [
|
|
574
|
+
TData,
|
|
575
|
+
TError,
|
|
576
|
+
`${mutationKeyTypeName} | null`,
|
|
577
|
+
requestName
|
|
578
|
+
].filter(Boolean);
|
|
579
|
+
const paramsNode = getParams$3(node, {
|
|
580
|
+
paramsCasing,
|
|
581
|
+
pathParamsType,
|
|
582
|
+
dataReturnType,
|
|
583
|
+
resolver: tsResolver,
|
|
584
|
+
mutationKeyTypeName
|
|
585
|
+
});
|
|
586
|
+
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
587
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
588
|
+
name,
|
|
589
|
+
isExportable: true,
|
|
590
|
+
isIndexable: true,
|
|
591
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
592
|
+
name,
|
|
593
|
+
export: true,
|
|
594
|
+
params: paramsSignature,
|
|
595
|
+
JSDoc: { comments: getComments(node) },
|
|
596
|
+
children: `
|
|
597
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
598
|
+
const mutationKey = ${mutationKeyName}()
|
|
599
|
+
|
|
600
|
+
return useSWRMutation<${generics.join(", ")}>(
|
|
601
|
+
shouldFetch ? mutationKey : null,
|
|
602
|
+
async (_url${requestName ? ", { arg: data }" : ""}) => {
|
|
603
|
+
return ${clientName}(${clientCallStr})
|
|
604
|
+
},
|
|
605
|
+
mutationOptions
|
|
606
|
+
)
|
|
607
|
+
`
|
|
608
|
+
})
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region src/components/MutationKey.tsx
|
|
613
|
+
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
614
|
+
function getParams$2() {
|
|
615
|
+
return _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
616
|
+
}
|
|
617
|
+
__name(getParams$2, "getParams");
|
|
618
|
+
const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
|
|
619
|
+
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
620
|
+
}, "getTransformer");
|
|
621
|
+
function MutationKey({ name, paramsCasing, node, typeName, transformer = getTransformer$1 }) {
|
|
622
|
+
const paramsNode = getParams$2();
|
|
623
|
+
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
624
|
+
const keys = transformer({
|
|
625
|
+
node,
|
|
626
|
+
casing: paramsCasing
|
|
627
|
+
});
|
|
628
|
+
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, {
|
|
629
|
+
name,
|
|
630
|
+
isExportable: true,
|
|
631
|
+
isIndexable: true,
|
|
632
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
633
|
+
name,
|
|
634
|
+
export: true,
|
|
635
|
+
params: paramsSignature,
|
|
636
|
+
singleLine: true,
|
|
637
|
+
children: `[${keys.join(", ")}] as const`
|
|
638
|
+
})
|
|
639
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
640
|
+
name: typeName,
|
|
641
|
+
isExportable: true,
|
|
642
|
+
isIndexable: true,
|
|
643
|
+
isTypeOnly: true,
|
|
644
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
645
|
+
name: typeName,
|
|
646
|
+
export: true,
|
|
647
|
+
children: `ReturnType<typeof ${name}>`
|
|
648
|
+
})
|
|
649
|
+
})] });
|
|
650
|
+
}
|
|
651
|
+
MutationKey.getParams = getParams$2;
|
|
652
|
+
MutationKey.getTransformer = getTransformer$1;
|
|
653
|
+
//#endregion
|
|
654
|
+
//#region src/components/QueryKey.tsx
|
|
655
|
+
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
656
|
+
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
657
|
+
function getParams$1(node, options) {
|
|
658
|
+
return buildQueryKeyParams(node, options);
|
|
659
|
+
}
|
|
660
|
+
__name(getParams$1, "getParams");
|
|
661
|
+
const getTransformer = ({ node, casing }) => {
|
|
662
|
+
const path = new URLPath(node.path, { casing });
|
|
663
|
+
const hasQueryParams = node.parameters.some((p) => p.in === "query");
|
|
664
|
+
const hasRequestBody = !!node.requestBody?.schema;
|
|
665
|
+
return [
|
|
666
|
+
path.toObject({
|
|
667
|
+
type: "path",
|
|
668
|
+
stringify: true
|
|
669
|
+
}),
|
|
670
|
+
hasQueryParams ? "...(params ? [params] : [])" : void 0,
|
|
671
|
+
hasRequestBody ? "...(data ? [data] : [])" : void 0
|
|
672
|
+
].filter(Boolean);
|
|
673
|
+
};
|
|
674
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = getTransformer }) {
|
|
675
|
+
const paramsNode = getParams$1(node, {
|
|
676
|
+
pathParamsType,
|
|
677
|
+
paramsCasing,
|
|
678
|
+
resolver: tsResolver
|
|
679
|
+
});
|
|
680
|
+
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
681
|
+
const keys = transformer({
|
|
682
|
+
node,
|
|
683
|
+
casing: paramsCasing
|
|
684
|
+
});
|
|
685
|
+
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, {
|
|
686
|
+
name,
|
|
687
|
+
isExportable: true,
|
|
688
|
+
isIndexable: true,
|
|
689
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
690
|
+
name,
|
|
691
|
+
export: true,
|
|
692
|
+
params: paramsSignature,
|
|
693
|
+
singleLine: true,
|
|
694
|
+
children: `[${keys.join(", ")}] as const`
|
|
695
|
+
})
|
|
696
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
697
|
+
name: typeName,
|
|
698
|
+
isExportable: true,
|
|
699
|
+
isIndexable: true,
|
|
700
|
+
isTypeOnly: true,
|
|
701
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
702
|
+
name: typeName,
|
|
703
|
+
export: true,
|
|
704
|
+
children: `ReturnType<typeof ${name}>`
|
|
705
|
+
})
|
|
706
|
+
})] });
|
|
707
|
+
}
|
|
708
|
+
QueryKey.getParams = getParams$1;
|
|
709
|
+
QueryKey.getTransformer = getTransformer;
|
|
710
|
+
QueryKey.callPrinter = callPrinter$2;
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/components/QueryOptions.tsx
|
|
713
|
+
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
714
|
+
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
715
|
+
function getQueryOptionsParams(node, options) {
|
|
716
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
717
|
+
const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
|
|
718
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
719
|
+
paramsType,
|
|
720
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
721
|
+
paramsCasing,
|
|
722
|
+
resolver,
|
|
723
|
+
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
724
|
+
name: "config",
|
|
725
|
+
type: _kubb_core.ast.createParamsType({
|
|
726
|
+
variant: "reference",
|
|
727
|
+
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
728
|
+
}),
|
|
729
|
+
default: "{}"
|
|
730
|
+
})]
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
|
|
734
|
+
const paramsNode = getQueryOptionsParams(node, {
|
|
735
|
+
paramsType,
|
|
736
|
+
paramsCasing,
|
|
737
|
+
pathParamsType,
|
|
738
|
+
resolver: tsResolver
|
|
739
|
+
});
|
|
740
|
+
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
741
|
+
const paramsCall = callPrinter$1.print(paramsNode) ?? "";
|
|
742
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
743
|
+
name,
|
|
744
|
+
isExportable: true,
|
|
745
|
+
isIndexable: true,
|
|
746
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
747
|
+
name,
|
|
748
|
+
export: true,
|
|
749
|
+
params: paramsSignature,
|
|
750
|
+
children: `
|
|
751
|
+
return {
|
|
752
|
+
fetcher: async () => {
|
|
753
|
+
return ${clientName}(${paramsCall})
|
|
754
|
+
},
|
|
755
|
+
}
|
|
756
|
+
`
|
|
757
|
+
})
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/components/Query.tsx
|
|
762
|
+
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
763
|
+
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
764
|
+
function getParams(node, options) {
|
|
765
|
+
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
766
|
+
const responseName = resolver.resolveResponseName(node);
|
|
767
|
+
const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
|
|
768
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
769
|
+
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
770
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
771
|
+
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
772
|
+
name: "options",
|
|
773
|
+
type: _kubb_core.ast.createParamsType({
|
|
774
|
+
variant: "reference",
|
|
775
|
+
name: `{
|
|
776
|
+
query?: Parameters<typeof useSWR<${TData}, ${TError}>>[2],
|
|
777
|
+
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
778
|
+
shouldFetch?: boolean,
|
|
779
|
+
immutable?: boolean
|
|
780
|
+
}`
|
|
781
|
+
}),
|
|
782
|
+
default: "{}"
|
|
783
|
+
});
|
|
784
|
+
if (paramsType === "object") {
|
|
785
|
+
const baseParams = _kubb_core.ast.createOperationParams(node, {
|
|
786
|
+
paramsType: "object",
|
|
787
|
+
pathParamsType: "object",
|
|
788
|
+
paramsCasing,
|
|
789
|
+
resolver,
|
|
790
|
+
extraParams: []
|
|
791
|
+
});
|
|
792
|
+
return _kubb_core.ast.createFunctionParameters({ params: [...baseParams.params, optionsParam] });
|
|
793
|
+
}
|
|
794
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
795
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
796
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
797
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
798
|
+
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
799
|
+
const bodyType = node.requestBody?.schema ? _kubb_core.ast.createParamsType({
|
|
800
|
+
variant: "reference",
|
|
801
|
+
name: resolver.resolveDataName(node)
|
|
802
|
+
}) : void 0;
|
|
803
|
+
const bodyRequired = node.requestBody?.required ?? false;
|
|
804
|
+
const params = [];
|
|
805
|
+
if (pathParams.length) {
|
|
806
|
+
const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
|
|
807
|
+
name: p.name,
|
|
808
|
+
type: resolvePathParamType(node, p, resolver),
|
|
809
|
+
optional: !p.required
|
|
810
|
+
}));
|
|
811
|
+
params.push({
|
|
812
|
+
kind: "ParameterGroup",
|
|
813
|
+
properties: pathChildren,
|
|
814
|
+
inline: pathParamsType === "inline",
|
|
815
|
+
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
819
|
+
name: "data",
|
|
820
|
+
type: bodyType,
|
|
821
|
+
optional: !bodyRequired
|
|
822
|
+
}));
|
|
823
|
+
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
824
|
+
const headerGroupType = node.parameters.some((p) => p.in === "header") ? (() => {
|
|
825
|
+
const hParams = casedParams.filter((p) => p.in === "header");
|
|
826
|
+
const firstParam = hParams[0];
|
|
827
|
+
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
828
|
+
if (groupName !== resolver.resolveParamName(node, firstParam)) return {
|
|
829
|
+
type: _kubb_core.ast.createParamsType({
|
|
830
|
+
variant: "reference",
|
|
831
|
+
name: groupName
|
|
832
|
+
}),
|
|
833
|
+
optional: hParams.every((p) => !p.required)
|
|
834
|
+
};
|
|
835
|
+
})() : void 0;
|
|
836
|
+
params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
|
|
837
|
+
params.push(optionsParam);
|
|
838
|
+
return _kubb_core.ast.createFunctionParameters({ params });
|
|
839
|
+
}
|
|
840
|
+
function Query({ name, node, tsResolver, queryKeyName, queryKeyTypeName, queryOptionsName, dataReturnType, paramsType, paramsCasing, pathParamsType }) {
|
|
841
|
+
const responseName = tsResolver.resolveResponseName(node);
|
|
842
|
+
const errorNames = resolveErrorNames(node, tsResolver);
|
|
843
|
+
const generics = [
|
|
844
|
+
dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`,
|
|
845
|
+
`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
|
|
846
|
+
`${queryKeyTypeName} | null`
|
|
847
|
+
];
|
|
848
|
+
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
849
|
+
pathParamsType,
|
|
850
|
+
paramsCasing,
|
|
851
|
+
resolver: tsResolver
|
|
852
|
+
});
|
|
853
|
+
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
854
|
+
const paramsNode = getParams(node, {
|
|
855
|
+
paramsType,
|
|
856
|
+
paramsCasing,
|
|
857
|
+
pathParamsType,
|
|
858
|
+
dataReturnType,
|
|
859
|
+
resolver: tsResolver
|
|
860
|
+
});
|
|
861
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
862
|
+
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
863
|
+
paramsType,
|
|
864
|
+
paramsCasing,
|
|
865
|
+
pathParamsType,
|
|
866
|
+
resolver: tsResolver
|
|
867
|
+
});
|
|
868
|
+
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
869
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
870
|
+
name,
|
|
871
|
+
isExportable: true,
|
|
872
|
+
isIndexable: true,
|
|
873
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
874
|
+
name,
|
|
875
|
+
export: true,
|
|
876
|
+
params: paramsSignature,
|
|
877
|
+
JSDoc: { comments: getComments(node) },
|
|
878
|
+
children: `
|
|
879
|
+
const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
|
|
880
|
+
|
|
881
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
882
|
+
|
|
883
|
+
return useSWR<${generics.join(", ")}>(
|
|
884
|
+
shouldFetch ? queryKey : null,
|
|
885
|
+
{
|
|
886
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),
|
|
887
|
+
...(immutable ? {
|
|
888
|
+
revalidateIfStale: false,
|
|
889
|
+
revalidateOnFocus: false,
|
|
890
|
+
revalidateOnReconnect: false
|
|
891
|
+
} : { }),
|
|
892
|
+
...queryOptions
|
|
893
|
+
}
|
|
894
|
+
)
|
|
895
|
+
`
|
|
896
|
+
})
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
//#endregion
|
|
900
|
+
Object.defineProperty(exports, "Mutation", {
|
|
901
|
+
enumerable: true,
|
|
902
|
+
get: function() {
|
|
903
|
+
return Mutation;
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
Object.defineProperty(exports, "MutationKey", {
|
|
907
|
+
enumerable: true,
|
|
908
|
+
get: function() {
|
|
909
|
+
return MutationKey;
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
Object.defineProperty(exports, "Query", {
|
|
913
|
+
enumerable: true,
|
|
914
|
+
get: function() {
|
|
915
|
+
return Query;
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
Object.defineProperty(exports, "QueryKey", {
|
|
919
|
+
enumerable: true,
|
|
920
|
+
get: function() {
|
|
921
|
+
return QueryKey;
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
Object.defineProperty(exports, "QueryOptions", {
|
|
925
|
+
enumerable: true,
|
|
926
|
+
get: function() {
|
|
927
|
+
return QueryOptions;
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
Object.defineProperty(exports, "__name", {
|
|
931
|
+
enumerable: true,
|
|
932
|
+
get: function() {
|
|
933
|
+
return __name;
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
Object.defineProperty(exports, "__toESM", {
|
|
937
|
+
enumerable: true,
|
|
938
|
+
get: function() {
|
|
939
|
+
return __toESM;
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
Object.defineProperty(exports, "camelCase", {
|
|
943
|
+
enumerable: true,
|
|
944
|
+
get: function() {
|
|
945
|
+
return camelCase;
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
Object.defineProperty(exports, "transformName", {
|
|
949
|
+
enumerable: true,
|
|
950
|
+
get: function() {
|
|
951
|
+
return transformName;
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
//# sourceMappingURL=components-BJSzUg7M.cjs.map
|