/*! * Based on work from * https://github.com/mohayonao/json-touch-patch * (c) 2018 mohayonao * * MIT license * (c) 2022 Jacob Wright * * * NOTE: using /array/- syntax to indicate the end of the array makes it impossible to rebase arrays correctly in all */ import type { JSONPatchOp, JSONPatchCustomTypes, ApplyJSONPatchOptions } from './types'; /** * A JSONPatch helps with creating and applying one or more "JSON patches". It can track one or more changes * together which may form a single operation or transaction. */ export declare class JSONPatch { ops: JSONPatchOp[]; types: JSONPatchCustomTypes; /** * Create a new JSONPatch, optionally with an existing array of operations. */ constructor(ops?: JSONPatchOp[], types?: JSONPatchCustomTypes); op(op: string, path: string, value?: any, from?: string): this; /** * Tests a value exists. If it doesn't, the patch is not applied. */ test(path: string, value: any): this; /** * Adds the value to an object or array, inserted before the given index. */ add(path: string, value: any): this; /** * Deletes the value at the given path or removes it from an array. */ remove(path: string): this; /** * Replaces a value (same as remove+add). */ replace(path: string, value: any): this; /** * Copies the value at `from` to `path`. */ copy(from: string, path: string): this; /** * Moves the value at `from` to `path`. */ move(from: string, path: string): this; /** * Creates a patch from an object partial, updating each field. Set a field to undefined to delete it. */ addUpdates(updates: { [key: string]: any; }, path?: string): this; /** * This will ensure an "add empty object" operation is created for each property along the path that does not exist. */ addObjectsInPath(obj: any, path: string): this; /** * Apply this patch to an object, returning a new object with the applied changes (or the same object if nothing * changed in the patch). Optionally apply the page at the given path prefix. */ patch(obj: T, options: ApplyJSONPatchOptions): T; /** * Rebase this patch against another JSONPatch or array of operations */ rebase(over: JSONPatch | JSONPatchOp[]): JSONPatch; /** * Create a patch which can reverse what this patch does. Because JSON Patches do not store previous values, you * must provide the previous object to create a reverse patch. */ invert(object: any): JSONPatch; revert(object: any): JSONPatch; /** * Returns an array of patch operations. */ toJSON(): JSONPatchOp[]; /** * Create a new JSONPatch with the provided JSON patch operations. */ static fromJSON(ops: any): JSONPatch; }