@eryx-org/eryx 0.15.0 → 0.15.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.
@@ -1,6 +1,15 @@
1
1
  /** @module Interface eryx:net/tcp@0.1.0 **/
2
+ /**
3
+ * @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
4
+ */
2
5
  export function connect(host: string, port: number, timeoutMs: number): TcpHandle;
6
+ /**
7
+ * @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
8
+ */
3
9
  export function read(handle: TcpHandle, len: number, timeoutMs: number): Uint8Array;
10
+ /**
11
+ * @throws {TcpError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
12
+ */
4
13
  export function write(handle: TcpHandle, timeoutMs: number, data: Uint8Array): number;
5
14
  export function close(handle: TcpHandle): void;
6
15
  export type TcpHandle = number;
@@ -1,6 +1,15 @@
1
1
  /** @module Interface eryx:net/tls@0.1.0 **/
2
+ /**
3
+ * @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
4
+ */
2
5
  export function upgrade(tcp: TcpHandle, hostname: string, timeoutMs: number): TlsHandle;
6
+ /**
7
+ * @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
8
+ */
3
9
  export function read(handle: TlsHandle, len: number, timeoutMs: number): Uint8Array;
10
+ /**
11
+ * @throws {TlsError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
12
+ */
4
13
  export function write(handle: TlsHandle, timeoutMs: number, data: Uint8Array): number;
5
14
  export function close(handle: TlsHandle): void;
6
15
  export type TcpHandle = import('./eryx-net-tcp.js').TcpHandle;
