Path: blob/master/src/packages/conat/service/formatter.ts
1452 views
/*1Formatting services in a project.2*/34import { createServiceClient, createServiceHandler } from "./typed";56import type {7Options as FormatterOptions,8FormatResult,9} from "@cocalc/util/code-formatter";1011// TODO: we may change it to NOT take compute server and have this listening from12// project and all compute servers... and have only the one with the file open13// actually reply.14interface FormatterApi {15formatter: (opts: {16path: string;17options: FormatterOptions;18}) => Promise<FormatResult>;19}2021export function formatterClient({ compute_server_id = 0, project_id }) {22return createServiceClient<FormatterApi>({23project_id,24compute_server_id,25service: "formatter",26});27}2829export async function createFormatterService({30compute_server_id = 0,31project_id,32impl,33}: {34project_id: string;35compute_server_id?: number;36impl: FormatterApi;37}) {38return await createServiceHandler<FormatterApi>({39project_id,40compute_server_id,41service: "formatter",42description: "Code formatter API",43impl,44});45}464748