diff --git a/README.md b/README.md index 61a6565a..75ea5973 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ JSON-Patch A leaner and meaner implementation of JSON-Patch. Small footprint. High performance. -With Fast-JSON-Patch, you can: +With JSON-Patch, you can: - **apply** patches - **validate** a sequence of patches - **observe** for changes (and generate patches when a change is detected) @@ -46,7 +46,7 @@ $ npm install fast-json-patch --save $ bower install fast-json-patch --save ``` -### [download as ZIP](https://github.com/Starcounter-Jack/Fast-JSON-Patch/archive/master.zip) +### [download as ZIP](https://github.com/Starcounter-Jack/JSON-Patch/archive/master.zip) ## Adding to your project @@ -227,4 +227,4 @@ OPERATION_VALUE_OUT_OF_BOUNDS | The specified index MUST NOT be greater than the ## Changelog -To see the list of recent changes, see [Releases](https://github.com/Starcounter-Jack/Fast-JSON-Patch/releases). +To see the list of recent changes, see [Releases](https://github.com/Starcounter-Jack/JSON-Patch/releases). diff --git a/bower.json b/bower.json index 7e0727ea..24234081 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "fast-json-patch", - "version": "0.5.0", - "homepage": "https://github.com/Starcounter-Jack/Fast-JSON-Patch", + "version": "0.5.1", + "homepage": "https://github.com/Starcounter-Jack/JSON-Patch", "description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities", "main": "src/json-patch-duplex.js", "keywords": ["json", "patch", "http", "rest"], diff --git a/dist/json-patch-duplex.min.js b/dist/json-patch-duplex.min.js index 5a18fce4..eb4b4cef 100644 --- a/dist/json-patch-duplex.min.js +++ b/dist/json-patch-duplex.min.js @@ -1,7 +1,7 @@ /*! -* https://github.com/Starcounter-Jack/Fast-JSON-Patch -* json-patch-duplex.js 0.5.0 +* https://github.com/Starcounter-Jack/JSON-Patch +* json-patch-duplex.js 0.5.1 * (c) 2013 Joachim Wester * MIT license */ -var 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(A(a)){if(!A(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=s(c),g=f.length;if(s(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,b){var e;for(var f in a)if(a.hasOwnProperty(f)){if(a[f]===b)return c(f)+"/";if("object"==typeof a[f]&&(e=d(a[f],b),""!=e))return c(f)+"/"+e}return""}function e(a,b){if(a===b)return"/";var c=d(a,b);if(""===c)throw new Error("Object not found in root");return"/"+c}function f(a){for(var b=0,c=x.length;c>b;b++)if(x[b].obj===a)return x[b]}function g(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 h(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 i(a,b){n(b),Object.observe?m(b,a):clearTimeout(b.next);var c=f(a);h(c,b)}function j(a){return"object"==typeof a?JSON.parse(JSON.stringify(a)):a}function k(a,b){var c,d=[],h=a,i=f(a);if(i?c=g(i,b):(i=new y(a),x.push(i)),c)return c;if(Object.observe)c=function(f){m(c,a),l(c,a);for(var g=0,i=f.length;i>g;){if(("length"!==f[g].name||!A(f[g].object))&&"__Jasmine_been_here_before__"!==f[g].name){var j=f[g].type;switch(j){case"new":j="add";break;case"deleted":j="delete";break;case"updated":j="update"}w[j].call(f[g],d,e(h,f[g].object))}g++}d&&b&&b(d),c.patches=d,d=[]};else if(c={},i.value=j(a),b){c.callback=b,c.next=null;var k=this.intervals||[100,1e3,1e4,6e4];if(void 0===k.push)throw new Error("jsonpatch.intervals must be an array");var o=0,p=function(){n(c)},q=function(){clearTimeout(c.next),c.next=setTimeout(function(){p(),o=0,c.next=setTimeout(r,k[o++])},0)},r=function(){p(),o==k.length&&(o=k.length-1),c.next=setTimeout(r,k[o++])};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mousedown",q),window.addEventListener("mouseup",q),window.addEventListener("keydown",q)):(window.attachEvent("onmousedown",q),window.attachEvent("onmouseup",q),window.attachEvent("onkeydown",q))),c.next=setTimeout(r,k[o++])}return c.patches=d,c.object=a,i.observers.push(new z(b,c)),l(c,a)}function l(a,b){if(Object.observe){Object.observe(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&l(a,d)}}return a}function m(a,b){if(Object.observe){Object.unobserve(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&m(a,d)}}return a}function n(a){if(Object.observe)Object.deliverChangeRecords(a);else{for(var b,c=0,d=x.length;d>c;c++)if(x[c].obj===a.object){b=x[c];break}o(b.value,a.object,a.patches,""),a.patches.length&&q(b.value,a.patches)}var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function o(a,b,d,e){for(var f=s(b),g=s(a),h=!1,i=!1,k=g.length-1;k>=0;k--){var l=g[k],m=a[l];if(b.hasOwnProperty(l)){var n=b[l];m instanceof Object?o(m,n,d,e+"/"+c(l)):m!=n&&(h=!0,d.push({op:"replace",path:e+"/"+c(l),value:j(n)}))}else d.push({op:"remove",path:e+"/"+c(l)}),i=!0}if(i||f.length!=g.length)for(var k=0;kc;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function q(a,b){for(var c,d=!1,e=0,f=b.length;f>e;){c=b[e],e++;var g=c.path.split("/"),h=a,i=1,j=g.length;if(void 0===c.value&&("add"===c.op||"replace"===c.op||"test"===c.op))throw new Error("'value' MUST be defined");if(void 0===c.from&&("copy"===c.op||"move"===c.op))throw new Error("'from' MUST be defined");for(;;)if(A(h)){var k;if("-"===g[i])k=h.length;else{if(!p(g[i]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");k=parseInt(g[i],10)}if(i++,i>=j){d=u[c.op].call(c,h,k,a);break}h=h[k]}else{var l=g[i];if(void 0!==l){if(l&&-1!=l.indexOf("~")&&(l=l.replace(/~1/g,"/").replace(/~0/g,"~")),i++,i>=j){d=t[c.op].call(c,h,l,a);break}}else if(i++,i>=j){d=v[c.op].call(c,h,l,a);break}h=h[l]}}return d}function r(a,b){var c=[];return o(a,b,c,""),c}if(!a.observe){var s=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),t={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 q(c,[d]),q(c,[{op:"remove",path:this.from}]),q(c,[{op:"add",path:this.path,value:d.value}]),!0},copy:function(a,b,c){var d={op:"_get",path:this.from};return q(c,[d]),q(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]}},u={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");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:t.move,copy:t.copy,test:t.test,_get:t._get},v={add:function(a){v.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)&&t.remove.call(this,a,b);return!0},replace:function(a){return q(a,[{op:"remove",path:this.path}]),q(a,[{op:"add",path:this.path,value:this.value}]),!0},move:t.move,copy:t.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:t._get},w={add:function(a,b){var d={op:"add",path:b+c(this.name),value:this.object[this.name]};a.push(d)},"delete":function(a,b){var d={op:"remove",path:b+c(this.name)};a.push(d)},update:function(a,b){var d={op:"replace",path:b+c(this.name),value:this.object[this.name]};a.push(d)}},x=[];a.intervals;var y=function(){function a(a){this.observers=[],this.obj=a}return a}(),z=function(){function a(a,b){this.callback=a,this.observer=b}return a}();a.unobserve=i,a.observe=k,a.generate=n;var A;A=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=q,a.compare=r}}(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); \ No newline at end of file +var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.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(C(a)){if(!C(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=u(c),g=f.length;if(u(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,b){var e;for(var f in a)if(a.hasOwnProperty(f)){if(a[f]===b)return c(f)+"/";if("object"==typeof a[f]&&(e=d(a[f],b),""!=e))return c(f)+"/"+e}return""}function e(a,b){if(a===b)return"/";var c=d(a,b);if(""===c)throw new OriginalError("Object not found in root");return"/"+c}function f(a){for(var b=0,c=z.length;c>b;b++)if(z[b].obj===a)return z[b]}function g(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 h(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 i(a,b){n(b),Object.observe?m(b,a):clearTimeout(b.next);var c=f(a);h(c,b)}function j(a){return"object"==typeof a?JSON.parse(JSON.stringify(a)):a}function k(a,b){var c,d=[],h=a,i=f(a);if(i?c=g(i,b):(i=new A(a),z.push(i)),c)return c;if(Object.observe)c=function(f){m(c,a),l(c,a);for(var g=0,i=f.length;i>g;){if(("length"!==f[g].name||!C(f[g].object))&&"__Jasmine_been_here_before__"!==f[g].name){var j=f[g].type;switch(j){case"new":j="add";break;case"deleted":j="delete";break;case"updated":j="update"}y[j].call(f[g],d,e(h,f[g].object))}g++}d&&b&&b(d),c.patches=d,d=[]};else if(c={},i.value=j(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 o=0,p=function(){n(c)},q=function(){clearTimeout(c.next),c.next=setTimeout(function(){p(),o=0,c.next=setTimeout(r,k[o++])},0)},r=function(){p(),o==k.length&&(o=k.length-1),c.next=setTimeout(r,k[o++])};"undefined"!=typeof window&&(window.addEventListener?(window.addEventListener("mousedown",q),window.addEventListener("mouseup",q),window.addEventListener("keydown",q)):(document.documentElement.attachEvent("onmousedown",q),document.documentElement.attachEvent("onmouseup",q),document.documentElement.attachEvent("onkeydown",q))),c.next=setTimeout(r,k[o++])}return c.patches=d,c.object=a,i.observers.push(new B(b,c)),l(c,a)}function l(a,b){if(Object.observe){Object.observe(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&l(a,d)}}return a}function m(a,b){if(Object.observe){Object.unobserve(b,a);for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];d&&"object"==typeof d&&m(a,d)}}return a}function n(a){if(Object.observe)Object.deliverChangeRecords(a);else{for(var b,c=0,d=z.length;d>c;c++)if(z[c].obj===a.object){b=z[c];break}o(b.value,a.object,a.patches,""),a.patches.length&&q(b.value,a.patches)}var e=a.patches;return e.length>0&&(a.patches=[],a.callback&&a.callback(e)),e}function o(a,b,d,e){for(var f=u(b),g=u(a),h=!1,i=!1,k=g.length-1;k>=0;k--){var l=g[k],m=a[l];if(b.hasOwnProperty(l)){var n=b[l];"object"==typeof m&&null!=m&&"object"==typeof n&&null!=n?o(m,n,d,e+"/"+c(l)):m!=n&&(h=!0,d.push({op:"replace",path:e+"/"+c(l),value:j(n)}))}else d.push({op:"remove",path:e+"/"+c(l)}),i=!0}if(i||f.length!=g.length)for(var k=0;kc;){b=a.charCodeAt(c);{if(!(b>=48&&57>=b))return!1;c++}}return!0}function q(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.split("/"),j=a,k=1,l=i.length,m=void 0;;){if(e=i[k],c&&void 0==m&&(void 0==j[e]?m=i.slice(0,k).join("/"):k==l-1&&(m=d.path),void 0!=m&&this.validator(d,g-1,a,m)),k++,void 0===e&&k>=l){f=x[d.op].call(d,j,e,a);break}if(C(j)){if("-"===e)e=j.length;else{if(c&&!p(e))throw new D("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(k>=l){if(c&&"add"===d.op&&e>j.length)throw new D("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=w[d.op].call(d,j,e,a);break}}else if(e&&-1!=e.indexOf("~")&&(e=e.replace(/~1/g,"/").replace(/~0/g,"~")),k>=l){f=v[d.op].call(d,j,e,a);break}j=j[e]}}return f}function r(a,b){var c=[];return o(a,b,c,""),c}function s(b,c,d,e){if("object"!=typeof b||null===b||C(b))throw new D("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!v[b.op])throw new D("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 D("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 D("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 D("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",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 D("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 D("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 D("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function t(a,b){try{if(!C(a))throw new D("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(b)b=JSON.parse(JSON.stringify(b)),q.call(this,b,a,!0);else for(var c=0;cd;d++)if(!b(a[d],c[d]))return!1;return!0}var h=f(c),i=h.length;if(f(a).length!==i)return!1;for(var d=0;i>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){for(var d,f=!1,j=0,k=b.length;k>j;){d=b[j],j++;var l=d.path.split("/"),m=a,n=1,o=l.length;if(void 0===d.value&&("add"===d.op||"replace"===d.op||"test"===d.op))throw new Error("'value' MUST be defined");if(void 0===d.from&&("copy"===d.op||"move"===d.op))throw new Error("'from' MUST be defined");for(;;)if(e(m)){var p;if("-"===l[n])p=m.length;else{if(!c(l[n]))throw new Error("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index");p=parseInt(l[n],10)}if(n++,n>=o){f=h[d.op].call(d,m,p,a);break}m=m[p]}else{var q=l[n];if(void 0!==q){if(q&&-1!=q.indexOf("~")&&(q=q.replace(/~1/g,"/").replace(/~0/g,"~")),n++,n>=o){f=g[d.op].call(d,m,q,a);break}}else if(n++,n>=o){f=i[d.op].call(d,m,q,a);break}m=m[q]}}return f}if(!a.apply){var e,f=function(){return Object.keys?Object.keys:function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}}(),g={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]}},h={add:function(a,b){if(b>a.length)throw new Error("The specified index MUST NOT be greater than the number of elements in the array.");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:g.move,copy:g.copy,test:g.test,_get:g._get},i={add:function(a){i.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)&&g.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:g.move,copy:g.copy,test:function(a){return JSON.stringify(a)===JSON.stringify(this.value)},_get:g._get};e=Array.isArray?Array.isArray:function(a){return a.push&&"number"==typeof a.length},a.apply=d}}(jsonpatch||(jsonpatch={})),"undefined"!=typeof exports&&(exports.apply=jsonpatch.apply); \ No newline at end of file +var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.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(g(a)){if(!g(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=h(c),i=f.length;if(h(a).length!==i)return!1;for(var d=0;i>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,h=!1,m=0,n=b.length;n>m;){e=b[m],m++;for(var o=e.path.split("/"),p=a,q=1,r=o.length,s=void 0;;){if(f=o[q],d&&void 0==s&&(void 0==p[f]?s=o.slice(0,q).join("/"):q==r-1&&(s=e.path),void 0!=s&&this.validator(e,m-1,a,s)),q++,void 0===f&&q>=r){h=k[e.op].call(e,p,f,a);break}if(g(p)){if("-"===f)f=p.length;else{if(d&&!c(f))throw new l("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",m-1,e.path,e);f=parseInt(f,10)}if(q>=r){if(d&&"add"===e.op&&f>p.length)throw new l("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",m-1,e.path,e);h=j[e.op].call(e,p,f,a);break}}else if(f&&-1!=f.indexOf("~")&&(f=f.replace(/~1/g,"/").replace(/~0/g,"~")),q>=r){h=i[e.op].call(e,p,f,a);break}p=p[f]}}return h}function e(b,c,d,e){if("object"!=typeof b||null===b||g(b))throw new l("Operation is not an object","OPERATION_NOT_AN_OBJECT",c,b,d);if(!i[b.op])throw new l("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 l("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 l("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 l("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",c,b,d);if(d)if("add"==b.op){var f=b.path.split("/").length,h=e.split("/").length;if(f!==h+1&&f!==h)throw new l("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 l("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 j={op:"_get",path:b.from,value:void 0},k=a.validate([j],d);if(k&&"OPERATION_PATH_UNRESOLVABLE"===k.name)throw new l("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",c,b,d)}}function f(a,b){try{if(!g(a))throw new l("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