@kubb/plugin-ts 5.0.0-beta.15 → 5.0.0-beta.22
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 +25 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +26 -26
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/factory.ts +2 -7
- package/src/generators/typeGenerator.tsx +9 -9
- package/src/printers/printerTs.ts +22 -25
package/dist/index.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ type PrinterTsOptions = {
|
|
|
82
82
|
* Properties to exclude using `Omit<Type, Keys>`.
|
|
83
83
|
* Forces type alias syntax regardless of `syntaxType` setting.
|
|
84
84
|
*/
|
|
85
|
-
keysToOmit?: Array<string
|
|
85
|
+
keysToOmit?: Array<string> | null;
|
|
86
86
|
/**
|
|
87
87
|
* Transforms raw schema names into valid TypeScript identifiers.
|
|
88
88
|
*/
|
|
@@ -552,8 +552,8 @@ type FunctionPrinterOptions = {
|
|
|
552
552
|
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
553
553
|
name: "functionParameters";
|
|
554
554
|
options: FunctionPrinterOptions;
|
|
555
|
-
transform: (node: ast.FunctionParamNode) => string | null
|
|
556
|
-
print: (node: ast.FunctionParamNode) => string | null
|
|
555
|
+
transform: (node: ast.FunctionParamNode) => string | null;
|
|
556
|
+
print: (node: ast.FunctionParamNode) => string | null;
|
|
557
557
|
};
|
|
558
558
|
//#endregion
|
|
559
559
|
//#region src/resolvers/resolverTs.d.ts
|
package/dist/index.js
CHANGED
|
@@ -876,7 +876,7 @@ const printerTs = ast.definePrinter((options) => {
|
|
|
876
876
|
date: dateOrStringNode,
|
|
877
877
|
time: dateOrStringNode,
|
|
878
878
|
ref(node) {
|
|
879
|
-
if (!node.name) return;
|
|
879
|
+
if (!node.name) return null;
|
|
880
880
|
const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
881
881
|
return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) && this.options.enumTypeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.resolveEnumKeyName({ name: refName }, this.options.enumTypeSuffix) : node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
|
|
882
882
|
},
|
|
@@ -913,16 +913,16 @@ const printerTs = ast.definePrinter((options) => {
|
|
|
913
913
|
return createIntersectionDeclaration({
|
|
914
914
|
withParentheses: true,
|
|
915
915
|
nodes: buildMemberNodes(node.members, this.transform)
|
|
916
|
-
}) ??
|
|
916
|
+
}) ?? null;
|
|
917
917
|
},
|
|
918
918
|
array(node) {
|
|
919
919
|
return createArrayDeclaration({
|
|
920
920
|
nodes: (node.items ?? []).map((item) => this.transform(item)).filter(isNonNullable),
|
|
921
921
|
arrayType: this.options.arrayType
|
|
922
|
-
}) ??
|
|
922
|
+
}) ?? null;
|
|
923
923
|
},
|
|
924
924
|
tuple(node) {
|
|
925
|
-
return buildTupleNode(node, this.transform);
|
|
925
|
+
return buildTupleNode(node, this.transform) ?? null;
|
|
926
926
|
},
|
|
927
927
|
object(node) {
|
|
928
928
|
const { transform, options } = this;
|
|
@@ -949,27 +949,27 @@ const printerTs = ast.definePrinter((options) => {
|
|
|
949
949
|
},
|
|
950
950
|
print(node) {
|
|
951
951
|
const { name, syntaxType = "type", description, keysToOmit } = this.options;
|
|
952
|
-
|
|
953
|
-
if (!
|
|
952
|
+
const transformed = this.transform(node);
|
|
953
|
+
if (!transformed) return null;
|
|
954
954
|
const meta = ast.syncSchemaRef(node);
|
|
955
955
|
if (!name) {
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
return safePrint(base);
|
|
956
|
+
const withNullable = meta.nullable ? createUnionDeclaration({ nodes: [transformed, keywordTypeNodes.null] }) : transformed;
|
|
957
|
+
return safePrint((meta.nullish || meta.optional) && addsUndefined ? createUnionDeclaration({ nodes: [withNullable, keywordTypeNodes.undefined] }) : withNullable);
|
|
959
958
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
959
|
+
const inner = (() => {
|
|
960
|
+
const omitted = keysToOmit?.length ? createOmitDeclaration({
|
|
961
|
+
keys: keysToOmit,
|
|
962
|
+
type: transformed,
|
|
963
|
+
nonNullable: true
|
|
964
|
+
}) : transformed;
|
|
965
|
+
const withNullable = meta.nullable ? createUnionDeclaration({ nodes: [omitted, keywordTypeNodes.null] }) : omitted;
|
|
966
|
+
return meta.nullish || meta.optional ? createUnionDeclaration({ nodes: [withNullable, keywordTypeNodes.undefined] }) : withNullable;
|
|
967
|
+
})();
|
|
968
968
|
return safePrint(createTypeDeclaration({
|
|
969
969
|
name,
|
|
970
970
|
isExportable: true,
|
|
971
971
|
type: inner,
|
|
972
|
-
syntax:
|
|
972
|
+
syntax: syntaxType === "type" || inner.kind === syntaxKind.union || !!keysToOmit?.length ? "type" : "interface",
|
|
973
973
|
comments: buildPropertyJSDocComments({
|
|
974
974
|
...meta,
|
|
975
975
|
description
|
|
@@ -998,10 +998,10 @@ const typeGenerator = defineGenerator({
|
|
|
998
998
|
renderer: jsxRendererSync,
|
|
999
999
|
schema(node, ctx) {
|
|
1000
1000
|
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
|
|
1001
|
-
const { adapter, config, resolver, root
|
|
1001
|
+
const { adapter, config, resolver, root } = ctx;
|
|
1002
1002
|
if (!node.name) return;
|
|
1003
1003
|
const mode = ctx.getMode(output);
|
|
1004
|
-
const enumSchemaNames = new Set(
|
|
1004
|
+
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1005
1005
|
function resolveImportName(schemaName) {
|
|
1006
1006
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
|
|
1007
1007
|
return resolver.resolveTypeName(schemaName);
|
|
@@ -1045,11 +1045,11 @@ const typeGenerator = defineGenerator({
|
|
|
1045
1045
|
baseName: meta.file.baseName,
|
|
1046
1046
|
path: meta.file.path,
|
|
1047
1047
|
meta: meta.file.meta,
|
|
1048
|
-
banner: resolver.resolveBanner(
|
|
1048
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
1049
1049
|
output,
|
|
1050
1050
|
config
|
|
1051
1051
|
}),
|
|
1052
|
-
footer: resolver.resolveFooter(
|
|
1052
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1053
1053
|
output,
|
|
1054
1054
|
config
|
|
1055
1055
|
}),
|
|
@@ -1075,7 +1075,7 @@ const typeGenerator = defineGenerator({
|
|
|
1075
1075
|
},
|
|
1076
1076
|
operation(node, ctx) {
|
|
1077
1077
|
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = ctx.options;
|
|
1078
|
-
const { adapter, config, resolver, root
|
|
1078
|
+
const { adapter, config, resolver, root } = ctx;
|
|
1079
1079
|
const mode = ctx.getMode(output);
|
|
1080
1080
|
const params = ast.caseParams(node.parameters, paramsCasing);
|
|
1081
1081
|
const meta = { file: resolver.resolveFile({
|
|
@@ -1088,7 +1088,7 @@ const typeGenerator = defineGenerator({
|
|
|
1088
1088
|
output,
|
|
1089
1089
|
group
|
|
1090
1090
|
}) };
|
|
1091
|
-
const enumSchemaNames = new Set(
|
|
1091
|
+
const enumSchemaNames = new Set(ctx.meta.enumNames);
|
|
1092
1092
|
function resolveImportName(schemaName) {
|
|
1093
1093
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
|
|
1094
1094
|
return resolver.resolveTypeName(schemaName);
|
|
@@ -1227,11 +1227,11 @@ const typeGenerator = defineGenerator({
|
|
|
1227
1227
|
baseName: meta.file.baseName,
|
|
1228
1228
|
path: meta.file.path,
|
|
1229
1229
|
meta: meta.file.meta,
|
|
1230
|
-
banner: resolver.resolveBanner(
|
|
1230
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
1231
1231
|
output,
|
|
1232
1232
|
config
|
|
1233
1233
|
}),
|
|
1234
|
-
footer: resolver.resolveFooter(
|
|
1234
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1235
1235
|
output,
|
|
1236
1236
|
config
|
|
1237
1237
|
}),
|