jacquard_api/place_stream/server/
create_webhook.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::UriValue;
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::place_stream::server::RewriteRule;
18use crate::place_stream::server::Webhook;
19
20#[lexicon]
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase")]
23pub struct CreateWebhook<'a> {
24 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(default = "_default_create_webhook_active")]
27 pub active: Option<bool>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 #[serde(borrow)]
31 pub description: Option<CowStr<'a>>,
32 #[serde(borrow)]
34 pub events: Vec<CowStr<'a>>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 #[serde(borrow)]
38 pub mute_words: Option<Vec<CowStr<'a>>>,
39 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub name: Option<CowStr<'a>>,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 #[serde(borrow)]
46 pub prefix: Option<CowStr<'a>>,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 #[serde(borrow)]
50 pub rewrite: Option<Vec<RewriteRule<'a>>>,
51 #[serde(skip_serializing_if = "Option::is_none")]
53 #[serde(borrow)]
54 pub suffix: Option<CowStr<'a>>,
55 #[serde(borrow)]
57 pub url: UriValue<'a>,
58}
59
60
61#[lexicon]
62#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
63#[serde(rename_all = "camelCase")]
64pub struct CreateWebhookOutput<'a> {
65 #[serde(borrow)]
66 pub webhook: Webhook<'a>,
67}
68
69
70#[open_union]
71#[derive(
72 Serialize,
73 Deserialize,
74 Debug,
75 Clone,
76 PartialEq,
77 Eq,
78 thiserror::Error,
79 miette::Diagnostic,
80 IntoStatic
81)]
82
83#[serde(tag = "error", content = "message")]
84#[serde(bound(deserialize = "'de: 'a"))]
85pub enum CreateWebhookError<'a> {
86 #[serde(rename = "InvalidUrl")]
88 InvalidUrl(Option<CowStr<'a>>),
89 #[serde(rename = "DuplicateWebhook")]
91 DuplicateWebhook(Option<CowStr<'a>>),
92 #[serde(rename = "TooManyWebhooks")]
94 TooManyWebhooks(Option<CowStr<'a>>),
95}
96
97impl core::fmt::Display for CreateWebhookError<'_> {
98 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
99 match self {
100 Self::InvalidUrl(msg) => {
101 write!(f, "InvalidUrl")?;
102 if let Some(msg) = msg {
103 write!(f, ": {}", msg)?;
104 }
105 Ok(())
106 }
107 Self::DuplicateWebhook(msg) => {
108 write!(f, "DuplicateWebhook")?;
109 if let Some(msg) = msg {
110 write!(f, ": {}", msg)?;
111 }
112 Ok(())
113 }
114 Self::TooManyWebhooks(msg) => {
115 write!(f, "TooManyWebhooks")?;
116 if let Some(msg) = msg {
117 write!(f, ": {}", msg)?;
118 }
119 Ok(())
120 }
121 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
122 }
123 }
124}
125
126pub struct CreateWebhookResponse;
128impl jacquard_common::xrpc::XrpcResp for CreateWebhookResponse {
129 const NSID: &'static str = "place.stream.server.createWebhook";
130 const ENCODING: &'static str = "application/json";
131 type Output<'de> = CreateWebhookOutput<'de>;
132 type Err<'de> = CreateWebhookError<'de>;
133}
134
135impl<'a> jacquard_common::xrpc::XrpcRequest for CreateWebhook<'a> {
136 const NSID: &'static str = "place.stream.server.createWebhook";
137 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
138 "application/json",
139 );
140 type Response = CreateWebhookResponse;
141}
142
143pub struct CreateWebhookRequest;
145impl jacquard_common::xrpc::XrpcEndpoint for CreateWebhookRequest {
146 const PATH: &'static str = "/xrpc/place.stream.server.createWebhook";
147 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
148 "application/json",
149 );
150 type Request<'de> = CreateWebhook<'de>;
151 type Response = CreateWebhookResponse;
152}
153
154fn _default_create_webhook_active() -> Option<bool> {
155 Some(false)
156}
157
158pub mod create_webhook_state {
159
160 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
161 #[allow(unused)]
162 use ::core::marker::PhantomData;
163 mod sealed {
164 pub trait Sealed {}
165 }
166 pub trait State: sealed::Sealed {
168 type Events;
169 type Url;
170 }
171 pub struct Empty(());
173 impl sealed::Sealed for Empty {}
174 impl State for Empty {
175 type Events = Unset;
176 type Url = Unset;
177 }
178 pub struct SetEvents<S: State = Empty>(PhantomData<fn() -> S>);
180 impl<S: State> sealed::Sealed for SetEvents<S> {}
181 impl<S: State> State for SetEvents<S> {
182 type Events = Set<members::events>;
183 type Url = S::Url;
184 }
185 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
187 impl<S: State> sealed::Sealed for SetUrl<S> {}
188 impl<S: State> State for SetUrl<S> {
189 type Events = S::Events;
190 type Url = Set<members::url>;
191 }
192 #[allow(non_camel_case_types)]
194 pub mod members {
195 pub struct events(());
197 pub struct url(());
199 }
200}
201
202pub struct CreateWebhookBuilder<'a, S: create_webhook_state::State> {
204 _state: PhantomData<fn() -> S>,
205 _fields: (
206 Option<bool>,
207 Option<CowStr<'a>>,
208 Option<Vec<CowStr<'a>>>,
209 Option<Vec<CowStr<'a>>>,
210 Option<CowStr<'a>>,
211 Option<CowStr<'a>>,
212 Option<Vec<RewriteRule<'a>>>,
213 Option<CowStr<'a>>,
214 Option<UriValue<'a>>,
215 ),
216 _lifetime: PhantomData<&'a ()>,
217}
218
219impl<'a> CreateWebhook<'a> {
220 pub fn new() -> CreateWebhookBuilder<'a, create_webhook_state::Empty> {
222 CreateWebhookBuilder::new()
223 }
224}
225
226impl<'a> CreateWebhookBuilder<'a, create_webhook_state::Empty> {
227 pub fn new() -> Self {
229 CreateWebhookBuilder {
230 _state: PhantomData,
231 _fields: (None, None, None, None, None, None, None, None, None),
232 _lifetime: PhantomData,
233 }
234 }
235}
236
237impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
238 pub fn active(mut self, value: impl Into<Option<bool>>) -> Self {
240 self._fields.0 = value.into();
241 self
242 }
243 pub fn maybe_active(mut self, value: Option<bool>) -> Self {
245 self._fields.0 = value;
246 self
247 }
248}
249
250impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
251 pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
253 self._fields.1 = value.into();
254 self
255 }
256 pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
258 self._fields.1 = value;
259 self
260 }
261}
262
263impl<'a, S> CreateWebhookBuilder<'a, S>
264where
265 S: create_webhook_state::State,
266 S::Events: create_webhook_state::IsUnset,
267{
268 pub fn events(
270 mut self,
271 value: impl Into<Vec<CowStr<'a>>>,
272 ) -> CreateWebhookBuilder<'a, create_webhook_state::SetEvents<S>> {
273 self._fields.2 = Option::Some(value.into());
274 CreateWebhookBuilder {
275 _state: PhantomData,
276 _fields: self._fields,
277 _lifetime: PhantomData,
278 }
279 }
280}
281
282impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
283 pub fn mute_words(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
285 self._fields.3 = value.into();
286 self
287 }
288 pub fn maybe_mute_words(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
290 self._fields.3 = value;
291 self
292 }
293}
294
295impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
296 pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
298 self._fields.4 = value.into();
299 self
300 }
301 pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
303 self._fields.4 = value;
304 self
305 }
306}
307
308impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
309 pub fn prefix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
311 self._fields.5 = value.into();
312 self
313 }
314 pub fn maybe_prefix(mut self, value: Option<CowStr<'a>>) -> Self {
316 self._fields.5 = value;
317 self
318 }
319}
320
321impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
322 pub fn rewrite(mut self, value: impl Into<Option<Vec<RewriteRule<'a>>>>) -> Self {
324 self._fields.6 = value.into();
325 self
326 }
327 pub fn maybe_rewrite(mut self, value: Option<Vec<RewriteRule<'a>>>) -> Self {
329 self._fields.6 = value;
330 self
331 }
332}
333
334impl<'a, S: create_webhook_state::State> CreateWebhookBuilder<'a, S> {
335 pub fn suffix(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
337 self._fields.7 = value.into();
338 self
339 }
340 pub fn maybe_suffix(mut self, value: Option<CowStr<'a>>) -> Self {
342 self._fields.7 = value;
343 self
344 }
345}
346
347impl<'a, S> CreateWebhookBuilder<'a, S>
348where
349 S: create_webhook_state::State,
350 S::Url: create_webhook_state::IsUnset,
351{
352 pub fn url(
354 mut self,
355 value: impl Into<UriValue<'a>>,
356 ) -> CreateWebhookBuilder<'a, create_webhook_state::SetUrl<S>> {
357 self._fields.8 = Option::Some(value.into());
358 CreateWebhookBuilder {
359 _state: PhantomData,
360 _fields: self._fields,
361 _lifetime: PhantomData,
362 }
363 }
364}
365
366impl<'a, S> CreateWebhookBuilder<'a, S>
367where
368 S: create_webhook_state::State,
369 S::Events: create_webhook_state::IsSet,
370 S::Url: create_webhook_state::IsSet,
371{
372 pub fn build(self) -> CreateWebhook<'a> {
374 CreateWebhook {
375 active: self._fields.0.or_else(|| Some(false)),
376 description: self._fields.1,
377 events: self._fields.2.unwrap(),
378 mute_words: self._fields.3,
379 name: self._fields.4,
380 prefix: self._fields.5,
381 rewrite: self._fields.6,
382 suffix: self._fields.7,
383 url: self._fields.8.unwrap(),
384 extra_data: Default::default(),
385 }
386 }
387 pub fn build_with_data(
389 self,
390 extra_data: BTreeMap<
391 jacquard_common::deps::smol_str::SmolStr,
392 jacquard_common::types::value::Data<'a>,
393 >,
394 ) -> CreateWebhook<'a> {
395 CreateWebhook {
396 active: self._fields.0.or_else(|| Some(false)),
397 description: self._fields.1,
398 events: self._fields.2.unwrap(),
399 mute_words: self._fields.3,
400 name: self._fields.4,
401 prefix: self._fields.5,
402 rewrite: self._fields.6,
403 suffix: self._fields.7,
404 url: self._fields.8.unwrap(),
405 extra_data: Some(extra_data),
406 }
407 }
408}