@bytecodealliance/preview2-shim 0.0.8 → 0.0.9

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 (102) hide show
  1. package/README.md +1 -0
  2. package/lib/browser/cli-base.js +57 -0
  3. package/lib/browser/clocks.js +50 -0
  4. package/lib/browser/filesystem.js +134 -141
  5. package/lib/browser/http.js +120 -0
  6. package/lib/browser/index.js +15 -37
  7. package/lib/browser/io.js +62 -20
  8. package/lib/browser/logging.js +16 -0
  9. package/lib/browser/poll.js +10 -6
  10. package/lib/browser/random.js +32 -25
  11. package/lib/browser/sockets.js +203 -0
  12. package/lib/nodejs/{preopens.js → cli-base.js} +47 -8
  13. package/lib/nodejs/clocks.js +50 -0
  14. package/lib/nodejs/filesystem.js +239 -234
  15. package/lib/nodejs/http.js +120 -0
  16. package/lib/nodejs/index.js +15 -37
  17. package/lib/nodejs/io.js +138 -19
  18. package/lib/nodejs/logging.js +16 -0
  19. package/lib/nodejs/poll.js +10 -6
  20. package/lib/nodejs/random.js +18 -13
  21. package/lib/nodejs/sockets.js +203 -0
  22. package/package.json +1 -1
  23. package/types/exports/{HTTP.d.ts → http-incoming-handler.d.ts} +1 -1
  24. package/types/imports/cli-base-environment.d.ts +17 -0
  25. package/types/imports/{exit.d.ts → cli-base-exit.d.ts} +4 -1
  26. package/types/imports/{preopens.d.ts → cli-base-preopens.d.ts} +6 -9
  27. package/types/imports/cli-base-stderr.d.ts +5 -0
  28. package/types/imports/cli-base-stdin.d.ts +5 -0
  29. package/types/imports/cli-base-stdout.d.ts +5 -0
  30. package/types/imports/clocks-monotonic-clock.d.ts +24 -0
  31. package/types/imports/clocks-timezone.d.ts +71 -0
  32. package/types/imports/clocks-wall-clock.d.ts +31 -0
  33. package/types/imports/filesystem-filesystem.d.ts +857 -0
  34. package/types/imports/{default-outgoing-HTTP.d.ts → http-outgoing-handler.d.ts} +1 -1
  35. package/types/imports/{types.d.ts → http-types.d.ts} +28 -28
  36. package/types/imports/io-streams.d.ts +180 -0
  37. package/types/imports/logging-handler.d.ts +40 -0
  38. package/types/imports/poll-poll.d.ts +41 -0
  39. package/types/imports/random-insecure-seed.d.ts +22 -0
  40. package/types/imports/random-insecure.d.ts +20 -0
  41. package/types/imports/random-random.d.ts +22 -0
  42. package/types/imports/{instance-network.d.ts → sockets-instance-network.d.ts} +4 -1
  43. package/types/imports/sockets-ip-name-lookup.d.ts +76 -0
  44. package/types/imports/sockets-network.d.ts +212 -0
  45. package/types/imports/sockets-tcp-create-socket.d.ts +33 -0
  46. package/types/imports/sockets-tcp.d.ts +285 -0
  47. package/types/imports/sockets-udp-create-socket.d.ts +33 -0
  48. package/types/imports/sockets-udp.d.ts +219 -0
  49. package/types/wasi-command.d.ts +23 -0
  50. package/types/wasi-proxy.d.ts +11 -44
  51. package/types/wasi-reactor.d.ts +23 -70
  52. package/lib/browser/console.js +0 -12
  53. package/lib/browser/default-outgoing-HTTP.js +0 -3
  54. package/lib/browser/environment.js +0 -17
  55. package/lib/browser/exit.js +0 -21
  56. package/lib/browser/instance-network.js +0 -3
  57. package/lib/browser/ip-name-lookup.js +0 -23
  58. package/lib/browser/monotonic-clock.js +0 -14
  59. package/lib/browser/network.js +0 -3
  60. package/lib/browser/preopens.js +0 -11
  61. package/lib/browser/stderr.js +0 -4
  62. package/lib/browser/streams.js +0 -60
  63. package/lib/browser/tcp-create-socket.js +0 -3
  64. package/lib/browser/tcp.js +0 -75
  65. package/lib/browser/timezone.js +0 -12
  66. package/lib/browser/types.js +0 -99
  67. package/lib/browser/udp-create-socket.js +0 -3
  68. package/lib/browser/udp.js +0 -75
  69. package/lib/browser/wall-clock.js +0 -9
  70. package/lib/nodejs/console.js +0 -12
  71. package/lib/nodejs/default-outgoing-HTTP.js +0 -3
  72. package/lib/nodejs/environment.js +0 -19
  73. package/lib/nodejs/exit.js +0 -3
  74. package/lib/nodejs/instance-network.js +0 -3
  75. package/lib/nodejs/ip-name-lookup.js +0 -23
  76. package/lib/nodejs/monotonic-clock.js +0 -14
  77. package/lib/nodejs/network.js +0 -3
  78. package/lib/nodejs/stderr.js +0 -4
  79. package/lib/nodejs/streams.js +0 -97
  80. package/lib/nodejs/tcp-create-socket.js +0 -3
  81. package/lib/nodejs/tcp.js +0 -75
  82. package/lib/nodejs/timezone.js +0 -12
  83. package/lib/nodejs/types.js +0 -99
  84. package/lib/nodejs/udp-create-socket.js +0 -3
  85. package/lib/nodejs/udp.js +0 -75
  86. package/lib/nodejs/wall-clock.js +0 -9
  87. package/types/imports/console.d.ts +0 -17
  88. package/types/imports/environment.d.ts +0 -4
  89. package/types/imports/filesystem.d.ts +0 -210
  90. package/types/imports/ip-name-lookup.d.ts +0 -19
  91. package/types/imports/monotonic-clock.d.ts +0 -8
  92. package/types/imports/network.d.ts +0 -50
  93. package/types/imports/poll.d.ts +0 -5
  94. package/types/imports/random.d.ts +0 -5
  95. package/types/imports/streams.d.ts +0 -23
  96. package/types/imports/tcp-create-socket.d.ts +0 -9
  97. package/types/imports/tcp.d.ts +0 -52
  98. package/types/imports/timezone.d.ts +0 -13
  99. package/types/imports/udp-create-socket.d.ts +0 -9
  100. package/types/imports/udp.d.ts +0 -36
  101. package/types/imports/wall-clock.d.ts +0 -8
  102. package/types/index.d.ts +0 -8
