import { VSBuffer } from "@codingame/monaco-vscode-api/vscode/vs/base/common/buffer"; /** IMPORTANT: `Key` comes first. Then we should sort in order of least->most expensive to diff */ declare enum TransformKind { Key = 0, Primitive = 1, Array = 2, Object = 3 } /** Schema entries sorted with key properties first */ export type SchemaEntries = [ string, Transform ][]; interface TransformBase { readonly kind: TransformKind; /** Extracts the serializable value from the source object */ extract(from: TFrom): TTo; } /** Transform for primitive values (keys and values) that can be compared for equality */ export interface TransformValue extends TransformBase { readonly kind: TransformKind.Key | TransformKind.Primitive; /** Compares two serialized values for equality */ equals(a: TTo, b: TTo): boolean; } /** Transform for arrays with an item schema */ export interface TransformArray extends TransformBase { readonly kind: TransformKind.Array; /** The schema for array items */ readonly itemSchema: TransformObject | TransformValue; } /** Transform for objects with child properties */ export interface TransformObject extends TransformBase { readonly kind: TransformKind.Object; /** Schema entries sorted with Key properties first */ readonly children: SchemaEntries; /** Checks if the object is sealed (won't change). */ sealed?(obj: TTo, wasSerialized: boolean): boolean; } export type Transform = TransformValue | TransformArray | TransformObject; export type Schema = { [K in keyof Required]: Transform; }; /** * A primitive that will be tracked and compared first. If this is changed, the entire * object is thrown out and re-stored. */ export declare function key(comparator?: (a: R, b: R) => boolean): TransformValue; /** A value that will be tracked and replaced if the comparator is not equal. */ export declare function value(): TransformValue; export declare function value(comparator: (a: R, b: R) => boolean): TransformValue; /** An array that will use the schema to compare items positionally. */ export declare function array(schema: TransformObject | TransformValue): TransformArray; export interface ObjectOptions { /** * Returns true if the object is sealed and will never change again. * When comparing two sealed objects, only key fields are compared * (to detect replacement), but other fields are not diffed. */ sealed?: (obj: R, wasSerialized: boolean) => boolean; } /** An object schema. */ export declare function object(schema: Schema, options?: ObjectOptions): TransformObject; /** * Defines a getter on the object to extract a value, compared with the given schema. * It should return the value that will get serialized in the resulting log file. */ export declare function t(getter: (obj: T) => O, schema: Transform): Transform; /** Shortcut for t(fn, value()) */ export declare function v(getter: (obj: T) => R): TransformValue; export declare function v(getter: (obj: T) => R, comparator: (a: R, b: R) => boolean): TransformValue; /** * An implementation of an append-based mutation logger. Given a `Transform` * definition of an object, it can recreate it from a file on disk. It is * then stateful, and given a `write` call it can update the log in a minimal * way. */ export declare class ObjectMutationLog { private readonly _transform; private readonly _compactAfterEntries; private _previous; private _entryCount; private _hasPendingWrite; private _pendingPrevious; private _pendingEntryCount; constructor(_transform: Transform, _compactAfterEntries?: number); /** * Creates an initial log file from the given object. */ createInitial(current: TFrom): VSBuffer; /** * Creates an initial log file from the serialized object. * * Unlike {@link write}, this commits state immediately without requiring * {@link confirmWrite}. This is safe because the returned buffer contains * a self-contained `Initial` entry — if it fails to persist, no * incremental entries can be appended to a non-existent file. */ createInitialFromSerialized(value: TTo): VSBuffer; /** * Reads and reconstructs the state from a log file. */ read(content: VSBuffer): TTo; /** * Writes updates to the log. Returns the operation type and data to write. * The caller **must** invoke {@link confirmWrite} after the data is * successfully persisted to commit the internal state. Without confirmation, * the next write is computed against the last confirmed state, and will only * produce a full initial entry when no confirmed state exists, preventing * corrupted log files when a write fails. */ write(current: TFrom): { op: "append" | "replace"; data: VSBuffer; }; /** * Commits the internal state after a successful write to disk. */ confirmWrite(): void; private _clearPending; private _applySet; private _applyPush; private _diff; private _diffObject; private _diffArray; private _hasKeyMismatch; } export {};