feat: getWorkspaces ipc

This commit is contained in:
linonetwo 2023-01-09 16:27:09 +08:00
parent a409009d65
commit e9ee729b5d
12 changed files with 155 additions and 9 deletions

View File

@ -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.
*/

@ -1 +1 @@
Subproject commit f7f7eee8492a95509d237d64081e03669df2e31f
Subproject commit eb1826dbef56153f3ae3838ed2514a46e11756d7

View File

@ -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",

View File

@ -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

View File

@ -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<GetWorkspacesResult, String> {
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>(

View File

@ -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"

View File

@ -1,6 +1,7 @@
#[allow(unused_imports)]
extern crate serde;
extern crate schemars;
extern crate jwst_storage;
pub mod blob;
pub mod document;

View File

@ -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<WorkspaceWithPermission>,
}
#[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),
}

View File

@ -48,7 +48,6 @@ export class DataCenter {
new TauriIPCProvider({
logger: dc._logger,
workspaces: dc._workspaces.createScope(),
blobs: dc._blobStorage,
})
);
}

View File

@ -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<CreateWorkspaceResult>('create_workspace', {
parameters,
});
export const getWorkspaces = async (parameters: GetWorkspaces) =>
await invoke<GetWorkspacesResult>('create_workspace', {
parameters,
});
export const putBlob = async (parameters: PutBlob) =>
await invoke<string>('put_blob', {

View File

@ -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"
}
}
}
}
}

View File

@ -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;