@kubb/plugin-fetch 5.10.0-canary.20261025T201031 → 5.10.1
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/index.cjs +89 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +85 -114
- package/dist/index.js.map +1 -1
- package/dist/templates/fetch.d.ts +1 -3
- package/dist/templates/serializers.d.ts +1 -3
- package/dist/templates/standardSchema.d.ts +1 -3
- package/kubb-extension.json +1 -1
- package/package.json +7 -7
- package/templates/fetch.ts +1 -1
- package/templates/serializers.ts +5 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
2
|
import "@kubb/plugin-zod";
|
|
3
3
|
import "@kubb/plugin-ts";
|
|
4
|
-
//#region ../../internals/client/src/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Validator applied to the request and response using schemas from `@kubb/plugin-zod`.
|
|
7
6
|
* - `false`: no validation.
|
|
@@ -181,8 +180,6 @@ type ResolvedOptions = {
|
|
|
181
180
|
} | undefined;
|
|
182
181
|
resolver: ResolverClient;
|
|
183
182
|
};
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/types.d.ts
|
|
186
183
|
/**
|
|
187
184
|
* The plugin factory type for `@kubb/plugin-fetch`. Shares the options surface, resolver, and
|
|
188
185
|
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
@@ -196,16 +193,12 @@ declare global {
|
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
}
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/generators/clientGenerator.d.ts
|
|
201
196
|
/**
|
|
202
197
|
* Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
|
|
203
198
|
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
204
199
|
* that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
205
200
|
*/
|
|
206
201
|
export declare const clientGenerator: import("kubb/kit").Generator<PluginFetch>;
|
|
207
|
-
//#endregion
|
|
208
|
-
//#region src/plugin.d.ts
|
|
209
202
|
/**
|
|
210
203
|
* Canonical plugin name for `@kubb/plugin-fetch`. Used for driver lookups and cross-plugin
|
|
211
204
|
* dependency references.
|
|
@@ -234,6 +227,5 @@ export declare const pluginFetchName = "plugin-fetch";
|
|
|
234
227
|
* ```
|
|
235
228
|
*/
|
|
236
229
|
export declare const pluginFetch: import("kubb/kit").PluginFactory<PluginFetch>;
|
|
237
|
-
//#endregion
|
|
238
230
|
export { type Options, type PluginFetch, type ResolvedOptions, type ResolverClient, pluginFetch as default };
|
|
239
231
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
2
|
import "@kubb/plugin-zod";
|
|
3
3
|
import "@kubb/plugin-ts";
|
|
4
|
-
//#region ../../internals/client/src/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Validator applied to the request and response using schemas from `@kubb/plugin-zod`.
|
|
7
6
|
* - `false`: no validation.
|
|
@@ -181,8 +180,6 @@ type ResolvedOptions = {
|
|
|
181
180
|
} | undefined;
|
|
182
181
|
resolver: ResolverClient;
|
|
183
182
|
};
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/types.d.ts
|
|
186
183
|
/**
|
|
187
184
|
* The plugin factory type for `@kubb/plugin-fetch`. Shares the options surface, resolver, and
|
|
188
185
|
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
@@ -196,16 +193,12 @@ declare global {
|
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
}
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/generators/clientGenerator.d.ts
|
|
201
196
|
/**
|
|
202
197
|
* Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
|
|
203
198
|
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
204
199
|
* that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
205
200
|
*/
|
|
206
201
|
export declare const clientGenerator: import("kubb/kit").Generator<PluginFetch>;
|
|
207
|
-
//#endregion
|
|
208
|
-
//#region src/plugin.d.ts
|
|
209
202
|
/**
|
|
210
203
|
* Canonical plugin name for `@kubb/plugin-fetch`. Used for driver lookups and cross-plugin
|
|
211
204
|
* dependency references.
|
|
@@ -234,6 +227,5 @@ export declare const pluginFetchName = "plugin-fetch";
|
|
|
234
227
|
* ```
|
|
235
228
|
*/
|
|
236
229
|
export declare const pluginFetch: import("kubb/kit").PluginFactory<PluginFetch>;
|
|
237
|
-
//#endregion
|
|
238
230
|
export { type Options, type PluginFetch, type ResolvedOptions, type ResolverClient, pluginFetch as default };
|
|
239
231
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, injectFile, macroSimplifyUnion, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
1
|
+
import { Diagnostics, Resolver, Url, addGenerator, ast, camelCase, createResolver, defineExtension, defineGenerator, injectFile, macroSimplifyUnion, pascalCase, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
4
4
|
import { File, Function, jsxRenderer } from "kubb/jsx";
|
|
5
5
|
import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
|
|
9
|
-
//#region ../../internals/shared/src/operation.ts
|
|
8
|
+
// ../../internals/shared/src/operation.ts
|
|
10
9
|
/**
|
|
11
10
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
12
11
|
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
@@ -184,6 +183,16 @@ function getOperationParameters(node) {
|
|
|
184
183
|
operationParameterGroupsByNode.set(node, groups);
|
|
185
184
|
return groups;
|
|
186
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Builds the combined `{ body, path, query, headers }` options object schema for an operation,
|
|
188
|
+
* referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
|
|
189
|
+
* `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
|
|
190
|
+
* shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
|
|
191
|
+
* printer to emit `z.object(…)` rather than a record.
|
|
192
|
+
*/
|
|
193
|
+
function hasRequestContentTypeChoice(node) {
|
|
194
|
+
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
195
|
+
}
|
|
187
196
|
function getStatusCodeNumber(statusCode) {
|
|
188
197
|
const code = Number(statusCode);
|
|
189
198
|
return Number.isNaN(code) ? null : code;
|
|
@@ -201,58 +210,7 @@ function getOperationSuccessResponses(node) {
|
|
|
201
210
|
function getPrimarySuccessResponse(node) {
|
|
202
211
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
203
212
|
}
|
|
204
|
-
|
|
205
|
-
//#region ../../internals/utils/src/casing.ts
|
|
206
|
-
/**
|
|
207
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
208
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
209
|
-
* and capitalizes each word according to `pascal`.
|
|
210
|
-
*
|
|
211
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
212
|
-
*/
|
|
213
|
-
function convert(text, pascal) {
|
|
214
|
-
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) => {
|
|
215
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
216
|
-
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
217
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
218
|
-
}
|
|
219
|
-
const cache = /* @__PURE__ */ new Map();
|
|
220
|
-
const cacheLimit = 1e4;
|
|
221
|
-
function toCamelOrPascal(text, pascal) {
|
|
222
|
-
const key = `${pascal ? "P" : "c"}${text}`;
|
|
223
|
-
const cached = cache.get(key);
|
|
224
|
-
if (cached !== void 0) return cached;
|
|
225
|
-
const result = convert(text, pascal);
|
|
226
|
-
if (cache.size >= cacheLimit) cache.clear();
|
|
227
|
-
cache.set(key, result);
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Converts `text` to camelCase.
|
|
232
|
-
*
|
|
233
|
-
* @example Word boundaries
|
|
234
|
-
* `camelCase('hello-world') // 'helloWorld'`
|
|
235
|
-
*
|
|
236
|
-
* @example With a prefix
|
|
237
|
-
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
238
|
-
*/
|
|
239
|
-
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
240
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Converts `text` to PascalCase.
|
|
244
|
-
*
|
|
245
|
-
* @example Word boundaries
|
|
246
|
-
* `pascalCase('hello-world') // 'HelloWorld'`
|
|
247
|
-
*
|
|
248
|
-
* @example With a suffix
|
|
249
|
-
* `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
|
|
250
|
-
*/
|
|
251
|
-
function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
252
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
213
|
+
// ../../internals/utils/src/reserved.ts
|
|
256
214
|
/**
|
|
257
215
|
* JavaScript and Java reserved words.
|
|
258
216
|
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
@@ -260,6 +218,7 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
260
218
|
const reservedWords = /* @__PURE__ */ new Set([
|
|
261
219
|
"abstract",
|
|
262
220
|
"arguments",
|
|
221
|
+
"await",
|
|
263
222
|
"boolean",
|
|
264
223
|
"break",
|
|
265
224
|
"byte",
|
|
@@ -390,8 +349,7 @@ function ensureValidVarName(name) {
|
|
|
390
349
|
function isIdentifier(name) {
|
|
391
350
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
392
351
|
}
|
|
393
|
-
|
|
394
|
-
//#region ../../internals/utils/src/codegen.ts
|
|
352
|
+
// ../../internals/utils/src/codegen.ts
|
|
395
353
|
/**
|
|
396
354
|
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
397
355
|
* comments.
|
|
@@ -407,8 +365,32 @@ function buildJSDoc(comments, options = {}) {
|
|
|
407
365
|
if (comments.length === 0) return fallback;
|
|
408
366
|
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
409
367
|
}
|
|
410
|
-
|
|
411
|
-
|
|
368
|
+
// ../../internals/shared/src/resolver.ts
|
|
369
|
+
/**
|
|
370
|
+
* The shared top-level `name` of the operation plugins, computed once per operation name and build.
|
|
371
|
+
*/
|
|
372
|
+
function resolveOperationName(name) {
|
|
373
|
+
return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
377
|
+
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
378
|
+
* name. Leave `scope` empty for the operation's own declaration.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
function operationKey(node, ...scope) {
|
|
386
|
+
return [
|
|
387
|
+
"operation",
|
|
388
|
+
node.method,
|
|
389
|
+
node.path,
|
|
390
|
+
...scope.map(String)
|
|
391
|
+
];
|
|
392
|
+
}
|
|
393
|
+
// ../../internals/shared/src/group.ts
|
|
412
394
|
/**
|
|
413
395
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
414
396
|
* shared default naming so every plugin groups output consistently:
|
|
@@ -438,8 +420,7 @@ function createGroupConfig(group) {
|
|
|
438
420
|
name: group.name ? group.name : defaultName
|
|
439
421
|
};
|
|
440
422
|
}
|
|
441
|
-
|
|
442
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
423
|
+
// ../../internals/client/src/builders/validatorOptions.ts
|
|
443
424
|
/**
|
|
444
425
|
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
445
426
|
*/
|
|
@@ -482,8 +463,7 @@ function buildZodErrorParse(node, zodResolver) {
|
|
|
482
463
|
if (!node.responses.some((res) => !isSuccessStatusCode(res.statusCode) && res.content?.some((entry) => entry.schema))) return null;
|
|
483
464
|
return zodResolver.response.error?.(node) || null;
|
|
484
465
|
}
|
|
485
|
-
|
|
486
|
-
//#region ../../internals/client/src/builders/security.ts
|
|
466
|
+
// ../../internals/client/src/builders/security.ts
|
|
487
467
|
function serializeAuth(auth) {
|
|
488
468
|
const parts = [`type: '${auth.type}'`];
|
|
489
469
|
if (auth.scheme) parts.push(`scheme: '${auth.scheme}'`);
|
|
@@ -554,8 +534,7 @@ function buildSecurityMetadata({ security }) {
|
|
|
554
534
|
if (!security?.length) return null;
|
|
555
535
|
return `[${security.map(serializeAuth).join(", ")}]`;
|
|
556
536
|
}
|
|
557
|
-
|
|
558
|
-
//#region ../../internals/client/src/builders/validator.ts
|
|
537
|
+
// ../../internals/client/src/builders/validator.ts
|
|
559
538
|
/**
|
|
560
539
|
* Builds the validator-hook references for one operation. Request body and params validation run before the send.
|
|
561
540
|
* Response validation runs on the success body only. Returns `null` references when the matching
|
|
@@ -597,17 +576,16 @@ function buildValidatorLiteral(hooks, keys) {
|
|
|
597
576
|
const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
|
|
598
577
|
return entries.length ? `validator: { ${entries.join(", ")} }` : null;
|
|
599
578
|
}
|
|
600
|
-
|
|
601
|
-
//#region ../../internals/client/src/builders/contentType.ts
|
|
579
|
+
// ../../internals/client/src/builders/contentType.ts
|
|
602
580
|
/**
|
|
603
|
-
* Builds the `contentType` entry baked into the call config, or `null`
|
|
581
|
+
* Builds the `contentType` entry baked into the call config, or `null` without a request body.
|
|
604
582
|
*
|
|
605
583
|
* `merge` is `true` when the generated function must destructure `contentType` from `options` and
|
|
606
584
|
* merge it over the baked request default, because the caller can also pick a response content type.
|
|
607
585
|
*/
|
|
608
586
|
function buildContentType({ node }) {
|
|
609
587
|
const { defaultContentType } = getContentTypeInfo(node);
|
|
610
|
-
const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema)
|
|
588
|
+
const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema) ? defaultContentType : null;
|
|
611
589
|
if (!requestContentType) return {
|
|
612
590
|
literal: null,
|
|
613
591
|
merge: false
|
|
@@ -618,8 +596,7 @@ function buildContentType({ node }) {
|
|
|
618
596
|
literal: merge ? `contentType: { request: '${requestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${requestContentType}' }`
|
|
619
597
|
};
|
|
620
598
|
}
|
|
621
|
-
|
|
622
|
-
//#region ../../internals/client/src/builders/generics.ts
|
|
599
|
+
// ../../internals/client/src/builders/generics.ts
|
|
623
600
|
/**
|
|
624
601
|
* Builds the `RequestResult` generic arguments for one operation: the per-status responses record
|
|
625
602
|
* plus the per-call `ThrowOnError` flag. `SuccessOf` / `ErrorOf` split the record inside the
|
|
@@ -650,8 +627,7 @@ function buildResultType({ node, types, returnType }) {
|
|
|
650
627
|
if (returnType === "plain") return `Promise<RequestResult<${generics}>>`;
|
|
651
628
|
return `Unwrappable<RequestResult<${generics}>>`;
|
|
652
629
|
}
|
|
653
|
-
|
|
654
|
-
//#region ../../internals/client/src/builders/returnStatement.ts
|
|
630
|
+
// ../../internals/client/src/builders/returnStatement.ts
|
|
655
631
|
/**
|
|
656
632
|
* Builds the return statement of a generated operation function. With the default
|
|
657
633
|
* `returnType: 'full'` the runtime call already resolves to `{ data, error, request, response }`.
|
|
@@ -675,22 +651,22 @@ function buildResultType({ node, types, returnType }) {
|
|
|
675
651
|
* `return request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>`
|
|
676
652
|
*/
|
|
677
653
|
function buildReturnStatement({ node, types, callConfig, returnType, throwOnErrorDefault }) {
|
|
678
|
-
|
|
654
|
+
const request = returnType !== "plain" && hasRequestContentTypeChoice(node) ? `request<${types.response.options(node)}['body']>` : "request";
|
|
655
|
+
if (returnType === "data") return `return unwrapResult(${request}(${callConfig}), config.throwOnError ?? ${throwOnErrorDefault}) as ${buildResultType({
|
|
679
656
|
node,
|
|
680
657
|
types,
|
|
681
658
|
returnType
|
|
682
659
|
})}`;
|
|
683
|
-
if (returnType === "plain") return `return request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
660
|
+
if (returnType === "plain") return `return ${request}(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
684
661
|
node,
|
|
685
662
|
types
|
|
686
663
|
})}>>`;
|
|
687
|
-
return `return withUnwrap(request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
664
|
+
return `return withUnwrap(${request}(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
|
|
688
665
|
node,
|
|
689
666
|
types
|
|
690
667
|
})}>>)`;
|
|
691
668
|
}
|
|
692
|
-
|
|
693
|
-
//#region ../../internals/client/src/builders/signature.ts
|
|
669
|
+
// ../../internals/client/src/builders/signature.ts
|
|
694
670
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
695
671
|
/**
|
|
696
672
|
* Builds the grouped-options signature for one operation: a single `options` object whose `TData`
|
|
@@ -718,8 +694,7 @@ function buildGroupedOptionsSignature({ node, types, returnType, throwOnErrorDef
|
|
|
718
694
|
generics: [`ThrowOnError extends boolean = ${throwOnErrorDefault}`]
|
|
719
695
|
};
|
|
720
696
|
}
|
|
721
|
-
|
|
722
|
-
//#region ../../internals/client/src/builders/styles.ts
|
|
697
|
+
// ../../internals/client/src/builders/styles.ts
|
|
723
698
|
/**
|
|
724
699
|
* Renders a parameter name as an object-literal key, quoted when it is not a bare identifier. Every
|
|
725
700
|
* location keeps the spec name: the runtime looks path styles up by the `{name}` placeholder in the
|
|
@@ -791,8 +766,7 @@ function buildStyles({ node }) {
|
|
|
791
766
|
const entries = [...Object.keys(groups).filter((location) => groups[location].length > 0).map((location) => `${location}: { ${groups[location].join(", ")} }`), serializeBodyEncoding(node)].filter(Boolean);
|
|
792
767
|
return entries.length > 0 ? `{ ${entries.join(", ")} }` : null;
|
|
793
768
|
}
|
|
794
|
-
|
|
795
|
-
//#region ../../internals/client/src/components/Operation.tsx
|
|
769
|
+
// ../../internals/client/src/components/Operation.tsx
|
|
796
770
|
/**
|
|
797
771
|
* Renders one client operation: the grouped `<Name>Request` type and the function that forwards a
|
|
798
772
|
* single `options` object to the resolved client and returns the `Unwrappable<RequestResult>`. The
|
|
@@ -869,8 +843,7 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
|
|
|
869
843
|
})
|
|
870
844
|
});
|
|
871
845
|
}
|
|
872
|
-
|
|
873
|
-
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
846
|
+
// ../../internals/client/src/resolveOperationTypes.ts
|
|
874
847
|
/**
|
|
875
848
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
876
849
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -880,6 +853,7 @@ function toZodTypeResolver(resolver) {
|
|
|
880
853
|
return {
|
|
881
854
|
...resolver,
|
|
882
855
|
file: resolver.file.bind(resolver),
|
|
856
|
+
memo: (key, compute) => resolver.memo(`zodTypes:${key}`, compute),
|
|
883
857
|
param: {
|
|
884
858
|
name: (node, p) => type(resolver.param.name(node, p)),
|
|
885
859
|
path: (node, p) => type(resolver.param.path(node, p)),
|
|
@@ -936,8 +910,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
936
910
|
group: pluginZod.options.group ?? void 0
|
|
937
911
|
};
|
|
938
912
|
}
|
|
939
|
-
|
|
940
|
-
//#region ../../internals/client/src/generators/clientGenerator.tsx
|
|
913
|
+
// ../../internals/client/src/generators/clientGenerator.tsx
|
|
941
914
|
/**
|
|
942
915
|
* Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`,
|
|
943
916
|
* `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared
|
|
@@ -964,8 +937,12 @@ function createClientGenerator(name, resolveClientPath) {
|
|
|
964
937
|
zodResolver
|
|
965
938
|
});
|
|
966
939
|
const importedZodNames = validatorHooks.importedZodNames;
|
|
940
|
+
const operationName = resolver.name(node.operationId);
|
|
967
941
|
const meta = {
|
|
968
|
-
name: resolver.
|
|
942
|
+
name: resolver.resolveName({
|
|
943
|
+
key: operationKey(node),
|
|
944
|
+
name: operationName
|
|
945
|
+
}),
|
|
969
946
|
file: resolver.file({
|
|
970
947
|
...operationFileEntry(node, node.operationId),
|
|
971
948
|
root,
|
|
@@ -1080,8 +1057,7 @@ function createClientGenerator(name, resolveClientPath) {
|
|
|
1080
1057
|
}
|
|
1081
1058
|
});
|
|
1082
1059
|
}
|
|
1083
|
-
|
|
1084
|
-
//#region ../../internals/client/src/components/SdkClient.tsx
|
|
1060
|
+
// ../../internals/client/src/components/SdkClient.tsx
|
|
1085
1061
|
/**
|
|
1086
1062
|
* Builds the call config literal forwarded to the contract client; the `throwOnError` fallback is applied after the `...config` spread.
|
|
1087
1063
|
*/
|
|
@@ -1171,8 +1147,7 @@ function SdkClient({ name, operations, returnType, throwOnErrorDefault }) {
|
|
|
1171
1147
|
children: classCode
|
|
1172
1148
|
});
|
|
1173
1149
|
}
|
|
1174
|
-
|
|
1175
|
-
//#region ../../internals/client/src/components/SdkFacade.tsx
|
|
1150
|
+
// ../../internals/client/src/components/SdkFacade.tsx
|
|
1176
1151
|
/**
|
|
1177
1152
|
* Renders a composed root SDK class that instantiates every tag client from one shared config, so
|
|
1178
1153
|
* `new PetStore({ baseURL }).petClient.getPetById(...)` reaches an operation through a single entry
|
|
@@ -1195,8 +1170,7 @@ function SdkFacade({ name, members }) {
|
|
|
1195
1170
|
children: classCode
|
|
1196
1171
|
});
|
|
1197
1172
|
}
|
|
1198
|
-
|
|
1199
|
-
//#region ../../internals/client/src/generators/sdkGenerator.tsx
|
|
1173
|
+
// ../../internals/client/src/generators/sdkGenerator.tsx
|
|
1200
1174
|
function resolveTypeImportNames(node, types) {
|
|
1201
1175
|
return [types.response.options(node), types.response.responses(node)];
|
|
1202
1176
|
}
|
|
@@ -1233,9 +1207,13 @@ function buildControllers(nodes, ctx, types) {
|
|
|
1233
1207
|
validator,
|
|
1234
1208
|
zodResolver
|
|
1235
1209
|
}) : null;
|
|
1210
|
+
const name = resolver.name(node.operationId);
|
|
1236
1211
|
return {
|
|
1237
1212
|
node,
|
|
1238
|
-
name: resolver.
|
|
1213
|
+
name: resolver.resolveName({
|
|
1214
|
+
key: operationKey(node),
|
|
1215
|
+
name
|
|
1216
|
+
}),
|
|
1239
1217
|
types,
|
|
1240
1218
|
typeFile,
|
|
1241
1219
|
zodFile,
|
|
@@ -1246,7 +1224,7 @@ function buildControllers(nodes, ctx, types) {
|
|
|
1246
1224
|
return nodes.reduce((acc, operationNode) => {
|
|
1247
1225
|
if (!ast.isHttpOperationNode(operationNode)) return acc;
|
|
1248
1226
|
const tag = operationNode.tags[0];
|
|
1249
|
-
const name = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.groupName(tag) : resolver.className("ApiClient");
|
|
1227
|
+
const name = tag ? ensureValidVarName(group?.name?.({ group: camelCase(tag) }) ?? resolver.groupName(tag)) : resolver.className("ApiClient");
|
|
1250
1228
|
const file = resolver.file({
|
|
1251
1229
|
name,
|
|
1252
1230
|
extname: ".ts",
|
|
@@ -1448,19 +1426,17 @@ function createSdkGenerator() {
|
|
|
1448
1426
|
}
|
|
1449
1427
|
});
|
|
1450
1428
|
}
|
|
1451
|
-
|
|
1452
|
-
//#region ../../internals/client/src/macros.ts
|
|
1429
|
+
// ../../internals/client/src/macros.ts
|
|
1453
1430
|
/**
|
|
1454
1431
|
* Macros the client plugins apply by default, ahead of any user macros. `macroSimplifyUnion`
|
|
1455
1432
|
* drops union members a broader scalar already covers, keeping the generated response and error
|
|
1456
1433
|
* unions tidy. A plugin wires them with `ctx.setMacros([...defaultMacros, ...userMacros])`.
|
|
1457
1434
|
*/
|
|
1458
1435
|
const defaultMacros = [macroSimplifyUnion];
|
|
1459
|
-
|
|
1460
|
-
//#region ../../internals/client/src/resolver.ts
|
|
1436
|
+
// ../../internals/client/src/resolver.ts
|
|
1461
1437
|
/**
|
|
1462
|
-
* Default resolver shared by the client plugins. Functions
|
|
1463
|
-
*
|
|
1438
|
+
* Default resolver shared by the client plugins. Functions use safe camelCase identifiers and
|
|
1439
|
+
* files inherit the built-in casing; classes and tag groups use PascalCase.
|
|
1464
1440
|
*
|
|
1465
1441
|
* @example
|
|
1466
1442
|
* ```ts
|
|
@@ -1470,6 +1446,7 @@ const defaultMacros = [macroSimplifyUnion];
|
|
|
1470
1446
|
*/
|
|
1471
1447
|
const resolverClient = createResolver({
|
|
1472
1448
|
pluginName: "plugin-contract-client",
|
|
1449
|
+
name: resolveOperationName,
|
|
1473
1450
|
className(name) {
|
|
1474
1451
|
return ensureValidVarName(pascalCase(name));
|
|
1475
1452
|
},
|
|
@@ -1480,25 +1457,21 @@ const resolverClient = createResolver({
|
|
|
1480
1457
|
return ensureValidVarName(camelCase(name));
|
|
1481
1458
|
}
|
|
1482
1459
|
});
|
|
1483
|
-
|
|
1484
|
-
//#region src/generators/clientGenerator.tsx
|
|
1460
|
+
// src/generators/clientGenerator.tsx
|
|
1485
1461
|
/**
|
|
1486
1462
|
* Built-in operation generator for `@kubb/plugin-fetch`. Emits one async function per OpenAPI
|
|
1487
1463
|
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
|
|
1488
1464
|
* that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
1489
1465
|
*/
|
|
1490
1466
|
const clientGenerator = createClientGenerator("fetch");
|
|
1491
|
-
|
|
1492
|
-
//#region kubb-extension.json
|
|
1467
|
+
// kubb-extension.json
|
|
1493
1468
|
var compatibility = {
|
|
1494
|
-
"kubb": ">=5.
|
|
1469
|
+
"kubb": ">=5.14.6",
|
|
1495
1470
|
"node": ">=22.22"
|
|
1496
1471
|
};
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
//#endregion
|
|
1501
|
-
//#region src/templates.ts
|
|
1472
|
+
// package.json
|
|
1473
|
+
var version = "5.10.1";
|
|
1474
|
+
// src/templates.ts
|
|
1502
1475
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
|
1503
1476
|
const fetchClientTemplatePath = fileURLToPath(new URL("../templates/fetch.ts", import.meta.url));
|
|
1504
1477
|
/** Absolute path to the fetch serializers template, copied into `.kubb/serializers.ts`. */
|
|
@@ -1508,8 +1481,7 @@ const fetchSerializersTemplatePath = fileURLToPath(new URL("../templates/seriali
|
|
|
1508
1481
|
* emit the helper into the generated `.kubb/standardSchema.ts` verbatim.
|
|
1509
1482
|
*/
|
|
1510
1483
|
const standardSchemaTemplatePath = fileURLToPath(new URL("../templates/standardSchema.ts", import.meta.url));
|
|
1511
|
-
|
|
1512
|
-
//#region src/plugin.ts
|
|
1484
|
+
// src/plugin.ts
|
|
1513
1485
|
/**
|
|
1514
1486
|
* Canonical plugin name for `@kubb/plugin-fetch`. Used for driver lookups and cross-plugin
|
|
1515
1487
|
* dependency references.
|
|
@@ -1594,7 +1566,6 @@ const pluginFetch = defineExtension({
|
|
|
1594
1566
|
return resolved;
|
|
1595
1567
|
}
|
|
1596
1568
|
});
|
|
1597
|
-
//#endregion
|
|
1598
1569
|
export { clientGenerator, pluginFetch as default, pluginFetch, pluginFetchName };
|
|
1599
1570
|
|
|
1600
1571
|
//# sourceMappingURL=index.js.map
|