Proto selection UI/models

This commit is contained in:
Gregory Schier
2024-02-06 12:29:23 -08:00
parent c85a11edf1
commit 562a36d616
28 changed files with 382 additions and 154 deletions

View File

@@ -34,7 +34,7 @@ use tokio::sync::Mutex;
use tokio::time::sleep;
use window_shadows::set_shadow;
use grpc::manager::GrpcManager;
use grpc::manager::GrpcHandle;
use grpc::ServiceDefinition;
use window_ext::TrafficLightWindowExt;
@@ -95,19 +95,20 @@ async fn migrate_db(app_handle: AppHandle, db: &Mutex<Pool<Sqlite>>) -> Result<(
async fn cmd_grpc_reflect(
request_id: &str,
app_handle: AppHandle,
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> Result<Vec<ServiceDefinition>, String> {
let req = get_grpc_request(&app_handle, request_id)
.await
.map_err(|e| e.to_string())?;
let uri = safe_uri(&req.url).map_err(|e| e.to_string())?;
grpc::reflect(&uri).await
grpc_handle.lock().await.clean_reflect(&uri).await
}
#[tauri::command]
async fn cmd_grpc_call_unary(
request_id: &str,
app_handle: AppHandle,
grpc_handle: State<'_, Mutex<GrpcManager>>,
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> Result<GrpcMessage, String> {
let req = get_grpc_request(&app_handle, request_id)
.await
@@ -316,7 +317,7 @@ async fn cmd_grpc_client_streaming(
let conn = conn.clone();
let req = req.clone();
async move {
let grpc_handle = app_handle.state::<Mutex<GrpcManager>>();
let grpc_handle = app_handle.state::<Mutex<GrpcHandle>>();
let msg = grpc_handle
.lock()
.await
@@ -404,7 +405,7 @@ async fn cmd_grpc_client_streaming(
async fn cmd_grpc_streaming(
request_id: &str,
app_handle: AppHandle,
grpc_handle: State<'_, Mutex<GrpcManager>>,
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> Result<String, String> {
let req = get_grpc_request(&app_handle, request_id)
.await
@@ -614,7 +615,7 @@ async fn cmd_grpc_streaming(
async fn cmd_grpc_server_streaming(
request_id: &str,
app_handle: AppHandle,
grpc_handle: State<'_, Mutex<GrpcManager>>,
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> Result<GrpcConnection, String> {
let req = get_grpc_request(&app_handle, request_id)
.await
@@ -1627,7 +1628,7 @@ fn main() {
app.manage(Mutex::new(yaak_updater));
// Add GRPC manager
let grpc_handle = GrpcManager::default();
let grpc_handle = GrpcHandle::default();
app.manage(Mutex::new(grpc_handle));
// Add DB handle

View File

@@ -204,6 +204,7 @@ pub struct GrpcRequest {
pub service: Option<String>,
pub method: Option<String>,
pub message: String,
pub proto_files: Json<Vec<String>>,
}
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)]
@@ -497,9 +498,10 @@ pub async fn upsert_grpc_request(
sqlx::query!(
r#"
INSERT INTO grpc_requests (
id, name, workspace_id, folder_id, sort_priority, url, service, method, message
id, name, workspace_id, folder_id, sort_priority, url, service, method, message,
proto_files
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
updated_at = CURRENT_TIMESTAMP,
name = excluded.name,
@@ -508,7 +510,8 @@ pub async fn upsert_grpc_request(
url = excluded.url,
service = excluded.service,
method = excluded.method,
message = excluded.message
message = excluded.message,
proto_files = excluded.proto_files
"#,
id,
trimmed_name,
@@ -519,6 +522,7 @@ pub async fn upsert_grpc_request(
request.service,
request.method,
request.message,
request.proto_files,
)
.execute(&db)
.await?;
@@ -539,7 +543,8 @@ pub async fn get_grpc_request(
r#"
SELECT
id, model, workspace_id, folder_id, created_at, updated_at, name, sort_priority,
url, service, method, message
url, service, method, message,
proto_files AS "proto_files!: sqlx::types::Json<Vec<String>>"
FROM grpc_requests
WHERE id = ?
"#,
@@ -559,7 +564,8 @@ pub async fn list_grpc_requests(
r#"
SELECT
id, model, workspace_id, folder_id, created_at, updated_at, name, sort_priority,
url, service, method, message
url, service, method, message,
proto_files AS "proto_files!: sqlx::types::Json<Vec<String>>"
FROM grpc_requests
WHERE workspace_id = ?
"#,