@kubb/plugin-client 5.0.0-alpha.29 → 5.0.0-alpha.30
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 +91 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.js +93 -123
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/generators/classClientGenerator.tsx +14 -27
- package/src/generators/clientGenerator.tsx +24 -37
- package/src/generators/groupedClientGenerator.tsx +29 -30
- package/src/generators/operationsGenerator.tsx +2 -4
- package/src/generators/staticClassClientGenerator.tsx +77 -76
- package/src/plugin.ts +22 -44
- package/src/types.ts +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -191,6 +191,9 @@ type Options = {
|
|
|
191
191
|
} & ClientImportPath & ParamsTypeOptions;
|
|
192
192
|
type ResolvedOptions = {
|
|
193
193
|
output: Output;
|
|
194
|
+
exclude: Array<Exclude>;
|
|
195
|
+
include: Array<Include> | undefined;
|
|
196
|
+
override: Array<Override<ResolvedOptions>>;
|
|
194
197
|
group: Group | undefined;
|
|
195
198
|
client: Options['client'];
|
|
196
199
|
clientType: NonNullable<Options['clientType']>;
|
|
@@ -207,6 +210,13 @@ type ResolvedOptions = {
|
|
|
207
210
|
resolver: ResolverClient;
|
|
208
211
|
};
|
|
209
212
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions, ResolverClient>;
|
|
213
|
+
declare global {
|
|
214
|
+
namespace Kubb {
|
|
215
|
+
interface PluginRegistry {
|
|
216
|
+
'plugin-client': PluginClient;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
210
220
|
//#endregion
|
|
211
221
|
//#region src/components/Client.d.ts
|
|
212
222
|
type Props$1 = {
|
|
@@ -391,19 +401,19 @@ declare namespace UrlLegacy {
|
|
|
391
401
|
}
|
|
392
402
|
//#endregion
|
|
393
403
|
//#region src/generators/classClientGenerator.d.ts
|
|
394
|
-
declare const classClientGenerator: _$_kubb_core0.
|
|
404
|
+
declare const classClientGenerator: _$_kubb_core0.Generator<PluginClient>;
|
|
395
405
|
//#endregion
|
|
396
406
|
//#region src/generators/clientGenerator.d.ts
|
|
397
|
-
declare const clientGenerator: _$_kubb_core0.
|
|
407
|
+
declare const clientGenerator: _$_kubb_core0.Generator<PluginClient>;
|
|
398
408
|
//#endregion
|
|
399
409
|
//#region src/generators/groupedClientGenerator.d.ts
|
|
400
|
-
declare const groupedClientGenerator: _$_kubb_core0.
|
|
410
|
+
declare const groupedClientGenerator: _$_kubb_core0.Generator<PluginClient>;
|
|
401
411
|
//#endregion
|
|
402
412
|
//#region src/generators/operationsGenerator.d.ts
|
|
403
|
-
declare const operationsGenerator: _$_kubb_core0.
|
|
413
|
+
declare const operationsGenerator: _$_kubb_core0.Generator<PluginClient>;
|
|
404
414
|
//#endregion
|
|
405
415
|
//#region src/generators/staticClassClientGenerator.d.ts
|
|
406
|
-
declare const staticClassClientGenerator: _$_kubb_core0.
|
|
416
|
+
declare const staticClassClientGenerator: _$_kubb_core0.Generator<PluginClient>;
|
|
407
417
|
//#endregion
|
|
408
418
|
//#region src/plugin.d.ts
|
|
409
419
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,11 @@ import { source } from "./templates/clients/axios.source.js";
|
|
|
3
3
|
import { source as source$1 } from "./templates/clients/fetch.source.js";
|
|
4
4
|
import { source as source$2 } from "./templates/config.source.js";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { caseParams, createFunctionParameter, createOperationParams, createTypeNode
|
|
6
|
+
import { caseParams, createFunctionParameter, createOperationParams, createTypeNode } from "@kubb/ast";
|
|
7
7
|
import { functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
8
8
|
import { Const, File, Function as Function$1, FunctionParams } from "@kubb/react-fabric";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
10
|
-
import { createPlugin, defineGenerator, definePresets, defineResolver,
|
|
10
|
+
import { createPlugin, defineGenerator, definePresets, defineResolver, getPreset, mergeGenerators } from "@kubb/core";
|
|
11
11
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
12
12
|
//#region ../../internals/utils/src/casing.ts
|
|
13
13
|
/**
|
|
@@ -866,11 +866,10 @@ function resolveZodImportNames$1(node, zodResolver) {
|
|
|
866
866
|
__name(resolveZodImportNames$1, "resolveZodImportNames");
|
|
867
867
|
const classClientGenerator = defineGenerator({
|
|
868
868
|
name: "classClient",
|
|
869
|
-
|
|
870
|
-
|
|
869
|
+
operations(nodes, options) {
|
|
870
|
+
const { adapter, config, driver, resolver, root } = this;
|
|
871
871
|
const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options;
|
|
872
872
|
const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
|
|
873
|
-
const root = path.resolve(config.root, config.output.path);
|
|
874
873
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
875
874
|
if (!pluginTs?.resolver) return null;
|
|
876
875
|
const tsResolver = pluginTs.resolver;
|
|
@@ -878,30 +877,29 @@ const classClientGenerator = defineGenerator({
|
|
|
878
877
|
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
879
878
|
const zodResolver = pluginZod?.resolver;
|
|
880
879
|
function buildOperationData(node) {
|
|
881
|
-
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
882
880
|
const typeFile = tsResolver.resolveFile({
|
|
883
|
-
name:
|
|
881
|
+
name: node.operationId,
|
|
884
882
|
extname: ".ts",
|
|
885
|
-
tag:
|
|
886
|
-
path:
|
|
883
|
+
tag: node.tags[0] ?? "default",
|
|
884
|
+
path: node.path
|
|
887
885
|
}, {
|
|
888
886
|
root,
|
|
889
887
|
output: tsPluginOptions?.output ?? output,
|
|
890
888
|
group: tsPluginOptions?.group
|
|
891
889
|
});
|
|
892
890
|
const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
|
|
893
|
-
name:
|
|
891
|
+
name: node.operationId,
|
|
894
892
|
extname: ".ts",
|
|
895
|
-
tag:
|
|
896
|
-
path:
|
|
893
|
+
tag: node.tags[0] ?? "default",
|
|
894
|
+
path: node.path
|
|
897
895
|
}, {
|
|
898
896
|
root,
|
|
899
897
|
output: pluginZod.options.output ?? output,
|
|
900
898
|
group: pluginZod.options.group
|
|
901
899
|
}) : void 0;
|
|
902
900
|
return {
|
|
903
|
-
node
|
|
904
|
-
name: resolver.resolveName(
|
|
901
|
+
node,
|
|
902
|
+
name: resolver.resolveName(node.operationId),
|
|
905
903
|
tsResolver,
|
|
906
904
|
zodResolver,
|
|
907
905
|
typeFile,
|
|
@@ -1028,12 +1026,12 @@ const classClientGenerator = defineGenerator({
|
|
|
1028
1026
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1029
1027
|
name: ["fetch"],
|
|
1030
1028
|
root: file.path,
|
|
1031
|
-
path: path.resolve(
|
|
1029
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
1032
1030
|
}),
|
|
1033
1031
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1034
1032
|
name: ["mergeConfig"],
|
|
1035
1033
|
root: file.path,
|
|
1036
|
-
path: path.resolve(
|
|
1034
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
1037
1035
|
}),
|
|
1038
1036
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1039
1037
|
name: [
|
|
@@ -1042,14 +1040,14 @@ const classClientGenerator = defineGenerator({
|
|
|
1042
1040
|
"ResponseErrorConfig"
|
|
1043
1041
|
],
|
|
1044
1042
|
root: file.path,
|
|
1045
|
-
path: path.resolve(
|
|
1043
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
1046
1044
|
isTypeOnly: true
|
|
1047
1045
|
})
|
|
1048
1046
|
] }),
|
|
1049
1047
|
hasFormData && /* @__PURE__ */ jsx(File.Import, {
|
|
1050
1048
|
name: ["buildFormData"],
|
|
1051
1049
|
root: file.path,
|
|
1052
|
-
path: path.resolve(
|
|
1050
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
1053
1051
|
}),
|
|
1054
1052
|
Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
|
|
1055
1053
|
const typeFile = typeFilesByPath.get(filePath);
|
|
@@ -1116,7 +1114,7 @@ const classClientGenerator = defineGenerator({
|
|
|
1116
1114
|
}) : /* @__PURE__ */ jsx(File.Import, {
|
|
1117
1115
|
name: ["Client", "RequestConfig"],
|
|
1118
1116
|
root: wrapperFile.path,
|
|
1119
|
-
path: path.resolve(
|
|
1117
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
1120
1118
|
isTypeOnly: true
|
|
1121
1119
|
}),
|
|
1122
1120
|
controllers.map(({ name, file }) => /* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1131,72 +1129,70 @@ const classClientGenerator = defineGenerator({
|
|
|
1131
1129
|
]
|
|
1132
1130
|
}, wrapperFile.path));
|
|
1133
1131
|
}
|
|
1134
|
-
return files;
|
|
1132
|
+
return /* @__PURE__ */ jsx(Fragment, { children: files });
|
|
1135
1133
|
}
|
|
1136
1134
|
});
|
|
1137
1135
|
//#endregion
|
|
1138
1136
|
//#region src/generators/clientGenerator.tsx
|
|
1139
1137
|
const clientGenerator = defineGenerator({
|
|
1140
1138
|
name: "client",
|
|
1141
|
-
|
|
1142
|
-
|
|
1139
|
+
operation(node, options) {
|
|
1140
|
+
const { adapter, config, driver, resolver, root } = this;
|
|
1143
1141
|
const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options;
|
|
1144
1142
|
const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
|
|
1145
|
-
const root = path.resolve(config.root, config.output.path);
|
|
1146
1143
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1147
1144
|
if (!pluginTs?.resolver) return null;
|
|
1148
1145
|
const tsResolver = pluginTs.resolver;
|
|
1149
1146
|
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
1150
1147
|
const zodResolver = pluginZod?.resolver;
|
|
1151
|
-
const
|
|
1152
|
-
const casedParams = caseParams(transformedNode.parameters, paramsCasing);
|
|
1148
|
+
const casedParams = caseParams(node.parameters, paramsCasing);
|
|
1153
1149
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
1154
1150
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
1155
1151
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
1156
1152
|
const importedTypeNames = [
|
|
1157
|
-
...pathParams.map((p) => tsResolver.resolvePathParamsName(
|
|
1158
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(
|
|
1159
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(
|
|
1160
|
-
|
|
1161
|
-
tsResolver.resolveResponseName(
|
|
1162
|
-
...
|
|
1153
|
+
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
1154
|
+
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
1155
|
+
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
1156
|
+
node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
|
|
1157
|
+
tsResolver.resolveResponseName(node),
|
|
1158
|
+
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
1163
1159
|
].filter(Boolean);
|
|
1164
|
-
const importedZodNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(
|
|
1160
|
+
const importedZodNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter(Boolean) : [];
|
|
1165
1161
|
const meta = {
|
|
1166
|
-
name: resolver.resolveName(
|
|
1167
|
-
urlName: `get${resolver.resolveName(
|
|
1162
|
+
name: resolver.resolveName(node.operationId),
|
|
1163
|
+
urlName: `get${resolver.resolveName(node.operationId).charAt(0).toUpperCase()}${resolver.resolveName(node.operationId).slice(1)}Url`,
|
|
1168
1164
|
file: resolver.resolveFile({
|
|
1169
|
-
name:
|
|
1165
|
+
name: node.operationId,
|
|
1170
1166
|
extname: ".ts",
|
|
1171
|
-
tag:
|
|
1172
|
-
path:
|
|
1167
|
+
tag: node.tags[0] ?? "default",
|
|
1168
|
+
path: node.path
|
|
1173
1169
|
}, {
|
|
1174
1170
|
root,
|
|
1175
1171
|
output,
|
|
1176
1172
|
group
|
|
1177
1173
|
}),
|
|
1178
1174
|
fileTs: tsResolver.resolveFile({
|
|
1179
|
-
name:
|
|
1175
|
+
name: node.operationId,
|
|
1180
1176
|
extname: ".ts",
|
|
1181
|
-
tag:
|
|
1182
|
-
path:
|
|
1177
|
+
tag: node.tags[0] ?? "default",
|
|
1178
|
+
path: node.path
|
|
1183
1179
|
}, {
|
|
1184
1180
|
root,
|
|
1185
1181
|
output: pluginTs.options?.output ?? output,
|
|
1186
1182
|
group: pluginTs.options?.group
|
|
1187
1183
|
}),
|
|
1188
1184
|
fileZod: zodResolver && pluginZod?.options ? zodResolver.resolveFile({
|
|
1189
|
-
name:
|
|
1185
|
+
name: node.operationId,
|
|
1190
1186
|
extname: ".ts",
|
|
1191
|
-
tag:
|
|
1192
|
-
path:
|
|
1187
|
+
tag: node.tags[0] ?? "default",
|
|
1188
|
+
path: node.path
|
|
1193
1189
|
}, {
|
|
1194
1190
|
root,
|
|
1195
1191
|
output: pluginZod.options.output ?? output,
|
|
1196
1192
|
group: pluginZod.options.group
|
|
1197
1193
|
}) : void 0
|
|
1198
1194
|
};
|
|
1199
|
-
const isFormData =
|
|
1195
|
+
const isFormData = node.requestBody?.contentType === "multipart/form-data";
|
|
1200
1196
|
return /* @__PURE__ */ jsxs(File, {
|
|
1201
1197
|
baseName: meta.file.baseName,
|
|
1202
1198
|
path: meta.file.path,
|
|
@@ -1224,7 +1220,7 @@ const clientGenerator = defineGenerator({
|
|
|
1224
1220
|
})] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
|
|
1225
1221
|
name: ["fetch"],
|
|
1226
1222
|
root: meta.file.path,
|
|
1227
|
-
path: path.resolve(
|
|
1223
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
1228
1224
|
}), /* @__PURE__ */ jsx(File.Import, {
|
|
1229
1225
|
name: [
|
|
1230
1226
|
"Client",
|
|
@@ -1232,13 +1228,13 @@ const clientGenerator = defineGenerator({
|
|
|
1232
1228
|
"ResponseErrorConfig"
|
|
1233
1229
|
],
|
|
1234
1230
|
root: meta.file.path,
|
|
1235
|
-
path: path.resolve(
|
|
1231
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
1236
1232
|
isTypeOnly: true
|
|
1237
1233
|
})] }),
|
|
1238
|
-
isFormData &&
|
|
1234
|
+
isFormData && node.requestBody?.schema && /* @__PURE__ */ jsx(File.Import, {
|
|
1239
1235
|
name: ["buildFormData"],
|
|
1240
1236
|
root: meta.file.path,
|
|
1241
|
-
path: path.resolve(
|
|
1237
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
1242
1238
|
}),
|
|
1243
1239
|
meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1244
1240
|
name: importedZodNames,
|
|
@@ -1257,7 +1253,7 @@ const clientGenerator = defineGenerator({
|
|
|
1257
1253
|
pathParamsType,
|
|
1258
1254
|
paramsCasing,
|
|
1259
1255
|
paramsType,
|
|
1260
|
-
node
|
|
1256
|
+
node,
|
|
1261
1257
|
tsResolver,
|
|
1262
1258
|
isIndexable: urlType === "export",
|
|
1263
1259
|
isExportable: urlType === "export"
|
|
@@ -1270,7 +1266,7 @@ const clientGenerator = defineGenerator({
|
|
|
1270
1266
|
pathParamsType,
|
|
1271
1267
|
paramsCasing,
|
|
1272
1268
|
paramsType,
|
|
1273
|
-
node
|
|
1269
|
+
node,
|
|
1274
1270
|
tsResolver,
|
|
1275
1271
|
zodResolver,
|
|
1276
1272
|
parser
|
|
@@ -1283,16 +1279,14 @@ const clientGenerator = defineGenerator({
|
|
|
1283
1279
|
//#region src/generators/groupedClientGenerator.tsx
|
|
1284
1280
|
const groupedClientGenerator = defineGenerator({
|
|
1285
1281
|
name: "groupedClient",
|
|
1286
|
-
|
|
1287
|
-
|
|
1282
|
+
operations(nodes, options) {
|
|
1283
|
+
const { config, resolver, adapter, root } = this;
|
|
1288
1284
|
const { output, group } = options;
|
|
1289
|
-
|
|
1290
|
-
return nodes.reduce((acc, operationNode) => {
|
|
1285
|
+
return /* @__PURE__ */ jsx(Fragment, { children: nodes.reduce((acc, operationNode) => {
|
|
1291
1286
|
if (group?.type === "tag") {
|
|
1292
1287
|
const tag = operationNode.tags[0];
|
|
1293
1288
|
const name = tag ? group?.name?.({ group: camelCase(tag) }) : void 0;
|
|
1294
1289
|
if (!tag || !name) return acc;
|
|
1295
|
-
const transformedNode = plugin.transformer ? transform(operationNode, plugin.transformer) : operationNode;
|
|
1296
1290
|
const file = resolver.resolveFile({
|
|
1297
1291
|
name,
|
|
1298
1292
|
extname: ".ts",
|
|
@@ -1303,17 +1297,17 @@ const groupedClientGenerator = defineGenerator({
|
|
|
1303
1297
|
group
|
|
1304
1298
|
});
|
|
1305
1299
|
const clientFile = resolver.resolveFile({
|
|
1306
|
-
name:
|
|
1300
|
+
name: operationNode.operationId,
|
|
1307
1301
|
extname: ".ts",
|
|
1308
|
-
tag:
|
|
1309
|
-
path:
|
|
1302
|
+
tag: operationNode.tags[0] ?? "default",
|
|
1303
|
+
path: operationNode.path
|
|
1310
1304
|
}, {
|
|
1311
1305
|
root,
|
|
1312
1306
|
output,
|
|
1313
1307
|
group
|
|
1314
1308
|
});
|
|
1315
1309
|
const client = {
|
|
1316
|
-
name: resolver.resolveName(
|
|
1310
|
+
name: resolver.resolveName(operationNode.operationId),
|
|
1317
1311
|
file: clientFile
|
|
1318
1312
|
};
|
|
1319
1313
|
const previous = acc.find((item) => item.file.path === file.path);
|
|
@@ -1353,7 +1347,7 @@ const groupedClientGenerator = defineGenerator({
|
|
|
1353
1347
|
})
|
|
1354
1348
|
})]
|
|
1355
1349
|
}, file.path);
|
|
1356
|
-
});
|
|
1350
|
+
}) });
|
|
1357
1351
|
}
|
|
1358
1352
|
});
|
|
1359
1353
|
//#endregion
|
|
@@ -1381,10 +1375,9 @@ function Operations({ name, nodes }) {
|
|
|
1381
1375
|
//#region src/generators/operationsGenerator.tsx
|
|
1382
1376
|
const operationsGenerator = defineGenerator({
|
|
1383
1377
|
name: "client",
|
|
1384
|
-
|
|
1385
|
-
|
|
1378
|
+
operations(nodes, options) {
|
|
1379
|
+
const { config, resolver, adapter, root } = this;
|
|
1386
1380
|
const { output, group } = options;
|
|
1387
|
-
const root = path.resolve(config.root, config.output.path);
|
|
1388
1381
|
const name = "operations";
|
|
1389
1382
|
const file = resolver.resolveFile({
|
|
1390
1383
|
name,
|
|
@@ -1499,11 +1492,10 @@ function resolveZodImportNames(node, zodResolver) {
|
|
|
1499
1492
|
}
|
|
1500
1493
|
const staticClassClientGenerator = defineGenerator({
|
|
1501
1494
|
name: "staticClassClient",
|
|
1502
|
-
|
|
1503
|
-
|
|
1495
|
+
operations(nodes, options) {
|
|
1496
|
+
const { adapter, config, driver, resolver, root } = this;
|
|
1504
1497
|
const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options;
|
|
1505
1498
|
const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
|
|
1506
|
-
const root = path.resolve(config.root, config.output.path);
|
|
1507
1499
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1508
1500
|
if (!pluginTs?.resolver) return null;
|
|
1509
1501
|
const tsResolver = pluginTs.resolver;
|
|
@@ -1511,30 +1503,29 @@ const staticClassClientGenerator = defineGenerator({
|
|
|
1511
1503
|
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
1512
1504
|
const zodResolver = pluginZod?.resolver;
|
|
1513
1505
|
function buildOperationData(node) {
|
|
1514
|
-
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
1515
1506
|
const typeFile = tsResolver.resolveFile({
|
|
1516
|
-
name:
|
|
1507
|
+
name: node.operationId,
|
|
1517
1508
|
extname: ".ts",
|
|
1518
|
-
tag:
|
|
1519
|
-
path:
|
|
1509
|
+
tag: node.tags[0] ?? "default",
|
|
1510
|
+
path: node.path
|
|
1520
1511
|
}, {
|
|
1521
1512
|
root,
|
|
1522
1513
|
output: tsPluginOptions?.output ?? output,
|
|
1523
1514
|
group: tsPluginOptions?.group
|
|
1524
1515
|
});
|
|
1525
1516
|
const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
|
|
1526
|
-
name:
|
|
1517
|
+
name: node.operationId,
|
|
1527
1518
|
extname: ".ts",
|
|
1528
|
-
tag:
|
|
1529
|
-
path:
|
|
1519
|
+
tag: node.tags[0] ?? "default",
|
|
1520
|
+
path: node.path
|
|
1530
1521
|
}, {
|
|
1531
1522
|
root,
|
|
1532
1523
|
output: pluginZod.options.output ?? output,
|
|
1533
1524
|
group: pluginZod.options.group
|
|
1534
1525
|
}) : void 0;
|
|
1535
1526
|
return {
|
|
1536
|
-
node
|
|
1537
|
-
name: resolver.resolveName(
|
|
1527
|
+
node,
|
|
1528
|
+
name: resolver.resolveName(node.operationId),
|
|
1538
1529
|
tsResolver,
|
|
1539
1530
|
zodResolver,
|
|
1540
1531
|
typeFile,
|
|
@@ -1619,7 +1610,7 @@ const staticClassClientGenerator = defineGenerator({
|
|
|
1619
1610
|
zodFilesByPath
|
|
1620
1611
|
};
|
|
1621
1612
|
}
|
|
1622
|
-
return controllers.map(({ name, file, operations: ops }) => {
|
|
1613
|
+
return /* @__PURE__ */ jsx(Fragment, { children: controllers.map(({ name, file, operations: ops }) => {
|
|
1623
1614
|
const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
|
|
1624
1615
|
const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
|
|
1625
1616
|
zodImportsByFile: /* @__PURE__ */ new Map(),
|
|
@@ -1661,12 +1652,12 @@ const staticClassClientGenerator = defineGenerator({
|
|
|
1661
1652
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1662
1653
|
name: ["fetch"],
|
|
1663
1654
|
root: file.path,
|
|
1664
|
-
path: path.resolve(
|
|
1655
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
1665
1656
|
}),
|
|
1666
1657
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1667
1658
|
name: ["mergeConfig"],
|
|
1668
1659
|
root: file.path,
|
|
1669
|
-
path: path.resolve(
|
|
1660
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
1670
1661
|
}),
|
|
1671
1662
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1672
1663
|
name: [
|
|
@@ -1675,14 +1666,14 @@ const staticClassClientGenerator = defineGenerator({
|
|
|
1675
1666
|
"ResponseErrorConfig"
|
|
1676
1667
|
],
|
|
1677
1668
|
root: file.path,
|
|
1678
|
-
path: path.resolve(
|
|
1669
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
1679
1670
|
isTypeOnly: true
|
|
1680
1671
|
})
|
|
1681
1672
|
] }),
|
|
1682
1673
|
hasFormData && /* @__PURE__ */ jsx(File.Import, {
|
|
1683
1674
|
name: ["buildFormData"],
|
|
1684
1675
|
root: file.path,
|
|
1685
|
-
path: path.resolve(
|
|
1676
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
1686
1677
|
}),
|
|
1687
1678
|
Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
|
|
1688
1679
|
const typeFile = typeFilesByPath.get(filePath);
|
|
@@ -1719,10 +1710,13 @@ const staticClassClientGenerator = defineGenerator({
|
|
|
1719
1710
|
})
|
|
1720
1711
|
]
|
|
1721
1712
|
}, file.path);
|
|
1722
|
-
});
|
|
1713
|
+
}) });
|
|
1723
1714
|
}
|
|
1724
1715
|
});
|
|
1725
1716
|
//#endregion
|
|
1717
|
+
//#region package.json
|
|
1718
|
+
var version = "5.0.0-alpha.30";
|
|
1719
|
+
//#endregion
|
|
1726
1720
|
//#region src/resolvers/resolverClient.ts
|
|
1727
1721
|
/**
|
|
1728
1722
|
* Resolver for `@kubb/plugin-client` that provides the default naming
|
|
@@ -1819,7 +1813,7 @@ const pluginClient = createPlugin((options) => {
|
|
|
1819
1813
|
const { output = {
|
|
1820
1814
|
path: "clients",
|
|
1821
1815
|
barrelType: "named"
|
|
1822
|
-
}, group,
|
|
1816
|
+
}, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, bundle = false, wrapper, baseURL, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer } = options;
|
|
1823
1817
|
const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
|
|
1824
1818
|
const preset = getPreset({
|
|
1825
1819
|
preset: compatibilityPreset,
|
|
@@ -1832,10 +1826,12 @@ const pluginClient = createPlugin((options) => {
|
|
|
1832
1826
|
operations ? operationsGenerator : void 0
|
|
1833
1827
|
].filter((x) => Boolean(x))
|
|
1834
1828
|
});
|
|
1829
|
+
const mergedGenerator = mergeGenerators(preset.generators ?? []);
|
|
1835
1830
|
let resolveNameWarning = false;
|
|
1836
1831
|
let resolvePathWarning = false;
|
|
1837
1832
|
return {
|
|
1838
1833
|
name: pluginClientName,
|
|
1834
|
+
version,
|
|
1839
1835
|
get resolver() {
|
|
1840
1836
|
return preset.resolver;
|
|
1841
1837
|
},
|
|
@@ -1848,6 +1844,9 @@ const pluginClient = createPlugin((options) => {
|
|
|
1848
1844
|
clientType,
|
|
1849
1845
|
bundle,
|
|
1850
1846
|
output,
|
|
1847
|
+
exclude,
|
|
1848
|
+
include,
|
|
1849
|
+
override,
|
|
1851
1850
|
group: group ? {
|
|
1852
1851
|
...group,
|
|
1853
1852
|
name: group.name ? group.name : (ctx) => {
|
|
@@ -1870,7 +1869,7 @@ const pluginClient = createPlugin((options) => {
|
|
|
1870
1869
|
pre: [pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
1871
1870
|
resolvePath(baseName, pathMode, options) {
|
|
1872
1871
|
if (!resolvePathWarning) {
|
|
1873
|
-
this.
|
|
1872
|
+
this.warn("Do not use resolvePath for pluginClient, use resolverClient.resolvePath instead");
|
|
1874
1873
|
resolvePathWarning = true;
|
|
1875
1874
|
}
|
|
1876
1875
|
return this.plugin.resolver.resolvePath({
|
|
@@ -1879,23 +1878,27 @@ const pluginClient = createPlugin((options) => {
|
|
|
1879
1878
|
tag: options?.group?.tag,
|
|
1880
1879
|
path: options?.group?.path
|
|
1881
1880
|
}, {
|
|
1882
|
-
root:
|
|
1881
|
+
root: this.root,
|
|
1883
1882
|
output,
|
|
1884
1883
|
group: this.plugin.options.group
|
|
1885
1884
|
});
|
|
1886
1885
|
},
|
|
1887
1886
|
resolveName(name, type) {
|
|
1888
1887
|
if (!resolveNameWarning) {
|
|
1889
|
-
this.
|
|
1888
|
+
this.warn("Do not use resolveName for pluginClient, use resolverClient.default instead");
|
|
1890
1889
|
resolveNameWarning = true;
|
|
1891
1890
|
}
|
|
1892
1891
|
return this.plugin.resolver.default(name, type);
|
|
1893
1892
|
},
|
|
1894
|
-
async
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1893
|
+
async operation(node, options) {
|
|
1894
|
+
return mergedGenerator.operation?.call(this, node, options);
|
|
1895
|
+
},
|
|
1896
|
+
async operations(nodes, options) {
|
|
1897
|
+
return mergedGenerator.operations?.call(this, nodes, options);
|
|
1898
|
+
},
|
|
1899
|
+
async buildStart() {
|
|
1900
|
+
const { plugin } = this;
|
|
1901
|
+
const root = this.root;
|
|
1899
1902
|
if (bundle && !plugin.options.importPath) await this.addFile({
|
|
1900
1903
|
baseName: "fetch.ts",
|
|
1901
1904
|
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
@@ -1920,39 +1923,6 @@ const pluginClient = createPlugin((options) => {
|
|
|
1920
1923
|
imports: [],
|
|
1921
1924
|
exports: []
|
|
1922
1925
|
});
|
|
1923
|
-
const collectedOperations = [];
|
|
1924
|
-
const generatorContext = {
|
|
1925
|
-
generators: preset.generators,
|
|
1926
|
-
plugin,
|
|
1927
|
-
resolver,
|
|
1928
|
-
exclude,
|
|
1929
|
-
include,
|
|
1930
|
-
override,
|
|
1931
|
-
fabric,
|
|
1932
|
-
adapter,
|
|
1933
|
-
config,
|
|
1934
|
-
driver
|
|
1935
|
-
};
|
|
1936
|
-
await walk(rootNode, {
|
|
1937
|
-
depth: "shallow",
|
|
1938
|
-
async operation(operationNode) {
|
|
1939
|
-
if (resolver.resolveOptions(operationNode, {
|
|
1940
|
-
options: plugin.options,
|
|
1941
|
-
exclude,
|
|
1942
|
-
include,
|
|
1943
|
-
override
|
|
1944
|
-
}) !== null) collectedOperations.push(operationNode);
|
|
1945
|
-
await runGeneratorOperation(operationNode, generatorContext);
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
await runGeneratorOperations(collectedOperations, generatorContext);
|
|
1949
|
-
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
1950
|
-
type: output.barrelType ?? "named",
|
|
1951
|
-
root,
|
|
1952
|
-
output,
|
|
1953
|
-
meta: { pluginName: this.plugin.name }
|
|
1954
|
-
});
|
|
1955
|
-
await this.upsertFile(...barrelFiles);
|
|
1956
1926
|
}
|
|
1957
1927
|
};
|
|
1958
1928
|
});
|