Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

server.ts

71 lines2.4 KB

1import { Schema } from "effect";
2import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas";
3import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings";
4import { EditorId } from "./editor";
5import { ProviderKind } from "./orchestration";
6​
7const KeybindingsMalformedConfigIssue = Schema.Struct({
8 kind: Schema.Literal("keybindings.malformed-config"),
9 message: TrimmedNonEmptyString,
10});
11​
12const KeybindingsInvalidEntryIssue = Schema.Struct({
13 kind: Schema.Literal("keybindings.invalid-entry"),
14 message: TrimmedNonEmptyString,
15 index: Schema.Number,
16});
17​
18export const ServerConfigIssue = Schema.Union([
19 KeybindingsMalformedConfigIssue,
20 KeybindingsInvalidEntryIssue,
21]);
22export type ServerConfigIssue = typeof ServerConfigIssue.Type;
23​
24const ServerConfigIssues = Schema.Array(ServerConfigIssue);
25​
26export const ServerProviderStatusState = Schema.Literals(["ready", "warning", "error"]);
27export type ServerProviderStatusState = typeof ServerProviderStatusState.Type;
28​
29export const ServerProviderAuthStatus = Schema.Literals([
30 "authenticated",
31 "unauthenticated",
32 "unknown",
33]);
34export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
35​
36export const ServerProviderStatus = Schema.Struct({
37 provider: ProviderKind,
38 status: ServerProviderStatusState,
39 available: Schema.Boolean,
40 authStatus: ServerProviderAuthStatus,
41 checkedAt: IsoDateTime,
42 message: Schema.optional(TrimmedNonEmptyString),
43});
44export type ServerProviderStatus = typeof ServerProviderStatus.Type;
45​
46const ServerProviderStatuses = Schema.Array(ServerProviderStatus);
47​
48export const ServerConfig = Schema.Struct({
49 cwd: TrimmedNonEmptyString,
50 keybindingsConfigPath: TrimmedNonEmptyString,
51 keybindings: ResolvedKeybindingsConfig,
52 issues: ServerConfigIssues,
53 providers: ServerProviderStatuses,
54 availableEditors: Schema.Array(EditorId),
55});
56export type ServerConfig = typeof ServerConfig.Type;
57​
58export const ServerUpsertKeybindingInput = KeybindingRule;
59export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
60​
61export const ServerUpsertKeybindingResult = Schema.Struct({
62 keybindings: ResolvedKeybindingsConfig,
63 issues: ServerConfigIssues,
64});
65export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
66​
67export const ServerConfigUpdatedPayload = Schema.Struct({
68 issues: ServerConfigIssues,
69 providers: ServerProviderStatuses,
70});
71export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;