Fix xpath filtering

This commit is contained in:
Gregory Schier
2024-08-08 22:54:15 -07:00
parent 8081c86ec6
commit 3050995fed
12 changed files with 35 additions and 41 deletions

8
package-lock.json generated
View File

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

View File

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

View File

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

View File

@@ -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<JsonValue>, };
export type FilterResponse = { content: string, };

View File

@@ -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<JsonValue> | { [key: string]: JsonValue };

View File

@@ -81,7 +81,7 @@ new Promise<void>(async (resolve, reject) => {
);
const replyPayload: InternalEventPayload = {
type: 'filter_response',
items: JSON.parse(reply),
content: reply,
};
sendToServer({ id: genId(), pluginRefId, replyId, payload: replyPayload });
return;

View File

@@ -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<PluginManager>>,
filter: &str,
) -> Result<Vec<Value>, String> {
println!("FILTERING? {filter}");
) -> Result<FilterResponse, String> {
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())
}

View File

@@ -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<Envi
let dbm = &*window.app_handle().state::<SqliteConnection>();
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<Wry>, workspace_id: &str) -> Result
pub async fn delete_folder(window: &WebviewWindow, id: &str) -> Result<Folder> {
let folder = get_folder(window, id).await?;
let dbm = &*window.app_handle().state::<SqliteConnection>();
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(),
])

View File

@@ -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<Value>,
pub content: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]

View File

@@ -1,5 +1,5 @@
pub mod error;
mod events;
pub mod events;
pub mod manager;
mod nodejs;
pub mod plugin;

View File

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

View File

@@ -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;
},
});
}