From b5eed9bf9dfa6606408c5c8bf5d08fdae110adab Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 8 Aug 2024 22:54:15 -0700 Subject: [PATCH] Fix xpath filtering --- package-lock.json | 8 ++--- package.json | 2 +- plugin-runtime-types/package.json | 2 +- .../src/gen/FilterResponse.ts | 3 +- .../src/gen/serde_json/JsonValue.ts | 3 -- plugin-runtime/src/index.worker.ts | 2 +- src-tauri/src/lib.rs | 5 ++- src-tauri/yaak_models/src/queries.rs | 34 ++++++++----------- src-tauri/yaak_plugin_runtime/src/events.rs | 3 +- src-tauri/yaak_plugin_runtime/src/lib.rs | 2 +- src-web/hooks/useCreateHttpRequest.ts | 2 +- src-web/hooks/useFilterResponse.ts | 10 ++++-- 12 files changed, 35 insertions(+), 41 deletions(-) delete mode 100644 plugin-runtime-types/src/gen/serde_json/JsonValue.ts diff --git a/package-lock.json b/package-lock.json index 4c1eea80..52ac313c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@tauri-apps/plugin-fs": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "^2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0-rc.0", - "@yaakapp/api": "^0.1.2", + "@yaakapp/api": "^0.1.3", "buffer": "^6.0.3", "classnames": "^2.3.2", "cm6-graphql": "^0.0.9", @@ -2981,9 +2981,9 @@ "integrity": "sha512-N8tkAACJx2ww8vFMneJmaAgmjAG1tnVBZJRLRcx061tmsLRZHSEZSLuGWnwPtunsSLvSqXQ2wfp7Mgqg1I+2dQ==" }, "node_modules/@yaakapp/api": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.2.tgz", - "integrity": "sha512-VEs+H9ZJjp/MFHKbqTdG/eGtvjDZ36P1pmzEYm6VYGIN2Bfw3OyXzkn7vgIg1savX0LU/U5kI88AYXGMr5Fjdw==", + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.3.tgz", + "integrity": "sha512-y5zYlyfJkO2bqDRBZFB6DCI+MJzDIjslnApsiW6F0fQHa4QP/gGXEbpjBRa32O4K/CfjziGBpW/yAzYuwBCYDQ==", "dependencies": { "@types/node": "^22.0.0" } diff --git a/package.json b/package.json index 633d2a16..9a1480bb 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@tauri-apps/plugin-fs": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "^2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0-rc.0", - "@yaakapp/api": "^0.1.2", + "@yaakapp/api": "^0.1.3", "buffer": "^6.0.3", "classnames": "^2.3.2", "cm6-graphql": "^0.0.9", diff --git a/plugin-runtime-types/package.json b/plugin-runtime-types/package.json index 89b63eaf..6eca5214 100644 --- a/plugin-runtime-types/package.json +++ b/plugin-runtime-types/package.json @@ -1,6 +1,6 @@ { "name": "@yaakapp/api", - "version": "0.1.2", + "version": "0.1.3", "main": "lib/index.js", "typings": "./lib/index.d.ts", "files": [ diff --git a/plugin-runtime-types/src/gen/FilterResponse.ts b/plugin-runtime-types/src/gen/FilterResponse.ts index 9298ab34..fa2fcc15 100644 --- a/plugin-runtime-types/src/gen/FilterResponse.ts +++ b/plugin-runtime-types/src/gen/FilterResponse.ts @@ -1,4 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { JsonValue } from "./serde_json/JsonValue"; -export type FilterResponse = { items: Array, }; +export type FilterResponse = { content: string, }; diff --git a/plugin-runtime-types/src/gen/serde_json/JsonValue.ts b/plugin-runtime-types/src/gen/serde_json/JsonValue.ts deleted file mode 100644 index 1af2d6e0..00000000 --- a/plugin-runtime-types/src/gen/serde_json/JsonValue.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type JsonValue = number | string | Array | { [key: string]: JsonValue }; diff --git a/plugin-runtime/src/index.worker.ts b/plugin-runtime/src/index.worker.ts index 8f7a9cc4..06ff789c 100644 --- a/plugin-runtime/src/index.worker.ts +++ b/plugin-runtime/src/index.worker.ts @@ -81,7 +81,7 @@ new Promise(async (resolve, reject) => { ); const replyPayload: InternalEventPayload = { type: 'filter_response', - items: JSON.parse(reply), + content: reply, }; sendToServer({ id: genId(), pluginRefId, replyId, payload: replyPayload }); return; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0f94ca1c..5a661fc4 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -59,6 +59,7 @@ use yaak_models::queries::{ upsert_cookie_jar, upsert_environment, upsert_folder, upsert_grpc_connection, upsert_grpc_event, upsert_grpc_request, upsert_http_request, upsert_workspace, }; +use yaak_plugin_runtime::events::FilterResponse; mod analytics; mod export_resources; @@ -720,8 +721,7 @@ async fn cmd_filter_response( response_id: &str, plugin_manager: State<'_, Mutex>, filter: &str, -) -> Result, String> { - println!("FILTERING? {filter}"); +) -> Result { let response = get_http_response(&w, response_id) .await .expect("Failed to get response"); @@ -746,7 +746,6 @@ async fn cmd_filter_response( .await .run_filter(filter, &body, &content_type) .await - .map(|r| r.items) .map_err(|e| e.to_string()) } diff --git a/src-tauri/yaak_models/src/queries.rs b/src-tauri/yaak_models/src/queries.rs index 0fabacf8..f43fa355 100644 --- a/src-tauri/yaak_models/src/queries.rs +++ b/src-tauri/yaak_models/src/queries.rs @@ -196,7 +196,7 @@ pub async fn upsert_workspace(window: &WebviewWindow, workspace: Workspace) -> R CurrentTimestamp.into(), trimmed_name.into(), workspace.description.into(), - serde_json::to_string(&workspace.variables).unwrap().into(), + serde_json::to_string(&workspace.variables)?.into(), workspace.setting_request_timeout.into(), workspace.setting_follow_redirects.into(), workspace.setting_validate_certificates.into(), @@ -350,10 +350,8 @@ pub async fn upsert_grpc_request( .as_ref() .map(|s| s.as_str()) .into(), - serde_json::to_string(&request.authentication) - .unwrap() - .into(), - serde_json::to_string(&request.metadata).unwrap().into(), + serde_json::to_string(&request.authentication)?.into(), + serde_json::to_string(&request.metadata)?.into(), ]) .on_conflict( OnConflict::column(GrpcRequestIden::Id) @@ -447,7 +445,7 @@ pub async fn upsert_grpc_connection( connection.elapsed.into(), connection.status.into(), connection.error.as_ref().map(|s| s.as_str()).into(), - serde_json::to_string(&connection.trailers).unwrap().into(), + serde_json::to_string(&connection.trailers)?.into(), connection.url.as_str().into(), ]) .on_conflict( @@ -555,8 +553,8 @@ pub async fn upsert_grpc_event(window: &WebviewWindow, event: &GrpcEvent) -> Res event.request_id.as_str().into(), event.connection_id.as_str().into(), event.content.as_str().into(), - serde_json::to_string(&event.event_type).unwrap().into(), - serde_json::to_string(&event.metadata).unwrap().into(), + serde_json::to_string(&event.event_type)?.into(), + serde_json::to_string(&event.metadata)?.into(), event.status.into(), event.error.as_ref().map(|s| s.as_str()).into(), ]) @@ -639,7 +637,7 @@ pub async fn upsert_cookie_jar( CurrentTimestamp.into(), cookie_jar.workspace_id.as_str().into(), trimmed_name.into(), - serde_json::to_string(&cookie_jar.cookies).unwrap().into(), + serde_json::to_string(&cookie_jar.cookies)?.into(), ]) .on_conflict( OnConflict::column(GrpcEventIden::Id) @@ -681,7 +679,7 @@ pub async fn delete_environment(window: &WebviewWindow, id: &str) -> Result(); let db = dbm.0.lock().await.get().unwrap(); - + let (sql, params) = Query::delete() .from_table(EnvironmentIden::Table) .cond_where(Expr::col(EnvironmentIden::Id).eq(id)) @@ -807,9 +805,7 @@ pub async fn upsert_environment( CurrentTimestamp.into(), environment.workspace_id.as_str().into(), trimmed_name.into(), - serde_json::to_string(&environment.variables) - .unwrap() - .into(), + serde_json::to_string(&environment.variables)?.into(), ]) .on_conflict( OnConflict::column(GrpcEventIden::Id) @@ -871,7 +867,7 @@ pub async fn list_folders(mgr: &impl Manager, workspace_id: &str) -> Result pub async fn delete_folder(window: &WebviewWindow, id: &str) -> Result { let folder = get_folder(window, id).await?; - + let dbm = &*window.app_handle().state::(); let db = dbm.0.lock().await.get().unwrap(); @@ -975,13 +971,13 @@ pub async fn upsert_http_request(window: &WebviewWindow, r: HttpRequest) -> Resu r.folder_id.as_ref().map(|s| s.as_str()).into(), trimmed_name.into(), r.url.as_str().into(), - serde_json::to_string(&r.url_parameters).unwrap().into(), + serde_json::to_string(&r.url_parameters)?.into(), r.method.as_str().into(), - serde_json::to_string(&r.body).unwrap().into(), + serde_json::to_string(&r.body)?.into(), r.body_type.as_ref().map(|s| s.as_str()).into(), - serde_json::to_string(&r.authentication).unwrap().into(), + serde_json::to_string(&r.authentication)?.into(), r.authentication_type.as_ref().map(|s| s.as_str()).into(), - serde_json::to_string(&r.headers).unwrap().into(), + serde_json::to_string(&r.headers)?.into(), r.sort_priority.into(), ]) .on_conflict( @@ -1110,7 +1106,7 @@ pub async fn create_http_response( status_reason.into(), content_length.into(), body_path.into(), - serde_json::to_string(&headers).unwrap().into(), + serde_json::to_string(&headers)?.into(), version.into(), remote_addr.into(), ]) diff --git a/src-tauri/yaak_plugin_runtime/src/events.rs b/src-tauri/yaak_plugin_runtime/src/events.rs index 0abcf7fc..a7c5ab0c 100644 --- a/src-tauri/yaak_plugin_runtime/src/events.rs +++ b/src-tauri/yaak_plugin_runtime/src/events.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use serde_json::Value; use ts_rs::TS; use yaak_models::models::{Environment, Folder, GrpcConnection, GrpcEvent, GrpcRequest, HttpRequest, HttpResponse, KeyValue, Workspace}; @@ -79,7 +78,7 @@ pub struct FilterRequest { #[serde(default, rename_all = "camelCase")] #[ts(export)] pub struct FilterResponse { - pub items: Vec, + pub content: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] diff --git a/src-tauri/yaak_plugin_runtime/src/lib.rs b/src-tauri/yaak_plugin_runtime/src/lib.rs index 9edeff09..233a5636 100644 --- a/src-tauri/yaak_plugin_runtime/src/lib.rs +++ b/src-tauri/yaak_plugin_runtime/src/lib.rs @@ -1,5 +1,5 @@ pub mod error; -mod events; +pub mod events; pub mod manager; mod nodejs; pub mod plugin; diff --git a/src-web/hooks/useCreateHttpRequest.ts b/src-web/hooks/useCreateHttpRequest.ts index f2a9aab6..c7e62672 100644 --- a/src-web/hooks/useCreateHttpRequest.ts +++ b/src-web/hooks/useCreateHttpRequest.ts @@ -22,7 +22,7 @@ export function useCreateHttpRequest() { if (patch.sortPriority === undefined) { if (activeRequest != null) { // Place above currently-active request - patch.sortPriority = activeRequest.sortPriority + 0.0001; + patch.sortPriority = activeRequest.sortPriority - 0.0001; } else { // Place at the very top patch.sortPriority = -Date.now(); diff --git a/src-web/hooks/useFilterResponse.ts b/src-web/hooks/useFilterResponse.ts index cb5e9e95..e921f303 100644 --- a/src-web/hooks/useFilterResponse.ts +++ b/src-web/hooks/useFilterResponse.ts @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query'; -import type { JsonValue } from '@yaakapp/api/lib/gen/serde_json/JsonValue'; +import type { FilterResponse } from '@yaakapp/api'; import { invokeCmd } from '../lib/tauri'; export function useFilterResponse({ @@ -16,8 +16,12 @@ export function useFilterResponse({ return null; } - const items = (await invokeCmd('cmd_filter_response', { responseId, filter })) as JsonValue[]; - return JSON.stringify(items, null, 2); + const result = (await invokeCmd('cmd_filter_response', { + responseId, + filter, + })) as FilterResponse; + + return result.content; }, }); }