2023-10-03 12:16:33 +00:00
|
|
|
import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts";
|
2023-08-04 16:56:55 +00:00
|
|
|
import { SysCallMapping } from "../../plugos/system.ts";
|
|
|
|
import type { Space } from "../../web/space.ts";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Almost the same as web/syscalls/space.ts except leaving out client-specific stuff
|
|
|
|
*/
|
|
|
|
export function spaceSyscalls(space: Space): SysCallMapping {
|
|
|
|
return {
|
|
|
|
"space.listPages": (): Promise<PageMeta[]> => {
|
|
|
|
return space.fetchPageList();
|
|
|
|
},
|
|
|
|
"space.readPage": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
): Promise<string> => {
|
|
|
|
return (await space.readPage(name)).text;
|
|
|
|
},
|
|
|
|
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
|
|
|
|
return space.getPageMeta(name);
|
|
|
|
},
|
|
|
|
"space.writePage": (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
text: string,
|
|
|
|
): Promise<PageMeta> => {
|
|
|
|
return space.writePage(name, text);
|
|
|
|
},
|
|
|
|
"space.deletePage": async (_ctx, name: string) => {
|
|
|
|
await space.deletePage(name);
|
|
|
|
},
|
|
|
|
"space.listPlugs": (): Promise<string[]> => {
|
|
|
|
return space.listPlugs();
|
|
|
|
},
|
|
|
|
"space.listAttachments": async (): Promise<AttachmentMeta[]> => {
|
|
|
|
return await space.fetchAttachmentList();
|
|
|
|
},
|
|
|
|
"space.readAttachment": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
): Promise<Uint8Array> => {
|
|
|
|
return (await space.readAttachment(name)).data;
|
|
|
|
},
|
|
|
|
"space.getAttachmentMeta": async (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return await space.getAttachmentMeta(name);
|
|
|
|
},
|
|
|
|
"space.writeAttachment": (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
data: Uint8Array,
|
|
|
|
): Promise<AttachmentMeta> => {
|
|
|
|
return space.writeAttachment(name, data);
|
|
|
|
},
|
|
|
|
"space.deleteAttachment": async (_ctx, name: string) => {
|
|
|
|
await space.deleteAttachment(name);
|
|
|
|
},
|
2023-08-20 15:51:00 +00:00
|
|
|
|
|
|
|
// FS
|
|
|
|
"space.listFiles": (): Promise<FileMeta[]> => {
|
|
|
|
return space.spacePrimitives.fetchFileList();
|
|
|
|
},
|
|
|
|
"space.getFileMeta": (_ctx, name: string): Promise<FileMeta> => {
|
|
|
|
return space.spacePrimitives.getFileMeta(name);
|
|
|
|
},
|
|
|
|
"space.readFile": async (_ctx, name: string): Promise<Uint8Array> => {
|
|
|
|
return (await space.spacePrimitives.readFile(name)).data;
|
|
|
|
},
|
|
|
|
"space.writeFile": (
|
|
|
|
_ctx,
|
|
|
|
name: string,
|
|
|
|
data: Uint8Array,
|
|
|
|
): Promise<FileMeta> => {
|
|
|
|
return space.spacePrimitives.writeFile(name, data);
|
|
|
|
},
|
|
|
|
"space.deleteFile": (_ctx, name: string) => {
|
|
|
|
return space.spacePrimitives.deleteFile(name);
|
|
|
|
},
|
2023-08-04 16:56:55 +00:00
|
|
|
};
|
|
|
|
}
|