loro-mirror
Version:
Type-safe state management synchronized with Loro CRDT via a declarative schema and bidirectional mirroring.
97 lines • 4.6 kB
TypeScript
import { ContainerID, LoroDoc } from "loro-crdt";
import { ContainerSchemaType, LoroListSchema, LoroMapSchema, LoroMovableListSchema, LoroTreeSchema, RootSchemaType, SchemaType } from "../schema";
import { InferContainerOptions, type Change } from "./mirror";
import { type ObjectLike, type ArrayLike } from "./utils";
/**
* Finds the longest increasing subsequence of a sequence of numbers
* @param sequence The sequence of numbers
* @returns The longest increasing subsequence
*/
export declare function longestIncreasingSubsequence(sequence: number[]): number[];
type IdSelector<T> = (item: T) => string | undefined;
/**
* Diffs a container between two states
*
* @param doc The LoroDoc instance
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID can be "" for root level changes
* @param schema The schema for the container (can be undefined)
* @returns The list of changes
*/
export declare function diffContainer(doc: LoroDoc, oldState: unknown, newState: unknown, containerId: ContainerID | "", schema: SchemaType | undefined, inferOptions?: InferContainerOptions): Change[];
/**
* Diffs a [LoroText] between two states
*
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID
* @returns The list of changes
*/
export declare function diffText(oldState: string, newState: string, containerId: ContainerID | ""): Change[];
/**
* Diffs a LoroTree between two states
*
* Produces structural tree operations (create/move/delete) and per-node data updates.
*/
export declare function diffTree(doc: LoroDoc, oldState: ArrayLike, newState: ArrayLike, containerId: ContainerID, schema: LoroTreeSchema<Record<string, SchemaType>> | undefined, inferOptions?: InferContainerOptions): Change[];
/**
* Finds the difference between two lists based on an idSelector function
*
* Time Complexity:
*
* - O(1) if not changed
* - O(n + klogk) for insertions/deletions/replacements, where k is the number of deletions
* - O(n) for one move op
* - Worst case O(n^2) for move op
*
* @param doc The LoroDoc instance
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID
* @param schema The schema for the container
* @param idSelector The idSelector function
* @returns The list of changes
*/
export declare function diffMovableList<S extends ArrayLike>(doc: LoroDoc, oldState: S, newState: S, containerId: ContainerID, schema: LoroListSchema<SchemaType> | LoroMovableListSchema<SchemaType> | undefined, idSelector: IdSelector<unknown>, inferOptions?: InferContainerOptions): Change[];
/**
* Finds the difference between two lists based on an idSelector function
*
* @param doc The LoroDoc instance
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID
* @param schema The schema for the container
* @param idSelector The idSelector function
* @returns The list of changes
*/
export declare function diffListWithIdSelector<S extends ArrayLike>(doc: LoroDoc, oldState: S, newState: S, containerId: ContainerID, schema: LoroListSchema<SchemaType> | undefined, idSelector: IdSelector<unknown>, inferOptions?: InferContainerOptions): Change[];
/**
* Diffs a [LoroList] between two states
*
* This function handles list diffing without an ID selector.
* This can result in less precise updates, and can cause clone/fork of items.
*
* If an ID selector is possible, use [diffMovableList] instead.
*
* @param doc The LoroDoc instance
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID of the list
* @param schema The schema for the container
* @returns The list of changes
*/
export declare function diffList<S extends ArrayLike>(doc: LoroDoc, oldState: S, newState: S, containerId: ContainerID, schema: LoroListSchema<SchemaType> | undefined, inferOptions?: InferContainerOptions): Change[];
/**
* Diffs a [LoroMap] between two states
*
* @param doc The LoroDoc instance
* @param oldState The old state
* @param newState The new state
* @param containerId The container ID of the map
* @param schema The schema for the container
* @returns The list of changes
*/
export declare function diffMap<S extends ObjectLike>(doc: LoroDoc, oldState: S, newState: S, containerId: ContainerID | "", schema: LoroMapSchema<Record<string, SchemaType>> | RootSchemaType<Record<string, ContainerSchemaType>> | undefined, inferOptions?: InferContainerOptions): Change[];
export {};
//# sourceMappingURL=diff.d.ts.map