210e9648bf
For the path to be accurate it needs to be calculated at the moment of op insert not at commit. This is because the path may contain list indexes in parent objects that could change by inserts and deletes later in the transaction. The primary change was adding op_observer to the transaction object and removing it from commit options. The beginnings of a wasm level `applyPatch` system is laid out here. |
||
---|---|---|
.. | ||
cmake | ||
examples | ||
img | ||
src | ||
test | ||
.gitignore | ||
build.rs | ||
Cargo.toml | ||
cbindgen.toml | ||
CMakeLists.txt | ||
README.md |
Methods we need to support
Basic management
AMcreate()
AMclone(doc)
AMfree(doc)
AMconfig(doc, key, val)
// set actoractor = get_actor(doc)
Transactions
AMpendingOps(doc)
AMcommit(doc, message, time)
AMrollback(doc)
Write
AMset{Map|List}(doc, obj, prop, value)
AMinsert(doc, obj, index, value)
AMpush(doc, obj, value)
AMdel{Map|List}(doc, obj, prop)
AMinc{Map|List}(doc, obj, prop, value)
AMspliceText(doc, obj, start, num_del, text)
Read (the heads argument is optional and can be on an at
variant)
AMkeys(doc, obj, heads)
AMlength(doc, obj, heads)
AMlistRange(doc, obj, heads)
AMmapRange(doc, obj, heads)
AMvalues(doc, obj, heads)
AMtext(doc, obj, heads)
Sync
AMgenerateSyncMessage(doc, state)
AMreceiveSyncMessage(doc, state, message)
AMinitSyncState()
Save / Load
AMload(data)
AMloadIncremental(doc, data)
AMsave(doc)
AMsaveIncremental(doc)
Low Level Access
AMapplyChanges(doc, changes)
AMgetChanges(doc, deps)
AMgetChangesAdded(doc1, doc2)
AMgetHeads(doc)
AMgetLastLocalChange(doc)
AMgetMissingDeps(doc, heads)
Encode/Decode
AMencodeChange(change)
AMdecodeChange(change)
AMencodeSyncMessage(change)
AMdecodeSyncMessage(change)
AMencodeSyncState(change)
AMdecodeSyncState(change)
Open Question - Memory management
Most of these calls return one or more items of arbitrary length. Doing memory management in C is tricky. This is my proposed solution...
// returns 1 or zero opids
n = automerge_set(doc, "_root", "hello", datatype, value);
if (n) {
automerge_pop(doc, &obj, len);
}
// returns n values
n = automerge_values(doc, "_root", "hello");
for (i = 0; i<n ;i ++) {
automerge_pop_value(doc, &value, &datatype, len);
}
There would be one pop method per object type. Users allocs and frees the buffers. Multiple return values would result in multiple pops. Too small buffers would error and allow retry.
Formats
Actors - We could do (bytes,len) or a hex encoded string?.
ObjIds - We could do flat bytes of the ExId struct but lets do human readable strings for now - the struct would be faster but opque
Heads - Might as well make it a flat buffer (n, hash, hash, ...)
Changes - Put them all in a flat concatenated buffer
Encode/Decode - to json strings?