@kubb/plugin-react-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
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- let kubb_kit = require("kubb/kit");
28
27
  let node_path = require("node:path");
29
28
  node_path = __toESM(node_path, 1);
29
+ let kubb_kit = require("kubb/kit");
30
30
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
31
31
  let kubb_jsx = require("kubb/jsx");
32
32
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
@@ -206,33 +206,17 @@ function getNestedAccessor(param, accessor) {
206
206
  }
207
207
  //#endregion
208
208
  //#region ../../internals/utils/src/url.ts
209
- function transformParam(raw, casing) {
210
- const param = isValidVarName(raw) ? raw : camelCase(raw);
211
- return casing === "camelcase" ? camelCase(param) : param;
212
- }
213
- function toParamsObject(path, { replacer, casing } = {}) {
214
- const params = {};
215
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
216
- const param = transformParam(match[1], casing);
217
- const key = replacer ? replacer(param) : param;
218
- params[key] = key;
219
- }
220
- return Object.keys(params).length > 0 ? params : null;
209
+ /**
210
+ * Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
211
+ * camelCases it only enough to become one otherwise (for example a hyphenated path segment).
212
+ */
213
+ function transformParam(raw) {
214
+ return isValidVarName(raw) ? raw : camelCase(raw);
221
215
  }
222
216
  /**
223
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
217
+ * Helpers for OpenAPI/Swagger paths.
224
218
  */
225
219
  var Url = class Url {
226
- /**
227
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
228
- *
229
- * @example
230
- * Url.canParse('https://petstore.swagger.io/v2') // true
231
- * Url.canParse('/pet/{petId}') // false
232
- */
233
- static canParse(url, base) {
234
- return URL.canParse(url, base);
235
- }
236
220
  /**
237
221
  * Converts an OpenAPI/Swagger path to Express-style colon syntax.
238
222
  *
@@ -248,15 +232,14 @@ var Url = class Url {
248
232
  * key.
249
233
  *
250
234
  * @example
251
- * Url.toCasedTemplate('/projects/{project_id}', { casing: 'camelcase' }) // '/projects/{projectId}'
235
+ * Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
252
236
  */
253
- static toCasedTemplate(path, { casing } = {}) {
254
- return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name, casing)}}`);
237
+ static toSafeTemplate(path) {
238
+ return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
255
239
  }
256
240
  /**
257
241
  * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
258
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
259
- * and `casing` controls parameter identifier casing.
242
+ * `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
260
243
  *
261
244
  * @example
262
245
  * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
@@ -264,10 +247,10 @@ var Url = class Url {
264
247
  * @example
265
248
  * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
266
249
  */
267
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
250
+ static toTemplateString(path, { prefix, replacer } = {}) {
268
251
  const result = path.split(/\{([^}]+)\}/).map((part, i) => {
269
252
  if (i % 2 === 0) return part;
270
- const param = transformParam(part, casing);
253
+ const param = transformParam(part);
271
254
  return `\${${replacer ? replacer(param) : param}}`;
272
255
  }).join("");
273
256
  return `\`${prefix ?? ""}${result}\``;
@@ -275,8 +258,8 @@ var Url = class Url {
275
258
  /**
276
259
  * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
277
260
  * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
278
- * names are camelCased to match the generated `path` type, and `prefix` is prepended inside the
279
- * literal. Shared by the client and cypress generators that pass a grouped `path` object.
261
+ * names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
262
+ * the client and cypress generators that pass a grouped `path` object.
280
263
  *
281
264
  * @example
282
265
  * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
@@ -284,72 +267,25 @@ var Url = class Url {
284
267
  static toGroupedTemplateString(path, { prefix } = {}) {
285
268
  return Url.toTemplateString(path, {
286
269
  prefix,
287
- casing: "camelcase",
288
270
  replacer: (name) => `path.${name}`
289
271
  });
290
272
  }
291
- /**
292
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
293
- * expression when `stringify` is set.
294
- *
295
- * @example
296
- * Url.toObject('/pet/{petId}')
297
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
298
- */
299
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
300
- const object = {
301
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
302
- replacer,
303
- casing
304
- }),
305
- params: toParamsObject(path, {
306
- replacer,
307
- casing
308
- })
309
- };
310
- if (stringify) {
311
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
312
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
313
- return `{ url: '${object.url}' }`;
314
- }
315
- return object;
316
- }
317
273
  };
318
274
  //#endregion
319
275
  //#region ../../internals/shared/src/params.ts
320
- const caseParamsCache = /* @__PURE__ */ new WeakMap();
321
276
  /**
322
- * Applies camelCase to parameter names and returns a new array without mutating the input.
277
+ * Drops parameters that share the same name, keeping the first.
323
278
  *
324
- * Run it before handing parameters to schema builders so output property keys get the right casing
325
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
326
- * original array is returned unchanged. Results are cached per input array.
279
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
280
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
281
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
282
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
327
283
  */
