Skip to main content

ic_query/nns/
inventory_request.rs

1//! Module: nns::inventory_request
2//!
3//! Responsibility: define shared request contracts for Registry-derived NNS inventory reports.
4//! Does not own: family-specific filters, source calls, cache IO, or report projection.
5//! Boundary: keeps identical cache, list, info, and refresh provenance from drifting by family.
6
7use std::path::PathBuf;
8
9///
10/// NnsInventoryCacheRequest
11///
12/// Shared cache identity for Registry-derived NNS inventory reports.
13///
14
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct NnsInventoryCacheRequest {
17    pub cache_root: PathBuf,
18    pub network: String,
19}
20
21impl NnsInventoryCacheRequest {
22    #[must_use]
23    pub fn new(cache_root: impl Into<PathBuf>, network: impl Into<String>) -> Self {
24        Self {
25            cache_root: cache_root.into(),
26            network: network.into(),
27        }
28    }
29}
30
31///
32/// NnsInventoryListRequest
33///
34/// Shared request for a complete Registry-derived NNS inventory report.
35///
36
37#[derive(Clone, Debug, Eq, PartialEq)]
38pub struct NnsInventoryListRequest {
39    pub cache: NnsInventoryCacheRequest,
40    pub source_endpoint: String,
41    pub now_unix_secs: u64,
42}
43
44impl NnsInventoryListRequest {
45    #[must_use]
46    pub fn new(
47        cache: NnsInventoryCacheRequest,
48        source_endpoint: impl Into<String>,
49        now_unix_secs: u64,
50    ) -> Self {
51        Self {
52            cache,
53            source_endpoint: source_endpoint.into(),
54            now_unix_secs,
55        }
56    }
57}
58
59///
60/// NnsInventoryInfoRequest
61///
62/// Shared request for one Registry-derived NNS inventory row selected by id or prefix.
63///
64
65#[derive(Clone, Debug, Eq, PartialEq)]
66pub struct NnsInventoryInfoRequest {
67    pub cache: NnsInventoryCacheRequest,
68    pub source_endpoint: String,
69    pub input: String,
70    pub now_unix_secs: u64,
71}
72
73impl NnsInventoryInfoRequest {
74    #[must_use]
75    pub fn new(
76        cache: NnsInventoryCacheRequest,
77        source_endpoint: impl Into<String>,
78        input: impl Into<String>,
79        now_unix_secs: u64,
80    ) -> Self {
81        Self {
82            cache,
83            source_endpoint: source_endpoint.into(),
84            input: input.into(),
85            now_unix_secs,
86        }
87    }
88}
89
90///
91/// NnsInventoryRefreshRequest
92///
93/// Shared host request for refreshing one Registry-derived NNS inventory cache.
94///
95
96#[cfg(feature = "host")]
97#[derive(Clone, Debug, Eq, PartialEq)]
98pub struct NnsInventoryRefreshRequest {
99    pub cache: NnsInventoryCacheRequest,
100    pub source_endpoint: String,
101    pub now_unix_secs: u64,
102    pub lock_stale_after_seconds: u64,
103    pub dry_run: bool,
104    pub output_path: Option<PathBuf>,
105}
106
107#[cfg(feature = "host")]
108impl NnsInventoryRefreshRequest {
109    #[must_use]
110    pub fn new(
111        cache: NnsInventoryCacheRequest,
112        source_endpoint: impl Into<String>,
113        now_unix_secs: u64,
114        lock_stale_after_seconds: u64,
115    ) -> Self {
116        Self {
117            cache,
118            source_endpoint: source_endpoint.into(),
119            now_unix_secs,
120            lock_stale_after_seconds,
121            dry_run: false,
122            output_path: None,
123        }
124    }
125
126    #[must_use]
127    pub const fn with_dry_run(mut self, dry_run: bool) -> Self {
128        self.dry_run = dry_run;
129        self
130    }
131
132    #[must_use]
133    pub fn with_output_path(mut self, output_path: impl Into<PathBuf>) -> Self {
134        self.output_path = Some(output_path.into());
135        self
136    }
137}
138
139#[cfg(feature = "host")]
140impl_nns_leaf_cache_and_refresh_requests!(NnsInventoryCacheRequest, NnsInventoryRefreshRequest);