@kubb/plugin-fetch 5.10.0 → 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.js CHANGED
@@ -1,4 +1,4 @@
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";
@@ -210,55 +210,6 @@ function getOperationSuccessResponses(node) {
210
210
  function getPrimarySuccessResponse(node) {
211
211
  return getOperationSuccessResponses(node)[0] ?? null;
212
212
  }
213
- // ../../internals/utils/src/casing.ts
214
- /**
215
- * Shared implementation for camelCase and PascalCase conversion.
216
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
217
- * and capitalizes each word according to `pascal`.
218
- *
219
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
220
- */
221
- function convert(text, pascal) {
222
- 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) => {
223
- if (word.length > 1 && word === word.toUpperCase()) return word;
224
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
225
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
226
- }
227
- const cache = /* @__PURE__ */ new Map();
228
- const cacheLimit = 1e4;
229
- function toCamelOrPascal(text, pascal) {
230
- const key = `${pascal ? "P" : "c"}${text}`;
231
- const cached = cache.get(key);
232
- if (cached !== void 0) return cached;
233
- const result = convert(text, pascal);
234
- if (cache.size >= cacheLimit) cache.clear();
235
- cache.set(key, result);
236
- return result;
237
- }
238
- /**
239
- * Converts `text` to camelCase.
240
- *
241
- * @example Word boundaries
242
- * `camelCase('hello-world') // 'helloWorld'`
243
- *
244
- * @example With a prefix
245
- * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
246
- */
247
- function camelCase(text, { prefix = "", suffix = "" } = {}) {
248
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
249
- }
250
- /**
251
- * Converts `text` to PascalCase.
252
- *
253
- * @example Word boundaries
254
- * `pascalCase('hello-world') // 'HelloWorld'`
255
- *
256
- * @example With a suffix
257
- * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
258
- */
259
- function pascalCase(text, { prefix = "", suffix = "" } = {}) {
260
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
261
- }
262
213
  // ../../internals/utils/src/reserved.ts
263
214
  /**
264
215
  * JavaScript and Java reserved words.
@@ -415,8 +366,11 @@ function buildJSDoc(comments, options = {}) {
415
366
  return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
416
367
  }
417
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
+ */
418
372
  function resolveOperationName(name) {
419
- return ensureValidVarName(camelCase(name));
373
+ return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)));
420
374
  }
421
375
  /**
422
376
  * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
@@ -899,6 +853,7 @@ function toZodTypeResolver(resolver) {
899
853
  return {
900
854
  ...resolver,
901
855
  file: resolver.file.bind(resolver),
856
+ memo: (key, compute) => resolver.memo(`zodTypes:${key}`, compute),
902
857
  param: {
903
858
  name: (node, p) => type(resolver.param.name(node, p)),
904
859
  path: (node, p) => type(resolver.param.path(node, p)),
@@ -1269,7 +1224,7 @@ function buildControllers(nodes, ctx, types) {
1269
1224
  return nodes.reduce((acc, operationNode) => {
1270
1225
  if (!ast.isHttpOperationNode(operationNode)) return acc;
1271
1226
  const tag = operationNode.tags[0];
1272
- 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");
1273
1228
  const file = resolver.file({
1274
1229
  name,
1275
1230
  extname: ".ts",
@@ -1515,7 +1470,7 @@ var compatibility = {
1515
1470
  "node": ">=22.22"
1516
1471
  };
1517
1472
  // package.json
1518
- var version = "5.10.0";
1473
+ var version = "5.10.1";
1519
1474
  // src/templates.ts
1520
1475
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
1521
1476
  const fetchClientTemplatePath = fileURLToPath(new URL("../templates/fetch.ts", import.meta.url));