/** * Schema Inheritance - Reduce repetition by defining schemas once * * Allows defining column schemas once and referencing them in subsequent blocks. * Particularly effective for datasets with consistent structure across multiple * sections or time periods. * * Features: * - Schema definition and reuse * - Automatic schema detection from data * - Schema versioning for evolution * - Partial schema inheritance * - Schema composition and extension * * Example: * ``` * @schema user_v1: id:number, name:string, email:string, active:boolean * @use user_v1 * * # Users Block 1 * id,name,email,active * 1,Alice,alice@example.com,true * * @use user_v1 * # Users Block 2 (inherits schema, no need to repeat column names) * 2,Bob,bob@example.com,false * ``` * * Token Savings: 20-40% for datasets with multiple similar blocks */ import type { SchemaInheritOptions } from './types.js'; /** * Column schema definition */ export interface ColumnSchema { name: string; type: 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'mixed'; nullable?: boolean; defaultValue?: any; format?: string; } /** * Complete schema definition */ export interface Schema { name: string; version: number; columns: ColumnSchema[]; description?: string; createdAt?: Date; inheritsFrom?: string; } /** * Schema analysis result */ export interface SchemaAnalysis { schemaName: string; similarity: number; commonColumns: string[]; uniqueColumns: string[]; recommended: boolean; estimatedSavings: number; } /** * Schema inheritance manager */ export declare class SchemaInheritance { private options; private schemas; private schemaUsageCount; constructor(options?: Partial); /** * Infer schema from data * * @param data - Array of row objects * @param schemaName - Name for the schema * @returns Inferred schema */ inferSchema(data: any[], schemaName: string): Schema; /** * Infer column type from values * * @param values - Sample values * @returns Inferred type */ private inferColumnType; /** * Register a schema * * @param schema - Schema to register */ registerSchema(schema: Schema): void; /** * Get schema by name * * @param schemaName - Schema name * @returns Schema or undefined */ getSchema(schemaName: string): Schema | undefined; /** * Analyze similarity between two datasets * * @param data1 - First dataset * @param data2 - Second dataset * @returns Analysis result */ analyzeSimilarity(data1: any[], data2: any[]): SchemaAnalysis; /** * Create schema from dataset and auto-name * * @param data - Dataset * @param baseName - Base name for schema * @returns Created schema */ createSchemaFromData(data: any[], baseName?: string): Schema; /** * Extend existing schema * * @param baseSchemaName - Base schema to extend * @param additionalColumns - Additional columns * @param newSchemaName - Name for new schema * @returns Extended schema */ extendSchema(baseSchemaName: string, additionalColumns: ColumnSchema[], newSchemaName: string): Schema; /** * Generate TONL schema directive * * Format: @schema schemaName: col1:type1, col2:type2, ... * * @param schema - Schema to encode * @returns TONL directive string */ generateSchemaDirective(schema: Schema): string; /** * Generate schema usage directive * * Format: @use schemaName * * @param schemaName - Schema to use * @returns TONL directive string */ generateUseDirective(schemaName: string): string; /** * Parse schema directive * * @param directive - Schema directive like "@schema user_v1: id:number, name:string" * @returns Parsed schema */ parseSchemaDirective(directive: string): Schema; /** * Parse use directive * * @param directive - Use directive like "@use user_v1" * @returns Schema name */ parseUseDirective(directive: string): string; /** * Apply schema to data (validate and fill defaults) * * @param data - Data rows * @param schemaName - Schema to apply * @returns Validated data */ applySchema(data: any[], schemaName: string): any[]; /** * Find best matching schema for data * * @param data - Dataset * @returns Best matching schema name or null */ findMatchingSchema(data: any[]): string | null; /** * Estimate savings from using schema inheritance * * @param blocks - Array of data blocks * @returns Estimated byte savings */ estimateSavings(blocks: any[][]): number; /** * Get all registered schemas * * @returns Array of schema names */ getSchemaNames(): string[]; /** * Get schema usage statistics * * @returns Map of schema name to usage count */ getUsageStats(): Map; /** * Clear all schemas */ clear(): void; /** * Check if schema inheritance would be beneficial * * @param blocks - Data blocks to analyze * @returns True if recommended */ shouldUseInheritance(blocks: any[][]): boolean; } //# sourceMappingURL=schema-inherit.d.ts.map