pub(crate) mod facts;
pub(crate) mod post;
pub(crate) mod post_events;
pub(crate) mod runtime;
pub(crate) mod wire;
use helix_core::{Correlation, TimerId};
use serde_json::Value;
use std::collections::{HashMap, VecDeque};
pub(crate) const EVENT: &str = "im:category_chain:projection";
pub(crate) const STATUS_EVENT: &str = "im:category_chain:operation";
#[derive(Debug, Clone, PartialEq)]
pub struct Request {
pub command: String,
pub channel: String,
pub chain: Option<String>,
pub viewer: String,
pub req_id: Option<String>,
pub mutation: Option<String>,
pub query_scope: String,
pub temporary_id: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Document {
pub scope: String,
pub revision: String,
pub value: Value,
pub write: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Work {
pub request: Request,
pub documents: Vec<Document>,
pub visibility_scope: String,
pub post_guard: Option<String>,
pub permissions: Option<Value>,
pub index: usize,
pub data: Value,
pub event_seq: Option<crate::state::Seq>,
pub ws: bool,
pub reconcile: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Pending {
Prepare { request: Request, payload: Vec<u8> },
Http { request: Request, timer: TimerId },
Visibility(Work),
Head(Work),
MessageHead(Work),
MessageReadback(Work),
Persist(Work),
Readback(Work),
}
#[derive(Debug, Default)]
pub(crate) struct State {
pub queue: VecDeque<Work>,
pub busy: bool,
pub timers: HashMap<TimerId, Correlation>,
}
pub(crate) fn is_command(name: &str) -> bool {
wire::COMMANDS.contains(&name)
}
pub(crate) fn is_read(name: &str) -> bool {
matches!(
name,
"category_chain_capabilities"
| "category_chain_get"
| "category_chain_get_mine"
| "category_chain_entries"
| "category_chain_reconcile"
)
}
pub(crate) fn string(value: &Value, key: &str) -> Option<String> {
value
.get(key)
.and_then(Value::as_str)
.filter(|s| !s.is_empty())
.map(str::to_owned)
}