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,152 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import WebKit
|
|
3
|
+
|
|
4
|
+
@objc(WorkersCapacitorPlugin)
|
|
5
|
+
public final class WorkersCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
/// Optional embedding configuration; ordinary Capacitor applications keep their existing configuration.
|
|
7
|
+
public var documentDescriptorFactory: (() -> InstanceDescriptor)?
|
|
8
|
+
public let identifier = "WorkersCapacitorPlugin"
|
|
9
|
+
public let jsName = "WorkersCapacitor"
|
|
10
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
11
|
+
CAPPluginMethod(name: "cookiesGet", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "cookiesSet", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "start", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "stop", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "socketWatch", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "socketOpen", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "socketWrite", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "socketEnd", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "socketRead", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "socketClose", returnType: CAPPluginReturnPromise)
|
|
21
|
+
]
|
|
22
|
+
private var network = NetworkBridge()
|
|
23
|
+
private var networkLifecycle: NetworkLifecycle?
|
|
24
|
+
public override func load() {
|
|
25
|
+
guard let content = webView?.configuration.userContentController else { return }
|
|
26
|
+
let lifecycle = NetworkLifecycle { [weak self] in
|
|
27
|
+
guard let bridge = self?.bridge as? CapacitorBridge else { return }
|
|
28
|
+
bridge.dispatchQueue.async { [weak self] in
|
|
29
|
+
guard let self else { return }
|
|
30
|
+
let previous = self.network
|
|
31
|
+
previous.invalidate()
|
|
32
|
+
self.network = NetworkBridge()
|
|
33
|
+
Task { await previous.shutdown() }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
networkLifecycle = lifecycle
|
|
37
|
+
content.add(lifecycle, name: "WorkersCapacitorNetworkReset")
|
|
38
|
+
content.addUserScript(WKUserScript(
|
|
39
|
+
source: "window.webkit.messageHandlers.WorkersCapacitorNetworkReset.postMessage(null)",
|
|
40
|
+
injectionTime: .atDocumentStart, forMainFrameOnly: true
|
|
41
|
+
))
|
|
42
|
+
}
|
|
43
|
+
private var documentController: DocumentBridgeController?
|
|
44
|
+
@objc func start(_ call: CAPPluginCall) {
|
|
45
|
+
DispatchQueue.main.async { [weak self] in
|
|
46
|
+
guard let self = self, let bridge = self.bridge, let parent = bridge.viewController, let host = bridge.webView else { call.reject("Missing Capacitor bridge"); return }
|
|
47
|
+
guard self.documentController == nil else { call.reject("Document rendering already started"); return }
|
|
48
|
+
guard let entry = call.getString("entry"), entry.hasPrefix("/"), !entry.hasPrefix("//"), !entry.contains("\\"),
|
|
49
|
+
let baseURL = call.getString("baseURL"), let assets = call.getArray("assets", String.self), let script = call.getString("pageScript"), !script.isEmpty else { call.reject("Invalid document configuration"); return }
|
|
50
|
+
let child = DocumentBridgeController()
|
|
51
|
+
child.embeddedDescriptorFactory = self.documentDescriptorFactory
|
|
52
|
+
child.runtimeHost = host
|
|
53
|
+
child.localURL = bridge.config.localURL
|
|
54
|
+
child.settings = ["entry": entry, "baseURL": baseURL, "assets": assets, "pageScript": script]
|
|
55
|
+
self.documentController = child
|
|
56
|
+
parent.addChild(child)
|
|
57
|
+
child.view.frame = parent.view.bounds
|
|
58
|
+
child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
59
|
+
parent.view.addSubview(child.view)
|
|
60
|
+
child.didMove(toParent: parent)
|
|
61
|
+
call.resolve()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
@objc func stop(_ call: CAPPluginCall) {
|
|
65
|
+
let owner = network
|
|
66
|
+
DispatchQueue.main.async { [weak self] in
|
|
67
|
+
guard let self else { call.resolve(); return }
|
|
68
|
+
self.close()
|
|
69
|
+
Task { await owner.closeAll(); call.resolve() }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
@objc func socketWatch(_ call: CAPPluginCall) { network.socketWatch(call) }
|
|
73
|
+
@objc func socketOpen(_ call: CAPPluginCall) { network.socketOpen(call) }
|
|
74
|
+
@objc func socketWrite(_ call: CAPPluginCall) { network.socketWrite(call) }
|
|
75
|
+
@objc func socketEnd(_ call: CAPPluginCall) { network.socketEnd(call) }
|
|
76
|
+
@objc func socketRead(_ call: CAPPluginCall) { network.socketRead(call) }
|
|
77
|
+
@objc func socketClose(_ call: CAPPluginCall) { network.socketClose(call) }
|
|
78
|
+
// Use WebKit's persistent remote-origin jar, never the document's cookies.
|
|
79
|
+
private func cookieURL(_ call: CAPPluginCall) -> URL? {
|
|
80
|
+
guard let value = call.getString("url"), let url = URL(string: value),
|
|
81
|
+
url.scheme == "https", url.host != nil, url.user == nil, url.password == nil else {
|
|
82
|
+
call.reject("Cookies require an HTTPS URL without credentials"); return nil
|
|
83
|
+
}
|
|
84
|
+
return url
|
|
85
|
+
}
|
|
86
|
+
@objc func cookiesGet(_ call: CAPPluginCall) {
|
|
87
|
+
guard let url = cookieURL(call), let host = url.host?.lowercased() else { return }
|
|
88
|
+
DispatchQueue.main.async {
|
|
89
|
+
WKWebsiteDataStore.default().httpCookieStore.getAllCookies { cookies in
|
|
90
|
+
let path = url.path.isEmpty ? "/" : url.path
|
|
91
|
+
let matching = cookies.filter { cookie in
|
|
92
|
+
let domain = cookie.domain.lowercased()
|
|
93
|
+
let domainMatch = domain.hasPrefix(".")
|
|
94
|
+
? (host == String(domain.dropFirst()) || host.hasSuffix(domain)) : host == domain
|
|
95
|
+
let pathMatch = path == cookie.path || (path.hasPrefix(cookie.path) && (cookie.path.hasSuffix("/") || path.dropFirst(cookie.path.count).hasPrefix("/")))
|
|
96
|
+
return domainMatch && pathMatch && (cookie.expiresDate == nil || cookie.expiresDate! > Date())
|
|
97
|
+
}.sorted { $0.path.count > $1.path.count }
|
|
98
|
+
call.resolve(["cookie": matching.map { "\($0.name)=\($0.value)" }.joined(separator: "; ")])
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
@objc func cookiesSet(_ call: CAPPluginCall) {
|
|
103
|
+
guard let url = cookieURL(call) else { return }
|
|
104
|
+
guard let values = call.getArray("cookies", String.self) else { call.reject("Invalid remote cookies"); return }
|
|
105
|
+
DispatchQueue.main.async {
|
|
106
|
+
let store = WKWebsiteDataStore.default().httpCookieStore
|
|
107
|
+
// Process sequentially: duplicate names in a response obey header order.
|
|
108
|
+
func save(_ index: Int) {
|
|
109
|
+
if index == values.count { call.resolve(); return }
|
|
110
|
+
let cookies = HTTPCookie.cookies(withResponseHeaderFields: ["Set-Cookie": values[index]], for: url)
|
|
111
|
+
func insert(_ offset: Int) {
|
|
112
|
+
if offset == cookies.count { save(index + 1); return }
|
|
113
|
+
let cookie = cookies[offset]
|
|
114
|
+
guard cookie.domain.lowercased() == url.host?.lowercased() else { insert(offset + 1); return }
|
|
115
|
+
if let expiry = cookie.expiresDate, expiry <= Date() {
|
|
116
|
+
store.delete(cookie) { insert(offset + 1) }
|
|
117
|
+
} else { store.setCookie(cookie) { insert(offset + 1) } }
|
|
118
|
+
}
|
|
119
|
+
insert(0)
|
|
120
|
+
}
|
|
121
|
+
save(0)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
private func close() {
|
|
125
|
+
guard let child = documentController else { return }
|
|
126
|
+
child.close(); child.willMove(toParent: nil); child.view.removeFromSuperview(); child.removeFromParent()
|
|
127
|
+
documentController = nil
|
|
128
|
+
}
|
|
129
|
+
/// Releases the native resources after the owning JavaScript runtime has disposed.
|
|
130
|
+
@MainActor public func shutdown() async {
|
|
131
|
+
close()
|
|
132
|
+
await network.shutdown()
|
|
133
|
+
webView?.configuration.userContentController.removeScriptMessageHandler(forName: "WorkersCapacitorNetworkReset")
|
|
134
|
+
networkLifecycle = nil
|
|
135
|
+
}
|
|
136
|
+
deinit {
|
|
137
|
+
documentController?.close()
|
|
138
|
+
let network = network
|
|
139
|
+
Task { await network.shutdown() }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The handler does not retain the plugin. A new main-frame document receives a
|
|
144
|
+
// fresh network owner before its application scripts can open connections.
|
|
145
|
+
private final class NetworkLifecycle: NSObject, WKScriptMessageHandler {
|
|
146
|
+
private let reset: () -> Void
|
|
147
|
+
init(reset: @escaping () -> Void) { self.reset = reset }
|
|
148
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
149
|
+
guard message.frameInfo.isMainFrame else { return }
|
|
150
|
+
reset()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import SwiftUI
|
|
3
|
+
import WebKit
|
|
4
|
+
import Capacitor
|
|
5
|
+
import WorkersCapacitor
|
|
6
|
+
|
|
7
|
+
/// Embeds a Workers application in an ordinary UIKit application.
|
|
8
|
+
/// `assets` is the directory containing the generated application's index.html.
|
|
9
|
+
@MainActor public final class WorkersViewController: UIViewController {
|
|
10
|
+
private var runtime: EmbeddedRuntimeController?
|
|
11
|
+
private var closing: Task<Void, Error>?
|
|
12
|
+
private enum StartupState { case idle, waiting, ready, failed, closed }
|
|
13
|
+
private var startupState = StartupState.idle
|
|
14
|
+
private var startupDeadline: Task<Void, Never>?
|
|
15
|
+
public private(set) var startupError: String?
|
|
16
|
+
/// Called after failed startup has released the embedded runtime. A displayed
|
|
17
|
+
/// controller must receive the JavaScript ready handshake within 30 seconds.
|
|
18
|
+
public var onStartupError: ((String) -> Void)?
|
|
19
|
+
|
|
20
|
+
public init(assets: URL) throws {
|
|
21
|
+
guard assets.isFileURL,
|
|
22
|
+
FileManager.default.fileExists(atPath: assets.appendingPathComponent("index.html").path) else {
|
|
23
|
+
throw CocoaError(.fileReadNoSuchFile)
|
|
24
|
+
}
|
|
25
|
+
runtime = EmbeddedRuntimeController(assets: assets)
|
|
26
|
+
super.init(nibName: nil, bundle: nil)
|
|
27
|
+
runtime?.onStartupReady = { [weak self] in
|
|
28
|
+
guard let self, self.startupState == .idle || self.startupState == .waiting else { return }
|
|
29
|
+
self.startupState = .ready
|
|
30
|
+
self.startupDeadline?.cancel()
|
|
31
|
+
self.startupDeadline = nil
|
|
32
|
+
}
|
|
33
|
+
runtime?.onStartupFailure = { [weak self] message in
|
|
34
|
+
self?.failStartup(message)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@available(*, unavailable)
|
|
39
|
+
required init?(coder: NSCoder) { fatalError("Use init(assets:)") }
|
|
40
|
+
|
|
41
|
+
public override func viewDidLoad() {
|
|
42
|
+
super.viewDidLoad()
|
|
43
|
+
guard let runtime else { return }
|
|
44
|
+
addChild(runtime)
|
|
45
|
+
runtime.view.frame = view.bounds
|
|
46
|
+
runtime.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
47
|
+
view.addSubview(runtime.view)
|
|
48
|
+
runtime.didMove(toParent: self)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public override func viewWillAppear(_ animated: Bool) {
|
|
52
|
+
super.viewWillAppear(animated)
|
|
53
|
+
guard startupState == .idle else { return }
|
|
54
|
+
startupState = .waiting
|
|
55
|
+
startupDeadline = Task { @MainActor [weak self] in
|
|
56
|
+
do { try await Task.sleep(nanoseconds: 30_000_000_000) }
|
|
57
|
+
catch { return }
|
|
58
|
+
self?.failStartup("Workers application did not become ready within 30 seconds")
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private func failStartup(_ message: String) {
|
|
63
|
+
guard startupState == .idle || startupState == .waiting else { return }
|
|
64
|
+
startupState = .failed
|
|
65
|
+
startupDeadline?.cancel()
|
|
66
|
+
startupDeadline = nil
|
|
67
|
+
startupError = message
|
|
68
|
+
Task { @MainActor in
|
|
69
|
+
try? await self.closeRuntime()
|
|
70
|
+
guard self.startupState == .failed else { return }
|
|
71
|
+
self.onStartupError?(message)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Await before removing the controller. Disposes JavaScript in its owning
|
|
76
|
+
/// runtime realm, then releases document views, sockets, and native bridges.
|
|
77
|
+
/// A closed controller is terminal; create a new controller to open again.
|
|
78
|
+
public func close() async throws {
|
|
79
|
+
startupState = .closed
|
|
80
|
+
startupDeadline?.cancel()
|
|
81
|
+
startupDeadline = nil
|
|
82
|
+
try await closeRuntime()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private func closeRuntime() async throws {
|
|
86
|
+
if let closing { return try await closing.value }
|
|
87
|
+
guard let runtime else { return }
|
|
88
|
+
let task = Task { @MainActor in
|
|
89
|
+
var failure: Error?
|
|
90
|
+
if let webView = runtime.webView {
|
|
91
|
+
do {
|
|
92
|
+
try await Self.disposeJavaScript(in: webView)
|
|
93
|
+
} catch { failure = error }
|
|
94
|
+
}
|
|
95
|
+
await runtime.workers.shutdown()
|
|
96
|
+
runtime.webView?.configuration.userContentController.removeScriptMessageHandler(forName: "WorkersNativeStartupFailure")
|
|
97
|
+
runtime.webView?.stopLoading()
|
|
98
|
+
runtime.willMove(toParent: nil)
|
|
99
|
+
runtime.viewIfLoaded?.removeFromSuperview()
|
|
100
|
+
runtime.removeFromParent()
|
|
101
|
+
self.runtime = nil
|
|
102
|
+
if let failure { throw failure }
|
|
103
|
+
}
|
|
104
|
+
closing = task
|
|
105
|
+
try await task.value
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private static func disposeJavaScript(in webView: WKWebView) async throws {
|
|
109
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
110
|
+
let waiter = DisposalWaiter(continuation)
|
|
111
|
+
webView.callAsyncJavaScript(
|
|
112
|
+
"if (typeof globalThis.__workersNativeDispose === 'function') { await globalThis.__workersNativeDispose(); }",
|
|
113
|
+
arguments: [:], in: nil, in: .page
|
|
114
|
+
) { result in
|
|
115
|
+
switch result {
|
|
116
|
+
case .success: waiter.finish(nil)
|
|
117
|
+
case .failure(let error): waiter.finish(error)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
|
|
121
|
+
waiter.finish(URLError(.timedOut))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@MainActor private final class DisposalWaiter {
|
|
128
|
+
private var continuation: CheckedContinuation<Void, Error>?
|
|
129
|
+
init(_ continuation: CheckedContinuation<Void, Error>) { self.continuation = continuation }
|
|
130
|
+
func finish(_ error: Error?) {
|
|
131
|
+
guard let continuation else { return }
|
|
132
|
+
self.continuation = nil
|
|
133
|
+
if let error { continuation.resume(throwing: error) }
|
|
134
|
+
else { continuation.resume() }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private final class EmbeddedRuntimeController: CAPBridgeViewController {
|
|
139
|
+
let workers = WorkersCapacitorPlugin()
|
|
140
|
+
private let assets: URL
|
|
141
|
+
var onStartupFailure: ((String) -> Void)?
|
|
142
|
+
var onStartupReady: (() -> Void)?
|
|
143
|
+
private var failureHandler: StartupFailureHandler?
|
|
144
|
+
init(assets: URL) { self.assets = assets; super.init(nibName: nil, bundle: nil) }
|
|
145
|
+
@available(*, unavailable)
|
|
146
|
+
required init?(coder: NSCoder) { fatalError("Use init(assets:)") }
|
|
147
|
+
override func instanceDescriptor() -> InstanceDescriptor {
|
|
148
|
+
let descriptor = InstanceDescriptor(at: assets, configuration: nil, cordovaConfiguration: nil)
|
|
149
|
+
descriptor.handleApplicationNotifications = false
|
|
150
|
+
descriptor.contentInsetAdjustmentBehavior = .automatic
|
|
151
|
+
return descriptor
|
|
152
|
+
}
|
|
153
|
+
override func capacitorDidLoad() {
|
|
154
|
+
let assets = assets
|
|
155
|
+
workers.documentDescriptorFactory = {
|
|
156
|
+
let descriptor = InstanceDescriptor(at: assets, configuration: nil, cordovaConfiguration: nil)
|
|
157
|
+
descriptor.handleApplicationNotifications = false
|
|
158
|
+
descriptor.contentInsetAdjustmentBehavior = .automatic
|
|
159
|
+
return descriptor
|
|
160
|
+
}
|
|
161
|
+
bridge?.registerPluginInstance(workers)
|
|
162
|
+
guard let content = webView?.configuration.userContentController else { return }
|
|
163
|
+
let handler = StartupFailureHandler(ready: { [weak self] in self?.onStartupReady?() }, failed: { [weak self] message in self?.onStartupFailure?(message) })
|
|
164
|
+
failureHandler = handler
|
|
165
|
+
content.add(handler, name: "WorkersNativeStartupFailure")
|
|
166
|
+
content.addUserScript(WKUserScript(
|
|
167
|
+
source: "globalThis.WorkersNativeHost = { ready: () => window.webkit.messageHandlers.WorkersNativeStartupFailure.postMessage({type: 'ready'}), failed: message => window.webkit.messageHandlers.WorkersNativeStartupFailure.postMessage({type: 'failed', message: String(message)}) };",
|
|
168
|
+
injectionTime: .atDocumentStart, forMainFrameOnly: true))
|
|
169
|
+
}
|
|
170
|
+
override func setStatusBarDefaults() {}
|
|
171
|
+
override func setScreenOrientationDefaults() {}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private final class StartupFailureHandler: NSObject, WKScriptMessageHandler {
|
|
175
|
+
private let ready: () -> Void
|
|
176
|
+
private let failed: (String) -> Void
|
|
177
|
+
init(ready: @escaping () -> Void, failed: @escaping (String) -> Void) { self.ready = ready; self.failed = failed }
|
|
178
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
179
|
+
guard message.frameInfo.isMainFrame, let value = message.body as? [String: Any] else { return }
|
|
180
|
+
if value["type"] as? String == "ready" { ready() }
|
|
181
|
+
if value["type"] as? String == "failed", let message = value["message"] as? String { failed(message) }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// SwiftUI host. Construct the controller once and retain it for the view's lifetime.
|
|
186
|
+
@MainActor public struct WorkersView: UIViewControllerRepresentable {
|
|
187
|
+
public let controller: WorkersViewController
|
|
188
|
+
public init(controller: WorkersViewController) { self.controller = controller }
|
|
189
|
+
public func makeUIViewController(context: Context) -> WorkersViewController { controller }
|
|
190
|
+
public func updateUIViewController(_ uiViewController: WorkersViewController, context: Context) {}
|
|
191
|
+
public static func dismantleUIViewController(_ uiViewController: WorkersViewController, coordinator: ()) {
|
|
192
|
+
Task { try? await uiViewController.close() }
|
|
193
|
+
}
|
|
194
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,156 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cf-workers-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2-beta.local.sha2f5e4e6956f4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Bring Cloudflare Workers apps to iOS and Android.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/rdlabo-dev/cf-workers-native.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/rdlabo-dev/cf-workers-native#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/rdlabo-dev/cf-workers-native/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cloudflare",
|
|
16
|
+
"workers",
|
|
17
|
+
"capacitor",
|
|
18
|
+
"ios",
|
|
19
|
+
"android"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"tag": "beta",
|
|
27
|
+
"registry": "https://registry.npmjs.org"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"Package.swift",
|
|
33
|
+
"native/ios/*.swift",
|
|
34
|
+
"native/ios-host/*.swift",
|
|
35
|
+
"native/android/build.gradle",
|
|
36
|
+
"native/android/consumer-rules.pro",
|
|
37
|
+
"native/android/src/main/"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
"./ios": {
|
|
41
|
+
"types": "./dist/ios.d.ts",
|
|
42
|
+
"import": "./dist/ios.js"
|
|
43
|
+
},
|
|
44
|
+
"./android": {
|
|
45
|
+
"types": "./dist/android.d.ts",
|
|
46
|
+
"import": "./dist/android.js"
|
|
47
|
+
},
|
|
48
|
+
"./capacitor": {
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
|
+
"import": "./dist/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./tooling/vite": {
|
|
53
|
+
"types": "./dist/tooling/vite.d.ts",
|
|
54
|
+
"import": "./dist/tooling/vite.js"
|
|
55
|
+
},
|
|
56
|
+
"./shared/contracts": {
|
|
57
|
+
"types": "./dist/shared/contracts/index.d.ts",
|
|
58
|
+
"import": "./dist/shared/contracts/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./shared/contracts/testing": {
|
|
61
|
+
"types": "./dist/shared/contracts/testing.d.ts",
|
|
62
|
+
"import": "./dist/shared/contracts/testing.js"
|
|
63
|
+
},
|
|
64
|
+
"./cloudflare/workers": {
|
|
65
|
+
"types": "./dist/cloudflare/workers/feature.d.ts",
|
|
66
|
+
"import": "./dist/cloudflare/workers/feature.js"
|
|
67
|
+
},
|
|
68
|
+
"./cloudflare/bindings/kv": {
|
|
69
|
+
"types": "./dist/cloudflare/bindings/kv/index.d.ts",
|
|
70
|
+
"import": "./dist/cloudflare/bindings/kv/index.js"
|
|
71
|
+
},
|
|
72
|
+
"./cloudflare/workers/testing": {
|
|
73
|
+
"types": "./dist/cloudflare/workers/contract.d.ts",
|
|
74
|
+
"import": "./dist/cloudflare/workers/contract.js"
|
|
75
|
+
},
|
|
76
|
+
"./cloudflare/bindings/kv/testing": {
|
|
77
|
+
"types": "./dist/cloudflare/bindings/kv/contract.d.ts",
|
|
78
|
+
"import": "./dist/cloudflare/bindings/kv/contract.js"
|
|
79
|
+
},
|
|
80
|
+
"./tooling/esbuild": {
|
|
81
|
+
"types": "./dist/tooling/esbuild.d.ts",
|
|
82
|
+
"import": "./dist/tooling/esbuild.js"
|
|
83
|
+
},
|
|
84
|
+
"./browser/isolated": {
|
|
85
|
+
"types": "./dist/browser/isolated/transport.d.ts",
|
|
86
|
+
"import": "./dist/browser/isolated/transport.js"
|
|
87
|
+
},
|
|
88
|
+
"./cloudflare/apis/types": {
|
|
89
|
+
"types": "./dist/cloudflare/apis/types.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./environment": {
|
|
92
|
+
"types": "./dist/environment.d.ts",
|
|
93
|
+
"import": "./dist/environment.js"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"scripts": {
|
|
97
|
+
"build": "tsc -p tsconfig.build.json && node scripts/build-document-assets.mjs && node scripts/build-codecs.mjs && node scripts/build-notices.mjs",
|
|
98
|
+
"test": "vitest run",
|
|
99
|
+
"test:package": "node scripts/test-package.mjs",
|
|
100
|
+
"typecheck": "tsc --noEmit",
|
|
101
|
+
"format": "prettier --write .",
|
|
102
|
+
"format:check": "prettier --check .",
|
|
103
|
+
"prepack": "npm run build",
|
|
104
|
+
"release:prepare": "node scripts/prepare-local-release.mjs"
|
|
105
|
+
},
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"@babel/core": "^8.0.7",
|
|
108
|
+
"@babel/plugin-transform-async-generator-functions": "^8.0.6",
|
|
109
|
+
"@babel/plugin-transform-async-to-generator": "^8.0.1",
|
|
110
|
+
"@rollup/plugin-inject": "^5.0.5",
|
|
111
|
+
"brotli-dec-wasm": "2.3.2",
|
|
112
|
+
"esbuild": "^0.28.2",
|
|
113
|
+
"jsonc-parser": "^3.3.1",
|
|
114
|
+
"node-stdlib-browser": "^1.3.1",
|
|
115
|
+
"parse-srcset": "^1.0.2",
|
|
116
|
+
"parse5": "^8.0.1",
|
|
117
|
+
"punycode": "2.3.1",
|
|
118
|
+
"readable-stream": "4.8.0",
|
|
119
|
+
"rollup": "^4.64.9",
|
|
120
|
+
"smol-toml": "^1.9.1",
|
|
121
|
+
"string_decoder": "^1.3.0",
|
|
122
|
+
"vite-plugin-node-polyfills": "^0.28.0",
|
|
123
|
+
"web-streams-polyfill": "4.3.0"
|
|
124
|
+
},
|
|
125
|
+
"devDependencies": {
|
|
126
|
+
"@playwright/test": "^1.64.1",
|
|
127
|
+
"@types/node": "^26.6.5",
|
|
128
|
+
"hono": "^4.13.13",
|
|
129
|
+
"prettier": "3.8.4",
|
|
130
|
+
"typescript": "^7.0.2",
|
|
131
|
+
"vite": "^7.3.7",
|
|
132
|
+
"vitest": "^5.0.5",
|
|
133
|
+
"whatwg-url": "17.3.0"
|
|
134
|
+
},
|
|
135
|
+
"peerDependencies": {
|
|
136
|
+
"@capacitor/core": "^8.0.0",
|
|
137
|
+
"vite": "^7.3.7"
|
|
138
|
+
},
|
|
139
|
+
"peerDependenciesMeta": {
|
|
140
|
+
"vite": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
143
|
+
"@capacitor/core": {
|
|
144
|
+
"optional": true
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"capacitor": {
|
|
148
|
+
"ios": {
|
|
149
|
+
"src": "native/ios"
|
|
150
|
+
},
|
|
151
|
+
"android": {
|
|
152
|
+
"src": "native/android"
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"gitHead": "2f5e4e6956f41b2904f8a6b9c81cccf35c908b9a"
|
|
156
|
+
}
|