@silverbulletmd/silverbullet 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +18 -0
- package/README.md +98 -0
- package/client/asset_bundle/bundle.ts +95 -0
- package/client/data/datastore.ts +85 -0
- package/client/data/kv_primitives.ts +25 -0
- package/client/markdown_parser/constants.ts +13 -0
- package/client/plugos/event.ts +36 -0
- package/client/plugos/eventhook.ts +8 -0
- package/client/plugos/hooks/code_widget.ts +59 -0
- package/client/plugos/hooks/command.ts +104 -0
- package/client/plugos/hooks/document_editor.ts +77 -0
- package/client/plugos/hooks/event.ts +187 -0
- package/client/plugos/hooks/mq.ts +154 -0
- package/client/plugos/hooks/plug_namespace.ts +85 -0
- package/client/plugos/hooks/slash_command.ts +192 -0
- package/client/plugos/hooks/syscall.ts +66 -0
- package/client/plugos/manifest_cache.ts +67 -0
- package/client/plugos/plug.ts +99 -0
- package/client/plugos/plug_compile.ts +202 -0
- package/client/plugos/protocol.ts +40 -0
- package/client/plugos/proxy_fetch.ts +53 -0
- package/client/plugos/sandboxes/deno_worker_sandbox.ts +6 -0
- package/client/plugos/sandboxes/sandbox.ts +14 -0
- package/client/plugos/sandboxes/web_worker_sandbox.ts +17 -0
- package/client/plugos/sandboxes/worker_sandbox.ts +132 -0
- package/client/plugos/syscalls/asset.ts +35 -0
- package/client/plugos/syscalls/clientStore.ts +21 -0
- package/client/plugos/syscalls/client_code_widget.ts +12 -0
- package/client/plugos/syscalls/code_widget.ts +24 -0
- package/client/plugos/syscalls/config.ts +46 -0
- package/client/plugos/syscalls/datastore.ts +89 -0
- package/client/plugos/syscalls/editor.ts +673 -0
- package/client/plugos/syscalls/event.ts +36 -0
- package/client/plugos/syscalls/fetch.ts +128 -0
- package/client/plugos/syscalls/index.ts +102 -0
- package/client/plugos/syscalls/jsonschema.ts +69 -0
- package/client/plugos/syscalls/language.ts +23 -0
- package/client/plugos/syscalls/lua.ts +58 -0
- package/client/plugos/syscalls/markdown.ts +84 -0
- package/client/plugos/syscalls/mq.ts +52 -0
- package/client/plugos/syscalls/service_registry.ts +43 -0
- package/client/plugos/syscalls/shell.ts +39 -0
- package/client/plugos/syscalls/space.ts +139 -0
- package/client/plugos/syscalls/sync.ts +77 -0
- package/client/plugos/syscalls/system.ts +150 -0
- package/client/plugos/system.ts +201 -0
- package/client/plugos/types.ts +60 -0
- package/client/plugos/util.ts +14 -0
- package/client/plugos/worker_runtime.ts +195 -0
- package/client/space_lua/ast.ts +328 -0
- package/client/space_lua/ast_narrow.ts +81 -0
- package/client/space_lua/eval.ts +2478 -0
- package/client/space_lua/labels.ts +416 -0
- package/client/space_lua/numeric.ts +240 -0
- package/client/space_lua/parse.ts +1522 -0
- package/client/space_lua/query_collection.ts +232 -0
- package/client/space_lua/rp.ts +27 -0
- package/client/space_lua/runtime.ts +1702 -0
- package/client/space_lua/stdlib/crypto.ts +10 -0
- package/client/space_lua/stdlib/encoding.ts +19 -0
- package/client/space_lua/stdlib/format.ts +770 -0
- package/client/space_lua/stdlib/js.ts +73 -0
- package/client/space_lua/stdlib/load.ts +52 -0
- package/client/space_lua/stdlib/math.ts +193 -0
- package/client/space_lua/stdlib/net.ts +113 -0
- package/client/space_lua/stdlib/os.ts +368 -0
- package/client/space_lua/stdlib/space_lua.ts +153 -0
- package/client/space_lua/stdlib/string.ts +286 -0
- package/client/space_lua/stdlib/table.ts +401 -0
- package/client/space_lua/stdlib.ts +489 -0
- package/client/space_lua/tonumber.ts +501 -0
- package/client/space_lua/util.ts +96 -0
- package/dist/plug-compile.js +1513 -0
- package/package.json +120 -0
- package/plug-api/constants.ts +42 -0
- package/plug-api/lib/async.ts +162 -0
- package/plug-api/lib/crypto.ts +202 -0
- package/plug-api/lib/dates.ts +13 -0
- package/plug-api/lib/json.ts +136 -0
- package/plug-api/lib/limited_map.ts +72 -0
- package/plug-api/lib/memory_cache.ts +21 -0
- package/plug-api/lib/native_fetch.ts +6 -0
- package/plug-api/lib/ref.ts +275 -0
- package/plug-api/lib/resolve.ts +90 -0
- package/plug-api/lib/tags.ts +15 -0
- package/plug-api/lib/transclusion.ts +122 -0
- package/plug-api/lib/tree.ts +232 -0
- package/plug-api/lib/yaml.ts +284 -0
- package/plug-api/syscall.ts +15 -0
- package/plug-api/syscalls/asset.ts +36 -0
- package/plug-api/syscalls/client_store.ts +33 -0
- package/plug-api/syscalls/code_widget.ts +8 -0
- package/plug-api/syscalls/config.ts +58 -0
- package/plug-api/syscalls/datastore.ts +96 -0
- package/plug-api/syscalls/editor.ts +517 -0
- package/plug-api/syscalls/event.ts +47 -0
- package/plug-api/syscalls/index.ts +77 -0
- package/plug-api/syscalls/jsonschema.ts +25 -0
- package/plug-api/syscalls/language.ts +23 -0
- package/plug-api/syscalls/lua.ts +20 -0
- package/plug-api/syscalls/markdown.ts +38 -0
- package/plug-api/syscalls/mq.ts +79 -0
- package/plug-api/syscalls/shell.ts +14 -0
- package/plug-api/syscalls/space.ts +212 -0
- package/plug-api/syscalls/sync.ts +28 -0
- package/plug-api/syscalls/system.ts +102 -0
- package/plug-api/syscalls/yaml.ts +28 -0
- package/plug-api/syscalls.ts +21 -0
- package/plug-api/system_mock.ts +89 -0
- package/plug-api/types/client.ts +116 -0
- package/plug-api/types/config.ts +22 -0
- package/plug-api/types/datastore.ts +28 -0
- package/plug-api/types/event.ts +27 -0
- package/plug-api/types/index.ts +56 -0
- package/plug-api/types/manifest.ts +98 -0
- package/plug-api/types/namespace.ts +6 -0
- package/plugs/builtin_plugs.ts +14 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SysCallMapping } from "../../plugos/system.ts";
|
|
2
|
+
import { reloadAllWidgets } from "../../codemirror/code_widget.ts";
|
|
3
|
+
import { broadcastReload } from "../../components/widget_sandbox_iframe.ts";
|
|
4
|
+
|
|
5
|
+
export function clientCodeWidgetSyscalls(): SysCallMapping {
|
|
6
|
+
return {
|
|
7
|
+
"codeWidget.refreshAll": () => {
|
|
8
|
+
broadcastReload();
|
|
9
|
+
return reloadAllWidgets();
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SysCallMapping } from "../system.ts";
|
|
2
|
+
import type { CodeWidgetHook } from "../hooks/code_widget.ts";
|
|
3
|
+
import type { CodeWidgetContent } from "@silverbulletmd/silverbullet/type/client";
|
|
4
|
+
|
|
5
|
+
export function codeWidgetSyscalls(
|
|
6
|
+
codeWidgetHook: CodeWidgetHook,
|
|
7
|
+
): SysCallMapping {
|
|
8
|
+
return {
|
|
9
|
+
"codeWidget.render": (
|
|
10
|
+
_ctx,
|
|
11
|
+
lang: string,
|
|
12
|
+
body: string,
|
|
13
|
+
pageName: string,
|
|
14
|
+
): Promise<CodeWidgetContent | null> => {
|
|
15
|
+
const langCallback = codeWidgetHook.codeWidgetCallbacks.get(
|
|
16
|
+
lang,
|
|
17
|
+
);
|
|
18
|
+
if (!langCallback) {
|
|
19
|
+
throw new Error(`Code widget ${lang} not found`);
|
|
20
|
+
}
|
|
21
|
+
return langCallback(body, pageName);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SysCallMapping } from "../system.ts";
|
|
2
|
+
import type { Config } from "../../config.ts";
|
|
3
|
+
import { LuaStackFrame, luaValueToJS } from "../../space_lua/runtime.ts";
|
|
4
|
+
|
|
5
|
+
export function configSyscalls(config: Config): SysCallMapping {
|
|
6
|
+
return {
|
|
7
|
+
"config.get": (_ctx, path: string, defaultValue: any) => {
|
|
8
|
+
return config.get(path, defaultValue);
|
|
9
|
+
},
|
|
10
|
+
"config.set": (
|
|
11
|
+
_ctx,
|
|
12
|
+
keyOrValues: string | string[] | Record<string, any>,
|
|
13
|
+
value?: any,
|
|
14
|
+
) => {
|
|
15
|
+
config.set(keyOrValues as any, value);
|
|
16
|
+
},
|
|
17
|
+
"lua:config.setLuaValue": async (
|
|
18
|
+
_ctx,
|
|
19
|
+
keyOrValues: string | string[] | Record<string, any>,
|
|
20
|
+
value?: any,
|
|
21
|
+
) => {
|
|
22
|
+
// This is for special cases where we explicitly want to NOT convert a value to a JS value, but maintain its Lua version (mostly for LuaTables) — main use case: metatable
|
|
23
|
+
keyOrValues = await luaValueToJS(keyOrValues, LuaStackFrame.lostFrame);
|
|
24
|
+
config.set(keyOrValues as any, value);
|
|
25
|
+
},
|
|
26
|
+
"config.insert": (
|
|
27
|
+
_ctx,
|
|
28
|
+
key: string | string[],
|
|
29
|
+
value: any,
|
|
30
|
+
) => {
|
|
31
|
+
config.insert(key, value);
|
|
32
|
+
},
|
|
33
|
+
"config.has": (_ctx, path: string) => {
|
|
34
|
+
return config.has(path);
|
|
35
|
+
},
|
|
36
|
+
"config.define": (_ctx, key: string, schema: any) => {
|
|
37
|
+
config.define(key, schema);
|
|
38
|
+
},
|
|
39
|
+
"config.getValues": () => {
|
|
40
|
+
return config.values;
|
|
41
|
+
},
|
|
42
|
+
"config.getSchemas": () => {
|
|
43
|
+
return config.schemas;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LuaCollectionQuery,
|
|
3
|
+
queryLua,
|
|
4
|
+
} from "../../space_lua/query_collection.ts";
|
|
5
|
+
import type { DataStore } from "../../data/datastore.ts";
|
|
6
|
+
import type { SysCallMapping } from "../system.ts";
|
|
7
|
+
import {
|
|
8
|
+
jsToLuaValue,
|
|
9
|
+
LuaEnv,
|
|
10
|
+
LuaStackFrame,
|
|
11
|
+
luaValueToJS,
|
|
12
|
+
} from "../../space_lua/runtime.ts";
|
|
13
|
+
import type { KvQueryOptions } from "../../data/kv_primitives.ts";
|
|
14
|
+
import type { ClientSystem } from "../../client_system.ts";
|
|
15
|
+
|
|
16
|
+
import type { KV, KvKey } from "@silverbulletmd/silverbullet/type/datastore";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Exposes the datastore API to plugs, but scoping everything to a prefix based on the plug's name
|
|
20
|
+
* @param ds the datastore to wrap
|
|
21
|
+
* @param prefix prefix to scope all keys to to which the plug name will be appended
|
|
22
|
+
*/
|
|
23
|
+
export function dataStoreReadSyscalls(
|
|
24
|
+
ds: DataStore,
|
|
25
|
+
clientSystem: ClientSystem,
|
|
26
|
+
): SysCallMapping {
|
|
27
|
+
return {
|
|
28
|
+
"datastore.batchGet": (
|
|
29
|
+
_ctx,
|
|
30
|
+
keys: KvKey[],
|
|
31
|
+
): Promise<(any | undefined)[]> => {
|
|
32
|
+
return ds.batchGet(keys);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
"datastore.get": (_ctx, key: KvKey): Promise<any | null> => {
|
|
36
|
+
return ds.get(key);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
"datastore.query": async (_ctx, options: KvQueryOptions): Promise<KV[]> => {
|
|
40
|
+
const results: KV[] = [];
|
|
41
|
+
for await (const item of ds.query(options)) {
|
|
42
|
+
results.push(item);
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
"datastore.queryLua": async (
|
|
48
|
+
_ctx,
|
|
49
|
+
prefix: string[],
|
|
50
|
+
query: LuaCollectionQuery,
|
|
51
|
+
scopeVariables?: Record<string, any>,
|
|
52
|
+
): Promise<any[]> => {
|
|
53
|
+
const sf = LuaStackFrame.createWithGlobalEnv(
|
|
54
|
+
clientSystem.spaceLuaEnv.env,
|
|
55
|
+
);
|
|
56
|
+
let env = clientSystem.spaceLuaEnv.env;
|
|
57
|
+
if (scopeVariables) {
|
|
58
|
+
env = new LuaEnv(clientSystem.spaceLuaEnv.env);
|
|
59
|
+
for (const [key, value] of Object.entries(scopeVariables)) {
|
|
60
|
+
env.setLocal(key, jsToLuaValue(value));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (await queryLua<any>(ds.kv, prefix, query, env, sf)).map((item) =>
|
|
64
|
+
luaValueToJS(item, sf)
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function dataStoreWriteSyscalls(ds: DataStore): SysCallMapping {
|
|
71
|
+
return {
|
|
72
|
+
"datastore.delete": (_ctx, key: KvKey) => {
|
|
73
|
+
console.log("Deleting key", key);
|
|
74
|
+
return ds.delete(key);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
"datastore.set": (_ctx, key: KvKey, value: any) => {
|
|
78
|
+
return ds.set(key, value);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
"datastore.batchSet": (_ctx, kvs: KV[]) => {
|
|
82
|
+
return ds.batchSet(kvs);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
"datastore.batchDelete": (_ctx, keys: KvKey[]) => {
|
|
86
|
+
return ds.batchDelete(keys);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|