Skip to main content

kyu_extension/
lib.rs

1//! kyu-extension: Extension trait and procedure signatures.
2//!
3//! Extensions register named procedures (e.g., `algo.pageRank`) that can be
4//! invoked via `CALL algo.pageRank(...) YIELD node_id, rank`. Each procedure
5//! receives typed arguments and returns a table of named, typed columns.
6
7use std::collections::HashMap;
8
9use kyu_types::{LogicalType, TypedValue};
10
11/// A procedure parameter: name + type description.
12#[derive(Clone, Debug)]
13pub struct ProcParam {
14    pub name: String,
15    pub type_desc: String,
16}
17
18/// A procedure result column: name + logical type.
19#[derive(Clone, Debug)]
20pub struct ProcColumn {
21    pub name: String,
22    pub data_type: LogicalType,
23}
24
25/// Signature of an extension procedure.
26#[derive(Clone, Debug)]
27pub struct ProcedureSignature {
28    pub name: String,
29    pub params: Vec<ProcParam>,
30    pub columns: Vec<ProcColumn>,
31}
32
33/// A row of typed results, ordered by column index (matching ProcedureSignature.columns).
34pub type ProcRow = Vec<TypedValue>;
35
36/// Trait that every extension must implement.
37pub trait Extension: Send + Sync {
38    /// Extension name (e.g., "algo").
39    fn name(&self) -> &str;
40
41    /// List all procedures this extension provides.
42    fn procedures(&self) -> Vec<ProcedureSignature>;
43
44    /// Whether this extension needs the graph adjacency map.
45    /// Defaults to `false`. Override to `true` for graph algorithm extensions.
46    fn needs_graph(&self) -> bool {
47        false
48    }
49
50    /// Execute a named procedure with string arguments.
51    /// Returns rows of typed values, column-ordered per the procedure signature.
52    fn execute(
53        &self,
54        procedure: &str,
55        args: &[String],
56        adjacency: &HashMap<i64, Vec<(i64, f64)>>,
57    ) -> Result<Vec<ProcRow>, String>;
58}