pg-proto-parser
Version:
51 lines (50 loc) • 2.94 kB
TypeScript
import { Enum } from '@launchql/protobufjs';
import * as t from '@babel/types';
/**
* Converts a protobuf Enum into a TypeScript enum declaration.
* Example output: export enum MyEnum { VALUE1 = 0, VALUE2 = 1, ... }
* This is the traditional enum format that creates both type and value in TypeScript.
*/
export declare const convertEnumToTsEnumDeclaration: (enumData: Enum) => t.ExportNamedDeclaration;
/**
* Generates import statements for enums from a specified source module.
* Used when enums need to be imported into other generated files (like types.ts).
* Example output: import { Enum1, Enum2, ... } from './enums';
*/
export declare const generateEnumImports: (enums: Enum[], source: string) => t.ImportDeclaration;
/**
* Converts a protobuf Enum into a TypeScript union type of string literals.
* Example output: export type MyEnum = 'VALUE1' | 'VALUE2' | ...
* This creates a type-only representation without runtime values.
*/
export declare const convertEnumToTsUnionType: (enumData: Enum) => t.ExportNamedDeclaration;
/**
* Generates a bidirectional enum value converter function that can convert between string keys and numeric values.
* Creates getEnumValue(enumType, key) that accepts either string or number and returns the corresponding value.
* Example: getEnumValue('MyEnum', 'VALUE1') => 0, getEnumValue('MyEnum', 0) => 'VALUE1'
*/
export declare const generateEnumValueFunctions: (enumData: Enum[]) => t.ExportNamedDeclaration[];
/**
* Generates a unidirectional function that converts enum string keys to their numeric values.
* Creates getEnumInt(enumType, key) that only accepts string keys and returns numbers.
* Example: getEnumInt('MyEnum', 'VALUE1') => 0
*/
export declare const generateEnumToIntFunctions: (enumData: Enum[]) => t.ExportNamedDeclaration[];
/**
* Generates a nested object structure with individual converter functions for each enum.
* Creates enumToIntMap object where each enum has its own converter: enumToIntMap.MyEnum('VALUE1') => 0
* This format provides better type safety and autocomplete for specific enums.
*/
export declare const generateEnumToIntFunctionsNested: (enumData: Enum[]) => t.ExportNamedDeclaration[];
/**
* Generates a nested object structure with functions to convert enum numeric values to string keys.
* Creates enumToStringMap object where each enum has its own converter: enumToStringMap.MyEnum(0) => 'VALUE1'
* Provides type-safe reverse mapping from numbers to string keys.
*/
export declare const generateEnumToStringFunctionsNested: (enumData: Enum[]) => t.ExportNamedDeclaration[];
/**
* Generates a unidirectional function that converts enum numeric values to their string keys.
* Creates getEnumString(enumType, key) that only accepts numbers and returns string keys.
* Example: getEnumString('MyEnum', 0) => 'VALUE1'
*/
export declare const generateEnumToStringFunctions: (enumData: Enum[]) => t.ExportNamedDeclaration[];