@silverbulletmd/silverbullet 2.9.0 → 2.10.0
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/README.md +36 -23
- package/client/plugos/hooks/syscall.ts +24 -10
- package/client/plugos/syscalls/asset.ts +61 -23
- package/client/plugos/syscalls/clientStore.ts +32 -6
- package/client/plugos/syscalls/client_code_widget.ts +9 -4
- package/client/plugos/syscalls/code_widget.ts +26 -11
- package/client/plugos/syscalls/config.ts +146 -30
- package/client/plugos/syscalls/datastore.ts +146 -40
- package/client/plugos/syscalls/editor.ts +1432 -711
- package/client/plugos/syscalls/event.ts +46 -13
- package/client/plugos/syscalls/fetch.ts +123 -82
- package/client/plugos/syscalls/index.ts +242 -116
- package/client/plugos/syscalls/jsonschema.ts +107 -8
- package/client/plugos/syscalls/language.ts +38 -12
- package/client/plugos/syscalls/markdown.ts +166 -50
- package/client/plugos/syscalls/mq.ts +93 -20
- package/client/plugos/syscalls/schema_introspection.ts +33 -0
- package/client/plugos/syscalls/service_registry.ts +74 -20
- package/client/plugos/syscalls/shell.ts +51 -20
- package/client/plugos/syscalls/space.ts +169 -113
- package/client/plugos/syscalls/sync.ts +50 -19
- package/client/plugos/syscalls/system.ts +236 -139
- package/client/plugos/system.ts +21 -5
- package/client/space_lua/api_documentation.ts +107 -0
- package/client/space_lua/ast.ts +13 -0
- package/client/space_lua/eval.ts +12 -4
- package/client/space_lua/parse.ts +243 -108
- package/client/space_lua/pretty_print.ts +128 -54
- package/client/space_lua/query_collection.ts +4 -4
- package/client/space_lua/render_widget.ts +156 -0
- package/client/space_lua/runtime.ts +83 -22
- package/client/space_lua/stdlib/crypto.ts +8 -3
- package/client/space_lua/stdlib/encoding.ts +27 -9
- package/client/space_lua/stdlib/js.ts +137 -22
- package/client/space_lua/stdlib/load.ts +24 -15
- package/client/space_lua/stdlib/math.ts +323 -118
- package/client/space_lua/stdlib/net.ts +57 -9
- package/client/space_lua/stdlib/os.ts +111 -44
- package/client/space_lua/stdlib/space_lua.ts +344 -20
- package/client/space_lua/stdlib/string.ts +282 -104
- package/client/space_lua/stdlib/string_pack.ts +58 -19
- package/client/space_lua/stdlib/table.ts +195 -40
- package/client/space_lua/stdlib.ts +335 -93
- package/client/space_lua/syscalls.ts +270 -0
- package/dist/plug-compile.js +1 -1
- package/package.json +3 -3
- package/plug-api/lib/ref.ts +96 -0
- package/plug-api/lib/shortcut.ts +2 -1
- package/plug-api/syscalls/config.ts +5 -3
- package/plug-api/syscalls/editor.ts +16 -0
- package/plug-api/syscalls/index.ts +17 -1
- package/plug-api/syscalls/jsonschema.ts +9 -0
- package/plug-api/syscalls/lua.ts +7 -0
- package/plug-api/syscalls/shell.ts +0 -1
- package/plug-api/syscalls/system.ts +7 -0
- package/plug-api/system_mock.ts +2 -2
- package/plug-api/types/index.ts +52 -1
- package/plug-api/types/manifest.ts +22 -4
- package/plug-api/ui/cx.ts +1 -3
- package/plug-api/ui/index.ts +3 -0
- package/plug-api/ui/panel_styles.ts +4 -3
- package/plug-api/ui/slugify.ts +44 -0
- package/client/plugos/syscalls/lua.ts +0 -81
|
@@ -2,18 +2,36 @@ import { LuaBuiltinFunction, LuaTable } from "../runtime.ts";
|
|
|
2
2
|
import { base64Decode, base64Encode } from "../../../plug-api/lib/crypto.ts";
|
|
3
3
|
|
|
4
4
|
export const encodingApi = new LuaTable({
|
|
5
|
-
base64Encode: new LuaBuiltinFunction(
|
|
6
|
-
(_sf, s: string | Uint8Array): string => {
|
|
5
|
+
base64Encode: new LuaBuiltinFunction({
|
|
6
|
+
callback: (_sf, s: string | Uint8Array): string => {
|
|
7
7
|
return base64Encode(s);
|
|
8
8
|
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
description: "Encodes a string or byte buffer as Base64.",
|
|
10
|
+
parameters: [{ name: "data", type: "string|bytes" }],
|
|
11
|
+
returns: [{ type: "string", description: "Base64-encoded data." }],
|
|
12
12
|
}),
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
base64Decode: new LuaBuiltinFunction({
|
|
14
|
+
callback: (_sf, s: string): Uint8Array => {
|
|
15
|
+
return base64Decode(s);
|
|
16
|
+
},
|
|
17
|
+
description: "Decodes a Base64 string into a byte buffer.",
|
|
18
|
+
parameters: [{ name: "encoded", type: "string" }],
|
|
19
|
+
returns: [{ type: "bytes", description: "Decoded bytes." }],
|
|
20
|
+
}),
|
|
21
|
+
utf8Encode: new LuaBuiltinFunction({
|
|
22
|
+
callback: (_sf, s: string): Uint8Array => {
|
|
23
|
+
return new TextEncoder().encode(s);
|
|
24
|
+
},
|
|
25
|
+
description: "Encodes a UTF-8 string into a byte buffer.",
|
|
26
|
+
parameters: [{ name: "value", type: "string" }],
|
|
27
|
+
returns: [{ type: "bytes", description: "UTF-8 encoded bytes." }],
|
|
15
28
|
}),
|
|
16
|
-
utf8Decode: new LuaBuiltinFunction(
|
|
17
|
-
|
|
29
|
+
utf8Decode: new LuaBuiltinFunction({
|
|
30
|
+
callback: (_sf, data: Uint8Array): string => {
|
|
31
|
+
return new TextDecoder().decode(data);
|
|
32
|
+
},
|
|
33
|
+
description: "Decodes a UTF-8 byte buffer into a string.",
|
|
34
|
+
parameters: [{ name: "data", type: "bytes" }],
|
|
35
|
+
returns: [{ type: "string", description: "Decoded text." }],
|
|
18
36
|
}),
|
|
19
37
|
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
LuaTable,
|
|
5
5
|
luaValueToJS,
|
|
6
6
|
} from "../runtime.ts";
|
|
7
|
+
import { fsEndpoint } from "../../spaces/constants.ts";
|
|
7
8
|
|
|
8
9
|
export const jsApi = new LuaTable({
|
|
9
10
|
/**
|
|
@@ -12,57 +13,171 @@ export const jsApi = new LuaTable({
|
|
|
12
13
|
* @param args - The arguments to pass to the constructor.
|
|
13
14
|
* @returns The new instance.
|
|
14
15
|
*/
|
|
15
|
-
new: new LuaBuiltinFunction(
|
|
16
|
-
|
|
16
|
+
new: new LuaBuiltinFunction({
|
|
17
|
+
callback: (sf, constructorFn: any, ...args) => {
|
|
18
|
+
return new constructorFn(...args.map((v) => luaValueToJS(v, sf)));
|
|
19
|
+
},
|
|
20
|
+
description: "Creates an instance of a JavaScript class.",
|
|
21
|
+
signatures: ["js.new(constructor, ...): userdata"],
|
|
22
|
+
parameters: [
|
|
23
|
+
{
|
|
24
|
+
name: "constructor",
|
|
25
|
+
type: "userdata",
|
|
26
|
+
description: "JavaScript constructor function.",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "...",
|
|
30
|
+
description: "Constructor arguments converted to JavaScript values.",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
returns: [{ type: "userdata", description: "New JavaScript instance." }],
|
|
34
|
+
examples: [{ code: 'local value = js.new(js.window.Date, "2024-03-14")' }],
|
|
17
35
|
}),
|
|
18
36
|
/**
|
|
19
37
|
* Imports a JavaScript module.
|
|
20
38
|
* @param url - The URL of the module to import.
|
|
21
39
|
* @returns The imported module.
|
|
22
40
|
*/
|
|
23
|
-
import: new LuaBuiltinFunction(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
m
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
import: new LuaBuiltinFunction({
|
|
42
|
+
callback: async (_sf, url) => {
|
|
43
|
+
let m = await import(url);
|
|
44
|
+
// Unwrap default if it exists
|
|
45
|
+
if (Object.keys(m).length === 1 && m.default) {
|
|
46
|
+
m = m.default;
|
|
47
|
+
}
|
|
48
|
+
return m;
|
|
49
|
+
},
|
|
50
|
+
description: "Dynamically imports a JavaScript module from a URL.",
|
|
51
|
+
parameters: [{ name: "url", type: "string", description: "Module URL." }],
|
|
52
|
+
returns: [
|
|
53
|
+
{
|
|
54
|
+
type: "userdata",
|
|
55
|
+
description: "Imported module, with a sole default export unwrapped.",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
examples: [
|
|
59
|
+
{ code: 'local lib = js.import("https://esm.sh/lodash@4.17.21")' },
|
|
60
|
+
],
|
|
30
61
|
}),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Like `js.import`, but takes a path to a file in the current space (e.g.
|
|
64
|
+
* "Library/foo/bar.js") and resolves it to its full same-origin `/.fs` URL
|
|
65
|
+
* before importing.
|
|
66
|
+
* @param path - Space-relative path to the JS module (leading "/" optional).
|
|
67
|
+
* @returns The imported module (with a sole `default` export unwrapped).
|
|
68
|
+
*/
|
|
69
|
+
importFromSpace: new LuaBuiltinFunction({
|
|
70
|
+
callback: async (_sf, path: string) => {
|
|
71
|
+
const base = document.baseURI.replace(/\/*$/, "/");
|
|
72
|
+
const rel = String(path).replace(/^\/+/, "");
|
|
73
|
+
let m = await import(`${base}${fsEndpoint.slice(1)}/${rel}`);
|
|
74
|
+
// Unwrap default if it exists (same contract as `js.import`).
|
|
75
|
+
if (Object.keys(m).length === 1 && m.default) {
|
|
76
|
+
m = m.default;
|
|
37
77
|
}
|
|
38
|
-
return
|
|
39
|
-
}
|
|
78
|
+
return m;
|
|
79
|
+
},
|
|
80
|
+
description:
|
|
81
|
+
"Imports a JavaScript module from a file in the current space.",
|
|
82
|
+
parameters: [
|
|
83
|
+
{
|
|
84
|
+
name: "path",
|
|
85
|
+
type: "string",
|
|
86
|
+
description:
|
|
87
|
+
"Space-relative module path, with an optional leading slash.",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
returns: [
|
|
91
|
+
{
|
|
92
|
+
type: "userdata",
|
|
93
|
+
description: "Imported module, with a sole default export unwrapped.",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
examples: [
|
|
97
|
+
{ code: 'local acme = js.importFromSpace("Library/acme/acme.js")' },
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
eachIterable: new LuaBuiltinFunction({
|
|
101
|
+
callback: (_sf, val) => {
|
|
102
|
+
const iterator = val[Symbol.asyncIterator]();
|
|
103
|
+
return async () => {
|
|
104
|
+
const result = await iterator.next();
|
|
105
|
+
if (result.done) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return result.value;
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
description: "Creates a Lua iterator over a JavaScript async iterable.",
|
|
112
|
+
parameters: [
|
|
113
|
+
{
|
|
114
|
+
name: "iterable",
|
|
115
|
+
type: "userdata",
|
|
116
|
+
description: "JavaScript async iterable.",
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
returns: [
|
|
120
|
+
{
|
|
121
|
+
type: "function",
|
|
122
|
+
description: "Iterator yielding successive JavaScript values.",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
examples: [
|
|
126
|
+
{
|
|
127
|
+
code: "for value in js.eachIterable(someJsAsyncIterable) do\n print(value)\nend",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
40
130
|
}),
|
|
41
131
|
/**
|
|
42
132
|
* Converts a JavaScript value to a Lua value.
|
|
43
133
|
* @param val - The JavaScript value to convert.
|
|
44
134
|
* @returns The Lua value.
|
|
45
135
|
*/
|
|
46
|
-
tolua: new LuaBuiltinFunction(
|
|
136
|
+
tolua: new LuaBuiltinFunction({
|
|
137
|
+
callback: (_sf, val) => jsToLuaValue(val),
|
|
138
|
+
description: "Converts a JavaScript value to its Lua representation.",
|
|
139
|
+
parameters: [
|
|
140
|
+
{ name: "value", description: "JavaScript value to convert." },
|
|
141
|
+
],
|
|
142
|
+
returns: [{ description: "Converted Lua value." }],
|
|
143
|
+
examples: [{ code: "local luaTable = js.tolua(jsArray)" }],
|
|
144
|
+
}),
|
|
47
145
|
/**
|
|
48
146
|
* Converts a Lua value to a JavaScript value.
|
|
49
147
|
* @param val - The Lua value to convert.
|
|
50
148
|
* @returns The JavaScript value.
|
|
51
149
|
*/
|
|
52
|
-
tojs: new LuaBuiltinFunction(
|
|
150
|
+
tojs: new LuaBuiltinFunction({
|
|
151
|
+
callback: (sf, val) => luaValueToJS(val, sf),
|
|
152
|
+
description: "Converts a Lua value to its JavaScript representation.",
|
|
153
|
+
parameters: [{ name: "value", description: "Lua value to convert." }],
|
|
154
|
+
returns: [{ description: "Converted JavaScript value." }],
|
|
155
|
+
examples: [{ code: "local jsArray = js.tojs({1, 2, 3})" }],
|
|
156
|
+
}),
|
|
53
157
|
/**
|
|
54
158
|
* Logs a message to the console.
|
|
55
159
|
* @param args - The arguments to log.
|
|
56
160
|
*/
|
|
57
|
-
log: new LuaBuiltinFunction(
|
|
58
|
-
|
|
161
|
+
log: new LuaBuiltinFunction({
|
|
162
|
+
callback: (_sf, ...args) => {
|
|
163
|
+
console.log(...args);
|
|
164
|
+
},
|
|
165
|
+
description: "Logs values to the JavaScript console.",
|
|
166
|
+
parameters: [{ name: "...", description: "Values to log." }],
|
|
167
|
+
examples: [{ code: 'js.log("User data:", {name = "Ada"})' }],
|
|
59
168
|
}),
|
|
60
169
|
/**
|
|
61
170
|
* Converts a Lua value to a JSON string.
|
|
62
171
|
* @param val - The Lua value to convert.
|
|
63
172
|
* @returns The JSON string.
|
|
64
173
|
*/
|
|
65
|
-
stringify: new LuaBuiltinFunction(
|
|
174
|
+
stringify: new LuaBuiltinFunction({
|
|
175
|
+
callback: (_sf, val) => JSON.stringify(val),
|
|
176
|
+
description: "Serializes a value as JSON using JavaScript semantics.",
|
|
177
|
+
parameters: [{ name: "value", description: "Value to serialize." }],
|
|
178
|
+
returns: [{ type: "string", description: "JSON representation." }],
|
|
179
|
+
examples: [{ code: "print(js.stringify({1, 2, 3})) -- [1,2,3]" }],
|
|
180
|
+
}),
|
|
66
181
|
|
|
67
182
|
// Expose the global window object
|
|
68
183
|
window: globalThis,
|
|
@@ -24,22 +24,31 @@ export function luaLoad(code: LuaValue, sf: LuaStackFrame): LuaValue {
|
|
|
24
24
|
|
|
25
25
|
const globalEnv: LuaEnv = globalEnvMaybe as LuaEnv;
|
|
26
26
|
|
|
27
|
-
const runner = new LuaBuiltinFunction(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const runner = new LuaBuiltinFunction({
|
|
28
|
+
callback: async (innerSf: LuaStackFrame) => {
|
|
29
|
+
const res = await evalStatement(block, globalEnv, innerSf, true);
|
|
30
|
+
if (res === undefined) {
|
|
31
|
+
return null;
|
|
32
|
+
} else {
|
|
33
|
+
if (
|
|
34
|
+
res &&
|
|
35
|
+
typeof res === "object" &&
|
|
36
|
+
(res as any).ctrl === "return"
|
|
37
|
+
) {
|
|
38
|
+
return new LuaMultiRes((res as any).values);
|
|
39
|
+
}
|
|
40
|
+
if (res && typeof res === "object" && (res as any).ctrl === "break") {
|
|
41
|
+
throw new Error("break outside loop");
|
|
42
|
+
}
|
|
43
|
+
if (res && typeof res === "object" && (res as any).ctrl === "goto") {
|
|
44
|
+
throw new Error("unexpected goto signal");
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error("unexpected goto signal");
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
48
|
+
},
|
|
49
|
+
description: "Executes the Lua chunk compiled by `load`.",
|
|
50
|
+
signatures: ["function(...)"],
|
|
51
|
+
returns: [{ description: "Values returned by the compiled chunk." }],
|
|
43
52
|
});
|
|
44
53
|
|
|
45
54
|
return runner;
|