The host-side handler for FS-adapter RPC. A later /api-backed adapter (mapping ops onto linXiv's /api/notes CRUD, or a real on-disk vault) will implement this; the signatures mirror the HostFsAdapter / FsDirHandle method surface the editor consumes. Each method returns the matching FsResult variant (or throws — the client serializes the error into a texbrain:fs:result { ok: false }).

interface FsResponder {
    list(
        path: string,
    ): Promise<
        {
            entries: { kind: "file"
            | "directory"; name: string }[];
            kind: "list";
        },
    >;
    mkdir(path: string): Promise<{ kind: "ok" }>;
    readFile(
        path: string,
    ): Promise<{ binary: boolean; data: string; kind: "readFile" }>;
    remove(path: string, recursive: boolean): Promise<{ kind: "ok" }>;
    writeFile(
        path: string,
        data: string,
        binary: boolean,
    ): Promise<{ kind: "ok" }>;
}

Implemented by

Methods

  • values() — list immediate children of a directory.

    Parameters

    • path: string

    Returns Promise<
        {
            entries: { kind: "file"
            | "directory"; name: string }[];
            kind: "list";
        },
    >

  • getDirectoryHandle(create) — create a directory.

    Parameters

    • path: string

    Returns Promise<{ kind: "ok" }>

  • getFile().text()/arrayBuffer() — read a file (base64 when binary).

    Parameters

    • path: string

    Returns Promise<{ binary: boolean; data: string; kind: "readFile" }>

  • removeEntry — delete a file or directory.

    Parameters

    • path: string
    • recursive: boolean

    Returns Promise<{ kind: "ok" }>

  • createWritable().write — write a file (data is base64 when binary).

    Parameters

    • path: string
    • data: string
    • binary: boolean

    Returns Promise<{ kind: "ok" }>