'use strict';

var async = require('async');
var Anyfetch = require('anyfetch');

/**
 * HYDRATING FUNCTION
 *
 * @param {string} path Path of the specified file
 * @param {string} original document
 * @param {object} changes object provided by anyFetch's API. Update this object to send document's modification to anyFetch's API.
 * @param {function} cb Callback, first parameter is the error if any, then the processed data
 */
module.exports = function(path, document, changes, cb) {
  var anyfetch = new Anyfetch(document.access_token);
  anyfetch.setApiUrl(cb.apiUrl);

  async.waterfall([
    function(cb) {
      cb();
    },
  ], function(err) {
    cb(err, changes);
  });
};

@@ -38,16 +38,48 @@
 sync');%0A
+var crypto = require('crypto');%0A
 var Anyf
@@ -106,16 +106,16 @@
 etch');%0A
-
 %0A/**%0A * 
@@ -636,33 +636,566 @@
 tion
-(cb) %7B%0A      cb();%0A    %7D,
+ generateHash(cb) %7B%0A      var shasum = crypto.createHash('sha1');%0A      shasum.update(JSON.stringify(document.metadata));%0A      cb(null, shasum.digest('hex'));%0A    %7D,%0A    function getDocumentsWithSameHash(hash, cb) %7B%0A      changes.hash = hash;%0A%0A      anyfetch.getDocuments(%7Bhash: hash%7D, cb);%0A    %7D,%0A    function deleteOldDocuments(res, cb) %7B%0A      var documents = res.body.data;%0A%0A      async.each(documents, function(document, cb) %7B%0A        console.log(%22DELETE%22, document.identifier);%0A        anyfetch.deleteDocumentById(document.id, cb);%0A      %7D, cb);%0A    %7D
 %0A  %5D

Delete documents with same hash and update hash