From 51a427496cc75dd17a6aefd53d9f363d03a25fc2 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Mon, 9 Jan 2023 15:09:49 +0800 Subject: [PATCH] fix: update octobase and fix type mismatching --- client-app/src-OctoBase | 2 +- client-app/src-tauri/Cargo.lock | 13 +++++++++++++ client-app/src-tauri/Cargo.toml | 2 +- client-app/src-tauri/src/commands/document.rs | 8 ++++---- client-app/src-tauri/src/commands/workspace.rs | 6 +++--- client-app/src-tauri/src/state.rs | 6 +++--- client-app/src-tauri/types/src/document.rs | 4 ++-- .../src/provider/tauri-ipc/ipc/types/document.json | 6 ++---- .../src/provider/tauri-ipc/ipc/types/document.ts | 4 ++-- 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/client-app/src-OctoBase b/client-app/src-OctoBase index d682a717e..f7f7eee84 160000 --- a/client-app/src-OctoBase +++ b/client-app/src-OctoBase @@ -1 +1 @@ -Subproject commit d682a717e37b1eb202224891340fb39d68d172db +Subproject commit f7f7eee8492a95509d237d64081e03669df2e31f diff --git a/client-app/src-tauri/Cargo.lock b/client-app/src-tauri/Cargo.lock index 393263659..8254c2f1c 100644 --- a/client-app/src-tauri/Cargo.lock +++ b/client-app/src-tauri/Cargo.lock @@ -1746,9 +1746,11 @@ dependencies = [ "base64 0.20.0", "bytes", "chrono", + "dotenvy", "futures", "jwst", "jwst-logger", + "path-ext", "serde", "serde_json", "serde_repr", @@ -1756,6 +1758,7 @@ dependencies = [ "sqlx", "tokio", "tokio-util", + "uuid 1.2.2", "yrs", ] @@ -2407,6 +2410,15 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +[[package]] +name = "path-ext" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8285c3c3c3085f8819bdcebc9c7e783851527f34974d7d283ced36c977ae812" +dependencies = [ + "walkdir", +] + [[package]] name = "pathdiff" version = "0.2.1" @@ -4363,6 +4375,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ "getrandom 0.2.8", + "rand 0.8.5", "serde", ] diff --git a/client-app/src-tauri/Cargo.toml b/client-app/src-tauri/Cargo.toml index 0ec16b033..eee60af6c 100644 --- a/client-app/src-tauri/Cargo.toml +++ b/client-app/src-tauri/Cargo.toml @@ -19,7 +19,7 @@ ipc_types = { path = "./types" } futures = "^0.3.25" js-sys = "0.3.60" jwst = { path = "../src-OctoBase/libs/jwst" } -jwst-storage = { path = "../src-OctoBase/libs/jwst-storage", features = ["sqlite"] } +jwst-storage = { path = "../src-OctoBase/libs/jwst-storage", features = ["sqlite", "server"] } lib0 = "0.12.0" project-root = "0.2.2" schemars = "0.8.3" diff --git a/client-app/src-tauri/src/commands/document.rs b/client-app/src-tauri/src/commands/document.rs index 79cc5f174..a28b9d439 100644 --- a/client-app/src-tauri/src/commands/document.rs +++ b/client-app/src-tauri/src/commands/document.rs @@ -17,7 +17,7 @@ pub async fn get_doc<'s>( .lock() .await .doc_storage - .get(parameters.id) + .get(parameters.id.clone()) .await .ok() { @@ -27,7 +27,7 @@ pub async fn get_doc<'s>( } else { Err(format!( "Failed to get yDoc from {}", - parameters.id.to_string() + parameters.id )) } } @@ -42,7 +42,7 @@ pub async fn update_y_document<'s>( .lock() .await .doc_storage - .write_update(parameters.id, ¶meters.update) + .write_update(parameters.id.clone(), ¶meters.update) .await .ok() { @@ -50,7 +50,7 @@ pub async fn update_y_document<'s>( } else { Err(format!( "Failed to update yDoc to {}", - parameters.id.to_string() + parameters.id )) } } diff --git a/client-app/src-tauri/src/commands/workspace.rs b/client-app/src-tauri/src/commands/workspace.rs index 9f745ab2c..112b62a9a 100644 --- a/client-app/src-tauri/src/commands/workspace.rs +++ b/client-app/src-tauri/src/commands/workspace.rs @@ -19,7 +19,7 @@ pub async fn create_workspace<'s>( .await { Ok(new_workspace) => { - let workspace_doc = OctoBaseWorkspace::new(new_workspace.id.to_string()); + let workspace_doc = OctoBaseWorkspace::new(new_workspace.id.clone()); workspace_doc.with_trx(|mut workspace_doc_transaction| { workspace_doc_transaction.set_metadata( @@ -32,13 +32,13 @@ pub async fn create_workspace<'s>( .lock() .await .doc_storage - .write_doc(new_workspace.id, workspace_doc.doc()) + .write_doc(new_workspace.id.clone(), workspace_doc.doc()) .await { Err(error_message.to_string()) } else { Ok(CreateWorkspaceResult { - id: new_workspace.id.to_string(), + id: new_workspace.id.clone(), name: parameters.name, }) } diff --git a/client-app/src-tauri/src/state.rs b/client-app/src-tauri/src/state.rs index 4e13ece01..3a4787de4 100644 --- a/client-app/src-tauri/src/state.rs +++ b/client-app/src-tauri/src/state.rs @@ -1,4 +1,4 @@ -use jwst_storage::{BlobFsStorage, DBContext, DocFsStorage}; +use jwst_storage::{BlobFsStorage, SqliteDBContext, DocFsStorage}; use std::path::Path; use tauri::api::path::document_dir; use tokio::sync::Mutex; @@ -6,7 +6,7 @@ use tokio::sync::Mutex; pub struct AppStateRaw { pub blob_storage: BlobFsStorage, pub doc_storage: DocFsStorage, - pub metadata_db: DBContext, + pub metadata_db: SqliteDBContext, } impl AppStateRaw { @@ -27,7 +27,7 @@ impl AppStateRaw { Some(Self { doc_storage: DocFsStorage::new(Some(16), 500, Path::new(&doc_env).into()).await, blob_storage: BlobFsStorage::new(Some(16), Path::new(&blob_env).into()).await, - metadata_db: DBContext::new(db_env).await, + metadata_db: SqliteDBContext::new(db_env).await, }) } } diff --git a/client-app/src-tauri/types/src/document.rs b/client-app/src-tauri/types/src/document.rs index c3be57eac..99ebb9679 100644 --- a/client-app/src-tauri/types/src/document.rs +++ b/client-app/src-tauri/types/src/document.rs @@ -4,12 +4,12 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct YDocumentUpdate { pub update: Vec, - pub id: i64, + pub id: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct GetDocumentParameter { - pub id: i64, + pub id: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] pub struct GetDocumentResponse { diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/document.json b/packages/data-center/src/provider/tauri-ipc/ipc/types/document.json index 49f8caae3..eaef4a27c 100644 --- a/packages/data-center/src/provider/tauri-ipc/ipc/types/document.json +++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/document.json @@ -39,8 +39,7 @@ "required": ["id"], "properties": { "id": { - "type": "integer", - "format": "int64" + "type": "string" } } }, @@ -63,8 +62,7 @@ "required": ["id", "update"], "properties": { "id": { - "type": "integer", - "format": "int64" + "type": "string" }, "update": { "type": "array", diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/document.ts b/packages/data-center/src/provider/tauri-ipc/ipc/types/document.ts index 9b652b6ce..71603490f 100644 --- a/packages/data-center/src/provider/tauri-ipc/ipc/types/document.ts +++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/document.ts @@ -17,12 +17,12 @@ export type IDocumentParameters = }; export interface YDocumentUpdate { - id: number; + id: string; update: number[]; [k: string]: unknown; } export interface GetDocumentParameter { - id: number; + id: string; [k: string]: unknown; } export interface GetDocumentResponse {