From 5ae39901101044255c33e32ff6a72fc89b5b807b Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sun, 1 Sep 2024 06:58:46 +0530 Subject: [PATCH 1/6] copy wit file over from spin and generate bindings Signed-off-by: Rajat Jindal --- v2/README.md | 11 + v2/go.mod | 3 + v2/internal/fermyon/spin/config/abi.go | 12 + v2/internal/fermyon/spin/config/config.wit.go | 76 + v2/internal/fermyon/spin/config/empty.s | 3 + .../spin/http-trigger/http-trigger.wit.go | 4 + .../fermyon/spin/http-types/http-types.wit.go | 136 ++ v2/internal/fermyon/spin/http/abi.go | 34 + v2/internal/fermyon/spin/http/empty.s | 3 + v2/internal/fermyon/spin/http/http.wit.go | 24 + v2/internal/fermyon/spin/inbound-http/abi.go | 24 + v2/internal/fermyon/spin/inbound-http/empty.s | 3 + .../spin/inbound-http/inbound-http.exports.go | 15 + .../spin/inbound-http/inbound-http.wit.go | 17 + v2/internal/fermyon/spin/key-value/abi.go | 12 + v2/internal/fermyon/spin/key-value/empty.s | 3 + .../fermyon/spin/key-value/key-value.wit.go | 264 ++ v2/internal/fermyon/spin/llm/abi.go | 43 + v2/internal/fermyon/spin/llm/empty.s | 3 + v2/internal/fermyon/spin/llm/llm.wit.go | 201 ++ v2/internal/fermyon/spin/mysql/abi.go | 18 + v2/internal/fermyon/spin/mysql/empty.s | 3 + v2/internal/fermyon/spin/mysql/mysql.wit.go | 124 + v2/internal/fermyon/spin/postgres/abi.go | 18 + v2/internal/fermyon/spin/postgres/empty.s | 3 + .../fermyon/spin/postgres/postgres.wit.go | 124 + .../spin/rdbms-types/rdbms-types.wit.go | 428 ++++ .../spin/redis-types/redis-types.wit.go | 123 + v2/internal/fermyon/spin/redis/empty.s | 3 + v2/internal/fermyon/spin/redis/redis.wit.go | 183 ++ v2/internal/fermyon/spin/sqlite/abi.go | 17 + v2/internal/fermyon/spin/sqlite/empty.s | 3 + v2/internal/fermyon/spin/sqlite/sqlite.wit.go | 240 ++ .../v2.0.0/http-trigger/http-trigger.wit.go | 6 + .../fermyon/spin/v2.0.0/key-value/abi.go | 18 + .../fermyon/spin/v2.0.0/key-value/empty.s | 3 + .../spin/v2.0.0/key-value/key-value.wit.go | 210 ++ v2/internal/fermyon/spin/v2.0.0/llm/abi.go | 43 + v2/internal/fermyon/spin/v2.0.0/llm/empty.s | 3 + .../fermyon/spin/v2.0.0/llm/llm.wit.go | 201 ++ v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 12 + v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s | 3 + .../fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 166 ++ v2/internal/fermyon/spin/v2.0.0/mysql/abi.go | 18 + v2/internal/fermyon/spin/v2.0.0/mysql/empty.s | 3 + .../fermyon/spin/v2.0.0/mysql/mysql.wit.go | 87 + .../fermyon/spin/v2.0.0/postgres/abi.go | 18 + .../fermyon/spin/v2.0.0/postgres/empty.s | 3 + .../spin/v2.0.0/postgres/postgres.wit.go | 88 + .../v2.0.0/rdbms-types/rdbms-types.wit.go | 503 ++++ v2/internal/fermyon/spin/v2.0.0/redis/abi.go | 18 + v2/internal/fermyon/spin/v2.0.0/redis/empty.s | 3 + .../fermyon/spin/v2.0.0/redis/redis.wit.go | 376 +++ v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go | 17 + .../fermyon/spin/v2.0.0/sqlite/empty.s | 3 + .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 240 ++ .../fermyon/spin/v2.0.0/variables/abi.go | 12 + .../fermyon/spin/v2.0.0/variables/empty.s | 3 + .../spin/v2.0.0/variables/variables.wit.go | 87 + .../wasi/cli/v0.2.0/environment/empty.s | 3 + .../cli/v0.2.0/environment/environment.wit.go | 64 + v2/internal/wasi/cli/v0.2.0/exit/empty.s | 3 + v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 25 + v2/internal/wasi/cli/v0.2.0/stderr/empty.s | 3 + .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 24 + v2/internal/wasi/cli/v0.2.0/stdin/empty.s | 3 + .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 24 + v2/internal/wasi/cli/v0.2.0/stdout/empty.s | 3 + .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 24 + .../wasi/cli/v0.2.0/terminal-input/empty.s | 3 + .../terminal-input/terminal-input.wit.go | 36 + .../wasi/cli/v0.2.0/terminal-output/empty.s | 3 + .../terminal-output/terminal-output.wit.go | 36 + .../wasi/cli/v0.2.0/terminal-stderr/empty.s | 3 + .../terminal-stderr/terminal-stderr.wit.go | 29 + .../wasi/cli/v0.2.0/terminal-stdin/empty.s | 3 + .../terminal-stdin/terminal-stdin.wit.go | 29 + .../wasi/cli/v0.2.0/terminal-stdout/empty.s | 3 + .../terminal-stdout/terminal-stdout.wit.go | 29 + .../clocks/v0.2.0/monotonic-clock/empty.s | 3 + .../monotonic-clock/monotonic-clock.wit.go | 113 + .../wasi/clocks/v0.2.0/wall-clock/empty.s | 3 + .../v0.2.0/wall-clock/wall-clock.wit.go | 78 + .../wasi/filesystem/v0.2.0/preopens/empty.s | 3 + .../v0.2.0/preopens/preopens.wit.go | 25 + .../wasi/filesystem/v0.2.0/types/abi.go | 51 + .../wasi/filesystem/v0.2.0/types/empty.s | 3 + .../wasi/filesystem/v0.2.0/types/types.wit.go | 1357 +++++++++++ .../wasi/http/v0.2.0/incoming-handler/empty.s | 3 + .../incoming-handler.exports.go | 26 + .../incoming-handler/incoming-handler.wit.go | 21 + .../wasi/http/v0.2.0/outgoing-handler/abi.go | 24 + .../wasi/http/v0.2.0/outgoing-handler/empty.s | 3 + .../outgoing-handler/outgoing-handler.wit.go | 40 + v2/internal/wasi/http/v0.2.0/types/abi.go | 273 +++ v2/internal/wasi/http/v0.2.0/types/empty.s | 3 + .../wasi/http/v0.2.0/types/types.wit.go | 2141 +++++++++++++++++ v2/internal/wasi/io/v0.2.0/error/empty.s | 3 + v2/internal/wasi/io/v0.2.0/error/error.wit.go | 71 + v2/internal/wasi/io/v0.2.0/poll/empty.s | 3 + v2/internal/wasi/io/v0.2.0/poll/poll.wit.go | 108 + v2/internal/wasi/io/v0.2.0/streams/abi.go | 12 + v2/internal/wasi/io/v0.2.0/streams/empty.s | 3 + .../wasi/io/v0.2.0/streams/streams.wit.go | 519 ++++ .../wasi/random/v0.2.0/insecure-seed/empty.s | 3 + .../v0.2.0/insecure-seed/insecure-seed.wit.go | 41 + .../wasi/random/v0.2.0/insecure/empty.s | 3 + .../random/v0.2.0/insecure/insecure.wit.go | 57 + v2/internal/wasi/random/v0.2.0/random/empty.s | 3 + .../wasi/random/v0.2.0/random/random.wit.go | 61 + .../sockets/v0.2.0/instance-network/empty.s | 3 + .../instance-network/instance-network.wit.go | 28 + .../wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 14 + .../sockets/v0.2.0/ip-name-lookup/empty.s | 3 + .../ip-name-lookup/ip-name-lookup.wit.go | 121 + .../wasi/sockets/v0.2.0/network/abi.go | 12 + .../wasi/sockets/v0.2.0/network/empty.s | 3 + .../sockets/v0.2.0/network/network.wit.go | 315 +++ .../sockets/v0.2.0/tcp-create-socket/empty.s | 3 + .../tcp-create-socket.wit.go | 52 + v2/internal/wasi/sockets/v0.2.0/tcp/abi.go | 86 + v2/internal/wasi/sockets/v0.2.0/tcp/empty.s | 3 + .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 848 +++++++ .../sockets/v0.2.0/udp-create-socket/empty.s | 3 + .../udp-create-socket.wit.go | 52 + v2/internal/wasi/sockets/v0.2.0/udp/abi.go | 101 + v2/internal/wasi/sockets/v0.2.0/udp/empty.s | 3 + .../wasi/sockets/v0.2.0/udp/udp.wit.go | 641 +++++ v2/wit/deps/cli-2023-10-18/command.wit | 7 + v2/wit/deps/cli-2023-10-18/environment.wit | 18 + v2/wit/deps/cli-2023-10-18/exit.wit | 4 + v2/wit/deps/cli-2023-10-18/reactor.wit | 32 + v2/wit/deps/cli-2023-10-18/run.wit | 4 + v2/wit/deps/cli-2023-10-18/stdio.wit | 17 + v2/wit/deps/cli-2023-10-18/terminal.wit | 47 + v2/wit/deps/cli-2023-11-10/command.wit | 7 + v2/wit/deps/cli-2023-11-10/environment.wit | 18 + v2/wit/deps/cli-2023-11-10/exit.wit | 4 + v2/wit/deps/cli-2023-11-10/reactor.wit | 31 + v2/wit/deps/cli-2023-11-10/run.wit | 4 + v2/wit/deps/cli-2023-11-10/stdio.wit | 17 + v2/wit/deps/cli-2023-11-10/terminal.wit | 47 + v2/wit/deps/cli/command.wit | 7 + v2/wit/deps/cli/environment.wit | 18 + v2/wit/deps/cli/exit.wit | 4 + v2/wit/deps/cli/imports.wit | 20 + v2/wit/deps/cli/run.wit | 4 + v2/wit/deps/cli/stdio.wit | 17 + v2/wit/deps/cli/terminal.wit | 49 + .../clocks-2023-10-18/monotonic-clock.wit | 32 + v2/wit/deps/clocks-2023-10-18/timezone.wit | 48 + v2/wit/deps/clocks-2023-10-18/wall-clock.wit | 41 + v2/wit/deps/clocks-2023-10-18/world.wit | 7 + .../clocks-2023-11-10/monotonic-clock.wit | 45 + v2/wit/deps/clocks-2023-11-10/wall-clock.wit | 42 + v2/wit/deps/clocks-2023-11-10/world.wit | 6 + v2/wit/deps/clocks/monotonic-clock.wit | 45 + v2/wit/deps/clocks/wall-clock.wit | 42 + v2/wit/deps/clocks/world.wit | 6 + .../deps/filesystem-2023-10-18/preopens.wit | 6 + v2/wit/deps/filesystem-2023-10-18/types.wit | 810 +++++++ v2/wit/deps/filesystem-2023-10-18/world.wit | 6 + .../deps/filesystem-2023-11-10/preopens.wit | 8 + v2/wit/deps/filesystem-2023-11-10/types.wit | 634 +++++ v2/wit/deps/filesystem-2023-11-10/world.wit | 6 + v2/wit/deps/filesystem/preopens.wit | 8 + v2/wit/deps/filesystem/types.wit | 634 +++++ v2/wit/deps/filesystem/world.wit | 6 + .../deps/http-2023-10-18/incoming-handler.wit | 24 + .../deps/http-2023-10-18/outgoing-handler.wit | 20 + v2/wit/deps/http-2023-10-18/proxy.wit | 34 + v2/wit/deps/http-2023-10-18/types.wit | 208 ++ v2/wit/deps/http-2023-11-10/handler.wit | 43 + v2/wit/deps/http-2023-11-10/proxy.wit | 33 + v2/wit/deps/http-2023-11-10/types.wit | 559 +++++ v2/wit/deps/http/handler.wit | 43 + v2/wit/deps/http/proxy.wit | 32 + v2/wit/deps/http/types.wit | 570 +++++ v2/wit/deps/io-2023-10-18/poll.wit | 32 + v2/wit/deps/io-2023-10-18/streams.wit | 287 +++ v2/wit/deps/io-2023-10-18/world.wit | 1 + v2/wit/deps/io-2023-11-10/error.wit | 34 + v2/wit/deps/io-2023-11-10/poll.wit | 41 + v2/wit/deps/io-2023-11-10/streams.wit | 251 ++ v2/wit/deps/io-2023-11-10/world.wit | 6 + v2/wit/deps/io/error.wit | 34 + v2/wit/deps/io/poll.wit | 41 + v2/wit/deps/io/streams.wit | 262 ++ v2/wit/deps/io/world.wit | 6 + .../deps/random-2023-10-18/insecure-seed.wit | 24 + v2/wit/deps/random-2023-10-18/insecure.wit | 21 + v2/wit/deps/random-2023-10-18/random.wit | 25 + v2/wit/deps/random-2023-10-18/world.wit | 7 + .../deps/random-2023-11-10/insecure-seed.wit | 25 + v2/wit/deps/random-2023-11-10/insecure.wit | 22 + v2/wit/deps/random-2023-11-10/random.wit | 26 + v2/wit/deps/random-2023-11-10/world.wit | 7 + v2/wit/deps/random/insecure-seed.wit | 25 + v2/wit/deps/random/insecure.wit | 22 + v2/wit/deps/random/random.wit | 26 + v2/wit/deps/random/world.wit | 7 + .../sockets-2023-10-18/instance-network.wit | 9 + .../sockets-2023-10-18/ip-name-lookup.wit | 61 + v2/wit/deps/sockets-2023-10-18/network.wit | 146 ++ .../sockets-2023-10-18/tcp-create-socket.wit | 26 + v2/wit/deps/sockets-2023-10-18/tcp.wit | 268 +++ .../sockets-2023-10-18/udp-create-socket.wit | 26 + v2/wit/deps/sockets-2023-10-18/udp.wit | 213 ++ v2/wit/deps/sockets-2023-10-18/world.wit | 11 + .../sockets-2023-11-10/instance-network.wit | 9 + .../sockets-2023-11-10/ip-name-lookup.wit | 51 + v2/wit/deps/sockets-2023-11-10/network.wit | 147 ++ .../sockets-2023-11-10/tcp-create-socket.wit | 26 + v2/wit/deps/sockets-2023-11-10/tcp.wit | 321 +++ .../sockets-2023-11-10/udp-create-socket.wit | 26 + v2/wit/deps/sockets-2023-11-10/udp.wit | 277 +++ v2/wit/deps/sockets-2023-11-10/world.wit | 11 + v2/wit/deps/sockets/instance-network.wit | 9 + v2/wit/deps/sockets/ip-name-lookup.wit | 51 + v2/wit/deps/sockets/network.wit | 145 ++ v2/wit/deps/sockets/tcp-create-socket.wit | 27 + v2/wit/deps/sockets/tcp.wit | 353 +++ v2/wit/deps/sockets/udp-create-socket.wit | 27 + v2/wit/deps/sockets/udp.wit | 266 ++ v2/wit/deps/sockets/world.wit | 11 + v2/wit/deps/spin@unversioned/config.wit | 12 + v2/wit/deps/spin@unversioned/http-types.wit | 44 + v2/wit/deps/spin@unversioned/http.wit | 5 + v2/wit/deps/spin@unversioned/inbound-http.wit | 5 + .../deps/spin@unversioned/inbound-redis.wit | 6 + v2/wit/deps/spin@unversioned/key-value.wit | 80 + v2/wit/deps/spin@unversioned/llm.wit | 70 + v2/wit/deps/spin@unversioned/mysql.wit | 19 + v2/wit/deps/spin@unversioned/postgres.wit | 19 + v2/wit/deps/spin@unversioned/rdbms-types.wit | 65 + v2/wit/deps/spin@unversioned/redis-types.wit | 24 + v2/wit/deps/spin@unversioned/redis.wit | 31 + v2/wit/deps/spin@unversioned/sqlite.wit | 52 + v2/wit/deps/spin@unversioned/world.wit | 29 + v2/wit/key-value.wit | 47 + v2/wit/llm.wit | 70 + v2/wit/mqtt.wit | 31 + v2/wit/mysql.wit | 15 + v2/wit/postgres.wit | 15 + v2/wit/rdbms-types.wit | 80 + v2/wit/redis.wit | 70 + v2/wit/sqlite.wit | 50 + v2/wit/variables.wit | 18 + v2/wit/world.wit | 41 + 249 files changed, 21041 insertions(+) create mode 100644 v2/README.md create mode 100644 v2/go.mod create mode 100644 v2/internal/fermyon/spin/config/abi.go create mode 100644 v2/internal/fermyon/spin/config/config.wit.go create mode 100644 v2/internal/fermyon/spin/config/empty.s create mode 100644 v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go create mode 100644 v2/internal/fermyon/spin/http-types/http-types.wit.go create mode 100644 v2/internal/fermyon/spin/http/abi.go create mode 100644 v2/internal/fermyon/spin/http/empty.s create mode 100644 v2/internal/fermyon/spin/http/http.wit.go create mode 100644 v2/internal/fermyon/spin/inbound-http/abi.go create mode 100644 v2/internal/fermyon/spin/inbound-http/empty.s create mode 100644 v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go create mode 100644 v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go create mode 100644 v2/internal/fermyon/spin/key-value/abi.go create mode 100644 v2/internal/fermyon/spin/key-value/empty.s create mode 100644 v2/internal/fermyon/spin/key-value/key-value.wit.go create mode 100644 v2/internal/fermyon/spin/llm/abi.go create mode 100644 v2/internal/fermyon/spin/llm/empty.s create mode 100644 v2/internal/fermyon/spin/llm/llm.wit.go create mode 100644 v2/internal/fermyon/spin/mysql/abi.go create mode 100644 v2/internal/fermyon/spin/mysql/empty.s create mode 100644 v2/internal/fermyon/spin/mysql/mysql.wit.go create mode 100644 v2/internal/fermyon/spin/postgres/abi.go create mode 100644 v2/internal/fermyon/spin/postgres/empty.s create mode 100644 v2/internal/fermyon/spin/postgres/postgres.wit.go create mode 100644 v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go create mode 100644 v2/internal/fermyon/spin/redis-types/redis-types.wit.go create mode 100644 v2/internal/fermyon/spin/redis/empty.s create mode 100644 v2/internal/fermyon/spin/redis/redis.wit.go create mode 100644 v2/internal/fermyon/spin/sqlite/abi.go create mode 100644 v2/internal/fermyon/spin/sqlite/empty.s create mode 100644 v2/internal/fermyon/spin/sqlite/sqlite.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/key-value/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/key-value/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/llm/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/llm/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/mysql/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/mysql/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/postgres/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/postgres/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/redis/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/redis/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/variables/abi.go create mode 100644 v2/internal/fermyon/spin/v2.0.0/variables/empty.s create mode 100644 v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/environment/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/exit/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/stderr/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/stdin/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/stdout/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s create mode 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go create mode 100644 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s create mode 100644 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go create mode 100644 v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s create mode 100644 v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go create mode 100644 v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s create mode 100644 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go create mode 100644 v2/internal/wasi/filesystem/v0.2.0/types/abi.go create mode 100644 v2/internal/wasi/filesystem/v0.2.0/types/empty.s create mode 100644 v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go create mode 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s create mode 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go create mode 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go create mode 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go create mode 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s create mode 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go create mode 100644 v2/internal/wasi/http/v0.2.0/types/abi.go create mode 100644 v2/internal/wasi/http/v0.2.0/types/empty.s create mode 100644 v2/internal/wasi/http/v0.2.0/types/types.wit.go create mode 100644 v2/internal/wasi/io/v0.2.0/error/empty.s create mode 100644 v2/internal/wasi/io/v0.2.0/error/error.wit.go create mode 100644 v2/internal/wasi/io/v0.2.0/poll/empty.s create mode 100644 v2/internal/wasi/io/v0.2.0/poll/poll.wit.go create mode 100644 v2/internal/wasi/io/v0.2.0/streams/abi.go create mode 100644 v2/internal/wasi/io/v0.2.0/streams/empty.s create mode 100644 v2/internal/wasi/io/v0.2.0/streams/streams.wit.go create mode 100644 v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s create mode 100644 v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go create mode 100644 v2/internal/wasi/random/v0.2.0/insecure/empty.s create mode 100644 v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go create mode 100644 v2/internal/wasi/random/v0.2.0/random/empty.s create mode 100644 v2/internal/wasi/random/v0.2.0/random/random.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/network/abi.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/network/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/network/network.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/tcp/abi.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/tcp/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/udp/abi.go create mode 100644 v2/internal/wasi/sockets/v0.2.0/udp/empty.s create mode 100644 v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go create mode 100644 v2/wit/deps/cli-2023-10-18/command.wit create mode 100644 v2/wit/deps/cli-2023-10-18/environment.wit create mode 100644 v2/wit/deps/cli-2023-10-18/exit.wit create mode 100644 v2/wit/deps/cli-2023-10-18/reactor.wit create mode 100644 v2/wit/deps/cli-2023-10-18/run.wit create mode 100644 v2/wit/deps/cli-2023-10-18/stdio.wit create mode 100644 v2/wit/deps/cli-2023-10-18/terminal.wit create mode 100644 v2/wit/deps/cli-2023-11-10/command.wit create mode 100644 v2/wit/deps/cli-2023-11-10/environment.wit create mode 100644 v2/wit/deps/cli-2023-11-10/exit.wit create mode 100644 v2/wit/deps/cli-2023-11-10/reactor.wit create mode 100644 v2/wit/deps/cli-2023-11-10/run.wit create mode 100644 v2/wit/deps/cli-2023-11-10/stdio.wit create mode 100644 v2/wit/deps/cli-2023-11-10/terminal.wit create mode 100644 v2/wit/deps/cli/command.wit create mode 100644 v2/wit/deps/cli/environment.wit create mode 100644 v2/wit/deps/cli/exit.wit create mode 100644 v2/wit/deps/cli/imports.wit create mode 100644 v2/wit/deps/cli/run.wit create mode 100644 v2/wit/deps/cli/stdio.wit create mode 100644 v2/wit/deps/cli/terminal.wit create mode 100644 v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit create mode 100644 v2/wit/deps/clocks-2023-10-18/timezone.wit create mode 100644 v2/wit/deps/clocks-2023-10-18/wall-clock.wit create mode 100644 v2/wit/deps/clocks-2023-10-18/world.wit create mode 100644 v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit create mode 100644 v2/wit/deps/clocks-2023-11-10/wall-clock.wit create mode 100644 v2/wit/deps/clocks-2023-11-10/world.wit create mode 100644 v2/wit/deps/clocks/monotonic-clock.wit create mode 100644 v2/wit/deps/clocks/wall-clock.wit create mode 100644 v2/wit/deps/clocks/world.wit create mode 100644 v2/wit/deps/filesystem-2023-10-18/preopens.wit create mode 100644 v2/wit/deps/filesystem-2023-10-18/types.wit create mode 100644 v2/wit/deps/filesystem-2023-10-18/world.wit create mode 100644 v2/wit/deps/filesystem-2023-11-10/preopens.wit create mode 100644 v2/wit/deps/filesystem-2023-11-10/types.wit create mode 100644 v2/wit/deps/filesystem-2023-11-10/world.wit create mode 100644 v2/wit/deps/filesystem/preopens.wit create mode 100644 v2/wit/deps/filesystem/types.wit create mode 100644 v2/wit/deps/filesystem/world.wit create mode 100644 v2/wit/deps/http-2023-10-18/incoming-handler.wit create mode 100644 v2/wit/deps/http-2023-10-18/outgoing-handler.wit create mode 100644 v2/wit/deps/http-2023-10-18/proxy.wit create mode 100644 v2/wit/deps/http-2023-10-18/types.wit create mode 100644 v2/wit/deps/http-2023-11-10/handler.wit create mode 100644 v2/wit/deps/http-2023-11-10/proxy.wit create mode 100644 v2/wit/deps/http-2023-11-10/types.wit create mode 100644 v2/wit/deps/http/handler.wit create mode 100644 v2/wit/deps/http/proxy.wit create mode 100644 v2/wit/deps/http/types.wit create mode 100644 v2/wit/deps/io-2023-10-18/poll.wit create mode 100644 v2/wit/deps/io-2023-10-18/streams.wit create mode 100644 v2/wit/deps/io-2023-10-18/world.wit create mode 100644 v2/wit/deps/io-2023-11-10/error.wit create mode 100644 v2/wit/deps/io-2023-11-10/poll.wit create mode 100644 v2/wit/deps/io-2023-11-10/streams.wit create mode 100644 v2/wit/deps/io-2023-11-10/world.wit create mode 100644 v2/wit/deps/io/error.wit create mode 100644 v2/wit/deps/io/poll.wit create mode 100644 v2/wit/deps/io/streams.wit create mode 100644 v2/wit/deps/io/world.wit create mode 100644 v2/wit/deps/random-2023-10-18/insecure-seed.wit create mode 100644 v2/wit/deps/random-2023-10-18/insecure.wit create mode 100644 v2/wit/deps/random-2023-10-18/random.wit create mode 100644 v2/wit/deps/random-2023-10-18/world.wit create mode 100644 v2/wit/deps/random-2023-11-10/insecure-seed.wit create mode 100644 v2/wit/deps/random-2023-11-10/insecure.wit create mode 100644 v2/wit/deps/random-2023-11-10/random.wit create mode 100644 v2/wit/deps/random-2023-11-10/world.wit create mode 100644 v2/wit/deps/random/insecure-seed.wit create mode 100644 v2/wit/deps/random/insecure.wit create mode 100644 v2/wit/deps/random/random.wit create mode 100644 v2/wit/deps/random/world.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/instance-network.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/network.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/tcp.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/udp.wit create mode 100644 v2/wit/deps/sockets-2023-10-18/world.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/instance-network.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/network.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/tcp.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/udp.wit create mode 100644 v2/wit/deps/sockets-2023-11-10/world.wit create mode 100644 v2/wit/deps/sockets/instance-network.wit create mode 100644 v2/wit/deps/sockets/ip-name-lookup.wit create mode 100644 v2/wit/deps/sockets/network.wit create mode 100644 v2/wit/deps/sockets/tcp-create-socket.wit create mode 100644 v2/wit/deps/sockets/tcp.wit create mode 100644 v2/wit/deps/sockets/udp-create-socket.wit create mode 100644 v2/wit/deps/sockets/udp.wit create mode 100644 v2/wit/deps/sockets/world.wit create mode 100644 v2/wit/deps/spin@unversioned/config.wit create mode 100644 v2/wit/deps/spin@unversioned/http-types.wit create mode 100644 v2/wit/deps/spin@unversioned/http.wit create mode 100644 v2/wit/deps/spin@unversioned/inbound-http.wit create mode 100644 v2/wit/deps/spin@unversioned/inbound-redis.wit create mode 100644 v2/wit/deps/spin@unversioned/key-value.wit create mode 100644 v2/wit/deps/spin@unversioned/llm.wit create mode 100644 v2/wit/deps/spin@unversioned/mysql.wit create mode 100644 v2/wit/deps/spin@unversioned/postgres.wit create mode 100644 v2/wit/deps/spin@unversioned/rdbms-types.wit create mode 100644 v2/wit/deps/spin@unversioned/redis-types.wit create mode 100644 v2/wit/deps/spin@unversioned/redis.wit create mode 100644 v2/wit/deps/spin@unversioned/sqlite.wit create mode 100644 v2/wit/deps/spin@unversioned/world.wit create mode 100644 v2/wit/key-value.wit create mode 100644 v2/wit/llm.wit create mode 100644 v2/wit/mqtt.wit create mode 100644 v2/wit/mysql.wit create mode 100644 v2/wit/postgres.wit create mode 100644 v2/wit/rdbms-types.wit create mode 100644 v2/wit/redis.wit create mode 100644 v2/wit/sqlite.wit create mode 100644 v2/wit/variables.wit create mode 100644 v2/wit/world.wit diff --git a/v2/README.md b/v2/README.md new file mode 100644 index 0000000..3aedb4e --- /dev/null +++ b/v2/README.md @@ -0,0 +1,11 @@ +WIP + +spin-go-sdk with wasip2 support + +Notes: + +The bindings are generated with following tooling: + + +- ydnar/wasm-tools-go `a45ed842846a419a5efd02b9384e14417cc90817` +- wasm-tools `wasm-tools 1.216.0 (28c8962b1 2024-08-22)` \ No newline at end of file diff --git a/v2/go.mod b/v2/go.mod new file mode 100644 index 0000000..cea507d --- /dev/null +++ b/v2/go.mod @@ -0,0 +1,3 @@ +module github.com/fermyon/spin-go-sdk/v2 + +go 1.22.6 diff --git a/v2/internal/fermyon/spin/config/abi.go b/v2/internal/fermyon/spin/config/abi.go new file mode 100644 index 0000000..fb89be6 --- /dev/null +++ b/v2/internal/fermyon/spin/config/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package config + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} diff --git a/v2/internal/fermyon/spin/config/config.wit.go b/v2/internal/fermyon/spin/config/config.wit.go new file mode 100644 index 0000000..063d142 --- /dev/null +++ b/v2/internal/fermyon/spin/config/config.wit.go @@ -0,0 +1,76 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package config represents the imported interface "fermyon:spin/config". +package config + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the variant "fermyon:spin/config#error". +// +// variant error { +// provider(string), +// invalid-key(string), +// invalid-schema(string), +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorProvider returns a [Error] of case "provider". +func ErrorProvider(data string) Error { + return cm.New[Error](0, data) +} + +// Provider returns a non-nil *[string] if [Error] represents the variant case "provider". +func (self *Error) Provider() *string { + return cm.Case[string](self, 0) +} + +// ErrorInvalidKey returns a [Error] of case "invalid-key". +func ErrorInvalidKey(data string) Error { + return cm.New[Error](1, data) +} + +// InvalidKey returns a non-nil *[string] if [Error] represents the variant case "invalid-key". +func (self *Error) InvalidKey() *string { + return cm.Case[string](self, 1) +} + +// ErrorInvalidSchema returns a [Error] of case "invalid-schema". +func ErrorInvalidSchema(data string) Error { + return cm.New[Error](2, data) +} + +// InvalidSchema returns a non-nil *[string] if [Error] represents the variant case "invalid-schema". +func (self *Error) InvalidSchema() *string { + return cm.Case[string](self, 2) +} + +// ErrorOther returns a [Error] of case "other". +func ErrorOther(data string) Error { + return cm.New[Error](3, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 3) +} + +// GetConfig represents the imported function "get-config". +// +// Get a configuration value for the current component. +// The config key must match one defined in in the component manifest. +// +// get-config: func(key: string) -> result +// +//go:nosplit +func GetConfig(key string) (result cm.Result[ErrorShape, string, Error]) { + key0, key1 := cm.LowerString(key) + wasmimport_GetConfig((*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/config get-config +//go:noescape +func wasmimport_GetConfig(key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/fermyon/spin/config/empty.s b/v2/internal/fermyon/spin/config/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/config/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go new file mode 100644 index 0000000..258da3c --- /dev/null +++ b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package httptrigger represents the world "fermyon:spin/http-trigger". +package httptrigger diff --git a/v2/internal/fermyon/spin/http-types/http-types.wit.go b/v2/internal/fermyon/spin/http-types/http-types.wit.go new file mode 100644 index 0000000..fe11ccc --- /dev/null +++ b/v2/internal/fermyon/spin/http-types/http-types.wit.go @@ -0,0 +1,136 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package httptypes represents the imported interface "fermyon:spin/http-types". +package httptypes + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// HTTPStatus represents the u16 "fermyon:spin/http-types#http-status". +// +// type http-status = u16 +type HTTPStatus uint16 + +// Body represents the list "fermyon:spin/http-types#body". +// +// type body = list +type Body cm.List[uint8] + +// Headers represents the list "fermyon:spin/http-types#headers". +// +// type headers = list> +type Headers cm.List[[2]string] + +// Params represents the list "fermyon:spin/http-types#params". +// +// type params = list> +type Params cm.List[[2]string] + +// URI represents the string "fermyon:spin/http-types#uri". +// +// type uri = string +type URI string + +// Method represents the enum "fermyon:spin/http-types#method". +// +// enum method { +// get, +// post, +// put, +// delete, +// patch, +// head, +// options +// } +type Method uint8 + +const ( + MethodGet Method = iota + MethodPost + MethodPut + MethodDelete + MethodPatch + MethodHead + MethodOptions +) + +var stringsMethod = [7]string{ + "get", + "post", + "put", + "delete", + "patch", + "head", + "options", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Method) String() string { + return stringsMethod[e] +} + +// Request represents the record "fermyon:spin/http-types#request". +// +// record request { +// method: method, +// uri: uri, +// headers: headers, +// params: params, +// body: option, +// } +type Request struct { + Method Method + URI URI + Headers Headers + Params Params + Body cm.Option[Body] +} + +// Response represents the record "fermyon:spin/http-types#response". +// +// record response { +// status: http-status, +// headers: option, +// body: option, +// } +type Response struct { + Status HTTPStatus + Headers cm.Option[Headers] + Body cm.Option[Body] +} + +// HTTPError represents the enum "fermyon:spin/http-types#http-error". +// +// enum http-error { +// success, +// destination-not-allowed, +// invalid-url, +// request-error, +// runtime-error, +// too-many-requests +// } +type HTTPError uint8 + +const ( + HTTPErrorSuccess HTTPError = iota + HTTPErrorDestinationNotAllowed + HTTPErrorInvalidURL + HTTPErrorRequestError + HTTPErrorRuntimeError + HTTPErrorTooManyRequests +) + +var stringsHTTPError = [6]string{ + "success", + "destination-not-allowed", + "invalid-url", + "request-error", + "runtime-error", + "too-many-requests", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e HTTPError) String() string { + return stringsHTTPError[e] +} diff --git a/v2/internal/fermyon/spin/http/abi.go b/v2/internal/fermyon/spin/http/abi.go new file mode 100644 index 0000000..896811c --- /dev/null +++ b/v2/internal/fermyon/spin/http/abi.go @@ -0,0 +1,34 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package http + +import ( + httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// ResponseShape is used for storage in variant or result types. +type ResponseShape struct { + shape [unsafe.Sizeof(httptypes.Response{})]byte +} + +func lower_OptionBody(v cm.Option[httptypes.Body]) (f0 uint32, f1 *uint8, f2 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2 := cm.LowerList(*some) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_Request(v httptypes.Request) (f0 uint32, f1 *uint8, f2 uint32, f3 *[2]string, f4 uint32, f5 *[2]string, f6 uint32, f7 uint32, f8 *uint8, f9 uint32) { + f0 = (uint32)(v.Method) + f1, f2 = cm.LowerString(v.URI) + f3, f4 = cm.LowerList(v.Headers) + f5, f6 = cm.LowerList(v.Params) + f7, f8, f9 = lower_OptionBody(v.Body) + return +} diff --git a/v2/internal/fermyon/spin/http/empty.s b/v2/internal/fermyon/spin/http/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/http/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/http/http.wit.go b/v2/internal/fermyon/spin/http/http.wit.go new file mode 100644 index 0000000..46da5bd --- /dev/null +++ b/v2/internal/fermyon/spin/http/http.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package http represents the imported interface "fermyon:spin/http". +package http + +import ( + httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// SendRequest represents the imported function "send-request". +// +// send-request: func(req: request) -> result +// +//go:nosplit +func SendRequest(req httptypes.Request) (result cm.Result[ResponseShape, httptypes.Response, httptypes.HTTPError]) { + req0, req1, req2, req3, req4, req5, req6, req7, req8, req9 := lower_Request(req) + wasmimport_SendRequest((uint32)(req0), (*uint8)(req1), (uint32)(req2), (*[2]string)(req3), (uint32)(req4), (*[2]string)(req5), (uint32)(req6), (uint32)(req7), (*uint8)(req8), (uint32)(req9), &result) + return +} + +//go:wasmimport fermyon:spin/http send-request +//go:noescape +func wasmimport_SendRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32, result *cm.Result[ResponseShape, httptypes.Response, httptypes.HTTPError]) diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v2/internal/fermyon/spin/inbound-http/abi.go new file mode 100644 index 0000000..ecd701e --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/abi.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package inboundhttp + +import ( + httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +func lift_OptionBody(f0 uint32, f1 *uint8, f2 uint32) (v cm.Option[httptypes.Body]) { + if f0 == 0 { + return + } + return cm.Some[httptypes.Body](cm.LiftList[httptypes.Body]((*uint8)(f1), (uint32)(f2))) +} + +func lift_Request(f0 uint32, f1 *uint8, f2 uint32, f3 *[2]string, f4 uint32, f5 *[2]string, f6 uint32, f7 uint32, f8 *uint8, f9 uint32) (v httptypes.Request) { + v.Method = (httptypes.Method)(f0) + v.URI = cm.LiftString[httptypes.URI](f1, f2) + v.Headers = cm.LiftList[httptypes.Headers](f3, f4) + v.Params = cm.LiftList[httptypes.Params](f5, f6) + v.Body = lift_OptionBody(f7, f8, f9) + return +} diff --git a/v2/internal/fermyon/spin/inbound-http/empty.s b/v2/internal/fermyon/spin/inbound-http/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go new file mode 100644 index 0000000..57e5644 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go @@ -0,0 +1,15 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package inboundhttp + +import ( + httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" +) + +// Exports represents the caller-defined exports from "fermyon:spin/inbound-http". +var Exports struct { + // HandleRequest represents the caller-defined, exported function "handle-request". + // + // handle-request: func(req: request) -> response + HandleRequest func(req httptypes.Request) (result httptypes.Response) +} diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go new file mode 100644 index 0000000..2bd3a04 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package inboundhttp represents the exported interface "fermyon:spin/inbound-http". +package inboundhttp + +import ( + httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" +) + +//go:wasmexport fermyon:spin/inbound-http#handle-request +//export fermyon:spin/inbound-http#handle-request +func wasmexport_HandleRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32) (result *httptypes.Response) { + req := lift_Request((uint32)(req0), (*uint8)(req1), (uint32)(req2), (*[2]string)(req3), (uint32)(req4), (*[2]string)(req5), (uint32)(req6), (uint32)(req7), (*uint8)(req8), (uint32)(req9)) + result_ := Exports.HandleRequest(req) + result = &result_ + return +} diff --git a/v2/internal/fermyon/spin/key-value/abi.go b/v2/internal/fermyon/spin/key-value/abi.go new file mode 100644 index 0000000..0d1a032 --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} diff --git a/v2/internal/fermyon/spin/key-value/empty.s b/v2/internal/fermyon/spin/key-value/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/key-value/key-value.wit.go b/v2/internal/fermyon/spin/key-value/key-value.wit.go new file mode 100644 index 0000000..5dc38a4 --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/key-value.wit.go @@ -0,0 +1,264 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package keyvalue represents the imported interface "fermyon:spin/key-value". +package keyvalue + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Store represents the u32 "fermyon:spin/key-value#store". +// +// A handle to an open key-value store +// +// type store = u32 +type Store uint32 + +// Error represents the variant "fermyon:spin/key-value#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// store-table-full, +// no-such-store, +// access-denied, +// invalid-store, +// no-such-key, +// io(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorStoreTableFull returns a [Error] of case "store-table-full". +// +// Too many stores have been opened simultaneously. Closing one or more +// stores prior to retrying may address this. +func ErrorStoreTableFull() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// StoreTableFull returns true if [Error] represents the variant case "store-table-full". +func (self *Error) StoreTableFull() bool { + return self.Tag() == 0 +} + +// ErrorNoSuchStore returns a [Error] of case "no-such-store". +// +// The host does not recognize the store name requested. Defining and +// configuring a store with that name in a runtime configuration file +// may address this. +func ErrorNoSuchStore() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// NoSuchStore returns true if [Error] represents the variant case "no-such-store". +func (self *Error) NoSuchStore() bool { + return self.Tag() == 1 +} + +// ErrorAccessDenied returns a [Error] of case "access-denied". +// +// The requesting component does not have access to the specified store +// (which may or may not exist). +func ErrorAccessDenied() Error { + var data struct{} + return cm.New[Error](2, data) +} + +// AccessDenied returns true if [Error] represents the variant case "access-denied". +func (self *Error) AccessDenied() bool { + return self.Tag() == 2 +} + +// ErrorInvalidStore returns a [Error] of case "invalid-store". +// +// The store handle provided is not recognized, i.e. it was either never +// opened or has been closed. +func ErrorInvalidStore() Error { + var data struct{} + return cm.New[Error](3, data) +} + +// InvalidStore returns true if [Error] represents the variant case "invalid-store". +func (self *Error) InvalidStore() bool { + return self.Tag() == 3 +} + +// ErrorNoSuchKey returns a [Error] of case "no-such-key". +// +// No key-value tuple exists for the specified key in the specified +// store. +func ErrorNoSuchKey() Error { + var data struct{} + return cm.New[Error](4, data) +} + +// NoSuchKey returns true if [Error] represents the variant case "no-such-key". +func (self *Error) NoSuchKey() bool { + return self.Tag() == 4 +} + +// ErrorIO returns a [Error] of case "io". +// +// Some implementation-specific error has occurred (e.g. I/O) +func ErrorIO(data string) Error { + return cm.New[Error](5, data) +} + +// IO returns a non-nil *[string] if [Error] represents the variant case "io". +func (self *Error) IO() *string { + return cm.Case[string](self, 5) +} + +// Open represents the imported function "open". +// +// Open the store with the specified name. +// +// If `name` is "default", the default store is opened. Otherwise, +// `name` must refer to a store defined and configured in a runtime +// configuration file supplied with the application. +// +// `error::no-such-store` will be raised if the `name` is not recognized. +// +// open: func(name: string) -> result +// +//go:nosplit +func Open(name string) (result cm.Result[ErrorShape, Store, Error]) { + name0, name1 := cm.LowerString(name) + wasmimport_Open((*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value open +//go:noescape +func wasmimport_Open(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, Store, Error]) + +// Get represents the imported function "get". +// +// Get the value associated with the specified `key` from the specified +// `store`. +// +// `error::invalid-store` will be raised if `store` is not a valid handle +// to an open store, and `error::no-such-key` will be raised if there is no +// tuple for `key` in `store`. +// +// get: func(store: store, key: string) -> result, error> +// +//go:nosplit +func Get(store Store, key string) (result cm.Result[ErrorShape, cm.List[uint8], Error]) { + store0 := (uint32)(store) + key0, key1 := cm.LowerString(key) + wasmimport_Get((uint32)(store0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value get +//go:noescape +func wasmimport_Get(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[uint8], Error]) + +// Set represents the imported function "set". +// +// Set the `value` associated with the specified `key` in the specified +// `store`, overwriting any existing value. +// +// `error::invalid-store` will be raised if `store` is not a valid handle +// to an open store. +// +// set: func(store: store, key: string, value: list) -> result<_, error> +// +//go:nosplit +func Set(store Store, key string, value cm.List[uint8]) (result cm.Result[Error, struct{}, Error]) { + store0 := (uint32)(store) + key0, key1 := cm.LowerString(key) + value0, value1 := cm.LowerList(value) + wasmimport_Set((uint32)(store0), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value set +//go:noescape +func wasmimport_Set(store0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Delete represents the imported function "delete". +// +// Delete the tuple with the specified `key` from the specified `store`. +// +// `error::invalid-store` will be raised if `store` is not a valid handle +// to an open store. No error is raised if a tuple did not previously +// exist for `key`. +// +// delete: func(store: store, key: string) -> result<_, error> +// +//go:nosplit +func Delete(store Store, key string) (result cm.Result[Error, struct{}, Error]) { + store0 := (uint32)(store) + key0, key1 := cm.LowerString(key) + wasmimport_Delete((uint32)(store0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value delete +//go:noescape +func wasmimport_Delete(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Exists represents the imported function "exists". +// +// Return whether a tuple exists for the specified `key` in the specified +// `store`. +// +// `error::invalid-store` will be raised if `store` is not a valid handle +// to an open store. +// +// exists: func(store: store, key: string) -> result +// +//go:nosplit +func Exists(store Store, key string) (result cm.Result[ErrorShape, bool, Error]) { + store0 := (uint32)(store) + key0, key1 := cm.LowerString(key) + wasmimport_Exists((uint32)(store0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value exists +//go:noescape +func wasmimport_Exists(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) + +// GetKeys represents the imported function "get-keys". +// +// Return a list of all the keys in the specified `store`. +// +// `error::invalid-store` will be raised if `store` is not a valid handle +// to an open store. +// +// get-keys: func(store: store) -> result, error> +// +//go:nosplit +func GetKeys(store Store) (result cm.Result[ErrorShape, cm.List[string], Error]) { + store0 := (uint32)(store) + wasmimport_GetKeys((uint32)(store0), &result) + return +} + +//go:wasmimport fermyon:spin/key-value get-keys +//go:noescape +func wasmimport_GetKeys(store0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +// Close represents the imported function "close". +// +// Close the specified `store`. +// +// This has no effect if `store` is not a valid handle to an open store. +// +// close: func(store: store) +// +//go:nosplit +func Close(store Store) { + store0 := (uint32)(store) + wasmimport_Close((uint32)(store0)) + return +} + +//go:wasmimport fermyon:spin/key-value close +//go:noescape +func wasmimport_Close(store0 uint32) diff --git a/v2/internal/fermyon/spin/llm/abi.go b/v2/internal/fermyon/spin/llm/abi.go new file mode 100644 index 0000000..b75401b --- /dev/null +++ b/v2/internal/fermyon/spin/llm/abi.go @@ -0,0 +1,43 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// InferencingResultShape is used for storage in variant or result types. +type InferencingResultShape struct { + shape [unsafe.Sizeof(InferencingResult{})]byte +} + +func lower_InferencingParams(v InferencingParams) (f0 uint32, f1 float32, f2 uint32, f3 float32, f4 uint32, f5 float32) { + f0 = (uint32)(v.MaxTokens) + f1 = (float32)(v.RepeatPenalty) + f2 = (uint32)(v.RepeatPenaltyLastNTokenCount) + f3 = (float32)(v.Temperature) + f4 = (uint32)(v.TopK) + f5 = (float32)(v.TopP) + return +} + +func lower_OptionInferencingParams(v cm.Option[InferencingParams]) (f0 uint32, f1 uint32, f2 float32, f3 uint32, f4 float32, f5 uint32, f6 float32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5, v6 := lower_InferencingParams(*some) + f1 = (uint32)(v1) + f2 = (float32)(v2) + f3 = (uint32)(v3) + f4 = (float32)(v4) + f5 = (uint32)(v5) + f6 = (float32)(v6) + } + return +} + +// EmbeddingsResultShape is used for storage in variant or result types. +type EmbeddingsResultShape struct { + shape [unsafe.Sizeof(EmbeddingsResult{})]byte +} diff --git a/v2/internal/fermyon/spin/llm/empty.s b/v2/internal/fermyon/spin/llm/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/llm/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/llm/llm.wit.go b/v2/internal/fermyon/spin/llm/llm.wit.go new file mode 100644 index 0000000..929e5c3 --- /dev/null +++ b/v2/internal/fermyon/spin/llm/llm.wit.go @@ -0,0 +1,201 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package llm represents the imported interface "fermyon:spin/llm". +// +// A WASI interface dedicated to performing inferencing for Large Language Models. +package llm + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// InferencingModel represents the string "fermyon:spin/llm#inferencing-model". +// +// A Large Language Model. +// +// type inferencing-model = string +type InferencingModel string + +// InferencingParams represents the record "fermyon:spin/llm#inferencing-params". +// +// Inference request parameters +// +// record inferencing-params { +// max-tokens: u32, +// repeat-penalty: f32, +// repeat-penalty-last-n-token-count: u32, +// temperature: f32, +// top-k: u32, +// top-p: f32, +// } +type InferencingParams struct { + // The maximum tokens that should be inferred. + // + // Note: the backing implementation may return less tokens. + MaxTokens uint32 + + // The amount the model should avoid repeating tokens. + RepeatPenalty float32 + + // The number of tokens the model should apply the repeat penalty to. + RepeatPenaltyLastNTokenCount uint32 + + // The randomness with which the next token is selected. + Temperature float32 + + // The number of possible next tokens the model will choose from. + TopK uint32 + + // The probability total of next tokens the model will choose from. + TopP float32 +} + +// Error represents the variant "fermyon:spin/llm#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// model-not-supported, +// runtime-error(string), +// invalid-input(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorModelNotSupported returns a [Error] of case "model-not-supported". +func ErrorModelNotSupported() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// ModelNotSupported returns true if [Error] represents the variant case "model-not-supported". +func (self *Error) ModelNotSupported() bool { + return self.Tag() == 0 +} + +// ErrorRuntimeError returns a [Error] of case "runtime-error". +func ErrorRuntimeError(data string) Error { + return cm.New[Error](1, data) +} + +// RuntimeError returns a non-nil *[string] if [Error] represents the variant case "runtime-error". +func (self *Error) RuntimeError() *string { + return cm.Case[string](self, 1) +} + +// ErrorInvalidInput returns a [Error] of case "invalid-input". +func ErrorInvalidInput(data string) Error { + return cm.New[Error](2, data) +} + +// InvalidInput returns a non-nil *[string] if [Error] represents the variant case "invalid-input". +func (self *Error) InvalidInput() *string { + return cm.Case[string](self, 2) +} + +// InferencingUsage represents the record "fermyon:spin/llm#inferencing-usage". +// +// Usage information related to the inferencing result +// +// record inferencing-usage { +// prompt-token-count: u32, +// generated-token-count: u32, +// } +type InferencingUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 + + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 +} + +// InferencingResult represents the record "fermyon:spin/llm#inferencing-result". +// +// An inferencing result +// +// record inferencing-result { +// text: string, +// usage: inferencing-usage, +// } +type InferencingResult struct { + // The text generated by the model + // TODO: this should be a stream + Text string + + // Usage information about the inferencing request + Usage InferencingUsage +} + +// EmbeddingModel represents the string "fermyon:spin/llm#embedding-model". +// +// The model used for generating embeddings +// +// type embedding-model = string +type EmbeddingModel string + +// EmbeddingsUsage represents the record "fermyon:spin/llm#embeddings-usage". +// +// Usage related to an embeddings generation request +// +// record embeddings-usage { +// prompt-token-count: u32, +// } +type EmbeddingsUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 +} + +// EmbeddingsResult represents the record "fermyon:spin/llm#embeddings-result". +// +// Result of generating embeddings +// +// record embeddings-result { +// embeddings: list>, +// usage: embeddings-usage, +// } +type EmbeddingsResult struct { + // The embeddings generated by the request + Embeddings cm.List[cm.List[float32]] + + // Usage related to the embeddings generation request + Usage EmbeddingsUsage +} + +// Infer represents the imported function "infer". +// +// Perform inferencing using the provided model and prompt with the given optional +// params +// +// infer: func(model: inferencing-model, prompt: string, params: option) +// -> result +// +//go:nosplit +func Infer(model InferencingModel, prompt string, params cm.Option[InferencingParams]) (result cm.Result[InferencingResultShape, InferencingResult, Error]) { + model0, model1 := cm.LowerString(model) + prompt0, prompt1 := cm.LowerString(prompt) + params0, params1, params2, params3, params4, params5, params6 := lower_OptionInferencingParams(params) + wasmimport_Infer((*uint8)(model0), (uint32)(model1), (*uint8)(prompt0), (uint32)(prompt1), (uint32)(params0), (uint32)(params1), (float32)(params2), (uint32)(params3), (float32)(params4), (uint32)(params5), (float32)(params6), &result) + return +} + +//go:wasmimport fermyon:spin/llm infer +//go:noescape +func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) + +// GenerateEmbeddings represents the imported function "generate-embeddings". +// +// Generate embeddings for the supplied list of text +// +// generate-embeddings: func(model: embedding-model, text: list) -> result +// +//go:nosplit +func GenerateEmbeddings(model EmbeddingModel, text cm.List[string]) (result cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) { + model0, model1 := cm.LowerString(model) + text0, text1 := cm.LowerList(text) + wasmimport_GenerateEmbeddings((*uint8)(model0), (uint32)(model1), (*string)(text0), (uint32)(text1), &result) + return +} + +//go:wasmimport fermyon:spin/llm generate-embeddings +//go:noescape +func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/mysql/abi.go b/v2/internal/fermyon/spin/mysql/abi.go new file mode 100644 index 0000000..41d4103 --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mysql + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + "unsafe" +) + +// RowSetShape is used for storage in variant or result types. +type RowSetShape struct { + shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte +} + +// MysqlErrorShape is used for storage in variant or result types. +type MysqlErrorShape struct { + shape [unsafe.Sizeof(MysqlError{})]byte +} diff --git a/v2/internal/fermyon/spin/mysql/empty.s b/v2/internal/fermyon/spin/mysql/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/mysql/mysql.wit.go b/v2/internal/fermyon/spin/mysql/mysql.wit.go new file mode 100644 index 0000000..569fbee --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/mysql.wit.go @@ -0,0 +1,124 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package mysql represents the imported interface "fermyon:spin/mysql". +package mysql + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// MysqlError represents the variant "fermyon:spin/mysql#mysql-error". +// +// General purpose error. +// +// variant mysql-error { +// success, +// connection-failed(string), +// bad-parameter(string), +// query-failed(string), +// value-conversion-failed(string), +// other-error(string), +// } +type MysqlError cm.Variant[uint8, string, string] + +// MysqlErrorSuccess returns a [MysqlError] of case "success". +func MysqlErrorSuccess() MysqlError { + var data struct{} + return cm.New[MysqlError](0, data) +} + +// Success returns true if [MysqlError] represents the variant case "success". +func (self *MysqlError) Success() bool { + return self.Tag() == 0 +} + +// MysqlErrorConnectionFailed returns a [MysqlError] of case "connection-failed". +func MysqlErrorConnectionFailed(data string) MysqlError { + return cm.New[MysqlError](1, data) +} + +// ConnectionFailed returns a non-nil *[string] if [MysqlError] represents the variant case "connection-failed". +func (self *MysqlError) ConnectionFailed() *string { + return cm.Case[string](self, 1) +} + +// MysqlErrorBadParameter returns a [MysqlError] of case "bad-parameter". +func MysqlErrorBadParameter(data string) MysqlError { + return cm.New[MysqlError](2, data) +} + +// BadParameter returns a non-nil *[string] if [MysqlError] represents the variant case "bad-parameter". +func (self *MysqlError) BadParameter() *string { + return cm.Case[string](self, 2) +} + +// MysqlErrorQueryFailed returns a [MysqlError] of case "query-failed". +func MysqlErrorQueryFailed(data string) MysqlError { + return cm.New[MysqlError](3, data) +} + +// QueryFailed returns a non-nil *[string] if [MysqlError] represents the variant case "query-failed". +func (self *MysqlError) QueryFailed() *string { + return cm.Case[string](self, 3) +} + +// MysqlErrorValueConversionFailed returns a [MysqlError] of case "value-conversion-failed". +func MysqlErrorValueConversionFailed(data string) MysqlError { + return cm.New[MysqlError](4, data) +} + +// ValueConversionFailed returns a non-nil *[string] if [MysqlError] represents the variant case "value-conversion-failed". +func (self *MysqlError) ValueConversionFailed() *string { + return cm.Case[string](self, 4) +} + +// MysqlErrorOtherError returns a [MysqlError] of case "other-error". +func MysqlErrorOtherError(data string) MysqlError { + return cm.New[MysqlError](5, data) +} + +// OtherError returns a non-nil *[string] if [MysqlError] represents the variant case "other-error". +func (self *MysqlError) OtherError() *string { + return cm.Case[string](self, 5) +} + +// Query represents the imported function "query". +// +// query the database: select +// +// query: func(address: string, statement: string, params: list) +// -> result +// +//go:nosplit +func Query(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, MysqlError]) { + address0, address1 := cm.LowerString(address) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/mysql query +//go:noescape +func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, MysqlError]) + +// Execute represents the imported function "execute". +// +// execute command to the database: insert, update, delete +// +// execute: func(address: string, statement: string, params: list) +// -> result<_, mysql-error> +// +//go:nosplit +func Execute(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[MysqlError, struct{}, MysqlError]) { + address0, address1 := cm.LowerString(address) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/mysql execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[MysqlError, struct{}, MysqlError]) diff --git a/v2/internal/fermyon/spin/postgres/abi.go b/v2/internal/fermyon/spin/postgres/abi.go new file mode 100644 index 0000000..d1e2280 --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + "unsafe" +) + +// RowSetShape is used for storage in variant or result types. +type RowSetShape struct { + shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte +} + +// PgErrorShape is used for storage in variant or result types. +type PgErrorShape struct { + shape [unsafe.Sizeof(PgError{})]byte +} diff --git a/v2/internal/fermyon/spin/postgres/empty.s b/v2/internal/fermyon/spin/postgres/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/postgres/postgres.wit.go b/v2/internal/fermyon/spin/postgres/postgres.wit.go new file mode 100644 index 0000000..9f4c59a --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/postgres.wit.go @@ -0,0 +1,124 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package postgres represents the imported interface "fermyon:spin/postgres". +package postgres + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// PgError represents the variant "fermyon:spin/postgres#pg-error". +// +// General purpose error. +// +// variant pg-error { +// success, +// connection-failed(string), +// bad-parameter(string), +// query-failed(string), +// value-conversion-failed(string), +// other-error(string), +// } +type PgError cm.Variant[uint8, string, string] + +// PgErrorSuccess returns a [PgError] of case "success". +func PgErrorSuccess() PgError { + var data struct{} + return cm.New[PgError](0, data) +} + +// Success returns true if [PgError] represents the variant case "success". +func (self *PgError) Success() bool { + return self.Tag() == 0 +} + +// PgErrorConnectionFailed returns a [PgError] of case "connection-failed". +func PgErrorConnectionFailed(data string) PgError { + return cm.New[PgError](1, data) +} + +// ConnectionFailed returns a non-nil *[string] if [PgError] represents the variant case "connection-failed". +func (self *PgError) ConnectionFailed() *string { + return cm.Case[string](self, 1) +} + +// PgErrorBadParameter returns a [PgError] of case "bad-parameter". +func PgErrorBadParameter(data string) PgError { + return cm.New[PgError](2, data) +} + +// BadParameter returns a non-nil *[string] if [PgError] represents the variant case "bad-parameter". +func (self *PgError) BadParameter() *string { + return cm.Case[string](self, 2) +} + +// PgErrorQueryFailed returns a [PgError] of case "query-failed". +func PgErrorQueryFailed(data string) PgError { + return cm.New[PgError](3, data) +} + +// QueryFailed returns a non-nil *[string] if [PgError] represents the variant case "query-failed". +func (self *PgError) QueryFailed() *string { + return cm.Case[string](self, 3) +} + +// PgErrorValueConversionFailed returns a [PgError] of case "value-conversion-failed". +func PgErrorValueConversionFailed(data string) PgError { + return cm.New[PgError](4, data) +} + +// ValueConversionFailed returns a non-nil *[string] if [PgError] represents the variant case "value-conversion-failed". +func (self *PgError) ValueConversionFailed() *string { + return cm.Case[string](self, 4) +} + +// PgErrorOtherError returns a [PgError] of case "other-error". +func PgErrorOtherError(data string) PgError { + return cm.New[PgError](5, data) +} + +// OtherError returns a non-nil *[string] if [PgError] represents the variant case "other-error". +func (self *PgError) OtherError() *string { + return cm.Case[string](self, 5) +} + +// Query represents the imported function "query". +// +// query the database: select +// +// query: func(address: string, statement: string, params: list) +// -> result +// +//go:nosplit +func Query(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, PgError]) { + address0, address1 := cm.LowerString(address) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/postgres query +//go:noescape +func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, PgError]) + +// Execute represents the imported function "execute". +// +// execute command to the database: insert, update, delete +// +// execute: func(address: string, statement: string, params: list) +// -> result +// +//go:nosplit +func Execute(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[PgErrorShape, uint64, PgError]) { + address0, address1 := cm.LowerString(address) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/postgres execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[PgErrorShape, uint64, PgError]) diff --git a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go new file mode 100644 index 0000000..bdfb8da --- /dev/null +++ b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go @@ -0,0 +1,428 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package rdbmstypes represents the imported interface "fermyon:spin/rdbms-types". +package rdbmstypes + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// DbDataType represents the enum "fermyon:spin/rdbms-types#db-data-type". +// +// enum db-data-type { +// boolean, +// int8, +// int16, +// int32, +// int64, +// uint8, +// uint16, +// uint32, +// uint64, +// floating32, +// floating64, +// str, +// binary, +// other +// } +type DbDataType uint8 + +const ( + DbDataTypeBoolean DbDataType = iota + DbDataTypeInt8 + DbDataTypeInt16 + DbDataTypeInt32 + DbDataTypeInt64 + DbDataTypeUint8 + DbDataTypeUint16 + DbDataTypeUint32 + DbDataTypeUint64 + DbDataTypeFloating32 + DbDataTypeFloating64 + DbDataTypeStr + DbDataTypeBinary + DbDataTypeOther +) + +var stringsDbDataType = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "other", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e DbDataType) String() string { + return stringsDbDataType[e] +} + +// DbValue represents the variant "fermyon:spin/rdbms-types#db-value". +// +// variant db-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// uint8(u8), +// uint16(u16), +// uint32(u32), +// uint64(u64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// db-null, +// unsupported, +// } +type DbValue cm.Variant[uint8, string, int64] + +// DbValueBoolean returns a [DbValue] of case "boolean". +func DbValueBoolean(data bool) DbValue { + return cm.New[DbValue](0, data) +} + +// Boolean returns a non-nil *[bool] if [DbValue] represents the variant case "boolean". +func (self *DbValue) Boolean() *bool { + return cm.Case[bool](self, 0) +} + +// DbValueInt8 returns a [DbValue] of case "int8". +func DbValueInt8(data int8) DbValue { + return cm.New[DbValue](1, data) +} + +// Int8 returns a non-nil *[int8] if [DbValue] represents the variant case "int8". +func (self *DbValue) Int8() *int8 { + return cm.Case[int8](self, 1) +} + +// DbValueInt16 returns a [DbValue] of case "int16". +func DbValueInt16(data int16) DbValue { + return cm.New[DbValue](2, data) +} + +// Int16 returns a non-nil *[int16] if [DbValue] represents the variant case "int16". +func (self *DbValue) Int16() *int16 { + return cm.Case[int16](self, 2) +} + +// DbValueInt32 returns a [DbValue] of case "int32". +func DbValueInt32(data int32) DbValue { + return cm.New[DbValue](3, data) +} + +// Int32 returns a non-nil *[int32] if [DbValue] represents the variant case "int32". +func (self *DbValue) Int32() *int32 { + return cm.Case[int32](self, 3) +} + +// DbValueInt64 returns a [DbValue] of case "int64". +func DbValueInt64(data int64) DbValue { + return cm.New[DbValue](4, data) +} + +// Int64 returns a non-nil *[int64] if [DbValue] represents the variant case "int64". +func (self *DbValue) Int64() *int64 { + return cm.Case[int64](self, 4) +} + +// DbValueUint8 returns a [DbValue] of case "uint8". +func DbValueUint8(data uint8) DbValue { + return cm.New[DbValue](5, data) +} + +// Uint8 returns a non-nil *[uint8] if [DbValue] represents the variant case "uint8". +func (self *DbValue) Uint8() *uint8 { + return cm.Case[uint8](self, 5) +} + +// DbValueUint16 returns a [DbValue] of case "uint16". +func DbValueUint16(data uint16) DbValue { + return cm.New[DbValue](6, data) +} + +// Uint16 returns a non-nil *[uint16] if [DbValue] represents the variant case "uint16". +func (self *DbValue) Uint16() *uint16 { + return cm.Case[uint16](self, 6) +} + +// DbValueUint32 returns a [DbValue] of case "uint32". +func DbValueUint32(data uint32) DbValue { + return cm.New[DbValue](7, data) +} + +// Uint32 returns a non-nil *[uint32] if [DbValue] represents the variant case "uint32". +func (self *DbValue) Uint32() *uint32 { + return cm.Case[uint32](self, 7) +} + +// DbValueUint64 returns a [DbValue] of case "uint64". +func DbValueUint64(data uint64) DbValue { + return cm.New[DbValue](8, data) +} + +// Uint64 returns a non-nil *[uint64] if [DbValue] represents the variant case "uint64". +func (self *DbValue) Uint64() *uint64 { + return cm.Case[uint64](self, 8) +} + +// DbValueFloating32 returns a [DbValue] of case "floating32". +func DbValueFloating32(data float32) DbValue { + return cm.New[DbValue](9, data) +} + +// Floating32 returns a non-nil *[float32] if [DbValue] represents the variant case "floating32". +func (self *DbValue) Floating32() *float32 { + return cm.Case[float32](self, 9) +} + +// DbValueFloating64 returns a [DbValue] of case "floating64". +func DbValueFloating64(data float64) DbValue { + return cm.New[DbValue](10, data) +} + +// Floating64 returns a non-nil *[float64] if [DbValue] represents the variant case "floating64". +func (self *DbValue) Floating64() *float64 { + return cm.Case[float64](self, 10) +} + +// DbValueStr returns a [DbValue] of case "str". +func DbValueStr(data string) DbValue { + return cm.New[DbValue](11, data) +} + +// Str returns a non-nil *[string] if [DbValue] represents the variant case "str". +func (self *DbValue) Str() *string { + return cm.Case[string](self, 11) +} + +// DbValueBinary returns a [DbValue] of case "binary". +func DbValueBinary(data cm.List[uint8]) DbValue { + return cm.New[DbValue](12, data) +} + +// Binary returns a non-nil *[cm.List[uint8]] if [DbValue] represents the variant case "binary". +func (self *DbValue) Binary() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 12) +} + +// DbValueDbNull returns a [DbValue] of case "db-null". +func DbValueDbNull() DbValue { + var data struct{} + return cm.New[DbValue](13, data) +} + +// DbNull returns true if [DbValue] represents the variant case "db-null". +func (self *DbValue) DbNull() bool { + return self.Tag() == 13 +} + +// DbValueUnsupported returns a [DbValue] of case "unsupported". +func DbValueUnsupported() DbValue { + var data struct{} + return cm.New[DbValue](14, data) +} + +// Unsupported returns true if [DbValue] represents the variant case "unsupported". +func (self *DbValue) Unsupported() bool { + return self.Tag() == 14 +} + +// ParameterValue represents the variant "fermyon:spin/rdbms-types#parameter-value". +// +// variant parameter-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// uint8(u8), +// uint16(u16), +// uint32(u32), +// uint64(u64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// db-null, +// } +type ParameterValue cm.Variant[uint8, string, int64] + +// ParameterValueBoolean returns a [ParameterValue] of case "boolean". +func ParameterValueBoolean(data bool) ParameterValue { + return cm.New[ParameterValue](0, data) +} + +// Boolean returns a non-nil *[bool] if [ParameterValue] represents the variant case "boolean". +func (self *ParameterValue) Boolean() *bool { + return cm.Case[bool](self, 0) +} + +// ParameterValueInt8 returns a [ParameterValue] of case "int8". +func ParameterValueInt8(data int8) ParameterValue { + return cm.New[ParameterValue](1, data) +} + +// Int8 returns a non-nil *[int8] if [ParameterValue] represents the variant case "int8". +func (self *ParameterValue) Int8() *int8 { + return cm.Case[int8](self, 1) +} + +// ParameterValueInt16 returns a [ParameterValue] of case "int16". +func ParameterValueInt16(data int16) ParameterValue { + return cm.New[ParameterValue](2, data) +} + +// Int16 returns a non-nil *[int16] if [ParameterValue] represents the variant case "int16". +func (self *ParameterValue) Int16() *int16 { + return cm.Case[int16](self, 2) +} + +// ParameterValueInt32 returns a [ParameterValue] of case "int32". +func ParameterValueInt32(data int32) ParameterValue { + return cm.New[ParameterValue](3, data) +} + +// Int32 returns a non-nil *[int32] if [ParameterValue] represents the variant case "int32". +func (self *ParameterValue) Int32() *int32 { + return cm.Case[int32](self, 3) +} + +// ParameterValueInt64 returns a [ParameterValue] of case "int64". +func ParameterValueInt64(data int64) ParameterValue { + return cm.New[ParameterValue](4, data) +} + +// Int64 returns a non-nil *[int64] if [ParameterValue] represents the variant case "int64". +func (self *ParameterValue) Int64() *int64 { + return cm.Case[int64](self, 4) +} + +// ParameterValueUint8 returns a [ParameterValue] of case "uint8". +func ParameterValueUint8(data uint8) ParameterValue { + return cm.New[ParameterValue](5, data) +} + +// Uint8 returns a non-nil *[uint8] if [ParameterValue] represents the variant case "uint8". +func (self *ParameterValue) Uint8() *uint8 { + return cm.Case[uint8](self, 5) +} + +// ParameterValueUint16 returns a [ParameterValue] of case "uint16". +func ParameterValueUint16(data uint16) ParameterValue { + return cm.New[ParameterValue](6, data) +} + +// Uint16 returns a non-nil *[uint16] if [ParameterValue] represents the variant case "uint16". +func (self *ParameterValue) Uint16() *uint16 { + return cm.Case[uint16](self, 6) +} + +// ParameterValueUint32 returns a [ParameterValue] of case "uint32". +func ParameterValueUint32(data uint32) ParameterValue { + return cm.New[ParameterValue](7, data) +} + +// Uint32 returns a non-nil *[uint32] if [ParameterValue] represents the variant case "uint32". +func (self *ParameterValue) Uint32() *uint32 { + return cm.Case[uint32](self, 7) +} + +// ParameterValueUint64 returns a [ParameterValue] of case "uint64". +func ParameterValueUint64(data uint64) ParameterValue { + return cm.New[ParameterValue](8, data) +} + +// Uint64 returns a non-nil *[uint64] if [ParameterValue] represents the variant case "uint64". +func (self *ParameterValue) Uint64() *uint64 { + return cm.Case[uint64](self, 8) +} + +// ParameterValueFloating32 returns a [ParameterValue] of case "floating32". +func ParameterValueFloating32(data float32) ParameterValue { + return cm.New[ParameterValue](9, data) +} + +// Floating32 returns a non-nil *[float32] if [ParameterValue] represents the variant case "floating32". +func (self *ParameterValue) Floating32() *float32 { + return cm.Case[float32](self, 9) +} + +// ParameterValueFloating64 returns a [ParameterValue] of case "floating64". +func ParameterValueFloating64(data float64) ParameterValue { + return cm.New[ParameterValue](10, data) +} + +// Floating64 returns a non-nil *[float64] if [ParameterValue] represents the variant case "floating64". +func (self *ParameterValue) Floating64() *float64 { + return cm.Case[float64](self, 10) +} + +// ParameterValueStr returns a [ParameterValue] of case "str". +func ParameterValueStr(data string) ParameterValue { + return cm.New[ParameterValue](11, data) +} + +// Str returns a non-nil *[string] if [ParameterValue] represents the variant case "str". +func (self *ParameterValue) Str() *string { + return cm.Case[string](self, 11) +} + +// ParameterValueBinary returns a [ParameterValue] of case "binary". +func ParameterValueBinary(data cm.List[uint8]) ParameterValue { + return cm.New[ParameterValue](12, data) +} + +// Binary returns a non-nil *[cm.List[uint8]] if [ParameterValue] represents the variant case "binary". +func (self *ParameterValue) Binary() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 12) +} + +// ParameterValueDbNull returns a [ParameterValue] of case "db-null". +func ParameterValueDbNull() ParameterValue { + var data struct{} + return cm.New[ParameterValue](13, data) +} + +// DbNull returns true if [ParameterValue] represents the variant case "db-null". +func (self *ParameterValue) DbNull() bool { + return self.Tag() == 13 +} + +// Column represents the record "fermyon:spin/rdbms-types#column". +// +// record column { +// name: string, +// data-type: db-data-type, +// } +type Column struct { + Name string + DataType DbDataType +} + +// Row represents the list "fermyon:spin/rdbms-types#row". +// +// type row = list +type Row cm.List[DbValue] + +// RowSet represents the record "fermyon:spin/rdbms-types#row-set". +// +// record row-set { +// columns: list, +// rows: list, +// } +type RowSet struct { + Columns cm.List[Column] + Rows cm.List[Row] +} diff --git a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go new file mode 100644 index 0000000..f6e4dcd --- /dev/null +++ b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go @@ -0,0 +1,123 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package redistypes represents the imported interface "fermyon:spin/redis-types". +package redistypes + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the enum "fermyon:spin/redis-types#error". +// +// General purpose error. +// +// enum error { +// success, +// error +// } +type Error uint8 + +const ( + ErrorSuccess Error = iota + ErrorError +) + +var stringsError = [2]string{ + "success", + "error", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Error) String() string { + return stringsError[e] +} + +// Payload represents the list "fermyon:spin/redis-types#payload". +// +// The message payload. +// +// type payload = list +type Payload cm.List[uint8] + +// RedisParameter represents the variant "fermyon:spin/redis-types#redis-parameter". +// +// A parameter type for the general-purpose `execute` function. +// +// variant redis-parameter { +// int64(s64), +// binary(payload), +// } +type RedisParameter cm.Variant[uint8, Payload, int64] + +// RedisParameterInt64 returns a [RedisParameter] of case "int64". +func RedisParameterInt64(data int64) RedisParameter { + return cm.New[RedisParameter](0, data) +} + +// Int64 returns a non-nil *[int64] if [RedisParameter] represents the variant case "int64". +func (self *RedisParameter) Int64() *int64 { + return cm.Case[int64](self, 0) +} + +// RedisParameterBinary returns a [RedisParameter] of case "binary". +func RedisParameterBinary(data Payload) RedisParameter { + return cm.New[RedisParameter](1, data) +} + +// Binary returns a non-nil *[Payload] if [RedisParameter] represents the variant case "binary". +func (self *RedisParameter) Binary() *Payload { + return cm.Case[Payload](self, 1) +} + +// RedisResult represents the variant "fermyon:spin/redis-types#redis-result". +// +// A return type for the general-purpose `execute` function. +// +// variant redis-result { +// nil, +// status(string), +// int64(s64), +// binary(payload), +// } +type RedisResult cm.Variant[uint8, string, int64] + +// RedisResultNil returns a [RedisResult] of case "nil". +func RedisResultNil() RedisResult { + var data struct{} + return cm.New[RedisResult](0, data) +} + +// Nil returns true if [RedisResult] represents the variant case "nil". +func (self *RedisResult) Nil() bool { + return self.Tag() == 0 +} + +// RedisResultStatus returns a [RedisResult] of case "status". +func RedisResultStatus(data string) RedisResult { + return cm.New[RedisResult](1, data) +} + +// Status returns a non-nil *[string] if [RedisResult] represents the variant case "status". +func (self *RedisResult) Status() *string { + return cm.Case[string](self, 1) +} + +// RedisResultInt64 returns a [RedisResult] of case "int64". +func RedisResultInt64(data int64) RedisResult { + return cm.New[RedisResult](2, data) +} + +// Int64 returns a non-nil *[int64] if [RedisResult] represents the variant case "int64". +func (self *RedisResult) Int64() *int64 { + return cm.Case[int64](self, 2) +} + +// RedisResultBinary returns a [RedisResult] of case "binary". +func RedisResultBinary(data Payload) RedisResult { + return cm.New[RedisResult](3, data) +} + +// Binary returns a non-nil *[Payload] if [RedisResult] represents the variant case "binary". +func (self *RedisResult) Binary() *Payload { + return cm.Case[Payload](self, 3) +} diff --git a/v2/internal/fermyon/spin/redis/empty.s b/v2/internal/fermyon/spin/redis/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/redis/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/redis/redis.wit.go b/v2/internal/fermyon/spin/redis/redis.wit.go new file mode 100644 index 0000000..5500293 --- /dev/null +++ b/v2/internal/fermyon/spin/redis/redis.wit.go @@ -0,0 +1,183 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package redis represents the imported interface "fermyon:spin/redis". +package redis + +import ( + redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Publish represents the imported function "publish". +// +// Publish a Redis message to the specificed channel and return an error, if any. +// +// publish: func(address: string, channel: string, payload: payload) -> result<_, +// error> +// +//go:nosplit +func Publish(address string, channel string, payload redistypes.Payload) (result cm.Result[redistypes.Error, struct{}, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + channel0, channel1 := cm.LowerString(channel) + payload0, payload1 := cm.LowerList(payload) + wasmimport_Publish((*uint8)(address0), (uint32)(address1), (*uint8)(channel0), (uint32)(channel1), (*uint8)(payload0), (uint32)(payload1), &result) + return +} + +//go:wasmimport fermyon:spin/redis publish +//go:noescape +func wasmimport_Publish(address0 *uint8, address1 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[redistypes.Error, struct{}, redistypes.Error]) + +// Get represents the imported function "get". +// +// Get the value of a key. +// +// get: func(address: string, key: string) -> result +// +//go:nosplit +func Get(address string, key string) (result cm.Result[redistypes.Payload, redistypes.Payload, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Get((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis get +//go:noescape +func wasmimport_Get(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[redistypes.Payload, redistypes.Payload, redistypes.Error]) + +// Set represents the imported function "set". +// +// Set key to value. If key alreads holds a value, it is overwritten. +// +// set: func(address: string, key: string, value: payload) -> result<_, error> +// +//go:nosplit +func Set(address string, key string, value redistypes.Payload) (result cm.Result[redistypes.Error, struct{}, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + value0, value1 := cm.LowerList(value) + wasmimport_Set((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport fermyon:spin/redis set +//go:noescape +func wasmimport_Set(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[redistypes.Error, struct{}, redistypes.Error]) + +// Incr represents the imported function "incr". +// +// Increments the number stored at key by one. If the key does not exist, it is set +// to 0 before performing the operation. +// An error is returned if the key contains a value of the wrong type or contains +// a string that can not be represented as integer. +// +// incr: func(address: string, key: string) -> result +// +//go:nosplit +func Incr(address string, key string) (result cm.Result[int64, int64, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Incr((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis incr +//go:noescape +func wasmimport_Incr(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[int64, int64, redistypes.Error]) + +// Del represents the imported function "del". +// +// Removes the specified keys. A key is ignored if it does not exist. +// +// del: func(address: string, keys: list) -> result +// +//go:nosplit +func Del(address string, keys cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + keys0, keys1 := cm.LowerList(keys) + wasmimport_Del((*uint8)(address0), (uint32)(address1), (*string)(keys0), (uint32)(keys1), &result) + return +} + +//go:wasmimport fermyon:spin/redis del +//go:noescape +func wasmimport_Del(address0 *uint8, address1 uint32, keys0 *string, keys1 uint32, result *cm.Result[int64, int64, redistypes.Error]) + +// Sadd represents the imported function "sadd". +// +// Add the specified `values` to the set named `key`, returning the number of newly-added +// values. +// +// sadd: func(address: string, key: string, values: list) -> result +// +//go:nosplit +func Sadd(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + values0, values1 := cm.LowerList(values) + wasmimport_Sadd((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), (*string)(values0), (uint32)(values1), &result) + return +} + +//go:wasmimport fermyon:spin/redis sadd +//go:noescape +func wasmimport_Sadd(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, redistypes.Error]) + +// Smembers represents the imported function "smembers". +// +// Retrieve the contents of the set named `key`. +// +// smembers: func(address: string, key: string) -> result, error> +// +//go:nosplit +func Smembers(address string, key string) (result cm.Result[cm.List[string], cm.List[string], redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Smembers((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis smembers +//go:noescape +func wasmimport_Smembers(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[cm.List[string], cm.List[string], redistypes.Error]) + +// Srem represents the imported function "srem". +// +// Remove the specified `values` from the set named `key`, returning the number of +// newly-removed values. +// +// srem: func(address: string, key: string, values: list) -> result +// +//go:nosplit +func Srem(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + values0, values1 := cm.LowerList(values) + wasmimport_Srem((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), (*string)(values0), (uint32)(values1), &result) + return +} + +//go:wasmimport fermyon:spin/redis srem +//go:noescape +func wasmimport_Srem(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, redistypes.Error]) + +// Execute represents the imported function "execute". +// +// Execute an arbitrary Redis command and receive the result. +// +// execute: func(address: string, command: string, arguments: list) +// -> result, error> +// +//go:nosplit +func Execute(address string, command string, arguments cm.List[redistypes.RedisParameter]) (result cm.Result[cm.List[redistypes.RedisResult], cm.List[redistypes.RedisResult], redistypes.Error]) { + address0, address1 := cm.LowerString(address) + command0, command1 := cm.LowerString(command) + arguments0, arguments1 := cm.LowerList(arguments) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(command0), (uint32)(command1), (*redistypes.RedisParameter)(arguments0), (uint32)(arguments1), &result) + return +} + +//go:wasmimport fermyon:spin/redis execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, command0 *uint8, command1 uint32, arguments0 *redistypes.RedisParameter, arguments1 uint32, result *cm.Result[cm.List[redistypes.RedisResult], cm.List[redistypes.RedisResult], redistypes.Error]) diff --git a/v2/internal/fermyon/spin/sqlite/abi.go b/v2/internal/fermyon/spin/sqlite/abi.go new file mode 100644 index 0000000..a16610a --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/abi.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} + +// QueryResultShape is used for storage in variant or result types. +type QueryResultShape struct { + shape [unsafe.Sizeof(QueryResult{})]byte +} diff --git a/v2/internal/fermyon/spin/sqlite/empty.s b/v2/internal/fermyon/spin/sqlite/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go new file mode 100644 index 0000000..5a895cd --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go @@ -0,0 +1,240 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package sqlite represents the imported interface "fermyon:spin/sqlite". +package sqlite + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Connection represents the u32 "fermyon:spin/sqlite#connection". +// +// A handle to an open sqlite instance +// +// type connection = u32 +type Connection uint32 + +// Error represents the variant "fermyon:spin/sqlite#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// no-such-database, +// access-denied, +// invalid-connection, +// database-full, +// io(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorNoSuchDatabase returns a [Error] of case "no-such-database". +// +// The host does not recognize the database name requested. +func ErrorNoSuchDatabase() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// NoSuchDatabase returns true if [Error] represents the variant case "no-such-database". +func (self *Error) NoSuchDatabase() bool { + return self.Tag() == 0 +} + +// ErrorAccessDenied returns a [Error] of case "access-denied". +// +// The requesting component does not have access to the specified database (which +// may or may not exist). +func ErrorAccessDenied() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// AccessDenied returns true if [Error] represents the variant case "access-denied". +func (self *Error) AccessDenied() bool { + return self.Tag() == 1 +} + +// ErrorInvalidConnection returns a [Error] of case "invalid-connection". +// +// The provided connection is not valid +func ErrorInvalidConnection() Error { + var data struct{} + return cm.New[Error](2, data) +} + +// InvalidConnection returns true if [Error] represents the variant case "invalid-connection". +func (self *Error) InvalidConnection() bool { + return self.Tag() == 2 +} + +// ErrorDatabaseFull returns a [Error] of case "database-full". +// +// The database has reached its capacity +func ErrorDatabaseFull() Error { + var data struct{} + return cm.New[Error](3, data) +} + +// DatabaseFull returns true if [Error] represents the variant case "database-full". +func (self *Error) DatabaseFull() bool { + return self.Tag() == 3 +} + +// ErrorIO returns a [Error] of case "io". +// +// Some implementation-specific error has occurred (e.g. I/O) +func ErrorIO(data string) Error { + return cm.New[Error](4, data) +} + +// IO returns a non-nil *[string] if [Error] represents the variant case "io". +func (self *Error) IO() *string { + return cm.Case[string](self, 4) +} + +// Value represents the variant "fermyon:spin/sqlite#value". +// +// variant value { +// integer(s64), +// real(f64), +// text(string), +// blob(list), +// null, +// } +type Value cm.Variant[uint8, string, int64] + +// ValueInteger returns a [Value] of case "integer". +func ValueInteger(data int64) Value { + return cm.New[Value](0, data) +} + +// Integer returns a non-nil *[int64] if [Value] represents the variant case "integer". +func (self *Value) Integer() *int64 { + return cm.Case[int64](self, 0) +} + +// ValueReal returns a [Value] of case "real". +func ValueReal(data float64) Value { + return cm.New[Value](1, data) +} + +// Real returns a non-nil *[float64] if [Value] represents the variant case "real". +func (self *Value) Real() *float64 { + return cm.Case[float64](self, 1) +} + +// ValueText returns a [Value] of case "text". +func ValueText(data string) Value { + return cm.New[Value](2, data) +} + +// Text returns a non-nil *[string] if [Value] represents the variant case "text". +func (self *Value) Text() *string { + return cm.Case[string](self, 2) +} + +// ValueBlob returns a [Value] of case "blob". +func ValueBlob(data cm.List[uint8]) Value { + return cm.New[Value](3, data) +} + +// Blob returns a non-nil *[cm.List[uint8]] if [Value] represents the variant case "blob". +func (self *Value) Blob() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 3) +} + +// ValueNull returns a [Value] of case "null". +func ValueNull() Value { + var data struct{} + return cm.New[Value](4, data) +} + +// Null returns true if [Value] represents the variant case "null". +func (self *Value) Null() bool { + return self.Tag() == 4 +} + +// RowResult represents the record "fermyon:spin/sqlite#row-result". +// +// A set of values for each of the columns in a query-result +// +// record row-result { +// values: list, +// } +type RowResult struct { + Values cm.List[Value] +} + +// QueryResult represents the record "fermyon:spin/sqlite#query-result". +// +// A result of a query +// +// record query-result { +// columns: list, +// rows: list, +// } +type QueryResult struct { + // The names of the columns retrieved in the query + Columns cm.List[string] + + // the row results each containing the values for all the columns for a given row + Rows cm.List[RowResult] +} + +// Open represents the imported function "open". +// +// Open a connection to a named database instance. +// +// If `database` is "default", the default instance is opened. +// +// `error::no-such-database` will be raised if the `name` is not recognized. +// +// open: func(database: string) -> result +// +//go:nosplit +func Open(database string) (result cm.Result[ErrorShape, Connection, Error]) { + database0, database1 := cm.LowerString(database) + wasmimport_Open((*uint8)(database0), (uint32)(database1), &result) + return +} + +//go:wasmimport fermyon:spin/sqlite open +//go:noescape +func wasmimport_Open(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +// Execute represents the imported function "execute". +// +// Execute a statement returning back data if there is any +// +// execute: func(conn: connection, statement: string, parameters: list) -> +// result +// +//go:nosplit +func Execute(conn Connection, statement string, parameters cm.List[Value]) (result cm.Result[QueryResultShape, QueryResult, Error]) { + conn0 := (uint32)(conn) + statement0, statement1 := cm.LowerString(statement) + parameters0, parameters1 := cm.LowerList(parameters) + wasmimport_Execute((uint32)(conn0), (*uint8)(statement0), (uint32)(statement1), (*Value)(parameters0), (uint32)(parameters1), &result) + return +} + +//go:wasmimport fermyon:spin/sqlite execute +//go:noescape +func wasmimport_Execute(conn0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) + +// Close represents the imported function "close". +// +// Close the specified `connection`. +// +// close: func(conn: connection) +// +//go:nosplit +func Close(conn Connection) { + conn0 := (uint32)(conn) + wasmimport_Close((uint32)(conn0)) + return +} + +//go:wasmimport fermyon:spin/sqlite close +//go:noescape +func wasmimport_Close(conn0 uint32) diff --git a/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go new file mode 100644 index 0000000..5e2a11f --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go @@ -0,0 +1,6 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package httptrigger represents the world "fermyon:spin/http-trigger@2.0.0". +// +// The full world of a guest targeting an http-trigger +package httptrigger diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go new file mode 100644 index 0000000..3b9d3d5 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} + +// OptionListU8Shape is used for storage in variant or result types. +type OptionListU8Shape struct { + shape [unsafe.Sizeof(cm.Option[cm.List[uint8]]{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/empty.s b/v2/internal/fermyon/spin/v2.0.0/key-value/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go new file mode 100644 index 0000000..6b7b037 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go @@ -0,0 +1,210 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package keyvalue represents the imported interface "fermyon:spin/key-value@2.0.0". +package keyvalue + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Store represents the imported resource "fermyon:spin/key-value@2.0.0#store". +// +// An open key-value store +// +// resource store +type Store cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "store". +// +// Drops a resource handle. +// +//go:nosplit +func (self Store) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_StoreResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [resource-drop]store +//go:noescape +func wasmimport_StoreResourceDrop(self0 uint32) + +// StoreOpen represents the imported static function "open". +// +// Open the store with the specified label. +// +// `label` must refer to a store allowed in the spin.toml manifest. +// +// `error::no-such-store` will be raised if the `label` is not recognized. +// +// open: static func(label: string) -> result +// +//go:nosplit +func StoreOpen(label string) (result cm.Result[ErrorShape, Store, Error]) { + label0, label1 := cm.LowerString(label) + wasmimport_StoreOpen((*uint8)(label0), (uint32)(label1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [static]store.open +//go:noescape +func wasmimport_StoreOpen(label0 *uint8, label1 uint32, result *cm.Result[ErrorShape, Store, Error]) + +// Delete represents the imported method "delete". +// +// Delete the tuple with the specified `key` +// +// No error is raised if a tuple did not previously exist for `key`. +// +// delete: func(key: string) -> result<_, error> +// +//go:nosplit +func (self Store) Delete(key string) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_StoreDelete((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.delete +//go:noescape +func wasmimport_StoreDelete(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Exists represents the imported method "exists". +// +// Return whether a tuple exists for the specified `key` +// +// exists: func(key: string) -> result +// +//go:nosplit +func (self Store) Exists(key string) (result cm.Result[ErrorShape, bool, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_StoreExists((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.exists +//go:noescape +func wasmimport_StoreExists(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) + +// Get represents the imported method "get". +// +// Get the value associated with the specified `key` +// +// Returns `ok(none)` if the key does not exist. +// +// get: func(key: string) -> result>, error> +// +//go:nosplit +func (self Store) Get(key string) (result cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_StoreGet((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get +//go:noescape +func wasmimport_StoreGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) + +// GetKeys represents the imported method "get-keys". +// +// Return a list of all the keys +// +// get-keys: func() -> result, error> +// +//go:nosplit +func (self Store) GetKeys() (result cm.Result[ErrorShape, cm.List[string], Error]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_StoreGetKeys((uint32)(self0), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get-keys +//go:noescape +func wasmimport_StoreGetKeys(self0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +// Set represents the imported method "set". +// +// Set the `value` associated with the specified `key` overwriting any existing value. +// +// set: func(key: string, value: list) -> result<_, error> +// +//go:nosplit +func (self Store) Set(key string, value cm.List[uint8]) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + value0, value1 := cm.LowerList(value) + wasmimport_StoreSet((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.set +//go:noescape +func wasmimport_StoreSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Error represents the variant "fermyon:spin/key-value@2.0.0#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// store-table-full, +// no-such-store, +// access-denied, +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorStoreTableFull returns a [Error] of case "store-table-full". +// +// Too many stores have been opened simultaneously. Closing one or more +// stores prior to retrying may address this. +func ErrorStoreTableFull() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// StoreTableFull returns true if [Error] represents the variant case "store-table-full". +func (self *Error) StoreTableFull() bool { + return self.Tag() == 0 +} + +// ErrorNoSuchStore returns a [Error] of case "no-such-store". +// +// The host does not recognize the store label requested. +func ErrorNoSuchStore() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// NoSuchStore returns true if [Error] represents the variant case "no-such-store". +func (self *Error) NoSuchStore() bool { + return self.Tag() == 1 +} + +// ErrorAccessDenied returns a [Error] of case "access-denied". +// +// The requesting component does not have access to the specified store +// (which may or may not exist). +func ErrorAccessDenied() Error { + var data struct{} + return cm.New[Error](2, data) +} + +// AccessDenied returns true if [Error] represents the variant case "access-denied". +func (self *Error) AccessDenied() bool { + return self.Tag() == 2 +} + +// ErrorOther returns a [Error] of case "other". +// +// Some implementation-specific error has occurred (e.g. I/O) +func ErrorOther(data string) Error { + return cm.New[Error](3, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 3) +} diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go new file mode 100644 index 0000000..b75401b --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go @@ -0,0 +1,43 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// InferencingResultShape is used for storage in variant or result types. +type InferencingResultShape struct { + shape [unsafe.Sizeof(InferencingResult{})]byte +} + +func lower_InferencingParams(v InferencingParams) (f0 uint32, f1 float32, f2 uint32, f3 float32, f4 uint32, f5 float32) { + f0 = (uint32)(v.MaxTokens) + f1 = (float32)(v.RepeatPenalty) + f2 = (uint32)(v.RepeatPenaltyLastNTokenCount) + f3 = (float32)(v.Temperature) + f4 = (uint32)(v.TopK) + f5 = (float32)(v.TopP) + return +} + +func lower_OptionInferencingParams(v cm.Option[InferencingParams]) (f0 uint32, f1 uint32, f2 float32, f3 uint32, f4 float32, f5 uint32, f6 float32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5, v6 := lower_InferencingParams(*some) + f1 = (uint32)(v1) + f2 = (float32)(v2) + f3 = (uint32)(v3) + f4 = (float32)(v4) + f5 = (uint32)(v5) + f6 = (float32)(v6) + } + return +} + +// EmbeddingsResultShape is used for storage in variant or result types. +type EmbeddingsResultShape struct { + shape [unsafe.Sizeof(EmbeddingsResult{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/empty.s b/v2/internal/fermyon/spin/v2.0.0/llm/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go new file mode 100644 index 0000000..88bcb96 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go @@ -0,0 +1,201 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package llm represents the imported interface "fermyon:spin/llm@2.0.0". +// +// A WASI interface dedicated to performing inferencing for Large Language Models. +package llm + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// InferencingModel represents the string "fermyon:spin/llm@2.0.0#inferencing-model". +// +// A Large Language Model. +// +// type inferencing-model = string +type InferencingModel string + +// InferencingParams represents the record "fermyon:spin/llm@2.0.0#inferencing-params". +// +// Inference request parameters +// +// record inferencing-params { +// max-tokens: u32, +// repeat-penalty: f32, +// repeat-penalty-last-n-token-count: u32, +// temperature: f32, +// top-k: u32, +// top-p: f32, +// } +type InferencingParams struct { + // The maximum tokens that should be inferred. + // + // Note: the backing implementation may return less tokens. + MaxTokens uint32 + + // The amount the model should avoid repeating tokens. + RepeatPenalty float32 + + // The number of tokens the model should apply the repeat penalty to. + RepeatPenaltyLastNTokenCount uint32 + + // The randomness with which the next token is selected. + Temperature float32 + + // The number of possible next tokens the model will choose from. + TopK uint32 + + // The probability total of next tokens the model will choose from. + TopP float32 +} + +// Error represents the variant "fermyon:spin/llm@2.0.0#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// model-not-supported, +// runtime-error(string), +// invalid-input(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorModelNotSupported returns a [Error] of case "model-not-supported". +func ErrorModelNotSupported() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// ModelNotSupported returns true if [Error] represents the variant case "model-not-supported". +func (self *Error) ModelNotSupported() bool { + return self.Tag() == 0 +} + +// ErrorRuntimeError returns a [Error] of case "runtime-error". +func ErrorRuntimeError(data string) Error { + return cm.New[Error](1, data) +} + +// RuntimeError returns a non-nil *[string] if [Error] represents the variant case "runtime-error". +func (self *Error) RuntimeError() *string { + return cm.Case[string](self, 1) +} + +// ErrorInvalidInput returns a [Error] of case "invalid-input". +func ErrorInvalidInput(data string) Error { + return cm.New[Error](2, data) +} + +// InvalidInput returns a non-nil *[string] if [Error] represents the variant case "invalid-input". +func (self *Error) InvalidInput() *string { + return cm.Case[string](self, 2) +} + +// InferencingUsage represents the record "fermyon:spin/llm@2.0.0#inferencing-usage". +// +// Usage information related to the inferencing result +// +// record inferencing-usage { +// prompt-token-count: u32, +// generated-token-count: u32, +// } +type InferencingUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 + + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 +} + +// InferencingResult represents the record "fermyon:spin/llm@2.0.0#inferencing-result". +// +// An inferencing result +// +// record inferencing-result { +// text: string, +// usage: inferencing-usage, +// } +type InferencingResult struct { + // The text generated by the model + // TODO: this should be a stream + Text string + + // Usage information about the inferencing request + Usage InferencingUsage +} + +// EmbeddingModel represents the string "fermyon:spin/llm@2.0.0#embedding-model". +// +// The model used for generating embeddings +// +// type embedding-model = string +type EmbeddingModel string + +// EmbeddingsUsage represents the record "fermyon:spin/llm@2.0.0#embeddings-usage". +// +// Usage related to an embeddings generation request +// +// record embeddings-usage { +// prompt-token-count: u32, +// } +type EmbeddingsUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 +} + +// EmbeddingsResult represents the record "fermyon:spin/llm@2.0.0#embeddings-result". +// +// Result of generating embeddings +// +// record embeddings-result { +// embeddings: list>, +// usage: embeddings-usage, +// } +type EmbeddingsResult struct { + // The embeddings generated by the request + Embeddings cm.List[cm.List[float32]] + + // Usage related to the embeddings generation request + Usage EmbeddingsUsage +} + +// Infer represents the imported function "infer". +// +// Perform inferencing using the provided model and prompt with the given optional +// params +// +// infer: func(model: inferencing-model, prompt: string, params: option) +// -> result +// +//go:nosplit +func Infer(model InferencingModel, prompt string, params cm.Option[InferencingParams]) (result cm.Result[InferencingResultShape, InferencingResult, Error]) { + model0, model1 := cm.LowerString(model) + prompt0, prompt1 := cm.LowerString(prompt) + params0, params1, params2, params3, params4, params5, params6 := lower_OptionInferencingParams(params) + wasmimport_Infer((*uint8)(model0), (uint32)(model1), (*uint8)(prompt0), (uint32)(prompt1), (uint32)(params0), (uint32)(params1), (float32)(params2), (uint32)(params3), (float32)(params4), (uint32)(params5), (float32)(params6), &result) + return +} + +//go:wasmimport fermyon:spin/llm@2.0.0 infer +//go:noescape +func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) + +// GenerateEmbeddings represents the imported function "generate-embeddings". +// +// Generate embeddings for the supplied list of text +// +// generate-embeddings: func(model: embedding-model, text: list) -> result +// +//go:nosplit +func GenerateEmbeddings(model EmbeddingModel, text cm.List[string]) (result cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) { + model0, model1 := cm.LowerString(model) + text0, text1 := cm.LowerList(text) + wasmimport_GenerateEmbeddings((*uint8)(model0), (uint32)(model1), (*string)(text0), (uint32)(text1), &result) + return +} + +//go:wasmimport fermyon:spin/llm@2.0.0 generate-embeddings +//go:noescape +func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go new file mode 100644 index 0000000..889d12c --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mqtt + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s b/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go new file mode 100644 index 0000000..3409d31 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go @@ -0,0 +1,166 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package mqtt represents the imported interface "fermyon:spin/mqtt@2.0.0". +package mqtt + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the variant "fermyon:spin/mqtt@2.0.0#error". +// +// Errors related to interacting with Mqtt +// +// variant error { +// invalid-address, +// too-many-connections, +// connection-failed(string), +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorInvalidAddress returns a [Error] of case "invalid-address". +// +// An invalid address string +func ErrorInvalidAddress() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// InvalidAddress returns true if [Error] represents the variant case "invalid-address". +func (self *Error) InvalidAddress() bool { + return self.Tag() == 0 +} + +// ErrorTooManyConnections returns a [Error] of case "too-many-connections". +// +// There are too many open connections +func ErrorTooManyConnections() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// TooManyConnections returns true if [Error] represents the variant case "too-many-connections". +func (self *Error) TooManyConnections() bool { + return self.Tag() == 1 +} + +// ErrorConnectionFailed returns a [Error] of case "connection-failed". +// +// Connection failure e.g. address not allowed. +func ErrorConnectionFailed(data string) Error { + return cm.New[Error](2, data) +} + +// ConnectionFailed returns a non-nil *[string] if [Error] represents the variant case "connection-failed". +func (self *Error) ConnectionFailed() *string { + return cm.Case[string](self, 2) +} + +// ErrorOther returns a [Error] of case "other". +// +// Some other error occurred +func ErrorOther(data string) Error { + return cm.New[Error](3, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 3) +} + +// Qos represents the enum "fermyon:spin/mqtt@2.0.0#qos". +// +// QoS for publishing Mqtt messages +// +// enum qos { +// at-most-once, +// at-least-once, +// exactly-once +// } +type Qos uint8 + +const ( + QosAtMostOnce Qos = iota + QosAtLeastOnce + QosExactlyOnce +) + +var stringsQos = [3]string{ + "at-most-once", + "at-least-once", + "exactly-once", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Qos) String() string { + return stringsQos[e] +} + +// Connection represents the imported resource "fermyon:spin/mqtt@2.0.0#connection". +// +// resource connection +type Connection cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "connection". +// +// Drops a resource handle. +// +//go:nosplit +func (self Connection) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ConnectionResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +// ConnectionOpen represents the imported static function "open". +// +// Open a connection to the Mqtt instance at `address`. +// +// open: static func(address: string, username: string, password: string, keep-alive-interval-in-secs: +// u64) -> result +// +//go:nosplit +func ConnectionOpen(address string, username string, password string, keepAliveIntervalInSecs uint64) (result cm.Result[ErrorShape, Connection, Error]) { + address0, address1 := cm.LowerString(address) + username0, username1 := cm.LowerString(username) + password0, password1 := cm.LowerString(password) + keepAliveIntervalInSecs0 := (uint64)(keepAliveIntervalInSecs) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), (*uint8)(username0), (uint32)(username1), (*uint8)(password0), (uint32)(password1), (uint64)(keepAliveIntervalInSecs0), &result) + return +} + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, username0 *uint8, username1 uint32, password0 *uint8, password1 uint32, keepAliveIntervalInSecs0 uint64, result *cm.Result[ErrorShape, Connection, Error]) + +// Publish represents the imported method "publish". +// +// Publish an Mqtt message to the specified `topic`. +// +// publish: func(topic: string, payload: payload, qos: qos) -> result<_, error> +// +//go:nosplit +func (self Connection) Publish(topic string, payload Payload, qos Qos) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + topic0, topic1 := cm.LowerString(topic) + payload0, payload1 := cm.LowerList(payload) + qos0 := (uint32)(qos) + wasmimport_ConnectionPublish((uint32)(self0), (*uint8)(topic0), (uint32)(topic1), (*uint8)(payload0), (uint32)(payload1), (uint32)(qos0), &result) + return +} + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [method]connection.publish +//go:noescape +func wasmimport_ConnectionPublish(self0 uint32, topic0 *uint8, topic1 uint32, payload0 *uint8, payload1 uint32, qos0 uint32, result *cm.Result[Error, struct{}, Error]) + +// Payload represents the list "fermyon:spin/mqtt@2.0.0#payload". +// +// The message payload. +// +// type payload = list +type Payload cm.List[uint8] diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go new file mode 100644 index 0000000..7b18fbb --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mysql + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(rdbmstypes.Error{})]byte +} + +// RowSetShape is used for storage in variant or result types. +type RowSetShape struct { + shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/empty.s b/v2/internal/fermyon/spin/v2.0.0/mysql/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go new file mode 100644 index 0000000..cf7791d --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go @@ -0,0 +1,87 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package mysql represents the imported interface "fermyon:spin/mysql@2.0.0". +package mysql + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Connection represents the imported resource "fermyon:spin/mysql@2.0.0#connection". +// +// A connection to a MySQL database. +// +// resource connection +type Connection cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "connection". +// +// Drops a resource handle. +// +//go:nosplit +func (self Connection) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ConnectionResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +// ConnectionOpen represents the imported static function "open". +// +// Open a connection to the MySQL instance at `address`. +// +// open: static func(address: string) -> result +// +//go:nosplit +func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, rdbmstypes.Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, rdbmstypes.Error]) + +// Execute represents the imported method "execute". +// +// execute command to the database: insert, update, delete +// +// execute: func(statement: string, params: list) -> result<_, error> +// +//go:nosplit +func (self Connection) Execute(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[rdbmstypes.Error, struct{}, rdbmstypes.Error]) { + self0 := cm.Reinterpret[uint32](self) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[rdbmstypes.Error, struct{}, rdbmstypes.Error]) + +// Query represents the imported method "query". +// +// query the database: select +// +// query: func(statement: string, params: list) -> result +// +//go:nosplit +func (self Connection) Query(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) { + self0 := cm.Reinterpret[uint32](self) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.query +//go:noescape +func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go new file mode 100644 index 0000000..e8944bc --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(rdbmstypes.Error{})]byte +} + +// RowSetShape is used for storage in variant or result types. +type RowSetShape struct { + shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/empty.s b/v2/internal/fermyon/spin/v2.0.0/postgres/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go new file mode 100644 index 0000000..19ae149 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go @@ -0,0 +1,88 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package postgres represents the imported interface "fermyon:spin/postgres@2.0.0". +package postgres + +import ( + rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Connection represents the imported resource "fermyon:spin/postgres@2.0.0#connection". +// +// A connection to a postgres database. +// +// resource connection +type Connection cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "connection". +// +// Drops a resource handle. +// +//go:nosplit +func (self Connection) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ConnectionResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +// ConnectionOpen represents the imported static function "open". +// +// Open a connection to the Postgres instance at `address`. +// +// open: static func(address: string) -> result +// +//go:nosplit +func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, rdbmstypes.Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, rdbmstypes.Error]) + +// Execute represents the imported method "execute". +// +// Execute command to the database. +// +// execute: func(statement: string, params: list) -> result +// +//go:nosplit +func (self Connection) Execute(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[ErrorShape, uint64, rdbmstypes.Error]) { + self0 := cm.Reinterpret[uint32](self) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[ErrorShape, uint64, rdbmstypes.Error]) + +// Query represents the imported method "query". +// +// Query the database. +// +// query: func(statement: string, params: list) -> result +// +//go:nosplit +func (self Connection) Query(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) { + self0 := cm.Reinterpret[uint32](self) + statement0, statement1 := cm.LowerString(statement) + params0, params1 := cm.LowerList(params) + wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + return +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.query +//go:noescape +func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go new file mode 100644 index 0000000..7d37564 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go @@ -0,0 +1,503 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package rdbmstypes represents the imported interface "fermyon:spin/rdbms-types@2.0.0". +package rdbmstypes + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the variant "fermyon:spin/rdbms-types@2.0.0#error". +// +// Errors related to interacting with a database. +// +// variant error { +// connection-failed(string), +// bad-parameter(string), +// query-failed(string), +// value-conversion-failed(string), +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorConnectionFailed returns a [Error] of case "connection-failed". +func ErrorConnectionFailed(data string) Error { + return cm.New[Error](0, data) +} + +// ConnectionFailed returns a non-nil *[string] if [Error] represents the variant case "connection-failed". +func (self *Error) ConnectionFailed() *string { + return cm.Case[string](self, 0) +} + +// ErrorBadParameter returns a [Error] of case "bad-parameter". +func ErrorBadParameter(data string) Error { + return cm.New[Error](1, data) +} + +// BadParameter returns a non-nil *[string] if [Error] represents the variant case "bad-parameter". +func (self *Error) BadParameter() *string { + return cm.Case[string](self, 1) +} + +// ErrorQueryFailed returns a [Error] of case "query-failed". +func ErrorQueryFailed(data string) Error { + return cm.New[Error](2, data) +} + +// QueryFailed returns a non-nil *[string] if [Error] represents the variant case "query-failed". +func (self *Error) QueryFailed() *string { + return cm.Case[string](self, 2) +} + +// ErrorValueConversionFailed returns a [Error] of case "value-conversion-failed". +func ErrorValueConversionFailed(data string) Error { + return cm.New[Error](3, data) +} + +// ValueConversionFailed returns a non-nil *[string] if [Error] represents the variant case "value-conversion-failed". +func (self *Error) ValueConversionFailed() *string { + return cm.Case[string](self, 3) +} + +// ErrorOther returns a [Error] of case "other". +func ErrorOther(data string) Error { + return cm.New[Error](4, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 4) +} + +// DbDataType represents the enum "fermyon:spin/rdbms-types@2.0.0#db-data-type". +// +// Data types for a database column +// +// enum db-data-type { +// boolean, +// int8, +// int16, +// int32, +// int64, +// uint8, +// uint16, +// uint32, +// uint64, +// floating32, +// floating64, +// str, +// binary, +// other +// } +type DbDataType uint8 + +const ( + DbDataTypeBoolean DbDataType = iota + DbDataTypeInt8 + DbDataTypeInt16 + DbDataTypeInt32 + DbDataTypeInt64 + DbDataTypeUint8 + DbDataTypeUint16 + DbDataTypeUint32 + DbDataTypeUint64 + DbDataTypeFloating32 + DbDataTypeFloating64 + DbDataTypeStr + DbDataTypeBinary + DbDataTypeOther +) + +var stringsDbDataType = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "other", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e DbDataType) String() string { + return stringsDbDataType[e] +} + +// DbValue represents the variant "fermyon:spin/rdbms-types@2.0.0#db-value". +// +// Database values +// +// variant db-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// uint8(u8), +// uint16(u16), +// uint32(u32), +// uint64(u64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// db-null, +// unsupported, +// } +type DbValue cm.Variant[uint8, string, int64] + +// DbValueBoolean returns a [DbValue] of case "boolean". +func DbValueBoolean(data bool) DbValue { + return cm.New[DbValue](0, data) +} + +// Boolean returns a non-nil *[bool] if [DbValue] represents the variant case "boolean". +func (self *DbValue) Boolean() *bool { + return cm.Case[bool](self, 0) +} + +// DbValueInt8 returns a [DbValue] of case "int8". +func DbValueInt8(data int8) DbValue { + return cm.New[DbValue](1, data) +} + +// Int8 returns a non-nil *[int8] if [DbValue] represents the variant case "int8". +func (self *DbValue) Int8() *int8 { + return cm.Case[int8](self, 1) +} + +// DbValueInt16 returns a [DbValue] of case "int16". +func DbValueInt16(data int16) DbValue { + return cm.New[DbValue](2, data) +} + +// Int16 returns a non-nil *[int16] if [DbValue] represents the variant case "int16". +func (self *DbValue) Int16() *int16 { + return cm.Case[int16](self, 2) +} + +// DbValueInt32 returns a [DbValue] of case "int32". +func DbValueInt32(data int32) DbValue { + return cm.New[DbValue](3, data) +} + +// Int32 returns a non-nil *[int32] if [DbValue] represents the variant case "int32". +func (self *DbValue) Int32() *int32 { + return cm.Case[int32](self, 3) +} + +// DbValueInt64 returns a [DbValue] of case "int64". +func DbValueInt64(data int64) DbValue { + return cm.New[DbValue](4, data) +} + +// Int64 returns a non-nil *[int64] if [DbValue] represents the variant case "int64". +func (self *DbValue) Int64() *int64 { + return cm.Case[int64](self, 4) +} + +// DbValueUint8 returns a [DbValue] of case "uint8". +func DbValueUint8(data uint8) DbValue { + return cm.New[DbValue](5, data) +} + +// Uint8 returns a non-nil *[uint8] if [DbValue] represents the variant case "uint8". +func (self *DbValue) Uint8() *uint8 { + return cm.Case[uint8](self, 5) +} + +// DbValueUint16 returns a [DbValue] of case "uint16". +func DbValueUint16(data uint16) DbValue { + return cm.New[DbValue](6, data) +} + +// Uint16 returns a non-nil *[uint16] if [DbValue] represents the variant case "uint16". +func (self *DbValue) Uint16() *uint16 { + return cm.Case[uint16](self, 6) +} + +// DbValueUint32 returns a [DbValue] of case "uint32". +func DbValueUint32(data uint32) DbValue { + return cm.New[DbValue](7, data) +} + +// Uint32 returns a non-nil *[uint32] if [DbValue] represents the variant case "uint32". +func (self *DbValue) Uint32() *uint32 { + return cm.Case[uint32](self, 7) +} + +// DbValueUint64 returns a [DbValue] of case "uint64". +func DbValueUint64(data uint64) DbValue { + return cm.New[DbValue](8, data) +} + +// Uint64 returns a non-nil *[uint64] if [DbValue] represents the variant case "uint64". +func (self *DbValue) Uint64() *uint64 { + return cm.Case[uint64](self, 8) +} + +// DbValueFloating32 returns a [DbValue] of case "floating32". +func DbValueFloating32(data float32) DbValue { + return cm.New[DbValue](9, data) +} + +// Floating32 returns a non-nil *[float32] if [DbValue] represents the variant case "floating32". +func (self *DbValue) Floating32() *float32 { + return cm.Case[float32](self, 9) +} + +// DbValueFloating64 returns a [DbValue] of case "floating64". +func DbValueFloating64(data float64) DbValue { + return cm.New[DbValue](10, data) +} + +// Floating64 returns a non-nil *[float64] if [DbValue] represents the variant case "floating64". +func (self *DbValue) Floating64() *float64 { + return cm.Case[float64](self, 10) +} + +// DbValueStr returns a [DbValue] of case "str". +func DbValueStr(data string) DbValue { + return cm.New[DbValue](11, data) +} + +// Str returns a non-nil *[string] if [DbValue] represents the variant case "str". +func (self *DbValue) Str() *string { + return cm.Case[string](self, 11) +} + +// DbValueBinary returns a [DbValue] of case "binary". +func DbValueBinary(data cm.List[uint8]) DbValue { + return cm.New[DbValue](12, data) +} + +// Binary returns a non-nil *[cm.List[uint8]] if [DbValue] represents the variant case "binary". +func (self *DbValue) Binary() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 12) +} + +// DbValueDbNull returns a [DbValue] of case "db-null". +func DbValueDbNull() DbValue { + var data struct{} + return cm.New[DbValue](13, data) +} + +// DbNull returns true if [DbValue] represents the variant case "db-null". +func (self *DbValue) DbNull() bool { + return self.Tag() == 13 +} + +// DbValueUnsupported returns a [DbValue] of case "unsupported". +func DbValueUnsupported() DbValue { + var data struct{} + return cm.New[DbValue](14, data) +} + +// Unsupported returns true if [DbValue] represents the variant case "unsupported". +func (self *DbValue) Unsupported() bool { + return self.Tag() == 14 +} + +// ParameterValue represents the variant "fermyon:spin/rdbms-types@2.0.0#parameter-value". +// +// Values used in parameterized queries +// +// variant parameter-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// uint8(u8), +// uint16(u16), +// uint32(u32), +// uint64(u64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// db-null, +// } +type ParameterValue cm.Variant[uint8, string, int64] + +// ParameterValueBoolean returns a [ParameterValue] of case "boolean". +func ParameterValueBoolean(data bool) ParameterValue { + return cm.New[ParameterValue](0, data) +} + +// Boolean returns a non-nil *[bool] if [ParameterValue] represents the variant case "boolean". +func (self *ParameterValue) Boolean() *bool { + return cm.Case[bool](self, 0) +} + +// ParameterValueInt8 returns a [ParameterValue] of case "int8". +func ParameterValueInt8(data int8) ParameterValue { + return cm.New[ParameterValue](1, data) +} + +// Int8 returns a non-nil *[int8] if [ParameterValue] represents the variant case "int8". +func (self *ParameterValue) Int8() *int8 { + return cm.Case[int8](self, 1) +} + +// ParameterValueInt16 returns a [ParameterValue] of case "int16". +func ParameterValueInt16(data int16) ParameterValue { + return cm.New[ParameterValue](2, data) +} + +// Int16 returns a non-nil *[int16] if [ParameterValue] represents the variant case "int16". +func (self *ParameterValue) Int16() *int16 { + return cm.Case[int16](self, 2) +} + +// ParameterValueInt32 returns a [ParameterValue] of case "int32". +func ParameterValueInt32(data int32) ParameterValue { + return cm.New[ParameterValue](3, data) +} + +// Int32 returns a non-nil *[int32] if [ParameterValue] represents the variant case "int32". +func (self *ParameterValue) Int32() *int32 { + return cm.Case[int32](self, 3) +} + +// ParameterValueInt64 returns a [ParameterValue] of case "int64". +func ParameterValueInt64(data int64) ParameterValue { + return cm.New[ParameterValue](4, data) +} + +// Int64 returns a non-nil *[int64] if [ParameterValue] represents the variant case "int64". +func (self *ParameterValue) Int64() *int64 { + return cm.Case[int64](self, 4) +} + +// ParameterValueUint8 returns a [ParameterValue] of case "uint8". +func ParameterValueUint8(data uint8) ParameterValue { + return cm.New[ParameterValue](5, data) +} + +// Uint8 returns a non-nil *[uint8] if [ParameterValue] represents the variant case "uint8". +func (self *ParameterValue) Uint8() *uint8 { + return cm.Case[uint8](self, 5) +} + +// ParameterValueUint16 returns a [ParameterValue] of case "uint16". +func ParameterValueUint16(data uint16) ParameterValue { + return cm.New[ParameterValue](6, data) +} + +// Uint16 returns a non-nil *[uint16] if [ParameterValue] represents the variant case "uint16". +func (self *ParameterValue) Uint16() *uint16 { + return cm.Case[uint16](self, 6) +} + +// ParameterValueUint32 returns a [ParameterValue] of case "uint32". +func ParameterValueUint32(data uint32) ParameterValue { + return cm.New[ParameterValue](7, data) +} + +// Uint32 returns a non-nil *[uint32] if [ParameterValue] represents the variant case "uint32". +func (self *ParameterValue) Uint32() *uint32 { + return cm.Case[uint32](self, 7) +} + +// ParameterValueUint64 returns a [ParameterValue] of case "uint64". +func ParameterValueUint64(data uint64) ParameterValue { + return cm.New[ParameterValue](8, data) +} + +// Uint64 returns a non-nil *[uint64] if [ParameterValue] represents the variant case "uint64". +func (self *ParameterValue) Uint64() *uint64 { + return cm.Case[uint64](self, 8) +} + +// ParameterValueFloating32 returns a [ParameterValue] of case "floating32". +func ParameterValueFloating32(data float32) ParameterValue { + return cm.New[ParameterValue](9, data) +} + +// Floating32 returns a non-nil *[float32] if [ParameterValue] represents the variant case "floating32". +func (self *ParameterValue) Floating32() *float32 { + return cm.Case[float32](self, 9) +} + +// ParameterValueFloating64 returns a [ParameterValue] of case "floating64". +func ParameterValueFloating64(data float64) ParameterValue { + return cm.New[ParameterValue](10, data) +} + +// Floating64 returns a non-nil *[float64] if [ParameterValue] represents the variant case "floating64". +func (self *ParameterValue) Floating64() *float64 { + return cm.Case[float64](self, 10) +} + +// ParameterValueStr returns a [ParameterValue] of case "str". +func ParameterValueStr(data string) ParameterValue { + return cm.New[ParameterValue](11, data) +} + +// Str returns a non-nil *[string] if [ParameterValue] represents the variant case "str". +func (self *ParameterValue) Str() *string { + return cm.Case[string](self, 11) +} + +// ParameterValueBinary returns a [ParameterValue] of case "binary". +func ParameterValueBinary(data cm.List[uint8]) ParameterValue { + return cm.New[ParameterValue](12, data) +} + +// Binary returns a non-nil *[cm.List[uint8]] if [ParameterValue] represents the variant case "binary". +func (self *ParameterValue) Binary() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 12) +} + +// ParameterValueDbNull returns a [ParameterValue] of case "db-null". +func ParameterValueDbNull() ParameterValue { + var data struct{} + return cm.New[ParameterValue](13, data) +} + +// DbNull returns true if [ParameterValue] represents the variant case "db-null". +func (self *ParameterValue) DbNull() bool { + return self.Tag() == 13 +} + +// Column represents the record "fermyon:spin/rdbms-types@2.0.0#column". +// +// A database column +// +// record column { +// name: string, +// data-type: db-data-type, +// } +type Column struct { + Name string + DataType DbDataType +} + +// Row represents the list "fermyon:spin/rdbms-types@2.0.0#row". +// +// A database row +// +// type row = list +type Row cm.List[DbValue] + +// RowSet represents the record "fermyon:spin/rdbms-types@2.0.0#row-set". +// +// A set of database rows +// +// record row-set { +// columns: list, +// rows: list, +// } +type RowSet struct { + Columns cm.List[Column] + Rows cm.List[Row] +} diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go new file mode 100644 index 0000000..7bd36a5 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package redis + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} + +// OptionPayloadShape is used for storage in variant or result types. +type OptionPayloadShape struct { + shape [unsafe.Sizeof(cm.Option[Payload]{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/empty.s b/v2/internal/fermyon/spin/v2.0.0/redis/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go new file mode 100644 index 0000000..a7d7cd6 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go @@ -0,0 +1,376 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package redis represents the imported interface "fermyon:spin/redis@2.0.0". +package redis + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the variant "fermyon:spin/redis@2.0.0#error". +// +// Errors related to interacting with Redis +// +// variant error { +// invalid-address, +// too-many-connections, +// type-error, +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorInvalidAddress returns a [Error] of case "invalid-address". +// +// An invalid address string +func ErrorInvalidAddress() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// InvalidAddress returns true if [Error] represents the variant case "invalid-address". +func (self *Error) InvalidAddress() bool { + return self.Tag() == 0 +} + +// ErrorTooManyConnections returns a [Error] of case "too-many-connections". +// +// There are too many open connections +func ErrorTooManyConnections() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// TooManyConnections returns true if [Error] represents the variant case "too-many-connections". +func (self *Error) TooManyConnections() bool { + return self.Tag() == 1 +} + +// ErrorTypeError returns a [Error] of case "type-error". +// +// A retrieved value was not of the correct type +func ErrorTypeError() Error { + var data struct{} + return cm.New[Error](2, data) +} + +// TypeError returns true if [Error] represents the variant case "type-error". +func (self *Error) TypeError() bool { + return self.Tag() == 2 +} + +// ErrorOther returns a [Error] of case "other". +// +// Some other error occurred +func ErrorOther(data string) Error { + return cm.New[Error](3, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 3) +} + +// Connection represents the imported resource "fermyon:spin/redis@2.0.0#connection". +// +// resource connection +type Connection cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "connection". +// +// Drops a resource handle. +// +//go:nosplit +func (self Connection) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ConnectionResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +// ConnectionOpen represents the imported static function "open". +// +// Open a connection to the Redis instance at `address`. +// +// open: static func(address: string) -> result +// +//go:nosplit +func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +// Del represents the imported method "del". +// +// Removes the specified keys. +// +// A key is ignored if it does not exist. Returns the number of keys deleted. +// +// del: func(keys: list) -> result +// +//go:nosplit +func (self Connection) Del(keys cm.List[string]) (result cm.Result[ErrorShape, uint32, Error]) { + self0 := cm.Reinterpret[uint32](self) + keys0, keys1 := cm.LowerList(keys) + wasmimport_ConnectionDel((uint32)(self0), (*string)(keys0), (uint32)(keys1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.del +//go:noescape +func wasmimport_ConnectionDel(self0 uint32, keys0 *string, keys1 uint32, result *cm.Result[ErrorShape, uint32, Error]) + +// Execute represents the imported method "execute". +// +// Execute an arbitrary Redis command and receive the result. +// +// execute: func(command: string, arguments: list) -> result, +// error> +// +//go:nosplit +func (self Connection) Execute(command string, arguments cm.List[RedisParameter]) (result cm.Result[ErrorShape, cm.List[RedisResult], Error]) { + self0 := cm.Reinterpret[uint32](self) + command0, command1 := cm.LowerString(command) + arguments0, arguments1 := cm.LowerList(arguments) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(command0), (uint32)(command1), (*RedisParameter)(arguments0), (uint32)(arguments1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, command0 *uint8, command1 uint32, arguments0 *RedisParameter, arguments1 uint32, result *cm.Result[ErrorShape, cm.List[RedisResult], Error]) + +// Get represents the imported method "get". +// +// Get the value of a key. +// +// get: func(key: string) -> result, error> +// +//go:nosplit +func (self Connection) Get(key string) (result cm.Result[OptionPayloadShape, cm.Option[Payload], Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_ConnectionGet((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.get +//go:noescape +func wasmimport_ConnectionGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionPayloadShape, cm.Option[Payload], Error]) + +// Incr represents the imported method "incr". +// +// Increments the number stored at key by one. +// +// If the key does not exist, it is set to 0 before performing the operation. +// An `error::type-error` is returned if the key contains a value of the wrong type +// or contains a string that can not be represented as integer. +// +// incr: func(key: string) -> result +// +//go:nosplit +func (self Connection) Incr(key string) (result cm.Result[ErrorShape, int64, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_ConnectionIncr((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.incr +//go:noescape +func wasmimport_ConnectionIncr(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, int64, Error]) + +// Publish represents the imported method "publish". +// +// Publish a Redis message to the specified channel. +// +// publish: func(channel: string, payload: payload) -> result<_, error> +// +//go:nosplit +func (self Connection) Publish(channel string, payload Payload) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + channel0, channel1 := cm.LowerString(channel) + payload0, payload1 := cm.LowerList(payload) + wasmimport_ConnectionPublish((uint32)(self0), (*uint8)(channel0), (uint32)(channel1), (*uint8)(payload0), (uint32)(payload1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.publish +//go:noescape +func wasmimport_ConnectionPublish(self0 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Sadd represents the imported method "sadd". +// +// Add the specified `values` to the set named `key`, returning the number of newly-added +// values. +// +// sadd: func(key: string, values: list) -> result +// +//go:nosplit +func (self Connection) Sadd(key string, values cm.List[string]) (result cm.Result[ErrorShape, uint32, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + values0, values1 := cm.LowerList(values) + wasmimport_ConnectionSadd((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*string)(values0), (uint32)(values1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.sadd +//go:noescape +func wasmimport_ConnectionSadd(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) + +// Set represents the imported method "set". +// +// Set key to value. +// +// If key already holds a value, it is overwritten. +// +// set: func(key: string, value: payload) -> result<_, error> +// +//go:nosplit +func (self Connection) Set(key string, value Payload) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + value0, value1 := cm.LowerList(value) + wasmimport_ConnectionSet((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.set +//go:noescape +func wasmimport_ConnectionSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +// Smembers represents the imported method "smembers". +// +// Retrieve the contents of the set named `key`. +// +// smembers: func(key: string) -> result, error> +// +//go:nosplit +func (self Connection) Smembers(key string) (result cm.Result[ErrorShape, cm.List[string], Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_ConnectionSmembers((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.smembers +//go:noescape +func wasmimport_ConnectionSmembers(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +// Srem represents the imported method "srem". +// +// Remove the specified `values` from the set named `key`, returning the number of +// newly-removed values. +// +// srem: func(key: string, values: list) -> result +// +//go:nosplit +func (self Connection) Srem(key string, values cm.List[string]) (result cm.Result[ErrorShape, uint32, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + values0, values1 := cm.LowerList(values) + wasmimport_ConnectionSrem((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*string)(values0), (uint32)(values1), &result) + return +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.srem +//go:noescape +func wasmimport_ConnectionSrem(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) + +// Payload represents the list "fermyon:spin/redis@2.0.0#payload". +// +// The message payload. +// +// type payload = list +type Payload cm.List[uint8] + +// RedisParameter represents the variant "fermyon:spin/redis@2.0.0#redis-parameter". +// +// A parameter type for the general-purpose `execute` function. +// +// variant redis-parameter { +// int64(s64), +// binary(payload), +// } +type RedisParameter cm.Variant[uint8, Payload, int64] + +// RedisParameterInt64 returns a [RedisParameter] of case "int64". +func RedisParameterInt64(data int64) RedisParameter { + return cm.New[RedisParameter](0, data) +} + +// Int64 returns a non-nil *[int64] if [RedisParameter] represents the variant case "int64". +func (self *RedisParameter) Int64() *int64 { + return cm.Case[int64](self, 0) +} + +// RedisParameterBinary returns a [RedisParameter] of case "binary". +func RedisParameterBinary(data Payload) RedisParameter { + return cm.New[RedisParameter](1, data) +} + +// Binary returns a non-nil *[Payload] if [RedisParameter] represents the variant case "binary". +func (self *RedisParameter) Binary() *Payload { + return cm.Case[Payload](self, 1) +} + +// RedisResult represents the variant "fermyon:spin/redis@2.0.0#redis-result". +// +// A return type for the general-purpose `execute` function. +// +// variant redis-result { +// nil, +// status(string), +// int64(s64), +// binary(payload), +// } +type RedisResult cm.Variant[uint8, string, int64] + +// RedisResultNil returns a [RedisResult] of case "nil". +func RedisResultNil() RedisResult { + var data struct{} + return cm.New[RedisResult](0, data) +} + +// Nil returns true if [RedisResult] represents the variant case "nil". +func (self *RedisResult) Nil() bool { + return self.Tag() == 0 +} + +// RedisResultStatus returns a [RedisResult] of case "status". +func RedisResultStatus(data string) RedisResult { + return cm.New[RedisResult](1, data) +} + +// Status returns a non-nil *[string] if [RedisResult] represents the variant case "status". +func (self *RedisResult) Status() *string { + return cm.Case[string](self, 1) +} + +// RedisResultInt64 returns a [RedisResult] of case "int64". +func RedisResultInt64(data int64) RedisResult { + return cm.New[RedisResult](2, data) +} + +// Int64 returns a non-nil *[int64] if [RedisResult] represents the variant case "int64". +func (self *RedisResult) Int64() *int64 { + return cm.Case[int64](self, 2) +} + +// RedisResultBinary returns a [RedisResult] of case "binary". +func RedisResultBinary(data Payload) RedisResult { + return cm.New[RedisResult](3, data) +} + +// Binary returns a non-nil *[Payload] if [RedisResult] represents the variant case "binary". +func (self *RedisResult) Binary() *Payload { + return cm.Case[Payload](self, 3) +} diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go new file mode 100644 index 0000000..a16610a --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} + +// QueryResultShape is used for storage in variant or result types. +type QueryResultShape struct { + shape [unsafe.Sizeof(QueryResult{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s b/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go new file mode 100644 index 0000000..dd46721 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go @@ -0,0 +1,240 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package sqlite represents the imported interface "fermyon:spin/sqlite@2.0.0". +package sqlite + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Connection represents the imported resource "fermyon:spin/sqlite@2.0.0#connection". +// +// A handle to an open sqlite instance +// +// resource connection +type Connection cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "connection". +// +// Drops a resource handle. +// +//go:nosplit +func (self Connection) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ConnectionResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +// ConnectionOpen represents the imported static function "open". +// +// Open a connection to a named database instance. +// +// If `database` is "default", the default instance is opened. +// +// `error::no-such-database` will be raised if the `name` is not recognized. +// +// open: static func(database: string) -> result +// +//go:nosplit +func ConnectionOpen(database string) (result cm.Result[ErrorShape, Connection, Error]) { + database0, database1 := cm.LowerString(database) + wasmimport_ConnectionOpen((*uint8)(database0), (uint32)(database1), &result) + return +} + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +// Execute represents the imported method "execute". +// +// Execute a statement returning back data if there is any +// +// execute: func(statement: string, parameters: list) -> result +// +//go:nosplit +func (self Connection) Execute(statement string, parameters cm.List[Value]) (result cm.Result[QueryResultShape, QueryResult, Error]) { + self0 := cm.Reinterpret[uint32](self) + statement0, statement1 := cm.LowerString(statement) + parameters0, parameters1 := cm.LowerList(parameters) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*Value)(parameters0), (uint32)(parameters1), &result) + return +} + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) + +// Error represents the variant "fermyon:spin/sqlite@2.0.0#error". +// +// The set of errors which may be raised by functions in this interface +// +// variant error { +// no-such-database, +// access-denied, +// invalid-connection, +// database-full, +// io(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorNoSuchDatabase returns a [Error] of case "no-such-database". +// +// The host does not recognize the database name requested. +func ErrorNoSuchDatabase() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// NoSuchDatabase returns true if [Error] represents the variant case "no-such-database". +func (self *Error) NoSuchDatabase() bool { + return self.Tag() == 0 +} + +// ErrorAccessDenied returns a [Error] of case "access-denied". +// +// The requesting component does not have access to the specified database (which +// may or may not exist). +func ErrorAccessDenied() Error { + var data struct{} + return cm.New[Error](1, data) +} + +// AccessDenied returns true if [Error] represents the variant case "access-denied". +func (self *Error) AccessDenied() bool { + return self.Tag() == 1 +} + +// ErrorInvalidConnection returns a [Error] of case "invalid-connection". +// +// The provided connection is not valid +func ErrorInvalidConnection() Error { + var data struct{} + return cm.New[Error](2, data) +} + +// InvalidConnection returns true if [Error] represents the variant case "invalid-connection". +func (self *Error) InvalidConnection() bool { + return self.Tag() == 2 +} + +// ErrorDatabaseFull returns a [Error] of case "database-full". +// +// The database has reached its capacity +func ErrorDatabaseFull() Error { + var data struct{} + return cm.New[Error](3, data) +} + +// DatabaseFull returns true if [Error] represents the variant case "database-full". +func (self *Error) DatabaseFull() bool { + return self.Tag() == 3 +} + +// ErrorIO returns a [Error] of case "io". +// +// Some implementation-specific error has occurred (e.g. I/O) +func ErrorIO(data string) Error { + return cm.New[Error](4, data) +} + +// IO returns a non-nil *[string] if [Error] represents the variant case "io". +func (self *Error) IO() *string { + return cm.Case[string](self, 4) +} + +// Value represents the variant "fermyon:spin/sqlite@2.0.0#value". +// +// A single column's result from a database query +// +// variant value { +// integer(s64), +// real(f64), +// text(string), +// blob(list), +// null, +// } +type Value cm.Variant[uint8, string, int64] + +// ValueInteger returns a [Value] of case "integer". +func ValueInteger(data int64) Value { + return cm.New[Value](0, data) +} + +// Integer returns a non-nil *[int64] if [Value] represents the variant case "integer". +func (self *Value) Integer() *int64 { + return cm.Case[int64](self, 0) +} + +// ValueReal returns a [Value] of case "real". +func ValueReal(data float64) Value { + return cm.New[Value](1, data) +} + +// Real returns a non-nil *[float64] if [Value] represents the variant case "real". +func (self *Value) Real() *float64 { + return cm.Case[float64](self, 1) +} + +// ValueText returns a [Value] of case "text". +func ValueText(data string) Value { + return cm.New[Value](2, data) +} + +// Text returns a non-nil *[string] if [Value] represents the variant case "text". +func (self *Value) Text() *string { + return cm.Case[string](self, 2) +} + +// ValueBlob returns a [Value] of case "blob". +func ValueBlob(data cm.List[uint8]) Value { + return cm.New[Value](3, data) +} + +// Blob returns a non-nil *[cm.List[uint8]] if [Value] represents the variant case "blob". +func (self *Value) Blob() *cm.List[uint8] { + return cm.Case[cm.List[uint8]](self, 3) +} + +// ValueNull returns a [Value] of case "null". +func ValueNull() Value { + var data struct{} + return cm.New[Value](4, data) +} + +// Null returns true if [Value] represents the variant case "null". +func (self *Value) Null() bool { + return self.Tag() == 4 +} + +// RowResult represents the record "fermyon:spin/sqlite@2.0.0#row-result". +// +// A set of values for each of the columns in a query-result +// +// record row-result { +// values: list, +// } +type RowResult struct { + Values cm.List[Value] +} + +// QueryResult represents the record "fermyon:spin/sqlite@2.0.0#query-result". +// +// A result of a query +// +// record query-result { +// columns: list, +// rows: list, +// } +type QueryResult struct { + // The names of the columns retrieved in the query + Columns cm.List[string] + + // the row results each containing the values for all the columns for a given row + Rows cm.List[RowResult] +} diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/abi.go b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go new file mode 100644 index 0000000..b850a1e --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package variables + +import ( + "unsafe" +) + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + shape [unsafe.Sizeof(Error{})]byte +} diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/empty.s b/v2/internal/fermyon/spin/v2.0.0/variables/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go new file mode 100644 index 0000000..bb51cc5 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go @@ -0,0 +1,87 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package variables represents the imported interface "fermyon:spin/variables@2.0.0". +package variables + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Error represents the variant "fermyon:spin/variables@2.0.0#error". +// +// The set of errors which may be raised by functions in this interface. +// +// variant error { +// invalid-name(string), +// undefined(string), +// provider(string), +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorInvalidName returns a [Error] of case "invalid-name". +// +// The provided variable name is invalid. +func ErrorInvalidName(data string) Error { + return cm.New[Error](0, data) +} + +// InvalidName returns a non-nil *[string] if [Error] represents the variant case "invalid-name". +func (self *Error) InvalidName() *string { + return cm.Case[string](self, 0) +} + +// ErrorUndefined returns a [Error] of case "undefined". +// +// The provided variable is undefined. +func ErrorUndefined(data string) Error { + return cm.New[Error](1, data) +} + +// Undefined returns a non-nil *[string] if [Error] represents the variant case "undefined". +func (self *Error) Undefined() *string { + return cm.Case[string](self, 1) +} + +// ErrorProvider returns a [Error] of case "provider". +// +// A variables provider specific error has occurred. +func ErrorProvider(data string) Error { + return cm.New[Error](2, data) +} + +// Provider returns a non-nil *[string] if [Error] represents the variant case "provider". +func (self *Error) Provider() *string { + return cm.Case[string](self, 2) +} + +// ErrorOther returns a [Error] of case "other". +// +// Some implementation-specific error has occurred. +func ErrorOther(data string) Error { + return cm.New[Error](3, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 3) +} + +// Get represents the imported function "get". +// +// Get an application variable value for the current component. +// +// The name must match one defined in in the component manifest. +// +// get: func(name: string) -> result +// +//go:nosplit +func Get(name string) (result cm.Result[ErrorShape, string, Error]) { + name0, name1 := cm.LowerString(name) + wasmimport_Get((*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport fermyon:spin/variables@2.0.0 get +//go:noescape +func wasmimport_Get(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/wasi/cli/v0.2.0/environment/empty.s b/v2/internal/wasi/cli/v0.2.0/environment/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/environment/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go new file mode 100644 index 0000000..a582bdf --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go @@ -0,0 +1,64 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package environment represents the imported interface "wasi:cli/environment@0.2.0". +package environment + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetEnvironment represents the imported function "get-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> +// +//go:nosplit +func GetEnvironment() (result cm.List[[2]string]) { + wasmimport_GetEnvironment(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.0 get-environment +//go:noescape +func wasmimport_GetEnvironment(result *cm.List[[2]string]) + +// GetArguments represents the imported function "get-arguments". +// +// Get the POSIX-style arguments to the program. +// +// get-arguments: func() -> list +// +//go:nosplit +func GetArguments() (result cm.List[string]) { + wasmimport_GetArguments(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +//go:noescape +func wasmimport_GetArguments(result *cm.List[string]) + +// InitialCWD represents the imported function "initial-cwd". +// +// Return a path that programs should use as their initial current working +// directory, interpreting `.` as shorthand for this. +// +// initial-cwd: func() -> option +// +//go:nosplit +func InitialCWD() (result cm.Option[string]) { + wasmimport_InitialCWD(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd +//go:noescape +func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/v2/internal/wasi/cli/v0.2.0/exit/empty.s b/v2/internal/wasi/cli/v0.2.0/exit/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/exit/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go new file mode 100644 index 0000000..bf46d1b --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package exit represents the imported interface "wasi:cli/exit@0.2.0". +package exit + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Exit represents the imported function "exit". +// +// Exit the current instance and any linked instances. +// +// exit: func(status: result) +// +//go:nosplit +func Exit(status cm.BoolResult) { + status0 := cm.BoolToU32(status) + wasmimport_Exit((uint32)(status0)) + return +} + +//go:wasmimport wasi:cli/exit@0.2.0 exit +//go:noescape +func wasmimport_Exit(status0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/empty.s b/v2/internal/wasi/cli/v0.2.0/stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stderr/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go new file mode 100644 index 0000000..2fefd03 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stderr represents the imported interface "wasi:cli/stderr@0.2.0". +package stderr + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetStderr represents the imported function "get-stderr". +// +// get-stderr: func() -> output-stream +// +//go:nosplit +func GetStderr() (result streams.OutputStream) { + result0 := wasmimport_GetStderr() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr +//go:noescape +func wasmimport_GetStderr() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/empty.s b/v2/internal/wasi/cli/v0.2.0/stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdin/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go new file mode 100644 index 0000000..532179a --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stdin represents the imported interface "wasi:cli/stdin@0.2.0". +package stdin + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetStdin represents the imported function "get-stdin". +// +// get-stdin: func() -> input-stream +// +//go:nosplit +func GetStdin() (result streams.InputStream) { + result0 := wasmimport_GetStdin() + result = cm.Reinterpret[streams.InputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin +//go:noescape +func wasmimport_GetStdin() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/empty.s b/v2/internal/wasi/cli/v0.2.0/stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdout/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go new file mode 100644 index 0000000..d2a4ef5 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package stdout represents the imported interface "wasi:cli/stdout@0.2.0". +package stdout + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetStdout represents the imported function "get-stdout". +// +// get-stdout: func() -> output-stream +// +//go:nosplit +func GetStdout() (result streams.OutputStream) { + result0 := wasmimport_GetStdout() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return +} + +//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout +//go:noescape +func wasmimport_GetStdout() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go new file mode 100644 index 0000000..9dca7df --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go @@ -0,0 +1,36 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.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. +package terminalinput + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". +// +// The input side of a terminal. +// +// resource terminal-input +type TerminalInput cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "terminal-input". +// +// Drops a resource handle. +// +//go:nosplit +func (self TerminalInput) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalInputResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input +//go:noescape +func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go new file mode 100644 index 0000000..b6ff728 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go @@ -0,0 +1,36 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.0". +// +// 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. +package terminaloutput + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". +// +// The output side of a terminal. +// +// resource terminal-output +type TerminalOutput cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "terminal-output". +// +// Drops a resource handle. +// +//go:nosplit +func (self TerminalOutput) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalOutputResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output +//go:noescape +func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go new file mode 100644 index 0000000..4ce0f21 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.0". +// +// An interface providing an optional `terminal-output` for stderr as a +// link-time authority. +package terminalstderr + +import ( + terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetTerminalStderr represents the imported function "get-terminal-stderr". +// +// If stderr is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +// +// get-terminal-stderr: func() -> option +// +//go:nosplit +func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { + wasmimport_GetTerminalStderr(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr +//go:noescape +func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go new file mode 100644 index 0000000..486a0b0 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.0". +// +// An interface providing an optional `terminal-input` for stdin as a +// link-time authority. +package terminalstdin + +import ( + terminalinput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetTerminalStdin represents the imported function "get-terminal-stdin". +// +// If stdin is connected to a terminal, return a `terminal-input` handle +// allowing further interaction with it. +// +// get-terminal-stdin: func() -> option +// +//go:nosplit +func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { + wasmimport_GetTerminalStdin(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin +//go:noescape +func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go new file mode 100644 index 0000000..f6b5cbc --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.0". +// +// An interface providing an optional `terminal-output` for stdout as a +// link-time authority. +package terminalstdout + +import ( + terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetTerminalStdout represents the imported function "get-terminal-stdout". +// +// If stdout is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +// +// get-terminal-stdout: func() -> option +// +//go:nosplit +func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { + wasmimport_GetTerminalStdout(&result) + return +} + +//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout +//go:noescape +func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go new file mode 100644 index 0000000..b168d28 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -0,0 +1,113 @@ +// 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 ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 +func Now() (result Instant) { + result0 := wasmimport_Now() + result = (Instant)((uint64)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now +//go:noescape +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 +func Resolution() (result Duration) { + result0 := wasmimport_Resolution() + result = (Duration)((uint64)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution +//go:noescape +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 +func SubscribeInstant(when Instant) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeInstant((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +//go:noescape +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 +func SubscribeDuration(when Duration) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeDuration((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +//go:noescape +func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s b/v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go new file mode 100644 index 0000000..a59a313 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go @@ -0,0 +1,78 @@ +// 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 + +// 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 { + 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) + return +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 now +//go:noescape +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 +func Resolution() (result DateTime) { + wasmimport_Resolution(&result) + return +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution +//go:noescape +func wasmimport_Resolution(result *DateTime) diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s b/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go new file mode 100644 index 0000000..dc09813 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.0". +package preopens + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// GetDirectories represents the imported function "get-directories". +// +// Return the set of preopened directories, and their path. +// +// get-directories: func() -> list> +// +//go:nosplit +func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { + wasmimport_GetDirectories(&result) + return +} + +//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories +//go:noescape +func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go new file mode 100644 index 0000000..2f5edfa --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -0,0 +1,51 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// DateTimeShape is used for storage in variant or result types. +type DateTimeShape struct { + shape [unsafe.Sizeof(wallclock.DateTime{})]byte +} + +// MetadataHashValueShape is used for storage in variant or result types. +type MetadataHashValueShape struct { + shape [unsafe.Sizeof(MetadataHashValue{})]byte +} + +// TupleListU8BoolShape is used for storage in variant or result types. +type TupleListU8BoolShape struct { + shape [unsafe.Sizeof(cm.Tuple[cm.List[uint8], bool]{})]byte +} + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} + +func lower_NewTimestamp(v NewTimestamp) (f0 uint32, f1 uint64, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 2: // timestamp + v1, v2 := lower_DateTime(*v.Timestamp()) + f1 = (uint64)(v1) + f2 = (uint32)(v2) + } + return +} + +// DescriptorStatShape is used for storage in variant or result types. +type DescriptorStatShape struct { + shape [unsafe.Sizeof(DescriptorStat{})]byte +} + +// OptionDirectoryEntryShape is used for storage in variant or result types. +type OptionDirectoryEntryShape struct { + shape [unsafe.Sizeof(cm.Option[DirectoryEntry]{})]byte +} diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/empty.s b/v2/internal/wasi/filesystem/v0.2.0/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go new file mode 100644 index 0000000..11f0d2c --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -0,0 +1,1357 @@ +// 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 ( + wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" + ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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, +// character-device, +// directory, +// fifo, +// symbolic-link, +// regular-file, +// socket +// } +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 +) + +var stringsDescriptorType = [8]string{ + "unknown", + "block-device", + "character-device", + "directory", + "fifo", + "symbolic-link", + "regular-file", + "socket", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e DescriptorType) String() string { + return stringsDescriptorType[e] +} + +// 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, +// file-integrity-sync, +// data-integrity-sync, +// requested-write-sync, +// mutate-directory, +// } +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, +// exclusive, +// truncate, +// } +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, +// size: filesize, +// data-access-timestamp: option, +// data-modification-timestamp: option, +// 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. + 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] +} + +// 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, +// timestamp(datetime), +// } +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) +} + +// NoChange returns true if [NewTimestamp] represents the variant case "no-change". +func (self *NewTimestamp) NoChange() bool { + return self.Tag() == 0 +} + +// 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) +} + +// Now returns true if [NewTimestamp] represents the variant case "now". +func (self *NewTimestamp) Now() bool { + return self.Tag() == 1 +} + +// 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) +} + +// Timestamp returns a non-nil *[wallclock.DateTime] if [NewTimestamp] represents the variant case "timestamp". +func (self *NewTimestamp) Timestamp() *wallclock.DateTime { + return cm.Case[wallclock.DateTime](self, 2) +} + +// 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. + 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, +// 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 +// } +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 +) + +var stringsErrorCode = [37]string{ + "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", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ErrorCode) String() string { + return stringsErrorCode[e] +} + +// Advice represents the enum "wasi:filesystem/types@0.2.0#advice". +// +// File or memory access pattern advisory information. +// +// enum advice { +// normal, +// sequential, +// random, +// will-need, +// dont-need, +// no-reuse +// } +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 +) + +var stringsAdvice = [6]string{ + "normal", + "sequential", + "random", + "will-need", + "dont-need", + "no-reuse", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Advice) String() string { + return stringsAdvice[e] +} + +// 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. + 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 + +// ResourceDrop represents the imported resource-drop for resource "descriptor". +// +// Drops a resource handle. +// +//go:nosplit +func (self Descriptor) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor +//go:noescape +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 +func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + length0 := (uint64)(length) + advice0 := (uint32)(advice) + wasmimport_DescriptorAdvise((uint32)(self0), (uint64)(offset0), (uint64)(length0), (uint32)(advice0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise +//go:noescape +func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) AppendViaStream() (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream +//go:noescape +func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) + +// 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 +func (self Descriptor) CreateDirectoryAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorCreateDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at +//go:noescape +func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) GetFlags() (result cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetFlags((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags +//go:noescape +func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) + +// 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 +func (self Descriptor) GetType() (result cm.Result[DescriptorType, DescriptorType, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetType((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type +//go:noescape +func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) + +// 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 +func (self Descriptor) IsSameObject(other Descriptor) (result bool) { + self0 := cm.Reinterpret[uint32](self) + other0 := cm.Reinterpret[uint32](other) + result0 := wasmimport_DescriptorIsSameObject((uint32)(self0), (uint32)(other0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object +//go:noescape +func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) + +// 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> +// +//go:nosplit +func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor Descriptor, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPathFlags0 := (uint32)(oldPathFlags) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorLinkAt((uint32)(self0), (uint32)(oldPathFlags0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +//go:noescape +func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) MetadataHash() (result cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorMetadataHash((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +//go:noescape +func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +// 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 +// +//go:nosplit +func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorMetadataHashAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at +//go:noescape +func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +// 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 +// +//go:nosplit +func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) (result cm.Result[Descriptor, Descriptor, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + openFlags0 := (uint32)(openFlags) + flags0 := (uint32)(flags) + wasmimport_DescriptorOpenAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(openFlags0), (uint32)(flags0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at +//go:noescape +func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) + +// 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> +// +//go:nosplit +func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + length0 := (uint64)(length) + offset0 := (uint64)(offset) + wasmimport_DescriptorRead((uint32)(self0), (uint64)(length0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +//go:noescape +func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) + +// 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 +func (self Descriptor) ReadDirectory() (result cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorReadDirectory((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +//go:noescape +func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) + +// 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 +func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +//go:noescape +func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) + +// 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 +func (self Descriptor) ReadLinkAt(path string) (result cm.Result[string, string, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorReadLinkAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +//go:noescape +func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) + +// 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 +func (self Descriptor) RemoveDirectoryAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorRemoveDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +//go:noescape +func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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> +// +//go:nosplit +func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorRenameAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +//go:noescape +func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) SetSize(size FileSize) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + size0 := (uint64)(size) + wasmimport_DescriptorSetSize((uint32)(self0), (uint64)(size0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +//go:noescape +func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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> +// +//go:nosplit +func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimes((uint32)(self0), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +//go:noescape +func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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> +// +//go:nosplit +func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimesAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +//go:noescape +func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) Stat() (result cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorStat((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +//go:noescape +func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +// 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 +// +//go:nosplit +func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorStatAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:noescape +func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +// 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 +func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorSymlinkAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:noescape +func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) Sync() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSync((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:noescape +func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) SyncData() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSyncData((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:noescape +func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) UnlinkFileAt(path string) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorUnlinkFileAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:noescape +func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// 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 +func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm.Result[uint64, FileSize, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + buffer0, buffer1 := cm.LowerList(buffer) + offset0 := (uint64)(offset) + wasmimport_DescriptorWrite((uint32)(self0), (*uint8)(buffer0), (uint32)(buffer1), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:noescape +func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) + +// 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 +func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:noescape +func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "directory-entry-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self DirectoryEntryStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:noescape +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 +func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamReadDirectoryEntry((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:noescape +func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) + +// 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 +func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_FilesystemErrorCode((uint32)(err0), &result) + return +} + +//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code +//go:noescape +func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s b/v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go new file mode 100644 index 0000000..c3ea0ca --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go @@ -0,0 +1,26 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package incominghandler + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" +) + +// Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.0". +var Exports struct { + // Handle represents the caller-defined, exported function "handle". + // + // 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) + Handle func(request types.IncomingRequest, responseOut types.ResponseOutparam) +} diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go new file mode 100644 index 0000000..4c0505f --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package incominghandler represents the exported interface "wasi:http/incoming-handler@0.2.0". +// +// This interface defines a handler of incoming HTTP Requests. It should +// be exported by components which can respond to HTTP Requests. +package incominghandler + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +//go:wasmexport wasi:http/incoming-handler@0.2.0#handle +//export wasi:http/incoming-handler@0.2.0#handle +func wasmexport_Handle(request0 uint32, responseOut0 uint32) { + request := cm.Reinterpret[types.IncomingRequest]((uint32)(request0)) + responseOut := cm.Reinterpret[types.ResponseOutparam]((uint32)(responseOut0)) + Exports.Handle(request, responseOut) + return +} diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go new file mode 100644 index 0000000..a0a35d9 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go @@ -0,0 +1,24 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package outgoinghandler + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// ErrorCodeShape is used for storage in variant or result types. +type ErrorCodeShape struct { + shape [unsafe.Sizeof(types.ErrorCode{})]byte +} + +func lower_OptionRequestOptions(v cm.Option[types.RequestOptions]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := cm.Reinterpret[uint32](*some) + f1 = (uint32)(v1) + } + return +} diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s b/v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go new file mode 100644 index 0000000..1945bc0 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go @@ -0,0 +1,40 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package outgoinghandler represents the imported interface "wasi:http/outgoing-handler@0.2.0". +// +// This interface defines a handler of outgoing HTTP Requests. It should be +// imported by components which wish to make HTTP Requests. +package outgoinghandler + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Handle represents the imported function "handle". +// +// 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 +// +//go:nosplit +func Handle(request types.OutgoingRequest, options cm.Option[types.RequestOptions]) (result cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) { + request0 := cm.Reinterpret[uint32](request) + options0, options1 := lower_OptionRequestOptions(options) + wasmimport_Handle((uint32)(request0), (uint32)(options0), (uint32)(options1), &result) + return +} + +//go:wasmimport wasi:http/outgoing-handler@0.2.0 handle +//go:noescape +func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/types/abi.go b/v2/internal/wasi/http/v0.2.0/types/abi.go new file mode 100644 index 0000000..ff37570 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/abi.go @@ -0,0 +1,273 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// OptionFieldSizePayloadShape is used for storage in variant or result types. +type OptionFieldSizePayloadShape struct { + shape [unsafe.Sizeof(cm.Option[FieldSizePayload]{})]byte +} + +func lower_OptionString(v cm.Option[string]) (f0 uint32, f1 *uint8, f2 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2 := cm.LowerString(*some) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_Method(v Method) (f0 uint32, f1 *uint8, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 9: // other + v1, v2 := cm.LowerString(*v.Other()) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_Scheme(v Scheme) (f0 uint32, f1 *uint8, f2 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 2: // other + v1, v2 := cm.LowerString(*v.Other()) + f1 = (*uint8)(v1) + f2 = (uint32)(v2) + } + return +} + +func lower_OptionScheme(v cm.Option[Scheme]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3 := lower_Scheme(*some) + f1 = (uint32)(v1) + f2 = (*uint8)(v2) + f3 = (uint32)(v3) + } + return +} + +func lower_OptionDuration(v cm.Option[monotonicclock.Duration]) (f0 uint32, f1 uint64) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint64)(*some) + f1 = (uint64)(v1) + } + return +} + +// ErrorCodeShape is used for storage in variant or result types. +type ErrorCodeShape struct { + shape [unsafe.Sizeof(ErrorCode{})]byte +} + +func lower_OptionU16(v cm.Option[uint16]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_DNSErrorPayload(v DNSErrorPayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { + f0, f1, f2 = lower_OptionString(v.Rcode) + f3, f4 = lower_OptionU16(v.InfoCode) + return +} + +func lower_OptionU8(v cm.Option[uint8]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_TLSAlertReceivedPayload(v TLSAlertReceivedPayload) (f0 uint32, f1 uint32, f2 uint32, f3 *uint8, f4 uint32) { + f0, f1 = lower_OptionU8(v.AlertID) + f2, f3, f4 = lower_OptionString(v.AlertMessage) + return +} + +func lower_OptionU64(v cm.Option[uint64]) (f0 uint32, f1 uint64) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint64)(*some) + f1 = (uint64)(v1) + } + return +} + +func lower_OptionU32(v cm.Option[uint32]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := (uint32)(*some) + f1 = (uint32)(v1) + } + return +} + +func lower_FieldSizePayload(v FieldSizePayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { + f0, f1, f2 = lower_OptionString(v.FieldName) + f3, f4 = lower_OptionU32(v.FieldSize) + return +} + +func lower_OptionFieldSizePayload(v cm.Option[FieldSizePayload]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32, f4 uint32, f5 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*some) + f1 = (uint32)(v1) + f2 = (*uint8)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + } + return +} + +func lower_ErrorCode(v ErrorCode) (f0 uint32, f1 uint32, f2 uint64, f3 uint32, f4 uint32, f5 uint32, f6 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 1: // DNS-error + v1, v2, v3, v4, v5 := lower_DNSErrorPayload(*v.DNSError()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 14: // TLS-alert-received + v1, v2, v3, v4, v5 := lower_TLSAlertReceivedPayload(*v.TLSAlertReceived()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + f3 = (uint32)(v3) + f4 = cm.PointerToU32(v4) + f5 = (uint32)(v5) + case 17: // HTTP-request-body-size + v1, v2 := lower_OptionU64(*v.HTTPRequestBodySize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 21: // HTTP-request-header-section-size + v1, v2 := lower_OptionU32(*v.HTTPRequestHeaderSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 22: // HTTP-request-header-size + v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*v.HTTPRequestHeaderSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + f3 = cm.PointerToU32(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + case 23: // HTTP-request-trailer-section-size + v1, v2 := lower_OptionU32(*v.HTTPRequestTrailerSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 24: // HTTP-request-trailer-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPRequestTrailerSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 26: // HTTP-response-header-section-size + v1, v2 := lower_OptionU32(*v.HTTPResponseHeaderSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 27: // HTTP-response-header-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseHeaderSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 28: // HTTP-response-body-size + v1, v2 := lower_OptionU64(*v.HTTPResponseBodySize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 29: // HTTP-response-trailer-section-size + v1, v2 := lower_OptionU32(*v.HTTPResponseTrailerSectionSize()) + f1 = (uint32)(v1) + f2 = (uint64)(v2) + case 30: // HTTP-response-trailer-size + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseTrailerSize()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 31: // HTTP-response-transfer-coding + v1, v2, v3 := lower_OptionString(*v.HTTPResponseTransferCoding()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + case 32: // HTTP-response-content-coding + v1, v2, v3 := lower_OptionString(*v.HTTPResponseContentCoding()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + case 38: // internal-error + v1, v2, v3 := lower_OptionString(*v.InternalError()) + f1 = (uint32)(v1) + f2 = cm.PointerToU64(v2) + f3 = (uint32)(v3) + } + return +} + +func lower_ResultOutgoingResponseErrorCode(v cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) (f0 uint32, f1 uint32, f2 uint32, f3 uint64, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + if v.IsOK() { + v1 := cm.Reinterpret[uint32](*v.OK()) + f1 = (uint32)(v1) + } else { + f0 = 1 + v1, v2, v3, v4, v5, v6, v7 := lower_ErrorCode(*v.Err()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint64)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + } + return +} + +// ResultOptionTrailersErrorCodeShape is used for storage in variant or result types. +type ResultOptionTrailersErrorCodeShape struct { + shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode]{})]byte +} + +func lower_OptionTrailers(v cm.Option[Fields]) (f0 uint32, f1 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1 := cm.Reinterpret[uint32](*some) + f1 = (uint32)(v1) + } + return +} + +// ResultIncomingResponseErrorCodeShape is used for storage in variant or result types. +type ResultIncomingResponseErrorCodeShape struct { + shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode]{})]byte +} diff --git a/v2/internal/wasi/http/v0.2.0/types/empty.s b/v2/internal/wasi/http/v0.2.0/types/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wit.go b/v2/internal/wasi/http/v0.2.0/types/types.wit.go new file mode 100644 index 0000000..7e8d905 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/types.wit.go @@ -0,0 +1,2141 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package types represents the imported interface "wasi:http/types@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. +package types + +import ( + monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" + ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +// Method represents the variant "wasi:http/types@0.2.0#method". +// +// This type corresponds to HTTP standard Methods. +// +// variant method { +// get, +// head, +// post, +// put, +// delete, +// connect, +// options, +// trace, +// patch, +// other(string), +// } +type Method cm.Variant[uint8, string, string] + +// MethodGet returns a [Method] of case "get". +func MethodGet() Method { + var data struct{} + return cm.New[Method](0, data) +} + +// Get returns true if [Method] represents the variant case "get". +func (self *Method) Get() bool { + return self.Tag() == 0 +} + +// MethodHead returns a [Method] of case "head". +func MethodHead() Method { + var data struct{} + return cm.New[Method](1, data) +} + +// Head returns true if [Method] represents the variant case "head". +func (self *Method) Head() bool { + return self.Tag() == 1 +} + +// MethodPost returns a [Method] of case "post". +func MethodPost() Method { + var data struct{} + return cm.New[Method](2, data) +} + +// Post returns true if [Method] represents the variant case "post". +func (self *Method) Post() bool { + return self.Tag() == 2 +} + +// MethodPut returns a [Method] of case "put". +func MethodPut() Method { + var data struct{} + return cm.New[Method](3, data) +} + +// Put returns true if [Method] represents the variant case "put". +func (self *Method) Put() bool { + return self.Tag() == 3 +} + +// MethodDelete returns a [Method] of case "delete". +func MethodDelete() Method { + var data struct{} + return cm.New[Method](4, data) +} + +// Delete returns true if [Method] represents the variant case "delete". +func (self *Method) Delete() bool { + return self.Tag() == 4 +} + +// MethodConnect returns a [Method] of case "connect". +func MethodConnect() Method { + var data struct{} + return cm.New[Method](5, data) +} + +// Connect returns true if [Method] represents the variant case "connect". +func (self *Method) Connect() bool { + return self.Tag() == 5 +} + +// MethodOptions returns a [Method] of case "options". +func MethodOptions() Method { + var data struct{} + return cm.New[Method](6, data) +} + +// Options returns true if [Method] represents the variant case "options". +func (self *Method) Options() bool { + return self.Tag() == 6 +} + +// MethodTrace returns a [Method] of case "trace". +func MethodTrace() Method { + var data struct{} + return cm.New[Method](7, data) +} + +// Trace returns true if [Method] represents the variant case "trace". +func (self *Method) Trace() bool { + return self.Tag() == 7 +} + +// MethodPatch returns a [Method] of case "patch". +func MethodPatch() Method { + var data struct{} + return cm.New[Method](8, data) +} + +// Patch returns true if [Method] represents the variant case "patch". +func (self *Method) Patch() bool { + return self.Tag() == 8 +} + +// MethodOther returns a [Method] of case "other". +func MethodOther(data string) Method { + return cm.New[Method](9, data) +} + +// Other returns a non-nil *[string] if [Method] represents the variant case "other". +func (self *Method) Other() *string { + return cm.Case[string](self, 9) +} + +// Scheme represents the variant "wasi:http/types@0.2.0#scheme". +// +// This type corresponds to HTTP standard Related Schemes. +// +// variant scheme { +// HTTP, +// HTTPS, +// other(string), +// } +type Scheme cm.Variant[uint8, string, string] + +// SchemeHTTP returns a [Scheme] of case "HTTP". +func SchemeHTTP() Scheme { + var data struct{} + return cm.New[Scheme](0, data) +} + +// HTTP returns true if [Scheme] represents the variant case "HTTP". +func (self *Scheme) HTTP() bool { + return self.Tag() == 0 +} + +// SchemeHTTPS returns a [Scheme] of case "HTTPS". +func SchemeHTTPS() Scheme { + var data struct{} + return cm.New[Scheme](1, data) +} + +// HTTPS returns true if [Scheme] represents the variant case "HTTPS". +func (self *Scheme) HTTPS() bool { + return self.Tag() == 1 +} + +// SchemeOther returns a [Scheme] of case "other". +func SchemeOther(data string) Scheme { + return cm.New[Scheme](2, data) +} + +// Other returns a non-nil *[string] if [Scheme] represents the variant case "other". +func (self *Scheme) Other() *string { + return cm.Case[string](self, 2) +} + +// DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". +// +// Defines the case payload type for `DNS-error` above: +// +// record DNS-error-payload { +// rcode: option, +// info-code: option, +// } +type DNSErrorPayload struct { + Rcode cm.Option[string] + InfoCode cm.Option[uint16] +} + +// TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.0#TLS-alert-received-payload". +// +// Defines the case payload type for `TLS-alert-received` above: +// +// record TLS-alert-received-payload { +// alert-id: option, +// alert-message: option, +// } +type TLSAlertReceivedPayload struct { + AlertID cm.Option[uint8] + AlertMessage cm.Option[string] +} + +// FieldSizePayload represents the record "wasi:http/types@0.2.0#field-size-payload". +// +// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: +// +// record field-size-payload { +// field-name: option, +// field-size: option, +// } +type FieldSizePayload struct { + FieldName cm.Option[string] + FieldSize cm.Option[uint32] +} + +// ErrorCode represents the variant "wasi:http/types@0.2.0#error-code". +// +// 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 +// +// variant error-code { +// DNS-timeout, +// DNS-error(DNS-error-payload), +// destination-not-found, +// destination-unavailable, +// destination-IP-prohibited, +// destination-IP-unroutable, +// connection-refused, +// connection-terminated, +// connection-timeout, +// connection-read-timeout, +// connection-write-timeout, +// connection-limit-reached, +// TLS-protocol-error, +// TLS-certificate-error, +// TLS-alert-received(TLS-alert-received-payload), +// HTTP-request-denied, +// HTTP-request-length-required, +// HTTP-request-body-size(option), +// HTTP-request-method-invalid, +// HTTP-request-URI-invalid, +// HTTP-request-URI-too-long, +// HTTP-request-header-section-size(option), +// HTTP-request-header-size(option), +// HTTP-request-trailer-section-size(option), +// HTTP-request-trailer-size(field-size-payload), +// HTTP-response-incomplete, +// HTTP-response-header-section-size(option), +// HTTP-response-header-size(field-size-payload), +// HTTP-response-body-size(option), +// HTTP-response-trailer-section-size(option), +// HTTP-response-trailer-size(field-size-payload), +// HTTP-response-transfer-coding(option), +// HTTP-response-content-coding(option), +// HTTP-response-timeout, +// HTTP-upgrade-failed, +// HTTP-protocol-error, +// loop-detected, +// configuration-error, +// internal-error(option), +// } +type ErrorCode cm.Variant[uint8, OptionFieldSizePayloadShape, cm.Option[uint64]] + +// ErrorCodeDNSTimeout returns a [ErrorCode] of case "DNS-timeout". +func ErrorCodeDNSTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](0, data) +} + +// DNSTimeout returns true if [ErrorCode] represents the variant case "DNS-timeout". +func (self *ErrorCode) DNSTimeout() bool { + return self.Tag() == 0 +} + +// ErrorCodeDNSError returns a [ErrorCode] of case "DNS-error". +func ErrorCodeDNSError(data DNSErrorPayload) ErrorCode { + return cm.New[ErrorCode](1, data) +} + +// DNSError returns a non-nil *[DNSErrorPayload] if [ErrorCode] represents the variant case "DNS-error". +func (self *ErrorCode) DNSError() *DNSErrorPayload { + return cm.Case[DNSErrorPayload](self, 1) +} + +// ErrorCodeDestinationNotFound returns a [ErrorCode] of case "destination-not-found". +func ErrorCodeDestinationNotFound() ErrorCode { + var data struct{} + return cm.New[ErrorCode](2, data) +} + +// DestinationNotFound returns true if [ErrorCode] represents the variant case "destination-not-found". +func (self *ErrorCode) DestinationNotFound() bool { + return self.Tag() == 2 +} + +// ErrorCodeDestinationUnavailable returns a [ErrorCode] of case "destination-unavailable". +func ErrorCodeDestinationUnavailable() ErrorCode { + var data struct{} + return cm.New[ErrorCode](3, data) +} + +// DestinationUnavailable returns true if [ErrorCode] represents the variant case "destination-unavailable". +func (self *ErrorCode) DestinationUnavailable() bool { + return self.Tag() == 3 +} + +// ErrorCodeDestinationIPProhibited returns a [ErrorCode] of case "destination-IP-prohibited". +func ErrorCodeDestinationIPProhibited() ErrorCode { + var data struct{} + return cm.New[ErrorCode](4, data) +} + +// DestinationIPProhibited returns true if [ErrorCode] represents the variant case "destination-IP-prohibited". +func (self *ErrorCode) DestinationIPProhibited() bool { + return self.Tag() == 4 +} + +// ErrorCodeDestinationIPUnroutable returns a [ErrorCode] of case "destination-IP-unroutable". +func ErrorCodeDestinationIPUnroutable() ErrorCode { + var data struct{} + return cm.New[ErrorCode](5, data) +} + +// DestinationIPUnroutable returns true if [ErrorCode] represents the variant case "destination-IP-unroutable". +func (self *ErrorCode) DestinationIPUnroutable() bool { + return self.Tag() == 5 +} + +// ErrorCodeConnectionRefused returns a [ErrorCode] of case "connection-refused". +func ErrorCodeConnectionRefused() ErrorCode { + var data struct{} + return cm.New[ErrorCode](6, data) +} + +// ConnectionRefused returns true if [ErrorCode] represents the variant case "connection-refused". +func (self *ErrorCode) ConnectionRefused() bool { + return self.Tag() == 6 +} + +// ErrorCodeConnectionTerminated returns a [ErrorCode] of case "connection-terminated". +func ErrorCodeConnectionTerminated() ErrorCode { + var data struct{} + return cm.New[ErrorCode](7, data) +} + +// ConnectionTerminated returns true if [ErrorCode] represents the variant case "connection-terminated". +func (self *ErrorCode) ConnectionTerminated() bool { + return self.Tag() == 7 +} + +// ErrorCodeConnectionTimeout returns a [ErrorCode] of case "connection-timeout". +func ErrorCodeConnectionTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](8, data) +} + +// ConnectionTimeout returns true if [ErrorCode] represents the variant case "connection-timeout". +func (self *ErrorCode) ConnectionTimeout() bool { + return self.Tag() == 8 +} + +// ErrorCodeConnectionReadTimeout returns a [ErrorCode] of case "connection-read-timeout". +func ErrorCodeConnectionReadTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](9, data) +} + +// ConnectionReadTimeout returns true if [ErrorCode] represents the variant case "connection-read-timeout". +func (self *ErrorCode) ConnectionReadTimeout() bool { + return self.Tag() == 9 +} + +// ErrorCodeConnectionWriteTimeout returns a [ErrorCode] of case "connection-write-timeout". +func ErrorCodeConnectionWriteTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](10, data) +} + +// ConnectionWriteTimeout returns true if [ErrorCode] represents the variant case "connection-write-timeout". +func (self *ErrorCode) ConnectionWriteTimeout() bool { + return self.Tag() == 10 +} + +// ErrorCodeConnectionLimitReached returns a [ErrorCode] of case "connection-limit-reached". +func ErrorCodeConnectionLimitReached() ErrorCode { + var data struct{} + return cm.New[ErrorCode](11, data) +} + +// ConnectionLimitReached returns true if [ErrorCode] represents the variant case "connection-limit-reached". +func (self *ErrorCode) ConnectionLimitReached() bool { + return self.Tag() == 11 +} + +// ErrorCodeTLSProtocolError returns a [ErrorCode] of case "TLS-protocol-error". +func ErrorCodeTLSProtocolError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](12, data) +} + +// TLSProtocolError returns true if [ErrorCode] represents the variant case "TLS-protocol-error". +func (self *ErrorCode) TLSProtocolError() bool { + return self.Tag() == 12 +} + +// ErrorCodeTLSCertificateError returns a [ErrorCode] of case "TLS-certificate-error". +func ErrorCodeTLSCertificateError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](13, data) +} + +// TLSCertificateError returns true if [ErrorCode] represents the variant case "TLS-certificate-error". +func (self *ErrorCode) TLSCertificateError() bool { + return self.Tag() == 13 +} + +// ErrorCodeTLSAlertReceived returns a [ErrorCode] of case "TLS-alert-received". +func ErrorCodeTLSAlertReceived(data TLSAlertReceivedPayload) ErrorCode { + return cm.New[ErrorCode](14, data) +} + +// TLSAlertReceived returns a non-nil *[TLSAlertReceivedPayload] if [ErrorCode] represents the variant case "TLS-alert-received". +func (self *ErrorCode) TLSAlertReceived() *TLSAlertReceivedPayload { + return cm.Case[TLSAlertReceivedPayload](self, 14) +} + +// ErrorCodeHTTPRequestDenied returns a [ErrorCode] of case "HTTP-request-denied". +func ErrorCodeHTTPRequestDenied() ErrorCode { + var data struct{} + return cm.New[ErrorCode](15, data) +} + +// HTTPRequestDenied returns true if [ErrorCode] represents the variant case "HTTP-request-denied". +func (self *ErrorCode) HTTPRequestDenied() bool { + return self.Tag() == 15 +} + +// ErrorCodeHTTPRequestLengthRequired returns a [ErrorCode] of case "HTTP-request-length-required". +func ErrorCodeHTTPRequestLengthRequired() ErrorCode { + var data struct{} + return cm.New[ErrorCode](16, data) +} + +// HTTPRequestLengthRequired returns true if [ErrorCode] represents the variant case "HTTP-request-length-required". +func (self *ErrorCode) HTTPRequestLengthRequired() bool { + return self.Tag() == 16 +} + +// ErrorCodeHTTPRequestBodySize returns a [ErrorCode] of case "HTTP-request-body-size". +func ErrorCodeHTTPRequestBodySize(data cm.Option[uint64]) ErrorCode { + return cm.New[ErrorCode](17, data) +} + +// HTTPRequestBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-request-body-size". +func (self *ErrorCode) HTTPRequestBodySize() *cm.Option[uint64] { + return cm.Case[cm.Option[uint64]](self, 17) +} + +// ErrorCodeHTTPRequestMethodInvalid returns a [ErrorCode] of case "HTTP-request-method-invalid". +func ErrorCodeHTTPRequestMethodInvalid() ErrorCode { + var data struct{} + return cm.New[ErrorCode](18, data) +} + +// HTTPRequestMethodInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-method-invalid". +func (self *ErrorCode) HTTPRequestMethodInvalid() bool { + return self.Tag() == 18 +} + +// ErrorCodeHTTPRequestURIInvalid returns a [ErrorCode] of case "HTTP-request-URI-invalid". +func ErrorCodeHTTPRequestURIInvalid() ErrorCode { + var data struct{} + return cm.New[ErrorCode](19, data) +} + +// HTTPRequestURIInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-URI-invalid". +func (self *ErrorCode) HTTPRequestURIInvalid() bool { + return self.Tag() == 19 +} + +// ErrorCodeHTTPRequestURITooLong returns a [ErrorCode] of case "HTTP-request-URI-too-long". +func ErrorCodeHTTPRequestURITooLong() ErrorCode { + var data struct{} + return cm.New[ErrorCode](20, data) +} + +// HTTPRequestURITooLong returns true if [ErrorCode] represents the variant case "HTTP-request-URI-too-long". +func (self *ErrorCode) HTTPRequestURITooLong() bool { + return self.Tag() == 20 +} + +// ErrorCodeHTTPRequestHeaderSectionSize returns a [ErrorCode] of case "HTTP-request-header-section-size". +func ErrorCodeHTTPRequestHeaderSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](21, data) +} + +// HTTPRequestHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-header-section-size". +func (self *ErrorCode) HTTPRequestHeaderSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 21) +} + +// ErrorCodeHTTPRequestHeaderSize returns a [ErrorCode] of case "HTTP-request-header-size". +func ErrorCodeHTTPRequestHeaderSize(data cm.Option[FieldSizePayload]) ErrorCode { + return cm.New[ErrorCode](22, data) +} + +// HTTPRequestHeaderSize returns a non-nil *[cm.Option[FieldSizePayload]] if [ErrorCode] represents the variant case "HTTP-request-header-size". +func (self *ErrorCode) HTTPRequestHeaderSize() *cm.Option[FieldSizePayload] { + return cm.Case[cm.Option[FieldSizePayload]](self, 22) +} + +// ErrorCodeHTTPRequestTrailerSectionSize returns a [ErrorCode] of case "HTTP-request-trailer-section-size". +func ErrorCodeHTTPRequestTrailerSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](23, data) +} + +// HTTPRequestTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-trailer-section-size". +func (self *ErrorCode) HTTPRequestTrailerSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 23) +} + +// ErrorCodeHTTPRequestTrailerSize returns a [ErrorCode] of case "HTTP-request-trailer-size". +func ErrorCodeHTTPRequestTrailerSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](24, data) +} + +// HTTPRequestTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-request-trailer-size". +func (self *ErrorCode) HTTPRequestTrailerSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 24) +} + +// ErrorCodeHTTPResponseIncomplete returns a [ErrorCode] of case "HTTP-response-incomplete". +func ErrorCodeHTTPResponseIncomplete() ErrorCode { + var data struct{} + return cm.New[ErrorCode](25, data) +} + +// HTTPResponseIncomplete returns true if [ErrorCode] represents the variant case "HTTP-response-incomplete". +func (self *ErrorCode) HTTPResponseIncomplete() bool { + return self.Tag() == 25 +} + +// ErrorCodeHTTPResponseHeaderSectionSize returns a [ErrorCode] of case "HTTP-response-header-section-size". +func ErrorCodeHTTPResponseHeaderSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](26, data) +} + +// HTTPResponseHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-header-section-size". +func (self *ErrorCode) HTTPResponseHeaderSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 26) +} + +// ErrorCodeHTTPResponseHeaderSize returns a [ErrorCode] of case "HTTP-response-header-size". +func ErrorCodeHTTPResponseHeaderSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](27, data) +} + +// HTTPResponseHeaderSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-header-size". +func (self *ErrorCode) HTTPResponseHeaderSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 27) +} + +// ErrorCodeHTTPResponseBodySize returns a [ErrorCode] of case "HTTP-response-body-size". +func ErrorCodeHTTPResponseBodySize(data cm.Option[uint64]) ErrorCode { + return cm.New[ErrorCode](28, data) +} + +// HTTPResponseBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-response-body-size". +func (self *ErrorCode) HTTPResponseBodySize() *cm.Option[uint64] { + return cm.Case[cm.Option[uint64]](self, 28) +} + +// ErrorCodeHTTPResponseTrailerSectionSize returns a [ErrorCode] of case "HTTP-response-trailer-section-size". +func ErrorCodeHTTPResponseTrailerSectionSize(data cm.Option[uint32]) ErrorCode { + return cm.New[ErrorCode](29, data) +} + +// HTTPResponseTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-trailer-section-size". +func (self *ErrorCode) HTTPResponseTrailerSectionSize() *cm.Option[uint32] { + return cm.Case[cm.Option[uint32]](self, 29) +} + +// ErrorCodeHTTPResponseTrailerSize returns a [ErrorCode] of case "HTTP-response-trailer-size". +func ErrorCodeHTTPResponseTrailerSize(data FieldSizePayload) ErrorCode { + return cm.New[ErrorCode](30, data) +} + +// HTTPResponseTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-trailer-size". +func (self *ErrorCode) HTTPResponseTrailerSize() *FieldSizePayload { + return cm.Case[FieldSizePayload](self, 30) +} + +// ErrorCodeHTTPResponseTransferCoding returns a [ErrorCode] of case "HTTP-response-transfer-coding". +func ErrorCodeHTTPResponseTransferCoding(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](31, data) +} + +// HTTPResponseTransferCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-transfer-coding". +func (self *ErrorCode) HTTPResponseTransferCoding() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 31) +} + +// ErrorCodeHTTPResponseContentCoding returns a [ErrorCode] of case "HTTP-response-content-coding". +func ErrorCodeHTTPResponseContentCoding(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](32, data) +} + +// HTTPResponseContentCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-content-coding". +func (self *ErrorCode) HTTPResponseContentCoding() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 32) +} + +// ErrorCodeHTTPResponseTimeout returns a [ErrorCode] of case "HTTP-response-timeout". +func ErrorCodeHTTPResponseTimeout() ErrorCode { + var data struct{} + return cm.New[ErrorCode](33, data) +} + +// HTTPResponseTimeout returns true if [ErrorCode] represents the variant case "HTTP-response-timeout". +func (self *ErrorCode) HTTPResponseTimeout() bool { + return self.Tag() == 33 +} + +// ErrorCodeHTTPUpgradeFailed returns a [ErrorCode] of case "HTTP-upgrade-failed". +func ErrorCodeHTTPUpgradeFailed() ErrorCode { + var data struct{} + return cm.New[ErrorCode](34, data) +} + +// HTTPUpgradeFailed returns true if [ErrorCode] represents the variant case "HTTP-upgrade-failed". +func (self *ErrorCode) HTTPUpgradeFailed() bool { + return self.Tag() == 34 +} + +// ErrorCodeHTTPProtocolError returns a [ErrorCode] of case "HTTP-protocol-error". +func ErrorCodeHTTPProtocolError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](35, data) +} + +// HTTPProtocolError returns true if [ErrorCode] represents the variant case "HTTP-protocol-error". +func (self *ErrorCode) HTTPProtocolError() bool { + return self.Tag() == 35 +} + +// ErrorCodeLoopDetected returns a [ErrorCode] of case "loop-detected". +func ErrorCodeLoopDetected() ErrorCode { + var data struct{} + return cm.New[ErrorCode](36, data) +} + +// LoopDetected returns true if [ErrorCode] represents the variant case "loop-detected". +func (self *ErrorCode) LoopDetected() bool { + return self.Tag() == 36 +} + +// ErrorCodeConfigurationError returns a [ErrorCode] of case "configuration-error". +func ErrorCodeConfigurationError() ErrorCode { + var data struct{} + return cm.New[ErrorCode](37, data) +} + +// ConfigurationError returns true if [ErrorCode] represents the variant case "configuration-error". +func (self *ErrorCode) ConfigurationError() bool { + return self.Tag() == 37 +} + +// ErrorCodeInternalError returns a [ErrorCode] of case "internal-error". +// +// This is a catch-all error for anything that doesn't fit cleanly into a +// more specific case. It also includes an optional string for an +// 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. +func ErrorCodeInternalError(data cm.Option[string]) ErrorCode { + return cm.New[ErrorCode](38, data) +} + +// InternalError returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "internal-error". +func (self *ErrorCode) InternalError() *cm.Option[string] { + return cm.Case[cm.Option[string]](self, 38) +} + +// HeaderError represents the variant "wasi:http/types@0.2.0#header-error". +// +// This type enumerates the different kinds of errors that may occur when +// setting or appending to a `fields` resource. +// +// variant header-error { +// invalid-syntax, +// forbidden, +// immutable, +// } +type HeaderError uint8 + +const ( + // This error indicates that a `field-key` or `field-value` was + // syntactically invalid when used with an operation that sets headers in a + // `fields`. + HeaderErrorInvalidSyntax HeaderError = iota + + // This error indicates that a forbidden `field-key` was used when trying + // to set a header in a `fields`. + HeaderErrorForbidden + + // This error indicates that the operation on the `fields` was not + // permitted because the fields are immutable. + HeaderErrorImmutable +) + +var stringsHeaderError = [3]string{ + "invalid-syntax", + "forbidden", + "immutable", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e HeaderError) String() string { + return stringsHeaderError[e] +} + +// FieldKey represents the string "wasi:http/types@0.2.0#field-key". +// +// Field keys are always strings. +// +// type field-key = string +type FieldKey string + +// FieldValue represents the list "wasi:http/types@0.2.0#field-value". +// +// Field values should always be ASCII strings. However, in +// reality, HTTP implementations often have to interpret malformed values, +// so they are provided as a list of bytes. +// +// type field-value = list +type FieldValue cm.List[uint8] + +// Fields represents the imported resource "wasi:http/types@0.2.0#fields". +// +// This following block defines the `fields` resource which corresponds to +// HTTP standard Fields. Fields are a common representation used for both +// Headers and Trailers. +// +// A `fields` may be mutable or immutable. A `fields` created using the +// constructor, `from-list`, or `clone` will be mutable, but a `fields` +// resource given by other means (including, but not limited to, +// `incoming-request.headers`, `outgoing-request.headers`) might be be +// immutable. In an immutable fields, the `set`, `append`, and `delete` +// operations will fail with `header-error.immutable`. +// +// resource fields +type Fields cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "fields". +// +// Drops a resource handle. +// +//go:nosplit +func (self Fields) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FieldsResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields +//go:noescape +func wasmimport_FieldsResourceDrop(self0 uint32) + +// NewFields represents the imported constructor for resource "fields". +// +// Construct an empty HTTP Fields. +// +// The resulting `fields` is mutable. +// +// constructor() +// +//go:nosplit +func NewFields() (result Fields) { + result0 := wasmimport_NewFields() + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]fields +//go:noescape +func wasmimport_NewFields() (result0 uint32) + +// FieldsFromList represents the imported static function "from-list". +// +// Construct an HTTP Fields. +// +// The resulting `fields` is mutable. +// +// The 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. +// +// The tuple is a pair of the field key, represented as a string, and +// Value, represented as a list of bytes. In a valid Fields, all keys +// and values are valid UTF-8 strings. However, values are not always +// well-formed, so they are represented as a raw list of bytes. +// +// 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 +// +//go:nosplit +func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm.Result[Fields, Fields, HeaderError]) { + entries0, entries1 := cm.LowerList(entries) + wasmimport_FieldsFromList((*cm.Tuple[FieldKey, FieldValue])(entries0), (uint32)(entries1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list +//go:noescape +func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) + +// Append represents the imported method "append". +// +// 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> +// +//go:nosplit +func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + value0, value1 := cm.LowerList(value) + wasmimport_FieldsAppend((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.append +//go:noescape +func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// Clone represents the imported method "clone". +// +// 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. +// +// clone: func() -> fields +// +//go:nosplit +func (self Fields) Clone() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FieldsClone((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone +//go:noescape +func wasmimport_FieldsClone(self0 uint32) (result0 uint32) + +// Delete represents the imported method "delete". +// +// 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> +// +//go:nosplit +func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + wasmimport_FieldsDelete((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete +//go:noescape +func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// Entries represents the imported method "entries". +// +// 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> +// +//go:nosplit +func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FieldsEntries((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries +//go:noescape +func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) + +// Get represents the imported method "get". +// +// 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 +// +//go:nosplit +func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + wasmimport_FieldsGet((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.get +//go:noescape +func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) + +// Has represents the imported method "has". +// +// 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 +// +//go:nosplit +func (self Fields) Has(name FieldKey) (result bool) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + result0 := wasmimport_FieldsHas((uint32)(self0), (*uint8)(name0), (uint32)(name1)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.has +//go:noescape +func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) + +// Set represents the imported method "set". +// +// 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> +// +//go:nosplit +func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Result[HeaderError, struct{}, HeaderError]) { + self0 := cm.Reinterpret[uint32](self) + name0, name1 := cm.LowerString(name) + value0, value1 := cm.LowerList(value) + wasmimport_FieldsSet((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*FieldValue)(value0), (uint32)(value1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.set +//go:noescape +func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +// IncomingRequest represents the imported resource "wasi:http/types@0.2.0#incoming-request". +// +// Represents an incoming HTTP Request. +// +// resource incoming-request +type IncomingRequest cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-request". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingRequest) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request +//go:noescape +func wasmimport_IncomingRequestResourceDrop(self0 uint32) + +// Authority represents the imported method "authority". +// +// Returns the authority from the request, if it was present. +// +// authority: func() -> option +// +//go:nosplit +func (self IncomingRequest) Authority() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestAuthority((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority +//go:noescape +func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) + +// Consume represents the imported method "consume". +// +// Gives the `incoming-body` associated with this request. Will only +// return success at most once, and subsequent calls will return error. +// +// consume: func() -> result +// +//go:nosplit +func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestConsume((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume +//go:noescape +func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the `headers` associated with the request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// The `headers` returned are a child resource: it must be dropped before +// the parent `incoming-request` is dropped. Dropping this +// `incoming-request` before all children are dropped will trap. +// +// headers: func() -> headers +// +//go:nosplit +func (self IncomingRequest) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers +//go:noescape +func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) + +// Method represents the imported method "method". +// +// Returns the method of the incoming request. +// +// method: func() -> method +// +//go:nosplit +func (self IncomingRequest) Method() (result Method) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestMethod((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method +//go:noescape +func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) + +// PathWithQuery represents the imported method "path-with-query". +// +// Returns the path with query parameters from the request, as a string. +// +// path-with-query: func() -> option +// +//go:nosplit +func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestPathWithQuery((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query +//go:noescape +func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +// Scheme represents the imported method "scheme". +// +// Returns the protocol scheme from the request. +// +// scheme: func() -> option +// +//go:nosplit +func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingRequestScheme((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme +//go:noescape +func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +// OutgoingRequest represents the imported resource "wasi:http/types@0.2.0#outgoing-request". +// +// Represents an outgoing HTTP Request. +// +// resource outgoing-request +type OutgoingRequest cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-request". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingRequest) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request +//go:noescape +func wasmimport_OutgoingRequestResourceDrop(self0 uint32) + +// NewOutgoingRequest represents the imported constructor for resource "outgoing-request". +// +// Construct a new `outgoing-request` with a default `method` of `GET`, and +// `none` values for `path-with-query`, `scheme`, and `authority`. +// +// * `headers` is the HTTP Headers for the Request. +// +// It is possible to construct, or manipulate with the accessor functions +// below, an `outgoing-request` with an invalid combination of `scheme` +// 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) +// +//go:nosplit +func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) + result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request +//go:noescape +func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) + +// Authority represents the imported method "authority". +// +// 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. +// +// authority: func() -> option +// +//go:nosplit +func (self OutgoingRequest) Authority() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestAuthority((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority +//go:noescape +func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) + +// Body represents the imported method "body". +// +// Returns the resource corresponding to the outgoing Body for this +// Request. +// +// Returns success on the first call: the `outgoing-body` resource for +// this `outgoing-request` can be retrieved at most once. Subsequent +// calls will return error. +// +// body: func() -> result +// +//go:nosplit +func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestBody((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body +//go:noescape +func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the headers associated with the Request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `outgoing-request` is dropped, or its ownership is transfered to +// another component by e.g. `outgoing-handler.handle`. +// +// headers: func() -> headers +// +//go:nosplit +func (self OutgoingRequest) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers +//go:noescape +func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) + +// Method represents the imported method "method". +// +// Get the Method for the Request. +// +// method: func() -> method +// +//go:nosplit +func (self OutgoingRequest) Method() (result Method) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestMethod((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method +//go:noescape +func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) + +// PathWithQuery represents the imported method "path-with-query". +// +// 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 +// +//go:nosplit +func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestPathWithQuery((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query +//go:noescape +func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +// Scheme represents the imported method "scheme". +// +// Get the HTTP Related Scheme for the Request. When `none`, the +// implementation may choose an appropriate default scheme. +// +// scheme: func() -> option +// +//go:nosplit +func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingRequestScheme((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme +//go:noescape +func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +// SetAuthority represents the imported method "set-authority". +// +// Set the HTTP Authority for the Request. A value of `none` may be used +// with Related Schemes which do not require an Authority. The HTTP and +// HTTPS schemes always require an authority. Fails if the string given is +// not a syntactically valid uri authority. +// +// set-authority: func(authority: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + authority0, authority1, authority2 := lower_OptionString(authority) + result0 := wasmimport_OutgoingRequestSetAuthority((uint32)(self0), (uint32)(authority0), (*uint8)(authority1), (uint32)(authority2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority +//go:noescape +func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) + +// SetMethod represents the imported method "set-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 +// +//go:nosplit +func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + method0, method1, method2 := lower_Method(method) + result0 := wasmimport_OutgoingRequestSetMethod((uint32)(self0), (uint32)(method0), (*uint8)(method1), (uint32)(method2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method +//go:noescape +func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) + +// SetPathWithQuery represents the imported method "set-path-with-query". +// +// Set the combination of the HTTP Path and Query for the Request. +// When `none`, this represents an empty Path and empty Query. Fails is the +// string given is not a syntactically valid path and query uri component. +// +// set-path-with-query: func(path-with-query: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + pathWithQuery0, pathWithQuery1, pathWithQuery2 := lower_OptionString(pathWithQuery) + result0 := wasmimport_OutgoingRequestSetPathWithQuery((uint32)(self0), (uint32)(pathWithQuery0), (*uint8)(pathWithQuery1), (uint32)(pathWithQuery2)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query +//go:noescape +func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) + +// SetScheme represents the imported method "set-scheme". +// +// Set the HTTP Related Scheme for the Request. When `none`, the +// implementation may choose an appropriate default scheme. Fails if the +// string given is not a syntactically valid uri scheme. +// +// set-scheme: func(scheme: option) -> result +// +//go:nosplit +func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + scheme0, scheme1, scheme2, scheme3 := lower_OptionScheme(scheme) + result0 := wasmimport_OutgoingRequestSetScheme((uint32)(self0), (uint32)(scheme0), (uint32)(scheme1), (*uint8)(scheme2), (uint32)(scheme3)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme +//go:noescape +func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) + +// RequestOptions represents the imported resource "wasi:http/types@0.2.0#request-options". +// +// Parameters for making an HTTP Request. Each of these parameters is +// currently an optional timeout applicable to the transport layer of the +// HTTP protocol. +// +// These timeouts are separate from any the user may use to bound a +// blocking call to `wasi:io/poll.poll`. +// +// resource request-options +type RequestOptions cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "request-options". +// +// Drops a resource handle. +// +//go:nosplit +func (self RequestOptions) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options +//go:noescape +func wasmimport_RequestOptionsResourceDrop(self0 uint32) + +// NewRequestOptions represents the imported constructor for resource "request-options". +// +// Construct a default `request-options` value. +// +// constructor() +// +//go:nosplit +func NewRequestOptions() (result RequestOptions) { + result0 := wasmimport_NewRequestOptions() + result = cm.Reinterpret[RequestOptions]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options +//go:noescape +func wasmimport_NewRequestOptions() (result0 uint32) + +// BetweenBytesTimeout represents the imported method "between-bytes-timeout". +// +// The timeout for receiving subsequent chunks of bytes in the Response +// body stream. +// +// between-bytes-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// ConnectTimeout represents the imported method "connect-timeout". +// +// The timeout for the initial connect to the HTTP Server. +// +// connect-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout +//go:noescape +func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// FirstByteTimeout represents the imported method "first-byte-timeout". +// +// The timeout for receiving the first byte of the Response body. +// +// first-byte-timeout: func() -> option +// +//go:nosplit +func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) + +// SetBetweenBytesTimeout represents the imported method "set-between-bytes-timeout". +// +// 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. +// +// set-between-bytes-timeout: func(duration: option) -> result +// +//go:nosplit +func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetBetweenBytesTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// SetConnectTimeout represents the imported method "set-connect-timeout". +// +// 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 +// +//go:nosplit +func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetConnectTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout +//go:noescape +func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// SetFirstByteTimeout represents the imported method "set-first-byte-timeout". +// +// 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 +// +//go:nosplit +func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + duration0, duration1 := lower_OptionDuration(duration) + result0 := wasmimport_RequestOptionsSetFirstByteTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +// ResponseOutparam represents the imported resource "wasi:http/types@0.2.0#response-outparam". +// +// Represents the ability to send an HTTP Response. +// +// This resource is used by the `wasi:http/incoming-handler` interface to +// allow a Response to be sent corresponding to the Request provided as the +// other argument to `incoming-handler.handle`. +// +// resource response-outparam +type ResponseOutparam cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "response-outparam". +// +// Drops a resource handle. +// +//go:nosplit +func (self ResponseOutparam) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResponseOutparamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam +//go:noescape +func wasmimport_ResponseOutparamResourceDrop(self0 uint32) + +// ResponseOutparamSet represents the imported static function "set". +// +// Set the value of the `response-outparam` to either send a response, +// or indicate an error. +// +// This method consumes the `response-outparam` to ensure that it is +// called at most once. If it is never called, the implementation +// will respond with an error. +// +// 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) +// +//go:nosplit +func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) { + param0 := cm.Reinterpret[uint32](param) + response0, response1, response2, response3, response4, response5, response6, response7 := lower_ResultOutgoingResponseErrorCode(response) + wasmimport_ResponseOutparamSet((uint32)(param0), (uint32)(response0), (uint32)(response1), (uint32)(response2), (uint64)(response3), (uint32)(response4), (uint32)(response5), (uint32)(response6), (uint32)(response7)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set +//go:noescape +func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) + +// StatusCode represents the u16 "wasi:http/types@0.2.0#status-code". +// +// This type corresponds to the HTTP standard Status Code. +// +// type status-code = u16 +type StatusCode uint16 + +// IncomingResponse represents the imported resource "wasi:http/types@0.2.0#incoming-response". +// +// Represents an incoming HTTP Response. +// +// resource incoming-response +type IncomingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response +//go:noescape +func wasmimport_IncomingResponseResourceDrop(self0 uint32) + +// Consume represents the imported method "consume". +// +// Returns the incoming body. May be called at most once. Returns error +// if called additional times. +// +// consume: func() -> result +// +//go:nosplit +func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingResponseConsume((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume +//go:noescape +func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Returns the headers from the incoming response. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `incoming-response` is dropped. +// +// headers: func() -> headers +// +//go:nosplit +func (self IncomingResponse) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers +//go:noescape +func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) + +// Status represents the imported method "status". +// +// Returns the status code from the incoming response. +// +// status: func() -> status-code +// +//go:nosplit +func (self IncomingResponse) Status() (result StatusCode) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingResponseStatus((uint32)(self0)) + result = (StatusCode)((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status +//go:noescape +func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) + +// IncomingBody represents the imported resource "wasi:http/types@0.2.0#incoming-body". +// +// Represents an incoming HTTP Request or Response's Body. +// +// A body has both its contents - a stream of bytes - and a (possibly +// empty) set of trailers, indicating that the full contents of the +// body have been received. This resource represents the contents as +// an `input-stream` and the delivery of trailers as a `future-trailers`, +// and ensures that the user of this interface may only be consuming either +// the body contents or waiting on trailers at any given time. +// +// resource incoming-body +type IncomingBody cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-body". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingBody) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingBodyResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body +//go:noescape +func wasmimport_IncomingBodyResourceDrop(self0 uint32) + +// IncomingBodyFinish represents the imported static function "finish". +// +// 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 +// +//go:nosplit +func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { + this0 := cm.Reinterpret[uint32](this) + result0 := wasmimport_IncomingBodyFinish((uint32)(this0)) + result = cm.Reinterpret[FutureTrailers]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish +//go:noescape +func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) + +// Stream represents the imported method "stream". +// +// Returns the contents of the body, as a stream of bytes. +// +// Returns success on first call: the stream representing the contents +// can be retrieved at most once. Subsequent calls will return error. +// +// The returned `input-stream` resource is a child: it must be dropped +// before the parent `incoming-body` is dropped, or consumed by +// `incoming-body.finish`. +// +// This invariant ensures that the implementation can determine whether +// the user is consuming the contents of the body, waiting on the +// `future-trailers` to be ready, or neither. This allows for network +// backpressure is to be applied when the user is consuming the body, +// and for that backpressure to not inhibit delivery of the trailers if +// the user does not read the entire body. +// +// %stream: func() -> result +// +//go:nosplit +func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams.InputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingBodyStream((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream +//go:noescape +func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) + +// FutureTrailers represents the imported resource "wasi:http/types@0.2.0#future-trailers". +// +// Represents a future which may eventaully return trailers, or an error. +// +// In the case that the incoming HTTP Request or Response did not have any +// trailers, this future will resolve to the empty set of trailers once the +// complete Request or Response body has been received. +// +// resource future-trailers +type FutureTrailers cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "future-trailers". +// +// Drops a resource handle. +// +//go:nosplit +func (self FutureTrailers) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureTrailersResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers +//go:noescape +func wasmimport_FutureTrailersResourceDrop(self0 uint32) + +// Get represents the imported method "get". +// +// Returns the contents of the trailers, or an error which occured, +// once the future is ready. +// +// The outer `option` represents future readiness. Users can wait on this +// `option` to become `some` using the `subscribe` method. +// +// The outer `result` is used to retrieve the trailers or error at most +// once. It will be success on the first call in which the outer option +// is `some`, and error on subsequent calls. +// +// The inner `result` represents that either the HTTP Request or Response +// body, as well as any trailers, were received successfully, or that an +// error occured receiving them. The optional `trailers` indicates whether +// or not trailers were present in the body. +// +// When some `trailers` are returned by this method, the `trailers` +// resource is immutable, and a child. Use of the `set`, `append`, or +// `delete` methods will return an error, and the resource must be +// dropped before the parent `future-trailers` is dropped. +// +// get: func() -> option, error-code>>> +// +//go:nosplit +func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureTrailersGet((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get +//go:noescape +func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) + +// Subscribe represents the imported method "subscribe". +// +// 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 +// +//go:nosplit +func (self FutureTrailers) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe +//go:noescape +func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) + +// OutgoingResponse represents the imported resource "wasi:http/types@0.2.0#outgoing-response". +// +// Represents an outgoing HTTP Response. +// +// resource outgoing-response +type OutgoingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response +//go:noescape +func wasmimport_OutgoingResponseResourceDrop(self0 uint32) + +// NewOutgoingResponse represents the imported constructor for 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) +// +//go:nosplit +func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) + result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response +//go:noescape +func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) + +// Body represents the imported method "body". +// +// Returns the resource corresponding to the outgoing Body for this Response. +// +// Returns success on the first call: the `outgoing-body` resource for +// this `outgoing-response` can be retrieved at most once. Subsequent +// calls will return error. +// +// body: func() -> result +// +//go:nosplit +func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingResponseBody((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body +//go:noescape +func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +// Headers represents the imported method "headers". +// +// Get the headers associated with the Request. +// +// The returned `headers` resource is immutable: `set`, `append`, and +// `delete` operations will fail with `header-error.immutable`. +// +// This headers resource is a child: it must be dropped before the parent +// `outgoing-request` is dropped, or its ownership is transfered to +// another component by e.g. `outgoing-handler.handle`. +// +// headers: func() -> headers +// +//go:nosplit +func (self OutgoingResponse) Headers() (result Fields) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Fields]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers +//go:noescape +func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) + +// SetStatusCode represents the imported method "set-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 +// +//go:nosplit +func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.BoolResult) { + self0 := cm.Reinterpret[uint32](self) + statusCode0 := (uint32)(statusCode) + result0 := wasmimport_OutgoingResponseSetStatusCode((uint32)(self0), (uint32)(statusCode0)) + result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code +//go:noescape +func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) + +// StatusCode represents the imported method "status-code". +// +// Get the HTTP Status Code for the Response. +// +// status-code: func() -> status-code +// +//go:nosplit +func (self OutgoingResponse) StatusCode() (result StatusCode) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingResponseStatusCode((uint32)(self0)) + result = (StatusCode)((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code +//go:noescape +func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) + +// OutgoingBody represents the imported resource "wasi:http/types@0.2.0#outgoing-body". +// +// Represents an outgoing HTTP Request or Response's Body. +// +// A body has both its contents - a stream of bytes - and a (possibly +// empty) set of trailers, inducating the full contents of the body +// have been sent. This resource represents the contents as an +// `output-stream` child resource, and the completion of the body (with +// optional trailers) with a static function that consumes the +// `outgoing-body` resource, and ensures that the user of this interface +// may not write to the body contents after the body has been finished. +// +// If the user code drops this resource, as opposed to calling the static +// method `finish`, the implementation should treat the body as incomplete, +// and that an error has occured. The implementation should propogate this +// error to the HTTP protocol by whatever means it has available, +// including: corrupting the body on the wire, aborting the associated +// Request, or sending a late status code for the Response. +// +// resource outgoing-body +type OutgoingBody cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-body". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingBody) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingBodyResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body +//go:noescape +func wasmimport_OutgoingBodyResourceDrop(self0 uint32) + +// OutgoingBodyFinish represents the imported static function "finish". +// +// 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 +// should treat the body as corrupted. +// +// Fails if the body's `outgoing-request` or `outgoing-response` was +// 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> +// +//go:nosplit +func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + this0 := cm.Reinterpret[uint32](this) + trailers0, trailers1 := lower_OptionTrailers(trailers) + wasmimport_OutgoingBodyFinish((uint32)(this0), (uint32)(trailers0), (uint32)(trailers1), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish +//go:noescape +func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +// Write represents the imported method "write". +// +// Returns a stream for writing the body contents. +// +// The returned `output-stream` is a child resource: it must be dropped +// before the parent `outgoing-body` resource is dropped (or finished), +// otherwise the `outgoing-body` drop or `finish` will trap. +// +// Returns success on the first call: the `output-stream` resource for +// this `outgoing-body` may be retrieved at most once. Subsequent calls +// will return error. +// +// write: func() -> result +// +//go:nosplit +func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingBodyWrite((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write +//go:noescape +func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) + +// FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.0#future-incoming-response". +// +// Represents a future which may eventaully return an incoming HTTP +// Response, or an error. +// +// This resource is returned by the `wasi:http/outgoing-handler` interface to +// provide the HTTP Response corresponding to the sent Request. +// +// resource future-incoming-response +type FutureIncomingResponse cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "future-incoming-response". +// +// Drops a resource handle. +// +//go:nosplit +func (self FutureIncomingResponse) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureIncomingResponseResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response +//go:noescape +func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) + +// Get represents the imported method "get". +// +// Returns the incoming HTTP Response, or an error, once one is ready. +// +// The outer `option` represents future readiness. Users can wait on this +// `option` to become `some` using the `subscribe` method. +// +// The outer `result` is used to retrieve the response or error at most +// once. It will be success on the first call in which the outer option +// is `some`, and error on subsequent calls. +// +// The inner `result` represents that either the incoming HTTP Response +// status and headers have recieved successfully, or that an error +// occured. Errors may also occur while consuming the response body, +// but those will be reported by the `incoming-body` and its +// `output-stream` child. +// +// get: func() -> option>> +// +//go:nosplit +func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureIncomingResponseGet((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get +//go:noescape +func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) + +// Subscribe represents the imported method "subscribe". +// +// Returns a pollable which becomes ready when either the Response has +// been received, or an error has occured. When this pollable is ready, +// the `get` method will return `some`. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe +//go:noescape +func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) + +// HTTPErrorCode represents the imported function "http-error-code". +// +// 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 +// +//go:nosplit +func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_HTTPErrorCode((uint32)(err0), &result) + return +} + +//go:wasmimport wasi:http/types@0.2.0 http-error-code +//go:noescape +func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/io/v0.2.0/error/empty.s b/v2/internal/wasi/io/v0.2.0/error/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/error/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/io/v0.2.0/error/error.wit.go b/v2/internal/wasi/io/v0.2.0/error/error.wit.go new file mode 100644 index 0000000..96d18cf --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/error/error.wit.go @@ -0,0 +1,71 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ioerror represents the imported interface "wasi:io/error@0.2.0". +package ioerror + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "error". +// +// Drops a resource handle. +// +//go:nosplit +func (self Error) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error +//go:noescape +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 +func (self Error) ToDebugString() (result string) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorToDebugString((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string +//go:noescape +func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/v2/internal/wasi/io/v0.2.0/poll/empty.s b/v2/internal/wasi/io/v0.2.0/poll/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/poll/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go new file mode 100644 index 0000000..ba22e54 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -0,0 +1,108 @@ +// 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 ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "pollable". +// +// Drops a resource handle. +// +//go:nosplit +func (self Pollable) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable +//go:noescape +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 +func (self Pollable) Block() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableBlock((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block +//go:noescape +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 +func (self Pollable) Ready() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_PollableReady((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready +//go:noescape +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 +func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { + in0, in1 := cm.LowerList(in) + wasmimport_Poll((*Pollable)(in0), (uint32)(in1), &result) + return +} + +//go:wasmimport wasi:io/poll@0.2.0 poll +//go:noescape +func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/v2/internal/wasi/io/v0.2.0/streams/abi.go b/v2/internal/wasi/io/v0.2.0/streams/abi.go new file mode 100644 index 0000000..5f15002 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/streams/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package streams + +import ( + "unsafe" +) + +// StreamErrorShape is used for storage in variant or result types. +type StreamErrorShape struct { + shape [unsafe.Sizeof(StreamError{})]byte +} diff --git a/v2/internal/wasi/io/v0.2.0/streams/empty.s b/v2/internal/wasi/io/v0.2.0/streams/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/streams/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go new file mode 100644 index 0000000..8e9d2ae --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -0,0 +1,519 @@ +// 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 ( + ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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, +// } +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) +} + +// LastOperationFailed returns a non-nil *[ioerror.Error] if [StreamError] represents the variant case "last-operation-failed". +func (self *StreamError) LastOperationFailed() *ioerror.Error { + return cm.Case[ioerror.Error](self, 0) +} + +// 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) +} + +// Closed returns true if [StreamError] represents the variant case "closed". +func (self *StreamError) Closed() bool { + return self.Tag() == 1 +} + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "input-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self InputStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_InputStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream +//go:noescape +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 +func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingRead((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read +//go:noescape +func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +// 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 +func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingSkip((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip +//go:noescape +func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// 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 +func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamRead((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read +//go:noescape +func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +// 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 +func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamSkip((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip +//go:noescape +func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// 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 +func (self InputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe +//go:noescape +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 + +// ResourceDrop represents the imported resource-drop for resource "output-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutputStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream +//go:noescape +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 +func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamBlockingFlush((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush +//go:noescape +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// 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 +func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice +//go:noescape +func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// 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 +func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamBlockingWriteAndFlush((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// 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 +func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingWriteZeroesAndFlush((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) + +// 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 +func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamCheckWrite((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write +//go:noescape +func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) + +// 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 +func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamFlush((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush +//go:noescape +func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// 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 +func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice +//go:noescape +func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +// 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 +func (self OutputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe +//go:noescape +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 +func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamWrite((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write +//go:noescape +func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +// 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 +func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamWriteZeroes((uint32)(self0), (uint64)(len0), &result) + return +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes +//go:noescape +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s b/v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go new file mode 100644 index 0000000..3b8f33c --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go @@ -0,0 +1,41 @@ +// 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 +func InsecureSeed() (result [2]uint64) { + wasmimport_InsecureSeed(&result) + return +} + +//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed +//go:noescape +func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/v2/internal/wasi/random/v0.2.0/insecure/empty.s b/v2/internal/wasi/random/v0.2.0/insecure/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go new file mode 100644 index 0000000..4f813bf --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go @@ -0,0 +1,57 @@ +// 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 ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 +func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetInsecureRandomBytes((uint64)(len0), &result) + return +} + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes +//go:noescape +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 +func GetInsecureRandomU64() (result uint64) { + result0 := wasmimport_GetInsecureRandomU64() + result = (uint64)((uint64)(result0)) + return +} + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 +//go:noescape +func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/random/v0.2.0/random/empty.s b/v2/internal/wasi/random/v0.2.0/random/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/random/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wit.go b/v2/internal/wasi/random/v0.2.0/random/random.wit.go new file mode 100644 index 0000000..04b2319 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/random/random.wit.go @@ -0,0 +1,61 @@ +// 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 ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 +func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetRandomBytes((uint64)(len0), &result) + return +} + +//go:wasmimport wasi:random/random@0.2.0 get-random-bytes +//go:noescape +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 +func GetRandomU64() (result uint64) { + result0 := wasmimport_GetRandomU64() + result = (uint64)((uint64)(result0)) + return +} + +//go:wasmimport wasi:random/random@0.2.0 get-random-u64 +//go:noescape +func wasmimport_GetRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s b/v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go new file mode 100644 index 0000000..af26e1b --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -0,0 +1,28 @@ +// 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 ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// InstanceNetwork represents the imported function "instance-network". +// +// Get a handle to the default network. +// +// instance-network: func() -> network +// +//go:nosplit +func InstanceNetwork() (result network.Network) { + result0 := wasmimport_InstanceNetwork() + result = cm.Reinterpret[network.Network]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network +//go:noescape +func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go new file mode 100644 index 0000000..b1c29e6 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package ipnamelookup + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// OptionIPAddressShape is used for storage in variant or result types. +type OptionIPAddressShape struct { + shape [unsafe.Sizeof(cm.Option[network.IPAddress]{})]byte +} diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go new file mode 100644 index 0000000..b331a64 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -0,0 +1,121 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.0". +package ipnamelookup + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". +// +// resource resolve-address-stream +type ResolveAddressStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "resolve-address-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self ResolveAddressStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream +//go:noescape +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 +func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address +//go:noescape +func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) + +// 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 +func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe +//go:noescape +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 +// +//go:nosplit +func ResolveAddresses(network_ network.Network, name string) (result cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) { + network0 := cm.Reinterpret[uint32](network_) + name0, name1 := cm.LowerString(name) + wasmimport_ResolveAddresses((uint32)(network0), (*uint8)(name0), (uint32)(name1), &result) + return +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses +//go:noescape +func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/network/abi.go b/v2/internal/wasi/sockets/v0.2.0/network/abi.go new file mode 100644 index 0000000..54820be --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/abi.go @@ -0,0 +1,12 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package network + +import ( + "unsafe" +) + +// IPv6SocketAddressShape is used for storage in variant or result types. +type IPv6SocketAddressShape struct { + shape [unsafe.Sizeof(IPv6SocketAddress{})]byte +} diff --git a/v2/internal/wasi/sockets/v0.2.0/network/empty.s b/v2/internal/wasi/sockets/v0.2.0/network/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go new file mode 100644 index 0000000..4597e24 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -0,0 +1,315 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package network represents the imported interface "wasi:sockets/network@0.2.0". +package network + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "network". +// +// Drops a resource handle. +// +//go:nosplit +func (self Network) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_NetworkResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +//go:noescape +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, +// 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 +// } +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 +) + +var stringsErrorCode = [21]string{ + "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", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ErrorCode) String() string { + return stringsErrorCode[e] +} + +// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". +// +// enum ip-address-family { +// ipv4, +// ipv6 +// } +type IPAddressFamily uint8 + +const ( + // Similar to `AF_INET` in POSIX. + IPAddressFamilyIPv4 IPAddressFamily = iota + + // Similar to `AF_INET6` in POSIX. + IPAddressFamilyIPv6 +) + +var stringsIPAddressFamily = [2]string{ + "ipv4", + "ipv6", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e IPAddressFamily) String() string { + return stringsIPAddressFamily[e] +} + +// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". +// +// type ipv4-address = tuple +type IPv4Address [4]uint8 + +// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". +// +// type ipv6-address = tuple +type IPv6Address [8]uint16 + +// IPAddress represents the variant "wasi:sockets/network@0.2.0#ip-address". +// +// variant ip-address { +// ipv4(ipv4-address), +// ipv6(ipv6-address), +// } +type IPAddress cm.Variant[uint8, IPv6Address, IPv6Address] + +// IPAddressIPv4 returns a [IPAddress] of case "ipv4". +func IPAddressIPv4(data IPv4Address) IPAddress { + return cm.New[IPAddress](0, data) +} + +// IPv4 returns a non-nil *[IPv4Address] if [IPAddress] represents the variant case "ipv4". +func (self *IPAddress) IPv4() *IPv4Address { + return cm.Case[IPv4Address](self, 0) +} + +// IPAddressIPv6 returns a [IPAddress] of case "ipv6". +func IPAddressIPv6(data IPv6Address) IPAddress { + return cm.New[IPAddress](1, data) +} + +// IPv6 returns a non-nil *[IPv6Address] if [IPAddress] represents the variant case "ipv6". +func (self *IPAddress) IPv6() *IPv6Address { + return cm.Case[IPv6Address](self, 1) +} + +// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". +// +// record ipv4-socket-address { +// port: u16, +// address: ipv4-address, +// } +type IPv4SocketAddress struct { + // sin_port + Port uint16 + + // sin_addr + Address IPv4Address +} + +// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address". +// +// record ipv6-socket-address { +// port: u16, +// flow-info: u32, +// address: ipv6-address, +// scope-id: u32, +// } +type IPv6SocketAddress struct { + // sin6_port + Port uint16 + + // sin6_flowinfo + FlowInfo uint32 + + // sin6_addr + Address IPv6Address + + // sin6_scope_id + ScopeID uint32 +} + +// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". +// +// variant ip-socket-address { +// ipv4(ipv4-socket-address), +// ipv6(ipv6-socket-address), +// } +type IPSocketAddress cm.Variant[uint8, IPv6SocketAddressShape, IPv6SocketAddress] + +// IPSocketAddressIPv4 returns a [IPSocketAddress] of case "ipv4". +func IPSocketAddressIPv4(data IPv4SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](0, data) +} + +// IPv4 returns a non-nil *[IPv4SocketAddress] if [IPSocketAddress] represents the variant case "ipv4". +func (self *IPSocketAddress) IPv4() *IPv4SocketAddress { + return cm.Case[IPv4SocketAddress](self, 0) +} + +// IPSocketAddressIPv6 returns a [IPSocketAddress] of case "ipv6". +func IPSocketAddressIPv6(data IPv6SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](1, data) +} + +// IPv6 returns a non-nil *[IPv6SocketAddress] if [IPSocketAddress] represents the variant case "ipv6". +func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { + return cm.Case[IPv6SocketAddress](self, 1) +} diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go new file mode 100644 index 0000000..d3ef366 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -0,0 +1,52 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.0". +package tcpcreatesocket + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/tcp" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 +// +//go:nosplit +func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket +//go:noescape +func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go new file mode 100644 index 0000000..a2b2609 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -0,0 +1,86 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcp + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// TupleTCPSocketInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleTCPSocketInputStreamOutputStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream]{})]byte +} + +// TupleInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleInputStreamOutputStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple[streams.InputStream, streams.OutputStream]{})]byte +} + +// IPSocketAddressShape is used for storage in variant or result types. +type IPSocketAddressShape struct { + shape [unsafe.Sizeof(network.IPSocketAddress{})]byte +} + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s b/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go new file mode 100644 index 0000000..5cf0ea3 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -0,0 +1,848 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.0". +package tcp + +import ( + monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". +// +// enum shutdown-type { +// receive, +// send, +// both +// } +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 +) + +var stringsShutdownType = [3]string{ + "receive", + "send", + "both", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e ShutdownType) String() string { + return stringsShutdownType[e] +} + +// 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 + +// ResourceDrop represents the imported resource-drop for resource "tcp-socket". +// +// Drops a resource handle. +// +//go:nosplit +func (self TCPSocket) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket +//go:noescape +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 +func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketAccept((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept +//go:noescape +func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) + +// 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 +func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family +//go:noescape +func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishBind((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind +//go:noescape +func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// FinishConnect represents the imported method "finish-connect". +// +// finish-connect: func() -> result, error-code> +// +//go:nosplit +func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect +//go:noescape +func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) + +// FinishListen represents the imported method "finish-listen". +// +// finish-listen: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishListen((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen +//go:noescape +func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketHopLimit((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit +//go:noescape +func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) + +// 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 +func (self TCPSocket) IsListening() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketIsListening((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening +//go:noescape +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 +func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count +//go:noescape +func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, network.ErrorCode]) + +// 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 +func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, network.ErrorCode]) + +// 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 +func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) + +// 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 +func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval +//go:noescape +func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) + +// 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 +func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address +//go:noescape +func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// 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 +func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size +//go:noescape +func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// 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 +func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address +//go:noescape +func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size +//go:noescape +func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// SetHopLimit represents the imported method "set-hop-limit". +// +// set-hop-limit: func(value: u8) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit +//go:noescape +func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveCount represents the imported method "set-keep-alive-count". +// +// set-keep-alive-count: func(value: u32) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count +//go:noescape +func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveEnabled represents the imported method "set-keep-alive-enabled". +// +// set-keep-alive-enabled: func(value: bool) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := cm.BoolToU32(value) + wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveIdleTime represents the imported method "set-keep-alive-idle-time". +// +// set-keep-alive-idle-time: func(value: duration) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetKeepAliveInterval represents the imported method "set-keep-alive-interval". +// +// set-keep-alive-interval: func(value: duration) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval +//go:noescape +func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size +//go:noescape +func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". +// +// set-receive-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetSendBufferSize represents the imported method "set-send-buffer-size". +// +// set-send-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size +//go:noescape +func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + shutdownType0 := (uint32)(shutdownType) + wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown +//go:noescape +func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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> +// +//go:nosplit +func (self TCPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_TCPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind +//go:noescape +func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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> +// +//go:nosplit +func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11 := lower_IPSocketAddress(remoteAddress) + wasmimport_TCPSocketStartConnect((uint32)(self0), (uint32)(network0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect +//go:noescape +func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self TCPSocket) StartListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketStartListen((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen +//go:noescape +func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self TCPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe +//go:noescape +func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go new file mode 100644 index 0000000..3d6e832 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -0,0 +1,52 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.0". +package udpcreatesocket + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/udp" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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 +// +//go:nosplit +func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) + return +} + +//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket +//go:noescape +func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go new file mode 100644 index 0000000..bb6be9a --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -0,0 +1,101 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package udp + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" + "unsafe" +) + +// IPSocketAddressShape is used for storage in variant or result types. +type IPSocketAddressShape struct { + shape [unsafe.Sizeof(network.IPSocketAddress{})]byte +} + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(v.Tag()) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} + +// TupleIncomingDatagramStreamOutgoingDatagramStreamShape is used for storage in variant or result types. +type TupleIncomingDatagramStreamOutgoingDatagramStreamShape struct { + shape [unsafe.Sizeof(cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream]{})]byte +} + +func lower_OptionIPSocketAddress(v cm.Option[network.IPSocketAddress]) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32, f12 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 := lower_IPSocketAddress(*some) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + f12 = (uint32)(v12) + } + return +} diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/empty.s b/v2/internal/wasi/sockets/v0.2.0/udp/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go new file mode 100644 index 0000000..3e299c1 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -0,0 +1,641 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package udp represents the imported interface "wasi:sockets/udp@0.2.0". +package udp + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/ydnar/wasm-tools-go/cm" +) + +// 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`. + 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`. + 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 + +// ResourceDrop represents the imported resource-drop for resource "udp-socket". +// +// Drops a resource handle. +// +//go:nosplit +func (self UDPSocket) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket +//go:noescape +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 +func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family +//go:noescape +func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketFinishBind((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind +//go:noescape +func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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 +func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address +//go:noescape +func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// 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 +func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size +//go:noescape +func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// 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 +func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address +//go:noescape +func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size +//go:noescape +func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". +// +// set-receive-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetSendBufferSize represents the imported method "set-send-buffer-size". +// +// set-send-buffer-size: func(value: u64) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size +//go:noescape +func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// SetUnicastHopLimit represents the imported method "set-unicast-hop-limit". +// +// set-unicast-hop-limit: func(value: u8) -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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> +// +//go:nosplit +func (self UDPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_UDPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind +//go:noescape +func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) + +// 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> +// +//go:nosplit +func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) (result cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11, remoteAddress12 := lower_OptionIPSocketAddress(remoteAddress) + wasmimport_UDPSocketStream((uint32)(self0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), (uint32)(remoteAddress12), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream +//go:noescape +func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) + +// 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 +func (self UDPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe +//go:noescape +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 +func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) + +// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". +// +// resource incoming-datagram-stream +type IncomingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +//go:noescape +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 +func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + maxResults0 := (uint64)(maxResults) + wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +//go:noescape +func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) + +// 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 +func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +//go:noescape +func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) + +// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". +// +// resource outgoing-datagram-stream +type OutgoingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +//go:noescape +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 +func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +//go:noescape +func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// 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 +func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (result cm.Result[uint64, uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + datagrams0, datagrams1 := cm.LowerList(datagrams) + wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +//go:noescape +func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) + +// 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 +func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +//go:noescape +func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/v2/wit/deps/cli-2023-10-18/command.wit b/v2/wit/deps/cli-2023-10-18/command.wit new file mode 100644 index 0000000..d7ea2d9 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0-rc-2023-10-18; + +world command { + include reactor; + + export run; +} diff --git a/v2/wit/deps/cli-2023-10-18/environment.wit b/v2/wit/deps/cli-2023-10-18/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/environment.wit @@ -0,0 +1,18 @@ +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/v2/wit/deps/cli-2023-10-18/exit.wit b/v2/wit/deps/cli-2023-10-18/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/v2/wit/deps/cli-2023-10-18/reactor.wit b/v2/wit/deps/cli-2023-10-18/reactor.wit new file mode 100644 index 0000000..904b994 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/reactor.wit @@ -0,0 +1,32 @@ +package wasi:cli@0.2.0-rc-2023-10-18; + +world reactor { + import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/timezone@0.2.0-rc-2023-10-18; + import wasi:filesystem/types@0.2.0-rc-2023-10-18; + import wasi:filesystem/preopens@0.2.0-rc-2023-10-18; + import wasi:sockets/instance-network@0.2.0-rc-2023-10-18; + import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18; + import wasi:sockets/network@0.2.0-rc-2023-10-18; + import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18; + import wasi:sockets/tcp@0.2.0-rc-2023-10-18; + import wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18; + import wasi:sockets/udp@0.2.0-rc-2023-10-18; + import wasi:random/random@0.2.0-rc-2023-10-18; + import wasi:random/insecure@0.2.0-rc-2023-10-18; + import wasi:random/insecure-seed@0.2.0-rc-2023-10-18; + import wasi:io/poll@0.2.0-rc-2023-10-18; + import wasi:io/streams@0.2.0-rc-2023-10-18; + + 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/v2/wit/deps/cli-2023-10-18/run.wit b/v2/wit/deps/cli-2023-10-18/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/v2/wit/deps/cli-2023-10-18/stdio.wit b/v2/wit/deps/cli-2023-10-18/stdio.wit new file mode 100644 index 0000000..513ca92 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0-rc-2023-10-18.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/v2/wit/deps/cli-2023-10-18/terminal.wit b/v2/wit/deps/cli-2023-10-18/terminal.wit new file mode 100644 index 0000000..4749576 --- /dev/null +++ b/v2/wit/deps/cli-2023-10-18/terminal.wit @@ -0,0 +1,47 @@ +interface terminal-input { + /// The input side of a terminal. + resource 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-output { + /// The output side of a terminal. + resource 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. +} + +/// 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/v2/wit/deps/cli-2023-11-10/command.wit b/v2/wit/deps/cli-2023-11-10/command.wit new file mode 100644 index 0000000..74811d3 --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0-rc-2023-11-10; + +world command { + include reactor; + + export run; +} diff --git a/v2/wit/deps/cli-2023-11-10/environment.wit b/v2/wit/deps/cli-2023-11-10/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/environment.wit @@ -0,0 +1,18 @@ +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/v2/wit/deps/cli-2023-11-10/exit.wit b/v2/wit/deps/cli-2023-11-10/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/v2/wit/deps/cli-2023-11-10/reactor.wit b/v2/wit/deps/cli-2023-11-10/reactor.wit new file mode 100644 index 0000000..eafa2fd --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/reactor.wit @@ -0,0 +1,31 @@ +package wasi:cli@0.2.0-rc-2023-11-10; + +world reactor { + import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import wasi:filesystem/types@0.2.0-rc-2023-11-10; + import wasi:filesystem/preopens@0.2.0-rc-2023-11-10; + import wasi:sockets/instance-network@0.2.0-rc-2023-11-10; + import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10; + import wasi:sockets/network@0.2.0-rc-2023-11-10; + import wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10; + import wasi:sockets/tcp@0.2.0-rc-2023-11-10; + import wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10; + import wasi:sockets/udp@0.2.0-rc-2023-11-10; + import wasi:random/random@0.2.0-rc-2023-11-10; + import wasi:random/insecure@0.2.0-rc-2023-11-10; + import wasi:random/insecure-seed@0.2.0-rc-2023-11-10; + import wasi:io/poll@0.2.0-rc-2023-11-10; + import wasi:io/streams@0.2.0-rc-2023-11-10; + + 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/v2/wit/deps/cli-2023-11-10/run.wit b/v2/wit/deps/cli-2023-11-10/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/v2/wit/deps/cli-2023-11-10/stdio.wit b/v2/wit/deps/cli-2023-11-10/stdio.wit new file mode 100644 index 0000000..1b653b6 --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/stdio.wit @@ -0,0 +1,17 @@ +interface stdin { + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream}; + + get-stdin: func() -> input-stream; +} + +interface stdout { + use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; + + get-stdout: func() -> output-stream; +} + +interface stderr { + use wasi:io/streams@0.2.0-rc-2023-11-10.{output-stream}; + + get-stderr: func() -> output-stream; +} diff --git a/v2/wit/deps/cli-2023-11-10/terminal.wit b/v2/wit/deps/cli-2023-11-10/terminal.wit new file mode 100644 index 0000000..4749576 --- /dev/null +++ b/v2/wit/deps/cli-2023-11-10/terminal.wit @@ -0,0 +1,47 @@ +interface terminal-input { + /// The input side of a terminal. + resource 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-output { + /// The output side of a terminal. + resource 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. +} + +/// 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/v2/wit/deps/cli/command.wit b/v2/wit/deps/cli/command.wit new file mode 100644 index 0000000..d8005bd --- /dev/null +++ b/v2/wit/deps/cli/command.wit @@ -0,0 +1,7 @@ +package wasi:cli@0.2.0; + +world command { + include imports; + + export run; +} diff --git a/v2/wit/deps/cli/environment.wit b/v2/wit/deps/cli/environment.wit new file mode 100644 index 0000000..7006523 --- /dev/null +++ b/v2/wit/deps/cli/environment.wit @@ -0,0 +1,18 @@ +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/v2/wit/deps/cli/exit.wit b/v2/wit/deps/cli/exit.wit new file mode 100644 index 0000000..d0c2b82 --- /dev/null +++ b/v2/wit/deps/cli/exit.wit @@ -0,0 +1,4 @@ +interface exit { + /// Exit the current instance and any linked instances. + exit: func(status: result); +} diff --git a/v2/wit/deps/cli/imports.wit b/v2/wit/deps/cli/imports.wit new file mode 100644 index 0000000..083b84a --- /dev/null +++ b/v2/wit/deps/cli/imports.wit @@ -0,0 +1,20 @@ +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/v2/wit/deps/cli/run.wit b/v2/wit/deps/cli/run.wit new file mode 100644 index 0000000..a70ee8c --- /dev/null +++ b/v2/wit/deps/cli/run.wit @@ -0,0 +1,4 @@ +interface run { + /// Run the program. + run: func() -> result; +} diff --git a/v2/wit/deps/cli/stdio.wit b/v2/wit/deps/cli/stdio.wit new file mode 100644 index 0000000..31ef35b --- /dev/null +++ b/v2/wit/deps/cli/stdio.wit @@ -0,0 +1,17 @@ +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/v2/wit/deps/cli/terminal.wit b/v2/wit/deps/cli/terminal.wit new file mode 100644 index 0000000..38c724e --- /dev/null +++ b/v2/wit/deps/cli/terminal.wit @@ -0,0 +1,49 @@ +/// 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/v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit b/v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit new file mode 100644 index 0000000..c0ecb52 --- /dev/null +++ b/v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit @@ -0,0 +1,32 @@ +/// 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-rc-2023-10-18.{pollable}; + + /// A timestamp in nanoseconds. + type instant = 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. + resolution: func() -> instant; + + /// Create a `pollable` which will resolve once the specified time has been + /// reached. + subscribe: func( + when: instant, + absolute: bool + ) -> pollable; +} diff --git a/v2/wit/deps/clocks-2023-10-18/timezone.wit b/v2/wit/deps/clocks-2023-10-18/timezone.wit new file mode 100644 index 0000000..e717e7b --- /dev/null +++ b/v2/wit/deps/clocks-2023-10-18/timezone.wit @@ -0,0 +1,48 @@ +interface timezone { + use wall-clock.{datetime}; + + /// Return information needed to display the given `datetime`. This includes + /// the UTC offset, the time zone name, and a flag indicating whether + /// daylight saving time is active. + /// + /// If the timezone cannot be determined for the given `datetime`, return a + /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight + /// saving time. + display: func(when: datetime) -> timezone-display; + + /// The same as `display`, but only return the UTC offset. + utc-offset: func(when: datetime) -> s32; + + /// Information useful for displaying the timezone of a specific `datetime`. + /// + /// This information may vary within a single `timezone` to reflect daylight + /// saving time adjustments. + record timezone-display { + /// The number of seconds difference between UTC time and the local + /// time of the timezone. + /// + /// The returned value will always be less than 86400 which is the + /// number of seconds in a day (24*60*60). + /// + /// In implementations that do not expose an actual time zone, this + /// should return 0. + utc-offset: s32, + + /// The abbreviated name of the timezone to display to a user. The name + /// `UTC` indicates Coordinated Universal Time. Otherwise, this should + /// reference local standards for the name of the time zone. + /// + /// In implementations that do not expose an actual time zone, this + /// should be the string `UTC`. + /// + /// In time zones that do not have an applicable name, a formatted + /// representation of the UTC offset may be returned, such as `-04:00`. + name: string, + + /// Whether daylight saving time is active. + /// + /// In implementations that do not expose an actual time zone, this + /// should return false. + in-daylight-saving-time: bool, + } +} diff --git a/v2/wit/deps/clocks-2023-10-18/wall-clock.wit b/v2/wit/deps/clocks-2023-10-18/wall-clock.wit new file mode 100644 index 0000000..c395649 --- /dev/null +++ b/v2/wit/deps/clocks-2023-10-18/wall-clock.wit @@ -0,0 +1,41 @@ +/// 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/v2/wit/deps/clocks-2023-10-18/world.wit b/v2/wit/deps/clocks-2023-10-18/world.wit new file mode 100644 index 0000000..cdfb51d --- /dev/null +++ b/v2/wit/deps/clocks-2023-10-18/world.wit @@ -0,0 +1,7 @@ +package wasi:clocks@0.2.0-rc-2023-10-18; + +world imports { + import monotonic-clock; + import wall-clock; + import timezone; +} diff --git a/v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit b/v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit new file mode 100644 index 0000000..09ef32c --- /dev/null +++ b/v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit @@ -0,0 +1,45 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; +/// 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-rc-2023-11-10.{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/v2/wit/deps/clocks-2023-11-10/wall-clock.wit b/v2/wit/deps/clocks-2023-11-10/wall-clock.wit new file mode 100644 index 0000000..8abb9a0 --- /dev/null +++ b/v2/wit/deps/clocks-2023-11-10/wall-clock.wit @@ -0,0 +1,42 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; +/// 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/v2/wit/deps/clocks-2023-11-10/world.wit b/v2/wit/deps/clocks-2023-11-10/world.wit new file mode 100644 index 0000000..8fa080f --- /dev/null +++ b/v2/wit/deps/clocks-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:clocks@0.2.0-rc-2023-11-10; + +world imports { + import monotonic-clock; + import wall-clock; +} diff --git a/v2/wit/deps/clocks/monotonic-clock.wit b/v2/wit/deps/clocks/monotonic-clock.wit new file mode 100644 index 0000000..4e4dc3a --- /dev/null +++ b/v2/wit/deps/clocks/monotonic-clock.wit @@ -0,0 +1,45 @@ +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/v2/wit/deps/clocks/wall-clock.wit b/v2/wit/deps/clocks/wall-clock.wit new file mode 100644 index 0000000..440ca0f --- /dev/null +++ b/v2/wit/deps/clocks/wall-clock.wit @@ -0,0 +1,42 @@ +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/v2/wit/deps/clocks/world.wit b/v2/wit/deps/clocks/world.wit new file mode 100644 index 0000000..c022457 --- /dev/null +++ b/v2/wit/deps/clocks/world.wit @@ -0,0 +1,6 @@ +package wasi:clocks@0.2.0; + +world imports { + import monotonic-clock; + import wall-clock; +} diff --git a/v2/wit/deps/filesystem-2023-10-18/preopens.wit b/v2/wit/deps/filesystem-2023-10-18/preopens.wit new file mode 100644 index 0000000..3f787ac --- /dev/null +++ b/v2/wit/deps/filesystem-2023-10-18/preopens.wit @@ -0,0 +1,6 @@ +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/v2/wit/deps/filesystem-2023-10-18/types.wit b/v2/wit/deps/filesystem-2023-10-18/types.wit new file mode 100644 index 0000000..af36135 --- /dev/null +++ b/v2/wit/deps/filesystem-2023-10-18/types.wit @@ -0,0 +1,810 @@ +/// 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-rc-2023-10-18.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0-rc-2023-10-18.{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, + } + + /// Permissions mode used by `open-at`, `change-file-permissions-at`, and + /// similar. + flags modes { + /// True if the resource is considered readable by the containing + /// filesystem. + readable, + /// True if the resource is considered writable by the containing + /// filesystem. + writable, + /// True if the resource is considered executable by the containing + /// filesystem. This does not apply to directories. + executable, + } + + /// Access type used by `access-at`. + variant access-type { + /// Test for readability, writeability, or executability. + access(modes), + + /// Test whether the path exists. + exists, + } + + /// 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, + /// Permissions to use when creating a new file. + modes: modes + ) -> 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>; + + /// Check accessibility of a filesystem path. + /// + /// Check whether the given filesystem path names an object which is + /// readable, writable, or executable, or whether it exists. + /// + /// This does not a guarantee that subsequent accesses will succeed, as + /// filesystem permissions may be modified asynchronously by external + /// entities. + /// + /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. + access-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to check. + path: string, + /// The type of check to perform. + %type: access-type + ) -> 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>; + + /// Change the permissions of a filesystem object that is not a directory. + /// + /// Note that the ultimate meanings of these permissions is + /// filesystem-specific. + /// + /// Note: This is similar to `fchmodat` in POSIX. + change-file-permissions-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to operate on. + path: string, + /// The new permissions for the filesystem object. + modes: modes, + ) -> result<_, error-code>; + + /// Change the permissions of a directory. + /// + /// Note that the ultimate meanings of these permissions is + /// filesystem-specific. + /// + /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" + /// flag. `read` on a directory implies readability and searchability, and + /// `execute` is not valid for directories. + /// + /// Note: This is similar to `fchmodat` in POSIX. + change-directory-permissions-at: func( + /// Flags determining the method of how the path is resolved. + path-flags: path-flags, + /// The relative path to operate on. + path: string, + /// The new permissions for the directory. + modes: modes, + ) -> result<_, error-code>; + + /// Request a shared advisory lock for an open file. + /// + /// This requests a *shared* lock; more than one shared lock can be held for + /// a file at the same time. + /// + /// If the open file has an exclusive lock, this function downgrades the lock + /// to a shared lock. If it has a shared lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified how shared locks interact with locks acquired by + /// non-WASI programs. + /// + /// This function blocks until the lock can be acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix. + lock-shared: func() -> result<_, error-code>; + + /// Request an exclusive advisory lock for an open file. + /// + /// This requests an *exclusive* lock; no other locks may be held for the + /// file while an exclusive lock is held. + /// + /// If the open file has a shared lock and there are no exclusive locks held + /// for the file, this function upgrades the lock to an exclusive lock. If the + /// open file already has an exclusive lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified whether this function succeeds if the file descriptor + /// is not opened for writing. It is unspecified how exclusive locks interact + /// with locks acquired by non-WASI programs. + /// + /// This function blocks until the lock can be acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix. + lock-exclusive: func() -> result<_, error-code>; + + /// Request a shared advisory lock for an open file. + /// + /// This requests a *shared* lock; more than one shared lock can be held for + /// a file at the same time. + /// + /// If the open file has an exclusive lock, this function downgrades the lock + /// to a shared lock. If it has a shared lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified how shared locks interact with locks acquired by + /// non-WASI programs. + /// + /// This function returns `error-code::would-block` if the lock cannot be + /// acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. + try-lock-shared: func() -> result<_, error-code>; + + /// Request an exclusive advisory lock for an open file. + /// + /// This requests an *exclusive* lock; no other locks may be held for the + /// file while an exclusive lock is held. + /// + /// If the open file has a shared lock and there are no exclusive locks held + /// for the file, this function upgrades the lock to an exclusive lock. If the + /// open file already has an exclusive lock, this function has no effect. + /// + /// This requests an *advisory* lock, meaning that the file could be accessed + /// by other programs that don't hold the lock. + /// + /// It is unspecified whether this function succeeds if the file descriptor + /// is not opened for writing. It is unspecified how exclusive locks interact + /// with locks acquired by non-WASI programs. + /// + /// This function returns `error-code::would-block` if the lock cannot be + /// acquired. + /// + /// Not all filesystems support locking; on filesystems which don't support + /// locking, this function returns `error-code::unsupported`. + /// + /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. + try-lock-exclusive: func() -> result<_, error-code>; + + /// Release a shared or exclusive lock on an open file. + /// + /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix. + unlock: func() -> 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/v2/wit/deps/filesystem-2023-10-18/world.wit b/v2/wit/deps/filesystem-2023-10-18/world.wit new file mode 100644 index 0000000..3f953f8 --- /dev/null +++ b/v2/wit/deps/filesystem-2023-10-18/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0-rc-2023-10-18; + +world imports { + import types; + import preopens; +} diff --git a/v2/wit/deps/filesystem-2023-11-10/preopens.wit b/v2/wit/deps/filesystem-2023-11-10/preopens.wit new file mode 100644 index 0000000..95ec678 --- /dev/null +++ b/v2/wit/deps/filesystem-2023-11-10/preopens.wit @@ -0,0 +1,8 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; + +interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; +} diff --git a/v2/wit/deps/filesystem-2023-11-10/types.wit b/v2/wit/deps/filesystem-2023-11-10/types.wit new file mode 100644 index 0000000..059722a --- /dev/null +++ b/v2/wit/deps/filesystem-2023-11-10/types.wit @@ -0,0 +1,634 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; +/// 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-rc-2023-11-10.{input-stream, output-stream, error}; + use wasi:clocks/wall-clock@0.2.0-rc-2023-11-10.{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/v2/wit/deps/filesystem-2023-11-10/world.wit b/v2/wit/deps/filesystem-2023-11-10/world.wit new file mode 100644 index 0000000..285e0ba --- /dev/null +++ b/v2/wit/deps/filesystem-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0-rc-2023-11-10; + +world imports { + import types; + import preopens; +} diff --git a/v2/wit/deps/filesystem/preopens.wit b/v2/wit/deps/filesystem/preopens.wit new file mode 100644 index 0000000..da801f6 --- /dev/null +++ b/v2/wit/deps/filesystem/preopens.wit @@ -0,0 +1,8 @@ +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/v2/wit/deps/filesystem/types.wit b/v2/wit/deps/filesystem/types.wit new file mode 100644 index 0000000..11108fc --- /dev/null +++ b/v2/wit/deps/filesystem/types.wit @@ -0,0 +1,634 @@ +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/v2/wit/deps/filesystem/world.wit b/v2/wit/deps/filesystem/world.wit new file mode 100644 index 0000000..663f579 --- /dev/null +++ b/v2/wit/deps/filesystem/world.wit @@ -0,0 +1,6 @@ +package wasi:filesystem@0.2.0; + +world imports { + import types; + import preopens; +} diff --git a/v2/wit/deps/http-2023-10-18/incoming-handler.wit b/v2/wit/deps/http-2023-10-18/incoming-handler.wit new file mode 100644 index 0000000..6968d63 --- /dev/null +++ b/v2/wit/deps/http-2023-10-18/incoming-handler.wit @@ -0,0 +1,24 @@ +// The `wasi:http/incoming-handler` interface is meant to be exported by +// components and called by the host in response to a new incoming HTTP +// response. +// +// NOTE: in Preview3, this interface will be merged with +// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface +// that takes a `request` parameter and returns a `response` result. +// +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + // The `handle` function takes an outparam instead of returning its response + // so that the component may stream its response while streaming any other + // request or response bodies. The callee MUST write a response to the + // `response-outparam` and then finish the response before returning. The `handle` + // function is allowed to continue execution after finishing the response's + // output stream. While this post-response execution is taken off the + // critical path, since there is no return value, there is no way to report + // its success or failure. + handle: func( + request: incoming-request, + response-out: response-outparam + ); +} diff --git a/v2/wit/deps/http-2023-10-18/outgoing-handler.wit b/v2/wit/deps/http-2023-10-18/outgoing-handler.wit new file mode 100644 index 0000000..286e283 --- /dev/null +++ b/v2/wit/deps/http-2023-10-18/outgoing-handler.wit @@ -0,0 +1,20 @@ +// The `wasi:http/outgoing-handler` interface is meant to be imported by +// components and implemented by the host. +// +// NOTE: in Preview3, this interface will be merged with +// `wasi:http/outgoing-handler` into a single `wasi:http/handler` interface +// that takes a `request` parameter and returns a `response` result. +// +interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error}; + + // The parameter and result types of the `handle` function allow the caller + // to concurrently stream the bodies of the outgoing request and the incoming + // response. + // Consumes the outgoing-request. Gives an error if the outgoing-request + // is invalid or cannot be satisfied by this handler. + handle: func( + request: outgoing-request, + options: option + ) -> result; +} diff --git a/v2/wit/deps/http-2023-10-18/proxy.wit b/v2/wit/deps/http-2023-10-18/proxy.wit new file mode 100644 index 0000000..dde0659 --- /dev/null +++ b/v2/wit/deps/http-2023-10-18/proxy.wit @@ -0,0 +1,34 @@ +package wasi:http@0.2.0-rc-2023-10-18; + +// 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. + import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18; + import wasi:clocks/timezone@0.2.0-rc-2023-10-18; + import wasi:random/random@0.2.0-rc-2023-10-18; + + // 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-rc-2023-10-18; + import wasi:cli/stderr@0.2.0-rc-2023-10-18; + + // 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-rc-2023-10-18; + + // 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/v2/wit/deps/http-2023-10-18/types.wit b/v2/wit/deps/http-2023-10-18/types.wit new file mode 100644 index 0000000..2471f04 --- /dev/null +++ b/v2/wit/deps/http-2023-10-18/types.wit @@ -0,0 +1,208 @@ +/// The `wasi:http/types` interface is meant to be imported by components to +/// define the HTTP resource types and operations used by the component's +/// imported and exported interfaces. +interface types { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + + // This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string) + } + + // TODO: perhaps better align with HTTP semantics? + /// This type enumerates the different kinds of errors that may occur when + /// initially returning a response. + variant error { + invalid-url(string), + timeout-error(string), + protocol-error(string), + unexpected-error(string) + } + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. + resource fields { + // Multiple values for a header are multiple entries in the list with the + // same key. + constructor(entries: list>>); + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + get: func(name: string) -> list>; + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + set: func(name: string, value: list>); + delete: func(name: string); + append: func(name: string, value: list); + + // Values off wire are not necessarily well formed, so they are given by + // list instead of string. + entries: func() -> list>>; + + // Deep copy of all contents in a fields. + clone: func() -> fields; + } + + type headers = fields; + type trailers = fields; + + /// The following block defines the `incoming-request` and `outgoing-request` + /// resource types that correspond to HTTP standard Requests. + /// + /// The `consume` and `write` methods may only be called once (and + /// return failure thereafter). + resource incoming-request { + method: func() -> method; + + path-with-query: func() -> option; + + scheme: func() -> option; + + authority: func() -> option; + + headers: func() -> /* child */ headers; + + /// Returns the input-stream child at most once. + /// + /// If called more than once, subsequent calls return an error. + consume: func() -> result; + } + + resource outgoing-request { + constructor( + method: method, + path-with-query: option, + scheme: option, + authority: option, + headers: borrow + ); + + /// Will return the outgoing-body child at most once. + /// + /// If called more than once, subsequent calls return an error. + write: func() -> result< /* child */ outgoing-body>; + } + + /// Additional optional parameters that can be set when making a request. + record request-options { + // The following timeouts are specific to the HTTP protocol and work + // independently of the overall timeouts passed to `io.poll.poll-list`. + + /// The timeout for the initial connect. + connect-timeout-ms: option, + + /// The timeout for receiving the first byte of the response body. + first-byte-timeout-ms: option, + + /// The timeout for receiving the next chunk of bytes in the response body + /// stream. + between-bytes-timeout-ms: option + } + + /// The following block defines a special resource type used by the + /// `wasi:http/incoming-handler` interface. When resource types are added, this + /// block can be replaced by a proper `resource response-outparam { ... }` + /// definition. Later, with Preview3, the need for an outparam goes away entirely + /// (the `wasi:http/handler` interface used for both incoming and outgoing can + /// simply return a `stream`). + resource response-outparam { + set: static func(param: response-outparam, response: result); + } + + // This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// The following block defines the `incoming-response` and `outgoing-response` + /// resource types that correspond to HTTP standard Responses. + /// + /// The `consume` and `write` methods may only be called once (and return failure thereafter). + resource incoming-response { + status: func() -> status-code; + + headers: func() -> /* child */ headers; + + // May be called at most once. returns error if called additional times. + // TODO: make incoming-request-consume work the same way, giving a child + // incoming-body. + consume: func() -> result; + } + + resource incoming-body { + // returned input-stream is a child - the implementation may trap if + // incoming-body is dropped (or consumed by call to + // incoming-body-finish) before the input-stream is dropped. + // May be called at most once. returns error if called additional times. + %stream: func() -> result; + + // takes ownership of incoming-body. this will trap if the + // incoming-body-stream child is still alive! + finish: static func(this: incoming-body) -> + /* transitive child of the incoming-response of incoming-body */ future-trailers; + } + + resource future-trailers { + /// Pollable that resolves when the body has been fully read, and the trailers + /// are ready to be consumed. + subscribe: func() -> /* child */ pollable; + + /// Retrieve reference to trailers, if they are ready. + get: func() -> option>; + } + + resource outgoing-response { + constructor(status-code: status-code, headers: borrow); + + /// Will give the child outgoing-response at most once. subsequent calls will + /// return an error. + write: func() -> result; + } + + resource outgoing-body { + /// Will give the child output-stream at most once. subsequent calls will + /// return an 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 + /// should treat the body as corrupted. + finish: static func(this: outgoing-body, trailers: option); + } + + /// The following block defines a special resource type used by the + /// `wasi:http/outgoing-handler` interface to emulate + /// `future>` in advance of Preview3. Given a + /// `future-incoming-response`, the client can call the non-blocking `get` + /// method to get the result if it is available. If the result is not available, + /// the client can call `listen` to get a `pollable` that can be passed to + /// `wasi:io/poll.poll-list`. + resource future-incoming-response { + /// option indicates readiness. + /// outer result indicates you are allowed to get the + /// incoming-response-or-error at most once. subsequent calls after ready + /// will return an error here. + /// inner result indicates whether the incoming-response was available, or an + /// error occured. + get: func() -> option>>; + + subscribe: func() -> /* child */ pollable; + } +} diff --git a/v2/wit/deps/http-2023-11-10/handler.wit b/v2/wit/deps/http-2023-11-10/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/v2/wit/deps/http-2023-11-10/handler.wit @@ -0,0 +1,43 @@ +/// 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/v2/wit/deps/http-2023-11-10/proxy.wit b/v2/wit/deps/http-2023-11-10/proxy.wit new file mode 100644 index 0000000..453f590 --- /dev/null +++ b/v2/wit/deps/http-2023-11-10/proxy.wit @@ -0,0 +1,33 @@ +package wasi:http@0.2.0-rc-2023-11-10; + +/// 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. + import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import wasi:random/random@0.2.0-rc-2023-11-10; + + /// 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-rc-2023-11-10; + import wasi:cli/stderr@0.2.0-rc-2023-11-10; + + /// 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-rc-2023-11-10; + + /// 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/v2/wit/deps/http-2023-11-10/types.wit b/v2/wit/deps/http-2023-11-10/types.wit new file mode 100644 index 0000000..1dd4214 --- /dev/null +++ b/v2/wit/deps/http-2023-11-10/types.wit @@ -0,0 +1,559 @@ +/// 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. +interface types { + use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{duration}; + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; + use wasi:io/error@0.2.0-rc-2023-11-10.{error as io-error}; + use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string) + } + + /// 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 + variant error-code { + DNS-timeout, + DNS-error(DNS-error-payload), + destination-not-found, + destination-unavailable, + destination-IP-prohibited, + destination-IP-unroutable, + connection-refused, + connection-terminated, + connection-timeout, + connection-read-timeout, + connection-write-timeout, + connection-limit-reached, + TLS-protocol-error, + TLS-certificate-error, + TLS-alert-received(TLS-alert-received-payload), + HTTP-request-denied, + HTTP-request-length-required, + HTTP-request-body-size(option), + HTTP-request-method-invalid, + HTTP-request-URI-invalid, + HTTP-request-URI-too-long, + HTTP-request-header-section-size(option), + HTTP-request-header-size(option), + HTTP-request-trailer-section-size(option), + HTTP-request-trailer-size(field-size-payload), + HTTP-response-incomplete, + HTTP-response-header-section-size(option), + HTTP-response-header-size(field-size-payload), + HTTP-response-body-size(option), + HTTP-response-trailer-section-size(option), + HTTP-response-trailer-size(field-size-payload), + HTTP-response-transfer-coding(option), + HTTP-response-content-coding(option), + HTTP-response-timeout, + HTTP-upgrade-failed, + HTTP-protocol-error, + loop-detected, + configuration-error, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// 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 + } + + /// 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 { + /// This error indicates that a `field-key` or `field-value` was + /// 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, + } + + /// Field keys are always strings. + type field-key = string; + + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + type field-value = list; + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + resource fields { + + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + constructor(); + + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The 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. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. In a valid Fields, all keys + /// and values are valid UTF-8 strings. However, values are not always + /// well-formed, so they are represented as a raw list of bytes. + /// + /// 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; + + /// Get all of the values corresponding to a key. + get: func(name: field-key) -> list; + + /// 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>; + + /// 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. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + 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; + } + + /// 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`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// 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 + ); + + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + 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; + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + set-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; + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + 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. + authority: func() -> option; + /// Set the HTTP Authority for the Request. A value of `none` may be used + /// with Related Schemes which do not require an Authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + set-authority: func(authority: option) -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transfered to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + } + + /// Parameters for making an HTTP Request. Each of these parameters is an + /// optional timeout, with the unit in milliseconds, applicable to the + /// transport layer of the HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + + /// The timeout for the initial connect to the HTTP Server. + connect-timeout-ms: 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-ms: func(ms: option) -> result; + + /// The timeout for receiving the first byte of the Response body. + first-byte-timeout-ms: 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-ms: func(ms: option) -> result; + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + between-bytes-timeout-ms: 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. + set-between-bytes-timeout-ms: func(ms: option) -> result; + } + + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + resource response-outparam { + + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// 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, + ); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// 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; + } + + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + resource incoming-body { + + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + %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; + } + + /// Represents a future which may eventaully return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + 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. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The `result` represents that either the HTTP Request or Response body, + /// as well as any trailers, were received successfully, or that an error + /// occured receiving them. The optional `trailers` indicates whether or not + /// trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + get: func() -> option, error-code>>; + } + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `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 + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + } + + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occured. The implementation should propogate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + resource outgoing-body { + + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + 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 + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// 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>; + } + + /// Represents a future which may eventaully return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + resource future-incoming-response { + /// Returns a pollable which becomes ready when either the Response has + /// 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 + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have recieved successfully, or that an error + /// occured. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + get: func() -> option>>; + + } +} diff --git a/v2/wit/deps/http/handler.wit b/v2/wit/deps/http/handler.wit new file mode 100644 index 0000000..a34a064 --- /dev/null +++ b/v2/wit/deps/http/handler.wit @@ -0,0 +1,43 @@ +/// 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/v2/wit/deps/http/proxy.wit b/v2/wit/deps/http/proxy.wit new file mode 100644 index 0000000..687c24d --- /dev/null +++ b/v2/wit/deps/http/proxy.wit @@ -0,0 +1,32 @@ +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/v2/wit/deps/http/types.wit b/v2/wit/deps/http/types.wit new file mode 100644 index 0000000..755ac6a --- /dev/null +++ b/v2/wit/deps/http/types.wit @@ -0,0 +1,570 @@ +/// 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. +interface types { + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use wasi:io/streams@0.2.0.{input-stream, output-stream}; + use wasi:io/error@0.2.0.{error as io-error}; + use wasi:io/poll@0.2.0.{pollable}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string) + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string) + } + + /// 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 + variant error-code { + DNS-timeout, + DNS-error(DNS-error-payload), + destination-not-found, + destination-unavailable, + destination-IP-prohibited, + destination-IP-unroutable, + connection-refused, + connection-terminated, + connection-timeout, + connection-read-timeout, + connection-write-timeout, + connection-limit-reached, + TLS-protocol-error, + TLS-certificate-error, + TLS-alert-received(TLS-alert-received-payload), + HTTP-request-denied, + HTTP-request-length-required, + HTTP-request-body-size(option), + HTTP-request-method-invalid, + HTTP-request-URI-invalid, + HTTP-request-URI-too-long, + HTTP-request-header-section-size(option), + HTTP-request-header-size(option), + HTTP-request-trailer-section-size(option), + HTTP-request-trailer-size(field-size-payload), + HTTP-response-incomplete, + HTTP-response-header-section-size(option), + HTTP-response-header-size(field-size-payload), + HTTP-response-body-size(option), + HTTP-response-trailer-section-size(option), + HTTP-response-trailer-size(field-size-payload), + HTTP-response-transfer-coding(option), + HTTP-response-content-coding(option), + HTTP-response-timeout, + HTTP-upgrade-failed, + HTTP-protocol-error, + loop-detected, + configuration-error, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// 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 + } + + /// 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 { + /// This error indicates that a `field-key` or `field-value` was + /// 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, + } + + /// Field keys are always strings. + type field-key = string; + + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + type field-value = list; + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + resource fields { + + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + constructor(); + + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The 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. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. In a valid Fields, all keys + /// and values are valid UTF-8 strings. However, values are not always + /// well-formed, so they are represented as a raw list of bytes. + /// + /// 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; + + /// 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>; + + /// 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. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + 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; + } + + /// 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`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// 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 + ); + + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + 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; + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + set-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; + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + 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. + authority: func() -> option; + /// Set the HTTP Authority for the Request. A value of `none` may be used + /// with Related Schemes which do not require an Authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + set-authority: func(authority: option) -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transfered to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + } + + /// Parameters for making an HTTP Request. Each of these parameters is + /// currently an optional timeout applicable to the transport layer of the + /// HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + 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. + set-between-bytes-timeout: func(duration: option) -> result; + } + + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + resource response-outparam { + + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// 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, + ); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// 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; + } + + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + resource incoming-body { + + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + %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; + } + + /// Represents a future which may eventaully return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + 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. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the trailers or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the HTTP Request or Response + /// body, as well as any trailers, were received successfully, or that an + /// error occured receiving them. The optional `trailers` indicates whether + /// or not trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + get: func() -> option, error-code>>>; + } + + /// 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 + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `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 + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + } + + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occured. The implementation should propogate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + resource outgoing-body { + + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + 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 + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// 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>; + } + + /// Represents a future which may eventaully return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + resource future-incoming-response { + /// Returns a pollable which becomes ready when either the Response has + /// 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 + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have recieved successfully, or that an error + /// occured. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + get: func() -> option>>; + + } +} diff --git a/v2/wit/deps/io-2023-10-18/poll.wit b/v2/wit/deps/io-2023-10-18/poll.wit new file mode 100644 index 0000000..74835e6 --- /dev/null +++ b/v2/wit/deps/io-2023-10-18/poll.wit @@ -0,0 +1,32 @@ +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// A "pollable" handle. + resource pollable; + + /// 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-list: func(in: list>) -> list; + + /// Poll for completion on a single pollable. + /// + /// This function is similar to `poll-list`, but operates on only a single + /// pollable. When it returns, the handle is ready for I/O. + poll-one: func(in: borrow); +} diff --git a/v2/wit/deps/io-2023-10-18/streams.wit b/v2/wit/deps/io-2023-10-18/streams.wit new file mode 100644 index 0000000..c9600b7 --- /dev/null +++ b/v2/wit/deps/io-2023-10-18/streams.wit @@ -0,0 +1,287 @@ +/// 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 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 + } + + /// Contextual error information about the last failure that happened on + /// a read, write, or flush from an `input-stream` or `output-stream`. + /// + /// This type is returned through the `stream-error` type whenever an + /// operation on a stream directly fails or an error is discovered + /// after-the-fact, for example when a write's failure shows up through a + /// later `flush` or `check-write`. + /// + /// Interfaces such as `wasi:filesystem/types` provide functionality to + /// further "downcast" this error into interface-specific error information. + resource error { + /// Returns a string that's suitable to assist humans in debugging this + /// error. + /// + /// The returned string will change across platforms and hosts which + /// means that parsing it, for example, would be a + /// platform-compatibility hazard. + to-debug-string: func() -> string; + } + + /// 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. + /// + /// This function returns a list of bytes containing the data that was + /// read, along with a `stream-status` which, indicates whether further + /// reads are expected to produce data. The returned list will contain up to + /// `len` bytes; it may return fewer than requested, but not more. An + /// empty list and `stream-status:open` indicates no more data is + /// available at this time, and that the pollable given by `subscribe` + /// will be ready when more data is available. + /// + /// Once a stream has reached the end, subsequent calls to `read` or + /// `skip` will always report `stream-status:ended` rather than producing more + /// data. + /// + /// When the caller gives a `len` of 0, it represents a request to read 0 + /// bytes. This read should always succeed and return an empty list and + /// the current `stream-status`. + /// + /// 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, identical to `read`. + blocking-read: func( + /// The maximum number of bytes to read + len: u64 + ) -> result, stream-error>; + + /// Skip bytes from a stream. + /// + /// This is similar to the `read` function, but avoids copying the + /// bytes into the instance. + /// + /// Once a stream has reached the end, subsequent calls to read or + /// `skip` will always report end-of-stream rather than producing more + /// data. + /// + /// This function returns the number of bytes skipped, along with a + /// `stream-status` indicating whether the end of the stream was + /// reached. The returned value will be at most `len`; it may be less. + 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. + /// + /// 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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 + /// poll-one(pollable); + /// let Ok(n) = this.check-write(); // eliding error handling + /// let len = min(n, num_zeroes); + /// this.write-zeroes(len); // eliding error handling + /// num_zeroes -= len; + /// } + /// this.flush(); + /// // Wait for completion of `flush` + /// poll-one(pollable); + /// // 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. + /// + /// This function returns the number of bytes transferred; it may be less + /// than `len`. + /// + /// Unlike other I/O functions, this function blocks until all the data + /// read from the input stream has been written to the output stream. + splice: func( + /// The stream to read from + src: input-stream, + /// 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 at least + /// one byte can be read. + blocking-splice: func( + /// The stream to read from + src: input-stream, + /// The number of bytes to splice + len: u64, + ) -> result; + + /// Forward the entire contents of an input stream to an output stream. + /// + /// This function repeatedly reads from the input stream and writes + /// the data to the output stream, until the end of the input stream + /// is reached, or an error is encountered. + /// + /// Unlike other I/O functions, this function blocks until the end + /// of the input stream is seen and all the data has been written to + /// the output stream. + /// + /// This function returns the number of bytes transferred, and the status of + /// the output stream. + forward: func( + /// The stream to read from + src: input-stream + ) -> result; + } +} diff --git a/v2/wit/deps/io-2023-10-18/world.wit b/v2/wit/deps/io-2023-10-18/world.wit new file mode 100644 index 0000000..a0bcd31 --- /dev/null +++ b/v2/wit/deps/io-2023-10-18/world.wit @@ -0,0 +1 @@ +package wasi:io@0.2.0-rc-2023-10-18; diff --git a/v2/wit/deps/io-2023-11-10/error.wit b/v2/wit/deps/io-2023-11-10/error.wit new file mode 100644 index 0000000..31918ac --- /dev/null +++ b/v2/wit/deps/io-2023-11-10/error.wit @@ -0,0 +1,34 @@ +package wasi:io@0.2.0-rc-2023-11-10; + + +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/v2/wit/deps/io-2023-11-10/poll.wit b/v2/wit/deps/io-2023-11-10/poll.wit new file mode 100644 index 0000000..bddde3c --- /dev/null +++ b/v2/wit/deps/io-2023-11-10/poll.wit @@ -0,0 +1,41 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +/// A poll API intended to let users wait for I/O events on multiple handles +/// at once. +interface poll { + /// `pollable` epresents 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/v2/wit/deps/io-2023-11-10/streams.wit b/v2/wit/deps/io-2023-11-10/streams.wit new file mode 100644 index 0000000..e7e1b68 --- /dev/null +++ b/v2/wit/deps/io-2023-11-10/streams.wit @@ -0,0 +1,251 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +/// 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. + /// + /// 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. + /// + /// 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 + /// poll-one(pollable); + /// 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` + /// poll-one(pollable); + /// // 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 + /// poll-one(pollable); + /// let Ok(n) = this.check-write(); // eliding error handling + /// let len = min(n, num_zeroes); + /// this.write-zeroes(len); // eliding error handling + /// num_zeroes -= len; + /// } + /// this.flush(); + /// // Wait for completion of `flush` + /// poll-one(pollable); + /// // 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/v2/wit/deps/io-2023-11-10/world.wit b/v2/wit/deps/io-2023-11-10/world.wit new file mode 100644 index 0000000..8243da2 --- /dev/null +++ b/v2/wit/deps/io-2023-11-10/world.wit @@ -0,0 +1,6 @@ +package wasi:io@0.2.0-rc-2023-11-10; + +world imports { + import streams; + import poll; +} diff --git a/v2/wit/deps/io/error.wit b/v2/wit/deps/io/error.wit new file mode 100644 index 0000000..22e5b64 --- /dev/null +++ b/v2/wit/deps/io/error.wit @@ -0,0 +1,34 @@ +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/v2/wit/deps/io/poll.wit b/v2/wit/deps/io/poll.wit new file mode 100644 index 0000000..ddc67f8 --- /dev/null +++ b/v2/wit/deps/io/poll.wit @@ -0,0 +1,41 @@ +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/v2/wit/deps/io/streams.wit b/v2/wit/deps/io/streams.wit new file mode 100644 index 0000000..6d2f871 --- /dev/null +++ b/v2/wit/deps/io/streams.wit @@ -0,0 +1,262 @@ +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/v2/wit/deps/io/world.wit b/v2/wit/deps/io/world.wit new file mode 100644 index 0000000..5f0b43f --- /dev/null +++ b/v2/wit/deps/io/world.wit @@ -0,0 +1,6 @@ +package wasi:io@0.2.0; + +world imports { + import streams; + import poll; +} diff --git a/v2/wit/deps/random-2023-10-18/insecure-seed.wit b/v2/wit/deps/random-2023-10-18/insecure-seed.wit new file mode 100644 index 0000000..139aed1 --- /dev/null +++ b/v2/wit/deps/random-2023-10-18/insecure-seed.wit @@ -0,0 +1,24 @@ +/// 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/v2/wit/deps/random-2023-10-18/insecure.wit b/v2/wit/deps/random-2023-10-18/insecure.wit new file mode 100644 index 0000000..2ffd223 --- /dev/null +++ b/v2/wit/deps/random-2023-10-18/insecure.wit @@ -0,0 +1,21 @@ +/// 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/v2/wit/deps/random-2023-10-18/random.wit b/v2/wit/deps/random-2023-10-18/random.wit new file mode 100644 index 0000000..2c3c6a8 --- /dev/null +++ b/v2/wit/deps/random-2023-10-18/random.wit @@ -0,0 +1,25 @@ +/// 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/v2/wit/deps/random-2023-10-18/world.wit b/v2/wit/deps/random-2023-10-18/world.wit new file mode 100644 index 0000000..dcbff93 --- /dev/null +++ b/v2/wit/deps/random-2023-10-18/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0-rc-2023-10-18; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/v2/wit/deps/random-2023-11-10/insecure-seed.wit b/v2/wit/deps/random-2023-11-10/insecure-seed.wit new file mode 100644 index 0000000..f76e87d --- /dev/null +++ b/v2/wit/deps/random-2023-11-10/insecure-seed.wit @@ -0,0 +1,25 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/v2/wit/deps/random-2023-11-10/insecure.wit b/v2/wit/deps/random-2023-11-10/insecure.wit new file mode 100644 index 0000000..ec7b997 --- /dev/null +++ b/v2/wit/deps/random-2023-11-10/insecure.wit @@ -0,0 +1,22 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/v2/wit/deps/random-2023-11-10/random.wit b/v2/wit/deps/random-2023-11-10/random.wit new file mode 100644 index 0000000..7a7dfa2 --- /dev/null +++ b/v2/wit/deps/random-2023-11-10/random.wit @@ -0,0 +1,26 @@ +package wasi:random@0.2.0-rc-2023-11-10; +/// 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/v2/wit/deps/random-2023-11-10/world.wit b/v2/wit/deps/random-2023-11-10/world.wit new file mode 100644 index 0000000..49e5743 --- /dev/null +++ b/v2/wit/deps/random-2023-11-10/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0-rc-2023-11-10; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/v2/wit/deps/random/insecure-seed.wit b/v2/wit/deps/random/insecure-seed.wit new file mode 100644 index 0000000..47210ac --- /dev/null +++ b/v2/wit/deps/random/insecure-seed.wit @@ -0,0 +1,25 @@ +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/v2/wit/deps/random/insecure.wit b/v2/wit/deps/random/insecure.wit new file mode 100644 index 0000000..c58f4ee --- /dev/null +++ b/v2/wit/deps/random/insecure.wit @@ -0,0 +1,22 @@ +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/v2/wit/deps/random/random.wit b/v2/wit/deps/random/random.wit new file mode 100644 index 0000000..0c017f0 --- /dev/null +++ b/v2/wit/deps/random/random.wit @@ -0,0 +1,26 @@ +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/v2/wit/deps/random/world.wit b/v2/wit/deps/random/world.wit new file mode 100644 index 0000000..3da3491 --- /dev/null +++ b/v2/wit/deps/random/world.wit @@ -0,0 +1,7 @@ +package wasi:random@0.2.0; + +world imports { + import random; + import insecure; + import insecure-seed; +} diff --git a/v2/wit/deps/sockets-2023-10-18/instance-network.wit b/v2/wit/deps/sockets-2023-10-18/instance-network.wit new file mode 100644 index 0000000..14e4479 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/instance-network.wit @@ -0,0 +1,9 @@ + +/// 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/v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit b/v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit new file mode 100644 index 0000000..f2dab32 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit @@ -0,0 +1,61 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + use network.{network, error-code, ip-address, ip-address-family}; + + + /// Resolve an internet host name to a list of IP addresses. + /// + /// See the wasi-socket proposal README.md for a comparison with getaddrinfo. + /// + /// # Parameters + /// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted + /// to ASCII using IDNA encoding. + /// - `address-family`: If provided, limit the results to addresses of this specific address family. + /// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime + /// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on + /// systems without an active IPv6 interface. Notes: + /// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. + /// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. + /// + /// 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. + /// + /// At the moment, the stream never completes successfully with 0 items. Ie. the first call + /// to `resolve-next-address` never returns `ok(none)`. This may change in the future. + /// + /// # Typical errors + /// - `invalid-argument`: `name` is a syntactically invalid domain name. + /// - `invalid-argument`: `name` is an IP address. + /// - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) + /// + /// # References: + /// - + /// - + /// - + /// - + resolve-addresses: func(network: borrow, name: string, address-family: option, include-unavailable: bool) -> 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/v2/wit/deps/sockets-2023-10-18/network.wit b/v2/wit/deps/sockets-2023-10-18/network.wit new file mode 100644 index 0000000..fc51604 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/network.wit @@ -0,0 +1,146 @@ + +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 { + // ### GENERAL ERRORS ### + + /// 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, + + + + // ### TCP & UDP SOCKET ERRORS ### + + /// 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, + + + // ### TCP SOCKET ERRORS ### + + /// The connection was forcefully rejected + connection-refused, + + /// The connection was reset. + connection-reset, + + /// A connection was aborted. + connection-aborted, + + // ### UDP SOCKET ERRORS ### + datagram-too-large, + + + // ### NAME LOOKUP ERRORS ### + + /// 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 { + port: u16, // sin_port + address: ipv4-address, // sin_addr + } + + record ipv6-socket-address { + port: u16, // sin6_port + flow-info: u32, // sin6_flowinfo + address: ipv6-address, // sin6_addr + scope-id: u32, // sin6_scope_id + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } + +} diff --git a/v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit b/v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit new file mode 100644 index 0000000..a9a3373 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// This function does not require a network capability handle. This is considered to be safe because + /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`listen`/`connect` + /// 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/v2/wit/deps/sockets-2023-10-18/tcp.wit b/v2/wit/deps/sockets-2023-10-18/tcp.wit new file mode 100644 index 0000000..448f629 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/tcp.wit @@ -0,0 +1,268 @@ + +interface tcp { + use wasi:io/streams@0.2.0-rc-2023-10-18.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + 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 handle. + 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. + /// + /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will + /// implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 + /// + /// POSIX mentions: + /// > If connect() fails, the state of the socket is unspecified. Conforming applications should + /// > close the file descriptor and create a new socket before attempting to reconnect. + /// + /// WASI prescribes the following behavior: + /// - If `connect` fails because an input/state validation error, the socket should remain usable. + /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + /// Besides `drop`, any method after such a failure may return an error. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 Connection state. (EISCONN) + /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + /// + /// # Typical `finish` errors + /// - `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) + /// - `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) + /// + /// # 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 Listener state. + /// + /// Unlike POSIX: + /// - this function is async. This enables interactive WASI hosts to inject permission prompts. + /// - the socket must already be explicitly bound. + /// + /// # Typical `start` errors + /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + /// - `invalid-state`: The socket is already in the Listener state. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Connection state. The following properties are inherited from the listener socket: + /// - `address-family` + /// - `ipv6-only` + /// - `keep-alive` + /// - `no-delay` + /// - `unicast-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 Listener 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 this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + address-family: func() -> ip-address-family; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// Hints the desired listen queue size. Implementations are free to ignore this. + /// + /// # Typical errors + /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. + /// - `invalid-state`: (set) The socket is already in the Connection state. + set-listen-backlog-size: func(value: u64) -> result<_, error-code>; + + /// Equivalent to the SO_KEEPALIVE socket option. + keep-alive: func() -> result; + set-keep-alive: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the TCP_NODELAY socket option. + /// + /// The default value is `false`. + no-delay: func() -> result; + set-no-delay: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + /// + /// # Typical errors + /// - `invalid-argument`: (set) The TTL value must be 1 or higher. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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. + /// + /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. + /// In other words, after setting a value, reading the same setting back may return a different value. + /// + /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + /// actual data to be sent/received by the application, because the kernel might also use the buffer space + /// for internal metadata structures. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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; + + /// Initiate a graceful shutdown. + /// + /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read + /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. + /// Any data still in the receive queue at time of calling `shutdown` will be discarded. + /// - send: the socket is not expecting to send any more data to the peer. All subsequent write + /// operations on the `output-stream` associated with this socket will return an error. + /// - both: same effect as receive & send combined. + /// + /// The shutdown function does not close (drop) the socket. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} diff --git a/v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit b/v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit new file mode 100644 index 0000000..e026359 --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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-udp-socket: func(address-family: ip-address-family) -> result; +} diff --git a/v2/wit/deps/sockets-2023-10-18/udp.wit b/v2/wit/deps/sockets-2023-10-18/udp.wit new file mode 100644 index 0000000..91a8c6c --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/udp.wit @@ -0,0 +1,213 @@ + +interface udp { + use wasi:io/poll@0.2.0-rc-2023-10-18.{pollable}; + use network.{network, error-code, ip-socket-address, ip-address-family}; + + + record datagram { + data: list, // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + remote-address: ip-socket-address, + + /// Possible future additions: + /// local-address: ip-socket-address, // IP_PKTINFO / IP_RECVDSTADDR / IPV6_PKTINFO + /// local-interface: u32, // IP_PKTINFO / IP_RECVIF + /// ttl: u8, // IP_RECVTTL + /// dscp: u6, // IP_RECVTOS + /// ecn: u2, // IP_RECVTOS + } + + + + /// 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 TCP/UDP port is zero, the socket will be bound to a random free port. + /// + /// When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # References + /// - + /// - + /// - + /// - + start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; + finish-bind: func() -> result<_, error-code>; + + /// Set the destination address. + /// + /// The local-address is updated based on the best network path to `remote-address`. + /// + /// When a destination address is set: + /// - all receive operations will only return datagrams sent from the provided `remote-address`. + /// - the `send` function can only be used to send to this destination. + /// + /// Note that this function does not generate any network traffic and the peer is not aware of this "connection". + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # References + /// - + /// - + /// - + /// - + start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; + finish-connect: func() -> result<_, error-code>; + + /// 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. + /// If `max-results` is 0, this function returns successfully with an empty list. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not bound to any local address. (EINVAL) + /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + /// - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + receive: func(max-results: u64) -> result, error-code>; + + /// 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 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)`. + /// + /// The remote address option is required. To send a message to the "connected" peer, + /// call `remote-address` to get their address. + /// + /// # Typical errors + /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) + /// - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. + /// - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) + /// - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) + /// + /// # References + /// - + /// - + /// - + /// - + /// - + /// - + /// - + /// - + send: func(datagrams: list) -> result; + + /// 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 set with `connect`. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a 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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + 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. + /// + /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. + /// In other words, after setting a value, reading the same setting back may return a different value. + /// + /// Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + /// actual data to be sent/received by the application, because the kernel might also use the buffer space + /// for internal metadata structures. + /// + /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + 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; + } +} diff --git a/v2/wit/deps/sockets-2023-10-18/world.wit b/v2/wit/deps/sockets-2023-10-18/world.wit new file mode 100644 index 0000000..d16530c --- /dev/null +++ b/v2/wit/deps/sockets-2023-10-18/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0-rc-2023-10-18; + +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/v2/wit/deps/sockets-2023-11-10/instance-network.wit b/v2/wit/deps/sockets-2023-11-10/instance-network.wit new file mode 100644 index 0000000..e455d0f --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/instance-network.wit @@ -0,0 +1,9 @@ + +/// 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/v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit b/v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit new file mode 100644 index 0000000..931ccf7 --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit @@ -0,0 +1,51 @@ + +interface ip-name-lookup { + use wasi:io/poll@0.2.0-rc-2023-11-10.{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/v2/wit/deps/sockets-2023-11-10/network.wit b/v2/wit/deps/sockets-2023-11-10/network.wit new file mode 100644 index 0000000..6bb07cd --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/network.wit @@ -0,0 +1,147 @@ + +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 { + // ### GENERAL ERRORS ### + + /// 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, + + + + // ### TCP & UDP SOCKET ERRORS ### + + /// 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, + + + // ### TCP SOCKET ERRORS ### + + /// The connection was forcefully rejected + connection-refused, + + /// The connection was reset. + connection-reset, + + /// A connection was aborted. + connection-aborted, + + + // ### UDP SOCKET ERRORS ### + datagram-too-large, + + + // ### NAME LOOKUP ERRORS ### + + /// 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 { + port: u16, // sin_port + address: ipv4-address, // sin_addr + } + + record ipv6-socket-address { + port: u16, // sin6_port + flow-info: u32, // sin6_flowinfo + address: ipv6-address, // sin6_addr + scope-id: u32, // sin6_scope_id + } + + variant ip-socket-address { + ipv4(ipv4-socket-address), + ipv6(ipv6-socket-address), + } + +} diff --git a/v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit b/v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit new file mode 100644 index 0000000..768a07c --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// This function does not require a network capability handle. This is considered to be safe because + /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`listen`/`connect` + /// 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/v2/wit/deps/sockets-2023-11-10/tcp.wit b/v2/wit/deps/sockets-2023-11-10/tcp.wit new file mode 100644 index 0000000..b01b65e --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/tcp.wit @@ -0,0 +1,321 @@ + +interface tcp { + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; + use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{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 handle. + 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. + /// + /// When a socket is not explicitly bound, the first invocation to a listen or connect operation will + /// implicitly bind the socket. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 + /// + /// POSIX mentions: + /// > If connect() fails, the state of the socket is unspecified. Conforming applications should + /// > close the file descriptor and create a new socket before attempting to reconnect. + /// + /// WASI prescribes the following behavior: + /// - If `connect` fails because an input/state validation error, the socket should remain usable. + /// - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + /// Besides `drop`, any method after such a failure may return an error. + /// + /// # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + /// - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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 Connection state. (EISCONN) + /// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Listener state. + /// + /// Unlike POSIX: + /// - this function is async. This enables interactive WASI hosts to inject permission prompts. + /// - the socket must already be explicitly bound. + /// + /// # Typical `start` errors + /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + /// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + /// - `invalid-state`: The socket is already in the Listener state. + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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 Connection state. The following properties are inherited from the listener socket: + /// - `address-family` + /// - `ipv6-only` + /// - `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 Listener 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 listening for new connections. + /// + /// 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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> result<_, error-code>; + + /// 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 already in the Connection 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. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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. + /// - `invalid-state`: (set) The socket is already in the Connection state. + /// - `invalid-state`: (set) The socket is already in the Listener state. + 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; + + /// Initiate a graceful shutdown. + /// + /// - receive: the socket is not expecting to receive any more data from the peer. All subsequent read + /// operations on the `input-stream` associated with this socket will return an End Of Stream indication. + /// Any data still in the receive queue at time of calling `shutdown` will be discarded. + /// - send: the socket is not expecting to send any more data to the peer. All subsequent write + /// operations on the `output-stream` associated with this socket will return an error. + /// - both: same effect as receive & send combined. + /// + /// The shutdown function does not close (drop) the socket. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; + } +} diff --git a/v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit b/v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit new file mode 100644 index 0000000..cc58234 --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit @@ -0,0 +1,26 @@ + +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. + /// + /// 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/v2/wit/deps/sockets-2023-11-10/udp.wit b/v2/wit/deps/sockets-2023-11-10/udp.wit new file mode 100644 index 0000000..c8dafad --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/udp.wit @@ -0,0 +1,277 @@ + +interface udp { + use wasi:io/poll@0.2.0-rc-2023-11-10.{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. + /// + /// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + /// + /// # Typical `start` errors + /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + /// - `invalid-state`: The socket is already bound. (EINVAL) + /// + /// # Typical `finish` errors + /// - `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) + /// + /// # 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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; + + /// Whether IPv4 compatibility (dual-stack) mode is disabled or not. + /// + /// Equivalent to the IPV6_V6ONLY socket option. + /// + /// # Typical errors + /// - `not-supported`: (get/set) `this` socket is an IPv4 socket. + /// - `invalid-state`: (set) The socket is already bound. + /// - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + ipv6-only: func() -> result; + set-ipv6-only: func(value: bool) -> 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. + 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + /// - `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/v2/wit/deps/sockets-2023-11-10/world.wit b/v2/wit/deps/sockets-2023-11-10/world.wit new file mode 100644 index 0000000..49ad8d3 --- /dev/null +++ b/v2/wit/deps/sockets-2023-11-10/world.wit @@ -0,0 +1,11 @@ +package wasi:sockets@0.2.0-rc-2023-11-10; + +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/v2/wit/deps/sockets/instance-network.wit b/v2/wit/deps/sockets/instance-network.wit new file mode 100644 index 0000000..e455d0f --- /dev/null +++ b/v2/wit/deps/sockets/instance-network.wit @@ -0,0 +1,9 @@ + +/// 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/v2/wit/deps/sockets/ip-name-lookup.wit b/v2/wit/deps/sockets/ip-name-lookup.wit new file mode 100644 index 0000000..8e639ec --- /dev/null +++ b/v2/wit/deps/sockets/ip-name-lookup.wit @@ -0,0 +1,51 @@ + +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/v2/wit/deps/sockets/network.wit b/v2/wit/deps/sockets/network.wit new file mode 100644 index 0000000..9cadf06 --- /dev/null +++ b/v2/wit/deps/sockets/network.wit @@ -0,0 +1,145 @@ + +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/v2/wit/deps/sockets/tcp-create-socket.wit b/v2/wit/deps/sockets/tcp-create-socket.wit new file mode 100644 index 0000000..c7ddf1f --- /dev/null +++ b/v2/wit/deps/sockets/tcp-create-socket.wit @@ -0,0 +1,27 @@ + +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/v2/wit/deps/sockets/tcp.wit b/v2/wit/deps/sockets/tcp.wit new file mode 100644 index 0000000..5902b9e --- /dev/null +++ b/v2/wit/deps/sockets/tcp.wit @@ -0,0 +1,353 @@ + +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/v2/wit/deps/sockets/udp-create-socket.wit b/v2/wit/deps/sockets/udp-create-socket.wit new file mode 100644 index 0000000..0482d1f --- /dev/null +++ b/v2/wit/deps/sockets/udp-create-socket.wit @@ -0,0 +1,27 @@ + +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/v2/wit/deps/sockets/udp.wit b/v2/wit/deps/sockets/udp.wit new file mode 100644 index 0000000..d987a0a --- /dev/null +++ b/v2/wit/deps/sockets/udp.wit @@ -0,0 +1,266 @@ + +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/v2/wit/deps/sockets/world.wit b/v2/wit/deps/sockets/world.wit new file mode 100644 index 0000000..f8bb92a --- /dev/null +++ b/v2/wit/deps/sockets/world.wit @@ -0,0 +1,11 @@ +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/v2/wit/deps/spin@unversioned/config.wit b/v2/wit/deps/spin@unversioned/config.wit new file mode 100644 index 0000000..ac465fb --- /dev/null +++ b/v2/wit/deps/spin@unversioned/config.wit @@ -0,0 +1,12 @@ +interface config { + // Get a configuration value for the current component. + // The config key must match one defined in in the component manifest. + get-config: func(key: string) -> result; + + variant error { + provider(string), + invalid-key(string), + invalid-schema(string), + other(string), + } +} diff --git a/v2/wit/deps/spin@unversioned/http-types.wit b/v2/wit/deps/spin@unversioned/http-types.wit new file mode 100644 index 0000000..c941cc9 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/http-types.wit @@ -0,0 +1,44 @@ +interface http-types { + type http-status = u16; + + type body = list; + + type headers = list>; + + type params = list>; + + type uri = string; + + enum method { + get, + post, + put, + delete, + patch, + head, + options, + } + + record request { + method: method, + uri: uri, + headers: headers, + params: params, + body: option, + } + + record response { + status: http-status, + headers: option, + body: option, + } + + enum http-error { + success, + destination-not-allowed, + invalid-url, + request-error, + runtime-error, + too-many-requests, + } +} diff --git a/v2/wit/deps/spin@unversioned/http.wit b/v2/wit/deps/spin@unversioned/http.wit new file mode 100644 index 0000000..6ca943c --- /dev/null +++ b/v2/wit/deps/spin@unversioned/http.wit @@ -0,0 +1,5 @@ +interface http { + use http-types.{request, response, http-error}; + + send-request: func(req: request) -> result; +} diff --git a/v2/wit/deps/spin@unversioned/inbound-http.wit b/v2/wit/deps/spin@unversioned/inbound-http.wit new file mode 100644 index 0000000..968c576 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/inbound-http.wit @@ -0,0 +1,5 @@ +interface inbound-http { + use http-types.{request, response}; + + handle-request: func(req: request) -> response; +} diff --git a/v2/wit/deps/spin@unversioned/inbound-redis.wit b/v2/wit/deps/spin@unversioned/inbound-redis.wit new file mode 100644 index 0000000..a991e5d --- /dev/null +++ b/v2/wit/deps/spin@unversioned/inbound-redis.wit @@ -0,0 +1,6 @@ +interface inbound-redis { + use redis-types.{payload, error}; + + // The entrypoint for a Redis handler. + handle-message: func(message: payload) -> result<_, error>; +} diff --git a/v2/wit/deps/spin@unversioned/key-value.wit b/v2/wit/deps/spin@unversioned/key-value.wit new file mode 100644 index 0000000..314a758 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/key-value.wit @@ -0,0 +1,80 @@ +interface key-value { + // A handle to an open key-value store + type store = u32; + + // The set of errors which may be raised by functions in this interface + variant error { + // Too many stores have been opened simultaneously. Closing one or more + // stores prior to retrying may address this. + store-table-full, + + // The host does not recognize the store name requested. Defining and + // configuring a store with that name in a runtime configuration file + // may address this. + no-such-store, + + // The requesting component does not have access to the specified store + // (which may or may not exist). + access-denied, + + // The store handle provided is not recognized, i.e. it was either never + // opened or has been closed. + invalid-store, + + // No key-value tuple exists for the specified key in the specified + // store. + no-such-key, + + // Some implementation-specific error has occurred (e.g. I/O) + io(string) + } + + // Open the store with the specified name. + // + // If `name` is "default", the default store is opened. Otherwise, + // `name` must refer to a store defined and configured in a runtime + // configuration file supplied with the application. + // + // `error::no-such-store` will be raised if the `name` is not recognized. + open: func(name: string) -> result; + + // Get the value associated with the specified `key` from the specified + // `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store, and `error::no-such-key` will be raised if there is no + // tuple for `key` in `store`. + get: func(store: store, key: string) -> result, error>; + + // Set the `value` associated with the specified `key` in the specified + // `store`, overwriting any existing value. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + set: func(store: store, key: string, value: list) -> result<_, error>; + + // Delete the tuple with the specified `key` from the specified `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. No error is raised if a tuple did not previously + // exist for `key`. + delete: func(store: store, key: string) -> result<_, error>; + + // Return whether a tuple exists for the specified `key` in the specified + // `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + exists: func(store: store, key: string) -> result; + + // Return a list of all the keys in the specified `store`. + // + // `error::invalid-store` will be raised if `store` is not a valid handle + // to an open store. + get-keys: func(store: store) -> result, error>; + + // Close the specified `store`. + // + // This has no effect if `store` is not a valid handle to an open store. + close: func(store: store); +} diff --git a/v2/wit/deps/spin@unversioned/llm.wit b/v2/wit/deps/spin@unversioned/llm.wit new file mode 100644 index 0000000..ffed09c --- /dev/null +++ b/v2/wit/deps/spin@unversioned/llm.wit @@ -0,0 +1,70 @@ +// A WASI interface dedicated to performing inferencing for Large Language Models. +interface llm { + /// A Large Language Model. + type inferencing-model = string; + + /// Inference request parameters + record inferencing-params { + /// The maximum tokens that should be inferred. + /// + /// Note: the backing implementation may return less tokens. + max-tokens: u32, + /// The amount the model should avoid repeating tokens. + repeat-penalty: float32, + /// The number of tokens the model should apply the repeat penalty to. + repeat-penalty-last-n-token-count: u32, + /// The randomness with which the next token is selected. + temperature: float32, + /// The number of possible next tokens the model will choose from. + top-k: u32, + /// The probability total of next tokens the model will choose from. + top-p: float32 + } + + /// The set of errors which may be raised by functions in this interface + variant error { + model-not-supported, + runtime-error(string), + invalid-input(string) + } + + /// An inferencing result + record inferencing-result { + /// The text generated by the model + // TODO: this should be a stream + text: string, + /// Usage information about the inferencing request + usage: inferencing-usage + } + + /// Usage information related to the inferencing result + record inferencing-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + /// Number of tokens generated by the inferencing operation + generated-token-count: u32 + } + + /// Perform inferencing using the provided model and prompt with the given optional params + infer: func(model: inferencing-model, prompt: string, params: option) -> result; + + /// The model used for generating embeddings + type embedding-model = string; + + /// Generate embeddings for the supplied list of text + generate-embeddings: func(model: embedding-model, text: list) -> result; + + /// Result of generating embeddings + record embeddings-result { + /// The embeddings generated by the request + embeddings: list>, + /// Usage related to the embeddings generation request + usage: embeddings-usage + } + + /// Usage related to an embeddings generation request + record embeddings-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + } +} diff --git a/v2/wit/deps/spin@unversioned/mysql.wit b/v2/wit/deps/spin@unversioned/mysql.wit new file mode 100644 index 0000000..dd1b9c3 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/mysql.wit @@ -0,0 +1,19 @@ +interface mysql { + use rdbms-types.{parameter-value, row-set}; + + // General purpose error. + variant mysql-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string) + } + + // query the database: select + query: func(address: string, statement: string, params: list) -> result; + + // execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result<_, mysql-error>; +} diff --git a/v2/wit/deps/spin@unversioned/postgres.wit b/v2/wit/deps/spin@unversioned/postgres.wit new file mode 100644 index 0000000..e82ef42 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/postgres.wit @@ -0,0 +1,19 @@ +interface postgres { + use rdbms-types.{parameter-value, row-set}; + + // General purpose error. + variant pg-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string) + } + + // query the database: select + query: func(address: string, statement: string, params: list) -> result; + + // execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result; +} diff --git a/v2/wit/deps/spin@unversioned/rdbms-types.wit b/v2/wit/deps/spin@unversioned/rdbms-types.wit new file mode 100644 index 0000000..7af0420 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/rdbms-types.wit @@ -0,0 +1,65 @@ +interface rdbms-types { + enum db-data-type { + boolean, + int8, + int16, + int32, + int64, + uint8, + uint16, + uint32, + uint64, + floating32, + floating64, + str, + binary, + other, + } + + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + unsupported, + } + + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + } + + record column { + name: string, + data-type: db-data-type, + } + + type row = list; + + record row-set { + columns: list, + rows: list, + } +} diff --git a/v2/wit/deps/spin@unversioned/redis-types.wit b/v2/wit/deps/spin@unversioned/redis-types.wit new file mode 100644 index 0000000..6970f63 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/redis-types.wit @@ -0,0 +1,24 @@ +interface redis-types { + // General purpose error. + enum error { + success, + error, + } + + /// The message payload. + type payload = list; + + /// A parameter type for the general-purpose `execute` function. + variant redis-parameter { + int64(s64), + binary(payload) + } + + /// A return type for the general-purpose `execute` function. + variant redis-result { + nil, + status(string), + int64(s64), + binary(payload) + } +} diff --git a/v2/wit/deps/spin@unversioned/redis.wit b/v2/wit/deps/spin@unversioned/redis.wit new file mode 100644 index 0000000..1b64906 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/redis.wit @@ -0,0 +1,31 @@ +interface redis { + use redis-types.{payload, redis-parameter, redis-result, error}; + + // Publish a Redis message to the specificed channel and return an error, if any. + publish: func(address: string, channel: string, payload: payload) -> result<_, error>; + + // Get the value of a key. + get: func(address: string, key: string) -> result; + + // Set key to value. If key alreads holds a value, it is overwritten. + set: func(address: string, key: string, value: payload) -> result<_, error>; + + // Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. + // An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. + incr: func(address: string, key: string) -> result; + + // Removes the specified keys. A key is ignored if it does not exist. + del: func(address: string, keys: list) -> result; + + // Add the specified `values` to the set named `key`, returning the number of newly-added values. + sadd: func(address: string, key: string, values: list) -> result; + + // Retrieve the contents of the set named `key`. + smembers: func(address: string, key: string) -> result, error>; + + // Remove the specified `values` from the set named `key`, returning the number of newly-removed values. + srem: func(address: string, key: string, values: list) -> result; + + // Execute an arbitrary Redis command and receive the result. + execute: func(address: string, command: string, arguments: list) -> result, error>; +} diff --git a/v2/wit/deps/spin@unversioned/sqlite.wit b/v2/wit/deps/spin@unversioned/sqlite.wit new file mode 100644 index 0000000..7e2908f --- /dev/null +++ b/v2/wit/deps/spin@unversioned/sqlite.wit @@ -0,0 +1,52 @@ +interface sqlite { + // A handle to an open sqlite instance + type connection = u32; + + // The set of errors which may be raised by functions in this interface + variant error { + // The host does not recognize the database name requested. + no-such-database, + // The requesting component does not have access to the specified database (which may or may not exist). + access-denied, + // The provided connection is not valid + invalid-connection, + // The database has reached its capacity + database-full, + // Some implementation-specific error has occurred (e.g. I/O) + io(string) + } + + // Open a connection to a named database instance. + // + // If `database` is "default", the default instance is opened. + // + // `error::no-such-database` will be raised if the `name` is not recognized. + open: func(database: string) -> result; + + // Execute a statement returning back data if there is any + execute: func(conn: connection, statement: string, parameters: list) -> result; + + // Close the specified `connection`. + close: func(conn: connection); + + // A result of a query + record query-result { + // The names of the columns retrieved in the query + columns: list, + // the row results each containing the values for all the columns for a given row + rows: list, + } + + // A set of values for each of the columns in a query-result + record row-result { + values: list + } + + variant value { + integer(s64), + real(float64), + text(string), + blob(list), + null + } +} diff --git a/v2/wit/deps/spin@unversioned/world.wit b/v2/wit/deps/spin@unversioned/world.wit new file mode 100644 index 0000000..603a760 --- /dev/null +++ b/v2/wit/deps/spin@unversioned/world.wit @@ -0,0 +1,29 @@ +package fermyon:spin; + +world host { + include platform; + + export inbound-http; + export inbound-redis; +} + +world redis-trigger { + include platform; + export inbound-redis; +} + +world http-trigger { + include platform; + export inbound-http; +} + +world platform { + import config; + import http; + import postgres; + import mysql; + import sqlite; + import redis; + import key-value; + import llm; +} diff --git a/v2/wit/key-value.wit b/v2/wit/key-value.wit new file mode 100644 index 0000000..7ba4ed9 --- /dev/null +++ b/v2/wit/key-value.wit @@ -0,0 +1,47 @@ +interface key-value { + /// An open key-value store + resource store { + /// Open the store with the specified label. + /// + /// `label` must refer to a store allowed in the spin.toml manifest. + /// + /// `error::no-such-store` will be raised if the `label` is not recognized. + open: static func(label: string) -> result; + + /// Get the value associated with the specified `key` + /// + /// Returns `ok(none)` if the key does not exist. + get: func(key: string) -> result>, error>; + + /// Set the `value` associated with the specified `key` overwriting any existing value. + set: func(key: string, value: list) -> result<_, error>; + + /// Delete the tuple with the specified `key` + /// + /// No error is raised if a tuple did not previously exist for `key`. + delete: func(key: string) -> result<_, error>; + + /// Return whether a tuple exists for the specified `key` + exists: func(key: string) -> result; + + /// Return a list of all the keys + get-keys: func() -> result, error>; + } + + /// The set of errors which may be raised by functions in this interface + variant error { + /// Too many stores have been opened simultaneously. Closing one or more + /// stores prior to retrying may address this. + store-table-full, + + /// The host does not recognize the store label requested. + no-such-store, + + /// The requesting component does not have access to the specified store + /// (which may or may not exist). + access-denied, + + /// Some implementation-specific error has occurred (e.g. I/O) + other(string) + } +} diff --git a/v2/wit/llm.wit b/v2/wit/llm.wit new file mode 100644 index 0000000..ffed09c --- /dev/null +++ b/v2/wit/llm.wit @@ -0,0 +1,70 @@ +// A WASI interface dedicated to performing inferencing for Large Language Models. +interface llm { + /// A Large Language Model. + type inferencing-model = string; + + /// Inference request parameters + record inferencing-params { + /// The maximum tokens that should be inferred. + /// + /// Note: the backing implementation may return less tokens. + max-tokens: u32, + /// The amount the model should avoid repeating tokens. + repeat-penalty: float32, + /// The number of tokens the model should apply the repeat penalty to. + repeat-penalty-last-n-token-count: u32, + /// The randomness with which the next token is selected. + temperature: float32, + /// The number of possible next tokens the model will choose from. + top-k: u32, + /// The probability total of next tokens the model will choose from. + top-p: float32 + } + + /// The set of errors which may be raised by functions in this interface + variant error { + model-not-supported, + runtime-error(string), + invalid-input(string) + } + + /// An inferencing result + record inferencing-result { + /// The text generated by the model + // TODO: this should be a stream + text: string, + /// Usage information about the inferencing request + usage: inferencing-usage + } + + /// Usage information related to the inferencing result + record inferencing-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + /// Number of tokens generated by the inferencing operation + generated-token-count: u32 + } + + /// Perform inferencing using the provided model and prompt with the given optional params + infer: func(model: inferencing-model, prompt: string, params: option) -> result; + + /// The model used for generating embeddings + type embedding-model = string; + + /// Generate embeddings for the supplied list of text + generate-embeddings: func(model: embedding-model, text: list) -> result; + + /// Result of generating embeddings + record embeddings-result { + /// The embeddings generated by the request + embeddings: list>, + /// Usage related to the embeddings generation request + usage: embeddings-usage + } + + /// Usage related to an embeddings generation request + record embeddings-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + } +} diff --git a/v2/wit/mqtt.wit b/v2/wit/mqtt.wit new file mode 100644 index 0000000..32f04fb --- /dev/null +++ b/v2/wit/mqtt.wit @@ -0,0 +1,31 @@ +interface mqtt { + /// Errors related to interacting with Mqtt + variant error { + /// An invalid address string + invalid-address, + /// There are too many open connections + too-many-connections, + /// Connection failure e.g. address not allowed. + connection-failed(string), + /// Some other error occurred + other(string), + } + + /// QoS for publishing Mqtt messages + enum qos { + at-most-once, + at-least-once, + exactly-once, + } + + resource connection { + /// Open a connection to the Mqtt instance at `address`. + open: static func(address: string, username: string, password: string, keep-alive-interval-in-secs: u64) -> result; + + /// Publish an Mqtt message to the specified `topic`. + publish: func(topic: string, payload: payload, qos: qos) -> result<_, error>; + } + + /// The message payload. + type payload = list; +} diff --git a/v2/wit/mysql.wit b/v2/wit/mysql.wit new file mode 100644 index 0000000..446cf89 --- /dev/null +++ b/v2/wit/mysql.wit @@ -0,0 +1,15 @@ +interface mysql { + use rdbms-types.{parameter-value, row-set, error}; + + /// A connection to a MySQL database. + resource connection { + /// Open a connection to the MySQL instance at `address`. + open: static func(address: string) -> result; + + /// query the database: select + query: func(statement: string, params: list) -> result; + + /// execute command to the database: insert, update, delete + execute: func(statement: string, params: list) -> result<_, error>; + } +} diff --git a/v2/wit/postgres.wit b/v2/wit/postgres.wit new file mode 100644 index 0000000..ebe1ec6 --- /dev/null +++ b/v2/wit/postgres.wit @@ -0,0 +1,15 @@ +interface postgres { + use rdbms-types.{parameter-value, row-set, error}; + + /// A connection to a postgres database. + resource connection { + /// Open a connection to the Postgres instance at `address`. + open: static func(address: string) -> result; + + /// Query the database. + query: func(statement: string, params: list) -> result; + + /// Execute command to the database. + execute: func(statement: string, params: list) -> result; + } +} diff --git a/v2/wit/rdbms-types.wit b/v2/wit/rdbms-types.wit new file mode 100644 index 0000000..64f3e59 --- /dev/null +++ b/v2/wit/rdbms-types.wit @@ -0,0 +1,80 @@ +interface rdbms-types { + /// Errors related to interacting with a database. + variant error { + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other(string) + } + + /// Data types for a database column + enum db-data-type { + boolean, + int8, + int16, + int32, + int64, + uint8, + uint16, + uint32, + uint64, + floating32, + floating64, + str, + binary, + other, + } + + /// Database values + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + unsupported, + } + + /// Values used in parameterized queries + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(float32), + floating64(float64), + str(string), + binary(list), + db-null, + } + + /// A database column + record column { + name: string, + data-type: db-data-type, + } + + /// A database row + type row = list; + + /// A set of database rows + record row-set { + columns: list, + rows: list, + } +} diff --git a/v2/wit/redis.wit b/v2/wit/redis.wit new file mode 100644 index 0000000..27446eb --- /dev/null +++ b/v2/wit/redis.wit @@ -0,0 +1,70 @@ +interface redis { + /// Errors related to interacting with Redis + variant error { + /// An invalid address string + invalid-address, + /// There are too many open connections + too-many-connections, + /// A retrieved value was not of the correct type + type-error, + /// Some other error occurred + other(string), + } + + resource connection { + /// Open a connection to the Redis instance at `address`. + open: static func(address: string) -> result; + + /// Publish a Redis message to the specified channel. + publish: func(channel: string, payload: payload) -> result<_, error>; + + /// Get the value of a key. + get: func(key: string) -> result, error>; + + /// Set key to value. + /// + /// If key already holds a value, it is overwritten. + set: func(key: string, value: payload) -> result<_, error>; + + /// Increments the number stored at key by one. + /// + /// If the key does not exist, it is set to 0 before performing the operation. + /// An `error::type-error` is returned if the key contains a value of the wrong type + /// or contains a string that can not be represented as integer. + incr: func(key: string) -> result; + + /// Removes the specified keys. + /// + /// A key is ignored if it does not exist. Returns the number of keys deleted. + del: func(keys: list) -> result; + + /// Add the specified `values` to the set named `key`, returning the number of newly-added values. + sadd: func(key: string, values: list) -> result; + + /// Retrieve the contents of the set named `key`. + smembers: func(key: string) -> result, error>; + + /// Remove the specified `values` from the set named `key`, returning the number of newly-removed values. + srem: func(key: string, values: list) -> result; + + /// Execute an arbitrary Redis command and receive the result. + execute: func(command: string, arguments: list) -> result, error>; + } + + /// The message payload. + type payload = list; + + /// A parameter type for the general-purpose `execute` function. + variant redis-parameter { + int64(s64), + binary(payload) + } + + /// A return type for the general-purpose `execute` function. + variant redis-result { + nil, + status(string), + int64(s64), + binary(payload) + } +} diff --git a/v2/wit/sqlite.wit b/v2/wit/sqlite.wit new file mode 100644 index 0000000..8a5ab2d --- /dev/null +++ b/v2/wit/sqlite.wit @@ -0,0 +1,50 @@ +interface sqlite { + /// A handle to an open sqlite instance + resource connection { + /// Open a connection to a named database instance. + /// + /// If `database` is "default", the default instance is opened. + /// + /// `error::no-such-database` will be raised if the `name` is not recognized. + open: static func(database: string) -> result; + + /// Execute a statement returning back data if there is any + execute: func(statement: string, parameters: list) -> result; + } + + /// The set of errors which may be raised by functions in this interface + variant error { + /// The host does not recognize the database name requested. + no-such-database, + /// The requesting component does not have access to the specified database (which may or may not exist). + access-denied, + /// The provided connection is not valid + invalid-connection, + /// The database has reached its capacity + database-full, + /// Some implementation-specific error has occurred (e.g. I/O) + io(string) + } + + /// A result of a query + record query-result { + /// The names of the columns retrieved in the query + columns: list, + /// the row results each containing the values for all the columns for a given row + rows: list, + } + + /// A set of values for each of the columns in a query-result + record row-result { + values: list + } + + /// A single column's result from a database query + variant value { + integer(s64), + real(float64), + text(string), + blob(list), + null + } +} diff --git a/v2/wit/variables.wit b/v2/wit/variables.wit new file mode 100644 index 0000000..6c0511a --- /dev/null +++ b/v2/wit/variables.wit @@ -0,0 +1,18 @@ +interface variables { + /// Get an application variable value for the current component. + /// + /// The name must match one defined in in the component manifest. + get: func(name: string) -> result; + + /// The set of errors which may be raised by functions in this interface. + variant error { + /// The provided variable name is invalid. + invalid-name(string), + /// The provided variable is undefined. + undefined(string), + /// A variables provider specific error has occurred. + provider(string), + /// Some implementation-specific error has occurred. + other(string), + } +} diff --git a/v2/wit/world.wit b/v2/wit/world.wit new file mode 100644 index 0000000..b16e429 --- /dev/null +++ b/v2/wit/world.wit @@ -0,0 +1,41 @@ +package fermyon:spin@2.0.0; + +/// The full world of a guest targeting an http-trigger +world http-trigger { + include platform; + export wasi:http/incoming-handler@0.2.0; +} + +/// Like `http-trigger`, but using WASI 0.2.0-rc-2023-10-18 +world http-trigger-rc20231018 { + include platform-rc20231018; + export wasi:http/incoming-handler@0.2.0-rc-2023-10-18; +} + +/// The imports needed for a guest to run on a Spin host +world platform { + include wasi:cli/imports@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + import llm; + import redis; + import mqtt; + import postgres; + import mysql; + import sqlite; + import key-value; + import variables; +} + +/// Like `platform`, but using WASI 0.2.0-rc-2023-10-18 +world platform-rc20231018 { + include wasi:cli/reactor@0.2.0-rc-2023-10-18; + import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; + import llm; + import redis; + import mqtt; + import postgres; + import mysql; + import sqlite; + import key-value; + import variables; +} From d767705e3143e07b2a39900a500904951d32815f Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sun, 1 Sep 2024 07:37:24 +0530 Subject: [PATCH 2/6] incoming http handler Signed-off-by: Rajat Jindal --- v2/README.md | 8 +- v2/examples/http/go.mod | 12 ++ v2/examples/http/go.sum | 4 + v2/examples/http/main.go | 23 ++++ v2/examples/http/spin.toml | 16 +++ v2/go.mod | 5 + v2/go.sum | 4 + v2/http/client.go | 104 +++++++++++++++++ v2/http/convertor_incoming_request.go | 92 +++++++++++++++ v2/http/convertor_outgoing_request.go | 69 +++++++++++ v2/http/convertor_outgoing_response.go | 155 +++++++++++++++++++++++++ v2/http/http.go | 99 ++++++++++++++++ v2/http/streams.go | 45 +++++++ v2/wit/wit.go | 6 + 14 files changed, 639 insertions(+), 3 deletions(-) create mode 100644 v2/examples/http/go.mod create mode 100644 v2/examples/http/go.sum create mode 100644 v2/examples/http/main.go create mode 100644 v2/examples/http/spin.toml create mode 100644 v2/go.sum create mode 100644 v2/http/client.go create mode 100644 v2/http/convertor_incoming_request.go create mode 100644 v2/http/convertor_outgoing_request.go create mode 100644 v2/http/convertor_outgoing_response.go create mode 100644 v2/http/http.go create mode 100644 v2/http/streams.go create mode 100644 v2/wit/wit.go diff --git a/v2/README.md b/v2/README.md index 3aedb4e..5b333a9 100644 --- a/v2/README.md +++ b/v2/README.md @@ -4,8 +4,10 @@ spin-go-sdk with wasip2 support Notes: -The bindings are generated with following tooling: - +The current version of tooling used for this work: - ydnar/wasm-tools-go `a45ed842846a419a5efd02b9384e14417cc90817` -- wasm-tools `wasm-tools 1.216.0 (28c8962b1 2024-08-22)` \ No newline at end of file +- wasm-tools `wasm-tools 1.216.0 (28c8962b1 2024-08-22)` +- tinygo version 0.33.0 darwin/arm64 (using go version go1.22.6 and LLVM version 18.1.2) +- spin 2.8.0-pre0 (74d3517 2024-08-30) + diff --git a/v2/examples/http/go.mod b/v2/examples/http/go.mod new file mode 100644 index 0000000..a9d959b --- /dev/null +++ b/v2/examples/http/go.mod @@ -0,0 +1,12 @@ +module github.com/fermyon/spin-go-sdk/v2/examples/http + +go 1.22.6 + +require github.com/fermyon/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + github.com/ydnar/wasm-tools-go v0.1.5 // indirect +) + +replace github.com/fermyon/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/http/go.sum b/v2/examples/http/go.sum new file mode 100644 index 0000000..a445b61 --- /dev/null +++ b/v2/examples/http/go.sum @@ -0,0 +1,4 @@ +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= +github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= diff --git a/v2/examples/http/main.go b/v2/examples/http/main.go new file mode 100644 index 0000000..e0c267f --- /dev/null +++ b/v2/examples/http/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/fermyon/spin-go-sdk/v2/http" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + w.Header().Set("foo", "bar") + + //TODO(rajatjindal): calling WriteHeader is required right now, need to fix before merging + w.WriteHeader(http.StatusOK) + fmt.Fprintln(w, "== RESPONSE ==") + fmt.Fprintln(w, "Hello Fermyon!") + fmt.Fprintln(w, "Hello again Fermyon!") + }) +} + +func main() {} diff --git a/v2/examples/http/spin.toml b/v2/examples/http/spin.toml new file mode 100644 index 0000000..00625c4 --- /dev/null +++ b/v2/examples/http/spin.toml @@ -0,0 +1,16 @@ +spin_manifest_version = 2 + +[application] +authors = ["Rajat Jindal "] +description = "A simple Spin application written in (Tiny)Go." +name = "hello-example" +version = "1.0.0" + +[[trigger.http]] +route = "/hello" +component = "hello" + +[component.hello] +source = "main.wasm" +[component.hello.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/fermyon/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file diff --git a/v2/go.mod b/v2/go.mod index cea507d..b859d85 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -1,3 +1,8 @@ module github.com/fermyon/spin-go-sdk/v2 go 1.22.6 + +require ( + github.com/julienschmidt/httprouter v1.3.0 + github.com/ydnar/wasm-tools-go v0.1.5 +) diff --git a/v2/go.sum b/v2/go.sum new file mode 100644 index 0000000..a445b61 --- /dev/null +++ b/v2/go.sum @@ -0,0 +1,4 @@ +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= +github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= diff --git a/v2/http/client.go b/v2/http/client.go new file mode 100644 index 0000000..f041d5d --- /dev/null +++ b/v2/http/client.go @@ -0,0 +1,104 @@ +package http + +import ( + "fmt" + "io" + "net/http" + + outgoinghandler "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/outgoing-handler" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// NewTransport returns http.RoundTripper backed by Spin SDK +func NewTransport() http.RoundTripper { + return &Transport{} +} + +// Transport implements http.RoundTripper +type Transport struct{} + +// RoundTrip makes roundtrip using Spin SDK +func (r *Transport) RoundTrip(req *http.Request) (*http.Response, error) { + return Send(req) +} + +// NewClient returns a new HTTP client compatible with the Spin SDK +func NewClient() *http.Client { + return &http.Client{ + Transport: &Transport{}, + } +} + +func Send(req *http.Request) (*http.Response, error) { + or, err := NewOutgoingHttpRequest(req) + if err != nil { + return nil, err + } + + result := outgoinghandler.Handle(or, cm.None[types.RequestOptions]()) + if result.Err() != nil { + return nil, fmt.Errorf("TODO: convert to readable error") + } + + if result.IsErr() { + return nil, fmt.Errorf("error is %v", result.Err()) + } + + okresult := result.OK() + + //wait until resp is returned + okresult.Subscribe().Block() + + incomingResp := okresult.Get() + if incomingResp.None() { + return nil, fmt.Errorf("incoming resp is None") + } + + if incomingResp.Some().IsErr() { + return nil, fmt.Errorf("error is %v", incomingResp.Some().Err()) + } + + if incomingResp.Some().OK().IsErr() { + return nil, fmt.Errorf("error is %v", incomingResp.Some().OK().Err()) + } + + okresp := incomingResp.Some().OK().OK() + var body io.ReadCloser + if consumeResult := okresp.Consume(); consumeResult.IsErr() { + return nil, fmt.Errorf("failed to consume incoming request %s", *consumeResult.Err()) + } else if streamResult := consumeResult.OK().Stream(); streamResult.IsErr() { + return nil, fmt.Errorf("failed to consume incoming requests's stream %s", streamResult.Err()) + } else { + body = NewReadCloser(*streamResult.OK()) + } + + resp := &http.Response{ + StatusCode: int(okresp.Status()), + Body: body, + } + + return resp, nil +} + +func Get(url string) (*http.Response, error) { + req, err := http.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + return Send(req) +} + +func Post(url string, contentType string, body io.Reader) (*http.Response, error) { + req, err := http.NewRequest(http.MethodPost, url, body) + if err != nil { + return nil, err + } + + if contentType != "" { + req.Header.Set("Content-Type", contentType) + } + + return Send(req) +} diff --git a/v2/http/convertor_incoming_request.go b/v2/http/convertor_incoming_request.go new file mode 100644 index 0000000..f682cee --- /dev/null +++ b/v2/http/convertor_incoming_request.go @@ -0,0 +1,92 @@ +package http + +import ( + "fmt" + "io" + "net/http" + + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +type IncomingRequest = types.IncomingRequest + +// convert the IncomingRequest to http.Request +func NewHttpRequest(ir IncomingRequest) (req *http.Request, err error) { + // convert the http method to string + method, err := methodToString(ir.Method()) + if err != nil { + return nil, err + } + + // convert the path with query to a url + var url string + if pathWithQuery := ir.PathWithQuery(); pathWithQuery.None() { + url = "" + } else { + url = *pathWithQuery.Some() + } + + // convert the body to a reader + var body io.Reader + if consumeResult := ir.Consume(); consumeResult.IsErr() { + return nil, fmt.Errorf("failed to consume incoming request %s", *consumeResult.Err()) + } else if streamResult := consumeResult.OK().Stream(); streamResult.IsErr() { + return nil, fmt.Errorf("failed to consume incoming requests's stream %s", streamResult.Err()) + } else { + body = NewReader(*streamResult.OK()) + } + + // create a new request + req, err = http.NewRequest(method, url, body) + if err != nil { + return nil, err + } + + // update additional fields + toHttpHeader(ir.Headers(), &req.Header) + + return req, nil +} + +func methodToString(m types.Method) (string, error) { + if m.Connect() { + return "CONNECT", nil + } + if m.Delete() { + return "DELETE", nil + } + if m.Get() { + return "GET", nil + } + if m.Head() { + return "HEAD", nil + } + if m.Options() { + return "OPTIONS", nil + } + if m.Patch() { + return "PATCH", nil + } + if m.Post() { + return "POST", nil + } + if m.Put() { + return "PUT", nil + } + if m.Trace() { + return "TRACE", nil + } + if other := m.Other(); other != nil { + return *other, fmt.Errorf("unknown http method 'other'") + } + return "", fmt.Errorf("failed to convert http method") +} + +func toHttpHeader(src types.Fields, dest *http.Header) { + for _, f := range src.Entries().Slice() { + key := string(f.F0) + value := string(cm.List[uint8](f.F1).Slice()) + dest.Add(key, value) + } +} diff --git a/v2/http/convertor_outgoing_request.go b/v2/http/convertor_outgoing_request.go new file mode 100644 index 0000000..50ffb75 --- /dev/null +++ b/v2/http/convertor_outgoing_request.go @@ -0,0 +1,69 @@ +package http + +import ( + "net/http" + + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/ydnar/wasm-tools-go/cm" +) + +// convert the IncomingRequest to http.Request +func NewOutgoingHttpRequest(req *http.Request) (types.OutgoingRequest, error) { + headers := types.NewFields() + toWasiHeader(req.Header, headers) + + or := types.NewOutgoingRequest(headers) + or.SetAuthority(cm.Some(req.Host)) + or.SetMethod(toWasiMethod(req.Method)) + or.SetPathWithQuery(cm.Some(req.URL.RawPath)) + + switch req.URL.Scheme { + case "http": + or.SetScheme(cm.Some(types.SchemeHTTP())) + case "https": + or.SetScheme(cm.Some(types.SchemeHTTPS())) + default: + or.SetScheme(cm.Some(types.SchemeOther(req.URL.Scheme))) + } + + return or, nil +} + +func toWasiHeader(src http.Header, dest types.Fields) { + for k, v := range src { + key := types.FieldKey(k) + fieldVals := []types.FieldValue{} + + for _, val := range v { + fieldVals = append(fieldVals, types.FieldValue(cm.ToList([]uint8(val)))) + } + + //TODO(rjindal): check error + _ = dest.Set(key, cm.ToList(fieldVals)) + } +} + +func toWasiMethod(s string) types.Method { + switch s { + case http.MethodConnect: + return types.MethodConnect() + case http.MethodDelete: + return types.MethodDelete() + case http.MethodGet: + return types.MethodGet() + case http.MethodHead: + return types.MethodHead() + case http.MethodOptions: + return types.MethodOptions() + case http.MethodPatch: + return types.MethodPatch() + case http.MethodPost: + return types.MethodPost() + case http.MethodPut: + return types.MethodPut() + case http.MethodTrace: + return types.MethodTrace() + default: + return types.MethodOther(s) + } +} diff --git a/v2/http/convertor_outgoing_response.go b/v2/http/convertor_outgoing_response.go new file mode 100644 index 0000000..2301706 --- /dev/null +++ b/v2/http/convertor_outgoing_response.go @@ -0,0 +1,155 @@ +package http + +import ( + "fmt" + "net/http" + "strings" + + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/ydnar/wasm-tools-go/cm" +) + +var _ http.ResponseWriter = &responseOutparamWriter{} + +type responseOutparamWriter struct { + // wasi response outparam is set at the end of http_trigger_handle + outparam types.ResponseOutparam + // wasi response + response types.OutgoingResponse + // wasi http headers + wasiHeaders types.Fields + // go httpHeaders are reconciled on call to WriteHeader, Flush or at the end of http_trigger_handle + httpHeaders http.Header + // wasi response body is set on first write because it can only be called once + body *types.OutgoingBody + // wasi response stream is set on first write because it can only be called once + stream *streams.OutputStream + + statuscode int + + // this is to track whether a new response object has been created or not. + // if the user don't explicitly call Write(buf []byte) function, we reconcile + // implicitly with default status code 200 and response body OK + reconciled bool +} + +func (row *responseOutparamWriter) Header() http.Header { + return row.httpHeaders +} + +func (row *responseOutparamWriter) Write(buf []byte) (int, error) { + err := row.reconcile() + if err != nil { + return 0, err + } + + // acquire the response body's resource handle on first call to write + if row.body == nil { + bodyResult := row.response.Body() + if bodyResult.IsErr() { + return 0, fmt.Errorf("failed to acquire resource handle to response body: %s", bodyResult.Err()) + } + row.body = bodyResult.OK() + + writeResult := row.body.Write() + if writeResult.IsErr() { + return 0, fmt.Errorf("failed to acquire resource handle for response body's stream: %s", writeResult.Err()) + } + row.stream = writeResult.OK() + + result := cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](row.response) + types.ResponseOutparamSet(row.outparam, result) + } + + // //TODO: determine if we need to do these to fulfill the ResponseWriter contract + // // call WriteHeader(http.StatusOK) if it hasn't been called yet + // // call DetectContentType if headers doesn't contain content-type yet + // // if total data is under "a few" KB and there are no flush calls, Content-Length is added automatically + + contents := cm.ToList(buf) + writeResult := row.stream.Write(contents) + if writeResult.IsErr() { + if writeResult.Err().Closed() { + return 0, fmt.Errorf("failed to write to response body's stream: closed") + } + + //TODO: possible nil error here + return 0, fmt.Errorf("failed to write to response body's stream: %s", writeResult.Err().LastOperationFailed().ToDebugString()) + } + + row.stream.BlockingFlush() + + return int(contents.Len()), nil +} + +func (row *responseOutparamWriter) WriteHeader(statusCode int) { + row.statuscode = statusCode +} + +// reconcile headers from go to wasi +func (row *responseOutparamWriter) reconcileHeaders() error { + for key, vals := range row.httpHeaders { + // convert each value distincly + fieldVals := []types.FieldValue{} + for _, val := range vals { + fieldVals = append(fieldVals, types.FieldValue(cm.ToList([]uint8(val)))) + } + + if result := row.wasiHeaders.Set(types.FieldKey(key), cm.ToList(fieldVals)); result.IsErr() { + switch *result.Err() { + case types.HeaderErrorInvalidSyntax: + return fmt.Errorf("failed to set header %s to [%s]: invalid syntax", key, strings.Join(vals, ",")) + case types.HeaderErrorForbidden: + return fmt.Errorf("failed to set forbidden header key %s", key) + case types.HeaderErrorImmutable: + return fmt.Errorf("failed to set header on immutable header fields") + default: + return fmt.Errorf("not sure what happened here?") + } + } + } + + //TODO: handle deleted headers + + return nil +} + +// convert the ResponseOutparam to http.ResponseWriter +func NewHttpResponseWriter(out types.ResponseOutparam) *responseOutparamWriter { + row := &responseOutparamWriter{ + outparam: out, + httpHeaders: http.Header{}, + wasiHeaders: types.NewFields(), + } + + return row +} + +func (row *responseOutparamWriter) reconcile() error { + // this response has been already reconciled + // which means the user explicitly called response.Write(buf []byte) fn + if row.reconciled { + return nil + } + + err := row.reconcileHeaders() + if err != nil { + return err + } + + // setting any headers after this will cause panic + row.response = types.NewOutgoingResponse(row.wasiHeaders) + + // set status code. default to 200 + if row.statuscode == 0 { + row.statuscode = http.StatusOK + } + + row.response.SetStatusCode(types.StatusCode(row.statuscode)) + + // store that reconcilation has already happened + row.reconciled = true + + return nil +} diff --git a/v2/http/http.go b/v2/http/http.go new file mode 100644 index 0000000..a34fa24 --- /dev/null +++ b/v2/http/http.go @@ -0,0 +1,99 @@ +// Package http contains the helper functions for writing Spin HTTP components +// in TinyGo, as well as for sending outbound HTTP requests. +package http + +import ( + "fmt" + "net/http" + "os" + + incominghandler "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/incoming-handler" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/fermyon/spin-go-sdk/v2/wit" + "github.com/julienschmidt/httprouter" + "github.com/ydnar/wasm-tools-go/cm" +) + +// force wit files to be shipped with sdk dependency +var _ = wit.Wit + +func init() { + incominghandler.Exports.Handle = wasiHandle +} + +const ( + // The application base path. + HeaderBasePath = "spin-base-path" + // The component route pattern matched, _excluding_ any wildcard indicator. + HeaderComponentRoot = "spin-component-route" + // The full URL of the request. This includes full host and scheme information. + HeaderFullUrl = "spin-full-url" + // The part of the request path that was matched by the route (including + // the base and wildcard indicator if present). + HeaderMatchedRoute = "spin-matched-route" + // The request path relative to the component route (including any base). + HeaderPathInfo = "spin-path-info" + // The component route pattern matched, as written in the component + // manifest (that is, _excluding_ the base, but including the wildcard + // indicator if present). + HeaderRawComponentRoot = "spin-raw-component-route" + // The client address for the request. + HeaderClientAddr = "spin-client-addr" +) + +// Router is a http.Handler which can be used to dispatch requests to different +// handler functions via configurable routes +type Router = httprouter.Router + +// Params is a Param-slice, as returned by the router. +// The slice is ordered, the first URL parameter is also the first slice value. +// It is therefore safe to read values by the index. +type Params = httprouter.Params + +// Param is a single URL parameter, consisting of a key and a value. +type Param = httprouter.Param + +// RouterHandle is a function that can be registered to a route to handle HTTP +// requests. Like http.HandlerFunc, but has a third parameter for the values of +// wildcards (variables). +type RouterHandle = httprouter.Handle + +// New returns a new initialized Router. +// Path auto-correction, including trailing slashes, is enabled by default. +func NewRouter() *Router { + return httprouter.New() +} + +// handler is the function that will be called by the http trigger in Spin. +var handler = defaultHandler + +// defaultHandler is a placeholder for returning a useful error to stderr when +// the handler is not set. +var defaultHandler = func(http.ResponseWriter, *http.Request) { + fmt.Fprintln(os.Stderr, "http handler undefined") +} + +// Handle sets the handler function for the http trigger. +// It must be set in an init() function. +func Handle(fn func(http.ResponseWriter, *http.Request)) { + handler = fn +} + +var wasiHandle = func(request types.IncomingRequest, responseOut types.ResponseOutparam) { + // convert the incoming request to go's net/http type + httpReq, err := NewHttpRequest(request) + if err != nil { + //TODO(rajatjindal): return internal error from here + fmt.Printf("failed to convert wasi/http/types.IncomingRequest to http.Request: %s\n", err) + return + } + + // convert the response outparam to go's net/http type + httpRes := NewHttpResponseWriter(responseOut) + + // run the user's handler + handler(httpRes, httpReq) + + // ensure default status ok and response body are set + _ = httpRes.reconcile() +} diff --git a/v2/http/streams.go b/v2/http/streams.go new file mode 100644 index 0000000..5ec8210 --- /dev/null +++ b/v2/http/streams.go @@ -0,0 +1,45 @@ +package http + +import ( + "fmt" + "io" + + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" +) + +type inputStreamReader struct { + stream streams.InputStream +} + +func (r inputStreamReader) Close() error { + //noop + return nil +} + +func (r inputStreamReader) Read(p []byte) (n int, err error) { + readResult := r.stream.Read(uint64(len(p))) + if readResult.IsErr() { + readErr := readResult.Err() + if readErr.Closed() { + return 0, io.EOF + } + return 0, fmt.Errorf("failed to read from InputStream %s", readErr.LastOperationFailed().ToDebugString()) + } + + readList := readResult.OK() + copy(p, readList.Slice()) + return int(readList.Len()), nil +} + +// create an io.Reader from the input stream +func NewReader(s streams.InputStream) io.Reader { + return inputStreamReader{ + stream: s, + } +} + +func NewReadCloser(s streams.InputStream) io.ReadCloser { + return inputStreamReader{ + stream: s, + } +} diff --git a/v2/wit/wit.go b/v2/wit/wit.go new file mode 100644 index 0000000..30251b1 --- /dev/null +++ b/v2/wit/wit.go @@ -0,0 +1,6 @@ +package wit + +import "embed" + +//go:embed * +var Wit embed.FS From a2796762d5067ee5fa67dcf9f243841cc8405530 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sun, 1 Sep 2024 14:05:16 +0530 Subject: [PATCH 3/6] add basic integration test using dagger Signed-off-by: Rajat Jindal --- .dagger/.gitattributes | 4 + .dagger/.gitignore | 4 + .dagger/go.mod | 40 ++++++++++ .dagger/go.sum | 87 +++++++++++++++++++++ .dagger/main.go | 172 +++++++++++++++++++++++++++++++++++++++++ dagger.json | 6 ++ 6 files changed, 313 insertions(+) create mode 100644 .dagger/.gitattributes create mode 100644 .dagger/.gitignore create mode 100644 .dagger/go.mod create mode 100644 .dagger/go.sum create mode 100644 .dagger/main.go create mode 100644 dagger.json diff --git a/.dagger/.gitattributes b/.dagger/.gitattributes new file mode 100644 index 0000000..3a45493 --- /dev/null +++ b/.dagger/.gitattributes @@ -0,0 +1,4 @@ +/dagger.gen.go linguist-generated +/internal/dagger/** linguist-generated +/internal/querybuilder/** linguist-generated +/internal/telemetry/** linguist-generated diff --git a/.dagger/.gitignore b/.dagger/.gitignore new file mode 100644 index 0000000..7ebabcc --- /dev/null +++ b/.dagger/.gitignore @@ -0,0 +1,4 @@ +/dagger.gen.go +/internal/dagger +/internal/querybuilder +/internal/telemetry diff --git a/.dagger/go.mod b/.dagger/go.mod new file mode 100644 index 0000000..0f8bd0b --- /dev/null +++ b/.dagger/go.mod @@ -0,0 +1,40 @@ +module dagger/spin-go-sdk + +go 1.22.5 + +require ( + github.com/99designs/gqlgen v0.17.49 + github.com/Khan/genqlient v0.7.0 + github.com/vektah/gqlparser/v2 v2.5.16 + go.opentelemetry.io/otel v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 + go.opentelemetry.io/otel/log v0.3.0 + go.opentelemetry.io/otel/sdk v1.27.0 + go.opentelemetry.io/otel/sdk/log v0.3.0 + go.opentelemetry.io/otel/trace v1.27.0 + go.opentelemetry.io/proto/otlp v1.3.1 + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa + golang.org/x/sync v0.7.0 + google.golang.org/grpc v1.64.0 +) + +require ( + github.com/cenkalti/backoff/v4 v4.3.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/sosodev/duration v1.3.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect + go.opentelemetry.io/otel/metric v1.27.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect + google.golang.org/protobuf v1.34.1 // indirect +) diff --git a/.dagger/go.sum b/.dagger/go.sum new file mode 100644 index 0000000..6fea81b --- /dev/null +++ b/.dagger/go.sum @@ -0,0 +1,87 @@ +github.com/99designs/gqlgen v0.17.49 h1:b3hNGexHd33fBSAd4NDT/c3NCcQzcAVkknhN9ym36YQ= +github.com/99designs/gqlgen v0.17.49/go.mod h1:tC8YFVZMed81x7UJ7ORUwXF4Kn6SXuucFqQBhN8+BU0= +github.com/Khan/genqlient v0.7.0 h1:GZ1meyRnzcDTK48EjqB8t3bcfYvHArCUUvgOwpz1D4w= +github.com/Khan/genqlient v0.7.0/go.mod h1:HNyy3wZvuYwmW3Y7mkoQLZsa/R5n5yIRajS1kPBvSFM= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +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/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4= +github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8= +github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88 h1:oM0GTNKGlc5qHctWeIGTVyda4iFFalOzMZ3Ehj5rwB4= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88/go.mod h1:JGG8ebaMO5nXOPnvKEl+DiA4MGwFjCbjsxT1WHIEBPY= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 h1:ccBrA8nCY5mM0y5uO7FT0ze4S0TuFcWdDB2FxGMTjkI= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0/go.mod h1:/9pb6634zi2Lk8LYg9Q0X8Ar6jka4dkFOylBLbVQPCE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY= +go.opentelemetry.io/otel/log v0.3.0 h1:kJRFkpUFYtny37NQzL386WbznUByZx186DpEMKhEGZs= +go.opentelemetry.io/otel/log v0.3.0/go.mod h1:ziCwqZr9soYDwGNbIL+6kAvQC+ANvjgG367HVcyR/ys= +go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= +go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= +go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= +go.opentelemetry.io/otel/sdk/log v0.3.0 h1:GEjJ8iftz2l+XO1GF2856r7yYVh74URiF9JMcAacr5U= +go.opentelemetry.io/otel/sdk/log v0.3.0/go.mod h1:BwCxtmux6ACLuys1wlbc0+vGBd+xytjmjajwqqIul2g= +go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= +go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ= +google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/.dagger/main.go b/.dagger/main.go new file mode 100644 index 0000000..5c02b22 --- /dev/null +++ b/.dagger/main.go @@ -0,0 +1,172 @@ +// A generated module for SpinGoSdk functions +// +// This module has been generated via dagger init and serves as a reference to +// basic module structure as you get started with Dagger. +// +// Two functions have been pre-created. You can modify, delete, or add to them, +// as needed. They demonstrate usage of arguments and return types using simple +// echo and grep commands. The functions can be called from the dagger CLI or +// from one of the SDKs. +// +// The first line in this comment block is a short description line and the +// rest is a long description with more detail on the module's purpose or usage, +// if appropriate. All modules should have a short description. + +package main + +import ( + "context" + "dagger/spin-go-sdk/internal/dagger" + "fmt" + "path/filepath" + "runtime" + "strings" +) + +type Builder struct { + base string + tinygoVersion string + goVersion string + spinVersion string + wasmToolsVersion string +} + +func (m *Builder) WithTinyGoVersion(version string) *Builder { + m.tinygoVersion = version + return m +} + +func (m *Builder) WithGoVersion(version string) *Builder { + m.goVersion = version + return m +} + +func (m *Builder) WithSpinVersion(version string) *Builder { + m.spinVersion = version + return m +} + +func (m *Builder) WithWasmToolsVersion(version string) *Builder { + m.wasmToolsVersion = version + return m +} + +func (m *Builder) applyDefaults() *Builder { + if m.spinVersion == "" { + m.spinVersion = "canary" + } + + if m.tinygoVersion == "" { + m.tinygoVersion = "0.33.0" + } + + if m.goVersion == "" { + m.goVersion = "1.22.6" + } + + if m.wasmToolsVersion == "" { + m.wasmToolsVersion = "1.216.0" + } + + return m +} + +func (m *Builder) BuildEnv(ctx context.Context) *dagger.Container { + // TODO(rajatjindal): maybe there is a better way to do this + m.applyDefaults() + + // the base has to be ubuntu. I tried alpine, that didn't work + return dag.Container().From("ubuntu:latest"). + WithExec([]string{"apt-get", "update"}). + WithExec([]string{"apt-get", "install", "-y", "wget"}). + With(withSpin(m.spinVersion)). + With(withTinyGo(m.tinygoVersion)). + With(withGo(m.goVersion)). + With(withWasmTools(m.wasmToolsVersion)) +} + +func (m *Builder) BuildExample(ctx context.Context, source *dagger.Directory, example string) *dagger.Container { + return m.BuildEnv(ctx). + WithDirectory("/app", source). + WithWorkdir(fmt.Sprintf("/app/v2/examples/%s", example)). + WithExec([]string{"spin", "build"}). + WithExec([]string{"spin", "up", "-f", fmt.Sprintf("/app/v2/examples/%s", "http"), "--listen", "0.0.0.0:3000"}). + WithExposedPort(3000) +} + +func (m *Builder) TestIncomingHttp(ctx context.Context, source *dagger.Directory) error { + svc := m.BuildExample(ctx, source, "http").AsService() + + output, err := dag.Container(). + WithServiceBinding("test-service", svc). + From("curlimages/curl:latest"). + WithExec([]string{"sh", "-c", fmt.Sprintf("curl -vXGET 'http://test-service:3000/hello'")}). + Stdout(ctx) + if err != nil { + return err + } + + if !strings.Contains(output, "Hello Fermyon!") { + return fmt.Errorf("expected output to contain `Hello Fermyon!`. output: ", output) + } + + return nil +} + +func withTinyGo(version string) dagger.WithContainerFunc { + return func(c *dagger.Container) *dagger.Container { + releaseArtifactName := fmt.Sprintf("tinygo%s.%s-%s", version, runtime.GOOS, runtime.GOARCH) + releaseArtifactTarFile := fmt.Sprintf("%s.tar.gz", releaseArtifactName) + releaseArtifactDownloadLink := fmt.Sprintf("https://github.com/tinygo-org/tinygo/releases/download/v%s/%s", version, releaseArtifactTarFile) + return c. + WithExec([]string{"wget", releaseArtifactDownloadLink, "-O", releaseArtifactTarFile}). + WithExec([]string{"tar", "-xvf", releaseArtifactTarFile}). + WithExec([]string{"mkdir", "-p", "/opt"}). + WithExec([]string{"mv", "tinygo", "/opt/tinygo"}). + WithEnvVariable("TINYGOROOT", "/opt/tinygo"). + WithEnvVariable("PATH", "/opt/tinygo/bin:$PATH", dagger.ContainerWithEnvVariableOpts{ + Expand: true, + }) + } +} + +func withSpin(version string) dagger.WithContainerFunc { + return func(c *dagger.Container) *dagger.Container { + // TODO(rajatjindal): allow pulling specific version + // right now defaults to canary + return c.WithFile("/usr/local/bin/spin", dag.Container(). + From("ghcr.io/fermyon/spin:canary-distroless").File("/usr/local/bin/spin")) + } +} + +func withGo(version string) dagger.WithContainerFunc { + return func(c *dagger.Container) *dagger.Container { + releaseArtifactName := fmt.Sprintf("go%s.%s-%s", version, runtime.GOOS, runtime.GOARCH) + releaseArtifactTarFile := fmt.Sprintf("%s.tar.gz", releaseArtifactName) + releaseArtifactDownloadLink := fmt.Sprintf("https://go.dev/dl/%s", releaseArtifactTarFile) + return c. + WithExec([]string{"wget", releaseArtifactDownloadLink, "-O", releaseArtifactTarFile}). + WithExec([]string{"rm", "-rf", "/usr/local/go"}). + WithExec([]string{"tar", "-C", "/usr/local", "-xvf", releaseArtifactTarFile}). + WithEnvVariable("PATH", "/usr/local/go/bin:$PATH", dagger.ContainerWithEnvVariableOpts{ + Expand: true, + }) + } +} + +func withWasmTools(version string) dagger.WithContainerFunc { + return func(c *dagger.Container) *dagger.Container { + arch := "x86_64" + if runtime.GOARCH == "arm64" { + arch = "aarch64" + } + + releaseArtifactName := fmt.Sprintf("wasm-tools-%s-%s-%s", version, arch, runtime.GOOS) + releaseArtifactTarFile := fmt.Sprintf("%s.tar.gz", releaseArtifactName) + releaseArtifactDownloadLink := fmt.Sprintf("https://github.com/bytecodealliance/wasm-tools/releases/download/v%s/%s", version, releaseArtifactTarFile) + return c. + WithExec([]string{"wget", releaseArtifactDownloadLink, "-O", releaseArtifactTarFile}). + WithExec([]string{"tar", "-xvf", releaseArtifactTarFile}). + WithExec([]string{"mv", filepath.Join(releaseArtifactName, "wasm-tools"), "/usr/local/bin/wasm-tools"}) + } +} diff --git a/dagger.json b/dagger.json new file mode 100644 index 0000000..9e9cb16 --- /dev/null +++ b/dagger.json @@ -0,0 +1,6 @@ +{ + "name": "builder", + "sdk": "go", + "source": ".dagger", + "engineVersion": "v0.12.5" +} From b2502bfc4d1aaa364a235426148bce017e503e9a Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sun, 1 Sep 2024 14:15:06 +0530 Subject: [PATCH 4/6] add pr workflow Signed-off-by: Rajat Jindal --- .github/workflows/pr.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/pr.yaml diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..76cb37c --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,20 @@ +name: Run Integration tests +on: + push: + branches: + - wasip2-http + + workflow_dispatch: {} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Integration Tests + uses: dagger/dagger-for-github@v6 + with: + verb: call + module: . + args: test-incoming-http --source . From 9132e8b947b65fa40ab69213f7ba76808af70700 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Tue, 10 Sep 2024 06:41:21 +0530 Subject: [PATCH 5/6] use wasm-tools-go from bytecodealliance repo Signed-off-by: Rajat Jindal --- v2/examples/http/go.mod | 2 +- v2/examples/http/go.sum | 4 ++-- v2/go.mod | 2 +- v2/go.sum | 4 ++-- v2/http/client.go | 2 +- v2/http/convertor_incoming_request.go | 2 +- v2/http/convertor_outgoing_request.go | 2 +- v2/http/convertor_outgoing_response.go | 2 +- v2/http/http.go | 1 - v2/internal/fermyon/spin/config/config.wit.go | 2 +- v2/internal/fermyon/spin/http-types/http-types.wit.go | 2 +- v2/internal/fermyon/spin/http/abi.go | 2 +- v2/internal/fermyon/spin/http/http.wit.go | 2 +- v2/internal/fermyon/spin/inbound-http/abi.go | 2 +- v2/internal/fermyon/spin/key-value/key-value.wit.go | 2 +- v2/internal/fermyon/spin/llm/abi.go | 2 +- v2/internal/fermyon/spin/llm/llm.wit.go | 2 +- v2/internal/fermyon/spin/mysql/mysql.wit.go | 2 +- v2/internal/fermyon/spin/postgres/postgres.wit.go | 2 +- v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go | 2 +- v2/internal/fermyon/spin/redis-types/redis-types.wit.go | 2 +- v2/internal/fermyon/spin/redis/redis.wit.go | 2 +- v2/internal/fermyon/spin/sqlite/sqlite.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/key-value/abi.go | 2 +- v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/llm/abi.go | 2 +- v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go | 2 +- .../fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/redis/abi.go | 2 +- v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 2 +- v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go | 2 +- .../wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go | 2 +- v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go | 2 +- v2/internal/wasi/filesystem/v0.2.0/types/abi.go | 2 +- v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go | 2 +- .../wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go | 2 +- v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go | 2 +- .../wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go | 2 +- v2/internal/wasi/http/v0.2.0/types/abi.go | 2 +- v2/internal/wasi/http/v0.2.0/types/types.wit.go | 2 +- v2/internal/wasi/io/v0.2.0/error/error.wit.go | 2 +- v2/internal/wasi/io/v0.2.0/poll/poll.wit.go | 2 +- v2/internal/wasi/io/v0.2.0/streams/streams.wit.go | 2 +- v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go | 2 +- v2/internal/wasi/random/v0.2.0/random/random.wit.go | 2 +- .../sockets/v0.2.0/instance-network/instance-network.wit.go | 2 +- v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 2 +- .../wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go | 2 +- v2/internal/wasi/sockets/v0.2.0/network/network.wit.go | 2 +- .../sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go | 2 +- v2/internal/wasi/sockets/v0.2.0/tcp/abi.go | 2 +- v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go | 2 +- .../sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go | 2 +- v2/internal/wasi/sockets/v0.2.0/udp/abi.go | 2 +- v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go | 2 +- 69 files changed, 70 insertions(+), 71 deletions(-) diff --git a/v2/examples/http/go.mod b/v2/examples/http/go.mod index a9d959b..363619d 100644 --- a/v2/examples/http/go.mod +++ b/v2/examples/http/go.mod @@ -5,8 +5,8 @@ go 1.22.6 require github.com/fermyon/spin-go-sdk/v2 v2.0.0 require ( + github.com/bytecodealliance/wasm-tools-go v0.2.0 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - github.com/ydnar/wasm-tools-go v0.1.5 // indirect ) replace github.com/fermyon/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/http/go.sum b/v2/examples/http/go.sum index a445b61..6c36048 100644 --- a/v2/examples/http/go.sum +++ b/v2/examples/http/go.sum @@ -1,4 +1,4 @@ +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/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= -github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= diff --git a/v2/go.mod b/v2/go.mod index b859d85..130cfb4 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -3,6 +3,6 @@ module github.com/fermyon/spin-go-sdk/v2 go 1.22.6 require ( + github.com/bytecodealliance/wasm-tools-go v0.2.0 github.com/julienschmidt/httprouter v1.3.0 - github.com/ydnar/wasm-tools-go v0.1.5 ) diff --git a/v2/go.sum b/v2/go.sum index a445b61..6c36048 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,4 +1,4 @@ +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/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= -github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= diff --git a/v2/http/client.go b/v2/http/client.go index f041d5d..d16ad7e 100644 --- a/v2/http/client.go +++ b/v2/http/client.go @@ -5,9 +5,9 @@ import ( "io" "net/http" + "github.com/bytecodealliance/wasm-tools-go/cm" outgoinghandler "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/outgoing-handler" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) // NewTransport returns http.RoundTripper backed by Spin SDK diff --git a/v2/http/convertor_incoming_request.go b/v2/http/convertor_incoming_request.go index f682cee..53d0c00 100644 --- a/v2/http/convertor_incoming_request.go +++ b/v2/http/convertor_incoming_request.go @@ -5,8 +5,8 @@ import ( "io" "net/http" + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) type IncomingRequest = types.IncomingRequest diff --git a/v2/http/convertor_outgoing_request.go b/v2/http/convertor_outgoing_request.go index 50ffb75..afe494e 100644 --- a/v2/http/convertor_outgoing_request.go +++ b/v2/http/convertor_outgoing_request.go @@ -3,8 +3,8 @@ package http import ( "net/http" + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) // convert the IncomingRequest to http.Request diff --git a/v2/http/convertor_outgoing_response.go b/v2/http/convertor_outgoing_response.go index 2301706..36678d8 100644 --- a/v2/http/convertor_outgoing_response.go +++ b/v2/http/convertor_outgoing_response.go @@ -5,9 +5,9 @@ import ( "net/http" "strings" + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) var _ http.ResponseWriter = &responseOutparamWriter{} diff --git a/v2/http/http.go b/v2/http/http.go index a34fa24..7ac5d5d 100644 --- a/v2/http/http.go +++ b/v2/http/http.go @@ -11,7 +11,6 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "github.com/fermyon/spin-go-sdk/v2/wit" "github.com/julienschmidt/httprouter" - "github.com/ydnar/wasm-tools-go/cm" ) // force wit files to be shipped with sdk dependency diff --git a/v2/internal/fermyon/spin/config/config.wit.go b/v2/internal/fermyon/spin/config/config.wit.go index 063d142..99979b3 100644 --- a/v2/internal/fermyon/spin/config/config.wit.go +++ b/v2/internal/fermyon/spin/config/config.wit.go @@ -4,7 +4,7 @@ package config import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the variant "fermyon:spin/config#error". diff --git a/v2/internal/fermyon/spin/http-types/http-types.wit.go b/v2/internal/fermyon/spin/http-types/http-types.wit.go index fe11ccc..500b6d1 100644 --- a/v2/internal/fermyon/spin/http-types/http-types.wit.go +++ b/v2/internal/fermyon/spin/http-types/http-types.wit.go @@ -4,7 +4,7 @@ package httptypes import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // HTTPStatus represents the u16 "fermyon:spin/http-types#http-status". diff --git a/v2/internal/fermyon/spin/http/abi.go b/v2/internal/fermyon/spin/http/abi.go index 896811c..863023f 100644 --- a/v2/internal/fermyon/spin/http/abi.go +++ b/v2/internal/fermyon/spin/http/abi.go @@ -3,8 +3,8 @@ package http import ( + "github.com/bytecodealliance/wasm-tools-go/cm" httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/http/http.wit.go b/v2/internal/fermyon/spin/http/http.wit.go index 46da5bd..80b0a83 100644 --- a/v2/internal/fermyon/spin/http/http.wit.go +++ b/v2/internal/fermyon/spin/http/http.wit.go @@ -4,8 +4,8 @@ package http import ( + "github.com/bytecodealliance/wasm-tools-go/cm" httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" - "github.com/ydnar/wasm-tools-go/cm" ) // SendRequest represents the imported function "send-request". diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v2/internal/fermyon/spin/inbound-http/abi.go index ecd701e..c29d6c0 100644 --- a/v2/internal/fermyon/spin/inbound-http/abi.go +++ b/v2/internal/fermyon/spin/inbound-http/abi.go @@ -3,8 +3,8 @@ package inboundhttp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" - "github.com/ydnar/wasm-tools-go/cm" ) func lift_OptionBody(f0 uint32, f1 *uint8, f2 uint32) (v cm.Option[httptypes.Body]) { diff --git a/v2/internal/fermyon/spin/key-value/key-value.wit.go b/v2/internal/fermyon/spin/key-value/key-value.wit.go index 5dc38a4..e7ebda0 100644 --- a/v2/internal/fermyon/spin/key-value/key-value.wit.go +++ b/v2/internal/fermyon/spin/key-value/key-value.wit.go @@ -4,7 +4,7 @@ package keyvalue import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Store represents the u32 "fermyon:spin/key-value#store". diff --git a/v2/internal/fermyon/spin/llm/abi.go b/v2/internal/fermyon/spin/llm/abi.go index b75401b..2f54050 100644 --- a/v2/internal/fermyon/spin/llm/abi.go +++ b/v2/internal/fermyon/spin/llm/abi.go @@ -3,7 +3,7 @@ package llm import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/llm/llm.wit.go b/v2/internal/fermyon/spin/llm/llm.wit.go index 929e5c3..46f9e4c 100644 --- a/v2/internal/fermyon/spin/llm/llm.wit.go +++ b/v2/internal/fermyon/spin/llm/llm.wit.go @@ -6,7 +6,7 @@ package llm import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // InferencingModel represents the string "fermyon:spin/llm#inferencing-model". diff --git a/v2/internal/fermyon/spin/mysql/mysql.wit.go b/v2/internal/fermyon/spin/mysql/mysql.wit.go index 569fbee..e2dee05 100644 --- a/v2/internal/fermyon/spin/mysql/mysql.wit.go +++ b/v2/internal/fermyon/spin/mysql/mysql.wit.go @@ -4,8 +4,8 @@ package mysql import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" - "github.com/ydnar/wasm-tools-go/cm" ) // MysqlError represents the variant "fermyon:spin/mysql#mysql-error". diff --git a/v2/internal/fermyon/spin/postgres/postgres.wit.go b/v2/internal/fermyon/spin/postgres/postgres.wit.go index 9f4c59a..506470b 100644 --- a/v2/internal/fermyon/spin/postgres/postgres.wit.go +++ b/v2/internal/fermyon/spin/postgres/postgres.wit.go @@ -4,8 +4,8 @@ package postgres import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" - "github.com/ydnar/wasm-tools-go/cm" ) // PgError represents the variant "fermyon:spin/postgres#pg-error". diff --git a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go index bdfb8da..a584658 100644 --- a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go +++ b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go @@ -4,7 +4,7 @@ package rdbmstypes import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // DbDataType represents the enum "fermyon:spin/rdbms-types#db-data-type". diff --git a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go index f6e4dcd..bbad113 100644 --- a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go +++ b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go @@ -4,7 +4,7 @@ package redistypes import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the enum "fermyon:spin/redis-types#error". diff --git a/v2/internal/fermyon/spin/redis/redis.wit.go b/v2/internal/fermyon/spin/redis/redis.wit.go index 5500293..1090bf5 100644 --- a/v2/internal/fermyon/spin/redis/redis.wit.go +++ b/v2/internal/fermyon/spin/redis/redis.wit.go @@ -4,8 +4,8 @@ package redis import ( + "github.com/bytecodealliance/wasm-tools-go/cm" redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" - "github.com/ydnar/wasm-tools-go/cm" ) // Publish represents the imported function "publish". diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go index 5a895cd..93da5d9 100644 --- a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go @@ -4,7 +4,7 @@ package sqlite import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Connection represents the u32 "fermyon:spin/sqlite#connection". diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go index 3b9d3d5..c3f28e4 100644 --- a/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go @@ -3,7 +3,7 @@ package keyvalue import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go index 6b7b037..f38c71a 100644 --- a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go @@ -4,7 +4,7 @@ package keyvalue import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Store represents the imported resource "fermyon:spin/key-value@2.0.0#store". diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go index b75401b..2f54050 100644 --- a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go @@ -3,7 +3,7 @@ package llm import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go index 88bcb96..76eb6a4 100644 --- a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go @@ -6,7 +6,7 @@ package llm import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // InferencingModel represents the string "fermyon:spin/llm@2.0.0#inferencing-model". diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go index 3409d31..9d4f8c5 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go @@ -4,7 +4,7 @@ package mqtt import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the variant "fermyon:spin/mqtt@2.0.0#error". diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go index cf7791d..49855dd 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go @@ -4,8 +4,8 @@ package mysql import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" - "github.com/ydnar/wasm-tools-go/cm" ) // Connection represents the imported resource "fermyon:spin/mysql@2.0.0#connection". diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go index 19ae149..83ddb27 100644 --- a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go @@ -4,8 +4,8 @@ package postgres import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" - "github.com/ydnar/wasm-tools-go/cm" ) // Connection represents the imported resource "fermyon:spin/postgres@2.0.0#connection". diff --git a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go index 7d37564..097db56 100644 --- a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go @@ -4,7 +4,7 @@ package rdbmstypes import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the variant "fermyon:spin/rdbms-types@2.0.0#error". diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go index 7bd36a5..a1c2b51 100644 --- a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go @@ -3,7 +3,7 @@ package redis import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go index a7d7cd6..9fc8aed 100644 --- a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go @@ -4,7 +4,7 @@ package redis import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the variant "fermyon:spin/redis@2.0.0#error". diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go index dd46721..f2eeb11 100644 --- a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go @@ -4,7 +4,7 @@ package sqlite import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Connection represents the imported resource "fermyon:spin/sqlite@2.0.0#connection". diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go index bb51cc5..d8524e2 100644 --- a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go @@ -4,7 +4,7 @@ package variables import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the variant "fermyon:spin/variables@2.0.0#error". diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go index a582bdf..48e066d 100644 --- a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go @@ -4,7 +4,7 @@ package environment import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetEnvironment represents the imported function "get-environment". diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go index bf46d1b..3fccd93 100644 --- a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -4,7 +4,7 @@ package exit import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Exit represents the imported function "exit". diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go index 2fefd03..bf3e752 100644 --- a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -4,8 +4,8 @@ package stderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStderr represents the imported function "get-stderr". diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go index 532179a..fa94f9a 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -4,8 +4,8 @@ package stdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdin represents the imported function "get-stdin". diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go index d2a4ef5..ae711bb 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -4,8 +4,8 @@ package stdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // GetStdout represents the imported function "get-stdout". diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go index 9dca7df..e0114e0 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go @@ -10,7 +10,7 @@ package terminalinput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go index b6ff728..a63b0e6 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go @@ -10,7 +10,7 @@ package terminaloutput import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go index 4ce0f21..ed076a4 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -7,8 +7,8 @@ package terminalstderr import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStderr represents the imported function "get-terminal-stderr". diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go index 486a0b0..925e6dc 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -7,8 +7,8 @@ package terminalstdin import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminalinput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdin represents the imported function "get-terminal-stdin". diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go index f6b5cbc..88d77b0 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -7,8 +7,8 @@ package terminalstdout import ( + "github.com/bytecodealliance/wasm-tools-go/cm" terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" - "github.com/ydnar/wasm-tools-go/cm" ) // GetTerminalStdout represents the imported function "get-terminal-stdout". diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go index b168d28..68ffd9a 100644 --- a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -15,8 +15,8 @@ package monotonicclock import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/ydnar/wasm-tools-go/cm" ) // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go index dc09813..2f950ea 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -4,8 +4,8 @@ package preopens import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) // GetDirectories represents the imported function "get-directories". diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go index 2f5edfa..a22b723 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go +++ b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go index 11f0d2c..0408a1c 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go +++ b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -29,10 +29,10 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go index 4c0505f..22efec3 100644 --- a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go @@ -7,8 +7,8 @@ package incominghandler import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) //go:wasmexport wasi:http/incoming-handler@0.2.0#handle diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go index a0a35d9..8f28928 100644 --- a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go @@ -3,8 +3,8 @@ package outgoinghandler import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go index 1945bc0..9576fe0 100644 --- a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go @@ -7,8 +7,8 @@ package outgoinghandler import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/ydnar/wasm-tools-go/cm" ) // Handle represents the imported function "handle". diff --git a/v2/internal/wasi/http/v0.2.0/types/abi.go b/v2/internal/wasi/http/v0.2.0/types/abi.go index ff37570..2a9193e 100644 --- a/v2/internal/wasi/http/v0.2.0/types/abi.go +++ b/v2/internal/wasi/http/v0.2.0/types/abi.go @@ -3,8 +3,8 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wit.go b/v2/internal/wasi/http/v0.2.0/types/types.wit.go index 7e8d905..96ea918 100644 --- a/v2/internal/wasi/http/v0.2.0/types/types.wit.go +++ b/v2/internal/wasi/http/v0.2.0/types/types.wit.go @@ -8,11 +8,11 @@ package types import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/ydnar/wasm-tools-go/cm" ) // Method represents the variant "wasi:http/types@0.2.0#method". diff --git a/v2/internal/wasi/io/v0.2.0/error/error.wit.go b/v2/internal/wasi/io/v0.2.0/error/error.wit.go index 96d18cf..61d61db 100644 --- a/v2/internal/wasi/io/v0.2.0/error/error.wit.go +++ b/v2/internal/wasi/io/v0.2.0/error/error.wit.go @@ -4,7 +4,7 @@ package ioerror import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Error represents the imported resource "wasi:io/error@0.2.0#error". diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go index ba22e54..d11852f 100644 --- a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -7,7 +7,7 @@ package poll import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go index 8e9d2ae..d69726d 100644 --- a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go +++ b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -10,9 +10,9 @@ package streams import ( + "github.com/bytecodealliance/wasm-tools-go/cm" ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/ydnar/wasm-tools-go/cm" ) // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go index 4f813bf..bfe1e6c 100644 --- a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go +++ b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go @@ -9,7 +9,7 @@ package insecure import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wit.go b/v2/internal/wasi/random/v0.2.0/random/random.wit.go index 04b2319..da2eb57 100644 --- a/v2/internal/wasi/random/v0.2.0/random/random.wit.go +++ b/v2/internal/wasi/random/v0.2.0/random/random.wit.go @@ -9,7 +9,7 @@ package random import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // GetRandomBytes represents the imported function "get-random-bytes". diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go index af26e1b..6f094e6 100644 --- a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -6,8 +6,8 @@ package instancenetwork import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" ) // InstanceNetwork represents the imported function "instance-network". diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go index b1c29e6..23564f4 100644 --- a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go @@ -3,8 +3,8 @@ package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go index b331a64..a4154fb 100644 --- a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -4,9 +4,9 @@ package ipnamelookup import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" ) // ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go index 4597e24..b18bec9 100644 --- a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -4,7 +4,7 @@ package network import ( - "github.com/ydnar/wasm-tools-go/cm" + "github.com/bytecodealliance/wasm-tools-go/cm" ) // Network represents the imported resource "wasi:sockets/network@0.2.0#network". diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go index d3ef366..ce311f8 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -4,9 +4,9 @@ package tcpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/tcp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateTCPSocket represents the imported function "create-tcp-socket". diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go index a2b2609..ca71a81 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -3,9 +3,9 @@ package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go index 5cf0ea3..517451c 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -4,11 +4,11 @@ package tcp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" ) // ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go index 3d6e832..e52316f 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -4,9 +4,9 @@ package udpcreatesocket import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/udp" - "github.com/ydnar/wasm-tools-go/cm" ) // CreateUDPSocket represents the imported function "create-udp-socket". diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go index bb6be9a..6d5e282 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -3,8 +3,8 @@ package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" "unsafe" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go index 3e299c1..d4a6591 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -4,9 +4,9 @@ package udp import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/ydnar/wasm-tools-go/cm" ) // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". From 67b4c9592eadeda9ce3c6d714d0c8319be1a6a3c Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sat, 19 Oct 2024 07:40:02 +0530 Subject: [PATCH 6/6] update to latest version of wasm tools go Signed-off-by: Rajat Jindal --- v2/examples/http/go.mod | 2 +- v2/examples/http/go.sum | 4 +- v2/go.mod | 2 +- v2/go.sum | 4 +- v2/internal/fermyon/spin/config/abi.go | 2 + .../fermyon/spin/config/config.wasm.go | 13 + v2/internal/fermyon/spin/config/config.wit.go | 16 +- .../spin/http-trigger/http-trigger.wit | 442 +++ .../fermyon/spin/http-types/http-types.wit.go | 2 + v2/internal/fermyon/spin/http/abi.go | 1 + v2/internal/fermyon/spin/http/http.wasm.go | 13 + v2/internal/fermyon/spin/http/http.wit.go | 21 +- v2/internal/fermyon/spin/inbound-http/abi.go | 2 +- .../spin/inbound-http/inbound-http.exports.go | 6 +- .../spin/inbound-http/inbound-http.wit.go | 17 +- .../spin/inbound-http/inboundhttp.wasm.go | 14 + v2/internal/fermyon/spin/key-value/abi.go | 2 + .../fermyon/spin/key-value/key-value.wit.go | 42 +- .../fermyon/spin/key-value/keyvalue.wasm.go | 37 + v2/internal/fermyon/spin/llm/abi.go | 2 + v2/internal/fermyon/spin/llm/llm.wasm.go | 17 + v2/internal/fermyon/spin/llm/llm.wit.go | 24 +- v2/internal/fermyon/spin/mysql/abi.go | 7 +- v2/internal/fermyon/spin/mysql/mysql.wasm.go | 17 + v2/internal/fermyon/spin/mysql/mysql.wit.go | 40 +- v2/internal/fermyon/spin/postgres/abi.go | 3 + .../fermyon/spin/postgres/postgres.wasm.go | 17 + .../fermyon/spin/postgres/postgres.wit.go | 40 +- .../spin/rdbms-types/rdbms-types.wit.go | 47 + .../spin/redis-types/redis-types.wit.go | 22 + v2/internal/fermyon/spin/redis/redis.wasm.go | 46 + v2/internal/fermyon/spin/redis/redis.wit.go | 76 +- v2/internal/fermyon/spin/sqlite/abi.go | 3 + .../fermyon/spin/sqlite/sqlite.wasm.go | 21 + v2/internal/fermyon/spin/sqlite/sqlite.wit.go | 40 +- .../spin/v2.0.0/http-trigger/http-trigger.wit | 3121 +++++++++++++++++ .../fermyon/spin/v2.0.0/key-value/abi.go | 2 + .../spin/v2.0.0/key-value/key-value.wit.go | 40 +- .../spin/v2.0.0/key-value/keyvalue.wasm.go | 37 + v2/internal/fermyon/spin/v2.0.0/llm/abi.go | 2 + .../fermyon/spin/v2.0.0/llm/llm.wasm.go | 17 + .../fermyon/spin/v2.0.0/llm/llm.wit.go | 24 +- v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 2 + .../fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go | 21 + .../fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 24 +- v2/internal/fermyon/spin/v2.0.0/mysql/abi.go | 3 + .../fermyon/spin/v2.0.0/mysql/mysql.wasm.go | 25 + .../fermyon/spin/v2.0.0/mysql/mysql.wit.go | 41 +- .../fermyon/spin/v2.0.0/postgres/abi.go | 3 + .../spin/v2.0.0/postgres/postgres.wasm.go | 25 + .../spin/v2.0.0/postgres/postgres.wit.go | 41 +- .../v2.0.0/rdbms-types/rdbms-types.wit.go | 60 + v2/internal/fermyon/spin/v2.0.0/redis/abi.go | 2 + .../fermyon/spin/v2.0.0/redis/redis.wasm.go | 53 + .../fermyon/spin/v2.0.0/redis/redis.wit.go | 78 +- v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go | 3 + .../fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go | 21 + .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 40 +- .../fermyon/spin/v2.0.0/variables/abi.go | 2 + .../spin/v2.0.0/variables/variables.wasm.go | 13 + .../spin/v2.0.0/variables/variables.wit.go | 16 +- .../v0.2.0/environment/environment.wasm.go | 21 + .../cli/v0.2.0/environment/environment.wit.go | 12 - v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go | 9 + v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 4 - .../wasi/cli/v0.2.0/stderr/stderr.wasm.go | 9 + .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 13 +- .../wasi/cli/v0.2.0/stdin/stdin.wasm.go | 9 + .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 13 +- .../wasi/cli/v0.2.0/stdout/stdout.wasm.go | 9 + .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 13 +- .../terminal-input/terminal-input.wit.go | 4 - .../terminal-input/terminalinput.wasm.go | 9 + .../terminal-output/terminal-output.wit.go | 4 - .../terminal-output/terminaloutput.wasm.go | 9 + .../terminal-stderr/terminal-stderr.wit.go | 11 +- .../terminal-stderr/terminalstderr.wasm.go | 13 + .../terminal-stdin/terminal-stdin.wit.go | 11 +- .../terminal-stdin/terminalstdin.wasm.go | 13 + .../terminal-stdout/terminal-stdout.wit.go | 11 +- .../terminal-stdout/terminalstdout.wasm.go | 13 + .../monotonic-clock/monotonic-clock.wit.go | 29 +- .../monotonic-clock/monotonicclock.wasm.go | 21 + .../v0.2.0/wall-clock/wall-clock.wit.go | 13 +- .../v0.2.0/wall-clock/wallclock.wasm.go | 13 + .../v0.2.0/preopens/preopens.wasm.go | 13 + .../v0.2.0/preopens/preopens.wit.go | 11 +- .../wasi/filesystem/v0.2.0/types/abi.go | 9 +- .../filesystem/v0.2.0/types/types.wasm.go | 133 + .../wasi/filesystem/v0.2.0/types/types.wit.go | 183 +- .../incoming-handler.exports.go | 6 +- .../incoming-handler/incoming-handler.wit.go | 18 +- .../incoming-handler/incominghandler.wasm.go | 18 + .../wasi/http/v0.2.0/outgoing-handler/abi.go | 3 +- .../outgoing-handler/outgoing-handler.wit.go | 26 +- .../outgoing-handler/outgoinghandler.wasm.go | 13 + v2/internal/wasi/http/v0.2.0/types/abi.go | 17 +- .../wasi/http/v0.2.0/types/types.wasm.go | 257 ++ .../wasi/http/v0.2.0/types/types.wit.go | 410 +-- v2/internal/wasi/io/v0.2.0/error/error.wit.go | 8 - .../wasi/io/v0.2.0/error/ioerror.wasm.go | 13 + v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go | 25 + v2/internal/wasi/io/v0.2.0/poll/poll.wit.go | 16 - .../wasi/io/v0.2.0/streams/streams.wasm.go | 77 + .../wasi/io/v0.2.0/streams/streams.wit.go | 106 +- .../v0.2.0/insecure-seed/insecure-seed.wit.go | 4 - .../v0.2.0/insecure-seed/insecureseed.wasm.go | 9 + .../random/v0.2.0/insecure/insecure.wasm.go | 17 + .../random/v0.2.0/insecure/insecure.wit.go | 8 - .../wasi/random/v0.2.0/random/random.wasm.go | 17 + .../wasi/random/v0.2.0/random/random.wit.go | 8 - .../instance-network/instance-network.wit.go | 13 +- .../instance-network/instancenetwork.wasm.go | 9 + .../wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 4 +- .../ip-name-lookup/ip-name-lookup.wit.go | 44 +- .../ip-name-lookup/ipnamelookup.wasm.go | 25 + .../wasi/sockets/v0.2.0/network/abi.go | 2 + .../sockets/v0.2.0/network/network.wasm.go | 9 + .../sockets/v0.2.0/network/network.wit.go | 26 +- .../tcp-create-socket.wit.go | 26 +- .../tcp-create-socket/tcpcreatesocket.wasm.go | 13 + v2/internal/wasi/sockets/v0.2.0/tcp/abi.go | 8 +- .../wasi/sockets/v0.2.0/tcp/tcp.wasm.go | 125 + .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 212 +- .../udp-create-socket.wit.go | 26 +- .../udp-create-socket/udpcreatesocket.wasm.go | 13 + v2/internal/wasi/sockets/v0.2.0/udp/abi.go | 4 +- .../wasi/sockets/v0.2.0/udp/udp.wasm.go | 93 + .../wasi/sockets/v0.2.0/udp/udp.wit.go | 157 +- 129 files changed, 6043 insertions(+), 1257 deletions(-) create mode 100755 v2/internal/fermyon/spin/config/config.wasm.go create mode 100755 v2/internal/fermyon/spin/http-trigger/http-trigger.wit create mode 100755 v2/internal/fermyon/spin/http/http.wasm.go create mode 100755 v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go create mode 100755 v2/internal/fermyon/spin/key-value/keyvalue.wasm.go create mode 100755 v2/internal/fermyon/spin/llm/llm.wasm.go create mode 100755 v2/internal/fermyon/spin/mysql/mysql.wasm.go create mode 100755 v2/internal/fermyon/spin/postgres/postgres.wasm.go create mode 100755 v2/internal/fermyon/spin/redis/redis.wasm.go create mode 100755 v2/internal/fermyon/spin/sqlite/sqlite.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit create mode 100755 v2/internal/fermyon/spin/v2.0.0/key-value/keyvalue.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-input/terminalinput.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-output/terminaloutput.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminalstderr.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminalstdin.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminalstdout.wasm.go create mode 100755 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonicclock.wasm.go create mode 100755 v2/internal/wasi/clocks/v0.2.0/wall-clock/wallclock.wasm.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go create mode 100755 v2/internal/wasi/http/v0.2.0/incoming-handler/incominghandler.wasm.go create mode 100755 v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoinghandler.wasm.go create mode 100755 v2/internal/wasi/http/v0.2.0/types/types.wasm.go create mode 100755 v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go create mode 100755 v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go create mode 100755 v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go create mode 100755 v2/internal/wasi/random/v0.2.0/insecure-seed/insecureseed.wasm.go create mode 100755 v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go create mode 100755 v2/internal/wasi/random/v0.2.0/random/random.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/instance-network/instancenetwork.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ipnamelookup.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcpcreatesocket.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udpcreatesocket.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go diff --git a/v2/examples/http/go.mod b/v2/examples/http/go.mod index 363619d..5b95171 100644 --- a/v2/examples/http/go.mod +++ b/v2/examples/http/go.mod @@ -5,7 +5,7 @@ go 1.22.6 require github.com/fermyon/spin-go-sdk/v2 v2.0.0 require ( - github.com/bytecodealliance/wasm-tools-go v0.2.0 // indirect + github.com/bytecodealliance/wasm-tools-go v0.3.0 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect ) diff --git a/v2/examples/http/go.sum b/v2/examples/http/go.sum index 6c36048..89cd75b 100644 --- a/v2/examples/http/go.sum +++ b/v2/examples/http/go.sum @@ -1,4 +1,4 @@ -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.3.0 h1:9aeDFYpbi3gtIW/nJCH+P+LhFMqezGoOfzqbUZLadho= +github.com/bytecodealliance/wasm-tools-go v0.3.0/go.mod h1:VY+9FlpLi6jnhCrZLkyJjF9rjU4aEekgaRTk28MS2JE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/v2/go.mod b/v2/go.mod index 130cfb4..42b67b9 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -3,6 +3,6 @@ module github.com/fermyon/spin-go-sdk/v2 go 1.22.6 require ( - github.com/bytecodealliance/wasm-tools-go v0.2.0 + github.com/bytecodealliance/wasm-tools-go v0.3.0 github.com/julienschmidt/httprouter v1.3.0 ) diff --git a/v2/go.sum b/v2/go.sum index 6c36048..89cd75b 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,4 +1,4 @@ -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.3.0 h1:9aeDFYpbi3gtIW/nJCH+P+LhFMqezGoOfzqbUZLadho= +github.com/bytecodealliance/wasm-tools-go v0.3.0/go.mod h1:VY+9FlpLi6jnhCrZLkyJjF9rjU4aEekgaRTk28MS2JE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/v2/internal/fermyon/spin/config/abi.go b/v2/internal/fermyon/spin/config/abi.go index fb89be6..1e8e628 100644 --- a/v2/internal/fermyon/spin/config/abi.go +++ b/v2/internal/fermyon/spin/config/abi.go @@ -3,10 +3,12 @@ package config import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } diff --git a/v2/internal/fermyon/spin/config/config.wasm.go b/v2/internal/fermyon/spin/config/config.wasm.go new file mode 100755 index 0000000..06e46ba --- /dev/null +++ b/v2/internal/fermyon/spin/config/config.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package config + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/config get-config +//go:noescape +func wasmimport_GetConfig(key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/fermyon/spin/config/config.wit.go b/v2/internal/fermyon/spin/config/config.wit.go index 99979b3..7c3fd18 100644 --- a/v2/internal/fermyon/spin/config/config.wit.go +++ b/v2/internal/fermyon/spin/config/config.wit.go @@ -57,6 +57,18 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } +var stringsError = [4]string{ + "provider", + "invalid-key", + "invalid-schema", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // GetConfig represents the imported function "get-config". // // Get a configuration value for the current component. @@ -70,7 +82,3 @@ func GetConfig(key string) (result cm.Result[ErrorShape, string, Error]) { wasmimport_GetConfig((*uint8)(key0), (uint32)(key1), &result) return } - -//go:wasmimport fermyon:spin/config get-config -//go:noescape -func wasmimport_GetConfig(key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/fermyon/spin/http-trigger/http-trigger.wit b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit new file mode 100755 index 0000000..82dc634 --- /dev/null +++ b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit @@ -0,0 +1,442 @@ +package fermyon:spin; + +interface config { + variant error { + provider(string), + invalid-key(string), + invalid-schema(string), + other(string), + } + + /// Get a configuration value for the current component. + /// The config key must match one defined in in the component manifest. + get-config: func(key: string) -> result; +} + +interface http-types { + type http-status = u16; + type body = list; + type headers = list>; + type params = list>; + type uri = string; + enum method { + get, + post, + put, + delete, + patch, + head, + options + } + record request { + method: method, + uri: uri, + headers: headers, + params: params, + body: option, + } + record response { + status: http-status, + headers: option, + body: option, + } + enum http-error { + success, + destination-not-allowed, + invalid-url, + request-error, + runtime-error, + too-many-requests + } +} + +interface http { + use http-types.{request}; + use http-types.{response}; + use http-types.{http-error}; + send-request: func(req: request) -> result; +} + +interface inbound-http { + use http-types.{request}; + use http-types.{response}; + handle-request: func(req: request) -> response; +} + +interface key-value { + /// A handle to an open key-value store + type store = u32; + + /// The set of errors which may be raised by functions in this interface + variant error { + /// Too many stores have been opened simultaneously. Closing one or more + /// stores prior to retrying may address this. + store-table-full, + /// The host does not recognize the store name requested. Defining and + /// configuring a store with that name in a runtime configuration file + /// may address this. + no-such-store, + /// The requesting component does not have access to the specified store + /// (which may or may not exist). + access-denied, + /// The store handle provided is not recognized, i.e. it was either never + /// opened or has been closed. + invalid-store, + /// No key-value tuple exists for the specified key in the specified + /// store. + no-such-key, + /// Some implementation-specific error has occurred (e.g. I/O) + io(string), + } + + /// Open the store with the specified name. + /// + /// If `name` is "default", the default store is opened. Otherwise, + /// `name` must refer to a store defined and configured in a runtime + /// configuration file supplied with the application. + /// + /// `error::no-such-store` will be raised if the `name` is not recognized. + open: func(name: string) -> result; + + /// Get the value associated with the specified `key` from the specified + /// `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store, and `error::no-such-key` will be raised if there is no + /// tuple for `key` in `store`. + get: func(store: store, key: string) -> result, error>; + + /// Set the `value` associated with the specified `key` in the specified + /// `store`, overwriting any existing value. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. + set: func(store: store, key: string, value: list) -> result<_, error>; + + /// Delete the tuple with the specified `key` from the specified `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. No error is raised if a tuple did not previously + /// exist for `key`. + delete: func(store: store, key: string) -> result<_, error>; + + /// Return whether a tuple exists for the specified `key` in the specified + /// `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. + exists: func(store: store, key: string) -> result; + + /// Return a list of all the keys in the specified `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. + get-keys: func(store: store) -> result, error>; + + /// Close the specified `store`. + /// + /// This has no effect if `store` is not a valid handle to an open store. + close: func(store: store); +} + +/// A WASI interface dedicated to performing inferencing for Large Language Models. +interface llm { + /// A Large Language Model. + type inferencing-model = string; + + /// Inference request parameters + record inferencing-params { + /// The maximum tokens that should be inferred. + /// + /// Note: the backing implementation may return less tokens. + max-tokens: u32, + /// The amount the model should avoid repeating tokens. + repeat-penalty: f32, + /// The number of tokens the model should apply the repeat penalty to. + repeat-penalty-last-n-token-count: u32, + /// The randomness with which the next token is selected. + temperature: f32, + /// The number of possible next tokens the model will choose from. + top-k: u32, + /// The probability total of next tokens the model will choose from. + top-p: f32, + } + + /// The set of errors which may be raised by functions in this interface + variant error { + model-not-supported, + runtime-error(string), + invalid-input(string), + } + + /// Usage information related to the inferencing result + record inferencing-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + /// Number of tokens generated by the inferencing operation + generated-token-count: u32, + } + + /// An inferencing result + record inferencing-result { + /// The text generated by the model + /// TODO: this should be a stream + text: string, + /// Usage information about the inferencing request + usage: inferencing-usage, + } + + /// The model used for generating embeddings + type embedding-model = string; + + /// Usage related to an embeddings generation request + record embeddings-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + } + + /// Result of generating embeddings + record embeddings-result { + /// The embeddings generated by the request + embeddings: list>, + /// Usage related to the embeddings generation request + usage: embeddings-usage, + } + + /// Perform inferencing using the provided model and prompt with the given optional + /// params + infer: func(model: inferencing-model, prompt: string, params: option) -> result; + + /// Generate embeddings for the supplied list of text + generate-embeddings: func(model: embedding-model, text: list) -> result; +} + +interface rdbms-types { + enum db-data-type { + boolean, + int8, + int16, + int32, + int64, + uint8, + uint16, + uint32, + uint64, + floating32, + floating64, + str, + binary, + other + } + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + db-null, + unsupported, + } + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + db-null, + } + record column { + name: string, + data-type: db-data-type, + } + type row = list; + record row-set { + columns: list, + rows: list, + } +} + +interface mysql { + use rdbms-types.{parameter-value}; + use rdbms-types.{row-set}; + + /// General purpose error. + variant mysql-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string), + } + + /// query the database: select + query: func(address: string, statement: string, params: list) -> result; + + /// execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result<_, mysql-error>; +} + +interface postgres { + use rdbms-types.{parameter-value}; + use rdbms-types.{row-set}; + + /// General purpose error. + variant pg-error { + success, + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other-error(string), + } + + /// query the database: select + query: func(address: string, statement: string, params: list) -> result; + + /// execute command to the database: insert, update, delete + execute: func(address: string, statement: string, params: list) -> result; +} + +interface redis-types { + /// General purpose error. + enum error { success, error } + + /// The message payload. + type payload = list; + + /// A parameter type for the general-purpose `execute` function. + variant redis-parameter { + int64(s64), + binary(payload), + } + + /// A return type for the general-purpose `execute` function. + variant redis-result { + nil, + status(string), + int64(s64), + binary(payload), + } +} + +interface redis { + use redis-types.{payload}; + use redis-types.{redis-parameter}; + use redis-types.{redis-result}; + use redis-types.{error}; + + /// Publish a Redis message to the specificed channel and return an error, if any. + publish: func(address: string, channel: string, payload: payload) -> result<_, error>; + + /// Get the value of a key. + get: func(address: string, key: string) -> result; + + /// Set key to value. If key alreads holds a value, it is overwritten. + set: func(address: string, key: string, value: payload) -> result<_, error>; + + /// Increments the number stored at key by one. If the key does not exist, it is set + /// to 0 before performing the operation. + /// An error is returned if the key contains a value of the wrong type or contains + /// a string that can not be represented as integer. + incr: func(address: string, key: string) -> result; + + /// Removes the specified keys. A key is ignored if it does not exist. + del: func(address: string, keys: list) -> result; + + /// Add the specified `values` to the set named `key`, returning the number of newly-added + /// values. + sadd: func(address: string, key: string, values: list) -> result; + + /// Retrieve the contents of the set named `key`. + smembers: func(address: string, key: string) -> result, error>; + + /// Remove the specified `values` from the set named `key`, returning the number of + /// newly-removed values. + srem: func(address: string, key: string, values: list) -> result; + + /// Execute an arbitrary Redis command and receive the result. + execute: func(address: string, command: string, arguments: list) -> result, error>; +} + +interface sqlite { + /// A handle to an open sqlite instance + type connection = u32; + + /// The set of errors which may be raised by functions in this interface + variant error { + /// The host does not recognize the database name requested. + no-such-database, + /// The requesting component does not have access to the specified database (which + /// may or may not exist). + access-denied, + /// The provided connection is not valid + invalid-connection, + /// The database has reached its capacity + database-full, + /// Some implementation-specific error has occurred (e.g. I/O) + io(string), + } + variant value { + integer(s64), + real(f64), + text(string), + blob(list), + null, + } + + /// A set of values for each of the columns in a query-result + record row-result { values: list } + + /// A result of a query + record query-result { + /// The names of the columns retrieved in the query + columns: list, + /// the row results each containing the values for all the columns for a given row + rows: list, + } + + /// Open a connection to a named database instance. + /// + /// If `database` is "default", the default instance is opened. + /// + /// `error::no-such-database` will be raised if the `name` is not recognized. + open: func(database: string) -> result; + + /// Execute a statement returning back data if there is any + execute: func(conn: connection, statement: string, parameters: list) -> result; + + /// Close the specified `connection`. + close: func(conn: connection); +} + +world http-trigger { + import http-types; + import config; + import http; + import rdbms-types; + import postgres; + import mysql; + import sqlite; + import redis-types; + import redis; + import key-value; + import llm; + export inbound-http; +} diff --git a/v2/internal/fermyon/spin/http-types/http-types.wit.go b/v2/internal/fermyon/spin/http-types/http-types.wit.go index 500b6d1..04e98b1 100644 --- a/v2/internal/fermyon/spin/http-types/http-types.wit.go +++ b/v2/internal/fermyon/spin/http-types/http-types.wit.go @@ -80,6 +80,7 @@ func (e Method) String() string { // body: option, // } type Request struct { + _ cm.HostLayout Method Method URI URI Headers Headers @@ -95,6 +96,7 @@ type Request struct { // body: option, // } type Response struct { + _ cm.HostLayout Status HTTPStatus Headers cm.Option[Headers] Body cm.Option[Body] diff --git a/v2/internal/fermyon/spin/http/abi.go b/v2/internal/fermyon/spin/http/abi.go index 863023f..227fb5a 100644 --- a/v2/internal/fermyon/spin/http/abi.go +++ b/v2/internal/fermyon/spin/http/abi.go @@ -10,6 +10,7 @@ import ( // ResponseShape is used for storage in variant or result types. type ResponseShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(httptypes.Response{})]byte } diff --git a/v2/internal/fermyon/spin/http/http.wasm.go b/v2/internal/fermyon/spin/http/http.wasm.go new file mode 100755 index 0000000..b3c8405 --- /dev/null +++ b/v2/internal/fermyon/spin/http/http.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package http + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/http send-request +//go:noescape +func wasmimport_SendRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32, result *cm.Result[ResponseShape, Response, HTTPError]) diff --git a/v2/internal/fermyon/spin/http/http.wit.go b/v2/internal/fermyon/spin/http/http.wit.go index 80b0a83..4c1df29 100644 --- a/v2/internal/fermyon/spin/http/http.wit.go +++ b/v2/internal/fermyon/spin/http/http.wit.go @@ -8,17 +8,28 @@ import ( httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" ) +// Request represents the type alias "fermyon:spin/http#request". +// +// See [httptypes.Request] for more information. +type Request = httptypes.Request + +// Response represents the type alias "fermyon:spin/http#response". +// +// See [httptypes.Response] for more information. +type Response = httptypes.Response + +// HTTPError represents the type alias "fermyon:spin/http#http-error". +// +// See [httptypes.HTTPError] for more information. +type HTTPError = httptypes.HTTPError + // SendRequest represents the imported function "send-request". // // send-request: func(req: request) -> result // //go:nosplit -func SendRequest(req httptypes.Request) (result cm.Result[ResponseShape, httptypes.Response, httptypes.HTTPError]) { +func SendRequest(req Request) (result cm.Result[ResponseShape, Response, HTTPError]) { req0, req1, req2, req3, req4, req5, req6, req7, req8, req9 := lower_Request(req) wasmimport_SendRequest((uint32)(req0), (*uint8)(req1), (uint32)(req2), (*[2]string)(req3), (uint32)(req4), (*[2]string)(req5), (uint32)(req6), (uint32)(req7), (*uint8)(req8), (uint32)(req9), &result) return } - -//go:wasmimport fermyon:spin/http send-request -//go:noescape -func wasmimport_SendRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32, result *cm.Result[ResponseShape, httptypes.Response, httptypes.HTTPError]) diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v2/internal/fermyon/spin/inbound-http/abi.go index c29d6c0..1f802ad 100644 --- a/v2/internal/fermyon/spin/inbound-http/abi.go +++ b/v2/internal/fermyon/spin/inbound-http/abi.go @@ -11,7 +11,7 @@ func lift_OptionBody(f0 uint32, f1 *uint8, f2 uint32) (v cm.Option[httptypes.Bod if f0 == 0 { return } - return cm.Some[httptypes.Body](cm.LiftList[httptypes.Body]((*uint8)(f1), (uint32)(f2))) + return (cm.Option[httptypes.Body])(cm.Some[httptypes.Body](cm.LiftList[httptypes.Body]((*uint8)(f1), (uint32)(f2)))) } func lift_Request(f0 uint32, f1 *uint8, f2 uint32, f3 *[2]string, f4 uint32, f5 *[2]string, f6 uint32, f7 uint32, f8 *uint8, f9 uint32) (v httptypes.Request) { diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go index 57e5644..059257b 100644 --- a/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go @@ -2,14 +2,10 @@ package inboundhttp -import ( - httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" -) - // Exports represents the caller-defined exports from "fermyon:spin/inbound-http". var Exports struct { // HandleRequest represents the caller-defined, exported function "handle-request". // // handle-request: func(req: request) -> response - HandleRequest func(req httptypes.Request) (result httptypes.Response) + HandleRequest func(req Request) (result Response) } diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go index 2bd3a04..c952be2 100644 --- a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go @@ -7,11 +7,12 @@ import ( httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" ) -//go:wasmexport fermyon:spin/inbound-http#handle-request -//export fermyon:spin/inbound-http#handle-request -func wasmexport_HandleRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32) (result *httptypes.Response) { - req := lift_Request((uint32)(req0), (*uint8)(req1), (uint32)(req2), (*[2]string)(req3), (uint32)(req4), (*[2]string)(req5), (uint32)(req6), (uint32)(req7), (*uint8)(req8), (uint32)(req9)) - result_ := Exports.HandleRequest(req) - result = &result_ - return -} +// Request represents the type alias "fermyon:spin/inbound-http#request". +// +// See [httptypes.Request] for more information. +type Request = httptypes.Request + +// Response represents the type alias "fermyon:spin/inbound-http#response". +// +// See [httptypes.Response] for more information. +type Response = httptypes.Response diff --git a/v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go b/v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go new file mode 100755 index 0000000..09ece43 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package inboundhttp + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmexport fermyon:spin/inbound-http#handle-request +//export fermyon:spin/inbound-http#handle-request +func wasmexport_HandleRequest(req0 uint32, req1 *uint8, req2 uint32, req3 *[2]string, req4 uint32, req5 *[2]string, req6 uint32, req7 uint32, req8 *uint8, req9 uint32) (result *Response) { + req := lift_Request((uint32)(req0), (*uint8)(req1), (uint32)(req2), (*[2]string)(req3), (uint32)(req4), (*[2]string)(req5), (uint32)(req6), (uint32)(req7), (*uint8)(req8), (uint32)(req9)) + result_ := Exports.HandleRequest(req) + result = &result_ + return +} diff --git a/v2/internal/fermyon/spin/key-value/abi.go b/v2/internal/fermyon/spin/key-value/abi.go index 0d1a032..b69b7a4 100644 --- a/v2/internal/fermyon/spin/key-value/abi.go +++ b/v2/internal/fermyon/spin/key-value/abi.go @@ -3,10 +3,12 @@ package keyvalue import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } diff --git a/v2/internal/fermyon/spin/key-value/key-value.wit.go b/v2/internal/fermyon/spin/key-value/key-value.wit.go index e7ebda0..ee83618 100644 --- a/v2/internal/fermyon/spin/key-value/key-value.wit.go +++ b/v2/internal/fermyon/spin/key-value/key-value.wit.go @@ -111,6 +111,20 @@ func (self *Error) IO() *string { return cm.Case[string](self, 5) } +var stringsError = [6]string{ + "store-table-full", + "no-such-store", + "access-denied", + "invalid-store", + "no-such-key", + "io", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Open represents the imported function "open". // // Open the store with the specified name. @@ -130,10 +144,6 @@ func Open(name string) (result cm.Result[ErrorShape, Store, Error]) { return } -//go:wasmimport fermyon:spin/key-value open -//go:noescape -func wasmimport_Open(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, Store, Error]) - // Get represents the imported function "get". // // Get the value associated with the specified `key` from the specified @@ -153,10 +163,6 @@ func Get(store Store, key string) (result cm.Result[ErrorShape, cm.List[uint8], return } -//go:wasmimport fermyon:spin/key-value get -//go:noescape -func wasmimport_Get(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[uint8], Error]) - // Set represents the imported function "set". // // Set the `value` associated with the specified `key` in the specified @@ -176,10 +182,6 @@ func Set(store Store, key string, value cm.List[uint8]) (result cm.Result[Error, return } -//go:wasmimport fermyon:spin/key-value set -//go:noescape -func wasmimport_Set(store0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) - // Delete represents the imported function "delete". // // Delete the tuple with the specified `key` from the specified `store`. @@ -198,10 +200,6 @@ func Delete(store Store, key string) (result cm.Result[Error, struct{}, Error]) return } -//go:wasmimport fermyon:spin/key-value delete -//go:noescape -func wasmimport_Delete(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) - // Exists represents the imported function "exists". // // Return whether a tuple exists for the specified `key` in the specified @@ -220,10 +218,6 @@ func Exists(store Store, key string) (result cm.Result[ErrorShape, bool, Error]) return } -//go:wasmimport fermyon:spin/key-value exists -//go:noescape -func wasmimport_Exists(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) - // GetKeys represents the imported function "get-keys". // // Return a list of all the keys in the specified `store`. @@ -240,10 +234,6 @@ func GetKeys(store Store) (result cm.Result[ErrorShape, cm.List[string], Error]) return } -//go:wasmimport fermyon:spin/key-value get-keys -//go:noescape -func wasmimport_GetKeys(store0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) - // Close represents the imported function "close". // // Close the specified `store`. @@ -258,7 +248,3 @@ func Close(store Store) { wasmimport_Close((uint32)(store0)) return } - -//go:wasmimport fermyon:spin/key-value close -//go:noescape -func wasmimport_Close(store0 uint32) diff --git a/v2/internal/fermyon/spin/key-value/keyvalue.wasm.go b/v2/internal/fermyon/spin/key-value/keyvalue.wasm.go new file mode 100755 index 0000000..c7f256d --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/keyvalue.wasm.go @@ -0,0 +1,37 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/key-value open +//go:noescape +func wasmimport_Open(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, Store, Error]) + +//go:wasmimport fermyon:spin/key-value get +//go:noescape +func wasmimport_Get(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[uint8], Error]) + +//go:wasmimport fermyon:spin/key-value set +//go:noescape +func wasmimport_Set(store0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/key-value delete +//go:noescape +func wasmimport_Delete(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/key-value exists +//go:noescape +func wasmimport_Exists(store0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) + +//go:wasmimport fermyon:spin/key-value get-keys +//go:noescape +func wasmimport_GetKeys(store0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +//go:wasmimport fermyon:spin/key-value close +//go:noescape +func wasmimport_Close(store0 uint32) diff --git a/v2/internal/fermyon/spin/llm/abi.go b/v2/internal/fermyon/spin/llm/abi.go index 2f54050..4c76de2 100644 --- a/v2/internal/fermyon/spin/llm/abi.go +++ b/v2/internal/fermyon/spin/llm/abi.go @@ -9,6 +9,7 @@ import ( // InferencingResultShape is used for storage in variant or result types. type InferencingResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(InferencingResult{})]byte } @@ -39,5 +40,6 @@ func lower_OptionInferencingParams(v cm.Option[InferencingParams]) (f0 uint32, f // EmbeddingsResultShape is used for storage in variant or result types. type EmbeddingsResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(EmbeddingsResult{})]byte } diff --git a/v2/internal/fermyon/spin/llm/llm.wasm.go b/v2/internal/fermyon/spin/llm/llm.wasm.go new file mode 100755 index 0000000..734b115 --- /dev/null +++ b/v2/internal/fermyon/spin/llm/llm.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/llm infer +//go:noescape +func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) + +//go:wasmimport fermyon:spin/llm generate-embeddings +//go:noescape +func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/llm/llm.wit.go b/v2/internal/fermyon/spin/llm/llm.wit.go index 46f9e4c..872e6a8 100644 --- a/v2/internal/fermyon/spin/llm/llm.wit.go +++ b/v2/internal/fermyon/spin/llm/llm.wit.go @@ -29,6 +29,7 @@ type InferencingModel string // top-p: f32, // } type InferencingParams struct { + _ cm.HostLayout // The maximum tokens that should be inferred. // // Note: the backing implementation may return less tokens. @@ -92,6 +93,17 @@ func (self *Error) InvalidInput() *string { return cm.Case[string](self, 2) } +var stringsError = [3]string{ + "model-not-supported", + "runtime-error", + "invalid-input", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // InferencingUsage represents the record "fermyon:spin/llm#inferencing-usage". // // Usage information related to the inferencing result @@ -101,6 +113,7 @@ func (self *Error) InvalidInput() *string { // generated-token-count: u32, // } type InferencingUsage struct { + _ cm.HostLayout // Number of tokens in the prompt PromptTokenCount uint32 @@ -117,6 +130,7 @@ type InferencingUsage struct { // usage: inferencing-usage, // } type InferencingResult struct { + _ cm.HostLayout // The text generated by the model // TODO: this should be a stream Text string @@ -140,6 +154,7 @@ type EmbeddingModel string // prompt-token-count: u32, // } type EmbeddingsUsage struct { + _ cm.HostLayout // Number of tokens in the prompt PromptTokenCount uint32 } @@ -153,6 +168,7 @@ type EmbeddingsUsage struct { // usage: embeddings-usage, // } type EmbeddingsResult struct { + _ cm.HostLayout // The embeddings generated by the request Embeddings cm.List[cm.List[float32]] @@ -177,10 +193,6 @@ func Infer(model InferencingModel, prompt string, params cm.Option[InferencingPa return } -//go:wasmimport fermyon:spin/llm infer -//go:noescape -func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) - // GenerateEmbeddings represents the imported function "generate-embeddings". // // Generate embeddings for the supplied list of text @@ -195,7 +207,3 @@ func GenerateEmbeddings(model EmbeddingModel, text cm.List[string]) (result cm.R wasmimport_GenerateEmbeddings((*uint8)(model0), (uint32)(model1), (*string)(text0), (uint32)(text1), &result) return } - -//go:wasmimport fermyon:spin/llm generate-embeddings -//go:noescape -func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/mysql/abi.go b/v2/internal/fermyon/spin/mysql/abi.go index 41d4103..4d19e87 100644 --- a/v2/internal/fermyon/spin/mysql/abi.go +++ b/v2/internal/fermyon/spin/mysql/abi.go @@ -3,16 +3,13 @@ package mysql import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "unsafe" ) // RowSetShape is used for storage in variant or result types. type RowSetShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte } - -// MysqlErrorShape is used for storage in variant or result types. -type MysqlErrorShape struct { - shape [unsafe.Sizeof(MysqlError{})]byte -} diff --git a/v2/internal/fermyon/spin/mysql/mysql.wasm.go b/v2/internal/fermyon/spin/mysql/mysql.wasm.go new file mode 100755 index 0000000..d672df1 --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/mysql.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mysql + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/mysql query +//go:noescape +func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[RowSetShape, RowSet, MysqlError]) + +//go:wasmimport fermyon:spin/mysql execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[MysqlError, struct{}, MysqlError]) diff --git a/v2/internal/fermyon/spin/mysql/mysql.wit.go b/v2/internal/fermyon/spin/mysql/mysql.wit.go index e2dee05..d715223 100644 --- a/v2/internal/fermyon/spin/mysql/mysql.wit.go +++ b/v2/internal/fermyon/spin/mysql/mysql.wit.go @@ -8,6 +8,16 @@ import ( rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" ) +// ParameterValue represents the type alias "fermyon:spin/mysql#parameter-value". +// +// See [rdbmstypes.ParameterValue] for more information. +type ParameterValue = rdbmstypes.ParameterValue + +// RowSet represents the type alias "fermyon:spin/mysql#row-set". +// +// See [rdbmstypes.RowSet] for more information. +type RowSet = rdbmstypes.RowSet + // MysqlError represents the variant "fermyon:spin/mysql#mysql-error". // // General purpose error. @@ -83,6 +93,20 @@ func (self *MysqlError) OtherError() *string { return cm.Case[string](self, 5) } +var stringsMysqlError = [6]string{ + "success", + "connection-failed", + "bad-parameter", + "query-failed", + "value-conversion-failed", + "other-error", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v MysqlError) String() string { + return stringsMysqlError[v.Tag()] +} + // Query represents the imported function "query". // // query the database: select @@ -91,18 +115,14 @@ func (self *MysqlError) OtherError() *string { // -> result // //go:nosplit -func Query(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, MysqlError]) { +func Query(address string, statement string, params cm.List[ParameterValue]) (result cm.Result[RowSetShape, RowSet, MysqlError]) { address0, address1 := cm.LowerString(address) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } -//go:wasmimport fermyon:spin/mysql query -//go:noescape -func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, MysqlError]) - // Execute represents the imported function "execute". // // execute command to the database: insert, update, delete @@ -111,14 +131,10 @@ func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, state // -> result<_, mysql-error> // //go:nosplit -func Execute(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[MysqlError, struct{}, MysqlError]) { +func Execute(address string, statement string, params cm.List[ParameterValue]) (result cm.Result[MysqlError, struct{}, MysqlError]) { address0, address1 := cm.LowerString(address) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } - -//go:wasmimport fermyon:spin/mysql execute -//go:noescape -func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[MysqlError, struct{}, MysqlError]) diff --git a/v2/internal/fermyon/spin/postgres/abi.go b/v2/internal/fermyon/spin/postgres/abi.go index d1e2280..946016c 100644 --- a/v2/internal/fermyon/spin/postgres/abi.go +++ b/v2/internal/fermyon/spin/postgres/abi.go @@ -3,16 +3,19 @@ package postgres import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "unsafe" ) // RowSetShape is used for storage in variant or result types. type RowSetShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte } // PgErrorShape is used for storage in variant or result types. type PgErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(PgError{})]byte } diff --git a/v2/internal/fermyon/spin/postgres/postgres.wasm.go b/v2/internal/fermyon/spin/postgres/postgres.wasm.go new file mode 100755 index 0000000..9bf02e7 --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/postgres.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/postgres query +//go:noescape +func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[RowSetShape, RowSet, PgError]) + +//go:wasmimport fermyon:spin/postgres execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[PgErrorShape, uint64, PgError]) diff --git a/v2/internal/fermyon/spin/postgres/postgres.wit.go b/v2/internal/fermyon/spin/postgres/postgres.wit.go index 506470b..13fcfdd 100644 --- a/v2/internal/fermyon/spin/postgres/postgres.wit.go +++ b/v2/internal/fermyon/spin/postgres/postgres.wit.go @@ -8,6 +8,16 @@ import ( rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" ) +// ParameterValue represents the type alias "fermyon:spin/postgres#parameter-value". +// +// See [rdbmstypes.ParameterValue] for more information. +type ParameterValue = rdbmstypes.ParameterValue + +// RowSet represents the type alias "fermyon:spin/postgres#row-set". +// +// See [rdbmstypes.RowSet] for more information. +type RowSet = rdbmstypes.RowSet + // PgError represents the variant "fermyon:spin/postgres#pg-error". // // General purpose error. @@ -83,6 +93,20 @@ func (self *PgError) OtherError() *string { return cm.Case[string](self, 5) } +var stringsPgError = [6]string{ + "success", + "connection-failed", + "bad-parameter", + "query-failed", + "value-conversion-failed", + "other-error", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v PgError) String() string { + return stringsPgError[v.Tag()] +} + // Query represents the imported function "query". // // query the database: select @@ -91,18 +115,14 @@ func (self *PgError) OtherError() *string { // -> result // //go:nosplit -func Query(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, PgError]) { +func Query(address string, statement string, params cm.List[ParameterValue]) (result cm.Result[RowSetShape, RowSet, PgError]) { address0, address1 := cm.LowerString(address) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_Query((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } -//go:wasmimport fermyon:spin/postgres query -//go:noescape -func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, PgError]) - // Execute represents the imported function "execute". // // execute command to the database: insert, update, delete @@ -111,14 +131,10 @@ func wasmimport_Query(address0 *uint8, address1 uint32, statement0 *uint8, state // -> result // //go:nosplit -func Execute(address string, statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[PgErrorShape, uint64, PgError]) { +func Execute(address string, statement string, params cm.List[ParameterValue]) (result cm.Result[PgErrorShape, uint64, PgError]) { address0, address1 := cm.LowerString(address) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } - -//go:wasmimport fermyon:spin/postgres execute -//go:noescape -func wasmimport_Execute(address0 *uint8, address1 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[PgErrorShape, uint64, PgError]) diff --git a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go index a584658..af314e7 100644 --- a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go +++ b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go @@ -239,6 +239,29 @@ func (self *DbValue) Unsupported() bool { return self.Tag() == 14 } +var stringsDbValue = [15]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "db-null", + "unsupported", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v DbValue) String() string { + return stringsDbValue[v.Tag()] +} + // ParameterValue represents the variant "fermyon:spin/rdbms-types#parameter-value". // // variant parameter-value { @@ -400,6 +423,28 @@ func (self *ParameterValue) DbNull() bool { return self.Tag() == 13 } +var stringsParameterValue = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "db-null", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v ParameterValue) String() string { + return stringsParameterValue[v.Tag()] +} + // Column represents the record "fermyon:spin/rdbms-types#column". // // record column { @@ -407,6 +452,7 @@ func (self *ParameterValue) DbNull() bool { // data-type: db-data-type, // } type Column struct { + _ cm.HostLayout Name string DataType DbDataType } @@ -423,6 +469,7 @@ type Row cm.List[DbValue] // rows: list, // } type RowSet struct { + _ cm.HostLayout Columns cm.List[Column] Rows cm.List[Row] } diff --git a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go index bbad113..901d529 100644 --- a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go +++ b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go @@ -69,6 +69,16 @@ func (self *RedisParameter) Binary() *Payload { return cm.Case[Payload](self, 1) } +var stringsRedisParameter = [2]string{ + "int64", + "binary", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v RedisParameter) String() string { + return stringsRedisParameter[v.Tag()] +} + // RedisResult represents the variant "fermyon:spin/redis-types#redis-result". // // A return type for the general-purpose `execute` function. @@ -121,3 +131,15 @@ func RedisResultBinary(data Payload) RedisResult { func (self *RedisResult) Binary() *Payload { return cm.Case[Payload](self, 3) } + +var stringsRedisResult = [4]string{ + "nil", + "status", + "int64", + "binary", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v RedisResult) String() string { + return stringsRedisResult[v.Tag()] +} diff --git a/v2/internal/fermyon/spin/redis/redis.wasm.go b/v2/internal/fermyon/spin/redis/redis.wasm.go new file mode 100755 index 0000000..6bd04ae --- /dev/null +++ b/v2/internal/fermyon/spin/redis/redis.wasm.go @@ -0,0 +1,46 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package redis + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" + redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/redis publish +//go:noescape +func wasmimport_Publish(address0 *uint8, address1 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/redis get +//go:noescape +func wasmimport_Get(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[redistypes.Payload, Payload, Error]) + +//go:wasmimport fermyon:spin/redis set +//go:noescape +func wasmimport_Set(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/redis incr +//go:noescape +func wasmimport_Incr(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[int64, int64, Error]) + +//go:wasmimport fermyon:spin/redis del +//go:noescape +func wasmimport_Del(address0 *uint8, address1 uint32, keys0 *string, keys1 uint32, result *cm.Result[int64, int64, Error]) + +//go:wasmimport fermyon:spin/redis sadd +//go:noescape +func wasmimport_Sadd(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, Error]) + +//go:wasmimport fermyon:spin/redis smembers +//go:noescape +func wasmimport_Smembers(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[cm.List[string], cm.List[string], Error]) + +//go:wasmimport fermyon:spin/redis srem +//go:noescape +func wasmimport_Srem(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, Error]) + +//go:wasmimport fermyon:spin/redis execute +//go:noescape +func wasmimport_Execute(address0 *uint8, address1 uint32, command0 *uint8, command1 uint32, arguments0 *RedisParameter, arguments1 uint32, result *cm.Result[cm.List[RedisResult], cm.List[RedisResult], Error]) diff --git a/v2/internal/fermyon/spin/redis/redis.wit.go b/v2/internal/fermyon/spin/redis/redis.wit.go index 1090bf5..c4ee04c 100644 --- a/v2/internal/fermyon/spin/redis/redis.wit.go +++ b/v2/internal/fermyon/spin/redis/redis.wit.go @@ -8,6 +8,26 @@ import ( redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" ) +// Payload represents the type alias "fermyon:spin/redis#payload". +// +// See [redistypes.Payload] for more information. +type Payload = redistypes.Payload + +// RedisParameter represents the type alias "fermyon:spin/redis#redis-parameter". +// +// See [redistypes.RedisParameter] for more information. +type RedisParameter = redistypes.RedisParameter + +// RedisResult represents the type alias "fermyon:spin/redis#redis-result". +// +// See [redistypes.RedisResult] for more information. +type RedisResult = redistypes.RedisResult + +// Error represents the type alias "fermyon:spin/redis#error". +// +// See [redistypes.Error] for more information. +type Error = redistypes.Error + // Publish represents the imported function "publish". // // Publish a Redis message to the specificed channel and return an error, if any. @@ -16,7 +36,7 @@ import ( // error> // //go:nosplit -func Publish(address string, channel string, payload redistypes.Payload) (result cm.Result[redistypes.Error, struct{}, redistypes.Error]) { +func Publish(address string, channel string, payload Payload) (result cm.Result[Error, struct{}, Error]) { address0, address1 := cm.LowerString(address) channel0, channel1 := cm.LowerString(channel) payload0, payload1 := cm.LowerList(payload) @@ -24,10 +44,6 @@ func Publish(address string, channel string, payload redistypes.Payload) (result return } -//go:wasmimport fermyon:spin/redis publish -//go:noescape -func wasmimport_Publish(address0 *uint8, address1 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[redistypes.Error, struct{}, redistypes.Error]) - // Get represents the imported function "get". // // Get the value of a key. @@ -35,17 +51,13 @@ func wasmimport_Publish(address0 *uint8, address1 uint32, channel0 *uint8, chann // get: func(address: string, key: string) -> result // //go:nosplit -func Get(address string, key string) (result cm.Result[redistypes.Payload, redistypes.Payload, redistypes.Error]) { +func Get(address string, key string) (result cm.Result[redistypes.Payload, Payload, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) wasmimport_Get((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) return } -//go:wasmimport fermyon:spin/redis get -//go:noescape -func wasmimport_Get(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[redistypes.Payload, redistypes.Payload, redistypes.Error]) - // Set represents the imported function "set". // // Set key to value. If key alreads holds a value, it is overwritten. @@ -53,7 +65,7 @@ func wasmimport_Get(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, // set: func(address: string, key: string, value: payload) -> result<_, error> // //go:nosplit -func Set(address string, key string, value redistypes.Payload) (result cm.Result[redistypes.Error, struct{}, redistypes.Error]) { +func Set(address string, key string, value Payload) (result cm.Result[Error, struct{}, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) value0, value1 := cm.LowerList(value) @@ -61,10 +73,6 @@ func Set(address string, key string, value redistypes.Payload) (result cm.Result return } -//go:wasmimport fermyon:spin/redis set -//go:noescape -func wasmimport_Set(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[redistypes.Error, struct{}, redistypes.Error]) - // Incr represents the imported function "incr". // // Increments the number stored at key by one. If the key does not exist, it is set @@ -75,17 +83,13 @@ func wasmimport_Set(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, // incr: func(address: string, key: string) -> result // //go:nosplit -func Incr(address string, key string) (result cm.Result[int64, int64, redistypes.Error]) { +func Incr(address string, key string) (result cm.Result[int64, int64, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) wasmimport_Incr((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) return } -//go:wasmimport fermyon:spin/redis incr -//go:noescape -func wasmimport_Incr(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[int64, int64, redistypes.Error]) - // Del represents the imported function "del". // // Removes the specified keys. A key is ignored if it does not exist. @@ -93,17 +97,13 @@ func wasmimport_Incr(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, // del: func(address: string, keys: list) -> result // //go:nosplit -func Del(address string, keys cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { +func Del(address string, keys cm.List[string]) (result cm.Result[int64, int64, Error]) { address0, address1 := cm.LowerString(address) keys0, keys1 := cm.LowerList(keys) wasmimport_Del((*uint8)(address0), (uint32)(address1), (*string)(keys0), (uint32)(keys1), &result) return } -//go:wasmimport fermyon:spin/redis del -//go:noescape -func wasmimport_Del(address0 *uint8, address1 uint32, keys0 *string, keys1 uint32, result *cm.Result[int64, int64, redistypes.Error]) - // Sadd represents the imported function "sadd". // // Add the specified `values` to the set named `key`, returning the number of newly-added @@ -112,7 +112,7 @@ func wasmimport_Del(address0 *uint8, address1 uint32, keys0 *string, keys1 uint3 // sadd: func(address: string, key: string, values: list) -> result // //go:nosplit -func Sadd(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { +func Sadd(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) values0, values1 := cm.LowerList(values) @@ -120,10 +120,6 @@ func Sadd(address string, key string, values cm.List[string]) (result cm.Result[ return } -//go:wasmimport fermyon:spin/redis sadd -//go:noescape -func wasmimport_Sadd(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, redistypes.Error]) - // Smembers represents the imported function "smembers". // // Retrieve the contents of the set named `key`. @@ -131,17 +127,13 @@ func wasmimport_Sadd(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, // smembers: func(address: string, key: string) -> result, error> // //go:nosplit -func Smembers(address string, key string) (result cm.Result[cm.List[string], cm.List[string], redistypes.Error]) { +func Smembers(address string, key string) (result cm.Result[cm.List[string], cm.List[string], Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) wasmimport_Smembers((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) return } -//go:wasmimport fermyon:spin/redis smembers -//go:noescape -func wasmimport_Smembers(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[cm.List[string], cm.List[string], redistypes.Error]) - // Srem represents the imported function "srem". // // Remove the specified `values` from the set named `key`, returning the number of @@ -150,7 +142,7 @@ func wasmimport_Smembers(address0 *uint8, address1 uint32, key0 *uint8, key1 uin // srem: func(address: string, key: string, values: list) -> result // //go:nosplit -func Srem(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, redistypes.Error]) { +func Srem(address string, key string, values cm.List[string]) (result cm.Result[int64, int64, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) values0, values1 := cm.LowerList(values) @@ -158,10 +150,6 @@ func Srem(address string, key string, values cm.List[string]) (result cm.Result[ return } -//go:wasmimport fermyon:spin/redis srem -//go:noescape -func wasmimport_Srem(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[int64, int64, redistypes.Error]) - // Execute represents the imported function "execute". // // Execute an arbitrary Redis command and receive the result. @@ -170,14 +158,10 @@ func wasmimport_Srem(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, // -> result, error> // //go:nosplit -func Execute(address string, command string, arguments cm.List[redistypes.RedisParameter]) (result cm.Result[cm.List[redistypes.RedisResult], cm.List[redistypes.RedisResult], redistypes.Error]) { +func Execute(address string, command string, arguments cm.List[RedisParameter]) (result cm.Result[cm.List[RedisResult], cm.List[RedisResult], Error]) { address0, address1 := cm.LowerString(address) command0, command1 := cm.LowerString(command) arguments0, arguments1 := cm.LowerList(arguments) - wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(command0), (uint32)(command1), (*redistypes.RedisParameter)(arguments0), (uint32)(arguments1), &result) + wasmimport_Execute((*uint8)(address0), (uint32)(address1), (*uint8)(command0), (uint32)(command1), (*RedisParameter)(arguments0), (uint32)(arguments1), &result) return } - -//go:wasmimport fermyon:spin/redis execute -//go:noescape -func wasmimport_Execute(address0 *uint8, address1 uint32, command0 *uint8, command1 uint32, arguments0 *redistypes.RedisParameter, arguments1 uint32, result *cm.Result[cm.List[redistypes.RedisResult], cm.List[redistypes.RedisResult], redistypes.Error]) diff --git a/v2/internal/fermyon/spin/sqlite/abi.go b/v2/internal/fermyon/spin/sqlite/abi.go index a16610a..d055ecf 100644 --- a/v2/internal/fermyon/spin/sqlite/abi.go +++ b/v2/internal/fermyon/spin/sqlite/abi.go @@ -3,15 +3,18 @@ package sqlite import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } // QueryResultShape is used for storage in variant or result types. type QueryResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(QueryResult{})]byte } diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go b/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go new file mode 100755 index 0000000..78f4b53 --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin". + +//go:wasmimport fermyon:spin/sqlite open +//go:noescape +func wasmimport_Open(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/sqlite execute +//go:noescape +func wasmimport_Execute(conn0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) + +//go:wasmimport fermyon:spin/sqlite close +//go:noescape +func wasmimport_Close(conn0 uint32) diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go index 93da5d9..bb756c1 100644 --- a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go @@ -92,6 +92,19 @@ func (self *Error) IO() *string { return cm.Case[string](self, 4) } +var stringsError = [5]string{ + "no-such-database", + "access-denied", + "invalid-connection", + "database-full", + "io", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Value represents the variant "fermyon:spin/sqlite#value". // // variant value { @@ -154,6 +167,19 @@ func (self *Value) Null() bool { return self.Tag() == 4 } +var stringsValue = [5]string{ + "integer", + "real", + "text", + "blob", + "null", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Value) String() string { + return stringsValue[v.Tag()] +} + // RowResult represents the record "fermyon:spin/sqlite#row-result". // // A set of values for each of the columns in a query-result @@ -162,6 +188,7 @@ func (self *Value) Null() bool { // values: list, // } type RowResult struct { + _ cm.HostLayout Values cm.List[Value] } @@ -174,6 +201,7 @@ type RowResult struct { // rows: list, // } type QueryResult struct { + _ cm.HostLayout // The names of the columns retrieved in the query Columns cm.List[string] @@ -198,10 +226,6 @@ func Open(database string) (result cm.Result[ErrorShape, Connection, Error]) { return } -//go:wasmimport fermyon:spin/sqlite open -//go:noescape -func wasmimport_Open(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) - // Execute represents the imported function "execute". // // Execute a statement returning back data if there is any @@ -218,10 +242,6 @@ func Execute(conn Connection, statement string, parameters cm.List[Value]) (resu return } -//go:wasmimport fermyon:spin/sqlite execute -//go:noescape -func wasmimport_Execute(conn0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) - // Close represents the imported function "close". // // Close the specified `connection`. @@ -234,7 +254,3 @@ func Close(conn Connection) { wasmimport_Close((uint32)(conn0)) return } - -//go:wasmimport fermyon:spin/sqlite close -//go:noescape -func wasmimport_Close(conn0 uint32) diff --git a/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit new file mode 100755 index 0000000..37bed5e --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit @@ -0,0 +1,3121 @@ +package fermyon:spin; + +package fermyon:spin@2.0.0 { + interface key-value { + /// An open key-value store + resource store { + + /// Delete the tuple with the specified `key` + /// + /// No error is raised if a tuple did not previously exist for `key`. + delete: func(key: string) -> result<_, error>; + + /// Return whether a tuple exists for the specified `key` + exists: func(key: string) -> result; + + /// Get the value associated with the specified `key` + /// + /// Returns `ok(none)` if the key does not exist. + get: func(key: string) -> result>, error>; + + /// Return a list of all the keys + get-keys: func() -> result, error>; + + /// Set the `value` associated with the specified `key` overwriting any existing value. + set: func(key: string, value: list) -> result<_, error>; + + /// Open the store with the specified label. + /// + /// `label` must refer to a store allowed in the spin.toml manifest. + /// + /// `error::no-such-store` will be raised if the `label` is not recognized. + open: static func(label: string) -> result; + } + + /// The set of errors which may be raised by functions in this interface + variant error { + /// Too many stores have been opened simultaneously. Closing one or more + /// stores prior to retrying may address this. + store-table-full, + /// The host does not recognize the store label requested. + no-such-store, + /// The requesting component does not have access to the specified store + /// (which may or may not exist). + access-denied, + /// Some implementation-specific error has occurred (e.g. I/O) + other(string), + } + } + + /// A WASI interface dedicated to performing inferencing for Large Language Models. + interface llm { + /// A Large Language Model. + type inferencing-model = string; + + /// Inference request parameters + record inferencing-params { + /// The maximum tokens that should be inferred. + /// + /// Note: the backing implementation may return less tokens. + max-tokens: u32, + /// The amount the model should avoid repeating tokens. + repeat-penalty: f32, + /// The number of tokens the model should apply the repeat penalty to. + repeat-penalty-last-n-token-count: u32, + /// The randomness with which the next token is selected. + temperature: f32, + /// The number of possible next tokens the model will choose from. + top-k: u32, + /// The probability total of next tokens the model will choose from. + top-p: f32, + } + + /// The set of errors which may be raised by functions in this interface + variant error { + model-not-supported, + runtime-error(string), + invalid-input(string), + } + + /// Usage information related to the inferencing result + record inferencing-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + /// Number of tokens generated by the inferencing operation + generated-token-count: u32, + } + + /// An inferencing result + record inferencing-result { + /// The text generated by the model + /// TODO: this should be a stream + text: string, + /// Usage information about the inferencing request + usage: inferencing-usage, + } + + /// The model used for generating embeddings + type embedding-model = string; + + /// Usage related to an embeddings generation request + record embeddings-usage { + /// Number of tokens in the prompt + prompt-token-count: u32, + } + + /// Result of generating embeddings + record embeddings-result { + /// The embeddings generated by the request + embeddings: list>, + /// Usage related to the embeddings generation request + usage: embeddings-usage, + } + + /// Perform inferencing using the provided model and prompt with the given optional + /// params + infer: func(model: inferencing-model, prompt: string, params: option) -> result; + + /// Generate embeddings for the supplied list of text + generate-embeddings: func(model: embedding-model, text: list) -> result; + } + + interface mqtt { + /// Errors related to interacting with Mqtt + variant error { + /// An invalid address string + invalid-address, + /// There are too many open connections + too-many-connections, + /// Connection failure e.g. address not allowed. + connection-failed(string), + /// Some other error occurred + other(string), + } + + /// QoS for publishing Mqtt messages + enum qos { + at-most-once, + at-least-once, + exactly-once + } + resource connection { + + /// Publish an Mqtt message to the specified `topic`. + publish: func(topic: string, payload: payload, qos: qos) -> result<_, error>; + + /// Open a connection to the Mqtt instance at `address`. + open: static func(address: string, username: string, password: string, keep-alive-interval-in-secs: u64) -> result; + } + + /// The message payload. + type payload = list; + } + + interface rdbms-types { + /// Errors related to interacting with a database. + variant error { + connection-failed(string), + bad-parameter(string), + query-failed(string), + value-conversion-failed(string), + other(string), + } + + /// Data types for a database column + enum db-data-type { + boolean, + int8, + int16, + int32, + int64, + uint8, + uint16, + uint32, + uint64, + floating32, + floating64, + str, + binary, + other + } + + /// Database values + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + db-null, + unsupported, + } + + /// Values used in parameterized queries + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + uint8(u8), + uint16(u16), + uint32(u32), + uint64(u64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + db-null, + } + + /// A database column + record column { + name: string, + data-type: db-data-type, + } + + /// A database row + type row = list; + + /// A set of database rows + record row-set { + columns: list, + rows: list, + } + } + + interface mysql { + use rdbms-types.{parameter-value}; + use rdbms-types.{row-set}; + use rdbms-types.{error}; + + /// A connection to a MySQL database. + resource connection { + + /// execute command to the database: insert, update, delete + execute: func(statement: string, params: list) -> result<_, error>; + + /// query the database: select + query: func(statement: string, params: list) -> result; + + /// Open a connection to the MySQL instance at `address`. + open: static func(address: string) -> result; + } + } + + interface postgres { + use rdbms-types.{parameter-value}; + use rdbms-types.{row-set}; + use rdbms-types.{error}; + + /// A connection to a postgres database. + resource connection { + + /// Execute command to the database. + execute: func(statement: string, params: list) -> result; + + /// Query the database. + query: func(statement: string, params: list) -> result; + + /// Open a connection to the Postgres instance at `address`. + open: static func(address: string) -> result; + } + } + + interface redis { + /// Errors related to interacting with Redis + variant error { + /// An invalid address string + invalid-address, + /// There are too many open connections + too-many-connections, + /// A retrieved value was not of the correct type + type-error, + /// Some other error occurred + other(string), + } + resource connection { + + /// Removes the specified keys. + /// + /// A key is ignored if it does not exist. Returns the number of keys deleted. + del: func(keys: list) -> result; + + /// Execute an arbitrary Redis command and receive the result. + execute: func(command: string, arguments: list) -> result, error>; + + /// Get the value of a key. + get: func(key: string) -> result, error>; + + /// Increments the number stored at key by one. + /// + /// If the key does not exist, it is set to 0 before performing the operation. + /// An `error::type-error` is returned if the key contains a value of the wrong type + /// or contains a string that can not be represented as integer. + incr: func(key: string) -> result; + + /// Publish a Redis message to the specified channel. + publish: func(channel: string, payload: payload) -> result<_, error>; + + /// Add the specified `values` to the set named `key`, returning the number of newly-added + /// values. + sadd: func(key: string, values: list) -> result; + + /// Set key to value. + /// + /// If key already holds a value, it is overwritten. + set: func(key: string, value: payload) -> result<_, error>; + + /// Retrieve the contents of the set named `key`. + smembers: func(key: string) -> result, error>; + + /// Remove the specified `values` from the set named `key`, returning the number of + /// newly-removed values. + srem: func(key: string, values: list) -> result; + + /// Open a connection to the Redis instance at `address`. + open: static func(address: string) -> result; + } + + /// The message payload. + type payload = list; + + /// A parameter type for the general-purpose `execute` function. + variant redis-parameter { + int64(s64), + binary(payload), + } + + /// A return type for the general-purpose `execute` function. + variant redis-result { + nil, + status(string), + int64(s64), + binary(payload), + } + } + + interface sqlite { + /// A handle to an open sqlite instance + resource connection { + + /// Execute a statement returning back data if there is any + execute: func(statement: string, parameters: list) -> result; + + /// Open a connection to a named database instance. + /// + /// If `database` is "default", the default instance is opened. + /// + /// `error::no-such-database` will be raised if the `name` is not recognized. + open: static func(database: string) -> result; + } + + /// The set of errors which may be raised by functions in this interface + variant error { + /// The host does not recognize the database name requested. + no-such-database, + /// The requesting component does not have access to the specified database (which + /// may or may not exist). + access-denied, + /// The provided connection is not valid + invalid-connection, + /// The database has reached its capacity + database-full, + /// Some implementation-specific error has occurred (e.g. I/O) + io(string), + } + + /// A single column's result from a database query + variant value { + integer(s64), + real(f64), + text(string), + blob(list), + null, + } + + /// A set of values for each of the columns in a query-result + record row-result { values: list } + + /// A result of a query + record query-result { + /// The names of the columns retrieved in the query + columns: list, + /// the row results each containing the values for all the columns for a given row + rows: list, + } + } + + interface variables { + /// The set of errors which may be raised by functions in this interface. + variant error { + /// The provided variable name is invalid. + invalid-name(string), + /// The provided variable is undefined. + undefined(string), + /// A variables provider specific error has occurred. + provider(string), + /// Some implementation-specific error has occurred. + other(string), + } + + /// Get an application variable value for the current component. + /// + /// The name must match one defined in in the component manifest. + get: func(name: string) -> result; + } + + /// The full world of a guest targeting an http-trigger + world http-trigger { + import wasi:io/poll@0.2.0; + import wasi:clocks/monotonic-clock@0.2.0; + import wasi:io/error@0.2.0; + import wasi:io/streams@0.2.0; + import wasi:http/types@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + import llm; + import redis; + import mqtt; + import rdbms-types; + import postgres; + import mysql; + import sqlite; + import key-value; + import variables; + import wasi:cli/environment@0.2.0; + import wasi:cli/exit@0.2.0; + import wasi:cli/stdin@0.2.0; + import wasi:cli/stdout@0.2.0; + import wasi:cli/stderr@0.2.0; + import wasi:cli/terminal-input@0.2.0; + import wasi:cli/terminal-output@0.2.0; + import wasi:cli/terminal-stdin@0.2.0; + import wasi:cli/terminal-stdout@0.2.0; + import wasi:cli/terminal-stderr@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 wasi:http/incoming-handler@0.2.0; + } +} + +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 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; + } +} + +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}; + use wasi:io/streams@0.2.0.{output-stream}; + use wasi:io/streams@0.2.0.{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, + } + + /// 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; + + /// 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, + } + + /// 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 { + + /// 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>; + + /// 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; + + /// Create a directory. + /// + /// Note: This is similar to `mkdirat` in POSIX. + create-directory-at: func(path: string) -> 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; + + /// 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; + + /// 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>; + + /// 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(path-flags: path-flags, path: string) -> result; + + /// 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; + + /// 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>; + + /// 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; + + /// 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; + + /// 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; + + /// 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>; + + /// 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>; + + /// 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(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; + + /// 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>; + + /// 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(path-flags: path-flags, path: string) -> result; + + /// 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>; + + /// 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>; + + /// 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>; + + /// 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>; + + /// 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; + + /// 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; + } + + /// 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; + } + + interface preopens { + use types.{descriptor}; + + /// Return the set of preopened directories, and their path. + get-directories: func() -> list>; + } +} + +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. + interface types { + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use wasi:io/streams@0.2.0.{input-stream}; + use wasi:io/streams@0.2.0.{output-stream}; + use wasi:io/error@0.2.0.{error as io-error}; + use wasi:io/poll@0.2.0.{pollable}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string), + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { HTTP, HTTPS, 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 + variant error-code { + DNS-timeout, + DNS-error(DNS-error-payload), + destination-not-found, + destination-unavailable, + destination-IP-prohibited, + destination-IP-unroutable, + connection-refused, + connection-terminated, + connection-timeout, + connection-read-timeout, + connection-write-timeout, + connection-limit-reached, + TLS-protocol-error, + TLS-certificate-error, + TLS-alert-received(TLS-alert-received-payload), + HTTP-request-denied, + HTTP-request-length-required, + HTTP-request-body-size(option), + HTTP-request-method-invalid, + HTTP-request-URI-invalid, + HTTP-request-URI-too-long, + HTTP-request-header-section-size(option), + HTTP-request-header-size(option), + HTTP-request-trailer-section-size(option), + HTTP-request-trailer-size(field-size-payload), + HTTP-response-incomplete, + HTTP-response-header-section-size(option), + HTTP-response-header-size(field-size-payload), + HTTP-response-body-size(option), + HTTP-response-trailer-section-size(option), + HTTP-response-trailer-size(field-size-payload), + HTTP-response-transfer-coding(option), + HTTP-response-content-coding(option), + HTTP-response-timeout, + HTTP-upgrade-failed, + HTTP-protocol-error, + loop-detected, + configuration-error, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// 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), + } + + /// This type enumerates the different kinds of errors that may occur when + /// setting or appending to a `fields` resource. + variant header-error { + /// This error indicates that a `field-key` or `field-value` was + /// syntactically invalid when used with an operation that sets headers in a + /// `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, + } + + /// Field keys are always strings. + type field-key = string; + + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + type field-value = list; + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + resource fields { + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + constructor(); + + /// 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>; + + /// 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. + clone: func() -> fields; + + /// 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>; + + /// 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>; + + /// 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>; + + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The 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. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. In a valid Fields, all keys + /// and values are valid UTF-8 strings. However, values are not always + /// well-formed, so they are represented as a raw list of bytes. + /// + /// 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; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// Represents an incoming HTTP Request. + resource incoming-request { + + /// Returns the authority from the request, if it was present. + authority: func() -> option; + + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + consume: func() -> result; + + /// Get the `headers` associated with the request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + headers: func() -> headers; + + /// 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; + } + + /// 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`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// 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); + + /// 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. + authority: func() -> option; + + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transfered to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + + /// Get the Method for the Request. + method: func() -> method; + + /// 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; + + /// Get the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. + scheme: func() -> option; + + /// Set the HTTP Authority for the Request. A value of `none` may be used + /// with Related Schemes which do not require an Authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + set-authority: func(authority: option) -> result; + + /// 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; + + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + set-path-with-query: func(path-with-query: option) -> result; + + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + set-scheme: func(scheme: option) -> result; + } + + /// Parameters for making an HTTP Request. Each of these parameters is + /// currently an optional timeout applicable to the transport layer of the + /// HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + between-bytes-timeout: func() -> option; + + /// The timeout for the initial connect to the HTTP Server. + connect-timeout: func() -> option; + + /// The timeout for receiving the first byte of the Response body. + first-byte-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. + set-between-bytes-timeout: func(duration: option) -> result; + + /// 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; + + /// 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; + } + + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + resource response-outparam { + + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// 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); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// Represents an incoming HTTP Response. + resource incoming-response { + + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + consume: func() -> result; + + /// Returns the headers from the incoming response. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `incoming-response` is dropped. + headers: func() -> headers; + + /// Returns the status code from the incoming response. + status: func() -> status-code; + } + + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + resource incoming-body { + + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + %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; + } + + /// Represents a future which may eventaully return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + resource future-trailers { + + /// Returns the contents of the trailers, or an error which occured, + /// once the future is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the trailers or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the HTTP Request or Response + /// body, as well as any trailers, were received successfully, or that an + /// error occured receiving them. The optional `trailers` indicates whether + /// or not trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + get: func() -> option, error-code>>>; + + /// 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; + } + + /// 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); + + /// Returns the resource corresponding to the outgoing Body for this Response. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transfered to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + + /// 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 HTTP Status Code for the Response. + status-code: func() -> status-code; + } + + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occured. The implementation should propogate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + resource outgoing-body { + + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + 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 + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// 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>; + } + + /// Represents a future which may eventaully return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + resource future-incoming-response { + + /// Returns the incoming HTTP Response, or an error, once one is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have recieved successfully, or that an error + /// occured. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + get: func() -> option>>; + + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occured. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + } + + /// 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}; + use types.{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}; + use types.{request-options}; + use types.{future-incoming-response}; + use types.{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; + } +} + +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; + } + + /// 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; + } +} + +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; + } + } + + /// 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 { + + /// `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(); + + /// Return the readiness of a pollable. This function never blocks. + /// + /// Returns `true` when the pollable is ready, and `false` otherwise. + ready: func() -> bool; + } + + /// 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; + } + + /// 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 { + + /// 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>; + + /// 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; + + /// 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>; + + /// 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; + + /// 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 { + + /// Request to flush buffered output, and block until flush completes + /// and stream is ready for writing again. + blocking-flush: func() -> result<_, stream-error>; + + /// 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; + + /// 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>; + + /// 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(len: u64) -> result<_, stream-error>; + + /// 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; + + /// 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>; + + /// 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; + + /// 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; + + /// 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>; + + /// 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>; + } + } +} + +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; + } + + /// 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; + } + + /// 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; + } +} + +package wasi:sockets@0.2.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), + } + } + + /// 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; + } + + interface ip-name-lookup { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network}; + use network.{error-code}; + use network.{ip-address}; + 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; + } + + /// 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; + } + + interface tcp { + use wasi:io/streams@0.2.0.{input-stream}; + use wasi:io/streams@0.2.0.{output-stream}; + use wasi:io/poll@0.2.0.{pollable}; + use wasi:clocks/monotonic-clock@0.2.0.{duration}; + use network.{network}; + use network.{error-code}; + use network.{ip-socket-address}; + use network.{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 { + + /// 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>; + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + address-family: func() -> ip-address-family; + finish-bind: func() -> result<_, error-code>; + finish-connect: func() -> result, error-code>; + finish-listen: func() -> 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; + + /// Whether the socket is in the `listening` state. + /// + /// Equivalent to the SO_ACCEPTCONN socket option. + is-listening: func() -> bool; + + /// 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; + + /// 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; + + /// 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; + + /// 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; + + /// 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; + + /// 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; + + /// Get the remote address. + /// + /// # Typical errors + /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + /// + /// # References + /// - + /// - + /// - + /// - + remote-address: func() -> result; + send-buffer-size: func() -> result; + set-hop-limit: func(value: u8) -> result<_, error-code>; + set-keep-alive-count: func(value: u32) -> result<_, error-code>; + set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; + set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; + set-keep-alive-interval: func(value: duration) -> result<_, error-code>; + + /// 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>; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + + /// 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>; + + /// 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>; + + /// 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>; + + /// 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>; + + /// 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; + } + } + + interface tcp-create-socket { + use network.{network}; + use network.{error-code}; + use network.{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; + } + + interface udp { + use wasi:io/poll@0.2.0.{pollable}; + use network.{network}; + use network.{error-code}; + use network.{ip-socket-address}; + use network.{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 { + + /// Whether this is a IPv4 or IPv6 socket. + /// + /// Equivalent to the SO_DOMAIN socket option. + address-family: func() -> ip-address-family; + finish-bind: func() -> 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; + + /// 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; + + /// 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; + send-buffer-size: func() -> result; + set-receive-buffer-size: func(value: u64) -> result<_, error-code>; + set-send-buffer-size: func(value: u64) -> result<_, error-code>; + set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; + + /// 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>; + + /// 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>; + + /// 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; + + /// 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; + } + 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; + } + } + + interface udp-create-socket { + use network.{network}; + use network.{error-code}; + use network.{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/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go index c3f28e4..5c515f3 100644 --- a/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go @@ -9,10 +9,12 @@ import ( // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } // OptionListU8Shape is used for storage in variant or result types. type OptionListU8Shape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Option[cm.List[uint8]]{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go index f38c71a..2dc27dd 100644 --- a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go @@ -25,10 +25,6 @@ func (self Store) ResourceDrop() { return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [resource-drop]store -//go:noescape -func wasmimport_StoreResourceDrop(self0 uint32) - // StoreOpen represents the imported static function "open". // // Open the store with the specified label. @@ -46,10 +42,6 @@ func StoreOpen(label string) (result cm.Result[ErrorShape, Store, Error]) { return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [static]store.open -//go:noescape -func wasmimport_StoreOpen(label0 *uint8, label1 uint32, result *cm.Result[ErrorShape, Store, Error]) - // Delete represents the imported method "delete". // // Delete the tuple with the specified `key` @@ -66,10 +58,6 @@ func (self Store) Delete(key string) (result cm.Result[Error, struct{}, Error]) return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.delete -//go:noescape -func wasmimport_StoreDelete(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) - // Exists represents the imported method "exists". // // Return whether a tuple exists for the specified `key` @@ -84,10 +72,6 @@ func (self Store) Exists(key string) (result cm.Result[ErrorShape, bool, Error]) return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.exists -//go:noescape -func wasmimport_StoreExists(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) - // Get represents the imported method "get". // // Get the value associated with the specified `key` @@ -104,10 +88,6 @@ func (self Store) Get(key string) (result cm.Result[OptionListU8Shape, cm.Option return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get -//go:noescape -func wasmimport_StoreGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) - // GetKeys represents the imported method "get-keys". // // Return a list of all the keys @@ -121,10 +101,6 @@ func (self Store) GetKeys() (result cm.Result[ErrorShape, cm.List[string], Error return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get-keys -//go:noescape -func wasmimport_StoreGetKeys(self0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) - // Set represents the imported method "set". // // Set the `value` associated with the specified `key` overwriting any existing value. @@ -140,10 +116,6 @@ func (self Store) Set(key string, value cm.List[uint8]) (result cm.Result[Error, return } -//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.set -//go:noescape -func wasmimport_StoreSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) - // Error represents the variant "fermyon:spin/key-value@2.0.0#error". // // The set of errors which may be raised by functions in this interface @@ -208,3 +180,15 @@ func ErrorOther(data string) Error { func (self *Error) Other() *string { return cm.Case[string](self, 3) } + +var stringsError = [4]string{ + "store-table-full", + "no-such-store", + "access-denied", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/keyvalue.wasm.go b/v2/internal/fermyon/spin/v2.0.0/key-value/keyvalue.wasm.go new file mode 100755 index 0000000..ee1c646 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/keyvalue.wasm.go @@ -0,0 +1,37 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/key-value@2.0.0 [resource-drop]store +//go:noescape +func wasmimport_StoreResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [static]store.open +//go:noescape +func wasmimport_StoreOpen(label0 *uint8, label1 uint32, result *cm.Result[ErrorShape, Store, Error]) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.delete +//go:noescape +func wasmimport_StoreDelete(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.exists +//go:noescape +func wasmimport_StoreExists(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get +//go:noescape +func wasmimport_StoreGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get-keys +//go:noescape +func wasmimport_StoreGetKeys(self0 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.set +//go:noescape +func wasmimport_StoreSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go index 2f54050..4c76de2 100644 --- a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go @@ -9,6 +9,7 @@ import ( // InferencingResultShape is used for storage in variant or result types. type InferencingResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(InferencingResult{})]byte } @@ -39,5 +40,6 @@ func lower_OptionInferencingParams(v cm.Option[InferencingParams]) (f0 uint32, f // EmbeddingsResultShape is used for storage in variant or result types. type EmbeddingsResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(EmbeddingsResult{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go new file mode 100755 index 0000000..e6d6bb5 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/llm@2.0.0 infer +//go:noescape +func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) + +//go:wasmimport fermyon:spin/llm@2.0.0 generate-embeddings +//go:noescape +func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go index 76eb6a4..2a74825 100644 --- a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go @@ -29,6 +29,7 @@ type InferencingModel string // top-p: f32, // } type InferencingParams struct { + _ cm.HostLayout // The maximum tokens that should be inferred. // // Note: the backing implementation may return less tokens. @@ -92,6 +93,17 @@ func (self *Error) InvalidInput() *string { return cm.Case[string](self, 2) } +var stringsError = [3]string{ + "model-not-supported", + "runtime-error", + "invalid-input", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // InferencingUsage represents the record "fermyon:spin/llm@2.0.0#inferencing-usage". // // Usage information related to the inferencing result @@ -101,6 +113,7 @@ func (self *Error) InvalidInput() *string { // generated-token-count: u32, // } type InferencingUsage struct { + _ cm.HostLayout // Number of tokens in the prompt PromptTokenCount uint32 @@ -117,6 +130,7 @@ type InferencingUsage struct { // usage: inferencing-usage, // } type InferencingResult struct { + _ cm.HostLayout // The text generated by the model // TODO: this should be a stream Text string @@ -140,6 +154,7 @@ type EmbeddingModel string // prompt-token-count: u32, // } type EmbeddingsUsage struct { + _ cm.HostLayout // Number of tokens in the prompt PromptTokenCount uint32 } @@ -153,6 +168,7 @@ type EmbeddingsUsage struct { // usage: embeddings-usage, // } type EmbeddingsResult struct { + _ cm.HostLayout // The embeddings generated by the request Embeddings cm.List[cm.List[float32]] @@ -177,10 +193,6 @@ func Infer(model InferencingModel, prompt string, params cm.Option[InferencingPa return } -//go:wasmimport fermyon:spin/llm@2.0.0 infer -//go:noescape -func wasmimport_Infer(model0 *uint8, model1 uint32, prompt0 *uint8, prompt1 uint32, params0 uint32, params1 uint32, params2 float32, params3 uint32, params4 float32, params5 uint32, params6 float32, result *cm.Result[InferencingResultShape, InferencingResult, Error]) - // GenerateEmbeddings represents the imported function "generate-embeddings". // // Generate embeddings for the supplied list of text @@ -195,7 +207,3 @@ func GenerateEmbeddings(model EmbeddingModel, text cm.List[string]) (result cm.R wasmimport_GenerateEmbeddings((*uint8)(model0), (uint32)(model1), (*string)(text0), (uint32)(text1), &result) return } - -//go:wasmimport fermyon:spin/llm@2.0.0 generate-embeddings -//go:noescape -func wasmimport_GenerateEmbeddings(model0 *uint8, model1 uint32, text0 *string, text1 uint32, result *cm.Result[EmbeddingsResultShape, EmbeddingsResult, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go index 889d12c..4564d4b 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go @@ -3,10 +3,12 @@ package mqtt import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go new file mode 100755 index 0000000..ed54e1a --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mqtt + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, username0 *uint8, username1 uint32, password0 *uint8, password1 uint32, keepAliveIntervalInSecs0 uint64, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [method]connection.publish +//go:noescape +func wasmimport_ConnectionPublish(self0 uint32, topic0 *uint8, topic1 uint32, payload0 *uint8, payload1 uint32, qos0 uint32, result *cm.Result[Error, struct{}, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go index 9d4f8c5..b43c8d9 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go @@ -69,6 +69,18 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } +var stringsError = [4]string{ + "invalid-address", + "too-many-connections", + "connection-failed", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Qos represents the enum "fermyon:spin/mqtt@2.0.0#qos". // // QoS for publishing Mqtt messages @@ -113,10 +125,6 @@ func (self Connection) ResourceDrop() { return } -//go:wasmimport fermyon:spin/mqtt@2.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - // ConnectionOpen represents the imported static function "open". // // Open a connection to the Mqtt instance at `address`. @@ -134,10 +142,6 @@ func ConnectionOpen(address string, username string, password string, keepAliveI return } -//go:wasmimport fermyon:spin/mqtt@2.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, username0 *uint8, username1 uint32, password0 *uint8, password1 uint32, keepAliveIntervalInSecs0 uint64, result *cm.Result[ErrorShape, Connection, Error]) - // Publish represents the imported method "publish". // // Publish an Mqtt message to the specified `topic`. @@ -154,10 +158,6 @@ func (self Connection) Publish(topic string, payload Payload, qos Qos) (result c return } -//go:wasmimport fermyon:spin/mqtt@2.0.0 [method]connection.publish -//go:noescape -func wasmimport_ConnectionPublish(self0 uint32, topic0 *uint8, topic1 uint32, payload0 *uint8, payload1 uint32, qos0 uint32, result *cm.Result[Error, struct{}, Error]) - // Payload represents the list "fermyon:spin/mqtt@2.0.0#payload". // // The message payload. diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go index 7b18fbb..c30ced9 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go @@ -3,16 +3,19 @@ package mysql import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.Error{})]byte } // RowSetShape is used for storage in variant or result types. type RowSetShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go new file mode 100755 index 0000000..7421afd --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mysql + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/mysql@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/mysql@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.query +//go:noescape +func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[RowSetShape, RowSet, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go index 49855dd..6846927 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go @@ -8,6 +8,21 @@ import ( rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" ) +// ParameterValue represents the type alias "fermyon:spin/mysql@2.0.0#parameter-value". +// +// See [rdbmstypes.ParameterValue] for more information. +type ParameterValue = rdbmstypes.ParameterValue + +// RowSet represents the type alias "fermyon:spin/mysql@2.0.0#row-set". +// +// See [rdbmstypes.RowSet] for more information. +type RowSet = rdbmstypes.RowSet + +// Error represents the type alias "fermyon:spin/mysql@2.0.0#error". +// +// See [rdbmstypes.Error] for more information. +type Error = rdbmstypes.Error + // Connection represents the imported resource "fermyon:spin/mysql@2.0.0#connection". // // A connection to a MySQL database. @@ -26,10 +41,6 @@ func (self Connection) ResourceDrop() { return } -//go:wasmimport fermyon:spin/mysql@2.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - // ConnectionOpen represents the imported static function "open". // // Open a connection to the MySQL instance at `address`. @@ -37,16 +48,12 @@ func wasmimport_ConnectionResourceDrop(self0 uint32) // open: static func(address: string) -> result // //go:nosplit -func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, rdbmstypes.Error]) { +func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, Error]) { address0, address1 := cm.LowerString(address) wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) return } -//go:wasmimport fermyon:spin/mysql@2.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, rdbmstypes.Error]) - // Execute represents the imported method "execute". // // execute command to the database: insert, update, delete @@ -54,18 +61,14 @@ func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Resu // execute: func(statement: string, params: list) -> result<_, error> // //go:nosplit -func (self Connection) Execute(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[rdbmstypes.Error, struct{}, rdbmstypes.Error]) { +func (self Connection) Execute(statement string, params cm.List[ParameterValue]) (result cm.Result[Error, struct{}, Error]) { self0 := cm.Reinterpret[uint32](self) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } -//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.execute -//go:noescape -func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[rdbmstypes.Error, struct{}, rdbmstypes.Error]) - // Query represents the imported method "query". // // query the database: select @@ -74,14 +77,10 @@ func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 ui // error> // //go:nosplit -func (self Connection) Query(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) { +func (self Connection) Query(statement string, params cm.List[ParameterValue]) (result cm.Result[RowSetShape, RowSet, Error]) { self0 := cm.Reinterpret[uint32](self) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } - -//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.query -//go:noescape -func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go index e8944bc..2a7ab2a 100644 --- a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go @@ -3,16 +3,19 @@ package postgres import ( + "github.com/bytecodealliance/wasm-tools-go/cm" rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.Error{})]byte } // RowSetShape is used for storage in variant or result types. type RowSetShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go new file mode 100755 index 0000000..e52fffb --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/postgres@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/postgres@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[ErrorShape, uint64, Error]) + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.query +//go:noescape +func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *ParameterValue, params1 uint32, result *cm.Result[RowSetShape, RowSet, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go index 83ddb27..374c36f 100644 --- a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go @@ -8,6 +8,21 @@ import ( rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" ) +// ParameterValue represents the type alias "fermyon:spin/postgres@2.0.0#parameter-value". +// +// See [rdbmstypes.ParameterValue] for more information. +type ParameterValue = rdbmstypes.ParameterValue + +// RowSet represents the type alias "fermyon:spin/postgres@2.0.0#row-set". +// +// See [rdbmstypes.RowSet] for more information. +type RowSet = rdbmstypes.RowSet + +// Error represents the type alias "fermyon:spin/postgres@2.0.0#error". +// +// See [rdbmstypes.Error] for more information. +type Error = rdbmstypes.Error + // Connection represents the imported resource "fermyon:spin/postgres@2.0.0#connection". // // A connection to a postgres database. @@ -26,10 +41,6 @@ func (self Connection) ResourceDrop() { return } -//go:wasmimport fermyon:spin/postgres@2.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - // ConnectionOpen represents the imported static function "open". // // Open a connection to the Postgres instance at `address`. @@ -37,16 +48,12 @@ func wasmimport_ConnectionResourceDrop(self0 uint32) // open: static func(address: string) -> result // //go:nosplit -func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, rdbmstypes.Error]) { +func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, Error]) { address0, address1 := cm.LowerString(address) wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) return } -//go:wasmimport fermyon:spin/postgres@2.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, rdbmstypes.Error]) - // Execute represents the imported method "execute". // // Execute command to the database. @@ -55,18 +62,14 @@ func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Resu // error> // //go:nosplit -func (self Connection) Execute(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[ErrorShape, uint64, rdbmstypes.Error]) { +func (self Connection) Execute(statement string, params cm.List[ParameterValue]) (result cm.Result[ErrorShape, uint64, Error]) { self0 := cm.Reinterpret[uint32](self) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_ConnectionExecute((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } -//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.execute -//go:noescape -func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[ErrorShape, uint64, rdbmstypes.Error]) - // Query represents the imported method "query". // // Query the database. @@ -75,14 +78,10 @@ func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 ui // error> // //go:nosplit -func (self Connection) Query(statement string, params cm.List[rdbmstypes.ParameterValue]) (result cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) { +func (self Connection) Query(statement string, params cm.List[ParameterValue]) (result cm.Result[RowSetShape, RowSet, Error]) { self0 := cm.Reinterpret[uint32](self) statement0, statement1 := cm.LowerString(statement) params0, params1 := cm.LowerList(params) - wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*rdbmstypes.ParameterValue)(params0), (uint32)(params1), &result) + wasmimport_ConnectionQuery((uint32)(self0), (*uint8)(statement0), (uint32)(statement1), (*ParameterValue)(params0), (uint32)(params1), &result) return } - -//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.query -//go:noescape -func wasmimport_ConnectionQuery(self0 uint32, statement0 *uint8, statement1 uint32, params0 *rdbmstypes.ParameterValue, params1 uint32, result *cm.Result[RowSetShape, rdbmstypes.RowSet, rdbmstypes.Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go index 097db56..840a497 100644 --- a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go @@ -70,6 +70,19 @@ func (self *Error) Other() *string { return cm.Case[string](self, 4) } +var stringsError = [5]string{ + "connection-failed", + "bad-parameter", + "query-failed", + "value-conversion-failed", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // DbDataType represents the enum "fermyon:spin/rdbms-types@2.0.0#db-data-type". // // Data types for a database column @@ -306,6 +319,29 @@ func (self *DbValue) Unsupported() bool { return self.Tag() == 14 } +var stringsDbValue = [15]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "db-null", + "unsupported", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v DbValue) String() string { + return stringsDbValue[v.Tag()] +} + // ParameterValue represents the variant "fermyon:spin/rdbms-types@2.0.0#parameter-value". // // Values used in parameterized queries @@ -469,6 +505,28 @@ func (self *ParameterValue) DbNull() bool { return self.Tag() == 13 } +var stringsParameterValue = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "floating32", + "floating64", + "str", + "binary", + "db-null", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v ParameterValue) String() string { + return stringsParameterValue[v.Tag()] +} + // Column represents the record "fermyon:spin/rdbms-types@2.0.0#column". // // A database column @@ -478,6 +536,7 @@ func (self *ParameterValue) DbNull() bool { // data-type: db-data-type, // } type Column struct { + _ cm.HostLayout Name string DataType DbDataType } @@ -498,6 +557,7 @@ type Row cm.List[DbValue] // rows: list, // } type RowSet struct { + _ cm.HostLayout Columns cm.List[Column] Rows cm.List[Row] } diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go index a1c2b51..f2474f9 100644 --- a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go @@ -9,10 +9,12 @@ import ( // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } // OptionPayloadShape is used for storage in variant or result types. type OptionPayloadShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Option[Payload]{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go new file mode 100755 index 0000000..e97dd99 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go @@ -0,0 +1,53 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package redis + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/redis@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/redis@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.del +//go:noescape +func wasmimport_ConnectionDel(self0 uint32, keys0 *string, keys1 uint32, result *cm.Result[ErrorShape, uint32, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, command0 *uint8, command1 uint32, arguments0 *RedisParameter, arguments1 uint32, result *cm.Result[ErrorShape, cm.List[RedisResult], Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.get +//go:noescape +func wasmimport_ConnectionGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionPayloadShape, cm.Option[Payload], Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.incr +//go:noescape +func wasmimport_ConnectionIncr(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, int64, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.publish +//go:noescape +func wasmimport_ConnectionPublish(self0 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.sadd +//go:noescape +func wasmimport_ConnectionSadd(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.set +//go:noescape +func wasmimport_ConnectionSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.smembers +//go:noescape +func wasmimport_ConnectionSmembers(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.srem +//go:noescape +func wasmimport_ConnectionSrem(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go index 9fc8aed..1549d7f 100644 --- a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go @@ -70,6 +70,18 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } +var stringsError = [4]string{ + "invalid-address", + "too-many-connections", + "type-error", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Connection represents the imported resource "fermyon:spin/redis@2.0.0#connection". // // resource connection @@ -86,10 +98,6 @@ func (self Connection) ResourceDrop() { return } -//go:wasmimport fermyon:spin/redis@2.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - // ConnectionOpen represents the imported static function "open". // // Open a connection to the Redis instance at `address`. @@ -103,10 +111,6 @@ func ConnectionOpen(address string) (result cm.Result[ErrorShape, Connection, Er return } -//go:wasmimport fermyon:spin/redis@2.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) - // Del represents the imported method "del". // // Removes the specified keys. @@ -123,10 +127,6 @@ func (self Connection) Del(keys cm.List[string]) (result cm.Result[ErrorShape, u return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.del -//go:noescape -func wasmimport_ConnectionDel(self0 uint32, keys0 *string, keys1 uint32, result *cm.Result[ErrorShape, uint32, Error]) - // Execute represents the imported method "execute". // // Execute an arbitrary Redis command and receive the result. @@ -143,10 +143,6 @@ func (self Connection) Execute(command string, arguments cm.List[RedisParameter] return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.execute -//go:noescape -func wasmimport_ConnectionExecute(self0 uint32, command0 *uint8, command1 uint32, arguments0 *RedisParameter, arguments1 uint32, result *cm.Result[ErrorShape, cm.List[RedisResult], Error]) - // Get represents the imported method "get". // // Get the value of a key. @@ -161,10 +157,6 @@ func (self Connection) Get(key string) (result cm.Result[OptionPayloadShape, cm. return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.get -//go:noescape -func wasmimport_ConnectionGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionPayloadShape, cm.Option[Payload], Error]) - // Incr represents the imported method "incr". // // Increments the number stored at key by one. @@ -183,10 +175,6 @@ func (self Connection) Incr(key string) (result cm.Result[ErrorShape, int64, Err return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.incr -//go:noescape -func wasmimport_ConnectionIncr(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, int64, Error]) - // Publish represents the imported method "publish". // // Publish a Redis message to the specified channel. @@ -202,10 +190,6 @@ func (self Connection) Publish(channel string, payload Payload) (result cm.Resul return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.publish -//go:noescape -func wasmimport_ConnectionPublish(self0 uint32, channel0 *uint8, channel1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[Error, struct{}, Error]) - // Sadd represents the imported method "sadd". // // Add the specified `values` to the set named `key`, returning the number of newly-added @@ -222,10 +206,6 @@ func (self Connection) Sadd(key string, values cm.List[string]) (result cm.Resul return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.sadd -//go:noescape -func wasmimport_ConnectionSadd(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) - // Set represents the imported method "set". // // Set key to value. @@ -243,10 +223,6 @@ func (self Connection) Set(key string, value Payload) (result cm.Result[Error, s return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.set -//go:noescape -func wasmimport_ConnectionSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) - // Smembers represents the imported method "smembers". // // Retrieve the contents of the set named `key`. @@ -261,10 +237,6 @@ func (self Connection) Smembers(key string) (result cm.Result[ErrorShape, cm.Lis return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.smembers -//go:noescape -func wasmimport_ConnectionSmembers(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, cm.List[string], Error]) - // Srem represents the imported method "srem". // // Remove the specified `values` from the set named `key`, returning the number of @@ -281,10 +253,6 @@ func (self Connection) Srem(key string, values cm.List[string]) (result cm.Resul return } -//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.srem -//go:noescape -func wasmimport_ConnectionSrem(self0 uint32, key0 *uint8, key1 uint32, values0 *string, values1 uint32, result *cm.Result[ErrorShape, uint32, Error]) - // Payload represents the list "fermyon:spin/redis@2.0.0#payload". // // The message payload. @@ -322,6 +290,16 @@ func (self *RedisParameter) Binary() *Payload { return cm.Case[Payload](self, 1) } +var stringsRedisParameter = [2]string{ + "int64", + "binary", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v RedisParameter) String() string { + return stringsRedisParameter[v.Tag()] +} + // RedisResult represents the variant "fermyon:spin/redis@2.0.0#redis-result". // // A return type for the general-purpose `execute` function. @@ -374,3 +352,15 @@ func RedisResultBinary(data Payload) RedisResult { func (self *RedisResult) Binary() *Payload { return cm.Case[Payload](self, 3) } + +var stringsRedisResult = [4]string{ + "nil", + "status", + "int64", + "binary", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v RedisResult) String() string { + return stringsRedisResult[v.Tag()] +} diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go index a16610a..d055ecf 100644 --- a/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go @@ -3,15 +3,18 @@ package sqlite import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } // QueryResultShape is used for storage in variant or result types. type QueryResultShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(QueryResult{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go new file mode 100755 index 0000000..3a49d74 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [method]connection.execute +//go:noescape +func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go index f2eeb11..5299eed 100644 --- a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go @@ -25,10 +25,6 @@ func (self Connection) ResourceDrop() { return } -//go:wasmimport fermyon:spin/sqlite@2.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - // ConnectionOpen represents the imported static function "open". // // Open a connection to a named database instance. @@ -46,10 +42,6 @@ func ConnectionOpen(database string) (result cm.Result[ErrorShape, Connection, E return } -//go:wasmimport fermyon:spin/sqlite@2.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(database0 *uint8, database1 uint32, result *cm.Result[ErrorShape, Connection, Error]) - // Execute represents the imported method "execute". // // Execute a statement returning back data if there is any @@ -66,10 +58,6 @@ func (self Connection) Execute(statement string, parameters cm.List[Value]) (res return } -//go:wasmimport fermyon:spin/sqlite@2.0.0 [method]connection.execute -//go:noescape -func wasmimport_ConnectionExecute(self0 uint32, statement0 *uint8, statement1 uint32, parameters0 *Value, parameters1 uint32, result *cm.Result[QueryResultShape, QueryResult, Error]) - // Error represents the variant "fermyon:spin/sqlite@2.0.0#error". // // The set of errors which may be raised by functions in this interface @@ -148,6 +136,19 @@ func (self *Error) IO() *string { return cm.Case[string](self, 4) } +var stringsError = [5]string{ + "no-such-database", + "access-denied", + "invalid-connection", + "database-full", + "io", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Value represents the variant "fermyon:spin/sqlite@2.0.0#value". // // A single column's result from a database query @@ -212,6 +213,19 @@ func (self *Value) Null() bool { return self.Tag() == 4 } +var stringsValue = [5]string{ + "integer", + "real", + "text", + "blob", + "null", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Value) String() string { + return stringsValue[v.Tag()] +} + // RowResult represents the record "fermyon:spin/sqlite@2.0.0#row-result". // // A set of values for each of the columns in a query-result @@ -220,6 +234,7 @@ func (self *Value) Null() bool { // values: list, // } type RowResult struct { + _ cm.HostLayout Values cm.List[Value] } @@ -232,6 +247,7 @@ type RowResult struct { // rows: list, // } type QueryResult struct { + _ cm.HostLayout // The names of the columns retrieved in the query Columns cm.List[string] diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/abi.go b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go index b850a1e..5eb1db6 100644 --- a/v2/internal/fermyon/spin/v2.0.0/variables/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go @@ -3,10 +3,12 @@ package variables import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // ErrorShape is used for storage in variant or result types. type ErrorShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(Error{})]byte } diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go new file mode 100755 index 0000000..38e73fb --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package variables + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "fermyon:spin@2.0.0". + +//go:wasmimport fermyon:spin/variables@2.0.0 get +//go:noescape +func wasmimport_Get(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go index d8524e2..6d55dd7 100644 --- a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go @@ -67,6 +67,18 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } +var stringsError = [4]string{ + "invalid-name", + "undefined", + "provider", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return stringsError[v.Tag()] +} + // Get represents the imported function "get". // // Get an application variable value for the current component. @@ -81,7 +93,3 @@ func Get(name string) (result cm.Result[ErrorShape, string, Error]) { wasmimport_Get((*uint8)(name0), (uint32)(name1), &result) return } - -//go:wasmimport fermyon:spin/variables@2.0.0 get -//go:noescape -func wasmimport_Get(name0 *uint8, name1 uint32, result *cm.Result[ErrorShape, string, Error]) diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go b/v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go new file mode 100755 index 0000000..666ca89 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package environment + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/environment@0.2.0 get-environment +//go:noescape +func wasmimport_GetEnvironment(result *cm.List[[2]string]) + +//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +//go:noescape +func wasmimport_GetArguments(result *cm.List[string]) + +//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd +//go:noescape +func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go index 48e066d..71fc26b 100644 --- a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go @@ -26,10 +26,6 @@ func GetEnvironment() (result cm.List[[2]string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-environment -//go:noescape -func wasmimport_GetEnvironment(result *cm.List[[2]string]) - // GetArguments represents the imported function "get-arguments". // // Get the POSIX-style arguments to the program. @@ -42,10 +38,6 @@ func GetArguments() (result cm.List[string]) { return } -//go:wasmimport wasi:cli/environment@0.2.0 get-arguments -//go:noescape -func wasmimport_GetArguments(result *cm.List[string]) - // InitialCWD represents the imported function "initial-cwd". // // Return a path that programs should use as their initial current working @@ -58,7 +50,3 @@ func InitialCWD() (result cm.Option[string]) { wasmimport_InitialCWD(&result) return } - -//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd -//go:noescape -func wasmimport_InitialCWD(result *cm.Option[string]) diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go b/v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go new file mode 100755 index 0000000..849d5f5 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package exit + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/exit@0.2.0 exit +//go:noescape +func wasmimport_Exit(status0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go index 3fccd93..69f640d 100644 --- a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -19,7 +19,3 @@ func Exit(status cm.BoolResult) { wasmimport_Exit((uint32)(status0)) return } - -//go:wasmimport wasi:cli/exit@0.2.0 exit -//go:noescape -func wasmimport_Exit(status0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go new file mode 100755 index 0000000..462cf17 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package stderr + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr +//go:noescape +func wasmimport_GetStderr() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go index bf3e752..316db98 100644 --- a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -8,17 +8,18 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) +// OutputStream represents the imported type alias "wasi:cli/stderr@0.2.0#output-stream". +// +// See [streams.OutputStream] for more information. +type OutputStream = streams.OutputStream + // GetStderr represents the imported function "get-stderr". // // get-stderr: func() -> output-stream // //go:nosplit -func GetStderr() (result streams.OutputStream) { +func GetStderr() (result OutputStream) { result0 := wasmimport_GetStderr() - result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + result = cm.Reinterpret[OutputStream]((uint32)(result0)) return } - -//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr -//go:noescape -func wasmimport_GetStderr() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go new file mode 100755 index 0000000..374eb25 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package stdin + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin +//go:noescape +func wasmimport_GetStdin() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go index fa94f9a..3de546c 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -8,17 +8,18 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) +// InputStream represents the imported type alias "wasi:cli/stdin@0.2.0#input-stream". +// +// See [streams.InputStream] for more information. +type InputStream = streams.InputStream + // GetStdin represents the imported function "get-stdin". // // get-stdin: func() -> input-stream // //go:nosplit -func GetStdin() (result streams.InputStream) { +func GetStdin() (result InputStream) { result0 := wasmimport_GetStdin() - result = cm.Reinterpret[streams.InputStream]((uint32)(result0)) + result = cm.Reinterpret[InputStream]((uint32)(result0)) return } - -//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin -//go:noescape -func wasmimport_GetStdin() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go new file mode 100755 index 0000000..68e4a3d --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package stdout + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout +//go:noescape +func wasmimport_GetStdout() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go index ae711bb..d9d9b7d 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -8,17 +8,18 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) +// OutputStream represents the imported type alias "wasi:cli/stdout@0.2.0#output-stream". +// +// See [streams.OutputStream] for more information. +type OutputStream = streams.OutputStream + // GetStdout represents the imported function "get-stdout". // // get-stdout: func() -> output-stream // //go:nosplit -func GetStdout() (result streams.OutputStream) { +func GetStdout() (result OutputStream) { result0 := wasmimport_GetStdout() - result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + result = cm.Reinterpret[OutputStream]((uint32)(result0)) return } - -//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout -//go:noescape -func wasmimport_GetStdout() (result0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go index e0114e0..6cf743f 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go @@ -30,7 +30,3 @@ func (self TerminalInput) ResourceDrop() { wasmimport_TerminalInputResourceDrop((uint32)(self0)) return } - -//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input -//go:noescape -func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminalinput.wasm.go b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminalinput.wasm.go new file mode 100755 index 0000000..1df3794 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminalinput.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package terminalinput + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input +//go:noescape +func wasmimport_TerminalInputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go index a63b0e6..0216a1e 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go @@ -30,7 +30,3 @@ func (self TerminalOutput) ResourceDrop() { wasmimport_TerminalOutputResourceDrop((uint32)(self0)) return } - -//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output -//go:noescape -func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminaloutput.wasm.go b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminaloutput.wasm.go new file mode 100755 index 0000000..fb35fc4 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminaloutput.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package terminaloutput + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output +//go:noescape +func wasmimport_TerminalOutputResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go index ed076a4..c52739e 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -11,6 +11,11 @@ import ( terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" ) +// TerminalOutput represents the imported type alias "wasi:cli/terminal-stderr@0.2.0#terminal-output". +// +// See [terminaloutput.TerminalOutput] for more information. +type TerminalOutput = terminaloutput.TerminalOutput + // GetTerminalStderr represents the imported function "get-terminal-stderr". // // If stderr is connected to a terminal, return a `terminal-output` handle @@ -19,11 +24,7 @@ import ( // get-terminal-stderr: func() -> option // //go:nosplit -func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { +func GetTerminalStderr() (result cm.Option[TerminalOutput]) { wasmimport_GetTerminalStderr(&result) return } - -//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr -//go:noescape -func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminalstderr.wasm.go b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminalstderr.wasm.go new file mode 100755 index 0000000..06a88cb --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminalstderr.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package terminalstderr + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr +//go:noescape +func wasmimport_GetTerminalStderr(result *cm.Option[TerminalOutput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go index 925e6dc..a547d3e 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -11,6 +11,11 @@ import ( terminalinput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" ) +// TerminalInput represents the imported type alias "wasi:cli/terminal-stdin@0.2.0#terminal-input". +// +// See [terminalinput.TerminalInput] for more information. +type TerminalInput = terminalinput.TerminalInput + // GetTerminalStdin represents the imported function "get-terminal-stdin". // // If stdin is connected to a terminal, return a `terminal-input` handle @@ -19,11 +24,7 @@ import ( // get-terminal-stdin: func() -> option // //go:nosplit -func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { +func GetTerminalStdin() (result cm.Option[TerminalInput]) { wasmimport_GetTerminalStdin(&result) return } - -//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin -//go:noescape -func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminalstdin.wasm.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminalstdin.wasm.go new file mode 100755 index 0000000..4980c6e --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminalstdin.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package terminalstdin + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin +//go:noescape +func wasmimport_GetTerminalStdin(result *cm.Option[TerminalInput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go index 88d77b0..fd130cb 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -11,6 +11,11 @@ import ( terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" ) +// TerminalOutput represents the imported type alias "wasi:cli/terminal-stdout@0.2.0#terminal-output". +// +// See [terminaloutput.TerminalOutput] for more information. +type TerminalOutput = terminaloutput.TerminalOutput + // GetTerminalStdout represents the imported function "get-terminal-stdout". // // If stdout is connected to a terminal, return a `terminal-output` handle @@ -19,11 +24,7 @@ import ( // get-terminal-stdout: func() -> option // //go:nosplit -func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { +func GetTerminalStdout() (result cm.Option[TerminalOutput]) { wasmimport_GetTerminalStdout(&result) return } - -//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout -//go:noescape -func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminalstdout.wasm.go b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminalstdout.wasm.go new file mode 100755 index 0000000..3c5c5c3 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminalstdout.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package terminalstdout + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:cli@0.2.0". + +//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout +//go:noescape +func wasmimport_GetTerminalStdout(result *cm.Option[TerminalOutput]) diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go index 68ffd9a..5bdc560 100644 --- a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -19,6 +19,11 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" ) +// Pollable represents the imported type alias "wasi:clocks/monotonic-clock@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". // // An instant in time, in nanoseconds. An instant is relative to an @@ -51,10 +56,6 @@ func Now() (result Instant) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now -//go:noescape -func wasmimport_Now() (result0 uint64) - // Resolution represents the imported function "resolution". // // Query the resolution of the clock. Returns the duration of time @@ -69,10 +70,6 @@ func Resolution() (result Duration) { return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution -//go:noescape -func wasmimport_Resolution() (result0 uint64) - // SubscribeInstant represents the imported function "subscribe-instant". // // Create a `pollable` which will resolve once the specified instant @@ -81,17 +78,13 @@ func wasmimport_Resolution() (result0 uint64) // subscribe-instant: func(when: instant) -> pollable // //go:nosplit -func SubscribeInstant(when Instant) (result poll.Pollable) { +func SubscribeInstant(when Instant) (result Pollable) { when0 := (uint64)(when) result0 := wasmimport_SubscribeInstant((uint64)(when0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant -//go:noescape -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 @@ -101,13 +94,9 @@ func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) // subscribe-duration: func(when: duration) -> pollable // //go:nosplit -func SubscribeDuration(when Duration) (result poll.Pollable) { +func SubscribeDuration(when Duration) (result Pollable) { when0 := (uint64)(when) result0 := wasmimport_SubscribeDuration((uint64)(when0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } - -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration -//go:noescape -func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonicclock.wasm.go b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonicclock.wasm.go new file mode 100755 index 0000000..36a1720 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonicclock.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package monotonicclock + +// This file contains wasmimport and wasmexport declarations for "wasi:clocks@0.2.0". + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now +//go:noescape +func wasmimport_Now() (result0 uint64) + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution +//go:noescape +func wasmimport_Resolution() (result0 uint64) + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +//go:noescape +func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +//go:noescape +func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go index a59a313..86978fb 100644 --- a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go +++ b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go @@ -18,6 +18,10 @@ // 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. @@ -27,6 +31,7 @@ package wallclock // nanoseconds: u32, // } type DateTime struct { + _ cm.HostLayout Seconds uint64 Nanoseconds uint32 } @@ -55,10 +60,6 @@ func Now() (result DateTime) { return } -//go:wasmimport wasi:clocks/wall-clock@0.2.0 now -//go:noescape -func wasmimport_Now(result *DateTime) - // Resolution represents the imported function "resolution". // // Query the resolution of the clock. @@ -72,7 +73,3 @@ func Resolution() (result DateTime) { wasmimport_Resolution(&result) return } - -//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution -//go:noescape -func wasmimport_Resolution(result *DateTime) diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wallclock.wasm.go b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wallclock.wasm.go new file mode 100755 index 0000000..321ff3f --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wallclock.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package wallclock + +// This file contains wasmimport and wasmexport declarations for "wasi:clocks@0.2.0". + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 now +//go:noescape +func wasmimport_Now(result *DateTime) + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution +//go:noescape +func wasmimport_Resolution(result *DateTime) diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go new file mode 100755 index 0000000..efeb200 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package preopens + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:filesystem@0.2.0". + +//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories +//go:noescape +func wasmimport_GetDirectories(result *cm.List[cm.Tuple[Descriptor, string]]) diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go index 2f950ea..5133286 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -8,6 +8,11 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" ) +// Descriptor represents the imported type alias "wasi:filesystem/preopens@0.2.0#descriptor". +// +// See [types.Descriptor] for more information. +type Descriptor = types.Descriptor + // GetDirectories represents the imported function "get-directories". // // Return the set of preopened directories, and their path. @@ -15,11 +20,7 @@ import ( // get-directories: func() -> list> // //go:nosplit -func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { +func GetDirectories() (result cm.List[cm.Tuple[Descriptor, string]]) { wasmimport_GetDirectories(&result) return } - -//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories -//go:noescape -func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go index a22b723..211c988 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go +++ b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -8,18 +8,15 @@ import ( "unsafe" ) -// DateTimeShape is used for storage in variant or result types. -type DateTimeShape struct { - shape [unsafe.Sizeof(wallclock.DateTime{})]byte -} - // MetadataHashValueShape is used for storage in variant or result types. type MetadataHashValueShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(MetadataHashValue{})]byte } // TupleListU8BoolShape is used for storage in variant or result types. type TupleListU8BoolShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Tuple[cm.List[uint8], bool]{})]byte } @@ -42,10 +39,12 @@ func lower_NewTimestamp(v NewTimestamp) (f0 uint32, f1 uint64, f2 uint32) { // DescriptorStatShape is used for storage in variant or result types. type DescriptorStatShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(DescriptorStat{})]byte } // OptionDirectoryEntryShape is used for storage in variant or result types. type OptionDirectoryEntryShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Option[DirectoryEntry]{})]byte } diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go b/v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go new file mode 100755 index 0000000..2528152 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go @@ -0,0 +1,133 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:filesystem@0.2.0". + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor +//go:noescape +func wasmimport_DescriptorResourceDrop(self0 uint32) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise +//go:noescape +func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream +//go:noescape +func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[OutputStream, OutputStream, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at +//go:noescape +func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags +//go:noescape +func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type +//go:noescape +func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object +//go:noescape +func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +//go:noescape +func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +//go:noescape +func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at +//go:noescape +func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at +//go:noescape +func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +//go:noescape +func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +//go:noescape +func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +//go:noescape +func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[InputStream, InputStream, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +//go:noescape +func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +//go:noescape +func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +//go:noescape +func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +//go:noescape +func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +//go:noescape +func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +//go:noescape +func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +//go:noescape +func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:noescape +func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:noescape +func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:noescape +func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:noescape +func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:noescape +func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:noescape +func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:noescape +func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[OutputStream, OutputStream, ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:noescape +func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:noescape +func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) + +//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code +//go:noescape +func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go index 0408a1c..83ea870 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go +++ b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -31,10 +31,29 @@ package types import ( "github.com/bytecodealliance/wasm-tools-go/cm" wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" - ioerror "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) +// InputStream represents the imported type alias "wasi:filesystem/types@0.2.0#input-stream". +// +// See [streams.InputStream] for more information. +type InputStream = streams.InputStream + +// OutputStream represents the imported type alias "wasi:filesystem/types@0.2.0#output-stream". +// +// See [streams.OutputStream] for more information. +type OutputStream = streams.OutputStream + +// Error represents the imported type alias "wasi:filesystem/types@0.2.0#error". +// +// See [streams.Error] for more information. +type Error = streams.Error + +// DateTime represents the type alias "wasi:filesystem/types@0.2.0#datetime". +// +// See [wallclock.DateTime] for more information. +type DateTime = wallclock.DateTime + // FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". // // File size or length of a region within a file. @@ -227,6 +246,7 @@ type LinkCount uint64 // status-change-timestamp: option, // } type DescriptorStat struct { + _ cm.HostLayout // File type. Type DescriptorType @@ -241,19 +261,19 @@ type DescriptorStat struct { // // If the `option` is none, the platform doesn't maintain an access // timestamp for this file. - DataAccessTimestamp cm.Option[wallclock.DateTime] + DataAccessTimestamp cm.Option[DateTime] // Last data modification timestamp. // // If the `option` is none, the platform doesn't maintain a // modification timestamp for this file. - DataModificationTimestamp cm.Option[wallclock.DateTime] + DataModificationTimestamp cm.Option[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[DateTime] } // NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". @@ -265,7 +285,7 @@ type DescriptorStat struct { // now, // timestamp(datetime), // } -type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] +type NewTimestamp cm.Variant[uint8, DateTime, DateTime] // NewTimestampNoChange returns a [NewTimestamp] of case "no-change". // @@ -297,13 +317,24 @@ 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 { +func NewTimestampTimestamp(data DateTime) NewTimestamp { return cm.New[NewTimestamp](2, data) } -// Timestamp returns a non-nil *[wallclock.DateTime] if [NewTimestamp] represents the variant case "timestamp". -func (self *NewTimestamp) Timestamp() *wallclock.DateTime { - return cm.Case[wallclock.DateTime](self, 2) +// Timestamp returns a non-nil *[DateTime] if [NewTimestamp] represents the variant case "timestamp". +func (self *NewTimestamp) Timestamp() *DateTime { + return cm.Case[DateTime](self, 2) +} + +var stringsNewTimestamp = [3]string{ + "no-change", + "now", + "timestamp", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v NewTimestamp) String() string { + return stringsNewTimestamp[v.Tag()] } // DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". @@ -315,6 +346,7 @@ func (self *NewTimestamp) Timestamp() *wallclock.DateTime { // name: string, // } type DirectoryEntry struct { + _ cm.HostLayout // The type of the file referred to by this directory entry. Type DescriptorType @@ -593,6 +625,7 @@ func (e Advice) String() string { // upper: u64, // } type MetadataHashValue struct { + _ cm.HostLayout // 64 bits of a 128-bit hash value. Lower uint64 @@ -620,10 +653,6 @@ func (self Descriptor) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor -//go:noescape -func wasmimport_DescriptorResourceDrop(self0 uint32) - // Advise represents the imported method "advise". // // Provide file advisory information on a descriptor. @@ -642,10 +671,6 @@ func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) ( return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise -//go:noescape -func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // AppendViaStream represents the imported method "append-via-stream". // // Return a stream for appending to a file, if available. @@ -658,16 +683,12 @@ func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, a // append-via-stream: func() -> result // //go:nosplit -func (self Descriptor) AppendViaStream() (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { +func (self Descriptor) AppendViaStream() (result cm.Result[OutputStream, OutputStream, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream -//go:noescape -func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) - // CreateDirectoryAt represents the imported method "create-directory-at". // // Create a directory. @@ -684,10 +705,6 @@ func (self Descriptor) CreateDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at -//go:noescape -func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // GetFlags represents the imported method "get-flags". // // Get flags associated with a descriptor. @@ -706,10 +723,6 @@ func (self Descriptor) GetFlags() (result cm.Result[DescriptorFlags, DescriptorF return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags -//go:noescape -func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.Result[DescriptorFlags, DescriptorFlags, ErrorCode]) - // GetType represents the imported method "get-type". // // Get the dynamic type of a descriptor. @@ -732,10 +745,6 @@ func (self Descriptor) GetType() (result cm.Result[DescriptorType, DescriptorTyp return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type -//go:noescape -func wasmimport_DescriptorGetType(self0 uint32, result *cm.Result[DescriptorType, DescriptorType, ErrorCode]) - // IsSameObject represents the imported method "is-same-object". // // Test whether two descriptors refer to the same filesystem object. @@ -756,10 +765,6 @@ func (self Descriptor) IsSameObject(other Descriptor) (result bool) { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object -//go:noescape -func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) - // LinkAt represents the imported method "link-at". // // Create a hard link. @@ -780,10 +785,6 @@ func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescrip return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at -//go:noescape -func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // MetadataHash represents the imported method "metadata-hash". // // Return a hash of the metadata associated with a filesystem object referred @@ -815,10 +816,6 @@ func (self Descriptor) MetadataHash() (result cm.Result[MetadataHashValueShape, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash -//go:noescape -func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) - // MetadataHashAt represents the imported method "metadata-hash-at". // // Return a hash of the metadata associated with a filesystem object referred @@ -838,10 +835,6 @@ func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at -//go:noescape -func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[MetadataHashValueShape, MetadataHashValue, ErrorCode]) - // OpenAt represents the imported method "open-at". // // Open a file or directory. @@ -877,10 +870,6 @@ func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFl return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at -//go:noescape -func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.Result[Descriptor, Descriptor, ErrorCode]) - // Read represents the imported method "read". // // Read from a descriptor, without using and updating the descriptor's offset. @@ -907,10 +896,6 @@ func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.Result[ return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read -//go:noescape -func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.Result[TupleListU8BoolShape, cm.Tuple[cm.List[uint8], bool], ErrorCode]) - // ReadDirectory represents the imported method "read-directory". // // Read directory entries from a directory. @@ -932,10 +917,6 @@ func (self Descriptor) ReadDirectory() (result cm.Result[DirectoryEntryStream, D return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory -//go:noescape -func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[DirectoryEntryStream, DirectoryEntryStream, ErrorCode]) - // ReadViaStream represents the imported method "read-via-stream". // // Return a stream for reading from a file, if available. @@ -950,17 +931,13 @@ func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.Result[Director // read-via-stream: func(offset: filesize) -> result // //go:nosplit -func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) { +func (self Descriptor) ReadViaStream(offset FileSize) (result cm.Result[InputStream, InputStream, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) offset0 := (uint64)(offset) wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream -//go:noescape -func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.InputStream, streams.InputStream, ErrorCode]) - // ReadLinkAt represents the imported method "readlink-at". // // Read the contents of a symbolic link. @@ -980,10 +957,6 @@ func (self Descriptor) ReadLinkAt(path string) (result cm.Result[string, string, return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at -//go:noescape -func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[string, string, ErrorCode]) - // RemoveDirectoryAt represents the imported method "remove-directory-at". // // Remove a directory. @@ -1002,10 +975,6 @@ func (self Descriptor) RemoveDirectoryAt(path string) (result cm.Result[ErrorCod return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at -//go:noescape -func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // RenameAt represents the imported method "rename-at". // // Rename a filesystem object. @@ -1025,10 +994,6 @@ func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPat return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at -//go:noescape -func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // SetSize represents the imported method "set-size". // // Adjust the size of an open file. If this increases the file's size, the @@ -1046,10 +1011,6 @@ func (self Descriptor) SetSize(size FileSize) (result cm.Result[ErrorCode, struc return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size -//go:noescape -func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // SetTimes represents the imported method "set-times". // // Adjust the timestamps of an open file or directory. @@ -1070,10 +1031,6 @@ func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificati return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times -//go:noescape -func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // SetTimesAt represents the imported method "set-times-at". // // Adjust the timestamps of a file or directory. @@ -1097,10 +1054,6 @@ func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at -//go:noescape -func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // Stat represents the imported method "stat". // // Return the attributes of an open file or directory. @@ -1122,10 +1075,6 @@ func (self Descriptor) Stat() (result cm.Result[DescriptorStatShape, DescriptorS return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat -//go:noescape -func wasmimport_DescriptorStat(self0 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) - // StatAt represents the imported method "stat-at". // // Return the attributes of a file or directory. @@ -1148,10 +1097,6 @@ func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.Resul return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at -//go:noescape -func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.Result[DescriptorStatShape, DescriptorStat, ErrorCode]) - // SymlinkAt represents the imported method "symlink-at". // // Create a symbolic link (also known as a "symlink"). @@ -1172,10 +1117,6 @@ func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.Resu return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at -//go:noescape -func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // Sync represents the imported method "sync". // // Synchronize the data and metadata of a file to disk. @@ -1194,10 +1135,6 @@ func (self Descriptor) Sync() (result cm.Result[ErrorCode, struct{}, ErrorCode]) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync -//go:noescape -func wasmimport_DescriptorSync(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // SyncData represents the imported method "sync-data". // // Synchronize the data of a file to disk. @@ -1216,10 +1153,6 @@ func (self Descriptor) SyncData() (result cm.Result[ErrorCode, struct{}, ErrorCo return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data -//go:noescape -func wasmimport_DescriptorSyncData(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // UnlinkFileAt represents the imported method "unlink-file-at". // // Unlink a filesystem object that is not a directory. @@ -1237,10 +1170,6 @@ func (self Descriptor) UnlinkFileAt(path string) (result cm.Result[ErrorCode, st return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at -//go:noescape -func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // Write represents the imported method "write". // // Write to a descriptor, without using and updating the descriptor's offset. @@ -1264,10 +1193,6 @@ func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm. return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write -//go:noescape -func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.Result[uint64, FileSize, ErrorCode]) - // WriteViaStream represents the imported method "write-via-stream". // // Return a stream for writing to a file, if available. @@ -1280,17 +1205,13 @@ func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, of // write-via-stream: func(offset: filesize) -> result // //go:nosplit -func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) { +func (self Descriptor) WriteViaStream(offset FileSize) (result cm.Result[OutputStream, OutputStream, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) offset0 := (uint64)(offset) wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream -//go:noescape -func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.Result[streams.OutputStream, streams.OutputStream, ErrorCode]) - // DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". // // A stream of directory entries. @@ -1309,10 +1230,6 @@ func (self DirectoryEntryStream) ResourceDrop() { return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream -//go:noescape -func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) - // ReadDirectoryEntry represents the imported method "read-directory-entry". // // Read a single directory entry from a `directory-entry-stream`. @@ -1326,10 +1243,6 @@ func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.Result[OptionDi return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry -//go:noescape -func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.Result[OptionDirectoryEntryShape, cm.Option[DirectoryEntry], ErrorCode]) - // FilesystemErrorCode represents the imported function "filesystem-error-code". // // Attempts to extract a filesystem-related `error-code` from the stream @@ -1346,12 +1259,8 @@ func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm. // filesystem-error-code: func(err: borrow) -> option // //go:nosplit -func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { +func FilesystemErrorCode(err Error) (result cm.Option[ErrorCode]) { err0 := cm.Reinterpret[uint32](err) wasmimport_FilesystemErrorCode((uint32)(err0), &result) return } - -//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code -//go:noescape -func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go index c3ea0ca..673ccb4 100644 --- a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go @@ -2,10 +2,6 @@ package incominghandler -import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" -) - // Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.0". var Exports struct { // Handle represents the caller-defined, exported function "handle". @@ -22,5 +18,5 @@ var Exports struct { // with an error on its behalf. // // handle: func(request: incoming-request, response-out: response-outparam) - Handle func(request types.IncomingRequest, responseOut types.ResponseOutparam) + Handle func(request IncomingRequest, responseOut ResponseOutparam) } diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go index 22efec3..d4d1e04 100644 --- a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go @@ -7,15 +7,15 @@ package incominghandler import ( - "github.com/bytecodealliance/wasm-tools-go/cm" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" ) -//go:wasmexport wasi:http/incoming-handler@0.2.0#handle -//export wasi:http/incoming-handler@0.2.0#handle -func wasmexport_Handle(request0 uint32, responseOut0 uint32) { - request := cm.Reinterpret[types.IncomingRequest]((uint32)(request0)) - responseOut := cm.Reinterpret[types.ResponseOutparam]((uint32)(responseOut0)) - Exports.Handle(request, responseOut) - return -} +// IncomingRequest represents the exported type alias "wasi:http/incoming-handler@0.2.0#incoming-request". +// +// See [types.IncomingRequest] for more information. +type IncomingRequest = types.IncomingRequest + +// ResponseOutparam represents the exported type alias "wasi:http/incoming-handler@0.2.0#response-outparam". +// +// See [types.ResponseOutparam] for more information. +type ResponseOutparam = types.ResponseOutparam diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incominghandler.wasm.go b/v2/internal/wasi/http/v0.2.0/incoming-handler/incominghandler.wasm.go new file mode 100755 index 0000000..6531b7f --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incominghandler.wasm.go @@ -0,0 +1,18 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package incominghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:http@0.2.0". + +//go:wasmexport wasi:http/incoming-handler@0.2.0#handle +//export wasi:http/incoming-handler@0.2.0#handle +func wasmexport_Handle(request0 uint32, responseOut0 uint32) { + request := cm.Reinterpret[IncomingRequest]((uint32)(request0)) + responseOut := cm.Reinterpret[ResponseOutparam]((uint32)(responseOut0)) + Exports.Handle(request, responseOut) + return +} diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go index 8f28928..e3b469c 100644 --- a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go @@ -10,10 +10,11 @@ import ( // ErrorCodeShape is used for storage in variant or result types. type ErrorCodeShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(types.ErrorCode{})]byte } -func lower_OptionRequestOptions(v cm.Option[types.RequestOptions]) (f0 uint32, f1 uint32) { +func lower_OptionRequestOptions(v cm.Option[RequestOptions]) (f0 uint32, f1 uint32) { some := v.Some() if some != nil { f0 = 1 diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go index 9576fe0..f24af10 100644 --- a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go @@ -11,6 +11,26 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" ) +// OutgoingRequest represents the imported type alias "wasi:http/outgoing-handler@0.2.0#outgoing-request". +// +// See [types.OutgoingRequest] for more information. +type OutgoingRequest = types.OutgoingRequest + +// RequestOptions represents the imported type alias "wasi:http/outgoing-handler@0.2.0#request-options". +// +// See [types.RequestOptions] for more information. +type RequestOptions = types.RequestOptions + +// FutureIncomingResponse represents the imported type alias "wasi:http/outgoing-handler@0.2.0#future-incoming-response". +// +// See [types.FutureIncomingResponse] for more information. +type FutureIncomingResponse = types.FutureIncomingResponse + +// ErrorCode represents the type alias "wasi:http/outgoing-handler@0.2.0#error-code". +// +// See [types.ErrorCode] for more information. +type ErrorCode = types.ErrorCode + // Handle represents the imported function "handle". // // This function is invoked with an outgoing HTTP Request, and it returns @@ -28,13 +48,9 @@ import ( // error-code> // //go:nosplit -func Handle(request types.OutgoingRequest, options cm.Option[types.RequestOptions]) (result cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) { +func Handle(request OutgoingRequest, options cm.Option[RequestOptions]) (result cm.Result[ErrorCodeShape, FutureIncomingResponse, ErrorCode]) { request0 := cm.Reinterpret[uint32](request) options0, options1 := lower_OptionRequestOptions(options) wasmimport_Handle((uint32)(request0), (uint32)(options0), (uint32)(options1), &result) return } - -//go:wasmimport wasi:http/outgoing-handler@0.2.0 handle -//go:noescape -func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoinghandler.wasm.go b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoinghandler.wasm.go new file mode 100755 index 0000000..be91cf9 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoinghandler.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package outgoinghandler + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:http@0.2.0". + +//go:wasmimport wasi:http/outgoing-handler@0.2.0 handle +//go:noescape +func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, FutureIncomingResponse, ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/types/abi.go b/v2/internal/wasi/http/v0.2.0/types/abi.go index 2a9193e..b9f7787 100644 --- a/v2/internal/wasi/http/v0.2.0/types/abi.go +++ b/v2/internal/wasi/http/v0.2.0/types/abi.go @@ -4,12 +4,12 @@ package types import ( "github.com/bytecodealliance/wasm-tools-go/cm" - monotonicclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" "unsafe" ) // OptionFieldSizePayloadShape is used for storage in variant or result types. type OptionFieldSizePayloadShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Option[FieldSizePayload]{})]byte } @@ -58,7 +58,7 @@ func lower_OptionScheme(v cm.Option[Scheme]) (f0 uint32, f1 uint32, f2 *uint8, f return } -func lower_OptionDuration(v cm.Option[monotonicclock.Duration]) (f0 uint32, f1 uint64) { +func lower_OptionDuration(v cm.Option[Duration]) (f0 uint32, f1 uint64) { some := v.Some() if some != nil { f0 = 1 @@ -70,6 +70,7 @@ func lower_OptionDuration(v cm.Option[monotonicclock.Duration]) (f0 uint32, f1 u // ErrorCodeShape is used for storage in variant or result types. type ErrorCodeShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(ErrorCode{})]byte } @@ -252,12 +253,7 @@ func lower_ResultOutgoingResponseErrorCode(v cm.Result[ErrorCodeShape, OutgoingR return } -// ResultOptionTrailersErrorCodeShape is used for storage in variant or result types. -type ResultOptionTrailersErrorCodeShape struct { - shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode]{})]byte -} - -func lower_OptionTrailers(v cm.Option[Fields]) (f0 uint32, f1 uint32) { +func lower_OptionTrailers(v cm.Option[Trailers]) (f0 uint32, f1 uint32) { some := v.Some() if some != nil { f0 = 1 @@ -266,8 +262,3 @@ func lower_OptionTrailers(v cm.Option[Fields]) (f0 uint32, f1 uint32) { } return } - -// ResultIncomingResponseErrorCodeShape is used for storage in variant or result types. -type ResultIncomingResponseErrorCodeShape struct { - shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode]{})]byte -} diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wasm.go b/v2/internal/wasi/http/v0.2.0/types/types.wasm.go new file mode 100755 index 0000000..6a37cc9 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/types.wasm.go @@ -0,0 +1,257 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:http@0.2.0". + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields +//go:noescape +func wasmimport_FieldsResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [constructor]fields +//go:noescape +func wasmimport_NewFields() (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list +//go:noescape +func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.append +//go:noescape +func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone +//go:noescape +func wasmimport_FieldsClone(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete +//go:noescape +func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries +//go:noescape +func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.get +//go:noescape +func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.has +//go:noescape +func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.set +//go:noescape +func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request +//go:noescape +func wasmimport_IncomingRequestResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority +//go:noescape +func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume +//go:noescape +func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers +//go:noescape +func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method +//go:noescape +func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query +//go:noescape +func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme +//go:noescape +func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request +//go:noescape +func wasmimport_OutgoingRequestResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request +//go:noescape +func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority +//go:noescape +func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body +//go:noescape +func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers +//go:noescape +func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method +//go:noescape +func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query +//go:noescape +func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme +//go:noescape +func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority +//go:noescape +func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method +//go:noescape +func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query +//go:noescape +func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme +//go:noescape +func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options +//go:noescape +func wasmimport_RequestOptionsResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options +//go:noescape +func wasmimport_NewRequestOptions() (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[Duration]) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout +//go:noescape +func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[Duration]) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[Duration]) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout +//go:noescape +func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout +//go:noescape +func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout +//go:noescape +func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam +//go:noescape +func wasmimport_ResponseOutparamResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set +//go:noescape +func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response +//go:noescape +func wasmimport_IncomingResponseResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume +//go:noescape +func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers +//go:noescape +func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status +//go:noescape +func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body +//go:noescape +func wasmimport_IncomingBodyResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish +//go:noescape +func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream +//go:noescape +func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[InputStream, InputStream, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers +//go:noescape +func wasmimport_FutureTrailersResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get +//go:noescape +func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], struct{}]]) + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe +//go:noescape +func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response +//go:noescape +func wasmimport_OutgoingResponseResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response +//go:noescape +func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body +//go:noescape +func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers +//go:noescape +func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code +//go:noescape +func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code +//go:noescape +func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body +//go:noescape +func wasmimport_OutgoingBodyResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish +//go:noescape +func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write +//go:noescape +func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[OutputStream, OutputStream, struct{}]) + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response +//go:noescape +func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get +//go:noescape +func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe +//go:noescape +func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:http/types@0.2.0 http-error-code +//go:noescape +func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wit.go b/v2/internal/wasi/http/v0.2.0/types/types.wit.go index 96ea918..c0dccfc 100644 --- a/v2/internal/wasi/http/v0.2.0/types/types.wit.go +++ b/v2/internal/wasi/http/v0.2.0/types/types.wit.go @@ -15,6 +15,31 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) +// Duration represents the type alias "wasi:http/types@0.2.0#duration". +// +// See [monotonicclock.Duration] for more information. +type Duration = monotonicclock.Duration + +// InputStream represents the imported type alias "wasi:http/types@0.2.0#input-stream". +// +// See [streams.InputStream] for more information. +type InputStream = streams.InputStream + +// OutputStream represents the imported type alias "wasi:http/types@0.2.0#output-stream". +// +// See [streams.OutputStream] for more information. +type OutputStream = streams.OutputStream + +// IOError represents the imported type alias "wasi:http/types@0.2.0#io-error". +// +// See [ioerror.Error] for more information. +type IOError = ioerror.Error + +// Pollable represents the imported type alias "wasi:http/types@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + // Method represents the variant "wasi:http/types@0.2.0#method". // // This type corresponds to HTTP standard Methods. @@ -142,6 +167,24 @@ func (self *Method) Other() *string { return cm.Case[string](self, 9) } +var stringsMethod = [10]string{ + "get", + "head", + "post", + "put", + "delete", + "connect", + "options", + "trace", + "patch", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Method) String() string { + return stringsMethod[v.Tag()] +} + // Scheme represents the variant "wasi:http/types@0.2.0#scheme". // // This type corresponds to HTTP standard Related Schemes. @@ -185,6 +228,17 @@ func (self *Scheme) Other() *string { return cm.Case[string](self, 2) } +var stringsScheme = [3]string{ + "HTTP", + "HTTPS", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Scheme) String() string { + return stringsScheme[v.Tag()] +} + // DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". // // Defines the case payload type for `DNS-error` above: @@ -194,6 +248,7 @@ func (self *Scheme) Other() *string { // info-code: option, // } type DNSErrorPayload struct { + _ cm.HostLayout Rcode cm.Option[string] InfoCode cm.Option[uint16] } @@ -207,6 +262,7 @@ type DNSErrorPayload struct { // alert-message: option, // } type TLSAlertReceivedPayload struct { + _ cm.HostLayout AlertID cm.Option[uint8] AlertMessage cm.Option[string] } @@ -220,6 +276,7 @@ type TLSAlertReceivedPayload struct { // field-size: option, // } type FieldSizePayload struct { + _ cm.HostLayout FieldName cm.Option[string] FieldSize cm.Option[uint32] } @@ -692,6 +749,53 @@ func (self *ErrorCode) InternalError() *cm.Option[string] { return cm.Case[cm.Option[string]](self, 38) } +var stringsErrorCode = [39]string{ + "DNS-timeout", + "DNS-error", + "destination-not-found", + "destination-unavailable", + "destination-IP-prohibited", + "destination-IP-unroutable", + "connection-refused", + "connection-terminated", + "connection-timeout", + "connection-read-timeout", + "connection-write-timeout", + "connection-limit-reached", + "TLS-protocol-error", + "TLS-certificate-error", + "TLS-alert-received", + "HTTP-request-denied", + "HTTP-request-length-required", + "HTTP-request-body-size", + "HTTP-request-method-invalid", + "HTTP-request-URI-invalid", + "HTTP-request-URI-too-long", + "HTTP-request-header-section-size", + "HTTP-request-header-size", + "HTTP-request-trailer-section-size", + "HTTP-request-trailer-size", + "HTTP-response-incomplete", + "HTTP-response-header-section-size", + "HTTP-response-header-size", + "HTTP-response-body-size", + "HTTP-response-trailer-section-size", + "HTTP-response-trailer-size", + "HTTP-response-transfer-coding", + "HTTP-response-content-coding", + "HTTP-response-timeout", + "HTTP-upgrade-failed", + "HTTP-protocol-error", + "loop-detected", + "configuration-error", + "internal-error", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v ErrorCode) String() string { + return stringsErrorCode[v.Tag()] +} + // HeaderError represents the variant "wasi:http/types@0.2.0#header-error". // // This type enumerates the different kinds of errors that may occur when @@ -773,10 +877,6 @@ func (self Fields) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields -//go:noescape -func wasmimport_FieldsResourceDrop(self0 uint32) - // NewFields represents the imported constructor for resource "fields". // // Construct an empty HTTP Fields. @@ -792,10 +892,6 @@ func NewFields() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]fields -//go:noescape -func wasmimport_NewFields() (result0 uint32) - // FieldsFromList represents the imported static function "from-list". // // Construct an HTTP Fields. @@ -824,10 +920,6 @@ func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm. return } -//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list -//go:noescape -func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) - // Append represents the imported method "append". // // Append a value for a key. Does not change or delete any existing @@ -846,10 +938,6 @@ func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[Hea return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.append -//go:noescape -func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) - // Clone represents the imported method "clone". // // Make a deep copy of the Fields. Equivelant in behavior to calling the @@ -866,10 +954,6 @@ func (self Fields) Clone() (result Fields) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone -//go:noescape -func wasmimport_FieldsClone(self0 uint32) (result0 uint32) - // Delete represents the imported method "delete". // // Delete all values for a key. Does nothing if no values for the key @@ -887,10 +971,6 @@ func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{} return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete -//go:noescape -func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) - // Entries represents the imported method "entries". // // Retrieve the full set of keys and values in the Fields. Like the @@ -909,10 +989,6 @@ func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries -//go:noescape -func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) - // Get represents the imported method "get". // // Get all of the values corresponding to a key. If the key is not present @@ -930,10 +1006,6 @@ func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.get -//go:noescape -func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) - // Has represents the imported method "has". // // Returns `true` when the key is present in this `fields`. If the key is @@ -950,10 +1022,6 @@ func (self Fields) Has(name FieldKey) (result bool) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.has -//go:noescape -func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) - // Set represents the imported method "set". // // Set all of the values for a key. Clears any existing values for that @@ -972,9 +1040,15 @@ func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Resu return } -//go:wasmimport wasi:http/types@0.2.0 [method]fields.set -//go:noescape -func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) +// Headers represents the imported type alias "wasi:http/types@0.2.0#headers". +// +// See [Fields] for more information. +type Headers = Fields + +// Trailers represents the imported type alias "wasi:http/types@0.2.0#trailers". +// +// See [Fields] for more information. +type Trailers = Fields // IncomingRequest represents the imported resource "wasi:http/types@0.2.0#incoming-request". // @@ -994,10 +1068,6 @@ func (self IncomingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request -//go:noescape -func wasmimport_IncomingRequestResourceDrop(self0 uint32) - // Authority represents the imported method "authority". // // Returns the authority from the request, if it was present. @@ -1011,10 +1081,6 @@ func (self IncomingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority -//go:noescape -func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) - // Consume represents the imported method "consume". // // Gives the `incoming-body` associated with this request. Will only @@ -1029,10 +1095,6 @@ func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBo return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume -//go:noescape -func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) - // Headers represents the imported method "headers". // // Get the `headers` associated with the request. @@ -1047,17 +1109,13 @@ func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingB // headers: func() -> headers // //go:nosplit -func (self IncomingRequest) Headers() (result Fields) { +func (self IncomingRequest) Headers() (result Headers) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) - result = cm.Reinterpret[Fields]((uint32)(result0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers -//go:noescape -func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) - // Method represents the imported method "method". // // Returns the method of the incoming request. @@ -1071,10 +1129,6 @@ func (self IncomingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method -//go:noescape -func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) - // PathWithQuery represents the imported method "path-with-query". // // Returns the path with query parameters from the request, as a string. @@ -1088,10 +1142,6 @@ func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query -//go:noescape -func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) - // Scheme represents the imported method "scheme". // // Returns the protocol scheme from the request. @@ -1105,10 +1155,6 @@ func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme -//go:noescape -func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) - // OutgoingRequest represents the imported resource "wasi:http/types@0.2.0#outgoing-request". // // Represents an outgoing HTTP Request. @@ -1127,10 +1173,6 @@ func (self OutgoingRequest) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request -//go:noescape -func wasmimport_OutgoingRequestResourceDrop(self0 uint32) - // NewOutgoingRequest represents the imported constructor for resource "outgoing-request". // // Construct a new `outgoing-request` with a default `method` of `GET`, and @@ -1147,17 +1189,13 @@ func wasmimport_OutgoingRequestResourceDrop(self0 uint32) // constructor(headers: headers) // //go:nosplit -func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { +func NewOutgoingRequest(headers Headers) (result OutgoingRequest) { headers0 := cm.Reinterpret[uint32](headers) result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request -//go:noescape -func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) - // Authority represents the imported method "authority". // // Get the HTTP Authority for the Request. A value of `none` may be used @@ -1173,10 +1211,6 @@ func (self OutgoingRequest) Authority() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority -//go:noescape -func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) - // Body represents the imported method "body". // // Returns the resource corresponding to the outgoing Body for this @@ -1195,10 +1229,6 @@ func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body -//go:noescape -func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) - // Headers represents the imported method "headers". // // Get the headers associated with the Request. @@ -1213,17 +1243,13 @@ func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody // headers: func() -> headers // //go:nosplit -func (self OutgoingRequest) Headers() (result Fields) { +func (self OutgoingRequest) Headers() (result Headers) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) - result = cm.Reinterpret[Fields]((uint32)(result0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers -//go:noescape -func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) - // Method represents the imported method "method". // // Get the Method for the Request. @@ -1237,10 +1263,6 @@ func (self OutgoingRequest) Method() (result Method) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method -//go:noescape -func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) - // PathWithQuery represents the imported method "path-with-query". // // Get the combination of the HTTP Path and Query for the Request. @@ -1255,10 +1277,6 @@ func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query -//go:noescape -func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) - // Scheme represents the imported method "scheme". // // Get the HTTP Related Scheme for the Request. When `none`, the @@ -1273,10 +1291,6 @@ func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme -//go:noescape -func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) - // SetAuthority represents the imported method "set-authority". // // Set the HTTP Authority for the Request. A value of `none` may be used @@ -1295,10 +1309,6 @@ func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority -//go:noescape -func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) - // SetMethod represents the imported method "set-method". // // Set the Method for the Request. Fails if the string present in a @@ -1315,10 +1325,6 @@ func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method -//go:noescape -func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) - // SetPathWithQuery represents the imported method "set-path-with-query". // // Set the combination of the HTTP Path and Query for the Request. @@ -1336,10 +1342,6 @@ func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (r return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query -//go:noescape -func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) - // SetScheme represents the imported method "set-scheme". // // Set the HTTP Related Scheme for the Request. When `none`, the @@ -1357,10 +1359,6 @@ func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolR return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme -//go:noescape -func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) - // RequestOptions represents the imported resource "wasi:http/types@0.2.0#request-options". // // Parameters for making an HTTP Request. Each of these parameters is @@ -1384,10 +1382,6 @@ func (self RequestOptions) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options -//go:noescape -func wasmimport_RequestOptionsResourceDrop(self0 uint32) - // NewRequestOptions represents the imported constructor for resource "request-options". // // Construct a default `request-options` value. @@ -1401,10 +1395,6 @@ func NewRequestOptions() (result RequestOptions) { return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options -//go:noescape -func wasmimport_NewRequestOptions() (result0 uint32) - // BetweenBytesTimeout represents the imported method "between-bytes-timeout". // // The timeout for receiving subsequent chunks of bytes in the Response @@ -1413,16 +1403,12 @@ func wasmimport_NewRequestOptions() (result0 uint32) // between-bytes-timeout: func() -> option // //go:nosplit -func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotonicclock.Duration]) { +func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[Duration]) { self0 := cm.Reinterpret[uint32](self) wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout -//go:noescape -func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) - // ConnectTimeout represents the imported method "connect-timeout". // // The timeout for the initial connect to the HTTP Server. @@ -1430,16 +1416,12 @@ func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Optio // connect-timeout: func() -> option // //go:nosplit -func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Duration]) { +func (self RequestOptions) ConnectTimeout() (result cm.Option[Duration]) { self0 := cm.Reinterpret[uint32](self) wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout -//go:noescape -func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) - // FirstByteTimeout represents the imported method "first-byte-timeout". // // The timeout for receiving the first byte of the Response body. @@ -1447,16 +1429,12 @@ func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[mon // first-byte-timeout: func() -> option // //go:nosplit -func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.Duration]) { +func (self RequestOptions) FirstByteTimeout() (result cm.Option[Duration]) { self0 := cm.Reinterpret[uint32](self) wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout -//go:noescape -func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) - // SetBetweenBytesTimeout represents the imported method "set-between-bytes-timeout". // // Set the timeout for receiving subsequent chunks of bytes in the Response @@ -1466,7 +1444,7 @@ func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[m // set-between-bytes-timeout: func(duration: option) -> result // //go:nosplit -func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { +func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[Duration]) (result cm.BoolResult) { self0 := cm.Reinterpret[uint32](self) duration0, duration1 := lower_OptionDuration(duration) result0 := wasmimport_RequestOptionsSetBetweenBytesTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) @@ -1474,10 +1452,6 @@ func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotoniccl return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout -//go:noescape -func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) - // SetConnectTimeout represents the imported method "set-connect-timeout". // // Set the timeout for the initial connect to the HTTP Server. An error @@ -1486,7 +1460,7 @@ func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uin // set-connect-timeout: func(duration: option) -> result // //go:nosplit -func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { +func (self RequestOptions) SetConnectTimeout(duration cm.Option[Duration]) (result cm.BoolResult) { self0 := cm.Reinterpret[uint32](self) duration0, duration1 := lower_OptionDuration(duration) result0 := wasmimport_RequestOptionsSetConnectTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) @@ -1494,10 +1468,6 @@ func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.D return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout -//go:noescape -func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) - // SetFirstByteTimeout represents the imported method "set-first-byte-timeout". // // Set the timeout for receiving the first byte of the Response body. An @@ -1506,7 +1476,7 @@ func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, // set-first-byte-timeout: func(duration: option) -> result // //go:nosplit -func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { +func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[Duration]) (result cm.BoolResult) { self0 := cm.Reinterpret[uint32](self) duration0, duration1 := lower_OptionDuration(duration) result0 := wasmimport_RequestOptionsSetFirstByteTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) @@ -1514,10 +1484,6 @@ func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock return } -//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout -//go:noescape -func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) - // ResponseOutparam represents the imported resource "wasi:http/types@0.2.0#response-outparam". // // Represents the ability to send an HTTP Response. @@ -1540,10 +1506,6 @@ func (self ResponseOutparam) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam -//go:noescape -func wasmimport_ResponseOutparamResourceDrop(self0 uint32) - // ResponseOutparamSet represents the imported static function "set". // // Set the value of the `response-outparam` to either send a response, @@ -1567,10 +1529,6 @@ func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeSha return } -//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set -//go:noescape -func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) - // StatusCode represents the u16 "wasi:http/types@0.2.0#status-code". // // This type corresponds to the HTTP standard Status Code. @@ -1596,10 +1554,6 @@ func (self IncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response -//go:noescape -func wasmimport_IncomingResponseResourceDrop(self0 uint32) - // Consume represents the imported method "consume". // // Returns the incoming body. May be called at most once. Returns error @@ -1614,10 +1568,6 @@ func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingB return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume -//go:noescape -func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) - // Headers represents the imported method "headers". // // Returns the headers from the incoming response. @@ -1631,17 +1581,13 @@ func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[Incoming // headers: func() -> headers // //go:nosplit -func (self IncomingResponse) Headers() (result Fields) { +func (self IncomingResponse) Headers() (result Headers) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) - result = cm.Reinterpret[Fields]((uint32)(result0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers -//go:noescape -func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) - // Status represents the imported method "status". // // Returns the status code from the incoming response. @@ -1656,10 +1602,6 @@ func (self IncomingResponse) Status() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status -//go:noescape -func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) - // IncomingBody represents the imported resource "wasi:http/types@0.2.0#incoming-body". // // Represents an incoming HTTP Request or Response's Body. @@ -1685,10 +1627,6 @@ func (self IncomingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body -//go:noescape -func wasmimport_IncomingBodyResourceDrop(self0 uint32) - // IncomingBodyFinish represents the imported static function "finish". // // Takes ownership of `incoming-body`, and returns a `future-trailers`. @@ -1704,10 +1642,6 @@ func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { return } -//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish -//go:noescape -func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) - // Stream represents the imported method "stream". // // Returns the contents of the body, as a stream of bytes. @@ -1729,16 +1663,12 @@ func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) // %stream: func() -> result // //go:nosplit -func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams.InputStream, struct{}]) { +func (self IncomingBody) Stream() (result cm.Result[InputStream, InputStream, struct{}]) { self0 := cm.Reinterpret[uint32](self) wasmimport_IncomingBodyStream((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream -//go:noescape -func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) - // FutureTrailers represents the imported resource "wasi:http/types@0.2.0#future-trailers". // // Represents a future which may eventaully return trailers, or an error. @@ -1761,10 +1691,6 @@ func (self FutureTrailers) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers -//go:noescape -func wasmimport_FutureTrailersResourceDrop(self0 uint32) - // Get represents the imported method "get". // // Returns the contents of the trailers, or an error which occured, @@ -1790,16 +1716,12 @@ func wasmimport_FutureTrailersResourceDrop(self0 uint32) // get: func() -> option, error-code>>> // //go:nosplit -func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) { +func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], struct{}]]) { self0 := cm.Reinterpret[uint32](self) wasmimport_FutureTrailersGet((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get -//go:noescape -func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) - // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the trailers have @@ -1809,17 +1731,13 @@ func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.R // subscribe: func() -> pollable // //go:nosplit -func (self FutureTrailers) Subscribe() (result poll.Pollable) { +func (self FutureTrailers) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe -//go:noescape -func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) - // OutgoingResponse represents the imported resource "wasi:http/types@0.2.0#outgoing-response". // // Represents an outgoing HTTP Response. @@ -1838,10 +1756,6 @@ func (self OutgoingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response -//go:noescape -func wasmimport_OutgoingResponseResourceDrop(self0 uint32) - // NewOutgoingResponse represents the imported constructor for resource "outgoing-response". // // Construct an `outgoing-response`, with a default `status-code` of `200`. @@ -1853,17 +1767,13 @@ func wasmimport_OutgoingResponseResourceDrop(self0 uint32) // constructor(headers: headers) // //go:nosplit -func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { +func NewOutgoingResponse(headers Headers) (result OutgoingResponse) { headers0 := cm.Reinterpret[uint32](headers) result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response -//go:noescape -func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) - // Body represents the imported method "body". // // Returns the resource corresponding to the outgoing Body for this Response. @@ -1881,10 +1791,6 @@ func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body -//go:noescape -func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) - // Headers represents the imported method "headers". // // Get the headers associated with the Request. @@ -1899,17 +1805,13 @@ func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBod // headers: func() -> headers // //go:nosplit -func (self OutgoingResponse) Headers() (result Fields) { +func (self OutgoingResponse) Headers() (result Headers) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) - result = cm.Reinterpret[Fields]((uint32)(result0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers -//go:noescape -func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) - // SetStatusCode represents the imported method "set-status-code". // // Set the HTTP Status Code for the Response. Fails if the status-code @@ -1926,10 +1828,6 @@ func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.Boo return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code -//go:noescape -func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) - // StatusCode represents the imported method "status-code". // // Get the HTTP Status Code for the Response. @@ -1944,10 +1842,6 @@ func (self OutgoingResponse) StatusCode() (result StatusCode) { return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code -//go:noescape -func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) - // OutgoingBody represents the imported resource "wasi:http/types@0.2.0#outgoing-body". // // Represents an outgoing HTTP Request or Response's Body. @@ -1981,10 +1875,6 @@ func (self OutgoingBody) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body -//go:noescape -func wasmimport_OutgoingBodyResourceDrop(self0 uint32) - // OutgoingBodyFinish represents the imported static function "finish". // // Finalize an outgoing body, optionally providing trailers. This must be @@ -2001,17 +1891,13 @@ func wasmimport_OutgoingBodyResourceDrop(self0 uint32) // error-code> // //go:nosplit -func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { +func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Trailers]) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { this0 := cm.Reinterpret[uint32](this) trailers0, trailers1 := lower_OptionTrailers(trailers) wasmimport_OutgoingBodyFinish((uint32)(this0), (uint32)(trailers0), (uint32)(trailers1), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish -//go:noescape -func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) - // Write represents the imported method "write". // // Returns a stream for writing the body contents. @@ -2027,16 +1913,12 @@ func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uin // write: func() -> result // //go:nosplit -func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) { +func (self OutgoingBody) Write() (result cm.Result[OutputStream, OutputStream, struct{}]) { self0 := cm.Reinterpret[uint32](self) wasmimport_OutgoingBodyWrite((uint32)(self0), &result) return } -//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write -//go:noescape -func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) - // FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.0#future-incoming-response". // // Represents a future which may eventaully return an incoming HTTP @@ -2059,10 +1941,6 @@ func (self FutureIncomingResponse) ResourceDrop() { return } -//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response -//go:noescape -func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) - // Get represents the imported method "get". // // Returns the incoming HTTP Response, or an error, once one is ready. @@ -2089,10 +1967,6 @@ func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[E return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get -//go:noescape -func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) - // Subscribe represents the imported method "subscribe". // // Returns a pollable which becomes ready when either the Response has @@ -2102,17 +1976,13 @@ func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Res // subscribe: func() -> pollable // //go:nosplit -func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { +func (self FutureIncomingResponse) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe -//go:noescape -func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) - // HTTPErrorCode represents the imported function "http-error-code". // // Attempts to extract a http-related `error` from the wasi:io `error` @@ -2130,12 +2000,8 @@ func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) // http-error-code: func(err: borrow) -> option // //go:nosplit -func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { +func HTTPErrorCode(err IOError) (result cm.Option[ErrorCode]) { err0 := cm.Reinterpret[uint32](err) wasmimport_HTTPErrorCode((uint32)(err0), &result) return } - -//go:wasmimport wasi:http/types@0.2.0 http-error-code -//go:noescape -func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) diff --git a/v2/internal/wasi/io/v0.2.0/error/error.wit.go b/v2/internal/wasi/io/v0.2.0/error/error.wit.go index 61d61db..37e5527 100644 --- a/v2/internal/wasi/io/v0.2.0/error/error.wit.go +++ b/v2/internal/wasi/io/v0.2.0/error/error.wit.go @@ -43,10 +43,6 @@ func (self Error) ResourceDrop() { return } -//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error -//go:noescape -func wasmimport_ErrorResourceDrop(self0 uint32) - // ToDebugString represents the imported method "to-debug-string". // // Returns a string that is suitable to assist humans in debugging @@ -65,7 +61,3 @@ func (self Error) ToDebugString() (result string) { wasmimport_ErrorToDebugString((uint32)(self0), &result) return } - -//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string -//go:noescape -func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go b/v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go new file mode 100755 index 0000000..e254b5d --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package ioerror + +// This file contains wasmimport and wasmexport declarations for "wasi:io@0.2.0". + +//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error +//go:noescape +func wasmimport_ErrorResourceDrop(self0 uint32) + +//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string +//go:noescape +func wasmimport_ErrorToDebugString(self0 uint32, result *string) diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go b/v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go new file mode 100755 index 0000000..2d7525d --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package poll + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:io@0.2.0". + +//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable +//go:noescape +func wasmimport_PollableResourceDrop(self0 uint32) + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block +//go:noescape +func wasmimport_PollableBlock(self0 uint32) + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready +//go:noescape +func wasmimport_PollableReady(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:io/poll@0.2.0 poll +//go:noescape +func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go index d11852f..e0b3356 100644 --- a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -28,10 +28,6 @@ func (self Pollable) ResourceDrop() { return } -//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable -//go:noescape -func wasmimport_PollableResourceDrop(self0 uint32) - // Block represents the imported method "block". // // `block` returns immediately if the pollable is ready, and otherwise @@ -49,10 +45,6 @@ func (self Pollable) Block() { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block -//go:noescape -func wasmimport_PollableBlock(self0 uint32) - // Ready represents the imported method "ready". // // Return the readiness of a pollable. This function never blocks. @@ -69,10 +61,6 @@ func (self Pollable) Ready() (result bool) { return } -//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready -//go:noescape -func wasmimport_PollableReady(self0 uint32) (result0 uint32) - // Poll represents the imported function "poll". // // Poll for completion on a set of pollables. @@ -102,7 +90,3 @@ func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { wasmimport_Poll((*Pollable)(in0), (uint32)(in1), &result) return } - -//go:wasmimport wasi:io/poll@0.2.0 poll -//go:noescape -func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go b/v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go new file mode 100755 index 0000000..c0b196a --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go @@ -0,0 +1,77 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package streams + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:io@0.2.0". + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream +//go:noescape +func wasmimport_InputStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read +//go:noescape +func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip +//go:noescape +func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read +//go:noescape +func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip +//go:noescape +func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe +//go:noescape +func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream +//go:noescape +func wasmimport_OutputStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush +//go:noescape +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice +//go:noescape +func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush +//go:noescape +func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write +//go:noescape +func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush +//go:noescape +func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice +//go:noescape +func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe +//go:noescape +func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write +//go:noescape +func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes +//go:noescape +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go index d69726d..731dc07 100644 --- a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go +++ b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -15,6 +15,16 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" ) +// Error represents the imported type alias "wasi:io/streams@0.2.0#error". +// +// See [ioerror.Error] for more information. +type Error = ioerror.Error + +// Pollable represents the imported type alias "wasi:io/streams@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". // // An error for input-stream and output-stream operations. @@ -23,20 +33,20 @@ import ( // last-operation-failed(error), // closed, // } -type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] +type StreamError cm.Variant[uint8, Error, 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 { +func StreamErrorLastOperationFailed(data Error) StreamError { return cm.New[StreamError](0, data) } -// LastOperationFailed returns a non-nil *[ioerror.Error] if [StreamError] represents the variant case "last-operation-failed". -func (self *StreamError) LastOperationFailed() *ioerror.Error { - return cm.Case[ioerror.Error](self, 0) +// LastOperationFailed returns a non-nil *[Error] if [StreamError] represents the variant case "last-operation-failed". +func (self *StreamError) LastOperationFailed() *Error { + return cm.Case[Error](self, 0) } // StreamErrorClosed returns a [StreamError] of case "closed". @@ -54,6 +64,16 @@ func (self *StreamError) Closed() bool { return self.Tag() == 1 } +var stringsStreamError = [2]string{ + "last-operation-failed", + "closed", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v StreamError) String() string { + return stringsStreamError[v.Tag()] +} + // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". // // An input bytestream. @@ -79,10 +99,6 @@ func (self InputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream -//go:noescape -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 @@ -98,10 +114,6 @@ func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read -//go:noescape -func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) - // BlockingSkip represents the imported method "blocking-skip". // // Skip bytes from a stream, after blocking until at least one byte @@ -117,10 +129,6 @@ func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip -//go:noescape -func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) - // Read represents the imported method "read". // // Perform a non-blocking read from the stream. @@ -160,10 +168,6 @@ func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.L return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read -//go:noescape -func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) - // Skip represents the imported method "skip". // // Skip bytes from a stream. Returns number of bytes skipped. @@ -181,10 +185,6 @@ func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, Stre return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip -//go:noescape -func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once either the specified stream @@ -197,17 +197,13 @@ func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uin // subscribe: func() -> pollable // //go:nosplit -func (self InputStream) Subscribe() (result poll.Pollable) { +func (self InputStream) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe -//go:noescape -func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) - // OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". // // An output bytestream. @@ -233,10 +229,6 @@ func (self OutputStream) ResourceDrop() { return } -//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream -//go:noescape -func wasmimport_OutputStreamResourceDrop(self0 uint32) - // BlockingFlush represents the imported method "blocking-flush". // // Request to flush buffered output, and block until flush completes @@ -251,10 +243,6 @@ func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{} return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush -//go:noescape -func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) - // BlockingSplice represents the imported method "blocking-splice". // // Read from one stream and write to another, with blocking. @@ -274,10 +262,6 @@ func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice -//go:noescape -func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) - // BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". // // Perform a write of up to 4096 bytes, and then flush the stream. Block @@ -313,10 +297,6 @@ func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush -//go:noescape -func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) - // BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". // // Perform a write of up to 4096 zeroes, and then flush the stream. @@ -352,10 +332,6 @@ func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Res return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush -//go:noescape -func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) - // CheckWrite represents the imported method "check-write". // // Check readiness for writing. This function never blocks. @@ -377,10 +353,6 @@ func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamEr return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write -//go:noescape -func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) - // Flush represents the imported method "flush". // // Request to flush buffered output. This function never blocks. @@ -403,10 +375,6 @@ func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush -//go:noescape -func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) - // Splice represents the imported method "splice". // // Read from one stream and write to another. @@ -434,10 +402,6 @@ func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[ return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice -//go:noescape -func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the output-stream @@ -454,17 +418,13 @@ func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, resul // subscribe: func() -> pollable // //go:nosplit -func (self OutputStream) Subscribe() (result poll.Pollable) { +func (self OutputStream) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe -//go:noescape -func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) - // Write represents the imported method "write". // // Perform a write. This function never blocks. @@ -491,10 +451,6 @@ func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[Stream return } -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write -//go:noescape -func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) - // WriteZeroes represents the imported method "write-zeroes". // // Write zeroes to a stream. @@ -513,7 +469,3 @@ func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, wasmimport_OutputStreamWriteZeroes((uint32)(self0), (uint64)(len0), &result) return } - -//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes -//go:noescape -func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go index 3b8f33c..6f36367 100644 --- a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go +++ b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go @@ -35,7 +35,3 @@ func InsecureSeed() (result [2]uint64) { wasmimport_InsecureSeed(&result) return } - -//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed -//go:noescape -func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecureseed.wasm.go b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecureseed.wasm.go new file mode 100755 index 0000000..e94356d --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecureseed.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package insecureseed + +// This file contains wasmimport and wasmexport declarations for "wasi:random@0.2.0". + +//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed +//go:noescape +func wasmimport_InsecureSeed(result *[2]uint64) diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go new file mode 100755 index 0000000..5d2d34a --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package insecure + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:random@0.2.0". + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes +//go:noescape +func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 +//go:noescape +func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go index bfe1e6c..0d88a9c 100644 --- a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go +++ b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go @@ -32,10 +32,6 @@ func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes -//go:noescape -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. @@ -51,7 +47,3 @@ func GetInsecureRandomU64() (result uint64) { result = (uint64)((uint64)(result0)) return } - -//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 -//go:noescape -func wasmimport_GetInsecureRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wasm.go b/v2/internal/wasi/random/v0.2.0/random/random.wasm.go new file mode 100755 index 0000000..661e8f4 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/random/random.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package random + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:random@0.2.0". + +//go:wasmimport wasi:random/random@0.2.0 get-random-bytes +//go:noescape +func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) + +//go:wasmimport wasi:random/random@0.2.0 get-random-u64 +//go:noescape +func wasmimport_GetRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wit.go b/v2/internal/wasi/random/v0.2.0/random/random.wit.go index da2eb57..da1dfcb 100644 --- a/v2/internal/wasi/random/v0.2.0/random/random.wit.go +++ b/v2/internal/wasi/random/v0.2.0/random/random.wit.go @@ -36,10 +36,6 @@ func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { return } -//go:wasmimport wasi:random/random@0.2.0 get-random-bytes -//go:noescape -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. @@ -55,7 +51,3 @@ func GetRandomU64() (result uint64) { result = (uint64)((uint64)(result0)) return } - -//go:wasmimport wasi:random/random@0.2.0 get-random-u64 -//go:noescape -func wasmimport_GetRandomU64() (result0 uint64) diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go index 6f094e6..4344fd9 100644 --- a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -10,6 +10,11 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" ) +// Network represents the imported type alias "wasi:sockets/instance-network@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + // InstanceNetwork represents the imported function "instance-network". // // Get a handle to the default network. @@ -17,12 +22,8 @@ import ( // instance-network: func() -> network // //go:nosplit -func InstanceNetwork() (result network.Network) { +func InstanceNetwork() (result Network) { result0 := wasmimport_InstanceNetwork() - result = cm.Reinterpret[network.Network]((uint32)(result0)) + result = cm.Reinterpret[Network]((uint32)(result0)) return } - -//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network -//go:noescape -func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instancenetwork.wasm.go b/v2/internal/wasi/sockets/v0.2.0/instance-network/instancenetwork.wasm.go new file mode 100755 index 0000000..eb113e2 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/instancenetwork.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package instancenetwork + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network +//go:noescape +func wasmimport_InstanceNetwork() (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go index 23564f4..0f48f26 100644 --- a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go @@ -4,11 +4,11 @@ package ipnamelookup import ( "github.com/bytecodealliance/wasm-tools-go/cm" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "unsafe" ) // OptionIPAddressShape is used for storage in variant or result types. type OptionIPAddressShape struct { - shape [unsafe.Sizeof(cm.Option[network.IPAddress]{})]byte + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Option[IPAddress]{})]byte } diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go index a4154fb..924bcf7 100644 --- a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -9,6 +9,26 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" ) +// Pollable represents the imported type alias "wasi:sockets/ip-name-lookup@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + +// Network represents the imported type alias "wasi:sockets/ip-name-lookup@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + +// ErrorCode represents the type alias "wasi:sockets/ip-name-lookup@0.2.0#error-code". +// +// See [network.ErrorCode] for more information. +type ErrorCode = network.ErrorCode + +// IPAddress represents the type alias "wasi:sockets/ip-name-lookup@0.2.0#ip-address". +// +// See [network.IPAddress] for more information. +type IPAddress = network.IPAddress + // ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". // // resource resolve-address-stream @@ -25,10 +45,6 @@ func (self ResolveAddressStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream -//go:noescape -func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) - // ResolveNextAddress represents the imported method "resolve-next-address". // // Returns the next address from the resolver. @@ -51,16 +67,12 @@ func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) // resolve-next-address: func() -> result, error-code> // //go:nosplit -func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) { +func (self ResolveAddressStream) ResolveNextAddress() (result cm.Result[OptionIPAddressShape, cm.Option[IPAddress], ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address -//go:noescape -func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[network.IPAddress], network.ErrorCode]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the stream is ready for I/O. @@ -71,17 +83,13 @@ func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm. // subscribe: func() -> pollable // //go:nosplit -func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { +func (self ResolveAddressStream) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe -//go:noescape -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. @@ -109,13 +117,9 @@ func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) // error-code> // //go:nosplit -func ResolveAddresses(network_ network.Network, name string) (result cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) { +func ResolveAddresses(network_ Network, name string) (result cm.Result[ResolveAddressStream, ResolveAddressStream, ErrorCode]) { network0 := cm.Reinterpret[uint32](network_) name0, name1 := cm.LowerString(name) wasmimport_ResolveAddresses((uint32)(network0), (*uint8)(name0), (uint32)(name1), &result) return } - -//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses -//go:noescape -func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ipnamelookup.wasm.go b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ipnamelookup.wasm.go new file mode 100755 index 0000000..2908d40 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ipnamelookup.wasm.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package ipnamelookup + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream +//go:noescape +func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address +//go:noescape +func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.Result[OptionIPAddressShape, cm.Option[IPAddress], ErrorCode]) + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe +//go:noescape +func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses +//go:noescape +func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.Result[ResolveAddressStream, ResolveAddressStream, ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/network/abi.go b/v2/internal/wasi/sockets/v0.2.0/network/abi.go index 54820be..fc094e3 100644 --- a/v2/internal/wasi/sockets/v0.2.0/network/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/network/abi.go @@ -3,10 +3,12 @@ package network import ( + "github.com/bytecodealliance/wasm-tools-go/cm" "unsafe" ) // IPv6SocketAddressShape is used for storage in variant or result types. type IPv6SocketAddressShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(IPv6SocketAddress{})]byte } diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go b/v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go new file mode 100755 index 0000000..012a79f --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go @@ -0,0 +1,9 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package network + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +//go:noescape +func wasmimport_NetworkResourceDrop(self0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go index b18bec9..a7fb62b 100644 --- a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -27,10 +27,6 @@ func (self Network) ResourceDrop() { return } -//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network -//go:noescape -func wasmimport_NetworkResourceDrop(self0 uint32) - // ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". // // Error codes. @@ -250,6 +246,16 @@ func (self *IPAddress) IPv6() *IPv6Address { return cm.Case[IPv6Address](self, 1) } +var stringsIPAddress = [2]string{ + "ipv4", + "ipv6", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v IPAddress) String() string { + return stringsIPAddress[v.Tag()] +} + // IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". // // record ipv4-socket-address { @@ -257,6 +263,7 @@ func (self *IPAddress) IPv6() *IPv6Address { // address: ipv4-address, // } type IPv4SocketAddress struct { + _ cm.HostLayout // sin_port Port uint16 @@ -273,6 +280,7 @@ type IPv4SocketAddress struct { // scope-id: u32, // } type IPv6SocketAddress struct { + _ cm.HostLayout // sin6_port Port uint16 @@ -313,3 +321,13 @@ func IPSocketAddressIPv6(data IPv6SocketAddress) IPSocketAddress { func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { return cm.Case[IPv6SocketAddress](self, 1) } + +var stringsIPSocketAddress = [2]string{ + "ipv4", + "ipv6", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v IPSocketAddress) String() string { + return stringsIPSocketAddress[v.Tag()] +} diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go index ce311f8..f1c27b5 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -9,6 +9,26 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/tcp" ) +// Network represents the imported type alias "wasi:sockets/tcp-create-socket@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + +// ErrorCode represents the type alias "wasi:sockets/tcp-create-socket@0.2.0#error-code". +// +// See [network.ErrorCode] for more information. +type ErrorCode = network.ErrorCode + +// IPAddressFamily represents the type alias "wasi:sockets/tcp-create-socket@0.2.0#ip-address-family". +// +// See [network.IPAddressFamily] for more information. +type IPAddressFamily = network.IPAddressFamily + +// TCPSocket represents the imported type alias "wasi:sockets/tcp-create-socket@0.2.0#tcp-socket". +// +// See [tcp.TCPSocket] for more information. +type TCPSocket = tcp.TCPSocket + // CreateTCPSocket represents the imported function "create-tcp-socket". // // Create a new TCP socket. @@ -41,12 +61,8 @@ import ( // error-code> // //go:nosplit -func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) { +func CreateTCPSocket(addressFamily IPAddressFamily) (result cm.Result[TCPSocket, TCPSocket, ErrorCode]) { addressFamily0 := (uint32)(addressFamily) wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) return } - -//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket -//go:noescape -func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[tcp.TCPSocket, tcp.TCPSocket, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcpcreatesocket.wasm.go b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcpcreatesocket.wasm.go new file mode 100755 index 0000000..cb7c0cd --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcpcreatesocket.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcpcreatesocket + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket +//go:noescape +func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.Result[TCPSocket, TCPSocket, ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go index ca71a81..cb0a3f6 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -4,23 +4,25 @@ package tcp import ( "github.com/bytecodealliance/wasm-tools-go/cm" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "unsafe" ) // TupleTCPSocketInputStreamOutputStreamShape is used for storage in variant or result types. type TupleTCPSocketInputStreamOutputStreamShape struct { - shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream]{})]byte + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, InputStream, OutputStream]{})]byte } // TupleInputStreamOutputStreamShape is used for storage in variant or result types. type TupleInputStreamOutputStreamShape struct { - shape [unsafe.Sizeof(cm.Tuple[streams.InputStream, streams.OutputStream]{})]byte + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Tuple[InputStream, OutputStream]{})]byte } // IPSocketAddressShape is used for storage in variant or result types. type IPSocketAddressShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(network.IPSocketAddress{})]byte } diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go new file mode 100755 index 0000000..f1818db --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go @@ -0,0 +1,125 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket +//go:noescape +func wasmimport_TCPSocketResourceDrop(self0 uint32) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept +//go:noescape +func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, InputStream, OutputStream], ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family +//go:noescape +func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind +//go:noescape +func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect +//go:noescape +func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[InputStream, OutputStream], ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen +//go:noescape +func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit +//go:noescape +func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening +//go:noescape +func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count +//go:noescape +func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, Duration, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval +//go:noescape +func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, Duration, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address +//go:noescape +func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size +//go:noescape +func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address +//go:noescape +func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size +//go:noescape +func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit +//go:noescape +func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count +//go:noescape +func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled +//go:noescape +func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time +//go:noescape +func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval +//go:noescape +func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size +//go:noescape +func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size +//go:noescape +func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown +//go:noescape +func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind +//go:noescape +func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect +//go:noescape +func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen +//go:noescape +func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe +//go:noescape +func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go index 517451c..2fb3b9d 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -11,6 +11,46 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" ) +// InputStream represents the imported type alias "wasi:sockets/tcp@0.2.0#input-stream". +// +// See [streams.InputStream] for more information. +type InputStream = streams.InputStream + +// OutputStream represents the imported type alias "wasi:sockets/tcp@0.2.0#output-stream". +// +// See [streams.OutputStream] for more information. +type OutputStream = streams.OutputStream + +// Pollable represents the imported type alias "wasi:sockets/tcp@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + +// Duration represents the type alias "wasi:sockets/tcp@0.2.0#duration". +// +// See [monotonicclock.Duration] for more information. +type Duration = monotonicclock.Duration + +// Network represents the imported type alias "wasi:sockets/tcp@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + +// ErrorCode represents the type alias "wasi:sockets/tcp@0.2.0#error-code". +// +// See [network.ErrorCode] for more information. +type ErrorCode = network.ErrorCode + +// IPSocketAddress represents the type alias "wasi:sockets/tcp@0.2.0#ip-socket-address". +// +// See [network.IPSocketAddress] for more information. +type IPSocketAddress = network.IPSocketAddress + +// IPAddressFamily represents the type alias "wasi:sockets/tcp@0.2.0#ip-address-family". +// +// See [network.IPAddressFamily] for more information. +type IPAddressFamily = network.IPAddressFamily + // ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". // // enum shutdown-type { @@ -81,10 +121,6 @@ func (self TCPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket -//go:noescape -func wasmimport_TCPSocketResourceDrop(self0 uint32) - // Accept represents the imported method "accept". // // Accept a new client socket. @@ -120,16 +156,12 @@ func wasmimport_TCPSocketResourceDrop(self0 uint32) // accept: func() -> result, error-code> // //go:nosplit -func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) { +func (self TCPSocket) Accept() (result cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, InputStream, OutputStream], ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketAccept((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept -//go:noescape -func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketInputStreamOutputStreamShape, cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) - // AddressFamily represents the imported method "address-family". // // Whether this is a IPv4 or IPv6 socket. @@ -139,62 +171,46 @@ func wasmimport_TCPSocketAccept(self0 uint32, result *cm.Result[TupleTCPSocketIn // address-family: func() -> ip-address-family // //go:nosplit -func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { +func (self TCPSocket) AddressFamily() (result IPAddressFamily) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) result = (network.IPAddressFamily)((uint32)(result0)) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family -//go:noescape -func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) - // FinishBind represents the imported method "finish-bind". // // finish-bind: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketFinishBind((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind -//go:noescape -func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // FinishConnect represents the imported method "finish-connect". // // finish-connect: func() -> result, error-code> // //go:nosplit -func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) { +func (self TCPSocket) FinishConnect() (result cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[InputStream, OutputStream], ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect -//go:noescape -func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.Result[TupleInputStreamOutputStreamShape, cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) - // FinishListen represents the imported method "finish-listen". // // finish-listen: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) FinishListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) FinishListen() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketFinishListen((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen -//go:noescape -func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // HopLimit represents the imported method "hop-limit". // // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. @@ -207,16 +223,12 @@ func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.Result[network.Er // hop-limit: func() -> result // //go:nosplit -func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { +func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketHopLimit((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit -//go:noescape -func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) - // IsListening represents the imported method "is-listening". // // Whether the socket is in the `listening` state. @@ -233,10 +245,6 @@ func (self TCPSocket) IsListening() (result bool) { return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening -//go:noescape -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. @@ -255,16 +263,12 @@ func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) // keep-alive-count: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, network.ErrorCode]) { +func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count -//go:noescape -func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, uint32, network.ErrorCode]) - // KeepAliveEnabled represents the imported method "keep-alive-enabled". // // Enables or disables keepalive. @@ -281,16 +285,12 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, // keep-alive-enabled: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, network.ErrorCode]) { +func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled -//go:noescape -func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, network.ErrorCode]) - // KeepAliveIdleTime represents the imported method "keep-alive-idle-time". // // Amount of time the connection has to be idle before TCP starts sending keepalive @@ -310,16 +310,12 @@ func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, // keep-alive-idle-time: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { +func (self TCPSocket) KeepAliveIdleTime() (result cm.Result[uint64, Duration, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time -//go:noescape -func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) - // KeepAliveInterval represents the imported method "keep-alive-interval". // // The time between keepalive packets. @@ -338,16 +334,12 @@ func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.Result[uint6 // keep-alive-interval: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) { +func (self TCPSocket) KeepAliveInterval() (result cm.Result[uint64, Duration, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval -//go:noescape -func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint64, monotonicclock.Duration, network.ErrorCode]) - // LocalAddress represents the imported method "local-address". // // Get the bound local address. @@ -371,16 +363,12 @@ func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.Result[uint6 // local-address: func() -> result // //go:nosplit -func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { +func (self TCPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address -//go:noescape -func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) - // ReceiveBufferSize represents the imported method "receive-buffer-size". // // The kernel buffer space reserved for sends/receives on this socket. @@ -399,16 +387,12 @@ func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // receive-buffer-size: func() -> result // //go:nosplit -func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self TCPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size -//go:noescape -func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // RemoteAddress represents the imported method "remote-address". // // Get the remote address. @@ -425,111 +409,83 @@ func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // remote-address: func() -> result // //go:nosplit -func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { +func (self TCPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address -//go:noescape -func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) - // SendBufferSize represents the imported method "send-buffer-size". // // send-buffer-size: func() -> result // //go:nosplit -func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size -//go:noescape -func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // SetHopLimit represents the imported method "set-hop-limit". // // set-hop-limit: func(value: u8) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetHopLimit(value uint8) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint32)(value) wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit -//go:noescape -func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetKeepAliveCount represents the imported method "set-keep-alive-count". // // set-keep-alive-count: func(value: u32) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint32)(value) wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count -//go:noescape -func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetKeepAliveEnabled represents the imported method "set-keep-alive-enabled". // // set-keep-alive-enabled: func(value: bool) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := cm.BoolToU32(value) wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled -//go:noescape -func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetKeepAliveIdleTime represents the imported method "set-keep-alive-idle-time". // // set-keep-alive-idle-time: func(value: duration) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetKeepAliveIdleTime(value Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time -//go:noescape -func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetKeepAliveInterval represents the imported method "set-keep-alive-interval". // // set-keep-alive-interval: func(value: duration) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetKeepAliveInterval(value Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval -//go:noescape -func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetListenBacklogSize represents the imported method "set-listen-backlog-size". // // Hints the desired listen queue size. Implementations are free to ignore this. @@ -548,49 +504,37 @@ func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, resul // set-listen-backlog-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size -//go:noescape -func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetReceiveBufferSize represents the imported method "set-receive-buffer-size". // // set-receive-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size -//go:noescape -func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetSendBufferSize represents the imported method "set-send-buffer-size". // // set-send-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size -//go:noescape -func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // Shutdown represents the imported method "shutdown". // // Initiate a graceful shutdown. @@ -620,17 +564,13 @@ func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result * // shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) shutdownType0 := (uint32)(shutdownType) wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown -//go:noescape -func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // StartBind represents the imported method "start-bind". // // Bind the socket to a specific network on the provided IP address and port. @@ -685,7 +625,7 @@ func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm // result<_, error-code> // //go:nosplit -func (self TCPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) StartBind(network_ Network, localAddress IPSocketAddress) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) network0 := cm.Reinterpret[uint32](network_) localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) @@ -693,10 +633,6 @@ func (self TCPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind -//go:noescape -func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // StartConnect represents the imported method "start-connect". // // Connect to a remote endpoint. @@ -757,7 +693,7 @@ func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // -> result<_, error-code> // //go:nosplit -func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) StartConnect(network_ Network, remoteAddress IPSocketAddress) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) network0 := cm.Reinterpret[uint32](network_) remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11 := lower_IPSocketAddress(remoteAddress) @@ -765,10 +701,6 @@ func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress netwo return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect -//go:noescape -func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // StartListen represents the imported method "start-listen". // // Start listening for new connections. @@ -803,16 +735,12 @@ func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddre // start-listen: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) StartListen() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self TCPSocket) StartListen() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketStartListen((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen -//go:noescape -func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which can be used to poll for, or block on, @@ -836,13 +764,9 @@ func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.Result[network.Err // subscribe: func() -> pollable // //go:nosplit -func (self TCPSocket) Subscribe() (result poll.Pollable) { +func (self TCPSocket) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } - -//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe -//go:noescape -func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go index e52316f..8afa83d 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -9,6 +9,26 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/udp" ) +// Network represents the imported type alias "wasi:sockets/udp-create-socket@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + +// ErrorCode represents the type alias "wasi:sockets/udp-create-socket@0.2.0#error-code". +// +// See [network.ErrorCode] for more information. +type ErrorCode = network.ErrorCode + +// IPAddressFamily represents the type alias "wasi:sockets/udp-create-socket@0.2.0#ip-address-family". +// +// See [network.IPAddressFamily] for more information. +type IPAddressFamily = network.IPAddressFamily + +// UDPSocket represents the imported type alias "wasi:sockets/udp-create-socket@0.2.0#udp-socket". +// +// See [udp.UDPSocket] for more information. +type UDPSocket = udp.UDPSocket + // CreateUDPSocket represents the imported function "create-udp-socket". // // Create a new UDP socket. @@ -41,12 +61,8 @@ import ( // error-code> // //go:nosplit -func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) { +func CreateUDPSocket(addressFamily IPAddressFamily) (result cm.Result[UDPSocket, UDPSocket, ErrorCode]) { addressFamily0 := (uint32)(addressFamily) wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) return } - -//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket -//go:noescape -func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[udp.UDPSocket, udp.UDPSocket, network.ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udpcreatesocket.wasm.go b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udpcreatesocket.wasm.go new file mode 100755 index 0000000..5ff3a71 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udpcreatesocket.wasm.go @@ -0,0 +1,13 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package udpcreatesocket + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket +//go:noescape +func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.Result[UDPSocket, UDPSocket, ErrorCode]) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go index 6d5e282..b415bb1 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -10,6 +10,7 @@ import ( // IPSocketAddressShape is used for storage in variant or result types. type IPSocketAddressShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(network.IPSocketAddress{})]byte } @@ -76,10 +77,11 @@ func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 // TupleIncomingDatagramStreamOutgoingDatagramStreamShape is used for storage in variant or result types. type TupleIncomingDatagramStreamOutgoingDatagramStreamShape struct { + _ cm.HostLayout shape [unsafe.Sizeof(cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream]{})]byte } -func lower_OptionIPSocketAddress(v cm.Option[network.IPSocketAddress]) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32, f12 uint32) { +func lower_OptionIPSocketAddress(v cm.Option[IPSocketAddress]) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32, f12 uint32) { some := v.Some() if some != nil { f0 = 1 diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go new file mode 100755 index 0000000..ffdb7ed --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go @@ -0,0 +1,93 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package udp + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:sockets@0.2.0". + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket +//go:noescape +func wasmimport_UDPSocketResourceDrop(self0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family +//go:noescape +func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind +//go:noescape +func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address +//go:noescape +func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size +//go:noescape +func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address +//go:noescape +func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size +//go:noescape +func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size +//go:noescape +func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size +//go:noescape +func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind +//go:noescape +func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream +//go:noescape +func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe +//go:noescape +func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit +//go:noescape +func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +//go:noescape +func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +//go:noescape +func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +//go:noescape +func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +//go:noescape +func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +//go:noescape +func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +//go:noescape +func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, ErrorCode]) + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +//go:noescape +func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go index d4a6591..77ba489 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -9,6 +9,31 @@ import ( "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" ) +// Pollable represents the imported type alias "wasi:sockets/udp@0.2.0#pollable". +// +// See [poll.Pollable] for more information. +type Pollable = poll.Pollable + +// Network represents the imported type alias "wasi:sockets/udp@0.2.0#network". +// +// See [network.Network] for more information. +type Network = network.Network + +// ErrorCode represents the type alias "wasi:sockets/udp@0.2.0#error-code". +// +// See [network.ErrorCode] for more information. +type ErrorCode = network.ErrorCode + +// IPSocketAddress represents the type alias "wasi:sockets/udp@0.2.0#ip-socket-address". +// +// See [network.IPSocketAddress] for more information. +type IPSocketAddress = network.IPSocketAddress + +// IPAddressFamily represents the type alias "wasi:sockets/udp@0.2.0#ip-address-family". +// +// See [network.IPAddressFamily] for more information. +type IPAddressFamily = network.IPAddressFamily + // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". // // A received datagram. @@ -18,6 +43,7 @@ import ( // remote-address: ip-socket-address, // } type IncomingDatagram struct { + _ cm.HostLayout // The payload. // // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. @@ -29,7 +55,7 @@ type IncomingDatagram struct { // with, if any. // // Equivalent to the `src_addr` out parameter of `recvfrom`. - RemoteAddress network.IPSocketAddress + RemoteAddress IPSocketAddress } // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". @@ -41,6 +67,7 @@ type IncomingDatagram struct { // remote-address: option, // } type OutgoingDatagram struct { + _ cm.HostLayout // The payload. Data cm.List[uint8] @@ -53,7 +80,7 @@ type OutgoingDatagram struct { // // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise // it is equivalent to `sendto`. - RemoteAddress cm.Option[network.IPSocketAddress] + RemoteAddress cm.Option[IPSocketAddress] } // UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". @@ -74,10 +101,6 @@ func (self UDPSocket) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket -//go:noescape -func wasmimport_UDPSocketResourceDrop(self0 uint32) - // AddressFamily represents the imported method "address-family". // // Whether this is a IPv4 or IPv6 socket. @@ -87,32 +110,24 @@ func wasmimport_UDPSocketResourceDrop(self0 uint32) // address-family: func() -> ip-address-family // //go:nosplit -func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { +func (self UDPSocket) AddressFamily() (result IPAddressFamily) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) result = (network.IPAddressFamily)((uint32)(result0)) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family -//go:noescape -func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) - // FinishBind represents the imported method "finish-bind". // // finish-bind: func() -> result<_, error-code> // //go:nosplit -func (self UDPSocket) FinishBind() (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self UDPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketFinishBind((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind -//go:noescape -func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // LocalAddress represents the imported method "local-address". // // Get the current bound address. @@ -136,16 +151,12 @@ func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.Result[network.Erro // local-address: func() -> result // //go:nosplit -func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { +func (self UDPSocket) LocalAddress() (result cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address -//go:noescape -func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) - // ReceiveBufferSize represents the imported method "receive-buffer-size". // // The kernel buffer space reserved for sends/receives on this socket. @@ -164,16 +175,12 @@ func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.Result[IPSocketAd // receive-buffer-size: func() -> result // //go:nosplit -func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self UDPSocket) ReceiveBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size -//go:noescape -func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // RemoteAddress represents the imported method "remote-address". // // Get the address the socket is currently streaming to. @@ -190,79 +197,59 @@ func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.Result[uint6 // remote-address: func() -> result // //go:nosplit -func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) { +func (self UDPSocket) RemoteAddress() (result cm.Result[IPSocketAddressShape, IPSocketAddress, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address -//go:noescape -func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.Result[IPSocketAddressShape, network.IPSocketAddress, network.ErrorCode]) - // SendBufferSize represents the imported method "send-buffer-size". // // send-buffer-size: func() -> result // //go:nosplit -func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size -//go:noescape -func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // SetReceiveBufferSize represents the imported method "set-receive-buffer-size". // // set-receive-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size -//go:noescape -func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetSendBufferSize represents the imported method "set-send-buffer-size". // // set-send-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint64)(value) wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size -//go:noescape -func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // SetUnicastHopLimit represents the imported method "set-unicast-hop-limit". // // set-unicast-hop-limit: func(value: u8) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) value0 := (uint32)(value) wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit -//go:noescape -func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // StartBind represents the imported method "start-bind". // // Bind the socket to a specific network on the provided IP address and port. @@ -301,7 +288,7 @@ func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result // result<_, error-code> // //go:nosplit -func (self UDPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) { +func (self UDPSocket) StartBind(network_ Network, localAddress IPSocketAddress) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) network0 := cm.Reinterpret[uint32](network_) localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) @@ -309,10 +296,6 @@ func (self UDPSocket) StartBind(network_ network.Network, localAddress network.I return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind -//go:noescape -func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.Result[network.ErrorCode, struct{}, network.ErrorCode]) - // Stream represents the imported method "stream". // // Set up inbound & outbound communication channels, optionally to a specific peer. @@ -370,17 +353,13 @@ func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 // outgoing-datagram-stream>, error-code> // //go:nosplit -func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) (result cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) { +func (self UDPSocket) Stream(remoteAddress cm.Option[IPSocketAddress]) (result cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode]) { self0 := cm.Reinterpret[uint32](self) remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11, remoteAddress12 := lower_OptionIPSocketAddress(remoteAddress) wasmimport_UDPSocketStream((uint32)(self0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), (uint32)(remoteAddress12), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream -//go:noescape -func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the socket is ready for I/O. @@ -391,17 +370,13 @@ func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddre // subscribe: func() -> pollable // //go:nosplit -func (self UDPSocket) Subscribe() (result poll.Pollable) { +func (self UDPSocket) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe -//go:noescape -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. @@ -414,16 +389,12 @@ func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) // unicast-hop-limit: func() -> result // //go:nosplit -func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, network.ErrorCode]) { +func (self UDPSocket) UnicastHopLimit() (result cm.Result[uint8, uint8, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit -//go:noescape -func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.Result[uint8, uint8, network.ErrorCode]) - // IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". // // resource incoming-datagram-stream @@ -440,10 +411,6 @@ func (self IncomingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream -//go:noescape -func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) - // Receive represents the imported method "receive". // // Receive messages on the socket. @@ -475,17 +442,13 @@ func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) // receive: func(max-results: u64) -> result, error-code> // //go:nosplit -func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) { +func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], ErrorCode]) { self0 := cm.Reinterpret[uint32](self) maxResults0 := (uint64)(maxResults) wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive -//go:noescape -func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.Result[cm.List[IncomingDatagram], cm.List[IncomingDatagram], network.ErrorCode]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the stream is ready to receive again. @@ -496,17 +459,13 @@ func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, // subscribe: func() -> pollable // //go:nosplit -func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { +func (self IncomingDatagramStream) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe -//go:noescape -func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) - // OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". // // resource outgoing-datagram-stream @@ -523,10 +482,6 @@ func (self OutgoingDatagramStream) ResourceDrop() { return } -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream -//go:noescape -func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) - // CheckSend represents the imported method "check-send". // // Check readiness for sending. This function never blocks. @@ -544,16 +499,12 @@ func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) // check-send: func() -> result // //go:nosplit -func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self OutgoingDatagramStream) CheckSend() (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send -//go:noescape -func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // Send represents the imported method "send". // // Send messages on the socket. @@ -608,17 +559,13 @@ func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.Result[ // send: func(datagrams: list) -> result // //go:nosplit -func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (result cm.Result[uint64, uint64, network.ErrorCode]) { +func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (result cm.Result[uint64, uint64, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) datagrams0, datagrams1 := cm.LowerList(datagrams) wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) return } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send -//go:noescape -func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.Result[uint64, uint64, network.ErrorCode]) - // Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the stream is ready to send again. @@ -629,13 +576,9 @@ func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDat // subscribe: func() -> pollable // //go:nosplit -func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { +func (self OutgoingDatagramStream) Subscribe() (result Pollable) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) return } - -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe -//go:noescape -func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32)