Skip to main content

relay_knowledge/storage/
mod.rs

1//! Storage contracts and SQLite-backed graph state.
2//!
3//! Storage owns persisted graph facts, mutation log entries, derived index
4//! metadata, and health snapshots. Domain and interface modules must not depend
5//! on SQL or concrete database types.
6
7use std::{future::Future, pin::Pin, sync::Arc};
8
9mod contracts;
10mod partitioned;
11mod sqlite;
12
13pub use contracts::*;
14pub use partitioned::PartitionedSqliteKnowledgeStore;
15pub use sqlite::SqliteGraphStore;
16
17/// Async result returned by a configured storage factory.
18pub type KnowledgeStoreFactoryFuture<'a, T> =
19    Pin<Box<dyn Future<Output = Result<T, StorageError>> + Send + 'a>>;
20
21/// Configured outer-layer factory used for lazy storage initialization.
22///
23/// Application workflows depend on this contract and never construct a
24/// concrete database or probe a storage topology themselves.
25pub trait KnowledgeStoreFactory: Send + Sync {
26    fn open(&self) -> KnowledgeStoreFactoryFuture<'_, Arc<dyn KnowledgeStore>>;
27
28    fn topology_snapshot(&self) -> KnowledgeStoreFactoryFuture<'_, StorageTopologySnapshot>;
29}
30
31#[cfg(test)]
32pub(crate) async fn stage_empty_business_projection_with_fence_for_test<S>(
33    store: &S,
34    repository_id: impl Into<String>,
35    source_scope: impl Into<String>,
36    resolved_commit_sha: impl Into<String>,
37    fence: crate::domain::CodeIndexPublicationFence,
38) -> Result<crate::domain::BusinessKnowledgeStatus, StorageError>
39where
40    S: BusinessKnowledgeStore + CodeRepositoryStore + ?Sized,
41{
42    store
43        .replace_business_knowledge_projection_with_fence(
44            crate::domain::BusinessKnowledgeProjectionInput {
45                repository_id: repository_id.into(),
46                source_scope: source_scope.into(),
47                resolved_commit_sha: resolved_commit_sha.into(),
48                sources: Vec::new(),
49            },
50            fence,
51        )
52        .await
53}
54
55#[cfg(test)]
56pub(crate) async fn publish_empty_business_projection_for_test<S>(
57    store: &S,
58    repository_id: impl Into<String>,
59    source_scope: impl Into<String>,
60    resolved_commit_sha: impl Into<String>,
61) -> Result<crate::domain::BusinessKnowledgeStatus, StorageError>
62where
63    S: BusinessKnowledgeStore + CodeRepositoryStore + ?Sized,
64{
65    store
66        .replace_business_knowledge_projection(crate::domain::BusinessKnowledgeProjectionInput {
67            repository_id: repository_id.into(),
68            source_scope: source_scope.into(),
69            resolved_commit_sha: resolved_commit_sha.into(),
70            sources: Vec::new(),
71        })
72        .await
73}