Skip to main content

icydb_core/db/
catalog.rs

1//! Module: db::catalog
2//! Responsibility: catalog-level metadata DTOs for SHOW-style introspection.
3//! Does not own: schema validation, query planning, or runtime store policy.
4//! Boundary: projects runtime entity/store registration metadata for callers.
5
6use candid::CandidType;
7use serde::Deserialize;
8
9///
10/// EntityCatalogCounts
11///
12/// Compact count metadata for one `SHOW ENTITIES` row.
13///
14
15#[cfg_attr(
16    doc,
17    doc = "EntityCatalogCounts\n\nCompact count metadata for one SHOW ENTITIES row."
18)]
19#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
20pub struct EntityCatalogCounts {
21    columns: u32,
22    indexes: u32,
23    relations: u32,
24    schema_version: u32,
25}
26
27impl EntityCatalogCounts {
28    /// Construct compact entity catalog count metadata.
29    #[must_use]
30    pub const fn new(columns: u32, indexes: u32, relations: u32, schema_version: u32) -> Self {
31        Self {
32            columns,
33            indexes,
34            relations,
35            schema_version,
36        }
37    }
38}
39
40#[cfg_attr(
41    doc,
42    doc = "EntityCatalogDescription\n\nRuntime catalog entry for one registered entity."
43)]
44#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
45pub struct EntityCatalogDescription {
46    entity_name: String,
47    entity_path: String,
48    store_path: String,
49    storage: String,
50    columns: u32,
51    indexes: u32,
52    relations: u32,
53    schema_version: u32,
54}
55
56impl EntityCatalogDescription {
57    /// Construct one entity catalog entry.
58    #[must_use]
59    pub const fn new(
60        entity_name: String,
61        entity_path: String,
62        store_path: String,
63        storage: String,
64        counts: EntityCatalogCounts,
65    ) -> Self {
66        Self {
67            entity_name,
68            entity_path,
69            store_path,
70            storage,
71            columns: counts.columns,
72            indexes: counts.indexes,
73            relations: counts.relations,
74            schema_version: counts.schema_version,
75        }
76    }
77
78    /// Stable external entity name.
79    #[must_use]
80    pub const fn entity_name(&self) -> &str {
81        self.entity_name.as_str()
82    }
83
84    /// Runtime entity path.
85    #[must_use]
86    pub const fn entity_path(&self) -> &str {
87        self.entity_path.as_str()
88    }
89
90    /// Owning store path.
91    #[must_use]
92    pub const fn store_path(&self) -> &str {
93        self.store_path.as_str()
94    }
95
96    /// User-facing storage mode for the owning store.
97    #[must_use]
98    pub const fn storage(&self) -> &str {
99        self.storage.as_str()
100    }
101
102    /// Number of top-level columns registered for this entity.
103    #[must_use]
104    pub const fn columns(&self) -> u32 {
105        self.columns
106    }
107
108    /// Number of accepted secondary indexes registered for this entity.
109    #[must_use]
110    pub const fn indexes(&self) -> u32 {
111        self.indexes
112    }
113
114    /// Number of relation fields registered for this entity.
115    #[must_use]
116    pub const fn relations(&self) -> u32 {
117        self.relations
118    }
119
120    /// Accepted schema version for this entity.
121    #[must_use]
122    pub const fn schema_version(&self) -> u32 {
123        self.schema_version
124    }
125}
126
127///
128/// StoreCatalogDescription
129///
130/// One runtime-registered store entry for `SHOW STORES`.
131///
132
133#[cfg_attr(
134    doc,
135    doc = "StoreCatalogDescription\n\nRuntime catalog entry for one registered store."
136)]
137#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
138pub struct StoreCatalogDescription {
139    store_path: String,
140    storage: String,
141}
142
143impl StoreCatalogDescription {
144    /// Construct one store catalog entry.
145    #[must_use]
146    pub const fn new(store_path: String, storage: String) -> Self {
147        Self {
148            store_path,
149            storage,
150        }
151    }
152
153    /// Store path.
154    #[must_use]
155    pub const fn store_path(&self) -> &str {
156        self.store_path.as_str()
157    }
158
159    /// User-facing storage mode.
160    #[must_use]
161    pub const fn storage(&self) -> &str {
162        self.storage.as_str()
163    }
164}
165
166///
167/// MemoryCatalogDescription
168///
169/// One runtime-registered stable-memory allocation entry for `SHOW MEMORY`.
170///
171
172#[cfg_attr(
173    doc,
174    doc = "MemoryCatalogDescription\n\nRuntime catalog entry for one stable-memory allocation."
175)]
176#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
177pub struct MemoryCatalogDescription {
178    tag: String,
179    memory_id: u8,
180    store_path: String,
181}
182
183impl MemoryCatalogDescription {
184    /// Construct one memory catalog entry.
185    #[must_use]
186    pub const fn new(tag: String, memory_id: u8, store_path: String) -> Self {
187        Self {
188            tag,
189            memory_id,
190            store_path,
191        }
192    }
193
194    /// Durable stable-memory key used as the memory tag.
195    #[must_use]
196    pub const fn tag(&self) -> &str {
197        self.tag.as_str()
198    }
199
200    /// Stable-memory manager ID.
201    #[must_use]
202    pub const fn memory_id(&self) -> u8 {
203        self.memory_id
204    }
205
206    /// Owning store path.
207    #[must_use]
208    pub const fn store_path(&self) -> &str {
209        self.store_path.as_str()
210    }
211}