use napi::bindgen_prelude::*;
use napi_derive::napi;
use ruvector_core::DistanceMetric;
use std::collections::HashMap;
#[napi(string_enum)]
#[derive(Debug)]
pub enum JsDistanceMetric {
Euclidean,
Cosine,
DotProduct,
Manhattan,
}
impl From<JsDistanceMetric> for DistanceMetric {
fn from(metric: JsDistanceMetric) -> Self {
match metric {
JsDistanceMetric::Euclidean => DistanceMetric::Euclidean,
JsDistanceMetric::Cosine => DistanceMetric::Cosine,
JsDistanceMetric::DotProduct => DistanceMetric::DotProduct,
JsDistanceMetric::Manhattan => DistanceMetric::Manhattan,
}
}
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsGraphOptions {
pub distance_metric: Option<JsDistanceMetric>,
pub dimensions: Option<u32>,
pub storage_path: Option<String>,
}
impl Default for JsGraphOptions {
fn default() -> Self {
Self {
distance_metric: Some(JsDistanceMetric::Cosine),
dimensions: Some(384),
storage_path: None,
}
}
}
#[napi(object)]
#[derive(Clone)]
pub struct JsNode {
pub id: String,
pub embedding: Float32Array,
pub labels: Option<Vec<String>>,
pub properties: Option<HashMap<String, String>>,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsEdge {
pub from: String,
pub to: String,
pub description: String,
pub embedding: Float32Array,
pub confidence: Option<f64>,
pub metadata: Option<HashMap<String, String>>,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsHyperedge {
pub nodes: Vec<String>,
pub description: String,
pub embedding: Float32Array,
pub confidence: Option<f64>,
pub metadata: Option<HashMap<String, String>>,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsHyperedgeQuery {
pub embedding: Float32Array,
pub k: u32,
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsHyperedgeResult {
pub id: String,
pub score: f64,
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsNodeResult {
pub id: String,
pub labels: Vec<String>,
pub properties: HashMap<String, String>,
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsEdgeResult {
pub id: String,
pub from: String,
pub to: String,
pub edge_type: String,
pub properties: HashMap<String, String>,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsQueryResult {
pub nodes: Vec<JsNodeResult>,
pub edges: Vec<JsEdgeResult>,
pub stats: Option<JsGraphStats>,
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsGraphStats {
pub total_nodes: u32,
pub total_edges: u32,
pub avg_degree: f64,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsBatchInsert {
pub nodes: Vec<JsNode>,
pub edges: Vec<JsEdge>,
}
#[napi(object)]
#[derive(Debug, Clone)]
pub struct JsBatchResult {
pub node_ids: Vec<String>,
pub edge_ids: Vec<String>,
}
#[napi(string_enum)]
#[derive(Debug)]
pub enum JsTemporalGranularity {
Hourly,
Daily,
Monthly,
Yearly,
}
#[napi(object)]
#[derive(Clone)]
pub struct JsTemporalHyperedge {
pub hyperedge: JsHyperedge,
pub timestamp: i64,
pub expires_at: Option<i64>,
pub granularity: JsTemporalGranularity,
}