@silverbulletmd/silverbullet 2.9.0 → 2.11.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 (123) hide show
  1. package/README.md +38 -25
  2. package/client/asset_bundle/bundle.ts +0 -1
  3. package/client/config.ts +343 -0
  4. package/client/markdown_parser/constants.ts +3 -1
  5. package/client/plugos/hooks/command.ts +0 -5
  6. package/client/plugos/hooks/event.ts +0 -6
  7. package/client/plugos/hooks/mq.ts +0 -3
  8. package/client/plugos/hooks/slash_command.ts +1 -7
  9. package/client/plugos/hooks/syscall.ts +24 -14
  10. package/client/plugos/manifest_cache.ts +0 -32
  11. package/client/plugos/plug.ts +0 -3
  12. package/client/plugos/plug_compile.ts +3 -13
  13. package/client/plugos/sandboxes/worker_sandbox.ts +19 -9
  14. package/client/plugos/syscalls/asset.ts +61 -23
  15. package/client/plugos/syscalls/clientStore.ts +32 -6
  16. package/client/plugos/syscalls/client_code_widget.ts +9 -4
  17. package/client/plugos/syscalls/code_widget.ts +26 -11
  18. package/client/plugos/syscalls/config.ts +146 -30
  19. package/client/plugos/syscalls/datastore.ts +146 -40
  20. package/client/plugos/syscalls/editor.ts +1518 -722
  21. package/client/plugos/syscalls/event.ts +44 -13
  22. package/client/plugos/syscalls/fetch.ts +120 -83
  23. package/client/plugos/syscalls/icon.ts +46 -0
  24. package/client/plugos/syscalls/index.ts +267 -121
  25. package/client/plugos/syscalls/jsonschema.ts +107 -9
  26. package/client/plugos/syscalls/language.ts +38 -12
  27. package/client/plugos/syscalls/markdown.ts +166 -50
  28. package/client/plugos/syscalls/mq.ts +92 -20
  29. package/client/plugos/syscalls/navigator.ts +143 -0
  30. package/client/plugos/syscalls/schema_introspection.ts +33 -0
  31. package/client/plugos/syscalls/search.ts +44 -0
  32. package/client/plugos/syscalls/service_registry.ts +74 -20
  33. package/client/plugos/syscalls/shell.ts +51 -21
  34. package/client/plugos/syscalls/space.ts +412 -113
  35. package/client/plugos/syscalls/sync.ts +103 -20
  36. package/client/plugos/syscalls/system.ts +274 -139
  37. package/client/plugos/system.ts +28 -10
  38. package/client/plugos/worker_runtime.ts +0 -2
  39. package/client/space_lua/aggregates.ts +0 -16
  40. package/client/space_lua/api_documentation.ts +107 -0
  41. package/client/space_lua/ast.ts +13 -5
  42. package/client/space_lua/ast_narrow.ts +0 -5
  43. package/client/space_lua/budget.ts +113 -0
  44. package/client/space_lua/budget_ui.ts +49 -0
  45. package/client/space_lua/eval.ts +125 -92
  46. package/client/space_lua/labels.ts +0 -4
  47. package/client/space_lua/numeric.ts +0 -5
  48. package/client/space_lua/parse.ts +243 -125
  49. package/client/space_lua/pretty_print.ts +128 -54
  50. package/client/space_lua/quarantine.ts +127 -0
  51. package/client/space_lua/query_collection.ts +7 -51
  52. package/client/space_lua/query_env.ts +0 -2
  53. package/client/space_lua/render_lua_markdown.ts +2 -7
  54. package/client/space_lua/render_widget.ts +173 -0
  55. package/client/space_lua/runtime.ts +133 -92
  56. package/client/space_lua/stdlib/crypto.ts +8 -3
  57. package/client/space_lua/stdlib/encoding.ts +27 -9
  58. package/client/space_lua/stdlib/format.ts +0 -12
  59. package/client/space_lua/stdlib/js.ts +136 -23
  60. package/client/space_lua/stdlib/load.ts +24 -16
  61. package/client/space_lua/stdlib/math.ts +331 -133
  62. package/client/space_lua/stdlib/net.ts +57 -13
  63. package/client/space_lua/stdlib/os.ts +111 -54
  64. package/client/space_lua/stdlib/pattern.ts +10 -15
  65. package/client/space_lua/stdlib/space_lua.ts +344 -21
  66. package/client/space_lua/stdlib/string.ts +282 -104
  67. package/client/space_lua/stdlib/string_pack.ts +58 -22
  68. package/client/space_lua/stdlib/table.ts +195 -45
  69. package/client/space_lua/stdlib.ts +354 -125
  70. package/client/space_lua/syscalls.ts +270 -0
  71. package/client/space_lua/tonumber.ts +0 -9
  72. package/dist/plug-compile.js +2 -3
  73. package/package.json +15 -5
  74. package/plug-api/lib/async.ts +1 -6
  75. package/plug-api/lib/collation.ts +22 -0
  76. package/plug-api/lib/crypto.ts +16 -15
  77. package/plug-api/lib/dates.ts +33 -0
  78. package/plug-api/lib/fuzzy.ts +282 -0
  79. package/plug-api/lib/json.ts +0 -6
  80. package/plug-api/lib/limited_map.ts +0 -2
  81. package/plug-api/lib/link_write.ts +27 -0
  82. package/plug-api/{ui → lib}/panel_styles.ts +4 -3
  83. package/plug-api/lib/ref.ts +124 -5
  84. package/plug-api/lib/resolve.ts +0 -1
  85. package/plug-api/lib/resolve_path.ts +290 -0
  86. package/plug-api/lib/shortcut.ts +17 -1
  87. package/plug-api/lib/tags.ts +0 -3
  88. package/plug-api/lib/transclusion.ts +28 -1
  89. package/plug-api/lib/tree.ts +0 -5
  90. package/plug-api/lib/yaml.ts +3 -42
  91. package/plug-api/syscall.ts +1 -5
  92. package/plug-api/syscalls/config.ts +7 -5
  93. package/plug-api/syscalls/editor.ts +70 -208
  94. package/plug-api/syscalls/icon.ts +18 -0
  95. package/plug-api/syscalls/index.ts +39 -5
  96. package/plug-api/syscalls/jsonschema.ts +9 -0
  97. package/plug-api/syscalls/lua.ts +7 -0
  98. package/plug-api/syscalls/search.ts +11 -0
  99. package/plug-api/syscalls/shell.ts +0 -1
  100. package/plug-api/syscalls/space.ts +122 -5
  101. package/plug-api/syscalls/sync.ts +23 -2
  102. package/plug-api/syscalls/system.ts +53 -0
  103. package/plug-api/syscalls.ts +2 -0
  104. package/plug-api/system_mock.ts +15 -2
  105. package/plug-api/types/client.ts +4 -3
  106. package/plug-api/types/datastore.ts +11 -2
  107. package/plug-api/types/index.ts +62 -1
  108. package/plug-api/types/manifest.ts +22 -4
  109. package/plug-api/types/profile.ts +13 -0
  110. package/plug-api/types/revisions.ts +67 -0
  111. package/plug-api/ui/cx.ts +1 -3
  112. package/plug-api/ui/description.ts +64 -0
  113. package/plug-api/ui/hover.ts +69 -0
  114. package/plug-api/ui/index.ts +61 -2
  115. package/plug-api/ui/scroll.ts +30 -0
  116. package/plug-api/ui/slugify.ts +44 -0
  117. package/plug-api/ui/tree_model.ts +263 -0
  118. package/plug-api/ui/tree_types.ts +66 -0
  119. package/plug-api/ui/use_fit_collapse.ts +67 -0
  120. package/plugs/builtin_plugs.ts +0 -1
  121. package/plugs/index/types.ts +9 -0
  122. package/client/plugos/syscalls/lua.ts +0 -81
  123. package/plug-api/lib/memory_cache.ts +0 -21
