1- /*! fast-json-patch, version: 2.0.7 */
1+ /*! fast-json-patch, version: 2.1.0 */
22var jsonpatch =
33/******/ ( function ( modules ) { // webpackBootstrap
44/******/ // The module cache
@@ -72,16 +72,16 @@ var jsonpatch =
7272/* 0 */
7373/***/ ( function ( module , exports ) {
7474
75- var __extends = ( this && this . __extends ) || function ( d , b ) {
76- for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ;
77- function __ ( ) { this . constructor = d ; }
78- d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
79- } ;
8075/*!
8176 * https://github.com/Starcounter-Jack/JSON-Patch
8277 * (c) 2017 Joachim Wester
8378 * MIT license
8479 */
80+ var __extends = ( this && this . __extends ) || function ( d , b ) {
81+ for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ;
82+ function __ ( ) { this . constructor = d ; }
83+ d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
84+ } ;
8585var _hasOwnProperty = Object . prototype . hasOwnProperty ;
8686function hasOwnProperty ( obj , key ) {
8787 return _hasOwnProperty . call ( obj , key ) ;
@@ -218,15 +218,25 @@ function hasUndefined(obj) {
218218 return false ;
219219}
220220exports . hasUndefined = hasUndefined ;
221+ function patchErrorMessageFormatter ( message , args ) {
222+ var messageParts = [ message ] ;
223+ for ( var key in args ) {
224+ var value = typeof args [ key ] === 'object' ? JSON . stringify ( args [ key ] , null , 2 ) : args [ key ] ; // pretty print
225+ if ( typeof value !== 'undefined' ) {
226+ messageParts . push ( key + ": " + value ) ;
227+ }
228+ }
229+ return messageParts . join ( '\n' ) ;
230+ }
221231var PatchError = ( function ( _super ) {
222232 __extends ( PatchError , _super ) ;
223233 function PatchError ( message , name , index , operation , tree ) {
224- _super . call ( this , message ) ;
225- this . message = message ;
234+ _super . call ( this , patchErrorMessageFormatter ( message , { name : name , index : index , operation : operation , tree : tree } ) ) ;
226235 this . name = name ;
227236 this . index = index ;
228237 this . operation = operation ;
229238 this . tree = tree ;
239+ this . message = patchErrorMessageFormatter ( message , { name : name , index : index , operation : operation , tree : tree } ) ;
230240 }
231241 return PatchError ;
232242} ( Error ) ) ;
@@ -350,10 +360,11 @@ exports.getValueByPointer = getValueByPointer;
350360 * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
351361 * @return `{newDocument, result}` after the operation
352362 */
353- function applyOperation ( document , operation , validateOperation , mutateDocument , banPrototypeModifications ) {
363+ function applyOperation ( document , operation , validateOperation , mutateDocument , banPrototypeModifications , index ) {
354364 if ( validateOperation === void 0 ) { validateOperation = false ; }
355365 if ( mutateDocument === void 0 ) { mutateDocument = true ; }
356366 if ( banPrototypeModifications === void 0 ) { banPrototypeModifications = true ; }
367+ if ( index === void 0 ) { index = 0 ; }
357368 if ( validateOperation ) {
358369 if ( typeof validateOperation == 'function' ) {
359370 validateOperation ( operation , 0 , document , operation . path ) ;
@@ -384,7 +395,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
384395 else if ( operation . op === 'test' ) {
385396 returnValue . test = areEquals ( document , operation . value ) ;
386397 if ( returnValue . test === false ) {
387- throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , 0 , operation , document ) ;
398+ throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , index , operation , document ) ;
388399 }
389400 returnValue . newDocument = document ;
390401 return returnValue ;
@@ -400,7 +411,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
400411 }
401412 else {
402413 if ( validateOperation ) {
403- throw new exports . JsonPatchError ( 'Operation `op` property is not one of operations defined in RFC-6902' , 'OPERATION_OP_INVALID' , 0 , operation , document ) ;
414+ throw new exports . JsonPatchError ( 'Operation `op` property is not one of operations defined in RFC-6902' , 'OPERATION_OP_INVALID' , index , operation , document ) ;
404415 }
405416 else {
406417 return returnValue ;
@@ -450,19 +461,19 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
450461 }
451462 else {
452463 if ( validateOperation && ! helpers_1 . isInteger ( key ) ) {
453- 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 ) ;
464+ 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 ) ;
454465 } // only parse key when it's an integer for `arr.prop` to work
455466 else if ( helpers_1 . isInteger ( key ) ) {
456467 key = ~ ~ key ;
457468 }
458469 }
459470 if ( t >= len ) {
460471 if ( validateOperation && operation . op === "add" && key > obj . length ) {
461- 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 ) ;
472+ 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 ) ;
462473 }
463474 var returnValue = arrOps [ operation . op ] . call ( operation , obj , key , document ) ; // Apply patch
464475 if ( returnValue . test === false ) {
465- throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , 0 , operation , document ) ;
476+ throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , index , operation , document ) ;
466477 }
467478 return returnValue ;
468479 }
@@ -474,7 +485,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
474485 if ( t >= len ) {
475486 var returnValue = objOps [ operation . op ] . call ( operation , obj , key , document ) ; // Apply patch
476487 if ( returnValue . test === false ) {
477- throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , 0 , operation , document ) ;
488+ throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , index , operation , document ) ;
478489 }
479490 return returnValue ;
480491 }
@@ -512,7 +523,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
512523 var results = new Array ( patch . length ) ;
513524 for ( var i = 0 , length_1 = patch . length ; i < length_1 ; i ++ ) {
514525 // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
515- results [ i ] = applyOperation ( document , patch [ i ] , validateOperation , true , banPrototypeModifications ) ;
526+ results [ i ] = applyOperation ( document , patch [ i ] , validateOperation , true , banPrototypeModifications , i ) ;
516527 document = results [ i ] . newDocument ; // in case root was replaced
517528 }
518529 results . newDocument = document ;
@@ -528,10 +539,10 @@ exports.applyPatch = applyPatch;
528539 * @param operation The operation to apply
529540 * @return The updated document
530541 */
531- function applyReducer ( document , operation ) {
542+ function applyReducer ( document , operation , index ) {
532543 var operationResult = applyOperation ( document , operation ) ;
533544 if ( operationResult . test === false ) {
534- throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , 0 , operation , document ) ;
545+ throw new exports . JsonPatchError ( "Test operation failed" , 'TEST_OPERATION_FAILED' , index , operation , document ) ;
535546 }
536547 return operationResult . newDocument ;
537548}
0 commit comments