1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/// Persistence backends exposed by the polyglot boundary.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Backend {
/// Deterministic, in-process document backend for tests and local work.
Mock,
/// MongoDB document database.
MongoDb,
/// DuckDB in-process analytics database.
DuckDb,
/// Turso/libSQL edge database through its remote protocol.
Turso,
/// SurrealDB multi-model database through its HTTP protocol.
SurrealDb,
/// Qdrant dense-vector database through its HTTP protocol.
Qdrant,
/// Redis native data structures through its RESP protocol.
Redis,
}
/// Portable capabilities intentionally supported by an adapter.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Capability {
/// Typed document CRUD and bounded listing.
Documents,
/// Parameterized analytical statements and bounded result sets.
Analytics,
/// Explicit, bounded graph queries.
Graph,
/// Parameterized SQL over an edge-native remote protocol.
EdgeSql,
/// Typed relational model CRUD and bounded queries.
RelationalModels,
/// Dense-vector collection lifecycle and bounded nearest-neighbor queries.
Vectors,
/// Explicit hash, set, and sorted-set operations.
KeyValueStructures,
}
/// A backend's honest capability declaration.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BackendCapabilities {
backend: Backend,
capabilities: &'static [Capability],
}
impl BackendCapabilities {
/// Creates an immutable capability declaration.
pub const fn new(backend: Backend, capabilities: &'static [Capability]) -> Self {
Self {
backend,
capabilities,
}
}
/// Returns the backend described by this declaration.
pub const fn backend(self) -> Backend {
self.backend
}
/// Returns the explicitly supported capabilities.
pub const fn capabilities(self) -> &'static [Capability] {
self.capabilities
}
/// Tests whether a capability is declared.
pub fn supports(self, expected: Capability) -> bool {
self.capabilities.contains(&expected)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn capability_declarations_are_explicit() {
let declared = BackendCapabilities::new(Backend::Mock, &[Capability::Documents]);
assert_eq!(declared.backend(), Backend::Mock);
assert!(declared.supports(Capability::Documents));
assert!(!declared.supports(Capability::Graph));
}
}