Large "query" plug refactor into "directive"
This commit is contained in:
@@ -125,7 +125,7 @@ export class HttpServer {
|
||||
eventSyscalls(this.eventHook),
|
||||
markdownSyscalls(buildMarkdown([])),
|
||||
esbuildSyscalls([this.globalModules]),
|
||||
systemSyscalls(this),
|
||||
systemSyscalls(this, this.system),
|
||||
sandboxSyscalls(this.system),
|
||||
assetSyscalls(this.system),
|
||||
// jwtSyscalls(),
|
||||
|
||||
@@ -1,18 +1,33 @@
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { Plug } from "../../plugos/plug.ts";
|
||||
import { SysCallMapping, System } from "../../plugos/system.ts";
|
||||
import type { HttpServer } from "../http_server.ts";
|
||||
|
||||
export function systemSyscalls(httpServer: HttpServer): SysCallMapping {
|
||||
export function systemSyscalls(
|
||||
httpServer: HttpServer,
|
||||
system: System<any>,
|
||||
): SysCallMapping {
|
||||
return {
|
||||
"system.invokeFunction": (
|
||||
ctx,
|
||||
env: string,
|
||||
// Ignored in this context, always assuming server (this place)
|
||||
_env: string,
|
||||
name: string,
|
||||
...args: any[]
|
||||
) => {
|
||||
if (!ctx.plug) {
|
||||
throw Error("No plug associated with context");
|
||||
}
|
||||
return ctx.plug.invoke(name, args);
|
||||
let plug: Plug<any> | undefined = ctx.plug;
|
||||
if (name.indexOf(".") !== -1) {
|
||||
// plug name in the name
|
||||
const [plugName, functionName] = name.split(".");
|
||||
plug = system.loadedPlugs.get(plugName);
|
||||
if (!plug) {
|
||||
throw Error(`Plug ${plugName} not found`);
|
||||
}
|
||||
name = functionName;
|
||||
}
|
||||
return plug.invoke(name, args);
|
||||
},
|
||||
"system.reloadPlugs": () => {
|
||||
return httpServer.reloadPlugs();
|
||||
|
||||
Reference in New Issue
Block a user