cf-workers-native 0.1.4 → 0.1.5

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.
Files changed (161) hide show
  1. package/dist/browser/documents/page-source.js +1 -1
  2. package/dist/browser/fetch/host-call.js +6 -1
  3. package/dist/browser/fetch/native-network.d.ts +1 -1
  4. package/dist/browser/fetch/relay.js +2 -0
  5. package/dist/browser/isolated/transport.js +3 -2
  6. package/dist/browser/request/index.js +3 -2
  7. package/dist/cloudflare/workers/worker-runtime.js +2 -1
  8. package/dist/compat/console/index.d.ts +35 -0
  9. package/dist/compat/console/index.js +92 -0
  10. package/dist/compat/crypto/LICENSE-3RD-PARTY.md +19 -0
  11. package/dist/compat/crypto/LICENSE-APACHE +177 -0
  12. package/dist/compat/crypto/LICENSE.emscripten +102 -0
  13. package/dist/compat/crypto/LICENSE.musl +193 -0
  14. package/dist/compat/crypto/LICENSE.openssl +177 -0
  15. package/dist/compat/crypto/asymmetric.d.ts +13 -0
  16. package/dist/compat/crypto/asymmetric.js +239 -0
  17. package/dist/compat/crypto/brorand.cjs +74 -0
  18. package/dist/compat/crypto/brorand.d.cts +6 -0
  19. package/dist/compat/crypto/certificate.d.ts +14 -0
  20. package/dist/compat/crypto/certificate.js +66 -0
  21. package/dist/compat/crypto/ecdh.d.ts +15 -0
  22. package/dist/compat/crypto/ecdh.js +109 -0
  23. package/dist/compat/crypto/hkdf.d.ts +2 -0
  24. package/dist/compat/crypto/hkdf.js +52 -0
  25. package/dist/compat/crypto/index.cjs +2 -0
  26. package/dist/compat/crypto/index.d.cts +2 -0
  27. package/dist/compat/crypto/index.d.ts +30 -0
  28. package/dist/compat/crypto/index.js +83 -0
  29. package/dist/compat/crypto/key-formats.d.ts +6 -0
  30. package/dist/compat/crypto/key-formats.js +120 -0
  31. package/dist/compat/crypto/key-state.d.ts +9 -0
  32. package/dist/compat/crypto/key-state.js +4 -0
  33. package/dist/compat/crypto/keys.d.ts +50 -0
  34. package/dist/compat/crypto/keys.js +209 -0
  35. package/dist/compat/crypto/metadata.d.ts +4 -0
  36. package/dist/compat/crypto/metadata.js +22 -0
  37. package/dist/compat/crypto/native-crypto.d.ts +68 -0
  38. package/dist/compat/crypto/native-crypto.js +569 -0
  39. package/dist/compat/crypto/prime.d.ts +19 -0
  40. package/dist/compat/crypto/prime.js +146 -0
  41. package/dist/compat/crypto/random.d.ts +7 -0
  42. package/dist/compat/crypto/random.js +123 -0
  43. package/dist/compat/crypto/rsa.d.ts +5 -0
  44. package/dist/compat/crypto/rsa.js +173 -0
  45. package/dist/compat/crypto/scrypt.d.ts +25 -0
  46. package/dist/compat/crypto/scrypt.js +150 -0
  47. package/dist/compat/crypto/sign-errors.d.ts +8 -0
  48. package/dist/compat/crypto/sign-errors.js +13 -0
  49. package/dist/compat/crypto/sign-handle.d.ts +22 -0
  50. package/dist/compat/crypto/sign-handle.js +105 -0
  51. package/dist/compat/crypto/signatures.d.ts +28 -0
  52. package/dist/compat/crypto/signatures.js +252 -0
  53. package/dist/compat/crypto/symmetric.d.ts +29 -0
  54. package/dist/compat/crypto/symmetric.js +104 -0
  55. package/dist/compat/crypto/validation.d.ts +3 -0
  56. package/dist/compat/crypto/validation.js +19 -0
  57. package/dist/compat/crypto/x509.d.ts +30 -0
  58. package/dist/compat/crypto/x509.js +406 -0
  59. package/dist/compat/events/errors.d.ts +8 -0
  60. package/dist/compat/events/errors.js +39 -0
  61. package/dist/compat/events/index.cjs +2 -0
  62. package/dist/compat/events/index.d.cts +2 -0
  63. package/dist/compat/events/index.d.ts +64 -0
  64. package/dist/compat/events/index.js +792 -0
  65. package/dist/compat/events/intrinsics.d.ts +1 -0
  66. package/dist/compat/events/intrinsics.js +2 -0
  67. package/dist/compat/fs/embedded.d.ts +85 -0
  68. package/dist/compat/fs/embedded.js +255 -0
  69. package/dist/compat/fs/index.d.ts +7 -84
  70. package/dist/compat/fs/index.js +218 -252
  71. package/dist/compat/fs/mode.d.ts +1 -0
  72. package/dist/compat/fs/mode.js +13 -0
  73. package/dist/compat/fs/promises/index.d.ts +1 -1
  74. package/dist/compat/fs/promises/index.js +1 -1
  75. package/dist/compat/fs/writable.d.ts +6 -0
  76. package/dist/compat/fs/writable.js +142 -0
  77. package/dist/compat/http/symbols.d.ts +5 -0
  78. package/dist/compat/http/symbols.js +9 -0
  79. package/dist/compat/http-common/index.d.ts +37 -0
  80. package/dist/compat/http-common/index.js +43 -0
  81. package/dist/compat/http-outgoing/index.d.ts +13 -0
  82. package/dist/compat/http-outgoing/index.js +32 -0
  83. package/dist/compat/http-server/index.d.ts +18 -0
  84. package/dist/compat/http-server/index.js +107 -0
  85. package/dist/compat/module/builtins.d.ts +1 -0
  86. package/dist/compat/module/builtins.js +101 -0
  87. package/dist/compat/module/index.d.ts +4 -2
  88. package/dist/compat/module/index.js +22 -17
  89. package/dist/compat/module/metadata.d.ts +44 -0
  90. package/dist/compat/module/metadata.js +127 -0
  91. package/dist/compat/net/internal-net.js +4 -0
  92. package/dist/compat/net/sockets.d.ts +5 -0
  93. package/dist/compat/net/sockets.js +74 -13
  94. package/dist/compat/process/index.cjs +2 -0
  95. package/dist/compat/process/index.d.cts +4 -0
  96. package/dist/compat/process/index.d.ts +18 -0
  97. package/dist/compat/process/index.js +140 -0
  98. package/dist/compat/process/metadata.d.ts +135 -0
  99. package/dist/compat/process/metadata.js +251 -0
  100. package/dist/compat/process/state.d.ts +4 -0
  101. package/dist/compat/process/state.js +4 -0
  102. package/dist/compat/stream-web/LICENSE +22 -0
  103. package/dist/compat/stream-web/ponyfill.d.ts +1 -1
  104. package/dist/compat/stream-web/ponyfill.js +2369 -1775
  105. package/dist/compat/stream-web/runtime.d.ts +1 -1
  106. package/dist/compat/stream-web/runtime.js +3 -2
  107. package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
  108. package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
  109. package/dist/compat/stream-wrap/index.d.ts +1 -0
  110. package/dist/compat/stream-wrap/index.js +1 -0
  111. package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
  112. package/dist/compat/tls/LICENSE-APACHE +177 -0
  113. package/dist/compat/tls/constants.d.ts +7 -0
  114. package/dist/compat/tls/constants.js +14 -0
  115. package/dist/compat/tls/errors.d.ts +35 -0
  116. package/dist/compat/tls/errors.js +68 -0
  117. package/dist/compat/tls/helpers.d.ts +9 -0
  118. package/dist/compat/tls/helpers.js +207 -0
  119. package/dist/compat/tls/index.d.ts +26 -0
  120. package/dist/compat/tls/index.js +50 -0
  121. package/dist/compat/tls/jsstream.d.ts +19 -0
  122. package/dist/compat/tls/jsstream.js +186 -0
  123. package/dist/compat/tls/native-session.d.ts +3 -0
  124. package/dist/compat/tls/native-session.js +187 -0
  125. package/dist/compat/tls/wrap.d.ts +65 -0
  126. package/dist/compat/tls/wrap.js +544 -0
  127. package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
  128. package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
  129. package/dist/compat/tls-wrap/index.d.ts +7 -0
  130. package/dist/compat/tls-wrap/index.js +3 -0
  131. package/dist/compat/util/index.js +43 -1
  132. package/dist/compat/util/types/index.d.ts +3 -0
  133. package/dist/compat/util/types/index.js +5 -0
  134. package/dist/compat/zlib/LICENSE.brotli +19 -0
  135. package/dist/compat/zlib/LICENSE.emscripten +102 -0
  136. package/dist/compat/zlib/LICENSE.musl +193 -0
  137. package/dist/compat/zlib/LICENSE.zstd +30 -0
  138. package/dist/compat/zlib/compression.d.ts +55 -0
  139. package/dist/compat/zlib/compression.js +259 -0
  140. package/dist/compat/zlib/constants.d.ts +172 -0
  141. package/dist/compat/zlib/constants.js +173 -0
  142. package/dist/compat/zlib/index.d.ts +180 -0
  143. package/dist/compat/zlib/index.js +177 -0
  144. package/dist/compat/zlib/native-codecs.d.ts +17 -0
  145. package/dist/compat/zlib/native-codecs.js +168 -0
  146. package/dist/shared/globals/inject.d.ts +2 -1
  147. package/dist/shared/globals/inject.js +2 -1
  148. package/dist/shared/globals/runtime.d.ts +1 -2
  149. package/dist/shared/globals/runtime.js +1 -2
  150. package/dist/shared/request-scope.d.ts +4 -0
  151. package/dist/shared/request-scope.js +11 -0
  152. package/dist/tooling/async.js +36 -14
  153. package/dist/tooling/shared.d.ts +1 -0
  154. package/dist/tooling/shared.js +20 -1
  155. package/dist/tooling/vite.js +4 -3
  156. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +56 -8
  157. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
  158. package/native/ios/NetworkBridge.swift +11 -1
  159. package/native/ios/SocketBridge.swift +37 -2
  160. package/native/ios/WorkersCapacitorPlugin.swift +4 -0
  161. package/package.json +3 -1
