@bytecodealliance/preview3-shim 0.1.2 → 0.2.1

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 (112) hide show
  1. package/dist/nodejs/cli.d.ts +51 -0
  2. package/dist/nodejs/cli.js +106 -0
  3. package/dist/nodejs/clocks.d.ts +55 -0
  4. package/dist/nodejs/clocks.js +83 -0
  5. package/dist/nodejs/filesystem/descriptor.d.ts +443 -0
  6. package/dist/nodejs/filesystem/descriptor.js +1010 -0
  7. package/dist/nodejs/filesystem/error.d.ts +61 -0
  8. package/dist/nodejs/filesystem/error.js +86 -0
  9. package/dist/nodejs/filesystem/utils.d.ts +8 -0
  10. package/dist/nodejs/filesystem/utils.js +25 -0
  11. package/dist/nodejs/filesystem.js +2 -0
  12. package/dist/nodejs/finalization.d.ts +2 -0
  13. package/{lib → dist}/nodejs/finalization.js +15 -21
  14. package/dist/nodejs/future.d.ts +98 -0
  15. package/dist/nodejs/future.js +176 -0
  16. package/dist/nodejs/http/client.d.ts +22 -0
  17. package/dist/nodejs/http/client.js +138 -0
  18. package/dist/nodejs/http/error.d.ts +18 -0
  19. package/dist/nodejs/http/error.js +62 -0
  20. package/dist/nodejs/http/fields.d.ts +144 -0
  21. package/dist/nodejs/http/fields.js +332 -0
  22. package/dist/nodejs/http/request.d.ts +256 -0
  23. package/dist/nodejs/http/request.js +606 -0
  24. package/dist/nodejs/http/response.d.ts +82 -0
  25. package/dist/nodejs/http/response.js +202 -0
  26. package/dist/nodejs/http/server.d.ts +13 -0
  27. package/dist/nodejs/http/server.js +127 -0
  28. package/dist/nodejs/http.d.ts +19 -0
  29. package/{lib → dist}/nodejs/http.js +13 -18
  30. package/dist/nodejs/index.js +8 -0
  31. package/dist/nodejs/random.d.ts +5 -0
  32. package/{lib → dist}/nodejs/random.js +2 -8
  33. package/dist/nodejs/sockets/address.d.ts +78 -0
  34. package/dist/nodejs/sockets/address.js +120 -0
  35. package/dist/nodejs/sockets/error.d.ts +83 -0
  36. package/dist/nodejs/sockets/error.js +120 -0
  37. package/dist/nodejs/sockets/ip-name-lookup.d.ts +18 -0
  38. package/dist/nodejs/sockets/ip-name-lookup.js +84 -0
  39. package/dist/nodejs/sockets/tcp.d.ts +333 -0
  40. package/dist/nodejs/sockets/tcp.js +723 -0
  41. package/dist/nodejs/sockets/udp.d.ts +224 -0
  42. package/dist/nodejs/sockets/udp.js +475 -0
  43. package/dist/nodejs/sockets.d.ts +11 -0
  44. package/{lib → dist}/nodejs/sockets.js +2 -5
  45. package/dist/nodejs/stream.d.ts +161 -0
  46. package/dist/nodejs/stream.js +388 -0
  47. package/dist/nodejs/workers/cli-worker.d.ts +1 -0
  48. package/dist/nodejs/workers/cli-worker.js +41 -0
  49. package/dist/nodejs/workers/filesystem-worker.d.ts +1 -0
  50. package/dist/nodejs/workers/filesystem-worker.js +109 -0
  51. package/dist/nodejs/workers/http-worker.d.ts +1 -0
  52. package/dist/nodejs/workers/http-worker.js +355 -0
  53. package/dist/nodejs/workers/resource-worker.d.ts +13 -0
  54. package/dist/nodejs/workers/resource-worker.js +152 -0
  55. package/dist/nodejs/workers/tcp-worker.d.ts +2 -0
  56. package/dist/nodejs/workers/tcp-worker.js +318 -0
  57. package/dist/nodejs/workers/udp-worker.d.ts +1 -0
  58. package/dist/nodejs/workers/udp-worker.js +156 -0
  59. package/package.json +20 -12
  60. package/types/interfaces/wasi-cli-environment.d.ts +3 -3
  61. package/types/interfaces/wasi-cli-exit.d.ts +12 -1
  62. package/types/interfaces/wasi-cli-run.d.ts +1 -1
  63. package/types/interfaces/wasi-cli-stderr.d.ts +3 -3
  64. package/types/interfaces/wasi-cli-stdin.d.ts +5 -5
  65. package/types/interfaces/wasi-cli-stdout.d.ts +3 -3
  66. package/types/interfaces/wasi-cli-terminal-input.d.ts +1 -1
  67. package/types/interfaces/wasi-cli-terminal-output.d.ts +1 -1
  68. package/types/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
  69. package/types/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
  70. package/types/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
  71. package/types/interfaces/wasi-cli-types.d.ts +5 -5
  72. package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +3 -3
  73. package/types/interfaces/wasi-clocks-system-clock.d.ts +6 -6
  74. package/types/interfaces/wasi-clocks-types.d.ts +1 -1
  75. package/types/interfaces/wasi-filesystem-preopens.d.ts +1 -1
  76. package/types/interfaces/wasi-filesystem-types.d.ts +74 -74
  77. package/types/interfaces/wasi-http-client.d.ts +1 -1
  78. package/types/interfaces/wasi-http-handler.d.ts +1 -1
  79. package/types/interfaces/wasi-http-types.d.ts +34 -34
  80. package/types/interfaces/wasi-random-insecure-seed.d.ts +5 -5
  81. package/types/interfaces/wasi-random-insecure.d.ts +5 -5
  82. package/types/interfaces/wasi-random-random.d.ts +5 -5
  83. package/types/interfaces/wasi-sockets-ip-name-lookup.d.ts +11 -11
  84. package/types/interfaces/wasi-sockets-types.d.ts +121 -121
  85. package/types/wasi-cli-command.d.ts +23 -23
  86. package/types/wasi-http-service.d.ts +14 -14
  87. package/lib/nodejs/cli.js +0 -127
  88. package/lib/nodejs/clocks.js +0 -98
  89. package/lib/nodejs/filesystem/descriptor.js +0 -1093
  90. package/lib/nodejs/filesystem/error.js +0 -92
  91. package/lib/nodejs/filesystem/utils.js +0 -19
  92. package/lib/nodejs/future.js +0 -190
  93. package/lib/nodejs/http/client.js +0 -161
  94. package/lib/nodejs/http/error.js +0 -71
  95. package/lib/nodejs/http/fields.js +0 -373
  96. package/lib/nodejs/http/request.js +0 -691
  97. package/lib/nodejs/http/response.js +0 -227
  98. package/lib/nodejs/http/server.js +0 -157
  99. package/lib/nodejs/sockets/address.js +0 -146
  100. package/lib/nodejs/sockets/error.js +0 -123
  101. package/lib/nodejs/sockets/ip-name-lookup.js +0 -93
  102. package/lib/nodejs/sockets/tcp.js +0 -801
  103. package/lib/nodejs/sockets/udp.js +0 -516
  104. package/lib/nodejs/stream.js +0 -437
  105. package/lib/nodejs/workers/cli-worker.js +0 -49
  106. package/lib/nodejs/workers/filesystem-worker.js +0 -119
  107. package/lib/nodejs/workers/http-worker.js +0 -417
  108. package/lib/nodejs/workers/resource-worker.js +0 -195
  109. package/lib/nodejs/workers/tcp-worker.js +0 -370
  110. package/lib/nodejs/workers/udp-worker.js +0 -194
  111. /package/{lib/nodejs/filesystem.js → dist/nodejs/filesystem.d.ts} +0 -0
  112. /package/{lib/nodejs/index.js → dist/nodejs/index.d.ts} +0 -0
