Skip to main content

Mountain/Track/Effect/CreateEffectForRequest/Utilities/
Proxy.rs

1//! Cocoon-proxy helper for `CreateEffectForRequest` handlers that forward
2//! calls to the Cocoon Node.js sidecar via `IPCProvider::SendRequestToSideCar`.
3//!
4//! All 17 proxy handlers follow the same skeleton; `proxy_cocoon` collapses
5//! the repeated `Require()` / `format!` / `SendRequestToSideCar` boilerplate
6//! into a single await-able call. The caller retains the fallback / dev_log
7//! choice since error values differ per handler.
8
9use std::sync::Arc;
10
11use CommonLibrary::{
12	Environment::Requires::Requires,
13	IPC::{DTO::ProxyTarget::ProxyTarget, IPCProvider::IPCProvider as IPCProviderTrait},
14};
15use serde_json::Value;
16
17use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
18
19pub async fn proxy_cocoon(
20	run_time:&Arc<ApplicationRunTime>,
21
22	target:ProxyTarget,
23
24	method_suffix:&str,
25
26	params:Value,
27
28	timeout_ms:u64,
29) -> Result<Value, String> {
30	let ipc:Arc<dyn IPCProviderTrait> = run_time.Environment.Require();
31
32	let method = format!("{}${}", target.GetTargetPrefix(), method_suffix);
33
34	ipc.SendRequestToSideCar("cocoon-main".to_string(), method, params, timeout_ms)
35		.await
36		.map_err(|e| e.to_string())
37}