backbone-accounting 0.18.3

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! The events this module declares, as typed payloads (`events:` in its schema files).
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Each declaration is a struct here, namespaced under `declared::` so it cannot collide with a
//! hand-written event type, and implements `DeclaredEvent`: its name, version and aggregate, and
//! `record(..)`, which builds the outbox row. An event declared with `on:` is staged by the write
//! hooks of its aggregate, in the write's transaction. One without is staged by hand code:
//! `ctx.stage(event.record(&id, &ctx))` inside a write's hooks, or
//! `backbone_outbox::outbox::stage` in a transaction of its own.
//! Delivery is at least once; a consumer dedupes with `backbone_outbox::inbox::once`.

use backbone_core::write_hooks::DeclaredEvent;
use serde::{Deserialize, Serialize};

/// posting succeeds
/// Declared in `journal.hook.yaml`; staged by hand code.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AccountingPostPosted {
    pub post_id: serde_json::Value,
    pub journal_id: serde_json::Value,
    pub company_id: serde_json::Value,
    pub source_type: serde_json::Value,
    pub source_id: serde_json::Value,
    pub total_debit: serde_json::Value,
    pub total_credit: serde_json::Value,
    pub posted_at: serde_json::Value,
}

impl DeclaredEvent for AccountingPostPosted {
    const NAME: &'static str = "AccountingPostPosted";
    const VERSION: i32 = 1;
    const AGGREGATE: &'static str = "";
}

/// posting rejected
/// Declared in `journal.hook.yaml`; staged by hand code.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AccountingPostFailed {
    pub company_id: serde_json::Value,
    pub source_type: serde_json::Value,
    pub source_id: serde_json::Value,
    pub error_code: serde_json::Value,
    pub error_message: serde_json::Value,
    pub failed_at: serde_json::Value,
}

impl DeclaredEvent for AccountingPostFailed {
    const NAME: &'static str = "AccountingPostFailed";
    const VERSION: i32 = 1;
    const AGGREGATE: &'static str = "";
}

/// The Postgres schemas whose `outbox_events` table this module's staged events are written to.
pub const OUTBOX_SCHEMAS: &[&str] = &[];

/// Create the outbox and inbox tables of [`OUTBOX_SCHEMAS`] (idempotent). The composing service
/// runs it at startup with a role that may create tables, beside its relay; a write that stages an
/// event needs the table to exist.
pub async fn migrate_outbox(pool: &backbone_orm::PgPool) -> anyhow::Result<()> {
    for schema in OUTBOX_SCHEMAS {
        backbone_core::write_hooks::migrate_outbox(pool, schema).await?;
    }
    Ok(())
}