@bytecodealliance/preview2-shim 0.0.3 → 0.0.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 (75) hide show
  1. package/lib/browser/default-outgoing-HTTP.js +3 -0
  2. package/lib/browser/environment-preopens.js +3 -0
  3. package/lib/browser/http.js +17 -10
  4. package/lib/browser/index.js +34 -12
  5. package/lib/browser/instance-monotonic-clock.js +3 -0
  6. package/lib/browser/instance-wall-clock.js +3 -0
  7. package/lib/browser/io.js +10 -23
  8. package/lib/browser/poll.js +4 -0
  9. package/lib/browser/preopens.js +11 -0
  10. package/lib/browser/random.js +1 -1
  11. package/lib/browser/streams.js +60 -0
  12. package/lib/browser/types.js +99 -0
  13. package/lib/http/error.js +1 -1
  14. package/lib/http/make-request.js +4 -4
  15. package/lib/http/synckit/index.d.ts +71 -0
  16. package/lib/http/synckit/index.js +141 -0
  17. package/lib/http/wasi-http.js +267 -0
  18. package/lib/nodejs/default-outgoing-HTTP.js +3 -0
  19. package/lib/nodejs/environment-preopens.js +3 -0
  20. package/lib/nodejs/environment.js +4 -0
  21. package/lib/nodejs/filesystem.js +7 -5
  22. package/lib/nodejs/http.js +4 -4
  23. package/lib/nodejs/index.js +34 -12
  24. package/lib/nodejs/instance-monotonic-clock.js +3 -0
  25. package/lib/nodejs/instance-wall-clock.js +3 -0
  26. package/lib/nodejs/io.js +16 -24
  27. package/lib/nodejs/monotonic-clock.js +4 -0
  28. package/lib/nodejs/poll.js +4 -0
  29. package/lib/nodejs/preopens.js +11 -0
  30. package/lib/nodejs/random.js +1 -1
  31. package/lib/nodejs/streams.js +63 -0
  32. package/lib/nodejs/types.js +99 -0
  33. package/lib/nodejs/wall-clock.js +4 -0
  34. package/package.json +18 -3
  35. package/types/exports/HTTP.d.ts +7 -0
  36. package/types/imports/console.d.ts +17 -0
  37. package/types/imports/default-outgoing-HTTP.d.ts +9 -0
  38. package/types/imports/environment-preopens.d.ts +5 -0
  39. package/types/imports/environment.d.ts +3 -0
  40. package/types/imports/exit.d.ts +4 -0
  41. package/types/imports/filesystem.d.ts +212 -0
  42. package/types/imports/instance-monotonic-clock.d.ts +5 -0
  43. package/types/imports/instance-network.d.ts +5 -0
  44. package/types/imports/instance-wall-clock.d.ts +5 -0
  45. package/types/imports/ip-name-lookup.d.ts +19 -0
  46. package/types/imports/monotonic-clock.d.ts +10 -0
  47. package/types/imports/network.d.ts +50 -0
  48. package/types/imports/poll.d.ts +5 -0
  49. package/types/imports/preopens.d.ts +15 -0
  50. package/types/imports/random.d.ts +5 -0
  51. package/types/{wasi-stderr.d.ts → imports/stderr.d.ts} +1 -1
  52. package/types/imports/streams.d.ts +23 -0
  53. package/types/imports/tcp-create-socket.d.ts +9 -0
  54. package/types/imports/tcp.d.ts +52 -0
  55. package/types/imports/timezone.d.ts +13 -0
  56. package/types/imports/types.d.ts +119 -0
  57. package/types/imports/udp-create-socket.d.ts +9 -0
  58. package/types/imports/udp.d.ts +36 -0
  59. package/types/imports/wall-clock.d.ts +10 -0
  60. package/types/index.d.ts +8 -9
  61. package/types/wasi-proxy.d.ts +44 -0
  62. package/types/wasi-reactor.d.ts +72 -0
  63. package/lib/browser/clocks.js +0 -47
  64. package/lib/browser/default-clocks.js +0 -7
  65. package/lib/nodejs/default-clocks.js +0 -7
  66. package/types/wasi-clocks.d.ts +0 -11
  67. package/types/wasi-default-clocks.d.ts +0 -6
  68. package/types/wasi-exit.d.ts +0 -3
  69. package/types/wasi-filesystem.d.ts +0 -150
  70. package/types/wasi-http.d.ts +0 -55
  71. package/types/wasi-io.d.ts +0 -10
  72. package/types/wasi-poll.d.ts +0 -4
  73. package/types/wasi-random.d.ts +0 -3
  74. /package/lib/browser/{logging.js → console.js} +0 -0
  75. /package/lib/nodejs/{logging.js → console.js} +0 -0
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
6
  "type": "module",
