@bytecodealliance/preview2-shim 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/nodejs/io.js DELETED
@@ -1,160 +0,0 @@
1
- import { readSync as fsReadSync } from 'node:fs';
2
-
3
- function _convertFsError (e) {
4
- switch (e.code) {
5
- case 'EACCES': throw 'access';
6
- case 'EAGAIN':
7
- case 'EWOULDBLOCK': throw 'would-block';
8
- case 'EALREADY': throw 'already';
9
- case 'EBADF': throw 'bad-descriptor';
10
- case 'EBUSY': throw 'busy';
11
- case 'EDEADLK': throw 'deadlock';
12
- case 'EDQUOT': throw 'quota';
13
- case 'EEXIST': throw 'exist';
14
- case 'EFBIG': throw 'file-too-large';
15
- case 'EILSEQ': throw 'illegal-byte-sequence';
16
- case 'EINPROGRESS': throw 'in-progress';
17
- case 'EINTR': throw 'interrupted';
18
- case 'EINVAL': throw 'invalid';
19
- case 'EIO': throw 'io';
20
- case 'EISDIR': throw 'is-directory';
21
- case 'ELOOP': throw 'loop';
22
- case 'EMLINK': throw 'too-many-links';
23
- case 'EMSGSIZE': throw 'message-size';
24
- case 'ENAMETOOLONG': throw 'name-too-long'
25
- case 'ENODEV': throw 'no-device';
26
- case 'ENOENT': throw 'no-entry';
27
- case 'ENOLCK': throw 'no-lock';
28
- case 'ENOMEM': throw 'insufficient-memory';
29
- case 'ENOSPC': throw 'insufficient-space';
30
- case 'ENOTDIR': throw 'not-directory';
31
- case 'ENOTEMPTY': throw 'not-empty';
32
- case 'ENOTRECOVERABLE': throw 'not-recoverable';
33
- case 'ENOTSUP': throw 'unsupported';
34
- case 'ENOTTY': throw 'no-tty';
35
- case 'ENXIO': throw 'no-such-device';
36
- case 'EOVERFLOW': throw 'overflow';
37
- case 'EPERM': throw 'not-permitted';
38
- case 'EPIPE': throw 'pipe';
39
- case 'EROFS': throw 'read-only';
40
- case 'ESPIPE': throw 'invalid-seek';
41
- case 'ETXTBSY': throw 'text-file-busy';
42
- case 'EXDEV': throw 'cross-device';
43
- default: throw e;
44
- }
45
- }
46
-
47
- export let _streams = {};
48
- let streamCnt = 0;
49
- export function _createFsStream(fd, type, context) {
50
- _streams[streamCnt] = {
51
- type,
52
- fd,
53
- context
54
- };
55
- return streamCnt++;
56
- }
57
-
58
- export function _getFsStreamContext(stream, type) {
59
- const entry = _streams[stream];
60
- if (!entry)
61
- throw new Error(`No '${type}' stream found at stream ${stream}`);
62
- if (entry.type !== type)
63
- throw new Error(`Unexpected '${entry.type}' stream found at stream ${stream}, expected '${type}'`);
64
- return entry.context;
65
- }
66
-
67
- export function _dropFsStream(stream) {
68
- // TODO: recycling?
69
- delete _streams[stream];
70
- }
71
-
72
- export const streams = {
73
- read(s, len) {
74
- return streams.blockingRead(s, len);
75
- },
76
- blockingRead(s, len) {
77
- len = Number(len);
78
- const stream = _streams[s];
79
- switch (stream?.type) {
80
- case 'file': {
81
- const buf = Buffer.alloc(Number(len));
82
- try {
83
- const readBytes = fsReadSync(stream.fd, buf, 0, Number(len));
84
- if (readBytes < Number(len)) {
85
- return [new Uint8Array(buf.buffer, 0, readBytes), 'ended'];
86
- }
87
- return [new Uint8Array(buf.buffer, 0, readBytes), 'open'];
88
- }
89
- catch (e) {
90
- _convertFsError(e);
91
- }
92
- break;
93
- }
94
- }
95
- throw null;
96
- },
97
- skip(s, _len) {
98
- console.log(`[streams] Skip ${s}`);
99
- },
100
- blockingSkip(s, _len) {
101
- console.log(`[streams] Blocking skip ${s}`);
102
- },
103
- subscribeToInputStream(s) {
104
- console.log(`[streams] Subscribe to input stream ${s}`);
105
- },
106
- dropInputStream(s) {
107
- delete _streams[s];
108
- },
109
- checkWrite(_s) {
110
- // TODO: implement
111
- return 1000000n;
112
- },
113
- write(s, buf) {
114
- switch (s) {
115
- case 0:
116
- throw new Error(`TODO: write stdin`);
117
- case 1: {
118
- process.stdout.write(buf);
119
- break;
120
- }
121
- case 2: {
122
- process.stderr.write(buf);
123
- break;
124
- }
125
- default:
126
- throw new Error(`TODO: write ${s}`);
127
- }
128
- },
129
- blockingWriteAndFlush(s, buf) {
130
- // TODO: implement
131
- return streams.write(s, buf);
132
- },
133
- flush(s) {
134
- return streams.blockingFlush(s);
135
- },
136
- blockingFlush(_s) {
137
- // TODO: implement
138
- },
139
- writeZeroes(s, _len) {
140
- console.log(`[streams] Write zeroes ${s}`);
141
- },
142
- blockingWriteZeroes(s, _len) {
143
- console.log(`[streams] Blocking write zeroes ${s}`);
144
- },
145
- splice(s, _src, _len) {
146
- console.log(`[streams] Splice ${s}`);
147
- },
148
- blockingSplice(s, _src, _len) {
149
- console.log(`[streams] Blocking splice ${s}`);
150
- },
151
- forward(s, _src) {
152
- console.log(`[streams] Forward ${s}`);
153
- },
154
- subscribeToOutputStream(s) {
155
- console.log(`[streams] Subscribe to output stream ${s}`);
156
- },
157
- dropOutputStream(s) {
158
- console.log(`[streams] Drop output stream ${s}`);
159
- }
160
- };
@@ -1,14 +0,0 @@
1
- const levels = ["trace", "debug", "info", "warn", "error", "critical"];
2
-
3
- let logLevel = levels.indexOf("warn");
4
-
5
- export const logging = {
6
- log(level, context, msg) {
7
- if (logLevel > levels.indexOf(level)) return;
8
- process.stdout.write(`${level}: (${context}) ${msg}\n`);
9
- }
10
- };
11
-
12
- export function setLevel(level) {
13
- logLevel = levels.indexOf(level);
14
- }
@@ -1,39 +0,0 @@
1
- export namespace WasiPollPoll {
2
- /**
3
- * Dispose of the specified `pollable`, after which it may no longer
4
- * be used.
5
- */
6
- export function dropPollable(this_: Pollable): void;
7
- /**
8
- * Poll for completion on a set of pollables.
9
- *
10
- * The "oneoff" in the name refers to the fact that this function must do a
11
- * linear scan through the entire list of subscriptions, which may be
12
- * inefficient if the number is large and the same subscriptions are used
13
- * many times. In the future, this is expected to be obsoleted by the
14
- * component model async proposal, which will include a scalable waiting
15
- * facility.
16
- *
17
- * The result list<bool> is the same length as the argument
18
- * list<pollable>, and indicates the readiness of each corresponding
19
- * element in that / list, with true indicating ready.
20
- */
21
- export function pollOneoff(in_: Uint32Array): boolean[];
22
- }
23
- /**
24
- * A "pollable" handle.
25
- *
26
- * This is conceptually represents a `stream<_, _>`, or in other words,
27
- * a stream that one can wait on, repeatedly, but which does not itself
28
- * produce any data. It's temporary scaffolding until component-model's
29
- * async features are ready.
30
- *
31
- * And at present, it is a `u32` instead of being an actual handle, until
32
- * the wit-bindgen implementation of handles and resources is ready.
33
- *
34
- * `pollable` lifetimes are not automatically managed. Users must ensure
35
- * that they do not outlive the resource they reference.
36
- *
37
- * This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
38
- */
39
- export type Pollable = number;