cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4
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/LICENSE +21 -0
- package/Package.swift +25 -0
- package/README.md +92 -2
- package/dist/android.d.ts +2 -0
- package/dist/android.js +1 -0
- package/dist/browser/abort/index.d.ts +13 -0
- package/dist/browser/abort/index.js +66 -0
- package/dist/browser/body/index.d.ts +24 -0
- package/dist/browser/body/index.js +116 -0
- package/dist/browser/body/stream-body.d.ts +13 -0
- package/dist/browser/body/stream-body.js +84 -0
- package/dist/browser/documents/body.d.ts +3 -0
- package/dist/browser/documents/body.js +48 -0
- package/dist/browser/documents/form-body.d.ts +1 -0
- package/dist/browser/documents/form-body.js +54 -0
- package/dist/browser/documents/host.d.ts +11 -0
- package/dist/browser/documents/host.js +256 -0
- package/dist/browser/documents/links-source.d.ts +1 -0
- package/dist/browser/documents/links-source.js +1 -0
- package/dist/browser/documents/links.d.ts +1 -0
- package/dist/browser/documents/links.js +33 -0
- package/dist/browser/documents/page-config.d.ts +5 -0
- package/dist/browser/documents/page-config.js +5 -0
- package/dist/browser/documents/page-source.d.ts +1 -0
- package/dist/browser/documents/page-source.js +1 -0
- package/dist/browser/documents/page.d.ts +2 -0
- package/dist/browser/documents/page.js +153 -0
- package/dist/browser/documents/registration.d.ts +5 -0
- package/dist/browser/documents/registration.js +75 -0
- package/dist/browser/documents/runtime.d.ts +7 -0
- package/dist/browser/documents/runtime.js +161 -0
- package/dist/browser/documents/service-worker.js +285 -0
- package/dist/browser/encoding/index.d.ts +7 -0
- package/dist/browser/encoding/index.js +3 -0
- package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/fetch/LICENSE-APACHE +177 -0
- package/dist/browser/fetch/host-call.d.ts +3 -0
- package/dist/browser/fetch/host-call.js +67 -0
- package/dist/browser/fetch/index.d.ts +5 -0
- package/dist/browser/fetch/index.js +96 -0
- package/dist/browser/fetch/interop.d.ts +6 -0
- package/dist/browser/fetch/interop.js +48 -0
- package/dist/browser/fetch/native-network.d.ts +20 -0
- package/dist/browser/fetch/native-network.js +233 -0
- package/dist/browser/fetch/outbound.d.ts +2 -0
- package/dist/browser/fetch/outbound.js +11 -0
- package/dist/browser/fetch/relay.d.ts +7 -0
- package/dist/browser/fetch/relay.js +100 -0
- package/dist/browser/fetch/scope.d.ts +8 -0
- package/dist/browser/fetch/scope.js +108 -0
- package/dist/browser/fetch/transport.d.ts +39 -0
- package/dist/browser/fetch/transport.js +136 -0
- package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/headers/LICENSE-APACHE +177 -0
- package/dist/browser/headers/index.d.ts +20 -0
- package/dist/browser/headers/index.js +194 -0
- package/dist/browser/isolated/bridge.d.ts +8 -0
- package/dist/browser/isolated/bridge.js +267 -0
- package/dist/browser/isolated/protocol.d.ts +40 -0
- package/dist/browser/isolated/protocol.js +1 -0
- package/dist/browser/isolated/transport.d.ts +2 -0
- package/dist/browser/isolated/transport.js +157 -0
- package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/request/LICENSE-APACHE +177 -0
- package/dist/browser/request/index.d.ts +48 -0
- package/dist/browser/request/index.js +182 -0
- package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/response/LICENSE-APACHE +177 -0
- package/dist/browser/response/index.d.ts +43 -0
- package/dist/browser/response/index.js +192 -0
- package/dist/browser/response/status.d.ts +1 -0
- package/dist/browser/response/status.js +75 -0
- package/dist/browser/structured-clone/index.d.ts +1 -0
- package/dist/browser/structured-clone/index.js +479 -0
- package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
- package/dist/cloudflare/apis/types.d.ts +7 -0
- package/dist/cloudflare/apis/types.js +1 -0
- package/dist/cloudflare/bindings/config.d.ts +42 -0
- package/dist/cloudflare/bindings/config.js +280 -0
- package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
- package/dist/cloudflare/bindings/kv/contract.js +181 -0
- package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
- package/dist/cloudflare/bindings/kv/index.js +61 -0
- package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
- package/dist/cloudflare/bindings/kv/storage.js +320 -0
- package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
- package/dist/cloudflare/bindings/kv/types.js +1 -0
- package/dist/cloudflare/bindings/remote.d.ts +8 -0
- package/dist/cloudflare/bindings/remote.js +261 -0
- package/dist/cloudflare/workers/contract.d.ts +8 -0
- package/dist/cloudflare/workers/contract.js +65 -0
- package/dist/cloudflare/workers/feature.d.ts +10 -0
- package/dist/cloudflare/workers/feature.js +28 -0
- package/dist/cloudflare/workers/runtime.d.ts +23 -0
- package/dist/cloudflare/workers/runtime.js +121 -0
- package/dist/cloudflare/workers/types.d.ts +49 -0
- package/dist/cloudflare/workers/types.js +1 -0
- package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
- package/dist/cloudflare/workers/worker-runtime.js +267 -0
- package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/assert/LICENSE-APACHE +177 -0
- package/dist/compat/assert/assertion-error.d.ts +26 -0
- package/dist/compat/assert/assertion-error.js +468 -0
- package/dist/compat/assert/diff.d.ts +26 -0
- package/dist/compat/assert/diff.js +329 -0
- package/dist/compat/assert/errors.d.ts +11 -0
- package/dist/compat/assert/errors.js +55 -0
- package/dist/compat/assert/index.cjs +24 -0
- package/dist/compat/assert/index.d.cts +43 -0
- package/dist/compat/assert/index.d.ts +50 -0
- package/dist/compat/assert/index.js +858 -0
- package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/async-hooks/NOTICE.md +8 -0
- package/dist/compat/async-hooks/callbacks.d.ts +7 -0
- package/dist/compat/async-hooks/callbacks.js +18 -0
- package/dist/compat/async-hooks/hooks.d.ts +10 -0
- package/dist/compat/async-hooks/hooks.js +111 -0
- package/dist/compat/async-hooks/index.d.ts +41 -0
- package/dist/compat/async-hooks/index.js +298 -0
- package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/buffer/LICENSE-APACHE +177 -0
- package/dist/compat/buffer/blob.d.ts +22 -0
- package/dist/compat/buffer/blob.js +210 -0
- package/dist/compat/buffer/bytes.d.ts +34 -0
- package/dist/compat/buffer/bytes.js +228 -0
- package/dist/compat/buffer/errors.d.ts +41 -0
- package/dist/compat/buffer/errors.js +265 -0
- package/dist/compat/buffer/index.d.ts +25 -0
- package/dist/compat/buffer/index.js +24 -0
- package/dist/compat/buffer/internal-buffer.d.ts +148 -0
- package/dist/compat/buffer/internal-buffer.js +1809 -0
- package/dist/compat/buffer/support.d.ts +13 -0
- package/dist/compat/buffer/support.js +65 -0
- package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/child-process/LICENSE-APACHE +177 -0
- package/dist/compat/child-process/errors.d.ts +4 -0
- package/dist/compat/child-process/errors.js +6 -0
- package/dist/compat/child-process/index.d.ts +49 -0
- package/dist/compat/child-process/index.js +96 -0
- package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
- package/dist/compat/cluster/LICENSE-APACHE +177 -0
- package/dist/compat/cluster/errors.d.ts +4 -0
- package/dist/compat/cluster/errors.js +6 -0
- package/dist/compat/cluster/index.d.ts +47 -0
- package/dist/compat/cluster/index.js +88 -0
- package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/constants/LICENSE-APACHE +177 -0
- package/dist/compat/constants/index.d.ts +481 -0
- package/dist/compat/constants/index.js +488 -0
- package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/dgram/LICENSE-APACHE +177 -0
- package/dist/compat/dgram/index.d.ts +10 -0
- package/dist/compat/dgram/index.js +132 -0
- package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
- package/dist/compat/diagnostics-channel/index.d.ts +73 -0
- package/dist/compat/diagnostics-channel/index.js +261 -0
- package/dist/compat/diagnostics-channel/native.d.ts +26 -0
- package/dist/compat/diagnostics-channel/native.js +154 -0
- package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/dns/LICENSE-APACHE +177 -0
- package/dist/compat/dns/client.d.ts +72 -0
- package/dist/compat/dns/client.js +161 -0
- package/dist/compat/dns/constants.d.ts +27 -0
- package/dist/compat/dns/constants.js +31 -0
- package/dist/compat/dns/errors.d.ts +8 -0
- package/dist/compat/dns/errors.js +12 -0
- package/dist/compat/dns/index.d.ts +97 -0
- package/dist/compat/dns/index.js +127 -0
- package/dist/compat/dns/parser.d.ts +18 -0
- package/dist/compat/dns/parser.js +144 -0
- package/dist/compat/dns/promise-resolver.d.ts +82 -0
- package/dist/compat/dns/promise-resolver.js +113 -0
- package/dist/compat/dns/promises.d.ts +50 -0
- package/dist/compat/dns/promises.js +53 -0
- package/dist/compat/dns/resolver.d.ts +34 -0
- package/dist/compat/dns/resolver.js +415 -0
- package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/domain/LICENSE-APACHE +177 -0
- package/dist/compat/domain/index.d.ts +22 -0
- package/dist/compat/domain/index.js +79 -0
- package/dist/compat/fs/index.d.ts +85 -0
- package/dist/compat/fs/index.js +255 -0
- package/dist/compat/fs/promises/index.d.ts +3 -0
- package/dist/compat/fs/promises/index.js +3 -0
- package/dist/compat/http/index.d.ts +322 -0
- package/dist/compat/http/index.js +1356 -0
- package/dist/compat/http/registry.d.ts +19 -0
- package/dist/compat/http/registry.js +13 -0
- package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-agent/LICENSE-APACHE +177 -0
- package/dist/compat/http-agent/index.d.ts +7 -0
- package/dist/compat/http-agent/index.js +10 -0
- package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-client/LICENSE-APACHE +177 -0
- package/dist/compat/http-client/index.d.ts +6 -0
- package/dist/compat/http-client/index.js +7 -0
- package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
- package/dist/compat/http-incoming/index.d.ts +6 -0
- package/dist/compat/http-incoming/index.js +9 -0
- package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
- package/dist/compat/http2/LICENSE-APACHE +177 -0
- package/dist/compat/http2/constants.d.ts +255 -0
- package/dist/compat/http2/constants.js +515 -0
- package/dist/compat/http2/errors.d.ts +4 -0
- package/dist/compat/http2/errors.js +6 -0
- package/dist/compat/http2/index.d.ts +283 -0
- package/dist/compat/http2/index.js +68 -0
- package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/https/LICENSE-APACHE +177 -0
- package/dist/compat/https/agent.d.ts +10 -0
- package/dist/compat/https/agent.js +99 -0
- package/dist/compat/https/errors.d.ts +4 -0
- package/dist/compat/https/errors.js +6 -0
- package/dist/compat/https/index.d.ts +20 -0
- package/dist/compat/https/index.js +50 -0
- package/dist/compat/https/server.d.ts +8 -0
- package/dist/compat/https/server.js +27 -0
- package/dist/compat/immediate/index.d.ts +11 -0
- package/dist/compat/immediate/index.js +58 -0
- package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
- package/dist/compat/inspector/LICENSE-APACHE +177 -0
- package/dist/compat/inspector/errors.d.ts +4 -0
- package/dist/compat/inspector/errors.js +6 -0
- package/dist/compat/inspector/index.d.ts +18 -0
- package/dist/compat/inspector/index.js +117 -0
- package/dist/compat/inspector/promises.d.ts +18 -0
- package/dist/compat/inspector/promises.js +114 -0
- package/dist/compat/module/index.cjs +2 -0
- package/dist/compat/module/index.d.cts +2 -0
- package/dist/compat/module/index.d.ts +11 -0
- package/dist/compat/module/index.js +44 -0
- package/dist/compat/module/resolve-unavailable.d.ts +1 -0
- package/dist/compat/module/resolve-unavailable.js +3 -0
- package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/net/LICENSE-APACHE +177 -0
- package/dist/compat/net/error-base.d.ts +14 -0
- package/dist/compat/net/error-base.js +62 -0
- package/dist/compat/net/errors.d.ts +76 -0
- package/dist/compat/net/errors.js +333 -0
- package/dist/compat/net/index.d.ts +23 -0
- package/dist/compat/net/index.js +46 -0
- package/dist/compat/net/internal-net.d.ts +236 -0
- package/dist/compat/net/internal-net.js +2292 -0
- package/dist/compat/net/ports.d.ts +32 -0
- package/dist/compat/net/ports.js +149 -0
- package/dist/compat/net/reader.d.ts +8 -0
- package/dist/compat/net/reader.js +36 -0
- package/dist/compat/net/sockets.d.ts +20 -0
- package/dist/compat/net/sockets.js +195 -0
- package/dist/compat/net/validators.d.ts +18 -0
- package/dist/compat/net/validators.js +154 -0
- package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/os/LICENSE-APACHE +177 -0
- package/dist/compat/os/index.d.ts +329 -0
- package/dist/compat/os/index.js +278 -0
- package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/path/LICENSE-APACHE +177 -0
- package/dist/compat/path/index.d.ts +4 -0
- package/dist/compat/path/index.js +11 -0
- package/dist/compat/path/internal-path.d.ts +95 -0
- package/dist/compat/path/internal-path.js +1542 -0
- package/dist/compat/path/posix/index.d.ts +4 -0
- package/dist/compat/path/posix/index.js +5 -0
- package/dist/compat/path/win32/index.d.ts +4 -0
- package/dist/compat/path/win32/index.js +5 -0
- package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/perf-hooks/index.d.ts +85 -0
- package/dist/compat/perf-hooks/index.js +79 -0
- package/dist/compat/perf-hooks/performance.d.ts +96 -0
- package/dist/compat/perf-hooks/performance.js +445 -0
- package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/punycode/LICENSE-APACHE +177 -0
- package/dist/compat/punycode/index.d.ts +93 -0
- package/dist/compat/punycode/index.js +410 -0
- package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/querystring/LICENSE-APACHE +177 -0
- package/dist/compat/querystring/index.d.ts +14 -0
- package/dist/compat/querystring/index.js +18 -0
- package/dist/compat/querystring/internal-querystring.d.ts +22 -0
- package/dist/compat/querystring/internal-querystring.js +498 -0
- package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/readline/LICENSE-APACHE +177 -0
- package/dist/compat/readline/index.d.ts +21 -0
- package/dist/compat/readline/index.js +56 -0
- package/dist/compat/readline/interface.d.ts +22 -0
- package/dist/compat/readline/interface.js +85 -0
- package/dist/compat/readline/internal-promises.d.ts +32 -0
- package/dist/compat/readline/internal-promises.js +104 -0
- package/dist/compat/readline/promises.d.ts +8 -0
- package/dist/compat/readline/promises.js +32 -0
- package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/repl/LICENSE-APACHE +177 -0
- package/dist/compat/repl/builtin-modules.d.ts +1 -0
- package/dist/compat/repl/builtin-modules.js +101 -0
- package/dist/compat/repl/errors.d.ts +4 -0
- package/dist/compat/repl/errors.js +6 -0
- package/dist/compat/repl/index.d.ts +53 -0
- package/dist/compat/repl/index.js +106 -0
- package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/sqlite/LICENSE-APACHE +177 -0
- package/dist/compat/sqlite/index.d.ts +12 -0
- package/dist/compat/sqlite/index.js +101 -0
- package/dist/compat/sqlite/native.d.ts +16 -0
- package/dist/compat/sqlite/native.js +33 -0
- package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream/LICENSE-APACHE +177 -0
- package/dist/compat/stream/add-abort-signal.d.ts +4 -0
- package/dist/compat/stream/add-abort-signal.js +73 -0
- package/dist/compat/stream/compose.d.ts +1 -0
- package/dist/compat/stream/compose.js +313 -0
- package/dist/compat/stream/destroy.d.ts +5 -0
- package/dist/compat/stream/destroy.js +315 -0
- package/dist/compat/stream/duplex.d.ts +48 -0
- package/dist/compat/stream/duplex.js +789 -0
- package/dist/compat/stream/end-of-stream.d.ts +16 -0
- package/dist/compat/stream/end-of-stream.js +269 -0
- package/dist/compat/stream/errors.d.ts +40 -0
- package/dist/compat/stream/errors.js +86 -0
- package/dist/compat/stream/events.d.ts +6 -0
- package/dist/compat/stream/events.js +28 -0
- package/dist/compat/stream/index.cjs +27 -0
- package/dist/compat/stream/index.d.cts +25 -0
- package/dist/compat/stream/index.d.ts +20 -0
- package/dist/compat/stream/index.js +55 -0
- package/dist/compat/stream/legacy.d.ts +8 -0
- package/dist/compat/stream/legacy.js +105 -0
- package/dist/compat/stream/once.d.ts +7 -0
- package/dist/compat/stream/once.js +13 -0
- package/dist/compat/stream/pipeline.d.ts +5 -0
- package/dist/compat/stream/pipeline.js +567 -0
- package/dist/compat/stream/process.d.ts +1 -0
- package/dist/compat/stream/process.js +4 -0
- package/dist/compat/stream/promises.d.ts +7 -0
- package/dist/compat/stream/promises.js +60 -0
- package/dist/compat/stream/readable.d.ts +29 -0
- package/dist/compat/stream/readable.js +2267 -0
- package/dist/compat/stream/state.d.ts +8 -0
- package/dist/compat/stream/state.js +63 -0
- package/dist/compat/stream/transform.d.ts +2 -0
- package/dist/compat/stream/transform.js +202 -0
- package/dist/compat/stream/util.d.ts +55 -0
- package/dist/compat/stream/util.js +345 -0
- package/dist/compat/stream/validators.d.ts +2 -0
- package/dist/compat/stream/validators.js +14 -0
- package/dist/compat/stream/writable.d.ts +21 -0
- package/dist/compat/stream/writable.js +1325 -0
- package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
- package/dist/compat/stream-consumers/index.d.ts +14 -0
- package/dist/compat/stream-consumers/index.js +62 -0
- package/dist/compat/stream-consumers/iterable.d.ts +1 -0
- package/dist/compat/stream-consumers/iterable.js +34 -0
- package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
- package/dist/compat/stream-duplex/index.cjs +3 -0
- package/dist/compat/stream-duplex/index.d.cts +2 -0
- package/dist/compat/stream-duplex/index.d.ts +3 -0
- package/dist/compat/stream-duplex/index.js +8 -0
- package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
- package/dist/compat/stream-passthrough/index.cjs +3 -0
- package/dist/compat/stream-passthrough/index.d.cts +2 -0
- package/dist/compat/stream-passthrough/index.d.ts +3 -0
- package/dist/compat/stream-passthrough/index.js +8 -0
- package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
- package/dist/compat/stream-promises/index.d.ts +1 -0
- package/dist/compat/stream-promises/index.js +1 -0
- package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-readable/index.cjs +3 -0
- package/dist/compat/stream-readable/index.d.cts +2 -0
- package/dist/compat/stream-readable/index.d.ts +3 -0
- package/dist/compat/stream-readable/index.js +8 -0
- package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
- package/dist/compat/stream-transform/index.cjs +3 -0
- package/dist/compat/stream-transform/index.d.cts +2 -0
- package/dist/compat/stream-transform/index.d.ts +3 -0
- package/dist/compat/stream-transform/index.js +8 -0
- package/dist/compat/stream-web/LICENSE-MIT +22 -0
- package/dist/compat/stream-web/NOTICE.md +3 -0
- package/dist/compat/stream-web/context.d.ts +2 -0
- package/dist/compat/stream-web/context.js +35 -0
- package/dist/compat/stream-web/index.d.ts +80 -0
- package/dist/compat/stream-web/index.js +129 -0
- package/dist/compat/stream-web/interop.d.ts +6 -0
- package/dist/compat/stream-web/interop.js +72 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -0
- package/dist/compat/stream-web/ponyfill.js +2093 -0
- package/dist/compat/stream-web/runtime.d.ts +16 -0
- package/dist/compat/stream-web/runtime.js +51 -0
- package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-writable/index.cjs +3 -0
- package/dist/compat/stream-writable/index.d.cts +2 -0
- package/dist/compat/stream-writable/index.d.ts +3 -0
- package/dist/compat/stream-writable/index.js +8 -0
- package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
- package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
- package/dist/compat/string-decoder/index.d.ts +33 -0
- package/dist/compat/string-decoder/index.js +518 -0
- package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/test/LICENSE-APACHE +177 -0
- package/dist/compat/test/index.d.ts +9 -0
- package/dist/compat/test/index.js +11 -0
- package/dist/compat/test/mock.d.ts +103 -0
- package/dist/compat/test/mock.js +397 -0
- package/dist/compat/test/validators.d.ts +2 -0
- package/dist/compat/test/validators.js +14 -0
- package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/timers/LICENSE-APACHE +177 -0
- package/dist/compat/timers/errors.d.ts +28 -0
- package/dist/compat/timers/errors.js +206 -0
- package/dist/compat/timers/host.d.ts +11 -0
- package/dist/compat/timers/host.js +60 -0
- package/dist/compat/timers/index.cjs +3 -0
- package/dist/compat/timers/index.d.cts +23 -0
- package/dist/compat/timers/index.d.ts +36 -0
- package/dist/compat/timers/index.js +20 -0
- package/dist/compat/timers/installation.d.ts +4 -0
- package/dist/compat/timers/installation.js +61 -0
- package/dist/compat/timers/internal-promises.d.ts +19 -0
- package/dist/compat/timers/internal-promises.js +173 -0
- package/dist/compat/timers/promises.cjs +2 -0
- package/dist/compat/timers/promises.d.cts +12 -0
- package/dist/compat/timers/promises.d.ts +14 -0
- package/dist/compat/timers/promises.js +3 -0
- package/dist/compat/timers/timers.d.ts +32 -0
- package/dist/compat/timers/timers.js +147 -0
- package/dist/compat/timers/validation.d.ts +5 -0
- package/dist/compat/timers/validation.js +22 -0
- package/dist/compat/timers/wait.d.ts +4 -0
- package/dist/compat/timers/wait.js +91 -0
- package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-common/LICENSE-APACHE +177 -0
- package/dist/compat/tls-common/index.d.ts +14 -0
- package/dist/compat/tls-common/index.js +88 -0
- package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/trace-events/LICENSE-APACHE +177 -0
- package/dist/compat/trace-events/index.d.ts +18 -0
- package/dist/compat/trace-events/index.js +88 -0
- package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/tty/LICENSE-APACHE +177 -0
- package/dist/compat/tty/index.d.ts +17 -0
- package/dist/compat/tty/index.js +101 -0
- package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
- package/dist/compat/url/LICENSE-ADA +18 -0
- package/dist/compat/url/LICENSE-APACHE +177 -0
- package/dist/compat/url/LICENSE-UNICODE +39 -0
- package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
- package/dist/compat/url/brand.d.ts +4 -0
- package/dist/compat/url/brand.js +10 -0
- package/dist/compat/url/constants.d.ts +27 -0
- package/dist/compat/url/constants.js +28 -0
- package/dist/compat/url/errors.d.ts +44 -0
- package/dist/compat/url/errors.js +248 -0
- package/dist/compat/url/idna-data.d.ts +3958 -0
- package/dist/compat/url/idna-data.js +22 -0
- package/dist/compat/url/idna.d.ts +9 -0
- package/dist/compat/url/idna.js +47 -0
- package/dist/compat/url/index.d.ts +48 -0
- package/dist/compat/url/index.js +39 -0
- package/dist/compat/url/installation.d.ts +4 -0
- package/dist/compat/url/installation.js +61 -0
- package/dist/compat/url/internal-url.d.ts +34 -0
- package/dist/compat/url/internal-url.js +264 -0
- package/dist/compat/url/legacy-url.d.ts +28 -0
- package/dist/compat/url/legacy-url.js +870 -0
- package/dist/compat/url/parser-platform.d.ts +3 -0
- package/dist/compat/url/parser-platform.js +26 -0
- package/dist/compat/url/standard-url.d.ts +2 -0
- package/dist/compat/url/standard-url.js +3189 -0
- package/dist/compat/url/unicode.d.ts +2 -0
- package/dist/compat/url/unicode.js +119 -0
- package/dist/compat/url/validation.d.ts +2 -0
- package/dist/compat/url/validation.js +9 -0
- package/dist/compat/url/web-url.d.ts +27 -0
- package/dist/compat/url/web-url.js +119 -0
- package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/util/LICENSE-APACHE +177 -0
- package/dist/compat/util/additional.d.ts +11 -0
- package/dist/compat/util/additional.js +121 -0
- package/dist/compat/util/comparison-types.d.ts +16 -0
- package/dist/compat/util/comparison-types.js +50 -0
- package/dist/compat/util/comparisons.d.ts +1 -0
- package/dist/compat/util/comparisons.js +527 -0
- package/dist/compat/util/core.d.ts +18 -0
- package/dist/compat/util/core.js +265 -0
- package/dist/compat/util/debuglog.d.ts +1 -0
- package/dist/compat/util/debuglog.js +78 -0
- package/dist/compat/util/index.d.ts +35 -0
- package/dist/compat/util/index.js +77 -0
- package/dist/compat/util/inspect-binding.d.ts +13 -0
- package/dist/compat/util/inspect-binding.js +39 -0
- package/dist/compat/util/inspect-types.d.ts +13 -0
- package/dist/compat/util/inspect-types.js +30 -0
- package/dist/compat/util/inspect.d.ts +152 -0
- package/dist/compat/util/inspect.js +2503 -0
- package/dist/compat/util/mime.d.ts +24 -0
- package/dist/compat/util/mime.js +284 -0
- package/dist/compat/util/properties.d.ts +9 -0
- package/dist/compat/util/properties.js +76 -0
- package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/v8/LICENSE-APACHE +177 -0
- package/dist/compat/v8/errors.d.ts +5 -0
- package/dist/compat/v8/errors.js +7 -0
- package/dist/compat/v8/index.d.ts +106 -0
- package/dist/compat/v8/index.js +280 -0
- package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/vm/LICENSE-APACHE +177 -0
- package/dist/compat/vm/errors.d.ts +5 -0
- package/dist/compat/vm/errors.js +7 -0
- package/dist/compat/vm/index.d.ts +47 -0
- package/dist/compat/vm/index.js +231 -0
- package/dist/compat/vm/validation.d.ts +3 -0
- package/dist/compat/vm/validation.js +14 -0
- package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/wasi/LICENSE-APACHE +177 -0
- package/dist/compat/wasi/errors.d.ts +4 -0
- package/dist/compat/wasi/errors.js +6 -0
- package/dist/compat/wasi/index.d.ts +15 -0
- package/dist/compat/wasi/index.js +44 -0
- package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
- package/dist/compat/worker-threads/errors.d.ts +4 -0
- package/dist/compat/worker-threads/errors.js +6 -0
- package/dist/compat/worker-threads/index.d.ts +71 -0
- package/dist/compat/worker-threads/index.js +138 -0
- package/dist/compat/worker-threads/message-channel.d.ts +18 -0
- package/dist/compat/worker-threads/message-channel.js +157 -0
- package/dist/configured.d.ts +3 -0
- package/dist/configured.js +4 -0
- package/dist/environment.d.ts +4 -0
- package/dist/environment.js +18 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +107 -0
- package/dist/ios.d.ts +2 -0
- package/dist/ios.js +1 -0
- package/dist/native-entry.d.ts +8 -0
- package/dist/native-entry.js +67 -0
- package/dist/shared/brotli/LICENSE-APACHE +201 -0
- package/dist/shared/brotli/LICENSE-MIT +9 -0
- package/dist/shared/brotli/NOTICE +3 -0
- package/dist/shared/brotli/index.d.ts +2 -0
- package/dist/shared/brotli/index.js +288 -0
- package/dist/shared/contracts/index.d.ts +42 -0
- package/dist/shared/contracts/index.js +88 -0
- package/dist/shared/contracts/testing.d.ts +22 -0
- package/dist/shared/contracts/testing.js +57 -0
- package/dist/shared/globals/index.d.ts +3 -0
- package/dist/shared/globals/index.js +87 -0
- package/dist/shared/globals/inject.d.ts +2 -0
- package/dist/shared/globals/inject.js +3 -0
- package/dist/shared/globals/install.d.ts +1 -0
- package/dist/shared/globals/install.js +15 -0
- package/dist/shared/globals/node-install.d.ts +1 -0
- package/dist/shared/globals/node-install.js +4 -0
- package/dist/shared/globals/platform.d.ts +104 -0
- package/dist/shared/globals/platform.js +37 -0
- package/dist/shared/globals/runtime.d.ts +6 -0
- package/dist/shared/globals/runtime.js +8 -0
- package/dist/shared/globals/symbols.d.ts +4 -0
- package/dist/shared/globals/symbols.js +35 -0
- package/dist/shared/globals/web.d.ts +4 -0
- package/dist/shared/globals/web.js +108 -0
- package/dist/shared/http-wire/LICENSE.llhttp +22 -0
- package/dist/shared/http-wire/LICENSE.undici +21 -0
- package/dist/shared/http-wire/NOTICE.md +14 -0
- package/dist/shared/http-wire/index.d.ts +27 -0
- package/dist/shared/http-wire/index.js +132 -0
- package/dist/shared/http-wire/wasm.d.ts +2 -0
- package/dist/shared/http-wire/wasm.js +2 -0
- package/dist/tooling/async.d.ts +7 -0
- package/dist/tooling/async.js +99 -0
- package/dist/tooling/build-isolation.d.ts +4 -0
- package/dist/tooling/build-isolation.js +34 -0
- package/dist/tooling/documents.d.ts +7 -0
- package/dist/tooling/documents.js +26 -0
- package/dist/tooling/esbuild.d.ts +15 -0
- package/dist/tooling/esbuild.js +193 -0
- package/dist/tooling/files.d.ts +2 -0
- package/dist/tooling/files.js +18 -0
- package/dist/tooling/opennext/build.d.ts +1 -0
- package/dist/tooling/opennext/build.js +121 -0
- package/dist/tooling/opennext/index.d.ts +3 -0
- package/dist/tooling/opennext/index.js +213 -0
- package/dist/tooling/opennext/plan.d.ts +9 -0
- package/dist/tooling/opennext/plan.js +36 -0
- package/dist/tooling/opennext/safety.d.ts +4 -0
- package/dist/tooling/opennext/safety.js +36 -0
- package/dist/tooling/route-permissions.d.ts +3 -0
- package/dist/tooling/route-permissions.js +15 -0
- package/dist/tooling/server-modules.d.ts +30 -0
- package/dist/tooling/server-modules.js +98 -0
- package/dist/tooling/server-only-html.d.ts +1 -0
- package/dist/tooling/server-only-html.js +66 -0
- package/dist/tooling/server-only.d.ts +6 -0
- package/dist/tooling/server-only.js +53 -0
- package/dist/tooling/server.d.ts +25 -0
- package/dist/tooling/server.js +981 -0
- package/dist/tooling/shared.d.ts +13 -0
- package/dist/tooling/shared.js +130 -0
- package/dist/tooling/vite.d.ts +18 -0
- package/dist/tooling/vite.js +448 -0
- package/dist/tooling/void/index.d.ts +3 -0
- package/dist/tooling/void/index.js +205 -0
- package/dist/tooling/void/plan.d.ts +17 -0
- package/dist/tooling/void/plan.js +288 -0
- package/native/android/build.gradle +68 -0
- package/native/android/consumer-rules.pro +2 -0
- package/native/android/src/main/AndroidManifest.xml +6 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
- package/native/ios/DocumentBridge.swift +330 -0
- package/native/ios/NetworkBridge.swift +51 -0
- package/native/ios/SocketBridge.swift +180 -0
- package/native/ios/WorkersCapacitorPlugin.swift +152 -0
- package/native/ios-host/WorkersView.swift +194 -0
- package/package.json +154 -4
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { build } from "esbuild";
|
|
3
|
+
import { parseAst } from "rollup/parseAst";
|
|
4
|
+
import { serverOnlyFiles } from "./server-only.js";
|
|
5
|
+
import { permitsPath } from "./route-permissions.js";
|
|
6
|
+
import { transformAsync } from "@babel/core";
|
|
7
|
+
export { serverBindings, } from "../cloudflare/bindings/config.js";
|
|
8
|
+
class WiderServerBoundary extends Error {
|
|
9
|
+
}
|
|
10
|
+
function walk(node, visit, parent) {
|
|
11
|
+
visit(node, parent);
|
|
12
|
+
for (const value of Object.values(node)) {
|
|
13
|
+
const children = Array.isArray(value) ? value : [value];
|
|
14
|
+
for (const child of children)
|
|
15
|
+
if (child && typeof child === "object" && typeof child.type === "string")
|
|
16
|
+
walk(child, visit, node);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function names(node) {
|
|
20
|
+
const result = new Set();
|
|
21
|
+
walk(node, (child) => {
|
|
22
|
+
if (child.type === "Identifier")
|
|
23
|
+
result.add(child.name);
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function property(node) {
|
|
28
|
+
if (node.type !== "MemberExpression")
|
|
29
|
+
return;
|
|
30
|
+
if (!node.computed && node.property.type === "Identifier")
|
|
31
|
+
return node.property.name;
|
|
32
|
+
if (node.computed &&
|
|
33
|
+
node.property.type === "Literal" &&
|
|
34
|
+
typeof node.property.value === "string")
|
|
35
|
+
return node.property.value;
|
|
36
|
+
}
|
|
37
|
+
const routeMethods = new Set([
|
|
38
|
+
"get",
|
|
39
|
+
"post",
|
|
40
|
+
"put",
|
|
41
|
+
"patch",
|
|
42
|
+
"delete",
|
|
43
|
+
"options",
|
|
44
|
+
"head",
|
|
45
|
+
"all",
|
|
46
|
+
"on",
|
|
47
|
+
"use",
|
|
48
|
+
]);
|
|
49
|
+
/** Bundle local modules first so imported/re-exported helpers share one dependency graph. */
|
|
50
|
+
export async function compileServerWorker(entry, bindings, options = {}) {
|
|
51
|
+
const { execution = "network", localBindings = [], kvBindings = [], forceRemoteReason, serverOnly = [], ...buildOptions } = options;
|
|
52
|
+
if (execution !== "network" &&
|
|
53
|
+
execution !== "local" &&
|
|
54
|
+
!Array.isArray(execution))
|
|
55
|
+
throw new TypeError('execution must be "network", "local", or an array of route permissions');
|
|
56
|
+
if (Array.isArray(execution) &&
|
|
57
|
+
execution.some((route) => !route ||
|
|
58
|
+
!/^(\*|GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS)$/.test(route.method) ||
|
|
59
|
+
!(typeof route.path === "string"
|
|
60
|
+
? route.path === "*" || route.path.startsWith("/")
|
|
61
|
+
: route.path instanceof RegExp)))
|
|
62
|
+
throw new TypeError('execution routes require an uppercase HTTP method or "*" and a Hono registration path or RegExp');
|
|
63
|
+
if (execution === "local" && (bindings.length || forceRemoteReason))
|
|
64
|
+
throw new Error("local execution cannot use configured server bindings or server-only events; use network or route permissions");
|
|
65
|
+
if (localBindings.some((name) => bindings.includes(name)))
|
|
66
|
+
throw new Error("A server binding cannot also be a local binding");
|
|
67
|
+
if (execution === "local")
|
|
68
|
+
return {
|
|
69
|
+
mode: "worker",
|
|
70
|
+
reason: "Entire Worker distribution explicitly permitted",
|
|
71
|
+
// Keep the host bundler's loaders, aliases and transforms for full local execution.
|
|
72
|
+
local: `export { default } from ${JSON.stringify(entry.replaceAll("\\", "/"))};`,
|
|
73
|
+
selector: "export function needsRemote() { return false; }",
|
|
74
|
+
inputs: [],
|
|
75
|
+
routes: [
|
|
76
|
+
{
|
|
77
|
+
router: "worker",
|
|
78
|
+
method: "all",
|
|
79
|
+
path: "*",
|
|
80
|
+
remote: false,
|
|
81
|
+
reason: "Entire Worker distribution explicitly permitted; runtime compatibility is the application's responsibility",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
const denied = serverOnlyFiles(dirname(entry), serverOnly);
|
|
86
|
+
const privateInputs = new Set();
|
|
87
|
+
const bundled = await build({
|
|
88
|
+
...buildOptions,
|
|
89
|
+
plugins: [
|
|
90
|
+
{
|
|
91
|
+
name: "server-only-boundary",
|
|
92
|
+
setup(build) {
|
|
93
|
+
build.onLoad({ filter: /.*/ }, ({ path }) => {
|
|
94
|
+
if (!denied.matches(path))
|
|
95
|
+
return;
|
|
96
|
+
privateInputs.add(path);
|
|
97
|
+
return { contents: "", loader: "empty" };
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
absWorkingDir: dirname(entry),
|
|
103
|
+
entryPoints: [entry],
|
|
104
|
+
bundle: true,
|
|
105
|
+
packages: "external",
|
|
106
|
+
// Remote-only applications may import Cloudflare WASM modules and binary
|
|
107
|
+
// assets (for example next/og). Keep these files in the dependency graph
|
|
108
|
+
// for the client-import guard, without embedding unused server data.
|
|
109
|
+
loader: forceRemoteReason || execution === "network"
|
|
110
|
+
? { ".wasm": "empty", ".bin": "empty" }
|
|
111
|
+
: undefined,
|
|
112
|
+
format: "esm",
|
|
113
|
+
platform: "neutral",
|
|
114
|
+
write: false,
|
|
115
|
+
metafile: true,
|
|
116
|
+
treeShaking: true,
|
|
117
|
+
target: "es2022",
|
|
118
|
+
legalComments: "none",
|
|
119
|
+
logLevel: "silent",
|
|
120
|
+
});
|
|
121
|
+
const source = bundled.outputFiles[0].text;
|
|
122
|
+
const inputs = Object.keys(bundled.metafile.inputs).map((file) => resolve(dirname(entry), file));
|
|
123
|
+
try {
|
|
124
|
+
if (privateInputs.size)
|
|
125
|
+
throw new WiderServerBoundary(`Declared server-only dependency: ${[...privateInputs].join(", ")}`);
|
|
126
|
+
if (execution === "network")
|
|
127
|
+
throw new WiderServerBoundary("Network execution explicitly selected");
|
|
128
|
+
if (forceRemoteReason)
|
|
129
|
+
throw new WiderServerBoundary(forceRemoteReason);
|
|
130
|
+
return await partition(source, bindings, inputs, localBindings, kvBindings, execution);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (!(error instanceof WiderServerBoundary))
|
|
134
|
+
throw error;
|
|
135
|
+
return {
|
|
136
|
+
mode: "worker",
|
|
137
|
+
reason: error.message,
|
|
138
|
+
inputs,
|
|
139
|
+
local: 'export default { fetch() { throw new Error("Server-only Worker reached local dispatch"); } };',
|
|
140
|
+
selector: "export function needsRemote() { return true; }",
|
|
141
|
+
routes: [
|
|
142
|
+
{
|
|
143
|
+
router: "worker",
|
|
144
|
+
method: "all",
|
|
145
|
+
path: "*",
|
|
146
|
+
remote: true,
|
|
147
|
+
reason: error.message,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// A missing server binding is not proof of a local dependency. Resolve lexical
|
|
154
|
+
// bindings with Babel (already used by the build), including shadowed parameters.
|
|
155
|
+
// Network, process, caches and unknown host globals deliberately have no local
|
|
156
|
+
// contract here. Request dispatch stays on the server when they are referenced.
|
|
157
|
+
async function unresolvedReferences(source) {
|
|
158
|
+
const globals = new Set([
|
|
159
|
+
"undefined",
|
|
160
|
+
"NaN",
|
|
161
|
+
"Infinity",
|
|
162
|
+
"JSON",
|
|
163
|
+
"String",
|
|
164
|
+
"Number",
|
|
165
|
+
"Boolean",
|
|
166
|
+
"BigInt",
|
|
167
|
+
"Array",
|
|
168
|
+
"Object",
|
|
169
|
+
"Math",
|
|
170
|
+
"URL",
|
|
171
|
+
"URLSearchParams",
|
|
172
|
+
"TextEncoder",
|
|
173
|
+
"TextDecoder",
|
|
174
|
+
"Response",
|
|
175
|
+
"Request",
|
|
176
|
+
"Headers",
|
|
177
|
+
"Promise",
|
|
178
|
+
"RegExp",
|
|
179
|
+
"Error",
|
|
180
|
+
"TypeError",
|
|
181
|
+
"RangeError",
|
|
182
|
+
]);
|
|
183
|
+
const staticCalls = {
|
|
184
|
+
JSON: ["parse", "stringify"],
|
|
185
|
+
Math: [
|
|
186
|
+
"abs",
|
|
187
|
+
"ceil",
|
|
188
|
+
"floor",
|
|
189
|
+
"round",
|
|
190
|
+
"trunc",
|
|
191
|
+
"min",
|
|
192
|
+
"max",
|
|
193
|
+
"pow",
|
|
194
|
+
"sqrt",
|
|
195
|
+
"sign",
|
|
196
|
+
"random",
|
|
197
|
+
],
|
|
198
|
+
Number: [
|
|
199
|
+
"isFinite",
|
|
200
|
+
"isInteger",
|
|
201
|
+
"isNaN",
|
|
202
|
+
"isSafeInteger",
|
|
203
|
+
"parseFloat",
|
|
204
|
+
"parseInt",
|
|
205
|
+
],
|
|
206
|
+
String: ["fromCharCode", "fromCodePoint", "raw"],
|
|
207
|
+
Array: ["isArray", "from", "of"],
|
|
208
|
+
Object: ["is"],
|
|
209
|
+
Promise: ["resolve", "reject", "all", "allSettled", "race", "any"],
|
|
210
|
+
Response: ["json", "redirect", "error"],
|
|
211
|
+
URL: ["canParse", "parse"],
|
|
212
|
+
};
|
|
213
|
+
const staticValues = {
|
|
214
|
+
Math: ["E", "LN2", "LN10", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"],
|
|
215
|
+
Number: [
|
|
216
|
+
"EPSILON",
|
|
217
|
+
"MAX_SAFE_INTEGER",
|
|
218
|
+
"MIN_SAFE_INTEGER",
|
|
219
|
+
"MAX_VALUE",
|
|
220
|
+
"MIN_VALUE",
|
|
221
|
+
"NaN",
|
|
222
|
+
"NEGATIVE_INFINITY",
|
|
223
|
+
"POSITIVE_INFINITY",
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
const unresolved = new Set();
|
|
227
|
+
const references = new Map();
|
|
228
|
+
await transformAsync(source, {
|
|
229
|
+
configFile: false,
|
|
230
|
+
babelrc: false,
|
|
231
|
+
sourceType: "module",
|
|
232
|
+
code: false,
|
|
233
|
+
ast: false,
|
|
234
|
+
plugins: [
|
|
235
|
+
() => ({
|
|
236
|
+
visitor: {
|
|
237
|
+
ThisExpression(path) {
|
|
238
|
+
unresolved.add(path.node.start);
|
|
239
|
+
},
|
|
240
|
+
ObjectPattern(path) {
|
|
241
|
+
if (path.node.properties.some((property) => property.type === "ObjectProperty" &&
|
|
242
|
+
(property.computed ||
|
|
243
|
+
(property.key.type === "Identifier" &&
|
|
244
|
+
["constructor", "__proto__"].includes(property.key.name)) ||
|
|
245
|
+
(property.key.type === "StringLiteral" &&
|
|
246
|
+
["constructor", "__proto__"].includes(property.key.value)))))
|
|
247
|
+
throw new WiderServerBoundary("Dynamic runtime access requires a single Worker boundary");
|
|
248
|
+
unresolved.add(path.node.start);
|
|
249
|
+
},
|
|
250
|
+
SpreadElement(path) {
|
|
251
|
+
unresolved.add(path.node.start);
|
|
252
|
+
},
|
|
253
|
+
MetaProperty(path) {
|
|
254
|
+
unresolved.add(path.node.start);
|
|
255
|
+
},
|
|
256
|
+
AssignmentExpression(path) {
|
|
257
|
+
let target = path.node.left;
|
|
258
|
+
while (target.type === "MemberExpression")
|
|
259
|
+
target = target.object;
|
|
260
|
+
if (target.type !== "Identifier" ||
|
|
261
|
+
!path.scope.getBinding(target.name))
|
|
262
|
+
throw new WiderServerBoundary("Writes to ambient state require a single Worker boundary");
|
|
263
|
+
},
|
|
264
|
+
UpdateExpression(path) {
|
|
265
|
+
let target = path.node.argument;
|
|
266
|
+
while (target.type === "MemberExpression")
|
|
267
|
+
target = target.object;
|
|
268
|
+
if (target.type !== "Identifier" ||
|
|
269
|
+
!path.scope.getBinding(target.name))
|
|
270
|
+
throw new WiderServerBoundary("Writes to ambient state require a single Worker boundary");
|
|
271
|
+
},
|
|
272
|
+
ReferencedIdentifier(path) {
|
|
273
|
+
const name = path.node.name;
|
|
274
|
+
const binding = path.scope.getBinding(name);
|
|
275
|
+
if (!binding || binding.scope.path.isProgram())
|
|
276
|
+
references.set(path.node.start, name);
|
|
277
|
+
if (binding) {
|
|
278
|
+
if (binding.kind === "module") {
|
|
279
|
+
const declaration = binding.path.parentPath;
|
|
280
|
+
if (declaration?.isImportDeclaration() &&
|
|
281
|
+
[
|
|
282
|
+
"hono",
|
|
283
|
+
"hono/html",
|
|
284
|
+
"hono/jsx",
|
|
285
|
+
"hono/jsx/jsx-runtime",
|
|
286
|
+
].includes(declaration.node.source.value)) {
|
|
287
|
+
const use = path.parentPath;
|
|
288
|
+
if (!(((use.isCallExpression() || use.isNewExpression()) &&
|
|
289
|
+
use.node.callee === path.node) ||
|
|
290
|
+
(use.isTaggedTemplateExpression() &&
|
|
291
|
+
use.node.tag === path.node)))
|
|
292
|
+
throw new WiderServerBoundary("Escaped rendering import requires a single Worker boundary");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (["eval", "Function", "Reflect", "Proxy"].includes(name))
|
|
298
|
+
throw new WiderServerBoundary("Dynamic runtime access requires a single Worker boundary");
|
|
299
|
+
if (!globals.has(name)) {
|
|
300
|
+
unresolved.add(path.node.start);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (["undefined", "NaN", "Infinity"].includes(name))
|
|
304
|
+
return;
|
|
305
|
+
const parent = path.parentPath;
|
|
306
|
+
if ((parent.isCallExpression() || parent.isNewExpression()) &&
|
|
307
|
+
parent.node.callee === path.node &&
|
|
308
|
+
!["Math", "JSON"].includes(name))
|
|
309
|
+
return;
|
|
310
|
+
if (parent.isMemberExpression() &&
|
|
311
|
+
parent.node.object === path.node) {
|
|
312
|
+
const key = !parent.node.computed &&
|
|
313
|
+
parent.node.property.type === "Identifier"
|
|
314
|
+
? parent.node.property.name
|
|
315
|
+
: parent.node.computed &&
|
|
316
|
+
parent.node.property.type === "StringLiteral"
|
|
317
|
+
? parent.node.property.value
|
|
318
|
+
: undefined;
|
|
319
|
+
if (key && staticValues[name]?.includes(key))
|
|
320
|
+
return;
|
|
321
|
+
const use = parent.parentPath;
|
|
322
|
+
if (key &&
|
|
323
|
+
staticCalls[name]?.includes(key) &&
|
|
324
|
+
use.isCallExpression() &&
|
|
325
|
+
use.node.callee === parent.node)
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
// Do not chase aliases, reflection or arbitrary mutation of host objects.
|
|
329
|
+
throw new WiderServerBoundary("Escaped or unsupported use of a standard global requires a single Worker boundary");
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
}),
|
|
333
|
+
],
|
|
334
|
+
});
|
|
335
|
+
return { unresolved, references };
|
|
336
|
+
}
|
|
337
|
+
async function partition(source, bindings, inputs, localBindings, kvBindings, routePermissions) {
|
|
338
|
+
const program = parseAst(source);
|
|
339
|
+
const text = (node) => {
|
|
340
|
+
const span = node;
|
|
341
|
+
return source.slice(span.start, span.end);
|
|
342
|
+
};
|
|
343
|
+
function fail(message) {
|
|
344
|
+
throw new WiderServerBoundary(message);
|
|
345
|
+
}
|
|
346
|
+
const declarations = new Map();
|
|
347
|
+
const variables = new Map();
|
|
348
|
+
const constructors = new Set();
|
|
349
|
+
const environmentImports = new Set();
|
|
350
|
+
const opaqueImports = new Set();
|
|
351
|
+
const routerInitializers = new Map();
|
|
352
|
+
const routerNodes = new Map();
|
|
353
|
+
const writes = new Map();
|
|
354
|
+
const mutable = new Set();
|
|
355
|
+
const remoteState = new Set();
|
|
356
|
+
const registrations = new Map();
|
|
357
|
+
let exported;
|
|
358
|
+
for (const statement of program.body) {
|
|
359
|
+
if (statement.type === "ImportDeclaration") {
|
|
360
|
+
if (!statement.specifiers.length)
|
|
361
|
+
fail(`side-effect import ${statement.source.value} has no route owner`);
|
|
362
|
+
for (const specifier of statement.specifiers) {
|
|
363
|
+
declarations.set(specifier.local.name, statement);
|
|
364
|
+
if (typeof statement.source.value !== "string" ||
|
|
365
|
+
!["hono", "hono/html", "hono/jsx", "hono/jsx/jsx-runtime"].includes(statement.source.value))
|
|
366
|
+
opaqueImports.add(specifier.local.name);
|
|
367
|
+
if (statement.source.value === "hono" &&
|
|
368
|
+
specifier.type === "ImportSpecifier" &&
|
|
369
|
+
specifier.imported.type === "Identifier" &&
|
|
370
|
+
specifier.imported.name === "Hono")
|
|
371
|
+
constructors.add(specifier.local.name);
|
|
372
|
+
if (statement.source.value === "cloudflare:workers" &&
|
|
373
|
+
specifier.type === "ImportSpecifier" &&
|
|
374
|
+
specifier.imported.type === "Identifier" &&
|
|
375
|
+
specifier.imported.name === "env")
|
|
376
|
+
environmentImports.add(specifier.local.name);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if (statement.type === "VariableDeclaration") {
|
|
380
|
+
if (statement.declarations.length !== 1)
|
|
381
|
+
fail("combined declarations need separate dependency ownership");
|
|
382
|
+
const declaration = statement.declarations[0];
|
|
383
|
+
if (declaration.id.type !== "Identifier")
|
|
384
|
+
fail("top-level destructuring needs separate dependency ownership");
|
|
385
|
+
declarations.set(declaration.id.name, statement);
|
|
386
|
+
variables.set(declaration.id.name, declaration);
|
|
387
|
+
if (!declaration.init ||
|
|
388
|
+
declaration.init.type !== "Literal" ||
|
|
389
|
+
"regex" in declaration.init)
|
|
390
|
+
mutable.add(declaration.id.name);
|
|
391
|
+
}
|
|
392
|
+
else if ((statement.type === "FunctionDeclaration" ||
|
|
393
|
+
statement.type === "ClassDeclaration") &&
|
|
394
|
+
statement.id) {
|
|
395
|
+
if (statement.type === "ClassDeclaration")
|
|
396
|
+
fail("class initialization and static state require a single Worker boundary");
|
|
397
|
+
declarations.set(statement.id.name, statement);
|
|
398
|
+
// Functions are objects too: properties can be mutated directly, through
|
|
399
|
+
// aliases, or by Object.assign. Do not assume declaration syntax is immutable.
|
|
400
|
+
mutable.add(statement.id.name);
|
|
401
|
+
}
|
|
402
|
+
else if (statement.type === "ExportNamedDeclaration") {
|
|
403
|
+
for (const specifier of statement.specifiers)
|
|
404
|
+
if ((specifier.exported.type === "Identifier"
|
|
405
|
+
? specifier.exported.name
|
|
406
|
+
: specifier.exported.value) === "default" &&
|
|
407
|
+
specifier.local.type === "Identifier")
|
|
408
|
+
exported = specifier.local.name;
|
|
409
|
+
if (statement.declaration ||
|
|
410
|
+
statement.specifiers.length !== 1 ||
|
|
411
|
+
!exported)
|
|
412
|
+
fail("additional Worker exports require their own execution boundaries");
|
|
413
|
+
}
|
|
414
|
+
else if (statement.type !== "ExpressionStatement" &&
|
|
415
|
+
statement.type !== "EmptyStatement")
|
|
416
|
+
fail(`unsupported top-level ${statement.type}`);
|
|
417
|
+
}
|
|
418
|
+
// Cookie state belongs to the deployed origin's session jar. A Worker that
|
|
419
|
+
// touches it must not split login/logout/profile between two independent jars.
|
|
420
|
+
// Likewise, ambient global state cannot be shared with a local module instance.
|
|
421
|
+
const sharedGlobals = new Set([
|
|
422
|
+
"globalThis",
|
|
423
|
+
"global",
|
|
424
|
+
"self",
|
|
425
|
+
"window",
|
|
426
|
+
"document",
|
|
427
|
+
"process",
|
|
428
|
+
]);
|
|
429
|
+
const headerMethods = new Set(["get", "has", "set", "append", "delete"]);
|
|
430
|
+
const cookieName = (value) => typeof value === "string" && /^(?:set-)?cookie2?$/i.test(value);
|
|
431
|
+
function staticHeaderNames(node) {
|
|
432
|
+
if (node.type === "ObjectExpression")
|
|
433
|
+
return node.properties.every((item) => item.type === "Property" &&
|
|
434
|
+
!item.computed &&
|
|
435
|
+
(item.key.type === "Identifier" || item.key.type === "Literal"));
|
|
436
|
+
if (node.type === "ArrayExpression")
|
|
437
|
+
return node.elements.every((item) => item?.type === "ArrayExpression" &&
|
|
438
|
+
item.elements[0]?.type === "Literal" &&
|
|
439
|
+
typeof item.elements[0].value === "string");
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
// Direct operations on a configured server/KV binding cannot be local Headers
|
|
443
|
+
// operations. Aliases and other unknown receivers retain the conservative check.
|
|
444
|
+
function serverBindingReceiver(node) {
|
|
445
|
+
if (node.type !== "MemberExpression" ||
|
|
446
|
+
![...bindings, ...kvBindings].includes(property(node) ?? ""))
|
|
447
|
+
return false;
|
|
448
|
+
return ((node.object.type === "MemberExpression" &&
|
|
449
|
+
property(node.object) === "env") ||
|
|
450
|
+
(node.object.type === "Identifier" &&
|
|
451
|
+
environmentImports.has(node.object.name)));
|
|
452
|
+
}
|
|
453
|
+
walk(program, (child, parent) => {
|
|
454
|
+
if (child.type === "ImportDeclaration" &&
|
|
455
|
+
child.source.value === "hono/cookie")
|
|
456
|
+
fail("cookie helpers require a single Worker session boundary");
|
|
457
|
+
if (child.type === "Identifier" && sharedGlobals.has(child.name))
|
|
458
|
+
fail("ambient global state requires a single Worker boundary");
|
|
459
|
+
if ((child.type === "Literal" && cookieName(child.value)) ||
|
|
460
|
+
(child.type === "Identifier" && cookieName(child.name)))
|
|
461
|
+
fail("Cookie and Set-Cookie access require a single Worker session boundary");
|
|
462
|
+
if (child.type === "MemberExpression" &&
|
|
463
|
+
(property(child) === "header" ||
|
|
464
|
+
headerMethods.has(property(child) ?? "")) &&
|
|
465
|
+
!(parent?.type === "CallExpression" && parent.callee === child))
|
|
466
|
+
fail("escaped header or collection methods may access Cookie session state");
|
|
467
|
+
if (child.type === "Identifier" &&
|
|
468
|
+
child.name === "Headers" &&
|
|
469
|
+
!(parent?.type === "NewExpression" && parent.callee === child))
|
|
470
|
+
fail("an escaped Headers constructor may access Cookie session state");
|
|
471
|
+
if (child.type === "MemberExpression" &&
|
|
472
|
+
property(child) === "headers" &&
|
|
473
|
+
!(parent?.type === "MemberExpression" &&
|
|
474
|
+
parent.object === child &&
|
|
475
|
+
headerMethods.has(property(parent) ?? "")))
|
|
476
|
+
fail("an escaped header collection may contain Cookie session state");
|
|
477
|
+
if (child.type === "Property" &&
|
|
478
|
+
!child.computed &&
|
|
479
|
+
(child.key.type === "Identifier"
|
|
480
|
+
? child.key.name
|
|
481
|
+
: child.key.type === "Literal"
|
|
482
|
+
? child.key.value
|
|
483
|
+
: undefined) === "headers" &&
|
|
484
|
+
!staticHeaderNames(child.value))
|
|
485
|
+
fail("dynamic header collections may contain Cookie session state");
|
|
486
|
+
if (child.type === "NewExpression" &&
|
|
487
|
+
child.callee.type === "Identifier" &&
|
|
488
|
+
child.callee.name === "Headers" &&
|
|
489
|
+
child.arguments.length &&
|
|
490
|
+
!staticHeaderNames(child.arguments[0]))
|
|
491
|
+
fail("dynamic Headers initialization may contain Cookie session state");
|
|
492
|
+
if (child.type === "CallExpression" &&
|
|
493
|
+
child.callee.type === "MemberExpression") {
|
|
494
|
+
const method = property(child.callee);
|
|
495
|
+
// An aliased Headers receiver is indistinguishable from another collection
|
|
496
|
+
// here. Unknown collection keys therefore widen the boundary conservatively.
|
|
497
|
+
if ((method === "header" || headerMethods.has(method ?? "")) &&
|
|
498
|
+
!serverBindingReceiver(child.callee.object) &&
|
|
499
|
+
(child.arguments[0]?.type !== "Literal" ||
|
|
500
|
+
typeof child.arguments[0].value !== "string"))
|
|
501
|
+
fail("dynamic header or collection access may contain Cookie session state");
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
walk(program, (child) => {
|
|
505
|
+
if (child.type !== "AssignmentExpression" &&
|
|
506
|
+
child.type !== "UpdateExpression")
|
|
507
|
+
return;
|
|
508
|
+
let target = child.type === "AssignmentExpression" ? child.left : child.argument;
|
|
509
|
+
while (target.type === "MemberExpression")
|
|
510
|
+
target = target.object;
|
|
511
|
+
if (target.type === "Identifier" && declarations.has(target.name)) {
|
|
512
|
+
mutable.add(target.name);
|
|
513
|
+
if (child.type === "AssignmentExpression")
|
|
514
|
+
writes.set(target.name, [
|
|
515
|
+
...(writes.get(target.name) ?? []),
|
|
516
|
+
child.right,
|
|
517
|
+
]);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
function chain(node) {
|
|
521
|
+
if (node.type === "CallExpression" &&
|
|
522
|
+
node.callee.type === "MemberExpression" &&
|
|
523
|
+
node.callee.object.type !== "Super") {
|
|
524
|
+
const inner = chain(node.callee.object);
|
|
525
|
+
return { root: inner.root, calls: [...inner.calls, node] };
|
|
526
|
+
}
|
|
527
|
+
return { root: node, calls: [] };
|
|
528
|
+
}
|
|
529
|
+
for (const [name, declaration] of variables) {
|
|
530
|
+
if (!declaration.init)
|
|
531
|
+
continue;
|
|
532
|
+
const sequence = chain(declaration.init);
|
|
533
|
+
if (sequence.root.type === "NewExpression" &&
|
|
534
|
+
sequence.root.callee.type === "Identifier" &&
|
|
535
|
+
constructors.has(sequence.root.callee.name)) {
|
|
536
|
+
const args = sequence.root.arguments;
|
|
537
|
+
if (args.length &&
|
|
538
|
+
(args.length !== 1 ||
|
|
539
|
+
args[0].type !== "ObjectExpression" ||
|
|
540
|
+
args[0].properties.some((p) => p.type !== "Property" ||
|
|
541
|
+
p.computed ||
|
|
542
|
+
p.key.type !== "Identifier" ||
|
|
543
|
+
p.key.name !== "strict" ||
|
|
544
|
+
p.value.type !== "Literal" ||
|
|
545
|
+
typeof p.value.value !== "boolean")))
|
|
546
|
+
fail(`custom router construction for ${name} needs matching analysis`);
|
|
547
|
+
let initializer = text(sequence.root);
|
|
548
|
+
if (sequence.calls[0] &&
|
|
549
|
+
property(sequence.calls[0].callee) === "basePath") {
|
|
550
|
+
const call = sequence.calls.shift();
|
|
551
|
+
if (call.arguments.length !== 1 ||
|
|
552
|
+
call.arguments[0].type !== "Literal" ||
|
|
553
|
+
typeof call.arguments[0].value !== "string")
|
|
554
|
+
fail("basePath requires a static path");
|
|
555
|
+
if (!/^\/(?:[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*\/?)?$/.test(call.arguments[0].value))
|
|
556
|
+
fail("Patterned basePath requires a single Worker distribution boundary");
|
|
557
|
+
initializer += `.basePath(${text(call.arguments[0])})`;
|
|
558
|
+
}
|
|
559
|
+
routerInitializers.set(name, `const ${name} = ${initializer};`);
|
|
560
|
+
routerNodes.set(name, declarations.get(name));
|
|
561
|
+
if (sequence.calls.length)
|
|
562
|
+
registrations.set(declarations.get(name), sequence.calls.map((call) => ({ router: name, call })));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
// Removing an unused declaration is safe only when its initializer cannot
|
|
566
|
+
// execute application code. This intentionally excludes calls, property reads,
|
|
567
|
+
// spreads, computed keys and classes; preserving those in two graphs is unsafe.
|
|
568
|
+
function pureInitializer(node) {
|
|
569
|
+
switch (node.type) {
|
|
570
|
+
case "Literal":
|
|
571
|
+
case "Identifier":
|
|
572
|
+
case "ArrowFunctionExpression":
|
|
573
|
+
case "FunctionExpression":
|
|
574
|
+
return true;
|
|
575
|
+
case "ArrayExpression":
|
|
576
|
+
return node.elements.every((value) => !value || pureInitializer(value));
|
|
577
|
+
case "ObjectExpression":
|
|
578
|
+
return node.properties.every((value) => value.type === "Property" &&
|
|
579
|
+
!value.computed &&
|
|
580
|
+
value.kind === "init" &&
|
|
581
|
+
pureInitializer(value.value));
|
|
582
|
+
case "UnaryExpression":
|
|
583
|
+
return node.operator !== "delete" && node.argument.type === "Literal";
|
|
584
|
+
default:
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
for (const [name, declaration] of variables) {
|
|
589
|
+
if (!routerNodes.has(name) &&
|
|
590
|
+
declaration.init &&
|
|
591
|
+
!pureInitializer(declaration.init))
|
|
592
|
+
fail(`initializer for ${name} may execute application code before dispatch`);
|
|
593
|
+
}
|
|
594
|
+
if (!routerNodes.size)
|
|
595
|
+
fail("no statically constructed Hono router was found");
|
|
596
|
+
function rootRouter(name, seen = new Set()) {
|
|
597
|
+
if (routerNodes.has(name))
|
|
598
|
+
return name;
|
|
599
|
+
if (seen.has(name))
|
|
600
|
+
return fail("cyclic router alias");
|
|
601
|
+
seen.add(name);
|
|
602
|
+
const value = variables.get(name)?.init;
|
|
603
|
+
if (value?.type === "Identifier")
|
|
604
|
+
return rootRouter(value.name, seen);
|
|
605
|
+
return fail(`default export ${name} is not an existing router`);
|
|
606
|
+
}
|
|
607
|
+
const root = exported
|
|
608
|
+
? rootRouter(exported)
|
|
609
|
+
: fail("missing default Worker export");
|
|
610
|
+
for (const statement of program.body)
|
|
611
|
+
if (statement.type === "ExpressionStatement") {
|
|
612
|
+
const sequence = chain(statement.expression);
|
|
613
|
+
if (sequence.root.type !== "Identifier" || !sequence.calls.length)
|
|
614
|
+
fail("top-level side effects or dynamic router registration need an explicit execution boundary");
|
|
615
|
+
const router = rootRouter(sequence.root.name);
|
|
616
|
+
registrations.set(statement, sequence.calls.map((call) => ({ router, call })));
|
|
617
|
+
}
|
|
618
|
+
const { unresolved, references } = await unresolvedReferences(source);
|
|
619
|
+
function dependencies(node) {
|
|
620
|
+
const result = new Set();
|
|
621
|
+
walk(node, (child) => {
|
|
622
|
+
const name = references.get(child.start);
|
|
623
|
+
if (name)
|
|
624
|
+
result.add(name);
|
|
625
|
+
});
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
function closure(nodes) {
|
|
629
|
+
const result = new Set(nodes.flatMap((node) => [...dependencies(node)]));
|
|
630
|
+
for (const name of result) {
|
|
631
|
+
const declaration = declarations.get(name);
|
|
632
|
+
if (declaration && !routerNodes.has(name))
|
|
633
|
+
for (const dependency of dependencies(declaration))
|
|
634
|
+
result.add(dependency);
|
|
635
|
+
for (const value of writes.get(name) ?? [])
|
|
636
|
+
for (const dependency of dependencies(value))
|
|
637
|
+
result.add(dependency);
|
|
638
|
+
}
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
function rejectRouterEscape(nodes) {
|
|
642
|
+
if ([...closure(nodes)].some((name) => routerNodes.has(name)))
|
|
643
|
+
fail("router references inside application handlers require a single Worker boundary");
|
|
644
|
+
}
|
|
645
|
+
function server(nodes) {
|
|
646
|
+
const dependencies = closure(nodes);
|
|
647
|
+
let remote = [...dependencies].some((name) => bindings.includes(name) ||
|
|
648
|
+
environmentImports.has(name) ||
|
|
649
|
+
opaqueImports.has(name) ||
|
|
650
|
+
remoteState.has(name));
|
|
651
|
+
// A server-only handler can still affect other routes through runtime state.
|
|
652
|
+
// Always check whole-Worker boundaries, even after finding a remote binding.
|
|
653
|
+
for (const node of [
|
|
654
|
+
...nodes,
|
|
655
|
+
...[...dependencies]
|
|
656
|
+
.flatMap((name) => [
|
|
657
|
+
declarations.get(name),
|
|
658
|
+
...(writes.get(name) ?? []),
|
|
659
|
+
])
|
|
660
|
+
.filter((n) => !!n),
|
|
661
|
+
])
|
|
662
|
+
walk(node, (child, parent) => {
|
|
663
|
+
if (unresolved.has(child.start))
|
|
664
|
+
remote = true;
|
|
665
|
+
const key = property(child);
|
|
666
|
+
if (key && bindings.includes(key))
|
|
667
|
+
remote = true;
|
|
668
|
+
if (key === "constructor" || key === "__proto__")
|
|
669
|
+
fail("Dynamic runtime access requires a single Worker boundary");
|
|
670
|
+
if (["executionCtx", "event", "cf"].includes(key ?? ""))
|
|
671
|
+
remote = true;
|
|
672
|
+
// Passing an environment to unknown code or computing property names expands
|
|
673
|
+
// the whole operation's server boundary, never retries a partially run route.
|
|
674
|
+
if (key === "env" &&
|
|
675
|
+
(parent?.type !== "MemberExpression" ||
|
|
676
|
+
parent.object !== child ||
|
|
677
|
+
!localBindings.includes(property(parent) ?? "")))
|
|
678
|
+
remote = true;
|
|
679
|
+
if (child.type === "MemberExpression" &&
|
|
680
|
+
child.computed &&
|
|
681
|
+
child.property.type !== "Literal")
|
|
682
|
+
fail("Dynamic property access requires a single Worker boundary");
|
|
683
|
+
if (child.type === "ImportExpression" ||
|
|
684
|
+
(child.type === "Identifier" &&
|
|
685
|
+
["eval", "Function", "Reflect", "Proxy"].includes(child.name)))
|
|
686
|
+
remote = true;
|
|
687
|
+
});
|
|
688
|
+
return remote;
|
|
689
|
+
}
|
|
690
|
+
// Middleware has no independent distribution grant. Only an unconditional
|
|
691
|
+
// await next() can accompany a permitted route without changing authority.
|
|
692
|
+
function passthroughMiddleware(node, seen = new Set()) {
|
|
693
|
+
if (seen.has(node))
|
|
694
|
+
return false;
|
|
695
|
+
seen.add(node);
|
|
696
|
+
if (node.type === "Identifier") {
|
|
697
|
+
const value = variables.get(node.name)?.init ?? declarations.get(node.name);
|
|
698
|
+
return !!value && passthroughMiddleware(value, seen);
|
|
699
|
+
}
|
|
700
|
+
if (![
|
|
701
|
+
"ArrowFunctionExpression",
|
|
702
|
+
"FunctionExpression",
|
|
703
|
+
"FunctionDeclaration",
|
|
704
|
+
].includes(node.type))
|
|
705
|
+
return false;
|
|
706
|
+
const fn = node;
|
|
707
|
+
if (fn.params.length !== 2 ||
|
|
708
|
+
fn.params.some((p) => p.type !== "Identifier") ||
|
|
709
|
+
fn.body.type !== "BlockStatement" ||
|
|
710
|
+
fn.body.body.length !== 1)
|
|
711
|
+
return false;
|
|
712
|
+
const statement = fn.body.body[0];
|
|
713
|
+
return (statement.type === "ExpressionStatement" &&
|
|
714
|
+
statement.expression.type === "AwaitExpression" &&
|
|
715
|
+
statement.expression.argument.type === "CallExpression" &&
|
|
716
|
+
statement.expression.argument.callee.type === "Identifier" &&
|
|
717
|
+
statement.expression.argument.callee.name ===
|
|
718
|
+
fn.params[1].name &&
|
|
719
|
+
statement.expression.argument.arguments.length === 0);
|
|
720
|
+
}
|
|
721
|
+
function staticPath(node, seen = new Set()) {
|
|
722
|
+
if (node.type === "Literal")
|
|
723
|
+
return typeof node.value === "string";
|
|
724
|
+
if (node.type === "ArrayExpression")
|
|
725
|
+
return node.elements.every((item) => !!item && staticPath(item, seen));
|
|
726
|
+
if (node.type === "Identifier" &&
|
|
727
|
+
!seen.has(node.name) &&
|
|
728
|
+
!writes.has(node.name)) {
|
|
729
|
+
seen.add(node.name);
|
|
730
|
+
const value = variables.get(node.name)?.init;
|
|
731
|
+
return !!value && staticPath(value, seen);
|
|
732
|
+
}
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
const granted = new Set();
|
|
736
|
+
// Do not guess effective paths through mounts or aliases. They remain remote.
|
|
737
|
+
const entries = [...registrations.values()].flat();
|
|
738
|
+
for (const route of routePermissions) {
|
|
739
|
+
const matches = entries.filter(({ router, call }) => router === root &&
|
|
740
|
+
!routerInitializers.get(root)?.includes(".basePath(") &&
|
|
741
|
+
(route.method === "*"
|
|
742
|
+
? /^(get|head|post|put|patch|delete|options|all)$/.test(property(call.callee) ?? "")
|
|
743
|
+
: property(call.callee) === route.method.toLowerCase()) &&
|
|
744
|
+
permitsPath(route, literal(call.arguments[0])));
|
|
745
|
+
if (!matches.length)
|
|
746
|
+
throw new Error(`execution: cannot resolve ${route.method} ${route.path} to a direct Hono registration`);
|
|
747
|
+
for (const match of matches)
|
|
748
|
+
granted.add(match.call);
|
|
749
|
+
}
|
|
750
|
+
function distributionAllowed(call, handlers) {
|
|
751
|
+
if (property(call.callee) !== "use")
|
|
752
|
+
return granted.has(call);
|
|
753
|
+
return handlers.every((argument) => staticPath(argument) || passthroughMiddleware(argument));
|
|
754
|
+
}
|
|
755
|
+
// State shared with a remote operation must not be duplicated in a local
|
|
756
|
+
// module instance. Expand the boundary before generating either router.
|
|
757
|
+
let changed = true;
|
|
758
|
+
while (changed) {
|
|
759
|
+
changed = false;
|
|
760
|
+
for (const entries of registrations.values())
|
|
761
|
+
for (const { call } of entries) {
|
|
762
|
+
if (!server(call.arguments) &&
|
|
763
|
+
distributionAllowed(call, call.arguments))
|
|
764
|
+
continue;
|
|
765
|
+
for (const name of closure(call.arguments))
|
|
766
|
+
if (mutable.has(name) &&
|
|
767
|
+
!routerNodes.has(name) &&
|
|
768
|
+
!remoteState.has(name)) {
|
|
769
|
+
if (declarations.get(name)?.type === "FunctionDeclaration" &&
|
|
770
|
+
writes.has(name))
|
|
771
|
+
fail(`function object ${name} may share state across the Worker boundary`);
|
|
772
|
+
remoteState.add(name);
|
|
773
|
+
changed = true;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const candidates = [...registrations.values()]
|
|
778
|
+
.flat()
|
|
779
|
+
.filter(({ call }) => routeMethods.has(property(call.callee) ?? ""))
|
|
780
|
+
.sort((a, b) => a.call.end -
|
|
781
|
+
b.call.end)
|
|
782
|
+
.map((entry) => {
|
|
783
|
+
const method = property(entry.call.callee);
|
|
784
|
+
const pathCount = method === "on"
|
|
785
|
+
? 2
|
|
786
|
+
: method === "use" &&
|
|
787
|
+
entry.call.arguments[0] &&
|
|
788
|
+
!staticPath(entry.call.arguments[0])
|
|
789
|
+
? 0
|
|
790
|
+
: 1;
|
|
791
|
+
const paths = entry.call.arguments.slice(0, pathCount);
|
|
792
|
+
const handlers = entry.call.arguments.slice(pathCount);
|
|
793
|
+
return {
|
|
794
|
+
...entry,
|
|
795
|
+
method,
|
|
796
|
+
paths: method === "on" ? paths.slice(1) : paths,
|
|
797
|
+
handlers,
|
|
798
|
+
remote: server(handlers) || !distributionAllowed(entry.call, handlers),
|
|
799
|
+
};
|
|
800
|
+
});
|
|
801
|
+
function literal(node) {
|
|
802
|
+
if (node?.type === "Identifier")
|
|
803
|
+
return literal(variables.get(node.name)?.init ?? undefined);
|
|
804
|
+
return node?.type === "Literal" && typeof node.value === "string"
|
|
805
|
+
? node.value
|
|
806
|
+
: undefined;
|
|
807
|
+
}
|
|
808
|
+
function disjoint(a, b) {
|
|
809
|
+
if (a === undefined || b === undefined)
|
|
810
|
+
return false;
|
|
811
|
+
const plain = (path) => path.startsWith("/") && !/[:*{}?]/.test(path) && !path.includes("//");
|
|
812
|
+
if (plain(a) && plain(b))
|
|
813
|
+
return a.replace(/\/$/, "") !== b.replace(/\/$/, "");
|
|
814
|
+
const prefix = (path) => (path.match(/^\/[^:*{}?]*/)?.[0] ?? "")
|
|
815
|
+
.split("//")[0]
|
|
816
|
+
.replace(/\/$/, "");
|
|
817
|
+
const ap = prefix(a), bp = prefix(b);
|
|
818
|
+
return ((plain(a) && !a.startsWith(bp)) ||
|
|
819
|
+
(plain(b) && !b.startsWith(ap)) ||
|
|
820
|
+
(!ap.startsWith(bp) && !bp.startsWith(ap)));
|
|
821
|
+
}
|
|
822
|
+
function rootOutsideMount(a, b) {
|
|
823
|
+
if (a.router !== root || literal(a.paths[0]) !== "/")
|
|
824
|
+
return false;
|
|
825
|
+
const mounts = [...registrations.values()]
|
|
826
|
+
.flat()
|
|
827
|
+
.filter(({ call }) => property(call.callee) === "route");
|
|
828
|
+
return (mounts.length > 0 &&
|
|
829
|
+
mounts.every(({ router, call }) => router === root &&
|
|
830
|
+
call.arguments[1]?.type === "Identifier" &&
|
|
831
|
+
rootRouter(call.arguments[1].name) === b.router &&
|
|
832
|
+
/^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(literal(call.arguments[0]) ?? "")));
|
|
833
|
+
}
|
|
834
|
+
// Remove protected handlers from the distribution graph, not merely from
|
|
835
|
+
// request-time execution. Prefix checks only prove disjointness; uncertain
|
|
836
|
+
// overlap widens the boundary instead of recreating Hono's router.
|
|
837
|
+
const protectedCalls = new Set();
|
|
838
|
+
let widened = true;
|
|
839
|
+
while (widened) {
|
|
840
|
+
widened = false;
|
|
841
|
+
for (let i = 0; i < candidates.length; i++)
|
|
842
|
+
for (let j = i + 1; j < candidates.length; j++) {
|
|
843
|
+
const a = candidates[i], b = candidates[j];
|
|
844
|
+
if (a.remote && b.remote)
|
|
845
|
+
continue;
|
|
846
|
+
// A proven passthrough registered before the server operation writes
|
|
847
|
+
// its headers even to an unauthenticated response. A later middleware
|
|
848
|
+
// can be protected by the earlier operation and must not be distributed.
|
|
849
|
+
if ((!a.remote && a.method === "use") ||
|
|
850
|
+
(!a.remote && !b.remote && b.method === "use"))
|
|
851
|
+
continue;
|
|
852
|
+
if (!["all", "on", "use"].includes(a.method) &&
|
|
853
|
+
!["all", "on", "use"].includes(b.method) &&
|
|
854
|
+
a.method !== b.method &&
|
|
855
|
+
![a.method, b.method].every((method) => ["get", "head"].includes(method)))
|
|
856
|
+
continue;
|
|
857
|
+
if (a.router !== b.router) {
|
|
858
|
+
if (rootOutsideMount(a, b) || rootOutsideMount(b, a))
|
|
859
|
+
continue;
|
|
860
|
+
fail("Mounted route overlap requires a single Worker distribution boundary");
|
|
861
|
+
}
|
|
862
|
+
if (disjoint(literal(a.paths[0]), literal(b.paths[0])))
|
|
863
|
+
continue;
|
|
864
|
+
if (!a.remote && !b.remote)
|
|
865
|
+
fail("Overlapping local responses require a single Worker distribution boundary");
|
|
866
|
+
if (!a.remote)
|
|
867
|
+
protectedCalls.add(a.call);
|
|
868
|
+
if (!b.remote)
|
|
869
|
+
protectedCalls.add(b.call);
|
|
870
|
+
a.remote = b.remote = true;
|
|
871
|
+
widened = true;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
const distributionRemote = new Map(candidates.map(({ call, remote }) => [call, remote]));
|
|
875
|
+
const localRoots = [];
|
|
876
|
+
const selectorRoots = [];
|
|
877
|
+
const localRegistrations = new Map();
|
|
878
|
+
const selectorRegistrations = new Map();
|
|
879
|
+
const routes = [];
|
|
880
|
+
let remoteErrors = false;
|
|
881
|
+
const emit = (map, statement, code) => map.set(statement, [...(map.get(statement) ?? []), code]);
|
|
882
|
+
for (const [statement, items] of registrations)
|
|
883
|
+
for (const { router, call } of items) {
|
|
884
|
+
const method = property(call.callee);
|
|
885
|
+
if (!method)
|
|
886
|
+
fail("computed registration methods are not supported");
|
|
887
|
+
if (method === "route" || method === "basePath") {
|
|
888
|
+
// basePath returns a new router and needs alias ownership, not an ignored call.
|
|
889
|
+
if (method === "basePath")
|
|
890
|
+
fail("basePath requires router alias analysis; mounted route() routers are supported");
|
|
891
|
+
const [path, child] = call.arguments;
|
|
892
|
+
if (call.arguments.length !== 2 ||
|
|
893
|
+
!path ||
|
|
894
|
+
!staticPath(path) ||
|
|
895
|
+
child?.type !== "Identifier")
|
|
896
|
+
fail("route() requires a static mount path and router");
|
|
897
|
+
const mounted = rootRouter(child.name);
|
|
898
|
+
localRoots.push(path);
|
|
899
|
+
selectorRoots.push(path);
|
|
900
|
+
emit(localRegistrations, statement, `${router}.route(${text(path)}, ${mounted});`);
|
|
901
|
+
emit(selectorRegistrations, statement, `${router}.route(${text(path)}, ${mounted});`);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (method === "onError" || method === "notFound") {
|
|
905
|
+
rejectRouterEscape(call.arguments);
|
|
906
|
+
remoteErrors = true;
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
if (!routeMethods.has(method))
|
|
910
|
+
fail(`router operation ${method} needs execution analysis`);
|
|
911
|
+
const pathCount = method === "on"
|
|
912
|
+
? 2
|
|
913
|
+
: method === "use" &&
|
|
914
|
+
call.arguments[0] &&
|
|
915
|
+
!staticPath(call.arguments[0])
|
|
916
|
+
? 0
|
|
917
|
+
: 1;
|
|
918
|
+
const paths = call.arguments.slice(0, pathCount);
|
|
919
|
+
const handlers = call.arguments.slice(pathCount);
|
|
920
|
+
if (!handlers.length || paths.some((path) => !staticPath(path)))
|
|
921
|
+
fail(`dynamic path/method for ${router}.${method} cannot be matched before execution`);
|
|
922
|
+
rejectRouterEscape(handlers);
|
|
923
|
+
const remote = distributionRemote.get(call);
|
|
924
|
+
localRoots.push(...paths);
|
|
925
|
+
if (!remote)
|
|
926
|
+
localRoots.push(...handlers);
|
|
927
|
+
selectorRoots.push(...paths);
|
|
928
|
+
routes.push({
|
|
929
|
+
router,
|
|
930
|
+
method,
|
|
931
|
+
path: paths.map(text).join(",") || "*",
|
|
932
|
+
remote,
|
|
933
|
+
reason: protectedCalls.has(call)
|
|
934
|
+
? "Protected by an overlapping server handler or middleware; implementation is not distributed"
|
|
935
|
+
: remote
|
|
936
|
+
? !granted.has(call)
|
|
937
|
+
? "Route distribution was not permitted by execution"
|
|
938
|
+
: "Server dependency or dependency without a local execution contract or public rendering contract"
|
|
939
|
+
: granted.has(call)
|
|
940
|
+
? "Route and retained dependencies explicitly permitted for distribution; no overlapping server boundary"
|
|
941
|
+
: "Passthrough middleware with no overlapping server boundary",
|
|
942
|
+
});
|
|
943
|
+
const prefix = paths.length ? paths.map(text).join(",") + "," : "";
|
|
944
|
+
// Every candidate is visited, so a fallthrough to a server handler is selected
|
|
945
|
+
// before local middleware, even when an earlier candidate could have responded.
|
|
946
|
+
const marker = `async (c,next) => { ${remote ? 'c.set("__cwRemote",true);' : ""} await next(); ${granted.has(call) ? 'c.header("x-cw-local-route","1");' : ""} if(c.get("__cwRemote"))c.header("x-cw-remote","1"); }`;
|
|
947
|
+
emit(selectorRegistrations, statement, `${router}.${method}(${prefix}${marker});`);
|
|
948
|
+
emit(localRegistrations, statement, `${router}.${method}(${prefix}${remote ? '() => { throw new Error("Server route reached local dispatch"); }' : handlers.map(text).join(",")});`);
|
|
949
|
+
}
|
|
950
|
+
const needed = closure(localRoots);
|
|
951
|
+
const selectorNeeded = closure(selectorRoots);
|
|
952
|
+
// All constructors are needed in both graphs. The selector has no user handlers.
|
|
953
|
+
for (const name of constructors) {
|
|
954
|
+
needed.add(name);
|
|
955
|
+
selectorNeeded.add(name);
|
|
956
|
+
}
|
|
957
|
+
function generate(roots, calls) {
|
|
958
|
+
const included = new Set([...roots].map((name) => declarations.get(name)).filter(Boolean));
|
|
959
|
+
const lines = [];
|
|
960
|
+
for (const statement of program.body) {
|
|
961
|
+
const router = [...routerNodes].find(([, node]) => node === statement)?.[0];
|
|
962
|
+
if (router)
|
|
963
|
+
lines.push(routerInitializers.get(router));
|
|
964
|
+
else if (included.has(statement) &&
|
|
965
|
+
statement.type !== "ExportNamedDeclaration")
|
|
966
|
+
lines.push(text(statement));
|
|
967
|
+
lines.push(...(calls.get(statement) ?? []));
|
|
968
|
+
}
|
|
969
|
+
return lines.join("\n");
|
|
970
|
+
}
|
|
971
|
+
if (remoteErrors)
|
|
972
|
+
fail("Server-backed error/not-found handling can apply to every request");
|
|
973
|
+
return {
|
|
974
|
+
mode: "routes",
|
|
975
|
+
local: generate(needed, localRegistrations) + `\nexport default ${root};\n`,
|
|
976
|
+
selector: generate(selectorNeeded, selectorRegistrations) +
|
|
977
|
+
`\nexport async function needsRemote(request) { ${remoteErrors ? "return true;" : `const response = await ${root}.fetch(new Request(request.url, {method: request.method})); if(response.status >= 500) throw new Error("Remote route selection failed"); return response.headers.get("x-cw-local-route") !== "1" || response.headers.get("x-cw-remote") === "1";`} }\n`,
|
|
978
|
+
inputs,
|
|
979
|
+
routes,
|
|
980
|
+
};
|
|
981
|
+
}
|