@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.
Files changed (117) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +98 -0
  3. package/client/asset_bundle/bundle.ts +95 -0
  4. package/client/data/datastore.ts +85 -0
  5. package/client/data/kv_primitives.ts +25 -0
  6. package/client/markdown_parser/constants.ts +13 -0
  7. package/client/plugos/event.ts +36 -0
  8. package/client/plugos/eventhook.ts +8 -0
  9. package/client/plugos/hooks/code_widget.ts +59 -0
  10. package/client/plugos/hooks/command.ts +104 -0
  11. package/client/plugos/hooks/document_editor.ts +77 -0
  12. package/client/plugos/hooks/event.ts +187 -0
  13. package/client/plugos/hooks/mq.ts +154 -0
  14. package/client/plugos/hooks/plug_namespace.ts +85 -0
  15. package/client/plugos/hooks/slash_command.ts +192 -0
  16. package/client/plugos/hooks/syscall.ts +66 -0
  17. package/client/plugos/manifest_cache.ts +67 -0
  18. package/client/plugos/plug.ts +99 -0
  19. package/client/plugos/plug_compile.ts +202 -0
  20. package/client/plugos/protocol.ts +40 -0
  21. package/client/plugos/proxy_fetch.ts +53 -0
  22. package/client/plugos/sandboxes/deno_worker_sandbox.ts +6 -0
  23. package/client/plugos/sandboxes/sandbox.ts +14 -0
  24. package/client/plugos/sandboxes/web_worker_sandbox.ts +17 -0
  25. package/client/plugos/sandboxes/worker_sandbox.ts +132 -0
  26. package/client/plugos/syscalls/asset.ts +35 -0
  27. package/client/plugos/syscalls/clientStore.ts +21 -0
  28. package/client/plugos/syscalls/client_code_widget.ts +12 -0
  29. package/client/plugos/syscalls/code_widget.ts +24 -0
  30. package/client/plugos/syscalls/config.ts +46 -0
  31. package/client/plugos/syscalls/datastore.ts +89 -0
  32. package/client/plugos/syscalls/editor.ts +673 -0
  33. package/client/plugos/syscalls/event.ts +36 -0
  34. package/client/plugos/syscalls/fetch.ts +128 -0
  35. package/client/plugos/syscalls/index.ts +102 -0
  36. package/client/plugos/syscalls/jsonschema.ts +69 -0
  37. package/client/plugos/syscalls/language.ts +23 -0
  38. package/client/plugos/syscalls/lua.ts +58 -0
  39. package/client/plugos/syscalls/markdown.ts +84 -0
  40. package/client/plugos/syscalls/mq.ts +52 -0
  41. package/client/plugos/syscalls/service_registry.ts +43 -0
  42. package/client/plugos/syscalls/shell.ts +39 -0
  43. package/client/plugos/syscalls/space.ts +139 -0
  44. package/client/plugos/syscalls/sync.ts +77 -0
  45. package/client/plugos/syscalls/system.ts +150 -0
  46. package/client/plugos/system.ts +201 -0
  47. package/client/plugos/types.ts +60 -0
  48. package/client/plugos/util.ts +14 -0
  49. package/client/plugos/worker_runtime.ts +195 -0
  50. package/client/space_lua/ast.ts +328 -0
  51. package/client/space_lua/ast_narrow.ts +81 -0
  52. package/client/space_lua/eval.ts +2478 -0
  53. package/client/space_lua/labels.ts +416 -0
  54. package/client/space_lua/numeric.ts +240 -0
  55. package/client/space_lua/parse.ts +1522 -0
  56. package/client/space_lua/query_collection.ts +232 -0
  57. package/client/space_lua/rp.ts +27 -0
  58. package/client/space_lua/runtime.ts +1702 -0
  59. package/client/space_lua/stdlib/crypto.ts +10 -0
  60. package/client/space_lua/stdlib/encoding.ts +19 -0
  61. package/client/space_lua/stdlib/format.ts +770 -0
  62. package/client/space_lua/stdlib/js.ts +73 -0
  63. package/client/space_lua/stdlib/load.ts +52 -0
  64. package/client/space_lua/stdlib/math.ts +193 -0
  65. package/client/space_lua/stdlib/net.ts +113 -0
  66. package/client/space_lua/stdlib/os.ts +368 -0
  67. package/client/space_lua/stdlib/space_lua.ts +153 -0
  68. package/client/space_lua/stdlib/string.ts +286 -0
  69. package/client/space_lua/stdlib/table.ts +401 -0
  70. package/client/space_lua/stdlib.ts +489 -0
  71. package/client/space_lua/tonumber.ts +501 -0
  72. package/client/space_lua/util.ts +96 -0
  73. package/dist/plug-compile.js +1513 -0
  74. package/package.json +120 -0
  75. package/plug-api/constants.ts +42 -0
  76. package/plug-api/lib/async.ts +162 -0
  77. package/plug-api/lib/crypto.ts +202 -0
  78. package/plug-api/lib/dates.ts +13 -0
  79. package/plug-api/lib/json.ts +136 -0
  80. package/plug-api/lib/limited_map.ts +72 -0
  81. package/plug-api/lib/memory_cache.ts +21 -0
  82. package/plug-api/lib/native_fetch.ts +6 -0
  83. package/plug-api/lib/ref.ts +275 -0
  84. package/plug-api/lib/resolve.ts +90 -0
  85. package/plug-api/lib/tags.ts +15 -0
  86. package/plug-api/lib/transclusion.ts +122 -0
  87. package/plug-api/lib/tree.ts +232 -0
  88. package/plug-api/lib/yaml.ts +284 -0
  89. package/plug-api/syscall.ts +15 -0
  90. package/plug-api/syscalls/asset.ts +36 -0
  91. package/plug-api/syscalls/client_store.ts +33 -0
  92. package/plug-api/syscalls/code_widget.ts +8 -0
  93. package/plug-api/syscalls/config.ts +58 -0
  94. package/plug-api/syscalls/datastore.ts +96 -0
  95. package/plug-api/syscalls/editor.ts +517 -0
  96. package/plug-api/syscalls/event.ts +47 -0
  97. package/plug-api/syscalls/index.ts +77 -0
  98. package/plug-api/syscalls/jsonschema.ts +25 -0
  99. package/plug-api/syscalls/language.ts +23 -0
  100. package/plug-api/syscalls/lua.ts +20 -0
  101. package/plug-api/syscalls/markdown.ts +38 -0
  102. package/plug-api/syscalls/mq.ts +79 -0
  103. package/plug-api/syscalls/shell.ts +14 -0
  104. package/plug-api/syscalls/space.ts +212 -0
  105. package/plug-api/syscalls/sync.ts +28 -0
  106. package/plug-api/syscalls/system.ts +102 -0
  107. package/plug-api/syscalls/yaml.ts +28 -0
  108. package/plug-api/syscalls.ts +21 -0
  109. package/plug-api/system_mock.ts +89 -0
  110. package/plug-api/types/client.ts +116 -0
  111. package/plug-api/types/config.ts +22 -0
  112. package/plug-api/types/datastore.ts +28 -0
  113. package/plug-api/types/event.ts +27 -0
  114. package/plug-api/types/index.ts +56 -0
  115. package/plug-api/types/manifest.ts +98 -0
  116. package/plug-api/types/namespace.ts +6 -0
  117. package/plugs/builtin_plugs.ts +14 -0
