@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.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
2
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
3
+ import "@kubb/plugin-ts";
4
+ import "kubb/jsx";
5
+ import "@kubb/plugin-zod";
3
6
  //#region ../../internals/client/src/resolveClient.d.ts
4
7
  /**
5
8
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
3
2
  import path from "node:path";
3
+ import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
4
4
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
5
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
@@ -179,33 +179,17 @@ function getNestedAccessor(param, accessor) {
179
179
  }
180
180
  //#endregion
181
181
  //#region ../../internals/utils/src/url.ts
182
- function transformParam(raw, casing) {
183
- const param = isValidVarName(raw) ? raw : camelCase(raw);
184
- return casing === "camelcase" ? camelCase(param) : param;
185
- }
186
- function toParamsObject(path, { replacer, casing } = {}) {
187
- const params = {};
188
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
189
- const param = transformParam(match[1], casing);
190
- const key = replacer ? replacer(param) : param;
191
- params[key] = key;
192
- }
193
- return Object.keys(params).length > 0 ? params : null;
182
+ /**
183
+ * Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
184
+ * camelCases it only enough to become one otherwise (for example a hyphenated path segment).
185
+ */
186
+ function transformParam(raw) {
187
+ return isValidVarName(raw) ? raw : camelCase(raw);
194
188
  }
195
189
  /**
196
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
190
+ * Helpers for OpenAPI/Swagger paths.
197
191
  */
198
192
  var Url = class Url {
199
- /**
200
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
201
- *
202
- * @example
203
- * Url.canParse('https://petstore.swagger.io/v2') // true
204
- * Url.canParse('/pet/{petId}') // false
205
- */
206
- static canParse(url, base) {
207
- return URL.canParse(url, base);
208
- }
209
193
  /**
210
194
  * Converts an OpenAPI/Swagger path to Express-style colon syntax.
211
195
  *
@@ -221,15 +205,14 @@ var Url = class Url {
221
205
  * key.
222
206
  *
223
207
  * @example
224
- * Url.toCasedTemplate('/projects/{project_id}', { casing: 'camelcase' }) // '/projects/{projectId}'
208
+ * Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
225
209
  */
226
- static toCasedTemplate(path, { casing } = {}) {
227
- return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name, casing)}}`);
210
+ static toSafeTemplate(path) {
211
+ return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
228
212
  }
229
213
  /**
230
214
  * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
231
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
232
- * and `casing` controls parameter identifier casing.
215
+ * `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
233
216
  *
234
217
  * @example
235
218
  * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
@@ -237,10 +220,10 @@ var Url = class Url {
237
220
  * @example
238
221
  * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
239
222
  */
240
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
223
+ static toTemplateString(path, { prefix, replacer } = {}) {
241
224
  const result = path.split(/\{([^}]+)\}/).map((part, i) => {
242
225
  if (i % 2 === 0) return part;
243
- const param = transformParam(part, casing);
226
+ const param = transformParam(part);
244
227
  return `\${${replacer ? replacer(param) : param}}`;
245
228
  }).join("");
246
229
  return `\`${prefix ?? ""}${result}\``;
@@ -248,8 +231,8 @@ var Url = class Url {
248
231
  /**
249
232
  * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
250
233
  * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
251
- * names are camelCased to match the generated `path` type, and `prefix` is prepended inside the
252
- * literal. Shared by the client and cypress generators that pass a grouped `path` object.
234
+ * names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
235
+ * the client and cypress generators that pass a grouped `path` object.
253
236
  *
254
237
  * @example
255
238
  * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
@@ -257,72 +240,25 @@ var Url = class Url {
257
240
  static toGroupedTemplateString(path, { prefix } = {}) {
258
241
  return Url.toTemplateString(path, {
259
242
  prefix,
260
- casing: "camelcase",
261
243
  replacer: (name) => `path.${name}`
262
244
  });
263
245
  }
264
- /**
265
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
266
- * expression when `stringify` is set.
267
- *
268
- * @example
269
- * Url.toObject('/pet/{petId}')
270
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
271
- */
272
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
273
- const object = {
274
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
275
- replacer,
276
- casing
277
- }),
278
- params: toParamsObject(path, {
279
- replacer,
280
- casing
281
- })
282
- };
283
- if (stringify) {
284
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
285
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
286
- return `{ url: '${object.url}' }`;
287
- }
288
- return object;
289
- }
290
246
  };
291
247
  //#endregion
292
248
  //#region ../../internals/shared/src/params.ts
293
- const caseParamsCache = /* @__PURE__ */ new WeakMap();
294
249
  /**
295
- * Applies camelCase to parameter names and returns a new array without mutating the input.
250
+ * Drops parameters that share the same name, keeping the first.
296
251
  *
297
- * Run it before handing parameters to schema builders so output property keys get the right casing
298
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
299
- * original array is returned unchanged. Results are cached per input array.
252
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
253
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
254
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
255
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
300
256
  */
