@kubb/plugin-vue-query 5.0.0-beta.98 → 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.js CHANGED
@@ -178,33 +178,17 @@ function getNestedAccessor(param, accessor) {
178
178
  }
179
179
  //#endregion
180
180
  //#region ../../internals/utils/src/url.ts
181
- function transformParam(raw, casing) {
182
- const param = isValidVarName(raw) ? raw : camelCase(raw);
183
- return casing === "camelcase" ? camelCase(param) : param;
184
- }
185
- function toParamsObject(path, { replacer, casing } = {}) {
186
- const params = {};
187
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
188
- const param = transformParam(match[1], casing);
189
- const key = replacer ? replacer(param) : param;
190
- params[key] = key;
191
- }
192
- return Object.keys(params).length > 0 ? params : null;
181
+ /**
182
+ * Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
183
+ * camelCases it only enough to become one otherwise (for example a hyphenated path segment).
184
+ */
185
+ function transformParam(raw) {
186
+ return isValidVarName(raw) ? raw : camelCase(raw);
193
187
  }
194
188
  /**
195
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
189
+ * Helpers for OpenAPI/Swagger paths.
196
190
  */
197
191
  var Url = class Url {
198
- /**
199
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
200
- *
201
- * @example
202
- * Url.canParse('https://petstore.swagger.io/v2') // true
203
- * Url.canParse('/pet/{petId}') // false
204
- */
205
- static canParse(url, base) {
206
- return URL.canParse(url, base);
207
- }
208
192
  /**
209
193
  * Converts an OpenAPI/Swagger path to Express-style colon syntax.
210
194
  *
@@ -220,15 +204,14 @@ var Url = class Url {
220
204
  * key.
221
205
  *
222
206
  * @example
223
- * Url.toCasedTemplate('/projects/{project_id}', { casing: 'camelcase' }) // '/projects/{projectId}'
207
+ * Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
224
208
  */
225
- static toCasedTemplate(path, { casing } = {}) {
226
- return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name, casing)}}`);
209
+ static toSafeTemplate(path) {
210
+ return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
227
211
  }
228
212
  /**
229
213
  * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
230
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
231
- * and `casing` controls parameter identifier casing.
214
+ * `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
232
215
  *
233
216
  * @example
234
217
  * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
@@ -236,10 +219,10 @@ var Url = class Url {
236
219
  * @example
237
220
  * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
238
221
  */
239
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
222
+ static toTemplateString(path, { prefix, replacer } = {}) {
240
223
  const result = path.split(/\{([^}]+)\}/).map((part, i) => {
241
224
  if (i % 2 === 0) return part;
242
- const param = transformParam(part, casing);
225
+ const param = transformParam(part);
243
226
  return `\${${replacer ? replacer(param) : param}}`;
244
227
  }).join("");
245
228
  return `\`${prefix ?? ""}${result}\``;
@@ -247,8 +230,8 @@ var Url = class Url {
247
230
  /**
248
231
  * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
249
232
  * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
250
- * names are camelCased to match the generated `path` type, and `prefix` is prepended inside the
251
- * literal. Shared by the client and cypress generators that pass a grouped `path` object.
233
+ * names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
234
+ * the client and cypress generators that pass a grouped `path` object.
252
235
  *
253
236
  * @example
254
237
  * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
@@ -256,72 +239,25 @@ var Url = class Url {
256
239
  static toGroupedTemplateString(path, { prefix } = {}) {
257
240
  return Url.toTemplateString(path, {
258
241
  prefix,
259
- casing: "camelcase",
260
242
  replacer: (name) => `path.${name}`
261
243
  });
262
244
  }
263
- /**
264
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
265
- * expression when `stringify` is set.
266
- *
267
- * @example
268
- * Url.toObject('/pet/{petId}')
269
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
270
- */
271
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
272
- const object = {
273
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
274
- replacer,
275
- casing
276
- }),
277
- params: toParamsObject(path, {
278
- replacer,
279
- casing
280
- })
281
- };
282
- if (stringify) {
283
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
284
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
285
- return `{ url: '${object.url}' }`;
286
- }
287
- return object;
288
- }
289
245
  };
290
246
  //#endregion
291
247
  //#region ../../internals/shared/src/params.ts
