cf-workers-native 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/browser/documents/page-source.js +1 -1
- package/dist/browser/fetch/host-call.js +6 -1
- package/dist/browser/fetch/native-network.d.ts +1 -1
- package/dist/browser/fetch/relay.js +2 -0
- package/dist/browser/headers/index.d.ts +2 -0
- package/dist/browser/headers/index.js +5 -0
- package/dist/browser/isolated/transport.js +3 -2
- package/dist/browser/request/index.js +3 -2
- package/dist/browser/response/index.d.ts +2 -0
- package/dist/browser/response/index.js +11 -3
- package/dist/browser/structured-clone/index.d.ts +3 -0
- package/dist/browser/structured-clone/index.js +75 -7
- package/dist/browser/websocket/attachment-size.d.ts +3 -0
- package/dist/browser/websocket/attachment-size.js +336 -0
- package/dist/browser/websocket/brand.d.ts +4 -0
- package/dist/browser/websocket/brand.js +16 -0
- package/dist/browser/websocket/close-event.d.ts +7 -0
- package/dist/browser/websocket/close-event.js +30 -0
- package/dist/browser/websocket/compression.d.ts +5 -0
- package/dist/browser/websocket/compression.js +124 -0
- package/dist/browser/websocket/conversion.d.ts +2 -0
- package/dist/browser/websocket/conversion.js +13 -0
- package/dist/browser/websocket/endpoint.d.ts +39 -0
- package/dist/browser/websocket/endpoint.js +379 -0
- package/dist/browser/websocket/frames.d.ts +21 -0
- package/dist/browser/websocket/frames.js +121 -0
- package/dist/browser/websocket/native.d.ts +14 -0
- package/dist/browser/websocket/native.js +226 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
- package/dist/cloudflare/workers/worker-runtime.js +2 -1
- package/dist/compat/console/index.d.ts +35 -0
- package/dist/compat/console/index.js +92 -0
- package/dist/compat/crypto/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/crypto/LICENSE-APACHE +177 -0
- package/dist/compat/crypto/LICENSE.boringssl +238 -0
- package/dist/compat/crypto/LICENSE.emscripten +102 -0
- package/dist/compat/crypto/LICENSE.musl +193 -0
- package/dist/compat/crypto/LICENSE.ncrypto +21 -0
- package/dist/compat/crypto/LICENSE.openssl +177 -0
- package/dist/compat/crypto/asymmetric.d.ts +13 -0
- package/dist/compat/crypto/asymmetric.js +312 -0
- package/dist/compat/crypto/brorand.cjs +74 -0
- package/dist/compat/crypto/brorand.d.cts +6 -0
- package/dist/compat/crypto/certificate.d.ts +14 -0
- package/dist/compat/crypto/certificate.js +66 -0
- package/dist/compat/crypto/cipher-handle.d.ts +27 -0
- package/dist/compat/crypto/cipher-handle.js +239 -0
- package/dist/compat/crypto/cipher-info.d.ts +12 -0
- package/dist/compat/crypto/cipher-info.js +324 -0
- package/dist/compat/crypto/constants.d.ts +62 -0
- package/dist/compat/crypto/constants.js +68 -0
- package/dist/compat/crypto/dh-handle.d.ts +17 -0
- package/dist/compat/crypto/dh-handle.js +180 -0
- package/dist/compat/crypto/dh.d.ts +53 -0
- package/dist/compat/crypto/dh.js +138 -0
- package/dist/compat/crypto/digest-stream.d.ts +15 -0
- package/dist/compat/crypto/digest-stream.js +213 -0
- package/dist/compat/crypto/digests.d.ts +3 -0
- package/dist/compat/crypto/digests.js +32 -0
- package/dist/compat/crypto/ecdh.d.ts +25 -0
- package/dist/compat/crypto/ecdh.js +109 -0
- package/dist/compat/crypto/hash-handle.d.ts +23 -0
- package/dist/compat/crypto/hash-handle.js +70 -0
- package/dist/compat/crypto/hash.d.ts +37 -0
- package/dist/compat/crypto/hash.js +218 -0
- package/dist/compat/crypto/hkdf.d.ts +2 -0
- package/dist/compat/crypto/hkdf.js +78 -0
- package/dist/compat/crypto/index.cjs +2 -0
- package/dist/compat/crypto/index.d.cts +169 -0
- package/dist/compat/crypto/index.d.ts +213 -0
- package/dist/compat/crypto/index.js +96 -0
- package/dist/compat/crypto/key-errors.d.ts +10 -0
- package/dist/compat/crypto/key-errors.js +17 -0
- package/dist/compat/crypto/key-export.d.ts +8 -0
- package/dist/compat/crypto/key-export.js +49 -0
- package/dist/compat/crypto/key-formats.d.ts +7 -0
- package/dist/compat/crypto/key-formats.js +251 -0
- package/dist/compat/crypto/key-options.d.ts +1 -0
- package/dist/compat/crypto/key-options.js +74 -0
- package/dist/compat/crypto/key-state.d.ts +10 -0
- package/dist/compat/crypto/key-state.js +4 -0
- package/dist/compat/crypto/keys.d.ts +58 -0
- package/dist/compat/crypto/keys.js +278 -0
- package/dist/compat/crypto/metadata.d.ts +13 -0
- package/dist/compat/crypto/metadata.js +109 -0
- package/dist/compat/crypto/native-cipher.d.ts +17 -0
- package/dist/compat/crypto/native-cipher.js +192 -0
- package/dist/compat/crypto/native-crypto.d.ts +81 -0
- package/dist/compat/crypto/native-crypto.js +681 -0
- package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
- package/dist/compat/crypto/pbkdf2-handle.js +26 -0
- package/dist/compat/crypto/pbkdf2.d.ts +5 -0
- package/dist/compat/crypto/pbkdf2.js +60 -0
- package/dist/compat/crypto/prime.d.ts +19 -0
- package/dist/compat/crypto/prime.js +146 -0
- package/dist/compat/crypto/random.d.ts +18 -0
- package/dist/compat/crypto/random.js +203 -0
- package/dist/compat/crypto/rsa.d.ts +21 -0
- package/dist/compat/crypto/rsa.js +177 -0
- package/dist/compat/crypto/scrypt.d.ts +25 -0
- package/dist/compat/crypto/scrypt.js +152 -0
- package/dist/compat/crypto/sign-errors.d.ts +8 -0
- package/dist/compat/crypto/sign-errors.js +13 -0
- package/dist/compat/crypto/sign-handle.d.ts +22 -0
- package/dist/compat/crypto/sign-handle.js +149 -0
- package/dist/compat/crypto/signatures.d.ts +34 -0
- package/dist/compat/crypto/signatures.js +252 -0
- package/dist/compat/crypto/subtle-digest.d.ts +1 -0
- package/dist/compat/crypto/subtle-digest.js +56 -0
- package/dist/compat/crypto/symmetric.d.ts +45 -0
- package/dist/compat/crypto/symmetric.js +239 -0
- package/dist/compat/crypto/validation.d.ts +7 -0
- package/dist/compat/crypto/validation.js +46 -0
- package/dist/compat/crypto/webcrypto.d.ts +13 -0
- package/dist/compat/crypto/webcrypto.js +51 -0
- package/dist/compat/crypto/x509.d.ts +30 -0
- package/dist/compat/crypto/x509.js +407 -0
- package/dist/compat/events/errors.d.ts +8 -0
- package/dist/compat/events/errors.js +39 -0
- package/dist/compat/events/index.cjs +2 -0
- package/dist/compat/events/index.d.cts +2 -0
- package/dist/compat/events/index.d.ts +64 -0
- package/dist/compat/events/index.js +792 -0
- package/dist/compat/events/intrinsics.d.ts +1 -0
- package/dist/compat/events/intrinsics.js +2 -0
- package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/fs/LICENSE-APACHE +177 -0
- package/dist/compat/fs/directory-backend.d.ts +6 -0
- package/dist/compat/fs/directory-backend.js +51 -0
- package/dist/compat/fs/directory.d.ts +37 -0
- package/dist/compat/fs/directory.js +137 -0
- package/dist/compat/fs/embedded.d.ts +85 -0
- package/dist/compat/fs/embedded.js +260 -0
- package/dist/compat/fs/file-handle.d.ts +75 -0
- package/dist/compat/fs/file-handle.js +226 -0
- package/dist/compat/fs/glob-internal.d.ts +15 -0
- package/dist/compat/fs/glob-internal.js +417 -0
- package/dist/compat/fs/glob.d.ts +10 -0
- package/dist/compat/fs/glob.js +71 -0
- package/dist/compat/fs/index.d.ts +8 -82
- package/dist/compat/fs/index.js +736 -238
- package/dist/compat/fs/io-validation.d.ts +14 -0
- package/dist/compat/fs/io-validation.js +130 -0
- package/dist/compat/fs/io.d.ts +1 -0
- package/dist/compat/fs/io.js +282 -0
- package/dist/compat/fs/mode.d.ts +1 -0
- package/dist/compat/fs/mode.js +13 -0
- package/dist/compat/fs/promises/index.d.ts +3 -1
- package/dist/compat/fs/promises/index.js +1 -1
- package/dist/compat/fs/public-types.d.ts +120 -0
- package/dist/compat/fs/public-types.js +1 -0
- package/dist/compat/fs/stream-errors.d.ts +6 -0
- package/dist/compat/fs/stream-errors.js +8 -0
- package/dist/compat/fs/stream-utils.d.ts +16 -0
- package/dist/compat/fs/stream-utils.js +29 -0
- package/dist/compat/fs/streams.d.ts +104 -0
- package/dist/compat/fs/streams.js +794 -0
- package/dist/compat/fs/writable.d.ts +14 -0
- package/dist/compat/fs/writable.js +532 -0
- package/dist/compat/http/index.d.ts +11 -28
- package/dist/compat/http/index.js +81 -125
- package/dist/compat/http/server-options.d.ts +1 -0
- package/dist/compat/http/server-options.js +87 -0
- package/dist/compat/http/symbols.d.ts +5 -0
- package/dist/compat/http/symbols.js +9 -0
- package/dist/compat/http/unique-headers.d.ts +1 -0
- package/dist/compat/http/unique-headers.js +21 -0
- package/dist/compat/http-common/index.d.ts +37 -0
- package/dist/compat/http-common/index.js +43 -0
- package/dist/compat/http-outgoing/index.d.ts +14 -0
- package/dist/compat/http-outgoing/index.js +17 -0
- package/dist/compat/http-server/index.d.ts +18 -0
- package/dist/compat/http-server/index.js +26 -0
- package/dist/compat/https/index.d.ts +4 -2
- package/dist/compat/module/builtins.d.ts +1 -0
- package/dist/compat/module/builtins.js +101 -0
- package/dist/compat/module/index.d.ts +4 -2
- package/dist/compat/module/index.js +22 -17
- package/dist/compat/module/metadata.d.ts +44 -0
- package/dist/compat/module/metadata.js +127 -0
- package/dist/compat/net/internal-net.js +4 -0
- package/dist/compat/net/sockets.d.ts +5 -0
- package/dist/compat/net/sockets.js +153 -14
- package/dist/compat/net/validators.d.ts +1 -0
- package/dist/compat/net/validators.js +8 -0
- package/dist/compat/process/configuration.d.ts +113 -0
- package/dist/compat/process/configuration.js +115 -0
- package/dist/compat/process/directory.d.ts +4 -0
- package/dist/compat/process/directory.js +28 -0
- package/dist/compat/process/files.d.ts +3 -0
- package/dist/compat/process/files.js +10 -0
- package/dist/compat/process/index.cjs +2 -0
- package/dist/compat/process/index.d.cts +4 -0
- package/dist/compat/process/index.d.ts +20 -0
- package/dist/compat/process/index.js +113 -0
- package/dist/compat/process/metadata.d.ts +135 -0
- package/dist/compat/process/metadata.js +251 -0
- package/dist/compat/process/scheduling.d.ts +2 -0
- package/dist/compat/process/scheduling.js +60 -0
- package/dist/compat/process/state.d.ts +4 -0
- package/dist/compat/process/state.js +5 -0
- package/dist/compat/process/stdio.d.ts +18 -0
- package/dist/compat/process/stdio.js +66 -0
- package/dist/compat/stream/destroy.d.ts +1 -0
- package/dist/compat/stream/destroy.js +21 -1
- package/dist/compat/stream/readable.js +10 -2
- package/dist/compat/stream-web/LICENSE +22 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -1
- package/dist/compat/stream-web/ponyfill.js +2369 -1775
- package/dist/compat/stream-web/runtime.d.ts +1 -1
- package/dist/compat/stream-web/runtime.js +3 -2
- package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/stream-wrap/index.d.ts +1 -0
- package/dist/compat/stream-wrap/index.js +1 -0
- package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls/LICENSE-APACHE +177 -0
- package/dist/compat/tls/constants.d.ts +7 -0
- package/dist/compat/tls/constants.js +14 -0
- package/dist/compat/tls/errors.d.ts +35 -0
- package/dist/compat/tls/errors.js +68 -0
- package/dist/compat/tls/helpers.d.ts +9 -0
- package/dist/compat/tls/helpers.js +207 -0
- package/dist/compat/tls/index.d.ts +26 -0
- package/dist/compat/tls/index.js +50 -0
- package/dist/compat/tls/jsstream.d.ts +19 -0
- package/dist/compat/tls/jsstream.js +196 -0
- package/dist/compat/tls/native-session.d.ts +3 -0
- package/dist/compat/tls/native-session.js +187 -0
- package/dist/compat/tls/wrap.d.ts +65 -0
- package/dist/compat/tls/wrap.js +541 -0
- package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/tls-wrap/index.d.ts +7 -0
- package/dist/compat/tls-wrap/index.js +3 -0
- package/dist/compat/util/index.js +43 -1
- package/dist/compat/util/inspect.js +5 -1
- package/dist/compat/util/types/index.d.ts +3 -0
- package/dist/compat/util/types/index.js +5 -0
- package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/zlib/LICENSE-APACHE +177 -0
- package/dist/compat/zlib/LICENSE.brotli +19 -0
- package/dist/compat/zlib/LICENSE.emscripten +102 -0
- package/dist/compat/zlib/LICENSE.musl +193 -0
- package/dist/compat/zlib/LICENSE.zlib +22 -0
- package/dist/compat/zlib/LICENSE.zstd +30 -0
- package/dist/compat/zlib/classic-base.cjs +600 -0
- package/dist/compat/zlib/classic-base.d.cts +39 -0
- package/dist/compat/zlib/classic-binding.d.ts +28 -0
- package/dist/compat/zlib/classic-binding.js +105 -0
- package/dist/compat/zlib/classic.d.ts +44 -0
- package/dist/compat/zlib/classic.js +199 -0
- package/dist/compat/zlib/codec-binding.d.ts +33 -0
- package/dist/compat/zlib/codec-binding.js +141 -0
- package/dist/compat/zlib/compression.d.ts +26 -0
- package/dist/compat/zlib/compression.js +170 -0
- package/dist/compat/zlib/constants.d.ts +172 -0
- package/dist/compat/zlib/constants.js +173 -0
- package/dist/compat/zlib/errors.d.ts +21 -0
- package/dist/compat/zlib/errors.js +32 -0
- package/dist/compat/zlib/index.d.ts +544 -0
- package/dist/compat/zlib/index.js +194 -0
- package/dist/compat/zlib/input.d.ts +16 -0
- package/dist/compat/zlib/input.js +132 -0
- package/dist/compat/zlib/native-codecs.d.ts +24 -0
- package/dist/compat/zlib/native-codecs.js +180 -0
- package/dist/compat/zlib/native-zlib.d.ts +5 -0
- package/dist/compat/zlib/native-zlib.js +52 -0
- package/dist/compat/zlib/public-types.d.ts +48 -0
- package/dist/compat/zlib/public-types.js +1 -0
- package/dist/compat/zlib/validators.d.ts +3 -0
- package/dist/compat/zlib/validators.js +18 -0
- package/dist/shared/buffer-source.d.ts +5 -0
- package/dist/shared/buffer-source.js +70 -0
- package/dist/shared/globals/inject.d.ts +2 -1
- package/dist/shared/globals/inject.js +2 -1
- package/dist/shared/globals/platform.d.ts +8 -0
- package/dist/shared/globals/platform.js +1 -0
- package/dist/shared/globals/runtime.d.ts +1 -2
- package/dist/shared/globals/runtime.js +1 -2
- package/dist/shared/globals/web.js +5 -0
- package/dist/shared/request-context.d.ts +2 -0
- package/dist/shared/request-context.js +11 -0
- package/dist/shared/request-scope.d.ts +4 -0
- package/dist/shared/request-scope.js +14 -0
- package/dist/tooling/async.js +36 -14
- package/dist/tooling/shared.d.ts +1 -0
- package/dist/tooling/shared.js +26 -1
- package/dist/tooling/vite.js +8 -3
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +92 -13
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
- package/native/ios/NetworkBridge.swift +11 -1
- package/native/ios/SocketBridge.swift +37 -2
- package/native/ios/WorkersCapacitorPlugin.swift +4 -0
- package/package.json +4 -2
|
@@ -2,12 +2,14 @@ declare const ClientRequest: typeof import("../http/index.js").ClientRequest;
|
|
|
2
2
|
type ClientRequest = InstanceType<typeof ClientRequest>;
|
|
3
3
|
import { Agent, globalAgent } from "./agent.js";
|
|
4
4
|
import { Server } from "./server.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { IncomingMessage } from "node:http";
|
|
6
|
+
type IncomingMessageCallback = (message: IncomingMessage) => void;
|
|
6
7
|
import type { RequestOptions, RequestListener } from "node:http";
|
|
7
8
|
import type { ServerOptions } from "node:https";
|
|
8
9
|
export declare function request(url: string | URL | RequestOptions, options?: RequestOptions | IncomingMessageCallback, cb?: IncomingMessageCallback): ClientRequest;
|
|
9
10
|
export declare function get(input: string | URL | RequestOptions, options?: RequestOptions | IncomingMessageCallback, cb?: IncomingMessageCallback): ClientRequest;
|
|
10
|
-
export declare function createServer(
|
|
11
|
+
export declare function createServer(handler?: RequestListener): Server;
|
|
12
|
+
export declare function createServer(options: ServerOptions, handler?: RequestListener): Server;
|
|
11
13
|
export { Agent, globalAgent, Server };
|
|
12
14
|
declare const _default: {
|
|
13
15
|
get: typeof get;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const builtinModules: string[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
6
|
+
//
|
|
7
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
8
|
+
// copy of this software and associated documentation files (the
|
|
9
|
+
// "Software"), to deal in the Software without restriction, including
|
|
10
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
12
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
13
|
+
// following conditions:
|
|
14
|
+
//
|
|
15
|
+
// The above copyright notice and this permission notice shall be included
|
|
16
|
+
// in all copies or substantial portions of the Software.
|
|
17
|
+
//
|
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
19
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
21
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
22
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
23
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
24
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
// Intentionally does not include modules with mandatory 'node:'
|
|
26
|
+
// prefix like `node:test`.
|
|
27
|
+
// See: See https://nodejs.org/docs/latest/api/modules.html#built-in-modules-with-mandatory-node-prefix
|
|
28
|
+
// TODO(later): This list duplicates the list that is in
|
|
29
|
+
// workerd/jsg/modules.c++. Later we should source these
|
|
30
|
+
// from the same place so we don't have to maintain two lists.
|
|
31
|
+
export const builtinModules = [
|
|
32
|
+
"_http_agent",
|
|
33
|
+
"_http_client",
|
|
34
|
+
"_http_common",
|
|
35
|
+
"_http_incoming",
|
|
36
|
+
"_http_outgoing",
|
|
37
|
+
"_http_server",
|
|
38
|
+
"_stream_duplex",
|
|
39
|
+
"_stream_passthrough",
|
|
40
|
+
"_stream_readable",
|
|
41
|
+
"_stream_transform",
|
|
42
|
+
"_stream_wrap",
|
|
43
|
+
"_stream_writable",
|
|
44
|
+
"_tls_common",
|
|
45
|
+
"_tls_wrap",
|
|
46
|
+
"assert",
|
|
47
|
+
"assert/strict",
|
|
48
|
+
"async_hooks",
|
|
49
|
+
"buffer",
|
|
50
|
+
"child_process",
|
|
51
|
+
"cluster",
|
|
52
|
+
"console",
|
|
53
|
+
"constants",
|
|
54
|
+
"crypto",
|
|
55
|
+
"dgram",
|
|
56
|
+
"diagnostics_channel",
|
|
57
|
+
"dns",
|
|
58
|
+
"dns/promises",
|
|
59
|
+
"domain",
|
|
60
|
+
"events",
|
|
61
|
+
"fs",
|
|
62
|
+
"fs/promises",
|
|
63
|
+
"http",
|
|
64
|
+
"http2",
|
|
65
|
+
"https",
|
|
66
|
+
"inspector",
|
|
67
|
+
"inspector/promises",
|
|
68
|
+
"module",
|
|
69
|
+
"net",
|
|
70
|
+
"os",
|
|
71
|
+
"path",
|
|
72
|
+
"path/posix",
|
|
73
|
+
"path/win32",
|
|
74
|
+
"perf_hooks",
|
|
75
|
+
"process",
|
|
76
|
+
"punycode",
|
|
77
|
+
"querystring",
|
|
78
|
+
"readline",
|
|
79
|
+
"readline/promises",
|
|
80
|
+
"repl",
|
|
81
|
+
"stream",
|
|
82
|
+
"stream/consumers",
|
|
83
|
+
"stream/promises",
|
|
84
|
+
"stream/web",
|
|
85
|
+
"string_decoder",
|
|
86
|
+
"sys",
|
|
87
|
+
"timers",
|
|
88
|
+
"timers/promises",
|
|
89
|
+
"tls",
|
|
90
|
+
"trace_events",
|
|
91
|
+
"tty",
|
|
92
|
+
"url",
|
|
93
|
+
"util",
|
|
94
|
+
"util/types",
|
|
95
|
+
"v8",
|
|
96
|
+
"vm",
|
|
97
|
+
"wasi",
|
|
98
|
+
"worker_threads",
|
|
99
|
+
"zlib",
|
|
100
|
+
];
|
|
101
|
+
Object.freeze(builtinModules);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { builtinModules } from "./builtins.js";
|
|
2
|
+
export { builtinModules };
|
|
3
|
+
export * from "./metadata.js";
|
|
2
4
|
export declare function isBuiltin(specifier: string): boolean;
|
|
3
|
-
export declare function createRequire(
|
|
5
|
+
export declare function createRequire(filename: string | URL): (id: string) => unknown;
|
|
4
6
|
export declare class Module {
|
|
5
7
|
static builtinModules: string[];
|
|
6
8
|
static isBuiltin: typeof isBuiltin;
|
|
@@ -2,29 +2,33 @@
|
|
|
2
2
|
// the registered virtual filesystem; executable modules cannot be loaded in
|
|
3
3
|
// a bundled WebView runtime and throw explicitly.
|
|
4
4
|
import { readFileSync } from "../fs/index.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"module",
|
|
12
|
-
"net",
|
|
13
|
-
"path",
|
|
14
|
-
"querystring",
|
|
15
|
-
"stream",
|
|
16
|
-
"stream/web",
|
|
17
|
-
"string_decoder",
|
|
18
|
-
"util",
|
|
19
|
-
];
|
|
5
|
+
import { builtinModules } from "./builtins.js";
|
|
6
|
+
export { builtinModules };
|
|
7
|
+
import * as metadata from "./metadata.js";
|
|
8
|
+
export * from "./metadata.js";
|
|
9
|
+
import { posix } from "node:path";
|
|
10
|
+
import { ERR_INVALID_ARG_VALUE } from "../net/errors.js";
|
|
20
11
|
export function isBuiltin(specifier) {
|
|
12
|
+
if (typeof specifier !== "string")
|
|
13
|
+
return false;
|
|
14
|
+
if (["node:test", "node:test/reporters", "node:sqlite"].includes(specifier))
|
|
15
|
+
return true;
|
|
21
16
|
const name = specifier.startsWith("node:") ? specifier.slice(5) : specifier;
|
|
22
17
|
return builtinModules.includes(name);
|
|
23
18
|
}
|
|
24
|
-
export function createRequire(
|
|
19
|
+
export function createRequire(filename) {
|
|
20
|
+
const value = String(filename);
|
|
21
|
+
if (!value.startsWith("/") && !value.startsWith("file:"))
|
|
22
|
+
throw new ERR_INVALID_ARG_VALUE("path", value, "The argument must be a file URL object, a file URL string, or an absolute path string.");
|
|
23
|
+
const pathname = value.startsWith("file:")
|
|
24
|
+
? decodeURIComponent(new URL(value).pathname)
|
|
25
|
+
: value;
|
|
26
|
+
const directory = posix.dirname(pathname);
|
|
25
27
|
return function require(id) {
|
|
26
28
|
if (id.endsWith(".json")) {
|
|
27
|
-
const data = readFileSync(id, {
|
|
29
|
+
const data = readFileSync(posix.resolve(directory, id), {
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
});
|
|
28
32
|
return JSON.parse(data);
|
|
29
33
|
}
|
|
30
34
|
throw new Error(`createRequire cannot load '${id}' in this runtime: executable modules must be bundled.`);
|
|
@@ -41,4 +45,5 @@ export class Module {
|
|
|
41
45
|
return createRequire("/")(id);
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
Object.assign(Module, metadata);
|
|
44
49
|
export default Module;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare function register(): void;
|
|
2
|
+
export declare function runMain(): void;
|
|
3
|
+
export declare function syncBuiltinESMExports(): void;
|
|
4
|
+
export declare function wrap(): void;
|
|
5
|
+
export declare const globalPaths: string[];
|
|
6
|
+
export declare const constants: Readonly<{
|
|
7
|
+
__proto__: null;
|
|
8
|
+
compileCacheStatus: Readonly<{
|
|
9
|
+
__proto__: null;
|
|
10
|
+
FAILED: 0;
|
|
11
|
+
ENABLED: 1;
|
|
12
|
+
ALREADY_ENABLED: 2;
|
|
13
|
+
DISABLED: 3;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const _cache: {
|
|
17
|
+
__proto__: null;
|
|
18
|
+
};
|
|
19
|
+
export declare const _pathCache: {
|
|
20
|
+
__proto__: null;
|
|
21
|
+
};
|
|
22
|
+
export declare function _debug(): void;
|
|
23
|
+
export declare function _findPath(): void;
|
|
24
|
+
export declare function _initPaths(): void;
|
|
25
|
+
export declare function _load(): void;
|
|
26
|
+
export declare function _preloadModules(): void;
|
|
27
|
+
export declare function _resolveFilename(): void;
|
|
28
|
+
export declare function _resolveLookupPaths(): void;
|
|
29
|
+
export declare function _nodeModulePaths(): void;
|
|
30
|
+
export declare function findSourceMap(): void;
|
|
31
|
+
export declare function findPackageJSON(): void;
|
|
32
|
+
export declare function flushCompileCache(): void;
|
|
33
|
+
export declare function getSourceMapsSupport(): Record<string, boolean | null>;
|
|
34
|
+
export declare function setSourceMapsSupport(): void;
|
|
35
|
+
export declare function stripTypeScriptTypes(): void;
|
|
36
|
+
export declare function registerHooks(): void;
|
|
37
|
+
export declare function SourceMap(): void;
|
|
38
|
+
export declare function enableCompileCache(): void;
|
|
39
|
+
export declare function getCompileCacheDir(): undefined;
|
|
40
|
+
export declare const _extensions: {
|
|
41
|
+
".js": () => never;
|
|
42
|
+
".json": () => never;
|
|
43
|
+
".node": () => never;
|
|
44
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Pinned Workers module metadata and explicit stubs.
|
|
5
|
+
class ERR_METHOD_NOT_IMPLEMENTED extends Error {
|
|
6
|
+
code = "ERR_METHOD_NOT_IMPLEMENTED";
|
|
7
|
+
constructor(method) {
|
|
8
|
+
super(`The ${method} method is not implemented`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function register() {
|
|
12
|
+
// TODO(soon): We might support this in the future.
|
|
13
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.register");
|
|
14
|
+
}
|
|
15
|
+
export function runMain() {
|
|
16
|
+
// We don't plan to support this in the future.
|
|
17
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.runMain");
|
|
18
|
+
}
|
|
19
|
+
export function syncBuiltinESMExports() {
|
|
20
|
+
// We are unlikely to ever support this.
|
|
21
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.syncBuiltinESMExports");
|
|
22
|
+
}
|
|
23
|
+
export function wrap() {
|
|
24
|
+
// TODO(soon): Implement this feature.
|
|
25
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.wrap");
|
|
26
|
+
}
|
|
27
|
+
export const globalPaths = [];
|
|
28
|
+
const compileCacheStatus = Object.freeze({
|
|
29
|
+
__proto__: null,
|
|
30
|
+
FAILED: 0,
|
|
31
|
+
ENABLED: 1,
|
|
32
|
+
ALREADY_ENABLED: 2,
|
|
33
|
+
DISABLED: 3,
|
|
34
|
+
});
|
|
35
|
+
export const constants = Object.freeze({
|
|
36
|
+
__proto__: null,
|
|
37
|
+
compileCacheStatus,
|
|
38
|
+
});
|
|
39
|
+
export const _cache = { __proto__: null };
|
|
40
|
+
export const _pathCache = { __proto__: null };
|
|
41
|
+
export function _debug() {
|
|
42
|
+
// This is deprecated and will be removed in the future.
|
|
43
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._debug");
|
|
44
|
+
}
|
|
45
|
+
export function _findPath() {
|
|
46
|
+
// It doesn't make sense to support this.
|
|
47
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._findPath");
|
|
48
|
+
}
|
|
49
|
+
export function _initPaths() {
|
|
50
|
+
// It doesn't make sense to support this.
|
|
51
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._initPaths");
|
|
52
|
+
}
|
|
53
|
+
export function _load() {
|
|
54
|
+
// TODO(soon): Investigate the possibility of supporting this in the future.
|
|
55
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._load");
|
|
56
|
+
}
|
|
57
|
+
export function _preloadModules() {
|
|
58
|
+
// It doesn't make sense to support this.
|
|
59
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._preloadModules");
|
|
60
|
+
}
|
|
61
|
+
export function _resolveFilename() {
|
|
62
|
+
// TODO(soon): Investigate the possibility of supporting this in the future.
|
|
63
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._resolveFilename");
|
|
64
|
+
}
|
|
65
|
+
export function _resolveLookupPaths() {
|
|
66
|
+
// TODO(soon): Investigate the possibility of supporting this in the future.
|
|
67
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._resolveLookupPaths");
|
|
68
|
+
}
|
|
69
|
+
export function _nodeModulePaths() {
|
|
70
|
+
// It doesn't make sense to support this.
|
|
71
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._nodeModulePaths");
|
|
72
|
+
}
|
|
73
|
+
export function findSourceMap() {
|
|
74
|
+
// TODO(soon): Investigate the possibility of supporting this in the future.
|
|
75
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.findSourceMap");
|
|
76
|
+
}
|
|
77
|
+
export function findPackageJSON() {
|
|
78
|
+
// It doesn't make sense to support this.
|
|
79
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.findPackageJSON");
|
|
80
|
+
}
|
|
81
|
+
export function flushCompileCache() {
|
|
82
|
+
// We don't implement compile cache. This acts as a no-op.
|
|
83
|
+
}
|
|
84
|
+
export function getSourceMapsSupport() {
|
|
85
|
+
return Object.freeze({
|
|
86
|
+
__proto__: null,
|
|
87
|
+
enabled: false,
|
|
88
|
+
nodeModules: false,
|
|
89
|
+
generatedCode: false,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export function setSourceMapsSupport() {
|
|
93
|
+
// We don't implement source maps support.
|
|
94
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.setSourceMapsSupport");
|
|
95
|
+
}
|
|
96
|
+
export function stripTypeScriptTypes() {
|
|
97
|
+
// We don't implement stripping TypeScript types.
|
|
98
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.stripTypeScriptTypes");
|
|
99
|
+
}
|
|
100
|
+
export function registerHooks() {
|
|
101
|
+
// We don't implement hooks registration.
|
|
102
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.registerHooks");
|
|
103
|
+
}
|
|
104
|
+
export function SourceMap() {
|
|
105
|
+
// We don't support source maps.
|
|
106
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module.SourceMap");
|
|
107
|
+
}
|
|
108
|
+
export function enableCompileCache() {
|
|
109
|
+
// We don't plan to support this in the future.
|
|
110
|
+
// Since, this method shouldn't throw an error, we just act like a no-op.
|
|
111
|
+
}
|
|
112
|
+
export function getCompileCacheDir() {
|
|
113
|
+
// We don't plan to support this in the future.
|
|
114
|
+
// Since, compile cache acts as a no-op, we just return undefined.
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
export const _extensions = {
|
|
118
|
+
".js": () => {
|
|
119
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._extensions.js");
|
|
120
|
+
},
|
|
121
|
+
".json": () => {
|
|
122
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._extensions.json");
|
|
123
|
+
},
|
|
124
|
+
".node": () => {
|
|
125
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("module._extensions.node");
|
|
126
|
+
},
|
|
127
|
+
};
|
|
@@ -1336,6 +1336,10 @@ function initializeConnection(socket, options) {
|
|
|
1336
1336
|
allowHalfOpen: true,
|
|
1337
1337
|
// A Node.js socket is always capable of being upgraded to the TLS socket.
|
|
1338
1338
|
secureTransport: socket.encrypted ? "on" : "starttls",
|
|
1339
|
+
expectedServerHostname: socket.encrypted
|
|
1340
|
+
? socket.servername ||
|
|
1341
|
+
socket._host
|
|
1342
|
+
: undefined,
|
|
1339
1343
|
// We are not going to pass the high water-mark here. The outer Node.js
|
|
1340
1344
|
// stream will implement the appropriate backpressure for us.
|
|
1341
1345
|
});
|
|
@@ -4,6 +4,10 @@ export interface SocketInfo {
|
|
|
4
4
|
}
|
|
5
5
|
export interface PlatformSocket {
|
|
6
6
|
upgraded?: boolean;
|
|
7
|
+
secureTransport: "on" | "off" | "starttls";
|
|
8
|
+
startTls(options?: {
|
|
9
|
+
expectedServerHostname?: string;
|
|
10
|
+
}): PlatformSocket;
|
|
7
11
|
opened: Promise<SocketInfo>;
|
|
8
12
|
closed: Promise<void>;
|
|
9
13
|
readable: ReadableStream<Uint8Array>;
|
|
@@ -11,6 +15,7 @@ export interface PlatformSocket {
|
|
|
11
15
|
close(): Promise<void>;
|
|
12
16
|
}
|
|
13
17
|
export declare function connect(address: string, options?: {
|
|
18
|
+
expectedServerHostname?: string;
|
|
14
19
|
allowHalfOpen?: boolean;
|
|
15
20
|
secureTransport?: "on" | "off" | "starttls";
|
|
16
21
|
}): PlatformSocket;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { nativeTlsSession } from "../tls/native-session.js";
|
|
1
2
|
import { observeConsumption } from "./reader.js";
|
|
2
|
-
import { getNativeCall } from "../../browser/fetch/native-network.js";
|
|
3
|
+
import { getNativeCall, } from "../../browser/fetch/native-network.js";
|
|
3
4
|
function bytes(value) {
|
|
4
5
|
const decoded = atob(value);
|
|
5
6
|
return Uint8Array.from(decoded, (character) => character.charCodeAt(0));
|
|
@@ -28,6 +29,50 @@ export function connect(address, options = {}) {
|
|
|
28
29
|
(url.pathname && url.pathname !== "/"))
|
|
29
30
|
throw new TypeError("Invalid TCP address");
|
|
30
31
|
const id = crypto.randomUUID();
|
|
32
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
33
|
+
const directTls = options.secureTransport === "on";
|
|
34
|
+
let secureCall = call;
|
|
35
|
+
return transport((...args) => {
|
|
36
|
+
const operation = secureCall(...args);
|
|
37
|
+
return directTls
|
|
38
|
+
? operation.catch((error) => {
|
|
39
|
+
if (error instanceof Error &&
|
|
40
|
+
error.message.includes("TLS connection closed without close_notify"))
|
|
41
|
+
throw new Error("Network connection lost.");
|
|
42
|
+
throw error;
|
|
43
|
+
})
|
|
44
|
+
: operation;
|
|
45
|
+
}, id, host, options.secureTransport ?? "off", async () => {
|
|
46
|
+
try {
|
|
47
|
+
const info = await call("WorkersCapacitor", "socketOpen", {
|
|
48
|
+
id,
|
|
49
|
+
host,
|
|
50
|
+
port,
|
|
51
|
+
tls: false,
|
|
52
|
+
});
|
|
53
|
+
if (options.secureTransport === "on") {
|
|
54
|
+
const servername = options.expectedServerHostname ?? host;
|
|
55
|
+
const result = (await call("WorkersCapacitor", "socketStartTls", {
|
|
56
|
+
id,
|
|
57
|
+
servername,
|
|
58
|
+
}));
|
|
59
|
+
// Direct TLS and STARTTLS share the authenticated record engine. On iOS
|
|
60
|
+
// this also preserves TLS close_notify information that NW TLS hides.
|
|
61
|
+
if (result?.tlsEngine === "openssl-wasm")
|
|
62
|
+
secureCall = await nativeTlsSession(call, id, servername);
|
|
63
|
+
}
|
|
64
|
+
return info;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (directTls)
|
|
68
|
+
throw new Error("proxy request failed, cannot connect to the specified address");
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function transport(call, id, host, secureTransport, open, connectionInfo) {
|
|
74
|
+
let upgraded = false;
|
|
75
|
+
let activeWrite;
|
|
31
76
|
let readableController;
|
|
32
77
|
let writableController;
|
|
33
78
|
let readEnded = false, writeEnded = false, stopped = false;
|
|
@@ -39,7 +84,7 @@ export function connect(address, options = {}) {
|
|
|
39
84
|
void closed.catch(() => { });
|
|
40
85
|
let terminal = false, readPending = false, pendingBytes = 0;
|
|
41
86
|
const notifyTerminal = () => {
|
|
42
|
-
if (!terminal || stopped || readPending || pendingBytes !== 0)
|
|
87
|
+
if (upgraded || !terminal || stopped || readPending || pendingBytes !== 0)
|
|
43
88
|
return;
|
|
44
89
|
if (!readEnded) {
|
|
45
90
|
readEnded = true;
|
|
@@ -48,10 +93,21 @@ export function connect(address, options = {}) {
|
|
|
48
93
|
resolveClosed();
|
|
49
94
|
};
|
|
50
95
|
let closing;
|
|
96
|
+
let openingStarted = false;
|
|
51
97
|
const close = () => {
|
|
98
|
+
if (upgraded)
|
|
99
|
+
return Promise.resolve();
|
|
52
100
|
if (!closing) {
|
|
53
101
|
stopped = true;
|
|
54
|
-
|
|
102
|
+
// workerd Socket::close waits for the direct TLS connection result. A
|
|
103
|
+
// STARTTLS socket exposes TCP establishment separately, so its close can
|
|
104
|
+
// interrupt authentication. Do not synthesize this ordering with timers.
|
|
105
|
+
const pendingConnection = secureTransport === "on" && !connectionInfo && openingStarted
|
|
106
|
+
? opened.catch(() => { })
|
|
107
|
+
: Promise.resolve();
|
|
108
|
+
closing = pendingConnection
|
|
109
|
+
.then(() => call("WorkersCapacitor", "socketClose", { id }))
|
|
110
|
+
.then(() => {
|
|
55
111
|
if (!readEnded) {
|
|
56
112
|
readEnded = true;
|
|
57
113
|
readableController.error(new Error("Socket closed"));
|
|
@@ -69,7 +125,7 @@ export function connect(address, options = {}) {
|
|
|
69
125
|
return closing;
|
|
70
126
|
};
|
|
71
127
|
const fail = (error) => {
|
|
72
|
-
if (!stopped) {
|
|
128
|
+
if (!stopped && !upgraded) {
|
|
73
129
|
readableController.error(error);
|
|
74
130
|
writableController.error(error);
|
|
75
131
|
rejectClosed(error);
|
|
@@ -84,12 +140,8 @@ export function connect(address, options = {}) {
|
|
|
84
140
|
.then(() => {
|
|
85
141
|
if (stopped)
|
|
86
142
|
throw new Error("Socket closed before connection");
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
host: url.hostname.replace(/^\[|\]$/g, ""),
|
|
90
|
-
port,
|
|
91
|
-
tls: options.secureTransport === "on",
|
|
92
|
-
});
|
|
143
|
+
openingStarted = true;
|
|
144
|
+
return open();
|
|
93
145
|
})
|
|
94
146
|
.then(async (value) => {
|
|
95
147
|
if (stopped) {
|
|
@@ -100,7 +152,7 @@ export function connect(address, options = {}) {
|
|
|
100
152
|
});
|
|
101
153
|
void opened
|
|
102
154
|
.then(async () => {
|
|
103
|
-
if (stopped)
|
|
155
|
+
if (stopped || upgraded)
|
|
104
156
|
return;
|
|
105
157
|
await call("WorkersCapacitor", "socketWatch", { id });
|
|
106
158
|
terminal = true;
|
|
@@ -116,12 +168,14 @@ export function connect(address, options = {}) {
|
|
|
116
168
|
const controller = genericController;
|
|
117
169
|
try {
|
|
118
170
|
await opened;
|
|
171
|
+
if (upgraded)
|
|
172
|
+
return;
|
|
119
173
|
readPending = true;
|
|
120
174
|
const result = (await call("WorkersCapacitor", "socketRead", {
|
|
121
175
|
id,
|
|
122
176
|
maxBytes: 65536,
|
|
123
177
|
}));
|
|
124
|
-
if (stopped)
|
|
178
|
+
if (stopped || upgraded)
|
|
125
179
|
return;
|
|
126
180
|
if (result.eof) {
|
|
127
181
|
if (!readEnded) {
|
|
@@ -156,20 +210,32 @@ export function connect(address, options = {}) {
|
|
|
156
210
|
writableController = controller;
|
|
157
211
|
},
|
|
158
212
|
async write(chunk) {
|
|
159
|
-
|
|
213
|
+
if (upgraded)
|
|
214
|
+
throw new Error("Socket has been upgraded");
|
|
215
|
+
const writing = (async () => {
|
|
160
216
|
await opened;
|
|
161
217
|
for (let offset = 0; offset < chunk.byteLength; offset += 65536)
|
|
162
218
|
await call("WorkersCapacitor", "socketWrite", {
|
|
163
219
|
id,
|
|
164
220
|
chunk: encoded(chunk.subarray(offset, offset + 65536)),
|
|
165
221
|
});
|
|
222
|
+
})();
|
|
223
|
+
activeWrite = writing;
|
|
224
|
+
try {
|
|
225
|
+
await writing;
|
|
166
226
|
}
|
|
167
227
|
catch (error) {
|
|
168
228
|
fail(error);
|
|
169
229
|
throw error;
|
|
170
230
|
}
|
|
231
|
+
finally {
|
|
232
|
+
if (activeWrite === writing)
|
|
233
|
+
activeWrite = undefined;
|
|
234
|
+
}
|
|
171
235
|
},
|
|
172
236
|
async close() {
|
|
237
|
+
if (upgraded)
|
|
238
|
+
throw new Error("Socket has been upgraded");
|
|
173
239
|
try {
|
|
174
240
|
await opened;
|
|
175
241
|
await call("WorkersCapacitor", "socketEnd", { id });
|
|
@@ -190,6 +256,79 @@ export function connect(address, options = {}) {
|
|
|
190
256
|
pendingBytes -= count;
|
|
191
257
|
notifyTerminal();
|
|
192
258
|
});
|
|
193
|
-
|
|
259
|
+
const socket = {
|
|
260
|
+
// Workers STARTTLS inherits the established TCP connection's opened
|
|
261
|
+
// notification. Reads, writes and the terminal watcher still await the
|
|
262
|
+
// private authenticated `opened` promise above.
|
|
263
|
+
opened: connectionInfo ?? opened,
|
|
264
|
+
closed,
|
|
265
|
+
readable,
|
|
266
|
+
writable,
|
|
267
|
+
close,
|
|
268
|
+
secureTransport,
|
|
269
|
+
startTls(options = {}) {
|
|
270
|
+
if (upgraded ||
|
|
271
|
+
stopped ||
|
|
272
|
+
secureTransport !== "starttls" ||
|
|
273
|
+
readEnded ||
|
|
274
|
+
writeEnded)
|
|
275
|
+
throw new Error("Socket cannot be upgraded");
|
|
276
|
+
upgraded = true;
|
|
277
|
+
socket.upgraded = true;
|
|
278
|
+
const error = new Error("Socket has been upgraded");
|
|
279
|
+
readableController.error(error);
|
|
280
|
+
writableController.error(error);
|
|
281
|
+
resolveClosed();
|
|
282
|
+
let secureCall = call;
|
|
283
|
+
let tlsFailed = false;
|
|
284
|
+
const failedOperation = (method) => {
|
|
285
|
+
if (method === "socketRead")
|
|
286
|
+
return { eof: true };
|
|
287
|
+
if (method === "socketWatch" || method === "socketEnd")
|
|
288
|
+
return {};
|
|
289
|
+
throw new Error("Network connection lost.");
|
|
290
|
+
};
|
|
291
|
+
return transport(async (...args) => {
|
|
292
|
+
const method = args[1];
|
|
293
|
+
const io = [
|
|
294
|
+
"socketRead",
|
|
295
|
+
"socketWatch",
|
|
296
|
+
"socketWrite",
|
|
297
|
+
"socketEnd",
|
|
298
|
+
].includes(method);
|
|
299
|
+
if (tlsFailed && io)
|
|
300
|
+
return failedOperation(method);
|
|
301
|
+
try {
|
|
302
|
+
return await secureCall(...args);
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
if (!io)
|
|
306
|
+
throw error;
|
|
307
|
+
// Workers STARTTLS exposes transport/TLS failure as readable EOF,
|
|
308
|
+
// while writes fail. Never forward application bytes after a
|
|
309
|
+
// failed handshake; close still reaches the native resource.
|
|
310
|
+
tlsFailed = true;
|
|
311
|
+
return failedOperation(method);
|
|
312
|
+
}
|
|
313
|
+
}, id, host, "on", async () => {
|
|
314
|
+
const info = await opened;
|
|
315
|
+
await activeWrite;
|
|
316
|
+
const hostname = options.expectedServerHostname ?? host;
|
|
317
|
+
try {
|
|
318
|
+
const result = (await call("WorkersCapacitor", "socketStartTls", {
|
|
319
|
+
id,
|
|
320
|
+
servername: hostname,
|
|
321
|
+
}));
|
|
322
|
+
if (result?.tlsEngine === "openssl-wasm")
|
|
323
|
+
secureCall = await nativeTlsSession(call, id, hostname);
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
tlsFailed = true;
|
|
327
|
+
}
|
|
328
|
+
return info;
|
|
329
|
+
}, opened);
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
return socket;
|
|
194
333
|
}
|
|
195
334
|
export default { connect };
|
|
@@ -2,6 +2,7 @@ export declare function isInt32(value: unknown): value is number;
|
|
|
2
2
|
export declare function isUint32(value: unknown): value is number;
|
|
3
3
|
export declare function validateObject<T extends object>(value: T | null | undefined, name: string, options?: number): asserts value is T;
|
|
4
4
|
export declare function validateObject(value: unknown, name: string, options?: number): asserts value is Record<string, unknown>;
|
|
5
|
+
export declare function validateInteger(value: unknown, name: string, min?: number, max?: number): asserts value is number;
|
|
5
6
|
export declare function validateInt32(value: unknown, name: string, min?: number, max?: number): asserts value is number;
|
|
6
7
|
export declare function validateUint32(value: unknown, name: string, positive?: boolean): asserts value is number;
|
|
7
8
|
export declare function validateString(value: unknown, name: string): asserts value is string;
|
|
@@ -61,6 +61,14 @@ export function validateObject(value, name, options = kValidateObjectNone) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
export function validateInteger(value, name, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
|
|
65
|
+
if (typeof value !== "number")
|
|
66
|
+
throw new ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
67
|
+
if (!Number.isInteger(value))
|
|
68
|
+
throw new ERR_OUT_OF_RANGE(name, "an integer", value);
|
|
69
|
+
if (value < min || value > max)
|
|
70
|
+
throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
|
|
71
|
+
}
|
|
64
72
|
export function validateInt32(value, name, min = -2147483648, max = 2147483647) {
|
|
65
73
|
if (!isInt32(value)) {
|
|
66
74
|
if (typeof value !== "number") {
|