@kubb/plugin-swr 5.0.0-beta.42 → 5.0.0-beta.56
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-C8FJ3-Cb.cjs} +175 -196
- package/dist/components-C8FJ3-Cb.cjs.map +1 -0
- package/dist/{components-BuLagnaM.js → components-CR9NLFcO.js} +176 -197
- package/dist/components-CR9NLFcO.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-CSinCSzM.js → generators-BB6csINY.js} +67 -91
- package/dist/generators-BB6csINY.js.map +1 -0
- package/dist/{generators-D_Cz5DDw.cjs → generators-mw3FvFJD.cjs} +66 -90
- package/dist/generators-mw3FvFJD.cjs.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 +62 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +63 -13
- package/dist/index.js.map +1 -1
- package/dist/{types-BoANASs2.d.ts → types-Dz_j0Bqv.d.ts} +11 -14
- package/package.json +9 -17
- package/src/components/Mutation.tsx +3 -3
- package/src/components/Query.tsx +3 -3
- package/src/components/QueryOptions.tsx +3 -21
- package/src/generators/mutationGenerator.tsx +11 -7
- package/src/generators/queryGenerator.tsx +3 -7
- package/src/plugin.ts +6 -18
- package/src/resolvers/resolverSwr.ts +2 -2
- package/src/types.ts +9 -12
- package/src/utils.ts +8 -1
- 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
|
@@ -39,35 +39,19 @@ let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
|
39
39
|
function toCamelOrPascal(text, pascal) {
|
|
40
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
41
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
42
|
-
|
|
43
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
42
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
44
43
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
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
46
|
* Converts `text` to camelCase.
|
|
60
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
61
47
|
*
|
|
62
|
-
* @example
|
|
63
|
-
* camelCase('hello-world')
|
|
64
|
-
*
|
|
48
|
+
* @example Word boundaries
|
|
49
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
50
|
+
*
|
|
51
|
+
* @example With a prefix
|
|
52
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
65
53
|
*/
|
|
66
|
-
function camelCase(text, {
|
|
67
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
68
|
-
prefix,
|
|
69
|
-
suffix
|
|
70
|
-
} : {}));
|
|
54
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
71
55
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
72
56
|
}
|
|
73
57
|
//#endregion
|
|
@@ -174,99 +158,80 @@ function isValidVarName(name) {
|
|
|
174
158
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
175
159
|
}
|
|
176
160
|
//#endregion
|
|
177
|
-
//#region ../../internals/utils/src/
|
|
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
|
+
}
|
|
178
175
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* const p = new URLPath('/pet/{petId}')
|
|
183
|
-
* p.URL // '/pet/:petId'
|
|
184
|
-
* p.template // '`/pet/${petId}`'
|
|
176
|
+
* Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
|
|
185
177
|
*/
|
|
186
|
-
var
|
|
178
|
+
var Url = class Url {
|
|
187
179
|
/**
|
|
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`.
|
|
180
|
+
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
197
181
|
*
|
|
198
182
|
* @example
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* ```
|
|
183
|
+
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
184
|
+
* Url.canParse('/pet/{petId}') // false
|
|
202
185
|
*/
|
|
203
|
-
|
|
204
|
-
return
|
|
186
|
+
static canParse(url, base) {
|
|
187
|
+
return URL.canParse(url, base);
|
|
205
188
|
}
|
|
206
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
207
191
|
*
|
|
208
192
|
* @example
|
|
209
|
-
*
|
|
210
|
-
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
211
|
-
* new URLPath('/pet/{petId}').isURL // false
|
|
212
|
-
* ```
|
|
193
|
+
* Url.toPath('/pet/{petId}') // '/pet/:petId'
|
|
213
194
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return !!new URL(this.path).href;
|
|
217
|
-
} catch {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
195
|
+
static toPath(path) {
|
|
196
|
+
return path.replace(/\{([^}]+)\}/g, ":$1");
|
|
220
197
|
}
|
|
221
198
|
/**
|
|
222
|
-
* Converts
|
|
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.
|
|
223
202
|
*
|
|
224
203
|
* @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.
|
|
204
|
+
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
232
205
|
*
|
|
233
206
|
* @example
|
|
234
|
-
*
|
|
235
|
-
* new URLPath('/pet/{petId}').object
|
|
236
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
237
|
-
* ```
|
|
207
|
+
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
238
208
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
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}\``;
|
|
241
216
|
}
|
|
242
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
219
|
+
* expression when `stringify` is set.
|
|
243
220
|
*
|
|
244
221
|
* @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.
|
|
222
|
+
* Url.toObject('/pet/{petId}')
|
|
223
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
259
224
|
*/
|
|
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 } = {}) {
|
|
225
|
+
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
267
226
|
const object = {
|
|
268
|
-
url: type === "path" ?
|
|
269
|
-
|
|
227
|
+
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
228
|
+
replacer,
|
|
229
|
+
casing
|
|
230
|
+
}),
|
|
231
|
+
params: toParamsObject(path, {
|
|
232
|
+
replacer,
|
|
233
|
+
casing
|
|
234
|
+
})
|
|
270
235
|
};
|
|
271
236
|
if (stringify) {
|
|
272
237
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -275,85 +240,13 @@ var URLPath = class {
|
|
|
275
240
|
}
|
|
276
241
|
return object;
|
|
277
242
|
}
|
|
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
243
|
};
|
|
323
244
|
//#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
245
|
//#region ../../internals/shared/src/operation.ts
|
|
353
246
|
function getOperationLink(node, link) {
|
|
354
247
|
if (!link) return null;
|
|
355
248
|
if (typeof link === "function") return link(node) ?? null;
|
|
356
|
-
if (link === "urlPath") return node.path ? `{@link ${
|
|
249
|
+
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
357
250
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
358
251
|
}
|
|
359
252
|
function getContentTypeInfo(node) {
|
|
@@ -412,6 +305,19 @@ function resolveErrorNames(node, resolver) {
|
|
|
412
305
|
function resolveStatusCodeNames(node, resolver) {
|
|
413
306
|
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
414
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
|
+
}
|
|
415
321
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
416
322
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
417
323
|
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
@@ -445,15 +351,103 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
445
351
|
return result;
|
|
446
352
|
}
|
|
447
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
|
|
448
382
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
449
383
|
/**
|
|
450
|
-
*
|
|
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.
|
|
451
435
|
*
|
|
452
|
-
*
|
|
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.
|
|
453
442
|
*/
|
|
454
|
-
function resolveZodSchemaNames(node, zodResolver) {
|
|
455
|
-
if (!zodResolver) return [];
|
|
456
|
-
|
|
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));
|
|
457
451
|
}
|
|
458
452
|
/**
|
|
459
453
|
* Resolve the type for a single path parameter.
|
|
@@ -633,13 +627,13 @@ function injectNonNullAssertions(callStr, names) {
|
|
|
633
627
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
634
628
|
const queryKeyTransformer = ({ node, casing }) => {
|
|
635
629
|
if (!node.path) return [];
|
|
636
|
-
const path = new URLPath(node.path, { casing });
|
|
637
630
|
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
638
631
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
639
632
|
return [
|
|
640
|
-
|
|
633
|
+
Url.toObject(node.path, {
|
|
641
634
|
type: "path",
|
|
642
|
-
stringify: true
|
|
635
|
+
stringify: true,
|
|
636
|
+
casing
|
|
643
637
|
}),
|
|
644
638
|
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
645
639
|
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
@@ -694,7 +688,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
694
688
|
const { dataReturnType, mutationKeyTypeName, mutationArgTypeName, resolver } = options;
|
|
695
689
|
const responseName = resolver.resolveResponseName(node);
|
|
696
690
|
const errorNames = resolveErrorNames(node, resolver);
|
|
697
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
691
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
698
692
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
699
693
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
700
694
|
name: "options",
|
|
@@ -712,7 +706,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
712
706
|
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
713
707
|
const responseName = tsResolver.resolveResponseName(node);
|
|
714
708
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
715
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
709
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
|
|
716
710
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
717
711
|
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
718
712
|
paramsCasing,
|
|
@@ -810,22 +804,7 @@ function MutationKey({ name, typeName, node, paramsCasing, pathParamsType, trans
|
|
|
810
804
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
811
805
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
812
806
|
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
|
-
});
|
|
807
|
+
return buildQueryOptionsParams(node, options);
|
|
829
808
|
}
|
|
830
809
|
function QueryOptions({ name, clientName, node, tsResolver, paramsCasing, paramsType, pathParamsType }) {
|
|
831
810
|
const enabledNames = getEnabledParamNames(buildQueryKeyParams(node, {
|
|
@@ -868,7 +847,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
868
847
|
const responseName = resolver.resolveResponseName(node);
|
|
869
848
|
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
870
849
|
const errorNames = resolveErrorNames(node, resolver);
|
|
871
|
-
const TData = dataReturnType === "data" ? responseName :
|
|
850
|
+
const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
|
|
872
851
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
873
852
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
874
853
|
name: "options",
|
|
@@ -895,7 +874,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
895
874
|
const responseName = tsResolver.resolveResponseName(node);
|
|
896
875
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
897
876
|
const generics = [
|
|
898
|
-
dataReturnType === "data" ? responseName :
|
|
877
|
+
dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver),
|
|
899
878
|
`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
|
|
900
879
|
`${queryKeyTypeName} | null`
|
|
901
880
|
];
|
|
@@ -1026,4 +1005,4 @@ Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
|
1026
1005
|
}
|
|
1027
1006
|
});
|
|
1028
1007
|
|
|
1029
|
-
//# sourceMappingURL=components-
|
|
1008
|
+
//# sourceMappingURL=components-C8FJ3-Cb.cjs.map
|