92 lines
3.1 KiB
TypeScript
92 lines
3.1 KiB
TypeScript
import { Schema } from "effect";
|
|
import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas";
|
|
import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings";
|
|
import { EditorId } from "./editor";
|
|
import { ProviderKind } from "./orchestration";
|
|
import { ThemePaletteDefinition } from "./theme";
|
|
|
|
const KeybindingsMalformedConfigIssue = Schema.Struct({
|
|
kind: Schema.Literal("keybindings.malformed-config"),
|
|
message: TrimmedNonEmptyString,
|
|
});
|
|
|
|
const KeybindingsInvalidEntryIssue = Schema.Struct({
|
|
kind: Schema.Literal("keybindings.invalid-entry"),
|
|
message: TrimmedNonEmptyString,
|
|
index: Schema.Number,
|
|
});
|
|
|
|
const ThemesMalformedConfigIssue = Schema.Struct({
|
|
kind: Schema.Literal("themes.malformed-config"),
|
|
message: TrimmedNonEmptyString,
|
|
});
|
|
|
|
const ThemesInvalidEntryIssue = Schema.Struct({
|
|
kind: Schema.Literal("themes.invalid-entry"),
|
|
message: TrimmedNonEmptyString,
|
|
index: Schema.Number,
|
|
});
|
|
|
|
export const ServerConfigIssue = Schema.Union([
|
|
KeybindingsMalformedConfigIssue,
|
|
KeybindingsInvalidEntryIssue,
|
|
ThemesMalformedConfigIssue,
|
|
ThemesInvalidEntryIssue,
|
|
]);
|
|
export type ServerConfigIssue = typeof ServerConfigIssue.Type;
|
|
|
|
const ServerConfigIssues = Schema.Array(ServerConfigIssue);
|
|
|
|
export const ServerProviderStatusState = Schema.Literals(["ready", "warning", "error"]);
|
|
export type ServerProviderStatusState = typeof ServerProviderStatusState.Type;
|
|
|
|
export const ServerProviderAuthStatus = Schema.Literals([
|
|
"authenticated",
|
|
"unauthenticated",
|
|
"unknown",
|
|
]);
|
|
export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
|
|
|
|
export const ServerProviderStatus = Schema.Struct({
|
|
provider: ProviderKind,
|
|
status: ServerProviderStatusState,
|
|
available: Schema.Boolean,
|
|
authStatus: ServerProviderAuthStatus,
|
|
checkedAt: IsoDateTime,
|
|
message: Schema.optional(TrimmedNonEmptyString),
|
|
});
|
|
export type ServerProviderStatus = typeof ServerProviderStatus.Type;
|
|
|
|
const ServerProviderStatuses = Schema.Array(ServerProviderStatus);
|
|
|
|
export const ServerConfig = Schema.Struct({
|
|
cwd: TrimmedNonEmptyString,
|
|
keybindingsConfigPath: TrimmedNonEmptyString,
|
|
themesConfigPath: TrimmedNonEmptyString,
|
|
keybindings: ResolvedKeybindingsConfig,
|
|
customThemes: Schema.Array(ThemePaletteDefinition),
|
|
issues: ServerConfigIssues,
|
|
providers: ServerProviderStatuses,
|
|
availableEditors: Schema.Array(EditorId),
|
|
});
|
|
export type ServerConfig = typeof ServerConfig.Type;
|
|
|
|
export const ServerUpsertKeybindingInput = KeybindingRule;
|
|
export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
|
|
|
|
export const ServerUpsertKeybindingResult = Schema.Struct({
|
|
keybindings: ResolvedKeybindingsConfig,
|
|
issues: ServerConfigIssues,
|
|
});
|
|
export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
|
|
|
|
export const ServerConfigUpdatedPayload = Schema.Struct({
|
|
issues: ServerConfigIssues,
|
|
providers: ServerProviderStatuses,
|
|
updated: Schema.Array(Schema.Literals(["keybindings", "themes", "providers"])).check(
|
|
Schema.isMinLength(1),
|
|
Schema.isMaxLength(3),
|
|
),
|
|
});
|
|
export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
|