Skip to content

Commit 072b194

Browse files
committed
chore(json-crdt): 🤖 start a history folder
1 parent 3ec6776 commit 072b194

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/json-crdt/file/PatchLog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {ITimestampStruct, Patch, compare} from '../../json-crdt-patch';
22
import {printTree} from '../../util/print/printTree';
33
import {AvlMap} from '../../util/trees/avl/AvlMap';
44
import {Model} from '../model';
5-
import type {Printable} from '../../util/print/types';
65
import {first, next} from '../../util/trees/util';
6+
import type {Printable} from '../../util/print/types';
77

88
export class PatchLog implements Printable {
99
public static fromModel(model: Model<any>): PatchLog {

src/json-crdt/history/types.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)