UNPKG

@iyulab/oops

Version:

Core SDK for Oops - Safe text file editing with automatic backup

102 lines 3.88 kB
"use strict"; /** * Backup management for Oops */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BackupManager = void 0; const path = __importStar(require("path")); const file_system_1 = require("./file-system"); const git_1 = require("./git"); const errors_1 = require("./errors"); class BackupManager { workspacePath; gitWrapper; constructor(workspacePath) { this.workspacePath = workspacePath; this.gitWrapper = new git_1.GitWrapper(workspacePath); } async createBackup(filePath, message) { if (!(await file_system_1.FileSystem.exists(filePath))) { throw new errors_1.FileNotFoundError(filePath); } const backupPath = path.join(this.workspacePath, 'backup'); // Copy file to backup location await file_system_1.FileSystem.copyFile(filePath, backupPath); // Initialize git if needed if (!(await file_system_1.FileSystem.exists(path.join(this.workspacePath, '.git')))) { await this.gitWrapper.init(); } // Add and commit backup await this.gitWrapper.add('backup'); await this.gitWrapper.commit(message || 'Initial backup'); return { originalPath: filePath, backupPath, timestamp: new Date(), checksum: 'TODO', // TODO: Implement checksum metadata: { message: message || 'Initial backup', }, }; } async restoreBackup(backupInfo) { if (!(await file_system_1.FileSystem.exists(backupInfo.backupPath))) { throw new errors_1.FileNotFoundError(backupInfo.backupPath); } // Restore file from backup await file_system_1.FileSystem.copyFile(backupInfo.backupPath, backupInfo.originalPath); } async hasBackup(_filePath) { const backupPath = path.join(this.workspacePath, 'backup'); return await file_system_1.FileSystem.exists(backupPath); } async getBackupInfo(_filePath) { const backupPath = path.join(this.workspacePath, 'backup'); if (!(await file_system_1.FileSystem.exists(backupPath))) { return null; } // TODO: Implement proper backup info retrieval return { originalPath: _filePath, backupPath, timestamp: new Date(), checksum: 'TODO', metadata: {}, }; } } exports.BackupManager = BackupManager; //# sourceMappingURL=backup.js.map