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.
- 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/isolated/transport.js +3 -2
- package/dist/browser/request/index.js +3 -2
- 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 +19 -0
- package/dist/compat/crypto/LICENSE-APACHE +177 -0
- package/dist/compat/crypto/LICENSE.emscripten +102 -0
- package/dist/compat/crypto/LICENSE.musl +193 -0
- package/dist/compat/crypto/LICENSE.openssl +177 -0
- package/dist/compat/crypto/asymmetric.d.ts +13 -0
- package/dist/compat/crypto/asymmetric.js +239 -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/ecdh.d.ts +15 -0
- package/dist/compat/crypto/ecdh.js +109 -0
- package/dist/compat/crypto/hkdf.d.ts +2 -0
- package/dist/compat/crypto/hkdf.js +52 -0
- package/dist/compat/crypto/index.cjs +2 -0
- package/dist/compat/crypto/index.d.cts +2 -0
- package/dist/compat/crypto/index.d.ts +30 -0
- package/dist/compat/crypto/index.js +83 -0
- package/dist/compat/crypto/key-formats.d.ts +6 -0
- package/dist/compat/crypto/key-formats.js +120 -0
- package/dist/compat/crypto/key-state.d.ts +9 -0
- package/dist/compat/crypto/key-state.js +4 -0
- package/dist/compat/crypto/keys.d.ts +50 -0
- package/dist/compat/crypto/keys.js +209 -0
- package/dist/compat/crypto/metadata.d.ts +4 -0
- package/dist/compat/crypto/metadata.js +22 -0
- package/dist/compat/crypto/native-crypto.d.ts +68 -0
- package/dist/compat/crypto/native-crypto.js +569 -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 +7 -0
- package/dist/compat/crypto/random.js +123 -0
- package/dist/compat/crypto/rsa.d.ts +5 -0
- package/dist/compat/crypto/rsa.js +173 -0
- package/dist/compat/crypto/scrypt.d.ts +25 -0
- package/dist/compat/crypto/scrypt.js +150 -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 +105 -0
- package/dist/compat/crypto/signatures.d.ts +28 -0
- package/dist/compat/crypto/signatures.js +252 -0
- package/dist/compat/crypto/symmetric.d.ts +29 -0
- package/dist/compat/crypto/symmetric.js +104 -0
- package/dist/compat/crypto/validation.d.ts +3 -0
- package/dist/compat/crypto/validation.js +19 -0
- package/dist/compat/crypto/x509.d.ts +30 -0
- package/dist/compat/crypto/x509.js +406 -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/embedded.d.ts +85 -0
- package/dist/compat/fs/embedded.js +255 -0
- package/dist/compat/fs/index.d.ts +7 -84
- package/dist/compat/fs/index.js +218 -252
- 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 +1 -1
- package/dist/compat/fs/promises/index.js +1 -1
- package/dist/compat/fs/writable.d.ts +6 -0
- package/dist/compat/fs/writable.js +142 -0
- package/dist/compat/http/symbols.d.ts +5 -0
- package/dist/compat/http/symbols.js +9 -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 +13 -0
- package/dist/compat/http-outgoing/index.js +32 -0
- package/dist/compat/http-server/index.d.ts +18 -0
- package/dist/compat/http-server/index.js +107 -0
- 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 +74 -13
- package/dist/compat/process/index.cjs +2 -0
- package/dist/compat/process/index.d.cts +4 -0
- package/dist/compat/process/index.d.ts +18 -0
- package/dist/compat/process/index.js +140 -0
- package/dist/compat/process/metadata.d.ts +135 -0
- package/dist/compat/process/metadata.js +251 -0
- package/dist/compat/process/state.d.ts +4 -0
- package/dist/compat/process/state.js +4 -0
- 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 +186 -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 +544 -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/types/index.d.ts +3 -0
- package/dist/compat/util/types/index.js +5 -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.zstd +30 -0
- package/dist/compat/zlib/compression.d.ts +55 -0
- package/dist/compat/zlib/compression.js +259 -0
- package/dist/compat/zlib/constants.d.ts +172 -0
- package/dist/compat/zlib/constants.js +173 -0
- package/dist/compat/zlib/index.d.ts +180 -0
- package/dist/compat/zlib/index.js +177 -0
- package/dist/compat/zlib/native-codecs.d.ts +17 -0
- package/dist/compat/zlib/native-codecs.js +168 -0
- package/dist/shared/globals/inject.d.ts +2 -1
- package/dist/shared/globals/inject.js +2 -1
- package/dist/shared/globals/runtime.d.ts +1 -2
- package/dist/shared/globals/runtime.js +1 -2
- package/dist/shared/request-scope.d.ts +4 -0
- package/dist/shared/request-scope.js +11 -0
- package/dist/tooling/async.js +36 -14
- package/dist/tooling/shared.d.ts +1 -0
- package/dist/tooling/shared.js +20 -1
- package/dist/tooling/vite.js +4 -3
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +56 -8
- 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 +3 -1
|
@@ -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,20 @@ 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
|
+
return transport(call, id, host, options.secureTransport ?? "off", () => call("WorkersCapacitor", "socketOpen", {
|
|
34
|
+
id,
|
|
35
|
+
host,
|
|
36
|
+
port,
|
|
37
|
+
tls: options.secureTransport === "on",
|
|
38
|
+
...(options.expectedServerHostname
|
|
39
|
+
? { servername: options.expectedServerHostname }
|
|
40
|
+
: {}),
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
function transport(call, id, host, secureTransport, open) {
|
|
44
|
+
let upgraded = false;
|
|
45
|
+
let activeWrite;
|
|
31
46
|
let readableController;
|
|
32
47
|
let writableController;
|
|
33
48
|
let readEnded = false, writeEnded = false, stopped = false;
|
|
@@ -39,7 +54,7 @@ export function connect(address, options = {}) {
|
|
|
39
54
|
void closed.catch(() => { });
|
|
40
55
|
let terminal = false, readPending = false, pendingBytes = 0;
|
|
41
56
|
const notifyTerminal = () => {
|
|
42
|
-
if (!terminal || stopped || readPending || pendingBytes !== 0)
|
|
57
|
+
if (upgraded || !terminal || stopped || readPending || pendingBytes !== 0)
|
|
43
58
|
return;
|
|
44
59
|
if (!readEnded) {
|
|
45
60
|
readEnded = true;
|
|
@@ -49,6 +64,8 @@ export function connect(address, options = {}) {
|
|
|
49
64
|
};
|
|
50
65
|
let closing;
|
|
51
66
|
const close = () => {
|
|
67
|
+
if (upgraded)
|
|
68
|
+
return Promise.resolve();
|
|
52
69
|
if (!closing) {
|
|
53
70
|
stopped = true;
|
|
54
71
|
closing = call("WorkersCapacitor", "socketClose", { id }).then(() => {
|
|
@@ -69,7 +86,7 @@ export function connect(address, options = {}) {
|
|
|
69
86
|
return closing;
|
|
70
87
|
};
|
|
71
88
|
const fail = (error) => {
|
|
72
|
-
if (!stopped) {
|
|
89
|
+
if (!stopped && !upgraded) {
|
|
73
90
|
readableController.error(error);
|
|
74
91
|
writableController.error(error);
|
|
75
92
|
rejectClosed(error);
|
|
@@ -84,12 +101,7 @@ export function connect(address, options = {}) {
|
|
|
84
101
|
.then(() => {
|
|
85
102
|
if (stopped)
|
|
86
103
|
throw new Error("Socket closed before connection");
|
|
87
|
-
return
|
|
88
|
-
id,
|
|
89
|
-
host: url.hostname.replace(/^\[|\]$/g, ""),
|
|
90
|
-
port,
|
|
91
|
-
tls: options.secureTransport === "on",
|
|
92
|
-
});
|
|
104
|
+
return open();
|
|
93
105
|
})
|
|
94
106
|
.then(async (value) => {
|
|
95
107
|
if (stopped) {
|
|
@@ -100,7 +112,7 @@ export function connect(address, options = {}) {
|
|
|
100
112
|
});
|
|
101
113
|
void opened
|
|
102
114
|
.then(async () => {
|
|
103
|
-
if (stopped)
|
|
115
|
+
if (stopped || upgraded)
|
|
104
116
|
return;
|
|
105
117
|
await call("WorkersCapacitor", "socketWatch", { id });
|
|
106
118
|
terminal = true;
|
|
@@ -116,12 +128,14 @@ export function connect(address, options = {}) {
|
|
|
116
128
|
const controller = genericController;
|
|
117
129
|
try {
|
|
118
130
|
await opened;
|
|
131
|
+
if (upgraded)
|
|
132
|
+
return;
|
|
119
133
|
readPending = true;
|
|
120
134
|
const result = (await call("WorkersCapacitor", "socketRead", {
|
|
121
135
|
id,
|
|
122
136
|
maxBytes: 65536,
|
|
123
137
|
}));
|
|
124
|
-
if (stopped)
|
|
138
|
+
if (stopped || upgraded)
|
|
125
139
|
return;
|
|
126
140
|
if (result.eof) {
|
|
127
141
|
if (!readEnded) {
|
|
@@ -156,20 +170,32 @@ export function connect(address, options = {}) {
|
|
|
156
170
|
writableController = controller;
|
|
157
171
|
},
|
|
158
172
|
async write(chunk) {
|
|
159
|
-
|
|
173
|
+
if (upgraded)
|
|
174
|
+
throw new Error("Socket has been upgraded");
|
|
175
|
+
const writing = (async () => {
|
|
160
176
|
await opened;
|
|
161
177
|
for (let offset = 0; offset < chunk.byteLength; offset += 65536)
|
|
162
178
|
await call("WorkersCapacitor", "socketWrite", {
|
|
163
179
|
id,
|
|
164
180
|
chunk: encoded(chunk.subarray(offset, offset + 65536)),
|
|
165
181
|
});
|
|
182
|
+
})();
|
|
183
|
+
activeWrite = writing;
|
|
184
|
+
try {
|
|
185
|
+
await writing;
|
|
166
186
|
}
|
|
167
187
|
catch (error) {
|
|
168
188
|
fail(error);
|
|
169
189
|
throw error;
|
|
170
190
|
}
|
|
191
|
+
finally {
|
|
192
|
+
if (activeWrite === writing)
|
|
193
|
+
activeWrite = undefined;
|
|
194
|
+
}
|
|
171
195
|
},
|
|
172
196
|
async close() {
|
|
197
|
+
if (upgraded)
|
|
198
|
+
throw new Error("Socket has been upgraded");
|
|
173
199
|
try {
|
|
174
200
|
await opened;
|
|
175
201
|
await call("WorkersCapacitor", "socketEnd", { id });
|
|
@@ -190,6 +216,41 @@ export function connect(address, options = {}) {
|
|
|
190
216
|
pendingBytes -= count;
|
|
191
217
|
notifyTerminal();
|
|
192
218
|
});
|
|
193
|
-
|
|
219
|
+
const socket = {
|
|
220
|
+
opened,
|
|
221
|
+
closed,
|
|
222
|
+
readable,
|
|
223
|
+
writable,
|
|
224
|
+
close,
|
|
225
|
+
secureTransport,
|
|
226
|
+
startTls(options = {}) {
|
|
227
|
+
if (upgraded ||
|
|
228
|
+
stopped ||
|
|
229
|
+
secureTransport !== "starttls" ||
|
|
230
|
+
readEnded ||
|
|
231
|
+
writeEnded)
|
|
232
|
+
throw new Error("Socket cannot be upgraded");
|
|
233
|
+
upgraded = true;
|
|
234
|
+
socket.upgraded = true;
|
|
235
|
+
const error = new Error("Socket has been upgraded");
|
|
236
|
+
readableController.error(error);
|
|
237
|
+
writableController.error(error);
|
|
238
|
+
resolveClosed();
|
|
239
|
+
let secureCall = call;
|
|
240
|
+
return transport((...args) => secureCall(...args), id, host, "on", async () => {
|
|
241
|
+
const info = await opened;
|
|
242
|
+
await activeWrite;
|
|
243
|
+
const hostname = options.expectedServerHostname ?? host;
|
|
244
|
+
const result = (await call("WorkersCapacitor", "socketStartTls", {
|
|
245
|
+
id,
|
|
246
|
+
servername: hostname,
|
|
247
|
+
}));
|
|
248
|
+
if (result?.tlsEngine === "openssl-wasm")
|
|
249
|
+
secureCall = await nativeTlsSession(call, id, hostname);
|
|
250
|
+
return info;
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
return socket;
|
|
194
255
|
}
|
|
195
256
|
export default { connect };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { arch, pid, ppid, allowedNodeEnvironmentFlags, setSourceMapsEnabled, getSourceMapsSupport, ref, unref, setUncaughtExceptionCaptureCallback, hasUncaughtExceptionCaptureCallback, kill, binding, dlopen, exitCode, getActiveResourcesInfo, memoryUsage, resourceUsage, threadCpuUsage, cpuUsage, channel, connected, debugPort, noDeprecation, traceDeprecation, throwDeprecation, sourceMapsEnabled, execPath, permission, release, report, finalization, _rawDebug, moduleLoadList, _preload_modules, _linkedBinding, domain, _exiting, _getActiveRequests, _getActiveHandles, _kill, constrainedMemory, availableMemory, execve, _fatalException, _tickCallback, _debugProcess, _debugEnd, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, send, uptime, getegid, getgid, getgroups, geteuid, getuid, setegid, setgid, seteuid, setuid, setgroups, initgroups, } from "./metadata.js";
|
|
2
|
+
export * from "cf-workers-native:process-base";
|
|
3
|
+
export { default } from "./state.js";
|
|
4
|
+
export declare const on: (...args: any[]) => any;
|
|
5
|
+
export declare const addListener: typeof on;
|
|
6
|
+
export declare const once: (...args: any[]) => any;
|
|
7
|
+
export declare const prependListener: (...args: any[]) => any;
|
|
8
|
+
export declare const prependOnceListener: (...args: any[]) => any;
|
|
9
|
+
export declare const off: (...args: any[]) => any;
|
|
10
|
+
export declare const removeListener: typeof off;
|
|
11
|
+
export declare const removeAllListeners: (...args: any[]) => any;
|
|
12
|
+
export declare const emit: (...args: any[]) => any;
|
|
13
|
+
export declare const listeners: (...args: any[]) => any;
|
|
14
|
+
export declare function nextTick(callback: (...args: any[]) => void, ...args: any[]): void;
|
|
15
|
+
export declare function emitWarning(warning: string | Error, options?: any, codeOrCtor?: any, maybeCtor?: any): void;
|
|
16
|
+
export declare const hrtime: ((time?: [number, number]) => [number, number]) & {
|
|
17
|
+
bigint: () => bigint;
|
|
18
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as metadata from "./metadata.js";
|
|
2
|
+
export { arch, pid, ppid, allowedNodeEnvironmentFlags, setSourceMapsEnabled, getSourceMapsSupport, ref, unref, setUncaughtExceptionCaptureCallback, hasUncaughtExceptionCaptureCallback, kill, binding, dlopen, exitCode, getActiveResourcesInfo, memoryUsage, resourceUsage, threadCpuUsage, cpuUsage, channel, connected, debugPort, noDeprecation, traceDeprecation, throwDeprecation, sourceMapsEnabled, execPath, permission, release, report, finalization, _rawDebug, moduleLoadList, _preload_modules, _linkedBinding, domain, _exiting, _getActiveRequests, _getActiveHandles, _kill, constrainedMemory, availableMemory, execve, _fatalException, _tickCallback, _debugProcess, _debugEnd, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, send, uptime, getegid, getgid, getgroups, geteuid, getuid, setegid, setgid, seteuid, setuid, setgroups, initgroups, } from "./metadata.js";
|
|
3
|
+
// Event delivery, warning and nextTick integration for the WebView profile.
|
|
4
|
+
// Other process exports retain the existing polyfill; see ../events/README.md.
|
|
5
|
+
export * from "cf-workers-native:process-base";
|
|
6
|
+
import process from "./state.js";
|
|
7
|
+
export { default } from "./state.js";
|
|
8
|
+
import { EventEmitter } from "../events/index.js";
|
|
9
|
+
import { ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE } from "../net/errors.js";
|
|
10
|
+
let initialized = false;
|
|
11
|
+
function invoke(method, args) {
|
|
12
|
+
if (!initialized) {
|
|
13
|
+
EventEmitter.init.call(process);
|
|
14
|
+
initialized = true;
|
|
15
|
+
}
|
|
16
|
+
return Reflect.apply(EventEmitter.prototype[method], process, args);
|
|
17
|
+
}
|
|
18
|
+
export const on = (...args) => invoke("on", args);
|
|
19
|
+
export const addListener = on;
|
|
20
|
+
export const once = (...args) => invoke("once", args);
|
|
21
|
+
export const prependListener = (...args) => invoke("prependListener", args);
|
|
22
|
+
export const prependOnceListener = (...args) => invoke("prependOnceListener", args);
|
|
23
|
+
export const off = (...args) => invoke("off", args);
|
|
24
|
+
export const removeListener = off;
|
|
25
|
+
export const removeAllListeners = (...args) => invoke("removeAllListeners", args);
|
|
26
|
+
export const emit = (...args) => invoke("emit", args);
|
|
27
|
+
export const listeners = (...args) => invoke("listeners", args);
|
|
28
|
+
const rawListeners = (...args) => invoke("rawListeners", args);
|
|
29
|
+
const eventNames = (...args) => invoke("eventNames", args);
|
|
30
|
+
const listenerCount = (...args) => invoke("listenerCount", args);
|
|
31
|
+
const getMaxListeners = (...args) => invoke("getMaxListeners", args);
|
|
32
|
+
const setMaxListeners = (...args) => invoke("setMaxListeners", args);
|
|
33
|
+
// Pinned workerd also implements nextTick with queueMicrotask.
|
|
34
|
+
export function nextTick(callback, ...args) {
|
|
35
|
+
queueMicrotask(() => callback(...args));
|
|
36
|
+
}
|
|
37
|
+
// Adapted from cloudflare/workerd@5358e3d337336eaf696a48bc1563d808b10feba5,
|
|
38
|
+
// src/node/internal/internal_process.ts, Apache-2.0.
|
|
39
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
40
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
41
|
+
export function emitWarning(warning, options, codeOrCtor, maybeCtor) {
|
|
42
|
+
let err;
|
|
43
|
+
let name = "Warning", detail, code, ctor;
|
|
44
|
+
if (typeof options === "object" && !Array.isArray(options)) {
|
|
45
|
+
if (options.type)
|
|
46
|
+
name = options.type;
|
|
47
|
+
if (options.code)
|
|
48
|
+
code = options.code;
|
|
49
|
+
if (options.detail)
|
|
50
|
+
detail = options.detail;
|
|
51
|
+
ctor = options.ctor;
|
|
52
|
+
}
|
|
53
|
+
else if (typeof options === "string") {
|
|
54
|
+
name = options;
|
|
55
|
+
if (typeof codeOrCtor === "string") {
|
|
56
|
+
code = codeOrCtor;
|
|
57
|
+
if (typeof maybeCtor === "function")
|
|
58
|
+
ctor = maybeCtor;
|
|
59
|
+
else if (maybeCtor !== undefined)
|
|
60
|
+
throw new ERR_INVALID_ARG_TYPE("ctor", "function", maybeCtor);
|
|
61
|
+
}
|
|
62
|
+
else if (typeof codeOrCtor === "function")
|
|
63
|
+
ctor = codeOrCtor;
|
|
64
|
+
else if (codeOrCtor !== undefined)
|
|
65
|
+
throw new ERR_INVALID_ARG_TYPE("ctor", "function", codeOrCtor);
|
|
66
|
+
}
|
|
67
|
+
else if (typeof options === "function")
|
|
68
|
+
ctor = options;
|
|
69
|
+
else if (options !== undefined)
|
|
70
|
+
throw new ERR_INVALID_ARG_TYPE("options", "object", options);
|
|
71
|
+
if (typeof warning === "string") {
|
|
72
|
+
err = new (ctor || Error)(warning);
|
|
73
|
+
err.name = name;
|
|
74
|
+
}
|
|
75
|
+
else if (warning instanceof Error) {
|
|
76
|
+
err = warning;
|
|
77
|
+
if (name && name !== "Warning")
|
|
78
|
+
err.name = name;
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
throw new ERR_INVALID_ARG_TYPE("warning", "string or Error", warning);
|
|
82
|
+
if (code)
|
|
83
|
+
err.code = code;
|
|
84
|
+
if (detail && typeof detail === "string")
|
|
85
|
+
err.detail = detail;
|
|
86
|
+
// WebKit lacks V8's captureStackTrace. Exact stack inspection remains a
|
|
87
|
+
// process/engine acceptance gap even when warning delivery matches.
|
|
88
|
+
Error.captureStackTrace?.(err, ctor || emitWarning);
|
|
89
|
+
queueMicrotask(() => process.emit("warning", err));
|
|
90
|
+
}
|
|
91
|
+
export const hrtime = Object.assign(function hrtime(time) {
|
|
92
|
+
if (time !== undefined) {
|
|
93
|
+
if (!Array.isArray(time))
|
|
94
|
+
throw new ERR_INVALID_ARG_TYPE("time", "tuple of integers", time);
|
|
95
|
+
else if (time.length !== 2)
|
|
96
|
+
throw new ERR_OUT_OF_RANGE("time", "2", time);
|
|
97
|
+
}
|
|
98
|
+
const nanoTime = BigInt(Date.now()) * 1000000n;
|
|
99
|
+
const nanosBigint = nanoTime % 1000000000n;
|
|
100
|
+
let seconds = Number((nanoTime - nanosBigint) / 1000000000n);
|
|
101
|
+
let nanos = Number(nanosBigint);
|
|
102
|
+
if (time) {
|
|
103
|
+
const [prevSeconds, prevNanos] = time;
|
|
104
|
+
seconds -= prevSeconds;
|
|
105
|
+
nanos -= prevNanos;
|
|
106
|
+
// We don't have nanosecond-level precision, but if we
|
|
107
|
+
// did (say with the introduction of randomness), this
|
|
108
|
+
// is how we would handle nanosecond underflow
|
|
109
|
+
if (nanos < 0) {
|
|
110
|
+
seconds -= 1;
|
|
111
|
+
nanos += 1e9;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return [seconds, nanos];
|
|
115
|
+
}, {
|
|
116
|
+
bigint: function () {
|
|
117
|
+
return BigInt(Date.now()) * 1000000n;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
Object.assign(process, {
|
|
121
|
+
hrtime,
|
|
122
|
+
...metadata,
|
|
123
|
+
on,
|
|
124
|
+
addListener,
|
|
125
|
+
once,
|
|
126
|
+
prependListener,
|
|
127
|
+
prependOnceListener,
|
|
128
|
+
off,
|
|
129
|
+
removeListener,
|
|
130
|
+
removeAllListeners,
|
|
131
|
+
emit,
|
|
132
|
+
listeners,
|
|
133
|
+
rawListeners,
|
|
134
|
+
eventNames,
|
|
135
|
+
listenerCount,
|
|
136
|
+
getMaxListeners,
|
|
137
|
+
setMaxListeners,
|
|
138
|
+
nextTick,
|
|
139
|
+
emitWarning,
|
|
140
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { NodeError } from "../net/error-base.js";
|
|
2
|
+
export declare class ERR_EPERM extends NodeError {
|
|
3
|
+
path?: string;
|
|
4
|
+
syscall: string;
|
|
5
|
+
errno: number;
|
|
6
|
+
constructor(options: {
|
|
7
|
+
syscall: string;
|
|
8
|
+
errno?: number;
|
|
9
|
+
path?: string;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export declare const arch = "x64";
|
|
13
|
+
export declare const pid = 1;
|
|
14
|
+
export declare const ppid = 0;
|
|
15
|
+
export declare const allowedNodeEnvironmentFlags: Set<unknown>;
|
|
16
|
+
export declare function setSourceMapsEnabled(_enabled: boolean, _options?: {
|
|
17
|
+
nodeModules: boolean;
|
|
18
|
+
generatedCode: boolean;
|
|
19
|
+
}): void;
|
|
20
|
+
export declare function getSourceMapsSupport(): {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
nodeModules: boolean;
|
|
23
|
+
generatedCode: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function ref(): void;
|
|
26
|
+
export declare function unref(): void;
|
|
27
|
+
export declare function setUncaughtExceptionCaptureCallback(_fn?: (...args: unknown[]) => void): void;
|
|
28
|
+
export declare function hasUncaughtExceptionCaptureCallback(): boolean;
|
|
29
|
+
export declare function kill(_pid: number, _signal?: string | number): boolean;
|
|
30
|
+
export declare function binding(_name: string): unknown;
|
|
31
|
+
export declare function dlopen(_module: unknown, _filename: string, _flags?: number): void;
|
|
32
|
+
export declare const exitCode: number | undefined;
|
|
33
|
+
export declare function getActiveResourcesInfo(): string[];
|
|
34
|
+
export declare function memoryUsage(): {
|
|
35
|
+
rss: number;
|
|
36
|
+
heapTotal: number;
|
|
37
|
+
heapUsed: number;
|
|
38
|
+
external: number;
|
|
39
|
+
arrayBuffers: number;
|
|
40
|
+
};
|
|
41
|
+
export declare function resourceUsage(): {
|
|
42
|
+
userCPUTime: number;
|
|
43
|
+
systemCPUTime: number;
|
|
44
|
+
maxRSS: number;
|
|
45
|
+
sharedMemorySize: number;
|
|
46
|
+
unsharedDataSize: number;
|
|
47
|
+
unsharedStackSize: number;
|
|
48
|
+
minorPageFault: number;
|
|
49
|
+
majorPageFault: number;
|
|
50
|
+
swappedOut: number;
|
|
51
|
+
fsRead: number;
|
|
52
|
+
fsWrite: number;
|
|
53
|
+
ipcSent: number;
|
|
54
|
+
ipcReceived: number;
|
|
55
|
+
signalsCount: number;
|
|
56
|
+
voluntaryContextSwitches: number;
|
|
57
|
+
involuntaryContextSwitches: number;
|
|
58
|
+
};
|
|
59
|
+
export declare function threadCpuUsage(): {
|
|
60
|
+
user: number;
|
|
61
|
+
system: number;
|
|
62
|
+
};
|
|
63
|
+
export declare function cpuUsage(_previousValue?: {
|
|
64
|
+
user: number;
|
|
65
|
+
system: number;
|
|
66
|
+
}): {
|
|
67
|
+
user: number;
|
|
68
|
+
system: number;
|
|
69
|
+
};
|
|
70
|
+
export declare const channel: null;
|
|
71
|
+
export declare const connected = false;
|
|
72
|
+
export declare const debugPort = 0;
|
|
73
|
+
export declare const noDeprecation = false;
|
|
74
|
+
export declare const traceDeprecation = false;
|
|
75
|
+
export declare const throwDeprecation = false;
|
|
76
|
+
export declare const sourceMapsEnabled = false;
|
|
77
|
+
export declare const execPath = "";
|
|
78
|
+
export declare const permission: {
|
|
79
|
+
has: () => boolean;
|
|
80
|
+
};
|
|
81
|
+
export declare const release: {
|
|
82
|
+
name: string;
|
|
83
|
+
lts: boolean;
|
|
84
|
+
sourceUrl: string;
|
|
85
|
+
headersUrl: string;
|
|
86
|
+
};
|
|
87
|
+
export declare const report: {
|
|
88
|
+
compact: boolean;
|
|
89
|
+
directory: string;
|
|
90
|
+
filename: string;
|
|
91
|
+
getReport: () => Record<string, unknown>;
|
|
92
|
+
reportOnFatalError: boolean;
|
|
93
|
+
reportOnSignal: boolean;
|
|
94
|
+
reportOnUncaughtException: boolean;
|
|
95
|
+
excludeNetwork: boolean;
|
|
96
|
+
excludeEnv: boolean;
|
|
97
|
+
signal: string;
|
|
98
|
+
writeReport: () => string;
|
|
99
|
+
};
|
|
100
|
+
export declare const finalization: {
|
|
101
|
+
register: () => void;
|
|
102
|
+
registerBeforeExit: () => void;
|
|
103
|
+
unregister: () => void;
|
|
104
|
+
};
|
|
105
|
+
export declare function _rawDebug(...args: unknown[]): void;
|
|
106
|
+
export declare const moduleLoadList: string[];
|
|
107
|
+
export declare const _preload_modules: string[];
|
|
108
|
+
export declare function _linkedBinding(_name: string): unknown;
|
|
109
|
+
export declare const domain: null;
|
|
110
|
+
export declare const _exiting = false;
|
|
111
|
+
export declare function _getActiveRequests(): unknown[];
|
|
112
|
+
export declare function _getActiveHandles(): unknown[];
|
|
113
|
+
export declare function _kill(_pid: number, _signal: number): boolean;
|
|
114
|
+
export declare function constrainedMemory(): number;
|
|
115
|
+
export declare function availableMemory(): number;
|
|
116
|
+
export declare function execve(_file: string, _args: string[], _env: Record<string, string>): never;
|
|
117
|
+
export declare function _fatalException(_err: Error): boolean;
|
|
118
|
+
export declare function _tickCallback(): void;
|
|
119
|
+
export declare function _debugProcess(_pid: number): void;
|
|
120
|
+
export declare function _debugEnd(): void;
|
|
121
|
+
export declare function _startProfilerIdleNotifier(): void;
|
|
122
|
+
export declare function _stopProfilerIdleNotifier(): void;
|
|
123
|
+
export declare function send(_message: unknown, _sendHandle?: unknown): boolean;
|
|
124
|
+
export declare function uptime(): number;
|
|
125
|
+
export declare function getegid(): number;
|
|
126
|
+
export declare function getgid(): number;
|
|
127
|
+
export declare function getgroups(): number[];
|
|
128
|
+
export declare function geteuid(): number;
|
|
129
|
+
export declare function getuid(): number;
|
|
130
|
+
export declare function setegid(id: number | string): void;
|
|
131
|
+
export declare function setgid(id: number | string): void;
|
|
132
|
+
export declare function seteuid(id: number | string): void;
|
|
133
|
+
export declare function setuid(id: number | string): void;
|
|
134
|
+
export declare function setgroups(_groups: number[]): void;
|
|
135
|
+
export declare function initgroups(_user: number | string, _extractGroup: number | string): void;
|