• Stars
    star
    249
  • Rank 158,002 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 1 year ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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(),
    }
})

More Repositories

1

automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
JavaScript
14,768
star
2

automerge

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
JavaScript
3,205
star
3

hypermerge

Build p2p collaborative applications without any server infrastructure in Node.js
TypeScript
1,277
star
4

pushpin

A collaborative corkboard app
TypeScript
619
star
5

trellis

Trello clone / sample app for Automerge persistence library
JavaScript
497
star
6

automerge-repo

TypeScript
401
star
7

mpl

a p2p document synchronization system for automerge
JavaScript
278
star
8

pixelpusher

pushin' pix
JavaScript
219
star
9

automerge-swift

Swift language bindings presenting Automerge
Swift
205
star
10

automerge-swift-archived

Wrapper around Swift types that can be modified concurrently by different users, and merged again automatically (a CRDT).
Swift
159
star
11

automerge-go

Go
79
star
12

MeetingNotes

An example application that uses Automerge-Swift to provide collaborative note taking for meetings.
Swift
50
star
13

automerge-py

Rust
35
star
14

automerge-perf

Performance tests for Automerge
JavaScript
35
star
15

automerge-repo-rs

Rust
31
star
16

pinecone

An example Electron + React + Hypermerge application designed to be a starting point for your own ideas.
TypeScript
29
star
17

automerge-net

Network examples for Automerge
JavaScript
25
star
18

automerge-codemirror

TypeScript
21
star
19

automerge-prosemirror

TypeScript
20
star
20

automerge-java

Java
15
star
21

automerge.github.io

JavaScript
14
star
22

automerge-connection

A generic network synchronisation protocol for Automerge
JavaScript
12
star
23

sync-server

Simple WebSocket server for syncing Automerge clients
JavaScript
12
star
24

automerge-repo-swift

Extends the Automerge-swift library, providing support for working with multiple Automerge documents at once, with pluggable network and storage providers.
Swift
11
star
25

automerge-repo-sync-server

JavaScript
9
star
26

contaaacts

An automerge-swifter demo app
Swift
5
star
27

pixelpusherd

An archiver daemon for pixelpusher
JavaScript
5
star
28

automerge-swift-backend

A XCFramework wrapper for the rs-backend
Shell
5
star
29

automerge-repo-quickstart

TypeScript
5
star
30

prosemirror-quickstart

An example of using Automerge + Prosemirror
TypeScript
3
star
31

automerge-repo-network-peerjs

Network adapter for automerge-repo using peerjs
TypeScript
1
star