Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-json-patch

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-json-patch - npm Package Compare versions

Comparing version 0.5.7 to 1.0.0

CONTRIBUTING.md

4

dist/json-patch-duplex.min.js
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester
* MIT license
*/
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},OriginalError=Error,jsonpatch;!function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(y(a)){if(!y(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=r(c),g=f.length;if(r(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function d(a){for(var b=0,c=v.length;c>b;b++)if(v[b].obj===a)return v[b]}function e(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function f(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function g(a,b){b.unobserve()}function h(a){return"object"==typeof a?JSON.parse(JSON.stringify(a)):a}function i(a,b){var c,g=[],i=d(a);if(i?c=e(i,b):(i=new w(a),v.push(i)),c)return c;if(c={},i.value=h(a),b){c.callback=b,c.next=null;var k=this.intervals||[100,1e3,1e4,6e4];if(void 0===k.push)throw new OriginalError("jsonpatch.intervals must be an array");var l=0,m=function(){j(c)},n=function(){clearTimeout(c.next),c.next=setTimeout(function(){m(),l=0,c.next=setTimeout(o,k[l++])},0)},o=function(){m(),l==k.length&&(l=k.length-1),c.next=setTimeout(o,k[l++])};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mousedown",n),window.addEventListener("mouseup",n),window.addEventListener("keydown",n)):(document.documentElement.attachEvent("onmousedown",n),document.documentElement.attachEvent("onmouseup",n),document.documentElement.attachEvent("onkeydown",n))),c.next=setTimeout(o,k[l++])}return c.patches=g,c.object=a,c.unobserve=function(){j(c),clearTimeout(c.next),f(i,c),"undefined"!=typeof window&&(window.removeEventListener?(window.removeEventListener("mousedown",n),window.removeEventListener("mouseup",n),window.removeEventListener("keydown",n)):(document.documentElement.detachEvent("onmousedown",n),document.documentElement.detachEvent("onmouseup",n),document.documentElement.detachEvent("onkeydown",n)))},i.observers.push(new x(b,c)),c}function j(a){for(var b,c=0,d=v.length;d>c;c++)if(v[c].obj===a.object){b=v[c];break}k(b.value,a.object,a.patches,""),a.patches.length&&m(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function k(a,b,d,e){for(var f=r(b),g=r(a),i=!1,j=!1,l=g.length-1;l>=0;l--){var m=g[l],n=a[m];if(b.hasOwnProperty(m)){var o=b[m];"object"==typeof n&&null!=n&&"object"==typeof o&&null!=o?k(n,o,d,e+"/"+c(m)):n!=o&&(i=!0,d.push({op:"replace",path:e+"/"+c(m),value:h(o)}))}else d.push({op:"remove",path:e+"/"+c(m)}),j=!0}if(j||f.length!=g.length)for(var l=0;l<f.length;l++){var m=f[l];a.hasOwnProperty(m)||d.push({op:"add",path:e+"/"+c(m),value:h(b[m])})}}function l(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function m(a,b,c){for(var d,e,f=!1,g=0,h=b.length;h>g;){d=b[g],g++;for(var i=d.path||"",j=i.split("/"),k=a,m=1,n=j.length,o=void 0;;){if(e=j[m],c&&void 0===o&&(void 0===k[e]?o=j.slice(0,m).join("/"):m==n-1&&(o=d.path),void 0!==o&&this.validator(d,g-1,a,o)),m++,void 0===e&&m>=n){f=u[d.op].call(d,k,e,a);break}if(y(k)){if("-"===e)e=k.length;else{if(c&&!l(e))throw new z("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",g-1,d.path,d);e=parseInt(e,10)}if(m>=n){if(c&&"add"===d.op&&e>k.length)throw new z("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",g-1,d.path,d);f=t[d.op].call(d,k,e,a);break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),m>=n){f=s[d.op].call(d,k,e,a);break}k=k[e]}}return f}function n(a,b){var c=[];return k(a,b,c,""),c}function o(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(o(a[b]))return!0;return!1}function p(b,c,d,e){if("object"!=typeof b||null===b||y(b))throw new z("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!s[b.op])throw new z("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new z("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new z("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new z("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&o(b.value))throw new z("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,g=e.split("/").length;if(f!==g+1&&f!==g)throw new z("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new z("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var h={op:"_get",path:b.from,value:void 0},i=a.validate([h],d);if(i&&"OPERATION_PATH_UNRESOLVABLE"===i.name)throw new z("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function q(a,b){try{if(!y(a))throw new z("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),m.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(d){if(d instanceof z)return d;throw d}}var r=function(a){if(y(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},s={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var d={op:"_get",path:this.from};return m(c,[d]),m(c,[{op:"remove",path:this.from}]),m(c,[{op:"add",path:this.path,value:d.value}]),!0},copy:function(a,b,c){var d={op:"_get",path:this.from};return m(c,[d]),m(c,[{op:"add",path:this.path,value:d.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},t={add:function(a,b){return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},move:s.move,copy:s.copy,test:s.test,_get:s._get},u={add:function(a){u.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&s.remove.call(this,a,b);return!0},replace:function(a){return m(a,[{op:"remove",path:this.path}]),m(a,[{op:"add",path:this.path,value:this.value}]),!0},move:s.move,copy:s.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},v=[],w=function(){function a(a){this.observers=[],this.obj=a}return a}(),x=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=g,a.observe=i,a.generate=j;var y;y=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=m,a.compare=n;var z=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return __extends(b,a),b}(OriginalError);a.JsonPatchError=z,a.Error=z,a.validator=p,a.validate=q}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.observe=jsonpatch.observe,exports.unobserve=jsonpatch.unobserve,exports.generate=jsonpatch.generate,exports.compare=jsonpatch.compare,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},OriginalError=Error,jsonpatch;!function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(y(a)){if(!y(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=r(c),g=f.length;if(r(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){return-1===a.indexOf("/")&&-1===a.indexOf("~")?a:a.replace(/~/g,"~0").replace(/\//g,"~1")}function d(a){for(var b=0,c=v.length;c>b;b++)if(v[b].obj===a)return v[b]}function e(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function f(a,b){for(var c=0,d=a.observers.length;d>c;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function g(a,b){b.unobserve()}function h(a){switch(typeof a){case"object":return JSON.parse(JSON.stringify(a));case"undefined":return null;default:return a}}function i(a,b){var c,g=[],i=d(a);if(i?c=e(i,b):(i=new w(a),v.push(i)),c)return c;if(c={},i.value=h(a),b){c.callback=b,c.next=null;var k=function(){j(c)},l=function(){clearTimeout(c.next),c.next=setTimeout(k)};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mouseup",l),window.addEventListener("keyup",l)):(document.documentElement.attachEvent("onmouseup",l),document.documentElement.attachEvent("onkeyup",l)))}return c.patches=g,c.object=a,c.unobserve=function(){j(c),clearTimeout(c.next),f(i,c),"undefined"!=typeof window&&(window.removeEventListener?(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l)):(document.documentElement.detachEvent("onmouseup",l),document.documentElement.detachEvent("onkeyup",l)))},i.observers.push(new x(b,c)),c}function j(a){for(var b,c=0,d=v.length;d>c;c++)if(v[c].obj===a.object){b=v[c];break}k(b.value,a.object,a.patches,""),a.patches.length&&m(b.value,a.patches);var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function k(a,b,d,e){for(var f=r(b),g=r(a),i=!1,j=!1,l=g.length-1;l>=0;l--){var m=g[l],n=a[m];if(!b.hasOwnProperty(m)||void 0===b[m]&&y(b)===!1)d.push({op:"remove",path:e+"/"+c(m)}),j=!0;else{var o=b[m];"object"==typeof n&&null!=n&&"object"==typeof o&&null!=o?k(n,o,d,e+"/"+c(m)):n!=o&&(i=!0,d.push({op:"replace",path:e+"/"+c(m),value:h(o)}))}}if(j||f.length!=g.length)for(var l=0;l<f.length;l++){var m=f[l];a.hasOwnProperty(m)||void 0===b[m]||d.push({op:"add",path:e+"/"+c(m),value:h(b[m])})}}function l(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function m(a,b,c){for(var d,e,f=[],g=0,h=b.length;h>g;){d=b[g],g++;for(var i=d.path||"",j=i.split("/"),k=a,m=1,n=j.length,o=void 0;;){if(e=j[m],c&&void 0===o&&(void 0===k[e]?o=j.slice(0,m).join("/"):m==n-1&&(o=d.path),void 0!==o&&this.validator(d,g-1,a,o)),m++,void 0===e&&m>=n){f.push(u[d.op].call(d,k,e,a));break}if(y(k)){if("-"===e)e=k.length;else{if(c&&!l(e))throw new z("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",g-1,d.path,d);e=parseInt(e,10)}if(m>=n){if(c&&"add"===d.op&&e>k.length)throw new z("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",g-1,d.path,d);f.push(t[d.op].call(d,k,e,a));break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),m>=n){f.push(s[d.op].call(d,k,e,a));break}k=k[e]}}return f}function n(a,b){var c=[];return k(a,b,c,""),c}function o(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(o(a[b]))return!0;return!1}function p(b,c,d,e){if("object"!=typeof b||null===b||y(b))throw new z("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!s[b.op])throw new z("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new z("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new z("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new z("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&o(b.value))throw new z("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,g=e.split("/").length;if(f!==g+1&&f!==g)throw new z("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==e)throw new z("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var h={op:"_get",path:b.from,value:void 0},i=a.validate([h],d);if(i&&"OPERATION_PATH_UNRESOLVABLE"===i.name)throw new z("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function q(a,b){try{if(!y(a))throw new z("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),m.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(d){if(d instanceof z)return d;throw d}}var r=function(a){if(y(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},s={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var d={op:"_get",path:this.path};m(c,[d]);var e=void 0===d.value?void 0:JSON.parse(JSON.stringify(d.value)),f={op:"_get",path:this.from};return m(c,[f]),m(c,[{op:"remove",path:this.from}]),m(c,[{op:"add",path:this.path,value:f.value}]),e},copy:function(a,b,c){var d={op:"_get",path:this.from};m(c,[d]),m(c,[{op:"add",path:this.path,value:d.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},t={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:s.move,copy:s.copy,test:s.test,_get:s._get},u={add:function(a){u.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],s.remove.call(this,a,c));return b},replace:function(a){var b=m(a,[{op:"remove",path:this.path}]);return m(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:s.move,copy:s.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}},v=[],w=function(){function a(a){this.observers=[],this.obj=a}return a}(),x=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=g,a.observe=i,a.generate=j;var y;y=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=m,a.compare=n;var z=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return __extends(b,a),b}(OriginalError);a.JsonPatchError=z,a.Error=z,a.validator=p,a.validate=q}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.observe=jsonpatch.observe,exports.unobserve=jsonpatch.unobserve,exports.generate=jsonpatch.generate,exports.compare=jsonpatch.compare,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester
* MIT license
*/
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},OriginalError=Error,jsonpatch;!function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(h(a)){if(!h(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=i(c),g=f.length;if(i(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function d(a,b,d){for(var e,f,g=!1,i=0,n=b.length;n>i;){e=b[i],i++;for(var o=e.path||"",p=o.split("/"),q=a,r=1,s=p.length,t=void 0;;){if(f=p[r],d&&void 0===t&&(void 0===q[f]?t=p.slice(0,r).join("/"):r==s-1&&(t=e.path),void 0!==t&&this.validator(e,i-1,a,t)),r++,void 0===f&&r>=s){g=l[e.op].call(e,q,f,a);break}if(h(q)){if("-"===f)f=q.length;else{if(d&&!c(f))throw new m("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i-1,e.path,e);f=parseInt(f,10)}if(r>=s){if(d&&"add"===e.op&&f>q.length)throw new m("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i-1,e.path,e);g=k[e.op].call(e,q,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),r>=s){g=j[e.op].call(e,q,f,a);break}q=q[f]}}return g}function e(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(e(a[b]))return!0;return!1}function f(b,c,d,f){if("object"!=typeof b||null===b||h(b))throw new m("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!j[b.op])throw new m("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new m("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new m("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new m("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&e(b.value))throw new m("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var g=b.path.split("/").length,i=f.split("/").length;if(g!==i+1&&g!==i)throw new m("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==f)throw new m("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var k={op:"_get",path:b.from,value:void 0},l=a.validate([k],d);if(l&&"OPERATION_PATH_UNRESOLVABLE"===l.name)throw new m("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function g(a,b){try{if(!h(a))throw new m("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(e){if(e instanceof m)return e;throw e}}var h,i=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),j={add:function(a,b){return a[b]=this.value,!0},remove:function(a,b){return delete a[b],!0},replace:function(a,b){return a[b]=this.value,!0},move:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},copy:function(a,b,c){var e={op:"_get",path:this.from};return d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}]),!0},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},k={add:function(a,b){return a.splice(b,0,this.value),!0},remove:function(a,b){return a.splice(b,1),!0},replace:function(a,b){return a[b]=this.value,!0},move:j.move,copy:j.copy,test:j.test,_get:j._get},l={add:function(a){l.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b]);return!0},remove:function(a){for(var b in a)a.hasOwnProperty(b)&&j.remove.call(this,a,b);return!0},replace:function(a){return d(a,[{op:"remove",path:this.path}]),d(a,[{op:"add",path:this.path,value:this.value}]),!0},move:j.move,copy:j.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};h=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var m=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return __extends(b,a),b}(OriginalError);a.JsonPatchError=m,a.Error=m,a.validator=f,a.validate=g}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
var __extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},OriginalError=Error,jsonpatch;!function(a){function b(a,c){switch(typeof a){case"undefined":case"boolean":case"string":case"number":return a===c;case"object":if(null===a)return null===c;if(h(a)){if(!h(c)||a.length!==c.length)return!1;for(var d=0,e=a.length;e>d;d++)if(!b(a[d],c[d]))return!1;return!0}var f=i(c),g=f.length;if(i(a).length!==g)return!1;for(var d=0;g>d;d++)if(!b(a[d],c[d]))return!1;return!0;default:return!1}}function c(a){for(var b,c=0,d=a.length;d>c;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function d(a,b,d){for(var e,f,g=new Array(b.length),i=0,n=b.length;n>i;){e=b[i],i++;for(var o=e.path||"",p=o.split("/"),q=a,r=1,s=p.length,t=void 0;;){if(f=p[r],d&&void 0===t&&(void 0===q[f]?t=p.slice(0,r).join("/"):r==s-1&&(t=e.path),void 0!==t&&this.validator(e,i-1,a,t)),r++,void 0===f&&r>=s){g[i-1]=l[e.op].call(e,q,f,a);break}if(h(q)){if("-"===f)f=q.length;else{if(d&&!c(f))throw new m("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i-1,e.path,e);f=parseInt(f,10)}if(r>=s){if(d&&"add"===e.op&&f>q.length)throw new m("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i-1,e.path,e);g[i-1]=k[e.op].call(e,q,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),r>=s){g[i-1]=j[e.op].call(e,q,f,a);break}q=q[f]}}return g}function e(a){if(void 0===a)return!0;if("array"==typeof a||"object"==typeof a)for(var b in a)if(e(a[b]))return!0;return!1}function f(b,c,d,f){if("object"!=typeof b||null===b||h(b))throw new m("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!j[b.op])throw new m("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",c,b,d);if("string"!=typeof b.path)throw new m("Operation `path` property is not a string","OPERATION_PATH_INVALID",c,b,d);if(("move"===b.op||"copy"===b.op)&&"string"!=typeof b.from)throw new m("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&void 0===b.value)throw new m("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(("add"===b.op||"replace"===b.op||"test"===b.op)&&e(b.value))throw new m("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",c,b,d);if(d)if("add"==b.op){var g=b.path.split("/").length,i=f.split("/").length;if(g!==i+1&&g!==i)throw new m("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",c,b,d)}else if("replace"===b.op||"remove"===b.op||"_get"===b.op){if(b.path!==f)throw new m("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",c,b,d)}else if("move"===b.op||"copy"===b.op){var k={op:"_get",path:b.from,value:void 0},l=a.validate([k],d);if(l&&"OPERATION_PATH_UNRESOLVABLE"===l.name)throw new m("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function g(a,b){try{if(!h(a))throw new m("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),d.call(this,b,a,!0);else for(var c=0;c<a.length;c++)this.validator(a[c],c)}catch(e){if(e instanceof m)return e;throw e}}var h,i=function(a){if(h(a)){for(var b=new Array(a.length),c=0;c<b.length;c++)b[c]=""+c;return b}if(Object.keys)return Object.keys(a);var b=[];for(var d in a)a.hasOwnProperty(d)&&b.push(d);return b},j={add:function(a,b){a[b]=this.value},remove:function(a,b){var c=a[b];return delete a[b],c},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:function(a,b,c){var e={op:"_get",path:this.path};d(c,[e]);var f=void 0===e.value?void 0:JSON.parse(JSON.stringify(e.value)),g={op:"_get",path:this.from};return d(c,[g]),d(c,[{op:"remove",path:this.from}]),d(c,[{op:"add",path:this.path,value:g.value}]),f},copy:function(a,b,c){var e={op:"_get",path:this.from};d(c,[e]),d(c,[{op:"add",path:this.path,value:e.value}])},test:function(a,c){return b(a[c],this.value)},_get:function(a,b){this.value=a[b]}},k={add:function(a,b){return a.splice(b,0,this.value),b},remove:function(a,b){var c=a.splice(b,1);return c[0]},replace:function(a,b){var c=a[b];return a[b]=this.value,c},move:j.move,copy:j.copy,test:j.test,_get:j._get},l={add:function(a){l.remove.call(this,a);for(var b in this.value)this.value.hasOwnProperty(b)&&(a[b]=this.value[b])},remove:function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c],j.remove.call(this,a,c));return b},replace:function(a){var b=d(a,[{op:"remove",path:this.path}]);return d(a,[{op:"add",path:this.path,value:this.value}]),b[0]},move:j.move,copy:j.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:function(a){this.value=a}};h=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d;var m=function(a){function b(b,c,d,e,f){a.call(this,b),this.message=b,this.name=c,this.index=d,this.operation=e,this.tree=f}return __extends(b,a),b}(OriginalError);a.JsonPatchError=m,a.Error=m,a.validator=f,a.validate=g}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply,exports.validate=jsonpatch.validate,exports.validator=jsonpatch.validator,exports.JsonPatchError=jsonpatch.JsonPatchError,exports.Error=jsonpatch.Error);
{
"name": "fast-json-patch",
"version": "0.5.7",
"version": "1.0.0",
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities",

@@ -24,8 +24,3 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch",

},
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
}
],
"license": "MIT",
"main": "./src/json-patch-duplex",

@@ -38,4 +33,11 @@ "engines": {

"grunt-bump": "^0.3.0",
"grunt-contrib-uglify": "~0.5.0"
"grunt-contrib-uglify": "~0.5.0",
"jasmine-node": "^1.14.5",
"jsdom": "^9.2.1"
},
"scripts": {
"test": "jasmine-node --matchall --config duplex yes test/spec/coreSpec.js test/spec/duplexSpec.js",
"test-duplex": "jasmine-node --matchall --config duplex yes test/spec/duplexSpec.js",
"test-core": "jasmine-node --matchall --config duplex no test/spec/coreSpec.js"
}
}

@@ -14,4 +14,4 @@ JSON-Patch

JSON-Patch [(RFC6902)](http://tools.ietf.org/html/rfc6902) is a standard format that
allows you to update a JSON document by sending the changes rather than the whole document.
JSON-Patch [(RFC6902)](http://tools.ietf.org/html/rfc6902) is a standard format that
allows you to update a JSON document by sending the changes rather than the whole document.
JSON Patch plays well with the HTTP PATCH verb (method) and REST style programming.

@@ -34,7 +34,7 @@

Tested on 22.10.2015. Compared libraries:
Tested on 22.10.2015. Compared libraries:
- [Starcounter-Jack/JSON-Patch](https://github.com/Starcounter-Jack/JSON-Patch) 0.5.4
- [bruth/jsonpatch-js](https://github.com/bruth/jsonpatch-js) 0.5.0
- [dharmafly/jsonpatch.js](https://github.com/dharmafly/jsonpatch.js) master branch
- [bruth/jsonpatch-js](https://github.com/bruth/jsonpatch-js) 0.5.0
- [dharmafly/jsonpatch.js](https://github.com/dharmafly/jsonpatch.js) master branch
- [jiff](https://www.npmjs.com/package/jiff) 0.7.2 browserified

@@ -78,3 +78,3 @@ - [json8-patch](https://www.npmjs.com/package/json8-patch) 0.3.2 browserified

Call require to get the instance:
Call require to get the instance:

@@ -143,25 +143,2 @@ ```js

## Testing
### In a web browser
1. Testing **json-patch.js**
- Load `test/SpecRunner.html` in your web browser
2. Testing **json-patch-duplex.js**
- Load `test/SpecRunnerDuplex.html` in your web browser
Each of the test suite files contains *Jasmine* unit test suite and *Benchmark.js* performance test suite.
To run *Benchmark.js* performance tests, press "Run Tests" button.
### In Node.js
1. Go to directory where you have cloned the repo
2. Install Jasmine Node.js module by running command `npm install jasmine-node -g`
3. Testing **json-patch.js**
- Run command `jasmine-node --matchall --config duplex no test/spec/coreSpec.js`
4. Testing **json-patch-duplex.js**
- Run command `jasmine-node --matchall --config duplex yes test/spec/coreSpec.js test/spec/duplexSpec.js`
## API

@@ -257,10 +234,18 @@

## :no_entry_sign: `undefined`s (JS to JSON projection)
## `undefined`s (JS to JSON projection)
~~As `undefined` is not a valid value for any JSON node, it's also not valid value o JSON Patch operation object value property. Therefore `jsonpatch` will not generate JSON Patches that sets anything to `undefined`.~~
As `undefined` type does not exist in JSON, it's also not a valid value of JSON Patch operation. Therefore `jsonpatch` will not generate JSON Patches that sets anything to `undefined`.
~~However, to play nicer with natural JavaScipt objects `jsonpatch` can be applied to an object that contains `undefined`, in such case we will use it as native `JSON.stringify` - we will treat them as non-existing nodes, and map to `null` for array elements.~~
Whenever a value is set to `undefined` in JS, JSON-Patch methods `generate` and `compare` will treat it similarly to how JavaScript method [`JSON.stringify` (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) treats them:
> If `undefined` (...) is encountered during conversion it is either omitted (when it is found in an object) or censored to `null` (when it is found in an array).
See the [ECMAScript spec](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-json.stringify) for details.
## Changelog
To see the list of recent changes, see [Releases](https://github.com/Starcounter-Jack/JSON-Patch/releases).
## License
MIT
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester

@@ -74,13 +74,19 @@ * MIT license

obj[key] = this.value;
return true;
},
remove: function (obj, key) {
var removed = obj[key];
delete obj[key];
return true;
return removed;
},
replace: function (obj, key) {
var removed = obj[key];
obj[key] = this.value;
return true;
return removed;
},
move: function (obj, key, tree) {
var getOriginalDestination = { op: "_get", path: this.path };
apply(tree, [getOriginalDestination]);
// In case value is moved up and overwrites its ancestor
var original = getOriginalDestination.value === undefined ?
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value));
var temp = { op: "_get", path: this.from };

@@ -94,3 +100,3 @@ apply(tree, [temp]);

]);
return true;
return original;
},

@@ -103,3 +109,2 @@ copy: function (obj, key, tree) {

]);
return true;
},

@@ -117,11 +122,13 @@ test: function (obj, key) {

arr.splice(i, 0, this.value);
return true;
// this may be needed when using '-' in an array
return i;
},
remove: function (arr, i) {
arr.splice(i, 1);
return true;
var removedList = arr.splice(i, 1);
return removedList[0];
},
replace: function (arr, i) {
var removed = arr[i];
arr[i] = this.value;
return true;
return removed;
},

@@ -142,14 +149,15 @@ move: objOps.move,

}
return true;
},
remove: function (obj) {
var removed = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
removed[key] = obj[key];
objOps.remove.call(this, obj, key);
}
}
return true;
return removed;
},
replace: function (obj) {
apply(obj, [
var removed = apply(obj, [
{ op: "remove", path: this.path }

@@ -160,3 +168,3 @@ ]);

]);
return true;
return removed[0];
},

@@ -172,26 +180,2 @@ move: objOps.move,

};
var observeOps = {
add: function (patches, path) {
var patch = {
op: "add",
path: path + escapePathComponent(this.name),
value: this.object[this.name] };
patches.push(patch);
},
'delete': function (patches, path) {
var patch = {
op: "remove",
path: path + escapePathComponent(this.name)
};
patches.push(patch);
},
update: function (patches, path) {
var patch = {
op: "replace",
path: path + escapePathComponent(this.name),
value: this.object[this.name]
};
patches.push(patch);
}
};
function escapePathComponent(str) {

@@ -236,3 +220,3 @@ if (str.indexOf('/') === -1 && str.indexOf('~') === -1)

return Mirror;
})();
}());
var ObserverInfo = (function () {

@@ -244,3 +228,3 @@ function ObserverInfo(callback, observer) {

return ObserverInfo;
})();
}());
function getMirror(obj) {

@@ -273,8 +257,10 @@ for (var i = 0, ilen = beforeDict.length; i < ilen; i++) {

function deepClone(obj) {
if (typeof obj === "object") {
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
else {
return obj; //no need to clone primitives
}
}

@@ -301,7 +287,2 @@ function observe(obj, callback) {

observer.next = null;
var intervals = this.intervals || [100, 1000, 10000, 60000];
if (intervals.push === void 0) {
throw new OriginalError("jsonpatch.intervals must be an array");
}
var currentInterval = 0;
var dirtyCheck = function () {

@@ -312,27 +293,14 @@ generate(observer);

clearTimeout(observer.next);
observer.next = setTimeout(function () {
dirtyCheck();
currentInterval = 0;
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
}, 0);
observer.next = setTimeout(dirtyCheck);
};
var slowCheck = function () {
dirtyCheck();
if (currentInterval == intervals.length)
currentInterval = intervals.length - 1;
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
};
if (typeof window !== 'undefined') {
if (window.addEventListener) {
window.addEventListener('mousedown', fastCheck);
window.addEventListener('mouseup', fastCheck);
window.addEventListener('keydown', fastCheck);
window.addEventListener('keyup', fastCheck);
}
else {
document.documentElement.attachEvent('onmousedown', fastCheck);
document.documentElement.attachEvent('onmouseup', fastCheck);
document.documentElement.attachEvent('onkeydown', fastCheck);
document.documentElement.attachEvent('onkeyup', fastCheck);
}
}
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
}

@@ -347,10 +315,8 @@ observer.patches = patches;

if (window.removeEventListener) {
window.removeEventListener('mousedown', fastCheck);
window.removeEventListener('mouseup', fastCheck);
window.removeEventListener('keydown', fastCheck);
window.removeEventListener('keyup', fastCheck);
}
else {
document.documentElement.detachEvent('onmousedown', fastCheck);
document.documentElement.detachEvent('onmouseup', fastCheck);
document.documentElement.detachEvent('onkeydown', fastCheck);
document.documentElement.detachEvent('onkeyup', fastCheck);
}

@@ -395,3 +361,3 @@ }

var oldVal = mirror[key];
if (obj.hasOwnProperty(key)) {
if (obj.hasOwnProperty(key) && !(obj[key] === undefined && _isArray(obj) === false)) {
var newVal = obj[key];

@@ -418,3 +384,3 @@ if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) {

var key = newKeys[t];
if (!mirror.hasOwnProperty(key)) {
if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) {
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key]) });

@@ -448,5 +414,11 @@ }

}
/// Apply a json-patch operation on an object tree
/**
* Apply a json-patch operation on an object tree
* Returns an array of results of operations.
* Each element can either be a boolean (if op == 'test') or
* the removed object (operations that remove things)
* or just be undefined
*/
function apply(tree, patches, validate) {
var result = false, p = 0, plen = patches.length, patch, key;
var results = [], p = 0, plen = patches.length, patch, key;
while (p < plen) {

@@ -480,3 +452,3 @@ patch = patches[p];

if (t >= len) {
result = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(rootOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -499,3 +471,3 @@ }

}
result = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(arrOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -508,3 +480,3 @@ }

if (t >= len) {
result = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(objOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -516,3 +488,3 @@ }

}
return result;
return results;
}

@@ -537,3 +509,3 @@ jsonpatch.apply = apply;

return JsonPatchError;
})(OriginalError);
}(OriginalError));
jsonpatch.JsonPatchError = JsonPatchError;

@@ -650,1 +622,2 @@ jsonpatch.Error = JsonPatchError;

}
//# sourceMappingURL=json-patch-duplex.js.map
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester

@@ -88,15 +88,23 @@ * MIT license

obj[key] = this.value;
return true;
},
remove: function (obj, key) {
var removed = obj[key];
delete obj[key];
return true;
return removed;
},
replace: function (obj, key) {
var removed = obj[key];
obj[key] = this.value;
return true;
return removed;
},
move: function (obj, key, tree) {
var getOriginalDestination : any = {op: "_get", path: this.path};
apply(tree, [getOriginalDestination]);
// In case value is moved up and overwrites its ancestor
var original = getOriginalDestination.value === undefined ?
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value));
var temp:any = {op: "_get", path: this.from};
apply(tree, [temp]);
apply(tree, [

@@ -108,3 +116,3 @@ {op: "remove", path: this.from}

]);
return true;
return original;
},

@@ -117,3 +125,2 @@ copy: function (obj, key, tree) {

]);
return true;
},

@@ -132,11 +139,13 @@ test: function (obj, key) {

arr.splice(i, 0, this.value);
return true;
// this may be needed when using '-' in an array
return i;
},
remove: function (arr, i) {
arr.splice(i, 1);
return true;
var removedList = arr.splice(i, 1);
return removedList[0];
},
replace: function (arr, i) {
var removed = arr[i];
arr[i] = this.value;
return true;
return removed;
},

@@ -158,14 +167,15 @@ move: objOps.move,

}
return true;
},
remove: function (obj) {
var removed = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
removed[key] = obj[key];
objOps.remove.call(this, obj, key);
}
}
return true;
return removed;
},
replace: function (obj) {
apply(obj, [
var removed = apply(obj, [
{op: "remove", path: this.path}

@@ -176,3 +186,3 @@ ]);

]);
return true;
return removed[0];
},

@@ -189,27 +199,2 @@ move: objOps.move,

var observeOps = {
add: function (patches:any[], path) {
var patch = {
op: "add",
path: path + escapePathComponent(this.name),
value: this.object[this.name]};
patches.push(patch);
},
'delete': function (patches:any[], path) { //single quotes needed because 'delete' is a keyword in IE8
var patch = {
op: "remove",
path: path + escapePathComponent(this.name)
};
patches.push(patch);
},
update: function (patches:any[], path) {
var patch = {
op: "replace",
path: path + escapePathComponent(this.name),
value: this.object[this.name]
};
patches.push(patch);
}
};
function escapePathComponent (str) {

@@ -251,4 +236,2 @@ if (str.indexOf('/') === -1 && str.indexOf('~') === -1) return str;

export var intervals;
class Mirror {

@@ -303,8 +286,12 @@ obj: any;

function deepClone(obj:any) {
if (typeof obj === "object") {
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
switch (typeof obj) {
case "object":
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
case "undefined":
return null; //this is how JSON.stringify behaves for array items
default:
return obj; //no need to clone primitives
}
else {
return obj; //no need to clone primitives
}
}

@@ -336,38 +323,20 @@

observer.next = null;
var intervals = this.intervals || [100, 1000, 10000, 60000];
if (intervals.push === void 0) {
throw new OriginalError("jsonpatch.intervals must be an array");
}
var currentInterval = 0;
var dirtyCheck = function () {
generate(observer);
var dirtyCheck = () => {
generate(observer);
};
var fastCheck = function () {
clearTimeout(observer.next);
observer.next = setTimeout(function () {
dirtyCheck();
currentInterval = 0;
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
}, 0);
var fastCheck = () => {
clearTimeout(observer.next);
observer.next = setTimeout(dirtyCheck);
};
var slowCheck = function () {
dirtyCheck();
if (currentInterval == intervals.length)
currentInterval = intervals.length - 1;
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
};
if (typeof window !== 'undefined') { //not Node
if (window.addEventListener) { //standards
window.addEventListener('mousedown', fastCheck);
window.addEventListener('mouseup', fastCheck);
window.addEventListener('keydown', fastCheck);
window.addEventListener('keyup', fastCheck);
}
else { //IE8
document.documentElement.attachEvent('onmousedown', fastCheck);
document.documentElement.attachEvent('onmouseup', fastCheck);
document.documentElement.attachEvent('onkeydown', fastCheck);
document.documentElement.attachEvent('onkeyup', fastCheck);
}
}
observer.next = setTimeout(slowCheck, intervals[currentInterval++]);
}

@@ -377,3 +346,3 @@ observer.patches = patches;

observer.unobserve = function () {
observer.unobserve = () => {
generate(observer);

@@ -385,10 +354,8 @@ clearTimeout(observer.next);

if (window.removeEventListener) {
window.removeEventListener('mousedown', fastCheck);
window.removeEventListener('mouseup', fastCheck);
window.removeEventListener('keydown', fastCheck);
window.removeEventListener('keyup', fastCheck);
}
else {
document.documentElement.detachEvent('onmousedown', fastCheck);
document.documentElement.detachEvent('onmouseup', fastCheck);
document.documentElement.detachEvent('onkeydown', fastCheck);
document.documentElement.detachEvent('onkeyup', fastCheck);
}

@@ -437,3 +404,3 @@ }

var oldVal = mirror[key];
if (obj.hasOwnProperty(key)) {
if (obj.hasOwnProperty(key) && !(obj[key] === undefined && _isArray(obj) === false)) {
var newVal = obj[key];

@@ -462,3 +429,3 @@ if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) {

var key = newKeys[t];
if (!mirror.hasOwnProperty(key)) {
if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) {
patches.push({op: "add", path: path + "/" + escapePathComponent(key), value: deepClone(obj[key])});

@@ -495,5 +462,11 @@ }

/// Apply a json-patch operation on an object tree
export function apply(tree:any, patches:any[], validate?:boolean):boolean {
var result = false
/**
* Apply a json-patch operation on an object tree
* Returns an array of results of operations.
* Each element can either be a boolean (if op == 'test') or
* the removed object (operations that remove things)
* or just be undefined
*/
export function apply(tree:any, patches:any[], validate?:boolean):Array<any> {
var results = []
, p = 0

@@ -534,3 +507,3 @@ , plen = patches.length

if (t >= len) {
result = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(rootOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -553,3 +526,3 @@ }

}
result = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(arrOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -562,3 +535,3 @@ }

if (t >= len) {
result = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
results.push(objOps[patch.op].call(patch, obj, key, tree)); // Apply patch
break;

@@ -570,3 +543,3 @@ }

}
return result;
return results;
}

@@ -573,0 +546,0 @@

/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester

@@ -15,15 +15,21 @@ * MIT license

(function (jsonpatch) {
var _objectKeys = (function () {
if (Object.keys)
return Object.keys;
return function (o) {
var keys = [];
for (var i in o) {
if (o.hasOwnProperty(i)) {
keys.push(i);
}
var _objectKeys = function (obj) {
if (_isArray(obj)) {
var keys = new Array(obj.length);
for (var k = 0; k < keys.length; k++) {
keys[k] = "" + k;
}
return keys;
};
})();
}
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
keys.push(i);
}
}
return keys;
};
function _equals(a, b) {

@@ -69,13 +75,19 @@ switch (typeof a) {

obj[key] = this.value;
return true;
},
remove: function (obj, key) {
var removed = obj[key];
delete obj[key];
return true;
return removed;
},
replace: function (obj, key) {
var removed = obj[key];
obj[key] = this.value;
return true;
return removed;
},
move: function (obj, key, tree) {
var getOriginalDestination = { op: "_get", path: this.path };
apply(tree, [getOriginalDestination]);
// In case value is moved up and overwrites its ancestor
var original = getOriginalDestination.value === undefined ?
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value));
var temp = { op: "_get", path: this.from };

@@ -89,3 +101,3 @@ apply(tree, [temp]);

]);
return true;
return original;
},

@@ -98,3 +110,2 @@ copy: function (obj, key, tree) {

]);
return true;
},

@@ -112,11 +123,13 @@ test: function (obj, key) {

arr.splice(i, 0, this.value);
return true;
// this may be needed when using '-' in an array
return i;
},
remove: function (arr, i) {
arr.splice(i, 1);
return true;
var removedList = arr.splice(i, 1);
return removedList[0];
},
replace: function (arr, i) {
var removed = arr[i];
arr[i] = this.value;
return true;
return removed;
},

@@ -137,14 +150,15 @@ move: objOps.move,

}
return true;
},
remove: function (obj) {
var removed = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
removed[key] = obj[key];
objOps.remove.call(this, obj, key);
}
}
return true;
return removed;
},
replace: function (obj) {
apply(obj, [
var removed = apply(obj, [
{ op: "remove", path: this.path }

@@ -155,3 +169,3 @@ ]);

]);
return true;
return removed[0];
},

@@ -191,5 +205,11 @@ move: objOps.move,

}
/// Apply a json-patch operation on an object tree
/**
* Apply a json-patch operation on an object tree
* Returns an array of results of operations.
* Each element can either be a boolean (if op == 'test') or
* the removed object (operations that remove things)
* or just be undefined
*/
function apply(tree, patches, validate) {
var result = false, p = 0, plen = patches.length, patch, key;
var results = new Array(patches.length), p = 0, plen = patches.length, patch, key;
while (p < plen) {

@@ -223,3 +243,3 @@ patch = patches[p];

if (t >= len) {
result = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -242,3 +262,3 @@ }

}
result = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -251,3 +271,3 @@ }

if (t >= len) {
result = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -259,3 +279,3 @@ }

}
return result;
return results;
}

@@ -274,3 +294,3 @@ jsonpatch.apply = apply;

return JsonPatchError;
})(OriginalError);
}(OriginalError));
jsonpatch.JsonPatchError = JsonPatchError;

@@ -383,1 +403,2 @@ jsonpatch.Error = JsonPatchError;

}
//# sourceMappingURL=json-patch.js.map
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* json-patch-duplex.js version: 0.5.7
* json-patch-duplex.js version: 1.0.0
* (c) 2013 Joachim Wester

@@ -9,18 +9,28 @@ * MIT license

var OriginalError = Error;
module jsonpatch {
var _objectKeys = (function () {
if (Object.keys)
return Object.keys;
var _objectKeys = function (obj) {
if (_isArray(obj)) {
var keys = new Array(obj.length);
return function (o) { //IE8
var keys = [];
for (var i in o) {
if (o.hasOwnProperty(i)) {
keys.push(i);
}
for (var k = 0; k < keys.length; k++) {
keys[k] = "" + k;
}
return keys;
}
})();
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
keys.push(i);
}
}
return keys;
};
function _equals(a, b) {

@@ -73,15 +83,23 @@ switch (typeof a) {

obj[key] = this.value;
return true;
},
remove: function (obj, key) {
var removed = obj[key];
delete obj[key];
return true;
return removed;
},
replace: function (obj, key) {
var removed = obj[key];
obj[key] = this.value;
return true;
return removed;
},
move: function (obj, key, tree) {
var getOriginalDestination : any = {op: "_get", path: this.path};
apply(tree, [getOriginalDestination]);
// In case value is moved up and overwrites its ancestor
var original = getOriginalDestination.value === undefined ?
undefined : JSON.parse(JSON.stringify(getOriginalDestination.value));
var temp:any = {op: "_get", path: this.from};
apply(tree, [temp]);
apply(tree, [

@@ -93,3 +111,3 @@ {op: "remove", path: this.from}

]);
return true;
return original;
},

@@ -102,3 +120,2 @@ copy: function (obj, key, tree) {

]);
return true;
},

@@ -117,11 +134,13 @@ test: function (obj, key) {

arr.splice(i, 0, this.value);
return true;
// this may be needed when using '-' in an array
return i;
},
remove: function (arr, i) {
arr.splice(i, 1);
return true;
var removedList = arr.splice(i, 1);
return removedList[0];
},
replace: function (arr, i) {
var removed = arr[i];
arr[i] = this.value;
return true;
return removed;
},

@@ -143,14 +162,15 @@ move: objOps.move,

}
return true;
},
remove: function (obj) {
var removed = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
removed[key] = obj[key];
objOps.remove.call(this, obj, key);
}
}
return true;
return removed;
},
replace: function (obj) {
apply(obj, [
var removed = apply(obj, [
{op: "remove", path: this.path}

@@ -161,3 +181,3 @@ ]);

]);
return true;
return removed[0];
},

@@ -200,5 +220,11 @@ move: objOps.move,

/// Apply a json-patch operation on an object tree
export function apply(tree:any, patches:any[], validate?:boolean):boolean {
var result = false
/**
* Apply a json-patch operation on an object tree
* Returns an array of results of operations.
* Each element can either be a boolean (if op == 'test') or
* the removed object (operations that remove things)
* or just be undefined
*/
export function apply(tree:any, patches:any[], validate?:boolean):Array<any> {
var results = new Array(patches.length)
, p = 0

@@ -239,3 +265,3 @@ , plen = patches.length

if (t >= len) {
result = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = rootOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -258,3 +284,3 @@ }

}
result = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = arrOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -267,3 +293,3 @@ }

if (t >= len) {
result = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
results[p - 1] = objOps[patch.op].call(patch, obj, key, tree); // Apply patch
break;

@@ -275,3 +301,3 @@ }

}
return result;
return results;
}

@@ -312,3 +338,3 @@

return false;
}
}

@@ -315,0 +341,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc