Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) {
/**
* @type {Array}
*/
const nextPathParts = patchObj.path.split('/');
const nextPathIdx = Number(nextPathParts.pop()) + offset;
const nextPath = nextPathParts.concat(nextPathIdx).join('/');
oldValue = ptr.get(reportA, nextPath);
offset++;
nextValue = {...patchObj, oldValue, path: nextPath};
} else {
// there's no old value to look up for 'add' operations.
if (patchObj.op === 'add') {
nextValue = patchObj;
} else {
oldValue = ptr.get(reportA, patchObj.path);
nextValue = {...patchObj, oldValue};
}
offset = 1;
}
lastPatchObj = patchObj;
observer.next(nextValue);
}, patch);
} catch (err) {
// is repeated 3 times with the same path. to get the old value--in other words,
// *what* was removed--we must increment the index at the end of the path
// and use that to retrieve the value from reportA.
if (
lastPatchObj &&
patchObj.op === 'remove' &&
patchObj.path === lastPatchObj.path &&
patchObj.op === lastPatchObj.op
) {
/**
* @type {Array}
*/
const nextPathParts = patchObj.path.split('/');
const nextPathIdx = Number(nextPathParts.pop()) + offset;
const nextPath = nextPathParts.concat(nextPathIdx).join('/');
oldValue = ptr.get(reportA, nextPath);
offset++;
nextValue = {...patchObj, oldValue, path: nextPath};
} else {
// there's no old value to look up for 'add' operations.
if (patchObj.op === 'add') {
nextValue = patchObj;
} else {
oldValue = ptr.get(reportA, patchObj.path);
nextValue = {...patchObj, oldValue};
}
offset = 1;
}
lastPatchObj = patchObj;
observer.next(nextValue);
}, patch);
} catch (err) {
function resolvePointerReference(obj, ref) {
return ptr.get(obj, ref);
}
resolveJsonPointer(target: object, pointer?: string): any {
let result;
if (pointer === undefined || pointer === "/") {
result = target;
} else {
result = jsonPtr.get(target, pointer);
}
if (result === undefined && this._config.errorOnRefNotFound) {
throw new Error(`The JSON pointer "${pointer}" resolves to undefined. Set Config.errorOnRefNotFound to false to suppress this message`);
}
return result;
}
.add("flitbit/json-ptr get", function() {
flitbit.get(doc, pointer);
})
.add("flitbit/json-ptr compiled", function() {