From ad66e18dfc07a937e93ab20f698b57c0020b764a Mon Sep 17 00:00:00 2001
From: Yosh
Date: Tue, 28 May 2024 14:25:19 +0200
Subject: [PATCH 1/8] Document per-item versions using `@since` gates
---
wit/handler.wit | 4 +++
wit/proxy.wit | 10 +++++++
wit/types.wit | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/wit/handler.wit b/wit/handler.wit
index a34a064..deecce2 100644
--- a/wit/handler.wit
+++ b/wit/handler.wit
@@ -1,5 +1,6 @@
/// This interface defines a handler of incoming HTTP Requests. It should
/// be exported by components which can respond to HTTP Requests.
+@since(version = 0.2.0)
interface incoming-handler {
use types.{incoming-request, response-outparam};
@@ -13,6 +14,7 @@ interface incoming-handler {
/// The implementor of this function must write a response to the
/// `response-outparam` before returning, or else the caller will respond
/// with an error on its behalf.
+ @since(version = 0.2.0)
handle: func(
request: incoming-request,
response-out: response-outparam
@@ -21,6 +23,7 @@ interface incoming-handler {
/// This interface defines a handler of outgoing HTTP Requests. It should be
/// imported by components which wish to make HTTP Requests.
+@since(version = 0.2.0)
interface outgoing-handler {
use types.{
outgoing-request, request-options, future-incoming-response, error-code
@@ -36,6 +39,7 @@ interface outgoing-handler {
/// This function may return an error if the `outgoing-request` is invalid
/// or not allowed to be made. Otherwise, protocol errors are reported
/// through the `future-incoming-response`.
+ @since(version = 0.2.0)
handle: func(
request: outgoing-request,
options: option
diff --git a/wit/proxy.wit b/wit/proxy.wit
index 26a975e..e8966b0 100644
--- a/wit/proxy.wit
+++ b/wit/proxy.wit
@@ -2,24 +2,31 @@ package wasi:http@0.2.0;
/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
/// It is intended to be `include`d in other worlds.
+@since(version = 0.2.0)
world imports {
/// HTTP proxies have access to time and randomness.
+ @since(version = 0.2.0)
include wasi:clocks/imports@0.2.0;
+ @since(version = 0.2.0)
import wasi:random/random@0.2.0;
/// Proxies have standard output and error streams which are expected to
/// terminate in a developer-facing console provided by the host.
+ @since(version = 0.2.0)
import wasi:cli/stdout@0.2.0;
+ @since(version = 0.2.0)
import wasi:cli/stderr@0.2.0;
/// TODO: this is a temporary workaround until component tooling is able to
/// gracefully handle the absence of stdin. Hosts must return an eof stream
/// for this import, which is what wasi-libc + tooling will do automatically
/// when this import is properly removed.
+ @since(version = 0.2.0)
import wasi:cli/stdin@0.2.0;
/// This is the default handler to use when user code simply wants to make an
/// HTTP request (e.g., via `fetch()`).
+ @since(version = 0.2.0)
import outgoing-handler;
}
@@ -27,12 +34,15 @@ world imports {
/// hosts that includes HTTP forward and reverse proxies. Components targeting
/// this world may concurrently stream in and out any number of incoming and
/// outgoing HTTP requests.
+@since(version = 0.2.0)
world proxy {
+ @since(version = 0.2.0)
include imports;
/// The host delivers incoming HTTP requests to a component by calling the
/// `handle` function of this exported interface. A host may arbitrarily reuse
/// or not reuse component instance when delivering incoming HTTP requests and
/// thus a component must be able to handle 0..N calls to `handle`.
+ @since(version = 0.2.0)
export incoming-handler;
}
diff --git a/wit/types.wit b/wit/types.wit
index 0ead178..5f6cfd7 100644
--- a/wit/types.wit
+++ b/wit/types.wit
@@ -1,6 +1,7 @@
/// This interface defines all of the types and methods for implementing
/// HTTP Requests and Responses, both incoming and outgoing, as well as
/// their headers, trailers, and bodies.
+@since(version = 0.2.0)
interface types {
use wasi:clocks/monotonic-clock@0.2.0.{duration};
use wasi:io/streams@0.2.0.{input-stream, output-stream};
@@ -8,6 +9,7 @@ interface types {
use wasi:io/poll@0.2.0.{pollable};
/// This type corresponds to HTTP standard Methods.
+ @since(version = 0.2.0)
variant method {
get,
head,
@@ -22,6 +24,7 @@ interface types {
}
/// This type corresponds to HTTP standard Related Schemes.
+ @since(version = 0.2.0)
variant scheme {
HTTP,
HTTPS,
@@ -30,6 +33,7 @@ interface types {
/// These cases are inspired by the IANA HTTP Proxy Error Types:
/// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
+ @since(version = 0.2.0)
variant error-code {
DNS-timeout,
DNS-error(DNS-error-payload),
@@ -78,18 +82,21 @@ interface types {
}
/// Defines the case payload type for `DNS-error` above:
+ @since(version = 0.2.0)
record DNS-error-payload {
rcode: option,
info-code: option
}
/// Defines the case payload type for `TLS-alert-received` above:
+ @since(version = 0.2.0)
record TLS-alert-received-payload {
alert-id: option,
alert-message: option
}
/// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+ @since(version = 0.2.0)
record field-size-payload {
field-name: option,
field-size: option
@@ -106,10 +113,12 @@ interface types {
///
/// Note that this function is fallible because not all io-errors are
/// http-related errors.
+ @since(version = 0.2.0)
http-error-code: func(err: borrow) -> option;
/// This type enumerates the different kinds of errors that may occur when
/// setting or appending to a `fields` resource.
+ @since(version = 0.2.0)
variant header-error {
/// This error indicates that a `field-key` or `field-value` was
/// syntactically invalid when used with an operation that sets headers in a
@@ -126,11 +135,13 @@ interface types {
}
/// Field keys are always strings.
+ @since(version = 0.2.0)
type field-key = string;
/// Field values should always be ASCII strings. However, in
/// reality, HTTP implementations often have to interpret malformed values,
/// so they are provided as a list of bytes.
+ @since(version = 0.2.0)
type field-value = list;
/// This following block defines the `fields` resource which corresponds to
@@ -143,11 +154,13 @@ interface types {
/// `incoming-request.headers`, `outgoing-request.headers`) might be be
/// immutable. In an immutable fields, the `set`, `append`, and `delete`
/// operations will fail with `header-error.immutable`.
+ @since(version = 0.2.0)
resource fields {
/// Construct an empty HTTP Fields.
///
/// The resulting `fields` is mutable.
+ @since(version = 0.2.0)
constructor();
/// Construct an HTTP Fields.
@@ -163,6 +176,7 @@ interface types {
///
/// An error result will be returned if any `field-key` or `field-value` is
/// syntactically invalid, or if a field is forbidden.
+ @since(version = 0.2.0)
from-list: static func(
entries: list>
) -> result;
@@ -171,10 +185,12 @@ interface types {
/// in this `fields` or is syntactically invalid, an empty list is returned.
/// However, if the key is present but empty, this is represented by a list
/// with one or more empty field-values present.
+ @since(version = 0.2.0)
get: func(name: field-key) -> list;
/// Returns `true` when the key is present in this `fields`. If the key is
/// syntactically invalid, `false` is returned.
+ @since(version = 0.2.0)
has: func(name: field-key) -> bool;
/// Set all of the values for a key. Clears any existing values for that
@@ -184,6 +200,7 @@ interface types {
///
/// Fails with `header-error.invalid-syntax` if the `field-key` or any of
/// the `field-value`s are syntactically invalid.
+ @since(version = 0.2.0)
set: func(name: field-key, value: list) -> result<_, header-error>;
/// Delete all values for a key. Does nothing if no values for the key
@@ -193,6 +210,7 @@ interface types {
///
/// Fails with `header-error.invalid-syntax` if the `field-key` is
/// syntactically invalid.
+ @since(version = 0.2.0)
delete: func(name: field-key) -> result<_, header-error>;
/// Append a value for a key. Does not change or delete any existing
@@ -202,6 +220,7 @@ interface types {
///
/// Fails with `header-error.invalid-syntax` if the `field-key` or
/// `field-value` are syntactically invalid.
+ @since(version = 0.2.0)
append: func(name: field-key, value: field-value) -> result<_, header-error>;
/// Retrieve the full set of keys and values in the Fields. Like the
@@ -210,33 +229,42 @@ interface types {
/// The outer list represents each key-value pair in the Fields. Keys
/// which have multiple values are represented by multiple entries in this
/// list with the same key.
+ @since(version = 0.2.0)
entries: func() -> list>;
/// Make a deep copy of the Fields. Equivalent in behavior to calling the
/// `fields` constructor on the return value of `entries`. The resulting
/// `fields` is mutable.
+ @since(version = 0.2.0)
clone: func() -> fields;
}
/// Headers is an alias for Fields.
+ @since(version = 0.2.0)
type headers = fields;
/// Trailers is an alias for Fields.
+ @since(version = 0.2.0)
type trailers = fields;
/// Represents an incoming HTTP Request.
+ @since(version = 0.2.0)
resource incoming-request {
/// Returns the method of the incoming request.
+ @since(version = 0.2.0)
method: func() -> method;
/// Returns the path with query parameters from the request, as a string.
+ @since(version = 0.2.0)
path-with-query: func() -> option;
/// Returns the protocol scheme from the request.
+ @since(version = 0.2.0)
scheme: func() -> option;
/// Returns the authority from the request, if it was present.
+ @since(version = 0.2.0)
authority: func() -> option;
/// Get the `headers` associated with the request.
@@ -247,14 +275,17 @@ interface types {
/// The `headers` returned are a child resource: it must be dropped before
/// the parent `incoming-request` is dropped. Dropping this
/// `incoming-request` before all children are dropped will trap.
+ @since(version = 0.2.0)
headers: func() -> headers;
/// Gives the `incoming-body` associated with this request. Will only
/// return success at most once, and subsequent calls will return error.
+ @since(version = 0.2.0)
consume: func() -> result;
}
/// Represents an outgoing HTTP Request.
+ @since(version = 0.2.0)
resource outgoing-request {
/// Construct a new `outgoing-request` with a default `method` of `GET`, and
@@ -267,6 +298,7 @@ interface types {
/// and `authority`, or `headers` which are not permitted to be sent.
/// It is the obligation of the `outgoing-handler.handle` implementation
/// to reject invalid constructions of `outgoing-request`.
+ @since(version = 0.2.0)
constructor(
headers: headers
);
@@ -277,38 +309,47 @@ interface types {
/// Returns success on the first call: the `outgoing-body` resource for
/// this `outgoing-request` can be retrieved at most once. Subsequent
/// calls will return error.
+ @since(version = 0.2.0)
body: func() -> result;
/// Get the Method for the Request.
+ @since(version = 0.2.0)
method: func() -> method;
/// Set the Method for the Request. Fails if the string present in a
/// `method.other` argument is not a syntactically valid method.
+ @since(version = 0.2.0)
set-method: func(method: method) -> result;
/// Get the combination of the HTTP Path and Query for the Request.
/// When `none`, this represents an empty Path and empty Query.
+ @since(version = 0.2.0)
path-with-query: func() -> option;
/// Set the combination of the HTTP Path and Query for the Request.
/// When `none`, this represents an empty Path and empty Query. Fails is the
/// string given is not a syntactically valid path and query uri component.
+ @since(version = 0.2.0)
set-path-with-query: func(path-with-query: option) -> result;
/// Get the HTTP Related Scheme for the Request. When `none`, the
/// implementation may choose an appropriate default scheme.
+ @since(version = 0.2.0)
scheme: func() -> option;
/// Set the HTTP Related Scheme for the Request. When `none`, the
/// implementation may choose an appropriate default scheme. Fails if the
/// string given is not a syntactically valid uri scheme.
+ @since(version = 0.2.0)
set-scheme: func(scheme: option) -> result;
/// Get the HTTP Authority for the Request. A value of `none` may be used
/// with Related Schemes which do not require an Authority. The HTTP and
/// HTTPS schemes always require an authority.
+ @since(version = 0.2.0)
authority: func() -> option;
/// Set the HTTP Authority for the Request. A value of `none` may be used
/// with Related Schemes which do not require an Authority. The HTTP and
/// HTTPS schemes always require an authority. Fails if the string given is
/// not a syntactically valid uri authority.
+ @since(version = 0.2.0)
set-authority: func(authority: option) -> result;
/// Get the headers associated with the Request.
@@ -319,6 +360,7 @@ interface types {
/// This headers resource is a child: it must be dropped before the parent
/// `outgoing-request` is dropped, or its ownership is transferred to
/// another component by e.g. `outgoing-handler.handle`.
+ @since(version = 0.2.0)
headers: func() -> headers;
}
@@ -328,31 +370,39 @@ interface types {
///
/// These timeouts are separate from any the user may use to bound a
/// blocking call to `wasi:io/poll.poll`.
+ @since(version = 0.2.0)
resource request-options {
/// Construct a default `request-options` value.
+ @since(version = 0.2.0)
constructor();
/// The timeout for the initial connect to the HTTP Server.
+ @since(version = 0.2.0)
connect-timeout: func() -> option;
/// Set the timeout for the initial connect to the HTTP Server. An error
/// return value indicates that this timeout is not supported.
+ @since(version = 0.2.0)
set-connect-timeout: func(duration: option) -> result;
/// The timeout for receiving the first byte of the Response body.
+ @since(version = 0.2.0)
first-byte-timeout: func() -> option;
/// Set the timeout for receiving the first byte of the Response body. An
/// error return value indicates that this timeout is not supported.
+ @since(version = 0.2.0)
set-first-byte-timeout: func(duration: option) -> result;
/// The timeout for receiving subsequent chunks of bytes in the Response
/// body stream.
+ @since(version = 0.2.0)
between-bytes-timeout: func() -> option;
/// Set the timeout for receiving subsequent chunks of bytes in the Response
/// body stream. An error return value indicates that this timeout is not
/// supported.
+ @since(version = 0.2.0)
set-between-bytes-timeout: func(duration: option) -> result;
}
@@ -361,6 +411,7 @@ interface types {
/// This resource is used by the `wasi:http/incoming-handler` interface to
/// allow a Response to be sent corresponding to the Request provided as the
/// other argument to `incoming-handler.handle`.
+ @since(version = 0.2.0)
resource response-outparam {
/// Set the value of the `response-outparam` to either send a response,
@@ -372,6 +423,7 @@ interface types {
///
/// The user may provide an `error` to `response` to allow the
/// implementation determine how to respond with an HTTP error response.
+ @since(version = 0.2.0)
set: static func(
param: response-outparam,
response: result,
@@ -379,12 +431,15 @@ interface types {
}
/// This type corresponds to the HTTP standard Status Code.
+ @since(version = 0.2.0)
type status-code = u16;
/// Represents an incoming HTTP Response.
+ @since(version = 0.2.0)
resource incoming-response {
/// Returns the status code from the incoming response.
+ @since(version = 0.2.0)
status: func() -> status-code;
/// Returns the headers from the incoming response.
@@ -394,10 +449,12 @@ interface types {
///
/// This headers resource is a child: it must be dropped before the parent
/// `incoming-response` is dropped.
+ @since(version = 0.2.0)
headers: func() -> headers;
/// Returns the incoming body. May be called at most once. Returns error
/// if called additional times.
+ @since(version = 0.2.0)
consume: func() -> result;
}
@@ -409,6 +466,7 @@ interface types {
/// an `input-stream` and the delivery of trailers as a `future-trailers`,
/// and ensures that the user of this interface may only be consuming either
/// the body contents or waiting on trailers at any given time.
+ @since(version = 0.2.0)
resource incoming-body {
/// Returns the contents of the body, as a stream of bytes.
@@ -426,10 +484,12 @@ interface types {
/// backpressure is to be applied when the user is consuming the body,
/// and for that backpressure to not inhibit delivery of the trailers if
/// the user does not read the entire body.
+ @since(version = 0.2.0)
%stream: func() -> result;
/// Takes ownership of `incoming-body`, and returns a `future-trailers`.
/// This function will trap if the `input-stream` child is still alive.
+ @since(version = 0.2.0)
finish: static func(this: incoming-body) -> future-trailers;
}
@@ -438,11 +498,13 @@ interface types {
/// In the case that the incoming HTTP Request or Response did not have any
/// trailers, this future will resolve to the empty set of trailers once the
/// complete Request or Response body has been received.
+ @since(version = 0.2.0)
resource future-trailers {
/// Returns a pollable which becomes ready when either the trailers have
/// been received, or an error has occurred. When this pollable is ready,
/// the `get` method will return `some`.
+ @since(version = 0.2.0)
subscribe: func() -> pollable;
/// Returns the contents of the trailers, or an error which occurred,
@@ -464,10 +526,12 @@ interface types {
/// resource is immutable, and a child. Use of the `set`, `append`, or
/// `delete` methods will return an error, and the resource must be
/// dropped before the parent `future-trailers` is dropped.
+ @since(version = 0.2.0)
get: func() -> option, error-code>>>;
}
/// Represents an outgoing HTTP Response.
+ @since(version = 0.2.0)
resource outgoing-response {
/// Construct an `outgoing-response`, with a default `status-code` of `200`.
@@ -475,13 +539,16 @@ interface types {
/// `set-status-code` method.
///
/// * `headers` is the HTTP Headers for the Response.
+ @since(version = 0.2.0)
constructor(headers: headers);
/// Get the HTTP Status Code for the Response.
+ @since(version = 0.2.0)
status-code: func() -> status-code;
/// Set the HTTP Status Code for the Response. Fails if the status-code
/// given is not a valid http status code.
+ @since(version = 0.2.0)
set-status-code: func(status-code: status-code) -> result;
/// Get the headers associated with the Request.
@@ -492,6 +559,7 @@ interface types {
/// This headers resource is a child: it must be dropped before the parent
/// `outgoing-request` is dropped, or its ownership is transferred to
/// another component by e.g. `outgoing-handler.handle`.
+ @since(version = 0.2.0)
headers: func() -> headers;
/// Returns the resource corresponding to the outgoing Body for this Response.
@@ -499,6 +567,7 @@ interface types {
/// Returns success on the first call: the `outgoing-body` resource for
/// this `outgoing-response` can be retrieved at most once. Subsequent
/// calls will return error.
+ @since(version = 0.2.0)
body: func() -> result;
}
@@ -518,6 +587,7 @@ interface types {
/// error to the HTTP protocol by whatever means it has available,
/// including: corrupting the body on the wire, aborting the associated
/// Request, or sending a late status code for the Response.
+ @since(version = 0.2.0)
resource outgoing-body {
/// Returns a stream for writing the body contents.
@@ -529,6 +599,7 @@ interface types {
/// Returns success on the first call: the `output-stream` resource for
/// this `outgoing-body` may be retrieved at most once. Subsequent calls
/// will return error.
+ @since(version = 0.2.0)
write: func() -> result;
/// Finalize an outgoing body, optionally providing trailers. This must be
@@ -540,6 +611,7 @@ interface types {
/// constructed with a Content-Length header, and the contents written
/// to the body (via `write`) does not match the value given in the
/// Content-Length.
+ @since(version = 0.2.0)
finish: static func(
this: outgoing-body,
trailers: option
@@ -551,10 +623,12 @@ interface types {
///
/// This resource is returned by the `wasi:http/outgoing-handler` interface to
/// provide the HTTP Response corresponding to the sent Request.
+ @since(version = 0.2.0)
resource future-incoming-response {
/// Returns a pollable which becomes ready when either the Response has
/// been received, or an error has occurred. When this pollable is ready,
/// the `get` method will return `some`.
+ @since(version = 0.2.0)
subscribe: func() -> pollable;
/// Returns the incoming HTTP Response, or an error, once one is ready.
@@ -571,7 +645,7 @@ interface types {
/// occurred. Errors may also occur while consuming the response body,
/// but those will be reported by the `incoming-body` and its
/// `output-stream` child.
+ @since(version = 0.2.0)
get: func() -> option>>;
-
}
}
From d6d9ccb6b240d94c9b3eea496a869cfd696db754 Mon Sep 17 00:00:00 2001
From: Yosh
Date: Fri, 21 Jun 2024 02:13:08 +0200
Subject: [PATCH 2/8] annotate `use` statements
---
wit-0.3.0-draft/handler.wit | 1 +
wit-0.3.0-draft/types.wit | 2 ++
wit/handler.wit | 2 ++
wit/types.wit | 4 ++++
4 files changed, 9 insertions(+)
diff --git a/wit-0.3.0-draft/handler.wit b/wit-0.3.0-draft/handler.wit
index 099d094..a2c5bc5 100644
--- a/wit-0.3.0-draft/handler.wit
+++ b/wit-0.3.0-draft/handler.wit
@@ -3,6 +3,7 @@
/// which can respond to HTTP Requests. In addition, it may be used to pass
/// a request from one component to another without any use of a network.
interface handler {
+ @since(version = 0.2.0)
use types.{request, response, error-code};
/// When exported, this function may be called with either an incoming
diff --git a/wit-0.3.0-draft/types.wit b/wit-0.3.0-draft/types.wit
index 58c655c..eda519d 100644
--- a/wit-0.3.0-draft/types.wit
+++ b/wit-0.3.0-draft/types.wit
@@ -1,7 +1,9 @@
/// This interface defines all of the types and methods for implementing HTTP
/// Requests and Responses, as well as their headers, trailers, and bodies.
interface types {
+ @since(version = 0.2.0)
use wasi:clocks/monotonic-clock@0.2.0.{duration};
+ @since(version = 0.2.0)
use wasi:io/error@0.2.0.{error};
/// This type corresponds to HTTP standard Methods.
diff --git a/wit/handler.wit b/wit/handler.wit
index deecce2..6a6c629 100644
--- a/wit/handler.wit
+++ b/wit/handler.wit
@@ -2,6 +2,7 @@
/// be exported by components which can respond to HTTP Requests.
@since(version = 0.2.0)
interface incoming-handler {
+ @since(version = 0.2.0)
use types.{incoming-request, response-outparam};
/// This function is invoked with an incoming HTTP Request, and a resource
@@ -25,6 +26,7 @@ interface incoming-handler {
/// imported by components which wish to make HTTP Requests.
@since(version = 0.2.0)
interface outgoing-handler {
+ @since(version = 0.2.0)
use types.{
outgoing-request, request-options, future-incoming-response, error-code
};
diff --git a/wit/types.wit b/wit/types.wit
index 5f6cfd7..981c110 100644
--- a/wit/types.wit
+++ b/wit/types.wit
@@ -3,9 +3,13 @@
/// their headers, trailers, and bodies.
@since(version = 0.2.0)
interface types {
+ @since(version = 0.2.0)
use wasi:clocks/monotonic-clock@0.2.0.{duration};
+ @since(version = 0.2.0)
use wasi:io/streams@0.2.0.{input-stream, output-stream};
+ @since(version = 0.2.0)
use wasi:io/error@0.2.0.{error as io-error};
+ @since(version = 0.2.0)
use wasi:io/poll@0.2.0.{pollable};
/// This type corresponds to HTTP standard Methods.
From 0dcd165c4e81758de7ad960694aab7e2b6962cc0 Mon Sep 17 00:00:00 2001
From: Yosh
Date: Mon, 24 Jun 2024 02:59:05 +0200
Subject: [PATCH 3/8] update `wit-abi-up-to-date` to parse `@since` gates
---
.github/workflows/main.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 113cfe9..43efdf3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -16,7 +16,7 @@ jobs:
curl -Lo 'wit-deps' https://github.com/bytecodealliance/wit-deps/releases/download/v0.3.2/wit-deps-x86_64-unknown-linux-musl
chmod +x ./wit-deps
./wit-deps lock --check
- - uses: WebAssembly/wit-abi-up-to-date@v17
+ - uses: WebAssembly/wit-abi-up-to-date@v21
with:
wit-bindgen: '0.17.0'
- worlds: 'imports proxy'
\ No newline at end of file
+ worlds: 'imports proxy'
From 703f971a29e9a55020a4ca477c4c8291712972db Mon Sep 17 00:00:00 2001
From: Yosh
Date: Sat, 13 Jul 2024 17:13:44 +0200
Subject: [PATCH 4/8] update wit deps
---
wit/deps.lock | 20 +++++-----
wit/deps/clocks/monotonic-clock.wit | 17 +++++---
wit/deps/clocks/timezone.wit | 55 ++++++++++++++++++++++++++
wit/deps/clocks/wall-clock.wit | 4 ++
wit/deps/clocks/world.wit | 5 +++
wit/deps/filesystem/preopens.wit | 3 ++
wit/deps/filesystem/types.wit | 44 +++++++++++++++++++++
wit/deps/filesystem/world.wit | 3 ++
wit/deps/io/error.wit | 16 ++++----
wit/deps/io/poll.wit | 12 ++++--
wit/deps/io/streams.wit | 20 ++++++++++
wit/deps/io/world.wit | 4 ++
wit/deps/random/insecure-seed.wit | 2 +
wit/deps/random/insecure.wit | 3 ++
wit/deps/random/random.wit | 3 ++
wit/deps/random/world.wit | 6 +++
wit/deps/sockets/instance-network.wit | 4 +-
wit/deps/sockets/ip-name-lookup.wit | 9 ++++-
wit/deps/sockets/network.wit | 12 +++++-
wit/deps/sockets/tcp-create-socket.wit | 5 ++-
wit/deps/sockets/tcp.wit | 48 ++++++++++++++++++----
wit/deps/sockets/udp-create-socket.wit | 5 ++-
wit/deps/sockets/udp.wit | 28 +++++++++++--
wit/deps/sockets/world.wit | 8 ++++
24 files changed, 292 insertions(+), 44 deletions(-)
create mode 100644 wit/deps/clocks/timezone.wit
diff --git a/wit/deps.lock b/wit/deps.lock
index 96be4b2..3439253 100644
--- a/wit/deps.lock
+++ b/wit/deps.lock
@@ -5,25 +5,25 @@ sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913
[clocks]
url = "https://github.com/WebAssembly/wasi-clocks/archive/main.tar.gz"
-sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613"
-sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a"
+sha256 = "f27a857de70c1b0dfbabda35812a8de1253089623b1a84ddd066183c6ffac5f8"
+sha512 = "9df1b0be1e4925f671fda65d433217798404f8e2e4fa60ff8bfdfd257f0b6d212ea350c141f308cf4cc57fb0b44899b14af1f9af97a05dcd6f8ae00a7594de8d"
[filesystem]
url = "https://github.com/WebAssembly/wasi-filesystem/archive/main.tar.gz"
-sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b"
-sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347"
+sha256 = "e37bda5e27222621771ba07d2e9daf862a728c31f91024badfc4f9a42c9ae8ee"
+sha512 = "81e92f5e4eca0c8f9606f26a1c4eebb3c53a708b57d3f7e7c60e97aa3c18794b72a44c39212de566442e25313b5ccb5b0b7c9070f3600f0c7c584ea9db91e207"
[io]
url = "https://github.com/WebAssembly/wasi-io/archive/main.tar.gz"
-sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c"
-sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb"
+sha256 = "f3e976740ed9512674c627c6588864c477a9ff539bb7e55c7b9ceab222399b52"
+sha512 = "c785122b4c04e2297e3fa37ae76c149b0a681444da106758cf673023923b69a6b2c65624ffbb6ad31edef02f9fbc677b05c89525f07b1159fe0c997a8c6b1a8f"
[random]
url = "https://github.com/WebAssembly/wasi-random/archive/main.tar.gz"
-sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d"
-sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4"
+sha256 = "2f0014e946e38947afe120836b17cdcfa608be993d38d55b81cc2d31e7e70b16"
+sha512 = "51ee623509040de77b0ba236e29589102538aacd3dd67168b06a09bf6ae469c762818fc07b5039d2a8b1838f4b5a5965a7c81ed0e2d47b142bece9d1ab8b93a6"
[sockets]
url = "https://github.com/WebAssembly/wasi-sockets/archive/main.tar.gz"
-sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966"
-sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae"
+sha256 = "5321ba37115d503bfe0880349e99ecbd26ee812708fa83d2b276ec8ee7571443"
+sha512 = "c3d71c2afa1475bf10d86b1e0623e2292e5dd407cf54103ad0d05c07fa95323bff9ad06e929d508b318a0a99a67132793fb9a04c17585843e24f090f5ee91367"
diff --git a/wit/deps/clocks/monotonic-clock.wit b/wit/deps/clocks/monotonic-clock.wit
index 4e4dc3a..cae2363 100644
--- a/wit/deps/clocks/monotonic-clock.wit
+++ b/wit/deps/clocks/monotonic-clock.wit
@@ -7,38 +7,43 @@ package wasi:clocks@0.2.0;
///
/// A monotonic clock is a clock which has an unspecified initial value, and
/// successive reads of the clock will produce non-decreasing values.
-///
-/// It is intended for measuring elapsed time.
+@since(version = 0.2.0)
interface monotonic-clock {
+ @since(version = 0.2.0)
use wasi:io/poll@0.2.0.{pollable};
/// An instant in time, in nanoseconds. An instant is relative to an
/// unspecified initial value, and can only be compared to instances from
/// the same monotonic-clock.
+ @since(version = 0.2.0)
type instant = u64;
/// A duration of time, in nanoseconds.
+ @since(version = 0.2.0)
type duration = u64;
/// Read the current value of the clock.
///
/// The clock is monotonic, therefore calling this function repeatedly will
/// produce a sequence of non-decreasing values.
+ @since(version = 0.2.0)
now: func() -> instant;
/// Query the resolution of the clock. Returns the duration of time
/// corresponding to a clock tick.
+ @since(version = 0.2.0)
resolution: func() -> duration;
/// Create a `pollable` which will resolve once the specified instant
- /// occured.
+ /// has occured.
+ @since(version = 0.2.0)
subscribe-instant: func(
when: instant,
) -> pollable;
- /// Create a `pollable` which will resolve once the given duration has
- /// elapsed, starting at the time at which this function was called.
- /// occured.
+ /// Create a `pollable` that will resolve after the specified duration has
+ /// elapsed from the time this function is invoked.
+ @since(version = 0.2.0)
subscribe-duration: func(
when: duration,
) -> pollable;
diff --git a/wit/deps/clocks/timezone.wit b/wit/deps/clocks/timezone.wit
new file mode 100644
index 0000000..3c28688
--- /dev/null
+++ b/wit/deps/clocks/timezone.wit
@@ -0,0 +1,55 @@
+package wasi:clocks@0.2.0;
+
+@unstable(feature = clocks-timezone)
+interface timezone {
+ @unstable(feature = clocks-timezone)
+ use wall-clock.{datetime};
+
+ /// Return information needed to display the given `datetime`. This includes
+ /// the UTC offset, the time zone name, and a flag indicating whether
+ /// daylight saving time is active.
+ ///
+ /// If the timezone cannot be determined for the given `datetime`, return a
+ /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
+ /// saving time.
+ @unstable(feature = clocks-timezone)
+ display: func(when: datetime) -> timezone-display;
+
+ /// The same as `display`, but only return the UTC offset.
+ @unstable(feature = clocks-timezone)
+ utc-offset: func(when: datetime) -> s32;
+
+ /// Information useful for displaying the timezone of a specific `datetime`.
+ ///
+ /// This information may vary within a single `timezone` to reflect daylight
+ /// saving time adjustments.
+ @unstable(feature = clocks-timezone)
+ record timezone-display {
+ /// The number of seconds difference between UTC time and the local
+ /// time of the timezone.
+ ///
+ /// The returned value will always be less than 86400 which is the
+ /// number of seconds in a day (24*60*60).
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should return 0.
+ utc-offset: s32,
+
+ /// The abbreviated name of the timezone to display to a user. The name
+ /// `UTC` indicates Coordinated Universal Time. Otherwise, this should
+ /// reference local standards for the name of the time zone.
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should be the string `UTC`.
+ ///
+ /// In time zones that do not have an applicable name, a formatted
+ /// representation of the UTC offset may be returned, such as `-04:00`.
+ name: string,
+
+ /// Whether daylight saving time is active.
+ ///
+ /// In implementations that do not expose an actual time zone, this
+ /// should return false.
+ in-daylight-saving-time: bool,
+ }
+}
diff --git a/wit/deps/clocks/wall-clock.wit b/wit/deps/clocks/wall-clock.wit
index 440ca0f..4b08d71 100644
--- a/wit/deps/clocks/wall-clock.wit
+++ b/wit/deps/clocks/wall-clock.wit
@@ -13,8 +13,10 @@ package wasi:clocks@0.2.0;
/// monotonic, making it unsuitable for measuring elapsed time.
///
/// It is intended for reporting the current date and time for humans.
+@since(version = 0.2.0)
interface wall-clock {
/// A time and date in seconds plus nanoseconds.
+ @since(version = 0.2.0)
record datetime {
seconds: u64,
nanoseconds: u32,
@@ -33,10 +35,12 @@ interface wall-clock {
///
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
+ @since(version = 0.2.0)
now: func() -> datetime;
/// Query the resolution of the clock.
///
/// The nanoseconds field of the output is always less than 1000000000.
+ @since(version = 0.2.0)
resolution: func() -> datetime;
}
diff --git a/wit/deps/clocks/world.wit b/wit/deps/clocks/world.wit
index c022457..76a9206 100644
--- a/wit/deps/clocks/world.wit
+++ b/wit/deps/clocks/world.wit
@@ -1,6 +1,11 @@
package wasi:clocks@0.2.0;
+@since(version = 0.2.0)
world imports {
+ @since(version = 0.2.0)
import monotonic-clock;
+ @since(version = 0.2.0)
import wall-clock;
+ @unstable(feature = clocks-timezone)
+ import timezone;
}
diff --git a/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit
index da801f6..08094ab 100644
--- a/wit/deps/filesystem/preopens.wit
+++ b/wit/deps/filesystem/preopens.wit
@@ -1,8 +1,11 @@
package wasi:filesystem@0.2.0;
+@since(version = 0.2.0)
interface preopens {
+ @since(version = 0.2.0)
use types.{descriptor};
/// Return the set of preopened directories, and their path.
+ @since(version = 0.2.0)
get-directories: func() -> list>;
}
diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit
index 11108fc..4900ae2 100644
--- a/wit/deps/filesystem/types.wit
+++ b/wit/deps/filesystem/types.wit
@@ -23,16 +23,21 @@ package wasi:filesystem@0.2.0;
/// [WASI filesystem path resolution].
///
/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
+@since(version = 0.2.0)
interface types {
+ @since(version = 0.2.0)
use wasi:io/streams@0.2.0.{input-stream, output-stream, error};
+ @since(version = 0.2.0)
use wasi:clocks/wall-clock@0.2.0.{datetime};
/// File size or length of a region within a file.
+ @since(version = 0.2.0)
type filesize = u64;
/// The type of a filesystem object referenced by a descriptor.
///
/// Note: This was called `filetype` in earlier versions of WASI.
+ @since(version = 0.2.0)
enum descriptor-type {
/// The type of the descriptor or file is unknown or is different from
/// any of the other types specified.
@@ -56,6 +61,7 @@ interface types {
/// Descriptor flags.
///
/// Note: This was called `fdflags` in earlier versions of WASI.
+ @since(version = 0.2.0)
flags descriptor-flags {
/// Read mode: Data can be read.
read,
@@ -99,6 +105,7 @@ interface types {
/// File attributes.
///
/// Note: This was called `filestat` in earlier versions of WASI.
+ @since(version = 0.2.0)
record descriptor-stat {
/// File type.
%type: descriptor-type,
@@ -125,6 +132,7 @@ interface types {
}
/// Flags determining the method of how paths are resolved.
+ @since(version = 0.2.0)
flags path-flags {
/// As long as the resolved path corresponds to a symbolic link, it is
/// expanded.
@@ -132,6 +140,7 @@ interface types {
}
/// Open flags used by `open-at`.
+ @since(version = 0.2.0)
flags open-flags {
/// Create file if it does not exist, similar to `O_CREAT` in POSIX.
create,
@@ -144,9 +153,11 @@ interface types {
}
/// Number of hard links to an inode.
+ @since(version = 0.2.0)
type link-count = u64;
/// When setting a timestamp, this gives the value to set it to.
+ @since(version = 0.2.0)
variant new-timestamp {
/// Leave the timestamp set to its previous value.
no-change,
@@ -248,6 +259,7 @@ interface types {
}
/// File or memory access pattern advisory information.
+ @since(version = 0.2.0)
enum advice {
/// The application has no advice to give on its behavior with respect
/// to the specified data.
@@ -271,6 +283,7 @@ interface types {
/// A 128-bit hash value, split into parts because wasm doesn't have a
/// 128-bit integer type.
+ @since(version = 0.2.0)
record metadata-hash-value {
/// 64 bits of a 128-bit hash value.
lower: u64,
@@ -281,6 +294,7 @@ interface types {
/// A descriptor is a reference to a filesystem object, which may be a file,
/// directory, named pipe, special file, or other object on which filesystem
/// calls may be made.
+ @since(version = 0.2.0)
resource descriptor {
/// Return a stream for reading from a file, if available.
///
@@ -290,6 +304,7 @@ interface types {
/// file and they do not interfere with each other.
///
/// Note: This allows using `read-stream`, which is similar to `read` in POSIX.
+ @since(version = 0.2.0)
read-via-stream: func(
/// The offset within the file at which to start reading.
offset: filesize,
@@ -301,6 +316,7 @@ interface types {
///
/// Note: This allows using `write-stream`, which is similar to `write` in
/// POSIX.
+ @since(version = 0.2.0)
write-via-stream: func(
/// The offset within the file at which to start writing.
offset: filesize,
@@ -312,11 +328,13 @@ interface types {
///
/// Note: This allows using `write-stream`, which is similar to `write` with
/// `O_APPEND` in in POSIX.
+ @since(version = 0.2.0)
append-via-stream: func() -> result;
/// Provide file advisory information on a descriptor.
///
/// This is similar to `posix_fadvise` in POSIX.
+ @since(version = 0.2.0)
advise: func(
/// The offset within the file to which the advisory applies.
offset: filesize,
@@ -332,6 +350,7 @@ interface types {
/// opened for writing.
///
/// Note: This is similar to `fdatasync` in POSIX.
+ @since(version = 0.2.0)
sync-data: func() -> result<_, error-code>;
/// Get flags associated with a descriptor.
@@ -340,6 +359,7 @@ interface types {
///
/// Note: This returns the value that was the `fs_flags` value returned
/// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
get-flags: func() -> result;
/// Get the dynamic type of a descriptor.
@@ -352,12 +372,14 @@ interface types {
///
/// Note: This returns the value that was the `fs_filetype` value returned
/// from `fdstat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
get-type: func() -> result;
/// Adjust the size of an open file. If this increases the file's size, the
/// extra bytes are filled with zeros.
///
/// Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
+ @since(version = 0.2.0)
set-size: func(size: filesize) -> result<_, error-code>;
/// Adjust the timestamps of an open file or directory.
@@ -365,6 +387,7 @@ interface types {
/// Note: This is similar to `futimens` in POSIX.
///
/// Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
+ @since(version = 0.2.0)
set-times: func(
/// The desired values of the data access timestamp.
data-access-timestamp: new-timestamp,
@@ -383,6 +406,7 @@ interface types {
/// In the future, this may change to return a `stream`.
///
/// Note: This is similar to `pread` in POSIX.
+ @since(version = 0.2.0)
read: func(
/// The maximum number of bytes to read.
length: filesize,
@@ -399,6 +423,7 @@ interface types {
/// In the future, this may change to take a `stream`.
///
/// Note: This is similar to `pwrite` in POSIX.
+ @since(version = 0.2.0)
write: func(
/// Data to write
buffer: list,
@@ -415,6 +440,7 @@ interface types {
/// This always returns a new stream which starts at the beginning of the
/// directory. Multiple streams may be active on the same directory, and they
/// do not interfere with each other.
+ @since(version = 0.2.0)
read-directory: func() -> result;
/// Synchronize the data and metadata of a file to disk.
@@ -423,11 +449,13 @@ interface types {
/// opened for writing.
///
/// Note: This is similar to `fsync` in POSIX.
+ @since(version = 0.2.0)
sync: func() -> result<_, error-code>;
/// Create a directory.
///
/// Note: This is similar to `mkdirat` in POSIX.
+ @since(version = 0.2.0)
create-directory-at: func(
/// The relative path at which to create the directory.
path: string,
@@ -442,6 +470,7 @@ interface types {
/// modified, use `metadata-hash`.
///
/// Note: This was called `fd_filestat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
stat: func() -> result;
/// Return the attributes of a file or directory.
@@ -451,6 +480,7 @@ interface types {
/// discussion of alternatives.
///
/// Note: This was called `path_filestat_get` in earlier versions of WASI.
+ @since(version = 0.2.0)
stat-at: func(
/// Flags determining the method of how the path is resolved.
path-flags: path-flags,
@@ -464,6 +494,7 @@ interface types {
///
/// Note: This was called `path_filestat_set_times` in earlier versions of
/// WASI.
+ @since(version = 0.2.0)
set-times-at: func(
/// Flags determining the method of how the path is resolved.
path-flags: path-flags,
@@ -478,6 +509,7 @@ interface types {
/// Create a hard link.
///
/// Note: This is similar to `linkat` in POSIX.
+ @since(version = 0.2.0)
link-at: func(
/// Flags determining the method of how the path is resolved.
old-path-flags: path-flags,
@@ -507,6 +539,7 @@ interface types {
/// `error-code::read-only`.
///
/// Note: This is similar to `openat` in POSIX.
+ @since(version = 0.2.0)
open-at: func(
/// Flags determining the method of how the path is resolved.
path-flags: path-flags,
@@ -524,6 +557,7 @@ interface types {
/// filesystem, this function fails with `error-code::not-permitted`.
///
/// Note: This is similar to `readlinkat` in POSIX.
+ @since(version = 0.2.0)
readlink-at: func(
/// The relative path of the symbolic link from which to read.
path: string,
@@ -534,6 +568,7 @@ interface types {
/// Return `error-code::not-empty` if the directory is not empty.
///
/// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
+ @since(version = 0.2.0)
remove-directory-at: func(
/// The relative path to a directory to remove.
path: string,
@@ -542,6 +577,7 @@ interface types {
/// Rename a filesystem object.
///
/// Note: This is similar to `renameat` in POSIX.
+ @since(version = 0.2.0)
rename-at: func(
/// The relative source path of the file or directory to rename.
old-path: string,
@@ -557,6 +593,7 @@ interface types {
/// `error-code::not-permitted`.
///
/// Note: This is similar to `symlinkat` in POSIX.
+ @since(version = 0.2.0)
symlink-at: func(
/// The contents of the symbolic link.
old-path: string,
@@ -568,6 +605,7 @@ interface types {
///
/// Return `error-code::is-directory` if the path refers to a directory.
/// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
+ @since(version = 0.2.0)
unlink-file-at: func(
/// The relative path to a file to unlink.
path: string,
@@ -579,6 +617,7 @@ interface types {
/// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
/// wasi-filesystem does not expose device and inode numbers, so this function
/// may be used instead.
+ @since(version = 0.2.0)
is-same-object: func(other: borrow) -> bool;
/// Return a hash of the metadata associated with a filesystem object referred
@@ -600,12 +639,14 @@ interface types {
/// computed hash.
///
/// However, none of these is required.
+ @since(version = 0.2.0)
metadata-hash: func() -> result;
/// Return a hash of the metadata associated with a filesystem object referred
/// to by a directory descriptor and a relative path.
///
/// This performs the same hash computation as `metadata-hash`.
+ @since(version = 0.2.0)
metadata-hash-at: func(
/// Flags determining the method of how the path is resolved.
path-flags: path-flags,
@@ -615,8 +656,10 @@ interface types {
}
/// A stream of directory entries.
+ @since(version = 0.2.0)
resource directory-entry-stream {
/// Read a single directory entry from a `directory-entry-stream`.
+ @since(version = 0.2.0)
read-directory-entry: func() -> result
It is intended to be portable at least between Unix-family platforms and
Windows.
@@ -51,7 +51,7 @@ represented as a u64.
u64
-
Import interface wasi:io/error@0.2.0
+
Import interface wasi:io/error@0.2.0
Types
resource error
@@ -61,17 +61,15 @@ which provides some human-readable information about the error.
In the wasi:io package, this resource is returned through the
wasi:io/streams/stream-error type.
To provide more specific error information, other interfaces may
-provide functions to further "downcast" this error into more specific
-error information. For example, errors returned in streams derived
-from filesystem types to be described using the filesystem's own
-error-code type, using the function
-wasi:filesystem/types/filesystem-error-code, which takes a parameter
-borrow<error> and returns
-option<wasi:filesystem/types/error-code>.
+offer functions to "downcast" this error into more specific types. For example,
+errors returned from streams derived from filesystem types can be described using
+the filesystem's own error-code type. This is done using the function
+wasi:filesystem/types/filesystem-error-code, which takes a borrow<error>
+parameter and returns an option<wasi:filesystem/types/error-code>.
The set of functions which can "downcast" an error into a more
concrete type is open.
Functions
-
[method]error.to-debug-string: func
+
[method]error.to-debug-string: func
Returns a string that is suitable to assist humans in debugging
this error.
WARNING: The returned string should not be consumed mechanically!
@@ -80,13 +78,13 @@ details. Parsing this string is a major platform-compatibility
hazard.
@@ -120,14 +118,17 @@ containing only this pollable.
interest, and waits until one or more of the events is ready for I/O.
The result list<u32> contains one or more indices of handles in the
argument list that is ready for I/O.
-
If the list contains more elements than can be indexed with a u32
-value, this function traps.
+
This function traps if either:
+
+
the list is empty, or:
+
the list contains more elements than can be indexed with a u32 value.
+
A timeout can be implemented by adding a pollable from the
wasi-clocks API to the list.
This function does not return a result; polling in itself does not
do any I/O so it doesn't fail. If any of the I/O sources identified by
the pollables has an error, it is indicated by marking the source as
-being reaedy for I/O.
WASI I/O is an I/O abstraction API which is currently focused on providing
stream types.
In the future, the component model is expected to add built-in stream types;
@@ -175,14 +176,17 @@ use the subscribe function to obtain a po
for using wasi:io/poll.
resource output-stream
An output bytestream.
-
output-streams are non-blocking to the extent practical on
+
output-streams are non-blocking to the extent practical on
underlying platforms. Except where specified otherwise, I/O operations also
always return promptly, after the number of bytes that can be written
promptly, which could even be zero. To wait for the stream to be ready to
accept data, the subscribe function to obtain a pollable which can be
-polled for using wasi:io/poll.
+polled for using wasi:io/poll.
+
Dropping an output-stream while there's still an active write in
+progress may result in the data being lost. Before dropping the stream,
+be sure to fully flush your writes.
Functions
-
[method]input-stream.read: func
+
[method]input-stream.read: func
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
@@ -206,51 +210,51 @@ as a return value by the callee. The callee may return a list of bytes
less than len in size while more bytes are available for reading.
Create a pollable which will resolve once either the specified stream
has bytes available to read or the other end of the stream has been
closed.
@@ -259,13 +263,13 @@ Implementations may trap if the input-streampollables created with this function are dropped.
Check readiness for writing. This function never blocks.
Returns the number of bytes permitted for the next call to write,
or an error. Calling write with more bytes than this function has
@@ -275,13 +279,13 @@ become ready when this function will report at least 1 byte, or an
error.
When the destination of a write is binary data, the bytes from
contents are written verbatim. When the destination of a write is
@@ -294,14 +298,14 @@ length of less than or equal to n. Otherwise, this function will trap.
Request to flush buffered output. This function never blocks.
This tells the output-stream that the caller intends any buffered
output to be flushed. the output which is expected to be flushed
@@ -343,26 +347,26 @@ completed. The subscribe pollable will become ready when the
flush has completed and the stream can accept more writes.
Create a pollable which will resolve once the output-stream
-is ready for more writing, or an error has occured. When this
+is ready for more writing, or an error has occurred. When this
pollable is ready, check-write will return ok(n) with n>0, or an
error.
If the stream is closed, this pollable is always ready immediately.
@@ -371,13 +375,13 @@ Implementations may trap if the output-streampollables created with this function are dropped.
This should be used precisely like write with the exact same
preconditions (must use check-write first), but instead of
@@ -385,14 +389,14 @@ passing a list of bytes, you simply pass the number of zero-bytes
that should be written.
Read from one stream and write to another, with blocking.
This is similar to splice, except that it blocks until the
output-stream is ready for writing, and the input-stream
is ready for reading, before performing the splice.
This interface defines all of the types and methods for implementing
HTTP Requests and Responses, both incoming and outgoing, as well as
their headers, trailers, and bodies.
Get all of the values corresponding to a key. If the key is not present
in this fields or is syntactically invalid, an empty list is returned.
However, if the key is present but empty, this is represented by a list
with one or more empty field-values present.
Retrieve the full set of keys and values in the Fields. Like the
constructor, the list represents each key-value pair.
The outer list represents each key-value pair in the Fields. Keys
@@ -902,65 +904,65 @@ which have multiple values are represented by multiple entries in this
list with the same key.
Make a deep copy of the Fields. Equivalent in behavior to calling the
fields constructor on the return value of entries. The resulting
fields is mutable.
Returns the resource corresponding to the outgoing Body for this
Request.
Returns success on the first call: the outgoing-body resource for
@@ -1013,109 +1015,109 @@ this outgoing-request can be retrie
calls will return error.
Set the combination of the HTTP Path and Query for the Request.
When none, this represents an empty Path and empty Query. Fails is the
string given is not a syntactically valid path and query uri component.
Set the HTTP Related Scheme for the Request. When none, the
implementation may choose an appropriate default scheme. Fails if the
string given is not a syntactically valid uri scheme.
Get the HTTP Authority for the Request. A value of none may be used
with Related Schemes which do not require an Authority. The HTTP and
HTTPS schemes always require an authority.
Set the HTTP Authority for the Request. A value of none may be used
with Related Schemes which do not require an Authority. The HTTP and
HTTPS schemes always require an authority. Fails if the string given is
not a syntactically valid uri authority.
Set the timeout for receiving subsequent chunks of bytes in the Response
body stream. An error return value indicates that this timeout is not
supported.
Returns a pollable which becomes ready when either the trailers have
been received, or an error has occurred. When this pollable is ready,
the get method will return some.
Returns the contents of the trailers, or an error which occurred,
once the future is ready.
The outer option represents future readiness. Users can wait on this
@@ -1314,11 +1316,11 @@ resource is immutable, and a child. Use of the set, appendfuture-trailers is dropped.
Returns the resource corresponding to the outgoing Body for this Response.
Returns success on the first call: the outgoing-body resource for
this outgoing-response can be retrieved at most once. Subsequent
calls will return error.
The returned output-stream is a child resource: it must be dropped
before the parent outgoing-body resource is dropped (or finished),
@@ -1395,13 +1397,13 @@ this outgoing-body may be retrieved at
will return error.
Finalize an outgoing body, optionally providing trailers. This must be
called to signal that the response is complete. If the outgoing-body
is dropped without calling outgoing-body.finalize, the implementation
@@ -1412,26 +1414,26 @@ to the body (via write) does not match the value given in the
Content-Length.
Returns a pollable which becomes ready when either the Response has
been received, or an error has occurred. When this pollable is ready,
the get method will return some.
WASI Wall Clock is a clock API intended to let users query the current
time. The name "wall" makes an analogy to a "clock on the wall", which
is not necessarily monotonic as it may be reset.
@@ -59,14 +59,17 @@ containing only this pollable.
interest, and waits until one or more of the events is ready for I/O.
The result list<u32> contains one or more indices of handles in the
argument list that is ready for I/O.
-
If the list contains more elements than can be indexed with a u32
-value, this function traps.
+
This function traps if either:
+
+
the list is empty, or:
+
the list contains more elements than can be indexed with a u32 value.
+
A timeout can be implemented by adding a pollable from the
wasi-clocks API to the list.
This function does not return a result; polling in itself does not
do any I/O so it doesn't fail. If any of the I/O sources identified by
the pollables has an error, it is indicated by marking the source as
-being reaedy for I/O.
@@ -146,17 +147,15 @@ which provides some human-readable information about the error.
In the wasi:io package, this resource is returned through the
wasi:io/streams/stream-error type.
To provide more specific error information, other interfaces may
-provide functions to further "downcast" this error into more specific
-error information. For example, errors returned in streams derived
-from filesystem types to be described using the filesystem's own
-error-code type, using the function
-wasi:filesystem/types/filesystem-error-code, which takes a parameter
-borrow<error> and returns
-option<wasi:filesystem/types/error-code>.
+offer functions to "downcast" this error into more specific types. For example,
+errors returned from streams derived from filesystem types can be described using
+the filesystem's own error-code type. This is done using the function
+wasi:filesystem/types/filesystem-error-code, which takes a borrow<error>
+parameter and returns an option<wasi:filesystem/types/error-code>.
The set of functions which can "downcast" an error into a more
concrete type is open.
Functions
-
[method]error.to-debug-string: func
+
[method]error.to-debug-string: func
Returns a string that is suitable to assist humans in debugging
this error.
WARNING: The returned string should not be consumed mechanically!
@@ -165,13 +164,13 @@ details. Parsing this string is a major platform-compatibility
hazard.
WASI I/O is an I/O abstraction API which is currently focused on providing
stream types.
In the future, the component model is expected to add built-in stream types;
@@ -210,14 +209,17 @@ use the subscribe function to obtain a po
for using wasi:io/poll.
resource output-stream
An output bytestream.
-
output-streams are non-blocking to the extent practical on
+
output-streams are non-blocking to the extent practical on
underlying platforms. Except where specified otherwise, I/O operations also
always return promptly, after the number of bytes that can be written
promptly, which could even be zero. To wait for the stream to be ready to
accept data, the subscribe function to obtain a pollable which can be
-polled for using wasi:io/poll.
+polled for using wasi:io/poll.
+
Dropping an output-stream while there's still an active write in
+progress may result in the data being lost. Before dropping the stream,
+be sure to fully flush your writes.
Functions
-
[method]input-stream.read: func
+
[method]input-stream.read: func
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
@@ -241,51 +243,51 @@ as a return value by the callee. The callee may return a list of bytes
less than len in size while more bytes are available for reading.
Create a pollable which will resolve once either the specified stream
has bytes available to read or the other end of the stream has been
closed.
@@ -294,13 +296,13 @@ Implementations may trap if the input-streampollables created with this function are dropped.
Check readiness for writing. This function never blocks.
Returns the number of bytes permitted for the next call to write,
or an error. Calling write with more bytes than this function has
@@ -310,13 +312,13 @@ become ready when this function will report at least 1 byte, or an
error.
When the destination of a write is binary data, the bytes from
contents are written verbatim. When the destination of a write is
@@ -329,14 +331,14 @@ length of less than or equal to n. Otherwise, this function will trap.
Request to flush buffered output. This function never blocks.
This tells the output-stream that the caller intends any buffered
output to be flushed. the output which is expected to be flushed
@@ -378,26 +380,26 @@ completed. The subscribe pollable will become ready when the
flush has completed and the stream can accept more writes.
Create a pollable which will resolve once the output-stream
-is ready for more writing, or an error has occured. When this
+is ready for more writing, or an error has occurred. When this
pollable is ready, check-write will return ok(n) with n>0, or an
error.
If the stream is closed, this pollable is always ready immediately.
@@ -406,13 +408,13 @@ Implementations may trap if the output-streampollables created with this function are dropped.
This should be used precisely like write with the exact same
preconditions (must use check-write first), but instead of
@@ -420,14 +422,14 @@ passing a list of bytes, you simply pass the number of zero-bytes
that should be written.
Read from one stream and write to another, with blocking.
This is similar to splice, except that it blocks until the
output-stream is ready for writing, and the input-stream
is ready for reading, before performing the splice.
This interface defines all of the types and methods for implementing
HTTP Requests and Responses, both incoming and outgoing, as well as
their headers, trailers, and bodies.
Get all of the values corresponding to a key. If the key is not present
in this fields or is syntactically invalid, an empty list is returned.
However, if the key is present but empty, this is represented by a list
with one or more empty field-values present.
Retrieve the full set of keys and values in the Fields. Like the
constructor, the list represents each key-value pair.
The outer list represents each key-value pair in the Fields. Keys
@@ -837,65 +839,65 @@ which have multiple values are represented by multiple entries in this
list with the same key.
Make a deep copy of the Fields. Equivalent in behavior to calling the
fields constructor on the return value of entries. The resulting
fields is mutable.
Set the combination of the HTTP Path and Query for the Request.
When none, this represents an empty Path and empty Query. Fails is the
string given is not a syntactically valid path and query uri component.
Set the HTTP Related Scheme for the Request. When none, the
implementation may choose an appropriate default scheme. Fails if the
string given is not a syntactically valid uri scheme.
Get the HTTP Authority for the Request. A value of none may be used
with Related Schemes which do not require an Authority. The HTTP and
HTTPS schemes always require an authority.
Set the HTTP Authority for the Request. A value of none may be used
with Related Schemes which do not require an Authority. The HTTP and
HTTPS schemes always require an authority. Fails if the string given is
not a syntactically valid uri authority.
Set the timeout for receiving subsequent chunks of bytes in the Response
body stream. An error return value indicates that this timeout is not
supported.
Returns a pollable which becomes ready when either the trailers have
been received, or an error has occurred. When this pollable is ready,
the get method will return some.
Returns the contents of the trailers, or an error which occurred,
once the future is ready.
The outer option represents future readiness. Users can wait on this
@@ -1249,11 +1251,11 @@ resource is immutable, and a child. Use of the set, appendfuture-trailers is dropped.
Returns the resource corresponding to the outgoing Body for this Response.
Returns success on the first call: the outgoing-body resource for
this outgoing-response can be retrieved at most once. Subsequent
calls will return error.
The returned output-stream is a child resource: it must be dropped
before the parent outgoing-body resource is dropped (or finished),
@@ -1330,13 +1332,13 @@ this outgoing-body may be retrieved at
will return error.
Finalize an outgoing body, optionally providing trailers. This must be
called to signal that the response is complete. If the outgoing-body
is dropped without calling outgoing-body.finalize, the implementation
@@ -1347,26 +1349,26 @@ to the body (via write) does not match the value given in the
Content-Length.
Returns a pollable which becomes ready when either the Response has
been received, or an error has occurred. When this pollable is ready,
the get method will return some.
WASI Wall Clock is a clock API intended to let users query the current
time. The name "wall" makes an analogy to a "clock on the wall", which
is not necessarily monotonic as it may be reset.