import { JsonArrayLens, JsonLens, JsonObjectLens, PatchOperation } from './json-lens'; interface SchemaLensOptions { readonly rootPath?: JsonLens[]; readonly jsonPointer?: string; readonly fileName: string; readonly reportInto?: PatchReport[]; readonly patchInto?: PatchOperation[]; } /** * A patch that indicates a mistake by upstream users */ export interface PatchReport { readonly subject: any; readonly fileName: string; readonly path: string; readonly patch: PatchOperation; readonly reason: string; } export declare class SchemaLens implements JsonLens, JsonObjectLens, JsonArrayLens { /** Filename of the file */ readonly fileName: string; /** JSON Pointer (RFC 6901) to the current value (ex. `/foo/bar/3`) */ readonly jsonPointer: string; /** The path of the lenses to the current value, current lens is always in this list. */ readonly rootPath: JsonLens[]; /** The value currently under the lens */ readonly value: any; readonly reports: PatchReport[]; readonly patches: PatchOperation[]; readonly removedKeys: string[]; constructor(value: any, options: SchemaLensOptions); get hasPatches(): boolean; /** Type test for whether the current lens points to a json object. */ isJsonObject(): this is JsonObjectLens; isJsonArray(): this is JsonArrayLens; wasRemoved(key: string): boolean; /** Fully replace the current value with a different one. */ replaceValue(reason: string, newValue: any): void; /** Remove the property with the given name on the current object. The property will not be recursed into. */ removeProperty(reason: string, name: string): void; /** Rename a property, optionally transforming its value. */ renameProperty(reason: string, oldName: string, newName: string, fx?: (x: any) => any): void; /** Add a property */ addProperty(reason: string, name: string, value: any): void; /** Replace a property */ replaceProperty(reason: string, name: string, value: any): void; /** Recurse through the object field. */ descendObjectField(key: string): SchemaLens; /** Recurse through the array. */ descendArrayElement(index: number): SchemaLens; recordPatch(reason: string, patch: PatchOperation): void; /** * Escapes a segment of a key for JSON Pointer (RFC 6901). * * Rules: * ~ → ~0 * / → ~1 */ escapeKey(key: string): string; } export type Patcher = (lens: L) => void; export type JsonLensPatcher = Patcher; export type JsonObjectPatcher = Patcher; export declare function makeCompositePatcher(...patchers: Patcher[]): Patcher; export declare function onlyObjects(patcher: Patcher): Patcher; /** * Apply a patcher to a data structure */ export declare function applyPatcher(root: any, patcher: JsonLensPatcher): { root: any; patches: PatchReport[]; }; export {};