lash_remote_protocol/protocol/
triggers.rs1#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
2pub struct RemoteTriggerOccurrenceRequest {
3 pub protocol_version: u32,
4 pub source_type: String,
5 pub source_key: String,
6 #[serde(default)]
7 pub payload: serde_json::Value,
8 pub idempotency_key: String,
9 #[serde(default, skip_serializing_if = "Option::is_none")]
10 pub source: Option<serde_json::Value>,
11}
12
13impl RemoteTriggerOccurrenceRequest {
14 pub fn new(
15 source_type: impl Into<String>,
16 source_key: impl Into<String>,
17 payload: serde_json::Value,
18 idempotency_key: impl Into<String>,
19 ) -> Self {
20 Self {
21 protocol_version: REMOTE_PROTOCOL_VERSION,
22 source_type: source_type.into(),
23 source_key: source_key.into(),
24 payload,
25 idempotency_key: idempotency_key.into(),
26 source: None,
27 }
28 }
29
30 pub fn with_source(mut self, source: serde_json::Value) -> Self {
31 self.source = Some(source);
32 self
33 }
34
35 pub fn validate(&self) -> Result<(), RemoteProtocolError> {
36 ensure_protocol_version(self.protocol_version)?;
37 require_non_empty(
38 "RemoteTriggerOccurrenceRequest",
39 "source_type",
40 &self.source_type,
41 )?;
42 require_non_empty(
43 "RemoteTriggerOccurrenceRequest",
44 "source_key",
45 &self.source_key,
46 )?;
47 require_non_empty(
48 "RemoteTriggerOccurrenceRequest",
49 "idempotency_key",
50 &self.idempotency_key,
51 )
52 }
53}
54
55#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
56pub struct RemoteTriggerOccurrenceRecord {
57 pub occurrence_id: String,
58 pub source_type: String,
59 pub source_key: String,
60 #[serde(default)]
61 pub payload: serde_json::Value,
62 pub idempotency_key: String,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub source: Option<serde_json::Value>,
65 pub occurred_at_ms: u64,
66}
67
68#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
69pub struct RemoteTriggerEmitReport {
70 pub protocol_version: u32,
71 #[serde(default, skip_serializing_if = "String::is_empty")]
72 pub occurrence_id: String,
73 #[serde(default, skip_serializing_if = "Vec::is_empty")]
74 pub started_process_ids: Vec<String>,
75}
76
77impl RemoteTriggerEmitReport {
78 pub fn validate(&self) -> Result<(), RemoteProtocolError> {
79 ensure_protocol_version(self.protocol_version)
80 }
81}
82
83#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
84pub struct RemoteTriggerSubscriptionFilter {
85 pub protocol_version: u32,
86 #[serde(default, skip_serializing_if = "Option::is_none")]
87 pub session_id: Option<String>,
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 pub handle: Option<String>,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
91 pub name: Option<String>,
92 #[serde(default, skip_serializing_if = "Option::is_none")]
93 pub source_type: Option<String>,
94 #[serde(default, skip_serializing_if = "Option::is_none")]
95 pub source_key: Option<String>,
96 #[serde(default, skip_serializing_if = "Option::is_none")]
97 pub target: Option<serde_json::Value>,
98 #[serde(default, skip_serializing_if = "Option::is_none")]
99 pub enabled: Option<bool>,
100}
101
102impl Default for RemoteTriggerSubscriptionFilter {
103 fn default() -> Self {
104 Self {
105 protocol_version: REMOTE_PROTOCOL_VERSION,
106 session_id: None,
107 handle: None,
108 name: None,
109 source_type: None,
110 source_key: None,
111 target: None,
112 enabled: None,
113 }
114 }
115}
116
117impl RemoteTriggerSubscriptionFilter {
118 pub fn for_session(session_id: impl Into<String>) -> Self {
119 Self {
120 protocol_version: REMOTE_PROTOCOL_VERSION,
121 session_id: Some(session_id.into()),
122 ..Self::default()
123 }
124 }
125
126 pub fn for_source_type(source_type: impl Into<String>) -> Self {
127 Self {
128 protocol_version: REMOTE_PROTOCOL_VERSION,
129 source_type: Some(source_type.into()),
130 ..Self::default()
131 }
132 }
133
134 pub fn validate(&self) -> Result<(), RemoteProtocolError> {
135 ensure_protocol_version(self.protocol_version)
136 }
137}
138
139#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
140pub struct RemoteTriggerRegistration {
141 pub handle: String,
142 pub source_key: String,
143 #[serde(default, skip_serializing_if = "Option::is_none")]
144 pub name: Option<String>,
145 pub source_type: String,
146 #[serde(default)]
147 pub source: serde_json::Value,
148 pub target: RemoteTriggerTargetSummary,
149 #[serde(default = "default_true")]
150 pub enabled: bool,
151}
152
153#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
154pub struct RemoteTriggerTargetSummary {
155 pub process_name: String,
156 #[serde(default)]
157 pub inputs: serde_json::Value,
158}
159
160fn default_true() -> bool {
161 true
162}