@kubb/plugin-swr 5.0.0-beta.81 → 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 +53 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.cjs
CHANGED
|
@@ -30,10 +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
|
|
35
|
+
let kubb_jsx = require("kubb/jsx");
|
|
36
|
+
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
37
37
|
//#region ../../internals/utils/src/casing.ts
|
|
38
38
|
/**
|
|
39
39
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -660,11 +660,11 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
660
660
|
node,
|
|
661
661
|
casing: "camelcase"
|
|
662
662
|
});
|
|
663
|
-
return /* @__PURE__ */ (0,
|
|
663
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
664
664
|
name,
|
|
665
665
|
isExportable: true,
|
|
666
666
|
isIndexable: true,
|
|
667
|
-
children: /* @__PURE__ */ (0,
|
|
667
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
|
|
668
668
|
name,
|
|
669
669
|
export: true,
|
|
670
670
|
params: paramsSignature,
|
|
@@ -809,21 +809,21 @@ function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
|
809
809
|
node,
|
|
810
810
|
casing: "camelcase"
|
|
811
811
|
});
|
|
812
|
-
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, {
|
|
813
813
|
name,
|
|
814
814
|
isExportable: true,
|
|
815
815
|
isIndexable: true,
|
|
816
|
-
children: /* @__PURE__ */ (0,
|
|
816
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
|
|
817
817
|
name,
|
|
818
818
|
export: true,
|
|
819
819
|
params: paramsSignature,
|
|
820
820
|
singleLine: true,
|
|
821
821
|
children: `[${keys.join(", ")}] as const`
|
|
822
822
|
})
|
|
823
|
-
}), /* @__PURE__ */ (0,
|
|
823
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
824
824
|
name: typeName,
|
|
825
825
|
isTypeOnly: true,
|
|
826
|
-
children: /* @__PURE__ */ (0,
|
|
826
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
827
827
|
name: typeName,
|
|
828
828
|
children: `ReturnType<typeof ${name}>`
|
|
829
829
|
})
|
|
@@ -874,21 +874,21 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
874
874
|
resolver: tsResolver
|
|
875
875
|
});
|
|
876
876
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
877
|
-
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, {
|
|
878
878
|
name: mutationArgTypeName,
|
|
879
879
|
isExportable: true,
|
|
880
880
|
isIndexable: true,
|
|
881
881
|
isTypeOnly: true,
|
|
882
|
-
children: /* @__PURE__ */ (0,
|
|
882
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
883
883
|
name: mutationArgTypeName,
|
|
884
884
|
export: true,
|
|
885
885
|
children: hasMutationParams ? argTypeBody : "never"
|
|
886
886
|
})
|
|
887
|
-
}), /* @__PURE__ */ (0,
|
|
887
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
888
888
|
name,
|
|
889
889
|
isExportable: true,
|
|
890
890
|
isIndexable: true,
|
|
891
|
-
children: /* @__PURE__ */ (0,
|
|
891
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
892
892
|
name,
|
|
893
893
|
export: true,
|
|
894
894
|
params: paramsSignature,
|
|
@@ -911,16 +911,16 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
911
911
|
//#endregion
|
|
912
912
|
//#region src/components/MutationKey.tsx
|
|
913
913
|
function MutationKey({ name, typeName, node, transformer }) {
|
|
914
|
-
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, {
|
|
915
915
|
name,
|
|
916
916
|
node,
|
|
917
917
|
transformer
|
|
918
|
-
}), /* @__PURE__ */ (0,
|
|
918
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
919
919
|
name: typeName,
|
|
920
920
|
isExportable: true,
|
|
921
921
|
isIndexable: true,
|
|
922
922
|
isTypeOnly: true,
|
|
923
|
-
children: /* @__PURE__ */ (0,
|
|
923
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
924
924
|
export: true,
|
|
925
925
|
name: typeName,
|
|
926
926
|
children: `ReturnType<typeof ${name}>`
|
|
@@ -941,11 +941,11 @@ function QueryOptions({ name, clientName, node, tsResolver }) {
|
|
|
941
941
|
signal: false
|
|
942
942
|
})}
|
|
943
943
|
return data`;
|
|
944
|
-
return /* @__PURE__ */ (0,
|
|
944
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
945
945
|
name,
|
|
946
946
|
isExportable: true,
|
|
947
947
|
isIndexable: true,
|
|
948
|
-
children: /* @__PURE__ */ (0,
|
|
948
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
949
949
|
name,
|
|
950
950
|
export: true,
|
|
951
951
|
params: paramsSignature,
|
|
@@ -993,11 +993,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
993
993
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
994
994
|
const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
|
|
995
995
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
996
|
-
return /* @__PURE__ */ (0,
|
|
996
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
997
997
|
name,
|
|
998
998
|
isExportable: true,
|
|
999
999
|
isIndexable: true,
|
|
1000
|
-
children: /* @__PURE__ */ (0,
|
|
1000
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1001
1001
|
name,
|
|
1002
1002
|
export: true,
|
|
1003
1003
|
params: paramsSignature,
|
|
@@ -1030,11 +1030,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1030
1030
|
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
1031
1031
|
* the matching `fooMutationKey` helper.
|
|
1032
1032
|
*/
|
|
1033
|
-
const mutationGenerator = (0,
|
|
1033
|
+
const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
1034
1034
|
name: "swr-mutation",
|
|
1035
|
-
renderer:
|
|
1035
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1036
1036
|
operation(node, ctx) {
|
|
1037
|
-
if (!
|
|
1037
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1038
1038
|
const { config, driver, resolver, root } = ctx;
|
|
1039
1039
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1040
1040
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1083,7 +1083,7 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1083
1083
|
includeParams: false
|
|
1084
1084
|
})].filter((name) => Boolean(name));
|
|
1085
1085
|
const calledClientName = contractOp.name;
|
|
1086
|
-
return /* @__PURE__ */ (0,
|
|
1086
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1087
1087
|
baseName: meta.file.baseName,
|
|
1088
1088
|
path: meta.file.path,
|
|
1089
1089
|
meta: meta.file.meta,
|
|
@@ -1104,40 +1104,40 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1104
1104
|
}
|
|
1105
1105
|
}),
|
|
1106
1106
|
children: [
|
|
1107
|
-
/* @__PURE__ */ (0,
|
|
1107
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1108
1108
|
name: [contractOp.name],
|
|
1109
1109
|
root: meta.file.path,
|
|
1110
1110
|
path: contractOp.path
|
|
1111
1111
|
}),
|
|
1112
|
-
/* @__PURE__ */ (0,
|
|
1112
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1113
1113
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1114
1114
|
root: meta.file.path,
|
|
1115
1115
|
path: contractOp.clientPath,
|
|
1116
1116
|
isTypeOnly: true
|
|
1117
1117
|
}),
|
|
1118
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1118
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1119
1119
|
name: Array.from(new Set(importedTypeNames)),
|
|
1120
1120
|
root: meta.file.path,
|
|
1121
1121
|
path: meta.fileTs.path,
|
|
1122
1122
|
isTypeOnly: true
|
|
1123
1123
|
}),
|
|
1124
|
-
/* @__PURE__ */ (0,
|
|
1124
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1125
1125
|
name: mutationKeyName,
|
|
1126
1126
|
typeName: mutationKeyTypeName,
|
|
1127
1127
|
node,
|
|
1128
1128
|
transformer: ctx.options.mutationKey
|
|
1129
1129
|
}),
|
|
1130
|
-
mutation && /* @__PURE__ */ (0,
|
|
1131
|
-
/* @__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, {
|
|
1132
1132
|
name: "useSWRMutation",
|
|
1133
1133
|
path: importPath
|
|
1134
1134
|
}),
|
|
1135
|
-
/* @__PURE__ */ (0,
|
|
1135
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1136
1136
|
name: ["SWRMutationConfiguration"],
|
|
1137
1137
|
path: importPath,
|
|
1138
1138
|
isTypeOnly: true
|
|
1139
1139
|
}),
|
|
1140
|
-
/* @__PURE__ */ (0,
|
|
1140
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1141
1141
|
name: mutationHookName,
|
|
1142
1142
|
clientName: calledClientName,
|
|
1143
1143
|
mutationKeyName,
|
|
@@ -1157,11 +1157,11 @@ const mutationGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1157
1157
|
* Built-in generator for `useSWR` hooks. Emits one `useFoo` hook per read operation plus the
|
|
1158
1158
|
* matching `fooQueryKey` helper and `fooQueryOptions` factory.
|
|
1159
1159
|
*/
|
|
1160
|
-
const queryGenerator = (0,
|
|
1160
|
+
const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1161
1161
|
name: "swr-query",
|
|
1162
|
-
renderer:
|
|
1162
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1163
1163
|
operation(node, ctx) {
|
|
1164
|
-
if (!
|
|
1164
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1165
1165
|
const { config, driver, resolver, root } = ctx;
|
|
1166
1166
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1167
1167
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1212,7 +1212,7 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1212
1212
|
includeParams: false
|
|
1213
1213
|
})].filter((name) => Boolean(name));
|
|
1214
1214
|
const calledClientName = contractOp.name;
|
|
1215
|
-
return /* @__PURE__ */ (0,
|
|
1215
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1216
1216
|
baseName: meta.file.baseName,
|
|
1217
1217
|
path: meta.file.path,
|
|
1218
1218
|
meta: meta.file.meta,
|
|
@@ -1233,47 +1233,47 @@ const queryGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1233
1233
|
}
|
|
1234
1234
|
}),
|
|
1235
1235
|
children: [
|
|
1236
|
-
/* @__PURE__ */ (0,
|
|
1236
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1237
1237
|
name: [contractOp.name],
|
|
1238
1238
|
root: meta.file.path,
|
|
1239
1239
|
path: contractOp.path
|
|
1240
1240
|
}),
|
|
1241
|
-
/* @__PURE__ */ (0,
|
|
1241
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1242
1242
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1243
1243
|
root: meta.file.path,
|
|
1244
1244
|
path: contractOp.clientPath,
|
|
1245
1245
|
isTypeOnly: true
|
|
1246
1246
|
}),
|
|
1247
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1247
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1248
1248
|
name: Array.from(new Set(importedTypeNames)),
|
|
1249
1249
|
root: meta.file.path,
|
|
1250
1250
|
path: meta.fileTs.path,
|
|
1251
1251
|
isTypeOnly: true
|
|
1252
1252
|
}),
|
|
1253
|
-
/* @__PURE__ */ (0,
|
|
1253
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1254
1254
|
name: queryKeyName,
|
|
1255
1255
|
typeName: queryKeyTypeName,
|
|
1256
1256
|
node,
|
|
1257
1257
|
tsResolver,
|
|
1258
1258
|
transformer: ctx.options.queryKey
|
|
1259
1259
|
}),
|
|
1260
|
-
/* @__PURE__ */ (0,
|
|
1260
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1261
1261
|
name: queryOptionsName,
|
|
1262
1262
|
clientName: calledClientName,
|
|
1263
1263
|
node,
|
|
1264
1264
|
tsResolver
|
|
1265
1265
|
}),
|
|
1266
|
-
query && /* @__PURE__ */ (0,
|
|
1267
|
-
/* @__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, {
|
|
1268
1268
|
name: "useSWR",
|
|
1269
1269
|
path: importPath
|
|
1270
1270
|
}),
|
|
1271
|
-
/* @__PURE__ */ (0,
|
|
1271
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1272
1272
|
name: ["SWRConfiguration"],
|
|
1273
1273
|
path: importPath,
|
|
1274
1274
|
isTypeOnly: true
|
|
1275
1275
|
}),
|
|
1276
|
-
/* @__PURE__ */ (0,
|
|
1276
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
|
|
1277
1277
|
name: queryName,
|
|
1278
1278
|
queryOptionsName,
|
|
1279
1279
|
queryKeyName,
|
|
@@ -1299,7 +1299,7 @@ function capitalize(name) {
|
|
|
1299
1299
|
* @example
|
|
1300
1300
|
* `resolverSwr.default('list pets', 'function') // → 'listPets'`
|
|
1301
1301
|
*/
|
|
1302
|
-
const resolverSwr = (0,
|
|
1302
|
+
const resolverSwr = (0, kubb_kit.defineResolver)(() => ({
|
|
1303
1303
|
name: "default",
|
|
1304
1304
|
pluginName: "plugin-swr",
|
|
1305
1305
|
default(name, type) {
|
|
@@ -1353,7 +1353,7 @@ const pluginSwrName = "plugin-swr";
|
|
|
1353
1353
|
*
|
|
1354
1354
|
* @example
|
|
1355
1355
|
* ```ts
|
|
1356
|
-
* import { defineConfig } from 'kubb'
|
|
1356
|
+
* import { defineConfig } from 'kubb/config'
|
|
1357
1357
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1358
1358
|
* import { pluginSwr } from '@kubb/plugin-swr'
|
|
1359
1359
|
*
|
|
@@ -1367,7 +1367,7 @@ const pluginSwrName = "plugin-swr";
|
|
|
1367
1367
|
* })
|
|
1368
1368
|
* ```
|
|
1369
1369
|
*/
|
|
1370
|
-
const pluginSwr = (0,
|
|
1370
|
+
const pluginSwr = (0, kubb_kit.definePlugin)((options) => {
|
|
1371
1371
|
const { output = {
|
|
1372
1372
|
path: "hooks",
|
|
1373
1373
|
barrel: { type: "named" }
|
|
@@ -1398,17 +1398,17 @@ const pluginSwr = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1398
1398
|
queryKey,
|
|
1399
1399
|
query: query === false ? false : {
|
|
1400
1400
|
importPath: "swr",
|
|
1401
|
-
methods: ["
|
|
1401
|
+
methods: ["GET"],
|
|
1402
1402
|
...query
|
|
1403
1403
|
},
|
|
1404
1404
|
mutationKey,
|
|
1405
1405
|
mutation: mutation === false ? false : {
|
|
1406
1406
|
importPath: "swr/mutation",
|
|
1407
1407
|
methods: [
|
|
1408
|
-
"
|
|
1409
|
-
"
|
|
1410
|
-
"
|
|
1411
|
-
"
|
|
1408
|
+
"POST",
|
|
1409
|
+
"PUT",
|
|
1410
|
+
"PATCH",
|
|
1411
|
+
"DELETE"
|
|
1412
1412
|
],
|
|
1413
1413
|
...mutation
|
|
1414
1414
|
},
|