1
- /*! fast-json-patch, version: 2.0.7 */
1
+ /*! fast-json-patch, version: 2.1.0 */
2
2
var jsonpatch =
3
3
/******/ ( function ( modules ) { // webpackBootstrap
4
4
/******/ // The module cache
@@ -72,16 +72,16 @@ var jsonpatch =
72
72
/* 0 */
73
73
/***/ ( function ( module , exports ) {
74
74
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
- } ;
80
75
/*!
81
76
* https://github.com/Starcounter-Jack/JSON-Patch
82
77
* (c) 2017 Joachim Wester
83
78
* MIT license
84
79
*/
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
+ } ;
85
85
var _hasOwnProperty = Object . prototype . hasOwnProperty ;
86
86
function hasOwnProperty ( obj , key ) {
87
87
return _hasOwnProperty . call ( obj , key ) ;
@@ -218,15 +218,25 @@ function hasUndefined(obj) {
218
218
return false ;
219
219
}
220
220
exports . 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
+ }
221
231
var PatchError = ( function ( _super ) {
222
232
__extends ( PatchError , _super ) ;
223
233
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 } ) ) ;
226
235
this . name = name ;
227
236
this . index = index ;
228
237
this . operation = operation ;
229
238
this . tree = tree ;
239
+ this . message = patchErrorMessageFormatter ( message , { name : name , index : index , operation : operation , tree : tree } ) ;
230
240
}
231
241
return PatchError ;
232
242
} ( Error ) ) ;
@@ -350,10 +360,11 @@ exports.getValueByPointer = getValueByPointer;
350
360
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
351
361
* @return `{newDocument, result}` after the operation
352
362
*/
353
- function applyOperation ( document , operation , validateOperation , mutateDocument , banPrototypeModifications ) {
363
+ function applyOperation ( document , operation , validateOperation , mutateDocument , banPrototypeModifications , index ) {
354
364
if ( validateOperation === void 0 ) { validateOperation = false ; }
355
365
if ( mutateDocument === void 0 ) { mutateDocument = true ; }
356
366
if ( banPrototypeModifications === void 0 ) { banPrototypeModifications = true ; }
367
+ if ( index === void 0 ) { index = 0 ; }
357
368
if ( validateOperation ) {
358
369
if ( typeof validateOperation == 'function' ) {
359
370
validateOperation ( operation , 0 , document , operation . path ) ;
@@ -384,7 +395,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
384
395
else if ( operation . op === 'test' ) {
385
396
returnValue . test = areEquals ( document , operation . value ) ;
386
397
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 ) ;
388
399
}
389
400
returnValue . newDocument = document ;
390
401
return returnValue ;
@@ -400,7 +411,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
400
411
}
401
412
else {
402
413
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 ) ;
404
415
}
405
416
else {
406
417
return returnValue ;
@@ -450,19 +461,19 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
450
461
}
451
462
else {
452
463
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 ) ;
454
465
} // only parse key when it's an integer for `arr.prop` to work
455
466
else if ( helpers_1 . isInteger ( key ) ) {
456
467
key = ~ ~ key ;
457
468
}
458
469
}
459
470
if ( t >= len ) {
460
471
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 ) ;
462
473
}
463
474
var returnValue = arrOps [ operation . op ] . call ( operation , obj , key , document ) ; // Apply patch
464
475
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 ) ;
466
477
}
467
478
return returnValue ;
468
479
}
@@ -474,7 +485,7 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
474
485
if ( t >= len ) {
475
486
var returnValue = objOps [ operation . op ] . call ( operation , obj , key , document ) ; // Apply patch
476
487
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 ) ;
478
489
}
479
490
return returnValue ;
480
491
}
@@ -512,7 +523,7 @@ function applyPatch(document, patch, validateOperation, mutateDocument, banProto
512
523
var results = new Array ( patch . length ) ;
513
524
for ( var i = 0 , length_1 = patch . length ; i < length_1 ; i ++ ) {
514
525
// 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 ) ;
516
527
document = results [ i ] . newDocument ; // in case root was replaced
517
528
}
518
529
results . newDocument = document ;
@@ -528,10 +539,10 @@ exports.applyPatch = applyPatch;
528
539
* @param operation The operation to apply
529
540
* @return The updated document
530
541
*/
531
- function applyReducer ( document , operation ) {
542
+ function applyReducer ( document , operation , index ) {
532
543
var operationResult = applyOperation ( document , operation ) ;
533
544
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 ) ;
535
546
}
536
547
return operationResult . newDocument ;
537
548
}
0 commit comments