Skip to content

Commit 978125e

Browse files
committed
api: add info to history query
1 parent 10e5b31 commit 978125e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ export interface Patch {
1414
};
1515
}
1616

17+
export interface HistoryInfo {
18+
doctype: string;
19+
init: { time: Date; size: number; error: string };
20+
last_active: Date;
21+
path: string;
22+
project_id: string;
23+
read_only: boolean;
24+
save: {
25+
state: string;
26+
error: string;
27+
hash: number;
28+
time: number;
29+
expected_hash: number;
30+
};
31+
string_id: string;
32+
users: string[];
33+
}
34+
1735
export interface Sync {
1836
history: (opts: {
1937
account_id?: string;

src/packages/conat/sync/akv.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export class AKV<T = any> {
141141
});
142142
};
143143

144+
// WARNING/TODO: this getAll implementation is not at all clever!
145+
// getAll = async () => {
146+
// const v: { [key: string]: T } = {};
147+
// for (const key of await this.keys()) {
148+
// v[key] = await this.get(key);
149+
// }
150+
// return v;
151+
// };
152+
144153
sqlite = async (
145154
statement: string,
146155
params?: any[],

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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";
4+
import { type Patch, type HistoryInfo } from "@cocalc/conat/hub/api/sync";
5+
import { client_db } from "@cocalc/util/db-schema/client-db";
56

67
export async function history({
78
account_id,
@@ -15,7 +16,7 @@ export async function history({
1516
path: string;
1617
start_seq?: number;
1718
end_seq?: number;
18-
}): Promise<{ patches: Patch[] }> {
19+
}): Promise<{ patches: Patch[]; info: HistoryInfo }> {
1920
if (!account_id || !(await isCollaborator({ account_id, project_id }))) {
2021
throw Error("user must be collaborator on source project");
2122
}
@@ -34,5 +35,18 @@ export async function history({
3435
})) {
3536
patches.push(patch as any);
3637
}
37-
return { patches };
38+
39+
const akv = client.sync.akv({
40+
name: `__dko__syncstrings:${client_db.sha1(project_id, path)}`,
41+
project_id,
42+
noInventory: true,
43+
});
44+
const keys = await akv.keys();
45+
const info: Partial<HistoryInfo> = {};
46+
for (const key of keys) {
47+
if (key[0] != "[") continue;
48+
info[JSON.parse(key)[1]] = await akv.get(key);
49+
}
50+
51+
return { patches, info: info as HistoryInfo };
3852
}

0 commit comments

Comments
 (0)