rename i64 as RevId

This commit is contained in:
appflowy 2021-10-02 21:35:06 +08:00
parent af6afafd0f
commit c9cfe9dfeb
41 changed files with 560 additions and 278 deletions

View File

@ -14,6 +14,53 @@ import 'revision.pbenum.dart';
export 'revision.pbenum.dart';
class RevId extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'RevId', createEmptyInstance: create)
..aInt64(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'inner')
..hasRequiredFields = false
;
RevId._() : super();
factory RevId({
$fixnum.Int64? inner,
}) {
final _result = create();
if (inner != null) {
_result.inner = inner;
}
return _result;
}
factory RevId.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory RevId.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
RevId clone() => RevId()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
RevId copyWith(void Function(RevId) updates) => super.copyWith((message) => updates(message as RevId)) as RevId; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static RevId create() => RevId._();
RevId createEmptyInstance() => create();
static $pb.PbList<RevId> createRepeated() => $pb.PbList<RevId>();
@$core.pragma('dart2js:noInline')
static RevId getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<RevId>(create);
static RevId? _defaultInstance;
@$pb.TagNumber(1)
$fixnum.Int64 get inner => $_getI64(0);
@$pb.TagNumber(1)
set inner($fixnum.Int64 v) { $_setInt64(0, v); }
@$pb.TagNumber(1)
$core.bool hasInner() => $_has(0);
@$pb.TagNumber(1)
void clearInner() => clearField(1);
}
class Revision extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Revision', createEmptyInstance: create)
..aInt64(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'baseRevId')

View File

