diff --git a/.idea/silverbullet.iml b/.idea/silverbullet.iml index 5e764c4..b1375a5 100644 --- a/.idea/silverbullet.iml +++ b/.idea/silverbullet.iml @@ -2,7 +2,9 @@ - + + + diff --git a/package.json b/package.json index dbe2c15..7abe71f 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "context": "node" }, "test": { - "source": ["plugs/lib/tree.test.ts"], + "source": ["plugs/lib/tree.test.ts", "webapp/spaces/sync.test.ts"], "outputFormat": "commonjs", "isLibrary": true, "context": "node" @@ -64,6 +64,7 @@ "cors": "^2.8.5", "events": "^3.3.0", "express": "^4.17.3", + "dexie": "^3.2.1", "jest": "^27.5.1", "knex": "^1.0.4", "node-cron": "^3.0.0", @@ -75,6 +76,8 @@ "supertest": "^6.2.2", "vm2": "^3.9.9", "yaml": "^1.10.2", + "fake-indexeddb": "^3.1.7", + "yargs": "^17.3.1" }, "devDependencies": { diff --git a/plugos-silverbullet-syscall/editor.ts b/plugos-silverbullet-syscall/editor.ts index 66567a2..16249f6 100644 --- a/plugos-silverbullet-syscall/editor.ts +++ b/plugos-silverbullet-syscall/editor.ts @@ -1,4 +1,4 @@ -import {syscall} from "./syscall"; +import { syscall } from "./syscall"; export function getCurrentPage(): Promise { return syscall("editor.getCurrentPage"); diff --git a/plugos-silverbullet-syscall/markdown.ts b/plugos-silverbullet-syscall/markdown.ts index 88b98ba..de11461 100644 --- a/plugos-silverbullet-syscall/markdown.ts +++ b/plugos-silverbullet-syscall/markdown.ts @@ -1,5 +1,5 @@ -import {syscall} from "./syscall"; -import type {MarkdownTree} from "../common/tree"; +import { syscall } from "./syscall"; +import type { MarkdownTree } from "../common/tree"; export async function parseMarkdown(text: string): Promise { return syscall("markdown.parseMarkdown", text); diff --git a/plugos-silverbullet-syscall/system.ts b/plugos-silverbullet-syscall/system.ts index 3e2598c..c57312e 100644 --- a/plugos-silverbullet-syscall/system.ts +++ b/plugos-silverbullet-syscall/system.ts @@ -1,6 +1,7 @@ import { syscall } from "./syscall"; -export async function invokeFunctionOnServer( +export async function invokeFunction( + env: string, name: string, ...args: any[] ): Promise { diff --git a/plugos/bin/plugos-server.ts b/plugos/bin/plugos-server.ts index 8f9ab8e..f219243 100755 --- a/plugos/bin/plugos-server.ts +++ b/plugos/bin/plugos-server.ts @@ -2,18 +2,18 @@ import express from "express"; import yargs from "yargs"; -import {hideBin} from "yargs/helpers"; -import {DiskPlugLoader} from "../plug_loader"; -import {CronHookT, NodeCronHook} from "../hooks/node_cron"; +import { hideBin } from "yargs/helpers"; +import { DiskPlugLoader } from "../plug_loader"; +import { CronHookT, NodeCronHook } from "../hooks/node_cron"; import shellSyscalls from "../syscalls/shell.node"; -import {System} from "../system"; -import {EndpointHook, EndpointHookT} from "../hooks/endpoint"; -import {safeRun} from "../util"; +import { System } from "../system"; +import { EndpointHook, EndpointHookT } from "../hooks/endpoint"; +import { safeRun } from "../util"; import knex from "knex"; -import {ensureTable, storeSyscalls} from "../syscalls/store.knex_node"; -import {fetchSyscalls} from "../syscalls/fetch.node"; -import {EventHook, EventHookT} from "../hooks/event"; -import {eventSyscalls} from "../syscalls/event"; +import { ensureTable, storeSyscalls } from "../syscalls/store.knex_node"; +import { fetchSyscalls } from "../syscalls/fetch.node"; +import { EventHook, EventHookT } from "../hooks/event"; +import { eventSyscalls } from "../syscalls/event"; let args = yargs(hideBin(process.argv)) .option("port", { diff --git a/plugos/environments/sandbox_worker.ts b/plugos/environments/sandbox_worker.ts index afde0c6..46414d8 100644 --- a/plugos/environments/sandbox_worker.ts +++ b/plugos/environments/sandbox_worker.ts @@ -1,5 +1,5 @@ -import {safeRun} from "../util"; -import {ControllerMessage, WorkerMessage} from "./worker"; +import { safeRun } from "../util"; +import { ControllerMessage, WorkerMessage } from "./worker"; let loadedFunctions = new Map(); let pendingRequests = new Map< diff --git a/plugos/hooks/event.ts b/plugos/hooks/event.ts index 34c178a..df0c231 100644 --- a/plugos/hooks/event.ts +++ b/plugos/hooks/event.ts @@ -1,6 +1,6 @@ -import {Hook, Manifest} from "../types"; -import {System} from "../system"; -import {safeRun} from "../util"; +import { Hook, Manifest } from "../types"; +import { System } from "../system"; +import { safeRun } from "../util"; // System events: // - plug:load (plugName: string) diff --git a/plugos/runtime.test.ts b/plugos/runtime.test.ts index a38ac34..2fa2528 100644 --- a/plugos/runtime.test.ts +++ b/plugos/runtime.test.ts @@ -1,6 +1,6 @@ -import {createSandbox} from "./environments/node_sandbox"; -import {expect, test} from "@jest/globals"; -import {System} from "./system"; +import { createSandbox } from "./environments/node_sandbox"; +import { expect, test } from "@jest/globals"; +import { System } from "./system"; test("Run a Node sandbox", async () => { let system = new System("server"); diff --git a/plugos/syscalls/event.ts b/plugos/syscalls/event.ts index 2492ea7..b109af9 100644 --- a/plugos/syscalls/event.ts +++ b/plugos/syscalls/event.ts @@ -1,5 +1,5 @@ -import {SysCallMapping} from "../system"; -import {EventHook} from "../hooks/event"; +import { SysCallMapping } from "../system"; +import { EventHook } from "../hooks/event"; export function eventSyscalls(eventHook: EventHook): SysCallMapping { return { diff --git a/plugos/syscalls/fetch.node.ts b/plugos/syscalls/fetch.node.ts index 805e9f3..61520e6 100644 --- a/plugos/syscalls/fetch.node.ts +++ b/plugos/syscalls/fetch.node.ts @@ -1,5 +1,5 @@ -import fetch, {RequestInfo, RequestInit} from "node-fetch"; -import {SysCallMapping} from "../system"; +import fetch, { RequestInfo, RequestInit } from "node-fetch"; +import { SysCallMapping } from "../system"; export function fetchSyscalls(): SysCallMapping { return { diff --git a/plugos/syscalls/shell.node.ts b/plugos/syscalls/shell.node.ts index 1bc8de2..c4eeb24 100644 --- a/plugos/syscalls/shell.node.ts +++ b/plugos/syscalls/shell.node.ts @@ -1,6 +1,6 @@ -import {promisify} from "util"; -import {execFile} from "child_process"; -import type {SysCallMapping} from "../system"; +import { promisify } from "util"; +import { execFile } from "child_process"; +import type { SysCallMapping } from "../system"; const execFilePromise = promisify(execFile); diff --git a/plugos/syscalls/store.dexie_browser.test.ts b/plugos/syscalls/store.dexie_browser.test.ts index 693a60b..124ecd3 100644 --- a/plugos/syscalls/store.dexie_browser.test.ts +++ b/plugos/syscalls/store.dexie_browser.test.ts @@ -1,7 +1,7 @@ -import {createSandbox} from "../environments/node_sandbox"; -import {expect, test} from "@jest/globals"; -import {System} from "../system"; -import {storeSyscalls} from "./store.dexie_browser"; +import { createSandbox } from "../environments/node_sandbox"; +import { expect, test } from "@jest/globals"; +import { System } from "../system"; +import { storeSyscalls } from "./store.dexie_browser"; // For testing in node.js require("fake-indexeddb/auto"); diff --git a/plugos/syscalls/store.dexie_browser.ts b/plugos/syscalls/store.dexie_browser.ts index 9c1467c..6a91fb4 100644 --- a/plugos/syscalls/store.dexie_browser.ts +++ b/plugos/syscalls/store.dexie_browser.ts @@ -1,5 +1,5 @@ import Dexie from "dexie"; -import {SysCallMapping} from "../system"; +import { SysCallMapping } from "../system"; export type KV = { key: string; diff --git a/plugos/syscalls/store.knex_node.test.ts b/plugos/syscalls/store.knex_node.test.ts index 66df80c..51af124 100644 --- a/plugos/syscalls/store.knex_node.test.ts +++ b/plugos/syscalls/store.knex_node.test.ts @@ -1,7 +1,7 @@ -import {createSandbox} from "../environments/node_sandbox"; -import {expect, test} from "@jest/globals"; -import {System} from "../system"; -import {ensureTable, storeSyscalls} from "./store.knex_node"; +import { createSandbox } from "../environments/node_sandbox"; +import { expect, test } from "@jest/globals"; +import { System } from "../system"; +import { ensureTable, storeSyscalls } from "./store.knex_node"; import knex from "knex"; import fs from "fs/promises"; diff --git a/plugos/syscalls/store.knex_node.ts b/plugos/syscalls/store.knex_node.ts index 0afe388..70df523 100644 --- a/plugos/syscalls/store.knex_node.ts +++ b/plugos/syscalls/store.knex_node.ts @@ -1,5 +1,5 @@ -import {Knex} from "knex"; -import {SysCallMapping} from "../system"; +import { Knex } from "knex"; +import { SysCallMapping } from "../system"; type Item = { page: string; diff --git a/plugos/syscalls/transport.ts b/plugos/syscalls/transport.ts index 34637a5..8b88620 100644 --- a/plugos/syscalls/transport.ts +++ b/plugos/syscalls/transport.ts @@ -1,6 +1,6 @@ import { SyscallContext, SysCallMapping } from "../system"; -export function transportSyscalls( +export function proxySyscalls( names: string[], transportCall: ( ctx: SyscallContext, diff --git a/plugos/system.ts b/plugos/system.ts index ee405c8..f31e3d5 100644 --- a/plugos/system.ts +++ b/plugos/system.ts @@ -1,7 +1,7 @@ -import {Hook, Manifest, RuntimeEnvironment} from "./types"; -import {EventEmitter} from "../common/event"; -import {SandboxFactory} from "./sandbox"; -import {Plug} from "./plug"; +import { Hook, Manifest, RuntimeEnvironment } from "./types"; +import { EventEmitter } from "../common/event"; +import { SandboxFactory } from "./sandbox"; +import { Plug } from "./plug"; export interface SysCallMapping { [key: string]: (ctx: SyscallContext, ...args: any) => Promise | any; diff --git a/plugs/core/item.ts b/plugs/core/item.ts index c47416b..4965af5 100644 --- a/plugs/core/item.ts +++ b/plugs/core/item.ts @@ -1,9 +1,9 @@ -import {IndexEvent} from "../../webapp/app_event"; -import {whiteOutQueries} from "./materialized_queries"; +import { IndexEvent } from "../../webapp/app_event"; +import { whiteOutQueries } from "./materialized_queries"; -import {batchSet} from "plugos-silverbullet-syscall/index"; -import {parseMarkdown} from "plugos-silverbullet-syscall/markdown"; -import {collectNodesMatching, MarkdownTree, renderMarkdown,} from "../lib/tree"; +import { batchSet } from "plugos-silverbullet-syscall/index"; +import { parseMarkdown } from "plugos-silverbullet-syscall/markdown"; +import { collectNodesMatching, MarkdownTree, renderMarkdown } from "../lib/tree"; type Item = { item: string; diff --git a/plugs/core/materialized_queries.ts b/plugs/core/materialized_queries.ts index f507c34..ae3dc25 100644 --- a/plugs/core/materialized_queries.ts +++ b/plugs/core/materialized_queries.ts @@ -1,8 +1,8 @@ -import {flashNotification, getCurrentPage, reloadPage, save,} from "plugos-silverbullet-syscall/editor"; +import { flashNotification, getCurrentPage, reloadPage, save } from "plugos-silverbullet-syscall/editor"; -import {listPages, readPage, writePage,} from "plugos-silverbullet-syscall/space"; -import {invokeFunctionOnServer} from "plugos-silverbullet-syscall/system"; -import {scanPrefixGlobal} from "plugos-silverbullet-syscall"; +import { listPages, readPage, writePage } from "plugos-silverbullet-syscall/space"; +import { invokeFunction } from "plugos-silverbullet-syscall/system"; +import { scanPrefixGlobal } from "plugos-silverbullet-syscall"; export const queryRegex = /()(.+?)()/gs; @@ -31,7 +31,11 @@ async function replaceAsync( export async function updateMaterializedQueriesCommand() { const currentPage = await getCurrentPage(); await save(); - await invokeFunctionOnServer("updateMaterializedQueriesOnPage", currentPage); + await invokeFunction( + "server", + "updateMaterializedQueriesOnPage", + currentPage + ); await reloadPage(); await flashNotification("Updated materialized queries"); } diff --git a/plugs/core/navigate.ts b/plugs/core/navigate.ts index 4585908..e0a492a 100644 --- a/plugs/core/navigate.ts +++ b/plugs/core/navigate.ts @@ -1,9 +1,9 @@ -import {ClickEvent} from "../../webapp/app_event"; -import {updateMaterializedQueriesCommand} from "./materialized_queries"; -import {getCursor, getText, navigate as navigateTo, openUrl,} from "plugos-silverbullet-syscall/editor"; -import {taskToggleAtPos} from "../tasks/task"; -import {parseMarkdown} from "plugos-silverbullet-syscall/markdown"; -import {MarkdownTree, nodeAtPos} from "../lib/tree"; +import { ClickEvent } from "../../webapp/app_event"; +import { updateMaterializedQueriesCommand } from "./materialized_queries"; +import { getCursor, getText, navigate as navigateTo, openUrl } from "plugos-silverbullet-syscall/editor"; +import { taskToggleAtPos } from "../tasks/task"; +import { parseMarkdown } from "plugos-silverbullet-syscall/markdown"; +import { MarkdownTree, nodeAtPos } from "../lib/tree"; const materializedQueryPrefix = /