Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
let docOld = undefined;
const isUpdate = map[id + ''] && map[id + ''].merge;
if (isUpdate) {
docOld = Automerge.load(map[id + ''].merge);
updated.push(id);
} else {
docOld = Automerge.init();
}
const docInt =
typeof changes === 'string' ? Automerge.load(changes) : undefined;
const docNew = docInt
? Automerge.merge(docOld, docInt)
: Automerge.applyChanges(docOld, changes);
if (Object.keys(Automerge.getMissingDeps(docNew)).length) {
unsuccessful.push(id);
return;
}
/* if (!history.length) {
return {
...snapshot,
actor: undefined,
id,
merge: Automerge.save(docNew)
};
}*/
const history = Automerge.getHistory(docNew);
const { change, snapshot } = history[history.length - 1];
return {
...snapshot,
_loadMissingBlocks (hex) {
const docId = this.hexToId(hex)
if (docId !== hex) return
const deps = Automerge.getMissingDeps(this.find(docId))
return Promise.all(Object.keys(deps).map(actor => {
const last = deps[actor] + 1 // last is exclusive
return this._loadBlocks(docId, actor, last)
}))
}
_loadMissingDependencyBlocks(docId) {
log('_loadMissingDependencyBlocks', docId)
const doc = this.find(docId)
const deps = Automerge.getMissingDeps(doc)
return Promise.all(Object.keys(deps).map((actorId) => {
const last = deps[actorId] + 1 // last is exclusive
return this._loadBlocksWithDependencies(docId, actorId, last)
}))
}
_loadMissingBlocks (actorId) {
const docId = this.actorToId(actorId)
if (docId !== actorId) return
const deps = Automerge.getMissingDeps(this.find(docId))
return Promise.all(Object.keys(deps).map(actor => {
const last = deps[actor] + 1 // last is exclusive
return this._loadBlocks(docId, actor, last)
}))
}
isMissingDeps (docId) {
const deps = Automerge.getMissingDeps(this.find(docId))
return !!Object.keys(deps).length
}
isMissingDeps (docId) {
const deps = Automerge.getMissingDeps(this.find(docId))
return !!Object.keys(deps).length
}