@kubb/plugin-fetch 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 +41 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
- package/src/generators/clientGenerator.tsx +2 -2
- package/src/plugin.ts +2 -2
- package/src/types.ts +1 -1
- package/templates/fetch.ts +20 -10
- package/templates/serializers.ts +4 -0
package/dist/index.cjs
CHANGED
|
@@ -26,13 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
//#endregion
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
|
-
let
|
|
30
|
-
let
|
|
29
|
+
let kubb_kit = require("kubb/kit");
|
|
30
|
+
let kubb_jsx = require("kubb/jsx");
|
|
31
31
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
|
-
let
|
|
32
|
+
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
33
33
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
34
|
-
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
35
|
-
let _kubb_ast_macros = require("@kubb/ast/macros");
|
|
36
34
|
let node_url = require("node:url");
|
|
37
35
|
//#region ../../internals/utils/src/casing.ts
|
|
38
36
|
/**
|
|
@@ -784,7 +782,7 @@ function serializeParameter(parameter) {
|
|
|
784
782
|
* ```
|
|
785
783
|
*/
|
|
786
784
|
function buildStyles({ node }) {
|
|
787
|
-
if (!
|
|
785
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
788
786
|
const groups = {
|
|
789
787
|
path: [],
|
|
790
788
|
query: [],
|
|
@@ -834,7 +832,7 @@ function buildValidatorHooks({ node, validator, zodResolver }) {
|
|
|
834
832
|
* and call config are built with the AST factory, and only the jsx-renderer emits the source.
|
|
835
833
|
*/
|
|
836
834
|
function Operation({ name, node, tsResolver, zodResolver, validator, security, isExportable = true, isIndexable = true }) {
|
|
837
|
-
if (!
|
|
835
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
838
836
|
const signature = buildGroupedOptionsSignature({
|
|
839
837
|
node,
|
|
840
838
|
tsResolver
|
|
@@ -876,11 +874,11 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
876
874
|
tsResolver,
|
|
877
875
|
callConfig
|
|
878
876
|
});
|
|
879
|
-
return /* @__PURE__ */ (0,
|
|
877
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
880
878
|
name,
|
|
881
879
|
isExportable,
|
|
882
880
|
isIndexable,
|
|
883
|
-
children: /* @__PURE__ */ (0,
|
|
881
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.Function, {
|
|
884
882
|
name,
|
|
885
883
|
export: isExportable,
|
|
886
884
|
generics: signature.generics,
|
|
@@ -893,7 +891,7 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
893
891
|
}) },
|
|
894
892
|
children: [
|
|
895
893
|
mergeContentType ? "const { client: request = client, contentType, ...config } = options" : "const { client: request = client, ...config } = options",
|
|
896
|
-
/* @__PURE__ */ (0,
|
|
894
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)("br", {}),
|
|
897
895
|
returnStatement
|
|
898
896
|
]
|
|
899
897
|
})
|
|
@@ -930,7 +928,7 @@ function buildCallConfig({ node, validator, zodResolver, security }) {
|
|
|
930
928
|
* one operation can be routed to a different environment without a new instance.
|
|
931
929
|
*/
|
|
932
930
|
function buildSdkMethod({ node, name, tsResolver, zodResolver, validator, security }) {
|
|
933
|
-
if (!
|
|
931
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return "";
|
|
934
932
|
const signature = buildGroupedOptionsSignature({
|
|
935
933
|
node,
|
|
936
934
|
tsResolver
|
|
@@ -946,7 +944,7 @@ function buildSdkMethod({ node, name, tsResolver, zodResolver, validator, securi
|
|
|
946
944
|
})
|
|
947
945
|
});
|
|
948
946
|
const generics = signature.generics.length ? `<${signature.generics.join(", ")}>` : "";
|
|
949
|
-
const jsdoc =
|
|
947
|
+
const jsdoc = kubb_kit.ast.buildJSDoc(buildOperationComments(node, {
|
|
950
948
|
link: "urlPath",
|
|
951
949
|
linkPosition: "beforeDeprecated",
|
|
952
950
|
splitLines: true
|
|
@@ -982,7 +980,7 @@ function SdkClient({ name, isExportable = true, isIndexable = true, operations,
|
|
|
982
980
|
" this.client = createClient(config)",
|
|
983
981
|
" }"
|
|
984
982
|
].join("\n")}\n\n${methods.join("\n\n")}\n}`;
|
|
985
|
-
return /* @__PURE__ */ (0,
|
|
983
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File.Source, {
|
|
986
984
|
name,
|
|
987
985
|
isExportable,
|
|
988
986
|
isIndexable,
|
|
@@ -1006,7 +1004,7 @@ function SdkFacade({ name, isExportable = true, isIndexable = true, members, chi
|
|
|
1006
1004
|
...assignments,
|
|
1007
1005
|
" }"
|
|
1008
1006
|
].join("\n")}\n}`;
|
|
1009
|
-
return /* @__PURE__ */ (0,
|
|
1007
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File.Source, {
|
|
1010
1008
|
name,
|
|
1011
1009
|
isExportable,
|
|
1012
1010
|
isIndexable,
|
|
@@ -1051,7 +1049,7 @@ function buildControllers(nodes, ctx) {
|
|
|
1051
1049
|
output: pluginZod.options?.output ?? output,
|
|
1052
1050
|
group: pluginZod.options?.group ?? void 0
|
|
1053
1051
|
}) : null;
|
|
1054
|
-
const security =
|
|
1052
|
+
const security = kubb_kit.ast.isHttpOperationNode(node) ? getOperationSecurity({
|
|
1055
1053
|
document,
|
|
1056
1054
|
method: node.method,
|
|
1057
1055
|
path: node.path
|
|
@@ -1067,7 +1065,7 @@ function buildControllers(nodes, ctx) {
|
|
|
1067
1065
|
};
|
|
1068
1066
|
}
|
|
1069
1067
|
return nodes.reduce((acc, operationNode) => {
|
|
1070
|
-
if (!
|
|
1068
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return acc;
|
|
1071
1069
|
const tag = operationNode.tags[0];
|
|
1072
1070
|
const name = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.resolveGroupName(tag) : resolver.resolveClassName("ApiClient");
|
|
1073
1071
|
const file = resolver.resolveFile({
|
|
@@ -1119,9 +1117,9 @@ function collectImportsByFile(ops, pick) {
|
|
|
1119
1117
|
* direct method.
|
|
1120
1118
|
*/
|
|
1121
1119
|
function createSdkGenerator() {
|
|
1122
|
-
return (0,
|
|
1120
|
+
return (0, kubb_kit.defineGenerator)({
|
|
1123
1121
|
name: "sdk",
|
|
1124
|
-
renderer:
|
|
1122
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1125
1123
|
operations(nodes, ctx) {
|
|
1126
1124
|
const { config, resolver, root } = ctx;
|
|
1127
1125
|
const { output, group, validator, sdk } = ctx.options;
|
|
@@ -1156,19 +1154,19 @@ function createSdkGenerator() {
|
|
|
1156
1154
|
namesByPath: /* @__PURE__ */ new Map(),
|
|
1157
1155
|
filesByPath: /* @__PURE__ */ new Map()
|
|
1158
1156
|
};
|
|
1159
|
-
return /* @__PURE__ */ (0,
|
|
1157
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1160
1158
|
baseName: file.baseName,
|
|
1161
1159
|
path: file.path,
|
|
1162
1160
|
meta: file.meta,
|
|
1163
1161
|
banner: banner(file),
|
|
1164
1162
|
footer: footer(file),
|
|
1165
1163
|
children: [
|
|
1166
|
-
/* @__PURE__ */ (0,
|
|
1164
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1167
1165
|
name: ["createClient"],
|
|
1168
1166
|
root: file.path,
|
|
1169
1167
|
path: clientPath
|
|
1170
1168
|
}),
|
|
1171
|
-
/* @__PURE__ */ (0,
|
|
1169
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1172
1170
|
name: [
|
|
1173
1171
|
"ClientConfig",
|
|
1174
1172
|
"ClientInstance",
|
|
@@ -1179,23 +1177,23 @@ function createSdkGenerator() {
|
|
|
1179
1177
|
path: clientPath,
|
|
1180
1178
|
isTypeOnly: true
|
|
1181
1179
|
}),
|
|
1182
|
-
validator === "zod" && ops.some((op) => op.node.requestBody?.content?.[0]?.schema != null) && /* @__PURE__ */ (0,
|
|
1180
|
+
validator === "zod" && ops.some((op) => op.node.requestBody?.content?.[0]?.schema != null) && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1183
1181
|
name: ["z"],
|
|
1184
1182
|
path: "zod",
|
|
1185
1183
|
isTypeOnly: true
|
|
1186
1184
|
}),
|
|
1187
|
-
Array.from(typeNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0,
|
|
1185
|
+
Array.from(typeNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1188
1186
|
name: Array.from(set),
|
|
1189
1187
|
root: file.path,
|
|
1190
1188
|
path: typeFilesByPath.get(filePath).path,
|
|
1191
1189
|
isTypeOnly: true
|
|
1192
1190
|
}, filePath)),
|
|
1193
|
-
isValidatorEnabled(validator) && Array.from(zodNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0,
|
|
1191
|
+
isValidatorEnabled(validator) && Array.from(zodNamesByPath.entries()).map(([filePath, set]) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1194
1192
|
name: Array.from(set),
|
|
1195
1193
|
root: file.path,
|
|
1196
1194
|
path: zodFilesByPath.get(filePath).path
|
|
1197
1195
|
}, filePath)),
|
|
1198
|
-
/* @__PURE__ */ (0,
|
|
1196
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SdkClient, {
|
|
1199
1197
|
name: className,
|
|
1200
1198
|
operations: ops,
|
|
1201
1199
|
validator
|
|
@@ -1212,7 +1210,7 @@ function createSdkGenerator() {
|
|
|
1212
1210
|
group: group ?? void 0
|
|
1213
1211
|
}), controllers.flatMap((controller) => controller.operations));
|
|
1214
1212
|
const classFiles = controllers.map(({ name, file, operations: ops }) => renderClassFile(name, file, ops));
|
|
1215
|
-
if (!sdk.name) return /* @__PURE__ */ (0,
|
|
1213
|
+
if (!sdk.name) return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx_jsx_runtime.Fragment, { children: classFiles });
|
|
1216
1214
|
const sdkFile = resolver.resolveFile({
|
|
1217
1215
|
name: sdk.name,
|
|
1218
1216
|
extname: ".ts"
|
|
@@ -1226,25 +1224,25 @@ function createSdkGenerator() {
|
|
|
1226
1224
|
className: name,
|
|
1227
1225
|
propName: resolver.resolveClientPropertyName(tag ?? name)
|
|
1228
1226
|
}));
|
|
1229
|
-
return /* @__PURE__ */ (0,
|
|
1227
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [classFiles, /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1230
1228
|
baseName: sdkFile.baseName,
|
|
1231
1229
|
path: sdkFile.path,
|
|
1232
1230
|
meta: sdkFile.meta,
|
|
1233
1231
|
banner: banner(sdkFile),
|
|
1234
1232
|
footer: footer(sdkFile),
|
|
1235
1233
|
children: [
|
|
1236
|
-
/* @__PURE__ */ (0,
|
|
1234
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1237
1235
|
name: ["ClientConfig"],
|
|
1238
1236
|
root: sdkFile.path,
|
|
1239
1237
|
path: clientPath,
|
|
1240
1238
|
isTypeOnly: true
|
|
1241
1239
|
}),
|
|
1242
|
-
controllers.map(({ name, file }) => /* @__PURE__ */ (0,
|
|
1240
|
+
controllers.map(({ name, file }) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1243
1241
|
name: [name],
|
|
1244
1242
|
root: sdkFile.path,
|
|
1245
1243
|
path: file.path
|
|
1246
1244
|
}, name)),
|
|
1247
|
-
/* @__PURE__ */ (0,
|
|
1245
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SdkFacade, {
|
|
1248
1246
|
name: facadeName,
|
|
1249
1247
|
members
|
|
1250
1248
|
})
|
|
@@ -1260,7 +1258,7 @@ function createSdkGenerator() {
|
|
|
1260
1258
|
* drops union members a broader scalar already covers, keeping the generated response and error
|
|
1261
1259
|
* unions tidy. A plugin wires them with `ctx.setMacros([...defaultMacros, ...userMacros])`.
|
|
1262
1260
|
*/
|
|
1263
|
-
const defaultMacros = [
|
|
1261
|
+
const defaultMacros = [kubb_kit.ast.macroSimplifyUnion];
|
|
1264
1262
|
//#endregion
|
|
1265
1263
|
//#region ../../internals/client/src/resolver.ts
|
|
1266
1264
|
/**
|
|
@@ -1273,7 +1271,7 @@ const defaultMacros = [_kubb_ast_macros.macroSimplifyUnion];
|
|
|
1273
1271
|
* resolverClient.resolveGroupName('pet') // 'PetClient'
|
|
1274
1272
|
* ```
|
|
1275
1273
|
*/
|
|
1276
|
-
const resolverClient = (0,
|
|
1274
|
+
const resolverClient = (0, kubb_kit.defineResolver)(() => ({
|
|
1277
1275
|
name: "default",
|
|
1278
1276
|
pluginName: "plugin-contract-client",
|
|
1279
1277
|
default(name, type) {
|
|
@@ -1303,11 +1301,11 @@ const resolverClient = (0, _kubb_core.defineResolver)(() => ({
|
|
|
1303
1301
|
* operation using the shared `Operation` component: a grouped `<Name>Request` type and a function that
|
|
1304
1302
|
* forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
|
|
1305
1303
|
*/
|
|
1306
|
-
const clientGenerator = (0,
|
|
1304
|
+
const clientGenerator = (0, kubb_kit.defineGenerator)({
|
|
1307
1305
|
name: "fetch",
|
|
1308
|
-
renderer:
|
|
1306
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1309
1307
|
operation(node, ctx) {
|
|
1310
|
-
if (!
|
|
1308
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1311
1309
|
const { config, driver, resolver, root } = ctx;
|
|
1312
1310
|
const { output, validator, group } = ctx.options;
|
|
1313
1311
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
@@ -1347,7 +1345,7 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1347
1345
|
});
|
|
1348
1346
|
const clientPath = node_path.default.resolve(root, ".kubb/client.ts");
|
|
1349
1347
|
const eventStream = isEventStream(node);
|
|
1350
|
-
return /* @__PURE__ */ (0,
|
|
1348
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1351
1349
|
baseName: meta.file.baseName,
|
|
1352
1350
|
path: meta.file.path,
|
|
1353
1351
|
meta: meta.file.meta,
|
|
@@ -1368,12 +1366,12 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1368
1366
|
}
|
|
1369
1367
|
}),
|
|
1370
1368
|
children: [
|
|
1371
|
-
/* @__PURE__ */ (0,
|
|
1369
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1372
1370
|
name: eventStream ? ["client", "toEventStream"] : ["client"],
|
|
1373
1371
|
root: meta.file.path,
|
|
1374
1372
|
path: clientPath
|
|
1375
1373
|
}),
|
|
1376
|
-
/* @__PURE__ */ (0,
|
|
1374
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1377
1375
|
name: eventStream ? [
|
|
1378
1376
|
"Options",
|
|
1379
1377
|
"EventStreamResult",
|
|
@@ -1383,18 +1381,18 @@ const clientGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1383
1381
|
path: clientPath,
|
|
1384
1382
|
isTypeOnly: true
|
|
1385
1383
|
}),
|
|
1386
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
1384
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1387
1385
|
name: Array.from(new Set(importedTypeNames)),
|
|
1388
1386
|
root: meta.file.path,
|
|
1389
1387
|
path: meta.fileTs.path,
|
|
1390
1388
|
isTypeOnly: true
|
|
1391
1389
|
}),
|
|
1392
|
-
meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0,
|
|
1390
|
+
meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1393
1391
|
name: importedZodNames,
|
|
1394
1392
|
root: meta.file.path,
|
|
1395
1393
|
path: meta.fileZod.path
|
|
1396
1394
|
}),
|
|
1397
|
-
/* @__PURE__ */ (0,
|
|
1395
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Operation, {
|
|
1398
1396
|
name: meta.name,
|
|
1399
1397
|
node,
|
|
1400
1398
|
tsResolver,
|
|
@@ -1432,7 +1430,7 @@ const pluginFetchName = "plugin-fetch";
|
|
|
1432
1430
|
*
|
|
1433
1431
|
* @example
|
|
1434
1432
|
* ```ts
|
|
1435
|
-
* import { defineConfig } from 'kubb'
|
|
1433
|
+
* import { defineConfig } from 'kubb/config'
|
|
1436
1434
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1437
1435
|
* import { pluginFetch } from '@kubb/plugin-fetch'
|
|
1438
1436
|
*
|
|
@@ -1446,7 +1444,7 @@ const pluginFetchName = "plugin-fetch";
|
|
|
1446
1444
|
* })
|
|
1447
1445
|
* ```
|
|
1448
1446
|
*/
|
|
1449
|
-
const pluginFetch = (0,
|
|
1447
|
+
const pluginFetch = (0, kubb_kit.definePlugin)((options) => {
|
|
1450
1448
|
const { output = {
|
|
1451
1449
|
path: "clients",
|
|
1452
1450
|
barrel: { type: "named" }
|