stateset_embedded/
integration_mappings.rs1use stateset_core::{
4 CreateIntegrationMapping, IntegrationMapping, IntegrationMappingFilter, IntegrationMappingId,
5 MappingLookup, Result, UpdateIntegrationMapping,
6};
7use stateset_db::{Database, DatabaseCapability};
8use std::sync::Arc;
9
10pub struct IntegrationMappings {
12 db: Arc<dyn Database>,
13}
14
15impl std::fmt::Debug for IntegrationMappings {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 f.debug_struct("IntegrationMappings").finish_non_exhaustive()
18 }
19}
20
21impl IntegrationMappings {
22 pub(crate) fn new(db: Arc<dyn Database>) -> Self {
23 Self { db }
24 }
25
26 #[must_use]
28 pub fn is_supported(&self) -> bool {
29 self.db.supports_capability(DatabaseCapability::IntegrationMappings)
30 }
31
32 fn ensure(&self) -> Result<()> {
33 self.db.ensure_capability(DatabaseCapability::IntegrationMappings)
34 }
35
36 pub fn create(&self, input: CreateIntegrationMapping) -> Result<IntegrationMapping> {
38 self.ensure()?;
39 self.db.integration_mappings().create(input)
40 }
41
42 pub fn get(&self, id: IntegrationMappingId) -> Result<Option<IntegrationMapping>> {
44 self.ensure()?;
45 self.db.integration_mappings().get(id)
46 }
47
48 pub fn update(
50 &self,
51 id: IntegrationMappingId,
52 input: UpdateIntegrationMapping,
53 ) -> Result<IntegrationMapping> {
54 self.ensure()?;
55 self.db.integration_mappings().update(id, input)
56 }
57
58 pub fn list(&self, filter: IntegrationMappingFilter) -> Result<Vec<IntegrationMapping>> {
60 self.ensure()?;
61 self.db.integration_mappings().list(filter)
62 }
63
64 pub fn delete(&self, id: IntegrationMappingId) -> Result<()> {
66 self.ensure()?;
67 self.db.integration_mappings().delete(id)
68 }
69
70 pub fn bulk_upsert(&self, items: Vec<CreateIntegrationMapping>) -> Result<u64> {
72 self.ensure()?;
73 self.db.integration_mappings().bulk_upsert(items)
74 }
75
76 pub fn resolve(&self, lookup: &MappingLookup) -> Result<Option<String>> {
78 self.ensure()?;
79 self.db.integration_mappings().resolve(lookup)
80 }
81}