@@ -170,31 +170,109 @@ export class Descriptor {
170
170
  * This type does not have a public constructor.
171
171
  */
172
172
  private constructor();
173
+ /**
174
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
175
+ */
173
176
  readViaStream(offset: Filesize): InputStream;
177
+ /**
178
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
179
+ */
174
180
  writeViaStream(offset: Filesize): OutputStream;
181
+ /**
182
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
183
+ */
175
184
  appendViaStream(): OutputStream;
185
+ /**
186
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
187
+ */
176
188
  advise(offset: Filesize, length: Filesize, advice: Advice): void;
189
+ /**
190
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
191
+ */
177
192
  syncData(): void;
193
+ /**
194
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
195
+ */
178
196
  getFlags(): DescriptorFlags;
197
+ /**
198
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
199
+ */
179
200
  getType(): DescriptorType;
201
+ /**
202
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
203
+ */
180
204
  setSize(size: Filesize): void;
205
+ /**
206
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
207
+ */
181
208
  setTimes(dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
209
+ /**
210
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
211
+ */
182
212
  read(length: Filesize, offset: Filesize): [Uint8Array, boolean];
213
+ /**
214
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
215
+ */
183
216
  write(buffer: Uint8Array, offset: Filesize): Filesize;
217
+ /**
218
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
219
+ */
184
220
  readDirectory(): DirectoryEntryStream;
221
+ /**
222
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
223
+ */
185
224
  sync(): void;
225
+ /**
226
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
227
+ */
186
228
  createDirectoryAt(path: string): void;
229
+ /**
230
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
231
+ */
187
232
  stat(): DescriptorStat;
233
+ /**
234
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
235
+ */
188
236
  statAt(pathFlags: PathFlags, path: string): DescriptorStat;
237
+ /**
238
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
239
+ */
189
240
  setTimesAt(pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
241
+ /**
242
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
243
+ */
190
244
  linkAt(oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
245
+ /**
246
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
247
+ */
191
248
  openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Descriptor;
249
+ /**
250
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
251
+ */
192
252
  readlinkAt(path: string): string;
253
+ /**
254
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
255
+ */
193
256
  removeDirectoryAt(path: string): void;
257
+ /**
258
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
259
+ */
194
260
  renameAt(oldPath: string, newDescriptor: Descriptor, newPath: string): void;
261
+ /**
262
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
263
+ */
195
264
  symlinkAt(oldPath: string, newPath: string): void;
265
+ /**
266
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
267
+ */
196
268
  unlinkFileAt(path: string): void;
269
+ /**
270
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
271
+ */
197
272
  metadataHash(): MetadataHashValue;
273
+ /**
274
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
275
+ */
198
276
  metadataHashAt(pathFlags: PathFlags, path: string): MetadataHashValue;
199
277
  }
200
278
 
@@ -203,5 +281,8 @@ export class DirectoryEntryStream {
203
281
  * This type does not have a public constructor.
204
282
  */
205
283
  private constructor();
284
+ /**
285
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
286
+ */
206
287
  readDirectoryEntry(): DirectoryEntry | undefined;
207
288
  }
@@ -15,7 +15,13 @@ export class InputStream {
15
15
  * This type does not have a public constructor.
16
16
  */
17
17
  private constructor();
18
+ /**
19
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
20
+ */
18
21
  read(len: bigint): Uint8Array;
22
+ /**
23
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
24
+ */
19
25
  blockingRead(len: bigint): Uint8Array;
20
26
  subscribe(): Pollable;
21
27
  }
@@ -25,9 +31,21 @@ export class OutputStream {
25
31
  * This type does not have a public constructor.
26
32
  */
27
33
  private constructor();
34
+ /**
35
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
36
+ */
28
37
  checkWrite(): bigint;
38
+ /**
39
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
40
+ */
29
41
  write(contents: Uint8Array): void;
42
+ /**
43
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
44
+ */
30
45
  blockingWriteAndFlush(contents: Uint8Array): void;
46
+ /**
47
+ * @throws {StreamError} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
48
+ */
31
49
  blockingFlush(): void;
32
50
  subscribe(): Pollable;
33
51
  }
@@ -1,4 +1,7 @@
1
1
  /** @module Interface wasi:sockets/ip-name-lookup@0.2.0 **/
2
+ /**
3
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
4
+ */
2
5
  export function resolveAddresses(network: Network, name: string): ResolveAddressStream;
3
6
  export type IpAddress = import('./wasi-sockets-network.js').IpAddress;
4
7
  export type ErrorCode = import('./wasi-sockets-network.js').ErrorCode;
@@ -10,6 +13,9 @@ export class ResolveAddressStream {
10
13
  * This type does not have a public constructor.
11
14
  */
12
15
  private constructor();
16
+ /**
17
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
18
+ */
13
19
  resolveNextAddress(): IpAddress | undefined;
14
20
  subscribe(): Pollable;
15
21
  }
@@ -1,4 +1,7 @@
1
1
  /** @module Interface wasi:sockets/tcp-create-socket@0.2.0 **/
2
+ /**
3
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
4
+ */
2
5
  export function createTcpSocket(addressFamily: IpAddressFamily): TcpSocket;
3
6
  export type IpAddressFamily = import('./wasi-sockets-network.js').IpAddressFamily;
4
7
  export type TcpSocket = import('./wasi-sockets-tcp.js').TcpSocket;
@@ -22,31 +22,106 @@ export class TcpSocket {
22
22
  * This type does not have a public constructor.
23
23
  */
24
24
  private constructor();
25
+ /**
26
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
27
+ */
25
28
  startBind(network: Network, localAddress: IpSocketAddress): void;
29
+ /**
30
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
31
+ */
26
32
  finishBind(): void;
33
+ /**
34
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
35
+ */
27
36
  startConnect(network: Network, remoteAddress: IpSocketAddress): void;
37
+ /**
38
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
39
+ */
28
40
  finishConnect(): [InputStream, OutputStream];
41
+ /**
42
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
43
+ */
29
44
  startListen(): void;
45
+ /**
46
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
47
+ */
30
48
  finishListen(): void;
49
+ /**
50
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
51
+ */
31
52
  accept(): [TcpSocket, InputStream, OutputStream];
53
+ /**
54
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
55
+ */
32
56
  localAddress(): IpSocketAddress;
57
+ /**
58
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
59
+ */
33
60
  remoteAddress(): IpSocketAddress;
34
61
  isListening(): boolean;
62
+ /**
63
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
64
+ */
35
65
  setListenBacklogSize(value: bigint): void;
66
+ /**
67
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
68
+ */
36
69
  keepAliveEnabled(): boolean;
70
+ /**
71
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
72
+ */
37
73
  setKeepAliveEnabled(value: boolean): void;
74
+ /**
75
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
76
+ */
38
77
  keepAliveIdleTime(): Duration;
78
+ /**
79
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
80
+ */
39
81
  setKeepAliveIdleTime(value: Duration): void;
82
+ /**
83
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
84
+ */
40
85
  keepAliveInterval(): Duration;
86
+ /**
87
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
88
+ */
41
89
  setKeepAliveInterval(value: Duration): void;
90
+ /**
91
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
92
+ */
42
93
  keepAliveCount(): number;
94
+ /**
95
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
96
+ */
43
97
  setKeepAliveCount(value: number): void;
98
+ /**
99
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
100
+ */
44
101
  hopLimit(): number;
102
+ /**
103
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
104
+ */
45
105
  setHopLimit(value: number): void;
106
+ /**
107
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
108
+ */
46
109
  receiveBufferSize(): bigint;
110
+ /**
111
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
112
+ */
47
113
  setReceiveBufferSize(value: bigint): void;
114
+ /**
115
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
116
+ */
48
117
  sendBufferSize(): bigint;
118
+ /**
119
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
120
+ */
49
121
  setSendBufferSize(value: bigint): void;
50
122
  subscribe(): Pollable;
123
+ /**
124
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
125
+ */
51
126
  shutdown(shutdownType: ShutdownType): void;
52
127
  }
@@ -1,4 +1,7 @@
1
1
  /** @module Interface wasi:sockets/udp-create-socket@0.2.0 **/
2
+ /**
3
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
4
+ */
2
5
  export function createUdpSocket(addressFamily: IpAddressFamily): UdpSocket;
3
6
  export type IpAddressFamily = import('./wasi-sockets-network.js').IpAddressFamily;
4
7
  export type UdpSocket = import('./wasi-sockets-udp.js').UdpSocket;
@@ -17,6 +17,9 @@ export class IncomingDatagramStream {
17
17
  * This type does not have a public constructor.
18
18
  */
19
19
  private constructor();
20
+ /**
21
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
22
+ */
20
23
  receive(maxResults: bigint): Array<IncomingDatagram>;
21
24
  subscribe(): Pollable;
22
25
  }
@@ -26,7 +29,13 @@ export class OutgoingDatagramStream {
26
29
  * This type does not have a public constructor.
27
30
  */
28
31
  private constructor();
32
+ /**
33
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
34
+ */
29
35
  checkSend(): bigint;
36
+ /**
37
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
38
+ */
30
39
  send(datagrams: Array<OutgoingDatagram>): bigint;
31
40
  subscribe(): Pollable;
32
41
  }
@@ -36,16 +45,49 @@ export class UdpSocket {
36
45
  * This type does not have a public constructor.
37
46
  */
38
47
  private constructor();
48
+ /**
49
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
50
+ */
39
51
  startBind(network: Network, localAddress: IpSocketAddress): void;
52
+ /**
53
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
54
+ */
40
55
  finishBind(): void;
56
+ /**
57
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
58
+ */
41
59
  stream(remoteAddress: IpSocketAddress | undefined): [IncomingDatagramStream, OutgoingDatagramStream];
60
+ /**
61
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
62
+ */
42
63
  localAddress(): IpSocketAddress;
64
+ /**
65
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
66
+ */
43
67
  remoteAddress(): IpSocketAddress;
68
+ /**
69
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
70
+ */
44
71
  unicastHopLimit(): number;
72
+ /**
73
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
74
+ */
45
75
  setUnicastHopLimit(value: number): void;
76
+ /**
77
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
78
+ */
46
79
  receiveBufferSize(): bigint;
80
+ /**
81
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
82
+ */
47
83
  setReceiveBufferSize(value: bigint): void;
84
+ /**
85
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
86
+ */
48
87
  sendBufferSize(): bigint;
88
+ /**
89
+ * @throws {ErrorCode} To return the error of the result, throw it, or an `Error` that has it as its `payload`.
90
+ */
49
91
  setSendBufferSize(value: bigint): void;
50
92
  subscribe(): Pollable;
51
93
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@eryx-org/eryx",
3
3
  "type": "module",
4
4
  "description": "A Python sandbox powered by WebAssembly, for browser and Node.js",
5
- "version": "0.15.0",
5
+ "version": "0.15.1",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
package/shims/net.js CHANGED
@@ -117,13 +117,18 @@ function checkTimeout(name, value) {
117
117
  * Check `netConfig` and fill in the defaults; null disables networking.
118
118
  *
119
119
  * Throws a TypeError if a network is not a valid CIDR, maxConnections is
120
- * not a non-negative integer, or a timeout is not greater than zero.
120
+ * not a non-negative integer, a timeout is not greater than zero, or
121
+ * httpRules (the Rust crate's method and path rules) are given.
121
122
  *
122
123
  * @param {import("./net.js").NetConfig | null} netConfig
123
124
  * @returns {Policy | null}
124
125
  */
125
126
  function toPolicy(netConfig) {
126
127
  if (!netConfig) return null;
128
+ // Requests aren't parsed here, so rules couldn't be enforced.
129
+ if (netConfig.httpRules?.length) {
130
+ throw new TypeError("httpRules are not supported by the JavaScript host");
131
+ }
127
132
  // Copies, so changing the caller's arrays later can't change the policy.
128
133
  const list = (xs, fallback) => Object.freeze([...(xs ?? fallback)]);
129
134
  const next = {