@bytecodealliance/jco 0.11.0 → 0.11.2

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/README.md +15 -2
  2. package/lib/wasi_snapshot_preview1.command.wasm +0 -0
  3. package/lib/wasi_snapshot_preview1.reactor.wasm +0 -0
  4. package/obj/exports/local-wasm-tools-tools.d.ts +43 -0
  5. package/obj/exports/wasi-cli-terminal-input.d.ts +1 -1
  6. package/obj/exports/wasi-cli-terminal-output.d.ts +1 -1
  7. package/obj/exports/wasi-filesystem-types.d.ts +9 -9
  8. package/obj/exports/wasi-io-streams.d.ts +6 -6
  9. package/obj/imports/wasi-cli-environment.d.ts +1 -1
  10. package/obj/imports/wasi-cli-exit.d.ts +1 -1
  11. package/obj/imports/wasi-cli-stderr.d.ts +1 -1
  12. package/obj/imports/wasi-cli-stdin.d.ts +1 -1
  13. package/obj/imports/wasi-cli-stdout.d.ts +1 -1
  14. package/obj/imports/wasi-cli-terminal-input.d.ts +2 -2
  15. package/obj/imports/wasi-cli-terminal-output.d.ts +2 -2
  16. package/obj/imports/wasi-cli-terminal-stderr.d.ts +1 -1
  17. package/obj/imports/wasi-cli-terminal-stdin.d.ts +1 -1
  18. package/obj/imports/wasi-cli-terminal-stdout.d.ts +1 -1
  19. package/obj/imports/wasi-clocks-wall-clock.d.ts +1 -1
  20. package/obj/imports/wasi-filesystem-preopens.d.ts +1 -1
  21. package/obj/imports/wasi-filesystem-types.d.ts +10 -10
  22. package/obj/imports/wasi-io-streams.d.ts +7 -7
  23. package/obj/imports/wasi-random-random.d.ts +1 -1
  24. package/obj/js-component-bindgen-component.component.wasm +0 -0
  25. package/obj/js-component-bindgen-component.core.wasm +0 -0
  26. package/obj/js-component-bindgen-component.core2.wasm +0 -0
  27. package/obj/js-component-bindgen-component.d.ts +15 -15
  28. package/obj/js-component-bindgen-component.js +2 -2
  29. package/obj/wasm-tools.component.wasm +0 -0
  30. package/obj/wasm-tools.core.wasm +0 -0
  31. package/obj/wasm-tools.core2.wasm +0 -0
  32. package/obj/wasm-tools.d.ts +17 -56
  33. package/obj/wasm-tools.js +23 -12
  34. package/package.json +7 -4
  35. package/src/api.js +2 -1
  36. package/src/browser.js +3 -0
  37. package/src/cmd/opt.js +2 -1
  38. package/src/cmd/run.js +103 -0
  39. package/src/cmd/transpile.js +3 -2
  40. package/src/cmd/wasm-tools.js +10 -3
  41. package/src/jco.js +11 -1
  42. package/obj/exports/wasi-cli-base-environment.d.ts +0 -3
  43. package/obj/exports/wasi-cli-base-exit.d.ts +0 -4
  44. package/obj/exports/wasi-cli-base-preopens.d.ts +0 -5
  45. package/obj/exports/wasi-cli-base-stderr.d.ts +0 -5
  46. package/obj/exports/wasi-cli-base-stdin.d.ts +0 -5
  47. package/obj/exports/wasi-cli-base-stdout.d.ts +0 -5
  48. package/obj/exports/wasi-filesystem-filesystem.d.ts +0 -152
  49. package/obj/imports/wasi-cli-base-environment.d.ts +0 -3
  50. package/obj/imports/wasi-cli-base-exit.d.ts +0 -4
  51. package/obj/imports/wasi-cli-base-preopens.d.ts +0 -5
  52. package/obj/imports/wasi-cli-base-stderr.d.ts +0 -5
  53. package/obj/imports/wasi-cli-base-stdin.d.ts +0 -5
  54. package/obj/imports/wasi-cli-base-stdout.d.ts +0 -5
  55. package/obj/imports/wasi-filesystem-filesystem.d.ts +0 -152
  56. package/obj/interfaces/environment.d.ts +0 -3
  57. package/obj/interfaces/exit.d.ts +0 -4
  58. package/obj/interfaces/filesystem.d.ts +0 -152
  59. package/obj/interfaces/preopens.d.ts +0 -5
  60. package/obj/interfaces/random.d.ts +0 -3
  61. package/obj/interfaces/stderr.d.ts +0 -5
  62. package/obj/interfaces/stdin.d.ts +0 -5
  63. package/obj/interfaces/stdout.d.ts +0 -5
  64. package/obj/interfaces/streams.d.ts +0 -21
  65. package/obj/interfaces/wall-clock.d.ts +0 -6
  66. package/obj/interfaces/wasi-cli-base-environment.d.ts +0 -3
  67. package/obj/interfaces/wasi-cli-base-exit.d.ts +0 -4
  68. package/obj/interfaces/wasi-cli-base-preopens.d.ts +0 -5
  69. package/obj/interfaces/wasi-cli-base-stderr.d.ts +0 -5
  70. package/obj/interfaces/wasi-cli-base-stdin.d.ts +0 -5
  71. package/obj/interfaces/wasi-cli-base-stdout.d.ts +0 -5
  72. package/obj/interfaces/wasi-clocks-wall-clock.d.ts +0 -6
  73. package/obj/interfaces/wasi-filesystem-filesystem.d.ts +0 -152
  74. package/obj/interfaces/wasi-io-streams.d.ts +0 -21
  75. package/obj/interfaces/wasi-random-random.d.ts +0 -3
