@kubb/plugin-swr 5.0.0-beta.80 → 5.0.0-beta.84
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 +85 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -167
- package/dist/index.js +41 -105
- package/dist/index.js.map +1 -1
- package/package.json +4 -7
package/dist/index.cjs
CHANGED
|
@@ -30,11 +30,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
//#endregion
|
|
31
31
|
let node_path = require("node:path");
|
|
32
32
|
node_path = __toESM(node_path, 1);
|
|
33
|
-
let
|
|
33
|
+
let kubb_kit = require("kubb/kit");
|
|
34
34
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
35
|
+
let kubb_jsx = require("kubb/jsx");
|
|
36
|
+
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
38
37
|
//#region ../../internals/utils/src/casing.ts
|
|
39
38
|
/**
|
|
40
39
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -555,16 +554,6 @@ function createGroupConfig(group) {
|
|
|
555
554
|
};
|
|
556
555
|
}
|
|
557
556
|
//#endregion
|
|
558
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
559
|
-
/**
|
|
560
|
-
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
561
|
-
*/
|
|
562
|
-
function isValidatorEnabled(validator) {
|
|
563
|
-
if (!validator) return false;
|
|
564
|
-
if (validator === "zod") return true;
|
|
565
|
-
return Boolean(validator.request || validator.response);
|
|
566
|
-
}
|
|
567
|
-
//#endregion
|
|
568
557
|
//#region ../../internals/client/src/resolveClient.ts
|
|
569
558
|
/**
|
|
570
559
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -671,11 +660,11 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
671
660
|
node,
|
|
672
661
|
casing: "camelcase"
|
|
673
662
|
});
|
|
674
|
-
return /* @__PURE__ */ (0,
|
|
663
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
675
664
|
name,
|
|
676
665
|
isExportable: true,
|
|
677
666
|
isIndexable: true,
|
|
678
|
-
children: /* @__PURE__ */ (0,
|
|
667
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
|
|
679
668
|
name,
|
|
680
669
|
export: true,
|
|
681
670
|
params: paramsSignature,
|
|
@@ -783,51 +772,6 @@ function buildClientCall(node, options) {
|
|
|
783
772
|
].filter((part) => part !== null).join(", ")} })`;
|
|
784
773
|
}
|
|
785
774
|
/**
|
|
786
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
787
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
788
|
-
*/
|
|
789
|
-
function resolveResponseParser(parser) {
|
|
790
|
-
if (!parser) return null;
|
|
791
|
-
if (parser === "zod") return "zod";
|
|
792
|
-
return parser.response ?? null;
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
796
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
797
|
-
*/
|
|
798
|
-
function resolveRequestParser(parser) {
|
|
799
|
-
if (!parser) return null;
|
|
800
|
-
if (parser === "zod") return "zod";
|
|
801
|
-
return parser.request ?? null;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
805
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
806
|
-
*/
|
|
807
|
-
function resolveQueryParamsParser(parser) {
|
|
808
|
-
if (!parser || parser === "zod") return null;
|
|
809
|
-
return parser.request ?? null;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
813
|
-
*
|
|
814
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
815
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
816
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
817
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
818
|
-
*
|
|
819
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
820
|
-
*/
|
|
821
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
822
|
-
if (!zodResolver || !parser) return [];
|
|
823
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
824
|
-
return [
|
|
825
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
826
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
827
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
828
|
-
].filter((n) => Boolean(n));
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
775
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
832
776
|
* typed from the operation's `RequestConfig` minus `url`. The query key transformer reads the
|
|
833
777
|
* grouped `path`/`query`/`body` bindings.
|
|
@@ -865,21 +809,21 @@ function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
|
865
809
|
node,
|
|
866
810
|
casing: "camelcase"
|
|
867
811
|
});
|
|
868
|
-
return /* @__PURE__ */ (0,
|
|
812
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
869
813
|
name,
|
|
870
814
|
isExportable: true,
|
|
871
815
|
isIndexable: true,
|
|
872
|
-
children: /* @__PURE__ */ (0,
|
|
816
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
|
|
873
817
|
name,
|
|
874
818
|
export: true,
|
|
875
819
|
params: paramsSignature,
|
|
876
820
|
singleLine: true,
|
|
877
821
|
children: `[${keys.join(", ")}] as const`
|
|
878
822
|
})
|
|
879
|
-
}), /* @__PURE__ */ (0,
|
|
823
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
880
824
|
name: typeName,
|
|
881
825
|
isTypeOnly: true,
|
|
882
|
-
children: /* @__PURE__ */ (0,
|
|
826
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
883
827
|
name: typeName,
|
|
884
828
|
children: `ReturnType<typeof ${name}>`
|
|
885
829
|
})
|
|
@@ -930,21 +874,21 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
930
874
|
resolver: tsResolver
|
|
931
875
|
});
|
|
932
876
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
933
|
-
return /* @__PURE__ */ (0,
|
|
877
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
934
878
|
name: mutationArgTypeName,
|
|
935
879
|
isExportable: true,
|
|
936
880
|
isIndexable: true,
|
|
937
881
|
isTypeOnly: true,
|
|
938
|
-
children: /* @__PURE__ */ (0,
|
|
882
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
939
883
|
name: mutationArgTypeName,
|
|
940
884
|
export: true,
|
|
941
885
|
children: hasMutationParams ? argTypeBody : "never"
|
|
942
886
|
})
|
|
943
|
-
}), /* @__PURE__ */ (0,
|
|
887
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
944
888
|
name,
|
|
945
889
|
isExportable: true,
|
|
946
890
|
isIndexable: true,
|
|
947
|
-
children: /* @__PURE__ */ (0,
|
|
891
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
948
892
|
name,
|
|
949
893
|
export: true,
|
|
950
894
|
params: paramsSignature,
|
|
@@ -967,16 +911,16 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
967
911
|
//#endregion
|
|
968
912
|
//#region src/components/MutationKey.tsx
|
|
969
913
|
function MutationKey({ name, typeName, node, transformer }) {
|
|
970
|
-
return /* @__PURE__ */ (0,
|
|
914
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey$1, {
|
|
971
915
|
name,
|
|
972
916
|
node,
|
|
973
917
|
transformer
|
|
974
|
-
}), /* @__PURE__ */ (0,
|
|
918
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
975
919
|
name: typeName,
|
|
976
920
|
isExportable: true,
|
|
977
921
|
isIndexable: true,
|
|
978
922
|
isTypeOnly: true,
|
|
979
|
-
children: /* @__PURE__ */ (0,
|
|
923
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
980
924
|
export: true,
|
|
981
925
|
name: typeName,
|
|
982
926
|
children: `ReturnType<typeof ${name}>`
|
|
@@ -997,11 +941,11 @@ function QueryOptions({ name, clientName, node, tsResolver }) {
|
|
|
997
941
|
signal: false
|
|
998
942
|
})}
|
|
999
943
|
return data`;
|
|
1000
|
-
return /* @__PURE__ */ (0,
|
|
944
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1001
945
|
name,
|
|
1002
946
|
isExportable: true,
|
|
1003
947
|
isIndexable: true,
|
|
1004
|
-
children: /* @__PURE__ */ (0,
|
|
948
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1005
949
|
name,
|
|
1006
950
|
export: true,
|
|
1007
951
|
params: paramsSignature,
|
|
@@ -1049,11 +993,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1049
993
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1050
994
|
const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
|
|
1051
995
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1052
|
-
return /* @__PURE__ */ (0,
|
|
996
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1053
997
|
name,
|
|
1054
998
|
isExportable: true,
|
|
1055
999
|
isIndexable: true,
|
|
1056
|
-
children: /* @__PURE__ */ (0,
|
|
1000
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1057
1001
|
name,
|
|
1058
1002
|
export: true,
|
|
1059
1003
|
params: paramsSignature,
|
|
@@ -1086,13 +1030,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1086
1030
|
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
1087
1031
|
* the matching `fooMutationKey` helper.
|
|
1088
1032
|
*/
|
|
1089
|
-
const mutationGenerator = (0,
|
|
1033
|
+
const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
1090
1034
|
name: "swr-mutation",
|
|
1091
|
-
renderer:
|
|
1035
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1092
1036
|
operation(node, ctx) {
|
|
1093
|
-
if (!
|
|
1037
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1094
1038
|
const { config, driver, resolver, root } = ctx;
|
|
1095
|
-
const { output, query, mutation,
|
|
1039
|
+
const { output, query, mutation, client, group } = ctx.options;
|
|
1096
1040
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1097
1041
|
if (!pluginTs) return null;
|
|
1098
1042
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1138,21 +1082,8 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1138
1082
|
order: "body-response-first",
|
|
1139
1083
|
includeParams: false
|
|
1140
1084
|
})].filter((name) => Boolean(name));
|
|
1141
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
|
|
1142
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : void 0;
|
|
1143
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
1144
|
-
name: node.operationId,
|
|
1145
|
-
extname: ".ts",
|
|
1146
|
-
tag: node.tags[0] ?? "default",
|
|
1147
|
-
path: node.path
|
|
1148
|
-
}, {
|
|
1149
|
-
root,
|
|
1150
|
-
output: pluginZod?.options?.output ?? output,
|
|
1151
|
-
group: pluginZod?.options?.group
|
|
1152
|
-
}) : void 0;
|
|
1153
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1154
1085
|
const calledClientName = contractOp.name;
|
|
1155
|
-
return /* @__PURE__ */ (0,
|
|
1086
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1156
1087
|
baseName: meta.file.baseName,
|
|
1157
1088
|
path: meta.file.path,
|
|
1158
1089
|
meta: meta.file.meta,
|
|
@@ -1173,45 +1104,40 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1173
1104
|
}
|
|
1174
1105
|
}),
|
|
1175
1106
|
children: [
|
|
1176
|
-
|
|
1177
|
-
name: zodSchemaNames,
|
|
1178
|
-
root: meta.file.path,
|
|
1179
|
-
path: fileZod.path
|
|
1180
|
-
}),
|
|
1181
|
-
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1107
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1182
1108
|
name: [contractOp.name],
|
|
1183
1109
|
root: meta.file.path,
|
|
1184
1110
|
path: contractOp.path
|
|
1185
1111
|
}),
|
|
1186
|
-
/* @__PURE__ */ (0,
|
|
1112
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1187
1113
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1188
1114
|
root: meta.file.path,
|
|
1189
1115
|
path: contractOp.clientPath,
|
|
1190
1116
|
isTypeOnly: true
|
|
1191
1117
|
}),
|
|
1192
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1118
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1193
1119
|
name: Array.from(new Set(importedTypeNames)),
|
|
1194
1120
|
root: meta.file.path,
|
|
1195
1121
|
path: meta.fileTs.path,
|
|
1196
1122
|
isTypeOnly: true
|
|
1197
1123
|
}),
|
|
1198
|
-
/* @__PURE__ */ (0,
|
|
1124
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1199
1125
|
name: mutationKeyName,
|
|
1200
1126
|
typeName: mutationKeyTypeName,
|
|
1201
1127
|
node,
|
|
1202
1128
|
transformer: ctx.options.mutationKey
|
|
1203
1129
|
}),
|
|
1204
|
-
mutation && /* @__PURE__ */ (0,
|
|
1205
|
-
/* @__PURE__ */ (0,
|
|
1130
|
+
mutation && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1131
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1206
1132
|
name: "useSWRMutation",
|
|
1207
1133
|
path: importPath
|
|
1208
1134
|
}),
|
|
1209
|
-
/* @__PURE__ */ (0,
|
|
1135
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1210
1136
|
name: ["SWRMutationConfiguration"],
|
|
1211
1137
|
path: importPath,
|
|
1212
1138
|
isTypeOnly: true
|
|
1213
1139
|
}),
|
|
1214
|
-
/* @__PURE__ */ (0,
|
|
1140
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1215
1141
|
name: mutationHookName,
|
|
1216
1142
|
clientName: calledClientName,
|
|
1217
1143
|
mutationKeyName,
|
|
@@ -1227,13 +1153,17 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1227
1153
|
});
|
|
1228
1154
|
//#endregion
|
|
1229
1155
|
//#region src/generators/queryGenerator.tsx
|
|
1230
|
-
|
|
1156
|
+
/**
|
|
1157
|
+
* Built-in generator for `useSWR` hooks. Emits one `useFoo` hook per read operation plus the
|
|
1158
|
+
* matching `fooQueryKey` helper and `fooQueryOptions` factory.
|
|
1159
|
+
*/
|
|
1160
|
+
const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1231
1161
|
name: "swr-query",
|
|
1232
|
-
renderer:
|
|
1162
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1233
1163
|
operation(node, ctx) {
|
|
1234
|
-
if (!
|
|
1164
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1235
1165
|
const { config, driver, resolver, root } = ctx;
|
|
1236
|
-
const { output, query, mutation,
|
|
1166
|
+
const { output, query, mutation, client, group } = ctx.options;
|
|
1237
1167
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1238
1168
|
if (!pluginTs) return null;
|
|
1239
1169
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1281,21 +1211,8 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1281
1211
|
order: "body-response-first",
|
|
1282
1212
|
includeParams: false
|
|
1283
1213
|
})].filter((name) => Boolean(name));
|
|
1284
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
|
|
1285
|
-
const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : void 0;
|
|
1286
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
1287
|
-
name: node.operationId,
|
|
1288
|
-
extname: ".ts",
|
|
1289
|
-
tag: node.tags[0] ?? "default",
|
|
1290
|
-
path: node.path
|
|
1291
|
-
}, {
|
|
1292
|
-
root,
|
|
1293
|
-
output: pluginZod?.options?.output ?? output,
|
|
1294
|
-
group: pluginZod?.options?.group
|
|
1295
|
-
}) : void 0;
|
|
1296
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1297
1214
|
const calledClientName = contractOp.name;
|
|
1298
|
-
return /* @__PURE__ */ (0,
|
|
1215
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1299
1216
|
baseName: meta.file.baseName,
|
|
1300
1217
|
path: meta.file.path,
|
|
1301
1218
|
meta: meta.file.meta,
|
|
@@ -1316,52 +1233,47 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1316
1233
|
}
|
|
1317
1234
|
}),
|
|
1318
1235
|
children: [
|
|
1319
|
-
|
|
1320
|
-
name: zodSchemaNames,
|
|
1321
|
-
root: meta.file.path,
|
|
1322
|
-
path: fileZod.path
|
|
1323
|
-
}),
|
|
1324
|
-
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1236
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1325
1237
|
name: [contractOp.name],
|
|
1326
1238
|
root: meta.file.path,
|
|
1327
1239
|
path: contractOp.path
|
|
1328
1240
|
}),
|
|
1329
|
-
/* @__PURE__ */ (0,
|
|
1241
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1330
1242
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1331
1243
|
root: meta.file.path,
|
|
1332
1244
|
path: contractOp.clientPath,
|
|
1333
1245
|
isTypeOnly: true
|
|
1334
1246
|
}),
|
|
1335
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1247
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1336
1248
|
name: Array.from(new Set(importedTypeNames)),
|
|
1337
1249
|
root: meta.file.path,
|
|
1338
1250
|
path: meta.fileTs.path,
|
|
1339
1251
|
isTypeOnly: true
|
|
1340
1252
|
}),
|
|
1341
|
-
/* @__PURE__ */ (0,
|
|
1253
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1342
1254
|
name: queryKeyName,
|
|
1343
1255
|
typeName: queryKeyTypeName,
|
|
1344
1256
|
node,
|
|
1345
1257
|
tsResolver,
|
|
1346
1258
|
transformer: ctx.options.queryKey
|
|
1347
1259
|
}),
|
|
1348
|
-
/* @__PURE__ */ (0,
|
|
1260
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1349
1261
|
name: queryOptionsName,
|
|
1350
1262
|
clientName: calledClientName,
|
|
1351
1263
|
node,
|
|
1352
1264
|
tsResolver
|
|
1353
1265
|
}),
|
|
1354
|
-
query && /* @__PURE__ */ (0,
|
|
1355
|
-
/* @__PURE__ */ (0,
|
|
1266
|
+
query && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1267
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1356
1268
|
name: "useSWR",
|
|
1357
1269
|
path: importPath
|
|
1358
1270
|
}),
|
|
1359
|
-
/* @__PURE__ */ (0,
|
|
1271
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1360
1272
|
name: ["SWRConfiguration"],
|
|
1361
1273
|
path: importPath,
|
|
1362
1274
|
isTypeOnly: true
|
|
1363
1275
|
}),
|
|
1364
|
-
/* @__PURE__ */ (0,
|
|
1276
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
|
|
1365
1277
|
name: queryName,
|
|
1366
1278
|
queryOptionsName,
|
|
1367
1279
|
queryKeyName,
|
|
@@ -1387,7 +1299,7 @@ function capitalize(name) {
|
|
|
1387
1299
|
* @example
|
|
1388
1300
|
* `resolverSwr.default('list pets', 'function') // → 'listPets'`
|
|
1389
1301
|
*/
|
|
1390
|
-
const resolverSwr = (0,
|
|
1302
|
+
const resolverSwr = (0, kubb_kit.defineResolver)(() => ({
|
|
1391
1303
|
name: "default",
|
|
1392
1304
|
pluginName: "plugin-swr",
|
|
1393
1305
|
default(name, type) {
|
|
@@ -1429,18 +1341,43 @@ const resolverSwr = (0, _kubb_core.defineResolver)(() => ({
|
|
|
1429
1341
|
}));
|
|
1430
1342
|
//#endregion
|
|
1431
1343
|
//#region src/plugin.ts
|
|
1344
|
+
/**
|
|
1345
|
+
* Canonical plugin name for `@kubb/plugin-swr`. Used for driver lookups and cross-plugin
|
|
1346
|
+
* dependency references.
|
|
1347
|
+
*/
|
|
1432
1348
|
const pluginSwrName = "plugin-swr";
|
|
1433
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* Generates SWR hooks from OpenAPI operations. Read operations become `useFoo` hooks built on
|
|
1351
|
+
* `useSWR` and write operations become `useFoo` hooks built on `useSWRMutation`, wrapping the
|
|
1352
|
+
* client functions from `@kubb/plugin-axios` or `@kubb/plugin-fetch`.
|
|
1353
|
+
*
|
|
1354
|
+
* @example
|
|
1355
|
+
* ```ts
|
|
1356
|
+
* import { defineConfig } from 'kubb/config'
|
|
1357
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1358
|
+
* import { pluginSwr } from '@kubb/plugin-swr'
|
|
1359
|
+
*
|
|
1360
|
+
* export default defineConfig({
|
|
1361
|
+
* input: { path: './petStore.yaml' },
|
|
1362
|
+
* output: { path: './src/gen' },
|
|
1363
|
+
* plugins: [
|
|
1364
|
+
* pluginTs(),
|
|
1365
|
+
* pluginSwr({ output: { path: './hooks' } }),
|
|
1366
|
+
* ],
|
|
1367
|
+
* })
|
|
1368
|
+
* ```
|
|
1369
|
+
*/
|
|
1370
|
+
const pluginSwr = (0, kubb_kit.definePlugin)((options) => {
|
|
1434
1371
|
const { output = {
|
|
1435
1372
|
path: "hooks",
|
|
1436
1373
|
barrel: { type: "named" }
|
|
1437
|
-
}, group, exclude = [], include, override = [],
|
|
1374
|
+
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1438
1375
|
const selectedGenerators = [queryGenerator, mutationGenerator].filter((generator) => Boolean(generator));
|
|
1439
1376
|
const groupConfig = createGroupConfig(group) ?? void 0;
|
|
1440
1377
|
return {
|
|
1441
1378
|
name: pluginSwrName,
|
|
1442
1379
|
options,
|
|
1443
|
-
dependencies: [_kubb_plugin_ts.pluginTsName
|
|
1380
|
+
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
1444
1381
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1445
1382
|
const resolver = userResolver ? {
|
|
1446
1383
|
...resolverSwr,
|
|
@@ -1461,21 +1398,20 @@ const pluginSwr = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1461
1398
|
queryKey,
|
|
1462
1399
|
query: query === false ? false : {
|
|
1463
1400
|
importPath: "swr",
|
|
1464
|
-
methods: ["
|
|
1401
|
+
methods: ["GET"],
|
|
1465
1402
|
...query
|
|
1466
1403
|
},
|
|
1467
1404
|
mutationKey,
|
|
1468
1405
|
mutation: mutation === false ? false : {
|
|
1469
1406
|
importPath: "swr/mutation",
|
|
1470
1407
|
methods: [
|
|
1471
|
-
"
|
|
1472
|
-
"
|
|
1473
|
-
"
|
|
1474
|
-
"
|
|
1408
|
+
"POST",
|
|
1409
|
+
"PUT",
|
|
1410
|
+
"PATCH",
|
|
1411
|
+
"DELETE"
|
|
1475
1412
|
],
|
|
1476
1413
|
...mutation
|
|
1477
1414
|
},
|
|
1478
|
-
validator,
|
|
1479
1415
|
group: groupConfig,
|
|
1480
1416
|
exclude,
|
|
1481
1417
|
include,
|