diff --git a/README.md b/README.md index effb891..bf1ff52 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ And in your world definition: ``` -include wasmcloud:component/imports; +include wasmcloud:component-go/imports@0.1.0; ``` diff --git a/_examples/http-client/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/_examples/http-client/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go index 16d47cf..3a2ec57 100644 --- a/_examples/http-client/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go +++ b/_examples/http-client/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -1,17 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". -// -// WASI Monotonic Clock is a clock API intended to let users measure elapsed -// time. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// 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. package monotonicclock import ( @@ -21,27 +10,16 @@ import ( // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". // -// 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. -// // type instant = u64 type Instant uint64 // Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". // -// A duration of time, in nanoseconds. -// // type duration = u64 type Duration uint64 // Now represents the imported function "now". // -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. -// // now: func() -> instant // //go:nosplit @@ -57,9 +35,6 @@ func wasmimport_Now() (result0 uint64) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. -// // resolution: func() -> duration // //go:nosplit @@ -75,9 +50,6 @@ func wasmimport_Resolution() (result0 uint64) // SubscribeInstant represents the imported function "subscribe-instant". // -// Create a `pollable` which will resolve once the specified instant -// occured. -// // subscribe-instant: func(when: instant) -> pollable // //go:nosplit @@ -94,10 +66,6 @@ func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. -// // subscribe-duration: func(when: duration) -> pollable // //go:nosplit diff --git a/_examples/http-client/gen/wasi/clocks/wall-clock/wall-clock.wit.go b/_examples/http-client/gen/wasi/clocks/wall-clock/wall-clock.wit.go index 871a2e1..9f425d8 100644 --- a/_examples/http-client/gen/wasi/clocks/wall-clock/wall-clock.wit.go +++ b/_examples/http-client/gen/wasi/clocks/wall-clock/wall-clock.wit.go @@ -1,21 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". -// -// 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. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// A wall clock is a clock which measures the date and time according to -// some external reference. -// -// External references may be reset, so this clock is not necessarily -// monotonic, making it unsuitable for measuring elapsed time. -// -// It is intended for reporting the current date and time for humans. package wallclock import ( @@ -24,8 +9,6 @@ import ( // DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". // -// A time and date in seconds plus nanoseconds. -// // record datetime { // seconds: u64, // nanoseconds: u32, @@ -38,22 +21,8 @@ type DateTime struct { // Now represents the imported function "now". // -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// // now: func() -> datetime // -// [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 -// //go:nosplit func Now() (result DateTime) { wasmimport_Now(&result) @@ -66,10 +35,6 @@ func wasmimport_Now(result *DateTime) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -// // resolution: func() -> datetime // //go:nosplit diff --git a/_examples/http-client/gen/wasi/filesystem/preopens/preopens.wit.go b/_examples/http-client/gen/wasi/filesystem/preopens/preopens.wit.go index 2192a64..1bb547e 100644 --- a/_examples/http-client/gen/wasi/filesystem/preopens/preopens.wit.go +++ b/_examples/http-client/gen/wasi/filesystem/preopens/preopens.wit.go @@ -10,8 +10,6 @@ import ( // GetDirectories represents the imported function "get-directories". // -// Return the set of preopened directories, and their path. -// // get-directories: func() -> list> // //go:nosplit diff --git a/_examples/http-client/gen/wasi/filesystem/types/types.wit.go b/_examples/http-client/gen/wasi/filesystem/types/types.wit.go index de3b9b8..89fa06c 100644 --- a/_examples/http-client/gen/wasi/filesystem/types/types.wit.go +++ b/_examples/http-client/gen/wasi/filesystem/types/types.wit.go @@ -1,31 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package types represents the imported interface "wasi:filesystem/types@0.2.0". -// -// WASI filesystem is a filesystem API primarily intended to let users run WASI -// programs that access their files on their existing filesystems, without -// significant overhead. -// -// It is intended to be roughly portable between Unix-family platforms and -// Windows, though it does not hide many of the major differences. -// -// Paths are passed as interface-type `string`s, meaning they must consist of -// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -// paths which are not accessible by this API. -// -// The directory separator in WASI is always the forward-slash (`/`). -// -// All paths in WASI are relative paths, and are interpreted relative to a -// `descriptor` referring to a base directory. If a `path` argument to any WASI -// function starts with `/`, or if any step of resolving a `path`, including -// `..` and symbolic link steps, reaches a directory outside of the base -// directory, or reaches a symlink to an absolute or rooted path in the -// underlying filesystem, the function fails with `error-code::not-permitted`. -// -// For more information about WASI path resolution and sandboxing, see -// [WASI filesystem path resolution]. -// -// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md package types import ( @@ -37,17 +12,11 @@ import ( // FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". // -// File size or length of a region within a file. -// // type filesize = u64 type FileSize uint64 // DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". // -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. -// // enum descriptor-type { // unknown, // block-device, @@ -61,29 +30,13 @@ type FileSize uint64 type DescriptorType uint8 const ( - // The type of the descriptor or file is unknown or is different from - // any of the other types specified. DescriptorTypeUnknown DescriptorType = iota - - // The descriptor refers to a block device inode. DescriptorTypeBlockDevice - - // The descriptor refers to a character device inode. DescriptorTypeCharacterDevice - - // The descriptor refers to a directory inode. DescriptorTypeDirectory - - // The descriptor refers to a named pipe. DescriptorTypeFIFO - - // The file refers to a symbolic link inode. DescriptorTypeSymbolicLink - - // The descriptor refers to a regular file inode. DescriptorTypeRegularFile - - // The descriptor refers to a socket. DescriptorTypeSocket ) @@ -105,10 +58,6 @@ func (e DescriptorType) String() string { // DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". // -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. -// // flags descriptor-flags { // read, // write, @@ -120,69 +69,27 @@ func (e DescriptorType) String() string { type DescriptorFlags uint8 const ( - // Read mode: Data can be read. DescriptorFlagsRead DescriptorFlags = 1 << iota - - // Write mode: Data can be written to. DescriptorFlagsWrite - - // Request that writes be performed according to synchronized I/O file - // integrity completion. The data stored in the file and the file's - // metadata are synchronized. This is similar to `O_SYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsFileIntegritySync - - // Request that writes be performed according to synchronized I/O data - // integrity completion. Only the data stored in the file is - // synchronized. This is similar to `O_DSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsDataIntegritySync - - // Requests that reads be performed at the same level of integrety - // requested for writes. This is similar to `O_RSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsRequestedWriteSync - - // Mutating directories mode: Directory contents may be mutated. - // - // When this flag is unset on a descriptor, operations using the - // descriptor which would create, rename, delete, modify the data or - // metadata of filesystem objects, or obtain another handle which - // would permit any of those, shall fail with `error-code::read-only` if - // they would otherwise succeed. - // - // This may only be set on directories. DescriptorFlagsMutateDirectory ) // PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". // -// Flags determining the method of how paths are resolved. -// // flags path-flags { // symlink-follow, // } type PathFlags uint8 const ( - // As long as the resolved path corresponds to a symbolic link, it is - // expanded. PathFlagsSymlinkFollow PathFlags = 1 << iota ) // OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". // -// Open flags used by `open-at`. -// // flags open-flags { // create, // directory, @@ -192,32 +99,19 @@ const ( type OpenFlags uint8 const ( - // Create file if it does not exist, similar to `O_CREAT` in POSIX. OpenFlagsCreate OpenFlags = 1 << iota - - // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. OpenFlagsDirectory - - // Fail if file already exists, similar to `O_EXCL` in POSIX. OpenFlagsExclusive - - // Truncate file to size 0, similar to `O_TRUNC` in POSIX. OpenFlagsTruncate ) // LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". // -// Number of hard links to an inode. -// // type link-count = u64 type LinkCount uint64 // DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". // -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. -// // record descriptor-stat { // %type: descriptor-type, // link-count: link-count, @@ -227,40 +121,17 @@ type LinkCount uint64 // status-change-timestamp: option, // } type DescriptorStat struct { - _ cm.HostLayout - // File type. - Type DescriptorType - - // Number of hard links to the file. - LinkCount LinkCount - - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. - Size FileSize - - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - DataAccessTimestamp cm.Option[wallclock.DateTime] - - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. + _ cm.HostLayout + Type DescriptorType + LinkCount LinkCount + Size FileSize + DataAccessTimestamp cm.Option[wallclock.DateTime] DataModificationTimestamp cm.Option[wallclock.DateTime] - - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. - StatusChangeTimestamp cm.Option[wallclock.DateTime] + StatusChangeTimestamp cm.Option[wallclock.DateTime] } // NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". // -// When setting a timestamp, this gives the value to set it to. -// // variant new-timestamp { // no-change, // now, @@ -269,8 +140,6 @@ type DescriptorStat struct { type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] // NewTimestampNoChange returns a [NewTimestamp] of case "no-change". -// -// Leave the timestamp set to its previous value. func NewTimestampNoChange() NewTimestamp { var data struct{} return cm.New[NewTimestamp](0, data) @@ -282,9 +151,6 @@ func (self *NewTimestamp) NoChange() bool { } // NewTimestampNow returns a [NewTimestamp] of case "now". -// -// Set the timestamp to the current time of the system clock associated -// with the filesystem. func NewTimestampNow() NewTimestamp { var data struct{} return cm.New[NewTimestamp](1, data) @@ -296,8 +162,6 @@ func (self *NewTimestamp) Now() bool { } // NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". -// -// Set the timestamp to the given value. func NewTimestampTimestamp(data wallclock.DateTime) NewTimestamp { return cm.New[NewTimestamp](2, data) } @@ -309,28 +173,18 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { // DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". // -// A directory entry. -// // record directory-entry { // %type: descriptor-type, // name: string, // } type DirectoryEntry struct { - _ cm.HostLayout - // The type of the file referred to by this directory entry. + _ cm.HostLayout Type DescriptorType - - // The name of the object. Name string } // ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". // -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. -// // enum error-code { // access, // would-block, @@ -373,116 +227,42 @@ type DirectoryEntry struct { type ErrorCode uint8 const ( - // Permission denied, similar to `EACCES` in POSIX. ErrorCodeAccess ErrorCode = iota - - // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` - // in POSIX. ErrorCodeWouldBlock - - // Connection already in progress, similar to `EALREADY` in POSIX. ErrorCodeAlready - - // Bad descriptor, similar to `EBADF` in POSIX. ErrorCodeBadDescriptor - - // Device or resource busy, similar to `EBUSY` in POSIX. ErrorCodeBusy - - // Resource deadlock would occur, similar to `EDEADLK` in POSIX. ErrorCodeDeadlock - - // Storage quota exceeded, similar to `EDQUOT` in POSIX. ErrorCodeQuota - - // File exists, similar to `EEXIST` in POSIX. ErrorCodeExist - - // File too large, similar to `EFBIG` in POSIX. ErrorCodeFileTooLarge - - // Illegal byte sequence, similar to `EILSEQ` in POSIX. ErrorCodeIllegalByteSequence - - // Operation in progress, similar to `EINPROGRESS` in POSIX. ErrorCodeInProgress - - // Interrupted function, similar to `EINTR` in POSIX. ErrorCodeInterrupted - - // Invalid argument, similar to `EINVAL` in POSIX. ErrorCodeInvalid - - // I/O error, similar to `EIO` in POSIX. ErrorCodeIO - - // Is a directory, similar to `EISDIR` in POSIX. ErrorCodeIsDirectory - - // Too many levels of symbolic links, similar to `ELOOP` in POSIX. ErrorCodeLoop - - // Too many links, similar to `EMLINK` in POSIX. ErrorCodeTooManyLinks - - // Message too large, similar to `EMSGSIZE` in POSIX. ErrorCodeMessageSize - - // Filename too long, similar to `ENAMETOOLONG` in POSIX. ErrorCodeNameTooLong - - // No such device, similar to `ENODEV` in POSIX. ErrorCodeNoDevice - - // No such file or directory, similar to `ENOENT` in POSIX. ErrorCodeNoEntry - - // No locks available, similar to `ENOLCK` in POSIX. ErrorCodeNoLock - - // Not enough space, similar to `ENOMEM` in POSIX. ErrorCodeInsufficientMemory - - // No space left on device, similar to `ENOSPC` in POSIX. ErrorCodeInsufficientSpace - - // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. ErrorCodeNotDirectory - - // Directory not empty, similar to `ENOTEMPTY` in POSIX. ErrorCodeNotEmpty - - // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. ErrorCodeNotRecoverable - - // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. ErrorCodeUnsupported - - // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. ErrorCodeNoTTY - - // No such device or address, similar to `ENXIO` in POSIX. ErrorCodeNoSuchDevice - - // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. ErrorCodeOverflow - - // Operation not permitted, similar to `EPERM` in POSIX. ErrorCodeNotPermitted - - // Broken pipe, similar to `EPIPE` in POSIX. ErrorCodePipe - - // Read-only file system, similar to `EROFS` in POSIX. ErrorCodeReadOnly - - // Invalid seek, similar to `ESPIPE` in POSIX. ErrorCodeInvalidSeek - - // Text file busy, similar to `ETXTBSY` in POSIX. ErrorCodeTextFileBusy - - // Cross-device link, similar to `EXDEV` in POSIX. ErrorCodeCrossDevice ) @@ -533,8 +313,6 @@ func (e ErrorCode) String() string { // Advice represents the enum "wasi:filesystem/types@0.2.0#advice". // -// File or memory access pattern advisory information. -// // enum advice { // normal, // sequential, @@ -546,28 +324,11 @@ func (e ErrorCode) String() string { type Advice uint8 const ( - // The application has no advice to give on its behavior with respect - // to the specified data. AdviceNormal Advice = iota - - // The application expects to access the specified data sequentially - // from lower offsets to higher offsets. AdviceSequential - - // The application expects to access the specified data in a random - // order. AdviceRandom - - // The application expects to access the specified data in the near - // future. AdviceWillNeed - - // The application expects that it will not access the specified data - // in the near future. AdviceDontNeed - - // The application expects to access the specified data once and then - // not reuse it thereafter. AdviceNoReuse ) @@ -587,28 +348,18 @@ func (e Advice) String() string { // MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". // -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -// // record metadata-hash-value { // lower: u64, // upper: u64, // } type MetadataHashValue struct { - _ cm.HostLayout - // 64 bits of a 128-bit hash value. + _ cm.HostLayout Lower uint64 - - // Another 64 bits of a 128-bit hash value. Upper uint64 } // Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". // -// 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. -// // resource descriptor type Descriptor cm.Resource @@ -629,10 +380,6 @@ func wasmimport_DescriptorResourceDrop(self0 uint32) // Advise represents the imported method "advise". // -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. -// // advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> // //go:nosplit @@ -651,13 +398,6 @@ func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, a // AppendViaStream represents the imported method "append-via-stream". // -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. -// // append-via-stream: func() -> result // //go:nosplit @@ -673,10 +413,6 @@ func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[stream // CreateDirectoryAt represents the imported method "create-directory-at". // -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. -// // create-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -693,13 +429,6 @@ func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 ui // GetFlags represents the imported method "get-flags". // -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-flags: func() -> result // //go:nosplit @@ -715,17 +444,6 @@ func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFla // GetType represents the imported method "get-type". // -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-type: func() -> result // //go:nosplit @@ -741,13 +459,6 @@ func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType // IsSameObject represents the imported method "is-same-object". // -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// 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. -// // is-same-object: func(other: borrow) -> bool // //go:nosplit @@ -765,10 +476,6 @@ func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uin // LinkAt represents the imported method "link-at". // -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. -// // link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, // new-path: string) -> result<_, error-code> // @@ -789,26 +496,6 @@ func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *u // MetadataHash represents the imported method "metadata-hash". // -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. -// // metadata-hash: func() -> result // //go:nosplit @@ -824,11 +511,6 @@ func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataH // MetadataHashAt represents the imported method "metadata-hash-at". // -// 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`. -// // metadata-hash-at: func(path-flags: path-flags, path: string) -> result // @@ -847,25 +529,6 @@ func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 // OpenAt represents the imported method "open-at". // -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// descriptor not currently open/ it is randomized to prevent applications -// from depending on making assumptions about indexes, since this is -// error-prone in multi-threaded contexts. The returned descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. -// // open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: // descriptor-flags) -> result // @@ -886,18 +549,6 @@ func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // Read represents the imported method "read". // -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. -// // read: func(length: filesize, offset: filesize) -> result, bool>, // error-code> // @@ -916,16 +567,6 @@ func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, res // ReadDirectory represents the imported method "read-directory". // -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// 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. -// // read-directory: func() -> result // //go:nosplit @@ -941,15 +582,6 @@ func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[Director // ReadViaStream represents the imported method "read-via-stream". // -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. -// // read-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -966,13 +598,6 @@ func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm // ReadLinkAt represents the imported method "readlink-at". // -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. -// // readlink-at: func(path: string) -> result // //go:nosplit @@ -989,12 +614,6 @@ func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, r // RemoveDirectoryAt represents the imported method "remove-directory-at". // -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. -// // remove-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1011,10 +630,6 @@ func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 ui // RenameAt represents the imported method "rename-at". // -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. -// // rename-at: func(old-path: string, new-descriptor: borrow, new-path: // string) -> result<_, error-code> // @@ -1034,11 +649,6 @@ func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint3 // SetSize represents the imported method "set-size". // -// 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. -// // set-size: func(size: filesize) -> result<_, error-code> // //go:nosplit @@ -1055,12 +665,6 @@ func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ // SetTimes represents the imported method "set-times". // -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -// // set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: // new-timestamp) -> result<_, error-code> // @@ -1079,13 +683,6 @@ func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, da // SetTimesAt represents the imported method "set-times-at". // -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. -// // set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: // new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> // @@ -1106,16 +703,6 @@ func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uin // Stat represents the imported method "stat". // -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. -// // stat: func() -> result // //go:nosplit @@ -1131,14 +718,6 @@ func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatSha // StatAt represents the imported method "stat-at". // -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. -// // stat-at: func(path-flags: path-flags, path: string) -> result // @@ -1157,13 +736,6 @@ func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // SymlinkAt represents the imported method "symlink-at". // -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. -// // symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> // //go:nosplit @@ -1181,13 +753,6 @@ func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint // Sync represents the imported method "sync". // -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. -// // sync: func() -> result<_, error-code> // //go:nosplit @@ -1203,13 +768,6 @@ func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct // SyncData represents the imported method "sync-data". // -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. -// // sync-data: func() -> result<_, error-code> // //go:nosplit @@ -1225,11 +783,6 @@ func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, st // UnlinkFileAt represents the imported method "unlink-file-at". // -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. -// // unlink-file-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1246,16 +799,6 @@ func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, // Write represents the imported method "write". // -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. -// // write: func(buffer: list, offset: filesize) -> result // //go:nosplit @@ -1273,13 +816,6 @@ func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, of // WriteViaStream represents the imported method "write-via-stream". // -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. -// // write-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -1296,8 +832,6 @@ func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *c // DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". // -// A stream of directory entries. -// // resource directory-entry-stream type DirectoryEntryStream cm.Resource @@ -1318,8 +852,6 @@ func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) // ReadDirectoryEntry represents the imported method "read-directory-entry". // -// Read a single directory entry from a `directory-entry-stream`. -// // read-directory-entry: func() -> result, error-code> // //go:nosplit @@ -1335,17 +867,6 @@ func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm. // FilesystemErrorCode represents the imported function "filesystem-error-code". // -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. -// // filesystem-error-code: func(err: borrow) -> option // //go:nosplit diff --git a/_examples/http-client/gen/wasi/io/error/error.wit.go b/_examples/http-client/gen/wasi/io/error/error.wit.go index 61d61db..6a2cf9b 100644 --- a/_examples/http-client/gen/wasi/io/error/error.wit.go +++ b/_examples/http-client/gen/wasi/io/error/error.wit.go @@ -9,26 +9,6 @@ import ( // Error represents the imported resource "wasi:io/error@0.2.0#error". // -// A resource which represents some error information. -// -// The only method provided by this resource is `to-debug-string`, -// 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, `error`s 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` and returns -// `option`. -// -// The set of functions which can "downcast" an `error` into a more -// concrete type is open. -// // resource error type Error cm.Resource @@ -49,14 +29,6 @@ func wasmimport_ErrorResourceDrop(self0 uint32) // ToDebugString represents the imported method "to-debug-string". // -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. -// // to-debug-string: func() -> string // //go:nosplit diff --git a/_examples/http-client/gen/wasi/io/poll/poll.wit.go b/_examples/http-client/gen/wasi/io/poll/poll.wit.go index d11852f..d111f72 100644 --- a/_examples/http-client/gen/wasi/io/poll/poll.wit.go +++ b/_examples/http-client/gen/wasi/io/poll/poll.wit.go @@ -1,9 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package poll represents the imported interface "wasi:io/poll@0.2.0". -// -// A poll API intended to let users wait for I/O events on multiple handles -// at once. package poll import ( @@ -12,8 +9,6 @@ import ( // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". // -// `pollable` represents a single I/O event which may be ready, or not. -// // resource pollable type Pollable cm.Resource @@ -34,12 +29,6 @@ func wasmimport_PollableResourceDrop(self0 uint32) // Block represents the imported method "block". // -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. -// // block: func() // //go:nosplit @@ -55,10 +44,6 @@ func wasmimport_PollableBlock(self0 uint32) // Ready represents the imported method "ready". // -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. -// // ready: func() -> bool // //go:nosplit @@ -75,25 +60,6 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // Poll represents the imported function "poll". // -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` 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. -// -// 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. -// // poll: func(in: list>) -> list // //go:nosplit diff --git a/_examples/http-client/gen/wasi/io/streams/streams.wit.go b/_examples/http-client/gen/wasi/io/streams/streams.wit.go index 2e20407..d507ff2 100644 --- a/_examples/http-client/gen/wasi/io/streams/streams.wit.go +++ b/_examples/http-client/gen/wasi/io/streams/streams.wit.go @@ -1,12 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package streams represents the imported interface "wasi:io/streams@0.2.0". -// -// 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; -// when it does, they are expected to subsume this API. package streams import ( @@ -17,8 +11,6 @@ import ( // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". // -// An error for input-stream and output-stream operations. -// // variant stream-error { // last-operation-failed(error), // closed, @@ -26,10 +18,6 @@ import ( type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] // StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". -// -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { return cm.New[StreamError](0, data) } @@ -40,10 +28,6 @@ func (self *StreamError) LastOperationFailed() *ioerror.Error { } // StreamErrorClosed returns a [StreamError] of case "closed". -// -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. func StreamErrorClosed() StreamError { var data struct{} return cm.New[StreamError](1, data) @@ -56,15 +40,6 @@ func (self *StreamError) Closed() bool { // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". // -// An input bytestream. -// -// `input-stream`s are *non-blocking* to the extent practical on underlying -// platforms. I/O operations always return promptly; if fewer bytes are -// promptly available than requested, they return the number of bytes promptly -// available, which could even be zero. To wait for data to be available, -// use the `subscribe` function to obtain a `pollable` which can be polled -// for using `wasi:io/poll`. -// // resource input-stream type InputStream cm.Resource @@ -85,9 +60,6 @@ func wasmimport_InputStreamResourceDrop(self0 uint32) // BlockingRead represents the imported method "blocking-read". // -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. -// // blocking-read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -104,9 +76,6 @@ func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Re // BlockingSkip represents the imported method "blocking-skip". // -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. -// // blocking-skip: func(len: u64) -> result // //go:nosplit @@ -123,33 +92,6 @@ func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Re // Read represents the imported method "read". // -// 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 -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// 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. -// // read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -166,11 +108,6 @@ func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm. // Skip represents the imported method "skip". // -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. -// // skip: func(len: u64) -> result // //go:nosplit @@ -187,13 +124,6 @@ func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uin // Subscribe represents the imported method "subscribe". // -// 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. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -210,15 +140,6 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) // OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". // -// An output bytestream. -// -// `output-stream`s 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`. -// // resource output-stream type OutputStream cm.Resource @@ -239,9 +160,6 @@ func wasmimport_OutputStreamResourceDrop(self0 uint32) // BlockingFlush represents the imported method "blocking-flush". // -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. -// // blocking-flush: func() -> result<_, stream-error> // //go:nosplit @@ -257,12 +175,6 @@ func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[Stream // BlockingSplice represents the imported method "blocking-splice". // -// 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`. -// // blocking-splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -280,29 +192,6 @@ func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint6 // BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". // -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-and-flush: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -319,29 +208,6 @@ func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8 // BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". // -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// 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` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> // //go:nosplit @@ -358,16 +224,6 @@ func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint6 // CheckWrite represents the imported method "check-write". // -// 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 -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. -// // check-write: func() -> result // //go:nosplit @@ -383,17 +239,6 @@ func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, u // Flush represents the imported method "flush". // -// 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 -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. -// // flush: func() -> result<_, stream-error> // //go:nosplit @@ -409,20 +254,6 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, s // Splice represents the imported method "splice". // -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. -// // splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -440,17 +271,6 @@ func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, resul // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. 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. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -467,20 +287,6 @@ func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) // Write represents the imported method "write". // -// 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. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. -// // write: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -497,13 +303,6 @@ func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint // WriteZeroes represents the imported method "write-zeroes". // -// Write zeroes to a stream. -// -// 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. -// // write-zeroes: func(len: u64) -> result<_, stream-error> // //go:nosplit diff --git a/_examples/http-client/gen/wasi/random/insecure-seed/insecure-seed.wit.go b/_examples/http-client/gen/wasi/random/insecure-seed/insecure-seed.wit.go index 3b8f33c..27f899f 100644 --- a/_examples/http-client/gen/wasi/random/insecure-seed/insecure-seed.wit.go +++ b/_examples/http-client/gen/wasi/random/insecure-seed/insecure-seed.wit.go @@ -1,33 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". -// -// The insecure-seed interface for seeding hash-map DoS resistance. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecureseed // InsecureSeed represents the imported function "insecure-seed". // -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. -// // insecure-seed: func() -> tuple // //go:nosplit diff --git a/_examples/http-client/gen/wasi/random/insecure/insecure.wit.go b/_examples/http-client/gen/wasi/random/insecure/insecure.wit.go index bfe1e6c..8ff72e3 100644 --- a/_examples/http-client/gen/wasi/random/insecure/insecure.wit.go +++ b/_examples/http-client/gen/wasi/random/insecure/insecure.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecure represents the imported interface "wasi:random/insecure@0.2.0". -// -// The insecure interface for insecure pseudo-random numbers. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecure import ( @@ -14,15 +9,6 @@ import ( // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". // -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. -// // get-insecure-random-bytes: func(len: u64) -> list // //go:nosplit @@ -38,11 +24,6 @@ func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) // GetInsecureRandomU64 represents the imported function "get-insecure-random-u64". // -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. -// // get-insecure-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/http-client/gen/wasi/random/random/random.wit.go b/_examples/http-client/gen/wasi/random/random/random.wit.go index da2eb57..b7d24e4 100644 --- a/_examples/http-client/gen/wasi/random/random/random.wit.go +++ b/_examples/http-client/gen/wasi/random/random/random.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package random represents the imported interface "wasi:random/random@0.2.0". -// -// WASI Random is a random data API. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package random import ( @@ -14,19 +9,6 @@ import ( // GetRandomBytes represents the imported function "get-random-bytes". // -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. -// // get-random-bytes: func(len: u64) -> list // //go:nosplit @@ -42,11 +24,6 @@ func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) // GetRandomU64 represents the imported function "get-random-u64". // -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. -// // get-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/http-client/gen/wasi/sockets/instance-network/instance-network.wit.go b/_examples/http-client/gen/wasi/sockets/instance-network/instance-network.wit.go index 91bc794..721199a 100644 --- a/_examples/http-client/gen/wasi/sockets/instance-network/instance-network.wit.go +++ b/_examples/http-client/gen/wasi/sockets/instance-network/instance-network.wit.go @@ -1,8 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". -// -// This interface provides a value-export of the default network handle.. package instancenetwork import ( @@ -12,8 +10,6 @@ import ( // InstanceNetwork represents the imported function "instance-network". // -// Get a handle to the default network. -// // instance-network: func() -> network // //go:nosplit diff --git a/_examples/http-client/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/_examples/http-client/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go index af6dbc1..7e803c0 100644 --- a/_examples/http-client/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go +++ b/_examples/http-client/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -31,23 +31,6 @@ func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) // ResolveNextAddress represents the imported method "resolve-next-address". // -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated -// IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. -// (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. -// (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) -// // resolve-next-address: func() -> result, error-code> // //go:nosplit @@ -63,11 +46,6 @@ func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm. // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -84,27 +62,6 @@ func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) // ResolveAddresses represents the imported function "resolve-addresses". // -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -// // resolve-addresses: func(network: borrow, name: string) -> result // diff --git a/_examples/http-client/gen/wasi/sockets/network/network.wit.go b/_examples/http-client/gen/wasi/sockets/network/network.wit.go index bdc8634..3e1a3ac 100644 --- a/_examples/http-client/gen/wasi/sockets/network/network.wit.go +++ b/_examples/http-client/gen/wasi/sockets/network/network.wit.go @@ -9,10 +9,6 @@ import ( // Network represents the imported resource "wasi:sockets/network@0.2.0#network". // -// An opaque resource that represents access to (a subset of) the network. -// This enables context-based security for networking. -// There is no need for this to map 1:1 to a physical network interface. -// // resource network type Network cm.Resource @@ -33,20 +29,6 @@ func wasmimport_NetworkResourceDrop(self0 uint32) // ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". // -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ -// per API. -// // enum error-code { // unknown, // access-denied, @@ -73,87 +55,26 @@ func wasmimport_NetworkResourceDrop(self0 uint32) type ErrorCode uint8 const ( - // Unknown error ErrorCodeUnknown ErrorCode = iota - - // Access denied. - // - // POSIX equivalent: EACCES, EPERM ErrorCodeAccessDenied - - // The operation is not supported. - // - // POSIX equivalent: EOPNOTSUPP ErrorCodeNotSupported - - // One of the arguments is invalid. - // - // POSIX equivalent: EINVAL ErrorCodeInvalidArgument - - // Not enough memory to complete the operation. - // - // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY ErrorCodeOutOfMemory - - // The operation timed out before it could finish completely. ErrorCodeTimeout - - // This operation is incompatible with another asynchronous operation that is already - // in progress. - // - // POSIX equivalent: EALREADY ErrorCodeConcurrencyConflict - - // Trying to finish an asynchronous operation that: - // - has not been started yet, or: - // - was already finished by a previous `finish-*` call. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeNotInProgress - - // The operation has been aborted because it could not be completed immediately. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeWouldBlock - - // The operation is not valid in the socket's current state. ErrorCodeInvalidState - - // A new socket resource could not be created because of a system limit. ErrorCodeNewSocketLimit - - // A bind operation failed because the provided address is not an address that the - // `network` can bind to. ErrorCodeAddressNotBindable - - // A bind operation failed because the provided address is already in use or because - // there are no ephemeral ports available. ErrorCodeAddressInUse - - // The remote address is not reachable ErrorCodeRemoteUnreachable - - // The TCP connection was forcefully rejected ErrorCodeConnectionRefused - - // The TCP connection was reset. ErrorCodeConnectionReset - - // A TCP connection was aborted. ErrorCodeConnectionAborted - - // The size of a datagram sent to a UDP socket exceeded the maximum - // supported size. ErrorCodeDatagramTooLarge - - // Name does not exist or has no suitable associated IP addresses. ErrorCodeNameUnresolvable - - // A temporary failure in name resolution occurred. ErrorCodeTemporaryResolverFailure - - // A permanent failure in name resolution occurred. ErrorCodePermanentResolverFailure ) @@ -195,10 +116,7 @@ func (e ErrorCode) String() string { type IPAddressFamily uint8 const ( - // Similar to `AF_INET` in POSIX. IPAddressFamilyIPv4 IPAddressFamily = iota - - // Similar to `AF_INET6` in POSIX. IPAddressFamilyIPv6 ) @@ -257,11 +175,8 @@ func (self *IPAddress) IPv6() *IPv6Address { // address: ipv4-address, // } type IPv4SocketAddress struct { - _ cm.HostLayout - // sin_port - Port uint16 - - // sin_addr + _ cm.HostLayout + Port uint16 Address IPv4Address } @@ -274,18 +189,11 @@ type IPv4SocketAddress struct { // scope-id: u32, // } type IPv6SocketAddress struct { - _ cm.HostLayout - // sin6_port - Port uint16 - - // sin6_flowinfo + _ cm.HostLayout + Port uint16 FlowInfo uint32 - - // sin6_addr - Address IPv6Address - - // sin6_scope_id - ScopeID uint32 + Address IPv6Address + ScopeID uint32 } // IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". diff --git a/_examples/http-client/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/_examples/http-client/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go index c1f18c8..75de3d6 100644 --- a/_examples/http-client/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go +++ b/_examples/http-client/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateTCPSocket represents the imported function "create-tcp-socket". // -// 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`/`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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // create-tcp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/http-client/gen/wasi/sockets/tcp/tcp.wit.go b/_examples/http-client/gen/wasi/sockets/tcp/tcp.wit.go index a70a28c..934d697 100644 --- a/_examples/http-client/gen/wasi/sockets/tcp/tcp.wit.go +++ b/_examples/http-client/gen/wasi/sockets/tcp/tcp.wit.go @@ -21,13 +21,8 @@ import ( type ShutdownType uint8 const ( - // Similar to `SHUT_RD` in POSIX. ShutdownTypeReceive ShutdownType = iota - - // Similar to `SHUT_WR` in POSIX. ShutdownTypeSend - - // Similar to `SHUT_RDWR` in POSIX. ShutdownTypeBoth ) @@ -44,29 +39,6 @@ func (e ShutdownType) String() string { // TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". // -// A TCP socket resource. -// -// The socket can be in one of the following states: -// - `unbound` -// - `bind-in-progress` -// - `bound` (See note below) -// - `listen-in-progress` -// - `listening` -// - `connect-in-progress` -// - `connected` -// - `closed` -// See -// for a more information. -// -// Note: Except where explicitly mentioned, whenever this documentation uses -// the term "bound" without backticks it actually means: in the `bound` state *or -// higher*. -// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) -// -// In addition to the general error codes documented on the -// `network::error-code` type, TCP socket methods may always return -// `error(invalid-state)` when in the `closed` state. -// // resource tcp-socket type TCPSocket cm.Resource @@ -87,36 +59,6 @@ func wasmimport_TCPSocketResourceDrop(self0 uint32) // Accept represents the imported method "accept". // -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties -// are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated -// by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // accept: func() -> result, error-code> // //go:nosplit @@ -132,10 +74,6 @@ func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketIn // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -197,13 +135,6 @@ func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.Er // HopLimit represents the imported method "hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // hop-limit: func() -> result // //go:nosplit @@ -219,10 +150,6 @@ func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, // IsListening represents the imported method "is-listening". // -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. -// // is-listening: func() -> bool // //go:nosplit @@ -239,19 +166,6 @@ func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) // KeepAliveCount represents the imported method "keep-alive-count". // -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-count: func() -> result // //go:nosplit @@ -267,17 +181,6 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, // KeepAliveEnabled represents the imported method "keep-alive-enabled". // -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only -// come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. -// // keep-alive-enabled: func() -> result // //go:nosplit @@ -293,20 +196,6 @@ func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, // KeepAliveIdleTime represents the imported method "keep-alive-idle-time". // -// Amount of time the connection has to be idle before TCP starts sending keepalive -// packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-idle-time: func() -> result // //go:nosplit @@ -322,19 +211,6 @@ func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint6 // KeepAliveInterval represents the imported method "keep-alive-interval". // -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-interval: func() -> result // //go:nosplit @@ -350,24 +226,6 @@ func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint6 // LocalAddress represents the imported method "local-address". // -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -383,19 +241,6 @@ func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -411,17 +256,6 @@ func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -532,19 +366,6 @@ func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, resul // SetListenBacklogSize represents the imported method "set-listen-backlog-size". // -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog -// size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` -// state. -// // set-listen-backlog-size: func(value: u64) -> result<_, error-code> // //go:nosplit @@ -593,30 +414,6 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // Shutdown represents the imported method "shutdown". // -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> // //go:nosplit @@ -633,54 +430,6 @@ func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. -// (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the -// TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means -// that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where -// this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -699,60 +448,6 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // StartConnect represents the imported method "start-connect". // -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, -// ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. -// (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL -// on Windows) -// - `invalid-argument`: The socket is already attached to a different network. -// The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. -// (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, -// EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - -// // start-connect: func(network: borrow, remote-address: ip-socket-address) // -> result<_, error-code> // @@ -771,35 +466,6 @@ func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddre // StartListen represents the imported method "start-listen". // -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - -// // start-listen: func() -> result<_, error-code> // //go:nosplit @@ -815,24 +481,6 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/http-client/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/_examples/http-client/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go index e77481b..4c53876 100644 --- a/_examples/http-client/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go +++ b/_examples/http-client/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateUDPSocket represents the imported function "create-udp-socket". // -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - -// // create-udp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/http-client/gen/wasi/sockets/udp/udp.wit.go b/_examples/http-client/gen/wasi/sockets/udp/udp.wit.go index 3638261..f007297 100644 --- a/_examples/http-client/gen/wasi/sockets/udp/udp.wit.go +++ b/_examples/http-client/gen/wasi/sockets/udp/udp.wit.go @@ -11,57 +11,30 @@ import ( // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". // -// A received datagram. -// // record incoming-datagram { // data: list, // remote-address: ip-socket-address, // } type IncomingDatagram struct { - _ cm.HostLayout - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - Data cm.List[uint8] - - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized - // with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress network.IPSocketAddress } // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". // -// A datagram to be sent out. -// // record outgoing-datagram { // data: list, // remote-address: option, // } type OutgoingDatagram struct { - _ cm.HostLayout - // The payload. - Data cm.List[uint8] - - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address - // exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise - // it is equivalent to `sendto`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress cm.Option[network.IPSocketAddress] } // UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". // -// A UDP socket handle. -// // resource udp-socket type UDPSocket cm.Resource @@ -82,10 +55,6 @@ func wasmimport_UDPSocketResourceDrop(self0 uint32) // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -117,24 +86,6 @@ func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.Erro // LocalAddress represents the imported method "local-address". // -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -150,19 +101,6 @@ func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -178,17 +116,6 @@ func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -267,38 +194,6 @@ func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -317,57 +212,6 @@ func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // Stream represents the imported method "stream". // -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate -// any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` -// may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating -// with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, -// but -// only the most recently returned pair of streams will be operational. Implementations -// may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling -// `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// // %stream: func(remote-address: option) -> result, error-code> // @@ -385,11 +229,6 @@ func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddre // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -406,13 +245,6 @@ func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) // UnicastHopLimit represents the imported method "unicast-hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // unicast-hop-limit: func() -> result // //go:nosplit @@ -448,32 +280,6 @@ func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) // Receive represents the imported method "receive". // -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without -// blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET -// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // receive: func(max-results: u64) -> result, error-code> // //go:nosplit @@ -490,11 +296,6 @@ func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -531,18 +332,6 @@ func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) // CheckSend represents the imported method "check-send". // -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. -// // check-send: func() -> result // //go:nosplit @@ -558,55 +347,6 @@ func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[ // Send represents the imported method "send". // -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking -// and -// returns how many messages were actually sent (or queued for sending). This function -// never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` -// is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and -// sequentially -// sending each individual datagram until either the end of the list has been reached -// or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns -// an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations -// must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` -// permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` -// is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` -// was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // send: func(datagrams: list) -> result // //go:nosplit @@ -623,11 +363,6 @@ func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDat // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/http-client/wasmcloud.toml b/_examples/http-client/wasmcloud.toml index 969a6cf..c0b416f 100644 --- a/_examples/http-client/wasmcloud.toml +++ b/_examples/http-client/wasmcloud.toml @@ -1,10 +1,9 @@ name = "http_client" -language = "other" +language = "tinygo" type = "component" version = "0.1.0" [component] -build_command = "tinygo build -target=wasip2 --wit-package ./wit --wit-world example -o build/http_client.wasm main.go" wit_world = "example" wasm_target = "wasm32-wasi-preview2" destination = "build/http_client_s.wasm" diff --git a/_examples/http-client/wit/deps.lock b/_examples/http-client/wit/deps.lock index 9b4d85b..22c6b1d 100644 --- a/_examples/http-client/wit/deps.lock +++ b/_examples/http-client/wit/deps.lock @@ -1,55 +1,49 @@ -[cli] -sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" -sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" +["wasi-cli-0.2.0"] +sha256 = "13b041ec2314d48107929c335df3ca81b1bb0a35bfec38e206a59162a4c209cd" +sha512 = "725886b3244f4894a1121cd66e1bea0775964ca1b3811be3ae43a4c692cb7d5f27d851072637b8ec64bd5e71e85bb5e860f8331fe8f77353d9d7868ce1d72a8e" -[clocks] -sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" -sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" +["wasi-clocks-0.2.0"] +sha256 = "daf7133b4f60ba73185449327dd48d2b324799db858ab463bcd32d954a9ff394" +sha512 = "5992296c504aebfad359ab1676bba63b5d22e33112c240a437ee733433aa50552144242f8998180ff36f0da56e5f65691dbb1898331ce878bd9fa439b8909742" -[component] +["wasi-config-0.2.0-draft"] +sha256 = "5c6b4a10b21fbab2397d579c6f8bf8a484160dfdf20b6343080b0bad097849a3" +sha512 = "d3cf5fd1d12590aefd561330337870e2e468c84753c11e19bccd165c916a696722cc29af3572984e6256088b6e683763675d5b8cec3d195f9e2961fe405629b8" + +["wasi-filesystem-0.2.0"] +sha256 = "739d4fc43cd51421382e5d1a0cf643a2985691d480ae75600cdcd382665b3e55" +sha512 = "67f61ef46833060cc4d7a258da7a82024830762c4ecfd522d32bdc5e6bf4df26043f9a8c13ea38b191df180176826aa7b163816618a939015efff5987557dc16" + +["wasi-http-0.2.0"] +sha256 = "f22b6f3b3c12289e522041067b0a2db99a27c181e9ef3ed36930aa0286232d63" +sha512 = "f9b38ef4f58cb9e069b51ee45df52ce6ca9af0a9774c3d09dc99598f36afcd902557221be2f1a6bcccdecb880e4d7436b533e03f4b9250d5b0e1466afd3a62ce" + +["wasi-io-0.2.0"] +sha256 = "0bc0cc0d474a5c4f3c2e2092664c4e235a0390e5d206d3bdc4007488d9d5e00f" +sha512 = "497f37742a94ca32eaa77dce5d9144682e743b30c2d702d37726d43735a25fa9d421afbf5945da158c0e46a0adf941f607b0e0f5d26494af52f021265f78329c" + +["wasi-logging-0.1.0-draft"] +sha256 = "619c4d2336045bab9129e5af568decd5e963006291d496a23cddf796f3a61c2e" +sha512 = "c163aa6f4e566cb85d373f25e590e552fc2530fdf50946c38d305e9f2cd189d86ff8540d163e42acd2cebbe3cef98967cd1efb14ce196da132fcf6caf4f6155d" + +["wasi-random-0.2.0"] +sha256 = "efcdf344435591830f5fbed67a2c215bba112893518a8ef4c7234a4796b8dbcd" +sha512 = "c78a10e9b6401116eac703430609a849854a27a4ff3bc7737d514536a9c16a2fc206a35f8f96b7c40f254d6a66e6873361970754fa69b856025886cd462a2832" + +["wasi-sockets-0.2.0"] +sha256 = "aa3c13fee8c788c95de5a917a54d776d5adb2afd90a77224864941ce27c5d471" +sha512 = "4e3be65dd127ccd4bfa1af8f86fea556d6e22d25e4b637f9b9ebf66ae1f6331f904edff042adc9be16fec511e3295170e6c13516715d2cd3e5aaffbd96158fa9" + +["wasmcloud-bus-1.0.0"] +sha256 = "f823b5c8293cb585092107120139c34c405f57362761a133d543f5d68c65d591" +sha512 = "12e6aa4eac6139b60ea72cc7b6ded6ac9b144b15557be9f2329b6e84b5a161d8f6344674afd0526a883cb61e34c06fee9dbadbaee1d783cd957bc43dab4bfc2d" + +[wasmcloud-component-go] path = "../../../wit" -sha256 = "ec5b1fc6183ecd80b8328e2345d96d2b7e9fc8c2085300389d21c078ab03729f" -sha512 = "5b1488b7be9f9e05b713aa9cc5465eb730550eab3ae3a9a5ca8a243947a6ae9b90e4a4f06ecd9cc9a375306bb619c54b16856a73d25aa227c45352b88ec741db" -deps = ["cli", "clocks", "config", "filesystem", "io", "lattice", "logging", "messaging", "random", "secrets", "sockets"] - -[config] -sha256 = "9148c06861712b69170af7b8ec37896b4104297d920fdec9f3bcc0b1eee4a5c8" -sha512 = "25a54101620f279c835b39f56f6dbf8a92b374b6faaf6cf6aaa1ea06d8b97b9b79788cf8abd9c2ad0c11e3629dba6a2513b71f2c54b9f95027054ae54a4615b8" - -[filesystem] -sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" -sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" - -[http] -url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -sha256 = "8f44402bde16c48e28c47dc53eab0b26af5b3b3482a1852cf77673e0880ba1c1" -sha512 = "760695f9a25c25bf75a25b731cb21c3bda9e288e450edda823324ecbc73d5d798bbb5de2edad999566980836f037463ee9e57d61789d04b3f3e381475b1a9a0f" -deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] - -[io] -sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" -sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" - -[lattice] -sha256 = "b4946a8bfa48b2f4ac404de03617d25712879596be5417bde3de09ca9c369462" -sha512 = "09918bb2fa8f7af022f71453348be38ec7fd1a35df6809b8d0c5f246856712f969557ff65d9e5d4619e905191e27fba2fbbcc9f38c777a7b09eb73c30909d33f" - -[logging] -sha256 = "9676b482485bb0fd2751a390374c1108865a096b7037f4b5dbe524f066bfb06e" -sha512 = "30a621a6d48a0175e8047c062e618523a85f69c45a7c31918da2b888f7527fce1aca67fa132552222725d0f6cdcaed95be7f16c28488d9468c0fad00cb7450b9" - -[messaging] -sha256 = "41ada083aceb2b4ba92d9bd16d19b6462cc02b10378c9a49135c3447f9138a44" -sha512 = "aa9c819dfd9e85b19661f6087ffd824c44fc38c8a4bc1005c4e7fd34fe844633c52cae7a0412e9ea90f71826e0660e8a3b5672a0f0303c524e4139643ae675ac" - -[random] -sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" -sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" - -[secrets] -sha256 = "4c965f81e4f8510e917976dc7017b070d23b964724e3ca058f28ec9e3d691854" -sha512 = "c23d3d86846b7f35238347974c104a3056e5871db85a8e17c607cf2c48c5fc6dc550fa698a233b78de2c7b25e80ff6c590d0a4bf8c8892b48b3cec52bc141d32" - -[sockets] -sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" -sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" +sha256 = "995bd9ad8d0523f04480196b6746da80ddc5daf2e3be6b126c224d1fe9bda103" +sha512 = "e5af5fbb4242fc151d83ce86fa05d54274eb33a42b8856453659a1191d5142cd3792c914df8db330a9f692089974bbd1e6d3695142a8e5416d10b5b856839ce9" +deps = ["wasi-cli-0.2.0", "wasi-clocks-0.2.0", "wasi-config-0.2.0-draft", "wasi-filesystem-0.2.0", "wasi-http-0.2.0", "wasi-io-0.2.0", "wasi-logging-0.1.0-draft", "wasi-random-0.2.0", "wasi-sockets-0.2.0", "wasmcloud-bus-1.0.0", "wasmcloud-secrets-0.1.0-draft"] + +["wasmcloud-secrets-0.1.0-draft"] +sha256 = "8e0ec182ea30a420744887cdb42660bf703194eaf8ecf2f0dc0efc4159247ea4" +sha512 = "f0037028e47d307b1551068fcdb9249a0a1cd3d7d1e8d99f33713ec1ee22bc5242fe63155a9f7aaa0492640df2c79ea40ed0839e2add222c069787b59c09f1b3" diff --git a/_examples/http-client/wit/deps.toml b/_examples/http-client/wit/deps.toml index 9a0440f..4d1db6f 100644 --- a/_examples/http-client/wit/deps.toml +++ b/_examples/http-client/wit/deps.toml @@ -1,2 +1 @@ -http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -component = "../../../wit" +wasmcloud-component-go = "../../../wit" diff --git a/_examples/http-client/wit/deps/cli/command.wit b/_examples/http-client/wit/deps/cli/command.wit deleted file mode 100644 index d8005bd..0000000 --- a/_examples/http-client/wit/deps/cli/command.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:cli@0.2.0; - -world command { - include imports; - - export run; -} diff --git a/_examples/http-client/wit/deps/cli/environment.wit b/_examples/http-client/wit/deps/cli/environment.wit deleted file mode 100644 index 7006523..0000000 --- a/_examples/http-client/wit/deps/cli/environment.wit +++ /dev/null @@ -1,18 +0,0 @@ -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - get-environment: func() -> list>; - - /// Get the POSIX-style arguments to the program. - get-arguments: func() -> list; - - /// Return a path that programs should use as their initial current working - /// directory, interpreting `.` as shorthand for this. - initial-cwd: func() -> option; -} diff --git a/_examples/http-client/wit/deps/cli/exit.wit b/_examples/http-client/wit/deps/cli/exit.wit deleted file mode 100644 index d0c2b82..0000000 --- a/_examples/http-client/wit/deps/cli/exit.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface exit { - /// Exit the current instance and any linked instances. - exit: func(status: result); -} diff --git a/_examples/http-client/wit/deps/cli/imports.wit b/_examples/http-client/wit/deps/cli/imports.wit deleted file mode 100644 index 083b84a..0000000 --- a/_examples/http-client/wit/deps/cli/imports.wit +++ /dev/null @@ -1,20 +0,0 @@ -package wasi:cli@0.2.0; - -world imports { - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:sockets/imports@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; - - import environment; - import exit; - import stdin; - import stdout; - import stderr; - import terminal-input; - import terminal-output; - import terminal-stdin; - import terminal-stdout; - import terminal-stderr; -} diff --git a/_examples/http-client/wit/deps/cli/run.wit b/_examples/http-client/wit/deps/cli/run.wit deleted file mode 100644 index a70ee8c..0000000 --- a/_examples/http-client/wit/deps/cli/run.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface run { - /// Run the program. - run: func() -> result; -} diff --git a/_examples/http-client/wit/deps/cli/stdio.wit b/_examples/http-client/wit/deps/cli/stdio.wit deleted file mode 100644 index 31ef35b..0000000 --- a/_examples/http-client/wit/deps/cli/stdio.wit +++ /dev/null @@ -1,17 +0,0 @@ -interface stdin { - use wasi:io/streams@0.2.0.{input-stream}; - - get-stdin: func() -> input-stream; -} - -interface stdout { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stdout: func() -> output-stream; -} - -interface stderr { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stderr: func() -> output-stream; -} diff --git a/_examples/http-client/wit/deps/cli/terminal.wit b/_examples/http-client/wit/deps/cli/terminal.wit deleted file mode 100644 index 38c724e..0000000 --- a/_examples/http-client/wit/deps/cli/terminal.wit +++ /dev/null @@ -1,49 +0,0 @@ -/// Terminal input. -/// -/// In the future, this may include functions for disabling echoing, -/// disabling input buffering so that keyboard events are sent through -/// immediately, querying supported features, and so on. -interface terminal-input { - /// The input side of a terminal. - resource terminal-input; -} - -/// Terminal output. -/// -/// In the future, this may include functions for querying the terminal -/// size, being notified of terminal size changes, querying supported -/// features, and so on. -interface terminal-output { - /// The output side of a terminal. - resource terminal-output; -} - -/// An interface providing an optional `terminal-input` for stdin as a -/// link-time authority. -interface terminal-stdin { - use terminal-input.{terminal-input}; - - /// If stdin is connected to a terminal, return a `terminal-input` handle - /// allowing further interaction with it. - get-terminal-stdin: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stdout as a -/// link-time authority. -interface terminal-stdout { - use terminal-output.{terminal-output}; - - /// If stdout is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stdout: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stderr as a -/// link-time authority. -interface terminal-stderr { - use terminal-output.{terminal-output}; - - /// If stderr is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stderr: func() -> option; -} diff --git a/_examples/http-client/wit/deps/clocks/monotonic-clock.wit b/_examples/http-client/wit/deps/clocks/monotonic-clock.wit deleted file mode 100644 index 4e4dc3a..0000000 --- a/_examples/http-client/wit/deps/clocks/monotonic-clock.wit +++ /dev/null @@ -1,45 +0,0 @@ -package wasi:clocks@0.2.0; -/// WASI Monotonic Clock is a clock API intended to let users measure elapsed -/// time. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// 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. -interface monotonic-clock { - 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. - type instant = u64; - - /// A duration of time, in nanoseconds. - 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. - now: func() -> instant; - - /// Query the resolution of the clock. Returns the duration of time - /// corresponding to a clock tick. - resolution: func() -> duration; - - /// Create a `pollable` which will resolve once the specified instant - /// occured. - 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. - subscribe-duration: func( - when: duration, - ) -> pollable; -} diff --git a/_examples/http-client/wit/deps/clocks/wall-clock.wit b/_examples/http-client/wit/deps/clocks/wall-clock.wit deleted file mode 100644 index 440ca0f..0000000 --- a/_examples/http-client/wit/deps/clocks/wall-clock.wit +++ /dev/null @@ -1,42 +0,0 @@ -package wasi:clocks@0.2.0; -/// 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. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// A wall clock is a clock which measures the date and time according to -/// some external reference. -/// -/// External references may be reset, so this clock is not necessarily -/// monotonic, making it unsuitable for measuring elapsed time. -/// -/// It is intended for reporting the current date and time for humans. -interface wall-clock { - /// A time and date in seconds plus nanoseconds. - record datetime { - seconds: u64, - nanoseconds: u32, - } - - /// Read the current value of the clock. - /// - /// This clock is not monotonic, therefore calling this function repeatedly - /// will not necessarily produce a sequence of non-decreasing values. - /// - /// The returned timestamps represent the number of seconds since - /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], - /// also known as [Unix Time]. - /// - /// The nanoseconds field of the output is always less than 1000000000. - /// - /// [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 - now: func() -> datetime; - - /// Query the resolution of the clock. - /// - /// The nanoseconds field of the output is always less than 1000000000. - resolution: func() -> datetime; -} diff --git a/_examples/http-client/wit/deps/clocks/world.wit b/_examples/http-client/wit/deps/clocks/world.wit deleted file mode 100644 index c022457..0000000 --- a/_examples/http-client/wit/deps/clocks/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:clocks@0.2.0; - -world imports { - import monotonic-clock; - import wall-clock; -} diff --git a/_examples/http-client/wit/deps/config/runtime_config.wit b/_examples/http-client/wit/deps/config/runtime_config.wit deleted file mode 100644 index 29d53b1..0000000 --- a/_examples/http-client/wit/deps/config/runtime_config.wit +++ /dev/null @@ -1,25 +0,0 @@ -interface runtime { - /// An error type that encapsulates the different errors that can occur fetching config - variant config-error { - /// This indicates an error from an "upstream" config source. - /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), - /// the error message is a string. - upstream(string), - /// This indicates an error from an I/O operation. - /// As this could be almost _anything_ (such as a file read, network connection, etc), - /// the error message is a string. - /// Depending on how this ends up being consumed, - /// we may consider moving this to use the `wasi:io/error` type instead. - /// For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - } - - /// Gets a single opaque config value set at the given key if it exists - get: func( - /// A string key to fetch - key: string - ) -> result, config-error>; - - /// Gets a list of all set config data - get-all: func() -> result>, config-error>; -} diff --git a/_examples/http-client/wit/deps/config/world.wit b/_examples/http-client/wit/deps/config/world.wit deleted file mode 100644 index 378c4a7..0000000 --- a/_examples/http-client/wit/deps/config/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:config@0.2.0-draft; - -world imports { - /// The runtime interface for config - import runtime; -} \ No newline at end of file diff --git a/_examples/http-client/wit/deps/filesystem/preopens.wit b/_examples/http-client/wit/deps/filesystem/preopens.wit deleted file mode 100644 index da801f6..0000000 --- a/_examples/http-client/wit/deps/filesystem/preopens.wit +++ /dev/null @@ -1,8 +0,0 @@ -package wasi:filesystem@0.2.0; - -interface preopens { - use types.{descriptor}; - - /// Return the set of preopened directories, and their path. - get-directories: func() -> list>; -} diff --git a/_examples/http-client/wit/deps/filesystem/types.wit b/_examples/http-client/wit/deps/filesystem/types.wit deleted file mode 100644 index 11108fc..0000000 --- a/_examples/http-client/wit/deps/filesystem/types.wit +++ /dev/null @@ -1,634 +0,0 @@ -package wasi:filesystem@0.2.0; -/// WASI filesystem is a filesystem API primarily intended to let users run WASI -/// programs that access their files on their existing filesystems, without -/// significant overhead. -/// -/// It is intended to be roughly portable between Unix-family platforms and -/// Windows, though it does not hide many of the major differences. -/// -/// Paths are passed as interface-type `string`s, meaning they must consist of -/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -/// paths which are not accessible by this API. -/// -/// The directory separator in WASI is always the forward-slash (`/`). -/// -/// All paths in WASI are relative paths, and are interpreted relative to a -/// `descriptor` referring to a base directory. If a `path` argument to any WASI -/// function starts with `/`, or if any step of resolving a `path`, including -/// `..` and symbolic link steps, reaches a directory outside of the base -/// directory, or reaches a symlink to an absolute or rooted path in the -/// underlying filesystem, the function fails with `error-code::not-permitted`. -/// -/// For more information about WASI path resolution and sandboxing, see -/// [WASI filesystem path resolution]. -/// -/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md -interface types { - use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0.{datetime}; - - /// File size or length of a region within a file. - type filesize = u64; - - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - enum descriptor-type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - unknown, - /// The descriptor refers to a block device inode. - block-device, - /// The descriptor refers to a character device inode. - character-device, - /// The descriptor refers to a directory inode. - directory, - /// The descriptor refers to a named pipe. - fifo, - /// The file refers to a symbolic link inode. - symbolic-link, - /// The descriptor refers to a regular file inode. - regular-file, - /// The descriptor refers to a socket. - socket, - } - - /// Descriptor flags. - /// - /// Note: This was called `fdflags` in earlier versions of WASI. - flags descriptor-flags { - /// Read mode: Data can be read. - read, - /// Write mode: Data can be written to. - write, - /// Request that writes be performed according to synchronized I/O file - /// integrity completion. The data stored in the file and the file's - /// metadata are synchronized. This is similar to `O_SYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - file-integrity-sync, - /// Request that writes be performed according to synchronized I/O data - /// integrity completion. Only the data stored in the file is - /// synchronized. This is similar to `O_DSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - data-integrity-sync, - /// Requests that reads be performed at the same level of integrety - /// requested for writes. This is similar to `O_RSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - requested-write-sync, - /// Mutating directories mode: Directory contents may be mutated. - /// - /// When this flag is unset on a descriptor, operations using the - /// descriptor which would create, rename, delete, modify the data or - /// metadata of filesystem objects, or obtain another handle which - /// would permit any of those, shall fail with `error-code::read-only` if - /// they would otherwise succeed. - /// - /// This may only be set on directories. - mutate-directory, - } - - /// File attributes. - /// - /// Note: This was called `filestat` in earlier versions of WASI. - record descriptor-stat { - /// File type. - %type: descriptor-type, - /// Number of hard links to the file. - link-count: link-count, - /// For regular files, the file size in bytes. For symbolic links, the - /// length in bytes of the pathname contained in the symbolic link. - size: filesize, - /// Last data access timestamp. - /// - /// If the `option` is none, the platform doesn't maintain an access - /// timestamp for this file. - data-access-timestamp: option, - /// Last data modification timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// modification timestamp for this file. - data-modification-timestamp: option, - /// Last file status-change timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// status-change timestamp for this file. - status-change-timestamp: option, - } - - /// Flags determining the method of how paths are resolved. - flags path-flags { - /// As long as the resolved path corresponds to a symbolic link, it is - /// expanded. - symlink-follow, - } - - /// Open flags used by `open-at`. - flags open-flags { - /// Create file if it does not exist, similar to `O_CREAT` in POSIX. - create, - /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. - directory, - /// Fail if file already exists, similar to `O_EXCL` in POSIX. - exclusive, - /// Truncate file to size 0, similar to `O_TRUNC` in POSIX. - truncate, - } - - /// Number of hard links to an inode. - type link-count = u64; - - /// When setting a timestamp, this gives the value to set it to. - variant new-timestamp { - /// Leave the timestamp set to its previous value. - no-change, - /// Set the timestamp to the current time of the system clock associated - /// with the filesystem. - now, - /// Set the timestamp to the given value. - timestamp(datetime), - } - - /// A directory entry. - record directory-entry { - /// The type of the file referred to by this directory entry. - %type: descriptor-type, - - /// The name of the object. - name: string, - } - - /// Error codes returned by functions, similar to `errno` in POSIX. - /// Not all of these error codes are returned by the functions provided by this - /// API; some are used in higher-level library layers, and others are provided - /// merely for alignment with POSIX. - enum error-code { - /// Permission denied, similar to `EACCES` in POSIX. - access, - /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. - would-block, - /// Connection already in progress, similar to `EALREADY` in POSIX. - already, - /// Bad descriptor, similar to `EBADF` in POSIX. - bad-descriptor, - /// Device or resource busy, similar to `EBUSY` in POSIX. - busy, - /// Resource deadlock would occur, similar to `EDEADLK` in POSIX. - deadlock, - /// Storage quota exceeded, similar to `EDQUOT` in POSIX. - quota, - /// File exists, similar to `EEXIST` in POSIX. - exist, - /// File too large, similar to `EFBIG` in POSIX. - file-too-large, - /// Illegal byte sequence, similar to `EILSEQ` in POSIX. - illegal-byte-sequence, - /// Operation in progress, similar to `EINPROGRESS` in POSIX. - in-progress, - /// Interrupted function, similar to `EINTR` in POSIX. - interrupted, - /// Invalid argument, similar to `EINVAL` in POSIX. - invalid, - /// I/O error, similar to `EIO` in POSIX. - io, - /// Is a directory, similar to `EISDIR` in POSIX. - is-directory, - /// Too many levels of symbolic links, similar to `ELOOP` in POSIX. - loop, - /// Too many links, similar to `EMLINK` in POSIX. - too-many-links, - /// Message too large, similar to `EMSGSIZE` in POSIX. - message-size, - /// Filename too long, similar to `ENAMETOOLONG` in POSIX. - name-too-long, - /// No such device, similar to `ENODEV` in POSIX. - no-device, - /// No such file or directory, similar to `ENOENT` in POSIX. - no-entry, - /// No locks available, similar to `ENOLCK` in POSIX. - no-lock, - /// Not enough space, similar to `ENOMEM` in POSIX. - insufficient-memory, - /// No space left on device, similar to `ENOSPC` in POSIX. - insufficient-space, - /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. - not-directory, - /// Directory not empty, similar to `ENOTEMPTY` in POSIX. - not-empty, - /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. - not-recoverable, - /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. - unsupported, - /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. - no-tty, - /// No such device or address, similar to `ENXIO` in POSIX. - no-such-device, - /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. - overflow, - /// Operation not permitted, similar to `EPERM` in POSIX. - not-permitted, - /// Broken pipe, similar to `EPIPE` in POSIX. - pipe, - /// Read-only file system, similar to `EROFS` in POSIX. - read-only, - /// Invalid seek, similar to `ESPIPE` in POSIX. - invalid-seek, - /// Text file busy, similar to `ETXTBSY` in POSIX. - text-file-busy, - /// Cross-device link, similar to `EXDEV` in POSIX. - cross-device, - } - - /// File or memory access pattern advisory information. - enum advice { - /// The application has no advice to give on its behavior with respect - /// to the specified data. - normal, - /// The application expects to access the specified data sequentially - /// from lower offsets to higher offsets. - sequential, - /// The application expects to access the specified data in a random - /// order. - random, - /// The application expects to access the specified data in the near - /// future. - will-need, - /// The application expects that it will not access the specified data - /// in the near future. - dont-need, - /// The application expects to access the specified data once and then - /// not reuse it thereafter. - no-reuse, - } - - /// A 128-bit hash value, split into parts because wasm doesn't have a - /// 128-bit integer type. - record metadata-hash-value { - /// 64 bits of a 128-bit hash value. - lower: u64, - /// Another 64 bits of a 128-bit hash value. - upper: u64, - } - - /// 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. - resource descriptor { - /// Return a stream for reading from a file, if available. - /// - /// May fail with an error-code describing why the file cannot be read. - /// - /// Multiple read, write, and append streams may be active on the same open - /// file and they do not interfere with each other. - /// - /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. - read-via-stream: func( - /// The offset within the file at which to start reading. - offset: filesize, - ) -> result; - - /// Return a stream for writing to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be written. - /// - /// Note: This allows using `write-stream`, which is similar to `write` in - /// POSIX. - write-via-stream: func( - /// The offset within the file at which to start writing. - offset: filesize, - ) -> result; - - /// Return a stream for appending to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be appended. - /// - /// Note: This allows using `write-stream`, which is similar to `write` with - /// `O_APPEND` in in POSIX. - append-via-stream: func() -> result; - - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - advise: func( - /// The offset within the file to which the advisory applies. - offset: filesize, - /// The length of the region to which the advisory applies. - length: filesize, - /// The advice. - advice: advice - ) -> result<_, error-code>; - - /// Synchronize the data of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fdatasync` in POSIX. - sync-data: func() -> result<_, error-code>; - - /// Get flags associated with a descriptor. - /// - /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. - /// - /// Note: This returns the value that was the `fs_flags` value returned - /// from `fdstat_get` in earlier versions of WASI. - get-flags: func() -> result; - - /// Get the dynamic type of a descriptor. - /// - /// Note: This returns the same value as the `type` field of the `fd-stat` - /// returned by `stat`, `stat-at` and similar. - /// - /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided - /// by `fstat` in POSIX. - /// - /// Note: This returns the value that was the `fs_filetype` value returned - /// from `fdstat_get` in earlier versions of WASI. - 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. - set-size: func(size: filesize) -> result<_, error-code>; - - /// Adjust the timestamps of an open file or directory. - /// - /// Note: This is similar to `futimens` in POSIX. - /// - /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. - set-times: func( - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Read from a descriptor, without using and updating the descriptor's offset. - /// - /// This function returns a list of bytes containing the data that was - /// read, along with a bool which, when true, indicates that the end of the - /// file was reached. The returned list will contain up to `length` bytes; it - /// may return fewer than requested, if the end of the file is reached or - /// if the I/O operation is interrupted. - /// - /// In the future, this may change to return a `stream`. - /// - /// Note: This is similar to `pread` in POSIX. - read: func( - /// The maximum number of bytes to read. - length: filesize, - /// The offset within the file at which to read. - offset: filesize, - ) -> result, bool>, error-code>; - - /// Write to a descriptor, without using and updating the descriptor's offset. - /// - /// It is valid to write past the end of a file; the file is extended to the - /// extent of the write, with bytes between the previous end and the start of - /// the write set to zero. - /// - /// In the future, this may change to take a `stream`. - /// - /// Note: This is similar to `pwrite` in POSIX. - write: func( - /// Data to write - buffer: list, - /// The offset within the file at which to write. - offset: filesize, - ) -> result; - - /// Read directory entries from a directory. - /// - /// On filesystems where directories contain entries referring to themselves - /// and their parents, often named `.` and `..` respectively, these entries - /// are omitted. - /// - /// 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. - read-directory: func() -> result; - - /// Synchronize the data and metadata of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fsync` in POSIX. - sync: func() -> result<_, error-code>; - - /// Create a directory. - /// - /// Note: This is similar to `mkdirat` in POSIX. - create-directory-at: func( - /// The relative path at which to create the directory. - path: string, - ) -> result<_, error-code>; - - /// Return the attributes of an open file or directory. - /// - /// Note: This is similar to `fstat` in POSIX, except that it does not return - /// device and inode information. For testing whether two descriptors refer to - /// the same underlying filesystem object, use `is-same-object`. To obtain - /// additional data that can be used do determine whether a file has been - /// modified, use `metadata-hash`. - /// - /// Note: This was called `fd_filestat_get` in earlier versions of WASI. - stat: func() -> result; - - /// Return the attributes of a file or directory. - /// - /// Note: This is similar to `fstatat` in POSIX, except that it does not - /// return device and inode information. See the `stat` description for a - /// discussion of alternatives. - /// - /// Note: This was called `path_filestat_get` in earlier versions of WASI. - stat-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - - /// Adjust the timestamps of a file or directory. - /// - /// Note: This is similar to `utimensat` in POSIX. - /// - /// Note: This was called `path_filestat_set_times` in earlier versions of - /// WASI. - set-times-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to operate on. - path: string, - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Create a hard link. - /// - /// Note: This is similar to `linkat` in POSIX. - link-at: func( - /// Flags determining the method of how the path is resolved. - old-path-flags: path-flags, - /// The relative source path from which to link. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path at which to create the hard link. - new-path: string, - ) -> result<_, error-code>; - - /// Open a file or directory. - /// - /// The returned descriptor is not guaranteed to be the lowest-numbered - /// descriptor not currently open/ it is randomized to prevent applications - /// from depending on making assumptions about indexes, since this is - /// error-prone in multi-threaded contexts. The returned descriptor is - /// guaranteed to be less than 2**31. - /// - /// If `flags` contains `descriptor-flags::mutate-directory`, and the base - /// descriptor doesn't have `descriptor-flags::mutate-directory` set, - /// `open-at` fails with `error-code::read-only`. - /// - /// If `flags` contains `write` or `mutate-directory`, or `open-flags` - /// contains `truncate` or `create`, and the base descriptor doesn't have - /// `descriptor-flags::mutate-directory` set, `open-at` fails with - /// `error-code::read-only`. - /// - /// Note: This is similar to `openat` in POSIX. - open-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the object to open. - path: string, - /// The method by which to open the file. - open-flags: open-flags, - /// Flags to use for the resulting descriptor. - %flags: descriptor-flags, - ) -> result; - - /// Read the contents of a symbolic link. - /// - /// If the contents contain an absolute or rooted path in the underlying - /// filesystem, this function fails with `error-code::not-permitted`. - /// - /// Note: This is similar to `readlinkat` in POSIX. - readlink-at: func( - /// The relative path of the symbolic link from which to read. - path: string, - ) -> result; - - /// Remove a directory. - /// - /// Return `error-code::not-empty` if the directory is not empty. - /// - /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - remove-directory-at: func( - /// The relative path to a directory to remove. - path: string, - ) -> result<_, error-code>; - - /// Rename a filesystem object. - /// - /// Note: This is similar to `renameat` in POSIX. - rename-at: func( - /// The relative source path of the file or directory to rename. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path to which to rename the file or directory. - new-path: string, - ) -> result<_, error-code>; - - /// Create a symbolic link (also known as a "symlink"). - /// - /// If `old-path` starts with `/`, the function fails with - /// `error-code::not-permitted`. - /// - /// Note: This is similar to `symlinkat` in POSIX. - symlink-at: func( - /// The contents of the symbolic link. - old-path: string, - /// The relative destination path at which to create the symbolic link. - new-path: string, - ) -> result<_, error-code>; - - /// Unlink a filesystem object that is not a directory. - /// - /// Return `error-code::is-directory` if the path refers to a directory. - /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. - unlink-file-at: func( - /// The relative path to a file to unlink. - path: string, - ) -> result<_, error-code>; - - /// Test whether two descriptors refer to the same filesystem object. - /// - /// In POSIX, this corresponds to testing whether the two descriptors have the - /// 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. - is-same-object: func(other: borrow) -> bool; - - /// Return a hash of the metadata associated with a filesystem object referred - /// to by a descriptor. - /// - /// This returns a hash of the last-modification timestamp and file size, and - /// may also include the inode number, device number, birth timestamp, and - /// other metadata fields that may change when the file is modified or - /// replaced. It may also include a secret value chosen by the - /// implementation and not otherwise exposed. - /// - /// Implementations are encourated to provide the following properties: - /// - /// - If the file is not modified or replaced, the computed hash value should - /// usually not change. - /// - If the object is modified or replaced, the computed hash value should - /// usually change. - /// - The inputs to the hash should not be easily computable from the - /// computed hash. - /// - /// However, none of these is required. - 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`. - metadata-hash-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - } - - /// A stream of directory entries. - resource directory-entry-stream { - /// Read a single directory entry from a `directory-entry-stream`. - read-directory-entry: func() -> result, error-code>; - } - - /// Attempts to extract a filesystem-related `error-code` from the stream - /// `error` provided. - /// - /// Stream operations which return `stream-error::last-operation-failed` - /// have a payload with more information about the operation that failed. - /// This payload can be passed through to this function to see if there's - /// filesystem-related information about the error to return. - /// - /// Note that this function is fallible because not all stream-related - /// errors are filesystem-related errors. - filesystem-error-code: func(err: borrow) -> option; -} diff --git a/_examples/http-client/wit/deps/filesystem/world.wit b/_examples/http-client/wit/deps/filesystem/world.wit deleted file mode 100644 index 663f579..0000000 --- a/_examples/http-client/wit/deps/filesystem/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:filesystem@0.2.0; - -world imports { - import types; - import preopens; -} diff --git a/_examples/http-client/wit/deps/http/handler.wit b/_examples/http-client/wit/deps/http/handler.wit deleted file mode 100644 index a34a064..0000000 --- a/_examples/http-client/wit/deps/http/handler.wit +++ /dev/null @@ -1,43 +0,0 @@ -/// This interface defines a handler of incoming HTTP Requests. It should -/// be exported by components which can respond to HTTP Requests. -interface incoming-handler { - use types.{incoming-request, response-outparam}; - - /// This function is invoked with an incoming HTTP Request, and a resource - /// `response-outparam` which provides the capability to reply with an HTTP - /// Response. The response is sent by calling the `response-outparam.set` - /// method, which allows execution to continue after the response has been - /// sent. This enables both streaming to the response body, and performing other - /// work. - /// - /// 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. - handle: func( - request: incoming-request, - response-out: response-outparam - ); -} - -/// This interface defines a handler of outgoing HTTP Requests. It should be -/// imported by components which wish to make HTTP Requests. -interface outgoing-handler { - use types.{ - outgoing-request, request-options, future-incoming-response, error-code - }; - - /// This function is invoked with an outgoing HTTP Request, and it returns - /// a resource `future-incoming-response` which represents an HTTP Response - /// which may arrive in the future. - /// - /// The `options` argument accepts optional parameters for the HTTP - /// protocol's transport layer. - /// - /// 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`. - handle: func( - request: outgoing-request, - options: option - ) -> result; -} diff --git a/_examples/http-client/wit/deps/http/proxy.wit b/_examples/http-client/wit/deps/http/proxy.wit deleted file mode 100644 index 687c24d..0000000 --- a/_examples/http-client/wit/deps/http/proxy.wit +++ /dev/null @@ -1,32 +0,0 @@ -package wasi:http@0.2.0; - -/// The `wasi:http/proxy` world captures a widely-implementable intersection of -/// 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. -world proxy { - /// HTTP proxies have access to time and randomness. - include wasi:clocks/imports@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. - import wasi:cli/stdout@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. - 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()`). - import outgoing-handler; - - /// 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`. - export incoming-handler; -} diff --git a/_examples/http-client/wit/deps/io/error.wit b/_examples/http-client/wit/deps/io/error.wit deleted file mode 100644 index 22e5b64..0000000 --- a/_examples/http-client/wit/deps/io/error.wit +++ /dev/null @@ -1,34 +0,0 @@ -package wasi:io@0.2.0; - - -interface error { - /// A resource which represents some error information. - /// - /// The only method provided by this resource is `to-debug-string`, - /// 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, `error`s 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` and returns - /// `option`. - /// - /// The set of functions which can "downcast" an `error` into a more - /// concrete type is open. - resource error { - /// Returns a string that is suitable to assist humans in debugging - /// this error. - /// - /// WARNING: The returned string should not be consumed mechanically! - /// It may change across platforms, hosts, or other implementation - /// details. Parsing this string is a major platform-compatibility - /// hazard. - to-debug-string: func() -> string; - } -} diff --git a/_examples/http-client/wit/deps/io/poll.wit b/_examples/http-client/wit/deps/io/poll.wit deleted file mode 100644 index ddc67f8..0000000 --- a/_examples/http-client/wit/deps/io/poll.wit +++ /dev/null @@ -1,41 +0,0 @@ -package wasi:io@0.2.0; - -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// `pollable` represents a single I/O event which may be ready, or not. - resource pollable { - - /// Return the readiness of a pollable. This function never blocks. - /// - /// Returns `true` when the pollable is ready, and `false` otherwise. - ready: func() -> bool; - - /// `block` returns immediately if the pollable is ready, and otherwise - /// blocks until ready. - /// - /// This function is equivalent to calling `poll.poll` on a list - /// containing only this pollable. - block: func(); - } - - /// Poll for completion on a set of pollables. - /// - /// This function takes a list of pollables, which identify I/O sources of - /// interest, and waits until one or more of the events is ready for I/O. - /// - /// The result `list` 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. - /// - /// 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. - poll: func(in: list>) -> list; -} diff --git a/_examples/http-client/wit/deps/io/streams.wit b/_examples/http-client/wit/deps/io/streams.wit deleted file mode 100644 index 6d2f871..0000000 --- a/_examples/http-client/wit/deps/io/streams.wit +++ /dev/null @@ -1,262 +0,0 @@ -package wasi:io@0.2.0; - -/// 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; -/// when it does, they are expected to subsume this API. -interface streams { - use error.{error}; - use poll.{pollable}; - - /// An error for input-stream and output-stream operations. - variant stream-error { - /// The last operation (a write or flush) failed before completion. - /// - /// More information is available in the `error` payload. - last-operation-failed(error), - /// The stream is closed: no more input will be accepted by the - /// stream. A closed output-stream will return this error on all - /// future operations. - closed - } - - /// An input bytestream. - /// - /// `input-stream`s are *non-blocking* to the extent practical on underlying - /// platforms. I/O operations always return promptly; if fewer bytes are - /// promptly available than requested, they return the number of bytes promptly - /// available, which could even be zero. To wait for data to be available, - /// use the `subscribe` function to obtain a `pollable` which can be polled - /// for using `wasi:io/poll`. - resource input-stream { - /// 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 - /// empty when no bytes are available for reading at this time. The - /// pollable given by `subscribe` will be ready when more bytes are - /// available. - /// - /// This function fails with a `stream-error` when the operation - /// encounters an error, giving `last-operation-failed`, or when the - /// stream is closed, giving `closed`. - /// - /// When the caller gives a `len` of 0, it represents a request to - /// read 0 bytes. If the stream is still open, this call should - /// succeed and return an empty list, or otherwise fail with `closed`. - /// - /// The `len` parameter is a `u64`, which could represent a list of u8 which - /// is not possible to allocate in wasm32, or not desirable to allocate as - /// 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. - read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Read bytes from a stream, after blocking until at least one byte can - /// be read. Except for blocking, behavior is identical to `read`. - blocking-read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Skip bytes from a stream. Returns number of bytes skipped. - /// - /// Behaves identical to `read`, except instead of returning a list - /// of bytes, returns the number of bytes consumed from the stream. - skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// Skip bytes from a stream, after blocking until at least one byte - /// can be skipped. Except for blocking behavior, identical to `skip`. - blocking-skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// 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. - /// The created `pollable` is a child resource of the `input-stream`. - /// Implementations may trap if the `input-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - } - - - /// An output bytestream. - /// - /// `output-stream`s 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`. - resource output-stream { - /// 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 - /// permitted will trap. - /// - /// When this function returns 0 bytes, the `subscribe` pollable will - /// become ready when this function will report at least 1 byte, or an - /// error. - check-write: func() -> result; - - /// 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. - /// - /// returns Err(closed) without writing if the stream has closed since - /// the last call to check-write provided a permit. - write: func( - contents: list - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 bytes, and then flush the stream. Block - /// until all of these operations are complete, or an error occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write`, and `flush`, and is implemented with the - /// following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while !contents.is_empty() { - /// // Wait for the stream to become writable - /// pollable.block(); - /// let Ok(n) = this.check-write(); // eliding error handling - /// let len = min(n, contents.len()); - /// let (chunk, rest) = contents.split_at(len); - /// this.write(chunk ); // eliding error handling - /// contents = rest; - /// } - /// this.flush(); - /// // Wait for completion of `flush` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-and-flush: func( - contents: list - ) -> result<_, stream-error>; - - /// 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 - /// is all that has been passed to `write` prior to this call. - /// - /// Upon calling this function, the `output-stream` will not accept any - /// writes (`check-write` will return `ok(0)`) until the flush has - /// completed. The `subscribe` pollable will become ready when the - /// flush has completed and the stream can accept more writes. - flush: func() -> result<_, stream-error>; - - /// Request to flush buffered output, and block until flush completes - /// and stream is ready for writing again. - blocking-flush: func() -> result<_, stream-error>; - - /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. 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. - /// - /// The created `pollable` is a child resource of the `output-stream`. - /// Implementations may trap if the `output-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - - /// Write zeroes to a stream. - /// - /// 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. - write-zeroes: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 zeroes, and then flush the stream. - /// Block until all of these operations are complete, or an error - /// occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with - /// the following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while num_zeroes != 0 { - /// // Wait for the stream to become writable - /// 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` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-zeroes-and-flush: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Read from one stream and write to another. - /// - /// The behavior of splice is equivelant to: - /// 1. calling `check-write` on the `output-stream` - /// 2. calling `read` on the `input-stream` with the smaller of the - /// `check-write` permitted length and the `len` provided to `splice` - /// 3. calling `write` on the `output-stream` with that read data. - /// - /// Any error reported by the call to `check-write`, `read`, or - /// `write` ends the splice and reports that error. - /// - /// This function returns the number of bytes transferred; it may be less - /// than `len`. - splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - - /// 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`. - blocking-splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - } -} diff --git a/_examples/http-client/wit/deps/io/world.wit b/_examples/http-client/wit/deps/io/world.wit deleted file mode 100644 index 5f0b43f..0000000 --- a/_examples/http-client/wit/deps/io/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:io@0.2.0; - -world imports { - import streams; - import poll; -} diff --git a/_examples/http-client/wit/deps/lattice/bus.wit b/_examples/http-client/wit/deps/lattice/bus.wit deleted file mode 100644 index 9275448..0000000 --- a/_examples/http-client/wit/deps/lattice/bus.wit +++ /dev/null @@ -1,14 +0,0 @@ -package wasmcloud:bus@1.0.0; - -interface lattice { - /// Interface target. This represents an interface, which can be selected by `set-link-name`. - resource call-target-interface { - constructor(namespace: string, %package: string, %interface: string); - } - - /// Set an optional link name to use for all interfaces specified. This is advanced - /// functionality only available within wasmcloud and, as such, is exposed here as part of the - /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces - /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component - set-link-name: func(name: string, interfaces: list); -} diff --git a/_examples/http-client/wit/deps/logging/logging.wit b/_examples/http-client/wit/deps/logging/logging.wit deleted file mode 100644 index 8c0bdf8..0000000 --- a/_examples/http-client/wit/deps/logging/logging.wit +++ /dev/null @@ -1,35 +0,0 @@ -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - - /// Describes messages indicating hazardous situations. - warn, - - /// Describes messages indicating serious errors. - error, - - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} diff --git a/_examples/http-client/wit/deps/logging/world.wit b/_examples/http-client/wit/deps/logging/world.wit deleted file mode 100644 index ede6286..0000000 --- a/_examples/http-client/wit/deps/logging/world.wit +++ /dev/null @@ -1,5 +0,0 @@ -package wasi:logging; - -world imports { - import logging; -} diff --git a/_examples/http-client/wit/deps/messaging/messaging.wit b/_examples/http-client/wit/deps/messaging/messaging.wit deleted file mode 100644 index 239d289..0000000 --- a/_examples/http-client/wit/deps/messaging/messaging.wit +++ /dev/null @@ -1,27 +0,0 @@ -package wasmcloud:messaging@0.2.0; - -// Types common to message broker interactions -interface types { - // A message sent to or received from a broker - record broker-message { - subject: string, - body: list, - reply-to: option, - } -} - -interface handler { - use types.{broker-message}; - - // Callback handled to invoke a function when a message is received from a subscription - handle-message: func(msg: broker-message) -> result<_, string>; -} - -interface consumer { - use types.{broker-message}; - - // Perform a request operation on a subject - request: func(subject: string, body: list, timeout-ms: u32) -> result; - // Publish a message to a subject without awaiting a response - publish: func(msg: broker-message) -> result<_, string>; -} diff --git a/_examples/http-client/wit/deps/random/insecure-seed.wit b/_examples/http-client/wit/deps/random/insecure-seed.wit deleted file mode 100644 index 47210ac..0000000 --- a/_examples/http-client/wit/deps/random/insecure-seed.wit +++ /dev/null @@ -1,25 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure-seed interface for seeding hash-map DoS resistance. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure-seed { - /// Return a 128-bit value that may contain a pseudo-random value. - /// - /// The returned value is not required to be computed from a CSPRNG, and may - /// even be entirely deterministic. Host implementations are encouraged to - /// provide pseudo-random values to any program exposed to - /// attacker-controlled content, to enable DoS protection built into many - /// languages' hash-map implementations. - /// - /// This function is intended to only be called once, by a source language - /// to initialize Denial Of Service (DoS) protection in its hash-map - /// implementation. - /// - /// # Expected future evolution - /// - /// This will likely be changed to a value import, to prevent it from being - /// called multiple times and potentially used for purposes other than DoS - /// protection. - insecure-seed: func() -> tuple; -} diff --git a/_examples/http-client/wit/deps/random/insecure.wit b/_examples/http-client/wit/deps/random/insecure.wit deleted file mode 100644 index c58f4ee..0000000 --- a/_examples/http-client/wit/deps/random/insecure.wit +++ /dev/null @@ -1,22 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure interface for insecure pseudo-random numbers. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure { - /// Return `len` insecure pseudo-random bytes. - /// - /// This function is not cryptographically secure. Do not use it for - /// anything related to security. - /// - /// There are no requirements on the values of the returned bytes, however - /// implementations are encouraged to return evenly distributed values with - /// a long period. - get-insecure-random-bytes: func(len: u64) -> list; - - /// Return an insecure pseudo-random `u64` value. - /// - /// This function returns the same type of pseudo-random data as - /// `get-insecure-random-bytes`, represented as a `u64`. - get-insecure-random-u64: func() -> u64; -} diff --git a/_examples/http-client/wit/deps/random/random.wit b/_examples/http-client/wit/deps/random/random.wit deleted file mode 100644 index 0c017f0..0000000 --- a/_examples/http-client/wit/deps/random/random.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wasi:random@0.2.0; -/// WASI Random is a random data API. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface random { - /// Return `len` cryptographically-secure random or pseudo-random bytes. - /// - /// This function must produce data at least as cryptographically secure and - /// fast as an adequately seeded cryptographically-secure pseudo-random - /// number generator (CSPRNG). It must not block, from the perspective of - /// the calling program, under any circumstances, including on the first - /// request and on requests for numbers of bytes. The returned data must - /// always be unpredictable. - /// - /// This function must always return fresh data. Deterministic environments - /// must omit this function, rather than implementing it with deterministic - /// data. - get-random-bytes: func(len: u64) -> list; - - /// Return a cryptographically-secure random or pseudo-random `u64` value. - /// - /// This function returns the same type of data as `get-random-bytes`, - /// represented as a `u64`. - get-random-u64: func() -> u64; -} diff --git a/_examples/http-client/wit/deps/random/world.wit b/_examples/http-client/wit/deps/random/world.wit deleted file mode 100644 index 3da3491..0000000 --- a/_examples/http-client/wit/deps/random/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:random@0.2.0; - -world imports { - import random; - import insecure; - import insecure-seed; -} diff --git a/_examples/http-client/wit/deps/secrets/secrets.wit b/_examples/http-client/wit/deps/secrets/secrets.wit deleted file mode 100644 index da6f4ad..0000000 --- a/_examples/http-client/wit/deps/secrets/secrets.wit +++ /dev/null @@ -1,56 +0,0 @@ -/// This WIT interface powers secret support in wasmCloud -/// -/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 - -package wasmcloud:secrets@0.1.0-draft; - -interface store { - // An error type that encapsulates the different errors that can occur fetching secrets - variant secrets-error { - // This indicates an error from an "upstream" secrets source. - // As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), - // the error message is a string. - upstream(string), - // This indicates an error from an I/O operation. - // As this could be almost _anything_ (such as a file read, network connection, etc), - // the error message is a string. - // Depending on how this ends up being consumed, - // we may consider moving this to use the `wasi:io/error` type instead. - // For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - // This indicates that the secret was not found. Generally "not found" errors will - // be handled by the upstream secrets backend, but there are cases where the host - // may need to return this error. - not-found, - } - - // A secret value can be either a string or a byte array, which lets you - // store binary data as a secret. - variant secret-value { - // A string value - %string(string), - // A byte array value - bytes(list), - } - - // A secret is a resource that can only be borrowed. This allows you to - // pass around handles to secrets and not reveal the values until a - // component needs them. - // You need to use the reveal interface to get the value. - resource secret; - - // Gets a single opaque secrets value set at the given key if it exists - get: func( - // A string key to fetch - key: string, - ) -> result; - -} - -interface reveal { - use store.{secret, secret-value}; - - // Reveals the value of a secret to the caller. - // This lets you easily audit your code to discover where secrets are being used. - reveal: func(s: borrow) -> secret-value; -} diff --git a/_examples/http-client/wit/deps/sockets/instance-network.wit b/_examples/http-client/wit/deps/sockets/instance-network.wit deleted file mode 100644 index e455d0f..0000000 --- a/_examples/http-client/wit/deps/sockets/instance-network.wit +++ /dev/null @@ -1,9 +0,0 @@ - -/// This interface provides a value-export of the default network handle.. -interface instance-network { - use network.{network}; - - /// Get a handle to the default network. - instance-network: func() -> network; - -} diff --git a/_examples/http-client/wit/deps/sockets/ip-name-lookup.wit b/_examples/http-client/wit/deps/sockets/ip-name-lookup.wit deleted file mode 100644 index 8e639ec..0000000 --- a/_examples/http-client/wit/deps/sockets/ip-name-lookup.wit +++ /dev/null @@ -1,51 +0,0 @@ - -interface ip-name-lookup { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-address}; - - - /// Resolve an internet host name to a list of IP addresses. - /// - /// Unicode domain names are automatically converted to ASCII using IDNA encoding. - /// If the input is an IP address string, the address is parsed and returned - /// as-is without making any external requests. - /// - /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. - /// - /// This function never blocks. It either immediately fails or immediately - /// returns successfully with a `resolve-address-stream` that can be used - /// to (asynchronously) fetch the results. - /// - /// # Typical errors - /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. - /// - /// # References: - /// - - /// - - /// - - /// - - resolve-addresses: func(network: borrow, name: string) -> result; - - resource resolve-address-stream { - /// Returns the next address from the resolver. - /// - /// This function should be called multiple times. On each call, it will - /// return the next address in connection order preference. If all - /// addresses have been exhausted, this function returns `none`. - /// - /// This function never returns IPv4-mapped IPv6 addresses. - /// - /// # Typical errors - /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) - /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) - /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) - /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) - resolve-next-address: func() -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/http-client/wit/deps/sockets/network.wit b/_examples/http-client/wit/deps/sockets/network.wit deleted file mode 100644 index 9cadf06..0000000 --- a/_examples/http-client/wit/deps/sockets/network.wit +++ /dev/null @@ -1,145 +0,0 @@ - -interface network { - /// An opaque resource that represents access to (a subset of) the network. - /// This enables context-based security for networking. - /// There is no need for this to map 1:1 to a physical network interface. - resource network; - - /// Error codes. - /// - /// In theory, every API can return any error code. - /// In practice, API's typically only return the errors documented per API - /// combined with a couple of errors that are always possible: - /// - `unknown` - /// - `access-denied` - /// - `not-supported` - /// - `out-of-memory` - /// - `concurrency-conflict` - /// - /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. - enum error-code { - /// Unknown error - unknown, - - /// Access denied. - /// - /// POSIX equivalent: EACCES, EPERM - access-denied, - - /// The operation is not supported. - /// - /// POSIX equivalent: EOPNOTSUPP - not-supported, - - /// One of the arguments is invalid. - /// - /// POSIX equivalent: EINVAL - invalid-argument, - - /// Not enough memory to complete the operation. - /// - /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY - out-of-memory, - - /// The operation timed out before it could finish completely. - timeout, - - /// This operation is incompatible with another asynchronous operation that is already in progress. - /// - /// POSIX equivalent: EALREADY - concurrency-conflict, - - /// Trying to finish an asynchronous operation that: - /// - has not been started yet, or: - /// - was already finished by a previous `finish-*` call. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - not-in-progress, - - /// The operation has been aborted because it could not be completed immediately. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - would-block, - - - /// The operation is not valid in the socket's current state. - invalid-state, - - /// A new socket resource could not be created because of a system limit. - new-socket-limit, - - /// A bind operation failed because the provided address is not an address that the `network` can bind to. - address-not-bindable, - - /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. - address-in-use, - - /// The remote address is not reachable - remote-unreachable, - - - /// The TCP connection was forcefully rejected - connection-refused, - - /// The TCP connection was reset. - connection-reset, - - /// A TCP connection was aborted. - connection-aborted, - - - /// The size of a datagram sent to a UDP socket exceeded the maximum - /// supported size. - datagram-too-large, - - - /// Name does not exist or has no suitable associated IP addresses. - name-unresolvable, - - /// A temporary failure in name resolution occurred. - temporary-resolver-failure, - - /// A permanent failure in name resolution occurred. - permanent-resolver-failure, - } - - enum ip-address-family { - /// Similar to `AF_INET` in POSIX. - ipv4, - - /// Similar to `AF_INET6` in POSIX. - ipv6, - } - - type ipv4-address = tuple; - type ipv6-address = tuple; - - variant ip-address { - ipv4(ipv4-address), - ipv6(ipv6-address), - } - - record ipv4-socket-address { - /// sin_port - port: u16, - /// sin_addr - address: ipv4-address, - } - - record ipv6-socket-address { - /// sin6_port - port: u16, - /// sin6_flowinfo - flow-info: u32, - /// sin6_addr - address: ipv6-address, - /// sin6_scope_id - scope-id: u32, - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - -} diff --git a/_examples/http-client/wit/deps/sockets/tcp-create-socket.wit b/_examples/http-client/wit/deps/sockets/tcp-create-socket.wit deleted file mode 100644 index c7ddf1f..0000000 --- a/_examples/http-client/wit/deps/sockets/tcp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface tcp-create-socket { - use network.{network, error-code, ip-address-family}; - use tcp.{tcp-socket}; - - /// 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`/`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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - create-tcp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/http-client/wit/deps/sockets/tcp.wit b/_examples/http-client/wit/deps/sockets/tcp.wit deleted file mode 100644 index 5902b9e..0000000 --- a/_examples/http-client/wit/deps/sockets/tcp.wit +++ /dev/null @@ -1,353 +0,0 @@ - -interface tcp { - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/poll@0.2.0.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0.{duration}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - enum shutdown-type { - /// Similar to `SHUT_RD` in POSIX. - receive, - - /// Similar to `SHUT_WR` in POSIX. - send, - - /// Similar to `SHUT_RDWR` in POSIX. - both, - } - - /// A TCP socket resource. - /// - /// The socket can be in one of the following states: - /// - `unbound` - /// - `bind-in-progress` - /// - `bound` (See note below) - /// - `listen-in-progress` - /// - `listening` - /// - `connect-in-progress` - /// - `connected` - /// - `closed` - /// See - /// for a more information. - /// - /// Note: Except where explicitly mentioned, whenever this documentation uses - /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. - /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) - /// - /// In addition to the general error codes documented on the - /// `network::error-code` type, TCP socket methods may always return - /// `error(invalid-state)` when in the `closed` state. - resource tcp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the TCP/UDP port is zero, the socket will be bound to a random free port. - /// - /// Bind can be attempted multiple times on the same socket, even with - /// different arguments on each iteration. But never concurrently and - /// only as long as the previous bind failed. Once a bind succeeds, the - /// binding can't be changed anymore. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) - /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT - /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR - /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior - /// and SO_REUSEADDR performs something different entirely. - /// - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Connect to a remote endpoint. - /// - /// On success: - /// - the socket is transitioned into the `connection` state. - /// - a pair of streams is returned that can be used to read & write to the connection - /// - /// After a failed connection attempt, the socket will be in the `closed` - /// state and the only valid action left is to `drop` the socket. A single - /// socket can not be used to connect more than once. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) - /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) - /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) - /// - `timeout`: Connection timed out. (ETIMEDOUT) - /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) - /// - `connection-reset`: The connection was reset. (ECONNRESET) - /// - `connection-aborted`: The connection was aborted. (ECONNABORTED) - /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `not-in-progress`: A connect operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// The POSIX equivalent of `start-connect` is the regular `connect` syscall. - /// Because all WASI sockets are non-blocking this is expected to return - /// EINPROGRESS, which should be translated to `ok()` in WASI. - /// - /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` - /// with a timeout of 0 on the socket descriptor. Followed by a check for - /// the `SO_ERROR` socket option, in case the poll signaled readiness. - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: func() -> result, error-code>; - - /// Start listening for new connections. - /// - /// Transitions the socket into the `listening` state. - /// - /// Unlike POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the `listening` state. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) - /// - `not-in-progress`: A listen operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the listen operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `listen` as part of either `start-listen` or `finish-listen`. - /// - /// # References - /// - - /// - - /// - - /// - - start-listen: func() -> result<_, error-code>; - finish-listen: func() -> result<_, error-code>; - - /// Accept a new client socket. - /// - /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `keep-alive-enabled` - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// - `hop-limit` - /// - `receive-buffer-size` - /// - `send-buffer-size` - /// - /// On success, this function returns the newly accepted client socket along with - /// a pair of streams that can be used to read & write to the connection. - /// - /// # Typical errors - /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) - /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) - /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - accept: func() -> result, error-code>; - - /// Get the bound local address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the remote address. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether the socket is in the `listening` state. - /// - /// Equivalent to the SO_ACCEPTCONN socket option. - is-listening: func() -> bool; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Hints the desired listen queue size. Implementations are free to ignore this. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// - /// # Typical errors - /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - /// - `invalid-argument`: (set) The provided value was 0. - /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. - set-listen-backlog-size: func(value: u64) -> result<_, error-code>; - - /// Enables or disables keepalive. - /// - /// The keepalive behavior can be adjusted using: - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. - /// - /// Equivalent to the SO_KEEPALIVE socket option. - keep-alive-enabled: func() -> result; - set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; - - /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-idle-time: func() -> result; - set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; - - /// The time between keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPINTVL socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-interval: func() -> result; - set-keep-alive-interval: func(value: duration) -> result<_, error-code>; - - /// The maximum amount of keepalive packets TCP should send before aborting the connection. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPCNT socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-count: func() -> result; - set-keep-alive-count: func(value: u32) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - hop-limit: func() -> result; - set-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which can be used to poll for, or block on, - /// completion of any of the asynchronous operations of this socket. - /// - /// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` - /// return `error(would-block)`, this pollable can be used to wait for - /// their success or failure, after which the method can be retried. - /// - /// The pollable is not limited to the async operation that happens to be - /// in progress at the time of calling `subscribe` (if any). Theoretically, - /// `subscribe` only has to be called once per socket and can then be - /// (re)used for the remainder of the socket's lifetime. - /// - /// See - /// for a more information. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - - /// Initiate a graceful shutdown. - /// - /// - `receive`: The socket is not expecting to receive any data from - /// the peer. The `input-stream` associated with this socket will be - /// closed. Any data still in the receive queue at time of calling - /// this method will be discarded. - /// - `send`: The socket has no more data to send to the peer. The `output-stream` - /// associated with this socket will be closed and a FIN packet will be sent. - /// - `both`: Same effect as `receive` & `send` combined. - /// - /// This function is idempotent. Shutting a down a direction more than once - /// has no effect and returns `ok`. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } -} diff --git a/_examples/http-client/wit/deps/sockets/udp-create-socket.wit b/_examples/http-client/wit/deps/sockets/udp-create-socket.wit deleted file mode 100644 index 0482d1f..0000000 --- a/_examples/http-client/wit/deps/sockets/udp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface udp-create-socket { - use network.{network, error-code, ip-address-family}; - use udp.{udp-socket}; - - /// Create a new UDP socket. - /// - /// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References: - /// - - /// - - /// - - /// - - create-udp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/http-client/wit/deps/sockets/udp.wit b/_examples/http-client/wit/deps/sockets/udp.wit deleted file mode 100644 index d987a0a..0000000 --- a/_examples/http-client/wit/deps/sockets/udp.wit +++ /dev/null @@ -1,266 +0,0 @@ - -interface udp { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - /// A received datagram. - record incoming-datagram { - /// The payload. - /// - /// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - data: list, - - /// The source address. - /// - /// This field is guaranteed to match the remote address the stream was initialized with, if any. - /// - /// Equivalent to the `src_addr` out parameter of `recvfrom`. - remote-address: ip-socket-address, - } - - /// A datagram to be sent out. - record outgoing-datagram { - /// The payload. - data: list, - - /// The destination address. - /// - /// The requirements on this field depend on how the stream was initialized: - /// - with a remote address: this field must be None or match the stream's remote address exactly. - /// - without a remote address: this field is required. - /// - /// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. - remote-address: option, - } - - - - /// A UDP socket handle. - resource udp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the port is zero, the socket will be bound to a random free port. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Set up inbound & outbound communication channels, optionally to a specific peer. - /// - /// This function only changes the local socket configuration and does not generate any network traffic. - /// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, - /// based on the best network path to `remote-address`. - /// - /// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: - /// - `send` can only be used to send to this destination. - /// - `receive` will only return datagrams sent from the provided `remote-address`. - /// - /// This method may be called multiple times on the same socket to change its association, but - /// only the most recently returned pair of streams will be operational. Implementations may trap if - /// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. - /// - /// The POSIX equivalent in pseudo-code is: - /// ```text - /// if (was previously connected) { - /// connect(s, AF_UNSPEC) - /// } - /// if (remote_address is Some) { - /// connect(s, remote_address) - /// } - /// ``` - /// - /// Unlike in POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-state`: The socket is not bound. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - %stream: func(remote-address: option) -> result, error-code>; - - /// Get the current bound address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the address the socket is currently streaming to. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - unicast-hop-limit: func() -> result; - set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which will resolve once the socket is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource incoming-datagram-stream { - /// Receive messages on the socket. - /// - /// This function attempts to receive up to `max-results` datagrams on the socket without blocking. - /// The returned list may contain fewer elements than requested, but never more. - /// - /// This function returns successfully with an empty list when either: - /// - `max-results` is 0, or: - /// - `max-results` is greater than 0, but no results are immediately available. - /// This function never returns `error(would-block)`. - /// - /// # Typical errors - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - receive: func(max-results: u64) -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready to receive again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource outgoing-datagram-stream { - /// Check readiness for sending. This function never blocks. - /// - /// Returns the number of datagrams permitted for the next call to `send`, - /// or an error. Calling `send` with more datagrams than this function has - /// permitted will trap. - /// - /// When this function returns ok(0), the `subscribe` pollable will - /// become ready when this function will report at least ok(1), or an - /// error. - /// - /// Never returns `would-block`. - check-send: func() -> result; - - /// Send messages on the socket. - /// - /// This function attempts to send all provided `datagrams` on the socket without blocking and - /// returns how many messages were actually sent (or queued for sending). This function never - /// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. - /// - /// This function semantically behaves the same as iterating the `datagrams` list and sequentially - /// sending each individual datagram until either the end of the list has been reached or the first error occurred. - /// If at least one datagram has been sent successfully, this function never returns an error. - /// - /// If the input list is empty, the function returns `ok(0)`. - /// - /// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if - /// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) - /// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - send: func(datagrams: list) -> result; - - /// Create a `pollable` which will resolve once the stream is ready to send again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/http-client/wit/deps/sockets/world.wit b/_examples/http-client/wit/deps/sockets/world.wit deleted file mode 100644 index f8bb92a..0000000 --- a/_examples/http-client/wit/deps/sockets/world.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi:sockets@0.2.0; - -world imports { - import instance-network; - import network; - import udp; - import udp-create-socket; - import tcp; - import tcp-create-socket; - import ip-name-lookup; -} diff --git a/_examples/http-client/wit/deps/wasi-cli-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-cli-0.2.0/package.wit new file mode 100644 index 0000000..0a2737b --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-cli-0.2.0/package.wit @@ -0,0 +1,159 @@ +package wasi:cli@0.2.0; + +interface environment { + /// Get the POSIX-style environment variables. + /// + /// Each environment variable is provided as a pair of string variable names + /// and string value. + /// + /// Morally, these are a value import, but until value imports are available + /// in the component model, this import function should return the same + /// values each time it is called. + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + initial-cwd: func() -> option; +} + +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} + +interface run { + /// Run the program. + run: func() -> result; +} + +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} + +/// Terminal input. +/// +/// In the future, this may include functions for disabling echoing, +/// disabling input buffering so that keyboard events are sent through +/// immediately, querying supported features, and so on. +interface terminal-input { + /// The input side of a terminal. + resource terminal-input; +} + +/// Terminal output. +/// +/// In the future, this may include functions for querying the terminal +/// size, being notified of terminal size changes, querying supported +/// features, and so on. +interface terminal-output { + /// The output side of a terminal. + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +interface terminal-stdin { + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +interface terminal-stdout { + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +interface terminal-stderr { + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stderr: func() -> option; +} + +world imports { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; +} +world command { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; + + export run; +} diff --git a/_examples/http-client/wit/deps/wasi-clocks-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-clocks-0.2.0/package.wit new file mode 100644 index 0000000..9e0ba3d --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-clocks-0.2.0/package.wit @@ -0,0 +1,29 @@ +package wasi:clocks@0.2.0; + +interface monotonic-clock { + use wasi:io/poll@0.2.0.{pollable}; + + type instant = u64; + + type duration = u64; + + now: func() -> instant; + + resolution: func() -> duration; + + subscribe-instant: func(when: instant) -> pollable; + + subscribe-duration: func(when: duration) -> pollable; +} + +interface wall-clock { + record datetime { + seconds: u64, + nanoseconds: u32, + } + + now: func() -> datetime; + + resolution: func() -> datetime; +} + diff --git a/_examples/http-client/wit/deps/wasi-config-0.2.0-draft/package.wit b/_examples/http-client/wit/deps/wasi-config-0.2.0-draft/package.wit new file mode 100644 index 0000000..7065b9b --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-config-0.2.0-draft/package.wit @@ -0,0 +1,28 @@ +package wasi:config@0.2.0-draft; + +interface runtime { + /// An error type that encapsulates the different errors that can occur fetching config + variant config-error { + /// This indicates an error from an "upstream" config source. + /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + } + + /// Gets a single opaque config value set at the given key if it exists + get: func(key: string) -> result, config-error>; + + /// Gets a list of all set config data + get-all: func() -> result>, config-error>; +} + +world imports { + import runtime; +} diff --git a/_examples/http-client/wit/deps/wasi-filesystem-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-filesystem-0.2.0/package.wit new file mode 100644 index 0000000..cb6a2be --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-filesystem-0.2.0/package.wit @@ -0,0 +1,158 @@ +package wasi:filesystem@0.2.0; + +interface types { + use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0.{datetime}; + + type filesize = u64; + + enum descriptor-type { + unknown, + block-device, + character-device, + directory, + fifo, + symbolic-link, + regular-file, + socket, + } + + flags descriptor-flags { + read, + write, + file-integrity-sync, + data-integrity-sync, + requested-write-sync, + mutate-directory, + } + + flags path-flags { + symlink-follow, + } + + flags open-flags { + create, + directory, + exclusive, + truncate, + } + + type link-count = u64; + + record descriptor-stat { + %type: descriptor-type, + link-count: link-count, + size: filesize, + data-access-timestamp: option, + data-modification-timestamp: option, + status-change-timestamp: option, + } + + variant new-timestamp { + no-change, + now, + timestamp(datetime), + } + + record directory-entry { + %type: descriptor-type, + name: string, + } + + enum error-code { + 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, + } + + enum advice { + normal, + sequential, + random, + will-need, + dont-need, + no-reuse, + } + + record metadata-hash-value { + lower: u64, + upper: u64, + } + + resource descriptor { + read-via-stream: func(offset: filesize) -> result; + write-via-stream: func(offset: filesize) -> result; + append-via-stream: func() -> result; + advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>; + sync-data: func() -> result<_, error-code>; + get-flags: func() -> result; + get-type: func() -> result; + set-size: func(size: filesize) -> result<_, error-code>; + set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + read: func(length: filesize, offset: filesize) -> result, bool>, error-code>; + write: func(buffer: list, offset: filesize) -> result; + read-directory: func() -> result; + sync: func() -> result<_, error-code>; + create-directory-at: func(path: string) -> result<_, error-code>; + stat: func() -> result; + stat-at: func(path-flags: path-flags, path: string) -> result; + set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result; + readlink-at: func(path: string) -> result; + remove-directory-at: func(path: string) -> result<_, error-code>; + rename-at: func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + symlink-at: func(old-path: string, new-path: string) -> result<_, error-code>; + unlink-file-at: func(path: string) -> result<_, error-code>; + is-same-object: func(other: borrow) -> bool; + metadata-hash: func() -> result; + metadata-hash-at: func(path-flags: path-flags, path: string) -> result; + } + + resource directory-entry-stream { + read-directory-entry: func() -> result, error-code>; + } + + filesystem-error-code: func(err: borrow) -> option; +} + +interface preopens { + use types.{descriptor}; + + get-directories: func() -> list>; +} + diff --git a/_examples/http-server/wit/deps/http/types.wit b/_examples/http-client/wit/deps/wasi-http-0.2.0/package.wit similarity index 88% rename from _examples/http-server/wit/deps/http/types.wit rename to _examples/http-client/wit/deps/wasi-http-0.2.0/package.wit index 755ac6a..11f7ff4 100644 --- a/_examples/http-server/wit/deps/http/types.wit +++ b/_examples/http-client/wit/deps/wasi-http-0.2.0/package.wit @@ -1,3 +1,5 @@ +package wasi:http@0.2.0; + /// 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. @@ -18,18 +20,36 @@ interface types { options, trace, patch, - other(string) + other(string), } /// This type corresponds to HTTP standard Related Schemes. variant scheme { HTTP, HTTPS, - other(string) + other(string), + } + + /// Defines the case payload type for `DNS-error` above: + record DNS-error-payload { + rcode: option, + info-code: option, + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option, } /// 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 + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types variant error-code { DNS-timeout, DNS-error(DNS-error-payload), @@ -74,40 +94,9 @@ interface types { /// unstructured description of the error. Users should not depend on the /// string for diagnosing errors, as it's not required to be consistent /// between implementations. - internal-error(option) - } - - /// Defines the case payload type for `DNS-error` above: - record DNS-error-payload { - rcode: option, - info-code: option - } - - /// Defines the case payload type for `TLS-alert-received` above: - record TLS-alert-received-payload { - alert-id: option, - alert-message: option - } - - /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: - record field-size-payload { - field-name: option, - field-size: option + internal-error(option), } - /// Attempts to extract a http-related `error` from the wasi:io `error` - /// provided. - /// - /// Stream operations which return - /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of - /// type `wasi:io/error/error` with more information about the operation - /// that failed. This payload can be passed through to this function to see - /// if there's http-related information about the error to return. - /// - /// Note that this function is fallible because not all io-errors are - /// http-related errors. - 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. variant header-error { @@ -115,11 +104,9 @@ interface types { /// syntactically invalid when used with an operation that sets headers in a /// `fields`. invalid-syntax, - /// This error indicates that a forbidden `field-key` was used when trying /// to set a header in a `fields`. forbidden, - /// This error indicates that the operation on the `fields` was not /// permitted because the fields are immutable. immutable, @@ -144,12 +131,10 @@ interface types { /// immutable. In an immutable fields, the `set`, `append`, and `delete` /// operations will fail with `header-error.immutable`. resource fields { - /// Construct an empty HTTP Fields. /// /// The resulting `fields` is mutable. constructor(); - /// Construct an HTTP Fields. /// /// The resulting `fields` is mutable. @@ -165,46 +150,37 @@ interface types { /// /// An error result will be returned if any header or value was /// syntactically invalid, or if a header was forbidden. - from-list: static func( - entries: list> - ) -> result; - + from-list: static func(entries: list>) -> result; /// Get all of the values corresponding to a key. If the key is not present /// in this `fields`, 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. 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. has: func(name: field-key) -> bool; - /// Set all of the values for a key. Clears any existing values for that /// key, if they have been set. /// /// Fails with `header-error.immutable` if the `fields` are immutable. set: func(name: field-key, value: list) -> result<_, header-error>; - /// Delete all values for a key. Does nothing if no values for the key /// exist. /// /// Fails with `header-error.immutable` if the `fields` are immutable. delete: func(name: field-key) -> result<_, header-error>; - /// Append a value for a key. Does not change or delete any existing /// values for that key. /// /// Fails with `header-error.immutable` if the `fields` are immutable. append: func(name: field-key, value: field-value) -> result<_, header-error>; - /// 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 /// which have multiple values are represented by multiple entries in this /// list with the same key. - entries: func() -> list>; - + entries: func() -> list>; /// Make a deep copy of the Fields. Equivelant in behavior to calling the /// `fields` constructor on the return value of `entries`. The resulting /// `fields` is mutable. @@ -219,19 +195,14 @@ interface types { /// Represents an incoming HTTP Request. resource incoming-request { - /// Returns the method of the incoming request. method: func() -> method; - /// Returns the path with query parameters from the request, as a string. path-with-query: func() -> option; - /// Returns the protocol scheme from the request. scheme: func() -> option; - /// Returns the authority from the request, if it was present. authority: func() -> option; - /// Get the `headers` associated with the request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -241,7 +212,6 @@ interface types { /// the parent `incoming-request` is dropped. Dropping this /// `incoming-request` before all children are dropped will trap. headers: func() -> headers; - /// Gives the `incoming-body` associated with this request. Will only /// return success at most once, and subsequent calls will return error. consume: func() -> result; @@ -249,7 +219,6 @@ interface types { /// Represents an outgoing HTTP Request. resource outgoing-request { - /// Construct a new `outgoing-request` with a default `method` of `GET`, and /// `none` values for `path-with-query`, `scheme`, and `authority`. /// @@ -260,10 +229,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`. - constructor( - headers: headers - ); - + constructor(headers: headers); /// Returns the resource corresponding to the outgoing Body for this /// Request. /// @@ -271,13 +237,11 @@ interface types { /// this `outgoing-request` can be retrieved at most once. Subsequent /// calls will return error. body: func() -> result; - /// Get the Method for the Request. 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. 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. path-with-query: func() -> option; @@ -285,7 +249,6 @@ interface types { /// 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-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. scheme: func() -> option; @@ -293,7 +256,6 @@ interface types { /// implementation may choose an appropriate default scheme. Fails if the /// string given is not a syntactically valid uri scheme. 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. @@ -303,7 +265,6 @@ interface types { /// HTTPS schemes always require an authority. Fails if the string given is /// not a syntactically valid uri authority. set-authority: func(authority: option) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -324,25 +285,19 @@ interface types { resource request-options { /// Construct a default `request-options` value. constructor(); - /// The timeout for the initial connect to the HTTP Server. 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. set-connect-timeout: func(duration: option) -> result; - /// The timeout for receiving the first byte of the Response body. 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. set-first-byte-timeout: func(duration: option) -> result; - /// The timeout for receiving subsequent chunks of bytes in the Response /// body stream. 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. @@ -355,7 +310,6 @@ interface types { /// allow a Response to be sent corresponding to the Request provided as the /// other argument to `incoming-handler.handle`. resource response-outparam { - /// Set the value of the `response-outparam` to either send a response, /// or indicate an error. /// @@ -365,10 +319,7 @@ interface types { /// /// The user may provide an `error` to `response` to allow the /// implementation determine how to respond with an HTTP error response. - set: static func( - param: response-outparam, - response: result, - ); + set: static func(param: response-outparam, response: result); } /// This type corresponds to the HTTP standard Status Code. @@ -376,10 +327,8 @@ interface types { /// Represents an incoming HTTP Response. resource incoming-response { - /// Returns the status code from the incoming response. status: func() -> status-code; - /// Returns the headers from the incoming response. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -388,7 +337,6 @@ interface types { /// This headers resource is a child: it must be dropped before the parent /// `incoming-response` is dropped. headers: func() -> headers; - /// Returns the incoming body. May be called at most once. Returns error /// if called additional times. consume: func() -> result; @@ -403,7 +351,6 @@ interface types { /// and ensures that the user of this interface may only be consuming either /// the body contents or waiting on trailers at any given time. resource incoming-body { - /// Returns the contents of the body, as a stream of bytes. /// /// Returns success on first call: the stream representing the contents @@ -420,7 +367,6 @@ interface types { /// and for that backpressure to not inhibit delivery of the trailers if /// the user does not read the entire body. %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. finish: static func(this: incoming-body) -> future-trailers; @@ -432,12 +378,10 @@ interface types { /// trailers, this future will resolve to the empty set of trailers once the /// complete Request or Response body has been received. resource future-trailers { - /// Returns a pollable which becomes ready when either the trailers have /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the contents of the trailers, or an error which occured, /// once the future is ready. /// @@ -462,21 +406,17 @@ interface types { /// Represents an outgoing HTTP Response. resource outgoing-response { - /// Construct an `outgoing-response`, with a default `status-code` of `200`. /// If a different `status-code` is needed, it must be set via the /// `set-status-code` method. /// /// * `headers` is the HTTP Headers for the Response. constructor(headers: headers); - /// Get the HTTP Status Code for the Response. 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. set-status-code: func(status-code: status-code) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -486,7 +426,6 @@ interface types { /// `outgoing-request` is dropped, or its ownership is transfered to /// another component by e.g. `outgoing-handler.handle`. headers: func() -> headers; - /// Returns the resource corresponding to the outgoing Body for this Response. /// /// Returns success on the first call: the `outgoing-body` resource for @@ -512,7 +451,6 @@ interface types { /// including: corrupting the body on the wire, aborting the associated /// Request, or sending a late status code for the Response. resource outgoing-body { - /// Returns a stream for writing the body contents. /// /// The returned `output-stream` is a child resource: it must be dropped @@ -523,7 +461,6 @@ interface types { /// this `outgoing-body` may be retrieved at most once. Subsequent calls /// will return error. write: func() -> result; - /// 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 @@ -533,10 +470,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. - finish: static func( - this: outgoing-body, - trailers: option - ) -> result<_, error-code>; + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; } /// Represents a future which may eventaully return an incoming HTTP @@ -549,7 +483,6 @@ interface types { /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the incoming HTTP Response, or an error, once one is ready. /// /// The outer `option` represents future readiness. Users can wait on this @@ -565,6 +498,74 @@ interface types { /// but those will be reported by the `incoming-body` and its /// `output-stream` child. get: func() -> option>>; - } + + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + http-error-code: func(err: borrow) -> option; +} + +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// 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. + handle: func(request: incoming-request, response-out: response-outparam); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error-code}; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// 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`. + handle: func(request: outgoing-request, options: option) -> result; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// 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. +world proxy { + import wasi:random/random@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import types; + import outgoing-handler; + import wasi:clocks/wall-clock@0.2.0; + + export incoming-handler; } diff --git a/_examples/http-client/wit/deps/wasi-io-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-io-0.2.0/package.wit new file mode 100644 index 0000000..1840029 --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-io-0.2.0/package.wit @@ -0,0 +1,48 @@ +package wasi:io@0.2.0; + +interface error { + resource error { + to-debug-string: func() -> string; + } +} + +interface poll { + resource pollable { + ready: func() -> bool; + block: func(); + } + + poll: func(in: list>) -> list; +} + +interface streams { + use error.{error}; + use poll.{pollable}; + + variant stream-error { + last-operation-failed(error), + closed, + } + + resource input-stream { + read: func(len: u64) -> result, stream-error>; + blocking-read: func(len: u64) -> result, stream-error>; + skip: func(len: u64) -> result; + blocking-skip: func(len: u64) -> result; + subscribe: func() -> pollable; + } + + resource output-stream { + check-write: func() -> result; + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) -> result<_, stream-error>; + flush: func() -> result<_, stream-error>; + blocking-flush: func() -> result<_, stream-error>; + subscribe: func() -> pollable; + write-zeroes: func(len: u64) -> result<_, stream-error>; + blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>; + splice: func(src: borrow, len: u64) -> result; + blocking-splice: func(src: borrow, len: u64) -> result; + } +} + diff --git a/_examples/http-client/wit/deps/wasi-logging-0.1.0-draft/package.wit b/_examples/http-client/wit/deps/wasi-logging-0.1.0-draft/package.wit new file mode 100644 index 0000000..df4e8de --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-logging-0.1.0-draft/package.wit @@ -0,0 +1,36 @@ +package wasi:logging; + +/// WASI Logging is a logging API intended to let users emit log messages with +/// simple priority levels and context values. +interface logging { + /// A log level, describing a kind of message. + enum level { + /// Describes messages about the values of variables and the flow of + /// control within a program. + trace, + /// Describes messages likely to be of interest to someone debugging a + /// program. + debug, + /// Describes messages likely to be of interest to someone monitoring a + /// program. + info, + /// Describes messages indicating hazardous situations. + warn, + /// Describes messages indicating serious errors. + error, + /// Describes messages indicating fatal errors. + critical, + } + + /// Emit a log message. + /// + /// A log message has a `level` describing what kind of message is being + /// sent, a context, which is an uninterpreted string meant to help + /// consumers group similar messages, and a string containing the message + /// text. + log: func(level: level, context: string, message: string); +} + +world imports { + import logging; +} diff --git a/_examples/http-client/wit/deps/wasi-random-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-random-0.2.0/package.wit new file mode 100644 index 0000000..58c179e --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-random-0.2.0/package.wit @@ -0,0 +1,18 @@ +package wasi:random@0.2.0; + +interface random { + get-random-bytes: func(len: u64) -> list; + + get-random-u64: func() -> u64; +} + +interface insecure { + get-insecure-random-bytes: func(len: u64) -> list; + + get-insecure-random-u64: func() -> u64; +} + +interface insecure-seed { + insecure-seed: func() -> tuple; +} + diff --git a/_examples/http-client/wit/deps/wasi-sockets-0.2.0/package.wit b/_examples/http-client/wit/deps/wasi-sockets-0.2.0/package.wit new file mode 100644 index 0000000..0602b85 --- /dev/null +++ b/_examples/http-client/wit/deps/wasi-sockets-0.2.0/package.wit @@ -0,0 +1,179 @@ +package wasi:sockets@0.2.0; + +interface network { + resource network; + + enum error-code { + unknown, + access-denied, + not-supported, + invalid-argument, + out-of-memory, + timeout, + concurrency-conflict, + not-in-progress, + would-block, + invalid-state, + new-socket-limit, + address-not-bindable, + address-in-use, + remote-unreachable, + connection-refused, + connection-reset, + connection-aborted, + datagram-too-large, + name-unresolvable, + temporary-resolver-failure, + permanent-resolver-failure, + } + + enum ip-address-family { + ipv4, + ipv6, + } + + type ipv4-address = tuple; + + type ipv6-address = tuple; + + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + record ipv4-socket-address { + port: u16, + address: ipv4-address, + } + + record ipv6-socket-address { + port: u16, + flow-info: u32, + address: ipv6-address, + scope-id: u32, + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } +} + +interface instance-network { + use network.{network}; + + instance-network: func() -> network; +} + +interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + record incoming-datagram { + data: list, + remote-address: ip-socket-address, + } + + record outgoing-datagram { + data: list, + remote-address: option, + } + + resource udp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + %stream: func(remote-address: option) -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + address-family: func() -> ip-address-family; + unicast-hop-limit: func() -> result; + set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + } + + resource incoming-datagram-stream { + receive: func(max-results: u64) -> result, error-code>; + subscribe: func() -> pollable; + } + + resource outgoing-datagram-stream { + check-send: func() -> result; + send: func(datagrams: list) -> result; + subscribe: func() -> pollable; + } +} + +interface udp-create-socket { + use network.{network, error-code, ip-address-family}; + use udp.{udp-socket}; + + create-udp-socket: func(address-family: ip-address-family) -> result; +} + +interface tcp { + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/poll@0.2.0.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + enum shutdown-type { + receive, + send, + both, + } + + resource tcp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + finish-connect: func() -> result, error-code>; + start-listen: func() -> result<_, error-code>; + finish-listen: func() -> result<_, error-code>; + accept: func() -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + is-listening: func() -> bool; + address-family: func() -> ip-address-family; + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + keep-alive-enabled: func() -> result; + set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; + keep-alive-idle-time: func() -> result; + set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; + keep-alive-interval: func() -> result; + set-keep-alive-interval: func(value: duration) -> result<_, error-code>; + keep-alive-count: func() -> result; + set-keep-alive-count: func(value: u32) -> result<_, error-code>; + hop-limit: func() -> result; + set-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} + +interface tcp-create-socket { + use network.{network, error-code, ip-address-family}; + use tcp.{tcp-socket}; + + create-tcp-socket: func(address-family: ip-address-family) -> result; +} + +interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-address}; + + resource resolve-address-stream { + resolve-next-address: func() -> result, error-code>; + subscribe: func() -> pollable; + } + + resolve-addresses: func(network: borrow, name: string) -> result; +} + diff --git a/_examples/http-client/wit/deps/wasmcloud-bus-1.0.0/package.wit b/_examples/http-client/wit/deps/wasmcloud-bus-1.0.0/package.wit new file mode 100644 index 0000000..1008a6f --- /dev/null +++ b/_examples/http-client/wit/deps/wasmcloud-bus-1.0.0/package.wit @@ -0,0 +1,15 @@ +package wasmcloud:bus@1.0.0; + +interface lattice { + /// Interface target. This represents an interface, which can be selected by `set-link-name`. + resource call-target-interface { + constructor(namespace: string, %package: string, %interface: string); + } + + /// Set an optional link name to use for all interfaces specified. This is advanced + /// functionality only available within wasmcloud and, as such, is exposed here as part of the + /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces + /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component + set-link-name: func(name: string, interfaces: list); +} + diff --git a/_examples/http-server/wit/deps/component/world.wit b/_examples/http-client/wit/deps/wasmcloud-component-go/world.wit similarity index 77% rename from _examples/http-server/wit/deps/component/world.wit rename to _examples/http-client/wit/deps/wasmcloud-component-go/world.wit index 186845a..f881ff8 100644 --- a/_examples/http-server/wit/deps/component/world.wit +++ b/_examples/http-client/wit/deps/wasmcloud-component-go/world.wit @@ -1,11 +1,8 @@ -package wasmcloud:component; +package wasmcloud:component-go@0.1.0; world exports { // wasi export wasi:http/incoming-handler@0.2.0; - - // wasmcloud - export wasmcloud:messaging/handler@0.2.0; } world imports { @@ -19,7 +16,6 @@ world imports { // wasmcloud import wasmcloud:bus/lattice@1.0.0; - import wasmcloud:messaging/consumer@0.2.0; import wasmcloud:secrets/store@0.1.0-draft; import wasmcloud:secrets/reveal@0.1.0-draft; } diff --git a/_examples/http-client/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit b/_examples/http-client/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit new file mode 100644 index 0000000..a431b95 --- /dev/null +++ b/_examples/http-client/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit @@ -0,0 +1,52 @@ +/// This WIT interface powers secret support in wasmCloud +/// +/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 +package wasmcloud:secrets@0.1.0-draft; + +interface store { + /// An error type that encapsulates the different errors that can occur fetching secrets + variant secrets-error { + /// This indicates an error from an "upstream" secrets source. + /// As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + /// This indicates that the secret was not found. Generally "not found" errors will + /// be handled by the upstream secrets backend, but there are cases where the host + /// may need to return this error. + not-found, + } + + /// A secret value can be either a string or a byte array, which lets you + /// store binary data as a secret. + variant secret-value { + /// A string value + %string(string), + /// A byte array value + bytes(list), + } + + /// A secret is a resource that can only be borrowed. This allows you to + /// pass around handles to secrets and not reveal the values until a + /// component needs them. + /// You need to use the reveal interface to get the value. + resource secret; + + /// Gets a single opaque secrets value set at the given key if it exists + get: func(key: string) -> result; +} + +interface reveal { + use store.{secret, secret-value}; + + /// Reveals the value of a secret to the caller. + /// This lets you easily audit your code to discover where secrets are being used. + reveal: func(s: borrow) -> secret-value; +} + diff --git a/_examples/http-client/wit/world.wit b/_examples/http-client/wit/world.wit index 2156a0e..7324736 100644 --- a/_examples/http-client/wit/world.wit +++ b/_examples/http-client/wit/world.wit @@ -1,7 +1,7 @@ package example:http-client; world example { - include wasmcloud:component/imports; + include wasmcloud:component-go/imports@0.1.0; import wasi:http/outgoing-handler@0.2.0; export wasi:http/incoming-handler@0.2.0; diff --git a/_examples/http-server/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/_examples/http-server/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go index 36b8c33..472d764 100644 --- a/_examples/http-server/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go +++ b/_examples/http-server/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -1,17 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". -// -// WASI Monotonic Clock is a clock API intended to let users measure elapsed -// time. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// 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. package monotonicclock import ( @@ -21,27 +10,16 @@ import ( // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". // -// 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. -// // type instant = u64 type Instant uint64 // Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". // -// A duration of time, in nanoseconds. -// // type duration = u64 type Duration uint64 // Now represents the imported function "now". // -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. -// // now: func() -> instant // //go:nosplit @@ -57,9 +35,6 @@ func wasmimport_Now() (result0 uint64) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. -// // resolution: func() -> duration // //go:nosplit @@ -75,9 +50,6 @@ func wasmimport_Resolution() (result0 uint64) // SubscribeInstant represents the imported function "subscribe-instant". // -// Create a `pollable` which will resolve once the specified instant -// occured. -// // subscribe-instant: func(when: instant) -> pollable // //go:nosplit @@ -94,10 +66,6 @@ func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. -// // subscribe-duration: func(when: duration) -> pollable // //go:nosplit diff --git a/_examples/http-server/gen/wasi/clocks/wall-clock/wall-clock.wit.go b/_examples/http-server/gen/wasi/clocks/wall-clock/wall-clock.wit.go index 871a2e1..9f425d8 100644 --- a/_examples/http-server/gen/wasi/clocks/wall-clock/wall-clock.wit.go +++ b/_examples/http-server/gen/wasi/clocks/wall-clock/wall-clock.wit.go @@ -1,21 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". -// -// 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. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// A wall clock is a clock which measures the date and time according to -// some external reference. -// -// External references may be reset, so this clock is not necessarily -// monotonic, making it unsuitable for measuring elapsed time. -// -// It is intended for reporting the current date and time for humans. package wallclock import ( @@ -24,8 +9,6 @@ import ( // DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". // -// A time and date in seconds plus nanoseconds. -// // record datetime { // seconds: u64, // nanoseconds: u32, @@ -38,22 +21,8 @@ type DateTime struct { // Now represents the imported function "now". // -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// // now: func() -> datetime // -// [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 -// //go:nosplit func Now() (result DateTime) { wasmimport_Now(&result) @@ -66,10 +35,6 @@ func wasmimport_Now(result *DateTime) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -// // resolution: func() -> datetime // //go:nosplit diff --git a/_examples/http-server/gen/wasi/filesystem/preopens/preopens.wit.go b/_examples/http-server/gen/wasi/filesystem/preopens/preopens.wit.go index d0ba8c2..7ee0138 100644 --- a/_examples/http-server/gen/wasi/filesystem/preopens/preopens.wit.go +++ b/_examples/http-server/gen/wasi/filesystem/preopens/preopens.wit.go @@ -10,8 +10,6 @@ import ( // GetDirectories represents the imported function "get-directories". // -// Return the set of preopened directories, and their path. -// // get-directories: func() -> list> // //go:nosplit diff --git a/_examples/http-server/gen/wasi/filesystem/types/types.wit.go b/_examples/http-server/gen/wasi/filesystem/types/types.wit.go index e5977cb..3fb5270 100644 --- a/_examples/http-server/gen/wasi/filesystem/types/types.wit.go +++ b/_examples/http-server/gen/wasi/filesystem/types/types.wit.go @@ -1,31 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package types represents the imported interface "wasi:filesystem/types@0.2.0". -// -// WASI filesystem is a filesystem API primarily intended to let users run WASI -// programs that access their files on their existing filesystems, without -// significant overhead. -// -// It is intended to be roughly portable between Unix-family platforms and -// Windows, though it does not hide many of the major differences. -// -// Paths are passed as interface-type `string`s, meaning they must consist of -// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -// paths which are not accessible by this API. -// -// The directory separator in WASI is always the forward-slash (`/`). -// -// All paths in WASI are relative paths, and are interpreted relative to a -// `descriptor` referring to a base directory. If a `path` argument to any WASI -// function starts with `/`, or if any step of resolving a `path`, including -// `..` and symbolic link steps, reaches a directory outside of the base -// directory, or reaches a symlink to an absolute or rooted path in the -// underlying filesystem, the function fails with `error-code::not-permitted`. -// -// For more information about WASI path resolution and sandboxing, see -// [WASI filesystem path resolution]. -// -// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md package types import ( @@ -37,17 +12,11 @@ import ( // FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". // -// File size or length of a region within a file. -// // type filesize = u64 type FileSize uint64 // DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". // -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. -// // enum descriptor-type { // unknown, // block-device, @@ -61,29 +30,13 @@ type FileSize uint64 type DescriptorType uint8 const ( - // The type of the descriptor or file is unknown or is different from - // any of the other types specified. DescriptorTypeUnknown DescriptorType = iota - - // The descriptor refers to a block device inode. DescriptorTypeBlockDevice - - // The descriptor refers to a character device inode. DescriptorTypeCharacterDevice - - // The descriptor refers to a directory inode. DescriptorTypeDirectory - - // The descriptor refers to a named pipe. DescriptorTypeFIFO - - // The file refers to a symbolic link inode. DescriptorTypeSymbolicLink - - // The descriptor refers to a regular file inode. DescriptorTypeRegularFile - - // The descriptor refers to a socket. DescriptorTypeSocket ) @@ -105,10 +58,6 @@ func (e DescriptorType) String() string { // DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". // -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. -// // flags descriptor-flags { // read, // write, @@ -120,69 +69,27 @@ func (e DescriptorType) String() string { type DescriptorFlags uint8 const ( - // Read mode: Data can be read. DescriptorFlagsRead DescriptorFlags = 1 << iota - - // Write mode: Data can be written to. DescriptorFlagsWrite - - // Request that writes be performed according to synchronized I/O file - // integrity completion. The data stored in the file and the file's - // metadata are synchronized. This is similar to `O_SYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsFileIntegritySync - - // Request that writes be performed according to synchronized I/O data - // integrity completion. Only the data stored in the file is - // synchronized. This is similar to `O_DSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsDataIntegritySync - - // Requests that reads be performed at the same level of integrety - // requested for writes. This is similar to `O_RSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsRequestedWriteSync - - // Mutating directories mode: Directory contents may be mutated. - // - // When this flag is unset on a descriptor, operations using the - // descriptor which would create, rename, delete, modify the data or - // metadata of filesystem objects, or obtain another handle which - // would permit any of those, shall fail with `error-code::read-only` if - // they would otherwise succeed. - // - // This may only be set on directories. DescriptorFlagsMutateDirectory ) // PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". // -// Flags determining the method of how paths are resolved. -// // flags path-flags { // symlink-follow, // } type PathFlags uint8 const ( - // As long as the resolved path corresponds to a symbolic link, it is - // expanded. PathFlagsSymlinkFollow PathFlags = 1 << iota ) // OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". // -// Open flags used by `open-at`. -// // flags open-flags { // create, // directory, @@ -192,32 +99,19 @@ const ( type OpenFlags uint8 const ( - // Create file if it does not exist, similar to `O_CREAT` in POSIX. OpenFlagsCreate OpenFlags = 1 << iota - - // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. OpenFlagsDirectory - - // Fail if file already exists, similar to `O_EXCL` in POSIX. OpenFlagsExclusive - - // Truncate file to size 0, similar to `O_TRUNC` in POSIX. OpenFlagsTruncate ) // LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". // -// Number of hard links to an inode. -// // type link-count = u64 type LinkCount uint64 // DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". // -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. -// // record descriptor-stat { // %type: descriptor-type, // link-count: link-count, @@ -227,40 +121,17 @@ type LinkCount uint64 // status-change-timestamp: option, // } type DescriptorStat struct { - _ cm.HostLayout - // File type. - Type DescriptorType - - // Number of hard links to the file. - LinkCount LinkCount - - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. - Size FileSize - - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - DataAccessTimestamp cm.Option[wallclock.DateTime] - - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. + _ cm.HostLayout + Type DescriptorType + LinkCount LinkCount + Size FileSize + DataAccessTimestamp cm.Option[wallclock.DateTime] DataModificationTimestamp cm.Option[wallclock.DateTime] - - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. - StatusChangeTimestamp cm.Option[wallclock.DateTime] + StatusChangeTimestamp cm.Option[wallclock.DateTime] } // NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". // -// When setting a timestamp, this gives the value to set it to. -// // variant new-timestamp { // no-change, // now, @@ -269,8 +140,6 @@ type DescriptorStat struct { type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] // NewTimestampNoChange returns a [NewTimestamp] of case "no-change". -// -// Leave the timestamp set to its previous value. func NewTimestampNoChange() NewTimestamp { var data struct{} return cm.New[NewTimestamp](0, data) @@ -282,9 +151,6 @@ func (self *NewTimestamp) NoChange() bool { } // NewTimestampNow returns a [NewTimestamp] of case "now". -// -// Set the timestamp to the current time of the system clock associated -// with the filesystem. func NewTimestampNow() NewTimestamp { var data struct{} return cm.New[NewTimestamp](1, data) @@ -296,8 +162,6 @@ func (self *NewTimestamp) Now() bool { } // NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". -// -// Set the timestamp to the given value. func NewTimestampTimestamp(data wallclock.DateTime) NewTimestamp { return cm.New[NewTimestamp](2, data) } @@ -309,28 +173,18 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { // DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". // -// A directory entry. -// // record directory-entry { // %type: descriptor-type, // name: string, // } type DirectoryEntry struct { - _ cm.HostLayout - // The type of the file referred to by this directory entry. + _ cm.HostLayout Type DescriptorType - - // The name of the object. Name string } // ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". // -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. -// // enum error-code { // access, // would-block, @@ -373,116 +227,42 @@ type DirectoryEntry struct { type ErrorCode uint8 const ( - // Permission denied, similar to `EACCES` in POSIX. ErrorCodeAccess ErrorCode = iota - - // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` - // in POSIX. ErrorCodeWouldBlock - - // Connection already in progress, similar to `EALREADY` in POSIX. ErrorCodeAlready - - // Bad descriptor, similar to `EBADF` in POSIX. ErrorCodeBadDescriptor - - // Device or resource busy, similar to `EBUSY` in POSIX. ErrorCodeBusy - - // Resource deadlock would occur, similar to `EDEADLK` in POSIX. ErrorCodeDeadlock - - // Storage quota exceeded, similar to `EDQUOT` in POSIX. ErrorCodeQuota - - // File exists, similar to `EEXIST` in POSIX. ErrorCodeExist - - // File too large, similar to `EFBIG` in POSIX. ErrorCodeFileTooLarge - - // Illegal byte sequence, similar to `EILSEQ` in POSIX. ErrorCodeIllegalByteSequence - - // Operation in progress, similar to `EINPROGRESS` in POSIX. ErrorCodeInProgress - - // Interrupted function, similar to `EINTR` in POSIX. ErrorCodeInterrupted - - // Invalid argument, similar to `EINVAL` in POSIX. ErrorCodeInvalid - - // I/O error, similar to `EIO` in POSIX. ErrorCodeIO - - // Is a directory, similar to `EISDIR` in POSIX. ErrorCodeIsDirectory - - // Too many levels of symbolic links, similar to `ELOOP` in POSIX. ErrorCodeLoop - - // Too many links, similar to `EMLINK` in POSIX. ErrorCodeTooManyLinks - - // Message too large, similar to `EMSGSIZE` in POSIX. ErrorCodeMessageSize - - // Filename too long, similar to `ENAMETOOLONG` in POSIX. ErrorCodeNameTooLong - - // No such device, similar to `ENODEV` in POSIX. ErrorCodeNoDevice - - // No such file or directory, similar to `ENOENT` in POSIX. ErrorCodeNoEntry - - // No locks available, similar to `ENOLCK` in POSIX. ErrorCodeNoLock - - // Not enough space, similar to `ENOMEM` in POSIX. ErrorCodeInsufficientMemory - - // No space left on device, similar to `ENOSPC` in POSIX. ErrorCodeInsufficientSpace - - // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. ErrorCodeNotDirectory - - // Directory not empty, similar to `ENOTEMPTY` in POSIX. ErrorCodeNotEmpty - - // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. ErrorCodeNotRecoverable - - // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. ErrorCodeUnsupported - - // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. ErrorCodeNoTTY - - // No such device or address, similar to `ENXIO` in POSIX. ErrorCodeNoSuchDevice - - // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. ErrorCodeOverflow - - // Operation not permitted, similar to `EPERM` in POSIX. ErrorCodeNotPermitted - - // Broken pipe, similar to `EPIPE` in POSIX. ErrorCodePipe - - // Read-only file system, similar to `EROFS` in POSIX. ErrorCodeReadOnly - - // Invalid seek, similar to `ESPIPE` in POSIX. ErrorCodeInvalidSeek - - // Text file busy, similar to `ETXTBSY` in POSIX. ErrorCodeTextFileBusy - - // Cross-device link, similar to `EXDEV` in POSIX. ErrorCodeCrossDevice ) @@ -533,8 +313,6 @@ func (e ErrorCode) String() string { // Advice represents the enum "wasi:filesystem/types@0.2.0#advice". // -// File or memory access pattern advisory information. -// // enum advice { // normal, // sequential, @@ -546,28 +324,11 @@ func (e ErrorCode) String() string { type Advice uint8 const ( - // The application has no advice to give on its behavior with respect - // to the specified data. AdviceNormal Advice = iota - - // The application expects to access the specified data sequentially - // from lower offsets to higher offsets. AdviceSequential - - // The application expects to access the specified data in a random - // order. AdviceRandom - - // The application expects to access the specified data in the near - // future. AdviceWillNeed - - // The application expects that it will not access the specified data - // in the near future. AdviceDontNeed - - // The application expects to access the specified data once and then - // not reuse it thereafter. AdviceNoReuse ) @@ -587,28 +348,18 @@ func (e Advice) String() string { // MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". // -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -// // record metadata-hash-value { // lower: u64, // upper: u64, // } type MetadataHashValue struct { - _ cm.HostLayout - // 64 bits of a 128-bit hash value. + _ cm.HostLayout Lower uint64 - - // Another 64 bits of a 128-bit hash value. Upper uint64 } // Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". // -// 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. -// // resource descriptor type Descriptor cm.Resource @@ -629,10 +380,6 @@ func wasmimport_DescriptorResourceDrop(self0 uint32) // Advise represents the imported method "advise". // -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. -// // advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> // //go:nosplit @@ -651,13 +398,6 @@ func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, a // AppendViaStream represents the imported method "append-via-stream". // -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. -// // append-via-stream: func() -> result // //go:nosplit @@ -673,10 +413,6 @@ func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[stream // CreateDirectoryAt represents the imported method "create-directory-at". // -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. -// // create-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -693,13 +429,6 @@ func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 ui // GetFlags represents the imported method "get-flags". // -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-flags: func() -> result // //go:nosplit @@ -715,17 +444,6 @@ func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFla // GetType represents the imported method "get-type". // -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-type: func() -> result // //go:nosplit @@ -741,13 +459,6 @@ func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType // IsSameObject represents the imported method "is-same-object". // -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// 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. -// // is-same-object: func(other: borrow) -> bool // //go:nosplit @@ -765,10 +476,6 @@ func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uin // LinkAt represents the imported method "link-at". // -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. -// // link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, // new-path: string) -> result<_, error-code> // @@ -789,26 +496,6 @@ func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *u // MetadataHash represents the imported method "metadata-hash". // -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. -// // metadata-hash: func() -> result // //go:nosplit @@ -824,11 +511,6 @@ func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataH // MetadataHashAt represents the imported method "metadata-hash-at". // -// 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`. -// // metadata-hash-at: func(path-flags: path-flags, path: string) -> result // @@ -847,25 +529,6 @@ func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 // OpenAt represents the imported method "open-at". // -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// descriptor not currently open/ it is randomized to prevent applications -// from depending on making assumptions about indexes, since this is -// error-prone in multi-threaded contexts. The returned descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. -// // open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: // descriptor-flags) -> result // @@ -886,18 +549,6 @@ func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // Read represents the imported method "read". // -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. -// // read: func(length: filesize, offset: filesize) -> result, bool>, // error-code> // @@ -916,16 +567,6 @@ func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, res // ReadDirectory represents the imported method "read-directory". // -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// 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. -// // read-directory: func() -> result // //go:nosplit @@ -941,15 +582,6 @@ func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[Director // ReadViaStream represents the imported method "read-via-stream". // -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. -// // read-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -966,13 +598,6 @@ func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm // ReadLinkAt represents the imported method "readlink-at". // -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. -// // readlink-at: func(path: string) -> result // //go:nosplit @@ -989,12 +614,6 @@ func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, r // RemoveDirectoryAt represents the imported method "remove-directory-at". // -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. -// // remove-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1011,10 +630,6 @@ func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 ui // RenameAt represents the imported method "rename-at". // -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. -// // rename-at: func(old-path: string, new-descriptor: borrow, new-path: // string) -> result<_, error-code> // @@ -1034,11 +649,6 @@ func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint3 // SetSize represents the imported method "set-size". // -// 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. -// // set-size: func(size: filesize) -> result<_, error-code> // //go:nosplit @@ -1055,12 +665,6 @@ func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ // SetTimes represents the imported method "set-times". // -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -// // set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: // new-timestamp) -> result<_, error-code> // @@ -1079,13 +683,6 @@ func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, da // SetTimesAt represents the imported method "set-times-at". // -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. -// // set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: // new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> // @@ -1106,16 +703,6 @@ func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uin // Stat represents the imported method "stat". // -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. -// // stat: func() -> result // //go:nosplit @@ -1131,14 +718,6 @@ func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatSha // StatAt represents the imported method "stat-at". // -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. -// // stat-at: func(path-flags: path-flags, path: string) -> result // @@ -1157,13 +736,6 @@ func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // SymlinkAt represents the imported method "symlink-at". // -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. -// // symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> // //go:nosplit @@ -1181,13 +753,6 @@ func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint // Sync represents the imported method "sync". // -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. -// // sync: func() -> result<_, error-code> // //go:nosplit @@ -1203,13 +768,6 @@ func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct // SyncData represents the imported method "sync-data". // -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. -// // sync-data: func() -> result<_, error-code> // //go:nosplit @@ -1225,11 +783,6 @@ func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, st // UnlinkFileAt represents the imported method "unlink-file-at". // -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. -// // unlink-file-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1246,16 +799,6 @@ func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, // Write represents the imported method "write". // -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. -// // write: func(buffer: list, offset: filesize) -> result // //go:nosplit @@ -1273,13 +816,6 @@ func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, of // WriteViaStream represents the imported method "write-via-stream". // -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. -// // write-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -1296,8 +832,6 @@ func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *c // DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". // -// A stream of directory entries. -// // resource directory-entry-stream type DirectoryEntryStream cm.Resource @@ -1318,8 +852,6 @@ func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) // ReadDirectoryEntry represents the imported method "read-directory-entry". // -// Read a single directory entry from a `directory-entry-stream`. -// // read-directory-entry: func() -> result, error-code> // //go:nosplit @@ -1335,17 +867,6 @@ func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm. // FilesystemErrorCode represents the imported function "filesystem-error-code". // -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. -// // filesystem-error-code: func(err: borrow) -> option // //go:nosplit diff --git a/_examples/http-server/gen/wasi/io/error/error.wit.go b/_examples/http-server/gen/wasi/io/error/error.wit.go index 61d61db..6a2cf9b 100644 --- a/_examples/http-server/gen/wasi/io/error/error.wit.go +++ b/_examples/http-server/gen/wasi/io/error/error.wit.go @@ -9,26 +9,6 @@ import ( // Error represents the imported resource "wasi:io/error@0.2.0#error". // -// A resource which represents some error information. -// -// The only method provided by this resource is `to-debug-string`, -// 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, `error`s 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` and returns -// `option`. -// -// The set of functions which can "downcast" an `error` into a more -// concrete type is open. -// // resource error type Error cm.Resource @@ -49,14 +29,6 @@ func wasmimport_ErrorResourceDrop(self0 uint32) // ToDebugString represents the imported method "to-debug-string". // -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. -// // to-debug-string: func() -> string // //go:nosplit diff --git a/_examples/http-server/gen/wasi/io/poll/poll.wit.go b/_examples/http-server/gen/wasi/io/poll/poll.wit.go index d11852f..d111f72 100644 --- a/_examples/http-server/gen/wasi/io/poll/poll.wit.go +++ b/_examples/http-server/gen/wasi/io/poll/poll.wit.go @@ -1,9 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package poll represents the imported interface "wasi:io/poll@0.2.0". -// -// A poll API intended to let users wait for I/O events on multiple handles -// at once. package poll import ( @@ -12,8 +9,6 @@ import ( // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". // -// `pollable` represents a single I/O event which may be ready, or not. -// // resource pollable type Pollable cm.Resource @@ -34,12 +29,6 @@ func wasmimport_PollableResourceDrop(self0 uint32) // Block represents the imported method "block". // -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. -// // block: func() // //go:nosplit @@ -55,10 +44,6 @@ func wasmimport_PollableBlock(self0 uint32) // Ready represents the imported method "ready". // -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. -// // ready: func() -> bool // //go:nosplit @@ -75,25 +60,6 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // Poll represents the imported function "poll". // -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` 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. -// -// 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. -// // poll: func(in: list>) -> list // //go:nosplit diff --git a/_examples/http-server/gen/wasi/io/streams/streams.wit.go b/_examples/http-server/gen/wasi/io/streams/streams.wit.go index 19b10b4..575235f 100644 --- a/_examples/http-server/gen/wasi/io/streams/streams.wit.go +++ b/_examples/http-server/gen/wasi/io/streams/streams.wit.go @@ -1,12 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package streams represents the imported interface "wasi:io/streams@0.2.0". -// -// 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; -// when it does, they are expected to subsume this API. package streams import ( @@ -17,8 +11,6 @@ import ( // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". // -// An error for input-stream and output-stream operations. -// // variant stream-error { // last-operation-failed(error), // closed, @@ -26,10 +18,6 @@ import ( type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] // StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". -// -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { return cm.New[StreamError](0, data) } @@ -40,10 +28,6 @@ func (self *StreamError) LastOperationFailed() *ioerror.Error { } // StreamErrorClosed returns a [StreamError] of case "closed". -// -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. func StreamErrorClosed() StreamError { var data struct{} return cm.New[StreamError](1, data) @@ -56,15 +40,6 @@ func (self *StreamError) Closed() bool { // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". // -// An input bytestream. -// -// `input-stream`s are *non-blocking* to the extent practical on underlying -// platforms. I/O operations always return promptly; if fewer bytes are -// promptly available than requested, they return the number of bytes promptly -// available, which could even be zero. To wait for data to be available, -// use the `subscribe` function to obtain a `pollable` which can be polled -// for using `wasi:io/poll`. -// // resource input-stream type InputStream cm.Resource @@ -85,9 +60,6 @@ func wasmimport_InputStreamResourceDrop(self0 uint32) // BlockingRead represents the imported method "blocking-read". // -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. -// // blocking-read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -104,9 +76,6 @@ func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Re // BlockingSkip represents the imported method "blocking-skip". // -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. -// // blocking-skip: func(len: u64) -> result // //go:nosplit @@ -123,33 +92,6 @@ func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Re // Read represents the imported method "read". // -// 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 -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// 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. -// // read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -166,11 +108,6 @@ func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm. // Skip represents the imported method "skip". // -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. -// // skip: func(len: u64) -> result // //go:nosplit @@ -187,13 +124,6 @@ func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uin // Subscribe represents the imported method "subscribe". // -// 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. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -210,15 +140,6 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) // OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". // -// An output bytestream. -// -// `output-stream`s 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`. -// // resource output-stream type OutputStream cm.Resource @@ -239,9 +160,6 @@ func wasmimport_OutputStreamResourceDrop(self0 uint32) // BlockingFlush represents the imported method "blocking-flush". // -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. -// // blocking-flush: func() -> result<_, stream-error> // //go:nosplit @@ -257,12 +175,6 @@ func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[Stream // BlockingSplice represents the imported method "blocking-splice". // -// 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`. -// // blocking-splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -280,29 +192,6 @@ func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint6 // BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". // -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-and-flush: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -319,29 +208,6 @@ func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8 // BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". // -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// 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` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> // //go:nosplit @@ -358,16 +224,6 @@ func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint6 // CheckWrite represents the imported method "check-write". // -// 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 -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. -// // check-write: func() -> result // //go:nosplit @@ -383,17 +239,6 @@ func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, u // Flush represents the imported method "flush". // -// 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 -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. -// // flush: func() -> result<_, stream-error> // //go:nosplit @@ -409,20 +254,6 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, s // Splice represents the imported method "splice". // -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. -// // splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -440,17 +271,6 @@ func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, resul // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. 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. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -467,20 +287,6 @@ func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) // Write represents the imported method "write". // -// 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. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. -// // write: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -497,13 +303,6 @@ func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint // WriteZeroes represents the imported method "write-zeroes". // -// Write zeroes to a stream. -// -// 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. -// // write-zeroes: func(len: u64) -> result<_, stream-error> // //go:nosplit diff --git a/_examples/http-server/gen/wasi/random/insecure-seed/insecure-seed.wit.go b/_examples/http-server/gen/wasi/random/insecure-seed/insecure-seed.wit.go index 3b8f33c..27f899f 100644 --- a/_examples/http-server/gen/wasi/random/insecure-seed/insecure-seed.wit.go +++ b/_examples/http-server/gen/wasi/random/insecure-seed/insecure-seed.wit.go @@ -1,33 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". -// -// The insecure-seed interface for seeding hash-map DoS resistance. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecureseed // InsecureSeed represents the imported function "insecure-seed". // -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. -// // insecure-seed: func() -> tuple // //go:nosplit diff --git a/_examples/http-server/gen/wasi/random/insecure/insecure.wit.go b/_examples/http-server/gen/wasi/random/insecure/insecure.wit.go index bfe1e6c..8ff72e3 100644 --- a/_examples/http-server/gen/wasi/random/insecure/insecure.wit.go +++ b/_examples/http-server/gen/wasi/random/insecure/insecure.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecure represents the imported interface "wasi:random/insecure@0.2.0". -// -// The insecure interface for insecure pseudo-random numbers. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecure import ( @@ -14,15 +9,6 @@ import ( // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". // -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. -// // get-insecure-random-bytes: func(len: u64) -> list // //go:nosplit @@ -38,11 +24,6 @@ func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) // GetInsecureRandomU64 represents the imported function "get-insecure-random-u64". // -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. -// // get-insecure-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/http-server/gen/wasi/random/random/random.wit.go b/_examples/http-server/gen/wasi/random/random/random.wit.go index da2eb57..b7d24e4 100644 --- a/_examples/http-server/gen/wasi/random/random/random.wit.go +++ b/_examples/http-server/gen/wasi/random/random/random.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package random represents the imported interface "wasi:random/random@0.2.0". -// -// WASI Random is a random data API. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package random import ( @@ -14,19 +9,6 @@ import ( // GetRandomBytes represents the imported function "get-random-bytes". // -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. -// // get-random-bytes: func(len: u64) -> list // //go:nosplit @@ -42,11 +24,6 @@ func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) // GetRandomU64 represents the imported function "get-random-u64". // -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. -// // get-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/http-server/gen/wasi/sockets/instance-network/instance-network.wit.go b/_examples/http-server/gen/wasi/sockets/instance-network/instance-network.wit.go index 02ee282..c8dfecd 100644 --- a/_examples/http-server/gen/wasi/sockets/instance-network/instance-network.wit.go +++ b/_examples/http-server/gen/wasi/sockets/instance-network/instance-network.wit.go @@ -1,8 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". -// -// This interface provides a value-export of the default network handle.. package instancenetwork import ( @@ -12,8 +10,6 @@ import ( // InstanceNetwork represents the imported function "instance-network". // -// Get a handle to the default network. -// // instance-network: func() -> network // //go:nosplit diff --git a/_examples/http-server/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/_examples/http-server/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go index a94096f..1cdacc3 100644 --- a/_examples/http-server/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go +++ b/_examples/http-server/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -31,23 +31,6 @@ func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) // ResolveNextAddress represents the imported method "resolve-next-address". // -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated -// IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. -// (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. -// (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) -// // resolve-next-address: func() -> result, error-code> // //go:nosplit @@ -63,11 +46,6 @@ func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm. // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -84,27 +62,6 @@ func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) // ResolveAddresses represents the imported function "resolve-addresses". // -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -// // resolve-addresses: func(network: borrow, name: string) -> result // diff --git a/_examples/http-server/gen/wasi/sockets/network/network.wit.go b/_examples/http-server/gen/wasi/sockets/network/network.wit.go index bdc8634..3e1a3ac 100644 --- a/_examples/http-server/gen/wasi/sockets/network/network.wit.go +++ b/_examples/http-server/gen/wasi/sockets/network/network.wit.go @@ -9,10 +9,6 @@ import ( // Network represents the imported resource "wasi:sockets/network@0.2.0#network". // -// An opaque resource that represents access to (a subset of) the network. -// This enables context-based security for networking. -// There is no need for this to map 1:1 to a physical network interface. -// // resource network type Network cm.Resource @@ -33,20 +29,6 @@ func wasmimport_NetworkResourceDrop(self0 uint32) // ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". // -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ -// per API. -// // enum error-code { // unknown, // access-denied, @@ -73,87 +55,26 @@ func wasmimport_NetworkResourceDrop(self0 uint32) type ErrorCode uint8 const ( - // Unknown error ErrorCodeUnknown ErrorCode = iota - - // Access denied. - // - // POSIX equivalent: EACCES, EPERM ErrorCodeAccessDenied - - // The operation is not supported. - // - // POSIX equivalent: EOPNOTSUPP ErrorCodeNotSupported - - // One of the arguments is invalid. - // - // POSIX equivalent: EINVAL ErrorCodeInvalidArgument - - // Not enough memory to complete the operation. - // - // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY ErrorCodeOutOfMemory - - // The operation timed out before it could finish completely. ErrorCodeTimeout - - // This operation is incompatible with another asynchronous operation that is already - // in progress. - // - // POSIX equivalent: EALREADY ErrorCodeConcurrencyConflict - - // Trying to finish an asynchronous operation that: - // - has not been started yet, or: - // - was already finished by a previous `finish-*` call. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeNotInProgress - - // The operation has been aborted because it could not be completed immediately. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeWouldBlock - - // The operation is not valid in the socket's current state. ErrorCodeInvalidState - - // A new socket resource could not be created because of a system limit. ErrorCodeNewSocketLimit - - // A bind operation failed because the provided address is not an address that the - // `network` can bind to. ErrorCodeAddressNotBindable - - // A bind operation failed because the provided address is already in use or because - // there are no ephemeral ports available. ErrorCodeAddressInUse - - // The remote address is not reachable ErrorCodeRemoteUnreachable - - // The TCP connection was forcefully rejected ErrorCodeConnectionRefused - - // The TCP connection was reset. ErrorCodeConnectionReset - - // A TCP connection was aborted. ErrorCodeConnectionAborted - - // The size of a datagram sent to a UDP socket exceeded the maximum - // supported size. ErrorCodeDatagramTooLarge - - // Name does not exist or has no suitable associated IP addresses. ErrorCodeNameUnresolvable - - // A temporary failure in name resolution occurred. ErrorCodeTemporaryResolverFailure - - // A permanent failure in name resolution occurred. ErrorCodePermanentResolverFailure ) @@ -195,10 +116,7 @@ func (e ErrorCode) String() string { type IPAddressFamily uint8 const ( - // Similar to `AF_INET` in POSIX. IPAddressFamilyIPv4 IPAddressFamily = iota - - // Similar to `AF_INET6` in POSIX. IPAddressFamilyIPv6 ) @@ -257,11 +175,8 @@ func (self *IPAddress) IPv6() *IPv6Address { // address: ipv4-address, // } type IPv4SocketAddress struct { - _ cm.HostLayout - // sin_port - Port uint16 - - // sin_addr + _ cm.HostLayout + Port uint16 Address IPv4Address } @@ -274,18 +189,11 @@ type IPv4SocketAddress struct { // scope-id: u32, // } type IPv6SocketAddress struct { - _ cm.HostLayout - // sin6_port - Port uint16 - - // sin6_flowinfo + _ cm.HostLayout + Port uint16 FlowInfo uint32 - - // sin6_addr - Address IPv6Address - - // sin6_scope_id - ScopeID uint32 + Address IPv6Address + ScopeID uint32 } // IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". diff --git a/_examples/http-server/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/_examples/http-server/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go index 8b2eb43..b682801 100644 --- a/_examples/http-server/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go +++ b/_examples/http-server/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateTCPSocket represents the imported function "create-tcp-socket". // -// 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`/`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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // create-tcp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/http-server/gen/wasi/sockets/tcp/tcp.wit.go b/_examples/http-server/gen/wasi/sockets/tcp/tcp.wit.go index 39162ae..b16cfab 100644 --- a/_examples/http-server/gen/wasi/sockets/tcp/tcp.wit.go +++ b/_examples/http-server/gen/wasi/sockets/tcp/tcp.wit.go @@ -21,13 +21,8 @@ import ( type ShutdownType uint8 const ( - // Similar to `SHUT_RD` in POSIX. ShutdownTypeReceive ShutdownType = iota - - // Similar to `SHUT_WR` in POSIX. ShutdownTypeSend - - // Similar to `SHUT_RDWR` in POSIX. ShutdownTypeBoth ) @@ -44,29 +39,6 @@ func (e ShutdownType) String() string { // TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". // -// A TCP socket resource. -// -// The socket can be in one of the following states: -// - `unbound` -// - `bind-in-progress` -// - `bound` (See note below) -// - `listen-in-progress` -// - `listening` -// - `connect-in-progress` -// - `connected` -// - `closed` -// See -// for a more information. -// -// Note: Except where explicitly mentioned, whenever this documentation uses -// the term "bound" without backticks it actually means: in the `bound` state *or -// higher*. -// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) -// -// In addition to the general error codes documented on the -// `network::error-code` type, TCP socket methods may always return -// `error(invalid-state)` when in the `closed` state. -// // resource tcp-socket type TCPSocket cm.Resource @@ -87,36 +59,6 @@ func wasmimport_TCPSocketResourceDrop(self0 uint32) // Accept represents the imported method "accept". // -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties -// are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated -// by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // accept: func() -> result, error-code> // //go:nosplit @@ -132,10 +74,6 @@ func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketIn // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -197,13 +135,6 @@ func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.Er // HopLimit represents the imported method "hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // hop-limit: func() -> result // //go:nosplit @@ -219,10 +150,6 @@ func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, // IsListening represents the imported method "is-listening". // -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. -// // is-listening: func() -> bool // //go:nosplit @@ -239,19 +166,6 @@ func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) // KeepAliveCount represents the imported method "keep-alive-count". // -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-count: func() -> result // //go:nosplit @@ -267,17 +181,6 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, // KeepAliveEnabled represents the imported method "keep-alive-enabled". // -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only -// come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. -// // keep-alive-enabled: func() -> result // //go:nosplit @@ -293,20 +196,6 @@ func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, // KeepAliveIdleTime represents the imported method "keep-alive-idle-time". // -// Amount of time the connection has to be idle before TCP starts sending keepalive -// packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-idle-time: func() -> result // //go:nosplit @@ -322,19 +211,6 @@ func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint6 // KeepAliveInterval represents the imported method "keep-alive-interval". // -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-interval: func() -> result // //go:nosplit @@ -350,24 +226,6 @@ func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint6 // LocalAddress represents the imported method "local-address". // -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -383,19 +241,6 @@ func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -411,17 +256,6 @@ func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -532,19 +366,6 @@ func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, resul // SetListenBacklogSize represents the imported method "set-listen-backlog-size". // -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog -// size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` -// state. -// // set-listen-backlog-size: func(value: u64) -> result<_, error-code> // //go:nosplit @@ -593,30 +414,6 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // Shutdown represents the imported method "shutdown". // -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> // //go:nosplit @@ -633,54 +430,6 @@ func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. -// (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the -// TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means -// that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where -// this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -699,60 +448,6 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // StartConnect represents the imported method "start-connect". // -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, -// ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. -// (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL -// on Windows) -// - `invalid-argument`: The socket is already attached to a different network. -// The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. -// (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, -// EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - -// // start-connect: func(network: borrow, remote-address: ip-socket-address) // -> result<_, error-code> // @@ -771,35 +466,6 @@ func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddre // StartListen represents the imported method "start-listen". // -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - -// // start-listen: func() -> result<_, error-code> // //go:nosplit @@ -815,24 +481,6 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/http-server/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/_examples/http-server/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go index 71ab1dd..cc39f68 100644 --- a/_examples/http-server/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go +++ b/_examples/http-server/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateUDPSocket represents the imported function "create-udp-socket". // -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - -// // create-udp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/http-server/gen/wasi/sockets/udp/udp.wit.go b/_examples/http-server/gen/wasi/sockets/udp/udp.wit.go index 1a384d0..ac4b5eb 100644 --- a/_examples/http-server/gen/wasi/sockets/udp/udp.wit.go +++ b/_examples/http-server/gen/wasi/sockets/udp/udp.wit.go @@ -11,57 +11,30 @@ import ( // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". // -// A received datagram. -// // record incoming-datagram { // data: list, // remote-address: ip-socket-address, // } type IncomingDatagram struct { - _ cm.HostLayout - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - Data cm.List[uint8] - - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized - // with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress network.IPSocketAddress } // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". // -// A datagram to be sent out. -// // record outgoing-datagram { // data: list, // remote-address: option, // } type OutgoingDatagram struct { - _ cm.HostLayout - // The payload. - Data cm.List[uint8] - - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address - // exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise - // it is equivalent to `sendto`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress cm.Option[network.IPSocketAddress] } // UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". // -// A UDP socket handle. -// // resource udp-socket type UDPSocket cm.Resource @@ -82,10 +55,6 @@ func wasmimport_UDPSocketResourceDrop(self0 uint32) // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -117,24 +86,6 @@ func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.Erro // LocalAddress represents the imported method "local-address". // -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -150,19 +101,6 @@ func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -178,17 +116,6 @@ func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -267,38 +194,6 @@ func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -317,57 +212,6 @@ func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // Stream represents the imported method "stream". // -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate -// any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` -// may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating -// with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, -// but -// only the most recently returned pair of streams will be operational. Implementations -// may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling -// `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// // %stream: func(remote-address: option) -> result, error-code> // @@ -385,11 +229,6 @@ func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddre // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -406,13 +245,6 @@ func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) // UnicastHopLimit represents the imported method "unicast-hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // unicast-hop-limit: func() -> result // //go:nosplit @@ -448,32 +280,6 @@ func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) // Receive represents the imported method "receive". // -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without -// blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET -// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // receive: func(max-results: u64) -> result, error-code> // //go:nosplit @@ -490,11 +296,6 @@ func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -531,18 +332,6 @@ func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) // CheckSend represents the imported method "check-send". // -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. -// // check-send: func() -> result // //go:nosplit @@ -558,55 +347,6 @@ func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[ // Send represents the imported method "send". // -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking -// and -// returns how many messages were actually sent (or queued for sending). This function -// never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` -// is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and -// sequentially -// sending each individual datagram until either the end of the list has been reached -// or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns -// an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations -// must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` -// permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` -// is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` -// was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // send: func(datagrams: list) -> result // //go:nosplit @@ -623,11 +363,6 @@ func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDat // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/http-server/wasmcloud.toml b/_examples/http-server/wasmcloud.toml index b6e70bc..d8f1dd4 100644 --- a/_examples/http-server/wasmcloud.toml +++ b/_examples/http-server/wasmcloud.toml @@ -1,10 +1,9 @@ name = "http_server" -language = "other" +language = "tinygo" type = "component" version = "0.1.0" [component] -build_command = "tinygo build -target=wasip2 --wit-package ./wit --wit-world example -o build/http_server.wasm main.go" wit_world = "example" wasm_target = "wasm32-wasi-preview2" destination = "build/http_server_s.wasm" diff --git a/_examples/http-server/wit/deps.lock b/_examples/http-server/wit/deps.lock index 9b4d85b..22c6b1d 100644 --- a/_examples/http-server/wit/deps.lock +++ b/_examples/http-server/wit/deps.lock @@ -1,55 +1,49 @@ -[cli] -sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" -sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" +["wasi-cli-0.2.0"] +sha256 = "13b041ec2314d48107929c335df3ca81b1bb0a35bfec38e206a59162a4c209cd" +sha512 = "725886b3244f4894a1121cd66e1bea0775964ca1b3811be3ae43a4c692cb7d5f27d851072637b8ec64bd5e71e85bb5e860f8331fe8f77353d9d7868ce1d72a8e" -[clocks] -sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" -sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" +["wasi-clocks-0.2.0"] +sha256 = "daf7133b4f60ba73185449327dd48d2b324799db858ab463bcd32d954a9ff394" +sha512 = "5992296c504aebfad359ab1676bba63b5d22e33112c240a437ee733433aa50552144242f8998180ff36f0da56e5f65691dbb1898331ce878bd9fa439b8909742" -[component] +["wasi-config-0.2.0-draft"] +sha256 = "5c6b4a10b21fbab2397d579c6f8bf8a484160dfdf20b6343080b0bad097849a3" +sha512 = "d3cf5fd1d12590aefd561330337870e2e468c84753c11e19bccd165c916a696722cc29af3572984e6256088b6e683763675d5b8cec3d195f9e2961fe405629b8" + +["wasi-filesystem-0.2.0"] +sha256 = "739d4fc43cd51421382e5d1a0cf643a2985691d480ae75600cdcd382665b3e55" +sha512 = "67f61ef46833060cc4d7a258da7a82024830762c4ecfd522d32bdc5e6bf4df26043f9a8c13ea38b191df180176826aa7b163816618a939015efff5987557dc16" + +["wasi-http-0.2.0"] +sha256 = "f22b6f3b3c12289e522041067b0a2db99a27c181e9ef3ed36930aa0286232d63" +sha512 = "f9b38ef4f58cb9e069b51ee45df52ce6ca9af0a9774c3d09dc99598f36afcd902557221be2f1a6bcccdecb880e4d7436b533e03f4b9250d5b0e1466afd3a62ce" + +["wasi-io-0.2.0"] +sha256 = "0bc0cc0d474a5c4f3c2e2092664c4e235a0390e5d206d3bdc4007488d9d5e00f" +sha512 = "497f37742a94ca32eaa77dce5d9144682e743b30c2d702d37726d43735a25fa9d421afbf5945da158c0e46a0adf941f607b0e0f5d26494af52f021265f78329c" + +["wasi-logging-0.1.0-draft"] +sha256 = "619c4d2336045bab9129e5af568decd5e963006291d496a23cddf796f3a61c2e" +sha512 = "c163aa6f4e566cb85d373f25e590e552fc2530fdf50946c38d305e9f2cd189d86ff8540d163e42acd2cebbe3cef98967cd1efb14ce196da132fcf6caf4f6155d" + +["wasi-random-0.2.0"] +sha256 = "efcdf344435591830f5fbed67a2c215bba112893518a8ef4c7234a4796b8dbcd" +sha512 = "c78a10e9b6401116eac703430609a849854a27a4ff3bc7737d514536a9c16a2fc206a35f8f96b7c40f254d6a66e6873361970754fa69b856025886cd462a2832" + +["wasi-sockets-0.2.0"] +sha256 = "aa3c13fee8c788c95de5a917a54d776d5adb2afd90a77224864941ce27c5d471" +sha512 = "4e3be65dd127ccd4bfa1af8f86fea556d6e22d25e4b637f9b9ebf66ae1f6331f904edff042adc9be16fec511e3295170e6c13516715d2cd3e5aaffbd96158fa9" + +["wasmcloud-bus-1.0.0"] +sha256 = "f823b5c8293cb585092107120139c34c405f57362761a133d543f5d68c65d591" +sha512 = "12e6aa4eac6139b60ea72cc7b6ded6ac9b144b15557be9f2329b6e84b5a161d8f6344674afd0526a883cb61e34c06fee9dbadbaee1d783cd957bc43dab4bfc2d" + +[wasmcloud-component-go] path = "../../../wit" -sha256 = "ec5b1fc6183ecd80b8328e2345d96d2b7e9fc8c2085300389d21c078ab03729f" -sha512 = "5b1488b7be9f9e05b713aa9cc5465eb730550eab3ae3a9a5ca8a243947a6ae9b90e4a4f06ecd9cc9a375306bb619c54b16856a73d25aa227c45352b88ec741db" -deps = ["cli", "clocks", "config", "filesystem", "io", "lattice", "logging", "messaging", "random", "secrets", "sockets"] - -[config] -sha256 = "9148c06861712b69170af7b8ec37896b4104297d920fdec9f3bcc0b1eee4a5c8" -sha512 = "25a54101620f279c835b39f56f6dbf8a92b374b6faaf6cf6aaa1ea06d8b97b9b79788cf8abd9c2ad0c11e3629dba6a2513b71f2c54b9f95027054ae54a4615b8" - -[filesystem] -sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" -sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" - -[http] -url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -sha256 = "8f44402bde16c48e28c47dc53eab0b26af5b3b3482a1852cf77673e0880ba1c1" -sha512 = "760695f9a25c25bf75a25b731cb21c3bda9e288e450edda823324ecbc73d5d798bbb5de2edad999566980836f037463ee9e57d61789d04b3f3e381475b1a9a0f" -deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] - -[io] -sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" -sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" - -[lattice] -sha256 = "b4946a8bfa48b2f4ac404de03617d25712879596be5417bde3de09ca9c369462" -sha512 = "09918bb2fa8f7af022f71453348be38ec7fd1a35df6809b8d0c5f246856712f969557ff65d9e5d4619e905191e27fba2fbbcc9f38c777a7b09eb73c30909d33f" - -[logging] -sha256 = "9676b482485bb0fd2751a390374c1108865a096b7037f4b5dbe524f066bfb06e" -sha512 = "30a621a6d48a0175e8047c062e618523a85f69c45a7c31918da2b888f7527fce1aca67fa132552222725d0f6cdcaed95be7f16c28488d9468c0fad00cb7450b9" - -[messaging] -sha256 = "41ada083aceb2b4ba92d9bd16d19b6462cc02b10378c9a49135c3447f9138a44" -sha512 = "aa9c819dfd9e85b19661f6087ffd824c44fc38c8a4bc1005c4e7fd34fe844633c52cae7a0412e9ea90f71826e0660e8a3b5672a0f0303c524e4139643ae675ac" - -[random] -sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" -sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" - -[secrets] -sha256 = "4c965f81e4f8510e917976dc7017b070d23b964724e3ca058f28ec9e3d691854" -sha512 = "c23d3d86846b7f35238347974c104a3056e5871db85a8e17c607cf2c48c5fc6dc550fa698a233b78de2c7b25e80ff6c590d0a4bf8c8892b48b3cec52bc141d32" - -[sockets] -sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" -sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" +sha256 = "995bd9ad8d0523f04480196b6746da80ddc5daf2e3be6b126c224d1fe9bda103" +sha512 = "e5af5fbb4242fc151d83ce86fa05d54274eb33a42b8856453659a1191d5142cd3792c914df8db330a9f692089974bbd1e6d3695142a8e5416d10b5b856839ce9" +deps = ["wasi-cli-0.2.0", "wasi-clocks-0.2.0", "wasi-config-0.2.0-draft", "wasi-filesystem-0.2.0", "wasi-http-0.2.0", "wasi-io-0.2.0", "wasi-logging-0.1.0-draft", "wasi-random-0.2.0", "wasi-sockets-0.2.0", "wasmcloud-bus-1.0.0", "wasmcloud-secrets-0.1.0-draft"] + +["wasmcloud-secrets-0.1.0-draft"] +sha256 = "8e0ec182ea30a420744887cdb42660bf703194eaf8ecf2f0dc0efc4159247ea4" +sha512 = "f0037028e47d307b1551068fcdb9249a0a1cd3d7d1e8d99f33713ec1ee22bc5242fe63155a9f7aaa0492640df2c79ea40ed0839e2add222c069787b59c09f1b3" diff --git a/_examples/http-server/wit/deps.toml b/_examples/http-server/wit/deps.toml index 9a0440f..4d1db6f 100644 --- a/_examples/http-server/wit/deps.toml +++ b/_examples/http-server/wit/deps.toml @@ -1,2 +1 @@ -http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -component = "../../../wit" +wasmcloud-component-go = "../../../wit" diff --git a/_examples/http-server/wit/deps/cli/command.wit b/_examples/http-server/wit/deps/cli/command.wit deleted file mode 100644 index d8005bd..0000000 --- a/_examples/http-server/wit/deps/cli/command.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:cli@0.2.0; - -world command { - include imports; - - export run; -} diff --git a/_examples/http-server/wit/deps/cli/environment.wit b/_examples/http-server/wit/deps/cli/environment.wit deleted file mode 100644 index 7006523..0000000 --- a/_examples/http-server/wit/deps/cli/environment.wit +++ /dev/null @@ -1,18 +0,0 @@ -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - get-environment: func() -> list>; - - /// Get the POSIX-style arguments to the program. - get-arguments: func() -> list; - - /// Return a path that programs should use as their initial current working - /// directory, interpreting `.` as shorthand for this. - initial-cwd: func() -> option; -} diff --git a/_examples/http-server/wit/deps/cli/exit.wit b/_examples/http-server/wit/deps/cli/exit.wit deleted file mode 100644 index d0c2b82..0000000 --- a/_examples/http-server/wit/deps/cli/exit.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface exit { - /// Exit the current instance and any linked instances. - exit: func(status: result); -} diff --git a/_examples/http-server/wit/deps/cli/imports.wit b/_examples/http-server/wit/deps/cli/imports.wit deleted file mode 100644 index 083b84a..0000000 --- a/_examples/http-server/wit/deps/cli/imports.wit +++ /dev/null @@ -1,20 +0,0 @@ -package wasi:cli@0.2.0; - -world imports { - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:sockets/imports@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; - - import environment; - import exit; - import stdin; - import stdout; - import stderr; - import terminal-input; - import terminal-output; - import terminal-stdin; - import terminal-stdout; - import terminal-stderr; -} diff --git a/_examples/http-server/wit/deps/cli/run.wit b/_examples/http-server/wit/deps/cli/run.wit deleted file mode 100644 index a70ee8c..0000000 --- a/_examples/http-server/wit/deps/cli/run.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface run { - /// Run the program. - run: func() -> result; -} diff --git a/_examples/http-server/wit/deps/cli/stdio.wit b/_examples/http-server/wit/deps/cli/stdio.wit deleted file mode 100644 index 31ef35b..0000000 --- a/_examples/http-server/wit/deps/cli/stdio.wit +++ /dev/null @@ -1,17 +0,0 @@ -interface stdin { - use wasi:io/streams@0.2.0.{input-stream}; - - get-stdin: func() -> input-stream; -} - -interface stdout { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stdout: func() -> output-stream; -} - -interface stderr { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stderr: func() -> output-stream; -} diff --git a/_examples/http-server/wit/deps/cli/terminal.wit b/_examples/http-server/wit/deps/cli/terminal.wit deleted file mode 100644 index 38c724e..0000000 --- a/_examples/http-server/wit/deps/cli/terminal.wit +++ /dev/null @@ -1,49 +0,0 @@ -/// Terminal input. -/// -/// In the future, this may include functions for disabling echoing, -/// disabling input buffering so that keyboard events are sent through -/// immediately, querying supported features, and so on. -interface terminal-input { - /// The input side of a terminal. - resource terminal-input; -} - -/// Terminal output. -/// -/// In the future, this may include functions for querying the terminal -/// size, being notified of terminal size changes, querying supported -/// features, and so on. -interface terminal-output { - /// The output side of a terminal. - resource terminal-output; -} - -/// An interface providing an optional `terminal-input` for stdin as a -/// link-time authority. -interface terminal-stdin { - use terminal-input.{terminal-input}; - - /// If stdin is connected to a terminal, return a `terminal-input` handle - /// allowing further interaction with it. - get-terminal-stdin: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stdout as a -/// link-time authority. -interface terminal-stdout { - use terminal-output.{terminal-output}; - - /// If stdout is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stdout: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stderr as a -/// link-time authority. -interface terminal-stderr { - use terminal-output.{terminal-output}; - - /// If stderr is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stderr: func() -> option; -} diff --git a/_examples/http-server/wit/deps/clocks/monotonic-clock.wit b/_examples/http-server/wit/deps/clocks/monotonic-clock.wit deleted file mode 100644 index 4e4dc3a..0000000 --- a/_examples/http-server/wit/deps/clocks/monotonic-clock.wit +++ /dev/null @@ -1,45 +0,0 @@ -package wasi:clocks@0.2.0; -/// WASI Monotonic Clock is a clock API intended to let users measure elapsed -/// time. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// 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. -interface monotonic-clock { - 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. - type instant = u64; - - /// A duration of time, in nanoseconds. - 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. - now: func() -> instant; - - /// Query the resolution of the clock. Returns the duration of time - /// corresponding to a clock tick. - resolution: func() -> duration; - - /// Create a `pollable` which will resolve once the specified instant - /// occured. - 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. - subscribe-duration: func( - when: duration, - ) -> pollable; -} diff --git a/_examples/http-server/wit/deps/clocks/wall-clock.wit b/_examples/http-server/wit/deps/clocks/wall-clock.wit deleted file mode 100644 index 440ca0f..0000000 --- a/_examples/http-server/wit/deps/clocks/wall-clock.wit +++ /dev/null @@ -1,42 +0,0 @@ -package wasi:clocks@0.2.0; -/// 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. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// A wall clock is a clock which measures the date and time according to -/// some external reference. -/// -/// External references may be reset, so this clock is not necessarily -/// monotonic, making it unsuitable for measuring elapsed time. -/// -/// It is intended for reporting the current date and time for humans. -interface wall-clock { - /// A time and date in seconds plus nanoseconds. - record datetime { - seconds: u64, - nanoseconds: u32, - } - - /// Read the current value of the clock. - /// - /// This clock is not monotonic, therefore calling this function repeatedly - /// will not necessarily produce a sequence of non-decreasing values. - /// - /// The returned timestamps represent the number of seconds since - /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], - /// also known as [Unix Time]. - /// - /// The nanoseconds field of the output is always less than 1000000000. - /// - /// [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 - now: func() -> datetime; - - /// Query the resolution of the clock. - /// - /// The nanoseconds field of the output is always less than 1000000000. - resolution: func() -> datetime; -} diff --git a/_examples/http-server/wit/deps/clocks/world.wit b/_examples/http-server/wit/deps/clocks/world.wit deleted file mode 100644 index c022457..0000000 --- a/_examples/http-server/wit/deps/clocks/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:clocks@0.2.0; - -world imports { - import monotonic-clock; - import wall-clock; -} diff --git a/_examples/http-server/wit/deps/config/runtime_config.wit b/_examples/http-server/wit/deps/config/runtime_config.wit deleted file mode 100644 index 29d53b1..0000000 --- a/_examples/http-server/wit/deps/config/runtime_config.wit +++ /dev/null @@ -1,25 +0,0 @@ -interface runtime { - /// An error type that encapsulates the different errors that can occur fetching config - variant config-error { - /// This indicates an error from an "upstream" config source. - /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), - /// the error message is a string. - upstream(string), - /// This indicates an error from an I/O operation. - /// As this could be almost _anything_ (such as a file read, network connection, etc), - /// the error message is a string. - /// Depending on how this ends up being consumed, - /// we may consider moving this to use the `wasi:io/error` type instead. - /// For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - } - - /// Gets a single opaque config value set at the given key if it exists - get: func( - /// A string key to fetch - key: string - ) -> result, config-error>; - - /// Gets a list of all set config data - get-all: func() -> result>, config-error>; -} diff --git a/_examples/http-server/wit/deps/config/world.wit b/_examples/http-server/wit/deps/config/world.wit deleted file mode 100644 index 378c4a7..0000000 --- a/_examples/http-server/wit/deps/config/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:config@0.2.0-draft; - -world imports { - /// The runtime interface for config - import runtime; -} \ No newline at end of file diff --git a/_examples/http-server/wit/deps/filesystem/preopens.wit b/_examples/http-server/wit/deps/filesystem/preopens.wit deleted file mode 100644 index da801f6..0000000 --- a/_examples/http-server/wit/deps/filesystem/preopens.wit +++ /dev/null @@ -1,8 +0,0 @@ -package wasi:filesystem@0.2.0; - -interface preopens { - use types.{descriptor}; - - /// Return the set of preopened directories, and their path. - get-directories: func() -> list>; -} diff --git a/_examples/http-server/wit/deps/filesystem/types.wit b/_examples/http-server/wit/deps/filesystem/types.wit deleted file mode 100644 index 11108fc..0000000 --- a/_examples/http-server/wit/deps/filesystem/types.wit +++ /dev/null @@ -1,634 +0,0 @@ -package wasi:filesystem@0.2.0; -/// WASI filesystem is a filesystem API primarily intended to let users run WASI -/// programs that access their files on their existing filesystems, without -/// significant overhead. -/// -/// It is intended to be roughly portable between Unix-family platforms and -/// Windows, though it does not hide many of the major differences. -/// -/// Paths are passed as interface-type `string`s, meaning they must consist of -/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -/// paths which are not accessible by this API. -/// -/// The directory separator in WASI is always the forward-slash (`/`). -/// -/// All paths in WASI are relative paths, and are interpreted relative to a -/// `descriptor` referring to a base directory. If a `path` argument to any WASI -/// function starts with `/`, or if any step of resolving a `path`, including -/// `..` and symbolic link steps, reaches a directory outside of the base -/// directory, or reaches a symlink to an absolute or rooted path in the -/// underlying filesystem, the function fails with `error-code::not-permitted`. -/// -/// For more information about WASI path resolution and sandboxing, see -/// [WASI filesystem path resolution]. -/// -/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md -interface types { - use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0.{datetime}; - - /// File size or length of a region within a file. - type filesize = u64; - - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - enum descriptor-type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - unknown, - /// The descriptor refers to a block device inode. - block-device, - /// The descriptor refers to a character device inode. - character-device, - /// The descriptor refers to a directory inode. - directory, - /// The descriptor refers to a named pipe. - fifo, - /// The file refers to a symbolic link inode. - symbolic-link, - /// The descriptor refers to a regular file inode. - regular-file, - /// The descriptor refers to a socket. - socket, - } - - /// Descriptor flags. - /// - /// Note: This was called `fdflags` in earlier versions of WASI. - flags descriptor-flags { - /// Read mode: Data can be read. - read, - /// Write mode: Data can be written to. - write, - /// Request that writes be performed according to synchronized I/O file - /// integrity completion. The data stored in the file and the file's - /// metadata are synchronized. This is similar to `O_SYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - file-integrity-sync, - /// Request that writes be performed according to synchronized I/O data - /// integrity completion. Only the data stored in the file is - /// synchronized. This is similar to `O_DSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - data-integrity-sync, - /// Requests that reads be performed at the same level of integrety - /// requested for writes. This is similar to `O_RSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - requested-write-sync, - /// Mutating directories mode: Directory contents may be mutated. - /// - /// When this flag is unset on a descriptor, operations using the - /// descriptor which would create, rename, delete, modify the data or - /// metadata of filesystem objects, or obtain another handle which - /// would permit any of those, shall fail with `error-code::read-only` if - /// they would otherwise succeed. - /// - /// This may only be set on directories. - mutate-directory, - } - - /// File attributes. - /// - /// Note: This was called `filestat` in earlier versions of WASI. - record descriptor-stat { - /// File type. - %type: descriptor-type, - /// Number of hard links to the file. - link-count: link-count, - /// For regular files, the file size in bytes. For symbolic links, the - /// length in bytes of the pathname contained in the symbolic link. - size: filesize, - /// Last data access timestamp. - /// - /// If the `option` is none, the platform doesn't maintain an access - /// timestamp for this file. - data-access-timestamp: option, - /// Last data modification timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// modification timestamp for this file. - data-modification-timestamp: option, - /// Last file status-change timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// status-change timestamp for this file. - status-change-timestamp: option, - } - - /// Flags determining the method of how paths are resolved. - flags path-flags { - /// As long as the resolved path corresponds to a symbolic link, it is - /// expanded. - symlink-follow, - } - - /// Open flags used by `open-at`. - flags open-flags { - /// Create file if it does not exist, similar to `O_CREAT` in POSIX. - create, - /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. - directory, - /// Fail if file already exists, similar to `O_EXCL` in POSIX. - exclusive, - /// Truncate file to size 0, similar to `O_TRUNC` in POSIX. - truncate, - } - - /// Number of hard links to an inode. - type link-count = u64; - - /// When setting a timestamp, this gives the value to set it to. - variant new-timestamp { - /// Leave the timestamp set to its previous value. - no-change, - /// Set the timestamp to the current time of the system clock associated - /// with the filesystem. - now, - /// Set the timestamp to the given value. - timestamp(datetime), - } - - /// A directory entry. - record directory-entry { - /// The type of the file referred to by this directory entry. - %type: descriptor-type, - - /// The name of the object. - name: string, - } - - /// Error codes returned by functions, similar to `errno` in POSIX. - /// Not all of these error codes are returned by the functions provided by this - /// API; some are used in higher-level library layers, and others are provided - /// merely for alignment with POSIX. - enum error-code { - /// Permission denied, similar to `EACCES` in POSIX. - access, - /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. - would-block, - /// Connection already in progress, similar to `EALREADY` in POSIX. - already, - /// Bad descriptor, similar to `EBADF` in POSIX. - bad-descriptor, - /// Device or resource busy, similar to `EBUSY` in POSIX. - busy, - /// Resource deadlock would occur, similar to `EDEADLK` in POSIX. - deadlock, - /// Storage quota exceeded, similar to `EDQUOT` in POSIX. - quota, - /// File exists, similar to `EEXIST` in POSIX. - exist, - /// File too large, similar to `EFBIG` in POSIX. - file-too-large, - /// Illegal byte sequence, similar to `EILSEQ` in POSIX. - illegal-byte-sequence, - /// Operation in progress, similar to `EINPROGRESS` in POSIX. - in-progress, - /// Interrupted function, similar to `EINTR` in POSIX. - interrupted, - /// Invalid argument, similar to `EINVAL` in POSIX. - invalid, - /// I/O error, similar to `EIO` in POSIX. - io, - /// Is a directory, similar to `EISDIR` in POSIX. - is-directory, - /// Too many levels of symbolic links, similar to `ELOOP` in POSIX. - loop, - /// Too many links, similar to `EMLINK` in POSIX. - too-many-links, - /// Message too large, similar to `EMSGSIZE` in POSIX. - message-size, - /// Filename too long, similar to `ENAMETOOLONG` in POSIX. - name-too-long, - /// No such device, similar to `ENODEV` in POSIX. - no-device, - /// No such file or directory, similar to `ENOENT` in POSIX. - no-entry, - /// No locks available, similar to `ENOLCK` in POSIX. - no-lock, - /// Not enough space, similar to `ENOMEM` in POSIX. - insufficient-memory, - /// No space left on device, similar to `ENOSPC` in POSIX. - insufficient-space, - /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. - not-directory, - /// Directory not empty, similar to `ENOTEMPTY` in POSIX. - not-empty, - /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. - not-recoverable, - /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. - unsupported, - /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. - no-tty, - /// No such device or address, similar to `ENXIO` in POSIX. - no-such-device, - /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. - overflow, - /// Operation not permitted, similar to `EPERM` in POSIX. - not-permitted, - /// Broken pipe, similar to `EPIPE` in POSIX. - pipe, - /// Read-only file system, similar to `EROFS` in POSIX. - read-only, - /// Invalid seek, similar to `ESPIPE` in POSIX. - invalid-seek, - /// Text file busy, similar to `ETXTBSY` in POSIX. - text-file-busy, - /// Cross-device link, similar to `EXDEV` in POSIX. - cross-device, - } - - /// File or memory access pattern advisory information. - enum advice { - /// The application has no advice to give on its behavior with respect - /// to the specified data. - normal, - /// The application expects to access the specified data sequentially - /// from lower offsets to higher offsets. - sequential, - /// The application expects to access the specified data in a random - /// order. - random, - /// The application expects to access the specified data in the near - /// future. - will-need, - /// The application expects that it will not access the specified data - /// in the near future. - dont-need, - /// The application expects to access the specified data once and then - /// not reuse it thereafter. - no-reuse, - } - - /// A 128-bit hash value, split into parts because wasm doesn't have a - /// 128-bit integer type. - record metadata-hash-value { - /// 64 bits of a 128-bit hash value. - lower: u64, - /// Another 64 bits of a 128-bit hash value. - upper: u64, - } - - /// 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. - resource descriptor { - /// Return a stream for reading from a file, if available. - /// - /// May fail with an error-code describing why the file cannot be read. - /// - /// Multiple read, write, and append streams may be active on the same open - /// file and they do not interfere with each other. - /// - /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. - read-via-stream: func( - /// The offset within the file at which to start reading. - offset: filesize, - ) -> result; - - /// Return a stream for writing to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be written. - /// - /// Note: This allows using `write-stream`, which is similar to `write` in - /// POSIX. - write-via-stream: func( - /// The offset within the file at which to start writing. - offset: filesize, - ) -> result; - - /// Return a stream for appending to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be appended. - /// - /// Note: This allows using `write-stream`, which is similar to `write` with - /// `O_APPEND` in in POSIX. - append-via-stream: func() -> result; - - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - advise: func( - /// The offset within the file to which the advisory applies. - offset: filesize, - /// The length of the region to which the advisory applies. - length: filesize, - /// The advice. - advice: advice - ) -> result<_, error-code>; - - /// Synchronize the data of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fdatasync` in POSIX. - sync-data: func() -> result<_, error-code>; - - /// Get flags associated with a descriptor. - /// - /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. - /// - /// Note: This returns the value that was the `fs_flags` value returned - /// from `fdstat_get` in earlier versions of WASI. - get-flags: func() -> result; - - /// Get the dynamic type of a descriptor. - /// - /// Note: This returns the same value as the `type` field of the `fd-stat` - /// returned by `stat`, `stat-at` and similar. - /// - /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided - /// by `fstat` in POSIX. - /// - /// Note: This returns the value that was the `fs_filetype` value returned - /// from `fdstat_get` in earlier versions of WASI. - 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. - set-size: func(size: filesize) -> result<_, error-code>; - - /// Adjust the timestamps of an open file or directory. - /// - /// Note: This is similar to `futimens` in POSIX. - /// - /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. - set-times: func( - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Read from a descriptor, without using and updating the descriptor's offset. - /// - /// This function returns a list of bytes containing the data that was - /// read, along with a bool which, when true, indicates that the end of the - /// file was reached. The returned list will contain up to `length` bytes; it - /// may return fewer than requested, if the end of the file is reached or - /// if the I/O operation is interrupted. - /// - /// In the future, this may change to return a `stream`. - /// - /// Note: This is similar to `pread` in POSIX. - read: func( - /// The maximum number of bytes to read. - length: filesize, - /// The offset within the file at which to read. - offset: filesize, - ) -> result, bool>, error-code>; - - /// Write to a descriptor, without using and updating the descriptor's offset. - /// - /// It is valid to write past the end of a file; the file is extended to the - /// extent of the write, with bytes between the previous end and the start of - /// the write set to zero. - /// - /// In the future, this may change to take a `stream`. - /// - /// Note: This is similar to `pwrite` in POSIX. - write: func( - /// Data to write - buffer: list, - /// The offset within the file at which to write. - offset: filesize, - ) -> result; - - /// Read directory entries from a directory. - /// - /// On filesystems where directories contain entries referring to themselves - /// and their parents, often named `.` and `..` respectively, these entries - /// are omitted. - /// - /// 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. - read-directory: func() -> result; - - /// Synchronize the data and metadata of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fsync` in POSIX. - sync: func() -> result<_, error-code>; - - /// Create a directory. - /// - /// Note: This is similar to `mkdirat` in POSIX. - create-directory-at: func( - /// The relative path at which to create the directory. - path: string, - ) -> result<_, error-code>; - - /// Return the attributes of an open file or directory. - /// - /// Note: This is similar to `fstat` in POSIX, except that it does not return - /// device and inode information. For testing whether two descriptors refer to - /// the same underlying filesystem object, use `is-same-object`. To obtain - /// additional data that can be used do determine whether a file has been - /// modified, use `metadata-hash`. - /// - /// Note: This was called `fd_filestat_get` in earlier versions of WASI. - stat: func() -> result; - - /// Return the attributes of a file or directory. - /// - /// Note: This is similar to `fstatat` in POSIX, except that it does not - /// return device and inode information. See the `stat` description for a - /// discussion of alternatives. - /// - /// Note: This was called `path_filestat_get` in earlier versions of WASI. - stat-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - - /// Adjust the timestamps of a file or directory. - /// - /// Note: This is similar to `utimensat` in POSIX. - /// - /// Note: This was called `path_filestat_set_times` in earlier versions of - /// WASI. - set-times-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to operate on. - path: string, - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Create a hard link. - /// - /// Note: This is similar to `linkat` in POSIX. - link-at: func( - /// Flags determining the method of how the path is resolved. - old-path-flags: path-flags, - /// The relative source path from which to link. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path at which to create the hard link. - new-path: string, - ) -> result<_, error-code>; - - /// Open a file or directory. - /// - /// The returned descriptor is not guaranteed to be the lowest-numbered - /// descriptor not currently open/ it is randomized to prevent applications - /// from depending on making assumptions about indexes, since this is - /// error-prone in multi-threaded contexts. The returned descriptor is - /// guaranteed to be less than 2**31. - /// - /// If `flags` contains `descriptor-flags::mutate-directory`, and the base - /// descriptor doesn't have `descriptor-flags::mutate-directory` set, - /// `open-at` fails with `error-code::read-only`. - /// - /// If `flags` contains `write` or `mutate-directory`, or `open-flags` - /// contains `truncate` or `create`, and the base descriptor doesn't have - /// `descriptor-flags::mutate-directory` set, `open-at` fails with - /// `error-code::read-only`. - /// - /// Note: This is similar to `openat` in POSIX. - open-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the object to open. - path: string, - /// The method by which to open the file. - open-flags: open-flags, - /// Flags to use for the resulting descriptor. - %flags: descriptor-flags, - ) -> result; - - /// Read the contents of a symbolic link. - /// - /// If the contents contain an absolute or rooted path in the underlying - /// filesystem, this function fails with `error-code::not-permitted`. - /// - /// Note: This is similar to `readlinkat` in POSIX. - readlink-at: func( - /// The relative path of the symbolic link from which to read. - path: string, - ) -> result; - - /// Remove a directory. - /// - /// Return `error-code::not-empty` if the directory is not empty. - /// - /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - remove-directory-at: func( - /// The relative path to a directory to remove. - path: string, - ) -> result<_, error-code>; - - /// Rename a filesystem object. - /// - /// Note: This is similar to `renameat` in POSIX. - rename-at: func( - /// The relative source path of the file or directory to rename. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path to which to rename the file or directory. - new-path: string, - ) -> result<_, error-code>; - - /// Create a symbolic link (also known as a "symlink"). - /// - /// If `old-path` starts with `/`, the function fails with - /// `error-code::not-permitted`. - /// - /// Note: This is similar to `symlinkat` in POSIX. - symlink-at: func( - /// The contents of the symbolic link. - old-path: string, - /// The relative destination path at which to create the symbolic link. - new-path: string, - ) -> result<_, error-code>; - - /// Unlink a filesystem object that is not a directory. - /// - /// Return `error-code::is-directory` if the path refers to a directory. - /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. - unlink-file-at: func( - /// The relative path to a file to unlink. - path: string, - ) -> result<_, error-code>; - - /// Test whether two descriptors refer to the same filesystem object. - /// - /// In POSIX, this corresponds to testing whether the two descriptors have the - /// 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. - is-same-object: func(other: borrow) -> bool; - - /// Return a hash of the metadata associated with a filesystem object referred - /// to by a descriptor. - /// - /// This returns a hash of the last-modification timestamp and file size, and - /// may also include the inode number, device number, birth timestamp, and - /// other metadata fields that may change when the file is modified or - /// replaced. It may also include a secret value chosen by the - /// implementation and not otherwise exposed. - /// - /// Implementations are encourated to provide the following properties: - /// - /// - If the file is not modified or replaced, the computed hash value should - /// usually not change. - /// - If the object is modified or replaced, the computed hash value should - /// usually change. - /// - The inputs to the hash should not be easily computable from the - /// computed hash. - /// - /// However, none of these is required. - 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`. - metadata-hash-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - } - - /// A stream of directory entries. - resource directory-entry-stream { - /// Read a single directory entry from a `directory-entry-stream`. - read-directory-entry: func() -> result, error-code>; - } - - /// Attempts to extract a filesystem-related `error-code` from the stream - /// `error` provided. - /// - /// Stream operations which return `stream-error::last-operation-failed` - /// have a payload with more information about the operation that failed. - /// This payload can be passed through to this function to see if there's - /// filesystem-related information about the error to return. - /// - /// Note that this function is fallible because not all stream-related - /// errors are filesystem-related errors. - filesystem-error-code: func(err: borrow) -> option; -} diff --git a/_examples/http-server/wit/deps/filesystem/world.wit b/_examples/http-server/wit/deps/filesystem/world.wit deleted file mode 100644 index 663f579..0000000 --- a/_examples/http-server/wit/deps/filesystem/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:filesystem@0.2.0; - -world imports { - import types; - import preopens; -} diff --git a/_examples/http-server/wit/deps/http/handler.wit b/_examples/http-server/wit/deps/http/handler.wit deleted file mode 100644 index a34a064..0000000 --- a/_examples/http-server/wit/deps/http/handler.wit +++ /dev/null @@ -1,43 +0,0 @@ -/// This interface defines a handler of incoming HTTP Requests. It should -/// be exported by components which can respond to HTTP Requests. -interface incoming-handler { - use types.{incoming-request, response-outparam}; - - /// This function is invoked with an incoming HTTP Request, and a resource - /// `response-outparam` which provides the capability to reply with an HTTP - /// Response. The response is sent by calling the `response-outparam.set` - /// method, which allows execution to continue after the response has been - /// sent. This enables both streaming to the response body, and performing other - /// work. - /// - /// 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. - handle: func( - request: incoming-request, - response-out: response-outparam - ); -} - -/// This interface defines a handler of outgoing HTTP Requests. It should be -/// imported by components which wish to make HTTP Requests. -interface outgoing-handler { - use types.{ - outgoing-request, request-options, future-incoming-response, error-code - }; - - /// This function is invoked with an outgoing HTTP Request, and it returns - /// a resource `future-incoming-response` which represents an HTTP Response - /// which may arrive in the future. - /// - /// The `options` argument accepts optional parameters for the HTTP - /// protocol's transport layer. - /// - /// 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`. - handle: func( - request: outgoing-request, - options: option - ) -> result; -} diff --git a/_examples/http-server/wit/deps/http/proxy.wit b/_examples/http-server/wit/deps/http/proxy.wit deleted file mode 100644 index 687c24d..0000000 --- a/_examples/http-server/wit/deps/http/proxy.wit +++ /dev/null @@ -1,32 +0,0 @@ -package wasi:http@0.2.0; - -/// The `wasi:http/proxy` world captures a widely-implementable intersection of -/// 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. -world proxy { - /// HTTP proxies have access to time and randomness. - include wasi:clocks/imports@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. - import wasi:cli/stdout@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. - 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()`). - import outgoing-handler; - - /// 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`. - export incoming-handler; -} diff --git a/_examples/http-server/wit/deps/io/error.wit b/_examples/http-server/wit/deps/io/error.wit deleted file mode 100644 index 22e5b64..0000000 --- a/_examples/http-server/wit/deps/io/error.wit +++ /dev/null @@ -1,34 +0,0 @@ -package wasi:io@0.2.0; - - -interface error { - /// A resource which represents some error information. - /// - /// The only method provided by this resource is `to-debug-string`, - /// 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, `error`s 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` and returns - /// `option`. - /// - /// The set of functions which can "downcast" an `error` into a more - /// concrete type is open. - resource error { - /// Returns a string that is suitable to assist humans in debugging - /// this error. - /// - /// WARNING: The returned string should not be consumed mechanically! - /// It may change across platforms, hosts, or other implementation - /// details. Parsing this string is a major platform-compatibility - /// hazard. - to-debug-string: func() -> string; - } -} diff --git a/_examples/http-server/wit/deps/io/poll.wit b/_examples/http-server/wit/deps/io/poll.wit deleted file mode 100644 index ddc67f8..0000000 --- a/_examples/http-server/wit/deps/io/poll.wit +++ /dev/null @@ -1,41 +0,0 @@ -package wasi:io@0.2.0; - -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// `pollable` represents a single I/O event which may be ready, or not. - resource pollable { - - /// Return the readiness of a pollable. This function never blocks. - /// - /// Returns `true` when the pollable is ready, and `false` otherwise. - ready: func() -> bool; - - /// `block` returns immediately if the pollable is ready, and otherwise - /// blocks until ready. - /// - /// This function is equivalent to calling `poll.poll` on a list - /// containing only this pollable. - block: func(); - } - - /// Poll for completion on a set of pollables. - /// - /// This function takes a list of pollables, which identify I/O sources of - /// interest, and waits until one or more of the events is ready for I/O. - /// - /// The result `list` 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. - /// - /// 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. - poll: func(in: list>) -> list; -} diff --git a/_examples/http-server/wit/deps/io/streams.wit b/_examples/http-server/wit/deps/io/streams.wit deleted file mode 100644 index 6d2f871..0000000 --- a/_examples/http-server/wit/deps/io/streams.wit +++ /dev/null @@ -1,262 +0,0 @@ -package wasi:io@0.2.0; - -/// 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; -/// when it does, they are expected to subsume this API. -interface streams { - use error.{error}; - use poll.{pollable}; - - /// An error for input-stream and output-stream operations. - variant stream-error { - /// The last operation (a write or flush) failed before completion. - /// - /// More information is available in the `error` payload. - last-operation-failed(error), - /// The stream is closed: no more input will be accepted by the - /// stream. A closed output-stream will return this error on all - /// future operations. - closed - } - - /// An input bytestream. - /// - /// `input-stream`s are *non-blocking* to the extent practical on underlying - /// platforms. I/O operations always return promptly; if fewer bytes are - /// promptly available than requested, they return the number of bytes promptly - /// available, which could even be zero. To wait for data to be available, - /// use the `subscribe` function to obtain a `pollable` which can be polled - /// for using `wasi:io/poll`. - resource input-stream { - /// 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 - /// empty when no bytes are available for reading at this time. The - /// pollable given by `subscribe` will be ready when more bytes are - /// available. - /// - /// This function fails with a `stream-error` when the operation - /// encounters an error, giving `last-operation-failed`, or when the - /// stream is closed, giving `closed`. - /// - /// When the caller gives a `len` of 0, it represents a request to - /// read 0 bytes. If the stream is still open, this call should - /// succeed and return an empty list, or otherwise fail with `closed`. - /// - /// The `len` parameter is a `u64`, which could represent a list of u8 which - /// is not possible to allocate in wasm32, or not desirable to allocate as - /// 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. - read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Read bytes from a stream, after blocking until at least one byte can - /// be read. Except for blocking, behavior is identical to `read`. - blocking-read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Skip bytes from a stream. Returns number of bytes skipped. - /// - /// Behaves identical to `read`, except instead of returning a list - /// of bytes, returns the number of bytes consumed from the stream. - skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// Skip bytes from a stream, after blocking until at least one byte - /// can be skipped. Except for blocking behavior, identical to `skip`. - blocking-skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// 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. - /// The created `pollable` is a child resource of the `input-stream`. - /// Implementations may trap if the `input-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - } - - - /// An output bytestream. - /// - /// `output-stream`s 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`. - resource output-stream { - /// 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 - /// permitted will trap. - /// - /// When this function returns 0 bytes, the `subscribe` pollable will - /// become ready when this function will report at least 1 byte, or an - /// error. - check-write: func() -> result; - - /// 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. - /// - /// returns Err(closed) without writing if the stream has closed since - /// the last call to check-write provided a permit. - write: func( - contents: list - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 bytes, and then flush the stream. Block - /// until all of these operations are complete, or an error occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write`, and `flush`, and is implemented with the - /// following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while !contents.is_empty() { - /// // Wait for the stream to become writable - /// pollable.block(); - /// let Ok(n) = this.check-write(); // eliding error handling - /// let len = min(n, contents.len()); - /// let (chunk, rest) = contents.split_at(len); - /// this.write(chunk ); // eliding error handling - /// contents = rest; - /// } - /// this.flush(); - /// // Wait for completion of `flush` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-and-flush: func( - contents: list - ) -> result<_, stream-error>; - - /// 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 - /// is all that has been passed to `write` prior to this call. - /// - /// Upon calling this function, the `output-stream` will not accept any - /// writes (`check-write` will return `ok(0)`) until the flush has - /// completed. The `subscribe` pollable will become ready when the - /// flush has completed and the stream can accept more writes. - flush: func() -> result<_, stream-error>; - - /// Request to flush buffered output, and block until flush completes - /// and stream is ready for writing again. - blocking-flush: func() -> result<_, stream-error>; - - /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. 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. - /// - /// The created `pollable` is a child resource of the `output-stream`. - /// Implementations may trap if the `output-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - - /// Write zeroes to a stream. - /// - /// 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. - write-zeroes: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 zeroes, and then flush the stream. - /// Block until all of these operations are complete, or an error - /// occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with - /// the following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while num_zeroes != 0 { - /// // Wait for the stream to become writable - /// 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` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-zeroes-and-flush: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Read from one stream and write to another. - /// - /// The behavior of splice is equivelant to: - /// 1. calling `check-write` on the `output-stream` - /// 2. calling `read` on the `input-stream` with the smaller of the - /// `check-write` permitted length and the `len` provided to `splice` - /// 3. calling `write` on the `output-stream` with that read data. - /// - /// Any error reported by the call to `check-write`, `read`, or - /// `write` ends the splice and reports that error. - /// - /// This function returns the number of bytes transferred; it may be less - /// than `len`. - splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - - /// 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`. - blocking-splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - } -} diff --git a/_examples/http-server/wit/deps/io/world.wit b/_examples/http-server/wit/deps/io/world.wit deleted file mode 100644 index 5f0b43f..0000000 --- a/_examples/http-server/wit/deps/io/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:io@0.2.0; - -world imports { - import streams; - import poll; -} diff --git a/_examples/http-server/wit/deps/lattice/bus.wit b/_examples/http-server/wit/deps/lattice/bus.wit deleted file mode 100644 index 9275448..0000000 --- a/_examples/http-server/wit/deps/lattice/bus.wit +++ /dev/null @@ -1,14 +0,0 @@ -package wasmcloud:bus@1.0.0; - -interface lattice { - /// Interface target. This represents an interface, which can be selected by `set-link-name`. - resource call-target-interface { - constructor(namespace: string, %package: string, %interface: string); - } - - /// Set an optional link name to use for all interfaces specified. This is advanced - /// functionality only available within wasmcloud and, as such, is exposed here as part of the - /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces - /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component - set-link-name: func(name: string, interfaces: list); -} diff --git a/_examples/http-server/wit/deps/logging/logging.wit b/_examples/http-server/wit/deps/logging/logging.wit deleted file mode 100644 index 8c0bdf8..0000000 --- a/_examples/http-server/wit/deps/logging/logging.wit +++ /dev/null @@ -1,35 +0,0 @@ -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - - /// Describes messages indicating hazardous situations. - warn, - - /// Describes messages indicating serious errors. - error, - - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} diff --git a/_examples/http-server/wit/deps/logging/world.wit b/_examples/http-server/wit/deps/logging/world.wit deleted file mode 100644 index ede6286..0000000 --- a/_examples/http-server/wit/deps/logging/world.wit +++ /dev/null @@ -1,5 +0,0 @@ -package wasi:logging; - -world imports { - import logging; -} diff --git a/_examples/http-server/wit/deps/messaging/messaging.wit b/_examples/http-server/wit/deps/messaging/messaging.wit deleted file mode 100644 index 239d289..0000000 --- a/_examples/http-server/wit/deps/messaging/messaging.wit +++ /dev/null @@ -1,27 +0,0 @@ -package wasmcloud:messaging@0.2.0; - -// Types common to message broker interactions -interface types { - // A message sent to or received from a broker - record broker-message { - subject: string, - body: list, - reply-to: option, - } -} - -interface handler { - use types.{broker-message}; - - // Callback handled to invoke a function when a message is received from a subscription - handle-message: func(msg: broker-message) -> result<_, string>; -} - -interface consumer { - use types.{broker-message}; - - // Perform a request operation on a subject - request: func(subject: string, body: list, timeout-ms: u32) -> result; - // Publish a message to a subject without awaiting a response - publish: func(msg: broker-message) -> result<_, string>; -} diff --git a/_examples/http-server/wit/deps/random/insecure-seed.wit b/_examples/http-server/wit/deps/random/insecure-seed.wit deleted file mode 100644 index 47210ac..0000000 --- a/_examples/http-server/wit/deps/random/insecure-seed.wit +++ /dev/null @@ -1,25 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure-seed interface for seeding hash-map DoS resistance. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure-seed { - /// Return a 128-bit value that may contain a pseudo-random value. - /// - /// The returned value is not required to be computed from a CSPRNG, and may - /// even be entirely deterministic. Host implementations are encouraged to - /// provide pseudo-random values to any program exposed to - /// attacker-controlled content, to enable DoS protection built into many - /// languages' hash-map implementations. - /// - /// This function is intended to only be called once, by a source language - /// to initialize Denial Of Service (DoS) protection in its hash-map - /// implementation. - /// - /// # Expected future evolution - /// - /// This will likely be changed to a value import, to prevent it from being - /// called multiple times and potentially used for purposes other than DoS - /// protection. - insecure-seed: func() -> tuple; -} diff --git a/_examples/http-server/wit/deps/random/insecure.wit b/_examples/http-server/wit/deps/random/insecure.wit deleted file mode 100644 index c58f4ee..0000000 --- a/_examples/http-server/wit/deps/random/insecure.wit +++ /dev/null @@ -1,22 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure interface for insecure pseudo-random numbers. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure { - /// Return `len` insecure pseudo-random bytes. - /// - /// This function is not cryptographically secure. Do not use it for - /// anything related to security. - /// - /// There are no requirements on the values of the returned bytes, however - /// implementations are encouraged to return evenly distributed values with - /// a long period. - get-insecure-random-bytes: func(len: u64) -> list; - - /// Return an insecure pseudo-random `u64` value. - /// - /// This function returns the same type of pseudo-random data as - /// `get-insecure-random-bytes`, represented as a `u64`. - get-insecure-random-u64: func() -> u64; -} diff --git a/_examples/http-server/wit/deps/random/random.wit b/_examples/http-server/wit/deps/random/random.wit deleted file mode 100644 index 0c017f0..0000000 --- a/_examples/http-server/wit/deps/random/random.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wasi:random@0.2.0; -/// WASI Random is a random data API. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface random { - /// Return `len` cryptographically-secure random or pseudo-random bytes. - /// - /// This function must produce data at least as cryptographically secure and - /// fast as an adequately seeded cryptographically-secure pseudo-random - /// number generator (CSPRNG). It must not block, from the perspective of - /// the calling program, under any circumstances, including on the first - /// request and on requests for numbers of bytes. The returned data must - /// always be unpredictable. - /// - /// This function must always return fresh data. Deterministic environments - /// must omit this function, rather than implementing it with deterministic - /// data. - get-random-bytes: func(len: u64) -> list; - - /// Return a cryptographically-secure random or pseudo-random `u64` value. - /// - /// This function returns the same type of data as `get-random-bytes`, - /// represented as a `u64`. - get-random-u64: func() -> u64; -} diff --git a/_examples/http-server/wit/deps/random/world.wit b/_examples/http-server/wit/deps/random/world.wit deleted file mode 100644 index 3da3491..0000000 --- a/_examples/http-server/wit/deps/random/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:random@0.2.0; - -world imports { - import random; - import insecure; - import insecure-seed; -} diff --git a/_examples/http-server/wit/deps/secrets/secrets.wit b/_examples/http-server/wit/deps/secrets/secrets.wit deleted file mode 100644 index da6f4ad..0000000 --- a/_examples/http-server/wit/deps/secrets/secrets.wit +++ /dev/null @@ -1,56 +0,0 @@ -/// This WIT interface powers secret support in wasmCloud -/// -/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 - -package wasmcloud:secrets@0.1.0-draft; - -interface store { - // An error type that encapsulates the different errors that can occur fetching secrets - variant secrets-error { - // This indicates an error from an "upstream" secrets source. - // As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), - // the error message is a string. - upstream(string), - // This indicates an error from an I/O operation. - // As this could be almost _anything_ (such as a file read, network connection, etc), - // the error message is a string. - // Depending on how this ends up being consumed, - // we may consider moving this to use the `wasi:io/error` type instead. - // For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - // This indicates that the secret was not found. Generally "not found" errors will - // be handled by the upstream secrets backend, but there are cases where the host - // may need to return this error. - not-found, - } - - // A secret value can be either a string or a byte array, which lets you - // store binary data as a secret. - variant secret-value { - // A string value - %string(string), - // A byte array value - bytes(list), - } - - // A secret is a resource that can only be borrowed. This allows you to - // pass around handles to secrets and not reveal the values until a - // component needs them. - // You need to use the reveal interface to get the value. - resource secret; - - // Gets a single opaque secrets value set at the given key if it exists - get: func( - // A string key to fetch - key: string, - ) -> result; - -} - -interface reveal { - use store.{secret, secret-value}; - - // Reveals the value of a secret to the caller. - // This lets you easily audit your code to discover where secrets are being used. - reveal: func(s: borrow) -> secret-value; -} diff --git a/_examples/http-server/wit/deps/sockets/instance-network.wit b/_examples/http-server/wit/deps/sockets/instance-network.wit deleted file mode 100644 index e455d0f..0000000 --- a/_examples/http-server/wit/deps/sockets/instance-network.wit +++ /dev/null @@ -1,9 +0,0 @@ - -/// This interface provides a value-export of the default network handle.. -interface instance-network { - use network.{network}; - - /// Get a handle to the default network. - instance-network: func() -> network; - -} diff --git a/_examples/http-server/wit/deps/sockets/ip-name-lookup.wit b/_examples/http-server/wit/deps/sockets/ip-name-lookup.wit deleted file mode 100644 index 8e639ec..0000000 --- a/_examples/http-server/wit/deps/sockets/ip-name-lookup.wit +++ /dev/null @@ -1,51 +0,0 @@ - -interface ip-name-lookup { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-address}; - - - /// Resolve an internet host name to a list of IP addresses. - /// - /// Unicode domain names are automatically converted to ASCII using IDNA encoding. - /// If the input is an IP address string, the address is parsed and returned - /// as-is without making any external requests. - /// - /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. - /// - /// This function never blocks. It either immediately fails or immediately - /// returns successfully with a `resolve-address-stream` that can be used - /// to (asynchronously) fetch the results. - /// - /// # Typical errors - /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. - /// - /// # References: - /// - - /// - - /// - - /// - - resolve-addresses: func(network: borrow, name: string) -> result; - - resource resolve-address-stream { - /// Returns the next address from the resolver. - /// - /// This function should be called multiple times. On each call, it will - /// return the next address in connection order preference. If all - /// addresses have been exhausted, this function returns `none`. - /// - /// This function never returns IPv4-mapped IPv6 addresses. - /// - /// # Typical errors - /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) - /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) - /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) - /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) - resolve-next-address: func() -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/http-server/wit/deps/sockets/network.wit b/_examples/http-server/wit/deps/sockets/network.wit deleted file mode 100644 index 9cadf06..0000000 --- a/_examples/http-server/wit/deps/sockets/network.wit +++ /dev/null @@ -1,145 +0,0 @@ - -interface network { - /// An opaque resource that represents access to (a subset of) the network. - /// This enables context-based security for networking. - /// There is no need for this to map 1:1 to a physical network interface. - resource network; - - /// Error codes. - /// - /// In theory, every API can return any error code. - /// In practice, API's typically only return the errors documented per API - /// combined with a couple of errors that are always possible: - /// - `unknown` - /// - `access-denied` - /// - `not-supported` - /// - `out-of-memory` - /// - `concurrency-conflict` - /// - /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. - enum error-code { - /// Unknown error - unknown, - - /// Access denied. - /// - /// POSIX equivalent: EACCES, EPERM - access-denied, - - /// The operation is not supported. - /// - /// POSIX equivalent: EOPNOTSUPP - not-supported, - - /// One of the arguments is invalid. - /// - /// POSIX equivalent: EINVAL - invalid-argument, - - /// Not enough memory to complete the operation. - /// - /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY - out-of-memory, - - /// The operation timed out before it could finish completely. - timeout, - - /// This operation is incompatible with another asynchronous operation that is already in progress. - /// - /// POSIX equivalent: EALREADY - concurrency-conflict, - - /// Trying to finish an asynchronous operation that: - /// - has not been started yet, or: - /// - was already finished by a previous `finish-*` call. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - not-in-progress, - - /// The operation has been aborted because it could not be completed immediately. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - would-block, - - - /// The operation is not valid in the socket's current state. - invalid-state, - - /// A new socket resource could not be created because of a system limit. - new-socket-limit, - - /// A bind operation failed because the provided address is not an address that the `network` can bind to. - address-not-bindable, - - /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. - address-in-use, - - /// The remote address is not reachable - remote-unreachable, - - - /// The TCP connection was forcefully rejected - connection-refused, - - /// The TCP connection was reset. - connection-reset, - - /// A TCP connection was aborted. - connection-aborted, - - - /// The size of a datagram sent to a UDP socket exceeded the maximum - /// supported size. - datagram-too-large, - - - /// Name does not exist or has no suitable associated IP addresses. - name-unresolvable, - - /// A temporary failure in name resolution occurred. - temporary-resolver-failure, - - /// A permanent failure in name resolution occurred. - permanent-resolver-failure, - } - - enum ip-address-family { - /// Similar to `AF_INET` in POSIX. - ipv4, - - /// Similar to `AF_INET6` in POSIX. - ipv6, - } - - type ipv4-address = tuple; - type ipv6-address = tuple; - - variant ip-address { - ipv4(ipv4-address), - ipv6(ipv6-address), - } - - record ipv4-socket-address { - /// sin_port - port: u16, - /// sin_addr - address: ipv4-address, - } - - record ipv6-socket-address { - /// sin6_port - port: u16, - /// sin6_flowinfo - flow-info: u32, - /// sin6_addr - address: ipv6-address, - /// sin6_scope_id - scope-id: u32, - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - -} diff --git a/_examples/http-server/wit/deps/sockets/tcp-create-socket.wit b/_examples/http-server/wit/deps/sockets/tcp-create-socket.wit deleted file mode 100644 index c7ddf1f..0000000 --- a/_examples/http-server/wit/deps/sockets/tcp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface tcp-create-socket { - use network.{network, error-code, ip-address-family}; - use tcp.{tcp-socket}; - - /// 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`/`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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - create-tcp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/http-server/wit/deps/sockets/tcp.wit b/_examples/http-server/wit/deps/sockets/tcp.wit deleted file mode 100644 index 5902b9e..0000000 --- a/_examples/http-server/wit/deps/sockets/tcp.wit +++ /dev/null @@ -1,353 +0,0 @@ - -interface tcp { - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/poll@0.2.0.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0.{duration}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - enum shutdown-type { - /// Similar to `SHUT_RD` in POSIX. - receive, - - /// Similar to `SHUT_WR` in POSIX. - send, - - /// Similar to `SHUT_RDWR` in POSIX. - both, - } - - /// A TCP socket resource. - /// - /// The socket can be in one of the following states: - /// - `unbound` - /// - `bind-in-progress` - /// - `bound` (See note below) - /// - `listen-in-progress` - /// - `listening` - /// - `connect-in-progress` - /// - `connected` - /// - `closed` - /// See - /// for a more information. - /// - /// Note: Except where explicitly mentioned, whenever this documentation uses - /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. - /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) - /// - /// In addition to the general error codes documented on the - /// `network::error-code` type, TCP socket methods may always return - /// `error(invalid-state)` when in the `closed` state. - resource tcp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the TCP/UDP port is zero, the socket will be bound to a random free port. - /// - /// Bind can be attempted multiple times on the same socket, even with - /// different arguments on each iteration. But never concurrently and - /// only as long as the previous bind failed. Once a bind succeeds, the - /// binding can't be changed anymore. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) - /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT - /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR - /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior - /// and SO_REUSEADDR performs something different entirely. - /// - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Connect to a remote endpoint. - /// - /// On success: - /// - the socket is transitioned into the `connection` state. - /// - a pair of streams is returned that can be used to read & write to the connection - /// - /// After a failed connection attempt, the socket will be in the `closed` - /// state and the only valid action left is to `drop` the socket. A single - /// socket can not be used to connect more than once. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) - /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) - /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) - /// - `timeout`: Connection timed out. (ETIMEDOUT) - /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) - /// - `connection-reset`: The connection was reset. (ECONNRESET) - /// - `connection-aborted`: The connection was aborted. (ECONNABORTED) - /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `not-in-progress`: A connect operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// The POSIX equivalent of `start-connect` is the regular `connect` syscall. - /// Because all WASI sockets are non-blocking this is expected to return - /// EINPROGRESS, which should be translated to `ok()` in WASI. - /// - /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` - /// with a timeout of 0 on the socket descriptor. Followed by a check for - /// the `SO_ERROR` socket option, in case the poll signaled readiness. - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: func() -> result, error-code>; - - /// Start listening for new connections. - /// - /// Transitions the socket into the `listening` state. - /// - /// Unlike POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the `listening` state. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) - /// - `not-in-progress`: A listen operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the listen operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `listen` as part of either `start-listen` or `finish-listen`. - /// - /// # References - /// - - /// - - /// - - /// - - start-listen: func() -> result<_, error-code>; - finish-listen: func() -> result<_, error-code>; - - /// Accept a new client socket. - /// - /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `keep-alive-enabled` - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// - `hop-limit` - /// - `receive-buffer-size` - /// - `send-buffer-size` - /// - /// On success, this function returns the newly accepted client socket along with - /// a pair of streams that can be used to read & write to the connection. - /// - /// # Typical errors - /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) - /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) - /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - accept: func() -> result, error-code>; - - /// Get the bound local address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the remote address. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether the socket is in the `listening` state. - /// - /// Equivalent to the SO_ACCEPTCONN socket option. - is-listening: func() -> bool; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Hints the desired listen queue size. Implementations are free to ignore this. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// - /// # Typical errors - /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - /// - `invalid-argument`: (set) The provided value was 0. - /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. - set-listen-backlog-size: func(value: u64) -> result<_, error-code>; - - /// Enables or disables keepalive. - /// - /// The keepalive behavior can be adjusted using: - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. - /// - /// Equivalent to the SO_KEEPALIVE socket option. - keep-alive-enabled: func() -> result; - set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; - - /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-idle-time: func() -> result; - set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; - - /// The time between keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPINTVL socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-interval: func() -> result; - set-keep-alive-interval: func(value: duration) -> result<_, error-code>; - - /// The maximum amount of keepalive packets TCP should send before aborting the connection. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPCNT socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-count: func() -> result; - set-keep-alive-count: func(value: u32) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - hop-limit: func() -> result; - set-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which can be used to poll for, or block on, - /// completion of any of the asynchronous operations of this socket. - /// - /// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` - /// return `error(would-block)`, this pollable can be used to wait for - /// their success or failure, after which the method can be retried. - /// - /// The pollable is not limited to the async operation that happens to be - /// in progress at the time of calling `subscribe` (if any). Theoretically, - /// `subscribe` only has to be called once per socket and can then be - /// (re)used for the remainder of the socket's lifetime. - /// - /// See - /// for a more information. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - - /// Initiate a graceful shutdown. - /// - /// - `receive`: The socket is not expecting to receive any data from - /// the peer. The `input-stream` associated with this socket will be - /// closed. Any data still in the receive queue at time of calling - /// this method will be discarded. - /// - `send`: The socket has no more data to send to the peer. The `output-stream` - /// associated with this socket will be closed and a FIN packet will be sent. - /// - `both`: Same effect as `receive` & `send` combined. - /// - /// This function is idempotent. Shutting a down a direction more than once - /// has no effect and returns `ok`. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } -} diff --git a/_examples/http-server/wit/deps/sockets/udp-create-socket.wit b/_examples/http-server/wit/deps/sockets/udp-create-socket.wit deleted file mode 100644 index 0482d1f..0000000 --- a/_examples/http-server/wit/deps/sockets/udp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface udp-create-socket { - use network.{network, error-code, ip-address-family}; - use udp.{udp-socket}; - - /// Create a new UDP socket. - /// - /// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References: - /// - - /// - - /// - - /// - - create-udp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/http-server/wit/deps/sockets/udp.wit b/_examples/http-server/wit/deps/sockets/udp.wit deleted file mode 100644 index d987a0a..0000000 --- a/_examples/http-server/wit/deps/sockets/udp.wit +++ /dev/null @@ -1,266 +0,0 @@ - -interface udp { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - /// A received datagram. - record incoming-datagram { - /// The payload. - /// - /// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - data: list, - - /// The source address. - /// - /// This field is guaranteed to match the remote address the stream was initialized with, if any. - /// - /// Equivalent to the `src_addr` out parameter of `recvfrom`. - remote-address: ip-socket-address, - } - - /// A datagram to be sent out. - record outgoing-datagram { - /// The payload. - data: list, - - /// The destination address. - /// - /// The requirements on this field depend on how the stream was initialized: - /// - with a remote address: this field must be None or match the stream's remote address exactly. - /// - without a remote address: this field is required. - /// - /// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. - remote-address: option, - } - - - - /// A UDP socket handle. - resource udp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the port is zero, the socket will be bound to a random free port. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Set up inbound & outbound communication channels, optionally to a specific peer. - /// - /// This function only changes the local socket configuration and does not generate any network traffic. - /// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, - /// based on the best network path to `remote-address`. - /// - /// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: - /// - `send` can only be used to send to this destination. - /// - `receive` will only return datagrams sent from the provided `remote-address`. - /// - /// This method may be called multiple times on the same socket to change its association, but - /// only the most recently returned pair of streams will be operational. Implementations may trap if - /// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. - /// - /// The POSIX equivalent in pseudo-code is: - /// ```text - /// if (was previously connected) { - /// connect(s, AF_UNSPEC) - /// } - /// if (remote_address is Some) { - /// connect(s, remote_address) - /// } - /// ``` - /// - /// Unlike in POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-state`: The socket is not bound. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - %stream: func(remote-address: option) -> result, error-code>; - - /// Get the current bound address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the address the socket is currently streaming to. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - unicast-hop-limit: func() -> result; - set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which will resolve once the socket is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource incoming-datagram-stream { - /// Receive messages on the socket. - /// - /// This function attempts to receive up to `max-results` datagrams on the socket without blocking. - /// The returned list may contain fewer elements than requested, but never more. - /// - /// This function returns successfully with an empty list when either: - /// - `max-results` is 0, or: - /// - `max-results` is greater than 0, but no results are immediately available. - /// This function never returns `error(would-block)`. - /// - /// # Typical errors - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - receive: func(max-results: u64) -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready to receive again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource outgoing-datagram-stream { - /// Check readiness for sending. This function never blocks. - /// - /// Returns the number of datagrams permitted for the next call to `send`, - /// or an error. Calling `send` with more datagrams than this function has - /// permitted will trap. - /// - /// When this function returns ok(0), the `subscribe` pollable will - /// become ready when this function will report at least ok(1), or an - /// error. - /// - /// Never returns `would-block`. - check-send: func() -> result; - - /// Send messages on the socket. - /// - /// This function attempts to send all provided `datagrams` on the socket without blocking and - /// returns how many messages were actually sent (or queued for sending). This function never - /// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. - /// - /// This function semantically behaves the same as iterating the `datagrams` list and sequentially - /// sending each individual datagram until either the end of the list has been reached or the first error occurred. - /// If at least one datagram has been sent successfully, this function never returns an error. - /// - /// If the input list is empty, the function returns `ok(0)`. - /// - /// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if - /// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) - /// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - send: func(datagrams: list) -> result; - - /// Create a `pollable` which will resolve once the stream is ready to send again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/http-server/wit/deps/sockets/world.wit b/_examples/http-server/wit/deps/sockets/world.wit deleted file mode 100644 index f8bb92a..0000000 --- a/_examples/http-server/wit/deps/sockets/world.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi:sockets@0.2.0; - -world imports { - import instance-network; - import network; - import udp; - import udp-create-socket; - import tcp; - import tcp-create-socket; - import ip-name-lookup; -} diff --git a/_examples/http-server/wit/deps/wasi-cli-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-cli-0.2.0/package.wit new file mode 100644 index 0000000..0a2737b --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-cli-0.2.0/package.wit @@ -0,0 +1,159 @@ +package wasi:cli@0.2.0; + +interface environment { + /// Get the POSIX-style environment variables. + /// + /// Each environment variable is provided as a pair of string variable names + /// and string value. + /// + /// Morally, these are a value import, but until value imports are available + /// in the component model, this import function should return the same + /// values each time it is called. + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + initial-cwd: func() -> option; +} + +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} + +interface run { + /// Run the program. + run: func() -> result; +} + +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} + +/// Terminal input. +/// +/// In the future, this may include functions for disabling echoing, +/// disabling input buffering so that keyboard events are sent through +/// immediately, querying supported features, and so on. +interface terminal-input { + /// The input side of a terminal. + resource terminal-input; +} + +/// Terminal output. +/// +/// In the future, this may include functions for querying the terminal +/// size, being notified of terminal size changes, querying supported +/// features, and so on. +interface terminal-output { + /// The output side of a terminal. + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +interface terminal-stdin { + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +interface terminal-stdout { + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +interface terminal-stderr { + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stderr: func() -> option; +} + +world imports { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; +} +world command { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; + + export run; +} diff --git a/_examples/http-server/wit/deps/wasi-clocks-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-clocks-0.2.0/package.wit new file mode 100644 index 0000000..9e0ba3d --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-clocks-0.2.0/package.wit @@ -0,0 +1,29 @@ +package wasi:clocks@0.2.0; + +interface monotonic-clock { + use wasi:io/poll@0.2.0.{pollable}; + + type instant = u64; + + type duration = u64; + + now: func() -> instant; + + resolution: func() -> duration; + + subscribe-instant: func(when: instant) -> pollable; + + subscribe-duration: func(when: duration) -> pollable; +} + +interface wall-clock { + record datetime { + seconds: u64, + nanoseconds: u32, + } + + now: func() -> datetime; + + resolution: func() -> datetime; +} + diff --git a/_examples/http-server/wit/deps/wasi-config-0.2.0-draft/package.wit b/_examples/http-server/wit/deps/wasi-config-0.2.0-draft/package.wit new file mode 100644 index 0000000..7065b9b --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-config-0.2.0-draft/package.wit @@ -0,0 +1,28 @@ +package wasi:config@0.2.0-draft; + +interface runtime { + /// An error type that encapsulates the different errors that can occur fetching config + variant config-error { + /// This indicates an error from an "upstream" config source. + /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + } + + /// Gets a single opaque config value set at the given key if it exists + get: func(key: string) -> result, config-error>; + + /// Gets a list of all set config data + get-all: func() -> result>, config-error>; +} + +world imports { + import runtime; +} diff --git a/_examples/http-server/wit/deps/wasi-filesystem-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-filesystem-0.2.0/package.wit new file mode 100644 index 0000000..cb6a2be --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-filesystem-0.2.0/package.wit @@ -0,0 +1,158 @@ +package wasi:filesystem@0.2.0; + +interface types { + use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0.{datetime}; + + type filesize = u64; + + enum descriptor-type { + unknown, + block-device, + character-device, + directory, + fifo, + symbolic-link, + regular-file, + socket, + } + + flags descriptor-flags { + read, + write, + file-integrity-sync, + data-integrity-sync, + requested-write-sync, + mutate-directory, + } + + flags path-flags { + symlink-follow, + } + + flags open-flags { + create, + directory, + exclusive, + truncate, + } + + type link-count = u64; + + record descriptor-stat { + %type: descriptor-type, + link-count: link-count, + size: filesize, + data-access-timestamp: option, + data-modification-timestamp: option, + status-change-timestamp: option, + } + + variant new-timestamp { + no-change, + now, + timestamp(datetime), + } + + record directory-entry { + %type: descriptor-type, + name: string, + } + + enum error-code { + 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, + } + + enum advice { + normal, + sequential, + random, + will-need, + dont-need, + no-reuse, + } + + record metadata-hash-value { + lower: u64, + upper: u64, + } + + resource descriptor { + read-via-stream: func(offset: filesize) -> result; + write-via-stream: func(offset: filesize) -> result; + append-via-stream: func() -> result; + advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>; + sync-data: func() -> result<_, error-code>; + get-flags: func() -> result; + get-type: func() -> result; + set-size: func(size: filesize) -> result<_, error-code>; + set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + read: func(length: filesize, offset: filesize) -> result, bool>, error-code>; + write: func(buffer: list, offset: filesize) -> result; + read-directory: func() -> result; + sync: func() -> result<_, error-code>; + create-directory-at: func(path: string) -> result<_, error-code>; + stat: func() -> result; + stat-at: func(path-flags: path-flags, path: string) -> result; + set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result; + readlink-at: func(path: string) -> result; + remove-directory-at: func(path: string) -> result<_, error-code>; + rename-at: func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + symlink-at: func(old-path: string, new-path: string) -> result<_, error-code>; + unlink-file-at: func(path: string) -> result<_, error-code>; + is-same-object: func(other: borrow) -> bool; + metadata-hash: func() -> result; + metadata-hash-at: func(path-flags: path-flags, path: string) -> result; + } + + resource directory-entry-stream { + read-directory-entry: func() -> result, error-code>; + } + + filesystem-error-code: func(err: borrow) -> option; +} + +interface preopens { + use types.{descriptor}; + + get-directories: func() -> list>; +} + diff --git a/_examples/http-client/wit/deps/http/types.wit b/_examples/http-server/wit/deps/wasi-http-0.2.0/package.wit similarity index 88% rename from _examples/http-client/wit/deps/http/types.wit rename to _examples/http-server/wit/deps/wasi-http-0.2.0/package.wit index 755ac6a..11f7ff4 100644 --- a/_examples/http-client/wit/deps/http/types.wit +++ b/_examples/http-server/wit/deps/wasi-http-0.2.0/package.wit @@ -1,3 +1,5 @@ +package wasi:http@0.2.0; + /// 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. @@ -18,18 +20,36 @@ interface types { options, trace, patch, - other(string) + other(string), } /// This type corresponds to HTTP standard Related Schemes. variant scheme { HTTP, HTTPS, - other(string) + other(string), + } + + /// Defines the case payload type for `DNS-error` above: + record DNS-error-payload { + rcode: option, + info-code: option, + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option, } /// 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 + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types variant error-code { DNS-timeout, DNS-error(DNS-error-payload), @@ -74,40 +94,9 @@ interface types { /// unstructured description of the error. Users should not depend on the /// string for diagnosing errors, as it's not required to be consistent /// between implementations. - internal-error(option) - } - - /// Defines the case payload type for `DNS-error` above: - record DNS-error-payload { - rcode: option, - info-code: option - } - - /// Defines the case payload type for `TLS-alert-received` above: - record TLS-alert-received-payload { - alert-id: option, - alert-message: option - } - - /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: - record field-size-payload { - field-name: option, - field-size: option + internal-error(option), } - /// Attempts to extract a http-related `error` from the wasi:io `error` - /// provided. - /// - /// Stream operations which return - /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of - /// type `wasi:io/error/error` with more information about the operation - /// that failed. This payload can be passed through to this function to see - /// if there's http-related information about the error to return. - /// - /// Note that this function is fallible because not all io-errors are - /// http-related errors. - 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. variant header-error { @@ -115,11 +104,9 @@ interface types { /// syntactically invalid when used with an operation that sets headers in a /// `fields`. invalid-syntax, - /// This error indicates that a forbidden `field-key` was used when trying /// to set a header in a `fields`. forbidden, - /// This error indicates that the operation on the `fields` was not /// permitted because the fields are immutable. immutable, @@ -144,12 +131,10 @@ interface types { /// immutable. In an immutable fields, the `set`, `append`, and `delete` /// operations will fail with `header-error.immutable`. resource fields { - /// Construct an empty HTTP Fields. /// /// The resulting `fields` is mutable. constructor(); - /// Construct an HTTP Fields. /// /// The resulting `fields` is mutable. @@ -165,46 +150,37 @@ interface types { /// /// An error result will be returned if any header or value was /// syntactically invalid, or if a header was forbidden. - from-list: static func( - entries: list> - ) -> result; - + from-list: static func(entries: list>) -> result; /// Get all of the values corresponding to a key. If the key is not present /// in this `fields`, 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. 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. has: func(name: field-key) -> bool; - /// Set all of the values for a key. Clears any existing values for that /// key, if they have been set. /// /// Fails with `header-error.immutable` if the `fields` are immutable. set: func(name: field-key, value: list) -> result<_, header-error>; - /// Delete all values for a key. Does nothing if no values for the key /// exist. /// /// Fails with `header-error.immutable` if the `fields` are immutable. delete: func(name: field-key) -> result<_, header-error>; - /// Append a value for a key. Does not change or delete any existing /// values for that key. /// /// Fails with `header-error.immutable` if the `fields` are immutable. append: func(name: field-key, value: field-value) -> result<_, header-error>; - /// 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 /// which have multiple values are represented by multiple entries in this /// list with the same key. - entries: func() -> list>; - + entries: func() -> list>; /// Make a deep copy of the Fields. Equivelant in behavior to calling the /// `fields` constructor on the return value of `entries`. The resulting /// `fields` is mutable. @@ -219,19 +195,14 @@ interface types { /// Represents an incoming HTTP Request. resource incoming-request { - /// Returns the method of the incoming request. method: func() -> method; - /// Returns the path with query parameters from the request, as a string. path-with-query: func() -> option; - /// Returns the protocol scheme from the request. scheme: func() -> option; - /// Returns the authority from the request, if it was present. authority: func() -> option; - /// Get the `headers` associated with the request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -241,7 +212,6 @@ interface types { /// the parent `incoming-request` is dropped. Dropping this /// `incoming-request` before all children are dropped will trap. headers: func() -> headers; - /// Gives the `incoming-body` associated with this request. Will only /// return success at most once, and subsequent calls will return error. consume: func() -> result; @@ -249,7 +219,6 @@ interface types { /// Represents an outgoing HTTP Request. resource outgoing-request { - /// Construct a new `outgoing-request` with a default `method` of `GET`, and /// `none` values for `path-with-query`, `scheme`, and `authority`. /// @@ -260,10 +229,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`. - constructor( - headers: headers - ); - + constructor(headers: headers); /// Returns the resource corresponding to the outgoing Body for this /// Request. /// @@ -271,13 +237,11 @@ interface types { /// this `outgoing-request` can be retrieved at most once. Subsequent /// calls will return error. body: func() -> result; - /// Get the Method for the Request. 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. 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. path-with-query: func() -> option; @@ -285,7 +249,6 @@ interface types { /// 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-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. scheme: func() -> option; @@ -293,7 +256,6 @@ interface types { /// implementation may choose an appropriate default scheme. Fails if the /// string given is not a syntactically valid uri scheme. 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. @@ -303,7 +265,6 @@ interface types { /// HTTPS schemes always require an authority. Fails if the string given is /// not a syntactically valid uri authority. set-authority: func(authority: option) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -324,25 +285,19 @@ interface types { resource request-options { /// Construct a default `request-options` value. constructor(); - /// The timeout for the initial connect to the HTTP Server. 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. set-connect-timeout: func(duration: option) -> result; - /// The timeout for receiving the first byte of the Response body. 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. set-first-byte-timeout: func(duration: option) -> result; - /// The timeout for receiving subsequent chunks of bytes in the Response /// body stream. 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. @@ -355,7 +310,6 @@ interface types { /// allow a Response to be sent corresponding to the Request provided as the /// other argument to `incoming-handler.handle`. resource response-outparam { - /// Set the value of the `response-outparam` to either send a response, /// or indicate an error. /// @@ -365,10 +319,7 @@ interface types { /// /// The user may provide an `error` to `response` to allow the /// implementation determine how to respond with an HTTP error response. - set: static func( - param: response-outparam, - response: result, - ); + set: static func(param: response-outparam, response: result); } /// This type corresponds to the HTTP standard Status Code. @@ -376,10 +327,8 @@ interface types { /// Represents an incoming HTTP Response. resource incoming-response { - /// Returns the status code from the incoming response. status: func() -> status-code; - /// Returns the headers from the incoming response. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -388,7 +337,6 @@ interface types { /// This headers resource is a child: it must be dropped before the parent /// `incoming-response` is dropped. headers: func() -> headers; - /// Returns the incoming body. May be called at most once. Returns error /// if called additional times. consume: func() -> result; @@ -403,7 +351,6 @@ interface types { /// and ensures that the user of this interface may only be consuming either /// the body contents or waiting on trailers at any given time. resource incoming-body { - /// Returns the contents of the body, as a stream of bytes. /// /// Returns success on first call: the stream representing the contents @@ -420,7 +367,6 @@ interface types { /// and for that backpressure to not inhibit delivery of the trailers if /// the user does not read the entire body. %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. finish: static func(this: incoming-body) -> future-trailers; @@ -432,12 +378,10 @@ interface types { /// trailers, this future will resolve to the empty set of trailers once the /// complete Request or Response body has been received. resource future-trailers { - /// Returns a pollable which becomes ready when either the trailers have /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the contents of the trailers, or an error which occured, /// once the future is ready. /// @@ -462,21 +406,17 @@ interface types { /// Represents an outgoing HTTP Response. resource outgoing-response { - /// Construct an `outgoing-response`, with a default `status-code` of `200`. /// If a different `status-code` is needed, it must be set via the /// `set-status-code` method. /// /// * `headers` is the HTTP Headers for the Response. constructor(headers: headers); - /// Get the HTTP Status Code for the Response. 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. set-status-code: func(status-code: status-code) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -486,7 +426,6 @@ interface types { /// `outgoing-request` is dropped, or its ownership is transfered to /// another component by e.g. `outgoing-handler.handle`. headers: func() -> headers; - /// Returns the resource corresponding to the outgoing Body for this Response. /// /// Returns success on the first call: the `outgoing-body` resource for @@ -512,7 +451,6 @@ interface types { /// including: corrupting the body on the wire, aborting the associated /// Request, or sending a late status code for the Response. resource outgoing-body { - /// Returns a stream for writing the body contents. /// /// The returned `output-stream` is a child resource: it must be dropped @@ -523,7 +461,6 @@ interface types { /// this `outgoing-body` may be retrieved at most once. Subsequent calls /// will return error. write: func() -> result; - /// 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 @@ -533,10 +470,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. - finish: static func( - this: outgoing-body, - trailers: option - ) -> result<_, error-code>; + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; } /// Represents a future which may eventaully return an incoming HTTP @@ -549,7 +483,6 @@ interface types { /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the incoming HTTP Response, or an error, once one is ready. /// /// The outer `option` represents future readiness. Users can wait on this @@ -565,6 +498,74 @@ interface types { /// but those will be reported by the `incoming-body` and its /// `output-stream` child. get: func() -> option>>; - } + + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + http-error-code: func(err: borrow) -> option; +} + +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// 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. + handle: func(request: incoming-request, response-out: response-outparam); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error-code}; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// 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`. + handle: func(request: outgoing-request, options: option) -> result; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// 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. +world proxy { + import wasi:random/random@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import types; + import outgoing-handler; + import wasi:clocks/wall-clock@0.2.0; + + export incoming-handler; } diff --git a/_examples/http-server/wit/deps/wasi-io-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-io-0.2.0/package.wit new file mode 100644 index 0000000..1840029 --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-io-0.2.0/package.wit @@ -0,0 +1,48 @@ +package wasi:io@0.2.0; + +interface error { + resource error { + to-debug-string: func() -> string; + } +} + +interface poll { + resource pollable { + ready: func() -> bool; + block: func(); + } + + poll: func(in: list>) -> list; +} + +interface streams { + use error.{error}; + use poll.{pollable}; + + variant stream-error { + last-operation-failed(error), + closed, + } + + resource input-stream { + read: func(len: u64) -> result, stream-error>; + blocking-read: func(len: u64) -> result, stream-error>; + skip: func(len: u64) -> result; + blocking-skip: func(len: u64) -> result; + subscribe: func() -> pollable; + } + + resource output-stream { + check-write: func() -> result; + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) -> result<_, stream-error>; + flush: func() -> result<_, stream-error>; + blocking-flush: func() -> result<_, stream-error>; + subscribe: func() -> pollable; + write-zeroes: func(len: u64) -> result<_, stream-error>; + blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>; + splice: func(src: borrow, len: u64) -> result; + blocking-splice: func(src: borrow, len: u64) -> result; + } +} + diff --git a/_examples/http-server/wit/deps/wasi-logging-0.1.0-draft/package.wit b/_examples/http-server/wit/deps/wasi-logging-0.1.0-draft/package.wit new file mode 100644 index 0000000..df4e8de --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-logging-0.1.0-draft/package.wit @@ -0,0 +1,36 @@ +package wasi:logging; + +/// WASI Logging is a logging API intended to let users emit log messages with +/// simple priority levels and context values. +interface logging { + /// A log level, describing a kind of message. + enum level { + /// Describes messages about the values of variables and the flow of + /// control within a program. + trace, + /// Describes messages likely to be of interest to someone debugging a + /// program. + debug, + /// Describes messages likely to be of interest to someone monitoring a + /// program. + info, + /// Describes messages indicating hazardous situations. + warn, + /// Describes messages indicating serious errors. + error, + /// Describes messages indicating fatal errors. + critical, + } + + /// Emit a log message. + /// + /// A log message has a `level` describing what kind of message is being + /// sent, a context, which is an uninterpreted string meant to help + /// consumers group similar messages, and a string containing the message + /// text. + log: func(level: level, context: string, message: string); +} + +world imports { + import logging; +} diff --git a/_examples/http-server/wit/deps/wasi-random-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-random-0.2.0/package.wit new file mode 100644 index 0000000..58c179e --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-random-0.2.0/package.wit @@ -0,0 +1,18 @@ +package wasi:random@0.2.0; + +interface random { + get-random-bytes: func(len: u64) -> list; + + get-random-u64: func() -> u64; +} + +interface insecure { + get-insecure-random-bytes: func(len: u64) -> list; + + get-insecure-random-u64: func() -> u64; +} + +interface insecure-seed { + insecure-seed: func() -> tuple; +} + diff --git a/_examples/http-server/wit/deps/wasi-sockets-0.2.0/package.wit b/_examples/http-server/wit/deps/wasi-sockets-0.2.0/package.wit new file mode 100644 index 0000000..0602b85 --- /dev/null +++ b/_examples/http-server/wit/deps/wasi-sockets-0.2.0/package.wit @@ -0,0 +1,179 @@ +package wasi:sockets@0.2.0; + +interface network { + resource network; + + enum error-code { + unknown, + access-denied, + not-supported, + invalid-argument, + out-of-memory, + timeout, + concurrency-conflict, + not-in-progress, + would-block, + invalid-state, + new-socket-limit, + address-not-bindable, + address-in-use, + remote-unreachable, + connection-refused, + connection-reset, + connection-aborted, + datagram-too-large, + name-unresolvable, + temporary-resolver-failure, + permanent-resolver-failure, + } + + enum ip-address-family { + ipv4, + ipv6, + } + + type ipv4-address = tuple; + + type ipv6-address = tuple; + + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + record ipv4-socket-address { + port: u16, + address: ipv4-address, + } + + record ipv6-socket-address { + port: u16, + flow-info: u32, + address: ipv6-address, + scope-id: u32, + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } +} + +interface instance-network { + use network.{network}; + + instance-network: func() -> network; +} + +interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + record incoming-datagram { + data: list, + remote-address: ip-socket-address, + } + + record outgoing-datagram { + data: list, + remote-address: option, + } + + resource udp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + %stream: func(remote-address: option) -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + address-family: func() -> ip-address-family; + unicast-hop-limit: func() -> result; + set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + } + + resource incoming-datagram-stream { + receive: func(max-results: u64) -> result, error-code>; + subscribe: func() -> pollable; + } + + resource outgoing-datagram-stream { + check-send: func() -> result; + send: func(datagrams: list) -> result; + subscribe: func() -> pollable; + } +} + +interface udp-create-socket { + use network.{network, error-code, ip-address-family}; + use udp.{udp-socket}; + + create-udp-socket: func(address-family: ip-address-family) -> result; +} + +interface tcp { + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/poll@0.2.0.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + enum shutdown-type { + receive, + send, + both, + } + + resource tcp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + finish-connect: func() -> result, error-code>; + start-listen: func() -> result<_, error-code>; + finish-listen: func() -> result<_, error-code>; + accept: func() -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + is-listening: func() -> bool; + address-family: func() -> ip-address-family; + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + keep-alive-enabled: func() -> result; + set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; + keep-alive-idle-time: func() -> result; + set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; + keep-alive-interval: func() -> result; + set-keep-alive-interval: func(value: duration) -> result<_, error-code>; + keep-alive-count: func() -> result; + set-keep-alive-count: func(value: u32) -> result<_, error-code>; + hop-limit: func() -> result; + set-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} + +interface tcp-create-socket { + use network.{network, error-code, ip-address-family}; + use tcp.{tcp-socket}; + + create-tcp-socket: func(address-family: ip-address-family) -> result; +} + +interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-address}; + + resource resolve-address-stream { + resolve-next-address: func() -> result, error-code>; + subscribe: func() -> pollable; + } + + resolve-addresses: func(network: borrow, name: string) -> result; +} + diff --git a/_examples/http-server/wit/deps/wasmcloud-bus-1.0.0/package.wit b/_examples/http-server/wit/deps/wasmcloud-bus-1.0.0/package.wit new file mode 100644 index 0000000..1008a6f --- /dev/null +++ b/_examples/http-server/wit/deps/wasmcloud-bus-1.0.0/package.wit @@ -0,0 +1,15 @@ +package wasmcloud:bus@1.0.0; + +interface lattice { + /// Interface target. This represents an interface, which can be selected by `set-link-name`. + resource call-target-interface { + constructor(namespace: string, %package: string, %interface: string); + } + + /// Set an optional link name to use for all interfaces specified. This is advanced + /// functionality only available within wasmcloud and, as such, is exposed here as part of the + /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces + /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component + set-link-name: func(name: string, interfaces: list); +} + diff --git a/_examples/invoke/wit/deps/component/world.wit b/_examples/http-server/wit/deps/wasmcloud-component-go/world.wit similarity index 77% rename from _examples/invoke/wit/deps/component/world.wit rename to _examples/http-server/wit/deps/wasmcloud-component-go/world.wit index 186845a..f881ff8 100644 --- a/_examples/invoke/wit/deps/component/world.wit +++ b/_examples/http-server/wit/deps/wasmcloud-component-go/world.wit @@ -1,11 +1,8 @@ -package wasmcloud:component; +package wasmcloud:component-go@0.1.0; world exports { // wasi export wasi:http/incoming-handler@0.2.0; - - // wasmcloud - export wasmcloud:messaging/handler@0.2.0; } world imports { @@ -19,7 +16,6 @@ world imports { // wasmcloud import wasmcloud:bus/lattice@1.0.0; - import wasmcloud:messaging/consumer@0.2.0; import wasmcloud:secrets/store@0.1.0-draft; import wasmcloud:secrets/reveal@0.1.0-draft; } diff --git a/_examples/http-server/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit b/_examples/http-server/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit new file mode 100644 index 0000000..a431b95 --- /dev/null +++ b/_examples/http-server/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit @@ -0,0 +1,52 @@ +/// This WIT interface powers secret support in wasmCloud +/// +/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 +package wasmcloud:secrets@0.1.0-draft; + +interface store { + /// An error type that encapsulates the different errors that can occur fetching secrets + variant secrets-error { + /// This indicates an error from an "upstream" secrets source. + /// As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + /// This indicates that the secret was not found. Generally "not found" errors will + /// be handled by the upstream secrets backend, but there are cases where the host + /// may need to return this error. + not-found, + } + + /// A secret value can be either a string or a byte array, which lets you + /// store binary data as a secret. + variant secret-value { + /// A string value + %string(string), + /// A byte array value + bytes(list), + } + + /// A secret is a resource that can only be borrowed. This allows you to + /// pass around handles to secrets and not reveal the values until a + /// component needs them. + /// You need to use the reveal interface to get the value. + resource secret; + + /// Gets a single opaque secrets value set at the given key if it exists + get: func(key: string) -> result; +} + +interface reveal { + use store.{secret, secret-value}; + + /// Reveals the value of a secret to the caller. + /// This lets you easily audit your code to discover where secrets are being used. + reveal: func(s: borrow) -> secret-value; +} + diff --git a/_examples/http-server/wit/world.wit b/_examples/http-server/wit/world.wit index 26d8a35..4240d18 100644 --- a/_examples/http-server/wit/world.wit +++ b/_examples/http-server/wit/world.wit @@ -1,6 +1,6 @@ package example:http-server; world example { - include wasmcloud:component/imports; + include wasmcloud:component-go/imports@0.1.0; export wasi:http/incoming-handler@0.2.0; } diff --git a/_examples/invoke/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go b/_examples/invoke/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go index 8367885..5e83bb4 100644 --- a/_examples/invoke/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go +++ b/_examples/invoke/gen/wasi/clocks/monotonic-clock/monotonic-clock.wit.go @@ -1,17 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". -// -// WASI Monotonic Clock is a clock API intended to let users measure elapsed -// time. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// 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. package monotonicclock import ( @@ -21,27 +10,16 @@ import ( // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". // -// 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. -// // type instant = u64 type Instant uint64 // Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". // -// A duration of time, in nanoseconds. -// // type duration = u64 type Duration uint64 // Now represents the imported function "now". // -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. -// // now: func() -> instant // //go:nosplit @@ -57,9 +35,6 @@ func wasmimport_Now() (result0 uint64) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. -// // resolution: func() -> duration // //go:nosplit @@ -75,9 +50,6 @@ func wasmimport_Resolution() (result0 uint64) // SubscribeInstant represents the imported function "subscribe-instant". // -// Create a `pollable` which will resolve once the specified instant -// occured. -// // subscribe-instant: func(when: instant) -> pollable // //go:nosplit @@ -94,10 +66,6 @@ func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. -// // subscribe-duration: func(when: duration) -> pollable // //go:nosplit diff --git a/_examples/invoke/gen/wasi/clocks/wall-clock/wall-clock.wit.go b/_examples/invoke/gen/wasi/clocks/wall-clock/wall-clock.wit.go index a59a313..9f425d8 100644 --- a/_examples/invoke/gen/wasi/clocks/wall-clock/wall-clock.wit.go +++ b/_examples/invoke/gen/wasi/clocks/wall-clock/wall-clock.wit.go @@ -1,54 +1,28 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". -// -// 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. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// A wall clock is a clock which measures the date and time according to -// some external reference. -// -// External references may be reset, so this clock is not necessarily -// monotonic, making it unsuitable for measuring elapsed time. -// -// It is intended for reporting the current date and time for humans. package wallclock +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + // DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". // -// A time and date in seconds plus nanoseconds. -// // record datetime { // seconds: u64, // nanoseconds: u32, // } type DateTime struct { + _ cm.HostLayout Seconds uint64 Nanoseconds uint32 } // Now represents the imported function "now". // -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// // now: func() -> datetime // -// [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 -// //go:nosplit func Now() (result DateTime) { wasmimport_Now(&result) @@ -61,10 +35,6 @@ func wasmimport_Now(result *DateTime) // Resolution represents the imported function "resolution". // -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -// // resolution: func() -> datetime // //go:nosplit diff --git a/_examples/invoke/gen/wasi/filesystem/preopens/preopens.wit.go b/_examples/invoke/gen/wasi/filesystem/preopens/preopens.wit.go index ec0cd4a..6ef6166 100644 --- a/_examples/invoke/gen/wasi/filesystem/preopens/preopens.wit.go +++ b/_examples/invoke/gen/wasi/filesystem/preopens/preopens.wit.go @@ -10,8 +10,6 @@ import ( // GetDirectories represents the imported function "get-directories". // -// Return the set of preopened directories, and their path. -// // get-directories: func() -> list> // //go:nosplit diff --git a/_examples/invoke/gen/wasi/filesystem/types/types.wit.go b/_examples/invoke/gen/wasi/filesystem/types/types.wit.go index 7f2eb3d..97cd3fd 100644 --- a/_examples/invoke/gen/wasi/filesystem/types/types.wit.go +++ b/_examples/invoke/gen/wasi/filesystem/types/types.wit.go @@ -1,31 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package types represents the imported interface "wasi:filesystem/types@0.2.0". -// -// WASI filesystem is a filesystem API primarily intended to let users run WASI -// programs that access their files on their existing filesystems, without -// significant overhead. -// -// It is intended to be roughly portable between Unix-family platforms and -// Windows, though it does not hide many of the major differences. -// -// Paths are passed as interface-type `string`s, meaning they must consist of -// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -// paths which are not accessible by this API. -// -// The directory separator in WASI is always the forward-slash (`/`). -// -// All paths in WASI are relative paths, and are interpreted relative to a -// `descriptor` referring to a base directory. If a `path` argument to any WASI -// function starts with `/`, or if any step of resolving a `path`, including -// `..` and symbolic link steps, reaches a directory outside of the base -// directory, or reaches a symlink to an absolute or rooted path in the -// underlying filesystem, the function fails with `error-code::not-permitted`. -// -// For more information about WASI path resolution and sandboxing, see -// [WASI filesystem path resolution]. -// -// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md package types import ( @@ -37,17 +12,11 @@ import ( // FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". // -// File size or length of a region within a file. -// // type filesize = u64 type FileSize uint64 // DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". // -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. -// // enum descriptor-type { // unknown, // block-device, @@ -61,29 +30,13 @@ type FileSize uint64 type DescriptorType uint8 const ( - // The type of the descriptor or file is unknown or is different from - // any of the other types specified. DescriptorTypeUnknown DescriptorType = iota - - // The descriptor refers to a block device inode. DescriptorTypeBlockDevice - - // The descriptor refers to a character device inode. DescriptorTypeCharacterDevice - - // The descriptor refers to a directory inode. DescriptorTypeDirectory - - // The descriptor refers to a named pipe. DescriptorTypeFIFO - - // The file refers to a symbolic link inode. DescriptorTypeSymbolicLink - - // The descriptor refers to a regular file inode. DescriptorTypeRegularFile - - // The descriptor refers to a socket. DescriptorTypeSocket ) @@ -105,10 +58,6 @@ func (e DescriptorType) String() string { // DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". // -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. -// // flags descriptor-flags { // read, // write, @@ -120,69 +69,27 @@ func (e DescriptorType) String() string { type DescriptorFlags uint8 const ( - // Read mode: Data can be read. DescriptorFlagsRead DescriptorFlags = 1 << iota - - // Write mode: Data can be written to. DescriptorFlagsWrite - - // Request that writes be performed according to synchronized I/O file - // integrity completion. The data stored in the file and the file's - // metadata are synchronized. This is similar to `O_SYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsFileIntegritySync - - // Request that writes be performed according to synchronized I/O data - // integrity completion. Only the data stored in the file is - // synchronized. This is similar to `O_DSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsDataIntegritySync - - // Requests that reads be performed at the same level of integrety - // requested for writes. This is similar to `O_RSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. DescriptorFlagsRequestedWriteSync - - // Mutating directories mode: Directory contents may be mutated. - // - // When this flag is unset on a descriptor, operations using the - // descriptor which would create, rename, delete, modify the data or - // metadata of filesystem objects, or obtain another handle which - // would permit any of those, shall fail with `error-code::read-only` if - // they would otherwise succeed. - // - // This may only be set on directories. DescriptorFlagsMutateDirectory ) // PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". // -// Flags determining the method of how paths are resolved. -// // flags path-flags { // symlink-follow, // } type PathFlags uint8 const ( - // As long as the resolved path corresponds to a symbolic link, it is - // expanded. PathFlagsSymlinkFollow PathFlags = 1 << iota ) // OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". // -// Open flags used by `open-at`. -// // flags open-flags { // create, // directory, @@ -192,32 +99,19 @@ const ( type OpenFlags uint8 const ( - // Create file if it does not exist, similar to `O_CREAT` in POSIX. OpenFlagsCreate OpenFlags = 1 << iota - - // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. OpenFlagsDirectory - - // Fail if file already exists, similar to `O_EXCL` in POSIX. OpenFlagsExclusive - - // Truncate file to size 0, similar to `O_TRUNC` in POSIX. OpenFlagsTruncate ) // LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". // -// Number of hard links to an inode. -// // type link-count = u64 type LinkCount uint64 // DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". // -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. -// // record descriptor-stat { // %type: descriptor-type, // link-count: link-count, @@ -227,39 +121,17 @@ type LinkCount uint64 // status-change-timestamp: option, // } type DescriptorStat struct { - // File type. - Type DescriptorType - - // Number of hard links to the file. - LinkCount LinkCount - - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. - Size FileSize - - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - DataAccessTimestamp cm.Option[wallclock.DateTime] - - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. + _ cm.HostLayout + Type DescriptorType + LinkCount LinkCount + Size FileSize + DataAccessTimestamp cm.Option[wallclock.DateTime] DataModificationTimestamp cm.Option[wallclock.DateTime] - - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. - StatusChangeTimestamp cm.Option[wallclock.DateTime] + StatusChangeTimestamp cm.Option[wallclock.DateTime] } // NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". // -// When setting a timestamp, this gives the value to set it to. -// // variant new-timestamp { // no-change, // now, @@ -268,8 +140,6 @@ type DescriptorStat struct { type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] // NewTimestampNoChange returns a [NewTimestamp] of case "no-change". -// -// Leave the timestamp set to its previous value. func NewTimestampNoChange() NewTimestamp { var data struct{} return cm.New[NewTimestamp](0, data) @@ -281,9 +151,6 @@ func (self *NewTimestamp) NoChange() bool { } // NewTimestampNow returns a [NewTimestamp] of case "now". -// -// Set the timestamp to the current time of the system clock associated -// with the filesystem. func NewTimestampNow() NewTimestamp { var data struct{} return cm.New[NewTimestamp](1, data) @@ -295,8 +162,6 @@ func (self *NewTimestamp) Now() bool { } // NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". -// -// Set the timestamp to the given value. func NewTimestampTimestamp(data wallclock.DateTime) NewTimestamp { return cm.New[NewTimestamp](2, data) } @@ -308,27 +173,18 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { // DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". // -// A directory entry. -// // record directory-entry { // %type: descriptor-type, // name: string, // } type DirectoryEntry struct { - // The type of the file referred to by this directory entry. + _ cm.HostLayout Type DescriptorType - - // The name of the object. Name string } // ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". // -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. -// // enum error-code { // access, // would-block, @@ -371,116 +227,42 @@ type DirectoryEntry struct { type ErrorCode uint8 const ( - // Permission denied, similar to `EACCES` in POSIX. ErrorCodeAccess ErrorCode = iota - - // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` - // in POSIX. ErrorCodeWouldBlock - - // Connection already in progress, similar to `EALREADY` in POSIX. ErrorCodeAlready - - // Bad descriptor, similar to `EBADF` in POSIX. ErrorCodeBadDescriptor - - // Device or resource busy, similar to `EBUSY` in POSIX. ErrorCodeBusy - - // Resource deadlock would occur, similar to `EDEADLK` in POSIX. ErrorCodeDeadlock - - // Storage quota exceeded, similar to `EDQUOT` in POSIX. ErrorCodeQuota - - // File exists, similar to `EEXIST` in POSIX. ErrorCodeExist - - // File too large, similar to `EFBIG` in POSIX. ErrorCodeFileTooLarge - - // Illegal byte sequence, similar to `EILSEQ` in POSIX. ErrorCodeIllegalByteSequence - - // Operation in progress, similar to `EINPROGRESS` in POSIX. ErrorCodeInProgress - - // Interrupted function, similar to `EINTR` in POSIX. ErrorCodeInterrupted - - // Invalid argument, similar to `EINVAL` in POSIX. ErrorCodeInvalid - - // I/O error, similar to `EIO` in POSIX. ErrorCodeIO - - // Is a directory, similar to `EISDIR` in POSIX. ErrorCodeIsDirectory - - // Too many levels of symbolic links, similar to `ELOOP` in POSIX. ErrorCodeLoop - - // Too many links, similar to `EMLINK` in POSIX. ErrorCodeTooManyLinks - - // Message too large, similar to `EMSGSIZE` in POSIX. ErrorCodeMessageSize - - // Filename too long, similar to `ENAMETOOLONG` in POSIX. ErrorCodeNameTooLong - - // No such device, similar to `ENODEV` in POSIX. ErrorCodeNoDevice - - // No such file or directory, similar to `ENOENT` in POSIX. ErrorCodeNoEntry - - // No locks available, similar to `ENOLCK` in POSIX. ErrorCodeNoLock - - // Not enough space, similar to `ENOMEM` in POSIX. ErrorCodeInsufficientMemory - - // No space left on device, similar to `ENOSPC` in POSIX. ErrorCodeInsufficientSpace - - // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. ErrorCodeNotDirectory - - // Directory not empty, similar to `ENOTEMPTY` in POSIX. ErrorCodeNotEmpty - - // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. ErrorCodeNotRecoverable - - // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. ErrorCodeUnsupported - - // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. ErrorCodeNoTTY - - // No such device or address, similar to `ENXIO` in POSIX. ErrorCodeNoSuchDevice - - // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. ErrorCodeOverflow - - // Operation not permitted, similar to `EPERM` in POSIX. ErrorCodeNotPermitted - - // Broken pipe, similar to `EPIPE` in POSIX. ErrorCodePipe - - // Read-only file system, similar to `EROFS` in POSIX. ErrorCodeReadOnly - - // Invalid seek, similar to `ESPIPE` in POSIX. ErrorCodeInvalidSeek - - // Text file busy, similar to `ETXTBSY` in POSIX. ErrorCodeTextFileBusy - - // Cross-device link, similar to `EXDEV` in POSIX. ErrorCodeCrossDevice ) @@ -531,8 +313,6 @@ func (e ErrorCode) String() string { // Advice represents the enum "wasi:filesystem/types@0.2.0#advice". // -// File or memory access pattern advisory information. -// // enum advice { // normal, // sequential, @@ -544,28 +324,11 @@ func (e ErrorCode) String() string { type Advice uint8 const ( - // The application has no advice to give on its behavior with respect - // to the specified data. AdviceNormal Advice = iota - - // The application expects to access the specified data sequentially - // from lower offsets to higher offsets. AdviceSequential - - // The application expects to access the specified data in a random - // order. AdviceRandom - - // The application expects to access the specified data in the near - // future. AdviceWillNeed - - // The application expects that it will not access the specified data - // in the near future. AdviceDontNeed - - // The application expects to access the specified data once and then - // not reuse it thereafter. AdviceNoReuse ) @@ -585,27 +348,18 @@ func (e Advice) String() string { // MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". // -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -// // record metadata-hash-value { // lower: u64, // upper: u64, // } type MetadataHashValue struct { - // 64 bits of a 128-bit hash value. + _ cm.HostLayout Lower uint64 - - // Another 64 bits of a 128-bit hash value. Upper uint64 } // Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". // -// 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. -// // resource descriptor type Descriptor cm.Resource @@ -626,10 +380,6 @@ func wasmimport_DescriptorResourceDrop(self0 uint32) // Advise represents the imported method "advise". // -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. -// // advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> // //go:nosplit @@ -648,13 +398,6 @@ func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, a // AppendViaStream represents the imported method "append-via-stream". // -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. -// // append-via-stream: func() -> result // //go:nosplit @@ -670,10 +413,6 @@ func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[stream // CreateDirectoryAt represents the imported method "create-directory-at". // -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. -// // create-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -690,13 +429,6 @@ func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 ui // GetFlags represents the imported method "get-flags". // -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-flags: func() -> result // //go:nosplit @@ -712,17 +444,6 @@ func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFla // GetType represents the imported method "get-type". // -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. -// // get-type: func() -> result // //go:nosplit @@ -738,13 +459,6 @@ func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType // IsSameObject represents the imported method "is-same-object". // -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// 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. -// // is-same-object: func(other: borrow) -> bool // //go:nosplit @@ -762,10 +476,6 @@ func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uin // LinkAt represents the imported method "link-at". // -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. -// // link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, // new-path: string) -> result<_, error-code> // @@ -786,26 +496,6 @@ func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *u // MetadataHash represents the imported method "metadata-hash". // -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. -// // metadata-hash: func() -> result // //go:nosplit @@ -821,11 +511,6 @@ func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataH // MetadataHashAt represents the imported method "metadata-hash-at". // -// 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`. -// // metadata-hash-at: func(path-flags: path-flags, path: string) -> result // @@ -844,25 +529,6 @@ func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 // OpenAt represents the imported method "open-at". // -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// descriptor not currently open/ it is randomized to prevent applications -// from depending on making assumptions about indexes, since this is -// error-prone in multi-threaded contexts. The returned descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. -// // open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: // descriptor-flags) -> result // @@ -883,18 +549,6 @@ func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // Read represents the imported method "read". // -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. -// // read: func(length: filesize, offset: filesize) -> result, bool>, // error-code> // @@ -913,16 +567,6 @@ func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, res // ReadDirectory represents the imported method "read-directory". // -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// 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. -// // read-directory: func() -> result // //go:nosplit @@ -938,15 +582,6 @@ func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[Director // ReadViaStream represents the imported method "read-via-stream". // -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. -// // read-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -963,13 +598,6 @@ func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm // ReadLinkAt represents the imported method "readlink-at". // -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. -// // readlink-at: func(path: string) -> result // //go:nosplit @@ -986,12 +614,6 @@ func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, r // RemoveDirectoryAt represents the imported method "remove-directory-at". // -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. -// // remove-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1008,10 +630,6 @@ func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 ui // RenameAt represents the imported method "rename-at". // -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. -// // rename-at: func(old-path: string, new-descriptor: borrow, new-path: // string) -> result<_, error-code> // @@ -1031,11 +649,6 @@ func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint3 // SetSize represents the imported method "set-size". // -// 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. -// // set-size: func(size: filesize) -> result<_, error-code> // //go:nosplit @@ -1052,12 +665,6 @@ func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ // SetTimes represents the imported method "set-times". // -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -// // set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: // new-timestamp) -> result<_, error-code> // @@ -1076,13 +683,6 @@ func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, da // SetTimesAt represents the imported method "set-times-at". // -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. -// // set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: // new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> // @@ -1103,16 +703,6 @@ func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uin // Stat represents the imported method "stat". // -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. -// // stat: func() -> result // //go:nosplit @@ -1128,14 +718,6 @@ func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatSha // StatAt represents the imported method "stat-at". // -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. -// // stat-at: func(path-flags: path-flags, path: string) -> result // @@ -1154,13 +736,6 @@ func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, // SymlinkAt represents the imported method "symlink-at". // -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. -// // symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> // //go:nosplit @@ -1178,13 +753,6 @@ func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint // Sync represents the imported method "sync". // -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. -// // sync: func() -> result<_, error-code> // //go:nosplit @@ -1200,13 +768,6 @@ func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct // SyncData represents the imported method "sync-data". // -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. -// // sync-data: func() -> result<_, error-code> // //go:nosplit @@ -1222,11 +783,6 @@ func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, st // UnlinkFileAt represents the imported method "unlink-file-at". // -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. -// // unlink-file-at: func(path: string) -> result<_, error-code> // //go:nosplit @@ -1243,16 +799,6 @@ func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, // Write represents the imported method "write". // -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. -// // write: func(buffer: list, offset: filesize) -> result // //go:nosplit @@ -1270,13 +816,6 @@ func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, of // WriteViaStream represents the imported method "write-via-stream". // -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. -// // write-via-stream: func(offset: filesize) -> result // //go:nosplit @@ -1293,8 +832,6 @@ func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *c // DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". // -// A stream of directory entries. -// // resource directory-entry-stream type DirectoryEntryStream cm.Resource @@ -1315,8 +852,6 @@ func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) // ReadDirectoryEntry represents the imported method "read-directory-entry". // -// Read a single directory entry from a `directory-entry-stream`. -// // read-directory-entry: func() -> result, error-code> // //go:nosplit @@ -1332,17 +867,6 @@ func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm. // FilesystemErrorCode represents the imported function "filesystem-error-code". // -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. -// // filesystem-error-code: func(err: borrow) -> option // //go:nosplit diff --git a/_examples/invoke/gen/wasi/http/types/types.wit.go b/_examples/invoke/gen/wasi/http/types/types.wit.go index c7a9fcf..24f0a7a 100644 --- a/_examples/invoke/gen/wasi/http/types/types.wit.go +++ b/_examples/invoke/gen/wasi/http/types/types.wit.go @@ -194,6 +194,7 @@ func (self *Scheme) Other() *string { // info-code: option, // } type DNSErrorPayload struct { + _ cm.HostLayout Rcode cm.Option[string] InfoCode cm.Option[uint16] } @@ -207,6 +208,7 @@ type DNSErrorPayload struct { // alert-message: option, // } type TLSAlertReceivedPayload struct { + _ cm.HostLayout AlertID cm.Option[uint8] AlertMessage cm.Option[string] } @@ -220,6 +222,7 @@ type TLSAlertReceivedPayload struct { // field-size: option, // } type FieldSizePayload struct { + _ cm.HostLayout FieldName cm.Option[string] FieldSize cm.Option[uint32] } diff --git a/_examples/invoke/gen/wasi/io/error/error.wit.go b/_examples/invoke/gen/wasi/io/error/error.wit.go index 61d61db..6a2cf9b 100644 --- a/_examples/invoke/gen/wasi/io/error/error.wit.go +++ b/_examples/invoke/gen/wasi/io/error/error.wit.go @@ -9,26 +9,6 @@ import ( // Error represents the imported resource "wasi:io/error@0.2.0#error". // -// A resource which represents some error information. -// -// The only method provided by this resource is `to-debug-string`, -// 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, `error`s 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` and returns -// `option`. -// -// The set of functions which can "downcast" an `error` into a more -// concrete type is open. -// // resource error type Error cm.Resource @@ -49,14 +29,6 @@ func wasmimport_ErrorResourceDrop(self0 uint32) // ToDebugString represents the imported method "to-debug-string". // -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. -// // to-debug-string: func() -> string // //go:nosplit diff --git a/_examples/invoke/gen/wasi/io/poll/poll.wit.go b/_examples/invoke/gen/wasi/io/poll/poll.wit.go index d11852f..d111f72 100644 --- a/_examples/invoke/gen/wasi/io/poll/poll.wit.go +++ b/_examples/invoke/gen/wasi/io/poll/poll.wit.go @@ -1,9 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package poll represents the imported interface "wasi:io/poll@0.2.0". -// -// A poll API intended to let users wait for I/O events on multiple handles -// at once. package poll import ( @@ -12,8 +9,6 @@ import ( // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". // -// `pollable` represents a single I/O event which may be ready, or not. -// // resource pollable type Pollable cm.Resource @@ -34,12 +29,6 @@ func wasmimport_PollableResourceDrop(self0 uint32) // Block represents the imported method "block". // -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. -// // block: func() // //go:nosplit @@ -55,10 +44,6 @@ func wasmimport_PollableBlock(self0 uint32) // Ready represents the imported method "ready". // -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. -// // ready: func() -> bool // //go:nosplit @@ -75,25 +60,6 @@ func wasmimport_PollableReady(self0 uint32) (result0 uint32) // Poll represents the imported function "poll". // -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` 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. -// -// 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. -// // poll: func(in: list>) -> list // //go:nosplit diff --git a/_examples/invoke/gen/wasi/io/streams/streams.wit.go b/_examples/invoke/gen/wasi/io/streams/streams.wit.go index 2a61880..fb08437 100644 --- a/_examples/invoke/gen/wasi/io/streams/streams.wit.go +++ b/_examples/invoke/gen/wasi/io/streams/streams.wit.go @@ -1,12 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package streams represents the imported interface "wasi:io/streams@0.2.0". -// -// 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; -// when it does, they are expected to subsume this API. package streams import ( @@ -17,8 +11,6 @@ import ( // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". // -// An error for input-stream and output-stream operations. -// // variant stream-error { // last-operation-failed(error), // closed, @@ -26,10 +18,6 @@ import ( type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] // StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". -// -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { return cm.New[StreamError](0, data) } @@ -40,10 +28,6 @@ func (self *StreamError) LastOperationFailed() *ioerror.Error { } // StreamErrorClosed returns a [StreamError] of case "closed". -// -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. func StreamErrorClosed() StreamError { var data struct{} return cm.New[StreamError](1, data) @@ -56,15 +40,6 @@ func (self *StreamError) Closed() bool { // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". // -// An input bytestream. -// -// `input-stream`s are *non-blocking* to the extent practical on underlying -// platforms. I/O operations always return promptly; if fewer bytes are -// promptly available than requested, they return the number of bytes promptly -// available, which could even be zero. To wait for data to be available, -// use the `subscribe` function to obtain a `pollable` which can be polled -// for using `wasi:io/poll`. -// // resource input-stream type InputStream cm.Resource @@ -85,9 +60,6 @@ func wasmimport_InputStreamResourceDrop(self0 uint32) // BlockingRead represents the imported method "blocking-read". // -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. -// // blocking-read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -104,9 +76,6 @@ func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Re // BlockingSkip represents the imported method "blocking-skip". // -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. -// // blocking-skip: func(len: u64) -> result // //go:nosplit @@ -123,33 +92,6 @@ func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Re // Read represents the imported method "read". // -// 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 -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// 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. -// // read: func(len: u64) -> result, stream-error> // //go:nosplit @@ -166,11 +108,6 @@ func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm. // Skip represents the imported method "skip". // -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. -// // skip: func(len: u64) -> result // //go:nosplit @@ -187,13 +124,6 @@ func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uin // Subscribe represents the imported method "subscribe". // -// 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. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -210,15 +140,6 @@ func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) // OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". // -// An output bytestream. -// -// `output-stream`s 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`. -// // resource output-stream type OutputStream cm.Resource @@ -239,9 +160,6 @@ func wasmimport_OutputStreamResourceDrop(self0 uint32) // BlockingFlush represents the imported method "blocking-flush". // -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. -// // blocking-flush: func() -> result<_, stream-error> // //go:nosplit @@ -257,12 +175,6 @@ func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[Stream // BlockingSplice represents the imported method "blocking-splice". // -// 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`. -// // blocking-splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -280,29 +192,6 @@ func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint6 // BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". // -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-and-flush: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -319,29 +208,6 @@ func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8 // BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". // -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// 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` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// // blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> // //go:nosplit @@ -358,16 +224,6 @@ func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint6 // CheckWrite represents the imported method "check-write". // -// 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 -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. -// // check-write: func() -> result // //go:nosplit @@ -383,17 +239,6 @@ func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, u // Flush represents the imported method "flush". // -// 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 -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. -// // flush: func() -> result<_, stream-error> // //go:nosplit @@ -409,20 +254,6 @@ func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, s // Splice represents the imported method "splice". // -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. -// // splice: func(src: borrow, len: u64) -> result // //go:nosplit @@ -440,17 +271,6 @@ func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, resul // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. 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. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -// // subscribe: func() -> pollable // //go:nosplit @@ -467,20 +287,6 @@ func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) // Write represents the imported method "write". // -// 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. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. -// // write: func(contents: list) -> result<_, stream-error> // //go:nosplit @@ -497,13 +303,6 @@ func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint // WriteZeroes represents the imported method "write-zeroes". // -// Write zeroes to a stream. -// -// 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. -// // write-zeroes: func(len: u64) -> result<_, stream-error> // //go:nosplit diff --git a/_examples/invoke/gen/wasi/random/insecure-seed/insecure-seed.wit.go b/_examples/invoke/gen/wasi/random/insecure-seed/insecure-seed.wit.go index 3b8f33c..27f899f 100644 --- a/_examples/invoke/gen/wasi/random/insecure-seed/insecure-seed.wit.go +++ b/_examples/invoke/gen/wasi/random/insecure-seed/insecure-seed.wit.go @@ -1,33 +1,10 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". -// -// The insecure-seed interface for seeding hash-map DoS resistance. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecureseed // InsecureSeed represents the imported function "insecure-seed". // -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. -// // insecure-seed: func() -> tuple // //go:nosplit diff --git a/_examples/invoke/gen/wasi/random/insecure/insecure.wit.go b/_examples/invoke/gen/wasi/random/insecure/insecure.wit.go index bfe1e6c..8ff72e3 100644 --- a/_examples/invoke/gen/wasi/random/insecure/insecure.wit.go +++ b/_examples/invoke/gen/wasi/random/insecure/insecure.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package insecure represents the imported interface "wasi:random/insecure@0.2.0". -// -// The insecure interface for insecure pseudo-random numbers. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package insecure import ( @@ -14,15 +9,6 @@ import ( // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". // -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. -// // get-insecure-random-bytes: func(len: u64) -> list // //go:nosplit @@ -38,11 +24,6 @@ func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) // GetInsecureRandomU64 represents the imported function "get-insecure-random-u64". // -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. -// // get-insecure-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/invoke/gen/wasi/random/random/random.wit.go b/_examples/invoke/gen/wasi/random/random/random.wit.go index da2eb57..b7d24e4 100644 --- a/_examples/invoke/gen/wasi/random/random/random.wit.go +++ b/_examples/invoke/gen/wasi/random/random/random.wit.go @@ -1,11 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package random represents the imported interface "wasi:random/random@0.2.0". -// -// WASI Random is a random data API. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. package random import ( @@ -14,19 +9,6 @@ import ( // GetRandomBytes represents the imported function "get-random-bytes". // -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. -// // get-random-bytes: func(len: u64) -> list // //go:nosplit @@ -42,11 +24,6 @@ func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) // GetRandomU64 represents the imported function "get-random-u64". // -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. -// // get-random-u64: func() -> u64 // //go:nosplit diff --git a/_examples/invoke/gen/wasi/sockets/instance-network/instance-network.wit.go b/_examples/invoke/gen/wasi/sockets/instance-network/instance-network.wit.go index 9df0a04..02a8556 100644 --- a/_examples/invoke/gen/wasi/sockets/instance-network/instance-network.wit.go +++ b/_examples/invoke/gen/wasi/sockets/instance-network/instance-network.wit.go @@ -1,8 +1,6 @@ // Code generated by wit-bindgen-go. DO NOT EDIT. // Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". -// -// This interface provides a value-export of the default network handle.. package instancenetwork import ( @@ -12,8 +10,6 @@ import ( // InstanceNetwork represents the imported function "instance-network". // -// Get a handle to the default network. -// // instance-network: func() -> network // //go:nosplit diff --git a/_examples/invoke/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go b/_examples/invoke/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go index 036881b..173c51f 100644 --- a/_examples/invoke/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go +++ b/_examples/invoke/gen/wasi/sockets/ip-name-lookup/ip-name-lookup.wit.go @@ -31,23 +31,6 @@ func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) // ResolveNextAddress represents the imported method "resolve-next-address". // -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated -// IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. -// (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. -// (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) -// // resolve-next-address: func() -> result, error-code> // //go:nosplit @@ -63,11 +46,6 @@ func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm. // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -84,27 +62,6 @@ func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) // ResolveAddresses represents the imported function "resolve-addresses". // -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -// // resolve-addresses: func(network: borrow, name: string) -> result // diff --git a/_examples/invoke/gen/wasi/sockets/network/network.wit.go b/_examples/invoke/gen/wasi/sockets/network/network.wit.go index b18bec9..3e1a3ac 100644 --- a/_examples/invoke/gen/wasi/sockets/network/network.wit.go +++ b/_examples/invoke/gen/wasi/sockets/network/network.wit.go @@ -9,10 +9,6 @@ import ( // Network represents the imported resource "wasi:sockets/network@0.2.0#network". // -// An opaque resource that represents access to (a subset of) the network. -// This enables context-based security for networking. -// There is no need for this to map 1:1 to a physical network interface. -// // resource network type Network cm.Resource @@ -33,20 +29,6 @@ func wasmimport_NetworkResourceDrop(self0 uint32) // ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". // -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ -// per API. -// // enum error-code { // unknown, // access-denied, @@ -73,87 +55,26 @@ func wasmimport_NetworkResourceDrop(self0 uint32) type ErrorCode uint8 const ( - // Unknown error ErrorCodeUnknown ErrorCode = iota - - // Access denied. - // - // POSIX equivalent: EACCES, EPERM ErrorCodeAccessDenied - - // The operation is not supported. - // - // POSIX equivalent: EOPNOTSUPP ErrorCodeNotSupported - - // One of the arguments is invalid. - // - // POSIX equivalent: EINVAL ErrorCodeInvalidArgument - - // Not enough memory to complete the operation. - // - // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY ErrorCodeOutOfMemory - - // The operation timed out before it could finish completely. ErrorCodeTimeout - - // This operation is incompatible with another asynchronous operation that is already - // in progress. - // - // POSIX equivalent: EALREADY ErrorCodeConcurrencyConflict - - // Trying to finish an asynchronous operation that: - // - has not been started yet, or: - // - was already finished by a previous `finish-*` call. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeNotInProgress - - // The operation has been aborted because it could not be completed immediately. - // - // Note: this is scheduled to be removed when `future`s are natively supported. ErrorCodeWouldBlock - - // The operation is not valid in the socket's current state. ErrorCodeInvalidState - - // A new socket resource could not be created because of a system limit. ErrorCodeNewSocketLimit - - // A bind operation failed because the provided address is not an address that the - // `network` can bind to. ErrorCodeAddressNotBindable - - // A bind operation failed because the provided address is already in use or because - // there are no ephemeral ports available. ErrorCodeAddressInUse - - // The remote address is not reachable ErrorCodeRemoteUnreachable - - // The TCP connection was forcefully rejected ErrorCodeConnectionRefused - - // The TCP connection was reset. ErrorCodeConnectionReset - - // A TCP connection was aborted. ErrorCodeConnectionAborted - - // The size of a datagram sent to a UDP socket exceeded the maximum - // supported size. ErrorCodeDatagramTooLarge - - // Name does not exist or has no suitable associated IP addresses. ErrorCodeNameUnresolvable - - // A temporary failure in name resolution occurred. ErrorCodeTemporaryResolverFailure - - // A permanent failure in name resolution occurred. ErrorCodePermanentResolverFailure ) @@ -195,10 +116,7 @@ func (e ErrorCode) String() string { type IPAddressFamily uint8 const ( - // Similar to `AF_INET` in POSIX. IPAddressFamilyIPv4 IPAddressFamily = iota - - // Similar to `AF_INET6` in POSIX. IPAddressFamilyIPv6 ) @@ -257,10 +175,8 @@ func (self *IPAddress) IPv6() *IPv6Address { // address: ipv4-address, // } type IPv4SocketAddress struct { - // sin_port - Port uint16 - - // sin_addr + _ cm.HostLayout + Port uint16 Address IPv4Address } @@ -273,17 +189,11 @@ type IPv4SocketAddress struct { // scope-id: u32, // } type IPv6SocketAddress struct { - // sin6_port - Port uint16 - - // sin6_flowinfo + _ cm.HostLayout + Port uint16 FlowInfo uint32 - - // sin6_addr - Address IPv6Address - - // sin6_scope_id - ScopeID uint32 + Address IPv6Address + ScopeID uint32 } // IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". diff --git a/_examples/invoke/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go b/_examples/invoke/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go index 5397b92..445276a 100644 --- a/_examples/invoke/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go +++ b/_examples/invoke/gen/wasi/sockets/tcp-create-socket/tcp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateTCPSocket represents the imported function "create-tcp-socket". // -// 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`/`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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // create-tcp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/invoke/gen/wasi/sockets/tcp/tcp.wit.go b/_examples/invoke/gen/wasi/sockets/tcp/tcp.wit.go index dc29168..7251b36 100644 --- a/_examples/invoke/gen/wasi/sockets/tcp/tcp.wit.go +++ b/_examples/invoke/gen/wasi/sockets/tcp/tcp.wit.go @@ -21,13 +21,8 @@ import ( type ShutdownType uint8 const ( - // Similar to `SHUT_RD` in POSIX. ShutdownTypeReceive ShutdownType = iota - - // Similar to `SHUT_WR` in POSIX. ShutdownTypeSend - - // Similar to `SHUT_RDWR` in POSIX. ShutdownTypeBoth ) @@ -44,29 +39,6 @@ func (e ShutdownType) String() string { // TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". // -// A TCP socket resource. -// -// The socket can be in one of the following states: -// - `unbound` -// - `bind-in-progress` -// - `bound` (See note below) -// - `listen-in-progress` -// - `listening` -// - `connect-in-progress` -// - `connected` -// - `closed` -// See -// for a more information. -// -// Note: Except where explicitly mentioned, whenever this documentation uses -// the term "bound" without backticks it actually means: in the `bound` state *or -// higher*. -// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) -// -// In addition to the general error codes documented on the -// `network::error-code` type, TCP socket methods may always return -// `error(invalid-state)` when in the `closed` state. -// // resource tcp-socket type TCPSocket cm.Resource @@ -87,36 +59,6 @@ func wasmimport_TCPSocketResourceDrop(self0 uint32) // Accept represents the imported method "accept". // -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties -// are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated -// by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -// // accept: func() -> result, error-code> // //go:nosplit @@ -132,10 +74,6 @@ func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketIn // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -197,13 +135,6 @@ func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.Er // HopLimit represents the imported method "hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // hop-limit: func() -> result // //go:nosplit @@ -219,10 +150,6 @@ func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, // IsListening represents the imported method "is-listening". // -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. -// // is-listening: func() -> bool // //go:nosplit @@ -239,19 +166,6 @@ func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) // KeepAliveCount represents the imported method "keep-alive-count". // -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-count: func() -> result // //go:nosplit @@ -267,17 +181,6 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, // KeepAliveEnabled represents the imported method "keep-alive-enabled". // -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only -// come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. -// // keep-alive-enabled: func() -> result // //go:nosplit @@ -293,20 +196,6 @@ func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, // KeepAliveIdleTime represents the imported method "keep-alive-idle-time". // -// Amount of time the connection has to be idle before TCP starts sending keepalive -// packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-idle-time: func() -> result // //go:nosplit @@ -322,19 +211,6 @@ func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint6 // KeepAliveInterval represents the imported method "keep-alive-interval". // -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // keep-alive-interval: func() -> result // //go:nosplit @@ -350,24 +226,6 @@ func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint6 // LocalAddress represents the imported method "local-address". // -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -383,19 +241,6 @@ func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -411,17 +256,6 @@ func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -532,19 +366,6 @@ func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, resul // SetListenBacklogSize represents the imported method "set-listen-backlog-size". // -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog -// size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` -// state. -// // set-listen-backlog-size: func(value: u64) -> result<_, error-code> // //go:nosplit @@ -593,30 +414,6 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // Shutdown represents the imported method "shutdown". // -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> // //go:nosplit @@ -633,54 +430,6 @@ func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. -// (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the -// TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means -// that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where -// this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -699,60 +448,6 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // StartConnect represents the imported method "start-connect". // -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, -// ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. -// (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL -// on Windows) -// - `invalid-argument`: The socket is already attached to a different network. -// The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. -// (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, -// EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - -// // start-connect: func(network: borrow, remote-address: ip-socket-address) // -> result<_, error-code> // @@ -771,35 +466,6 @@ func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddre // StartListen represents the imported method "start-listen". // -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. -// (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - -// // start-listen: func() -> result<_, error-code> // //go:nosplit @@ -815,24 +481,6 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/invoke/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go b/_examples/invoke/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go index 1aa91ed..21eb33b 100644 --- a/_examples/invoke/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go +++ b/_examples/invoke/gen/wasi/sockets/udp-create-socket/udp-create-socket.wit.go @@ -11,32 +11,6 @@ import ( // CreateUDPSocket represents the imported function "create-udp-socket". // -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of -// a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - -// // create-udp-socket: func(address-family: ip-address-family) -> result // diff --git a/_examples/invoke/gen/wasi/sockets/udp/udp.wit.go b/_examples/invoke/gen/wasi/sockets/udp/udp.wit.go index 5941384..47b5fd0 100644 --- a/_examples/invoke/gen/wasi/sockets/udp/udp.wit.go +++ b/_examples/invoke/gen/wasi/sockets/udp/udp.wit.go @@ -11,55 +11,30 @@ import ( // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". // -// A received datagram. -// // record incoming-datagram { // data: list, // remote-address: ip-socket-address, // } type IncomingDatagram struct { - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - Data cm.List[uint8] - - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized - // with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress network.IPSocketAddress } // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". // -// A datagram to be sent out. -// // record outgoing-datagram { // data: list, // remote-address: option, // } type OutgoingDatagram struct { - // The payload. - Data cm.List[uint8] - - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address - // exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise - // it is equivalent to `sendto`. + _ cm.HostLayout + Data cm.List[uint8] RemoteAddress cm.Option[network.IPSocketAddress] } // UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". // -// A UDP socket handle. -// // resource udp-socket type UDPSocket cm.Resource @@ -80,10 +55,6 @@ func wasmimport_UDPSocketResourceDrop(self0 uint32) // AddressFamily represents the imported method "address-family". // -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -// // address-family: func() -> ip-address-family // //go:nosplit @@ -115,24 +86,6 @@ func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.Erro // LocalAddress represents the imported method "local-address". // -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the -// socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -// // local-address: func() -> result // //go:nosplit @@ -148,19 +101,6 @@ func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // ReceiveBufferSize represents the imported method "receive-buffer-size". // -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or -// rounded. -// I.e. after setting a value, reading the same setting back may return a different -// value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -// // receive-buffer-size: func() -> result // //go:nosplit @@ -176,17 +116,6 @@ func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // RemoteAddress represents the imported method "remote-address". // -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -// // remote-address: func() -> result // //go:nosplit @@ -265,38 +194,6 @@ func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result // StartBind represents the imported method "start-bind". // -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the -// implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. -// (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS -// on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` -// can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. -// (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -// // start-bind: func(network: borrow, local-address: ip-socket-address) -> // result<_, error-code> // @@ -315,57 +212,6 @@ func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // Stream represents the imported method "stream". // -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate -// any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` -// may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating -// with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, -// but -// only the most recently returned pair of streams will be operational. Implementations -// may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling -// `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were -// no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// // %stream: func(remote-address: option) -> result, error-code> // @@ -383,11 +229,6 @@ func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddre // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -404,13 +245,6 @@ func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) // UnicastHopLimit represents the imported method "unicast-hop-limit". // -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -// // unicast-hop-limit: func() -> result // //go:nosplit @@ -446,32 +280,6 @@ func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) // Receive represents the imported method "receive". // -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without -// blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET -// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // receive: func(max-results: u64) -> result, error-code> // //go:nosplit @@ -488,11 +296,6 @@ func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit @@ -529,18 +332,6 @@ func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) // CheckSend represents the imported method "check-send". // -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. -// // check-send: func() -> result // //go:nosplit @@ -556,55 +347,6 @@ func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[ // Send represents the imported method "send". // -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking -// and -// returns how many messages were actually sent (or queued for sending). This function -// never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` -// is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and -// sequentially -// sending each individual datagram until either the end of the list has been reached -// or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns -// an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations -// must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` -// permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` -// is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` -// was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// // send: func(datagrams: list) -> result // //go:nosplit @@ -621,11 +363,6 @@ func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDat // Subscribe represents the imported method "subscribe". // -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// // subscribe: func() -> pollable // //go:nosplit diff --git a/_examples/invoke/gen/wasmcloud/secrets/store/store.wit.go b/_examples/invoke/gen/wasmcloud/secrets/store/store.wit.go index 06891e7..09dbab5 100644 --- a/_examples/invoke/gen/wasmcloud/secrets/store/store.wit.go +++ b/_examples/invoke/gen/wasmcloud/secrets/store/store.wit.go @@ -72,7 +72,7 @@ func (self *SecretsError) NotFound() bool { // store binary data as a secret. // // variant secret-value { -// string(string), +// %string(string), // bytes(list), // } type SecretValue cm.Variant[uint8, string, cm.List[uint8]] diff --git a/_examples/invoke/go.mod b/_examples/invoke/go.mod index 8565666..5b9b456 100644 --- a/_examples/invoke/go.mod +++ b/_examples/invoke/go.mod @@ -3,7 +3,7 @@ module github.com/wasmCloud/component-sdk-go/_examples/invoke go 1.23.0 require ( - github.com/bytecodealliance/wasm-tools-go v0.2.0 + github.com/bytecodealliance/wasm-tools-go v0.2.1 github.com/stretchr/testify v1.9.0 github.com/wasmCloud/wadge v0.3.0 go.wasmcloud.dev/component v0.0.0-20240910182305-2785f866ff0f @@ -13,14 +13,14 @@ require ( github.com/coreos/go-semver v0.3.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/samber/lo v1.44.0 // indirect + github.com/samber/lo v1.47.0 // indirect github.com/samber/slog-common v0.17.1 // indirect github.com/urfave/cli/v3 v3.0.0-alpha9 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/tools v0.24.0 // indirect + golang.org/x/text v0.18.0 // indirect + golang.org/x/tools v0.25.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/_examples/invoke/go.sum b/_examples/invoke/go.sum index 0bc6ef0..a617385 100644 --- a/_examples/invoke/go.sum +++ b/_examples/invoke/go.sum @@ -1,13 +1,13 @@ -github.com/bytecodealliance/wasm-tools-go v0.2.0 h1:JdmiZew7ewHjf+ZGGRE4gZM85Ad/PGW/5I57hepEOjQ= -github.com/bytecodealliance/wasm-tools-go v0.2.0/go.mod h1:2GnJCUlcDrslZ/L6+yYqoUnewDlBvqRS2N/0NW9ro6w= +github.com/bytecodealliance/wasm-tools-go v0.2.1 h1:0o+zGdbgOcam4ZNA8NPS5Xxl1FV57XTeLerOJy4EVsY= +github.com/bytecodealliance/wasm-tools-go v0.2.1/go.mod h1:+h2zz8UoMx8l1F1b2pv6LCbZFc85HFQZDQcRdfa4ovs= github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA= -github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/samber/slog-common v0.17.1 h1:jTqqLBgoJshpoxlPSGiypyOanjH6tY+i9bwyYmIbjhI= github.com/samber/slog-common v0.17.1/go.mod h1:mZSJhinB4aqHziR0SKPqpVZjJ0JO35JfH+dDIWqaCBk= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= @@ -18,16 +18,16 @@ github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkU github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= github.com/wasmCloud/wadge v0.3.0 h1:uDmsxgeACARbW9idI9HBf9CQj+nQHskRN7lch6WzJN0= github.com/wasmCloud/wadge v0.3.0/go.mod h1:d1D1q/mtLr6v6hg/UCIq4G8Ygf6ku7M8VS6/4MhL5Xk= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= +golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/_examples/invoke/wit/deps.lock b/_examples/invoke/wit/deps.lock index 9b4d85b..22c6b1d 100644 --- a/_examples/invoke/wit/deps.lock +++ b/_examples/invoke/wit/deps.lock @@ -1,55 +1,49 @@ -[cli] -sha256 = "285865a31d777181b075f39e92bcfe59c89cd6bacce660be1b9a627646956258" -sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913d7ee727c011f0f72994ea7dc8e661ebcc0a6b34b587297d80cd9b3f7e8" +["wasi-cli-0.2.0"] +sha256 = "13b041ec2314d48107929c335df3ca81b1bb0a35bfec38e206a59162a4c209cd" +sha512 = "725886b3244f4894a1121cd66e1bea0775964ca1b3811be3ae43a4c692cb7d5f27d851072637b8ec64bd5e71e85bb5e860f8331fe8f77353d9d7868ce1d72a8e" -[clocks] -sha256 = "468b4d12892fe926b8eb5d398dbf579d566c93231fa44f415440572c695b7613" -sha512 = "e6b53a07221f1413953c9797c68f08b815fdaebf66419bbc1ea3e8b7dece73731062693634731f311a03957b268cf9cc509c518bd15e513c318aa04a8459b93a" +["wasi-clocks-0.2.0"] +sha256 = "daf7133b4f60ba73185449327dd48d2b324799db858ab463bcd32d954a9ff394" +sha512 = "5992296c504aebfad359ab1676bba63b5d22e33112c240a437ee733433aa50552144242f8998180ff36f0da56e5f65691dbb1898331ce878bd9fa439b8909742" -[component] +["wasi-config-0.2.0-draft"] +sha256 = "5c6b4a10b21fbab2397d579c6f8bf8a484160dfdf20b6343080b0bad097849a3" +sha512 = "d3cf5fd1d12590aefd561330337870e2e468c84753c11e19bccd165c916a696722cc29af3572984e6256088b6e683763675d5b8cec3d195f9e2961fe405629b8" + +["wasi-filesystem-0.2.0"] +sha256 = "739d4fc43cd51421382e5d1a0cf643a2985691d480ae75600cdcd382665b3e55" +sha512 = "67f61ef46833060cc4d7a258da7a82024830762c4ecfd522d32bdc5e6bf4df26043f9a8c13ea38b191df180176826aa7b163816618a939015efff5987557dc16" + +["wasi-http-0.2.0"] +sha256 = "f22b6f3b3c12289e522041067b0a2db99a27c181e9ef3ed36930aa0286232d63" +sha512 = "f9b38ef4f58cb9e069b51ee45df52ce6ca9af0a9774c3d09dc99598f36afcd902557221be2f1a6bcccdecb880e4d7436b533e03f4b9250d5b0e1466afd3a62ce" + +["wasi-io-0.2.0"] +sha256 = "0bc0cc0d474a5c4f3c2e2092664c4e235a0390e5d206d3bdc4007488d9d5e00f" +sha512 = "497f37742a94ca32eaa77dce5d9144682e743b30c2d702d37726d43735a25fa9d421afbf5945da158c0e46a0adf941f607b0e0f5d26494af52f021265f78329c" + +["wasi-logging-0.1.0-draft"] +sha256 = "619c4d2336045bab9129e5af568decd5e963006291d496a23cddf796f3a61c2e" +sha512 = "c163aa6f4e566cb85d373f25e590e552fc2530fdf50946c38d305e9f2cd189d86ff8540d163e42acd2cebbe3cef98967cd1efb14ce196da132fcf6caf4f6155d" + +["wasi-random-0.2.0"] +sha256 = "efcdf344435591830f5fbed67a2c215bba112893518a8ef4c7234a4796b8dbcd" +sha512 = "c78a10e9b6401116eac703430609a849854a27a4ff3bc7737d514536a9c16a2fc206a35f8f96b7c40f254d6a66e6873361970754fa69b856025886cd462a2832" + +["wasi-sockets-0.2.0"] +sha256 = "aa3c13fee8c788c95de5a917a54d776d5adb2afd90a77224864941ce27c5d471" +sha512 = "4e3be65dd127ccd4bfa1af8f86fea556d6e22d25e4b637f9b9ebf66ae1f6331f904edff042adc9be16fec511e3295170e6c13516715d2cd3e5aaffbd96158fa9" + +["wasmcloud-bus-1.0.0"] +sha256 = "f823b5c8293cb585092107120139c34c405f57362761a133d543f5d68c65d591" +sha512 = "12e6aa4eac6139b60ea72cc7b6ded6ac9b144b15557be9f2329b6e84b5a161d8f6344674afd0526a883cb61e34c06fee9dbadbaee1d783cd957bc43dab4bfc2d" + +[wasmcloud-component-go] path = "../../../wit" -sha256 = "ec5b1fc6183ecd80b8328e2345d96d2b7e9fc8c2085300389d21c078ab03729f" -sha512 = "5b1488b7be9f9e05b713aa9cc5465eb730550eab3ae3a9a5ca8a243947a6ae9b90e4a4f06ecd9cc9a375306bb619c54b16856a73d25aa227c45352b88ec741db" -deps = ["cli", "clocks", "config", "filesystem", "io", "lattice", "logging", "messaging", "random", "secrets", "sockets"] - -[config] -sha256 = "9148c06861712b69170af7b8ec37896b4104297d920fdec9f3bcc0b1eee4a5c8" -sha512 = "25a54101620f279c835b39f56f6dbf8a92b374b6faaf6cf6aaa1ea06d8b97b9b79788cf8abd9c2ad0c11e3629dba6a2513b71f2c54b9f95027054ae54a4615b8" - -[filesystem] -sha256 = "498c465cfd04587db40f970fff2185daa597d074c20b68a8bcbae558f261499b" -sha512 = "ead452f9b7bfb88593a502ec00d76d4228003d51c40fd0408aebc32d35c94673551b00230d730873361567cc209ec218c41fb4e95bad194268592c49e7964347" - -[http] -url = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -sha256 = "8f44402bde16c48e28c47dc53eab0b26af5b3b3482a1852cf77673e0880ba1c1" -sha512 = "760695f9a25c25bf75a25b731cb21c3bda9e288e450edda823324ecbc73d5d798bbb5de2edad999566980836f037463ee9e57d61789d04b3f3e381475b1a9a0f" -deps = ["cli", "clocks", "filesystem", "io", "random", "sockets"] - -[io] -sha256 = "7210e5653539a15478f894d4da24cc69d61924cbcba21d2804d69314a88e5a4c" -sha512 = "49184a1b0945a889abd52d25271172ed3dc2db6968fcdddb1bab7ee0081f4a3eeee0977ad2291126a37631c0d86eeea75d822fa8af224c422134500bf9f0f2bb" - -[lattice] -sha256 = "b4946a8bfa48b2f4ac404de03617d25712879596be5417bde3de09ca9c369462" -sha512 = "09918bb2fa8f7af022f71453348be38ec7fd1a35df6809b8d0c5f246856712f969557ff65d9e5d4619e905191e27fba2fbbcc9f38c777a7b09eb73c30909d33f" - -[logging] -sha256 = "9676b482485bb0fd2751a390374c1108865a096b7037f4b5dbe524f066bfb06e" -sha512 = "30a621a6d48a0175e8047c062e618523a85f69c45a7c31918da2b888f7527fce1aca67fa132552222725d0f6cdcaed95be7f16c28488d9468c0fad00cb7450b9" - -[messaging] -sha256 = "41ada083aceb2b4ba92d9bd16d19b6462cc02b10378c9a49135c3447f9138a44" -sha512 = "aa9c819dfd9e85b19661f6087ffd824c44fc38c8a4bc1005c4e7fd34fe844633c52cae7a0412e9ea90f71826e0660e8a3b5672a0f0303c524e4139643ae675ac" - -[random] -sha256 = "7371d03c037d924caba2587fb2e7c5773a0d3c5fcecbf7971e0e0ba57973c53d" -sha512 = "964c4e8925a53078e4d94ba907b54f89a0b7e154f46823a505391471466c17f53c8692682e5c85771712acd88b348686173fc07c53a3cfe3d301b8cd8ddd0de4" - -[secrets] -sha256 = "4c965f81e4f8510e917976dc7017b070d23b964724e3ca058f28ec9e3d691854" -sha512 = "c23d3d86846b7f35238347974c104a3056e5871db85a8e17c607cf2c48c5fc6dc550fa698a233b78de2c7b25e80ff6c590d0a4bf8c8892b48b3cec52bc141d32" - -[sockets] -sha256 = "622bd28bbeb43736375dc02bd003fd3a016ff8ee91e14bab488325c6b38bf966" -sha512 = "5a63c1f36de0c4548e1d2297bdbededb28721cbad94ef7825c469eae29d7451c97e00b4c1d6730ee1ec0c4a5aac922961a2795762d4a0c3bb54e30a391a84bae" +sha256 = "995bd9ad8d0523f04480196b6746da80ddc5daf2e3be6b126c224d1fe9bda103" +sha512 = "e5af5fbb4242fc151d83ce86fa05d54274eb33a42b8856453659a1191d5142cd3792c914df8db330a9f692089974bbd1e6d3695142a8e5416d10b5b856839ce9" +deps = ["wasi-cli-0.2.0", "wasi-clocks-0.2.0", "wasi-config-0.2.0-draft", "wasi-filesystem-0.2.0", "wasi-http-0.2.0", "wasi-io-0.2.0", "wasi-logging-0.1.0-draft", "wasi-random-0.2.0", "wasi-sockets-0.2.0", "wasmcloud-bus-1.0.0", "wasmcloud-secrets-0.1.0-draft"] + +["wasmcloud-secrets-0.1.0-draft"] +sha256 = "8e0ec182ea30a420744887cdb42660bf703194eaf8ecf2f0dc0efc4159247ea4" +sha512 = "f0037028e47d307b1551068fcdb9249a0a1cd3d7d1e8d99f33713ec1ee22bc5242fe63155a9f7aaa0492640df2c79ea40ed0839e2add222c069787b59c09f1b3" diff --git a/_examples/invoke/wit/deps.toml b/_examples/invoke/wit/deps.toml index 9a0440f..4d1db6f 100644 --- a/_examples/invoke/wit/deps.toml +++ b/_examples/invoke/wit/deps.toml @@ -1,2 +1 @@ -http = "https://github.com/WebAssembly/wasi-http/archive/v0.2.0.tar.gz" -component = "../../../wit" +wasmcloud-component-go = "../../../wit" diff --git a/_examples/invoke/wit/deps/cli/command.wit b/_examples/invoke/wit/deps/cli/command.wit deleted file mode 100644 index d8005bd..0000000 --- a/_examples/invoke/wit/deps/cli/command.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:cli@0.2.0; - -world command { - include imports; - - export run; -} diff --git a/_examples/invoke/wit/deps/cli/environment.wit b/_examples/invoke/wit/deps/cli/environment.wit deleted file mode 100644 index 7006523..0000000 --- a/_examples/invoke/wit/deps/cli/environment.wit +++ /dev/null @@ -1,18 +0,0 @@ -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - get-environment: func() -> list>; - - /// Get the POSIX-style arguments to the program. - get-arguments: func() -> list; - - /// Return a path that programs should use as their initial current working - /// directory, interpreting `.` as shorthand for this. - initial-cwd: func() -> option; -} diff --git a/_examples/invoke/wit/deps/cli/exit.wit b/_examples/invoke/wit/deps/cli/exit.wit deleted file mode 100644 index d0c2b82..0000000 --- a/_examples/invoke/wit/deps/cli/exit.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface exit { - /// Exit the current instance and any linked instances. - exit: func(status: result); -} diff --git a/_examples/invoke/wit/deps/cli/imports.wit b/_examples/invoke/wit/deps/cli/imports.wit deleted file mode 100644 index 083b84a..0000000 --- a/_examples/invoke/wit/deps/cli/imports.wit +++ /dev/null @@ -1,20 +0,0 @@ -package wasi:cli@0.2.0; - -world imports { - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:sockets/imports@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; - - import environment; - import exit; - import stdin; - import stdout; - import stderr; - import terminal-input; - import terminal-output; - import terminal-stdin; - import terminal-stdout; - import terminal-stderr; -} diff --git a/_examples/invoke/wit/deps/cli/run.wit b/_examples/invoke/wit/deps/cli/run.wit deleted file mode 100644 index a70ee8c..0000000 --- a/_examples/invoke/wit/deps/cli/run.wit +++ /dev/null @@ -1,4 +0,0 @@ -interface run { - /// Run the program. - run: func() -> result; -} diff --git a/_examples/invoke/wit/deps/cli/stdio.wit b/_examples/invoke/wit/deps/cli/stdio.wit deleted file mode 100644 index 31ef35b..0000000 --- a/_examples/invoke/wit/deps/cli/stdio.wit +++ /dev/null @@ -1,17 +0,0 @@ -interface stdin { - use wasi:io/streams@0.2.0.{input-stream}; - - get-stdin: func() -> input-stream; -} - -interface stdout { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stdout: func() -> output-stream; -} - -interface stderr { - use wasi:io/streams@0.2.0.{output-stream}; - - get-stderr: func() -> output-stream; -} diff --git a/_examples/invoke/wit/deps/cli/terminal.wit b/_examples/invoke/wit/deps/cli/terminal.wit deleted file mode 100644 index 38c724e..0000000 --- a/_examples/invoke/wit/deps/cli/terminal.wit +++ /dev/null @@ -1,49 +0,0 @@ -/// Terminal input. -/// -/// In the future, this may include functions for disabling echoing, -/// disabling input buffering so that keyboard events are sent through -/// immediately, querying supported features, and so on. -interface terminal-input { - /// The input side of a terminal. - resource terminal-input; -} - -/// Terminal output. -/// -/// In the future, this may include functions for querying the terminal -/// size, being notified of terminal size changes, querying supported -/// features, and so on. -interface terminal-output { - /// The output side of a terminal. - resource terminal-output; -} - -/// An interface providing an optional `terminal-input` for stdin as a -/// link-time authority. -interface terminal-stdin { - use terminal-input.{terminal-input}; - - /// If stdin is connected to a terminal, return a `terminal-input` handle - /// allowing further interaction with it. - get-terminal-stdin: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stdout as a -/// link-time authority. -interface terminal-stdout { - use terminal-output.{terminal-output}; - - /// If stdout is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stdout: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stderr as a -/// link-time authority. -interface terminal-stderr { - use terminal-output.{terminal-output}; - - /// If stderr is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - get-terminal-stderr: func() -> option; -} diff --git a/_examples/invoke/wit/deps/clocks/monotonic-clock.wit b/_examples/invoke/wit/deps/clocks/monotonic-clock.wit deleted file mode 100644 index 4e4dc3a..0000000 --- a/_examples/invoke/wit/deps/clocks/monotonic-clock.wit +++ /dev/null @@ -1,45 +0,0 @@ -package wasi:clocks@0.2.0; -/// WASI Monotonic Clock is a clock API intended to let users measure elapsed -/// time. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// 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. -interface monotonic-clock { - 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. - type instant = u64; - - /// A duration of time, in nanoseconds. - 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. - now: func() -> instant; - - /// Query the resolution of the clock. Returns the duration of time - /// corresponding to a clock tick. - resolution: func() -> duration; - - /// Create a `pollable` which will resolve once the specified instant - /// occured. - 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. - subscribe-duration: func( - when: duration, - ) -> pollable; -} diff --git a/_examples/invoke/wit/deps/clocks/wall-clock.wit b/_examples/invoke/wit/deps/clocks/wall-clock.wit deleted file mode 100644 index 440ca0f..0000000 --- a/_examples/invoke/wit/deps/clocks/wall-clock.wit +++ /dev/null @@ -1,42 +0,0 @@ -package wasi:clocks@0.2.0; -/// 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. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// A wall clock is a clock which measures the date and time according to -/// some external reference. -/// -/// External references may be reset, so this clock is not necessarily -/// monotonic, making it unsuitable for measuring elapsed time. -/// -/// It is intended for reporting the current date and time for humans. -interface wall-clock { - /// A time and date in seconds plus nanoseconds. - record datetime { - seconds: u64, - nanoseconds: u32, - } - - /// Read the current value of the clock. - /// - /// This clock is not monotonic, therefore calling this function repeatedly - /// will not necessarily produce a sequence of non-decreasing values. - /// - /// The returned timestamps represent the number of seconds since - /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], - /// also known as [Unix Time]. - /// - /// The nanoseconds field of the output is always less than 1000000000. - /// - /// [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 - now: func() -> datetime; - - /// Query the resolution of the clock. - /// - /// The nanoseconds field of the output is always less than 1000000000. - resolution: func() -> datetime; -} diff --git a/_examples/invoke/wit/deps/clocks/world.wit b/_examples/invoke/wit/deps/clocks/world.wit deleted file mode 100644 index c022457..0000000 --- a/_examples/invoke/wit/deps/clocks/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:clocks@0.2.0; - -world imports { - import monotonic-clock; - import wall-clock; -} diff --git a/_examples/invoke/wit/deps/config/runtime_config.wit b/_examples/invoke/wit/deps/config/runtime_config.wit deleted file mode 100644 index 29d53b1..0000000 --- a/_examples/invoke/wit/deps/config/runtime_config.wit +++ /dev/null @@ -1,25 +0,0 @@ -interface runtime { - /// An error type that encapsulates the different errors that can occur fetching config - variant config-error { - /// This indicates an error from an "upstream" config source. - /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), - /// the error message is a string. - upstream(string), - /// This indicates an error from an I/O operation. - /// As this could be almost _anything_ (such as a file read, network connection, etc), - /// the error message is a string. - /// Depending on how this ends up being consumed, - /// we may consider moving this to use the `wasi:io/error` type instead. - /// For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - } - - /// Gets a single opaque config value set at the given key if it exists - get: func( - /// A string key to fetch - key: string - ) -> result, config-error>; - - /// Gets a list of all set config data - get-all: func() -> result>, config-error>; -} diff --git a/_examples/invoke/wit/deps/config/world.wit b/_examples/invoke/wit/deps/config/world.wit deleted file mode 100644 index 378c4a7..0000000 --- a/_examples/invoke/wit/deps/config/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:config@0.2.0-draft; - -world imports { - /// The runtime interface for config - import runtime; -} \ No newline at end of file diff --git a/_examples/invoke/wit/deps/filesystem/preopens.wit b/_examples/invoke/wit/deps/filesystem/preopens.wit deleted file mode 100644 index da801f6..0000000 --- a/_examples/invoke/wit/deps/filesystem/preopens.wit +++ /dev/null @@ -1,8 +0,0 @@ -package wasi:filesystem@0.2.0; - -interface preopens { - use types.{descriptor}; - - /// Return the set of preopened directories, and their path. - get-directories: func() -> list>; -} diff --git a/_examples/invoke/wit/deps/filesystem/types.wit b/_examples/invoke/wit/deps/filesystem/types.wit deleted file mode 100644 index 11108fc..0000000 --- a/_examples/invoke/wit/deps/filesystem/types.wit +++ /dev/null @@ -1,634 +0,0 @@ -package wasi:filesystem@0.2.0; -/// WASI filesystem is a filesystem API primarily intended to let users run WASI -/// programs that access their files on their existing filesystems, without -/// significant overhead. -/// -/// It is intended to be roughly portable between Unix-family platforms and -/// Windows, though it does not hide many of the major differences. -/// -/// Paths are passed as interface-type `string`s, meaning they must consist of -/// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain -/// paths which are not accessible by this API. -/// -/// The directory separator in WASI is always the forward-slash (`/`). -/// -/// All paths in WASI are relative paths, and are interpreted relative to a -/// `descriptor` referring to a base directory. If a `path` argument to any WASI -/// function starts with `/`, or if any step of resolving a `path`, including -/// `..` and symbolic link steps, reaches a directory outside of the base -/// directory, or reaches a symlink to an absolute or rooted path in the -/// underlying filesystem, the function fails with `error-code::not-permitted`. -/// -/// For more information about WASI path resolution and sandboxing, see -/// [WASI filesystem path resolution]. -/// -/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md -interface types { - use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; - use wasi:clocks/wall-clock@0.2.0.{datetime}; - - /// File size or length of a region within a file. - type filesize = u64; - - /// The type of a filesystem object referenced by a descriptor. - /// - /// Note: This was called `filetype` in earlier versions of WASI. - enum descriptor-type { - /// The type of the descriptor or file is unknown or is different from - /// any of the other types specified. - unknown, - /// The descriptor refers to a block device inode. - block-device, - /// The descriptor refers to a character device inode. - character-device, - /// The descriptor refers to a directory inode. - directory, - /// The descriptor refers to a named pipe. - fifo, - /// The file refers to a symbolic link inode. - symbolic-link, - /// The descriptor refers to a regular file inode. - regular-file, - /// The descriptor refers to a socket. - socket, - } - - /// Descriptor flags. - /// - /// Note: This was called `fdflags` in earlier versions of WASI. - flags descriptor-flags { - /// Read mode: Data can be read. - read, - /// Write mode: Data can be written to. - write, - /// Request that writes be performed according to synchronized I/O file - /// integrity completion. The data stored in the file and the file's - /// metadata are synchronized. This is similar to `O_SYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - file-integrity-sync, - /// Request that writes be performed according to synchronized I/O data - /// integrity completion. Only the data stored in the file is - /// synchronized. This is similar to `O_DSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - data-integrity-sync, - /// Requests that reads be performed at the same level of integrety - /// requested for writes. This is similar to `O_RSYNC` in POSIX. - /// - /// The precise semantics of this operation have not yet been defined for - /// WASI. At this time, it should be interpreted as a request, and not a - /// requirement. - requested-write-sync, - /// Mutating directories mode: Directory contents may be mutated. - /// - /// When this flag is unset on a descriptor, operations using the - /// descriptor which would create, rename, delete, modify the data or - /// metadata of filesystem objects, or obtain another handle which - /// would permit any of those, shall fail with `error-code::read-only` if - /// they would otherwise succeed. - /// - /// This may only be set on directories. - mutate-directory, - } - - /// File attributes. - /// - /// Note: This was called `filestat` in earlier versions of WASI. - record descriptor-stat { - /// File type. - %type: descriptor-type, - /// Number of hard links to the file. - link-count: link-count, - /// For regular files, the file size in bytes. For symbolic links, the - /// length in bytes of the pathname contained in the symbolic link. - size: filesize, - /// Last data access timestamp. - /// - /// If the `option` is none, the platform doesn't maintain an access - /// timestamp for this file. - data-access-timestamp: option, - /// Last data modification timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// modification timestamp for this file. - data-modification-timestamp: option, - /// Last file status-change timestamp. - /// - /// If the `option` is none, the platform doesn't maintain a - /// status-change timestamp for this file. - status-change-timestamp: option, - } - - /// Flags determining the method of how paths are resolved. - flags path-flags { - /// As long as the resolved path corresponds to a symbolic link, it is - /// expanded. - symlink-follow, - } - - /// Open flags used by `open-at`. - flags open-flags { - /// Create file if it does not exist, similar to `O_CREAT` in POSIX. - create, - /// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. - directory, - /// Fail if file already exists, similar to `O_EXCL` in POSIX. - exclusive, - /// Truncate file to size 0, similar to `O_TRUNC` in POSIX. - truncate, - } - - /// Number of hard links to an inode. - type link-count = u64; - - /// When setting a timestamp, this gives the value to set it to. - variant new-timestamp { - /// Leave the timestamp set to its previous value. - no-change, - /// Set the timestamp to the current time of the system clock associated - /// with the filesystem. - now, - /// Set the timestamp to the given value. - timestamp(datetime), - } - - /// A directory entry. - record directory-entry { - /// The type of the file referred to by this directory entry. - %type: descriptor-type, - - /// The name of the object. - name: string, - } - - /// Error codes returned by functions, similar to `errno` in POSIX. - /// Not all of these error codes are returned by the functions provided by this - /// API; some are used in higher-level library layers, and others are provided - /// merely for alignment with POSIX. - enum error-code { - /// Permission denied, similar to `EACCES` in POSIX. - access, - /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. - would-block, - /// Connection already in progress, similar to `EALREADY` in POSIX. - already, - /// Bad descriptor, similar to `EBADF` in POSIX. - bad-descriptor, - /// Device or resource busy, similar to `EBUSY` in POSIX. - busy, - /// Resource deadlock would occur, similar to `EDEADLK` in POSIX. - deadlock, - /// Storage quota exceeded, similar to `EDQUOT` in POSIX. - quota, - /// File exists, similar to `EEXIST` in POSIX. - exist, - /// File too large, similar to `EFBIG` in POSIX. - file-too-large, - /// Illegal byte sequence, similar to `EILSEQ` in POSIX. - illegal-byte-sequence, - /// Operation in progress, similar to `EINPROGRESS` in POSIX. - in-progress, - /// Interrupted function, similar to `EINTR` in POSIX. - interrupted, - /// Invalid argument, similar to `EINVAL` in POSIX. - invalid, - /// I/O error, similar to `EIO` in POSIX. - io, - /// Is a directory, similar to `EISDIR` in POSIX. - is-directory, - /// Too many levels of symbolic links, similar to `ELOOP` in POSIX. - loop, - /// Too many links, similar to `EMLINK` in POSIX. - too-many-links, - /// Message too large, similar to `EMSGSIZE` in POSIX. - message-size, - /// Filename too long, similar to `ENAMETOOLONG` in POSIX. - name-too-long, - /// No such device, similar to `ENODEV` in POSIX. - no-device, - /// No such file or directory, similar to `ENOENT` in POSIX. - no-entry, - /// No locks available, similar to `ENOLCK` in POSIX. - no-lock, - /// Not enough space, similar to `ENOMEM` in POSIX. - insufficient-memory, - /// No space left on device, similar to `ENOSPC` in POSIX. - insufficient-space, - /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. - not-directory, - /// Directory not empty, similar to `ENOTEMPTY` in POSIX. - not-empty, - /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. - not-recoverable, - /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. - unsupported, - /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. - no-tty, - /// No such device or address, similar to `ENXIO` in POSIX. - no-such-device, - /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. - overflow, - /// Operation not permitted, similar to `EPERM` in POSIX. - not-permitted, - /// Broken pipe, similar to `EPIPE` in POSIX. - pipe, - /// Read-only file system, similar to `EROFS` in POSIX. - read-only, - /// Invalid seek, similar to `ESPIPE` in POSIX. - invalid-seek, - /// Text file busy, similar to `ETXTBSY` in POSIX. - text-file-busy, - /// Cross-device link, similar to `EXDEV` in POSIX. - cross-device, - } - - /// File or memory access pattern advisory information. - enum advice { - /// The application has no advice to give on its behavior with respect - /// to the specified data. - normal, - /// The application expects to access the specified data sequentially - /// from lower offsets to higher offsets. - sequential, - /// The application expects to access the specified data in a random - /// order. - random, - /// The application expects to access the specified data in the near - /// future. - will-need, - /// The application expects that it will not access the specified data - /// in the near future. - dont-need, - /// The application expects to access the specified data once and then - /// not reuse it thereafter. - no-reuse, - } - - /// A 128-bit hash value, split into parts because wasm doesn't have a - /// 128-bit integer type. - record metadata-hash-value { - /// 64 bits of a 128-bit hash value. - lower: u64, - /// Another 64 bits of a 128-bit hash value. - upper: u64, - } - - /// 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. - resource descriptor { - /// Return a stream for reading from a file, if available. - /// - /// May fail with an error-code describing why the file cannot be read. - /// - /// Multiple read, write, and append streams may be active on the same open - /// file and they do not interfere with each other. - /// - /// Note: This allows using `read-stream`, which is similar to `read` in POSIX. - read-via-stream: func( - /// The offset within the file at which to start reading. - offset: filesize, - ) -> result; - - /// Return a stream for writing to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be written. - /// - /// Note: This allows using `write-stream`, which is similar to `write` in - /// POSIX. - write-via-stream: func( - /// The offset within the file at which to start writing. - offset: filesize, - ) -> result; - - /// Return a stream for appending to a file, if available. - /// - /// May fail with an error-code describing why the file cannot be appended. - /// - /// Note: This allows using `write-stream`, which is similar to `write` with - /// `O_APPEND` in in POSIX. - append-via-stream: func() -> result; - - /// Provide file advisory information on a descriptor. - /// - /// This is similar to `posix_fadvise` in POSIX. - advise: func( - /// The offset within the file to which the advisory applies. - offset: filesize, - /// The length of the region to which the advisory applies. - length: filesize, - /// The advice. - advice: advice - ) -> result<_, error-code>; - - /// Synchronize the data of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fdatasync` in POSIX. - sync-data: func() -> result<_, error-code>; - - /// Get flags associated with a descriptor. - /// - /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. - /// - /// Note: This returns the value that was the `fs_flags` value returned - /// from `fdstat_get` in earlier versions of WASI. - get-flags: func() -> result; - - /// Get the dynamic type of a descriptor. - /// - /// Note: This returns the same value as the `type` field of the `fd-stat` - /// returned by `stat`, `stat-at` and similar. - /// - /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided - /// by `fstat` in POSIX. - /// - /// Note: This returns the value that was the `fs_filetype` value returned - /// from `fdstat_get` in earlier versions of WASI. - 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. - set-size: func(size: filesize) -> result<_, error-code>; - - /// Adjust the timestamps of an open file or directory. - /// - /// Note: This is similar to `futimens` in POSIX. - /// - /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. - set-times: func( - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Read from a descriptor, without using and updating the descriptor's offset. - /// - /// This function returns a list of bytes containing the data that was - /// read, along with a bool which, when true, indicates that the end of the - /// file was reached. The returned list will contain up to `length` bytes; it - /// may return fewer than requested, if the end of the file is reached or - /// if the I/O operation is interrupted. - /// - /// In the future, this may change to return a `stream`. - /// - /// Note: This is similar to `pread` in POSIX. - read: func( - /// The maximum number of bytes to read. - length: filesize, - /// The offset within the file at which to read. - offset: filesize, - ) -> result, bool>, error-code>; - - /// Write to a descriptor, without using and updating the descriptor's offset. - /// - /// It is valid to write past the end of a file; the file is extended to the - /// extent of the write, with bytes between the previous end and the start of - /// the write set to zero. - /// - /// In the future, this may change to take a `stream`. - /// - /// Note: This is similar to `pwrite` in POSIX. - write: func( - /// Data to write - buffer: list, - /// The offset within the file at which to write. - offset: filesize, - ) -> result; - - /// Read directory entries from a directory. - /// - /// On filesystems where directories contain entries referring to themselves - /// and their parents, often named `.` and `..` respectively, these entries - /// are omitted. - /// - /// 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. - read-directory: func() -> result; - - /// Synchronize the data and metadata of a file to disk. - /// - /// This function succeeds with no effect if the file descriptor is not - /// opened for writing. - /// - /// Note: This is similar to `fsync` in POSIX. - sync: func() -> result<_, error-code>; - - /// Create a directory. - /// - /// Note: This is similar to `mkdirat` in POSIX. - create-directory-at: func( - /// The relative path at which to create the directory. - path: string, - ) -> result<_, error-code>; - - /// Return the attributes of an open file or directory. - /// - /// Note: This is similar to `fstat` in POSIX, except that it does not return - /// device and inode information. For testing whether two descriptors refer to - /// the same underlying filesystem object, use `is-same-object`. To obtain - /// additional data that can be used do determine whether a file has been - /// modified, use `metadata-hash`. - /// - /// Note: This was called `fd_filestat_get` in earlier versions of WASI. - stat: func() -> result; - - /// Return the attributes of a file or directory. - /// - /// Note: This is similar to `fstatat` in POSIX, except that it does not - /// return device and inode information. See the `stat` description for a - /// discussion of alternatives. - /// - /// Note: This was called `path_filestat_get` in earlier versions of WASI. - stat-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - - /// Adjust the timestamps of a file or directory. - /// - /// Note: This is similar to `utimensat` in POSIX. - /// - /// Note: This was called `path_filestat_set_times` in earlier versions of - /// WASI. - set-times-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to operate on. - path: string, - /// The desired values of the data access timestamp. - data-access-timestamp: new-timestamp, - /// The desired values of the data modification timestamp. - data-modification-timestamp: new-timestamp, - ) -> result<_, error-code>; - - /// Create a hard link. - /// - /// Note: This is similar to `linkat` in POSIX. - link-at: func( - /// Flags determining the method of how the path is resolved. - old-path-flags: path-flags, - /// The relative source path from which to link. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path at which to create the hard link. - new-path: string, - ) -> result<_, error-code>; - - /// Open a file or directory. - /// - /// The returned descriptor is not guaranteed to be the lowest-numbered - /// descriptor not currently open/ it is randomized to prevent applications - /// from depending on making assumptions about indexes, since this is - /// error-prone in multi-threaded contexts. The returned descriptor is - /// guaranteed to be less than 2**31. - /// - /// If `flags` contains `descriptor-flags::mutate-directory`, and the base - /// descriptor doesn't have `descriptor-flags::mutate-directory` set, - /// `open-at` fails with `error-code::read-only`. - /// - /// If `flags` contains `write` or `mutate-directory`, or `open-flags` - /// contains `truncate` or `create`, and the base descriptor doesn't have - /// `descriptor-flags::mutate-directory` set, `open-at` fails with - /// `error-code::read-only`. - /// - /// Note: This is similar to `openat` in POSIX. - open-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the object to open. - path: string, - /// The method by which to open the file. - open-flags: open-flags, - /// Flags to use for the resulting descriptor. - %flags: descriptor-flags, - ) -> result; - - /// Read the contents of a symbolic link. - /// - /// If the contents contain an absolute or rooted path in the underlying - /// filesystem, this function fails with `error-code::not-permitted`. - /// - /// Note: This is similar to `readlinkat` in POSIX. - readlink-at: func( - /// The relative path of the symbolic link from which to read. - path: string, - ) -> result; - - /// Remove a directory. - /// - /// Return `error-code::not-empty` if the directory is not empty. - /// - /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - remove-directory-at: func( - /// The relative path to a directory to remove. - path: string, - ) -> result<_, error-code>; - - /// Rename a filesystem object. - /// - /// Note: This is similar to `renameat` in POSIX. - rename-at: func( - /// The relative source path of the file or directory to rename. - old-path: string, - /// The base directory for `new-path`. - new-descriptor: borrow, - /// The relative destination path to which to rename the file or directory. - new-path: string, - ) -> result<_, error-code>; - - /// Create a symbolic link (also known as a "symlink"). - /// - /// If `old-path` starts with `/`, the function fails with - /// `error-code::not-permitted`. - /// - /// Note: This is similar to `symlinkat` in POSIX. - symlink-at: func( - /// The contents of the symbolic link. - old-path: string, - /// The relative destination path at which to create the symbolic link. - new-path: string, - ) -> result<_, error-code>; - - /// Unlink a filesystem object that is not a directory. - /// - /// Return `error-code::is-directory` if the path refers to a directory. - /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. - unlink-file-at: func( - /// The relative path to a file to unlink. - path: string, - ) -> result<_, error-code>; - - /// Test whether two descriptors refer to the same filesystem object. - /// - /// In POSIX, this corresponds to testing whether the two descriptors have the - /// 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. - is-same-object: func(other: borrow) -> bool; - - /// Return a hash of the metadata associated with a filesystem object referred - /// to by a descriptor. - /// - /// This returns a hash of the last-modification timestamp and file size, and - /// may also include the inode number, device number, birth timestamp, and - /// other metadata fields that may change when the file is modified or - /// replaced. It may also include a secret value chosen by the - /// implementation and not otherwise exposed. - /// - /// Implementations are encourated to provide the following properties: - /// - /// - If the file is not modified or replaced, the computed hash value should - /// usually not change. - /// - If the object is modified or replaced, the computed hash value should - /// usually change. - /// - The inputs to the hash should not be easily computable from the - /// computed hash. - /// - /// However, none of these is required. - 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`. - metadata-hash-at: func( - /// Flags determining the method of how the path is resolved. - path-flags: path-flags, - /// The relative path of the file or directory to inspect. - path: string, - ) -> result; - } - - /// A stream of directory entries. - resource directory-entry-stream { - /// Read a single directory entry from a `directory-entry-stream`. - read-directory-entry: func() -> result, error-code>; - } - - /// Attempts to extract a filesystem-related `error-code` from the stream - /// `error` provided. - /// - /// Stream operations which return `stream-error::last-operation-failed` - /// have a payload with more information about the operation that failed. - /// This payload can be passed through to this function to see if there's - /// filesystem-related information about the error to return. - /// - /// Note that this function is fallible because not all stream-related - /// errors are filesystem-related errors. - filesystem-error-code: func(err: borrow) -> option; -} diff --git a/_examples/invoke/wit/deps/filesystem/world.wit b/_examples/invoke/wit/deps/filesystem/world.wit deleted file mode 100644 index 663f579..0000000 --- a/_examples/invoke/wit/deps/filesystem/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:filesystem@0.2.0; - -world imports { - import types; - import preopens; -} diff --git a/_examples/invoke/wit/deps/http/handler.wit b/_examples/invoke/wit/deps/http/handler.wit deleted file mode 100644 index a34a064..0000000 --- a/_examples/invoke/wit/deps/http/handler.wit +++ /dev/null @@ -1,43 +0,0 @@ -/// This interface defines a handler of incoming HTTP Requests. It should -/// be exported by components which can respond to HTTP Requests. -interface incoming-handler { - use types.{incoming-request, response-outparam}; - - /// This function is invoked with an incoming HTTP Request, and a resource - /// `response-outparam` which provides the capability to reply with an HTTP - /// Response. The response is sent by calling the `response-outparam.set` - /// method, which allows execution to continue after the response has been - /// sent. This enables both streaming to the response body, and performing other - /// work. - /// - /// 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. - handle: func( - request: incoming-request, - response-out: response-outparam - ); -} - -/// This interface defines a handler of outgoing HTTP Requests. It should be -/// imported by components which wish to make HTTP Requests. -interface outgoing-handler { - use types.{ - outgoing-request, request-options, future-incoming-response, error-code - }; - - /// This function is invoked with an outgoing HTTP Request, and it returns - /// a resource `future-incoming-response` which represents an HTTP Response - /// which may arrive in the future. - /// - /// The `options` argument accepts optional parameters for the HTTP - /// protocol's transport layer. - /// - /// 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`. - handle: func( - request: outgoing-request, - options: option - ) -> result; -} diff --git a/_examples/invoke/wit/deps/http/proxy.wit b/_examples/invoke/wit/deps/http/proxy.wit deleted file mode 100644 index 687c24d..0000000 --- a/_examples/invoke/wit/deps/http/proxy.wit +++ /dev/null @@ -1,32 +0,0 @@ -package wasi:http@0.2.0; - -/// The `wasi:http/proxy` world captures a widely-implementable intersection of -/// 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. -world proxy { - /// HTTP proxies have access to time and randomness. - include wasi:clocks/imports@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. - import wasi:cli/stdout@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. - 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()`). - import outgoing-handler; - - /// 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`. - export incoming-handler; -} diff --git a/_examples/invoke/wit/deps/io/error.wit b/_examples/invoke/wit/deps/io/error.wit deleted file mode 100644 index 22e5b64..0000000 --- a/_examples/invoke/wit/deps/io/error.wit +++ /dev/null @@ -1,34 +0,0 @@ -package wasi:io@0.2.0; - - -interface error { - /// A resource which represents some error information. - /// - /// The only method provided by this resource is `to-debug-string`, - /// 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, `error`s 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` and returns - /// `option`. - /// - /// The set of functions which can "downcast" an `error` into a more - /// concrete type is open. - resource error { - /// Returns a string that is suitable to assist humans in debugging - /// this error. - /// - /// WARNING: The returned string should not be consumed mechanically! - /// It may change across platforms, hosts, or other implementation - /// details. Parsing this string is a major platform-compatibility - /// hazard. - to-debug-string: func() -> string; - } -} diff --git a/_examples/invoke/wit/deps/io/poll.wit b/_examples/invoke/wit/deps/io/poll.wit deleted file mode 100644 index ddc67f8..0000000 --- a/_examples/invoke/wit/deps/io/poll.wit +++ /dev/null @@ -1,41 +0,0 @@ -package wasi:io@0.2.0; - -/// A poll API intended to let users wait for I/O events on multiple handles -/// at once. -interface poll { - /// `pollable` represents a single I/O event which may be ready, or not. - resource pollable { - - /// Return the readiness of a pollable. This function never blocks. - /// - /// Returns `true` when the pollable is ready, and `false` otherwise. - ready: func() -> bool; - - /// `block` returns immediately if the pollable is ready, and otherwise - /// blocks until ready. - /// - /// This function is equivalent to calling `poll.poll` on a list - /// containing only this pollable. - block: func(); - } - - /// Poll for completion on a set of pollables. - /// - /// This function takes a list of pollables, which identify I/O sources of - /// interest, and waits until one or more of the events is ready for I/O. - /// - /// The result `list` 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. - /// - /// 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. - poll: func(in: list>) -> list; -} diff --git a/_examples/invoke/wit/deps/io/streams.wit b/_examples/invoke/wit/deps/io/streams.wit deleted file mode 100644 index 6d2f871..0000000 --- a/_examples/invoke/wit/deps/io/streams.wit +++ /dev/null @@ -1,262 +0,0 @@ -package wasi:io@0.2.0; - -/// 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; -/// when it does, they are expected to subsume this API. -interface streams { - use error.{error}; - use poll.{pollable}; - - /// An error for input-stream and output-stream operations. - variant stream-error { - /// The last operation (a write or flush) failed before completion. - /// - /// More information is available in the `error` payload. - last-operation-failed(error), - /// The stream is closed: no more input will be accepted by the - /// stream. A closed output-stream will return this error on all - /// future operations. - closed - } - - /// An input bytestream. - /// - /// `input-stream`s are *non-blocking* to the extent practical on underlying - /// platforms. I/O operations always return promptly; if fewer bytes are - /// promptly available than requested, they return the number of bytes promptly - /// available, which could even be zero. To wait for data to be available, - /// use the `subscribe` function to obtain a `pollable` which can be polled - /// for using `wasi:io/poll`. - resource input-stream { - /// 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 - /// empty when no bytes are available for reading at this time. The - /// pollable given by `subscribe` will be ready when more bytes are - /// available. - /// - /// This function fails with a `stream-error` when the operation - /// encounters an error, giving `last-operation-failed`, or when the - /// stream is closed, giving `closed`. - /// - /// When the caller gives a `len` of 0, it represents a request to - /// read 0 bytes. If the stream is still open, this call should - /// succeed and return an empty list, or otherwise fail with `closed`. - /// - /// The `len` parameter is a `u64`, which could represent a list of u8 which - /// is not possible to allocate in wasm32, or not desirable to allocate as - /// 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. - read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Read bytes from a stream, after blocking until at least one byte can - /// be read. Except for blocking, behavior is identical to `read`. - blocking-read: func( - /// The maximum number of bytes to read - len: u64 - ) -> result, stream-error>; - - /// Skip bytes from a stream. Returns number of bytes skipped. - /// - /// Behaves identical to `read`, except instead of returning a list - /// of bytes, returns the number of bytes consumed from the stream. - skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// Skip bytes from a stream, after blocking until at least one byte - /// can be skipped. Except for blocking behavior, identical to `skip`. - blocking-skip: func( - /// The maximum number of bytes to skip. - len: u64, - ) -> result; - - /// 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. - /// The created `pollable` is a child resource of the `input-stream`. - /// Implementations may trap if the `input-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - } - - - /// An output bytestream. - /// - /// `output-stream`s 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`. - resource output-stream { - /// 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 - /// permitted will trap. - /// - /// When this function returns 0 bytes, the `subscribe` pollable will - /// become ready when this function will report at least 1 byte, or an - /// error. - check-write: func() -> result; - - /// 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. - /// - /// returns Err(closed) without writing if the stream has closed since - /// the last call to check-write provided a permit. - write: func( - contents: list - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 bytes, and then flush the stream. Block - /// until all of these operations are complete, or an error occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write`, and `flush`, and is implemented with the - /// following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while !contents.is_empty() { - /// // Wait for the stream to become writable - /// pollable.block(); - /// let Ok(n) = this.check-write(); // eliding error handling - /// let len = min(n, contents.len()); - /// let (chunk, rest) = contents.split_at(len); - /// this.write(chunk ); // eliding error handling - /// contents = rest; - /// } - /// this.flush(); - /// // Wait for completion of `flush` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-and-flush: func( - contents: list - ) -> result<_, stream-error>; - - /// 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 - /// is all that has been passed to `write` prior to this call. - /// - /// Upon calling this function, the `output-stream` will not accept any - /// writes (`check-write` will return `ok(0)`) until the flush has - /// completed. The `subscribe` pollable will become ready when the - /// flush has completed and the stream can accept more writes. - flush: func() -> result<_, stream-error>; - - /// Request to flush buffered output, and block until flush completes - /// and stream is ready for writing again. - blocking-flush: func() -> result<_, stream-error>; - - /// Create a `pollable` which will resolve once the output-stream - /// is ready for more writing, or an error has occured. 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. - /// - /// The created `pollable` is a child resource of the `output-stream`. - /// Implementations may trap if the `output-stream` is dropped before - /// all derived `pollable`s created with this function are dropped. - subscribe: func() -> pollable; - - /// Write zeroes to a stream. - /// - /// 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. - write-zeroes: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Perform a write of up to 4096 zeroes, and then flush the stream. - /// Block until all of these operations are complete, or an error - /// occurs. - /// - /// This is a convenience wrapper around the use of `check-write`, - /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with - /// the following pseudo-code: - /// - /// ```text - /// let pollable = this.subscribe(); - /// while num_zeroes != 0 { - /// // Wait for the stream to become writable - /// 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` - /// pollable.block(); - /// // Check for any errors that arose during `flush` - /// let _ = this.check-write(); // eliding error handling - /// ``` - blocking-write-zeroes-and-flush: func( - /// The number of zero-bytes to write - len: u64 - ) -> result<_, stream-error>; - - /// Read from one stream and write to another. - /// - /// The behavior of splice is equivelant to: - /// 1. calling `check-write` on the `output-stream` - /// 2. calling `read` on the `input-stream` with the smaller of the - /// `check-write` permitted length and the `len` provided to `splice` - /// 3. calling `write` on the `output-stream` with that read data. - /// - /// Any error reported by the call to `check-write`, `read`, or - /// `write` ends the splice and reports that error. - /// - /// This function returns the number of bytes transferred; it may be less - /// than `len`. - splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - - /// 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`. - blocking-splice: func( - /// The stream to read from - src: borrow, - /// The number of bytes to splice - len: u64, - ) -> result; - } -} diff --git a/_examples/invoke/wit/deps/io/world.wit b/_examples/invoke/wit/deps/io/world.wit deleted file mode 100644 index 5f0b43f..0000000 --- a/_examples/invoke/wit/deps/io/world.wit +++ /dev/null @@ -1,6 +0,0 @@ -package wasi:io@0.2.0; - -world imports { - import streams; - import poll; -} diff --git a/_examples/invoke/wit/deps/lattice/bus.wit b/_examples/invoke/wit/deps/lattice/bus.wit deleted file mode 100644 index 9275448..0000000 --- a/_examples/invoke/wit/deps/lattice/bus.wit +++ /dev/null @@ -1,14 +0,0 @@ -package wasmcloud:bus@1.0.0; - -interface lattice { - /// Interface target. This represents an interface, which can be selected by `set-link-name`. - resource call-target-interface { - constructor(namespace: string, %package: string, %interface: string); - } - - /// Set an optional link name to use for all interfaces specified. This is advanced - /// functionality only available within wasmcloud and, as such, is exposed here as part of the - /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces - /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component - set-link-name: func(name: string, interfaces: list); -} diff --git a/_examples/invoke/wit/deps/logging/logging.wit b/_examples/invoke/wit/deps/logging/logging.wit deleted file mode 100644 index 8c0bdf8..0000000 --- a/_examples/invoke/wit/deps/logging/logging.wit +++ /dev/null @@ -1,35 +0,0 @@ -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - - /// Describes messages indicating hazardous situations. - warn, - - /// Describes messages indicating serious errors. - error, - - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} diff --git a/_examples/invoke/wit/deps/logging/world.wit b/_examples/invoke/wit/deps/logging/world.wit deleted file mode 100644 index ede6286..0000000 --- a/_examples/invoke/wit/deps/logging/world.wit +++ /dev/null @@ -1,5 +0,0 @@ -package wasi:logging; - -world imports { - import logging; -} diff --git a/_examples/invoke/wit/deps/messaging/messaging.wit b/_examples/invoke/wit/deps/messaging/messaging.wit deleted file mode 100644 index 239d289..0000000 --- a/_examples/invoke/wit/deps/messaging/messaging.wit +++ /dev/null @@ -1,27 +0,0 @@ -package wasmcloud:messaging@0.2.0; - -// Types common to message broker interactions -interface types { - // A message sent to or received from a broker - record broker-message { - subject: string, - body: list, - reply-to: option, - } -} - -interface handler { - use types.{broker-message}; - - // Callback handled to invoke a function when a message is received from a subscription - handle-message: func(msg: broker-message) -> result<_, string>; -} - -interface consumer { - use types.{broker-message}; - - // Perform a request operation on a subject - request: func(subject: string, body: list, timeout-ms: u32) -> result; - // Publish a message to a subject without awaiting a response - publish: func(msg: broker-message) -> result<_, string>; -} diff --git a/_examples/invoke/wit/deps/random/insecure-seed.wit b/_examples/invoke/wit/deps/random/insecure-seed.wit deleted file mode 100644 index 47210ac..0000000 --- a/_examples/invoke/wit/deps/random/insecure-seed.wit +++ /dev/null @@ -1,25 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure-seed interface for seeding hash-map DoS resistance. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure-seed { - /// Return a 128-bit value that may contain a pseudo-random value. - /// - /// The returned value is not required to be computed from a CSPRNG, and may - /// even be entirely deterministic. Host implementations are encouraged to - /// provide pseudo-random values to any program exposed to - /// attacker-controlled content, to enable DoS protection built into many - /// languages' hash-map implementations. - /// - /// This function is intended to only be called once, by a source language - /// to initialize Denial Of Service (DoS) protection in its hash-map - /// implementation. - /// - /// # Expected future evolution - /// - /// This will likely be changed to a value import, to prevent it from being - /// called multiple times and potentially used for purposes other than DoS - /// protection. - insecure-seed: func() -> tuple; -} diff --git a/_examples/invoke/wit/deps/random/insecure.wit b/_examples/invoke/wit/deps/random/insecure.wit deleted file mode 100644 index c58f4ee..0000000 --- a/_examples/invoke/wit/deps/random/insecure.wit +++ /dev/null @@ -1,22 +0,0 @@ -package wasi:random@0.2.0; -/// The insecure interface for insecure pseudo-random numbers. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface insecure { - /// Return `len` insecure pseudo-random bytes. - /// - /// This function is not cryptographically secure. Do not use it for - /// anything related to security. - /// - /// There are no requirements on the values of the returned bytes, however - /// implementations are encouraged to return evenly distributed values with - /// a long period. - get-insecure-random-bytes: func(len: u64) -> list; - - /// Return an insecure pseudo-random `u64` value. - /// - /// This function returns the same type of pseudo-random data as - /// `get-insecure-random-bytes`, represented as a `u64`. - get-insecure-random-u64: func() -> u64; -} diff --git a/_examples/invoke/wit/deps/random/random.wit b/_examples/invoke/wit/deps/random/random.wit deleted file mode 100644 index 0c017f0..0000000 --- a/_examples/invoke/wit/deps/random/random.wit +++ /dev/null @@ -1,26 +0,0 @@ -package wasi:random@0.2.0; -/// WASI Random is a random data API. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -interface random { - /// Return `len` cryptographically-secure random or pseudo-random bytes. - /// - /// This function must produce data at least as cryptographically secure and - /// fast as an adequately seeded cryptographically-secure pseudo-random - /// number generator (CSPRNG). It must not block, from the perspective of - /// the calling program, under any circumstances, including on the first - /// request and on requests for numbers of bytes. The returned data must - /// always be unpredictable. - /// - /// This function must always return fresh data. Deterministic environments - /// must omit this function, rather than implementing it with deterministic - /// data. - get-random-bytes: func(len: u64) -> list; - - /// Return a cryptographically-secure random or pseudo-random `u64` value. - /// - /// This function returns the same type of data as `get-random-bytes`, - /// represented as a `u64`. - get-random-u64: func() -> u64; -} diff --git a/_examples/invoke/wit/deps/random/world.wit b/_examples/invoke/wit/deps/random/world.wit deleted file mode 100644 index 3da3491..0000000 --- a/_examples/invoke/wit/deps/random/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package wasi:random@0.2.0; - -world imports { - import random; - import insecure; - import insecure-seed; -} diff --git a/_examples/invoke/wit/deps/secrets/secrets.wit b/_examples/invoke/wit/deps/secrets/secrets.wit deleted file mode 100644 index da6f4ad..0000000 --- a/_examples/invoke/wit/deps/secrets/secrets.wit +++ /dev/null @@ -1,56 +0,0 @@ -/// This WIT interface powers secret support in wasmCloud -/// -/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 - -package wasmcloud:secrets@0.1.0-draft; - -interface store { - // An error type that encapsulates the different errors that can occur fetching secrets - variant secrets-error { - // This indicates an error from an "upstream" secrets source. - // As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), - // the error message is a string. - upstream(string), - // This indicates an error from an I/O operation. - // As this could be almost _anything_ (such as a file read, network connection, etc), - // the error message is a string. - // Depending on how this ends up being consumed, - // we may consider moving this to use the `wasi:io/error` type instead. - // For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - // This indicates that the secret was not found. Generally "not found" errors will - // be handled by the upstream secrets backend, but there are cases where the host - // may need to return this error. - not-found, - } - - // A secret value can be either a string or a byte array, which lets you - // store binary data as a secret. - variant secret-value { - // A string value - %string(string), - // A byte array value - bytes(list), - } - - // A secret is a resource that can only be borrowed. This allows you to - // pass around handles to secrets and not reveal the values until a - // component needs them. - // You need to use the reveal interface to get the value. - resource secret; - - // Gets a single opaque secrets value set at the given key if it exists - get: func( - // A string key to fetch - key: string, - ) -> result; - -} - -interface reveal { - use store.{secret, secret-value}; - - // Reveals the value of a secret to the caller. - // This lets you easily audit your code to discover where secrets are being used. - reveal: func(s: borrow) -> secret-value; -} diff --git a/_examples/invoke/wit/deps/sockets/instance-network.wit b/_examples/invoke/wit/deps/sockets/instance-network.wit deleted file mode 100644 index e455d0f..0000000 --- a/_examples/invoke/wit/deps/sockets/instance-network.wit +++ /dev/null @@ -1,9 +0,0 @@ - -/// This interface provides a value-export of the default network handle.. -interface instance-network { - use network.{network}; - - /// Get a handle to the default network. - instance-network: func() -> network; - -} diff --git a/_examples/invoke/wit/deps/sockets/ip-name-lookup.wit b/_examples/invoke/wit/deps/sockets/ip-name-lookup.wit deleted file mode 100644 index 8e639ec..0000000 --- a/_examples/invoke/wit/deps/sockets/ip-name-lookup.wit +++ /dev/null @@ -1,51 +0,0 @@ - -interface ip-name-lookup { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-address}; - - - /// Resolve an internet host name to a list of IP addresses. - /// - /// Unicode domain names are automatically converted to ASCII using IDNA encoding. - /// If the input is an IP address string, the address is parsed and returned - /// as-is without making any external requests. - /// - /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. - /// - /// This function never blocks. It either immediately fails or immediately - /// returns successfully with a `resolve-address-stream` that can be used - /// to (asynchronously) fetch the results. - /// - /// # Typical errors - /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. - /// - /// # References: - /// - - /// - - /// - - /// - - resolve-addresses: func(network: borrow, name: string) -> result; - - resource resolve-address-stream { - /// Returns the next address from the resolver. - /// - /// This function should be called multiple times. On each call, it will - /// return the next address in connection order preference. If all - /// addresses have been exhausted, this function returns `none`. - /// - /// This function never returns IPv4-mapped IPv6 addresses. - /// - /// # Typical errors - /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) - /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) - /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) - /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) - resolve-next-address: func() -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/invoke/wit/deps/sockets/network.wit b/_examples/invoke/wit/deps/sockets/network.wit deleted file mode 100644 index 9cadf06..0000000 --- a/_examples/invoke/wit/deps/sockets/network.wit +++ /dev/null @@ -1,145 +0,0 @@ - -interface network { - /// An opaque resource that represents access to (a subset of) the network. - /// This enables context-based security for networking. - /// There is no need for this to map 1:1 to a physical network interface. - resource network; - - /// Error codes. - /// - /// In theory, every API can return any error code. - /// In practice, API's typically only return the errors documented per API - /// combined with a couple of errors that are always possible: - /// - `unknown` - /// - `access-denied` - /// - `not-supported` - /// - `out-of-memory` - /// - `concurrency-conflict` - /// - /// See each individual API for what the POSIX equivalents are. They sometimes differ per API. - enum error-code { - /// Unknown error - unknown, - - /// Access denied. - /// - /// POSIX equivalent: EACCES, EPERM - access-denied, - - /// The operation is not supported. - /// - /// POSIX equivalent: EOPNOTSUPP - not-supported, - - /// One of the arguments is invalid. - /// - /// POSIX equivalent: EINVAL - invalid-argument, - - /// Not enough memory to complete the operation. - /// - /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY - out-of-memory, - - /// The operation timed out before it could finish completely. - timeout, - - /// This operation is incompatible with another asynchronous operation that is already in progress. - /// - /// POSIX equivalent: EALREADY - concurrency-conflict, - - /// Trying to finish an asynchronous operation that: - /// - has not been started yet, or: - /// - was already finished by a previous `finish-*` call. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - not-in-progress, - - /// The operation has been aborted because it could not be completed immediately. - /// - /// Note: this is scheduled to be removed when `future`s are natively supported. - would-block, - - - /// The operation is not valid in the socket's current state. - invalid-state, - - /// A new socket resource could not be created because of a system limit. - new-socket-limit, - - /// A bind operation failed because the provided address is not an address that the `network` can bind to. - address-not-bindable, - - /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. - address-in-use, - - /// The remote address is not reachable - remote-unreachable, - - - /// The TCP connection was forcefully rejected - connection-refused, - - /// The TCP connection was reset. - connection-reset, - - /// A TCP connection was aborted. - connection-aborted, - - - /// The size of a datagram sent to a UDP socket exceeded the maximum - /// supported size. - datagram-too-large, - - - /// Name does not exist or has no suitable associated IP addresses. - name-unresolvable, - - /// A temporary failure in name resolution occurred. - temporary-resolver-failure, - - /// A permanent failure in name resolution occurred. - permanent-resolver-failure, - } - - enum ip-address-family { - /// Similar to `AF_INET` in POSIX. - ipv4, - - /// Similar to `AF_INET6` in POSIX. - ipv6, - } - - type ipv4-address = tuple; - type ipv6-address = tuple; - - variant ip-address { - ipv4(ipv4-address), - ipv6(ipv6-address), - } - - record ipv4-socket-address { - /// sin_port - port: u16, - /// sin_addr - address: ipv4-address, - } - - record ipv6-socket-address { - /// sin6_port - port: u16, - /// sin6_flowinfo - flow-info: u32, - /// sin6_addr - address: ipv6-address, - /// sin6_scope_id - scope-id: u32, - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - -} diff --git a/_examples/invoke/wit/deps/sockets/tcp-create-socket.wit b/_examples/invoke/wit/deps/sockets/tcp-create-socket.wit deleted file mode 100644 index c7ddf1f..0000000 --- a/_examples/invoke/wit/deps/sockets/tcp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface tcp-create-socket { - use network.{network, error-code, ip-address-family}; - use tcp.{tcp-socket}; - - /// 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`/`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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - create-tcp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/invoke/wit/deps/sockets/tcp.wit b/_examples/invoke/wit/deps/sockets/tcp.wit deleted file mode 100644 index 5902b9e..0000000 --- a/_examples/invoke/wit/deps/sockets/tcp.wit +++ /dev/null @@ -1,353 +0,0 @@ - -interface tcp { - use wasi:io/streams@0.2.0.{input-stream, output-stream}; - use wasi:io/poll@0.2.0.{pollable}; - use wasi:clocks/monotonic-clock@0.2.0.{duration}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - enum shutdown-type { - /// Similar to `SHUT_RD` in POSIX. - receive, - - /// Similar to `SHUT_WR` in POSIX. - send, - - /// Similar to `SHUT_RDWR` in POSIX. - both, - } - - /// A TCP socket resource. - /// - /// The socket can be in one of the following states: - /// - `unbound` - /// - `bind-in-progress` - /// - `bound` (See note below) - /// - `listen-in-progress` - /// - `listening` - /// - `connect-in-progress` - /// - `connected` - /// - `closed` - /// See - /// for a more information. - /// - /// Note: Except where explicitly mentioned, whenever this documentation uses - /// the term "bound" without backticks it actually means: in the `bound` state *or higher*. - /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`) - /// - /// In addition to the general error codes documented on the - /// `network::error-code` type, TCP socket methods may always return - /// `error(invalid-state)` when in the `closed` state. - resource tcp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the TCP/UDP port is zero, the socket will be bound to a random free port. - /// - /// Bind can be attempted multiple times on the same socket, even with - /// different arguments on each iteration. But never concurrently and - /// only as long as the previous bind failed. Once a bind succeeds, the - /// binding can't be changed anymore. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) - /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT - /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR - /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior - /// and SO_REUSEADDR performs something different entirely. - /// - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Connect to a remote endpoint. - /// - /// On success: - /// - the socket is transitioned into the `connection` state. - /// - a pair of streams is returned that can be used to read & write to the connection - /// - /// After a failed connection attempt, the socket will be in the `closed` - /// state and the only valid action left is to `drop` the socket. A single - /// socket can not be used to connect more than once. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) - /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) - /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) - /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) - /// - `timeout`: Connection timed out. (ETIMEDOUT) - /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) - /// - `connection-reset`: The connection was reset. (ECONNRESET) - /// - `connection-aborted`: The connection was aborted. (ECONNABORTED) - /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `not-in-progress`: A connect operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// The POSIX equivalent of `start-connect` is the regular `connect` syscall. - /// Because all WASI sockets are non-blocking this is expected to return - /// EINPROGRESS, which should be translated to `ok()` in WASI. - /// - /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` - /// with a timeout of 0 on the socket descriptor. Followed by a check for - /// the `SO_ERROR` socket option, in case the poll signaled readiness. - /// - /// # References - /// - - /// - - /// - - /// - - start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; - finish-connect: func() -> result, error-code>; - - /// Start listening for new connections. - /// - /// Transitions the socket into the `listening` state. - /// - /// Unlike POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) - /// - `invalid-state`: The socket is already in the `listening` state. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) - /// - `not-in-progress`: A listen operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the listen operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `listen` as part of either `start-listen` or `finish-listen`. - /// - /// # References - /// - - /// - - /// - - /// - - start-listen: func() -> result<_, error-code>; - finish-listen: func() -> result<_, error-code>; - - /// Accept a new client socket. - /// - /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: - /// - `address-family` - /// - `keep-alive-enabled` - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// - `hop-limit` - /// - `receive-buffer-size` - /// - `send-buffer-size` - /// - /// On success, this function returns the newly accepted client socket along with - /// a pair of streams that can be used to read & write to the connection. - /// - /// # Typical errors - /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) - /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) - /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References - /// - - /// - - /// - - /// - - accept: func() -> result, error-code>; - - /// Get the bound local address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the remote address. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether the socket is in the `listening` state. - /// - /// Equivalent to the SO_ACCEPTCONN socket option. - is-listening: func() -> bool; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Hints the desired listen queue size. Implementations are free to ignore this. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// - /// # Typical errors - /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - /// - `invalid-argument`: (set) The provided value was 0. - /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. - set-listen-backlog-size: func(value: u64) -> result<_, error-code>; - - /// Enables or disables keepalive. - /// - /// The keepalive behavior can be adjusted using: - /// - `keep-alive-idle-time` - /// - `keep-alive-interval` - /// - `keep-alive-count` - /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. - /// - /// Equivalent to the SO_KEEPALIVE socket option. - keep-alive-enabled: func() -> result; - set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; - - /// Amount of time the connection has to be idle before TCP starts sending keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-idle-time: func() -> result; - set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; - - /// The time between keepalive packets. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPINTVL socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-interval: func() -> result; - set-keep-alive-interval: func(value: duration) -> result<_, error-code>; - - /// The maximum amount of keepalive packets TCP should send before aborting the connection. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the TCP_KEEPCNT socket option. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - keep-alive-count: func() -> result; - set-keep-alive-count: func(value: u32) -> result<_, error-code>; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - hop-limit: func() -> result; - set-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which can be used to poll for, or block on, - /// completion of any of the asynchronous operations of this socket. - /// - /// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` - /// return `error(would-block)`, this pollable can be used to wait for - /// their success or failure, after which the method can be retried. - /// - /// The pollable is not limited to the async operation that happens to be - /// in progress at the time of calling `subscribe` (if any). Theoretically, - /// `subscribe` only has to be called once per socket and can then be - /// (re)used for the remainder of the socket's lifetime. - /// - /// See - /// for a more information. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - - /// Initiate a graceful shutdown. - /// - /// - `receive`: The socket is not expecting to receive any data from - /// the peer. The `input-stream` associated with this socket will be - /// closed. Any data still in the receive queue at time of calling - /// this method will be discarded. - /// - `send`: The socket has no more data to send to the peer. The `output-stream` - /// associated with this socket will be closed and a FIN packet will be sent. - /// - `both`: Same effect as `receive` & `send` combined. - /// - /// This function is idempotent. Shutting a down a direction more than once - /// has no effect and returns `ok`. - /// - /// The shutdown function does not close (drop) the socket. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; - } -} diff --git a/_examples/invoke/wit/deps/sockets/udp-create-socket.wit b/_examples/invoke/wit/deps/sockets/udp-create-socket.wit deleted file mode 100644 index 0482d1f..0000000 --- a/_examples/invoke/wit/deps/sockets/udp-create-socket.wit +++ /dev/null @@ -1,27 +0,0 @@ - -interface udp-create-socket { - use network.{network, error-code, ip-address-family}; - use udp.{udp-socket}; - - /// Create a new UDP socket. - /// - /// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` 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` 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. - /// - /// # Typical errors - /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) - /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) - /// - /// # References: - /// - - /// - - /// - - /// - - create-udp-socket: func(address-family: ip-address-family) -> result; -} diff --git a/_examples/invoke/wit/deps/sockets/udp.wit b/_examples/invoke/wit/deps/sockets/udp.wit deleted file mode 100644 index d987a0a..0000000 --- a/_examples/invoke/wit/deps/sockets/udp.wit +++ /dev/null @@ -1,266 +0,0 @@ - -interface udp { - use wasi:io/poll@0.2.0.{pollable}; - use network.{network, error-code, ip-socket-address, ip-address-family}; - - /// A received datagram. - record incoming-datagram { - /// The payload. - /// - /// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - data: list, - - /// The source address. - /// - /// This field is guaranteed to match the remote address the stream was initialized with, if any. - /// - /// Equivalent to the `src_addr` out parameter of `recvfrom`. - remote-address: ip-socket-address, - } - - /// A datagram to be sent out. - record outgoing-datagram { - /// The payload. - data: list, - - /// The destination address. - /// - /// The requirements on this field depend on how the stream was initialized: - /// - with a remote address: this field must be None or match the stream's remote address exactly. - /// - without a remote address: this field is required. - /// - /// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. - remote-address: option, - } - - - - /// A UDP socket handle. - resource udp-socket { - /// Bind the socket to a specific network on the provided IP address and port. - /// - /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which - /// network interface(s) to bind to. - /// If the port is zero, the socket will be bound to a random free port. - /// - /// # Typical errors - /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - /// - `invalid-state`: The socket is already bound. (EINVAL) - /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) - /// - `address-in-use`: Address is already in use. (EADDRINUSE) - /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) - /// - `not-in-progress`: A `bind` operation is not in progress. - /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) - /// - /// # Implementors note - /// Unlike in POSIX, in WASI the bind operation is async. This enables - /// interactive WASI hosts to inject permission prompts. Runtimes that - /// don't want to make use of this ability can simply call the native - /// `bind` as part of either `start-bind` or `finish-bind`. - /// - /// # References - /// - - /// - - /// - - /// - - start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; - finish-bind: func() -> result<_, error-code>; - - /// Set up inbound & outbound communication channels, optionally to a specific peer. - /// - /// This function only changes the local socket configuration and does not generate any network traffic. - /// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, - /// based on the best network path to `remote-address`. - /// - /// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: - /// - `send` can only be used to send to this destination. - /// - `receive` will only return datagrams sent from the provided `remote-address`. - /// - /// This method may be called multiple times on the same socket to change its association, but - /// only the most recently returned pair of streams will be operational. Implementations may trap if - /// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. - /// - /// The POSIX equivalent in pseudo-code is: - /// ```text - /// if (was previously connected) { - /// connect(s, AF_UNSPEC) - /// } - /// if (remote_address is Some) { - /// connect(s, remote_address) - /// } - /// ``` - /// - /// Unlike in POSIX, the socket must already be explicitly bound. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-state`: The socket is not bound. - /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - %stream: func(remote-address: option) -> result, error-code>; - - /// Get the current bound address. - /// - /// POSIX mentions: - /// > If the socket has not been bound to a local name, the value - /// > stored in the object pointed to by `address` is unspecified. - /// - /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not bound to any local address. - /// - /// # References - /// - - /// - - /// - - /// - - local-address: func() -> result; - - /// Get the address the socket is currently streaming to. - /// - /// # Typical errors - /// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) - /// - /// # References - /// - - /// - - /// - - /// - - remote-address: func() -> result; - - /// Whether this is a IPv4 or IPv6 socket. - /// - /// Equivalent to the SO_DOMAIN socket option. - address-family: func() -> ip-address-family; - - /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The TTL value must be 1 or higher. - unicast-hop-limit: func() -> result; - set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; - - /// The kernel buffer space reserved for sends/receives on this socket. - /// - /// If the provided value is 0, an `invalid-argument` error is returned. - /// Any other value will never cause an error, but it might be silently clamped and/or rounded. - /// I.e. after setting a value, reading the same setting back may return a different value. - /// - /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - /// - /// # Typical errors - /// - `invalid-argument`: (set) The provided value was 0. - receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - - /// Create a `pollable` which will resolve once the socket is ready for I/O. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource incoming-datagram-stream { - /// Receive messages on the socket. - /// - /// This function attempts to receive up to `max-results` datagrams on the socket without blocking. - /// The returned list may contain fewer elements than requested, but never more. - /// - /// This function returns successfully with an empty list when either: - /// - `max-results` is 0, or: - /// - `max-results` is greater than 0, but no results are immediately available. - /// This function never returns `error(would-block)`. - /// - /// # Typical errors - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - receive: func(max-results: u64) -> result, error-code>; - - /// Create a `pollable` which will resolve once the stream is ready to receive again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } - - resource outgoing-datagram-stream { - /// Check readiness for sending. This function never blocks. - /// - /// Returns the number of datagrams permitted for the next call to `send`, - /// or an error. Calling `send` with more datagrams than this function has - /// permitted will trap. - /// - /// When this function returns ok(0), the `subscribe` pollable will - /// become ready when this function will report at least ok(1), or an - /// error. - /// - /// Never returns `would-block`. - check-send: func() -> result; - - /// Send messages on the socket. - /// - /// This function attempts to send all provided `datagrams` on the socket without blocking and - /// returns how many messages were actually sent (or queued for sending). This function never - /// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. - /// - /// This function semantically behaves the same as iterating the `datagrams` list and sequentially - /// sending each individual datagram until either the end of the list has been reached or the first error occurred. - /// If at least one datagram has been sent successfully, this function never returns an error. - /// - /// If the input list is empty, the function returns `ok(0)`. - /// - /// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if - /// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. - /// - /// # Typical errors - /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) - /// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) - /// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) - /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) - /// - `connection-refused`: The connection was refused. (ECONNREFUSED) - /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - /// - /// # References - /// - - /// - - /// - - /// - - /// - - /// - - /// - - /// - - send: func(datagrams: list) -> result; - - /// Create a `pollable` which will resolve once the stream is ready to send again. - /// - /// Note: this function is here for WASI Preview2 only. - /// It's planned to be removed when `future` is natively supported in Preview3. - subscribe: func() -> pollable; - } -} diff --git a/_examples/invoke/wit/deps/sockets/world.wit b/_examples/invoke/wit/deps/sockets/world.wit deleted file mode 100644 index f8bb92a..0000000 --- a/_examples/invoke/wit/deps/sockets/world.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi:sockets@0.2.0; - -world imports { - import instance-network; - import network; - import udp; - import udp-create-socket; - import tcp; - import tcp-create-socket; - import ip-name-lookup; -} diff --git a/_examples/invoke/wit/deps/wasi-cli-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-cli-0.2.0/package.wit new file mode 100644 index 0000000..0a2737b --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-cli-0.2.0/package.wit @@ -0,0 +1,159 @@ +package wasi:cli@0.2.0; + +interface environment { + /// Get the POSIX-style environment variables. + /// + /// Each environment variable is provided as a pair of string variable names + /// and string value. + /// + /// Morally, these are a value import, but until value imports are available + /// in the component model, this import function should return the same + /// values each time it is called. + get-environment: func() -> list>; + + /// Get the POSIX-style arguments to the program. + get-arguments: func() -> list; + + /// Return a path that programs should use as their initial current working + /// directory, interpreting `.` as shorthand for this. + initial-cwd: func() -> option; +} + +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} + +interface run { + /// Run the program. + run: func() -> result; +} + +interface stdin { + use wasi:io/streams@0.2.0.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0.{output-stream}; + + get-stderr: func() -> output-stream; +} + +/// Terminal input. +/// +/// In the future, this may include functions for disabling echoing, +/// disabling input buffering so that keyboard events are sent through +/// immediately, querying supported features, and so on. +interface terminal-input { + /// The input side of a terminal. + resource terminal-input; +} + +/// Terminal output. +/// +/// In the future, this may include functions for querying the terminal +/// size, being notified of terminal size changes, querying supported +/// features, and so on. +interface terminal-output { + /// The output side of a terminal. + resource terminal-output; +} + +/// An interface providing an optional `terminal-input` for stdin as a +/// link-time authority. +interface terminal-stdin { + use terminal-input.{terminal-input}; + + /// If stdin is connected to a terminal, return a `terminal-input` handle + /// allowing further interaction with it. + get-terminal-stdin: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stdout as a +/// link-time authority. +interface terminal-stdout { + use terminal-output.{terminal-output}; + + /// If stdout is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stdout: func() -> option; +} + +/// An interface providing an optional `terminal-output` for stderr as a +/// link-time authority. +interface terminal-stderr { + use terminal-output.{terminal-output}; + + /// If stderr is connected to a terminal, return a `terminal-output` handle + /// allowing further interaction with it. + get-terminal-stderr: func() -> option; +} + +world imports { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; +} +world command { + import environment; + import exit; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import stdin; + import stdout; + import stderr; + import terminal-input; + import terminal-output; + import terminal-stdin; + import terminal-stdout; + import terminal-stderr; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:clocks/wall-clock@0.2.0; + import wasi:filesystem/types@0.2.0; + import wasi:filesystem/preopens@0.2.0; + import wasi:sockets/network@0.2.0; + import wasi:sockets/instance-network@0.2.0; + import wasi:sockets/udp@0.2.0; + import wasi:sockets/udp-create-socket@0.2.0; + import wasi:sockets/tcp@0.2.0; + import wasi:sockets/tcp-create-socket@0.2.0; + import wasi:sockets/ip-name-lookup@0.2.0; + import wasi:random/random@0.2.0; + import wasi:random/insecure@0.2.0; + import wasi:random/insecure-seed@0.2.0; + + export run; +} diff --git a/_examples/invoke/wit/deps/wasi-clocks-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-clocks-0.2.0/package.wit new file mode 100644 index 0000000..9e0ba3d --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-clocks-0.2.0/package.wit @@ -0,0 +1,29 @@ +package wasi:clocks@0.2.0; + +interface monotonic-clock { + use wasi:io/poll@0.2.0.{pollable}; + + type instant = u64; + + type duration = u64; + + now: func() -> instant; + + resolution: func() -> duration; + + subscribe-instant: func(when: instant) -> pollable; + + subscribe-duration: func(when: duration) -> pollable; +} + +interface wall-clock { + record datetime { + seconds: u64, + nanoseconds: u32, + } + + now: func() -> datetime; + + resolution: func() -> datetime; +} + diff --git a/_examples/invoke/wit/deps/wasi-config-0.2.0-draft/package.wit b/_examples/invoke/wit/deps/wasi-config-0.2.0-draft/package.wit new file mode 100644 index 0000000..7065b9b --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-config-0.2.0-draft/package.wit @@ -0,0 +1,28 @@ +package wasi:config@0.2.0-draft; + +interface runtime { + /// An error type that encapsulates the different errors that can occur fetching config + variant config-error { + /// This indicates an error from an "upstream" config source. + /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + } + + /// Gets a single opaque config value set at the given key if it exists + get: func(key: string) -> result, config-error>; + + /// Gets a list of all set config data + get-all: func() -> result>, config-error>; +} + +world imports { + import runtime; +} diff --git a/_examples/invoke/wit/deps/wasi-filesystem-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-filesystem-0.2.0/package.wit new file mode 100644 index 0000000..cb6a2be --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-filesystem-0.2.0/package.wit @@ -0,0 +1,158 @@ +package wasi:filesystem@0.2.0; + +interface types { + use wasi:io/streams@0.2.0.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0.{datetime}; + + type filesize = u64; + + enum descriptor-type { + unknown, + block-device, + character-device, + directory, + fifo, + symbolic-link, + regular-file, + socket, + } + + flags descriptor-flags { + read, + write, + file-integrity-sync, + data-integrity-sync, + requested-write-sync, + mutate-directory, + } + + flags path-flags { + symlink-follow, + } + + flags open-flags { + create, + directory, + exclusive, + truncate, + } + + type link-count = u64; + + record descriptor-stat { + %type: descriptor-type, + link-count: link-count, + size: filesize, + data-access-timestamp: option, + data-modification-timestamp: option, + status-change-timestamp: option, + } + + variant new-timestamp { + no-change, + now, + timestamp(datetime), + } + + record directory-entry { + %type: descriptor-type, + name: string, + } + + enum error-code { + 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, + } + + enum advice { + normal, + sequential, + random, + will-need, + dont-need, + no-reuse, + } + + record metadata-hash-value { + lower: u64, + upper: u64, + } + + resource descriptor { + read-via-stream: func(offset: filesize) -> result; + write-via-stream: func(offset: filesize) -> result; + append-via-stream: func() -> result; + advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>; + sync-data: func() -> result<_, error-code>; + get-flags: func() -> result; + get-type: func() -> result; + set-size: func(size: filesize) -> result<_, error-code>; + set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + read: func(length: filesize, offset: filesize) -> result, bool>, error-code>; + write: func(buffer: list, offset: filesize) -> result; + read-directory: func() -> result; + sync: func() -> result<_, error-code>; + create-directory-at: func(path: string) -> result<_, error-code>; + stat: func() -> result; + stat-at: func(path-flags: path-flags, path: string) -> result; + set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result; + readlink-at: func(path: string) -> result; + remove-directory-at: func(path: string) -> result<_, error-code>; + rename-at: func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; + symlink-at: func(old-path: string, new-path: string) -> result<_, error-code>; + unlink-file-at: func(path: string) -> result<_, error-code>; + is-same-object: func(other: borrow) -> bool; + metadata-hash: func() -> result; + metadata-hash-at: func(path-flags: path-flags, path: string) -> result; + } + + resource directory-entry-stream { + read-directory-entry: func() -> result, error-code>; + } + + filesystem-error-code: func(err: borrow) -> option; +} + +interface preopens { + use types.{descriptor}; + + get-directories: func() -> list>; +} + diff --git a/_examples/invoke/wit/deps/http/types.wit b/_examples/invoke/wit/deps/wasi-http-0.2.0/package.wit similarity index 88% rename from _examples/invoke/wit/deps/http/types.wit rename to _examples/invoke/wit/deps/wasi-http-0.2.0/package.wit index 755ac6a..11f7ff4 100644 --- a/_examples/invoke/wit/deps/http/types.wit +++ b/_examples/invoke/wit/deps/wasi-http-0.2.0/package.wit @@ -1,3 +1,5 @@ +package wasi:http@0.2.0; + /// 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. @@ -18,18 +20,36 @@ interface types { options, trace, patch, - other(string) + other(string), } /// This type corresponds to HTTP standard Related Schemes. variant scheme { HTTP, HTTPS, - other(string) + other(string), + } + + /// Defines the case payload type for `DNS-error` above: + record DNS-error-payload { + rcode: option, + info-code: option, + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option, } /// 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 + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types variant error-code { DNS-timeout, DNS-error(DNS-error-payload), @@ -74,40 +94,9 @@ interface types { /// unstructured description of the error. Users should not depend on the /// string for diagnosing errors, as it's not required to be consistent /// between implementations. - internal-error(option) - } - - /// Defines the case payload type for `DNS-error` above: - record DNS-error-payload { - rcode: option, - info-code: option - } - - /// Defines the case payload type for `TLS-alert-received` above: - record TLS-alert-received-payload { - alert-id: option, - alert-message: option - } - - /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: - record field-size-payload { - field-name: option, - field-size: option + internal-error(option), } - /// Attempts to extract a http-related `error` from the wasi:io `error` - /// provided. - /// - /// Stream operations which return - /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of - /// type `wasi:io/error/error` with more information about the operation - /// that failed. This payload can be passed through to this function to see - /// if there's http-related information about the error to return. - /// - /// Note that this function is fallible because not all io-errors are - /// http-related errors. - 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. variant header-error { @@ -115,11 +104,9 @@ interface types { /// syntactically invalid when used with an operation that sets headers in a /// `fields`. invalid-syntax, - /// This error indicates that a forbidden `field-key` was used when trying /// to set a header in a `fields`. forbidden, - /// This error indicates that the operation on the `fields` was not /// permitted because the fields are immutable. immutable, @@ -144,12 +131,10 @@ interface types { /// immutable. In an immutable fields, the `set`, `append`, and `delete` /// operations will fail with `header-error.immutable`. resource fields { - /// Construct an empty HTTP Fields. /// /// The resulting `fields` is mutable. constructor(); - /// Construct an HTTP Fields. /// /// The resulting `fields` is mutable. @@ -165,46 +150,37 @@ interface types { /// /// An error result will be returned if any header or value was /// syntactically invalid, or if a header was forbidden. - from-list: static func( - entries: list> - ) -> result; - + from-list: static func(entries: list>) -> result; /// Get all of the values corresponding to a key. If the key is not present /// in this `fields`, 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. 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. has: func(name: field-key) -> bool; - /// Set all of the values for a key. Clears any existing values for that /// key, if they have been set. /// /// Fails with `header-error.immutable` if the `fields` are immutable. set: func(name: field-key, value: list) -> result<_, header-error>; - /// Delete all values for a key. Does nothing if no values for the key /// exist. /// /// Fails with `header-error.immutable` if the `fields` are immutable. delete: func(name: field-key) -> result<_, header-error>; - /// Append a value for a key. Does not change or delete any existing /// values for that key. /// /// Fails with `header-error.immutable` if the `fields` are immutable. append: func(name: field-key, value: field-value) -> result<_, header-error>; - /// 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 /// which have multiple values are represented by multiple entries in this /// list with the same key. - entries: func() -> list>; - + entries: func() -> list>; /// Make a deep copy of the Fields. Equivelant in behavior to calling the /// `fields` constructor on the return value of `entries`. The resulting /// `fields` is mutable. @@ -219,19 +195,14 @@ interface types { /// Represents an incoming HTTP Request. resource incoming-request { - /// Returns the method of the incoming request. method: func() -> method; - /// Returns the path with query parameters from the request, as a string. path-with-query: func() -> option; - /// Returns the protocol scheme from the request. scheme: func() -> option; - /// Returns the authority from the request, if it was present. authority: func() -> option; - /// Get the `headers` associated with the request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -241,7 +212,6 @@ interface types { /// the parent `incoming-request` is dropped. Dropping this /// `incoming-request` before all children are dropped will trap. headers: func() -> headers; - /// Gives the `incoming-body` associated with this request. Will only /// return success at most once, and subsequent calls will return error. consume: func() -> result; @@ -249,7 +219,6 @@ interface types { /// Represents an outgoing HTTP Request. resource outgoing-request { - /// Construct a new `outgoing-request` with a default `method` of `GET`, and /// `none` values for `path-with-query`, `scheme`, and `authority`. /// @@ -260,10 +229,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`. - constructor( - headers: headers - ); - + constructor(headers: headers); /// Returns the resource corresponding to the outgoing Body for this /// Request. /// @@ -271,13 +237,11 @@ interface types { /// this `outgoing-request` can be retrieved at most once. Subsequent /// calls will return error. body: func() -> result; - /// Get the Method for the Request. 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. 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. path-with-query: func() -> option; @@ -285,7 +249,6 @@ interface types { /// 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-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. scheme: func() -> option; @@ -293,7 +256,6 @@ interface types { /// implementation may choose an appropriate default scheme. Fails if the /// string given is not a syntactically valid uri scheme. 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. @@ -303,7 +265,6 @@ interface types { /// HTTPS schemes always require an authority. Fails if the string given is /// not a syntactically valid uri authority. set-authority: func(authority: option) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -324,25 +285,19 @@ interface types { resource request-options { /// Construct a default `request-options` value. constructor(); - /// The timeout for the initial connect to the HTTP Server. 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. set-connect-timeout: func(duration: option) -> result; - /// The timeout for receiving the first byte of the Response body. 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. set-first-byte-timeout: func(duration: option) -> result; - /// The timeout for receiving subsequent chunks of bytes in the Response /// body stream. 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. @@ -355,7 +310,6 @@ interface types { /// allow a Response to be sent corresponding to the Request provided as the /// other argument to `incoming-handler.handle`. resource response-outparam { - /// Set the value of the `response-outparam` to either send a response, /// or indicate an error. /// @@ -365,10 +319,7 @@ interface types { /// /// The user may provide an `error` to `response` to allow the /// implementation determine how to respond with an HTTP error response. - set: static func( - param: response-outparam, - response: result, - ); + set: static func(param: response-outparam, response: result); } /// This type corresponds to the HTTP standard Status Code. @@ -376,10 +327,8 @@ interface types { /// Represents an incoming HTTP Response. resource incoming-response { - /// Returns the status code from the incoming response. status: func() -> status-code; - /// Returns the headers from the incoming response. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -388,7 +337,6 @@ interface types { /// This headers resource is a child: it must be dropped before the parent /// `incoming-response` is dropped. headers: func() -> headers; - /// Returns the incoming body. May be called at most once. Returns error /// if called additional times. consume: func() -> result; @@ -403,7 +351,6 @@ interface types { /// and ensures that the user of this interface may only be consuming either /// the body contents or waiting on trailers at any given time. resource incoming-body { - /// Returns the contents of the body, as a stream of bytes. /// /// Returns success on first call: the stream representing the contents @@ -420,7 +367,6 @@ interface types { /// and for that backpressure to not inhibit delivery of the trailers if /// the user does not read the entire body. %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. finish: static func(this: incoming-body) -> future-trailers; @@ -432,12 +378,10 @@ interface types { /// trailers, this future will resolve to the empty set of trailers once the /// complete Request or Response body has been received. resource future-trailers { - /// Returns a pollable which becomes ready when either the trailers have /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the contents of the trailers, or an error which occured, /// once the future is ready. /// @@ -462,21 +406,17 @@ interface types { /// Represents an outgoing HTTP Response. resource outgoing-response { - /// Construct an `outgoing-response`, with a default `status-code` of `200`. /// If a different `status-code` is needed, it must be set via the /// `set-status-code` method. /// /// * `headers` is the HTTP Headers for the Response. constructor(headers: headers); - /// Get the HTTP Status Code for the Response. 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. set-status-code: func(status-code: status-code) -> result; - /// Get the headers associated with the Request. /// /// The returned `headers` resource is immutable: `set`, `append`, and @@ -486,7 +426,6 @@ interface types { /// `outgoing-request` is dropped, or its ownership is transfered to /// another component by e.g. `outgoing-handler.handle`. headers: func() -> headers; - /// Returns the resource corresponding to the outgoing Body for this Response. /// /// Returns success on the first call: the `outgoing-body` resource for @@ -512,7 +451,6 @@ interface types { /// including: corrupting the body on the wire, aborting the associated /// Request, or sending a late status code for the Response. resource outgoing-body { - /// Returns a stream for writing the body contents. /// /// The returned `output-stream` is a child resource: it must be dropped @@ -523,7 +461,6 @@ interface types { /// this `outgoing-body` may be retrieved at most once. Subsequent calls /// will return error. write: func() -> result; - /// 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 @@ -533,10 +470,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. - finish: static func( - this: outgoing-body, - trailers: option - ) -> result<_, error-code>; + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; } /// Represents a future which may eventaully return an incoming HTTP @@ -549,7 +483,6 @@ interface types { /// been received, or an error has occured. When this pollable is ready, /// the `get` method will return `some`. subscribe: func() -> pollable; - /// Returns the incoming HTTP Response, or an error, once one is ready. /// /// The outer `option` represents future readiness. Users can wait on this @@ -565,6 +498,74 @@ interface types { /// but those will be reported by the `incoming-body` and its /// `output-stream` child. get: func() -> option>>; - } + + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + http-error-code: func(err: borrow) -> option; +} + +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// 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. + handle: func(request: incoming-request, response-out: response-outparam); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error-code}; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// 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`. + handle: func(request: outgoing-request, options: option) -> result; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// 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. +world proxy { + import wasi:random/random@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/poll@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import types; + import outgoing-handler; + import wasi:clocks/wall-clock@0.2.0; + + export incoming-handler; } diff --git a/_examples/invoke/wit/deps/wasi-io-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-io-0.2.0/package.wit new file mode 100644 index 0000000..1840029 --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-io-0.2.0/package.wit @@ -0,0 +1,48 @@ +package wasi:io@0.2.0; + +interface error { + resource error { + to-debug-string: func() -> string; + } +} + +interface poll { + resource pollable { + ready: func() -> bool; + block: func(); + } + + poll: func(in: list>) -> list; +} + +interface streams { + use error.{error}; + use poll.{pollable}; + + variant stream-error { + last-operation-failed(error), + closed, + } + + resource input-stream { + read: func(len: u64) -> result, stream-error>; + blocking-read: func(len: u64) -> result, stream-error>; + skip: func(len: u64) -> result; + blocking-skip: func(len: u64) -> result; + subscribe: func() -> pollable; + } + + resource output-stream { + check-write: func() -> result; + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) -> result<_, stream-error>; + flush: func() -> result<_, stream-error>; + blocking-flush: func() -> result<_, stream-error>; + subscribe: func() -> pollable; + write-zeroes: func(len: u64) -> result<_, stream-error>; + blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>; + splice: func(src: borrow, len: u64) -> result; + blocking-splice: func(src: borrow, len: u64) -> result; + } +} + diff --git a/_examples/invoke/wit/deps/wasi-logging-0.1.0-draft/package.wit b/_examples/invoke/wit/deps/wasi-logging-0.1.0-draft/package.wit new file mode 100644 index 0000000..df4e8de --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-logging-0.1.0-draft/package.wit @@ -0,0 +1,36 @@ +package wasi:logging; + +/// WASI Logging is a logging API intended to let users emit log messages with +/// simple priority levels and context values. +interface logging { + /// A log level, describing a kind of message. + enum level { + /// Describes messages about the values of variables and the flow of + /// control within a program. + trace, + /// Describes messages likely to be of interest to someone debugging a + /// program. + debug, + /// Describes messages likely to be of interest to someone monitoring a + /// program. + info, + /// Describes messages indicating hazardous situations. + warn, + /// Describes messages indicating serious errors. + error, + /// Describes messages indicating fatal errors. + critical, + } + + /// Emit a log message. + /// + /// A log message has a `level` describing what kind of message is being + /// sent, a context, which is an uninterpreted string meant to help + /// consumers group similar messages, and a string containing the message + /// text. + log: func(level: level, context: string, message: string); +} + +world imports { + import logging; +} diff --git a/_examples/invoke/wit/deps/wasi-random-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-random-0.2.0/package.wit new file mode 100644 index 0000000..58c179e --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-random-0.2.0/package.wit @@ -0,0 +1,18 @@ +package wasi:random@0.2.0; + +interface random { + get-random-bytes: func(len: u64) -> list; + + get-random-u64: func() -> u64; +} + +interface insecure { + get-insecure-random-bytes: func(len: u64) -> list; + + get-insecure-random-u64: func() -> u64; +} + +interface insecure-seed { + insecure-seed: func() -> tuple; +} + diff --git a/_examples/invoke/wit/deps/wasi-sockets-0.2.0/package.wit b/_examples/invoke/wit/deps/wasi-sockets-0.2.0/package.wit new file mode 100644 index 0000000..0602b85 --- /dev/null +++ b/_examples/invoke/wit/deps/wasi-sockets-0.2.0/package.wit @@ -0,0 +1,179 @@ +package wasi:sockets@0.2.0; + +interface network { + resource network; + + enum error-code { + unknown, + access-denied, + not-supported, + invalid-argument, + out-of-memory, + timeout, + concurrency-conflict, + not-in-progress, + would-block, + invalid-state, + new-socket-limit, + address-not-bindable, + address-in-use, + remote-unreachable, + connection-refused, + connection-reset, + connection-aborted, + datagram-too-large, + name-unresolvable, + temporary-resolver-failure, + permanent-resolver-failure, + } + + enum ip-address-family { + ipv4, + ipv6, + } + + type ipv4-address = tuple; + + type ipv6-address = tuple; + + variant ip-address { + ipv4(ipv4-address), + ipv6(ipv6-address), + } + + record ipv4-socket-address { + port: u16, + address: ipv4-address, + } + + record ipv6-socket-address { + port: u16, + flow-info: u32, + address: ipv6-address, + scope-id: u32, + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } +} + +interface instance-network { + use network.{network}; + + instance-network: func() -> network; +} + +interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + record incoming-datagram { + data: list, + remote-address: ip-socket-address, + } + + record outgoing-datagram { + data: list, + remote-address: option, + } + + resource udp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + %stream: func(remote-address: option) -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + address-family: func() -> ip-address-family; + unicast-hop-limit: func() -> result; + set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + } + + resource incoming-datagram-stream { + receive: func(max-results: u64) -> result, error-code>; + subscribe: func() -> pollable; + } + + resource outgoing-datagram-stream { + check-send: func() -> result; + send: func(datagrams: list) -> result; + subscribe: func() -> pollable; + } +} + +interface udp-create-socket { + use network.{network, error-code, ip-address-family}; + use udp.{udp-socket}; + + create-udp-socket: func(address-family: ip-address-family) -> result; +} + +interface tcp { + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/poll@0.2.0.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + enum shutdown-type { + receive, + send, + both, + } + + resource tcp-socket { + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + finish-connect: func() -> result, error-code>; + start-listen: func() -> result<_, error-code>; + finish-listen: func() -> result<_, error-code>; + accept: func() -> result, error-code>; + local-address: func() -> result; + remote-address: func() -> result; + is-listening: func() -> bool; + address-family: func() -> ip-address-family; + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + keep-alive-enabled: func() -> result; + set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; + keep-alive-idle-time: func() -> result; + set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; + keep-alive-interval: func() -> result; + set-keep-alive-interval: func(value: duration) -> result<_, error-code>; + keep-alive-count: func() -> result; + set-keep-alive-count: func(value: u32) -> result<_, error-code>; + hop-limit: func() -> result; + set-hop-limit: func(value: u8) -> result<_, error-code>; + receive-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + send-buffer-size: func() -> result; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + subscribe: func() -> pollable; + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} + +interface tcp-create-socket { + use network.{network, error-code, ip-address-family}; + use tcp.{tcp-socket}; + + create-tcp-socket: func(address-family: ip-address-family) -> result; +} + +interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network, error-code, ip-address}; + + resource resolve-address-stream { + resolve-next-address: func() -> result, error-code>; + subscribe: func() -> pollable; + } + + resolve-addresses: func(network: borrow, name: string) -> result; +} + diff --git a/_examples/invoke/wit/deps/wasmcloud-bus-1.0.0/package.wit b/_examples/invoke/wit/deps/wasmcloud-bus-1.0.0/package.wit new file mode 100644 index 0000000..1008a6f --- /dev/null +++ b/_examples/invoke/wit/deps/wasmcloud-bus-1.0.0/package.wit @@ -0,0 +1,15 @@ +package wasmcloud:bus@1.0.0; + +interface lattice { + /// Interface target. This represents an interface, which can be selected by `set-link-name`. + resource call-target-interface { + constructor(namespace: string, %package: string, %interface: string); + } + + /// Set an optional link name to use for all interfaces specified. This is advanced + /// functionality only available within wasmcloud and, as such, is exposed here as part of the + /// wasmcloud:bus package. This is used when you are linking multiple of the same interfaces + /// (i.e. a keyvalue implementation for caching and another one for secrets) to a component + set-link-name: func(name: string, interfaces: list); +} + diff --git a/_examples/http-client/wit/deps/component/world.wit b/_examples/invoke/wit/deps/wasmcloud-component-go/world.wit similarity index 77% rename from _examples/http-client/wit/deps/component/world.wit rename to _examples/invoke/wit/deps/wasmcloud-component-go/world.wit index 186845a..f881ff8 100644 --- a/_examples/http-client/wit/deps/component/world.wit +++ b/_examples/invoke/wit/deps/wasmcloud-component-go/world.wit @@ -1,11 +1,8 @@ -package wasmcloud:component; +package wasmcloud:component-go@0.1.0; world exports { // wasi export wasi:http/incoming-handler@0.2.0; - - // wasmcloud - export wasmcloud:messaging/handler@0.2.0; } world imports { @@ -19,7 +16,6 @@ world imports { // wasmcloud import wasmcloud:bus/lattice@1.0.0; - import wasmcloud:messaging/consumer@0.2.0; import wasmcloud:secrets/store@0.1.0-draft; import wasmcloud:secrets/reveal@0.1.0-draft; } diff --git a/_examples/invoke/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit b/_examples/invoke/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit new file mode 100644 index 0000000..a431b95 --- /dev/null +++ b/_examples/invoke/wit/deps/wasmcloud-secrets-0.1.0-draft/package.wit @@ -0,0 +1,52 @@ +/// This WIT interface powers secret support in wasmCloud +/// +/// See RFC #2190 https://github.com/wasmCloud/wasmCloud/issues/2190 +package wasmcloud:secrets@0.1.0-draft; + +interface store { + /// An error type that encapsulates the different errors that can occur fetching secrets + variant secrets-error { + /// This indicates an error from an "upstream" secrets source. + /// As this could be almost _anything_ (such as Vault, Kubernetes Secrets, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + /// This indicates that the secret was not found. Generally "not found" errors will + /// be handled by the upstream secrets backend, but there are cases where the host + /// may need to return this error. + not-found, + } + + /// A secret value can be either a string or a byte array, which lets you + /// store binary data as a secret. + variant secret-value { + /// A string value + %string(string), + /// A byte array value + bytes(list), + } + + /// A secret is a resource that can only be borrowed. This allows you to + /// pass around handles to secrets and not reveal the values until a + /// component needs them. + /// You need to use the reveal interface to get the value. + resource secret; + + /// Gets a single opaque secrets value set at the given key if it exists + get: func(key: string) -> result; +} + +interface reveal { + use store.{secret, secret-value}; + + /// Reveals the value of a secret to the caller. + /// This lets you easily audit your code to discover where secrets are being used. + reveal: func(s: borrow) -> secret-value; +} + diff --git a/_examples/invoke/wit/world.wit b/_examples/invoke/wit/world.wit index a13f6c0..0cf3cc6 100644 --- a/_examples/invoke/wit/world.wit +++ b/_examples/invoke/wit/world.wit @@ -5,6 +5,6 @@ interface invoker { } world example { - include wasmcloud:component/imports; + include wasmcloud:component-go/imports@0.1.0; export invoker; }