Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 25, 2024
1 parent 35316ec commit a91f76b
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 149 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ wasm-encoder = "0.40.0"
wasm-metadata = "0.10.16"
wasmparser = "0.120.0"
wasmprinter = "0.2.77"
wasmtime-environ = { version = "16.0.0", features = ["component-model"] }
wasmtime-environ = { version = "17.0.0", features = ["component-model"] }
wat = "1.0.84"
wit-bindgen = "0.16.0"
wit-bindgen-core = "0.16.0"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bytecodealliance/jco",
"version": "0.14.2",
"version": "1.0.0",
"description": "JavaScript tooling for working with WebAssembly Components",
"author": "Guy Bedford",
"bin": {
Expand All @@ -18,7 +18,7 @@
},
"type": "module",
"dependencies": {
"@bytecodealliance/preview2-shim": "0.14.2",
"@bytecodealliance/preview2-shim": "0.15.1",
"binaryen": "^111.0.0",
"chalk-template": "^0.4.0",
"commander": "^9.4.1",
Expand All @@ -34,7 +34,7 @@
"eslint": "^8.30.0",
"mocha": "^10.2.0",
"terser": "^5.16.1",
"typescript": "^4.3.2"
"typescript": "^5.3.3"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/preview2-shim/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bytecodealliance/preview2-shim",
"version": "0.14.2",
"version": "0.15.1",
"description": "WASI Preview2 shim for JS environments",
"author": "Guy Bedford, Eduardo Rodrigues<[email protected]>",
"type": "module",
Expand Down
23 changes: 23 additions & 0 deletions packages/preview2-shim/types/cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { WasiCliEnvironment } from './interfaces/wasi-cli-environment.d.ts';
import type { WasiCliExit } from './interfaces/wasi-cli-exit.d.ts';
import type { WasiCliRun } from './interfaces/wasi-cli-run.d.ts';
import type { WasiCliStderr } from './interfaces/wasi-cli-stderr.d.ts';
import type { WasiCliStdin } from './interfaces/wasi-cli-stdin.d.ts';
import type { WasiCliStdout } from './interfaces/wasi-cli-stdout.d.ts';
import type { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input.d.ts';
import type { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output.d.ts';
import type { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr.d.ts';
import type { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin.d.ts';
import type { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout.d.ts';

export const environment: typeof WasiCliEnvironment;
export const exit: typeof WasiCliExit;
export const run: typeof WasiCliRun;
export const stderr: typeof WasiCliStderr;
export const stdin: typeof WasiCliStdin;
export const stdout: typeof WasiCliStdout;
export const terminalInput: typeof WasiCliTerminalInput;
export const terminalOutput: typeof WasiCliTerminalOutput;
export const terminalStderr: typeof WasiCliTerminalStderr;
export const terminalStdin: typeof WasiCliTerminalStdin;
export const terminalStdout: typeof WasiCliTerminalStdout;
5 changes: 5 additions & 0 deletions packages/preview2-shim/types/clocks.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { WasiClocksMonotonicClock } from './interfaces/wasi-clocks-monotonic-clock.d.ts';
import type { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.d.ts';

export const wallClock: typeof WasiClocksMonotonicClock;
export const monotonicClock: typeof WasiClocksWallClock;
5 changes: 5 additions & 0 deletions packages/preview2-shim/types/filesystem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens.d.ts';
import type { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types.d.ts';

export const preopens: typeof WasiFilesystemPreopens;
export const types: typeof WasiFilesystemTypes;
7 changes: 7 additions & 0 deletions packages/preview2-shim/types/http.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { WasiHttpIncomingHandler } from './interfaces/wasi-http-incoming-handler.d.ts';
import type { WasiHttpOutgoingHandler } from './interfaces/wasi-http-outgoing-handler.d.ts';
import type { WasiHttpTypes } from './interfaces/wasi-http-types.d.ts';

export const incomingHandler: typeof WasiHttpIncomingHandler;
export const outgoingHandler: typeof WasiHttpOutgoingHandler;
export const types: typeof WasiHttpTypes;
15 changes: 15 additions & 0 deletions packages/preview2-shim/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type * as WasiCli from "./cli.d.ts";
import type * as WasiClocks from './clocks.d.ts';
import type * as WasiFilesystem from './filesystem.d.ts';
import type * as WasiHttp from "./http.d.ts";
import type * as WasiIo from "./io.d.ts";
import type * as WasiRandom from "./random.d.ts";
import type * as WasiSockets from "./sockets.d.ts";

export const cli: typeof WasiCli;
export const clocks: typeof WasiClocks;
export const filesystem: typeof WasiFilesystem;
export const http: typeof WasiHttp;
export const io: typeof WasiIo;
export const random: typeof WasiRandom;
export const sockets: typeof WasiSockets;
58 changes: 29 additions & 29 deletions packages/preview2-shim/types/interfaces/wasi-http-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ export type Trailers = Fields;
export type StatusCode = number;
export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };

export class ResponseOutparam {
static set(param: ResponseOutparam, response: Result<OutgoingResponse, ErrorCode>): void;
}

export class OutgoingResponse {
constructor(headers: Headers)
statusCode(): StatusCode;
setStatusCode(statusCode: StatusCode): void;
headers(): Headers;
body(): OutgoingBody;
}

export class OutgoingBody {
write(): OutputStream;
static finish(this_: OutgoingBody, trailers: Trailers | undefined): void;
Expand All @@ -640,50 +652,36 @@ export class Fields {
get(name: FieldKey): FieldValue[];
has(name: FieldKey): boolean;
set(name: FieldKey, value: FieldValue[]): void;
delete(name: FieldKey): void;
'delete'(name: FieldKey): void;
append(name: FieldKey, value: FieldValue): void;
entries(): [FieldKey, FieldValue][];
clone(): Fields;
}

export class FutureIncomingResponse {
subscribe(): Pollable;
get(): Result<Result<IncomingResponse, ErrorCode>, void> | undefined;
}

export class IncomingRequest {
method(): Method;
pathWithQuery(): string | undefined;
scheme(): Scheme | undefined;
authority(): string | undefined;
headers(): Headers;
consume(): IncomingBody;
}

export class IncomingBody {
stream(): InputStream;
static finish(this_: IncomingBody): FutureTrailers;
}

export class FutureIncomingResponse {
subscribe(): Pollable;
get(): Result<Result<IncomingResponse, ErrorCode>, void> | undefined;
}

export class FutureTrailers {
subscribe(): Pollable;
get(): Result<Result<Trailers | undefined, ErrorCode>, void> | undefined;
}

export class IncomingResponse {
status(): StatusCode;
export class IncomingRequest {
method(): Method;
pathWithQuery(): string | undefined;
scheme(): Scheme | undefined;
authority(): string | undefined;
headers(): Headers;
consume(): IncomingBody;
}

export class OutgoingResponse {
constructor(headers: Headers)
statusCode(): StatusCode;
setStatusCode(statusCode: StatusCode): void;
headers(): Headers;
body(): OutgoingBody;
}

export class OutgoingRequest {
constructor(headers: Headers)
body(): OutgoingBody;
Expand All @@ -698,6 +696,12 @@ export class OutgoingRequest {
headers(): Headers;
}

export class IncomingResponse {
status(): StatusCode;
headers(): Headers;
consume(): IncomingBody;
}

export class RequestOptions {
constructor()
connectTimeout(): Duration | undefined;
Expand All @@ -707,7 +711,3 @@ export class RequestOptions {
betweenBytesTimeout(): Duration | undefined;
setBetweenBytesTimeout(duration: Duration | undefined): void;
}

export class ResponseOutparam {
static set(param: ResponseOutparam, response: Result<OutgoingResponse, ErrorCode>): void;
}
21 changes: 16 additions & 5 deletions packages/preview2-shim/types/interfaces/wasi-io-streams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export namespace WasiIoStreams {
/**
* Perform a non-blocking read from the stream.
*
* When the source of a `read` is binary data, the bytes from the source
* are returned verbatim. When the source of a `read` is known to the
* implementation to be text, bytes containing the UTF-8 encoding of the
* text are returned.
*
* This function returns a list of bytes containing the read data,
* when successful. The returned list will contain up to `len` bytes;
* it may return fewer than requested, but not more. The list is
Expand Down Expand Up @@ -60,6 +65,12 @@ export namespace WasiIoStreams {
/**
* Perform a write. This function never blocks.
*
* When the destination of a `write` is binary data, the bytes from
* `contents` are written verbatim. When the destination of a `write` is
* known to the implementation to be text, the bytes of `contents` are
* transcoded from UTF-8 into the encoding of the destination and then
* written.
*
* Precondition: check-write gave permit of Ok(n) and contents has a
* length of less than or equal to n. Otherwise, this function will trap.
*
Expand All @@ -78,7 +89,7 @@ export namespace WasiIoStreams {
* let pollable = this.subscribe();
* while !contents.is_empty() {
* // Wait for the stream to become writable
* poll-one(pollable);
* pollable.block();
* let Ok(n) = this.check-write(); // eliding error handling
* let len = min(n, contents.len());
* let (chunk, rest) = contents.split_at(len);
Expand All @@ -87,7 +98,7 @@ export namespace WasiIoStreams {
* }
* this.flush();
* // Wait for completion of `flush`
* poll-one(pollable);
* pollable.block();
* // Check for any errors that arose during `flush`
* let _ = this.check-write(); // eliding error handling
* ```
Expand Down Expand Up @@ -123,7 +134,7 @@ export namespace WasiIoStreams {
/**
* Write zeroes to a stream.
*
* this should be used precisely like `write` with the exact same
* This should be used precisely like `write` with the exact same
* preconditions (must use check-write first), but instead of
* passing a list of bytes, you simply pass the number of zero-bytes
* that should be written.
Expand All @@ -141,15 +152,15 @@ export namespace WasiIoStreams {
* let pollable = this.subscribe();
* while num_zeroes != 0 {
* // Wait for the stream to become writable
* poll-one(pollable);
* pollable.block();
* let Ok(n) = this.check-write(); // eliding error handling
* let len = min(n, num_zeroes);
* this.write-zeroes(len); // eliding error handling
* num_zeroes -= len;
* }
* this.flush();
* // Wait for completion of `flush`
* poll-one(pollable);
* pollable.block();
* // Check for any errors that arose during `flush`
* let _ = this.check-write(); // eliding error handling
* ```
Expand Down
26 changes: 23 additions & 3 deletions packages/preview2-shim/types/interfaces/wasi-sockets-network.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export namespace WasiSocketsNetwork {
* The remote address is not reachable
* ## `"connection-refused"`
*
* The connection was forcefully rejected
* The TCP connection was forcefully rejected
* ## `"connection-reset"`
*
* The connection was reset.
* The TCP connection was reset.
* ## `"connection-aborted"`
*
* A connection was aborted.
* A TCP connection was aborted.
* ## `"datagram-too-large"`
*
* The size of a datagram sent to a UDP socket exceeded the maximum
* supported size.
* ## `"name-unresolvable"`
*
* Name does not exist or has no suitable associated IP addresses.
Expand Down Expand Up @@ -119,13 +121,31 @@ export interface IpAddressIpv6 {
val: Ipv6Address,
}
export interface Ipv4SocketAddress {
/**
* sin_port
*/
port: number,
/**
* sin_addr
*/
address: Ipv4Address,
}
export interface Ipv6SocketAddress {
/**
* sin6_port
*/
port: number,
/**
* sin6_flowinfo
*/
flowInfo: number,
/**
* sin6_addr
*/
address: Ipv6Address,
/**
* sin6_scope_id
*/
scopeId: number,
}
export type IpSocketAddress = IpSocketAddressIpv4 | IpSocketAddressIpv6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ export namespace WasiSocketsTcpCreateSocket {
* Create a new TCP socket.
*
* Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX.
* On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise.
*
* This function does not require a network capability handle. This is considered to be safe because
* at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`listen`/`connect`
* at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect`
* is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
*
* All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
Expand Down
Loading

0 comments on commit a91f76b

Please sign in to comment.