samod_core/io/storage_task.rs
1use crate::storage_key::StorageKey;
2
3/// Represents storage operations that can be performed by both the main Samod instance
4/// and document actors.
5///
6/// `StorageTask` defines the common interface for all storage operations:
7/// - Single value operations (Load, Put, Delete)
8/// - Bulk operations (LoadRange)
9///
10/// This enum is used in two contexts:
11/// 1. As part of `IoAction::Storage(StorageTask)` for the main Samod instance
12/// 2. As part of `DocumentIoTask` for document actors
13///
14/// ## Storage Model
15///
16/// Storage operations work with a simple key-value model:
17/// - Keys are represented by `StorageKey`
18/// - Values are arbitrary byte arrays
19/// - Range queries are supported via prefix matching
20#[derive(Debug, Clone)]
21pub enum StorageTask {
22    /// Load a single value from storage by its key.
23    ///
24    /// This operation should retrieve the value associated with the given key
25    /// from persistent storage. If the key doesn't exist, the operation should
26    /// complete successfully with a `None` result.
27    ///
28    /// # Fields
29    ///
30    /// * `key` - The storage key to look up
31    Load { key: StorageKey },
32
33    /// Load all key-value pairs that have keys starting with the given prefix.
34    ///
35    /// This operation performs a range query over the storage, returning all
36    /// entries whose keys begin with the specified prefix. This is used for
37    /// efficient bulk operations and queries over related data.
38    ///
39    /// # Fields
40    ///
41    /// * `prefix` - The key prefix to match against
42    LoadRange { prefix: StorageKey },
43
44    /// Store a key-value pair in persistent storage.
45    ///
46    /// This operation should persist the given key-value pair to storage,
47    /// replacing any existing value for the same key.
48    ///
49    /// # Fields
50    ///
51    /// * `key` - The storage key
52    /// * `value` - The data to store
53    Put { key: StorageKey, value: Vec<u8> },
54
55    /// Remove a key-value pair from persistent storage.
56    ///
57    /// This operation should remove the entry for the given key from storage.
58    /// If the key doesn't exist, the operation should complete successfully
59    /// as a no-op.
60    ///
61    /// # Fields
62    ///
63    /// * `key` - The storage key to remove
64    Delete { key: StorageKey },
65}