328
- function caseParams(params, casing) {
329
- if (!casing) return params;
330
- const cached = caseParamsCache.get(params);
331
- if (cached) return cached;
332
- const result = params.map((param) => ({
333
- ...param,
334
- name: camelCase(param.name)
335
- }));
336
- caseParamsCache.set(params, result);
337
- return result;
338
- }
339
- /**
340
- * Drops parameters that collapse to the same property identity once camelCased, keeping the first.
341
- *
342
- * Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
343
- * `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
344
- * an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
345
- * identity so the resulting group is collision-free regardless of the names each caller carries.
346
- */
347
- function dedupeByCasedName(params) {
284
+ function dedupeParams(params) {
348
285
  const seen = /* @__PURE__ */ new Set();
349
286
  return params.filter((param) => {
350
- const key = camelCase(param.name);
351
- if (seen.has(key)) return false;
352
- seen.add(key);
287
+ if (seen.has(param.name)) return false;
288
+ seen.add(param.name);
353
289
  return true;
354
290
  });
355
291
  }
@@ -468,13 +404,15 @@ function buildOperationComments(node, options = {}) {
468
404
  if (!splitLines) return filteredComments;
469
405
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
470
406
  }
471
- function getOperationParameters(node, options = {}) {
472
- const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
407
+ function getOperationParameters(node) {
473
408
  return {
474
- path: dedupeByCasedName(params.filter((param) => param.in === "path")),
475
- query: dedupeByCasedName(params.filter((param) => param.in === "query")),
476
- header: dedupeByCasedName(params.filter((param) => param.in === "header")),
477
- cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
409
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
410
+ ...param,
411
+ name: camelCase(param.name)
412
+ })),
413
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
414
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
415
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
478
416
  };
479
417
  }
480
418
  function getStatusCodeNumber(statusCode) {
@@ -509,7 +447,7 @@ function resolveStatusCodeNames(node, resolver) {
509
447
  }
510
448
  const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
511
449
  function resolveOperationTypeNames(node, resolver, options = {}) {
512
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
450
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
513
451
  let byResolver = typeNamesByResolver.get(resolver);
514
452
  if (byResolver) {
515
453
  const cached = byResolver.get(cacheKey);
@@ -518,7 +456,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
518
456
  byResolver = /* @__PURE__ */ new Map();
519
457
  typeNamesByResolver.set(resolver, byResolver);
520
458
  }
521
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
459
+ const { path, query, header } = getOperationParameters(node);
522
460
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
523
461
  const exclude = new Set(options.exclude ?? []);
524
462
  const paramNames = options.includeParams === false ? [] : [
@@ -807,7 +745,7 @@ function resolveFallbackPageParamType(initialPageParam) {
807
745
  * so callers can reuse it when rewriting the paginated request.
808
746
  */
809
747
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
810
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
748
+ const firstQueryParam = getOperationParameters(node).query[0];
811
749
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
812
750
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
813
751
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1308,7 +1246,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
1308
1246
  }
1309
1247
  if (isInfiniteOp) {
1310
1248
  const normalizeKey = (key) => key.replace(/\?$/, "");
1311
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1249
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1312
1250
  if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
1313
1251
  const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
1314
1252
  const infiniteHookName = resolver.infiniteQuery.name(node);
@@ -1716,7 +1654,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1716
1654
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1717
1655
  if (!isQuery || isMutation || !infiniteOptions) return null;
1718
1656
  const normalizeKey = (key) => key.replace(/\?$/, "");
1719
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1657
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1720
1658
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1721
1659
  const importPath = query ? query.importPath : "@tanstack/react-query";
1722
1660
  const contractOp = resolveClientOperation({
@@ -1745,7 +1683,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1745
1683
  group: pluginTs.options?.group ?? void 0
1746
1684
  })
1747
1685
  };
1748
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
1686
+ const rawQueryParams = getOperationParameters(node).query;
1749
1687
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
1750
1688
  const importedTypeNames = [
1751
1689
  tsResolver.response.options(node),
@@ -2168,7 +2106,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2168
2106
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
2169
2107
  if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
2170
2108
  const normalizeKey = (key) => key.replace(/\?$/, "");
2171
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
2109
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
2172
2110
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
2173
2111
  const importPath = query ? query.importPath : "@tanstack/react-query";
2174
2112
  const contractOp = resolveClientOperation({
@@ -2197,7 +2135,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2197
2135
  group: pluginTs.options?.group ?? void 0
2198
2136
  })
2199
2137
  };
2200
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
2138
+ const rawQueryParams = getOperationParameters(node).query;
2201
2139
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
2202
2140
  const importedTypeNames = [
2203
2141
  tsResolver.response.options(node),