UNPKG

pg-proto-parser

Version:
48 lines (47 loc) 2.93 kB
import { Type } from '@launchql/protobufjs'; import * as t from '@babel/types'; import { PgProtoParserOptions } from '../../options'; /** * Generates import statements for types from a specified source module. * Can optionally add a suffix to imported type names (e.g., import { Type as TypeSuffix }) * Used when types need to be imported into other generated files. */ export declare const generateTypeImports: (types: Type[], source: string, suffix?: string) => t.ImportDeclaration; /** * Generates helper factory methods for creating AST node instances. * Creates an object with camelCase methods for each type (e.g., selectStmt() for SelectStmt type). * Each method accepts optional initial values and returns the type directly. * Example output: { selectStmt: (_p?: SelectStmt) => SelectStmt } */ export declare const generateAstHelperMethods: (types: Type[]) => t.ExportDefaultDeclaration; /** * Generates helper factory methods that return AST nodes wrapped in a type-specific object. * Creates an object with camelCase methods for each type (e.g., selectStmt() for SelectStmt type). * Each method accepts optional initial values and returns { TypeName: TypeInstance }. * Example output: { selectStmt: (_p?: SelectStmt) => { SelectStmt: SelectStmt } } */ export declare const generateWrappedAstHelperMethods: (types: Type[]) => t.ExportDefaultDeclaration; /** * Generates a TypeScript union type named 'Node' that includes all AST node types. * Can generate either a simple union (Type1 | Type2 | ...) or wrapped objects ({ Type1: Type1 } | { Type2: Type2 } | ...) * based on the wrappedNodeTypeExport option. This is the main type used to represent any AST node. */ export declare const generateNodeUnionType: (options: PgProtoParserOptions, types: Type[]) => t.ExportNamedDeclaration; /** * Generates a Node union type where each type is wrapped in an object with the type name as key. * Example output: type Node = { SelectStmt: SelectStmt } | { InsertStmt: InsertStmt } | ... * This format makes it easier to determine the specific type of a node at runtime. */ export declare const generateNodeUnionTypeObjectKeys: (types: Type[]) => t.ExportNamedDeclaration; /** * Converts a protobuf Type definition into a TypeScript interface declaration. * Handles field types, arrays (repeated fields), and optional fields based on options. * Example: Type "SelectStmt" with fields becomes: export interface SelectStmt { field1?: Type1; ... } */ export declare const convertTypeToTsInterface: (type: Type, options: PgProtoParserOptions) => t.ExportNamedDeclaration; /** * Generates import specifiers for types from the configured types source. * Used in ast-helpers to import all the type definitions. * Example output: import { SelectStmt, InsertStmt, ... } from './types'; */ export declare const generateTypeImportSpecifiers: (types: Type[], options: PgProtoParserOptions) => t.ImportDeclaration;