zod-to-x
Version:
Multi language types generation from Zod schemas.
81 lines (80 loc) • 3.83 kB
TypeScript
import { ASTCommon, ASTDiscriminatedUnion, ASTEnum, ASTIntersection, ASTNativeEnum, ASTObject, ASTUnion, Zod2X } from "../../core";
import { IZod2ProtoV3Opt } from "./options";
/**
* @deprecated Zod2ProtoV3 will not be considered as a transpilerable programming language, but as
* another utility such as `zod2JsonSchemaDefinitions`.
*/
export declare class Zod2ProtoV3 extends Zod2X<IZod2ProtoV3Opt> {
constructor(opt?: IZod2ProtoV3Opt);
protected getUnionType: () => string;
protected addImportFromFile(filename: string, namespace: string): string;
protected getTypeFromExternalNamespace(namespace: string, typeName: string): string;
protected addExtendedType(name: string, parentNamespace: string, parentTypeName: string): void;
protected getComment: (data: string, indent?: string) => string;
protected getBooleanType: () => string;
protected getStringType: () => string;
protected getNumberType: (isInt: boolean, range: {
min?: number;
max?: number;
}) => string;
protected getAnyType: () => string;
protected getDateType: () => string;
protected getSetType: (itemType: string) => string;
/**
* @description Determines the equivalent Protobuf type for a tuple based on its item types.
*
* Protobuf v3 does not directly support tuples. However, if all the types
* in the tuple are identical, it can be represented as a `repeated` field
* of that type. If the tuple contains mixed types, Protobuf cannot represent
* it directly, and an alternative approach (e.g., defining a Protobuf message)
* should be considered.
*
* @param itemsType - An array of strings representing the types of the tuple elements.
* @returns A string representing the Protobuf type for the tuple.
* If all tuple elements are of the same type, it returns a `repeated` field of that
* type.
* @throws NotTranspilerableTypeError if the tuple contains mixed types.
*/
protected getTupleType: (itemsType: string[]) => string;
protected getIntersectionType: (itemsType: string[]) => string;
protected getArrayType(arrayType: string, arrayDeep: number): string;
protected getLiteralStringType(value: string | number): string | number;
protected getMapType(keyType: string, valueType: string): string;
protected getRecordType(keyType: string, valueType: string): string;
protected transpileEnum(data: (ASTEnum | ASTNativeEnum) & ASTCommon): void;
protected transpileIntersection(data: ASTIntersection & ASTCommon): void;
protected transpileStruct(data: ASTObject & ASTCommon): void;
/**
* Transpiles a Zod union or discriminated union into a Protobuf-compatible `oneof` message.
*
* @limitations Currently supports `oneOf` for options that can be represented as a
* Protobuf message or enum. Other types are not yet supported.
* @param data The AST representation of a union or discriminated union, including its
* common metadata.
* @example
* Input:
* {
* name: "UserContact",
* options: ["EmailContact", "PhoneContact", "SocialContact"],
* description: "Represents different ways to contact a user."
* }
*
* Generated Output:
* message UserContact {
* oneof user_contact_oneof {
* EmailContact email_contact = 1;
* PhoneContact phone_contact = 2;
* SocialContact social_contact = 3;
* }
* }
*/
protected transpileUnion(data: (ASTUnion | ASTDiscriminatedUnion) & ASTCommon): void;
protected runBefore(): void;
protected runAfter(): void;
/**
* Adapt field name according to user input.
* @param fieldName
* @returns
*/
private _adaptField;
}