@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.
Files changed (63) hide show
  1. package/README.md +36 -23
  2. package/client/plugos/hooks/syscall.ts +24 -10
  3. package/client/plugos/syscalls/asset.ts +61 -23
  4. package/client/plugos/syscalls/clientStore.ts +32 -6
  5. package/client/plugos/syscalls/client_code_widget.ts +9 -4
  6. package/client/plugos/syscalls/code_widget.ts +26 -11
  7. package/client/plugos/syscalls/config.ts +146 -30
  8. package/client/plugos/syscalls/datastore.ts +146 -40
  9. package/client/plugos/syscalls/editor.ts +1432 -711
  10. package/client/plugos/syscalls/event.ts +46 -13
  11. package/client/plugos/syscalls/fetch.ts +123 -82
  12. package/client/plugos/syscalls/index.ts +242 -116
  13. package/client/plugos/syscalls/jsonschema.ts +107 -8
  14. package/client/plugos/syscalls/language.ts +38 -12
  15. package/client/plugos/syscalls/markdown.ts +166 -50
  16. package/client/plugos/syscalls/mq.ts +93 -20
  17. package/client/plugos/syscalls/schema_introspection.ts +33 -0
  18. package/client/plugos/syscalls/service_registry.ts +74 -20
  19. package/client/plugos/syscalls/shell.ts +51 -20
  20. package/client/plugos/syscalls/space.ts +169 -113
  21. package/client/plugos/syscalls/sync.ts +50 -19
  22. package/client/plugos/syscalls/system.ts +236 -139
  23. package/client/plugos/system.ts +21 -5
  24. package/client/space_lua/api_documentation.ts +107 -0
  25. package/client/space_lua/ast.ts +13 -0
  26. package/client/space_lua/eval.ts +12 -4
  27. package/client/space_lua/parse.ts +243 -108
  28. package/client/space_lua/pretty_print.ts +128 -54
  29. package/client/space_lua/query_collection.ts +4 -4
  30. package/client/space_lua/render_widget.ts +156 -0
  31. package/client/space_lua/runtime.ts +83 -22
  32. package/client/space_lua/stdlib/crypto.ts +8 -3
  33. package/client/space_lua/stdlib/encoding.ts +27 -9
  34. package/client/space_lua/stdlib/js.ts +137 -22
  35. package/client/space_lua/stdlib/load.ts +24 -15
  36. package/client/space_lua/stdlib/math.ts +323 -118
  37. package/client/space_lua/stdlib/net.ts +57 -9
  38. package/client/space_lua/stdlib/os.ts +111 -44
  39. package/client/space_lua/stdlib/space_lua.ts +344 -20
  40. package/client/space_lua/stdlib/string.ts +282 -104
  41. package/client/space_lua/stdlib/string_pack.ts +58 -19
  42. package/client/space_lua/stdlib/table.ts +195 -40
  43. package/client/space_lua/stdlib.ts +335 -93
  44. package/client/space_lua/syscalls.ts +270 -0
  45. package/dist/plug-compile.js +1 -1
  46. package/package.json +3 -3
  47. package/plug-api/lib/ref.ts +96 -0
  48. package/plug-api/lib/shortcut.ts +2 -1
  49. package/plug-api/syscalls/config.ts +5 -3
  50. package/plug-api/syscalls/editor.ts +16 -0
  51. package/plug-api/syscalls/index.ts +17 -1
  52. package/plug-api/syscalls/jsonschema.ts +9 -0
  53. package/plug-api/syscalls/lua.ts +7 -0
  54. package/plug-api/syscalls/shell.ts +0 -1
  55. package/plug-api/syscalls/system.ts +7 -0
  56. package/plug-api/system_mock.ts +2 -2
  57. package/plug-api/types/index.ts +52 -1
  58. package/plug-api/types/manifest.ts +22 -4
  59. package/plug-api/ui/cx.ts +1 -3
  60. package/plug-api/ui/index.ts +3 -0
  61. package/plug-api/ui/panel_styles.ts +4 -3
  62. package/plug-api/ui/slugify.ts +44 -0
  63. package/client/plugos/syscalls/lua.ts +0 -81
