mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-29 02:42:47 -04:00
49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
#![allow(clippy::unwrap_used, clippy::panic)] // TODO: Brendan remove this once you've got error handling here
|
|
|
|
mod actor;
|
|
mod db_operation;
|
|
pub mod ingest;
|
|
mod manager;
|
|
|
|
use sd_prisma::prisma::{crdt_operation, instance, PrismaClient};
|
|
use sd_sync::CRDTOperation;
|
|
|
|
use std::{
|
|
collections::HashMap,
|
|
sync::{atomic::AtomicBool, Arc},
|
|
};
|
|
|
|
pub use ingest::*;
|
|
pub use manager::*;
|
|
pub use uhlc::NTP64;
|
|
|
|
#[derive(Clone)]
|
|
pub enum SyncMessage {
|
|
Ingested,
|
|
Created,
|
|
}
|
|
|
|
pub type Timestamps = Arc<tokio::sync::RwLock<HashMap<uuid::Uuid, NTP64>>>;
|
|
|
|
pub struct SharedState {
|
|
pub db: Arc<PrismaClient>,
|
|
pub emit_messages_flag: Arc<AtomicBool>,
|
|
pub instance: uuid::Uuid,
|
|
pub timestamps: Timestamps,
|
|
pub clock: uhlc::HLC,
|
|
}
|
|
|
|
#[must_use]
|
|
pub fn crdt_op_db(op: &CRDTOperation) -> crdt_operation::Create {
|
|
crdt_operation::Create {
|
|
id: op.id.as_bytes().to_vec(),
|
|
timestamp: op.timestamp.0 as i64,
|
|
instance: instance::pub_id::equals(op.instance.as_bytes().to_vec()),
|
|
kind: op.kind().to_string(),
|
|
data: serde_json::to_vec(&op.data).unwrap(),
|
|
model: op.model.to_string(),
|
|
record_id: serde_json::to_vec(&op.record_id).unwrap(),
|
|
_params: vec![],
|
|
}
|
|
}
|