automerge/automerge-c
Orion Henry 7a6dfcc289
The patch interface needs an accurate path per patch op
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.
2022-10-06 22:41:37 +01:00
..
cmake Replace _INCLUDED with _H as the suffix for 2022-07-25 01:04:35 -07:00
examples Add AMchangesInit() for @rkuhn in #411. 2022-08-23 05:34:45 -07:00
img Squashed commit of the following: 2022-04-19 08:35:44 -06:00
src The patch interface needs an accurate path per patch op 2022-10-06 22:41:37 +01:00
test Add AMchangesInit() for @rkuhn in #411. 2022-08-23 05:34:45 -07:00
.gitignore Squashed commit of the following: 2022-04-19 08:35:44 -06:00
build.rs Normalize the header include statement for all C 2022-08-22 22:28:23 -07:00
Cargo.toml Remove storage-v2 feature flag 2022-08-22 21:21:21 +01:00
cbindgen.toml Expose automerge::AutoCommit::get_change_by_hash() 2022-08-06 15:04:46 -07:00
CMakeLists.txt Normalize the header include statement for all C 2022-08-22 22:28:23 -07:00
README.md update list of read methods in c readme 2022-06-14 21:28:10 -04:00

Methods we need to support

Basic management

  1. AMcreate()
  2. AMclone(doc)
  3. AMfree(doc)
  4. AMconfig(doc, key, val) // set actor
  5. actor = get_actor(doc)

Transactions

  1. AMpendingOps(doc)
  2. AMcommit(doc, message, time)
  3. AMrollback(doc)

Write

  1. AMset{Map|List}(doc, obj, prop, value)
  2. AMinsert(doc, obj, index, value)
  3. AMpush(doc, obj, value)
  4. AMdel{Map|List}(doc, obj, prop)
  5. AMinc{Map|List}(doc, obj, prop, value)
  6. AMspliceText(doc, obj, start, num_del, text)

Read (the heads argument is optional and can be on an at variant)

  1. AMkeys(doc, obj, heads)
  2. AMlength(doc, obj, heads)
  3. AMlistRange(doc, obj, heads)
  4. AMmapRange(doc, obj, heads)
  5. AMvalues(doc, obj, heads)
  6. AMtext(doc, obj, heads)

Sync

  1. AMgenerateSyncMessage(doc, state)
  2. AMreceiveSyncMessage(doc, state, message)
  3. AMinitSyncState()

Save / Load

  1. AMload(data)
  2. AMloadIncremental(doc, data)
  3. AMsave(doc)
  4. AMsaveIncremental(doc)

Low Level Access

  1. AMapplyChanges(doc, changes)
  2. AMgetChanges(doc, deps)
  3. AMgetChangesAdded(doc1, doc2)
  4. AMgetHeads(doc)
  5. AMgetLastLocalChange(doc)
  6. AMgetMissingDeps(doc, heads)

Encode/Decode

  1. AMencodeChange(change)
  2. AMdecodeChange(change)
  3. AMencodeSyncMessage(change)
  4. AMdecodeSyncMessage(change)
  5. AMencodeSyncState(change)
  6. 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?