@@ -25,65 +25,171 @@ export function dataStoreReadSyscalls(
25
25
  clientSystem: ClientSystem,
26
26
  ): SysCallMapping {
27
27
  return {
28
- "datastore.batchGet": (
29
- _ctx,
30
- keys: KvKey[],
31
- ): Promise<(any | undefined)[]> => {
32
- return ds.batchGet(keys);
28
+ "datastore.batchGet": {
29
+ callback: (_ctx, keys: KvKey[]): Promise<(any | undefined)[]> => {
30
+ return ds.batchGet(keys);
31
+ },
32
+ description: "Gets multiple values from the key-value store.",
33
+ parameters: [
34
+ { name: "keys", type: "table", description: "List of keys to read." },
35
+ ],
36
+ returns: [
37
+ {
38
+ type: "table",
39
+ description: "Values in key order, with nil for missing keys.",
40
+ },
41
+ ],
42
+ examples: [
43
+ {
44
+ code: 'local values = datastore.batchGet({{"user", "1"}, {"user", "2"}})',
45
+ },
46
+ ],
33
47
  },
34
48
 
35
- "datastore.get": (_ctx, key: KvKey): Promise<any | null> => {
36
- return ds.get(key);
49
+ "datastore.get": {
50
+ callback: (_ctx, key: KvKey): Promise<any | null> => {
51
+ return ds.get(key);
52
+ },
53
+ description: "Gets a value from the key-value store.",
54
+ parameters: [
55
+ { name: "key", type: "table", description: "Key segments." },
56
+ ],
57
+ returns: [{ description: "Stored value, or nil when absent." }],
58
+ examples: [{ code: 'local user = datastore.get({"user", "123"})' }],
37
59
  },
38
60
 
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;
61
+ "datastore.query": {
62
+ callback: async (_ctx, options: KvQueryOptions): Promise<KV[]> => {
63
+ const results: KV[] = [];
64
+ for await (const item of ds.query(options)) {
65
+ results.push(item);
66
+ }
67
+ return results;
68
+ },
69
+ description:
70
+ "Queries key-value entries, optionally restricted to a key prefix.",
71
+ parameters: [
72
+ {
73
+ name: "options",
74
+ type: "table",
75
+ description: "Query options, including an optional prefix.",
76
+ },
77
+ ],
78
+ returns: [{ type: "table", description: "Matching key-value entries." }],
45
79
  },
46
80
 
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));
81
+ "datastore.queryLua": {
82
+ callback: async (
83
+ _ctx,
84
+ prefix: string[],
85
+ query: LuaCollectionQuery,
86
+ scopeVariables?: Record<string, any>,
87
+ ): Promise<any[]> => {
88
+ const sf = LuaStackFrame.createWithGlobalEnv(
89
+ clientSystem.spaceLuaEnv.env,
90
+ );
91
+ let env = clientSystem.spaceLuaEnv.env;
92
+ if (scopeVariables) {
93
+ env = new LuaEnv(clientSystem.spaceLuaEnv.env);
94
+ for (const [key, value] of Object.entries(scopeVariables)) {
95
+ env.setLocal(key, jsToLuaValue(value));
96
+ }
61
97
  }
62
- }
63
- return (await queryLua<any>(ds.kv, prefix, query, env, sf)).map((item) =>
64
- luaValueToJS(item, sf),
65
- );
98
+ return (await queryLua<any>(ds.kv, prefix, query, env, sf)).map(
99
+ (item) => luaValueToJS(item, sf),
100
+ );
101
+ },
102
+ description: "Runs a Space Lua collection query over a key prefix.",
103
+ parameters: [
104
+ {
105
+ name: "prefix",
106
+ type: "table",
107
+ description: "Key prefix to query.",
108
+ },
109
+ {
110
+ name: "query",
111
+ type: "table",
112
+ description: "Parsed collection query.",
113
+ },
114
+ {
115
+ name: "scopeVariables",
116
+ type: "table",
117
+ description: "Additional variables available to the query.",
118
+ optional: true,
119
+ },
120
+ ],
121
+ returns: [
122
+ {
123
+ type: "table",
124
+ description: "Query results converted to Lua values.",
125
+ },
126
+ ],
66
127
  },
67
128
  };
68
129
  }
69
130
 
70
131
  export function dataStoreWriteSyscalls(ds: DataStore): SysCallMapping {
71
132
  return {
72
- "datastore.delete": (_ctx, key: KvKey) => {
73
- console.log("Deleting key", key);
74
- return ds.delete(key);
133
+ "datastore.delete": {
134
+ callback: (_ctx, key: KvKey) => {
135
+ console.log("Deleting key", key);
136
+ return ds.delete(key);
137
+ },
138
+ description: "Deletes a value from the key-value store.",
139
+ parameters: [
140
+ { name: "key", type: "table", description: "Key segments." },
141
+ ],
142
+ examples: [{ code: 'datastore.delete({"user", "123"})' }],
75
143
  },
76
144
 
77
- "datastore.set": (_ctx, key: KvKey, value: any) => {
78
- return ds.set(key, value);
145
+ "datastore.set": {
146
+ callback: (_ctx, key: KvKey, value: any) => {
147
+ return ds.set(key, value);
148
+ },
149
+ description: "Sets a value in the key-value store.",
150
+ parameters: [
151
+ { name: "key", type: "table", description: "Key segments." },
152
+ { name: "value", description: "Value to store." },
153
+ ],
154
+ examples: [{ code: 'datastore.set({"user", "123"}, {name = "John"})' }],
79
155
  },
80
156
 
81
- "datastore.batchSet": (_ctx, kvs: KV[]) => {
82
- return ds.batchSet(kvs);
157
+ "datastore.batchSet": {
158
+ callback: (_ctx, kvs: KV[]) => {
159
+ return ds.batchSet(kvs);
160
+ },
161
+ description: "Sets multiple key-value entries in one operation.",
162
+ parameters: [
163
+ {
164
+ name: "entries",
165
+ type: "table",
166
+ description: "Entries with key and value fields.",
167
+ },
168
+ ],
169
+ examples: [
170
+ {
171
+ code: 'datastore.batchSet({\n {key = {"user", "1"}, value = {name = "Alice"}},\n {key = {"user", "2"}, value = {name = "Bob"}},\n})',
172
+ },
173
+ ],
83
174
  },
84
175
 
85
- "datastore.batchDelete": (_ctx, keys: KvKey[]) => {
86
- return ds.batchDelete(keys);
176
+ "datastore.batchDelete": {
177
+ callback: (_ctx, keys: KvKey[]) => {
178
+ return ds.batchDelete(keys);
179
+ },
180
+ description: "Deletes multiple values from the key-value store.",
181
+ parameters: [
182
+ {
183
+ name: "keys",
184
+ type: "table",
185
+ description: "List of keys to delete.",
186
+ },
187
+ ],
188
+ examples: [
189
+ {
190
+ code: 'datastore.batchDelete({{"user", "1"}, {"user", "2"}})',
191
+ },
192
+ ],
87
193
  },
88
194
  };
89
195
  }