@silverbulletmd/silverbullet 2.4.1 → 2.5.3
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 +20 -4
- package/client/markdown_parser/constants.ts +2 -2
- package/client/plugos/hooks/code_widget.ts +0 -3
- package/client/plugos/hooks/document_editor.ts +0 -3
- package/client/plugos/hooks/event.ts +1 -1
- package/client/plugos/hooks/mq.ts +1 -1
- package/client/plugos/hooks/plug_namespace.ts +0 -3
- package/client/plugos/hooks/slash_command.ts +2 -2
- package/client/plugos/plug.ts +0 -1
- package/client/plugos/plug_compile.ts +28 -29
- package/client/plugos/proxy_fetch.ts +1 -1
- package/client/plugos/sandboxes/web_worker_sandbox.ts +1 -1
- package/client/plugos/sandboxes/worker_sandbox.ts +2 -3
- package/client/plugos/syscalls/editor.ts +12 -12
- package/client/plugos/syscalls/fetch.ts +1 -1
- package/client/plugos/syscalls/jsonschema.ts +1 -1
- package/client/plugos/syscalls/mq.ts +1 -1
- package/client/plugos/syscalls/space.ts +1 -1
- package/client/plugos/system.ts +2 -2
- package/client/plugos/worker_runtime.ts +8 -29
- package/client/space_lua/aggregates.ts +209 -0
- package/client/space_lua/ast.ts +24 -2
- package/client/space_lua/eval.ts +58 -53
- package/client/space_lua/labels.ts +1 -1
- package/client/space_lua/parse.ts +117 -12
- package/client/space_lua/query_collection.ts +850 -70
- package/client/space_lua/query_env.ts +26 -0
- package/client/space_lua/runtime.ts +47 -17
- package/client/space_lua/stdlib/format.ts +19 -19
- package/client/space_lua/stdlib/math.ts +73 -48
- package/client/space_lua/stdlib/net.ts +2 -2
- package/client/space_lua/stdlib/os.ts +5 -0
- package/client/space_lua/stdlib/pattern.ts +702 -0
- package/client/space_lua/stdlib/prng.ts +145 -0
- package/client/space_lua/stdlib/space_lua.ts +3 -8
- package/client/space_lua/stdlib/string.ts +103 -181
- package/client/space_lua/stdlib/string_pack.ts +486 -0
- package/client/space_lua/stdlib/table.ts +73 -9
- package/client/space_lua/stdlib.ts +38 -14
- package/client/space_lua/tonumber.ts +3 -2
- package/client/space_lua/util.ts +43 -9
- package/dist/plug-compile.js +23 -69
- package/dist/worker_runtime_bundle.js +233 -0
- package/package.json +16 -11
- package/plug-api/constants.ts +0 -32
- package/plug-api/lib/async.ts +2 -2
- package/plug-api/lib/crypto.ts +11 -11
- package/plug-api/lib/json.ts +1 -1
- package/plug-api/lib/limited_map.ts +1 -1
- package/plug-api/lib/native_fetch.ts +2 -0
- package/plug-api/lib/ref.ts +5 -5
- package/plug-api/lib/transclusion.ts +5 -5
- package/plug-api/lib/tree.ts +50 -2
- package/plug-api/lib/yaml.ts +10 -10
- package/plug-api/syscalls/editor.ts +1 -1
- package/plug-api/system_mock.ts +0 -1
- package/client/plugos/sandboxes/deno_worker_sandbox.ts +0 -6
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ And if you are comfortable **programming** a little bit — now we’re really t
|
|
|
22
22
|
Check out the [instructions](https://silverbullet.md/Install).
|
|
23
23
|
|
|
24
24
|
## Developing SilverBullet
|
|
25
|
-
SilverBullet's frontend is written in [TypeScript](https://www.typescriptlang.org/) and built on top of the excellent [CodeMirror 6](https://codemirror.net/) editor component. Additional UI is built using [Preact](https://preactjs.com). [ESBuild](https://esbuild.github.io)
|
|
25
|
+
SilverBullet's frontend is written in [TypeScript](https://www.typescriptlang.org/) and built on top of the excellent [CodeMirror 6](https://codemirror.net/) editor component. Additional UI is built using [Preact](https://preactjs.com). [ESBuild](https://esbuild.github.io) is used to build the frontend.
|
|
26
26
|
|
|
27
27
|
The server backend is written in Go.
|
|
28
28
|
|
|
@@ -43,9 +43,15 @@ If you're considering contributing changes, be aware of the [LLM use policy](htt
|
|
|
43
43
|
* `website/`: silverbullet.md website content
|
|
44
44
|
|
|
45
45
|
### Requirements
|
|
46
|
-
* [
|
|
46
|
+
* [Node.js](https://nodejs.org/) 24+ and npm 10+: Used to build the frontend and plugs
|
|
47
47
|
* [Go](https://go.dev/): Used to build the backend
|
|
48
48
|
|
|
49
|
+
The project includes `.nvmrc` and `.node-version` files. If you use [nvm](https://github.com/nvm-sh/nvm) or another Node version manager, it will automatically use the correct Node.js version:
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
nvm use # If using nvm
|
|
53
|
+
```
|
|
54
|
+
|
|
49
55
|
It's convenient to also install [air](https://github.com/air-verse/air) for development, this will automatically rebuild both the frontend and backend when changes are made:
|
|
50
56
|
|
|
51
57
|
```shell
|
|
@@ -53,6 +59,12 @@ go install github.com/air-verse/air@latest
|
|
|
53
59
|
```
|
|
54
60
|
Make sure your `$GOPATH/bin` is in your $PATH.
|
|
55
61
|
|
|
62
|
+
First, install dependencies:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
npm install
|
|
66
|
+
```
|
|
67
|
+
|
|
56
68
|
To build everything and run the server:
|
|
57
69
|
|
|
58
70
|
```shell
|
|
@@ -62,7 +74,9 @@ air <PATH-TO-YOUR-SPACE>
|
|
|
62
74
|
Alternatively, to build:
|
|
63
75
|
|
|
64
76
|
```shell
|
|
65
|
-
make
|
|
77
|
+
make build
|
|
78
|
+
# or
|
|
79
|
+
npm run build
|
|
66
80
|
```
|
|
67
81
|
|
|
68
82
|
To run the resulting server:
|
|
@@ -82,10 +96,12 @@ make check
|
|
|
82
96
|
make fmt
|
|
83
97
|
# Run all tests
|
|
84
98
|
make test
|
|
99
|
+
# Run benchmarks
|
|
100
|
+
make bench
|
|
85
101
|
```
|
|
86
102
|
|
|
87
103
|
### Build a docker container
|
|
88
|
-
Note, you do not need
|
|
104
|
+
Note, you do not need Node.js nor Go locally installed for this to work:
|
|
89
105
|
|
|
90
106
|
```shell
|
|
91
107
|
docker build -t silverbullet .
|
|
@@ -4,10 +4,10 @@ export const mdLinkRegex = /!?\[(?<title>[^\]]*)\]\((?<url>.+)\)/g;
|
|
|
4
4
|
export const tagRegex =
|
|
5
5
|
/#(?:(?:\d*[^\d\s!@#$%^&*(),.?":{}|<>\\][^\s!@#$%^&*(),.?":{}|<>\\]*)|(?:<[^>\n]+>))/;
|
|
6
6
|
export const nakedUrlRegex =
|
|
7
|
-
/(^https?:\/\/([-a-zA-Z0-9@:%_
|
|
7
|
+
/(^https?:\/\/([-a-zA-Z0-9@:%_+~#=]|(?:[.](?!(\s|$)))){1,256})(([-a-zA-Z0-9(@:%_+~#?&=/]|(?:[.,:;)](?!(\s|$))))*)/;
|
|
8
8
|
export const frontmatterQuotesRegex = /["'].*["']/g;
|
|
9
9
|
export const frontmatterUrlRegex = /([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s"']+)/g;
|
|
10
10
|
export const frontmatterWikiLinkRegex =
|
|
11
11
|
/(?<leadingTrivia>!?\[\[)(?<stringRef>.*?)(?:\|(?<alias>.*?))?(?<trailingTrivia>\]\])/g;
|
|
12
12
|
export const frontmatterMailtoRegex = /(mailto:[^@\s]+@[^@\s"']+)/ig;
|
|
13
|
-
export const pWikiLinkRegex = new RegExp(
|
|
13
|
+
export const pWikiLinkRegex = new RegExp(`^${wikiLinkRegex.source}`); // Modified regex used only in parser
|
|
@@ -7,9 +7,6 @@ export class CodeWidgetHook implements Hook<CodeWidgetT> {
|
|
|
7
7
|
codeWidgetCallbacks = new Map<string, CodeWidgetCallback>();
|
|
8
8
|
codeWidgetModes = new Map<string, "markdown" | "iframe">();
|
|
9
9
|
|
|
10
|
-
constructor() {
|
|
11
|
-
}
|
|
12
|
-
|
|
13
10
|
collectAllCodeWidgets(system: System<CodeWidgetT>) {
|
|
14
11
|
this.codeWidgetCallbacks.clear();
|
|
15
12
|
for (const plug of system.loadedPlugs.values()) {
|
|
@@ -9,9 +9,6 @@ export class DocumentEditorHook implements Hook<DocumentEditorT> {
|
|
|
9
9
|
{ extensions: string[]; callback: DocumentEditorCallback }
|
|
10
10
|
>();
|
|
11
11
|
|
|
12
|
-
constructor() {
|
|
13
|
-
}
|
|
14
|
-
|
|
15
12
|
collectAllDocumentEditors(system: System<DocumentEditorT>) {
|
|
16
13
|
this.documentEditors.clear();
|
|
17
14
|
for (const plug of system.loadedPlugs.values()) {
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
SlashCompletions,
|
|
16
16
|
} from "@silverbulletmd/silverbullet/type/client";
|
|
17
17
|
|
|
18
|
-
const slashCommandRegexp = /([^\w:]|^)\/[\w
|
|
18
|
+
const slashCommandRegexp = /([^\w:]|^)\/[\w#-]*/;
|
|
19
19
|
|
|
20
20
|
export class SlashCommandHook implements Hook<SlashCommandHookT> {
|
|
21
21
|
slashCommands: SlashCommand[] = [];
|
|
@@ -94,7 +94,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
|
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
96
|
if (
|
|
97
|
-
def.exceptContexts
|
|
97
|
+
def.exceptContexts?.some(
|
|
98
98
|
(context) => parentNodes.some((node) => node.startsWith(context)),
|
|
99
99
|
)
|
|
100
100
|
) {
|
package/client/plugos/plug.ts
CHANGED
|
@@ -70,7 +70,6 @@ export class Plug<HookT> {
|
|
|
70
70
|
const sandbox = this.sandbox!;
|
|
71
71
|
if (funDef.redirect) {
|
|
72
72
|
// Function redirect, look up
|
|
73
|
-
// deno-lint-ignore no-this-alias
|
|
74
73
|
let plug: Plug<HookT> | undefined = this;
|
|
75
74
|
if (funDef.redirect.indexOf(".") !== -1) {
|
|
76
75
|
const [plugName, functionName] = funDef.redirect.split(".");
|
|
@@ -3,23 +3,33 @@ import { readFile, writeFile, mkdtemp, rm, mkdir } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import * as YAML from "js-yaml";
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import * as esbuild from "esbuild";
|
|
7
7
|
import { bundleAssets } from "../asset_bundle/builder.ts";
|
|
8
8
|
import type { Manifest } from "./types.ts";
|
|
9
|
-
import { version } from "../../version.ts";
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
// )
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
|
|
12
|
+
// Resolve the pre-built worker_runtime bundle path
|
|
13
|
+
// When running from source: ../../dist/worker_runtime_bundle.js (from client/plugos/)
|
|
14
|
+
// When bundled: ./worker_runtime_bundle.js (from dist/)
|
|
15
|
+
const currentDir = import.meta.dirname;
|
|
16
|
+
const bundledPath = path.join(currentDir, "worker_runtime_bundle.js");
|
|
17
|
+
const sourcePath = path.join(currentDir, "../../dist/worker_runtime_bundle.js");
|
|
18
|
+
const workerRuntimeBundlePath = existsSync(bundledPath)
|
|
19
|
+
? bundledPath
|
|
20
|
+
: sourcePath;
|
|
21
|
+
|
|
22
|
+
const workerRuntimePlugin: esbuild.Plugin = {
|
|
23
|
+
name: "worker-runtime",
|
|
24
|
+
setup(build) {
|
|
25
|
+
build.onResolve({ filter: /^worker-runtime$/ }, () => ({
|
|
26
|
+
path: workerRuntimeBundlePath,
|
|
27
|
+
}));
|
|
28
|
+
},
|
|
29
|
+
};
|
|
17
30
|
|
|
18
31
|
export type CompileOptions = {
|
|
19
32
|
debug?: boolean;
|
|
20
|
-
runtimeUrl?: string;
|
|
21
|
-
// path to config file
|
|
22
|
-
configPath?: string;
|
|
23
33
|
// Print info on bundle size
|
|
24
34
|
info?: boolean;
|
|
25
35
|
};
|
|
@@ -50,9 +60,7 @@ export async function compileManifest(
|
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
const jsFile = `
|
|
53
|
-
import { setupMessageListener } from "
|
|
54
|
-
options.runtimeUrl || workerRuntimeUrl
|
|
55
|
-
}";
|
|
63
|
+
import { setupMessageListener } from "worker-runtime";
|
|
56
64
|
|
|
57
65
|
// Imports
|
|
58
66
|
${
|
|
@@ -64,7 +72,7 @@ ${
|
|
|
64
72
|
// Resolve path
|
|
65
73
|
filePath = path.join(rootPath, filePath);
|
|
66
74
|
|
|
67
|
-
return `import {${jsFunctionName} as ${funcName}} from "
|
|
75
|
+
return `import {${jsFunctionName} as ${funcName}} from "${
|
|
68
76
|
// Replacing \ with / for Windows
|
|
69
77
|
path.resolve(filePath).replaceAll(
|
|
70
78
|
"\\",
|
|
@@ -111,12 +119,7 @@ setupMessageListener(functionMapping, manifest, self.postMessage);
|
|
|
111
119
|
outfile: outFile,
|
|
112
120
|
metafile: options.info,
|
|
113
121
|
treeShaking: true,
|
|
114
|
-
plugins: [
|
|
115
|
-
denoPlugin({
|
|
116
|
-
configPath: options.configPath &&
|
|
117
|
-
path.resolve(process.cwd(), options.configPath),
|
|
118
|
-
}),
|
|
119
|
-
],
|
|
122
|
+
plugins: [workerRuntimePlugin],
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
if (options.info) {
|
|
@@ -125,7 +128,7 @@ setupMessageListener(functionMapping, manifest, self.postMessage);
|
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
let jsCode = await readFile(outFile, "utf-8");
|
|
128
|
-
jsCode =
|
|
131
|
+
jsCode = patchBundledJS(jsCode);
|
|
129
132
|
await writeFile(outFile, jsCode, "utf-8");
|
|
130
133
|
|
|
131
134
|
// Clean up temp directory
|
|
@@ -172,18 +175,16 @@ export async function compileManifests(
|
|
|
172
175
|
await buildAll();
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
export function
|
|
176
|
-
//
|
|
178
|
+
export function patchBundledJS(code: string): string {
|
|
179
|
+
// One bundled dependency has a lookbehind regex that WebKit can't parse; replace it with a no-op
|
|
177
180
|
return code.replaceAll("/(?<=\\n)/", "/()/");
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
export async function plugCompileCommand(
|
|
181
|
-
{ dist, debug, info
|
|
184
|
+
{ dist, debug, info }: {
|
|
182
185
|
dist: string;
|
|
183
186
|
debug: boolean;
|
|
184
187
|
info: boolean;
|
|
185
|
-
config?: string;
|
|
186
|
-
runtimeUrl?: string;
|
|
187
188
|
},
|
|
188
189
|
...manifestPaths: string[]
|
|
189
190
|
) {
|
|
@@ -193,8 +194,6 @@ export async function plugCompileCommand(
|
|
|
193
194
|
{
|
|
194
195
|
debug: debug,
|
|
195
196
|
info: info,
|
|
196
|
-
runtimeUrl,
|
|
197
|
-
configPath: config,
|
|
198
197
|
},
|
|
199
198
|
);
|
|
200
199
|
esbuild.stop();
|
|
@@ -39,7 +39,7 @@ export async function performLocalFetch(
|
|
|
39
39
|
method: req.method,
|
|
40
40
|
headers: req.headers,
|
|
41
41
|
body: req.base64Body && base64Decode(req.base64Body),
|
|
42
|
-
// Casting
|
|
42
|
+
// Casting to any due to TypeScript fetch type limitations
|
|
43
43
|
} as any,
|
|
44
44
|
);
|
|
45
45
|
return {
|
|
@@ -11,7 +11,7 @@ export function createWorkerSandboxFromLocalPath<HookT>(
|
|
|
11
11
|
plug,
|
|
12
12
|
new URL(
|
|
13
13
|
name,
|
|
14
|
-
document.baseURI.slice(0, -1) + fsEndpoint
|
|
14
|
+
`${document.baseURI.slice(0, -1) + fsEndpoint}/`, // We're NOT striping trailing '/', this used to be `location.origin`
|
|
15
15
|
),
|
|
16
16
|
);
|
|
17
17
|
}
|
|
@@ -94,10 +94,9 @@ export class WorkerSandbox<HookT> implements Sandbox<HookT> {
|
|
|
94
94
|
const resultCbs = this.outstandingInvocations.get(data.id!);
|
|
95
95
|
this.outstandingInvocations.delete(data.id!);
|
|
96
96
|
if (data.error) {
|
|
97
|
-
resultCbs
|
|
98
|
-
resultCbs.reject(new Error(data.error));
|
|
97
|
+
resultCbs?.reject(new Error(data.error));
|
|
99
98
|
} else {
|
|
100
|
-
resultCbs
|
|
99
|
+
resultCbs?.resolve(data.result);
|
|
101
100
|
}
|
|
102
101
|
break;
|
|
103
102
|
}
|
|
@@ -110,7 +110,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (
|
|
113
|
-
// @ts-
|
|
113
|
+
// @ts-expect-error: Legacy support
|
|
114
114
|
ref.page !== undefined
|
|
115
115
|
) {
|
|
116
116
|
console.warn(
|
|
@@ -127,7 +127,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
127
127
|
|
|
128
128
|
legacyRef.kind ??= "page";
|
|
129
129
|
|
|
130
|
-
let details: Ref["details"]
|
|
130
|
+
let details: Ref["details"] ;
|
|
131
131
|
|
|
132
132
|
if (typeof legacyRef.pos === "number") {
|
|
133
133
|
details = {
|
|
@@ -232,7 +232,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
232
232
|
"editor.newWindow": () => {
|
|
233
233
|
globalThis.open(
|
|
234
234
|
location.href,
|
|
235
|
-
|
|
235
|
+
`rnd${Math.random()}`,
|
|
236
236
|
`width=${globalThis.innerWidth},heigh=${globalThis.innerHeight}`,
|
|
237
237
|
);
|
|
238
238
|
},
|
|
@@ -268,7 +268,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
268
268
|
const reader = new FileReader();
|
|
269
269
|
reader.readAsArrayBuffer(file);
|
|
270
270
|
reader.onloadend = async (evt) => {
|
|
271
|
-
if (evt.target?.readyState
|
|
271
|
+
if (evt.target?.readyState === FileReader.DONE) {
|
|
272
272
|
resolve({
|
|
273
273
|
name: file.name,
|
|
274
274
|
contentType: file.type,
|
|
@@ -311,7 +311,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
311
311
|
_ctx,
|
|
312
312
|
id: string,
|
|
313
313
|
mode: number,
|
|
314
|
-
html: string,
|
|
314
|
+
html: HTMLElement | HTMLElement[] | string,
|
|
315
315
|
script: string,
|
|
316
316
|
) => {
|
|
317
317
|
client.ui.viewDispatch({
|
|
@@ -506,7 +506,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
506
506
|
},
|
|
507
507
|
"editor.vimEx": (_ctx, exCommand: string) => {
|
|
508
508
|
const cm = vimGetCm(client.editorView);
|
|
509
|
-
if (cm
|
|
509
|
+
if (cm?.state.vim) {
|
|
510
510
|
return Vim.handleEx(cm as any, exCommand);
|
|
511
511
|
} else {
|
|
512
512
|
throw new Error("Vim mode not active or not initialized.");
|
|
@@ -555,30 +555,30 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|
|
555
555
|
if (config) {
|
|
556
556
|
config.unmap?.forEach((binding) => {
|
|
557
557
|
if (typeof binding === "string") {
|
|
558
|
-
console.log(
|
|
559
|
-
// @ts-
|
|
558
|
+
console.log(`Unmapping ${binding}`);
|
|
559
|
+
// @ts-expect-error: unmap expects a string for the mode, this is problematic with Ex mappings which requires undefined or false
|
|
560
560
|
Vim.unmap(binding, undefined);
|
|
561
561
|
} else if (binding.key) {
|
|
562
562
|
console.log(
|
|
563
|
-
|
|
563
|
+
`Unmapping ${binding.key} in ${binding.mode ?? "normal"}`,
|
|
564
564
|
);
|
|
565
565
|
Vim.unmap(binding.key, binding.mode ?? "normal");
|
|
566
566
|
}
|
|
567
567
|
});
|
|
568
568
|
config.map?.forEach(({ map, to, mode }) => {
|
|
569
569
|
console.log(
|
|
570
|
-
|
|
570
|
+
`Mapping ${map} to ${to} for ${mode ?? "normal"}`,
|
|
571
571
|
);
|
|
572
572
|
Vim.map(map, to, mode ?? "normal");
|
|
573
573
|
});
|
|
574
574
|
config.noremap?.forEach(({ map, to, mode }) => {
|
|
575
575
|
console.log(
|
|
576
|
-
|
|
576
|
+
`Noremapping ${map} to ${to} for ${mode ?? "normal"}`,
|
|
577
577
|
);
|
|
578
578
|
Vim.noremap(map, to, mode ?? "normal");
|
|
579
579
|
});
|
|
580
580
|
config.commands?.forEach(({ ex, command }) => {
|
|
581
|
-
console.log(
|
|
581
|
+
console.log(`Mapping command '${command}' to Ex ${ex}`);
|
|
582
582
|
Vim.defineEx(ex, "", () => client.runCommandByName(command));
|
|
583
583
|
});
|
|
584
584
|
} else {
|
|
@@ -82,7 +82,7 @@ export function sandboxFetchSyscalls(
|
|
|
82
82
|
fetchOptions.headers = buildProxyHeaders(options?.headers);
|
|
83
83
|
const resp = await client.httpSpacePrimitives.authenticatedFetch(
|
|
84
84
|
buildProxyUrl(client, url),
|
|
85
|
-
// Casting
|
|
85
|
+
// Casting to any due to TypeScript fetch type limitations
|
|
86
86
|
fetchOptions as any,
|
|
87
87
|
);
|
|
88
88
|
const statusCode = +(resp.headers.get("x-proxy-status-code") || "200");
|
|
@@ -33,7 +33,7 @@ export function validateObject(schema: any, object: any): undefined | string {
|
|
|
33
33
|
} else {
|
|
34
34
|
let text = ajv.errorsText(validate.errors);
|
|
35
35
|
text = text.replaceAll("/", ".");
|
|
36
|
-
text = text.replace(/^data[
|
|
36
|
+
text = text.replace(/^data[.\s]/, "");
|
|
37
37
|
return text;
|
|
38
38
|
}
|
|
39
39
|
} catch (e: any) {
|
|
@@ -17,7 +17,7 @@ export function mqSyscalls(
|
|
|
17
17
|
_ctx,
|
|
18
18
|
def: MQListenerSpec,
|
|
19
19
|
) => {
|
|
20
|
-
def.autoAck = def.autoAck
|
|
20
|
+
def.autoAck = def.autoAck !== false;
|
|
21
21
|
// console.log("Registering Lua event listener: ", def.name);
|
|
22
22
|
client.config.insert([
|
|
23
23
|
"mqSubscriptions",
|
|
@@ -32,7 +32,7 @@ export function spaceReadSyscalls(client: Client): SysCallMapping {
|
|
|
32
32
|
return (await client.space.readRef(ref)).text;
|
|
33
33
|
},
|
|
34
34
|
"space.pageExists": (_ctx, name: string): boolean => {
|
|
35
|
-
return client.clientSystem.allKnownFiles.has(name
|
|
35
|
+
return client.clientSystem.allKnownFiles.has(`${name}.md`);
|
|
36
36
|
},
|
|
37
37
|
"space.getPageMeta": (_ctx, name: string): Promise<PageMeta> => {
|
|
38
38
|
return client.space.getPageMeta(name);
|
package/client/plugos/system.ts
CHANGED
|
@@ -193,8 +193,8 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
|
|
193
193
|
this.plugs.delete(name);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
unloadAll(): Promise<void
|
|
197
|
-
|
|
196
|
+
async unloadAll(): Promise<void> {
|
|
197
|
+
await Promise.all(
|
|
198
198
|
Array.from(this.plugs.keys()).map(this.unload.bind(this)),
|
|
199
199
|
);
|
|
200
200
|
}
|
|
@@ -15,34 +15,14 @@ let workerPostMessage = (_msg: ControllerMessage): void => {
|
|
|
15
15
|
throw new Error("Not initialized yet");
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
// Determines if we're running in a web worker environment (Deno or browser)
|
|
21
|
-
// - in a browser's main threads, typeof window is "object"
|
|
18
|
+
// Determines if we're running in a web worker environment
|
|
19
|
+
// - in a browser's main thread, typeof window is "object"
|
|
22
20
|
// - in a browser's worker threads, typeof window === "undefined"
|
|
23
|
-
// - in Deno's main thread typeof window === "object"
|
|
24
|
-
// - in Deno's workers typeof window === "undefined
|
|
25
21
|
// - in Cloudflare workers typeof window === "undefined", but typeof globalThis.WebSocketPair is defined
|
|
26
22
|
const runningAsWebWorker = typeof window === "undefined" &&
|
|
27
|
-
// @ts-
|
|
23
|
+
// @ts-expect-error: globalThis
|
|
28
24
|
typeof globalThis.WebSocketPair === "undefined";
|
|
29
25
|
|
|
30
|
-
if (typeof Deno === "undefined") {
|
|
31
|
-
// @ts-ignore: Deno hack
|
|
32
|
-
self.Deno = {
|
|
33
|
-
args: [],
|
|
34
|
-
// @ts-ignore: Deno hack
|
|
35
|
-
build: {
|
|
36
|
-
arch: "x86_64",
|
|
37
|
-
},
|
|
38
|
-
env: {
|
|
39
|
-
// @ts-ignore: Deno hack
|
|
40
|
-
get() {
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
26
|
const pendingRequests = new Map<
|
|
47
27
|
number,
|
|
48
28
|
{
|
|
@@ -156,17 +136,16 @@ export async function sandboxFetch(
|
|
|
156
136
|
return syscall("sandboxFetch.fetch", reqInfo, options);
|
|
157
137
|
}
|
|
158
138
|
|
|
159
|
-
// @ts-ignore: monkey patching fetch
|
|
160
139
|
globalThis.nativeFetch = globalThis.fetch;
|
|
161
140
|
|
|
162
141
|
// Monkey patch fetch()
|
|
163
142
|
export function monkeyPatchFetch() {
|
|
164
|
-
// @ts-
|
|
165
|
-
globalThis.fetch = async
|
|
143
|
+
// @ts-expect-error: monkey patching fetch
|
|
144
|
+
globalThis.fetch = async (
|
|
166
145
|
reqInfo: RequestInfo,
|
|
167
146
|
init?: RequestInit,
|
|
168
|
-
): Promise<Response> {
|
|
169
|
-
const encodedBody = init
|
|
147
|
+
): Promise<Response> => {
|
|
148
|
+
const encodedBody = init?.body
|
|
170
149
|
? base64Encode(
|
|
171
150
|
new Uint8Array(await (new Response(init.body)).arrayBuffer()),
|
|
172
151
|
)
|
|
@@ -179,7 +158,7 @@ export function monkeyPatchFetch() {
|
|
|
179
158
|
base64Body: encodedBody,
|
|
180
159
|
},
|
|
181
160
|
);
|
|
182
|
-
// Casting
|
|
161
|
+
// Casting to any due to TypeScript fetch type limitations
|
|
183
162
|
return new Response(
|
|
184
163
|
(r.base64Body ? base64Decode(r.base64Body) : null) as any,
|
|
185
164
|
{
|