diff --git a/src/crdt/index.js b/src/crdt/index.js index fa4e28de..ec028dff 100644 --- a/src/crdt/index.js +++ b/src/crdt/index.js @@ -128,7 +128,25 @@ export const put = async (blocks, head, key, value) => { * @returns {Promise} */ export const del = async (blocks, head, key, options) => { - throw new Error('not implemented') + const mblocks = new MemoryBlockstore() + blocks = new MultiBlockFetcher(mblocks, blocks) + + if (!head.length) { + const shard = await ShardBlock.create() + mblocks.putSync(shard.cid, shard.bytes) + const result = await Pail.put(blocks, shard.cid, key, value) + /** @type {API.Operation} */ + const data = { type: 'put', root: result.root, key, value } + const event = await EventBlock.create(data, head) + head = await Clock.advance(blocks, head, event.cid) + return { + root: result.root, + additions: [shard, ...result.additions], + removals: result.removals, + head, + event + } + } } /**