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 accepted entity and registered-store metadata for callers.
5
6use serde::Deserialize;
7
8///
9/// EntityCatalogCounts
10///
11/// Compact count metadata for one `SHOW ENTITIES` row.
12///
13
14#[cfg_attr(
15    doc,
16    doc = "EntityCatalogCounts\n\nCompact count metadata for one SHOW ENTITIES row."
17)]
18#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
19pub struct EntityCatalogCounts {
20    columns: u32,
21    indexes: u32,
22    relations: u32,
23    schema_version: u32,
24}
25
26impl EntityCatalogCounts {
27    /// Construct compact entity catalog count metadata.
28    #[must_use]
29    pub const fn new(columns: u32, indexes: u32, relations: u32, schema_version: u32) -> Self {
30        Self {
31            columns,
32            indexes,
33            relations,
34            schema_version,
35        }
36    }
37}
38
39#[cfg_attr(
40    doc,
41    doc = "EntityCatalogDescription\n\nRuntime catalog entry for one accepted entity."
42)]
43#[derive(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
44#[cfg_attr(not(target_family = "wasm"), derive(ic_wire::Wire))]
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(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
138#[cfg_attr(not(target_family = "wasm"), derive(ic_wire::Wire))]
139pub struct StoreCatalogDescription {
140    store_path: String,
141    storage: String,
142}
143
144impl StoreCatalogDescription {
145    /// Construct one store catalog entry.
146    #[must_use]
147    pub const fn new(store_path: String, storage: String) -> Self {
148        Self {
149            store_path,
150            storage,
151        }
152    }
153
154    /// Store path.
155    #[must_use]
156    pub const fn store_path(&self) -> &str {
157        self.store_path.as_str()
158    }
159
160    /// User-facing storage mode.
161    #[must_use]
162    pub const fn storage(&self) -> &str {
163        self.storage.as_str()
164    }
165}
166
167///
168/// MemoryCatalogDescription
169///
170/// One runtime-registered stable-memory allocation entry for `SHOW MEMORY`.
171///
172
173#[cfg_attr(
174    doc,
175    doc = "MemoryCatalogDescription\n\nRuntime catalog entry for one stable-memory allocation."
176)]
177#[derive(Clone, Debug, Deserialize, Eq, PartialEq, serde::Serialize)]
178#[cfg_attr(not(target_family = "wasm"), derive(ic_wire::Wire))]
179pub struct MemoryCatalogDescription {
180    tag: String,
181    memory_id: u8,
182    store_path: String,
183}
184
185impl MemoryCatalogDescription {
186    /// Construct one memory catalog entry.
187    #[must_use]
188    pub const fn new(tag: String, memory_id: u8, store_path: String) -> Self {
189        Self {
190            tag,
191            memory_id,
192            store_path,
193        }
194    }
195
196    /// Durable stable-memory key used as the memory tag.
197    #[must_use]
198    pub const fn tag(&self) -> &str {
199        self.tag.as_str()
200    }
201
202    /// Stable-memory manager ID.
203    #[must_use]
204    pub const fn memory_id(&self) -> u8 {
205        self.memory_id
206    }
207
208    /// Owning store path.
209    #[must_use]
210    pub const fn store_path(&self) -> &str {
211        self.store_path.as_str()
212    }
213}