jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.pmsky.vote
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::bytes::Bytes;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "social.pmsky.vote",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Vote<S: BosStr = DefaultStr> {
    ///The persistent, anonymous identifier for the user casting the vote.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aid: Option<S>,
    ///Optionally, CID specifying the specific version of 'uri' resource this vote applies to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    ///Timestamp when this vote was created.
    pub cts: Datetime,
    ///An optional array of predefined reasons justifying the vote.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reasons: Option<Vec<S>>,
    ///Signature of dag-cbor encoded vote.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default, with = "jacquard_common::opt_serde_bytes_helper")]
    pub sig: Option<Bytes>,
    ///the account creating the vote, not necessarily the same as the user who voted
    pub src: Did<S>,
    ///AT URI of the record, repository (account), or other resource that this vote applies to.
    pub uri: UriValue<S>,
    ///The value of the vote. The exact meaning depends on what is being voted on, but generally '+1' means 'approval', -1 means 'disapproval', and 0 indicates 'neutrality'.
    pub val: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct VoteGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Vote<S>,
}

impl<S: BosStr> Vote<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, VoteRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct VoteRecord;
impl XrpcResp for VoteRecord {
    const NSID: &'static str = "social.pmsky.vote";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = VoteGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<VoteGetRecordOutput<S>> for Vote<S> {
    fn from(output: VoteGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Vote<S> {
    const NSID: &'static str = "social.pmsky.vote";
    type Record = VoteRecord;
}

impl Collection for VoteRecord {
    const NSID: &'static str = "social.pmsky.vote";
    type Record = VoteRecord;
}

impl<S: BosStr> LexiconSchema for Vote<S> {
    fn nsid() -> &'static str {
        "social.pmsky.vote"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_pmsky_vote()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod vote_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Uri;
        type Src;
        type Val;
        type Cts;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
        type Src = Unset;
        type Val = Unset;
        type Cts = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Uri = Set<members::uri>;
        type Src = St::Src;
        type Val = St::Val;
        type Cts = St::Cts;
    }
    ///State transition - sets the `src` field to Set
    pub struct SetSrc<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSrc<St> {}
    impl<St: State> State for SetSrc<St> {
        type Uri = St::Uri;
        type Src = Set<members::src>;
        type Val = St::Val;
        type Cts = St::Cts;
    }
    ///State transition - sets the `val` field to Set
    pub struct SetVal<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVal<St> {}
    impl<St: State> State for SetVal<St> {
        type Uri = St::Uri;
        type Src = St::Src;
        type Val = Set<members::val>;
        type Cts = St::Cts;
    }
    ///State transition - sets the `cts` field to Set
    pub struct SetCts<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCts<St> {}
    impl<St: State> State for SetCts<St> {
        type Uri = St::Uri;
        type Src = St::Src;
        type Val = St::Val;
        type Cts = Set<members::cts>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `src` field
        pub struct src(());
        ///Marker type for the `val` field
        pub struct val(());
        ///Marker type for the `cts` field
        pub struct cts(());
    }
}

/// Builder for constructing an instance of this type.
pub struct VoteBuilder<S: BosStr, St: vote_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<Cid<S>>,
        Option<Datetime>,
        Option<Vec<S>>,
        Option<Bytes>,
        Option<Did<S>>,
        Option<UriValue<S>>,
        Option<i64>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> Vote<S> {
    /// Create a new builder for this type.
    pub fn new() -> VoteBuilder<S, vote_state::Empty> {
        VoteBuilder::new()
    }
}

impl<S: BosStr> VoteBuilder<S, vote_state::Empty> {
    /// Create a new builder with all fields unset.
    pub fn new() -> Self {
        VoteBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: vote_state::State> VoteBuilder<S, St> {
    /// Set the `aid` field (optional)
    pub fn aid(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `aid` field to an Option value (optional)
    pub fn maybe_aid(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<S: BosStr, St: vote_state::State> VoteBuilder<S, St> {
    /// Set the `cid` field (optional)
    pub fn cid(mut self, value: impl Into<Option<Cid<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `cid` field to an Option value (optional)
    pub fn maybe_cid(mut self, value: Option<Cid<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<S: BosStr, St> VoteBuilder<S, St>
where
    St: vote_state::State,
    St::Cts: vote_state::IsUnset,
{
    /// Set the `cts` field (required)
    pub fn cts(
        mut self,
        value: impl Into<Datetime>,
    ) -> VoteBuilder<S, vote_state::SetCts<St>> {
        self._fields.2 = Option::Some(value.into());
        VoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: vote_state::State> VoteBuilder<S, St> {
    /// Set the `reasons` field (optional)
    pub fn reasons(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `reasons` field to an Option value (optional)
    pub fn maybe_reasons(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<S: BosStr, St: vote_state::State> VoteBuilder<S, St> {
    /// Set the `sig` field (optional)
    pub fn sig(mut self, value: impl Into<Option<Bytes>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `sig` field to an Option value (optional)
    pub fn maybe_sig(mut self, value: Option<Bytes>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<S: BosStr, St> VoteBuilder<S, St>
where
    St: vote_state::State,
    St::Src: vote_state::IsUnset,
{
    /// Set the `src` field (required)
    pub fn src(
        mut self,
        value: impl Into<Did<S>>,
    ) -> VoteBuilder<S, vote_state::SetSrc<St>> {
        self._fields.5 = Option::Some(value.into());
        VoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> VoteBuilder<S, St>
where
    St: vote_state::State,
    St::Uri: vote_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> VoteBuilder<S, vote_state::SetUri<St>> {
        self._fields.6 = Option::Some(value.into());
        VoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> VoteBuilder<S, St>
where
    St: vote_state::State,
    St::Val: vote_state::IsUnset,
{
    /// Set the `val` field (required)
    pub fn val(
        mut self,
        value: impl Into<i64>,
    ) -> VoteBuilder<S, vote_state::SetVal<St>> {
        self._fields.7 = Option::Some(value.into());
        VoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> VoteBuilder<S, St>
where
    St: vote_state::State,
    St::Uri: vote_state::IsSet,
    St::Src: vote_state::IsSet,
    St::Val: vote_state::IsSet,
    St::Cts: vote_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Vote<S> {
        Vote {
            aid: self._fields.0,
            cid: self._fields.1,
            cts: self._fields.2.unwrap(),
            reasons: self._fields.3,
            sig: self._fields.4,
            src: self._fields.5.unwrap(),
            uri: self._fields.6.unwrap(),
            val: self._fields.7.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Vote<S> {
        Vote {
            aid: self._fields.0,
            cid: self._fields.1,
            cts: self._fields.2.unwrap(),
            reasons: self._fields.3,
            sig: self._fields.4,
            src: self._fields.5.unwrap(),
            uri: self._fields.6.unwrap(),
            val: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_social_pmsky_vote() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("social.pmsky.vote"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        description: Some(
                            CowStr::new_static(
                                "A vote record, representing a user's approval or disapproval of the referenced resource. The resource my be a proposal, a post, a web page, or anything that can be agreed or disagreed with.",
                            ),
                        ),
                        required: Some(
                            vec![
                                SmolStr::new_static("src"), SmolStr::new_static("uri"),
                                SmolStr::new_static("val"), SmolStr::new_static("cts")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("aid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The persistent, anonymous identifier for the user casting the vote.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("cid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optionally, CID specifying the specific version of 'uri' resource this vote applies to.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Cid),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("cts"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp when this vote was created."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("reasons"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "An optional array of predefined reasons justifying the vote.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sig"),
                                LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("src"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "the account creating the vote, not necessarily the same as the user who voted",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("uri"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT URI of the record, repository (account), or other resource that this vote applies to.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("val"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}