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