Skip to content

Commit 10e5b31

Browse files
committed
sync api: add better structure/typing
1 parent 06278b3 commit 10e5b31

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/packages/conat/hub/api/sync.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import { authFirst } from "./util";
22

3+
export interface Patch {
4+
seq: number;
5+
time: number;
6+
mesg: {
7+
time: number;
8+
wall: number;
9+
patch: string;
10+
user_id: number;
11+
is_snapshot?: boolean;
12+
parents: number[];
13+
version?: number;
14+
};
15+
}
16+
317
export interface Sync {
418
history: (opts: {
519
account_id?: string;
620
project_id: string;
721
path: string;
8-
}) => Promise<any[]>;
22+
}) => Promise<{ patches: Patch[] }>;
923
}
1024

1125
export const sync = {
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { conat } from "@cocalc/backend/conat";
22
import isCollaborator from "@cocalc/server/projects/is-collaborator";
33
import { patchesStreamName } from "@cocalc/conat/sync/synctable-stream";
4+
import { type Patch } from "@cocalc/conat/hub/api/sync";
45

56
export async function history({
67
account_id,
78
project_id,
89
path,
910
start_seq = 0,
11+
end_seq,
1012
}: {
1113
account_id?: string;
1214
project_id: string;
1315
path: string;
14-
start_seq: number;
15-
}): Promise<any[]> {
16+
start_seq?: number;
17+
end_seq?: number;
18+
}): Promise<{ patches: Patch[] }> {
1619
if (!account_id || !(await isCollaborator({ account_id, project_id }))) {
1720
throw Error("user must be collaborator on source project");
1821
}
@@ -24,21 +27,12 @@ export async function history({
2427
project_id,
2528
noInventory: true,
2629
});
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);
30+
const patches: Patch[] = [];
31+
for await (const patch of await astream.getAll({
32+
start_seq,
33+
end_seq,
34+
})) {
35+
patches.push(patch as any);
4236
}
4337
return { patches };
4438
}

0 commit comments

Comments
 (0)