Skip to main content

loonfs_core/path/write/
intent.rs

1//! [`CommitRequest`]: the one filesystem commit language, before planning.
2
3use loonfs_api::CommitId;
4
5/// The operation language a commit is written in, owned by `loonfs-api` and
6/// used here unchanged.
7///
8/// There is one spelling of a pre-planning operation across the workspace:
9/// what a client sends is what the planner matches on, so no surface
10/// translates between two versions of the same language. The durable
11/// fingerprint preimage is a separate, frozen spelling, and the planner's
12/// `operation_fingerprint_input` is the only place this one is renamed
13/// into it.
14pub use loonfs_api::FilesystemOperation;
15
16/// One logical filesystem commit: an idempotency key, an optional caller
17/// annotation, and an ordered, non-empty list of operations.
18///
19/// The whole request is one commit. Operations resolve in order, each seeing
20/// the effects of the ones before it, and either all of them commit or none
21/// of them do. A convenience one-operation request is this same type with a
22/// single-element list, so it plans, fingerprints, and replays identically.
23///
24/// This is the wire [`CommitRequest`](loonfs_api::CommitRequest) minus the
25/// content tokens: proofs are checked at the surface that accepts them, and
26/// what reaches the planner is the commit itself.
27///
28/// Paths are parsed once at the surface that accepts the raw string
29/// ([`parse_mutation_path`]); a request always carries validated, normalized
30/// paths.
31///
32/// [`parse_mutation_path`]: crate::path::parse_mutation_path
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct CommitRequest {
35    /// Client idempotency key for the whole request.
36    pub commit_id: CommitId,
37    /// Caller annotation recorded on the commit. Part of the request's
38    /// identity: reusing a commit id with a different message conflicts.
39    pub message: Option<String>,
40    /// Ordered operations. Must be non-empty.
41    pub operations: Vec<FilesystemOperation>,
42}
43
44impl CommitRequest {
45    /// A request carrying exactly one operation.
46    pub fn single(
47        commit_id: CommitId,
48        message: Option<String>,
49        operation: FilesystemOperation,
50    ) -> Self {
51        Self {
52            commit_id,
53            message,
54            operations: vec![operation],
55        }
56    }
57}