jacquard_api/network_slices/slice/
stats.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::string::Nsid;
18use jacquard_derive::{IntoStatic, lexicon};
19use jacquard_lexicon::lexicon::LexiconDoc;
20use jacquard_lexicon::schema::LexiconSchema;
21
22#[allow(unused_imports)]
23use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
24use serde::{Serialize, Deserialize};
25use crate::network_slices::slice::stats;
26
27#[lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
29#[serde(rename_all = "camelCase")]
30pub struct CollectionStats<'a> {
31 #[serde(borrow)]
33 pub collection: Nsid<'a>,
34 pub record_count: i64,
36 pub unique_actors: i64,
38}
39
40
41#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
42#[serde(rename_all = "camelCase")]
43pub struct Stats<'a> {
44 #[serde(borrow)]
45 pub slice: CowStr<'a>,
46}
47
48
49#[lexicon]
50#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
51#[serde(rename_all = "camelCase")]
52pub struct StatsOutput<'a> {
53 #[serde(borrow)]
55 pub collection_stats: Vec<stats::CollectionStats<'a>>,
56 #[serde(borrow)]
58 pub collections: Vec<Nsid<'a>>,
59 pub total_actors: i64,
61 pub total_lexicons: i64,
63 pub total_records: i64,
65}
66
67impl<'a> LexiconSchema for CollectionStats<'a> {
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
82pub struct StatsResponse;
84impl jacquard_common::xrpc::XrpcResp for StatsResponse {
85 const NSID: &'static str = "network.slices.slice.stats";
86 const ENCODING: &'static str = "application/json";
87 type Output<'de> = StatsOutput<'de>;
88 type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
89}
90
91impl<'a> jacquard_common::xrpc::XrpcRequest for Stats<'a> {
92 const NSID: &'static str = "network.slices.slice.stats";
93 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
94 type Response = StatsResponse;
95}
96
97pub struct StatsRequest;
99impl jacquard_common::xrpc::XrpcEndpoint for StatsRequest {
100 const PATH: &'static str = "/xrpc/network.slices.slice.stats";
101 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
102 type Request<'de> = Stats<'de>;
103 type Response = StatsResponse;
104}
105
106pub mod collection_stats_state {
107
108 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
109 #[allow(unused)]
110 use ::core::marker::PhantomData;
111 mod sealed {
112 pub trait Sealed {}
113 }
114 pub trait State: sealed::Sealed {
116 type UniqueActors;
117 type Collection;
118 type RecordCount;
119 }
120 pub struct Empty(());
122 impl sealed::Sealed for Empty {}
123 impl State for Empty {
124 type UniqueActors = Unset;
125 type Collection = Unset;
126 type RecordCount = Unset;
127 }
128 pub struct SetUniqueActors<S: State = Empty>(PhantomData<fn() -> S>);
130 impl<S: State> sealed::Sealed for SetUniqueActors<S> {}
131 impl<S: State> State for SetUniqueActors<S> {
132 type UniqueActors = Set<members::unique_actors>;
133 type Collection = S::Collection;
134 type RecordCount = S::RecordCount;
135 }
136 pub struct SetCollection<S: State = Empty>(PhantomData<fn() -> S>);
138 impl<S: State> sealed::Sealed for SetCollection<S> {}
139 impl<S: State> State for SetCollection<S> {
140 type UniqueActors = S::UniqueActors;
141 type Collection = Set<members::collection>;
142 type RecordCount = S::RecordCount;
143 }
144 pub struct SetRecordCount<S: State = Empty>(PhantomData<fn() -> S>);
146 impl<S: State> sealed::Sealed for SetRecordCount<S> {}
147 impl<S: State> State for SetRecordCount<S> {
148 type UniqueActors = S::UniqueActors;
149 type Collection = S::Collection;
150 type RecordCount = Set<members::record_count>;
151 }
152 #[allow(non_camel_case_types)]
154 pub mod members {
155 pub struct unique_actors(());
157 pub struct collection(());
159 pub struct record_count(());
161 }
162}
163
164pub struct CollectionStatsBuilder<'a, S: collection_stats_state::State> {
166 _state: PhantomData<fn() -> S>,
167 _fields: (Option<Nsid<'a>>, Option<i64>, Option<i64>),
168 _lifetime: PhantomData<&'a ()>,
169}
170
171impl<'a> CollectionStats<'a> {
172 pub fn new() -> CollectionStatsBuilder<'a, collection_stats_state::Empty> {
174 CollectionStatsBuilder::new()
175 }
176}
177
178impl<'a> CollectionStatsBuilder<'a, collection_stats_state::Empty> {
179 pub fn new() -> Self {
181 CollectionStatsBuilder {
182 _state: PhantomData,
183 _fields: (None, None, None),
184 _lifetime: PhantomData,
185 }
186 }
187}
188
189impl<'a, S> CollectionStatsBuilder<'a, S>
190where
191 S: collection_stats_state::State,
192 S::Collection: collection_stats_state::IsUnset,
193{
194 pub fn collection(
196 mut self,
197 value: impl Into<Nsid<'a>>,
198 ) -> CollectionStatsBuilder<'a, collection_stats_state::SetCollection<S>> {
199 self._fields.0 = Option::Some(value.into());
200 CollectionStatsBuilder {
201 _state: PhantomData,
202 _fields: self._fields,
203 _lifetime: PhantomData,
204 }
205 }
206}
207
208impl<'a, S> CollectionStatsBuilder<'a, S>
209where
210 S: collection_stats_state::State,
211 S::RecordCount: collection_stats_state::IsUnset,
212{
213 pub fn record_count(
215 mut self,
216 value: impl Into<i64>,
217 ) -> CollectionStatsBuilder<'a, collection_stats_state::SetRecordCount<S>> {
218 self._fields.1 = Option::Some(value.into());
219 CollectionStatsBuilder {
220 _state: PhantomData,
221 _fields: self._fields,
222 _lifetime: PhantomData,
223 }
224 }
225}
226
227impl<'a, S> CollectionStatsBuilder<'a, S>
228where
229 S: collection_stats_state::State,
230 S::UniqueActors: collection_stats_state::IsUnset,
231{
232 pub fn unique_actors(
234 mut self,
235 value: impl Into<i64>,
236 ) -> CollectionStatsBuilder<'a, collection_stats_state::SetUniqueActors<S>> {
237 self._fields.2 = Option::Some(value.into());
238 CollectionStatsBuilder {
239 _state: PhantomData,
240 _fields: self._fields,
241 _lifetime: PhantomData,
242 }
243 }
244}
245
246impl<'a, S> CollectionStatsBuilder<'a, S>
247where
248 S: collection_stats_state::State,
249 S::UniqueActors: collection_stats_state::IsSet,
250 S::Collection: collection_stats_state::IsSet,
251 S::RecordCount: collection_stats_state::IsSet,
252{
253 pub fn build(self) -> CollectionStats<'a> {
255 CollectionStats {
256 collection: self._fields.0.unwrap(),
257 record_count: self._fields.1.unwrap(),
258 unique_actors: self._fields.2.unwrap(),
259 extra_data: Default::default(),
260 }
261 }
262 pub fn build_with_data(
264 self,
265 extra_data: BTreeMap<
266 jacquard_common::deps::smol_str::SmolStr,
267 jacquard_common::types::value::Data<'a>,
268 >,
269 ) -> CollectionStats<'a> {
270 CollectionStats {
271 collection: self._fields.0.unwrap(),
272 record_count: self._fields.1.unwrap(),
273 unique_actors: self._fields.2.unwrap(),
274 extra_data: Some(extra_data),
275 }
276 }
277}
278
279fn lexicon_doc_network_slices_slice_stats() -> LexiconDoc<'static> {
280 #[allow(unused_imports)]
281 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
282 use jacquard_lexicon::lexicon::*;
283 use alloc::collections::BTreeMap;
284 LexiconDoc {
285 lexicon: Lexicon::Lexicon1,
286 id: CowStr::new_static("network.slices.slice.stats"),
287 defs: {
288 let mut map = BTreeMap::new();
289 map.insert(
290 SmolStr::new_static("collectionStats"),
291 LexUserType::Object(LexObject {
292 required: Some(
293 vec![
294 SmolStr::new_static("collection"),
295 SmolStr::new_static("recordCount"),
296 SmolStr::new_static("uniqueActors")
297 ],
298 ),
299 properties: {
300 #[allow(unused_mut)]
301 let mut map = BTreeMap::new();
302 map.insert(
303 SmolStr::new_static("collection"),
304 LexObjectProperty::String(LexString {
305 description: Some(CowStr::new_static("Collection NSID")),
306 format: Some(LexStringFormat::Nsid),
307 ..Default::default()
308 }),
309 );
310 map.insert(
311 SmolStr::new_static("recordCount"),
312 LexObjectProperty::Integer(LexInteger {
313 ..Default::default()
314 }),
315 );
316 map.insert(
317 SmolStr::new_static("uniqueActors"),
318 LexObjectProperty::Integer(LexInteger {
319 ..Default::default()
320 }),
321 );
322 map
323 },
324 ..Default::default()
325 }),
326 );
327 map.insert(
328 SmolStr::new_static("main"),
329 LexUserType::XrpcQuery(LexXrpcQuery {
330 parameters: Some(
331 LexXrpcQueryParameter::Params(LexXrpcParameters {
332 required: Some(vec![SmolStr::new_static("slice")]),
333 properties: {
334 #[allow(unused_mut)]
335 let mut map = BTreeMap::new();
336 map.insert(
337 SmolStr::new_static("slice"),
338 LexXrpcParametersProperty::String(LexString {
339 description: Some(
340 CowStr::new_static(
341 "AT-URI of the slice to get statistics for",
342 ),
343 ),
344 ..Default::default()
345 }),
346 );
347 map
348 },
349 ..Default::default()
350 }),
351 ),
352 ..Default::default()
353 }),
354 );
355 map
356 },
357 ..Default::default()
358 }
359}
360
361pub mod stats_state {
362
363 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
364 #[allow(unused)]
365 use ::core::marker::PhantomData;
366 mod sealed {
367 pub trait Sealed {}
368 }
369 pub trait State: sealed::Sealed {
371 type Slice;
372 }
373 pub struct Empty(());
375 impl sealed::Sealed for Empty {}
376 impl State for Empty {
377 type Slice = Unset;
378 }
379 pub struct SetSlice<S: State = Empty>(PhantomData<fn() -> S>);
381 impl<S: State> sealed::Sealed for SetSlice<S> {}
382 impl<S: State> State for SetSlice<S> {
383 type Slice = Set<members::slice>;
384 }
385 #[allow(non_camel_case_types)]
387 pub mod members {
388 pub struct slice(());
390 }
391}
392
393pub struct StatsBuilder<'a, S: stats_state::State> {
395 _state: PhantomData<fn() -> S>,
396 _fields: (Option<CowStr<'a>>,),
397 _lifetime: PhantomData<&'a ()>,
398}
399
400impl<'a> Stats<'a> {
401 pub fn new() -> StatsBuilder<'a, stats_state::Empty> {
403 StatsBuilder::new()
404 }
405}
406
407impl<'a> StatsBuilder<'a, stats_state::Empty> {
408 pub fn new() -> Self {
410 StatsBuilder {
411 _state: PhantomData,
412 _fields: (None,),
413 _lifetime: PhantomData,
414 }
415 }
416}
417
418impl<'a, S> StatsBuilder<'a, S>
419where
420 S: stats_state::State,
421 S::Slice: stats_state::IsUnset,
422{
423 pub fn slice(
425 mut self,
426 value: impl Into<CowStr<'a>>,
427 ) -> StatsBuilder<'a, stats_state::SetSlice<S>> {
428 self._fields.0 = Option::Some(value.into());
429 StatsBuilder {
430 _state: PhantomData,
431 _fields: self._fields,
432 _lifetime: PhantomData,
433 }
434 }
435}
436
437impl<'a, S> StatsBuilder<'a, S>
438where
439 S: stats_state::State,
440 S::Slice: stats_state::IsSet,
441{
442 pub fn build(self) -> Stats<'a> {
444 Stats {
445 slice: self._fields.0.unwrap(),
446 }
447 }
448}