# tinywasi

> A tiny WASI runtime

Latest version **1.0.2** (published 2022-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install tinywasi
pnpm add tinywasi
yarn add tinywasi
bun add tinywasi
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-03-27 |
| First published | 2022-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^14.19.0 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 119 |
| Author | QRDate.org + contributors |
| Maintainers | miunau |

## Links

- npm: https://www.npmjs.com/package/tinywasi
- Repository: https://github.com/qrdate/tinywasi
- Homepage: https://github.com/qrdate/tinywasi#readme
- Issues: https://github.com/qrdate/tinywasi/issues
- npm.io page: https://npm.io/package/tinywasi

## Recent versions

- 1.0.2 (latest) — 2022-03-27
- 1.0.1 — 2022-03-27

## README

# Tiny WASI - A tiny WASI runtime written in typescript

This runtime implements the bare minimum set of functions to get most C/C++
libraries that have been compiled with the "reactor" exec model running.

The only thing it allows is writing to stdout/stderr, getting the current time
and getting random numbers, which should really be enough for everyone.

## Example

```ts
import { TinyWASI } from "tinywasi";

let tinywasi = new TinyWASI();

let imports = {
	<your_own_imports>,
	...tinywasi.imports
};

const { module, instance } = await WebAssembly.instantiate( <wasm_source>, imports );

tinywasi.initialize( instance );
```

## API

### `new TinyWASI( trace?: boolean )`

Instantiates a new TinyWASI runtime.

#### Parameters

* `trace`: boolean, optional. Wether or not to print all system calls to the
console for debugging.


### `initialize( instance: WebAssembly.Instance )`

Initializes the runtime and WASM instance. Call this before making any
other calls.

#### Parameters

* `instance`: WebAssembly instance to connect to and initialize.


### `imports: array`

Array containing the functions to be imported by the WebAssembly module.  
Pass this directly to `WebAssembly.instantiate` or add it to your own imports.


## Implemented system calls

Currently TinyWASI implements the following system calls:


### `fd_fdstat_get`

Implemented for the proper function of `stat` and `isatty` which are needed for
printing to stdout/stderr to work correctly.


### `fd_write`

Implemented for writing to stdout and stderr.
Writing to any other file descriptor returns `ERRNO_BADF`.

All writes to stdout (fd 1) are logged to the console using `console.log`.  
All writes to stderr (fd 2) are logged to the console using `console.error`.  


### `clock_res_get` and `clock_time_get`

Implemented to make functions like `time()` work.
Right now only the realtime clock (id 0) is supported.


### `random_get`

Implemented to make C++ `std::random_device` work.


## Unimplemented system calls

All other system calls are unimplemented and return `ERRNO_NOSYS` while printing
an error message to the console.


## Dependencies

None.

### Dev-Dependencies

* typescript - for compiling the typescript source files to javascript
* @types/node - typescript definitions for node's API

Optionally:

* prettier - for code formatting using the included .prettierrc

---
_Source: https://npm.io/package/tinywasi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
