Factored out materialized query providers

This commit is contained in:
Zef Hemel
2022-04-19 16:54:47 +02:00
parent 31254d15e6
commit c7176b00fa
31 changed files with 437 additions and 187 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ async function compile(
filePath: string,
functionName: string,
debug: boolean,
meta = true
meta = false
) {
let outFile = "_out.tmp";
let inFile = filePath;
+5 -1
View File
@@ -21,8 +21,12 @@ let syscallReqId = 0;
let vm = new VM({
sandbox: {
console,
setTimeout,
clearTimeout,
setInterval,
clearInterval,
require: (moduleName: string): any => {
console.log("Loading", moduleName);
// console.log("Loading", moduleName);
if (preloadModules.includes(moduleName)) {
return require(`${workerData}/${moduleName}`);
} else {
+7 -2
View File
@@ -12,10 +12,11 @@ export type EventHookT = {
export class EventHook implements Hook<EventHookT> {
private system?: System<EventHookT>;
async dispatchEvent(eventName: string, data?: any): Promise<void> {
async dispatchEvent(eventName: string, data?: any): Promise<any[]> {
if (!this.system) {
throw new Error("Event hook is not initialized");
}
let responses: any[] = [];
for (const plug of this.system.loadedPlugs.values()) {
for (const [name, functionDef] of Object.entries(
plug.manifest!.functions
@@ -23,11 +24,15 @@ export class EventHook implements Hook<EventHookT> {
if (functionDef.events && functionDef.events.includes(eventName)) {
// Only dispatch functions that can run in this environment
if (plug.canInvoke(name)) {
await plug.invoke(name, [data]);
let result = await plug.invoke(name, [data]);
if (result !== undefined) {
responses.push(result);
}
}
}
}
}
return responses;
}
apply(system: System<EventHookT>): void {