mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 15:09:45 +02:00
Websocket Support (#159)
This commit is contained in:
@@ -21,4 +21,4 @@ tokio = { version = "1.42.0", features = ["fs", "sync", "macros"] }
|
||||
notify = "7.0.0"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { version = "2.0.3", features = ["build"] }
|
||||
tauri-plugin = { workspace = true, features = ["build"] }
|
||||
|
||||
@@ -16,8 +16,10 @@ export type HttpRequestHeader = { enabled?: boolean, name: string, value: string
|
||||
|
||||
export type HttpUrlParameter = { enabled?: boolean, name: string, value: string, id?: string, };
|
||||
|
||||
export type SyncModel = { "type": "workspace" } & Workspace | { "type": "environment" } & Environment | { "type": "folder" } & Folder | { "type": "http_request" } & HttpRequest | { "type": "grpc_request" } & GrpcRequest;
|
||||
export type SyncModel = { "type": "workspace" } & Workspace | { "type": "environment" } & Environment | { "type": "folder" } & Folder | { "type": "http_request" } & HttpRequest | { "type": "grpc_request" } & GrpcRequest | { "type": "websocket_request" } & WebsocketRequest;
|
||||
|
||||
export type SyncState = { model: "sync_state", id: string, workspaceId: string, createdAt: string, updatedAt: string, flushedAt: string, modelId: string, checksum: string, relPath: string, syncDir: string, };
|
||||
|
||||
export type WebsocketRequest = { model: "websocket_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, message: string, name: string, sortPriority: number, url: string, urlParameters: Array<HttpUrlParameter>, };
|
||||
|
||||
export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, name: string, description: string, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, };
|
||||
|
||||
@@ -6,7 +6,9 @@ use sha1::{Digest, Sha1};
|
||||
use std::path::Path;
|
||||
use tokio::fs;
|
||||
use ts_rs::TS;
|
||||
use yaak_models::models::{AnyModel, Environment, Folder, GrpcRequest, HttpRequest, Workspace};
|
||||
use yaak_models::models::{
|
||||
AnyModel, Environment, Folder, GrpcRequest, HttpRequest, WebsocketRequest, Workspace,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
@@ -17,6 +19,7 @@ pub enum SyncModel {
|
||||
Folder(Folder),
|
||||
HttpRequest(HttpRequest),
|
||||
GrpcRequest(GrpcRequest),
|
||||
WebsocketRequest(WebsocketRequest),
|
||||
}
|
||||
|
||||
impl SyncModel {
|
||||
@@ -62,6 +65,7 @@ impl SyncModel {
|
||||
SyncModel::Folder(m) => m.id,
|
||||
SyncModel::HttpRequest(m) => m.id,
|
||||
SyncModel::GrpcRequest(m) => m.id,
|
||||
SyncModel::WebsocketRequest(m) => m.id,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +76,7 @@ impl SyncModel {
|
||||
SyncModel::Folder(m) => m.workspace_id,
|
||||
SyncModel::HttpRequest(m) => m.workspace_id,
|
||||
SyncModel::GrpcRequest(m) => m.workspace_id,
|
||||
SyncModel::WebsocketRequest(m) => m.workspace_id,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +87,7 @@ impl SyncModel {
|
||||
SyncModel::Folder(m) => m.updated_at,
|
||||
SyncModel::HttpRequest(m) => m.updated_at,
|
||||
SyncModel::GrpcRequest(m) => m.updated_at,
|
||||
SyncModel::WebsocketRequest(m) => m.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,15 +101,20 @@ impl TryFrom<AnyModel> for SyncModel {
|
||||
AnyModel::Folder(m) => SyncModel::Folder(m),
|
||||
AnyModel::GrpcRequest(m) => SyncModel::GrpcRequest(m),
|
||||
AnyModel::HttpRequest(m) => SyncModel::HttpRequest(m),
|
||||
AnyModel::WebsocketRequest(m) => SyncModel::WebsocketRequest(m),
|
||||
AnyModel::Workspace(m) => SyncModel::Workspace(m),
|
||||
AnyModel::WorkspaceMeta(m) => return Err(UnknownModel(m.model)),
|
||||
|
||||
// Non-sync models
|
||||
AnyModel::CookieJar(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::GrpcConnection(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::GrpcEvent(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::HttpResponse(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::KeyValue(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::Plugin(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::Settings(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::KeyValue(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::WebsocketConnection(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::WebsocketEvent(m) => return Err(UnknownModel(m.model)),
|
||||
AnyModel::WorkspaceMeta(m) => return Err(UnknownModel(m.model)),
|
||||
};
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ use ts_rs::TS;
|
||||
use yaak_models::models::{SyncState, WorkspaceMeta};
|
||||
use yaak_models::queries::{
|
||||
batch_upsert, delete_environment, delete_folder, delete_grpc_request, delete_http_request,
|
||||
delete_sync_state, delete_workspace, get_workspace_export_resources, get_workspace_meta,
|
||||
list_sync_states_for_workspace, upsert_sync_state, upsert_workspace_meta, UpdateSource,
|
||||
delete_sync_state, delete_websocket_request, delete_workspace, get_workspace_export_resources,
|
||||
get_workspace_meta, list_sync_states_for_workspace, upsert_sync_state, upsert_workspace_meta,
|
||||
UpdateSource,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
@@ -296,6 +297,9 @@ async fn workspace_models<R: Runtime>(
|
||||
for m in resources.grpc_requests {
|
||||
sync_models.push(SyncModel::GrpcRequest(m));
|
||||
}
|
||||
for m in resources.websocket_requests {
|
||||
sync_models.push(SyncModel::WebsocketRequest(m));
|
||||
}
|
||||
|
||||
Ok(sync_models)
|
||||
}
|
||||
@@ -320,6 +324,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
let mut folders_to_upsert = Vec::new();
|
||||
let mut http_requests_to_upsert = Vec::new();
|
||||
let mut grpc_requests_to_upsert = Vec::new();
|
||||
let mut websocket_requests_to_upsert = Vec::new();
|
||||
|
||||
for op in sync_ops {
|
||||
// Only apply things if workspace ID matches
|
||||
@@ -381,6 +386,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
SyncModel::Folder(m) => folders_to_upsert.push(m),
|
||||
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
|
||||
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
|
||||
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
|
||||
};
|
||||
SyncStateOp::Create {
|
||||
model_id,
|
||||
@@ -397,6 +403,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
SyncModel::Folder(m) => folders_to_upsert.push(m),
|
||||
SyncModel::HttpRequest(m) => http_requests_to_upsert.push(m),
|
||||
SyncModel::GrpcRequest(m) => grpc_requests_to_upsert.push(m),
|
||||
SyncModel::WebsocketRequest(m) => websocket_requests_to_upsert.push(m),
|
||||
}
|
||||
SyncStateOp::Update {
|
||||
state: state.to_owned(),
|
||||
@@ -420,6 +427,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
||||
folders_to_upsert,
|
||||
http_requests_to_upsert,
|
||||
grpc_requests_to_upsert,
|
||||
websocket_requests_to_upsert,
|
||||
&UpdateSource::Sync,
|
||||
)
|
||||
.await?;
|
||||
@@ -543,6 +551,9 @@ async fn delete_model<R: Runtime>(window: &WebviewWindow<R>, model: &SyncModel)
|
||||
SyncModel::GrpcRequest(m) => {
|
||||
delete_grpc_request(window, m.id.as_str(), &UpdateSource::Sync).await?;
|
||||
}
|
||||
SyncModel::WebsocketRequest(m) => {
|
||||
delete_websocket_request(window, m.id.as_str(), &UpdateSource::Sync).await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user