Skip to main content

ic_query/ic/model/requests/
canisters.rs

1//! Module: ic::model::requests::canisters
2//!
3//! Responsibility: official Dashboard canister detail, count, and page request contracts.
4//! Does not own: network metrics, network resources, transport, or reports.
5//! Boundary: keeps shared filters and explicit bounded cursor-page intent together.
6
7use super::IcDashboardRequest;
8
9use serde::Serialize;
10
11///
12/// IcCanisterRequest
13///
14/// Request accepted by the official Dashboard canister report builder.
15///
16
17#[derive(Clone, Debug, Eq, PartialEq)]
18pub struct IcCanisterRequest {
19    /// Explicit Dashboard endpoint and caller collection clock.
20    pub dashboard: IcDashboardRequest,
21    /// Canister principal to inspect.
22    pub canister_id: String,
23}
24
25impl IcCanisterRequest {
26    /// Construct a live Dashboard canister request.
27    #[must_use]
28    pub fn new(dashboard: IcDashboardRequest, canister_id: impl Into<String>) -> Self {
29        Self {
30            dashboard,
31            canister_id: canister_id.into(),
32        }
33    }
34}
35
36///
37/// IcCanisterFilters
38///
39/// Official Dashboard filters shared by canister count and page requests.
40///
41
42#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
43pub struct IcCanisterFilters {
44    /// Select canisters according to whether the Dashboard records a name.
45    pub has_name: Option<bool>,
46    /// Select canisters assigned to this Subnet principal.
47    pub subnet_id: Option<String>,
48    /// Select canisters controlled by this principal.
49    pub controller_id: Option<String>,
50    /// Raw Dashboard language labels to include.
51    pub languages: Vec<String>,
52    /// Raw Dashboard canister classifications to include.
53    pub canister_types: Vec<String>,
54    /// Raw Dashboard text search, between two and one hundred characters.
55    pub query: Option<String>,
56}
57
58///
59/// IcCanisterCountRequest
60///
61/// Request for one bounded official Dashboard canister-count lookup.
62///
63
64#[derive(Clone, Debug, Eq, PartialEq)]
65pub struct IcCanisterCountRequest {
66    /// Explicit Dashboard endpoint and caller collection clock.
67    pub dashboard: IcDashboardRequest,
68    /// Filters applied by the Dashboard.
69    pub filters: IcCanisterFilters,
70}
71
72impl IcCanisterCountRequest {
73    /// Construct a live Dashboard canister-count request without filters.
74    #[must_use]
75    pub fn new(dashboard: IcDashboardRequest) -> Self {
76        Self {
77            dashboard,
78            filters: IcCanisterFilters::default(),
79        }
80    }
81
82    /// Set the Dashboard filters used by this request.
83    #[must_use]
84    pub fn with_filters(mut self, filters: IcCanisterFilters) -> Self {
85        self.filters = filters;
86        self
87    }
88}
89
90///
91/// IcCanisterPageRequest
92///
93/// Request for one bounded official Dashboard canister page.
94///
95
96#[derive(Clone, Debug, Eq, PartialEq)]
97pub struct IcCanisterPageRequest {
98    /// Explicit Dashboard endpoint and caller collection clock.
99    pub dashboard: IcDashboardRequest,
100    /// Filters applied by the Dashboard.
101    pub filters: IcCanisterFilters,
102    /// Maximum rows requested from the API.
103    pub limit: u16,
104    /// Exclusive forward cursor returned by an earlier page.
105    pub after: Option<String>,
106    /// Exclusive backward cursor returned by an earlier page.
107    pub before: Option<String>,
108}
109
110impl IcCanisterPageRequest {
111    /// Construct a live Dashboard page request with the default bounded limit.
112    #[must_use]
113    pub fn new(dashboard: IcDashboardRequest) -> Self {
114        Self {
115            dashboard,
116            filters: IcCanisterFilters::default(),
117            limit: crate::ic::DEFAULT_IC_CANISTER_PAGE_LIMIT,
118            after: None,
119            before: None,
120        }
121    }
122
123    /// Set the Dashboard filters used by this request.
124    #[must_use]
125    pub fn with_filters(mut self, filters: IcCanisterFilters) -> Self {
126        self.filters = filters;
127        self
128    }
129
130    /// Set the maximum number of returned rows.
131    #[must_use]
132    pub const fn with_limit(mut self, limit: u16) -> Self {
133        self.limit = limit;
134        self
135    }
136
137    /// Set an exclusive forward cursor.
138    #[must_use]
139    pub fn with_after(mut self, after: impl Into<String>) -> Self {
140        self.after = Some(after.into());
141        self
142    }
143
144    /// Set an exclusive backward cursor.
145    #[must_use]
146    pub fn with_before(mut self, before: impl Into<String>) -> Self {
147        self.before = Some(before.into());
148        self
149    }
150}