Skip to main content

bpmn_engine/repository/
traits.rs

1//! Repository Traits
2//!
3//! Abstraction traits for process instance persistence.
4
5use crate::engine::instance::ProcessInstance;
6use async_trait::async_trait;
7use std::sync::Arc;
8
9/// Repository Trait
10///
11/// Trait for process instance repositories.
12/// This abstraction allows for different storage backends (memory, database, etc.).
13#[async_trait]
14pub trait Repository: Send + Sync {
15    /// Save a process instance
16    async fn save(&self, instance: Arc<ProcessInstance>) -> Result<(), RepositoryError>;
17
18    /// Get a process instance by ID
19    async fn get(&self, instance_id: &str) -> Result<Option<Arc<ProcessInstance>>, RepositoryError>;
20
21    /// Delete a process instance
22    async fn delete(&self, instance_id: &str) -> Result<(), RepositoryError>;
23
24    /// List all process instance IDs
25    async fn list_ids(&self) -> Result<Vec<String>, RepositoryError>;
26
27    /// Check if a process instance exists
28    async fn exists(&self, instance_id: &str) -> Result<bool, RepositoryError> {
29        Ok(self.get(instance_id).await?.is_some())
30    }
31}
32
33/// Repository Error
34#[derive(Debug, thiserror::Error)]
35pub enum RepositoryError {
36    #[error("Repository operation failed: {0}")]
37    OperationFailed(String),
38    #[error("Instance not found: {0}")]
39    NotFound(String),
40    #[error("Storage error: {0}")]
41    StorageError(String),
42}
43