@kubb/plugin-fetch 5.7.0 → 5.7.2

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Diagnostics, Resolver, Url, addGenerator, assertPluginOption, ast, createResolver, defineExtension, defineGenerator, injectFile, macroSimplifyUnion, setMacros, setResolver, useConfig } from "kubb/kit";
1
+ import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, injectFile, macroSimplifyUnion, 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";
@@ -210,12 +210,23 @@ function getPrimarySuccessResponse(node) {
210
210
  *
211
211
  * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
212
212
  */
213
- function toCamelOrPascal(text, pascal) {
213
+ function convert(text, pascal) {
214
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
215
  if (word.length > 1 && word === word.toUpperCase()) return word;
216
216
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
217
217
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
218
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
+ }
219
230
  /**
220
231
  * Converts `text` to camelCase.
221
232
  *
@@ -688,25 +699,27 @@ function toKey(name, location) {
688
699
  return isValidVarName(key) ? key : JSON.stringify(key);
689
700
  }
690
701
  /**
691
- * Serializes one parameter's metadata into a `{ style, explode, allowReserved }` literal, or `null`
692
- * when the parameter carries none. Path and query carry the serialization `style`; header and cookie
693
- * use a fixed style (`simple` and `form`), so only `explode` is emitted for them. `allowReserved`
694
- * only applies to query parameters.
702
+ * Serializes one parameter's metadata into a `{ style, explode, allowReserved, contentType }`
703
+ * literal, or `null` when the parameter carries none. Path and query carry the serialization
704
+ * `style`; header and cookie use a fixed style (`simple` and `form`), so only `explode` is emitted
705
+ * for them. `allowReserved` only applies to query parameters, and `contentType` to every location
706
+ * except path.
695
707
  */
696
708
  function serializeParameter(parameter) {
697
709
  const parts = [];
698
710
  if ((parameter.in === "path" || parameter.in === "query") && parameter.style) parts.push(`style: '${parameter.style}'`);
699
711
  if (parameter.explode !== void 0) parts.push(`explode: ${parameter.explode}`);
700
712
  if (parameter.in === "query" && parameter.allowReserved !== void 0) parts.push(`allowReserved: ${parameter.allowReserved}`);
713
+ if (parameter.in !== "path" && parameter.contentType) parts.push(`contentType: '${parameter.contentType}'`);
701
714
  return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
702
715
  }
703
716
  /**
704
717
  * Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
705
718
  * Path entries are keyed by the camelCased name to match the URL template placeholders; query,
706
719
  * header, and cookie entries keep the spec name to match the keys the runtime serializes.
707
- * Only parameters whose source defines `style`, `explode`, or `allowReserved` are emitted, so calls without
708
- * serialization metadata keep the runtime defaults and existing output is unchanged. Returns `null`
709
- * when no parameter carries metadata.
720
+ * Only parameters whose source defines `style`, `explode`, `allowReserved`, or `contentType` are
721
+ * emitted, so calls without serialization metadata keep the runtime defaults and existing output
722
+ * is unchanged. Returns `null` when no parameter carries metadata.
710
723
  *
711
724
  * @example
712
725
  * ```ts
@@ -1404,7 +1417,7 @@ var compatibility = {
1404
1417
  };
1405
1418
  //#endregion
1406
1419
  //#region package.json
1407
- var version = "5.7.0";
1420
+ var version = "5.7.2";
1408
1421
  //#endregion
1409
1422
  //#region src/templates.ts
1410
1423
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
@@ -1478,32 +1491,6 @@ const pluginFetch = defineExtension({
1478
1491
  } : void 0,
1479
1492
  resolver: userResolver ? Resolver.merge(resolverClient, userResolver) : resolverClient
1480
1493
  };
1481
- const allowedReturnTypes = [
1482
- "full",
1483
- "data",
1484
- "plain"
1485
- ];
1486
- assertPluginOption({
1487
- plugin: pluginFetchName,
1488
- option: "returnType",
1489
- value: returnType,
1490
- allowed: allowedReturnTypes
1491
- });
1492
- for (const [index, entry] of override.entries()) {
1493
- if (entry.options.returnType === void 0) continue;
1494
- assertPluginOption({
1495
- plugin: pluginFetchName,
1496
- option: `override[${index}].options.returnType`,
1497
- value: entry.options.returnType,
1498
- allowed: allowedReturnTypes
1499
- });
1500
- }
1501
- if (resolved.sdk) assertPluginOption({
1502
- plugin: pluginFetchName,
1503
- option: "sdk.mode",
1504
- value: resolved.sdk.mode,
1505
- allowed: ["tag", "flat"]
1506
- });
1507
1494
  setResolver(resolved.resolver);
1508
1495
  setMacros([...defaultMacros, ...options.macros ?? []]);
1509
1496
  addGenerator(resolved.sdk ? createSdkGenerator() : clientGenerator);