7
+ "types": "./types/index.d.ts",
7
8
  "exports": {
9
+ ".": {
10
+ "types": "./types/index.d.ts",
11
+ "node": "./lib/nodejs/index.js",
12
+ "default": "./lib/browser/index.js"
13
+ },
8
14
  "./*": {
9
- "types": "./types/*.js",
15
+ "types": "./types/*.d.ts",
10
16
  "node": "./lib/nodejs/*.js",
11
17
  "default": "./lib/browser/*.js"
12
18
  }
@@ -20,5 +26,14 @@
20
26
  ],
21
27
  "devDependencies": {
22
28
  "mocha": "^10.2.0"
23
- }
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/bytecodealliance/jco.git"
33
+ },
34
+ "license": "(Apache-2.0 WITH LLVM-exception)",
35
+ "bugs": {
36
+ "url": "https://github.com/bytecodealliance/jco/issues"
37
+ },
38
+ "homepage": "https://github.com/bytecodealliance/jco#readme"
24
39
  }
@@ -0,0 +1,7 @@
1
+ export namespace Http {
2
+ export function handle(request: IncomingRequest, responseOut: ResponseOutparam): void;
3
+ }
4
+ import type { IncomingRequest } from '../imports/types';
5
+ export { IncomingRequest };
6
+ import type { ResponseOutparam } from '../imports/types';
7
+ export { ResponseOutparam };
@@ -0,0 +1,17 @@
1
+ export namespace Console {
2
+ export function log(level: Level, context: string, message: string): void;
3
+ }
4
+ /**
5
+ * # Variants
6
+ *
7
+ * ## `"trace"`
8
+ *
9
+ * ## `"debug"`
10
+ *
11
+ * ## `"info"`
12
+ *
13
+ * ## `"warn"`
14
+ *
15
+ * ## `"error"`
16
+ */
17
+ export type Level = 'trace' | 'debug' | 'info' | 'warn' | 'error';
@@ -0,0 +1,9 @@
1
+ export namespace DefaultOutgoingHttp {
2
+ export function handle(request: OutgoingRequest, options: RequestOptions | null): FutureIncomingResponse;
3
+ }
4
+ import type { OutgoingRequest } from '../imports/types';
5
+ export { OutgoingRequest };
6
+ import type { RequestOptions } from '../imports/types';
7
+ export { RequestOptions };
8
+ import type { FutureIncomingResponse } from '../imports/types';
9
+ export { FutureIncomingResponse };
@@ -0,0 +1,5 @@
1
+ export namespace EnvironmentPreopens {
2
+ export function preopens(): [Descriptor, string][];
3
+ }
4
+ import type { Descriptor } from '../imports/filesystem';
5
+ export { Descriptor };
@@ -0,0 +1,3 @@
1
+ export namespace Environment {
2
+ export function getEnvironment(): [string, string][];
3
+ }
@@ -0,0 +1,4 @@
1
+ export namespace Exit {
2
+ export function exit(status: Result<void, void>): void;
3
+ }
4
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -0,0 +1,212 @@
1
+ export namespace Filesystem {
2
+ export function readViaStream(this: Descriptor, offset: Filesize): InputStream;
3
+ export function writeViaStream(this: Descriptor, offset: Filesize): OutputStream;
4
+ export function appendViaStream(this: Descriptor): OutputStream;
5
+ export function advise(this: Descriptor, offset: Filesize, length: Filesize, advice: Advice): void;
6
+ export function syncData(this: Descriptor): void;
7
+ export function getFlags(this: Descriptor): DescriptorFlags;
8
+ export function getType(this: Descriptor): DescriptorType;
9
+ export function setFlags(this: Descriptor, flags: DescriptorFlags): void;
10
+ export function setSize(this: Descriptor, size: Filesize): void;
11
+ export function setTimes(this: Descriptor, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
12
+ export function read(this: Descriptor, length: Filesize, offset: Filesize): [Uint8Array | ArrayBuffer, boolean];
13
+ export function write(this: Descriptor, buffer: Uint8Array, offset: Filesize): Filesize;
14
+ export function readDirectory(this: Descriptor): DirectoryEntryStream;
15
+ export function sync(this: Descriptor): void;
16
+ export function createDirectoryAt(this: Descriptor, path: string): void;
17
+ export function stat(this: Descriptor): DescriptorStat;
18
+ export function statAt(this: Descriptor, pathFlags: PathFlags, path: string): DescriptorStat;
19
+ export function setTimesAt(this: Descriptor, pathFlags: PathFlags, path: string, dataAccessTimestamp: NewTimestamp, dataModificationTimestamp: NewTimestamp): void;
20
+ export function linkAt(this: Descriptor, oldPathFlags: PathFlags, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
21
+ export function openAt(this: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
22
+ export function readlinkAt(this: Descriptor, path: string): string;
23
+ export function removeDirectoryAt(this: Descriptor, path: string): void;
24
+ export function renameAt(this: Descriptor, oldPath: string, newDescriptor: Descriptor, newPath: string): void;
25
+ export function symlinkAt(this: Descriptor, oldPath: string, newPath: string): void;
26
+ export function unlinkFileAt(this: Descriptor, path: string): void;
27
+ export function changeFilePermissionsAt(this: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
28
+ export function changeDirectoryPermissionsAt(this: Descriptor, pathFlags: PathFlags, path: string, modes: Modes): void;
29
+ export function lockShared(this: Descriptor): void;
30
+ export function lockExclusive(this: Descriptor): void;
31
+ export function tryLockShared(this: Descriptor): void;
32
+ export function tryLockExclusive(this: Descriptor): void;
33
+ export function unlock(this: Descriptor): void;
34
+ export function dropDescriptor(this: Descriptor): void;
35
+ export function readDirectoryEntry(this: DirectoryEntryStream): DirectoryEntry | null;
36
+ export function dropDirectoryEntryStream(this: DirectoryEntryStream): void;
37
+ }
38
+ export type Descriptor = number;
39
+ export type Filesize = bigint;
40
+ import type { InputStream } from '../imports/streams';
41
+ export { InputStream };
42
+ import type { OutputStream } from '../imports/streams';
43
+ export { OutputStream };
44
+ /**
45
+ * # Variants
46
+ *
47
+ * ## `"normal"`
48
+ *
49
+ * ## `"sequential"`
50
+ *
51
+ * ## `"random"`
52
+ *
53
+ * ## `"will-need"`
54
+ *
55
+ * ## `"dont-need"`
56
+ *
57
+ * ## `"no-reuse"`
58
+ */
59
+ export type Advice = 'normal' | 'sequential' | 'random' | 'will-need' | 'dont-need' | 'no-reuse';
60
+ /**
61
+ * # Variants
62
+ *
63
+ * ## `"access"`
64
+ *
65
+ * ## `"would-block"`
66
+ *
67
+ * ## `"already"`
68
+ *
69
+ * ## `"bad-descriptor"`
70
+ *
71
+ * ## `"busy"`
72
+ *
73
+ * ## `"deadlock"`
74
+ *
75
+ * ## `"quota"`
76
+ *
77
+ * ## `"exist"`
78
+ *
79
+ * ## `"file-too-large"`
80
+ *
81
+ * ## `"illegal-byte-sequence"`
82
+ *
83
+ * ## `"in-progress"`
84
+ *
85
+ * ## `"interrupted"`
86
+ *
87
+ * ## `"invalid"`
88
+ *
89
+ * ## `"io"`
90
+ *
91
+ * ## `"is-directory"`
92
+ *
93
+ * ## `"loop"`
94
+ *
95
+ * ## `"too-many-links"`
96
+ *
97
+ * ## `"message-size"`
98
+ *
99
+ * ## `"name-too-long"`
100
+ *
101
+ * ## `"no-device"`
102
+ *
103
+ * ## `"no-entry"`
104
+ *
105
+ * ## `"no-lock"`
106
+ *
107
+ * ## `"insufficient-memory"`
108
+ *
109
+ * ## `"insufficient-space"`
110
+ *
111
+ * ## `"not-directory"`
112
+ *
113
+ * ## `"not-empty"`
114
+ *
115
+ * ## `"not-recoverable"`
116
+ *
117
+ * ## `"unsupported"`
118
+ *
119
+ * ## `"no-tty"`
120
+ *
121
+ * ## `"no-such-device"`
122
+ *
123
+ * ## `"overflow"`
124
+ *
125
+ * ## `"not-permitted"`
126
+ *
127
+ * ## `"pipe"`
128
+ *
129
+ * ## `"read-only"`
130
+ *
131
+ * ## `"invalid-seek"`
132
+ *
133
+ * ## `"text-file-busy"`
134
+ *
135
+ * ## `"cross-device"`
136
+ */
137
+ export type ErrorCode = 'access' | 'would-block' | 'already' | 'bad-descriptor' | 'busy' | 'deadlock' | 'quota' | 'exist' | 'file-too-large' | 'illegal-byte-sequence' | 'in-progress' | 'interrupted' | 'invalid' | 'io' | 'is-directory' | 'loop' | 'too-many-links' | 'message-size' | 'name-too-long' | 'no-device' | 'no-entry' | 'no-lock' | 'insufficient-memory' | 'insufficient-space' | 'not-directory' | 'not-empty' | 'not-recoverable' | 'unsupported' | 'no-tty' | 'no-such-device' | 'overflow' | 'not-permitted' | 'pipe' | 'read-only' | 'invalid-seek' | 'text-file-busy' | 'cross-device';
138
+ export interface DescriptorFlags {
139
+ read?: boolean,
140
+ write?: boolean,
141
+ nonBlocking?: boolean,
142
+ fileIntegritySync?: boolean,
143
+ dataIntegritySync?: boolean,
144
+ requestedWriteSync?: boolean,
145
+ mutateDirectory?: boolean,
146
+ }
147
+ /**
148
+ * # Variants
149
+ *
150
+ * ## `"unknown"`
151
+ *
152
+ * ## `"block-device"`
153
+ *
154
+ * ## `"character-device"`
155
+ *
156
+ * ## `"directory"`
157
+ *
158
+ * ## `"fifo"`
159
+ *
160
+ * ## `"symbolic-link"`
161
+ *
162
+ * ## `"regular-file"`
163
+ *
164
+ * ## `"socket"`
165
+ */
166
+ export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
167
+ import type { Datetime } from '../imports/wall-clock';
168
+ export { Datetime };
169
+ export type NewTimestamp = NewTimestampNoChange | NewTimestampNow | NewTimestampTimestamp;
170
+ export interface NewTimestampNoChange {
171
+ tag: 'no-change',
172
+ }
173
+ export interface NewTimestampNow {
174
+ tag: 'now',
175
+ }
176
+ export interface NewTimestampTimestamp {
177
+ tag: 'timestamp',
178
+ val: Datetime,
179
+ }
180
+ export type DirectoryEntryStream = number;
181
+ export type Device = bigint;
182
+ export type Inode = bigint;
183
+ export type LinkCount = bigint;
184
+ export interface DescriptorStat {
185
+ device: Device,
186
+ inode: Inode,
187
+ type: DescriptorType,
188
+ linkCount: LinkCount,
189
+ size: Filesize,
190
+ dataAccessTimestamp: Datetime,
191
+ dataModificationTimestamp: Datetime,
192
+ statusChangeTimestamp: Datetime,
193
+ }
194
+ export interface PathFlags {
195
+ symlinkFollow?: boolean,
196
+ }
197
+ export interface OpenFlags {
198
+ create?: boolean,
199
+ directory?: boolean,
200
+ exclusive?: boolean,
201
+ truncate?: boolean,
202
+ }
203
+ export interface Modes {
204
+ readable?: boolean,
205
+ writeable?: boolean,
206
+ executable?: boolean,
207
+ }
208
+ export interface DirectoryEntry {
209
+ inode?: Inode,
210
+ type: DescriptorType,
211
+ name: string,
212
+ }
@@ -0,0 +1,5 @@
1
+ export namespace InstanceMonotonicClock {
2
+ export function instanceMonotonicClock(): MonotonicClock;
3
+ }
4
+ import type { MonotonicClock } from '../imports/monotonic-clock';
5
+ export { MonotonicClock };
@@ -0,0 +1,5 @@
1
+ export namespace InstanceNetwork {
2
+ export function instanceNetwork(): Network;
3
+ }
4
+ import type { Network } from '../imports/network';
5
+ export { Network };
@@ -0,0 +1,5 @@
1
+ export namespace InstanceWallClock {
2
+ export function instanceWallClock(): WallClock;
3
+ }
4
+ import type { WallClock } from '../imports/wall-clock';
5
+ export { WallClock };
@@ -0,0 +1,19 @@
1
+ export namespace IpNameLookup {
2
+ export function resolveAddresses(network: Network, name: string, addressFamily: IpAddressFamily | null, includeUnavailable: boolean): ResolveAddressStream;
3
+ export function resolveNextAddress(this: ResolveAddressStream): IpAddress | null;
4
+ export function dropResolveAddressStream(this: ResolveAddressStream): void;
5
+ export function nonBlocking(this: ResolveAddressStream): boolean;
6
+ export function setNonBlocking(this: ResolveAddressStream, value: boolean): void;
7
+ export function subscribe(this: ResolveAddressStream): Pollable;
8
+ }
9
+ import type { Network } from '../imports/network';
10
+ export { Network };
11
+ import type { IpAddressFamily } from '../imports/network';
12
+ export { IpAddressFamily };
13
+ export type ResolveAddressStream = number;
14
+ import type { Error } from '../imports/network';
15
+ export { Error };
16
+ import type { IpAddress } from '../imports/network';
17
+ export { IpAddress };
18
+ import type { Pollable } from '../imports/poll';
19
+ export { Pollable };
@@ -0,0 +1,10 @@
1
+ export namespace MonotonicClock {
2
+ export function now(this: MonotonicClock): Instant;
3
+ export function resolution(this: MonotonicClock): Instant;
4
+ export function subscribe(this: MonotonicClock, when: Instant, absolute: boolean): Pollable;
5
+ export function dropMonotonicClock(this: MonotonicClock): void;
6
+ }
7
+ export type MonotonicClock = number;
8
+ export type Instant = bigint;
9
+ import type { Pollable } from '../imports/poll';
10
+ export { Pollable };
@@ -0,0 +1,50 @@
1
+ export namespace Network {
2
+ export function dropNetwork(this: Network): void;
3
+ }
4
+ export type Network = number;
5
+ export type Ipv6Address = [number, number, number, number, number, number, number, number];
6
+ export interface Ipv6SocketAddress {
7
+ port: number,
8
+ flowInfo: number,
9
+ address: Ipv6Address,
10
+ scopeId: number,
11
+ }
12
+ export type Ipv4Address = [number, number, number, number];
13
+ export interface Ipv4SocketAddress {
14
+ port: number,
15
+ address: Ipv4Address,
16
+ }
17
+ export type IpSocketAddress = IpSocketAddressIpv4 | IpSocketAddressIpv6;
18
+ export interface IpSocketAddressIpv4 {
19
+ tag: 'ipv4',
20
+ val: Ipv4SocketAddress,
21
+ }
22
+ export interface IpSocketAddressIpv6 {
23
+ tag: 'ipv6',
24
+ val: Ipv6SocketAddress,
25
+ }
26
+ export type IpAddress = IpAddressIpv4 | IpAddressIpv6;
27
+ export interface IpAddressIpv4 {
28
+ tag: 'ipv4',
29
+ val: Ipv4Address,
30
+ }
31
+ export interface IpAddressIpv6 {
32
+ tag: 'ipv6',
33
+ val: Ipv6Address,
34
+ }
35
+ /**
36
+ * # Variants
37
+ *
38
+ * ## `"unknown"`
39
+ *
40
+ * ## `"again"`
41
+ */
42
+ export type Error = 'unknown' | 'again';
43
+ /**
44
+ * # Variants
45
+ *
46
+ * ## `"ipv4"`
47
+ *
48
+ * ## `"ipv6"`
49
+ */
50
+ export type IpAddressFamily = 'ipv4' | 'ipv6';
@@ -0,0 +1,5 @@
1
+ export namespace Poll {
2
+ export function dropPollable(this: Pollable): void;
3
+ export function pollOneoff(in_: Uint32Array): Uint8Array | ArrayBuffer;
4
+ }
5
+ export type Pollable = number;
@@ -0,0 +1,15 @@
1
+ export namespace Preopens {
2
+ export function getStdio(): StdioPreopens;
3
+ export function getDirectories(): [Descriptor, string][];
4
+ }
5
+ import type { InputStream } from '../imports/streams';
6
+ export { InputStream };
7
+ import type { OutputStream } from '../imports/streams';
8
+ export { OutputStream };
9
+ export interface StdioPreopens {
10
+ stdin: InputStream,
11
+ stdout: OutputStream,
12
+ stderr: OutputStream,
13
+ }
14
+ import type { Descriptor } from '../imports/filesystem';
15
+ export { Descriptor };
@@ -0,0 +1,5 @@
1
+ export namespace Random {
2
+ export function getRandomBytes(len: bigint): Uint8Array | ArrayBuffer;
3
+ export function getRandomU64(): bigint;
4
+ export function insecureRandom(): [bigint, bigint];
5
+ }
@@ -1,3 +1,3 @@
1
- export namespace WasiStderr {
1
+ export namespace Stderr {
2
2
  export function print(message: string): void;
3
3
  }
@@ -0,0 +1,23 @@
1
+ export namespace Streams {
2
+ export function read(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
3
+ export function blockingRead(this: InputStream, len: bigint): [Uint8Array | ArrayBuffer, boolean];
4
+ export function skip(this: InputStream, len: bigint): [bigint, boolean];
5
+ export function blockingSkip(this: InputStream, len: bigint): [bigint, boolean];
6
+ export function subscribeToInputStream(this: InputStream): Pollable;
7
+ export function dropInputStream(this: InputStream): void;
8
+ export function write(this: OutputStream, buf: Uint8Array): bigint;
9
+ export function blockingWrite(this: OutputStream, buf: Uint8Array): bigint;
10
+ export function writeZeroes(this: OutputStream, len: bigint): bigint;
11
+ export function blockingWriteZeroes(this: OutputStream, len: bigint): bigint;
12
+ export function splice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
13
+ export function blockingSplice(this: OutputStream, src: InputStream, len: bigint): [bigint, boolean];
14
+ export function forward(this: OutputStream, src: InputStream): bigint;
15
+ export function subscribeToOutputStream(this: OutputStream): Pollable;
16
+ export function dropOutputStream(this: OutputStream): void;
17
+ }
18
+ export type InputStream = number;
19
+ export interface StreamError {
20
+ }
21
+ import type { Pollable } from '../imports/poll';
22
+ export { Pollable };
23
+ export type OutputStream = number;
@@ -0,0 +1,9 @@
1
+ export namespace TcpCreateSocket {
2
+ export function createTcpSocket(addressFamily: IpAddressFamily): TcpSocket;
3
+ }
4
+ import type { IpAddressFamily } from '../imports/network';
5
+ export { IpAddressFamily };
6
+ import type { TcpSocket } from '../imports/tcp';
7
+ export { TcpSocket };
8
+ import type { Error } from '../imports/network';
9
+ export { Error };
@@ -0,0 +1,52 @@
1
+ export namespace Tcp {
2
+ export function bind(this: TcpSocket, network: Network, localAddress: IpSocketAddress): void;
3
+ export function connect(this: TcpSocket, network: Network, remoteAddress: IpSocketAddress): [InputStream, OutputStream];
4
+ export function listen(this: TcpSocket, network: Network): void;
5
+ export function accept(this: TcpSocket): [TcpSocket, InputStream, OutputStream];
6
+ export function localAddress(this: TcpSocket): IpSocketAddress;
7
+ export function remoteAddress(this: TcpSocket): IpSocketAddress;
8
+ export function addressFamily(this: TcpSocket): IpAddressFamily;
9
+ export function ipv6Only(this: TcpSocket): boolean;
10
+ export function setIpv6Only(this: TcpSocket, value: boolean): void;
11
+ export function setListenBacklogSize(this: TcpSocket, value: bigint): void;
12
+ export function keepAlive(this: TcpSocket): boolean;
13
+ export function setKeepAlive(this: TcpSocket, value: boolean): void;
14
+ export function noDelay(this: TcpSocket): boolean;
15
+ export function setNoDelay(this: TcpSocket, value: boolean): void;
16
+ export function unicastHopLimit(this: TcpSocket): number;
17
+ export function setUnicastHopLimit(this: TcpSocket, value: number): void;
18
+ export function receiveBufferSize(this: TcpSocket): bigint;
19
+ export function setReceiveBufferSize(this: TcpSocket, value: bigint): void;
20
+ export function sendBufferSize(this: TcpSocket): bigint;
21
+ export function setSendBufferSize(this: TcpSocket, value: bigint): void;
22
+ export function nonBlocking(this: TcpSocket): boolean;
23
+ export function setNonBlocking(this: TcpSocket, value: boolean): void;
24
+ export function subscribe(this: TcpSocket): Pollable;
25
+ export function shutdown(this: TcpSocket, shutdownType: ShutdownType): void;
26
+ export function dropTcpSocket(this: TcpSocket): void;
27
+ }
28
+ export type TcpSocket = number;
29
+ import type { Network } from '../imports/network';
30
+ export { Network };
31
+ import type { IpSocketAddress } from '../imports/network';
32
+ export { IpSocketAddress };
33
+ import type { Error } from '../imports/network';
34
+ export { Error };
35
+ import type { InputStream } from '../imports/streams';
36
+ export { InputStream };
37
+ import type { OutputStream } from '../imports/streams';
38
+ export { OutputStream };
39
+ import type { IpAddressFamily } from '../imports/network';
40
+ export { IpAddressFamily };
41
+ import type { Pollable } from '../imports/poll';
42
+ export { Pollable };
43
+ /**
44
+ * # Variants
45
+ *
46
+ * ## `"receive"`
47
+ *
48
+ * ## `"send"`
49
+ *
50
+ * ## `"both"`
51
+ */
52
+ export type ShutdownType = 'receive' | 'send' | 'both';
@@ -0,0 +1,13 @@
1
+ export namespace Timezone {
2
+ export function display(this: Timezone, when: Datetime): TimezoneDisplay;
3
+ export function utcOffset(this: Timezone, when: Datetime): number;
4
+ export function dropTimezone(this: Timezone): void;
5
+ }
6
+ export type Timezone = number;
7
+ import type { Datetime } from '../imports/wall-clock';
8
+ export { Datetime };
9
+ export interface TimezoneDisplay {
10
+ utcOffset: number,
11
+ name: string,
12
+ inDaylightSavingTime: boolean,
13
+ }
@@ -0,0 +1,119 @@
1
+ export namespace Types {
2
+ export function dropFields(fields: Fields): void;
3
+ export function newFields(entries: [string, string][]): Fields;
4
+ export function fieldsGet(fields: Fields, name: string): string[];
5
+ export function fieldsSet(fields: Fields, name: string, value: string[]): void;
6
+ export function fieldsDelete(fields: Fields, name: string): void;
7
+ export function fieldsAppend(fields: Fields, name: string, value: string): void;
8
+ export function fieldsEntries(fields: Fields): [string, string][];
9
+ export function fieldsClone(fields: Fields): Fields;
10
+ export function finishIncomingStream(s: IncomingStream): Trailers | null;
11
+ export function finishOutgoingStream(s: OutgoingStream, trailers: Trailers | null): void;
12
+ export function dropIncomingRequest(request: IncomingRequest): void;
13
+ export function dropOutgoingRequest(request: OutgoingRequest): void;
14
+ export function incomingRequestMethod(request: IncomingRequest): Method;
15
+ export function incomingRequestPath(request: IncomingRequest): string;
16
+ export function incomingRequestQuery(request: IncomingRequest): string;
17
+ export function incomingRequestScheme(request: IncomingRequest): Scheme | null;
18
+ export function incomingRequestAuthority(request: IncomingRequest): string;
19
+ export function incomingRequestHeaders(request: IncomingRequest): Headers;
20
+ export function incomingRequestConsume(request: IncomingRequest): IncomingStream;
21
+ export function newOutgoingRequest(method: Method, path: string, query: string, scheme: Scheme | null, authority: string, headers: Headers): OutgoingRequest;
22
+ export function outgoingRequestWrite(request: OutgoingRequest): OutgoingStream;
23
+ export function dropResponseOutparam(response: ResponseOutparam): void;
24
+ export function setResponseOutparam(response: Result<OutgoingResponse, Error>): void;
25
+ export function dropIncomingResponse(response: IncomingResponse): void;
26
+ export function dropOutgoingResponse(response: OutgoingResponse): void;
27
+ export function incomingResponseStatus(response: IncomingResponse): StatusCode;
28
+ export function incomingResponseHeaders(response: IncomingResponse): Headers;
29
+ export function incomingResponseConsume(response: IncomingResponse): IncomingStream;
30
+ export function newOutgoingResponse(statusCode: StatusCode, headers: Headers): OutgoingResponse;
31
+ export function outgoingResponseWrite(response: OutgoingResponse): OutgoingStream;
32
+ export function dropFutureIncomingResponse(f: FutureIncomingResponse): void;
33
+ export function futureIncomingResponseGet(f: FutureIncomingResponse): Result<IncomingResponse, Error> | null;
34
+ export function listenToFutureIncomingResponse(f: FutureIncomingResponse): Pollable;
35
+ }
36
+ export type Fields = number;
37
+ import type { InputStream } from '../imports/streams';
38
+ export { InputStream };
39
+ export type IncomingStream = InputStream;
40
+ export type Trailers = Fields;
41
+ import type { OutputStream } from '../imports/streams';
42
+ export { OutputStream };
43
+ export type OutgoingStream = OutputStream;
44
+ export type IncomingRequest = number;
45
+ export type OutgoingRequest = number;
46
+ export type Method = MethodGet | MethodHead | MethodPost | MethodPut | MethodDelete | MethodConnect | MethodOptions | MethodTrace | MethodPatch | MethodOther;
47
+ export interface MethodGet {
48
+ tag: 'get',
49
+ }
50
+ export interface MethodHead {
51
+ tag: 'head',
52
+ }
53
+ export interface MethodPost {
54
+ tag: 'post',
55
+ }
56
+ export interface MethodPut {
57
+ tag: 'put',
58
+ }
59
+ export interface MethodDelete {
60
+ tag: 'delete',
61
+ }
62
+ export interface MethodConnect {
63
+ tag: 'connect',
64
+ }
65
+ export interface MethodOptions {
66
+ tag: 'options',
67
+ }
68
+ export interface MethodTrace {
69
+ tag: 'trace',
70
+ }
71
+ export interface MethodPatch {
72
+ tag: 'patch',
73
+ }
74
+ export interface MethodOther {
75
+ tag: 'other',
76
+ val: string,
77
+ }
78
+ export type Scheme = SchemeHttp | SchemeHttps | SchemeOther;
79
+ export interface SchemeHttp {
80
+ tag: 'HTTP',
81
+ }
82
+ export interface SchemeHttps {
83
+ tag: 'HTTPS',
84
+ }
85
+ export interface SchemeOther {
86
+ tag: 'other',
87
+ val: string,
88
+ }
89
+ export type Headers = Fields;
90
+ export type ResponseOutparam = number;
91
+ export type OutgoingResponse = number;
92
+ export type Error = ErrorInvalidUrl | ErrorTimeoutError | ErrorProtocolError | ErrorUnexpectedError;
93
+ export interface ErrorInvalidUrl {
94
+ tag: 'invalid-url',
95
+ val: string,
96
+ }
97
+ export interface ErrorTimeoutError {
98
+ tag: 'timeout-error',
99
+ val: string,
100
+ }
101
+ export interface ErrorProtocolError {
102
+ tag: 'protocol-error',
103
+ val: string,
104
+ }
105
+ export interface ErrorUnexpectedError {
106
+ tag: 'unexpected-error',
107
+ val: string,
108
+ }
109
+ export type IncomingResponse = number;
110
+ export type StatusCode = number;
111
+ export type FutureIncomingResponse = number;
112
+ import type { Pollable } from '../imports/poll';
113
+ export { Pollable };
114
+ export interface RequestOptions {
115
+ connectTimeoutMs?: number,
116
+ firstByteTimeoutMs?: number,
117
+ betweenBytesTimeoutMs?: number,
118
+ }
119
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };