Implement clone_repo and start handling synchronization requests

This commit is contained in:
Antonio Scandurra 2023-07-19 16:04:44 +02:00
parent e6b7bbee25
commit 27b06c1d09
3 changed files with 215 additions and 15 deletions

View file

@ -1,20 +1,25 @@
use crate::{
operations::{CreateBranch, CreateDocument, Edit},
OperationId, RepoId, Request, RevisionId, RoomCredentials,
OperationCount, OperationId, ReplicaId, RepoId, Request, RevisionId, RoomCredentials,
};
use collections::BTreeMap;
use serde::{Deserialize, Serialize};
use std::{any::Any, sync::Arc};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum RequestEnvelope {
PublishRepo(PublishRepo),
CloneRepo(CloneRepo),
SyncRepo(SyncRepo),
}
impl RequestEnvelope {
pub fn unwrap(self) -> Box<dyn Any> {
Box::new(match self {
RequestEnvelope::PublishRepo(request) => request,
})
match self {
RequestEnvelope::PublishRepo(request) => Box::new(request),
RequestEnvelope::CloneRepo(request) => Box::new(request),
RequestEnvelope::SyncRepo(request) => Box::new(request),
}
}
}
@ -45,6 +50,49 @@ pub struct PublishRepoResponse {
pub credentials: RoomCredentials,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CloneRepo {
pub name: Arc<str>,
}
impl Request for CloneRepo {
type Response = CloneRepoResponse;
}
impl Into<RequestEnvelope> for CloneRepo {
fn into(self) -> RequestEnvelope {
RequestEnvelope::CloneRepo(self)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct CloneRepoResponse {
pub repo_id: RepoId,
pub replica_id: ReplicaId,
pub credentials: RoomCredentials,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SyncRepo {
pub id: RepoId,
pub max_operation_ids: BTreeMap<ReplicaId, OperationCount>,
}
impl Request for SyncRepo {
type Response = SyncRepoResponse;
}
impl Into<RequestEnvelope> for SyncRepo {
fn into(self) -> RequestEnvelope {
RequestEnvelope::SyncRepo(self)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct SyncRepoResponse {
pub operations: Vec<Operation>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum MessageEnvelope {
Operation(Operation),