Skip to main content

arora_websocket/
method.rs

1//! RPC method metadata types for the Arora protocol.
2
3use arora_types::value::{Type, Value};
4use serde::{Deserialize, Serialize};
5
6/// Descriptor for an RPC method parameter.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct MethodParam {
9    /// Parameter name
10    pub name: String,
11
12    /// Parameter type
13    pub param_type: Type,
14
15    /// Whether this parameter is required
16    #[serde(default)]
17    pub required: bool,
18
19    /// Default value if not provided
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub default_value: Option<Value>,
22
23    /// Human-readable description
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub description: Option<String>,
26}
27
28/// Metadata describing an available RPC method.
29///
30/// Methods represent callable operations that can be invoked via the Invoke message.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct MethodInfo {
33    /// Method path/name (e.g., "audio/play", "animation/trigger", "reset")
34    pub path: String,
35
36    /// Method parameters
37    #[serde(default, skip_serializing_if = "Vec::is_empty")]
38    pub params: Vec<MethodParam>,
39
40    /// Return type (None means void/unit)
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub return_type: Option<Type>,
43
44    /// Human-readable description
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub description: Option<String>,
47}
48
49/// Result type for method invocation.
50#[derive(Debug, Clone)]
51pub struct InvokeResult {
52    pub success: bool,
53    pub value: Option<Value>,
54    pub message: Option<String>,
55}
56
57impl InvokeResult {
58    /// Create a successful result with no return value.
59    pub fn ok() -> Self {
60        Self {
61            success: true,
62            value: None,
63            message: None,
64        }
65    }
66
67    /// Create a successful result with a return value.
68    pub fn ok_with_value(value: Value) -> Self {
69        Self {
70            success: true,
71            value: Some(value),
72            message: None,
73        }
74    }
75
76    /// Create an error result.
77    pub fn err(message: impl Into<String>) -> Self {
78        Self {
79            success: false,
80            value: None,
81            message: Some(message.into()),
82        }
83    }
84}