Skip to main content

outbox_core/
lib.rs

1use crate::config::OutboxConfig;
2use crate::error::OutboxError;
3use crate::model::Event;
4use crate::object::{EventType, IdempotencyToken, Payload};
5use crate::storage::OutboxWriter;
6
7mod config;
8mod error;
9mod gc;
10mod idempotency;
11mod manager;
12mod model;
13mod object;
14mod processor;
15mod publisher;
16mod service;
17mod storage;
18
19/// # Warning
20/// This function performs a raw insert into the database WITHOUT checking the
21/// idempotency storage. It is kept only for backward compatibility.
22///
23/// For production use with deduplication, please migrate to [`service::OutboxService`].
24///
25/// # Errors
26///
27/// Returns [`OutboxError`] if the `writer` fails to insert the event into the database.
28///
29/// # Panics
30///
31/// Panics if the idempotency strategy is set to `Custom`, but `get_event` returns `None`.
32#[deprecated(
33    since = "0.2.0",
34    note = "SECURITY WARNING: This standalone function ignores idempotency checks.
35           Use `OutboxService::add_event` for safe, deduplicated event publishing.
36           This function is no longer recommended and will be removed in 0.3.0."
37)]
38pub async fn add_event<W, F>(
39    writer: &W,
40    event_type: &str,
41    payload: serde_json::Value,
42    config: &OutboxConfig,
43    provided_token: Option<String>,
44    get_event: F,
45) -> Result<(), OutboxError>
46where
47    W: OutboxWriter,
48    F: FnOnce() -> Option<Event>,
49{
50    let i_token = config
51        .idempotency_strategy
52        .invoke(provided_token, get_event)
53        .map(IdempotencyToken::new);
54
55    let event = Event::new(EventType::new(event_type), Payload::new(payload), i_token);
56    writer.insert_event(event).await
57}
58
59pub mod prelude {
60    pub use crate::idempotency::storage::IdempotencyStorageProvider;
61    pub use crate::publisher::Transport;
62    pub use crate::storage::{OutboxStorage, OutboxWriter};
63
64    pub use crate::config::{IdempotencyStrategy, OutboxConfig};
65    pub use crate::manager::OutboxManager;
66    pub use crate::processor::OutboxProcessor;
67    pub use crate::service::OutboxService;
68
69    pub use crate::model::{Event, EventStatus};
70    pub use crate::object::{EventId, EventType, IdempotencyToken, Payload};
71
72    pub use crate::error::OutboxError;
73
74    #[allow(deprecated)]
75    pub use crate::add_event;
76}