Massive restructure of plugin API

This commit is contained in:
Zef Hemel
2022-10-14 15:11:33 +02:00
parent 982623fc38
commit 7d28b53b75
70 changed files with 826 additions and 969 deletions
@@ -0,0 +1,13 @@
import { syscall } from "./syscall.ts";
export function set(key: string, value: any): Promise<void> {
return syscall("clientStore.set", key, value);
}
export function get(key: string): Promise<any> {
return syscall("clientStore.get", key);
}
export function del(key: string): Promise<void> {
return syscall("clientStore.delete", key);
}
+116
View File
@@ -0,0 +1,116 @@
import { syscall } from "./syscall.ts";
import { FilterOption } from "../../common/types.ts";
export function getCurrentPage(): Promise<string> {
return syscall("editor.getCurrentPage");
}
export function setPage(newName: string): Promise<void> {
return syscall("editor.setPage", newName);
}
export function getText(): Promise<string> {
return syscall("editor.getText");
}
export function getCursor(): Promise<number> {
return syscall("editor.getCursor");
}
export function getSelection(): Promise<{ from: number; to: number }> {
return syscall("editor.getSelection");
}
export function setSelection(from: number, to: number): Promise<void> {
return syscall("editor.setSelection", from, to);
}
export function save(): Promise<void> {
return syscall("editor.save");
}
export function navigate(
name: string,
pos?: string | number,
replaceState = false,
): Promise<void> {
return syscall("editor.navigate", name, pos, replaceState);
}
export function reloadPage(): Promise<void> {
return syscall("editor.reloadPage");
}
export function openUrl(url: string): Promise<void> {
return syscall("editor.openUrl", url);
}
export function flashNotification(
message: string,
type: "info" | "error" = "info",
): Promise<void> {
return syscall("editor.flashNotification", message, type);
}
export function filterBox(
label: string,
options: FilterOption[],
helpText = "",
placeHolder = "",
): Promise<FilterOption | undefined> {
return syscall("editor.filterBox", label, options, helpText, placeHolder);
}
export function showPanel(
id: "lhs" | "rhs" | "bhs" | "modal",
mode: number,
html: string,
script = "",
): Promise<void> {
return syscall("editor.showPanel", id, mode, html, script);
}
export function hidePanel(id: "lhs" | "rhs" | "bhs" | "modal"): Promise<void> {
return syscall("editor.hidePanel", id);
}
export function insertAtPos(text: string, pos: number): Promise<void> {
return syscall("editor.insertAtPos", text, pos);
}
export function replaceRange(
from: number,
to: number,
text: string,
): Promise<void> {
return syscall("editor.replaceRange", from, to, text);
}
export function moveCursor(pos: number): Promise<void> {
return syscall("editor.moveCursor", pos);
}
export function insertAtCursor(text: string): Promise<void> {
return syscall("editor.insertAtCursor", text);
}
export function matchBefore(
re: string,
): Promise<{ from: number; to: number; text: string } | null> {
return syscall("editor.matchBefore", re);
}
export function dispatch(change: any): Promise<void> {
return syscall("editor.dispatch", change);
}
export function prompt(
message: string,
defaultValue = "",
): Promise<string | undefined> {
return syscall("editor.prompt", message, defaultValue);
}
export function enableReadOnlyMode(enabled: boolean) {
return syscall("editor.enableReadOnlyMode", enabled);
}
+54
View File
@@ -0,0 +1,54 @@
import type { Query } from "../plugos-syscall/store.ts";
import { syscall } from "./syscall.ts";
export type KV = {
key: string;
value: any;
};
export function set(
page: string,
key: string,
value: any,
): Promise<void> {
return syscall("index.set", page, key, value);
}
export function batchSet(page: string, kvs: KV[]): Promise<void> {
return syscall("index.batchSet", page, kvs);
}
export function get(page: string, key: string): Promise<any> {
return syscall("index.get", page, key);
}
export function del(page: string, key: string): Promise<void> {
return syscall("index.delete", page, key);
}
export function queryPrefix(
prefix: string,
): Promise<{ key: string; page: string; value: any }[]> {
return syscall("index.queryPrefix", prefix);
}
export function query(
query: Query,
): Promise<{ key: string; page: string; value: any }[]> {
return syscall("index.query", query);
}
export function clearPageIndexForPage(page: string): Promise<void> {
return syscall("index.clearPageIndexForPage", page);
}
export function deletePrefixForPage(
page: string,
prefix: string,
): Promise<void> {
return syscall("index.deletePrefixForPage", page, prefix);
}
export function clearPageIndex(): Promise<void> {
return syscall("index.clearPageIndex");
}
@@ -0,0 +1,7 @@
import { syscall } from "./syscall.ts";
import type { ParseTree } from "$sb/lib/tree.ts";
export function parseMarkdown(text: string): Promise<ParseTree> {
return syscall("markdown.parseMarkdown", text);
}
+7
View File
@@ -0,0 +1,7 @@
export * as clientStore from "./clientStore.ts";
export * as editor from "./editor.ts";
export * as index from "./index.ts";
export * as markdown from "./markdown.ts";
export * as sandbox from "./sandbox.ts";
export * as space from "./space.ts";
export * as system from "./system.ts";
+5
View File
@@ -0,0 +1,5 @@
import type { LogEntry } from "../../plugos/sandbox.ts";
export function getServerLogs(): Promise<LogEntry[]> {
return syscall("sandbox.getServerLogs");
}
+54
View File
@@ -0,0 +1,54 @@
import { syscall } from "./syscall.ts";
import { AttachmentMeta, PageMeta } from "../../common/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");
}
export function listAttachments(): Promise<PageMeta[]> {
return syscall("space.listAttachments");
}
export function getAttachmentMeta(name: string): Promise<AttachmentMeta> {
return syscall("space.getAttachmentMeta", name);
}
export function readAttachment(
name: string,
): Promise<string> {
return syscall("space.readAttachment", name);
}
export function writeAttachment(
name: string,
encoding: "string" | "dataurl",
data: string,
): Promise<AttachmentMeta> {
return syscall("space.writeAttachment", name, encoding, data);
}
export function deleteAttachment(name: string): Promise<void> {
return syscall("space.deleteAttachment", name);
}
+16
View File
@@ -0,0 +1,16 @@
declare global {
function syscall(name: string, ...args: any[]): Promise<any>;
}
// This is the case when running tests only, so giving it a dummy syscall function
if (typeof self === "undefined") {
// @ts-ignore: test
// deno-lint-ignore no-global-assign
self = {
syscall: () => {
throw new Error("Not implemented here");
},
};
}
export const syscall = self.syscall;
+24
View File
@@ -0,0 +1,24 @@
import type { CommandDef } from "../../web/hooks/command.ts";
import { syscall } from "./syscall.ts";
export function invokeFunction(
env: string,
name: string,
...args: any[]
): Promise<any> {
return syscall("system.invokeFunction", env, name, ...args);
}
// Only available on the client
export function invokeCommand(name: string): Promise<any> {
return syscall("system.invokeCommand", name);
}
// Only available on the client
export function listCommands(): Promise<{ [key: string]: CommandDef }> {
return syscall("system.listCommands");
}
export function reloadPlugs() {
syscall("system.reloadPlugs");
}