cs-element
Version:
Advanced reactive data management library with state machines, blueprints, persistence, compression, networking, and multithreading support
263 lines • 8.19 kB
TypeScript
import { CSElementPlugin } from '../types/plugin-interfaces';
import { CSElement } from '../core/CSElement';
export interface PluginConfig {
enabled?: boolean;
[key: string]: any;
}
export interface PluginContext {
element?: CSElement;
operation?: string;
args?: any[];
metadata?: Record<string, any>;
timestamp?: Date;
userId?: string;
sessionId?: string;
}
export interface PluginResult {
success: boolean;
data?: any;
error?: string;
metadata?: Record<string, any>;
}
export declare enum BackupType {
FULL = "full",
INCREMENTAL = "incremental",
DIFFERENTIAL = "differential",
SNAPSHOT = "snapshot"
}
export declare enum BackupStatus {
PENDING = "pending",
IN_PROGRESS = "in_progress",
COMPLETED = "completed",
FAILED = "failed",
CANCELLED = "cancelled"
}
export declare enum CompressionType {
NONE = "none",
GZIP = "gzip",
BROTLI = "brotli",
LZ4 = "lz4"
}
export declare enum StorageLocation {
LOCAL = "local",
CLOUD = "cloud",
NETWORK = "network",
DATABASE = "database"
}
export declare enum RestoreMode {
FULL_RESTORE = "full_restore",
SELECTIVE_RESTORE = "selective_restore",
POINT_IN_TIME = "point_in_time",
MERGE = "merge"
}
export interface BackupMetadata {
id: string;
name: string;
description?: string;
type: BackupType;
status: BackupStatus;
createdAt: Date;
completedAt?: Date;
size: number;
compressedSize: number;
compressionType: CompressionType;
storageLocation: StorageLocation;
elementCount: number;
checksum: string;
version: string;
tags: string[];
dependencies: string[];
isEncrypted: boolean;
retentionPolicy?: RetentionPolicy;
}
export interface BackupData {
metadata: BackupMetadata;
elements: BackupSerializedElement[];
relationships: ElementRelationship[];
globalData: Record<string, any>;
plugins: PluginSnapshot[];
timestamp: Date;
schemaVersion: string;
}
export interface BackupSerializedElement {
id: string;
data: Record<string, any>;
metadata: Record<string, any>;
parentId?: string;
childrenIds: string[];
createdAt: Date;
updatedAt: Date;
}
export interface ElementRelationship {
parentId: string;
childId: string;
type: 'parent-child' | 'reference' | 'dependency';
metadata?: Record<string, any>;
}
export interface PluginSnapshot {
name: string;
version: string;
config: Record<string, any>;
data: Record<string, any>;
}
export interface RetentionPolicy {
maxAge: number;
maxCount: number;
keepDaily: number;
keepWeekly: number;
keepMonthly: number;
keepYearly: number;
}
export interface RestoreOptions {
mode: RestoreMode;
targetElements?: string[];
targetDate?: Date;
conflictResolution: 'overwrite' | 'skip' | 'merge' | 'rename';
validateIntegrity: boolean;
restorePlugins: boolean;
restoreRelationships: boolean;
dryRun: boolean;
}
export interface RestoreResult {
success: boolean;
restoredElements: string[];
skippedElements: string[];
conflicts: RestoreConflict[];
errors: string[];
duration: number;
timestamp: Date;
}
export interface RestoreConflict {
elementId: string;
type: 'data_conflict' | 'version_conflict' | 'relationship_conflict';
description: string;
resolution: string;
}
export interface BackupSchedule {
id: string;
name: string;
type: BackupType;
cron: string;
enabled: boolean;
retentionPolicy: RetentionPolicy;
includePlugins: boolean;
compression: CompressionType;
storageLocation: StorageLocation;
lastRun?: Date;
nextRun?: Date;
failureCount: number;
maxRetries: number;
}
export interface BackupJob {
id: string;
scheduleId?: string;
type: BackupType;
status: BackupStatus;
startTime: Date;
endTime?: Date;
progress: number;
currentOperation: string;
elementsProcessed: number;
totalElements: number;
errors: string[];
result?: BackupMetadata;
}
export interface BackupPluginConfig extends PluginConfig {
enableAutoBackup: boolean;
defaultBackupType: BackupType;
defaultCompression: CompressionType;
defaultStorageLocation: StorageLocation;
maxBackupSize: number;
maxConcurrentJobs: number;
retentionPolicy: RetentionPolicy;
encryptBackups: boolean;
verifyIntegrity: boolean;
includePluginData: boolean;
backupPath: string;
tempPath: string;
chunkSize: number;
}
export interface BackupStats {
totalBackups: number;
successfulBackups: number;
failedBackups: number;
totalSize: number;
compressedSize: number;
compressionRatio: number;
averageBackupTime: number;
lastBackupTime?: Date;
lastSuccessfulBackup?: Date;
lastFailedBackup?: Date;
activeJobs: number;
scheduledJobs: number;
oldestBackup?: Date;
newestBackup?: Date;
}
export declare class BackupPlugin implements CSElementPlugin {
readonly name = "BackupPlugin";
readonly version = "1.0.0";
readonly description = "\u041F\u043B\u0430\u0433\u0438\u043D \u0434\u043B\u044F \u0440\u0435\u0437\u0435\u0440\u0432\u043D\u043E\u0433\u043E \u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F \u0438 \u0432\u043E\u0441\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445";
private config;
private backups;
private schedules;
private activeJobs;
private stats;
private schedulerTimer?;
private lastFullBackup?;
install(CSElementClass: typeof CSElement): void;
constructor(config?: Partial<BackupPluginConfig>);
initialize(): Promise<void>;
destroy(): Promise<void>;
getConfig(): BackupPluginConfig;
updateConfig(newConfig: Partial<BackupPluginConfig>): void;
afterCreate(element: CSElement, _context: PluginContext): Promise<PluginResult>;
afterUpdate(element: CSElement, _context: PluginContext): Promise<PluginResult>;
afterDelete(element: CSElement, _context: PluginContext): Promise<PluginResult>;
createBackup(name: string, type?: BackupType, options?: Partial<BackupMetadata>): Promise<string>;
createFullBackup(name: string): Promise<string>;
createIncrementalBackup(name: string): Promise<string>;
createSnapshot(name: string): Promise<string>;
restoreBackup(backupId: string, options: RestoreOptions): Promise<RestoreResult>;
createSchedule(scheduleData: Omit<BackupSchedule, 'id' | 'lastRun' | 'nextRun' | 'failureCount'>): string;
getSchedule(id: string): BackupSchedule | undefined;
updateSchedule(id: string, updates: Partial<BackupSchedule>): boolean;
deleteSchedule(id: string): boolean;
getBackup(id: string): BackupMetadata | undefined;
getAllBackups(): BackupMetadata[];
deleteBackup(id: string): Promise<boolean>;
verifyBackup(id: string): Promise<boolean>;
getBackupInfo(id: string): Promise<Record<string, any> | null>;
private collectBackupData;
/**
* Сериализация элемента для бэкапа с использованием встроенной сериализации
*/
private serializeElementForBackup;
private saveBackup;
private loadBackup;
private createMockBackupData;
private restoreElements;
private restoreRelationships;
private restorePlugins;
private simulateRestore;
private validateBackupIntegrity;
private startScheduler;
private runScheduledBackups;
private calculateNextRun;
private shouldTriggerIncrementalBackup;
private getIncrementalDependencies;
private cleanupOldBackups;
private ensureDirectories;
private loadExistingBackups;
private deleteBackupFile;
private compress;
private decompress;
private calculateChecksum;
private calculateDataSize;
private updateStats;
private generateId;
getStats(): BackupStats;
getAllSchedules(): BackupSchedule[];
getActiveJobs(): BackupJob[];
getJob(id: string): BackupJob | undefined;
}
//# sourceMappingURL=BackupPlugin.d.ts.map