package/src/cmd/run.js ADDED
@@ -0,0 +1,103 @@
1
+ import { transpile } from './transpile.js';
2
+ import { tmpdir } from 'node:os';
3
+ import { rm, stat, mkdir, writeFile, symlink, chmod } from 'node:fs/promises';
4
+ import { basename, resolve, extname } from 'node:path';
5
+ import { spawn } from 'node:child_process';
6
+ import { argv0, exit } from 'node:process';
7
+ import { fileURLToPath } from 'node:url';
8
+ import * as crypto from 'node:crypto';
9
+ import c from 'chalk-template';
10
+
11
+ function getTmpDir (name) {
12
+ return resolve(tmpdir(), crypto.createHash('sha256').update(name).update(Math.random().toString()).digest('hex'));
13
+ }
14
+
15
+ export async function run (componentPath, args) {
16
+ const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity));
17
+ const outDir = resolve(getTmpDir(name));
18
+ let cp;
19
+ try {
20
+ try {
21
+ await transpile(componentPath, {
22
+ name,
23
+ quiet: true,
24
+ noTypescript: true,
25
+ wasiShim: true,
26
+ outDir
27
+ });
28
+ }
29
+ catch (e) {
30
+ console.error(c`{red ERR}: Unable to transpile command for execution`);
31
+ throw e;
32
+ }
33
+
34
+ await mkdir(resolve(outDir, 'node_modules', '@bytecodealliance'), { recursive: true });
35
+ await writeFile(resolve(outDir, 'package.json'), JSON.stringify({ type: 'module' }));
36
+
37
+ let preview2ShimPath = fileURLToPath(new URL('../../node_modules/@bytecodealliance/preview2-shim', import.meta.url));
38
+ while (true) {
39
+ try {
40
+ if ((await stat(preview2ShimPath)).isDirectory()) {
41
+ break;
42
+ }
43
+ }
44
+ catch {}
45
+ let len = preview2ShimPath.length;
46
+ preview2ShimPath = resolve(preview2ShimPath, '../../../node_modules/@bytecodealliance/preview2-shim');
47
+ if (preview2ShimPath.length === len) {
48
+ console.error(c`{red ERR}: Unable to locate the {bold @bytecodealliance/preview2-shim} package, make sure it is installed.`);
49
+ return;
50
+ }
51
+ }
52
+
53
+ await symlink(preview2ShimPath, resolve(outDir, 'node_modules/@bytecodealliance/preview2-shim'), 'dir');
54
+
55
+ const runPath = resolve(outDir, '_run.js');
56
+ await writeFile(runPath, `
57
+ import { _setEnv, _setArgs, _setCwd } from '@bytecodealliance/preview2-shim/cli';
58
+ _setArgs(process.argv.slice(1));
59
+ _setEnv(process.env);
60
+ _setCwd(process.cwd());
61
+ function logInvalidCommand () {
62
+ console.error('Not a valid command component to execute, make sure it was built to a command adapter and with the same version.');
63
+ }
64
+ try {
65
+ const mod = await import('./${name}.js');
66
+ if (!mod.run || !mod.run.run) {
67
+ logInvalidCommand();
68
+ process.exit(1);
69
+ }
70
+ try {
71
+ mod.run.run();
72
+ }
73
+ catch (e) {
74
+ console.error(e);
75
+ process.exit(1);
76
+ }
77
+ }
78
+ catch (e) {
79
+ logInvalidCommand();
80
+ throw e;
81
+ }
82
+ `);
83
+ await chmod(runPath, 0o777);
84
+
85
+ cp = spawn(argv0, [runPath, ...args], { stdio: 'inherit' });
86
+ }
87
+ finally {
88
+ if (!cp) {
89
+ try {
90
+ await rm(outDir, { recursive: true });
91
+ } catch {}
92
+ }
93
+ }
94
+
95
+ const exitCode = await new Promise((resolve, reject) => {
96
+ cp.on('error', reject);
97
+ cp.on('exit', resolve);
98
+ });
99
+ try {
100
+ await rm(outDir, { recursive: true });
101
+ } catch {}
102
+ exit(exitCode);
103
+ }
@@ -10,8 +10,8 @@ import { fileURLToPath } from 'url';
10
10
  import ora from '#ora';
