CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync/editor/generic/export.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { SortedPatchList } from "./sorted-patch-list";
7
import { Patch } from "./types";
8
9
export interface HistoryEntry {
10
time_utc: Date;
11
account_id: string;
12
patch?: any[];
13
patch_length?: number;
14
}
15
16
export interface HistoryExportOptions {
17
patches?: boolean;
18
patch_lengths?: boolean; // length of each patch (some measure of amount changed)
19
}
20
21
export function export_history(
22
account_ids: string[],
23
patch_list: SortedPatchList,
24
options: HistoryExportOptions
25
): HistoryEntry[] {
26
const patches: Patch[] = patch_list.export();
27
const entries: HistoryEntry[] = [];
28
for (const x of patches) {
29
const time_utc = x.time;
30
let account_id = account_ids[x.user_id];
31
if (account_id == null) {
32
account_id = "unknown"; // should never happen...
33
}
34
const entry: HistoryEntry = { time_utc, account_id };
35
if (options.patches) {
36
entry.patch = x.patch;
37
}
38
if (options.patch_lengths) {
39
entry.patch_length = JSON.stringify(x.patch).length;
40
}
41
entries.push(entry);
42
}
43
return entries;
44
}
45
46