@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
|
@@ -10,130 +10,186 @@ import type {
|
|
|
10
10
|
|
|
11
11
|
export function spaceReadSyscalls(client: Client): SysCallMapping {
|
|
12
12
|
return {
|
|
13
|
-
"space.listPages":
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
"space.listPages": {
|
|
14
|
+
callback: (): Promise<PageMeta[]> => client.space.fetchPageList(),
|
|
15
|
+
description: "Lists all pages in the space.",
|
|
16
|
+
},
|
|
17
|
+
"space.readPage": {
|
|
18
|
+
callback: async (_ctx, name: string): Promise<string> =>
|
|
19
|
+
(await client.space.readPage(name)).text,
|
|
20
|
+
description: "Reads a page and returns its Markdown text.",
|
|
21
|
+
signatures: ["space.readPage(name)"],
|
|
22
|
+
},
|
|
23
|
+
"space.readPageWithMeta": {
|
|
24
|
+
callback: (
|
|
25
|
+
_ctx,
|
|
26
|
+
name: string,
|
|
27
|
+
): Promise<{ text: string; meta: PageMeta }> =>
|
|
28
|
+
client.space.readPage(name),
|
|
29
|
+
description:
|
|
30
|
+
"Reads a page and returns both its Markdown text and metadata.",
|
|
31
|
+
signatures: ["space.readPageWithMeta(name)"],
|
|
32
|
+
},
|
|
33
|
+
"space.readRef": {
|
|
34
|
+
callback: async (_ctx, ref: string | Ref): Promise<string> => {
|
|
35
|
+
if (typeof ref === "string") {
|
|
36
|
+
ref = parseToRef(ref)!;
|
|
37
|
+
if (!ref) {
|
|
38
|
+
throw new Error(`Invalid ref: ${ref}`);
|
|
39
|
+
}
|
|
30
40
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
"space.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
"space.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
"space.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
return (await client.space.readRef(ref)).text;
|
|
42
|
+
},
|
|
43
|
+
description:
|
|
44
|
+
"Reads the text addressed by a page, header, or position reference.",
|
|
45
|
+
signatures: ["space.readRef(ref)"],
|
|
46
|
+
},
|
|
47
|
+
"space.pageExists": {
|
|
48
|
+
callback: (_ctx, name: string): boolean =>
|
|
49
|
+
client.clientSystem.allKnownFiles.has(`${name}.md`),
|
|
50
|
+
description: "Checks whether a page exists in the space.",
|
|
51
|
+
signatures: ["space.pageExists(name)"],
|
|
52
|
+
},
|
|
53
|
+
"space.getPageMeta": {
|
|
54
|
+
callback: (_ctx, name: string): Promise<PageMeta> =>
|
|
55
|
+
client.space.getPageMeta(name),
|
|
56
|
+
description: "Returns metadata for a page.",
|
|
57
|
+
signatures: ["space.getPageMeta(name)"],
|
|
58
|
+
},
|
|
59
|
+
"space.listPlugs": {
|
|
60
|
+
callback: (): Promise<FileMeta[]> => client.space.listPlugs(),
|
|
61
|
+
description: "Lists all plug files in the space.",
|
|
62
|
+
},
|
|
63
|
+
"space.listDocuments": {
|
|
64
|
+
callback: async (): Promise<DocumentMeta[]> =>
|
|
65
|
+
await client.space.fetchDocumentList(),
|
|
66
|
+
description: "Lists all non-page documents in the space.",
|
|
67
|
+
},
|
|
68
|
+
"space.readDocument": {
|
|
69
|
+
callback: async (_ctx, name: string): Promise<Uint8Array> =>
|
|
70
|
+
(await client.space.readDocument(name)).data,
|
|
71
|
+
description: "Reads a document as binary data.",
|
|
72
|
+
signatures: ["space.readDocument(name)"],
|
|
73
|
+
},
|
|
74
|
+
"space.getDocumentMeta": {
|
|
75
|
+
callback: async (_ctx, name: string): Promise<DocumentMeta> =>
|
|
76
|
+
await client.space.getDocumentMeta(name),
|
|
77
|
+
description: "Returns metadata for a document.",
|
|
78
|
+
signatures: ["space.getDocumentMeta(name)"],
|
|
54
79
|
},
|
|
55
80
|
// DEPRECATED, please use document versions instead, left here for backwards compatibility
|
|
56
|
-
"space.listAttachments":
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
"space.
|
|
63
|
-
_ctx,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
"space.listAttachments": {
|
|
82
|
+
callback: async (): Promise<DocumentMeta[]> =>
|
|
83
|
+
await client.space.fetchDocumentList(),
|
|
84
|
+
description: "Deprecated alias for space.listDocuments.",
|
|
85
|
+
deprecated: "Use space.listDocuments instead.",
|
|
86
|
+
},
|
|
87
|
+
"space.readAttachment": {
|
|
88
|
+
callback: async (_ctx, name: string): Promise<Uint8Array> =>
|
|
89
|
+
(await client.space.readDocument(name)).data,
|
|
90
|
+
description: "Deprecated alias for space.readDocument.",
|
|
91
|
+
deprecated: "Use space.readDocument instead.",
|
|
92
|
+
signatures: ["space.readAttachment(name)"],
|
|
93
|
+
},
|
|
94
|
+
"space.getAttachmentMeta": {
|
|
95
|
+
callback: async (_ctx, name: string): Promise<DocumentMeta> =>
|
|
96
|
+
await client.space.getDocumentMeta(name),
|
|
97
|
+
description: "Deprecated alias for space.getDocumentMeta.",
|
|
98
|
+
deprecated: "Use space.getDocumentMeta instead.",
|
|
99
|
+
signatures: ["space.getAttachmentMeta(name)"],
|
|
67
100
|
},
|
|
68
101
|
// FS
|
|
69
|
-
"space.listFiles":
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
"space.listFiles": {
|
|
103
|
+
callback: (): Promise<FileMeta[]> =>
|
|
104
|
+
client.space.spacePrimitives.fetchFileList(),
|
|
105
|
+
description: "Lists every file in the space.",
|
|
106
|
+
},
|
|
107
|
+
"space.getFileMeta": {
|
|
108
|
+
callback: (_ctx, name: string): Promise<FileMeta> =>
|
|
109
|
+
client.space.spacePrimitives.getFileMeta(name),
|
|
110
|
+
description: "Returns metadata for an arbitrary space file.",
|
|
111
|
+
signatures: ["space.getFileMeta(name)"],
|
|
112
|
+
},
|
|
113
|
+
"space.readFile": {
|
|
114
|
+
callback: async (_ctx, name: string): Promise<Uint8Array> =>
|
|
115
|
+
(await client.space.spacePrimitives.readFile(name)).data,
|
|
116
|
+
description: "Reads an arbitrary space file as binary data.",
|
|
117
|
+
signatures: ["space.readFile(name)"],
|
|
118
|
+
},
|
|
119
|
+
"space.readFileWithMeta": {
|
|
120
|
+
callback: async (
|
|
121
|
+
_ctx,
|
|
122
|
+
name: string,
|
|
123
|
+
): Promise<{ data: Uint8Array; meta: FileMeta }> =>
|
|
124
|
+
await client.space.spacePrimitives.readFile(name),
|
|
125
|
+
description: "Reads an arbitrary space file together with its metadata.",
|
|
126
|
+
signatures: ["space.readFileWithMeta(name)"],
|
|
127
|
+
},
|
|
128
|
+
"space.fileExists": {
|
|
129
|
+
callback: async (_ctx, name: string): Promise<boolean> => {
|
|
130
|
+
// If a full sync has successfully completed (so we know what files exist)
|
|
131
|
+
// and we have a snapshot, let's use the snapshot
|
|
132
|
+
if (
|
|
133
|
+
client.fullSyncCompleted &&
|
|
134
|
+
!client.eventedSpacePrimitives.isSnapshotEmpty()
|
|
135
|
+
) {
|
|
136
|
+
return !!client.eventedSpacePrimitives.getSnapshot()[name];
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await client.space.spacePrimitives.getFileMeta(name);
|
|
140
|
+
// If this returned the file exists
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
// Assumption: any error means the file does not exist
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
description: "Checks whether an arbitrary file exists in the space.",
|
|
148
|
+
signatures: ["space.fileExists(name)"],
|
|
101
149
|
},
|
|
102
150
|
};
|
|
103
151
|
}
|
|
104
152
|
|
|
105
153
|
export function spaceWriteSyscalls(editor: Client): SysCallMapping {
|
|
106
154
|
return {
|
|
107
|
-
"space.writePage":
|
|
108
|
-
_ctx,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
"space.writePage": {
|
|
156
|
+
callback: (_ctx, name: string, text: string): Promise<PageMeta> =>
|
|
157
|
+
editor.space.writePage(name, text),
|
|
158
|
+
description: "Writes Markdown text to a page and returns its metadata.",
|
|
159
|
+
signatures: ["space.writePage(name, text)"],
|
|
160
|
+
},
|
|
161
|
+
"space.deletePage": {
|
|
162
|
+
callback: async (_ctx, name: string) => {
|
|
163
|
+
console.log("Deleting page");
|
|
164
|
+
await editor.space.deletePage(name);
|
|
165
|
+
},
|
|
166
|
+
description: "Deletes a page from the space.",
|
|
167
|
+
signatures: ["space.deletePage(name)"],
|
|
168
|
+
},
|
|
169
|
+
"space.writeDocument": {
|
|
170
|
+
callback: (_ctx, name: string, data: Uint8Array): Promise<DocumentMeta> =>
|
|
171
|
+
editor.space.writeDocument(name, data),
|
|
172
|
+
description: "Writes binary document data and returns its metadata.",
|
|
173
|
+
signatures: ["space.writeDocument(name, data)"],
|
|
174
|
+
},
|
|
175
|
+
"space.deleteDocument": {
|
|
176
|
+
callback: async (_ctx, name: string) => {
|
|
177
|
+
await editor.space.deleteDocument(name);
|
|
178
|
+
},
|
|
179
|
+
description: "Deletes a document from the space.",
|
|
180
|
+
signatures: ["space.deleteDocument(name)"],
|
|
181
|
+
},
|
|
182
|
+
"space.writeFile": {
|
|
183
|
+
callback: (_ctx, name: string, data: Uint8Array): Promise<FileMeta> =>
|
|
184
|
+
editor.space.spacePrimitives.writeFile(name, data),
|
|
185
|
+
description: "Writes an arbitrary binary file and returns its metadata.",
|
|
186
|
+
signatures: ["space.writeFile(name, data)"],
|
|
187
|
+
},
|
|
188
|
+
"space.deleteFile": {
|
|
189
|
+
callback: (_ctx, name: string) =>
|
|
190
|
+
editor.space.spacePrimitives.deleteFile(name),
|
|
191
|
+
description: "Deletes an arbitrary file from the space.",
|
|
192
|
+
signatures: ["space.deleteFile(name)"],
|
|
137
193
|
},
|
|
138
194
|
};
|
|
139
195
|
}
|
|
@@ -60,27 +60,58 @@ export function syncSyscalls(client: Client): SysCallMapping {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return {
|
|
63
|
-
"sync.hasInitialSyncCompleted":
|
|
64
|
-
|
|
63
|
+
"sync.hasInitialSyncCompleted": {
|
|
64
|
+
callback: (): boolean => {
|
|
65
|
+
return client.fullSyncCompleted;
|
|
66
|
+
},
|
|
67
|
+
description:
|
|
68
|
+
"Checks whether the initial client synchronization has completed.",
|
|
69
|
+
returns: [
|
|
70
|
+
{ type: "boolean", description: "Whether initial sync is complete." },
|
|
71
|
+
],
|
|
65
72
|
},
|
|
66
|
-
"sync.performFileSync":
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
"sync.performFileSync": {
|
|
74
|
+
callback: async (_ctx, path: string): Promise<void> => {
|
|
75
|
+
await client.postServiceWorkerMessage({
|
|
76
|
+
type: "perform-file-sync",
|
|
77
|
+
path,
|
|
78
|
+
});
|
|
79
|
+
// postServiceWorkerMessage returns silently if no SW, so only wait if SW is active
|
|
80
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
81
|
+
if (registration?.active) {
|
|
82
|
+
return waitForServiceWorkerActivation(path);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
description:
|
|
86
|
+
"Prioritizes a file for immediate synchronization and waits for completion.",
|
|
87
|
+
parameters: [
|
|
88
|
+
{
|
|
89
|
+
name: "path",
|
|
90
|
+
type: "string",
|
|
91
|
+
description: "Space-relative file path.",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
examples: [{ code: 'sync.performFileSync("notes/important.md")' }],
|
|
76
95
|
},
|
|
77
|
-
"sync.performSpaceSync":
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
"sync.performSpaceSync": {
|
|
97
|
+
callback: async (): Promise<number> => {
|
|
98
|
+
await client.postServiceWorkerMessage({ type: "perform-space-sync" });
|
|
99
|
+
const registration = await navigator.serviceWorker.getRegistration();
|
|
100
|
+
if (registration?.active) {
|
|
101
|
+
return waitForServiceWorkerActivation();
|
|
102
|
+
}
|
|
103
|
+
return 0;
|
|
104
|
+
},
|
|
105
|
+
description:
|
|
106
|
+
"Starts an immediate full-space synchronization and waits for completion.",
|
|
107
|
+
returns: [
|
|
108
|
+
{
|
|
109
|
+
type: "number",
|
|
110
|
+
description:
|
|
111
|
+
"Number of sync operations, or zero without an active worker.",
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
examples: [{ code: "local changes = sync.performSpaceSync()" }],
|
|
84
115
|
},
|
|
85
116
|
};
|
|
86
117
|
}
|