diff --git a/.idea/appflowy_client.iml b/.idea/appflowy_client.iml
index ee323030e9..12b5c938f9 100644
--- a/.idea/appflowy_client.iml
+++ b/.idea/appflowy_client.iml
@@ -7,6 +7,8 @@
+
+
diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index 06f3134367..1e952e4d5f 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -44,7 +44,6 @@
-
@@ -59,7 +58,6 @@
-
@@ -131,7 +129,6 @@
-
@@ -139,7 +136,6 @@
-
@@ -161,7 +157,6 @@
-
@@ -177,7 +172,6 @@
-
@@ -229,7 +223,6 @@
-
@@ -255,7 +248,6 @@
-
@@ -422,7 +414,6 @@
-
@@ -430,7 +421,6 @@
-
@@ -460,7 +450,6 @@
-
@@ -540,7 +529,6 @@
-
@@ -606,7 +594,6 @@
-
@@ -614,7 +601,6 @@
-
@@ -622,7 +608,6 @@
-
@@ -637,7 +622,6 @@
-
@@ -652,7 +636,6 @@
-
@@ -660,7 +643,6 @@
-
@@ -690,7 +672,6 @@
-
@@ -705,7 +686,6 @@
-
@@ -778,10 +758,8 @@
-
-
@@ -799,17 +777,13 @@
-
-
-
-
@@ -819,7 +793,6 @@
-
@@ -827,7 +800,6 @@
-
@@ -851,15 +823,12 @@
-
-
-
@@ -873,7 +842,6 @@
-
@@ -884,28 +852,20 @@
-
-
-
-
-
-
-
-
diff --git a/Makefile.toml b/Makefile.toml
new file mode 100644
index 0000000000..4f9fb3d977
--- /dev/null
+++ b/Makefile.toml
@@ -0,0 +1,75 @@
+extend = [
+ { path = "scripts/makefile/desktop.toml" },
+]
+
+[env]
+CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
+CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
+CARGO_MAKE_CRATE_NAME = "dart-ffi"
+DEV = true
+LIB_OUT_DIR = "debug"
+RELEASE = false
+TARGET_OS = "unknown"
+
+[tasks.setup-crate-type]
+private = true
+script = [
+ """
+ toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml
+ crate_type = set ""
+ os = get_env TARGET_OS
+ is_android = eq ${os} "android"
+ is_ios = eq ${os} "ios"
+ is_macos = eq ${os} "macos"
+ is_pad = eq ${os} "pad"
+
+ if ${is_android}
+ crate_type = set "cdylib"
+ elseif ${is_ios}
+ crate_type = set "staticlib"
+ elseif ${is_macos}
+ crate_type = set "cdylib"
+ elseif ${is_pad}
+ crate_type = set "cdylib"
+ else
+ crate_type = set "rlib"
+ end
+
+ val = replace ${toml} "rlib" ${crate_type}
+ result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml ${val}
+ assert ${result}
+ """,
+]
+script_runner = "@duckscript"
+
+
+[tasks.restore-crate-type]
+private = true
+script = [
+ """
+ toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml
+ crate_type = set ""
+ os = get_env TARGET_OS
+ is_android = eq ${os} "android"
+ is_ios = eq ${os} "ios"
+ is_macos = eq ${os} "macos"
+ is_pad = eq ${os} "pad"
+
+ if ${is_android}
+ crate_type = set "cdylib"
+ elseif ${is_ios}
+ crate_type = set "staticlib"
+ elseif ${is_macos}
+ crate_type = set "cdylib"
+ elseif ${is_pad}
+ crate_type = set "cdylib"
+ else
+ crate_type = set "rlib"
+ end
+
+ val = replace ${toml} ${crate_type} "rlib"
+ result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml ${val}
+ assert ${result}
+ """,
+]
+script_runner = "@duckscript"
\ No newline at end of file
diff --git a/app_flowy/macos/Podfile.lock b/app_flowy/macos/Podfile.lock
index ee4eff018c..2260813685 100644
--- a/app_flowy/macos/Podfile.lock
+++ b/app_flowy/macos/Podfile.lock
@@ -24,7 +24,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_size/macos
SPEC CHECKSUMS:
- flowy_sdk: 12d2c047ed260a0aa8788a0b9616da46e2312025
+ flowy_sdk: c302ac0a22dea596db0df8073b9637b2bf2ff6fd
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
path_provider_macos: a0a3fd666cb7cd0448e936fb4abad4052961002b
window_size: 339dafa0b27a95a62a843042038fa6c3c48de195
diff --git a/app_flowy/packages/flowy_sdk/ios/flowy_sdk.podspec b/app_flowy/packages/flowy_sdk/ios/flowy_sdk.podspec
index de720c906f..c38482c452 100644
--- a/app_flowy/packages/flowy_sdk/ios/flowy_sdk.podspec
+++ b/app_flowy/packages/flowy_sdk/ios/flowy_sdk.podspec
@@ -20,5 +20,5 @@ A new flutter plugin project.
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
- s.vendored_libraries = "libflowy_ffi.dylib"
+ s.vendored_libraries = "libdart_ffi.dylib"
end
diff --git a/app_flowy/packages/flowy_sdk/lib/cqrs/auto_gen.dart b/app_flowy/packages/flowy_sdk/lib/cqrs/auto_gen.dart
deleted file mode 100644
index 2296cc99f1..0000000000
--- a/app_flowy/packages/flowy_sdk/lib/cqrs/auto_gen.dart
+++ /dev/null
@@ -1,1328 +0,0 @@
-
-
-/// Auto gen code from rust ast, do not edit
-part of 'cqrs.dart';
-class WorkspaceCreateRequest {
- WorkspaceCreation body;
- WorkspaceCreateRequest(this.body);
- Future> send() {
- final command = Command.Workspace_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Workspace.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class WorkspaceDeleteRequest {
- IdentifiableEntity body;
- WorkspaceDeleteRequest(this.body);
- Future> send() {
- final command = Command.Workspace_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Workspace.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class WorkspaceUpdateRequest {
- WorkspaceChangeset body;
- WorkspaceUpdateRequest(this.body);
- Future> send() {
- final command = Command.Workspace_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Workspace.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class WorkspaceQueryRequest {
- WorkspaceQuery body;
- WorkspaceQueryRequest(this.body);
- Future> send() {
- final command = Command.Workspace_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = WorkspaceQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class ViewCreateRequest {
- ViewCreation body;
- ViewCreateRequest(this.body);
- Future> send() {
- final command = Command.View_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = ViewCreation.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class ViewDeleteRequest {
- IdentifiableEntity body;
- ViewDeleteRequest(this.body);
- Future> send() {
- final command = Command.View_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = View.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class ViewUpdateRequest {
- ViewChangeset body;
- ViewUpdateRequest(this.body);
- Future> send() {
- final command = Command.View_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = View.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class ViewQueryRequest {
- ViewQuery body;
- ViewQueryRequest(this.body);
- Future> send() {
- final command = Command.View_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = ViewQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class GridViewCreateRequest {
- GridViewCreation body;
- GridViewCreateRequest(this.body);
- Future> send() {
- final command = Command.Grid_View_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = GridViewCreationResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class ViewDisplayUpdateRequest {
- ViewDisplayChangeset body;
- ViewDisplayUpdateRequest(this.body);
- Future> send() {
- final command = Command.View_Display_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = ViewDisplay.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class TableCreateRequest {
- TableCreation body;
- TableCreateRequest(this.body);
- Future> send() {
- final command = Command.Table_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = TableCreation.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class TableDeleteRequest {
- IdentifiableEntity body;
- TableDeleteRequest(this.body);
- Future> send() {
- final command = Command.Table_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = FYTable.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class TableUpdateRequest {
- FYTableChangeset body;
- TableUpdateRequest(this.body);
- Future> send() {
- final command = Command.Table_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = FYTable.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class TableQueryRequest {
- TableQuery body;
- TableQueryRequest(this.body);
- Future> send() {
- final command = Command.Table_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = TableQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class RowCreateRequest {
- RowCreation body;
- RowCreateRequest(this.body);
- Future> send() {
- final command = Command.Row_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Row.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class RowDeleteRequest {
- IdentifiableEntity body;
- RowDeleteRequest(this.body);
- Future> send() {
- final command = Command.Row_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Row.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class RowUpdateRequest {
- RowChangeset body;
- RowUpdateRequest(this.body);
- Future> send() {
- final command = Command.Row_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Row.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class RowQueryRequest {
- RowQuery body;
- RowQueryRequest(this.body);
- Future> send() {
- final command = Command.Row_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = RowQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class FieldCreateRequest {
- FieldCreation body;
- FieldCreateRequest(this.body);
- Future> send() {
- final command = Command.Field_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Field.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class FieldDeleteRequest {
- IdentifiableEntity body;
- FieldDeleteRequest(this.body);
- Future> send() {
- final command = Command.Field_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Field.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class FieldUpdateRequest {
- FieldChangeset body;
- FieldUpdateRequest(this.body);
- Future> send() {
- final command = Command.Field_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Field.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class FieldQueryRequest {
- FieldQuery body;
- FieldQueryRequest(this.body);
- Future> send() {
- final command = Command.Field_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = FieldQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class AppCreateRequest {
- AppCreation body;
- AppCreateRequest(this.body);
- Future> send() {
- final command = Command.App_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = App.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class AppDeleteRequest {
- IdentifiableEntity body;
- AppDeleteRequest(this.body);
- Future> send() {
- final command = Command.App_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = App.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class AppUpdateRequest {
- AppChangeset body;
- AppUpdateRequest(this.body);
- Future> send() {
- final command = Command.App_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = App.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class AppQueryRequest {
- AppQuery body;
- AppQueryRequest(this.body);
- Future> send() {
- final command = Command.App_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = AppQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class CellCreateRequest {
- CellCreation body;
- CellCreateRequest(this.body);
- Future> send() {
- final command = Command.Cell_Create;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Cell.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class CellDeleteRequest {
- IdentifiableEntity body;
- CellDeleteRequest(this.body);
- Future> send() {
- final command = Command.Cell_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Cell.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class CellUpdateRequest {
- CellChangeset body;
- CellUpdateRequest(this.body);
- Future> send() {
- final command = Command.Cell_Update;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = Cell.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class CellQueryRequest {
- CellQuery body;
- CellQueryRequest(this.body);
- Future> send() {
- final command = Command.Cell_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = CellQueryResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserQueryRequest {
- Uint8List? body;
- UserQueryRequest();
- Future> send() {
- final command = Command.User_Query;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = UserQueryResult.fromBuffer(response.body);
- return left(pb);
- }
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
-
- });
- }
-}
-class UserCheckRequest {
- Uint8List? body;
- UserCheckRequest();
- Future> send() {
- final command = Command.User_Check;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = User.fromBuffer(response.body);
- return left(pb);
- }
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
-
- });
- }
-}
-class UserSignInRequest {
- UserSignIn body;
- UserSignInRequest(this.body);
- Future> send() {
- final command = Command.User_Sign_In;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = UserSignInResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserSignUpRequest {
- UserSignUp body;
- UserSignUpRequest(this.body);
- Future> send() {
- final command = Command.User_Sign_Up;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = UserSignUpResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserSignOutRequest {
- UserSignOut body;
- UserSignOutRequest(this.body);
- Future> send() {
- final command = Command.User_Sign_Out;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- return left(response);
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserActiveRequest {
- User body;
- UserActiveRequest(this.body);
- Future> send() {
- final command = Command.User_Active;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- return left(response);
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserMobileCodeRequest {
- VerificationCodeRequest body;
- UserMobileCodeRequest(this.body);
- Future> send() {
- final command = Command.User_Mobile_Code;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = VerificationCodeResponse.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class UserAuthInputRequest {
- UserAuthInput body;
- UserAuthInputRequest(this.body);
- Future> send() {
- final command = Command.User_Auth_Input;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = UserAuthInput.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class BucketSetRequest {
- BucketItem body;
- BucketSetRequest(this.body);
- Future> send() {
- final command = Command.Bucket_Set;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- return left(response);
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class BucketGetRequest {
- BucketItem body;
- BucketGetRequest(this.body);
- Future> send() {
- final command = Command.Bucket_Get;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncQuery(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = BucketItem.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class BucketDeleteRequest {
- BucketItem body;
- BucketDeleteRequest(this.body);
- Future> send() {
- final command = Command.Bucket_Delete;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- return left(response);
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
-class CSVImportRequest {
- FlowyResource body;
- CSVImportRequest(this.body);
- Future> send() {
- final command = Command.CSV_Import;
- var request = RequestPacket.create()
- ..command = command
- ..id = uuid();
- return protobufToBytes(body).fold(
- (req_bytes) {
- request.body = req_bytes;
- return asyncCommand(request).then((response) {
- try {
- if (response.hasErr()) {
- return right(FlowyError.from(response));
- } else {
- final pb = ShareResult.fromBuffer(response.body);
- return left(pb);
- }
-
- } catch (e, s) {
- final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
- return right(error);
- }
- });
- },
- (err) => Future(() {
- final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
- return right(error);
- }),
- );
- }
-}
diff --git a/app_flowy/packages/flowy_sdk/lib/cqrs/cqrs.dart b/app_flowy/packages/flowy_sdk/lib/cqrs/cqrs.dart
deleted file mode 100644
index feb88b3821..0000000000
--- a/app_flowy/packages/flowy_sdk/lib/cqrs/cqrs.dart
+++ /dev/null
@@ -1,55 +0,0 @@
-import 'package:dartz/dartz.dart';
-import 'package:flowy_protobuf/remote.dart';
-import 'package:infra/uuid.dart';
-import 'dart:typed_data';
-import 'package:flowy_protobuf/all.dart';
-import 'util.dart';
-
-part 'auto_gen.dart';
-
-class FlowyError {
- late StatusCode _statusCode;
- late String _error;
- late bool _has_error;
-
- StatusCode get statusCode {
- return _statusCode;
- }
-
- String get error {
- return _error;
- }
-
- bool get has_error {
- return _has_error;
- }
-
- String toString() {
- return "$_statusCode: $_error";
- }
-
- @override
- bool operator ==(other) {
- if (other is FlowyError) {
- return (this.statusCode == other.statusCode &&
- this._error == other._error);
- } else {
- return false;
- }
- }
-
- FlowyError({required StatusCode statusCode, required String error}) {
- _statusCode = statusCode;
- _error = error;
- _has_error = true;
- }
-
- factory FlowyError.from(ResponsePacket resp) {
- return FlowyError(statusCode: resp.statusCode, error: resp.err)
- .._has_error = resp.hasErr();
- }
-
- factory FlowyError.fromError(String error, StatusCode statusCode) {
- return FlowyError(statusCode: statusCode, error: error);
- }
-}
diff --git a/app_flowy/packages/flowy_sdk/lib/cqrs/util.dart b/app_flowy/packages/flowy_sdk/lib/cqrs/util.dart
deleted file mode 100644
index 076d36df18..0000000000
--- a/app_flowy/packages/flowy_sdk/lib/cqrs/util.dart
+++ /dev/null
@@ -1,77 +0,0 @@
-import 'package:dartz/dartz.dart';
-import 'package:flowy_protobuf/remote.dart';
-// ignore: import_of_legacy_library_into_null_safe
-import 'package:protobuf/protobuf.dart';
-import 'package:flowy_sdk/ffi/adaptor.dart';
-import 'dart:typed_data';
-import 'package:flowy_logger/flowy_logger.dart';
-
-Either protobufToBytes(
- T? message) {
- try {
- if (message != null) {
- return left(message.writeToBuffer());
- } else {
- return left(Uint8List.fromList([]));
- }
- } catch (e, s) {
- return right(
- 'FlowyFFI syncRequest error: ${e.runtimeType}. Stack trace: $s');
- }
-}
-
-Future asyncCommand(RequestPacket request) {
- try {
- return FFIAdaptor.asyncRequest(request).future.then((value) {
- try {
- final resp = ResponsePacket.fromBuffer(value);
- return Future.microtask(() => resp);
- } catch (e, s) {
- Log.error('FlowyFFI asyncRequest error: ${e.runtimeType}\n');
- Log.error('Stack trace \n $s');
- final resp = responseFromRequest(
- request, "FlowyFFI asyncRequest error: ${e.runtimeType}");
- return Future.microtask(() => resp);
- }
- });
- } catch (e, s) {
- Log.error('FlowyFFI asyncRequest error: ${e.runtimeType}\n');
- Log.error('Stack trace \n $s');
- final resp = responseFromRequest(
- request, "FlowyFFI asyncRequest error: ${e.runtimeType}");
- return Future.microtask(() => resp);
- }
-}
-
-Future asyncQuery(RequestPacket request) {
- try {
- return FFIAdaptor.asyncQuery(request).future.then((value) {
- try {
- final resp = ResponsePacket.fromBuffer(value);
- return Future.microtask(() => resp);
- } catch (e, s) {
- Log.error('FlowyFFI asyncRequest error: ${e.runtimeType}\n');
- Log.error('Stack trace \n $s');
- final resp = responseFromRequest(
- request, "FlowyFFI asyncRequest error: ${e.runtimeType}");
- return Future.microtask(() => resp);
- }
- });
- } catch (e, s) {
- Log.error('FlowyFFI asyncRequest error: ${e.runtimeType}\n');
- Log.error('Stack trace \n $s');
- final resp = responseFromRequest(
- request, "FlowyFFI asyncRequest error: ${e.runtimeType}");
- return Future.microtask(() => resp);
- }
-}
-
-ResponsePacket responseFromRequest(RequestPacket request, String message) {
- var resp = ResponsePacket();
- resp.id = request.id;
- resp.statusCode = StatusCode.Fail;
- resp.command = request.command;
- resp.err = message;
-
- return resp;
-}
diff --git a/app_flowy/packages/flowy_sdk/lib/ffi/adaptor.dart b/app_flowy/packages/flowy_sdk/lib/ffi/adaptor.dart
index c699f8dc2e..26face2e2d 100644
--- a/app_flowy/packages/flowy_sdk/lib/ffi/adaptor.dart
+++ b/app_flowy/packages/flowy_sdk/lib/ffi/adaptor.dart
@@ -42,88 +42,5 @@ class FFIAdaptor {
return completer;
}
-
- static Completer asyncQuery(RequestPacket request) {
- Uint8List bytes = request.writeToBuffer();
- assert(bytes.isEmpty == false);
- if (bytes.isEmpty) {
- throw FFIAdaptorException(FFIExceptionType.RequestPacketIsEmpty);
- }
-
- final Pointer input = calloc.allocate(bytes.length);
- final list = input.asTypedList(bytes.length);
- list.setAll(0, bytes);
-
- final completer = Completer();
- final port = singleCompletePort(completer);
- ffi.async_query(port.nativePort, input, bytes.length);
- calloc.free(input);
-
- return completer;
- }
-
- //https://suragch.medium.com/working-with-bytes-in-dart-6ece83455721
- static FFISafeUint8Wrapper syncRequest(RequestPacket request) {
- Uint8List bytes;
- try {
- bytes = request.writeToBuffer();
- } catch (e, s) {
- //TODO nathan: upload the log
- print('Sync RequestPacket writeToBuffer error: ${e.runtimeType}');
- print('Stack trace \n $s');
- rethrow;
- }
-
- assert(bytes.isEmpty == false);
- if (bytes.isEmpty) {
- throw FFIAdaptorException(FFIExceptionType.RequestPacketIsEmpty);
- }
-
- final Pointer dartPtr = _pointerFromBytes(bytes);
- Pointer rustPtr = ffi.sync_command(dartPtr, bytes.length);
- calloc.free(dartPtr);
- FFISafeUint8Wrapper safeWrapper;
- try {
- safeWrapper = FFISafeUint8Wrapper(rustPtr);
- } catch (_) {
- rethrow;
- }
- return safeWrapper;
- }
-
- // inline?
- static Pointer _pointerFromBytes(Uint8List bytes) {
- final Pointer ptr = calloc.allocate(bytes.length);
- final list = ptr.asTypedList(bytes.length);
- list.setAll(0, bytes);
- return ptr;
- }
}
-class FFISafeUint8Wrapper {
- Pointer _ptr;
- int _responseBytesLen = 0;
- int _markerBytesLen = 4;
- FFISafeUint8Wrapper(this._ptr) {
- try {
- this._responseBytesLen =
- ByteData.sublistView(_ptr.asTypedList(_markerBytesLen))
- .getUint32(0, Endian.big);
- } catch (_) {
- throw FFIAdaptorException(FFIExceptionType.RequestPacketIsEmpty);
- }
-
- if (this._responseBytesLen < _markerBytesLen) {
- throw FFIAdaptorException(FFIExceptionType.ResponsePacketIsInvalid);
- }
- }
-
- void destroy() {
- ffi.free_rust(_ptr, _responseBytesLen + _markerBytesLen);
- }
-
- Uint8List buffer() {
- Pointer respPtr = _ptr.elementAt(_markerBytesLen);
- return respPtr.asTypedList(_responseBytesLen);
- }
-}
diff --git a/app_flowy/packages/flowy_sdk/lib/ffi/ffi.dart b/app_flowy/packages/flowy_sdk/lib/ffi/ffi.dart
index e469b3535e..07ffbb89e6 100644
--- a/app_flowy/packages/flowy_sdk/lib/ffi/ffi.dart
+++ b/app_flowy/packages/flowy_sdk/lib/ffi/ffi.dart
@@ -1,4 +1,4 @@
-/// bindings for `libflowy_ffi`
+/// bindings for `libdart_ffi`
import 'dart:ffi';
import 'dart:io';
@@ -14,9 +14,9 @@ final DynamicLibrary dl = _dl;
DynamicLibrary _open() {
if (is_tester()) {
return DynamicLibrary.open(
- '${Directory.systemTemp.path}/app_flowy/libflowy_ffi.dylib');
+ '${Directory.systemTemp.path}/app_flowy/libdart_ffi.dylib');
} else {
- if (Platform.isAndroid) return DynamicLibrary.open('libflowy_ffi.so');
+ if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so');
if (Platform.isMacOS) return DynamicLibrary.executable();
if (Platform.isIOS) return DynamicLibrary.executable();
throw UnsupportedError('This platform is not supported.');
@@ -45,92 +45,6 @@ typedef _invoke_async_Dart = void Function(
int len,
);
-/// C function `command_sync`.
-Pointer sync_command(
- Pointer input,
- int len,
-) {
- return _invoke_sync(input, len);
-}
-
-final _invoke_sync_Dart _invoke_sync =
- _dl.lookupFunction<_invoke_sync_C, _invoke_sync_Dart>('sync_command');
-typedef _invoke_sync_C = Pointer Function(
- Pointer input,
- Uint64 len,
-);
-typedef _invoke_sync_Dart = Pointer Function(
- Pointer input,
- int len,
-);
-
-/// C function `async_query`.
-void async_query(
- int port,
- Pointer input,
- int len,
-) {
- _invoke_async_query(port, input, len);
-}
-
-final _invoke_async_query_Dart _invoke_async_query =
- _dl.lookupFunction<_invoke_async_query_C, _invoke_async_query_Dart>(
- 'async_query');
-typedef _invoke_async_query_C = Void Function(
- Int64 port,
- Pointer input,
- Uint64 len,
-);
-typedef _invoke_async_query_Dart = void Function(
- int port,
- Pointer input,
- int len,
-);
-
-/// C function `free_rust`.
-void free_rust(
- Pointer input,
- int len,
-) {
- _free_rust(input, len);
-}
-
-final _free_rust_Dart _free_rust =
- _dl.lookupFunction<_free_rust_C, _free_rust_Dart>('free_rust');
-typedef _free_rust_C = Void Function(
- Pointer input,
- Uint64 len,
-);
-typedef _free_rust_Dart = void Function(
- Pointer input,
- int len,
-);
-
-/// C function `init_stream`.
-int init_stream(int port) {
- return _init_stream(port);
-}
-
-final _init_stream_Dart _init_stream =
- _dl.lookupFunction<_init_stream_C, _init_stream_Dart>('init_stream');
-
-typedef _init_stream_C = Int32 Function(
- Int64 port,
-);
-typedef _init_stream_Dart = int Function(
- int port,
-);
-
-/// C function `init_logger`.
-int init_logger() {
- return _init_logger();
-}
-
-final _init_logger_Dart _init_logger =
- _dl.lookupFunction<_init_logger_C, _init_logger_Dart>('init_logger');
-typedef _init_logger_C = Int64 Function();
-typedef _init_logger_Dart = int Function();
-
/// C function `init_sdk`.
int init_sdk(
Pointer path,
@@ -174,22 +88,6 @@ typedef _store_dart_post_cobject_Dart = void Function(
Pointer)>> ptr,
);
-/// C function `setup_logger`.
-void setup_logger(
- Pointer ptr,
-) {
- _setup_logger(ptr);
-}
-
-final _setup_logger_Dart _setup_logger =
- _dl.lookupFunction<_setup_logger_C, _setup_logger_Dart>('setup_logger');
-typedef _setup_logger_C = Void Function(
- Pointer ptr,
-);
-typedef _setup_logger_Dart = void Function(
- Pointer ptr,
-);
-
bool is_tester() {
if (Foundation.kDebugMode) {
// ignore: unnecessary_null_comparison
diff --git a/app_flowy/packages/flowy_sdk/lib/ffi/rust_to_flutter_stream.dart b/app_flowy/packages/flowy_sdk/lib/ffi/rust_to_flutter_stream.dart
deleted file mode 100644
index a88a9b6d2a..0000000000
--- a/app_flowy/packages/flowy_sdk/lib/ffi/rust_to_flutter_stream.dart
+++ /dev/null
@@ -1,54 +0,0 @@
-import 'dart:isolate';
-import 'dart:async';
-import 'dart:typed_data';
-import 'dart:ffi';
-import 'package:flowy_logger/flowy_logger.dart';
-import 'package:flowy_protobuf/model/observable.pb.dart';
-
-typedef ObserverCallback = void Function(ObservableSubject observable);
-
-class R2FStream {
- static R2FStream shared = R2FStream._internal();
- late RawReceivePort _ffiPort;
- late StreamController _streamController;
- late StreamController _observableController;
- late StreamSubscription _ffiSubscription;
-
- int get port => _ffiPort.sendPort.nativePort;
- StreamController get observable => _observableController;
-
- R2FStream._internal() {
- _ffiPort = RawReceivePort();
- _streamController = StreamController();
- _observableController = StreamController.broadcast();
-
- _ffiPort.handler = _streamController.add;
- _ffiSubscription = _streamController.stream.listen(streamCallback);
- }
-
- factory R2FStream() {
- return shared;
- }
-
- static listen(void Function(ObservableSubject subject) callback) {
- R2FStream.shared.observable.stream.listen(callback);
- }
-
- void streamCallback(Uint8List bytes) {
- try {
- final observable = ObservableSubject.fromBuffer(bytes);
- _observableController.add(observable);
- } catch (e, s) {
- Log.error('FFIStream handleReceviedBytes error: ${e.runtimeType}');
- Log.error('Stack trace \n $s');
- rethrow;
- }
- }
-
- Future dispose() async {
- await _ffiSubscription.cancel();
- await _streamController.close();
- await _observableController.close();
- _ffiPort.close();
- }
-}
diff --git a/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart b/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart
index e1a1dc8524..5abe02caea 100644
--- a/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart
+++ b/app_flowy/packages/flowy_sdk/lib/flowy_sdk.dart
@@ -1,11 +1,9 @@
-export 'cqrs/cqrs.dart';
export 'package:async/async.dart';
import 'dart:io';
import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:ffi';
-import 'ffi/rust_to_flutter_stream.dart';
import 'ffi/ffi.dart' as ffi;
import 'package:ffi/ffi.dart';
@@ -19,16 +17,11 @@ class FlowySDK {
const FlowySDK();
void dispose() {
- R2FStream.shared.dispose();
+
}
Future init(Directory sdkDir) async {
- final port = R2FStream.shared.port;
- ffi.init_stream(port);
-
- ffi.init_logger();
ffi.store_dart_post_cobject(NativeApi.postCObject);
- print("Application document directory: ${sdkDir.absolute}");
ffi.init_sdk(sdkDir.path.toNativeUtf8());
}
}
diff --git a/app_flowy/packages/flowy_sdk/macos/Classes/binding.h b/app_flowy/packages/flowy_sdk/macos/Classes/binding.h
index 9ac0b90249..ac6bcf50e4 100644
--- a/app_flowy/packages/flowy_sdk/macos/Classes/binding.h
+++ b/app_flowy/packages/flowy_sdk/macos/Classes/binding.h
@@ -3,20 +3,9 @@
#include
#include
-int64_t init_logger();
int64_t init_sdk(char *path);
-int32_t init_stream(int64_t port);
-
void async_command(int64_t port, const uint8_t *input, uintptr_t len);
-void async_query(int64_t port, const uint8_t *input, uintptr_t len);
-
-const uint8_t *sync_command(const uint8_t *input, uintptr_t len);
-
-void free_rust(
- uint8_t *ptr,
- uint32_t length);
-
void link_me_please(void);
\ No newline at end of file
diff --git a/app_flowy/packages/flowy_sdk/macos/flowy_sdk.podspec b/app_flowy/packages/flowy_sdk/macos/flowy_sdk.podspec
index 79b009d92e..ff416e83fe 100644
--- a/app_flowy/packages/flowy_sdk/macos/flowy_sdk.podspec
+++ b/app_flowy/packages/flowy_sdk/macos/flowy_sdk.podspec
@@ -20,5 +20,5 @@ A new flutter plugin project.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
# s.static_framework = true
- s.vendored_libraries = "libflowy_ffi.dylib"
+ s.vendored_libraries = "libdart_ffi.dylib"
end
diff --git a/rust-lib/Cargo.toml b/rust-lib/Cargo.toml
index 456a79dcfe..5d0ec862f2 100644
--- a/rust-lib/Cargo.toml
+++ b/rust-lib/Cargo.toml
@@ -1,6 +1,8 @@
[workspace]
members = [
"flowy-sys",
+ "flowy-sdk",
+ "dart-ffi",
]
[profile.dev]
diff --git a/rust-lib/dart-ffi/Cargo.toml b/rust-lib/dart-ffi/Cargo.toml
new file mode 100644
index 0000000000..9ca697fef4
--- /dev/null
+++ b/rust-lib/dart-ffi/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "dart-ffi"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+[lib]
+name = "dart_ffi"
+# this value will change depending on the target os
+# for iOS it would be `rlib`
+# for Macos it would be `rlib`
+# for android it would be `c-dylib`
+# default rlib
+crate-type = ["rlib"]
+
+
+[dependencies]
+allo-isolate = {version = "^0.1", features = ["catch-unwind",]}
+byteorder = {version = "1.3.4"}
+ffi-support = {version = "0.4.2"}
+protobuf = {version = "2.20.0"}
+lazy_static = {version = "1.4.0"}
+tokio = { version = "1", features = ["sync"] }
+log = "0.4.14"
+
+flowy-sys = {path = "../flowy-sys"}
+flowy-sdk = {path = "../flowy-sdk"}
\ No newline at end of file
diff --git a/rust-lib/dart-ffi/binding.h b/rust-lib/dart-ffi/binding.h
new file mode 100644
index 0000000000..ac6bcf50e4
--- /dev/null
+++ b/rust-lib/dart-ffi/binding.h
@@ -0,0 +1,11 @@
+#include
+#include
+#include
+#include
+
+
+int64_t init_sdk(char *path);
+
+void async_command(int64_t port, const uint8_t *input, uintptr_t len);
+
+void link_me_please(void);
\ No newline at end of file
diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs
new file mode 100644
index 0000000000..19e3fa191c
--- /dev/null
+++ b/rust-lib/dart-ffi/src/lib.rs
@@ -0,0 +1,46 @@
+use flowy_sys::prelude::*;
+use std::{cell::RefCell, ffi::CStr, os::raw::c_char};
+
+#[no_mangle]
+pub extern "C" fn init_sdk(path: *mut c_char) -> i64 {
+ let c_str: &CStr = unsafe { CStr::from_ptr(path) };
+ let path: &str = c_str.to_str().unwrap();
+ println!("{}", path);
+ return 1;
+}
+
+#[no_mangle]
+pub extern "C" fn async_command(port: i64, input: *const u8, len: usize) {
+ let bytes = unsafe { std::slice::from_raw_parts(input, len) }.to_vec();
+ let request = EventRequest::from_data(bytes);
+
+ let stream_data = StreamData::new(port, Some(request)).with_callback(Box::new(|_config, response| {
+ log::info!("async resp: {:?}", response);
+ }));
+
+ async_send(stream_data);
+}
+
+#[inline(never)]
+#[no_mangle]
+pub extern "C" fn link_me_please() {}
+
+thread_local!(
+ static STREAM_SENDER: RefCell