import type { FileMeta } from "../../plug-api/types.ts"; import type { SpacePrimitives } from "./space_primitives.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(name: string): Promise<{ meta: FileMeta; data: Uint8Array }> { const { meta, data } = await this.wrapped.readFile(name); return { meta: { ...meta, perm: "ro", }, data, }; } async getFileMeta(name: string): Promise { const meta = await this.wrapped.getFileMeta(name); 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"); } }