Skip to main content

omgbase_mutate/
lib.rs

1//! # omgbase-mutate
2//!
3//! The omgbase mutation kernel, Rust implementation of `spec/mutate`: a
4//! document loaded from the store as a mutable block tree ([`MutDoc`]), the
5//! six kernel operations over it with placement addressing and
6//! compare-and-swap expectations ([`ops`]), the splice renderer with its
7//! dirty rules ([`render`]), changeset placeholder resolution
8//! ([`changeset`]), the whole-document lowering ([`lower`]), the opset
9//! ([`opset`]) and the public effect vocabulary with its plan shape, conflict
10//! rules and digest ([`effects`], 2.3). Every function here is pure: the store loads, applies,
11//! commits, and hosts the macros and document operations.
12//!
13//! ```
14//! use omgbase_mutate::{MutBlock, MutDoc, At, Parent, To, op_insert, render};
15//! use omgbase_reconcile::SequentialMinter;
16//!
17//! let mut doc = MutDoc::new("d_0", "a.md", vec![MutBlock::new("b_0", "heading", "# Title", "\n")]);
18//! let mut minter = SequentialMinter::new("b");
19//! let to = To { parent: Parent::Doc, at: At::End };
20//! let result = op_insert(&mut doc, &to, "A paragraph.", 0, None, &mut minter).unwrap();
21//! assert_eq!(result.ids, ["b_0"]);
22//! assert_eq!(render(&doc), "# Title\n\nA paragraph.\n");
23//! ```
24
25#![forbid(unsafe_code)]
26
27pub mod changeset;
28pub mod effects;
29pub mod error;
30pub mod lower;
31pub mod ops;
32pub mod opset;
33pub mod render;
34pub mod tree;
35
36pub use changeset::{Op, parse_placeholder, resolve_op, resolve_placeholder, resolve_to};
37pub use effects::{
38    Admission, ConflictTracker, Effect, EffectExpect, ExpectMap, Field, Focus, FocusInfo,
39    FocusTarget, IdentityOp, IdentityPreview, NewId, NewIdKind, PLAN_VERSION, PLANNER_V, Plan,
40    PlanCreate, PlanFrontmatter, PlanMove, PlanOpset, PlanPreview, PlanRevision, PlanTombstone,
41    Preconditions, Repair, RetargetHitPreview, RetargetPairPreview, RetargetPreview, ScalarWrite,
42    Target, canonical_json, classify_field, map_block_ids, parse_new_symbol, shift_placeholders,
43};
44pub use error::{ErrorCode, MutationError, Result};
45pub use lower::{LowerResult, body_of, lcs, lower_replace, lower_top_level, strip_frontmatter};
46pub use omgbase_reconcile::Minter;
47pub use ops::{
48    At, Expect, OpResult, Parent, To, UpdateArgs, check_content_hash, check_parent_children_hash,
49    cross_doc_move, default_trivia, op_insert, op_merge, op_move, op_remove, op_split, op_update,
50    parse_content, parse_document, resolve_target, separates_blocks,
51};
52pub use opset::{Opset, OpsetPrecondition, OpsetSummary, PlanDisposition, PlanOp, summarize};
53pub use render::{render, render_block};
54pub use tree::{BlockPath, MutBlock, MutDoc, child_ids, parent_children_hash, raw_hash_hex};
55
56/// The `spec/mutate/VERSION` this crate implements (`major.minor`).
57pub const SPEC_VERSION: &str = "3.0";
58
59/// This crate's own version (`Cargo.toml`), for the surface's `version` tool.
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn spec_version_matches_the_crate_line() {
68        let crate_version = env!("CARGO_PKG_VERSION");
69        assert!(
70            crate_version.starts_with(&format!("{SPEC_VERSION}.")),
71            "crate {crate_version} must track spec {SPEC_VERSION}.x"
72        );
73    }
74}