Example #1
0
  self.get(key, function(err, original) {
    if(err) {
      return callback(err);
    }

    var newValue;

    try {
      var originalObject = JSON.parse(original);
      newValue = jsondiffpatch.unpatch(originalObject, diff);
    } catch(e) {
      newValue = jsondiffpatch.unpatch(original, diff);
    }

    var action = 'put';
    if(!newValue) {
      action = 'del';
    }

    var operation = {
      type: action,
      key: [self.dataPrefix, key].join('-'),
      value: newValue
    };

    callback(null, operation);
  });
Example #2
0
export function patchModFile(opts = {}) {
  if(!opts.delta) {
    return Promise.reject("No delta object to restore from");
  } else if(!files[opts.filetype]) {
    return Promise.reject(`Filetype: ${opts.filetype} invalid`);
  }
  return Promise.resolve(unpatch(files[opts.filetype], opts.delta));
}