@kubb/plugin-vue-query 5.0.0-beta.95 → 5.0.0-beta.99

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
@@ -28,12 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  enumerable: true
29
29
  }) : target, mod));
30
30
  //#endregion
31
+ let node_path = require("node:path");
32
+ node_path = __toESM(node_path, 1);
31
33
  let kubb_kit = require("kubb/kit");
32
34
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
33
35
  let kubb_jsx = require("kubb/jsx");
34
36
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
35
- let node_path = require("node:path");
36
- node_path = __toESM(node_path, 1);
37
37
  //#region ../../internals/utils/src/casing.ts
38
38
  /**
39
39
  * Shared implementation for camelCase and PascalCase conversion.
@@ -208,33 +208,17 @@ function getNestedAccessor(param, accessor) {
208
208
  }
209
209
  //#endregion
210
210
  //#region ../../internals/utils/src/url.ts
211
- function transformParam(raw, casing) {
212
- const param = isValidVarName(raw) ? raw : camelCase(raw);
213
- return casing === "camelcase" ? camelCase(param) : param;
214
- }
215
- function toParamsObject(path, { replacer, casing } = {}) {
216
- const params = {};
217
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
218
- const param = transformParam(match[1], casing);
219
- const key = replacer ? replacer(param) : param;
220
- params[key] = key;
221
- }
222
- return Object.keys(params).length > 0 ? params : null;
211
+ /**
212
+ * Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
213
+ * camelCases it only enough to become one otherwise (for example a hyphenated path segment).
214
+ */
215
+ function transformParam(raw) {
216
+ return isValidVarName(raw) ? raw : camelCase(raw);
223
217
  }
224
218
  /**
225
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
219
+ * Helpers for OpenAPI/Swagger paths.
226
220
  */
227
221
  var Url = class Url {
228
- /**
229
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
230
- *
231
- * @example
232
- * Url.canParse('https://petstore.swagger.io/v2') // true
233
- * Url.canParse('/pet/{petId}') // false
234
- */
235
- static canParse(url, base) {
236
- return URL.canParse(url, base);
237
- }
238
222
  /**
239
223
  * Converts an OpenAPI/Swagger path to Express-style colon syntax.
240
224
  *
@@ -250,15 +234,14 @@ var Url = class Url {
250
234
  * key.
251
235
  *
252
236
  * @example
253
- * Url.toCasedTemplate('/projects/{project_id}', { casing: 'camelcase' }) // '/projects/{projectId}'
237
+ * Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
254
238
  */
255
- static toCasedTemplate(path, { casing } = {}) {
256
- return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name, casing)}}`);
239
+ static toSafeTemplate(path) {
240
+ return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
257
241
  }
258
242
  /**
259
243
  * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
260
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
261
- * and `casing` controls parameter identifier casing.
244
+ * `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
262
245
  *
263
246
  * @example
264
247
  * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
@@ -266,10 +249,10 @@ var Url = class Url {
266
249
  * @example
267
250
  * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
268
251
  */
269
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
252
+ static toTemplateString(path, { prefix, replacer } = {}) {
270
253
  const result = path.split(/\{([^}]+)\}/).map((part, i) => {
271
254
  if (i % 2 === 0) return part;
272
- const param = transformParam(part, casing);
255
+ const param = transformParam(part);
273
256
  return `\${${replacer ? replacer(param) : param}}`;
274
257
  }).join("");
275
258
  return `\`${prefix ?? ""}${result}\``;
@@ -277,8 +260,8 @@ var Url = class Url {
277
260
  /**
278
261
  * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
279
262
  * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
280
- * names are camelCased to match the generated `path` type, and `prefix` is prepended inside the
281
- * literal. Shared by the client and cypress generators that pass a grouped `path` object.
263
+ * names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
264
+ * the client and cypress generators that pass a grouped `path` object.
282
265
  *
283
266
  * @example
284
267
  * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
@@ -286,72 +269,25 @@ var Url = class Url {
286
269
  static toGroupedTemplateString(path, { prefix } = {}) {
287
270
  return Url.toTemplateString(path, {
288
271
  prefix,
289
- casing: "camelcase",
290
272
  replacer: (name) => `path.${name}`
291
273
  });
292
274
  }
293
- /**
294
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
295
- * expression when `stringify` is set.
296
- *
297
- * @example
298
- * Url.toObject('/pet/{petId}')
299
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
300
- */
301
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
302
- const object = {
303
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
304
- replacer,
305
- casing
306
- }),
307
- params: toParamsObject(path, {
308
- replacer,
309
- casing
310
- })
311
- };
312
- if (stringify) {
313
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
314
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
315
- return `{ url: '${object.url}' }`;
316
- }
317
- return object;
318
- }
319
275
  };
