@bytecodealliance/preview3-shim 0.1.2 → 0.2.0
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/nodejs/cli.d.ts +51 -0
- package/dist/nodejs/cli.js +106 -0
- package/dist/nodejs/clocks.d.ts +55 -0
- package/dist/nodejs/clocks.js +83 -0
- package/dist/nodejs/filesystem/descriptor.d.ts +443 -0
- package/dist/nodejs/filesystem/descriptor.js +1010 -0
- package/dist/nodejs/filesystem/error.d.ts +61 -0
- package/dist/nodejs/filesystem/error.js +86 -0
- package/dist/nodejs/filesystem/utils.d.ts +8 -0
- package/dist/nodejs/filesystem/utils.js +25 -0
- package/dist/nodejs/filesystem.js +2 -0
- package/dist/nodejs/finalization.d.ts +2 -0
- package/{lib → dist}/nodejs/finalization.js +15 -21
- package/dist/nodejs/future.d.ts +98 -0
- package/dist/nodejs/future.js +176 -0
- package/dist/nodejs/http/client.d.ts +22 -0
- package/dist/nodejs/http/client.js +138 -0
- package/dist/nodejs/http/error.d.ts +18 -0
- package/dist/nodejs/http/error.js +62 -0
- package/dist/nodejs/http/fields.d.ts +144 -0
- package/dist/nodejs/http/fields.js +327 -0
- package/dist/nodejs/http/request.d.ts +256 -0
- package/dist/nodejs/http/request.js +606 -0
- package/dist/nodejs/http/response.d.ts +82 -0
- package/dist/nodejs/http/response.js +202 -0
- package/dist/nodejs/http/server.d.ts +13 -0
- package/dist/nodejs/http/server.js +127 -0
- package/dist/nodejs/http.d.ts +19 -0
- package/{lib → dist}/nodejs/http.js +13 -18
- package/dist/nodejs/index.js +8 -0
- package/dist/nodejs/random.d.ts +5 -0
- package/{lib → dist}/nodejs/random.js +2 -8
- package/dist/nodejs/sockets/address.d.ts +78 -0
- package/dist/nodejs/sockets/address.js +120 -0
- package/dist/nodejs/sockets/error.d.ts +83 -0
- package/dist/nodejs/sockets/error.js +120 -0
- package/dist/nodejs/sockets/ip-name-lookup.d.ts +18 -0
- package/dist/nodejs/sockets/ip-name-lookup.js +84 -0
- package/dist/nodejs/sockets/tcp.d.ts +333 -0
- package/dist/nodejs/sockets/tcp.js +723 -0
- package/dist/nodejs/sockets/udp.d.ts +224 -0
- package/dist/nodejs/sockets/udp.js +475 -0
- package/dist/nodejs/sockets.d.ts +11 -0
- package/{lib → dist}/nodejs/sockets.js +2 -5
- package/dist/nodejs/stream.d.ts +161 -0
- package/dist/nodejs/stream.js +388 -0
- package/dist/nodejs/workers/cli-worker.d.ts +1 -0
- package/dist/nodejs/workers/cli-worker.js +41 -0
- package/dist/nodejs/workers/filesystem-worker.d.ts +1 -0
- package/dist/nodejs/workers/filesystem-worker.js +102 -0
- package/dist/nodejs/workers/http-worker.d.ts +1 -0
- package/dist/nodejs/workers/http-worker.js +355 -0
- package/dist/nodejs/workers/resource-worker.d.ts +13 -0
- package/dist/nodejs/workers/resource-worker.js +152 -0
- package/dist/nodejs/workers/tcp-worker.d.ts +2 -0
- package/dist/nodejs/workers/tcp-worker.js +318 -0
- package/dist/nodejs/workers/udp-worker.d.ts +1 -0
- package/dist/nodejs/workers/udp-worker.js +156 -0
- package/package.json +20 -12
- package/types/interfaces/wasi-cli-environment.d.ts +3 -3
- package/types/interfaces/wasi-cli-exit.d.ts +12 -1
- package/types/interfaces/wasi-cli-run.d.ts +1 -1
- package/types/interfaces/wasi-cli-stderr.d.ts +3 -3
- package/types/interfaces/wasi-cli-stdin.d.ts +5 -5
- package/types/interfaces/wasi-cli-stdout.d.ts +3 -3
- package/types/interfaces/wasi-cli-terminal-input.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-output.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
- package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
- package/types/interfaces/wasi-cli-types.d.ts +5 -5
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +3 -3
- package/types/interfaces/wasi-clocks-system-clock.d.ts +6 -6
- package/types/interfaces/wasi-clocks-types.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
- package/types/interfaces/wasi-filesystem-types.d.ts +74 -74
- package/types/interfaces/wasi-http-client.d.ts +1 -1
- package/types/interfaces/wasi-http-handler.d.ts +1 -1
- package/types/interfaces/wasi-http-types.d.ts +34 -34
- package/types/interfaces/wasi-random-insecure-seed.d.ts +5 -5
- package/types/interfaces/wasi-random-insecure.d.ts +5 -5
- package/types/interfaces/wasi-random-random.d.ts +5 -5
- package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +11 -11
- package/types/interfaces/wasi-sockets-types.d.ts +121 -121
- package/types/wasi-cli-command.d.ts +23 -23
- package/types/wasi-http-service.d.ts +14 -14
- package/lib/nodejs/cli.js +0 -127
- package/lib/nodejs/clocks.js +0 -98
- package/lib/nodejs/filesystem/descriptor.js +0 -1093
- package/lib/nodejs/filesystem/error.js +0 -92
- package/lib/nodejs/filesystem/utils.js +0 -19
- package/lib/nodejs/future.js +0 -190
- package/lib/nodejs/http/client.js +0 -161
- package/lib/nodejs/http/error.js +0 -71
- package/lib/nodejs/http/fields.js +0 -373
- package/lib/nodejs/http/request.js +0 -691
- package/lib/nodejs/http/response.js +0 -227
- package/lib/nodejs/http/server.js +0 -157
- package/lib/nodejs/sockets/address.js +0 -146
- package/lib/nodejs/sockets/error.js +0 -123
- package/lib/nodejs/sockets/ip-name-lookup.js +0 -93
- package/lib/nodejs/sockets/tcp.js +0 -801
- package/lib/nodejs/sockets/udp.js +0 -516
- package/lib/nodejs/stream.js +0 -437
- package/lib/nodejs/workers/cli-worker.js +0 -49
- package/lib/nodejs/workers/filesystem-worker.js +0 -119
- package/lib/nodejs/workers/http-worker.js +0 -417
- package/lib/nodejs/workers/resource-worker.js +0 -195
- package/lib/nodejs/workers/tcp-worker.js +0 -370
- package/lib/nodejs/workers/udp-worker.js +0 -194
- /package/{lib/nodejs/filesystem.js → dist/nodejs/filesystem.d.ts} +0 -0
- /package/{lib/nodejs/index.js → dist/nodejs/index.d.ts} +0 -0
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { lookup } from "node:dns/promises";
|
|
2
|
-
import { isIP } from "node:net";
|
|
3
|
-
import { domainToASCII } from "node:url";
|
|
4
|
-
|
|
5
|
-
import { ipv4ToTuple, ipv6ToTuple } from "./address.js";
|
|
6
|
-
import { SocketError } from "./error.js";
|
|
7
|
-
|
|
8
|
-
const DNS_ERROR_MAP = {
|
|
9
|
-
EACCES: "access-denied",
|
|
10
|
-
EPERM: "access-denied",
|
|
11
|
-
EINVAL: "invalid-argument",
|
|
12
|
-
ENOTFOUND: "name-unresolvable",
|
|
13
|
-
EAI_ADDRFAMILY: "name-unresolvable",
|
|
14
|
-
EAI_AGAIN: "temporary-resolver-failure",
|
|
15
|
-
EAI_FAIL: "permanent-resolver-failure",
|
|
16
|
-
EAI_NODATA: "name-unresolvable",
|
|
17
|
-
EAI_NONAME: "name-unresolvable",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function ipAddress(address, family) {
|
|
21
|
-
switch (family) {
|
|
22
|
-
case 4:
|
|
23
|
-
return { tag: "ipv4", val: ipv4ToTuple(address) };
|
|
24
|
-
case 6:
|
|
25
|
-
return { tag: "ipv6", val: ipv6ToTuple(address) };
|
|
26
|
-
default:
|
|
27
|
-
throw new SocketError("other", `Unknown IP address family: ${family}`, `${family}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function normalizeLookupName(name) {
|
|
32
|
-
if (typeof name !== "string" || name === "" || name.trim() !== name) {
|
|
33
|
-
throw new SocketError("invalid-argument");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (name.startsWith("[") || name.endsWith("]")) {
|
|
37
|
-
const bracketedIpv6 = name.match(/^\[([^\]]+)\]$/);
|
|
38
|
-
if (bracketedIpv6 && isIP(bracketedIpv6[1]) === 6) {
|
|
39
|
-
return bracketedIpv6[1];
|
|
40
|
-
}
|
|
41
|
-
throw new SocketError("invalid-argument");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isIP(name) !== 0) {
|
|
45
|
-
return name;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const asciiName = domainToASCII(name);
|
|
49
|
-
if (asciiName === "") {
|
|
50
|
-
throw new SocketError("invalid-argument");
|
|
51
|
-
}
|
|
52
|
-
return asciiName;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const ipNameLookup = {
|
|
56
|
-
/**
|
|
57
|
-
* Resolve an internet host name to a list of IP addresses.
|
|
58
|
-
*
|
|
59
|
-
* WIT:
|
|
60
|
-
* ```
|
|
61
|
-
* resolve-addresses: async func(name: string) -> result<list<ip-address>, error-code>
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @param {string} name - Host name or IP address to resolve.
|
|
65
|
-
* @returns {Promise<Array<{tag: "ipv4" | "ipv6", val: number[]}>>}
|
|
66
|
-
* @throws {SocketError} payload.tag maps to wasi:sockets/ip-name-lookup error-code.
|
|
67
|
-
*/
|
|
68
|
-
async resolveAddresses(name) {
|
|
69
|
-
try {
|
|
70
|
-
const lookupName = normalizeLookupName(name);
|
|
71
|
-
const literalFamily = isIP(lookupName);
|
|
72
|
-
if (literalFamily !== 0) {
|
|
73
|
-
return [ipAddress(lookupName, literalFamily)];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const addresses = await lookup(lookupName, { all: true, verbatim: false });
|
|
77
|
-
const result = addresses.map(({ address, family }) => ipAddress(address, family));
|
|
78
|
-
|
|
79
|
-
if (result.length === 0) {
|
|
80
|
-
throw new SocketError("name-unresolvable");
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
if (error instanceof SocketError) {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
const tag = DNS_ERROR_MAP[error?.code] ?? "other";
|
|
88
|
-
throw new SocketError(tag, error?.message, tag === "other" ? error?.code : undefined, {
|
|
89
|
-
cause: error,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
};
|