@@ -5,45 +5,161 @@ import { stripFunctions } from "../util.ts";
5
5
 
6
6
  export function configSyscalls(config: Config): SysCallMapping {
7
7
  return {
8
- "config.get": (_ctx, path: string, defaultValue: any) => {
9
- return config.get(path, defaultValue);
8
+ "config.get": {
9
+ callback: (_ctx, path: string, defaultValue: any) => {
10
+ return config.get(path, defaultValue);
11
+ },
12
+ description:
13
+ "Gets a configuration value by path, with dot notation support.",
14
+ parameters: [
15
+ { name: "path", type: "string", description: "Configuration path." },
16
+ {
17
+ name: "defaultValue",
18
+ description: "Value returned when the path is absent.",
19
+ },
20
+ ],
21
+ returns: [{ description: "Configured value or the supplied default." }],
22
+ examples: [{ code: 'local theme = config.get("theme", "light")' }],
10
23
  },
11
- "config.set": (
12
- _ctx,
13
- keyOrValues: string | string[] | Record<string, any>,
14
- value?: any,
15
- ) => {
16
- config.set(keyOrValues as any, value);
24
+ "config.set": {
25
+ callback: (
26
+ _ctx,
27
+ keyOrValues: string | string[] | Record<string, any>,
28
+ value?: any,
29
+ ) => {
30
+ config.set(keyOrValues as any, value);
31
+ },
32
+ description: "Sets one configuration value or multiple values at once.",
33
+ signatures: ["config.set(path, value)", "config.set(values)"],
34
+ parameters: [
35
+ {
36
+ name: "pathOrValues",
37
+ description: "Configuration path or table of values.",
38
+ },
39
+ {
40
+ name: "value",
41
+ description: "Value to set when a path is supplied.",
42
+ optional: true,
43
+ },
44
+ ],
45
+ examples: [
46
+ { code: 'config.set("theme", "dark")' },
47
+ { code: 'config.set({theme = "dark", fontSize = 14})' },
48
+ ],
17
49
  },
18
- "lua:config.setLuaValue": async (
19
- _ctx,
20
- keyOrValues: string | string[] | Record<string, any>,
21
- value?: any,
22
- ) => {
23
- // This is for special cases where we explicitly want to NOT convert a value to a JS value, but maintain its Lua version (mostly for LuaTables) — main use case: metatable
24
- keyOrValues = await luaValueToJS(keyOrValues, LuaStackFrame.lostFrame);
25
- config.set(keyOrValues as any, value);
50
+ "lua:config.setLuaValue": {
51
+ callback: async (
52
+ _ctx,
53
+ keyOrValues: string | string[] | Record<string, any>,
54
+ value?: any,
55
+ ) => {
56
+ // This is for special cases where we explicitly want to NOT convert a value to a JS value, but maintain its Lua version (mostly for LuaTables) — main use case: metatable
57
+ keyOrValues = await luaValueToJS(keyOrValues, LuaStackFrame.lostFrame);
58
+ config.set(keyOrValues as any, value);
59
+ },
60
+ description:
61
+ "Sets configuration while preserving the supplied Lua value representation.",
62
+ signatures: [
63
+ "config.setLuaValue(path, value)",
64
+ "config.setLuaValue(values)",
65
+ ],
66
+ parameters: [
67
+ {
68
+ name: "pathOrValues",
69
+ description: "Configuration path or table of values.",
70
+ },
71
+ {
72
+ name: "value",
73
+ description: "Lua value to preserve.",
74
+ optional: true,
75
+ },
76
+ ],
26
77
  },
27
- "config.insert": (_ctx, key: string | string[], value: any) => {
28
- config.insert(key, value);
78
+ "config.insert": {
79
+ callback: (_ctx, key: string | string[], value: any) => {
80
+ config.insert(key, value);
81
+ },
82
+ description: "Appends a value to the configuration array at a path.",
83
+ parameters: [
84
+ { name: "path", description: "Configuration path." },
85
+ { name: "value", description: "Value to append." },
86
+ ],
29
87
  },
30
- "config.has": (_ctx, path: string) => {
31
- return config.has(path);
88
+ "config.has": {
89
+ callback: (_ctx, path: string) => {
90
+ return config.has(path);
91
+ },
92
+ description: "Checks whether a configuration path exists.",
93
+ parameters: [
94
+ { name: "path", type: "string", description: "Configuration path." },
95
+ ],
96
+ returns: [{ type: "boolean", description: "Whether the path exists." }],
32
97
  },
33
- "config.define": (_ctx, key: string, schema: any) => {
34
- config.define(key, schema);
98
+ "config.define": {
99
+ callback: (_ctx, key: string, schema: any) => {
100
+ config.define(key, schema);
101
+ },
102
+ description: "Defines a JSON schema for a configuration key.",
103
+ parameters: [
104
+ { name: "key", type: "string", description: "Configuration key." },
105
+ {
106
+ name: "schema",
107
+ type: "table",
108
+ description:
109
+ "JSON Schema definition; default applies a missing value and ui annotations expose it in the Configuration Manager.",
110
+ },
111
+ ],
112
+ examples: [
113
+ {
114
+ code: 'config.define("shortWikiLinks", {\n description = "Render short wiki link labels",\n type = "boolean",\n default = true,\n ui = {category = "Editor", label = "Short wiki links", priority = 1},\n})',
115
+ },
116
+ ],
35
117
  },
36
- "config.defineCategory": (_ctx, definition: any) => {
37
- config.defineCategory(definition);
118
+ "config.defineCategory": {
119
+ callback: (_ctx, definition: any) => {
120
+ config.defineCategory(definition);
121
+ },
122
+ description: "Defines or updates a Configuration Manager UI category.",
123
+ parameters: [
124
+ {
125
+ name: "definition",
126
+ type: "table",
127
+ description: "Category name, description, and priority.",
128
+ },
129
+ ],
130
+ examples: [
131
+ {
132
+ code: 'config.defineCategory {\n name = "Editor",\n description = "Page editor behavior.",\n priority = 50,\n}',
133
+ },
134
+ ],
38
135
  },
39
- "config.getValues": () => {
40
- return stripFunctions(config.values);
136
+ "config.getValues": {
137
+ callback: () => {
138
+ return stripFunctions(config.values);
139
+ },
140
+ description: "Gets all configuration values as a single table.",
141
+ returns: [{ type: "table", description: "All configuration values." }],
41
142
  },
42
- "config.getSchemas": () => {
43
- return stripFunctions(config.schemas);
143
+ "config.getSchemas": {
144
+ callback: () => {
145
+ return stripFunctions(config.schemas);
146
+ },
147
+ description: "Gets all defined configuration schemas.",
148
+ returns: [
149
+ {
150
+ type: "table",
151
+ description: "Schemas keyed by configuration path.",
152
+ },
153
+ ],
44
154
  },
45
- "config.getCategories": () => {
46
- return { ...config.categories };
155
+ "config.getCategories": {
156
+ callback: () => {
157
+ return { ...config.categories };
158
+ },
159
+ description: "Gets all Configuration Manager UI categories.",
160
+ returns: [
161
+ { type: "table", description: "Category definitions keyed by name." },
162
+ ],
47
163
  },
48
164
  };
49
165
  }
@@ -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
  }