// Core CND Types and Interfaces import { Observable } from 'rxjs'; // Main CND Configuration with Enterprise Features export interface CNDConfig { cbd: { host: string; port: number; database: string; auth?: { username?: string; password?: string; token?: string; }; }; // Enterprise Features enterprise?: { enabled: boolean; features: { serviceDiscovery?: boolean; authentication?: boolean; authorization?: boolean; encryption?: boolean; audit?: boolean; monitoring?: boolean; backup?: boolean; clustering?: boolean; }; }; // Service Discovery Integration serviceDiscovery?: { enabled: boolean; registryUrl?: string; serviceName?: string; healthCheckInterval?: number; tags?: string[]; }; // Authentication & Authorization auth?: { enabled: boolean; provider: 'internal' | 'oauth2' | 'jwt' | 'saml' | 'ldap'; config: { secret?: string; issuer?: string; audience?: string; algorithms?: string[]; publicKey?: string; privateKey?: string; }; rbac?: { enabled: boolean; roles: Record; permissions: Record; }; }; // Security & Encryption security?: { encryption?: { enabled: boolean; algorithm: 'aes-256-gcm' | 'aes-192-gcm' | 'aes-128-gcm'; keyRotation?: { enabled: boolean; interval: number; // days }; }; audit?: { enabled: boolean; storage: 'database' | 'file' | 'external'; retention: number; // days }; rateLimit?: { enabled: boolean; windowMs: number; maxRequests: number; }; }; realtime?: { enabled: boolean; websocketPort?: number; }; cache?: { enabled: boolean; ttl?: number; distributed?: boolean; redis?: { host: string; port: number; password?: string; }; }; // Performance & Monitoring performance?: { monitoring?: { enabled: boolean; metricsPort?: number; healthCheckPath?: string; }; clustering?: { enabled: boolean; nodes: string[]; replicationFactor: number; }; backup?: { enabled: boolean; schedule: string; // cron expression storage: 's3' | 'gcs' | 'azure' | 'local'; retention: number; // days }; }; logging?: { enabled: boolean; level: 'debug' | 'info' | 'warn' | 'error'; structured?: boolean; destination?: 'console' | 'file' | 'elasticsearch' | 'splunk'; }; } // Enterprise Service Types export interface ServiceDiscoveryConfig { enabled: boolean; registryUrl: string; serviceName: string; serviceId: string; version: string; tags: string[]; healthCheck: { path: string; interval: number; timeout: number; }; metadata: Record; } export interface AuthenticationContext { userId: string; sessionId: string; permissions: string[]; roles: string[]; tenant?: string; expiresAt: Date; metadata: Record; } export interface AuditLog { id: string; timestamp: Date; userId: string; sessionId: string; operation: string; resource: string; details: Record; result: 'success' | 'failure' | 'partial'; duration: number; metadata: Record; } export interface MetricsData { timestamp: Date; service: string; operation: string; duration: number; status: 'success' | 'error'; metadata: Record; } // Schema Definition Types export interface SchemaDefinition { [tableName: string]: TableSchema; } export interface TableSchema { [fieldName: string]: FieldDefinition | RelationDefinition; } export interface FieldDefinition { type: 'string' | 'number' | 'boolean' | 'date' | 'json' | 'text' | 'uuid'; primary?: boolean; unique?: boolean; required?: boolean; default?: any; references?: string; // "table.field" } export interface RelationDefinition { name: string; type: 'hasOne' | 'hasMany' | 'belongsTo' | 'manyToMany'; table: string; foreignKey?: string; pivotTable?: string; fieldName?: string; } // Query Types export interface QueryResult { data: T[]; count: number; executionTime: number; query: string; } export interface QueryBuilder { select(fields?: string[]): QueryBuilder; where(conditions: Record): QueryBuilder; orderBy(field: string, direction?: 'asc' | 'desc'): QueryBuilder; limit(count: number): QueryBuilder; offset(count: number): QueryBuilder; include(relations: string[]): QueryBuilder; execute(): Promise>; first(): Promise; live(): Observable; } // Document API Types export interface DocumentQuery { find(query?: Record): Promise; findOne(query?: Record): Promise; findById(id: string): Promise; create(document: Partial): Promise; update(id: string, updates: Partial): Promise; delete(id: string): Promise; count(query?: Record): Promise; search(text: string, fields?: string[]): Promise; } // Graph API Types export interface GraphNode { id: string; labels: string[]; properties: Record; } export interface GraphRelationship { id: string; type: string; startNode: string; endNode: string; properties: Record; } export interface GraphQuery { match(pattern: string): GraphQuery; where(conditions: Record): GraphQuery; return(fields: string[]): Promise; create(node: Partial): Promise; relate(from: string, to: string, type: string, properties?: Record): Promise; } // Vector API Types export interface VectorQuery { insert(id: string, vector: number[], metadata?: Record): Promise; similarity(vector: number[], options?: { threshold?: number; limit?: number }): Promise; delete(id: string): Promise; update(id: string, vector: number[], metadata?: Record): Promise; } export interface VectorResult { id: string; score: number; metadata: Record; } // Time Series API Types export interface TimeSeriesQuery { insert(timestamp: Date, value: number, tags?: Record): Promise; range(start: Date, end: Date): TimeSeriesQuery; where(tags: Record): TimeSeriesQuery; aggregate(func: 'avg' | 'sum' | 'min' | 'max' | 'count', interval?: string): Promise; latest(): Promise; } export interface TimeSeriesPoint { timestamp: Date; value: number; tags: Record; } // Cache API Types export interface CacheAPI { get(key: string): Promise; set(key: string, value: T, options?: { ttl?: number }): Promise; delete(key: string): Promise; exists(key: string): Promise; expire(key: string, ttl: number): Promise; keys(pattern?: string): Promise; flush(): Promise; } // Migration Types export interface MigrationOptions { tables?: string[]; collections?: string[]; transform?: Record any>; batchSize?: number; dryRun?: boolean; } export interface MigrationResult { source: string; tablesProcessed: string[]; recordsProcessed: number; errors: string[]; duration: number; } // Real-time Types export interface RealtimeSubscription { id: string; query: string; callback: (data: any) => void; unsubscribe: () => void; } // Transaction Types export interface Transaction { sql(query: TemplateStringsArray, ...values: any[]): Promise; collection(name: string): DocumentQuery; commit(): Promise; rollback(): Promise; } // Admin Types export interface AdminConfig { auth?: { provider: 'keycloak' | 'auth0' | 'custom'; config: Record; }; tables?: Record; }>; customPages?: Record; } // Error Types export class CNDError extends Error { constructor( message: string, public code: string, public details?: Record ) { super(message); this.name = 'CNDError'; } } export class CNDValidationError extends CNDError { constructor(message: string, public field: string, public value: any) { super(message, 'VALIDATION_ERROR', { field, value }); this.name = 'CNDValidationError'; } } export class CNDConnectionError extends CNDError { constructor(message: string, public host: string, public port: number) { super(message, 'CONNECTION_ERROR', { host, port }); this.name = 'CNDConnectionError'; } }