Skip to main content

scc_engine/
graph.rs

1//! Engine graph operations: search, listings, recompile.
2//!
3//! Returns VALUES (entities, pairs, packs); transports render them.
4//! The FTS+LIKE fallback contract moves with the code.
5
6use scc_api::QueryRequest;
7
8// trace:exempt reason=internal-detail
9pub struct QueryHit {
10    pub entities: Vec<scc_core::Entity>,
11    /// (name, signature, kind, file, start_line)
12    pub symbols: Vec<(String, String, String, String, u32)>,
13}
14
15// trace:exempt reason=internal-detail
16pub fn query(store: &scc_store::Store, req: &QueryRequest) -> crate::Result<QueryHit> {
17    let limit = req.limit.max(1);
18    let entities = store.search_entities(&req.query, limit)?;
19    let symbols = store.search_symbols(&req.query, limit)?;
20    let (entities, symbols) = if entities.is_empty() && symbols.is_empty() {
21        (
22            store.search_entities_like(&req.query, limit)?,
23            store.search_symbols_like(&req.query, limit)?,
24        )
25    } else {
26        (entities, symbols)
27    };
28    Ok(QueryHit { entities, symbols })
29}
30
31// trace:exempt reason=internal-detail
32pub fn components(store: &scc_store::Store) -> crate::Result<Vec<scc_core::Entity>> {
33    Ok(store.components()?)
34}
35
36// trace:exempt reason=internal-detail
37pub fn flows(store: &scc_store::Store) -> crate::Result<Vec<scc_core::Flow>> {
38    Ok(store.flows()?)
39}
40
41// trace:exempt reason=internal-detail
42pub fn relationships(
43    store: &scc_store::Store,
44    subject: Option<&str>,
45    predicate: Option<&str>,
46    limit: usize,
47) -> crate::Result<Vec<scc_core::Relationship>> {
48    let mut out = if let Some(s) = subject {
49        store.relationships_for(s)?
50    } else {
51        store.all_relationships()?
52    };
53    if let Some(p) = predicate {
54        out.retain(|r| r.predicate == p);
55    }
56    out.truncate(limit.max(1));
57    Ok(out)
58}