11
11
 
12
12
  export async function transpile (componentPath, opts, program) {
13
- const varIdx = program.parent.rawArgs.indexOf('--');
14
- if (varIdx !== -1)
13
+ const varIdx = program?.parent.rawArgs.indexOf('--');
14
+ if (varIdx !== undefined && varIdx !== -1)
15
15
  opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
16
16
  const component = await readFile(componentPath);
17
17
 
@@ -108,6 +108,7 @@ export async function transpileComponent (component, opts = {}) {
108
108
  instantiation: opts.instantiation || opts.js,
109
109
  validLiftingOptimization: opts.validLiftingOptimization ?? false,
110
110
  noNodejsCompat: !(opts.nodejsCompat ?? true),
111
+ noTypescript: opts.noTypescript || false,
111
112
  tlaCompat: opts.tlaCompat ?? false,
112
113
  base64Cutoff: opts.js ? 0 : opts.base64Cutoff ?? 5000
113
114
  });
@@ -1,6 +1,7 @@
1
1
  import { writeFile } from "node:fs/promises";
2
2
  import { readFile } from '../common.js';
3
- import { $init, print as printFn, parse as parseFn, componentWit as componentWitFn, componentNew as componentNewFn, componentEmbed as componentEmbedFn, metadataAdd as metadataAddFn, metadataShow as metadataShowFn } from "../../obj/wasm-tools.js";
3
+ import { $init, tools } from "../../obj/wasm-tools.js";
4
+ const { print: printFn, parse: parseFn, componentWit: componentWitFn, componentNew: componentNewFn, componentEmbed: componentEmbedFn, metadataAdd: metadataAddFn, metadataShow: metadataShowFn } = tools;
4
5
  import { resolve, basename, extname } from 'node:path';
5
6
  import c from 'chalk-template';
6
7
 