package/README.md CHANGED
@@ -16,6 +16,7 @@ Currently supports Node.js and browser versions, but alternative implementations
16
16
  | Poll | :x: | :x: |
17
17
  | Random | :heavy_check_mark: | :heavy_check_mark: |
18
18
  | Sockets | :x: | :x: |
19
+ | CLI Base | :heavy_check_mark: | :heavy_check_mark: |
19
20
 
20
21
  # License
21
22
 
@@ -0,0 +1,57 @@
1
+ let _env;
2
+ export function _setEnv (envObj) {
3
+ _env = Object.entries(envObj);
4
+ }
5
+
6
+ export const cliBaseEnvironment = {
7
+ getEnvironment () {
8
+ if (!_env) _env = [];
9
+ return _env;
10
+ }
11
+ };
12
+
13
+ class ComponentExit extends Error {
14
+ constructor(code) {
15
+ super(`Component exited ${code === 0 ? 'successfully' : 'with error'}`);
16
+ this.code = code;
17
+ }
18
+ }
19
+
20
+ export const cliBaseExit = {
21
+ exit (status) {
22
+ throw new ComponentExit(status.tag === 'err' ? 1 : 0);
23
+ }
24
+ };
25
+
26
+ export const cliBasePreopens = {
27
+ getDirectories () {
28
+ return [];
29
+ }
30
+ }
31
+
32
+ export const cliBaseStdin = {
33
+ getStdin () {
34
+ return 0;
35
+ }
36
+ };
37
+
38
+ export const cliBaseStdout = {
39
+ getStdout () {
40
+ return 1;
41
+ }
42
+ };
43
+
44
+ export const cliBaseStderr = {
45
+ getStderr () {
46
+ return 2;
47
+ }
48
+ };
49
+
50
+ export {
51
+ cliBaseEnvironment as environment,
52
+ cliBaseExit as exit,
53
+ cliBasePreopens as preopens,
54
+ cliBaseStdin as stdin,
55
+ cliBaseStdout as stdout,
56
+ cliBaseStderr as stderr
57
+ }
@@ -0,0 +1,50 @@
1
+ function _hrtimeBigint () {
2
+ return BigInt(Math.floor(performance.now() * 1e9));
3
+ }
4
+
5
+ let _hrStart = _hrtimeBigint();
6
+
7
+ export const clocksMonotonicClock = {
8
+ resolution() {
9
+ return 1n;
10
+ },
11
+ now () {
12
+ return _hrtimeBigint() - _hrStart;
13
+ },
14
+ subscribe (_when, _absolute) {
15
+ console.log(`[monotonic-clock] Subscribe`);
16
+ }
17
+ };
18
+
19
+ export const clocksTimezone = {
20
+ display (timezone, when) {
21
+ console.log(`[timezone] DISPLAY ${timezone} ${when}`);
22
+ },
23
+
24
+ utcOffset (timezone, when) {
25
+ console.log(`[timezone] UTC OFFSET ${timezone} ${when}`);
26
+ return 0;
27
+ },
28
+
29
+ dropTimezone (timezone) {
30
+ console.log(`[timezone] DROP ${timezone}`);
31
+ }
32
+ };
33
+
34
+ export const clocksWallClock = {
35
+ now() {
36
+ const seconds = BigInt(Math.floor(Date.now() / 1e3));
37
+ const nanoseconds = (Date.now() % 1e3) * 1e6;
38
+ return { seconds, nanoseconds };
39
+ },
40
+
41
+ resolution() {
42
+ console.log(`[wall-clock] Wall clock resolution`);
43
+ }
44
+ };
45
+
46
+ export {
47
+ clocksMonotonicClock as monotonicClock,
48
+ clocksTimezone as timezone,
49
+ clocksWallClock as wallClock
50
+ }
@@ -1,150 +1,143 @@
1
- // export interface DescriptorStat {
2
- // dev: Device,
3
- // ino: Inode,
4
- // type: DescriptorType,
5
- // nlink: Linkcount,
6
- // size: Filesize,
7
- // atim: Timestamp,
8
- // mtim: Timestamp,
9
- // ctim: Timestamp,
10
- // }
11
-
12
- export function readViaStream(fd, offset) {
13
- console.log(`[filesystem] READ STREAM ${fd} ${offset}`);
14
- }
15
-
16
- export function writeViaStream(fd, offset) {
17
- console.log(`[filesystem] WRITE STREAM ${fd} ${offset}`);
18
- }
19
-
20
- export function appendViaStream(fd) {
21
- console.log(`[filesystem] APPEND STREAM ${fd}`);
22
- }
23
-
24
- export function advise(fd, offset, length, advice) {
25
- console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
26
- }
27
-
28
- export function syncData(fd) {
29
- console.log(`[filesystem] SYNC DATA ${fd}`);
30
- }
31
-
32
- export function getFlags(fd) {
33
- console.log(`[filesystem] FLAGS FOR ${fd}`);
34
- }
35
-
36
- export function getType(fd) {
37
- console.log(`[filesystem] GET TYPE ${fd}`);
38
- }
39
-
40
- export function setFlags(fd, flags) {
41
- console.log(`[filesystem] SET FLAGS ${fd} ${JSON.stringify(flags)}`);
42
- }
43
-
44
- export function setSize(fd, size) {
45
- console.log(`[filesystem] SET SIZE`, fd, size);
46
- }
47
-
48
- export function setTimes(fd, dataAccessTimestamp, dataModificationTimestamp) {
49
- console.log(`[filesystem] SET TIMES`, fd, dataAccessTimestamp, dataModificationTimestamp);
50
- }
51
-
52
- export function read(fd, length, offset) {
53
- console.log(`[filesystem] READ`, fd, length, offset);
54
- }
55
-
56
- export function write(fd, buffer, offset) {
57
- console.log(`[filesystem] WRITE`, fd, buffer, offset);
58
- }
59
-
60
- export function readDirectory(fd) {
61
- console.log(`[filesystem] READ DIR`, fd);
62
- }
63
-
64
- export function sync(fd) {
65
- console.log(`[filesystem] SYNC`, fd);
66
- }
67
-
68
- export function createDirectoryAt(fd, path) {
69
- console.log(`[filesystem] CREATE DIRECTORY`, fd, path);
70
- }
71
-
72
- export function stat(fd) {
73
- console.log(`[filesystem] STAT`, fd);
74
- }
75
-
76
- export function statAt(fd, pathFlags, path) {
77
- console.log(`[filesystem] STAT`, fd, pathFlags, path);
78
- }
79
-
80
- export function setTimesAt(fd) {
81
- console.log(`[filesystem] SET TIMES AT`, fd);
82
- }
83
-
84
- export function linkAt(fd) {
85
- console.log(`[filesystem] LINK AT`, fd);
86
- }
87
-
88
- export function openAt(fd) {
89
- console.log(`[filesystem] OPEN AT`, fd);
90
- }
91
-
92
- export function readlinkAt(fd) {
93
- console.log(`[filesystem] READLINK AT`, fd);
94
- }
95
-
96
- export function removeDirectoryAt(fd) {
97
- console.log(`[filesystem] REMOVE DIR AT`, fd);
98
- }
99
-
100
- export function renameAt(fd) {
101
- console.log(`[filesystem] RENAME AT`, fd);
102
- }
103
-
104
- export function symlinkAt(fd) {
105
- console.log(`[filesystem] SYMLINK AT`, fd);
106
- }
107
-
108
- export function unlinkFileAt(fd) {
109
- console.log(`[filesystem] UNLINK FILE AT`, fd);
110
- }
1
+ export const filesystem = {
2
+ readViaStream(fd, offset) {
3
+ console.log(`[filesystem] READ STREAM ${fd} ${offset}`);
4
+ },
5
+
6
+ writeViaStream(fd, offset) {
7
+ console.log(`[filesystem] WRITE STREAM ${fd} ${offset}`);
8
+ },
9
+
10
+ appendViaStream(fd) {
11
+ console.log(`[filesystem] APPEND STREAM ${fd}`);
12
+ },
13
+
14
+ advise(fd, offset, length, advice) {
15
+ console.log(`[filesystem] ADVISE`, fd, offset, length, advice);
16
+ },
17
+
18
+ syncData(fd) {
19
+ console.log(`[filesystem] SYNC DATA ${fd}`);
20
+ },
21
+
22
+ getFlags(fd) {
23
+ console.log(`[filesystem] FLAGS FOR ${fd}`);
24
+ },
25
+
26
+ getType(fd) {
27
+ console.log(`[filesystem] GET TYPE ${fd}`);
28
+ },
29
+
30
+ setFlags(fd, flags) {
31
+ console.log(`[filesystem] SET FLAGS ${fd} ${JSON.stringify(flags)}`);
32
+ },
33
+
34
+ setSize(fd, size) {
35
+ console.log(`[filesystem] SET SIZE`, fd, size);
36
+ },
37
+
38
+ setTimes(fd, dataAccessTimestamp, dataModificationTimestamp) {
39
+ console.log(`[filesystem] SET TIMES`, fd, dataAccessTimestamp, dataModificationTimestamp);
40
+ },
41
+
42
+ read(fd, length, offset) {
43
+ console.log(`[filesystem] READ`, fd, length, offset);
44
+ },
45
+
46
+ write(fd, buffer, offset) {
47
+ console.log(`[filesystem] WRITE`, fd, buffer, offset);
48
+ },
49
+
50
+ readDirectory(fd) {
51
+ console.log(`[filesystem] READ DIR`, fd);
52
+ },
53
+
54
+ sync(fd) {
55
+ console.log(`[filesystem] SYNC`, fd);
56
+ },
57
+
58
+ createDirectoryAt(fd, path) {
59
+ console.log(`[filesystem] CREATE DIRECTORY`, fd, path);
60
+ },
61
+
62
+ stat(fd) {
63
+ console.log(`[filesystem] STAT`, fd);
64
+ },
65
+
66
+ statAt(fd, pathFlags, path) {
67
+ console.log(`[filesystem] STAT`, fd, pathFlags, path);
68
+ },
69
+
70
+ setTimesAt(fd) {
71
+ console.log(`[filesystem] SET TIMES AT`, fd);
72
+ },
73
+
74
+ linkAt(fd) {
75
+ console.log(`[filesystem] LINK AT`, fd);
76
+ },
77
+
78
+ openAt(fd) {
79
+ console.log(`[filesystem] OPEN AT ${fd}`);
80
+ },
81
+
82
+ readlinkAt(fd) {
83
+ console.log(`[filesystem] READLINK AT`, fd);
84
+ },
85
+
86
+ removeDirectoryAt(fd) {
87
+ console.log(`[filesystem] REMOVE DIR AT`, fd);
88
+ },
89
+
90
+ renameAt(fd) {
91
+ console.log(`[filesystem] RENAME AT`, fd);
92
+ },
93
+
94
+ symlinkAt(fd) {
95
+ console.log(`[filesystem] SYMLINK AT`, fd);
96
+ },
97
+
98
+ unlinkFileAt(fd) {
99
+ console.log(`[filesystem] UNLINK FILE AT`, fd);
100
+ },
101
+
102
+ changeFilePermissionsAt(fd) {
103
+ console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
104
+ },
111
105
 
112
- export function changeFilePermissionsAt(fd) {
113
- console.log(`[filesystem] CHANGE FILE PERMISSIONS AT`, fd);
114
- }
106
+ changeDirectoryPermissionsAt(fd) {
107
+ console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, fd);
108
+ },
115
109
 
