use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;
pub type VertexId = Uuid;
pub type EdgeId = Uuid;
pub type Label = String;
pub type PropertyKey = String;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(untagged)]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Integer(i64), String(String),
}
pub type Properties = HashMap<PropertyKey, Value>;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GraphRef_(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TxId(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ContentHash(pub String);
impl ContentHash {
pub fn sha256(data: [u8; 32]) -> Self {
use sha2::{Sha256, Digest};
let mut hasher = Sha256::new();
hasher.update(data);
let result = hasher.finalize();
Self(hex::encode(result))
}
}
#[derive(Debug, thiserror::Error)]
pub enum KotobaError {
#[error("Parse error: {0}")]
Parse(String),
#[error("Execution error: {0}")]
Execution(String),
#[error("Storage error: {0}")]
Storage(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Rewrite error: {0}")]
Rewrite(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("IO error: {0}")]
IoError(String),
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("Not found: {0}")]
NotFound(String),
#[error("Security error: {0}")]
Security(String),
#[error("Configuration error: {0}")]
Configuration(String),
}
pub type Result<T> = std::result::Result<T, KotobaError>;