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