@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
|
@@ -9,25 +9,58 @@ export function eventSyscalls(
|
|
|
9
9
|
client: Client,
|
|
10
10
|
): SysCallMapping {
|
|
11
11
|
return {
|
|
12
|
-
"event.dispatch":
|
|
13
|
-
|
|
12
|
+
"event.dispatch": {
|
|
13
|
+
callback: (_ctx, eventName: string, data: any) => {
|
|
14
|
+
return eventHook.dispatchEvent(eventName, data);
|
|
15
|
+
},
|
|
16
|
+
description:
|
|
17
|
+
"Dispatches an event and collects responses from its listeners.",
|
|
18
|
+
parameters: [
|
|
19
|
+
{ name: "eventName", type: "string", description: "Event name." },
|
|
20
|
+
{ name: "data", description: "Event payload." },
|
|
21
|
+
],
|
|
22
|
+
returns: [{ type: "table", description: "Listener responses." }],
|
|
23
|
+
examples: [
|
|
24
|
+
{
|
|
25
|
+
code: 'local responses = event.dispatch("data.request", {id = 123})',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
14
28
|
},
|
|
15
|
-
"event.listEvents":
|
|
16
|
-
|
|
29
|
+
"event.listEvents": {
|
|
30
|
+
callback: () => {
|
|
31
|
+
return eventHook.listEvents();
|
|
32
|
+
},
|
|
33
|
+
description: "Lists all event names that currently have listeners.",
|
|
34
|
+
returns: [{ type: "table", description: "Registered event names." }],
|
|
17
35
|
},
|
|
18
36
|
/**
|
|
19
37
|
* Define a Lua event listener
|
|
20
38
|
*/
|
|
21
|
-
"event.listen":
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
"event.listen": {
|
|
40
|
+
callback: (_ctx, def: EventSubscription) => {
|
|
41
|
+
// console.log("Registering Lua event listener: ", def.name);
|
|
42
|
+
client.config.insert(
|
|
43
|
+
["eventListeners", def.name],
|
|
44
|
+
async (...args: any[]) => {
|
|
45
|
+
// Convert return value to JS
|
|
46
|
+
const val = await def.run(...args);
|
|
47
|
+
return luaValueToJS(val, LuaStackFrame.lostFrame);
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
description: "Registers a Space Lua listener on the event bus.",
|
|
52
|
+
parameters: [
|
|
53
|
+
{
|
|
54
|
+
name: "listener",
|
|
55
|
+
type: "table",
|
|
56
|
+
description: "Listener definition with name and run callback.",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
examples: [
|
|
60
|
+
{
|
|
61
|
+
code: 'event.listen { name = "my-event", run = function(e) print(e.data) end }',
|
|
29
62
|
},
|
|
30
|
-
|
|
63
|
+
],
|
|
31
64
|
},
|
|
32
65
|
};
|
|
33
66
|
}
|
|
@@ -15,91 +15,132 @@ import { fsEndpoint } from "../../spaces/constants.ts";
|
|
|
15
15
|
export function sandboxFetchSyscalls(client: Client): SysCallMapping {
|
|
16
16
|
return {
|
|
17
17
|
// For use in Lua
|
|
18
|
-
"http.request":
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
"http.request": {
|
|
19
|
+
callback: async (
|
|
20
|
+
_ctx,
|
|
21
|
+
url: string,
|
|
22
|
+
options: ProxyFetchRequest = {},
|
|
23
|
+
): Promise<ProxyFetchResponse> => {
|
|
24
|
+
console.warn("Deprecated: use net.proxyFetch() instead");
|
|
25
|
+
// JSONify any non-serializable body
|
|
26
|
+
if (
|
|
27
|
+
options?.body &&
|
|
28
|
+
typeof options.body !== "string" &&
|
|
29
|
+
!(options.body instanceof Uint8Array)
|
|
30
|
+
) {
|
|
31
|
+
options.body = JSON.stringify(options.body);
|
|
32
|
+
}
|
|
33
|
+
const fetchOptions = options
|
|
34
|
+
? {
|
|
35
|
+
method: options.method,
|
|
36
|
+
headers: {} as Record<string, string>,
|
|
37
|
+
body: options.body,
|
|
38
|
+
}
|
|
39
|
+
: {};
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
fetchOptions.headers = buildProxyHeaders(options?.headers);
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
43
|
+
const resp = await client.httpSpacePrimitives.authenticatedFetch(
|
|
44
|
+
buildProxyUrl(client, url),
|
|
45
|
+
fetchOptions,
|
|
46
|
+
);
|
|
47
|
+
// Do sensible things with the body based on the content type
|
|
48
|
+
// Read as ArrayBuffer first to safely handle empty responses (e.g.
|
|
49
|
+
// PUT/DELETE returning 204 with Content-Type: application/json).
|
|
50
|
+
// resp.arrayBuffer() never throws on an empty body, whereas
|
|
51
|
+
// resp.json() would throw a SyntaxError.
|
|
52
|
+
const rawBytes = new Uint8Array(await resp.arrayBuffer());
|
|
53
|
+
let body: any;
|
|
54
|
+
const contentTypeHeader =
|
|
55
|
+
options.responseEncoding ||
|
|
56
|
+
resp.headers.get("x-proxy-header-content-type");
|
|
57
|
+
const statusCode = +(resp.headers.get("x-proxy-status-code") || "200");
|
|
58
|
+
if (rawBytes.length === 0) {
|
|
59
|
+
body = null;
|
|
60
|
+
} else if (contentTypeHeader?.startsWith("application/json")) {
|
|
61
|
+
body = JSON.parse(new TextDecoder().decode(rawBytes));
|
|
62
|
+
} else if (
|
|
63
|
+
contentTypeHeader?.startsWith("application/xml") ||
|
|
64
|
+
contentTypeHeader?.startsWith("text/")
|
|
65
|
+
) {
|
|
66
|
+
body = new TextDecoder().decode(rawBytes);
|
|
67
|
+
} else {
|
|
68
|
+
body = rawBytes;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
ok: resp.ok,
|
|
72
|
+
status: statusCode,
|
|
73
|
+
headers: extractProxyHeaders(resp.headers),
|
|
74
|
+
body: body,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
description:
|
|
78
|
+
"Performs an authenticated HTTP request through the server proxy.",
|
|
79
|
+
parameters: [
|
|
80
|
+
{ name: "url", type: "string", description: "Target URL." },
|
|
81
|
+
{
|
|
82
|
+
name: "options",
|
|
83
|
+
type: "table",
|
|
84
|
+
description: "Method, headers, body, and response encoding.",
|
|
85
|
+
optional: true,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
returns: [
|
|
89
|
+
{
|
|
90
|
+
type: "table",
|
|
91
|
+
description: "Status, headers, and decoded response body.",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
deprecated: "Use net.proxyFetch instead.",
|
|
95
|
+
see: "API/net#net.proxyFetch(url, options?)",
|
|
75
96
|
},
|
|
76
|
-
"sandboxFetch.fetch":
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
"sandboxFetch.fetch": {
|
|
98
|
+
callback: async (
|
|
99
|
+
_ctx,
|
|
100
|
+
url: string,
|
|
101
|
+
options?: ProxyFetchRequest64,
|
|
102
|
+
): Promise<ProxyFetchResponse64> => {
|
|
103
|
+
// console.log("Got sandbox fetch ", url, op);
|
|
104
|
+
const fetchOptions = options
|
|
105
|
+
? {
|
|
106
|
+
method: options.method,
|
|
107
|
+
headers: options.headers,
|
|
108
|
+
body: options.base64Body && base64Decode(options.base64Body),
|
|
109
|
+
}
|
|
110
|
+
: {};
|
|
111
|
+
fetchOptions.headers = buildProxyHeaders(options?.headers);
|
|
112
|
+
const resp = await client.httpSpacePrimitives.authenticatedFetch(
|
|
113
|
+
buildProxyUrl(client, url),
|
|
114
|
+
// Casting to any due to TypeScript fetch type limitations
|
|
115
|
+
fetchOptions as any,
|
|
116
|
+
);
|
|
117
|
+
const statusCode = +(resp.headers.get("x-proxy-status-code") || "200");
|
|
118
|
+
const body = await resp.arrayBuffer();
|
|
119
|
+
return {
|
|
120
|
+
ok: resp.ok,
|
|
121
|
+
status: statusCode,
|
|
122
|
+
headers: extractProxyHeaders(resp.headers),
|
|
123
|
+
base64Body: base64Encode(new Uint8Array(body)),
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
description:
|
|
127
|
+
"Performs an authenticated proxied fetch for a plug sandbox.",
|
|
128
|
+
parameters: [
|
|
129
|
+
{ name: "url", type: "string", description: "Target URL." },
|
|
130
|
+
{
|
|
131
|
+
name: "options",
|
|
132
|
+
type: "table",
|
|
133
|
+
description: "Method, headers, and base64-encoded body.",
|
|
134
|
+
optional: true,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
returns: [
|
|
138
|
+
{
|
|
139
|
+
type: "table",
|
|
140
|
+
description: "Status, headers, and base64-encoded response body.",
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
see: "API/http",
|
|
103
144
|
},
|
|
104
145
|
};
|
|
105
146
|
}
|