diff options
Diffstat (limited to 'frontend/lib/drive_types.ts')
| -rw-r--r-- | frontend/lib/drive_types.ts | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/frontend/lib/drive_types.ts b/frontend/lib/drive_types.ts index 9220d82..a168a72 100644 --- a/frontend/lib/drive_types.ts +++ b/frontend/lib/drive_types.ts | |||
| @@ -22,12 +22,57 @@ export interface DriveTreeResponse { | |||
| 22 | root: DriveTreeNode[] | 22 | root: DriveTreeNode[] |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | export interface DriveLogEntry { | 25 | // Base interface for all log entries with common fields |
| 26 | export interface DriveLogEntryBase { | ||
| 26 | timestamp: number | 27 | timestamp: number |
| 27 | log_id: number | 28 | revision: number // Changed from log_id to match Rust OperationHeader |
| 28 | email: string | 29 | email: string |
| 29 | action: string | 30 | } |
| 31 | |||
| 32 | // Specific log entry types based on Rust OperationData variants | ||
| 33 | export interface DriveLogEntryCreateFile extends DriveLogEntryBase { | ||
| 34 | action: "create_file" | ||
| 30 | path: string | 35 | path: string |
| 31 | blob_id: string | 36 | blob_id: string |
| 32 | size: number | 37 | size: number |
| 33 | } | 38 | } |
| 39 | |||
| 40 | export interface DriveLogEntryCreateDir extends DriveLogEntryBase { | ||
| 41 | action: "create_dir" | ||
| 42 | path: string | ||
| 43 | } | ||
| 44 | |||
| 45 | export interface DriveLogEntryRemove extends DriveLogEntryBase { | ||
| 46 | action: "remove" | ||
| 47 | path: string | ||
| 48 | } | ||
| 49 | |||
| 50 | export interface DriveLogEntryRename extends DriveLogEntryBase { | ||
| 51 | action: "rename" | ||
| 52 | old_path: string | ||
| 53 | new_path: string | ||
| 54 | } | ||
| 55 | |||
| 56 | // Discriminated union of all possible log entry types | ||
| 57 | export type DriveLogEntry = | ||
| 58 | | DriveLogEntryCreateFile | ||
| 59 | | DriveLogEntryCreateDir | ||
| 60 | | DriveLogEntryRemove | ||
| 61 | | DriveLogEntryRename | ||
| 62 | |||
| 63 | // Type guards for working with discriminated unions | ||
| 64 | export function isCreateFileEntry(entry: DriveLogEntry): entry is DriveLogEntryCreateFile { | ||
| 65 | return entry.action === "create_file" | ||
| 66 | } | ||
| 67 | |||
| 68 | export function isCreateDirEntry(entry: DriveLogEntry): entry is DriveLogEntryCreateDir { | ||
| 69 | return entry.action === "create_dir" | ||
| 70 | } | ||
| 71 | |||
| 72 | export function isRemoveEntry(entry: DriveLogEntry): entry is DriveLogEntryRemove { | ||
| 73 | return entry.action === "remove" | ||
| 74 | } | ||
| 75 | |||
| 76 | export function isRenameEntry(entry: DriveLogEntry): entry is DriveLogEntryRename { | ||
| 77 | return entry.action === "rename" | ||
| 78 | } | ||