301
- function caseParams(params, casing) {
302
- if (!casing) return params;
303
- const cached = caseParamsCache.get(params);
304
- if (cached) return cached;
305
- const result = params.map((param) => ({
306
- ...param,
307
- name: camelCase(param.name)
308
- }));
309
- caseParamsCache.set(params, result);
310
- return result;
311
- }
312
- /**
313
- * Drops parameters that collapse to the same property identity once camelCased, keeping the first.
314
- *
315
- * Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
316
- * `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
317
- * an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
318
- * identity so the resulting group is collision-free regardless of the names each caller carries.
319
- */
320
- function dedupeByCasedName(params) {
257
+ function dedupeParams(params) {
321
258
  const seen = /* @__PURE__ */ new Set();
322
259
  return params.filter((param) => {
323
- const key = camelCase(param.name);
324
- if (seen.has(key)) return false;
325
- seen.add(key);
260
+ if (seen.has(param.name)) return false;
261
+ seen.add(param.name);
326
262
  return true;
327
263
  });
328
264
  }
@@ -441,13 +377,15 @@ function buildOperationComments(node, options = {}) {
441
377
  if (!splitLines) return filteredComments;
442
378
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
443
379
  }
444
- function getOperationParameters(node, options = {}) {
445
- const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
380
+ function getOperationParameters(node) {
446
381
  return {
447
- path: dedupeByCasedName(params.filter((param) => param.in === "path")),
448
- query: dedupeByCasedName(params.filter((param) => param.in === "query")),
449
- header: dedupeByCasedName(params.filter((param) => param.in === "header")),
450
- cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
382
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
383
+ ...param,
384
+ name: camelCase(param.name)
385
+ })),
386
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
387
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
388
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
451
389
  };
452
390
  }
453
391
  function getStatusCodeNumber(statusCode) {
@@ -482,7 +420,7 @@ function resolveStatusCodeNames(node, resolver) {
482
420
  }
483
421
  const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
484
422
  function resolveOperationTypeNames(node, resolver, options = {}) {
485
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
423
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
486
424
  let byResolver = typeNamesByResolver.get(resolver);
487
425
  if (byResolver) {
488
426
  const cached = byResolver.get(cacheKey);
@@ -491,7 +429,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
491
429
  byResolver = /* @__PURE__ */ new Map();
492
430
  typeNamesByResolver.set(resolver, byResolver);
493
431
  }
494
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
432
+ const { path, query, header } = getOperationParameters(node);
495
433
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
496
434
  const exclude = new Set(options.exclude ?? []);
497
435
  const paramNames = options.includeParams === false ? [] : [
@@ -780,7 +718,7 @@ function resolveFallbackPageParamType(initialPageParam) {
780
718
  * so callers can reuse it when rewriting the paginated request.
781
719
  */
782
720
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
783
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
721
+ const firstQueryParam = getOperationParameters(node).query[0];
784
722
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
785
723
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
786
724
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1281,7 +1219,7 @@ const hookOptionsGenerator = defineGenerator({
1281
1219
  }
1282
1220
  if (isInfiniteOp) {
1283
1221
  const normalizeKey = (key) => key.replace(/\?$/, "");
1284
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1222
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1285
1223
  if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
1286
1224
  const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
1287
1225
  const infiniteHookName = resolver.infiniteQuery.name(node);
@@ -1689,7 +1627,7 @@ const infiniteQueryGenerator = defineGenerator({
1689
1627
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1690
1628
  if (!isQuery || isMutation || !infiniteOptions) return null;
1691
1629
  const normalizeKey = (key) => key.replace(/\?$/, "");
1692
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1630
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1693
1631
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1694
1632
  const importPath = query ? query.importPath : "@tanstack/react-query";
1695
1633
  const contractOp = resolveClientOperation({
@@ -1718,7 +1656,7 @@ const infiniteQueryGenerator = defineGenerator({
1718
1656
  group: pluginTs.options?.group ?? void 0
1719
1657
  })
1720
1658
  };
1721
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
1659
+ const rawQueryParams = getOperationParameters(node).query;
1722
1660
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
1723
1661
  const importedTypeNames = [
1724
1662
  tsResolver.response.options(node),
@@ -2141,7 +2079,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
2141
2079
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
2142
2080
  if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
2143
2081
  const normalizeKey = (key) => key.replace(/\?$/, "");
2144
- const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
2082
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
2145
2083
  if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
2146
2084
  const importPath = query ? query.importPath : "@tanstack/react-query";
2147
2085
  const contractOp = resolveClientOperation({
@@ -2170,7 +2108,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
2170
2108
  group: pluginTs.options?.group ?? void 0
2171
2109
  })
2172
2110
  };
2173
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
2111
+ const rawQueryParams = getOperationParameters(node).query;
2174
2112
  const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
2175
2113
  const importedTypeNames = [
2176
2114
  tsResolver.response.options(node),