import type { SpacePrimitives } from "./space_primitives.ts"; import type { FileMeta } from "../../type/index.ts"; export class ReadOnlySpacePrimitives implements SpacePrimitives { wrapped: SpacePrimitives; constructor(wrapped: SpacePrimitives) { this.wrapped = wrapped; } async fetchFileList(): Promise { return (await this.wrapped.fetchFileList()).map((f: FileMeta) => ({ ...f, perm: "ro", })); } async readFile(path: string): Promise<{ meta: FileMeta; data: Uint8Array }> { const { meta, data } = await this.wrapped.readFile(path); return { meta: { ...meta, perm: "ro", }, data, }; } async getFileMeta(path: string, observing?: boolean): Promise { const meta = await this.wrapped.getFileMeta(path, observing); return { ...meta, perm: "ro", }; } writeFile(): Promise { throw new Error("Read only space, not allowed to write"); } deleteFile(): Promise { throw new Error("Read only space, not allowed to delete"); } }