Skip to main content

bkb_core/
store.rs

1use anyhow::Result;
2use async_trait::async_trait;
3
4use chrono::{DateTime, Utc};
5
6use crate::model::{
7	CommitContext, DocumentContext, Reference, SearchParams, SearchResults, Timeline,
8};
9
10/// Trait for querying the Bitcoin Knowledge Base.
11///
12/// Implemented by `LocalSqliteStore` (direct DB queries) and
13/// `RemoteApiStore` (HTTP client to the BKB service).
14#[async_trait]
15pub trait KnowledgeStore: Send + Sync {
16	/// Full-text (and optionally semantic) search across all documents.
17	async fn search(&self, params: SearchParams) -> Result<SearchResults>;
18
19	/// Get a single document by ID with full content, references, and concepts.
20	async fn get_document(&self, id: &str) -> Result<Option<DocumentContext>>;
21
22	/// Find all documents referencing a given entity (BIP, BOLT, issue, commit, or concept).
23	async fn get_references(
24		&self, entity: &str, ref_type: Option<&str>, limit: u32,
25	) -> Result<Vec<Reference>>;
26
27	/// Get comprehensive context for a BIP: spec text, all referencing documents, and incoming
28	/// refs.
29	async fn lookup_bip(&self, number: u32) -> Result<Option<DocumentContext>>;
30
31	/// Get comprehensive context for a BOLT: spec text, all referencing documents, and incoming
32	/// refs.
33	async fn lookup_bolt(&self, number: u32) -> Result<Option<DocumentContext>>;
34
35	/// Get comprehensive context for a bLIP: spec text, all referencing documents, and incoming
36	/// refs.
37	async fn lookup_blip(&self, number: u32) -> Result<Option<DocumentContext>>;
38
39	/// Get comprehensive context for a LUD: spec text, all referencing documents, and incoming
40	/// refs.
41	async fn lookup_lud(&self, number: u32) -> Result<Option<DocumentContext>>;
42
43	/// Get comprehensive context for a NUT: spec text, all referencing documents, and incoming
44	/// refs.
45	async fn lookup_nut(&self, number: u32) -> Result<Option<DocumentContext>>;
46
47	/// Chronological timeline of a concept across all sources.
48	async fn timeline(
49		&self, concept: &str, after: Option<DateTime<Utc>>, before: Option<DateTime<Utc>>,
50	) -> Result<Timeline>;
51
52	/// Find commits matching a query, with associated PR and discussion context.
53	async fn find_commit(&self, query: &str, repo: Option<&str>) -> Result<Vec<CommitContext>>;
54}