refactor(server): canonicalize service API (#31049)

This commit is contained in:
Dax
2026-06-07 03:27:28 +00:00
committed by GitHub
parent 53ff1b57c9
commit fe0c4f8c74
388 changed files with 7103 additions and 4092 deletions
+52
View File
@@ -0,0 +1,52 @@
import { createContext, type JSX, useContext } from "solid-js"
export type PlatformFiles = Readonly<{
readText(path: string): Promise<string>
readBytes(path: string): Promise<Uint8Array>
mime(path: string): Promise<string>
}>
export type PlatformClipboardContent = Readonly<{
data: string
mime: string
}>
export type TuiPlatform = Readonly<{
files: PlatformFiles
state?: Readonly<{
read(): Promise<Record<string, unknown>>
write(value: Record<string, unknown>): Promise<void>
}>
themes?: Readonly<{
discover(): Promise<Record<string, unknown>>
subscribeRefresh?(refresh: () => void): () => void
}>
clipboard?: Readonly<{
read?(): Promise<PlatformClipboardContent | undefined>
write?(text: string): Promise<void>
}>
editor?: Readonly<{
open(input: Readonly<{ value: string; cwd?: string }>): Promise<string | undefined>
connection?(directory: string): Readonly<{ url: string; authToken?: string; source: string }> | undefined
selection?(directory: string): Promise<unknown>
}>
export?: Readonly<{
write(path: string, content: string): Promise<void>
}>
}>
const PlatformContext = createContext<TuiPlatform>()
export function TuiPlatformProvider(props: { value: TuiPlatform; children: JSX.Element }) {
return <PlatformContext.Provider value={props.value}>{props.children}</PlatformContext.Provider>
}
export function useTuiPlatform() {
const value = useContext(PlatformContext)
if (!value) throw new Error("TuiPlatformProvider is missing")
return value
}
export function useOptionalTuiPlatform() {
return useContext(PlatformContext)
}