/** * @module types/storage-schema * @description TypeScript type definitions for the StorageSchema API */ /** * Supported field types in storage schema */ export type SchemaFieldType = 'string' | 'number' | 'boolean' | 'date' | 'point' | 'string[]' | 'number[]' | 'text' | 'json' | 'binary'; /** * Field validation function type */ export type FieldValidator = (value: T) => boolean | string | Promise; /** * Field transformation function type */ export type FieldTransformer = (value: TIn) => TOut | Promise; /** * Enhanced field definition with all options */ export interface SchemaFieldDefinition { /** Data type of the field */ type: SchemaFieldType; /** Whether the field should be indexed for searching */ indexed?: boolean; /** Whether the field should be sortable (text fields only) */ sortable?: boolean; /** Whether the field should be normalized (text fields only) */ normalized?: boolean; /** Separator for array fields */ separator?: string; /** Default value for the field */ default?: any; /** Whether the field is required */ required?: boolean; /** Whether the field is unique */ unique?: boolean; /** Whether the field is immutable (can't be updated after creation) */ immutable?: boolean; /** Validation function for the field */ validate?: FieldValidator; /** Transformation to apply when storing */ transformIn?: FieldTransformer; /** Transformation to apply when retrieving */ transformOut?: FieldTransformer; /** Description of the field */ description?: string; /** Example value for documentation */ example?: any; /** Minimum value (for numbers) or length (for strings) */ min?: number; /** Maximum value (for numbers) or length (for strings) */ max?: number; /** Pattern for string validation (regex) */ pattern?: string | RegExp; /** Enumeration of allowed values */ enum?: any[]; /** Custom metadata */ metadata?: Record; } /** * Schema configuration type (can be simple or detailed) */ export type SchemaFieldConfig = SchemaFieldType | SchemaFieldDefinition; /** * Complete schema configuration */ export interface SchemaConfiguration { [fieldName: string]: SchemaFieldConfig; } /** * Schema validation error details */ export interface SchemaValidationError { /** Field that failed validation */ field: string; /** Error message */ message: string; /** The invalid value */ value?: any; /** Error code for programmatic handling */ code?: string; /** Nested path for complex objects */ path?: string[]; } /** * Schema validation warning details */ export interface SchemaValidationWarning { /** Field that triggered the warning */ field: string; /** Warning message */ message: string; /** Warning code for programmatic handling */ code?: string; } /** * Schema validation result */ export interface SchemaValidationResult { /** Whether the data is valid */ valid: boolean; /** List of validation errors */ errors: SchemaValidationError[]; /** List of validation warnings */ warnings: SchemaValidationWarning[]; /** Sanitized/transformed data (if valid) */ data?: any; } /** * Schema field difference */ export interface SchemaFieldDiff { /** Field name */ field: string; /** Old field configuration */ oldConfig?: SchemaFieldConfig; /** New field configuration */ newConfig?: SchemaFieldConfig; /** Type of change */ changeType: 'added' | 'removed' | 'modified'; /** Details of what changed */ changes?: string[]; } /** * Schema comparison result */ export interface SchemaComparisonResult { /** Whether schemas are identical */ identical: boolean; /** Fields added in the new schema */ added: string[]; /** Fields removed from the old schema */ removed: string[]; /** Fields with modified configurations */ modified: SchemaFieldDiff[]; /** Whether the changes are backward compatible */ backwardCompatible: boolean; /** Breaking changes that require migration */ breakingChanges: string[]; } /** * Schema migration step */ export interface SchemaMigrationStep { /** Type of action to perform */ action: 'add' | 'remove' | 'modify' | 'transform' | 'rename'; /** Field(s) affected */ field?: string | string[]; /** New field name (for rename action) */ newField?: string; /** Description of the step */ description: string; /** Transformation function (for transform action) */ transform?: FieldTransformer; /** Whether this step is safe (no data loss) */ safe: boolean; /** SQL-like migration command (for documentation) */ command?: string; } /** * Schema migration plan */ export interface SchemaMigrationPlan { /** Source schema version/name */ from: string; /** Target schema version/name */ to: string; /** Steps to migrate from old to new schema */ steps: SchemaMigrationStep[]; /** Whether migration is safe (no data loss) */ safe: boolean; /** Potential data loss warnings */ warnings: string[]; /** Estimated affected records */ affectedRecords?: number; /** Rollback plan */ rollback?: SchemaMigrationStep[]; } /** * Schema statistics */ export interface SchemaStatistics { /** Total number of fields */ fieldCount: number; /** Number of indexed fields */ indexedFieldCount: number; /** Number of required fields */ requiredFieldCount: number; /** Number of unique fields */ uniqueFieldCount: number; /** Field type distribution */ fieldTypes: Record; /** Estimated storage overhead */ estimatedOverhead: number; /** Complexity score (0-100) */ complexityScore: number; } /** * Schema export format */ export interface SchemaExport { /** Schema version */ version: string; /** Export timestamp */ timestamp: Date; /** Schema name */ name: string; /** Schema configuration */ schema: SchemaConfiguration; /** Data structure type */ dataStructure: 'JSON' | 'HASH'; /** Schema metadata */ metadata?: { description?: string; author?: string; tags?: string[]; [key: string]: any; }; } /** * Schema import options */ export interface SchemaImportOptions { /** Overwrite existing schema */ overwrite?: boolean; /** Validate imported schema */ validate?: boolean; /** Merge with existing schema */ merge?: boolean; /** Prefix for imported field names */ fieldPrefix?: string; /** Transform field names */ transformFieldNames?: (name: string) => string; } /** * Schema extension options */ export interface SchemaExtensionOptions { /** Overwrite existing fields */ overwrite?: boolean; /** Prefix for new field names */ prefix?: string; /** Validate extended schema */ validate?: boolean; } /** * Schema merge options */ export interface SchemaMergeOptions { /** Strategy for handling conflicts */ conflictStrategy?: 'error' | 'keepFirst' | 'keepSecond' | 'merge'; /** Custom conflict resolver */ conflictResolver?: (field: string, first: SchemaFieldConfig, second: SchemaFieldConfig) => SchemaFieldConfig; /** Validate merged schema */ validate?: boolean; } /** * Schema clone options */ export interface SchemaCloneOptions { /** New name for the cloned schema */ name?: string; /** Fields to include (whitelist) */ includeFields?: string[]; /** Fields to exclude (blacklist) */ excludeFields?: string[]; /** Transform field configurations */ transformFields?: (field: string, config: SchemaFieldConfig) => SchemaFieldConfig; } /** * Type guard to check if a value is a valid field type */ export declare function isValidFieldType(value: any): value is SchemaFieldType; /** * Type guard to check if a value is a field definition */ export declare function isFieldDefinition(value: any): value is SchemaFieldDefinition; /** * Type guard to check if a value is a schema configuration */ export declare function isSchemaConfiguration(value: any): value is SchemaConfiguration; /** * Utility type for extracting entity type from schema */ export type SchemaEntity = { [K in keyof S]: S[K] extends SchemaFieldDefinition ? S[K]['type'] extends 'string' ? string : S[K]['type'] extends 'number' ? number : S[K]['type'] extends 'boolean' ? boolean : S[K]['type'] extends 'date' ? Date : S[K]['type'] extends 'string[]' ? string[] : S[K]['type'] extends 'number[]' ? number[] : any : S[K] extends 'string' ? string : S[K] extends 'number' ? number : S[K] extends 'boolean' ? boolean : S[K] extends 'date' ? Date : S[K] extends 'string[]' ? string[] : S[K] extends 'number[]' ? number[] : any; }; //# sourceMappingURL=storage-schema.d.ts.map