@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
@@ -58,8 +58,14 @@ export const tableApi = new LuaTable({
58
58
  * @param j - The end index.
59
59
  * @returns The concatenated string.
60
60
  */
61
- concat: new LuaBuiltinFunction(
62
- async (sf, tbl: LuaTable | any[], sep?: string, i?: number, j?: number) => {
61
+ concat: new LuaBuiltinFunction({
62
+ callback: async (
63
+ sf,
64
+ tbl: LuaTable | any[],
65
+ sep?: string,
66
+ i?: number,
67
+ j?: number,
68
+ ) => {
63
69
  sep = sep ?? "";
64
70
  i = i ?? 1;
65
71
  if (j === undefined || j === null) {
@@ -108,7 +114,16 @@ export const tableApi = new LuaTable({
108
114
  }
109
115
  return out.join(sep);
110
116
  },
111
- ),
117
+ description:
118
+ "Concatenates table elements from `i` through `j` using an optional separator.",
119
+ parameters: [
120
+ { name: "table", type: "table" },
121
+ { name: "sep", type: "string", optional: true },
122
+ { name: "i", type: "integer", optional: true },
123
+ { name: "j", type: "integer", optional: true },
124
+ ],
125
+ returns: [{ type: "string" }],
126
+ }),
112
127
 
113
128
  /**
114
129
  * Inserts an element into a table at a specified position.
@@ -116,8 +131,8 @@ export const tableApi = new LuaTable({
116
131
  * @param posOrValue - The position or value to insert.
117
132
  * @param value - The value to insert.
118
133
  */
119
- insert: new LuaBuiltinFunction(
120
- async (
134
+ insert: new LuaBuiltinFunction({
135
+ callback: async (
121
136
  sf,
122
137
  tbl: LuaTable | any[],
123
138
  posOrValue: number | any,
@@ -159,15 +174,38 @@ export const tableApi = new LuaTable({
159
174
 
160
175
  await luaSet(tbl, pos, v, sf);
161
176
  },
162
- ),
177
+ description:
178
+ "Inserts a value at a position, shifting later elements, or appends it when no position is supplied.",
179
+ signatures: [
180
+ "table.insert(table, value)",
181
+ "table.insert(table, pos, value)",
182
+ ],
183
+ parameters: [
184
+ { name: "table", type: "table" },
185
+ {
186
+ name: "posOrValue",
187
+ description: "Insertion position or appended value.",
188
+ },
189
+ {
190
+ name: "value",
191
+ description: "Value for positional insertion.",
192
+ optional: true,
193
+ },
194
+ ],
195
+ examples: [
196
+ {
197
+ code: 'local fruits = {"apple", "orange"}\ntable.insert(fruits, 2, "banana")\nprint(table.concat(fruits, ", "))',
198
+ },
199
+ ],
200
+ }),
163
201
 
164
202
  /**
165
203
  * Removes an element from a table at a specified position.
166
204
  * @param tbl - The table to remove the element from.
167
205
  * @param pos - The position of the element to remove.
168
206
  */
169
- remove: new LuaBuiltinFunction(
170
- async (sf, tbl: LuaTable | any[], pos?: number) => {
207
+ remove: new LuaBuiltinFunction({
208
+ callback: async (sf, tbl: LuaTable | any[], pos?: number) => {
171
209
  if (Array.isArray(tbl)) {
172
210
  const n = tbl.length;
173
211
  const p = pos ?? n;
@@ -202,7 +240,19 @@ export const tableApi = new LuaTable({
202
240
 
203
241
  return v;
204
242
  },
205
- ),
243
+ description:
244
+ "Removes and returns an element, shifting later elements down.",
245
+ parameters: [
246
+ { name: "table", type: "table" },
247
+ {
248
+ name: "pos",
249
+ type: "integer",
250
+ description: "Position; defaults to the last element.",
251
+ optional: true,
252
+ },
253
+ ],
254
+ returns: [{ description: "Removed value." }],
255
+ }),
206
256
 
207
257
  /**
208
258
  * Moves elements from table a1 into table a2 (defaults to a1).
@@ -215,8 +265,8 @@ export const tableApi = new LuaTable({
215
265
  * @param a2 - Destination table (defaults to a1).
216
266
  * @returns a2.
217
267
  */
218
- move: new LuaBuiltinFunction(
219
- async (
268
+ move: new LuaBuiltinFunction({
269
+ callback: async (
220
270
  sf,
221
271
  a1: LuaTable | any[],
222
272
  f: number,
@@ -252,7 +302,22 @@ export const tableApi = new LuaTable({
252
302
 
253
303
  return a2;
254
304
  },
255
- ),
305
+ description:
306
+ "Moves an inclusive element range to a destination table while handling overlaps.",
307
+ parameters: [
308
+ { name: "a1", type: "table", description: "Source table." },
309
+ { name: "f", type: "integer", description: "First source index." },
310
+ { name: "e", type: "integer", description: "Last source index." },
311
+ { name: "t", type: "integer", description: "Destination start index." },
312
+ {
313
+ name: "a2",
314
+ type: "table",
315
+ description: "Destination table; defaults to `a1`.",
316
+ optional: true,
317
+ },
318
+ ],
319
+ returns: [{ type: "table", description: "Destination table." }],
320
+ }),
256
321
 
257
322
  /**
258
323
  * Sorts a table.
@@ -260,8 +325,8 @@ export const tableApi = new LuaTable({
260
325
  * @param comp - The comparison function.
261
326
  * @returns The sorted table.
262
327
  */
263
- sort: new LuaBuiltinFunction(
264
- async (sf, tbl: LuaTable | any[], comp?: ILuaFunction) => {
328
+ sort: new LuaBuiltinFunction({
329
+ callback: async (sf, tbl: LuaTable | any[], comp?: ILuaFunction) => {
265
330
  if (Array.isArray(tbl)) {
266
331
  return await asyncQuickSort(tbl, async (a, b) => {
267
332
  if (comp) {
@@ -311,7 +376,19 @@ export const tableApi = new LuaTable({
311
376
 
312
377
  return tbl;
313
378
  },
314
- ),
379
+ description:
380
+ "Sorts a table in place using ascending order or an optional comparison function.",
381
+ parameters: [
382
+ { name: "table", type: "table" },
383
+ { name: "comp", type: "function", optional: true },
384
+ ],
385
+ returns: [{ type: "table", description: "The sorted table in Space Lua." }],
386
+ examples: [
387
+ {
388
+ code: "local numbers = {3, 1, 2}\ntable.sort(numbers, function(a, b) return a > b end)",
389
+ },
390
+ ],
391
+ }),
315
392
 
316
393
  /**
317
394
  * Returns the keys of a table.
@@ -319,11 +396,17 @@ export const tableApi = new LuaTable({
319
396
  * @param tbl - The table to get the keys from.
320
397
  * @returns The keys of the table.
321
398
  */
322
- keys: new LuaBuiltinFunction((_sf, tbl: LuaTable | LuaEnv | any) => {
323
- if (tbl.keys) {
324
- return tbl.keys();
325
- }
326
- return Object.keys(tbl);
399
+ keys: new LuaBuiltinFunction({
400
+ callback: (_sf, tbl: LuaTable | LuaEnv | any) => {
401
+ if (tbl.keys) {
402
+ return tbl.keys();
403
+ }
404
+ return Object.keys(tbl);
405
+ },
406
+ description:
407
+ "Returns an array containing all keys of a table or JavaScript object.",
408
+ parameters: [{ name: "table", type: "table" }],
409
+ returns: [{ type: "table", description: "Array of keys." }],
327
410
  }),
328
411
 
329
412
  /**
@@ -333,8 +416,8 @@ export const tableApi = new LuaTable({
333
416
  * @param value - The value to check for.
334
417
  * @returns True if the value is in the table, false otherwise.
335
418
  */
336
- includes: new LuaBuiltinFunction(
337
- (sf, tbl: LuaTable | any[], value: LuaValue) => {
419
+ includes: new LuaBuiltinFunction({
420
+ callback: (sf, tbl: LuaTable | any[], value: LuaValue) => {
338
421
  if (!tbl) {
339
422
  return false;
340
423
  }
@@ -355,7 +438,14 @@ export const tableApi = new LuaTable({
355
438
  sf,
356
439
  );
357
440
  },
358
- ),
441
+ description:
442
+ "Returns whether any table value is Lua-equal to a requested value.",
443
+ parameters: [
444
+ { name: "table", type: "table" },
445
+ { name: "value", description: "Value to find." },
446
+ ],
447
+ returns: [{ type: "boolean" }],
448
+ }),
359
449
 
360
450
  /**
361
451
  * Returns a new table from an old one, only with selected keys
@@ -363,8 +453,12 @@ export const tableApi = new LuaTable({
363
453
  * @param keys a list of keys to select from the table, if keys[0] is a table or array, assumed to contain the keys to select
364
454
  * @returns a new table with only the selected keys
365
455
  */
366
- select: new LuaBuiltinFunction(
367
- (sf, tbl: LuaTable | Record<string, any>, ...keys: LuaValue[]) => {
456
+ select: new LuaBuiltinFunction({
457
+ callback: (
458
+ sf,
459
+ tbl: LuaTable | Record<string, any>,
460
+ ...keys: LuaValue[]
461
+ ) => {
368
462
  // Normalize arguments
369
463
  if (Array.isArray(keys[0])) {
370
464
  // First argument is key array, let's unpack
@@ -383,20 +477,50 @@ export const tableApi = new LuaTable({
383
477
  }
384
478
  return resultTable;
385
479
  },
386
- ),
480
+ description: "Copies selected keys from a table into a new table.",
481
+ signatures: [
482
+ "table.select(table, ...keys): table",
483
+ "table.select(table, keys): table",
484
+ ],
485
+ parameters: [
486
+ { name: "table", type: "table" },
487
+ {
488
+ name: "keys",
489
+ description: "Individual keys or one array-like table of keys.",
490
+ },
491
+ ],
492
+ returns: [{ type: "table" }],
493
+ examples: [
494
+ {
495
+ code: '${query[[\n from p = index.pages()\n limit 3\n select table.select(p, "name", "lastModified")\n]]}',
496
+ language: "markdown",
497
+ },
498
+ ],
499
+ }),
387
500
 
388
501
  /**
389
502
  * Returns a new table with all arguments stored in keys 1, 2, ..., n
390
503
  * and t.n = n (the total number of arguments).
391
504
  */
392
- pack: new LuaBuiltinFunction(async (sf, ...args: any[]) => {
393
- const tbl = new LuaTable();
394
- const n = args.length;
395
- for (let i = 0; i < n; i++) {
396
- await luaSet(tbl, i + 1, args[i], sf);
397
- }
398
- void tbl.rawSet("n", n);
399
- return tbl;
505
+ pack: new LuaBuiltinFunction({
506
+ callback: async (sf, ...args: any[]) => {
507
+ const tbl = new LuaTable();
508
+ const n = args.length;
509
+ for (let i = 0; i < n; i++) {
510
+ await luaSet(tbl, i + 1, args[i], sf);
511
+ }
512
+ void tbl.rawSet("n", n);
513
+ return tbl;
514
+ },
515
+ description:
516
+ "Packs all arguments into a table with a count stored in field `n`.",
517
+ signatures: ["table.pack(...): table"],
518
+ returns: [
519
+ {
520
+ type: "table",
521
+ description: "Arguments at integer keys plus field `n`.",
522
+ },
523
+ ],
400
524
  }),
401
525
 
402
526
  /**
@@ -404,8 +528,8 @@ export const tableApi = new LuaTable({
404
528
  * i defaults to 1, j defaults to #t (honours __len).
405
529
  * Empty range returns no values (null), not an empty multi-res.
406
530
  */
407
- unpack: new LuaBuiltinFunction(
408
- async (sf, tbl: LuaTable | any[], i?: number, j?: number) => {
531
+ unpack: new LuaBuiltinFunction({
532
+ callback: async (sf, tbl: LuaTable | any[], i?: number, j?: number) => {
409
533
  i = i === undefined || i === null ? 1 : i;
410
534
  if (j === undefined || j === null) {
411
535
  j = Array.isArray(tbl)
@@ -425,7 +549,18 @@ export const tableApi = new LuaTable({
425
549
  }
426
550
  return new LuaMultiRes(result);
427
551
  },
428
- ),
552
+ description:
553
+ "Returns the table values from index `i` through `j` as separate results.",
554
+ parameters: [
555
+ { name: "table", type: "table" },
556
+ { name: "i", type: "integer", optional: true },
557
+ { name: "j", type: "integer", optional: true },
558
+ ],
559
+ returns: [{ description: "One result per selected element." }],
560
+ examples: [
561
+ { code: 'local second, third = table.unpack({"a", "b", "c"}, 2, 3)' },
562
+ ],
563
+ }),
429
564
 
430
565
  // Non-standard Lua functions
431
566
  /**
@@ -435,8 +570,8 @@ export const tableApi = new LuaTable({
435
570
  * @param fromIndex - The index to start searching from.
436
571
  * @returns Lua multi value of index, value, or nil if no element is found.
437
572
  */
438
- find: new LuaBuiltinFunction(
439
- async (
573
+ find: new LuaBuiltinFunction({
574
+ callback: async (
440
575
  sf,
441
576
  tbl: LuaTable | any[],
442
577
  criteriaFn: ILuaFunction,
@@ -457,5 +592,25 @@ export const tableApi = new LuaTable({
457
592
  }
458
593
  return null;
459
594
  },
460
- ),
595
+ description:
596
+ "Finds the first array element accepted by a predicate and returns its index and value.",
597
+ parameters: [
598
+ { name: "table", type: "table" },
599
+ {
600
+ name: "criteriaFn",
601
+ type: "function",
602
+ description: "Predicate called with each value.",
603
+ },
604
+ { name: "fromIndex", type: "integer", optional: true },
605
+ ],
606
+ returns: [
607
+ { type: "integer|nil", description: "Matching index or `nil`." },
608
+ { description: "Matching value." },
609
+ ],
610
+ examples: [
611
+ {
612
+ code: "local index, value = table.find({1, 2, 3, 4}, function(n) return n % 2 == 0 end)",
613
+ },
614
+ ],
615
+ }),
461
616
  });