@ -19,6 +19,16 @@ const RevType$json = const {
/// Descriptor for `RevType`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List revTypeDescriptor = $convert.base64Decode('CgdSZXZUeXBlEgkKBUxvY2FsEAASCgoGUmVtb3RlEAE=');
@$core.Deprecated('Use revIdDescriptor instead')
const RevId$json = const {
'1': 'RevId',
'2': const [
const {'1': 'inner', '3': 1, '4': 1, '5': 3, '10': 'inner'},
],
};
/// Descriptor for `RevId`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List revIdDescriptor = $convert.base64Decode('CgVSZXZJZBIUCgVpbm5lchgBIAEoA1IFaW5uZXI=');
@$core.Deprecated('Use revisionDescriptor instead')
const Revision$json = const {
'1': 'Revision',

View File

@ -15,7 +15,7 @@ export 'ws.pbenum.dart';
class WsDocumentData extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'WsDocumentData', createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'docId')
..e<WsDataType>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'ty', $pb.PbFieldType.OE, defaultOrMaker: WsDataType.Acked, valueOf: WsDataType.valueOf, enumValues: WsDataType.values)
..a<$core.List<$core.int>>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'data', $pb.PbFieldType.OY)
..hasRequiredFields = false
@ -23,13 +23,13 @@ class WsDocumentData extends $pb.GeneratedMessage {
WsDocumentData._() : super();
factory WsDocumentData({
$core.String? id,
$core.String? docId,
WsDataType? ty,
$core.List<$core.int>? data,
}) {
final _result = create();
if (id != null) {
_result.id = id;
if (docId != null) {
_result.docId = docId;
}
if (ty != null) {
_result.ty = ty;
@ -61,13 +61,13 @@ class WsDocumentData extends $pb.GeneratedMessage {
static WsDocumentData? _defaultInstance;
@$pb.TagNumber(1)
$core.String get id => $_getSZ(0);
$core.String get docId => $_getSZ(0);
@$pb.TagNumber(1)
set id($core.String v) { $_setString(0, v); }
set docId($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasId() => $_has(0);
$core.bool hasDocId() => $_has(0);
@$pb.TagNumber(1)
void clearId() => clearField(1);
void clearDocId() => clearField(1);
@$pb.TagNumber(2)
WsDataType get ty => $_getN(1);

View File

@ -14,12 +14,14 @@ class WsDataType extends $pb.ProtobufEnum {
static const WsDataType PushRev = WsDataType._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PushRev');
static const WsDataType PullRev = WsDataType._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PullRev');
static const WsDataType Conflict = WsDataType._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Conflict');
static const WsDataType NewConnection = WsDataType._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewConnection');
static const $core.List<WsDataType> values = <WsDataType> [
Acked,
PushRev,
PullRev,
Conflict,
NewConnection,
];
static final $core.Map<$core.int, WsDataType> _byValue = $pb.ProtobufEnum.initByValue(values);

View File

@ -16,20 +16,21 @@ const WsDataType$json = const {
const {'1': 'PushRev', '2': 1},
const {'1': 'PullRev', '2': 2},
const {'1': 'Conflict', '2': 3},
const {'1': 'NewConnection', '2': 4},
],
};
/// Descriptor for `WsDataType`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List wsDataTypeDescriptor = $convert.base64Decode('CgpXc0RhdGFUeXBlEgkKBUFja2VkEAASCwoHUHVzaFJldhABEgsKB1B1bGxSZXYQAhIMCghDb25mbGljdBAD');
final $typed_data.Uint8List wsDataTypeDescriptor = $convert.base64Decode('CgpXc0RhdGFUeXBlEgkKBUFja2VkEAASCwoHUHVzaFJldhABEgsKB1B1bGxSZXYQAhIMCghDb25mbGljdBADEhEKDU5ld0Nvbm5lY3Rpb24QBA==');
@$core.Deprecated('Use wsDocumentDataDescriptor instead')
const WsDocumentData$json = const {
'1': 'WsDocumentData',
'2': const [
const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
const {'1': 'doc_id', '3': 1, '4': 1, '5': 9, '10': 'docId'},
const {'1': 'ty', '3': 2, '4': 1, '5': 14, '6': '.WsDataType', '10': 'ty'},
const {'1': 'data', '3': 3, '4': 1, '5': 12, '10': 'data'},
],
};
/// Descriptor for `WsDocumentData`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List wsDocumentDataDescriptor = $convert.base64Decode('Cg5Xc0RvY3VtZW50RGF0YRIOCgJpZBgBIAEoCVICaWQSGwoCdHkYAiABKA4yCy5Xc0RhdGFUeXBlUgJ0eRISCgRkYXRhGAMgASgMUgRkYXRh');
final $typed_data.Uint8List wsDocumentDataDescriptor = $convert.base64Decode('Cg5Xc0RvY3VtZW50RGF0YRIVCgZkb2NfaWQYASABKAlSBWRvY0lkEhsKAnR5GAIgASgOMgsuV3NEYXRhVHlwZVICdHkSEgoEZGF0YRgDIAEoDFIEZGF0YQ==');

View File

@ -4,12 +4,12 @@ use crate::service::{
ws::WsMessageAdaptor,
};
use actix_web::web::Data;
use byteorder::{BigEndian, WriteBytesExt};
use bytes::Bytes;
use dashmap::DashMap;
use flowy_document::{
entities::ws::{WsDataType, WsDocumentData},
protobuf::{Doc, RevType, Revision, RevisionRange, UpdateDocParams},
protobuf::{Doc, RevId, RevType, Revision, RevisionRange, UpdateDocParams},
services::doc::Document,
};
use flowy_net::errors::{internal_error, ServerError};
@ -162,7 +162,7 @@ impl ServerEditDoc {
fn mk_push_rev_ws_message(doc_id: &str, revision: Revision) -> WsMessageAdaptor {
let bytes = revision.write_to_bytes().unwrap();
let data = WsDocumentData {
id: doc_id.to_string(),
doc_id: doc_id.to_string(),
ty: WsDataType::PushRev,
data: bytes,
};
@ -179,7 +179,7 @@ fn mk_pull_rev_ws_message(doc_id: &str, from_rev_id: i64, to_rev_id: i64) -> WsM
let bytes = range.write_to_bytes().unwrap();
let data = WsDocumentData {
id: doc_id.to_string(),
doc_id: doc_id.to_string(),
ty: WsDataType::PullRev,
data: bytes,
};
@ -187,13 +187,17 @@ fn mk_pull_rev_ws_message(doc_id: &str, from_rev_id: i64, to_rev_id: i64) -> WsM
}
fn mk_acked_ws_message(revision: &Revision) -> WsMessageAdaptor {
let mut wtr = vec![];
let _ = wtr.write_i64::<BigEndian>(revision.rev_id);
// let mut wtr = vec![];
// let _ = wtr.write_i64::<BigEndian>(revision.rev_id);
let mut rev_id = RevId::new();
rev_id.set_inner(revision.rev_id);
let data = rev_id.write_to_bytes().unwrap();
let data = WsDocumentData {
id: revision.doc_id.clone(),
doc_id: revision.doc_id.clone(),
ty: WsDataType::Acked,
data: wtr,
data,
};
mk_ws_message(data)

View File

@ -1,8 +1,5 @@
use crate::service::{
doc::edit::{
edit_actor::{EditDocActor, EditMsg},
ServerEditDoc,
},
doc::edit::edit_actor::{EditDocActor, EditMsg},
ws::{entities::Socket, WsUser},
};
use actix_web::web::Data;

View File

@ -72,6 +72,10 @@ impl DocWsActor {
match document_data.ty {
WsDataType::Acked => Ok(()),
WsDataType::PushRev => self.handle_push_rev(user, socket, document_data.data, pool).await,
WsDataType::NewConnection => {
// TODO: send notifications to other users who visited the doc
Ok(())
},
WsDataType::PullRev => Ok(()),
WsDataType::Conflict => Ok(()),
}

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,7 +1,7 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod ffi_response;
pub use ffi_response::*;
mod ffi_response;
pub use ffi_response::*;
mod ffi_request;
pub use ffi_request::*;
mod ffi_request;
pub use ffi_request::*;

View File

@ -58,6 +58,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "UpdateDocParams"
| "DocDelta"
| "QueryDocParams"
| "RevId"
| "Revision"
| "RevisionRange"
| "WsDocumentData"
@ -74,7 +75,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "UserProfile"
| "UpdateUserRequest"
| "UpdateUserParams"
| "UserError" => TypeCategory::Protobuf,
| "UserError"
=> TypeCategory::Protobuf,
"ViewType"
| "WorkspaceEvent"
| "ErrorCode"
@ -85,7 +87,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "DocObservable"
| "FFIStatusCode"
| "UserEvent"
| "UserObservable" => TypeCategory::Enum,
| "UserObservable"
=> TypeCategory::Enum,
"Option" => TypeCategory::Opt,
_ => TypeCategory::Primitive,

View File

@ -1,6 +1,8 @@
use crate::services::util::md5;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_ot::core::Delta;
use std::fmt::Formatter;
#[derive(Debug, ProtoBuf_Enum, Clone, Eq, PartialEq)]
pub enum RevType {
@ -12,6 +14,46 @@ impl std::default::Default for RevType {
fn default() -> Self { RevType::Local }
}
// [[i64 to bytes]]
// use byteorder::{BigEndian, ReadBytesExt};
// use std::{io::Cursor};
// impl std::convert::TryFrom<Bytes> for RevId {
// type Error = DocError;
//
// fn try_from(bytes: Bytes) -> Result<Self, Self::Error> {
// // let mut wtr = vec![];
// // let _ = wtr.write_i64::<BigEndian>(revision.rev_id);
//
// let mut rdr = Cursor::new(bytes);
// match rdr.read_i64::<BigEndian>() {
// Ok(rev_id) => Ok(RevId(rev_id)),
// Err(e) => Err(DocError::internal().context(e)),
// }
// }
// }
#[derive(Clone, Debug, ProtoBuf, Default)]
pub struct RevId {
#[pb(index = 1)]
inner: i64,
}
impl AsRef<i64> for RevId {
fn as_ref(&self) -> &i64 { &self.inner }
}
impl std::convert::Into<i64> for RevId {
fn into(self) -> i64 { self.inner }
}
impl std::convert::From<i64> for RevId {
fn from(value: i64) -> Self { RevId { inner: value } }
}
impl std::fmt::Display for RevId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!("{}", self.inner)) }
}
#[derive(Clone, Default, ProtoBuf)]
pub struct Revision {
#[pb(index = 1)]
@ -50,12 +92,18 @@ impl std::fmt::Debug for Revision {
}
impl Revision {
pub fn new(base_rev_id: i64, rev_id: i64, delta_data: Vec<u8>, doc_id: &str, ty: RevType) -> Revision {
pub fn new<T1: Into<i64>, T2: Into<i64>>(
base_rev_id: T1,
rev_id: T2,
delta_data: Vec<u8>,
doc_id: &str,
ty: RevType,
) -> Revision {
let md5 = md5(&delta_data);
let doc_id = doc_id.to_owned();
Self {
base_rev_id,
rev_id,
base_rev_id: base_rev_id.into(),
rev_id: rev_id.into(),
delta_data,
md5,
doc_id,

View File

@ -1,15 +1,25 @@
use crate::entities::doc::Revision;
use crate::{entities::doc::Revision, errors::DocError};
use bytes::Bytes;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_ws::{WsMessage, WsModule};
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
#[derive(Debug, Clone, ProtoBuf_Enum, Eq, PartialEq, Hash)]
pub enum WsDataType {
Acked = 0,
PushRev = 1,
PullRev = 2,
Conflict = 3,
Acked = 0,
PushRev = 1,
PullRev = 2, // data should be Revision
Conflict = 3,
NewConnection = 4,
}
impl WsDataType {
pub fn data<T>(&self, bytes: Bytes) -> Result<T, DocError>
where
T: TryFrom<Bytes, Error = DocError>,
{
T::try_from(bytes)
}
}
impl std::default::Default for WsDataType {
@ -19,13 +29,14 @@ impl std::default::Default for WsDataType {
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct WsDocumentData {
#[pb(index = 1)]
pub id: String,
pub doc_id: String,
#[pb(index = 2)]
pub ty: WsDataType,
// Opti: parse the data with type constraints
#[pb(index = 3)]
pub data: Vec<u8>, // Delta
pub data: Vec<u8>,
}
impl std::convert::From<Revision> for WsDocumentData {
@ -34,7 +45,7 @@ impl std::convert::From<Revision> for WsDocumentData {
let bytes: Bytes = revision.try_into().unwrap();
let data = bytes.to_vec();
Self {
id,
doc_id: id,
ty: WsDataType::PushRev,
data,
}

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,19 +1,19 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod ws;
pub use ws::*;
mod ws;
pub use ws::*;
mod observable;
pub use observable::*;
mod observable;
pub use observable::*;
mod errors;
pub use errors::*;
mod errors;
pub use errors::*;
mod revision;
pub use revision::*;
mod revision;
pub use revision::*;
mod event;
pub use event::*;
mod event;
pub use event::*;
mod doc;
pub use doc::*;
mod doc;
pub use doc::*;

View File

@ -23,6 +23,158 @@
/// of protobuf runtime.
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1;
#[derive(PartialEq,Clone,Default)]
pub struct RevId {
// message fields
pub inner: i64,
// special fields
pub unknown_fields: ::protobuf::UnknownFields,
pub cached_size: ::protobuf::CachedSize,
}
impl<'a> ::std::default::Default for &'a RevId {
fn default() -> &'a RevId {
<RevId as ::protobuf::Message>::default_instance()
}
}
impl RevId {
pub fn new() -> RevId {
::std::default::Default::default()
}
// int64 inner = 1;
pub fn get_inner(&self) -> i64 {
self.inner
}
pub fn clear_inner(&mut self) {
self.inner = 0;
}
// Param is passed by value, moved
pub fn set_inner(&mut self, v: i64) {
self.inner = v;
}
}
impl ::protobuf::Message for RevId {
fn is_initialized(&self) -> bool {
true
}
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
while !is.eof()? {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
}
let tmp = is.read_int64()?;
self.inner = tmp;
},
_ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
},
};
}
::std::result::Result::Ok(())
}
// Compute sizes of nested messages
#[allow(unused_variables)]
fn compute_size(&self) -> u32 {
let mut my_size = 0;
if self.inner != 0 {
my_size += ::protobuf::rt::value_size(1, self.inner, ::protobuf::wire_format::WireTypeVarint);
}
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size);
my_size
}
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
if self.inner != 0 {
os.write_int64(1, self.inner)?;
}
os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(())
}
fn get_cached_size(&self) -> u32 {
self.cached_size.get()
}
fn get_unknown_fields(&self) -> &::protobuf::UnknownFields {
&self.unknown_fields
}
fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields {
&mut self.unknown_fields
}
fn as_any(&self) -> &dyn (::std::any::Any) {
self as &dyn (::std::any::Any)
}
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
Self::descriptor_static()
}
fn new() -> RevId {
RevId::new()
}
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT;
descriptor.get(|| {
let mut fields = ::std::vec::Vec::new();
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt64>(
"inner",
|m: &RevId| { &m.inner },
|m: &mut RevId| { &mut m.inner },
));
::protobuf::reflect::MessageDescriptor::new_pb_name::<RevId>(
"RevId",
fields,
file_descriptor_proto()
)
})
}
fn default_instance() -> &'static RevId {
static instance: ::protobuf::rt::LazyV2<RevId> = ::protobuf::rt::LazyV2::INIT;
instance.get(RevId::new)
}
}
impl ::protobuf::Clear for RevId {
fn clear(&mut self) {
self.inner = 0;
self.unknown_fields.clear();
}
}
impl ::std::fmt::Debug for RevId {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
::protobuf::text_format::fmt(self, f)
}
}
impl ::protobuf::reflect::ProtobufValue for RevId {
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
::protobuf::reflect::ReflectValueRef::Message(self)
}
}
#[derive(PartialEq,Clone,Default)]
pub struct Revision {
// message fields
@ -647,48 +799,53 @@ impl ::protobuf::reflect::ProtobufValue for RevType {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x0erevision.proto\"\xa3\x01\n\x08Revision\x12\x1e\n\x0bbase_rev_id\
\x18\x01\x20\x01(\x03R\tbaseRevId\x12\x15\n\x06rev_id\x18\x02\x20\x01(\
\x03R\x05revId\x12\x1d\n\ndelta_data\x18\x03\x20\x01(\x0cR\tdeltaData\
\x12\x10\n\x03md5\x18\x04\x20\x01(\tR\x03md5\x12\x15\n\x06doc_id\x18\x05\
\x20\x01(\tR\x05docId\x12\x18\n\x02ty\x18\x06\x20\x01(\x0e2\x08.RevTypeR\
\x02ty\"b\n\rRevisionRange\x12\x15\n\x06doc_id\x18\x01\x20\x01(\tR\x05do\
cId\x12\x1e\n\x0bfrom_rev_id\x18\x02\x20\x01(\x03R\tfromRevId\x12\x1a\n\
\tto_rev_id\x18\x03\x20\x01(\x03R\x07toRevId*\x20\n\x07RevType\x12\t\n\
\x05Local\x10\0\x12\n\n\x06Remote\x10\x01J\x9b\x05\n\x06\x12\x04\0\0\x12\
\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\t\x01\
\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x10\n\x0b\n\x04\x04\0\x02\0\x12\x03\
\x03\x04\x1a\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\n\x05\
\x04\0\x02\0\x01\x12\x03\x03\n\x15\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\
\x03\x18\x19\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x15\n\x0c\n\x05\
\x04\0\x02\x01\x05\x12\x03\x04\x04\t\n\x0c\n\x05\x04\0\x02\x01\x01\x12\
\x03\x04\n\x10\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x13\x14\n\x0b\n\
\x04\x04\0\x02\x02\x12\x03\x05\x04\x19\n\x0c\n\x05\x04\0\x02\x02\x05\x12\
\x03\x05\x04\t\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\n\x14\n\x0c\n\
\x05\x04\0\x02\x02\x03\x12\x03\x05\x17\x18\n\x0b\n\x04\x04\0\x02\x03\x12\
\x03\x06\x04\x13\n\x0c\n\x05\x04\0\x02\x03\x05\x12\x03\x06\x04\n\n\x0c\n\
\x05\x04\0\x02\x03\x01\x12\x03\x06\x0b\x0e\n\x0c\n\x05\x04\0\x02\x03\x03\
\x12\x03\x06\x11\x12\n\x0b\n\x04\x04\0\x02\x04\x12\x03\x07\x04\x16\n\x0c\
\n\x05\x04\0\x02\x04\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\0\x02\x04\x01\
\x12\x03\x07\x0b\x11\n\x0c\n\x05\x04\0\x02\x04\x03\x12\x03\x07\x14\x15\n\
\x0b\n\x04\x04\0\x02\x05\x12\x03\x08\x04\x13\n\x0c\n\x05\x04\0\x02\x05\
\x06\x12\x03\x08\x04\x0b\n\x0c\n\x05\x04\0\x02\x05\x01\x12\x03\x08\x0c\
\x0e\n\x0c\n\x05\x04\0\x02\x05\x03\x12\x03\x08\x11\x12\n\n\n\x02\x04\x01\
\x12\x04\n\0\x0e\x01\n\n\n\x03\x04\x01\x01\x12\x03\n\x08\x15\n\x0b\n\x04\
\x04\x01\x02\0\x12\x03\x0b\x04\x16\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\
\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x0b\x0b\x11\n\x0c\n\x05\
\x04\x01\x02\0\x03\x12\x03\x0b\x14\x15\n\x0b\n\x04\x04\x01\x02\x01\x12\
\x03\x0c\x04\x1a\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x0c\x04\t\n\x0c\
\n\x05\x04\x01\x02\x01\x01\x12\x03\x0c\n\x15\n\x0c\n\x05\x04\x01\x02\x01\
\x03\x12\x03\x0c\x18\x19\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\r\x04\x18\n\
\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\r\x04\t\n\x0c\n\x05\x04\x01\x02\
\x02\x01\x12\x03\r\n\x13\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\r\x16\
\x17\n\n\n\x02\x05\0\x12\x04\x0f\0\x12\x01\n\n\n\x03\x05\0\x01\x12\x03\
\x0f\x05\x0c\n\x0b\n\x04\x05\0\x02\0\x12\x03\x10\x04\x0e\n\x0c\n\x05\x05\
\0\x02\0\x01\x12\x03\x10\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x10\
\x0c\r\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x11\x04\x0f\n\x0c\n\x05\x05\0\
\x02\x01\x01\x12\x03\x11\x04\n\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x11\
\r\x0eb\x06proto3\
\n\x0erevision.proto\"\x1d\n\x05RevId\x12\x14\n\x05inner\x18\x01\x20\x01\
(\x03R\x05inner\"\xa3\x01\n\x08Revision\x12\x1e\n\x0bbase_rev_id\x18\x01\
\x20\x01(\x03R\tbaseRevId\x12\x15\n\x06rev_id\x18\x02\x20\x01(\x03R\x05r\
evId\x12\x1d\n\ndelta_data\x18\x03\x20\x01(\x0cR\tdeltaData\x12\x10\n\
\x03md5\x18\x04\x20\x01(\tR\x03md5\x12\x15\n\x06doc_id\x18\x05\x20\x01(\
\tR\x05docId\x12\x18\n\x02ty\x18\x06\x20\x01(\x0e2\x08.RevTypeR\x02ty\"b\
\n\rRevisionRange\x12\x15\n\x06doc_id\x18\x01\x20\x01(\tR\x05docId\x12\
\x1e\n\x0bfrom_rev_id\x18\x02\x20\x01(\x03R\tfromRevId\x12\x1a\n\tto_rev\
_id\x18\x03\x20\x01(\x03R\x07toRevId*\x20\n\x07RevType\x12\t\n\x05Local\
\x10\0\x12\n\n\x06Remote\x10\x01J\xea\x05\n\x06\x12\x04\0\0\x15\x01\n\
\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x04\x01\n\n\
\n\x03\x04\0\x01\x12\x03\x02\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\
\x04\x14\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\n\x05\x04\0\
\x02\0\x01\x12\x03\x03\n\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\
\x13\n\n\n\x02\x04\x01\x12\x04\x05\0\x0c\x01\n\n\n\x03\x04\x01\x01\x12\
\x03\x05\x08\x10\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x06\x04\x1a\n\x0c\n\
\x05\x04\x01\x02\0\x05\x12\x03\x06\x04\t\n\x0c\n\x05\x04\x01\x02\0\x01\
\x12\x03\x06\n\x15\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x06\x18\x19\n\
\x0b\n\x04\x04\x01\x02\x01\x12\x03\x07\x04\x15\n\x0c\n\x05\x04\x01\x02\
\x01\x05\x12\x03\x07\x04\t\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x07\n\
\x10\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x07\x13\x14\n\x0b\n\x04\x04\
\x01\x02\x02\x12\x03\x08\x04\x19\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\
\x08\x04\t\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\x08\n\x14\n\x0c\n\x05\
\x04\x01\x02\x02\x03\x12\x03\x08\x17\x18\n\x0b\n\x04\x04\x01\x02\x03\x12\
\x03\t\x04\x13\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\t\x04\n\n\x0c\n\
\x05\x04\x01\x02\x03\x01\x12\x03\t\x0b\x0e\n\x0c\n\x05\x04\x01\x02\x03\
\x03\x12\x03\t\x11\x12\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\n\x04\x16\n\
\x0c\n\x05\x04\x01\x02\x04\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\
\x04\x01\x12\x03\n\x0b\x11\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\n\x14\
\x15\n\x0b\n\x04\x04\x01\x02\x05\x12\x03\x0b\x04\x13\n\x0c\n\x05\x04\x01\
\x02\x05\x06\x12\x03\x0b\x04\x0b\n\x0c\n\x05\x04\x01\x02\x05\x01\x12\x03\
\x0b\x0c\x0e\n\x0c\n\x05\x04\x01\x02\x05\x03\x12\x03\x0b\x11\x12\n\n\n\
\x02\x04\x02\x12\x04\r\0\x11\x01\n\n\n\x03\x04\x02\x01\x12\x03\r\x08\x15\
\n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0e\x04\x16\n\x0c\n\x05\x04\x02\x02\0\
\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0e\x0b\x11\
\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0e\x14\x15\n\x0b\n\x04\x04\x02\
\x02\x01\x12\x03\x0f\x04\x1a\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0f\
\x04\t\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x0f\n\x15\n\x0c\n\x05\x04\
\x02\x02\x01\x03\x12\x03\x0f\x18\x19\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\
\x10\x04\x18\n\x0c\n\x05\x04\x02\x02\x02\x05\x12\x03\x10\x04\t\n\x0c\n\
\x05\x04\x02\x02\x02\x01\x12\x03\x10\n\x13\n\x0c\n\x05\x04\x02\x02\x02\
\x03\x12\x03\x10\x16\x17\n\n\n\x02\x05\0\x12\x04\x12\0\x15\x01\n\n\n\x03\
\x05\0\x01\x12\x03\x12\x05\x0c\n\x0b\n\x04\x05\0\x02\0\x12\x03\x13\x04\
\x0e\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x13\x04\t\n\x0c\n\x05\x05\0\x02\
\0\x02\x12\x03\x13\x0c\r\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x14\x04\x0f\n\
\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x14\x04\n\n\x0c\n\x05\x05\0\x02\x01\
\x02\x12\x03\x14\r\x0eb\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -26,7 +26,7 @@
#[derive(PartialEq,Clone,Default)]
pub struct WsDocumentData {
// message fields
pub id: ::std::string::String,
pub doc_id: ::std::string::String,
pub ty: WsDataType,
pub data: ::std::vec::Vec<u8>,
// special fields
@ -45,30 +45,30 @@ impl WsDocumentData {
::std::default::Default::default()
}
// string id = 1;
// string doc_id = 1;
pub fn get_id(&self) -> &str {
&self.id
pub fn get_doc_id(&self) -> &str {
&self.doc_id
}
pub fn clear_id(&mut self) {
self.id.clear();
pub fn clear_doc_id(&mut self) {
self.doc_id.clear();
}
// Param is passed by value, moved
pub fn set_id(&mut self, v: ::std::string::String) {
self.id = v;
pub fn set_doc_id(&mut self, v: ::std::string::String) {
self.doc_id = v;
}
// Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first.
pub fn mut_id(&mut self) -> &mut ::std::string::String {
&mut self.id
pub fn mut_doc_id(&mut self) -> &mut ::std::string::String {
&mut self.doc_id
}
// Take field
pub fn take_id(&mut self) -> ::std::string::String {
::std::mem::replace(&mut self.id, ::std::string::String::new())
pub fn take_doc_id(&mut self) -> ::std::string::String {
::std::mem::replace(&mut self.doc_id, ::std::string::String::new())
}
// .WsDataType ty = 2;
@ -123,7 +123,7 @@ impl ::protobuf::Message for WsDocumentData {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?;
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.doc_id)?;
},
2 => {
::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.ty, 2, &mut self.unknown_fields)?
@ -143,8 +143,8 @@ impl ::protobuf::Message for WsDocumentData {
#[allow(unused_variables)]
fn compute_size(&self) -> u32 {
let mut my_size = 0;
if !self.id.is_empty() {
my_size += ::protobuf::rt::string_size(1, &self.id);
if !self.doc_id.is_empty() {
my_size += ::protobuf::rt::string_size(1, &self.doc_id);
}
if self.ty != WsDataType::Acked {
my_size += ::protobuf::rt::enum_size(2, self.ty);
@ -158,8 +158,8 @@ impl ::protobuf::Message for WsDocumentData {
}
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
if !self.id.is_empty() {
os.write_string(1, &self.id)?;
if !self.doc_id.is_empty() {
os.write_string(1, &self.doc_id)?;
}
if self.ty != WsDataType::Acked {
os.write_enum(2, ::protobuf::ProtobufEnum::value(&self.ty))?;
@ -206,9 +206,9 @@ impl ::protobuf::Message for WsDocumentData {
descriptor.get(|| {
let mut fields = ::std::vec::Vec::new();
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"id",
|m: &WsDocumentData| { &m.id },
|m: &mut WsDocumentData| { &mut m.id },
"doc_id",
|m: &WsDocumentData| { &m.doc_id },
|m: &mut WsDocumentData| { &mut m.doc_id },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum<WsDataType>>(
"ty",
@ -236,7 +236,7 @@ impl ::protobuf::Message for WsDocumentData {
impl ::protobuf::Clear for WsDocumentData {
fn clear(&mut self) {
self.id.clear();
self.doc_id.clear();
self.ty = WsDataType::Acked;
self.data.clear();
self.unknown_fields.clear();
@ -261,6 +261,7 @@ pub enum WsDataType {
PushRev = 1,
PullRev = 2,
Conflict = 3,
NewConnection = 4,
}
impl ::protobuf::ProtobufEnum for WsDataType {
@ -274,6 +275,7 @@ impl ::protobuf::ProtobufEnum for WsDataType {
1 => ::std::option::Option::Some(WsDataType::PushRev),
2 => ::std::option::Option::Some(WsDataType::PullRev),
3 => ::std::option::Option::Some(WsDataType::Conflict),
4 => ::std::option::Option::Some(WsDataType::NewConnection),
_ => ::std::option::Option::None
}
}
@ -284,6 +286,7 @@ impl ::protobuf::ProtobufEnum for WsDataType {
WsDataType::PushRev,
WsDataType::PullRev,
WsDataType::Conflict,
WsDataType::NewConnection,
];
values
}
@ -312,30 +315,33 @@ impl ::protobuf::reflect::ProtobufValue for WsDataType {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x08ws.proto\"Q\n\x0eWsDocumentData\x12\x0e\n\x02id\x18\x01\x20\x01(\t\
R\x02id\x12\x1b\n\x02ty\x18\x02\x20\x01(\x0e2\x0b.WsDataTypeR\x02ty\x12\
\x12\n\x04data\x18\x03\x20\x01(\x0cR\x04data*?\n\nWsDataType\x12\t\n\x05\
Acked\x10\0\x12\x0b\n\x07PushRev\x10\x01\x12\x0b\n\x07PullRev\x10\x02\
\x12\x0c\n\x08Conflict\x10\x03J\x8b\x03\n\x06\x12\x04\0\0\x0c\x01\n\x08\
\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\
\x03\x04\0\x01\x12\x03\x02\x08\x16\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\
\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\
\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\
\x11\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x16\n\x0c\n\x05\x04\0\x02\
\x01\x06\x12\x03\x04\x04\x0e\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\
\x0f\x11\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x14\x15\n\x0b\n\x04\
\x04\0\x02\x02\x12\x03\x05\x04\x13\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\
\x05\x04\t\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\n\x0e\n\x0c\n\x05\
\x04\0\x02\x02\x03\x12\x03\x05\x11\x12\n\n\n\x02\x05\0\x12\x04\x07\0\x0c\
\x01\n\n\n\x03\x05\0\x01\x12\x03\x07\x05\x0f\n\x0b\n\x04\x05\0\x02\0\x12\
\x03\x08\x04\x0e\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x08\x04\t\n\x0c\n\
\x05\x05\0\x02\0\x02\x12\x03\x08\x0c\r\n\x0b\n\x04\x05\0\x02\x01\x12\x03\
\t\x04\x10\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\t\x04\x0b\n\x0c\n\x05\
\x05\0\x02\x01\x02\x12\x03\t\x0e\x0f\n\x0b\n\x04\x05\0\x02\x02\x12\x03\n\
\x04\x10\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\n\x04\x0b\n\x0c\n\x05\x05\
\0\x02\x02\x02\x12\x03\n\x0e\x0f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x0b\
\x04\x11\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x0b\x04\x0c\n\x0c\n\x05\
\x05\0\x02\x03\x02\x12\x03\x0b\x0f\x10b\x06proto3\
\n\x08ws.proto\"X\n\x0eWsDocumentData\x12\x15\n\x06doc_id\x18\x01\x20\
\x01(\tR\x05docId\x12\x1b\n\x02ty\x18\x02\x20\x01(\x0e2\x0b.WsDataTypeR\
\x02ty\x12\x12\n\x04data\x18\x03\x20\x01(\x0cR\x04data*R\n\nWsDataType\
\x12\t\n\x05Acked\x10\0\x12\x0b\n\x07PushRev\x10\x01\x12\x0b\n\x07PullRe\
v\x10\x02\x12\x0c\n\x08Conflict\x10\x03\x12\x11\n\rNewConnection\x10\x04\
J\xb4\x03\n\x06\x12\x04\0\0\r\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\
\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\
\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\
\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x11\n\x0c\
\n\x05\x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\
\x03\x04\x04\x16\n\x0c\n\x05\x04\0\x02\x01\x06\x12\x03\x04\x04\x0e\n\x0c\
\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0f\x11\n\x0c\n\x05\x04\0\x02\x01\
\x03\x12\x03\x04\x14\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x13\n\
\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\t\n\x0c\n\x05\x04\0\x02\x02\
\x01\x12\x03\x05\n\x0e\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x11\x12\
\n\n\n\x02\x05\0\x12\x04\x07\0\r\x01\n\n\n\x03\x05\0\x01\x12\x03\x07\x05\
\x0f\n\x0b\n\x04\x05\0\x02\0\x12\x03\x08\x04\x0e\n\x0c\n\x05\x05\0\x02\0\
\x01\x12\x03\x08\x04\t\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x08\x0c\r\n\
\x0b\n\x04\x05\0\x02\x01\x12\x03\t\x04\x10\n\x0c\n\x05\x05\0\x02\x01\x01\
\x12\x03\t\x04\x0b\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\t\x0e\x0f\n\x0b\
\n\x04\x05\0\x02\x02\x12\x03\n\x04\x10\n\x0c\n\x05\x05\0\x02\x02\x01\x12\
\x03\n\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\n\x0e\x0f\n\x0b\n\
\x04\x05\0\x02\x03\x12\x03\x0b\x04\x11\n\x0c\n\x05\x05\0\x02\x03\x01\x12\
\x03\x0b\x04\x0c\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x0b\x0f\x10\n\x0b\
\n\x04\x05\0\x02\x04\x12\x03\x0c\x04\x16\n\x0c\n\x05\x05\0\x02\x04\x01\
\x12\x03\x0c\x04\x11\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0c\x14\x15b\
\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -1,5 +1,8 @@
syntax = "proto3";
message RevId {
int64 inner = 1;
}
message Revision {
int64 base_rev_id = 1;
int64 rev_id = 2;

View File

@ -1,7 +1,7 @@
syntax = "proto3";
message WsDocumentData {
string id = 1;
string doc_id = 1;
WsDataType ty = 2;
bytes data = 3;
}
@ -10,4 +10,5 @@ enum WsDataType {
PushRev = 1;
PullRev = 2;
Conflict = 3;
NewConnection = 4;
}

View File

@ -9,7 +9,7 @@ use flowy_infra::future::{wrap_future, FnFuture, ResultFuture};
use crate::{
entities::doc::{CreateDocParams, Doc, DocDelta, QueryDocParams},
errors::{internal_error, DocError, DocResult},
errors::{internal_error, DocError},
module::DocumentUser,
services::{
cache::DocCache,
@ -177,7 +177,7 @@ impl RevisionServer for RevisionServerImpl {
Some(doc) => {
let delta = Delta::from_bytes(doc.data)?;
Ok(DocRevision {
rev_id: doc.rev_id,
rev_id: doc.rev_id.into(),
delta,
})
},

View File

@ -1,22 +1,18 @@
use crate::{
errors::{internal_error, DocError, DocResult},
entities::doc::RevId,
errors::{internal_error, DocResult},
services::doc::{
edit::{message::EditMsg, DocId},
Document,
UndoResult,
},
sql_tables::{DocTableChangeset, DocTableSql},
};
use async_stream::stream;
use flowy_database::ConnectionPool;
use flowy_ot::core::{Attribute, Delta, Interval};
use flowy_ot::core::Delta;
use futures::stream::StreamExt;
use std::{cell::RefCell, sync::Arc};
use tokio::{
macros::support::Future,
sync::{mpsc, oneshot, RwLock},
task::spawn_blocking,
};
use std::sync::Arc;
use tokio::sync::{mpsc, RwLock};
pub struct DocumentEditActor {
doc_id: DocId,
@ -115,12 +111,12 @@ impl DocumentEditActor {
}
#[tracing::instrument(level = "debug", skip(self, rev_id), err)]
async fn save_to_disk(&self, rev_id: i64) -> DocResult<()> {
async fn save_to_disk(&self, rev_id: RevId) -> DocResult<()> {
let data = self.document.read().await.to_json();
let changeset = DocTableChangeset {
id: self.doc_id.clone(),
data,
rev_id,
rev_id: rev_id.into(),
};
let sql = DocTableSql {};
let conn = self.pool.get().map_err(internal_error)?;

View File

@ -1,6 +1,6 @@
use crate::{
entities::{
doc::{Doc, RevType, Revision, RevisionRange},
doc::{Doc, RevId, RevType, Revision, RevisionRange},
ws::{WsDataType, WsDocumentData},
},
errors::{internal_error, DocError, DocResult},
@ -10,8 +10,6 @@ use crate::{
revision::{RevisionManager, RevisionServer},
UndoResult,
},
server::Server,
util::bytes_to_rev_id,
ws::{WsDocumentHandler, WsDocumentSender},
},
};
@ -62,7 +60,7 @@ impl ClientEditDoc {
let _ = self.document.send(msg);
let delta_data = rx.await.map_err(internal_error)??.to_bytes();
let rev_id = self.mk_revision(&delta_data).await?;
save(rev_id, self.document.clone()).await
save(rev_id.into(), self.document.clone()).await
}
pub async fn delete(&self, interval: Interval) -> Result<(), DocError> {
@ -139,12 +137,12 @@ impl ClientEditDoc {
Ok(Doc { id, data, rev_id })
}
async fn mk_revision(&self, delta_data: &Bytes) -> Result<i64, DocError> {
async fn mk_revision(&self, delta_data: &Bytes) -> Result<RevId, DocError> {
let (base_rev_id, rev_id) = self.rev_manager.next_rev_id();
let delta_data = delta_data.to_vec();
let revision = Revision::new(base_rev_id, rev_id, delta_data, &self.doc_id, RevType::Local);
self.rev_manager.add_revision(revision).await;
Ok(rev_id)
Ok(rev_id.into())
}
#[tracing::instrument(level = "debug", skip(self, data), err)]
@ -182,8 +180,9 @@ impl WsDocumentHandler for ClientEditDoc {
let range = RevisionRange::try_from(bytes)?;
let _ = rev_manager.send_revisions(range)?;
},
WsDataType::NewConnection => {},
WsDataType::Acked => {
let rev_id = bytes_to_rev_id(bytes.to_vec())?;
let rev_id = RevId::try_from(bytes)?;
let _ = rev_manager.ack_rev(rev_id);
},
WsDataType::Conflict => {},
@ -199,7 +198,7 @@ impl WsDocumentHandler for ClientEditDoc {
}
}
async fn save(rev_id: i64, document: UnboundedSender<EditMsg>) -> DocResult<()> {
async fn save(rev_id: RevId, document: UnboundedSender<EditMsg>) -> DocResult<()> {
let (ret, rx) = oneshot::channel::<DocResult<()>>();
let _ = document.send(EditMsg::SaveRevision { rev_id, ret });
let result = rx.await.map_err(internal_error)?;
@ -222,7 +221,7 @@ async fn handle_push_rev(
let _ = document.send(msg);
match rx.await.map_err(internal_error)? {
Ok(_) => save(revision.rev_id, document).await,
Ok(_) => save(revision.rev_id.into(), document).await,
Err(e) => {
rev_manager.push_compose_revision(revision);
Err(e)

View File

@ -1,11 +1,9 @@
use crate::{
errors::DocResult,
services::doc::{edit::DocId, Document, UndoResult},
sql_tables::{DocTableChangeset, DocTableSql},
};
use crate::{errors::DocResult, services::doc::UndoResult};
use flowy_ot::core::{Attribute, Delta, Interval};
use crate::entities::doc::RevId;
use tokio::sync::oneshot;
pub type Ret<T> = oneshot::Sender<DocResult<T>>;
pub enum EditMsg {
Delta {
@ -48,7 +46,7 @@ pub enum EditMsg {
ret: Ret<String>,
},
SaveRevision {
rev_id: i64,
rev_id: RevId,
ret: Ret<()>,
},
}

View File

@ -8,16 +8,16 @@ use crate::{
},
};
use crate::{entities::doc::Doc, errors::DocResult, services::server::Server};
use crate::{entities::doc::RevId, errors::DocResult};
use flowy_database::ConnectionPool;
use flowy_infra::future::ResultFuture;
use flowy_ot::core::Delta;
use parking_lot::RwLock;
use std::{collections::VecDeque, sync::Arc};
use tokio::sync::{mpsc, oneshot, oneshot::error::RecvError};
use tokio::sync::{mpsc, oneshot};
pub struct DocRevision {
pub rev_id: i64,
pub rev_id: RevId,
pub delta: Delta,
}
@ -37,7 +37,7 @@ impl RevisionManager {
pub async fn new(
doc_id: &str,
pool: Arc<ConnectionPool>,
ws_sender: Arc<dyn WsDocumentSender>,
ws: Arc<dyn WsDocumentSender>,
server: Arc<dyn RevisionServer>,
) -> DocResult<(Self, Delta)> {
let (sender, receiver) = mpsc::channel::<StoreCmd>(50);
@ -45,14 +45,15 @@ impl RevisionManager {
tokio::spawn(store.run());
let DocRevision { rev_id, delta } = fetch_document(sender.clone()).await?;
log::info!("😁Document delta: {:?}", delta);
let doc_id = doc_id.to_string();
let rev_id_counter = RevIdCounter::new(rev_id);
let rev_id_counter = RevIdCounter::new(rev_id.into());
let pending_revs = RwLock::new(VecDeque::new());
let manager = Self {
doc_id,
rev_id_counter,
ws: ws_sender,
ws,
pending_revs,
store: sender,
};
@ -83,7 +84,7 @@ impl RevisionManager {
Ok(())
}
pub fn ack_rev(&self, rev_id: i64) -> Result<(), DocError> {
pub fn ack_rev(&self, rev_id: RevId) -> Result<(), DocError> {
let sender = self.store.clone();
tokio::spawn(async move {
let _ = sender.send(StoreCmd::AckRevision { rev_id }).await;

View File

@ -1,21 +1,15 @@
use crate::{
entities::doc::{Doc, Revision, RevisionRange},
entities::doc::{RevId, Revision, RevisionRange},
errors::{internal_error, DocError, DocResult},
services::{
doc::revision::{util::RevisionOperation, DocRevision, RevisionServer},
server::Server,
},
sql_tables::{DocTableSql, RevChangeset, RevState, RevTableSql},
services::doc::revision::{util::RevisionOperation, DocRevision, RevisionServer},
sql_tables::{DocTableSql, RevState, RevTableSql},
};
use async_stream::stream;
use dashmap::DashMap;
use flowy_database::{ConnectionPool, SqliteConnection};
use flowy_ot::{
core::{Attributes, Delta, OperationTransformable},
errors::OTError,
};
use flowy_database::ConnectionPool;
use flowy_ot::core::{Attributes, Delta, OperationTransformable};
use futures::{stream::StreamExt, TryFutureExt};
use std::{cell::RefCell, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};
use tokio::{
sync::{mpsc, oneshot, RwLock},
task::{spawn_blocking, JoinHandle},
@ -26,7 +20,7 @@ pub enum StoreCmd {
revision: Revision,
},
AckRevision {
rev_id: i64,
rev_id: RevId,
},
SendRevisions {
range: RevisionRange,
@ -106,8 +100,8 @@ impl RevisionStore {
self.save_revisions().await;
}
async fn handle_revision_acked(&self, rev_id: i64) {
match self.revs.get_mut(&rev_id) {
async fn handle_revision_acked(&self, rev_id: RevId) {
match self.revs.get_mut(rev_id.as_ref()) {
None => {},
Some(mut rev) => rev.value_mut().finish(),
}
@ -194,7 +188,7 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc<Persistence>) -> DocRes
return Err(DocError::not_found());
}
let rev_id = revisions.last().unwrap().rev_id;
let rev_id: RevId = revisions.last().unwrap().rev_id.into();
let mut delta = Delta::new();
for revision in revisions {
match Delta::from_bytes(revision.delta_data) {
@ -282,7 +276,7 @@ impl Persistence {
// result
// }
// fn delete_revision(&self, rev_id: i64) {
// fn delete_revision(&self, rev_id: RevId) {
// let op_sql = self.op_sql.clone();
// let pool = self.pool.clone();
// let doc_id = self.doc_id.clone();

View File

@ -1,10 +1,5 @@
use crate::errors::DocError;
use byteorder::{BigEndian, ReadBytesExt};
use flowy_ot::core::{NEW_LINE, WHITESPACE};
use std::{
io::Cursor,
sync::atomic::{AtomicI64, Ordering::SeqCst},
};
use std::sync::atomic::{AtomicI64, Ordering::SeqCst};
#[inline]
pub fn find_newline(s: &str) -> Option<usize> {
@ -29,15 +24,6 @@ pub fn md5<T: AsRef<[u8]>>(data: T) -> String {
md5
}
#[inline]
pub fn bytes_to_rev_id(bytes: Vec<u8>) -> Result<i64, DocError> {
let mut rdr = Cursor::new(bytes);
match rdr.read_i64::<BigEndian>() {
Ok(rev_id) => Ok(rev_id),
Err(e) => Err(DocError::internal().context(e)),
}
}
#[derive(Debug)]
pub(crate) struct RevIdCounter(pub AtomicI64);

View File

@ -37,9 +37,9 @@ impl WsDocumentManager {
pub fn receive_data(&self, data: Bytes) {
let data: WsDocumentData = data.try_into().unwrap();
match self.ws_handlers.get(&data.id) {
match self.ws_handlers.get(&data.doc_id) {
None => {
log::error!("Can't find any source handler for {:?}", data.id);
log::error!("Can't find any source handler for {:?}", data.doc_id);
},
Some(handler) => {
handler.receive(data);

View File

@ -14,7 +14,7 @@ impl DocTable {
Self {
id: doc.id,
data: doc.data,
rev_id: 0,
rev_id: doc.rev_id.into(),
}
}
}
@ -32,7 +32,7 @@ impl std::convert::Into<Doc> for DocTable {
Doc {
id: self.id,
data: self.data,
rev_id: self.rev_id,
rev_id: self.rev_id.into(),
}
}
}
@ -42,7 +42,7 @@ impl std::convert::From<Doc> for DocTable {
Self {
id: doc.id,
data: doc.data,
rev_id: doc.rev_id,
rev_id: doc.rev_id.into(),
}
}
}

View File

@ -3,7 +3,7 @@ use crate::{
errors::DocError,
sql_tables::{doc::RevTable, RevChangeset, RevState, RevTableType},
};
use diesel::{insert_into, update};
use diesel::update;
use flowy_database::{
insert_or_ignore_into,
prelude::*,
@ -42,7 +42,7 @@ impl RevTableSql {
pub(crate) fn update_rev_table(&self, changeset: RevChangeset, conn: &SqliteConnection) -> Result<(), DocError> {
let filter = dsl::rev_table
.filter(rev_id.eq(changeset.rev_id))
.filter(rev_id.eq(changeset.rev_id.as_ref()))
.filter(doc_id.eq(changeset.doc_id));
let _ = update(filter).set(state.eq(changeset.state)).execute(conn)?;
log::debug!("Set {} to {:?}", changeset.rev_id, changeset.state);

View File

@ -1,5 +1,5 @@
use crate::{
entities::doc::{RevType, Revision},
entities::doc::{RevId, RevType, Revision},
services::util::md5,
};
use diesel::sql_types::Integer;
@ -110,6 +110,6 @@ impl_sql_integer_expression!(RevTableType);
#[allow(dead_code)]
pub(crate) struct RevChangeset {
pub(crate) doc_id: String,
pub(crate) rev_id: i64,
pub(crate) rev_id: RevId,
pub(crate) state: RevState,
}

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,4 +1,4 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod kv;
pub use kv::*;
mod kv;
pub use kv::*;

View File

@ -2,13 +2,13 @@ use crate::{config::HEADER_TOKEN, errors::ServerError, response::FlowyResponse};
use bytes::Bytes;
use hyper::http;
use protobuf::ProtobufError;
use reqwest::{header::HeaderMap, Client, Error, Method, Response};
use reqwest::{header::HeaderMap, Client, Method, Response};
use std::{
convert::{TryFrom, TryInto},
sync::Arc,
time::Duration,
};
use tokio::sync::{oneshot, oneshot::error::RecvError};
use tokio::sync::oneshot;
pub trait ResponseMiddleware {
fn receive_response(&self, token: &Option<String>, response: &FlowyResponse);

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,4 +1,4 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod subject;
pub use subject::*;
mod subject;
pub use subject::*;

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,19 +1,19 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod observable;
pub use observable::*;
mod observable;
pub use observable::*;
mod user_table;
pub use user_table::*;
mod user_table;
pub use user_table::*;
mod errors;
pub use errors::*;
mod errors;
pub use errors::*;
mod user_profile;
pub use user_profile::*;
mod user_profile;
pub use user_profile::*;
mod event;
pub use event::*;
mod event;
pub use event::*;
mod auth;
pub use auth::*;
mod auth;
pub use auth::*;

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,49 +1,49 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod view_update;
pub use view_update::*;
mod view_update;
pub use view_update::*;
mod view_delete;
pub use view_delete::*;
mod view_delete;
pub use view_delete::*;
mod app_query;
pub use app_query::*;
mod app_query;
pub use app_query::*;
mod workspace_delete;
pub use workspace_delete::*;
mod workspace_delete;
pub use workspace_delete::*;
mod observable;
pub use observable::*;
mod observable;
pub use observable::*;
mod errors;
pub use errors::*;
mod errors;
pub use errors::*;
mod workspace_update;
pub use workspace_update::*;
mod workspace_update;
pub use workspace_update::*;
mod app_create;
pub use app_create::*;
mod app_create;
pub use app_create::*;
mod workspace_query;
pub use workspace_query::*;
mod workspace_query;
pub use workspace_query::*;
mod event;
pub use event::*;
mod event;
pub use event::*;
mod view_create;
pub use view_create::*;
mod view_create;
pub use view_create::*;
mod workspace_user_detail;
pub use workspace_user_detail::*;
mod workspace_user_detail;
pub use workspace_user_detail::*;
mod workspace_create;
pub use workspace_create::*;
mod workspace_create;
pub use workspace_create::*;
mod app_update;
pub use app_update::*;
mod app_update;
pub use app_update::*;
mod view_query;
pub use view_query::*;
mod view_query;
pub use view_query::*;
mod app_delete;
pub use app_delete::*;
mod app_delete;
pub use app_delete::*;

View File

@ -1,2 +1,4 @@
mod model;
pub use model::*;

View File

@ -1,7 +1,7 @@
// Auto-generated, do not edit
// Auto-generated, do not edit
mod errors;
pub use errors::*;
mod errors;
pub use errors::*;
mod msg;
pub use msg::*;
mod msg;
pub use msg::*;