json-patch-es6
Advanced tools
Comparing version 2.0.7 to 2.0.8
@@ -1,2 +0,2 @@ | ||
/*! fast-json-patch, version: 2.0.7 */ | ||
/*! fast-json-patch, version: 2.0.8 */ | ||
var jsonpatch = | ||
@@ -73,4 +73,15 @@ /******/ (function(modules) { // webpackBootstrap | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (immutable) */ __webpack_exports__["f"] = hasOwnProperty; | ||
/* harmony export (immutable) */ __webpack_exports__["e"] = _objectKeys; | ||
/* harmony export (immutable) */ __webpack_exports__["b"] = _deepClone; | ||
/* harmony export (immutable) */ __webpack_exports__["g"] = isInteger; | ||
/* harmony export (immutable) */ __webpack_exports__["c"] = escapePathComponent; | ||
/* harmony export (immutable) */ __webpack_exports__["d"] = unescapePathComponent; | ||
/* unused harmony export _getPathRecursive */ | ||
/* unused harmony export getPath */ | ||
/* harmony export (immutable) */ __webpack_exports__["h"] = hasUndefined; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return PatchError; }); | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
@@ -90,3 +101,2 @@ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
} | ||
exports.hasOwnProperty = hasOwnProperty; | ||
function _objectKeys(obj) { | ||
@@ -111,3 +121,2 @@ if (Array.isArray(obj)) { | ||
} | ||
exports._objectKeys = _objectKeys; | ||
; | ||
@@ -130,3 +139,2 @@ /** | ||
} | ||
exports._deepClone = _deepClone; | ||
//3x faster than cached /^\d+$/.test(str) | ||
@@ -147,3 +155,2 @@ function isInteger(str) { | ||
} | ||
exports.isInteger = isInteger; | ||
/** | ||
@@ -159,3 +166,2 @@ * Escapes a json pointer path | ||
} | ||
exports.escapePathComponent = escapePathComponent; | ||
/** | ||
@@ -169,3 +175,2 @@ * Unescapes a json pointer path | ||
} | ||
exports.unescapePathComponent = unescapePathComponent; | ||
function _getPathRecursive(root, obj) { | ||
@@ -188,3 +193,2 @@ var found; | ||
} | ||
exports._getPathRecursive = _getPathRecursive; | ||
function getPath(root, obj) { | ||
@@ -200,3 +204,2 @@ if (root === obj) { | ||
} | ||
exports.getPath = getPath; | ||
/** | ||
@@ -229,3 +232,2 @@ * Recursively checks whether an object has any undefined values inside. | ||
} | ||
exports.hasUndefined = hasUndefined; | ||
var PatchError = (function (_super) { | ||
@@ -243,3 +245,2 @@ __extends(PatchError, _super); | ||
}(Error)); | ||
exports.PatchError = PatchError; | ||
@@ -249,19 +250,24 @@ | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* (c) 2017 Joachim Wester | ||
* MIT license | ||
*/ | ||
// declare var require: any; | ||
var deep_equal_1 = __webpack_require__(2); | ||
"use strict"; | ||
/* unused harmony export JsonPatchError */ | ||
/* unused harmony export deepClone */ | ||
/* harmony export (immutable) */ __webpack_exports__["d"] = getValueByPointer; | ||
/* harmony export (immutable) */ __webpack_exports__["a"] = applyOperation; | ||
/* harmony export (immutable) */ __webpack_exports__["b"] = applyPatch; | ||
/* harmony export (immutable) */ __webpack_exports__["c"] = applyReducer; | ||
/* harmony export (immutable) */ __webpack_exports__["f"] = validator; | ||
/* harmony export (immutable) */ __webpack_exports__["e"] = validate; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__deep_equal__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__helpers__ = __webpack_require__(0); | ||
var equalsOptions = { strict: true }; | ||
//const _equals = require('deep-equal'); | ||
var areEquals = function (a, b) { | ||
return deep_equal_1.deepEqual(a, b, equalsOptions); | ||
return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__deep_equal__["a" /* deepEqual */])(a, b, equalsOptions); | ||
}; | ||
var helpers_1 = __webpack_require__(0); | ||
exports.JsonPatchError = helpers_1.PatchError; | ||
exports.deepClone = helpers_1._deepClone; | ||
var JsonPatchError = __WEBPACK_IMPORTED_MODULE_1__helpers__["a" /* PatchError */]; | ||
var deepClone = __WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */]; | ||
/* We use a Javascript hash to store each | ||
@@ -295,3 +301,3 @@ function. Each hash entry (property) uses | ||
if (removed) { | ||
removed = helpers_1._deepClone(removed); | ||
removed = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(removed); | ||
} | ||
@@ -305,3 +311,3 @@ var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed; | ||
// enforce copy by value so further operations don't affect source (see issue #177) | ||
applyOperation(document, { op: "add", path: this.path, value: helpers_1._deepClone(valueToCopy) }); | ||
applyOperation(document, { op: "add", path: this.path, value: __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(valueToCopy) }); | ||
return { newDocument: document }; | ||
@@ -320,3 +326,3 @@ }, | ||
add: function (arr, i, document) { | ||
if (helpers_1.isInteger(i)) { | ||
if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["g" /* isInteger */])(i)) { | ||
arr.splice(i, 0, this.value); | ||
@@ -360,3 +366,2 @@ } | ||
} | ||
exports.getValueByPointer = getValueByPointer; | ||
/** | ||
@@ -408,3 +413,3 @@ * Apply a single JSON Patch Operation on a JSON document. | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -425,3 +430,3 @@ returnValue.newDocument = document; | ||
if (validateOperation) { | ||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', 0, operation, document); | ||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', 0, operation, document); | ||
} | ||
@@ -435,3 +440,3 @@ else { | ||
if (!mutateDocument) { | ||
document = helpers_1._deepClone(document); | ||
document = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(document); | ||
} | ||
@@ -473,6 +478,6 @@ var path = operation.path || ""; | ||
else { | ||
if (validateOperation && !helpers_1.isInteger(key)) { | ||
throw new exports.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", 0, operation.path, operation); | ||
if (validateOperation && !__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["g" /* isInteger */])(key)) { | ||
throw new 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", 0, operation.path, operation); | ||
} // only parse key when it's an integer for `arr.prop` to work | ||
else if (helpers_1.isInteger(key)) { | ||
else if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["g" /* isInteger */])(key)) { | ||
key = ~~key; | ||
@@ -483,7 +488,7 @@ } | ||
if (validateOperation && operation.op === "add" && key > obj.length) { | ||
throw new exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", 0, operation.path, operation); | ||
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", 0, operation.path, operation); | ||
} | ||
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -495,3 +500,3 @@ return returnValue; | ||
if (key && key.indexOf('~') != -1) { | ||
key = helpers_1.unescapePathComponent(key); | ||
key = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["d" /* unescapePathComponent */])(key); | ||
} | ||
@@ -501,3 +506,3 @@ if (t >= len) { | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -511,3 +516,2 @@ return returnValue; | ||
} | ||
exports.applyOperation = applyOperation; | ||
/** | ||
@@ -530,7 +534,7 @@ * Apply a full JSON Patch array on a JSON document. | ||
if (!Array.isArray(patch)) { | ||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
} | ||
} | ||
if (!mutateDocument) { | ||
document = helpers_1._deepClone(document); | ||
document = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(document); | ||
} | ||
@@ -545,3 +549,2 @@ var results = new Array(patch.length); | ||
} | ||
exports.applyPatch = applyPatch; | ||
/** | ||
@@ -559,7 +562,6 @@ * Apply a single JSON Patch Operation on a JSON document. | ||
if (operationResult.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
return operationResult.newDocument; | ||
} | ||
exports.applyReducer = applyReducer; | ||
/** | ||
@@ -574,22 +576,22 @@ * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error. | ||
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) { | ||
throw new exports.JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document); | ||
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document); | ||
} | ||
else if (!objOps[operation.op]) { | ||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document); | ||
} | ||
else if (typeof operation.path !== 'string') { | ||
throw new exports.JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document); | ||
} | ||
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) { | ||
// paths that aren't empty string should start with "/" | ||
throw new exports.JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document); | ||
} | ||
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') { | ||
throw new exports.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document); | ||
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document); | ||
} | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) { | ||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document); | ||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document); | ||
} | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_1.hasUndefined(operation.value)) { | ||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document); | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["h" /* hasUndefined */])(operation.value)) { | ||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document); | ||
} | ||
@@ -601,3 +603,3 @@ else if (document) { | ||
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) { | ||
throw new exports.JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document); | ||
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document); | ||
} | ||
@@ -607,3 +609,3 @@ } | ||
if (operation.path !== existingPathFragment) { | ||
throw new exports.JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document); | ||
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document); | ||
} | ||
@@ -615,3 +617,3 @@ } | ||
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') { | ||
throw new exports.JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document); | ||
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document); | ||
} | ||
@@ -621,3 +623,2 @@ } | ||
} | ||
exports.validator = validator; | ||
/** | ||
@@ -633,7 +634,7 @@ * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document. | ||
if (!Array.isArray(sequence)) { | ||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
} | ||
if (document) { | ||
//clone document and sequence so that we can safely try applying operations | ||
applyPatch(helpers_1._deepClone(document), helpers_1._deepClone(sequence), externalValidator || true); | ||
applyPatch(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(document), __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(sequence), externalValidator || true); | ||
} | ||
@@ -648,3 +649,3 @@ else { | ||
catch (e) { | ||
if (e instanceof exports.JsonPatchError) { | ||
if (e instanceof JsonPatchError) { | ||
return e; | ||
@@ -657,3 +658,2 @@ } | ||
} | ||
exports.validate = validate; | ||
@@ -663,4 +663,6 @@ | ||
/* 2 */ | ||
/***/ (function(module, exports) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (immutable) */ __webpack_exports__["a"] = deepEqual; | ||
var pSlice = Array.prototype.slice; | ||
@@ -758,3 +760,2 @@ var objectKeys = Object.keys; | ||
} | ||
exports.deepEqual = deepEqual; | ||
; | ||
@@ -765,32 +766,35 @@ | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* (c) 2017 Joachim Wester | ||
* MIT license | ||
*/ | ||
//declare var require: any; | ||
var deep_equal_1 = __webpack_require__(2); | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony export (immutable) */ __webpack_exports__["unobserve"] = unobserve; | ||
/* harmony export (immutable) */ __webpack_exports__["observe"] = observe; | ||
/* harmony export (immutable) */ __webpack_exports__["generate"] = generate; | ||
/* harmony export (immutable) */ __webpack_exports__["compare"] = compare; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__deep_equal__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__helpers__ = __webpack_require__(0); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core__ = __webpack_require__(1); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "applyOperation", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["a"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "applyPatch", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["b"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "applyReducer", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["c"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "getValueByPointer", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["d"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "validate", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["e"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "validator", function() { return __WEBPACK_IMPORTED_MODULE_2__core__["f"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "JsonPatchError", function() { return __WEBPACK_IMPORTED_MODULE_1__helpers__["a"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "deepClone", function() { return __WEBPACK_IMPORTED_MODULE_1__helpers__["b"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "escapePathComponent", function() { return __WEBPACK_IMPORTED_MODULE_1__helpers__["c"]; }); | ||
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "unescapePathComponent", function() { return __WEBPACK_IMPORTED_MODULE_1__helpers__["d"]; }); | ||
var equalsOptions = { strict: true }; | ||
// const _equals = require('deep-equal'); | ||
var areEquals = function (a, b) { | ||
return deep_equal_1.deepEqual(a, b, equalsOptions); | ||
return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__deep_equal__["a" /* deepEqual */])(a, b, equalsOptions); | ||
}; | ||
var helpers_1 = __webpack_require__(0); | ||
var core_1 = __webpack_require__(1); | ||
/* export all core functions */ | ||
var core_2 = __webpack_require__(1); | ||
exports.applyOperation = core_2.applyOperation; | ||
exports.applyPatch = core_2.applyPatch; | ||
exports.applyReducer = core_2.applyReducer; | ||
exports.getValueByPointer = core_2.getValueByPointer; | ||
exports.validate = core_2.validate; | ||
exports.validator = core_2.validator; | ||
/* export some helpers */ | ||
var helpers_2 = __webpack_require__(0); | ||
exports.JsonPatchError = helpers_2.PatchError; | ||
exports.deepClone = helpers_2._deepClone; | ||
exports.escapePathComponent = helpers_2.escapePathComponent; | ||
exports.unescapePathComponent = helpers_2.unescapePathComponent; | ||
var beforeDict = []; | ||
@@ -839,3 +843,2 @@ var Mirror = (function () { | ||
} | ||
exports.unobserve = unobserve; | ||
/** | ||
@@ -860,3 +863,3 @@ * Observes changes made to an object, which can then be retrieved using generate | ||
observer = {}; | ||
mirror.value = helpers_1._deepClone(obj); | ||
mirror.value = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(obj); | ||
if (callback) { | ||
@@ -913,3 +916,2 @@ observer.callback = callback; | ||
} | ||
exports.observe = observe; | ||
/** | ||
@@ -928,3 +930,3 @@ * Generate an array of patches from an observer | ||
if (observer.patches.length) { | ||
core_1.applyPatch(mirror.value, observer.patches); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__core__["b" /* applyPatch */])(mirror.value, observer.patches); | ||
} | ||
@@ -940,3 +942,2 @@ var temp = observer.patches; | ||
} | ||
exports.generate = generate; | ||
// Dirty check if obj is different from mirror, generate patches and update mirror | ||
@@ -950,4 +951,4 @@ function _generate(mirror, obj, patches, path) { | ||
} | ||
var newKeys = helpers_1._objectKeys(obj); | ||
var oldKeys = helpers_1._objectKeys(mirror); | ||
var newKeys = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["e" /* _objectKeys */])(obj); | ||
var oldKeys = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["e" /* _objectKeys */])(mirror); | ||
var changed = false; | ||
@@ -959,6 +960,6 @@ var deleted = false; | ||
var oldVal = mirror[key]; | ||
if (helpers_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { | ||
if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["f" /* hasOwnProperty */])(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { | ||
var newVal = obj[key]; | ||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { | ||
_generate(oldVal, newVal, patches, path + "/" + helpers_1.escapePathComponent(key)); | ||
_generate(oldVal, newVal, patches, path + "/" + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["c" /* escapePathComponent */])(key)); | ||
} | ||
@@ -968,3 +969,3 @@ else { | ||
changed = true; | ||
patches.push({ op: "replace", path: path + "/" + helpers_1.escapePathComponent(key), value: helpers_1._deepClone(newVal) }); | ||
patches.push({ op: "replace", path: path + "/" + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["c" /* escapePathComponent */])(key), value: __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(newVal) }); | ||
} | ||
@@ -974,3 +975,3 @@ } | ||
else { | ||
patches.push({ op: "remove", path: path + "/" + helpers_1.escapePathComponent(key) }); | ||
patches.push({ op: "remove", path: path + "/" + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["c" /* escapePathComponent */])(key) }); | ||
deleted = true; // property has been deleted | ||
@@ -984,4 +985,4 @@ } | ||
var key = newKeys[t]; | ||
if (!helpers_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) { | ||
patches.push({ op: "add", path: path + "/" + helpers_1.escapePathComponent(key), value: helpers_1._deepClone(obj[key]) }); | ||
if (!__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["f" /* hasOwnProperty */])(mirror, key) && obj[key] !== undefined) { | ||
patches.push({ op: "add", path: path + "/" + __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["c" /* escapePathComponent */])(key), value: __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__helpers__["b" /* _deepClone */])(obj[key]) }); | ||
} | ||
@@ -998,3 +999,2 @@ } | ||
} | ||
exports.compare = compare; | ||
@@ -1001,0 +1001,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! fast-json-patch, version: 2.0.7 */ | ||
var jsonpatch=function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.i=function(a){return a},b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=3)}([function(a,b){function c(a,b){return i.call(a,b)}function d(a){if(Array.isArray(a)){for(var b=Array(a.length),d=0;d<b.length;d++)b[d]=''+d;return b}if(Object.keys)return Object.keys(a);var b=[];for(var e in a)c(a,e)&&b.push(e);return b}function e(a){return-1===a.indexOf('/')&&-1===a.indexOf('~')?a:a.replace(/~/g,'~0').replace(/\//g,'~1')}function f(a,b){var d;for(var g in a)if(c(a,g)){if(a[g]===b)return e(g)+'/';if('object'==typeof a[g]&&(d=f(a[g],b),''!=d))return e(g)+'/'+d}return''}function g(a){if(a===void 0)return!0;if(a)if(Array.isArray(a)){for(var b=0,c=a.length;b<c;b++)if(g(a[b]))return!0;}else if('object'==typeof a)for(var e=d(a),f=e.length,b=0;b<f;b++)if(g(a[e[b]]))return!0;return!1}var h=this&&this.__extends||function(a,c){function b(){this.constructor=a}for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);a.prototype=null===c?Object.create(c):(b.prototype=c.prototype,new b)},i=Object.prototype.hasOwnProperty;b.hasOwnProperty=c,b._objectKeys=d;b._deepClone=function(a){switch(typeof a){case'object':return JSON.parse(JSON.stringify(a));case'undefined':return null;default:return a;}},b.isInteger=function(a){for(var b,c=0,d=a.length;c<d;){if(b=a.charCodeAt(c),48<=b&&57>=b){c++;continue}return!1}return!0},b.escapePathComponent=e,b.unescapePathComponent=function(a){return a.replace(/~1/g,'/').replace(/~0/g,'~')},b._getPathRecursive=f,b.getPath=function(a,b){if(a===b)return'/';var c=f(a,b);if(''===c)throw new Error('Object not found in root');return'/'+c},b.hasUndefined=g;var j=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 h(b,a),b}(Error);b.PatchError=j},function(a,b,c){function d(a,b){if(''==b)return a;var c={op:'_get',path:b};return e(a,c),c.value}function e(a,c,e,f){if(void 0===e&&(e=!1),void 0===f&&(f=!0),e&&('function'==typeof e?e(c,0,a,c.path):g(c,0)),''===c.path){var h={newDocument:a};if('add'===c.op)return h.newDocument=c.value,h;if('replace'===c.op)return h.newDocument=c.value,h.removed=a,h;if('move'===c.op||'copy'===c.op)return h.newDocument=d(a,c.from),'move'===c.op&&(h.removed=a),h;if('test'===c.op){if(h.test=k(a,c.value),!1===h.test)throw new b.JsonPatchError('Test operation failed','TEST_OPERATION_FAILED',0,c,a);return h.newDocument=a,h}if('remove'===c.op)return h.removed=a,h.newDocument=null,h;if('_get'===c.op)return c.value=a,h;if(e)throw new b.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902','OPERATION_OP_INVALID',0,c,a);else return h}else{f||(a=l._deepClone(a));var i,j,o,p=c.path||'',q=p.split('/'),r=a,s=1,t=q.length;for(o='function'==typeof e?e:g;;){if(j=q[s],e&&void 0==i&&(void 0===r[j]?i=q.slice(0,s).join('/'):s==t-1&&(i=c.path),void 0!==i&&o(c,0,a,i)),s++,Array.isArray(r)){if('-'===j)j=r.length;else if(e&&!l.isInteger(j))throw new b.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',0,c.path,c);else l.isInteger(j)&&(j=~~j);if(s>=t){if(e&&'add'===c.op&&j>r.length)throw new b.JsonPatchError('The specified index MUST NOT be greater than the number of elements in the array','OPERATION_VALUE_OUT_OF_BOUNDS',0,c.path,c);var h=n[c.op].call(c,r,j,a);if(!1===h.test)throw new b.JsonPatchError('Test operation failed','TEST_OPERATION_FAILED',0,c,a);return h}}else if(j&&-1!=j.indexOf('~')&&(j=l.unescapePathComponent(j)),s>=t){var h=m[c.op].call(c,r,j,a);if(!1===h.test)throw new b.JsonPatchError('Test operation failed','TEST_OPERATION_FAILED',0,c,a);return h}r=r[j]}}}function f(a,c,d,f){if(void 0===f&&(f=!0),d&&!Array.isArray(c))throw new b.JsonPatchError('Patch sequence must be an array','SEQUENCE_NOT_AN_ARRAY');f||(a=l._deepClone(a));for(var g=Array(c.length),h=0,i=c.length;h<i;h++)g[h]=e(a,c[h],d),a=g[h].newDocument;return g.newDocument=a,g}function g(a,c,d,e){if('object'!=typeof a||null===a||Array.isArray(a))throw new b.JsonPatchError('Operation is not an object','OPERATION_NOT_AN_OBJECT',c,a,d);else if(!m[a.op])throw new b.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902','OPERATION_OP_INVALID',c,a,d);else if('string'!=typeof a.path)throw new b.JsonPatchError('Operation `path` property is not a string','OPERATION_PATH_INVALID',c,a,d);else if(0!==a.path.indexOf('/')&&0<a.path.length)throw new b.JsonPatchError('Operation `path` property must start with "/"','OPERATION_PATH_INVALID',c,a,d);else if(('move'===a.op||'copy'===a.op)&&'string'!=typeof a.from)throw new b.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)','OPERATION_FROM_REQUIRED',c,a,d);else if(('add'===a.op||'replace'===a.op||'test'===a.op)&&a.value===void 0)throw new b.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)','OPERATION_VALUE_REQUIRED',c,a,d);else if(('add'===a.op||'replace'===a.op||'test'===a.op)&&l.hasUndefined(a.value))throw new b.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)','OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED',c,a,d);else if(d)if('add'==a.op){var f=a.path.split('/').length,g=e.split('/').length;if(f!==g+1&&f!==g)throw new b.JsonPatchError('Cannot perform an `add` operation at the desired path','OPERATION_PATH_CANNOT_ADD',c,a,d)}else if('replace'===a.op||'remove'===a.op||'_get'===a.op){if(a.path!==e)throw new b.JsonPatchError('Cannot perform the operation at a path that does not exist','OPERATION_PATH_UNRESOLVABLE',c,a,d);}else if('move'===a.op||'copy'===a.op){var i={op:'_get',path:a.from,value:void 0},j=h([i],d);if(j&&'OPERATION_PATH_UNRESOLVABLE'===j.name)throw new b.JsonPatchError('Cannot perform the operation from a path that does not exist','OPERATION_FROM_UNRESOLVABLE',c,a,d)}}function h(a,c,d){try{if(!Array.isArray(a))throw new b.JsonPatchError('Patch sequence must be an array','SEQUENCE_NOT_AN_ARRAY');if(c)f(l._deepClone(c),l._deepClone(a),d||!0);else{d=d||g;for(var e=0;e<a.length;e++)d(a[e],e,c,void 0)}}catch(a){if(a instanceof b.JsonPatchError)return a;throw a}}var i=c(2),j={strict:!0},k=function(c,a){return i.deepEqual(c,a,j)},l=c(0);b.JsonPatchError=l.PatchError,b.deepClone=l._deepClone;var m={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,c){var f=d(c,this.path);f&&(f=l._deepClone(f));var g=e(c,{op:'remove',path:this.from}).removed;return e(c,{op:'add',path:this.path,value:g}),{newDocument:c,removed:f}},copy:function(a,b,c){var f=d(c,this.from);return e(c,{op:'add',path:this.path,value:l._deepClone(f)}),{newDocument:c}},test:function(a,b,c){return{newDocument:c,test:k(a[b],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},n={add:function(a,b,c){return l.isInteger(b)?a.splice(b,0,this.value):a[b]=this.value,{newDocument:c,index:b}},remove:function(a,b,c){var d=a.splice(b,1);return{newDocument:c,removed:d[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:m.move,copy:m.copy,test:m.test,_get:m._get};b.getValueByPointer=d,b.applyOperation=e,b.applyPatch=f,b.applyReducer=function(a,c){var d=e(a,c);if(!1===d.test)throw new b.JsonPatchError('Test operation failed','TEST_OPERATION_FAILED',0,c,a);return d.newDocument},b.validator=g,b.validate=h},function(a,b){function c(a){return'[object Arguments]'==Object.prototype.toString.call(a)}function d(a){return null===a||a===void 0}function e(a){return a&&'object'==typeof a&&'number'==typeof a.length&&('function'!=typeof a.copy||'function'!=typeof a.slice?!1:0<a.length&&'number'!=typeof a[0]?!1:!0)}function f(f,j,k){var l,m;if(d(f)||d(j))return!1;if(f.prototype!==j.prototype)return!1;if(c(f))return!!c(j)&&(f=h.call(f),j=h.call(j),g(f,j,k));if(e(f)){if(!e(j))return!1;if(f.length!==j.length)return!1;for(l=0;l<f.length;l++)if(f[l]!==j[l])return!1;return!0}try{var n=i(f),o=i(j)}catch(a){return!1}if(n.length!=o.length)return!1;for(n.sort(),o.sort(),l=n.length-1;0<=l;l--)if(n[l]!=o[l])return!1;for(l=n.length-1;0<=l;l--)if(m=n[l],!g(f[m],j[m],k))return!1;return typeof f==typeof j}function g(a,b,c){return c||(c={}),a===b||(a instanceof Date&&b instanceof Date?a.getTime()===b.getTime():a&&b&&('object'==typeof a||'object'==typeof b)?f(a,b,c):c.strict?a===b:a==b)}var h=Array.prototype.slice,i=Object.keys;b.deepEqual=g},function(a,b,c){function d(a){for(var b=0,c=o.length;b<c;b++)if(o[b].obj===a)return o[b]}function e(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function f(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function g(a){for(var b,c=0,d=o.length;c<d;c++)if(o[c].obj===a.object){b=o[c];break}h(b.value,a.object,a.patches,''),a.patches.length&&l.applyPatch(b.value,a.patches);var e=a.patches;return 0<e.length&&(a.patches=[],a.callback&&a.callback(e)),e}function h(a,b,c,d){if(b!==a){'function'==typeof b.toJSON&&(b=b.toJSON());for(var e=k._objectKeys(b),f=k._objectKeys(a),g=!1,i=!1,j=f.length-1;0<=j;j--){var l=f[j],m=a[l];if(k.hasOwnProperty(b,l)&&(void 0!==b[l]||void 0===m||!1!==Array.isArray(b))){var n=b[l];'object'==typeof m&&null!=m&&'object'==typeof n&&null!=n?h(m,n,c,d+'/'+k.escapePathComponent(l)):m!==n&&(g=!0,c.push({op:'replace',path:d+'/'+k.escapePathComponent(l),value:k._deepClone(n)}))}else c.push({op:'remove',path:d+'/'+k.escapePathComponent(l)}),i=!0}if(i||e.length!=f.length)for(var l,j=0;j<e.length;j++)l=e[j],k.hasOwnProperty(a,l)||void 0===b[l]||c.push({op:'add',path:d+'/'+k.escapePathComponent(l),value:k._deepClone(b[l])})}}var i=c(2),j={strict:!0},k=c(0),l=c(1),m=c(1);b.applyOperation=m.applyOperation,b.applyPatch=m.applyPatch,b.applyReducer=m.applyReducer,b.getValueByPointer=m.getValueByPointer,b.validate=m.validate,b.validator=m.validator;var n=c(0);b.JsonPatchError=n.PatchError,b.deepClone=n._deepClone,b.escapePathComponent=n.escapePathComponent,b.unescapePathComponent=n.unescapePathComponent;var o=[],p=function(){return function(a){this.observers=[],this.obj=a}}(),q=function(){return function(a,b){this.callback=a,this.observer=b}}();b.unobserve=function(a,b){b.unobserve()},b.observe=function(a,b){var c,h=d(a);if(h?c=e(h,b):(h=new p(a),o.push(h)),c)return c;if(c={},h.value=k._deepClone(a),b){c.callback=b,c.next=null;var i=function(){g(c)},j=function(){clearTimeout(c.next),c.next=setTimeout(i)};'undefined'!=typeof window&&(window.addEventListener?(window.addEventListener('mouseup',j),window.addEventListener('keyup',j),window.addEventListener('mousedown',j),window.addEventListener('keydown',j),window.addEventListener('change',j)):(document.documentElement.attachEvent('onmouseup',j),document.documentElement.attachEvent('onkeyup',j),document.documentElement.attachEvent('onmousedown',j),document.documentElement.attachEvent('onkeydown',j),document.documentElement.attachEvent('onchange',j)))}return c.patches=[],c.object=a,c.unobserve=function(){g(c),clearTimeout(c.next),f(h,c),'undefined'!=typeof window&&(window.removeEventListener?(window.removeEventListener('mouseup',j),window.removeEventListener('keyup',j),window.removeEventListener('mousedown',j),window.removeEventListener('keydown',j)):(document.documentElement.detachEvent('onmouseup',j),document.documentElement.detachEvent('onkeyup',j),document.documentElement.detachEvent('onmousedown',j),document.documentElement.detachEvent('onkeydown',j)))},h.observers.push(new q(b,c)),c},b.generate=g,b.compare=function(a,b){var c=[];return h(a,b,c,''),c}}]); | ||
/*! fast-json-patch, version: 2.0.8 */ | ||
var jsonpatch=function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.i=function(a){return a},b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=3)}([function(a,b,c){'use strict';function d(a,b){return h.call(a,b)}function e(a){if(Array.isArray(a)){for(var b=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 e in a)d(a,e)&&b.push(e);return b}function f(a){if(a===void 0)return!0;if(a)if(Array.isArray(a)){for(var b=0,c=a.length;b<c;b++)if(f(a[b]))return!0;}else if('object'==typeof a)for(var d=e(a),g=d.length,b=0;b<g;b++)if(f(a[d[b]]))return!0;return!1}b.f=d,b.e=e,b.b=function(a){switch(typeof a){case'object':return JSON.parse(JSON.stringify(a));case'undefined':return null;default:return a;}},b.g=function(a){for(var b,c=0,d=a.length;c<d;){if(b=a.charCodeAt(c),48<=b&&57>=b){c++;continue}return!1}return!0},b.c=function(a){return-1===a.indexOf('/')&&-1===a.indexOf('~')?a:a.replace(/~/g,'~0').replace(/\//g,'~1')},b.d=function(a){return a.replace(/~1/g,'/').replace(/~0/g,'~')},b.h=f,c.d(b,'a',function(){return i});var g=this&&this.__extends||function(a,c){function b(){this.constructor=a}for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);a.prototype=null===c?Object.create(c):(b.prototype=c.prototype,new b)},h=Object.prototype.hasOwnProperty;var i=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 g(b,a),b}(Error)},function(a,b,c){'use strict';function d(a,b){if(''==b)return a;var c={op:'_get',path:b};return e(a,c),c.value}function e(a,b,e,f){if(void 0===e&&(e=!1),void 0===f&&(f=!0),e&&('function'==typeof e?e(b,0,a,b.path):g(b,0)),''===b.path){var h={newDocument:a};if('add'===b.op)return h.newDocument=b.value,h;if('replace'===b.op)return h.newDocument=b.value,h.removed=a,h;if('move'===b.op||'copy'===b.op)return h.newDocument=d(a,b.from),'move'===b.op&&(h.removed=a),h;if('test'===b.op){if(h.test=l(a,b.value),!1===h.test)throw new m('Test operation failed','TEST_OPERATION_FAILED',0,b,a);return h.newDocument=a,h}if('remove'===b.op)return h.removed=a,h.newDocument=null,h;if('_get'===b.op)return b.value=a,h;if(e)throw new m('Operation `op` property is not one of operations defined in RFC-6902','OPERATION_OP_INVALID',0,b,a);else return h}else{f||(a=c.i(j.b)(a));var i,k,n,q=b.path||'',r=q.split('/'),s=a,u=1,t=r.length;for(n='function'==typeof e?e:g;;){if(k=r[u],e&&void 0==i&&(void 0===s[k]?i=r.slice(0,u).join('/'):u==t-1&&(i=b.path),void 0!==i&&n(b,0,a,i)),u++,Array.isArray(s)){if('-'===k)k=s.length;else if(e&&!c.i(j.g)(k))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',0,b.path,b);else c.i(j.g)(k)&&(k=~~k);if(u>=t){if(e&&'add'===b.op&&k>s.length)throw new m('The specified index MUST NOT be greater than the number of elements in the array','OPERATION_VALUE_OUT_OF_BOUNDS',0,b.path,b);var h=p[b.op].call(b,s,k,a);if(!1===h.test)throw new m('Test operation failed','TEST_OPERATION_FAILED',0,b,a);return h}}else if(k&&-1!=k.indexOf('~')&&(k=c.i(j.d)(k)),u>=t){var h=o[b.op].call(b,s,k,a);if(!1===h.test)throw new m('Test operation failed','TEST_OPERATION_FAILED',0,b,a);return h}s=s[k]}}}function f(a,b,d,f){if(void 0===f&&(f=!0),d&&!Array.isArray(b))throw new m('Patch sequence must be an array','SEQUENCE_NOT_AN_ARRAY');f||(a=c.i(j.b)(a));for(var g=Array(b.length),h=0,i=b.length;h<i;h++)g[h]=e(a,b[h],d),a=g[h].newDocument;return g.newDocument=a,g}function g(a,b,d,e){if('object'!=typeof a||null===a||Array.isArray(a))throw new m('Operation is not an object','OPERATION_NOT_AN_OBJECT',b,a,d);else if(!o[a.op])throw new m('Operation `op` property is not one of operations defined in RFC-6902','OPERATION_OP_INVALID',b,a,d);else if('string'!=typeof a.path)throw new m('Operation `path` property is not a string','OPERATION_PATH_INVALID',b,a,d);else if(0!==a.path.indexOf('/')&&0<a.path.length)throw new m('Operation `path` property must start with "/"','OPERATION_PATH_INVALID',b,a,d);else if(('move'===a.op||'copy'===a.op)&&'string'!=typeof a.from)throw new m('Operation `from` property is not present (applicable in `move` and `copy` operations)','OPERATION_FROM_REQUIRED',b,a,d);else if(('add'===a.op||'replace'===a.op||'test'===a.op)&&a.value===void 0)throw new m('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)','OPERATION_VALUE_REQUIRED',b,a,d);else if(('add'===a.op||'replace'===a.op||'test'===a.op)&&c.i(j.h)(a.value))throw new m('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)','OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED',b,a,d);else if(d)if('add'==a.op){var f=a.path.split('/').length,g=e.split('/').length;if(f!==g+1&&f!==g)throw new m('Cannot perform an `add` operation at the desired path','OPERATION_PATH_CANNOT_ADD',b,a,d)}else if('replace'===a.op||'remove'===a.op||'_get'===a.op){if(a.path!==e)throw new m('Cannot perform the operation at a path that does not exist','OPERATION_PATH_UNRESOLVABLE',b,a,d);}else if('move'===a.op||'copy'===a.op){var i={op:'_get',path:a.from,value:void 0},k=h([i],d);if(k&&'OPERATION_PATH_UNRESOLVABLE'===k.name)throw new m('Cannot perform the operation from a path that does not exist','OPERATION_FROM_UNRESOLVABLE',b,a,d)}}function h(a,b,d){try{if(!Array.isArray(a))throw new m('Patch sequence must be an array','SEQUENCE_NOT_AN_ARRAY');if(b)f(c.i(j.b)(b),c.i(j.b)(a),d||!0);else{d=d||g;for(var e=0;e<a.length;e++)d(a[e],e,b,void 0)}}catch(a){if(a instanceof m)return a;throw a}}b.d=d,b.a=e,b.b=f,b.c=function(a,b){var c=e(a,b);if(!1===c.test)throw new m('Test operation failed','TEST_OPERATION_FAILED',0,b,a);return c.newDocument},b.f=g,b.e=h;var i=c(2),j=c(0),k={strict:!0},l=function(d,a){return c.i(i.a)(d,a,k)},m=j.a,n=j.b,o={add:function(a,b,c){return a[b]=this.value,{newDocument:c}},remove:function(a,b,c){var d=a[b];return delete a[b],{newDocument:c,removed:d}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:function(a,b,f){var g=d(f,this.path);g&&(g=c.i(j.b)(g));var h=e(f,{op:'remove',path:this.from}).removed;return e(f,{op:'add',path:this.path,value:h}),{newDocument:f,removed:g}},copy:function(a,b,f){var g=d(f,this.from);return e(f,{op:'add',path:this.path,value:c.i(j.b)(g)}),{newDocument:f}},test:function(a,b,c){return{newDocument:c,test:l(a[b],this.value)}},_get:function(a,b,c){return this.value=a[b],{newDocument:c}}},p={add:function(a,b,d){return c.i(j.g)(b)?a.splice(b,0,this.value):a[b]=this.value,{newDocument:d,index:b}},remove:function(a,b,c){var d=a.splice(b,1);return{newDocument:c,removed:d[0]}},replace:function(a,b,c){var d=a[b];return a[b]=this.value,{newDocument:c,removed:d}},move:o.move,copy:o.copy,test:o.test,_get:o._get}},function(a,b){'use strict';function c(a){return'[object Arguments]'==Object.prototype.toString.call(a)}function d(a){return null===a||a===void 0}function e(a){return a&&'object'==typeof a&&'number'==typeof a.length&&('function'!=typeof a.copy||'function'!=typeof a.slice?!1:0<a.length&&'number'!=typeof a[0]?!1:!0)}function f(f,j,k){var l,m;if(d(f)||d(j))return!1;if(f.prototype!==j.prototype)return!1;if(c(f))return!!c(j)&&(f=h.call(f),j=h.call(j),g(f,j,k));if(e(f)){if(!e(j))return!1;if(f.length!==j.length)return!1;for(l=0;l<f.length;l++)if(f[l]!==j[l])return!1;return!0}try{var n=i(f),o=i(j)}catch(a){return!1}if(n.length!=o.length)return!1;for(n.sort(),o.sort(),l=n.length-1;0<=l;l--)if(n[l]!=o[l])return!1;for(l=n.length-1;0<=l;l--)if(m=n[l],!g(f[m],j[m],k))return!1;return typeof f==typeof j}function g(a,b,c){return c||(c={}),a===b||(a instanceof Date&&b instanceof Date?a.getTime()===b.getTime():a&&b&&('object'==typeof a||'object'==typeof b)?f(a,b,c):c.strict?a===b:a==b)}b.a=g;var h=Array.prototype.slice,i=Object.keys},function(a,b,c){'use strict';function d(a){for(var b=0,c=m.length;b<c;b++)if(m[b].obj===a)return m[b]}function e(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].callback===b)return a.observers[c].observer}function f(a,b){for(var c=0,d=a.observers.length;c<d;c++)if(a.observers[c].observer===b)return void a.observers.splice(c,1)}function g(a){for(var b,d=0,e=m.length;d<e;d++)if(m[d].obj===a.object){b=m[d];break}h(b.value,a.object,a.patches,''),a.patches.length&&c.i(k.b)(b.value,a.patches);var f=a.patches;return 0<f.length&&(a.patches=[],a.callback&&a.callback(f)),f}function h(a,b,d,e){if(b!==a){'function'==typeof b.toJSON&&(b=b.toJSON());for(var f=c.i(j.e)(b),g=c.i(j.e)(a),i=!1,k=!1,l=g.length-1;0<=l;l--){var m=g[l],n=a[m];if(c.i(j.f)(b,m)&&(void 0!==b[m]||void 0===n||!1!==Array.isArray(b))){var o=b[m];'object'==typeof n&&null!=n&&'object'==typeof o&&null!=o?h(n,o,d,e+'/'+c.i(j.c)(m)):n!==o&&(i=!0,d.push({op:'replace',path:e+'/'+c.i(j.c)(m),value:c.i(j.b)(o)}))}else d.push({op:'remove',path:e+'/'+c.i(j.c)(m)}),k=!0}if(k||f.length!=g.length)for(var m,l=0;l<f.length;l++)m=f[l],c.i(j.f)(a,m)||void 0===b[m]||d.push({op:'add',path:e+'/'+c.i(j.c)(m),value:c.i(j.b)(b[m])})}}Object.defineProperty(b,'__esModule',{value:!0}),b.unobserve=function(a,b){b.unobserve()},b.observe=function(a,b){var h,i=d(a);if(i?h=e(i,b):(i=new n(a),m.push(i)),h)return h;if(h={},i.value=c.i(j.b)(a),b){h.callback=b,h.next=null;var k=function(){g(h)},l=function(){clearTimeout(h.next),h.next=setTimeout(k)};'undefined'!=typeof window&&(window.addEventListener?(window.addEventListener('mouseup',l),window.addEventListener('keyup',l),window.addEventListener('mousedown',l),window.addEventListener('keydown',l),window.addEventListener('change',l)):(document.documentElement.attachEvent('onmouseup',l),document.documentElement.attachEvent('onkeyup',l),document.documentElement.attachEvent('onmousedown',l),document.documentElement.attachEvent('onkeydown',l),document.documentElement.attachEvent('onchange',l)))}return h.patches=[],h.object=a,h.unobserve=function(){g(h),clearTimeout(h.next),f(i,h),'undefined'!=typeof window&&(window.removeEventListener?(window.removeEventListener('mouseup',l),window.removeEventListener('keyup',l),window.removeEventListener('mousedown',l),window.removeEventListener('keydown',l)):(document.documentElement.detachEvent('onmouseup',l),document.documentElement.detachEvent('onkeyup',l),document.documentElement.detachEvent('onmousedown',l),document.documentElement.detachEvent('onkeydown',l)))},i.observers.push(new o(b,h)),h},b.generate=g,b.compare=function(a,b){var c=[];return h(a,b,c,''),c};var i=c(2),j=c(0),k=c(1);c.d(b,'applyOperation',function(){return k.a}),c.d(b,'applyPatch',function(){return k.b}),c.d(b,'applyReducer',function(){return k.c}),c.d(b,'getValueByPointer',function(){return k.d}),c.d(b,'validate',function(){return k.e}),c.d(b,'validator',function(){return k.f}),c.d(b,'JsonPatchError',function(){return j.a}),c.d(b,'deepClone',function(){return j.b}),c.d(b,'escapePathComponent',function(){return j.c}),c.d(b,'unescapePathComponent',function(){return j.d});var l={strict:!0},m=[],n=function(){return function(a){this.observers=[],this.obj=a}}(),o=function(){return function(a,b){this.callback=a,this.observer=b}}()}]); |
@@ -1,16 +0,10 @@ | ||
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* (c) 2017 Joachim Wester | ||
* MIT license | ||
*/ | ||
// declare var require: any; | ||
var deep_equal_1 = require('./deep-equal'); | ||
import { deepEqual as _equals } from './deep-equal'; | ||
var equalsOptions = { strict: true }; | ||
//const _equals = require('deep-equal'); | ||
var areEquals = function (a, b) { | ||
return deep_equal_1.deepEqual(a, b, equalsOptions); | ||
return _equals(a, b, equalsOptions); | ||
}; | ||
var helpers_1 = require('./helpers'); | ||
exports.JsonPatchError = helpers_1.PatchError; | ||
exports.deepClone = helpers_1._deepClone; | ||
import { PatchError, _deepClone, isInteger, unescapePathComponent, hasUndefined } from './helpers'; | ||
export var JsonPatchError = PatchError; | ||
export var deepClone = _deepClone; | ||
/* We use a Javascript hash to store each | ||
@@ -44,3 +38,3 @@ function. Each hash entry (property) uses | ||
if (removed) { | ||
removed = helpers_1._deepClone(removed); | ||
removed = _deepClone(removed); | ||
} | ||
@@ -54,3 +48,3 @@ var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed; | ||
// enforce copy by value so further operations don't affect source (see issue #177) | ||
applyOperation(document, { op: "add", path: this.path, value: helpers_1._deepClone(valueToCopy) }); | ||
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) }); | ||
return { newDocument: document }; | ||
@@ -69,3 +63,3 @@ }, | ||
add: function (arr, i, document) { | ||
if (helpers_1.isInteger(i)) { | ||
if (isInteger(i)) { | ||
arr.splice(i, 0, this.value); | ||
@@ -101,3 +95,3 @@ } | ||
*/ | ||
function getValueByPointer(document, pointer) { | ||
export function getValueByPointer(document, pointer) { | ||
if (pointer == '') { | ||
@@ -110,3 +104,2 @@ return document; | ||
} | ||
exports.getValueByPointer = getValueByPointer; | ||
/** | ||
@@ -125,3 +118,3 @@ * Apply a single JSON Patch Operation on a JSON document. | ||
*/ | ||
function applyOperation(document, operation, validateOperation, mutateDocument) { | ||
export function applyOperation(document, operation, validateOperation, mutateDocument) { | ||
if (validateOperation === void 0) { validateOperation = false; } | ||
@@ -159,3 +152,3 @@ if (mutateDocument === void 0) { mutateDocument = true; } | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -176,3 +169,3 @@ returnValue.newDocument = document; | ||
if (validateOperation) { | ||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', 0, operation, document); | ||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', 0, operation, document); | ||
} | ||
@@ -186,3 +179,3 @@ else { | ||
if (!mutateDocument) { | ||
document = helpers_1._deepClone(document); | ||
document = _deepClone(document); | ||
} | ||
@@ -224,6 +217,6 @@ var path = operation.path || ""; | ||
else { | ||
if (validateOperation && !helpers_1.isInteger(key)) { | ||
throw new exports.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", 0, operation.path, operation); | ||
if (validateOperation && !isInteger(key)) { | ||
throw new 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", 0, operation.path, operation); | ||
} // only parse key when it's an integer for `arr.prop` to work | ||
else if (helpers_1.isInteger(key)) { | ||
else if (isInteger(key)) { | ||
key = ~~key; | ||
@@ -234,7 +227,7 @@ } | ||
if (validateOperation && operation.op === "add" && key > obj.length) { | ||
throw new exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", 0, operation.path, operation); | ||
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", 0, operation.path, operation); | ||
} | ||
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -246,3 +239,3 @@ return returnValue; | ||
if (key && key.indexOf('~') != -1) { | ||
key = helpers_1.unescapePathComponent(key); | ||
key = unescapePathComponent(key); | ||
} | ||
@@ -252,3 +245,3 @@ if (t >= len) { | ||
if (returnValue.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
@@ -262,3 +255,2 @@ return returnValue; | ||
} | ||
exports.applyOperation = applyOperation; | ||
/** | ||
@@ -277,11 +269,11 @@ * Apply a full JSON Patch array on a JSON document. | ||
*/ | ||
function applyPatch(document, patch, validateOperation, mutateDocument) { | ||
export function applyPatch(document, patch, validateOperation, mutateDocument) { | ||
if (mutateDocument === void 0) { mutateDocument = true; } | ||
if (validateOperation) { | ||
if (!Array.isArray(patch)) { | ||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
} | ||
} | ||
if (!mutateDocument) { | ||
document = helpers_1._deepClone(document); | ||
document = _deepClone(document); | ||
} | ||
@@ -296,3 +288,2 @@ var results = new Array(patch.length); | ||
} | ||
exports.applyPatch = applyPatch; | ||
/** | ||
@@ -307,10 +298,9 @@ * Apply a single JSON Patch Operation on a JSON document. | ||
*/ | ||
function applyReducer(document, operation) { | ||
export function applyReducer(document, operation) { | ||
var operationResult = applyOperation(document, operation); | ||
if (operationResult.test === false) { | ||
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document); | ||
} | ||
return operationResult.newDocument; | ||
} | ||
exports.applyReducer = applyReducer; | ||
/** | ||
@@ -323,24 +313,24 @@ * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error. | ||
*/ | ||
function validator(operation, index, document, existingPathFragment) { | ||
export function validator(operation, index, document, existingPathFragment) { | ||
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) { | ||
throw new exports.JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document); | ||
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document); | ||
} | ||
else if (!objOps[operation.op]) { | ||
throw new exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document); | ||
} | ||
else if (typeof operation.path !== 'string') { | ||
throw new exports.JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document); | ||
} | ||
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) { | ||
// paths that aren't empty string should start with "/" | ||
throw new exports.JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document); | ||
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document); | ||
} | ||
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') { | ||
throw new exports.JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document); | ||
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document); | ||
} | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) { | ||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document); | ||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document); | ||
} | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && helpers_1.hasUndefined(operation.value)) { | ||
throw new exports.JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document); | ||
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) { | ||
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document); | ||
} | ||
@@ -352,3 +342,3 @@ else if (document) { | ||
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) { | ||
throw new exports.JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document); | ||
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document); | ||
} | ||
@@ -358,3 +348,3 @@ } | ||
if (operation.path !== existingPathFragment) { | ||
throw new exports.JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document); | ||
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document); | ||
} | ||
@@ -366,3 +356,3 @@ } | ||
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') { | ||
throw new exports.JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document); | ||
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document); | ||
} | ||
@@ -372,3 +362,2 @@ } | ||
} | ||
exports.validator = validator; | ||
/** | ||
@@ -381,10 +370,10 @@ * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document. | ||
*/ | ||
function validate(sequence, document, externalValidator) { | ||
export function validate(sequence, document, externalValidator) { | ||
try { | ||
if (!Array.isArray(sequence)) { | ||
throw new exports.JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); | ||
} | ||
if (document) { | ||
//clone document and sequence so that we can safely try applying operations | ||
applyPatch(helpers_1._deepClone(document), helpers_1._deepClone(sequence), externalValidator || true); | ||
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true); | ||
} | ||
@@ -399,3 +388,3 @@ else { | ||
catch (e) { | ||
if (e instanceof exports.JsonPatchError) { | ||
if (e instanceof JsonPatchError) { | ||
return e; | ||
@@ -408,2 +397,1 @@ } | ||
} | ||
exports.validate = validate; |
@@ -76,3 +76,3 @@ var pSlice = Array.prototype.slice; | ||
} | ||
function deepEqual(actual, expected, opts) { | ||
export function deepEqual(actual, expected, opts) { | ||
if (!opts) | ||
@@ -94,3 +94,2 @@ opts = {}; | ||
} | ||
exports.deepEqual = deepEqual; | ||
; |
@@ -1,29 +0,13 @@ | ||
/*! | ||
* https://github.com/Starcounter-Jack/JSON-Patch | ||
* (c) 2017 Joachim Wester | ||
* MIT license | ||
*/ | ||
//declare var require: any; | ||
var deep_equal_1 = require('./deep-equal'); | ||
import { deepEqual as _equals } from './deep-equal'; | ||
var equalsOptions = { strict: true }; | ||
// const _equals = require('deep-equal'); | ||
var areEquals = function (a, b) { | ||
return deep_equal_1.deepEqual(a, b, equalsOptions); | ||
return _equals(a, b, equalsOptions); | ||
}; | ||
var helpers_1 = require('./helpers'); | ||
var core_1 = require('./core'); | ||
import { _deepClone, _objectKeys, escapePathComponent, hasOwnProperty } from './helpers'; | ||
import { applyPatch } from './core'; | ||
/* export all core functions */ | ||
var core_2 = require('./core'); | ||
exports.applyOperation = core_2.applyOperation; | ||
exports.applyPatch = core_2.applyPatch; | ||
exports.applyReducer = core_2.applyReducer; | ||
exports.getValueByPointer = core_2.getValueByPointer; | ||
exports.validate = core_2.validate; | ||
exports.validator = core_2.validator; | ||
export { applyOperation, applyPatch, applyReducer, getValueByPointer, validate, validator } from './core'; | ||
/* export some helpers */ | ||
var helpers_2 = require('./helpers'); | ||
exports.JsonPatchError = helpers_2.PatchError; | ||
exports.deepClone = helpers_2._deepClone; | ||
exports.escapePathComponent = helpers_2.escapePathComponent; | ||
exports.unescapePathComponent = helpers_2.unescapePathComponent; | ||
export { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent } from './helpers'; | ||
var beforeDict = []; | ||
@@ -69,10 +53,9 @@ var Mirror = (function () { | ||
*/ | ||
function unobserve(root, observer) { | ||
export function unobserve(root, observer) { | ||
observer.unobserve(); | ||
} | ||
exports.unobserve = unobserve; | ||
/** | ||
* Observes changes made to an object, which can then be retrieved using generate | ||
*/ | ||
function observe(obj, callback) { | ||
export function observe(obj, callback) { | ||
var patches = []; | ||
@@ -93,3 +76,3 @@ var root = obj; | ||
observer = {}; | ||
mirror.value = helpers_1._deepClone(obj); | ||
mirror.value = _deepClone(obj); | ||
if (callback) { | ||
@@ -146,7 +129,6 @@ observer.callback = callback; | ||
} | ||
exports.observe = observe; | ||
/** | ||
* Generate an array of patches from an observer | ||
*/ | ||
function generate(observer) { | ||
export function generate(observer) { | ||
var mirror; | ||
@@ -161,3 +143,3 @@ for (var i = 0, length = beforeDict.length; i < length; i++) { | ||
if (observer.patches.length) { | ||
core_1.applyPatch(mirror.value, observer.patches); | ||
applyPatch(mirror.value, observer.patches); | ||
} | ||
@@ -173,3 +155,2 @@ var temp = observer.patches; | ||
} | ||
exports.generate = generate; | ||
// Dirty check if obj is different from mirror, generate patches and update mirror | ||
@@ -183,4 +164,4 @@ function _generate(mirror, obj, patches, path) { | ||
} | ||
var newKeys = helpers_1._objectKeys(obj); | ||
var oldKeys = helpers_1._objectKeys(mirror); | ||
var newKeys = _objectKeys(obj); | ||
var oldKeys = _objectKeys(mirror); | ||
var changed = false; | ||
@@ -192,6 +173,6 @@ var deleted = false; | ||
var oldVal = mirror[key]; | ||
if (helpers_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { | ||
if (hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { | ||
var newVal = obj[key]; | ||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { | ||
_generate(oldVal, newVal, patches, path + "/" + helpers_1.escapePathComponent(key)); | ||
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key)); | ||
} | ||
@@ -201,3 +182,3 @@ else { | ||
changed = true; | ||
patches.push({ op: "replace", path: path + "/" + helpers_1.escapePathComponent(key), value: helpers_1._deepClone(newVal) }); | ||
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) }); | ||
} | ||
@@ -207,3 +188,3 @@ } | ||
else { | ||
patches.push({ op: "remove", path: path + "/" + helpers_1.escapePathComponent(key) }); | ||
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) }); | ||
deleted = true; // property has been deleted | ||
@@ -217,4 +198,4 @@ } | ||
var key = newKeys[t]; | ||
if (!helpers_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) { | ||
patches.push({ op: "add", path: path + "/" + helpers_1.escapePathComponent(key), value: helpers_1._deepClone(obj[key]) }); | ||
if (!hasOwnProperty(mirror, key) && obj[key] !== undefined) { | ||
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) }); | ||
} | ||
@@ -226,3 +207,3 @@ } | ||
*/ | ||
function compare(tree1, tree2) { | ||
export function compare(tree1, tree2) { | ||
var patches = []; | ||
@@ -232,2 +213,1 @@ _generate(tree1, tree2, patches, ''); | ||
} | ||
exports.compare = compare; |
@@ -12,7 +12,6 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
function hasOwnProperty(obj, key) { | ||
export function hasOwnProperty(obj, key) { | ||
return _hasOwnProperty.call(obj, key); | ||
} | ||
exports.hasOwnProperty = hasOwnProperty; | ||
function _objectKeys(obj) { | ||
export function _objectKeys(obj) { | ||
if (Array.isArray(obj)) { | ||
@@ -36,3 +35,2 @@ var keys = new Array(obj.length); | ||
} | ||
exports._objectKeys = _objectKeys; | ||
; | ||
@@ -45,3 +43,3 @@ /** | ||
*/ | ||
function _deepClone(obj) { | ||
export function _deepClone(obj) { | ||
switch (typeof obj) { | ||
@@ -56,5 +54,4 @@ case "object": | ||
} | ||
exports._deepClone = _deepClone; | ||
//3x faster than cached /^\d+$/.test(str) | ||
function isInteger(str) { | ||
export function isInteger(str) { | ||
var i = 0; | ||
@@ -73,3 +70,2 @@ var len = str.length; | ||
} | ||
exports.isInteger = isInteger; | ||
/** | ||
@@ -80,3 +76,3 @@ * Escapes a json pointer path | ||
*/ | ||
function escapePathComponent(path) { | ||
export function escapePathComponent(path) { | ||
if (path.indexOf('/') === -1 && path.indexOf('~') === -1) | ||
@@ -86,3 +82,2 @@ return path; | ||
} | ||
exports.escapePathComponent = escapePathComponent; | ||
/** | ||
@@ -93,7 +88,6 @@ * Unescapes a json pointer path | ||
*/ | ||
function unescapePathComponent(path) { | ||
export function unescapePathComponent(path) { | ||
return path.replace(/~1/g, '/').replace(/~0/g, '~'); | ||
} | ||
exports.unescapePathComponent = unescapePathComponent; | ||
function _getPathRecursive(root, obj) { | ||
export function _getPathRecursive(root, obj) { | ||
var found; | ||
@@ -115,4 +109,3 @@ for (var key in root) { | ||
} | ||
exports._getPathRecursive = _getPathRecursive; | ||
function getPath(root, obj) { | ||
export function getPath(root, obj) { | ||
if (root === obj) { | ||
@@ -127,7 +120,6 @@ return '/'; | ||
} | ||
exports.getPath = getPath; | ||
/** | ||
* Recursively checks whether an object has any undefined values inside. | ||
*/ | ||
function hasUndefined(obj) { | ||
export function hasUndefined(obj) { | ||
if (obj === undefined) { | ||
@@ -156,4 +148,3 @@ return true; | ||
} | ||
exports.hasUndefined = hasUndefined; | ||
var PatchError = (function (_super) { | ||
export var PatchError = (function (_super) { | ||
__extends(PatchError, _super); | ||
@@ -170,2 +161,1 @@ function PatchError(message, name, index, operation, tree) { | ||
}(Error)); | ||
exports.PatchError = PatchError; |
{ | ||
"name": "json-patch-es6", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"description": "Fast implementation of JSON-Patch (RFC-6902) with duplex (observe changes) capabilities", | ||
@@ -25,3 +25,3 @@ "homepage": "https://github.com/Starcounter-Jack/JSON-Patch", | ||
"license": "MIT", | ||
"module": "lib/duplex.js", | ||
"module": "src/duplex.js", | ||
"main": "dist/fast-json-patch.js", | ||
@@ -45,3 +45,3 @@ "typings": "lib/duplex.d.ts", | ||
"tsc": "tsc", | ||
"version": "tsc && webpack && git add -A", | ||
"version": "tsc -p tsconfig-es6.json && webpack && git add -A", | ||
"build": "tsc && webpack", | ||
@@ -48,0 +48,0 @@ "build-es6": "tsc -p tsconfig-es6.json && webpack", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144102
1987