@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.cjs CHANGED
@@ -236,12 +236,23 @@ function getPrimarySuccessResponse(node) {
236
236
  *
237
237
  * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
238
238
  */
239
- function toCamelOrPascal(text, pascal) {
239
+ function convert(text, pascal) {
240
240
  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) => {
241
241
  if (word.length > 1 && word === word.toUpperCase()) return word;
242
242
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
243
243
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
244
244
  }
245
+ const cache = /* @__PURE__ */ new Map();
246
+ const cacheLimit = 1e4;
247
+ function toCamelOrPascal(text, pascal) {
248
+ const key = `${pascal ? "P" : "c"}${text}`;
249
+ const cached = cache.get(key);
250
+ if (cached !== void 0) return cached;
251
+ const result = convert(text, pascal);
252
+ if (cache.size >= cacheLimit) cache.clear();
253
+ cache.set(key, result);
254
+ return result;
255
+ }
245
256
  /**
246
257
  * Converts `text` to camelCase.
247
258
  *
@@ -714,25 +725,27 @@ function toKey(name, location) {
714
725
  return isValidVarName(key) ? key : JSON.stringify(key);
715
726
  }
716
727
  /**
717
- * Serializes one parameter's metadata into a `{ style, explode, allowReserved }` literal, or `null`
718
- * when the parameter carries none. Path and query carry the serialization `style`; header and cookie
719
- * use a fixed style (`simple` and `form`), so only `explode` is emitted for them. `allowReserved`
720
- * only applies to query parameters.
728
+ * Serializes one parameter's metadata into a `{ style, explode, allowReserved, contentType }`
729
+ * literal, or `null` when the parameter carries none. Path and query carry the serialization
730
+ * `style`; header and cookie use a fixed style (`simple` and `form`), so only `explode` is emitted
731
+ * for them. `allowReserved` only applies to query parameters, and `contentType` to every location
732
+ * except path.
721
733
  */
722
734
  function serializeParameter(parameter) {
723
735
  const parts = [];
724
736
  if ((parameter.in === "path" || parameter.in === "query") && parameter.style) parts.push(`style: '${parameter.style}'`);
725
737
  if (parameter.explode !== void 0) parts.push(`explode: ${parameter.explode}`);
726
738
  if (parameter.in === "query" && parameter.allowReserved !== void 0) parts.push(`allowReserved: ${parameter.allowReserved}`);
739
+ if (parameter.in !== "path" && parameter.contentType) parts.push(`contentType: '${parameter.contentType}'`);
727
740
  return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
728
741
  }
729
742
  /**
730
743
  * Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
731
744
  * Path entries are keyed by the camelCased name to match the URL template placeholders; query,
732
745
  * header, and cookie entries keep the spec name to match the keys the runtime serializes.
733
- * Only parameters whose source defines `style`, `explode`, or `allowReserved` are emitted, so calls without
734
- * serialization metadata keep the runtime defaults and existing output is unchanged. Returns `null`
735
- * when no parameter carries metadata.
746
+ * Only parameters whose source defines `style`, `explode`, `allowReserved`, or `contentType` are
747
+ * emitted, so calls without serialization metadata keep the runtime defaults and existing output
748
+ * is unchanged. Returns `null` when no parameter carries metadata.
736
749
  *
737
750
  * @example
738
751
  * ```ts
@@ -1430,7 +1443,7 @@ var compatibility = {
1430
1443
  };
1431
1444
  //#endregion
1432
1445
  //#region package.json
1433
- var version = "5.7.0";
1446
+ var version = "5.7.2";
1434
1447
  //#endregion
1435
1448
  //#region src/templates.ts
1436
1449
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
@@ -1504,32 +1517,6 @@ const pluginFetch = (0, kubb_kit.defineExtension)({
1504
1517
  } : void 0,
1505
1518
  resolver: userResolver ? kubb_kit.Resolver.merge(resolverClient, userResolver) : resolverClient
1506
1519
  };
1507
- const allowedReturnTypes = [
1508
- "full",
1509
- "data",
1510
- "plain"
1511
- ];
1512
- (0, kubb_kit.assertPluginOption)({
1513
- plugin: pluginFetchName,
1514
- option: "returnType",
1515
- value: returnType,
1516
- allowed: allowedReturnTypes
1517
- });
1518
- for (const [index, entry] of override.entries()) {
1519
- if (entry.options.returnType === void 0) continue;
1520
- (0, kubb_kit.assertPluginOption)({
1521
- plugin: pluginFetchName,
1522
- option: `override[${index}].options.returnType`,
1523
- value: entry.options.returnType,
1524
- allowed: allowedReturnTypes
1525
- });
1526
- }
1527
- if (resolved.sdk) (0, kubb_kit.assertPluginOption)({
1528
- plugin: pluginFetchName,
1529
- option: "sdk.mode",
1530
- value: resolved.sdk.mode,
1531
- allowed: ["tag", "flat"]
1532
- });
1533
1520
  (0, kubb_kit.setResolver)(resolved.resolver);
1534
1521
  (0, kubb_kit.setMacros)([...defaultMacros, ...options.macros ?? []]);
1535
1522
  (0, kubb_kit.addGenerator)(resolved.sdk ? createSdkGenerator() : clientGenerator);