@kubb/plugin-ts 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 +72 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +74 -103
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/generators/typeGenerator.tsx +33 -46
- package/src/generators/typeGeneratorLegacy.tsx +16 -28
- package/src/plugin.ts +23 -49
- package/src/types.ts +12 -1
package/dist/index.cjs
CHANGED
|
@@ -21,8 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
let node_path = require("node:path");
|
|
25
|
-
node_path = __toESM(node_path);
|
|
26
24
|
let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
|
|
27
25
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
28
26
|
let _kubb_ast = require("@kubb/ast");
|
|
@@ -882,19 +880,17 @@ const printerTs = (0, _kubb_core.definePrinter)((options) => {
|
|
|
882
880
|
//#region src/generators/typeGenerator.tsx
|
|
883
881
|
const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
884
882
|
name: "typescript",
|
|
885
|
-
|
|
886
|
-
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
883
|
+
schema(node, options) {
|
|
887
884
|
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = options;
|
|
888
|
-
const
|
|
889
|
-
if (!
|
|
890
|
-
const
|
|
891
|
-
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
885
|
+
const { adapter, config, resolver, root } = this;
|
|
886
|
+
if (!node.name) return;
|
|
887
|
+
const mode = this.getMode(output);
|
|
892
888
|
const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => (0, _kubb_ast.narrowSchema)(s, _kubb_ast.schemaTypes.enum) && s.name).map((s) => s.name));
|
|
893
889
|
function resolveImportName(schemaName) {
|
|
894
890
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
|
|
895
891
|
return resolver.resolveTypeName(schemaName);
|
|
896
892
|
}
|
|
897
|
-
const imports = adapter.getImports(
|
|
893
|
+
const imports = adapter.getImports(node, (schemaName) => ({
|
|
898
894
|
name: resolveImportName(schemaName),
|
|
899
895
|
path: resolver.resolveFile({
|
|
900
896
|
name: schemaName,
|
|
@@ -905,11 +901,11 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
905
901
|
group
|
|
906
902
|
}).path
|
|
907
903
|
}));
|
|
908
|
-
const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(
|
|
904
|
+
const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(node, _kubb_ast.schemaTypes.enum);
|
|
909
905
|
const meta = {
|
|
910
|
-
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(
|
|
906
|
+
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
|
|
911
907
|
file: resolver.resolveFile({
|
|
912
|
-
name:
|
|
908
|
+
name: node.name,
|
|
913
909
|
extname: ".ts"
|
|
914
910
|
}, {
|
|
915
911
|
root,
|
|
@@ -924,7 +920,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
924
920
|
enumTypeSuffix,
|
|
925
921
|
name: meta.name,
|
|
926
922
|
syntaxType,
|
|
927
|
-
description:
|
|
923
|
+
description: node.description,
|
|
928
924
|
resolver,
|
|
929
925
|
enumSchemaNames,
|
|
930
926
|
nodes: printer?.nodes
|
|
@@ -947,12 +943,12 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
947
943
|
name: imp.name,
|
|
948
944
|
isTypeOnly: true
|
|
949
945
|
}, [
|
|
950
|
-
|
|
946
|
+
node.name,
|
|
951
947
|
imp.path,
|
|
952
948
|
imp.isTypeOnly
|
|
953
949
|
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
|
|
954
950
|
name: meta.name,
|
|
955
|
-
node
|
|
951
|
+
node,
|
|
956
952
|
enumType,
|
|
957
953
|
enumTypeSuffix,
|
|
958
954
|
enumKeyCasing,
|
|
@@ -961,17 +957,16 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
961
957
|
})]
|
|
962
958
|
});
|
|
963
959
|
},
|
|
964
|
-
|
|
960
|
+
operation(node, options) {
|
|
965
961
|
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = options;
|
|
966
|
-
const
|
|
967
|
-
const
|
|
968
|
-
const
|
|
969
|
-
const params = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
|
|
962
|
+
const { adapter, config, resolver, root } = this;
|
|
963
|
+
const mode = this.getMode(output);
|
|
964
|
+
const params = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
|
|
970
965
|
const meta = { file: resolver.resolveFile({
|
|
971
|
-
name:
|
|
966
|
+
name: node.operationId,
|
|
972
967
|
extname: ".ts",
|
|
973
|
-
tag:
|
|
974
|
-
path:
|
|
968
|
+
tag: node.tags[0] ?? "default",
|
|
969
|
+
path: node.path
|
|
975
970
|
}, {
|
|
976
971
|
root,
|
|
977
972
|
output,
|
|
@@ -1029,38 +1024,38 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1029
1024
|
}
|
|
1030
1025
|
const paramTypes = params.map((param) => renderSchemaType({
|
|
1031
1026
|
schema: param.schema,
|
|
1032
|
-
name: resolver.resolveParamName(
|
|
1027
|
+
name: resolver.resolveParamName(node, param)
|
|
1033
1028
|
}));
|
|
1034
|
-
const requestType =
|
|
1029
|
+
const requestType = node.requestBody?.schema ? renderSchemaType({
|
|
1035
1030
|
schema: {
|
|
1036
|
-
...
|
|
1037
|
-
description:
|
|
1031
|
+
...node.requestBody.schema,
|
|
1032
|
+
description: node.requestBody.description ?? node.requestBody.schema.description
|
|
1038
1033
|
},
|
|
1039
|
-
name: resolver.resolveDataName(
|
|
1040
|
-
keysToOmit:
|
|
1034
|
+
name: resolver.resolveDataName(node),
|
|
1035
|
+
keysToOmit: node.requestBody.keysToOmit
|
|
1041
1036
|
}) : null;
|
|
1042
|
-
const responseTypes =
|
|
1037
|
+
const responseTypes = node.responses.map((res) => renderSchemaType({
|
|
1043
1038
|
schema: res.schema,
|
|
1044
|
-
name: resolver.resolveResponseStatusName(
|
|
1039
|
+
name: resolver.resolveResponseStatusName(node, res.statusCode),
|
|
1045
1040
|
keysToOmit: res.keysToOmit
|
|
1046
1041
|
}));
|
|
1047
1042
|
const dataType = renderSchemaType({
|
|
1048
1043
|
schema: buildData({
|
|
1049
|
-
...
|
|
1044
|
+
...node,
|
|
1050
1045
|
parameters: params
|
|
1051
1046
|
}, { resolver }),
|
|
1052
|
-
name: resolver.resolveRequestConfigName(
|
|
1047
|
+
name: resolver.resolveRequestConfigName(node)
|
|
1053
1048
|
});
|
|
1054
1049
|
const responsesType = renderSchemaType({
|
|
1055
|
-
schema: buildResponses(
|
|
1056
|
-
name: resolver.resolveResponsesName(
|
|
1050
|
+
schema: buildResponses(node, { resolver }),
|
|
1051
|
+
name: resolver.resolveResponsesName(node)
|
|
1057
1052
|
});
|
|
1058
1053
|
const responseType = renderSchemaType({
|
|
1059
|
-
schema:
|
|
1060
|
-
...buildResponseUnion(
|
|
1054
|
+
schema: node.responses.some((res) => res.schema) ? {
|
|
1055
|
+
...buildResponseUnion(node, { resolver }),
|
|
1061
1056
|
description: "Union of all possible responses"
|
|
1062
1057
|
} : null,
|
|
1063
|
-
name: resolver.resolveResponseName(
|
|
1058
|
+
name: resolver.resolveResponseName(node)
|
|
1064
1059
|
});
|
|
1065
1060
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
1066
1061
|
baseName: meta.file.baseName,
|
|
@@ -1086,6 +1081,9 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1086
1081
|
}
|
|
1087
1082
|
});
|
|
1088
1083
|
//#endregion
|
|
1084
|
+
//#region package.json
|
|
1085
|
+
var version = "5.0.0-alpha.30";
|
|
1086
|
+
//#endregion
|
|
1089
1087
|
//#region src/resolvers/resolverTs.ts
|
|
1090
1088
|
/**
|
|
1091
1089
|
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
@@ -1359,14 +1357,12 @@ function nameUnnamedEnums(node, parentName) {
|
|
|
1359
1357
|
}
|
|
1360
1358
|
const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
1361
1359
|
name: "typescript-legacy",
|
|
1362
|
-
|
|
1363
|
-
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
1360
|
+
schema(node, options) {
|
|
1364
1361
|
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group } = options;
|
|
1365
|
-
const
|
|
1366
|
-
if (!
|
|
1367
|
-
const
|
|
1368
|
-
const
|
|
1369
|
-
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
1362
|
+
const { adapter, config, resolver, root } = this;
|
|
1363
|
+
if (!node.name) return;
|
|
1364
|
+
const mode = this.getMode(output);
|
|
1365
|
+
const imports = adapter.getImports(node, (schemaName) => ({
|
|
1370
1366
|
name: resolver.resolveTypeName(schemaName),
|
|
1371
1367
|
path: resolver.resolveFile({
|
|
1372
1368
|
name: schemaName,
|
|
@@ -1377,11 +1373,11 @@ const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1377
1373
|
group
|
|
1378
1374
|
}).path
|
|
1379
1375
|
}));
|
|
1380
|
-
const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(
|
|
1376
|
+
const isEnumSchema = !!(0, _kubb_ast.narrowSchema)(node, _kubb_ast.schemaTypes.enum);
|
|
1381
1377
|
const meta = {
|
|
1382
|
-
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(
|
|
1378
|
+
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
|
|
1383
1379
|
file: resolver.resolveFile({
|
|
1384
|
-
name:
|
|
1380
|
+
name: node.name,
|
|
1385
1381
|
extname: ".ts"
|
|
1386
1382
|
}, {
|
|
1387
1383
|
root,
|
|
@@ -1396,7 +1392,7 @@ const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1396
1392
|
enumTypeSuffix,
|
|
1397
1393
|
name: meta.name,
|
|
1398
1394
|
syntaxType,
|
|
1399
|
-
description:
|
|
1395
|
+
description: node.description,
|
|
1400
1396
|
resolver
|
|
1401
1397
|
});
|
|
1402
1398
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
@@ -1417,12 +1413,12 @@ const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1417
1413
|
name: imp.name,
|
|
1418
1414
|
isTypeOnly: true
|
|
1419
1415
|
}, [
|
|
1420
|
-
|
|
1416
|
+
node.name,
|
|
1421
1417
|
imp.path,
|
|
1422
1418
|
imp.isTypeOnly
|
|
1423
1419
|
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Type, {
|
|
1424
1420
|
name: meta.name,
|
|
1425
|
-
node
|
|
1421
|
+
node,
|
|
1426
1422
|
enumType,
|
|
1427
1423
|
enumTypeSuffix,
|
|
1428
1424
|
enumKeyCasing,
|
|
@@ -1431,17 +1427,16 @@ const typeGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1431
1427
|
})]
|
|
1432
1428
|
});
|
|
1433
1429
|
},
|
|
1434
|
-
|
|
1430
|
+
operation(node, options) {
|
|
1435
1431
|
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output } = options;
|
|
1436
|
-
const
|
|
1437
|
-
const
|
|
1438
|
-
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
1432
|
+
const { adapter, config, resolver, root } = this;
|
|
1433
|
+
const mode = this.getMode(output);
|
|
1439
1434
|
const params = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
|
|
1440
1435
|
const meta = { file: resolver.resolveFile({
|
|
1441
|
-
name:
|
|
1436
|
+
name: node.operationId,
|
|
1442
1437
|
extname: ".ts",
|
|
1443
|
-
tag:
|
|
1444
|
-
path:
|
|
1438
|
+
tag: node.tags[0] ?? "default",
|
|
1439
|
+
path: node.path
|
|
1445
1440
|
}, {
|
|
1446
1441
|
root,
|
|
1447
1442
|
output,
|
|
@@ -1618,10 +1613,12 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1618
1613
|
transformer: userTransformer,
|
|
1619
1614
|
generators: userGenerators
|
|
1620
1615
|
});
|
|
1616
|
+
const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
|
|
1621
1617
|
let resolveNameWarning = false;
|
|
1622
1618
|
let resolvePathWarning = false;
|
|
1623
1619
|
return {
|
|
1624
1620
|
name: pluginTsName,
|
|
1621
|
+
version,
|
|
1625
1622
|
get resolver() {
|
|
1626
1623
|
return preset.resolver;
|
|
1627
1624
|
},
|
|
@@ -1631,6 +1628,9 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1631
1628
|
get options() {
|
|
1632
1629
|
return {
|
|
1633
1630
|
output,
|
|
1631
|
+
exclude,
|
|
1632
|
+
include,
|
|
1633
|
+
override,
|
|
1634
1634
|
optionalType,
|
|
1635
1635
|
group: group ? {
|
|
1636
1636
|
...group,
|
|
@@ -1650,7 +1650,7 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1650
1650
|
},
|
|
1651
1651
|
resolvePath(baseName, pathMode, options) {
|
|
1652
1652
|
if (!resolvePathWarning) {
|
|
1653
|
-
this.
|
|
1653
|
+
this.warn("Do not use resolvePath for pluginTs, use resolverTs.resolvePath instead");
|
|
1654
1654
|
resolvePathWarning = true;
|
|
1655
1655
|
}
|
|
1656
1656
|
return this.plugin.resolver.resolvePath({
|
|
@@ -1659,59 +1659,29 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1659
1659
|
tag: options?.group?.tag,
|
|
1660
1660
|
path: options?.group?.path
|
|
1661
1661
|
}, {
|
|
1662
|
-
root:
|
|
1662
|
+
root: this.root,
|
|
1663
1663
|
output,
|
|
1664
1664
|
group: this.plugin.options.group
|
|
1665
1665
|
});
|
|
1666
1666
|
},
|
|
1667
1667
|
resolveName(name, type) {
|
|
1668
1668
|
if (!resolveNameWarning) {
|
|
1669
|
-
this.
|
|
1669
|
+
this.warn("Do not use resolveName for pluginTs, use resolverTs.default instead");
|
|
1670
1670
|
resolveNameWarning = true;
|
|
1671
1671
|
}
|
|
1672
1672
|
return this.plugin.resolver.default(name, type);
|
|
1673
1673
|
},
|
|
1674
|
-
async
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
include,
|
|
1686
|
-
override,
|
|
1687
|
-
fabric,
|
|
1688
|
-
adapter,
|
|
1689
|
-
config,
|
|
1690
|
-
driver
|
|
1691
|
-
};
|
|
1692
|
-
await (0, _kubb_ast.walk)(rootNode, {
|
|
1693
|
-
depth: "shallow",
|
|
1694
|
-
async schema(schemaNode) {
|
|
1695
|
-
await (0, _kubb_core.runGeneratorSchema)(schemaNode, generatorContext);
|
|
1696
|
-
},
|
|
1697
|
-
async operation(operationNode) {
|
|
1698
|
-
if (resolver.resolveOptions(operationNode, {
|
|
1699
|
-
options: plugin.options,
|
|
1700
|
-
exclude,
|
|
1701
|
-
include,
|
|
1702
|
-
override
|
|
1703
|
-
}) !== null) collectedOperations.push(operationNode);
|
|
1704
|
-
await (0, _kubb_core.runGeneratorOperation)(operationNode, generatorContext);
|
|
1705
|
-
}
|
|
1706
|
-
});
|
|
1707
|
-
await (0, _kubb_core.runGeneratorOperations)(collectedOperations, generatorContext);
|
|
1708
|
-
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
1709
|
-
type: output.barrelType ?? "named",
|
|
1710
|
-
root,
|
|
1711
|
-
output,
|
|
1712
|
-
meta: { pluginName: this.plugin.name }
|
|
1713
|
-
});
|
|
1714
|
-
await this.upsertFile(...barrelFiles);
|
|
1674
|
+
async schema(node, options) {
|
|
1675
|
+
return mergedGenerator.schema?.call(this, node, options);
|
|
1676
|
+
},
|
|
1677
|
+
async operation(node, options) {
|
|
1678
|
+
return mergedGenerator.operation?.call(this, node, options);
|
|
1679
|
+
},
|
|
1680
|
+
async operations(nodes, options) {
|
|
1681
|
+
return mergedGenerator.operations?.call(this, nodes, options);
|
|
1682
|
+
},
|
|
1683
|
+
async buildStart() {
|
|
1684
|
+
await this.openInStudio({ ast: true });
|
|
1715
1685
|
}
|
|
1716
1686
|
};
|
|
1717
1687
|
});
|