@kubb/plugin-swr 5.6.0-canary.20261025T201031 → 5.6.0

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
@@ -4,8 +4,7 @@ import { createFunctionParameter, createFunctionParameters, createObjectBindingP
4
4
  import { pluginZodName } from "@kubb/plugin-zod";
5
5
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
7
- //#endregion
8
- //#region ../../internals/shared/src/operation.ts
7
+ // ../../internals/shared/src/operation.ts
9
8
  /**
10
9
  * Builds the `ResolverFileParams` every operation generator passes to
11
10
  * `resolver.file`: a file named `name`, tagged by the operation's first
@@ -74,6 +73,24 @@ function getContentTypeInfo(node) {
74
73
  function getResponseContentTypeInfo(node) {
75
74
  return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
76
75
  }
76
+ /**
77
+ * Reads the single base content type of an operation's primary success response, lowercased and
78
+ * stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or
79
+ * more than one content type, since neither case has a single type to act on.
80
+ */
81
+ function getPrimarySuccessContentType(node) {
82
+ const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? [];
83
+ if (contentTypes.length !== 1) return void 0;
84
+ return contentTypes[0].split(";")[0].trim().toLowerCase();
85
+ }
86
+ /**
87
+ * Whether an operation streams its primary success response as Server-Sent Events
88
+ * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
89
+ * one-shot `RequestResult`.
90
+ */
91
+ function isEventStream(node) {
92
+ return getPrimarySuccessContentType(node) === "text/event-stream";
93
+ }
77
94
  const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
78
95
  function buildRequestConfigType(node) {
79
96
  const request = getContentTypeInfo(node);
@@ -165,6 +182,22 @@ function getOperationParameters(node) {
165
182
  operationParameterGroupsByNode.set(node, groups);
166
183
  return groups;
167
184
  }
185
+ /**
186
+ * Builds the combined `{ body, path, query, headers }` options object schema for an operation,
187
+ * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
188
+ * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
189
+ * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
190
+ * printer to emit `z.object(…)` rather than a record.
191
+ */
192
+ function hasRequestContentTypeChoice(node) {
193
+ return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
194
+ }
195
+ /**
196
+ * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
197
+ */
198
+ function castToClientOptions(callArg, clientName, returnType = "full") {
199
+ return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
200
+ }
168
201
  function getStatusCodeNumber(statusCode) {
169
202
  const code = Number(statusCode);
170
203
  return Number.isNaN(code) ? null : code;
@@ -227,8 +260,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
227
260
  byResolver.set(cacheKey, result);
228
261
  return result;
229
262
  }
230
- //#endregion
231
- //#region ../../internals/utils/src/casing.ts
263
+ // ../../internals/utils/src/casing.ts
232
264
  /**
233
265
  * Shared implementation for camelCase and PascalCase conversion.
234
266
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -275,8 +307,168 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
275
307
  function capitalize(text) {
276
308
  return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
277
309
  }
278
- //#endregion
279
- //#region ../../internals/shared/src/group.ts
310
+ // ../../internals/utils/src/reserved.ts
311
+ /**
312
+ * JavaScript and Java reserved words.
313
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
314
+ */
315
+ const reservedWords = /* @__PURE__ */ new Set([
316
+ "abstract",
317
+ "arguments",
318
+ "await",
319
+ "boolean",
320
+ "break",
321
+ "byte",
322
+ "case",
323
+ "catch",
324
+ "char",
325
+ "class",
326
+ "const",
327
+ "continue",
328
+ "debugger",
329
+ "default",
330
+ "delete",
331
+ "do",
332
+ "double",
333
+ "else",
334
+ "enum",
335
+ "eval",
336
+ "export",
337
+ "extends",
338
+ "false",
339
+ "final",
340
+ "finally",
341
+ "float",
342
+ "for",
343
+ "function",
344
+ "goto",
345
+ "if",
346
+ "implements",
347
+ "import",
348
+ "in",
349
+ "instanceof",
350
+ "int",
351
+ "interface",
352
+ "let",
353
+ "long",
354
+ "native",
355
+ "new",
356
+ "null",
357
+ "package",
358
+ "private",
359
+ "protected",
360
+ "public",
361
+ "return",
362
+ "short",
363
+ "static",
364
+ "super",
365
+ "switch",
366
+ "synchronized",
367
+ "this",
368
+ "throw",
369
+ "throws",
370
+ "transient",
371
+ "true",
372
+ "try",
373
+ "typeof",
374
+ "var",
375
+ "void",
376
+ "volatile",
377
+ "while",
378
+ "with",
379
+ "yield",
380
+ "Array",
381
+ "Date",
382
+ "hasOwnProperty",
383
+ "Infinity",
384
+ "isFinite",
385
+ "isNaN",
386
+ "isPrototypeOf",
387
+ "length",
388
+ "Math",
389
+ "name",
390
+ "NaN",
391
+ "Number",
392
+ "Object",
393
+ "prototype",
394
+ "String",
395
+ "toString",
396
+ "undefined",
397
+ "valueOf"
398
+ ]);
399
+ /**
400
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
401
+ *
402
+ * @example
403
+ * ```ts
404
+ * isValidVarName('status') // true
405
+ * isValidVarName('class') // false (reserved word)
406
+ * isValidVarName('42foo') // false (starts with digit)
407
+ * ```
408
+ */
409
+ function isValidVarName(name) {
410
+ if (!name || reservedWords.has(name)) return false;
411
+ return isIdentifier(name);
412
+ }
413
+ /**
414
+ * Returns `name` when it's a syntactically valid JavaScript variable name,
415
+ * otherwise prefixes it with `_` so the result is a valid identifier.
416
+ *
417
+ * Useful for sanitizing OpenAPI schema names or operation IDs that start with
418
+ * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
419
+ * variable, type, or function names.
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * ensureValidVarName('409') // '_409'
424
+ * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
425
+ * ensureValidVarName('Pet') // 'Pet'
426
+ * ensureValidVarName('class') // '_class'
427
+ * ```
428
+ */
429
+ function ensureValidVarName(name) {
430
+ if (!name || isValidVarName(name)) return name;
431
+ return `_${name}`;
432
+ }
433
+ /**
434
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
435
+ *
436
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
437
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
438
+ * deciding whether an object key needs quoting.
439
+ *
440
+ * @example
441
+ * ```ts
442
+ * isIdentifier('name') // true
443
+ * isIdentifier('x-total')// false
444
+ * ```
445
+ */
446
+ function isIdentifier(name) {
447
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
448
+ }
449
+ // ../../internals/shared/src/resolver.ts
450
+ function resolveOperationName(name) {
451
+ return ensureValidVarName(camelCase(name));
452
+ }
453
+ /**
454
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
455
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
456
+ * name. Leave `scope` empty for the operation's own declaration.
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
461
+ * ```
462
+ */
463
+ function operationKey(node, ...scope) {
464
+ return [
465
+ "operation",
466
+ node.method,
467
+ node.path,
468
+ ...scope.map(String)
469
+ ];
470
+ }
471
+ // ../../internals/shared/src/group.ts
280
472
  /**
281
473
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
282
474
  * shared default naming so every plugin groups output consistently:
@@ -306,17 +498,14 @@ function createGroupConfig(group) {
306
498
  name: group.name ? group.name : defaultName
307
499
  };
308
500
  }
309
- //#endregion
310
- //#region kubb-extension.json
501
+ // kubb-extension.json
311
502
  var compatibility = {
312
- "kubb": ">=5.8.3",
503
+ "kubb": ">=5.14.6",
313
504
  "node": ">=22.22"
314
505
  };
315
- //#endregion
316
- //#region package.json
317
- var version = "5.6.0-canary.20261025T201031";
318
- //#endregion
319
- //#region ../../internals/client/src/resolveOperationTypes.ts
506
+ // package.json
507
+ var version = "5.6.0";
508
+ // ../../internals/client/src/resolveOperationTypes.ts
320
509
  /**
321
510
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
322
511
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -382,8 +571,7 @@ function resolveOperationTypes(driver, pluginName) {
382
571
  group: pluginZod.options.group ?? void 0
383
572
  };
384
573
  }
385
- //#endregion
386
- //#region ../../internals/client/src/resolveClient.ts
574
+ // ../../internals/client/src/resolveClient.ts
387
575
  /**
388
576
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
389
577
  * operation, shared so the selection rules and diagnostics stay in one place.
@@ -493,8 +681,7 @@ function resolveContractClient(options) {
493
681
  }
494
682
  return resolved;
495
683
  }
496
- //#endregion
497
- //#region ../../internals/client/src/resolveClientOperation.ts
684
+ // ../../internals/client/src/resolveClientOperation.ts
498
685
  function isRelativeImport(importPath) {
499
686
  return importPath.startsWith(".");
500
687
  }
@@ -541,8 +728,12 @@ function resolveClientOperation(options) {
541
728
  group: operationOptions.group ?? void 0
542
729
  });
543
730
  const { importPath } = operationOptions;
731
+ const name = resolver.name(node.operationId);
544
732
  return {
545
- name: resolver.name(node.operationId),
733
+ name: resolver.resolveName({
734
+ key: operationKey(node),
735
+ name
736
+ }),
546
737
  path: file.path,
547
738
  clientPath: importPath === void 0 ? path.resolve(root, ".kubb/client.ts") : resolveImportPath({
548
739
  importPath,
@@ -553,8 +744,7 @@ function resolveClientOperation(options) {
553
744
  };
554
745
  });
555
746
  }
556
- //#endregion
557
- //#region ../../internals/tanstack-query/src/components/HookFile.tsx
747
+ // ../../internals/tanstack-query/src/components/HookFile.tsx
558
748
  /**
559
749
  * Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
560
750
  * `pluginZod({ inferred: 'codec' })`), banner and footer.
@@ -643,8 +833,7 @@ function HookFile({ hook, imports, children }) {
643
833
  ]
644
834
  });
645
835
  }
646
- //#endregion
647
- //#region ../../internals/tanstack-query/src/utils.ts
836
+ // ../../internals/tanstack-query/src/utils.ts
648
837
  /**
649
838
  * The grouped request options, ordered for both the destructured signature and the
650
839
  * call passed to the underlying client.
@@ -667,7 +856,7 @@ const requestGroupOrder = [
667
856
  * `MaybeRefOrGetter` per group.
668
857
  */
669
858
  function buildGroupedRequestParam(node, options) {
670
- const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
859
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
671
860
  const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
672
861
  const names = keys.filter((key) => groups[key]);
673
862
  if (names.length === 0) return null;
@@ -679,6 +868,11 @@ function buildGroupedRequestParam(node, options) {
679
868
  };
680
869
  const isOptional = names.every((name) => !requiredByGroup[name]);
681
870
  const optionsName = resolver.response.options(node);
871
+ if (withContentType && hasRequestContentTypeChoice(node)) return createFunctionParameter({
872
+ name: "variables",
873
+ type: optionsName,
874
+ optional: false
875
+ });
682
876
  const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
683
877
  const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
684
878
  if (memberTypeWrapper) {
@@ -736,14 +930,17 @@ function buildQueryOptionsParams(node, options) {
736
930
  * ```
737
931
  */
738
932
  function buildClientCall(node, options) {
739
- const { clientName, signal = false, unwrapName } = options;
933
+ const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
740
934
  const { groups } = getRequestGroupOptionality(node);
741
- return `${clientName}({ ${[
935
+ const names = requestGroupOrder.filter((key) => groups[key]);
936
+ const args = [
742
937
  "...config",
743
- ...requestGroupOrder.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
938
+ ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
744
939
  signal ? "signal: config.signal ?? signal" : null,
745
940
  "throwOnError: true"
746
- ].filter((part) => part !== null).join(", ")} })`;
941
+ ].filter((part) => part !== null);
942
+ if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
943
+ return `${clientName}({ ${args.join(", ")} })`;
747
944
  }
748
945
  /**
749
946
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
@@ -812,9 +1009,14 @@ function resolveMutationConfig(mutation, options) {
812
1009
  /**
813
1010
  * Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
814
1011
  * Disabled query and mutation configs do not claim operations, and a method already claimed by an
815
- * enabled query config never counts as a mutation.
1012
+ * enabled query config never counts as a mutation. Event streams are consumed through the client
1013
+ * directly, so they do not generate query or mutation hooks.
816
1014
  */
817
1015
  function classifyOperation(node, { query, mutation }) {
1016
+ if (isEventStream(node)) return {
1017
+ isQuery: false,
1018
+ isMutation: false
1019
+ };
818
1020
  const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
819
1021
  const queryMethods = new Set(query ? query.methods : []);
820
1022
  return {
@@ -862,8 +1064,7 @@ function buildHookParams(node, options) {
862
1064
  }) : null;
863
1065
  return createFunctionParameters({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
864
1066
  }
865
- //#endregion
866
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
1067
+ // ../../internals/tanstack-query/src/components/MutationKey.tsx
867
1068
  const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
868
1069
  /**
869
1070
  * Default `mutationKey` builder. Call it from a custom builder to extend the default key.
@@ -910,8 +1111,7 @@ function MutationKey({ name, node, transformer, typeName }) {
910
1111
  })
911
1112
  })] });
912
1113
  }
913
- //#endregion
914
- //#region ../../internals/tanstack-query/src/resolver.ts
1114
+ // ../../internals/tanstack-query/src/resolver.ts
915
1115
  /**
916
1116
  * Builds the shared query namespace for a variant. Spread the result into
917
1117
  * `createResolver` once per variant the plugin supports.
@@ -927,19 +1127,39 @@ function MutationKey({ name, node, transformer, typeName }) {
927
1127
  function createQueryResolver(variant = "") {
928
1128
  return {
929
1129
  name(node) {
930
- return `use${capitalize(this.name(node.operationId))}${variant}`;
1130
+ const name = `use${capitalize(this.name(node.operationId))}${variant}`;
1131
+ return this.resolveName({
1132
+ key: operationKey(node, "query", variant, "name"),
1133
+ name
1134
+ });
931
1135
  },
932
1136
  optionsName(node) {
933
- return `${this.name(node.operationId)}${variant}QueryOptions`;
1137
+ const name = `${this.name(node.operationId)}${variant}QueryOptions`;
1138
+ return this.resolveName({
1139
+ key: operationKey(node, "query", variant, "optionsName"),
1140
+ name
1141
+ });
934
1142
  },
935
1143
  keyName(node) {
936
- return `${this.name(node.operationId)}${variant}QueryKey`;
1144
+ const name = `${this.name(node.operationId)}${variant}QueryKey`;
1145
+ return this.resolveName({
1146
+ key: operationKey(node, "query", variant, "keyName"),
1147
+ name
1148
+ });
937
1149
  },
938
1150
  keyTypeName(node) {
939
- return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1151
+ const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1152
+ return this.resolveName({
1153
+ key: operationKey(node, "query", variant, "keyTypeName"),
1154
+ name
1155
+ });
940
1156
  },
941
1157
  clientName(node) {
942
- return `${this.name(node.operationId)}${variant}`;
1158
+ const name = `${this.name(node.operationId)}${variant}`;
1159
+ return this.resolveName({
1160
+ key: operationKey(node, "query", variant, "clientName"),
1161
+ name
1162
+ });
943
1163
  }
944
1164
  };
945
1165
  }
@@ -956,15 +1176,22 @@ function createQueryResolver(variant = "") {
956
1176
  function createMutationResolver() {
957
1177
  return {
958
1178
  name(node) {
959
- return `use${capitalize(this.name(node.operationId))}`;
1179
+ const name = `use${capitalize(this.name(node.operationId))}`;
1180
+ return this.resolveName({
1181
+ key: operationKey(node, "mutation", "name"),
1182
+ name
1183
+ });
960
1184
  },
961
1185
  keyName(node) {
962
- return `${this.name(node.operationId)}MutationKey`;
1186
+ const name = `${this.name(node.operationId)}MutationKey`;
1187
+ return this.resolveName({
1188
+ key: operationKey(node, "mutation", "keyName"),
1189
+ name
1190
+ });
963
1191
  }
964
1192
  };
965
1193
  }
966
- //#endregion
967
- //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
1194
+ // ../../internals/tanstack-query/src/components/QueryKey.tsx
968
1195
  const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
969
1196
  /**
970
1197
  * Default `queryKey` builder. Call it from a custom builder to extend the default key.
@@ -1022,8 +1249,7 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
1022
1249
  })
1023
1250
  })] });
1024
1251
  }
1025
- //#endregion
1026
- //#region src/components/Mutation.tsx
1252
+ // src/components/Mutation.tsx
1027
1253
  const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
1028
1254
  const callPrinter$1 = functionPrinter({ mode: "call" });
1029
1255
  function buildMutationParamsNode(node, options) {
@@ -1041,14 +1267,19 @@ function buildMutationParamsNode(node, options) {
1041
1267
  }
1042
1268
  function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver, returnType = "full" }) {
1043
1269
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1044
- const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1270
+ const groupedParam = buildGroupedRequestParam(node, {
1271
+ resolver: tsResolver,
1272
+ withContentType: true
1273
+ });
1045
1274
  const hasMutationParams = groupedParam !== null;
1046
1275
  const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
1047
1276
  const argTypeBody = hasMutationParams ? tsResolver.response.options(node) : "";
1048
1277
  const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
1049
1278
  const mutationFnBody = buildCallResultBody(buildClientCall(node, {
1050
1279
  clientName,
1051
- signal: false
1280
+ signal: false,
1281
+ withContentType: true,
1282
+ returnType
1052
1283
  }), { returnType });
1053
1284
  const generics = [
1054
1285
  TData,
@@ -1096,8 +1327,7 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
1096
1327
  })
1097
1328
  })] });
1098
1329
  }
1099
- //#endregion
1100
- //#region src/generators/mutationGenerator.tsx
1330
+ // src/generators/mutationGenerator.tsx
1101
1331
  /**
1102
1332
  * Built-in generator for `useSWRMutation` hooks. Emits one `useFooMutation` hook
1103
1333
  * per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
@@ -1166,8 +1396,7 @@ const mutationGenerator = defineGenerator({
1166
1396
  });
1167
1397
  }
1168
1398
  });
1169
- //#endregion
1170
- //#region src/components/Query.tsx
1399
+ // src/components/Query.tsx
1171
1400
  const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1172
1401
  const callPrinter = functionPrinter({ mode: "call" });
1173
1402
  function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
@@ -1221,8 +1450,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1221
1450
  })
1222
1451
  });
1223
1452
  }
1224
- //#endregion
1225
- //#region src/components/QueryOptions.tsx
1453
+ // src/components/QueryOptions.tsx
1226
1454
  const declarationPrinter = functionPrinter({ mode: "declaration" });
1227
1455
  function QueryOptions({ name, clientName, node, tsResolver, returnType = "full" }) {
1228
1456
  const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
@@ -1249,8 +1477,7 @@ function QueryOptions({ name, clientName, node, tsResolver, returnType = "full"
1249
1477
  })
1250
1478
  });
1251
1479
  }
1252
- //#endregion
1253
- //#region src/generators/queryGenerator.tsx
1480
+ // src/generators/queryGenerator.tsx
1254
1481
  /**
1255
1482
  * Built-in generator for `useSWR` hooks. Emits one `useFoo` hook per read operation plus the
1256
1483
  * matching `fooQueryKey` helper and `fooQueryOptions` factory.
@@ -1330,14 +1557,13 @@ const queryGenerator = defineGenerator({
1330
1557
  });
1331
1558
  }
1332
1559
  });
1333
- //#endregion
1334
- //#region src/resolvers/resolverSwr.ts
1560
+ // src/resolvers/resolverSwr.ts
1335
1561
  /**
1336
1562
  * Default resolver used by `@kubb/plugin-swr`. Decides the names and file paths for every generated
1337
1563
  * SWR hook (`useFoo`, `useFooMutation`) and its companion helpers (`fooQueryKey`, `fooQueryOptions`,
1338
1564
  * `fooMutationKey`).
1339
1565
  *
1340
- * Functions and files use the built-in camelCase casing; hooks get the `use` prefix.
1566
+ * Functions use safe camelCase identifiers; hooks get the `use` prefix.
1341
1567
  *
1342
1568
  * @example Resolve hook and helper names
1343
1569
  * ```ts
@@ -1350,19 +1576,27 @@ const queryGenerator = defineGenerator({
1350
1576
  */
1351
1577
  const resolverSwr = createResolver({
1352
1578
  pluginName: "plugin-swr",
1579
+ name: resolveOperationName,
1353
1580
  query: createQueryResolver(),
1354
1581
  mutation: {
1355
1582
  ...createMutationResolver(),
1356
1583
  keyTypeName(node) {
1357
- return `${capitalize(this.name(node.operationId))}MutationKey`;
1584
+ const name = `${capitalize(this.name(node.operationId))}MutationKey`;
1585
+ return this.resolveName({
1586
+ key: operationKey(node, "mutation", "keyTypeName"),
1587
+ name
1588
+ });
1358
1589
  },
1359
1590
  argTypeName(node) {
1360
- return `${capitalize(this.name(node.operationId))}MutationArg`;
1591
+ const name = `${capitalize(this.name(node.operationId))}MutationArg`;
1592
+ return this.resolveName({
1593
+ key: operationKey(node, "mutation", "argTypeName"),
1594
+ name
1595
+ });
1361
1596
  }
1362
1597
  }
1363
1598
  });
1364
- //#endregion
1365
- //#region src/plugin.ts
1599
+ // src/plugin.ts
1366
1600
  /**
1367
1601
  * Canonical plugin name for `@kubb/plugin-swr`. Used for driver lookups and cross-plugin
1368
1602
  * dependency references.
@@ -1425,7 +1659,6 @@ const pluginSwr = defineExtension({
1425
1659
  };
1426
1660
  }
1427
1661
  });
1428
- //#endregion
1429
1662
  export { pluginSwr as default, pluginSwr, mutationKeyTransformer, pluginSwrName, queryKeyTransformer, resolverSwr };
1430
1663
 
1431
1664
  //# sourceMappingURL=index.js.map