From adea0f884df96affe722eb0d80ea393812cf1ac6 Mon Sep 17 00:00:00 2001 From: beam-bence Date: Thu, 8 Sep 2022 08:22:17 +0200 Subject: [PATCH 1/2] fix: passing parameter index to validator functions instead of constant 0 --- src/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.ts b/src/core.ts index cac6607..b1a63a9 100644 --- a/src/core.ts +++ b/src/core.ts @@ -182,10 +182,10 @@ export function getValueByPointer(document: any, pointer: string): any { export function applyOperation(document: T, operation: Operation, validateOperation: boolean | Validator = false, mutateDocument: boolean = true, banPrototypeModifications: boolean = true, index: number = 0): OperationResult { if (validateOperation) { if (typeof validateOperation == 'function') { - validateOperation(operation, 0, document, operation.path); + validateOperation(operation, index, document, operation.path); } else { - validator(operation, 0); + validator(operation, index); } } /* ROOT OPERATIONS */ From 2822dd281ab4baaf05233be50a8f23cc6df5eaa0 Mon Sep 17 00:00:00 2001 From: beam-bence Date: Thu, 8 Sep 2022 08:22:58 +0200 Subject: [PATCH 2/2] added @param index to JSDoc --- src/core.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core.ts b/src/core.ts index b1a63a9..c95078b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -177,6 +177,7 @@ export function getValueByPointer(document: any, pointer: string): any { * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation. * @param mutateDocument Whether to mutate the original document or clone it before applying * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`. + * @param index The index of the operation if it is from a patch. * @return `{newDocument, result}` after the operation */ export function applyOperation(document: T, operation: Operation, validateOperation: boolean | Validator = false, mutateDocument: boolean = true, banPrototypeModifications: boolean = true, index: number = 0): OperationResult {