Skip to content
Projetos

Sobre

Uma estrutura de dados semelhante a JSON (um CRDT) que pode ser modificada simultaneamente por diferentes usuários e mesclada novamente de forma automática.

Ferramentas de desenvolvimento

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
+6
em 15 dias
+24
em 1 mês
+51

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

Automerge

Automerge logo

homepage main docs latest docs ci

Automerge is a library which provides fast implementations of several different CRDTs, a compact compression format for these CRDTs, and a sync protocol for efficiently transmitting those changes over the network. The objective of the project is to support local-first applications in the same way that relational databases support server applications - by providing mechanisms for persistence which allow application developers to avoid thinking about hard distributed computing problems. Automerge aims to be PostgreSQL for your local-first app.

On our website you'll find documentation for JavaScript, complete with tutorials and an API reference. This repository also contains the core Rust library which is compiled to WebAssembly and exposed in JavaScript, the docs for which can be found on docs.rs. Finally, there is a C library in rust/automerge-c — take a look at the README there for more details.

If you're familiar with CRDTs and interested in the design of Automerge in particular take a look at the binary format spec.

Finally, if you want to talk to us about this project please join our Discord server!

Status

This project is formed of a core Rust implementation which is exposed via FFI in javascript+WASM, C, and soon other languages. Alex (@alexjg) and Orion (@orionz) are working full time on maintaining automerge, other members of Ink & Switch are also contributing time and there are several other maintainers. We recently released Automerge 3 which achieved around a 10x reduction in memory usage.

In general we try and respect semver.

JavaScript

A stable release of the javascript package is available as @automerge/automerge.

Rust

The rust codebase is currently oriented around producing a performant backend for the Javascript wrapper and as such the API for Rust code is low level and not well documented. We will be returning to this over the next few months but for now you will need to be comfortable reading the tests and asking questions to figure out how to use it. If you are looking to build rust applications which use automerge you may want to look into autosurgeon.

Repository Organisation

  • ./rust - the rust implementation and also the Rust components of platform specific wrappers (e.g. automerge-wasm for the WASM API or automerge-c for the C FFI bindings)
  • ./javascript - The javascript library which uses automerge-wasm internally but presents a more idiomatic javascript interface
  • ./scripts - scripts which are useful to maintenance of the repository. This includes the scripts which are run in CI.
  • ./img - static assets for use in .md files

Building

To build this codebase you will need:

  • rust
  • node

And if you are interested in building the automerge-c library

  • cmake
  • cmocka
  • doxygen
  • ninja

You will also need to install the following with cargo install

  • wasm-bindgen-cli
  • wasm-opt
  • cargo-deny

And ensure you have added the wasm32-unknown-unknown target for rust cross-compilation. The wasm build also requires the nightly toolchain and the rust-src component (see the macOS instructions below for the exact commands); these are used by automerge-wasm and the JS package to build std with panic=unwind so panics surface as JS exceptions.

The various subprojects (the rust code, the wrapper projects) have their own build instructions, but to run the tests that will be run in CI you can run ./scripts/ci/run.

For macOS

These instructions worked to build locally on macOS 13.1 (arm64) as of Nov 29th 2022.

# clone the repo
git clone https://github.com/automerge/automerge
cd automerge

# install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# install cmake, node, cmocka
brew install cmake node cmocka

# install javascript dependencies
npm --prefix ./javascript install

# install rust dependencies
cargo install wasm-bindgen-cli wasm-opt cargo-deny

# get nightly rust to produce optimized automerge-c builds
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly

# add wasm target in addition to current architecture
rustup target add wasm32-unknown-unknown

# Run ci script
./scripts/ci/run

If your build fails to find cmocka.h you may need to teach it about homebrew's installation location:

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib
./scripts/ci/run

Nix Flake

If you have Nix installed, there is a flake available with all of the dependencies configured and some helper scripts.

$ nix develop

  ____                                          _
 / ___|___  _ __ ___  _ __ ___   __ _ _ __   __| |___
| |   / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` / __|
| |__| (_) | | | | | | | | | | | (_| | | | | (_| \__ \
 \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|___/


build:deno          | Build Deno-wrapped Wasm library
build:host          | Build for aarch64-darwin
build:node          | Build JS-wrapped Wasm library
build:wasi          | Build for Wasm32-WASI
build:wasm:nodejs   | Build for wasm32-unknown-unknown with Node.js bindgings
build:wasm:web      | Build for wasm32-unknown-unknown with web bindings
docs:build:host     | Refresh the docs
docs:build:wasm     | Refresh the docs with the wasm32-unknown-unknown target
docs:open:host      | Open refreshed docs
docs:open:wasm      | Open refreshed docs
# ✂️  SNIP ✂️

$ rustc --version
rustc 1.82.0 (f6e511eec 2024-10-15) # latest at time of writing

CI entry points are also exposed by the flake. GitHub Actions invokes these same commands, so on Linux the complete non-Windows CI suite can be run with:

$ nix run .#ci

Individual jobs can be run while iterating, for example:

$ nix run .#ci-fmt
$ nix run .#ci-lint
$ nix run .#ci-js-tests
$ nix run .#ci-node18-packaging-test

On macOS, nix run .#ci runs the native host test used by the macOS CI job. The native Windows job remains separate because Nix under WSL would test Linux rather than Windows.

Contributing

Please try and split your changes up into relatively independent commits which change one subsystem at a time and add good commit messages which describe what the change is and why you're making it (err on the side of longer commit messages). git blame should give future maintainers a good idea of why something is the way it is.

Releasing

Both the JavaScript package and the Rust crates are released by GitHub Actions workflows. The JavaScript package is triggered by GitHub Releases and the Rust crates are triggered by pushing tags.

JavaScript package

The JS package is released by a GitHub Actions workflow which picks up releases and publishes them to npm using trusted publishing. The steps to release are:

  1. Bump the version in javascript/package.json and merge the PR to main after CI passes.
  2. Create the tag js/automerge-<version> at that commit and publish a GitHub Release for it. Mark it as a prerelease if the package version is a prerelease (for example, 3.6.0-alpha.0).
  3. Check the Release workflow and the npm dist-tag:
    • Stable versions go to latest and also deploy the JS docs.
    • alpha and beta prereleases go to next.
    • Other named prereleases use their suffix without trailing numeric counters. For example, 3.6.0-signing-experimental.2 goes to signing-experimental. Use an npm-compatible tag name other than latest.

To build and inspect the package locally without publishing, run nix run .#release-js-build followed by nix run .#release-js-pack -- --dry-run.

Rust crates

Bump the versions of the crates in the various Cargo.tomls which you intend to release, update their internal dependency version requirements as needed, and merge the PR to main after CI passes. Update the changelog when releasing automerge.

Create and push the normal tag for each crate you intend to release:

  • rust/hexane-<version>
  • rust/automerge-<version>
  • rust/automerge-test-<version>

You can push these tags together or separately, in either order. Name the tags explicitly when pushing: GitHub does not trigger workflows if more than three tags are pushed at once. No GitHub Release is required.

One problem we have had to solve here is that automerge depends on hexane and you may be releasing a new version of both crates at once. To get around this the Release Rust crates workflow waits for up to 20 minutes for the non-dev workspace dependencies to appear on crates.io. That allows you to push both tags at once and the automerge workflow will wait for the hexane one to finish.

To verify packaging locally without publishing, run Cargo from rust/ once its dependencies are available, for example:

cargo publish --registry crates-io --dry-run --package automerge

For either registry, check whether the version is already present before retrying a failed publish job. A published version cannot be uploaded again.

Explore projetos relacionados

Carregando…