@kubb/plugin-swr 5.0.0-beta.42 → 5.0.0-beta.64
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-CD7ZoS3B.cjs → components-DxWGjLWg.cjs} +231 -313
- package/dist/components-DxWGjLWg.cjs.map +1 -0
- package/dist/{components-BuLagnaM.js → components-mWBRE6E4.js} +232 -314
- package/dist/components-mWBRE6E4.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-D_Cz5DDw.cjs → generators-CJ4ziuNk.cjs} +66 -90
- package/dist/generators-CJ4ziuNk.cjs.map +1 -0
- package/dist/{generators-CSinCSzM.js → generators-D2blgLOY.js} +67 -91
- package/dist/generators-D2blgLOY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +6 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +68 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-BoANASs2.d.ts → types-DcBaH0gA.d.ts} +13 -16
- package/package.json +10 -18
- package/dist/components-BuLagnaM.js.map +0 -1
- package/dist/components-CD7ZoS3B.cjs.map +0 -1
- package/dist/generators-CSinCSzM.js.map +0 -1
- package/dist/generators-D_Cz5DDw.cjs.map +0 -1
- package/extension.yaml +0 -199
- 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 -74
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -2
- package/src/generators/mutationGenerator.tsx +0 -162
- package/src/generators/queryGenerator.tsx +0 -174
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -154
- package/src/resolvers/resolverSwr.ts +0 -56
- package/src/types.ts +0 -197
- package/src/utils.ts +0 -10
|
@@ -25,6 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
27
|
let _kubb_core = require("@kubb/core");
|
|
28
|
+
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
28
29
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
29
30
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
30
31
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
@@ -39,35 +40,19 @@ let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
|
39
40
|
function toCamelOrPascal(text, pascal) {
|
|
40
41
|
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
42
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
42
|
-
|
|
43
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
43
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
44
44
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
45
45
|
}
|
|
46
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
47
|
* Converts `text` to camelCase.
|
|
60
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
61
48
|
*
|
|
62
|
-
* @example
|
|
63
|
-
* camelCase('hello-world')
|
|
64
|
-
*
|
|
49
|
+
* @example Word boundaries
|
|
50
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
51
|
+
*
|
|
52
|
+
* @example With a prefix
|
|
53
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
65
54
|
*/
|
|
66
|
-
function camelCase(text, {
|
|
67
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
68
|
-
prefix,
|
|
69
|
-
suffix
|
|
70
|
-
} : {}));
|
|
55
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
71
56
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
72
57
|
}
|
|
73
58
|
//#endregion
|
|
@@ -174,99 +159,80 @@ function isValidVarName(name) {
|
|
|
174
159
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
175
160
|
}
|
|
176
161
|
//#endregion
|
|
177
|
-
//#region ../../internals/utils/src/
|
|
162
|
+
//#region ../../internals/utils/src/url.ts
|
|
163
|
+
function transformParam(raw, casing) {
|
|
164
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
165
|
+
return casing === "camelcase" ? camelCase(param) : param;
|
|
166
|
+
}
|
|
167
|
+
function toParamsObject(path, { replacer, casing } = {}) {
|
|
168
|
+
const params = {};
|
|
169
|
+
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
170
|
+
const param = transformParam(match[1], casing);
|
|
171
|
+
const key = replacer ? replacer(param) : param;
|
|
172
|
+
params[key] = key;
|
|
173
|
+
}
|
|
174
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
175
|
+
}
|
|
178
176
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* const p = new URLPath('/pet/{petId}')
|
|
183
|
-
* p.URL // '/pet/:petId'
|
|
184
|
-
* p.template // '`/pet/${petId}`'
|
|
177
|
+
* Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
|
|
185
178
|
*/
|
|
186
|
-
var
|
|
179
|
+
var Url = class Url {
|
|
187
180
|
/**
|
|
188
|
-
*
|
|
189
|
-
*/
|
|
190
|
-
path;
|
|
191
|
-
#options;
|
|
192
|
-
constructor(path, options = {}) {
|
|
193
|
-
this.path = path;
|
|
194
|
-
this.#options = options;
|
|
195
|
-
}
|
|
196
|
-
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
181
|
+
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
197
182
|
*
|
|
198
183
|
* @example
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* ```
|
|
184
|
+
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
185
|
+
* Url.canParse('/pet/{petId}') // false
|
|
202
186
|
*/
|
|
203
|
-
|
|
204
|
-
return
|
|
187
|
+
static canParse(url, base) {
|
|
188
|
+
return URL.canParse(url, base);
|
|
205
189
|
}
|
|
206
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
207
192
|
*
|
|
208
193
|
* @example
|
|
209
|
-
*
|
|
210
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
211
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
212
|
-
* ```
|
|
194
|
+
* Url.toPath('/pet/{petId}') // '/pet/:petId'
|
|
213
195
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return !!new URL(this.path).href;
|
|
217
|
-
} catch {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
196
|
+
static toPath(path) {
|
|
197
|
+
return path.replace(/\{([^}]+)\}/g, ":$1");
|
|
220
198
|
}
|
|
221
199
|
/**
|
|
222
|
-
* Converts
|
|
200
|
+
* Converts an OpenAPI/Swagger path to a TypeScript template literal string.
|
|
201
|
+
* `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
|
|
202
|
+
* and `casing` controls parameter identifier casing.
|
|
223
203
|
*
|
|
224
204
|
* @example
|
|
225
|
-
*
|
|
226
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
227
|
-
*/
|
|
228
|
-
get template() {
|
|
229
|
-
return this.toTemplateString();
|
|
230
|
-
}
|
|
231
|
-
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
205
|
+
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
232
206
|
*
|
|
233
207
|
* @example
|
|
234
|
-
*
|
|
235
|
-
* new URLPath('/pet/{petId}').object
|
|
236
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
237
|
-
* ```
|
|
208
|
+
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
238
209
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
210
|
+
static toTemplateString(path, { prefix, replacer, casing } = {}) {
|
|
211
|
+
const result = path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
212
|
+
if (i % 2 === 0) return part;
|
|
213
|
+
const param = transformParam(part, casing);
|
|
214
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
215
|
+
}).join("");
|
|
216
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
241
217
|
}
|
|
242
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
220
|
+
* expression when `stringify` is set.
|
|
243
221
|
*
|
|
244
222
|
* @example
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* new URLPath('/pet').params // null
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
get params() {
|
|
251
|
-
return this.toParamsObject();
|
|
252
|
-
}
|
|
253
|
-
#transformParam(raw) {
|
|
254
|
-
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
255
|
-
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
223
|
+
* Url.toObject('/pet/{petId}')
|
|
224
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
259
225
|
*/
|
|
260
|
-
|
|
261
|
-
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
262
|
-
const raw = match[1];
|
|
263
|
-
fn(raw, this.#transformParam(raw));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
226
|
+
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
267
227
|
const object = {
|
|
268
|
-
url: type === "path" ?
|
|
269
|
-
|
|
228
|
+
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
229
|
+
replacer,
|
|
230
|
+
casing
|
|
231
|
+
}),
|
|
232
|
+
params: toParamsObject(path, {
|
|
233
|
+
replacer,
|
|
234
|
+
casing
|
|
235
|
+
})
|
|
270
236
|
};
|
|
271
237
|
if (stringify) {
|
|
272
238
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -275,85 +241,13 @@ var URLPath = class {
|
|
|
275
241
|
}
|
|
276
242
|
return object;
|
|
277
243
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
280
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
281
|
-
*
|
|
282
|
-
* @example
|
|
283
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
284
|
-
*/
|
|
285
|
-
toTemplateString({ prefix, replacer } = {}) {
|
|
286
|
-
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
287
|
-
if (i % 2 === 0) return part;
|
|
288
|
-
const param = this.#transformParam(part);
|
|
289
|
-
return `\${${replacer ? replacer(param) : param}}`;
|
|
290
|
-
}).join("");
|
|
291
|
-
return `\`${prefix ?? ""}${result}\``;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
295
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
296
|
-
* Returns `undefined` when no path parameters are found.
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```ts
|
|
300
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
301
|
-
* // { petId: 'petId', tagId: 'tagId' }
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
toParamsObject(replacer) {
|
|
305
|
-
const params = {};
|
|
306
|
-
this.#eachParam((_raw, param) => {
|
|
307
|
-
const key = replacer ? replacer(param) : param;
|
|
308
|
-
params[key] = key;
|
|
309
|
-
});
|
|
310
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
311
|
-
}
|
|
312
|
-
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* ```ts
|
|
316
|
-
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
toURLPath() {
|
|
320
|
-
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
321
|
-
}
|
|
322
244
|
};
|
|
323
245
|
//#endregion
|
|
324
|
-
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
325
|
-
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
326
|
-
const mutationKeyTransformer = ({ node, casing }) => {
|
|
327
|
-
if (!node.path) return [];
|
|
328
|
-
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
329
|
-
};
|
|
330
|
-
function MutationKey$1({ name, paramsCasing, node, transformer }) {
|
|
331
|
-
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
332
|
-
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
333
|
-
const keys = (transformer ?? mutationKeyTransformer)({
|
|
334
|
-
node,
|
|
335
|
-
casing: paramsCasing
|
|
336
|
-
});
|
|
337
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
338
|
-
name,
|
|
339
|
-
isExportable: true,
|
|
340
|
-
isIndexable: true,
|
|
341
|
-
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
342
|
-
name,
|
|
343
|
-
export: true,
|
|
344
|
-
params: paramsSignature,
|
|
345
|
-
singleLine: true,
|
|
346
|
-
children: `[${keys.join(", ")}] as const`
|
|
347
|
-
})
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
__name(MutationKey$1, "MutationKey");
|
|
351
|
-
//#endregion
|
|
352
246
|
//#region ../../internals/shared/src/operation.ts
|
|
353
247
|
function getOperationLink(node, link) {
|
|
354
248
|
if (!link) return null;
|
|
355
249
|
if (typeof link === "function") return link(node) ?? null;
|
|
356
|
-
if (link === "urlPath") return node.path ? `{@link ${
|
|
250
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
357
251
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
358
252
|
}
|
|
359
253
|
function getContentTypeInfo(node) {
|
|
@@ -390,7 +284,7 @@ function buildOperationComments(node, options = {}) {
|
|
|
390
284
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
391
285
|
}
|
|
392
286
|
function getOperationParameters(node, options = {}) {
|
|
393
|
-
const params =
|
|
287
|
+
const params = (0, _kubb_ast_utils.caseParams)(node.parameters, options.paramsCasing);
|
|
394
288
|
return {
|
|
395
289
|
path: params.filter((param) => param.in === "path"),
|
|
396
290
|
query: params.filter((param) => param.in === "query"),
|
|
@@ -412,6 +306,19 @@ function resolveErrorNames(node, resolver) {
|
|
|
412
306
|
function resolveStatusCodeNames(node, resolver) {
|
|
413
307
|
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
414
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Builds the discriminated union type string for `dataReturnType: 'full'` return shapes.
|
|
311
|
+
* Each member is `{ status: N; data: StatusNType; statusText: string }`.
|
|
312
|
+
*/
|
|
313
|
+
function buildStatusUnionType(node, resolver) {
|
|
314
|
+
const members = node.responses.map((r) => {
|
|
315
|
+
const typeName = resolver.resolveResponseStatusName(node, r.statusCode);
|
|
316
|
+
const statusCode = Number.parseInt(r.statusCode, 10);
|
|
317
|
+
return `{ status: ${Number.isNaN(statusCode) ? "number" : String(statusCode)}; data: ${typeName}; statusText: string }`;
|
|
318
|
+
});
|
|
319
|
+
if (members.length === 1) return members[0];
|
|
320
|
+
return `(${members.join(" | ")})`;
|
|
321
|
+
}
|
|
415
322
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
416
323
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
417
324
|
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
@@ -445,118 +352,156 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
445
352
|
return result;
|
|
446
353
|
}
|
|
447
354
|
//#endregion
|
|
355
|
+
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
356
|
+
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
357
|
+
const mutationKeyTransformer = ({ node }) => {
|
|
358
|
+
if (!node.path) return [];
|
|
359
|
+
return [`{ url: '${Url.toPath(node.path)}' }`];
|
|
360
|
+
};
|
|
361
|
+
function MutationKey$1({ name, paramsCasing, node, transformer }) {
|
|
362
|
+
const paramsNode = _kubb_core.ast.factory.createFunctionParameters({ params: [] });
|
|
363
|
+
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
364
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
365
|
+
node,
|
|
366
|
+
casing: paramsCasing
|
|
367
|
+
});
|
|
368
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
369
|
+
name,
|
|
370
|
+
isExportable: true,
|
|
371
|
+
isIndexable: true,
|
|
372
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
373
|
+
name,
|
|
374
|
+
export: true,
|
|
375
|
+
params: paramsSignature,
|
|
376
|
+
singleLine: true,
|
|
377
|
+
children: `[${keys.join(", ")}] as const`
|
|
378
|
+
})
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
__name(MutationKey$1, "MutationKey");
|
|
382
|
+
//#endregion
|
|
448
383
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
449
384
|
/**
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
385
|
+
* Returns the `TypeLiteral` members of a destructured group parameter, or `null`
|
|
386
|
+
* for a plain named parameter.
|
|
453
387
|
*/
|
|
454
|
-
function
|
|
455
|
-
if (
|
|
456
|
-
return
|
|
388
|
+
function groupMembers(param) {
|
|
389
|
+
if (typeof param.name === "string") return null;
|
|
390
|
+
return param.type && typeof param.type !== "string" && param.type.kind === "TypeLiteral" ? param.type.members : [];
|
|
457
391
|
}
|
|
458
392
|
/**
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* - When they match (v5 default) → `TypeName` (direct reference).
|
|
393
|
+
* Builds the shared `(…params, config = {})` parameter list for a TanStack
|
|
394
|
+
* query-options function. The trailing `config` parameter is typed as a partial
|
|
395
|
+
* `RequestConfig` with an optional `client`. Framework plugins wrap the result
|
|
396
|
+
* when needed, for example vue-query applies `MaybeRefOrGetter`.
|
|
464
397
|
*/
|
|
465
|
-
function
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
398
|
+
function buildQueryOptionsParams(node, options) {
|
|
399
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
400
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
401
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
402
|
+
paramsType,
|
|
403
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
404
|
+
paramsCasing,
|
|
405
|
+
resolver,
|
|
406
|
+
extraParams: [_kubb_core.ast.factory.createFunctionParameter({
|
|
407
|
+
name: "config",
|
|
408
|
+
type: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
409
|
+
default: "{}"
|
|
410
|
+
})]
|
|
476
411
|
});
|
|
477
412
|
}
|
|
478
413
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* equals the individual param name (no real group).
|
|
414
|
+
* Returns `'zod'` when response-direction parsing is enabled.
|
|
415
|
+
* The string shorthand `'zod'` also enables response parsing.
|
|
482
416
|
*/
|
|
483
|
-
function
|
|
484
|
-
if (!
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
488
|
-
return {
|
|
489
|
-
type: _kubb_core.ast.createParamsType({
|
|
490
|
-
variant: "reference",
|
|
491
|
-
name: groupName
|
|
492
|
-
}),
|
|
493
|
-
optional: params.every((p) => !p.required)
|
|
494
|
-
};
|
|
417
|
+
function resolveResponseParser(parser) {
|
|
418
|
+
if (!parser) return null;
|
|
419
|
+
if (parser === "zod") return "zod";
|
|
420
|
+
return parser.response ?? null;
|
|
495
421
|
}
|
|
496
422
|
/**
|
|
497
|
-
*
|
|
423
|
+
* Returns `'zod'` when request body parsing is enabled.
|
|
424
|
+
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
498
425
|
*/
|
|
499
|
-
function
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return [];
|
|
426
|
+
function resolveRequestParser(parser) {
|
|
427
|
+
if (!parser) return null;
|
|
428
|
+
if (parser === "zod") return "zod";
|
|
429
|
+
return parser.request ?? null;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Returns `'zod'` when query-params parsing is enabled.
|
|
433
|
+
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
434
|
+
*/
|
|
435
|
+
function resolveQueryParamsParser(parser) {
|
|
436
|
+
if (!parser || parser === "zod") return null;
|
|
437
|
+
return parser.request ?? null;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
441
|
+
*
|
|
442
|
+
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
443
|
+
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
444
|
+
* - `parser: { response: 'zod' }`: response name only.
|
|
445
|
+
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
446
|
+
*
|
|
447
|
+
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
448
|
+
*/
|
|
449
|
+
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
450
|
+
if (!zodResolver || !parser) return [];
|
|
451
|
+
const { query: queryParams } = getOperationParameters(node);
|
|
452
|
+
return [
|
|
453
|
+
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
454
|
+
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
455
|
+
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
456
|
+
].filter((n) => Boolean(n));
|
|
524
457
|
}
|
|
525
458
|
/**
|
|
526
459
|
* Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
|
|
527
460
|
*/
|
|
528
461
|
function buildQueryKeyParams(node, options) {
|
|
529
462
|
const { pathParamsType, paramsCasing, resolver } = options;
|
|
530
|
-
const casedParams =
|
|
463
|
+
const casedParams = (0, _kubb_ast_utils.caseParams)(node.parameters, paramsCasing);
|
|
531
464
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
532
465
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
533
|
-
const queryGroupType =
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
466
|
+
const queryGroupType = (0, _kubb_ast_utils.resolveGroupType)({
|
|
467
|
+
node,
|
|
468
|
+
params: queryParams,
|
|
469
|
+
group: "query",
|
|
470
|
+
resolver
|
|
471
|
+
});
|
|
472
|
+
const bodyType = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
538
473
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
539
474
|
const params = [];
|
|
540
475
|
if (pathParams.length) {
|
|
541
|
-
const pathChildren = pathParams.map((p) =>
|
|
476
|
+
const pathChildren = pathParams.map((p) => ({
|
|
542
477
|
name: p.name,
|
|
543
|
-
type:
|
|
478
|
+
type: (0, _kubb_ast_utils.resolveParamType)({
|
|
479
|
+
node,
|
|
480
|
+
param: p,
|
|
481
|
+
resolver
|
|
482
|
+
}),
|
|
544
483
|
optional: !p.required
|
|
545
484
|
}));
|
|
546
|
-
params.push({
|
|
547
|
-
kind: "ParameterGroup",
|
|
485
|
+
if (pathParamsType === "object") params.push(_kubb_core.ast.factory.createFunctionParameter({
|
|
548
486
|
properties: pathChildren,
|
|
549
|
-
inline: pathParamsType === "inline",
|
|
550
487
|
default: pathChildren.every((c) => c.optional) ? "{}" : void 0
|
|
551
|
-
});
|
|
488
|
+
}));
|
|
489
|
+
else params.push(...pathChildren.map((child) => _kubb_core.ast.factory.createFunctionParameter(child)));
|
|
552
490
|
}
|
|
553
|
-
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
491
|
+
if (bodyType) params.push(_kubb_core.ast.factory.createFunctionParameter({
|
|
554
492
|
name: "data",
|
|
555
493
|
type: bodyType,
|
|
556
494
|
optional: !bodyRequired
|
|
557
495
|
}));
|
|
558
|
-
params.push(...
|
|
559
|
-
|
|
496
|
+
params.push(...(0, _kubb_ast_utils.buildGroupParam)({
|
|
497
|
+
name: "params",
|
|
498
|
+
node,
|
|
499
|
+
params: queryParams,
|
|
500
|
+
groupType: queryGroupType,
|
|
501
|
+
resolver,
|
|
502
|
+
wrapType: (type) => type
|
|
503
|
+
}));
|
|
504
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params });
|
|
560
505
|
}
|
|
561
506
|
/**
|
|
562
507
|
* Collect the names of the required params (no default) that drive the `enabled`
|
|
@@ -565,12 +510,11 @@ function buildQueryKeyParams(node, options) {
|
|
|
565
510
|
*/
|
|
566
511
|
function getEnabledParamNames(paramsNode) {
|
|
567
512
|
const required = [];
|
|
568
|
-
for (const param of paramsNode.params)
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
513
|
+
for (const param of paramsNode.params) {
|
|
514
|
+
const members = groupMembers(param);
|
|
515
|
+
if (members) {
|
|
516
|
+
for (const member of members) if (!member.optional) required.push(member.name);
|
|
517
|
+
} else if (typeof param.name === "string" && !param.optional && param.default === void 0) required.push(param.name);
|
|
574
518
|
}
|
|
575
519
|
return required;
|
|
576
520
|
}
|
|
@@ -586,27 +530,25 @@ function markParamsOptional(paramsNode, names) {
|
|
|
586
530
|
if (names.length === 0) return paramsNode;
|
|
587
531
|
const nameSet = new Set(names);
|
|
588
532
|
const params = paramsNode.params.map((param) => {
|
|
589
|
-
|
|
590
|
-
|
|
533
|
+
const members = groupMembers(param);
|
|
534
|
+
if (members) {
|
|
535
|
+
const next = members.map((member) => nameSet.has(member.name) ? {
|
|
536
|
+
...member,
|
|
537
|
+
optional: true
|
|
538
|
+
} : member);
|
|
591
539
|
return {
|
|
592
|
-
...
|
|
593
|
-
|
|
594
|
-
name: child.name,
|
|
595
|
-
type: child.type,
|
|
596
|
-
rest: child.rest,
|
|
597
|
-
optional: true
|
|
598
|
-
}) : child)
|
|
540
|
+
...param,
|
|
541
|
+
type: _kubb_core.ast.factory.createTypeLiteral({ members: next })
|
|
599
542
|
};
|
|
600
543
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
rest: fp.rest,
|
|
544
|
+
return typeof param.name === "string" && nameSet.has(param.name) ? _kubb_core.ast.factory.createFunctionParameter({
|
|
545
|
+
name: param.name,
|
|
546
|
+
type: param.type,
|
|
547
|
+
rest: param.rest,
|
|
606
548
|
optional: true
|
|
607
|
-
}) :
|
|
549
|
+
}) : param;
|
|
608
550
|
});
|
|
609
|
-
return _kubb_core.ast.createFunctionParameters({ params });
|
|
551
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params });
|
|
610
552
|
}
|
|
611
553
|
/**
|
|
612
554
|
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
@@ -633,13 +575,13 @@ function injectNonNullAssertions(callStr, names) {
|
|
|
633
575
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
634
576
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
635
577
|
if (!node.path) return [];
|
|
636
|
-
const path = new URLPath(node.path, { casing });
|
|
637
578
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
638
579
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
639
580
|
return [
|
|
640
|
-
|
|
581
|
+
Url.toObject(node.path, {
|
|
641
582
|
type: "path",
|
|
642
|
-
stringify: true
|
|
583
|
+
stringify: true,
|
|
584
|
+
casing
|
|
643
585
|
}),
|
|
644
586
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
645
587
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -681,9 +623,9 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
681
623
|
//#region src/components/Mutation.tsx
|
|
682
624
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
683
625
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
684
|
-
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "
|
|
626
|
+
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
685
627
|
function createMutationArgParams(node, options) {
|
|
686
|
-
return
|
|
628
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
687
629
|
paramsType: "inline",
|
|
688
630
|
pathParamsType: "inline",
|
|
689
631
|
paramsCasing: options.paramsCasing,
|
|
@@ -694,25 +636,22 @@ function buildMutationParamsNode(node, options) {
|
|
|
694
636
|
const { dataReturnType, mutationKeyTypeName, mutationArgTypeName, resolver } = options;
|
|
695
637
|
const responseName = resolver.resolveResponseName(node);
|
|
696
638
|
const errorNames = resolveErrorNames(node, resolver);
|
|
697
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
639
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
698
640
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
699
|
-
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
641
|
+
return _kubb_core.ast.factory.createFunctionParameters({ params: [_kubb_core.ast.factory.createFunctionParameter({
|
|
700
642
|
name: "options",
|
|
701
|
-
type:
|
|
702
|
-
variant: "reference",
|
|
703
|
-
name: `{
|
|
643
|
+
type: `{
|
|
704
644
|
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
|
|
705
645
|
client?: ${buildRequestConfigType(node, resolver)},
|
|
706
646
|
shouldFetch?: boolean,
|
|
707
|
-
}
|
|
708
|
-
}),
|
|
647
|
+
}`,
|
|
709
648
|
default: "{}"
|
|
710
649
|
})] });
|
|
711
650
|
}
|
|
712
651
|
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
713
652
|
const responseName = tsResolver.resolveResponseName(node);
|
|
714
653
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
715
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
654
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
716
655
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
717
656
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
718
657
|
paramsCasing,
|
|
@@ -735,17 +674,14 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
735
674
|
resolver: tsResolver
|
|
736
675
|
});
|
|
737
676
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
738
|
-
const clientCallParamsNode =
|
|
677
|
+
const clientCallParamsNode = (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
739
678
|
paramsType,
|
|
740
679
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
741
680
|
paramsCasing,
|
|
742
681
|
resolver: tsResolver,
|
|
743
|
-
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
682
|
+
extraParams: [_kubb_core.ast.factory.createFunctionParameter({
|
|
744
683
|
name: "config",
|
|
745
|
-
type:
|
|
746
|
-
variant: "reference",
|
|
747
|
-
name: buildRequestConfigType(node, tsResolver)
|
|
748
|
-
}),
|
|
684
|
+
type: buildRequestConfigType(node, tsResolver),
|
|
749
685
|
default: "{}"
|
|
750
686
|
})]
|
|
751
687
|
});
|
|
@@ -810,22 +746,7 @@ function MutationKey({ name, typeName, node, paramsCasing, pathParamsType, trans
|
|
|
810
746
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
811
747
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
812
748
|
function getQueryOptionsParams(node, options) {
|
|
813
|
-
|
|
814
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
815
|
-
return _kubb_core.ast.createOperationParams(node, {
|
|
816
|
-
paramsType,
|
|
817
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
818
|
-
paramsCasing,
|
|
819
|
-
resolver,
|
|
820
|
-
extraParams: [_kubb_core.ast.createFunctionParameter({
|
|
821
|
-
name: "config",
|
|
822
|
-
type: _kubb_core.ast.createParamsType({
|
|
823
|
-
variant: "reference",
|
|
824
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
|
|
825
|
-
}),
|
|
826
|
-
default: "{}"
|
|
827
|
-
})]
|
|
828
|
-
});
|
|
749
|
+
return buildQueryOptionsParams(node, options);
|
|
829
750
|
}
|
|
830
751
|
function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
|
|
831
752
|
const enabledNames = getEnabledParamNames(buildQueryKeyParams(node, {
|
|
@@ -868,22 +789,19 @@ function buildQueryParamsNode(node, options) {
|
|
|
868
789
|
const responseName = resolver.resolveResponseName(node);
|
|
869
790
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
870
791
|
const errorNames = resolveErrorNames(node, resolver);
|
|
871
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
792
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
872
793
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
873
|
-
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
794
|
+
const optionsParam = _kubb_core.ast.factory.createFunctionParameter({
|
|
874
795
|
name: "options",
|
|
875
|
-
type:
|
|
876
|
-
variant: "reference",
|
|
877
|
-
name: `{
|
|
796
|
+
type: `{
|
|
878
797
|
query?: SWRConfiguration<${[TData, TError].join(", ")}>,
|
|
879
798
|
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
|
|
880
799
|
shouldFetch?: boolean,
|
|
881
800
|
immutable?: boolean
|
|
882
|
-
}
|
|
883
|
-
}),
|
|
801
|
+
}`,
|
|
884
802
|
default: "{}"
|
|
885
803
|
});
|
|
886
|
-
return
|
|
804
|
+
return (0, _kubb_ast_utils.createOperationParams)(node, {
|
|
887
805
|
paramsType,
|
|
888
806
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
889
807
|
paramsCasing,
|
|
@@ -895,7 +813,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
895
813
|
const responseName = tsResolver.resolveResponseName(node);
|
|
896
814
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
897
815
|
const generics = [
|
|
898
|
-
dataReturnType === "data" ? responseName :
|
|
816
|
+
dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver),
|
|
899
817
|
`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
|
|
900
818
|
`${queryKeyTypeName} | null`
|
|
901
819
|
];
|
|
@@ -1026,4 +944,4 @@ Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
|
1026
944
|
}
|
|
1027
945
|
});
|
|
1028
946
|
|
|
1029
|
-
//# sourceMappingURL=components-
|
|
947
|
+
//# sourceMappingURL=components-DxWGjLWg.cjs.map
|