(document, patch, validateOperation, mutateDocument, banPrototypeModifications)
| 261 | * @return An array of `{newDocument, result}` after the patch |
| 262 | */ |
| 263 | export function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) { |
| 264 | if (mutateDocument === void 0) { mutateDocument = true; } |
| 265 | if (banPrototypeModifications === void 0) { banPrototypeModifications = true; } |
| 266 | if (validateOperation) { |
| 267 | if (!Array.isArray(patch)) { |
| 268 | throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY'); |
| 269 | } |
| 270 | } |
| 271 | if (!mutateDocument) { |
| 272 | document = _deepClone(document); |
| 273 | } |
| 274 | var results = new Array(patch.length); |
| 275 | for (var i = 0, length_1 = patch.length; i < length_1; i++) { |
| 276 | // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true` |
| 277 | results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i); |
| 278 | document = results[i].newDocument; // in case root was replaced |
| 279 | } |
| 280 | results.newDocument = document; |
| 281 | return results; |
| 282 | } |
| 283 | /** |
| 284 | * Apply a single JSON Patch Operation on a JSON document. |
| 285 | * Returns the updated document. |
no test coverage detected