@sproutboat/runtime 0.19.2 → 0.21.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.
- package/CHANGELOG.md +95 -0
- package/package.json +1 -1
- package/src/native-fetch-prelude.js +488 -83
- package/src/source.ts +8 -4
- package/src/transport-broker.js +566 -56
- package/src/transport-embedded.js +4 -0
- package/src/wrap.ts +30 -3
- package/test/native-base64.ts +11 -2
- package/test/native-service-bindings.ts +396 -0
package/src/source.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { neutraliseExports } from "./wrap";
|
|
1
|
+
import { inlineWorkersImports, neutraliseExports } from "./wrap";
|
|
2
2
|
|
|
3
3
|
export type SourceValidation = { ok: true } | { ok: false; errors: string[] };
|
|
4
4
|
|
|
@@ -28,7 +28,10 @@ const alwaysForbidden: Array<[RegExp, string]> = [
|
|
|
28
28
|
|
|
29
29
|
];
|
|
30
30
|
|
|
31
|
-
export function validateHttpSyncSource(
|
|
31
|
+
export function validateHttpSyncSource(module: string): SourceValidation {
|
|
32
|
+
// `cloudflare:workers` is the one import allowed past bundling: the compiler turns it
|
|
33
|
+
// into globals the same way (see inlineWorkersImports).
|
|
34
|
+
const source = inlineWorkersImports(module);
|
|
32
35
|
const errors: string[] = [];
|
|
33
36
|
// The default export must be an object literal with a `fetch` method. A module
|
|
34
37
|
// may also declare Durable Object classes / helpers before it, so this is not
|
|
@@ -36,8 +39,9 @@ export function validateHttpSyncSource(source: string): SourceValidation {
|
|
|
36
39
|
// A hand-written file exports inline; a bundled one re-exports at the end.
|
|
37
40
|
// `neutraliseExports` is the same reader the compiler uses, so `check` cannot
|
|
38
41
|
// accept a module the build would then reject.
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
// A WorkerEntrypoint may serve only RPC, with no fetch() at all.
|
|
43
|
+
if (neutraliseExports(source) === null || (!/\bfetch\s*\(/.test(source) && !/\bextends\s+WorkerEntrypoint\b/.test(source))) {
|
|
44
|
+
errors.push("handler must default-export an object with fetch(request), or a WorkerEntrypoint class");
|
|
41
45
|
}
|
|
42
46
|
for (const [pattern, message] of alwaysForbidden) if (pattern.test(source)) errors.push(message);
|
|
43
47
|
return errors.length ? { ok: false, errors } : { ok: true };
|