rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
82 lines (81 loc) • 3.7 kB
TypeScript
import { JsonMapping } from '../transformers/PostgresJsonQueryBuilder';
/**
* Represents the structure extracted from JsonMapping analysis
*/
export type ExtractedStructure = 'primitive' | {
[key: string]: ExtractedStructure;
} | ExtractedStructure[];
/**
* Represents the expected type structure for validation
*/
export type ExpectedTypeStructure = 'primitive' | {
[key: string]: ExpectedTypeStructure;
} | ExpectedTypeStructure[];
/**
* Result of JsonMapping validation
*/
export interface ValidationResult {
isValid: boolean;
errors: string[];
missingProperties: string[];
extraProperties: string[];
}
export declare class JsonSchemaValidator {
/**
* Validates JsonMapping structure against an expected type structure.
* Checks if the JsonMapping covers all required properties and relationships.
*
* @param jsonMapping The JsonMapping configuration to validate
* @param expectedStructure The expected type structure to validate against
* @returns ValidationResult containing validation status and detailed errors
*/
static validate(jsonMapping: JsonMapping, expectedStructure: ExpectedTypeStructure): ValidationResult;
/**
* Validates JsonMapping structure and throws an error if validation fails.
* Convenience method for strict validation scenarios.
*
* @param jsonMapping The JsonMapping configuration to validate
* @param expectedStructure The expected type structure to validate against
* @throws Error if validation fails with detailed error messages
*/
static validateStrict(jsonMapping: JsonMapping, expectedStructure: ExpectedTypeStructure): void;
/**
* Extracts structure information from JsonMapping configuration.
* Analyzes rootEntity and nestedEntities to build complete structure map.
*
* @param jsonMapping The JsonMapping to analyze
* @returns ExtractedStructure representing the mapping structure
*/
private static extractStructureFromJsonMapping; /**
* Extracts structure from a nested entity, including its children.
*/
private static extractNestedEntityStructure; /**
* Compares extracted structure with expected structure with proper type guards.
*/
private static compareStructures;
/**
* Validates JsonMapping structure against a sample object that implements the expected type.
* This method extracts structure from the sample object and compares it with JsonMapping.
*
* @param jsonMapping The JsonMapping configuration to validate
* @param sampleObject A sample object that implements the expected interface/type
* @returns ValidationResult containing validation status and detailed errors
*/
static validateAgainstSample<T>(jsonMapping: JsonMapping, sampleObject: T): ValidationResult;
/**
* Validates JsonMapping structure against a sample object and throws an error if validation fails.
* Convenience method for strict validation scenarios with sample objects.
*
* @param jsonMapping The JsonMapping configuration to validate
* @param sampleObject A sample object that implements the expected interface/type
* @throws Error if validation fails with detailed error messages
*/
static validateAgainstSampleStrict<T>(jsonMapping: JsonMapping, sampleObject: T): void; /**
* Extracts structure information from a sample object.
* Recursively analyzes the object properties to build a structure map.
*
* @param sampleObject The sample object to analyze
* @returns ExpectedTypeStructure representing the object structure
*/
private static extractStructureFromSample;
}