UNPKG

zod-to-x

Version:

Multi language types generation from Zod schemas.

97 lines (96 loc) 3.54 kB
import { ASTCommon, ASTDiscriminatedUnion, ASTEnum, ASTIntersection, ASTNativeEnum, ASTObject, ASTUnion, Zod2X } from "../../core"; import { IZod2TsOpt } from "./options"; export declare class Zod2Ts extends Zod2X<IZod2TsOpt> { constructor(opt?: IZod2TsOpt); protected runAfter(): void; protected runBefore(): void; protected addImportFromFile(filename: string, namespace: string): string; protected getTypeFromExternalNamespace(namespace: string, typeName: string): string; protected addExtendedType(name: string, parentNamespace: string, parentTypeName: string, opt?: { isUnion?: boolean; isDiscriminatedUnion?: boolean; }): void; protected getComment: (data: string, indent?: string) => string; protected getAnyType: () => string; protected getBooleanType: () => string; protected getDateType: () => string; /** Ex: Set<TypeA> */ protected getSetType: (itemType: string) => string; protected getStringType: () => string; /** Ex: [TypeA, TypeB] */ protected getTupleType: (itemsType: string[]) => string; /** Ex: TypeA | TypeB */ protected getUnionType: (itemsType: string[]) => string; /** Ex: TypeA & TypeB */ protected getIntersectionType: (itemsType: string[]) => string; protected getNumberType: () => string; /** Ex: Array<Array<TypeA[]>> */ protected getArrayType(arrayType: string, arrayDeep: number): string; protected getLiteralStringType(value: string | number, parentEnumNameKey?: [string, string]): string | number; /** Ex: Map<TypeA, TypeB> */ protected getMapType(keyType: string, valueType: string): string; /** Ex: Record<TypeA, TypeB> */ protected getRecordType(keyType: string, valueType: string): string; /** Ex: * enum { * ItemKey1: 0, // case of nativeEnum * ItemKey2: "ItemValue2" // case of Enum * } */ protected transpileEnum(data: (ASTEnum | ASTNativeEnum) & ASTCommon): void; /** Ex: * // Interface output * // Class output if non-object intersection * type TypeC = TypeA & TypeB * * // Class output all-object intersection * class TypeC { * ...attributesTypeA, * ...attributesTypeB * * constructor(data: TypeC) { * ...attributesAssignment * } * } * */ protected transpileIntersection(data: ASTIntersection & ASTCommon): void; protected transpileStruct(data: ASTObject & ASTCommon): void; /** Ex: * // Interface output * // Class output for Discriminated Union or non-objects union * type TypeC = TypeA | TypeB * * // Class output for all-object Union * class TypeC { * ...attributesTypeA, * ...attributesTypeB * * constructor(data: TypeC) { * ...attributesAssignment * } * } * */ protected transpileUnion(data: (ASTUnion | ASTDiscriminatedUnion) & ASTCommon): void; /** Ex: * interface MyStruct { * att1: TypeA; * att2?: TypeB; * } * */ private _transpileStructuAsInterface; /** Ex: * class MyStruct { * att1: TypeA; * att2?: TypeB; * * constructor(data: MyStruct) { * this.att1 = data.att1; * this.att2 = data.att2; * } * } * */ private _transpileStructAsClass; /** For Interface/Class attributes. * Ex: attribute1?: TypeA | null */ private _transpileMember; }