harmos_domain/operations/host/
payloads.rs1use crate::model::storage::codec::{Bytes, Code, Id, Index, Optional, Text, coded, product};
22use crate::plugin::Grant;
23use crate::{Identifier, MemorySize};
24
25product!(Catalog {
30 kind: Code<CatalogKind> => 1,
31 schema: Optional<Id> => 2,
32 after: Optional<Text> => 3,
33 rows: Optional<Index> => 4,
34 bytes: Optional<Index> => 5,
35});
36
37product!(CatalogPage { entries: Bytes => 1, next: Optional<Text> => 2 });
38
39coded!(CatalogKind { Operations, Schemas, Streams, Objects });
40
41#[derive(Clone, Debug, PartialEq, Eq)]
46pub struct Catalog {
47 pub kind: CatalogKind,
48 pub schema: Option<Identifier>,
49 pub after: Option<String>,
50 pub rows: Option<usize>,
51 pub bytes: Option<usize>,
52}
53
54#[derive(Clone, Debug, Default, PartialEq, Eq)]
55pub struct CatalogPage {
56 pub entries: Vec<u8>,
57 pub next: Option<String>,
58}
59
60#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
63pub enum CatalogKind {
64 #[default]
65 Operations,
66
67 Schemas,
68 Streams,
69 Objects,
70}
71
72impl Catalog {
77 pub fn required_grant(&self) -> Option<Grant> {
80 let (family, all) = match self.kind {
81 CatalogKind::Operations => return None,
82 CatalogKind::Schemas => ("schemas", "schemas:*"),
83 CatalogKind::Streams => ("streams", "streams:*"),
84 CatalogKind::Objects => ("objects", "objects:*"),
85 };
86 Some(Grant::of("host.catalog", self.schema.as_ref().map_or_else(|| all.to_owned(), |schema| format!("{family}:schema:{schema}"))))
87 }
88}
89
90impl MemorySize for Catalog {
91 fn memory_size(&self) -> usize {
92 std::mem::size_of::<Self>()
93 .saturating_add(self.schema.as_ref().map_or(0, |schema| schema.as_str().len()))
94 .saturating_add(self.after.as_ref().map_or(0, String::capacity))
95 }
96}
97
98impl MemorySize for CatalogPage {
99 fn memory_size(&self) -> usize {
100 std::mem::size_of::<Self>().saturating_add(self.entries.capacity()).saturating_add(self.next.as_ref().map_or(0, String::capacity))
101 }
102}
103
104