Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed Apr 1, 2019
1 parent 56975ef commit 476caa8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
47 changes: 29 additions & 18 deletions dist/fast-json-patch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! fast-json-patch, version: 2.0.7 */
/*! fast-json-patch, version: 2.1.0 */
var jsonpatch =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -72,16 +72,16 @@ var jsonpatch =
/* 0 */
/***/ (function(module, exports) {

var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017 Joachim Wester
* MIT license
*/
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var _hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwnProperty(obj, key) {
return _hasOwnProperty.call(obj, key);
Expand Down Expand Up @@ -218,15 +218,25 @@ function hasUndefined(obj) {
return false;
}
exports.hasUndefined = hasUndefined;
function patchErrorMessageFormatter(message, args) {
var messageParts = [message];
for (var key in args) {
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
if (typeof value !== 'undefined') {
messageParts.push(key + ": " + value);
}
}
return messageParts.join('\n');
}
var PatchError = (function (_super) {
__extends(PatchError, _super);
function PatchError(message, name, index, operation, tree) {
_super.call(this, message);
this.message = message;
_super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree }));
this.name = name;
this.index = index;
this.operation = operation;
this.tree = tree;
this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
}
return PatchError;
}(Error));
Expand Down Expand Up @@ -350,10 +360,11 @@ exports.getValueByPointer = getValueByPointer;
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
* @return `{newDocument, result}` after the operation
*/
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications) {
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
if (validateOperation === void 0) { validateOperation = false; }
if (mutateDocument === void 0) { mutateDocument = true; }
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
if (index === void 0) { index = 0; }
if (validateOperation) {
if (typeof validateOperation == 'function') {
validateOperation(operation, 0, document, operation.path);
Expand Down Expand Up @@ -384,7 +395,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
else if (operation.op === 'test') {
returnValue.test = areEquals(document, operation.value);
if (returnValue.test === false) {
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document);
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
returnValue.newDocument = document;
return returnValue;
Expand All @@ -400,7 +411,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
}
else {
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 exports.JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
}
else {
return returnValue;
Expand Down Expand Up @@ -450,19 +461,19 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
}
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);
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", index, operation, document);
} // only parse key when it's an integer for `arr.prop` to work
else if (helpers_1.isInteger(key)) {
key = ~~key;
}
}
if (t >= len) {
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 exports.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
}
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 exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
return returnValue;
}
Expand All @@ -474,7 +485,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
if (t >= len) {
var returnValue = objOps[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 exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
return returnValue;
}
Expand Down Expand Up @@ -512,7 +523,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
var results = new Array(patch.length);
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications);
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
document = results[i].newDocument; // in case root was replaced
}
results.newDocument = document;
Expand All @@ -528,10 +539,10 @@ exports.applyPatch = applyPatch;
* @param operation The operation to apply
* @return The updated document
*/
function applyReducer(document, operation) {
function applyReducer(document, operation, index) {
var operationResult = applyOperation(document, operation);
if (operationResult.test === false) {
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', 0, operation, document);
throw new exports.JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
return operationResult.newDocument;
}
Expand Down
Loading

0 comments on commit 476caa8

Please sign in to comment.