rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
63 lines (62 loc) • 1.99 kB
TypeScript
/**
* Model-driven JSON mapping structure that mirrors TypeScript model definitions.
* This approach provides intuitive, hierarchical mapping that closely resembles the target data structure.
*/
import { JsonMapping } from './PostgresJsonQueryBuilder';
/**
* Supported field types for database column mapping.
*/
export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'auto';
/**
* Field mapping configuration that can be either a simple column name or enhanced mapping with type control.
*/
export type FieldMapping = string | {
column: string;
type?: FieldType;
} | {
from: string;
type?: FieldType;
};
/**
* Nested object or array structure definition.
*/
export interface NestedStructure {
type: 'object' | 'array';
from: string;
structure: StructureFields;
}
/**
* Structure fields can contain either field mappings or nested structures.
*/
export type StructureFields = {
[key: string]: FieldMapping | NestedStructure;
};
/**
* Model-driven JSON mapping that mirrors TypeScript interface structure.
* This design makes it easy to understand the relationship between models and database columns.
*/
export interface ModelDrivenJsonMapping {
typeInfo: {
interface: string;
importPath: string;
};
structure: StructureFields;
}
/**
* Type protection configuration extracted from the model-driven mapping.
*/
export interface TypeProtectionConfig {
protectedStringFields: string[];
}
/**
* Convert a model-driven JSON mapping to the traditional JsonMapping format.
* This enables backward compatibility with existing PostgresJsonQueryBuilder.
*/
export declare function convertModelDrivenMapping(modelMapping: ModelDrivenJsonMapping): {
jsonMapping: JsonMapping;
typeProtection: TypeProtectionConfig;
};
/**
* Validate that a model-driven mapping structure is well-formed.
*/
export declare function validateModelDrivenMapping(mapping: ModelDrivenJsonMapping): string[];