1
0
silverbullet/plug-api/silverbullet-syscall/space.ts

93 lines
2.3 KiB
TypeScript
Raw Normal View History

import { syscall } from "./syscall.ts";
import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts";
export function listPages(unfiltered = false): Promise<PageMeta[]> {
return syscall("space.listPages", unfiltered);
}
export function getPageMeta(name: string): Promise<PageMeta> {
return syscall("space.getPageMeta", name);
}
export function readPage(
name: string,
): Promise<string> {
return syscall("space.readPage", name);
}
export function writePage(name: string, text: string): Promise<PageMeta> {
return syscall("space.writePage", name, text);
}
export function deletePage(name: string): Promise<void> {
return syscall("space.deletePage", name);
}
export function listPlugs(): Promise<string[]> {
return syscall("space.listPlugs");
}
2023-08-20 15:51:00 +00:00
export function listAttachments(): Promise<AttachmentMeta[]> {
return syscall("space.listAttachments");
}
export function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
return syscall("space.getAttachmentMeta", name);
}
2023-01-13 14:41:29 +00:00
/**
* Read an attachment from the space
* @param name path of the attachment to read
* @returns the attachment data encoded as a data URL
*/
export function readAttachment(
name: string,
2023-08-15 05:56:29 +00:00
): Promise<Uint8Array> {
return syscall("space.readAttachment", name);
}
2023-01-13 14:41:29 +00:00
/**
* Writes an attachment to the space
* @param name path of the attachment to write
* @param data data itself
* @returns
*/
export function writeAttachment(
name: string,
data: Uint8Array,
): Promise<AttachmentMeta> {
return syscall("space.writeAttachment", name, data);
}
2023-01-13 14:41:29 +00:00
/**
* Deletes an attachment from the space
* @param name path of the attachment to delete
*/
export function deleteAttachment(name: string): Promise<void> {
return syscall("space.deleteAttachment", name);
}
2023-08-20 15:51:00 +00:00
// FS
export function listFiles(): Promise<FileMeta[]> {
return syscall("space.listFiles");
}
export function readFile(name: string): Promise<Uint8Array> {
return syscall("space.readFile", name);
}
export function getFileMeta(name: string): Promise<FileMeta> {
return syscall("space.getFileMeta", name);
}
export function writeFile(
name: string,
data: Uint8Array,
): Promise<FileMeta> {
return syscall("space.writeFile", name, data);
}
export function deleteFile(name: string): Promise<void> {
return syscall("space.deleteFile", name);
}