diff --git a/apps/android/app/src/main/java/com/example/jwst_demo/MainActivity.kt b/apps/android/app/src/main/java/com/example/jwst_demo/MainActivity.kt index 62715036..6a6fe3ae 100644 --- a/apps/android/app/src/main/java/com/example/jwst_demo/MainActivity.kt +++ b/apps/android/app/src/main/java/com/example/jwst_demo/MainActivity.kt @@ -40,9 +40,14 @@ class MainActivity : AppCompatActivity() { val database = File(filesDir, "jwst.db") val storage = Storage(database.absolutePath, "ws://10.0.2.2:3000/collaboration", "debug") - storage.initWorkspace(getRandomId(), getStaticWorkspace().hexStringToByteArray()) - val text = storage.getWorkspace("test1").get().get("test").get().get("test").get() + val randomId = getRandomId() + storage.initWorkspace(randomId, getStaticWorkspace().hexStringToByteArray()) + val text = storage.getWorkspace(randomId).get().get("test").get().get("test").get() Log.i("jwst", "text: $text") + storage.exportWorkspace(randomId).getOrNull()?.let { data -> + val isSame = data.contentEquals(getStaticWorkspace().hexStringToByteArray()) + Log.i("jwst", "exported data: $isSame") + } storage.getWorkspace("test").unwrap()?.let { workspace -> setupWorkspace(workspace) diff --git a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/Info.plist b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/Info.plist index 1809eda0..9bf2c5d0 100644 --- a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/Info.plist +++ b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/Info.plist @@ -26,7 +26,7 @@ HeadersPath Headers LibraryIdentifier - ios-arm64 + ios-arm64-simulator LibraryPath liboctobase.a SupportedArchitectures @@ -35,6 +35,8 @@ SupportedPlatform ios + SupportedPlatformVariant + simulator BinaryPath @@ -42,7 +44,7 @@ HeadersPath Headers LibraryIdentifier - ios-arm64-simulator + ios-arm64 LibraryPath liboctobase.a SupportedArchitectures @@ -51,8 +53,6 @@ SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64-simulator/Headers/jwst-swift.h b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64-simulator/Headers/jwst-swift.h index 98c97d3a..18792a98 100644 --- a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64-simulator/Headers/jwst-swift.h +++ b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64-simulator/Headers/jwst-swift.h @@ -122,8 +122,8 @@ bool __swift_bridge__$Storage$is_connected(void* self); bool __swift_bridge__$Storage$is_finished(void* self); bool __swift_bridge__$Storage$is_error(void* self); void* __swift_bridge__$Storage$get_sync_state(void* self); -bool __swift_bridge__$Storage$init(void* self, void* workspace_id, void* data); -void* __swift_bridge__$Storage$export(void* self, void* workspace_id); +bool __swift_bridge__$Storage$import_workspace(void* self, void* workspace_id, void* data); +void* __swift_bridge__$Storage$export_workspace(void* self, void* workspace_id); void* __swift_bridge__$Storage$connect(void* self, void* workspace_id, void* remote); void* __swift_bridge__$Storage$get_last_synced(void* self); diff --git a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64/Headers/jwst-swift.h b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64/Headers/jwst-swift.h index 98c97d3a..18792a98 100644 --- a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64/Headers/jwst-swift.h +++ b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/ios-arm64/Headers/jwst-swift.h @@ -122,8 +122,8 @@ bool __swift_bridge__$Storage$is_connected(void* self); bool __swift_bridge__$Storage$is_finished(void* self); bool __swift_bridge__$Storage$is_error(void* self); void* __swift_bridge__$Storage$get_sync_state(void* self); -bool __swift_bridge__$Storage$init(void* self, void* workspace_id, void* data); -void* __swift_bridge__$Storage$export(void* self, void* workspace_id); +bool __swift_bridge__$Storage$import_workspace(void* self, void* workspace_id, void* data); +void* __swift_bridge__$Storage$export_workspace(void* self, void* workspace_id); void* __swift_bridge__$Storage$connect(void* self, void* workspace_id, void* remote); void* __swift_bridge__$Storage$get_last_synced(void* self); diff --git a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/macos-arm64/Headers/jwst-swift.h b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/macos-arm64/Headers/jwst-swift.h index 98c97d3a..18792a98 100644 --- a/apps/swift/OctoBaseSwift/RustXcframework.xcframework/macos-arm64/Headers/jwst-swift.h +++ b/apps/swift/OctoBaseSwift/RustXcframework.xcframework/macos-arm64/Headers/jwst-swift.h @@ -122,8 +122,8 @@ bool __swift_bridge__$Storage$is_connected(void* self); bool __swift_bridge__$Storage$is_finished(void* self); bool __swift_bridge__$Storage$is_error(void* self); void* __swift_bridge__$Storage$get_sync_state(void* self); -bool __swift_bridge__$Storage$init(void* self, void* workspace_id, void* data); -void* __swift_bridge__$Storage$export(void* self, void* workspace_id); +bool __swift_bridge__$Storage$import_workspace(void* self, void* workspace_id, void* data); +void* __swift_bridge__$Storage$export_workspace(void* self, void* workspace_id); void* __swift_bridge__$Storage$connect(void* self, void* workspace_id, void* remote); void* __swift_bridge__$Storage$get_last_synced(void* self); diff --git a/apps/swift/OctoBaseSwift/Sources/OctoBase/jwst-swift.swift b/apps/swift/OctoBaseSwift/Sources/OctoBase/jwst-swift.swift index 98decd0d..2cbb9c22 100644 --- a/apps/swift/OctoBaseSwift/Sources/OctoBase/jwst-swift.swift +++ b/apps/swift/OctoBaseSwift/Sources/OctoBase/jwst-swift.swift @@ -578,12 +578,12 @@ public class StorageRefMut: StorageRef { } } extension StorageRefMut { - public func init(_ workspace_id: GenericIntoRustString, _ data: RustVec) -> Bool { - __swift_bridge__$Storage$init(ptr, { let rustString = workspace_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let val = data; val.isOwned = false; return val.ptr }()) + public func import_workspace(_ workspace_id: GenericIntoRustString, _ data: RustVec) -> Bool { + __swift_bridge__$Storage$import_workspace(ptr, { let rustString = workspace_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let val = data; val.isOwned = false; return val.ptr }()) } - public func export(_ workspace_id: GenericIntoRustString) -> Optional> { - { let val = __swift_bridge__$Storage$export(ptr, { let rustString = workspace_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { return RustVec(ptr: val!) } else { return nil } }() + public func export_workspace(_ workspace_id: GenericIntoRustString) -> Optional> { + { let val = __swift_bridge__$Storage$export_workspace(ptr, { let rustString = workspace_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val != nil { return RustVec(ptr: val!) } else { return nil } }() } public func connect(_ workspace_id: GenericIntoRustString, _ remote: GenericIntoRustString) -> Optional { diff --git a/libs/jwst-binding/jwst-jni/android/build.gradle b/libs/jwst-binding/jwst-jni/android/build.gradle index 3e664058..195ea74d 100644 --- a/libs/jwst-binding/jwst-jni/android/build.gradle +++ b/libs/jwst-binding/jwst-jni/android/build.gradle @@ -117,7 +117,7 @@ publishing { release(MavenPublication) { groupId = 'com.toeverything' artifactId = 'octobase' - version = '0.2.7' + version = '0.2.8' afterEvaluate { from components.release diff --git a/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/JWST.kt b/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/JWST.kt index 3a9ee62f..d06aa383 100644 --- a/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/JWST.kt +++ b/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/JWST.kt @@ -183,7 +183,7 @@ class Storage constructor(path: String, private val remote: String = "", private val error get() = this.storage.error() fun initWorkspace(id: String, data: ByteArray): Result { - val success = this.storage.init(id,data) + val success = this.storage.import_workspace(id,data) return if (success) { Result.success(Unit) } else { @@ -193,7 +193,7 @@ class Storage constructor(path: String, private val remote: String = "", private } fun exportWorkspace(id: String): Result { - val data = this.storage.export(id) + val data = this.storage.export_workspace(id) return if (data.isNotEmpty()) { Result.success(data) } else { diff --git a/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/lib/JwstStorage.java b/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/lib/JwstStorage.java index 0e776e38..c3032a94 100644 --- a/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/lib/JwstStorage.java +++ b/libs/jwst-binding/jwst-jni/android/src/main/java/com/toeverything/jwst/lib/JwstStorage.java @@ -58,19 +58,19 @@ public final boolean is_error() { } private static native @NonNull String do_get_sync_state(long self); - public final boolean import(@NonNull String workspace_id, @NonNull byte [] data) { - boolean ret = do_import(mNativeObj, workspace_id, data); + public final boolean import_workspace(@NonNull String workspace_id, @NonNull byte [] data) { + boolean ret = do_import_workspace(mNativeObj, workspace_id, data); return ret; } - private static native boolean do_import(long self, @NonNull String workspace_id, byte [] data); + private static native boolean do_import_workspace(long self, @NonNull String workspace_id, byte [] data); - public final byte [] export(@NonNull String workspace_id) { - byte [] ret = do_export(mNativeObj, workspace_id); + public final byte [] export_workspace(@NonNull String workspace_id) { + byte [] ret = do_export_workspace(mNativeObj, workspace_id); return ret; } - private static native byte [] do_export(long self, @NonNull String workspace_id); + private static native byte [] do_export_workspace(long self, @NonNull String workspace_id); public final @NonNull java.util.Optional connect(@NonNull String workspace_id, @NonNull String remote) { long ret = do_connect(mNativeObj, workspace_id, remote); diff --git a/libs/jwst-binding/jwst-jni/build.rs b/libs/jwst-binding/jwst-jni/build.rs index a8507f8e..7bda352e 100644 --- a/libs/jwst-binding/jwst-jni/build.rs +++ b/libs/jwst-binding/jwst-jni/build.rs @@ -56,8 +56,8 @@ foreign_typemap!( fn JwstStorage::is_finished(&self) -> bool; fn JwstStorage::is_error(&self) -> bool; fn JwstStorage::get_sync_state(&self) -> String; - fn JwstStorage::import(&mut self, workspace_id: String, data: &[u8]) -> bool; alias import; - fn JwstStorage::export(&mut self, workspace_id: String) -> Vec; alias export; + fn JwstStorage::import_workspace(&mut self, workspace_id: String, data: &[u8]) -> bool; alias import_workspace; + fn JwstStorage::export_workspace(&mut self, workspace_id: String) -> Vec; alias export_workspace; fn JwstStorage::connect(&mut self, workspace_id: String, remote: String) -> Option; alias connect; fn JwstStorage::get_last_synced(&self) ->Vec; } diff --git a/libs/jwst-binding/jwst-jni/src/java_glue.rs.in b/libs/jwst-binding/jwst-jni/src/java_glue.rs.in index b10ccdf6..6b5c4cd2 100644 --- a/libs/jwst-binding/jwst-jni/src/java_glue.rs.in +++ b/libs/jwst-binding/jwst-jni/src/java_glue.rs.in @@ -39,8 +39,8 @@ foreign_class!( fn JwstStorage::is_finished(&self) -> bool; fn JwstStorage::is_error(&self) -> bool; fn JwstStorage::get_sync_state(&self) -> String; - fn JwstStorage::import(&mut self, workspace_id: String, data: &[u8]) -> bool; alias import; - fn JwstStorage::export(&mut self, workspace_id: String) -> Vec; alias export; + fn JwstStorage::import_workspace(&mut self, workspace_id: String, data: &[u8]) -> bool; alias import_workspace; + fn JwstStorage::export_workspace(&mut self, workspace_id: String) -> Vec; alias export_workspace; fn JwstStorage::connect(&mut self, workspace_id: String, remote: String) -> Option; alias connect; fn JwstStorage::get_last_synced(&self) ->Vec; } diff --git a/libs/jwst-binding/jwst-jni/src/storage.rs b/libs/jwst-binding/jwst-jni/src/storage.rs index e364f82c..08e6b1b0 100644 --- a/libs/jwst-binding/jwst-jni/src/storage.rs +++ b/libs/jwst-binding/jwst-jni/src/storage.rs @@ -91,8 +91,8 @@ impl JwstStorage { } } - pub fn import(&mut self, workspace_id: String, data: &[u8]) -> bool { - match self.import_workspace(workspace_id, data) { + pub fn import_workspace(&mut self, workspace_id: String, data: &[u8]) -> bool { + match self.import_workspace_inner(workspace_id, data) { Ok(_) => true, Err(e) => { let error = format!("Failed to init workspace: {:?}", e); @@ -103,7 +103,7 @@ impl JwstStorage { } } - fn import_workspace(&self, workspace_id: String, data: &[u8]) -> JwstStorageResult { + fn import_workspace_inner(&self, workspace_id: String, data: &[u8]) -> JwstStorageResult { let rt = Arc::new( Builder::new_multi_thread() .worker_threads(1) @@ -115,8 +115,8 @@ impl JwstStorage { rt.block_on(self.storage.init_workspace(workspace_id, data.to_vec())) } - pub fn export(&mut self, workspace_id: String) -> Vec { - match self.export_workspace(workspace_id) { + pub fn export_workspace(&mut self, workspace_id: String) -> Vec { + match self.export_workspace_inner(workspace_id) { Ok(data) => data, Err(e) => { let error = format!("Failed to export workspace: {:?}", e); @@ -127,7 +127,7 @@ impl JwstStorage { } } - fn export_workspace(&self, workspace_id: String) -> JwstStorageResult> { + fn export_workspace_inner(&self, workspace_id: String) -> JwstStorageResult> { let rt = Arc::new( Builder::new_multi_thread() .worker_threads(1) @@ -165,7 +165,6 @@ impl JwstStorage { match workspace { Ok(mut workspace) => { - warn!("is_offline: {}, remote: {}", is_offline, remote); if is_offline { let identifier = nanoid!(); let (last_synced_tx, last_synced_rx) = channel::(128); diff --git a/libs/jwst-binding/jwst-swift/src/lib.rs b/libs/jwst-binding/jwst-swift/src/lib.rs index 74634e57..466e149b 100644 --- a/libs/jwst-binding/jwst-swift/src/lib.rs +++ b/libs/jwst-binding/jwst-swift/src/lib.rs @@ -134,9 +134,9 @@ mod ffi { fn get_sync_state(self: &Storage) -> String; - fn import(self: &mut Storage, workspace_id: String, data: Vec) -> bool; + fn import_workspace(self: &mut Storage, workspace_id: String, data: Vec) -> bool; - fn export(self: &mut Storage, workspace_id: String) -> Option>; + fn export_workspace(self: &mut Storage, workspace_id: String) -> Option>; fn connect(self: &mut Storage, workspace_id: String, remote: String) -> Option; diff --git a/libs/jwst-binding/jwst-swift/src/storage.rs b/libs/jwst-binding/jwst-swift/src/storage.rs index 704704d4..39a36e23 100644 --- a/libs/jwst-binding/jwst-swift/src/storage.rs +++ b/libs/jwst-binding/jwst-swift/src/storage.rs @@ -88,8 +88,8 @@ impl Storage { } } - pub fn import(&mut self, workspace_id: String, data: Vec) -> bool { - match self.import_workspace(workspace_id, data) { + pub fn import_workspace(&mut self, workspace_id: String, data: Vec) -> bool { + match self.import_workspace_inner(workspace_id, data) { Ok(_) => true, Err(e) => { let error = format!("Failed to init workspace: {:?}", e); @@ -100,7 +100,7 @@ impl Storage { } } - fn import_workspace(&self, workspace_id: String, data: Vec) -> JwstStorageResult { + fn import_workspace_inner(&self, workspace_id: String, data: Vec) -> JwstStorageResult { let rt = Arc::new( Builder::new_multi_thread() .worker_threads(1) @@ -112,8 +112,8 @@ impl Storage { rt.block_on(self.storage.init_workspace(workspace_id, data)) } - pub fn export(&mut self, workspace_id: String) -> Option> { - match self.export_workspace(workspace_id) { + pub fn export_workspace(&mut self, workspace_id: String) -> Option> { + match self.export_workspace_inner(workspace_id) { Ok(data) => Some(data), Err(e) => { let error = format!("Failed to export workspace: {:?}", e); @@ -124,7 +124,7 @@ impl Storage { } } - fn export_workspace(&self, workspace_id: String) -> JwstStorageResult> { + fn export_workspace_inner(&self, workspace_id: String) -> JwstStorageResult> { let rt = Arc::new( Builder::new_multi_thread() .worker_threads(1) @@ -133,7 +133,10 @@ impl Storage { .build() .map_err(JwstStorageError::SyncThread)?, ); - rt.block_on(self.storage.export_workspace(workspace_id)) + let workspace = rt.block_on(async { self.get_workspace(&workspace_id).await })?; + let binary = workspace.to_binary()?; + + Ok(binary) } pub fn connect(&mut self, workspace_id: String, remote: String) -> Option {