import type { ParsedRule, SchemaArray, SchemaObject, SchemaLiteral, ValidationField, ParsedSchemaTree, CompilerOutput } from '../types.js'; import { CompilerBuffer } from './buffer/index.js'; /** * Compiler exposes the API to compile the schema tree into a set of Javascript * instructions. */ export declare class Compiler { private schema; /** * Reference counters. They are required for node compilers to * create safe and unique variable names */ outVariableCounter: number; referenceVariableCounter: number; arrayIndexVariableCounter: number; /** * The name of certain properties referenced inside * the compiled output */ COMPILER_REFERENCES: { validations: string; exists: string; isObject: string; reportError: string; }; constructor(schema: ParsedSchemaTree); /** * Returns the name of the options object for a given variable */ getVariableOptionsName(variableName: string): string; /** * Returns the name of the mutation function for a given variable */ getVariableMutationName(variableName: string): string; /** * The variable name to hold the boolean if value is undefined or not */ getVariableExistsName(variableName: string): string; /** * Returns the declaration for the undefined and the null check */ getVariableExistsDeclaration(variableName: string): string; /** * Returns the expression to declare the mutation function for a given * field. */ getMutationFnDeclararationExpression(variableName: string): string; /** * Returns the expression to declare the options */ getOptionsDeclarationExpression(variableName: string, field: string, tip: string, pointer: string, arrayExpressionPointer?: string): string; /** * Returns the method call expression for executing validation * a given rule */ getValidationCallableExpression(variableName: string, rule: ParsedRule): string; /** * Converts a pointer to a Javascript expression */ pointerToExpression(pointer: ValidationField): string; /** * Converts an array of pointers to a Javascript expression */ pointersToExpression(pointer: ValidationField[]): string; /** * Compiles a given node inside the schema tree. The compiled * output is written to the buffer */ compileNode(field: string | ValidationField, node: SchemaArray | SchemaLiteral | SchemaObject, buffer: CompilerBuffer, parentPointer: ValidationField[], referenceVariable?: string, outVariable?: string): void; /** * Compiles all nodes for the schema tree recursively. The compiled * output is written to the buffer. */ compileTree(tree: ParsedSchemaTree, buffer: CompilerBuffer, parentPointer: ValidationField[], referenceVariable?: string, outVariable?: string): void; /** * Compiles the tree and returns the compiled code as a string. */ compileAsString(): string; /** * Compiles the schema tree to an executable function */ compile(): CompilerOutput; }