Exposed "store" syscalls to client and server environments

website
Zef Hemel 2022-07-12 12:30:15 +02:00
parent 8a10369d91
commit f0d09a51e6
3 changed files with 27 additions and 2 deletions

View File

@ -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();

View File

@ -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)
);

View File

@ -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)
);
}