import { CommitInfo, GetLocalStoreFn } from './types'; export type DocAndMetadata = { doc: Doc; metadata: CommitMetadata; }; export type CommitDoc = { ref: string; } & DocAndMetadata; export type ComputeRefFn = ( baseRef: string | undefined, mergeRef: string | undefined, delta: Delta | undefined, ) => string; export type DiffFn = ( prior: SavedDoc | undefined, doc: SavedDoc, ) => Delta | undefined; export type PatchFn = ( priorOrNext: SavedDoc | undefined, delta: Delta | undefined, ) => SavedDoc; export type AddNewCommitMetadataFn = ( metadata: CommitMetadata, commitRef: string, userId: string, clientId: string, ) => CommitMetadata; export interface DocCache { get: (ref: string) => CommitDoc | undefined; set: (ref: string, doc: CommitDoc) => void; has: (ref: string) => boolean; delete: (ref: string) => void; } export type MergeHelpers = { getCommitInfo(ref: string): CommitInfo; computeLatestDoc(ref: string): CommitDoc; addMerge( doc: LatestDoc, metadata: CommitMetadata, temp: boolean, leftRef: string, rightRef: string, ): string; }; export type MergeAllBranchesFn = ( branchHeadRefs: string[], helpers: MergeHelpers, ) => void; export type MigrateDocFn< SavedDoc, LatestDoc extends SavedDoc, CommitMetadata, > = ( doc: SavedDoc, metadata: CommitMetadata, ) => DocAndMetadata; export interface Differ { /** Computed the difference between two Docs */ readonly diff: DiffFn; /** Apply a patch from one Doc to another */ readonly patch: PatchFn; } export type TrimergeClientOptions< SavedDoc, LatestDoc extends SavedDoc, CommitMetadata, Delta, Presence, > = { readonly differ: Differ; /** Calculate the ref string for a given edit */ readonly computeRef: ComputeRefFn; /** Merge all head commits */ readonly mergeAllBranches: MergeAllBranchesFn; /** Get the Local commit store. */ readonly getLocalStore: GetLocalStoreFn; /** How to convert a historical format of your document to the latest version of the document. * If not supplied, the document will always be treated as if it is in the latest format. */ readonly migrate?: MigrateDocFn; readonly addNewCommitMetadata?: AddNewCommitMetadataFn; /** This is an optional entry point to an alternative storage system for documents. This allows * consumers of TrimergeClient to create snapshots of the document and cut off the recursive * building up of the Document. */ readonly docCache?: DocCache; };