@yihuangdb/storage-object
Version:
A Node.js storage object layer library using Redis OM
247 lines • 7.32 kB
TypeScript
/**
* @module types/storage-system
* @description TypeScript type definitions for the StorageSystem API
*/
import { StorageObject, StorageOptions } from '../storage';
import { StorageSchema } from '../storage-schema';
import { SchemaConfig } from '../schema';
/**
* Global configuration options for StorageSystem
*/
export interface StorageSystemConfig {
/** Default Redis connection options */
defaultConnection?: {
host?: string;
port?: number;
password?: string;
database?: number;
};
/** Default storage options for all new storages */
defaultStorageOptions?: Partial<StorageOptions>;
/** Enable automatic schema validation */
autoValidation?: boolean;
/** Enable performance monitoring */
enableMonitoring?: boolean;
/** Maximum number of storage instances to cache */
maxCacheSize?: number;
/** Enable debug logging */
debug?: boolean;
}
/**
* Storage metadata returned by StorageSystem
*/
export interface StorageSystemMetadata {
/** Name of the storage */
name: string;
/** Creation timestamp */
createdAt: Date;
/** Last modified timestamp */
updatedAt: Date;
/** Schema configuration */
schema: SchemaConfig;
/** Storage options */
options: StorageOptions;
/** Number of entities in the storage */
entityCount?: number;
/** Storage status */
status: 'active' | 'inactive' | 'error';
/** Error message if status is 'error' */
error?: string;
}
/**
* Bulk operation result from StorageSystem
*/
export interface BulkOperationResult {
/** Whether the operation was successful */
success: boolean;
/** Number of items processed */
processed: number;
/** Number of successful operations */
succeeded: number;
/** Number of failed operations */
failed: number;
/** Error details for failed operations */
errors?: Array<{
index: number;
error: string;
}>;
}
/**
* Storage statistics from StorageSystem
*/
export interface StorageSystemStats {
/** Total number of storage instances */
totalStorages: number;
/** Number of active storage instances */
activeStorages: number;
/** Total number of entities across all storages */
totalEntities: number;
/** Memory usage statistics */
memoryUsage?: {
used: number;
available: number;
percentage: number;
};
/** Connection pool statistics */
connectionPool?: {
totalConnections: number;
activeConnections: number;
idleConnections: number;
waitingRequests: number;
};
/** Schema registry statistics */
schemaRegistry?: {
schemaCount: number;
totalOperations: number;
activeSchemas: number;
deprecatedSchemas: number;
};
}
/**
* Storage health check result
*/
export interface StorageHealthCheck {
/** Overall health status */
healthy: boolean;
/** Individual component health */
components: {
redis: boolean;
connectionPool: boolean;
schemaRegistry: boolean;
};
/** Health check timestamp */
timestamp: Date;
/** Response time in milliseconds */
responseTime: number;
/** Any warning messages */
warnings?: string[];
/** Any error messages */
errors?: string[];
}
/**
* Storage backup options
*/
export interface StorageBackupOptions {
/** Path to save the backup */
path: string;
/** Include data in backup */
includeData?: boolean;
/** Include schemas in backup */
includeSchemas?: boolean;
/** Include metadata in backup */
includeMetadata?: boolean;
/** Compression format */
compression?: 'gzip' | 'none';
/** Encrypt the backup */
encrypt?: boolean;
/** Encryption key (if encrypt is true) */
encryptionKey?: string;
}
/**
* Storage restore options
*/
export interface StorageRestoreOptions {
/** Path to restore from */
path: string;
/** Overwrite existing data */
overwrite?: boolean;
/** Restore data */
restoreData?: boolean;
/** Restore schemas */
restoreSchemas?: boolean;
/** Restore metadata */
restoreMetadata?: boolean;
/** Decryption key (if backup is encrypted) */
decryptionKey?: string;
/** Skip validation during restore */
skipValidation?: boolean;
}
/**
* Storage migration options
*/
export interface StorageMigrationOptions {
/** Backup before migration */
backup?: boolean;
/** Validate data after migration */
validate?: boolean;
/** Batch size for migration */
batchSize?: number;
/** Continue on error */
continueOnError?: boolean;
/** Progress callback */
onProgress?: (progress: {
current: number;
total: number;
percentage: number;
}) => void;
}
/**
* Storage monitor event
*/
export interface StorageMonitorEvent {
/** Event type */
type: 'create' | 'update' | 'delete' | 'query' | 'error';
/** Storage name */
storage: string;
/** Entity ID (if applicable) */
entityId?: string;
/** Event timestamp */
timestamp: Date;
/** Event data */
data?: any;
/** Error details (if type is 'error') */
error?: {
message: string;
stack?: string;
};
/** Performance metrics */
metrics?: {
duration: number;
memoryUsed?: number;
};
}
/**
* Storage monitor options
*/
export interface StorageMonitorOptions {
/** Events to monitor */
events?: Array<'create' | 'update' | 'delete' | 'query' | 'error' | 'all'>;
/** Include performance metrics */
includeMetrics?: boolean;
/** Include full entity data in events */
includeData?: boolean;
/** Buffer size for event queue */
bufferSize?: number;
/** Flush interval in milliseconds */
flushInterval?: number;
}
/**
* Type guard to check if a value is a StorageSchema
*/
export declare function isStorageSchema(value: any): value is StorageSchema;
/**
* Type guard to check if a value is a SchemaConfig
*/
export declare function isSchemaConfig(value: any): value is SchemaConfig;
/**
* Storage System API interface
*/
export interface IStorageSystem {
create<T extends Record<string, any>>(name: string, schema: SchemaConfig | StorageSchema<T>, options?: StorageOptions): Promise<StorageObject<T>>;
get<T extends Record<string, any>>(name: string): Promise<StorageObject<T> | null>;
delete(name: string): Promise<boolean>;
exists(name: string): Promise<boolean>;
list(): Promise<string[]>;
getMetadata(name: string): Promise<StorageSystemMetadata | null>;
validate(name: string): Promise<boolean>;
initialize(config?: StorageSystemConfig): Promise<void>;
shutdown(): Promise<void>;
flushAll(): Promise<void>;
getStats(): Promise<StorageSystemStats>;
healthCheck(): Promise<StorageHealthCheck>;
monitor(options?: StorageMonitorOptions): (callback: (event: StorageMonitorEvent) => void) => () => void;
backup(options: StorageBackupOptions): Promise<void>;
restore(options: StorageRestoreOptions): Promise<void>;
migrate(name: string, newSchema: SchemaConfig | StorageSchema, options?: StorageMigrationOptions): Promise<void>;
}
//# sourceMappingURL=storage-system.d.ts.map