diff --git a/.github/workflows/advisory-cron.yaml b/.github/workflows/advisory-cron.yaml
deleted file mode 100644
index 31bac5a3..00000000
--- a/.github/workflows/advisory-cron.yaml
+++ /dev/null
@@ -1,17 +0,0 @@
-name: Advisories
-on:
- schedule:
- - cron: '0 18 * * *'
-jobs:
- cargo-deny:
- runs-on: ubuntu-latest
- strategy:
- matrix:
- checks:
- - advisories
- - bans licenses sources
- steps:
- - uses: actions/checkout@v2
- - uses: EmbarkStudios/cargo-deny-action@v1
- with:
- command: check ${{ matrix.checks }}
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
deleted file mode 100644
index a5d42010..00000000
--- a/.github/workflows/ci.yaml
+++ /dev/null
@@ -1,177 +0,0 @@
-name: CI
-on:
- push:
- branches:
- - main
- pull_request:
- branches:
- - main
-jobs:
- fmt:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- components: rustfmt
- - uses: Swatinem/rust-cache@v1
- - run: ./scripts/ci/fmt
- shell: bash
-
- lint:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- components: clippy
- - uses: Swatinem/rust-cache@v1
- - run: ./scripts/ci/lint
- shell: bash
-
- docs:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- - uses: Swatinem/rust-cache@v1
- - name: Build rust docs
- run: ./scripts/ci/rust-docs
- shell: bash
- - name: Install doxygen
- run: sudo apt-get install -y doxygen
- shell: bash
-
- cargo-deny:
- runs-on: ubuntu-latest
- strategy:
- matrix:
- checks:
- - advisories
- - bans licenses sources
- continue-on-error: ${{ matrix.checks == 'advisories' }}
- steps:
- - uses: actions/checkout@v2
- - uses: EmbarkStudios/cargo-deny-action@v1
- with:
- arguments: '--manifest-path ./rust/Cargo.toml'
- command: check ${{ matrix.checks }}
-
- wasm_tests:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Install wasm-bindgen-cli
- run: cargo install wasm-bindgen-cli wasm-opt
- - name: Install wasm32 target
- run: rustup target add wasm32-unknown-unknown
- - name: run tests
- run: ./scripts/ci/wasm_tests
- deno_tests:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: denoland/setup-deno@v1
- with:
- deno-version: v1.x
- - name: Install wasm-bindgen-cli
- run: cargo install wasm-bindgen-cli wasm-opt
- - name: Install wasm32 target
- run: rustup target add wasm32-unknown-unknown
- - name: run tests
- run: ./scripts/ci/deno_tests
-
- js_fmt:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: install
- run: yarn global add prettier
- - name: format
- run: prettier -c javascript/.prettierrc javascript
-
- js_tests:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: Install wasm-bindgen-cli
- run: cargo install wasm-bindgen-cli wasm-opt
- - name: Install wasm32 target
- run: rustup target add wasm32-unknown-unknown
- - name: run tests
- run: ./scripts/ci/js_tests
-
- cmake_build:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- - uses: Swatinem/rust-cache@v1
- - name: Install CMocka
- run: sudo apt-get install -y libcmocka-dev
- - name: Install/update CMake
- uses: jwlawson/actions-setup-cmake@v1.12
- with:
- cmake-version: latest
- - name: Build and test C bindings
- run: ./scripts/ci/cmake-build Release Static
- shell: bash
-
- linux:
- runs-on: ubuntu-latest
- strategy:
- matrix:
- toolchain:
- - 1.60.0
- - nightly
- continue-on-error: ${{ matrix.toolchain == 'nightly' }}
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: ${{ matrix.toolchain }}
- default: true
- - uses: Swatinem/rust-cache@v1
- - run: ./scripts/ci/build-test
- shell: bash
-
- macos:
- runs-on: macos-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- - uses: Swatinem/rust-cache@v1
- - run: ./scripts/ci/build-test
- shell: bash
-
- windows:
- runs-on: windows-latest
- steps:
- - uses: actions/checkout@v2
- - uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: 1.66.0
- default: true
- - uses: Swatinem/rust-cache@v1
- - run: ./scripts/ci/build-test
- shell: bash
diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml
deleted file mode 100644
index b501d526..00000000
--- a/.github/workflows/docs.yaml
+++ /dev/null
@@ -1,52 +0,0 @@
-on:
- push:
- branches:
- - main
-
-name: Documentation
-
-jobs:
- deploy-docs:
- concurrency: deploy-docs
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
-
- - name: Toolchain
- uses: actions-rs/toolchain@v1
- with:
- profile: minimal
- toolchain: stable
- override: true
-
- - name: Cache
- uses: Swatinem/rust-cache@v1
-
- - name: Clean docs dir
- run: rm -rf docs
- shell: bash
-
- - name: Clean Rust docs dir
- uses: actions-rs/cargo@v1
- with:
- command: clean
- args: --manifest-path ./rust/Cargo.toml --doc
-
- - name: Build Rust docs
- uses: actions-rs/cargo@v1
- with:
- command: doc
- args: --manifest-path ./rust/Cargo.toml --workspace --all-features --no-deps
-
- - name: Move Rust docs
- run: mkdir -p docs && mv rust/target/doc/* docs/.
- shell: bash
-
- - name: Configure root page
- run: echo '' > docs/index.html
-
- - name: Deploy docs
- uses: peaceiris/actions-gh-pages@v3
- with:
- github_token: ${{ secrets.GITHUB_TOKEN }}
- publish_dir: ./docs
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
deleted file mode 100644
index b3c0aed1..00000000
--- a/.github/workflows/release.yaml
+++ /dev/null
@@ -1,106 +0,0 @@
-name: Release
-on:
- push:
- branches:
- - main
-
-jobs:
- check_if_wasm_version_upgraded:
- name: Check if WASM version has been upgraded
- runs-on: ubuntu-latest
- outputs:
- wasm_version: ${{ steps.version-updated.outputs.current-package-version }}
- wasm_has_updated: ${{ steps.version-updated.outputs.has-updated }}
- steps:
- - uses: JiPaix/package-json-updated-action@v1.0.5
- id: version-updated
- with:
- path: rust/automerge-wasm/package.json
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- publish-wasm:
- name: Publish WASM package
- runs-on: ubuntu-latest
- needs:
- - check_if_wasm_version_upgraded
- # We create release only if the version in the package.json has been upgraded
- if: needs.check_if_wasm_version_upgraded.outputs.wasm_has_updated == 'true'
- steps:
- - uses: actions/setup-node@v3
- with:
- node-version: '16.x'
- registry-url: 'https://registry.npmjs.org'
- - uses: denoland/setup-deno@v1
- - uses: actions/checkout@v3
- with:
- fetch-depth: 0
- ref: ${{ github.ref }}
- - name: Get rid of local github workflows
- run: rm -r .github/workflows
- - name: Remove tmp_branch if it exists
- run: git push origin :tmp_branch || true
- - run: git checkout -b tmp_branch
- - name: Install wasm-bindgen-cli
- run: cargo install wasm-bindgen-cli wasm-opt
- - name: Install wasm32 target
- run: rustup target add wasm32-unknown-unknown
- - name: run wasm js tests
- id: wasm_js_tests
- run: ./scripts/ci/wasm_tests
- - name: run wasm deno tests
- id: wasm_deno_tests
- run: ./scripts/ci/deno_tests
- - name: build release
- id: build_release
- run: |
- npm --prefix $GITHUB_WORKSPACE/rust/automerge-wasm run release
- - name: Collate deno release files
- if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
- run: |
- mkdir $GITHUB_WORKSPACE/deno_wasm_dist
- cp $GITHUB_WORKSPACE/rust/automerge-wasm/deno/* $GITHUB_WORKSPACE/deno_wasm_dist
- cp $GITHUB_WORKSPACE/rust/automerge-wasm/index.d.ts $GITHUB_WORKSPACE/deno_wasm_dist
- cp $GITHUB_WORKSPACE/rust/automerge-wasm/README.md $GITHUB_WORKSPACE/deno_wasm_dist
- cp $GITHUB_WORKSPACE/rust/automerge-wasm/LICENSE $GITHUB_WORKSPACE/deno_wasm_dist
- sed -i '1i /// ' $GITHUB_WORKSPACE/deno_wasm_dist/automerge_wasm.js
- - name: Create npm release
- if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
- run: |
- if [ "$(npm --prefix $GITHUB_WORKSPACE/rust/automerge-wasm show . version)" = "$VERSION" ]; then
- echo "This version is already published"
- exit 0
- fi
- EXTRA_ARGS="--access public"
- if [[ $VERSION == *"alpha."* ]] || [[ $VERSION == *"beta."* ]] || [[ $VERSION == *"rc."* ]]; then
- echo "Is pre-release version"
- EXTRA_ARGS="$EXTRA_ARGS --tag next"
- fi
- if [ "$NODE_AUTH_TOKEN" = "" ]; then
- echo "Can't publish on NPM, You need a NPM_TOKEN secret."
- false
- fi
- npm publish $GITHUB_WORKSPACE/rust/automerge-wasm $EXTRA_ARGS
- env:
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- VERSION: ${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
- - name: Commit wasm deno release files
- run: |
- git config --global user.name "actions"
- git config --global user.email actions@github.com
- git add $GITHUB_WORKSPACE/deno_wasm_dist
- git commit -am "Add deno release files"
- git push origin tmp_branch
- - name: Tag wasm release
- if: steps.wasm_js_tests.outcome == 'success' && steps.wasm_deno_tests.outcome == 'success'
- uses: softprops/action-gh-release@v1
- with:
- name: Automerge Wasm v${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
- tag_name: js/automerge-wasm-${{ needs.check_if_wasm_version_upgraded.outputs.wasm_version }}
- target_commitish: tmp_branch
- generate_release_notes: false
- draft: false
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- - name: Remove tmp_branch
- run: git push origin :tmp_branch
-
diff --git a/deno_wasm_dist/LICENSE b/deno_wasm_dist/LICENSE
new file mode 100644
index 00000000..63b21502
--- /dev/null
+++ b/deno_wasm_dist/LICENSE
@@ -0,0 +1,10 @@
+MIT License
+
+Copyright 2022, Ink & Switch LLC
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/deno_wasm_dist/README.md b/deno_wasm_dist/README.md
new file mode 100644
index 00000000..20256313
--- /dev/null
+++ b/deno_wasm_dist/README.md
@@ -0,0 +1,469 @@
+## Automerge WASM Low Level Interface
+
+This package is a low level interface to the [automerge rust](https://github.com/automerge/automerge-rs/tree/experiment) CRDT. The api is intended to be as "close to the metal" as possible with only a few ease of use accommodations. This library is used as the underpinnings for the [Automerge JS wrapper](https://github.com/automerge/automerge-rs/tree/experiment/automerge-js) and can be used as is or as a basis for another higher level expression of a CRDT.
+
+All example code can be found in `test/readme.ts`
+
+### Why CRDT?
+
+CRDT stands for Conflict Free Replicated Data Type. It is a data structure that offers eventual consistency where multiple actors can write to the document independently and then these edits can be automatically merged together into a coherent document that, as much as possible, preserves the intent of the different writers. This allows for novel masterless application design where different components need not have a central coordinating server when altering application state.
+
+### Terminology
+
+The term Actor, Object Id and Heads are used through this documentation. Detailed explanations are in the glossary at the end of this readme. But the most basic definition would be...
+
+An Actor is a unique id that distinguishes a single writer to a document. It can be any hex string.
+
+An Object id uniquely identifies a Map, List or Text object within a document. It can be treated as an opaque string and can be used across documents. This id comes as a string in the form of `{number}@{actor}` - so `"10@aabbcc"` for example. The string `"_root"` or `"/"` can also be used to refer to the document root. These strings are durable and can be used on any descendant or copy of the document that generated them.
+
+Heads refers to a set of hashes that uniquely identifies a point in time in a document's history. Heads are useful for comparing documents state or retrieving past states from the document.
+
+### Automerge Scalar Types
+
+Automerge has many scalar types. Methods like `put()` and `insert()` take an optional data type parameter. Normally the type can be inferred but in some cases, such as telling the difference between int, uint and a counter, it cannot.
+
+These are puts without a data type
+
+```javascript
+ import { create } from "@automerge/automerge-wasm"
+
+ let doc = create()
+ doc.put("/", "prop1", 100) // int
+ doc.put("/", "prop2", 3.14) // f64
+ doc.put("/", "prop3", "hello world")
+ doc.put("/", "prop4", new Date())
+ doc.put("/", "prop5", new Uint8Array([1,2,3]))
+ doc.put("/", "prop6", true)
+ doc.put("/", "prop7", null)
+```
+
+Put's with a data type and examples of all the supported data types.
+
+While int vs uint vs f64 matters little in javascript, Automerge is a cross platform library where these distinctions matter.
+
+```javascript
+ import { create } from "@automerge/automerge-wasm"
+
+ let doc = create()
+ doc.put("/", "prop1", 100, "int")
+ doc.put("/", "prop2", 100, "uint")
+ doc.put("/", "prop3", 100.5, "f64")
+ doc.put("/", "prop4", 100, "counter")
+ doc.put("/", "prop5", 1647531707301, "timestamp")
+ doc.put("/", "prop6", new Date(), "timestamp")
+ doc.put("/", "prop7", "hello world", "str")
+ doc.put("/", "prop8", new Uint8Array([1,2,3]), "bytes")
+ doc.put("/", "prop9", true, "boolean")
+ doc.put("/", "prop10", null, "null")
+```
+
+### Automerge Object Types
+
+Automerge WASM supports 3 object types. Maps, lists, and text. Maps are key value stores where the values can be any scalar type or any object type. Lists are numerically indexed sets of data that can hold any scalar or any object type.
+
+```javascript
+ import { create } from "@automerge/automerge-wasm"
+
+ let doc = create()
+
+ // you can create an object by passing in the inital state - if blank pass in `{}`
+ // the return value is the Object Id
+ // these functions all return an object id
+
+ let config = doc.putObject("/", "config", { align: "left", archived: false, cycles: [10, 19, 21] })
+ let token = doc.putObject("/", "tokens", {})
+
+ // lists can be made with javascript arrays
+
+ let birds = doc.putObject("/", "birds", ["bluejay", "penguin", "puffin"])
+ let bots = doc.putObject("/", "bots", [])
+
+ // text is initialized with a string
+
+ let notes = doc.putObject("/", "notes", "Hello world!")
+```
+
+You can access objects by passing the object id as the first parameter for a call.
+
+```javascript
+ import { create } from "@automerge/automerge-wasm"
+
+ let doc = create()
+
+ let config = doc.putObject("/", "config", { align: "left", archived: false, cycles: [10, 19, 21] })
+
+ doc.put(config, "align", "right")
+
+ // Anywhere Object Ids are being used a path can also be used.
+ // The following two statements are equivalent:
+
+ // get the id then use it
+
+ // get returns a single simple javascript value or undefined
+ // getWithType returns an Array of the datatype plus basic type or null
+
+ let id = doc.getWithType("/", "config")
+ if (id && id[0] === 'map') {
+ doc.put(id[1], "align", "right")
+ }
+
+ // use a path instead
+
+ doc.put("/config", "align", "right")
+```
+
+Using the id directly is always faster (as it prevents the path to id conversion internally) so it is preferred for performance critical code.
+
+### Maps
+
+Maps are key/value stores. The root object is always a map. The keys are always strings. The values can be any scalar type or any object.
+
+```javascript
+ let doc = create()
+ let mymap = doc.putObject("_root", "mymap", { foo: "bar"})
+ // make a new map with the foo key
+
+ doc.put(mymap, "bytes", new Uint8Array([1,2,3]))
+ // assign a byte array to key `bytes` of the mymap object
+
+ let submap = doc.putObject(mymap, "sub", {})
+ // make a new empty object and assign it to the key `sub` of mymap
+
+ doc.keys(mymap) // returns ["bytes","foo","sub"]
+ doc.materialize("_root") // returns { mymap: { bytes: new Uint8Array([1,2,3]), foo: "bar", sub: {}}}
+```
+
+### Lists
+
+Lists are index addressable sets of values. These values can be any scalar or object type. You can manipulate lists with `insert()`, `put()`, `insertObject()`, `putObject()`, `push()`, `pushObject()`, `splice()`, and `delete()`.
+
+```javascript
+ let doc = create()
+ let items = doc.putObject("_root", "items", [10,"box"])
+ // init a new list with two elements
+ doc.push(items, true) // push `true` to the end of the list
+ doc.putObject(items, 0, { hello: "world" }) // overwrite the value 10 with an object with a key and value
+ doc.delete(items, 1) // delete "box"
+ doc.splice(items, 2, 0, ["bag", "brick"]) // splice in "bag" and "brick" at position 2
+ doc.insert(items, 0, "bat") // insert "bat" to the beginning of the list
+ doc.insertObject(items, 1, [1,2]) // insert a list with 2 values at pos 1
+
+ doc.materialize(items) // returns [ "bat", [1,2], { hello : "world" }, true, "bag", "brick"]
+ doc.length(items) // returns 6
+```
+
+### Text
+
+Text is a specialized list type intended for modifying a text document. The primary way to interact with a text document is via the `splice()` method. Spliced strings will be indexable by character (important to note for platforms that index by graphmeme cluster).
+
+```javascript
+ let doc = create("aaaaaa")
+ let notes = doc.putObject("_root", "notes", "Hello world")
+ doc.splice(notes, 6, 5, "everyone")
+
+ doc.text(notes) // returns "Hello everyone"
+```
+
+### Tables
+
+Automerge's Table type is currently not implemented.
+
+### Querying Data
+
+When querying maps use the `get()` method with the object in question and the property to query. This method returns a tuple with the data type and the data. The `keys()` method will return all the keys on the object. If you are interested in conflicted values from a merge use `getAll()` instead which returns an array of values instead of just the winner.
+
+```javascript
+ let doc1 = create("aabbcc")
+ doc1.put("_root", "key1", "val1")
+ let key2 = doc1.putObject("_root", "key2", [])
+
+ doc1.get("_root", "key1") // returns "val1"
+ doc1.getWithType("_root", "key2") // returns ["list", "2@aabbcc"]
+ doc1.keys("_root") // returns ["key1", "key2"]
+
+ let doc2 = doc1.fork("ffaaff")
+
+ // put a value concurrently
+ doc1.put("_root","key3","doc1val")
+ doc2.put("_root","key3","doc2val")
+
+ doc1.merge(doc2)
+
+ doc1.get("_root","key3") // returns "doc2val"
+ doc1.getAll("_root","key3") // returns [[ "str", "doc1val"], ["str", "doc2val"]]
+```
+
+### Counters
+
+Counters are 64 bit ints that support the increment operation. Frequently different actors will want to increment or decrement a number and have all these coalesse into a merged value.
+
+```javascript
+ let doc1 = create("aaaaaa")
+ doc1.put("_root", "number", 0)
+ doc1.put("_root", "total", 0, "counter")
+
+ let doc2 = doc1.fork("bbbbbb")
+ doc2.put("_root", "number", 10)
+ doc2.increment("_root", "total", 11)
+
+ doc1.put("_root", "number", 20)
+ doc1.increment("_root", "total", 22)
+
+ doc1.merge(doc2)
+
+ doc1.materialize("_root") // returns { number: 10, total: 33 }
+```
+
+### Transactions
+
+Generally speaking you don't need to think about transactions when using Automerge. Normal edits queue up into an in-progress transaction. You can query the number of ops in the current transaction with `pendingOps()`. The transaction will commit automatically on certains calls such as `save()`, `saveIncremental()`, `fork()`, `merge()`, `getHeads()`, `applyChanges()`, `generateSyncMessage()`, and `receiveSyncMessage()`. When the transaction commits the heads of the document change. If you want to roll back all the in progress ops you can call `doc.rollback()`. If you want to manually commit a transaction in progress you can call `doc.commit()` with an optional commit message and timestamp.
+
+```javascript
+ let doc = create()
+
+ doc.put("_root", "key", "val1")
+
+ doc.get("_root", "key") // returns "val1"
+ doc.pendingOps() // returns 1
+
+ doc.rollback()
+
+ doc.get("_root", "key") // returns null
+ doc.pendingOps() // returns 0
+
+ doc.put("_root", "key", "val2")
+
+ doc.pendingOps() // returns 1
+
+ doc.commit("test commit 1")
+
+ doc.get("_root", "key") // returns "val2"
+ doc.pendingOps() // returns 0
+```
+
+### Viewing Old Versions of the Document
+
+All query functions can take an optional argument of `heads` which allow you to query a prior document state. Heads are a set of change hashes that uniquely identify a point in the document history. The `getHeads()` method can retrieve these at any point.
+
+```javascript
+ let doc = create()
+
+ doc.put("_root", "key", "val1")
+ let heads1 = doc.getHeads()
+
+ doc.put("_root", "key", "val2")
+ let heads2 = doc.getHeads()
+
+ doc.put("_root", "key", "val3")
+
+ doc.get("_root","key") // returns "val3"
+ doc.get("_root","key",heads2) // returns "val2"
+ doc.get("_root","key",heads1) // returns "val1"
+ doc.get("_root","key",[]) // returns undefined
+```
+
+This works for `get()`, `getAll()`, `keys()`, `length()`, `text()`, and `materialize()`
+
+Queries of old document states are not indexed internally and will be slower than normal access. If you need a fast indexed version of a document at a previous point in time you can create one with `doc.forkAt(heads, actor?)`
+
+### Forking and Merging
+
+You can `fork()` a document which makes an exact copy of it. This assigns a new actor so changes made to the fork can be merged back in with the original. The `forkAt()` takes a Heads, allowing you to fork off a document from a previous point in its history. These documents allocate new memory in WASM and need to be freed.
+
+The `merge()` command applies all changes in the argument doc into the calling doc. Therefore if doc a has 1000 changes that doc b lacks and doc b has only 10 changes that doc a lacks, `a.merge(b)` will be much faster than `b.merge(a)`.
+
+```javascript
+ let doc1 = create()
+ doc1.put("_root", "key1", "val1")
+
+ let doc2 = doc1.fork()
+
+ doc1.put("_root", "key2", "val2")
+ doc2.put("_root", "key3", "val3")
+
+ doc1.merge(doc2)
+
+ doc1.materialize("_root") // returns { key1: "val1", key2: "val2", key3: "val3" }
+ doc2.materialize("_root") // returns { key1: "val1", key3: "val3" }
+```
+
+Note that calling `a.merge(a)` will produce an unrecoverable error from the wasm-bindgen layer which (as of this writing) there is no workaround for.
+
+### Saving and Loading
+
+Calling `save()` converts the document to a compressed `Uint8Array()` that can be saved to durable storage. This format uses a columnar storage format that compresses away most of the Automerge metadata needed to manage the CRDT state, but does include all of the change history.
+
+If you wish to incrementally update a saved Automerge doc you can call `saveIncremental()` to get a `Uint8Array()` of bytes that can be appended to the file with all the new changes(). Note that the `saveIncremental()` bytes are not as compressed as the whole document save as each chunk has metadata information needed to parse it. It may make sense to periodically perform a new `save()` to get the smallest possible file footprint.
+
+The `load()` function takes a `Uint8Array()` of bytes produced in this way and constitutes a new document. The `loadIncremental()` method is available if you wish to consume the result of a `saveIncremental()` with an already instanciated document.
+
+```javascript
+ import { create, load } from "@automerge/automerge-wasm"
+
+ let doc1 = create()
+
+ doc1.put("_root", "key1", "value1")
+
+ let save1 = doc1.save()
+
+ let doc2 = load(save1)
+
+ doc2.materialize("_root") // returns { key1: "value1" }
+
+ doc1.put("_root", "key2", "value2")
+
+ let saveIncremental = doc1.saveIncremental()
+
+ let save2 = doc1.save()
+
+ let save3 = new Uint8Array([... save1, ... saveIncremental])
+
+ // save2 has fewer bytes than save3 but contains the same ops
+
+ doc2.loadIncremental(saveIncremental)
+
+ let doc3 = load(save2)
+
+ let doc4 = load(save3)
+
+ doc1.materialize("_root") // returns { key1: "value1", key2: "value2" }
+ doc2.materialize("_root") // returns { key1: "value1", key2: "value2" }
+ doc3.materialize("_root") // returns { key1: "value1", key2: "value2" }
+ doc4.materialize("_root") // returns { key1: "value1", key2: "value2" }
+```
+
+One interesting feature of automerge binary saves is that they can be concatenated together in any order and can still be loaded into a coherent merged document.
+
+```javascript
+import { load } from "@automerge/automerge-wasm"
+import * as fs from "fs"
+
+let file1 = fs.readFileSync("automerge_save_1");
+let file2 = fs.readFileSync("automerge_save_2");
+
+let docA = load(file1).merge(load(file2))
+let docB = load(Buffer.concat([ file1, file2 ]))
+
+assert.deepEqual(docA.materialize("/"), docB.materialize("/"))
+assert.equal(docA.save(), docB.save())
+```
+
+### Syncing
+
+When syncing a document the `generateSyncMessage()` and `receiveSyncMessage()` methods will produce and consume sync messages. A sync state object will need to be managed for the duration of the connection (created by the function `initSyncState()` and can be serialized to a Uint8Array() to preserve sync state with the `encodeSyncState()` and `decodeSyncState()` functions.
+
+A very simple sync implementation might look like this.
+
+```javascript
+ import { encodeSyncState, decodeSyncState, initSyncState } from "@automerge/automerge-wasm"
+
+ let states = {}
+
+ function receiveMessageFromPeer(doc, peer_id, message) {
+ let syncState = states[peer_id]
+ doc.receiveMessage(syncState, message)
+ let reply = doc.generateSyncMessage(syncState)
+ if (reply) {
+ sendMessage(peer_id, reply)
+ }
+ }
+
+ function notifyPeerAboutUpdates(doc, peer_id) {
+ let syncState = states[peer_id]
+ let message = doc.generateSyncMessage(syncState)
+ if (message) {
+ sendMessage(peer_id, message)
+ }
+ }
+
+ function onDisconnect(peer_id) {
+ let state = states[peer_id]
+ if (state) {
+ saveSyncToStorage(peer_id, encodeSyncState(state))
+ }
+ delete states[peer_id]
+ }
+
+ function onConnect(peer_id) {
+ let state = loadSyncFromStorage(peer_id)
+ if (state) {
+ states[peer_id] = decodeSyncState(state)
+ } else {
+ states[peer_id] = initSyncState()
+ }
+ }
+```
+
+### Glossary: Actors
+
+Some basic concepts you will need to know to better understand the api are Actors and Object Ids.
+
+Actors are ids that need to be unique to each process writing to a document. This is normally one actor per device. Or for a web app one actor per tab per browser would be needed. It can be a uuid, or a public key, or a certificate, as your application demands. All that matters is that its bytes are unique. Actors are always expressed in this api as a hex string.
+
+Methods that create new documents will generate random actors automatically - if you wish to supply your own it is always taken as an optional argument. This is true for the following functions.
+
+```javascript
+ import { create, load } from "@automerge/automerge-wasm"
+
+ let doc1 = create() // random actorid
+ let doc2 = create("aabbccdd")
+ let doc3 = doc1.fork() // random actorid
+ let doc4 = doc2.fork("ccdd0011")
+ let doc5 = load(doc3.save()) // random actorid
+ let doc6 = load(doc4.save(), "00aabb11")
+
+ let actor = doc1.getActor()
+```
+
+### Glossary: Object Id's
+
+Object Ids uniquely identify an object within a document. They are represented as strings in the format of `{counter}@{actor}`. The root object is a special case and can be referred to as `_root`. The counter is an ever increasing integer, starting at 1, that is always one higher than the highest counter seen in the document thus far. Object Id's do not change when the object is modified but they do if it is overwritten with a new object.
+
+```javascript
+ let doc = create("aabbcc")
+ let o1 = doc.putObject("_root", "o1", {})
+ let o2 = doc.putObject("_root", "o2", {})
+ doc.put(o1, "hello", "world")
+
+ assert.deepEqual(doc.materialize("_root"), { "o1": { hello: "world" }, "o2": {} })
+ assert.equal(o1, "1@aabbcc")
+ assert.equal(o2, "2@aabbcc")
+
+ let o1v2 = doc.putObject("_root", "o1", {})
+
+ doc.put(o1, "a", "b") // modifying an overwritten object - does nothing
+ doc.put(o1v2, "x", "y") // modifying the new "o1" object
+
+ assert.deepEqual(doc.materialize("_root"), { "o1": { x: "y" }, "o2": {} })
+```
+
+### Appendix: Building
+
+ The following steps should allow you to build the package
+
+ ```
+ $ rustup target add wasm32-unknown-unknown
+ $ cargo install wasm-bindgen-cli
+ $ cargo install wasm-opt
+ $ yarn
+ $ yarn release
+ $ yarn pack
+ ```
+
+### Appendix: WASM and Memory Allocation
+
+Allocated memory in rust will be freed automatically on platforms that support `FinalizationRegistry`.
+
+This is currently supported in [all major browsers and nodejs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry).
+
+On unsupported platforms you can free memory explicitly.
+
+```javascript
+ import { create, initSyncState } from "@automerge/automerge-wasm"
+
+ let doc = create()
+ let sync = initSyncState()
+
+ doc.free()
+ sync.free()
+```
diff --git a/deno_wasm_dist/automerge_wasm.js b/deno_wasm_dist/automerge_wasm.js
new file mode 100644
index 00000000..b987558d
--- /dev/null
+++ b/deno_wasm_dist/automerge_wasm.js
@@ -0,0 +1,1663 @@
+///
+
+
+const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
+
+cachedTextDecoder.decode();
+
+let cachedUint8Memory0 = new Uint8Array();
+
+function getUint8Memory0() {
+ if (cachedUint8Memory0.byteLength === 0) {
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
+ }
+ return cachedUint8Memory0;
+}
+
+function getStringFromWasm0(ptr, len) {
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
+}
+
+const heap = new Array(32).fill(undefined);
+
+heap.push(undefined, null, true, false);
+
+let heap_next = heap.length;
+
+function addHeapObject(obj) {
+ if (heap_next === heap.length) heap.push(heap.length + 1);
+ const idx = heap_next;
+ heap_next = heap[idx];
+
+ heap[idx] = obj;
+ return idx;
+}
+
+function getObject(idx) { return heap[idx]; }
+
+function dropObject(idx) {
+ if (idx < 36) return;
+ heap[idx] = heap_next;
+ heap_next = idx;
+}
+
+function takeObject(idx) {
+ const ret = getObject(idx);
+ dropObject(idx);
+ return ret;
+}
+
+let WASM_VECTOR_LEN = 0;
+
+const cachedTextEncoder = new TextEncoder('utf-8');
+
+const encodeString = function (arg, view) {
+ return cachedTextEncoder.encodeInto(arg, view);
+};
+
+function passStringToWasm0(arg, malloc, realloc) {
+
+ if (realloc === undefined) {
+ const buf = cachedTextEncoder.encode(arg);
+ const ptr = malloc(buf.length);
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
+ WASM_VECTOR_LEN = buf.length;
+ return ptr;
+ }
+
+ let len = arg.length;
+ let ptr = malloc(len);
+
+ const mem = getUint8Memory0();
+
+ let offset = 0;
+
+ for (; offset < len; offset++) {
+ const code = arg.charCodeAt(offset);
+ if (code > 0x7F) break;
+ mem[ptr + offset] = code;
+ }
+
+ if (offset !== len) {
+ if (offset !== 0) {
+ arg = arg.slice(offset);
+ }
+ ptr = realloc(ptr, len, len = offset + arg.length * 3);
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
+ const ret = encodeString(arg, view);
+
+ offset += ret.written;
+ }
+
+ WASM_VECTOR_LEN = offset;
+ return ptr;
+}
+
+function isLikeNone(x) {
+ return x === undefined || x === null;
+}
+
+let cachedInt32Memory0 = new Int32Array();
+
+function getInt32Memory0() {
+ if (cachedInt32Memory0.byteLength === 0) {
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
+ }
+ return cachedInt32Memory0;
+}
+
+let cachedFloat64Memory0 = new Float64Array();
+
+function getFloat64Memory0() {
+ if (cachedFloat64Memory0.byteLength === 0) {
+ cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
+ }
+ return cachedFloat64Memory0;
+}
+
+function debugString(val) {
+ // primitive types
+ const type = typeof val;
+ if (type == 'number' || type == 'boolean' || val == null) {
+ return `${val}`;
+ }
+ if (type == 'string') {
+ return `"${val}"`;
+ }
+ if (type == 'symbol') {
+ const description = val.description;
+ if (description == null) {
+ return 'Symbol';
+ } else {
+ return `Symbol(${description})`;
+ }
+ }
+ if (type == 'function') {
+ const name = val.name;
+ if (typeof name == 'string' && name.length > 0) {
+ return `Function(${name})`;
+ } else {
+ return 'Function';
+ }
+ }
+ // objects
+ if (Array.isArray(val)) {
+ const length = val.length;
+ let debug = '[';
+ if (length > 0) {
+ debug += debugString(val[0]);
+ }
+ for(let i = 1; i < length; i++) {
+ debug += ', ' + debugString(val[i]);
+ }
+ debug += ']';
+ return debug;
+ }
+ // Test for built-in
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
+ let className;
+ if (builtInMatches.length > 1) {
+ className = builtInMatches[1];
+ } else {
+ // Failed to match the standard '[object ClassName]'
+ return toString.call(val);
+ }
+ if (className == 'Object') {
+ // we're a user defined class or Object
+ // JSON.stringify avoids problems with cycles, and is generally much
+ // easier than looping through ownProperties of `val`.
+ try {
+ return 'Object(' + JSON.stringify(val) + ')';
+ } catch (_) {
+ return 'Object';
+ }
+ }
+ // errors
+ if (val instanceof Error) {
+ return `${val.name}: ${val.message}\n${val.stack}`;
+ }
+ // TODO we could test for more things here, like `Set`s and `Map`s.
+ return className;
+}
+
+function _assertClass(instance, klass) {
+ if (!(instance instanceof klass)) {
+ throw new Error(`expected instance of ${klass.name}`);
+ }
+ return instance.ptr;
+}
+/**
+* @param {boolean} text_v2
+* @param {string | undefined} actor
+* @returns {Automerge}
+*/
+export function create(text_v2, actor) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = isLikeNone(actor) ? 0 : passStringToWasm0(actor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.create(retptr, text_v2, ptr0, len0);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return Automerge.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {Uint8Array} data
+* @param {boolean} text_v2
+* @param {string | undefined} actor
+* @returns {Automerge}
+*/
+export function load(data, text_v2, actor) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = isLikeNone(actor) ? 0 : passStringToWasm0(actor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.load(retptr, addHeapObject(data), text_v2, ptr0, len0);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return Automerge.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {any} change
+* @returns {Uint8Array}
+*/
+export function encodeChange(change) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.encodeChange(retptr, addHeapObject(change));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {Uint8Array} change
+* @returns {any}
+*/
+export function decodeChange(change) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.decodeChange(retptr, addHeapObject(change));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @returns {SyncState}
+*/
+export function initSyncState() {
+ const ret = wasm.initSyncState();
+ return SyncState.__wrap(ret);
+}
+
+/**
+* @param {any} state
+* @returns {SyncState}
+*/
+export function importSyncState(state) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.importSyncState(retptr, addHeapObject(state));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return SyncState.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {SyncState} state
+* @returns {any}
+*/
+export function exportSyncState(state) {
+ _assertClass(state, SyncState);
+ const ret = wasm.exportSyncState(state.ptr);
+ return takeObject(ret);
+}
+
+/**
+* @param {any} message
+* @returns {Uint8Array}
+*/
+export function encodeSyncMessage(message) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.encodeSyncMessage(retptr, addHeapObject(message));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {Uint8Array} msg
+* @returns {any}
+*/
+export function decodeSyncMessage(msg) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.decodeSyncMessage(retptr, addHeapObject(msg));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+/**
+* @param {SyncState} state
+* @returns {Uint8Array}
+*/
+export function encodeSyncState(state) {
+ _assertClass(state, SyncState);
+ const ret = wasm.encodeSyncState(state.ptr);
+ return takeObject(ret);
+}
+
+/**
+* @param {Uint8Array} data
+* @returns {SyncState}
+*/
+export function decodeSyncState(data) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.decodeSyncState(retptr, addHeapObject(data));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return SyncState.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+}
+
+function handleError(f, args) {
+ try {
+ return f.apply(this, args);
+ } catch (e) {
+ wasm.__wbindgen_exn_store(addHeapObject(e));
+ }
+}
+
+function getArrayU8FromWasm0(ptr, len) {
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
+}
+/**
+* How text is represented in materialized objects on the JS side
+*/
+export const TextRepresentation = Object.freeze({
+/**
+* As an array of characters and objects
+*/
+Array:0,"0":"Array",
+/**
+* As a single JS string
+*/
+String:1,"1":"String", });
+
+const AutomergeFinalization = new FinalizationRegistry(ptr => wasm.__wbg_automerge_free(ptr));
+/**
+*/
+export class Automerge {
+
+ static __wrap(ptr) {
+ const obj = Object.create(Automerge.prototype);
+ obj.ptr = ptr;
+ AutomergeFinalization.register(obj, obj.ptr, obj);
+ return obj;
+ }
+
+ __destroy_into_raw() {
+ const ptr = this.ptr;
+ this.ptr = 0;
+ AutomergeFinalization.unregister(this);
+ return ptr;
+ }
+
+ free() {
+ const ptr = this.__destroy_into_raw();
+ wasm.__wbg_automerge_free(ptr);
+ }
+ /**
+ * @param {string | undefined} actor
+ * @param {number} text_rep
+ * @returns {Automerge}
+ */
+ static new(actor, text_rep) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = isLikeNone(actor) ? 0 : passStringToWasm0(actor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.automerge_new(retptr, ptr0, len0, text_rep);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return Automerge.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {string | undefined} actor
+ * @returns {Automerge}
+ */
+ clone(actor) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = isLikeNone(actor) ? 0 : passStringToWasm0(actor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.automerge_clone(retptr, this.ptr, ptr0, len0);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return Automerge.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {string | undefined} actor
+ * @param {any} heads
+ * @returns {Automerge}
+ */
+ fork(actor, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ var ptr0 = isLikeNone(actor) ? 0 : passStringToWasm0(actor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ wasm.automerge_fork(retptr, this.ptr, ptr0, len0, addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return Automerge.__wrap(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @returns {any}
+ */
+ pendingOps() {
+ const ret = wasm.automerge_pendingOps(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @param {string | undefined} message
+ * @param {number | undefined} time
+ * @returns {any}
+ */
+ commit(message, time) {
+ var ptr0 = isLikeNone(message) ? 0 : passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ const ret = wasm.automerge_commit(this.ptr, ptr0, len0, !isLikeNone(time), isLikeNone(time) ? 0 : time);
+ return takeObject(ret);
+ }
+ /**
+ * @param {Automerge} other
+ * @returns {Array}
+ */
+ merge(other) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ _assertClass(other, Automerge);
+ wasm.automerge_merge(retptr, this.ptr, other.ptr);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @returns {number}
+ */
+ rollback() {
+ const ret = wasm.automerge_rollback(this.ptr);
+ return ret;
+ }
+ /**
+ * @param {any} obj
+ * @param {Array | undefined} heads
+ * @returns {Array}
+ */
+ keys(obj, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_keys(retptr, this.ptr, addHeapObject(obj), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {Array | undefined} heads
+ * @returns {string}
+ */
+ text(obj, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_text(retptr, this.ptr, addHeapObject(obj), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
+ var ptr0 = r0;
+ var len0 = r1;
+ if (r3) {
+ ptr0 = 0; len0 = 0;
+ throw takeObject(r2);
+ }
+ return getStringFromWasm0(ptr0, len0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ wasm.__wbindgen_free(ptr0, len0);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {number} start
+ * @param {number} delete_count
+ * @param {any} text
+ */
+ splice(obj, start, delete_count, text) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_splice(retptr, this.ptr, addHeapObject(obj), start, delete_count, addHeapObject(text));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} value
+ * @param {any} datatype
+ */
+ push(obj, value, datatype) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_push(retptr, this.ptr, addHeapObject(obj), addHeapObject(value), addHeapObject(datatype));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} value
+ * @returns {string | undefined}
+ */
+ pushObject(obj, value) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_pushObject(retptr, this.ptr, addHeapObject(obj), addHeapObject(value));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
+ if (r3) {
+ throw takeObject(r2);
+ }
+ let v0;
+ if (r0 !== 0) {
+ v0 = getStringFromWasm0(r0, r1).slice();
+ wasm.__wbindgen_free(r0, r1 * 1);
+ }
+ return v0;
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {number} index
+ * @param {any} value
+ * @param {any} datatype
+ */
+ insert(obj, index, value, datatype) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_insert(retptr, this.ptr, addHeapObject(obj), index, addHeapObject(value), addHeapObject(datatype));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {number} index
+ * @param {any} value
+ * @returns {string | undefined}
+ */
+ insertObject(obj, index, value) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_insertObject(retptr, this.ptr, addHeapObject(obj), index, addHeapObject(value));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
+ if (r3) {
+ throw takeObject(r2);
+ }
+ let v0;
+ if (r0 !== 0) {
+ v0 = getStringFromWasm0(r0, r1).slice();
+ wasm.__wbindgen_free(r0, r1 * 1);
+ }
+ return v0;
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ * @param {any} value
+ * @param {any} datatype
+ */
+ put(obj, prop, value, datatype) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_put(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop), addHeapObject(value), addHeapObject(datatype));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ * @param {any} value
+ * @returns {any}
+ */
+ putObject(obj, prop, value) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_putObject(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop), addHeapObject(value));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ * @param {any} value
+ */
+ increment(obj, prop, value) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_increment(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop), addHeapObject(value));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ * @param {Array | undefined} heads
+ * @returns {any}
+ */
+ get(obj, prop, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_get(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ * @param {Array | undefined} heads
+ * @returns {any}
+ */
+ getWithType(obj, prop, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getWithType(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} arg
+ * @param {Array | undefined} heads
+ * @returns {Array}
+ */
+ getAll(obj, arg, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getAll(retptr, this.ptr, addHeapObject(obj), addHeapObject(arg), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} enable
+ * @returns {any}
+ */
+ enableFreeze(enable) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_enableFreeze(retptr, this.ptr, addHeapObject(enable));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} enable
+ * @returns {any}
+ */
+ enablePatches(enable) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_enablePatches(retptr, this.ptr, addHeapObject(enable));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} datatype
+ * @param {any} _function
+ */
+ registerDatatype(datatype, _function) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_registerDatatype(retptr, this.ptr, addHeapObject(datatype), addHeapObject(_function));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} object
+ * @param {any} meta
+ * @param {any} callback
+ * @returns {any}
+ */
+ applyPatches(object, meta, callback) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_applyPatches(retptr, this.ptr, addHeapObject(object), addHeapObject(meta), addHeapObject(callback));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @returns {Array}
+ */
+ popPatches() {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_popPatches(retptr, this.ptr);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {Array | undefined} heads
+ * @returns {number}
+ */
+ length(obj, heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_length(retptr, this.ptr, addHeapObject(obj), isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getFloat64Memory0()[retptr / 8 + 0];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
+ if (r3) {
+ throw takeObject(r2);
+ }
+ return r0;
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {any} prop
+ */
+ delete(obj, prop) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_delete(retptr, this.ptr, addHeapObject(obj), addHeapObject(prop));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @returns {Uint8Array}
+ */
+ save() {
+ const ret = wasm.automerge_save(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @returns {Uint8Array}
+ */
+ saveIncremental() {
+ const ret = wasm.automerge_saveIncremental(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @param {Uint8Array} data
+ * @returns {number}
+ */
+ loadIncremental(data) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_loadIncremental(retptr, this.ptr, addHeapObject(data));
+ var r0 = getFloat64Memory0()[retptr / 8 + 0];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
+ if (r3) {
+ throw takeObject(r2);
+ }
+ return r0;
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} changes
+ */
+ applyChanges(changes) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_applyChanges(retptr, this.ptr, addHeapObject(changes));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} have_deps
+ * @returns {Array}
+ */
+ getChanges(have_deps) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getChanges(retptr, this.ptr, addHeapObject(have_deps));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} hash
+ * @returns {any}
+ */
+ getChangeByHash(hash) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getChangeByHash(retptr, this.ptr, addHeapObject(hash));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {Automerge} other
+ * @returns {Array}
+ */
+ getChangesAdded(other) {
+ _assertClass(other, Automerge);
+ const ret = wasm.automerge_getChangesAdded(this.ptr, other.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @returns {Array}
+ */
+ getHeads() {
+ const ret = wasm.automerge_getHeads(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @returns {string}
+ */
+ getActorId() {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getActorId(retptr, this.ptr);
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ return getStringFromWasm0(r0, r1);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ wasm.__wbindgen_free(r0, r1);
+ }
+ }
+ /**
+ * @returns {any}
+ */
+ getLastLocalChange() {
+ const ret = wasm.automerge_getLastLocalChange(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ */
+ dump() {
+ wasm.automerge_dump(this.ptr);
+ }
+ /**
+ * @param {Array | undefined} heads
+ * @returns {Array}
+ */
+ getMissingDeps(heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_getMissingDeps(retptr, this.ptr, isLikeNone(heads) ? 0 : addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {SyncState} state
+ * @param {Uint8Array} message
+ */
+ receiveSyncMessage(state, message) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ _assertClass(state, SyncState);
+ wasm.automerge_receiveSyncMessage(retptr, this.ptr, state.ptr, addHeapObject(message));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {SyncState} state
+ * @returns {any}
+ */
+ generateSyncMessage(state) {
+ _assertClass(state, SyncState);
+ const ret = wasm.automerge_generateSyncMessage(this.ptr, state.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @param {any} meta
+ * @returns {any}
+ */
+ toJS(meta) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_toJS(retptr, this.ptr, addHeapObject(meta));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} obj
+ * @param {Array | undefined} heads
+ * @param {any} meta
+ * @returns {any}
+ */
+ materialize(obj, heads, meta) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.automerge_materialize(retptr, this.ptr, addHeapObject(obj), isLikeNone(heads) ? 0 : addHeapObject(heads), addHeapObject(meta));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
+ if (r2) {
+ throw takeObject(r1);
+ }
+ return takeObject(r0);
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {string | undefined} message
+ * @param {number | undefined} time
+ * @returns {any}
+ */
+ emptyChange(message, time) {
+ var ptr0 = isLikeNone(message) ? 0 : passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ const ret = wasm.automerge_emptyChange(this.ptr, ptr0, len0, !isLikeNone(time), isLikeNone(time) ? 0 : time);
+ return takeObject(ret);
+ }
+}
+
+const SyncStateFinalization = new FinalizationRegistry(ptr => wasm.__wbg_syncstate_free(ptr));
+/**
+*/
+export class SyncState {
+
+ static __wrap(ptr) {
+ const obj = Object.create(SyncState.prototype);
+ obj.ptr = ptr;
+ SyncStateFinalization.register(obj, obj.ptr, obj);
+ return obj;
+ }
+
+ __destroy_into_raw() {
+ const ptr = this.ptr;
+ this.ptr = 0;
+ SyncStateFinalization.unregister(this);
+ return ptr;
+ }
+
+ free() {
+ const ptr = this.__destroy_into_raw();
+ wasm.__wbg_syncstate_free(ptr);
+ }
+ /**
+ * @returns {any}
+ */
+ get sharedHeads() {
+ const ret = wasm.syncstate_sharedHeads(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @returns {any}
+ */
+ get lastSentHeads() {
+ const ret = wasm.syncstate_lastSentHeads(this.ptr);
+ return takeObject(ret);
+ }
+ /**
+ * @param {any} heads
+ */
+ set lastSentHeads(heads) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.syncstate_set_lastSentHeads(retptr, this.ptr, addHeapObject(heads));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @param {any} hashes
+ */
+ set sentHashes(hashes) {
+ try {
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
+ wasm.syncstate_set_sentHashes(retptr, this.ptr, addHeapObject(hashes));
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
+ if (r1) {
+ throw takeObject(r0);
+ }
+ } finally {
+ wasm.__wbindgen_add_to_stack_pointer(16);
+ }
+ }
+ /**
+ * @returns {SyncState}
+ */
+ clone() {
+ const ret = wasm.syncstate_clone(this.ptr);
+ return SyncState.__wrap(ret);
+ }
+}
+
+const imports = {
+ __wbindgen_placeholder__: {
+ __wbindgen_string_new: function(arg0, arg1) {
+ const ret = getStringFromWasm0(arg0, arg1);
+ return addHeapObject(ret);
+ },
+ __wbindgen_object_drop_ref: function(arg0) {
+ takeObject(arg0);
+ },
+ __wbindgen_object_clone_ref: function(arg0) {
+ const ret = getObject(arg0);
+ return addHeapObject(ret);
+ },
+ __wbindgen_is_undefined: function(arg0) {
+ const ret = getObject(arg0) === undefined;
+ return ret;
+ },
+ __wbindgen_string_get: function(arg0, arg1) {
+ const obj = getObject(arg1);
+ const ret = typeof(obj) === 'string' ? obj : undefined;
+ var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ var len0 = WASM_VECTOR_LEN;
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+ },
+ __wbindgen_number_new: function(arg0) {
+ const ret = arg0;
+ return addHeapObject(ret);
+ },
+ __wbindgen_is_function: function(arg0) {
+ const ret = typeof(getObject(arg0)) === 'function';
+ return ret;
+ },
+ __wbindgen_number_get: function(arg0, arg1) {
+ const obj = getObject(arg1);
+ const ret = typeof(obj) === 'number' ? obj : undefined;
+ getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
+ },
+ __wbindgen_is_string: function(arg0) {
+ const ret = typeof(getObject(arg0)) === 'string';
+ return ret;
+ },
+ __wbindgen_is_null: function(arg0) {
+ const ret = getObject(arg0) === null;
+ return ret;
+ },
+ __wbindgen_boolean_get: function(arg0) {
+ const v = getObject(arg0);
+ const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
+ return ret;
+ },
+ __wbindgen_json_serialize: function(arg0, arg1) {
+ const obj = getObject(arg1);
+ const ret = JSON.stringify(obj === undefined ? null : obj);
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ const len0 = WASM_VECTOR_LEN;
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+ },
+ __wbindgen_error_new: function(arg0, arg1) {
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_new_abda76e883ba8a5f: function() {
+ const ret = new Error();
+ return addHeapObject(ret);
+ },
+ __wbg_stack_658279fe44541cf6: function(arg0, arg1) {
+ const ret = getObject(arg1).stack;
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ const len0 = WASM_VECTOR_LEN;
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+ },
+ __wbg_error_f851667af71bcfc6: function(arg0, arg1) {
+ try {
+ console.error(getStringFromWasm0(arg0, arg1));
+ } finally {
+ wasm.__wbindgen_free(arg0, arg1);
+ }
+ },
+ __wbindgen_bigint_from_i64: function(arg0) {
+ const ret = arg0;
+ return addHeapObject(ret);
+ },
+ __wbindgen_bigint_from_u64: function(arg0) {
+ const ret = BigInt.asUintN(64, arg0);
+ return addHeapObject(ret);
+ },
+ __wbindgen_is_object: function(arg0) {
+ const val = getObject(arg0);
+ const ret = typeof(val) === 'object' && val !== null;
+ return ret;
+ },
+ __wbindgen_jsval_loose_eq: function(arg0, arg1) {
+ const ret = getObject(arg0) == getObject(arg1);
+ return ret;
+ },
+ __wbg_String_91fba7ded13ba54c: function(arg0, arg1) {
+ const ret = String(getObject(arg1));
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ const len0 = WASM_VECTOR_LEN;
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+ },
+ __wbg_set_20cbc34131e76824: function(arg0, arg1, arg2) {
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
+ },
+ __wbg_crypto_e1d53a1d73fb10b8: function(arg0) {
+ const ret = getObject(arg0).crypto;
+ return addHeapObject(ret);
+ },
+ __wbg_process_038c26bf42b093f8: function(arg0) {
+ const ret = getObject(arg0).process;
+ return addHeapObject(ret);
+ },
+ __wbg_versions_ab37218d2f0b24a8: function(arg0) {
+ const ret = getObject(arg0).versions;
+ return addHeapObject(ret);
+ },
+ __wbg_node_080f4b19d15bc1fe: function(arg0) {
+ const ret = getObject(arg0).node;
+ return addHeapObject(ret);
+ },
+ __wbg_msCrypto_6e7d3e1f92610cbb: function(arg0) {
+ const ret = getObject(arg0).msCrypto;
+ return addHeapObject(ret);
+ },
+ __wbg_require_78a3dcfbdba9cbce: function() { return handleError(function () {
+ const ret = module.require;
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_getRandomValues_805f1c3d65988a5a: function() { return handleError(function (arg0, arg1) {
+ getObject(arg0).getRandomValues(getObject(arg1));
+ }, arguments) },
+ __wbg_randomFillSync_6894564c2c334c42: function() { return handleError(function (arg0, arg1, arg2) {
+ getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
+ }, arguments) },
+ __wbg_log_4b5638ad60bdc54a: function(arg0) {
+ console.log(getObject(arg0));
+ },
+ __wbg_log_89ca282a8a49b121: function(arg0, arg1) {
+ console.log(getObject(arg0), getObject(arg1));
+ },
+ __wbg_get_57245cc7d7c7619d: function(arg0, arg1) {
+ const ret = getObject(arg0)[arg1 >>> 0];
+ return addHeapObject(ret);
+ },
+ __wbg_length_6e3bbe7c8bd4dbd8: function(arg0) {
+ const ret = getObject(arg0).length;
+ return ret;
+ },
+ __wbg_new_1d9a920c6bfc44a8: function() {
+ const ret = new Array();
+ return addHeapObject(ret);
+ },
+ __wbg_newnoargs_b5b063fc6c2f0376: function(arg0, arg1) {
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_next_579e583d33566a86: function(arg0) {
+ const ret = getObject(arg0).next;
+ return addHeapObject(ret);
+ },
+ __wbg_next_aaef7c8aa5e212ac: function() { return handleError(function (arg0) {
+ const ret = getObject(arg0).next();
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_done_1b73b0672e15f234: function(arg0) {
+ const ret = getObject(arg0).done;
+ return ret;
+ },
+ __wbg_value_1ccc36bc03462d71: function(arg0) {
+ const ret = getObject(arg0).value;
+ return addHeapObject(ret);
+ },
+ __wbg_iterator_6f9d4f28845f426c: function() {
+ const ret = Symbol.iterator;
+ return addHeapObject(ret);
+ },
+ __wbg_get_765201544a2b6869: function() { return handleError(function (arg0, arg1) {
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_call_97ae9d8645dc388b: function() { return handleError(function (arg0, arg1) {
+ const ret = getObject(arg0).call(getObject(arg1));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_new_0b9bfdd97583284e: function() {
+ const ret = new Object();
+ return addHeapObject(ret);
+ },
+ __wbg_length_f2ab5db52e68a619: function(arg0) {
+ const ret = getObject(arg0).length;
+ return ret;
+ },
+ __wbg_self_6d479506f72c6a71: function() { return handleError(function () {
+ const ret = self.self;
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_window_f2557cc78490aceb: function() { return handleError(function () {
+ const ret = window.window;
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_globalThis_7f206bda628d5286: function() { return handleError(function () {
+ const ret = globalThis.globalThis;
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_global_ba75c50d1cf384f4: function() { return handleError(function () {
+ const ret = global.global;
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_set_a68214f35c417fa9: function(arg0, arg1, arg2) {
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
+ },
+ __wbg_from_7ce3cb27cb258569: function(arg0) {
+ const ret = Array.from(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_isArray_27c46c67f498e15d: function(arg0) {
+ const ret = Array.isArray(getObject(arg0));
+ return ret;
+ },
+ __wbg_push_740e4b286702d964: function(arg0, arg1) {
+ const ret = getObject(arg0).push(getObject(arg1));
+ return ret;
+ },
+ __wbg_unshift_1bf718f5eb23ad8a: function(arg0, arg1) {
+ const ret = getObject(arg0).unshift(getObject(arg1));
+ return ret;
+ },
+ __wbg_instanceof_ArrayBuffer_e5e48f4762c5610b: function(arg0) {
+ let result;
+ try {
+ result = getObject(arg0) instanceof ArrayBuffer;
+ } catch {
+ result = false;
+ }
+ const ret = result;
+ return ret;
+ },
+ __wbg_new_8d2af00bc1e329ee: function(arg0, arg1) {
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_call_168da88779e35f61: function() { return handleError(function (arg0, arg1, arg2) {
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_call_e1f72c051cdab859: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_instanceof_Date_b979044f17219415: function(arg0) {
+ let result;
+ try {
+ result = getObject(arg0) instanceof Date;
+ } catch {
+ result = false;
+ }
+ const ret = result;
+ return ret;
+ },
+ __wbg_getTime_cb82adb2556ed13e: function(arg0) {
+ const ret = getObject(arg0).getTime();
+ return ret;
+ },
+ __wbg_new_c8631234f931e1c4: function(arg0) {
+ const ret = new Date(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_instanceof_Object_595a1007518cbea3: function(arg0) {
+ let result;
+ try {
+ result = getObject(arg0) instanceof Object;
+ } catch {
+ result = false;
+ }
+ const ret = result;
+ return ret;
+ },
+ __wbg_assign_e3deabdbb7f0913d: function(arg0, arg1) {
+ const ret = Object.assign(getObject(arg0), getObject(arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_defineProperty_e47dcaf04849e02c: function(arg0, arg1, arg2) {
+ const ret = Object.defineProperty(getObject(arg0), getObject(arg1), getObject(arg2));
+ return addHeapObject(ret);
+ },
+ __wbg_entries_65a76a413fc91037: function(arg0) {
+ const ret = Object.entries(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_freeze_863b0fb5229a1aa6: function(arg0) {
+ const ret = Object.freeze(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_keys_0702294afaeb6044: function(arg0) {
+ const ret = Object.keys(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_values_f72d246067c121fe: function(arg0) {
+ const ret = Object.values(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_concat_783dc3b16a989c3a: function(arg0, arg1) {
+ const ret = getObject(arg0).concat(getObject(arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_slice_283900b9d91a5de8: function(arg0, arg1, arg2) {
+ const ret = getObject(arg0).slice(arg1 >>> 0, arg2 >>> 0);
+ return addHeapObject(ret);
+ },
+ __wbg_for_5dcca67bf52b18ca: function(arg0, arg1) {
+ const ret = Symbol.for(getStringFromWasm0(arg0, arg1));
+ return addHeapObject(ret);
+ },
+ __wbg_toString_1f0448acb8520180: function(arg0) {
+ const ret = getObject(arg0).toString();
+ return addHeapObject(ret);
+ },
+ __wbg_buffer_3f3d764d4747d564: function(arg0) {
+ const ret = getObject(arg0).buffer;
+ return addHeapObject(ret);
+ },
+ __wbg_newwithbyteoffsetandlength_d9aa266703cb98be: function(arg0, arg1, arg2) {
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
+ return addHeapObject(ret);
+ },
+ __wbg_new_8c3f0052272a457a: function(arg0) {
+ const ret = new Uint8Array(getObject(arg0));
+ return addHeapObject(ret);
+ },
+ __wbg_set_83db9690f9353e79: function(arg0, arg1, arg2) {
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
+ },
+ __wbg_length_9e1ae1900cb0fbd5: function(arg0) {
+ const ret = getObject(arg0).length;
+ return ret;
+ },
+ __wbg_instanceof_Uint8Array_971eeda69eb75003: function(arg0) {
+ let result;
+ try {
+ result = getObject(arg0) instanceof Uint8Array;
+ } catch {
+ result = false;
+ }
+ const ret = result;
+ return ret;
+ },
+ __wbg_newwithlength_f5933855e4f48a19: function(arg0) {
+ const ret = new Uint8Array(arg0 >>> 0);
+ return addHeapObject(ret);
+ },
+ __wbg_subarray_58ad4efbb5bcb886: function(arg0, arg1, arg2) {
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
+ return addHeapObject(ret);
+ },
+ __wbg_apply_75f7334893eef4ad: function() { return handleError(function (arg0, arg1, arg2) {
+ const ret = Reflect.apply(getObject(arg0), getObject(arg1), getObject(arg2));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_deleteProperty_424563545efc9635: function() { return handleError(function (arg0, arg1) {
+ const ret = Reflect.deleteProperty(getObject(arg0), getObject(arg1));
+ return ret;
+ }, arguments) },
+ __wbg_ownKeys_bf24e1178641d9f0: function() { return handleError(function (arg0) {
+ const ret = Reflect.ownKeys(getObject(arg0));
+ return addHeapObject(ret);
+ }, arguments) },
+ __wbg_set_bf3f89b92d5a34bf: function() { return handleError(function (arg0, arg1, arg2) {
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
+ return ret;
+ }, arguments) },
+ __wbindgen_debug_string: function(arg0, arg1) {
+ const ret = debugString(getObject(arg1));
+ const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
+ const len0 = WASM_VECTOR_LEN;
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
+ },
+ __wbindgen_throw: function(arg0, arg1) {
+ throw new Error(getStringFromWasm0(arg0, arg1));
+ },
+ __wbindgen_memory: function() {
+ const ret = wasm.memory;
+ return addHeapObject(ret);
+ },
+ },
+
+};
+
+const wasm_url = new URL('automerge_wasm_bg.wasm', import.meta.url);
+let wasmCode = '';
+switch (wasm_url.protocol) {
+ case 'file:':
+ wasmCode = await Deno.readFile(wasm_url);
+ break
+ case 'https:':
+ case 'http:':
+ wasmCode = await (await fetch(wasm_url)).arrayBuffer();
+ break
+ default:
+ throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);
+}
+
+const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance;
+const wasm = wasmInstance.exports;
+
diff --git a/deno_wasm_dist/automerge_wasm_bg.wasm b/deno_wasm_dist/automerge_wasm_bg.wasm
new file mode 100644
index 00000000..94444630
Binary files /dev/null and b/deno_wasm_dist/automerge_wasm_bg.wasm differ
diff --git a/deno_wasm_dist/index.d.ts b/deno_wasm_dist/index.d.ts
new file mode 100644
index 00000000..29586b47
--- /dev/null
+++ b/deno_wasm_dist/index.d.ts
@@ -0,0 +1,232 @@
+export type Actor = string;
+export type ObjID = string;
+export type Change = Uint8Array;
+export type SyncMessage = Uint8Array;
+export type Prop = string | number;
+export type Hash = string;
+export type Heads = Hash[];
+export type Value = string | number | boolean | null | Date | Uint8Array
+export type MaterializeValue = { [key:string]: MaterializeValue } | Array | Value
+export type ObjType = string | Array | { [key: string]: ObjType | Value }
+export type FullValue =
+ ["str", string] |
+ ["int", number] |
+ ["uint", number] |
+ ["f64", number] |
+ ["boolean", boolean] |
+ ["timestamp", Date] |
+ ["counter", number] |
+ ["bytes", Uint8Array] |
+ ["null", null] |
+ ["map", ObjID] |
+ ["list", ObjID] |
+ ["text", ObjID] |
+ ["table", ObjID]
+
+export type FullValueWithId =
+ ["str", string, ObjID ] |
+ ["int", number, ObjID ] |
+ ["uint", number, ObjID ] |
+ ["f64", number, ObjID ] |
+ ["boolean", boolean, ObjID ] |
+ ["timestamp", Date, ObjID ] |
+ ["counter", number, ObjID ] |
+ ["bytes", Uint8Array, ObjID ] |
+ ["null", null, ObjID ] |
+ ["map", ObjID ] |
+ ["list", ObjID] |
+ ["text", ObjID] |
+ ["table", ObjID]
+
+export enum ObjTypeName {
+ list = "list",
+ map = "map",
+ table = "table",
+ text = "text",
+}
+
+export type Datatype =
+ "boolean" |
+ "str" |
+ "int" |
+ "uint" |
+ "f64" |
+ "null" |
+ "timestamp" |
+ "counter" |
+ "bytes" |
+ "map" |
+ "text" |
+ "list";
+
+export type SyncHave = {
+ lastSync: Heads,
+ bloom: Uint8Array,
+}
+
+export type DecodedSyncMessage = {
+ heads: Heads,
+ need: Heads,
+ have: SyncHave[]
+ changes: Change[]
+}
+
+export type DecodedChange = {
+ actor: Actor,
+ seq: number
+ startOp: number,
+ time: number,
+ message: string | null,
+ deps: Heads,
+ hash: Hash,
+ ops: Op[]
+}
+
+type PartialBy = Omit & Partial>
+export type ChangeToEncode = PartialBy
+
+export type Op = {
+ action: string,
+ obj: ObjID,
+ key: string,
+ value?: string | number | boolean,
+ datatype?: string,
+ pred: string[],
+}
+
+export type Patch = PutPatch | DelPatch | SplicePatch | IncPatch;
+
+export type PutPatch = {
+ action: 'put'
+ path: Prop[],
+ value: Value
+ conflict: boolean
+}
+
+export type IncPatch = {
+ action: 'inc'
+ path: Prop[],
+ value: number
+}
+
+export type DelPatch = {
+ action: 'del'
+ path: Prop[],
+ length?: number,
+}
+
+export type SplicePatch = {
+ action: 'splice'
+ path: Prop[],
+ values: Value[],
+}
+
+export function encodeChange(change: ChangeToEncode): Change;
+export function create(text_v2: boolean, actor?: Actor): Automerge;
+export function load(data: Uint8Array, text_v2: boolean, actor?: Actor): Automerge;
+export function decodeChange(change: Change): DecodedChange;
+export function initSyncState(): SyncState;
+export function encodeSyncMessage(message: DecodedSyncMessage): SyncMessage;
+export function decodeSyncMessage(msg: SyncMessage): DecodedSyncMessage;
+export function encodeSyncState(state: SyncState): Uint8Array;
+export function decodeSyncState(data: Uint8Array): SyncState;
+export function exportSyncState(state: SyncState): JsSyncState;
+export function importSyncState(state: JsSyncState): SyncState;
+
+export interface API {
+ create(text_v2: boolean, actor?: Actor): Automerge;
+ load(data: Uint8Array, text_v2: boolean, actor?: Actor): Automerge;
+ encodeChange(change: ChangeToEncode): Change;
+ decodeChange(change: Change): DecodedChange;
+ initSyncState(): SyncState;
+ encodeSyncMessage(message: DecodedSyncMessage): SyncMessage;
+ decodeSyncMessage(msg: SyncMessage): DecodedSyncMessage;
+ encodeSyncState(state: SyncState): Uint8Array;
+ decodeSyncState(data: Uint8Array): SyncState;
+ exportSyncState(state: SyncState): JsSyncState;
+ importSyncState(state: JsSyncState): SyncState;
+}
+
+export class Automerge {
+ // change state
+ put(obj: ObjID, prop: Prop, value: Value, datatype?: Datatype): void;
+ putObject(obj: ObjID, prop: Prop, value: ObjType): ObjID;
+ insert(obj: ObjID, index: number, value: Value, datatype?: Datatype): void;
+ insertObject(obj: ObjID, index: number, value: ObjType): ObjID;
+ push(obj: ObjID, value: Value, datatype?: Datatype): void;
+ pushObject(obj: ObjID, value: ObjType): ObjID;
+ splice(obj: ObjID, start: number, delete_count: number, text?: string | Array): ObjID[] | undefined;
+ increment(obj: ObjID, prop: Prop, value: number): void;
+ delete(obj: ObjID, prop: Prop): void;
+
+ // returns a single value - if there is a conflict return the winner
+ get(obj: ObjID, prop: Prop, heads?: Heads): Value | undefined;
+ getWithType(obj: ObjID, prop: Prop, heads?: Heads): FullValue | null;
+ // return all values in case of a conflict
+ getAll(obj: ObjID, arg: Prop, heads?: Heads): FullValueWithId[];
+ keys(obj: ObjID, heads?: Heads): string[];
+ text(obj: ObjID, heads?: Heads): string;
+ length(obj: ObjID, heads?: Heads): number;
+ materialize(obj?: ObjID, heads?: Heads, metadata?: unknown): MaterializeValue;
+ toJS(): MaterializeValue;
+
+ // transactions
+ commit(message?: string, time?: number): Hash | null;
+ emptyChange(message?: string, time?: number): Hash;
+ merge(other: Automerge): Heads;
+ getActorId(): Actor;
+ pendingOps(): number;
+ rollback(): number;
+
+ // patches
+ enablePatches(enable: boolean): boolean;
+ enableFreeze(enable: boolean): boolean;
+ registerDatatype(datatype: string, callback: Function): void;
+ popPatches(): Patch[];
+
+ // save and load to local store
+ save(): Uint8Array;
+ saveIncremental(): Uint8Array;
+ loadIncremental(data: Uint8Array): number;
+
+ // sync over network
+ receiveSyncMessage(state: SyncState, message: SyncMessage): void;
+ generateSyncMessage(state: SyncState): SyncMessage | null;
+
+ // low level change functions
+ applyChanges(changes: Change[]): void;
+ getChanges(have_deps: Heads): Change[];
+ getChangeByHash(hash: Hash): Change | null;
+ getChangesAdded(other: Automerge): Change[];
+ getHeads(): Heads;
+ getLastLocalChange(): Change | null;
+ getMissingDeps(heads?: Heads): Heads;
+
+ // memory management
+ free(): void; // only needed if weak-refs are unsupported
+ clone(actor?: string): Automerge; // TODO - remove, this is dangerous
+ fork(actor?: string, heads?: Heads): Automerge;
+
+ // dump internal state to console.log - for debugging
+ dump(): void;
+
+ // experimental api can go here
+ applyPatches(obj: Doc, meta?: unknown, callback?: (patch: Array, before: Doc, after: Doc) => void): Doc;
+}
+
+export interface JsSyncState {
+ sharedHeads: Heads;
+ lastSentHeads: Heads;
+ theirHeads: Heads | undefined;
+ theirHeed: Heads | undefined;
+ theirHave: SyncHave[] | undefined;
+ sentHashes: Heads;
+}
+
+export class SyncState {
+ free(): void;
+ clone(): SyncState;
+ lastSentHeads: Heads;
+ sentHashes: Heads;
+ readonly sharedHeads: Heads;
+}