@silverbulletmd/silverbullet 2.4.2 → 2.6.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.
- package/README.md +19 -4
- package/client/asset_bundle/bundle.ts +3 -9
- package/client/data/datastore.ts +4 -5
- package/client/markdown_parser/constants.ts +5 -4
- package/client/plugos/hooks/code_widget.ts +3 -8
- package/client/plugos/hooks/command.ts +8 -8
- package/client/plugos/hooks/document_editor.ts +10 -15
- package/client/plugos/hooks/event.ts +33 -36
- package/client/plugos/hooks/mq.ts +17 -17
- package/client/plugos/hooks/plug_namespace.ts +3 -8
- package/client/plugos/hooks/slash_command.ts +13 -28
- package/client/plugos/hooks/syscall.ts +3 -3
- package/client/plugos/manifest_cache.ts +22 -15
- package/client/plugos/plug.ts +2 -6
- package/client/plugos/plug_compile.ts +79 -78
- package/client/plugos/protocol.ts +28 -28
- package/client/plugos/proxy_fetch.ts +7 -6
- package/client/plugos/sandboxes/web_worker_sandbox.ts +1 -1
- package/client/plugos/sandboxes/worker_sandbox.ts +18 -18
- package/client/plugos/syscalls/asset.ts +1 -3
- package/client/plugos/syscalls/code_widget.ts +1 -3
- package/client/plugos/syscalls/config.ts +1 -5
- package/client/plugos/syscalls/datastore.ts +1 -1
- package/client/plugos/syscalls/editor.ts +72 -69
- package/client/plugos/syscalls/event.ts +9 -12
- package/client/plugos/syscalls/fetch.ts +31 -23
- package/client/plugos/syscalls/index.ts +10 -1
- package/client/plugos/syscalls/jsonschema.ts +72 -32
- package/client/plugos/syscalls/language.ts +9 -5
- package/client/plugos/syscalls/markdown.ts +29 -7
- package/client/plugos/syscalls/mq.ts +4 -12
- package/client/plugos/syscalls/service_registry.ts +1 -4
- package/client/plugos/syscalls/shell.ts +2 -5
- package/client/plugos/syscalls/space.ts +1 -1
- package/client/plugos/syscalls/sync.ts +69 -60
- package/client/plugos/syscalls/system.ts +2 -3
- package/client/plugos/system.ts +6 -12
- package/client/plugos/worker_runtime.ts +12 -33
- package/client/space_lua/aggregates.ts +782 -0
- package/client/space_lua/ast.ts +42 -8
- package/client/space_lua/ast_narrow.ts +4 -2
- package/client/space_lua/eval.ts +886 -575
- package/client/space_lua/labels.ts +7 -12
- package/client/space_lua/liq_null.ts +6 -0
- package/client/space_lua/numeric.ts +5 -8
- package/client/space_lua/parse.ts +346 -120
- package/client/space_lua/query_collection.ts +926 -82
- package/client/space_lua/query_env.ts +26 -0
- package/client/space_lua/render_lua_markdown.ts +369 -0
- package/client/space_lua/rp.ts +5 -4
- package/client/space_lua/runtime.ts +288 -155
- package/client/space_lua/stdlib/format.ts +53 -39
- package/client/space_lua/stdlib/js.ts +3 -7
- package/client/space_lua/stdlib/load.ts +1 -3
- package/client/space_lua/stdlib/math.ts +84 -58
- package/client/space_lua/stdlib/net.ts +27 -17
- package/client/space_lua/stdlib/os.ts +81 -85
- package/client/space_lua/stdlib/pattern.ts +695 -0
- package/client/space_lua/stdlib/prng.ts +148 -0
- package/client/space_lua/stdlib/space_lua.ts +17 -23
- package/client/space_lua/stdlib/string.ts +102 -190
- package/client/space_lua/stdlib/string_pack.ts +490 -0
- package/client/space_lua/stdlib/table.ts +76 -16
- package/client/space_lua/stdlib.ts +53 -39
- package/client/space_lua/tonumber.ts +82 -42
- package/client/space_lua/util.ts +53 -15
- package/dist/plug-compile.js +55 -98
- package/package.json +27 -20
- package/plug-api/constants.ts +0 -32
- package/plug-api/lib/async.ts +20 -7
- package/plug-api/lib/crypto.ts +16 -17
- package/plug-api/lib/dates.ts +15 -7
- package/plug-api/lib/json.ts +11 -5
- package/plug-api/lib/limited_map.ts +1 -1
- package/plug-api/lib/native_fetch.ts +2 -0
- package/plug-api/lib/ref.ts +23 -23
- package/plug-api/lib/resolve.ts +7 -11
- package/plug-api/lib/tags.ts +13 -4
- package/plug-api/lib/transclusion.ts +10 -21
- package/plug-api/lib/tree.ts +165 -45
- package/plug-api/lib/yaml.ts +35 -25
- package/plug-api/syscalls/asset.ts +1 -1
- package/plug-api/syscalls/config.ts +1 -4
- package/plug-api/syscalls/editor.ts +15 -15
- package/plug-api/syscalls/jsonschema.ts +1 -3
- package/plug-api/syscalls/lua.ts +3 -9
- package/plug-api/syscalls/mq.ts +1 -4
- package/plug-api/syscalls/shell.ts +4 -1
- package/plug-api/syscalls/space.ts +3 -10
- package/plug-api/syscalls/system.ts +1 -4
- package/plug-api/syscalls/yaml.ts +2 -6
- package/plug-api/system_mock.ts +0 -1
- package/plug-api/types/client.ts +16 -1
- package/plug-api/types/event.ts +6 -4
- package/plug-api/types/manifest.ts +8 -9
- package/plugs/builtin_plugs.ts +2 -2
- package/client/plugos/sandboxes/deno_worker_sandbox.ts +0 -6
|
@@ -16,9 +16,7 @@ function weekNumber(
|
|
|
16
16
|
|
|
17
17
|
if (iso) {
|
|
18
18
|
const target = new Date(date);
|
|
19
|
-
target.setUTCDate(
|
|
20
|
-
target.getUTCDate() + 3 - ((target.getUTCDay() + 6) % 7),
|
|
21
|
-
);
|
|
19
|
+
target.setUTCDate(target.getUTCDate() + 3 - ((target.getUTCDay() + 6) % 7));
|
|
22
20
|
|
|
23
21
|
const yearStart = new Date(Date.UTC(target.getUTCFullYear(), 0, 4));
|
|
24
22
|
const weekStart = new Date(yearStart);
|
|
@@ -34,11 +32,10 @@ function weekNumber(
|
|
|
34
32
|
const offset = (7 + (startDay - weekStartDay)) % 7;
|
|
35
33
|
const firstWeekStart = new Date(yearStart);
|
|
36
34
|
|
|
37
|
-
firstWeekStart.setUTCDate(yearStart.getUTCDate() + (7 - offset) % 7);
|
|
35
|
+
firstWeekStart.setUTCDate(yearStart.getUTCDate() + ((7 - offset) % 7));
|
|
38
36
|
|
|
39
37
|
if (date < firstWeekStart) return 0;
|
|
40
|
-
return 1 +
|
|
41
|
-
Math.floor((date.getTime() - firstWeekStart.getTime()) / ONE_WEEK);
|
|
38
|
+
return 1 + Math.floor((date.getTime() - firstWeekStart.getTime()) / ONE_WEEK);
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
function dayOfYear(d: Date, utc: boolean): number {
|
|
@@ -47,25 +44,25 @@ function dayOfYear(d: Date, utc: boolean): number {
|
|
|
47
44
|
|
|
48
45
|
const current = utc
|
|
49
46
|
? new Date(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
Date.UTC(
|
|
48
|
+
year,
|
|
49
|
+
d.getUTCMonth(),
|
|
50
|
+
d.getUTCDate(),
|
|
51
|
+
d.getUTCHours(),
|
|
52
|
+
d.getUTCMinutes(),
|
|
53
|
+
d.getUTCSeconds(),
|
|
54
|
+
),
|
|
55
|
+
)
|
|
59
56
|
: new Date(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
Date.UTC(
|
|
58
|
+
year,
|
|
59
|
+
d.getMonth(),
|
|
60
|
+
d.getDate(),
|
|
61
|
+
d.getHours(),
|
|
62
|
+
d.getMinutes(),
|
|
63
|
+
d.getSeconds(),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
69
66
|
|
|
70
67
|
return Math.floor((current.getTime() - start.getTime()) / ONE_DAY);
|
|
71
68
|
}
|
|
@@ -76,9 +73,7 @@ function isoWeekYear(d: Date, utc: boolean): number {
|
|
|
76
73
|
const day = utc ? d.getUTCDate() : d.getDate();
|
|
77
74
|
const target = new Date(Date.UTC(year, month, day));
|
|
78
75
|
|
|
79
|
-
target.setUTCDate(
|
|
80
|
-
target.getUTCDate() + 3 - ((target.getUTCDay() + 6) % 7),
|
|
81
|
-
);
|
|
76
|
+
target.setUTCDate(target.getUTCDate() + 3 - ((target.getUTCDay() + 6) % 7));
|
|
82
77
|
|
|
83
78
|
return target.getUTCFullYear();
|
|
84
79
|
}
|
|
@@ -138,7 +133,7 @@ function dateTable(d: Date, utc: boolean): LuaTable {
|
|
|
138
133
|
});
|
|
139
134
|
|
|
140
135
|
if (!utc) {
|
|
141
|
-
tbl.rawSet("isdst", isDST(d));
|
|
136
|
+
void tbl.rawSet("isdst", isDST(d));
|
|
142
137
|
}
|
|
143
138
|
|
|
144
139
|
return tbl;
|
|
@@ -146,107 +141,104 @@ function dateTable(d: Date, utc: boolean): LuaTable {
|
|
|
146
141
|
|
|
147
142
|
// Build the specifier map for a given `Date` and `utc` flag.
|
|
148
143
|
// Returns a record mapping single-char specifier to its output string.
|
|
149
|
-
function buildSpecMap(
|
|
150
|
-
d: Date,
|
|
151
|
-
utc: boolean,
|
|
152
|
-
): Record<string, () => string> {
|
|
144
|
+
function buildSpecMap(d: Date, utc: boolean): Record<string, () => string> {
|
|
153
145
|
const h = () => hr(d, utc);
|
|
154
146
|
const h12 = () => h() % 12 || 12;
|
|
155
147
|
const dow = () => wd(d, utc);
|
|
156
148
|
|
|
157
149
|
return {
|
|
158
150
|
// Date
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
Y: () => yr(d, utc).toString(),
|
|
152
|
+
y: () => pad2(yr(d, utc) % 100),
|
|
153
|
+
C: () => pad2(Math.floor(yr(d, utc) / 100)),
|
|
154
|
+
m: () => pad2(mo(d, utc) + 1),
|
|
155
|
+
d: () => pad2(da(d, utc)),
|
|
156
|
+
e: () => da(d, utc).toString().padStart(2, " "),
|
|
157
|
+
j: () => pad3(dayOfYear(d, utc)),
|
|
166
158
|
|
|
167
159
|
// Time
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
160
|
+
H: () => pad2(h()),
|
|
161
|
+
I: () => pad2(h12()),
|
|
162
|
+
M: () => pad2(mi(d, utc)),
|
|
163
|
+
S: () => pad2(sc(d, utc)),
|
|
164
|
+
p: () => (h() >= 12 ? "PM" : "AM"),
|
|
173
165
|
|
|
174
166
|
// Weekday
|
|
175
|
-
|
|
167
|
+
A: () =>
|
|
176
168
|
d.toLocaleString("en-US", {
|
|
177
169
|
weekday: "long",
|
|
178
170
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
179
171
|
}),
|
|
180
|
-
|
|
172
|
+
a: () =>
|
|
181
173
|
d.toLocaleString("en-US", {
|
|
182
174
|
weekday: "short",
|
|
183
175
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
184
176
|
}),
|
|
185
|
-
|
|
186
|
-
|
|
177
|
+
w: () => dow().toString(),
|
|
178
|
+
u: () => (dow() === 0 ? 7 : dow()).toString(),
|
|
187
179
|
|
|
188
180
|
// Month name
|
|
189
|
-
|
|
181
|
+
b: () =>
|
|
190
182
|
d.toLocaleString("en-US", {
|
|
191
183
|
month: "short",
|
|
192
184
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
193
185
|
}),
|
|
194
|
-
|
|
186
|
+
h: () =>
|
|
195
187
|
d.toLocaleString("en-US", {
|
|
196
188
|
month: "short",
|
|
197
189
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
198
190
|
}),
|
|
199
|
-
|
|
191
|
+
B: () =>
|
|
200
192
|
d.toLocaleString("en-US", {
|
|
201
193
|
month: "long",
|
|
202
194
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
203
195
|
}),
|
|
204
196
|
|
|
205
197
|
// Week number
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
U: () => pad2(weekNumber(d, utc, 0, false)),
|
|
199
|
+
W: () => pad2(weekNumber(d, utc, 1, false)),
|
|
200
|
+
V: () => pad2(weekNumber(d, utc, 1, true)),
|
|
201
|
+
G: () => isoWeekYear(d, utc).toString(),
|
|
202
|
+
g: () => pad2(isoWeekYear(d, utc) % 100),
|
|
211
203
|
|
|
212
204
|
// Composite specifiers
|
|
213
|
-
|
|
205
|
+
c: () =>
|
|
214
206
|
d.toLocaleString("en-US", {
|
|
215
207
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
216
208
|
}),
|
|
217
|
-
|
|
209
|
+
x: () =>
|
|
218
210
|
d.toLocaleDateString("en-US", {
|
|
219
211
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
220
212
|
}),
|
|
221
|
-
|
|
213
|
+
X: () =>
|
|
222
214
|
d.toLocaleTimeString("en-US", {
|
|
223
215
|
...(utc ? { timeZone: "UTC" } : {}),
|
|
224
216
|
}),
|
|
225
|
-
|
|
217
|
+
D: () =>
|
|
226
218
|
`${pad2(mo(d, utc) + 1)}/${pad2(da(d, utc))}/${pad2(yr(d, utc) % 100)}`,
|
|
227
|
-
|
|
219
|
+
F: () =>
|
|
228
220
|
`${yr(d, utc).toString()}-${pad2(mo(d, utc) + 1)}-${pad2(da(d, utc))}`,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
R: () => `${pad2(h())}:${pad2(mi(d, utc))}`,
|
|
222
|
+
T: () => `${pad2(h())}:${pad2(mi(d, utc))}:${pad2(sc(d, utc))}`,
|
|
223
|
+
r: () =>
|
|
232
224
|
`${pad2(h12())}:${pad2(mi(d, utc))}:${pad2(sc(d, utc))} ${
|
|
233
225
|
h() >= 12 ? "PM" : "AM"
|
|
234
226
|
}`,
|
|
235
227
|
|
|
236
228
|
// Epoch
|
|
237
|
-
|
|
229
|
+
s: () => Math.floor(d.getTime() / 1000).toString(),
|
|
238
230
|
|
|
239
231
|
// Whitespace
|
|
240
|
-
|
|
241
|
-
|
|
232
|
+
n: () => "\n",
|
|
233
|
+
t: () => "\t",
|
|
242
234
|
|
|
243
235
|
// Timezone
|
|
244
|
-
|
|
236
|
+
Z: () => {
|
|
245
237
|
if (utc) return "UTC";
|
|
246
238
|
const match = d.toTimeString().match(/\((.*)\)/);
|
|
247
239
|
return match ? match[1] : "";
|
|
248
240
|
},
|
|
249
|
-
|
|
241
|
+
z: () => {
|
|
250
242
|
if (utc) return "+0000";
|
|
251
243
|
const offset = -d.getTimezoneOffset();
|
|
252
244
|
const sign = offset >= 0 ? "+" : "-";
|
|
@@ -344,25 +336,29 @@ export const osApi = new LuaTable({
|
|
|
344
336
|
// Otherwise, format specifiers follow ISO C `strftime`.
|
|
345
337
|
//
|
|
346
338
|
// If format is absent, it defaults to `%c`.
|
|
347
|
-
date: new LuaBuiltinFunction(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
339
|
+
date: new LuaBuiltinFunction((_sf, format?: string, timestamp?: number) => {
|
|
340
|
+
let fmt = format ?? "%c";
|
|
341
|
+
let utc = false;
|
|
342
|
+
|
|
343
|
+
if (fmt.startsWith("!")) {
|
|
344
|
+
utc = true;
|
|
345
|
+
fmt = fmt.slice(1);
|
|
346
|
+
}
|
|
356
347
|
|
|
357
|
-
|
|
348
|
+
const d =
|
|
349
|
+
timestamp !== undefined && timestamp !== null
|
|
358
350
|
? new Date(timestamp * 1000)
|
|
359
351
|
: new Date();
|
|
360
352
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
353
|
+
if (fmt === "*t") {
|
|
354
|
+
return dateTable(d, utc);
|
|
355
|
+
}
|
|
364
356
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
357
|
+
return luaFormatTime(fmt, d, utc);
|
|
358
|
+
}),
|
|
359
|
+
|
|
360
|
+
// Returns an approximation of CPU time used by the program in seconds.
|
|
361
|
+
clock: new LuaBuiltinFunction((_sf): number => {
|
|
362
|
+
return performance.now() / 1000.0;
|
|
363
|
+
}),
|
|
368
364
|
});
|