Skip to main content

state_engine/ports/
required.rs

1use serde_json::Value;
2use std::collections::HashMap;
3
4/// In-process memory store. Internal mutability is the implementor's responsibility.
5pub trait InMemoryClient: Send + Sync {
6    fn get(&self, key: &str) -> Option<Value>;
7    fn set(&self, key: &str, value: Value) -> bool;
8    fn delete(&self, key: &str) -> bool;
9}
10
11/// KVS store. Serialization/deserialization is handled by the State layer.
12/// Internal mutability is the implementor's responsibility.
13pub trait KVSClient: Send + Sync {
14    fn get(&self, key: &str) -> Option<String>;
15    /// `ttl` in seconds.
16    fn set(&self, key: &str, value: String, ttl: Option<u64>) -> bool;
17    fn delete(&self, key: &str) -> bool;
18}
19
20/// Environment / config store.
21/// Internal mutability is the implementor's responsibility.
22pub trait EnvClient: Send + Sync {
23    fn get(&self, key: &str) -> Option<String>;
24    fn set(&self, key: &str, value: String) -> bool;
25    fn delete(&self, key: &str) -> bool;
26}
27
28/// Relational DB client.
29/// Do NOT call State inside DbClient — it would cause recursion.
30/// `connection` is a Value::Object resolved from the manifest.
31/// `columns` are extracted from the manifest `map` definition.
32pub trait DbClient: Send + Sync {
33    fn get(
34        &self,
35        connection: &Value,
36        table: &str,
37        columns: &[&str],
38        where_clause: Option<&str>,
39    ) -> Option<Vec<HashMap<String, Value>>>;
40    fn set(
41        &self,
42        connection: &Value,
43        table: &str,
44        values: &HashMap<String, Value>,
45        where_clause: Option<&str>,
46    ) -> bool;
47    fn delete(
48        &self,
49        connection: &Value,
50        table: &str,
51        where_clause: Option<&str>,
52    ) -> bool;
53}
54
55/// HTTP client.
56/// `headers` is an optional map of header name → value.
57pub trait HttpClient: Send + Sync {
58    fn get(
59        &self,
60        url: &str,
61        headers: Option<&HashMap<String, String>>,
62    ) -> Option<Value>;
63    fn set(
64        &self,
65        url: &str,
66        body: Value,
67        headers: Option<&HashMap<String, String>>,
68    ) -> bool;
69    fn delete(
70        &self,
71        url: &str,
72        headers: Option<&HashMap<String, String>>,
73    ) -> bool;
74}
75
76/// File client. `map` drives field extraction from file contents.
77pub trait FileClient: Send + Sync {
78    fn get(&self, key: &str) -> Option<String>;
79    fn set(&self, key: &str, value: String) -> bool;
80    fn delete(&self, key: &str) -> bool;
81}