SilverBullet pivot to become an offline-first PWA (#403)
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
import type {
|
||||
ProxyFetchRequest,
|
||||
ProxyFetchResponse,
|
||||
} from "../../common/proxy_fetch.ts";
|
||||
import { base64Decode } from "../../plugos/asset_bundle/base64.ts";
|
||||
|
||||
export type SandboxFetchRequest = {
|
||||
method?: string;
|
||||
headers?: Record<string, string>;
|
||||
body?: string;
|
||||
};
|
||||
|
||||
export type SandboxFetchResponse = {
|
||||
ok: boolean;
|
||||
status: number;
|
||||
headers: Record<string, string>;
|
||||
// We base64 encode the body because the body can be binary data that we have to push through the worker boundary
|
||||
base64Body: string;
|
||||
};
|
||||
|
||||
export function sandboxFetch(
|
||||
url: string,
|
||||
options?: SandboxFetchRequest,
|
||||
): Promise<SandboxFetchResponse> {
|
||||
options?: ProxyFetchRequest,
|
||||
): Promise<ProxyFetchResponse> {
|
||||
// @ts-ignore: monkey patching fetch
|
||||
return syscall("sandboxFetch.fetch", url, options);
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { syscall } from "./syscall.ts";
|
||||
import type { FileMeta, ProxyFileSystem } from "./types.ts";
|
||||
|
||||
export class LocalFileSystem implements ProxyFileSystem {
|
||||
constructor(readonly root: string) {
|
||||
}
|
||||
|
||||
readFile(
|
||||
path: string,
|
||||
encoding: "utf8" | "dataurl" = "utf8",
|
||||
): Promise<string> {
|
||||
return syscall("fs.readFile", `${this.root}/${path}`, encoding);
|
||||
}
|
||||
|
||||
async getFileMeta(path: string): Promise<FileMeta> {
|
||||
return this.removeRootDir(
|
||||
await syscall("fs.getFileMeta", `${this.root}/${path}`),
|
||||
);
|
||||
}
|
||||
|
||||
writeFile(
|
||||
path: string,
|
||||
text: string,
|
||||
encoding: "utf8" | "dataurl" = "utf8",
|
||||
): Promise<FileMeta> {
|
||||
return syscall("fs.writeFile", `${this.root}/${path}`, text, encoding);
|
||||
}
|
||||
|
||||
deleteFile(path: string): Promise<void> {
|
||||
return syscall("fs.deleteFile", `${this.root}/${path}`);
|
||||
}
|
||||
|
||||
async listFiles(
|
||||
dirName: string,
|
||||
recursive = false,
|
||||
): Promise<FileMeta[]> {
|
||||
return (await syscall(
|
||||
"fs.listFiles",
|
||||
`${this.root}/${dirName}`,
|
||||
recursive,
|
||||
)).map(this.removeRootDir.bind(this));
|
||||
}
|
||||
|
||||
private removeRootDir(fileMeta: FileMeta): FileMeta {
|
||||
fileMeta.name = fileMeta.name.substring(this.root.length + 1);
|
||||
return fileMeta;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { syscall } from "./syscall.ts";
|
||||
|
||||
export function fullTextIndex(key: string, value: string) {
|
||||
return syscall("fulltext.index", key, value);
|
||||
}
|
||||
|
||||
export function fullTextDelete(key: string) {
|
||||
return syscall("fulltext.delete", key);
|
||||
}
|
||||
|
||||
export type FullTextSearchOptions = {
|
||||
limit?: number;
|
||||
highlightPrefix?: string;
|
||||
highlightPostfix?: string;
|
||||
highlightEllipsis?: string;
|
||||
summaryMaxLength?: number;
|
||||
};
|
||||
|
||||
export function fullTextSearch(
|
||||
phrase: string,
|
||||
options: FullTextSearchOptions = {},
|
||||
) {
|
||||
return syscall("fulltext.search", phrase, options);
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
export * as asset from "./asset.ts";
|
||||
export * as events from "./event.ts";
|
||||
// export * as fs from "./fs.ts";
|
||||
export { LocalFileSystem } from "./fs.ts";
|
||||
export * as sandbox from "./sandbox.ts";
|
||||
export * as fulltext from "./fulltext.ts";
|
||||
export * as shell from "./shell.ts";
|
||||
export * as store from "./store.ts";
|
||||
export * as YAML from "./yaml.ts";
|
||||
export * from "./syscall.ts";
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { LogEntry } from "../../plugos/sandbox.ts";
|
||||
|
||||
export function getLogs(): Promise<LogEntry[]> {
|
||||
return syscall("sandbox.getLogs");
|
||||
}
|
||||
@@ -3,6 +3,6 @@ import { syscall } from "./syscall.ts";
|
||||
export function run(
|
||||
cmd: string,
|
||||
args: string[],
|
||||
): Promise<{ stdout: string; stderr: string }> {
|
||||
): Promise<{ stdout: string; stderr: string; code: number }> {
|
||||
return syscall("shell.run", cmd, args);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ export function get(key: string): Promise<any> {
|
||||
return syscall("store.get", key);
|
||||
}
|
||||
|
||||
export function batchGet(keys: string[]): Promise<(any | undefined)[]> {
|
||||
return syscall("store.batchGet", keys);
|
||||
}
|
||||
|
||||
export function has(key: string): Promise<boolean> {
|
||||
return syscall("store.has", key);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
export type FileMeta = {
|
||||
name: string;
|
||||
lastModified: number;
|
||||
};
|
||||
|
||||
export interface ProxyFileSystem {
|
||||
readFile(
|
||||
path: string,
|
||||
encoding: "utf8" | "dataurl",
|
||||
): Promise<string>;
|
||||
|
||||
getFileMeta(path: string): Promise<FileMeta>;
|
||||
|
||||
writeFile(
|
||||
path: string,
|
||||
text: string,
|
||||
encoding: "utf8" | "dataurl",
|
||||
): Promise<FileMeta>;
|
||||
|
||||
deleteFile(path: string): Promise<void>;
|
||||
|
||||
listFiles(
|
||||
path: string,
|
||||
): Promise<FileMeta[]>;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { syscall } from "./syscall.ts";
|
||||
|
||||
export function parse(
|
||||
text: string,
|
||||
): Promise<any> {
|
||||
return syscall("yaml.parse", text);
|
||||
}
|
||||
|
||||
export function stringify(
|
||||
obj: any,
|
||||
): Promise<string> {
|
||||
return syscall("yaml.stringify", obj);
|
||||
}
|
||||
Reference in New Issue
Block a user