Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fixtures(__dirname, 'operations', ({ module }) => {
const { input, output } = module
const operations = module.default
const inputSyncDoc = toSyncDocument(input.document.toJSON())
const initAutomergeDoc = Automerge.init();
const emptyAutomergeDoc = Automerge.change(initAutomergeDoc, automergeDoc => {
automergeDoc.doc = inputSyncDoc;
});
const changedAutomergeDoc = Automerge.change(emptyAutomergeDoc, automergeDoc => {
operations.forEach(op => applyOperation(automergeDoc.doc, op));
})
// check our rep matched
const expectedDoc = output.document.toJSON();
const actualDoc = toSlateDocument(changedAutomergeDoc.doc);
assert.deepEqual(actualDoc, expectedDoc);
})
)
const { transformer, loadedDoc } = setup(input);
// insert text into the second nested paragraph
const op = {
type: "insert_text",
path: [0, 1, 0],
offset: 5,
text: 'h',
}
// load the cache
// transformer.apply(loadedDoc.doc);
const changedDoc = Automerge.change(loadedDoc, doc => applyOperation(doc.doc, op))
const changes = Automerge.getChanges(loadedDoc, changedDoc);
const transformed = transformer.apply(changedDoc.doc, changes);
expect(transformed.toJSON()).toEqual(output.toJSON());
})
export const applySlateOperations = (docSet, docId, slateOperations, clientId) => {
const currentDoc = docSet.getDoc(docId)
if (currentDoc) {
const message = clientId ? `Client ${clientId}` : "Change log"
const docNew = Automerge.change(currentDoc, message, doc => {
// Use the Slate operations to modify the Automerge document.
applySlateOperationsHelper(doc, slateOperations)
})
docSet.setDoc(docId, docNew)
}
}
it('2. Alice makes an edit', () => {
alice2 = Automerge.change(alice1, doc => { doc.x0y0 = 'r' })
assert.deepEqual(alice2, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'r',
x0y1: 'w',
x1y0: 'w',
x1y1: 'w'
})
bob2 = bob1
})
it('5. Both Alice and Bob make edits while offline', () => {
alice5 = Automerge.change(alice4, doc => {
doc.x1y0 = 'g'
doc.x1y1 = 'r'
})
bob5 = Automerge.change(bob4, doc => {
doc.x1y0 = 'g'
doc.x1y1 = 'w'
})
assert.deepEqual(alice5, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'r',
x0y1: 'w',
x1y0: 'g',
x1y1: 'r'
})
assert.deepEqual(bob5, {
_objectId: '00000000-0000-0000-0000-000000000000',
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
.then((fileContents) => {
if(fileContents){
console.log('file loaded number ' + count);
let object = Automerge.init();
object = Automerge.change(object, file => {
file.team = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).team;
file.integrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).integrations;
file.lastUpdated = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).lastUpdated;
file.accountSettings = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).accountSettings;
file.editorView = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorView;
file.editorName = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorName;
file.editorPermissions = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPermissions;
file.editorIntegrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorIntegrations;
file.editorPublish = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPublish;
file.journoView = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoView;
file.journoName = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoName;
file.journoRoles = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoRoles;
file.journoPermissions = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoPermissions;
file.journoIntegrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoIntegrations;
});
this.setState({file2: object});
updateDoc,
})
codeMirror.on('change', codeMirrorHandler)
docSet.registerHandler((updatedDocId, updatedDoc) => {
if (updatedDocId === docId) {
automergeHandler(updatedDoc)
}
})
}
createCodeMirror(rightDocSet, 'right')
createCodeMirror(leftDocSet, 'left')
rightDocSet.setDoc(
docId,
Automerge.change(Automerge.init(), doc => (doc.text = new Automerge.Text()))
)
function createSheet() {
watchableDoc.set(
change(doc, draft => {
if (draft.sheets == undefined) draft.sheets = []
draft.sheets.push(new Text())
})
)
}
function updateData(
state: DemoboardProjectState,
callback: (value: Proxy) => void,
): DemoboardProjectState {
let commitMessage = Date.now()
return {
...state,
data: change(state.data, String(commitMessage), callback),
}
}