@@ -0,0 +1,77 @@
1
+ import type { LuaCollectionQuery } from "../../client/space_lua/query_collection.ts";
2
+ import { syscall } from "@silverbulletmd/silverbullet/syscall";
3
+ import type { ObjectValue } from "../../plug-api/types/index.ts";
4
+
5
+ /**
6
+ * Exposes the SilverBullet object indexing system
7
+ * @module
8
+ */
9
+
10
+ /**
11
+ * Indexes objects for a specific page
12
+ * @param page - The page identifier where objects will be indexed
13
+ * @param objects - Array of objects to be indexed
14
+ * @returns Promise that resolves when indexing is complete
15
+ */
16
+ export function indexObjects<T>(
17
+ page: string,
18
+ objects: ObjectValue<T>[],
19
+ ): Promise<void> {
20
+ return syscall("index.indexObjects", page, objects);
21
+ }
22
+
23
+ export function validateObjects<T>(
24
+ page: string,
25
+ objects: ObjectValue<T>[],
26
+ ): Promise<{ error: string; object: ObjectValue } | null> {
27
+ return syscall("index.validateObjects", page, objects);
28
+ }
29
+
30
+ /**
31
+ * Queries objects using a Lua-based collection query
32
+ * @param tag - The tag to filter objects by
33
+ * @param query - Lua query parameters to filter objects
34
+ * @param scopedVariables - Optional variables to be used in the Lua query
35
+ * @returns Promise that resolves with an array of matching objects
36
+ */
37
+ export function queryLuaObjects<T>(
38
+ tag: string,
39
+ query: LuaCollectionQuery,
40
+ scopedVariables?: Record<string, any>,
41
+ ): Promise<ObjectValue<T>[]> {
42
+ return syscall("index.queryLuaObjects", tag, query, scopedVariables);
43
+ }
44
+
45
+ /**
46
+ * Retrieves a specific object by its reference
47
+ * @param page - The page identifier where the object is located
48
+ * @param tag - The tag of the object
49
+ * @param ref - The reference identifier of the object
50
+ * @returns Promise that resolves with the matching object or undefined if not found
51
+ */
52
+ export function getObjectByRef<T>(
53
+ page: string,
54
+ tag: string,
55
+ ref: string,
56
+ ): Promise<ObjectValue<T> | undefined> {
57
+ return syscall("index.getObjectByRef", page, tag, ref);
58
+ }
59
+
60
+ /**
61
+ * Ensures that the full index is built and up-to-date
62
+ */
63
+ export function ensureFullIndex(): Promise<void> {
64
+ return syscall("index.ensureFullIndex");
65
+ }
66
+
67
+ export function reindexSpace(): Promise<void> {
68
+ return syscall("index.reindexSpace");
69
+ }
70
+
71
+ export function deleteObject(
72
+ page: string,
73
+ tag: string,
74
+ ref: string,
75
+ ): Promise<void> {
76
+ return syscall("index.deleteObject", page, tag, ref);
77
+ }
@@ -0,0 +1,25 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ /**
4
+ * Validates a JSON object against a JSON schema.
5
+ * @param schema the JSON schema to validate against
6
+ * @param object the JSON object to validate
7
+ * @returns an error message if the object is invalid, or undefined if it is valid
8
+ */
9
+ export function validateObject(
10
+ schema: any,
11
+ object: any,
12
+ ): Promise<string | undefined> {
13
+ return syscall("jsonschema.validateObject", schema, object);
14
+ }
15
+
16
+ /**
17
+ * Validates a JSON schema.
18
+ * @param schema the JSON schema to validate
19
+ * @returns an error message if the schema is invalid, or undefined if it is valid
20
+ */
21
+ export function validateSchema(
22
+ schema: any,
23
+ ): Promise<string | undefined> {
24
+ return syscall("jsonschema.validateSchema", schema);
25
+ }
@@ -0,0 +1,23 @@
1
+ import { syscall } from "../syscall.ts";
2
+ import type { ParseTree } from "../lib/tree.ts";
3
+
4
+ /**
5
+ * Parses a piece of code using any of the supported SB languages, see `common/languages.ts` for a list
6
+ * @param language the language to parse
7
+ * @param code the code to parse
8
+ * @returns a ParseTree representation of the code
9
+ */
10
+ export function parseLanguage(
11
+ language: string,
12
+ code: string,
13
+ ): Promise<ParseTree> {
14
+ return syscall("language.parseLanguage", language, code);
15
+ }
16
+
17
+ /**
18
+ * Lists all supported languages in fenced code blocks
19
+ * @returns a list of all supported languages
20
+ */
21
+ export function listLanguages(): Promise<string[]> {
22
+ return syscall("language.listLanguages");
23
+ }
@@ -0,0 +1,20 @@
1
+ import { syscall } from "../syscall.ts";
2
+ import type { LuaBlock, LuaExpression } from "../../client/space_lua/ast.ts";
3
+
4
+ export function parse(
5
+ code: string,
6
+ ): Promise<LuaBlock> {
7
+ return syscall("lua.parse", code);
8
+ }
9
+
10
+ export function parseExpression(
11
+ expression: string,
12
+ ): Promise<LuaExpression> {
13
+ return syscall("lua.parseExpression", expression);
14
+ }
15
+
16
+ export function evalExpression(
17
+ expression: string,
18
+ ): Promise<any> {
19
+ return syscall("lua.evalExpression", expression);
20
+ }
@@ -0,0 +1,38 @@
1
+ import { syscall } from "../syscall.ts";
2
+ import type { ParseTree } from "../lib/tree.ts";
3
+
4
+ /**
5
+ * Parses a piece of markdown text into a ParseTree.
6
+ * @param text the markdown text to parse
7
+ * @returns a ParseTree representation of the markdown text
8
+ */
9
+ export function parseMarkdown(text: string): Promise<ParseTree> {
10
+ return syscall("markdown.parseMarkdown", text);
11
+ }
12
+
13
+ /**
14
+ * Renders a ParseTree to markdown.
15
+ * @param tree the parse tree
16
+ * @returns the rendered markdown of a passed parse tree
17
+ */
18
+ export function renderParseTree(tree: ParseTree): Promise<string> {
19
+ return syscall("markdown.renderParseTree", tree);
20
+ }
21
+
22
+ /**
23
+ * Expands custom markdown Lua directives and transclusions into plain markdown
24
+ * @param tree the parse tree
25
+ * @returns the expaneded markdown
26
+ */
27
+ export function expandMarkdown(tree: ParseTree): Promise<ParseTree> {
28
+ return syscall("markdown.expandMarkdown", tree);
29
+ }
30
+
31
+ /**
32
+ * Renders markdown text to HTML.
33
+ * @param markdownText the markdown text to render
34
+ * @returns HTML representation of the markdown
35
+ */
36
+ export function markdownToHtml(markdownText: string): Promise<string> {
37
+ return syscall("markdown.markdownToHtml", markdownText);
38
+ }
@@ -0,0 +1,79 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ import type { MQStats } from "../../plug-api/types/datastore.ts";
4
+
5
+ /**
6
+ * Implements a simple Message Queue system.
7
+ * @module
8
+ */
9
+
10
+ /**
11
+ * Sends a message to a queue.
12
+ * @param queue the name of the queue to send the message to
13
+ * @param body the body of the message to send
14
+ */
15
+ export function send(queue: string, body: any): Promise<void> {
16
+ return syscall("mq.send", queue, body);
17
+ }
18
+
19
+ /**
20
+ * Sends a batch of messages to a queue.
21
+ * @param queue the name of the queue
22
+ * @param bodies the bodies of the messages to send
23
+ */
24
+ export function batchSend(
25
+ queue: string,
26
+ bodies: any[],
27
+ ): Promise<void> {
28
+ return syscall("mq.batchSend", queue, bodies);
29
+ }
30
+
31
+ /**
32
+ * Flushes all messages from a queue.
33
+ * @param queue the name of the queue to subscribe to
34
+ */
35
+ export function flushQueue(queue: string): Promise<void> {
36
+ return syscall("mq.flushQueue", queue);
37
+ }
38
+
39
+ /**
40
+ * Flushes all messages from all queues.
41
+ */
42
+ export function flushAllQueues(): Promise<void> {
43
+ return syscall("mq.flushAllQueues");
44
+ }
45
+
46
+ /**
47
+ * Acknowledges a message from a queue, in case it needs to be explicitly acknowledged.
48
+ * @param queue the name of the queue the message came from
49
+ * @param id the id of the message to acknowledge
50
+ */
51
+ export function ack(queue: string, id: string): Promise<void> {
52
+ return syscall("mq.ack", queue, id);
53
+ }
54
+
55
+ /**
56
+ * Acknowledges a batch of messages from a queue, in case they need to be explicitly acknowledged.
57
+ * @param queue the name of the queue the messages came from
58
+ * @param ids the ids of the messages to acknowledge
59
+ */
60
+ export function batchAck(queue: string, ids: string[]): Promise<void> {
61
+ return syscall("mq.batchAck", queue, ids);
62
+ }
63
+
64
+ /**
65
+ * Retrieves stats on a particular queue.
66
+ * @param queue the name of the queue
67
+ */
68
+ export function getQueueStats(queue?: string): Promise<MQStats> {
69
+ return syscall("mq.getQueueStats", queue);
70
+ }
71
+
72
+ /**
73
+ * Waits for a queue to become empty.
74
+ * @param queue the name of the queue
75
+ * @returns a promise that resolves when the queue is empty
76
+ */
77
+ export function awaitEmptyQueue(queue: string): Promise<void> {
78
+ return syscall("mq.awaitEmptyQueue", queue);
79
+ }
@@ -0,0 +1,14 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ /**
4
+ * Runs a shell command.
5
+ * @param cmd the command to run
6
+ * @param args the arguments to pass to the command
7
+ * @returns the stdout, stderr, and exit code of the command
8
+ */
9
+ export function run(
10
+ cmd: string,
11
+ args: string[],
12
+ ): Promise<{ stdout: string; stderr: string; code: number }> {
13
+ return syscall("shell.run", cmd, args);
14
+ }
@@ -0,0 +1,212 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ import type {
4
+ DocumentMeta,
5
+ FileMeta,
6
+ PageMeta,
7
+ } from "../../plug-api/types/index.ts";
8
+ import type { Ref } from "@silverbulletmd/silverbullet/lib/ref";
9
+
10
+ /**
11
+ * Exposes the space with its pages, documents and plugs.
12
+ * @module
13
+ */
14
+
15
+ /**
16
+ * Lists all pages (files ending in .md) in the space.
17
+ * @param unfiltered
18
+ * @returns a list of all pages in the space represented as PageMeta objects
19
+ */
20
+ export function listPages(): Promise<PageMeta[]> {
21
+ return syscall("space.listPages");
22
+ }
23
+
24
+ /**
25
+ * Get metadata for a page in the space.
26
+ * @param name the name of the page to get metadata for
27
+ * @returns the metadata for the page
28
+ */
29
+ export function getPageMeta(name: string): Promise<PageMeta> {
30
+ return syscall("space.getPageMeta", name);
31
+ }
32
+
33
+ /**
34
+ * Check if a page exists in the space.
35
+ * @param name the name of the page to check
36
+ * @returns true if the page exists, false otherwise
37
+ */
38
+ export function pageExists(name: string): Promise<boolean> {
39
+ return syscall("space.pageExists", name);
40
+ }
41
+
42
+ /**
43
+ * Read a page from the space as text.
44
+ * @param name the name of the page to read
45
+ * @returns the text of the page
46
+ */
47
+ export function readPage(
48
+ name: string,
49
+ ): Promise<string> {
50
+ return syscall("space.readPage", name);
51
+ }
52
+
53
+ /**
54
+ * Read a page from the space returning both its text and meta data
55
+ * @param name the name of the page to read
56
+ * @returns
57
+ * - text: page text as a string
58
+ * - meta: pageMeta
59
+ */
60
+ export function readPageWithMeta(
61
+ name: string,
62
+ ): Promise<{ text: string; meta: PageMeta }> {
63
+ return syscall("space.readPageWithMeta", name);
64
+ }
65
+
66
+ /**
67
+ * Write a page to the space.
68
+ * @param name the name of the page to write
69
+ * @param text the text of the page to write
70
+ * @returns the metadata for the written page
71
+ */
72
+ export function writePage(name: string, text: string): Promise<PageMeta> {
73
+ return syscall("space.writePage", name, text);
74
+ }
75
+
76
+ /**
77
+ * Delete a page from the space.
78
+ * @param name the name of the page to delete
79
+ */
80
+ export function deletePage(name: string): Promise<void> {
81
+ return syscall("space.deletePage", name);
82
+ }
83
+
84
+ /**
85
+ * List all plugs in the space.
86
+ * @returns a list of all plugs in the space represented as FileMeta objects
87
+ */
88
+ export function listPlugs(): Promise<FileMeta[]> {
89
+ return syscall("space.listPlugs");
90
+ }
91
+
92
+ /**
93
+ * Lists all documents in the space (all files not ending in .md).
94
+ * @returns a list of all documents in the space represented as DocumentMeta objects
95
+ */
96
+ export function listDocuments(): Promise<DocumentMeta[]> {
97
+ return syscall("space.listDocuments");
98
+ }
99
+
100
+ /**
101
+ * Get metadata for an document in the space.
102
+ * @param name the path of the document to get metadata for
103
+ * @returns the metadata for the document
104
+ */
105
+ export function getDocumentMeta(name: string): Promise<DocumentMeta> {
106
+ return syscall("space.getDocumentMeta", name);
107
+ }
108
+
109
+ /**
110
+ * Read an document from the space
111
+ * @param name path of the document to read
112
+ * @returns the document data as a UInt8Array
113
+ */
114
+ export function readDocument(
115
+ name: string,
116
+ ): Promise<Uint8Array> {
117
+ return syscall("space.readDocument", name);
118
+ }
119
+
120
+ /**
121
+ * Writes a document to the space
122
+ * @param name path of the document to write
123
+ * @param data data itself
124
+ * @returns
125
+ */
126
+ export function writeDocument(
127
+ name: string,
128
+ data: Uint8Array,
129
+ ): Promise<DocumentMeta> {
130
+ return syscall("space.writeDocument", name, data);
131
+ }
132
+
133
+ /**
134
+ * Deletes a document from the space
135
+ * @param name path of the document to delete
136
+ */
137
+ export function deleteDocument(name: string): Promise<void> {
138
+ return syscall("space.deleteDocument", name);
139
+ }
140
+
141
+ // Lower level-file operations
142
+
143
+ /**
144
+ * List all files in the space (pages, documents and plugs).
145
+ * @returns a list of all files in the space represented as FileMeta objects
146
+ */
147
+ export function listFiles(): Promise<FileMeta[]> {
148
+ return syscall("space.listFiles");
149
+ }
150
+
151
+ /**
152
+ * Read a file from the space as a Uint8Array.
153
+ * @param name the name of the file to read
154
+ * @returns the data of the file
155
+ */
156
+ export function readFile(name: string): Promise<Uint8Array> {
157
+ return syscall("space.readFile", name);
158
+ }
159
+
160
+ /**
161
+ * Reads a reference (e.g. page#header or page@20) and returns it as a string
162
+ */
163
+ export function readRef(ref: string | Ref): Promise<string> {
164
+ return syscall("space.readRef", ref);
165
+ }
166
+
167
+ /**
168
+ * Read a file from the space returning both its data and meta data
169
+ * @param name the name of the page to read
170
+ * @returns
171
+ * - data: file content
172
+ * - meta: pageMeta
173
+ */
174
+ export function readFileWithMeta(
175
+ name: string,
176
+ ): Promise<{ data: Uint8Array; meta: FileMeta }> {
177
+ return syscall("space.readFileWithMeta", name);
178
+ }
179
+
180
+ /**
181
+ * Get metadata for a file in the space.
182
+ * @param name the name of the file to get metadata for
183
+ * @returns the metadata for the file
184
+ */
185
+ export function getFileMeta(name: string): Promise<FileMeta> {
186
+ return syscall("space.getFileMeta", name);
187
+ }
188
+
189
+ /**
190
+ * Write a file to the space.
191
+ * @param name the name of the file to write
192
+ * @param data the data of the file to write
193
+ * @returns the metadata for the written file
194
+ */
195
+ export function writeFile(
196
+ name: string,
197
+ data: Uint8Array,
198
+ ): Promise<FileMeta> {
199
+ return syscall("space.writeFile", name, data);
200
+ }
201
+
202
+ /**
203
+ * Delete a file from the space.
204
+ * @param name the name of the file to delete
205
+ */
206
+ export function deleteFile(name: string): Promise<void> {
207
+ return syscall("space.deleteFile", name);
208
+ }
209
+
210
+ export function fileExists(name: string): Promise<boolean> {
211
+ return syscall("space.fileExists", name);
212
+ }
@@ -0,0 +1,28 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ /**
4
+ * Syscalls that interact with the sync engine (when the client runs in Sync mode)
5
+ * @module
6
+ */
7
+
8
+ /**
9
+ * Checks if an initial sync has completed
10
+ */
11
+ export function hasInitialSyncCompleted(): Promise<boolean> {
12
+ return syscall("sync.hasInitialSyncCompleted");
13
+ }
14
+
15
+ /**
16
+ * Syncs a file immediately. Sync would happen automatically, but this prioritizes the file.
17
+ * @param path the path to the file to sync
18
+ */
19
+ export function performFileSync(path: string): Promise<void> {
20
+ return syscall("sync.performFileSync", path);
21
+ }
22
+
23
+ /**
24
+ * Performs an immediate full sync.
25
+ */
26
+ export function performSpaceSync(): Promise<number> {
27
+ return syscall("sync.performSpaceSync");
28
+ }
@@ -0,0 +1,102 @@
1
+ import { syscall } from "../syscall.ts";
2
+ import type { CommandDef } from "../types/manifest.ts";
3
+ import type { SyscallMeta } from "@silverbulletmd/silverbullet/type/index";
4
+
5
+ /**
6
+ * System level syscalls
7
+ * @module
8
+ */
9
+
10
+ /**
11
+ * Invoke a plug function
12
+ * @param name a string representing the name of the function to invoke ("plug.functionName")
13
+ * @param args arguments to pass to the function
14
+ * @returns
15
+ */
16
+ export function invokeFunction(
17
+ name: string,
18
+ ...args: any[]
19
+ ): Promise<any> {
20
+ return syscall("system.invokeFunction", name, ...args);
21
+ }
22
+
23
+ /**
24
+ * Invoke a client command by name
25
+ * Note: only available on the client
26
+ * @param name name of the command
27
+ * @param args arguments to pass to the command
28
+ */
29
+ export function invokeCommand(name: string, args?: string[]): Promise<any> {
30
+ return syscall("system.invokeCommand", name, args);
31
+ }
32
+
33
+ /**
34
+ * Lists all commands available
35
+ * @returns a map of all available commands
36
+ */
37
+ export function listCommands(): Promise<Record<string, CommandDef>> {
38
+ return syscall("system.listCommands");
39
+ }
40
+
41
+ /**
42
+ * Lists all syscalls available
43
+ * @returns a list of all available syscalls
44
+ */
45
+ export function listSyscalls(): Promise<SyscallMeta[]> {
46
+ return syscall("system.listSyscalls");
47
+ }
48
+
49
+ /**
50
+ * Trigger a reload of all plugs
51
+ * @returns
52
+ */
53
+ export function reloadPlugs(): Promise<void> {
54
+ return syscall("system.reloadPlugs");
55
+ }
56
+
57
+ /**
58
+ * Returns the current mode of the system, either "ro" (read-only) or "rw" (read-write)
59
+ */
60
+ export function getMode(): Promise<"ro" | "rw"> {
61
+ return syscall("system.getMode");
62
+ }
63
+
64
+ /**
65
+ * Returns the prefix set by SB_URL_PREFIX or "/" if the variable isn't set
66
+ */
67
+ export function getURLPrefix(): Promise<string> {
68
+ return syscall("system.getURLPrefix");
69
+ }
70
+
71
+ /**
72
+ * Returns the base URI for this SilverBullet isntance
73
+ */
74
+ export function getBaseURI(): Promise<string> {
75
+ return syscall("system.getBaseURI");
76
+ }
77
+
78
+ /**
79
+ * Returns the SilverBullet version
80
+ */
81
+ export function getVersion(): Promise<string> {
82
+ return syscall("system.getVersion");
83
+ }
84
+
85
+ export function getConfig<T = any>(
86
+ key: string,
87
+ defaultValue: any = undefined,
88
+ ): Promise<T> {
89
+ return syscall("system.getConfig", key, defaultValue);
90
+ }
91
+
92
+ export function wipeClient(logout = false): Promise<void> {
93
+ return syscall("system.wipeClient", logout);
94
+ }
95
+
96
+ /**
97
+ * DEPRECATED
98
+ * Deletes all IndexedDB databases that are not connected to client (e.g. legacy databases)
99
+ */
100
+ export function cleanDatabases(): Promise<boolean> {
101
+ return syscall("system.cleanDatabases");
102
+ }
@@ -0,0 +1,28 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ /**
4
+ * YAML operations, exposed via `index` plug
5
+ * @module
6
+ */
7
+
8
+ /**
9
+ * Parses a YAML string into a JavaScript object.
10
+ * @param text the YAML text to parse
11
+ * @returns a JavaScript object representation of the YAML text
12
+ */
13
+ export function parse(
14
+ text: string,
15
+ ): Promise<any> {
16
+ return syscall("yaml.parse", text);
17
+ }
18
+
19
+ /**
20
+ * Converts a JavaScript object into a YAML string.
21
+ * @param obj the object to stringify
22
+ * @returns a YAML string representation of the object
23
+ */
24
+ export function stringify(
25
+ obj: any,
26
+ ): Promise<string> {
27
+ return syscall("yaml.stringify", obj);
28
+ }
@@ -0,0 +1,21 @@
1
+ export * as editor from "./syscalls/editor.ts";
2
+ export * as markdown from "./syscalls/markdown.ts";
3
+ export * as space from "./syscalls/space.ts";
4
+ export * as system from "./syscalls/system.ts";
5
+ export * as clientStore from "./syscalls/client_store.ts";
6
+ export * as sync from "./syscalls/sync.ts";
7
+ export * as language from "./syscalls/language.ts";
8
+ export * as codeWidget from "./syscalls/code_widget.ts";
9
+ export * as asset from "./syscalls/asset.ts";
10
+ export * as events from "./syscalls/event.ts";
11
+ export * as shell from "./syscalls/shell.ts";
12
+ export * as mq from "./syscalls/mq.ts";
13
+ export * as datastore from "./syscalls/datastore.ts";
14
+ export * as jsonschema from "./syscalls/jsonschema.ts";
15
+ export * as lua from "./syscalls/lua.ts";
16
+ export * as config from "./syscalls/config.ts";
17
+
18
+ // Not technically syscalls, but we want to export them for convenience
19
+ export * as index from "./syscalls/index.ts";
20
+
21
+ export * from "./syscall.ts";