MCPcopy Index your code
hub / github.com/automerge/autosurgeon

github.com/automerge/autosurgeon @v0.12.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.12.0 ↗ · + Follow
585 symbols 1,515 edges 38 files 44 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

autosurgeon

Build crates docs

Autosurgeon is a Rust library for working with data in automerge documents. See the documentation for a detailed guide.

Quickstart

autosurgeon requires rust 1.65 or newer.

Add autosurgeon to your dependencies with cargo add

cargo add autosurgeon

Then we can define a data model which derives Reconcile and Hydrate and start reading and writing from automerge documents

use autosurgeon::{Reconcile, Hydrate, hydrate, reconcile};

// A simple contact document

#[derive(Debug, Clone, Reconcile, Hydrate, PartialEq)]
struct Contact {
    name: String,
    address: Address,
}

#[derive(Debug, Clone, Reconcile, Hydrate, PartialEq)]
struct Address {
   line_one: String,
   line_two: Option<String>,
   city: String,
   postcode: String,
}

let mut contact = Contact {
     name: "Sherlock Holmes".to_string(),
     address: Address{
         line_one: "221B Baker St".to_string(),
         line_two: None,
         city: "London".to_string(),
         postcode: "NW1 6XE".to_string(),
     },
};

// Put data into a document
let mut doc = automerge::AutoCommit::new();
reconcile(&mut doc, &contact).unwrap();

// Get data out of a document
let contact2: Contact = hydrate(&doc).unwrap();
assert_eq!(contact, contact2);

// Fork and make changes
let mut doc2 = doc.fork().with_actor(automerge::ActorId::random());
let mut contact2: Contact = hydrate(&doc2).unwrap();
contact2.name = "Dangermouse".to_string();
reconcile(&mut doc2, &contact2).unwrap();

// Concurrently on doc1
contact.address.line_one = "221C Baker St".to_string();
reconcile(&mut doc, &contact).unwrap();

// Now merge the documents
// Reconciled changes will merge in somewhat sensible ways
doc.merge(&mut doc2).unwrap();

let merged: Contact = hydrate(&doc).unwrap();
assert_eq!(merged, Contact {
    name: "Dangermouse".to_string(), // This was updated in the first doc
    address: Address {
          line_one: "221C Baker St".to_string(), // This was concurrently updated in doc2
          line_two: None,
          city: "London".to_string(),
          postcode: "NW1 6XE".to_string(),
    }
})

Extension points exported contracts — how you extend this code

Hydrate (Interface)
A type which can be hydrated from an automerge document There are no required methods on this trait. Instead implemento [21 …
autosurgeon/src/hydrate.rs
Field (Interface)
(no doc) [3 implementers]
autosurgeon-derive/src/reconcile/struct_impl.rs
Reconcile (Interface)
A data type which can be reconciled The required method is `reconcile`. This allows you to update the state of a docume [31 …
autosurgeon/src/reconcile.rs
VariantField (Interface)
(no doc) [2 implementers]
autosurgeon-derive/src/reconcile/enum_impl.rs
Reconciler (Interface)
A node in the document we are reconciling with. The methods on reconciler modify the underlying document if the documen [3 …
autosurgeon/src/reconcile.rs
VariantWithFields (Interface)
(no doc) [2 implementers]
autosurgeon-derive/src/reconcile/enum_impl.rs
ReadDoc (Interface)
An abstraction over the different ways of reading an automerge document [3 implementers]
autosurgeon/src/doc.rs
MapReconciler (Interface)
A node in the document which is a map. A `MapReconciler` is obtained from [`Reconciler::map`] so once you have a `MapRe [2 …
autosurgeon/src/reconcile.rs

Core symbols most depended-on inside this repo

reconcile_prop
called by 81
autosurgeon/src/reconcile.rs
as_ref
called by 66
autosurgeon/src/bytes.rs
map
called by 62
autosurgeon/src/reconcile.rs
hydrate_prop
called by 39
autosurgeon/src/hydrate.rs
put
called by 39
autosurgeon/src/doc.rs
reconcile
called by 25
autosurgeon/src/reconcile.rs
insert
called by 25
autosurgeon/src/doc.rs
put_object
called by 23
autosurgeon/src/doc.rs

Shape

Method 248
Function 167
Class 112
Enum 45
Interface 13

Languages

Rust100%

Modules by API surface

autosurgeon/src/reconcile.rs67 symbols
autosurgeon/src/reconcile/reconcile_to_am_hydrate.rs58 symbols
autosurgeon-derive/src/reconcile/enum_impl.rs40 symbols
autosurgeon/src/hydrate.rs37 symbols
autosurgeon-derive/tests/reconcile.rs34 symbols
autosurgeon-derive/src/reconcile/struct_impl.rs33 symbols
autosurgeon-derive/tests/reconcile_with.rs32 symbols
autosurgeon/src/doc.rs21 symbols
autosurgeon-derive/tests/rename.rs21 symbols
autosurgeon/src/text.rs19 symbols
autosurgeon-derive/src/attrs.rs19 symbols
autosurgeon/src/reconcile/reconcile_key_matching_tests.rs18 symbols

For agents

$ claude mcp add autosurgeon \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page