116
- export function changeDirectoryPermissionsAt(fd) {
117
- console.log(`[filesystem] CHANGE DIR PERMISSIONS AT`, fd);
118
- }
110
+ lockShared(fd) {
111
+ console.log(`[filesystem] LOCK SHARED`, fd);
112
+ },
119
113
 
120
- export function lockShared(fd) {
121
- console.log(`[filesystem] LOCK SHARED`, fd);
122
- }
114
+ lockExclusive(fd) {
115
+ console.log(`[filesystem] LOCK EXCLUSIVE`, fd);
116
+ },
123
117
 
124
- export function lockExclusive(fd) {
125
- console.log(`[filesystem] LOCK EXCLUSIVE`, fd);
126
- }
118
+ tryLockShared(fd) {
119
+ console.log(`[filesystem] TRY LOCK SHARED`, fd);
120
+ },
127
121
 
128
- export function tryLockShared(fd) {
129
- console.log(`[filesystem] TRY LOCK SHARED`, fd);
130
- }
122
+ tryLockExclusive(fd) {
123
+ console.log(`[filesystem] TRY LOCK EXCLUSIVE`, fd);
124
+ },
131
125
 
132
- export function tryLockExclusive(fd) {
133
- console.log(`[filesystem] TRY LOCK EXCLUSIVE`, fd);
134
- }
126
+ unlock(fd) {
127
+ console.log(`[filesystem] UNLOCK`, fd);
128
+ },
135
129
 
