@kubb/plugin-swr 5.1.0-canary.20260907T104725 → 5.1.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 +33 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -425,6 +425,9 @@ function resolveContractClient(options) {
|
|
|
425
425
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
426
426
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
427
427
|
* one computed result instead of each re-deriving the name and path.
|
|
428
|
+
*
|
|
429
|
+
* `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
|
|
430
|
+
* dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
|
|
428
431
|
*/
|
|
429
432
|
function resolveClientOperation(options) {
|
|
430
433
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
@@ -441,7 +444,8 @@ function resolveClientOperation(options) {
|
|
|
441
444
|
return {
|
|
442
445
|
name: resolver.name(node.operationId),
|
|
443
446
|
path: file.path,
|
|
444
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
447
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts"),
|
|
448
|
+
returnType: plugin?.options?.returnType ?? "full"
|
|
445
449
|
};
|
|
446
450
|
});
|
|
447
451
|
}
|
|
@@ -548,6 +552,24 @@ function buildClientCall(node, options) {
|
|
|
548
552
|
].filter((part) => part !== null).join(", ")} })`;
|
|
549
553
|
}
|
|
550
554
|
/**
|
|
555
|
+
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
556
|
+
* success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
|
|
557
|
+
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
558
|
+
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
559
|
+
* off the full result by hand.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```ts
|
|
563
|
+
* buildCallResultBody(buildClientCall(node, { clientName: 'getPetById' }))
|
|
564
|
+
* // return getPetById({ ...config, throwOnError: true }).unwrap()
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
function buildCallResultBody(call, options = {}) {
|
|
568
|
+
const { returnType = "full" } = options;
|
|
569
|
+
if (returnType === "data") return `return await ${call}`;
|
|
570
|
+
return `return ${call}.unwrap()`;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
551
573
|
* Applies the shared query defaults during plugin setup: `false` disables query generation, and an
|
|
552
574
|
* object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
|
|
553
575
|
*/
|
|
@@ -755,7 +777,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
755
777
|
default: "{}"
|
|
756
778
|
})] });
|
|
757
779
|
}
|
|
758
|
-
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver }) {
|
|
780
|
+
function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, mutationArgTypeName, node, tsResolver, returnType = "full" }) {
|
|
759
781
|
const responseName = tsResolver.response.response(node);
|
|
760
782
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
761
783
|
const TData = responseName;
|
|
@@ -765,10 +787,10 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
765
787
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
766
788
|
const argTypeBody = hasMutationParams ? tsResolver.response.options(node) : "";
|
|
767
789
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
|
|
768
|
-
const mutationFnBody =
|
|
790
|
+
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
769
791
|
clientName,
|
|
770
792
|
signal: false
|
|
771
|
-
})}
|
|
793
|
+
}), { returnType });
|
|
772
794
|
const generics = [
|
|
773
795
|
TData,
|
|
774
796
|
TError,
|
|
@@ -904,13 +926,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
904
926
|
//#endregion
|
|
905
927
|
//#region src/components/QueryOptions.tsx
|
|
906
928
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
907
|
-
function QueryOptions({ name, clientName, node, tsResolver }) {
|
|
929
|
+
function QueryOptions({ name, clientName, node, tsResolver, returnType = "full" }) {
|
|
908
930
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
909
931
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
910
|
-
const fetcherBody =
|
|
932
|
+
const fetcherBody = buildCallResultBody(buildClientCall(node, {
|
|
911
933
|
clientName,
|
|
912
934
|
signal: false
|
|
913
|
-
})}
|
|
935
|
+
}), { returnType });
|
|
914
936
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
915
937
|
name,
|
|
916
938
|
isExportable: true,
|
|
@@ -1050,7 +1072,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1050
1072
|
mutationKeyTypeName,
|
|
1051
1073
|
mutationArgTypeName,
|
|
1052
1074
|
node,
|
|
1053
|
-
tsResolver
|
|
1075
|
+
tsResolver,
|
|
1076
|
+
returnType: contractOp.returnType
|
|
1054
1077
|
})
|
|
1055
1078
|
] })
|
|
1056
1079
|
]
|
|
@@ -1166,7 +1189,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1166
1189
|
name: queryOptionsName,
|
|
1167
1190
|
clientName: calledClientName,
|
|
1168
1191
|
node,
|
|
1169
|
-
tsResolver
|
|
1192
|
+
tsResolver,
|
|
1193
|
+
returnType: contractOp.returnType
|
|
1170
1194
|
}),
|
|
1171
1195
|
query && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1172
1196
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|