|
| 1 | +import {Patch} from "../../json-crdt-patch"; |
| 2 | +import {PatchLog} from "../file/PatchLog"; |
| 3 | +import {Model} from "../model"; |
| 4 | + |
| 5 | +/** |
| 6 | + * A history of patches that have been applied to a model, stored on the |
| 7 | + * "remote": (1) server; (2) content addressable storage; or (3) peer-to-peer |
| 8 | + * network. |
| 9 | + * |
| 10 | + * Cases: |
| 11 | + * |
| 12 | + * - `RemoteHistoryServer` |
| 13 | + * - `RemoteHistoryServerIdempotent` |
| 14 | + * - `RemoteHistoryCAS` |
| 15 | + * - `RemoteHistoryP2P` |
| 16 | + */ |
| 17 | +export interface RemoteHistory<Cursor> { |
| 18 | + /** |
| 19 | + * Load latest state of the model, and any unmerged "tip" of patches |
| 20 | + * it might have. |
| 21 | + * |
| 22 | + * @todo Maybe `state` and `tip` should be serialized to JSON? |
| 23 | + */ |
| 24 | + loadLatest(id: string): Promise<[cursor: Cursor, state: Model]>; |
| 25 | + |
| 26 | + loadAfter(id: string, cursor: Cursor): Promise<[cursor: Cursor, tip: Patch[]]>; |
| 27 | + |
| 28 | + loadBefore(id: string, cursor: Cursor): Promise<[cursor: Cursor, state: Model, tip: Patch[]]>; |
| 29 | + |
| 30 | + apply(id: string, patches: Patch[]): Promise<void>; |
| 31 | + |
| 32 | + /** |
| 33 | + * Subscribe to the latest changes to the model. |
| 34 | + * @param callback |
| 35 | + */ |
| 36 | + subscribe(id: string, cursor: Cursor, callback: (changes: Patch[]) => void): void; |
| 37 | +} |
| 38 | + |
| 39 | +export interface LocalHistory { |
| 40 | + load(id: string): Promise<EditingSessionHistory>; |
| 41 | + // loadHistory(id: string): Promise<PatchLog>; |
| 42 | + apply(id: string, patches: Patch[]): Promise<void>; |
| 43 | +} |
| 44 | + |
| 45 | +export interface EditingSessionHistory { |
| 46 | + load(id: string): Promise<Model>; |
| 47 | + loadHistory(id: string): Promise<PatchLog>; |
| 48 | + undo(id: string): Promise<void>; |
| 49 | + redo(id: string): Promise<void>; |
| 50 | +} |
0 commit comments