136
- export function unlock(fd) {
137
- console.log(`[filesystem] UNLOCK`, fd);
138
- }
130
+ dropDescriptor(fd) {
131
+ console.log(`[filesystem] DROP DESCRIPTOR`, fd);
132
+ },
139
133
 
140
- export function dropDescriptor(fd) {
141
- console.log(`[filesystem] DROP DESCRIPTOR`, fd);
142
- }
134
+ readDirectoryEntry(stream) {
135
+ console.log(`[filesystem] READ DIRECTRY ENTRY`, stream);
136
+ },
143
137
 
144
- export function readDirectoryEntry(stream) {
145
- console.log(`[filesystem] READ DIRECTRY ENTRY`, stream);
146
- }
147
-
148
- export function dropDirectoryEntryStream(stream) {
149
- console.log(`[filesystem] DROP DIRECTORY ENTRY`, stream);
150
- }
138
+ dropDirectoryEntryStream(stream) {
139
+ console.log(`[filesystem] DROP DIRECTORY ENTRY`, stream);
140
+ }
141
+ };
142
+
143
+ export { filesystem as filesystemFilesystem }
@@ -33,3 +33,123 @@ export function send(req) {
33
33
  throw new UnexpectedError(err.message);
34
34
  }
35
35
  }
36
+
37
+ export const httpIncomingHandler = {
38
+ handle () {
39
+
40
+ }
41
+ };
42
+
43
+ export const httpOutgoingHandler = {
44
+ handle () {
45
+
46
+ }
47
+ };
48
+
49
+ export const httpTypes = {
50
+ dropFields(_fields) {
51
+ console.log("[types] Drop fields");
52
+ },
53
+ newFields(_entries) {
54
+ console.log("[types] New fields");
55
+ },
56
+ fieldsGet(_fields, _name) {
57
+ console.log("[types] Fields get");
58
+ },
59
+ fieldsSet(_fields, _name, _value) {
60
+ console.log("[types] Fields set");
61
+ },
62
+ fieldsDelete(_fields, _name) {
63
+ console.log("[types] Fields delete");
64
+ },
65
+ fieldsAppend(_fields, _name, _value) {
66
+ console.log("[types] Fields append");
67
+ },
68
+ fieldsEntries(_fields) {
69
+ console.log("[types] Fields entries");
70
+ },
71
+ fieldsClone(_fields) {
72
+ console.log("[types] Fields clone");
73
+ },
74
+ finishIncomingStream(s) {
75
+ console.log(`[types] Finish incoming stream ${s}`);
76
+ },
77
+ finishOutgoingStream(s, _trailers) {
78
+ console.log(`[types] Finish outgoing stream ${s}`);
79
+ },
80
+ dropIncomingRequest(_req) {
81
+ console.log("[types] Drop incoming request");
82
+ },
83
+ dropOutgoingRequest(_req) {
84
+ console.log("[types] Drop outgoing request");
85
+ },
86
+ incomingRequestMethod(_req) {
87
+ console.log("[types] Incoming request method");
88
+ },
89
+ incomingRequestPath(_req) {
90
+ console.log("[types] Incoming request path");
91
+ },
92
+ incomingRequestQuery(_req) {
93
+ console.log("[types] Incoming request query");
94
+ },
95
+ incomingRequestScheme(_req) {
96
+ console.log("[types] Incoming request scheme");
97
+ },
98
+ incomingRequestAuthority(_req) {
99
+ console.log("[types] Incoming request authority");
100
+ },
101
+ incomingRequestHeaders(_req) {
102
+ console.log("[types] Incoming request headers");
103
+ },
104
+ incomingRequestConsume(_req) {
105
+ console.log("[types] Incoming request consume");
106
+ },
107
+ newOutgoingRequest(_method, _path, _query, _scheme, _authority, _headers) {
108
+ console.log("[types] New outgoing request");
109
+ },
110
+ outgoingRequestWrite(_req) {
111
+ console.log("[types] Outgoing request write");
112
+ },
113
+ dropResponseOutparam(_res) {
114
+ console.log("[types] Drop response outparam");
115
+ },
116
+ setResponseOutparam(_response) {
117
+ console.log("[types] Drop fields");
118
+ },
119
+ dropIncomingResponse(_res) {
120
+ console.log("[types] Drop incoming response");
121
+ },
122
+ dropOutgoingResponse(_res) {
123
+ console.log("[types] Drop outgoing response");
124
+ },
125
+ incomingResponseStatus(_res) {
126
+ console.log("[types] Incoming response status");
127
+ },
128
+ incomingResponseHeaders(_res) {
129
+ console.log("[types] Incoming response headers");
130
+ },
131
+ incomingResponseConsume(_res) {
132
+ console.log("[types] Incoming response consume");
133
+ },
134
+ newOutgoingResponse(_statusCode, _headers) {
135
+ console.log("[types] New outgoing response");
136
+ },
137
+ outgoingResponseWrite(_res) {
138
+ console.log("[types] Outgoing response write");
139
+ },
140
+ dropFutureIncomingResponse(_f) {
141
+ console.log("[types] Drop future incoming response");
142
+ },
143
+ futureIncomingResponseGet(_f) {
144
+ console.log("[types] Future incoming response get");
145
+ },
146
+ listenToFutureIncomingResponse(_f) {
147
+ console.log("[types] Listen to future incoming response");
148
+ }
149
+ };
150
+
151
+ export {
152
+ httpIncomingHandler as incomingHandler,
153
+ httpOutgoingHandler as outgoingHandler,
154
+ httpTypes as types
155
+ }
@@ -1,45 +1,23 @@
1
- import * as console from "./console.js";
2
- import * as defaultOutgoingHttp from "./default-outgoing-HTTP.js";
3
- import * as environment from "./environment.js";
4
- import * as exit from "./exit.js";
1
+ import * as clocks from "./clocks.js";
5
2
  import * as filesystem from "./filesystem.js";
