UNPKG

1.95 kBTypeScriptView Raw
1import { Operation, TestOperation, VoidableDiff } from './diff';
2export { Operation, TestOperation };
3export declare type Patch = Operation[];
4/**
5Apply a 'application/json-patch+json'-type patch to an object.
6
7`patch` *must* be an array of operations.
8
9> Operation objects MUST have exactly one "op" member, whose value
10> indicates the operation to perform. Its value MUST be one of "add",
11> "remove", "replace", "move", "copy", or "test"; other values are
12> errors.
13
14This method mutates the target object in-place.
15
16@returns list of results, one for each operation: `null` indicated success,
17 otherwise, the result will be an instance of one of the Error classes:
18 MissingError, InvalidOperationError, or TestError.
19*/
20export declare function applyPatch(object: any, patch: Operation[]): (import("./patch").MissingError | import("./patch").TestError | import("./patch").InvalidOperationError | null)[];
21/**
22Produce a 'application/json-patch+json'-type patch to get from one object to
23another.
24
25This does not alter `input` or `output` unless they have a property getter with
26side-effects (which is not a good idea anyway).
27
28`diff` is called on each pair of comparable non-primitive nodes in the
29`input`/`output` object trees, producing nested patches. Return `undefined`
30to fall back to default behaviour.
31
32Returns list of operations to perform on `input` to produce `output`.
33*/
34export declare function createPatch(input: any, output: any, diff?: VoidableDiff): Operation[];
35/**
36Produce an 'application/json-patch+json'-type list of tests, to verify that
37existing values in an object are identical to the those captured at some
38checkpoint (whenever this function is called).
39
40This does not alter `input` or `output` unless they have a property getter with
41side-effects (which is not a good idea anyway).
42
43Returns list of test operations.
44*/
45export declare function createTests(input: any, patch: Operation[]): TestOperation[];