import type { Emitter, ot, IDisposable } from "@codesandbox/pitcher-common"; import type { file } from "@codesandbox/pitcher-protocol"; import type { IFile } from "./IFile"; export type SyncState = "SYNCED" | "RESYNCING"; export type ClientSelections = Map; export interface IIncomingOperationEvent { revision: number; clientSelections: ClientSelections; operation: ot.TextOperation; reason: ot.OperationReason; } export interface ISendOperationEvent { revision: number; operation: ot.TextOperation; } export interface IOperationAckEvent { revision: number; clientSelections: ClientSelections; } export interface ISelectionEvent { clientSelections: ClientSelections; reason?: file.SelectionsUpdateReason; } export interface IErrorEvent { error: string; metadata: Record; } export interface IDocument extends IDisposable { onIncomingOperation: Emitter["event"]; onOperationAck: Emitter["event"]; onSelection: Emitter["event"]; onError: Emitter["event"]; onResync: Emitter["event"]; file: IFile; otClient: ot.Client; clientSelections: ClientSelections; syncState: SyncState; /** * Resync is used when there is an internal issue with the OT Document, which means we can gracefully recover * changes made on the server with any pending/queued operations from the client */ resync(content: string, revision: number): void; /** * In extreme cases we want to be able to reset the otClient to the server state. We do this when the code editor * is not able to apply its operations to the OT Document or it has problems applying server operations to the code editor. There * is not good way to recover from this and it should really never happen. But if it does happen we can completely reset the OTClient with * the current server document and its revision */ reset(content: string, revision: number): void; sendDocumentAck(revision: number): Promise<{ revision: number; }>; sendDocumentOperation(operation: ot.TextOperation, revision: number): Promise<{ revision: number; }>; /** * Apply a text operation to the ot-client * * @param operation the operation to apply */ applyClient(operation: ot.TextOperation): void; sendSelection(selection: file.ISelection, reason?: file.SelectionsUpdateReason): Promise; dispose(): void; } //# sourceMappingURL=IDocument.d.ts.map