Monorepo with yarn workspaces requires yarn 3.2
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { syscall } from "./syscall";
|
||||
|
||||
export async function dispatch(
|
||||
eventName: string,
|
||||
data: any,
|
||||
timeout?: number
|
||||
): Promise<any[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeouter: any = -1;
|
||||
if (timeout) {
|
||||
timeouter = setTimeout(() => {
|
||||
console.log("Timeout!");
|
||||
reject("timeout");
|
||||
}, timeout);
|
||||
}
|
||||
syscall("event.dispatch", eventName, data)
|
||||
.then((r) => {
|
||||
if (timeouter !== -1) {
|
||||
clearTimeout(timeouter);
|
||||
}
|
||||
resolve(r);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { syscall } from "./syscall";
|
||||
|
||||
export async function json(url: RequestInfo, init: RequestInit): Promise<any> {
|
||||
return syscall("fetch.json", url, init);
|
||||
}
|
||||
|
||||
export async function text(
|
||||
url: RequestInfo,
|
||||
init: RequestInit = {}
|
||||
): Promise<string> {
|
||||
return syscall("fetch.text", url, init);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@silverbulletmd/plugos-syscall",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { syscall } from "./syscall";
|
||||
|
||||
export async function run(
|
||||
cmd: string,
|
||||
args: string[]
|
||||
): Promise<{ stdout: string; stderr: string }> {
|
||||
return syscall("shell.run", cmd, args);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { syscall } from "./syscall";
|
||||
|
||||
export type KV = {
|
||||
key: string;
|
||||
value: any;
|
||||
};
|
||||
|
||||
export async function set(key: string, value: any): Promise<void> {
|
||||
return syscall("store.set", key, value);
|
||||
}
|
||||
|
||||
export async function batchSet(kvs: KV[]): Promise<void> {
|
||||
return syscall("store.batchSet", kvs);
|
||||
}
|
||||
|
||||
export async function get(key: string): Promise<any> {
|
||||
return syscall("store.get", key);
|
||||
}
|
||||
|
||||
export async function del(key: string): Promise<void> {
|
||||
return syscall("store.delete", key);
|
||||
}
|
||||
|
||||
export async function batchDel(keys: string[]): Promise<void> {
|
||||
return syscall("store.batchDelete", keys);
|
||||
}
|
||||
|
||||
export async function queryPrefix(
|
||||
prefix: string
|
||||
): Promise<{ key: string; value: any }[]> {
|
||||
return syscall("store.scanPrefix", prefix);
|
||||
}
|
||||
|
||||
export async function deletePrefix(prefix: string): Promise<void> {
|
||||
return syscall("store.deletePrefix", prefix);
|
||||
}
|
||||
|
||||
export async function deleteAll(): Promise<void> {
|
||||
return syscall("store.deleteAll");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
declare global {
|
||||
function syscall(name: string, ...args: any[]): Promise<any>;
|
||||
}
|
||||
|
||||
export const syscall = self.syscall;
|
||||
Reference in New Issue
Block a user