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;
13pub mod tag;
14
15pub use catalog::{Catalog, CatalogField, CatalogFieldType};
16pub use content_block::{ContentBlock, ContentBlockState};
17pub use custom_attribute::{CustomAttribute, CustomAttributeRegistry, CustomAttributeType};
18pub use email_template::EmailTemplate;
19pub use tag::{Tag, TagRegistry};
20
21/// Every resource type braze-sync manages, as a single sum type.
22///
23/// Adding a variant here will produce match-exhaustiveness errors at every
24/// downstream site that consumes a `Resource`. That is intentional.
25#[derive(Debug, Clone, PartialEq)]
26pub enum Resource {
27    CatalogSchema(Catalog),
28    ContentBlock(ContentBlock),
29    EmailTemplate(EmailTemplate),
30    CustomAttributeRegistry(CustomAttributeRegistry),
31    TagRegistry(TagRegistry),
32}
33
34/// Lightweight tag for filtering / CLI args. Mirrors [`Resource`] but
35/// without the payload.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, clap::ValueEnum)]
37#[clap(rename_all = "snake_case")]
38pub enum ResourceKind {
39    CatalogSchema,
40    ContentBlock,
41    EmailTemplate,
42    CustomAttribute,
43    Tag,
44}
45
46impl ResourceKind {
47    pub fn as_str(&self) -> &'static str {
48        match self {
49            Self::CatalogSchema => "catalog_schema",
50            Self::ContentBlock => "content_block",
51            Self::EmailTemplate => "email_template",
52            Self::CustomAttribute => "custom_attribute",
53            Self::Tag => "tag",
54        }
55    }
56
57    pub fn all() -> &'static [Self] {
58        &[
59            Self::CatalogSchema,
60            Self::ContentBlock,
61            Self::EmailTemplate,
62            Self::CustomAttribute,
63            Self::Tag,
64        ]
65    }
66}
67
68impl Resource {
69    pub fn kind(&self) -> ResourceKind {
70        match self {
71            Self::CatalogSchema(_) => ResourceKind::CatalogSchema,
72            Self::ContentBlock(_) => ResourceKind::ContentBlock,
73            Self::EmailTemplate(_) => ResourceKind::EmailTemplate,
74            Self::CustomAttributeRegistry(_) => ResourceKind::CustomAttribute,
75            Self::TagRegistry(_) => ResourceKind::Tag,
76        }
77    }
78}