Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/service/formatter.ts
1452 views
1
/*
2
Formatting services in a project.
3
*/
4
5
import { createServiceClient, createServiceHandler } from "./typed";
6
7
import type {
8
Options as FormatterOptions,
9
FormatResult,
10
} from "@cocalc/util/code-formatter";
11
12
// TODO: we may change it to NOT take compute server and have this listening from
13
// project and all compute servers... and have only the one with the file open
14
// actually reply.
15
interface FormatterApi {
16
formatter: (opts: {
17
path: string;
18
options: FormatterOptions;
19
}) => Promise<FormatResult>;
20
}
21
22
export function formatterClient({ compute_server_id = 0, project_id }) {
23
return createServiceClient<FormatterApi>({
24
project_id,
25
compute_server_id,
26
service: "formatter",
27
});
28
}
29
30
export async function createFormatterService({
31
compute_server_id = 0,
32
project_id,
33
impl,
34
}: {
35
project_id: string;
36
compute_server_id?: number;
37
impl: FormatterApi;
38
}) {
39
return await createServiceHandler<FormatterApi>({
40
project_id,
41
compute_server_id,
42
service: "formatter",
43
description: "Code formatter API",
44
impl,
45
});
46
}
47
48