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

server.ts

82 lines3.2 KB

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