diff --git a/deno.json b/deno.json index 5c2fbd0c..a1ae4f95 100644 --- a/deno.json +++ b/deno.json @@ -4,7 +4,6 @@ "exports": { "./syscall": "./plug-api/syscall.ts", "./syscalls": "./plug-api/syscalls.ts", - "./types": "./plug-api/types.ts", "./lib/json": "./plug-api/lib/json.ts", "./lib/tree": "./plug-api/lib/tree.ts", "./lib/attribute": "./plug-api/lib/attribute.ts", @@ -12,12 +11,10 @@ "./lib/page_ref": "./plug-api/lib/page_ref.ts", "./lib/resolve": "./plug-api/lib/resolve.ts", "./lib/query_expression": "./plug-api/lib/query_expression.ts", - "./lib/yaml_page": "./plug-api/lib/yaml_page.ts", "./lib/query": "./plug-api/lib/query.ts", "./lib/frontmatter": "./plug-api/lib/frontmatter.ts", "./lib/markdown": "./plug-api/lib/markdown.ts", "./lib/tags": "./plug-api/lib/tags.ts", - "./type/config": "./type/config.ts", "./type/rpc": "./type/rpc.ts", "./type/client": "./type/client.ts" }, @@ -101,7 +98,6 @@ "@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.7", "@silverbulletmd/silverbullet/syscall": "./plug-api/syscall.ts", "@silverbulletmd/silverbullet/syscalls": "./plug-api/syscalls.ts", - "@silverbulletmd/silverbullet/types": "./plug-api/types.ts", "@silverbulletmd/silverbullet/lib/json": "./plug-api/lib/json.ts", "@silverbulletmd/silverbullet/lib/tree": "./plug-api/lib/tree.ts", "@silverbulletmd/silverbullet/lib/attribute": "./plug-api/lib/attribute.ts", @@ -109,13 +105,11 @@ "@silverbulletmd/silverbullet/lib/page_ref": "./plug-api/lib/page_ref.ts", "@silverbulletmd/silverbullet/lib/resolve": "./plug-api/lib/resolve.ts", "@silverbulletmd/silverbullet/lib/query_expression": "./plug-api/lib/query_expression.ts", - "@silverbulletmd/silverbullet/lib/yaml_page": "./plug-api/lib/yaml_page.ts", "@silverbulletmd/silverbullet/lib/native_fetch": "./plug-api/lib/native_fetch.ts", "@silverbulletmd/silverbullet/lib/query": "./plug-api/lib/query.ts", "@silverbulletmd/silverbullet/lib/frontmatter": "./plug-api/lib/frontmatter.ts", "@silverbulletmd/silverbullet/lib/markdown": "./plug-api/lib/markdown.ts", "@silverbulletmd/silverbullet/lib/tags": "./plug-api/lib/tags.ts", - "@silverbulletmd/silverbullet/type/config": "./type/config.ts", "@silverbulletmd/silverbullet/type/rpc": "./type/rpc.ts", "@silverbulletmd/silverbullet/type/client": "./type/client.ts", "@codemirror/autocomplete": "https://esm.sh/@codemirror/autocomplete@6.18.1?external=@codemirror/state,@codemirror/commands,@lezer/common,@codemirror/view,@codemirror/language&target=es2022", diff --git a/lib/command.ts b/lib/command.ts deleted file mode 100644 index 777edfb1..00000000 --- a/lib/command.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { CommandDef, SlashCommandDef } from "./manifest.ts"; -import type { SlashCompletions } from "@silverbulletmd/silverbullet/types"; - -export type RunnableCommand = { - run?: (args?: any[]) => Promise; -}; - -export type Command = CommandDef & RunnableCommand; -export type SlashCommand = SlashCommandDef & { - run: (...args: any[]) => Promise; -}; - -export type CommandHookEvents = { - commandsUpdated(commands: Map): void; -}; - -// TODO: Move this elsewhere -export function isValidEditor( - currentEditor: string | undefined, - requiredEditor: string | undefined, -): boolean { - return (requiredEditor === undefined) || - (currentEditor === undefined && - requiredEditor === "page") || - (requiredEditor === "any") || - (currentEditor === requiredEditor) || - (currentEditor !== undefined && requiredEditor === "notpage"); -} diff --git a/lib/data/datastore.ts b/lib/data/datastore.ts index e26cd242..4c5632c5 100644 --- a/lib/data/datastore.ts +++ b/lib/data/datastore.ts @@ -3,9 +3,10 @@ import { queryLua, } from "../space_lua/query_collection.ts"; import { LuaEnv, LuaStackFrame } from "../space_lua/runtime.ts"; -import type { KV, KvKey } from "../../plug-api/types.ts"; import type { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; +import type { KV, KvKey } from "../../type/datastore.ts"; + /** * This is the data store class you'll actually want to use, wrapping the primitives * in a more user-friendly way diff --git a/lib/data/indexeddb_kv_primitives.ts b/lib/data/indexeddb_kv_primitives.ts index 920505ad..e3babcdb 100644 --- a/lib/data/indexeddb_kv_primitives.ts +++ b/lib/data/indexeddb_kv_primitives.ts @@ -1,7 +1,8 @@ -import type { KV, KvKey } from "../../plug-api/types.ts"; import type { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; import { type IDBPDatabase, openDB } from "idb"; +import type { KV, KvKey } from "../../type/datastore.ts"; + const sep = "\0"; const objectStoreName = "data"; diff --git a/lib/data/kv_primitives.test.ts b/lib/data/kv_primitives.test.ts index b41e07c0..8cf08652 100644 --- a/lib/data/kv_primitives.test.ts +++ b/lib/data/kv_primitives.test.ts @@ -1,6 +1,7 @@ import type { KvPrimitives } from "./kv_primitives.ts"; import { assertEquals } from "@std/assert"; -import type { KV } from "../../plug-api/types.ts"; + +import type { KV } from "../../type/datastore.ts"; export async function allTests(db: KvPrimitives) { await db.batchSet([ diff --git a/lib/data/kv_primitives.ts b/lib/data/kv_primitives.ts index e51a46a8..53d310f1 100644 --- a/lib/data/kv_primitives.ts +++ b/lib/data/kv_primitives.ts @@ -1,4 +1,4 @@ -import type { KV, KvKey } from "../../plug-api/types.ts"; +import type { KV, KvKey } from "../../type/datastore.ts"; export type KvQueryOptions = { prefix?: KvKey; diff --git a/lib/data/memory_kv_primitives.test.ts b/lib/data/memory_kv_primitives.test.ts index 7c715ab1..4be89d9c 100644 --- a/lib/data/memory_kv_primitives.test.ts +++ b/lib/data/memory_kv_primitives.test.ts @@ -1,8 +1,9 @@ import { assertEquals } from "@std/assert"; import { MemoryKvPrimitives } from "./memory_kv_primitives.ts"; -import type { KV } from "../../plug-api/types.ts"; import { allTests } from "./kv_primitives.test.ts"; +import type { KV } from "../../type/datastore.ts"; + Deno.test("MemoryKvPrimitives loads from non-existent file without error", async () => { const tempPath = await Deno.makeTempFile() + "_nonexistent"; // Disable throttling for tests diff --git a/lib/data/memory_kv_primitives.ts b/lib/data/memory_kv_primitives.ts index c76052c7..f38594fb 100644 --- a/lib/data/memory_kv_primitives.ts +++ b/lib/data/memory_kv_primitives.ts @@ -1,7 +1,8 @@ -import type { KV, KvKey } from "@silverbulletmd/silverbullet/types"; import type { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; import { throttle } from "../async.ts"; +import type { KV, KvKey } from "../../type/datastore.ts"; + const memoryKeySeparator = "\0"; export class MemoryKvPrimitives implements KvPrimitives { diff --git a/lib/data/mq.datastore.test.ts b/lib/data/mq.datastore.test.ts index c078b012..3a1f4407 100644 --- a/lib/data/mq.datastore.test.ts +++ b/lib/data/mq.datastore.test.ts @@ -4,7 +4,8 @@ import { MemoryKvPrimitives } from "./memory_kv_primitives.ts"; import { DataStore } from "./datastore.ts"; import { PrefixedKvPrimitives } from "./prefixed_kv_primitives.ts"; import { FakeTime } from "@std/testing/time"; -import type { MQMessage } from "../../plug-api/types.ts"; + +import type { MQMessage } from "../../type/datastore.ts"; Deno.test("DataStore MQ", async () => { const time = new FakeTime(); diff --git a/lib/data/mq.datastore.ts b/lib/data/mq.datastore.ts index 06c74a00..b630ef9a 100644 --- a/lib/data/mq.datastore.ts +++ b/lib/data/mq.datastore.ts @@ -1,13 +1,13 @@ +import type { DataStore } from "./datastore.ts"; +import { parseExpressionString } from "../space_lua/parse.ts"; +import { LuaEnv } from "../space_lua/runtime.ts"; import type { KV, KvKey, MQMessage, MQStats, MQSubscribeOptions, -} from "../../plug-api/types.ts"; -import type { DataStore } from "./datastore.ts"; -import { parseExpressionString } from "../space_lua/parse.ts"; -import { LuaEnv } from "../space_lua/runtime.ts"; +} from "../../type/datastore.ts"; export type ProcessingMessage = MQMessage & { ts: number; diff --git a/lib/data/prefixed_kv_primitives.ts b/lib/data/prefixed_kv_primitives.ts index 1c125458..3f112aa0 100644 --- a/lib/data/prefixed_kv_primitives.ts +++ b/lib/data/prefixed_kv_primitives.ts @@ -1,6 +1,7 @@ -import type { KV, KvKey } from "../../plug-api/types.ts"; import type { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts"; +import type { KV, KvKey } from "../../type/datastore.ts"; + /** * Turns any KvPrimitives into a KvPrimitives that automatically prefixes all keys (and removes them again when reading) */ diff --git a/lib/dates.ts b/lib/dates.ts index 2c3de3b0..7aa56a5d 100644 --- a/lib/dates.ts +++ b/lib/dates.ts @@ -2,14 +2,6 @@ export function niceDate(d: Date): string { return localDateString(d).split("T")[0]; } -export function niceTime(d: Date): string { - return localDateString(d).split("T")[1].split(".")[0]; -} - -export function safeTime(d: Date): string { - return niceTime(d).replace(/:/g, "-"); -} - export function localDateString(d: Date): string { return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + diff --git a/lib/event.ts b/lib/event.ts deleted file mode 100644 index dc7f544a..00000000 --- a/lib/event.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { EventSubscriptionDef } from "./manifest.ts"; - -export type EventSubscription = EventSubscriptionDef & { - run: (...args: any[]) => Promise; -}; diff --git a/lib/plugos/hooks/mq.ts b/lib/plugos/hooks/mq.ts index 3c46fe47..e8d9fcd3 100644 --- a/lib/plugos/hooks/mq.ts +++ b/lib/plugos/hooks/mq.ts @@ -1,9 +1,9 @@ import type { Hook, Manifest } from "../types.ts"; import type { System } from "../system.ts"; -import type { MQMessage } from "../../../plug-api/types.ts"; import { throttle } from "../../async.ts"; import type { MQHookT } from "../../manifest.ts"; import type { DataStoreMQ } from "../../data/mq.datastore.ts"; +import type { MQMessage } from "../../../type/datastore.ts"; export class MQHook implements Hook { subscriptions: (() => void)[] = []; diff --git a/lib/plugos/syscalls/asset.ts b/lib/plugos/syscalls/asset.ts index cfbe14f8..f8a5a3ab 100644 --- a/lib/plugos/syscalls/asset.ts +++ b/lib/plugos/syscalls/asset.ts @@ -1,5 +1,5 @@ -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; import type { SysCallMapping, System } from "../system.ts"; +import type { FileMeta } from "../../../type/index.ts"; export default function assetSyscalls(system: System): SysCallMapping { return { diff --git a/lib/plugos/syscalls/fs.deno.test.ts b/lib/plugos/syscalls/fs.deno.test.ts index 87f906de..0caf4f76 100644 --- a/lib/plugos/syscalls/fs.deno.test.ts +++ b/lib/plugos/syscalls/fs.deno.test.ts @@ -1,8 +1,8 @@ -import type { FileMeta } from "../../../plug-api/types.ts"; import { assert } from "@std/assert"; import fileSystemSyscalls from "./fs.deno.ts"; import { dirname, resolve } from "@std/path"; import { fileURLToPath } from "node:url"; +import type { FileMeta } from "../../../type/index.ts"; Deno.test("Test FS operations", async () => { const thisFolder = resolve( diff --git a/lib/plugos/syscalls/fs.deno.ts b/lib/plugos/syscalls/fs.deno.ts index 891877d2..9e79953a 100644 --- a/lib/plugos/syscalls/fs.deno.ts +++ b/lib/plugos/syscalls/fs.deno.ts @@ -1,9 +1,9 @@ import type { SysCallMapping } from "../system.ts"; -import type { FileMeta } from "../../../plug-api/types.ts"; import { base64DecodeDataUrl, base64Encode } from "../../crypto.ts"; import { dirname, resolve } from "@std/path"; import { mime } from "mimetypes"; import { walk } from "@std/fs"; +import type { FileMeta } from "../../../type/index.ts"; export default function fileSystemSyscalls(root = "/"): SysCallMapping { function resolvedPath(p: string): string { diff --git a/lib/plugos/worker_runtime.ts b/lib/plugos/worker_runtime.ts index 796d229b..ecd7bffb 100644 --- a/lib/plugos/worker_runtime.ts +++ b/lib/plugos/worker_runtime.ts @@ -4,6 +4,7 @@ import type { ProxyFetchRequest64, ProxyFetchResponse64, } from "../proxy_fetch.ts"; +import { base64Decode, base64Encode } from "../crypto.ts"; declare global { function syscall(name: string, ...args: any[]): Promise; @@ -136,28 +137,6 @@ export function setupMessageListener( }); } -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 async function sandboxFetch( reqInfo: RequestInfo, options?: ProxyFetchRequest64, diff --git a/lib/space_lua/query_collection.ts b/lib/space_lua/query_collection.ts index a0c5042a..0f6115b1 100644 --- a/lib/space_lua/query_collection.ts +++ b/lib/space_lua/query_collection.ts @@ -3,9 +3,11 @@ import { LuaEnv, luaGet, luaKeys, LuaStackFrame } from "./runtime.ts"; import { evalExpression } from "./eval.ts"; import { asyncQuickSort } from "./util.ts"; import type { DataStore } from "../data/datastore.ts"; -import type { KvKey } from "@silverbulletmd/silverbullet/types"; import type { KvPrimitives } from "../data/kv_primitives.ts"; -import type { QueryCollationConfig } from "@silverbulletmd/silverbullet/type/client"; + +import type { QueryCollationConfig } from "../../type/config.ts"; + +import type { KvKey } from "../../type/datastore.ts"; export function buildItemEnv( objectVariable: string | undefined, diff --git a/lib/spaces/asset_bundle_space_primitives.ts b/lib/spaces/asset_bundle_space_primitives.ts index bfbc3108..fbe0cfae 100644 --- a/lib/spaces/asset_bundle_space_primitives.ts +++ b/lib/spaces/asset_bundle_space_primitives.ts @@ -1,6 +1,7 @@ import type { SpacePrimitives } from "./space_primitives.ts"; import type { AssetBundle } from "../../lib/asset_bundle/bundle.ts"; -import type { FileMeta } from "../../plug-api/types.ts"; + +import type { FileMeta } from "../../type/index.ts"; export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { constructor( diff --git a/lib/spaces/datastore_space_primitives.ts b/lib/spaces/datastore_space_primitives.ts index 986c8c76..23920d25 100644 --- a/lib/spaces/datastore_space_primitives.ts +++ b/lib/spaces/datastore_space_primitives.ts @@ -1,7 +1,7 @@ import type { SpacePrimitives } from "./space_primitives.ts"; import { mime } from "mimetypes"; -import type { FileMeta } from "../../plug-api/types.ts"; import type { DataStore } from "../data/datastore.ts"; +import type { FileMeta } from "../../type/index.ts"; export type FileContent = { name: string; diff --git a/lib/spaces/disk_space_primitives.ts b/lib/spaces/disk_space_primitives.ts index 02c70738..ea203e0e 100644 --- a/lib/spaces/disk_space_primitives.ts +++ b/lib/spaces/disk_space_primitives.ts @@ -2,7 +2,8 @@ import * as path from "@std/path"; import { readAll } from "@std/io/read-all"; import type { SpacePrimitives } from "./space_primitives.ts"; import { mime } from "mimetypes"; -import type { FileMeta } from "../../plug-api/types.ts"; + +import type { FileMeta } from "../../type/index.ts"; function lookupContentType(path: string): string { return mime.getType(path) || "application/octet-stream"; diff --git a/lib/spaces/evented_space_primitives.ts b/lib/spaces/evented_space_primitives.ts index 7da2a4f0..3a968b1e 100644 --- a/lib/spaces/evented_space_primitives.ts +++ b/lib/spaces/evented_space_primitives.ts @@ -1,8 +1,8 @@ -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; import type { EventHook } from "../../web/hooks/event.ts"; import { plugPrefix } from "../spaces/constants.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; +import type { FileMeta } from "../../type/index.ts"; /** * Events exposed: diff --git a/lib/spaces/fallback_space_primitives.ts b/lib/spaces/fallback_space_primitives.ts index 627cd4c2..e757ab9e 100644 --- a/lib/spaces/fallback_space_primitives.ts +++ b/lib/spaces/fallback_space_primitives.ts @@ -1,5 +1,5 @@ -import type { FileMeta } from "../../plug-api/types.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; +import type { FileMeta } from "../../type/index.ts"; /** * FallbackSpacePrimitives is a SpacePrimitives implementation that will try to fall back to another SpacePrimitives implementation for two diff --git a/lib/spaces/filtered_space_primitives.ts b/lib/spaces/filtered_space_primitives.ts index a57c25c5..f7ba0ebe 100644 --- a/lib/spaces/filtered_space_primitives.ts +++ b/lib/spaces/filtered_space_primitives.ts @@ -1,5 +1,5 @@ -import type { FileMeta } from "../../plug-api/types.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; +import type { FileMeta } from "../../type/index.ts"; export class FilteredSpacePrimitives implements SpacePrimitives { constructor( diff --git a/lib/spaces/http_space_primitives.ts b/lib/spaces/http_space_primitives.ts index 93f3ea3a..05d8cf2c 100644 --- a/lib/spaces/http_space_primitives.ts +++ b/lib/spaces/http_space_primitives.ts @@ -1,10 +1,10 @@ import type { SpacePrimitives } from "./space_primitives.ts"; -import type { FileMeta } from "../../plug-api/types.ts"; import { encodePageURI } from "@silverbulletmd/silverbullet/lib/page_ref"; import { flushCachesAndUnregisterServiceWorker, unregisterServiceWorkers, } from "../../web/sw_util.ts"; +import type { FileMeta } from "../../type/index.ts"; const defaultFetchTimeout = 30000; // 30 seconds diff --git a/lib/spaces/kv_meta_space_primitives.ts b/lib/spaces/kv_meta_space_primitives.ts deleted file mode 100644 index b28cb489..00000000 --- a/lib/spaces/kv_meta_space_primitives.ts +++ /dev/null @@ -1,95 +0,0 @@ -import type { FileMeta } from "../../plug-api/types.ts"; -import { mime } from "mimetypes"; -import type { KvPrimitives } from "../data/kv_primitives.ts"; -import type { SpacePrimitives } from "./space_primitives.ts"; - -export type KvMetaSpacePrimitivesCallbacks = { - readFile: ( - name: string, - spacePrimitives: SpacePrimitives, - ) => Promise; - writeFile: ( - name: string, - data: Uint8Array, - spacePrimitives: SpacePrimitives, - ) => Promise; - deleteFile: (name: string, spacePrimitives: SpacePrimitives) => Promise; -}; - -export class KvMetaSpacePrimitives implements SpacePrimitives { - constructor( - protected kv: KvPrimitives, - private callbacks: KvMetaSpacePrimitivesCallbacks, - ) { - } - - async readFile( - name: string, - ): Promise<{ data: Uint8Array; meta: FileMeta }> { - const [data, [meta]] = await Promise.all([ - this.callbacks.readFile(name, this), - this.kv.batchGet([[name]]), - ]); - return { data, meta: meta }; - } - - async writeFile( - name: string, - data: Uint8Array, - _selfUpdate?: boolean | undefined, - desiredMeta?: FileMeta | undefined, - ): Promise { - let meta: FileMeta | undefined; - try { - // Build off of the existing file meta, if file exists - meta = await this.getFileMeta(name); - } catch { - // Not found, that's fine - } - if (!meta) { - meta = { - name, - perm: "rw", - created: Date.now(), - contentType: mime.getType(name) || "application/octet-stream", - // These will be overwritten in a bit - lastModified: 0, - size: 0, - }; - } - meta = { - ...meta, - lastModified: desiredMeta?.lastModified || Date.now(), - size: data.byteLength, - }; - await Promise.all([ - this.callbacks.writeFile(name, data, this), - this.kv.batchSet([{ key: [name], value: meta }]), - ]); - - return meta; - } - - async deleteFile(name: string): Promise { - await Promise.all([ - this.callbacks.deleteFile(name, this), - this.kv.batchDelete([[name]]), - ]); - } - - async fetchFileList(): Promise { - const files: FileMeta[] = []; - for await (const meta of this.kv.query({})) { - files.push(meta.value); - } - return files; - } - - async getFileMeta(name: string): Promise { - const fileMeta = (await this.kv.batchGet([[name]]))[0]; - if (!fileMeta) { - throw new Error("Not found"); - } - return fileMeta; - } -} diff --git a/lib/spaces/plug_space_primitives.ts b/lib/spaces/plug_space_primitives.ts index 288cb507..bd8ab629 100644 --- a/lib/spaces/plug_space_primitives.ts +++ b/lib/spaces/plug_space_primitives.ts @@ -1,7 +1,7 @@ import type { SpacePrimitives } from "./space_primitives.ts"; import type { NamespaceOperation } from "../plugos/namespace.ts"; -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; import type { PlugNamespaceHook } from "../../web/hooks/plug_namespace.ts"; +import type { FileMeta } from "../../type/index.ts"; export class PlugSpacePrimitives implements SpacePrimitives { constructor( diff --git a/lib/spaces/ro_space_primitives.ts b/lib/spaces/ro_space_primitives.ts index bffed68c..6541ea13 100644 --- a/lib/spaces/ro_space_primitives.ts +++ b/lib/spaces/ro_space_primitives.ts @@ -1,5 +1,5 @@ -import type { FileMeta } from "../../plug-api/types.ts"; import type { SpacePrimitives } from "./space_primitives.ts"; +import type { FileMeta } from "../../type/index.ts"; export class ReadOnlySpacePrimitives implements SpacePrimitives { wrapped: SpacePrimitives; diff --git a/lib/spaces/space_primitives.ts b/lib/spaces/space_primitives.ts index 2310e02e..d7947601 100644 --- a/lib/spaces/space_primitives.ts +++ b/lib/spaces/space_primitives.ts @@ -1,4 +1,4 @@ -import type { FileMeta } from "../../plug-api/types.ts"; +import type { FileMeta } from "../../type/index.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/lib/spaces/sync.ts b/lib/spaces/sync.ts index 1dfea812..737e9c29 100644 --- a/lib/spaces/sync.ts +++ b/lib/spaces/sync.ts @@ -1,7 +1,7 @@ import type { SpacePrimitives } from "./space_primitives.ts"; import { EventEmitter } from "../plugos/event.ts"; -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; import { plugPrefix } from "./constants.ts"; +import type { FileMeta } from "../../type/index.ts"; type SyncHash = number; diff --git a/plug-api/lib/frontmatter.ts b/plug-api/lib/frontmatter.ts index d90591c0..51ee1983 100644 --- a/plug-api/lib/frontmatter.ts +++ b/plug-api/lib/frontmatter.ts @@ -3,7 +3,6 @@ import { type ParseTree, renderToText, replaceNodesMatchingAsync, - traverseTreeAsync, } from "./tree.ts"; import { cleanupJSON } from "./json.ts"; import { YAML } from "../syscalls.ts"; @@ -11,10 +10,10 @@ import { extractHashtag } from "./tags.ts"; export type FrontMatter = { tags?: string[] } & Record; -export type FrontmatterExtractOptions = { +export type FrontMatterExtractOptions = { removeKeys?: string[]; removeTags?: string[] | true; - removeFrontmatterSection?: boolean; + removeFrontMatterSection?: boolean; }; /** @@ -22,9 +21,9 @@ export type FrontmatterExtractOptions = { * optionally removes certain keys from the front matter * Side effect: will add parent pointers */ -export async function extractFrontmatter( +export async function extractFrontMatter( tree: ParseTree, - options: FrontmatterExtractOptions = {}, + options: FrontMatterExtractOptions = {}, ): Promise { let data: FrontMatter = { tags: [], @@ -105,7 +104,7 @@ export async function extractFrontmatter( } // If nothing is left, let's just delete this whole block if ( - Object.keys(newData).length === 0 || options.removeFrontmatterSection + Object.keys(newData).length === 0 || options.removeFrontMatterSection ) { return null; } @@ -136,62 +135,3 @@ export async function extractFrontmatter( return data; } - -/** - * Updates the front matter of a markdown document and returns the text as a rendered string - */ -export async function prepareFrontmatterDispatch( - tree: ParseTree, - data: string | Record, -): Promise { - let dispatchData: any = null; - await traverseTreeAsync(tree, async (t) => { - // Find FrontMatter and parse it - if (t.type === "FrontMatter") { - const bodyNode = t.children![1].children![0]; - const yamlText = renderToText(bodyNode); - - try { - let frontmatterText = ""; - if (typeof data === "string") { - frontmatterText = yamlText + data + "\n"; - } else { - const parsedYaml = await YAML.parse(yamlText) as any; - const newData = { ...parsedYaml, ...data }; - frontmatterText = await YAML.stringify(newData); - } - // Patch inline - dispatchData = { - changes: { - from: bodyNode.from, - to: bodyNode.to, - insert: frontmatterText, - }, - }; - } catch (e: any) { - console.error("Error parsing YAML", e); - } - return true; - } - return false; - }); - if (!dispatchData) { - // If we didn't find frontmatter, let's add it - let frontmatterText = ""; - if (typeof data === "string") { - frontmatterText = data + "\n"; - } else { - frontmatterText = await YAML.stringify(data); - } - const fullFrontmatterText = "---\n" + frontmatterText + - "---\n"; - dispatchData = { - changes: { - from: 0, - to: 0, - insert: fullFrontmatterText, - }, - }; - } - return dispatchData; -} diff --git a/plug-api/lib/json.test.ts b/plug-api/lib/json.test.ts index 882f43c7..3dd20a41 100644 --- a/plug-api/lib/json.test.ts +++ b/plug-api/lib/json.test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "@std/assert"; -import { cleanupJSON, deepClone, deepEqual, deepObjectMerge } from "./json.ts"; +import { cleanupJSON, deepClone, deepEqual } from "./json.ts"; Deno.test("JSON utils", () => { assertEquals(deepEqual({ a: 1 }, { a: 1 }), true); @@ -7,14 +7,6 @@ Deno.test("JSON utils", () => { assertEquals(deepEqual({ a: {} }, { a: null }), false); assertEquals(deepEqual({ a: {} }, { a: undefined }), false); assertEquals(deepEqual({ a: null }, { a: {} }), false); - assertEquals(deepObjectMerge({ a: 1 }, { a: 2 }), { a: 2 }); - assertEquals( - deepObjectMerge({ list: [1, 2, 3] }, { list: [4, 5, 6] }), - { list: [1, 2, 3, 4, 5, 6] }, - ); - assertEquals(deepObjectMerge({ a: { b: 1 } }, { a: { c: 2 } }), { - a: { b: 1, c: 2 }, - }); assertEquals(cleanupJSON({ "a.b": 1 }), { a: { b: 1 } }); assertEquals(cleanupJSON({ a: { "a.b": 1 } }), { a: { a: { b: 1 } }, diff --git a/plug-api/lib/json.ts b/plug-api/lib/json.ts index b4444cff..7c4a6564 100644 --- a/plug-api/lib/json.ts +++ b/plug-api/lib/json.ts @@ -99,47 +99,6 @@ export function cleanupJSON(a: any): any { return expanded; } -/** - * Performs a deep merge of two objects, with b taking precedence over a - * @param a - * @param b - * @returns - */ -export function deepObjectMerge(a: any, b: any, reverseArrays = false): any { - if (typeof a !== typeof b) { - return b; - } - if (a === undefined || a === null) { - return b; - } - if (b === undefined || b === null) { - return a; - } - - if (typeof a === "object") { - if (Array.isArray(a) && Array.isArray(b)) { - if (reverseArrays) { - return [...b, ...a]; - } else { - return [...a, ...b]; - } - } else { - const aKeys = Object.keys(a); - const bKeys = Object.keys(b); - const merged = { ...a }; - for (const key of bKeys) { - if (aKeys.includes(key)) { - merged[key] = deepObjectMerge(a[key], b[key], reverseArrays); - } else { - merged[key] = b[key]; - } - } - return merged; - } - } - return b; -} - export function deepClone(obj: T, ignoreKeys: string[] = []): T { // Handle null, undefined, or primitive types (string, number, boolean, symbol, bigint) if (obj === null || typeof obj !== "object") { diff --git a/plug-api/lib/markdown.ts b/plug-api/lib/markdown.ts deleted file mode 100644 index 7cb52cef..00000000 --- a/plug-api/lib/markdown.ts +++ /dev/null @@ -1,128 +0,0 @@ -import { - findNodeOfType, - type ParseTree, - renderToText, -} from "@silverbulletmd/silverbullet/lib/tree"; - -/** - * Strips markdown from a ParseTree - */ -export function stripMarkdown( - tree: ParseTree, -): string { - if (tree.type?.endsWith("Mark") || tree.type?.endsWith("Delimiter")) { - return ""; - } - - const stripArray = (arr: ParseTree[]) => arr.map(stripMarkdown).join(""); - - switch (tree.type) { - case "Document": - case "Emphasis": - case "Highlight": - case "Strikethrough": - case "InlineCode": - case "StrongEmphasis": - case "Superscript": - case "Subscript": - case "Paragraph": - case "ATXHeading1": - case "ATXHeading2": - case "ATXHeading3": - case "ATXHeading4": - case "ATXHeading5": - case "ATXHeading6": - case "Blockquote": - case "BulletList": - case "OrderedList": - case "ListItem": - case "Table": - case "TableHeader": - case "TableCell": - case "TableRow": - case "Task": - case "HTMLTag": { - return stripArray(tree.children!); - } - - case "FencedCode": - case "CodeBlock": { - tree.children = tree.children!.filter((c) => c.type); - return stripArray(tree.children!); - } - - case "Link": { - const linkTextChildren = tree.children!.slice(1, -4); - return stripArray(linkTextChildren); - } - - case "Image": { - const altTextNode = findNodeOfType(tree, "WikiLinkAlias") || - tree.children![1]; - let altText = altTextNode && altTextNode.type !== "LinkMark" - ? renderToText(altTextNode) - : ""; - - const dimReg = /\d*[^\|\s]*?[xX]\d*[^\|\s]*/.exec(altText); - if (dimReg) { - altText = altText.replace(dimReg[0], "").replace("|", ""); - } - - return altText; - } - - case "WikiLink": { - const aliasNode = findNodeOfType(tree, "WikiLinkAlias"); - - let linkText; - if (aliasNode) { - linkText = aliasNode.children![0].text!; - } else { - const ref = findNodeOfType(tree, "WikiLinkPage")!.children![0].text!; - linkText = ref.split("/").pop()!; - } - - return linkText; - } - - case "NakedURL": { - const url = tree.children![0].text!; - return url; - } - - case "TaskState": { - return tree.children![1].text!; - } - - case "Escape": { - return tree.children![0].text!.slice(1); - } - - case "CodeText": - case "Entity": { - return tree.children![0].text!; - } - - case "DeadlineDate": { - return renderToText(tree); - } - - case "CodeInfo": - case "CommentBlock": - case "FrontMatter": - case "Hashtag": - case "HardBreak": - case "HorizontalRule": - case "NamedAnchor": - case "Attribute": { - return ""; - } - - case undefined: - return tree.text!; - - default: - console.log("Unknown tree type: ", tree.type); - return ""; - } -} diff --git a/plug-api/lib/secrets_page.ts b/plug-api/lib/secrets_page.ts deleted file mode 100644 index 3ad1f050..00000000 --- a/plug-api/lib/secrets_page.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { readYamlPage } from "./yaml_page.ts"; - -// Read SECRETS page and retrieve specific set of secret keys -// Note: in this implementation there's no encryption employed at all so it's just a matter -// of not decising this SECRETS page to other places -export async function readSecrets(keys: string[]): Promise { - try { - const allSecrets = await readYamlPage("SECRETS", ["yaml", "secrets"]); - const collectedSecrets: any[] = []; - for (const key of keys) { - const secret = allSecrets[key]; - if (secret) { - collectedSecrets.push(secret); - } else { - throw new Error(`No such secret: ${key}`); - } - } - return collectedSecrets; - } catch (e: any) { - if (e.message === "Not found") { - throw new Error(`No such secret: ${keys[0]}`); - } - throw e; - } -} - -// Read SECRETS page and retrieve a specific secret -export async function readSecret(key: string): Promise { - try { - const allSecrets = await readYamlPage("SECRETS", ["yaml", "secrets"]); - const val = allSecrets[key]; - if (val === undefined) { - throw new Error(`No such secret: ${key}`); - } - return val; - } catch (e: any) { - if (e.message === "Not found") { - throw new Error(`No such secret: ${key}`); - } - throw e; - } -} diff --git a/plug-api/lib/tags.ts b/plug-api/lib/tags.ts index 87ab3a01..67657686 100644 --- a/plug-api/lib/tags.ts +++ b/plug-api/lib/tags.ts @@ -1,10 +1,10 @@ import type { FrontMatter } from "./frontmatter.ts"; -import type { ObjectValue } from "../types.ts"; import { type ParseTree, traverseTree, } from "@silverbulletmd/silverbullet/lib/tree"; import { tagRegex } from "../../web/markdown_parser/constants.ts"; +import type { ObjectValue } from "../../type/index.ts"; export function updateITags(obj: ObjectValue, frontmatter: FrontMatter) { const itags = [obj.tag, ...frontmatter.tags || []]; diff --git a/plug-api/lib/tree.ts b/plug-api/lib/tree.ts index a731face..b41151c4 100644 --- a/plug-api/lib/tree.ts +++ b/plug-api/lib/tree.ts @@ -8,8 +8,6 @@ export type ParseTree = { parent?: ParseTree; }; -export type AST = [string, ...AST[]] | string; - export function addParentPointers(tree: ParseTree) { if (!tree.children) { return; @@ -205,15 +203,6 @@ export function renderToText(tree?: ParseTree): string { return pieces.join(""); } -export function cloneTree(tree: ParseTree): ParseTree { - const newTree = { ...tree }; - if (tree.children) { - newTree.children = tree.children.map(cloneTree); - } - delete newTree.parent; - return newTree; -} - export function cleanTree(tree: ParseTree, omitTrimmable = true): ParseTree { if (tree.type === "⚠") { throw new Error( diff --git a/plug-api/lib/yaml_page.ts b/plug-api/lib/yaml_page.ts deleted file mode 100644 index 5af54522..00000000 --- a/plug-api/lib/yaml_page.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { findNodeOfType, traverseTree } from "./tree.ts"; -import { markdown, space, YAML } from "../syscalls.ts"; - -export async function readCodeBlockPage( - pageName: string, - allowedLanguages?: string[], -): Promise { - const text = await space.readPage(pageName); - const tree = await markdown.parseMarkdown(text); - let codeText: string | undefined; - - traverseTree(tree, (t): boolean => { - // Find a fenced code block - if (t.type !== "FencedCode") { - return false; - } - const codeInfoNode = findNodeOfType(t, "CodeInfo"); - if (allowedLanguages && !codeInfoNode) { - return false; - } - if ( - allowedLanguages && - !allowedLanguages.includes(codeInfoNode!.children![0].text!) - ) { - return false; - } - const codeTextNode = findNodeOfType(t, "CodeText"); - if (!codeTextNode) { - // Honestly, this shouldn't happen - return false; - } - codeText = codeTextNode.children![0].text!; - return true; - }); - - return codeText; -} - -export async function readYamlPage( - pageName: string, - allowedLanguages = ["yaml"], -): Promise { - const codeText = await readCodeBlockPage(pageName, allowedLanguages); - if (codeText === undefined) { - return undefined; - } - try { - return YAML.parse(codeText); - } catch (e: any) { - console.error("YAML Page parser error", e); - throw new Error(`YAML Error: ${e.message}`); - } -} - -export async function writeYamlPage( - pageName: string, - data: any, - prelude = "", -): Promise { - const text = await YAML.stringify(data); - await space.writePage(pageName, prelude + "```yaml\n" + text + "\n```"); -} diff --git a/plug-api/syscalls.ts b/plug-api/syscalls.ts index c5df3dee..c44472e4 100644 --- a/plug-api/syscalls.ts +++ b/plug-api/syscalls.ts @@ -2,7 +2,7 @@ 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 clientStore from "./syscalls/client_store.ts"; export * as sync from "./syscalls/sync.ts"; export * as language from "./syscalls/language.ts"; export * as codeWidget from "./syscalls/code_widget.ts"; diff --git a/plug-api/syscalls/asset.ts b/plug-api/syscalls/asset.ts index 37136f55..1e854ad7 100644 --- a/plug-api/syscalls/asset.ts +++ b/plug-api/syscalls/asset.ts @@ -1,6 +1,7 @@ import { base64DecodeDataUrl } from "../../lib/crypto.ts"; import { syscall } from "../syscall.ts"; -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; + +import type { FileMeta } from "../../type/index.ts"; /** * Reads an asset embedded in a plug (via the `assets` field in the plug manifest). diff --git a/plug-api/syscalls/clientStore.ts b/plug-api/syscalls/client_store.ts similarity index 100% rename from plug-api/syscalls/clientStore.ts rename to plug-api/syscalls/client_store.ts diff --git a/plug-api/syscalls/datastore.ts b/plug-api/syscalls/datastore.ts index a419ceeb..a482c892 100644 --- a/plug-api/syscalls/datastore.ts +++ b/plug-api/syscalls/datastore.ts @@ -1,6 +1,7 @@ import type { LuaCollectionQuery } from "../../lib/space_lua/query_collection.ts"; import { syscall } from "../syscall.ts"; -import type { KV, KvKey, KvQuery } from "../types.ts"; + +import type { KV, KvKey, KvQuery } from "../../type/datastore.ts"; /** * Exposes a key value story with query capabilities. diff --git a/plug-api/syscalls/editor.ts b/plug-api/syscalls/editor.ts index e307ded2..9627651e 100644 --- a/plug-api/syscalls/editor.ts +++ b/plug-api/syscalls/editor.ts @@ -1,7 +1,10 @@ -import type { PageMeta, UploadFile } from "../types.ts"; import { syscall } from "../syscall.ts"; -import type { FilterOption } from "@silverbulletmd/silverbullet/type/client"; +import type { + FilterOption, + UploadFile, +} from "@silverbulletmd/silverbullet/type/client"; import type { Ref } from "@silverbulletmd/silverbullet/lib/page_ref"; +import type { PageMeta } from "../../type/index.ts"; /** * Exposes various editor utilities. diff --git a/plug-api/syscalls/index.ts b/plug-api/syscalls/index.ts index 382b95c2..6d34dc4b 100644 --- a/plug-api/syscalls/index.ts +++ b/plug-api/syscalls/index.ts @@ -1,6 +1,6 @@ -import type { ObjectValue } from "@silverbulletmd/silverbullet/types"; import type { LuaCollectionQuery } from "../../lib/space_lua/query_collection.ts"; import { syscall } from "@silverbulletmd/silverbullet/syscall"; +import type { ObjectValue } from "../../type/index.ts"; /** * Exposes the SilverBullet object indexing system diff --git a/plug-api/syscalls/mq.ts b/plug-api/syscalls/mq.ts index 279f6bf9..5b6a2761 100644 --- a/plug-api/syscalls/mq.ts +++ b/plug-api/syscalls/mq.ts @@ -1,5 +1,6 @@ import { syscall } from "../syscall.ts"; -import type { MQStats } from "../types.ts"; + +import type { MQStats } from "../../type/datastore.ts"; /** * Implements a simple Message Queue system. diff --git a/plug-api/syscalls/space.ts b/plug-api/syscalls/space.ts index 69d9ffc1..ae6d6a4e 100644 --- a/plug-api/syscalls/space.ts +++ b/plug-api/syscalls/space.ts @@ -1,5 +1,6 @@ import { syscall } from "../syscall.ts"; -import type { DocumentMeta, FileMeta, PageMeta } from "../types.ts"; + +import type { DocumentMeta, FileMeta, PageMeta } from "../../type/index.ts"; /** * Exposes the space with its pages, documents and plugs. diff --git a/plug-api/syscalls/system.ts b/plug-api/syscalls/system.ts index ff656d45..abefd968 100644 --- a/plug-api/syscalls/system.ts +++ b/plug-api/syscalls/system.ts @@ -1,6 +1,6 @@ -import type { SyscallMeta } from "../types.ts"; import { syscall } from "../syscall.ts"; import type { CommandDef } from "../../lib/manifest.ts"; +import type { SyscallMeta } from "../../type/index.ts"; /** * System level syscalls diff --git a/plug-api/types.ts b/plug-api/types.ts deleted file mode 100644 index c79f21ac..00000000 --- a/plug-api/types.ts +++ /dev/null @@ -1,251 +0,0 @@ -import type { ParseTree } from "./lib/tree.ts"; -import type { TextChange } from "../web/change.ts"; - -export type FileMeta = { - name: string; - created: number; - lastModified: number; - contentType: string; - size: number; - perm: "ro" | "rw"; - noSync?: boolean; -}; - -export type PageMeta = ObjectValue< - { - name: string; - created: string; // indexing it as a string - lastModified: string; // indexing it as a string - perm: "ro" | "rw"; - lastOpened?: number; - pageDecoration?: PageDecoration; - } & Record ->; - -/** - * Decorates a page when it matches certain criteria - */ -export type PageDecoration = { - prefix?: string; - cssClasses?: string[]; - hide?: boolean; - renderWidgets?: boolean; // Defaults to true -}; - -export type DocumentMeta = ObjectValue< - { - name: string; - contentType: string; - created: string; - lastModified: string; - size: number; - perm: "ro" | "rw"; - extension: string; - } & Record ->; - -export type SyscallMeta = { - name: string; - requiredPermissions: string[]; - argCount: number; -}; - -// Message Queue related types -export type MQMessage = { - id: string; - queue: string; - body: any; - retries?: number; -}; - -export type MQStats = { - queued: number; - processing: number; - dlq: number; -}; - -export type MQSubscribeOptions = { - batchSize?: number; - pollInterval?: number; -}; - -// Key-Value Store related types -export type KvKey = string[]; - -export type KV = { - key: KvKey; - value: T; -}; - -export type KvQuery = { - prefix?: KvKey; -}; - -/** - * An ObjectValue that can be indexed by the `index` plug, needs to have a minimum of - * of two fields: - * - ref: a unique reference (id) for the object, ideally a page reference - * - tags: a list of tags that the object belongs to - */ -export type ObjectValue = { - ref: string; - tag: string; // main tag - tags?: string[]; - itags?: string[]; // implicit or inherited tags (inherited from the page for instance) -} & T; - -// Code widget stuff -export type CodeWidgetCallback = ( - bodyText: string, - pageName: string, -) => Promise; - -export type CodeWidgetContent = { - html: string; - script?: string; - buttons?: CodeWidgetButton[]; -}; - -export type CodeWidgetButton = { - widgetTarget?: boolean; - description: string; - svg: string; - invokeFunction: string[]; -}; - -// Document editors stuff -export type DocumentEditorCallback = () => Promise; - -export type DocumentEditorContent = { - html: string; - script?: string; -}; - -export type LintDiagnostic = { - from: number; - to: number; - severity: "error" | "warning" | "info" | "hint"; - message: string; -}; - -export type UploadFile = { - name: string; - 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:pageSaving" - | "editor:pageSaved" - | "editor:pageCreating" - | "editor:pageModified" - | "editor:documentSaving" - | "editor:documentSaved" - | "editor:modeswitch" - | "plugs:loaded" - | "cron:secondPassed" - | "hooks:renderTopWidgets" - | "hooks:renderBottomWidgets"; - -export type ClickEvent = { - page: string; - pos: number; - metaKey: boolean; - ctrlKey: boolean; - altKey: boolean; -}; - -export type EnrichedClickEvent = ClickEvent & { - parentNodes: string[]; -}; - -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 PageCreatingEvent = { - name: string; -}; - -export type PageCreatingContent = { - text: string; - perm: "ro" | "rw"; -}; - -export type SlashCompletionOption = { - label: string; - detail?: string; - invoke: string; - order?: number; -} & Record; - -export type SlashCompletions = { - // Ignore this one, only for compatibility with regular completions - from?: number; - // The actual completions - options: SlashCompletionOption[]; -}; - -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[]; -}; - -// HTTP Endpoint related types -export type EndpointRequest = { - method: string; - fullPath: string; - path: string; - query: { [key: string]: string }; - headers: { [key: string]: string }; - body: any; -}; - -export type EndpointResponse = { - status?: number; - headers?: { [key: string]: string }; - body: any; -}; diff --git a/plugs/editor/complete.ts b/plugs/editor/complete.ts index e7a2b3c8..7b673c08 100644 --- a/plugs/editor/complete.ts +++ b/plugs/editor/complete.ts @@ -1,11 +1,8 @@ -import type { - CompleteEvent, - DocumentMeta, - PageMeta, -} from "@silverbulletmd/silverbullet/types"; import { folderName } from "@silverbulletmd/silverbullet/lib/resolve"; import { queryLuaObjects } from "../index/api.ts"; import { language, lua } from "@silverbulletmd/silverbullet/syscalls"; +import type { DocumentMeta, PageMeta } from "../../type/index.ts"; +import type { CompleteEvent } from "@silverbulletmd/silverbullet/type/client"; // Page completion export async function pageComplete(completeEvent: CompleteEvent) { diff --git a/plugs/editor/navigate.ts b/plugs/editor/navigate.ts index 7c4d74e4..a901cbd0 100644 --- a/plugs/editor/navigate.ts +++ b/plugs/editor/navigate.ts @@ -1,4 +1,3 @@ -import type { ClickEvent } from "../../plug-api/types.ts"; import { extractHashtag } from "../../plug-api/lib/tags.ts"; import { editor, markdown } from "@silverbulletmd/silverbullet/syscalls"; import { @@ -14,6 +13,7 @@ import { } from "@silverbulletmd/silverbullet/lib/resolve"; import { parseRef } from "@silverbulletmd/silverbullet/lib/page_ref"; import { tagPrefix } from "../index/constants.ts"; +import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client"; async function actionClickOrActionEnter( mdTree: ParseTree | null, diff --git a/plugs/editor/upload.ts b/plugs/editor/upload.ts index 87f2d6d7..a3444655 100644 --- a/plugs/editor/upload.ts +++ b/plugs/editor/upload.ts @@ -1,8 +1,8 @@ import { editor, space, system } from "@silverbulletmd/silverbullet/syscalls"; -import type { UploadFile } from "@silverbulletmd/silverbullet/types"; import { defaultLinkStyle, maximumDocumentSize } from "../../web/constants.ts"; import { resolvePath } from "@silverbulletmd/silverbullet/lib/resolve"; import { encodePageURI } from "@silverbulletmd/silverbullet/lib/page_ref"; +import type { UploadFile } from "@silverbulletmd/silverbullet/type/client"; export async function saveFile(file: UploadFile) { const maxSize = await system.getConfig( diff --git a/plugs/emoji/emoji.ts b/plugs/emoji/emoji.ts index e3280c8c..59a16e1f 100644 --- a/plugs/emoji/emoji.ts +++ b/plugs/emoji/emoji.ts @@ -1,7 +1,8 @@ import emojiBlob from "./emoji.json" with { type: "json" }; -import type { CompleteEvent } from "../../plug-api/types.ts"; import { editor, system } from "@silverbulletmd/silverbullet/syscalls"; -import type { EmojiConfig } from "@silverbulletmd/silverbullet/type/client"; + +import type { EmojiConfig } from "../../type/config.ts"; +import type { CompleteEvent } from "@silverbulletmd/silverbullet/type/client"; let emojiConfig: EmojiConfig = { aliases: [] }; diff --git a/plugs/index/api.ts b/plugs/index/api.ts index 06c1e818..fc4b7a27 100644 --- a/plugs/index/api.ts +++ b/plugs/index/api.ts @@ -1,17 +1,19 @@ import { datastore, markdown } from "@silverbulletmd/silverbullet/syscalls"; -import type { KV, KvKey, KvQuery, ObjectValue } from "../../plug-api/types.ts"; import { ttlCache } from "../../lib/memory_cache.ts"; import type { LuaCollectionQuery } from "../../lib/space_lua/query_collection.ts"; import { - extractFrontmatter as extractFrontmatterFromTree, + extractFrontMatter as extractFrontmatterFromTree, type FrontMatter, - type FrontmatterExtractOptions, + type FrontMatterExtractOptions, } from "../../plug-api/lib/frontmatter.ts"; import { collectNodesOfType, renderToText, } from "@silverbulletmd/silverbullet/lib/tree"; import { applyPatches, type SetKeyPatch } from "../../lib/yaml.ts"; +import type { ObjectValue } from "../../type/index.ts"; + +import type { KV, KvKey, KvQuery } from "../../type/datastore.ts"; const indexKey = "idx"; const pageKey = "ridx"; @@ -163,7 +165,7 @@ export function getObjectByRef( export async function extractFrontmatter( text: string, - extractOptions: FrontmatterExtractOptions = {}, + extractOptions: FrontMatterExtractOptions = {}, ): Promise<{ frontmatter: FrontMatter; text: string }> { const tree = await markdown.parseMarkdown(text); const frontmatter = await extractFrontmatterFromTree(tree, extractOptions); diff --git a/plugs/index/attributes.ts b/plugs/index/attributes.ts index 44337698..9dd72ca2 100644 --- a/plugs/index/attributes.ts +++ b/plugs/index/attributes.ts @@ -1,4 +1,4 @@ -import type { ObjectValue } from "../../plug-api/types.ts"; +import type { ObjectValue } from "../../type/index.ts"; export type SimpleJSONType = { type?: "string" | "number" | "boolean" | "any" | "array" | "object" | "null"; diff --git a/plugs/index/command.ts b/plugs/index/command.ts index cb88d250..44911141 100644 --- a/plugs/index/command.ts +++ b/plugs/index/command.ts @@ -6,10 +6,11 @@ import { space, system, } from "@silverbulletmd/silverbullet/syscalls"; -import type { IndexEvent, MQMessage } from "@silverbulletmd/silverbullet/types"; +import type { IndexEvent } from "../../type/event.ts"; import { sleep } from "../../lib/async.ts"; import { indexDocument } from "./document.ts"; import { clearFileIndex } from "./api.ts"; +import type { MQMessage } from "../../type/datastore.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 cbb2ed74..ef228f58 100644 --- a/plugs/index/data.ts +++ b/plugs/index/data.ts @@ -3,11 +3,12 @@ import { collectNodesOfType, findNodeOfType, } from "@silverbulletmd/silverbullet/lib/tree"; -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { indexObjects } from "./api.ts"; import type { TagObject } from "./tags.ts"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { updateITags } from "@silverbulletmd/silverbullet/lib/tags"; +import type { ObjectValue } from "../../type/index.ts"; type DataObject = ObjectValue< { @@ -18,7 +19,7 @@ type DataObject = ObjectValue< export async function indexData({ name, tree }: IndexTreeEvent) { const dataObjects: ObjectValue[] = []; - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); await Promise.all( collectNodesOfType(tree, "FencedCode").map(async (t) => { diff --git a/plugs/index/document.ts b/plugs/index/document.ts index d8e845c1..b1f81093 100644 --- a/plugs/index/document.ts +++ b/plugs/index/document.ts @@ -1,6 +1,6 @@ import { space, system } from "@silverbulletmd/silverbullet/syscalls"; -import type { DocumentMeta } from "@silverbulletmd/silverbullet/types"; import { indexObjects } from "./api.ts"; +import type { DocumentMeta } from "../../type/index.ts"; // Note: clearFileIndex is not called but since this is the only attachmet:index listener, this should be fine (famous last words) export async function indexDocument(name: string) { diff --git a/plugs/index/header.ts b/plugs/index/header.ts index 6c071d78..c51afecf 100644 --- a/plugs/index/header.ts +++ b/plugs/index/header.ts @@ -3,16 +3,14 @@ import { collectNodesOfType, renderToText, } from "@silverbulletmd/silverbullet/lib/tree"; -import type { - CompleteEvent, - IndexTreeEvent, - ObjectValue, -} from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { indexObjects, queryLuaObjects } from "./api.ts"; import { parseRef } from "@silverbulletmd/silverbullet/lib/page_ref"; import { extractAttributes } from "@silverbulletmd/silverbullet/lib/attribute"; import { extractHashtag } from "../../plug-api/lib/tags.ts"; import { lua } from "@silverbulletmd/silverbullet/syscalls"; +import type { ObjectValue } from "../../type/index.ts"; +import type { CompleteEvent } from "@silverbulletmd/silverbullet/type/client"; type HeaderObject = ObjectValue< { diff --git a/plugs/index/item.ts b/plugs/index/item.ts index 3f3b48a0..c5bd7bbf 100644 --- a/plugs/index/item.ts +++ b/plugs/index/item.ts @@ -1,4 +1,4 @@ -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { findParentMatching, @@ -18,10 +18,11 @@ import { updateITags, } from "@silverbulletmd/silverbullet/lib/tags"; import { - extractFrontmatter, + extractFrontMatter, type FrontMatter, } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { deepClone } from "@silverbulletmd/silverbullet/lib/json"; +import type { ObjectValue } from "../../type/index.ts"; export type ItemObject = ObjectValue< { @@ -41,7 +42,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) { export async function extractItems(name: string, tree: ParseTree) { const items: ObjectValue[] = []; - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); await traverseTreeAsync(tree, async (n) => { if (n.type !== "ListItem") { diff --git a/plugs/index/lint.ts b/plugs/index/lint.ts index ececace0..896ade77 100644 --- a/plugs/index/lint.ts +++ b/plugs/index/lint.ts @@ -1,10 +1,13 @@ import { lua, YAML } from "@silverbulletmd/silverbullet/syscalls"; -import type { LintDiagnostic, LintEvent } from "../../plug-api/types.ts"; import { findNodeOfType, renderToText, traverseTreeAsync, } from "@silverbulletmd/silverbullet/lib/tree"; +import type { + LintDiagnostic, + LintEvent, +} from "@silverbulletmd/silverbullet/type/client"; export async function lintYAML({ tree }: LintEvent): Promise { const diagnostics: LintDiagnostic[] = []; diff --git a/plugs/index/page.ts b/plugs/index/page.ts index d88df442..477dc3ef 100644 --- a/plugs/index/page.ts +++ b/plugs/index/page.ts @@ -1,4 +1,4 @@ -import type { IndexTreeEvent } from "@silverbulletmd/silverbullet/types"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { editor, lua, @@ -7,8 +7,7 @@ import { YAML, } from "@silverbulletmd/silverbullet/syscalls"; -import type { LintDiagnostic, PageMeta } from "../../plug-api/types.ts"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { extractAttributes } from "@silverbulletmd/silverbullet/lib/attribute"; import { deleteObject, @@ -23,6 +22,8 @@ import { } from "@silverbulletmd/silverbullet/lib/tree"; import { updateITags } from "@silverbulletmd/silverbullet/lib/tags"; import type { AspiringPageObject } from "./page_links.ts"; +import type { PageMeta } from "../../type/index.ts"; +import type { LintDiagnostic } from "@silverbulletmd/silverbullet/type/client"; export async function indexPage({ name, tree }: IndexTreeEvent) { if (name.startsWith("_")) { @@ -30,7 +31,7 @@ export async function indexPage({ name, tree }: IndexTreeEvent) { return; } const pageMeta = await space.getPageMeta(name); - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); const toplevelAttributes = await extractAttributes(tree); // Push them all into the page object diff --git a/plugs/index/page_links.ts b/plugs/index/page_links.ts index 6b020bd5..3127c7d5 100644 --- a/plugs/index/page_links.ts +++ b/plugs/index/page_links.ts @@ -4,16 +4,13 @@ import { renderToText, traverseTree, } from "@silverbulletmd/silverbullet/lib/tree"; -import type { - IndexTreeEvent, - ObjectValue, -} from "@silverbulletmd/silverbullet/types"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { isLocalPath, resolvePath, } from "@silverbulletmd/silverbullet/lib/resolve"; import { indexObjects, queryLuaObjects } from "./api.ts"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { updateITags } from "@silverbulletmd/silverbullet/lib/tags"; import { looksLikePathWithExtension, @@ -25,6 +22,7 @@ import { wikiLinkRegex, } from "../../web/markdown_parser/constants.ts"; import { lua, space } from "@silverbulletmd/silverbullet/syscalls"; +import type { ObjectValue } from "../../type/index.ts"; export type LinkObject = ObjectValue< { @@ -67,7 +65,7 @@ export type AspiringPageObject = ObjectValue<{ export async function indexLinks({ name, tree }: IndexTreeEvent) { const links: ObjectValue[] = []; - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); const pageText = renderToText(tree); // If this is a meta template page, we don't want to index links diff --git a/plugs/index/paragraph.ts b/plugs/index/paragraph.ts index 9560c69b..b2c047bf 100644 --- a/plugs/index/paragraph.ts +++ b/plugs/index/paragraph.ts @@ -1,4 +1,4 @@ -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { indexObjects } from "./api.ts"; import { collectNodesOfType, @@ -8,8 +8,9 @@ import { } from "../../plug-api/lib/tree.ts"; import { extractAttributes } from "@silverbulletmd/silverbullet/lib/attribute"; import { updateITags } from "@silverbulletmd/silverbullet/lib/tags"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { extractHashtag } from "../../plug-api/lib/tags.ts"; +import type { ObjectValue } from "../../type/index.ts"; /** ParagraphObject An index object for the top level text nodes */ export type ParagraphObject = ObjectValue< @@ -23,7 +24,7 @@ export type ParagraphObject = ObjectValue< export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) { const objects: ParagraphObject[] = []; - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); await traverseTreeAsync(tree, async (p) => { if (p.type !== "Paragraph") { diff --git a/plugs/index/plug_api.ts b/plugs/index/plug_api.ts index a1a83817..7f280d22 100644 --- a/plugs/index/plug_api.ts +++ b/plugs/index/plug_api.ts @@ -1,5 +1,7 @@ -import type { KV, KvQuery, ObjectValue } from "../../plug-api/types.ts"; import { system } from "@silverbulletmd/silverbullet/syscalls"; +import type { ObjectValue } from "../../type/index.ts"; + +import type { KV, KvQuery } from "../../type/datastore.ts"; export function indexObjects( page: string, diff --git a/plugs/index/refactor.ts b/plugs/index/refactor.ts index fba5dccd..8bda898e 100644 --- a/plugs/index/refactor.ts +++ b/plugs/index/refactor.ts @@ -10,7 +10,6 @@ import { absoluteToRelativePath, folderName, } from "@silverbulletmd/silverbullet/lib/resolve"; -import type { ObjectValue } from "@silverbulletmd/silverbullet/types"; import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree"; import { addParentPointers, @@ -19,6 +18,7 @@ import { nodeAtPos, } from "@silverbulletmd/silverbullet/lib/tree"; import { queryLuaObjects } from "./api.ts"; +import type { ObjectValue } from "../../type/index.ts"; /** * Renames a single page. diff --git a/plugs/index/script.ts b/plugs/index/script.ts index 1bc5493b..d56c8e5a 100644 --- a/plugs/index/script.ts +++ b/plugs/index/script.ts @@ -1,6 +1,7 @@ -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { collectNodesOfType, findNodeOfType } from "../../plug-api/lib/tree.ts"; import { indexObjects } from "./api.ts"; +import type { ObjectValue } from "../../type/index.ts"; export type ScriptObject = ObjectValue<{ script: string; diff --git a/plugs/index/style.ts b/plugs/index/style.ts index be2acb2c..593f870c 100644 --- a/plugs/index/style.ts +++ b/plugs/index/style.ts @@ -1,6 +1,7 @@ -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { collectNodesOfType, findNodeOfType } from "../../plug-api/lib/tree.ts"; import { indexObjects } from "./api.ts"; +import type { ObjectValue } from "../../type/index.ts"; export type StyleObject = ObjectValue<{ style: string; diff --git a/plugs/index/table.ts b/plugs/index/table.ts index c1fbae19..68e5cf44 100644 --- a/plugs/index/table.ts +++ b/plugs/index/table.ts @@ -1,4 +1,4 @@ -import type { IndexTreeEvent, ObjectValue } from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { extractHashtag } from "../../plug-api/lib/tags.ts"; import { collectNodesMatching, @@ -6,6 +6,7 @@ import { type ParseTree, } from "@silverbulletmd/silverbullet/lib/tree"; import { indexObjects } from "./api.ts"; +import type { ObjectValue } from "../../type/index.ts"; type TableRowObject = & ObjectValue<{ diff --git a/plugs/index/tags.ts b/plugs/index/tags.ts index 7037789b..ec87b926 100644 --- a/plugs/index/tags.ts +++ b/plugs/index/tags.ts @@ -1,9 +1,5 @@ -import type { - CompleteEvent, - IndexTreeEvent, - ObjectValue, -} from "../../plug-api/types.ts"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import type { IndexTreeEvent } from "../../type/event.ts"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { indexObjects, queryLuaObjects } from "./api.ts"; import { addParentPointers, @@ -11,6 +7,8 @@ import { findParentMatching, } from "@silverbulletmd/silverbullet/lib/tree"; import { extractHashtag, renderHashtag } from "../../plug-api/lib/tags.ts"; +import type { ObjectValue } from "../../type/index.ts"; +import type { CompleteEvent } from "@silverbulletmd/silverbullet/type/client"; export type TagObject = ObjectValue<{ name: string; @@ -21,7 +19,7 @@ export type TagObject = ObjectValue<{ export async function indexTags({ name, tree }: IndexTreeEvent) { const tags = new Set(); // name:parent addParentPointers(tree); - const pageTags: string[] = (await extractFrontmatter(tree)).tags || []; + const pageTags: string[] = (await extractFrontMatter(tree)).tags || []; for (const pageTag of pageTags) { tags.add(`${pageTag}:page`); } diff --git a/plugs/search/search.ts b/plugs/search/search.ts index 6302fc67..44aac425 100644 --- a/plugs/search/search.ts +++ b/plugs/search/search.ts @@ -2,7 +2,7 @@ import type { IndexTreeEvent, PageCreatingContent, PageCreatingEvent, -} from "../../plug-api/types.ts"; +} from "../../type/event.ts"; import { renderToText } from "@silverbulletmd/silverbullet/lib/tree"; import { editor } from "@silverbulletmd/silverbullet/syscalls"; import { ftsIndexPage, ftsSearch } from "./engine.ts"; diff --git a/plugs/tasks/complete.ts b/plugs/tasks/complete.ts index 51e869b9..d66799ec 100644 --- a/plugs/tasks/complete.ts +++ b/plugs/tasks/complete.ts @@ -1,6 +1,6 @@ -import type { CompleteEvent } from "../../plug-api/types.ts"; import { queryLuaObjects } from "../index/api.ts"; import type { TaskStateObject } from "./task.ts"; +import type { CompleteEvent } from "@silverbulletmd/silverbullet/type/client"; export async function completeTaskState(completeEvent: CompleteEvent) { const taskMatch = /([\-\*]\s+\[)([^\[\]]+)$/.exec( diff --git a/plugs/tasks/task.ts b/plugs/tasks/task.ts index 5164710d..4051c9a6 100644 --- a/plugs/tasks/task.ts +++ b/plugs/tasks/task.ts @@ -1,8 +1,4 @@ -import type { - ClickEvent, - IndexTreeEvent, - ObjectValue, -} from "../../plug-api/types.ts"; +import type { IndexTreeEvent } from "../../type/event.ts"; import { editor, @@ -36,7 +32,7 @@ import { extractHashTags, updateITags, } from "@silverbulletmd/silverbullet/lib/tags"; -import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; +import { extractFrontMatter } from "@silverbulletmd/silverbullet/lib/frontmatter"; import { parseRef, positionOfLine, @@ -44,6 +40,8 @@ import { import { enrichItemFromParents } from "../index/item.ts"; import { deepClone } from "@silverbulletmd/silverbullet/lib/json"; import { queryLuaObjects } from "../index/api.ts"; +import type { ObjectValue } from "../../type/index.ts"; +import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client"; export type TaskObject = ObjectValue< { @@ -76,7 +74,7 @@ export async function extractTasks( ): Promise { const tasks: ObjectValue[] = []; const taskStates = new Map(); - const frontmatter = await extractFrontmatter(tree); + const frontmatter = await extractFrontMatter(tree); await traverseTreeAsync(tree, async (n) => { if (n.type !== "Task") { diff --git a/scripts/generate_fs_list.ts b/scripts/generate_fs_list.ts index a4999fbc..95ccc38f 100644 --- a/scripts/generate_fs_list.ts +++ b/scripts/generate_fs_list.ts @@ -1,7 +1,8 @@ import { walk } from "@std/fs/walk"; import { resolve } from "@std/path"; import { mime } from "mimetypes"; -import type { FileMeta } from "../plug-api/types.ts"; + +import type { FileMeta } from "../type/index.ts"; const rootDir = resolve("website_build"); diff --git a/server/crypto.ts b/server/crypto.ts index 1c4b172d..34fd5b7a 100644 --- a/server/crypto.ts +++ b/server/crypto.ts @@ -1,6 +1,7 @@ import { create, getNumericDate, verify } from "djwt"; import type { KvPrimitives } from "../lib/data/kv_primitives.ts"; -import type { KvKey } from "@silverbulletmd/silverbullet/types"; + +import type { KvKey } from "../type/datastore.ts"; const jwtSecretKey: KvKey = ["jwtSecretKey"]; diff --git a/server/http_server.ts b/server/http_server.ts index 3ae9f640..6dda7122 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -2,7 +2,6 @@ import { type Context, Hono } from "hono"; import { deleteCookie, getCookie, setCookie } from "hono/cookie"; import { validator } from "hono/validator"; import type { AssetBundle } from "../lib/asset_bundle/bundle.ts"; -import type { FileMeta } from "@silverbulletmd/silverbullet/types"; import { handleShellEndpoint } from "./shell_endpoint.ts"; import type { KvPrimitives } from "../lib/data/kv_primitives.ts"; import { compile as gitIgnoreCompiler } from "gitignore-parser"; @@ -25,6 +24,7 @@ import { type ShellBackend, } from "./shell_backend.ts"; import { CONFIG_TEMPLATE, INDEX_TEMPLATE } from "../web/PAGE_TEMPLATES.ts"; +import type { FileMeta } from "../type/index.ts"; const authenticationExpirySeconds = 60 * 60 * 24 * 7; // 1 week diff --git a/server/shell_backend.ts b/server/shell_backend.ts index b518a996..515a853a 100644 --- a/server/shell_backend.ts +++ b/server/shell_backend.ts @@ -1,66 +1,66 @@ -import type {ShellRequest, ShellResponse} from "../type/rpc.ts"; -import type {ServerOptions} from "./http_server.ts"; +import type { ShellRequest, ShellResponse } from "../type/rpc.ts"; +import type { ServerOptions } from "./http_server.ts"; /** * Configuration via environment variables: * - SB_SHELL_BACKEND: "local" or "off" */ export function determineShellBackend( - serverOptions: ServerOptions, + serverOptions: ServerOptions, ): ShellBackend { - const backendConfig = Deno.env.get("SB_SHELL_BACKEND") || "local"; - switch (backendConfig) { - case "local": - return new LocalShell(serverOptions.pagesPath); - default: - console.info( - "Running in shellless mode, meaning shell commands are disabled", - ); - return new NotSupportedShell(); - } + const backendConfig = Deno.env.get("SB_SHELL_BACKEND") || "local"; + switch (backendConfig) { + case "local": + return new LocalShell(serverOptions.pagesPath); + default: + console.info( + "Running in shellless mode, meaning shell commands are disabled", + ); + return new NotSupportedShell(); + } } export interface ShellBackend { - handle(shellRequest: ShellRequest): Promise; + handle(shellRequest: ShellRequest): Promise; } export class NotSupportedShell implements ShellBackend { - handle(): Promise { - return Promise.resolve({ - stdout: "", - stderr: "Not supported", - code: 1, - }); - } + handle(): Promise { + return Promise.resolve({ + stdout: "", + stderr: "Not supported", + code: 1, + }); + } } export class LocalShell implements ShellBackend { - constructor(private cwd: string) { + constructor(private cwd: string) { + } + + async handle(shellRequest: ShellRequest): Promise { + console.log( + "Running shell command:", + shellRequest.cmd, + shellRequest.args, + ); + const p = new Deno.Command(shellRequest.cmd, { + cwd: this.cwd, + args: shellRequest.args, + stdout: "piped", + stderr: "piped", + }); + const output = await p.output(); + const stdout = new TextDecoder().decode(output.stdout); + const stderr = new TextDecoder().decode(output.stderr); + if (output.code !== 0) { + console.error("Error running shell command", stdout, stderr); } - async handle(shellRequest: ShellRequest): Promise { - console.log( - "Running shell command:", - shellRequest.cmd, - shellRequest.args, - ); - const p = new Deno.Command(shellRequest.cmd, { - cwd: this.cwd, - args: shellRequest.args, - stdout: "piped", - stderr: "piped", - }); - const output = await p.output(); - const stdout = new TextDecoder().decode(output.stdout); - const stderr = new TextDecoder().decode(output.stderr); - if (output.code !== 0) { - console.error("Error running shell command", stdout, stderr); - } - - return { - stderr, - stdout, - code: output.code, - }; - } + return { + stderr, + stdout, + code: output.code, + }; + } } diff --git a/server/util.ts b/server/util.ts index 3d53b22e..50af7774 100644 --- a/server/util.ts +++ b/server/util.ts @@ -1,7 +1,7 @@ export function utcDateString(mtime: number): string { - return new Date(mtime).toUTCString(); + return new Date(mtime).toUTCString(); } export function authCookieName(host: string) { - return `auth_${host.replaceAll(/\W/g, "_")}`; -} \ No newline at end of file + return `auth_${host.replaceAll(/\W/g, "_")}`; +} diff --git a/type/client.ts b/type/client.ts index ec47929a..be418dcc 100644 --- a/type/client.ts +++ b/type/client.ts @@ -1,4 +1,5 @@ -// Used by FilterBox +import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree"; + export type FilterOption = { name: string; description?: string; @@ -17,27 +18,110 @@ export type Notification = { export type PanelMode = number; -export type EmojiConfig = { - aliases: string[][]; +export type CodeWidgetContent = { + html: string; + script?: string; + buttons?: CodeWidgetButton[]; }; -export type SmartQuotesConfig = { - enabled?: boolean; - double?: { left?: string; right?: string }; - single?: { left?: string; right?: string }; +export type CodeWidgetButton = { + widgetTarget?: boolean; + description: string; + svg: string; + invokeFunction: string[]; }; -type vimMode = "normal" | "insert" | "visual"; - -export type VimConfig = { - unmap?: (string | { key: string; mode?: vimMode })[]; - map?: { map: string; to: string; mode?: vimMode }[]; - noremap?: { map: string; to: string; mode?: vimMode }[]; - commands?: { ex: string; command: string }[]; +// Document editors stuff +export type DocumentEditorCallback = () => Promise; +export type DocumentEditorContent = { + html: string; + script?: string; }; -export type QueryCollationConfig = { - enabled?: boolean; - locale?: string; - options?: object; +export type LintDiagnostic = { + from: number; + to: number; + severity: "error" | "warning" | "info" | "hint"; + message: string; }; + +export type UploadFile = { + name: string; + 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:pageSaving" + | "editor:pageSaved" + | "editor:pageCreating" + | "editor:pageModified" + | "editor:documentSaving" + | "editor:documentSaved" + | "editor:modeswitch" + | "plugs:loaded" + | "cron:secondPassed" + | "hooks:renderTopWidgets" + | "hooks:renderBottomWidgets"; + +export type ClickEvent = { + page: string; + pos: number; + metaKey: boolean; + ctrlKey: boolean; + altKey: boolean; +}; + +export type EnrichedClickEvent = ClickEvent & { + parentNodes: string[]; +}; + +export type LintEvent = { + name: string; + tree: ParseTree; +}; + +export type CompleteEvent = { + pageName: string; + linePrefix: string; + pos: number; + parentNodes: string[]; +}; + +export type SlashCompletionOption = { + label: string; + detail?: string; + invoke: string; + order?: number; +} & Record; + +export type SlashCompletions = { + // Ignore this one, only for compatibility with regular completions + from?: number; + // The actual completions + options: SlashCompletionOption[]; +}; + +export type WidgetContent = { + html?: string; + script?: string; + markdown?: string; + url?: string; + height?: number; + width?: number; +}; + +// Code widget stuff +export type CodeWidgetCallback = ( + bodyText: string, + pageName: string, +) => Promise; diff --git a/type/command.ts b/type/command.ts new file mode 100644 index 00000000..550f4680 --- /dev/null +++ b/type/command.ts @@ -0,0 +1,15 @@ +import type { CommandDef, SlashCommandDef } from "../lib/manifest.ts"; + +import type { SlashCompletions } from "@silverbulletmd/silverbullet/type/client"; + +export type Command = CommandDef & { + run?: (args?: any[]) => Promise; +}; + +export type SlashCommand = SlashCommandDef & { + run: (...args: any[]) => Promise; +}; + +export type CommandHookEvents = { + commandsUpdated(commands: Map): void; +}; diff --git a/type/config.ts b/type/config.ts new file mode 100644 index 00000000..9a0ae456 --- /dev/null +++ b/type/config.ts @@ -0,0 +1,22 @@ +export type EmojiConfig = { + aliases: string[][]; +}; +export type QueryCollationConfig = { + enabled?: boolean; + locale?: string; + options?: object; +}; + +type vimMode = "normal" | "insert" | "visual"; + +export type VimConfig = { + unmap?: (string | { key: string; mode?: vimMode })[]; + map?: { map: string; to: string; mode?: vimMode }[]; + noremap?: { map: string; to: string; mode?: vimMode }[]; + commands?: { ex: string; command: string }[]; +}; +export type SmartQuotesConfig = { + enabled?: boolean; + double?: { left?: string; right?: string }; + single?: { left?: string; right?: string }; +}; diff --git a/type/datastore.ts b/type/datastore.ts new file mode 100644 index 00000000..c8960cde --- /dev/null +++ b/type/datastore.ts @@ -0,0 +1,28 @@ +// Message Queue related types +export type MQMessage = { + id: string; + queue: string; + body: any; + retries?: number; +}; +export type MQStats = { + queued: number; + processing: number; + dlq: number; +}; +export type MQSubscribeOptions = { + batchSize?: number; + pollInterval?: number; +}; + +// KV types +export type KvKey = string[]; + +export type KV = { + key: KvKey; + value: T; +}; + +export type KvQuery = { + prefix?: KvKey; +}; diff --git a/type/event.ts b/type/event.ts new file mode 100644 index 00000000..bc4c8846 --- /dev/null +++ b/type/event.ts @@ -0,0 +1,24 @@ +import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree"; +import type { EventSubscriptionDef } from "../lib/manifest.ts"; + +export type IndexEvent = { + name: string; + text: string; +}; + +export type IndexTreeEvent = { + name: string; + tree: ParseTree; +}; + +export type PageCreatingEvent = { + name: string; +}; + +export type PageCreatingContent = { + text: string; + perm: "ro" | "rw"; +}; +export type EventSubscription = EventSubscriptionDef & { + run: (...args: any[]) => Promise; +}; diff --git a/type/index.ts b/type/index.ts new file mode 100644 index 00000000..e53aeb1c --- /dev/null +++ b/type/index.ts @@ -0,0 +1,56 @@ +export type FileMeta = { + name: string; + created: number; + lastModified: number; + contentType: string; + size: number; + perm: "ro" | "rw"; + noSync?: boolean; +}; +/** + * Decorates a page when it matches certain criteria + */ +export type PageDecoration = { + prefix?: string; + cssClasses?: string[]; + hide?: boolean; + renderWidgets?: boolean; // Defaults to true +}; +export type PageMeta = ObjectValue< + { + name: string; + created: string; // indexing it as a string + lastModified: string; // indexing it as a string + perm: "ro" | "rw"; + lastOpened?: number; + pageDecoration?: PageDecoration; + } & Record +>; +export type DocumentMeta = ObjectValue< + { + name: string; + contentType: string; + created: string; + lastModified: string; + size: number; + perm: "ro" | "rw"; + extension: string; + } & Record +>; +export type SyscallMeta = { + name: string; + requiredPermissions: string[]; + argCount: number; +}; +/** + * An ObjectValue that can be indexed by the `index` plug, needs to have a minimum of + * of two fields: + * - ref: a unique reference (id) for the object, ideally a page reference + * - tags: a list of tags that the object belongs to + */ +export type ObjectValue = { + ref: string; + tag: string; // main tag + tags?: string[]; + itags?: string[]; // implicit or inherited tags (inherited from the page for instance) +} & T; diff --git a/web/client.ts b/web/client.ts index e0895c5e..412083ff 100644 --- a/web/client.ts +++ b/web/client.ts @@ -8,9 +8,17 @@ import { syntaxTree } from "@codemirror/language"; import { history, isolateHistory } from "@codemirror/commands"; import type { SyntaxNode } from "@lezer/common"; import { Space } from "./space.ts"; -import type { FilterOption } from "@silverbulletmd/silverbullet/type/client"; +import type { + AppEvent, + ClickEvent, + CodeWidgetButton, + CompleteEvent, + EnrichedClickEvent, + FilterOption, + SlashCompletions, +} from "@silverbulletmd/silverbullet/type/client"; import { EventHook } from "./hooks/event.ts"; -import { type Command, isValidEditor } from "../lib/command.ts"; +import type { Command } from "../type/command.ts"; import { type LocationState, parseRefFromURI, @@ -19,16 +27,7 @@ import { import type { AppViewState } from "./ui_types.ts"; -import type { - AppEvent, - ClickEvent, - CompleteEvent, - DocumentMeta, - EnrichedClickEvent, - PageCreatingContent, - PageCreatingEvent, - SlashCompletions, -} from "@silverbulletmd/silverbullet/types"; +import type { PageCreatingContent, PageCreatingEvent } from "../type/event.ts"; import type { StyleObject } from "../plugs/index/style.ts"; import { throttle } from "../lib/async.ts"; import { PlugSpacePrimitives } from "../lib/spaces/plug_space_primitives.ts"; @@ -46,15 +45,10 @@ import { validatePath, } from "@silverbulletmd/silverbullet/lib/page_ref"; import { ClientSystem } from "./client_system.ts"; -import { createEditorState } from "./editor_state.ts"; +import { createEditorState, isValidEditor } from "./editor_state.ts"; import { MainUI } from "./editor_ui.tsx"; import { cleanPageRef } from "@silverbulletmd/silverbullet/lib/resolve"; import type { SpacePrimitives } from "../lib/spaces/space_primitives.ts"; -import type { - CodeWidgetButton, - FileMeta, - PageMeta, -} from "@silverbulletmd/silverbullet/types"; import { DataStore } from "../lib/data/datastore.ts"; import { IndexedDBKvPrimitives } from "../lib/data/indexeddb_kv_primitives.ts"; import { DataStoreMQ } from "../lib/data/mq.datastore.ts"; @@ -67,6 +61,7 @@ import { diffAndPrepareChanges } from "./cm_util.ts"; import { DocumentEditor } from "./document_editor.ts"; import { parseExpressionString } from "../lib/space_lua/parse.ts"; import { Config } from "./config.ts"; +import type { DocumentMeta, FileMeta, PageMeta } from "../type/index.ts"; const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/; diff --git a/web/client_system.ts b/web/client_system.ts index 5296e966..53b2a94a 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -42,7 +42,7 @@ import { configSyscalls } from "./syscalls/config.ts"; import { eventListenerSyscalls } from "./syscalls/event.ts"; import { DocumentEditorHook } from "./hooks/document_editor.ts"; import type { LuaCollectionQuery } from "../lib/space_lua/query_collection.ts"; -import type { Command } from "../lib/command.ts"; +import type { Command } from "../type/command.ts"; import { SpaceLuaEnvironment } from "./space_lua.ts"; import { type ILuaFunction, diff --git a/web/cm_plugins/clean.ts b/web/cm_plugins/clean.ts index ad3c36f4..22937424 100644 --- a/web/cm_plugins/clean.ts +++ b/web/cm_plugins/clean.ts @@ -1,4 +1,3 @@ -import type { ClickEvent } from "../../plug-api/types.ts"; import type { Extension } from "@codemirror/state"; import type { Client } from "../client.ts"; import { blockquotePlugin } from "./block_quote.ts"; @@ -15,6 +14,7 @@ import { frontmatterPlugin } from "./frontmatter.ts"; import { cleanEscapePlugin } from "./escapes.ts"; import { luaDirectivePlugin } from "./lua_directive.ts"; import { hashtagPlugin } from "./hashtag.ts"; +import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client"; export function cleanModePlugins(client: Client) { return [ diff --git a/web/cm_plugins/editor_paste.ts b/web/cm_plugins/editor_paste.ts index fbaaeb82..493ce524 100644 --- a/web/cm_plugins/editor_paste.ts +++ b/web/cm_plugins/editor_paste.ts @@ -1,7 +1,6 @@ import { syntaxTree } from "@codemirror/language"; import { EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view"; import type { Client } from "../client.ts"; -import type { UploadFile } from "@silverbulletmd/silverbullet/types"; // We use turndown to convert HTML to Markdown import TurndownService from "turndown"; @@ -18,6 +17,7 @@ import { maximumDocumentSize } from "../constants.ts"; import { safeRun } from "../../lib/async.ts"; import { resolvePath } from "@silverbulletmd/silverbullet/lib/resolve"; import { localDateString } from "../../lib/dates.ts"; +import type { UploadFile } from "@silverbulletmd/silverbullet/type/client"; const turndownService = new TurndownService({ hr: "---", diff --git a/web/cm_plugins/iframe_widget.ts b/web/cm_plugins/iframe_widget.ts index 888a74c5..8f17a330 100644 --- a/web/cm_plugins/iframe_widget.ts +++ b/web/cm_plugins/iframe_widget.ts @@ -1,10 +1,10 @@ -import type { - CodeWidgetCallback, - WidgetContent, -} from "../../plug-api/types.ts"; import { WidgetType } from "@codemirror/view"; import type { Client } from "../client.ts"; import { createWidgetSandboxIFrame } from "../components/widget_sandbox_iframe.ts"; +import type { + CodeWidgetCallback, + WidgetContent, +} from "@silverbulletmd/silverbullet/type/client"; export class IFrameWidget extends WidgetType { iframe?: HTMLIFrameElement; diff --git a/web/cm_plugins/lint.ts b/web/cm_plugins/lint.ts index 1df4da8a..78f09631 100644 --- a/web/cm_plugins/lint.ts +++ b/web/cm_plugins/lint.ts @@ -1,8 +1,8 @@ import { type Diagnostic, linter } from "@codemirror/lint"; import type { Client } from "../client.ts"; import { parse } from "../markdown_parser/parse_tree.ts"; -import type { LintEvent } from "../../plug-api/types.ts"; import { extendedMarkdownLanguage } from "../markdown_parser/parser.ts"; +import type { LintEvent } from "@silverbulletmd/silverbullet/type/client"; export function plugLinter(client: Client) { return linter(async (view): Promise => { diff --git a/web/cm_plugins/lua_directive.ts b/web/cm_plugins/lua_directive.ts index fd2081f3..1dc725dc 100644 --- a/web/cm_plugins/lua_directive.ts +++ b/web/cm_plugins/lua_directive.ts @@ -23,8 +23,8 @@ import { import { encodeRef } from "@silverbulletmd/silverbullet/lib/page_ref"; import { resolveASTReference } from "../space_lua.ts"; import { LuaWidget } from "./lua_widget.ts"; -import type { PageMeta } from "@silverbulletmd/silverbullet/types"; import YAML from "js-yaml"; +import type { PageMeta } from "../../type/index.ts"; export function luaDirectivePlugin(client: Client) { return decoratorStateField((state: EditorState) => { diff --git a/web/cm_plugins/smart_quotes.ts b/web/cm_plugins/smart_quotes.ts index af7a9043..3bec3ea7 100644 --- a/web/cm_plugins/smart_quotes.ts +++ b/web/cm_plugins/smart_quotes.ts @@ -2,7 +2,8 @@ import type { KeyBinding } from "@codemirror/view"; import { syntaxTree } from "@codemirror/language"; import { EditorSelection } from "@codemirror/state"; import type { Client } from "../client.ts"; -import type { SmartQuotesConfig } from "@silverbulletmd/silverbullet/type/client"; + +import type { SmartQuotesConfig } from "../../type/config.ts"; const straightQuoteContexts = [ "CommentBlock", diff --git a/web/cm_plugins/util.ts b/web/cm_plugins/util.ts index 61f7e5c2..8000a663 100644 --- a/web/cm_plugins/util.ts +++ b/web/cm_plugins/util.ts @@ -9,7 +9,8 @@ import { import type { DecorationSet } from "@codemirror/view"; import { Decoration, EditorView, WidgetType } from "@codemirror/view"; import type { Client } from "../client.ts"; -import type { PageMeta } from "@silverbulletmd/silverbullet/types"; + +import type { PageMeta } from "../../type/index.ts"; type LinkOptions = { text: string; diff --git a/web/cm_plugins/wiki_link.ts b/web/cm_plugins/wiki_link.ts index c7fead3b..508ce930 100644 --- a/web/cm_plugins/wiki_link.ts +++ b/web/cm_plugins/wiki_link.ts @@ -1,4 +1,3 @@ -import type { ClickEvent } from "@silverbulletmd/silverbullet/types"; import { syntaxTree } from "@codemirror/language"; import { Decoration } from "@codemirror/view"; import type { Client } from "../client.ts"; @@ -12,6 +11,7 @@ import { encodeRef, parseRef, } from "@silverbulletmd/silverbullet/lib/page_ref"; +import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client"; /** * Plugin to hide path prefix when the cursor is not inside. diff --git a/web/components/command_palette.tsx b/web/components/command_palette.tsx index 58aee54f..a3e66240 100644 --- a/web/components/command_palette.tsx +++ b/web/components/command_palette.tsx @@ -4,7 +4,7 @@ import type { CompletionResult, } from "@codemirror/autocomplete"; import { Terminal } from "preact-feather"; -import type { Command } from "../../lib/command.ts"; +import type { Command } from "../../type/command.ts"; import type { FilterOption } from "@silverbulletmd/silverbullet/type/client"; export function CommandPalette({ diff --git a/web/components/page_navigator.tsx b/web/components/page_navigator.tsx index 905abd04..98c0239f 100644 --- a/web/components/page_navigator.tsx +++ b/web/components/page_navigator.tsx @@ -4,12 +4,9 @@ import type { CompletionContext, CompletionResult, } from "@codemirror/autocomplete"; -import type { - DocumentMeta, - PageMeta, -} from "@silverbulletmd/silverbullet/types"; import { tagRegex as mdTagRegex } from "../markdown_parser/constants.ts"; import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags"; +import type { DocumentMeta, PageMeta } from "../../type/index.ts"; const tagRegex = new RegExp(mdTagRegex.source, "g"); diff --git a/web/components/widget_sandbox_iframe.ts b/web/components/widget_sandbox_iframe.ts index ce3785b3..54515124 100644 --- a/web/components/widget_sandbox_iframe.ts +++ b/web/components/widget_sandbox_iframe.ts @@ -1,6 +1,6 @@ -import type { WidgetContent } from "../../plug-api/types.ts"; import type { Client } from "../client.ts"; import { panelHtml } from "./panel_html.ts"; +import type { WidgetContent } from "@silverbulletmd/silverbullet/type/client"; /** * Implements sandbox widgets using iframe with a pooling mechanism to speed up loading diff --git a/web/document_editor.ts b/web/document_editor.ts index 75b6cc2d..3993d3c1 100644 --- a/web/document_editor.ts +++ b/web/document_editor.ts @@ -1,7 +1,7 @@ -import type { DocumentMeta } from "@silverbulletmd/silverbullet/types"; import type { Client } from "./client.ts"; import { html as skeleton } from "./document_editor_skeleton.ts"; import { timeout } from "../lib/async.ts"; +import type { DocumentMeta } from "../type/index.ts"; export class DocumentEditor { iframe!: HTMLIFrameElement; diff --git a/web/editor_state.ts b/web/editor_state.ts index 6e067776..695ee43c 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -39,7 +39,6 @@ import { inlineContentPlugin } from "./cm_plugins/inline_content.ts"; import { cleanModePlugins } from "./cm_plugins/clean.ts"; import { lineWrapper } from "./cm_plugins/line_wrapper.ts"; import { createSmartQuoteKeyBindings } from "./cm_plugins/smart_quotes.ts"; -import type { ClickEvent } from "../plug-api/types.ts"; import { documentExtension, pasteLinkExtension, @@ -52,7 +51,7 @@ import { extendedMarkdownLanguage } from "./markdown_parser/parser.ts"; import { safeRun } from "../lib/async.ts"; import { codeCopyPlugin } from "./cm_plugins/code_copy.ts"; import { disableSpellcheck } from "./cm_plugins/spell_checking.ts"; -import { isValidEditor } from "../lib/command.ts"; +import type { ClickEvent } from "@silverbulletmd/silverbullet/type/client"; export function createEditorState( client: Client, @@ -301,6 +300,19 @@ export function createEditorState( }); } +// TODO: Move this elsewhere +export function isValidEditor( + currentEditor: string | undefined, + requiredEditor: string | undefined, +): boolean { + return (requiredEditor === undefined) || + (currentEditor === undefined && + requiredEditor === "page") || + (requiredEditor === "any") || + (currentEditor === requiredEditor) || + (currentEditor !== undefined && requiredEditor === "notpage"); +} + export function createCommandKeyBindings(client: Client): KeyBinding[] { const commandKeyBindings: KeyBinding[] = []; diff --git a/web/hooks/code_widget.ts b/web/hooks/code_widget.ts index 0cf78cae..635d7645 100644 --- a/web/hooks/code_widget.ts +++ b/web/hooks/code_widget.ts @@ -1,7 +1,7 @@ import type { Hook, Manifest } from "../../lib/plugos/types.ts"; import type { System } from "../../lib/plugos/system.ts"; -import type { CodeWidgetCallback } from "../../plug-api/types.ts"; import type { CodeWidgetT } from "../../lib/manifest.ts"; +import type { CodeWidgetCallback } from "@silverbulletmd/silverbullet/type/client"; export class CodeWidgetHook implements Hook { codeWidgetCallbacks = new Map(); diff --git a/web/hooks/command.ts b/web/hooks/command.ts index 90056d36..1f296fa3 100644 --- a/web/hooks/command.ts +++ b/web/hooks/command.ts @@ -2,7 +2,7 @@ import type { Hook, Manifest } from "../../lib/plugos/types.ts"; import type { System } from "../../lib/plugos/system.ts"; import { EventEmitter } from "../../lib/plugos/event.ts"; import { throttle } from "../../lib/async.ts"; -import type { Command, CommandHookEvents } from "../../lib/command.ts"; +import type { Command, CommandHookEvents } from "../../type/command.ts"; import type { CommandHookT } from "../../lib/manifest.ts"; export class CommandHook extends EventEmitter diff --git a/web/hooks/document_editor.ts b/web/hooks/document_editor.ts index 1d5f3ca8..7055795d 100644 --- a/web/hooks/document_editor.ts +++ b/web/hooks/document_editor.ts @@ -1,7 +1,7 @@ import type { Hook, Manifest } from "../../lib/plugos/types.ts"; import type { DocumentEditorT } from "../../lib/manifest.ts"; -import type { DocumentEditorCallback } from "@silverbulletmd/silverbullet/types"; import type { System } from "../../lib/plugos/system.ts"; +import type { DocumentEditorCallback } from "@silverbulletmd/silverbullet/type/client"; export class DocumentEditorHook implements Hook { documentEditors = new Map< diff --git a/web/hooks/slash_command.ts b/web/hooks/slash_command.ts index 20abcc19..bcb165bf 100644 --- a/web/hooks/slash_command.ts +++ b/web/hooks/slash_command.ts @@ -7,13 +7,13 @@ import type { } from "@codemirror/autocomplete"; import type { Client } from "../client.ts"; import { syntaxTree } from "@codemirror/language"; +import { safeRun, throttle } from "../../lib/async.ts"; +import type { SlashCommandHookT } from "../../lib/manifest.ts"; +import type { SlashCommand } from "../../type/command.ts"; import type { SlashCompletionOption, SlashCompletions, -} from "../../plug-api/types.ts"; -import { safeRun, throttle } from "../../lib/async.ts"; -import type { SlashCommandHookT } from "../../lib/manifest.ts"; -import type { SlashCommand } from "../../lib/command.ts"; +} from "@silverbulletmd/silverbullet/type/client"; const slashCommandRegexp = /([^\w:]|^)\/[\w#\-]*/; diff --git a/web/markdown/markdown_render.ts b/web/markdown/markdown_render.ts index 98020440..a927d360 100644 --- a/web/markdown/markdown_render.ts +++ b/web/markdown/markdown_render.ts @@ -10,9 +10,9 @@ import { import { encodeRef, parseRef } from "@silverbulletmd/silverbullet/lib/page_ref"; import { Fragment, renderHtml, type Tag } from "./html_render.ts"; import { isLocalPath } from "@silverbulletmd/silverbullet/lib/resolve"; -import type { PageMeta } from "@silverbulletmd/silverbullet/types"; import * as TagConstants from "../../plugs/index/constants.ts"; import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags"; +import type { PageMeta } from "../../type/index.ts"; export type MarkdownRenderOptions = { failOnUnknown?: true; diff --git a/web/reducer.ts b/web/reducer.ts index a9da973c..fbec0a70 100644 --- a/web/reducer.ts +++ b/web/reducer.ts @@ -1,5 +1,5 @@ -import type { PageMeta } from "../plug-api/types.ts"; import type { Action, AppViewState } from "./ui_types.ts"; +import type { PageMeta } from "../type/index.ts"; export default function reducer( state: AppViewState, diff --git a/web/space.ts b/web/space.ts index 5248c4ee..c093f985 100644 --- a/web/space.ts +++ b/web/space.ts @@ -1,10 +1,10 @@ import { plugPrefix } from "../lib/spaces/constants.ts"; -import type { DocumentMeta, FileMeta, PageMeta } from "../plug-api/types.ts"; import type { EventHook } from "../web/hooks/event.ts"; import { safeRun } from "../lib/async.ts"; import { localDateString } from "../lib/dates.ts"; import type { EventedSpacePrimitives } from "../lib/spaces/evented_space_primitives.ts"; +import type { DocumentMeta, FileMeta, PageMeta } from "../type/index.ts"; const pageWatchInterval = 5000; diff --git a/web/syscalls/clientStore.ts b/web/syscalls/clientStore.ts index 86a8a719..ede34fdd 100644 --- a/web/syscalls/clientStore.ts +++ b/web/syscalls/clientStore.ts @@ -1,6 +1,7 @@ import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { DataStore } from "../../lib/data/datastore.ts"; -import type { KvKey } from "../../plug-api/types.ts"; + +import type { KvKey } from "../../type/datastore.ts"; export function clientStoreSyscalls( ds: DataStore, diff --git a/web/syscalls/code_widget.ts b/web/syscalls/code_widget.ts index ca5af768..e16fba49 100644 --- a/web/syscalls/code_widget.ts +++ b/web/syscalls/code_widget.ts @@ -1,6 +1,6 @@ -import type { CodeWidgetContent } from "../../plug-api/types.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { CodeWidgetHook } from "../hooks/code_widget.ts"; +import type { CodeWidgetContent } from "@silverbulletmd/silverbullet/type/client"; export function codeWidgetSyscalls( codeWidgetHook: CodeWidgetHook, diff --git a/web/syscalls/datastore.ts b/web/syscalls/datastore.ts index d34b9a68..4c9a5947 100644 --- a/web/syscalls/datastore.ts +++ b/web/syscalls/datastore.ts @@ -2,7 +2,6 @@ import { type LuaCollectionQuery, queryLua, } from "../../lib/space_lua/query_collection.ts"; -import type { KV, KvKey } from "../../plug-api/types.ts"; import type { DataStore } from "../../lib/data/datastore.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; import { @@ -14,6 +13,8 @@ import { import type { KvQueryOptions } from "../../lib/data/kv_primitives.ts"; import type { ClientSystem } from "../client_system.ts"; +import type { KV, KvKey } from "../../type/datastore.ts"; + /** * Exposes the datastore API to plugs, but scoping everything to a prefix based on the plug's name * @param ds the datastore to wrap diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index b4c46cb9..86ffc69f 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -21,12 +21,13 @@ import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { FilterOption, - VimConfig, + UploadFile, } from "@silverbulletmd/silverbullet/type/client"; -import type { PageMeta, UploadFile } from "../../plug-api/types.ts"; import { openSearchPanel } from "@codemirror/search"; import { parseRef, type Ref } from "@silverbulletmd/silverbullet/lib/page_ref"; import { insertNewlineContinueMarkup } from "@codemirror/lang-markdown"; +import type { VimConfig } from "../../type/config.ts"; +import type { PageMeta } from "../../type/index.ts"; export function editorSyscalls(client: Client): SysCallMapping { const syscalls: SysCallMapping = { diff --git a/web/syscalls/event.ts b/web/syscalls/event.ts index e2304e80..c0d8036f 100644 --- a/web/syscalls/event.ts +++ b/web/syscalls/event.ts @@ -2,7 +2,8 @@ import type { SysCallMapping } from "../../lib/plugos/system.ts"; import { LuaStackFrame, luaValueToJS } from "../../lib/space_lua/runtime.ts"; import type { Client } from "../client.ts"; -import type { EventSubscription } from "../../lib/event.ts"; + +import type { EventSubscription } from "../../type/event.ts"; export function eventListenerSyscalls( client: Client, diff --git a/web/syscalls/space.ts b/web/syscalls/space.ts index 9bab3cc1..70aaca9a 100644 --- a/web/syscalls/space.ts +++ b/web/syscalls/space.ts @@ -1,6 +1,7 @@ import type { Client } from "../client.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; -import type { DocumentMeta, FileMeta, PageMeta } from "../../plug-api/types.ts"; + +import type { DocumentMeta, FileMeta, PageMeta } from "../../type/index.ts"; export function spaceReadSyscalls(editor: Client): SysCallMapping { return { diff --git a/web/syscalls/system.ts b/web/syscalls/system.ts index d427a3dd..5abc1a95 100644 --- a/web/syscalls/system.ts +++ b/web/syscalls/system.ts @@ -1,8 +1,8 @@ -import type { SyscallMeta } from "../../plug-api/types.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { Client } from "../client.ts"; import { version } from "../../version.ts"; import type { CommandDef } from "../../lib/manifest.ts"; +import type { SyscallMeta } from "../../type/index.ts"; export function systemSyscalls( client: Client, diff --git a/web/ui_types.ts b/web/ui_types.ts index 1fca2be8..62eec37c 100644 --- a/web/ui_types.ts +++ b/web/ui_types.ts @@ -1,9 +1,7 @@ -import type { Command } from "../lib/command.ts"; +import type { Command } from "../type/command.ts"; import type { FilterOption, Notification, PanelMode } from "../type/client.ts"; -import type { - DocumentMeta, - PageMeta, -} from "@silverbulletmd/silverbullet/types"; + +import type { DocumentMeta, PageMeta } from "../type/index.ts"; export type PanelConfig = { mode?: PanelMode;