Mountain/Binary/IPC/
UpdateSubscriptionCommand.rs

1//! # UpdateSubscriptionCommand
2//!
3//! Manages update subscriptions for document synchronization.
4//!
5//! ## RESPONSIBILITIES
6//!
7//! ### Subscription Management
8//! - Subscribe to document updates
9//! - Manage subscription targets
10//! - Track subscriber information
11//! - Validate subscription parameters
12//!
13//! ## ARCHITECTURAL ROLE
14//!
15//! ### Position in Mountain
16//! - IPC wrapper command in Binary subsystem
17//! - Update subscription endpoint
18//!
19//! ### Dependencies
20//! - crate::IPC::WindAdvancedSync: Subscription management
21//! - tauri: IPC framework
22//! - serde_json: JSON serialization
23//! - log: Logging framework
24//!
25//! ### Dependents
26//! - Wind frontend: Subscribes to updates
27//!
28//! ## SECURITY
29//!
30//! ### Considerations
31//! - Validate target and subscriber identifiers
32//! - Implement authorization for subscriptions
33//! - Prevent duplicate subscriptions
34//!
35//! ## PERFORMANCE
36//!
37//! ### Considerations
38//! - Subscription operations should be fast
39//! - Consider batching for bulk subscriptions
40
41use log::error;
42use serde_json::Value;
43use tauri::AppHandle;
44
45/// Subscribe to updates.
46///
47/// Subscribes a subscriber to receive updates for a target.
48///
49/// # Arguments
50///
51/// * `app_handle` - Tauri application handle
52/// * `subscription_data` - JSON object with target and subscriber fields
53///
54/// # Returns
55///
56/// Returns success JSON or an error string.
57///
58/// # Errors
59///
60/// Returns an error if:
61/// - Required fields missing
62/// - Subscription fails
63#[tauri::command]
64pub async fn MountainSubscribeToUpdates(app_handle:AppHandle, subscription_data:Value) -> Result<Value, String> {
65	let Target = subscription_data["target"]
66		.as_str()
67		.ok_or_else(|| {
68			error!("[IPC] [Sync] Missing target in subscription_data");
69			"Missing target"
70		})?
71		.to_string();
72	let Subscriber = subscription_data["subscriber"]
73		.as_str()
74		.ok_or_else(|| {
75			error!("[IPC] [Sync] Missing subscriber in subscription_data");
76			"Missing subscriber"
77		})?
78		.to_string();
79
80	crate::IPC::WindAdvancedSync::mountain_subscribe_to_updates(app_handle, Target, Subscriber)
81		.await
82		.map_err(|Error| {
83			error!("[IPC] [Sync] Failed to subscribe to updates: {}", Error);
84			Error.to_string()
85		})
86		.map(|_| Value::Null)
87}