mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-16 23:01:31 +02:00
Share one exporter, and flush the file before saying it is written (#686)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
caeebebc75
commit
f827aae46d
@@ -3,7 +3,7 @@
|
||||
use crate::error::Result;
|
||||
use crate::host::Host;
|
||||
use yaak::example::create_example_workspace;
|
||||
use yaak::export::{self, ExportDataParams};
|
||||
use yaak_models::export::{self, ExportDataParams};
|
||||
use yaak_models::util::BatchUpsertResult;
|
||||
use yaak_rpc_schema::*;
|
||||
use yaak_templates::format_json::format_json;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
use crate::Result;
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
use yaak_models::util::get_workspace_export_resources;
|
||||
//! Building an export document.
|
||||
//!
|
||||
//! Here rather than in `yaak` because the whole of it is this crate: a connection, the
|
||||
//! resources, and JSON. Putting it where the browser can reach it too is what keeps a
|
||||
//! tab's export from being a second implementation that drifts.
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::query_manager::QueryManager;
|
||||
use crate::util::get_workspace_export_resources;
|
||||
|
||||
pub struct ExportDataParams<'a> {
|
||||
pub query_manager: &'a QueryManager,
|
||||
@@ -12,8 +18,8 @@ pub struct ExportDataParams<'a> {
|
||||
/// The export document, as JSON.
|
||||
///
|
||||
/// Returned rather than written: where an export goes is the host's to decide, and a browser
|
||||
/// tab has no path to be handed. The desktop hands the bytes to its save dialog; a tab hands
|
||||
/// them to a download. Neither needs this function to know which.
|
||||
/// tab has no path to be handed. The desktop hands the bytes to its save dialog, the CLI
|
||||
/// writes them, a tab downloads them. None of that is this function's business.
|
||||
pub fn export_data(params: ExportDataParams<'_>) -> Result<String> {
|
||||
let db = params.query_manager.connect();
|
||||
let export_data = get_workspace_export_resources(
|
||||
@@ -13,6 +13,7 @@ pub mod client_db;
|
||||
mod connection_or_tx;
|
||||
pub mod cookies;
|
||||
pub mod error;
|
||||
pub mod export;
|
||||
pub mod migrate;
|
||||
pub mod models;
|
||||
pub mod models_ops;
|
||||
|
||||
@@ -697,22 +697,22 @@ export function __wbg_warn_b6f36cac66fc96a4(arg0, arg1) {
|
||||
console.warn(arg0, arg1);
|
||||
}
|
||||
export function __wbindgen_cast_0000000000000001(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1115, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1116, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9b5275515258a0f8___convert__closures_____invoke___wasm_bindgen_9b5275515258a0f8___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_9b5275515258a0f8___JsError___true_);
|
||||
return ret;
|
||||
}
|
||||
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 207, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 206, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9b5275515258a0f8___convert__closures_____invoke___web_sys_e1a11cd1518a8b4d___features__gen_Event__Event______true_);
|
||||
return ret;
|
||||
}
|
||||
export function __wbindgen_cast_0000000000000003(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 172, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 113, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9b5275515258a0f8___convert__closures_____invoke___web_sys_e1a11cd1518a8b4d___features__gen_IdbVersionChangeEvent__IdbVersionChangeEvent__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_9b5275515258a0f8___JsValue___true_);
|
||||
return ret;
|
||||
}
|
||||
export function __wbindgen_cast_0000000000000004(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 209, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 208, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_9b5275515258a0f8___convert__closures_____invoke_______true_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Binary file not shown.
+11
-11
@@ -416,20 +416,20 @@ fn dispatch(
|
||||
to_json(())
|
||||
}
|
||||
|
||||
// The export document, built by the same `yaak-models` helper the desktop and the CLI
|
||||
// build it with. Nothing about what an export *is* is decided here — this host only
|
||||
// differs in what happens to the bytes afterwards, which is the tab's business.
|
||||
// The same `export_data` the desktop and the CLI call, not a second copy of its
|
||||
// steps. Nothing about what an export *is* is decided here; this host differs only
|
||||
// in what happens to the bytes afterwards, which is the tab's business.
|
||||
"cmd_export_data" => {
|
||||
let req: ExportDataReq = from_js(payload)?;
|
||||
let db = host.queries.connect();
|
||||
let export = yaak_models::util::get_workspace_export_resources(
|
||||
&db,
|
||||
EXPORT_VERSION,
|
||||
req.workspace_ids.iter().map(|s| s.as_str()).collect(),
|
||||
req.include_private_environments,
|
||||
to_json(
|
||||
yaak_models::export::export_data(yaak_models::export::ExportDataParams {
|
||||
query_manager: &host.queries,
|
||||
yaak_version: EXPORT_VERSION,
|
||||
workspace_ids: req.workspace_ids.iter().map(|s| s.as_str()).collect(),
|
||||
include_private_environments: req.include_private_environments,
|
||||
})
|
||||
.map_err(js_error)?,
|
||||
)
|
||||
.map_err(js_error)?;
|
||||
to_json(serde_json::to_string_pretty(&export).map_err(js_error)?)
|
||||
}
|
||||
|
||||
"cmd_get_workspace_meta" => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod error;
|
||||
pub mod example;
|
||||
pub mod export;
|
||||
pub mod import;
|
||||
pub mod plugin_events;
|
||||
pub mod response_body;
|
||||
|
||||
Reference in New Issue
Block a user