From 4838353585c9755f14cebcf70f5749d3bd69ab80 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 15 Aug 2026 11:25:27 -0700 Subject: [PATCH] Move the RPC wire schema into a Tauri-free crate (#553) Co-authored-by: Claude Fable 5 --- Cargo.lock | 17 + Cargo.toml | 2 + apps/yaak-client/lib/rpc.ts | 2 +- apps/yaak-client/lib/sendEphemeralRequest.ts | 2 +- crates-tauri/yaak-app-client/Cargo.toml | 1 + .../yaak-app-client/bindings/index.ts | 4 - crates-tauri/yaak-app-client/index.ts | 6 +- .../yaak-app-client/src/git_watcher.rs | 10 +- crates-tauri/yaak-app-client/src/lib.rs | 18 +- crates-tauri/yaak-app-client/src/rpc_ext.rs | 967 +--------------- crates-tauri/yaak-app-client/src/sync_ext.rs | 10 +- crates/common/yaak-rpc-schema/Cargo.toml | 18 + crates/common/yaak-rpc-schema/README.md | 44 + .../yaak-rpc-schema}/bindings/gen_api.ts | 0 .../yaak-rpc-schema}/bindings/gen_events.ts | 0 .../yaak-rpc-schema}/bindings/gen_git.ts | 0 .../yaak-rpc-schema}/bindings/gen_grpc.ts | 0 .../yaak-rpc-schema}/bindings/gen_models.ts | 0 .../yaak-rpc-schema}/bindings/gen_rpc.ts | 16 +- .../yaak-rpc-schema}/bindings/gen_search.ts | 0 .../yaak-rpc-schema}/bindings/gen_sync.ts | 0 .../yaak-rpc-schema}/bindings/gen_util.ts | 0 .../yaak-rpc-schema}/bindings/parser.ts | 0 .../common/yaak-rpc-schema}/bindings/sse.ts | 0 crates/common/yaak-rpc-schema/index.ts | 4 + crates/common/yaak-rpc-schema/package.json | 6 + crates/common/yaak-rpc-schema/src/lib.rs | 1021 +++++++++++++++++ crates/yaak-sync/index.ts | 2 +- package.json | 1 + 29 files changed, 1156 insertions(+), 995 deletions(-) create mode 100644 crates/common/yaak-rpc-schema/Cargo.toml create mode 100644 crates/common/yaak-rpc-schema/README.md rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_api.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_events.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_git.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_grpc.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_models.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_rpc.ts (98%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_search.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_sync.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/gen_util.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/parser.ts (100%) rename {crates-tauri/yaak-app-client => crates/common/yaak-rpc-schema}/bindings/sse.ts (100%) create mode 100644 crates/common/yaak-rpc-schema/index.ts create mode 100644 crates/common/yaak-rpc-schema/package.json create mode 100644 crates/common/yaak-rpc-schema/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 551f9cf7..68899a5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11035,6 +11035,7 @@ dependencies = [ "yaak-models", "yaak-plugins", "yaak-rpc", + "yaak-rpc-schema", "yaak-sse", "yaak-sync", "yaak-system-appearance", @@ -11372,6 +11373,22 @@ dependencies = [ "ts-rs", ] +[[package]] +name = "yaak-rpc-schema" +version = "0.0.0" +dependencies = [ + "serde", + "ts-rs", + "yaak-git", + "yaak-grpc", + "yaak-models", + "yaak-plugins", + "yaak-sse", + "yaak-sync", + "yaak-templates", + "yaak-ws", +] + [[package]] name = "yaak-sse" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 81df1687..5f9ced20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ # Common/foundation crates "crates/common/yaak-database", "crates/common/yaak-rpc", + "crates/common/yaak-rpc-schema", # Shared crates (no Tauri dependency) "crates/yaak-core", "crates/yaak-common", @@ -63,6 +64,7 @@ ts-rs = "11.1.0" # Internal crates - common/foundation yaak-database = { path = "crates/common/yaak-database" } yaak-rpc = { path = "crates/common/yaak-rpc" } +yaak-rpc-schema = { path = "crates/common/yaak-rpc-schema" } # Internal crates - shared yaak-core = { path = "crates/yaak-core" } diff --git a/apps/yaak-client/lib/rpc.ts b/apps/yaak-client/lib/rpc.ts index 74be4d49..e1a9eb24 100644 --- a/apps/yaak-client/lib/rpc.ts +++ b/apps/yaak-client/lib/rpc.ts @@ -1,6 +1,6 @@ import type { RpcPayload } from "@yaakapp-internal/platform"; import { platform } from "@yaakapp-internal/platform"; -import type { RpcSchema } from "@yaakapp-internal/tauri-client"; +import type { RpcSchema } from "@yaakapp-internal/rpc-schema"; /** * Every backend command the app can call: the generated wire schema, one field diff --git a/apps/yaak-client/lib/sendEphemeralRequest.ts b/apps/yaak-client/lib/sendEphemeralRequest.ts index bd6ca524..1c9838b1 100644 --- a/apps/yaak-client/lib/sendEphemeralRequest.ts +++ b/apps/yaak-client/lib/sendEphemeralRequest.ts @@ -1,5 +1,5 @@ import type { HttpRequest } from "@yaakapp-internal/models"; -import type { EphemeralHttpResponse } from "@yaakapp-internal/tauri-client"; +import type { EphemeralHttpResponse } from "@yaakapp-internal/rpc-schema"; import { getActiveCookieJar } from "../hooks/useActiveCookieJar"; import { rpc } from "./rpc"; diff --git a/crates-tauri/yaak-app-client/Cargo.toml b/crates-tauri/yaak-app-client/Cargo.toml index 99faaa07..a6f7555c 100644 --- a/crates-tauri/yaak-app-client/Cargo.toml +++ b/crates-tauri/yaak-app-client/Cargo.toml @@ -73,6 +73,7 @@ url = "2" tokio-util = { version = "0.7", features = ["codec"] } ts-rs = { workspace = true } yaak-rpc = { workspace = true } +yaak-rpc-schema = { workspace = true } uuid = "1.12.1" yaak-api = { workspace = true } yaak-common = { workspace = true } diff --git a/crates-tauri/yaak-app-client/bindings/index.ts b/crates-tauri/yaak-app-client/bindings/index.ts index 88e89783..accd88f2 100644 --- a/crates-tauri/yaak-app-client/bindings/index.ts +++ b/crates-tauri/yaak-app-client/bindings/index.ts @@ -1,7 +1,5 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type GitWatchResult = { unlistenEvent: string, }; - export type PluginUpdateInfo = { name: string, currentVersion: string, latestVersion: string, }; export type PluginUpdateNotification = { updateCount: number, plugins: Array, }; @@ -12,8 +10,6 @@ export type UpdateResponse = { "type": "ack" } | { "type": "action", action: Upd export type UpdateResponseAction = "install" | "skip"; -export type WatchResult = { unlistenEvent: string, }; - export type YaakNotification = { timestamp: string, timeout: number | null, id: string, title: string | null, message: string, color: string | null, action: YaakNotificationAction | null, }; export type YaakNotificationAction = { label: string, url: string, }; diff --git a/crates-tauri/yaak-app-client/index.ts b/crates-tauri/yaak-app-client/index.ts index 9a021054..09eab936 100644 --- a/crates-tauri/yaak-app-client/index.ts +++ b/crates-tauri/yaak-app-client/index.ts @@ -1,4 +1,4 @@ -// ts-rs owns bindings/index.ts and rewrites it on export, so this hand-written -// entry point is where the generated files come together. -export * from "./bindings/gen_rpc"; +// ts-rs owns bindings/index.ts and rewrites it on export. What remains here +// after the RPC schema moved to @yaakapp-internal/rpc-schema is the +// desktop-only surface: updater and notification types. export * from "./bindings/index"; diff --git a/crates-tauri/yaak-app-client/src/git_watcher.rs b/crates-tauri/yaak-app-client/src/git_watcher.rs index b84a47cd..17e0cfc4 100644 --- a/crates-tauri/yaak-app-client/src/git_watcher.rs +++ b/crates-tauri/yaak-app-client/src/git_watcher.rs @@ -2,7 +2,6 @@ use crate::error::{Error, Result}; use chrono::Utc; use log::{debug, error, warn}; use notify::Watcher; -use serde::{Deserialize, Serialize}; use std::path::Path; use std::sync::mpsc; use std::time::Duration; @@ -10,18 +9,11 @@ use tauri::{AppHandle, Listener, Runtime}; use tokio::select; use tokio::sync::watch; use tokio::time::sleep; -use ts_rs::TS; use yaak_git::{GitWorktreeStatus, git_path_is_ignored, git_repository_paths, git_worktree_status}; +use yaak_rpc_schema::GitWatchResult; const GIT_STATUS_COALESCE_WINDOW: Duration = Duration::from_millis(250); -#[derive(Debug, Clone, Serialize, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "index.ts")] -pub(crate) struct GitWatchResult { - unlisten_event: String, -} - pub(crate) async fn watch_git_worktree_status( app_handle: AppHandle, dir: &Path, diff --git a/crates-tauri/yaak-app-client/src/lib.rs b/crates-tauri/yaak-app-client/src/lib.rs index 8aa3a6f7..53e45519 100644 --- a/crates-tauri/yaak-app-client/src/lib.rs +++ b/crates-tauri/yaak-app-client/src/lib.rs @@ -8,7 +8,6 @@ use crate::import::{import_data, import_url}; use crate::models_ext::{BlobManagerExt, QueryManagerExt}; use crate::notifications::YaakNotifier; use crate::render::{render_grpc_request, render_json_value, render_template}; -use crate::rpc_ext::EphemeralHttpResponse; use crate::updates::{UpdateMode, UpdateTrigger, YaakUpdater}; use crate::uri_scheme::handle_deep_link; use error::Result as YaakResult; @@ -57,6 +56,7 @@ use yaak_plugins::events::{ use yaak_plugins::manager::PluginManager; use yaak_plugins::plugin_meta::{PluginMetadata, get_plugin_meta}; use yaak_plugins::template_callback::PluginTemplateCallback; +use yaak_rpc_schema::{AppMetaData, EphemeralHttpResponse}; use yaak_sse::sse::ServerSentEvent; use yaak_tauri_utils::window::WorkspaceWindowTrait; use yaak_templates::format_json::format_json; @@ -184,22 +184,6 @@ impl PluginContextExt for WebviewWindow { } } -#[derive(serde::Serialize, ts_rs::TS)] -#[serde(default, rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub struct AppMetaData { - is_dev: bool, - version: String, - cli_version: Option, - name: String, - app_data_dir: String, - app_log_dir: String, - vendored_plugin_dir: String, - default_project_dir: String, - feature_updater: bool, - feature_license: bool, -} - async fn cmd_metadata(app_handle: AppHandle) -> YaakResult { let app_data_dir = app_handle.path().app_data_dir()?; let app_log_dir = app_handle.path().app_log_dir()?; diff --git a/crates-tauri/yaak-app-client/src/rpc_ext.rs b/crates-tauri/yaak-app-client/src/rpc_ext.rs index 2a8361a9..b3614532 100644 --- a/crates-tauri/yaak-app-client/src/rpc_ext.rs +++ b/crates-tauri/yaak-app-client/src/rpc_ext.rs @@ -1,29 +1,25 @@ -//! The client's RPC surface: every command, as one registry. +//! The client's RPC surface: every command, wired to its Tauri implementation. //! -//! Each command has a request struct (the wire payload), an adapter that calls -//! the underlying implementation, and an entry in `rpc_commands!` below, which -//! builds the router and emits the `RpcSchema` TypeScript definition. The -//! single `rpc` Tauri command is the only way the frontend reaches any of -//! this — one envelope, `{ cmd, payload }`, exactly like the proxy app. +//! The *shape* of the surface — command names, request payloads, response +//! types — is declared once in `yaak_rpc_schema`, which is also where the +//! TypeScript bindings come from. This module supplies the desktop's half: an +//! adapter per command that turns a `ClientCtx` and a request struct into a +//! call on the existing implementation, and the single `rpc` Tauri command that +//! is the only way the frontend reaches any of it — one envelope, +//! `{ cmd, payload }`, exactly like the proxy app. //! //! Adapters exist so command implementations keep their natural Tauri //! signatures (window, app handle, managed state) while the wire format stays -//! transport-agnostic: a future WebSocket host dispatches into the same router -//! with a different `ClientCtx` construction and nothing else changes. +//! transport-agnostic: another host builds its router from the same schema with +//! a different context type and its own adapters, and the frontend cannot tell. use crate::error::Result; -use crate::git_watcher::GitWatchResult; use crate::notifications::YaakNotifier; -use crate::sync_ext::WatchResult; use crate::updates::YaakUpdater; -use crate::AppMetaData; use log::warn; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::path::PathBuf; +use serde::Serialize; use tauri::{Manager, Runtime, State, WebviewWindow}; use tokio::sync::Mutex; -use ts_rs::TS; use yaak_crypto::manager::EncryptionManager; use yaak_git::{ BranchDeleteResult, CloneResult, GitBranchInfo, GitCommit, GitFileDiff, GitRemote, @@ -32,26 +28,24 @@ use yaak_git::{ use yaak_grpc::manager::GrpcHandle; use yaak_grpc::ServiceDefinition; use yaak_models::models::{ - AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, + GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, HttpResponseEvent, Plugin, Settings, WebsocketConnection, WebsocketEvent, WorkspaceMeta, }; use yaak_models::util::BatchUpsertResult; use yaak_plugins::events::{ - CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest, - CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse, - GetFolderActionsResponse, GetGrpcRequestActionsResponse, + FilterResponse, GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse, GetWebsocketRequestActionsResponse, - GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose, + GetWorkspaceActionsResponse, }; use yaak_plugins::api::{PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse}; use yaak_plugins::manager::PluginManager; use yaak_plugins::plugin_meta::PluginMetadata; use yaak_rpc::RpcRouter; +use yaak_rpc_schema::*; use yaak_sse::sse::ServerSentEvent; use yaak_sync::sync::SyncOp; -use yaak_templates::Tokens; use yaak_ws::WebsocketManager; /// Per-call context: the window a command was invoked from. @@ -115,14 +109,6 @@ fn stream_emitter( // -- Streaming commands (hand-written: they push events while they run) -- -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitWatchWorktreeStatusReq { - pub dir: PathBuf, - pub stream_id: String, -} - async fn cmd_git_watch_worktree_status( ctx: ClientCtx, req: CmdGitWatchWorktreeStatusReq, @@ -136,15 +122,6 @@ async fn cmd_git_watch_worktree_status( .await } -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSyncWatchReq { - pub sync_dir: PathBuf, - pub workspace_id: String, - pub stream_id: String, -} - async fn cmd_sync_watch( ctx: ClientCtx, req: CmdSyncWatchReq, @@ -159,811 +136,22 @@ async fn cmd_sync_watch( .await?) } -macro_rules! rpc_commands { +/// Build the router with every command in the schema registered to its +/// adapter here. Generic over the runtime so the same registry serves Wry and +/// CEF builds. Adding a command means adding it to the schema *and* writing an +/// adapter below; a missing adapter fails to compile rather than 404 at runtime. +macro_rules! register_commands { ( $( $name:ident ( $req:ty ) -> $res:ty ),* $(,)? ) => { - /// Build the router with every command registered. Generic over the - /// runtime so the same registry serves Wry and CEF builds. pub(crate) fn build_rpc_router() -> RpcRouter> { let mut router = RpcRouter::new(); $( router.register(stringify!($name), yaak_rpc::rpc_handler_async!($name)); )* router } - - /// The wire schema, exported to TypeScript. Field name = command name, - /// tuple = (request payload, response payload). - #[derive(TS)] - #[ts(export, export_to = "gen_rpc.ts")] - #[allow(non_snake_case, unused)] - pub(crate) struct RpcSchema { - $( pub $name: ($req, $res), )* - } }; } +yaak_rpc_schema::with_commands!(register_commands); -// -- Request payloads and adapters (generated from the original command signatures) -- - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdMetadataReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdTemplateTokensToStringReq { - pub tokens: Tokens, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdRenderTemplateReq { - pub template: String, - pub workspace_id: String, - pub environment_id: Option, - pub purpose: Option, - pub ignore_error: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSendFeedbackReq { - pub feature: String, - pub text: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDismissNotificationReq { - pub notification_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGrpcReflectReq { - pub request_id: String, - pub environment_id: Option, - pub proto_files: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGrpcGoReq { - pub request_id: String, - pub environment_id: Option, - pub proto_files: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdRestartReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSendEphemeralRequestReq { - pub request: HttpRequest, - pub environment_id: Option, - pub cookie_jar_id: Option, -} - -/// An unsaved response and its body. -/// -/// The body rides along because nothing stored it: there is no database row to -/// look up later and no file for a host to read, so this is the caller's only -/// copy. -#[derive(Debug, Serialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub struct EphemeralHttpResponse { - pub response: HttpResponse, - pub body: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdFormatJsonReq { - pub text: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdFormatGraphqlReq { - pub text: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdHttpResponseBodyReq { - pub response_id: String, - pub filter: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdHttpResponseBodyPathReq { - pub response_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdHttpRequestBodyReq { - pub response_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetSseEventsReq { - pub response_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetHttpResponseEventsReq { - pub response_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdImportDataReq { - pub file_path: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdImportUrlReq { - pub url: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdHttpRequestActionsReq {} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWebsocketRequestActionsReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallWebsocketRequestActionReq { - pub req: CallWebsocketRequestActionRequest, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWorkspaceActionsReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallWorkspaceActionReq { - pub req: CallWorkspaceActionRequest, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdFolderActionsReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallFolderActionReq { - pub req: CallFolderActionRequest, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGrpcRequestActionsReq {} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdTemplateFunctionSummariesReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdTemplateFunctionConfigReq { - pub function_name: String, - pub values: HashMap, - pub model: AnyModel, - pub environment_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetHttpAuthenticationSummariesReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetHttpAuthenticationConfigReq { - pub auth_name: String, - pub values: HashMap, - pub model: AnyModel, - pub environment_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallHttpRequestActionReq { - pub req: CallHttpRequestActionRequest, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallGrpcRequestActionReq { - pub req: CallGrpcRequestActionRequest, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCallHttpAuthenticationActionReq { - pub auth_name: String, - pub action_index: i32, - pub values: HashMap, - pub model: AnyModel, - pub environment_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCurlToRequestReq { - pub command: String, - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdExportDataReq { - pub export_path: String, - pub workspace_ids: Vec, - pub include_private_environments: bool, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSaveBase64ToBinaryReq { - pub filepath: String, - pub data: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSaveResponseReq { - pub response_id: String, - pub filepath: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSendHttpRequestReq { - pub environment_id: Option, - pub cookie_jar_id: Option, - pub request_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdReloadPluginsReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginInfoReq { - pub id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDeleteAllGrpcConnectionsReq { - pub request_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDeleteSendHistoryReq { - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDeleteAllHttpResponsesReq { - pub request_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetWorkspaceMetaReq { - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdNewChildWindowReq { - pub url: String, - pub label: String, - pub title: String, - pub inner_size: (f64, f64), -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdNewMainWindowReq { - pub url: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdCheckForUpdatesReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDecryptTemplateReq { - pub template: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSecureTemplateReq { - pub template: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGetThemesReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdEnableEncryptionReq { - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdRevealWorkspaceKeyReq { - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSetWorkspaceKeyReq { - pub workspace_id: String, - pub key: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDisableEncryptionReq { - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdDefaultHeadersReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsUpsertReq { - pub model: AnyModel, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsDeleteReq { - pub model: AnyModel, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsDuplicateReq { - pub model_type: String, - pub model_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsWebsocketEventsReq { - pub connection_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsGrpcEventsReq { - pub connection_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsGetSettingsReq {} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsGetGraphqlIntrospectionReq { - pub request_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsUpsertGraphqlIntrospectionReq { - pub request_id: String, - pub workspace_id: String, - pub content: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct ModelsWorkspaceModelsReq { - pub workspace_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitCheckoutReq { - pub dir: PathBuf, - pub branch: String, - pub force: bool, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitBranchReq { - pub dir: PathBuf, - pub branch: String, - pub base: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitDeleteBranchReq { - pub dir: PathBuf, - pub branch: String, - pub force: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitDeleteRemoteBranchReq { - pub dir: PathBuf, - pub branch: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitMergeBranchReq { - pub dir: PathBuf, - pub branch: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitRenameBranchReq { - pub dir: PathBuf, - pub old_name: String, - pub new_name: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitStatusReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitBranchInfoReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitWorktreeStatusReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitLogReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitLogForFileReq { - pub dir: PathBuf, - pub rela_path: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitFileDiffForCommitReq { - pub dir: PathBuf, - pub commit_oid: String, - pub rela_path: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitInitializeReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitCloneReq { - pub url: String, - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitCommitReq { - pub dir: PathBuf, - pub message: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitFetchAllReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitPushReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitPullReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitPullForceResetReq { - pub dir: PathBuf, - pub remote: String, - pub branch: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitPullMergeReq { - pub dir: PathBuf, - pub remote: String, - pub branch: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitAddReq { - pub dir: PathBuf, - pub rela_paths: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitUnstageReq { - pub dir: PathBuf, - pub rela_paths: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitResetChangesReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitRestoreFilesReq { - pub dir: PathBuf, - pub rela_paths: Vec, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitRestoreFileFromCommitReq { - pub dir: PathBuf, - pub commit_oid: String, - pub rela_path: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitAddCredentialReq { - pub remote_url: String, - pub username: String, - pub password: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitRemotesReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitAddRemoteReq { - pub dir: PathBuf, - pub name: String, - pub url: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdGitRmRemoteReq { - pub dir: PathBuf, - pub name: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSyncCalculateReq { - pub workspace_id: String, - pub sync_dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSyncCalculateFsReq { - pub dir: PathBuf, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdSyncApplyReq { - pub sync_ops: Vec, - pub sync_dir: PathBuf, - pub workspace_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWsDeleteConnectionsReq { - pub request_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWsSendReq { - pub connection_id: String, - pub environment_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWsCloseReq { - pub connection_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdWsConnectReq { - pub request_id: String, - pub environment_id: Option, - pub cookie_jar_id: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsSearchReq { - pub query: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsInstallReq { - pub name: String, - pub version: Option, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsInstallFromDirectoryReq { - pub directory: String, -} - -#[derive(Debug, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsUninstallReq { - pub plugin_id: String, -} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginInitErrorsReq {} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsUpdatesReq {} - -#[derive(Debug, Deserialize, TS)] -#[ts(export, export_to = "gen_rpc.ts")] -pub(crate) struct CmdPluginsUpdateAllReq {} +// -- Adapters -- async fn cmd_metadata(ctx: ClientCtx, _req: CmdMetadataReq) -> Result { Ok(crate::cmd_metadata(ctx.window.app_handle().clone()).await?) @@ -1393,114 +581,3 @@ async fn cmd_plugins_update_all(ctx: ClientCtx, _req: CmdPluginsU Ok(crate::plugins_ext::cmd_plugins_update_all(ctx.window.clone()).await?) } -rpc_commands! { - cmd_metadata(CmdMetadataReq) -> AppMetaData, - cmd_template_tokens_to_string(CmdTemplateTokensToStringReq) -> String, - cmd_render_template(CmdRenderTemplateReq) -> String, - cmd_send_feedback(CmdSendFeedbackReq) -> (), - cmd_dismiss_notification(CmdDismissNotificationReq) -> (), - cmd_grpc_reflect(CmdGrpcReflectReq) -> Vec, - cmd_grpc_go(CmdGrpcGoReq) -> String, - cmd_restart(CmdRestartReq) -> (), - cmd_send_ephemeral_request(CmdSendEphemeralRequestReq) -> EphemeralHttpResponse, - cmd_format_json(CmdFormatJsonReq) -> String, - cmd_format_graphql(CmdFormatGraphqlReq) -> String, - cmd_http_response_body(CmdHttpResponseBodyReq) -> FilterResponse, - cmd_http_response_body_path(CmdHttpResponseBodyPathReq) -> Option, - cmd_http_request_body(CmdHttpRequestBodyReq) -> Option>, - cmd_get_sse_events(CmdGetSseEventsReq) -> Vec, - cmd_get_http_response_events(CmdGetHttpResponseEventsReq) -> Vec, - cmd_import_data(CmdImportDataReq) -> BatchUpsertResult, - cmd_import_url(CmdImportUrlReq) -> BatchUpsertResult, - cmd_http_request_actions(CmdHttpRequestActionsReq) -> Vec, - cmd_websocket_request_actions(CmdWebsocketRequestActionsReq) -> Vec, - cmd_call_websocket_request_action(CmdCallWebsocketRequestActionReq) -> (), - cmd_workspace_actions(CmdWorkspaceActionsReq) -> Vec, - cmd_call_workspace_action(CmdCallWorkspaceActionReq) -> (), - cmd_folder_actions(CmdFolderActionsReq) -> Vec, - cmd_call_folder_action(CmdCallFolderActionReq) -> (), - cmd_grpc_request_actions(CmdGrpcRequestActionsReq) -> Vec, - cmd_template_function_summaries(CmdTemplateFunctionSummariesReq) -> Vec, - cmd_template_function_config(CmdTemplateFunctionConfigReq) -> GetTemplateFunctionConfigResponse, - cmd_get_http_authentication_summaries(CmdGetHttpAuthenticationSummariesReq) -> Vec, - cmd_get_http_authentication_config(CmdGetHttpAuthenticationConfigReq) -> GetHttpAuthenticationConfigResponse, - cmd_call_http_request_action(CmdCallHttpRequestActionReq) -> (), - cmd_call_grpc_request_action(CmdCallGrpcRequestActionReq) -> (), - cmd_call_http_authentication_action(CmdCallHttpAuthenticationActionReq) -> (), - cmd_curl_to_request(CmdCurlToRequestReq) -> HttpRequest, - cmd_export_data(CmdExportDataReq) -> (), - cmd_save_base64_to_binary(CmdSaveBase64ToBinaryReq) -> (), - cmd_save_response(CmdSaveResponseReq) -> (), - cmd_send_http_request(CmdSendHttpRequestReq) -> HttpResponse, - cmd_reload_plugins(CmdReloadPluginsReq) -> Vec<(String, String)>, - cmd_plugin_info(CmdPluginInfoReq) -> PluginMetadata, - cmd_delete_all_grpc_connections(CmdDeleteAllGrpcConnectionsReq) -> (), - cmd_delete_send_history(CmdDeleteSendHistoryReq) -> (), - cmd_delete_all_http_responses(CmdDeleteAllHttpResponsesReq) -> (), - cmd_get_workspace_meta(CmdGetWorkspaceMetaReq) -> WorkspaceMeta, - cmd_new_child_window(CmdNewChildWindowReq) -> (), - cmd_new_main_window(CmdNewMainWindowReq) -> (), - cmd_check_for_updates(CmdCheckForUpdatesReq) -> bool, - cmd_decrypt_template(CmdDecryptTemplateReq) -> String, - cmd_secure_template(CmdSecureTemplateReq) -> String, - cmd_get_themes(CmdGetThemesReq) -> Vec, - cmd_enable_encryption(CmdEnableEncryptionReq) -> (), - cmd_reveal_workspace_key(CmdRevealWorkspaceKeyReq) -> String, - cmd_set_workspace_key(CmdSetWorkspaceKeyReq) -> (), - cmd_disable_encryption(CmdDisableEncryptionReq) -> (), - cmd_default_headers(CmdDefaultHeadersReq) -> Vec, - models_upsert(ModelsUpsertReq) -> String, - models_delete(ModelsDeleteReq) -> String, - models_duplicate(ModelsDuplicateReq) -> String, - models_websocket_events(ModelsWebsocketEventsReq) -> Vec, - models_grpc_events(ModelsGrpcEventsReq) -> Vec, - models_get_settings(ModelsGetSettingsReq) -> Settings, - models_get_graphql_introspection(ModelsGetGraphqlIntrospectionReq) -> Option, - models_upsert_graphql_introspection(ModelsUpsertGraphqlIntrospectionReq) -> GraphQlIntrospection, - models_workspace_models(ModelsWorkspaceModelsReq) -> String, - cmd_git_checkout(CmdGitCheckoutReq) -> String, - cmd_git_branch(CmdGitBranchReq) -> (), - cmd_git_delete_branch(CmdGitDeleteBranchReq) -> BranchDeleteResult, - cmd_git_delete_remote_branch(CmdGitDeleteRemoteBranchReq) -> (), - cmd_git_merge_branch(CmdGitMergeBranchReq) -> (), - cmd_git_rename_branch(CmdGitRenameBranchReq) -> (), - cmd_git_status(CmdGitStatusReq) -> GitStatusSummary, - cmd_git_branch_info(CmdGitBranchInfoReq) -> GitBranchInfo, - cmd_git_worktree_status(CmdGitWorktreeStatusReq) -> GitWorktreeStatus, - cmd_git_log(CmdGitLogReq) -> Vec, - cmd_git_log_for_file(CmdGitLogForFileReq) -> Vec, - cmd_git_file_diff_for_commit(CmdGitFileDiffForCommitReq) -> GitFileDiff, - cmd_git_initialize(CmdGitInitializeReq) -> (), - cmd_git_clone(CmdGitCloneReq) -> CloneResult, - cmd_git_commit(CmdGitCommitReq) -> (), - cmd_git_fetch_all(CmdGitFetchAllReq) -> (), - cmd_git_push(CmdGitPushReq) -> PushResult, - cmd_git_pull(CmdGitPullReq) -> PullResult, - cmd_git_pull_force_reset(CmdGitPullForceResetReq) -> PullResult, - cmd_git_pull_merge(CmdGitPullMergeReq) -> PullResult, - cmd_git_add(CmdGitAddReq) -> (), - cmd_git_unstage(CmdGitUnstageReq) -> (), - cmd_git_reset_changes(CmdGitResetChangesReq) -> (), - cmd_git_restore_files(CmdGitRestoreFilesReq) -> (), - cmd_git_restore_file_from_commit(CmdGitRestoreFileFromCommitReq) -> (), - cmd_git_add_credential(CmdGitAddCredentialReq) -> (), - cmd_git_remotes(CmdGitRemotesReq) -> Vec, - cmd_git_add_remote(CmdGitAddRemoteReq) -> GitRemote, - cmd_git_rm_remote(CmdGitRmRemoteReq) -> (), - cmd_sync_calculate(CmdSyncCalculateReq) -> Vec, - cmd_sync_calculate_fs(CmdSyncCalculateFsReq) -> Vec, - cmd_sync_apply(CmdSyncApplyReq) -> (), - cmd_ws_delete_connections(CmdWsDeleteConnectionsReq) -> (), - cmd_ws_send(CmdWsSendReq) -> WebsocketConnection, - cmd_ws_close(CmdWsCloseReq) -> WebsocketConnection, - cmd_ws_connect(CmdWsConnectReq) -> WebsocketConnection, - cmd_plugins_search(CmdPluginsSearchReq) -> PluginSearchResponse, - cmd_plugins_install(CmdPluginsInstallReq) -> (), - cmd_plugins_install_from_directory(CmdPluginsInstallFromDirectoryReq) -> Plugin, - cmd_plugins_uninstall(CmdPluginsUninstallReq) -> Plugin, - cmd_plugin_init_errors(CmdPluginInitErrorsReq) -> Vec<(String, String)>, - cmd_plugins_updates(CmdPluginsUpdatesReq) -> PluginUpdatesResponse, - cmd_plugins_update_all(CmdPluginsUpdateAllReq) -> Vec, - cmd_git_watch_worktree_status(CmdGitWatchWorktreeStatusReq) -> GitWatchResult, - cmd_sync_watch(CmdSyncWatchReq) -> WatchResult, -} diff --git a/crates-tauri/yaak-app-client/src/sync_ext.rs b/crates-tauri/yaak-app-client/src/sync_ext.rs index 1d7e8c37..223573ce 100644 --- a/crates-tauri/yaak-app-client/src/sync_ext.rs +++ b/crates-tauri/yaak-app-client/src/sync_ext.rs @@ -6,11 +6,10 @@ use crate::error::Result; use crate::models_ext::{BlobManagerExt, QueryManagerExt}; use chrono::Utc; use log::warn; -use serde::{Deserialize, Serialize}; use std::path::Path; use tauri::{AppHandle, Listener, Runtime}; use tokio::sync::watch; -use ts_rs::TS; +use yaak_rpc_schema::WatchResult; use yaak_sync::error::Error::InvalidSyncDirectory; use yaak_sync::sync::{ FsCandidate, SyncOp, apply_sync_ops, apply_sync_state_ops, compute_sync_ops, get_db_candidates, @@ -57,13 +56,6 @@ pub(crate) async fn cmd_sync_apply( Ok(()) } -#[derive(Debug, Clone, Serialize, Deserialize, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export, export_to = "index.ts")] -pub(crate) struct WatchResult { - unlisten_event: String, -} - pub(crate) async fn sync_watch( app_handle: AppHandle, sync_dir: &Path, diff --git a/crates/common/yaak-rpc-schema/Cargo.toml b/crates/common/yaak-rpc-schema/Cargo.toml new file mode 100644 index 00000000..7e07b427 --- /dev/null +++ b/crates/common/yaak-rpc-schema/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "yaak-rpc-schema" +version = "0.0.0" +edition = "2024" +authors = ["Gregory Schier"] +publish = false + +[dependencies] +serde = { workspace = true, features = ["derive"] } +ts-rs = { workspace = true } +yaak-git = { workspace = true } +yaak-grpc = { workspace = true } +yaak-models = { workspace = true } +yaak-plugins = { workspace = true } +yaak-sse = { workspace = true } +yaak-sync = { workspace = true } +yaak-templates = { workspace = true } +yaak-ws = { workspace = true } diff --git a/crates/common/yaak-rpc-schema/README.md b/crates/common/yaak-rpc-schema/README.md new file mode 100644 index 00000000..d078c439 --- /dev/null +++ b/crates/common/yaak-rpc-schema/README.md @@ -0,0 +1,44 @@ +# yaak-rpc-schema + +The wire schema for the app's RPC surface: every command name, its request +payload, and its response type, declared once. + +Every host that serves the Yaak UI — the desktop app today, the browser bridge +and anything after it — imports these types and implements the commands against +them. That is what keeps a request's shape from drifting between hosts, and it +is why the TypeScript bindings (`bindings/gen_rpc.ts`, exposed to the frontend +as `@yaakapp-internal/rpc-schema`) are generated from one place. + +Nothing here depends on Tauri or on any host. Request structs are plain data, +and so are the few response types declared here rather than in an engine crate. +Command *bodies* live with the host that runs them. + +## Adding a command + +1. Add its request struct and an entry in `with_commands!` in `src/lib.rs`. +2. Write the adapter in each host — the desktop's live in + `crates-tauri/yaak-app-client/src/rpc_ext.rs`. A host that does not support + the command still has to say so; a missing adapter fails to compile. +3. Regenerate the bindings: `cargo test -p yaak-rpc-schema` writes + `bindings/gen_rpc.ts`, which is committed. + +## How hosts consume the list + +`with_commands!` takes the name of a `macro_rules!` macro and calls it with the +full `name(Req) -> Res` list. Each host writes a small macro that receives that +list and builds its router: + +```rust +macro_rules! register_commands { + ( $( $name:ident ( $req:ty ) -> $res:ty ),* $(,)? ) => { + pub fn build_router() -> RpcRouter { + let mut router = RpcRouter::new(); + $( router.register(stringify!($name), rpc_handler_async!($name)); )* + router + } + }; +} +yaak_rpc_schema::with_commands!(register_commands); +``` + +The schema decides *what* commands exist; the host decides *how* each one runs. diff --git a/crates-tauri/yaak-app-client/bindings/gen_api.ts b/crates/common/yaak-rpc-schema/bindings/gen_api.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_api.ts rename to crates/common/yaak-rpc-schema/bindings/gen_api.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_events.ts b/crates/common/yaak-rpc-schema/bindings/gen_events.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_events.ts rename to crates/common/yaak-rpc-schema/bindings/gen_events.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_git.ts b/crates/common/yaak-rpc-schema/bindings/gen_git.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_git.ts rename to crates/common/yaak-rpc-schema/bindings/gen_git.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_grpc.ts b/crates/common/yaak-rpc-schema/bindings/gen_grpc.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_grpc.ts rename to crates/common/yaak-rpc-schema/bindings/gen_grpc.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_models.ts b/crates/common/yaak-rpc-schema/bindings/gen_models.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_models.ts rename to crates/common/yaak-rpc-schema/bindings/gen_models.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_rpc.ts b/crates/common/yaak-rpc-schema/bindings/gen_rpc.ts similarity index 98% rename from crates-tauri/yaak-app-client/bindings/gen_rpc.ts rename to crates/common/yaak-rpc-schema/bindings/gen_rpc.ts index 721370cf..f94107fe 100644 --- a/crates-tauri/yaak-app-client/bindings/gen_rpc.ts +++ b/crates/common/yaak-rpc-schema/bindings/gen_rpc.ts @@ -7,10 +7,12 @@ import type { AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpReques import type { PluginMetadata } from "./gen_search"; import type { SyncOp } from "./gen_sync"; import type { BatchUpsertResult } from "./gen_util"; -import type { GitWatchResult, WatchResult } from "./index"; import type { Tokens } from "./parser"; import type { ServerSentEvent } from "./sse"; +/** + * What the frontend learns about the host it is talking to. + */ export type AppMetaData = { isDev: boolean, version: string, cliVersion: string | null, name: string, appDataDir: string, appLogDir: string, vendoredPluginDir: string, defaultProjectDir: string, featureUpdater: boolean, featureLicense: boolean, }; export type CmdCallFolderActionReq = { req: CallFolderActionRequest, }; @@ -222,6 +224,12 @@ export type CmdWsSendReq = { connectionId: string, environmentId: string | null, */ export type EphemeralHttpResponse = { response: HttpResponse, body: Array, }; +/** + * Returned by the two watch commands: the name of the event to emit to stop + * the watcher. + */ +export type GitWatchResult = { unlistenEvent: string, }; + export type ModelsDeleteReq = { model: AnyModel, }; export type ModelsDuplicateReq = { modelType: string, modelId: string, }; @@ -240,8 +248,6 @@ export type ModelsWebsocketEventsReq = { connectionId: string, }; export type ModelsWorkspaceModelsReq = { workspaceId: string | null, }; -/** - * The wire schema, exported to TypeScript. Field name = command name, - * tuple = (request payload, response payload). - */ export type RpcSchema = { cmd_metadata: [CmdMetadataReq, AppMetaData], cmd_template_tokens_to_string: [CmdTemplateTokensToStringReq, string], cmd_render_template: [CmdRenderTemplateReq, string], cmd_send_feedback: [CmdSendFeedbackReq, null], cmd_dismiss_notification: [CmdDismissNotificationReq, null], cmd_grpc_reflect: [CmdGrpcReflectReq, Array], cmd_grpc_go: [CmdGrpcGoReq, string], cmd_restart: [CmdRestartReq, null], cmd_send_ephemeral_request: [CmdSendEphemeralRequestReq, EphemeralHttpResponse], cmd_format_json: [CmdFormatJsonReq, string], cmd_format_graphql: [CmdFormatGraphqlReq, string], cmd_http_response_body: [CmdHttpResponseBodyReq, FilterResponse], cmd_http_response_body_path: [CmdHttpResponseBodyPathReq, string | null], cmd_http_request_body: [CmdHttpRequestBodyReq, Array | null], cmd_get_sse_events: [CmdGetSseEventsReq, Array], cmd_get_http_response_events: [CmdGetHttpResponseEventsReq, Array], cmd_import_data: [CmdImportDataReq, BatchUpsertResult], cmd_import_url: [CmdImportUrlReq, BatchUpsertResult], cmd_http_request_actions: [CmdHttpRequestActionsReq, Array], cmd_websocket_request_actions: [CmdWebsocketRequestActionsReq, Array], cmd_call_websocket_request_action: [CmdCallWebsocketRequestActionReq, null], cmd_workspace_actions: [CmdWorkspaceActionsReq, Array], cmd_call_workspace_action: [CmdCallWorkspaceActionReq, null], cmd_folder_actions: [CmdFolderActionsReq, Array], cmd_call_folder_action: [CmdCallFolderActionReq, null], cmd_grpc_request_actions: [CmdGrpcRequestActionsReq, Array], cmd_template_function_summaries: [CmdTemplateFunctionSummariesReq, Array], cmd_template_function_config: [CmdTemplateFunctionConfigReq, GetTemplateFunctionConfigResponse], cmd_get_http_authentication_summaries: [CmdGetHttpAuthenticationSummariesReq, Array], cmd_get_http_authentication_config: [CmdGetHttpAuthenticationConfigReq, GetHttpAuthenticationConfigResponse], cmd_call_http_request_action: [CmdCallHttpRequestActionReq, null], cmd_call_grpc_request_action: [CmdCallGrpcRequestActionReq, null], cmd_call_http_authentication_action: [CmdCallHttpAuthenticationActionReq, null], cmd_curl_to_request: [CmdCurlToRequestReq, HttpRequest], cmd_export_data: [CmdExportDataReq, null], cmd_save_base64_to_binary: [CmdSaveBase64ToBinaryReq, null], cmd_save_response: [CmdSaveResponseReq, null], cmd_send_http_request: [CmdSendHttpRequestReq, HttpResponse], cmd_reload_plugins: [CmdReloadPluginsReq, Array<[string, string]>], cmd_plugin_info: [CmdPluginInfoReq, PluginMetadata], cmd_delete_all_grpc_connections: [CmdDeleteAllGrpcConnectionsReq, null], cmd_delete_send_history: [CmdDeleteSendHistoryReq, null], cmd_delete_all_http_responses: [CmdDeleteAllHttpResponsesReq, null], cmd_get_workspace_meta: [CmdGetWorkspaceMetaReq, WorkspaceMeta], cmd_new_child_window: [CmdNewChildWindowReq, null], cmd_new_main_window: [CmdNewMainWindowReq, null], cmd_check_for_updates: [CmdCheckForUpdatesReq, boolean], cmd_decrypt_template: [CmdDecryptTemplateReq, string], cmd_secure_template: [CmdSecureTemplateReq, string], cmd_get_themes: [CmdGetThemesReq, Array], cmd_enable_encryption: [CmdEnableEncryptionReq, null], cmd_reveal_workspace_key: [CmdRevealWorkspaceKeyReq, string], cmd_set_workspace_key: [CmdSetWorkspaceKeyReq, null], cmd_disable_encryption: [CmdDisableEncryptionReq, null], cmd_default_headers: [CmdDefaultHeadersReq, Array], models_upsert: [ModelsUpsertReq, string], models_delete: [ModelsDeleteReq, string], models_duplicate: [ModelsDuplicateReq, string], models_websocket_events: [ModelsWebsocketEventsReq, Array], models_grpc_events: [ModelsGrpcEventsReq, Array], models_get_settings: [ModelsGetSettingsReq, Settings], models_get_graphql_introspection: [ModelsGetGraphqlIntrospectionReq, GraphQlIntrospection | null], models_upsert_graphql_introspection: [ModelsUpsertGraphqlIntrospectionReq, GraphQlIntrospection], models_workspace_models: [ModelsWorkspaceModelsReq, string], cmd_git_checkout: [CmdGitCheckoutReq, string], cmd_git_branch: [CmdGitBranchReq, null], cmd_git_delete_branch: [CmdGitDeleteBranchReq, BranchDeleteResult], cmd_git_delete_remote_branch: [CmdGitDeleteRemoteBranchReq, null], cmd_git_merge_branch: [CmdGitMergeBranchReq, null], cmd_git_rename_branch: [CmdGitRenameBranchReq, null], cmd_git_status: [CmdGitStatusReq, GitStatusSummary], cmd_git_branch_info: [CmdGitBranchInfoReq, GitBranchInfo], cmd_git_worktree_status: [CmdGitWorktreeStatusReq, GitWorktreeStatus], cmd_git_log: [CmdGitLogReq, Array], cmd_git_log_for_file: [CmdGitLogForFileReq, Array], cmd_git_file_diff_for_commit: [CmdGitFileDiffForCommitReq, GitFileDiff], cmd_git_initialize: [CmdGitInitializeReq, null], cmd_git_clone: [CmdGitCloneReq, CloneResult], cmd_git_commit: [CmdGitCommitReq, null], cmd_git_fetch_all: [CmdGitFetchAllReq, null], cmd_git_push: [CmdGitPushReq, PushResult], cmd_git_pull: [CmdGitPullReq, PullResult], cmd_git_pull_force_reset: [CmdGitPullForceResetReq, PullResult], cmd_git_pull_merge: [CmdGitPullMergeReq, PullResult], cmd_git_add: [CmdGitAddReq, null], cmd_git_unstage: [CmdGitUnstageReq, null], cmd_git_reset_changes: [CmdGitResetChangesReq, null], cmd_git_restore_files: [CmdGitRestoreFilesReq, null], cmd_git_restore_file_from_commit: [CmdGitRestoreFileFromCommitReq, null], cmd_git_add_credential: [CmdGitAddCredentialReq, null], cmd_git_remotes: [CmdGitRemotesReq, Array], cmd_git_add_remote: [CmdGitAddRemoteReq, GitRemote], cmd_git_rm_remote: [CmdGitRmRemoteReq, null], cmd_sync_calculate: [CmdSyncCalculateReq, Array], cmd_sync_calculate_fs: [CmdSyncCalculateFsReq, Array], cmd_sync_apply: [CmdSyncApplyReq, null], cmd_ws_delete_connections: [CmdWsDeleteConnectionsReq, null], cmd_ws_send: [CmdWsSendReq, WebsocketConnection], cmd_ws_close: [CmdWsCloseReq, WebsocketConnection], cmd_ws_connect: [CmdWsConnectReq, WebsocketConnection], cmd_plugins_search: [CmdPluginsSearchReq, PluginSearchResponse], cmd_plugins_install: [CmdPluginsInstallReq, null], cmd_plugins_install_from_directory: [CmdPluginsInstallFromDirectoryReq, Plugin], cmd_plugins_uninstall: [CmdPluginsUninstallReq, Plugin], cmd_plugin_init_errors: [CmdPluginInitErrorsReq, Array<[string, string]>], cmd_plugins_updates: [CmdPluginsUpdatesReq, PluginUpdatesResponse], cmd_plugins_update_all: [CmdPluginsUpdateAllReq, Array], cmd_git_watch_worktree_status: [CmdGitWatchWorktreeStatusReq, GitWatchResult], cmd_sync_watch: [CmdSyncWatchReq, WatchResult], }; + +export type WatchResult = { unlistenEvent: string, }; diff --git a/crates-tauri/yaak-app-client/bindings/gen_search.ts b/crates/common/yaak-rpc-schema/bindings/gen_search.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_search.ts rename to crates/common/yaak-rpc-schema/bindings/gen_search.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_sync.ts b/crates/common/yaak-rpc-schema/bindings/gen_sync.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_sync.ts rename to crates/common/yaak-rpc-schema/bindings/gen_sync.ts diff --git a/crates-tauri/yaak-app-client/bindings/gen_util.ts b/crates/common/yaak-rpc-schema/bindings/gen_util.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/gen_util.ts rename to crates/common/yaak-rpc-schema/bindings/gen_util.ts diff --git a/crates-tauri/yaak-app-client/bindings/parser.ts b/crates/common/yaak-rpc-schema/bindings/parser.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/parser.ts rename to crates/common/yaak-rpc-schema/bindings/parser.ts diff --git a/crates-tauri/yaak-app-client/bindings/sse.ts b/crates/common/yaak-rpc-schema/bindings/sse.ts similarity index 100% rename from crates-tauri/yaak-app-client/bindings/sse.ts rename to crates/common/yaak-rpc-schema/bindings/sse.ts diff --git a/crates/common/yaak-rpc-schema/index.ts b/crates/common/yaak-rpc-schema/index.ts new file mode 100644 index 00000000..811ff4de --- /dev/null +++ b/crates/common/yaak-rpc-schema/index.ts @@ -0,0 +1,4 @@ +// The RPC wire schema, generated by ts-rs from the Rust declarations in +// src/lib.rs. `RpcSchema` maps every command name to its (request, response) +// pair; the app's `rpc()` helper derives its command union from it. +export * from "./bindings/gen_rpc"; diff --git a/crates/common/yaak-rpc-schema/package.json b/crates/common/yaak-rpc-schema/package.json new file mode 100644 index 00000000..adc1d72b --- /dev/null +++ b/crates/common/yaak-rpc-schema/package.json @@ -0,0 +1,6 @@ +{ + "name": "@yaakapp-internal/rpc-schema", + "version": "1.0.0", + "private": true, + "main": "index.ts" +} diff --git a/crates/common/yaak-rpc-schema/src/lib.rs b/crates/common/yaak-rpc-schema/src/lib.rs new file mode 100644 index 00000000..79416228 --- /dev/null +++ b/crates/common/yaak-rpc-schema/src/lib.rs @@ -0,0 +1,1021 @@ +//! The wire schema for the app's RPC surface: every command name, its request +//! payload, and its response type. +//! +//! This is the one place the frontend contract is declared. Each host — the +//! desktop app, the bridge, anything that comes later — imports these types and +//! implements the commands against them, so the shape of a request cannot +//! drift between hosts and the TypeScript bindings are generated once. +//! +//! Nothing here depends on Tauri or on any host. Request structs are plain data +//! and the few response types declared here (rather than in an engine crate) +//! are too. Command *bodies* live with the host that runs them. + +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::path::PathBuf; +use ts_rs::TS; +use yaak_git::{ + BranchDeleteResult, CloneResult, GitBranchInfo, GitCommit, GitFileDiff, GitRemote, + GitStatusSummary, GitWorktreeStatus, PullResult, PushResult, +}; +use yaak_grpc::ServiceDefinition; +use yaak_models::models::{ + AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, + HttpResponseEvent, Plugin, Settings, WebsocketConnection, WebsocketEvent, WorkspaceMeta, +}; +use yaak_models::util::BatchUpsertResult; +use yaak_plugins::api::{PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse}; +use yaak_plugins::events::{ + CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest, + CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse, + GetFolderActionsResponse, GetGrpcRequestActionsResponse, + GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, + GetHttpRequestActionsResponse, GetTemplateFunctionConfigResponse, + GetTemplateFunctionSummaryResponse, GetThemesResponse, GetWebsocketRequestActionsResponse, + GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose, +}; +use yaak_plugins::plugin_meta::PluginMetadata; +use yaak_sse::sse::ServerSentEvent; +use yaak_sync::sync::SyncOp; +use yaak_templates::Tokens; + +// -- Response types that belong to the schema rather than to an engine crate -- + +/// What the frontend learns about the host it is talking to. +#[derive(Debug, Default, Serialize, TS)] +#[serde(default, rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct AppMetaData { + pub is_dev: bool, + pub version: String, + pub cli_version: Option, + pub name: String, + pub app_data_dir: String, + pub app_log_dir: String, + pub vendored_plugin_dir: String, + pub default_project_dir: String, + pub feature_updater: bool, + pub feature_license: bool, +} + +/// Returned by the two watch commands: the name of the event to emit to stop +/// the watcher. +#[derive(Debug, Clone, Serialize, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct GitWatchResult { + pub unlisten_event: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct WatchResult { + pub unlisten_event: String, +} + +// -- Request payloads -- + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitWatchWorktreeStatusReq { + pub dir: PathBuf, + pub stream_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSyncWatchReq { + pub sync_dir: PathBuf, + pub workspace_id: String, + pub stream_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdMetadataReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdTemplateTokensToStringReq { + pub tokens: Tokens, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdRenderTemplateReq { + pub template: String, + pub workspace_id: String, + pub environment_id: Option, + pub purpose: Option, + pub ignore_error: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSendFeedbackReq { + pub feature: String, + pub text: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDismissNotificationReq { + pub notification_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGrpcReflectReq { + pub request_id: String, + pub environment_id: Option, + pub proto_files: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGrpcGoReq { + pub request_id: String, + pub environment_id: Option, + pub proto_files: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdRestartReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSendEphemeralRequestReq { + pub request: HttpRequest, + pub environment_id: Option, + pub cookie_jar_id: Option, +} + +/// An unsaved response and its body. +/// +/// The body rides along because nothing stored it: there is no database row to +/// look up later and no file for a host to read, so this is the caller's only +/// copy. +#[derive(Debug, Serialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct EphemeralHttpResponse { + pub response: HttpResponse, + pub body: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdFormatJsonReq { + pub text: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdFormatGraphqlReq { + pub text: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdHttpResponseBodyReq { + pub response_id: String, + pub filter: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdHttpResponseBodyPathReq { + pub response_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdHttpRequestBodyReq { + pub response_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetSseEventsReq { + pub response_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetHttpResponseEventsReq { + pub response_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdImportDataReq { + pub file_path: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdImportUrlReq { + pub url: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdHttpRequestActionsReq {} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWebsocketRequestActionsReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallWebsocketRequestActionReq { + pub req: CallWebsocketRequestActionRequest, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWorkspaceActionsReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallWorkspaceActionReq { + pub req: CallWorkspaceActionRequest, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdFolderActionsReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallFolderActionReq { + pub req: CallFolderActionRequest, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGrpcRequestActionsReq {} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdTemplateFunctionSummariesReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdTemplateFunctionConfigReq { + pub function_name: String, + pub values: HashMap, + pub model: AnyModel, + pub environment_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetHttpAuthenticationSummariesReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetHttpAuthenticationConfigReq { + pub auth_name: String, + pub values: HashMap, + pub model: AnyModel, + pub environment_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallHttpRequestActionReq { + pub req: CallHttpRequestActionRequest, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallGrpcRequestActionReq { + pub req: CallGrpcRequestActionRequest, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCallHttpAuthenticationActionReq { + pub auth_name: String, + pub action_index: i32, + pub values: HashMap, + pub model: AnyModel, + pub environment_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCurlToRequestReq { + pub command: String, + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdExportDataReq { + pub export_path: String, + pub workspace_ids: Vec, + pub include_private_environments: bool, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSaveBase64ToBinaryReq { + pub filepath: String, + pub data: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSaveResponseReq { + pub response_id: String, + pub filepath: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSendHttpRequestReq { + pub environment_id: Option, + pub cookie_jar_id: Option, + pub request_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdReloadPluginsReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginInfoReq { + pub id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDeleteAllGrpcConnectionsReq { + pub request_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDeleteSendHistoryReq { + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDeleteAllHttpResponsesReq { + pub request_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetWorkspaceMetaReq { + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdNewChildWindowReq { + pub url: String, + pub label: String, + pub title: String, + pub inner_size: (f64, f64), +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdNewMainWindowReq { + pub url: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdCheckForUpdatesReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDecryptTemplateReq { + pub template: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSecureTemplateReq { + pub template: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGetThemesReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdEnableEncryptionReq { + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdRevealWorkspaceKeyReq { + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSetWorkspaceKeyReq { + pub workspace_id: String, + pub key: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDisableEncryptionReq { + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdDefaultHeadersReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsUpsertReq { + pub model: AnyModel, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsDeleteReq { + pub model: AnyModel, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsDuplicateReq { + pub model_type: String, + pub model_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsWebsocketEventsReq { + pub connection_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsGrpcEventsReq { + pub connection_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsGetSettingsReq {} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsGetGraphqlIntrospectionReq { + pub request_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsUpsertGraphqlIntrospectionReq { + pub request_id: String, + pub workspace_id: String, + pub content: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct ModelsWorkspaceModelsReq { + pub workspace_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitCheckoutReq { + pub dir: PathBuf, + pub branch: String, + pub force: bool, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitBranchReq { + pub dir: PathBuf, + pub branch: String, + pub base: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitDeleteBranchReq { + pub dir: PathBuf, + pub branch: String, + pub force: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitDeleteRemoteBranchReq { + pub dir: PathBuf, + pub branch: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitMergeBranchReq { + pub dir: PathBuf, + pub branch: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitRenameBranchReq { + pub dir: PathBuf, + pub old_name: String, + pub new_name: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitStatusReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitBranchInfoReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitWorktreeStatusReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitLogReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitLogForFileReq { + pub dir: PathBuf, + pub rela_path: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitFileDiffForCommitReq { + pub dir: PathBuf, + pub commit_oid: String, + pub rela_path: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitInitializeReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitCloneReq { + pub url: String, + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitCommitReq { + pub dir: PathBuf, + pub message: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitFetchAllReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitPushReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitPullReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitPullForceResetReq { + pub dir: PathBuf, + pub remote: String, + pub branch: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitPullMergeReq { + pub dir: PathBuf, + pub remote: String, + pub branch: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitAddReq { + pub dir: PathBuf, + pub rela_paths: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitUnstageReq { + pub dir: PathBuf, + pub rela_paths: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitResetChangesReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitRestoreFilesReq { + pub dir: PathBuf, + pub rela_paths: Vec, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitRestoreFileFromCommitReq { + pub dir: PathBuf, + pub commit_oid: String, + pub rela_path: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitAddCredentialReq { + pub remote_url: String, + pub username: String, + pub password: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitRemotesReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitAddRemoteReq { + pub dir: PathBuf, + pub name: String, + pub url: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdGitRmRemoteReq { + pub dir: PathBuf, + pub name: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSyncCalculateReq { + pub workspace_id: String, + pub sync_dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSyncCalculateFsReq { + pub dir: PathBuf, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdSyncApplyReq { + pub sync_ops: Vec, + pub sync_dir: PathBuf, + pub workspace_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWsDeleteConnectionsReq { + pub request_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWsSendReq { + pub connection_id: String, + pub environment_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWsCloseReq { + pub connection_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdWsConnectReq { + pub request_id: String, + pub environment_id: Option, + pub cookie_jar_id: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsSearchReq { + pub query: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsInstallReq { + pub name: String, + pub version: Option, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsInstallFromDirectoryReq { + pub directory: String, +} + +#[derive(Debug, Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsUninstallReq { + pub plugin_id: String, +} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginInitErrorsReq {} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsUpdatesReq {} + +#[derive(Debug, Deserialize, TS)] +#[ts(export, export_to = "gen_rpc.ts")] +pub struct CmdPluginsUpdateAllReq {} + +// -- The command list -- + +/// Declare the command list once, then hand it to a host. +/// +/// Every host builds its router from the same list by passing a macro of its +/// own that receives `name(ReqType) -> ResType` triples: the schema stays the +/// single source of truth for *what* commands exist, and each host decides +/// *how* — which handler runs, or whether the command is unsupported there. +/// +/// ```ignore +/// macro_rules! register { ( $( $name:ident ( $req:ty ) -> $res:ty ),* $(,)? ) => { ... } } +/// yaak_rpc_schema::with_commands!(register); +/// ``` +#[macro_export] +macro_rules! with_commands { + ($callback:ident) => { + $callback! { + cmd_metadata(CmdMetadataReq) -> AppMetaData, + cmd_template_tokens_to_string(CmdTemplateTokensToStringReq) -> String, + cmd_render_template(CmdRenderTemplateReq) -> String, + cmd_send_feedback(CmdSendFeedbackReq) -> (), + cmd_dismiss_notification(CmdDismissNotificationReq) -> (), + cmd_grpc_reflect(CmdGrpcReflectReq) -> Vec, + cmd_grpc_go(CmdGrpcGoReq) -> String, + cmd_restart(CmdRestartReq) -> (), + cmd_send_ephemeral_request(CmdSendEphemeralRequestReq) -> EphemeralHttpResponse, + cmd_format_json(CmdFormatJsonReq) -> String, + cmd_format_graphql(CmdFormatGraphqlReq) -> String, + cmd_http_response_body(CmdHttpResponseBodyReq) -> FilterResponse, + cmd_http_response_body_path(CmdHttpResponseBodyPathReq) -> Option, + cmd_http_request_body(CmdHttpRequestBodyReq) -> Option>, + cmd_get_sse_events(CmdGetSseEventsReq) -> Vec, + cmd_get_http_response_events(CmdGetHttpResponseEventsReq) -> Vec, + cmd_import_data(CmdImportDataReq) -> BatchUpsertResult, + cmd_import_url(CmdImportUrlReq) -> BatchUpsertResult, + cmd_http_request_actions(CmdHttpRequestActionsReq) -> Vec, + cmd_websocket_request_actions(CmdWebsocketRequestActionsReq) -> Vec, + cmd_call_websocket_request_action(CmdCallWebsocketRequestActionReq) -> (), + cmd_workspace_actions(CmdWorkspaceActionsReq) -> Vec, + cmd_call_workspace_action(CmdCallWorkspaceActionReq) -> (), + cmd_folder_actions(CmdFolderActionsReq) -> Vec, + cmd_call_folder_action(CmdCallFolderActionReq) -> (), + cmd_grpc_request_actions(CmdGrpcRequestActionsReq) -> Vec, + cmd_template_function_summaries(CmdTemplateFunctionSummariesReq) -> Vec, + cmd_template_function_config(CmdTemplateFunctionConfigReq) -> GetTemplateFunctionConfigResponse, + cmd_get_http_authentication_summaries(CmdGetHttpAuthenticationSummariesReq) -> Vec, + cmd_get_http_authentication_config(CmdGetHttpAuthenticationConfigReq) -> GetHttpAuthenticationConfigResponse, + cmd_call_http_request_action(CmdCallHttpRequestActionReq) -> (), + cmd_call_grpc_request_action(CmdCallGrpcRequestActionReq) -> (), + cmd_call_http_authentication_action(CmdCallHttpAuthenticationActionReq) -> (), + cmd_curl_to_request(CmdCurlToRequestReq) -> HttpRequest, + cmd_export_data(CmdExportDataReq) -> (), + cmd_save_base64_to_binary(CmdSaveBase64ToBinaryReq) -> (), + cmd_save_response(CmdSaveResponseReq) -> (), + cmd_send_http_request(CmdSendHttpRequestReq) -> HttpResponse, + cmd_reload_plugins(CmdReloadPluginsReq) -> Vec<(String, String)>, + cmd_plugin_info(CmdPluginInfoReq) -> PluginMetadata, + cmd_delete_all_grpc_connections(CmdDeleteAllGrpcConnectionsReq) -> (), + cmd_delete_send_history(CmdDeleteSendHistoryReq) -> (), + cmd_delete_all_http_responses(CmdDeleteAllHttpResponsesReq) -> (), + cmd_get_workspace_meta(CmdGetWorkspaceMetaReq) -> WorkspaceMeta, + cmd_new_child_window(CmdNewChildWindowReq) -> (), + cmd_new_main_window(CmdNewMainWindowReq) -> (), + cmd_check_for_updates(CmdCheckForUpdatesReq) -> bool, + cmd_decrypt_template(CmdDecryptTemplateReq) -> String, + cmd_secure_template(CmdSecureTemplateReq) -> String, + cmd_get_themes(CmdGetThemesReq) -> Vec, + cmd_enable_encryption(CmdEnableEncryptionReq) -> (), + cmd_reveal_workspace_key(CmdRevealWorkspaceKeyReq) -> String, + cmd_set_workspace_key(CmdSetWorkspaceKeyReq) -> (), + cmd_disable_encryption(CmdDisableEncryptionReq) -> (), + cmd_default_headers(CmdDefaultHeadersReq) -> Vec, + models_upsert(ModelsUpsertReq) -> String, + models_delete(ModelsDeleteReq) -> String, + models_duplicate(ModelsDuplicateReq) -> String, + models_websocket_events(ModelsWebsocketEventsReq) -> Vec, + models_grpc_events(ModelsGrpcEventsReq) -> Vec, + models_get_settings(ModelsGetSettingsReq) -> Settings, + models_get_graphql_introspection(ModelsGetGraphqlIntrospectionReq) -> Option, + models_upsert_graphql_introspection(ModelsUpsertGraphqlIntrospectionReq) -> GraphQlIntrospection, + models_workspace_models(ModelsWorkspaceModelsReq) -> String, + cmd_git_checkout(CmdGitCheckoutReq) -> String, + cmd_git_branch(CmdGitBranchReq) -> (), + cmd_git_delete_branch(CmdGitDeleteBranchReq) -> BranchDeleteResult, + cmd_git_delete_remote_branch(CmdGitDeleteRemoteBranchReq) -> (), + cmd_git_merge_branch(CmdGitMergeBranchReq) -> (), + cmd_git_rename_branch(CmdGitRenameBranchReq) -> (), + cmd_git_status(CmdGitStatusReq) -> GitStatusSummary, + cmd_git_branch_info(CmdGitBranchInfoReq) -> GitBranchInfo, + cmd_git_worktree_status(CmdGitWorktreeStatusReq) -> GitWorktreeStatus, + cmd_git_log(CmdGitLogReq) -> Vec, + cmd_git_log_for_file(CmdGitLogForFileReq) -> Vec, + cmd_git_file_diff_for_commit(CmdGitFileDiffForCommitReq) -> GitFileDiff, + cmd_git_initialize(CmdGitInitializeReq) -> (), + cmd_git_clone(CmdGitCloneReq) -> CloneResult, + cmd_git_commit(CmdGitCommitReq) -> (), + cmd_git_fetch_all(CmdGitFetchAllReq) -> (), + cmd_git_push(CmdGitPushReq) -> PushResult, + cmd_git_pull(CmdGitPullReq) -> PullResult, + cmd_git_pull_force_reset(CmdGitPullForceResetReq) -> PullResult, + cmd_git_pull_merge(CmdGitPullMergeReq) -> PullResult, + cmd_git_add(CmdGitAddReq) -> (), + cmd_git_unstage(CmdGitUnstageReq) -> (), + cmd_git_reset_changes(CmdGitResetChangesReq) -> (), + cmd_git_restore_files(CmdGitRestoreFilesReq) -> (), + cmd_git_restore_file_from_commit(CmdGitRestoreFileFromCommitReq) -> (), + cmd_git_add_credential(CmdGitAddCredentialReq) -> (), + cmd_git_remotes(CmdGitRemotesReq) -> Vec, + cmd_git_add_remote(CmdGitAddRemoteReq) -> GitRemote, + cmd_git_rm_remote(CmdGitRmRemoteReq) -> (), + cmd_sync_calculate(CmdSyncCalculateReq) -> Vec, + cmd_sync_calculate_fs(CmdSyncCalculateFsReq) -> Vec, + cmd_sync_apply(CmdSyncApplyReq) -> (), + cmd_ws_delete_connections(CmdWsDeleteConnectionsReq) -> (), + cmd_ws_send(CmdWsSendReq) -> WebsocketConnection, + cmd_ws_close(CmdWsCloseReq) -> WebsocketConnection, + cmd_ws_connect(CmdWsConnectReq) -> WebsocketConnection, + cmd_plugins_search(CmdPluginsSearchReq) -> PluginSearchResponse, + cmd_plugins_install(CmdPluginsInstallReq) -> (), + cmd_plugins_install_from_directory(CmdPluginsInstallFromDirectoryReq) -> Plugin, + cmd_plugins_uninstall(CmdPluginsUninstallReq) -> Plugin, + cmd_plugin_init_errors(CmdPluginInitErrorsReq) -> Vec<(String, String)>, + cmd_plugins_updates(CmdPluginsUpdatesReq) -> PluginUpdatesResponse, + cmd_plugins_update_all(CmdPluginsUpdateAllReq) -> Vec, + cmd_git_watch_worktree_status(CmdGitWatchWorktreeStatusReq) -> GitWatchResult, + cmd_sync_watch(CmdSyncWatchReq) -> WatchResult, + } + }; +} + +// The TypeScript export: field name = command name, tuple = (request, response). +// Generated from the same list the hosts build their routers from. +macro_rules! declare_schema { + ( $( $name:ident ( $req:ty ) -> $res:ty ),* $(,)? ) => { + #[derive(TS)] + #[ts(export, export_to = "gen_rpc.ts")] + #[allow(non_snake_case, unused)] + pub struct RpcSchema { + $( pub $name: ($req, $res), )* + } + }; +} +with_commands!(declare_schema); diff --git a/crates/yaak-sync/index.ts b/crates/yaak-sync/index.ts index eabf7e7d..cb8bf087 100644 --- a/crates/yaak-sync/index.ts +++ b/crates/yaak-sync/index.ts @@ -1,5 +1,5 @@ import { platform } from "@yaakapp-internal/platform"; -import type { WatchResult } from "@yaakapp-internal/tauri-client"; +import type { WatchResult } from "@yaakapp-internal/rpc-schema"; import { SyncOp } from "./bindings/gen_sync"; import { WatchEvent } from "./bindings/gen_watch"; diff --git a/package.json b/package.json index 135ad25c..9d793088 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "crates-tauri/yaak-fonts", "crates-tauri/yaak-license", "crates-tauri/yaak-mac-window", + "crates/common/yaak-rpc-schema", "crates/yaak-crypto", "crates/yaak-git", "crates/yaak-models",