From e9ee729b5d2542388c91126f9230f84ce4494462 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Mon, 9 Jan 2023 16:27:09 +0800 Subject: [PATCH] feat: getWorkspaces ipc --- client-app/scripts/buildSubModules.mjs | 2 +- client-app/src-OctoBase | 2 +- client-app/src-tauri/Cargo.lock | 2 + client-app/src-tauri/src/commands.rs | 1 + .../src-tauri/src/commands/workspace.rs | 25 ++++++- client-app/src-tauri/types/Cargo.toml | 1 + client-app/src-tauri/types/src/lib.rs | 1 + client-app/src-tauri/types/src/workspace.rs | 22 ++++-- packages/data-center/src/datacenter.ts | 1 - .../src/provider/tauri-ipc/ipc/methods.ts | 11 ++- .../tauri-ipc/ipc/types/workspace.json | 72 +++++++++++++++++++ .../provider/tauri-ipc/ipc/types/workspace.ts | 24 +++++++ 12 files changed, 155 insertions(+), 9 deletions(-) diff --git a/client-app/scripts/buildSubModules.mjs b/client-app/scripts/buildSubModules.mjs index 7edb08b986..9e5ed32ace 100644 --- a/client-app/scripts/buildSubModules.mjs +++ b/client-app/scripts/buildSubModules.mjs @@ -7,7 +7,7 @@ const repoDirectory = path.join(__dirname, '..'); const publicDistributionDirectory = path.join(repoDirectory, 'public'); -const octoBaseBranchName = 'master'; +const octoBaseBranchName = 'feat/jsonschema-for-types'; /** * 1. Until OctoBase become public, we link it using submodule too. */ diff --git a/client-app/src-OctoBase b/client-app/src-OctoBase index f7f7eee849..eb1826dbef 160000 --- a/client-app/src-OctoBase +++ b/client-app/src-OctoBase @@ -1 +1 @@ -Subproject commit f7f7eee8492a95509d237d64081e03669df2e31f +Subproject commit eb1826dbef56153f3ae3838ed2514a46e11756d7 diff --git a/client-app/src-tauri/Cargo.lock b/client-app/src-tauri/Cargo.lock index 8254c2f1ca..dc4dc06402 100644 --- a/client-app/src-tauri/Cargo.lock +++ b/client-app/src-tauri/Cargo.lock @@ -1599,6 +1599,7 @@ dependencies = [ name = "ipc_types" version = "0.1.0" dependencies = [ + "jwst-storage", "project-root", "schemars", "serde", @@ -1751,6 +1752,7 @@ dependencies = [ "jwst", "jwst-logger", "path-ext", + "schemars", "serde", "serde_json", "serde_repr", diff --git a/client-app/src-tauri/src/commands.rs b/client-app/src-tauri/src/commands.rs index c416b3b8e9..5848ba9fd6 100644 --- a/client-app/src-tauri/src/commands.rs +++ b/client-app/src-tauri/src/commands.rs @@ -11,6 +11,7 @@ pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static { update_y_document, create_workspace, update_workspace, + get_workspaces, get_doc, put_blob, get_blob diff --git a/client-app/src-tauri/src/commands/workspace.rs b/client-app/src-tauri/src/commands/workspace.rs index 112b62a9a8..37178a2020 100644 --- a/client-app/src-tauri/src/commands/workspace.rs +++ b/client-app/src-tauri/src/commands/workspace.rs @@ -1,9 +1,32 @@ -use ipc_types::workspace::{CreateWorkspace, CreateWorkspaceResult, UpdateWorkspace}; +use ipc_types::workspace::{ + CreateWorkspace, CreateWorkspaceResult, GetWorkspacesResult, UpdateWorkspace, +}; use jwst::{DocStorage, Workspace as OctoBaseWorkspace}; use lib0::any::Any; use crate::state::AppState; +#[tauri::command] +/// create yDoc for a workspace +pub async fn get_workspaces<'s>( + state: tauri::State<'s, AppState>, + parameters: CreateWorkspace, +) -> Result { + match &state + .0 + .lock() + .await + .metadata_db + .get_user_workspaces(parameters.user_id) + .await + { + Ok(user_workspaces) => Ok(GetWorkspacesResult { + workspaces: user_workspaces.clone(), + }), + Err(error_message) => Err(error_message.to_string()), + } +} + #[tauri::command] /// create yDoc for a workspace pub async fn create_workspace<'s>( diff --git a/client-app/src-tauri/types/Cargo.toml b/client-app/src-tauri/types/Cargo.toml index ae0e7867b5..f738609be8 100644 --- a/client-app/src-tauri/types/Cargo.toml +++ b/client-app/src-tauri/types/Cargo.toml @@ -3,6 +3,7 @@ name = "ipc_types" version = "0.1.0" [dependencies] +jwst-storage = { path = "../../src-OctoBase/libs/jwst-storage", features = ["sqlite", "server"] } project-root = "0.2.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/client-app/src-tauri/types/src/lib.rs b/client-app/src-tauri/types/src/lib.rs index d013c56e52..def441e017 100644 --- a/client-app/src-tauri/types/src/lib.rs +++ b/client-app/src-tauri/types/src/lib.rs @@ -1,6 +1,7 @@ #[allow(unused_imports)] extern crate serde; extern crate schemars; +extern crate jwst_storage; pub mod blob; pub mod document; diff --git a/client-app/src-tauri/types/src/workspace.rs b/client-app/src-tauri/types/src/workspace.rs index fd120d6a42..9b501f29a0 100644 --- a/client-app/src-tauri/types/src/workspace.rs +++ b/client-app/src-tauri/types/src/workspace.rs @@ -1,7 +1,8 @@ +use jwst_storage::model::WorkspaceWithPermission; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct CreateWorkspace { // TODO: make all id string, on Octobase side, and rewrite all related tests pub user_id: i32, @@ -11,21 +12,34 @@ pub struct CreateWorkspace { pub name: String, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] +pub struct GetWorkspaces { + // TODO: make all id string, on Octobase side, and rewrite all related tests + pub user_id: i32, +} + +#[derive(Debug, Clone, Serialize, JsonSchema)] pub struct CreateWorkspaceResult { pub id: String, pub name: String, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, JsonSchema)] +pub struct GetWorkspacesResult { + pub workspaces: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct UpdateWorkspace { pub id: i64, pub public: bool, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Clone, Serialize, JsonSchema)] pub enum IWorkspaceParameters { CreateWorkspace(CreateWorkspace), + GetWorkspaces(GetWorkspaces), + GetWorkspacesResult(GetWorkspacesResult), UpdateWorkspace(UpdateWorkspace), CreateWorkspaceResult(CreateWorkspaceResult), } diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts index 2f448307e4..b700e07dc4 100644 --- a/packages/data-center/src/datacenter.ts +++ b/packages/data-center/src/datacenter.ts @@ -48,7 +48,6 @@ export class DataCenter { new TauriIPCProvider({ logger: dc._logger, workspaces: dc._workspaces.createScope(), - blobs: dc._blobStorage, }) ); } diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts b/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts index 2fa482016b..b68f99293e 100644 --- a/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts +++ b/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts @@ -4,7 +4,12 @@ import { GetDocumentResponse, YDocumentUpdate, } from './types/document'; -import { CreateWorkspace, CreateWorkspaceResult } from './types/workspace'; +import { + CreateWorkspace, + CreateWorkspaceResult, + GetWorkspaces, + GetWorkspacesResult, +} from './types/workspace'; import { GetBlob, PutBlob } from './types/blob'; export const updateYDocument = async (parameters: YDocumentUpdate) => @@ -21,6 +26,10 @@ export const createWorkspace = async (parameters: CreateWorkspace) => await invoke('create_workspace', { parameters, }); +export const getWorkspaces = async (parameters: GetWorkspaces) => + await invoke('create_workspace', { + parameters, + }); export const putBlob = async (parameters: PutBlob) => await invoke('put_blob', { diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json index ea1a855958..aa1c6a40f3 100644 --- a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json +++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json @@ -12,6 +12,26 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": ["GetWorkspaces"], + "properties": { + "GetWorkspaces": { + "$ref": "#/definitions/GetWorkspaces" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": ["GetWorkspacesResult"], + "properties": { + "GetWorkspacesResult": { + "$ref": "#/definitions/GetWorkspacesResult" + } + }, + "additionalProperties": false + }, { "type": "object", "required": ["UpdateWorkspace"], @@ -60,6 +80,32 @@ } } }, + "GetWorkspaces": { + "type": "object", + "required": ["user_id"], + "properties": { + "user_id": { + "type": "integer", + "format": "int32" + } + } + }, + "GetWorkspacesResult": { + "type": "object", + "required": ["workspaces"], + "properties": { + "workspaces": { + "type": "array", + "items": { + "$ref": "#/definitions/WorkspaceWithPermission" + } + } + } + }, + "PermissionType": { + "type": "string", + "enum": ["Read", "Write", "Admin", "Owner"] + }, "UpdateWorkspace": { "type": "object", "required": ["id", "public"], @@ -72,6 +118,32 @@ "type": "boolean" } } + }, + "WorkspaceType": { + "type": "string", + "enum": ["Private", "Normal"] + }, + "WorkspaceWithPermission": { + "type": "object", + "required": ["created_at", "id", "permission", "public", "type"], + "properties": { + "created_at": { + "type": "integer", + "format": "int64" + }, + "id": { + "type": "string" + }, + "permission": { + "$ref": "#/definitions/PermissionType" + }, + "public": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/WorkspaceType" + } + } } } } diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts index 97918f736c..97d08ed90a 100644 --- a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts +++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts @@ -9,12 +9,20 @@ export type IWorkspaceParameters = | { CreateWorkspace: CreateWorkspace; } + | { + GetWorkspaces: GetWorkspaces; + } + | { + GetWorkspacesResult: GetWorkspacesResult; + } | { UpdateWorkspace: UpdateWorkspace; } | { CreateWorkspaceResult: CreateWorkspaceResult; }; +export type PermissionType = 'Read' | 'Write' | 'Admin' | 'Owner'; +export type WorkspaceType = 'Private' | 'Normal'; export interface CreateWorkspace { /** @@ -24,6 +32,22 @@ export interface CreateWorkspace { user_id: number; [k: string]: unknown; } +export interface GetWorkspaces { + user_id: number; + [k: string]: unknown; +} +export interface GetWorkspacesResult { + workspaces: WorkspaceWithPermission[]; + [k: string]: unknown; +} +export interface WorkspaceWithPermission { + created_at: number; + id: string; + permission: PermissionType; + public: boolean; + type: WorkspaceType; + [k: string]: unknown; +} export interface UpdateWorkspace { id: number; public: boolean;