292
- const caseParamsCache = /* @__PURE__ */ new WeakMap();
293
248
  /**
294
- * Applies camelCase to parameter names and returns a new array without mutating the input.
249
+ * Drops parameters that share the same name, keeping the first.
295
250
  *
296
- * Run it before handing parameters to schema builders so output property keys get the right casing
297
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
298
- * original array is returned unchanged. Results are cached per input array.
251
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
252
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
253
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
254
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
299
255
  */
300
- function caseParams(params, casing) {
301
- if (!casing) return params;
302
- const cached = caseParamsCache.get(params);
303
- if (cached) return cached;
304
- const result = params.map((param) => ({
305
- ...param,
306
- name: camelCase(param.name)
307
- }));
308
- caseParamsCache.set(params, result);
309
- return result;
310
- }
311
- /**
312
- * Drops parameters that collapse to the same property identity once camelCased, keeping the first.
313
- *
314
- * Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
315
- * `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
316
- * an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
317
- * identity so the resulting group is collision-free regardless of the names each caller carries.
318
- */
319
- function dedupeByCasedName(params) {
256
+ function dedupeParams(params) {
320
257
  const seen = /* @__PURE__ */ new Set();
321
258
  return params.filter((param) => {
322
- const key = camelCase(param.name);
323
- if (seen.has(key)) return false;
324
- seen.add(key);
259
+ if (seen.has(param.name)) return false;
260
+ seen.add(param.name);
325
261
  return true;
326
262
  });
327
263
  }
@@ -440,13 +376,15 @@ function buildOperationComments(node, options = {}) {
440
376
  if (!splitLines) return filteredComments;
441
377
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
442
378
  }
443
- function getOperationParameters(node, options = {}) {
444
- const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
379
+ function getOperationParameters(node) {
445
380
  return {
446
- path: dedupeByCasedName(params.filter((param) => param.in === "path")),
447
- query: dedupeByCasedName(params.filter((param) => param.in === "query")),
448
- header: dedupeByCasedName(params.filter((param) => param.in === "header")),
449
- cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
381
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
382
+ ...param,
383
+ name: camelCase(param.name)
384
+ })),
385
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
386
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
387
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
450
388
  };
451
389
  }
452
390
  function getStatusCodeNumber(statusCode) {
@@ -481,7 +419,7 @@ function resolveStatusCodeNames(node, resolver) {
481
419
  }
482
420
  const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
483
421
  function resolveOperationTypeNames(node, resolver, options = {}) {
484
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
422
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
485
423
  let byResolver = typeNamesByResolver.get(resolver);
486
424
  if (byResolver) {
487
425
  const cached = byResolver.get(cacheKey);
@@ -490,7 +428,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
490
428
  byResolver = /* @__PURE__ */ new Map();
491
429
  typeNamesByResolver.set(resolver, byResolver);
492
430
  }
493
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
431
+ const { path, query, header } = getOperationParameters(node);
494
432
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
495
433
  const exclude = new Set(options.exclude ?? []);
496
434
  const paramNames = options.includeParams === false ? [] : [
@@ -682,7 +620,7 @@ function resolveFallbackPageParamType(initialPageParam) {
682
620
  * so callers can reuse it when rewriting the paginated request.
683
621
  */
684
622
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
685
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
623
+ const firstQueryParam = getOperationParameters(node).query[0];
686
624
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
687
625
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
688
626
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1361,7 +1299,7 @@ const infiniteQueryGenerator = defineGenerator({
1361
1299
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1362
1300
  if (!isQuery || isMutation || !infiniteOptions) return null;
1363
1301
  const normalizeKey = (key) => key.replace(/\?$/, "");
1364
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1302
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1365
1303
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1366
1304
  const importPath = query ? query.importPath : "@tanstack/vue-query";
1367
1305
  const contractOp = resolveClientOperation({
@@ -1390,7 +1328,7 @@ const infiniteQueryGenerator = defineGenerator({
1390
1328
  group: pluginTs.options?.group ?? void 0
1391
1329
  })
1392
1330
  };
1393
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
1331
+ const rawQueryParams = getOperationParameters(node).query;
1394
1332
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
1395
1333
  const importedTypeNames = [
1396
1334
  tsResolver.response.options(node),