@@ -0,0 +1,83 @@
1
+ export declare const ERROR_MAP: {
2
+ EACCES: string;
3
+ EPERM: string;
4
+ EOPNOTSUPP: string;
5
+ ENOPROTOOPT: string;
6
+ EPFNOSUPPORT: string;
7
+ EPROTONOSUPPORT: string;
8
+ ESOCKTNOSUPPORT: string;
9
+ EINVAL: string;
10
+ EAFNOSUPPORT: string;
11
+ ENOMEM: string;
12
+ ENOBUFS: string;
13
+ ETIMEDOUT: string;
14
+ EADDRINUSE: string;
15
+ EADDRNOTAVAIL: string;
16
+ EHOSTUNREACH: string;
17
+ EHOSTDOWN: string;
18
+ ENETUNREACH: string;
19
+ ENETDOWN: string;
20
+ ENONET: string;
21
+ ECONNREFUSED: string;
22
+ EPIPE: string;
23
+ ECONNRESET: string;
24
+ ECONNABORTED: string;
25
+ EMSGSIZE: string;
26
+ ENOTCONN: string;
27
+ EISCONN: string;
28
+ EALREADY: string;
29
+ EDESTADDRREQ: string;
30
+ };
31
+ export declare const CODE_MAP: {
32
+ 4053: string;
33
+ 4083: string;
34
+ ENOTCONN: string;
35
+ EBADF: string;
36
+ EACCES: string;
37
+ EPERM: string;
38
+ ENOTSUP: string;
39
+ EOPNOTSUPP: string;
40
+ ENOPROTOOPT: string;
41
+ EPFNOSUPPORT: string;
42
+ EPROTONOSUPPORT: string;
43
+ ESOCKTNOSUPPORT: string;
44
+ EINVAL: string;
45
+ EAFNOSUPPORT: string;
46
+ ENOMEM: string;
47
+ ENOBUFS: string;
48
+ 4090: string;
49
+ EADDRNOTAVAIL: string;
50
+ 4091: string;
51
+ EADDRINUSE: string;
52
+ EHOSTUNREACH: string;
53
+ EHOSTDOWN: string;
54
+ ENETUNREACH: string;
55
+ ENETDOWN: string;
56
+ ENONET: string;
57
+ ECONNREFUSED: string;
58
+ EPIPE: string;
59
+ ECONNRESET: string;
60
+ ECONNABORTED: string;
61
+ EMSGSIZE: string;
62
+ };
63
+ /**
64
+ * Custom error for Socket operations with JCO compatible payload.
65
+ *
66
+ * https://bytecodealliance.github.io/jco/wit-type-representations.html#result-considerations-idiomatic-js-errors-for-host-implementations
67
+ */
68
+ export declare class SocketError extends Error {
69
+ payload: any;
70
+ /**
71
+ * @param {string} tag – machine‐readable error tag
72
+ * @param {string} [message] – human‐readable message
73
+ * @param {any} [val] – optional extra data
74
+ */
75
+ constructor(tag: any, message?: any, val?: any, opts?: {
76
+ cause?: unknown;
77
+ });
78
+ /**
79
+ * Create or rewrap an error into SocketError
80
+ * @param {any} err – number, string, Error, or SocketError
81
+ */
82
+ static from(err: any): SocketError;
83
+ }
@@ -0,0 +1,120 @@
1
+ export const ERROR_MAP = {
2
+ EACCES: "access-denied",
3
+ EPERM: "access-denied",
4
+ EOPNOTSUPP: "not-supported",
5
+ ENOPROTOOPT: "not-supported",
6
+ EPFNOSUPPORT: "not-supported",
7
+ EPROTONOSUPPORT: "not-supported",
8
+ ESOCKTNOSUPPORT: "not-supported",
9
+ EINVAL: "invalid-argument",
10
+ EAFNOSUPPORT: "invalid-argument",
11
+ ENOMEM: "out-of-memory",
12
+ ENOBUFS: "out-of-memory",
13
+ ETIMEDOUT: "timeout",
14
+ EADDRINUSE: "address-in-use",
15
+ EADDRNOTAVAIL: "address-not-bindable",
16
+ EHOSTUNREACH: "remote-unreachable",
17
+ EHOSTDOWN: "remote-unreachable",
18
+ ENETUNREACH: "remote-unreachable",
19
+ ENETDOWN: "remote-unreachable",
20
+ ENONET: "remote-unreachable",
21
+ ECONNREFUSED: "connection-refused",
22
+ EPIPE: "connection-broken",
23
+ ECONNRESET: "connection-reset",
24
+ ECONNABORTED: "connection-aborted",
25
+ EMSGSIZE: "datagram-too-large",
26
+ ENOTCONN: "invalid-state",
27
+ EISCONN: "invalid-state",
28
+ EALREADY: "invalid-state",
29
+ EDESTADDRREQ: "invalid-argument",
30
+ };
31
+ export const CODE_MAP = {
32
+ 4053: "invalid-state",
33
+ 4083: "invalid-state",
34
+ ENOTCONN: "invalid-state",
35
+ EBADF: "invalid-state",
36
+ EACCES: "access-denied",
37
+ EPERM: "access-denied",
38
+ ENOTSUP: "not-supported",
39
+ EOPNOTSUPP: "not-supported",
40
+ ENOPROTOOPT: "not-supported",
41
+ EPFNOSUPPORT: "not-supported",
42
+ EPROTONOSUPPORT: "not-supported",
43
+ ESOCKTNOSUPPORT: "not-supported",
44
+ EINVAL: "invalid-argument",
45
+ EAFNOSUPPORT: "invalid-argument",
46
+ ENOMEM: "out-of-memory",
47
+ ENOBUFS: "out-of-memory",
48
+ 4090: "address-not-bindable",
49
+ EADDRNOTAVAIL: "address-not-bindable",
50
+ 4091: "address-in-use",
51
+ EADDRINUSE: "address-in-use",
52
+ EHOSTUNREACH: "remote-unreachable",
53
+ EHOSTDOWN: "remote-unreachable",
54
+ ENETUNREACH: "remote-unreachable",
55
+ ENETDOWN: "remote-unreachable",
56
+ ENONET: "remote-unreachable",
57
+ ECONNREFUSED: "connection-refused",
58
+ EPIPE: "connection-broken",
59
+ ECONNRESET: "connection-reset",
60
+ ECONNABORTED: "connection-aborted",
61
+ EMSGSIZE: "datagram-too-large",
62
+ };
63
+ /**
64
+ * Custom error for Socket operations with JCO compatible payload.
65
+ *
66
+ * https://bytecodealliance.github.io/jco/wit-type-representations.html#result-considerations-idiomatic-js-errors-for-host-implementations
67
+ */
68
+ export class SocketError extends Error {
69
+ payload;
70
+ /**
71
+ * @param {string} tag – machine‐readable error tag
72
+ * @param {string} [message] – human‐readable message
73
+ * @param {any} [val] – optional extra data
74
+ */
75
+ constructor(tag, message = undefined, val = undefined, opts = {}) {
76
+ super(message ?? `Error: ${tag}`, { cause: opts.cause });
77
+ this.name = "SocketError";
78
+ this.payload = val !== undefined ? { tag, val } : { tag };
79
+ }
80
+ /**
81
+ * Create or rewrap an error into SocketError
82
+ * @param {any} err – number, string, Error, or SocketError
83
+ */
84
+ static from(err) {
85
+ if (err instanceof SocketError) {
86
+ return err;
87
+ }
88
+ let tag, message, val;
89
+ if (typeof err === "number") {
90
+ tag = CODE_MAP[err] ?? "other";
91
+ message = `Error code ${err}`;
92
+ if (tag === "other") {
93
+ val = message;
94
+ }
95
+ }
96
+ else if (typeof err === "string") {
97
+ tag = ERROR_MAP[err] ?? "other";
98
+ if (tag === "other") {
99
+ val = err;
100
+ }
101
+ }
102
+ else if (err && typeof err.code === "string") {
103
+ tag = ERROR_MAP[err.code] ?? "other";
104
+ message = err.message;
105
+ if (tag === "other") {
106
+ val = err.code;
107
+ }
108
+ }
109
+ else if (err && typeof err.message === "string" && ERROR_MAP[err.message]) {
110
+ tag = ERROR_MAP[err.message];
111
+ message = err.message;
112
+ }
113
+ else {
114
+ tag = "other";
115
+ message = err?.message;
116
+ val = message;
117
+ }
118
+ return new SocketError(tag, message, val);
119
+ }
120
+ }
@@ -0,0 +1,18 @@
1
+ export declare const ipNameLookup: {
2
+ /**
3
+ * Resolve an internet host name to a list of IP addresses.
4
+ *
5
+ * WIT:
6
+ * ```
7
+ * resolve-addresses: async func(name: string) -> result<list<ip-address>, error-code>
8
+ * ```
9
+ *
10
+ * @param {string} name - Host name or IP address to resolve.
11
+ * @returns {Promise<Array<{tag: "ipv4" | "ipv6", val: number[]}>>}
12
+ * @throws {SocketError} payload.tag maps to wasi:sockets/ip-name-lookup error-code.
13
+ */
14
+ resolveAddresses(name: any): Promise<{
15
+ tag: string;
16
+ val: any;
17
+ }[]>;
18
+ };
@@ -0,0 +1,84 @@
1
+ import { lookup } from "node:dns/promises";
2
+ import { isIP } from "node:net";
3
+ import { domainToASCII } from "node:url";
4
+ import { ipv4ToTuple, ipv6ToTuple } from "./address.js";
5
+ import { SocketError } from "./error.js";
6
+ const DNS_ERROR_MAP = {
7
+ EACCES: "access-denied",
8
+ EPERM: "access-denied",
9
+ EINVAL: "invalid-argument",
10
+ ENOTFOUND: "name-unresolvable",
11
+ EAI_ADDRFAMILY: "name-unresolvable",
12
+ EAI_AGAIN: "temporary-resolver-failure",
13
+ EAI_FAIL: "permanent-resolver-failure",
14
+ EAI_NODATA: "name-unresolvable",
15
+ EAI_NONAME: "name-unresolvable",
16
+ };
17
+ function ipAddress(address, family) {
18
+ switch (family) {
19
+ case 4:
20
+ return { tag: "ipv4", val: ipv4ToTuple(address) };
21
+ case 6:
22
+ return { tag: "ipv6", val: ipv6ToTuple(address) };
23
+ default:
24
+ throw new SocketError("other", `Unknown IP address family: ${family}`, `${family}`);
25
+ }
26
+ }
27
+ function normalizeLookupName(name) {
28
+ if (typeof name !== "string" || name === "" || name.trim() !== name) {
29
+ throw new SocketError("invalid-argument");
30
+ }
31
+ if (name.startsWith("[") || name.endsWith("]")) {
32
+ const bracketedIpv6 = name.match(/^\[([^\]]+)\]$/);
33
+ if (bracketedIpv6 && isIP(bracketedIpv6[1]) === 6) {
34
+ return bracketedIpv6[1];
35
+ }
36
+ throw new SocketError("invalid-argument");
37
+ }
38
+ if (isIP(name) !== 0) {
39
+ return name;
40
+ }
41
+ const asciiName = domainToASCII(name);
42
+ if (asciiName === "") {
43
+ throw new SocketError("invalid-argument");
44
+ }
45
+ return asciiName;
46
+ }
47
+ export const ipNameLookup = {
48
+ /**
49
+ * Resolve an internet host name to a list of IP addresses.
50
+ *
51
+ * WIT:
52
+ * ```
53
+ * resolve-addresses: async func(name: string) -> result<list<ip-address>, error-code>
54
+ * ```
55
+ *
56
+ * @param {string} name - Host name or IP address to resolve.
57
+ * @returns {Promise<Array<{tag: "ipv4" | "ipv6", val: number[]}>>}
58
+ * @throws {SocketError} payload.tag maps to wasi:sockets/ip-name-lookup error-code.
59
+ */
60
+ async resolveAddresses(name) {
61
+ try {
62
+ const lookupName = normalizeLookupName(name);
63
+ const literalFamily = isIP(lookupName);
64
+ if (literalFamily !== 0) {
65
+ return [ipAddress(lookupName, literalFamily)];
66
+ }
67
+ const addresses = await lookup(lookupName, { all: true, verbatim: false });
68
+ const result = addresses.map(({ address, family }) => ipAddress(address, family));
69
+ if (result.length === 0) {
70
+ throw new SocketError("name-unresolvable");
71
+ }
72
+ return result;
73
+ }
74
+ catch (error) {
75
+ if (error instanceof SocketError) {
76
+ throw error;
77
+ }
78
+ const tag = DNS_ERROR_MAP[error?.code] ?? "other";
79
+ throw new SocketError(tag, error?.message, tag === "other" ? error?.code : undefined, {
80
+ cause: error,
81
+ });
82
+ }
83
+ },
84
+ };
@@ -0,0 +1,333 @@
1
+ import { StreamReader } from "../stream.js";
2
+ import { FutureReader } from "../future.js";
3
+ /**
4
+ * Creates a new TCP socket
5
+ * WIT: createTcpSocket: func(address-family: ip-address-family) -> result<tcp-socket, error-code>
6
+ *
7
+ * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6)
8
+ * @returns {TcpSocket>} A new TCP socket instance
9
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `addressFamily` is not IPV4 or IPV6
10
+ * @throws {SocketError} for other errors, payload.tag maps the low-level system error_
11
+ */
12
+ export declare function createTcpSocket(addressFamily: any): TcpSocket;
13
+ export declare class TcpSocket {
14
+ #private;
15
+ /**
16
+ * WIT static constructor for `wasi:sockets/types.tcp-socket`.
17
+ *
18
+ * WIT:
19
+ * ```
20
+ * create: static func(address-family: ip-address-family) -> result<tcp-socket, error-code>
21
+ * ```
22
+ *
23
+ * @static
24
+ * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6)
25
+ * @returns {TcpSocket} A new TcpSocket instance
26
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `addressFamily` is not IPV4 or IPV6
27
+ * @throws {SocketError} for other socket creation errors
28
+ */
29
+ static create(addressFamily: any): TcpSocket;
30
+ /**
31
+ * Creates a new TCP socket
32
+ * WIT:
33
+ * ```
34
+ * constructor(address-family: ip-address-family)
35
+ * ```
36
+ *
37
+ * @static
38
+ * @param {IP_ADDRESS_FAMILY} addressFamily - The IP address family (IPv4 or IPv6)
39
+ * @param {number} socketId - The internal socket identifier
40
+ * @returns {TcpSocket} A new TcpSocket instance
41
+ * @private
42
+ */
43
+ static _create(t: any, addressFamily: any, socketId: any): TcpSocket;
44
+ /**
45
+ * Binds the socket to a local address
46
+ * WIT:
47
+ * ```
48
+ * bind: func(local-address: ip-socket-address) -> result<_, error-code>
49
+ * ```
50
+ *
51
+ * @param {Object} localAddress - The local address to bind to
52
+ * @returns {void}
53
+ * @throws {SocketError} with payload.tag 'invalid-state' if the socket is not in ~STATE.UNBOUND~
54
+ * @throws {SocketError} with payload.tag 'invalid-argument' if ~localAddress~ is invalid
55
+ * @throws {SocketError} for other errors, payload.tag maps the system error
56
+ */
57
+ bind(localAddress: any): void;
58
+ /**
59
+ * Connects to a remote endpoint
60
+ * WIT:
61
+ * ```
62
+ * connect: async func(remote-address: ip-socket-address) -> result<_, error-code>
63
+ * ```
64
+ *
65
+ * @async
66
+ * @param {Object} remoteAddress - The remote address to connect to
67
+ * @returns {Promise<void>}
68
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is CONNECTING, CONNECTED, or LISTENING
69
+ * @throws {SocketError} with payload.tag 'invalid-argument' if ~remoteAddress~ is invalid or port == 0
70
+ * @throws {SocketError} for other errors, payload.tag maps the system error
71
+ */
72
+ connect(remoteAddress: any): Promise<void>;
73
+ /**
74
+ * Starts listening for connections
75
+ * WIT:
76
+ * ```
77
+ * listen: func() -> result<stream<tcp-socket>, error-code>
78
+ * ```
79
+ *
80
+ * @returns {StreamReader} A stream of incoming TCP socket connections
81
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is LISTENING or CONNECTED
82
+ * @throws {SocketError} for other errors, payload.tag maps the system error
83
+ */
84
+ listen(): StreamReader;
85
+ /**
86
+ * Sends data to the connected peer
87
+ * WIT:
88
+ * ```
89
+ * send: async func(data: stream<u8>) -> result<_, error-code>
90
+ * ```
91
+ *
92
+ * @async
93
+ * @param {object} data - The byte stream to send.
94
+ * @returns {Promise<void>}
95
+ * @throws {SocketError} With payload.tag 'invalid-state' if socket is not CONNECTED
96
+ * @throws {SocketError} With payload.tag 'invalid-argument' if `data` is not a readable byte stream
97
+ * @throws {SocketError} for other errors, payload.tag maps the system error
98
+ */
99
+ send(data: any): Promise<void>;
100
+ /**
101
+ * Receives data from the connected peer
102
+ * WIT:
103
+ * ```
104
+ * receive: func() -> tuple<stream<u8>, future<result<_, error-code>>>
105
+ * ```
106
+ *
107
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is not CONNECTED
108
+ * @throws {SocketError} for other errors, payload.tag maps the system error
109
+ * @returns {{ stream: StreamReader, future: FutureReader }}
110
+ */
111
+ receive(): (StreamReader | FutureReader)[];
112
+ /**
113
+ * Gets the bound local address
114
+ * WIT:
115
+ * ```
116
+ * local-address: func() -> result<ip-socket-address, error-code>
117
+ * ```
118
+ *
119
+ * @returns {Object} The local socket address
120
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is not BOUND
121
+ * @throws {SocketError} for other errors, payload.tag maps the system error
122
+ */
123
+ getLocalAddress(): any;
124
+ /**
125
+ * Gets the remote address
126
+ * WIT:
127
+ * ```
128
+ * remote-address: func() -> result<ip-socket-address, error-code>
129
+ * ```
130
+ *
131
+ * @returns {Object} The remote socket address
132
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is not CONNECTED
133
+ * @throws {SocketError} for other errors, payload.tag maps the system error
134
+ */
135
+ getRemoteAddress(): any;
136
+ /**
137
+ * Checks if the socket is in listening state
138
+ * WIT:
139
+ * ```
140
+ * is-listening: func() -> bool
141
+ * ```
142
+ *
143
+ * @returns {boolean} True if socket is listening, false otherwise
144
+ */
145
+ getIsListening(): boolean;
146
+ /**
147
+ * Gets the address family
148
+ * WIT:
149
+ * ```
150
+ * address-family: func() -> ip-address-family
151
+ * ```
152
+ *
153
+ * @returns {IP_ADDRESS_FAMILY} The IP address family (IPv4 or IPv6)
154
+ */
155
+ getAddressFamily(): any;
156
+ /**
157
+ * Sets the listen backlog size
158
+ * WIT:
159
+ * ```
160
+ * set-listen-backlog-size: func(value: u64) -> result<_, error-code>
161
+ * ```
162
+ *
163
+ * @param {bigint} value - The backlog size
164
+ * @returns {void}
165
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0
166
+ * @throws {SocketError} with payload.tag 'not-supported' if socket is CONNECTING or CONNECTED
167
+ * @throws {SocketError} with payload.tag 'invalid-state' if socket is not UNBOUND or BOUND
168
+ * @throws {SocketError} for other errors, payload.tag maps the system error
169
+ */
170
+ setListenBacklogSize(value: any): void;
171
+ /**
172
+ * Gets whether keep-alive is enabled
173
+ * WIT:
174
+ * ```
175
+ * keep-alive-enabled: func() -> result<bool, error-code>
176
+ * ```
177
+ *
178
+ * @returns {boolean} True if keep-alive is enabled, false otherwise
179
+ */
180
+ getKeepAliveEnabled(): boolean;
181
+ /**
182
+ * Sets keep-alive enabled state
183
+ * WIT:
184
+ * ```
185
+ * set-keep-alive-enabled: func(value: bool) -> result<_, error-code>
186
+ * ```
187
+ *
188
+ * @async
189
+ * @param {boolean} value - Whether to enable keep-alive
190
+ * @returns {void}
191
+ * @throws {SocketError} for other errors, payload.tag maps the system error
192
+ */
193
+ setKeepAliveEnabled(value: any): void;
194
+ /**
195
+ * Gets the keep-alive idle time
196
+ * WIT:
197
+ * ```
198
+ * keep-alive-idle-time: func() -> result<duration, error-code>
199
+ * ```
200
+ *
201
+ * @returns {bigint} The keep-alive idle time in nanoseconds
202
+ */
203
+ getKeepAliveIdleTime(): bigint;
204
+ /**
205
+ * Sets the keep-alive idle time
206
+ * WIT:
207
+ * ```
208
+ * set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>
209
+ * ```
210
+ *
211
+ * @param {bigint} value - The idle time in nanoseconds
212
+ * @returns {void}
213
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1
214
+ * @throws {SocketError} for other errors, payload.tag maps the system error
215
+ */
216
+ setKeepAliveIdleTime(value: any): void;
217
+ /**
218
+ * Gets the keep-alive interval
219
+ * WIT:
220
+ * ```
221
+ * keep-alive-interval: func() -> result<duration, error-code>
222
+ * ```
223
+ *
224
+ * @returns {bigint} The keep-alive interval in nanoseconds
225
+ */
226
+ getKeepAliveInterval(): bigint;
227
+ /**
228
+ * Sets the keep-alive interval
229
+ * WIT:
230
+ * ```
231
+ * set-keep-alive-interval: func(value: duration) -> result<_, error-code>
232
+ * ```
233
+ *
234
+ * @param {bigint} value - The interval in nanoseconds
235
+ * @returns {void}
236
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1
237
+ */
238
+ setKeepAliveInterval(value: any): void;
239
+ /**
240
+ * Gets the keep-alive count
241
+ * WIT:
242
+ * ```
243
+ * keep-alive-count: func() -> result<u32, error-code>
244
+ * ```
245
+ *
246
+ * @returns {number} The keep-alive count
247
+ */
248
+ getKeepAliveCount(): number;
249
+ /**
250
+ * Sets the keep-alive count
251
+ * WIT:
252
+ * ```
253
+ * set-keep-alive-count: func(value: u32) -> result<_, error-code>
254
+ * ```
255
+ *
256
+ * @param {number} value - The keep-alive count
257
+ * @returns {void}
258
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1
259
+ */
260
+ setKeepAliveCount(value: any): void;
261
+ /**
262
+ * Gets the hop limit
263
+ * WIT:
264
+ * ```
265
+ * hop-limit: func() -> result<u8, error-code>
266
+ * ```
267
+ *
268
+ * @returns {number} The hop limit
269
+ */
270
+ getHopLimit(): number;
271
+ /**
272
+ * Sets the hop limit
273
+ * WIT:
274
+ * ```
275
+ * set-hop-limit: func(value: u8) -> result<_, error-code>
276
+ * ```
277
+ *
278
+ * @param {number} value - The hop limit
279
+ * @returns {void}
280
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is less than 1
281
+ */
282
+ setHopLimit(value: any): void;
283
+ /**
284
+ * Gets the receive buffer size
285
+ * WIT:
286
+ * ```
287
+ * receive-buffer-size: func() -> result<u64, error-code>
288
+ * ```
289
+ *
290
+ * @returns {bigint} The receive buffer size in bytes
291
+ * @throws {SocketError} for other errors, payload.tag maps the system error
292
+ */
293
+ getReceiveBufferSize(): any;
294
+ /**
295
+ * Sets the receive buffer size
296
+ * WIT:
297
+ * ```
298
+ * set-receive-buffer-size: func(value: u64) -> result<_, error-code>
299
+ * ```
300
+ *
301
+ * @param {bigint} value - The receive buffer size in bytes
302
+ * @returns {void}
303
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0
304
+ */
305
+ setReceiveBufferSize(value: any): void;
306
+ /**
307
+ * Gets the send buffer size
308
+ * WIT:
309
+ * ```
310
+ * send-buffer-size: func() -> result<u64, error-code>
311
+ * ```
312
+ *
313
+ * @returns {bigint} The send buffer size in bytes
314
+ * @throws {SocketError} for other errors, payload.tag maps the system error
315
+ */
316
+ getSendBufferSize(): any;
317
+ /**
318
+ * Sets the send buffer size
319
+ * WIT:
320
+ * ```
321
+ * set-send-buffer-size: func(value: u64) -> result<_, error-code>
322
+ * ```
323
+ *
324
+ * @param {bigint} value - The send buffer size in bytes
325
+ * @returns {void}
326
+ * @throws {SocketError} with payload.tag 'invalid-argument' if `value` is 0
327
+ */
328
+ setSendBufferSize(value: any): void;
329
+ /**
330
+ * Disposes the socket
331
+ */
332
+ [Symbol.dispose](): void;
333
+ }