@kubb/plugin-swr 5.6.0-canary.20261025T193222 → 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.cjs +296 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -15
- package/dist/index.d.ts +1 -15
- package/dist/index.js +295 -62
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
|
|
5
|
+
// \0rolldown/runtime.js
|
|
6
6
|
var __create = Object.create;
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
26
|
let kubb_kit = require("kubb/kit");
|
|
28
27
|
let node_path = require("node:path");
|
|
29
28
|
node_path = __toESM(node_path, 1);
|
|
@@ -31,7 +30,7 @@ let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
|
31
30
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
32
31
|
let kubb_jsx = require("kubb/jsx");
|
|
33
32
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
34
|
-
|
|
33
|
+
// ../../internals/shared/src/operation.ts
|
|
35
34
|
/**
|
|
36
35
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
37
36
|
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
@@ -100,6 +99,24 @@ function getContentTypeInfo(node) {
|
|
|
100
99
|
function getResponseContentTypeInfo(node) {
|
|
101
100
|
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
102
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads the single base content type of an operation's primary success response, lowercased and
|
|
104
|
+
* stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or
|
|
105
|
+
* more than one content type, since neither case has a single type to act on.
|
|
106
|
+
*/
|
|
107
|
+
function getPrimarySuccessContentType(node) {
|
|
108
|
+
const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? [];
|
|
109
|
+
if (contentTypes.length !== 1) return void 0;
|
|
110
|
+
return contentTypes[0].split(";")[0].trim().toLowerCase();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether an operation streams its primary success response as Server-Sent Events
|
|
114
|
+
* (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
|
|
115
|
+
* one-shot `RequestResult`.
|
|
116
|
+
*/
|
|
117
|
+
function isEventStream(node) {
|
|
118
|
+
return getPrimarySuccessContentType(node) === "text/event-stream";
|
|
119
|
+
}
|
|
103
120
|
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
104
121
|
function buildRequestConfigType(node) {
|
|
105
122
|
const request = getContentTypeInfo(node);
|
|
@@ -191,6 +208,22 @@ function getOperationParameters(node) {
|
|
|
191
208
|
operationParameterGroupsByNode.set(node, groups);
|
|
192
209
|
return groups;
|
|
193
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Builds the combined `{ body, path, query, headers }` options object schema for an operation,
|
|
213
|
+
* referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
|
|
214
|
+
* `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
|
|
215
|
+
* shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
|
|
216
|
+
* printer to emit `z.object(…)` rather than a record.
|
|
217
|
+
*/
|
|
218
|
+
function hasRequestContentTypeChoice(node) {
|
|
219
|
+
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
|
|
223
|
+
*/
|
|
224
|
+
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
225
|
+
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
226
|
+
}
|
|
194
227
|
function getStatusCodeNumber(statusCode) {
|
|
195
228
|
const code = Number(statusCode);
|
|
196
229
|
return Number.isNaN(code) ? null : code;
|
|
@@ -253,8 +286,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
253
286
|
byResolver.set(cacheKey, result);
|
|
254
287
|
return result;
|
|
255
288
|
}
|
|
256
|
-
|
|
257
|
-
//#region ../../internals/utils/src/casing.ts
|
|
289
|
+
// ../../internals/utils/src/casing.ts
|
|
258
290
|
/**
|
|
259
291
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
260
292
|
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
@@ -301,8 +333,168 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
301
333
|
function capitalize(text) {
|
|
302
334
|
return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
303
335
|
}
|
|
304
|
-
|
|
305
|
-
|
|
336
|
+
// ../../internals/utils/src/reserved.ts
|
|
337
|
+
/**
|
|
338
|
+
* JavaScript and Java reserved words.
|
|
339
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
340
|
+
*/
|
|
341
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
342
|
+
"abstract",
|
|
343
|
+
"arguments",
|
|
344
|
+
"await",
|
|
345
|
+
"boolean",
|
|
346
|
+
"break",
|
|
347
|
+
"byte",
|
|
348
|
+
"case",
|
|
349
|
+
"catch",
|
|
350
|
+
"char",
|
|
351
|
+
"class",
|
|
352
|
+
"const",
|
|
353
|
+
"continue",
|
|
354
|
+
"debugger",
|
|
355
|
+
"default",
|
|
356
|
+
"delete",
|
|
357
|
+
"do",
|
|
358
|
+
"double",
|
|
359
|
+
"else",
|
|
360
|
+
"enum",
|
|
361
|
+
"eval",
|
|
362
|
+
"export",
|
|
363
|
+
"extends",
|
|
364
|
+
"false",
|
|
365
|
+
"final",
|
|
366
|
+
"finally",
|
|
367
|
+
"float",
|
|
368
|
+
"for",
|
|
369
|
+
"function",
|
|
370
|
+
"goto",
|
|
371
|
+
"if",
|
|
372
|
+
"implements",
|
|
373
|
+
"import",
|
|
374
|
+
"in",
|
|
375
|
+
"instanceof",
|
|
376
|
+
"int",
|
|
377
|
+
"interface",
|
|
378
|
+
"let",
|
|
379
|
+
"long",
|
|
380
|
+
"native",
|
|
381
|
+
"new",
|
|
382
|
+
"null",
|
|
383
|
+
"package",
|
|
384
|
+
"private",
|
|
385
|
+
"protected",
|
|
386
|
+
"public",
|
|
387
|
+
"return",
|
|
388
|
+
"short",
|
|
389
|
+
"static",
|
|
390
|
+
"super",
|
|
391
|
+
"switch",
|
|
392
|
+
"synchronized",
|
|
393
|
+
"this",
|
|
394
|
+
"throw",
|
|
395
|
+
"throws",
|
|
396
|
+
"transient",
|
|
397
|
+
"true",
|
|
398
|
+
"try",
|
|
399
|
+
"typeof",
|
|
400
|
+
"var",
|
|
401
|
+
"void",
|
|
402
|
+
"volatile",
|
|
403
|
+
"while",
|
|
404
|
+
"with",
|
|
405
|
+
"yield",
|
|
406
|
+
"Array",
|
|
407
|
+
"Date",
|
|
408
|
+
"hasOwnProperty",
|
|
409
|
+
"Infinity",
|
|
410
|
+
"isFinite",
|
|
411
|
+
"isNaN",
|
|
412
|
+
"isPrototypeOf",
|
|
413
|
+
"length",
|
|
414
|
+
"Math",
|
|
415
|
+
"name",
|
|
416
|
+
"NaN",
|
|
417
|
+
"Number",
|
|
418
|
+
"Object",
|
|
419
|
+
"prototype",
|
|
420
|
+
"String",
|
|
421
|
+
"toString",
|
|
422
|
+
"undefined",
|
|
423
|
+
"valueOf"
|
|
424
|
+
]);
|
|
425
|
+
/**
|
|
426
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* isValidVarName('status') // true
|
|
431
|
+
* isValidVarName('class') // false (reserved word)
|
|
432
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
function isValidVarName(name) {
|
|
436
|
+
if (!name || reservedWords.has(name)) return false;
|
|
437
|
+
return isIdentifier(name);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
441
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
442
|
+
*
|
|
443
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
444
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
445
|
+
* variable, type, or function names.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* ensureValidVarName('409') // '_409'
|
|
450
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
451
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
452
|
+
* ensureValidVarName('class') // '_class'
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
function ensureValidVarName(name) {
|
|
456
|
+
if (!name || isValidVarName(name)) return name;
|
|
457
|
+
return `_${name}`;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
461
|
+
*
|
|
462
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
463
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
464
|
+
* deciding whether an object key needs quoting.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* isIdentifier('name') // true
|
|
469
|
+
* isIdentifier('x-total')// false
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
function isIdentifier(name) {
|
|
473
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
474
|
+
}
|
|
475
|
+
// ../../internals/shared/src/resolver.ts
|
|
476
|
+
function resolveOperationName(name) {
|
|
477
|
+
return ensureValidVarName(camelCase(name));
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
481
|
+
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
482
|
+
* name. Leave `scope` empty for the operation's own declaration.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
function operationKey(node, ...scope) {
|
|
490
|
+
return [
|
|
491
|
+
"operation",
|
|
492
|
+
node.method,
|
|
493
|
+
node.path,
|
|
494
|
+
...scope.map(String)
|
|
495
|
+
];
|
|
496
|
+
}
|
|
497
|
+
// ../../internals/shared/src/group.ts
|
|
306
498
|
/**
|
|
307
499
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
308
500
|
* shared default naming so every plugin groups output consistently:
|
|
@@ -332,17 +524,14 @@ function createGroupConfig(group) {
|
|
|
332
524
|
name: group.name ? group.name : defaultName
|
|
333
525
|
};
|
|
334
526
|
}
|
|
335
|
-
|
|
336
|
-
//#region kubb-extension.json
|
|
527
|
+
// kubb-extension.json
|
|
337
528
|
var compatibility = {
|
|
338
|
-
"kubb": ">=5.
|
|
529
|
+
"kubb": ">=5.14.6",
|
|
339
530
|
"node": ">=22.22"
|
|
340
531
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
532
|
+
// package.json
|
|
533
|
+
var version = "5.6.0";
|
|
534
|
+
// ../../internals/client/src/resolveOperationTypes.ts
|
|
346
535
|
/**
|
|
347
536
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
348
537
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -408,8 +597,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
408
597
|
group: pluginZod.options.group ?? void 0
|
|
409
598
|
};
|
|
410
599
|
}
|
|
411
|
-
|
|
412
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
600
|
+
// ../../internals/client/src/resolveClient.ts
|
|
413
601
|
/**
|
|
414
602
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
415
603
|
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
@@ -519,8 +707,7 @@ function resolveContractClient(options) {
|
|
|
519
707
|
}
|
|
520
708
|
return resolved;
|
|
521
709
|
}
|
|
522
|
-
|
|
523
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
710
|
+
// ../../internals/client/src/resolveClientOperation.ts
|
|
524
711
|
function isRelativeImport(importPath) {
|
|
525
712
|
return importPath.startsWith(".");
|
|
526
713
|
}
|
|
@@ -567,8 +754,12 @@ function resolveClientOperation(options) {
|
|
|
567
754
|
group: operationOptions.group ?? void 0
|
|
568
755
|
});
|
|
569
756
|
const { importPath } = operationOptions;
|
|
757
|
+
const name = resolver.name(node.operationId);
|
|
570
758
|
return {
|
|
571
|
-
name: resolver.
|
|
759
|
+
name: resolver.resolveName({
|
|
760
|
+
key: operationKey(node),
|
|
761
|
+
name
|
|
762
|
+
}),
|
|
572
763
|
path: file.path,
|
|
573
764
|
clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
|
|
574
765
|
importPath,
|
|
@@ -579,8 +770,7 @@ function resolveClientOperation(options) {
|
|
|
579
770
|
};
|
|
580
771
|
});
|
|
581
772
|
}
|
|
582
|
-
|
|
583
|
-
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
773
|
+
// ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
584
774
|
/**
|
|
585
775
|
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
586
776
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
@@ -669,8 +859,7 @@ function HookFile({ hook, imports, children }) {
|
|
|
669
859
|
]
|
|
670
860
|
});
|
|
671
861
|
}
|
|
672
|
-
|
|
673
|
-
//#region ../../internals/tanstack-query/src/utils.ts
|
|
862
|
+
// ../../internals/tanstack-query/src/utils.ts
|
|
674
863
|
/**
|
|
675
864
|
* The grouped request options, ordered for both the destructured signature and the
|
|
676
865
|
* call passed to the underlying client.
|
|
@@ -693,7 +882,7 @@ const requestGroupOrder = [
|
|
|
693
882
|
* `MaybeRefOrGetter` per group.
|
|
694
883
|
*/
|
|
695
884
|
function buildGroupedRequestParam(node, options) {
|
|
696
|
-
const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
|
|
885
|
+
const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
|
|
697
886
|
const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
|
|
698
887
|
const names = keys.filter((key) => groups[key]);
|
|
699
888
|
if (names.length === 0) return null;
|
|
@@ -705,6 +894,11 @@ function buildGroupedRequestParam(node, options) {
|
|
|
705
894
|
};
|
|
706
895
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
707
896
|
const optionsName = resolver.response.options(node);
|
|
897
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
898
|
+
name: "variables",
|
|
899
|
+
type: optionsName,
|
|
900
|
+
optional: false
|
|
901
|
+
});
|
|
708
902
|
const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
|
|
709
903
|
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
710
904
|
if (memberTypeWrapper) {
|
|
@@ -762,14 +956,17 @@ function buildQueryOptionsParams(node, options) {
|
|
|
762
956
|
* ```
|
|
763
957
|
*/
|
|
764
958
|
function buildClientCall(node, options) {
|
|
765
|
-
const { clientName, signal = false, unwrapName } = options;
|
|
959
|
+
const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
|
|
766
960
|
const { groups } = getRequestGroupOptionality(node);
|
|
767
|
-
|
|
961
|
+
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
962
|
+
const args = [
|
|
768
963
|
"...config",
|
|
769
|
-
...
|
|
964
|
+
...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
|
|
770
965
|
signal ? "signal: config.signal ?? signal" : null,
|
|
771
966
|
"throwOnError: true"
|
|
772
|
-
].filter((part) => part !== null)
|
|
967
|
+
].filter((part) => part !== null);
|
|
968
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
|
|
969
|
+
return `${clientName}({ ${args.join(", ")} })`;
|
|
773
970
|
}
|
|
774
971
|
/**
|
|
775
972
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
@@ -838,9 +1035,14 @@ function resolveMutationConfig(mutation, options) {
|
|
|
838
1035
|
/**
|
|
839
1036
|
* Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
|
|
840
1037
|
* Disabled query and mutation configs do not claim operations, and a method already claimed by an
|
|
841
|
-
* enabled query config never counts as a mutation.
|
|
1038
|
+
* enabled query config never counts as a mutation. Event streams are consumed through the client
|
|
1039
|
+
* directly, so they do not generate query or mutation hooks.
|
|
842
1040
|
*/
|
|
843
1041
|
function classifyOperation(node, { query, mutation }) {
|
|
1042
|
+
if (isEventStream(node)) return {
|
|
1043
|
+
isQuery: false,
|
|
1044
|
+
isMutation: false
|
|
1045
|
+
};
|
|
844
1046
|
const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
845
1047
|
const queryMethods = new Set(query ? query.methods : []);
|
|
846
1048
|
return {
|
|
@@ -888,8 +1090,7 @@ function buildHookParams(node, options) {
|
|
|
888
1090
|
}) : null;
|
|
889
1091
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
890
1092
|
}
|
|
891
|
-
|
|
892
|
-
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
1093
|
+
// ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
893
1094
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
894
1095
|
/**
|
|
895
1096
|
* Default `mutationKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -936,8 +1137,7 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
936
1137
|
})
|
|
937
1138
|
})] });
|
|
938
1139
|
}
|
|
939
|
-
|
|
940
|
-
//#region ../../internals/tanstack-query/src/resolver.ts
|
|
1140
|
+
// ../../internals/tanstack-query/src/resolver.ts
|
|
941
1141
|
/**
|
|
942
1142
|
* Builds the shared query namespace for a variant. Spread the result into
|
|
943
1143
|
* `createResolver` once per variant the plugin supports.
|
|
@@ -953,19 +1153,39 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
953
1153
|
function createQueryResolver(variant = "") {
|
|
954
1154
|
return {
|
|
955
1155
|
name(node) {
|
|
956
|
-
|
|
1156
|
+
const name = `use${capitalize(this.name(node.operationId))}${variant}`;
|
|
1157
|
+
return this.resolveName({
|
|
1158
|
+
key: operationKey(node, "query", variant, "name"),
|
|
1159
|
+
name
|
|
1160
|
+
});
|
|
957
1161
|
},
|
|
958
1162
|
optionsName(node) {
|
|
959
|
-
|
|
1163
|
+
const name = `${this.name(node.operationId)}${variant}QueryOptions`;
|
|
1164
|
+
return this.resolveName({
|
|
1165
|
+
key: operationKey(node, "query", variant, "optionsName"),
|
|
1166
|
+
name
|
|
1167
|
+
});
|
|
960
1168
|
},
|
|
961
1169
|
keyName(node) {
|
|
962
|
-
|
|
1170
|
+
const name = `${this.name(node.operationId)}${variant}QueryKey`;
|
|
1171
|
+
return this.resolveName({
|
|
1172
|
+
key: operationKey(node, "query", variant, "keyName"),
|
|
1173
|
+
name
|
|
1174
|
+
});
|
|
963
1175
|
},
|
|
964
1176
|
keyTypeName(node) {
|
|
965
|
-
|
|
1177
|
+
const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
|
|
1178
|
+
return this.resolveName({
|
|
1179
|
+
key: operationKey(node, "query", variant, "keyTypeName"),
|
|
1180
|
+
name
|
|
1181
|
+
});
|
|
966
1182
|
},
|
|
967
1183
|
clientName(node) {
|
|
968
|
-
|
|
1184
|
+
const name = `${this.name(node.operationId)}${variant}`;
|
|
1185
|
+
return this.resolveName({
|
|
1186
|
+
key: operationKey(node, "query", variant, "clientName"),
|
|
1187
|
+
name
|
|
1188
|
+
});
|
|
969
1189
|
}
|
|
970
1190
|
};
|
|
971
1191
|
}
|
|
@@ -982,15 +1202,22 @@ function createQueryResolver(variant = "") {
|
|
|
982
1202
|
function createMutationResolver() {
|
|
983
1203
|
return {
|
|
984
1204
|
name(node) {
|
|
985
|
-
|
|
1205
|
+
const name = `use${capitalize(this.name(node.operationId))}`;
|
|
1206
|
+
return this.resolveName({
|
|
1207
|
+
key: operationKey(node, "mutation", "name"),
|
|
1208
|
+
name
|
|
1209
|
+
});
|
|
986
1210
|
},
|
|
987
1211
|
keyName(node) {
|
|
988
|
-
|
|
1212
|
+
const name = `${this.name(node.operationId)}MutationKey`;
|
|
1213
|
+
return this.resolveName({
|
|
1214
|
+
key: operationKey(node, "mutation", "keyName"),
|
|
1215
|
+
name
|
|
1216
|
+
});
|
|
989
1217
|
}
|
|
990
1218
|
};
|
|
991
1219
|
}
|
|
992
|
-
|
|
993
|
-
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
1220
|
+
// ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
994
1221
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
995
1222
|
/**
|
|
996
1223
|
* Default `queryKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -1048,8 +1275,7 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1048
1275
|
})
|
|
1049
1276
|
})] });
|
|
1050
1277
|
}
|
|
1051
|
-
|
|
1052
|
-
//#region src/components/Mutation.tsx
|
|
1278
|
+
// src/components/Mutation.tsx
|
|
1053
1279
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1054
1280
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1055
1281
|
function buildMutationParamsNode(node, options) {
|
|
@@ -1067,14 +1293,19 @@ function buildMutationParamsNode(node, options) {
|
|
|
1067
1293
|
}
|
|
1068
1294
|
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver, returnType = "full" }) {
|
|
1069
1295
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1070
|
-
const groupedParam = buildGroupedRequestParam(node, {
|
|
1296
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
1297
|
+
resolver: tsResolver,
|
|
1298
|
+
withContentType: true
|
|
1299
|
+
});
|
|
1071
1300
|
const hasMutationParams = groupedParam !== null;
|
|
1072
1301
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1073
1302
|
const argTypeBody = hasMutationParams ? tsResolver.response.options(node) : "";
|
|
1074
1303
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
|
|
1075
1304
|
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1076
1305
|
clientName,
|
|
1077
|
-
signal: false
|
|
1306
|
+
signal: false,
|
|
1307
|
+
withContentType: true,
|
|
1308
|
+
returnType
|
|
1078
1309
|
}), { returnType });
|
|
1079
1310
|
const generics = [
|
|
1080
1311
|
TData,
|
|
@@ -1122,8 +1353,7 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
1122
1353
|
})
|
|
1123
1354
|
})] });
|
|
1124
1355
|
}
|
|
1125
|
-
|
|
1126
|
-
//#region src/generators/mutationGenerator.tsx
|
|
1356
|
+
// src/generators/mutationGenerator.tsx
|
|
1127
1357
|
/**
|
|
1128
1358
|
* Built-in generator for `useSWRMutation` hooks. Emits one `useFooMutation` hook
|
|
1129
1359
|
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
@@ -1192,8 +1422,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1192
1422
|
});
|
|
1193
1423
|
}
|
|
1194
1424
|
});
|
|
1195
|
-
|
|
1196
|
-
//#region src/components/Query.tsx
|
|
1425
|
+
// src/components/Query.tsx
|
|
1197
1426
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1198
1427
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1199
1428
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
@@ -1247,8 +1476,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1247
1476
|
})
|
|
1248
1477
|
});
|
|
1249
1478
|
}
|
|
1250
|
-
|
|
1251
|
-
//#region src/components/QueryOptions.tsx
|
|
1479
|
+
// src/components/QueryOptions.tsx
|
|
1252
1480
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1253
1481
|
function QueryOptions({ name, clientName, node, tsResolver, returnType = "full" }) {
|
|
1254
1482
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
@@ -1275,8 +1503,7 @@ function QueryOptions({ name, clientName, node, tsResolver, returnType = "full"
|
|
|
1275
1503
|
})
|
|
1276
1504
|
});
|
|
1277
1505
|
}
|
|
1278
|
-
|
|
1279
|
-
//#region src/generators/queryGenerator.tsx
|
|
1506
|
+
// src/generators/queryGenerator.tsx
|
|
1280
1507
|
/**
|
|
1281
1508
|
* Built-in generator for `useSWR` hooks. Emits one `useFoo` hook per read operation plus the
|
|
1282
1509
|
* matching `fooQueryKey` helper and `fooQueryOptions` factory.
|
|
@@ -1356,14 +1583,13 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1356
1583
|
});
|
|
1357
1584
|
}
|
|
1358
1585
|
});
|
|
1359
|
-
|
|
1360
|
-
//#region src/resolvers/resolverSwr.ts
|
|
1586
|
+
// src/resolvers/resolverSwr.ts
|
|
1361
1587
|
/**
|
|
1362
1588
|
* Default resolver used by `@kubb/plugin-swr`. Decides the names and file paths for every generated
|
|
1363
1589
|
* SWR hook (`useFoo`, `useFooMutation`) and its companion helpers (`fooQueryKey`, `fooQueryOptions`,
|
|
1364
1590
|
* `fooMutationKey`).
|
|
1365
1591
|
*
|
|
1366
|
-
* Functions
|
|
1592
|
+
* Functions use safe camelCase identifiers; hooks get the `use` prefix.
|
|
1367
1593
|
*
|
|
1368
1594
|
* @example Resolve hook and helper names
|
|
1369
1595
|
* ```ts
|
|
@@ -1376,19 +1602,27 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1376
1602
|
*/
|
|
1377
1603
|
const resolverSwr = (0, kubb_kit.createResolver)({
|
|
1378
1604
|
pluginName: "plugin-swr",
|
|
1605
|
+
name: resolveOperationName,
|
|
1379
1606
|
query: createQueryResolver(),
|
|
1380
1607
|
mutation: {
|
|
1381
1608
|
...createMutationResolver(),
|
|
1382
1609
|
keyTypeName(node) {
|
|
1383
|
-
|
|
1610
|
+
const name = `${capitalize(this.name(node.operationId))}MutationKey`;
|
|
1611
|
+
return this.resolveName({
|
|
1612
|
+
key: operationKey(node, "mutation", "keyTypeName"),
|
|
1613
|
+
name
|
|
1614
|
+
});
|
|
1384
1615
|
},
|
|
1385
1616
|
argTypeName(node) {
|
|
1386
|
-
|
|
1617
|
+
const name = `${capitalize(this.name(node.operationId))}MutationArg`;
|
|
1618
|
+
return this.resolveName({
|
|
1619
|
+
key: operationKey(node, "mutation", "argTypeName"),
|
|
1620
|
+
name
|
|
1621
|
+
});
|
|
1387
1622
|
}
|
|
1388
1623
|
}
|
|
1389
1624
|
});
|
|
1390
|
-
|
|
1391
|
-
//#region src/plugin.ts
|
|
1625
|
+
// src/plugin.ts
|
|
1392
1626
|
/**
|
|
1393
1627
|
* Canonical plugin name for `@kubb/plugin-swr`. Used for driver lookups and cross-plugin
|
|
1394
1628
|
* dependency references.
|
|
@@ -1451,7 +1685,6 @@ const pluginSwr = (0, kubb_kit.defineExtension)({
|
|
|
1451
1685
|
};
|
|
1452
1686
|
}
|
|
1453
1687
|
});
|
|
1454
|
-
//#endregion
|
|
1455
1688
|
exports.default = pluginSwr;
|
|
1456
1689
|
exports.mutationKeyTransformer = mutationKeyTransformer;
|
|
1457
1690
|
exports.pluginSwr = pluginSwr;
|