6
- import * as instanceNetwork from "./instance-network.js";
7
- import * as ipNameLookup from "./ip-name-lookup.js";
8
- import * as monotonicClock from "./monotonic-clock.js";
9
- import * as network from "./network.js";
3
+ import * as http from "./http.js";
4
+ import * as io from "./io.js";
5
+ import * as logging from "./logging.js";
10
6
  import * as poll from "./poll.js";
11
- import * as preopens from "./preopens.js";
12
7
  import * as random from "./random.js";
13
- import * as streams from "./streams.js";
14
- import * as tcpCreateSocket from "./tcp-create-socket.js";
15
- import * as tcp from "./tcp.js";
16
- import * as timezone from "./timezone.js";
17
- import * as types from "./types.js";
18
- import * as udpCreateSocket from "./udp-create-socket.js";
19
- import * as udp from "./udp.js";
20
- import * as wallClock from "./wall-clock.js";
8
+ import * as sockets from "./sockets.js";
9
+ import * as cliBase from "./cli-base.js";
21
10
 
22
11
  export const importObject = {
23
- 'console': console,
24
- 'default-outgoing-HTTP': defaultOutgoingHttp,
25
- 'environment': environment,
26
- 'exit': exit,
27
- 'filesystem': filesystem,
28
- 'instance-network': instanceNetwork,
29
- 'ip-name-lookup': ipNameLookup,
30
- 'monotonic-clock': monotonicClock,
31
- 'network': network,
32
- 'poll': poll,
33
- 'preopens': preopens,
34
- 'random': random,
35
- 'streams': streams,
36
- 'tcp-create-socket': tcpCreateSocket,
37
- 'tcp': tcp,
38
- 'timezone': timezone,
39
- 'types': types,
40
- 'udp-create-socket': udpCreateSocket,
41
- 'udp': udp,
42
- 'wall-clock': wallClock
12
+ clocks,
13
+ filesystem,
14
+ http,
15
+ io,
16
+ logging,
17
+ poll,
18
+ random,
19
+ sockets,
20
+ cliBase,
43
21
  };
