Skip to main content

uni_plugin_host/
commit_result.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4//! Commit-result value types, shared by the API crate and the plugin-host
5//! hooks engine. Pure data — no `Uni` coupling.
6
7use std::time::Duration;
8
9/// Result of committing a transaction.
10#[derive(Debug, Default)]
11pub struct CommitResult {
12    /// Number of mutations committed.
13    pub mutations_committed: usize,
14    /// Number of rules promoted to the parent session.
15    pub rules_promoted: usize,
16    /// Database version after commit.
17    pub version: u64,
18    /// Database version when the transaction was created.
19    pub started_at_version: u64,
20    /// WAL log sequence number of the commit (0 when no WAL is configured).
21    pub wal_lsn: u64,
22    /// Duration of the commit operation (lock + WAL + merge).
23    pub duration: Duration,
24    /// Errors encountered during rule promotion (best-effort).
25    pub rule_promotion_errors: Vec<RulePromotionError>,
26}
27
28impl CommitResult {
29    /// Number of versions that committed between tx start and commit.
30    /// 0 means no concurrent commits occurred.
31    pub fn version_gap(&self) -> u64 {
32        self.version.saturating_sub(self.started_at_version + 1)
33    }
34}
35
36/// Error encountered during rule promotion at commit time.
37#[derive(Debug, Clone)]
38pub struct RulePromotionError {
39    pub rule_text: String,
40    pub error: String,
41}