Skip to main content

braze_sync/resource/
mod.rs

1//! Domain types for the four resources braze-sync manages.
2//!
3//! See IMPLEMENTATION.md §6 for the complete type contracts. Adding a new
4//! variant to [`Resource`] / [`ResourceKind`] forces every `match` site in
5//! `diff/`, `fs/`, and `braze/` to be updated — that compiler-enforced
6//! exhaustiveness is the central reason braze-sync is written in Rust
7//! (§2.4).
8
9pub mod catalog;
10pub mod content_block;
11pub mod custom_attribute;
12pub mod email_template;
13
14pub use catalog::{Catalog, CatalogField, CatalogFieldType};
15pub use content_block::{ContentBlock, ContentBlockState};
16pub use custom_attribute::{CustomAttribute, CustomAttributeRegistry, CustomAttributeType};
17pub use email_template::EmailTemplate;
18
19/// Every resource type braze-sync manages, as a single sum type.
20///
21/// Adding a variant here will produce match-exhaustiveness errors at every
22/// downstream site that consumes a `Resource`. That is intentional.
23#[derive(Debug, Clone, PartialEq)]
24pub enum Resource {
25    CatalogSchema(Catalog),
26    ContentBlock(ContentBlock),
27    EmailTemplate(EmailTemplate),
28    CustomAttributeRegistry(CustomAttributeRegistry),
29}
30
31/// Lightweight tag for filtering / CLI args. Mirrors [`Resource`] but
32/// without the payload.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, clap::ValueEnum)]
34#[clap(rename_all = "snake_case")]
35pub enum ResourceKind {
36    CatalogSchema,
37    ContentBlock,
38    EmailTemplate,
39    CustomAttribute,
40}
41
42impl ResourceKind {
43    pub fn as_str(&self) -> &'static str {
44        match self {
45            Self::CatalogSchema => "catalog_schema",
46            Self::ContentBlock => "content_block",
47            Self::EmailTemplate => "email_template",
48            Self::CustomAttribute => "custom_attribute",
49        }
50    }
51
52    pub fn all() -> &'static [Self] {
53        &[
54            Self::CatalogSchema,
55            Self::ContentBlock,
56            Self::EmailTemplate,
57            Self::CustomAttribute,
58        ]
59    }
60}
61
62impl Resource {
63    pub fn kind(&self) -> ResourceKind {
64        match self {
65            Self::CatalogSchema(_) => ResourceKind::CatalogSchema,
66            Self::ContentBlock(_) => ResourceKind::ContentBlock,
67            Self::EmailTemplate(_) => ResourceKind::EmailTemplate,
68            Self::CustomAttributeRegistry(_) => ResourceKind::CustomAttribute,
69        }
70    }
71}