@@ -0,0 +1,9 @@
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
+ // Copyright Joyent and Node contributors. All rights reserved. MIT license.
5
+ export const kIncomingMessage = Symbol("IncomingMessage");
6
+ export const kServerResponse = Symbol("ServerResponse");
7
+ export const kUniqueHeaders = Symbol("kUniqueHeaders");
8
+ export const kHighWaterMark = Symbol("kHighWaterMark");
9
+ export const kConnectionsCheckingInterval = Symbol("http.server.connectionsCheckingInterval");
@@ -0,0 +1,37 @@
1
+ import { METHODS as methods } from "../http/index.js";
2
+ import { kIncomingMessage } from "../http/symbols.js";
3
+ export { methods, kIncomingMessage };
4
+ /**
5
+ * Verifies that the given val is a valid HTTP token
6
+ * per the rules defined in RFC 7230
7
+ * See https://tools.ietf.org/html/rfc7230#section-3.2.6
8
+ */
9
+ export declare function _checkIsHttpToken(val: string): boolean;
10
+ /**
11
+ * True if val contains an invalid field-vchar
12
+ * field-value = *( field-content / obs-fold )
13
+ * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
14
+ * field-vchar = VCHAR / obs-text
15
+ */
16
+ export declare function _checkInvalidHeaderChar(val: number | string | ReadonlyArray<string>): boolean;
17
+ export declare const CRLF = "\r\n";
18
+ export declare const chunkExpression: RegExp;
19
+ export declare const continueExpression: RegExp;
20
+ export declare const parsers: {
21
+ name: string;
22
+ max: number;
23
+ };
24
+ declare const _default: {
25
+ _checkIsHttpToken: typeof _checkIsHttpToken;
26
+ _checkInvalidHeaderChar: typeof _checkInvalidHeaderChar;
27
+ chunkExpression: RegExp;
28
+ kIncomingMessage: symbol;
29
+ CRLF: string;
30
+ continueExpression: RegExp;
31
+ methods: string[];
32
+ parsers: {
33
+ name: string;
34
+ max: number;
35
+ };
36
+ };
37
+ export default _default;
@@ -0,0 +1,43 @@
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
+ // Copyright Joyent and Node contributors. All rights reserved. MIT license.
5
+ import { METHODS as methods } from "../http/index.js";
6
+ import { kIncomingMessage } from "../http/symbols.js";
7
+ export { methods, kIncomingMessage };
8
+ const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
9
+ /**
10
+ * Verifies that the given val is a valid HTTP token
11
+ * per the rules defined in RFC 7230
12
+ * See https://tools.ietf.org/html/rfc7230#section-3.2.6
13
+ */
14
+ export function _checkIsHttpToken(val) {
15
+ return tokenRegExp.test(val);
16
+ }
17
+ const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
18
+ /**
19
+ * True if val contains an invalid field-vchar
20
+ * field-value = *( field-content / obs-fold )
21
+ * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
22
+ * field-vchar = VCHAR / obs-text
23
+ */
24
+ export function _checkInvalidHeaderChar(val) {
25
+ if (Array.isArray(val)) {
26
+ return val.some((v) => headerCharRegex.test(v));
27
+ }
28
+ return headerCharRegex.test(`${val}`);
29
+ }
30
+ export const CRLF = "\r\n";
31
+ export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
32
+ export const continueExpression = /(?:^|\W)100-continue(?:$|\W)/i;
33
+ export const parsers = { name: "parsers", max: 1000 };
34
+ export default {
35
+ _checkIsHttpToken,
36
+ _checkInvalidHeaderChar,
37
+ chunkExpression,
38
+ kIncomingMessage,
39
+ CRLF,
40
+ continueExpression,
41
+ methods,
42
+ parsers,
43
+ };
@@ -0,0 +1,13 @@
1
+ import { OutgoingMessage, validateHeaderName, validateHeaderValue } from "../http/index.js";
2
+ import { kUniqueHeaders, kHighWaterMark } from "../http/symbols.js";
3
+ export { OutgoingMessage, validateHeaderName, validateHeaderValue, kUniqueHeaders, kHighWaterMark, };
4
+ export declare function parseUniqueHeadersOption(headers?: (string | string[])[]): Set<string> | null;
5
+ declare const _default: {
6
+ OutgoingMessage: typeof OutgoingMessage;
7
+ validateHeaderName: typeof validateHeaderName;
8
+ validateHeaderValue: typeof validateHeaderValue;
9
+ kUniqueHeaders: symbol;
10
+ kHighWaterMark: symbol;
11
+ parseUniqueHeadersOption: typeof parseUniqueHeadersOption;
12
+ };
13
+ export default _default;
@@ -0,0 +1,32 @@
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
+ // Copyright Joyent and Node contributors. All rights reserved. MIT license.
5
+ import { OutgoingMessage, validateHeaderName, validateHeaderValue, } from "../http/index.js";
6
+ import { kUniqueHeaders, kHighWaterMark } from "../http/symbols.js";
7
+ export { OutgoingMessage, validateHeaderName, validateHeaderValue, kUniqueHeaders, kHighWaterMark, };
8
+ export function parseUniqueHeadersOption(headers) {
9
+ if (!Array.isArray(headers)) {
10
+ return null;
11
+ }
12
+ const unique = new Set();
13
+ for (const header of headers) {
14
+ if (Array.isArray(header)) {
15
+ for (const h of header) {
16
+ unique.add(h.toLowerCase());
17
+ }
18
+ }
19
+ else {
20
+ unique.add(header.toLowerCase());
21
+ }
22
+ }
23
+ return unique;
24
+ }
25
+ export default {
26
+ OutgoingMessage,
27
+ validateHeaderName,
28
+ validateHeaderValue,
29
+ kUniqueHeaders,
30
+ kHighWaterMark,
31
+ parseUniqueHeadersOption,
32
+ };
@@ -0,0 +1,18 @@
1
+ import { Server, ServerResponse, STATUS_CODES, _connectionListener } from "../http/index.js";
2
+ import { kServerResponse, kConnectionsCheckingInterval } from "../http/symbols.js";
3
+ export { Server, ServerResponse, STATUS_CODES, kServerResponse, kConnectionsCheckingInterval, _connectionListener, };
4
+ export declare function setupConnectionsTracking(): never;
5
+ export declare function storeHTTPOptions(this: any, options: any): void;
6
+ export declare function httpServerPreClose(server: any): void;
7
+ declare const _default: {
8
+ Server: typeof Server;
9
+ ServerResponse: typeof ServerResponse;
10
+ STATUS_CODES: Record<number, string>;
11
+ kServerResponse: symbol;
12
+ kConnectionsCheckingInterval: symbol;
13
+ _connectionListener: typeof _connectionListener;
14
+ setupConnectionsTracking: typeof setupConnectionsTracking;
15
+ storeHTTPOptions: typeof storeHTTPOptions;
16
+ httpServerPreClose: typeof httpServerPreClose;
17
+ };
18
+ export default _default;
@@ -0,0 +1,107 @@
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
+ // Copyright Joyent and Node contributors. All rights reserved. MIT license.
5
+ import { Server, ServerResponse, IncomingMessage, STATUS_CODES, _connectionListener, } from "../http/index.js";
6
+ import { kIncomingMessage, kServerResponse, kConnectionsCheckingInterval, } from "../http/symbols.js";
7
+ import { validateInteger } from "../crypto/validation.js";
8
+ import { validateBoolean } from "../net/validators.js";
9
+ import { ERR_OUT_OF_RANGE } from "../net/errors.js";
10
+ class ERR_OPTION_NOT_IMPLEMENTED extends Error {
11
+ code = "ERR_OPTION_NOT_IMPLEMENTED";
12
+ constructor(option) {
13
+ super(`The ${option} option is not implemented`);
14
+ }
15
+ }
16
+ export { Server, ServerResponse, STATUS_CODES, kServerResponse, kConnectionsCheckingInterval, _connectionListener, };
17
+ export function setupConnectionsTracking() {
18
+ throw Object.assign(new Error("The setupConnectionsTracking method is not implemented"), { code: "ERR_METHOD_NOT_IMPLEMENTED" });
19
+ }
20
+ export function storeHTTPOptions(options) {
21
+ this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
22
+ this[kServerResponse] = options.ServerResponse || ServerResponse;
23
+ const maxHeaderSize = options.maxHeaderSize;
24
+ if (maxHeaderSize !== undefined) {
25
+ validateInteger(maxHeaderSize, "maxHeaderSize", 0);
26
+ throw new ERR_OPTION_NOT_IMPLEMENTED("maxHeaderSize");
27
+ }
28
+ const insecureHTTPParser = options.insecureHTTPParser;
29
+ if (insecureHTTPParser !== undefined) {
30
+ // If enabled it will use a HTTP parser with leniency flags enabled.
31
+ // Since our implementation does not use any http parser, and uses "fetch" API,
32
+ // it doesn't make sense to support this option.
33
+ validateBoolean(insecureHTTPParser, "options.insecureHTTPParser");
34
+ }
35
+ const requestTimeout = options.requestTimeout;
36
+ if (requestTimeout !== undefined) {
37
+ validateInteger(requestTimeout, "requestTimeout", 0);
38
+ this.requestTimeout = requestTimeout;
39
+ }
40
+ else {
41
+ this.requestTimeout = 300_000; // 5 minutes
42
+ }
43
+ const headersTimeout = options.headersTimeout;
44
+ if (headersTimeout !== undefined) {
45
+ validateInteger(headersTimeout, "headersTimeout", 0);
46
+ this.headersTimeout = headersTimeout;
47
+ }
48
+ else {
49
+ this.headersTimeout = Math.min(60_000, this.requestTimeout); // Minimum between 60 seconds or requestTimeout
50
+ }
51
+ if (this.requestTimeout > 0 &&
52
+ this.headersTimeout > 0 &&
53
+ this.headersTimeout > this.requestTimeout) {
54
+ throw new ERR_OUT_OF_RANGE("headersTimeout", "<= requestTimeout", headersTimeout);
55
+ }
56
+ const keepAliveTimeout = options.keepAliveTimeout;
57
+ if (keepAliveTimeout !== undefined) {
58
+ validateInteger(keepAliveTimeout, "keepAliveTimeout", 0);
59
+ throw new ERR_OPTION_NOT_IMPLEMENTED("keepAliveTimeout");
60
+ }
61
+ const keepAliveTimeoutBuffer = options.keepAliveTimeoutBuffer;
62
+ if (keepAliveTimeoutBuffer !== undefined) {
63
+ validateInteger(keepAliveTimeoutBuffer, "keepAliveTimeoutBuffer");
64
+ throw new ERR_OPTION_NOT_IMPLEMENTED("keepAliveTimeoutBuffer");
65
+ }
66
+ const connectionsCheckingInterval = options.connectionsCheckingInterval;
67
+ if (connectionsCheckingInterval !== undefined) {
68
+ validateInteger(connectionsCheckingInterval, "connectionsCheckingInterval", 0);
69
+ throw new ERR_OPTION_NOT_IMPLEMENTED("connectionsCheckingInterval");
70
+ }
71
+ const requireHostHeader = options.requireHostHeader;
72
+ if (requireHostHeader !== undefined) {
73
+ validateBoolean(requireHostHeader, "options.requireHostHeader");
74
+ this.requireHostHeader = requireHostHeader;
75
+ }
76
+ else {
77
+ this.requireHostHeader = true;
78
+ }
79
+ const joinDuplicateHeaders = options.joinDuplicateHeaders;
80
+ if (joinDuplicateHeaders !== undefined) {
81
+ validateBoolean(joinDuplicateHeaders, "options.joinDuplicateHeaders");
82
+ }
83
+ this.joinDuplicateHeaders = joinDuplicateHeaders ?? false;
84
+ const rejectNonStandardBodyWrites = options.rejectNonStandardBodyWrites;
85
+ if (rejectNonStandardBodyWrites !== undefined) {
86
+ validateBoolean(rejectNonStandardBodyWrites, "options.rejectNonStandardBodyWrites");
87
+ this.rejectNonStandardBodyWrites = rejectNonStandardBodyWrites;
88
+ }
89
+ else {
90
+ this.rejectNonStandardBodyWrites = false;
91
+ }
92
+ }
93
+ export function httpServerPreClose(server) {
94
+ server.closeIdleConnections();
95
+ clearInterval(server[kConnectionsCheckingInterval]);
96
+ }
97
+ export default {
98
+ Server,
99
+ ServerResponse,
100
+ STATUS_CODES,
101
+ kServerResponse,
102
+ kConnectionsCheckingInterval,
103
+ _connectionListener,
104
+ setupConnectionsTracking,
105
+ storeHTTPOptions,
106
+ httpServerPreClose,
107
+ };
@@ -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
- export declare const builtinModules: string[];
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(_filename: string | URL): (id: string) => unknown;
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
- export const builtinModules = [
6
- "async_hooks",
7
- "buffer",
8
- "fs",
9
- "fs/promises",
10
- "http",
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(_filename) {
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, { encoding: "utf8" });
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;