From f0d09a51e666bfee0cbee6dc54cc89a47e4ef459 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 12 Jul 2022 12:30:15 +0200 Subject: [PATCH] Exposed "store" syscalls to client and server environments --- packages/server/express_server.ts | 10 ++++++++-- packages/web/editor.tsx | 2 ++ packages/web/syscalls/store.ts | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 packages/web/syscalls/store.ts diff --git a/packages/server/express_server.ts b/packages/server/express_server.ts index e153cc2d..b6da35b9 100644 --- a/packages/server/express_server.ts +++ b/packages/server/express_server.ts @@ -10,7 +10,7 @@ import bodyParser from "body-parser"; import { EventHook } from "@plugos/plugos/hooks/event"; import spaceSyscalls from "./syscalls/space"; import { eventSyscalls } from "@plugos/plugos/syscalls/event"; -import { ensureTable, pageIndexSyscalls } from "./syscalls"; +import { ensureTable as ensureIndexTable, pageIndexSyscalls } from "./syscalls"; import knex, { Knex } from "knex"; import shellSyscalls from "@plugos/plugos/syscalls/shell.node"; import { NodeCronHook } from "@plugos/plugos/hooks/node_cron"; @@ -49,6 +49,10 @@ import { PlugSpacePrimitives } from "./hooks/plug_space_primitives"; import { PageNamespaceHook } from "./hooks/page_namespace"; import { readFileSync } from "fs"; import fileSystemSyscalls from "@plugos/plugos/syscalls/fs.node"; +import { + storeSyscalls, + ensureTable as ensureStoreTable, +} from "@plugos/plugos/syscalls/store.knex_node"; const safeFilename = /^[a-zA-Z0-9_\-\.]+$/; @@ -117,6 +121,7 @@ export class ExpressServer { this.system.registerSyscalls( [], pageIndexSyscalls(this.db), + storeSyscalls(this.db, "store"), fullTextSearchSyscalls(this.db, "fts"), spaceSyscalls(this.space), eventSyscalls(this.eventHook), @@ -260,7 +265,8 @@ export class ExpressServer { next(); }; - await ensureTable(this.db); + await ensureIndexTable(this.db); + await ensureStoreTable(this.db, "store"); await ensureFTSTable(this.db, "fts"); await this.ensureIndexPage(); diff --git a/packages/web/editor.tsx b/packages/web/editor.tsx index f5fc1c8f..3aa4cd25 100644 --- a/packages/web/editor.tsx +++ b/packages/web/editor.tsx @@ -60,6 +60,7 @@ import { FilterOption, PageMeta } from "@silverbulletmd/common/types"; import { syntaxTree } from "@codemirror/language"; import sandboxSyscalls from "@plugos/plugos/syscalls/sandbox"; import { eventSyscalls } from "@plugos/plugos/syscalls/event"; +import { storeSyscalls } from "./syscalls/store"; class PageState { constructor( @@ -155,6 +156,7 @@ export class Editor { systemSyscalls(this), markdownSyscalls(buildMarkdown(this.mdExtensions)), clientStoreSyscalls(), + storeSyscalls(this.space), sandboxSyscalls(this.system) ); diff --git a/packages/web/syscalls/store.ts b/packages/web/syscalls/store.ts new file mode 100644 index 00000000..10eacde4 --- /dev/null +++ b/packages/web/syscalls/store.ts @@ -0,0 +1,17 @@ +import { SysCallMapping } from "@plugos/plugos/system"; +import { proxySyscalls } from "@plugos/plugos/syscalls/transport"; +import { Space } from "@silverbulletmd/common/spaces/space"; + +export function storeSyscalls(space: Space): SysCallMapping { + return proxySyscalls( + [ + "store.queryPrefix", + "store.get", + "store.set", + "store.batchSet", + "store.delete", + "store.deletePrefix", + ], + (ctx, name, ...args) => space.proxySyscall(ctx.plug, name, args) + ); +}