Skip to content

Commit 06278b3

Browse files
committed
api: implement getting all patches associate to a document
1 parent ac5d9ae commit 06278b3

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/packages/conat/core/client.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,14 +1450,13 @@ export class Client extends EventEmitter {
14501450
sync = {
14511451
dkv: async <T,>(opts: DKVOptions): Promise<DKV<T>> =>
14521452
await dkv<T>({ ...opts, client: this }),
1453-
akv: async <T,>(opts: DKVOptions): Promise<AKV<T>> =>
1454-
await akv<T>({ ...opts, client: this }),
1453+
akv: <T,>(opts: DKVOptions): AKV<T> => akv<T>({ ...opts, client: this }),
14551454
dko: async <T,>(opts: DKVOptions): Promise<DKO<T>> =>
14561455
await dko<T>({ ...opts, client: this }),
14571456
dstream: async <T,>(opts: DStreamOptions): Promise<DStream<T>> =>
14581457
await dstream<T>({ ...opts, client: this }),
1459-
astream: async <T,>(opts: DStreamOptions): Promise<AStream<T>> =>
1460-
await astream<T>({ ...opts, client: this }),
1458+
astream: <T,>(opts: DStreamOptions): AStream<T> =>
1459+
astream<T>({ ...opts, client: this }),
14611460
synctable: async (opts: SyncTableOptions): Promise<ConatSyncTable> =>
14621461
await createSyncTable({ ...opts, client: this }),
14631462
};

src/packages/conat/sync/astream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class AStream<T = any> {
9999
// or network is flaky, but will return all data properly in order
100100
// then throw an exception with code 503 rather than returning data
101101
// with something skipped.
102-
async *getAll(opts): AsyncGenerator<
102+
async *getAll(opts?): AsyncGenerator<
103103
{
104104
mesg: T;
105105
headers?: Headers;
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
1-
//import { conat } from "@cocalc/backend/conat";
1+
import { conat } from "@cocalc/backend/conat";
22
import isCollaborator from "@cocalc/server/projects/is-collaborator";
3+
import { patchesStreamName } from "@cocalc/conat/sync/synctable-stream";
34

45
export async function history({
56
account_id,
67
project_id,
78
path,
9+
start_seq = 0,
810
}: {
911
account_id?: string;
1012
project_id: string;
1113
path: string;
14+
start_seq: number;
1215
}): Promise<any[]> {
1316
if (!account_id || !(await isCollaborator({ account_id, project_id }))) {
1417
throw Error("user must be collaborator on source project");
1518
}
1619

17-
// const client = conat();
18-
// this will be much easier once the fs2 branch is merged
19-
throw Error(`not implemented yet -- can't get history of ${path} yet`);
20+
const client = conat();
21+
const name = patchesStreamName({ project_id, path });
22+
const astream = client.sync.astream({
23+
name,
24+
project_id,
25+
noInventory: true,
26+
});
27+
const patches: {
28+
seq: number;
29+
time: number;
30+
mesg: {
31+
time: number;
32+
wall: number;
33+
patch: string;
34+
user_id: number;
35+
is_snapshot?: boolean;
36+
parents: number[];
37+
version?: number;
38+
};
39+
}[] = [];
40+
for await (const patch of await astream.getAll({ start_seq })) {
41+
patches.push(patch);
42+
}
43+
return { patches };
2044
}

0 commit comments

Comments
 (0)