Skip to main content

jacquard_api/network_slices/slice/
stats.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: network.slices.slice.stats
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::string::Nsid;
19use jacquard_common::types::value::Data;
20use jacquard_derive::IntoStatic;
21use jacquard_lexicon::lexicon::LexiconDoc;
22use jacquard_lexicon::schema::LexiconSchema;
23
24use crate::network_slices::slice::stats;
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Deserialize, Serialize};
28
29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
30#[serde(
31    rename_all = "camelCase",
32    bound(deserialize = "S: Deserialize<'de> + BosStr")
33)]
34pub struct CollectionStats<S: BosStr = DefaultStr> {
35    ///Collection NSID
36    pub collection: Nsid<S>,
37    ///Number of records in this collection
38    pub record_count: i64,
39    ///Number of unique actors with records in this collection
40    pub unique_actors: i64,
41    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
42    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
43}
44
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
46#[serde(
47    rename_all = "camelCase",
48    bound(deserialize = "S: Deserialize<'de> + BosStr")
49)]
50pub struct Stats<S: BosStr = DefaultStr> {
51    pub slice: S,
52}
53
54#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
55#[serde(
56    rename_all = "camelCase",
57    bound(deserialize = "S: Deserialize<'de> + BosStr")
58)]
59pub struct StatsOutput<S: BosStr = DefaultStr> {
60    ///Per-collection statistics
61    pub collection_stats: Vec<stats::CollectionStats<S>>,
62    ///List of collection NSIDs indexed in this slice
63    pub collections: Vec<Nsid<S>>,
64    ///Total number of unique actors indexed in this slice
65    pub total_actors: i64,
66    ///Total number of lexicons defined for this slice
67    pub total_lexicons: i64,
68    ///Total number of records indexed in this slice
69    pub total_records: i64,
70    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
71    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
72}
73
74impl<S: BosStr> LexiconSchema for CollectionStats<S> {
75    fn nsid() -> &'static str {
76        "network.slices.slice.stats"
77    }
78    fn def_name() -> &'static str {
79        "collectionStats"
80    }
81    fn lexicon_doc() -> LexiconDoc<'static> {
82        lexicon_doc_network_slices_slice_stats()
83    }
84    fn validate(&self) -> Result<(), ConstraintError> {
85        Ok(())
86    }
87}
88
89/** Response marker for the `network.slices.slice.stats` query.
90
91Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `StatsOutput<S>` for this endpoint.*/
92pub struct StatsResponse;
93impl jacquard_common::xrpc::XrpcResp for StatsResponse {
94    const NSID: &'static str = "network.slices.slice.stats";
95    const ENCODING: &'static str = "application/json";
96    type Output<S: BosStr> = StatsOutput<S>;
97    type Err = jacquard_common::xrpc::GenericError;
98}
99
100impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Stats<S> {
101    const NSID: &'static str = "network.slices.slice.stats";
102    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
103    type Response = StatsResponse;
104}
105
106/** Endpoint marker for the `network.slices.slice.stats` query.
107
108Path: `/xrpc/network.slices.slice.stats`. The request payload type is `Stats<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
109pub struct StatsRequest;
110impl jacquard_common::xrpc::XrpcEndpoint for StatsRequest {
111    const PATH: &'static str = "/xrpc/network.slices.slice.stats";
112    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
113    type Request<S: BosStr> = Stats<S>;
114    type Response = StatsResponse;
115}
116
117pub mod collection_stats_state {
118
119    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
120    #[allow(unused)]
121    use ::core::marker::PhantomData;
122    mod sealed {
123        pub trait Sealed {}
124    }
125    /// State trait tracking which required fields have been set
126    pub trait State: sealed::Sealed {
127        type Collection;
128        type RecordCount;
129        type UniqueActors;
130    }
131    /// Empty state - all required fields are unset
132    pub struct Empty(());
133    impl sealed::Sealed for Empty {}
134    impl State for Empty {
135        type Collection = Unset;
136        type RecordCount = Unset;
137        type UniqueActors = Unset;
138    }
139    ///State transition - sets the `collection` field to Set
140    pub struct SetCollection<St: State = Empty>(PhantomData<fn() -> St>);
141    impl<St: State> sealed::Sealed for SetCollection<St> {}
142    impl<St: State> State for SetCollection<St> {
143        type Collection = Set<members::collection>;
144        type RecordCount = St::RecordCount;
145        type UniqueActors = St::UniqueActors;
146    }
147    ///State transition - sets the `record_count` field to Set
148    pub struct SetRecordCount<St: State = Empty>(PhantomData<fn() -> St>);
149    impl<St: State> sealed::Sealed for SetRecordCount<St> {}
150    impl<St: State> State for SetRecordCount<St> {
151        type Collection = St::Collection;
152        type RecordCount = Set<members::record_count>;
153        type UniqueActors = St::UniqueActors;
154    }
155    ///State transition - sets the `unique_actors` field to Set
156    pub struct SetUniqueActors<St: State = Empty>(PhantomData<fn() -> St>);
157    impl<St: State> sealed::Sealed for SetUniqueActors<St> {}
158    impl<St: State> State for SetUniqueActors<St> {
159        type Collection = St::Collection;
160        type RecordCount = St::RecordCount;
161        type UniqueActors = Set<members::unique_actors>;
162    }
163    /// Marker types for field names
164    #[allow(non_camel_case_types)]
165    pub mod members {
166        ///Marker type for the `collection` field
167        pub struct collection(());
168        ///Marker type for the `record_count` field
169        pub struct record_count(());
170        ///Marker type for the `unique_actors` field
171        pub struct unique_actors(());
172    }
173}
174
175/// Builder for constructing an instance of this type.
176pub struct CollectionStatsBuilder<St: collection_stats_state::State, S: BosStr = DefaultStr> {
177    _state: PhantomData<fn() -> St>,
178    _fields: (Option<Nsid<S>>, Option<i64>, Option<i64>),
179    _type: PhantomData<fn() -> S>,
180}
181
182impl CollectionStats<DefaultStr> {
183    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
184    pub fn new() -> CollectionStatsBuilder<collection_stats_state::Empty, DefaultStr> {
185        CollectionStatsBuilder::new()
186    }
187}
188
189impl<S: BosStr> CollectionStats<S> {
190    /// Create a new builder for this type
191    pub fn builder() -> CollectionStatsBuilder<collection_stats_state::Empty, S> {
192        CollectionStatsBuilder::builder()
193    }
194}
195
196impl CollectionStatsBuilder<collection_stats_state::Empty, DefaultStr> {
197    /// Create a new builder with all fields unset, using the default string type, if needed
198    pub fn new() -> Self {
199        CollectionStatsBuilder {
200            _state: PhantomData,
201            _fields: (None, None, None),
202            _type: PhantomData,
203        }
204    }
205}
206
207impl<S: BosStr> CollectionStatsBuilder<collection_stats_state::Empty, S> {
208    /// Create a new builder with all fields unset
209    pub fn builder() -> Self {
210        CollectionStatsBuilder {
211            _state: PhantomData,
212            _fields: (None, None, None),
213            _type: PhantomData,
214        }
215    }
216}
217
218impl<St, S: BosStr> CollectionStatsBuilder<St, S>
219where
220    St: collection_stats_state::State,
221    St::Collection: collection_stats_state::IsUnset,
222{
223    /// Set the `collection` field (required)
224    pub fn collection(
225        mut self,
226        value: impl Into<Nsid<S>>,
227    ) -> CollectionStatsBuilder<collection_stats_state::SetCollection<St>, S> {
228        self._fields.0 = Option::Some(value.into());
229        CollectionStatsBuilder {
230            _state: PhantomData,
231            _fields: self._fields,
232            _type: PhantomData,
233        }
234    }
235}
236
237impl<St, S: BosStr> CollectionStatsBuilder<St, S>
238where
239    St: collection_stats_state::State,
240    St::RecordCount: collection_stats_state::IsUnset,
241{
242    /// Set the `recordCount` field (required)
243    pub fn record_count(
244        mut self,
245        value: impl Into<i64>,
246    ) -> CollectionStatsBuilder<collection_stats_state::SetRecordCount<St>, S> {
247        self._fields.1 = Option::Some(value.into());
248        CollectionStatsBuilder {
249            _state: PhantomData,
250            _fields: self._fields,
251            _type: PhantomData,
252        }
253    }
254}
255
256impl<St, S: BosStr> CollectionStatsBuilder<St, S>
257where
258    St: collection_stats_state::State,
259    St::UniqueActors: collection_stats_state::IsUnset,
260{
261    /// Set the `uniqueActors` field (required)
262    pub fn unique_actors(
263        mut self,
264        value: impl Into<i64>,
265    ) -> CollectionStatsBuilder<collection_stats_state::SetUniqueActors<St>, S> {
266        self._fields.2 = Option::Some(value.into());
267        CollectionStatsBuilder {
268            _state: PhantomData,
269            _fields: self._fields,
270            _type: PhantomData,
271        }
272    }
273}
274
275impl<St, S: BosStr> CollectionStatsBuilder<St, S>
276where
277    St: collection_stats_state::State,
278    St::Collection: collection_stats_state::IsSet,
279    St::RecordCount: collection_stats_state::IsSet,
280    St::UniqueActors: collection_stats_state::IsSet,
281{
282    /// Build the final struct.
283    pub fn build(self) -> CollectionStats<S> {
284        CollectionStats {
285            collection: self._fields.0.unwrap(),
286            record_count: self._fields.1.unwrap(),
287            unique_actors: self._fields.2.unwrap(),
288            extra_data: Default::default(),
289        }
290    }
291    /// Build the final struct with custom extra_data.
292    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> CollectionStats<S> {
293        CollectionStats {
294            collection: self._fields.0.unwrap(),
295            record_count: self._fields.1.unwrap(),
296            unique_actors: self._fields.2.unwrap(),
297            extra_data: Some(extra_data),
298        }
299    }
300}
301
302fn lexicon_doc_network_slices_slice_stats() -> LexiconDoc<'static> {
303    use alloc::collections::BTreeMap;
304    #[allow(unused_imports)]
305    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
306    use jacquard_lexicon::lexicon::*;
307    LexiconDoc {
308        lexicon: Lexicon::Lexicon1,
309        id: CowStr::new_static("network.slices.slice.stats"),
310        defs: {
311            let mut map = BTreeMap::new();
312            map.insert(
313                SmolStr::new_static("collectionStats"),
314                LexUserType::Object(LexObject {
315                    required: Some(vec![
316                        SmolStr::new_static("collection"),
317                        SmolStr::new_static("recordCount"),
318                        SmolStr::new_static("uniqueActors"),
319                    ]),
320                    properties: {
321                        #[allow(unused_mut)]
322                        let mut map = BTreeMap::new();
323                        map.insert(
324                            SmolStr::new_static("collection"),
325                            LexObjectProperty::String(LexString {
326                                description: Some(CowStr::new_static("Collection NSID")),
327                                format: Some(LexStringFormat::Nsid),
328                                ..Default::default()
329                            }),
330                        );
331                        map.insert(
332                            SmolStr::new_static("recordCount"),
333                            LexObjectProperty::Integer(LexInteger {
334                                ..Default::default()
335                            }),
336                        );
337                        map.insert(
338                            SmolStr::new_static("uniqueActors"),
339                            LexObjectProperty::Integer(LexInteger {
340                                ..Default::default()
341                            }),
342                        );
343                        map
344                    },
345                    ..Default::default()
346                }),
347            );
348            map.insert(
349                SmolStr::new_static("main"),
350                LexUserType::XrpcQuery(LexXrpcQuery {
351                    parameters: Some(LexXrpcQueryParameter::Params(LexXrpcParameters {
352                        required: Some(vec![SmolStr::new_static("slice")]),
353                        properties: {
354                            #[allow(unused_mut)]
355                            let mut map = BTreeMap::new();
356                            map.insert(
357                                SmolStr::new_static("slice"),
358                                LexXrpcParametersProperty::String(LexString {
359                                    description: Some(CowStr::new_static(
360                                        "AT-URI of the slice to get statistics for",
361                                    )),
362                                    ..Default::default()
363                                }),
364                            );
365                            map
366                        },
367                        ..Default::default()
368                    })),
369                    ..Default::default()
370                }),
371            );
372            map
373        },
374        ..Default::default()
375    }
376}
377
378pub mod stats_state {
379
380    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
381    #[allow(unused)]
382    use ::core::marker::PhantomData;
383    mod sealed {
384        pub trait Sealed {}
385    }
386    /// State trait tracking which required fields have been set
387    pub trait State: sealed::Sealed {
388        type Slice;
389    }
390    /// Empty state - all required fields are unset
391    pub struct Empty(());
392    impl sealed::Sealed for Empty {}
393    impl State for Empty {
394        type Slice = Unset;
395    }
396    ///State transition - sets the `slice` field to Set
397    pub struct SetSlice<St: State = Empty>(PhantomData<fn() -> St>);
398    impl<St: State> sealed::Sealed for SetSlice<St> {}
399    impl<St: State> State for SetSlice<St> {
400        type Slice = Set<members::slice>;
401    }
402    /// Marker types for field names
403    #[allow(non_camel_case_types)]
404    pub mod members {
405        ///Marker type for the `slice` field
406        pub struct slice(());
407    }
408}
409
410/// Builder for constructing an instance of this type.
411pub struct StatsBuilder<St: stats_state::State, S: BosStr = DefaultStr> {
412    _state: PhantomData<fn() -> St>,
413    _fields: (Option<S>,),
414    _type: PhantomData<fn() -> S>,
415}
416
417impl Stats<DefaultStr> {
418    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
419    pub fn new() -> StatsBuilder<stats_state::Empty, DefaultStr> {
420        StatsBuilder::new()
421    }
422}
423
424impl<S: BosStr> Stats<S> {
425    /// Create a new builder for this type
426    pub fn builder() -> StatsBuilder<stats_state::Empty, S> {
427        StatsBuilder::builder()
428    }
429}
430
431impl StatsBuilder<stats_state::Empty, DefaultStr> {
432    /// Create a new builder with all fields unset, using the default string type, if needed
433    pub fn new() -> Self {
434        StatsBuilder {
435            _state: PhantomData,
436            _fields: (None,),
437            _type: PhantomData,
438        }
439    }
440}
441
442impl<S: BosStr> StatsBuilder<stats_state::Empty, S> {
443    /// Create a new builder with all fields unset
444    pub fn builder() -> Self {
445        StatsBuilder {
446            _state: PhantomData,
447            _fields: (None,),
448            _type: PhantomData,
449        }
450    }
451}
452
453impl<St, S: BosStr> StatsBuilder<St, S>
454where
455    St: stats_state::State,
456    St::Slice: stats_state::IsUnset,
457{
458    /// Set the `slice` field (required)
459    pub fn slice(mut self, value: impl Into<S>) -> StatsBuilder<stats_state::SetSlice<St>, S> {
460        self._fields.0 = Option::Some(value.into());
461        StatsBuilder {
462            _state: PhantomData,
463            _fields: self._fields,
464            _type: PhantomData,
465        }
466    }
467}
468
469impl<St, S: BosStr> StatsBuilder<St, S>
470where
471    St: stats_state::State,
472    St::Slice: stats_state::IsSet,
473{
474    /// Build the final struct.
475    pub fn build(self) -> Stats<S> {
476        Stats {
477            slice: self._fields.0.unwrap(),
478        }
479    }
480}