rfc6902
Version:
Complete implementation of RFC6902 (patch and diff)
48 lines (38 loc) • 2 kB
TypeScript
import { Pointer } from './pointer';
export { Pointer };
import { Operation, TestOperation, VoidableDiff } from './diff';
export { Operation, TestOperation };
export type Patch = Operation[];
/**
Apply a 'application/json-patch+json'-type patch to an object.
`patch` *must* be an array of operations.
> Operation objects MUST have exactly one "op" member, whose value
> indicates the operation to perform. Its value MUST be one of "add",
> "remove", "replace", "move", "copy", or "test"; other values are
> errors.
This method mutates the target object in-place.
@returns list of results, one for each operation: `null` indicated success,
otherwise, the result will be an instance of one of the Error classes:
MissingError, InvalidOperationError, or TestError.
*/
export declare function applyPatch(object: any, patch: Operation[]): (import("./patch").MissingError | import("./patch").TestError | import("./patch").InvalidOperationError | null)[];
/**
Produce a 'application/json-patch+json'-type patch to get from one object to
another.
This does not alter `input` or `output` unless they have a property getter with
side-effects (which is not a good idea anyway).
`diff` is called on each pair of comparable non-primitive nodes in the
`input`/`output` object trees, producing nested patches. Return `undefined`
to fall back to default behaviour.
Returns list of operations to perform on `input` to produce `output`.
*/
export declare function createPatch(input: any, output: any, diff?: VoidableDiff): Operation[];
/**
Produce an 'application/json-patch+json'-type list of tests, to verify that
existing values in an object are identical to the those captured at some
checkpoint (whenever this function is called).
This does not alter `input` or `output` unless they have a property getter with
side-effects (which is not a good idea anyway).
Returns list of test operations.
*/
export declare function createTests(input: any, patch: Operation[]): TestOperation[];