Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/project/api/index.ts
1453 views
1
import { type System, system } from "./system";
2
import { type Editor, editor } from "./editor";
3
import { type Sync, sync } from "./sync";
4
import { handleErrorMessage } from "@cocalc/conat/util";
5
6
export interface ProjectApi {
7
system: System;
8
editor: Editor;
9
sync: Sync;
10
}
11
12
const ProjectApiStructure = {
13
system,
14
editor,
15
sync,
16
} as const;
17
18
export function initProjectApi(callProjectApi): ProjectApi {
19
const projectApi: any = {};
20
for (const group in ProjectApiStructure) {
21
if (projectApi[group] == null) {
22
projectApi[group] = {};
23
}
24
for (const functionName in ProjectApiStructure[group]) {
25
projectApi[group][functionName] = async (...args) =>
26
handleErrorMessage(
27
await callProjectApi({
28
name: `${group}.${functionName}`,
29
args,
30
}),
31
);
32
}
33
}
34
return projectApi as ProjectApi;
35
}
36
37