@@ -37,8 +38,14 @@ export async function componentNew(file, opts) {
37
38
  await $init;
38
39
  const source = file ? await readFile(file) : null;
39
40
  let adapters = null;
41
+ if (opts.wasiReactor && opts.wasiCommand)
42
+ throw new Error('Must select one of --wasi-command or --wasi-reactor');
43
+ if (opts.wasiReactor)
44
+ adapters = [['wasi_snapshot_preview1', (await readFile(new URL('../../lib/wasi_snapshot_preview1.reactor.wasm', import.meta.url))).buffer]];
45
+ else if (opts.wasiCommand)
46
+ adapters = [['wasi_snapshot_preview1', (await readFile(new URL('../../lib/wasi_snapshot_preview1.command.wasm', import.meta.url))).buffer]];
40
47
  if (opts.adapt)
41
- adapters = await Promise.all(opts.adapt.map(async adapt => {
48
+ adapters = adapters.concat(await Promise.all(opts.adapt.map(async adapt => {
42
49
  let adapter;
43
50
  if (adapt.includes('='))
44
51
  adapter = adapt.split('=');
@@ -46,7 +53,7 @@ export async function componentNew(file, opts) {
46
53
  adapter = [basename(adapt).slice(0, -extname(adapt).length), adapt];
47
54
  adapter[1] = await readFile(adapter[1]);
48
55
  return adapter;
49
- }));
56
+ })));
50
57
  const output = componentNewFn(source, adapters);
51
58
  await writeFile(opts.output, output);
52
59
  }
package/src/jco.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { program } from 'commander';
3
3
  import { opt } from './cmd/opt.js';
4
4
  import { transpile } from './cmd/transpile.js';
5
+ import { run } from './cmd/run.js';
5
6
  import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js';
6
7
  import { componentize } from './cmd/componentize.js';
7
8
  import c from 'chalk-template';
@@ -10,7 +11,7 @@ program
10
11
  .name('jco')
11
12
  .description(c`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
12
13
  .usage('<command> [options]')
13
- .version('0.11.0');
14
+ .version('0.11.2');
14
15
 
15
16
  function myParseInt(value) {
16
17
  return parseInt(value, 10);
@@ -47,6 +48,13 @@ program.command('transpile')
47
48
  .option('--', 'for --optimize, custom wasm-opt arguments (defaults to best size optimization)')
48
49
  .action(asyncAction(transpile));
49
50
 
51
+ program.command('run')
52
+ .description('Run a WebAssembly Command component')
53
+ .usage('<command.wasm> <args...>')
54
+ .argument('<command>', 'Wasm command binary to run')
55
+ .argument('[args...]', 'Any CLI arguments to provide to the command')
56
+ .action(asyncAction(run));
57
+
50
58
  program.command('opt')
51
59
  .description('optimizes a Wasm component, including running wasm-opt Binaryen optimizations')
52
60
  .usage('<component-file> -o <output-file>')
@@ -94,6 +102,8 @@ program.command('new')
94
102
  .requiredOption('-o, --output <output-file>', 'Wasm component output filepath')
95
103
  .option('--name <name>', 'custom output name')
96
104
  .option('--adapt <[NAME=]adapter...>', 'component adapters to apply')
105
+ .option('--wasi-reactor', 'build with the WASI Reactor adapter')
106
+ .option('--wasi-command', 'build with the WASI Command adapter')
97
107
  .action(asyncAction(componentNew));
98
108
 
99
109
  program.command('embed')
@@ -1,3 +0,0 @@
1
- export namespace WasiCliBaseEnvironment {
2
- export function getEnvironment(): [string, string][];
3
- }
@@ -1,4 +0,0 @@
1
- export namespace WasiCliBaseExit {
2
- export function exit(status: Result<void, void>): void;
3
- }
4
- export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBasePreopens {
2
- export function getDirectories(): [Descriptor, string][];
3
- }
4
- import type { Descriptor } from '../exports/wasi-filesystem-filesystem';
5
- export { Descriptor };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStderr {
2
- export function getStderr(): OutputStream;
3
- }
4
- import type { OutputStream } from '../exports/wasi-io-streams';
5
- export { OutputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStdin {
2
- export function getStdin(): InputStream;
3
- }
4
- import type { InputStream } from '../exports/wasi-io-streams';
5
- export { InputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStdout {
2
- export function getStdout(): OutputStream;
3
- }
4
- import type { OutputStream } from '../exports/wasi-io-streams';
5
- export { OutputStream };
@@ -1,152 +0,0 @@
1
- export namespace WasiFilesystemFilesystem {
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 getType(this: Descriptor): DescriptorType;
6
- export function stat(this: Descriptor): DescriptorStat;
7
- export function openAt(this: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
8
- export function dropDescriptor(this: Descriptor): void;
9
- export function dropDirectoryEntryStream(this: DirectoryEntryStream): void;
10
- }
11
- export type Descriptor = number;
12
- export type Filesize = bigint;
13
- import type { InputStream } from '../exports/wasi-io-streams';
14
- export { InputStream };
15
- /**
16
- * # Variants
17
- *
18
- * ## `"access"`
19
- *
20
- * ## `"would-block"`
21
- *
22
- * ## `"already"`
23
- *
24
- * ## `"bad-descriptor"`
25
- *
26
- * ## `"busy"`
27
- *
28
- * ## `"deadlock"`
29
- *
30
- * ## `"quota"`
31
- *
32
- * ## `"exist"`
33
- *
34
- * ## `"file-too-large"`
35
- *
36
- * ## `"illegal-byte-sequence"`
37
- *
38
- * ## `"in-progress"`
39
- *
40
- * ## `"interrupted"`
41
- *
42
- * ## `"invalid"`
43
- *
44
- * ## `"io"`
45
- *
46
- * ## `"is-directory"`
47
- *
48
- * ## `"loop"`
49
- *
50
- * ## `"too-many-links"`
51
- *
52
- * ## `"message-size"`
53
- *
54
- * ## `"name-too-long"`
55
- *
56
- * ## `"no-device"`
57
- *
58
- * ## `"no-entry"`
59
- *
60
- * ## `"no-lock"`
61
- *
62
- * ## `"insufficient-memory"`
63
- *
64
- * ## `"insufficient-space"`
65
- *
66
- * ## `"not-directory"`
67
- *
68
- * ## `"not-empty"`
69
- *
70
- * ## `"not-recoverable"`
71
- *
72
- * ## `"unsupported"`
73
- *
74
- * ## `"no-tty"`
75
- *
76
- * ## `"no-such-device"`
77
- *
78
- * ## `"overflow"`
79
- *
80
- * ## `"not-permitted"`
81
- *
82
- * ## `"pipe"`
83
- *
84
- * ## `"read-only"`
85
- *
86
- * ## `"invalid-seek"`
87
- *
88
- * ## `"text-file-busy"`
89
- *
90
- * ## `"cross-device"`
91
- */
92
- 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';
93
- import type { OutputStream } from '../exports/wasi-io-streams';
94
- export { OutputStream };
95
- /**
96
- * # Variants
97
- *
98
- * ## `"unknown"`
99
- *
100
- * ## `"block-device"`
101
- *
102
- * ## `"character-device"`
103
- *
104
- * ## `"directory"`
105
- *
106
- * ## `"fifo"`
107
- *
108
- * ## `"symbolic-link"`
109
- *
110
- * ## `"regular-file"`
111
- *
112
- * ## `"socket"`
113
- */
114
- export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
115
- export type Device = bigint;
116
- export type Inode = bigint;
117
- export type LinkCount = bigint;
118
- import type { Datetime } from '../exports/wasi-clocks-wall-clock';
119
- export { Datetime };
120
- export interface DescriptorStat {
121
- device: Device,
122
- inode: Inode,
123
- type: DescriptorType,
124
- linkCount: LinkCount,
125
- size: Filesize,
126
- dataAccessTimestamp: Datetime,
127
- dataModificationTimestamp: Datetime,
128
- statusChangeTimestamp: Datetime,
129
- }
130
- export interface PathFlags {
131
- symlinkFollow?: boolean,
132
- }
133
- export interface OpenFlags {
134
- create?: boolean,
135
- directory?: boolean,
136
- exclusive?: boolean,
137
- truncate?: boolean,
138
- }
139
- export interface DescriptorFlags {
140
- read?: boolean,
141
- write?: boolean,
142
- fileIntegritySync?: boolean,
143
- dataIntegritySync?: boolean,
144
- requestedWriteSync?: boolean,
145
- mutateDirectory?: boolean,
146
- }
147
- export interface Modes {
148
- readable?: boolean,
149
- writable?: boolean,
150
- executable?: boolean,
151
- }
152
- export type DirectoryEntryStream = number;
@@ -1,3 +0,0 @@
1
- export namespace WasiCliBaseEnvironment1 {
2
- export function getEnvironment(): [string, string][];
3
- }
@@ -1,4 +0,0 @@
1
- export namespace WasiCliBaseExit1 {
2
- export function exit(status: Result<void, void>): void;
3
- }
4
- export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBasePreopens1 {
2
- export function getDirectories(): [Descriptor, string][];
3
- }
4
- import type { Descriptor } from '../imports/wasi-filesystem-filesystem';
5
- export { Descriptor };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStderr1 {
2
- export function getStderr(): OutputStream;
3
- }
4
- import type { OutputStream } from '../imports/wasi-io-streams';
5
- export { OutputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStdin1 {
2
- export function getStdin(): InputStream;
3
- }
4
- import type { InputStream } from '../imports/wasi-io-streams';
5
- export { InputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliBaseStdout1 {
2
- export function getStdout(): OutputStream;
3
- }
4
- import type { OutputStream } from '../imports/wasi-io-streams';
5
- export { OutputStream };
@@ -1,152 +0,0 @@
1
- export namespace WasiFilesystemFilesystem1 {
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 getType(this: Descriptor): DescriptorType;
6
- export function stat(this: Descriptor): DescriptorStat;
7
- export function openAt(this: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
8
- export function dropDescriptor(this: Descriptor): void;
9
- export function dropDirectoryEntryStream(this: DirectoryEntryStream): void;
10
- }
11
- export type Descriptor = number;
12
- export type Filesize = bigint;
13
- import type { InputStream } from '../imports/wasi-io-streams';
14
- export { InputStream };
15
- /**
16
- * # Variants
17
- *
18
- * ## `"access"`
19
- *
20
- * ## `"would-block"`
21
- *
22
- * ## `"already"`
23
- *
24
- * ## `"bad-descriptor"`
25
- *
26
- * ## `"busy"`
27
- *
28
- * ## `"deadlock"`
29
- *
30
- * ## `"quota"`
31
- *
32
- * ## `"exist"`
33
- *
34
- * ## `"file-too-large"`
35
- *
36
- * ## `"illegal-byte-sequence"`
37
- *
38
- * ## `"in-progress"`
39
- *
40
- * ## `"interrupted"`
41
- *
42
- * ## `"invalid"`
43
- *
44
- * ## `"io"`
45
- *
46
- * ## `"is-directory"`
47
- *
48
- * ## `"loop"`
49
- *
50
- * ## `"too-many-links"`
51
- *
52
- * ## `"message-size"`
53
- *
54
- * ## `"name-too-long"`
55
- *
56
- * ## `"no-device"`
57
- *
58
- * ## `"no-entry"`
59
- *
60
- * ## `"no-lock"`
61
- *
62
- * ## `"insufficient-memory"`
63
- *
64
- * ## `"insufficient-space"`
65
- *
66
- * ## `"not-directory"`
67
- *
68
- * ## `"not-empty"`
69
- *
70
- * ## `"not-recoverable"`
71
- *
72
- * ## `"unsupported"`
73
- *
74
- * ## `"no-tty"`
75
- *
76
- * ## `"no-such-device"`
77
- *
78
- * ## `"overflow"`
79
- *
80
- * ## `"not-permitted"`
81
- *
82
- * ## `"pipe"`
83
- *
84
- * ## `"read-only"`
85
- *
86
- * ## `"invalid-seek"`
87
- *
88
- * ## `"text-file-busy"`
89
- *
90
- * ## `"cross-device"`
91
- */
92
- 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';
93
- import type { OutputStream } from '../imports/wasi-io-streams';
94
- export { OutputStream };
95
- /**
96
- * # Variants
97
- *
98
- * ## `"unknown"`
99
- *
100
- * ## `"block-device"`
101
- *
102
- * ## `"character-device"`
103
- *
104
- * ## `"directory"`
105
- *
106
- * ## `"fifo"`
107
- *
108
- * ## `"symbolic-link"`
109
- *
110
- * ## `"regular-file"`
111
- *
112
- * ## `"socket"`
113
- */
114
- export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
115
- export type Device = bigint;
116
- export type Inode = bigint;
117
- export type LinkCount = bigint;
118
- import type { Datetime } from '../imports/wasi-clocks-wall-clock';
119
- export { Datetime };
120
- export interface DescriptorStat {
121
- device: Device,
122
- inode: Inode,
123
- type: DescriptorType,
124
- linkCount: LinkCount,
125
- size: Filesize,
126
- dataAccessTimestamp: Datetime,
127
- dataModificationTimestamp: Datetime,
128
- statusChangeTimestamp: Datetime,
129
- }
130
- export interface PathFlags {
131
- symlinkFollow?: boolean,
132
- }
133
- export interface OpenFlags {
134
- create?: boolean,
135
- directory?: boolean,
136
- exclusive?: boolean,
137
- truncate?: boolean,
138
- }
139
- export interface DescriptorFlags {
140
- read?: boolean,
141
- write?: boolean,
142
- fileIntegritySync?: boolean,
143
- dataIntegritySync?: boolean,
144
- requestedWriteSync?: boolean,
145
- mutateDirectory?: boolean,
146
- }
147
- export interface Modes {
148
- readable?: boolean,
149
- writable?: boolean,
150
- executable?: boolean,
151
- }
152
- export type DirectoryEntryStream = number;
@@ -1,3 +0,0 @@
1
- export namespace Environment {
2
- export function getEnvironment(): [string, string][];
3
- }
@@ -1,4 +0,0 @@
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 };