diff options
| author | diogo464 <[email protected]> | 2025-08-14 15:34:42 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-14 15:34:42 +0100 |
| commit | 6c70d6a60b286f7cfbbde4e428d41c8de2c7e77a (patch) | |
| tree | c5047911c102f885af3671418477231a4a2351f4 /frontend/lib/drive_types.ts | |
| parent | a9f1dbeed109b175fbf78e18a1ede3eba44924f8 (diff) | |
feat: improve DriveLogEntry types with discriminated unions
- Replace generic DriveLogEntry with action-specific discriminated unions
- Add DriveLogEntryCreateFile, CreateDir, Remove, Rename types
- Update Drive_log parsing to create correct union types based on action
- Add type guards (isCreateFileEntry, isRenameEntry, etc.) for safe access
- Enhance History UI to properly display rename operations (old → new)
- Change log_id to revision to match Rust OperationHeader structure
- Improve type safety and maintainability
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
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 | } | ||
