//#region src/pointer.d.ts type Token = string | number | { toString: () => string; }; /** * RFC-6901 complaint pointer * * Identifies a specific value within a JavaScript Object Notation (JSON) document. * * @see https://datatracker.ietf.org/doc/html/rfc6901 */ declare class Pointer { readonly tokens: Token[]; constructor(tokens: Token[]); static from(str: Pointer | string | Uint8Array | ArrayBuffer): Pointer; delete(a: T): T | undefined; evaluatePointer(a: unknown, existCheck?: boolean): [parent: NonNullable | null, key: Token | undefined, value: unknown]; extend(token?: Token): Pointer; get(a: T): unknown; inspect(): string; /** * Move `newVal` (the value taken from `from`) to this pointer's location. * * When `from` and `to` are members of the same object/map, this is treated as an in-place * rename/overwrite, so the member keeps its original position rather than being appended to * the end (which is otherwise unavoidable in JS, since a fresh key is always inserted last). */ move(a: T, from: Pointer, newVal: V): T | V; push(a: T, newVal: V): T | V; set(a: T, value: V): T | V; /** * Convert pointers to string for easy BSONification */ toBSON(): string; toJSON(): string; /** * https://datatracker.ietf.org/doc/html/rfc6901#section-5 */ toString(): string; asymmetricMatch(other: unknown): boolean; } declare const RootPointer: Pointer; //#endregion //#region src/patch.d.ts declare namespace Mini { type AddOp = [op: "+", path: Pointer | string, value: V]; type RemoveOp = [op: "-", path: Pointer | string]; type ReplaceOp = [op: "~", path: Pointer | string, value: V]; type MoveOp = [op: ">", from: Pointer | string, to: Pointer | string]; type CopyOp = [op: "^", from: Pointer | string, to: Pointer | string]; type TestOp = [op: "?", path: Pointer | string, value: V]; type Op = AddOp | RemoveOp | ReplaceOp | MoveOp | CopyOp | TestOp; type Patch = Op[]; } declare namespace Maxi { type AddOp = { op: "add"; path: Pointer | string; value: V; }; type RemoveOp = { op: "remove"; path: Pointer | string; }; type ReplaceOp = { op: "replace"; path: Pointer | string; value: V; }; type MoveOp = { op: "move"; from: Pointer | string; path: Pointer | string; }; type CopyOp = { op: "copy"; from: Pointer | string; path: Pointer | string; }; type TestOp = { op: "test"; path: Pointer | string; value: V; }; type Op = AddOp | RemoveOp | ReplaceOp | MoveOp | CopyOp | TestOp; type Patch = Op[]; } declare namespace Serial { type Op = Uint8Array; type Patch = Uint8Array; } type Op = Mini.Op | Maxi.Op | Serial.Op; type MaxiPatch = Maxi.Patch; type MiniPatch = Mini.Patch; type SerialPatch = Serial.Patch; type Patch = Op[] | SerialPatch; //#endregion //#region src/utils/types.d.ts type CloneOpts = { clone?: Cloner; }; type EqOpts = { eq?: EqFunc; }; type Transformer = "minify" | "maximize" | "serialize"; type TransformOpts = { transform?: Transformer; }; type OptimizeStrategy = "byte" | "impact"; type OptimizeOpts = { optimize?: OptimizeStrategy; }; type CreateOpts = EqOpts & CloneOpts & TransformOpts & OptimizeOpts & { diff?: Differ; }; type DiffOpts = CreateOpts; type ApplyOpts = EqOpts & CloneOpts & TransformOpts; type SkipFunc = () => never; /** * Optional user defined deep clone function * * @param val - The value to clone * @param opts - options for custom handling * * Call `opts.skip()` to allow default handling */ type Cloner = (val: T, opts: WithSkip & O) => T; /** * Optional user defined diff creation function * * @param input - the source to base the difference from * @param output - the target to base the diff on * @param ptr - Pointer representing the current position relative to the input root * @param opts - options for custom handling * * Call `opts.skip()` to allow default handling */ type Differ = (input: Exclude, output: Exclude, ptr: Pointer, opts: WithSkip & O) => T; /** * Optional user defined deep equality function * * @param a - left hand side of the equality comparison * @param b - right hand side of the equality comparison * @param opts - options for custom handling * * Call `opts.skip()` to allow default handling */ type EqFunc = (a: Exclude, b: Exclude, opts: WithSkip & O) => boolean; type WithSkip = T & { skip: SkipFunc; }; //#endregion //#region src/utils/eq.d.ts /** * Returns whether the two passed arguments are equal * * @param a - left hand side of the equality comparison * @param b - right hand side of the equality comparison * @param opts - options for custom handling */ declare function eq(a: any, b: any, opts?: EqOpts): boolean; //#endregion //#region src/utils/transform.d.ts /** * Convert a Patch into a {@link MiniPatch} * * @param patch - The patch to transform * @param transform - The transform to apply */ declare function transform(patch: Patch, transform: "minify"): MiniPatch; /** * Convert a Patch into a {@link MaxiPatch} * * @param patch - The patch to transform * @param transform - The transform to apply */ declare function transform(patch: Patch, transform: "maximize"): MaxiPatch; /** * Convert a Patch into a {@link SerialPatch} * * @param patch - The patch to transform * @param transform - The transform to apply */ declare function transform(patch: Patch, transform: "serialize"): SerialPatch; /** * Convert a Patch into a uniform format, following the provided transform * If `transform` isn't set, the {@link Patch} is unaltered * * @param patch - The patch to transform * @param transform - The transform to apply */ declare function transform(patch: Patch, transform?: Transformer): Patch; //#endregion //#region src/apply.d.ts /** * * @param target - The object to apply a patch to * @param patch - The patch to apply * @param opts - Optional options for custom handling */ declare function apply(target: DocType, patch: Patch | null, opts?: ApplyOpts): unknown; //#endregion //#region src/create.d.ts /** * Returns a list of operations (a JSON Patch) comprised of the operations to transform `input` into `output`. * It attempts to produce the smallest patch, this does not necessarily mean the smallest number of operations, * as a full replacement may result in more bytes being sent. * * For array transformations we attempt to reduce the size of operations by running an edit distance style algorithm, * with support for `add`, `remove`, `replace`, `copy`, `array replace` operations. * * The output will be a {@link MiniPatch} * * If the user provided {@link Differ} returns a {@link SerialPatch}, * it will be converted to a {@link MiniPatch} and then combined with the other patches * * @param input - The input to compare from * @param output - The output to compare to * @param opts - options for custom handling * @param opts.transform - force the output to all be minified */ declare function create(input: any, output: any, opts: CreateOpts & { transform: "minify"; }): MiniPatch | null; /** * Returns a list of operations (a JSON Patch) comprised of the operations to transform `input` into `output`. * It attempts to produce the smallest patch, this does not necessarily mean the smallest number of operations, * as a full replacement may result in more bytes being sent. * * For array transformations we attempt to reduce the size of operations by running an edit distance style algorithm, * with support for `add`, `remove`, `replace`, `copy`, `array replace` operations. * * The output will be a {@link MaxiPatch} * * If the user provided {@link Differ} returns a {@link SerialPatch}, * it will be converted to a {@link MiniPatch} and then combined with the other patches * * @param input - The input to compare from * @param output - The output to compare to * @param opts - options for custom handling * @param opts.transform - force the output to all be maximised */ declare function create(input: any, output: any, opts: CreateOpts & { transform: "maximize"; }): MaxiPatch | null; /** * Returns a list of operations (a JSON Patch) comprised of the operations to transform `input` into `output`. * It attempts to produce the smallest patch, this does not necessarily mean the smallest number of operations, * as a full replacement may result in more bytes being sent. * * For array transformations we attempt to reduce the size of operations by running an edit distance style algorithm, * with support for `add`, `remove`, `replace`, `copy`, `array replace` operations. * * The output will be a {@link SerialPatch} * * If the user provided {@link Differ} returns a {@link SerialPatch}, * it will be converted to a {@link MiniPatch} and then combined with the other patches * * @param input - The input to compare from * @param output - The output to compare to * @param opts - options for custom handling * @param opts.transform - force the output to be serialized */ declare function create(input: any, output: any, opts: CreateOpts & { transform: "serialize"; }): SerialPatch | null; /** * Returns a list of operations (a JSON Patch) comprising the operations to transform `input` into `output`. * By default, it attempts to produce the smallest patch by byte size, * this does not necessarily mean it impacts the least number of fields, * as a full replacement may result in fewer bytes being sent. * Use `opts.optimize: 'impact'` to optimize for the least number of fields impacted instead. * * For array transformations we attempt to reduce the size of operations by running an edit distance style algorithm, * with support for `add`, `remove`, `replace`, `copy`, `array replace` operations. * * The output will be a {@link Patch} * * If the user provided {@link Differ} returns a {@link SerialPatch}, * it will be converted to a {@link MiniPatch} and then combined with the other patches * * @param input - The input to compare from * @param output - The output to compare to * @param opts - Optional options for custom handling */ declare function create(input: any, output: any, opts: CreateOpts): Patch | null; /** * Returns a list of operations (a JSON Patch) comprised of the operations to transform `input` into `output`. * It attempts to produce the smallest patch, this does not necessarily mean the smallest number of operations, * as a full replacement may result in more bytes being sent. * * For array transformations we attempt to reduce the size of operations by running an edit distance style algorithm, * with support for `add`, `remove`, `replace`, `copy`, `array replace` operations. * * The output will be a {@link MiniPatch} * * @param input - The input to compare from * @param output - The output to compare to */ declare function create(input: any, output: any): MiniPatch | null; //#endregion export { type Maxi, type MaxiPatch, type Mini, type MiniPatch, type Patch, Pointer, RootPointer, type Serial, type SerialPatch, apply, create, eq, transform };