320
276
  //#endregion
321
277
  //#region ../../internals/shared/src/params.ts
322
- const caseParamsCache = /* @__PURE__ */ new WeakMap();
323
278
  /**
324
- * Applies camelCase to parameter names and returns a new array without mutating the input.
279
+ * Drops parameters that share the same name, keeping the first.
325
280
  *
326
- * Run it before handing parameters to schema builders so output property keys get the right casing
327
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
328
- * original array is returned unchanged. Results are cached per input array.
281
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
282
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
283
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
284
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
329
285
  */
330
- function caseParams(params, casing) {
331
- if (!casing) return params;
332
- const cached = caseParamsCache.get(params);
333
- if (cached) return cached;
334
- const result = params.map((param) => ({
335
- ...param,
336
- name: camelCase(param.name)
337
- }));
338
- caseParamsCache.set(params, result);
339
- return result;
340
- }
341
- /**
342
- * Drops parameters that collapse to the same property identity once camelCased, keeping the first.
343
- *
344
- * Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
345
- * `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
346
- * an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
347
- * identity so the resulting group is collision-free regardless of the names each caller carries.
348
- */
349
- function dedupeByCasedName(params) {
286
+ function dedupeParams(params) {
350
287
  const seen = /* @__PURE__ */ new Set();
351
288
  return params.filter((param) => {
352
- const key = camelCase(param.name);
353
- if (seen.has(key)) return false;
354
- seen.add(key);
289
+ if (seen.has(param.name)) return false;
290
+ seen.add(param.name);
355
291
  return true;
356
292
  });
357
293
  }
@@ -470,13 +406,15 @@ function buildOperationComments(node, options = {}) {
470
406
  if (!splitLines) return filteredComments;
471
407
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
472
408
  }
473
- function getOperationParameters(node, options = {}) {
474
- const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
409
+ function getOperationParameters(node) {
475
410
  return {
476
- path: dedupeByCasedName(params.filter((param) => param.in === "path")),
477
- query: dedupeByCasedName(params.filter((param) => param.in === "query")),
478
- header: dedupeByCasedName(params.filter((param) => param.in === "header")),
479
- cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
411
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
412
+ ...param,
413
+ name: camelCase(param.name)
414
+ })),
415
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
416
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
417
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
480
418
  };
481
419
  }
482
420
  function getStatusCodeNumber(statusCode) {
@@ -511,7 +449,7 @@ function resolveStatusCodeNames(node, resolver) {
511
449
  }
512
450
  const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
513
451
  function resolveOperationTypeNames(node, resolver, options = {}) {
514
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
452
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
515
453
  let byResolver = typeNamesByResolver.get(resolver);
516
454
  if (byResolver) {
517
455
  const cached = byResolver.get(cacheKey);
@@ -520,7 +458,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
520
458
  byResolver = /* @__PURE__ */ new Map();
521
459
  typeNamesByResolver.set(resolver, byResolver);
522
460
  }
523
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
461
+ const { path, query, header } = getOperationParameters(node);
524
462
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
525
463
  const exclude = new Set(options.exclude ?? []);
526
464
  const paramNames = options.includeParams === false ? [] : [
@@ -712,7 +650,7 @@ function resolveFallbackPageParamType(initialPageParam) {
712
650
  * so callers can reuse it when rewriting the paginated request.
713
651
  */
714
652
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
715
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
653
+ const firstQueryParam = getOperationParameters(node).query[0];
716
654
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
717
655
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
718
656
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1391,7 +1329,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1391
1329
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1392
1330
  if (!isQuery || isMutation || !infiniteOptions) return null;
1393
1331
  const normalizeKey = (key) => key.replace(/\?$/, "");
1394
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1332
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1395
1333
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1396
1334
  const importPath = query ? query.importPath : "@tanstack/vue-query";
1397
1335
  const contractOp = resolveClientOperation({
@@ -1420,7 +1358,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1420
1358
  group: pluginTs.options?.group ?? void 0
1421
1359
  })
1422
1360
  };
1423
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
1361
+ const rawQueryParams = getOperationParameters(node).query;
1424
1362
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
1425
1363
  const importedTypeNames = [
1426
1364
  tsResolver.response.options(node),