44
22
 
45
23
  export { WasiHttp } from "../http/wasi-http.js";
package/lib/browser/io.js CHANGED
@@ -1,22 +1,64 @@
1
- export function read(s, len) {
2
- console.log(`[io] Read ${s} ${len}`);
3
- }
4
-
5
- export function write(s, buf) {
6
- switch (s) {
7
- case 0:
8
- throw new Error(`TODO: write stdin`);
9
- case 1: {
10
- const decoder = new TextDecoder();
11
- console.log(decoder.decode(buf));
12
- return BigInt(buf.byteLength);
13
- }
14
- case 2: {
15
- const decoder = new TextDecoder();
16
- console.error(decoder.decode(buf));
17
- return BigInt(buf.byteLength);
1
+ export const ioStreams = {
2
+ read(s, len) {
3
+ console.log(`[streams] Read ${s} ${len}`);
4
+ },
5
+ blockingRead(s, len) {
6
+ console.log(`[streams] Blocking read ${s} ${len}`);
7
+ },
8
+ skip(s, _len) {
9
+ console.log(`[streams] Skip ${s}`);
10
+ },
11
+ blockingSkip(s, _len) {
12
+ console.log(`[streams] Blocking skip ${s}`);
13
+ },
14
+ subscribeToInputStream(s) {
15
+ console.log(`[streams] Subscribe to input stream ${s}`);
16
+ },
17
+ dropInputStream(s) {
18
+ console.log(`[streams] Drop input stream ${s}`);
19
+ },
20
+ write(s, buf) {
21
+ switch (s) {
22
+ case 0:
23
+ throw new Error(`TODO: write stdin`);
24
+ case 1: {
25
+ const decoder = new TextDecoder();
26
+ console.log(decoder.decode(buf));
27
+ return BigInt(buf.byteLength);
28
+ }
29
+ case 2: {
30
+ const decoder = new TextDecoder();
31
+ console.error(decoder.decode(buf));
32
+ return BigInt(buf.byteLength);
33
+ }
34
+ default:
35
+ throw new Error(`TODO: write ${s}`);
18
36
  }
19
- default:
20
- throw new Error(`TODO: write ${s}`);
37
+ },
38
+ blockingWrite(s, _buf) {
39
+ console.log(`[streams] Blocking write ${s}`);
40
+ },
41
+ writeZeroes(s, _len) {
42
+ console.log(`[streams] Write zeroes ${s}`);
43
+ },
44
+ blockingWriteZeroes(s, _len) {
45
+ console.log(`[streams] Blocking write zeroes ${s}`);
46
+ },
47
+ splice(s, _src, _len) {
48
+ console.log(`[streams] Splice ${s}`);
49
+ },
50
+ blockingSplice(s, _src, _len) {
51
+ console.log(`[streams] Blocking splice ${s}`);
52
+ },
53
+ forward(s, _src) {
54
+ console.log(`[streams] Forward ${s}`);
55
+ },
56
+ subscribeToOutputStream(s) {
57
+ console.log(`[streams] Subscribe to output stream ${s}`);
58
+ },
59
+ dropOutputStream(s) {
60
+ console.log(`[streams] Drop output stream ${s}`);
21
61
  }
22
- }
62
+ };
63
+
64
+ export { ioStreams as streams }
@@ -0,0 +1,16 @@
1
+ const levels = ["trace", "debug", "info", "warn", "error"];
2
+
3
+ let logLevel = levels.indexOf("warn");
4
+
5
+ export const loggingHandler = {
6
+ log(level, context, msg) {
7
+ if (logLevel > levels.indexOf(level)) return;
8
+ console[level](`(${context}) ${msg}\n`);
9
+ }
10
+ };
11
+
12
+ export function setLevel(level) {
13
+ logLevel = levels.indexOf(level);
14
+ }
15
+
16
+ export { loggingHandler as handler }