-
Notifications
You must be signed in to change notification settings - Fork 213
/
fast-json-patch.min.js
14 lines (14 loc) · 13.2 KB
/
fast-json-patch.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! fast-json-patch, version: 2.2.0 */
var jsonpatch=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t){
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017 Joachim Wester
* MIT license
*/
var r,n=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=Object.prototype.hasOwnProperty;function a(e,t){return o.call(e,t)}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),r=0;r<t.length;r++)t[r]=""+r;return t}if(Object.keys)return Object.keys(e);t=[];for(var n in e)a(e,n)&&t.push(n);return t}function p(e){return-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function u(e,t){var r;for(var n in e)if(a(e,n)){if(e[n]===t)return p(n)+"/";if("object"==typeof e[n]&&""!=(r=u(e[n],t)))return p(n)+"/"+r}return""}function s(e,t){var r=[e];for(var n in t){var o="object"==typeof t[n]?JSON.stringify(t[n],null,2):t[n];void 0!==o&&r.push(n+": "+o)}return r.join("\n")}t.hasOwnProperty=a,t._objectKeys=i,t._deepClone=function(e){switch(typeof e){case"object":return JSON.parse(JSON.stringify(e));case"undefined":return null;default:return e}},t.isInteger=function(e){for(var t,r=0,n=e.length;r<n;){if(!((t=e.charCodeAt(r))>=48&&t<=57))return!1;r++}return!0},t.escapePathComponent=p,t.unescapePathComponent=function(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")},t._getPathRecursive=u,t.getPath=function(e,t){if(e===t)return"/";var r=u(e,t);if(""===r)throw new Error("Object not found in root");return"/"+r},t.hasUndefined=function e(t){if(void 0===t)return!0;if(t)if(Array.isArray(t)){for(var r=0,n=t.length;r<n;r++)if(e(t[r]))return!0}else if("object"==typeof t){var o=i(t),a=o.length;for(r=0;r<a;r++)if(e(t[o[r]]))return!0}return!1};var c=function(e){function t(t,r,n,o,a){var i=this.constructor,p=e.call(this,s(t,{name:r,index:n,operation:o,tree:a}))||this;return p.name=r,p.index=n,p.operation=o,p.tree=a,Object.setPrototypeOf(p,i.prototype),p.message=s(t,{name:r,index:n,operation:o,tree:a}),p}return n(t,e),t}(Error);t.PatchError=c},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(3),o=r(0);t.JsonPatchError=o.PatchError,t.deepClone=o._deepClone;var a={add:function(e,t,r){return e[t]=this.value,{newDocument:r}},remove:function(e,t,r){var n=e[t];return delete e[t],{newDocument:r,removed:n}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:function(e,t,r){var n=p(r,this.path);n&&(n=o._deepClone(n));var a=u(r,{op:"remove",path:this.from}).removed;return u(r,{op:"add",path:this.path,value:a}),{newDocument:r,removed:n}},copy:function(e,t,r){var n=p(r,this.from);return u(r,{op:"add",path:this.path,value:o._deepClone(n)}),{newDocument:r}},test:function(e,t,r){return{newDocument:r,test:n(e[t],this.value)}},_get:function(e,t,r){return this.value=e[t],{newDocument:r}}},i={add:function(e,t,r){return o.isInteger(t)?e.splice(t,0,this.value):e[t]=this.value,{newDocument:r,index:t}},remove:function(e,t,r){return{newDocument:r,removed:e.splice(t,1)[0]}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:a.move,copy:a.copy,test:a.test,_get:a._get};function p(e,t){if(""==t)return e;var r={op:"_get",path:t};return u(e,r),r.value}function u(e,r,u,s,c,l){if(void 0===u&&(u=!1),void 0===s&&(s=!0),void 0===c&&(c=!0),void 0===l&&(l=0),u&&("function"==typeof u?u(r,0,e,r.path):f(r,0)),""===r.path){var h={newDocument:e};if("add"===r.op)return h.newDocument=r.value,h;if("replace"===r.op)return h.newDocument=r.value,h.removed=e,h;if("move"===r.op||"copy"===r.op)return h.newDocument=p(e,r.from),"move"===r.op&&(h.removed=e),h;if("test"===r.op){if(h.test=n(e,r.value),!1===h.test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",l,r,e);return h.newDocument=e,h}if("remove"===r.op)return h.removed=e,h.newDocument=null,h;if("_get"===r.op)return r.value=e,h;if(u)throw new t.JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",l,r,e);return h}s||(e=o._deepClone(e));var d=(r.path||"").split("/"),v=e,y=1,w=d.length,_=void 0,O=void 0,m=void 0;for(m="function"==typeof u?u:f;;){if(O=d[y],c&&"__proto__"==O)throw new TypeError("JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(u&&void 0===_&&(void 0===v[O]?_=d.slice(0,y).join("/"):y==w-1&&(_=r.path),void 0!==_&&m(r,0,e,_)),y++,Array.isArray(v)){if("-"===O)O=v.length;else{if(u&&!o.isInteger(O))throw new t.JsonPatchError("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",l,r,e);o.isInteger(O)&&(O=~~O)}if(y>=w){if(u&&"add"===r.op&&O>v.length)throw new t.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",l,r,e);if(!1===(h=i[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",l,r,e);return h}}else if(O&&-1!=O.indexOf("~")&&(O=o.unescapePathComponent(O)),y>=w){if(!1===(h=a[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",l,r,e);return h}v=v[O]}}function s(e,r,n,a,i){if(void 0===a&&(a=!0),void 0===i&&(i=!0),n&&!Array.isArray(r))throw new t.JsonPatchError("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");a||(e=o._deepClone(e));for(var p=new Array(r.length),s=0,c=r.length;s<c;s++)p[s]=u(e,r[s],n,!0,i,s),e=p[s].newDocument;return p.newDocument=e,p}function c(e,r,n){var o=u(e,r);if(!1===o.test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",n,r,e);return o.newDocument}function f(e,r,n,i){if("object"!=typeof e||null===e||Array.isArray(e))throw new t.JsonPatchError("Operation is not an object","OPERATION_NOT_AN_OBJECT",r,e,n);if(!a[e.op])throw new t.JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",r,e,n);if("string"!=typeof e.path)throw new t.JsonPatchError("Operation `path` property is not a string","OPERATION_PATH_INVALID",r,e,n);if(0!==e.path.indexOf("/")&&e.path.length>0)throw new t.JsonPatchError('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",r,e,n);if(("move"===e.op||"copy"===e.op)&&"string"!=typeof e.from)throw new t.JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",r,e,n);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&void 0===e.value)throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",r,e,n);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&o.hasUndefined(e.value))throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",r,e,n);if(n)if("add"==e.op){var p=e.path.split("/").length,u=i.split("/").length;if(p!==u+1&&p!==u)throw new t.JsonPatchError("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",r,e,n)}else if("replace"===e.op||"remove"===e.op||"_get"===e.op){if(e.path!==i)throw new t.JsonPatchError("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",r,e,n)}else if("move"===e.op||"copy"===e.op){var s=l([{op:"_get",path:e.from,value:void 0}],n);if(s&&"OPERATION_PATH_UNRESOLVABLE"===s.name)throw new t.JsonPatchError("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",r,e,n)}}function l(e,r,n){try{if(!Array.isArray(e))throw new t.JsonPatchError("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(r)s(o._deepClone(r),o._deepClone(e),n||!0);else{n=n||f;for(var a=0;a<e.length;a++)n(e[a],a,r,void 0)}}catch(e){if(e instanceof t.JsonPatchError)return e;throw e}}t.getValueByPointer=p,t.applyOperation=u,t.applyPatch=s,t.applyReducer=c,t.validator=f,t.validate=l,t.default={JsonPatchError:t.JsonPatchError,deepClone:t.deepClone,getValueByPointer:p,applyOperation:u,applyPatch:s,applyReducer:c,validator:f,validate:l}},function(e,t,r){var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0});
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017 Joachim Wester
* MIT license
*/
var o=r(0),a=r(1),i=r(1);t.applyOperation=i.applyOperation,t.applyPatch=i.applyPatch,t.applyReducer=i.applyReducer,t.getValueByPointer=i.getValueByPointer,t.validate=i.validate,t.validator=i.validator;var p=r(0);t.JsonPatchError=p.PatchError,t.deepClone=p._deepClone,t.escapePathComponent=p.escapePathComponent,t.unescapePathComponent=p.unescapePathComponent;var u=new WeakMap,s=function(e){this.observers=new Map,this.obj=e},c=function(e,t){this.callback=e,this.observer=t};function f(e,t){t.unobserve()}function l(e,t){var r,n=function(e){return u.get(e)}(e);if(n){var a=function(e,t){return e.observers.get(t)}(n,t);r=a&&a.observer}else n=new s(e),u.set(e,n);if(r)return r;if(r={},n.value=o._deepClone(e),t){r.callback=t,r.next=null;var i=function(){h(r)},p=function(){clearTimeout(r.next),r.next=setTimeout(i)};"undefined"!=typeof window&&(window.addEventListener("mouseup",p),window.addEventListener("keyup",p),window.addEventListener("mousedown",p),window.addEventListener("keydown",p),window.addEventListener("change",p))}return r.patches=[],r.object=e,r.unobserve=function(){h(r),clearTimeout(r.next),function(e,t){e.observers.delete(t.callback)}(n,r),"undefined"!=typeof window&&(window.removeEventListener("mouseup",p),window.removeEventListener("keyup",p),window.removeEventListener("mousedown",p),window.removeEventListener("keydown",p),window.removeEventListener("change",p))},n.observers.set(t,new c(t,r)),r}function h(e,t){void 0===t&&(t=!1);var r=u.get(e.object);d(r.value,e.object,e.patches,"",t),e.patches.length&&a.applyPatch(r.value,e.patches);var n=e.patches;return n.length>0&&(e.patches=[],e.callback&&e.callback(n)),n}function d(e,t,r,n,a){if(t!==e){"function"==typeof t.toJSON&&(t=t.toJSON());for(var i=o._objectKeys(t),p=o._objectKeys(e),u=!1,s=p.length-1;s>=0;s--){var c=e[l=p[s]];if(!o.hasOwnProperty(t,l)||void 0===t[l]&&void 0!==c&&!1===Array.isArray(t))Array.isArray(e)===Array.isArray(t)?(a&&r.push({op:"test",path:n+"/"+o.escapePathComponent(l),value:o._deepClone(c)}),r.push({op:"remove",path:n+"/"+o.escapePathComponent(l)}),u=!0):(a&&r.push({op:"test",path:n,value:e}),r.push({op:"replace",path:n,value:t}),!0);else{var f=t[l];"object"==typeof c&&null!=c&&"object"==typeof f&&null!=f?d(c,f,r,n+"/"+o.escapePathComponent(l),a):c!==f&&(!0,a&&r.push({op:"test",path:n+"/"+o.escapePathComponent(l),value:o._deepClone(c)}),r.push({op:"replace",path:n+"/"+o.escapePathComponent(l),value:o._deepClone(f)}))}}if(u||i.length!=p.length)for(s=0;s<i.length;s++){var l=i[s];o.hasOwnProperty(e,l)||void 0===t[l]||r.push({op:"add",path:n+"/"+o.escapePathComponent(l),value:o._deepClone(t[l])})}}}function v(e,t,r){void 0===r&&(r=!1);var n=[];return d(e,t,n,"",r),n}t.unobserve=f,t.observe=l,t.generate=h,t.compare=v;var y=r(1),w=r(0);t.default=n({},y,{unobserve:f,observe:l,generate:h,compare:v,JsonPatchError:w.PatchError,deepClone:o._deepClone,escapePathComponent:o.escapePathComponent,unescapePathComponent:w.unescapePathComponent})},function(e,t,r){"use strict";var n=Array.isArray,o=Object.keys,a=Object.prototype.hasOwnProperty;e.exports=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){var i,p,u,s=n(t),c=n(r);if(s&&c){if((p=t.length)!=r.length)return!1;for(i=p;0!=i--;)if(!e(t[i],r[i]))return!1;return!0}if(s!=c)return!1;var f=t instanceof Date,l=r instanceof Date;if(f!=l)return!1;if(f&&l)return t.getTime()==r.getTime();var h=t instanceof RegExp,d=r instanceof RegExp;if(h!=d)return!1;if(h&&d)return t.toString()==r.toString();var v=o(t);if((p=v.length)!==o(r).length)return!1;for(i=p;0!=i--;)if(!a.call(r,v[i]))return!1;for(i=p;0!=i--;)if(!e(t[u=v[i]],r[u]))return!1;return!0}return t!=t&&r!=r}}]);