diff --git a/.vscode/settings.json b/.vscode/settings.json index 31b8e9b2..621c336b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,5 @@ }, "[typescript]": { "editor.defaultFormatter": "denoland.vscode-deno" - }, - "deno.documentPreloadLimit": 0 + } } diff --git a/build_bundle.ts b/build_bundle.ts index 6f9969e2..c223fefa 100644 --- a/build_bundle.ts +++ b/build_bundle.ts @@ -1,4 +1,4 @@ -import { denoPlugins, esbuild } from "./plugos/deps.ts"; +import { denoPlugins, esbuild } from "./lib/plugos/deps.ts"; await Deno.mkdir("dist", { recursive: true }); await esbuild.build({ diff --git a/build_plugs.ts b/build_plugs.ts index 309c8f4e..5129d00f 100644 --- a/build_plugs.ts +++ b/build_plugs.ts @@ -1,5 +1,5 @@ -import { esbuild, flags, path } from "./plugos/deps.ts"; -import { compileManifests } from "./plugos/compile.ts"; +import { esbuild, flags, path } from "./lib/plugos/deps.ts"; +import { compileManifests } from "./lib/plugos/compile.ts"; import { builtinPlugNames } from "./plugs/builtin_plugs.ts"; if (import.meta.main) { diff --git a/build_web.ts b/build_web.ts index 59562ad2..d6bde12b 100644 --- a/build_web.ts +++ b/build_web.ts @@ -1,11 +1,11 @@ import { copy } from "https://deno.land/std@0.165.0/fs/copy.ts"; import sass from "https://deno.land/x/denosass@1.0.4/mod.ts"; -import { bundleFolder } from "./plugos/asset_bundle/builder.ts"; +import { bundleFolder } from "./lib/asset_bundle/builder.ts"; import * as flags from "https://deno.land/std@0.165.0/flags/mod.ts"; -import { patchDenoLibJS } from "./plugos/compile.ts"; -import { denoPlugins, esbuild } from "./plugos/deps.ts"; +import { patchDenoLibJS } from "./lib/plugos/compile.ts"; +import { denoPlugins, esbuild } from "./lib/plugos/deps.ts"; export async function bundleAll( watch: boolean, diff --git a/cli/plug_run.test.ts b/cli/plug_run.test.ts index e777c6fc..651cbe15 100644 --- a/cli/plug_run.test.ts +++ b/cli/plug_run.test.ts @@ -1,11 +1,11 @@ -import { AssetBundle } from "../plugos/asset_bundle/bundle.ts"; -import { compileManifest } from "../plugos/compile.ts"; -import { esbuild } from "../plugos/deps.ts"; +import { AssetBundle } from "$lib/asset_bundle/bundle.ts"; +import { compileManifest } from "$lib/plugos/compile.ts"; +import { esbuild } from "$lib/plugos/deps.ts"; import { runPlug } from "./plug_run.ts"; import assets from "../dist/plug_asset_bundle.json" assert { type: "json" }; -import { assertEquals } from "../test_deps.ts"; -import { path } from "../common/deps.ts"; -import { MemoryKvPrimitives } from "../plugos/lib/memory_kv_primitives.ts"; +import { assertEquals } from "$lib/test_deps.ts"; +import { path } from "$common/deps.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; Deno.test("Test plug run", { sanitizeResources: false, diff --git a/cli/plug_run.ts b/cli/plug_run.ts index 2810f8aa..40a44180 100644 --- a/cli/plug_run.ts +++ b/cli/plug_run.ts @@ -1,16 +1,16 @@ -import { DiskSpacePrimitives } from "../common/spaces/disk_space_primitives.ts"; -import { AssetBundle } from "../plugos/asset_bundle/bundle.ts"; +import { DiskSpacePrimitives } from "$common/spaces/disk_space_primitives.ts"; +import { AssetBundle } from "../lib/asset_bundle/bundle.ts"; -import { sleep } from "$sb/lib/async.ts"; import { ServerSystem } from "../server/server_system.ts"; -import { AssetBundlePlugSpacePrimitives } from "../common/spaces/asset_bundle_space_primitives.ts"; -import { EndpointHook } from "../plugos/hooks/endpoint.ts"; +import { AssetBundlePlugSpacePrimitives } from "$common/spaces/asset_bundle_space_primitives.ts"; +import { EndpointHook } from "../server/hooks/endpoint.ts"; import { LocalShell } from "../server/shell_backend.ts"; import { Hono } from "../server/deps.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; +import { EventHook } from "$lib/plugos/hooks/event.ts"; +import { sleep } from "$lib/async.ts"; export async function runPlug( spacePath: string, diff --git a/cmd/constants.ts b/cmd/constants.ts deleted file mode 100644 index 07a2607e..00000000 --- a/cmd/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const silverBulletDbFile = ".silverbullet.db"; diff --git a/cmd/plug_compile.ts b/cmd/plug_compile.ts index 0d3cceca..499fa7df 100644 --- a/cmd/plug_compile.ts +++ b/cmd/plug_compile.ts @@ -1,5 +1,5 @@ -import { compileManifests } from "../plugos/compile.ts"; -import { esbuild } from "../plugos/deps.ts"; +import { compileManifests } from "../lib/plugos/compile.ts"; +import { esbuild } from "../lib/plugos/deps.ts"; export async function plugCompileCommand( { watch, dist, debug, info, importmap, runtimeUrl }: { diff --git a/cmd/plug_run.ts b/cmd/plug_run.ts index 44262dde..4507f4cf 100644 --- a/cmd/plug_run.ts +++ b/cmd/plug_run.ts @@ -1,9 +1,9 @@ import { runPlug } from "../cli/plug_run.ts"; -import { path } from "../common/deps.ts"; +import { path } from "$common/deps.ts"; import assets from "../dist/plug_asset_bundle.json" assert { type: "json", }; -import { AssetBundle } from "../plugos/asset_bundle/bundle.ts"; +import { AssetBundle } from "$lib/asset_bundle/bundle.ts"; import { determineDatabaseBackend } from "../server/db_backend.ts"; export async function plugRunCommand( diff --git a/cmd/server.ts b/cmd/server.ts index ba42cd3d..0dc95feb 100644 --- a/cmd/server.ts +++ b/cmd/server.ts @@ -5,13 +5,13 @@ import clientAssetBundle from "../dist/client_asset_bundle.json" assert { import plugAssetBundle from "../dist/plug_asset_bundle.json" assert { type: "json", }; -import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts"; -import { sleep } from "$sb/lib/async.ts"; +import { AssetBundle, AssetJson } from "../lib/asset_bundle/bundle.ts"; import { determineDatabaseBackend } from "../server/db_backend.ts"; import { SpaceServerConfig } from "../server/instance.ts"; import { runPlug } from "../cli/plug_run.ts"; -import { PrefixedKvPrimitives } from "../plugos/lib/prefixed_kv_primitives.ts"; +import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts"; +import { sleep } from "$lib/async.ts"; export async function serveCommand( options: { diff --git a/cmd/sync.ts b/cmd/sync.ts index f42888e4..2234bda3 100644 --- a/cmd/sync.ts +++ b/cmd/sync.ts @@ -1,5 +1,5 @@ -import { SpaceSync, SyncStatusItem } from "../common/spaces/sync.ts"; -import { MemoryKvPrimitives } from "../plugos/lib/memory_kv_primitives.ts"; +import { SpaceSync, SyncStatusItem } from "$common/spaces/sync.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; import { determineStorageBackend } from "../server/storage_backend.ts"; export async function syncCommand( diff --git a/common/command.test.ts b/common/command.test.ts index 97660849..c4d7c9ef 100644 --- a/common/command.test.ts +++ b/common/command.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { parseCommand } from "./command.ts"; Deno.test("Command parser", () => { diff --git a/common/common_system.ts b/common/common_system.ts index 91b69fda..8b4a070f 100644 --- a/common/common_system.ts +++ b/common/common_system.ts @@ -1,15 +1,15 @@ import { AppCommand, CommandHook } from "./hooks/command.ts"; -import { PlugNamespaceHook } from "./hooks/plug_namespace.ts"; +import { PlugNamespaceHook } from "$common/hooks/plug_namespace.ts"; import { SilverBulletHooks } from "./manifest.ts"; import { buildQueryFunctions } from "./query_functions.ts"; import { ScriptEnvironment } from "./space_script.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { System } from "../plugos/system.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { System } from "$lib/plugos/system.ts"; import { CodeWidgetHook } from "../web/hooks/code_widget.ts"; import { PanelWidgetHook } from "../web/hooks/panel_widget.ts"; import { SlashCommandHook } from "../web/hooks/slash_command.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; export abstract class CommonSystem { system!: System; diff --git a/common/deps.ts b/common/deps.ts index c4a84d63..b924253e 100644 --- a/common/deps.ts +++ b/common/deps.ts @@ -1,22 +1,7 @@ -export { - history, - historyKeymap, - indentWithTab, - standardKeymap, -} from "@codemirror/commands"; -export { - autocompletion, - closeBrackets, - closeBracketsKeymap, - CompletionContext, - completionKeymap, -} from "@codemirror/autocomplete"; -export type { Completion, CompletionResult } from "@codemirror/autocomplete"; - export { styleTags, Tag, tagHighlighter, tags } from "@lezer/highlight"; -export * as YAML from "https://esm.sh/js-yaml@4.1.0"; -export * as path from "https://deno.land/std@0.189.0/path/mod.ts"; +export * as YAML from "js-yaml"; +export * as path from "$std/path/mod.ts"; import { Intl, @@ -56,84 +41,27 @@ export { export type { NodeType, SyntaxNode, SyntaxNodeRef, Tree } from "@lezer/common"; -export { - closeSearchPanel, - openSearchPanel, - searchKeymap, -} from "@codemirror/search"; -export { - Decoration, - drawSelection, - dropCursor, - EditorView, - gutter, - highlightSpecialChars, - keymap, - placeholder, - runScopeHandlers, - ViewPlugin, - ViewUpdate, - WidgetType, -} from "@codemirror/view"; -export type { DecorationSet, KeyBinding } from "@codemirror/view"; +export { markdown } from "@codemirror/lang-markdown"; -export { markdown } from "https://esm.sh/@codemirror/lang-markdown@6.2.3?external=@codemirror/state,@lezer/common,@codemirror/language,@lezer/markdown,@codemirror/view,@lezer/highlight,@codemirror/lang-html&target=es2022"; - -export { - EditorSelection, - EditorState, - Range, - SelectionRange, - StateField, - Text, - Transaction, -} from "@codemirror/state"; -export type { - ChangeSpec, - Compartment, - Extension, - StateCommand, -} from "@codemirror/state"; -export { - codeFolding, - defaultHighlightStyle, - defineLanguageFacet, - foldAll, - foldCode, - foldedRanges, - foldGutter, - foldInside, - HighlightStyle, - indentNodeProp, - indentOnInput, - Language, - languageDataProp, - LanguageDescription, - LanguageSupport, - ParseContext, - StreamLanguage, - syntaxHighlighting, - syntaxTree, - toggleFold, - unfoldAll, - unfoldCode, -} from "@codemirror/language"; - -export { yaml as yamlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/yaml?external=@codemirror/language&target=es2022"; +// Language modes +export { yaml as yamlLanguage } from "@codemirror/legacy-modes/mode/yaml?external=@codemirror/language&target=es2022"; export { pgSQL as postgresqlLanguage, standardSQL as sqlLanguage, -} from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/sql?external=@codemirror/language&target=es2022"; -export { rust as rustLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/rust?external=@codemirror/language&target=es2022"; -export { css as cssLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/css?external=@codemirror/language&target=es2022"; +} from "@codemirror/legacy-modes/mode/sql?external=@codemirror/language&target=es2022"; +export { rust as rustLanguage } from "@codemirror/legacy-modes/mode/rust?external=@codemirror/language&target=es2022"; +export { css as cssLanguage } from "@codemirror/legacy-modes/mode/css?external=@codemirror/language&target=es2022"; +export { python as pythonLanguage } from "@codemirror/legacy-modes/mode/python?external=@codemirror/language&target=es2022"; +export { protobuf as protobufLanguage } from "@codemirror/legacy-modes/mode/protobuf?external=@codemirror/language&target=es2022"; +export { shell as shellLanguage } from "@codemirror/legacy-modes/mode/shell?external=@codemirror/language&target=es2022"; +export { swift as swiftLanguage } from "@codemirror/legacy-modes/mode/swift?external=@codemirror/language&target=es2022"; +export { toml as tomlLanguage } from "@codemirror/legacy-modes/mode/toml?external=@codemirror/language&target=es2022"; +export { xml as xmlLanguage } from "@codemirror/legacy-modes/mode/xml?external=@codemirror/language&target=es2022"; +export { json as jsonLanguage } from "@codemirror/legacy-modes/mode/javascript?external=@codemirror/language&target=es2022"; export { htmlLanguage } from "@codemirror/lang-html"; -export { python as pythonLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/python?external=@codemirror/language&target=es2022"; -export { protobuf as protobufLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/protobuf?external=@codemirror/language&target=es2022"; -export { shell as shellLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/shell?external=@codemirror/language&target=es2022"; -export { swift as swiftLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/swift?external=@codemirror/language&target=es2022"; -export { toml as tomlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/toml?external=@codemirror/language&target=es2022"; -export { xml as xmlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/xml?external=@codemirror/language&target=es2022"; -export { json as jsonLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/javascript?external=@codemirror/language&target=es2022"; + +export { Language, StreamLanguage } from "@codemirror/language"; + export { c as cLanguage, cpp as cppLanguage, @@ -144,15 +72,15 @@ export { objectiveC as objectiveCLanguage, objectiveCpp as objectiveCppLanguage, scala as scalaLanguage, -} from "https://esm.sh/@codemirror/legacy-modes@6.3.3/mode/clike?external=@codemirror/language&target=es2022"; +} from "@codemirror/legacy-modes/mode/clike?external=@codemirror/language&target=es2022"; export { javascriptLanguage, typescriptLanguage, -} from "https://esm.sh/@codemirror/lang-javascript@6.2.1?external=@codemirror/language,@codemirror/autocomplete,@codemirror/view,@codemirror/state,@codemirror/lint,@lezer/common,@lezer/lr,@lezer/javascript,@codemirror/commands&target=es2022"; +} from "@codemirror/lang-javascript"; -export { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; +export { mime } from "mimetypes"; -export { compile as gitIgnoreCompiler } from "https://esm.sh/gitignore-parser@0.0.2"; +export { compile as gitIgnoreCompiler } from "gitignore-parser"; -export { z } from "https://deno.land/x/zod@v3.22.4/mod.ts"; +export { z } from "zod"; diff --git a/common/hooks/command.ts b/common/hooks/command.ts index 336d97da..14389171 100644 --- a/common/hooks/command.ts +++ b/common/hooks/command.ts @@ -1,13 +1,13 @@ -import { Hook, Manifest } from "../../plugos/types.ts"; -import { System } from "../../plugos/system.ts"; -import { EventEmitter } from "../../plugos/event.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; +import { System } from "../../lib/plugos/system.ts"; +import { EventEmitter } from "../../lib/plugos/event.ts"; +import { ObjectValue } from "../../type/types.ts"; import { FrontmatterConfig, SnippetConfig, } from "../../plugs/template/types.ts"; -import { throttle } from "$sb/lib/async.ts"; import { NewPageConfig } from "../../plugs/template/types.ts"; +import { throttle } from "../../lib/async.ts"; export type CommandDef = { name: string; diff --git a/common/hooks/plug_namespace.ts b/common/hooks/plug_namespace.ts index 194a0496..e5c5fa65 100644 --- a/common/hooks/plug_namespace.ts +++ b/common/hooks/plug_namespace.ts @@ -1,6 +1,6 @@ -import { Plug } from "../../plugos/plug.ts"; -import { System } from "../../plugos/system.ts"; -import { Hook, Manifest } from "../../plugos/types.ts"; +import { Plug } from "../../lib/plugos/plug.ts"; +import { System } from "../../lib/plugos/system.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; export type NamespaceOperation = | "readFile" diff --git a/common/json.test.ts b/common/json.test.ts deleted file mode 100644 index d29fd993..00000000 --- a/common/json.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { assertEquals } from "../test_deps.ts"; -import { decodeBSON, encodeBSON, traverseAndRewriteJSON } from "./json.ts"; - -Deno.test("traverseAndRewrite", () => { - const bufArray = new Uint8Array([1, 2, 3]); - const obj = { - foo: "bar", - list: ["hello", { sup: "world" }], - nested: { - baz: "qux", - }, - special: { - value: () => { - return bufArray; - }, - }, - }; - - const rewritten = traverseAndRewriteJSON(obj, (val) => { - if (typeof val?.value === "function") { - return val.value(); - } - if (typeof val === "string") { - return val.toUpperCase(); - } - return val; - }); - - assertEquals(rewritten, { - foo: "BAR", - list: ["HELLO", { sup: "WORLD" }], - nested: { - baz: "QUX", - }, - special: bufArray, - }); -}); - -Deno.test("BSON encoding", () => { - // Test some primitives - assertEquals(decodeBSON(encodeBSON("test")), "test"); - assertEquals(decodeBSON(encodeBSON([1, 2, 3])), [1, 2, 3]); - assertEquals(decodeBSON(encodeBSON(true)), true); - assertEquals(decodeBSON(encodeBSON(false)), false); - assertEquals(decodeBSON(encodeBSON(null)), null); - assertEquals(decodeBSON(encodeBSON(0)), 0); - - assertEquals(decodeBSON(encodeBSON(undefined)), undefined); - - const blob = new Uint8Array([1, 2, 3]); - assertEquals(decodeBSON(encodeBSON(blob)), blob); - - // Then move to more advanced wrapped content - const obj = { - foo: "bar", - list: ["hello", { sup: "world" }], - nested: { - baz: "qux", - }, - bin: blob, - }; - assertEquals(decodeBSON(encodeBSON(obj)), obj); -}); diff --git a/common/json.ts b/common/json.ts deleted file mode 100644 index 13ae1ade..00000000 --- a/common/json.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { BSON } from "https://esm.sh/bson@6.2.0"; - -// BSON doesn't support top-level primitives, so we need to wrap them in an object -const topLevelValueKey = "$_tl"; - -// BSON doesn't support undefined, so we need to encode it as a "magic" string -const undefinedPlaceHolder = "$_undefined_$"; - -/** - * BSON encoder, but also supporting "edge cases" like encoding strings, numbers, etc. - * @param obj - * @returns - */ -export function encodeBSON(obj: any): Uint8Array { - if ( - obj === undefined || obj === null || - !(typeof obj === "object" && obj.constructor === Object) - ) { - obj = { [topLevelValueKey]: obj }; - } - obj = traverseAndRewriteJSON(obj, (val) => { - if (val === undefined) { - return undefinedPlaceHolder; - } - return val; - }); - return BSON.serialize(obj); -} - -export function decodeBSON(data: Uint8Array): any { - let result = BSON.deserialize(data); - // For whatever reason the BSON library doesn't unwrap binary blobs automatically - result = traverseAndRewriteJSON(result, (val) => { - if (typeof val?.value === "function") { - return val.value(); - } else if (val === undefinedPlaceHolder) { - return undefined; - } - return val; - }); - if (Object.hasOwn(result, topLevelValueKey)) { - return result[topLevelValueKey]; - } else { - return result; - } -} - -/** - * Traverses and rewrites an object recursively. - * - * @param obj - The object to traverse and rewrite. - * @param rewrite - The function to apply for rewriting each value. - * @returns The rewritten object. - */ -export function traverseAndRewriteJSON( - obj: any, - rewrite: (val: any) => any, -): any { - // Apply rewrite to object as a whole - obj = rewrite(obj); - // Recurse down if this is an array or a "plain object" - if ( - obj && (Array.isArray(obj) || - (typeof obj === "object" && obj.constructor === Object)) - ) { - const keys = Object.keys(obj); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; - obj[key] = traverseAndRewriteJSON(obj[key], rewrite); - } - } - return obj; -} diff --git a/common/manifest.ts b/common/manifest.ts index 0ae7522c..952a21df 100644 --- a/common/manifest.ts +++ b/common/manifest.ts @@ -1,12 +1,12 @@ -import * as plugos from "../plugos/types.ts"; -import { CronHookT } from "../plugos/hooks/cron.ts"; -import { EventHookT } from "../plugos/hooks/event.ts"; +import * as plugos from "../lib/plugos/types.ts"; +import { CronHookT } from "../lib/plugos/hooks/cron.ts"; +import { EventHookT } from "../lib/plugos/hooks/event.ts"; import { CommandHookT } from "./hooks/command.ts"; import { SlashCommandHookT } from "../web/hooks/slash_command.ts"; import { PlugNamespaceHookT } from "./hooks/plug_namespace.ts"; import { CodeWidgetT } from "../web/hooks/code_widget.ts"; -import { MQHookT } from "../plugos/hooks/mq.ts"; -import { EndpointHookT } from "../plugos/hooks/endpoint.ts"; +import { MQHookT } from "../lib/plugos/hooks/mq.ts"; +import { EndpointHookT } from "../server/hooks/endpoint.ts"; import { PanelWidgetT } from "../web/hooks/panel_widget.ts"; /** Silverbullet hooks give plugs access to silverbullet core systems. diff --git a/common/markdown_parser/parse_tree.ts b/common/markdown_parser/parse_tree.ts index 13e02de6..a0689556 100644 --- a/common/markdown_parser/parse_tree.ts +++ b/common/markdown_parser/parse_tree.ts @@ -1,4 +1,4 @@ -import type { ParseTree } from "$sb/lib/tree.ts"; +import type { ParseTree } from "$lib/tree.ts"; import type { Language, SyntaxNode } from "../deps.ts"; export function lezerToParseTree( diff --git a/common/markdown_parser/parser.test.ts b/common/markdown_parser/parser.test.ts index 99c37bac..b5a89c2a 100644 --- a/common/markdown_parser/parser.test.ts +++ b/common/markdown_parser/parser.test.ts @@ -1,10 +1,6 @@ import { parse } from "./parse_tree.ts"; -import { - collectNodesOfType, - findNodeOfType, - renderToText, -} from "../../plug-api/lib/tree.ts"; -import { assertEquals, assertNotEquals } from "../../test_deps.ts"; +import { collectNodesOfType, findNodeOfType, renderToText } from "$lib/tree.ts"; +import { assertEquals, assertNotEquals } from "$lib/test_deps.ts"; import { extendedMarkdownLanguage } from "./parser.ts"; const sample1 = `--- diff --git a/common/proxy_fetch.ts b/common/proxy_fetch.ts index d05ef71f..7edc0053 100644 --- a/common/proxy_fetch.ts +++ b/common/proxy_fetch.ts @@ -1,4 +1,4 @@ -import { base64Decode, base64Encode } from "../plugos/asset_bundle/base64.ts"; +import { base64Decode, base64Encode } from "../lib/crypto.ts"; export type ProxyFetchRequest = { method?: string; diff --git a/common/query_functions.ts b/common/query_functions.ts index ebe6dff4..3ec169ce 100644 --- a/common/query_functions.ts +++ b/common/query_functions.ts @@ -1,8 +1,8 @@ -import { FunctionMap } from "$sb/types.ts"; -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; -import { System } from "../plugos/system.ts"; -import { Query } from "$sb/types.ts"; -import { LimitedMap } from "$sb/lib/limited_map.ts"; +import { FunctionMap } from "../type/types.ts"; +import { builtinFunctions } from "../lib/builtin_query_functions.ts"; +import { System } from "../lib/plugos/system.ts"; +import { Query } from "../type/types.ts"; +import { LimitedMap } from "$lib/limited_map.ts"; const pageCacheTtl = 10 * 1000; // 10s diff --git a/common/util.ts b/common/settings.ts similarity index 84% rename from common/util.ts rename to common/settings.ts index 9491dff6..eedb0230 100644 --- a/common/util.ts +++ b/common/settings.ts @@ -1,27 +1,9 @@ -import { INDEX_TEMPLATE, SETTINGS_TEMPLATE } from "./PAGE_TEMPLATES.ts"; import { YAML } from "./deps.ts"; +import { INDEX_TEMPLATE, SETTINGS_TEMPLATE } from "./PAGE_TEMPLATES.ts"; import { SpacePrimitives } from "./spaces/space_primitives.ts"; -import { expandPropertyNames } from "$sb/lib/json.ts"; +import { expandPropertyNames } from "../lib/json.ts"; import type { BuiltinSettings } from "../web/types.ts"; -/** - * Runs a function safely by catching any errors and logging them to the console. - * @param fn - The function to run. - */ -export function safeRun(fn: () => Promise) { - fn().catch((e) => { - console.error(e); - }); -} - -/** - * Checks if the current platform is Mac-like (Mac, iPhone, iPod, iPad). - * @returns A boolean indicating if the platform is Mac-like. - */ -export function isMacLike() { - return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform); -} - // TODO: This is naive, may be better to use a proper parser const yamlSettingsRegex = /```yaml([^`]+)```/; diff --git a/web/space.ts b/common/space.ts similarity index 94% rename from web/space.ts rename to common/space.ts index 8991fc04..d3047529 100644 --- a/web/space.ts +++ b/common/space.ts @@ -1,9 +1,9 @@ -import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; -import { plugPrefix } from "../common/spaces/constants.ts"; -import { safeRun } from "../common/util.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { plugPrefix } from "$common/spaces/constants.ts"; -import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; +import { AttachmentMeta, FileMeta, PageMeta } from "../type/types.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { safeRun } from "../lib/async.ts"; const pageWatchInterval = 5000; diff --git a/common/space_index.ts b/common/space_index.ts index 239ddaca..2a0292ea 100644 --- a/common/space_index.ts +++ b/common/space_index.ts @@ -1,5 +1,5 @@ -import { DataStore } from "../plugos/lib/datastore.ts"; -import { System } from "../plugos/system.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { System } from "$lib/plugos/system.ts"; const indexVersionKey = ["$indexVersion"]; diff --git a/common/space_script.ts b/common/space_script.ts index 3b8db11f..3828d270 100644 --- a/common/space_script.ts +++ b/common/space_script.ts @@ -1,4 +1,4 @@ -import { System } from "../plugos/system.ts"; +import { System } from "../lib/plugos/system.ts"; import { ScriptObject } from "../plugs/index/script.ts"; import { AppCommand, CommandDef } from "./hooks/command.ts"; diff --git a/common/spaces/asset_bundle_space_primitives.ts b/common/spaces/asset_bundle_space_primitives.ts index e963d66c..0e576f09 100644 --- a/common/spaces/asset_bundle_space_primitives.ts +++ b/common/spaces/asset_bundle_space_primitives.ts @@ -1,6 +1,6 @@ import { SpacePrimitives } from "./space_primitives.ts"; -import { AssetBundle } from "../../plugos/asset_bundle/bundle.ts"; -import { FileMeta } from "$sb/types.ts"; +import { AssetBundle } from "../../lib/asset_bundle/bundle.ts"; +import { FileMeta } from "../../type/types.ts"; export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { constructor( diff --git a/common/spaces/chunked_datastore_space_primitives.test.ts b/common/spaces/chunked_datastore_space_primitives.test.ts index 375904d6..b58986a3 100644 --- a/common/spaces/chunked_datastore_space_primitives.test.ts +++ b/common/spaces/chunked_datastore_space_primitives.test.ts @@ -1,5 +1,5 @@ -import { MemoryKvPrimitives } from "../../plugos/lib/memory_kv_primitives.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { ChunkedKvStoreSpacePrimitives } from "./chunked_datastore_space_primitives.ts"; import { testSpacePrimitives } from "./space_primitives.test.ts"; diff --git a/common/spaces/chunked_datastore_space_primitives.ts b/common/spaces/chunked_datastore_space_primitives.ts index 50e7a5c7..3078ad79 100644 --- a/common/spaces/chunked_datastore_space_primitives.ts +++ b/common/spaces/chunked_datastore_space_primitives.ts @@ -1,8 +1,8 @@ import type { SpacePrimitives } from "./space_primitives.ts"; -import { KvKey } from "$sb/types.ts"; -import { KvPrimitives } from "../../plugos/lib/kv_primitives.ts"; +import { KvKey } from "$type/types.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; import { KvMetaSpacePrimitives } from "./kv_meta_space_primitives.ts"; -import { PrefixedKvPrimitives } from "../../plugos/lib/prefixed_kv_primitives.ts"; +import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts"; /** * A space primitives implementation that stores files in chunks in a KV store. diff --git a/common/spaces/datastore_space_primitives.test.ts b/common/spaces/datastore_space_primitives.test.ts index 0222d4fc..98de1f78 100644 --- a/common/spaces/datastore_space_primitives.test.ts +++ b/common/spaces/datastore_space_primitives.test.ts @@ -1,6 +1,6 @@ import "https://esm.sh/fake-indexeddb@4.0.2/auto"; -import { DataStore } from "../../plugos/lib/datastore.ts"; -import { IndexedDBKvPrimitives } from "../../plugos/lib/indexeddb_kv_primitives.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { IndexedDBKvPrimitives } from "$lib/data/indexeddb_kv_primitives.ts"; import { DataStoreSpacePrimitives } from "./datastore_space_primitives.ts"; import { testSpacePrimitives } from "./space_primitives.test.ts"; diff --git a/common/spaces/datastore_space_primitives.ts b/common/spaces/datastore_space_primitives.ts index 2cb83308..a860fff4 100644 --- a/common/spaces/datastore_space_primitives.ts +++ b/common/spaces/datastore_space_primitives.ts @@ -1,7 +1,7 @@ import type { SpacePrimitives } from "./space_primitives.ts"; -import { mime } from "../deps.ts"; -import { FileMeta } from "$sb/types.ts"; -import { DataStore } from "../../plugos/lib/datastore.ts"; +import { mime } from "mimetypes"; +import { FileMeta } from "$type/types.ts"; +import { DataStore } from "$lib/data/datastore.ts"; export type FileContent = { name: string; diff --git a/common/spaces/deno_kv_space_primitives.test.ts b/common/spaces/deno_kv_space_primitives.test.ts index fbd55ca0..a1db1def 100644 --- a/common/spaces/deno_kv_space_primitives.test.ts +++ b/common/spaces/deno_kv_space_primitives.test.ts @@ -1,6 +1,6 @@ -import { DenoKvPrimitives } from "../../plugos/lib/deno_kv_primitives.ts"; -import { ChunkedKvStoreSpacePrimitives } from "./chunked_datastore_space_primitives.ts"; -import { testSpacePrimitives } from "./space_primitives.test.ts"; +import { DenoKvPrimitives } from "$lib/data/deno_kv_primitives.ts"; +import { ChunkedKvStoreSpacePrimitives } from "$common/spaces/chunked_datastore_space_primitives.ts"; +import { testSpacePrimitives } from "$common/spaces/space_primitives.test.ts"; Deno.test("deno kv test", async () => { const tempFile = await Deno.makeTempFile({ suffix: ".db" }); diff --git a/common/spaces/disk_space_primitives.ts b/common/spaces/disk_space_primitives.ts index 72ecebbd..c175c6af 100644 --- a/common/spaces/disk_space_primitives.ts +++ b/common/spaces/disk_space_primitives.ts @@ -3,7 +3,7 @@ import { readAll } from "https://deno.land/std@0.165.0/streams/conversion.ts"; import { SpacePrimitives } from "./space_primitives.ts"; import { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; import { walk } from "https://deno.land/std@0.198.0/fs/walk.ts"; -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../type/types.ts"; function lookupContentType(path: string): string { return mime.getType(path) || "application/octet-stream"; diff --git a/common/spaces/encrypted_space_primitives.test.ts b/common/spaces/encrypted_space_primitives.test.ts index 3421f340..5eb2c79c 100644 --- a/common/spaces/encrypted_space_primitives.test.ts +++ b/common/spaces/encrypted_space_primitives.test.ts @@ -1,5 +1,5 @@ -import { MemoryKvPrimitives } from "../../plugos/lib/memory_kv_primitives.ts"; -import { assert, assertEquals } from "../../test_deps.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; import { ChunkedKvStoreSpacePrimitives } from "./chunked_datastore_space_primitives.ts"; import { EncryptedSpacePrimitives } from "./encrypted_space_primitives.ts"; import { testSpacePrimitives } from "./space_primitives.test.ts"; diff --git a/common/spaces/encrypted_space_primitives.ts b/common/spaces/encrypted_space_primitives.ts index 36ff8ee4..c64d491b 100644 --- a/common/spaces/encrypted_space_primitives.ts +++ b/common/spaces/encrypted_space_primitives.ts @@ -1,4 +1,4 @@ -import { FileMeta } from "../../plug-api/types.ts"; +import { FileMeta } from "../../type/types.ts"; import { base32Decode, base32Encode, @@ -8,7 +8,8 @@ import { exportKey, generateSalt, importKey, -} from "../crypto.ts"; +} from "../../lib/crypto.ts"; +import { plugPrefix } from "./constants.ts"; import { SpacePrimitives } from "./space_primitives.ts"; export const encryptedFileExt = ".crypt"; @@ -178,7 +179,7 @@ export class EncryptedSpacePrimitives implements SpacePrimitives { } isUnencryptedPath(name: string) { - return name.startsWith("_plug/"); + return name.startsWith(plugPrefix); } /** diff --git a/common/spaces/evented_space_primitives.ts b/common/spaces/evented_space_primitives.ts index 1fb149fb..5fbfdd1b 100644 --- a/common/spaces/evented_space_primitives.ts +++ b/common/spaces/evented_space_primitives.ts @@ -1,5 +1,5 @@ -import { FileMeta } from "$sb/types.ts"; -import { EventHook } from "../../plugos/hooks/event.ts"; +import { FileMeta } from "../../type/types.ts"; +import { EventHook } from "../../lib/plugos/hooks/event.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; diff --git a/common/spaces/fallback_space_primitives.ts b/common/spaces/fallback_space_primitives.ts index 964ba2e9..8a18e2bb 100644 --- a/common/spaces/fallback_space_primitives.ts +++ b/common/spaces/fallback_space_primitives.ts @@ -1,4 +1,4 @@ -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../type/types.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; /** diff --git a/common/spaces/filtered_space_primitives.ts b/common/spaces/filtered_space_primitives.ts index 6b3ce05f..a227e0ef 100644 --- a/common/spaces/filtered_space_primitives.ts +++ b/common/spaces/filtered_space_primitives.ts @@ -1,4 +1,4 @@ -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../type/types.ts"; import { SpacePrimitives } from "./space_primitives.ts"; export class FilteredSpacePrimitives implements SpacePrimitives { diff --git a/common/spaces/http_space_primitives.ts b/common/spaces/http_space_primitives.ts index 26ee4c17..250a46c2 100644 --- a/common/spaces/http_space_primitives.ts +++ b/common/spaces/http_space_primitives.ts @@ -1,6 +1,6 @@ import { SpacePrimitives } from "./space_primitives.ts"; -import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts"; -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../type/types.ts"; +import { flushCachesAndUnregisterServiceWorker } from "./sw_util.ts"; export class HttpSpacePrimitives implements SpacePrimitives { constructor( diff --git a/common/spaces/kv_meta_space_primitives.ts b/common/spaces/kv_meta_space_primitives.ts index 06ae54de..e75fe528 100644 --- a/common/spaces/kv_meta_space_primitives.ts +++ b/common/spaces/kv_meta_space_primitives.ts @@ -1,6 +1,6 @@ -import { FileMeta } from "$sb/types.ts"; -import { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; -import { KvPrimitives } from "../../plugos/lib/kv_primitives.ts"; +import { FileMeta } from "$type/types.ts"; +import { mime } from "mimetypes"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; import { SpacePrimitives } from "./space_primitives.ts"; export type KvMetaSpacePrimitivesCallbacks = { diff --git a/common/spaces/plug_space_primitives.ts b/common/spaces/plug_space_primitives.ts index d65b4259..4f0e3b5c 100644 --- a/common/spaces/plug_space_primitives.ts +++ b/common/spaces/plug_space_primitives.ts @@ -1,5 +1,5 @@ -import { SpacePrimitives } from "../../common/spaces/space_primitives.ts"; -import { FileMeta } from "$sb/types.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { FileMeta } from "../../type/types.ts"; import { NamespaceOperation, PlugNamespaceHook, diff --git a/common/spaces/ro_space_primitives.ts b/common/spaces/ro_space_primitives.ts index e6dafce5..6a42c002 100644 --- a/common/spaces/ro_space_primitives.ts +++ b/common/spaces/ro_space_primitives.ts @@ -1,4 +1,4 @@ -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../type/types.ts"; import { SpacePrimitives } from "./space_primitives.ts"; export class ReadOnlySpacePrimitives implements SpacePrimitives { diff --git a/common/spaces/s3_space_primitives.test.ts b/common/spaces/s3_space_primitives.test.ts index 5f824327..6e58f217 100644 --- a/common/spaces/s3_space_primitives.test.ts +++ b/common/spaces/s3_space_primitives.test.ts @@ -1,6 +1,6 @@ import { S3SpacePrimitives } from "./s3_space_primitives.ts"; -import { MemoryKvPrimitives } from "../../plugos/lib/memory_kv_primitives.ts"; -import { testSpacePrimitives } from "./space_primitives.test.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; +import { testSpacePrimitives } from "$common/spaces/space_primitives.test.ts"; Deno.test("s3_space_primitives", async () => { return; diff --git a/common/spaces/s3_space_primitives.ts b/common/spaces/s3_space_primitives.ts index 0c48fa67..398659d0 100644 --- a/common/spaces/s3_space_primitives.ts +++ b/common/spaces/s3_space_primitives.ts @@ -2,10 +2,10 @@ import { S3Client } from "https://deno.land/x/s3_lite_client@0.4.0/mod.ts"; import type { ClientOptions } from "https://deno.land/x/s3_lite_client@0.4.0/client.ts"; import { KvMetaSpacePrimitives } from "./kv_meta_space_primitives.ts"; -import { KvPrimitives } from "../../plugos/lib/kv_primitives.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; import { mime } from "../deps.ts"; -import { KV, KvKey } from "$sb/types.ts"; -import { PrefixedKvPrimitives } from "../../plugos/lib/prefixed_kv_primitives.ts"; +import { KV, KvKey } from "$type/types.ts"; +import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts"; export type S3SpacePrimitivesOptions = ClientOptions; diff --git a/common/spaces/space_primitives.test.ts b/common/spaces/space_primitives.test.ts index 0dfd2b1b..019ff00f 100644 --- a/common/spaces/space_primitives.test.ts +++ b/common/spaces/space_primitives.test.ts @@ -1,4 +1,4 @@ -import { assert, assertEquals } from "../../test_deps.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; import { SpacePrimitives } from "./space_primitives.ts"; export async function testSpacePrimitives(spacePrimitives: SpacePrimitives) { diff --git a/common/spaces/space_primitives.ts b/common/spaces/space_primitives.ts index d0ce7da7..d7df70d7 100644 --- a/common/spaces/space_primitives.ts +++ b/common/spaces/space_primitives.ts @@ -1,4 +1,4 @@ -import type { FileMeta } from "$sb/types.ts"; +import type { FileMeta } from "../../type/types.ts"; /** * A generic interface used by `Space` to interact with the underlying storage, designed to be easy to implement for different storage backends diff --git a/common/sw_util.ts b/common/spaces/sw_util.ts similarity index 100% rename from common/sw_util.ts rename to common/spaces/sw_util.ts diff --git a/common/spaces/sync.test.ts b/common/spaces/sync.test.ts index e8678edf..0cf4b31e 100644 --- a/common/spaces/sync.test.ts +++ b/common/spaces/sync.test.ts @@ -1,6 +1,6 @@ import { SpaceSync, SyncStatusItem } from "./sync.ts"; import { DiskSpacePrimitives } from "./disk_space_primitives.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; Deno.test("Test store", async () => { const primaryPath = await Deno.makeTempDir(); diff --git a/common/spaces/sync.ts b/common/spaces/sync.ts index 8301f44a..ba6e949d 100644 --- a/common/spaces/sync.ts +++ b/common/spaces/sync.ts @@ -1,6 +1,7 @@ import { SpacePrimitives } from "./space_primitives.ts"; -import { EventEmitter } from "../../plugos/event.ts"; -import { FileMeta } from "$sb/types.ts"; +import { EventEmitter } from "../../lib/plugos/event.ts"; +import { FileMeta } from "../../type/types.ts"; +import { plugPrefix } from "./constants.ts"; type SyncHash = number; @@ -76,7 +77,7 @@ export class SpaceSync extends EventEmitter { // Just make sure that _plug/ files appear first // This is important for the initial sync: plugs are loaded the moment they are pulled into the space, // which would activate e.g. any indexing logic for the remaining space content - return a.startsWith("_plug/") ? -1 : 1; + return a.startsWith(plugPrefix) ? -1 : 1; }); // console.log("[sync]", "Iterating over all files"); let filesProcessed = 0; diff --git a/common/syscalls/language.ts b/common/syscalls/language.ts index 3524ea9a..2ed49e2d 100644 --- a/common/syscalls/language.ts +++ b/common/syscalls/language.ts @@ -1,6 +1,6 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { parse } from "../markdown_parser/parse_tree.ts"; -import type { ParseTree } from "$sb/lib/tree.ts"; +import type { ParseTree } from "$lib/tree.ts"; import { builtinLanguages, languageFor } from "../languages.ts"; export function languageSyscalls(): SysCallMapping { diff --git a/common/syscalls/markdown.ts b/common/syscalls/markdown.ts index beebd7d7..6506380f 100644 --- a/common/syscalls/markdown.ts +++ b/common/syscalls/markdown.ts @@ -1,6 +1,6 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { parse } from "../markdown_parser/parse_tree.ts"; -import type { ParseTree } from "$sb/lib/tree.ts"; +import type { ParseTree } from "$lib/tree.ts"; import { extendedMarkdownLanguage } from "../markdown_parser/parser.ts"; export function markdownSyscalls(): SysCallMapping { diff --git a/common/syscalls/system.ts b/common/syscalls/system.ts index a75f51b6..c49e5942 100644 --- a/common/syscalls/system.ts +++ b/common/syscalls/system.ts @@ -1,5 +1,5 @@ -import { SyscallMeta } from "$sb/types.ts"; -import { SysCallMapping, System } from "../../plugos/system.ts"; +import { SyscallMeta } from "../../type/types.ts"; +import { SysCallMapping, System } from "../../lib/plugos/system.ts"; import type { Client } from "../../web/client.ts"; import { CommandDef } from "../hooks/command.ts"; import { proxySyscall } from "../../web/syscalls/util.ts"; diff --git a/common/syscalls/template.ts b/common/syscalls/template.ts index 07845719..a341ed0d 100644 --- a/common/syscalls/template.ts +++ b/common/syscalls/template.ts @@ -1,9 +1,9 @@ -import { FunctionMap } from "$sb/types.ts"; -import { AST } from "$sb/lib/tree.ts"; -import { SysCallMapping } from "../../plugos/system.ts"; -import { renderTemplate } from "../template/render.ts"; -import { parseTemplate } from "../template/template_parser.ts"; -import { DataStore } from "../../plugos/lib/datastore.ts"; +import { FunctionMap } from "$type/types.ts"; +import { AST } from "$lib/tree.ts"; +import { SysCallMapping } from "$lib/plugos/system.ts"; +import { renderTemplate } from "$common/template/render.ts"; +import { parseTemplate } from "$common/template/template_parser.ts"; +import { DataStore } from "$lib/data/datastore.ts"; export function templateSyscalls(ds: DataStore): SysCallMapping { return { diff --git a/common/syscalls/yaml.ts b/common/syscalls/yaml.ts index 3546b6ba..7a284fdb 100644 --- a/common/syscalls/yaml.ts +++ b/common/syscalls/yaml.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { YAML } from "../../web/deps.ts"; type YamlStringifyOptions = { diff --git a/common/template/render.test.ts b/common/template/render.test.ts index e2bdc2ea..4cc7da84 100644 --- a/common/template/render.test.ts +++ b/common/template/render.test.ts @@ -1,5 +1,5 @@ -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { builtinFunctions } from "../../lib/builtin_query_functions.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { renderTemplate } from "./render.ts"; import { parseTemplate } from "./template_parser.ts"; diff --git a/common/template/render.ts b/common/template/render.ts index b3401b73..29967790 100644 --- a/common/template/render.ts +++ b/common/template/render.ts @@ -1,7 +1,7 @@ -import { AST } from "$sb/lib/tree.ts"; +import { AST } from "$lib/tree.ts"; import { evalQueryExpression } from "$sb/lib/query_expression.ts"; import { expressionToKvQueryExpression } from "$sb/lib/parse-query.ts"; -import { FunctionMap } from "$sb/types.ts"; +import { FunctionMap } from "../../type/types.ts"; import { jsonToMDTable } from "../../plugs/template/util.ts"; export async function renderTemplate( diff --git a/common/template/template_parser.test.ts b/common/template/template_parser.test.ts index f0fec182..2a3d80d8 100644 --- a/common/template/template_parser.test.ts +++ b/common/template/template_parser.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { parseTemplate } from "./template_parser.ts"; Deno.test("Test template", () => { diff --git a/common/template/template_parser.ts b/common/template/template_parser.ts index 5bf2c520..778104c6 100644 --- a/common/template/template_parser.ts +++ b/common/template/template_parser.ts @@ -4,9 +4,8 @@ import { parse } from "../markdown_parser/parse_tree.ts"; import { parser as templateParser } from "./parse-template.js"; import { parser as expressionParser } from "../markdown_parser/parse-expression.js"; import { parser as queryParser } from "../markdown_parser/parse-query.js"; -import { AST } from "$sb/lib/tree.ts"; -import { parseTreeToAST } from "$sb/lib/tree.ts"; -import { deepEqual } from "$sb/lib/json.ts"; +import { AST, parseTreeToAST } from "$lib/tree.ts"; +import { deepEqual } from "../../lib/json.ts"; export const templateLanguage = LRLanguage.define({ name: "template", diff --git a/import_map.json b/import_map.json index a10f34bc..913e684f 100644 --- a/import_map.json +++ b/import_map.json @@ -16,9 +16,25 @@ "@codemirror/lang-css": "https://esm.sh/@codemirror/lang-css@6.2.1?external=@codemirror/language,@codemirror/autocomplete,@codemirror/state,@lezer/lr,@lezer/html&target=es2022", "@codemirror/lang-html": "https://esm.sh/@codemirror/lang-html@6.4.7?external=@codemirror/language,@codemirror/autocomplete,@codemirror/lang-css,@codemirror/state,@lezer/lr,@lezer/html&target=es2022", "@codemirror/search": "https://esm.sh/@codemirror/search@6.5.5?external=@codemirror/state,@codemirror/view&target=es2022", + "@codemirror/lang-markdown": "https://esm.sh/@codemirror/lang-markdown@6.2.3?external=@codemirror/state,@lezer/common,@codemirror/language,@lezer/markdown,@codemirror/view,@lezer/highlight,@codemirror/lang-html&target=es2022", + "@codemirror/legacy-modes/": "https://esm.sh/@codemirror/legacy-modes@6.3.3/", + "@codemirror/lang-javascript": "https://esm.sh/@codemirror/lang-javascript@6.2.1?external=@codemirror/language,@codemirror/autocomplete,@codemirror/view,@codemirror/state,@codemirror/lint,@lezer/common,@lezer/lr,@lezer/javascript,@codemirror/commands&target=es2022", + "@replit/codemirror-vim": "https://esm.sh/@replit/codemirror-vim@6.0.14?external=@codemirror/state,@codemirror/language,@codemirror/view,@codemirror/search,@codemirror/commands", + + "djwt": "https://deno.land/x/djwt@v3.0.1/mod.ts", + "js-yaml": "https://esm.sh/js-yaml@4.1.0", + "mimetypes": "https://deno.land/x/mimetypes@v1.0.0/mod.ts", + "gitignore-parser": "https://esm.sh/gitignore-parser@0.0.2", + "turndown": "https://cdn.skypack.dev/turndown@7.1.1", + "turndown-plugin-gfm": "https://cdn.skypack.dev/@joplin/turndown-plugin-gfm@1.0.45", + + "$common/": "./common/", + "$lib/": "./lib/", + "$type/": "./type/", "preact": "https://esm.sh/preact@10.11.1", "$sb/": "./plug-api/", - "zod": "https://deno.land/x/zod@v3.22.4/mod.ts" + "zod": "https://deno.land/x/zod@v3.22.4/mod.ts", + "$std/": "https://deno.land/std@0.189.0/" } } diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 00000000..d2913120 --- /dev/null +++ b/lib/README.md @@ -0,0 +1 @@ +This folder contains library functions that is generally reusable, not specific to SilverBullet. This code can be used from within plugs or the core code base. \ No newline at end of file diff --git a/plugos/asset_bundle/builder.ts b/lib/asset_bundle/builder.ts similarity index 95% rename from plugos/asset_bundle/builder.ts rename to lib/asset_bundle/builder.ts index 3981a3be..0fdcc83d 100644 --- a/plugos/asset_bundle/builder.ts +++ b/lib/asset_bundle/builder.ts @@ -1,4 +1,4 @@ -import { globToRegExp, mime, path, walk } from "../deps.ts"; +import { globToRegExp, mime, path, walk } from "../plugos/deps.ts"; import { AssetBundle } from "./bundle.ts"; export async function bundleAssets( diff --git a/plugos/asset_bundle/bundle.test.ts b/lib/asset_bundle/bundle.test.ts similarity index 92% rename from plugos/asset_bundle/bundle.test.ts rename to lib/asset_bundle/bundle.test.ts index cc68f3cc..1a65febf 100644 --- a/plugos/asset_bundle/bundle.test.ts +++ b/lib/asset_bundle/bundle.test.ts @@ -1,5 +1,5 @@ import { AssetBundle } from "./bundle.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; Deno.test("Asset bundle", () => { const assetBundle = new AssetBundle(); diff --git a/plugos/asset_bundle/bundle.ts b/lib/asset_bundle/bundle.ts similarity index 96% rename from plugos/asset_bundle/bundle.ts rename to lib/asset_bundle/bundle.ts index 78ff5c7d..a64cd9cd 100644 --- a/plugos/asset_bundle/bundle.ts +++ b/lib/asset_bundle/bundle.ts @@ -1,4 +1,4 @@ -import { base64Decode, base64EncodedDataUrl } from "./base64.ts"; +import { base64Decode, base64EncodedDataUrl } from "$lib/crypto.ts"; type DataUrl = string; diff --git a/plug-api/lib/async.test.ts b/lib/async.test.ts similarity index 95% rename from plug-api/lib/async.test.ts rename to lib/async.test.ts index b7e9288d..75cc2fc8 100644 --- a/plug-api/lib/async.test.ts +++ b/lib/async.test.ts @@ -1,4 +1,4 @@ -import { assert, assertEquals } from "../../test_deps.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; import { batchRequests, PromiseQueue, sleep } from "./async.ts"; Deno.test("PromiseQueue test", async () => { diff --git a/plug-api/lib/async.ts b/lib/async.ts similarity index 90% rename from plug-api/lib/async.ts rename to lib/async.ts index 243447a5..91d4414a 100644 --- a/plug-api/lib/async.ts +++ b/lib/async.ts @@ -89,3 +89,13 @@ export async function batchRequests( } return results; } + +/** + * Runs a function safely by catching any errors and logging them to the console. + * @param fn - The function to run. + */ +export function safeRun(fn: () => Promise) { + fn().catch((e) => { + console.error(e); + }); +} diff --git a/plug-api/lib/builtin_query_functions.ts b/lib/builtin_query_functions.ts similarity index 94% rename from plug-api/lib/builtin_query_functions.ts rename to lib/builtin_query_functions.ts index d14d7e4b..3d0f82ee 100644 --- a/plug-api/lib/builtin_query_functions.ts +++ b/lib/builtin_query_functions.ts @@ -1,5 +1,5 @@ -import type { FunctionMap } from "$sb/types.ts"; -import { niceDate, niceTime } from "$sb/lib/dates.ts"; +import type { FunctionMap } from "../type/types.ts"; +import { niceDate, niceTime } from "./dates.ts"; export const builtinFunctions: FunctionMap = { today() { diff --git a/plug-api/lib/cheap_yaml.test.ts b/lib/cheap_yaml.test.ts similarity index 96% rename from plug-api/lib/cheap_yaml.test.ts rename to lib/cheap_yaml.test.ts index 799cfb31..a0edea55 100644 --- a/plug-api/lib/cheap_yaml.test.ts +++ b/lib/cheap_yaml.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { determineTags, isTemplate } from "./cheap_yaml.ts"; Deno.test("cheap yaml", () => { diff --git a/plug-api/lib/cheap_yaml.ts b/lib/cheap_yaml.ts similarity index 100% rename from plug-api/lib/cheap_yaml.ts rename to lib/cheap_yaml.ts diff --git a/common/crypto.ts b/lib/crypto.ts similarity index 79% rename from common/crypto.ts rename to lib/crypto.ts index 542f674d..0f2e8d17 100644 --- a/common/crypto.ts +++ b/lib/crypto.ts @@ -146,3 +146,37 @@ function appendBuffer(buffer1: Uint8Array, buffer2: Uint8Array): Uint8Array { tmp.set(new Uint8Array(buffer2), buffer1.byteLength); return tmp; } + +export function base64Decode(s: string): Uint8Array { + const binString = atob(s); + const len = binString.length; + const bytes = new Uint8Array(len); + for (let i = 0; i < len; i++) { + bytes[i] = binString.charCodeAt(i); + } + return bytes; +} + +export function base64Encode(buffer: Uint8Array | string): string { + if (typeof buffer === "string") { + buffer = new TextEncoder().encode(buffer); + } + let binary = ""; + const len = buffer.byteLength; + for (let i = 0; i < len; i++) { + binary += String.fromCharCode(buffer[i]); + } + return btoa(binary); +} + +export function base64EncodedDataUrl( + mimeType: string, + buffer: Uint8Array, +): string { + return `data:${mimeType};base64,${base64Encode(buffer)}`; +} + +export function base64DecodeDataUrl(dataUrl: string): Uint8Array { + const b64Encoded = dataUrl.split(",", 2)[1]; + return base64Decode(b64Encoded); +} diff --git a/plugos/lib/datastore.test.ts b/lib/data/datastore.test.ts similarity index 90% rename from plugos/lib/datastore.test.ts rename to lib/data/datastore.test.ts index 0154c2cb..a9c42dc9 100644 --- a/plugos/lib/datastore.test.ts +++ b/lib/data/datastore.test.ts @@ -1,11 +1,11 @@ import "https://esm.sh/fake-indexeddb@4.0.2/auto"; -import { IndexedDBKvPrimitives } from "./indexeddb_kv_primitives.ts"; -import { DataStore } from "./datastore.ts"; -import { DenoKvPrimitives } from "./deno_kv_primitives.ts"; -import { KvPrimitives } from "./kv_primitives.ts"; +import { IndexedDBKvPrimitives } from "../data/indexeddb_kv_primitives.ts"; +import { DataStore } from "../data/datastore.ts"; +import { DenoKvPrimitives } from "../data/deno_kv_primitives.ts"; +import { KvPrimitives } from "../data/kv_primitives.ts"; import { assertEquals } from "https://deno.land/std@0.165.0/testing/asserts.ts"; -import { PrefixedKvPrimitives } from "./prefixed_kv_primitives.ts"; -import { Query } from "$sb/types.ts"; +import { PrefixedKvPrimitives } from "../data/prefixed_kv_primitives.ts"; +import { Query } from "$type/types.ts"; async function test(db: KvPrimitives) { const datastore = new DataStore(new PrefixedKvPrimitives(db, ["ds"]), { diff --git a/plugos/lib/datastore.ts b/lib/data/datastore.ts similarity index 95% rename from plugos/lib/datastore.ts rename to lib/data/datastore.ts index 9c872775..ec25ccd8 100644 --- a/plugos/lib/datastore.ts +++ b/lib/data/datastore.ts @@ -1,6 +1,6 @@ import { applyQueryNoFilterKV } from "$sb/lib/query.ts"; -import { FunctionMap, KV, KvKey, KvQuery } from "$sb/types.ts"; -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; +import { FunctionMap, KV, KvKey, KvQuery } from "$type/types.ts"; +import { builtinFunctions } from "$lib/builtin_query_functions.ts"; import { KvPrimitives } from "./kv_primitives.ts"; import { evalQueryExpression } from "$sb/lib/query_expression.ts"; /** diff --git a/plugos/lib/deno_kv_primitives.test.ts b/lib/data/deno_kv_primitives.test.ts similarity index 100% rename from plugos/lib/deno_kv_primitives.test.ts rename to lib/data/deno_kv_primitives.test.ts diff --git a/plugos/lib/deno_kv_primitives.ts b/lib/data/deno_kv_primitives.ts similarity index 97% rename from plugos/lib/deno_kv_primitives.ts rename to lib/data/deno_kv_primitives.ts index 94cb14c3..a3c3e18a 100644 --- a/plugos/lib/deno_kv_primitives.ts +++ b/lib/data/deno_kv_primitives.ts @@ -1,6 +1,6 @@ /// -import { KV, KvKey } from "$sb/types.ts"; +import { KV, KvKey } from "$type/types.ts"; import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; const kvBatchSize = 100; diff --git a/plugos/lib/dynamodb_kv_primitives.ts b/lib/data/dynamodb_kv_primitives.ts similarity index 97% rename from plugos/lib/dynamodb_kv_primitives.ts rename to lib/data/dynamodb_kv_primitives.ts index b8c2b826..6ea5ac81 100644 --- a/plugos/lib/dynamodb_kv_primitives.ts +++ b/lib/data/dynamodb_kv_primitives.ts @@ -1,4 +1,4 @@ -import { KV, KvKey } from "../../plug-api/types.ts"; +import { KV, KvKey } from "$type/types.ts"; import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; import { createClient, diff --git a/plugos/lib/indexeddb_kv_primitives.test.ts b/lib/data/indexeddb_kv_primitives.test.ts similarity index 100% rename from plugos/lib/indexeddb_kv_primitives.test.ts rename to lib/data/indexeddb_kv_primitives.test.ts diff --git a/plugos/lib/indexeddb_kv_primitives.ts b/lib/data/indexeddb_kv_primitives.ts similarity index 97% rename from plugos/lib/indexeddb_kv_primitives.ts rename to lib/data/indexeddb_kv_primitives.ts index aaa310ef..5169764d 100644 --- a/plugos/lib/indexeddb_kv_primitives.ts +++ b/lib/data/indexeddb_kv_primitives.ts @@ -1,4 +1,4 @@ -import { KV, KvKey } from "$sb/types.ts"; +import { KV, KvKey } from "$type/types.ts"; import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; import { IDBPDatabase, openDB } from "https://esm.sh/idb@7.1.1/with-async-ittr"; diff --git a/plugos/lib/kv_primitives.test.ts b/lib/data/kv_primitives.test.ts similarity index 95% rename from plugos/lib/kv_primitives.test.ts rename to lib/data/kv_primitives.test.ts index 8343a0cd..8fa33897 100644 --- a/plugos/lib/kv_primitives.test.ts +++ b/lib/data/kv_primitives.test.ts @@ -1,6 +1,6 @@ import { KvPrimitives } from "./kv_primitives.ts"; -import { assertEquals } from "../../test_deps.ts"; -import { KV } from "$sb/types.ts"; +import { assertEquals } from "$lib/test_deps.ts"; +import { KV } from "$type/types.ts"; export async function allTests(db: KvPrimitives) { await db.batchSet([ diff --git a/plugos/lib/kv_primitives.ts b/lib/data/kv_primitives.ts similarity index 87% rename from plugos/lib/kv_primitives.ts rename to lib/data/kv_primitives.ts index 81a85cc3..70f1b1df 100644 --- a/plugos/lib/kv_primitives.ts +++ b/lib/data/kv_primitives.ts @@ -1,4 +1,4 @@ -import { KV, KvKey } from "$sb/types.ts"; +import { KV, KvKey } from "$type/types.ts"; export type KvQueryOptions = { prefix?: KvKey; diff --git a/plugos/lib/memory_kv_primitives.test.ts b/lib/data/memory_kv_primitives.test.ts similarity index 100% rename from plugos/lib/memory_kv_primitives.test.ts rename to lib/data/memory_kv_primitives.test.ts diff --git a/plugos/lib/memory_kv_primitives.ts b/lib/data/memory_kv_primitives.ts similarity index 97% rename from plugos/lib/memory_kv_primitives.ts rename to lib/data/memory_kv_primitives.ts index cb9ea7d8..ff0d9771 100644 --- a/plugos/lib/memory_kv_primitives.ts +++ b/lib/data/memory_kv_primitives.ts @@ -1,4 +1,4 @@ -import { KV, KvKey } from "$sb/types.ts"; +import { KV, KvKey } from "$type/types.ts"; import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; const memoryKeySeparator = "\0"; diff --git a/plugos/lib/mq.datastore.test.ts b/lib/data/mq.datastore.test.ts similarity index 96% rename from plugos/lib/mq.datastore.test.ts rename to lib/data/mq.datastore.test.ts index dca3171e..b6956c8f 100644 --- a/plugos/lib/mq.datastore.test.ts +++ b/lib/data/mq.datastore.test.ts @@ -1,9 +1,9 @@ import { DataStoreMQ } from "./mq.datastore.ts"; -import { assertEquals } from "../../test_deps.ts"; -import { sleep } from "$sb/lib/async.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { DenoKvPrimitives } from "./deno_kv_primitives.ts"; import { DataStore } from "./datastore.ts"; import { PrefixedKvPrimitives } from "./prefixed_kv_primitives.ts"; +import { sleep } from "$lib/async.ts"; Deno.test("DataStore MQ", async () => { const tmpFile = await Deno.makeTempFile(); diff --git a/plugos/lib/mq.datastore.ts b/lib/data/mq.datastore.ts similarity index 99% rename from plugos/lib/mq.datastore.ts rename to lib/data/mq.datastore.ts index 53cdf0a4..d2d7ab56 100644 --- a/plugos/lib/mq.datastore.ts +++ b/lib/data/mq.datastore.ts @@ -1,4 +1,4 @@ -import { KV, MQMessage, MQStats, MQSubscribeOptions } from "$sb/types.ts"; +import { KV, MQMessage, MQStats, MQSubscribeOptions } from "$type/types.ts"; import { MessageQueue } from "./mq.ts"; import { DataStore } from "./datastore.ts"; diff --git a/plugos/lib/mq.ts b/lib/data/mq.ts similarity index 87% rename from plugos/lib/mq.ts rename to lib/data/mq.ts index 3717a57b..fbd849b6 100644 --- a/plugos/lib/mq.ts +++ b/lib/data/mq.ts @@ -1,4 +1,4 @@ -import { MQMessage, MQStats, MQSubscribeOptions } from "$sb/types.ts"; +import { MQMessage, MQStats, MQSubscribeOptions } from "$type/types.ts"; export interface MessageQueue { batchSend(queue: string, bodies: any[]): Promise; diff --git a/plugos/lib/prefixed_kv_primitives.ts b/lib/data/prefixed_kv_primitives.ts similarity index 96% rename from plugos/lib/prefixed_kv_primitives.ts rename to lib/data/prefixed_kv_primitives.ts index e153d066..d09b1e86 100644 --- a/plugos/lib/prefixed_kv_primitives.ts +++ b/lib/data/prefixed_kv_primitives.ts @@ -1,4 +1,4 @@ -import { KV, KvKey } from "$sb/types.ts"; +import { KV, KvKey } from "$type/types.ts"; import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; /** diff --git a/plug-api/lib/dates.ts b/lib/dates.ts similarity index 100% rename from plug-api/lib/dates.ts rename to lib/dates.ts diff --git a/plug-api/lib/json.test.ts b/lib/json.test.ts similarity index 93% rename from plug-api/lib/json.test.ts rename to lib/json.test.ts index 5e2ada03..9d365558 100644 --- a/plug-api/lib/json.test.ts +++ b/lib/json.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { deepEqual, deepObjectMerge, expandPropertyNames } from "./json.ts"; Deno.test("utils", () => { diff --git a/plug-api/lib/json.ts b/lib/json.ts similarity index 100% rename from plug-api/lib/json.ts rename to lib/json.ts diff --git a/plug-api/lib/limited_map.test.ts b/lib/limited_map.test.ts similarity index 85% rename from plug-api/lib/limited_map.test.ts rename to lib/limited_map.test.ts index a62859d8..1b676fa2 100644 --- a/plug-api/lib/limited_map.test.ts +++ b/lib/limited_map.test.ts @@ -1,5 +1,5 @@ -import { sleep } from "$sb/lib/async.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { sleep } from "$lib/async.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { LimitedMap } from "./limited_map.ts"; Deno.test("limited map", async () => { diff --git a/plug-api/lib/limited_map.ts b/lib/limited_map.ts similarity index 100% rename from plug-api/lib/limited_map.ts rename to lib/limited_map.ts diff --git a/plug-api/lib/memory_cache.test.ts b/lib/memory_cache.test.ts similarity index 72% rename from plug-api/lib/memory_cache.test.ts rename to lib/memory_cache.test.ts index f3e71492..52ba7564 100644 --- a/plug-api/lib/memory_cache.test.ts +++ b/lib/memory_cache.test.ts @@ -1,6 +1,6 @@ -import { sleep } from "$sb/lib/async.ts"; -import { ttlCache } from "$sb/lib/memory_cache.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { ttlCache } from "$lib/memory_cache.ts"; +import { sleep } from "$lib/async.ts"; +import { assertEquals } from "$lib/test_deps.ts"; Deno.test("Memory cache", async () => { let calls = 0; diff --git a/plug-api/lib/memory_cache.ts b/lib/memory_cache.ts similarity index 88% rename from plug-api/lib/memory_cache.ts rename to lib/memory_cache.ts index a9e3046b..ab22de05 100644 --- a/plug-api/lib/memory_cache.ts +++ b/lib/memory_cache.ts @@ -1,4 +1,4 @@ -import { LimitedMap } from "$sb/lib/limited_map.ts"; +import { LimitedMap } from "./limited_map.ts"; const cache = new LimitedMap(50); diff --git a/common/path.test.ts b/lib/path.test.ts similarity index 86% rename from common/path.test.ts rename to lib/path.test.ts index b4466576..4a3ac7f2 100644 --- a/common/path.test.ts +++ b/lib/path.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { folderName, resolve } from "./path.ts"; Deno.test("Path functions", () => { diff --git a/common/path.ts b/lib/path.ts similarity index 100% rename from common/path.ts rename to lib/path.ts diff --git a/plugos/compile.ts b/lib/plugos/compile.ts similarity index 95% rename from plugos/compile.ts rename to lib/plugos/compile.ts index 4d5f8f9e..dcd2bf70 100644 --- a/plugos/compile.ts +++ b/lib/plugos/compile.ts @@ -1,8 +1,8 @@ import { denoPlugins, esbuild, path, YAML } from "./deps.ts"; -import { bundleAssets } from "./asset_bundle/builder.ts"; -import { Manifest } from "./types.ts"; -import { version } from "../version.ts"; +import { bundleAssets } from "$lib/asset_bundle/builder.ts"; +import { Manifest } from "$lib/plugos/types.ts"; +import { version } from "../../version.ts"; // const workerRuntimeUrl = new URL("./worker_runtime.ts", import.meta.url); const workerRuntimeUrl = @@ -104,7 +104,7 @@ setupMessageListener(functionMapping, manifest); ...denoPlugins({ // TODO do this differently importMapURL: options.importMap || - new URL("../import_map.json", import.meta.url).toString(), + new URL("../../import_map.json", import.meta.url).toString(), loader: "native", }), ], diff --git a/plugos/deps.ts b/lib/plugos/deps.ts similarity index 100% rename from plugos/deps.ts rename to lib/plugos/deps.ts diff --git a/plugos/event.ts b/lib/plugos/event.ts similarity index 100% rename from plugos/event.ts rename to lib/plugos/event.ts diff --git a/plugos/hooks/cron.ts b/lib/plugos/hooks/cron.ts similarity index 100% rename from plugos/hooks/cron.ts rename to lib/plugos/hooks/cron.ts diff --git a/plugos/hooks/event.ts b/lib/plugos/hooks/event.ts similarity index 100% rename from plugos/hooks/event.ts rename to lib/plugos/hooks/event.ts diff --git a/plugos/hooks/mq.ts b/lib/plugos/hooks/mq.ts similarity index 95% rename from plugos/hooks/mq.ts rename to lib/plugos/hooks/mq.ts index 59f57b45..d7c47f7e 100644 --- a/plugos/hooks/mq.ts +++ b/lib/plugos/hooks/mq.ts @@ -1,8 +1,8 @@ import { Hook, Manifest } from "../types.ts"; import { System } from "../system.ts"; -import { MQMessage } from "$sb/types.ts"; -import { MessageQueue } from "../lib/mq.ts"; -import { throttle } from "$sb/lib/async.ts"; +import { MQMessage } from "$type/types.ts"; +import { MessageQueue } from "$lib/data/mq.ts"; +import { throttle } from "$lib/async.ts"; type MQSubscription = { queue: string; diff --git a/plugos/manifest_cache.ts b/lib/plugos/manifest_cache.ts similarity index 96% rename from plugos/manifest_cache.ts rename to lib/plugos/manifest_cache.ts index 27e716d0..f1f50aba 100644 --- a/plugos/manifest_cache.ts +++ b/lib/plugos/manifest_cache.ts @@ -1,4 +1,4 @@ -import { KvPrimitives } from "./lib/kv_primitives.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; import { Plug } from "./plug.ts"; import { Manifest } from "./types.ts"; diff --git a/plugos/plug.ts b/lib/plugos/plug.ts similarity index 98% rename from plugos/plug.ts rename to lib/plugos/plug.ts index 6c093be7..cd443b2c 100644 --- a/plugos/plug.ts +++ b/lib/plugos/plug.ts @@ -1,6 +1,6 @@ import { Manifest } from "./types.ts"; import { System } from "./system.ts"; -import { AssetBundle } from "./asset_bundle/bundle.ts"; +import { AssetBundle } from "../asset_bundle/bundle.ts"; import { Sandbox, SandboxFactory } from "./sandboxes/sandbox.ts"; export class Plug { diff --git a/plugos/protocol.ts b/lib/plugos/protocol.ts similarity index 92% rename from plugos/protocol.ts rename to lib/plugos/protocol.ts index 563f4a46..7925d9b4 100644 --- a/plugos/protocol.ts +++ b/lib/plugos/protocol.ts @@ -1,4 +1,4 @@ -import type { Manifest } from "../common/manifest.ts"; +import type { Manifest } from "$common/manifest.ts"; // Messages received from the worker export type ControllerMessage = diff --git a/plugos/runtime.test.ts b/lib/plugos/runtime.test.ts similarity index 95% rename from plugos/runtime.test.ts rename to lib/plugos/runtime.test.ts index ea79866d..26bc511b 100644 --- a/plugos/runtime.test.ts +++ b/lib/plugos/runtime.test.ts @@ -1,14 +1,14 @@ import { createSandbox } from "./sandboxes/deno_worker_sandbox.ts"; import { System } from "./system.ts"; -import { assert, assertEquals } from "../test_deps.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; import { compileManifest } from "./compile.ts"; import { esbuild } from "./deps.ts"; import { createSandbox as createNoSandbox, runWithSystemLock, } from "./sandboxes/no_sandbox.ts"; -import { sleep } from "$sb/lib/async.ts"; import { SysCallMapping } from "./system.ts"; +import { sleep } from "../async.ts"; Deno.test("Run a deno sandbox", { sanitizeResources: false, diff --git a/plugos/sandboxes/deno_worker_sandbox.ts b/lib/plugos/sandboxes/deno_worker_sandbox.ts similarity index 100% rename from plugos/sandboxes/deno_worker_sandbox.ts rename to lib/plugos/sandboxes/deno_worker_sandbox.ts diff --git a/plugos/sandboxes/no_sandbox.ts b/lib/plugos/sandboxes/no_sandbox.ts similarity index 98% rename from plugos/sandboxes/no_sandbox.ts rename to lib/plugos/sandboxes/no_sandbox.ts index e7009463..83a732bf 100644 --- a/plugos/sandboxes/no_sandbox.ts +++ b/lib/plugos/sandboxes/no_sandbox.ts @@ -1,9 +1,9 @@ -import { PromiseQueue } from "$sb/lib/async.ts"; import { Plug } from "../plug.ts"; import { Sandbox } from "./sandbox.ts"; import { Manifest } from "../types.ts"; import { System } from "../system.ts"; import { SandboxFactory } from "./sandbox.ts"; +import { PromiseQueue } from "../../async.ts"; /** * This implements a "no sandbox" sandbox that actually runs code the main thread, without any isolation. diff --git a/plugos/sandboxes/sandbox.ts b/lib/plugos/sandboxes/sandbox.ts similarity index 100% rename from plugos/sandboxes/sandbox.ts rename to lib/plugos/sandboxes/sandbox.ts diff --git a/plugos/sandboxes/web_worker_sandbox.ts b/lib/plugos/sandboxes/web_worker_sandbox.ts similarity index 100% rename from plugos/sandboxes/web_worker_sandbox.ts rename to lib/plugos/sandboxes/web_worker_sandbox.ts diff --git a/plugos/sandboxes/worker_sandbox.ts b/lib/plugos/sandboxes/worker_sandbox.ts similarity index 97% rename from plugos/sandboxes/worker_sandbox.ts rename to lib/plugos/sandboxes/worker_sandbox.ts index 20320256..3312cb18 100644 --- a/plugos/sandboxes/worker_sandbox.ts +++ b/lib/plugos/sandboxes/worker_sandbox.ts @@ -1,7 +1,7 @@ import { Manifest } from "../types.ts"; import { ControllerMessage, WorkerMessage } from "../protocol.ts"; import { Plug } from "../plug.ts"; -import { AssetBundle, AssetJson } from "../asset_bundle/bundle.ts"; +import { AssetBundle, AssetJson } from "../../asset_bundle/bundle.ts"; import { Sandbox } from "./sandbox.ts"; /** diff --git a/plugos/syscalls/asset.ts b/lib/plugos/syscalls/asset.ts similarity index 100% rename from plugos/syscalls/asset.ts rename to lib/plugos/syscalls/asset.ts diff --git a/plugos/syscalls/datastore.ts b/lib/plugos/syscalls/datastore.ts similarity index 93% rename from plugos/syscalls/datastore.ts rename to lib/plugos/syscalls/datastore.ts index f9bd528d..7aadb23b 100644 --- a/plugos/syscalls/datastore.ts +++ b/lib/plugos/syscalls/datastore.ts @@ -1,5 +1,5 @@ -import { KV, KvKey, KvQuery } from "$sb/types.ts"; -import type { DataStore } from "../lib/datastore.ts"; +import { KV, KvKey, KvQuery } from "$type/types.ts"; +import type { DataStore } from "$lib/data/datastore.ts"; import type { SysCallMapping } from "../system.ts"; /** diff --git a/plugos/syscalls/event.ts b/lib/plugos/syscalls/event.ts similarity index 100% rename from plugos/syscalls/event.ts rename to lib/plugos/syscalls/event.ts diff --git a/plugos/syscalls/fetch.ts b/lib/plugos/syscalls/fetch.ts similarity index 71% rename from plugos/syscalls/fetch.ts rename to lib/plugos/syscalls/fetch.ts index cd279d59..8706006c 100644 --- a/plugos/syscalls/fetch.ts +++ b/lib/plugos/syscalls/fetch.ts @@ -1,9 +1,6 @@ -import type { SysCallMapping } from "../../plugos/system.ts"; -import { - ProxyFetchRequest, - ProxyFetchResponse, -} from "../../common/proxy_fetch.ts"; -import { base64Encode } from "../asset_bundle/base64.ts"; +import type { SysCallMapping } from "../system.ts"; +import { ProxyFetchRequest, ProxyFetchResponse } from "$common/proxy_fetch.ts"; +import { base64Encode } from "../../crypto.ts"; export function sandboxFetchSyscalls(): SysCallMapping { return { diff --git a/plugos/syscalls/fs.deno.test.ts b/lib/plugos/syscalls/fs.deno.test.ts similarity index 82% rename from plugos/syscalls/fs.deno.test.ts rename to lib/plugos/syscalls/fs.deno.test.ts index cf4f65a0..aa3e4c0f 100644 --- a/plugos/syscalls/fs.deno.test.ts +++ b/lib/plugos/syscalls/fs.deno.test.ts @@ -1,5 +1,5 @@ -import { FileMeta } from "$sb/types.ts"; -import { assert } from "../../test_deps.ts"; +import { FileMeta } from "../../../type/types.ts"; +import { assert } from "$lib/test_deps.ts"; import { path } from "../deps.ts"; import fileSystemSyscalls from "./fs.deno.ts"; diff --git a/plugos/syscalls/fs.deno.ts b/lib/plugos/syscalls/fs.deno.ts similarity index 96% rename from plugos/syscalls/fs.deno.ts rename to lib/plugos/syscalls/fs.deno.ts index 4c5eb3a7..da68ab64 100644 --- a/plugos/syscalls/fs.deno.ts +++ b/lib/plugos/syscalls/fs.deno.ts @@ -1,7 +1,7 @@ import type { SysCallMapping } from "../system.ts"; import { mime, path, walk } from "../deps.ts"; -import { base64DecodeDataUrl, base64Encode } from "../asset_bundle/base64.ts"; -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../../../type/types.ts"; +import { base64DecodeDataUrl, base64Encode } from "../../crypto.ts"; export default function fileSystemSyscalls(root = "/"): SysCallMapping { function resolvedPath(p: string): string { diff --git a/plugos/syscalls/mq.ts b/lib/plugos/syscalls/mq.ts similarity index 92% rename from plugos/syscalls/mq.ts rename to lib/plugos/syscalls/mq.ts index 93ee29b2..a62125b6 100644 --- a/plugos/syscalls/mq.ts +++ b/lib/plugos/syscalls/mq.ts @@ -1,5 +1,5 @@ import { SysCallMapping } from "../system.ts"; -import { MessageQueue } from "../lib/mq.ts"; +import { MessageQueue } from "$lib/data/mq.ts"; export function mqSyscalls( mq: MessageQueue, diff --git a/plugos/system.ts b/lib/plugos/system.ts similarity index 100% rename from plugos/system.ts rename to lib/plugos/system.ts diff --git a/plugos/test.plug.yaml b/lib/plugos/test.plug.yaml similarity index 100% rename from plugos/test.plug.yaml rename to lib/plugos/test.plug.yaml diff --git a/plugos/test_func.test.ts b/lib/plugos/test_func.test.ts similarity index 63% rename from plugos/test_func.test.ts rename to lib/plugos/test_func.test.ts index 2f6d141e..5a41529e 100644 --- a/plugos/test_func.test.ts +++ b/lib/plugos/test_func.test.ts @@ -1,10 +1,13 @@ -import * as YAML from "https://deno.land/std@0.184.0/yaml/mod.ts"; -import { EndpointRequest, EndpointResponse } from "./hooks/endpoint.ts"; +import * as YAML from "js-yaml"; +import { + EndpointRequest, + EndpointResponse, +} from "../../server/hooks/endpoint.ts"; export async function hello() { const numbers = await syscall("addNumbers", 1, 2); return { - yamlMessage: YAML.stringify({ hello: "world" }), + yamlMessage: YAML.dump({ hello: "world" }), addedNumbers: numbers, }; } diff --git a/plugos/types.ts b/lib/plugos/types.ts similarity index 97% rename from plugos/types.ts rename to lib/plugos/types.ts index 95f3c3fe..9ecf7a1d 100644 --- a/plugos/types.ts +++ b/lib/plugos/types.ts @@ -1,5 +1,5 @@ import { System } from "./system.ts"; -import { AssetJson } from "./asset_bundle/bundle.ts"; +import { AssetJson } from "$lib/asset_bundle/bundle.ts"; /** The generic top level of a plug manifest file. * Defines plug metadata and functions. diff --git a/plugos/worker_runtime.ts b/lib/plugos/worker_runtime.ts similarity index 99% rename from plugos/worker_runtime.ts rename to lib/plugos/worker_runtime.ts index f09db587..7f1b188e 100644 --- a/plugos/worker_runtime.ts +++ b/lib/plugos/worker_runtime.ts @@ -3,7 +3,7 @@ import type { ControllerMessage, WorkerMessage } from "./protocol.ts"; import type { ProxyFetchRequest, ProxyFetchResponse, -} from "../common/proxy_fetch.ts"; +} from "$common/proxy_fetch.ts"; declare global { function syscall(name: string, ...args: any[]): Promise; diff --git a/test_deps.ts b/lib/test_deps.ts similarity index 100% rename from test_deps.ts rename to lib/test_deps.ts diff --git a/plug-api/lib/tree.test.ts b/lib/tree.test.ts similarity index 89% rename from plug-api/lib/tree.test.ts rename to lib/tree.test.ts index d45152d5..981344d3 100644 --- a/plug-api/lib/tree.test.ts +++ b/lib/tree.test.ts @@ -9,9 +9,9 @@ import { renderToText, replaceNodesMatching, } from "./tree.ts"; -import { assertEquals, assertNotEquals } from "../../test_deps.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { assertEquals, assertNotEquals } from "$lib/test_deps.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; const mdTest1 = ` # Heading diff --git a/plug-api/lib/tree.ts b/lib/tree.ts similarity index 100% rename from plug-api/lib/tree.ts rename to lib/tree.ts diff --git a/netlify.toml b/netlify.toml index 06f09445..81133584 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,8 +1,3 @@ [build] publish = "website_build" command = "./scripts/build_website.sh" - -[[plugins]] -package = "netlify-plugin-cache" - [plugins.inputs] - paths = ["deno_cache"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index c2edcd95..00000000 --- a/package-lock.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "silverbullet", - "version": "0.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "silverbullet", - "version": "0.0.0", - "dependencies": { - "netlify-plugin-cache": "^1.0.3" - } - }, - "node_modules/netlify-plugin-cache": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/netlify-plugin-cache/-/netlify-plugin-cache-1.0.3.tgz", - "integrity": "sha512-CTOwNWrTOP59T6y6unxQNnp1WX702v2R/faR5peSH94ebrYfyY4zT5IsRcIiHKq57jXeyCrhy0GLuTN8ktzuQg==" - } - }, - "dependencies": { - "netlify-plugin-cache": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/netlify-plugin-cache/-/netlify-plugin-cache-1.0.3.tgz", - "integrity": "sha512-CTOwNWrTOP59T6y6unxQNnp1WX702v2R/faR5peSH94ebrYfyY4zT5IsRcIiHKq57jXeyCrhy0GLuTN8ktzuQg==" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 81810576..00000000 --- a/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "silverbullet", - "version": "0.0.0", - "local": true, - "description": "This package.json is just for Netlify", - "dependencies": { - "netlify-plugin-cache": "^1.0.3" - } -} diff --git a/plug-api/app_event.ts b/plug-api/app_event.ts deleted file mode 100644 index 5ac6e50d..00000000 --- a/plug-api/app_event.ts +++ /dev/null @@ -1,81 +0,0 @@ -import type { ParseTree } from "$sb/lib/tree.ts"; -import { TextChange } from "$sb/lib/change.ts"; -import { Query } from "$sb/types.ts"; - -export type AppEvent = - | "page:click" - | "editor:complete" - | "minieditor:complete" - | "slash:complete" - | "editor:lint" - | "page:load" - | "editor:init" - | "editor:pageLoaded" // args: pageName, previousPage, isSynced - | "editor:pageReloaded" - | "editor:pageSaved" - | "editor:modeswitch" - | "plugs:loaded" - | "editor:pageModified"; - -export type QueryProviderEvent = { - query: Query; - variables?: Record; -}; - -export type ClickEvent = { - page: string; - pos: number; - metaKey: boolean; - ctrlKey: boolean; - altKey: boolean; -}; - -export type IndexEvent = { - name: string; - text: string; -}; - -export type IndexTreeEvent = { - name: string; - tree: ParseTree; -}; - -export type PublishEvent = { - uri?: string; - // Page name - name: string; -}; - -export type LintEvent = { - name: string; - tree: ParseTree; -}; - -export type CompleteEvent = { - pageName: string; - linePrefix: string; - pos: number; - parentNodes: string[]; -}; - -export type SlashCompletion = { - label: string; - detail?: string; - invoke: string; - order?: number; -} & Record; - -export type WidgetContent = { - html?: string; - script?: string; - markdown?: string; - url?: string; - height?: number; - width?: number; -}; - -/** PageModifiedEvent payload for "editor:pageModified". Fired when the document text changes - */ -export type PageModifiedEvent = { - changes: TextChange[]; -}; diff --git a/plug-api/lib/README.md b/plug-api/lib/README.md new file mode 100644 index 00000000..f50a9eac --- /dev/null +++ b/plug-api/lib/README.md @@ -0,0 +1 @@ +This folder contains useful library functions to be used by plugs, built-in or external. \ No newline at end of file diff --git a/plug-api/lib/async_util.test.ts b/plug-api/lib/async_util.test.ts deleted file mode 100644 index ca01f62f..00000000 --- a/plug-api/lib/async_util.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { assertEquals } from "../../test_deps.ts"; -import { PromiseQueue, sleep } from "./async.ts"; - -Deno.test("PromiseQueue test", async () => { - const q = new PromiseQueue(); - let r1RanFirst = false; - const r1 = q.runInQueue(async () => { - await sleep(10); - r1RanFirst = true; - console.log("1"); - return 1; - }); - const r2 = q.runInQueue(async () => { - console.log("2"); - await sleep(4); - return 2; - }); - console.log(await Promise.all([r1, r2])); - assertEquals(r1RanFirst, true); -}); diff --git a/plug-api/lib/attribute.test.ts b/plug-api/lib/attribute.test.ts index 4786e430..f98e66c2 100644 --- a/plug-api/lib/attribute.test.ts +++ b/plug-api/lib/attribute.test.ts @@ -1,9 +1,9 @@ import "$sb/lib/syscall_mock.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; -import { assertEquals } from "../../test_deps.ts"; -import { renderToText } from "$sb/lib/tree.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { assertEquals } from "$lib/test_deps.ts"; +import { renderToText } from "$lib/tree.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; const inlineAttributeSample = ` # My document diff --git a/plug-api/lib/attribute.ts b/plug-api/lib/attribute.ts index a9ac920f..25d43112 100644 --- a/plug-api/lib/attribute.ts +++ b/plug-api/lib/attribute.ts @@ -2,7 +2,7 @@ import { findNodeOfType, ParseTree, replaceNodesMatchingAsync, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; import { YAML } from "$sb/syscalls.ts"; diff --git a/plug-api/lib/feed.test.ts b/plug-api/lib/feed.test.ts index 77c531d2..3fc2e036 100644 --- a/plug-api/lib/feed.test.ts +++ b/plug-api/lib/feed.test.ts @@ -1,8 +1,8 @@ import "$sb/lib/syscall_mock.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { extractFeedItems } from "$sb/lib/feed.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; const feedSample1 = `--- test: ignore me diff --git a/plug-api/lib/feed.ts b/plug-api/lib/feed.ts index dd253e77..2bbc97c8 100644 --- a/plug-api/lib/feed.ts +++ b/plug-api/lib/feed.ts @@ -3,7 +3,11 @@ import { findNodeOfType, ParseTree, renderToText, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; + +/** + * Feed parsing functionality (WIP) + */ import { extractAttributes } from "$sb/lib/attribute.ts"; diff --git a/plug-api/lib/frontmatter.ts b/plug-api/lib/frontmatter.ts index ee2804b7..49f3d86f 100644 --- a/plug-api/lib/frontmatter.ts +++ b/plug-api/lib/frontmatter.ts @@ -1,13 +1,12 @@ -import { YAML } from "$sb/plugos-syscall/mod.ts"; - import { addParentPointers, ParseTree, renderToText, replaceNodesMatchingAsync, traverseTreeAsync, -} from "$sb/lib/tree.ts"; -import { expandPropertyNames } from "$sb/lib/json.ts"; +} from "$lib/tree.ts"; +import { expandPropertyNames } from "$lib/json.ts"; +import { YAML } from "$sb/syscalls.ts"; export type FrontMatter = { tags?: string[] } & Record; diff --git a/plug-api/lib/fetch.ts b/plug-api/lib/native_fetch.ts similarity index 100% rename from plug-api/lib/fetch.ts rename to plug-api/lib/native_fetch.ts diff --git a/plug-api/lib/page.test.ts b/plug-api/lib/page_ref.test.ts similarity index 89% rename from plug-api/lib/page.test.ts rename to plug-api/lib/page_ref.test.ts index 5db71590..de31de15 100644 --- a/plug-api/lib/page.test.ts +++ b/plug-api/lib/page_ref.test.ts @@ -1,5 +1,5 @@ -import { encodePageRef, parsePageRef } from "$sb/lib/page.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { encodePageRef, parsePageRef } from "./page_ref.ts"; +import { assertEquals } from "$lib/test_deps.ts"; Deno.test("Page utility functions", () => { // Base cases diff --git a/plug-api/lib/page.ts b/plug-api/lib/page_ref.ts similarity index 100% rename from plug-api/lib/page.ts rename to plug-api/lib/page_ref.ts diff --git a/plug-api/lib/parse-query.ts b/plug-api/lib/parse-query.ts index 33c09d05..26ca70a1 100644 --- a/plug-api/lib/parse-query.ts +++ b/plug-api/lib/parse-query.ts @@ -1,5 +1,5 @@ -import { type AST, parseTreeToAST } from "$sb/lib/tree.ts"; -import type { Query, QueryExpression } from "$sb/types.ts"; +import { type AST, parseTreeToAST } from "$lib/tree.ts"; +import type { Query, QueryExpression } from "../../type/types.ts"; import { language } from "$sb/syscalls.ts"; export function astToKvQuery( diff --git a/plug-api/lib/parser-query.test.ts b/plug-api/lib/parser-query.test.ts index 72ade1d8..e750f352 100644 --- a/plug-api/lib/parser-query.test.ts +++ b/plug-api/lib/parser-query.test.ts @@ -1,8 +1,8 @@ -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { AST, collectNodesOfType, parseTreeToAST } from "$sb/lib/tree.ts"; -import { assert, assertEquals } from "../../test_deps.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { AST, collectNodesOfType, parseTreeToAST } from "$lib/tree.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; import { astToKvQuery } from "$sb/lib/parse-query.ts"; -import { languageFor } from "../../common/languages.ts"; +import { languageFor } from "$common/languages.ts"; function wrapQueryParse(query: string): AST | null { const tree = parse(languageFor("query")!, query); diff --git a/plug-api/lib/query.ts b/plug-api/lib/query.ts index c231370b..387f7ff7 100644 --- a/plug-api/lib/query.ts +++ b/plug-api/lib/query.ts @@ -1,4 +1,4 @@ -import { FunctionMap, KV, Query, QueryExpression } from "$sb/types.ts"; +import { FunctionMap, KV, Query, QueryExpression } from "../../type/types.ts"; import { evalQueryExpression } from "$sb/lib/query_expression.ts"; /** diff --git a/plug-api/lib/query_expression.test.ts b/plug-api/lib/query_expression.test.ts index c482c6f2..280c6fb9 100644 --- a/plug-api/lib/query_expression.test.ts +++ b/plug-api/lib/query_expression.test.ts @@ -1,5 +1,5 @@ import { evalQueryExpression } from "$sb/lib/query_expression.ts"; -import { assert, assertEquals } from "../../test_deps.ts"; +import { assert, assertEquals } from "$lib/test_deps.ts"; Deno.test("Test query expression evaluation", async () => { assertEquals( diff --git a/plug-api/lib/query_expression.ts b/plug-api/lib/query_expression.ts index 94234ef3..91f99a91 100644 --- a/plug-api/lib/query_expression.ts +++ b/plug-api/lib/query_expression.ts @@ -1,4 +1,4 @@ -import { FunctionMap, QueryExpression } from "$sb/types.ts"; +import { FunctionMap, QueryExpression } from "../../type/types.ts"; export function evalQueryExpression( val: QueryExpression, diff --git a/plug-api/lib/resolve.test.ts b/plug-api/lib/resolve.test.ts index 509c2296..e0600c6d 100644 --- a/plug-api/lib/resolve.test.ts +++ b/plug-api/lib/resolve.test.ts @@ -5,9 +5,10 @@ import { resolvePath, rewritePageRefs, } from "$sb/lib/resolve.ts"; -import { assertEquals } from "../../test_deps.ts"; -import { parseMarkdown } from "$sb/lib/test_utils.ts"; -import { renderToText } from "$sb/lib/tree.ts"; +import { assertEquals } from "$lib/test_deps.ts"; +import { ParseTree, renderToText } from "$lib/tree.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; Deno.test("Test URL resolver", () => { assertEquals(resolvePath("test", "some page"), "some page"); @@ -104,3 +105,7 @@ page: "[[!silverbullet.md/template/use-template]]" resolveAttachmentPath("!silverbullet.md/something/bla", "/test.jpg"), ); }); + +function parseMarkdown(text: string): ParseTree { + return parse(extendedMarkdownLanguage, text); +} diff --git a/plug-api/lib/resolve.ts b/plug-api/lib/resolve.ts index dccb863e..02cbd095 100644 --- a/plug-api/lib/resolve.ts +++ b/plug-api/lib/resolve.ts @@ -1,4 +1,4 @@ -import { findNodeOfType, ParseTree, traverseTree } from "$sb/lib/tree.ts"; +import { findNodeOfType, ParseTree, traverseTree } from "$lib/tree.ts"; export function resolvePath( currentPage: string, diff --git a/plug-api/lib/settings_page.ts b/plug-api/lib/settings_page.ts index 1df934b8..69b3c687 100644 --- a/plug-api/lib/settings_page.ts +++ b/plug-api/lib/settings_page.ts @@ -1,7 +1,5 @@ import { readYamlPage } from "$sb/lib/yaml_page.ts"; -import { YAML } from "$sb/plugos-syscall/mod.ts"; - -import { editor, space } from "$sb/silverbullet-syscall/mod.ts"; +import { editor, space, YAML } from "$sb/syscalls.ts"; /** * Convenience function to read a specific set of settings from the `SETTINGS` page as well as default values diff --git a/plug-api/lib/syscall_mock.ts b/plug-api/lib/syscall_mock.ts index 4ed1a257..f42544ca 100644 --- a/plug-api/lib/syscall_mock.ts +++ b/plug-api/lib/syscall_mock.ts @@ -1,4 +1,4 @@ -import { YAML } from "../../common/deps.ts"; +import { YAML } from "$common/deps.ts"; globalThis.syscall = (name: string, ...args: readonly any[]) => { switch (name) { diff --git a/plug-api/lib/tags.ts b/plug-api/lib/tags.ts index f0358b8e..5d7ac9a0 100644 --- a/plug-api/lib/tags.ts +++ b/plug-api/lib/tags.ts @@ -1,5 +1,5 @@ import { FrontMatter } from "$sb/lib/frontmatter.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "../../type/types.ts"; export function updateITags(obj: ObjectValue, frontmatter: FrontMatter) { const itags = [obj.tag, ...frontmatter.tags || []]; diff --git a/plug-api/lib/test_utils.ts b/plug-api/lib/test_utils.ts deleted file mode 100644 index 2570f624..00000000 --- a/plug-api/lib/test_utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { ParseTree } from "$sb/lib/tree.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; - -export function parseMarkdown(text: string): ParseTree { - return parse(extendedMarkdownLanguage, text); -} diff --git a/plug-api/lib/yaml_page.ts b/plug-api/lib/yaml_page.ts index 8704e3a6..a7e98089 100644 --- a/plug-api/lib/yaml_page.ts +++ b/plug-api/lib/yaml_page.ts @@ -1,6 +1,5 @@ -import { findNodeOfType, traverseTree } from "$sb/lib/tree.ts"; -import { markdown, space } from "$sb/silverbullet-syscall/mod.ts"; -import { YAML } from "$sb/plugos-syscall/mod.ts"; +import { findNodeOfType, traverseTree } from "$lib/tree.ts"; +import { markdown, space, YAML } from "$sb/syscalls.ts"; export async function readCodeBlockPage( pageName: string, diff --git a/plug-api/plugos-syscall/mod.ts b/plug-api/plugos-syscall/mod.ts deleted file mode 100644 index 952dc3c8..00000000 --- a/plug-api/plugos-syscall/mod.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * as asset from "./asset.ts"; -export * as events from "./event.ts"; -export * as shell from "./shell.ts"; -export * as YAML from "./yaml.ts"; -export * as mq from "./mq.ts"; -export * from "./syscall.ts"; -export * as datastore from "./datastore.ts"; diff --git a/plug-api/plugos-syscall/syscall.ts b/plug-api/plugos-syscall/syscall.ts deleted file mode 100644 index 18908c4b..00000000 --- a/plug-api/plugos-syscall/syscall.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare global { - function syscall(name: string, ...args: any[]): Promise; -} - -export const syscall = globalThis.syscall; diff --git a/plug-api/silverbullet-syscall/mod.ts b/plug-api/silverbullet-syscall/mod.ts deleted file mode 100644 index 7b87093a..00000000 --- a/plug-api/silverbullet-syscall/mod.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * as editor from "./editor.ts"; -export * as markdown from "./markdown.ts"; -export * as space from "./space.ts"; -export * as system from "./system.ts"; -export * as clientStore from "./clientStore.ts"; -export * as sync from "./sync.ts"; -export * as debug from "./debug.ts"; -export * as language from "./language.ts"; -export * as template from "./template.ts"; -export * as codeWidget from "./code_widget.ts"; diff --git a/plug-api/silverbullet-syscall/syscall.ts b/plug-api/syscall.ts similarity index 89% rename from plug-api/silverbullet-syscall/syscall.ts rename to plug-api/syscall.ts index aa308732..0042d826 100644 --- a/plug-api/silverbullet-syscall/syscall.ts +++ b/plug-api/syscall.ts @@ -13,4 +13,4 @@ if (typeof self === "undefined") { }; } -export const syscall = self.syscall; +export const syscall = globalThis.syscall; diff --git a/plug-api/syscalls.ts b/plug-api/syscalls.ts index 740ff3aa..9081f127 100644 --- a/plug-api/syscalls.ts +++ b/plug-api/syscalls.ts @@ -1,2 +1,18 @@ -export * from "$sb/silverbullet-syscall/mod.ts"; -export * from "$sb/plugos-syscall/mod.ts"; +export * as editor from "./syscalls/editor.ts"; +export * as markdown from "./syscalls/markdown.ts"; +export * as space from "./syscalls/space.ts"; +export * as system from "./syscalls/system.ts"; +export * as clientStore from "./syscalls/clientStore.ts"; +export * as sync from "./syscalls/sync.ts"; +export * as debug from "./syscalls/debug.ts"; +export * as language from "./syscalls/language.ts"; +export * as template from "./syscalls/template.ts"; +export * as codeWidget from "./syscalls/code_widget.ts"; + +export * as asset from "./syscalls/asset.ts"; +export * as events from "./syscalls/event.ts"; +export * as shell from "./syscalls/shell.ts"; +export * as YAML from "./syscalls/yaml.ts"; +export * as mq from "./syscalls/mq.ts"; +export * from "./syscall.ts"; +export * as datastore from "./syscalls/datastore.ts"; diff --git a/plug-api/plugos-syscall/asset.ts b/plug-api/syscalls/asset.ts similarity index 76% rename from plug-api/plugos-syscall/asset.ts rename to plug-api/syscalls/asset.ts index 8e93d7c1..e084b4fe 100644 --- a/plug-api/plugos-syscall/asset.ts +++ b/plug-api/syscalls/asset.ts @@ -1,5 +1,5 @@ -import { base64DecodeDataUrl } from "../../plugos/asset_bundle/base64.ts"; -import { syscall } from "./syscall.ts"; +import { base64DecodeDataUrl } from "$lib/crypto.ts"; +import { syscall } from "../syscall.ts"; export async function readAsset( plugName: string, diff --git a/plug-api/silverbullet-syscall/clientStore.ts b/plug-api/syscalls/clientStore.ts similarity index 92% rename from plug-api/silverbullet-syscall/clientStore.ts rename to plug-api/syscalls/clientStore.ts index b48e4c2d..761ea72f 100644 --- a/plug-api/silverbullet-syscall/clientStore.ts +++ b/plug-api/syscalls/clientStore.ts @@ -1,4 +1,4 @@ -import { syscall } from "./syscall.ts"; +import { syscall } from "../syscall.ts"; /** * Implements a very simple (string) key value store for the client. diff --git a/plug-api/silverbullet-syscall/code_widget.ts b/plug-api/syscalls/code_widget.ts similarity index 76% rename from plug-api/silverbullet-syscall/code_widget.ts rename to plug-api/syscalls/code_widget.ts index 22f672fd..48d041a9 100644 --- a/plug-api/silverbullet-syscall/code_widget.ts +++ b/plug-api/syscalls/code_widget.ts @@ -1,5 +1,5 @@ -import type { CodeWidgetContent } from "$sb/types.ts"; -import { syscall } from "./syscall.ts"; +import type { CodeWidgetContent } from "$type/types.ts"; +import { syscall } from "../syscall.ts"; export function render( lang: string, diff --git a/plug-api/plugos-syscall/datastore.ts b/plug-api/syscalls/datastore.ts similarity index 90% rename from plug-api/plugos-syscall/datastore.ts rename to plug-api/syscalls/datastore.ts index efd94b29..79e76926 100644 --- a/plug-api/plugos-syscall/datastore.ts +++ b/plug-api/syscalls/datastore.ts @@ -1,5 +1,5 @@ -import { syscall } from "$sb/plugos-syscall/syscall.ts"; -import { KV, KvKey, KvQuery } from "$sb/types.ts"; +import { syscall } from "$sb/syscall.ts"; +import { KV, KvKey, KvQuery } from "$type/types.ts"; export function set(key: KvKey, value: any): Promise { return syscall("datastore.set", key, value); diff --git a/plug-api/silverbullet-syscall/debug.ts b/plug-api/syscalls/debug.ts similarity index 83% rename from plug-api/silverbullet-syscall/debug.ts rename to plug-api/syscalls/debug.ts index 2c1db5b6..6eea386f 100644 --- a/plug-api/silverbullet-syscall/debug.ts +++ b/plug-api/syscalls/debug.ts @@ -1,4 +1,4 @@ -import { syscall } from "./syscall.ts"; +import { syscall } from "../syscall.ts"; export function resetClient() { return syscall("debug.resetClient"); diff --git a/plug-api/silverbullet-syscall/editor.ts b/plug-api/syscalls/editor.ts similarity index 97% rename from plug-api/silverbullet-syscall/editor.ts rename to plug-api/syscalls/editor.ts index eb2e081d..966a2c8b 100644 --- a/plug-api/silverbullet-syscall/editor.ts +++ b/plug-api/syscalls/editor.ts @@ -1,7 +1,7 @@ import type { FilterOption } from "../../web/types.ts"; -import { PageRef } from "$sb/lib/page.ts"; -import { UploadFile } from "../types.ts"; -import { syscall } from "./syscall.ts"; +import { UploadFile } from "$type/types.ts"; +import { syscall } from "../syscall.ts"; +import type { PageRef } from "$sb/lib/page_ref.ts"; export function getCurrentPage(): Promise { return syscall("editor.getCurrentPage"); diff --git a/plug-api/plugos-syscall/event.ts b/plug-api/syscalls/event.ts similarity index 93% rename from plug-api/plugos-syscall/event.ts rename to plug-api/syscalls/event.ts index a2a3065e..296ad5e8 100644 --- a/plug-api/plugos-syscall/event.ts +++ b/plug-api/syscalls/event.ts @@ -1,4 +1,4 @@ -import { syscall } from "./syscall.ts"; +import { syscall } from "../syscall.ts"; export function dispatchEvent( eventName: string, diff --git a/plug-api/silverbullet-syscall/language.ts b/plug-api/syscalls/language.ts similarity index 81% rename from plug-api/silverbullet-syscall/language.ts rename to plug-api/syscalls/language.ts index 73963a1d..37bf649e 100644 --- a/plug-api/silverbullet-syscall/language.ts +++ b/plug-api/syscalls/language.ts @@ -1,6 +1,6 @@ -import { syscall } from "$sb/silverbullet-syscall/syscall.ts"; +import { syscall } from "../syscall.ts"; -import type { ParseTree } from "$sb/lib/tree.ts"; +import type { ParseTree } from "$lib/tree.ts"; /** * Parses a piece of code using any of the supported SB languages, see `common/languages.ts` for a list diff --git a/plug-api/silverbullet-syscall/markdown.ts b/plug-api/syscalls/markdown.ts similarity index 51% rename from plug-api/silverbullet-syscall/markdown.ts rename to plug-api/syscalls/markdown.ts index e766dcd0..54ffd9d9 100644 --- a/plug-api/silverbullet-syscall/markdown.ts +++ b/plug-api/syscalls/markdown.ts @@ -1,6 +1,6 @@ -import { syscall } from "$sb/silverbullet-syscall/syscall.ts"; +import { syscall } from "../syscall.ts"; -import type { ParseTree } from "$sb/lib/tree.ts"; +import type { ParseTree } from "$lib/tree.ts"; export function parseMarkdown(text: string): Promise { return syscall("markdown.parseMarkdown", text); diff --git a/plug-api/plugos-syscall/mq.ts b/plug-api/syscalls/mq.ts similarity index 84% rename from plug-api/plugos-syscall/mq.ts rename to plug-api/syscalls/mq.ts index 39d9534d..aeda54af 100644 --- a/plug-api/plugos-syscall/mq.ts +++ b/plug-api/syscalls/mq.ts @@ -1,5 +1,5 @@ -import { syscall } from "$sb/plugos-syscall/syscall.ts"; -import { MQStats } from "$sb/types.ts"; +import { syscall } from "$sb/syscall.ts"; +import type { MQStats } from "$type/types.ts"; export function send(queue: string, body: any) { return syscall("mq.send", queue, body); diff --git a/plug-api/plugos-syscall/shell.ts b/plug-api/syscalls/shell.ts similarity index 79% rename from plug-api/plugos-syscall/shell.ts rename to plug-api/syscalls/shell.ts index 1df8668e..1a56e6dd 100644 --- a/plug-api/plugos-syscall/shell.ts +++ b/plug-api/syscalls/shell.ts @@ -1,4 +1,4 @@ -import { syscall } from "./syscall.ts"; +import { syscall } from "../syscall.ts"; export function run( cmd: string, diff --git a/plug-api/silverbullet-syscall/space.ts b/plug-api/syscalls/space.ts similarity index 95% rename from plug-api/silverbullet-syscall/space.ts rename to plug-api/syscalls/space.ts index 688886f7..025c05a1 100644 --- a/plug-api/silverbullet-syscall/space.ts +++ b/plug-api/syscalls/space.ts @@ -1,5 +1,5 @@ -import { syscall } from "./syscall.ts"; -import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts"; +import { syscall } from "../syscall.ts"; +import { AttachmentMeta, FileMeta, PageMeta } from "$type/types.ts"; export function listPages(unfiltered = false): Promise { return syscall("space.listPages", unfiltered); diff --git a/plug-api/silverbullet-syscall/sync.ts b/plug-api/syscalls/sync.ts similarity index 86% rename from plug-api/silverbullet-syscall/sync.ts rename to plug-api/syscalls/sync.ts index e6f24faf..b5beb381 100644 --- a/plug-api/silverbullet-syscall/sync.ts +++ b/plug-api/syscalls/sync.ts @@ -1,4 +1,4 @@ -import { syscall } from "$sb/silverbullet-syscall/syscall.ts"; +import { syscall } from "../syscall.ts"; export function isSyncing(): Promise { return syscall("sync.isSyncing"); diff --git a/plug-api/silverbullet-syscall/system.ts b/plug-api/syscalls/system.ts similarity index 86% rename from plug-api/silverbullet-syscall/system.ts rename to plug-api/syscalls/system.ts index 6b84b3d1..029f19e6 100644 --- a/plug-api/silverbullet-syscall/system.ts +++ b/plug-api/syscalls/system.ts @@ -1,6 +1,6 @@ -import type { CommandDef } from "../../common/hooks/command.ts"; -import { SyscallMeta } from "$sb/types.ts"; -import { syscall } from "./syscall.ts"; +import type { CommandDef } from "$common/hooks/command.ts"; +import { SyscallMeta } from "$type/types.ts"; +import { syscall } from "../syscall.ts"; export function invokeFunction( name: string, diff --git a/plug-api/silverbullet-syscall/template.ts b/plug-api/syscalls/template.ts similarity index 86% rename from plug-api/silverbullet-syscall/template.ts rename to plug-api/syscalls/template.ts index c6c428f6..540b39e2 100644 --- a/plug-api/silverbullet-syscall/template.ts +++ b/plug-api/syscalls/template.ts @@ -1,4 +1,4 @@ -import { syscall } from "$sb/silverbullet-syscall/syscall.ts"; +import { syscall } from "../syscall.ts"; /** * Renders diff --git a/plug-api/plugos-syscall/yaml.ts b/plug-api/syscalls/yaml.ts similarity index 83% rename from plug-api/plugos-syscall/yaml.ts rename to plug-api/syscalls/yaml.ts index d15f19a9..3fb8fa60 100644 --- a/plug-api/plugos-syscall/yaml.ts +++ b/plug-api/syscalls/yaml.ts @@ -1,4 +1,4 @@ -import { syscall } from "./syscall.ts"; +import { syscall } from "../syscall.ts"; export function parse( text: string, diff --git a/plugos/asset_bundle/base64.test.ts b/plugos/asset_bundle/base64.test.ts deleted file mode 100644 index 9d82afc4..00000000 --- a/plugos/asset_bundle/base64.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { assertEquals } from "../../test_deps.ts"; -import { - base64Decode, - base64DecodeDataUrl, - base64EncodedDataUrl, -} from "./base64.ts"; -import { base64Encode } from "./base64.ts"; - -Deno.test("Base 64 encoding", () => { - const buf = new Uint8Array(3); - buf[0] = 1; - buf[1] = 2; - buf[2] = 3; - - assertEquals(buf, base64Decode(base64Encode(buf))); - - assertEquals( - buf, - base64DecodeDataUrl(base64EncodedDataUrl("application/octet-stream", buf)), - ); -}); diff --git a/plugos/asset_bundle/base64.ts b/plugos/asset_bundle/base64.ts deleted file mode 100644 index 84830e12..00000000 --- a/plugos/asset_bundle/base64.ts +++ /dev/null @@ -1,33 +0,0 @@ -export function base64Decode(s: string): Uint8Array { - const binString = atob(s); - const len = binString.length; - const bytes = new Uint8Array(len); - for (let i = 0; i < len; i++) { - bytes[i] = binString.charCodeAt(i); - } - return bytes; -} - -export function base64Encode(buffer: Uint8Array | string): string { - if (typeof buffer === "string") { - buffer = new TextEncoder().encode(buffer); - } - let binary = ""; - const len = buffer.byteLength; - for (let i = 0; i < len; i++) { - binary += String.fromCharCode(buffer[i]); - } - return btoa(binary); -} - -export function base64EncodedDataUrl( - mimeType: string, - buffer: Uint8Array, -): string { - return `data:${mimeType};base64,${base64Encode(buffer)}`; -} - -export function base64DecodeDataUrl(dataUrl: string): Uint8Array { - const b64Encoded = dataUrl.split(",", 2)[1]; - return base64Decode(b64Encoded); -} diff --git a/plugos/hooks/endpoint.test.ts b/plugos/hooks/endpoint.test.ts deleted file mode 100644 index a493a2b4..00000000 --- a/plugos/hooks/endpoint.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { createSandbox } from "../sandboxes/deno_worker_sandbox.ts"; -import { EndpointHook, EndpointHookT } from "./endpoint.ts"; -import { System } from "../system.ts"; - -import { assertEquals } from "../../test_deps.ts"; -import { compileManifest } from "../compile.ts"; -import { esbuild } from "../deps.ts"; -import { Hono } from "../../server/deps.ts"; - -Deno.test("Run a plugos endpoint server", { - sanitizeResources: false, - sanitizeOps: false, -}, async () => { - const tempDir = await Deno.makeTempDir(); - const system = new System("server"); - - const workerPath = await compileManifest( - new URL("../test.plug.yaml", import.meta.url).pathname, - tempDir, - ); - - await system.load("test", createSandbox(new URL(`file://${workerPath}`))); - - const app = new Hono(); - const port = 3123; - - const endpointHook = new EndpointHook("/_/"); - - app.all("*", (context, next) => { - return endpointHook.handleRequest(system, context, next); - }); - - const controller = new AbortController(); - Deno.serve({ port: port, signal: controller.signal }, app.fetch); - - const res = await fetch(`http://localhost:${port}/_/test/?name=Pete`); - assertEquals(res.status, 200); - assertEquals(await res.json(), [1, 2, 3]); - console.log("Aborting"); - controller.abort(); - await system.unloadAll(); - - await Deno.remove(tempDir, { recursive: true }); - esbuild.stop(); -}); diff --git a/plugs/editor/command.ts b/plugs/editor/command.ts index 846b9d77..f5678474 100644 --- a/plugs/editor/command.ts +++ b/plugs/editor/command.ts @@ -1,5 +1,5 @@ import { system } from "$sb/syscalls.ts"; -import { CompleteEvent } from "$sb/app_event.ts"; +import { CompleteEvent } from "$type/types.ts"; export async function commandComplete(completeEvent: CompleteEvent) { const match = /\{\[([^\]]*)$/.exec(completeEvent.linePrefix); diff --git a/plugs/editor/complete.ts b/plugs/editor/complete.ts index 76fbc563..fbbc1881 100644 --- a/plugs/editor/complete.ts +++ b/plugs/editor/complete.ts @@ -1,5 +1,4 @@ -import { CompleteEvent } from "$sb/app_event.ts"; -import { FileMeta, PageMeta } from "$sb/types.ts"; +import { CompleteEvent, FileMeta, PageMeta } from "$type/types.ts"; import { cacheFileListing } from "../federation/federation.ts"; import { queryObjects } from "../index/plug_api.ts"; diff --git a/plugs/editor/embed.ts b/plugs/editor/embed.ts index 9021c1cf..494c0581 100644 --- a/plugs/editor/embed.ts +++ b/plugs/editor/embed.ts @@ -1,5 +1,5 @@ import { YAML } from "$sb/syscalls.ts"; -import type { WidgetContent } from "$sb/app_event.ts"; +import type { WidgetContent } from "$type/types.ts"; type EmbedConfig = { url: string; diff --git a/plugs/editor/link.ts b/plugs/editor/link.ts index e1f11dec..2f18860a 100644 --- a/plugs/editor/link.ts +++ b/plugs/editor/link.ts @@ -1,4 +1,4 @@ -import { nodeAtPos } from "$sb/lib/tree.ts"; +import { nodeAtPos } from "$lib/tree.ts"; import { editor, events, markdown } from "$sb/syscalls.ts"; type UnfurlOption = { diff --git a/plugs/editor/navigate.ts b/plugs/editor/navigate.ts index 4aa7d877..841ab8c2 100644 --- a/plugs/editor/navigate.ts +++ b/plugs/editor/navigate.ts @@ -1,4 +1,4 @@ -import type { ClickEvent } from "$sb/app_event.ts"; +import type { ClickEvent } from "$type/types.ts"; import { editor, markdown, system } from "$sb/syscalls.ts"; import { addParentPointers, @@ -6,9 +6,9 @@ import { findParentMatching, nodeAtPos, ParseTree, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; import { resolveAttachmentPath, resolvePath } from "$sb/lib/resolve.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; import { tagPrefix } from "../index/constants.ts"; async function actionClickOrActionEnter( diff --git a/plugs/editor/upload.ts b/plugs/editor/upload.ts index 04d0fd80..3525f6d6 100644 --- a/plugs/editor/upload.ts +++ b/plugs/editor/upload.ts @@ -1,5 +1,5 @@ -import { editor, space } from "$sb/silverbullet-syscall/mod.ts"; -import { UploadFile } from "$sb/types.ts"; +import { editor, space } from "$sb/syscalls.ts"; +import { UploadFile } from "$type/types.ts"; const maximumAttachmentSize = 1024 * 1024 * 10; // 10MB diff --git a/plugs/emoji/emoji.ts b/plugs/emoji/emoji.ts index 1f90ea3a..b5506e1c 100644 --- a/plugs/emoji/emoji.ts +++ b/plugs/emoji/emoji.ts @@ -1,7 +1,7 @@ import emojiBlob from "./emoji.json" assert { type: "json" }; -import type { CompleteEvent } from "$sb/app_event.ts"; +import type { CompleteEvent } from "$type/types.ts"; import { readSetting } from "$sb/lib/settings_page.ts"; -import { editor } from "$sb/silverbullet-syscall/mod.ts"; +import { editor } from "$sb/syscalls.ts"; import type { EmojiConfig } from "../../web/types.ts"; let emojiConfig: EmojiConfig = { aliases: [] }; diff --git a/plugs/federation/federation.ts b/plugs/federation/federation.ts index 65637ea6..a8a2387e 100644 --- a/plugs/federation/federation.ts +++ b/plugs/federation/federation.ts @@ -1,8 +1,8 @@ -import "$sb/lib/fetch.ts"; +import "$sb/lib/native_fetch.ts"; import { federatedPathToUrl } from "$sb/lib/resolve.ts"; import { readFederationConfigs } from "./config.ts"; import { datastore } from "$sb/syscalls.ts"; -import type { FileMeta } from "$sb/types.ts"; +import type { FileMeta } from "../../type/types.ts"; async function responseToFileMeta( r: Response, diff --git a/plugs/index/anchor.ts b/plugs/index/anchor.ts index e18b136d..9d5b1ed8 100644 --- a/plugs/index/anchor.ts +++ b/plugs/index/anchor.ts @@ -1,8 +1,8 @@ -import { collectNodesOfType } from "$sb/lib/tree.ts"; -import type { CompleteEvent, IndexTreeEvent } from "$sb/app_event.ts"; -import { ObjectValue, QueryExpression } from "$sb/types.ts"; +import { collectNodesOfType } from "$lib/tree.ts"; +import type { CompleteEvent, IndexTreeEvent } from "$type/types.ts"; +import { ObjectValue, QueryExpression } from "$type/types.ts"; import { indexObjects, queryObjects } from "./api.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; type AnchorObject = ObjectValue<{ name: string; diff --git a/plugs/index/api.ts b/plugs/index/api.ts index 2f359d2f..dc0eb805 100644 --- a/plugs/index/api.ts +++ b/plugs/index/api.ts @@ -1,9 +1,15 @@ import { datastore } from "$sb/syscalls.ts"; -import { KV, KvKey, KvQuery, ObjectQuery, ObjectValue } from "$sb/types.ts"; -import { QueryProviderEvent } from "$sb/app_event.ts"; +import { + KV, + KvKey, + KvQuery, + ObjectQuery, + ObjectValue, +} from "../../type/types.ts"; +import { QueryProviderEvent } from "$type/types.ts"; import { builtins } from "./builtins.ts"; import { determineType } from "./attributes.ts"; -import { ttlCache } from "$sb/lib/memory_cache.ts"; +import { ttlCache } from "$lib/memory_cache.ts"; const indexKey = "idx"; const pageKey = "ridx"; diff --git a/plugs/index/attributes.ts b/plugs/index/attributes.ts index c243a2a1..bcc683a3 100644 --- a/plugs/index/attributes.ts +++ b/plugs/index/attributes.ts @@ -1,8 +1,8 @@ -import type { CompleteEvent } from "$sb/app_event.ts"; +import type { CompleteEvent } from "$type/types.ts"; import { events } from "$sb/syscalls.ts"; import { queryObjects } from "./api.ts"; -import { ObjectValue, QueryExpression } from "$sb/types.ts"; -import { determineTags } from "../../plug-api/lib/cheap_yaml.ts"; +import { ObjectValue, QueryExpression } from "../../type/types.ts"; +import { determineTags } from "$lib/cheap_yaml.ts"; export type AttributeObject = ObjectValue<{ name: string; diff --git a/plugs/index/builtins.ts b/plugs/index/builtins.ts index 31ac8626..bb12bcff 100644 --- a/plugs/index/builtins.ts +++ b/plugs/index/builtins.ts @@ -1,9 +1,9 @@ -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "../../type/types.ts"; import { system } from "$sb/syscalls.ts"; import { indexObjects } from "./api.ts"; -import { QueryProviderEvent } from "$sb/app_event.ts"; +import { QueryProviderEvent } from "$type/types.ts"; import { applyQuery } from "$sb/lib/query.ts"; -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; +import { builtinFunctions } from "$lib/builtin_query_functions.ts"; export const builtinPseudoPage = ":builtin:"; diff --git a/plugs/index/command.ts b/plugs/index/command.ts index 30a8e829..d7c9f576 100644 --- a/plugs/index/command.ts +++ b/plugs/index/command.ts @@ -1,8 +1,8 @@ import { editor, events, markdown, mq, space, system } from "$sb/syscalls.ts"; -import { sleep } from "$sb/lib/async.ts"; -import { IndexEvent } from "$sb/app_event.ts"; -import { MQMessage } from "$sb/types.ts"; -import { isTemplate } from "$sb/lib/cheap_yaml.ts"; +import { IndexEvent } from "$type/types.ts"; +import { MQMessage } from "$type/types.ts"; +import { isTemplate } from "$lib/cheap_yaml.ts"; +import { sleep } from "$lib/async.ts"; export async function reindexCommand() { await editor.flashNotification("Performing full page reindex..."); diff --git a/plugs/index/data.ts b/plugs/index/data.ts index 56d397e2..41d8f1e1 100644 --- a/plugs/index/data.ts +++ b/plugs/index/data.ts @@ -1,7 +1,7 @@ -import type { IndexTreeEvent } from "$sb/app_event.ts"; +import type { IndexTreeEvent } from "$type/types.ts"; import { YAML } from "$sb/syscalls.ts"; -import { collectNodesOfType, findNodeOfType } from "$sb/lib/tree.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { collectNodesOfType, findNodeOfType } from "$lib/tree.ts"; +import { ObjectValue } from "../../type/types.ts"; import { indexObjects } from "./api.ts"; import { TagObject } from "./tags.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; diff --git a/plugs/index/header.ts b/plugs/index/header.ts index c8bef992..20d830aa 100644 --- a/plugs/index/header.ts +++ b/plugs/index/header.ts @@ -1,8 +1,8 @@ -import { collectNodesMatching } from "$sb/lib/tree.ts"; -import type { CompleteEvent, IndexTreeEvent } from "$sb/app_event.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { collectNodesMatching } from "$lib/tree.ts"; +import type { CompleteEvent, IndexTreeEvent } from "$type/types.ts"; +import { ObjectValue } from "$type/types.ts"; import { indexObjects, queryObjects } from "./api.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; type HeaderObject = ObjectValue<{ name: string; diff --git a/plugs/index/item.ts b/plugs/index/item.ts index 8abc05fc..46f2d844 100644 --- a/plugs/index/item.ts +++ b/plugs/index/item.ts @@ -1,9 +1,9 @@ -import type { IndexTreeEvent } from "$sb/app_event.ts"; +import type { IndexTreeEvent } from "$type/types.ts"; -import { collectNodesOfType, ParseTree, renderToText } from "$sb/lib/tree.ts"; +import { collectNodesOfType, ParseTree, renderToText } from "$lib/tree.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; import { rewritePageRefs } from "$sb/lib/resolve.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "$type/types.ts"; import { indexObjects } from "./api.ts"; import { updateITags } from "$sb/lib/tags.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; diff --git a/plugs/index/lint.ts b/plugs/index/lint.ts index c5fccf80..7d80210c 100644 --- a/plugs/index/lint.ts +++ b/plugs/index/lint.ts @@ -1,11 +1,7 @@ import { YAML } from "$sb/syscalls.ts"; -import { LintDiagnostic, QueryExpression } from "$sb/types.ts"; -import { - findNodeOfType, - renderToText, - traverseTreeAsync, -} from "$sb/lib/tree.ts"; -import { LintEvent } from "$sb/app_event.ts"; +import { LintDiagnostic, QueryExpression } from "../../type/types.ts"; +import { findNodeOfType, renderToText, traverseTreeAsync } from "$lib/tree.ts"; +import { LintEvent } from "$type/types.ts"; import { queryObjects } from "./api.ts"; import { AttributeObject } from "./attributes.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; diff --git a/plugs/index/page.ts b/plugs/index/page.ts index 80ca010f..2145af1c 100644 --- a/plugs/index/page.ts +++ b/plugs/index/page.ts @@ -1,15 +1,11 @@ -import type { IndexTreeEvent } from "$sb/app_event.ts"; +import type { IndexTreeEvent } from "$type/types.ts"; import { editor, markdown, space, YAML } from "$sb/syscalls.ts"; -import type { LintDiagnostic, PageMeta } from "$sb/types.ts"; +import type { LintDiagnostic, PageMeta } from "../../type/types.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; import { indexObjects } from "./api.ts"; -import { - findNodeOfType, - renderToText, - traverseTreeAsync, -} from "$sb/lib/tree.ts"; +import { findNodeOfType, renderToText, traverseTreeAsync } from "$lib/tree.ts"; import { updateITags } from "$sb/lib/tags.ts"; export async function indexPage({ name, tree }: IndexTreeEvent) { diff --git a/plugs/index/page_links.ts b/plugs/index/page_links.ts index b1fd932b..b8243231 100644 --- a/plugs/index/page_links.ts +++ b/plugs/index/page_links.ts @@ -1,11 +1,11 @@ -import { findNodeOfType, renderToText, traverseTree } from "$sb/lib/tree.ts"; -import { IndexTreeEvent } from "$sb/app_event.ts"; +import { findNodeOfType, renderToText, traverseTree } from "$lib/tree.ts"; +import { IndexTreeEvent } from "$type/types.ts"; import { resolvePath } from "$sb/lib/resolve.ts"; import { indexObjects, queryObjects } from "./api.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "$type/types.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { updateITags } from "$sb/lib/tags.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; const pageRefRegex = /\[\[([^\]]+)\]\]/g; diff --git a/plugs/index/paragraph.ts b/plugs/index/paragraph.ts index 35fa4ad5..be774c8c 100644 --- a/plugs/index/paragraph.ts +++ b/plugs/index/paragraph.ts @@ -1,15 +1,13 @@ -import type { IndexTreeEvent } from "$sb/app_event.ts"; +import type { IndexTreeEvent } from "$type/types.ts"; import { indexObjects } from "./api.ts"; import { - addParentPointers, collectNodesOfType, findParentMatching, renderToText, traverseTreeAsync, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; -import { ObjectValue } from "$sb/types.ts"; -import a from "https://esm.sh/v135/node_process.js"; +import { ObjectValue } from "$type/types.ts"; import { updateITags } from "$sb/lib/tags.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; diff --git a/plugs/index/plug_api.ts b/plugs/index/plug_api.ts index 86a43bc4..a8cdc7dd 100644 --- a/plugs/index/plug_api.ts +++ b/plugs/index/plug_api.ts @@ -1,22 +1,22 @@ -import { KV, KvQuery, ObjectQuery, ObjectValue } from "$sb/types.ts"; -import { invokeFunction } from "$sb/silverbullet-syscall/system.ts"; -import { ttlCache } from "$sb/lib/memory_cache.ts"; +import { KV, KvQuery, ObjectQuery, ObjectValue } from "$type/types.ts"; +import { ttlCache } from "$lib/memory_cache.ts"; +import { system } from "$sb/syscalls.ts"; export function indexObjects( page: string, objects: ObjectValue[], ): Promise { - return invokeFunction("index.indexObjects", page, objects); + return system.invokeFunction("index.indexObjects", page, objects); } export function batchSet(page: string, kvs: KV[]): Promise { - return invokeFunction("index.batchSet", page, kvs); + return system.invokeFunction("index.batchSet", page, kvs); } export function query( query: KvQuery, ): Promise { - return invokeFunction("index.query", query); + return system.invokeFunction("index.query", query); } export function queryObjects( @@ -26,7 +26,7 @@ export function queryObjects( ): Promise[]> { return ttlCache( query, - () => invokeFunction("index.queryObjects", tag, query), + () => system.invokeFunction("index.queryObjects", tag, query), ttlSecs, // no-op when undefined ); } @@ -36,5 +36,5 @@ export function getObjectByRef( tag: string, ref: string, ): Promise { - return invokeFunction("index.getObjectByRef", page, tag, ref); + return system.invokeFunction("index.getObjectByRef", page, tag, ref); } diff --git a/plugs/index/refactor.ts b/plugs/index/refactor.ts index 8e1fda32..bb75b15f 100644 --- a/plugs/index/refactor.ts +++ b/plugs/index/refactor.ts @@ -1,5 +1,5 @@ import { editor, space } from "$sb/syscalls.ts"; -import { validatePageName } from "$sb/lib/page.ts"; +import { validatePageName } from "../../plug-api/lib/page_ref.ts"; import { getBackLinks } from "./page_links.ts"; export async function renamePageCommand(cmdDef: any) { diff --git a/plugs/index/script.ts b/plugs/index/script.ts index 824d2ea6..82f9ee7a 100644 --- a/plugs/index/script.ts +++ b/plugs/index/script.ts @@ -1,6 +1,6 @@ -import { IndexTreeEvent } from "$sb/app_event.ts"; -import { collectNodesOfType, findNodeOfType } from "$sb/lib/tree.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { IndexTreeEvent } from "$type/types.ts"; +import { collectNodesOfType, findNodeOfType } from "$lib/tree.ts"; +import { ObjectValue } from "$type/types.ts"; import { indexObjects } from "./api.ts"; export type ScriptObject = ObjectValue<{ diff --git a/plugs/index/snippet.test.ts b/plugs/index/snippet.test.ts index 8cf1df1f..4cc8a19a 100644 --- a/plugs/index/snippet.test.ts +++ b/plugs/index/snippet.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../test_deps.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { extractSnippet } from "./page_links.ts"; Deno.test("Snippet extraction", () => { diff --git a/plugs/index/tag_page.ts b/plugs/index/tag_page.ts index a4e9ab27..49e08b8a 100644 --- a/plugs/index/tag_page.ts +++ b/plugs/index/tag_page.ts @@ -1,6 +1,6 @@ -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "$type/types.ts"; import { markdown, system } from "$sb/syscalls.ts"; -import { renderToText } from "$sb/lib/tree.ts"; +import { renderToText } from "$lib/tree.ts"; import { tagPrefix } from "./constants.ts"; export async function readFileTag( diff --git a/plugs/index/tags.ts b/plugs/index/tags.ts index 6cd19d0a..08ae1dd3 100644 --- a/plugs/index/tags.ts +++ b/plugs/index/tags.ts @@ -1,12 +1,12 @@ -import type { CompleteEvent, IndexTreeEvent } from "$sb/app_event.ts"; +import type { CompleteEvent, IndexTreeEvent } from "$type/types.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { indexObjects, queryObjects } from "./api.ts"; import { addParentPointers, collectNodesOfType, findParentMatching, -} from "$sb/lib/tree.ts"; -import type { ObjectValue } from "$sb/types.ts"; +} from "$lib/tree.ts"; +import type { ObjectValue } from "../../type/types.ts"; export type TagObject = ObjectValue<{ name: string; diff --git a/plugs/index/toc.ts b/plugs/index/toc.ts index 1e5275f6..30315bb6 100644 --- a/plugs/index/toc.ts +++ b/plugs/index/toc.ts @@ -1,6 +1,6 @@ import { editor, markdown, YAML } from "$sb/syscalls.ts"; -import { CodeWidgetContent } from "$sb/types.ts"; -import { renderToText, traverseTree } from "$sb/lib/tree.ts"; +import { CodeWidgetContent } from "../../type/types.ts"; +import { renderToText, traverseTree } from "$lib/tree.ts"; type Header = { name: string; diff --git a/plugs/index/widget.ts b/plugs/index/widget.ts index 72f5b487..88e33944 100644 --- a/plugs/index/widget.ts +++ b/plugs/index/widget.ts @@ -1,12 +1,6 @@ -import { - codeWidget, - editor, - language, - markdown, - space, -} from "$sb/silverbullet-syscall/mod.ts"; -import { parseTreeToAST, renderToText } from "$sb/lib/tree.ts"; -import { CodeWidgetContent } from "$sb/types.ts"; +import { codeWidget, editor, language, markdown, space } from "$sb/syscalls.ts"; +import { parseTreeToAST, renderToText } from "$lib/tree.ts"; +import { CodeWidgetContent } from "$type/types.ts"; import { loadPageObject } from "../template/page.ts"; import { queryObjects } from "./api.ts"; import { TemplateObject, WidgetConfig } from "../template/types.ts"; diff --git a/plugs/markdown/api.ts b/plugs/markdown/api.ts index 3e351d42..97daf25d 100644 --- a/plugs/markdown/api.ts +++ b/plugs/markdown/api.ts @@ -3,9 +3,9 @@ import { ParseTree, renderToText, replaceNodesMatchingAsync, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; import { codeWidget } from "$sb/syscalls.ts"; -import { parseMarkdown } from "$sb/silverbullet-syscall/markdown.ts"; +import { parseMarkdown } from "../../plug-api/syscalls/markdown.ts"; import { MarkdownRenderOptions, renderMarkdownToHtml, diff --git a/plugs/markdown/markdown_render.test.ts b/plugs/markdown/markdown_render.test.ts index b9418d74..db0f8f1a 100644 --- a/plugs/markdown/markdown_render.test.ts +++ b/plugs/markdown/markdown_render.test.ts @@ -1,9 +1,9 @@ -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { System } from "../../plugos/system.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { System } from "../../lib/plugos/system.ts"; -import { createSandbox } from "../../plugos/sandboxes/deno_worker_sandbox.ts"; +import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts"; import { renderMarkdownToHtml } from "./markdown_render.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; Deno.test("Markdown render", async () => { const system = new System("server"); diff --git a/plugs/markdown/markdown_render.ts b/plugs/markdown/markdown_render.ts index 1b247282..f630941e 100644 --- a/plugs/markdown/markdown_render.ts +++ b/plugs/markdown/markdown_render.ts @@ -6,10 +6,9 @@ import { removeParentPointers, renderToText, traverseTree, -} from "$sb/lib/tree.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +} from "$lib/tree.ts"; +import { encodePageRef, parsePageRef } from "$sb/lib/page_ref.ts"; import { Fragment, renderHtml, Tag } from "./html_render.ts"; -import { encodePageRef } from "$sb/lib/page.ts"; export type MarkdownRenderOptions = { failOnUnknown?: true; diff --git a/plugs/markdown/util.ts b/plugs/markdown/util.ts index 38e94500..88f1cc2d 100644 --- a/plugs/markdown/util.ts +++ b/plugs/markdown/util.ts @@ -2,7 +2,7 @@ import { findNodeOfType, renderToText, replaceNodesMatching, -} from "$sb/lib/tree.ts"; +} from "$lib/tree.ts"; import { markdown } from "$sb/syscalls.ts"; export function encodePageUrl(name: string): string { diff --git a/plugs/plug-manager/plugmanager.ts b/plugs/plug-manager/plugmanager.ts index 5e88c8ab..3cde16df 100644 --- a/plugs/plug-manager/plugmanager.ts +++ b/plugs/plug-manager/plugmanager.ts @@ -1,6 +1,7 @@ import { editor, events, space, system } from "$sb/syscalls.ts"; import { readYamlPage } from "$sb/lib/yaml_page.ts"; import { builtinPlugNames } from "../builtin_plugs.ts"; +import { plugPrefix } from "$common/spaces/constants.ts"; const plugsPrelude = "This file lists all plugs that SilverBullet will load. Run the {[Plugs: Update]} command to update and reload this list of plugs.\n\n"; @@ -61,7 +62,7 @@ export async function updatePlugsCommand() { allCustomPlugNames.push(plugName); // console.log("Writing", `_plug/${plugName}.plug.js`, workerCode); await space.writeAttachment( - `_plug/${plugName}.plug.js`, + `${plugPrefix}${plugName}.plug.js`, new TextEncoder().encode(workerCode), ); } @@ -70,7 +71,7 @@ export async function updatePlugsCommand() { // And delete extra ones for (const { name: existingPlug } of await space.listPlugs()) { const plugName = existingPlug.substring( - "_plug/".length, + plugPrefix.length, existingPlug.length - ".plug.js".length, ); if (!allPlugNames.includes(plugName)) { diff --git a/plugs/query/api.ts b/plugs/query/api.ts index ed098207..34e52de5 100644 --- a/plugs/query/api.ts +++ b/plugs/query/api.ts @@ -1,7 +1,7 @@ import { parseQuery } from "$sb/lib/parse-query.ts"; -import { Query } from "$sb/types.ts"; +import { Query } from "../../type/types.ts"; import { events } from "$sb/syscalls.ts"; -import { QueryProviderEvent } from "$sb/app_event.ts"; +import { QueryProviderEvent } from "$type/types.ts"; import { resolvePath } from "$sb/lib/resolve.ts"; import { renderQueryTemplate } from "../template/util.ts"; diff --git a/plugs/query/complete.ts b/plugs/query/complete.ts index 642b84df..75dfcc91 100644 --- a/plugs/query/complete.ts +++ b/plugs/query/complete.ts @@ -1,4 +1,4 @@ -import { CompleteEvent } from "$sb/app_event.ts"; +import { CompleteEvent } from "$type/types.ts"; import { events, language } from "$sb/syscalls.ts"; import { AttributeCompleteEvent, diff --git a/plugs/query/lint.ts b/plugs/query/lint.ts index 3803aa6a..11f23cbe 100644 --- a/plugs/query/lint.ts +++ b/plugs/query/lint.ts @@ -1,9 +1,9 @@ -import { LintEvent } from "$sb/app_event.ts"; +import { LintEvent } from "$type/types.ts"; import { parseQuery } from "$sb/lib/parse-query.ts"; import { cleanPageRef, resolvePath } from "$sb/lib/resolve.ts"; -import { findNodeOfType, traverseTreeAsync } from "$sb/lib/tree.ts"; +import { findNodeOfType, traverseTreeAsync } from "$lib/tree.ts"; import { events, space } from "$sb/syscalls.ts"; -import { LintDiagnostic } from "$sb/types.ts"; +import { LintDiagnostic } from "$type/types.ts"; import { loadPageObject, replaceTemplateVars } from "../template/page.ts"; export async function lintQuery( diff --git a/plugs/query/widget.ts b/plugs/query/widget.ts index 3caf9863..8bf2a7a5 100644 --- a/plugs/query/widget.ts +++ b/plugs/query/widget.ts @@ -2,7 +2,7 @@ import { codeWidget, editor, events } from "$sb/syscalls.ts"; import { parseQuery } from "$sb/lib/parse-query.ts"; import { loadPageObject, replaceTemplateVars } from "../template/page.ts"; import { resolvePath } from "$sb/lib/resolve.ts"; -import { CodeWidgetContent } from "$sb/types.ts"; +import { CodeWidgetContent } from "../../type/types.ts"; import { jsonToMDTable, renderQueryTemplate } from "../template/util.ts"; import { renderQuery } from "./api.ts"; diff --git a/plugs/search/search.ts b/plugs/search/search.ts index e207d487..a2912162 100644 --- a/plugs/search/search.ts +++ b/plugs/search/search.ts @@ -1,11 +1,11 @@ -import { IndexTreeEvent, QueryProviderEvent } from "$sb/app_event.ts"; -import { renderToText } from "$sb/lib/tree.ts"; +import { IndexTreeEvent, QueryProviderEvent } from "$type/types.ts"; +import { renderToText } from "$lib/tree.ts"; import { applyQuery, liftAttributeFilter } from "$sb/lib/query.ts"; import { editor } from "$sb/syscalls.ts"; -import { FileMeta } from "$sb/types.ts"; -import { PromiseQueue } from "$sb/lib/async.ts"; +import { FileMeta } from "$type/types.ts"; import { ftsIndexPage, ftsSearch } from "./engine.ts"; import { evalQueryExpression } from "$sb/lib/query_expression.ts"; +import { PromiseQueue } from "$lib/async.ts"; const searchPrefix = "🔍 "; diff --git a/plugs/share/publish.ts b/plugs/share/publish.ts index 12d5bed7..6f91944f 100644 --- a/plugs/share/publish.ts +++ b/plugs/share/publish.ts @@ -1,6 +1,6 @@ import { editor, events, markdown } from "$sb/syscalls.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; -import { PublishEvent } from "$sb/app_event.ts"; +import { PublishEvent } from "$type/types.ts"; export async function publishCommand() { await editor.save(); diff --git a/plugs/tasks/complete.ts b/plugs/tasks/complete.ts index 08c60765..f496a4c7 100644 --- a/plugs/tasks/complete.ts +++ b/plugs/tasks/complete.ts @@ -1,4 +1,4 @@ -import { CompleteEvent } from "$sb/app_event.ts"; +import { CompleteEvent } from "$type/types.ts"; import { queryObjects } from "../index/plug_api.ts"; import { TaskStateObject } from "./task.ts"; diff --git a/plugs/tasks/task.ts b/plugs/tasks/task.ts index 3f8b7086..23b4c44f 100644 --- a/plugs/tasks/task.ts +++ b/plugs/tasks/task.ts @@ -1,4 +1,4 @@ -import type { ClickEvent, IndexTreeEvent } from "$sb/app_event.ts"; +import type { ClickEvent, IndexTreeEvent } from "$type/types.ts"; import { editor, markdown, space, sync } from "$sb/syscalls.ts"; @@ -13,15 +13,15 @@ import { renderToText, replaceNodesMatching, traverseTreeAsync, -} from "$sb/lib/tree.ts"; -import { niceDate } from "$sb/lib/dates.ts"; +} from "$lib/tree.ts"; +import { niceDate } from "$lib/dates.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; import { rewritePageRefs } from "$sb/lib/resolve.ts"; -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "$type/types.ts"; import { indexObjects, queryObjects } from "../index/plug_api.ts"; import { updateITags } from "$sb/lib/tags.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; export type TaskObject = ObjectValue< { diff --git a/plugs/template/api.ts b/plugs/template/api.ts index f82311a8..a03f730e 100644 --- a/plugs/template/api.ts +++ b/plugs/template/api.ts @@ -1,7 +1,7 @@ import { markdown, template, YAML } from "$sb/syscalls.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { TemplateObject } from "./types.ts"; -import { renderToText } from "$sb/lib/tree.ts"; +import { renderToText } from "$lib/tree.ts"; /** * Strips the template from its frontmatter and renders it. diff --git a/plugs/template/index.ts b/plugs/template/index.ts index 9881a398..8ddf163e 100644 --- a/plugs/template/index.ts +++ b/plugs/template/index.ts @@ -1,4 +1,4 @@ -import type { IndexTreeEvent } from "$sb/app_event.ts"; +import type { IndexTreeEvent } from "$type/types.ts"; import { system } from "$sb/syscalls.ts"; export async function indexTemplate({ name, tree }: IndexTreeEvent) { diff --git a/plugs/template/lint.ts b/plugs/template/lint.ts index 3ea85203..796af743 100644 --- a/plugs/template/lint.ts +++ b/plugs/template/lint.ts @@ -1,10 +1,5 @@ -import { LintEvent } from "$sb/app_event.ts"; -import { LintDiagnostic } from "$sb/types.ts"; -import { - findNodeOfType, - renderToText, - traverseTreeAsync, -} from "$sb/lib/tree.ts"; +import type { LintDiagnostic, LintEvent } from "$type/types.ts"; +import { findNodeOfType, renderToText, traverseTreeAsync } from "$lib/tree.ts"; import { FrontmatterConfig } from "./types.ts"; import { extractFrontmatter } from "$sb/lib/frontmatter.ts"; import { template, YAML } from "$sb/syscalls.ts"; diff --git a/plugs/template/page.ts b/plugs/template/page.ts index 471ce690..9f863ceb 100644 --- a/plugs/template/page.ts +++ b/plugs/template/page.ts @@ -1,5 +1,5 @@ import { editor, space, template } from "$sb/syscalls.ts"; -import { PageMeta } from "$sb/types.ts"; +import { PageMeta } from "../../type/types.ts"; import { getObjectByRef, queryObjects } from "../index/plug_api.ts"; import { FrontmatterConfig, TemplateObject } from "./types.ts"; import { renderTemplate } from "./api.ts"; diff --git a/plugs/template/snippet.ts b/plugs/template/snippet.ts index 603d23ed..e74008bd 100644 --- a/plugs/template/snippet.ts +++ b/plugs/template/snippet.ts @@ -1,4 +1,4 @@ -import { CompleteEvent, SlashCompletion } from "$sb/app_event.ts"; +import { CompleteEvent, SlashCompletion } from "$type/types.ts"; import { editor, markdown, space } from "$sb/syscalls.ts"; import type { AttributeCompletion } from "../index/attributes.ts"; import { queryObjects } from "../index/plug_api.ts"; diff --git a/plugs/template/types.ts b/plugs/template/types.ts index 45b0925c..94aa6c0a 100644 --- a/plugs/template/types.ts +++ b/plugs/template/types.ts @@ -1,4 +1,4 @@ -import { ObjectValue } from "$sb/types.ts"; +import { ObjectValue } from "../../type/types.ts"; import { z, ZodEffects } from "zod"; export const CommandConfig = z.object({ diff --git a/plugs/template/util.ts b/plugs/template/util.ts index 9a26d6bf..4d1dee2b 100644 --- a/plugs/template/util.ts +++ b/plugs/template/util.ts @@ -1,4 +1,4 @@ -import { PageMeta } from "$sb/types.ts"; +import { PageMeta } from "../../type/types.ts"; import { space, template } from "$sb/syscalls.ts"; import { cleanTemplate } from "./plug_api.ts"; diff --git a/plugs/template/var.ts b/plugs/template/var.ts index 18103e23..e0590604 100644 --- a/plugs/template/var.ts +++ b/plugs/template/var.ts @@ -1,4 +1,4 @@ -import { CompleteEvent } from "$sb/app_event.ts"; +import { CompleteEvent } from "$type/types.ts"; import { datastore, events } from "$sb/syscalls.ts"; import { diff --git a/plugs/template/widget.ts b/plugs/template/widget.ts index cb200578..e466e369 100644 --- a/plugs/template/widget.ts +++ b/plugs/template/widget.ts @@ -1,8 +1,8 @@ import { markdown, space, YAML } from "$sb/syscalls.ts"; import { loadPageObject, replaceTemplateVars } from "./page.ts"; -import { CodeWidgetContent, PageMeta } from "$sb/types.ts"; +import { CodeWidgetContent, PageMeta } from "$type/types.ts"; import { renderTemplate } from "./plug_api.ts"; -import { renderToText } from "$sb/lib/tree.ts"; +import { renderToText } from "$lib/tree.ts"; import { rewritePageRefs, rewritePageRefsInString } from "$sb/lib/resolve.ts"; import { queryParsed } from "../query/api.ts"; import { parseQuery } from "$sb/lib/parse-query.ts"; diff --git a/scripts/generate_fs_list.ts b/scripts/generate_fs_list.ts index 6f05e507..690943f7 100644 --- a/scripts/generate_fs_list.ts +++ b/scripts/generate_fs_list.ts @@ -1,7 +1,7 @@ import { walk } from "https://deno.land/std@0.165.0/fs/mod.ts"; import { resolve } from "https://deno.land/std@0.165.0/path/mod.ts"; import { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; -import { FileMeta } from "$sb/types.ts"; +import { FileMeta } from "../type/types.ts"; const rootDir = resolve("website_build"); diff --git a/server/crypto.test.ts b/server/crypto.test.ts index b1300be5..f7cbf8fb 100644 --- a/server/crypto.test.ts +++ b/server/crypto.test.ts @@ -1,6 +1,6 @@ -import { sleep } from "$sb/lib/async.ts"; -import { MemoryKvPrimitives } from "../plugos/lib/memory_kv_primitives.ts"; -import { assertEquals } from "../test_deps.ts"; +import { sleep } from "$lib/async.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { JWTIssuer } from "./crypto.ts"; Deno.test("Test JWT crypto", async () => { diff --git a/server/crypto.ts b/server/crypto.ts index 51f07d5c..eda441b6 100644 --- a/server/crypto.ts +++ b/server/crypto.ts @@ -1,9 +1,5 @@ -import { - create, - getNumericDate, - verify, -} from "https://deno.land/x/djwt@v3.0.1/mod.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; +import { create, getNumericDate, verify } from "djwt"; +import type { KvPrimitives } from "$lib/data/kv_primitives.ts"; const jwtSecretKey = "jwtSecretKey"; diff --git a/server/db_backend.ts b/server/db_backend.ts index 4111bafa..c1087b97 100644 --- a/server/db_backend.ts +++ b/server/db_backend.ts @@ -1,6 +1,6 @@ -import { DenoKvPrimitives } from "../plugos/lib/deno_kv_primitives.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { MemoryKvPrimitives } from "../plugos/lib/memory_kv_primitives.ts"; +import { DenoKvPrimitives } from "$lib/data/deno_kv_primitives.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; import { path } from "./deps.ts"; /** diff --git a/server/deps.ts b/server/deps.ts index e7c873b6..7f2a4722 100644 --- a/server/deps.ts +++ b/server/deps.ts @@ -1,4 +1,4 @@ -export * from "../common/deps.ts"; +export * from "$common/deps.ts"; export { Hono } from "https://deno.land/x/hono@v3.12.2/mod.ts"; export { diff --git a/plugos/hooks/endpoint.ts b/server/hooks/endpoint.ts similarity index 97% rename from plugos/hooks/endpoint.ts rename to server/hooks/endpoint.ts index 79ca66f2..b4e23389 100644 --- a/plugos/hooks/endpoint.ts +++ b/server/hooks/endpoint.ts @@ -1,5 +1,5 @@ -import { Hook, Manifest } from "../types.ts"; -import { System } from "../system.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; +import { System } from "../../lib/plugos/system.ts"; import { Context, Next } from "../../server/deps.ts"; export type EndpointRequest = { diff --git a/server/http_server.ts b/server/http_server.ts index c1fa512d..7db6cd4d 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -7,17 +7,17 @@ import { HonoRequest, setCookie, } from "./deps.ts"; -import { AssetBundle } from "../plugos/asset_bundle/bundle.ts"; -import { FileMeta } from "$sb/types.ts"; +import { AssetBundle } from "../lib/asset_bundle/bundle.ts"; +import { FileMeta } from "$type/types.ts"; import { ShellRequest } from "./rpc.ts"; import { SpaceServer, SpaceServerConfig } from "./instance.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { PrefixedKvPrimitives } from "../plugos/lib/prefixed_kv_primitives.ts"; -import { base64Encode } from "../plugos/asset_bundle/base64.ts"; -import { extendedMarkdownLanguage } from "../common/markdown_parser/parser.ts"; -import { parse } from "../common/markdown_parser/parse_tree.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { PrefixedKvPrimitives } from "$lib/data/prefixed_kv_primitives.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; import { renderMarkdownToHtml } from "../plugs/markdown/markdown_render.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; +import { parsePageRef } from "$sb/lib/page_ref.ts"; +import { base64Encode } from "$lib/crypto.ts"; const authenticationExpirySeconds = 60 * 60 * 24 * 7; // 1 week diff --git a/server/instance.ts b/server/instance.ts index b98404a1..746eccf4 100644 --- a/server/instance.ts +++ b/server/instance.ts @@ -1,15 +1,15 @@ -import { SilverBulletHooks } from "../common/manifest.ts"; -import { AssetBundlePlugSpacePrimitives } from "../common/spaces/asset_bundle_space_primitives.ts"; -import { FilteredSpacePrimitives } from "../common/spaces/filtered_space_primitives.ts"; -import { ReadOnlySpacePrimitives } from "../common/spaces/ro_space_primitives.ts"; -import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; -import { ensureAndLoadSettingsAndIndex } from "../common/util.ts"; -import { AssetBundle } from "../plugos/asset_bundle/bundle.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; -import { System } from "../plugos/system.ts"; +import { SilverBulletHooks } from "$common/manifest.ts"; +import { ensureAndLoadSettingsAndIndex } from "$common/settings.ts"; +import { AssetBundlePlugSpacePrimitives } from "$common/spaces/asset_bundle_space_primitives.ts"; +import { FilteredSpacePrimitives } from "$common/spaces/filtered_space_primitives.ts"; +import { ReadOnlySpacePrimitives } from "$common/spaces/ro_space_primitives.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { AssetBundle } from "../lib/asset_bundle/bundle.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; +import { System } from "$lib/plugos/system.ts"; import { BuiltinSettings } from "../web/types.ts"; import { JWTIssuer } from "./crypto.ts"; import { gitIgnoreCompiler } from "./deps.ts"; diff --git a/server/server_system.ts b/server/server_system.ts index 622b64ef..2cfbc533 100644 --- a/server/server_system.ts +++ b/server/server_system.ts @@ -1,43 +1,43 @@ -import { PlugNamespaceHook } from "../common/hooks/plug_namespace.ts"; -import { SilverBulletHooks } from "../common/manifest.ts"; -import { EventedSpacePrimitives } from "../common/spaces/evented_space_primitives.ts"; -import { PlugSpacePrimitives } from "../common/spaces/plug_space_primitives.ts"; -import { createSandbox } from "../plugos/sandboxes/web_worker_sandbox.ts"; -import { CronHook } from "../plugos/hooks/cron.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { MQHook } from "../plugos/hooks/mq.ts"; -import assetSyscalls from "../plugos/syscalls/asset.ts"; -import { eventSyscalls } from "../plugos/syscalls/event.ts"; -import { mqSyscalls } from "../plugos/syscalls/mq.ts"; -import { System } from "../plugos/system.ts"; -import { Space } from "../web/space.ts"; -import { markdownSyscalls } from "../common/syscalls/markdown.ts"; +import { PlugNamespaceHook } from "$common/hooks/plug_namespace.ts"; +import { SilverBulletHooks } from "$common/manifest.ts"; +import { EventedSpacePrimitives } from "$common/spaces/evented_space_primitives.ts"; +import { PlugSpacePrimitives } from "$common/spaces/plug_space_primitives.ts"; +import { createSandbox } from "../lib/plugos/sandboxes/web_worker_sandbox.ts"; +import { CronHook } from "../lib/plugos/hooks/cron.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { MQHook } from "../lib/plugos/hooks/mq.ts"; +import assetSyscalls from "../lib/plugos/syscalls/asset.ts"; +import { eventSyscalls } from "../lib/plugos/syscalls/event.ts"; +import { mqSyscalls } from "../lib/plugos/syscalls/mq.ts"; +import { System } from "../lib/plugos/system.ts"; +import { Space } from "../common/space.ts"; +import { markdownSyscalls } from "$common/syscalls/markdown.ts"; import { spaceReadSyscalls, spaceWriteSyscalls } from "./syscalls/space.ts"; -import { systemSyscalls } from "../common/syscalls/system.ts"; -import { yamlSyscalls } from "../common/syscalls/yaml.ts"; -import { sandboxFetchSyscalls } from "../plugos/syscalls/fetch.ts"; +import { systemSyscalls } from "$common/syscalls/system.ts"; +import { yamlSyscalls } from "$common/syscalls/yaml.ts"; +import { sandboxFetchSyscalls } from "../lib/plugos/syscalls/fetch.ts"; import { shellSyscalls } from "./syscalls/shell.ts"; -import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; -import { base64EncodedDataUrl } from "../plugos/asset_bundle/base64.ts"; -import { Plug } from "../plugos/plug.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { Plug } from "../lib/plugos/plug.ts"; +import { DataStore } from "$lib/data/datastore.ts"; import { dataStoreReadSyscalls, dataStoreWriteSyscalls, -} from "../plugos/syscalls/datastore.ts"; -import { languageSyscalls } from "../common/syscalls/language.ts"; -import { templateSyscalls } from "../common/syscalls/template.ts"; +} from "../lib/plugos/syscalls/datastore.ts"; +import { languageSyscalls } from "$common/syscalls/language.ts"; +import { templateSyscalls } from "$common/syscalls/template.ts"; import { codeWidgetSyscalls } from "../web/syscalls/code_widget.ts"; import { CodeWidgetHook } from "../web/hooks/code_widget.ts"; -import { KVPrimitivesManifestCache } from "../plugos/manifest_cache.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; +import { KVPrimitivesManifestCache } from "$lib/plugos/manifest_cache.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; import { ShellBackend } from "./shell_backend.ts"; -import { ensureSpaceIndex } from "../common/space_index.ts"; -import { FileMeta } from "$sb/types.ts"; -import { CommandHook } from "../common/hooks/command.ts"; -import { CommonSystem } from "../common/common_system.ts"; -import { MessageQueue } from "../plugos/lib/mq.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; +import { ensureSpaceIndex } from "$common/space_index.ts"; +import { FileMeta } from "$type/types.ts"; +import { CommandHook } from "$common/hooks/command.ts"; +import { CommonSystem } from "$common/common_system.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; +import { plugPrefix } from "$common/spaces/constants.ts"; +import { base64EncodedDataUrl } from "$lib/crypto.ts"; const fileListInterval = 30 * 1000; // 30s @@ -163,7 +163,7 @@ export class ServerSystem extends CommonSystem { }); } - if (path.startsWith("_plug/") && path.endsWith(".plug.js")) { + if (path.startsWith(plugPrefix) && path.endsWith(".plug.js")) { console.log("Plug updated, reloading:", path); this.system.unload(path); await this.loadPlugFromSpace(path); diff --git a/server/storage_backend.ts b/server/storage_backend.ts index 0de4d862..68ea0d3c 100644 --- a/server/storage_backend.ts +++ b/server/storage_backend.ts @@ -1,10 +1,10 @@ -import { DiskSpacePrimitives } from "../common/spaces/disk_space_primitives.ts"; -import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; +import { DiskSpacePrimitives } from "$common/spaces/disk_space_primitives.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; import { path } from "./deps.ts"; -import { S3SpacePrimitives } from "../common/spaces/s3_space_primitives.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { ChunkedKvStoreSpacePrimitives } from "../common/spaces/chunked_datastore_space_primitives.ts"; -import { HttpSpacePrimitives } from "../common/spaces/http_space_primitives.ts"; +import { S3SpacePrimitives } from "$common/spaces/s3_space_primitives.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { ChunkedKvStoreSpacePrimitives } from "$common/spaces/chunked_datastore_space_primitives.ts"; +import { HttpSpacePrimitives } from "$common/spaces/http_space_primitives.ts"; export async function determineStorageBackend( kvPrimitives: KvPrimitives, diff --git a/server/syscalls/shell.ts b/server/syscalls/shell.ts index 7fe8c1b9..53d592eb 100644 --- a/server/syscalls/shell.ts +++ b/server/syscalls/shell.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { ShellResponse } from "../../server/rpc.ts"; import { ShellBackend } from "../shell_backend.ts"; diff --git a/server/syscalls/space.ts b/server/syscalls/space.ts index bc40a8b0..a73eb01d 100644 --- a/server/syscalls/space.ts +++ b/server/syscalls/space.ts @@ -1,6 +1,6 @@ -import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts"; -import { SysCallMapping } from "../../plugos/system.ts"; -import type { Space } from "../../web/space.ts"; +import { AttachmentMeta, FileMeta, PageMeta } from "../../type/types.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; +import type { Space } from "../../common/space.ts"; /** * Almost the same as web/syscalls/space.ts except leaving out client-specific stuff diff --git a/plug-api/types.ts b/type/types.ts similarity index 72% rename from plug-api/types.ts rename to type/types.ts index 1ed2a066..cb0bd45a 100644 --- a/plug-api/types.ts +++ b/type/types.ts @@ -1,3 +1,6 @@ +import type { ParseTree } from "$lib/tree.ts"; +import type { TextChange } from "../web/change.ts"; + export type FileMeta = { name: string; created: number; @@ -171,3 +174,81 @@ export type UploadFile = { contentType: string; content: Uint8Array; }; + +export type AppEvent = + | "page:click" + | "editor:complete" + | "minieditor:complete" + | "slash:complete" + | "editor:lint" + | "page:load" + | "editor:init" + | "editor:pageLoaded" // args: pageName, previousPage, isSynced + | "editor:pageReloaded" + | "editor:pageSaved" + | "editor:modeswitch" + | "plugs:loaded" + | "editor:pageModified"; + +export type QueryProviderEvent = { + query: Query; + variables?: Record; +}; + +export type ClickEvent = { + page: string; + pos: number; + metaKey: boolean; + ctrlKey: boolean; + altKey: boolean; +}; + +export type IndexEvent = { + name: string; + text: string; +}; + +export type IndexTreeEvent = { + name: string; + tree: ParseTree; +}; + +export type PublishEvent = { + uri?: string; + // Page name + name: string; +}; + +export type LintEvent = { + name: string; + tree: ParseTree; +}; + +export type CompleteEvent = { + pageName: string; + linePrefix: string; + pos: number; + parentNodes: string[]; +}; + +export type SlashCompletion = { + label: string; + detail?: string; + invoke: string; + order?: number; +} & Record; + +export type WidgetContent = { + html?: string; + script?: string; + markdown?: string; + url?: string; + height?: number; + width?: number; +}; + +/** PageModifiedEvent payload for "editor:pageModified". Fired when the document text changes + */ +export type PageModifiedEvent = { + changes: TextChange[]; +}; diff --git a/web/boot.ts b/web/boot.ts index 52a4f480..f4f0cbfe 100644 --- a/web/boot.ts +++ b/web/boot.ts @@ -1,4 +1,4 @@ -import { safeRun } from "../common/util.ts"; +import { safeRun } from "../lib/async.ts"; import { Client } from "./client.ts"; const syncMode = window.silverBulletConfig.syncOnly || diff --git a/plug-api/lib/change.test.ts b/web/change.test.ts similarity index 90% rename from plug-api/lib/change.test.ts rename to web/change.test.ts index be64dbe7..df478fc2 100644 --- a/plug-api/lib/change.test.ts +++ b/web/change.test.ts @@ -1,4 +1,4 @@ -import { rangeLength, rangesOverlap } from "$sb/lib/change.ts"; +import { rangeLength, rangesOverlap } from "./change.ts"; import { assertEquals } from "https://deno.land/std@0.165.0/testing/asserts.ts"; Deno.test("rangeLength", () => { diff --git a/plug-api/lib/change.ts b/web/change.ts similarity index 100% rename from plug-api/lib/change.ts rename to web/change.ts diff --git a/web/client.ts b/web/client.ts index b9e408d5..5d701abd 100644 --- a/web/client.ts +++ b/web/client.ts @@ -7,12 +7,11 @@ import { gitIgnoreCompiler, SyntaxNode, syntaxTree, -} from "../common/deps.ts"; -import { Space } from "./space.ts"; +} from "./deps.ts"; +import { Space } from "../common/space.ts"; import { FilterOption } from "./types.ts"; -import { ensureAndLoadSettingsAndIndex } from "../common/util.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { AppCommand } from "../common/hooks/command.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { AppCommand } from "$common/hooks/command.ts"; import { PageState, parsePageRefFromURI, @@ -21,46 +20,47 @@ import { import { AppViewState, BuiltinSettings } from "./types.ts"; -import type { AppEvent, CompleteEvent } from "../plug-api/app_event.ts"; -import { throttle } from "$sb/lib/async.ts"; -import { PlugSpacePrimitives } from "../common/spaces/plug_space_primitives.ts"; -import { EventedSpacePrimitives } from "../common/spaces/evented_space_primitives.ts"; +import type { AppEvent, CompleteEvent } from "$type/types.ts"; +import { throttle } from "$lib/async.ts"; +import { PlugSpacePrimitives } from "$common/spaces/plug_space_primitives.ts"; +import { EventedSpacePrimitives } from "$common/spaces/evented_space_primitives.ts"; import { ISyncService, NoSyncSyncService, pageSyncInterval, SyncService, } from "./sync_service.ts"; -import { simpleHash } from "../common/crypto.ts"; -import { SyncStatus } from "../common/spaces/sync.ts"; -import { HttpSpacePrimitives } from "../common/spaces/http_space_primitives.ts"; -import { FallbackSpacePrimitives } from "../common/spaces/fallback_space_primitives.ts"; -import { FilteredSpacePrimitives } from "../common/spaces/filtered_space_primitives.ts"; -import { encodePageRef, validatePageName } from "$sb/lib/page.ts"; +import { simpleHash } from "$lib/crypto.ts"; +import { SyncStatus } from "$common/spaces/sync.ts"; +import { HttpSpacePrimitives } from "$common/spaces/http_space_primitives.ts"; +import { FallbackSpacePrimitives } from "$common/spaces/fallback_space_primitives.ts"; +import { FilteredSpacePrimitives } from "$common/spaces/filtered_space_primitives.ts"; +import { encodePageRef, validatePageName } from "$sb/lib/page_ref.ts"; import { ClientSystem } from "./client_system.ts"; import { createEditorState } from "./editor_state.ts"; import { MainUI } from "./editor_ui.tsx"; import { cleanPageRef } from "$sb/lib/resolve.ts"; -import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; -import { CodeWidgetButton, FileMeta, PageMeta } from "$sb/types.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { IndexedDBKvPrimitives } from "../plugos/lib/indexeddb_kv_primitives.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; -import { DataStoreSpacePrimitives } from "../common/spaces/datastore_space_primitives.ts"; +import { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { CodeWidgetButton, FileMeta, PageMeta } from "../type/types.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { IndexedDBKvPrimitives } from "$lib/data/indexeddb_kv_primitives.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; +import { DataStoreSpacePrimitives } from "$common/spaces/datastore_space_primitives.ts"; import { EncryptedSpacePrimitives, -} from "../common/spaces/encrypted_space_primitives.ts"; +} from "$common/spaces/encrypted_space_primitives.ts"; import { ensureSpaceIndex, markFullSpaceIndexComplete, -} from "../common/space_index.ts"; -import { LimitedMap } from "$sb/lib/limited_map.ts"; -import { renderTheTemplate } from "../common/syscalls/template.ts"; -import { PageRef } from "$sb/lib/page.ts"; -import { ReadOnlySpacePrimitives } from "../common/spaces/ro_space_primitives.ts"; -import { KvPrimitives } from "../plugos/lib/kv_primitives.ts"; -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; +} from "$common/space_index.ts"; +import { renderTheTemplate } from "$common/syscalls/template.ts"; +import { PageRef } from "../plug-api/lib/page_ref.ts"; +import { ReadOnlySpacePrimitives } from "$common/spaces/ro_space_primitives.ts"; +import { KvPrimitives } from "$lib/data/kv_primitives.ts"; +import { builtinFunctions } from "$lib/builtin_query_functions.ts"; +import { ensureAndLoadSettingsAndIndex } from "$common/settings.ts"; +import { LimitedMap } from "$lib/limited_map.ts"; const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/; const autoSaveInterval = 1000; diff --git a/web/client_system.ts b/web/client_system.ts index fe1c27a4..5769668b 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -1,48 +1,48 @@ -import { PlugNamespaceHook } from "../common/hooks/plug_namespace.ts"; -import { SilverBulletHooks } from "../common/manifest.ts"; -import { CronHook } from "../plugos/hooks/cron.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { createSandbox } from "../plugos/sandboxes/web_worker_sandbox.ts"; +import { PlugNamespaceHook } from "$common/hooks/plug_namespace.ts"; +import { SilverBulletHooks } from "$common/manifest.ts"; +import { CronHook } from "../lib/plugos/hooks/cron.ts"; +import { EventHook } from "../lib/plugos/hooks/event.ts"; +import { createSandbox } from "../lib/plugos/sandboxes/web_worker_sandbox.ts"; -import assetSyscalls from "../plugos/syscalls/asset.ts"; -import { eventSyscalls } from "../plugos/syscalls/event.ts"; -import { System } from "../plugos/system.ts"; +import assetSyscalls from "../lib/plugos/syscalls/asset.ts"; +import { eventSyscalls } from "../lib/plugos/syscalls/event.ts"; +import { System } from "../lib/plugos/system.ts"; import type { Client } from "./client.ts"; import { CodeWidgetHook } from "./hooks/code_widget.ts"; -import { CommandHook } from "../common/hooks/command.ts"; +import { CommandHook } from "$common/hooks/command.ts"; import { SlashCommandHook } from "./hooks/slash_command.ts"; import { clientStoreSyscalls } from "./syscalls/clientStore.ts"; import { debugSyscalls } from "./syscalls/debug.ts"; import { editorSyscalls } from "./syscalls/editor.ts"; import { sandboxFetchSyscalls } from "./syscalls/fetch.ts"; -import { markdownSyscalls } from "../common/syscalls/markdown.ts"; +import { markdownSyscalls } from "$common/syscalls/markdown.ts"; import { shellSyscalls } from "./syscalls/shell.ts"; import { spaceReadSyscalls, spaceWriteSyscalls } from "./syscalls/space.ts"; import { syncSyscalls } from "./syscalls/sync.ts"; -import { systemSyscalls } from "../common/syscalls/system.ts"; -import { yamlSyscalls } from "../common/syscalls/yaml.ts"; -import { Space } from "./space.ts"; -import { MQHook } from "../plugos/hooks/mq.ts"; -import { mqSyscalls } from "../plugos/syscalls/mq.ts"; +import { systemSyscalls } from "$common/syscalls/system.ts"; +import { yamlSyscalls } from "$common/syscalls/yaml.ts"; +import { Space } from "../common/space.ts"; +import { MQHook } from "../lib/plugos/hooks/mq.ts"; +import { mqSyscalls } from "../lib/plugos/syscalls/mq.ts"; import { mqProxySyscalls } from "./syscalls/mq.proxy.ts"; import { dataStoreProxySyscalls } from "./syscalls/datastore.proxy.ts"; import { dataStoreReadSyscalls, dataStoreWriteSyscalls, -} from "../plugos/syscalls/datastore.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { MessageQueue } from "../plugos/lib/mq.ts"; -import { languageSyscalls } from "../common/syscalls/language.ts"; -import { templateSyscalls } from "../common/syscalls/template.ts"; +} from "../lib/plugos/syscalls/datastore.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { languageSyscalls } from "$common/syscalls/language.ts"; +import { templateSyscalls } from "$common/syscalls/template.ts"; import { codeWidgetSyscalls } from "./syscalls/code_widget.ts"; import { clientCodeWidgetSyscalls } from "./syscalls/client_code_widget.ts"; -import { KVPrimitivesManifestCache } from "../plugos/manifest_cache.ts"; -import { deepObjectMerge } from "$sb/lib/json.ts"; -import { Query } from "$sb/types.ts"; +import { KVPrimitivesManifestCache } from "$lib/plugos/manifest_cache.ts"; +import { deepObjectMerge } from "$lib/json.ts"; +import { Query } from "$type/types.ts"; import { PanelWidgetHook } from "./hooks/panel_widget.ts"; import { createKeyBindings } from "./editor_state.ts"; -import { CommonSystem } from "../common/common_system.ts"; -import { DataStoreMQ } from "../plugos/lib/mq.datastore.ts"; +import { CommonSystem } from "$common/common_system.ts"; +import { DataStoreMQ } from "$lib/data/mq.datastore.ts"; +import { plugPrefix } from "$common/spaces/constants.ts"; const plugNameExtractRegex = /\/(.+)\.plug\.js$/; @@ -141,7 +141,7 @@ export class ClientSystem extends CommonSystem { this.eventHook.addLocalListener( "file:changed", async (path: string, _selfUpdate, _oldHash, newHash) => { - if (path.startsWith("_plug/") && path.endsWith(".plug.js")) { + if (path.startsWith(plugPrefix) && path.endsWith(".plug.js")) { const plugName = plugNameExtractRegex.exec(path)![1]; console.log("Plug updated, reloading", plugName, "from", path); this.system.unload(path); diff --git a/web/cm_plugins/clean.ts b/web/cm_plugins/clean.ts index 6f86e3d3..cdad2599 100644 --- a/web/cm_plugins/clean.ts +++ b/web/cm_plugins/clean.ts @@ -1,4 +1,4 @@ -import type { ClickEvent } from "../../plug-api/app_event.ts"; +import type { ClickEvent } from "$type/types.ts"; import type { Extension } from "../deps.ts"; import type { Client } from "../client.ts"; import { blockquotePlugin } from "./block_quote.ts"; diff --git a/web/cm_plugins/command_link.ts b/web/cm_plugins/command_link.ts index 12d4d07f..2b997418 100644 --- a/web/cm_plugins/command_link.ts +++ b/web/cm_plugins/command_link.ts @@ -1,4 +1,4 @@ -import { ClickEvent } from "$sb/app_event.ts"; +import { ClickEvent } from "$type/types.ts"; import { Decoration, syntaxTree } from "../deps.ts"; import { Client } from "../client.ts"; import { @@ -7,7 +7,7 @@ import { invisibleDecoration, isCursorInRange, } from "./util.ts"; -import { commandLinkRegex } from "../../common/command.ts"; +import { commandLinkRegex } from "$common/command.ts"; /** * Plugin to hide path prefix when the cursor is not inside. diff --git a/web/cm_plugins/editor_paste.ts b/web/cm_plugins/editor_paste.ts index 4bae6b08..274b7ef1 100644 --- a/web/cm_plugins/editor_paste.ts +++ b/web/cm_plugins/editor_paste.ts @@ -2,22 +2,15 @@ import { EditorView, syntaxTree, ViewPlugin, ViewUpdate } from "../deps.ts"; import { Client } from "../client.ts"; // We use turndown to convert HTML to Markdown -import TurndownService from "https://cdn.skypack.dev/turndown@7.1.1"; +import TurndownService from "turndown"; // With tables and task notation as well -import { - tables, - taskListItems, -} from "https://cdn.skypack.dev/@joplin/turndown-plugin-gfm@1.0.45"; -import { safeRun } from "../../common/util.ts"; -import { lezerToParseTree } from "../../common/markdown_parser/parse_tree.ts"; -import { - addParentPointers, - findParentMatching, - nodeAtPos, -} from "../../plug-api/lib/tree.ts"; -import { folderName, resolve } from "../../common/path.ts"; +import { tables, taskListItems } from "turndown-plugin-gfm"; +import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts"; +import { addParentPointers, findParentMatching, nodeAtPos } from "$lib/tree.ts"; +import { folderName, resolve } from "$lib/path.ts"; import { maximumAttachmentSize } from "../constants.ts"; +import { safeRun } from "$lib/async.ts"; const turndownService = new TurndownService({ hr: "---", diff --git a/web/cm_plugins/fenced_code.ts b/web/cm_plugins/fenced_code.ts index fb4fe9ac..c2236186 100644 --- a/web/cm_plugins/fenced_code.ts +++ b/web/cm_plugins/fenced_code.ts @@ -8,7 +8,7 @@ import { } from "./util.ts"; import { MarkdownWidget } from "./markdown_widget.ts"; import { IFrameWidget } from "./iframe_widget.ts"; -import { isTemplate } from "$sb/lib/cheap_yaml.ts"; +import { isTemplate } from "../../lib/cheap_yaml.ts"; export function fencedCodePlugin(editor: Client) { return decoratorStateField((state: EditorState) => { diff --git a/web/cm_plugins/iframe_widget.ts b/web/cm_plugins/iframe_widget.ts index 86eae3e9..7e165ed2 100644 --- a/web/cm_plugins/iframe_widget.ts +++ b/web/cm_plugins/iframe_widget.ts @@ -1,8 +1,7 @@ -import { WidgetContent } from "../../plug-api/app_event.ts"; +import { CodeWidgetCallback, WidgetContent } from "$type/types.ts"; import { WidgetType } from "../deps.ts"; import type { Client } from "../client.ts"; import { createWidgetSandboxIFrame } from "../components/widget_sandbox_iframe.ts"; -import type { CodeWidgetCallback } from "$sb/types.ts"; export class IFrameWidget extends WidgetType { iframe?: HTMLIFrameElement; diff --git a/web/cm_plugins/lint.ts b/web/cm_plugins/lint.ts index 616be650..76e73513 100644 --- a/web/cm_plugins/lint.ts +++ b/web/cm_plugins/lint.ts @@ -1,8 +1,8 @@ import { Diagnostic, linter } from "@codemirror/lint"; import type { Client } from "../client.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { LintEvent } from "$sb/app_event.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { LintEvent } from "$type/types.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; export function plugLinter(client: Client) { return linter(async (view): Promise => { diff --git a/web/cm_plugins/markdown_widget.ts b/web/cm_plugins/markdown_widget.ts index 7813b706..ea746b7d 100644 --- a/web/cm_plugins/markdown_widget.ts +++ b/web/cm_plugins/markdown_widget.ts @@ -1,11 +1,11 @@ import { WidgetType } from "../deps.ts"; import type { Client } from "../client.ts"; -import type { CodeWidgetButton, CodeWidgetCallback } from "$sb/types.ts"; +import type { CodeWidgetButton, CodeWidgetCallback } from "../../type/types.ts"; import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts"; import { resolveAttachmentPath } from "$sb/lib/resolve.ts"; -import { parse } from "../../common/markdown_parser/parse_tree.ts"; -import { parsePageRef } from "$sb/lib/page.ts"; -import { extendedMarkdownLanguage } from "../../common/markdown_parser/parser.ts"; +import { parse } from "$common/markdown_parser/parse_tree.ts"; +import { parsePageRef } from "../../plug-api/lib/page_ref.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; import { tagPrefix } from "../../plugs/index/constants.ts"; const activeWidgets = new Set(); diff --git a/web/cm_plugins/table.ts b/web/cm_plugins/table.ts index 63580d5c..1a41ea58 100644 --- a/web/cm_plugins/table.ts +++ b/web/cm_plugins/table.ts @@ -6,8 +6,8 @@ import { } from "./util.ts"; import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts"; -import { ParseTree, renderToText } from "$sb/lib/tree.ts"; -import { lezerToParseTree } from "../../common/markdown_parser/parse_tree.ts"; +import { ParseTree, renderToText } from "$lib/tree.ts"; +import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts"; import type { Client } from "../client.ts"; import { resolveAttachmentPath } from "$sb/lib/resolve.ts"; diff --git a/web/cm_plugins/wiki_link.ts b/web/cm_plugins/wiki_link.ts index fe101cb0..7eb07d0f 100644 --- a/web/cm_plugins/wiki_link.ts +++ b/web/cm_plugins/wiki_link.ts @@ -1,5 +1,5 @@ -import { pageLinkRegex } from "../../common/markdown_parser/parser.ts"; -import { ClickEvent } from "../../plug-api/app_event.ts"; +import { pageLinkRegex } from "$common/markdown_parser/parser.ts"; +import { ClickEvent } from "$type/types.ts"; import { Decoration, syntaxTree } from "../deps.ts"; import { Client } from "../client.ts"; import { @@ -9,7 +9,7 @@ import { LinkWidget, } from "./util.ts"; import { resolvePath } from "$sb/lib/resolve.ts"; -import { encodePageRef, parsePageRef } from "$sb/lib/page.ts"; +import { encodePageRef, parsePageRef } from "../../plug-api/lib/page_ref.ts"; /** * Plugin to hide path prefix when the cursor is not inside. diff --git a/web/syscalls/cm_util.ts b/web/cm_util.ts similarity index 100% rename from web/syscalls/cm_util.ts rename to web/cm_util.ts diff --git a/web/components/command_palette.tsx b/web/components/command_palette.tsx index 20352808..ca06e458 100644 --- a/web/components/command_palette.tsx +++ b/web/components/command_palette.tsx @@ -1,9 +1,8 @@ -import { isMacLike } from "../../common/util.ts"; import { FilterList } from "./filter.tsx"; import { CompletionContext, CompletionResult, featherIcons } from "../deps.ts"; -import { AppCommand } from "../../common/hooks/command.ts"; +import { AppCommand } from "$common/hooks/command.ts"; import { BuiltinSettings, FilterOption } from "../types.ts"; -import { parseCommand } from "../../common/command.ts"; +import { parseCommand } from "$common/command.ts"; export function CommandPalette({ commands, @@ -74,3 +73,11 @@ export function CommandPalette({ /> ); } + +/** + * Checks if the current platform is Mac-like (Mac, iPhone, iPod, iPad). + * @returns A boolean indicating if the platform is Mac-like. + */ +function isMacLike() { + return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform); +} diff --git a/web/components/filter.tsx b/web/components/filter.tsx index 1e51120f..ef6e15c3 100644 --- a/web/components/filter.tsx +++ b/web/components/filter.tsx @@ -1,16 +1,16 @@ import { CompletionContext, CompletionResult, + FeatherProps, + FunctionalComponent, useEffect, useRef, useState, } from "../deps.ts"; import { FilterOption } from "../types.ts"; -import { FunctionalComponent } from "https://esm.sh/v99/preact@10.11.3/src/index"; -import { FeatherProps } from "https://esm.sh/v99/preact-feather@4.2.1/dist/types"; import { MiniEditor } from "./mini_editor.tsx"; -import { fuzzySearchAndSort } from "./fuse_search.ts"; -import { deepEqual } from "$sb/lib/json.ts"; +import { fuzzySearchAndSort } from "../fuse_search.ts"; +import { deepEqual } from "$lib/json.ts"; export function FilterList({ placeholder, diff --git a/web/components/page_navigator.tsx b/web/components/page_navigator.tsx index 4e2fa768..a50c2cb0 100644 --- a/web/components/page_navigator.tsx +++ b/web/components/page_navigator.tsx @@ -1,7 +1,7 @@ import { FilterList } from "./filter.tsx"; import { FilterOption } from "../types.ts"; import { CompletionContext, CompletionResult } from "../deps.ts"; -import { PageMeta } from "$sb/types.ts"; +import { PageMeta } from "../../type/types.ts"; import { isFederationPath } from "$sb/lib/resolve.ts"; export const tagRegex = /#[^#\d\s\[\]]+\w+/g; diff --git a/web/components/widget_sandbox_iframe.ts b/web/components/widget_sandbox_iframe.ts index 66ecceb3..be4bb841 100644 --- a/web/components/widget_sandbox_iframe.ts +++ b/web/components/widget_sandbox_iframe.ts @@ -1,4 +1,4 @@ -import { WidgetContent } from "$sb/app_event.ts"; +import { WidgetContent } from "$type/types.ts"; import { Client } from "../client.ts"; import { panelHtml } from "./panel_html.ts"; diff --git a/web/deps.ts b/web/deps.ts index 8b5bf38b..38a55530 100644 --- a/web/deps.ts +++ b/web/deps.ts @@ -1,7 +1,85 @@ -export * from "../common/deps.ts"; +export * from "$common/deps.ts"; + +export { + history, + historyKeymap, + indentWithTab, + standardKeymap, +} from "@codemirror/commands"; +export { + autocompletion, + closeBrackets, + closeBracketsKeymap, + CompletionContext, + completionKeymap, +} from "@codemirror/autocomplete"; +export type { Completion, CompletionResult } from "@codemirror/autocomplete"; +export { + closeSearchPanel, + openSearchPanel, + searchKeymap, +} from "@codemirror/search"; +export { + Decoration, + drawSelection, + dropCursor, + EditorView, + gutter, + highlightSpecialChars, + keymap, + placeholder, + runScopeHandlers, + ViewPlugin, + ViewUpdate, + WidgetType, +} from "@codemirror/view"; +export type { DecorationSet, KeyBinding } from "@codemirror/view"; +export { + codeFolding, + defaultHighlightStyle, + defineLanguageFacet, + foldAll, + foldCode, + foldedRanges, + foldGutter, + foldInside, + HighlightStyle, + indentNodeProp, + indentOnInput, + Language, + languageDataProp, + LanguageDescription, + LanguageSupport, + ParseContext, + StreamLanguage, + syntaxHighlighting, + syntaxTree, + toggleFold, + unfoldAll, + unfoldCode, +} from "@codemirror/language"; +export { + EditorSelection, + EditorState, + Range, + SelectionRange, + StateField, + Text, + Transaction, +} from "@codemirror/state"; + +export type { + ChangeSpec, + Compartment, + Extension, + StateCommand, +} from "@codemirror/state"; export { Fragment, h, render as preactRender } from "preact"; export type { ComponentChildren, FunctionalComponent } from "preact"; + +export type { FeatherProps } from "https://esm.sh/v99/preact-feather@4.2.1/dist/types"; + export { useEffect, useReducer, @@ -12,8 +90,4 @@ export { export * as featherIcons from "https://esm.sh/preact-feather@4.2.1?external=preact"; // Vim mode -export { - getCM as vimGetCm, - Vim, - vim, -} from "https://esm.sh/@replit/codemirror-vim@6.0.14?external=@codemirror/state,@codemirror/language,@codemirror/view,@codemirror/search,@codemirror/commands"; +export { getCM as vimGetCm, Vim, vim } from "@replit/codemirror-vim"; diff --git a/web/editor_state.ts b/web/editor_state.ts index 5c5ebe16..d85219b3 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -24,26 +24,26 @@ import { syntaxHighlighting, ViewPlugin, ViewUpdate, -} from "../common/deps.ts"; + vim, +} from "./deps.ts"; import { Client } from "./client.ts"; -import { vim } from "./deps.ts"; import { inlineImagesPlugin } from "./cm_plugins/inline_image.ts"; import { cleanModePlugins } from "./cm_plugins/clean.ts"; import { lineWrapper } from "./cm_plugins/line_wrapper.ts"; import { smartQuoteKeymap } from "./cm_plugins/smart_quotes.ts"; -import { safeRun } from "../common/util.ts"; -import { ClickEvent } from "$sb/app_event.ts"; +import { ClickEvent } from "$type/types.ts"; import { attachmentExtension, pasteLinkExtension, } from "./cm_plugins/editor_paste.ts"; -import { TextChange } from "$sb/lib/change.ts"; +import { TextChange } from "./change.ts"; import { postScriptPrefacePlugin } from "./cm_plugins/top_bottom_panels.ts"; -import { languageFor } from "../common/languages.ts"; +import { languageFor } from "$common/languages.ts"; import { plugLinter } from "./cm_plugins/lint.ts"; import { Compartment, Extension } from "@codemirror/state"; -import { extendedMarkdownLanguage } from "../common/markdown_parser/parser.ts"; -import { parseCommand } from "../common/command.ts"; +import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; +import { parseCommand } from "$common/command.ts"; +import { safeRun } from "$lib/async.ts"; export function createEditorState( client: Client, diff --git a/web/editor_ui.tsx b/web/editor_ui.tsx index 4b17d3c2..d85ba013 100644 --- a/web/editor_ui.tsx +++ b/web/editor_ui.tsx @@ -1,4 +1,3 @@ -import { safeRun } from "../common/util.ts"; import { Confirm, Prompt } from "./components/basic_modals.tsx"; import { CommandPalette } from "./components/command_palette.tsx"; import { FilterList } from "./components/filter.tsx"; @@ -17,8 +16,8 @@ import { import type { Client } from "./client.ts"; import { Panel } from "./components/panel.tsx"; import { h } from "./deps.ts"; -import { sleep } from "$sb/lib/async.ts"; -import { parseCommand } from "../common/command.ts"; +import { safeRun, sleep } from "../lib/async.ts"; +import { parseCommand } from "$common/command.ts"; export class MainUI { viewState: AppViewState = initialViewState; diff --git a/web/components/fuse_search.test.ts b/web/fuse_search.test.ts similarity index 89% rename from web/components/fuse_search.test.ts rename to web/fuse_search.test.ts index a163776e..b8b90079 100644 --- a/web/components/fuse_search.test.ts +++ b/web/fuse_search.test.ts @@ -1,5 +1,5 @@ -import { FilterOption } from "../types.ts"; -import { assertEquals } from "../../test_deps.ts"; +import { FilterOption } from "./types.ts"; +import { assertEquals } from "$lib/test_deps.ts"; import { fuzzySearchAndSort } from "./fuse_search.ts"; Deno.test("testFuzzyFilter", () => { diff --git a/web/components/fuse_search.ts b/web/fuse_search.ts similarity index 97% rename from web/components/fuse_search.ts rename to web/fuse_search.ts index 3dfa080c..f31781c3 100644 --- a/web/components/fuse_search.ts +++ b/web/fuse_search.ts @@ -1,6 +1,6 @@ // @deno-types="https://deno.land/x/fuse@v6.4.1/dist/fuse.d.ts" import Fuse from "https://deno.land/x/fuse@v6.4.1/dist/fuse.esm.min.js"; -import { FilterOption } from "../types.ts"; +import { FilterOption } from "./types.ts"; type FuseOption = FilterOption & { baseName: string; diff --git a/web/hooks/code_widget.ts b/web/hooks/code_widget.ts index 66e39d85..cbedf7c9 100644 --- a/web/hooks/code_widget.ts +++ b/web/hooks/code_widget.ts @@ -1,6 +1,6 @@ -import { Hook, Manifest } from "../../plugos/types.ts"; -import { System } from "../../plugos/system.ts"; -import { CodeWidgetCallback } from "$sb/types.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; +import { System } from "../../lib/plugos/system.ts"; +import { CodeWidgetCallback } from "../../type/types.ts"; export type CodeWidgetT = { codeWidget?: string; diff --git a/web/hooks/panel_widget.ts b/web/hooks/panel_widget.ts index 3b7bd0c7..2ecf53ac 100644 --- a/web/hooks/panel_widget.ts +++ b/web/hooks/panel_widget.ts @@ -1,6 +1,6 @@ -import { Hook, Manifest } from "../../plugos/types.ts"; -import { System } from "../../plugos/system.ts"; -import { CodeWidgetCallback } from "$sb/types.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; +import { System } from "../../lib/plugos/system.ts"; +import { CodeWidgetCallback } from "../../type/types.ts"; export type PanelWidgetT = { panelWidget?: "top" | "bottom"; diff --git a/web/hooks/slash_command.ts b/web/hooks/slash_command.ts index c01b115b..f625f1da 100644 --- a/web/hooks/slash_command.ts +++ b/web/hooks/slash_command.ts @@ -1,10 +1,10 @@ -import { Hook, Manifest } from "../../plugos/types.ts"; -import { System } from "../../plugos/system.ts"; +import { Hook, Manifest } from "../../lib/plugos/types.ts"; +import { System } from "../../lib/plugos/system.ts"; import { Completion, CompletionContext, CompletionResult } from "../deps.ts"; -import { safeRun } from "../../common/util.ts"; import { Client } from "../client.ts"; import { syntaxTree } from "../deps.ts"; -import { SlashCompletion } from "$sb/app_event.ts"; +import { SlashCompletion } from "$type/types.ts"; +import { safeRun } from "../../lib/async.ts"; export type SlashCommandDef = { name: string; diff --git a/web/navigator.ts b/web/navigator.ts index 848f36cb..ae231440 100644 --- a/web/navigator.ts +++ b/web/navigator.ts @@ -1,9 +1,9 @@ -import { safeRun } from "../common/util.ts"; -import { PageRef, parsePageRef } from "$sb/lib/page.ts"; +import { PageRef, parsePageRef } from "../plug-api/lib/page_ref.ts"; import { Client } from "./client.ts"; import { cleanPageRef } from "$sb/lib/resolve.ts"; -import { renderTheTemplate } from "../common/syscalls/template.ts"; -import { builtinFunctions } from "$sb/lib/builtin_query_functions.ts"; +import { renderTheTemplate } from "$common/syscalls/template.ts"; +import { builtinFunctions } from "../lib/builtin_query_functions.ts"; +import { safeRun } from "../lib/async.ts"; export type PageState = PageRef & { scrollTop?: number; diff --git a/web/service_worker.ts b/web/service_worker.ts index 4694d00d..b107619b 100644 --- a/web/service_worker.ts +++ b/web/service_worker.ts @@ -1,7 +1,7 @@ -import type { FileContent } from "../common/spaces/datastore_space_primitives.ts"; -import { simpleHash } from "../common/crypto.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { IndexedDBKvPrimitives } from "../plugos/lib/indexeddb_kv_primitives.ts"; +import type { FileContent } from "$common/spaces/datastore_space_primitives.ts"; +import { simpleHash } from "$lib/crypto.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { IndexedDBKvPrimitives } from "$lib/data/indexeddb_kv_primitives.ts"; const CACHE_NAME = "{{CACHE_NAME}}_{{CONFIG_HASH}}"; diff --git a/web/style.ts b/web/style.ts index 7ec03511..d2f3c97f 100644 --- a/web/style.ts +++ b/web/style.ts @@ -1,6 +1,6 @@ -import { HighlightStyle } from "../common/deps.ts"; +import { HighlightStyle } from "./deps.ts"; import { tagHighlighter, tags as t } from "./deps.ts"; -import * as ct from "../common/markdown_parser/customtags.ts"; +import * as ct from "$common/markdown_parser/customtags.ts"; export default function highlightStyles() { tagHighlighter; diff --git a/web/sync_service.ts b/web/sync_service.ts index 1749f304..3dc8f074 100644 --- a/web/sync_service.ts +++ b/web/sync_service.ts @@ -1,13 +1,10 @@ -import { sleep } from "$sb/lib/async.ts"; -import type { SpacePrimitives } from "../common/spaces/space_primitives.ts"; -import { - SpaceSync, - SyncStatus, - SyncStatusItem, -} from "../common/spaces/sync.ts"; -import { EventHook } from "../plugos/hooks/event.ts"; -import { DataStore } from "../plugos/lib/datastore.ts"; -import { Space } from "./space.ts"; +import { plugPrefix } from "$common/spaces/constants.ts"; +import type { SpacePrimitives } from "$common/spaces/space_primitives.ts"; +import { SpaceSync, SyncStatus, SyncStatusItem } from "$common/spaces/sync.ts"; +import { sleep } from "$lib/async.ts"; +import { EventHook } from "$lib/plugos/hooks/event.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { Space } from "../common/space.ts"; // Keeps the current sync snapshot const syncSnapshotKey = ["sync", "snapshot"]; @@ -310,7 +307,7 @@ export class SyncService implements ISyncService { primary: SpacePrimitives, secondary: SpacePrimitives, ): Promise { - if (!name.startsWith("_plug/")) { + if (!name.startsWith(plugPrefix)) { const operations = await SpaceSync.primaryConflictResolver( name, snapshot, diff --git a/web/syscalls/clientStore.ts b/web/syscalls/clientStore.ts index a80bf498..f14c17cc 100644 --- a/web/syscalls/clientStore.ts +++ b/web/syscalls/clientStore.ts @@ -1,6 +1,6 @@ -import { SysCallMapping } from "../../plugos/system.ts"; -import { DataStore } from "../../plugos/lib/datastore.ts"; -import { KvKey } from "$sb/types.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; +import { DataStore } from "$lib/data/datastore.ts"; +import { KvKey } from "$type/types.ts"; export function clientStoreSyscalls( ds: DataStore, diff --git a/web/syscalls/client_code_widget.ts b/web/syscalls/client_code_widget.ts index e3e3461c..578e56de 100644 --- a/web/syscalls/client_code_widget.ts +++ b/web/syscalls/client_code_widget.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { reloadAllMarkdownWidgets } from "../cm_plugins/markdown_widget.ts"; import { broadcastReload } from "../components/widget_sandbox_iframe.ts"; diff --git a/web/syscalls/code_widget.ts b/web/syscalls/code_widget.ts index 5b8626af..89453f6f 100644 --- a/web/syscalls/code_widget.ts +++ b/web/syscalls/code_widget.ts @@ -1,5 +1,5 @@ -import { CodeWidgetContent } from "$sb/types.ts"; -import { SysCallMapping } from "../../plugos/system.ts"; +import { CodeWidgetContent } from "../../type/types.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { CodeWidgetHook } from "../hooks/code_widget.ts"; export function codeWidgetSyscalls( diff --git a/web/syscalls/datastore.proxy.ts b/web/syscalls/datastore.proxy.ts index 594a2888..5c3c638e 100644 --- a/web/syscalls/datastore.proxy.ts +++ b/web/syscalls/datastore.proxy.ts @@ -1,4 +1,4 @@ -import type { SysCallMapping } from "../../plugos/system.ts"; +import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { Client } from "../client.ts"; import { proxySyscalls } from "./util.ts"; diff --git a/web/syscalls/debug.ts b/web/syscalls/debug.ts index 5b3265d9..dfff9bb3 100644 --- a/web/syscalls/debug.ts +++ b/web/syscalls/debug.ts @@ -1,5 +1,5 @@ -import { KvKey } from "$sb/types.ts"; -import type { SysCallMapping } from "../../plugos/system.ts"; +import { KvKey } from "../../type/types.ts"; +import type { SysCallMapping } from "../../lib/plugos/system.ts"; import { Client } from "../client.ts"; export function debugSyscalls(client: Client): SysCallMapping { diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 204a57fc..4f30fccf 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -10,12 +10,12 @@ import { Vim, vimGetCm, } from "../deps.ts"; -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "$lib/plugos/system.ts"; import type { FilterOption } from "../types.ts"; -import { UploadFile } from "../../plug-api/types.ts"; -import { PageRef } from "$sb/lib/page.ts"; +import { UploadFile } from "$type/types.ts"; +import { PageRef } from "$sb/lib/page_ref.ts"; import { openSearchPanel } from "../deps.ts"; -import { diffAndPrepareChanges } from "./cm_util.ts"; +import { diffAndPrepareChanges } from "../cm_util.ts"; export function editorSyscalls(client: Client): SysCallMapping { const syscalls: SysCallMapping = { diff --git a/web/syscalls/fetch.ts b/web/syscalls/fetch.ts index 745585bb..8a99369e 100644 --- a/web/syscalls/fetch.ts +++ b/web/syscalls/fetch.ts @@ -1,14 +1,11 @@ -import type { SysCallMapping } from "../../plugos/system.ts"; +import type { SysCallMapping } from "../../lib/plugos/system.ts"; import { performLocalFetch, ProxyFetchRequest, ProxyFetchResponse, -} from "../../common/proxy_fetch.ts"; +} from "$common/proxy_fetch.ts"; import type { Client } from "../client.ts"; -import { - base64Decode, - base64Encode, -} from "../../plugos/asset_bundle/base64.ts"; +import { base64Decode, base64Encode } from "../../lib/crypto.ts"; export function sandboxFetchSyscalls( client: Client, diff --git a/web/syscalls/mq.proxy.ts b/web/syscalls/mq.proxy.ts index 9f0f996f..b81f66fb 100644 --- a/web/syscalls/mq.proxy.ts +++ b/web/syscalls/mq.proxy.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import { Client } from "../client.ts"; import { proxySyscalls } from "./util.ts"; diff --git a/web/syscalls/shell.ts b/web/syscalls/shell.ts index cf35586c..ca469b01 100644 --- a/web/syscalls/shell.ts +++ b/web/syscalls/shell.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import type { Client } from "../client.ts"; export function shellSyscalls( diff --git a/web/syscalls/space.ts b/web/syscalls/space.ts index 1d63d33f..1d54372a 100644 --- a/web/syscalls/space.ts +++ b/web/syscalls/space.ts @@ -1,6 +1,6 @@ import { Client } from "../client.ts"; -import { SysCallMapping } from "../../plugos/system.ts"; -import { AttachmentMeta, FileMeta, PageMeta } from "$sb/types.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; +import { AttachmentMeta, FileMeta, PageMeta } from "../../type/types.ts"; export function spaceReadSyscalls(editor: Client): SysCallMapping { return { diff --git a/web/syscalls/sync.ts b/web/syscalls/sync.ts index a9b357e2..41be99bb 100644 --- a/web/syscalls/sync.ts +++ b/web/syscalls/sync.ts @@ -1,4 +1,4 @@ -import { SysCallMapping } from "../../plugos/system.ts"; +import { SysCallMapping } from "../../lib/plugos/system.ts"; import type { Client } from "../client.ts"; export function syncSyscalls(editor: Client): SysCallMapping { diff --git a/web/syscalls/util.ts b/web/syscalls/util.ts index e37cb3e1..410fbf6a 100644 --- a/web/syscalls/util.ts +++ b/web/syscalls/util.ts @@ -1,5 +1,5 @@ -import { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts"; -import { SyscallContext, SysCallMapping } from "../../plugos/system.ts"; +import { HttpSpacePrimitives } from "$common/spaces/http_space_primitives.ts"; +import { SyscallContext, SysCallMapping } from "../../lib/plugos/system.ts"; import { Client } from "../client.ts"; export function proxySyscalls(client: Client, names: string[]): SysCallMapping { diff --git a/web/types.ts b/web/types.ts index cee2a974..3e6ceba7 100644 --- a/web/types.ts +++ b/web/types.ts @@ -1,7 +1,7 @@ -import { Manifest } from "../common/manifest.ts"; -import { PageMeta } from "$sb/types.ts"; -import { AppCommand } from "../common/hooks/command.ts"; -import { defaultSettings } from "../common/util.ts"; +import { Manifest } from "$common/manifest.ts"; +import { PageMeta } from "$type/types.ts"; +import { AppCommand } from "$common/hooks/command.ts"; +import { defaultSettings } from "$common/settings.ts"; // Used by FilterBox export type FilterOption = {