From d7c7c4f7bd08e9146919ca6eca72fb3c214403e6 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Sun, 1 Sep 2024 06:58:46 +0530 Subject: [PATCH 01/22] feat(sdk): add support for http trigger with wasip2 support Signed-off-by: Rajat Jindal --- .github/workflows/pr.yaml | 32 + Makefile | 4 + v2/README.md | 13 + v2/examples/http/go.mod | 12 + v2/examples/http/go.sum | 4 + v2/examples/http/main.go | 22 + v2/examples/http/spin.toml | 16 + v2/go.mod | 8 + 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 | 98 + v2/http/streams.go | 45 + v2/http/testdata/http-tinygo/go.mod | 12 + v2/http/testdata/http-tinygo/go.sum | 4 + v2/http/testdata/http-tinygo/main.go | 23 + v2/http/testdata/http-tinygo/spin.toml | 16 + v2/integration_test.go | 152 + v2/internal/fermyon/spin/config/abi.go | 14 + .../fermyon/spin/config/config.wasm.go | 13 + v2/internal/fermyon/spin/config/config.wit.go | 84 + v2/internal/fermyon/spin/config/empty.s | 3 + .../spin/http-trigger/http-trigger.wit | 442 +++ .../spin/http-trigger/http-trigger.wit.go | 4 + .../fermyon/spin/http-types/http-types.wit.go | 138 + v2/internal/fermyon/spin/http/abi.go | 35 + v2/internal/fermyon/spin/http/empty.s | 3 + v2/internal/fermyon/spin/http/http.wasm.go | 13 + v2/internal/fermyon/spin/http/http.wit.go | 35 + 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 | 11 + .../spin/inbound-http/inbound-http.wit.go | 18 + .../spin/inbound-http/inboundhttp.wasm.go | 14 + v2/internal/fermyon/spin/key-value/abi.go | 14 + v2/internal/fermyon/spin/key-value/empty.s | 3 + .../fermyon/spin/key-value/key-value.wit.go | 250 ++ .../fermyon/spin/key-value/keyvalue.wasm.go | 37 + v2/internal/fermyon/spin/llm/abi.go | 45 + v2/internal/fermyon/spin/llm/empty.s | 3 + v2/internal/fermyon/spin/llm/llm.wasm.go | 17 + v2/internal/fermyon/spin/llm/llm.wit.go | 209 ++ v2/internal/fermyon/spin/mysql/abi.go | 15 + v2/internal/fermyon/spin/mysql/empty.s | 3 + v2/internal/fermyon/spin/mysql/mysql.wasm.go | 17 + v2/internal/fermyon/spin/mysql/mysql.wit.go | 140 + v2/internal/fermyon/spin/postgres/abi.go | 21 + v2/internal/fermyon/spin/postgres/empty.s | 3 + .../fermyon/spin/postgres/postgres.wasm.go | 17 + .../fermyon/spin/postgres/postgres.wit.go | 140 + .../spin/rdbms-types/rdbms-types.wit.go | 475 +++ .../spin/redis-types/redis-types.wit.go | 145 + v2/internal/fermyon/spin/redis/empty.s | 3 + v2/internal/fermyon/spin/redis/redis.wasm.go | 46 + v2/internal/fermyon/spin/redis/redis.wit.go | 167 + v2/internal/fermyon/spin/sqlite/abi.go | 20 + v2/internal/fermyon/spin/sqlite/empty.s | 3 + .../fermyon/spin/sqlite/sqlite.wasm.go | 21 + v2/internal/fermyon/spin/sqlite/sqlite.wit.go | 256 ++ .../spin/v2.0.0/http-trigger/http-trigger.wit | 3121 +++++++++++++++++ .../v2.0.0/http-trigger/http-trigger.wit.go | 6 + .../fermyon/spin/v2.0.0/key-value/abi.go | 20 + .../fermyon/spin/v2.0.0/key-value/empty.s | 3 + .../spin/v2.0.0/key-value/key-value.wit.go | 194 + .../spin/v2.0.0/key-value/keyvalue.wasm.go | 37 + v2/internal/fermyon/spin/v2.0.0/llm/abi.go | 45 + v2/internal/fermyon/spin/v2.0.0/llm/empty.s | 3 + .../fermyon/spin/v2.0.0/llm/llm.wasm.go | 17 + .../fermyon/spin/v2.0.0/llm/llm.wit.go | 209 ++ v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 14 + v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s | 3 + .../fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go | 21 + .../fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 166 + v2/internal/fermyon/spin/v2.0.0/mysql/abi.go | 21 + v2/internal/fermyon/spin/v2.0.0/mysql/empty.s | 3 + .../fermyon/spin/v2.0.0/mysql/mysql.wasm.go | 25 + .../fermyon/spin/v2.0.0/mysql/mysql.wit.go | 86 + .../fermyon/spin/v2.0.0/postgres/abi.go | 21 + .../fermyon/spin/v2.0.0/postgres/empty.s | 3 + .../spin/v2.0.0/postgres/postgres.wasm.go | 25 + .../spin/v2.0.0/postgres/postgres.wit.go | 87 + .../v2.0.0/rdbms-types/rdbms-types.wit.go | 563 +++ v2/internal/fermyon/spin/v2.0.0/redis/abi.go | 20 + v2/internal/fermyon/spin/v2.0.0/redis/empty.s | 3 + .../fermyon/spin/v2.0.0/redis/redis.wasm.go | 53 + .../fermyon/spin/v2.0.0/redis/redis.wit.go | 366 ++ v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go | 20 + .../fermyon/spin/v2.0.0/sqlite/empty.s | 3 + .../fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go | 21 + .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 256 ++ .../fermyon/spin/v2.0.0/variables/abi.go | 14 + .../fermyon/spin/v2.0.0/variables/empty.s | 3 + .../spin/v2.0.0/variables/variables.wasm.go | 13 + .../spin/v2.0.0/variables/variables.wit.go | 95 + .../wasi/cli/v0.2.0/environment/empty.s | 3 + .../v0.2.0/environment/environment.wasm.go | 21 + .../cli/v0.2.0/environment/environment.wit.go | 52 + v2/internal/wasi/cli/v0.2.0/exit/empty.s | 3 + v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go | 9 + v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 21 + v2/internal/wasi/cli/v0.2.0/stderr/empty.s | 3 + .../wasi/cli/v0.2.0/stderr/stderr.wasm.go | 9 + .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 25 + v2/internal/wasi/cli/v0.2.0/stdin/empty.s | 3 + .../wasi/cli/v0.2.0/stdin/stdin.wasm.go | 9 + .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 25 + v2/internal/wasi/cli/v0.2.0/stdout/empty.s | 3 + .../wasi/cli/v0.2.0/stdout/stdout.wasm.go | 9 + .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 25 + .../wasi/cli/v0.2.0/terminal-input/empty.s | 3 + .../terminal-input/terminal-input.wit.go | 32 + .../terminal-input/terminalinput.wasm.go | 9 + .../wasi/cli/v0.2.0/terminal-output/empty.s | 3 + .../terminal-output/terminal-output.wit.go | 32 + .../terminal-output/terminaloutput.wasm.go | 9 + .../wasi/cli/v0.2.0/terminal-stderr/empty.s | 3 + .../terminal-stderr/terminal-stderr.wit.go | 30 + .../terminal-stderr/terminalstderr.wasm.go | 13 + .../wasi/cli/v0.2.0/terminal-stdin/empty.s | 3 + .../terminal-stdin/terminal-stdin.wit.go | 30 + .../terminal-stdin/terminalstdin.wasm.go | 13 + .../wasi/cli/v0.2.0/terminal-stdout/empty.s | 3 + .../terminal-stdout/terminal-stdout.wit.go | 30 + .../terminal-stdout/terminalstdout.wasm.go | 13 + .../clocks/v0.2.0/monotonic-clock/empty.s | 3 + .../monotonic-clock/monotonic-clock.wit.go | 102 + .../monotonic-clock/monotonicclock.wasm.go | 21 + .../wasi/clocks/v0.2.0/wall-clock/empty.s | 3 + .../v0.2.0/wall-clock/wall-clock.wit.go | 75 + .../v0.2.0/wall-clock/wallclock.wasm.go | 13 + .../wasi/filesystem/v0.2.0/preopens/empty.s | 3 + .../v0.2.0/preopens/preopens.wasm.go | 13 + .../v0.2.0/preopens/preopens.wit.go | 26 + .../wasi/filesystem/v0.2.0/types/abi.go | 50 + .../wasi/filesystem/v0.2.0/types/empty.s | 3 + .../filesystem/v0.2.0/types/types.wasm.go | 133 + .../wasi/filesystem/v0.2.0/types/types.wit.go | 1266 +++++++ .../wasi/http/v0.2.0/incoming-handler/empty.s | 3 + .../incoming-handler.exports.go | 22 + .../incoming-handler/incoming-handler.wit.go | 21 + .../incoming-handler/incominghandler.wasm.go | 18 + .../wasi/http/v0.2.0/outgoing-handler/abi.go | 25 + .../wasi/http/v0.2.0/outgoing-handler/empty.s | 3 + .../outgoing-handler/outgoing-handler.wit.go | 56 + .../outgoing-handler/outgoinghandler.wasm.go | 13 + v2/internal/wasi/http/v0.2.0/types/abi.go | 264 ++ v2/internal/wasi/http/v0.2.0/types/empty.s | 3 + .../wasi/http/v0.2.0/types/types.wasm.go | 257 ++ .../wasi/http/v0.2.0/types/types.wit.go | 2007 +++++++++++ v2/internal/wasi/io/v0.2.0/error/empty.s | 3 + v2/internal/wasi/io/v0.2.0/error/error.wit.go | 63 + .../wasi/io/v0.2.0/error/ioerror.wasm.go | 13 + v2/internal/wasi/io/v0.2.0/poll/empty.s | 3 + v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go | 25 + v2/internal/wasi/io/v0.2.0/poll/poll.wit.go | 92 + v2/internal/wasi/io/v0.2.0/streams/empty.s | 3 + .../wasi/io/v0.2.0/streams/streams.wasm.go | 77 + .../wasi/io/v0.2.0/streams/streams.wit.go | 471 +++ .../wasi/random/v0.2.0/insecure-seed/empty.s | 3 + .../v0.2.0/insecure-seed/insecure-seed.wit.go | 37 + .../v0.2.0/insecure-seed/insecureseed.wasm.go | 9 + .../wasi/random/v0.2.0/insecure/empty.s | 3 + .../random/v0.2.0/insecure/insecure.wasm.go | 17 + .../random/v0.2.0/insecure/insecure.wit.go | 49 + v2/internal/wasi/random/v0.2.0/random/empty.s | 3 + .../wasi/random/v0.2.0/random/random.wasm.go | 17 + .../wasi/random/v0.2.0/random/random.wit.go | 53 + .../sockets/v0.2.0/instance-network/empty.s | 3 + .../instance-network/instance-network.wit.go | 29 + .../instance-network/instancenetwork.wasm.go | 9 + .../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 | 125 + .../ip-name-lookup/ipnamelookup.wasm.go | 25 + .../wasi/sockets/v0.2.0/network/abi.go | 14 + .../wasi/sockets/v0.2.0/network/empty.s | 3 + .../sockets/v0.2.0/network/network.wasm.go | 9 + .../sockets/v0.2.0/network/network.wit.go | 333 ++ .../sockets/v0.2.0/tcp-create-socket/empty.s | 3 + .../tcp-create-socket.wit.go | 68 + .../tcp-create-socket/tcpcreatesocket.wasm.go | 13 + v2/internal/wasi/sockets/v0.2.0/tcp/abi.go | 88 + v2/internal/wasi/sockets/v0.2.0/tcp/empty.s | 3 + .../wasi/sockets/v0.2.0/tcp/tcp.wasm.go | 125 + .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 772 ++++ .../sockets/v0.2.0/udp-create-socket/empty.s | 3 + .../udp-create-socket.wit.go | 68 + .../udp-create-socket/udpcreatesocket.wasm.go | 13 + v2/internal/wasi/sockets/v0.2.0/udp/abi.go | 103 + v2/internal/wasi/sockets/v0.2.0/udp/empty.s | 3 + .../wasi/sockets/v0.2.0/udp/udp.wasm.go | 93 + .../wasi/sockets/v0.2.0/udp/udp.wit.go | 584 +++ 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/wit.go | 6 + v2/wit/world.wit | 41 + 316 files changed, 26692 insertions(+) create mode 100644 .github/workflows/pr.yaml create mode 100644 v2/README.md 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.mod 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/http/testdata/http-tinygo/go.mod create mode 100644 v2/http/testdata/http-tinygo/go.sum create mode 100644 v2/http/testdata/http-tinygo/main.go create mode 100644 v2/http/testdata/http-tinygo/spin.toml create mode 100644 v2/integration_test.go create mode 100755 v2/internal/fermyon/spin/config/abi.go create mode 100755 v2/internal/fermyon/spin/config/config.wasm.go create mode 100755 v2/internal/fermyon/spin/config/config.wit.go create mode 100755 v2/internal/fermyon/spin/config/empty.s create mode 100755 v2/internal/fermyon/spin/http-trigger/http-trigger.wit create mode 100755 v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go create mode 100755 v2/internal/fermyon/spin/http-types/http-types.wit.go create mode 100755 v2/internal/fermyon/spin/http/abi.go create mode 100755 v2/internal/fermyon/spin/http/empty.s create mode 100755 v2/internal/fermyon/spin/http/http.wasm.go create mode 100755 v2/internal/fermyon/spin/http/http.wit.go create mode 100755 v2/internal/fermyon/spin/inbound-http/abi.go create mode 100755 v2/internal/fermyon/spin/inbound-http/empty.s create mode 100755 v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go create mode 100755 v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go create mode 100755 v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go create mode 100755 v2/internal/fermyon/spin/key-value/abi.go create mode 100755 v2/internal/fermyon/spin/key-value/empty.s create mode 100755 v2/internal/fermyon/spin/key-value/key-value.wit.go create mode 100755 v2/internal/fermyon/spin/key-value/keyvalue.wasm.go create mode 100755 v2/internal/fermyon/spin/llm/abi.go create mode 100755 v2/internal/fermyon/spin/llm/empty.s create mode 100755 v2/internal/fermyon/spin/llm/llm.wasm.go create mode 100755 v2/internal/fermyon/spin/llm/llm.wit.go create mode 100755 v2/internal/fermyon/spin/mysql/abi.go create mode 100755 v2/internal/fermyon/spin/mysql/empty.s create mode 100755 v2/internal/fermyon/spin/mysql/mysql.wasm.go create mode 100755 v2/internal/fermyon/spin/mysql/mysql.wit.go create mode 100755 v2/internal/fermyon/spin/postgres/abi.go create mode 100755 v2/internal/fermyon/spin/postgres/empty.s create mode 100755 v2/internal/fermyon/spin/postgres/postgres.wasm.go create mode 100755 v2/internal/fermyon/spin/postgres/postgres.wit.go create mode 100755 v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go create mode 100755 v2/internal/fermyon/spin/redis-types/redis-types.wit.go create mode 100755 v2/internal/fermyon/spin/redis/empty.s create mode 100755 v2/internal/fermyon/spin/redis/redis.wasm.go create mode 100755 v2/internal/fermyon/spin/redis/redis.wit.go create mode 100755 v2/internal/fermyon/spin/sqlite/abi.go create mode 100755 v2/internal/fermyon/spin/sqlite/empty.s create mode 100755 v2/internal/fermyon/spin/sqlite/sqlite.wasm.go create mode 100755 v2/internal/fermyon/spin/sqlite/sqlite.wit.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/http-trigger/http-trigger.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/key-value/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/key-value/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go 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/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/llm/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mysql/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mysql/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/postgres/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/postgres/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/redis/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/redis/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/variables/abi.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/variables/empty.s create mode 100755 v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go create mode 100755 v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/environment/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/exit/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stderr/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdin/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdout/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go create mode 100755 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.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/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.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/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.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/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.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/empty.s create mode 100755 v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.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/empty.s create mode 100755 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.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/empty.s create mode 100755 v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.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/empty.s create mode 100755 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/types/abi.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/types/empty.s create mode 100755 v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go create mode 100755 v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go create mode 100755 v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s create mode 100755 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go create mode 100755 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.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/abi.go create mode 100755 v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s create mode 100755 v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.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/abi.go create mode 100755 v2/internal/wasi/http/v0.2.0/types/empty.s create mode 100755 v2/internal/wasi/http/v0.2.0/types/types.wasm.go create mode 100755 v2/internal/wasi/http/v0.2.0/types/types.wit.go create mode 100755 v2/internal/wasi/io/v0.2.0/error/empty.s create mode 100755 v2/internal/wasi/io/v0.2.0/error/error.wit.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/empty.s create mode 100755 v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go create mode 100755 v2/internal/wasi/io/v0.2.0/poll/poll.wit.go create mode 100755 v2/internal/wasi/io/v0.2.0/streams/empty.s create mode 100755 v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go create mode 100755 v2/internal/wasi/io/v0.2.0/streams/streams.wit.go create mode 100755 v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s create mode 100755 v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.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/empty.s create mode 100755 v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go create mode 100755 v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go create mode 100755 v2/internal/wasi/random/v0.2.0/random/empty.s create mode 100755 v2/internal/wasi/random/v0.2.0/random/random.wasm.go create mode 100755 v2/internal/wasi/random/v0.2.0/random/random.wit.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.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/abi.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.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/abi.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/network/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/network/network.wit.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.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/abi.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.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/abi.go create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp/empty.s create mode 100755 v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go create mode 100755 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/wit.go create mode 100644 v2/wit/world.wit diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 00000000..ad174d91 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,32 @@ +name: Run Integration tests +on: + push: + branches: + - wasip2-http + + workflow_dispatch: {} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + + - name: Setup TinyGo + uses: acifani/setup-tinygo@v2 + with: + tinygo-version: '0.33.0' + + - name: Setup Spin + uses: fermyon/actions/spin/setup@v1 + with: + version: "v2.7.0" + + - name: Run wasip2 integration tests + run: make test-integration-wasip2 + diff --git a/Makefile b/Makefile index 613e0c0b..e82a2b18 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,10 @@ test: test-integration test-integration: http/testdata/http-tinygo/main.wasm go test -v -count=1 . +.PHONY: test-integration-wasip2 +test-integration-wasip2: + cd v2 && go test -v -count=1 . + http/testdata/http-tinygo/main.wasm: generate http/testdata/http-tinygo/main.wasm: http/testdata/http-tinygo/main.go tinygo build -target=wasi -gc=leaking -no-debug -o http/testdata/http-tinygo/main.wasm http/testdata/http-tinygo/main.go diff --git a/v2/README.md b/v2/README.md new file mode 100644 index 00000000..5b333a9c --- /dev/null +++ b/v2/README.md @@ -0,0 +1,13 @@ +WIP + +spin-go-sdk with wasip2 support + +Notes: + +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)` +- 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 00000000..225c227f --- /dev/null +++ b/v2/examples/http/go.mod @@ -0,0 +1,12 @@ +module github.com/fermyon/spin-go-sdk/v2/examples/http + +go 1.23.2 + +require github.com/fermyon/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org v0.4.0 // 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 00000000..0c8b9316 --- /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= +go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= +go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= diff --git a/v2/examples/http/main.go b/v2/examples/http/main.go new file mode 100644 index 00000000..9d88dcd9 --- /dev/null +++ b/v2/examples/http/main.go @@ -0,0 +1,22 @@ +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") + + 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 00000000..00625c4a --- /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 new file mode 100644 index 00000000..93fb5c5c --- /dev/null +++ b/v2/go.mod @@ -0,0 +1,8 @@ +module github.com/fermyon/spin-go-sdk/v2 + +go 1.23.2 + +require ( + github.com/julienschmidt/httprouter v1.3.0 + go.bytecodealliance.org v0.4.0 +) diff --git a/v2/go.sum b/v2/go.sum new file mode 100644 index 00000000..0c8b9316 --- /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= +go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= +go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= diff --git a/v2/http/client.go b/v2/http/client.go new file mode 100644 index 00000000..46f9ac04 --- /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" + "go.bytecodealliance.org/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 00000000..cc7465ad --- /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" + "go.bytecodealliance.org/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 00000000..cb4747de --- /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" + "go.bytecodealliance.org/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 00000000..55483295 --- /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" + "go.bytecodealliance.org/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 00000000..7ac5d5de --- /dev/null +++ b/v2/http/http.go @@ -0,0 +1,98 @@ +// 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" +) + +// 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 00000000..5ec82107 --- /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/http/testdata/http-tinygo/go.mod b/v2/http/testdata/http-tinygo/go.mod new file mode 100644 index 00000000..06e45c38 --- /dev/null +++ b/v2/http/testdata/http-tinygo/go.mod @@ -0,0 +1,12 @@ +module github.com/fermyon/spin-go-sdk/v2/http/testdata/http + +go 1.23.2 + +require github.com/fermyon/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org v0.4.0 // indirect +) + +replace github.com/fermyon/spin-go-sdk/v2 => ../../../ diff --git a/v2/http/testdata/http-tinygo/go.sum b/v2/http/testdata/http-tinygo/go.sum new file mode 100644 index 00000000..0c8b9316 --- /dev/null +++ b/v2/http/testdata/http-tinygo/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= +go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= +go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= diff --git a/v2/http/testdata/http-tinygo/main.go b/v2/http/testdata/http-tinygo/main.go new file mode 100644 index 00000000..e0c267f2 --- /dev/null +++ b/v2/http/testdata/http-tinygo/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/http/testdata/http-tinygo/spin.toml b/v2/http/testdata/http-tinygo/spin.toml new file mode 100644 index 00000000..00625c4a --- /dev/null +++ b/v2/http/testdata/http-tinygo/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/integration_test.go b/v2/integration_test.go new file mode 100644 index 00000000..6eb9a70f --- /dev/null +++ b/v2/integration_test.go @@ -0,0 +1,152 @@ +package http + +import ( + "bytes" + "context" + "fmt" + "io" + "net" + "net/http" + "os" + "os/exec" + "path/filepath" + "testing" + "time" +) + +const spinBinary = "spin" + +func retryGet(t *testing.T, url string) *http.Response { + t.Helper() + + const maxTries = 600 // (10min) + for i := 1; i < maxTries; i++ { + // Catch call to `Fail` in other goroutine + if t.Failed() { + t.FailNow() + } + if res, err := http.Get(url); err != nil { + t.Log(err) + } else { + return res + } + time.Sleep(1 * time.Second) + } + t.Fatal("Get request timeout: ", url) + return nil +} + +type testSpin struct { + cancel func() + url string + cmd *exec.Cmd +} + +func startSpin(t *testing.T, dir string) *testSpin { + buildApp(t, dir) + + url := getFreePort(t) + + // long timeout because... ci + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + + cmd := exec.CommandContext(ctx, spinBinary, "up", "--listen", url) + cmd.Dir = dir + stderr := new(bytes.Buffer) + cmd.Stderr = stderr + if err := cmd.Start(); err != nil { + t.Log(stderr.String()) + t.Fatal(err) + } + + go func() { + _ = cmd.Wait() + if ctx.Err() == nil { + t.Log("spin exited before the test finished:", cmd.ProcessState) + t.Log("stderr:\n", stderr.String()) + t.Fail() + } + }() + + return &testSpin{ + cancel: cancel, + url: fmt.Sprintf("http://%s", url), + cmd: cmd, + } +} + +func buildApp(t *testing.T, dir string) { + t.Helper() + + t.Log("building application:", dir) + + cmd := exec.Command(spinBinary, "build") + cmd.Dir = dir + + stderr := new(bytes.Buffer) + cmd.Stderr = stderr + if err := cmd.Run(); err != nil { + t.Log(stderr.String()) + t.Errorf("Failed to build %q, %v", dir, err) + } +} + +func TestHTTPTriger(t *testing.T) { + spin := startSpin(t, "http/testdata/http-tinygo") + defer spin.cancel() + + resp := retryGet(t, spin.url+"/hello") + spin.cancel() + if resp.Body == nil { + t.Fatal("body is nil") + } + t.Log(resp.Status) + b, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + t.Fatal(err) + } + + // assert response body + want := "== RESPONSE ==\nHello Fermyon!\nHello again Fermyon!\n" + got := string(b) + if want != got { + t.Fatalf("body is not equal: want = %q got = %q", want, got) + } + + // assert response header + if resp.Header.Get("foo") != "bar" { + t.Fatal("header 'foo' was not set") + } +} + +// TestBuildExamples ensures that the tinygo examples will build successfully. +func TestBuildExamples(t *testing.T) { + examples, err := os.ReadDir("examples") + if err != nil { + t.Fatal(err) + } + for _, example := range examples { + example := example + t.Run(example.Name(), func(t *testing.T) { + t.Parallel() + buildApp(t, filepath.Join("examples", example.Name())) + }) + } +} + +func getFreePort(t *testing.T) string { + t.Helper() + + a, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal("failed to get free port: ", err) + } + + l, err := net.ListenTCP("tcp", a) + if err != nil { + t.Fatal("failed to get free port: ", err) + } + l.Close() + return l.Addr().String() +} diff --git a/v2/internal/fermyon/spin/config/abi.go b/v2/internal/fermyon/spin/config/abi.go new file mode 100755 index 00000000..9f91b71e --- /dev/null +++ b/v2/internal/fermyon/spin/config/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package config + +import ( + "go.bytecodealliance.org/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 00000000..82a2db72 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..71602b0e --- /dev/null +++ b/v2/internal/fermyon/spin/config/config.wit.go @@ -0,0 +1,84 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package config represents the imported interface "fermyon:spin/config". +package config + +import ( + "go.bytecodealliance.org/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) +} + +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. +// 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 +} diff --git a/v2/internal/fermyon/spin/config/empty.s b/v2/internal/fermyon/spin/config/empty.s new file mode 100755 index 00000000..5444f200 --- /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 b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit new file mode 100755 index 00000000..82dc634a --- /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-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go new file mode 100755 index 00000000..258da3cc --- /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 100755 index 00000000..b043ad92 --- /dev/null +++ b/v2/internal/fermyon/spin/http-types/http-types.wit.go @@ -0,0 +1,138 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package httptypes represents the imported interface "fermyon:spin/http-types". +package httptypes + +import ( + "go.bytecodealliance.org/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 { + _ cm.HostLayout + 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 { + _ cm.HostLayout + 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 100755 index 00000000..2b234b40 --- /dev/null +++ b/v2/internal/fermyon/spin/http/abi.go @@ -0,0 +1,35 @@ +// 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" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// ResponseShape is used for storage in variant or result types. +type ResponseShape struct { + _ cm.HostLayout + 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/http/http.wasm.go new file mode 100755 index 00000000..89f8e2a0 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..36676913 --- /dev/null +++ b/v2/internal/fermyon/spin/http/http.wit.go @@ -0,0 +1,35 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 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 +} diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v2/internal/fermyon/spin/inbound-http/abi.go new file mode 100755 index 00000000..92759dba --- /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" + "go.bytecodealliance.org/cm" +) + +func lift_OptionBody(f0 uint32, f1 *uint8, f2 uint32) (v cm.Option[httptypes.Body]) { + if f0 == 0 { + return + } + 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) { + 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..059257b8 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go @@ -0,0 +1,11 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package inboundhttp + +// 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 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 new file mode 100755 index 00000000..c952be21 --- /dev/null +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go @@ -0,0 +1,18 @@ +// 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" +) + +// 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 00000000..09ece433 --- /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 new file mode 100755 index 00000000..ab3e6c1e --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/fermyon/spin/key-value/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..1eec8f77 --- /dev/null +++ b/v2/internal/fermyon/spin/key-value/key-value.wit.go @@ -0,0 +1,250 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package keyvalue represents the imported interface "fermyon:spin/key-value". +package keyvalue + +import ( + "go.bytecodealliance.org/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) +} + +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. +// +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} 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 00000000..f49914bf --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..f9a3c279 --- /dev/null +++ b/v2/internal/fermyon/spin/llm/abi.go @@ -0,0 +1,45 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// InferencingResultShape is used for storage in variant or result types. +type InferencingResultShape struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/llm/llm.wasm.go new file mode 100755 index 00000000..fc5cac72 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..e97b9476 --- /dev/null +++ b/v2/internal/fermyon/spin/llm/llm.wit.go @@ -0,0 +1,209 @@ +// 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 ( + "go.bytecodealliance.org/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 { + _ cm.HostLayout + // 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) +} + +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 +// +// record inferencing-usage { +// prompt-token-count: u32, +// generated-token-count: u32, +// } +type InferencingUsage struct { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 +} + +// 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 +} diff --git a/v2/internal/fermyon/spin/mysql/abi.go b/v2/internal/fermyon/spin/mysql/abi.go new file mode 100755 index 00000000..9577bd93 --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/abi.go @@ -0,0 +1,15 @@ +// 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" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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/mysql/empty.s b/v2/internal/fermyon/spin/mysql/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/mysql/mysql.wasm.go new file mode 100755 index 00000000..4b35da74 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..7ed051fa --- /dev/null +++ b/v2/internal/fermyon/spin/mysql/mysql.wit.go @@ -0,0 +1,140 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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) +} + +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 +// +// query: func(address: string, statement: string, params: list) +// -> result +// +//go:nosplit +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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} diff --git a/v2/internal/fermyon/spin/postgres/abi.go b/v2/internal/fermyon/spin/postgres/abi.go new file mode 100755 index 00000000..3b91361b --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/abi.go @@ -0,0 +1,21 @@ +// 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" + "go.bytecodealliance.org/cm" + "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/empty.s b/v2/internal/fermyon/spin/postgres/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/postgres/postgres.wasm.go new file mode 100755 index 00000000..9606b852 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..2ad2aecb --- /dev/null +++ b/v2/internal/fermyon/spin/postgres/postgres.wit.go @@ -0,0 +1,140 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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) +} + +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 +// +// query: func(address: string, statement: string, params: list) +// -> result +// +//go:nosplit +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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} 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 100755 index 00000000..fd5e5b19 --- /dev/null +++ b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go @@ -0,0 +1,475 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package rdbmstypes represents the imported interface "fermyon:spin/rdbms-types". +package rdbmstypes + +import ( + "go.bytecodealliance.org/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 +} + +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 { +// 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 +} + +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 { +// name: string, +// data-type: db-data-type, +// } +type Column struct { + _ cm.HostLayout + 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 { + _ 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 new file mode 100755 index 00000000..4d35c5d8 --- /dev/null +++ b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go @@ -0,0 +1,145 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package redistypes represents the imported interface "fermyon:spin/redis-types". +package redistypes + +import ( + "go.bytecodealliance.org/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) +} + +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. +// +// 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) +} + +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/empty.s b/v2/internal/fermyon/spin/redis/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/redis/redis.wasm.go new file mode 100755 index 00000000..b5dfc7a5 --- /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 ( + redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" + "go.bytecodealliance.org/cm" +) + +// 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 new file mode 100755 index 00000000..27e5e653 --- /dev/null +++ b/v2/internal/fermyon/spin/redis/redis.wit.go @@ -0,0 +1,167 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// publish: func(address: string, channel: string, payload: payload) -> result<_, +// error> +// +//go:nosplit +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) + wasmimport_Publish((*uint8)(address0), (uint32)(address1), (*uint8)(channel0), (uint32)(channel1), (*uint8)(payload0), (uint32)(payload1), &result) + return +} + +// 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, Payload, Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Get((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// 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 Payload) (result cm.Result[Error, struct{}, 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 +} + +// 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, Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Incr((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// 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, Error]) { + address0, address1 := cm.LowerString(address) + keys0, keys1 := cm.LowerList(keys) + wasmimport_Del((*uint8)(address0), (uint32)(address1), (*string)(keys0), (uint32)(keys1), &result) + return +} + +// 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, 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 +} + +// 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], Error]) { + address0, address1 := cm.LowerString(address) + key0, key1 := cm.LowerString(key) + wasmimport_Smembers((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// 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, 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 +} + +// 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[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), (*RedisParameter)(arguments0), (uint32)(arguments1), &result) + return +} diff --git a/v2/internal/fermyon/spin/sqlite/abi.go b/v2/internal/fermyon/spin/sqlite/abi.go new file mode 100755 index 00000000..3790d14c --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/fermyon/spin/sqlite/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go new file mode 100755 index 00000000..9101eb48 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..00d54d2f --- /dev/null +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go @@ -0,0 +1,256 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package sqlite represents the imported interface "fermyon:spin/sqlite". +package sqlite + +import ( + "go.bytecodealliance.org/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) +} + +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 { +// 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 +} + +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 +// +// record row-result { +// values: list, +// } +type RowResult struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + // 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 +} + +// 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 +} + +// 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 +} 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 00000000..37bed5e2 --- /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/http-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go new file mode 100755 index 00000000..5e2a11f9 --- /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 100755 index 00000000..5dab0880 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package keyvalue + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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/empty.s b/v2/internal/fermyon/spin/v2.0.0/key-value/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..5b83d032 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go @@ -0,0 +1,194 @@ +// 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 ( + "go.bytecodealliance.org/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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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) +} + +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 00000000..d2840431 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..f9a3c279 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go @@ -0,0 +1,45 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package llm + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// InferencingResultShape is used for storage in variant or result types. +type InferencingResultShape struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go new file mode 100755 index 00000000..44caad36 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..9c5582bb --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go @@ -0,0 +1,209 @@ +// 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 ( + "go.bytecodealliance.org/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 { + _ cm.HostLayout + // 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) +} + +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 +// +// record inferencing-usage { +// prompt-token-count: u32, +// generated-token-count: u32, +// } +type InferencingUsage struct { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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 +} + +// 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 +} 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 100755 index 00000000..6dc79b7a --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package mqtt + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go new file mode 100755 index 00000000..beada6f3 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..9c75c603 --- /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 ( + "go.bytecodealliance.org/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) +} + +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 +// +// 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 +} + +// 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 +} + +// 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 +} + +// 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 100755 index 00000000..55ae0b62 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go @@ -0,0 +1,21 @@ +// 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" + "go.bytecodealliance.org/cm" + "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/empty.s b/v2/internal/fermyon/spin/v2.0.0/mysql/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go new file mode 100755 index 00000000..53234f2d --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..6bcf65b5 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go @@ -0,0 +1,86 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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 +} + +// 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, Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} 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 100755 index 00000000..02096128 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go @@ -0,0 +1,21 @@ +// 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" + "go.bytecodealliance.org/cm" + "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/empty.s b/v2/internal/fermyon/spin/v2.0.0/postgres/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go new file mode 100755 index 00000000..74aed046 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..cdd27d58 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go @@ -0,0 +1,87 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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 +} + +// 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, Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} 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 100755 index 00000000..dc0f3c10 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go @@ -0,0 +1,563 @@ +// 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 ( + "go.bytecodealliance.org/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) +} + +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 +// +// 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 +} + +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 +// +// 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 +} + +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 +// +// record column { +// name: string, +// data-type: db-data-type, +// } +type Column struct { + _ cm.HostLayout + 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 { + _ 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 new file mode 100755 index 00000000..3dd97e6d --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package redis + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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/empty.s b/v2/internal/fermyon/spin/v2.0.0/redis/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go new file mode 100755 index 00000000..8a4b6592 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..f75f5cd3 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go @@ -0,0 +1,366 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package redis represents the imported interface "fermyon:spin/redis@2.0.0". +package redis + +import ( + "go.bytecodealliance.org/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) +} + +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 +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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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) +} + +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. +// +// 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) +} + +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 new file mode 100755 index 00000000..3790d14c --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package sqlite + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go new file mode 100755 index 00000000..7d11ad95 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..5a9543ed --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go @@ -0,0 +1,256 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package sqlite represents the imported interface "fermyon:spin/sqlite@2.0.0". +package sqlite + +import ( + "go.bytecodealliance.org/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 +} + +// 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 +} + +// 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 +} + +// 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) +} + +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 +// +// 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 +} + +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 +// +// record row-result { +// values: list, +// } +type RowResult struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + // 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 100755 index 00000000..1e4a7713 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package variables + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/fermyon/spin/v2.0.0/variables/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go new file mode 100755 index 00000000..a0bc1b74 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..ee100691 --- /dev/null +++ b/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go @@ -0,0 +1,95 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package variables represents the imported interface "fermyon:spin/variables@2.0.0". +package variables + +import ( + "go.bytecodealliance.org/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) +} + +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. +// +// 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 +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go new file mode 100755 index 00000000..89bb596b --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..3a3b6247 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go @@ -0,0 +1,52 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package environment represents the imported interface "wasi:cli/environment@0.2.0". +package environment + +import ( + "go.bytecodealliance.org/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 +} + +// 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 +} + +// 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 +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go new file mode 100755 index 00000000..849d5f50 --- /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 new file mode 100755 index 00000000..d38d9432 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package exit represents the imported interface "wasi:cli/exit@0.2.0". +package exit + +import ( + "go.bytecodealliance.org/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 +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go new file mode 100755 index 00000000..462cf172 --- /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 new file mode 100755 index 00000000..18d3e9a0 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -0,0 +1,25 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 OutputStream) { + result0 := wasmimport_GetStderr() + result = cm.Reinterpret[OutputStream]((uint32)(result0)) + return +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go new file mode 100755 index 00000000..374eb253 --- /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 new file mode 100755 index 00000000..8fbf65f0 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -0,0 +1,25 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 InputStream) { + result0 := wasmimport_GetStdin() + result = cm.Reinterpret[InputStream]((uint32)(result0)) + return +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go new file mode 100755 index 00000000..68e4a3da --- /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 new file mode 100755 index 00000000..a0baaa6f --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -0,0 +1,25 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 OutputStream) { + result0 := wasmimport_GetStdout() + result = cm.Reinterpret[OutputStream]((uint32)(result0)) + return +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..fa12e90c --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go @@ -0,0 +1,32 @@ +// 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 ( + "go.bytecodealliance.org/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 +} 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 00000000..1df3794f --- /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/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..199e0cc0 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go @@ -0,0 +1,32 @@ +// 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 ( + "go.bytecodealliance.org/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 +} 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 00000000..fb35fc41 --- /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/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..aac4668e --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -0,0 +1,30 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +// allowing further interaction with it. +// +// get-terminal-stderr: func() -> option +// +//go:nosplit +func GetTerminalStderr() (result cm.Option[TerminalOutput]) { + wasmimport_GetTerminalStderr(&result) + return +} 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 00000000..be9af72f --- /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 ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..6f4137d5 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -0,0 +1,30 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +// allowing further interaction with it. +// +// get-terminal-stdin: func() -> option +// +//go:nosplit +func GetTerminalStdin() (result cm.Option[TerminalInput]) { + wasmimport_GetTerminalStdin(&result) + return +} 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 00000000..e3b3ac61 --- /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 ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..434f95d3 --- /dev/null +++ b/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -0,0 +1,30 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +// allowing further interaction with it. +// +// get-terminal-stdout: func() -> option +// +//go:nosplit +func GetTerminalStdout() (result cm.Option[TerminalOutput]) { + wasmimport_GetTerminalStdout(&result) + return +} 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 00000000..fa750ad9 --- /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 ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..2f124a68 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -0,0 +1,102 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +// 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 +} + +// 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 +} + +// 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 Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeInstant((uint64)(when0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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 Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeDuration((uint64)(when0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} 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 00000000..36a1720a --- /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/empty.s b/v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..2d31e9b4 --- /dev/null +++ b/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go @@ -0,0 +1,75 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". +// +// WASI Wall Clock is a clock API intended to let users query the current +// time. The name "wall" makes an analogy to a "clock on the wall", which +// is not necessarily monotonic as it may be reset. +// +// It is intended to be portable at least between Unix-family platforms and +// Windows. +// +// A wall clock is a clock which measures the date and time according to +// some external reference. +// +// External references may be reset, so this clock is not necessarily +// monotonic, making it unsuitable for measuring elapsed time. +// +// It is intended for reporting the current date and time for humans. +package wallclock + +import ( + "go.bytecodealliance.org/cm" +) + +// DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". +// +// A time and date in seconds plus nanoseconds. +// +// record datetime { +// seconds: u64, +// nanoseconds: u32, +// } +type DateTime struct { + _ cm.HostLayout + Seconds uint64 + Nanoseconds uint32 +} + +// Now represents the imported function "now". +// +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// now: func() -> datetime +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +// +//go:nosplit +func Now() (result DateTime) { + wasmimport_Now(&result) + return +} + +// 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 +} 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 00000000..321ff3f1 --- /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/empty.s b/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go new file mode 100755 index 00000000..1bcd416a --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..fc57b942 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -0,0 +1,26 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// get-directories: func() -> list> +// +//go:nosplit +func GetDirectories() (result cm.List[cm.Tuple[Descriptor, string]]) { + wasmimport_GetDirectories(&result) + return +} 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 100755 index 00000000..81e99e91 --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -0,0 +1,50 @@ +// 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" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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 +} + +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 { + _ 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/empty.s b/v2/internal/wasi/filesystem/v0.2.0/types/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go new file mode 100755 index 00000000..b97dad84 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..50826b3a --- /dev/null +++ b/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -0,0 +1,1266 @@ +// 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" + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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 { + _ cm.HostLayout + // File type. + Type DescriptorType + + // Number of hard links to the file. + LinkCount LinkCount + + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + Size FileSize + + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + DataAccessTimestamp cm.Option[DateTime] + + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + 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[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, DateTime, 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 DateTime) NewTimestamp { + return cm.New[NewTimestamp](2, data) +} + +// 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". +// +// A directory entry. +// +// record directory-entry { +// %type: descriptor-type, +// name: string, +// } +type DirectoryEntry struct { + _ cm.HostLayout + // The type of the file referred to by this directory entry. + 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 { + _ cm.HostLayout + // 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 +} + +// 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 +} + +// 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[OutputStream, OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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[InputStream, InputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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[OutputStream, OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} + +// 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 +} + +// 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 +} + +// 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 Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_FilesystemErrorCode((uint32)(err0), &result) + return +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..673ccb48 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go @@ -0,0 +1,22 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package incominghandler + +// 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 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 new file mode 100755 index 00000000..d4d1e04b --- /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" +) + +// 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 00000000..eae429f3 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..1a61628d --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go @@ -0,0 +1,25 @@ +// 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" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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[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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..e252f626 --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go @@ -0,0 +1,56 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +// 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 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 +} 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 00000000..6b3f3828 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..a7281fac --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/abi.go @@ -0,0 +1,264 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package types + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// OptionFieldSizePayloadShape is used for storage in variant or result types. +type OptionFieldSizePayloadShape struct { + _ cm.HostLayout + 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[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 { + _ cm.HostLayout + 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 +} + +func lower_OptionTrailers(v cm.Option[Trailers]) (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/types/empty.s b/v2/internal/wasi/http/v0.2.0/types/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/http/v0.2.0/types/types.wasm.go new file mode 100755 index 00000000..b025b2af --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..1b9a264f --- /dev/null +++ b/v2/internal/wasi/http/v0.2.0/types/types.wit.go @@ -0,0 +1,2007 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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) +} + +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. +// +// 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) +} + +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: +// +// record DNS-error-payload { +// rcode: option, +// info-code: option, +// } +type DNSErrorPayload struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + 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 { + _ cm.HostLayout + 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) +} + +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 +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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". +// +// 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 +} + +// 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 +} + +// 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 +} + +// 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 Headers) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 Headers) (result OutgoingRequest) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) + result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 Headers) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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[Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) + return +} + +// 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[Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) + return +} + +// 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[Duration]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) + return +} + +// 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[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 +} + +// 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[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 +} + +// 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[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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 Headers) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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[InputStream, InputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingBodyStream((uint32)(self0), &result) + return +} + +// 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 +} + +// 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[Trailers], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], struct{}]]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_FutureTrailersGet((uint32)(self0), &result) + return +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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 +} + +// 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 Headers) (result OutgoingResponse) { + headers0 := cm.Reinterpret[uint32](headers) + result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) + result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) + return +} + +// 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 +} + +// 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 Headers) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) + result = cm.Reinterpret[Headers]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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[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 +} + +// 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[OutputStream, OutputStream, struct{}]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingBodyWrite((uint32)(self0), &result) + return +} + +// 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 +} + +// 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 +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_HTTPErrorCode((uint32)(err0), &result) + return +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..24bad438 --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/error/error.wit.go @@ -0,0 +1,63 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package ioerror represents the imported interface "wasi:io/error@0.2.0". +package ioerror + +import ( + "go.bytecodealliance.org/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 +} + +// 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 +} 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 00000000..e254b5d8 --- /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/empty.s b/v2/internal/wasi/io/v0.2.0/poll/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go new file mode 100755 index 00000000..f7c55c3d --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..0c7973fe --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -0,0 +1,92 @@ +// 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 ( + "go.bytecodealliance.org/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 +} + +// 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 +} + +// 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 +} + +// 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 +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go new file mode 100755 index 00000000..eec56645 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..076408ba --- /dev/null +++ b/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -0,0 +1,471 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// variant stream-error { +// last-operation-failed(error), +// closed, +// } +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 Error) StreamError { + return cm.New[StreamError](0, data) +} + +// 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". +// +// 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 +} + +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. +// +// `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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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 +} + +// 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 +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..6f363673 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go @@ -0,0 +1,37 @@ +// 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 +} 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 00000000..e94356df --- /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/empty.s b/v2/internal/wasi/random/v0.2.0/insecure/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go new file mode 100755 index 00000000..498bfe4a --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..295a1ada --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go @@ -0,0 +1,49 @@ +// 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 ( + "go.bytecodealliance.org/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 +} + +// 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 +} 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/random/v0.2.0/random/random.wasm.go new file mode 100755 index 00000000..9096457b --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..bb90e7e0 --- /dev/null +++ b/v2/internal/wasi/random/v0.2.0/random/random.wit.go @@ -0,0 +1,53 @@ +// 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 ( + "go.bytecodealliance.org/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 +} + +// 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 +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..657fb465 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -0,0 +1,29 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// instance-network: func() -> network +// +//go:nosplit +func InstanceNetwork() (result Network) { + result0 := wasmimport_InstanceNetwork() + result = cm.Reinterpret[Network]((uint32)(result0)) + return +} 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 00000000..eb113e21 --- /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 new file mode 100755 index 00000000..a63f0d01 --- /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 ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// OptionIPAddressShape is used for storage in variant or result types. +type OptionIPAddressShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Option[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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..5cc32084 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -0,0 +1,125 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 +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 +} + +// 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[IPAddress], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) + return +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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, 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 +} 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 00000000..da5fb000 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..a088bd1d --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package network + +import ( + "go.bytecodealliance.org/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/empty.s b/v2/internal/wasi/sockets/v0.2.0/network/empty.s new file mode 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go new file mode 100755 index 00000000..012a79ff --- /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 new file mode 100755 index 00000000..53c2252f --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -0,0 +1,333 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package network represents the imported interface "wasi:sockets/network@0.2.0". +package network + +import ( + "go.bytecodealliance.org/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 +} + +// 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) +} + +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 { +// port: u16, +// address: ipv4-address, +// } +type IPv4SocketAddress struct { + _ cm.HostLayout + // 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 { + _ cm.HostLayout + // 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) +} + +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/empty.s b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s new file mode 100755 index 00000000..5444f200 --- /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 100755 index 00000000..151ab602 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -0,0 +1,68 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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 IPAddressFamily) (result cm.Result[TCPSocket, TCPSocket, ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) + return +} 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 00000000..b7b43155 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..670288cc --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -0,0 +1,88 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package tcp + +import ( + "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// TupleTCPSocketInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleTCPSocketInputStreamOutputStreamShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, InputStream, OutputStream]{})]byte +} + +// TupleInputStreamOutputStreamShape is used for storage in variant or result types. +type TupleInputStreamOutputStreamShape struct { + _ 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 +} + +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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go new file mode 100755 index 00000000..56247525 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..68eabf57 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -0,0 +1,772 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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 { +// 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 +} + +// 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, InputStream, OutputStream], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketAccept((uint32)(self0), &result) + return +} + +// 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 IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishBind((uint32)(self0), &result) + return +} + +// 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[InputStream, OutputStream], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) + return +} + +// FinishListen represents the imported method "finish-listen". +// +// finish-listen: func() -> result<_, error-code> +// +//go:nosplit +func (self TCPSocket) FinishListen() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishListen((uint32)(self0), &result) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketHopLimit((uint32)(self0), &result) + return +} + +// 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 +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) + return +} + +// 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, Duration, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) + return +} + +// 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, Duration, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) + return +} + +// 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, IPSocketAddress, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +// 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, IPSocketAddress, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) + return +} + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := cm.BoolToU32(value) + wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) + return +} + +// 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 Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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 Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + shutdownType0 := (uint32)(shutdownType) + wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) + return +} + +// 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, 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) + 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 +} + +// 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, 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) + 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 +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketStartListen((uint32)(self0), &result) + return +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} 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 100755 index 00000000..5444f200 --- /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 100755 index 00000000..dec4bc0f --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -0,0 +1,68 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// 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 IPAddressFamily) (result cm.Result[UDPSocket, UDPSocket, ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) + return +} 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 00000000..94b1ab67 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..e8cded35 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -0,0 +1,103 @@ +// 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" + "go.bytecodealliance.org/cm" + "unsafe" +) + +// IPSocketAddressShape is used for storage in variant or result types. +type IPSocketAddressShape struct { + _ cm.HostLayout + 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 { + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream]{})]byte +} + +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 + 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 100755 index 00000000..5444f200 --- /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.wasm.go b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go new file mode 100755 index 00000000..83ce8ca7 --- /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 ( + "go.bytecodealliance.org/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 new file mode 100755 index 00000000..372fcaa9 --- /dev/null +++ b/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -0,0 +1,584 @@ +// 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" + "go.bytecodealliance.org/cm" +) + +// 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. +// +// record incoming-datagram { +// data: list, +// remote-address: ip-socket-address, +// } +type IncomingDatagram struct { + _ cm.HostLayout + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + Data cm.List[uint8] + + // The source address. + // + // This field is guaranteed to match the remote address the stream was initialized + // with, if any. + // + // Equivalent to the `src_addr` out parameter of `recvfrom`. + RemoteAddress IPSocketAddress +} + +// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". +// +// A datagram to be sent out. +// +// record outgoing-datagram { +// data: list, +// remote-address: option, +// } +type OutgoingDatagram struct { + _ cm.HostLayout + // The payload. + Data cm.List[uint8] + + // The destination address. + // + // The requirements on this field depend on how the stream was initialized: + // - with a remote address: this field must be None or match the stream's remote address + // exactly. + // - without a remote address: this field is required. + // + // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise + // it is equivalent to `sendto`. + RemoteAddress cm.Option[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 +} + +// 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 IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return +} + +// FinishBind represents the imported method "finish-bind". +// +// finish-bind: func() -> result<_, error-code> +// +//go:nosplit +func (self UDPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketFinishBind((uint32)(self0), &result) + return +} + +// 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, IPSocketAddress, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) + return +} + +// 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, IPSocketAddress, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) + return +} + +// SendBufferSize represents the imported method "send-buffer-size". +// +// send-buffer-size: func() -> result +// +//go:nosplit +func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return +} + +// 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[ErrorCode, struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) + return +} + +// 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, 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) + 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 +} + +// 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[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 +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) + return +} + +// 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 +} + +// 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], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + maxResults0 := (uint64)(maxResults) + wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) + return +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} + +// 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 +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) + return +} + +// 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, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + datagrams0, datagrams1 := cm.LowerList(datagrams) + wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) + return +} + +// 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 Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[Pollable]((uint32)(result0)) + return +} 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 00000000..d7ea2d91 --- /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 00000000..70065233 --- /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 00000000..d0c2b82a --- /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 00000000..904b9946 --- /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 00000000..a70ee8c0 --- /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 00000000..513ca92d --- /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 00000000..47495769 --- /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 00000000..74811d32 --- /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 00000000..70065233 --- /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 00000000..d0c2b82a --- /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 00000000..eafa2fd4 --- /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 00000000..a70ee8c0 --- /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 00000000..1b653b6e --- /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 00000000..47495769 --- /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 00000000..d8005bd3 --- /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 00000000..70065233 --- /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 00000000..d0c2b82a --- /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 00000000..083b84a0 --- /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 00000000..a70ee8c0 --- /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 00000000..31ef35b5 --- /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 00000000..38c724ef --- /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 00000000..c0ecb529 --- /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 00000000..e717e7b8 --- /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 00000000..c3956496 --- /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 00000000..cdfb51d9 --- /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 00000000..09ef32c3 --- /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 00000000..8abb9a0c --- /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 00000000..8fa080f0 --- /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 00000000..4e4dc3a1 --- /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 00000000..440ca0f3 --- /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 00000000..c0224572 --- /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 00000000..3f787ac3 --- /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 00000000..af361354 --- /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 00000000..3f953f89 --- /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 00000000..95ec6784 --- /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 00000000..059722ab --- /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 00000000..285e0bae --- /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 00000000..da801f6d --- /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 00000000..11108fcd --- /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 00000000..663f5792 --- /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 00000000..6968d633 --- /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 00000000..286e2833 --- /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 00000000..dde0659d --- /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 00000000..2471f046 --- /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 00000000..a34a0649 --- /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 00000000..453f5905 --- /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 00000000..1dd4214c --- /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 00000000..a34a0649 --- /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 00000000..687c24d2 --- /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 00000000..755ac6a6 --- /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 00000000..74835e6a --- /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 00000000..c9600b70 --- /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 00000000..a0bcd312 --- /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 00000000..31918acb --- /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 00000000..bddde3c1 --- /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 00000000..e7e1b689 --- /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 00000000..8243da2e --- /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 00000000..22e5b648 --- /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 00000000..ddc67f8b --- /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 00000000..6d2f871e --- /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 00000000..5f0b43fe --- /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 00000000..139aed15 --- /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 00000000..2ffd223c --- /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 00000000..2c3c6a85 --- /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 00000000..dcbff938 --- /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 00000000..f76e87da --- /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 00000000..ec7b9973 --- /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 00000000..7a7dfa27 --- /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 00000000..49e5743b --- /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 00000000..47210ac6 --- /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 00000000..c58f4ee8 --- /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 00000000..0c017f09 --- /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 00000000..3da34914 --- /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 00000000..14e4479e --- /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 00000000..f2dab32f --- /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 00000000..fc516047 --- /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 00000000..a9a33738 --- /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 00000000..448f629e --- /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 00000000..e026359f --- /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 00000000..91a8c6c4 --- /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 00000000..d16530c3 --- /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 00000000..e455d0ff --- /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 00000000..931ccf7e --- /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 00000000..6bb07cd6 --- /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 00000000..768a07c8 --- /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 00000000..b01b65e6 --- /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 00000000..cc58234d --- /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 00000000..c8dafadf --- /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 00000000..49ad8d3d --- /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 00000000..e455d0ff --- /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 00000000..8e639ec5 --- /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 00000000..9cadf065 --- /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 00000000..c7ddf1f2 --- /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 00000000..5902b9ee --- /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 00000000..0482d1fe --- /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 00000000..d987a0a9 --- /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 00000000..f8bb92ae --- /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 00000000..ac465fbe --- /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 00000000..c941cc97 --- /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 00000000..6ca943cf --- /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 00000000..968c5762 --- /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 00000000..a991e5de --- /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 00000000..314a758c --- /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 00000000..ffed09cc --- /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 00000000..dd1b9c3e --- /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 00000000..e82ef42c --- /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 00000000..7af04209 --- /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 00000000..6970f63e --- /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 00000000..1b64906b --- /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 00000000..7e2908f0 --- /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 00000000..603a7602 --- /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 00000000..7ba4ed94 --- /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 00000000..ffed09cc --- /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 00000000..32f04fb5 --- /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 00000000..446cf89e --- /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 00000000..ebe1ec6a --- /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 00000000..64f3e59a --- /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 00000000..27446ebd --- /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 00000000..8a5ab2de --- /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 00000000..6c0511a8 --- /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/wit.go b/v2/wit/wit.go new file mode 100644 index 00000000..30251b11 --- /dev/null +++ b/v2/wit/wit.go @@ -0,0 +1,6 @@ +package wit + +import "embed" + +//go:embed * +var Wit embed.FS diff --git a/v2/wit/world.wit b/v2/wit/world.wit new file mode 100644 index 00000000..b16e4290 --- /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 2757940159cdddb90e47b77913b3e1bbcd5a0c10 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 2 Apr 2025 08:21:19 +0530 Subject: [PATCH 02/22] update go-modules and cm package. regen bindings Signed-off-by: Rajat Jindal --- v2/README.md | 24 +- v2/examples/http/go.mod | 8 +- v2/examples/http/go.sum | 4 +- v2/examples/http/main.go | 6 +- v2/examples/http/spin.toml | 2 +- v2/go.mod | 19 +- v2/go.sum | 35 + v2/http/client.go | 4 +- v2/http/convertor_incoming_request.go | 2 +- v2/http/convertor_outgoing_request.go | 2 +- v2/http/convertor_outgoing_response.go | 4 +- v2/http/http.go | 6 +- v2/http/streams.go | 2 +- v2/http/testdata/http-tinygo/go.mod | 8 +- v2/http/testdata/http-tinygo/go.sum | 4 +- v2/http/testdata/http-tinygo/main.go | 6 +- v2/http/testdata/http-tinygo/spin.toml | 2 +- v2/integration_test.go | 2 +- v2/internal/fermyon/spin/config/abi.go | 0 .../fermyon/spin/config/config.wasm.go | 0 v2/internal/fermyon/spin/config/config.wit.go | 4 +- v2/internal/fermyon/spin/config/empty.s | 0 .../spin/http-trigger/http-trigger.wit | 442 --- .../spin/http-trigger/http-trigger.wit.go | 0 .../fermyon/spin/http-types/http-types.wit.go | 54 +- v2/internal/fermyon/spin/http/abi.go | 4 +- v2/internal/fermyon/spin/http/empty.s | 0 v2/internal/fermyon/spin/http/http.wasm.go | 0 v2/internal/fermyon/spin/http/http.wit.go | 2 +- v2/internal/fermyon/spin/inbound-http/abi.go | 2 +- v2/internal/fermyon/spin/inbound-http/empty.s | 0 .../spin/inbound-http/inbound-http.exports.go | 0 ...boundhttp.wasm.go => inbound-http.wasm.go} | 0 .../spin/inbound-http/inbound-http.wit.go | 2 +- v2/internal/fermyon/spin/key-value/abi.go | 0 v2/internal/fermyon/spin/key-value/empty.s | 0 .../{keyvalue.wasm.go => key-value.wasm.go} | 0 .../fermyon/spin/key-value/key-value.wit.go | 4 +- v2/internal/fermyon/spin/llm/abi.go | 0 v2/internal/fermyon/spin/llm/empty.s | 0 v2/internal/fermyon/spin/llm/llm.wasm.go | 0 v2/internal/fermyon/spin/llm/llm.wit.go | 40 +- v2/internal/fermyon/spin/mysql/abi.go | 3 +- v2/internal/fermyon/spin/mysql/empty.s | 0 v2/internal/fermyon/spin/mysql/mysql.wasm.go | 0 v2/internal/fermyon/spin/mysql/mysql.wit.go | 6 +- v2/internal/fermyon/spin/postgres/abi.go | 3 +- v2/internal/fermyon/spin/postgres/empty.s | 0 .../fermyon/spin/postgres/postgres.wasm.go | 0 .../fermyon/spin/postgres/postgres.wit.go | 6 +- .../spin/rdbms-types/rdbms-types.wit.go | 37 +- .../spin/redis-types/redis-types.wit.go | 25 +- v2/internal/fermyon/spin/redis/empty.s | 0 v2/internal/fermyon/spin/redis/redis.wasm.go | 3 +- v2/internal/fermyon/spin/redis/redis.wit.go | 4 +- v2/internal/fermyon/spin/sqlite/abi.go | 0 v2/internal/fermyon/spin/sqlite/empty.s | 0 .../fermyon/spin/sqlite/sqlite.wasm.go | 0 v2/internal/fermyon/spin/sqlite/sqlite.wit.go | 18 +- .../spin/v2.0.0/http-trigger/http-trigger.wit | 3121 ----------------- .../v2.0.0/http-trigger/http-trigger.wit.go | 0 .../fermyon/spin/v2.0.0/key-value/abi.go | 0 .../fermyon/spin/v2.0.0/key-value/empty.s | 0 .../{keyvalue.wasm.go => key-value.wasm.go} | 0 .../spin/v2.0.0/key-value/key-value.wit.go | 4 +- v2/internal/fermyon/spin/v2.0.0/llm/abi.go | 0 v2/internal/fermyon/spin/v2.0.0/llm/empty.s | 0 .../fermyon/spin/v2.0.0/llm/llm.wasm.go | 0 .../fermyon/spin/v2.0.0/llm/llm.wit.go | 40 +- v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 0 v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s | 0 .../fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go | 0 .../fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 21 +- v2/internal/fermyon/spin/v2.0.0/mysql/abi.go | 5 +- v2/internal/fermyon/spin/v2.0.0/mysql/empty.s | 0 .../fermyon/spin/v2.0.0/mysql/mysql.wasm.go | 0 .../fermyon/spin/v2.0.0/mysql/mysql.wit.go | 2 +- .../fermyon/spin/v2.0.0/postgres/abi.go | 5 +- .../fermyon/spin/v2.0.0/postgres/empty.s | 0 .../spin/v2.0.0/postgres/postgres.wasm.go | 0 .../spin/v2.0.0/postgres/postgres.wit.go | 2 +- .../v2.0.0/rdbms-types/rdbms-types.wit.go | 41 +- v2/internal/fermyon/spin/v2.0.0/redis/abi.go | 0 v2/internal/fermyon/spin/v2.0.0/redis/empty.s | 0 .../fermyon/spin/v2.0.0/redis/redis.wasm.go | 0 .../fermyon/spin/v2.0.0/redis/redis.wit.go | 12 +- v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go | 0 .../fermyon/spin/v2.0.0/sqlite/empty.s | 0 .../fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go | 0 .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 18 +- .../fermyon/spin/v2.0.0/variables/abi.go | 0 .../fermyon/spin/v2.0.0/variables/empty.s | 0 .../spin/v2.0.0/variables/variables.wasm.go | 0 .../spin/v2.0.0/variables/variables.wit.go | 4 +- .../v3.0.0/http-trigger/http-trigger.wit.go | 6 + .../spin/postgres/v3.0.0/postgres/abi.go | 26 + .../spin/postgres/v3.0.0/postgres/empty.s | 3 + .../postgres/v3.0.0/postgres/postgres.wasm.go | 25 + .../postgres/v3.0.0/postgres/postgres.wit.go | 657 ++++ .../wasi/cli/v0.2.0/environment/empty.s | 0 .../v0.2.0/environment/environment.wasm.go | 0 .../cli/v0.2.0/environment/environment.wit.go | 0 v2/internal/wasi/cli/v0.2.0/exit/empty.s | 0 v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go | 0 v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stderr/empty.s | 0 .../wasi/cli/v0.2.0/stderr/stderr.wasm.go | 0 .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stdin/empty.s | 0 .../wasi/cli/v0.2.0/stdin/stdin.wasm.go | 0 .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 2 +- v2/internal/wasi/cli/v0.2.0/stdout/empty.s | 0 .../wasi/cli/v0.2.0/stdout/stdout.wasm.go | 0 .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-input/empty.s | 0 ...alinput.wasm.go => terminal-input.wasm.go} | 0 .../terminal-input/terminal-input.wit.go | 0 .../wasi/cli/v0.2.0/terminal-output/empty.s | 0 ...output.wasm.go => terminal-output.wasm.go} | 0 .../terminal-output/terminal-output.wit.go | 0 .../wasi/cli/v0.2.0/terminal-stderr/empty.s | 0 ...stderr.wasm.go => terminal-stderr.wasm.go} | 0 .../terminal-stderr/terminal-stderr.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-stdin/empty.s | 0 ...alstdin.wasm.go => terminal-stdin.wasm.go} | 0 .../terminal-stdin/terminal-stdin.wit.go | 2 +- .../wasi/cli/v0.2.0/terminal-stdout/empty.s | 0 ...stdout.wasm.go => terminal-stdout.wasm.go} | 0 .../terminal-stdout/terminal-stdout.wit.go | 2 +- .../clocks/v0.2.0/monotonic-clock/empty.s | 0 ...cclock.wasm.go => monotonic-clock.wasm.go} | 0 .../monotonic-clock/monotonic-clock.wit.go | 2 +- .../wasi/clocks/v0.2.0/wall-clock/empty.s | 0 .../{wallclock.wasm.go => wall-clock.wasm.go} | 0 .../v0.2.0/wall-clock/wall-clock.wit.go | 6 +- .../v0.2.0-draft-2024-09-27/store/abi.go | 20 + .../v0.2.0-draft-2024-09-27/store/empty.s | 3 + .../store/store.wasm.go | 17 + .../store/store.wit.go | 92 + .../wasi/filesystem/v0.2.0/preopens/empty.s | 0 .../v0.2.0/preopens/preopens.wasm.go | 0 .../v0.2.0/preopens/preopens.wit.go | 2 +- .../wasi/filesystem/v0.2.0/types/abi.go | 4 +- .../wasi/filesystem/v0.2.0/types/empty.s | 0 .../filesystem/v0.2.0/types/types.wasm.go | 0 .../wasi/filesystem/v0.2.0/types/types.wit.go | 87 +- .../wasi/http/v0.2.0/incoming-handler/empty.s | 0 .../incoming-handler.exports.go | 0 ...ndler.wasm.go => incoming-handler.wasm.go} | 0 .../incoming-handler/incoming-handler.wit.go | 2 +- .../wasi/http/v0.2.0/outgoing-handler/abi.go | 3 +- .../wasi/http/v0.2.0/outgoing-handler/empty.s | 0 ...ndler.wasm.go => outgoing-handler.wasm.go} | 0 .../outgoing-handler/outgoing-handler.wit.go | 2 +- v2/internal/wasi/http/v0.2.0/types/abi.go | 52 +- v2/internal/wasi/http/v0.2.0/types/empty.s | 0 .../wasi/http/v0.2.0/types/types.wasm.go | 0 .../wasi/http/v0.2.0/types/types.wit.go | 73 +- v2/internal/wasi/io/v0.2.0/error/empty.s | 0 .../error/{ioerror.wasm.go => error.wasm.go} | 0 v2/internal/wasi/io/v0.2.0/error/error.wit.go | 0 v2/internal/wasi/io/v0.2.0/poll/empty.s | 0 v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go | 0 v2/internal/wasi/io/v0.2.0/poll/poll.wit.go | 2 +- v2/internal/wasi/io/v0.2.0/streams/empty.s | 0 .../wasi/io/v0.2.0/streams/streams.wasm.go | 0 .../wasi/io/v0.2.0/streams/streams.wit.go | 34 +- .../keyvalue/v0.2.0-draft2/atomics/abi.go | 20 + .../v0.2.0-draft2/atomics/atomics.wasm.go | 29 + .../v0.2.0-draft2/atomics/atomics.wit.go | 171 + .../keyvalue/v0.2.0-draft2/atomics/empty.s | 3 + .../wasi/keyvalue/v0.2.0-draft2/batch/abi.go | 14 + .../v0.2.0-draft2/batch/batch.wasm.go | 21 + .../keyvalue/v0.2.0-draft2/batch/batch.wit.go | 134 + .../wasi/keyvalue/v0.2.0-draft2/batch/empty.s | 3 + .../wasi/keyvalue/v0.2.0-draft2/store/abi.go | 37 + .../wasi/keyvalue/v0.2.0-draft2/store/empty.s | 3 + .../v0.2.0-draft2/store/store.wasm.go | 37 + .../keyvalue/v0.2.0-draft2/store/store.wit.go | 294 ++ .../wasi/random/v0.2.0/insecure-seed/empty.s | 0 ...cureseed.wasm.go => insecure-seed.wasm.go} | 0 .../v0.2.0/insecure-seed/insecure-seed.wit.go | 0 .../wasi/random/v0.2.0/insecure/empty.s | 0 .../random/v0.2.0/insecure/insecure.wasm.go | 0 .../random/v0.2.0/insecure/insecure.wit.go | 0 v2/internal/wasi/random/v0.2.0/random/empty.s | 0 .../wasi/random/v0.2.0/random/random.wasm.go | 0 .../wasi/random/v0.2.0/random/random.wit.go | 0 .../sockets/v0.2.0/instance-network/empty.s | 0 ...twork.wasm.go => instance-network.wasm.go} | 0 .../instance-network/instance-network.wit.go | 2 +- .../wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 0 .../sockets/v0.2.0/ip-name-lookup/empty.s | 0 ...elookup.wasm.go => ip-name-lookup.wasm.go} | 0 .../ip-name-lookup/ip-name-lookup.wit.go | 4 +- .../wasi/sockets/v0.2.0/network/abi.go | 0 .../wasi/sockets/v0.2.0/network/empty.s | 0 .../sockets/v0.2.0/network/network.wasm.go | 0 .../sockets/v0.2.0/network/network.wit.go | 58 +- .../sockets/v0.2.0/tcp-create-socket/empty.s | 0 ...cket.wasm.go => tcp-create-socket.wasm.go} | 0 .../tcp-create-socket.wit.go | 4 +- v2/internal/wasi/sockets/v0.2.0/tcp/abi.go | 8 +- v2/internal/wasi/sockets/v0.2.0/tcp/empty.s | 0 .../wasi/sockets/v0.2.0/tcp/tcp.wasm.go | 2 +- .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 31 +- .../sockets/v0.2.0/udp-create-socket/empty.s | 0 ...cket.wasm.go => udp-create-socket.wasm.go} | 0 .../udp-create-socket.wit.go | 4 +- v2/internal/wasi/sockets/v0.2.0/udp/abi.go | 8 +- v2/internal/wasi/sockets/v0.2.0/udp/empty.s | 0 .../wasi/sockets/v0.2.0/udp/udp.wasm.go | 0 .../wasi/sockets/v0.2.0/udp/udp.wit.go | 20 +- v2/wit/deps/keyvalue-2024-10-17/atomic.wit | 46 + v2/wit/deps/keyvalue-2024-10-17/batch.wit | 63 + v2/wit/deps/keyvalue-2024-10-17/store.wit | 122 + v2/wit/deps/keyvalue-2024-10-17/watch.wit | 16 + v2/wit/deps/keyvalue-2024-10-17/world.wit | 26 + v2/wit/deps/spin-postgres@3.0.0/postgres.wit | 100 + v2/wit/{ => deps/spin@2.0.0}/key-value.wit | 0 v2/wit/{ => deps/spin@2.0.0}/llm.wit | 8 +- v2/wit/{ => deps/spin@2.0.0}/mqtt.wit | 0 v2/wit/{ => deps/spin@2.0.0}/mysql.wit | 0 v2/wit/{ => deps/spin@2.0.0}/postgres.wit | 0 v2/wit/{ => deps/spin@2.0.0}/rdbms-types.wit | 8 +- v2/wit/{ => deps/spin@2.0.0}/redis.wit | 0 v2/wit/{ => deps/spin@2.0.0}/sqlite.wit | 2 +- v2/wit/{ => deps/spin@2.0.0}/variables.wit | 0 v2/wit/deps/spin@2.0.0/world.wit | 41 + v2/wit/deps/spin@unversioned/llm.wit | 8 +- v2/wit/deps/spin@unversioned/rdbms-types.wit | 8 +- v2/wit/deps/spin@unversioned/sqlite.wit | 2 +- .../wasi-runtime-config-2024-09-27/store.wit | 30 + .../wasi-runtime-config-2024-09-27/world.wit | 6 + v2/wit/world.wit | 36 +- 235 files changed, 2670 insertions(+), 3965 deletions(-) mode change 100755 => 100644 v2/internal/fermyon/spin/config/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/config/config.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/config/config.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/config/empty.s delete mode 100755 v2/internal/fermyon/spin/http-trigger/http-trigger.wit mode change 100755 => 100644 v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/http-types/http-types.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/http/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/http/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/http/http.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/http/http.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/inbound-http/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/inbound-http/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go rename v2/internal/fermyon/spin/inbound-http/{inboundhttp.wasm.go => inbound-http.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/key-value/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/key-value/empty.s rename v2/internal/fermyon/spin/key-value/{keyvalue.wasm.go => key-value.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/fermyon/spin/key-value/key-value.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/llm/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/llm/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/llm/llm.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/llm/llm.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/mysql/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/mysql/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/mysql/mysql.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/mysql/mysql.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/postgres/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/postgres/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/postgres/postgres.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/postgres/postgres.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/redis-types/redis-types.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/redis/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/redis/redis.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/redis/redis.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/sqlite/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/sqlite/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/sqlite/sqlite.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/sqlite/sqlite.wit.go delete mode 100755 v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/key-value/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/key-value/empty.s rename v2/internal/fermyon/spin/v2.0.0/key-value/{keyvalue.wasm.go => key-value.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/llm/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/llm/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mysql/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mysql/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/postgres/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/postgres/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/redis/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/redis/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/variables/abi.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/variables/empty.s mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go mode change 100755 => 100644 v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go create mode 100644 v2/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go create mode 100644 v2/internal/spin/postgres/v3.0.0/postgres/abi.go create mode 100644 v2/internal/spin/postgres/v3.0.0/postgres/empty.s create mode 100644 v2/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go create mode 100644 v2/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/environment/empty.s mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/exit/empty.s mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stderr/empty.s mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdin/empty.s mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdout/empty.s mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s rename v2/internal/wasi/cli/v0.2.0/terminal-input/{terminalinput.wasm.go => terminal-input.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s rename v2/internal/wasi/cli/v0.2.0/terminal-output/{terminaloutput.wasm.go => terminal-output.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s rename v2/internal/wasi/cli/v0.2.0/terminal-stderr/{terminalstderr.wasm.go => terminal-stderr.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s rename v2/internal/wasi/cli/v0.2.0/terminal-stdin/{terminalstdin.wasm.go => terminal-stdin.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s rename v2/internal/wasi/cli/v0.2.0/terminal-stdout/{terminalstdout.wasm.go => terminal-stdout.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go mode change 100755 => 100644 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s rename v2/internal/wasi/clocks/v0.2.0/monotonic-clock/{monotonicclock.wasm.go => monotonic-clock.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go mode change 100755 => 100644 v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s rename v2/internal/wasi/clocks/v0.2.0/wall-clock/{wallclock.wasm.go => wall-clock.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go create mode 100644 v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go create mode 100644 v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s create mode 100644 v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go create mode 100644 v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/types/abi.go mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/types/empty.s mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go mode change 100755 => 100644 v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go rename v2/internal/wasi/http/v0.2.0/incoming-handler/{incominghandler.wasm.go => incoming-handler.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s rename v2/internal/wasi/http/v0.2.0/outgoing-handler/{outgoinghandler.wasm.go => outgoing-handler.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/types/abi.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/types/empty.s mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/types/types.wasm.go mode change 100755 => 100644 v2/internal/wasi/http/v0.2.0/types/types.wit.go mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/error/empty.s rename v2/internal/wasi/io/v0.2.0/error/{ioerror.wasm.go => error.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/error/error.wit.go mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/poll/empty.s mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/poll/poll.wit.go mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/streams/empty.s mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go mode change 100755 => 100644 v2/internal/wasi/io/v0.2.0/streams/streams.wit.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go create mode 100644 v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s rename v2/internal/wasi/random/v0.2.0/insecure-seed/{insecureseed.wasm.go => insecure-seed.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/insecure/empty.s mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/random/empty.s mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/random/random.wasm.go mode change 100755 => 100644 v2/internal/wasi/random/v0.2.0/random/random.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s rename v2/internal/wasi/sockets/v0.2.0/instance-network/{instancenetwork.wasm.go => instance-network.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s rename v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/{ipnamelookup.wasm.go => ip-name-lookup.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/network/abi.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/network/empty.s mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/network/network.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s rename v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/{tcpcreatesocket.wasm.go => tcp-create-socket.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp/abi.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp/empty.s mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s rename v2/internal/wasi/sockets/v0.2.0/udp-create-socket/{udpcreatesocket.wasm.go => udp-create-socket.wasm.go} (100%) mode change 100755 => 100644 mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp/abi.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp/empty.s mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go mode change 100755 => 100644 v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go create mode 100644 v2/wit/deps/keyvalue-2024-10-17/atomic.wit create mode 100644 v2/wit/deps/keyvalue-2024-10-17/batch.wit create mode 100644 v2/wit/deps/keyvalue-2024-10-17/store.wit create mode 100644 v2/wit/deps/keyvalue-2024-10-17/watch.wit create mode 100644 v2/wit/deps/keyvalue-2024-10-17/world.wit create mode 100644 v2/wit/deps/spin-postgres@3.0.0/postgres.wit rename v2/wit/{ => deps/spin@2.0.0}/key-value.wit (100%) rename v2/wit/{ => deps/spin@2.0.0}/llm.wit (95%) rename v2/wit/{ => deps/spin@2.0.0}/mqtt.wit (100%) rename v2/wit/{ => deps/spin@2.0.0}/mysql.wit (100%) rename v2/wit/{ => deps/spin@2.0.0}/postgres.wit (100%) rename v2/wit/{ => deps/spin@2.0.0}/rdbms-types.wit (92%) rename v2/wit/{ => deps/spin@2.0.0}/redis.wit (100%) rename v2/wit/{ => deps/spin@2.0.0}/sqlite.wit (98%) rename v2/wit/{ => deps/spin@2.0.0}/variables.wit (100%) create mode 100644 v2/wit/deps/spin@2.0.0/world.wit create mode 100644 v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit create mode 100644 v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit diff --git a/v2/README.md b/v2/README.md index 5b333a9c..56dce87e 100644 --- a/v2/README.md +++ b/v2/README.md @@ -6,8 +6,24 @@ Notes: 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)` -- 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) +- wit-bindgen-go `wit-bindgen-go version (devel) (0e3b31e354b31b4f2d5e7d5163e29fb2ffd0b052)` +- wasm-tools `wasm-tools 1.227.1` +- tinygo `tinygo version 0.37.0 darwin/arm64 (using go version go1.24.1 and LLVM version 19.1.2)` +- spin `spin 3.2.0-pre0 (3d07b0cb 2025-03-14)` +- go `go version go1.24.1 darwin/arm64` +- binaryen tools `binaryen-version_123` + +Regeneratin bindings: + +- install tooling as specified above +- make sure they are on PATH and picking up the versions as specified above +- cd `/v2` +- Run: `wit-bindgen-go generate -w http-trigger -p github.com/spinframework/spin-go-sdk/v2/internal --out internal ./wit` + +Testing: + +- cd `/v2/examples/http` +- Run `spin build` +- Run `spin up` +- In a separate terminal, run: `curl http://127.0.0.1:3000/hello` diff --git a/v2/examples/http/go.mod b/v2/examples/http/go.mod index 225c227f..07a0d32f 100644 --- a/v2/examples/http/go.mod +++ b/v2/examples/http/go.mod @@ -1,12 +1,12 @@ -module github.com/fermyon/spin-go-sdk/v2/examples/http +module github.com/spinframework/spin-go-sdk/v2/examples/http go 1.23.2 -require github.com/fermyon/spin-go-sdk/v2 v2.0.0 +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 require ( github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org v0.4.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect ) -replace github.com/fermyon/spin-go-sdk/v2 => ../../ +replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/http/go.sum b/v2/examples/http/go.sum index 0c8b9316..c1ebfdf4 100644 --- a/v2/examples/http/go.sum +++ b/v2/examples/http/go.sum @@ -1,4 +1,4 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= -go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/examples/http/main.go b/v2/examples/http/main.go index 9d88dcd9..90e2864c 100644 --- a/v2/examples/http/main.go +++ b/v2/examples/http/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/fermyon/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" ) func init() { @@ -14,8 +14,8 @@ func init() { w.WriteHeader(http.StatusOK) fmt.Fprintln(w, "== RESPONSE ==") - fmt.Fprintln(w, "Hello Fermyon!") - fmt.Fprintln(w, "Hello again Fermyon!") + fmt.Fprintln(w, "Hello spinframework!") + fmt.Fprintln(w, "Hello again spinframework!") }) } diff --git a/v2/examples/http/spin.toml b/v2/examples/http/spin.toml index 00625c4a..52b31fb2 100644 --- a/v2/examples/http/spin.toml +++ b/v2/examples/http/spin.toml @@ -13,4 +13,4 @@ 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 +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/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 93fb5c5c..e8a89272 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -1,8 +1,23 @@ -module github.com/fermyon/spin-go-sdk/v2 +module github.com/spinframework/spin-go-sdk/v2 go 1.23.2 require ( github.com/julienschmidt/httprouter v1.3.0 - go.bytecodealliance.org v0.4.0 + go.bytecodealliance.org v0.6.2 + go.bytecodealliance.org/cm v0.2.2 +) + +require ( + github.com/coreos/go-semver v0.3.1 // indirect + github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect + github.com/klauspost/compress v1.17.11 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/regclient/regclient v0.8.2 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/tetratelabs/wazero v1.9.0 // indirect + github.com/ulikunitz/xz v0.5.12 // indirect + github.com/urfave/cli/v3 v3.0.0-beta1 // indirect + golang.org/x/mod v0.23.0 // indirect + golang.org/x/sys v0.30.0 // indirect ) diff --git a/v2/go.sum b/v2/go.sum index 0c8b9316..c2db9fff 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,4 +1,39 @@ +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4= +github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/regclient/regclient v0.8.2 h1:23BQ3jWgKYHHIXUhp/S9laVJDHDoOQaQCzXMJ4undVE= +github.com/regclient/regclient v0.8.2/go.mod h1:uGyetv0o6VLyRDjtfeBqp/QBwRLJ3Hcn07/+8QbhNcM= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= +github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= +github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= +github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg= +github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= +go.bytecodealliance.org v0.6.2 h1:Jy4u5DVmSkXgsnwojBhJ+AD/YsJsR3VzVnxF0xRCqTQ= +go.bytecodealliance.org v0.6.2/go.mod h1:gqjTJm0y9NSksG4py/lSjIQ/SNuIlOQ+hCIEPQwtJgA= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= +golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= +golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/v2/http/client.go b/v2/http/client.go index 46f9ac04..e8465325 100644 --- a/v2/http/client.go +++ b/v2/http/client.go @@ -5,8 +5,8 @@ import ( "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" + outgoinghandler "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/outgoing-handler" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_incoming_request.go b/v2/http/convertor_incoming_request.go index cc7465ad..9346b57a 100644 --- a/v2/http/convertor_incoming_request.go +++ b/v2/http/convertor_incoming_request.go @@ -5,7 +5,7 @@ import ( "io" "net/http" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_outgoing_request.go b/v2/http/convertor_outgoing_request.go index cb4747de..daf462b4 100644 --- a/v2/http/convertor_outgoing_request.go +++ b/v2/http/convertor_outgoing_request.go @@ -3,7 +3,7 @@ package http import ( "net/http" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_outgoing_response.go b/v2/http/convertor_outgoing_response.go index 55483295..36729331 100644 --- a/v2/http/convertor_outgoing_response.go +++ b/v2/http/convertor_outgoing_response.go @@ -5,8 +5,8 @@ import ( "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/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/http.go b/v2/http/http.go index 7ac5d5de..c57e0b64 100644 --- a/v2/http/http.go +++ b/v2/http/http.go @@ -7,10 +7,10 @@ import ( "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" + incominghandler "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/incoming-handler" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/wit" ) // force wit files to be shipped with sdk dependency diff --git a/v2/http/streams.go b/v2/http/streams.go index 5ec82107..d24bdbf8 100644 --- a/v2/http/streams.go +++ b/v2/http/streams.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" ) type inputStreamReader struct { diff --git a/v2/http/testdata/http-tinygo/go.mod b/v2/http/testdata/http-tinygo/go.mod index 06e45c38..864c3383 100644 --- a/v2/http/testdata/http-tinygo/go.mod +++ b/v2/http/testdata/http-tinygo/go.mod @@ -1,12 +1,12 @@ -module github.com/fermyon/spin-go-sdk/v2/http/testdata/http +module github.com/spinframework/spin-go-sdk/v2/http/testdata/http go 1.23.2 -require github.com/fermyon/spin-go-sdk/v2 v2.0.0 +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 require ( github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org v0.4.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect ) -replace github.com/fermyon/spin-go-sdk/v2 => ../../../ +replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/http/testdata/http-tinygo/go.sum b/v2/http/testdata/http-tinygo/go.sum index 0c8b9316..c1ebfdf4 100644 --- a/v2/http/testdata/http-tinygo/go.sum +++ b/v2/http/testdata/http-tinygo/go.sum @@ -1,4 +1,4 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= -go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/http/testdata/http-tinygo/main.go b/v2/http/testdata/http-tinygo/main.go index e0c267f2..4b626d07 100644 --- a/v2/http/testdata/http-tinygo/main.go +++ b/v2/http/testdata/http-tinygo/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/fermyon/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" ) func init() { @@ -15,8 +15,8 @@ func init() { //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!") + fmt.Fprintln(w, "Hello spinframework!") + fmt.Fprintln(w, "Hello again spinframework!") }) } diff --git a/v2/http/testdata/http-tinygo/spin.toml b/v2/http/testdata/http-tinygo/spin.toml index 00625c4a..52b31fb2 100644 --- a/v2/http/testdata/http-tinygo/spin.toml +++ b/v2/http/testdata/http-tinygo/spin.toml @@ -13,4 +13,4 @@ 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 +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/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/integration_test.go b/v2/integration_test.go index 6eb9a70f..fb6e8e8c 100644 --- a/v2/integration_test.go +++ b/v2/integration_test.go @@ -108,7 +108,7 @@ func TestHTTPTriger(t *testing.T) { } // assert response body - want := "== RESPONSE ==\nHello Fermyon!\nHello again Fermyon!\n" + want := "== RESPONSE ==\nHello spinframework!\nHello again spinframework!\n" got := string(b) if want != got { t.Fatalf("body is not equal: want = %q got = %q", want, got) diff --git a/v2/internal/fermyon/spin/config/abi.go b/v2/internal/fermyon/spin/config/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/config/config.wasm.go b/v2/internal/fermyon/spin/config/config.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/config/config.wit.go b/v2/internal/fermyon/spin/config/config.wit.go old mode 100755 new mode 100644 index 71602b0e..30e9f111 --- a/v2/internal/fermyon/spin/config/config.wit.go +++ b/v2/internal/fermyon/spin/config/config.wit.go @@ -57,7 +57,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } -var stringsError = [4]string{ +var _ErrorStrings = [4]string{ "provider", "invalid-key", "invalid-schema", @@ -66,7 +66,7 @@ var stringsError = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // GetConfig represents the imported function "get-config". diff --git a/v2/internal/fermyon/spin/config/empty.s b/v2/internal/fermyon/spin/config/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/http-trigger/http-trigger.wit b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit deleted file mode 100755 index 82dc634a..00000000 --- a/v2/internal/fermyon/spin/http-trigger/http-trigger.wit +++ /dev/null @@ -1,442 +0,0 @@ -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-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/http-types/http-types.wit.go b/v2/internal/fermyon/spin/http-types/http-types.wit.go old mode 100755 new mode 100644 index b043ad92..f6145cc4 --- a/v2/internal/fermyon/spin/http-types/http-types.wit.go +++ b/v2/internal/fermyon/spin/http-types/http-types.wit.go @@ -55,7 +55,7 @@ const ( MethodOptions ) -var stringsMethod = [7]string{ +var _MethodStrings = [7]string{ "get", "post", "put", @@ -67,9 +67,22 @@ var stringsMethod = [7]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e Method) String() string { - return stringsMethod[e] + return _MethodStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e Method) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *Method) UnmarshalText(text []byte) error { + return _MethodUnmarshalCase(e, text) +} + +var _MethodUnmarshalCase = cm.CaseUnmarshaler[Method](_MethodStrings[:]) + // Request represents the record "fermyon:spin/http-types#request". // // record request { @@ -80,12 +93,12 @@ func (e Method) String() string { // body: option, // } type Request struct { - _ cm.HostLayout - Method Method - URI URI - Headers Headers - Params Params - Body cm.Option[Body] + _ cm.HostLayout `json:"-"` + Method Method `json:"method"` + URI URI `json:"uri"` + Headers Headers `json:"headers"` + Params Params `json:"params"` + Body cm.Option[Body] `json:"body"` } // Response represents the record "fermyon:spin/http-types#response". @@ -96,10 +109,10 @@ type Request struct { // body: option, // } type Response struct { - _ cm.HostLayout - Status HTTPStatus - Headers cm.Option[Headers] - Body cm.Option[Body] + _ cm.HostLayout `json:"-"` + Status HTTPStatus `json:"status"` + Headers cm.Option[Headers] `json:"headers"` + Body cm.Option[Body] `json:"body"` } // HTTPError represents the enum "fermyon:spin/http-types#http-error". @@ -123,7 +136,7 @@ const ( HTTPErrorTooManyRequests ) -var stringsHTTPError = [6]string{ +var _HTTPErrorStrings = [6]string{ "success", "destination-not-allowed", "invalid-url", @@ -134,5 +147,18 @@ var stringsHTTPError = [6]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e HTTPError) String() string { - return stringsHTTPError[e] + return _HTTPErrorStrings[e] } + +// MarshalText implements [encoding.TextMarshaler]. +func (e HTTPError) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *HTTPError) UnmarshalText(text []byte) error { + return _HTTPErrorUnmarshalCase(e, text) +} + +var _HTTPErrorUnmarshalCase = cm.CaseUnmarshaler[HTTPError](_HTTPErrorStrings[:]) diff --git a/v2/internal/fermyon/spin/http/abi.go b/v2/internal/fermyon/spin/http/abi.go old mode 100755 new mode 100644 index 2b234b40..9d51d703 --- a/v2/internal/fermyon/spin/http/abi.go +++ b/v2/internal/fermyon/spin/http/abi.go @@ -3,7 +3,7 @@ package http import ( - httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,7 +11,7 @@ import ( // ResponseShape is used for storage in variant or result types. type ResponseShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(httptypes.Response{})]byte + shape [unsafe.Sizeof(Response{})]byte } func lower_OptionBody(v cm.Option[httptypes.Body]) (f0 uint32, f1 *uint8, f2 uint32) { diff --git a/v2/internal/fermyon/spin/http/empty.s b/v2/internal/fermyon/spin/http/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/http/http.wasm.go b/v2/internal/fermyon/spin/http/http.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/http/http.wit.go b/v2/internal/fermyon/spin/http/http.wit.go old mode 100755 new mode 100644 index 36676913..bf022ce0 --- a/v2/internal/fermyon/spin/http/http.wit.go +++ b/v2/internal/fermyon/spin/http/http.wit.go @@ -4,7 +4,7 @@ package http import ( - httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v2/internal/fermyon/spin/inbound-http/abi.go old mode 100755 new mode 100644 index 92759dba..660c96eb --- a/v2/internal/fermyon/spin/inbound-http/abi.go +++ b/v2/internal/fermyon/spin/inbound-http/abi.go @@ -3,7 +3,7 @@ package inboundhttp import ( - httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/inbound-http/empty.s b/v2/internal/fermyon/spin/inbound-http/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/fermyon/spin/inbound-http/inboundhttp.wasm.go rename to v2/internal/fermyon/spin/inbound-http/inbound-http.wasm.go diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go old mode 100755 new mode 100644 index c952be21..0edd9c10 --- a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go +++ b/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go @@ -4,7 +4,7 @@ package inboundhttp import ( - httptypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" ) // Request represents the type alias "fermyon:spin/inbound-http#request". diff --git a/v2/internal/fermyon/spin/key-value/abi.go b/v2/internal/fermyon/spin/key-value/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/key-value/empty.s b/v2/internal/fermyon/spin/key-value/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/key-value/keyvalue.wasm.go b/v2/internal/fermyon/spin/key-value/key-value.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/fermyon/spin/key-value/keyvalue.wasm.go rename to v2/internal/fermyon/spin/key-value/key-value.wasm.go diff --git a/v2/internal/fermyon/spin/key-value/key-value.wit.go b/v2/internal/fermyon/spin/key-value/key-value.wit.go old mode 100755 new mode 100644 index 1eec8f77..34157201 --- a/v2/internal/fermyon/spin/key-value/key-value.wit.go +++ b/v2/internal/fermyon/spin/key-value/key-value.wit.go @@ -111,7 +111,7 @@ func (self *Error) IO() *string { return cm.Case[string](self, 5) } -var stringsError = [6]string{ +var _ErrorStrings = [6]string{ "store-table-full", "no-such-store", "access-denied", @@ -122,7 +122,7 @@ var stringsError = [6]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Open represents the imported function "open". diff --git a/v2/internal/fermyon/spin/llm/abi.go b/v2/internal/fermyon/spin/llm/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/llm/empty.s b/v2/internal/fermyon/spin/llm/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/llm/llm.wasm.go b/v2/internal/fermyon/spin/llm/llm.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/llm/llm.wit.go b/v2/internal/fermyon/spin/llm/llm.wit.go old mode 100755 new mode 100644 index e97b9476..2663b90a --- a/v2/internal/fermyon/spin/llm/llm.wit.go +++ b/v2/internal/fermyon/spin/llm/llm.wit.go @@ -29,26 +29,26 @@ type InferencingModel string // top-p: f32, // } type InferencingParams struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The maximum tokens that should be inferred. // // Note: the backing implementation may return less tokens. - MaxTokens uint32 + MaxTokens uint32 `json:"max-tokens"` // The amount the model should avoid repeating tokens. - RepeatPenalty float32 + RepeatPenalty float32 `json:"repeat-penalty"` // The number of tokens the model should apply the repeat penalty to. - RepeatPenaltyLastNTokenCount uint32 + RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` // The randomness with which the next token is selected. - Temperature float32 + Temperature float32 `json:"temperature"` // The number of possible next tokens the model will choose from. - TopK uint32 + TopK uint32 `json:"top-k"` // The probability total of next tokens the model will choose from. - TopP float32 + TopP float32 `json:"top-p"` } // Error represents the variant "fermyon:spin/llm#error". @@ -93,7 +93,7 @@ func (self *Error) InvalidInput() *string { return cm.Case[string](self, 2) } -var stringsError = [3]string{ +var _ErrorStrings = [3]string{ "model-not-supported", "runtime-error", "invalid-input", @@ -101,7 +101,7 @@ var stringsError = [3]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // InferencingUsage represents the record "fermyon:spin/llm#inferencing-usage". @@ -113,12 +113,12 @@ func (v Error) String() string { // generated-token-count: u32, // } type InferencingUsage struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // Number of tokens in the prompt - PromptTokenCount uint32 + PromptTokenCount uint32 `json:"prompt-token-count"` // Number of tokens generated by the inferencing operation - GeneratedTokenCount uint32 + GeneratedTokenCount uint32 `json:"generated-token-count"` } // InferencingResult represents the record "fermyon:spin/llm#inferencing-result". @@ -130,13 +130,13 @@ type InferencingUsage struct { // usage: inferencing-usage, // } type InferencingResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The text generated by the model // TODO: this should be a stream - Text string + Text string `json:"text"` // Usage information about the inferencing request - Usage InferencingUsage + Usage InferencingUsage `json:"usage"` } // EmbeddingModel represents the string "fermyon:spin/llm#embedding-model". @@ -154,9 +154,9 @@ type EmbeddingModel string // prompt-token-count: u32, // } type EmbeddingsUsage struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // Number of tokens in the prompt - PromptTokenCount uint32 + PromptTokenCount uint32 `json:"prompt-token-count"` } // EmbeddingsResult represents the record "fermyon:spin/llm#embeddings-result". @@ -168,12 +168,12 @@ type EmbeddingsUsage struct { // usage: embeddings-usage, // } type EmbeddingsResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The embeddings generated by the request - Embeddings cm.List[cm.List[float32]] + Embeddings cm.List[cm.List[float32]] `json:"embeddings"` // Usage related to the embeddings generation request - Usage EmbeddingsUsage + Usage EmbeddingsUsage `json:"usage"` } // Infer represents the imported function "infer". diff --git a/v2/internal/fermyon/spin/mysql/abi.go b/v2/internal/fermyon/spin/mysql/abi.go old mode 100755 new mode 100644 index 9577bd93..3fc15d55 --- a/v2/internal/fermyon/spin/mysql/abi.go +++ b/v2/internal/fermyon/spin/mysql/abi.go @@ -3,7 +3,6 @@ package mysql import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,5 +10,5 @@ import ( // RowSetShape is used for storage in variant or result types. type RowSetShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte + shape [unsafe.Sizeof(RowSet{})]byte } diff --git a/v2/internal/fermyon/spin/mysql/empty.s b/v2/internal/fermyon/spin/mysql/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/mysql/mysql.wasm.go b/v2/internal/fermyon/spin/mysql/mysql.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/mysql/mysql.wit.go b/v2/internal/fermyon/spin/mysql/mysql.wit.go old mode 100755 new mode 100644 index 7ed051fa..d7888f4d --- a/v2/internal/fermyon/spin/mysql/mysql.wit.go +++ b/v2/internal/fermyon/spin/mysql/mysql.wit.go @@ -4,7 +4,7 @@ package mysql import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" ) @@ -93,7 +93,7 @@ func (self *MysqlError) OtherError() *string { return cm.Case[string](self, 5) } -var stringsMysqlError = [6]string{ +var _MysqlErrorStrings = [6]string{ "success", "connection-failed", "bad-parameter", @@ -104,7 +104,7 @@ var stringsMysqlError = [6]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v MysqlError) String() string { - return stringsMysqlError[v.Tag()] + return _MysqlErrorStrings[v.Tag()] } // Query represents the imported function "query". diff --git a/v2/internal/fermyon/spin/postgres/abi.go b/v2/internal/fermyon/spin/postgres/abi.go old mode 100755 new mode 100644 index 3b91361b..5190ca2b --- a/v2/internal/fermyon/spin/postgres/abi.go +++ b/v2/internal/fermyon/spin/postgres/abi.go @@ -3,7 +3,6 @@ package postgres import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,7 +10,7 @@ import ( // RowSetShape is used for storage in variant or result types. type RowSetShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte + shape [unsafe.Sizeof(RowSet{})]byte } // PgErrorShape is used for storage in variant or result types. diff --git a/v2/internal/fermyon/spin/postgres/empty.s b/v2/internal/fermyon/spin/postgres/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/postgres/postgres.wasm.go b/v2/internal/fermyon/spin/postgres/postgres.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/postgres/postgres.wit.go b/v2/internal/fermyon/spin/postgres/postgres.wit.go old mode 100755 new mode 100644 index 2ad2aecb..31523eae --- a/v2/internal/fermyon/spin/postgres/postgres.wit.go +++ b/v2/internal/fermyon/spin/postgres/postgres.wit.go @@ -4,7 +4,7 @@ package postgres import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" ) @@ -93,7 +93,7 @@ func (self *PgError) OtherError() *string { return cm.Case[string](self, 5) } -var stringsPgError = [6]string{ +var _PgErrorStrings = [6]string{ "success", "connection-failed", "bad-parameter", @@ -104,7 +104,7 @@ var stringsPgError = [6]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v PgError) String() string { - return stringsPgError[v.Tag()] + return _PgErrorStrings[v.Tag()] } // Query represents the imported function "query". diff --git a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go old mode 100755 new mode 100644 index fd5e5b19..0af33555 --- a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go +++ b/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go @@ -44,7 +44,7 @@ const ( DbDataTypeOther ) -var stringsDbDataType = [14]string{ +var _DbDataTypeStrings = [14]string{ "boolean", "int8", "int16", @@ -63,9 +63,22 @@ var stringsDbDataType = [14]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e DbDataType) String() string { - return stringsDbDataType[e] + return _DbDataTypeStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e DbDataType) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *DbDataType) UnmarshalText(text []byte) error { + return _DbDataTypeUnmarshalCase(e, text) +} + +var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) + // DbValue represents the variant "fermyon:spin/rdbms-types#db-value". // // variant db-value { @@ -239,7 +252,7 @@ func (self *DbValue) Unsupported() bool { return self.Tag() == 14 } -var stringsDbValue = [15]string{ +var _DbValueStrings = [15]string{ "boolean", "int8", "int16", @@ -259,7 +272,7 @@ var stringsDbValue = [15]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v DbValue) String() string { - return stringsDbValue[v.Tag()] + return _DbValueStrings[v.Tag()] } // ParameterValue represents the variant "fermyon:spin/rdbms-types#parameter-value". @@ -423,7 +436,7 @@ func (self *ParameterValue) DbNull() bool { return self.Tag() == 13 } -var stringsParameterValue = [14]string{ +var _ParameterValueStrings = [14]string{ "boolean", "int8", "int16", @@ -442,7 +455,7 @@ var stringsParameterValue = [14]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v ParameterValue) String() string { - return stringsParameterValue[v.Tag()] + return _ParameterValueStrings[v.Tag()] } // Column represents the record "fermyon:spin/rdbms-types#column". @@ -452,9 +465,9 @@ func (v ParameterValue) String() string { // data-type: db-data-type, // } type Column struct { - _ cm.HostLayout - Name string - DataType DbDataType + _ cm.HostLayout `json:"-"` + Name string `json:"name"` + DataType DbDataType `json:"data-type"` } // Row represents the list "fermyon:spin/rdbms-types#row". @@ -469,7 +482,7 @@ type Row cm.List[DbValue] // rows: list, // } type RowSet struct { - _ cm.HostLayout - Columns cm.List[Column] - Rows cm.List[Row] + _ cm.HostLayout `json:"-"` + Columns cm.List[Column] `json:"columns"` + Rows cm.List[Row] `json:"rows"` } diff --git a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go old mode 100755 new mode 100644 index 4d35c5d8..9d4147ca --- a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go +++ b/v2/internal/fermyon/spin/redis-types/redis-types.wit.go @@ -22,16 +22,29 @@ const ( ErrorError ) -var stringsError = [2]string{ +var _ErrorStrings = [2]string{ "success", "error", } // String implements [fmt.Stringer], returning the enum case name of e. func (e Error) String() string { - return stringsError[e] + return _ErrorStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e Error) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *Error) UnmarshalText(text []byte) error { + return _ErrorUnmarshalCase(e, text) +} + +var _ErrorUnmarshalCase = cm.CaseUnmarshaler[Error](_ErrorStrings[:]) + // Payload represents the list "fermyon:spin/redis-types#payload". // // The message payload. @@ -69,14 +82,14 @@ func (self *RedisParameter) Binary() *Payload { return cm.Case[Payload](self, 1) } -var stringsRedisParameter = [2]string{ +var _RedisParameterStrings = [2]string{ "int64", "binary", } // String implements [fmt.Stringer], returning the variant case name of v. func (v RedisParameter) String() string { - return stringsRedisParameter[v.Tag()] + return _RedisParameterStrings[v.Tag()] } // RedisResult represents the variant "fermyon:spin/redis-types#redis-result". @@ -132,7 +145,7 @@ func (self *RedisResult) Binary() *Payload { return cm.Case[Payload](self, 3) } -var stringsRedisResult = [4]string{ +var _RedisResultStrings = [4]string{ "nil", "status", "int64", @@ -141,5 +154,5 @@ var stringsRedisResult = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v RedisResult) String() string { - return stringsRedisResult[v.Tag()] + return _RedisResultStrings[v.Tag()] } diff --git a/v2/internal/fermyon/spin/redis/empty.s b/v2/internal/fermyon/spin/redis/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/redis/redis.wasm.go b/v2/internal/fermyon/spin/redis/redis.wasm.go old mode 100755 new mode 100644 index b5dfc7a5..b474f609 --- a/v2/internal/fermyon/spin/redis/redis.wasm.go +++ b/v2/internal/fermyon/spin/redis/redis.wasm.go @@ -3,7 +3,6 @@ package redis import ( - redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" "go.bytecodealliance.org/cm" ) @@ -15,7 +14,7 @@ func wasmimport_Publish(address0 *uint8, address1 uint32, channel0 *uint8, chann //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]) +func wasmimport_Get(address0 *uint8, address1 uint32, key0 *uint8, key1 uint32, result *cm.Result[Payload, Payload, Error]) //go:wasmimport fermyon:spin/redis set //go:noescape diff --git a/v2/internal/fermyon/spin/redis/redis.wit.go b/v2/internal/fermyon/spin/redis/redis.wit.go old mode 100755 new mode 100644 index 27e5e653..c8672af6 --- a/v2/internal/fermyon/spin/redis/redis.wit.go +++ b/v2/internal/fermyon/spin/redis/redis.wit.go @@ -4,7 +4,7 @@ package redis import ( - redistypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/redis-types" + redistypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/redis-types" "go.bytecodealliance.org/cm" ) @@ -51,7 +51,7 @@ func Publish(address string, channel string, payload Payload) (result cm.Result[ // get: func(address: string, key: string) -> result // //go:nosplit -func Get(address string, key string) (result cm.Result[redistypes.Payload, Payload, Error]) { +func Get(address string, key string) (result cm.Result[Payload, Payload, Error]) { address0, address1 := cm.LowerString(address) key0, key1 := cm.LowerString(key) wasmimport_Get((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) diff --git a/v2/internal/fermyon/spin/sqlite/abi.go b/v2/internal/fermyon/spin/sqlite/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/sqlite/empty.s b/v2/internal/fermyon/spin/sqlite/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go b/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go old mode 100755 new mode 100644 index 00d54d2f..5e029b82 --- a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/sqlite/sqlite.wit.go @@ -92,7 +92,7 @@ func (self *Error) IO() *string { return cm.Case[string](self, 4) } -var stringsError = [5]string{ +var _ErrorStrings = [5]string{ "no-such-database", "access-denied", "invalid-connection", @@ -102,7 +102,7 @@ var stringsError = [5]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Value represents the variant "fermyon:spin/sqlite#value". @@ -167,7 +167,7 @@ func (self *Value) Null() bool { return self.Tag() == 4 } -var stringsValue = [5]string{ +var _ValueStrings = [5]string{ "integer", "real", "text", @@ -177,7 +177,7 @@ var stringsValue = [5]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Value) String() string { - return stringsValue[v.Tag()] + return _ValueStrings[v.Tag()] } // RowResult represents the record "fermyon:spin/sqlite#row-result". @@ -188,8 +188,8 @@ func (v Value) String() string { // values: list, // } type RowResult struct { - _ cm.HostLayout - Values cm.List[Value] + _ cm.HostLayout `json:"-"` + Values cm.List[Value] `json:"values"` } // QueryResult represents the record "fermyon:spin/sqlite#query-result". @@ -201,12 +201,12 @@ type RowResult struct { // rows: list, // } type QueryResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The names of the columns retrieved in the query - Columns cm.List[string] + Columns cm.List[string] `json:"columns"` // the row results each containing the values for all the columns for a given row - Rows cm.List[RowResult] + Rows cm.List[RowResult] `json:"rows"` } // Open represents the imported function "open". 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 deleted file mode 100755 index 37bed5e2..00000000 --- a/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit +++ /dev/null @@ -1,3121 +0,0 @@ -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/http-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/key-value.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/key-value/keyvalue.wasm.go rename to v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go 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 old mode 100755 new mode 100644 index 5b83d032..bf8e7f74 --- 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 @@ -181,7 +181,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } -var stringsError = [4]string{ +var _ErrorStrings = [4]string{ "store-table-full", "no-such-store", "access-denied", @@ -190,5 +190,5 @@ var stringsError = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go b/v2/internal/fermyon/spin/v2.0.0/llm/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/empty.s b/v2/internal/fermyon/spin/v2.0.0/llm/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 9c5582bb..db7f1e02 --- 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,26 +29,26 @@ type InferencingModel string // top-p: f32, // } type InferencingParams struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The maximum tokens that should be inferred. // // Note: the backing implementation may return less tokens. - MaxTokens uint32 + MaxTokens uint32 `json:"max-tokens"` // The amount the model should avoid repeating tokens. - RepeatPenalty float32 + RepeatPenalty float32 `json:"repeat-penalty"` // The number of tokens the model should apply the repeat penalty to. - RepeatPenaltyLastNTokenCount uint32 + RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` // The randomness with which the next token is selected. - Temperature float32 + Temperature float32 `json:"temperature"` // The number of possible next tokens the model will choose from. - TopK uint32 + TopK uint32 `json:"top-k"` // The probability total of next tokens the model will choose from. - TopP float32 + TopP float32 `json:"top-p"` } // Error represents the variant "fermyon:spin/llm@2.0.0#error". @@ -93,7 +93,7 @@ func (self *Error) InvalidInput() *string { return cm.Case[string](self, 2) } -var stringsError = [3]string{ +var _ErrorStrings = [3]string{ "model-not-supported", "runtime-error", "invalid-input", @@ -101,7 +101,7 @@ var stringsError = [3]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // InferencingUsage represents the record "fermyon:spin/llm@2.0.0#inferencing-usage". @@ -113,12 +113,12 @@ func (v Error) String() string { // generated-token-count: u32, // } type InferencingUsage struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // Number of tokens in the prompt - PromptTokenCount uint32 + PromptTokenCount uint32 `json:"prompt-token-count"` // Number of tokens generated by the inferencing operation - GeneratedTokenCount uint32 + GeneratedTokenCount uint32 `json:"generated-token-count"` } // InferencingResult represents the record "fermyon:spin/llm@2.0.0#inferencing-result". @@ -130,13 +130,13 @@ type InferencingUsage struct { // usage: inferencing-usage, // } type InferencingResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The text generated by the model // TODO: this should be a stream - Text string + Text string `json:"text"` // Usage information about the inferencing request - Usage InferencingUsage + Usage InferencingUsage `json:"usage"` } // EmbeddingModel represents the string "fermyon:spin/llm@2.0.0#embedding-model". @@ -154,9 +154,9 @@ type EmbeddingModel string // prompt-token-count: u32, // } type EmbeddingsUsage struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // Number of tokens in the prompt - PromptTokenCount uint32 + PromptTokenCount uint32 `json:"prompt-token-count"` } // EmbeddingsResult represents the record "fermyon:spin/llm@2.0.0#embeddings-result". @@ -168,12 +168,12 @@ type EmbeddingsUsage struct { // usage: embeddings-usage, // } type EmbeddingsResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The embeddings generated by the request - Embeddings cm.List[cm.List[float32]] + Embeddings cm.List[cm.List[float32]] `json:"embeddings"` // Usage related to the embeddings generation request - Usage EmbeddingsUsage + Usage EmbeddingsUsage `json:"usage"` } // Infer represents the imported function "infer". diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go b/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s b/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 9c75c603..9ab2f882 --- 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,7 +69,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } -var stringsError = [4]string{ +var _ErrorStrings = [4]string{ "invalid-address", "too-many-connections", "connection-failed", @@ -78,7 +78,7 @@ var stringsError = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Qos represents the enum "fermyon:spin/mqtt@2.0.0#qos". @@ -98,7 +98,7 @@ const ( QosExactlyOnce ) -var stringsQos = [3]string{ +var _QosStrings = [3]string{ "at-most-once", "at-least-once", "exactly-once", @@ -106,9 +106,22 @@ var stringsQos = [3]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e Qos) String() string { - return stringsQos[e] + return _QosStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e Qos) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *Qos) UnmarshalText(text []byte) error { + return _QosUnmarshalCase(e, text) +} + +var _QosUnmarshalCase = cm.CaseUnmarshaler[Qos](_QosStrings[:]) + // Connection represents the imported resource "fermyon:spin/mqtt@2.0.0#connection". // // resource connection diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go old mode 100755 new mode 100644 index 55ae0b62..8cf2987f --- a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go @@ -3,7 +3,6 @@ package mysql import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,11 +10,11 @@ import ( // ErrorShape is used for storage in variant or result types. type ErrorShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.Error{})]byte + shape [unsafe.Sizeof(Error{})]byte } // RowSetShape is used for storage in variant or result types. type RowSetShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte + shape [unsafe.Sizeof(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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 6bcf65b5..186e35d7 --- 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,7 +4,7 @@ package mysql import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go old mode 100755 new mode 100644 index 02096128..5f6c14f7 --- a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go +++ b/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go @@ -3,7 +3,6 @@ package postgres import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,11 +10,11 @@ import ( // ErrorShape is used for storage in variant or result types. type ErrorShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.Error{})]byte + shape [unsafe.Sizeof(Error{})]byte } // RowSetShape is used for storage in variant or result types. type RowSetShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(rdbmstypes.RowSet{})]byte + shape [unsafe.Sizeof(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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index cdd27d58..51270c90 --- 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,7 +4,7 @@ package postgres import ( - rdbmstypes "github.com/fermyon/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 index dc0f3c10..093b7e2d --- 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,7 +70,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 4) } -var stringsError = [5]string{ +var _ErrorStrings = [5]string{ "connection-failed", "bad-parameter", "query-failed", @@ -80,7 +80,7 @@ var stringsError = [5]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // DbDataType represents the enum "fermyon:spin/rdbms-types@2.0.0#db-data-type". @@ -122,7 +122,7 @@ const ( DbDataTypeOther ) -var stringsDbDataType = [14]string{ +var _DbDataTypeStrings = [14]string{ "boolean", "int8", "int16", @@ -141,9 +141,22 @@ var stringsDbDataType = [14]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e DbDataType) String() string { - return stringsDbDataType[e] + return _DbDataTypeStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e DbDataType) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *DbDataType) UnmarshalText(text []byte) error { + return _DbDataTypeUnmarshalCase(e, text) +} + +var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) + // DbValue represents the variant "fermyon:spin/rdbms-types@2.0.0#db-value". // // Database values @@ -319,7 +332,7 @@ func (self *DbValue) Unsupported() bool { return self.Tag() == 14 } -var stringsDbValue = [15]string{ +var _DbValueStrings = [15]string{ "boolean", "int8", "int16", @@ -339,7 +352,7 @@ var stringsDbValue = [15]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v DbValue) String() string { - return stringsDbValue[v.Tag()] + return _DbValueStrings[v.Tag()] } // ParameterValue represents the variant "fermyon:spin/rdbms-types@2.0.0#parameter-value". @@ -505,7 +518,7 @@ func (self *ParameterValue) DbNull() bool { return self.Tag() == 13 } -var stringsParameterValue = [14]string{ +var _ParameterValueStrings = [14]string{ "boolean", "int8", "int16", @@ -524,7 +537,7 @@ var stringsParameterValue = [14]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v ParameterValue) String() string { - return stringsParameterValue[v.Tag()] + return _ParameterValueStrings[v.Tag()] } // Column represents the record "fermyon:spin/rdbms-types@2.0.0#column". @@ -536,9 +549,9 @@ func (v ParameterValue) String() string { // data-type: db-data-type, // } type Column struct { - _ cm.HostLayout - Name string - DataType DbDataType + _ cm.HostLayout `json:"-"` + Name string `json:"name"` + DataType DbDataType `json:"data-type"` } // Row represents the list "fermyon:spin/rdbms-types@2.0.0#row". @@ -557,7 +570,7 @@ type Row cm.List[DbValue] // rows: list, // } type RowSet struct { - _ cm.HostLayout - Columns cm.List[Column] - Rows cm.List[Row] + _ cm.HostLayout `json:"-"` + Columns cm.List[Column] `json:"columns"` + Rows cm.List[Row] `json:"rows"` } diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go b/v2/internal/fermyon/spin/v2.0.0/redis/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/empty.s b/v2/internal/fermyon/spin/v2.0.0/redis/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index f75f5cd3..4a092f21 --- 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,7 +70,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } -var stringsError = [4]string{ +var _ErrorStrings = [4]string{ "invalid-address", "too-many-connections", "type-error", @@ -79,7 +79,7 @@ var stringsError = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Connection represents the imported resource "fermyon:spin/redis@2.0.0#connection". @@ -290,14 +290,14 @@ func (self *RedisParameter) Binary() *Payload { return cm.Case[Payload](self, 1) } -var stringsRedisParameter = [2]string{ +var _RedisParameterStrings = [2]string{ "int64", "binary", } // String implements [fmt.Stringer], returning the variant case name of v. func (v RedisParameter) String() string { - return stringsRedisParameter[v.Tag()] + return _RedisParameterStrings[v.Tag()] } // RedisResult represents the variant "fermyon:spin/redis@2.0.0#redis-result". @@ -353,7 +353,7 @@ func (self *RedisResult) Binary() *Payload { return cm.Case[Payload](self, 3) } -var stringsRedisResult = [4]string{ +var _RedisResultStrings = [4]string{ "nil", "status", "int64", @@ -362,5 +362,5 @@ var stringsRedisResult = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v RedisResult) String() string { - return stringsRedisResult[v.Tag()] + return _RedisResultStrings[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 old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s b/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 5a9543ed..a0feadd8 --- a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go +++ b/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go @@ -136,7 +136,7 @@ func (self *Error) IO() *string { return cm.Case[string](self, 4) } -var stringsError = [5]string{ +var _ErrorStrings = [5]string{ "no-such-database", "access-denied", "invalid-connection", @@ -146,7 +146,7 @@ var stringsError = [5]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Value represents the variant "fermyon:spin/sqlite@2.0.0#value". @@ -213,7 +213,7 @@ func (self *Value) Null() bool { return self.Tag() == 4 } -var stringsValue = [5]string{ +var _ValueStrings = [5]string{ "integer", "real", "text", @@ -223,7 +223,7 @@ var stringsValue = [5]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Value) String() string { - return stringsValue[v.Tag()] + return _ValueStrings[v.Tag()] } // RowResult represents the record "fermyon:spin/sqlite@2.0.0#row-result". @@ -234,8 +234,8 @@ func (v Value) String() string { // values: list, // } type RowResult struct { - _ cm.HostLayout - Values cm.List[Value] + _ cm.HostLayout `json:"-"` + Values cm.List[Value] `json:"values"` } // QueryResult represents the record "fermyon:spin/sqlite@2.0.0#query-result". @@ -247,10 +247,10 @@ type RowResult struct { // rows: list, // } type QueryResult struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The names of the columns retrieved in the query - Columns cm.List[string] + Columns cm.List[string] `json:"columns"` // the row results each containing the values for all the columns for a given row - Rows cm.List[RowResult] + Rows cm.List[RowResult] `json:"rows"` } diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/abi.go b/v2/internal/fermyon/spin/v2.0.0/variables/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/empty.s b/v2/internal/fermyon/spin/v2.0.0/variables/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index ee100691..1c406239 --- 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,7 +67,7 @@ func (self *Error) Other() *string { return cm.Case[string](self, 3) } -var stringsError = [4]string{ +var _ErrorStrings = [4]string{ "invalid-name", "undefined", "provider", @@ -76,7 +76,7 @@ var stringsError = [4]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Error) String() string { - return stringsError[v.Tag()] + return _ErrorStrings[v.Tag()] } // Get represents the imported function "get". diff --git a/v2/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go b/v2/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go new file mode 100644 index 00000000..b0cdd90d --- /dev/null +++ b/v2/internal/fermyon/spin/v3.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@3.0.0". +// +// The full world of a guest targeting an http-trigger +package httptrigger diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/abi.go b/v2/internal/spin/postgres/v3.0.0/postgres/abi.go new file mode 100644 index 00000000..e388ef69 --- /dev/null +++ b/v2/internal/spin/postgres/v3.0.0/postgres/abi.go @@ -0,0 +1,26 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// TupleS32U8U8U8U8U8U32Shape is used for storage in variant or result types. +type TupleS32U8U8U8U8U8U32Shape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]{})]byte +} + +// ErrorShape is used for storage in variant or result types. +type ErrorShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(Error{})]byte +} + +// RowSetShape is used for storage in variant or result types. +type RowSetShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(RowSet{})]byte +} diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/empty.s b/v2/internal/spin/postgres/v3.0.0/postgres/empty.s new file mode 100644 index 00000000..5444f200 --- /dev/null +++ b/v2/internal/spin/postgres/v3.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/spin/postgres/v3.0.0/postgres/postgres.wasm.go b/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go new file mode 100644 index 00000000..96304e3e --- /dev/null +++ b/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go @@ -0,0 +1,25 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package postgres + +import ( + "go.bytecodealliance.org/cm" +) + +// This file contains wasmimport and wasmexport declarations for "spin:postgres@3.0.0". + +//go:wasmimport spin:postgres/postgres@3.0.0 [resource-drop]connection +//go:noescape +func wasmimport_ConnectionResourceDrop(self0 uint32) + +//go:wasmimport spin:postgres/postgres@3.0.0 [static]connection.open +//go:noescape +func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) + +//go:wasmimport spin:postgres/postgres@3.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 spin:postgres/postgres@3.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/spin/postgres/v3.0.0/postgres/postgres.wit.go b/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go new file mode 100644 index 00000000..fe0bd785 --- /dev/null +++ b/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go @@ -0,0 +1,657 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package postgres represents the imported interface "spin:postgres/postgres@3.0.0". +package postgres + +import ( + "go.bytecodealliance.org/cm" +) + +// Error represents the variant "spin:postgres/postgres@3.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) +} + +var _ErrorStrings = [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 _ErrorStrings[v.Tag()] +} + +// DbDataType represents the enum "spin:postgres/postgres@3.0.0#db-data-type". +// +// Data types for a database column +// +// enum db-data-type { +// boolean, +// int8, +// int16, +// int32, +// int64, +// floating32, +// floating64, +// str, +// binary, +// date, +// time, +// datetime, +// timestamp, +// other +// } +type DbDataType uint8 + +const ( + DbDataTypeBoolean DbDataType = iota + DbDataTypeInt8 + DbDataTypeInt16 + DbDataTypeInt32 + DbDataTypeInt64 + DbDataTypeFloating32 + DbDataTypeFloating64 + DbDataTypeStr + DbDataTypeBinary + DbDataTypeDate + DbDataTypeTime + DbDataTypeDateTime + DbDataTypeTimestamp + DbDataTypeOther +) + +var _DbDataTypeStrings = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "floating32", + "floating64", + "str", + "binary", + "date", + "time", + "datetime", + "timestamp", + "other", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e DbDataType) String() string { + return _DbDataTypeStrings[e] +} + +// MarshalText implements [encoding.TextMarshaler]. +func (e DbDataType) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *DbDataType) UnmarshalText(text []byte) error { + return _DbDataTypeUnmarshalCase(e, text) +} + +var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) + +// DbValue represents the variant "spin:postgres/postgres@3.0.0#db-value". +// +// Database values +// +// variant db-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// date(tuple), +// time(tuple), +// datetime(tuple), +// timestamp(s64), +// db-null, +// unsupported, +// } +type DbValue cm.Variant[uint8, TupleS32U8U8U8U8U8U32Shape, 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) +} + +// DbValueFloating32 returns a [DbValue] of case "floating32". +func DbValueFloating32(data float32) DbValue { + return cm.New[DbValue](5, data) +} + +// Floating32 returns a non-nil *[float32] if [DbValue] represents the variant case "floating32". +func (self *DbValue) Floating32() *float32 { + return cm.Case[float32](self, 5) +} + +// DbValueFloating64 returns a [DbValue] of case "floating64". +func DbValueFloating64(data float64) DbValue { + return cm.New[DbValue](6, data) +} + +// Floating64 returns a non-nil *[float64] if [DbValue] represents the variant case "floating64". +func (self *DbValue) Floating64() *float64 { + return cm.Case[float64](self, 6) +} + +// DbValueStr returns a [DbValue] of case "str". +func DbValueStr(data string) DbValue { + return cm.New[DbValue](7, data) +} + +// Str returns a non-nil *[string] if [DbValue] represents the variant case "str". +func (self *DbValue) Str() *string { + return cm.Case[string](self, 7) +} + +// DbValueBinary returns a [DbValue] of case "binary". +func DbValueBinary(data cm.List[uint8]) DbValue { + return cm.New[DbValue](8, 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, 8) +} + +// DbValueDate returns a [DbValue] of case "date". +func DbValueDate(data cm.Tuple3[int32, uint8, uint8]) DbValue { + return cm.New[DbValue](9, data) +} + +// Date returns a non-nil *[cm.Tuple3[int32, uint8, uint8]] if [DbValue] represents the variant case "date". +func (self *DbValue) Date() *cm.Tuple3[int32, uint8, uint8] { + return cm.Case[cm.Tuple3[int32, uint8, uint8]](self, 9) +} + +// DbValueTime returns a [DbValue] of case "time". +// +// (year, month, day) +func DbValueTime(data cm.Tuple4[uint8, uint8, uint8, uint32]) DbValue { + return cm.New[DbValue](10, data) +} + +// Time returns a non-nil *[cm.Tuple4[uint8, uint8, uint8, uint32]] if [DbValue] represents the variant case "time". +func (self *DbValue) Time() *cm.Tuple4[uint8, uint8, uint8, uint32] { + return cm.Case[cm.Tuple4[uint8, uint8, uint8, uint32]](self, 10) +} + +// DbValueDateTime returns a [DbValue] of case "datetime". +// +// (hour, minute, second, nanosecond) +// Date-time types are always treated as UTC (without timezone info). +// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) +// tuple. +func DbValueDateTime(data cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) DbValue { + return cm.New[DbValue](11, data) +} + +// DateTime returns a non-nil *[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]] if [DbValue] represents the variant case "datetime". +func (self *DbValue) DateTime() *cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { + return cm.Case[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]](self, 11) +} + +// DbValueTimestamp returns a [DbValue] of case "timestamp". +// +// Unix timestamp (seconds since epoch) +func DbValueTimestamp(data int64) DbValue { + return cm.New[DbValue](12, data) +} + +// Timestamp returns a non-nil *[int64] if [DbValue] represents the variant case "timestamp". +func (self *DbValue) Timestamp() *int64 { + return cm.Case[int64](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 +} + +var _DbValueStrings = [15]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "floating32", + "floating64", + "str", + "binary", + "date", + "time", + "datetime", + "timestamp", + "db-null", + "unsupported", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v DbValue) String() string { + return _DbValueStrings[v.Tag()] +} + +// ParameterValue represents the variant "spin:postgres/postgres@3.0.0#parameter-value". +// +// Values used in parameterized queries +// +// variant parameter-value { +// boolean(bool), +// int8(s8), +// int16(s16), +// int32(s32), +// int64(s64), +// floating32(f32), +// floating64(f64), +// str(string), +// binary(list), +// date(tuple), +// time(tuple), +// datetime(tuple), +// timestamp(s64), +// db-null, +// } +type ParameterValue cm.Variant[uint8, TupleS32U8U8U8U8U8U32Shape, 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) +} + +// ParameterValueFloating32 returns a [ParameterValue] of case "floating32". +func ParameterValueFloating32(data float32) ParameterValue { + return cm.New[ParameterValue](5, data) +} + +// Floating32 returns a non-nil *[float32] if [ParameterValue] represents the variant case "floating32". +func (self *ParameterValue) Floating32() *float32 { + return cm.Case[float32](self, 5) +} + +// ParameterValueFloating64 returns a [ParameterValue] of case "floating64". +func ParameterValueFloating64(data float64) ParameterValue { + return cm.New[ParameterValue](6, data) +} + +// Floating64 returns a non-nil *[float64] if [ParameterValue] represents the variant case "floating64". +func (self *ParameterValue) Floating64() *float64 { + return cm.Case[float64](self, 6) +} + +// ParameterValueStr returns a [ParameterValue] of case "str". +func ParameterValueStr(data string) ParameterValue { + return cm.New[ParameterValue](7, data) +} + +// Str returns a non-nil *[string] if [ParameterValue] represents the variant case "str". +func (self *ParameterValue) Str() *string { + return cm.Case[string](self, 7) +} + +// ParameterValueBinary returns a [ParameterValue] of case "binary". +func ParameterValueBinary(data cm.List[uint8]) ParameterValue { + return cm.New[ParameterValue](8, 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, 8) +} + +// ParameterValueDate returns a [ParameterValue] of case "date". +func ParameterValueDate(data cm.Tuple3[int32, uint8, uint8]) ParameterValue { + return cm.New[ParameterValue](9, data) +} + +// Date returns a non-nil *[cm.Tuple3[int32, uint8, uint8]] if [ParameterValue] represents the variant case "date". +func (self *ParameterValue) Date() *cm.Tuple3[int32, uint8, uint8] { + return cm.Case[cm.Tuple3[int32, uint8, uint8]](self, 9) +} + +// ParameterValueTime returns a [ParameterValue] of case "time". +// +// (year, month, day) +func ParameterValueTime(data cm.Tuple4[uint8, uint8, uint8, uint32]) ParameterValue { + return cm.New[ParameterValue](10, data) +} + +// Time returns a non-nil *[cm.Tuple4[uint8, uint8, uint8, uint32]] if [ParameterValue] represents the variant case "time". +func (self *ParameterValue) Time() *cm.Tuple4[uint8, uint8, uint8, uint32] { + return cm.Case[cm.Tuple4[uint8, uint8, uint8, uint32]](self, 10) +} + +// ParameterValueDateTime returns a [ParameterValue] of case "datetime". +// +// (hour, minute, second, nanosecond) +// Date-time types are always treated as UTC (without timezone info). +// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) +// tuple. +func ParameterValueDateTime(data cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) ParameterValue { + return cm.New[ParameterValue](11, data) +} + +// DateTime returns a non-nil *[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]] if [ParameterValue] represents the variant case "datetime". +func (self *ParameterValue) DateTime() *cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { + return cm.Case[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]](self, 11) +} + +// ParameterValueTimestamp returns a [ParameterValue] of case "timestamp". +// +// Unix timestamp (seconds since epoch) +func ParameterValueTimestamp(data int64) ParameterValue { + return cm.New[ParameterValue](12, data) +} + +// Timestamp returns a non-nil *[int64] if [ParameterValue] represents the variant case "timestamp". +func (self *ParameterValue) Timestamp() *int64 { + return cm.Case[int64](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 +} + +var _ParameterValueStrings = [14]string{ + "boolean", + "int8", + "int16", + "int32", + "int64", + "floating32", + "floating64", + "str", + "binary", + "date", + "time", + "datetime", + "timestamp", + "db-null", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v ParameterValue) String() string { + return _ParameterValueStrings[v.Tag()] +} + +// Column represents the record "spin:postgres/postgres@3.0.0#column". +// +// A database column +// +// record column { +// name: string, +// data-type: db-data-type, +// } +type Column struct { + _ cm.HostLayout `json:"-"` + Name string `json:"name"` + DataType DbDataType `json:"data-type"` +} + +// Row represents the list "spin:postgres/postgres@3.0.0#row". +// +// A database row +// +// type row = list +type Row cm.List[DbValue] + +// RowSet represents the record "spin:postgres/postgres@3.0.0#row-set". +// +// A set of database rows +// +// record row-set { +// columns: list, +// rows: list, +// } +type RowSet struct { + _ cm.HostLayout `json:"-"` + Columns cm.List[Column] `json:"columns"` + Rows cm.List[Row] `json:"rows"` +} + +// Connection represents the imported resource "spin:postgres/postgres@3.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 +} + +// 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, Error]) { + address0, address1 := cm.LowerString(address) + wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} + +// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) + return +} diff --git a/v2/internal/wasi/cli/v0.2.0/environment/empty.s b/v2/internal/wasi/cli/v0.2.0/environment/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/cli/v0.2.0/exit/empty.s b/v2/internal/wasi/cli/v0.2.0/exit/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index d38d9432..947fa253 --- a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go +++ b/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -15,7 +15,7 @@ import ( // //go:nosplit func Exit(status cm.BoolResult) { - status0 := cm.BoolToU32(status) + status0 := (uint32)(cm.BoolToU32(status)) wasmimport_Exit((uint32)(status0)) return } diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/empty.s b/v2/internal/wasi/cli/v0.2.0/stderr/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 18d3e9a0..1358235a --- 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,7 +4,7 @@ package stderr import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/empty.s b/v2/internal/wasi/cli/v0.2.0/stdin/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 8fbf65f0..4d83364d --- 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,7 +4,7 @@ package stdin import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/empty.s b/v2/internal/wasi/cli/v0.2.0/stdout/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index a0baaa6f..8e34da3f --- 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,7 +4,7 @@ package stdout import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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/terminal-input.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-input/terminalinput.wasm.go rename to v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/terminal-output.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-output/terminaloutput.wasm.go rename to v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/terminal-stderr.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminalstderr.wasm.go rename to v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go 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 old mode 100755 new mode 100644 index aac4668e..4ff295fb --- 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,7 +7,7 @@ package terminalstderr import ( - terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + terminaloutput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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/terminal-stdin.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminalstdin.wasm.go rename to v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go 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 old mode 100755 new mode 100644 index 6f4137d5..3f8ae91e --- 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,7 +7,7 @@ package terminalstdin import ( - terminalinput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" + terminalinput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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/terminal-stdout.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminalstdout.wasm.go rename to v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go 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 old mode 100755 new mode 100644 index 434f95d3..564967dc --- 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,7 +7,7 @@ package terminalstdout import ( - terminaloutput "github.com/fermyon/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + terminaloutput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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/monotonic-clock.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonicclock.wasm.go rename to v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go 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 old mode 100755 new mode 100644 index 2f124a68..dfaa9fde --- 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,7 +15,7 @@ package monotonicclock import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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/wall-clock.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/wall-clock/wallclock.wasm.go rename to v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go 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 old mode 100755 new mode 100644 index 2d31e9b4..9c0a9684 --- 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 @@ -31,9 +31,9 @@ import ( // nanoseconds: u32, // } type DateTime struct { - _ cm.HostLayout - Seconds uint64 - Nanoseconds uint32 + _ cm.HostLayout `json:"-"` + Seconds uint64 `json:"seconds"` + Nanoseconds uint32 `json:"nanoseconds"` } // Now represents the imported function "now". diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go new file mode 100644 index 00000000..b7ad11d2 --- /dev/null +++ b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package store + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// OptionStringShape is used for storage in variant or result types. +type OptionStringShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(cm.Option[string]{})]byte +} + +// 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/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s new file mode 100644 index 00000000..5444f200 --- /dev/null +++ b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/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/config/v0.2.0-draft-2024-09-27/store/store.wasm.go b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go new file mode 100644 index 00000000..abc3b560 --- /dev/null +++ b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go @@ -0,0 +1,17 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package store + +import ( + "go.bytecodealliance.org/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:config@0.2.0-draft-2024-09-27". + +//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get +//go:noescape +func wasmimport_Get(key0 *uint8, key1 uint32, result *cm.Result[OptionStringShape, cm.Option[string], Error]) + +//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get-all +//go:noescape +func wasmimport_GetAll(result *cm.Result[ErrorShape, cm.List[[2]string], Error]) diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go new file mode 100644 index 00000000..15909a1a --- /dev/null +++ b/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go @@ -0,0 +1,92 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package store represents the imported interface "wasi:config/store@0.2.0-draft-2024-09-27". +package store + +import ( + "go.bytecodealliance.org/cm" +) + +// Error represents the variant "wasi:config/store@0.2.0-draft-2024-09-27#error". +// +// An error type that encapsulates the different errors that can occur fetching configuration +// values. +// +// variant error { +// upstream(string), +// io(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorUpstream returns a [Error] of case "upstream". +// +// This indicates an error from an "upstream" config source. +// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue +// buckets, etc), +// the error message is a string. +func ErrorUpstream(data string) Error { + return cm.New[Error](0, data) +} + +// Upstream returns a non-nil *[string] if [Error] represents the variant case "upstream". +func (self *Error) Upstream() *string { + return cm.Case[string](self, 0) +} + +// ErrorIO returns a [Error] of case "io". +// +// This indicates an error from an I/O operation. +// As this could be almost _anything_ (such as a file read, network connection, etc), +// the error message is a string. +// Depending on how this ends up being consumed, +// we may consider moving this to use the `wasi:io/error` type instead. +// For simplicity right now in supporting multiple implementations, it is being left +// as a string. +func ErrorIO(data string) Error { + return cm.New[Error](1, data) +} + +// IO returns a non-nil *[string] if [Error] represents the variant case "io". +func (self *Error) IO() *string { + return cm.Case[string](self, 1) +} + +var _ErrorStrings = [2]string{ + "upstream", + "io", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return _ErrorStrings[v.Tag()] +} + +// Get represents the imported function "get". +// +// Gets a configuration value of type `string` associated with the `key`. +// +// The value is returned as an `option`. If the key is not found, +// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned. +// +// get: func(key: string) -> result, error> +// +//go:nosplit +func Get(key string) (result cm.Result[OptionStringShape, cm.Option[string], Error]) { + key0, key1 := cm.LowerString(key) + wasmimport_Get((*uint8)(key0), (uint32)(key1), &result) + return +} + +// GetAll represents the imported function "get-all". +// +// Gets a list of configuration key-value pairs of type `string`. +// +// If an error occurs, an `Err(error)` is returned. +// +// get-all: func() -> result>, error> +// +//go:nosplit +func GetAll() (result cm.Result[ErrorShape, cm.List[[2]string], Error]) { + wasmimport_GetAll(&result) + return +} diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s b/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index fc57b942..7a8f2d1e --- 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,7 +4,7 @@ package preopens import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go old mode 100755 new mode 100644 index 81e99e91..7b981dfe --- a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go +++ b/v2/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -3,7 +3,7 @@ package types import ( - wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" + wallclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" "go.bytecodealliance.org/cm" "unsafe" ) @@ -30,7 +30,7 @@ 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()) + v1, v2 := lower_DateTime(*cm.Case[DateTime](&v, 2)) f1 = (uint64)(v1) f2 = (uint32)(v2) } diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/empty.s b/v2/internal/wasi/filesystem/v0.2.0/types/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 50826b3a..8b1c5af5 --- 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,8 +29,8 @@ package types import ( - wallclock "github.com/fermyon/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + wallclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) @@ -106,7 +106,7 @@ const ( DescriptorTypeSocket ) -var stringsDescriptorType = [8]string{ +var _DescriptorTypeStrings = [8]string{ "unknown", "block-device", "character-device", @@ -119,9 +119,22 @@ var stringsDescriptorType = [8]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e DescriptorType) String() string { - return stringsDescriptorType[e] + return _DescriptorTypeStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e DescriptorType) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *DescriptorType) UnmarshalText(text []byte) error { + return _DescriptorTypeUnmarshalCase(e, text) +} + +var _DescriptorTypeUnmarshalCase = cm.CaseUnmarshaler[DescriptorType](_DescriptorTypeStrings[:]) + // DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". // // Descriptor flags. @@ -246,34 +259,34 @@ type LinkCount uint64 // status-change-timestamp: option, // } type DescriptorStat struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // File type. - Type DescriptorType + Type DescriptorType `json:"type"` // Number of hard links to the file. - LinkCount LinkCount + LinkCount LinkCount `json:"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 + Size FileSize `json:"size"` // Last data access timestamp. // // If the `option` is none, the platform doesn't maintain an access // timestamp for this file. - DataAccessTimestamp cm.Option[DateTime] + DataAccessTimestamp cm.Option[DateTime] `json:"data-access-timestamp"` // Last data modification timestamp. // // If the `option` is none, the platform doesn't maintain a // modification timestamp for this file. - DataModificationTimestamp cm.Option[DateTime] + DataModificationTimestamp cm.Option[DateTime] `json:"data-modification-timestamp"` // 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[DateTime] + StatusChangeTimestamp cm.Option[DateTime] `json:"status-change-timestamp"` } // NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". @@ -326,7 +339,7 @@ func (self *NewTimestamp) Timestamp() *DateTime { return cm.Case[DateTime](self, 2) } -var stringsNewTimestamp = [3]string{ +var _NewTimestampStrings = [3]string{ "no-change", "now", "timestamp", @@ -334,7 +347,7 @@ var stringsNewTimestamp = [3]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v NewTimestamp) String() string { - return stringsNewTimestamp[v.Tag()] + return _NewTimestampStrings[v.Tag()] } // DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". @@ -346,12 +359,12 @@ func (v NewTimestamp) String() string { // name: string, // } type DirectoryEntry struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The type of the file referred to by this directory entry. - Type DescriptorType + Type DescriptorType `json:"type"` // The name of the object. - Name string + Name string `json:"name"` } // ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". @@ -516,7 +529,7 @@ const ( ErrorCodeCrossDevice ) -var stringsErrorCode = [37]string{ +var _ErrorCodeStrings = [37]string{ "access", "would-block", "already", @@ -558,9 +571,22 @@ var stringsErrorCode = [37]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e ErrorCode) String() string { - return stringsErrorCode[e] + return _ErrorCodeStrings[e] +} + +// MarshalText implements [encoding.TextMarshaler]. +func (e ErrorCode) MarshalText() ([]byte, error) { + return []byte(e.String()), nil } +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *ErrorCode) UnmarshalText(text []byte) error { + return _ErrorCodeUnmarshalCase(e, text) +} + +var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:]) + // Advice represents the enum "wasi:filesystem/types@0.2.0#advice". // // File or memory access pattern advisory information. @@ -601,7 +627,7 @@ const ( AdviceNoReuse ) -var stringsAdvice = [6]string{ +var _AdviceStrings = [6]string{ "normal", "sequential", "random", @@ -612,9 +638,22 @@ var stringsAdvice = [6]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e Advice) String() string { - return stringsAdvice[e] + return _AdviceStrings[e] +} + +// MarshalText implements [encoding.TextMarshaler]. +func (e Advice) MarshalText() ([]byte, error) { + return []byte(e.String()), nil } +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *Advice) UnmarshalText(text []byte) error { + return _AdviceUnmarshalCase(e, text) +} + +var _AdviceUnmarshalCase = cm.CaseUnmarshaler[Advice](_AdviceStrings[:]) + // 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 @@ -625,12 +664,12 @@ func (e Advice) String() string { // upper: u64, // } type MetadataHashValue struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // 64 bits of a 128-bit hash value. - Lower uint64 + Lower uint64 `json:"lower"` // Another 64 bits of a 128-bit hash value. - Upper uint64 + Upper uint64 `json:"upper"` } // Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". @@ -761,7 +800,7 @@ 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)) + result = (bool)(cm.U32ToBool((uint32)(result0))) return } 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/incoming-handler.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/http/v0.2.0/incoming-handler/incominghandler.wasm.go rename to v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go 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 old mode 100755 new mode 100644 index d4d1e04b..0e3d66c9 --- 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,7 +7,7 @@ package incominghandler import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" ) // IncomingRequest represents the exported type alias "wasi:http/incoming-handler@0.2.0#incoming-request". 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 old mode 100755 new mode 100644 index 1a61628d..cdc17d0d --- 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,7 +3,6 @@ package outgoinghandler import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,7 +10,7 @@ import ( // ErrorCodeShape is used for storage in variant or result types. type ErrorCodeShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(types.ErrorCode{})]byte + shape [unsafe.Sizeof(ErrorCode{})]byte } func lower_OptionRequestOptions(v cm.Option[RequestOptions]) (f0 uint32, f1 uint32) { 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 old mode 100755 new mode 100644 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/outgoing-handler.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoinghandler.wasm.go rename to v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go 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 old mode 100755 new mode 100644 index e252f626..fc7455f3 --- 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,7 +7,7 @@ package outgoinghandler import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/http/v0.2.0/types/abi.go b/v2/internal/wasi/http/v0.2.0/types/abi.go old mode 100755 new mode 100644 index a7281fac..6ffb1fdd --- a/v2/internal/wasi/http/v0.2.0/types/abi.go +++ b/v2/internal/wasi/http/v0.2.0/types/abi.go @@ -28,7 +28,7 @@ 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()) + v1, v2 := cm.LowerString(*cm.Case[string](&v, 9)) f1 = (*uint8)(v1) f2 = (uint32)(v2) } @@ -39,7 +39,7 @@ 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()) + v1, v2 := cm.LowerString(*cm.Case[string](&v, 2)) f1 = (*uint8)(v1) f2 = (uint32)(v2) } @@ -150,86 +150,86 @@ func lower_ErrorCode(v ErrorCode) (f0 uint32, f1 uint32, f2 uint64, f3 uint32, f f0 = (uint32)(v.Tag()) switch f0 { case 1: // DNS-error - v1, v2, v3, v4, v5 := lower_DNSErrorPayload(*v.DNSError()) + v1, v2, v3, v4, v5 := lower_DNSErrorPayload(*cm.Case[DNSErrorPayload](&v, 1)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(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()) + v1, v2, v3, v4, v5 := lower_TLSAlertReceivedPayload(*cm.Case[TLSAlertReceivedPayload](&v, 14)) f1 = (uint32)(v1) f2 = (uint64)(v2) f3 = (uint32)(v3) - f4 = cm.PointerToU32(v4) + f4 = (uint32)(cm.PointerToU32(v4)) f5 = (uint32)(v5) case 17: // HTTP-request-body-size - v1, v2 := lower_OptionU64(*v.HTTPRequestBodySize()) + v1, v2 := lower_OptionU64(*cm.Case[cm.Option[uint64]](&v, 17)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 21: // HTTP-request-header-section-size - v1, v2 := lower_OptionU32(*v.HTTPRequestHeaderSectionSize()) + v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 21)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 22: // HTTP-request-header-size - v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*v.HTTPRequestHeaderSize()) + v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*cm.Case[cm.Option[FieldSizePayload]](&v, 22)) f1 = (uint32)(v1) f2 = (uint64)(v2) - f3 = cm.PointerToU32(v3) + f3 = (uint32)(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()) + v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 23)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 24: // HTTP-request-trailer-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPRequestTrailerSize()) + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 24)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(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()) + v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 26)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 27: // HTTP-response-header-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseHeaderSize()) + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 27)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(cm.PointerToU64(v2)) f3 = (uint32)(v3) f4 = (uint32)(v4) f5 = (uint32)(v5) case 28: // HTTP-response-body-size - v1, v2 := lower_OptionU64(*v.HTTPResponseBodySize()) + v1, v2 := lower_OptionU64(*cm.Case[cm.Option[uint64]](&v, 28)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 29: // HTTP-response-trailer-section-size - v1, v2 := lower_OptionU32(*v.HTTPResponseTrailerSectionSize()) + v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 29)) f1 = (uint32)(v1) f2 = (uint64)(v2) case 30: // HTTP-response-trailer-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseTrailerSize()) + v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 30)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(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()) + v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 31)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(cm.PointerToU64(v2)) f3 = (uint32)(v3) case 32: // HTTP-response-content-coding - v1, v2, v3 := lower_OptionString(*v.HTTPResponseContentCoding()) + v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 32)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(cm.PointerToU64(v2)) f3 = (uint32)(v3) case 38: // internal-error - v1, v2, v3 := lower_OptionString(*v.InternalError()) + v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 38)) f1 = (uint32)(v1) - f2 = cm.PointerToU64(v2) + f2 = (uint64)(cm.PointerToU64(v2)) f3 = (uint32)(v3) } return diff --git a/v2/internal/wasi/http/v0.2.0/types/empty.s b/v2/internal/wasi/http/v0.2.0/types/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 1b9a264f..68bfe2ec --- 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,10 +8,10 @@ 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" + monotonicclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" + ioerror "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) @@ -167,7 +167,7 @@ func (self *Method) Other() *string { return cm.Case[string](self, 9) } -var stringsMethod = [10]string{ +var _MethodStrings = [10]string{ "get", "head", "post", @@ -182,7 +182,7 @@ var stringsMethod = [10]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Method) String() string { - return stringsMethod[v.Tag()] + return _MethodStrings[v.Tag()] } // Scheme represents the variant "wasi:http/types@0.2.0#scheme". @@ -228,7 +228,7 @@ func (self *Scheme) Other() *string { return cm.Case[string](self, 2) } -var stringsScheme = [3]string{ +var _SchemeStrings = [3]string{ "HTTP", "HTTPS", "other", @@ -236,7 +236,7 @@ var stringsScheme = [3]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v Scheme) String() string { - return stringsScheme[v.Tag()] + return _SchemeStrings[v.Tag()] } // DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". @@ -248,9 +248,9 @@ func (v Scheme) String() string { // info-code: option, // } type DNSErrorPayload struct { - _ cm.HostLayout - Rcode cm.Option[string] - InfoCode cm.Option[uint16] + _ cm.HostLayout `json:"-"` + Rcode cm.Option[string] `json:"rcode"` + InfoCode cm.Option[uint16] `json:"info-code"` } // TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.0#TLS-alert-received-payload". @@ -262,9 +262,9 @@ type DNSErrorPayload struct { // alert-message: option, // } type TLSAlertReceivedPayload struct { - _ cm.HostLayout - AlertID cm.Option[uint8] - AlertMessage cm.Option[string] + _ cm.HostLayout `json:"-"` + AlertID cm.Option[uint8] `json:"alert-id"` + AlertMessage cm.Option[string] `json:"alert-message"` } // FieldSizePayload represents the record "wasi:http/types@0.2.0#field-size-payload". @@ -276,9 +276,9 @@ type TLSAlertReceivedPayload struct { // field-size: option, // } type FieldSizePayload struct { - _ cm.HostLayout - FieldName cm.Option[string] - FieldSize cm.Option[uint32] + _ cm.HostLayout `json:"-"` + FieldName cm.Option[string] `json:"field-name"` + FieldSize cm.Option[uint32] `json:"field-size"` } // ErrorCode represents the variant "wasi:http/types@0.2.0#error-code". @@ -749,7 +749,7 @@ func (self *ErrorCode) InternalError() *cm.Option[string] { return cm.Case[cm.Option[string]](self, 38) } -var stringsErrorCode = [39]string{ +var _ErrorCodeStrings = [39]string{ "DNS-timeout", "DNS-error", "destination-not-found", @@ -793,7 +793,7 @@ var stringsErrorCode = [39]string{ // String implements [fmt.Stringer], returning the variant case name of v. func (v ErrorCode) String() string { - return stringsErrorCode[v.Tag()] + return _ErrorCodeStrings[v.Tag()] } // HeaderError represents the variant "wasi:http/types@0.2.0#header-error". @@ -823,7 +823,7 @@ const ( HeaderErrorImmutable ) -var stringsHeaderError = [3]string{ +var _HeaderErrorStrings = [3]string{ "invalid-syntax", "forbidden", "immutable", @@ -831,9 +831,22 @@ var stringsHeaderError = [3]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e HeaderError) String() string { - return stringsHeaderError[e] + return _HeaderErrorStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e HeaderError) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *HeaderError) UnmarshalText(text []byte) error { + return _HeaderErrorUnmarshalCase(e, text) +} + +var _HeaderErrorUnmarshalCase = cm.CaseUnmarshaler[HeaderError](_HeaderErrorStrings[:]) + // FieldKey represents the string "wasi:http/types@0.2.0#field-key". // // Field keys are always strings. @@ -1018,7 +1031,7 @@ 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)) + result = (bool)(cm.U32ToBool((uint32)(result0))) return } @@ -1305,7 +1318,7 @@ func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1321,7 +1334,7 @@ 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1338,7 +1351,7 @@ func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (r 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1355,7 +1368,7 @@ func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolR 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1448,7 +1461,7 @@ func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[Duration]) 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1464,7 +1477,7 @@ func (self RequestOptions) SetConnectTimeout(duration cm.Option[Duration]) (resu 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1480,7 +1493,7 @@ func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[Duration]) (re 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))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } @@ -1824,7 +1837,7 @@ func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.Boo self0 := cm.Reinterpret[uint32](self) statusCode0 := (uint32)(statusCode) result0 := wasmimport_OutgoingResponseSetStatusCode((uint32)(self0), (uint32)(statusCode0)) - result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) + result = (cm.BoolResult)((bool)(cm.U32ToBool((uint32)(result0)))) return } diff --git a/v2/internal/wasi/io/v0.2.0/error/empty.s b/v2/internal/wasi/io/v0.2.0/error/empty.s old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go b/v2/internal/wasi/io/v0.2.0/error/error.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/io/v0.2.0/error/ioerror.wasm.go rename to v2/internal/wasi/io/v0.2.0/error/error.wasm.go 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 old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/io/v0.2.0/poll/empty.s b/v2/internal/wasi/io/v0.2.0/poll/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 0c7973fe..10c0033b --- a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go +++ b/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -57,7 +57,7 @@ func (self Pollable) Block() { func (self Pollable) Ready() (result bool) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_PollableReady((uint32)(self0)) - result = cm.U32ToBool((uint32)(result0)) + result = (bool)(cm.U32ToBool((uint32)(result0))) return } diff --git a/v2/internal/wasi/io/v0.2.0/streams/empty.s b/v2/internal/wasi/io/v0.2.0/streams/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 076408ba..6e258eed --- 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,8 +10,8 @@ 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" + ioerror "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" "go.bytecodealliance.org/cm" ) @@ -64,14 +64,14 @@ func (self *StreamError) Closed() bool { return self.Tag() == 1 } -var stringsStreamError = [2]string{ +var _StreamErrorStrings = [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()] + return _StreamErrorStrings[v.Tag()] } // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". @@ -273,13 +273,13 @@ func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm // // 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; +// // 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` @@ -309,12 +309,12 @@ func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result // // 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; +// // 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` diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go new file mode 100644 index 00000000..20fb0c89 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go @@ -0,0 +1,20 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package atomics + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go new file mode 100644 index 00000000..a2357d75 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go @@ -0,0 +1,29 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package atomics + +import ( + "go.bytecodealliance.org/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [resource-drop]cas +//go:noescape +func wasmimport_CasResourceDrop(self0 uint32) + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [static]cas.new +//go:noescape +func wasmimport_CasNew(bucket0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, Cas, Error]) + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [method]cas.current +//go:noescape +func wasmimport_CasCurrent(self0 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 increment +//go:noescape +func wasmimport_Increment(bucket0 uint32, key0 *uint8, key1 uint32, delta0 uint64, result *cm.Result[ErrorShape, int64, Error]) + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 swap +//go:noescape +func wasmimport_Swap(cas0 uint32, value0 *uint8, value1 uint32, result *cm.Result[CasError, struct{}, CasError]) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go new file mode 100644 index 00000000..205fbe12 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go @@ -0,0 +1,171 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package atomics represents the imported interface "wasi:keyvalue/atomics@0.2.0-draft2". +// +// A keyvalue interface that provides atomic operations. +// +// Atomic operations are single, indivisible operations. When a fault causes an atomic +// operation to +// fail, it will appear to the invoker of the atomic operation that the action either +// completed +// successfully or did nothing at all. +// +// Please note that this interface is bare functions that take a reference to a bucket. +// This is to +// get around the current lack of a way to "extend" a resource with additional methods +// inside of +// wit. Future version of the interface will instead extend these methods on the base +// `bucket` +// resource. +package atomics + +import ( + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/keyvalue/v0.2.0-draft2/store" + "go.bytecodealliance.org/cm" +) + +// Bucket represents the imported type alias "wasi:keyvalue/atomics@0.2.0-draft2#bucket". +// +// See [store.Bucket] for more information. +type Bucket = store.Bucket + +// Error represents the type alias "wasi:keyvalue/atomics@0.2.0-draft2#error". +// +// See [store.Error] for more information. +type Error = store.Error + +// Cas represents the imported resource "wasi:keyvalue/atomics@0.2.0-draft2#cas". +// +// A handle to a CAS (compare-and-swap) operation. +// +// resource cas +type Cas cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "cas". +// +// Drops a resource handle. +// +//go:nosplit +func (self Cas) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_CasResourceDrop((uint32)(self0)) + return +} + +// CasNew represents the imported static function "new". +// +// Construct a new CAS operation. Implementors can map the underlying functionality +// (transactions, versions, etc) as desired. +// +// new: static func(bucket: borrow, key: string) -> result +// +//go:nosplit +func CasNew(bucket Bucket, key string) (result cm.Result[ErrorShape, Cas, Error]) { + bucket0 := cm.Reinterpret[uint32](bucket) + key0, key1 := cm.LowerString(key) + wasmimport_CasNew((uint32)(bucket0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// Current represents the imported method "current". +// +// Get the current value of the key (if it exists). This allows for avoiding reads +// if all +// that is needed to ensure the atomicity of the operation +// +// current: func() -> result>, error> +// +//go:nosplit +func (self Cas) Current() (result cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_CasCurrent((uint32)(self0), &result) + return +} + +// CasError represents the imported variant "wasi:keyvalue/atomics@0.2.0-draft2#cas-error". +// +// The error returned by a CAS operation +// +// variant cas-error { +// store-error(error), +// cas-failed(cas), +// } +type CasError cm.Variant[uint8, ErrorShape, Error] + +// CasErrorStoreError returns a [CasError] of case "store-error". +// +// A store error occurred when performing the operation +func CasErrorStoreError(data Error) CasError { + return cm.New[CasError](0, data) +} + +// StoreError returns a non-nil *[Error] if [CasError] represents the variant case "store-error". +func (self *CasError) StoreError() *Error { + return cm.Case[Error](self, 0) +} + +// CasErrorCasFailed returns a [CasError] of case "cas-failed". +// +// The CAS operation failed because the value was too old. This returns a new CAS +// handle +// for easy retries. Implementors MUST return a CAS handle that has been updated to +// the +// latest version or transaction. +func CasErrorCasFailed(data Cas) CasError { + return cm.New[CasError](1, data) +} + +// CasFailed returns a non-nil *[Cas] if [CasError] represents the variant case "cas-failed". +func (self *CasError) CasFailed() *Cas { + return cm.Case[Cas](self, 1) +} + +var _CasErrorStrings = [2]string{ + "store-error", + "cas-failed", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v CasError) String() string { + return _CasErrorStrings[v.Tag()] +} + +// Increment represents the imported function "increment". +// +// Atomically increment the value associated with the key in the store by the given +// delta. It +// returns the new value. +// +// If the key does not exist in the store, it creates a new key-value pair with the +// value set +// to the given delta. +// +// If any other error occurs, it returns an `Err(error)`. +// +// increment: func(bucket: borrow, key: string, delta: s64) -> result +// +//go:nosplit +func Increment(bucket Bucket, key string, delta int64) (result cm.Result[ErrorShape, int64, Error]) { + bucket0 := cm.Reinterpret[uint32](bucket) + key0, key1 := cm.LowerString(key) + delta0 := (uint64)(delta) + wasmimport_Increment((uint32)(bucket0), (*uint8)(key0), (uint32)(key1), (uint64)(delta0), &result) + return +} + +// Swap represents the imported function "swap". +// +// Perform the swap on a CAS operation. This consumes the CAS handle and returns an +// error if +// the CAS operation failed. +// +// swap: func(cas: cas, value: list) -> result<_, cas-error> +// +//go:nosplit +func Swap(cas Cas, value cm.List[uint8]) (result cm.Result[CasError, struct{}, CasError]) { + cas0 := cm.Reinterpret[uint32](cas) + value0, value1 := cm.LowerList(value) + wasmimport_Swap((uint32)(cas0), (*uint8)(value0), (uint32)(value1), &result) + return +} diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s new file mode 100644 index 00000000..5444f200 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/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/keyvalue/v0.2.0-draft2/batch/abi.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go new file mode 100644 index 00000000..9b6592ee --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go @@ -0,0 +1,14 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package batch + +import ( + "go.bytecodealliance.org/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/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go new file mode 100644 index 00000000..ea801e79 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go @@ -0,0 +1,21 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package batch + +import ( + "go.bytecodealliance.org/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 get-many +//go:noescape +func wasmimport_GetMany(bucket0 uint32, keys0 *string, keys1 uint32, result *cm.Result[ErrorShape, cm.List[cm.Tuple[string, cm.Option[cm.List[uint8]]]], Error]) + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 set-many +//go:noescape +func wasmimport_SetMany(bucket0 uint32, keyValues0 *cm.Tuple[string, cm.List[uint8]], keyValues1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 delete-many +//go:noescape +func wasmimport_DeleteMany(bucket0 uint32, keys0 *string, keys1 uint32, result *cm.Result[Error, struct{}, Error]) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go new file mode 100644 index 00000000..b1ca7152 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go @@ -0,0 +1,134 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package batch represents the imported interface "wasi:keyvalue/batch@0.2.0-draft2". +// +// A keyvalue interface that provides batch operations. +// +// A batch operation is an operation that operates on multiple keys at once. +// +// Batch operations are useful for reducing network round-trip time. For example, +// if you want to +// get the values associated with 100 keys, you can either do 100 get operations or +// you can do 1 +// batch get operation. The batch operation is faster because it only needs to make +// 1 network call +// instead of 100. +// +// A batch operation does not guarantee atomicity, meaning that if the batch operation +// fails, some +// of the keys may have been modified and some may not. +// +// This interface does has the same consistency guarantees as the `store` interface, +// meaning that +// you should be able to "read your writes." +// +// Please note that this interface is bare functions that take a reference to a bucket. +// This is to +// get around the current lack of a way to "extend" a resource with additional methods +// inside of +// wit. Future version of the interface will instead extend these methods on the base +// `bucket` +// resource. +package batch + +import ( + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/keyvalue/v0.2.0-draft2/store" + "go.bytecodealliance.org/cm" +) + +// Bucket represents the imported type alias "wasi:keyvalue/batch@0.2.0-draft2#bucket". +// +// See [store.Bucket] for more information. +type Bucket = store.Bucket + +// Error represents the type alias "wasi:keyvalue/batch@0.2.0-draft2#error". +// +// See [store.Error] for more information. +type Error = store.Error + +// GetMany represents the imported function "get-many". +// +// Get the key-value pairs associated with the keys in the store. It returns a list +// of +// key-value pairs. +// +// If any of the keys do not exist in the store, it returns a `none` value for that +// pair in the +// list. +// +// MAY show an out-of-date value if there are concurrent writes to the store. +// +// If any other error occurs, it returns an `Err(error)`. +// +// get-many: func(bucket: borrow, keys: list) -> result>>>, error> +// +//go:nosplit +func GetMany(bucket Bucket, keys cm.List[string]) (result cm.Result[ErrorShape, cm.List[cm.Tuple[string, cm.Option[cm.List[uint8]]]], Error]) { + bucket0 := cm.Reinterpret[uint32](bucket) + keys0, keys1 := cm.LowerList(keys) + wasmimport_GetMany((uint32)(bucket0), (*string)(keys0), (uint32)(keys1), &result) + return +} + +// SetMany represents the imported function "set-many". +// +// Set the values associated with the keys in the store. If the key already exists +// in the +// store, it overwrites the value. +// +// Note that the key-value pairs are not guaranteed to be set in the order they are +// provided. +// +// If any of the keys do not exist in the store, it creates a new key-value pair. +// +// If any other error occurs, it returns an `Err(error)`. When an error occurs, it +// does not +// rollback the key-value pairs that were already set. Thus, this batch operation +// does not +// guarantee atomicity, implying that some key-value pairs could be set while others +// might +// fail. +// +// Other concurrent operations may also be able to see the partial results. +// +// set-many: func(bucket: borrow, key-values: list>>) +// -> result<_, error> +// +//go:nosplit +func SetMany(bucket Bucket, keyValues cm.List[cm.Tuple[string, cm.List[uint8]]]) (result cm.Result[Error, struct{}, Error]) { + bucket0 := cm.Reinterpret[uint32](bucket) + keyValues0, keyValues1 := cm.LowerList(keyValues) + wasmimport_SetMany((uint32)(bucket0), (*cm.Tuple[string, cm.List[uint8]])(keyValues0), (uint32)(keyValues1), &result) + return +} + +// DeleteMany represents the imported function "delete-many". +// +// Delete the key-value pairs associated with the keys in the store. +// +// Note that the key-value pairs are not guaranteed to be deleted in the order they +// are +// provided. +// +// If any of the keys do not exist in the store, it skips the key. +// +// If any other error occurs, it returns an `Err(error)`. When an error occurs, it +// does not +// rollback the key-value pairs that were already deleted. Thus, this batch operation +// does not +// guarantee atomicity, implying that some key-value pairs could be deleted while +// others might +// fail. +// +// Other concurrent operations may also be able to see the partial results. +// +// delete-many: func(bucket: borrow, keys: list) -> result<_, error> +// +//go:nosplit +func DeleteMany(bucket Bucket, keys cm.List[string]) (result cm.Result[Error, struct{}, Error]) { + bucket0 := cm.Reinterpret[uint32](bucket) + keys0, keys1 := cm.LowerList(keys) + wasmimport_DeleteMany((uint32)(bucket0), (*string)(keys0), (uint32)(keys1), &result) + return +} diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s new file mode 100644 index 00000000..5444f200 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/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/keyvalue/v0.2.0-draft2/store/abi.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go new file mode 100644 index 00000000..8e92daf7 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go @@ -0,0 +1,37 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package store + +import ( + "go.bytecodealliance.org/cm" + "unsafe" +) + +// 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 +} + +// KeyResponseShape is used for storage in variant or result types. +type KeyResponseShape struct { + _ cm.HostLayout + shape [unsafe.Sizeof(KeyResponse{})]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 +} diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s new file mode 100644 index 00000000..5444f200 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/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/keyvalue/v0.2.0-draft2/store/store.wasm.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go new file mode 100644 index 00000000..58f1a36b --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go @@ -0,0 +1,37 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +package store + +import ( + "go.bytecodealliance.org/cm" +) + +// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [resource-drop]bucket +//go:noescape +func wasmimport_BucketResourceDrop(self0 uint32) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.delete +//go:noescape +func wasmimport_BucketDelete(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.exists +//go:noescape +func wasmimport_BucketExists(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.get +//go:noescape +func wasmimport_BucketGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.list-keys +//go:noescape +func wasmimport_BucketListKeys(self0 uint32, cursor0 uint32, cursor1 *uint8, cursor2 uint32, result *cm.Result[KeyResponseShape, KeyResponse, Error]) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.set +//go:noescape +func wasmimport_BucketSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 open +//go:noescape +func wasmimport_Open(identifier0 *uint8, identifier1 uint32, result *cm.Result[ErrorShape, Bucket, Error]) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go new file mode 100644 index 00000000..3aca4200 --- /dev/null +++ b/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go @@ -0,0 +1,294 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package store represents the imported interface "wasi:keyvalue/store@0.2.0-draft2". +// +// A keyvalue interface that provides eventually consistent key-value operations. +// +// Each of these operations acts on a single key-value pair. +// +// The value in the key-value pair is defined as a `u8` byte array and the intention +// is that it is +// the common denominator for all data types defined by different key-value stores +// to handle data, +// ensuring compatibility between different key-value stores. Note: the clients will +// be expecting +// serialization/deserialization overhead to be handled by the key-value store. The +// value could be +// a serialized object from JSON, HTML or vendor-specific data types like AWS S3 objects. +// +// Data consistency in a key value store refers to the guarantee that once a write +// operation +// completes, all subsequent read operations will return the value that was written. +// +// Any implementation of this interface must have enough consistency to guarantee +// "reading your +// writes." In particular, this means that the client should never get a value that +// is older than +// the one it wrote, but it MAY get a newer value if one was written around the same +// time. These +// guarantees only apply to the same client (which will likely be provided by the +// host or an +// external capability of some kind). In this context a "client" is referring to the +// caller or +// guest that is consuming this interface. Once a write request is committed by a +// specific client, +// all subsequent read requests by the same client will reflect that write or any +// subsequent +// writes. Another client running in a different context may or may not immediately +// see the result +// due to the replication lag. As an example of all of this, if a value at a given +// key is A, and +// the client writes B, then immediately reads, it should get B. If something else +// writes C in +// quick succession, then the client may get C. However, a client running in a separate +// context may +// still see A or B +package store + +import ( + "go.bytecodealliance.org/cm" +) + +// Error represents the variant "wasi:keyvalue/store@0.2.0-draft2#error". +// +// The set of errors which may be raised by functions in this package +// +// variant error { +// no-such-store, +// access-denied, +// other(string), +// } +type Error cm.Variant[uint8, string, string] + +// ErrorNoSuchStore returns a [Error] of case "no-such-store". +// +// The host does not recognize the store identifier requested. +func ErrorNoSuchStore() Error { + var data struct{} + return cm.New[Error](0, data) +} + +// NoSuchStore returns true if [Error] represents the variant case "no-such-store". +func (self *Error) NoSuchStore() bool { + return self.Tag() == 0 +} + +// 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](1, data) +} + +// AccessDenied returns true if [Error] represents the variant case "access-denied". +func (self *Error) AccessDenied() bool { + return self.Tag() == 1 +} + +// 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](2, data) +} + +// Other returns a non-nil *[string] if [Error] represents the variant case "other". +func (self *Error) Other() *string { + return cm.Case[string](self, 2) +} + +var _ErrorStrings = [3]string{ + "no-such-store", + "access-denied", + "other", +} + +// String implements [fmt.Stringer], returning the variant case name of v. +func (v Error) String() string { + return _ErrorStrings[v.Tag()] +} + +// KeyResponse represents the record "wasi:keyvalue/store@0.2.0-draft2#key-response". +// +// A response to a `list-keys` operation. +// +// record key-response { +// keys: list, +// cursor: option, +// } +type KeyResponse struct { + _ cm.HostLayout `json:"-"` + // The list of keys returned by the query. + Keys cm.List[string] `json:"keys"` + + // The continuation token to use to fetch the next page of keys. If this is `null`, + // then + // there are no more keys to fetch. + Cursor cm.Option[string] `json:"cursor"` +} + +// Bucket represents the imported resource "wasi:keyvalue/store@0.2.0-draft2#bucket". +// +// A bucket is a collection of key-value pairs. Each key-value pair is stored as a +// entry in the +// bucket, and the bucket itself acts as a collection of all these entries. +// +// It is worth noting that the exact terminology for bucket in key-value stores can +// very +// depending on the specific implementation. For example: +// +// 1. Amazon DynamoDB calls a collection of key-value pairs a table +// 2. Redis has hashes, sets, and sorted sets as different types of collections +// 3. Cassandra calls a collection of key-value pairs a column family +// 4. MongoDB calls a collection of key-value pairs a collection +// 5. Riak calls a collection of key-value pairs a bucket +// 6. Memcached calls a collection of key-value pairs a slab +// 7. Azure Cosmos DB calls a collection of key-value pairs a container +// +// In this interface, we use the term `bucket` to refer to a collection of key-value +// pairs +// +// resource bucket +type Bucket cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "bucket". +// +// Drops a resource handle. +// +//go:nosplit +func (self Bucket) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_BucketResourceDrop((uint32)(self0)) + return +} + +// Delete represents the imported method "delete". +// +// Delete the key-value pair associated with the key in the store. +// +// If the key does not exist in the store, it does nothing. +// +// If any other error occurs, it returns an `Err(error)`. +// +// delete: func(key: string) -> result<_, error> +// +//go:nosplit +func (self Bucket) Delete(key string) (result cm.Result[Error, struct{}, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_BucketDelete((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// Exists represents the imported method "exists". +// +// Check if the key exists in the store. +// +// If the key exists in the store, it returns `Ok(true)`. If the key does +// not exist in the store, it returns `Ok(false)`. +// +// If any other error occurs, it returns an `Err(error)`. +// +// exists: func(key: string) -> result +// +//go:nosplit +func (self Bucket) Exists(key string) (result cm.Result[ErrorShape, bool, Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_BucketExists((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// Get represents the imported method "get". +// +// Get the value associated with the specified `key` +// +// The value is returned as an option. If the key-value pair exists in the +// store, it returns `Ok(value)`. If the key does not exist in the +// store, it returns `Ok(none)`. +// +// If any other error occurs, it returns an `Err(error)`. +// +// get: func(key: string) -> result>, error> +// +//go:nosplit +func (self Bucket) Get(key string) (result cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) { + self0 := cm.Reinterpret[uint32](self) + key0, key1 := cm.LowerString(key) + wasmimport_BucketGet((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) + return +} + +// ListKeys represents the imported method "list-keys". +// +// Get all the keys in the store with an optional cursor (for use in pagination). +// It +// returns a list of keys. Please note that for most KeyValue implementations, this +// is a +// can be a very expensive operation and so it should be used judiciously. Implementations +// can return any number of keys in a single response, but they should never attempt +// to +// send more data than is reasonable (i.e. on a small edge device, this may only be +// a few +// KB, while on a large machine this could be several MB). Any response should also +// return +// a cursor that can be used to fetch the next page of keys. See the `key-response` +// record +// for more information. +// +// Note that the keys are not guaranteed to be returned in any particular order. +// +// If the store is empty, it returns an empty list. +// +// MAY show an out-of-date list of keys if there are concurrent writes to the store. +// +// If any error occurs, it returns an `Err(error)`. +// +// list-keys: func(cursor: option) -> result +// +//go:nosplit +func (self Bucket) ListKeys(cursor cm.Option[string]) (result cm.Result[KeyResponseShape, KeyResponse, Error]) { + self0 := cm.Reinterpret[uint32](self) + cursor0, cursor1, cursor2 := lower_OptionString(cursor) + wasmimport_BucketListKeys((uint32)(self0), (uint32)(cursor0), (*uint8)(cursor1), (uint32)(cursor2), &result) + return +} + +// Set represents the imported method "set". +// +// Set the value associated with the key in the store. If the key already +// exists in the store, it overwrites the value. +// +// If the key does not exist in the store, it creates a new key-value pair. +// +// If any other error occurs, it returns an `Err(error)`. +// +// set: func(key: string, value: list) -> result<_, error> +// +//go:nosplit +func (self Bucket) 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_BucketSet((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) + return +} + +// Open represents the imported function "open". +// +// Get the bucket with the specified identifier. +// +// `identifier` must refer to a bucket provided by the host. +// +// `error::no-such-store` will be raised if the `identifier` is not recognized. +// +// open: func(identifier: string) -> result +// +//go:nosplit +func Open(identifier string) (result cm.Result[ErrorShape, Bucket, Error]) { + identifier0, identifier1 := cm.LowerString(identifier) + wasmimport_Open((*uint8)(identifier0), (uint32)(identifier1), &result) + return +} 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 old mode 100755 new mode 100644 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/insecure-seed.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure-seed/insecureseed.wasm.go rename to v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go 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 old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/random/v0.2.0/insecure/empty.s b/v2/internal/wasi/random/v0.2.0/insecure/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/random/v0.2.0/random/empty.s b/v2/internal/wasi/random/v0.2.0/random/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/instance-network.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/instance-network/instancenetwork.wasm.go rename to v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go 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 old mode 100755 new mode 100644 index 657fb465..fee8730e --- 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,7 +6,7 @@ package instancenetwork import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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/ip-name-lookup.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ipnamelookup.wasm.go rename to v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go 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 old mode 100755 new mode 100644 index 5cc32084..63a5fbe9 --- 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,8 +4,8 @@ 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/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/network/abi.go b/v2/internal/wasi/sockets/v0.2.0/network/abi.go old mode 100755 new mode 100644 diff --git a/v2/internal/wasi/sockets/v0.2.0/network/empty.s b/v2/internal/wasi/sockets/v0.2.0/network/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 53c2252f..a37b5b9a --- a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go +++ b/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -153,7 +153,7 @@ const ( ErrorCodePermanentResolverFailure ) -var stringsErrorCode = [21]string{ +var _ErrorCodeStrings = [21]string{ "unknown", "access-denied", "not-supported", @@ -179,9 +179,22 @@ var stringsErrorCode = [21]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e ErrorCode) String() string { - return stringsErrorCode[e] + return _ErrorCodeStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e ErrorCode) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *ErrorCode) UnmarshalText(text []byte) error { + return _ErrorCodeUnmarshalCase(e, text) +} + +var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:]) + // IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". // // enum ip-address-family { @@ -198,16 +211,29 @@ const ( IPAddressFamilyIPv6 ) -var stringsIPAddressFamily = [2]string{ +var _IPAddressFamilyStrings = [2]string{ "ipv4", "ipv6", } // String implements [fmt.Stringer], returning the enum case name of e. func (e IPAddressFamily) String() string { - return stringsIPAddressFamily[e] + return _IPAddressFamilyStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e IPAddressFamily) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *IPAddressFamily) UnmarshalText(text []byte) error { + return _IPAddressFamilyUnmarshalCase(e, text) +} + +var _IPAddressFamilyUnmarshalCase = cm.CaseUnmarshaler[IPAddressFamily](_IPAddressFamilyStrings[:]) + // IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". // // type ipv4-address = tuple @@ -246,14 +272,14 @@ func (self *IPAddress) IPv6() *IPv6Address { return cm.Case[IPv6Address](self, 1) } -var stringsIPAddress = [2]string{ +var _IPAddressStrings = [2]string{ "ipv4", "ipv6", } // String implements [fmt.Stringer], returning the variant case name of v. func (v IPAddress) String() string { - return stringsIPAddress[v.Tag()] + return _IPAddressStrings[v.Tag()] } // IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". @@ -263,12 +289,12 @@ func (v IPAddress) String() string { // address: ipv4-address, // } type IPv4SocketAddress struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // sin_port - Port uint16 + Port uint16 `json:"port"` // sin_addr - Address IPv4Address + Address IPv4Address `json:"address"` } // IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address". @@ -280,18 +306,18 @@ type IPv4SocketAddress struct { // scope-id: u32, // } type IPv6SocketAddress struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // sin6_port - Port uint16 + Port uint16 `json:"port"` // sin6_flowinfo - FlowInfo uint32 + FlowInfo uint32 `json:"flow-info"` // sin6_addr - Address IPv6Address + Address IPv6Address `json:"address"` // sin6_scope_id - ScopeID uint32 + ScopeID uint32 `json:"scope-id"` } // IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". @@ -322,12 +348,12 @@ func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { return cm.Case[IPv6SocketAddress](self, 1) } -var stringsIPSocketAddress = [2]string{ +var _IPSocketAddressStrings = [2]string{ "ipv4", "ipv6", } // String implements [fmt.Stringer], returning the variant case name of v. func (v IPSocketAddress) String() string { - return stringsIPSocketAddress[v.Tag()] + return _IPSocketAddressStrings[v.Tag()] } 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 old mode 100755 new mode 100644 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/tcp-create-socket.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcpcreatesocket.wasm.go rename to v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go 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 old mode 100755 new mode 100644 index 151ab602..44143983 --- 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,8 +4,8 @@ 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/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/tcp" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go old mode 100755 new mode 100644 index 670288cc..25c05901 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -3,7 +3,7 @@ package tcp import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" "unsafe" ) @@ -23,7 +23,7 @@ type TupleInputStreamOutputStreamShape struct { // IPSocketAddressShape is used for storage in variant or result types. type IPSocketAddressShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(network.IPSocketAddress{})]byte + shape [unsafe.Sizeof(IPSocketAddress{})]byte } func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { @@ -64,14 +64,14 @@ func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 f0 = (uint32)(v.Tag()) switch f0 { case 0: // ipv4 - v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*cm.Case[network.IPv4SocketAddress](&v, 0)) 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()) + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*cm.Case[network.IPv6SocketAddress](&v, 1)) f1 = (uint32)(v1) f2 = (uint32)(v2) f3 = (uint32)(v3) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s b/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 56247525..d6e56c26 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go +++ b/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go @@ -46,7 +46,7 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32, //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]) +func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[ErrorCode, bool, ErrorCode]) //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time //go:noescape 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 old mode 100755 new mode 100644 index 68eabf57..72131944 --- 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,10 +4,10 @@ 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" + monotonicclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) @@ -71,7 +71,7 @@ const ( ShutdownTypeBoth ) -var stringsShutdownType = [3]string{ +var _ShutdownTypeStrings = [3]string{ "receive", "send", "both", @@ -79,9 +79,22 @@ var stringsShutdownType = [3]string{ // String implements [fmt.Stringer], returning the enum case name of e. func (e ShutdownType) String() string { - return stringsShutdownType[e] + return _ShutdownTypeStrings[e] } +// MarshalText implements [encoding.TextMarshaler]. +func (e ShutdownType) MarshalText() ([]byte, error) { + return []byte(e.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum +// case. Returns an error if the supplied text is not one of the enum cases. +func (e *ShutdownType) UnmarshalText(text []byte) error { + return _ShutdownTypeUnmarshalCase(e, text) +} + +var _ShutdownTypeUnmarshalCase = cm.CaseUnmarshaler[ShutdownType](_ShutdownTypeStrings[:]) + // TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". // // A TCP socket resource. @@ -241,7 +254,7 @@ func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, ErrorCode]) { func (self TCPSocket) IsListening() (result bool) { self0 := cm.Reinterpret[uint32](self) result0 := wasmimport_TCPSocketIsListening((uint32)(self0)) - result = cm.U32ToBool((uint32)(result0)) + result = (bool)(cm.U32ToBool((uint32)(result0))) return } @@ -285,7 +298,7 @@ func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, ErrorCo // keep-alive-enabled: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, ErrorCode]) { +func (self TCPSocket) KeepAliveEnabled() (result cm.Result[ErrorCode, bool, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) return @@ -457,7 +470,7 @@ func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[ErrorCod //go:nosplit func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { self0 := cm.Reinterpret[uint32](self) - value0 := cm.BoolToU32(value) + value0 := (uint32)(cm.BoolToU32(value)) wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) return } 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 old mode 100755 new mode 100644 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/udp-create-socket.wasm.go old mode 100755 new mode 100644 similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udpcreatesocket.wasm.go rename to v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go 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 old mode 100755 new mode 100644 index dec4bc0f..c9efe70c --- 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,8 +4,8 @@ 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/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/udp" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go old mode 100755 new mode 100644 index e8cded35..babcd376 --- a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go +++ b/v2/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -3,7 +3,7 @@ package udp import ( - "github.com/fermyon/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" "unsafe" ) @@ -11,7 +11,7 @@ import ( // IPSocketAddressShape is used for storage in variant or result types. type IPSocketAddressShape struct { _ cm.HostLayout - shape [unsafe.Sizeof(network.IPSocketAddress{})]byte + shape [unsafe.Sizeof(IPSocketAddress{})]byte } func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { @@ -52,14 +52,14 @@ func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 f0 = (uint32)(v.Tag()) switch f0 { case 0: // ipv4 - v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*cm.Case[network.IPv4SocketAddress](&v, 0)) 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()) + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*cm.Case[network.IPv6SocketAddress](&v, 1)) f1 = (uint32)(v1) f2 = (uint32)(v2) f3 = (uint32)(v3) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/empty.s b/v2/internal/wasi/sockets/v0.2.0/udp/empty.s old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 index 372fcaa9..425c6e25 --- 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,8 +4,8 @@ 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/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) @@ -43,11 +43,11 @@ type IPAddressFamily = network.IPAddressFamily // remote-address: ip-socket-address, // } type IncomingDatagram struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The payload. // // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - Data cm.List[uint8] + Data cm.List[uint8] `json:"data"` // The source address. // @@ -55,7 +55,7 @@ type IncomingDatagram struct { // with, if any. // // Equivalent to the `src_addr` out parameter of `recvfrom`. - RemoteAddress IPSocketAddress + RemoteAddress IPSocketAddress `json:"remote-address"` } // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". @@ -67,9 +67,9 @@ type IncomingDatagram struct { // remote-address: option, // } type OutgoingDatagram struct { - _ cm.HostLayout + _ cm.HostLayout `json:"-"` // The payload. - Data cm.List[uint8] + Data cm.List[uint8] `json:"data"` // The destination address. // @@ -80,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[IPSocketAddress] + RemoteAddress cm.Option[IPSocketAddress] `json:"remote-address"` } // UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". @@ -321,10 +321,10 @@ func (self UDPSocket) StartBind(network_ Network, localAddress IPSocketAddress) // The POSIX equivalent in pseudo-code is: // // if (was previously connected) { -// connect(s, AF_UNSPEC) +// connect(s, AF_UNSPEC) // } // if (remote_address is Some) { -// connect(s, remote_address) +// connect(s, remote_address) // } // // Unlike in POSIX, the socket must already be explicitly bound. diff --git a/v2/wit/deps/keyvalue-2024-10-17/atomic.wit b/v2/wit/deps/keyvalue-2024-10-17/atomic.wit new file mode 100644 index 00000000..4a02c580 --- /dev/null +++ b/v2/wit/deps/keyvalue-2024-10-17/atomic.wit @@ -0,0 +1,46 @@ +/// A keyvalue interface that provides atomic operations. +/// +/// Atomic operations are single, indivisible operations. When a fault causes an atomic operation to +/// fail, it will appear to the invoker of the atomic operation that the action either completed +/// successfully or did nothing at all. +/// +/// Please note that this interface is bare functions that take a reference to a bucket. This is to +/// get around the current lack of a way to "extend" a resource with additional methods inside of +/// wit. Future version of the interface will instead extend these methods on the base `bucket` +/// resource. +interface atomics { + use store.{bucket, error}; + + /// The error returned by a CAS operation + variant cas-error { + /// A store error occurred when performing the operation + store-error(error), + /// The CAS operation failed because the value was too old. This returns a new CAS handle + /// for easy retries. Implementors MUST return a CAS handle that has been updated to the + /// latest version or transaction. + cas-failed(cas), + } + + /// A handle to a CAS (compare-and-swap) operation. + resource cas { + /// Construct a new CAS operation. Implementors can map the underlying functionality + /// (transactions, versions, etc) as desired. + new: static func(bucket: borrow, key: string) -> result; + /// Get the current value of the key (if it exists). This allows for avoiding reads if all + /// that is needed to ensure the atomicity of the operation + current: func() -> result>, error>; + } + + /// Atomically increment the value associated with the key in the store by the given delta. It + /// returns the new value. + /// + /// If the key does not exist in the store, it creates a new key-value pair with the value set + /// to the given delta. + /// + /// If any other error occurs, it returns an `Err(error)`. + increment: func(bucket: borrow, key: string, delta: s64) -> result; + + /// Perform the swap on a CAS operation. This consumes the CAS handle and returns an error if + /// the CAS operation failed. + swap: func(cas: cas, value: list) -> result<_, cas-error>; +} diff --git a/v2/wit/deps/keyvalue-2024-10-17/batch.wit b/v2/wit/deps/keyvalue-2024-10-17/batch.wit new file mode 100644 index 00000000..6d6e8735 --- /dev/null +++ b/v2/wit/deps/keyvalue-2024-10-17/batch.wit @@ -0,0 +1,63 @@ +/// A keyvalue interface that provides batch operations. +/// +/// A batch operation is an operation that operates on multiple keys at once. +/// +/// Batch operations are useful for reducing network round-trip time. For example, if you want to +/// get the values associated with 100 keys, you can either do 100 get operations or you can do 1 +/// batch get operation. The batch operation is faster because it only needs to make 1 network call +/// instead of 100. +/// +/// A batch operation does not guarantee atomicity, meaning that if the batch operation fails, some +/// of the keys may have been modified and some may not. +/// +/// This interface does has the same consistency guarantees as the `store` interface, meaning that +/// you should be able to "read your writes." +/// +/// Please note that this interface is bare functions that take a reference to a bucket. This is to +/// get around the current lack of a way to "extend" a resource with additional methods inside of +/// wit. Future version of the interface will instead extend these methods on the base `bucket` +/// resource. +interface batch { + use store.{bucket, error}; + + /// Get the key-value pairs associated with the keys in the store. It returns a list of + /// key-value pairs. + /// + /// If any of the keys do not exist in the store, it returns a `none` value for that pair in the + /// list. + /// + /// MAY show an out-of-date value if there are concurrent writes to the store. + /// + /// If any other error occurs, it returns an `Err(error)`. + get-many: func(bucket: borrow, keys: list) -> result>>>, error>; + + /// Set the values associated with the keys in the store. If the key already exists in the + /// store, it overwrites the value. + /// + /// Note that the key-value pairs are not guaranteed to be set in the order they are provided. + /// + /// If any of the keys do not exist in the store, it creates a new key-value pair. + /// + /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not + /// rollback the key-value pairs that were already set. Thus, this batch operation does not + /// guarantee atomicity, implying that some key-value pairs could be set while others might + /// fail. + /// + /// Other concurrent operations may also be able to see the partial results. + set-many: func(bucket: borrow, key-values: list>>) -> result<_, error>; + + /// Delete the key-value pairs associated with the keys in the store. + /// + /// Note that the key-value pairs are not guaranteed to be deleted in the order they are + /// provided. + /// + /// If any of the keys do not exist in the store, it skips the key. + /// + /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it does not + /// rollback the key-value pairs that were already deleted. Thus, this batch operation does not + /// guarantee atomicity, implying that some key-value pairs could be deleted while others might + /// fail. + /// + /// Other concurrent operations may also be able to see the partial results. + delete-many: func(bucket: borrow, keys: list) -> result<_, error>; +} diff --git a/v2/wit/deps/keyvalue-2024-10-17/store.wit b/v2/wit/deps/keyvalue-2024-10-17/store.wit new file mode 100644 index 00000000..c7fef411 --- /dev/null +++ b/v2/wit/deps/keyvalue-2024-10-17/store.wit @@ -0,0 +1,122 @@ +/// A keyvalue interface that provides eventually consistent key-value operations. +/// +/// Each of these operations acts on a single key-value pair. +/// +/// The value in the key-value pair is defined as a `u8` byte array and the intention is that it is +/// the common denominator for all data types defined by different key-value stores to handle data, +/// ensuring compatibility between different key-value stores. Note: the clients will be expecting +/// serialization/deserialization overhead to be handled by the key-value store. The value could be +/// a serialized object from JSON, HTML or vendor-specific data types like AWS S3 objects. +/// +/// Data consistency in a key value store refers to the guarantee that once a write operation +/// completes, all subsequent read operations will return the value that was written. +/// +/// Any implementation of this interface must have enough consistency to guarantee "reading your +/// writes." In particular, this means that the client should never get a value that is older than +/// the one it wrote, but it MAY get a newer value if one was written around the same time. These +/// guarantees only apply to the same client (which will likely be provided by the host or an +/// external capability of some kind). In this context a "client" is referring to the caller or +/// guest that is consuming this interface. Once a write request is committed by a specific client, +/// all subsequent read requests by the same client will reflect that write or any subsequent +/// writes. Another client running in a different context may or may not immediately see the result +/// due to the replication lag. As an example of all of this, if a value at a given key is A, and +/// the client writes B, then immediately reads, it should get B. If something else writes C in +/// quick succession, then the client may get C. However, a client running in a separate context may +/// still see A or B +interface store { + /// The set of errors which may be raised by functions in this package + variant error { + /// The host does not recognize the store identifier 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 response to a `list-keys` operation. + record key-response { + /// The list of keys returned by the query. + keys: list, + /// The continuation token to use to fetch the next page of keys. If this is `null`, then + /// there are no more keys to fetch. + cursor: option + } + + /// Get the bucket with the specified identifier. + /// + /// `identifier` must refer to a bucket provided by the host. + /// + /// `error::no-such-store` will be raised if the `identifier` is not recognized. + open: func(identifier: string) -> result; + + /// A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the + /// bucket, and the bucket itself acts as a collection of all these entries. + /// + /// It is worth noting that the exact terminology for bucket in key-value stores can very + /// depending on the specific implementation. For example: + /// + /// 1. Amazon DynamoDB calls a collection of key-value pairs a table + /// 2. Redis has hashes, sets, and sorted sets as different types of collections + /// 3. Cassandra calls a collection of key-value pairs a column family + /// 4. MongoDB calls a collection of key-value pairs a collection + /// 5. Riak calls a collection of key-value pairs a bucket + /// 6. Memcached calls a collection of key-value pairs a slab + /// 7. Azure Cosmos DB calls a collection of key-value pairs a container + /// + /// In this interface, we use the term `bucket` to refer to a collection of key-value pairs + resource bucket { + /// Get the value associated with the specified `key` + /// + /// The value is returned as an option. If the key-value pair exists in the + /// store, it returns `Ok(value)`. If the key does not exist in the + /// store, it returns `Ok(none)`. + /// + /// If any other error occurs, it returns an `Err(error)`. + get: func(key: string) -> result>, error>; + + /// Set the value associated with the key in the store. If the key already + /// exists in the store, it overwrites the value. + /// + /// If the key does not exist in the store, it creates a new key-value pair. + /// + /// If any other error occurs, it returns an `Err(error)`. + set: func(key: string, value: list) -> result<_, error>; + + /// Delete the key-value pair associated with the key in the store. + /// + /// If the key does not exist in the store, it does nothing. + /// + /// If any other error occurs, it returns an `Err(error)`. + delete: func(key: string) -> result<_, error>; + + /// Check if the key exists in the store. + /// + /// If the key exists in the store, it returns `Ok(true)`. If the key does + /// not exist in the store, it returns `Ok(false)`. + /// + /// If any other error occurs, it returns an `Err(error)`. + exists: func(key: string) -> result; + + /// Get all the keys in the store with an optional cursor (for use in pagination). It + /// returns a list of keys. Please note that for most KeyValue implementations, this is a + /// can be a very expensive operation and so it should be used judiciously. Implementations + /// can return any number of keys in a single response, but they should never attempt to + /// send more data than is reasonable (i.e. on a small edge device, this may only be a few + /// KB, while on a large machine this could be several MB). Any response should also return + /// a cursor that can be used to fetch the next page of keys. See the `key-response` record + /// for more information. + /// + /// Note that the keys are not guaranteed to be returned in any particular order. + /// + /// If the store is empty, it returns an empty list. + /// + /// MAY show an out-of-date list of keys if there are concurrent writes to the store. + /// + /// If any error occurs, it returns an `Err(error)`. + list-keys: func(cursor: option) -> result; + } +} diff --git a/v2/wit/deps/keyvalue-2024-10-17/watch.wit b/v2/wit/deps/keyvalue-2024-10-17/watch.wit new file mode 100644 index 00000000..92991196 --- /dev/null +++ b/v2/wit/deps/keyvalue-2024-10-17/watch.wit @@ -0,0 +1,16 @@ +/// A keyvalue interface that provides watch operations. +/// +/// This interface is used to provide event-driven mechanisms to handle +/// keyvalue changes. +interface watcher { + /// A keyvalue interface that provides handle-watch operations. + use store.{bucket}; + + /// Handle the `set` event for the given bucket and key. It includes a reference to the `bucket` + /// that can be used to interact with the store. + on-set: func(bucket: bucket, key: string, value: list); + + /// Handle the `delete` event for the given bucket and key. It includes a reference to the + /// `bucket` that can be used to interact with the store. + on-delete: func(bucket: bucket, key: string); +} diff --git a/v2/wit/deps/keyvalue-2024-10-17/world.wit b/v2/wit/deps/keyvalue-2024-10-17/world.wit new file mode 100644 index 00000000..e8fb821a --- /dev/null +++ b/v2/wit/deps/keyvalue-2024-10-17/world.wit @@ -0,0 +1,26 @@ +package wasi:keyvalue@0.2.0-draft2; + +/// The `wasi:keyvalue/imports` world provides common APIs for interacting with key-value stores. +/// Components targeting this world will be able to do: +/// +/// 1. CRUD (create, read, update, delete) operations on key-value stores. +/// 2. Atomic `increment` and CAS (compare-and-swap) operations. +/// 3. Batch operations that can reduce the number of round trips to the network. +world imports { + /// The `store` capability allows the component to perform eventually consistent operations on + /// the key-value store. + import store; + + /// The `atomic` capability allows the component to perform atomic / `increment` and CAS + /// (compare-and-swap) operations. + import atomics; + + /// The `batch` capability allows the component to perform eventually consistent batch + /// operations that can reduce the number of round trips to the network. + import batch; +} + +world watch-service { + include imports; + export watcher; +} diff --git a/v2/wit/deps/spin-postgres@3.0.0/postgres.wit b/v2/wit/deps/spin-postgres@3.0.0/postgres.wit new file mode 100644 index 00000000..55833229 --- /dev/null +++ b/v2/wit/deps/spin-postgres@3.0.0/postgres.wit @@ -0,0 +1,100 @@ +package spin:postgres@3.0.0; + +interface postgres { + /// 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, + floating32, + floating64, + str, + binary, + date, + time, + datetime, + timestamp, + other, + } + + /// Database values + variant db-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + date(tuple), // (year, month, day) + time(tuple), // (hour, minute, second, nanosecond) + /// Date-time types are always treated as UTC (without timezone info). + /// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. + datetime(tuple), + /// Unix timestamp (seconds since epoch) + timestamp(s64), + db-null, + unsupported, + } + + /// Values used in parameterized queries + variant parameter-value { + boolean(bool), + int8(s8), + int16(s16), + int32(s32), + int64(s64), + floating32(f32), + floating64(f64), + str(string), + binary(list), + date(tuple), // (year, month, day) + time(tuple), // (hour, minute, second, nanosecond) + /// Date-time types are always treated as UTC (without timezone info). + /// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. + datetime(tuple), + /// Unix timestamp (seconds since epoch) + timestamp(s64), + 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, + } + + /// 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/key-value.wit b/v2/wit/deps/spin@2.0.0/key-value.wit similarity index 100% rename from v2/wit/key-value.wit rename to v2/wit/deps/spin@2.0.0/key-value.wit diff --git a/v2/wit/llm.wit b/v2/wit/deps/spin@2.0.0/llm.wit similarity index 95% rename from v2/wit/llm.wit rename to v2/wit/deps/spin@2.0.0/llm.wit index ffed09cc..bcb59b86 100644 --- a/v2/wit/llm.wit +++ b/v2/wit/deps/spin@2.0.0/llm.wit @@ -10,15 +10,15 @@ interface llm { /// Note: the backing implementation may return less tokens. max-tokens: u32, /// The amount the model should avoid repeating tokens. - repeat-penalty: float32, + 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: float32, + 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: float32 + top-p: f32 } /// The set of errors which may be raised by functions in this interface @@ -57,7 +57,7 @@ interface llm { /// Result of generating embeddings record embeddings-result { /// The embeddings generated by the request - embeddings: list>, + embeddings: list>, /// Usage related to the embeddings generation request usage: embeddings-usage } diff --git a/v2/wit/mqtt.wit b/v2/wit/deps/spin@2.0.0/mqtt.wit similarity index 100% rename from v2/wit/mqtt.wit rename to v2/wit/deps/spin@2.0.0/mqtt.wit diff --git a/v2/wit/mysql.wit b/v2/wit/deps/spin@2.0.0/mysql.wit similarity index 100% rename from v2/wit/mysql.wit rename to v2/wit/deps/spin@2.0.0/mysql.wit diff --git a/v2/wit/postgres.wit b/v2/wit/deps/spin@2.0.0/postgres.wit similarity index 100% rename from v2/wit/postgres.wit rename to v2/wit/deps/spin@2.0.0/postgres.wit diff --git a/v2/wit/rdbms-types.wit b/v2/wit/deps/spin@2.0.0/rdbms-types.wit similarity index 92% rename from v2/wit/rdbms-types.wit rename to v2/wit/deps/spin@2.0.0/rdbms-types.wit index 64f3e59a..aff2e960 100644 --- a/v2/wit/rdbms-types.wit +++ b/v2/wit/deps/spin@2.0.0/rdbms-types.wit @@ -37,8 +37,8 @@ interface rdbms-types { uint16(u16), uint32(u32), uint64(u64), - floating32(float32), - floating64(float64), + floating32(f32), + floating64(f64), str(string), binary(list), db-null, @@ -56,8 +56,8 @@ interface rdbms-types { uint16(u16), uint32(u32), uint64(u64), - floating32(float32), - floating64(float64), + floating32(f32), + floating64(f64), str(string), binary(list), db-null, diff --git a/v2/wit/redis.wit b/v2/wit/deps/spin@2.0.0/redis.wit similarity index 100% rename from v2/wit/redis.wit rename to v2/wit/deps/spin@2.0.0/redis.wit diff --git a/v2/wit/sqlite.wit b/v2/wit/deps/spin@2.0.0/sqlite.wit similarity index 98% rename from v2/wit/sqlite.wit rename to v2/wit/deps/spin@2.0.0/sqlite.wit index 8a5ab2de..d82f2d90 100644 --- a/v2/wit/sqlite.wit +++ b/v2/wit/deps/spin@2.0.0/sqlite.wit @@ -42,7 +42,7 @@ interface sqlite { /// A single column's result from a database query variant value { integer(s64), - real(float64), + real(f64), text(string), blob(list), null diff --git a/v2/wit/variables.wit b/v2/wit/deps/spin@2.0.0/variables.wit similarity index 100% rename from v2/wit/variables.wit rename to v2/wit/deps/spin@2.0.0/variables.wit diff --git a/v2/wit/deps/spin@2.0.0/world.wit b/v2/wit/deps/spin@2.0.0/world.wit new file mode 100644 index 00000000..b16e4290 --- /dev/null +++ b/v2/wit/deps/spin@2.0.0/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; +} diff --git a/v2/wit/deps/spin@unversioned/llm.wit b/v2/wit/deps/spin@unversioned/llm.wit index ffed09cc..bcb59b86 100644 --- a/v2/wit/deps/spin@unversioned/llm.wit +++ b/v2/wit/deps/spin@unversioned/llm.wit @@ -10,15 +10,15 @@ interface llm { /// Note: the backing implementation may return less tokens. max-tokens: u32, /// The amount the model should avoid repeating tokens. - repeat-penalty: float32, + 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: float32, + 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: float32 + top-p: f32 } /// The set of errors which may be raised by functions in this interface @@ -57,7 +57,7 @@ interface llm { /// Result of generating embeddings record embeddings-result { /// The embeddings generated by the request - embeddings: list>, + embeddings: list>, /// Usage related to the embeddings generation request usage: embeddings-usage } diff --git a/v2/wit/deps/spin@unversioned/rdbms-types.wit b/v2/wit/deps/spin@unversioned/rdbms-types.wit index 7af04209..8f9c9c38 100644 --- a/v2/wit/deps/spin@unversioned/rdbms-types.wit +++ b/v2/wit/deps/spin@unversioned/rdbms-types.wit @@ -26,8 +26,8 @@ interface rdbms-types { uint16(u16), uint32(u32), uint64(u64), - floating32(float32), - floating64(float64), + floating32(f32), + floating64(f64), str(string), binary(list), db-null, @@ -44,8 +44,8 @@ interface rdbms-types { uint16(u16), uint32(u32), uint64(u64), - floating32(float32), - floating64(float64), + floating32(f32), + floating64(f64), str(string), binary(list), db-null, diff --git a/v2/wit/deps/spin@unversioned/sqlite.wit b/v2/wit/deps/spin@unversioned/sqlite.wit index 7e2908f0..d5abcb2b 100644 --- a/v2/wit/deps/spin@unversioned/sqlite.wit +++ b/v2/wit/deps/spin@unversioned/sqlite.wit @@ -44,7 +44,7 @@ interface sqlite { variant value { integer(s64), - real(float64), + real(f64), text(string), blob(list), null diff --git a/v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit b/v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit new file mode 100644 index 00000000..794379a7 --- /dev/null +++ b/v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit @@ -0,0 +1,30 @@ +interface store { + /// An error type that encapsulates the different errors that can occur fetching configuration values. + variant error { + /// This indicates an error from an "upstream" config source. + /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + /// the error message is a string. + upstream(string), + /// This indicates an error from an I/O operation. + /// As this could be almost _anything_ (such as a file read, network connection, etc), + /// the error message is a string. + /// Depending on how this ends up being consumed, + /// we may consider moving this to use the `wasi:io/error` type instead. + /// For simplicity right now in supporting multiple implementations, it is being left as a string. + io(string), + } + + /// Gets a configuration value of type `string` associated with the `key`. + /// + /// The value is returned as an `option`. If the key is not found, + /// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned. + get: func( + /// A string key to fetch + key: string + ) -> result, error>; + + /// Gets a list of configuration key-value pairs of type `string`. + /// + /// If an error occurs, an `Err(error)` is returned. + get-all: func() -> result>, error>; +} diff --git a/v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit b/v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit new file mode 100644 index 00000000..e879af51 --- /dev/null +++ b/v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit @@ -0,0 +1,6 @@ +package wasi:config@0.2.0-draft-2024-09-27; + +world imports { + /// The interface for wasi:config/store + import store; +} \ No newline at end of file diff --git a/v2/wit/world.wit b/v2/wit/world.wit index b16e4290..07da9cd4 100644 --- a/v2/wit/world.wit +++ b/v2/wit/world.wit @@ -1,4 +1,4 @@ -package fermyon:spin@2.0.0; +package fermyon:spin@3.0.0; /// The full world of a guest targeting an http-trigger world http-trigger { @@ -6,36 +6,10 @@ world http-trigger { 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; + include fermyon:spin/platform@2.0.0; + include wasi:keyvalue/imports@0.2.0-draft2; + import spin:postgres/postgres@3.0.0; + import wasi:config/store@0.2.0-draft-2024-09-27; } From 3cd22afa9ce863a6e0e7df28da91a41568adf9c0 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 2 Apr 2025 13:51:10 +0530 Subject: [PATCH 03/22] feat(wasip2/kv): add support for wasip2 kv Signed-off-by: Rajat Jindal --- .github/workflows/pr.yaml | 4 +- v2/examples/kv/go.mod | 12 ++++ v2/examples/kv/go.sum | 4 ++ v2/examples/kv/main.go | 50 ++++++++++++++ v2/examples/kv/spin.toml | 17 +++++ v2/integration_test.go | 24 +++++++ v2/kv/kv.go | 103 +++++++++++++++++++++++++++++ v2/kv/testdata/key-value/go.mod | 12 ++++ v2/kv/testdata/key-value/go.sum | 4 ++ v2/kv/testdata/key-value/main.go | 50 ++++++++++++++ v2/kv/testdata/key-value/spin.toml | 17 +++++ 11 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 v2/examples/kv/go.mod create mode 100644 v2/examples/kv/go.sum create mode 100644 v2/examples/kv/main.go create mode 100644 v2/examples/kv/spin.toml create mode 100644 v2/kv/kv.go create mode 100644 v2/kv/testdata/key-value/go.mod create mode 100644 v2/kv/testdata/key-value/go.sum create mode 100644 v2/kv/testdata/key-value/main.go create mode 100644 v2/kv/testdata/key-value/spin.toml diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index ad174d91..bc0f5850 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,8 +1,8 @@ name: Run Integration tests on: - push: + pull_request: branches: - - wasip2-http + - wasip2 workflow_dispatch: {} diff --git a/v2/examples/kv/go.mod b/v2/examples/kv/go.mod new file mode 100644 index 00000000..5496fc65 --- /dev/null +++ b/v2/examples/kv/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v2/examples/kv + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/kv/go.sum b/v2/examples/kv/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v2/examples/kv/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/examples/kv/main.go b/v2/examples/kv/main.go new file mode 100644 index 00000000..012c946a --- /dev/null +++ b/v2/examples/kv/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + "github.com/spinframework/spin-go-sdk/v2/kv" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + store, err := kv.OpenDefault() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = store.Set("foo", []byte("bar")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + value, err := store.Get("foo") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if string(value) != "bar" { + http.Error(w, fmt.Sprintf("expected: %q, got: %q", "bar", value), http.StatusInternalServerError) + return + } + + keys, err := store.GetKeys() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(keys) + }) +} + +func main() {} diff --git a/v2/examples/kv/spin.toml b/v2/examples/kv/spin.toml new file mode 100644 index 00000000..b35d1c01 --- /dev/null +++ b/v2/examples/kv/spin.toml @@ -0,0 +1,17 @@ +spin_manifest_version = 2 + +[application] +authors = ["Rajat Jindal "] +description = "A simple Spin application written in (Tiny)Go." +name = "hello-kv" +version = "1.0.0" + +[[trigger.http]] +route = "/hello" +component = "hello" + +[component.hello] +source = "main.wasm" +key_value_stores = ["default"] +[component.hello.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/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/integration_test.go b/v2/integration_test.go index fb6e8e8c..7fb44705 100644 --- a/v2/integration_test.go +++ b/v2/integration_test.go @@ -120,6 +120,30 @@ func TestHTTPTriger(t *testing.T) { } } +func TestKeyValue(t *testing.T) { + spin := startSpin(t, "kv/testdata/key-value") + defer spin.cancel() + + resp := retryGet(t, spin.url+"/hello") + spin.cancel() + if resp.Body == nil { + t.Fatal("body is nil") + } + t.Log(resp.Status) + b, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + t.Fatal(err) + } + + // assert response body + want := "[\"foo\"]\n" + got := string(b) + if want != got { + t.Fatalf("body is not equal: want = %q got = %q", want, got) + } +} + // TestBuildExamples ensures that the tinygo examples will build successfully. func TestBuildExamples(t *testing.T) { examples, err := os.ReadDir("examples") diff --git a/v2/kv/kv.go b/v2/kv/kv.go new file mode 100644 index 00000000..0a6eb6b0 --- /dev/null +++ b/v2/kv/kv.go @@ -0,0 +1,103 @@ +package kv + +import ( + "fmt" + + keyvalue "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/key-value" + "go.bytecodealliance.org/cm" +) + +type Store struct { + store *keyvalue.Store +} + +// Open the store with the label. +func Open(label string) (*Store, error) { + result := keyvalue.StoreOpen(label) + if result.IsErr() { + return nil, errorVariantToError(*result.Err()) + } + + return &Store{ + store: result.OK(), + }, nil +} + +// Open the default store. +// +// This is equivalent to `kv.Open("default")`. +func OpenDefault() (*Store, error) { + return Open("default") +} + +// Set the key/value pair in store +func (s *Store) Set(key string, value []byte) error { + result := s.store.Set(key, cm.ToList(value)) + if result.IsErr() { + return errorVariantToError(*result.Err()) + } + + return nil +} + +// Get the value of provided key from the store +func (s *Store) Get(key string) ([]byte, error) { + result := s.store.Get(key) + if result.IsErr() { + return nil, errorVariantToError(*result.Err()) + } + + value := result.OK() + if value.None() { + return []byte(""), nil + } + + return value.Some().Slice(), nil +} + +// Delete the given key/value from the store +func (s *Store) Delete(key string) error { + result := s.store.Delete(key) + if result.IsErr() { + return errorVariantToError(*result.Err()) + } + + return nil +} + +// Exists check if a given key exist in the store +func (s *Store) Exists(key string) (bool, error) { + result := s.store.Exists(key) + if result.IsErr() { + return false, errorVariantToError(*result.Err()) + } + + return *result.OK(), nil +} + +// GetKets returns all the keys from the store +func (s *Store) GetKeys() ([]string, error) { + result := s.store.GetKeys() + if result.IsErr() { + return nil, errorVariantToError(*result.Err()) + } + + return result.OK().Slice(), nil +} + +func errorVariantToError(code keyvalue.Error) error { + switch code { + case keyvalue.ErrorAccessDenied(): + return fmt.Errorf("access denied") + case keyvalue.ErrorNoSuchStore(): + return fmt.Errorf("no such store") + case keyvalue.ErrorStoreTableFull(): + return fmt.Errorf("store table full") + default: + if code.Other() != nil { + return fmt.Errorf(*code.Other()) + } + + return fmt.Errorf("no error provided by host implementation") + } +} diff --git a/v2/kv/testdata/key-value/go.mod b/v2/kv/testdata/key-value/go.mod new file mode 100644 index 00000000..5528778a --- /dev/null +++ b/v2/kv/testdata/key-value/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v2/http/testdata/kv + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/kv/testdata/key-value/go.sum b/v2/kv/testdata/key-value/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v2/kv/testdata/key-value/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/kv/testdata/key-value/main.go b/v2/kv/testdata/key-value/main.go new file mode 100644 index 00000000..012c946a --- /dev/null +++ b/v2/kv/testdata/key-value/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + "github.com/spinframework/spin-go-sdk/v2/kv" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + store, err := kv.OpenDefault() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = store.Set("foo", []byte("bar")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + value, err := store.Get("foo") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if string(value) != "bar" { + http.Error(w, fmt.Sprintf("expected: %q, got: %q", "bar", value), http.StatusInternalServerError) + return + } + + keys, err := store.GetKeys() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(keys) + }) +} + +func main() {} diff --git a/v2/kv/testdata/key-value/spin.toml b/v2/kv/testdata/key-value/spin.toml new file mode 100644 index 00000000..bfd75049 --- /dev/null +++ b/v2/kv/testdata/key-value/spin.toml @@ -0,0 +1,17 @@ +spin_manifest_version = 2 + +[application] +authors = ["Rajat Jindal "] +description = "A simple Spin application written in (Tiny)Go." +name = "key-value" +version = "1.0.0" + +[[trigger.http]] +route = "/hello" +component = "hello" + +[component.hello] +source = "main.wasm" +key_value_stores = ["default"] +[component.hello.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file From 5b03b6d2a6426750941769c49424cee6b07c0177 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 2 Apr 2025 14:04:09 +0530 Subject: [PATCH 04/22] install wasm-tools and v3.2.0 of spin Signed-off-by: Rajat Jindal --- .github/workflows/pr.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index bc0f5850..0fb900a2 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -15,17 +15,20 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: '1.24' - name: Setup TinyGo uses: acifani/setup-tinygo@v2 with: - tinygo-version: '0.33.0' + tinygo-version: '0.37.0' - name: Setup Spin uses: fermyon/actions/spin/setup@v1 with: - version: "v2.7.0" + version: "v3.2.0" + + - name: Setup `wasm-tools` + uses: bytecodealliance/actions/wasm-tools/setup@v1 - name: Run wasip2 integration tests run: make test-integration-wasip2 From 8c008a4dd2abd71334e115983f41795744810d6e Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 2 Apr 2025 14:47:58 +0530 Subject: [PATCH 05/22] feat(wasip2/llm): add support for llm Signed-off-by: Rajat Jindal --- v2/examples/llm/.gitignore | 2 + v2/examples/llm/go.mod | 12 ++++ v2/examples/llm/go.sum | 4 ++ v2/examples/llm/main.go | 34 ++++++++++ v2/examples/llm/spin.toml | 19 ++++++ v2/llm/llm.go | 135 +++++++++++++++++++++++++++++++++++++ 6 files changed, 206 insertions(+) create mode 100644 v2/examples/llm/.gitignore create mode 100644 v2/examples/llm/go.mod create mode 100644 v2/examples/llm/go.sum create mode 100644 v2/examples/llm/main.go create mode 100644 v2/examples/llm/spin.toml create mode 100644 v2/llm/llm.go diff --git a/v2/examples/llm/.gitignore b/v2/examples/llm/.gitignore new file mode 100644 index 00000000..b5650104 --- /dev/null +++ b/v2/examples/llm/.gitignore @@ -0,0 +1,2 @@ +main.wasm +.spin/ diff --git a/v2/examples/llm/go.mod b/v2/examples/llm/go.mod new file mode 100644 index 00000000..cc73aecf --- /dev/null +++ b/v2/examples/llm/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v2/examples/llm + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/llm/go.sum b/v2/examples/llm/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v2/examples/llm/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/examples/llm/main.go b/v2/examples/llm/main.go new file mode 100644 index 00000000..55dae4ec --- /dev/null +++ b/v2/examples/llm/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + "github.com/spinframework/spin-go-sdk/v2/llm" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + result, err := llm.Infer("llama2-chat", "Tell me a joke", nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + fmt.Printf("Prompt tokens: %d\n", result.Usage.PromptTokenCount) + fmt.Printf("Generated tokens: %d\n", result.Usage.GeneratedTokenCount) + fmt.Fprint(w, result.Text) + fmt.Fprintf(w, "\n\n") + + embeddings, err := llm.GenerateEmbeddings("all-minilm-l6-v2", []string{"Hello world"}) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + fmt.Printf("%d\n", len(embeddings.Embeddings[0])) + fmt.Printf("Prompt Tokens: %d\n", embeddings.Usage.PromptTokenCount) + + }) +} + +func main() {} diff --git a/v2/examples/llm/spin.toml b/v2/examples/llm/spin.toml new file mode 100644 index 00000000..bcdda809 --- /dev/null +++ b/v2/examples/llm/spin.toml @@ -0,0 +1,19 @@ +spin_manifest_version = 2 + +[application] +authors = ["Fermyon Engineering "] +description = "Simple example using the llm sdk." +name = "llm-example" +version = "0.1.0" + +[[trigger.http]] +route = "/..." +component = "llm" + +[component.llm] +source = "main.wasm" +allowed_outbound_hosts = [] +ai_models = ["llama2-chat", "all-minilm-l6-v2"] +[component.llm.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] diff --git a/v2/llm/llm.go b/v2/llm/llm.go new file mode 100644 index 00000000..ac4b94db --- /dev/null +++ b/v2/llm/llm.go @@ -0,0 +1,135 @@ +package llm + +import ( + "fmt" + + "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/llm" + "go.bytecodealliance.org/cm" +) + +// The model use for inferencing +const ( + Llama2Chat InferencingModel = "llama2-chat" + CodellamaInstruct InferencingModel = "codellama-instruct" +) + +type InferencingParams struct { + // The maximum tokens that should be inferred. + // + // Note: the backing implementation may return less tokens. + MaxTokens uint32 `json:"max-tokens"` + + // The amount the model should avoid repeating tokens. + RepeatPenalty float32 `json:"repeat-penalty"` + + // The number of tokens the model should apply the repeat penalty to. + RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` + + // The randomness with which the next token is selected. + Temperature float32 `json:"temperature"` + + // The number of possible next tokens the model will choose from. + TopK uint32 `json:"top-k"` + + // The probability total of next tokens the model will choose from. + TopP float32 `json:"top-p"` +} + +type InferencingResult struct { + // The text generated by the model + // TODO: this should be a stream + Text string `json:"text"` + + // Usage information about the inferencing request + Usage InferencingUsage `json:"usage"` +} + +// Usage information related to the inferencing result +type InferencingUsage struct { + _ cm.HostLayout `json:"-"` + // Number of tokens in the prompt + PromptTokenCount uint32 `json:"prompt-token-count"` + + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 `json:"generated-token-count"` +} + +// A Large Language Model. +type InferencingModel string + +// The model used for generating embeddings +type EmbeddingModel string + +type EmbeddingsResult struct { + // Embeddings are the embeddings generated by the request. + Embeddings [][]float32 + // Usage is usage related to an embeddings generation request. + Usage *EmbeddingsUsage +} + +type EmbeddingsUsage struct { + // PromptTokenCount is number of tokens in the prompt. + PromptTokenCount int +} + +// Infer performs inferencing using the provided model and prompt with the +// given optional parameters. +func Infer(model string, prompt string, params *InferencingParams) (InferencingResult, error) { + iparams := cm.None[llm.InferencingParams]() + if params != nil { + iparams = cm.Some(llm.InferencingParams{ + MaxTokens: params.MaxTokens, + RepeatPenalty: params.RepeatPenalty, + RepeatPenaltyLastNTokenCount: params.RepeatPenaltyLastNTokenCount, + Temperature: params.Temperature, + TopK: params.TopK, + TopP: params.TopP, + }) + } + + result := llm.Infer(llm.InferencingModel(model), prompt, iparams) + if result.IsErr() { + return InferencingResult{}, errorVariantToError(*result.Err()) + } + + return InferencingResult{ + Text: result.OK().Text, + Usage: InferencingUsage{ + PromptTokenCount: result.OK().Usage.PromptTokenCount, + GeneratedTokenCount: result.OK().Usage.GeneratedTokenCount, + }, + }, nil +} + +// GenerateEmbeddings generates the embeddings for the supplied list of text. +func GenerateEmbeddings(model EmbeddingModel, text []string) (*EmbeddingsResult, error) { + result := llm.GenerateEmbeddings(llm.EmbeddingModel(model), cm.ToList(text)) + if result.IsErr() { + return &EmbeddingsResult{}, errorVariantToError(*result.Err()) + } + + embeddings := [][]float32{} + for _, l := range result.OK().Embeddings.Slice() { + embeddings = append(embeddings, l.Slice()) + } + + return &EmbeddingsResult{ + Embeddings: embeddings, + Usage: &EmbeddingsUsage{ + PromptTokenCount: int(result.OK().Usage.PromptTokenCount), + }, + }, nil +} + +func errorVariantToError(err llm.Error) error { + switch { + case llm.ErrorModelNotSupported() == err: + return fmt.Errorf("model not supported") + case err.RuntimeError() != nil: + return fmt.Errorf("runtime error %s", *err.RuntimeError()) + case err.InvalidInput() != nil: + return fmt.Errorf("invalid input %s", *err.InvalidInput()) + default: + return fmt.Errorf("no error provided by host implementation") + } +} From 72c0f2275d22d5f46c836e297a2276da46bda8e0 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Thu, 3 Apr 2025 06:41:24 +0530 Subject: [PATCH 06/22] add variables support for wasip2 sdk Signed-off-by: Rajat Jindal --- v2/examples/variables/go.mod | 12 ++++++++ v2/examples/variables/go.sum | 4 +++ v2/examples/variables/main.go | 24 +++++++++++++++ v2/examples/variables/spin.toml | 22 ++++++++++++++ v2/go.mod | 15 ---------- v2/go.sum | 35 ---------------------- v2/integration_test.go | 28 ++++++++++++++++-- v2/variables/testdata/variables/go.mod | 12 ++++++++ v2/variables/testdata/variables/go.sum | 4 +++ v2/variables/testdata/variables/main.go | 23 +++++++++++++++ v2/variables/testdata/variables/spin.toml | 22 ++++++++++++++ v2/variables/variables.go | 36 +++++++++++++++++++++++ 12 files changed, 185 insertions(+), 52 deletions(-) create mode 100644 v2/examples/variables/go.mod create mode 100644 v2/examples/variables/go.sum create mode 100644 v2/examples/variables/main.go create mode 100644 v2/examples/variables/spin.toml create mode 100644 v2/variables/testdata/variables/go.mod create mode 100644 v2/variables/testdata/variables/go.sum create mode 100644 v2/variables/testdata/variables/main.go create mode 100644 v2/variables/testdata/variables/spin.toml create mode 100644 v2/variables/variables.go diff --git a/v2/examples/variables/go.mod b/v2/examples/variables/go.mod new file mode 100644 index 00000000..3d0a5f58 --- /dev/null +++ b/v2/examples/variables/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v2/examples/variables + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/variables/go.sum b/v2/examples/variables/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v2/examples/variables/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/examples/variables/main.go b/v2/examples/variables/main.go new file mode 100644 index 00000000..e0a4091d --- /dev/null +++ b/v2/examples/variables/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + "github.com/spinframework/spin-go-sdk/v2/variables" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + + // Get variable value `message` defined in spin.toml. + val, err := variables.Get("message") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + fmt.Fprintln(w, "message: ", val) + }) +} + +func main() {} diff --git a/v2/examples/variables/spin.toml b/v2/examples/variables/spin.toml new file mode 100644 index 00000000..6c9fdb6e --- /dev/null +++ b/v2/examples/variables/spin.toml @@ -0,0 +1,22 @@ +spin_manifest_version = 2 + +[application] +name = "variables-example" +authors = ["Fermyon Engineering "] +description = "A simple Spin application written in (Tiny)Go." +version = "1.0.0" + +[variables] +object = { default = "teapot" } + +[[trigger.http]] +route = "/..." +component = "variables" + +[component.variables] +source = "main.wasm" +[component.variables.variables] +message = "I'm a {{object}}" + +[component.hello.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/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 e8a89272..ac994dcc 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -4,20 +4,5 @@ go 1.23.2 require ( github.com/julienschmidt/httprouter v1.3.0 - go.bytecodealliance.org v0.6.2 go.bytecodealliance.org/cm v0.2.2 ) - -require ( - github.com/coreos/go-semver v0.3.1 // indirect - github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect - github.com/klauspost/compress v1.17.11 // indirect - github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/regclient/regclient v0.8.2 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect - github.com/tetratelabs/wazero v1.9.0 // indirect - github.com/ulikunitz/xz v0.5.12 // indirect - github.com/urfave/cli/v3 v3.0.0-beta1 // indirect - golang.org/x/mod v0.23.0 // indirect - golang.org/x/sys v0.30.0 // indirect -) diff --git a/v2/go.sum b/v2/go.sum index c2db9fff..c1ebfdf4 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,39 +1,4 @@ -github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= -github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4= -github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= -github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/regclient/regclient v0.8.2 h1:23BQ3jWgKYHHIXUhp/S9laVJDHDoOQaQCzXMJ4undVE= -github.com/regclient/regclient v0.8.2/go.mod h1:uGyetv0o6VLyRDjtfeBqp/QBwRLJ3Hcn07/+8QbhNcM= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= -github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= -github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= -github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg= -github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= -go.bytecodealliance.org v0.4.0 h1:SRwgZIcXR54AmbJg9Y3AMgDlZlvD8dffteBYW+nCD3k= -go.bytecodealliance.org v0.4.0/go.mod h1:hkdjfgQ/bFZYUucnm9cn0Q8/SHO3iT0rzskYlkV4Jy0= -go.bytecodealliance.org v0.6.2 h1:Jy4u5DVmSkXgsnwojBhJ+AD/YsJsR3VzVnxF0xRCqTQ= -go.bytecodealliance.org v0.6.2/go.mod h1:gqjTJm0y9NSksG4py/lSjIQ/SNuIlOQ+hCIEPQwtJgA= go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= -golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= -golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/v2/integration_test.go b/v2/integration_test.go index 7fb44705..0fd458de 100644 --- a/v2/integration_test.go +++ b/v2/integration_test.go @@ -42,7 +42,7 @@ type testSpin struct { cmd *exec.Cmd } -func startSpin(t *testing.T, dir string) *testSpin { +func startSpin(t *testing.T, dir string, extraArgs ...string) *testSpin { buildApp(t, dir) url := getFreePort(t) @@ -50,7 +50,7 @@ func startSpin(t *testing.T, dir string) *testSpin { // long timeout because... ci ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - cmd := exec.CommandContext(ctx, spinBinary, "up", "--listen", url) + cmd := exec.CommandContext(ctx, spinBinary, append([]string{"up", "--listen", url}, extraArgs...)...) cmd.Dir = dir stderr := new(bytes.Buffer) cmd.Stderr = stderr @@ -144,6 +144,30 @@ func TestKeyValue(t *testing.T) { } } +func TestVariables(t *testing.T) { + spin := startSpin(t, "variables/testdata/variables") + defer spin.cancel() + + resp := retryGet(t, spin.url) + spin.cancel() + if resp.Body == nil { + t.Fatal("body is nil") + } + t.Log(resp.Status) + b, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + t.Fatal(err) + } + + // assert response body + want := "message: I'm a teapot\n" + got := string(b) + if want != got { + t.Fatalf("body is not equal: want = %q got = %q", want, got) + } +} + // TestBuildExamples ensures that the tinygo examples will build successfully. func TestBuildExamples(t *testing.T) { examples, err := os.ReadDir("examples") diff --git a/v2/variables/testdata/variables/go.mod b/v2/variables/testdata/variables/go.mod new file mode 100644 index 00000000..74ae187d --- /dev/null +++ b/v2/variables/testdata/variables/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v2/examples/variables + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v2 v2.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/variables/testdata/variables/go.sum b/v2/variables/testdata/variables/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v2/variables/testdata/variables/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v2/variables/testdata/variables/main.go b/v2/variables/testdata/variables/main.go new file mode 100644 index 00000000..bd16daff --- /dev/null +++ b/v2/variables/testdata/variables/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + "github.com/spinframework/spin-go-sdk/v2/variables" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + // Get variable value `message` defined in spin.toml. + val, err := variables.Get("message") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + fmt.Fprintln(w, "message: ", val) + }) +} + +func main() {} diff --git a/v2/variables/testdata/variables/spin.toml b/v2/variables/testdata/variables/spin.toml new file mode 100644 index 00000000..f51dd6db --- /dev/null +++ b/v2/variables/testdata/variables/spin.toml @@ -0,0 +1,22 @@ +spin_manifest_version = 2 + +[application] +name = "variables-example" +authors = ["Fermyon Engineering "] +description = "A simple Spin application written in (Tiny)Go." +version = "1.0.0" + +[variables] +object = { default = "teapot" } + +[[trigger.http]] +route = "/..." +component = "variables" + +[component.variables] +source = "main.wasm" +[component.variables.variables] +message = "I'm a {{object}}" + +[component.variables.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/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/variables/variables.go b/v2/variables/variables.go new file mode 100644 index 00000000..7223fdd1 --- /dev/null +++ b/v2/variables/variables.go @@ -0,0 +1,36 @@ +package variables + +import ( + "fmt" + + "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/variables" +) + +// Get an application variable value for the current component. +// +// The name must match one defined in in the component manifest. +func Get(key string) (string, error) { + result := variables.Get(key) + if result.IsErr() { + return "", errorVariantToError(*result.Err()) + } + + return *result.OK(), nil +} + +func errorVariantToError(err variables.Error) error { + switch { + case err.InvalidName() != nil: + return fmt.Errorf(*err.InvalidName()) + case err.Provider() != nil: + return fmt.Errorf(*err.Provider()) + case err.Undefined() != nil: + return fmt.Errorf(*err.Undefined()) + default: + if err.Other() != nil { + return fmt.Errorf(*err.Other()) + } + + return fmt.Errorf("no error provided by host implementation") + } +} From df221c79e496eea0e80c3e82dc3d1979b4bcab23 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 10 Jun 2025 19:23:24 -0700 Subject: [PATCH 07/22] Move v2 to v3 Signed-off-by: Adam Reese --- Makefile | 4 ++-- v2/examples/http/go.mod | 12 ------------ v2/examples/kv/go.mod | 12 ------------ v2/examples/llm/go.mod | 12 ------------ v2/examples/variables/go.mod | 12 ------------ v2/http/testdata/http-tinygo/go.mod | 12 ------------ v2/kv/testdata/key-value/go.mod | 12 ------------ v2/variables/testdata/variables/go.mod | 12 ------------ {v2 => v3}/README.md | 6 +++--- v3/examples/http/go.mod | 12 ++++++++++++ {v2 => v3}/examples/http/go.sum | 0 {v2 => v3}/examples/http/main.go | 2 +- .../http-tinygo => v3/examples/http}/spin.toml | 3 ++- v3/examples/kv/go.mod | 12 ++++++++++++ {v2 => v3}/examples/kv/go.sum | 0 {v2 => v3}/examples/kv/main.go | 4 ++-- {v2 => v3}/examples/kv/spin.toml | 3 ++- {v2 => v3}/examples/llm/.gitignore | 0 v3/examples/llm/go.mod | 12 ++++++++++++ {v2 => v3}/examples/llm/go.sum | 0 {v2 => v3}/examples/llm/main.go | 4 ++-- {v2 => v3}/examples/llm/spin.toml | 2 +- v3/examples/variables/go.mod | 12 ++++++++++++ {v2 => v3}/examples/variables/go.sum | 0 {v2 => v3}/examples/variables/main.go | 4 ++-- {v2 => v3}/examples/variables/spin.toml | 3 ++- {v2 => v3}/go.mod | 2 +- {v2 => v3}/go.sum | 0 {v2 => v3}/http/client.go | 4 ++-- {v2 => v3}/http/convertor_incoming_request.go | 2 +- {v2 => v3}/http/convertor_outgoing_request.go | 2 +- {v2 => v3}/http/convertor_outgoing_response.go | 4 ++-- {v2 => v3}/http/http.go | 6 +++--- {v2 => v3}/http/streams.go | 2 +- v3/http/testdata/http-tinygo/go.mod | 12 ++++++++++++ {v2 => v3}/http/testdata/http-tinygo/go.sum | 0 {v2 => v3}/http/testdata/http-tinygo/main.go | 2 +- .../http => v3/http/testdata/http-tinygo}/spin.toml | 3 ++- {v2 => v3}/integration_test.go | 0 {v2 => v3}/internal/fermyon/spin/config/abi.go | 0 .../internal/fermyon/spin/config/config.wasm.go | 0 .../internal/fermyon/spin/config/config.wit.go | 0 {v2 => v3}/internal/fermyon/spin/config/empty.s | 0 .../fermyon/spin/http-trigger/http-trigger.wit.go | 0 .../fermyon/spin/http-types/http-types.wit.go | 0 {v2 => v3}/internal/fermyon/spin/http/abi.go | 2 +- {v2 => v3}/internal/fermyon/spin/http/empty.s | 0 {v2 => v3}/internal/fermyon/spin/http/http.wasm.go | 0 {v2 => v3}/internal/fermyon/spin/http/http.wit.go | 2 +- {v2 => v3}/internal/fermyon/spin/inbound-http/abi.go | 2 +- .../internal/fermyon/spin/inbound-http/empty.s | 0 .../spin/inbound-http/inbound-http.exports.go | 0 .../fermyon/spin/inbound-http/inbound-http.wasm.go | 0 .../fermyon/spin/inbound-http/inbound-http.wit.go | 2 +- {v2 => v3}/internal/fermyon/spin/key-value/abi.go | 0 {v2 => v3}/internal/fermyon/spin/key-value/empty.s | 0 .../fermyon/spin/key-value/key-value.wasm.go | 0 .../internal/fermyon/spin/key-value/key-value.wit.go | 0 {v2 => v3}/internal/fermyon/spin/llm/abi.go | 0 {v2 => v3}/internal/fermyon/spin/llm/empty.s | 0 {v2 => v3}/internal/fermyon/spin/llm/llm.wasm.go | 0 {v2 => v3}/internal/fermyon/spin/llm/llm.wit.go | 0 {v2 => v3}/internal/fermyon/spin/mysql/abi.go | 0 {v2 => v3}/internal/fermyon/spin/mysql/empty.s | 0 {v2 => v3}/internal/fermyon/spin/mysql/mysql.wasm.go | 0 {v2 => v3}/internal/fermyon/spin/mysql/mysql.wit.go | 2 +- {v2 => v3}/internal/fermyon/spin/postgres/abi.go | 0 {v2 => v3}/internal/fermyon/spin/postgres/empty.s | 0 .../internal/fermyon/spin/postgres/postgres.wasm.go | 0 .../internal/fermyon/spin/postgres/postgres.wit.go | 2 +- .../fermyon/spin/rdbms-types/rdbms-types.wit.go | 0 .../fermyon/spin/redis-types/redis-types.wit.go | 0 {v2 => v3}/internal/fermyon/spin/redis/empty.s | 0 {v2 => v3}/internal/fermyon/spin/redis/redis.wasm.go | 0 {v2 => v3}/internal/fermyon/spin/redis/redis.wit.go | 2 +- {v2 => v3}/internal/fermyon/spin/sqlite/abi.go | 0 {v2 => v3}/internal/fermyon/spin/sqlite/empty.s | 0 .../internal/fermyon/spin/sqlite/sqlite.wasm.go | 0 .../internal/fermyon/spin/sqlite/sqlite.wit.go | 0 .../spin/v2.0.0/http-trigger/http-trigger.wit.go | 0 .../internal/fermyon/spin/v2.0.0/key-value/abi.go | 0 .../internal/fermyon/spin/v2.0.0/key-value/empty.s | 0 .../fermyon/spin/v2.0.0/key-value/key-value.wasm.go | 0 .../fermyon/spin/v2.0.0/key-value/key-value.wit.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/abi.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/empty.s | 0 .../internal/fermyon/spin/v2.0.0/llm/llm.wasm.go | 0 .../internal/fermyon/spin/v2.0.0/llm/llm.wit.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/empty.s | 0 .../internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go | 0 .../internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/mysql/abi.go | 0 .../internal/fermyon/spin/v2.0.0/mysql/empty.s | 0 .../internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go | 0 .../internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go | 2 +- .../internal/fermyon/spin/v2.0.0/postgres/abi.go | 0 .../internal/fermyon/spin/v2.0.0/postgres/empty.s | 0 .../fermyon/spin/v2.0.0/postgres/postgres.wasm.go | 0 .../fermyon/spin/v2.0.0/postgres/postgres.wit.go | 2 +- .../spin/v2.0.0/rdbms-types/rdbms-types.wit.go | 0 {v2 => v3}/internal/fermyon/spin/v2.0.0/redis/abi.go | 0 .../internal/fermyon/spin/v2.0.0/redis/empty.s | 0 .../internal/fermyon/spin/v2.0.0/redis/redis.wasm.go | 0 .../internal/fermyon/spin/v2.0.0/redis/redis.wit.go | 0 .../internal/fermyon/spin/v2.0.0/sqlite/abi.go | 0 .../internal/fermyon/spin/v2.0.0/sqlite/empty.s | 0 .../fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go | 0 .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 0 .../internal/fermyon/spin/v2.0.0/variables/abi.go | 0 .../internal/fermyon/spin/v2.0.0/variables/empty.s | 0 .../fermyon/spin/v2.0.0/variables/variables.wasm.go | 0 .../fermyon/spin/v2.0.0/variables/variables.wit.go | 0 .../spin/v3.0.0/http-trigger/http-trigger.wit.go | 0 .../internal/spin/postgres/v3.0.0/postgres/abi.go | 0 .../internal/spin/postgres/v3.0.0/postgres/empty.s | 0 .../spin/postgres/v3.0.0/postgres/postgres.wasm.go | 0 .../spin/postgres/v3.0.0/postgres/postgres.wit.go | 0 .../internal/wasi/cli/v0.2.0/environment/empty.s | 0 .../wasi/cli/v0.2.0/environment/environment.wasm.go | 0 .../wasi/cli/v0.2.0/environment/environment.wit.go | 0 {v2 => v3}/internal/wasi/cli/v0.2.0/exit/empty.s | 0 .../internal/wasi/cli/v0.2.0/exit/exit.wasm.go | 0 {v2 => v3}/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 0 {v2 => v3}/internal/wasi/cli/v0.2.0/stderr/empty.s | 0 .../internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go | 0 .../internal/wasi/cli/v0.2.0/stderr/stderr.wit.go | 2 +- {v2 => v3}/internal/wasi/cli/v0.2.0/stdin/empty.s | 0 .../internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go | 0 .../internal/wasi/cli/v0.2.0/stdin/stdin.wit.go | 2 +- {v2 => v3}/internal/wasi/cli/v0.2.0/stdout/empty.s | 0 .../internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go | 0 .../internal/wasi/cli/v0.2.0/stdout/stdout.wit.go | 2 +- .../internal/wasi/cli/v0.2.0/terminal-input/empty.s | 0 .../cli/v0.2.0/terminal-input/terminal-input.wasm.go | 0 .../cli/v0.2.0/terminal-input/terminal-input.wit.go | 0 .../internal/wasi/cli/v0.2.0/terminal-output/empty.s | 0 .../v0.2.0/terminal-output/terminal-output.wasm.go | 0 .../v0.2.0/terminal-output/terminal-output.wit.go | 0 .../internal/wasi/cli/v0.2.0/terminal-stderr/empty.s | 0 .../v0.2.0/terminal-stderr/terminal-stderr.wasm.go | 0 .../v0.2.0/terminal-stderr/terminal-stderr.wit.go | 2 +- .../internal/wasi/cli/v0.2.0/terminal-stdin/empty.s | 0 .../cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go | 0 .../cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go | 2 +- .../internal/wasi/cli/v0.2.0/terminal-stdout/empty.s | 0 .../v0.2.0/terminal-stdout/terminal-stdout.wasm.go | 0 .../v0.2.0/terminal-stdout/terminal-stdout.wit.go | 2 +- .../wasi/clocks/v0.2.0/monotonic-clock/empty.s | 0 .../v0.2.0/monotonic-clock/monotonic-clock.wasm.go | 0 .../v0.2.0/monotonic-clock/monotonic-clock.wit.go | 2 +- .../internal/wasi/clocks/v0.2.0/wall-clock/empty.s | 0 .../wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go | 0 .../wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go | 0 .../wasi/config/v0.2.0-draft-2024-09-27/store/abi.go | 0 .../config/v0.2.0-draft-2024-09-27/store/empty.s | 0 .../v0.2.0-draft-2024-09-27/store/store.wasm.go | 0 .../v0.2.0-draft-2024-09-27/store/store.wit.go | 0 .../internal/wasi/filesystem/v0.2.0/preopens/empty.s | 0 .../wasi/filesystem/v0.2.0/preopens/preopens.wasm.go | 0 .../wasi/filesystem/v0.2.0/preopens/preopens.wit.go | 2 +- .../internal/wasi/filesystem/v0.2.0/types/abi.go | 2 +- .../internal/wasi/filesystem/v0.2.0/types/empty.s | 0 .../wasi/filesystem/v0.2.0/types/types.wasm.go | 0 .../wasi/filesystem/v0.2.0/types/types.wit.go | 4 ++-- .../wasi/http/v0.2.0/incoming-handler/empty.s | 0 .../incoming-handler/incoming-handler.exports.go | 0 .../v0.2.0/incoming-handler/incoming-handler.wasm.go | 0 .../v0.2.0/incoming-handler/incoming-handler.wit.go | 2 +- .../wasi/http/v0.2.0/outgoing-handler/abi.go | 0 .../wasi/http/v0.2.0/outgoing-handler/empty.s | 0 .../v0.2.0/outgoing-handler/outgoing-handler.wasm.go | 0 .../v0.2.0/outgoing-handler/outgoing-handler.wit.go | 2 +- {v2 => v3}/internal/wasi/http/v0.2.0/types/abi.go | 0 {v2 => v3}/internal/wasi/http/v0.2.0/types/empty.s | 0 .../internal/wasi/http/v0.2.0/types/types.wasm.go | 0 .../internal/wasi/http/v0.2.0/types/types.wit.go | 8 ++++---- {v2 => v3}/internal/wasi/io/v0.2.0/error/empty.s | 0 .../internal/wasi/io/v0.2.0/error/error.wasm.go | 0 .../internal/wasi/io/v0.2.0/error/error.wit.go | 0 {v2 => v3}/internal/wasi/io/v0.2.0/poll/empty.s | 0 {v2 => v3}/internal/wasi/io/v0.2.0/poll/poll.wasm.go | 0 {v2 => v3}/internal/wasi/io/v0.2.0/poll/poll.wit.go | 0 {v2 => v3}/internal/wasi/io/v0.2.0/streams/empty.s | 0 .../internal/wasi/io/v0.2.0/streams/streams.wasm.go | 0 .../internal/wasi/io/v0.2.0/streams/streams.wit.go | 4 ++-- .../wasi/keyvalue/v0.2.0-draft2/atomics/abi.go | 0 .../keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go | 0 .../keyvalue/v0.2.0-draft2/atomics/atomics.wit.go | 2 +- .../wasi/keyvalue/v0.2.0-draft2/atomics/empty.s | 0 .../wasi/keyvalue/v0.2.0-draft2/batch/abi.go | 0 .../wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go | 0 .../wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go | 2 +- .../wasi/keyvalue/v0.2.0-draft2/batch/empty.s | 0 .../wasi/keyvalue/v0.2.0-draft2/store/abi.go | 0 .../wasi/keyvalue/v0.2.0-draft2/store/empty.s | 0 .../wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go | 0 .../wasi/keyvalue/v0.2.0-draft2/store/store.wit.go | 0 .../wasi/random/v0.2.0/insecure-seed/empty.s | 0 .../v0.2.0/insecure-seed/insecure-seed.wasm.go | 0 .../random/v0.2.0/insecure-seed/insecure-seed.wit.go | 0 .../internal/wasi/random/v0.2.0/insecure/empty.s | 0 .../wasi/random/v0.2.0/insecure/insecure.wasm.go | 0 .../wasi/random/v0.2.0/insecure/insecure.wit.go | 0 .../internal/wasi/random/v0.2.0/random/empty.s | 0 .../wasi/random/v0.2.0/random/random.wasm.go | 0 .../internal/wasi/random/v0.2.0/random/random.wit.go | 0 .../wasi/sockets/v0.2.0/instance-network/empty.s | 0 .../v0.2.0/instance-network/instance-network.wasm.go | 0 .../v0.2.0/instance-network/instance-network.wit.go | 2 +- .../wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 0 .../wasi/sockets/v0.2.0/ip-name-lookup/empty.s | 0 .../v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go | 0 .../v0.2.0/ip-name-lookup/ip-name-lookup.wit.go | 4 ++-- .../internal/wasi/sockets/v0.2.0/network/abi.go | 0 .../internal/wasi/sockets/v0.2.0/network/empty.s | 0 .../wasi/sockets/v0.2.0/network/network.wasm.go | 0 .../wasi/sockets/v0.2.0/network/network.wit.go | 0 .../wasi/sockets/v0.2.0/tcp-create-socket/empty.s | 0 .../tcp-create-socket/tcp-create-socket.wasm.go | 0 .../tcp-create-socket/tcp-create-socket.wit.go | 4 ++-- {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/abi.go | 2 +- {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/empty.s | 0 .../internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go | 0 .../internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go | 8 ++++---- .../wasi/sockets/v0.2.0/udp-create-socket/empty.s | 0 .../udp-create-socket/udp-create-socket.wasm.go | 0 .../udp-create-socket/udp-create-socket.wit.go | 4 ++-- {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/abi.go | 2 +- {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/empty.s | 0 .../internal/wasi/sockets/v0.2.0/udp/udp.wasm.go | 0 .../internal/wasi/sockets/v0.2.0/udp/udp.wit.go | 4 ++-- {v2 => v3}/kv/kv.go | 2 +- v3/kv/testdata/key-value/go.mod | 12 ++++++++++++ {v2 => v3}/kv/testdata/key-value/go.sum | 0 {v2 => v3}/kv/testdata/key-value/main.go | 4 ++-- {v2 => v3}/kv/testdata/key-value/spin.toml | 3 ++- {v2 => v3}/llm/llm.go | 2 +- v3/variables/testdata/variables/go.mod | 12 ++++++++++++ {v2 => v3}/variables/testdata/variables/go.sum | 0 {v2 => v3}/variables/testdata/variables/main.go | 4 ++-- {v2 => v3}/variables/testdata/variables/spin.toml | 3 ++- {v2 => v3}/variables/variables.go | 2 +- {v2 => v3}/wit/deps/cli-2023-10-18/command.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/environment.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/exit.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/reactor.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/run.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/stdio.wit | 0 {v2 => v3}/wit/deps/cli-2023-10-18/terminal.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/command.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/environment.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/exit.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/reactor.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/run.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/stdio.wit | 0 {v2 => v3}/wit/deps/cli-2023-11-10/terminal.wit | 0 {v2 => v3}/wit/deps/cli/command.wit | 0 {v2 => v3}/wit/deps/cli/environment.wit | 0 {v2 => v3}/wit/deps/cli/exit.wit | 0 {v2 => v3}/wit/deps/cli/imports.wit | 0 {v2 => v3}/wit/deps/cli/run.wit | 0 {v2 => v3}/wit/deps/cli/stdio.wit | 0 {v2 => v3}/wit/deps/cli/terminal.wit | 0 .../wit/deps/clocks-2023-10-18/monotonic-clock.wit | 0 {v2 => v3}/wit/deps/clocks-2023-10-18/timezone.wit | 0 {v2 => v3}/wit/deps/clocks-2023-10-18/wall-clock.wit | 0 {v2 => v3}/wit/deps/clocks-2023-10-18/world.wit | 0 .../wit/deps/clocks-2023-11-10/monotonic-clock.wit | 0 {v2 => v3}/wit/deps/clocks-2023-11-10/wall-clock.wit | 0 {v2 => v3}/wit/deps/clocks-2023-11-10/world.wit | 0 {v2 => v3}/wit/deps/clocks/monotonic-clock.wit | 0 {v2 => v3}/wit/deps/clocks/wall-clock.wit | 0 {v2 => v3}/wit/deps/clocks/world.wit | 0 .../wit/deps/filesystem-2023-10-18/preopens.wit | 0 {v2 => v3}/wit/deps/filesystem-2023-10-18/types.wit | 0 {v2 => v3}/wit/deps/filesystem-2023-10-18/world.wit | 0 .../wit/deps/filesystem-2023-11-10/preopens.wit | 0 {v2 => v3}/wit/deps/filesystem-2023-11-10/types.wit | 0 {v2 => v3}/wit/deps/filesystem-2023-11-10/world.wit | 0 {v2 => v3}/wit/deps/filesystem/preopens.wit | 0 {v2 => v3}/wit/deps/filesystem/types.wit | 0 {v2 => v3}/wit/deps/filesystem/world.wit | 0 .../wit/deps/http-2023-10-18/incoming-handler.wit | 0 .../wit/deps/http-2023-10-18/outgoing-handler.wit | 0 {v2 => v3}/wit/deps/http-2023-10-18/proxy.wit | 0 {v2 => v3}/wit/deps/http-2023-10-18/types.wit | 0 {v2 => v3}/wit/deps/http-2023-11-10/handler.wit | 0 {v2 => v3}/wit/deps/http-2023-11-10/proxy.wit | 0 {v2 => v3}/wit/deps/http-2023-11-10/types.wit | 0 {v2 => v3}/wit/deps/http/handler.wit | 0 {v2 => v3}/wit/deps/http/proxy.wit | 0 {v2 => v3}/wit/deps/http/types.wit | 0 {v2 => v3}/wit/deps/io-2023-10-18/poll.wit | 0 {v2 => v3}/wit/deps/io-2023-10-18/streams.wit | 0 {v2 => v3}/wit/deps/io-2023-10-18/world.wit | 0 {v2 => v3}/wit/deps/io-2023-11-10/error.wit | 0 {v2 => v3}/wit/deps/io-2023-11-10/poll.wit | 0 {v2 => v3}/wit/deps/io-2023-11-10/streams.wit | 0 {v2 => v3}/wit/deps/io-2023-11-10/world.wit | 0 {v2 => v3}/wit/deps/io/error.wit | 0 {v2 => v3}/wit/deps/io/poll.wit | 0 {v2 => v3}/wit/deps/io/streams.wit | 0 {v2 => v3}/wit/deps/io/world.wit | 0 {v2 => v3}/wit/deps/keyvalue-2024-10-17/atomic.wit | 0 {v2 => v3}/wit/deps/keyvalue-2024-10-17/batch.wit | 0 {v2 => v3}/wit/deps/keyvalue-2024-10-17/store.wit | 0 {v2 => v3}/wit/deps/keyvalue-2024-10-17/watch.wit | 0 {v2 => v3}/wit/deps/keyvalue-2024-10-17/world.wit | 0 .../wit/deps/random-2023-10-18/insecure-seed.wit | 0 {v2 => v3}/wit/deps/random-2023-10-18/insecure.wit | 0 {v2 => v3}/wit/deps/random-2023-10-18/random.wit | 0 {v2 => v3}/wit/deps/random-2023-10-18/world.wit | 0 .../wit/deps/random-2023-11-10/insecure-seed.wit | 0 {v2 => v3}/wit/deps/random-2023-11-10/insecure.wit | 0 {v2 => v3}/wit/deps/random-2023-11-10/random.wit | 0 {v2 => v3}/wit/deps/random-2023-11-10/world.wit | 0 {v2 => v3}/wit/deps/random/insecure-seed.wit | 0 {v2 => v3}/wit/deps/random/insecure.wit | 0 {v2 => v3}/wit/deps/random/random.wit | 0 {v2 => v3}/wit/deps/random/world.wit | 0 .../wit/deps/sockets-2023-10-18/instance-network.wit | 0 .../wit/deps/sockets-2023-10-18/ip-name-lookup.wit | 0 {v2 => v3}/wit/deps/sockets-2023-10-18/network.wit | 0 .../deps/sockets-2023-10-18/tcp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets-2023-10-18/tcp.wit | 0 .../deps/sockets-2023-10-18/udp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets-2023-10-18/udp.wit | 0 {v2 => v3}/wit/deps/sockets-2023-10-18/world.wit | 0 .../wit/deps/sockets-2023-11-10/instance-network.wit | 0 .../wit/deps/sockets-2023-11-10/ip-name-lookup.wit | 0 {v2 => v3}/wit/deps/sockets-2023-11-10/network.wit | 0 .../deps/sockets-2023-11-10/tcp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets-2023-11-10/tcp.wit | 0 .../deps/sockets-2023-11-10/udp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets-2023-11-10/udp.wit | 0 {v2 => v3}/wit/deps/sockets-2023-11-10/world.wit | 0 {v2 => v3}/wit/deps/sockets/instance-network.wit | 0 {v2 => v3}/wit/deps/sockets/ip-name-lookup.wit | 0 {v2 => v3}/wit/deps/sockets/network.wit | 0 {v2 => v3}/wit/deps/sockets/tcp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets/tcp.wit | 0 {v2 => v3}/wit/deps/sockets/udp-create-socket.wit | 0 {v2 => v3}/wit/deps/sockets/udp.wit | 0 {v2 => v3}/wit/deps/sockets/world.wit | 0 {v2 => v3}/wit/deps/spin-postgres@3.0.0/postgres.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/key-value.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/llm.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/mqtt.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/mysql.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/postgres.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/rdbms-types.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/redis.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/sqlite.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/variables.wit | 0 {v2 => v3}/wit/deps/spin@2.0.0/world.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/config.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/http-types.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/http.wit | 0 .../wit/deps/spin@unversioned/inbound-http.wit | 0 .../wit/deps/spin@unversioned/inbound-redis.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/key-value.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/llm.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/mysql.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/postgres.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/rdbms-types.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/redis-types.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/redis.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/sqlite.wit | 0 {v2 => v3}/wit/deps/spin@unversioned/world.wit | 0 .../deps/wasi-runtime-config-2024-09-27/store.wit | 0 .../deps/wasi-runtime-config-2024-09-27/world.wit | 0 {v2 => v3}/wit/wit.go | 0 {v2 => v3}/wit/world.wit | 0 374 files changed, 173 insertions(+), 167 deletions(-) delete mode 100644 v2/examples/http/go.mod delete mode 100644 v2/examples/kv/go.mod delete mode 100644 v2/examples/llm/go.mod delete mode 100644 v2/examples/variables/go.mod delete mode 100644 v2/http/testdata/http-tinygo/go.mod delete mode 100644 v2/kv/testdata/key-value/go.mod delete mode 100644 v2/variables/testdata/variables/go.mod rename {v2 => v3}/README.md (87%) create mode 100644 v3/examples/http/go.mod rename {v2 => v3}/examples/http/go.sum (100%) rename {v2 => v3}/examples/http/main.go (87%) rename {v2/http/testdata/http-tinygo => v3/examples/http}/spin.toml (84%) create mode 100644 v3/examples/kv/go.mod rename {v2 => v3}/examples/kv/go.sum (100%) rename {v2 => v3}/examples/kv/main.go (90%) rename {v2 => v3}/examples/kv/spin.toml (85%) rename {v2 => v3}/examples/llm/.gitignore (100%) create mode 100644 v3/examples/llm/go.mod rename {v2 => v3}/examples/llm/go.sum (100%) rename {v2 => v3}/examples/llm/main.go (88%) rename {v2 => v3}/examples/llm/spin.toml (89%) create mode 100644 v3/examples/variables/go.mod rename {v2 => v3}/examples/variables/go.sum (100%) rename {v2 => v3}/examples/variables/main.go (77%) rename {v2 => v3}/examples/variables/spin.toml (87%) rename {v2 => v3}/go.mod (68%) rename {v2 => v3}/go.sum (100%) rename {v2 => v3}/http/client.go (94%) rename {v2 => v3}/http/convertor_incoming_request.go (96%) rename {v2 => v3}/http/convertor_outgoing_request.go (96%) rename {v2 => v3}/http/convertor_outgoing_response.go (97%) rename {v2 => v3}/http/http.go (94%) rename {v2 => v3}/http/streams.go (92%) create mode 100644 v3/http/testdata/http-tinygo/go.mod rename {v2 => v3}/http/testdata/http-tinygo/go.sum (100%) rename {v2 => v3}/http/testdata/http-tinygo/main.go (89%) rename {v2/examples/http => v3/http/testdata/http-tinygo}/spin.toml (84%) rename {v2 => v3}/integration_test.go (100%) rename {v2 => v3}/internal/fermyon/spin/config/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/config/config.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/config/config.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/config/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/http-trigger/http-trigger.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/http-types/http-types.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/http/abi.go (92%) rename {v2 => v3}/internal/fermyon/spin/http/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/http/http.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/http/http.wit.go (94%) rename {v2 => v3}/internal/fermyon/spin/inbound-http/abi.go (92%) rename {v2 => v3}/internal/fermyon/spin/inbound-http/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/inbound-http/inbound-http.exports.go (100%) rename {v2 => v3}/internal/fermyon/spin/inbound-http/inbound-http.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/inbound-http/inbound-http.wit.go (88%) rename {v2 => v3}/internal/fermyon/spin/key-value/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/key-value/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/key-value/key-value.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/key-value/key-value.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/llm/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/llm/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/llm/llm.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/llm/llm.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/mysql/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/mysql/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/mysql/mysql.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/mysql/mysql.wit.go (98%) rename {v2 => v3}/internal/fermyon/spin/postgres/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/postgres/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/postgres/postgres.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/postgres/postgres.wit.go (98%) rename {v2 => v3}/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/redis-types/redis-types.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/redis/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/redis/redis.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/redis/redis.wit.go (98%) rename {v2 => v3}/internal/fermyon/spin/sqlite/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/sqlite/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/sqlite/sqlite.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/sqlite/sqlite.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/key-value/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/key-value/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/llm/llm.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mysql/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mysql/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go (97%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/postgres/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/postgres/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go (97%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/redis/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/redis/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/redis/redis.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/sqlite/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/sqlite/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/variables/abi.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/variables/empty.s (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go (100%) rename {v2 => v3}/internal/fermyon/spin/v2.0.0/variables/variables.wit.go (100%) rename {v2 => v3}/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go (100%) rename {v2 => v3}/internal/spin/postgres/v3.0.0/postgres/abi.go (100%) rename {v2 => v3}/internal/spin/postgres/v3.0.0/postgres/empty.s (100%) rename {v2 => v3}/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go (100%) rename {v2 => v3}/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/environment/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/environment/environment.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/environment/environment.wit.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/exit/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/exit/exit.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/exit/exit.wit.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stderr/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go (90%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdin/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go (90%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdout/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go (90%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-input/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-output/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go (93%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go (93%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go (100%) rename {v2 => v3}/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go (93%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s (100%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go (100%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go (97%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/wall-clock/empty.s (100%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go (100%) rename {v2 => v3}/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go (100%) rename {v2 => v3}/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go (100%) rename {v2 => v3}/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s (100%) rename {v2 => v3}/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go (100%) rename {v2 => v3}/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go (100%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/preopens/empty.s (100%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go (100%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go (91%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/types/abi.go (95%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/types/empty.s (100%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/types/types.wasm.go (100%) rename {v2 => v3}/internal/wasi/filesystem/v0.2.0/types/types.wit.go (99%) rename {v2 => v3}/internal/wasi/http/v0.2.0/incoming-handler/empty.s (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go (92%) rename {v2 => v3}/internal/wasi/http/v0.2.0/outgoing-handler/abi.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/outgoing-handler/empty.s (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go (97%) rename {v2 => v3}/internal/wasi/http/v0.2.0/types/abi.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/types/empty.s (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/types/types.wasm.go (100%) rename {v2 => v3}/internal/wasi/http/v0.2.0/types/types.wit.go (99%) rename {v2 => v3}/internal/wasi/io/v0.2.0/error/empty.s (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/error/error.wasm.go (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/error/error.wit.go (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/poll/empty.s (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/poll/poll.wasm.go (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/poll/poll.wit.go (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/streams/empty.s (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/streams/streams.wasm.go (100%) rename {v2 => v3}/internal/wasi/io/v0.2.0/streams/streams.wit.go (99%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go (98%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go (98%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go (100%) rename {v2 => v3}/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure-seed/empty.s (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure/empty.s (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/insecure/insecure.wit.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/random/empty.s (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/random/random.wasm.go (100%) rename {v2 => v3}/internal/wasi/random/v0.2.0/random/random.wit.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/instance-network/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go (92%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go (97%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/network/abi.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/network/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/network/network.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/network/network.wit.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go (95%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/abi.go (97%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go (99%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go (95%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/abi.go (97%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/empty.s (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go (100%) rename {v2 => v3}/internal/wasi/sockets/v0.2.0/udp/udp.wit.go (99%) rename {v2 => v3}/kv/kv.go (97%) create mode 100644 v3/kv/testdata/key-value/go.mod rename {v2 => v3}/kv/testdata/key-value/go.sum (100%) rename {v2 => v3}/kv/testdata/key-value/main.go (90%) rename {v2 => v3}/kv/testdata/key-value/spin.toml (85%) rename {v2 => v3}/llm/llm.go (98%) create mode 100644 v3/variables/testdata/variables/go.mod rename {v2 => v3}/variables/testdata/variables/go.sum (100%) rename {v2 => v3}/variables/testdata/variables/main.go (77%) rename {v2 => v3}/variables/testdata/variables/spin.toml (87%) rename {v2 => v3}/variables/variables.go (92%) rename {v2 => v3}/wit/deps/cli-2023-10-18/command.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/environment.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/exit.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/reactor.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/run.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/stdio.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-10-18/terminal.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/command.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/environment.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/exit.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/reactor.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/run.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/stdio.wit (100%) rename {v2 => v3}/wit/deps/cli-2023-11-10/terminal.wit (100%) rename {v2 => v3}/wit/deps/cli/command.wit (100%) rename {v2 => v3}/wit/deps/cli/environment.wit (100%) rename {v2 => v3}/wit/deps/cli/exit.wit (100%) rename {v2 => v3}/wit/deps/cli/imports.wit (100%) rename {v2 => v3}/wit/deps/cli/run.wit (100%) rename {v2 => v3}/wit/deps/cli/stdio.wit (100%) rename {v2 => v3}/wit/deps/cli/terminal.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-10-18/monotonic-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-10-18/timezone.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-10-18/wall-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-10-18/world.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-11-10/monotonic-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-11-10/wall-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks-2023-11-10/world.wit (100%) rename {v2 => v3}/wit/deps/clocks/monotonic-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks/wall-clock.wit (100%) rename {v2 => v3}/wit/deps/clocks/world.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-10-18/preopens.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-10-18/types.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-10-18/world.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-11-10/preopens.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-11-10/types.wit (100%) rename {v2 => v3}/wit/deps/filesystem-2023-11-10/world.wit (100%) rename {v2 => v3}/wit/deps/filesystem/preopens.wit (100%) rename {v2 => v3}/wit/deps/filesystem/types.wit (100%) rename {v2 => v3}/wit/deps/filesystem/world.wit (100%) rename {v2 => v3}/wit/deps/http-2023-10-18/incoming-handler.wit (100%) rename {v2 => v3}/wit/deps/http-2023-10-18/outgoing-handler.wit (100%) rename {v2 => v3}/wit/deps/http-2023-10-18/proxy.wit (100%) rename {v2 => v3}/wit/deps/http-2023-10-18/types.wit (100%) rename {v2 => v3}/wit/deps/http-2023-11-10/handler.wit (100%) rename {v2 => v3}/wit/deps/http-2023-11-10/proxy.wit (100%) rename {v2 => v3}/wit/deps/http-2023-11-10/types.wit (100%) rename {v2 => v3}/wit/deps/http/handler.wit (100%) rename {v2 => v3}/wit/deps/http/proxy.wit (100%) rename {v2 => v3}/wit/deps/http/types.wit (100%) rename {v2 => v3}/wit/deps/io-2023-10-18/poll.wit (100%) rename {v2 => v3}/wit/deps/io-2023-10-18/streams.wit (100%) rename {v2 => v3}/wit/deps/io-2023-10-18/world.wit (100%) rename {v2 => v3}/wit/deps/io-2023-11-10/error.wit (100%) rename {v2 => v3}/wit/deps/io-2023-11-10/poll.wit (100%) rename {v2 => v3}/wit/deps/io-2023-11-10/streams.wit (100%) rename {v2 => v3}/wit/deps/io-2023-11-10/world.wit (100%) rename {v2 => v3}/wit/deps/io/error.wit (100%) rename {v2 => v3}/wit/deps/io/poll.wit (100%) rename {v2 => v3}/wit/deps/io/streams.wit (100%) rename {v2 => v3}/wit/deps/io/world.wit (100%) rename {v2 => v3}/wit/deps/keyvalue-2024-10-17/atomic.wit (100%) rename {v2 => v3}/wit/deps/keyvalue-2024-10-17/batch.wit (100%) rename {v2 => v3}/wit/deps/keyvalue-2024-10-17/store.wit (100%) rename {v2 => v3}/wit/deps/keyvalue-2024-10-17/watch.wit (100%) rename {v2 => v3}/wit/deps/keyvalue-2024-10-17/world.wit (100%) rename {v2 => v3}/wit/deps/random-2023-10-18/insecure-seed.wit (100%) rename {v2 => v3}/wit/deps/random-2023-10-18/insecure.wit (100%) rename {v2 => v3}/wit/deps/random-2023-10-18/random.wit (100%) rename {v2 => v3}/wit/deps/random-2023-10-18/world.wit (100%) rename {v2 => v3}/wit/deps/random-2023-11-10/insecure-seed.wit (100%) rename {v2 => v3}/wit/deps/random-2023-11-10/insecure.wit (100%) rename {v2 => v3}/wit/deps/random-2023-11-10/random.wit (100%) rename {v2 => v3}/wit/deps/random-2023-11-10/world.wit (100%) rename {v2 => v3}/wit/deps/random/insecure-seed.wit (100%) rename {v2 => v3}/wit/deps/random/insecure.wit (100%) rename {v2 => v3}/wit/deps/random/random.wit (100%) rename {v2 => v3}/wit/deps/random/world.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/instance-network.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/ip-name-lookup.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/network.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/tcp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/tcp.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/udp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/udp.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-10-18/world.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/instance-network.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/ip-name-lookup.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/network.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/tcp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/tcp.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/udp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/udp.wit (100%) rename {v2 => v3}/wit/deps/sockets-2023-11-10/world.wit (100%) rename {v2 => v3}/wit/deps/sockets/instance-network.wit (100%) rename {v2 => v3}/wit/deps/sockets/ip-name-lookup.wit (100%) rename {v2 => v3}/wit/deps/sockets/network.wit (100%) rename {v2 => v3}/wit/deps/sockets/tcp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets/tcp.wit (100%) rename {v2 => v3}/wit/deps/sockets/udp-create-socket.wit (100%) rename {v2 => v3}/wit/deps/sockets/udp.wit (100%) rename {v2 => v3}/wit/deps/sockets/world.wit (100%) rename {v2 => v3}/wit/deps/spin-postgres@3.0.0/postgres.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/key-value.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/llm.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/mqtt.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/mysql.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/postgres.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/rdbms-types.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/redis.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/sqlite.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/variables.wit (100%) rename {v2 => v3}/wit/deps/spin@2.0.0/world.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/config.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/http-types.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/http.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/inbound-http.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/inbound-redis.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/key-value.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/llm.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/mysql.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/postgres.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/rdbms-types.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/redis-types.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/redis.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/sqlite.wit (100%) rename {v2 => v3}/wit/deps/spin@unversioned/world.wit (100%) rename {v2 => v3}/wit/deps/wasi-runtime-config-2024-09-27/store.wit (100%) rename {v2 => v3}/wit/deps/wasi-runtime-config-2024-09-27/world.wit (100%) rename {v2 => v3}/wit/wit.go (100%) rename {v2 => v3}/wit/world.wit (100%) diff --git a/Makefile b/Makefile index e82a2b18..e82f2fb7 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ test-integration: http/testdata/http-tinygo/main.wasm go test -v -count=1 . .PHONY: test-integration-wasip2 -test-integration-wasip2: - cd v2 && go test -v -count=1 . +test-integration-wasip2: + cd v3 && go test -v -count=1 . http/testdata/http-tinygo/main.wasm: generate http/testdata/http-tinygo/main.wasm: http/testdata/http-tinygo/main.go diff --git a/v2/examples/http/go.mod b/v2/examples/http/go.mod deleted file mode 100644 index 07a0d32f..00000000 --- a/v2/examples/http/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/examples/http - -go 1.23.2 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/kv/go.mod b/v2/examples/kv/go.mod deleted file mode 100644 index 5496fc65..00000000 --- a/v2/examples/kv/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/examples/kv - -go 1.24.1 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/llm/go.mod b/v2/examples/llm/go.mod deleted file mode 100644 index cc73aecf..00000000 --- a/v2/examples/llm/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/examples/llm - -go 1.24.1 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/examples/variables/go.mod b/v2/examples/variables/go.mod deleted file mode 100644 index 3d0a5f58..00000000 --- a/v2/examples/variables/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/examples/variables - -go 1.24.1 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../ diff --git a/v2/http/testdata/http-tinygo/go.mod b/v2/http/testdata/http-tinygo/go.mod deleted file mode 100644 index 864c3383..00000000 --- a/v2/http/testdata/http-tinygo/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/http/testdata/http - -go 1.23.2 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/kv/testdata/key-value/go.mod b/v2/kv/testdata/key-value/go.mod deleted file mode 100644 index 5528778a..00000000 --- a/v2/kv/testdata/key-value/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/http/testdata/kv - -go 1.24.1 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/variables/testdata/variables/go.mod b/v2/variables/testdata/variables/go.mod deleted file mode 100644 index 74ae187d..00000000 --- a/v2/variables/testdata/variables/go.mod +++ /dev/null @@ -1,12 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v2/examples/variables - -go 1.24.1 - -require github.com/spinframework/spin-go-sdk/v2 v2.0.0 - -require ( - github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v2 => ../../../ diff --git a/v2/README.md b/v3/README.md similarity index 87% rename from v2/README.md rename to v3/README.md index 56dce87e..e19db003 100644 --- a/v2/README.md +++ b/v3/README.md @@ -18,12 +18,12 @@ Regeneratin bindings: - install tooling as specified above - make sure they are on PATH and picking up the versions as specified above -- cd `/v2` -- Run: `wit-bindgen-go generate -w http-trigger -p github.com/spinframework/spin-go-sdk/v2/internal --out internal ./wit` +- cd `/v3` +- Run: `wit-bindgen-go generate -w http-trigger -p github.com/spinframework/spin-go-sdk/v3/internal --out internal ./wit` Testing: -- cd `/v2/examples/http` +- cd `/v3/examples/http` - Run `spin build` - Run `spin up` - In a separate terminal, run: `curl http://127.0.0.1:3000/hello` diff --git a/v3/examples/http/go.mod b/v3/examples/http/go.mod new file mode 100644 index 00000000..09edc64a --- /dev/null +++ b/v3/examples/http/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/http + +go 1.23.2 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v2/examples/http/go.sum b/v3/examples/http/go.sum similarity index 100% rename from v2/examples/http/go.sum rename to v3/examples/http/go.sum diff --git a/v2/examples/http/main.go b/v3/examples/http/main.go similarity index 87% rename from v2/examples/http/main.go rename to v3/examples/http/main.go index 90e2864c..d3f99656 100644 --- a/v2/examples/http/main.go +++ b/v3/examples/http/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { diff --git a/v2/http/testdata/http-tinygo/spin.toml b/v3/examples/http/spin.toml similarity index 84% rename from v2/http/testdata/http-tinygo/spin.toml rename to v3/examples/http/spin.toml index 52b31fb2..cdf364bd 100644 --- a/v2/http/testdata/http-tinygo/spin.toml +++ b/v3/examples/http/spin.toml @@ -13,4 +13,5 @@ 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/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v3/examples/kv/go.mod b/v3/examples/kv/go.mod new file mode 100644 index 00000000..50932795 --- /dev/null +++ b/v3/examples/kv/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/kv + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v2/examples/kv/go.sum b/v3/examples/kv/go.sum similarity index 100% rename from v2/examples/kv/go.sum rename to v3/examples/kv/go.sum diff --git a/v2/examples/kv/main.go b/v3/examples/kv/main.go similarity index 90% rename from v2/examples/kv/main.go rename to v3/examples/kv/main.go index 012c946a..4cfc8be5 100644 --- a/v2/examples/kv/main.go +++ b/v3/examples/kv/main.go @@ -5,8 +5,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/kv" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/kv" ) func init() { diff --git a/v2/examples/kv/spin.toml b/v3/examples/kv/spin.toml similarity index 85% rename from v2/examples/kv/spin.toml rename to v3/examples/kv/spin.toml index b35d1c01..f0649962 100644 --- a/v2/examples/kv/spin.toml +++ b/v3/examples/kv/spin.toml @@ -14,4 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v2/examples/llm/.gitignore b/v3/examples/llm/.gitignore similarity index 100% rename from v2/examples/llm/.gitignore rename to v3/examples/llm/.gitignore diff --git a/v3/examples/llm/go.mod b/v3/examples/llm/go.mod new file mode 100644 index 00000000..7d5787b8 --- /dev/null +++ b/v3/examples/llm/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/llm + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v2/examples/llm/go.sum b/v3/examples/llm/go.sum similarity index 100% rename from v2/examples/llm/go.sum rename to v3/examples/llm/go.sum diff --git a/v2/examples/llm/main.go b/v3/examples/llm/main.go similarity index 88% rename from v2/examples/llm/main.go rename to v3/examples/llm/main.go index 55dae4ec..c0712980 100644 --- a/v2/examples/llm/main.go +++ b/v3/examples/llm/main.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/llm" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/llm" ) func init() { diff --git a/v2/examples/llm/spin.toml b/v3/examples/llm/spin.toml similarity index 89% rename from v2/examples/llm/spin.toml rename to v3/examples/llm/spin.toml index bcdda809..48395efd 100644 --- a/v2/examples/llm/spin.toml +++ b/v3/examples/llm/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] ai_models = ["llama2-chat", "all-minilm-l6-v2"] [component.llm.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/variables/go.mod b/v3/examples/variables/go.mod new file mode 100644 index 00000000..428e0b6d --- /dev/null +++ b/v3/examples/variables/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/variables + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v2/examples/variables/go.sum b/v3/examples/variables/go.sum similarity index 100% rename from v2/examples/variables/go.sum rename to v3/examples/variables/go.sum diff --git a/v2/examples/variables/main.go b/v3/examples/variables/main.go similarity index 77% rename from v2/examples/variables/main.go rename to v3/examples/variables/main.go index e0a4091d..4791c8b1 100644 --- a/v2/examples/variables/main.go +++ b/v3/examples/variables/main.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/variables" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/variables" ) func init() { diff --git a/v2/examples/variables/spin.toml b/v3/examples/variables/spin.toml similarity index 87% rename from v2/examples/variables/spin.toml rename to v3/examples/variables/spin.toml index 6c9fdb6e..0ca6a397 100644 --- a/v2/examples/variables/spin.toml +++ b/v3/examples/variables/spin.toml @@ -19,4 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v2/go.mod b/v3/go.mod similarity index 68% rename from v2/go.mod rename to v3/go.mod index ac994dcc..4610aa65 100644 --- a/v2/go.mod +++ b/v3/go.mod @@ -1,4 +1,4 @@ -module github.com/spinframework/spin-go-sdk/v2 +module github.com/spinframework/spin-go-sdk/v3 go 1.23.2 diff --git a/v2/go.sum b/v3/go.sum similarity index 100% rename from v2/go.sum rename to v3/go.sum diff --git a/v2/http/client.go b/v3/http/client.go similarity index 94% rename from v2/http/client.go rename to v3/http/client.go index e8465325..b4ed4f8a 100644 --- a/v2/http/client.go +++ b/v3/http/client.go @@ -5,8 +5,8 @@ import ( "io" "net/http" - outgoinghandler "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/outgoing-handler" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + outgoinghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/outgoing-handler" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_incoming_request.go b/v3/http/convertor_incoming_request.go similarity index 96% rename from v2/http/convertor_incoming_request.go rename to v3/http/convertor_incoming_request.go index 9346b57a..97d5fbb0 100644 --- a/v2/http/convertor_incoming_request.go +++ b/v3/http/convertor_incoming_request.go @@ -5,7 +5,7 @@ import ( "io" "net/http" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_outgoing_request.go b/v3/http/convertor_outgoing_request.go similarity index 96% rename from v2/http/convertor_outgoing_request.go rename to v3/http/convertor_outgoing_request.go index daf462b4..738ec8c5 100644 --- a/v2/http/convertor_outgoing_request.go +++ b/v3/http/convertor_outgoing_request.go @@ -3,7 +3,7 @@ package http import ( "net/http" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/convertor_outgoing_response.go b/v3/http/convertor_outgoing_response.go similarity index 97% rename from v2/http/convertor_outgoing_response.go rename to v3/http/convertor_outgoing_response.go index 36729331..a8cfcea4 100644 --- a/v2/http/convertor_outgoing_response.go +++ b/v3/http/convertor_outgoing_response.go @@ -5,8 +5,8 @@ import ( "net/http" "strings" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/http/http.go b/v3/http/http.go similarity index 94% rename from v2/http/http.go rename to v3/http/http.go index c57e0b64..47c85aa6 100644 --- a/v2/http/http.go +++ b/v3/http/http.go @@ -8,9 +8,9 @@ import ( "os" "github.com/julienschmidt/httprouter" - incominghandler "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/incoming-handler" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" - "github.com/spinframework/spin-go-sdk/v2/wit" + incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/incoming-handler" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/wit" ) // force wit files to be shipped with sdk dependency diff --git a/v2/http/streams.go b/v3/http/streams.go similarity index 92% rename from v2/http/streams.go rename to v3/http/streams.go index d24bdbf8..8e1513fd 100644 --- a/v2/http/streams.go +++ b/v3/http/streams.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" ) type inputStreamReader struct { diff --git a/v3/http/testdata/http-tinygo/go.mod b/v3/http/testdata/http-tinygo/go.mod new file mode 100644 index 00000000..68be74b4 --- /dev/null +++ b/v3/http/testdata/http-tinygo/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/http/testdata/http + +go 1.23.2 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v2/http/testdata/http-tinygo/go.sum b/v3/http/testdata/http-tinygo/go.sum similarity index 100% rename from v2/http/testdata/http-tinygo/go.sum rename to v3/http/testdata/http-tinygo/go.sum diff --git a/v2/http/testdata/http-tinygo/main.go b/v3/http/testdata/http-tinygo/main.go similarity index 89% rename from v2/http/testdata/http-tinygo/main.go rename to v3/http/testdata/http-tinygo/main.go index 4b626d07..cc986078 100644 --- a/v2/http/testdata/http-tinygo/main.go +++ b/v3/http/testdata/http-tinygo/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { diff --git a/v2/examples/http/spin.toml b/v3/http/testdata/http-tinygo/spin.toml similarity index 84% rename from v2/examples/http/spin.toml rename to v3/http/testdata/http-tinygo/spin.toml index 52b31fb2..cdf364bd 100644 --- a/v2/examples/http/spin.toml +++ b/v3/http/testdata/http-tinygo/spin.toml @@ -13,4 +13,5 @@ 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/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v2/integration_test.go b/v3/integration_test.go similarity index 100% rename from v2/integration_test.go rename to v3/integration_test.go diff --git a/v2/internal/fermyon/spin/config/abi.go b/v3/internal/fermyon/spin/config/abi.go similarity index 100% rename from v2/internal/fermyon/spin/config/abi.go rename to v3/internal/fermyon/spin/config/abi.go diff --git a/v2/internal/fermyon/spin/config/config.wasm.go b/v3/internal/fermyon/spin/config/config.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/config/config.wasm.go rename to v3/internal/fermyon/spin/config/config.wasm.go diff --git a/v2/internal/fermyon/spin/config/config.wit.go b/v3/internal/fermyon/spin/config/config.wit.go similarity index 100% rename from v2/internal/fermyon/spin/config/config.wit.go rename to v3/internal/fermyon/spin/config/config.wit.go diff --git a/v2/internal/fermyon/spin/config/empty.s b/v3/internal/fermyon/spin/config/empty.s similarity index 100% rename from v2/internal/fermyon/spin/config/empty.s rename to v3/internal/fermyon/spin/config/empty.s diff --git a/v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go similarity index 100% rename from v2/internal/fermyon/spin/http-trigger/http-trigger.wit.go rename to v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go diff --git a/v2/internal/fermyon/spin/http-types/http-types.wit.go b/v3/internal/fermyon/spin/http-types/http-types.wit.go similarity index 100% rename from v2/internal/fermyon/spin/http-types/http-types.wit.go rename to v3/internal/fermyon/spin/http-types/http-types.wit.go diff --git a/v2/internal/fermyon/spin/http/abi.go b/v3/internal/fermyon/spin/http/abi.go similarity index 92% rename from v2/internal/fermyon/spin/http/abi.go rename to v3/internal/fermyon/spin/http/abi.go index 9d51d703..39139618 100644 --- a/v2/internal/fermyon/spin/http/abi.go +++ b/v3/internal/fermyon/spin/http/abi.go @@ -3,7 +3,7 @@ package http import ( - httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" "unsafe" ) diff --git a/v2/internal/fermyon/spin/http/empty.s b/v3/internal/fermyon/spin/http/empty.s similarity index 100% rename from v2/internal/fermyon/spin/http/empty.s rename to v3/internal/fermyon/spin/http/empty.s diff --git a/v2/internal/fermyon/spin/http/http.wasm.go b/v3/internal/fermyon/spin/http/http.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/http/http.wasm.go rename to v3/internal/fermyon/spin/http/http.wasm.go diff --git a/v2/internal/fermyon/spin/http/http.wit.go b/v3/internal/fermyon/spin/http/http.wit.go similarity index 94% rename from v2/internal/fermyon/spin/http/http.wit.go rename to v3/internal/fermyon/spin/http/http.wit.go index bf022ce0..63c3fb1d 100644 --- a/v2/internal/fermyon/spin/http/http.wit.go +++ b/v3/internal/fermyon/spin/http/http.wit.go @@ -4,7 +4,7 @@ package http import ( - httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/inbound-http/abi.go b/v3/internal/fermyon/spin/inbound-http/abi.go similarity index 92% rename from v2/internal/fermyon/spin/inbound-http/abi.go rename to v3/internal/fermyon/spin/inbound-http/abi.go index 660c96eb..0f09e935 100644 --- a/v2/internal/fermyon/spin/inbound-http/abi.go +++ b/v3/internal/fermyon/spin/inbound-http/abi.go @@ -3,7 +3,7 @@ package inboundhttp import ( - httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/inbound-http/empty.s b/v3/internal/fermyon/spin/inbound-http/empty.s similarity index 100% rename from v2/internal/fermyon/spin/inbound-http/empty.s rename to v3/internal/fermyon/spin/inbound-http/empty.s diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go similarity index 100% rename from v2/internal/fermyon/spin/inbound-http/inbound-http.exports.go rename to v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.wasm.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/inbound-http/inbound-http.wasm.go rename to v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go diff --git a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go similarity index 88% rename from v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go rename to v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go index 0edd9c10..aefeb211 100644 --- a/v2/internal/fermyon/spin/inbound-http/inbound-http.wit.go +++ b/v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go @@ -4,7 +4,7 @@ package inboundhttp import ( - httptypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/http-types" + httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" ) // Request represents the type alias "fermyon:spin/inbound-http#request". diff --git a/v2/internal/fermyon/spin/key-value/abi.go b/v3/internal/fermyon/spin/key-value/abi.go similarity index 100% rename from v2/internal/fermyon/spin/key-value/abi.go rename to v3/internal/fermyon/spin/key-value/abi.go diff --git a/v2/internal/fermyon/spin/key-value/empty.s b/v3/internal/fermyon/spin/key-value/empty.s similarity index 100% rename from v2/internal/fermyon/spin/key-value/empty.s rename to v3/internal/fermyon/spin/key-value/empty.s diff --git a/v2/internal/fermyon/spin/key-value/key-value.wasm.go b/v3/internal/fermyon/spin/key-value/key-value.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/key-value/key-value.wasm.go rename to v3/internal/fermyon/spin/key-value/key-value.wasm.go diff --git a/v2/internal/fermyon/spin/key-value/key-value.wit.go b/v3/internal/fermyon/spin/key-value/key-value.wit.go similarity index 100% rename from v2/internal/fermyon/spin/key-value/key-value.wit.go rename to v3/internal/fermyon/spin/key-value/key-value.wit.go diff --git a/v2/internal/fermyon/spin/llm/abi.go b/v3/internal/fermyon/spin/llm/abi.go similarity index 100% rename from v2/internal/fermyon/spin/llm/abi.go rename to v3/internal/fermyon/spin/llm/abi.go diff --git a/v2/internal/fermyon/spin/llm/empty.s b/v3/internal/fermyon/spin/llm/empty.s similarity index 100% rename from v2/internal/fermyon/spin/llm/empty.s rename to v3/internal/fermyon/spin/llm/empty.s diff --git a/v2/internal/fermyon/spin/llm/llm.wasm.go b/v3/internal/fermyon/spin/llm/llm.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/llm/llm.wasm.go rename to v3/internal/fermyon/spin/llm/llm.wasm.go diff --git a/v2/internal/fermyon/spin/llm/llm.wit.go b/v3/internal/fermyon/spin/llm/llm.wit.go similarity index 100% rename from v2/internal/fermyon/spin/llm/llm.wit.go rename to v3/internal/fermyon/spin/llm/llm.wit.go diff --git a/v2/internal/fermyon/spin/mysql/abi.go b/v3/internal/fermyon/spin/mysql/abi.go similarity index 100% rename from v2/internal/fermyon/spin/mysql/abi.go rename to v3/internal/fermyon/spin/mysql/abi.go diff --git a/v2/internal/fermyon/spin/mysql/empty.s b/v3/internal/fermyon/spin/mysql/empty.s similarity index 100% rename from v2/internal/fermyon/spin/mysql/empty.s rename to v3/internal/fermyon/spin/mysql/empty.s diff --git a/v2/internal/fermyon/spin/mysql/mysql.wasm.go b/v3/internal/fermyon/spin/mysql/mysql.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/mysql/mysql.wasm.go rename to v3/internal/fermyon/spin/mysql/mysql.wasm.go diff --git a/v2/internal/fermyon/spin/mysql/mysql.wit.go b/v3/internal/fermyon/spin/mysql/mysql.wit.go similarity index 98% rename from v2/internal/fermyon/spin/mysql/mysql.wit.go rename to v3/internal/fermyon/spin/mysql/mysql.wit.go index d7888f4d..91921384 100644 --- a/v2/internal/fermyon/spin/mysql/mysql.wit.go +++ b/v3/internal/fermyon/spin/mysql/mysql.wit.go @@ -4,7 +4,7 @@ package mysql import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/postgres/abi.go b/v3/internal/fermyon/spin/postgres/abi.go similarity index 100% rename from v2/internal/fermyon/spin/postgres/abi.go rename to v3/internal/fermyon/spin/postgres/abi.go diff --git a/v2/internal/fermyon/spin/postgres/empty.s b/v3/internal/fermyon/spin/postgres/empty.s similarity index 100% rename from v2/internal/fermyon/spin/postgres/empty.s rename to v3/internal/fermyon/spin/postgres/empty.s diff --git a/v2/internal/fermyon/spin/postgres/postgres.wasm.go b/v3/internal/fermyon/spin/postgres/postgres.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/postgres/postgres.wasm.go rename to v3/internal/fermyon/spin/postgres/postgres.wasm.go diff --git a/v2/internal/fermyon/spin/postgres/postgres.wit.go b/v3/internal/fermyon/spin/postgres/postgres.wit.go similarity index 98% rename from v2/internal/fermyon/spin/postgres/postgres.wit.go rename to v3/internal/fermyon/spin/postgres/postgres.wit.go index 31523eae..d67ca9b8 100644 --- a/v2/internal/fermyon/spin/postgres/postgres.wit.go +++ b/v3/internal/fermyon/spin/postgres/postgres.wit.go @@ -4,7 +4,7 @@ package postgres import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/rdbms-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go similarity index 100% rename from v2/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go rename to v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go diff --git a/v2/internal/fermyon/spin/redis-types/redis-types.wit.go b/v3/internal/fermyon/spin/redis-types/redis-types.wit.go similarity index 100% rename from v2/internal/fermyon/spin/redis-types/redis-types.wit.go rename to v3/internal/fermyon/spin/redis-types/redis-types.wit.go diff --git a/v2/internal/fermyon/spin/redis/empty.s b/v3/internal/fermyon/spin/redis/empty.s similarity index 100% rename from v2/internal/fermyon/spin/redis/empty.s rename to v3/internal/fermyon/spin/redis/empty.s diff --git a/v2/internal/fermyon/spin/redis/redis.wasm.go b/v3/internal/fermyon/spin/redis/redis.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/redis/redis.wasm.go rename to v3/internal/fermyon/spin/redis/redis.wasm.go diff --git a/v2/internal/fermyon/spin/redis/redis.wit.go b/v3/internal/fermyon/spin/redis/redis.wit.go similarity index 98% rename from v2/internal/fermyon/spin/redis/redis.wit.go rename to v3/internal/fermyon/spin/redis/redis.wit.go index c8672af6..f4ff970c 100644 --- a/v2/internal/fermyon/spin/redis/redis.wit.go +++ b/v3/internal/fermyon/spin/redis/redis.wit.go @@ -4,7 +4,7 @@ package redis import ( - redistypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/redis-types" + redistypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/redis-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/sqlite/abi.go b/v3/internal/fermyon/spin/sqlite/abi.go similarity index 100% rename from v2/internal/fermyon/spin/sqlite/abi.go rename to v3/internal/fermyon/spin/sqlite/abi.go diff --git a/v2/internal/fermyon/spin/sqlite/empty.s b/v3/internal/fermyon/spin/sqlite/empty.s similarity index 100% rename from v2/internal/fermyon/spin/sqlite/empty.s rename to v3/internal/fermyon/spin/sqlite/empty.s diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wasm.go b/v3/internal/fermyon/spin/sqlite/sqlite.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/sqlite/sqlite.wasm.go rename to v3/internal/fermyon/spin/sqlite/sqlite.wasm.go diff --git a/v2/internal/fermyon/spin/sqlite/sqlite.wit.go b/v3/internal/fermyon/spin/sqlite/sqlite.wit.go similarity index 100% rename from v2/internal/fermyon/spin/sqlite/sqlite.wit.go rename to v3/internal/fermyon/spin/sqlite/sqlite.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go rename to v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/abi.go b/v3/internal/fermyon/spin/v2.0.0/key-value/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/key-value/abi.go rename to v3/internal/fermyon/spin/v2.0.0/key-value/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/empty.s b/v3/internal/fermyon/spin/v2.0.0/key-value/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/key-value/empty.s rename to v3/internal/fermyon/spin/v2.0.0/key-value/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go b/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go b/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go rename to v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/abi.go b/v3/internal/fermyon/spin/v2.0.0/llm/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/llm/abi.go rename to v3/internal/fermyon/spin/v2.0.0/llm/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/empty.s b/v3/internal/fermyon/spin/v2.0.0/llm/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/llm/empty.s rename to v3/internal/fermyon/spin/v2.0.0/llm/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go b/v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go b/v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/llm/llm.wit.go rename to v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mqtt/abi.go rename to v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s b/v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mqtt/empty.s rename to v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go rename to v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/abi.go b/v3/internal/fermyon/spin/v2.0.0/mysql/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mysql/abi.go rename to v3/internal/fermyon/spin/v2.0.0/mysql/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/empty.s b/v3/internal/fermyon/spin/v2.0.0/mysql/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mysql/empty.s rename to v3/internal/fermyon/spin/v2.0.0/mysql/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go b/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go b/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go similarity index 97% rename from v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go rename to v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go index 186e35d7..890b85f0 100644 --- a/v2/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go +++ b/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go @@ -4,7 +4,7 @@ package mysql import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/abi.go b/v3/internal/fermyon/spin/v2.0.0/postgres/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/postgres/abi.go rename to v3/internal/fermyon/spin/v2.0.0/postgres/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/empty.s b/v3/internal/fermyon/spin/v2.0.0/postgres/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/postgres/empty.s rename to v3/internal/fermyon/spin/v2.0.0/postgres/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go b/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go b/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go similarity index 97% rename from v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go rename to v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go index 51270c90..112cf948 100644 --- a/v2/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go +++ b/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go @@ -4,7 +4,7 @@ package postgres import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/rdbms-types" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go b/v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go rename to v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/abi.go b/v3/internal/fermyon/spin/v2.0.0/redis/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/redis/abi.go rename to v3/internal/fermyon/spin/v2.0.0/redis/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/empty.s b/v3/internal/fermyon/spin/v2.0.0/redis/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/redis/empty.s rename to v3/internal/fermyon/spin/v2.0.0/redis/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go b/v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go b/v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/redis/redis.wit.go rename to v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/sqlite/abi.go rename to v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s b/v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/sqlite/empty.s rename to v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go rename to v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/abi.go b/v3/internal/fermyon/spin/v2.0.0/variables/abi.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/variables/abi.go rename to v3/internal/fermyon/spin/v2.0.0/variables/abi.go diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/empty.s b/v3/internal/fermyon/spin/v2.0.0/variables/empty.s similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/variables/empty.s rename to v3/internal/fermyon/spin/v2.0.0/variables/empty.s diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go b/v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go rename to v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go diff --git a/v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go b/v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v2.0.0/variables/variables.wit.go rename to v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go diff --git a/v2/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go similarity index 100% rename from v2/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go rename to v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/abi.go b/v3/internal/spin/postgres/v3.0.0/postgres/abi.go similarity index 100% rename from v2/internal/spin/postgres/v3.0.0/postgres/abi.go rename to v3/internal/spin/postgres/v3.0.0/postgres/abi.go diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/empty.s b/v3/internal/spin/postgres/v3.0.0/postgres/empty.s similarity index 100% rename from v2/internal/spin/postgres/v3.0.0/postgres/empty.s rename to v3/internal/spin/postgres/v3.0.0/postgres/empty.s diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go b/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go similarity index 100% rename from v2/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go rename to v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go diff --git a/v2/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go b/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go similarity index 100% rename from v2/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go rename to v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go diff --git a/v2/internal/wasi/cli/v0.2.0/environment/empty.s b/v3/internal/wasi/cli/v0.2.0/environment/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/environment/empty.s rename to v3/internal/wasi/cli/v0.2.0/environment/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go b/v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/environment/environment.wasm.go rename to v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/environment/environment.wit.go rename to v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go diff --git a/v2/internal/wasi/cli/v0.2.0/exit/empty.s b/v3/internal/wasi/cli/v0.2.0/exit/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/exit/empty.s rename to v3/internal/wasi/cli/v0.2.0/exit/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go b/v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/exit/exit.wasm.go rename to v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/exit/exit.wit.go rename to v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/empty.s b/v3/internal/wasi/cli/v0.2.0/stderr/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stderr/empty.s rename to v3/internal/wasi/cli/v0.2.0/stderr/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go b/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go rename to v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go similarity index 90% rename from v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go rename to v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go index 1358235a..07957121 100644 --- a/v2/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -4,7 +4,7 @@ package stderr import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/empty.s b/v3/internal/wasi/cli/v0.2.0/stdin/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stdin/empty.s rename to v3/internal/wasi/cli/v0.2.0/stdin/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go b/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go rename to v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go similarity index 90% rename from v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go rename to v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go index 4d83364d..96dbc47e 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -4,7 +4,7 @@ package stdin import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/empty.s b/v3/internal/wasi/cli/v0.2.0/stdout/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stdout/empty.s rename to v3/internal/wasi/cli/v0.2.0/stdout/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go b/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go rename to v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go similarity index 90% rename from v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go rename to v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go index 8e34da3f..5e4487d5 100644 --- a/v2/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -4,7 +4,7 @@ package stdout import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-input/empty.s rename to v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go rename to v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go rename to v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-output/empty.s rename to v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go rename to v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go rename to v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s rename to v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go similarity index 93% rename from v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go index 4ff295fb..e62c6a51 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -7,7 +7,7 @@ package terminalstderr import ( - terminaloutput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + terminaloutput "github.com/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-output" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s rename to v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go similarity index 93% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go index 3f8ae91e..fc4c6f37 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -7,7 +7,7 @@ package terminalstdin import ( - terminalinput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-input" + terminalinput "github.com/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-input" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s rename to v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go similarity index 100% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go diff --git a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go similarity index 93% rename from v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go rename to v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go index 564967dc..0b8eea9f 100644 --- a/v2/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go +++ b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -7,7 +7,7 @@ package terminalstdout import ( - terminaloutput "github.com/spinframework/spin-go-sdk/v2/internal/wasi/cli/v0.2.0/terminal-output" + terminaloutput "github.com/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-output" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s rename to v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go rename to v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go diff --git a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go similarity index 97% rename from v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go rename to v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go index dfaa9fde..e70e42fd 100644 --- a/v2/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go +++ b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -15,7 +15,7 @@ package monotonicclock import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s b/v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/wall-clock/empty.s rename to v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go b/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go rename to v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go diff --git a/v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go b/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go similarity index 100% rename from v2/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go rename to v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go similarity index 100% rename from v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go rename to v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s similarity index 100% rename from v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s rename to v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go similarity index 100% rename from v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go rename to v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go diff --git a/v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go similarity index 100% rename from v2/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go rename to v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s b/v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s similarity index 100% rename from v2/internal/wasi/filesystem/v0.2.0/preopens/empty.s rename to v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go b/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go similarity index 100% rename from v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go rename to v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go diff --git a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go similarity index 91% rename from v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go rename to v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go index 7a8f2d1e..a54013a0 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go +++ b/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -4,7 +4,7 @@ package preopens import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/filesystem/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/filesystem/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go b/v3/internal/wasi/filesystem/v0.2.0/types/abi.go similarity index 95% rename from v2/internal/wasi/filesystem/v0.2.0/types/abi.go rename to v3/internal/wasi/filesystem/v0.2.0/types/abi.go index 7b981dfe..f9ca50b6 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/abi.go +++ b/v3/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -3,7 +3,7 @@ package types import ( - wallclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" + wallclock "github.com/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/wall-clock" "go.bytecodealliance.org/cm" "unsafe" ) diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/empty.s b/v3/internal/wasi/filesystem/v0.2.0/types/empty.s similarity index 100% rename from v2/internal/wasi/filesystem/v0.2.0/types/empty.s rename to v3/internal/wasi/filesystem/v0.2.0/types/empty.s diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go b/v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go similarity index 100% rename from v2/internal/wasi/filesystem/v0.2.0/types/types.wasm.go rename to v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go diff --git a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go similarity index 99% rename from v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go rename to v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go index 8b1c5af5..6885fc45 100644 --- a/v2/internal/wasi/filesystem/v0.2.0/types/types.wit.go +++ b/v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -29,8 +29,8 @@ package types import ( - wallclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/wall-clock" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + wallclock "github.com/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/wall-clock" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s b/v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s similarity index 100% rename from v2/internal/wasi/http/v0.2.0/incoming-handler/empty.s rename to v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go rename to v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go rename to v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go diff --git a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go similarity index 92% rename from v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go rename to v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go index 0e3d66c9..b1d69596 100644 --- a/v2/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go +++ b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go @@ -7,7 +7,7 @@ package incominghandler import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" ) // IncomingRequest represents the exported type alias "wasi:http/incoming-handler@0.2.0#incoming-request". diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/outgoing-handler/abi.go rename to v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s b/v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s similarity index 100% rename from v2/internal/wasi/http/v0.2.0/outgoing-handler/empty.s rename to v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go rename to v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go diff --git a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go similarity index 97% rename from v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go rename to v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go index fc7455f3..6a4190e8 100644 --- a/v2/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go +++ b/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go @@ -7,7 +7,7 @@ package outgoinghandler import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/http/v0.2.0/types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/http/v0.2.0/types/abi.go b/v3/internal/wasi/http/v0.2.0/types/abi.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/types/abi.go rename to v3/internal/wasi/http/v0.2.0/types/abi.go diff --git a/v2/internal/wasi/http/v0.2.0/types/empty.s b/v3/internal/wasi/http/v0.2.0/types/empty.s similarity index 100% rename from v2/internal/wasi/http/v0.2.0/types/empty.s rename to v3/internal/wasi/http/v0.2.0/types/empty.s diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wasm.go b/v3/internal/wasi/http/v0.2.0/types/types.wasm.go similarity index 100% rename from v2/internal/wasi/http/v0.2.0/types/types.wasm.go rename to v3/internal/wasi/http/v0.2.0/types/types.wasm.go diff --git a/v2/internal/wasi/http/v0.2.0/types/types.wit.go b/v3/internal/wasi/http/v0.2.0/types/types.wit.go similarity index 99% rename from v2/internal/wasi/http/v0.2.0/types/types.wit.go rename to v3/internal/wasi/http/v0.2.0/types/types.wit.go index 68bfe2ec..fe72a34f 100644 --- a/v2/internal/wasi/http/v0.2.0/types/types.wit.go +++ b/v3/internal/wasi/http/v0.2.0/types/types.wit.go @@ -8,10 +8,10 @@ package types import ( - monotonicclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" - ioerror "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" + monotonicclock "github.com/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/monotonic-clock" + ioerror "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/error" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/io/v0.2.0/error/empty.s b/v3/internal/wasi/io/v0.2.0/error/empty.s similarity index 100% rename from v2/internal/wasi/io/v0.2.0/error/empty.s rename to v3/internal/wasi/io/v0.2.0/error/empty.s diff --git a/v2/internal/wasi/io/v0.2.0/error/error.wasm.go b/v3/internal/wasi/io/v0.2.0/error/error.wasm.go similarity index 100% rename from v2/internal/wasi/io/v0.2.0/error/error.wasm.go rename to v3/internal/wasi/io/v0.2.0/error/error.wasm.go diff --git a/v2/internal/wasi/io/v0.2.0/error/error.wit.go b/v3/internal/wasi/io/v0.2.0/error/error.wit.go similarity index 100% rename from v2/internal/wasi/io/v0.2.0/error/error.wit.go rename to v3/internal/wasi/io/v0.2.0/error/error.wit.go diff --git a/v2/internal/wasi/io/v0.2.0/poll/empty.s b/v3/internal/wasi/io/v0.2.0/poll/empty.s similarity index 100% rename from v2/internal/wasi/io/v0.2.0/poll/empty.s rename to v3/internal/wasi/io/v0.2.0/poll/empty.s diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go b/v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go similarity index 100% rename from v2/internal/wasi/io/v0.2.0/poll/poll.wasm.go rename to v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go diff --git a/v2/internal/wasi/io/v0.2.0/poll/poll.wit.go b/v3/internal/wasi/io/v0.2.0/poll/poll.wit.go similarity index 100% rename from v2/internal/wasi/io/v0.2.0/poll/poll.wit.go rename to v3/internal/wasi/io/v0.2.0/poll/poll.wit.go diff --git a/v2/internal/wasi/io/v0.2.0/streams/empty.s b/v3/internal/wasi/io/v0.2.0/streams/empty.s similarity index 100% rename from v2/internal/wasi/io/v0.2.0/streams/empty.s rename to v3/internal/wasi/io/v0.2.0/streams/empty.s diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go b/v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go similarity index 100% rename from v2/internal/wasi/io/v0.2.0/streams/streams.wasm.go rename to v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go diff --git a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go b/v3/internal/wasi/io/v0.2.0/streams/streams.wit.go similarity index 99% rename from v2/internal/wasi/io/v0.2.0/streams/streams.wit.go rename to v3/internal/wasi/io/v0.2.0/streams/streams.wit.go index 6e258eed..d2807315 100644 --- a/v2/internal/wasi/io/v0.2.0/streams/streams.wit.go +++ b/v3/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -10,8 +10,8 @@ package streams import ( - ioerror "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/error" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" + ioerror "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/error" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go similarity index 98% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go index 205fbe12..f71e5638 100644 --- a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go +++ b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go @@ -20,7 +20,7 @@ package atomics import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/keyvalue/v0.2.0-draft2/store" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/keyvalue/v0.2.0-draft2/store" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go similarity index 98% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go index b1ca7152..a934a1f0 100644 --- a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go +++ b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go @@ -32,7 +32,7 @@ package batch import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/keyvalue/v0.2.0-draft2/store" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/keyvalue/v0.2.0-draft2/store" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go diff --git a/v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go similarity index 100% rename from v2/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go rename to v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s b/v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure-seed/empty.s rename to v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go b/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go rename to v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go diff --git a/v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go b/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go rename to v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go diff --git a/v2/internal/wasi/random/v0.2.0/insecure/empty.s b/v3/internal/wasi/random/v0.2.0/insecure/empty.s similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure/empty.s rename to v3/internal/wasi/random/v0.2.0/insecure/empty.s diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go b/v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go rename to v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go diff --git a/v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/insecure/insecure.wit.go rename to v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go diff --git a/v2/internal/wasi/random/v0.2.0/random/empty.s b/v3/internal/wasi/random/v0.2.0/random/empty.s similarity index 100% rename from v2/internal/wasi/random/v0.2.0/random/empty.s rename to v3/internal/wasi/random/v0.2.0/random/empty.s diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wasm.go b/v3/internal/wasi/random/v0.2.0/random/random.wasm.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/random/random.wasm.go rename to v3/internal/wasi/random/v0.2.0/random/random.wasm.go diff --git a/v2/internal/wasi/random/v0.2.0/random/random.wit.go b/v3/internal/wasi/random/v0.2.0/random/random.wit.go similarity index 100% rename from v2/internal/wasi/random/v0.2.0/random/random.wit.go rename to v3/internal/wasi/random/v0.2.0/random/random.wit.go diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s b/v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/instance-network/empty.s rename to v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go b/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go similarity index 92% rename from v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go rename to v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go index fee8730e..381b5cce 100644 --- a/v2/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -6,7 +6,7 @@ package instancenetwork import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go rename to v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s rename to v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go similarity index 97% rename from v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go rename to v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go index 63a5fbe9..96791c89 100644 --- a/v2/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -4,8 +4,8 @@ package ipnamelookup import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/network/abi.go b/v3/internal/wasi/sockets/v0.2.0/network/abi.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/network/abi.go rename to v3/internal/wasi/sockets/v0.2.0/network/abi.go diff --git a/v2/internal/wasi/sockets/v0.2.0/network/empty.s b/v3/internal/wasi/sockets/v0.2.0/network/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/network/empty.s rename to v3/internal/wasi/sockets/v0.2.0/network/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go b/v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/network/network.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/network/network.wit.go b/v3/internal/wasi/sockets/v0.2.0/network/network.wit.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/network/network.wit.go rename to v3/internal/wasi/sockets/v0.2.0/network/network.wit.go diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s rename to v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go similarity index 95% rename from v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go rename to v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go index 44143983..5d2c9837 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -4,8 +4,8 @@ package tcpcreatesocket import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/tcp" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/tcp" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v3/internal/wasi/sockets/v0.2.0/tcp/abi.go similarity index 97% rename from v2/internal/wasi/sockets/v0.2.0/tcp/abi.go rename to v3/internal/wasi/sockets/v0.2.0/tcp/abi.go index 25c05901..665de00d 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ b/v3/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -3,7 +3,7 @@ package tcp import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" "unsafe" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/empty.s b/v3/internal/wasi/sockets/v0.2.0/tcp/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/tcp/empty.s rename to v3/internal/wasi/sockets/v0.2.0/tcp/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go b/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go similarity index 99% rename from v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go rename to v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go index 72131944..9f00f376 100644 --- a/v2/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -4,10 +4,10 @@ package tcp import ( - monotonicclock "github.com/spinframework/spin-go-sdk/v2/internal/wasi/clocks/v0.2.0/monotonic-clock" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/streams" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + monotonicclock "github.com/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/monotonic-clock" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s rename to v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go similarity index 95% rename from v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go rename to v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go index c9efe70c..af9c0e94 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -4,8 +4,8 @@ package udpcreatesocket import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/udp" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/udp" "go.bytecodealliance.org/cm" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go b/v3/internal/wasi/sockets/v0.2.0/udp/abi.go similarity index 97% rename from v2/internal/wasi/sockets/v0.2.0/udp/abi.go rename to v3/internal/wasi/sockets/v0.2.0/udp/abi.go index babcd376..0d8d5995 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/abi.go +++ b/v3/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -3,7 +3,7 @@ package udp import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" "unsafe" ) diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/empty.s b/v3/internal/wasi/sockets/v0.2.0/udp/empty.s similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/udp/empty.s rename to v3/internal/wasi/sockets/v0.2.0/udp/empty.s diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go b/v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go similarity index 100% rename from v2/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go rename to v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go diff --git a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go similarity index 99% rename from v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go rename to v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go index 425c6e25..16f6ccd0 100644 --- a/v2/internal/wasi/sockets/v0.2.0/udp/udp.wit.go +++ b/v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -4,8 +4,8 @@ package udp import ( - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v2/internal/wasi/sockets/v0.2.0/network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" "go.bytecodealliance.org/cm" ) diff --git a/v2/kv/kv.go b/v3/kv/kv.go similarity index 97% rename from v2/kv/kv.go rename to v3/kv/kv.go index 0a6eb6b0..a381c4f0 100644 --- a/v2/kv/kv.go +++ b/v3/kv/kv.go @@ -3,7 +3,7 @@ package kv import ( "fmt" - keyvalue "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/key-value" + keyvalue "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/key-value" "go.bytecodealliance.org/cm" ) diff --git a/v3/kv/testdata/key-value/go.mod b/v3/kv/testdata/key-value/go.mod new file mode 100644 index 00000000..7eaae3f7 --- /dev/null +++ b/v3/kv/testdata/key-value/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/http/testdata/kv + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v2/kv/testdata/key-value/go.sum b/v3/kv/testdata/key-value/go.sum similarity index 100% rename from v2/kv/testdata/key-value/go.sum rename to v3/kv/testdata/key-value/go.sum diff --git a/v2/kv/testdata/key-value/main.go b/v3/kv/testdata/key-value/main.go similarity index 90% rename from v2/kv/testdata/key-value/main.go rename to v3/kv/testdata/key-value/main.go index 012c946a..4cfc8be5 100644 --- a/v2/kv/testdata/key-value/main.go +++ b/v3/kv/testdata/key-value/main.go @@ -5,8 +5,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/kv" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/kv" ) func init() { diff --git a/v2/kv/testdata/key-value/spin.toml b/v3/kv/testdata/key-value/spin.toml similarity index 85% rename from v2/kv/testdata/key-value/spin.toml rename to v3/kv/testdata/key-value/spin.toml index bfd75049..ea812110 100644 --- a/v2/kv/testdata/key-value/spin.toml +++ b/v3/kv/testdata/key-value/spin.toml @@ -14,4 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v2/llm/llm.go b/v3/llm/llm.go similarity index 98% rename from v2/llm/llm.go rename to v3/llm/llm.go index ac4b94db..b634c390 100644 --- a/v2/llm/llm.go +++ b/v3/llm/llm.go @@ -3,7 +3,7 @@ package llm import ( "fmt" - "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/llm" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/llm" "go.bytecodealliance.org/cm" ) diff --git a/v3/variables/testdata/variables/go.mod b/v3/variables/testdata/variables/go.mod new file mode 100644 index 00000000..6c5be5e0 --- /dev/null +++ b/v3/variables/testdata/variables/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/variables + +go 1.24.1 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v2/variables/testdata/variables/go.sum b/v3/variables/testdata/variables/go.sum similarity index 100% rename from v2/variables/testdata/variables/go.sum rename to v3/variables/testdata/variables/go.sum diff --git a/v2/variables/testdata/variables/main.go b/v3/variables/testdata/variables/main.go similarity index 77% rename from v2/variables/testdata/variables/main.go rename to v3/variables/testdata/variables/main.go index bd16daff..b59196de 100644 --- a/v2/variables/testdata/variables/main.go +++ b/v3/variables/testdata/variables/main.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/variables" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/variables" ) func init() { diff --git a/v2/variables/testdata/variables/spin.toml b/v3/variables/testdata/variables/spin.toml similarity index 87% rename from v2/variables/testdata/variables/spin.toml rename to v3/variables/testdata/variables/spin.toml index f51dd6db..58959765 100644 --- a/v2/variables/testdata/variables/spin.toml +++ b/v3/variables/testdata/variables/spin.toml @@ -19,4 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v2)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" \ No newline at end of file +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" + diff --git a/v2/variables/variables.go b/v3/variables/variables.go similarity index 92% rename from v2/variables/variables.go rename to v3/variables/variables.go index 7223fdd1..87fbd5b5 100644 --- a/v2/variables/variables.go +++ b/v3/variables/variables.go @@ -3,7 +3,7 @@ package variables import ( "fmt" - "github.com/spinframework/spin-go-sdk/v2/internal/fermyon/spin/v2.0.0/variables" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/variables" ) // Get an application variable value for the current component. diff --git a/v2/wit/deps/cli-2023-10-18/command.wit b/v3/wit/deps/cli-2023-10-18/command.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/command.wit rename to v3/wit/deps/cli-2023-10-18/command.wit diff --git a/v2/wit/deps/cli-2023-10-18/environment.wit b/v3/wit/deps/cli-2023-10-18/environment.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/environment.wit rename to v3/wit/deps/cli-2023-10-18/environment.wit diff --git a/v2/wit/deps/cli-2023-10-18/exit.wit b/v3/wit/deps/cli-2023-10-18/exit.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/exit.wit rename to v3/wit/deps/cli-2023-10-18/exit.wit diff --git a/v2/wit/deps/cli-2023-10-18/reactor.wit b/v3/wit/deps/cli-2023-10-18/reactor.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/reactor.wit rename to v3/wit/deps/cli-2023-10-18/reactor.wit diff --git a/v2/wit/deps/cli-2023-10-18/run.wit b/v3/wit/deps/cli-2023-10-18/run.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/run.wit rename to v3/wit/deps/cli-2023-10-18/run.wit diff --git a/v2/wit/deps/cli-2023-10-18/stdio.wit b/v3/wit/deps/cli-2023-10-18/stdio.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/stdio.wit rename to v3/wit/deps/cli-2023-10-18/stdio.wit diff --git a/v2/wit/deps/cli-2023-10-18/terminal.wit b/v3/wit/deps/cli-2023-10-18/terminal.wit similarity index 100% rename from v2/wit/deps/cli-2023-10-18/terminal.wit rename to v3/wit/deps/cli-2023-10-18/terminal.wit diff --git a/v2/wit/deps/cli-2023-11-10/command.wit b/v3/wit/deps/cli-2023-11-10/command.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/command.wit rename to v3/wit/deps/cli-2023-11-10/command.wit diff --git a/v2/wit/deps/cli-2023-11-10/environment.wit b/v3/wit/deps/cli-2023-11-10/environment.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/environment.wit rename to v3/wit/deps/cli-2023-11-10/environment.wit diff --git a/v2/wit/deps/cli-2023-11-10/exit.wit b/v3/wit/deps/cli-2023-11-10/exit.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/exit.wit rename to v3/wit/deps/cli-2023-11-10/exit.wit diff --git a/v2/wit/deps/cli-2023-11-10/reactor.wit b/v3/wit/deps/cli-2023-11-10/reactor.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/reactor.wit rename to v3/wit/deps/cli-2023-11-10/reactor.wit diff --git a/v2/wit/deps/cli-2023-11-10/run.wit b/v3/wit/deps/cli-2023-11-10/run.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/run.wit rename to v3/wit/deps/cli-2023-11-10/run.wit diff --git a/v2/wit/deps/cli-2023-11-10/stdio.wit b/v3/wit/deps/cli-2023-11-10/stdio.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/stdio.wit rename to v3/wit/deps/cli-2023-11-10/stdio.wit diff --git a/v2/wit/deps/cli-2023-11-10/terminal.wit b/v3/wit/deps/cli-2023-11-10/terminal.wit similarity index 100% rename from v2/wit/deps/cli-2023-11-10/terminal.wit rename to v3/wit/deps/cli-2023-11-10/terminal.wit diff --git a/v2/wit/deps/cli/command.wit b/v3/wit/deps/cli/command.wit similarity index 100% rename from v2/wit/deps/cli/command.wit rename to v3/wit/deps/cli/command.wit diff --git a/v2/wit/deps/cli/environment.wit b/v3/wit/deps/cli/environment.wit similarity index 100% rename from v2/wit/deps/cli/environment.wit rename to v3/wit/deps/cli/environment.wit diff --git a/v2/wit/deps/cli/exit.wit b/v3/wit/deps/cli/exit.wit similarity index 100% rename from v2/wit/deps/cli/exit.wit rename to v3/wit/deps/cli/exit.wit diff --git a/v2/wit/deps/cli/imports.wit b/v3/wit/deps/cli/imports.wit similarity index 100% rename from v2/wit/deps/cli/imports.wit rename to v3/wit/deps/cli/imports.wit diff --git a/v2/wit/deps/cli/run.wit b/v3/wit/deps/cli/run.wit similarity index 100% rename from v2/wit/deps/cli/run.wit rename to v3/wit/deps/cli/run.wit diff --git a/v2/wit/deps/cli/stdio.wit b/v3/wit/deps/cli/stdio.wit similarity index 100% rename from v2/wit/deps/cli/stdio.wit rename to v3/wit/deps/cli/stdio.wit diff --git a/v2/wit/deps/cli/terminal.wit b/v3/wit/deps/cli/terminal.wit similarity index 100% rename from v2/wit/deps/cli/terminal.wit rename to v3/wit/deps/cli/terminal.wit diff --git a/v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit b/v3/wit/deps/clocks-2023-10-18/monotonic-clock.wit similarity index 100% rename from v2/wit/deps/clocks-2023-10-18/monotonic-clock.wit rename to v3/wit/deps/clocks-2023-10-18/monotonic-clock.wit diff --git a/v2/wit/deps/clocks-2023-10-18/timezone.wit b/v3/wit/deps/clocks-2023-10-18/timezone.wit similarity index 100% rename from v2/wit/deps/clocks-2023-10-18/timezone.wit rename to v3/wit/deps/clocks-2023-10-18/timezone.wit diff --git a/v2/wit/deps/clocks-2023-10-18/wall-clock.wit b/v3/wit/deps/clocks-2023-10-18/wall-clock.wit similarity index 100% rename from v2/wit/deps/clocks-2023-10-18/wall-clock.wit rename to v3/wit/deps/clocks-2023-10-18/wall-clock.wit diff --git a/v2/wit/deps/clocks-2023-10-18/world.wit b/v3/wit/deps/clocks-2023-10-18/world.wit similarity index 100% rename from v2/wit/deps/clocks-2023-10-18/world.wit rename to v3/wit/deps/clocks-2023-10-18/world.wit diff --git a/v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit b/v3/wit/deps/clocks-2023-11-10/monotonic-clock.wit similarity index 100% rename from v2/wit/deps/clocks-2023-11-10/monotonic-clock.wit rename to v3/wit/deps/clocks-2023-11-10/monotonic-clock.wit diff --git a/v2/wit/deps/clocks-2023-11-10/wall-clock.wit b/v3/wit/deps/clocks-2023-11-10/wall-clock.wit similarity index 100% rename from v2/wit/deps/clocks-2023-11-10/wall-clock.wit rename to v3/wit/deps/clocks-2023-11-10/wall-clock.wit diff --git a/v2/wit/deps/clocks-2023-11-10/world.wit b/v3/wit/deps/clocks-2023-11-10/world.wit similarity index 100% rename from v2/wit/deps/clocks-2023-11-10/world.wit rename to v3/wit/deps/clocks-2023-11-10/world.wit diff --git a/v2/wit/deps/clocks/monotonic-clock.wit b/v3/wit/deps/clocks/monotonic-clock.wit similarity index 100% rename from v2/wit/deps/clocks/monotonic-clock.wit rename to v3/wit/deps/clocks/monotonic-clock.wit diff --git a/v2/wit/deps/clocks/wall-clock.wit b/v3/wit/deps/clocks/wall-clock.wit similarity index 100% rename from v2/wit/deps/clocks/wall-clock.wit rename to v3/wit/deps/clocks/wall-clock.wit diff --git a/v2/wit/deps/clocks/world.wit b/v3/wit/deps/clocks/world.wit similarity index 100% rename from v2/wit/deps/clocks/world.wit rename to v3/wit/deps/clocks/world.wit diff --git a/v2/wit/deps/filesystem-2023-10-18/preopens.wit b/v3/wit/deps/filesystem-2023-10-18/preopens.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-10-18/preopens.wit rename to v3/wit/deps/filesystem-2023-10-18/preopens.wit diff --git a/v2/wit/deps/filesystem-2023-10-18/types.wit b/v3/wit/deps/filesystem-2023-10-18/types.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-10-18/types.wit rename to v3/wit/deps/filesystem-2023-10-18/types.wit diff --git a/v2/wit/deps/filesystem-2023-10-18/world.wit b/v3/wit/deps/filesystem-2023-10-18/world.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-10-18/world.wit rename to v3/wit/deps/filesystem-2023-10-18/world.wit diff --git a/v2/wit/deps/filesystem-2023-11-10/preopens.wit b/v3/wit/deps/filesystem-2023-11-10/preopens.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-11-10/preopens.wit rename to v3/wit/deps/filesystem-2023-11-10/preopens.wit diff --git a/v2/wit/deps/filesystem-2023-11-10/types.wit b/v3/wit/deps/filesystem-2023-11-10/types.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-11-10/types.wit rename to v3/wit/deps/filesystem-2023-11-10/types.wit diff --git a/v2/wit/deps/filesystem-2023-11-10/world.wit b/v3/wit/deps/filesystem-2023-11-10/world.wit similarity index 100% rename from v2/wit/deps/filesystem-2023-11-10/world.wit rename to v3/wit/deps/filesystem-2023-11-10/world.wit diff --git a/v2/wit/deps/filesystem/preopens.wit b/v3/wit/deps/filesystem/preopens.wit similarity index 100% rename from v2/wit/deps/filesystem/preopens.wit rename to v3/wit/deps/filesystem/preopens.wit diff --git a/v2/wit/deps/filesystem/types.wit b/v3/wit/deps/filesystem/types.wit similarity index 100% rename from v2/wit/deps/filesystem/types.wit rename to v3/wit/deps/filesystem/types.wit diff --git a/v2/wit/deps/filesystem/world.wit b/v3/wit/deps/filesystem/world.wit similarity index 100% rename from v2/wit/deps/filesystem/world.wit rename to v3/wit/deps/filesystem/world.wit diff --git a/v2/wit/deps/http-2023-10-18/incoming-handler.wit b/v3/wit/deps/http-2023-10-18/incoming-handler.wit similarity index 100% rename from v2/wit/deps/http-2023-10-18/incoming-handler.wit rename to v3/wit/deps/http-2023-10-18/incoming-handler.wit diff --git a/v2/wit/deps/http-2023-10-18/outgoing-handler.wit b/v3/wit/deps/http-2023-10-18/outgoing-handler.wit similarity index 100% rename from v2/wit/deps/http-2023-10-18/outgoing-handler.wit rename to v3/wit/deps/http-2023-10-18/outgoing-handler.wit diff --git a/v2/wit/deps/http-2023-10-18/proxy.wit b/v3/wit/deps/http-2023-10-18/proxy.wit similarity index 100% rename from v2/wit/deps/http-2023-10-18/proxy.wit rename to v3/wit/deps/http-2023-10-18/proxy.wit diff --git a/v2/wit/deps/http-2023-10-18/types.wit b/v3/wit/deps/http-2023-10-18/types.wit similarity index 100% rename from v2/wit/deps/http-2023-10-18/types.wit rename to v3/wit/deps/http-2023-10-18/types.wit diff --git a/v2/wit/deps/http-2023-11-10/handler.wit b/v3/wit/deps/http-2023-11-10/handler.wit similarity index 100% rename from v2/wit/deps/http-2023-11-10/handler.wit rename to v3/wit/deps/http-2023-11-10/handler.wit diff --git a/v2/wit/deps/http-2023-11-10/proxy.wit b/v3/wit/deps/http-2023-11-10/proxy.wit similarity index 100% rename from v2/wit/deps/http-2023-11-10/proxy.wit rename to v3/wit/deps/http-2023-11-10/proxy.wit diff --git a/v2/wit/deps/http-2023-11-10/types.wit b/v3/wit/deps/http-2023-11-10/types.wit similarity index 100% rename from v2/wit/deps/http-2023-11-10/types.wit rename to v3/wit/deps/http-2023-11-10/types.wit diff --git a/v2/wit/deps/http/handler.wit b/v3/wit/deps/http/handler.wit similarity index 100% rename from v2/wit/deps/http/handler.wit rename to v3/wit/deps/http/handler.wit diff --git a/v2/wit/deps/http/proxy.wit b/v3/wit/deps/http/proxy.wit similarity index 100% rename from v2/wit/deps/http/proxy.wit rename to v3/wit/deps/http/proxy.wit diff --git a/v2/wit/deps/http/types.wit b/v3/wit/deps/http/types.wit similarity index 100% rename from v2/wit/deps/http/types.wit rename to v3/wit/deps/http/types.wit diff --git a/v2/wit/deps/io-2023-10-18/poll.wit b/v3/wit/deps/io-2023-10-18/poll.wit similarity index 100% rename from v2/wit/deps/io-2023-10-18/poll.wit rename to v3/wit/deps/io-2023-10-18/poll.wit diff --git a/v2/wit/deps/io-2023-10-18/streams.wit b/v3/wit/deps/io-2023-10-18/streams.wit similarity index 100% rename from v2/wit/deps/io-2023-10-18/streams.wit rename to v3/wit/deps/io-2023-10-18/streams.wit diff --git a/v2/wit/deps/io-2023-10-18/world.wit b/v3/wit/deps/io-2023-10-18/world.wit similarity index 100% rename from v2/wit/deps/io-2023-10-18/world.wit rename to v3/wit/deps/io-2023-10-18/world.wit diff --git a/v2/wit/deps/io-2023-11-10/error.wit b/v3/wit/deps/io-2023-11-10/error.wit similarity index 100% rename from v2/wit/deps/io-2023-11-10/error.wit rename to v3/wit/deps/io-2023-11-10/error.wit diff --git a/v2/wit/deps/io-2023-11-10/poll.wit b/v3/wit/deps/io-2023-11-10/poll.wit similarity index 100% rename from v2/wit/deps/io-2023-11-10/poll.wit rename to v3/wit/deps/io-2023-11-10/poll.wit diff --git a/v2/wit/deps/io-2023-11-10/streams.wit b/v3/wit/deps/io-2023-11-10/streams.wit similarity index 100% rename from v2/wit/deps/io-2023-11-10/streams.wit rename to v3/wit/deps/io-2023-11-10/streams.wit diff --git a/v2/wit/deps/io-2023-11-10/world.wit b/v3/wit/deps/io-2023-11-10/world.wit similarity index 100% rename from v2/wit/deps/io-2023-11-10/world.wit rename to v3/wit/deps/io-2023-11-10/world.wit diff --git a/v2/wit/deps/io/error.wit b/v3/wit/deps/io/error.wit similarity index 100% rename from v2/wit/deps/io/error.wit rename to v3/wit/deps/io/error.wit diff --git a/v2/wit/deps/io/poll.wit b/v3/wit/deps/io/poll.wit similarity index 100% rename from v2/wit/deps/io/poll.wit rename to v3/wit/deps/io/poll.wit diff --git a/v2/wit/deps/io/streams.wit b/v3/wit/deps/io/streams.wit similarity index 100% rename from v2/wit/deps/io/streams.wit rename to v3/wit/deps/io/streams.wit diff --git a/v2/wit/deps/io/world.wit b/v3/wit/deps/io/world.wit similarity index 100% rename from v2/wit/deps/io/world.wit rename to v3/wit/deps/io/world.wit diff --git a/v2/wit/deps/keyvalue-2024-10-17/atomic.wit b/v3/wit/deps/keyvalue-2024-10-17/atomic.wit similarity index 100% rename from v2/wit/deps/keyvalue-2024-10-17/atomic.wit rename to v3/wit/deps/keyvalue-2024-10-17/atomic.wit diff --git a/v2/wit/deps/keyvalue-2024-10-17/batch.wit b/v3/wit/deps/keyvalue-2024-10-17/batch.wit similarity index 100% rename from v2/wit/deps/keyvalue-2024-10-17/batch.wit rename to v3/wit/deps/keyvalue-2024-10-17/batch.wit diff --git a/v2/wit/deps/keyvalue-2024-10-17/store.wit b/v3/wit/deps/keyvalue-2024-10-17/store.wit similarity index 100% rename from v2/wit/deps/keyvalue-2024-10-17/store.wit rename to v3/wit/deps/keyvalue-2024-10-17/store.wit diff --git a/v2/wit/deps/keyvalue-2024-10-17/watch.wit b/v3/wit/deps/keyvalue-2024-10-17/watch.wit similarity index 100% rename from v2/wit/deps/keyvalue-2024-10-17/watch.wit rename to v3/wit/deps/keyvalue-2024-10-17/watch.wit diff --git a/v2/wit/deps/keyvalue-2024-10-17/world.wit b/v3/wit/deps/keyvalue-2024-10-17/world.wit similarity index 100% rename from v2/wit/deps/keyvalue-2024-10-17/world.wit rename to v3/wit/deps/keyvalue-2024-10-17/world.wit diff --git a/v2/wit/deps/random-2023-10-18/insecure-seed.wit b/v3/wit/deps/random-2023-10-18/insecure-seed.wit similarity index 100% rename from v2/wit/deps/random-2023-10-18/insecure-seed.wit rename to v3/wit/deps/random-2023-10-18/insecure-seed.wit diff --git a/v2/wit/deps/random-2023-10-18/insecure.wit b/v3/wit/deps/random-2023-10-18/insecure.wit similarity index 100% rename from v2/wit/deps/random-2023-10-18/insecure.wit rename to v3/wit/deps/random-2023-10-18/insecure.wit diff --git a/v2/wit/deps/random-2023-10-18/random.wit b/v3/wit/deps/random-2023-10-18/random.wit similarity index 100% rename from v2/wit/deps/random-2023-10-18/random.wit rename to v3/wit/deps/random-2023-10-18/random.wit diff --git a/v2/wit/deps/random-2023-10-18/world.wit b/v3/wit/deps/random-2023-10-18/world.wit similarity index 100% rename from v2/wit/deps/random-2023-10-18/world.wit rename to v3/wit/deps/random-2023-10-18/world.wit diff --git a/v2/wit/deps/random-2023-11-10/insecure-seed.wit b/v3/wit/deps/random-2023-11-10/insecure-seed.wit similarity index 100% rename from v2/wit/deps/random-2023-11-10/insecure-seed.wit rename to v3/wit/deps/random-2023-11-10/insecure-seed.wit diff --git a/v2/wit/deps/random-2023-11-10/insecure.wit b/v3/wit/deps/random-2023-11-10/insecure.wit similarity index 100% rename from v2/wit/deps/random-2023-11-10/insecure.wit rename to v3/wit/deps/random-2023-11-10/insecure.wit diff --git a/v2/wit/deps/random-2023-11-10/random.wit b/v3/wit/deps/random-2023-11-10/random.wit similarity index 100% rename from v2/wit/deps/random-2023-11-10/random.wit rename to v3/wit/deps/random-2023-11-10/random.wit diff --git a/v2/wit/deps/random-2023-11-10/world.wit b/v3/wit/deps/random-2023-11-10/world.wit similarity index 100% rename from v2/wit/deps/random-2023-11-10/world.wit rename to v3/wit/deps/random-2023-11-10/world.wit diff --git a/v2/wit/deps/random/insecure-seed.wit b/v3/wit/deps/random/insecure-seed.wit similarity index 100% rename from v2/wit/deps/random/insecure-seed.wit rename to v3/wit/deps/random/insecure-seed.wit diff --git a/v2/wit/deps/random/insecure.wit b/v3/wit/deps/random/insecure.wit similarity index 100% rename from v2/wit/deps/random/insecure.wit rename to v3/wit/deps/random/insecure.wit diff --git a/v2/wit/deps/random/random.wit b/v3/wit/deps/random/random.wit similarity index 100% rename from v2/wit/deps/random/random.wit rename to v3/wit/deps/random/random.wit diff --git a/v2/wit/deps/random/world.wit b/v3/wit/deps/random/world.wit similarity index 100% rename from v2/wit/deps/random/world.wit rename to v3/wit/deps/random/world.wit diff --git a/v2/wit/deps/sockets-2023-10-18/instance-network.wit b/v3/wit/deps/sockets-2023-10-18/instance-network.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/instance-network.wit rename to v3/wit/deps/sockets-2023-10-18/instance-network.wit diff --git a/v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit b/v3/wit/deps/sockets-2023-10-18/ip-name-lookup.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/ip-name-lookup.wit rename to v3/wit/deps/sockets-2023-10-18/ip-name-lookup.wit diff --git a/v2/wit/deps/sockets-2023-10-18/network.wit b/v3/wit/deps/sockets-2023-10-18/network.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/network.wit rename to v3/wit/deps/sockets-2023-10-18/network.wit diff --git a/v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit b/v3/wit/deps/sockets-2023-10-18/tcp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/tcp-create-socket.wit rename to v3/wit/deps/sockets-2023-10-18/tcp-create-socket.wit diff --git a/v2/wit/deps/sockets-2023-10-18/tcp.wit b/v3/wit/deps/sockets-2023-10-18/tcp.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/tcp.wit rename to v3/wit/deps/sockets-2023-10-18/tcp.wit diff --git a/v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit b/v3/wit/deps/sockets-2023-10-18/udp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/udp-create-socket.wit rename to v3/wit/deps/sockets-2023-10-18/udp-create-socket.wit diff --git a/v2/wit/deps/sockets-2023-10-18/udp.wit b/v3/wit/deps/sockets-2023-10-18/udp.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/udp.wit rename to v3/wit/deps/sockets-2023-10-18/udp.wit diff --git a/v2/wit/deps/sockets-2023-10-18/world.wit b/v3/wit/deps/sockets-2023-10-18/world.wit similarity index 100% rename from v2/wit/deps/sockets-2023-10-18/world.wit rename to v3/wit/deps/sockets-2023-10-18/world.wit diff --git a/v2/wit/deps/sockets-2023-11-10/instance-network.wit b/v3/wit/deps/sockets-2023-11-10/instance-network.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/instance-network.wit rename to v3/wit/deps/sockets-2023-11-10/instance-network.wit diff --git a/v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit b/v3/wit/deps/sockets-2023-11-10/ip-name-lookup.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/ip-name-lookup.wit rename to v3/wit/deps/sockets-2023-11-10/ip-name-lookup.wit diff --git a/v2/wit/deps/sockets-2023-11-10/network.wit b/v3/wit/deps/sockets-2023-11-10/network.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/network.wit rename to v3/wit/deps/sockets-2023-11-10/network.wit diff --git a/v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit b/v3/wit/deps/sockets-2023-11-10/tcp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/tcp-create-socket.wit rename to v3/wit/deps/sockets-2023-11-10/tcp-create-socket.wit diff --git a/v2/wit/deps/sockets-2023-11-10/tcp.wit b/v3/wit/deps/sockets-2023-11-10/tcp.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/tcp.wit rename to v3/wit/deps/sockets-2023-11-10/tcp.wit diff --git a/v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit b/v3/wit/deps/sockets-2023-11-10/udp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/udp-create-socket.wit rename to v3/wit/deps/sockets-2023-11-10/udp-create-socket.wit diff --git a/v2/wit/deps/sockets-2023-11-10/udp.wit b/v3/wit/deps/sockets-2023-11-10/udp.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/udp.wit rename to v3/wit/deps/sockets-2023-11-10/udp.wit diff --git a/v2/wit/deps/sockets-2023-11-10/world.wit b/v3/wit/deps/sockets-2023-11-10/world.wit similarity index 100% rename from v2/wit/deps/sockets-2023-11-10/world.wit rename to v3/wit/deps/sockets-2023-11-10/world.wit diff --git a/v2/wit/deps/sockets/instance-network.wit b/v3/wit/deps/sockets/instance-network.wit similarity index 100% rename from v2/wit/deps/sockets/instance-network.wit rename to v3/wit/deps/sockets/instance-network.wit diff --git a/v2/wit/deps/sockets/ip-name-lookup.wit b/v3/wit/deps/sockets/ip-name-lookup.wit similarity index 100% rename from v2/wit/deps/sockets/ip-name-lookup.wit rename to v3/wit/deps/sockets/ip-name-lookup.wit diff --git a/v2/wit/deps/sockets/network.wit b/v3/wit/deps/sockets/network.wit similarity index 100% rename from v2/wit/deps/sockets/network.wit rename to v3/wit/deps/sockets/network.wit diff --git a/v2/wit/deps/sockets/tcp-create-socket.wit b/v3/wit/deps/sockets/tcp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets/tcp-create-socket.wit rename to v3/wit/deps/sockets/tcp-create-socket.wit diff --git a/v2/wit/deps/sockets/tcp.wit b/v3/wit/deps/sockets/tcp.wit similarity index 100% rename from v2/wit/deps/sockets/tcp.wit rename to v3/wit/deps/sockets/tcp.wit diff --git a/v2/wit/deps/sockets/udp-create-socket.wit b/v3/wit/deps/sockets/udp-create-socket.wit similarity index 100% rename from v2/wit/deps/sockets/udp-create-socket.wit rename to v3/wit/deps/sockets/udp-create-socket.wit diff --git a/v2/wit/deps/sockets/udp.wit b/v3/wit/deps/sockets/udp.wit similarity index 100% rename from v2/wit/deps/sockets/udp.wit rename to v3/wit/deps/sockets/udp.wit diff --git a/v2/wit/deps/sockets/world.wit b/v3/wit/deps/sockets/world.wit similarity index 100% rename from v2/wit/deps/sockets/world.wit rename to v3/wit/deps/sockets/world.wit diff --git a/v2/wit/deps/spin-postgres@3.0.0/postgres.wit b/v3/wit/deps/spin-postgres@3.0.0/postgres.wit similarity index 100% rename from v2/wit/deps/spin-postgres@3.0.0/postgres.wit rename to v3/wit/deps/spin-postgres@3.0.0/postgres.wit diff --git a/v2/wit/deps/spin@2.0.0/key-value.wit b/v3/wit/deps/spin@2.0.0/key-value.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/key-value.wit rename to v3/wit/deps/spin@2.0.0/key-value.wit diff --git a/v2/wit/deps/spin@2.0.0/llm.wit b/v3/wit/deps/spin@2.0.0/llm.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/llm.wit rename to v3/wit/deps/spin@2.0.0/llm.wit diff --git a/v2/wit/deps/spin@2.0.0/mqtt.wit b/v3/wit/deps/spin@2.0.0/mqtt.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/mqtt.wit rename to v3/wit/deps/spin@2.0.0/mqtt.wit diff --git a/v2/wit/deps/spin@2.0.0/mysql.wit b/v3/wit/deps/spin@2.0.0/mysql.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/mysql.wit rename to v3/wit/deps/spin@2.0.0/mysql.wit diff --git a/v2/wit/deps/spin@2.0.0/postgres.wit b/v3/wit/deps/spin@2.0.0/postgres.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/postgres.wit rename to v3/wit/deps/spin@2.0.0/postgres.wit diff --git a/v2/wit/deps/spin@2.0.0/rdbms-types.wit b/v3/wit/deps/spin@2.0.0/rdbms-types.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/rdbms-types.wit rename to v3/wit/deps/spin@2.0.0/rdbms-types.wit diff --git a/v2/wit/deps/spin@2.0.0/redis.wit b/v3/wit/deps/spin@2.0.0/redis.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/redis.wit rename to v3/wit/deps/spin@2.0.0/redis.wit diff --git a/v2/wit/deps/spin@2.0.0/sqlite.wit b/v3/wit/deps/spin@2.0.0/sqlite.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/sqlite.wit rename to v3/wit/deps/spin@2.0.0/sqlite.wit diff --git a/v2/wit/deps/spin@2.0.0/variables.wit b/v3/wit/deps/spin@2.0.0/variables.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/variables.wit rename to v3/wit/deps/spin@2.0.0/variables.wit diff --git a/v2/wit/deps/spin@2.0.0/world.wit b/v3/wit/deps/spin@2.0.0/world.wit similarity index 100% rename from v2/wit/deps/spin@2.0.0/world.wit rename to v3/wit/deps/spin@2.0.0/world.wit diff --git a/v2/wit/deps/spin@unversioned/config.wit b/v3/wit/deps/spin@unversioned/config.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/config.wit rename to v3/wit/deps/spin@unversioned/config.wit diff --git a/v2/wit/deps/spin@unversioned/http-types.wit b/v3/wit/deps/spin@unversioned/http-types.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/http-types.wit rename to v3/wit/deps/spin@unversioned/http-types.wit diff --git a/v2/wit/deps/spin@unversioned/http.wit b/v3/wit/deps/spin@unversioned/http.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/http.wit rename to v3/wit/deps/spin@unversioned/http.wit diff --git a/v2/wit/deps/spin@unversioned/inbound-http.wit b/v3/wit/deps/spin@unversioned/inbound-http.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/inbound-http.wit rename to v3/wit/deps/spin@unversioned/inbound-http.wit diff --git a/v2/wit/deps/spin@unversioned/inbound-redis.wit b/v3/wit/deps/spin@unversioned/inbound-redis.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/inbound-redis.wit rename to v3/wit/deps/spin@unversioned/inbound-redis.wit diff --git a/v2/wit/deps/spin@unversioned/key-value.wit b/v3/wit/deps/spin@unversioned/key-value.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/key-value.wit rename to v3/wit/deps/spin@unversioned/key-value.wit diff --git a/v2/wit/deps/spin@unversioned/llm.wit b/v3/wit/deps/spin@unversioned/llm.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/llm.wit rename to v3/wit/deps/spin@unversioned/llm.wit diff --git a/v2/wit/deps/spin@unversioned/mysql.wit b/v3/wit/deps/spin@unversioned/mysql.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/mysql.wit rename to v3/wit/deps/spin@unversioned/mysql.wit diff --git a/v2/wit/deps/spin@unversioned/postgres.wit b/v3/wit/deps/spin@unversioned/postgres.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/postgres.wit rename to v3/wit/deps/spin@unversioned/postgres.wit diff --git a/v2/wit/deps/spin@unversioned/rdbms-types.wit b/v3/wit/deps/spin@unversioned/rdbms-types.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/rdbms-types.wit rename to v3/wit/deps/spin@unversioned/rdbms-types.wit diff --git a/v2/wit/deps/spin@unversioned/redis-types.wit b/v3/wit/deps/spin@unversioned/redis-types.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/redis-types.wit rename to v3/wit/deps/spin@unversioned/redis-types.wit diff --git a/v2/wit/deps/spin@unversioned/redis.wit b/v3/wit/deps/spin@unversioned/redis.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/redis.wit rename to v3/wit/deps/spin@unversioned/redis.wit diff --git a/v2/wit/deps/spin@unversioned/sqlite.wit b/v3/wit/deps/spin@unversioned/sqlite.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/sqlite.wit rename to v3/wit/deps/spin@unversioned/sqlite.wit diff --git a/v2/wit/deps/spin@unversioned/world.wit b/v3/wit/deps/spin@unversioned/world.wit similarity index 100% rename from v2/wit/deps/spin@unversioned/world.wit rename to v3/wit/deps/spin@unversioned/world.wit diff --git a/v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit b/v3/wit/deps/wasi-runtime-config-2024-09-27/store.wit similarity index 100% rename from v2/wit/deps/wasi-runtime-config-2024-09-27/store.wit rename to v3/wit/deps/wasi-runtime-config-2024-09-27/store.wit diff --git a/v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit b/v3/wit/deps/wasi-runtime-config-2024-09-27/world.wit similarity index 100% rename from v2/wit/deps/wasi-runtime-config-2024-09-27/world.wit rename to v3/wit/deps/wasi-runtime-config-2024-09-27/world.wit diff --git a/v2/wit/wit.go b/v3/wit/wit.go similarity index 100% rename from v2/wit/wit.go rename to v3/wit/wit.go diff --git a/v2/wit/world.wit b/v3/wit/world.wit similarity index 100% rename from v2/wit/world.wit rename to v3/wit/world.wit From ea81e64bb45639e5674fb912b00f9f4a76460896 Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:39:47 -0500 Subject: [PATCH 08/22] feat(mqtt): implement mqtt in wasip2 Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- v3/examples/mqtt-outbound/.gitignore | 2 + v3/examples/mqtt-outbound/README.md | 31 ++++++++++++++ v3/examples/mqtt-outbound/compose.yaml | 15 +++++++ v3/examples/mqtt-outbound/go.mod | 12 ++++++ v3/examples/mqtt-outbound/go.sum | 4 ++ v3/examples/mqtt-outbound/main.go | 44 +++++++++++++++++++ v3/examples/mqtt-outbound/spin.toml | 20 +++++++++ v3/mqtt/mqtt.go | 58 ++++++++++++++++++++++++++ 8 files changed, 186 insertions(+) create mode 100644 v3/examples/mqtt-outbound/.gitignore create mode 100644 v3/examples/mqtt-outbound/README.md create mode 100644 v3/examples/mqtt-outbound/compose.yaml create mode 100644 v3/examples/mqtt-outbound/go.mod create mode 100644 v3/examples/mqtt-outbound/go.sum create mode 100644 v3/examples/mqtt-outbound/main.go create mode 100644 v3/examples/mqtt-outbound/spin.toml create mode 100644 v3/mqtt/mqtt.go diff --git a/v3/examples/mqtt-outbound/.gitignore b/v3/examples/mqtt-outbound/.gitignore new file mode 100644 index 00000000..b5650104 --- /dev/null +++ b/v3/examples/mqtt-outbound/.gitignore @@ -0,0 +1,2 @@ +main.wasm +.spin/ diff --git a/v3/examples/mqtt-outbound/README.md b/v3/examples/mqtt-outbound/README.md new file mode 100644 index 00000000..c3c66c6a --- /dev/null +++ b/v3/examples/mqtt-outbound/README.md @@ -0,0 +1,31 @@ +# Requirements +- Latest version of [TinyGo](https://tinygo.org/getting-started/) +- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) + +# Usage + +In one terminal window, run: +```sh +# Note that the `-d` flag is intentionally omitted +docker compose up +``` + +In another terminal, you'll run your Spin app: +```sh +spin up --build +``` + +In yet another terminal, you'll interact with the Spin app: +```sh +curl localhost:3000/publish +``` + +You will see logs appear in the `docker compose` window that look something like this: +```sh +$ docker compose up +... +broker | 1754324646: New connection from 172.18.0.1:36970 on port 1883. +broker | 1754324646: New client connected from 172.18.0.1:36970 as client001 (p2, c1, k30, u'user'). +subscriber | telemetry Eureka! +broker | 1754324646: Client client001 closed its connection. +``` diff --git a/v3/examples/mqtt-outbound/compose.yaml b/v3/examples/mqtt-outbound/compose.yaml new file mode 100644 index 00000000..d7d82070 --- /dev/null +++ b/v3/examples/mqtt-outbound/compose.yaml @@ -0,0 +1,15 @@ +services: + mosquitto: + image: eclipse-mosquitto:2.0.22 + container_name: broker + ports: + - "1883:1883" + command: mosquitto -c /mosquitto-no-auth.conf + + subscriber: + image: eclipse-mosquitto:2.0.22 + container_name: subscriber + depends_on: + - mosquitto + command: mosquitto_sub -h mosquitto -t '#' -v + restart: "no" # Clean up container when stopped \ No newline at end of file diff --git a/v3/examples/mqtt-outbound/go.mod b/v3/examples/mqtt-outbound/go.mod new file mode 100644 index 00000000..1b69eb44 --- /dev/null +++ b/v3/examples/mqtt-outbound/go.mod @@ -0,0 +1,12 @@ +module github.com/http_go + +go 1.24 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v3/examples/mqtt-outbound/go.sum b/v3/examples/mqtt-outbound/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v3/examples/mqtt-outbound/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/mqtt-outbound/main.go b/v3/examples/mqtt-outbound/main.go new file mode 100644 index 00000000..391628f2 --- /dev/null +++ b/v3/examples/mqtt-outbound/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "net/http" + "os" + "strconv" + + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/mqtt" +) + +func main() {} + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + addr := os.Getenv("MQTT_ADDRESS") + usr := os.Getenv("MQTT_USERNAME") + pass := os.Getenv("MQTT_PASSWORD") + keepAliveStr := os.Getenv("MQTT_KEEP_ALIVE_INTERVAL") + topic := os.Getenv("MQTT_TOPIC") + + keepAlive, err := strconv.Atoi(keepAliveStr) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("MQTT_KEEP_ALIVE_INTERVAL is not valid: must be an integer")) + } + + conn, err := mqtt.OpenConnection(addr, usr, pass, uint64(keepAlive)) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + } + + message := []byte("Eureka!") + + if err := conn.Publish(topic, message, mqtt.QosAtMostOnce); err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + } + + w.WriteHeader(200) + w.Write([]byte("Message successfully published!\n")) + }) +} diff --git a/v3/examples/mqtt-outbound/spin.toml b/v3/examples/mqtt-outbound/spin.toml new file mode 100644 index 00000000..44d39324 --- /dev/null +++ b/v3/examples/mqtt-outbound/spin.toml @@ -0,0 +1,20 @@ +spin_manifest_version = 2 + +[application] +name = "go-mqtt-outbound-example" +version = "0.1.0" +authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] +description = "Using Spin with MQTT" + +[[trigger.http]] +route = "/publish" +component = "mqtt-outbound" + +[component.mqtt-outbound] +source = "main.wasm" +# To test anonymous MQTT authentication, remove the values from MQTT_USERNAME and MQTT_PASSWORD env variables. +environment = { MQTT_ADDRESS = "mqtt://127.0.0.1:1883?client_id=client001", MQTT_USERNAME = "user", MQTT_PASSWORD = "password", MQTT_KEEP_ALIVE_INTERVAL = "30", MQTT_TOPIC = "telemetry" } +allowed_outbound_hosts = ["mqtt://127.0.0.1:1883"] +[component.mqtt-outbound.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] diff --git a/v3/mqtt/mqtt.go b/v3/mqtt/mqtt.go new file mode 100644 index 00000000..8a56b5f9 --- /dev/null +++ b/v3/mqtt/mqtt.go @@ -0,0 +1,58 @@ +package mqtt + +import ( + "errors" + "fmt" + + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/mqtt" + "go.bytecodealliance.org/cm" +) + +type Connection struct { + conn mqtt.Connection +} + +// OpenConnection initializes an MQTT connection +func OpenConnection(address, username, password string, keepAliveIntervalInSecs uint64) (Connection, error) { + conn, err, isErr := mqtt.ConnectionOpen(address, username, password, keepAliveIntervalInSecs).Result() + if isErr { + return Connection{}, toError(&err) + } + + return Connection{conn: conn}, nil +} + +// Publish publishes an MQTT message +func (c *Connection) Publish(topic string, payload []byte, qos QoS) error { + _, err, isErr := c.conn.Publish(topic, mqtt.Payload(cm.ToList(payload)), mqtt.Qos(qos)).Result() + if isErr { + return toError(&err) + } + + return nil +} + +// QoS for publishing Mqtt messages +type QoS = mqtt.Qos + +const ( + QosAtMostOnce = mqtt.QosAtMostOnce + QosAtLeastOnce = mqtt.QosAtLeastOnce + QosExactlyOnce = mqtt.QosExactlyOnce +) + +func toError(err *mqtt.Error) error { + if err == nil { + return nil + } + + if err.String() == "connection-failed" { + return fmt.Errorf("connection-failed: %s", *err.ConnectionFailed()) + } + + if err.String() == "other" { + return fmt.Errorf(*err.Other()) + } + + return errors.New(err.String()) +} From 52313d0e3af95a7ac3f981f83a75adaf506f9808 Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Mon, 25 Aug 2025 17:34:12 -0500 Subject: [PATCH 09/22] feat(redis): implement redis in wasip2 Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- v3/examples/mqtt-outbound/go.mod | 2 +- v3/examples/redis-outbound/README.md | 20 +++ v3/examples/redis-outbound/go.mod | 12 ++ v3/examples/redis-outbound/go.sum | 4 + v3/examples/redis-outbound/main.go | 155 ++++++++++++++++++ v3/examples/redis-outbound/spin.toml | 20 +++ v3/redis/redis.go | 232 +++++++++++++++++++++++++++ 7 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 v3/examples/redis-outbound/README.md create mode 100644 v3/examples/redis-outbound/go.mod create mode 100644 v3/examples/redis-outbound/go.sum create mode 100644 v3/examples/redis-outbound/main.go create mode 100644 v3/examples/redis-outbound/spin.toml create mode 100644 v3/redis/redis.go diff --git a/v3/examples/mqtt-outbound/go.mod b/v3/examples/mqtt-outbound/go.mod index 1b69eb44..1aeb9a92 100644 --- a/v3/examples/mqtt-outbound/go.mod +++ b/v3/examples/mqtt-outbound/go.mod @@ -1,4 +1,4 @@ -module github.com/http_go +module github.com/spinframework/spin-go-sdk/v3/examples/mqtt-outbound go 1.24 diff --git a/v3/examples/redis-outbound/README.md b/v3/examples/redis-outbound/README.md new file mode 100644 index 00000000..f29a426d --- /dev/null +++ b/v3/examples/redis-outbound/README.md @@ -0,0 +1,20 @@ +# Requirements +- Latest version of [TinyGo](https://tinygo.org/getting-started/) +- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) + +# Usage + +In one terminal window, you'll run a Redis container: +```sh +docker run -p 6379:6379 redis:8.2 +``` + +In another terminal, you'll run your Spin app: +```sh +spin up --build +``` + +In yet another terminal, you'll interact with the Spin app: +```sh +curl localhost:3000 +``` \ No newline at end of file diff --git a/v3/examples/redis-outbound/go.mod b/v3/examples/redis-outbound/go.mod new file mode 100644 index 00000000..67543678 --- /dev/null +++ b/v3/examples/redis-outbound/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/redis-outbound + +go 1.24 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v3/examples/redis-outbound/go.sum b/v3/examples/redis-outbound/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v3/examples/redis-outbound/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/redis-outbound/main.go b/v3/examples/redis-outbound/main.go new file mode 100644 index 00000000..3c0a431b --- /dev/null +++ b/v3/examples/redis-outbound/main.go @@ -0,0 +1,155 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "reflect" + "sort" + "strconv" + + spin_http "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/redis" +) + +func init() { + + // handler for the http trigger + spin_http.Handle(func(w http.ResponseWriter, _ *http.Request) { + + // addr is the environment variable set in `spin.toml` that points to the + // address of the Redis server. + addr := os.Getenv("REDIS_ADDRESS") + + // channel is the environment variable set in `spin.toml` that specifies + // the Redis channel that the component will publish to. + channel := os.Getenv("REDIS_CHANNEL") + + // payload is the data publish to the redis channel. + payload := []byte(`Hello redis from tinygo!`) + + rdb, err := redis.NewClient(addr) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if err := rdb.Publish(channel, payload); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // set redis `mykey` = `myvalue` + if err := rdb.Set("mykey", []byte("myvalue")); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // get redis payload for `mykey` + if payload, err := rdb.Get("mykey"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } else { + w.Write([]byte("mykey value was: ")) + w.Write(payload) + w.Write([]byte("\n")) + } + + // incr `spin-go-incr` by 1 + if payload, err := rdb.Incr("spin-go-incr"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } else { + w.Write([]byte("spin-go-incr value: ")) + w.Write([]byte(strconv.FormatInt(payload, 10))) + w.Write([]byte("\n")) + } + + // delete `spin-go-incr` and `mykey` + if payload, err := rdb.Del("spin-go-incr", "mykey", "non-existing-key"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } else { + w.Write([]byte("deleted keys num: ")) + w.Write([]byte(strconv.FormatInt(int64(payload), 10))) + w.Write([]byte("\n")) + } + + if _, err := rdb.Sadd("myset", "foo", "bar"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + { + expected := []string{"bar", "foo"} + payload, err := rdb.Smembers("myset") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + sort.Strings(payload) + if !reflect.DeepEqual(payload, expected) { + http.Error( + w, + fmt.Sprintf( + "unexpected SMEMBERS result: expected %v, got %v", + expected, + payload, + ), + http.StatusInternalServerError, + ) + return + } + } + + if _, err := rdb.Srem("myset", "bar"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + { + expected := []string{"foo"} + if payload, err := rdb.Smembers("myset"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } else if !reflect.DeepEqual(payload, expected) { + http.Error( + w, + fmt.Sprintf( + "unexpected SMEMBERS result: expected %v, got %v", + expected, + payload, + ), + http.StatusInternalServerError, + ) + return + } + } + + if _, err := rdb.Execute("set", "message", "hello"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if _, err := rdb.Execute("append", "message", " world"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if payload, err := rdb.Execute("get", "message"); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } else if !reflect.DeepEqual( + payload, + []*redis.Result{{ + Kind: redis.ResultKindBinary, + Val: []byte("hello world"), + }}) { + + http.Error(w, "unexpected GET result", http.StatusInternalServerError) + fmt.Println() + return + } + }) +} + +func main() {} diff --git a/v3/examples/redis-outbound/spin.toml b/v3/examples/redis-outbound/spin.toml new file mode 100644 index 00000000..9f34b373 --- /dev/null +++ b/v3/examples/redis-outbound/spin.toml @@ -0,0 +1,20 @@ +spin_manifest_version = 2 + +[application] +name = "go-redis-outbound-example" +version = "0.1.0" +authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] +description = "Using Spin with Redis" + +[[trigger.http]] +route = "/" +component = "redis-outbound" + +[component.redis-outbound] +source = "main.wasm" +environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messages" } +allowed_outbound_hosts = ["redis://localhost:6379"] + +[component.redis-outbound.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] diff --git a/v3/redis/redis.go b/v3/redis/redis.go new file mode 100644 index 00000000..0d6ce01f --- /dev/null +++ b/v3/redis/redis.go @@ -0,0 +1,232 @@ +// Package redis provides the handler function for the Redis trigger, as well +// as access to Redis within Spin components. + +package redis + +import ( + "errors" + "fmt" + + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/redis" + "go.bytecodealliance.org/cm" +) + +// Client is a Redis client. +type Client struct { + conn redis.Connection +} + +// NewClient returns a Redis client. +func NewClient(address string) (Client, error) { + conn, err, isErr := redis.ConnectionOpen(address).Result() + if isErr { + return Client{}, toError(err) + } + + return Client{conn: conn}, nil +} + +// Publish a Redis message to the specified channel. +func (c *Client) Publish(channel string, payload []byte) error { + _, err, isErr := c.conn.Publish(channel, redis.Payload(cm.ToList(payload))).Result() + if isErr { + return toError(err) + } + + return nil +} + +// Get the value of a key. +func (c *Client) Get(key string) ([]byte, error) { + payload, err, isErr := c.conn.Get(key).Result() + if isErr { + return nil, toError(err) + } + + if payload.None() { + return nil, nil + } + + return payload.Some().Slice(), nil +} + +// Set key to value. +// +// If key already holds a value, it is overwritten. +func (c *Client) Set(key string, payload []byte) error { + _, err, isErr := c.conn.Set(key, redis.Payload(cm.ToList(payload))).Result() + if isErr { + return toError(err) + } + + return nil +} + +// 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. +func (c *Client) Incr(key string) (int64, error) { + incrementedNum, err, isErr := c.conn.Incr(key).Result() + if isErr { + return 0, toError(err) + } + + return incrementedNum, nil +} + +// Removes the specified keys. +// +// A key is ignored if it does not exist. Returns the number of keys deleted. +func (c *Client) Del(keys ...string) (uint32, error) { + numKeysDeleted, err, isErr := c.conn.Del(cm.ToList(keys)).Result() + if isErr { + return 0, toError(err) + } + + return numKeysDeleted, nil +} + +// Add the specified `values` to the set named `key`, returning the number of newly-added values. +func (c *Client) Sadd(key string, values ...string) (uint32, error) { + numValuesAdded, err, isErr := c.conn.Sadd(key, cm.ToList(values)).Result() + if isErr { + return 0, toError(err) + } + + return numValuesAdded, nil +} + +// Retrieve the contents of the set named `key`. +func (c *Client) Smembers(key string) ([]string, error) { + setValues, err, isErr := c.conn.Smembers(key).Result() + if isErr { + return nil, toError(err) + } + + return setValues.Slice(), nil +} + +// Remove the specified `values` from the set named `key`, returning the number of newly-removed values. +func (c *Client) Srem(key string, values ...string) (uint32, error) { + valuesRemoved, err, isErr := c.conn.Srem(key, cm.ToList(values)).Result() + if isErr { + return 0, toError(err) + } + + return valuesRemoved, nil +} + +// ResultKind represents a result type returned from executing a Redis command. +type ResultKind uint8 + +const ( + ResultKindNil ResultKind = iota + ResultKindStatus + ResultKindInt64 + ResultKindBinary +) + +// String implements fmt.Stringer. +func (r ResultKind) String() string { + switch r { + case ResultKindNil: + return "nil" + case ResultKindStatus: + return "status" + case ResultKindInt64: + return "int64" + case ResultKindBinary: + return "binary" + default: + return "unknown" + } +} + +// GoString implements fmt.GoStringer. +func (r ResultKind) GoString() string { return r.String() } + +// Result represents a value returned from a Redis command. +type Result struct { + Kind ResultKind + Val any +} + +// Execute runs the specified Redis command with the specified arguments, +// returning zero or more results. This is a general-purpose function which +// should work with any Redis command. +// +// Arguments must be string, []byte, int, int64, or int32. +func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { + var params []redis.RedisParameter + for _, a := range arguments { + p, err := createParameter(a) + if err != nil { + return nil, err + } + params = append(params, p) + } + + redisResults, err, isErr := c.conn.Execute(command, cm.ToList(params)).Result() + if isErr { + return nil, toError(err) + } + + var results []*Result + for _, r := range redisResults.Slice() { + results = append(results, toResult(r)) + } + + return results, nil +} + +func createParameter(x any) (redis.RedisParameter, error) { + switch v := x.(type) { + case int: + return redis.RedisParameterInt64(int64(v)), nil + case int64: + return redis.RedisParameterInt64(v), nil + case int32: + return redis.RedisParameterInt64(int64(v)), nil + case []byte: + return redis.RedisParameterBinary(redis.Payload(cm.ToList(v))), nil + case string: + return redis.RedisParameterBinary(redis.Payload(cm.ToList([]byte(v)))), nil + default: + return redis.RedisParameter{}, fmt.Errorf("invalid type %T; must be string, []byte, int, int64, or int32", v) + } +} + +func toResult(param redis.RedisResult) *Result { + switch { + case param.Status() != nil: + return &Result{ + Kind: ResultKindStatus, + Val: param.Status(), + } + case param.Int64() != nil: + return &Result{ + Kind: ResultKindInt64, + Val: param.Int64(), + } + case param.Binary() != nil: + return &Result{ + Kind: ResultKindBinary, + Val: param.Binary().Slice(), + } + default: + return &Result{ + Kind: ResultKindNil, + Val: param.Nil(), + } + } +} + +func toError(e redis.Error) error { + if e.String() == "other" { + return fmt.Errorf(*e.Other()) + } + + return errors.New(e.String()) +} From b616203db29e422f25c0ab50fa130be52d4f33a4 Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Wed, 27 Aug 2025 17:47:00 -0500 Subject: [PATCH 10/22] feat(mysql): implement mysql in wasip2 Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- mysql/mysql.go | 9 +- v3/examples/mysql-outbound/.gitignore | 2 + v3/examples/mysql-outbound/README.md | 30 +++ v3/examples/mysql-outbound/compose.yaml | 24 ++ v3/examples/mysql-outbound/go.mod | 12 + v3/examples/mysql-outbound/go.sum | 4 + v3/examples/mysql-outbound/init.sql | 6 + v3/examples/mysql-outbound/main.go | 58 ++++ v3/examples/mysql-outbound/spin.toml | 19 ++ v3/internal/db/driver.go | 15 ++ v3/mysql/mysql.go | 342 ++++++++++++++++++++++++ 11 files changed, 516 insertions(+), 5 deletions(-) create mode 100644 v3/examples/mysql-outbound/.gitignore create mode 100644 v3/examples/mysql-outbound/README.md create mode 100644 v3/examples/mysql-outbound/compose.yaml create mode 100644 v3/examples/mysql-outbound/go.mod create mode 100644 v3/examples/mysql-outbound/go.sum create mode 100644 v3/examples/mysql-outbound/init.sql create mode 100644 v3/examples/mysql-outbound/main.go create mode 100644 v3/examples/mysql-outbound/spin.toml create mode 100644 v3/internal/db/driver.go create mode 100644 v3/mysql/mysql.go diff --git a/mysql/mysql.go b/mysql/mysql.go index e46cab73..e6437122 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -1,3 +1,4 @@ +// Package mysql provides access to MySQL within Spin components. package mysql import ( @@ -114,9 +115,8 @@ type rows struct { columns []string columnType []uint8 pos int - len int + numRows int rows [][]any - closed bool } var _ driver.Rows = (*rows)(nil) @@ -132,8 +132,7 @@ func (r *rows) Columns() []string { func (r *rows) Close() error { r.rows = nil r.pos = 0 - r.len = 0 - r.closed = true + r.numRows = 0 return nil } @@ -152,7 +151,7 @@ func (r *rows) Next(dest []driver.Value) error { // HasNextResultSet is called at the end of the current result set and // reports whether there is another result set after the current one. func (r *rows) HasNextResultSet() bool { - return r.pos < r.len + return r.pos < r.numRows } // NextResultSet advances the driver to the next result set even diff --git a/v3/examples/mysql-outbound/.gitignore b/v3/examples/mysql-outbound/.gitignore new file mode 100644 index 00000000..b5650104 --- /dev/null +++ b/v3/examples/mysql-outbound/.gitignore @@ -0,0 +1,2 @@ +main.wasm +.spin/ diff --git a/v3/examples/mysql-outbound/README.md b/v3/examples/mysql-outbound/README.md new file mode 100644 index 00000000..75105fca --- /dev/null +++ b/v3/examples/mysql-outbound/README.md @@ -0,0 +1,30 @@ +# Requirements +- Latest version of [TinyGo](https://tinygo.org/getting-started/) +- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) + +# Usage + +In a terminal window, use the below command to run MySQL: +```sh +docker compose up -d +``` + +Then, you'll build and run your Spin app: +```sh +spin up --build +``` + +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000 +``` + +You should see the output: +```json +[{"ID":1,"Name":"Splodge","Prey":null,"IsFinicky":false},{"ID":2,"Name":"Kiki","Prey":"Cicadas","IsFinicky":false},{"ID":3,"Name":"Slats","Prey":"Temptations","IsFinicky":true},{"ID":4,"Name":"Maya","Prey":"bananas","IsFinicky":true},{"ID":5,"Name":"Copper","Prey":"Foxes","IsFinicky":false}] +``` + +To stop and clean up the MySQL container, run the following: +```sh +docker compose down -v +``` \ No newline at end of file diff --git a/v3/examples/mysql-outbound/compose.yaml b/v3/examples/mysql-outbound/compose.yaml new file mode 100644 index 00000000..6d9c4430 --- /dev/null +++ b/v3/examples/mysql-outbound/compose.yaml @@ -0,0 +1,24 @@ +services: + mysql: + image: mysql:8 + container_name: mysql + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: spin_data + MYSQL_USER: spin + MYSQL_PASSWORD: spin + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql + - ./init.sql:/docker-entrypoint-initdb.d/init.sql + networks: + - mysql_network + +volumes: + mysql_data: + +networks: + mysql_network: + driver: bridge \ No newline at end of file diff --git a/v3/examples/mysql-outbound/go.mod b/v3/examples/mysql-outbound/go.mod new file mode 100644 index 00000000..3e780ed8 --- /dev/null +++ b/v3/examples/mysql-outbound/go.mod @@ -0,0 +1,12 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/mysql-outbound + +go 1.24 + +require github.com/spinframework/spin-go-sdk/v3 v3.0.0 + +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/cm v0.2.2 // indirect +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v3/examples/mysql-outbound/go.sum b/v3/examples/mysql-outbound/go.sum new file mode 100644 index 00000000..c1ebfdf4 --- /dev/null +++ b/v3/examples/mysql-outbound/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= +go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= +go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/mysql-outbound/init.sql b/v3/examples/mysql-outbound/init.sql new file mode 100644 index 00000000..c2d5384a --- /dev/null +++ b/v3/examples/mysql-outbound/init.sql @@ -0,0 +1,6 @@ +CREATE DATABASE IF NOT EXISTS spin_data; +USE spin_data; +CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); +INSERT INTO pets VALUES (1, 'Splodge', NULL, false); +INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); +INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/v3/examples/mysql-outbound/main.go b/v3/examples/mysql-outbound/main.go new file mode 100644 index 00000000..f20e9091 --- /dev/null +++ b/v3/examples/mysql-outbound/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "os" + + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/mysql" +) + +type Pet struct { + ID int64 + Name string + Prey *string // nullable field must be a pointer + IsFinicky bool +} + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + + // addr is the environment variable set in `spin.toml` that points to the + // address of the Mysql server. + addr := os.Getenv("DB_URL") + + db := mysql.Open(addr) + defer db.Close() + + if _, err := db.Query("REPLACE INTO pets VALUES (?, 'Maya', ?, ?);", 4, "bananas", true); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if _, err := db.Exec("INSERT INTO pets VALUES (?, ?, ?, ?)", 5, "Copper", "Foxes", false); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + rows, err := db.Query("SELECT * FROM pets") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + var pets []*Pet + for rows.Next() { + var pet Pet + if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { + fmt.Println(err) + } + pets = append(pets, &pet) + } + json.NewEncoder(w).Encode(pets) + }) +} + +func main() {} diff --git a/v3/examples/mysql-outbound/spin.toml b/v3/examples/mysql-outbound/spin.toml new file mode 100644 index 00000000..433b1a08 --- /dev/null +++ b/v3/examples/mysql-outbound/spin.toml @@ -0,0 +1,19 @@ +spin_manifest_version = 2 + +[application] +name = "go-mysql-outbound-example" +version = "0.1.0" +authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] +description = "Using Spin with MySQL" + +[[trigger.http]] +route = "/..." +component = "mysql" + +[component.mysql] +environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } +source = "main.wasm" +allowed_outbound_hosts = ["mysql://127.0.0.1"] +[component.mysql.build] +command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +watch = ["**/*.go", "go.mod"] diff --git a/v3/internal/db/driver.go b/v3/internal/db/driver.go new file mode 100644 index 00000000..e1c99051 --- /dev/null +++ b/v3/internal/db/driver.go @@ -0,0 +1,15 @@ +package db + +import "database/sql/driver" + +// GlobalParameterConverter is a global valueConverter instance to convert parameters. +var GlobalParameterConverter = &valueConverter{} + +var _ driver.ValueConverter = (*valueConverter)(nil) + +// valueConverter is a no-op value converter. +type valueConverter struct{} + +func (c *valueConverter) ConvertValue(v any) (driver.Value, error) { + return driver.Value(v), nil +} diff --git a/v3/mysql/mysql.go b/v3/mysql/mysql.go new file mode 100644 index 00000000..6d1729df --- /dev/null +++ b/v3/mysql/mysql.go @@ -0,0 +1,342 @@ +package mysql + +import ( + "context" + "database/sql" + "database/sql/driver" + "errors" + "io" + "reflect" + + spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/mysql" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" + "go.bytecodealliance.org/cm" +) + +// Open returns a new connection to the database. +func Open(name string) *sql.DB { + return sql.OpenDB(&connector{name: name}) +} + +type conn struct { + spinConn mysql.Connection +} + +func (c *conn) Close() error { + return nil +} + +func (c *conn) Prepare(query string) (driver.Stmt, error) { + return &stmt{conn: c, query: query}, nil +} + +func (c *conn) Begin() (driver.Tx, error) { + return nil, errors.New("transactions are unsupported by this driver") +} + +type connector struct { + conn *conn + name string +} + +func (d *connector) Connect(_ context.Context) (driver.Conn, error) { + if d.conn != nil { + return d.conn, nil + } + return d.Open(d.name) +} + +func (d *connector) Driver() driver.Driver { + return d +} + +func (d *connector) Open(name string) (driver.Conn, error) { + results := mysql.ConnectionOpen(name) + if results.IsErr() { + return nil, toError(results.Err()) + } + d.conn = &conn{spinConn: *results.OK()} + return d.conn, nil +} + +func (d *connector) Close() error { + if d.conn != nil { + d.conn.Close() + } + return nil +} + +type rows struct { + columns []string + columnType []uint8 + pos int + len int + rows [][]any + closed bool +} + +var _ driver.Rows = (*rows)(nil) +var _ driver.RowsColumnTypeScanType = (*rows)(nil) +var _ driver.RowsNextResultSet = (*rows)(nil) + +// Columns return column names. +func (r *rows) Columns() []string { + return r.columns +} + +// Close closes the rows iterator. +func (r *rows) Close() error { + r.rows = nil + r.pos = 0 + r.len = 0 + r.closed = true + return nil +} + +// Next moves the cursor to the next row. +func (r *rows) Next(dest []driver.Value) error { + if !r.HasNextResultSet() { + return io.EOF + } + for i := 0; i != len(r.columns); i++ { + dest[i] = driver.Value(r.rows[r.pos][i]) + } + r.pos++ + return nil +} + +// HasNextResultSet is called at the end of the current result set and +// reports whether there is another result set after the current one. +func (r *rows) HasNextResultSet() bool { + return r.pos < r.len +} + +// NextResultSet advances the driver to the next result set even +// if there are remaining rows in the current result set. +// +// NextResultSet should return io.EOF when there are no more result sets. +func (r *rows) NextResultSet() error { + if r.HasNextResultSet() { + r.pos++ + return nil + } + return io.EOF // Per interface spec. +} + +// ColumnTypeScanType return the value type that can be used to scan types into. +func (r *rows) ColumnTypeScanType(index int) reflect.Type { + return colTypeToReflectType(r.columnType[index]) +} + +type stmt struct { + conn *conn + query string +} + +var _ driver.Stmt = (*stmt)(nil) +var _ driver.ColumnConverter = (*stmt)(nil) + +// Close closes the statement. +func (s *stmt) Close() error { + return nil +} + +// NumInput returns the number of placeholder parameters. +func (s *stmt) NumInput() int { + // Golang sql won't sanity check argument counts before Query. + return -1 +} + +// Exec executes a query that doesn't return rows, such as an INSERT or +// UPDATE. +func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { + wasiParams := make([]mysql.ParameterValue, len(args)) + for i, v := range args { + wasiParams[i] = toWasiParameterValue(v) + } + + _, err, isErr := s.conn.spinConn.Execute(s.query, cm.ToList(wasiParams)).Result() + if isErr { + return &result{}, toError(&err) + } + + return &result{}, nil +} + +// Query executes a query that may return rows, such as a SELECT. +func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { + wasiParams := make([]mysql.ParameterValue, len(args)) + for i, v := range args { + wasiParams[i] = toWasiParameterValue(v) + } + + results, err, isErr := s.conn.spinConn.Query(s.query, cm.ToList(wasiParams)).Result() + if isErr { + return nil, toError(&err) + } + + rowLen := results.Rows.Len() + allRows := make([][]any, rowLen) + for rowNum, row := range results.Rows.Slice() { + allRows[rowNum] = toRow(row.Slice()) + } + + cols := results.Columns.Slice() + colNames := make([]string, len(cols)) + colTypes := make([]uint8, len(cols)) + for i, c := range cols { + colNames[i] = c.Name + colTypes[i] = uint8(c.DataType) + } + + rows := &rows{ + columns: colNames, + columnType: colTypes, + rows: allRows, + len: int(rowLen), + } + return rows, nil +} + +func toWasiParameterValue(x any) mysql.ParameterValue { + switch v := x.(type) { + case bool: + return rdbmstypes.ParameterValueBoolean(v) + case int8: + return rdbmstypes.ParameterValueInt8(v) + case int16: + return rdbmstypes.ParameterValueInt16(v) + case int32: + return rdbmstypes.ParameterValueInt32(v) + case int64: + return rdbmstypes.ParameterValueInt64(v) + case int: + return rdbmstypes.ParameterValueInt64(int64(v)) + case uint8: + return rdbmstypes.ParameterValueUint8(v) + case uint16: + return rdbmstypes.ParameterValueUint16(v) + case uint32: + return rdbmstypes.ParameterValueUint32(v) + case uint64: + return rdbmstypes.ParameterValueUint64(v) + case float32: + return rdbmstypes.ParameterValueFloating32(v) + case float64: + return rdbmstypes.ParameterValueFloating64(v) + case string: + return rdbmstypes.ParameterValueStr(v) + case []byte: + return rdbmstypes.ParameterValueBinary(cm.ToList([]uint8(v))) + case nil: + return rdbmstypes.ParameterValueDbNull() + default: + panic("unknown value type") + } +} + +func toError(err *mysql.Error) error { + if err == nil { + return nil + } + + switch err.String() { + case "bad-parameter": + return errors.New(*err.BadParameter()) + case "connection-failed": + return errors.New(*err.ConnectionFailed()) + case "query-failed": + return errors.New(*err.QueryFailed()) + case "value-conversion-failed": + return errors.New(*err.ValueConversionFailed()) + default: + // TODO: not sure if using "Other" as the default is appropriate + return errors.New(*err.Other()) + } +} + +func toRow(row []rdbmstypes.DbValue) []any { + result := make([]any, len(row)) + for i, v := range row { + switch v.String() { + case "boolean": + result[i] = *v.Boolean() + case "int8": + result[i] = *v.Int8() + case "int16": + result[i] = *v.Int16() + case "int32": + result[i] = *v.Int32() + case "int64": + result[i] = *v.Int64() + case "uint8": + result[i] = *v.Uint8() + case "uint16": + result[i] = *v.Uint16() + case "uint32": + result[i] = *v.Uint32() + case "uint64": + result[i] = *v.Uint64() + case "floating32": + result[i] = *v.Floating32() + case "floating64": + result[i] = *v.Floating64() + case "str": + result[i] = *v.Str() + case "binary": + result[i] = *v.Binary() + case "db-null": + result[i] = nil + default: + panic("unknown value type") + } + } + + return result +} + +// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. +func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { + return spindb.GlobalParameterConverter +} + +type result struct{} + +func (r result) LastInsertId() (int64, error) { + return -1, errors.New("LastInsertId is unsupported by this driver") +} + +func (r result) RowsAffected() (int64, error) { + return -1, errors.New("RowsAffected is unsupported by this driver") +} + +func colTypeToReflectType(typ uint8) reflect.Type { + switch typ { + case uint8(rdbmstypes.DbDataTypeBoolean): + return reflect.TypeOf(false) + case uint8(rdbmstypes.DbDataTypeInt8): + return reflect.TypeOf(int8(0)) + case uint8(rdbmstypes.DbDataTypeInt16): + return reflect.TypeOf(int16(0)) + case uint8(rdbmstypes.DbDataTypeInt32): + return reflect.TypeOf(int32(0)) + case uint8(rdbmstypes.DbDataTypeInt64): + return reflect.TypeOf(int64(0)) + case uint8(rdbmstypes.DbDataTypeUint8): + return reflect.TypeOf(uint8(0)) + case uint8(rdbmstypes.DbDataTypeUint16): + return reflect.TypeOf(uint16(0)) + case uint8(rdbmstypes.DbDataTypeUint32): + return reflect.TypeOf(uint32(0)) + case uint8(rdbmstypes.DbDataTypeUint64): + return reflect.TypeOf(uint64(0)) + case uint8(rdbmstypes.DbDataTypeStr): + return reflect.TypeOf("") + case uint8(rdbmstypes.DbDataTypeBinary): + return reflect.TypeOf(new([]byte)) + case uint8(rdbmstypes.DbDataTypeOther): + return reflect.TypeOf(new(any)).Elem() + } + panic("invalid db column type of " + string(typ)) +} From f407c8f7fda23cb2d9d4c7c1221b59170e041aac Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Tue, 20 Jan 2026 17:36:02 -0600 Subject: [PATCH 11/22] feat(wasip2): regenerate bindings with componentize-go Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- .github/workflows/pr.yaml | 25 +- .gitignore | 2 +- v3/README.md | 53 +- v3/examples/http/README.md | 15 + v3/examples/http/go.mod | 6 +- v3/examples/http/go.sum | 4 +- v3/examples/http/spin.toml | 5 +- v3/examples/kv/README.md | 20 + v3/examples/kv/go.mod | 6 +- v3/examples/kv/go.sum | 4 +- v3/examples/kv/spin.toml | 5 +- v3/examples/llm/go.mod | 6 +- v3/examples/llm/go.sum | 4 +- v3/examples/llm/spin.toml | 2 +- v3/examples/mqtt-outbound/README.md | 7 +- v3/examples/mqtt-outbound/go.mod | 6 +- v3/examples/mqtt-outbound/go.sum | 4 +- v3/examples/mqtt-outbound/spin.toml | 2 +- v3/examples/mysql-outbound/README.md | 9 +- v3/examples/mysql-outbound/go.mod | 6 +- v3/examples/mysql-outbound/go.sum | 4 +- v3/examples/mysql-outbound/spin.toml | 2 +- v3/examples/redis-outbound/README.md | 16 +- v3/examples/redis-outbound/go.mod | 6 +- v3/examples/redis-outbound/go.sum | 4 +- v3/examples/redis-outbound/spin.toml | 2 +- v3/examples/variables/README.md | 20 + v3/examples/variables/go.mod | 6 +- v3/examples/variables/go.sum | 4 +- v3/examples/variables/spin.toml | 7 +- v3/go.mod | 6 +- v3/go.sum | 4 +- v3/http/client.go | 32 +- v3/http/convertor_incoming_request.go | 56 +- v3/http/convertor_outgoing_request.go | 49 +- v3/http/convertor_outgoing_response.go | 31 +- v3/http/http.go | 11 +- v3/http/streams.go | 10 +- v3/http/testdata/http-tinygo/go.sum | 4 - v3/http/testdata/http-tinygo/spin.toml | 17 - v3/http/testdata/{http-tinygo => http}/go.mod | 6 +- v3/http/testdata/http/go.sum | 4 + .../testdata/{http-tinygo => http}/main.go | 0 v3/http/testdata/http/spin.toml | 17 + v3/integration_test.go | 5 +- .../wit_bindings.go | 13 + v3/internal/fermyon/spin/config/abi.go | 14 - .../fermyon/spin/config/config.wasm.go | 13 - v3/internal/fermyon/spin/config/config.wit.go | 84 - v3/internal/fermyon/spin/config/empty.s | 3 - .../spin/http-trigger/http-trigger.wit.go | 4 - .../fermyon/spin/http-types/http-types.wit.go | 164 - v3/internal/fermyon/spin/http/abi.go | 35 - v3/internal/fermyon/spin/http/empty.s | 3 - v3/internal/fermyon/spin/http/http.wasm.go | 13 - v3/internal/fermyon/spin/http/http.wit.go | 35 - v3/internal/fermyon/spin/inbound-http/abi.go | 24 - v3/internal/fermyon/spin/inbound-http/empty.s | 3 - .../spin/inbound-http/inbound-http.exports.go | 11 - .../spin/inbound-http/inbound-http.wasm.go | 14 - .../spin/inbound-http/inbound-http.wit.go | 18 - v3/internal/fermyon/spin/key-value/abi.go | 14 - v3/internal/fermyon/spin/key-value/empty.s | 3 - .../fermyon/spin/key-value/key-value.wasm.go | 37 - .../fermyon/spin/key-value/key-value.wit.go | 250 - v3/internal/fermyon/spin/llm/abi.go | 45 - v3/internal/fermyon/spin/llm/empty.s | 3 - v3/internal/fermyon/spin/llm/llm.wasm.go | 17 - v3/internal/fermyon/spin/llm/llm.wit.go | 209 - v3/internal/fermyon/spin/mysql/abi.go | 14 - v3/internal/fermyon/spin/mysql/empty.s | 3 - v3/internal/fermyon/spin/mysql/mysql.wasm.go | 17 - v3/internal/fermyon/spin/mysql/mysql.wit.go | 140 - v3/internal/fermyon/spin/postgres/abi.go | 20 - v3/internal/fermyon/spin/postgres/empty.s | 3 - .../fermyon/spin/postgres/postgres.wasm.go | 17 - .../fermyon/spin/postgres/postgres.wit.go | 140 - .../spin/rdbms-types/rdbms-types.wit.go | 488 -- .../spin/redis-types/redis-types.wit.go | 158 - v3/internal/fermyon/spin/redis/empty.s | 3 - v3/internal/fermyon/spin/redis/redis.wasm.go | 45 - v3/internal/fermyon/spin/redis/redis.wit.go | 167 - v3/internal/fermyon/spin/sqlite/abi.go | 20 - v3/internal/fermyon/spin/sqlite/empty.s | 3 - .../fermyon/spin/sqlite/sqlite.wasm.go | 21 - v3/internal/fermyon/spin/sqlite/sqlite.wit.go | 256 - .../v2.0.0/http-trigger/http-trigger.wit.go | 6 - .../fermyon/spin/v2.0.0/key-value/abi.go | 20 - .../fermyon/spin/v2.0.0/key-value/empty.s | 3 - .../spin/v2.0.0/key-value/key-value.wasm.go | 37 - .../spin/v2.0.0/key-value/key-value.wit.go | 194 - v3/internal/fermyon/spin/v2.0.0/llm/abi.go | 45 - v3/internal/fermyon/spin/v2.0.0/llm/empty.s | 3 - .../fermyon/spin/v2.0.0/llm/llm.wasm.go | 17 - .../fermyon/spin/v2.0.0/llm/llm.wit.go | 209 - v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go | 14 - v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s | 3 - .../fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go | 21 - .../fermyon/spin/v2.0.0/mqtt/mqtt.wit.go | 179 - v3/internal/fermyon/spin/v2.0.0/mysql/abi.go | 20 - v3/internal/fermyon/spin/v2.0.0/mysql/empty.s | 3 - .../fermyon/spin/v2.0.0/mysql/mysql.wasm.go | 25 - .../fermyon/spin/v2.0.0/mysql/mysql.wit.go | 86 - .../fermyon/spin/v2.0.0/postgres/abi.go | 20 - .../fermyon/spin/v2.0.0/postgres/empty.s | 3 - .../spin/v2.0.0/postgres/postgres.wasm.go | 25 - .../spin/v2.0.0/postgres/postgres.wit.go | 87 - .../v2.0.0/rdbms-types/rdbms-types.wit.go | 576 -- v3/internal/fermyon/spin/v2.0.0/redis/abi.go | 20 - v3/internal/fermyon/spin/v2.0.0/redis/empty.s | 3 - .../fermyon/spin/v2.0.0/redis/redis.wasm.go | 53 - .../fermyon/spin/v2.0.0/redis/redis.wit.go | 366 -- v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go | 20 - .../fermyon/spin/v2.0.0/sqlite/empty.s | 3 - .../fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go | 21 - .../fermyon/spin/v2.0.0/sqlite/sqlite.wit.go | 256 - .../fermyon/spin/v2.0.0/variables/abi.go | 14 - .../fermyon/spin/v2.0.0/variables/empty.s | 3 - .../spin/v2.0.0/variables/variables.wasm.go | 13 - .../spin/v2.0.0/variables/variables.wit.go | 95 - .../v3.0.0/http-trigger/http-trigger.wit.go | 6 - .../wit_bindings.go | 438 ++ .../fermyon_spin_2_0_0_llm/wit_bindings.go | 277 + .../fermyon_spin_2_0_0_mqtt/wit_bindings.go | 246 + .../fermyon_spin_2_0_0_mysql/wit_bindings.go | 533 ++ .../wit_bindings.go | 533 ++ .../wit_bindings.go | 436 ++ .../fermyon_spin_2_0_0_redis/wit_bindings.go | 811 +++ .../fermyon_spin_2_0_0_sqlite/wit_bindings.go | 396 ++ .../wit_bindings.go | 151 + .../spin/postgres/v3.0.0/postgres/abi.go | 26 - .../spin/postgres/v3.0.0/postgres/empty.s | 3 - .../postgres/v3.0.0/postgres/postgres.wasm.go | 25 - .../postgres/v3.0.0/postgres/postgres.wit.go | 657 --- .../spin_postgres_postgres/wit_bindings.go | 962 ++++ .../wasi/cli/v0.2.0/environment/empty.s | 3 - .../v0.2.0/environment/environment.wasm.go | 21 - .../cli/v0.2.0/environment/environment.wit.go | 52 - v3/internal/wasi/cli/v0.2.0/exit/empty.s | 3 - v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go | 9 - v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 21 - v3/internal/wasi/cli/v0.2.0/stderr/empty.s | 3 - .../wasi/cli/v0.2.0/stderr/stderr.wasm.go | 9 - .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 25 - v3/internal/wasi/cli/v0.2.0/stdin/empty.s | 3 - .../wasi/cli/v0.2.0/stdin/stdin.wasm.go | 9 - .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 25 - v3/internal/wasi/cli/v0.2.0/stdout/empty.s | 3 - .../wasi/cli/v0.2.0/stdout/stdout.wasm.go | 9 - .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 25 - .../wasi/cli/v0.2.0/terminal-input/empty.s | 3 - .../terminal-input/terminal-input.wasm.go | 9 - .../terminal-input/terminal-input.wit.go | 32 - .../wasi/cli/v0.2.0/terminal-output/empty.s | 3 - .../terminal-output/terminal-output.wasm.go | 9 - .../terminal-output/terminal-output.wit.go | 32 - .../wasi/cli/v0.2.0/terminal-stderr/empty.s | 3 - .../terminal-stderr/terminal-stderr.wasm.go | 13 - .../terminal-stderr/terminal-stderr.wit.go | 30 - .../wasi/cli/v0.2.0/terminal-stdin/empty.s | 3 - .../terminal-stdin/terminal-stdin.wasm.go | 13 - .../terminal-stdin/terminal-stdin.wit.go | 30 - .../wasi/cli/v0.2.0/terminal-stdout/empty.s | 3 - .../terminal-stdout/terminal-stdout.wasm.go | 13 - .../terminal-stdout/terminal-stdout.wit.go | 30 - .../clocks/v0.2.0/monotonic-clock/empty.s | 3 - .../monotonic-clock/monotonic-clock.wasm.go | 21 - .../monotonic-clock/monotonic-clock.wit.go | 102 - .../wasi/clocks/v0.2.0/wall-clock/empty.s | 3 - .../v0.2.0/wall-clock/wall-clock.wasm.go | 13 - .../v0.2.0/wall-clock/wall-clock.wit.go | 75 - .../v0.2.0-draft-2024-09-27/store/abi.go | 20 - .../v0.2.0-draft-2024-09-27/store/empty.s | 3 - .../store/store.wasm.go | 17 - .../store/store.wit.go | 92 - .../wasi/filesystem/v0.2.0/preopens/empty.s | 3 - .../v0.2.0/preopens/preopens.wasm.go | 13 - .../v0.2.0/preopens/preopens.wit.go | 26 - .../wasi/filesystem/v0.2.0/types/abi.go | 50 - .../wasi/filesystem/v0.2.0/types/empty.s | 3 - .../filesystem/v0.2.0/types/types.wasm.go | 133 - .../wasi/filesystem/v0.2.0/types/types.wit.go | 1305 ----- .../wasi/http/v0.2.0/incoming-handler/empty.s | 3 - .../incoming-handler.exports.go | 22 - .../incoming-handler/incoming-handler.wasm.go | 18 - .../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.wasm.go | 13 - .../outgoing-handler/outgoing-handler.wit.go | 56 - v3/internal/wasi/http/v0.2.0/types/abi.go | 264 - v3/internal/wasi/http/v0.2.0/types/empty.s | 3 - .../wasi/http/v0.2.0/types/types.wasm.go | 257 - .../wasi/http/v0.2.0/types/types.wit.go | 2020 ------- v3/internal/wasi/io/v0.2.0/error/empty.s | 3 - .../wasi/io/v0.2.0/error/error.wasm.go | 13 - v3/internal/wasi/io/v0.2.0/error/error.wit.go | 63 - v3/internal/wasi/io/v0.2.0/poll/empty.s | 3 - v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go | 25 - v3/internal/wasi/io/v0.2.0/poll/poll.wit.go | 92 - v3/internal/wasi/io/v0.2.0/streams/empty.s | 3 - .../wasi/io/v0.2.0/streams/streams.wasm.go | 77 - .../wasi/io/v0.2.0/streams/streams.wit.go | 471 -- .../keyvalue/v0.2.0-draft2/atomics/abi.go | 20 - .../v0.2.0-draft2/atomics/atomics.wasm.go | 29 - .../v0.2.0-draft2/atomics/atomics.wit.go | 171 - .../keyvalue/v0.2.0-draft2/atomics/empty.s | 3 - .../wasi/keyvalue/v0.2.0-draft2/batch/abi.go | 14 - .../v0.2.0-draft2/batch/batch.wasm.go | 21 - .../keyvalue/v0.2.0-draft2/batch/batch.wit.go | 134 - .../wasi/keyvalue/v0.2.0-draft2/batch/empty.s | 3 - .../wasi/keyvalue/v0.2.0-draft2/store/abi.go | 37 - .../wasi/keyvalue/v0.2.0-draft2/store/empty.s | 3 - .../v0.2.0-draft2/store/store.wasm.go | 37 - .../keyvalue/v0.2.0-draft2/store/store.wit.go | 294 - .../wasi/random/v0.2.0/insecure-seed/empty.s | 3 - .../insecure-seed/insecure-seed.wasm.go | 9 - .../v0.2.0/insecure-seed/insecure-seed.wit.go | 37 - .../wasi/random/v0.2.0/insecure/empty.s | 3 - .../random/v0.2.0/insecure/insecure.wasm.go | 17 - .../random/v0.2.0/insecure/insecure.wit.go | 49 - v3/internal/wasi/random/v0.2.0/random/empty.s | 3 - .../wasi/random/v0.2.0/random/random.wasm.go | 17 - .../wasi/random/v0.2.0/random/random.wit.go | 53 - .../sockets/v0.2.0/instance-network/empty.s | 3 - .../instance-network/instance-network.wasm.go | 9 - .../instance-network/instance-network.wit.go | 29 - .../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.wasm.go | 25 - .../ip-name-lookup/ip-name-lookup.wit.go | 125 - .../wasi/sockets/v0.2.0/network/abi.go | 14 - .../wasi/sockets/v0.2.0/network/empty.s | 3 - .../sockets/v0.2.0/network/network.wasm.go | 9 - .../sockets/v0.2.0/network/network.wit.go | 359 -- .../sockets/v0.2.0/tcp-create-socket/empty.s | 3 - .../tcp-create-socket.wasm.go | 13 - .../tcp-create-socket.wit.go | 68 - v3/internal/wasi/sockets/v0.2.0/tcp/abi.go | 88 - v3/internal/wasi/sockets/v0.2.0/tcp/empty.s | 3 - .../wasi/sockets/v0.2.0/tcp/tcp.wasm.go | 125 - .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 785 --- .../sockets/v0.2.0/udp-create-socket/empty.s | 3 - .../udp-create-socket.wasm.go | 13 - .../udp-create-socket.wit.go | 68 - v3/internal/wasi/sockets/v0.2.0/udp/abi.go | 103 - v3/internal/wasi/sockets/v0.2.0/udp/empty.s | 3 - .../wasi/sockets/v0.2.0/udp/udp.wasm.go | 93 - .../wasi/sockets/v0.2.0/udp/udp.wit.go | 584 -- .../wit_bindings.go | 110 + .../wasi_cli_0_2_0_exit/wit_bindings.go | 56 + .../wasi_cli_0_2_0_stderr/wit_bindings.go | 48 + .../wasi_cli_0_2_0_stdin/wit_bindings.go | 48 + .../wasi_cli_0_2_0_stdout/wit_bindings.go | 48 + .../wit_bindings.go | 80 + .../wit_bindings.go | 80 + .../wit_bindings.go | 67 + .../wit_bindings.go | 67 + .../wit_bindings.go | 67 + .../wit_bindings.go | 86 + .../wit_bindings.go | 72 + v3/internal/wasi_config_store/wit_bindings.go | 185 + .../wit_bindings.go | 64 + .../wit_bindings.go | 1347 +++++ .../wit_bindings.go | 39 + .../wit_bindings.go | 497 ++ .../wasi_http_0_2_0_types/wit_bindings.go | 4986 +++++++++++++++++ .../wasi_io_0_2_0_error/wit_bindings.go | 114 + .../wasi_io_0_2_0_poll/wit_bindings.go | 124 + .../wasi_io_0_2_0_streams/wit_bindings.go | 699 +++ .../wasi_keyvalue_atomics/wit_bindings.go | 328 ++ .../wasi_keyvalue_batch/wit_bindings.go | 231 + .../wasi_keyvalue_store/wit_bindings.go | 464 ++ .../wit_bindings.go | 63 + .../wit_bindings.go | 54 + .../wasi_random_0_2_0_random/wit_bindings.go | 63 + .../wit_bindings.go | 48 + .../wit_bindings.go | 174 + .../wit_bindings.go | 256 + .../wasi_sockets_0_2_0_tcp/wit_bindings.go | 908 +++ .../wit_bindings.go | 71 + .../wasi_sockets_0_2_0_udp/wit_bindings.go | 835 +++ .../wit_bindings.go | 71 + v3/internal/wit_exports/wit_exports.go | 50 + v3/kv/kv.go | 43 +- v3/kv/testdata/key-value/go.mod | 6 +- v3/kv/testdata/key-value/go.sum | 4 +- v3/kv/testdata/key-value/spin.toml | 4 +- v3/llm/llm.go | 42 +- v3/mqtt/mqtt.go | 37 +- v3/mysql/mysql.go | 139 +- v3/redis/redis.go | 110 +- v3/variables/testdata/variables/go.mod | 6 +- v3/variables/testdata/variables/go.sum | 4 +- v3/variables/testdata/variables/spin.toml | 4 +- v3/variables/variables.go | 26 +- 296 files changed, 17790 insertions(+), 15440 deletions(-) create mode 100644 v3/examples/http/README.md create mode 100644 v3/examples/kv/README.md create mode 100644 v3/examples/variables/README.md delete mode 100644 v3/http/testdata/http-tinygo/go.sum delete mode 100644 v3/http/testdata/http-tinygo/spin.toml rename v3/http/testdata/{http-tinygo => http}/go.mod (53%) create mode 100644 v3/http/testdata/http/go.sum rename v3/http/testdata/{http-tinygo => http}/main.go (100%) create mode 100644 v3/http/testdata/http/spin.toml create mode 100644 v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go delete mode 100644 v3/internal/fermyon/spin/config/abi.go delete mode 100644 v3/internal/fermyon/spin/config/config.wasm.go delete mode 100644 v3/internal/fermyon/spin/config/config.wit.go delete mode 100644 v3/internal/fermyon/spin/config/empty.s delete mode 100644 v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go delete mode 100644 v3/internal/fermyon/spin/http-types/http-types.wit.go delete mode 100644 v3/internal/fermyon/spin/http/abi.go delete mode 100644 v3/internal/fermyon/spin/http/empty.s delete mode 100644 v3/internal/fermyon/spin/http/http.wasm.go delete mode 100644 v3/internal/fermyon/spin/http/http.wit.go delete mode 100644 v3/internal/fermyon/spin/inbound-http/abi.go delete mode 100644 v3/internal/fermyon/spin/inbound-http/empty.s delete mode 100644 v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go delete mode 100644 v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go delete mode 100644 v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go delete mode 100644 v3/internal/fermyon/spin/key-value/abi.go delete mode 100644 v3/internal/fermyon/spin/key-value/empty.s delete mode 100644 v3/internal/fermyon/spin/key-value/key-value.wasm.go delete mode 100644 v3/internal/fermyon/spin/key-value/key-value.wit.go delete mode 100644 v3/internal/fermyon/spin/llm/abi.go delete mode 100644 v3/internal/fermyon/spin/llm/empty.s delete mode 100644 v3/internal/fermyon/spin/llm/llm.wasm.go delete mode 100644 v3/internal/fermyon/spin/llm/llm.wit.go delete mode 100644 v3/internal/fermyon/spin/mysql/abi.go delete mode 100644 v3/internal/fermyon/spin/mysql/empty.s delete mode 100644 v3/internal/fermyon/spin/mysql/mysql.wasm.go delete mode 100644 v3/internal/fermyon/spin/mysql/mysql.wit.go delete mode 100644 v3/internal/fermyon/spin/postgres/abi.go delete mode 100644 v3/internal/fermyon/spin/postgres/empty.s delete mode 100644 v3/internal/fermyon/spin/postgres/postgres.wasm.go delete mode 100644 v3/internal/fermyon/spin/postgres/postgres.wit.go delete mode 100644 v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go delete mode 100644 v3/internal/fermyon/spin/redis-types/redis-types.wit.go delete mode 100644 v3/internal/fermyon/spin/redis/empty.s delete mode 100644 v3/internal/fermyon/spin/redis/redis.wasm.go delete mode 100644 v3/internal/fermyon/spin/redis/redis.wit.go delete mode 100644 v3/internal/fermyon/spin/sqlite/abi.go delete mode 100644 v3/internal/fermyon/spin/sqlite/empty.s delete mode 100644 v3/internal/fermyon/spin/sqlite/sqlite.wasm.go delete mode 100644 v3/internal/fermyon/spin/sqlite/sqlite.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/key-value/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/key-value/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/llm/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/llm/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mysql/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mysql/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/postgres/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/postgres/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/redis/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/redis/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/variables/abi.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/variables/empty.s delete mode 100644 v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go delete mode 100644 v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go delete mode 100644 v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go create mode 100644 v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go create mode 100644 v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go delete mode 100644 v3/internal/spin/postgres/v3.0.0/postgres/abi.go delete mode 100644 v3/internal/spin/postgres/v3.0.0/postgres/empty.s delete mode 100644 v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go delete mode 100644 v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go create mode 100644 v3/internal/spin_postgres_postgres/wit_bindings.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/environment/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/exit/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stderr/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdin/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdout/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go delete mode 100644 v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go delete mode 100644 v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s delete mode 100644 v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go delete mode 100644 v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go delete mode 100644 v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s delete mode 100644 v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go delete mode 100644 v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go delete mode 100644 v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go delete mode 100644 v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s delete mode 100644 v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go delete mode 100644 v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/types/abi.go delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/types/empty.s delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go delete mode 100644 v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go delete mode 100644 v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s delete mode 100644 v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go delete mode 100644 v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go delete mode 100644 v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go delete mode 100644 v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go delete mode 100644 v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s delete mode 100644 v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go delete mode 100644 v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go delete mode 100644 v3/internal/wasi/http/v0.2.0/types/abi.go delete mode 100644 v3/internal/wasi/http/v0.2.0/types/empty.s delete mode 100644 v3/internal/wasi/http/v0.2.0/types/types.wasm.go delete mode 100644 v3/internal/wasi/http/v0.2.0/types/types.wit.go delete mode 100644 v3/internal/wasi/io/v0.2.0/error/empty.s delete mode 100644 v3/internal/wasi/io/v0.2.0/error/error.wasm.go delete mode 100644 v3/internal/wasi/io/v0.2.0/error/error.wit.go delete mode 100644 v3/internal/wasi/io/v0.2.0/poll/empty.s delete mode 100644 v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go delete mode 100644 v3/internal/wasi/io/v0.2.0/poll/poll.wit.go delete mode 100644 v3/internal/wasi/io/v0.2.0/streams/empty.s delete mode 100644 v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go delete mode 100644 v3/internal/wasi/io/v0.2.0/streams/streams.wit.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go delete mode 100644 v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure/empty.s delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go delete mode 100644 v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go delete mode 100644 v3/internal/wasi/random/v0.2.0/random/empty.s delete mode 100644 v3/internal/wasi/random/v0.2.0/random/random.wasm.go delete mode 100644 v3/internal/wasi/random/v0.2.0/random/random.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/network/abi.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/network/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/network/network.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp/abi.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp/abi.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp/empty.s delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go delete mode 100644 v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go create mode 100644 v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go create mode 100644 v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go create mode 100644 v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go create mode 100644 v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go create mode 100644 v3/internal/wasi_config_store/wit_bindings.go create mode 100644 v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go create mode 100644 v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go create mode 100644 v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go create mode 100644 v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go create mode 100644 v3/internal/wasi_http_0_2_0_types/wit_bindings.go create mode 100644 v3/internal/wasi_io_0_2_0_error/wit_bindings.go create mode 100644 v3/internal/wasi_io_0_2_0_poll/wit_bindings.go create mode 100644 v3/internal/wasi_io_0_2_0_streams/wit_bindings.go create mode 100644 v3/internal/wasi_keyvalue_atomics/wit_bindings.go create mode 100644 v3/internal/wasi_keyvalue_batch/wit_bindings.go create mode 100644 v3/internal/wasi_keyvalue_store/wit_bindings.go create mode 100644 v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go create mode 100644 v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go create mode 100644 v3/internal/wasi_random_0_2_0_random/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go create mode 100644 v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go create mode 100644 v3/internal/wit_exports/wit_exports.go diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 0fb900a2..8e6b0809 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -10,25 +10,28 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v6 - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.24' - - - name: Setup TinyGo - uses: acifani/setup-tinygo@v2 - with: - tinygo-version: '0.37.0' + go-version: '1.25' + + - name: Setup componentize-go + run: | + curl -LO https://github.com/asteurer/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz + echo "27fc32998f023a88a6a1f44524631a705163f23ce2a02fc14987726897360027 componentize-go-linux-amd64.tar.gz" | sha256sum --check + tar -xf componentize-go-linux-amd64.tar.gz + chmod +x componentize-go + mkdir -p $HOME/.local/bin + mv componentize-go $HOME/.local/bin/componentize-go + echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Setup Spin uses: fermyon/actions/spin/setup@v1 with: - version: "v3.2.0" - - - name: Setup `wasm-tools` - uses: bytecodealliance/actions/wasm-tools/setup@v1 + version: "v3.5.1" - name: Run wasip2 integration tests run: make test-integration-wasip2 diff --git a/.gitignore b/.gitignore index 32e954b6..2c6315af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .spin -main.wasm +*.wasm */sdk-version-go.c diff --git a/v3/README.md b/v3/README.md index e19db003..e81e93c7 100644 --- a/v3/README.md +++ b/v3/README.md @@ -1,29 +1,24 @@ -WIP - -spin-go-sdk with wasip2 support - -Notes: - -The current version of tooling used for this work: - -- wit-bindgen-go `wit-bindgen-go version (devel) (0e3b31e354b31b4f2d5e7d5163e29fb2ffd0b052)` -- wasm-tools `wasm-tools 1.227.1` -- tinygo `tinygo version 0.37.0 darwin/arm64 (using go version go1.24.1 and LLVM version 19.1.2)` -- spin `spin 3.2.0-pre0 (3d07b0cb 2025-03-14)` -- go `go version go1.24.1 darwin/arm64` -- binaryen tools `binaryen-version_123` - - -Regeneratin bindings: - -- install tooling as specified above -- make sure they are on PATH and picking up the versions as specified above -- cd `/v3` -- Run: `wit-bindgen-go generate -w http-trigger -p github.com/spinframework/spin-go-sdk/v3/internal --out internal ./wit` - -Testing: - -- cd `/v3/examples/http` -- Run `spin build` -- Run `spin up` -- In a separate terminal, run: `curl http://127.0.0.1:3000/hello` +# Overview +The `wasip2` implementation of the Spinframework Go SDK. + +## Generating the WIT bindings +Whenever WIT files are changed/added to the `v3/wit` directory, the bindings in `v3/wit_component` need to be regenerated. + +### Prerequisites +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version + +### Run +```sh +cd v3 + +# Delete all non-handwritten code +find $(pwd)/internal/ \ + -mindepth 1 \ + -maxdepth 1 \ + -type d \ + ! -name 'db' \ + ! -name 'export_wasi_http_0_2_0_incoming_handler' \ + -exec rm -rf {} + + +componentize-go -w http-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal +``` diff --git a/v3/examples/http/README.md b/v3/examples/http/README.md new file mode 100644 index 00000000..ede89d35 --- /dev/null +++ b/v3/examples/http/README.md @@ -0,0 +1,15 @@ +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version + +# Usage +Build and run the Spin app: +```sh +spin up --build +``` + +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello +``` diff --git a/v3/examples/http/go.mod b/v3/examples/http/go.mod index 09edc64a..915928c9 100644 --- a/v3/examples/http/go.mod +++ b/v3/examples/http/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/http -go 1.23.2 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/http/go.sum b/v3/examples/http/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/http/go.sum +++ b/v3/examples/http/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/http/spin.toml b/v3/examples/http/spin.toml index cdf364bd..6e15433a 100644 --- a/v3/examples/http/spin.toml +++ b/v3/examples/http/spin.toml @@ -2,7 +2,7 @@ spin_manifest_version = 2 [application] authors = ["Rajat Jindal "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." name = "hello-example" version = "1.0.0" @@ -13,5 +13,4 @@ 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/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" - +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" diff --git a/v3/examples/kv/README.md b/v3/examples/kv/README.md new file mode 100644 index 00000000..5f10f34d --- /dev/null +++ b/v3/examples/kv/README.md @@ -0,0 +1,20 @@ +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version + +# Usage +Build and run the Spin app: +```sh +spin up --build +``` + +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello +``` + +You should receive the following output: +``` +["foo"] +``` diff --git a/v3/examples/kv/go.mod b/v3/examples/kv/go.mod index 50932795..13a16a52 100644 --- a/v3/examples/kv/go.mod +++ b/v3/examples/kv/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/kv -go 1.24.1 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/kv/go.sum b/v3/examples/kv/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/kv/go.sum +++ b/v3/examples/kv/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/kv/spin.toml b/v3/examples/kv/spin.toml index f0649962..7a9c0ea6 100644 --- a/v3/examples/kv/spin.toml +++ b/v3/examples/kv/spin.toml @@ -2,7 +2,7 @@ spin_manifest_version = 2 [application] authors = ["Rajat Jindal "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." name = "hello-kv" version = "1.0.0" @@ -14,5 +14,4 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" - +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" diff --git a/v3/examples/llm/go.mod b/v3/examples/llm/go.mod index 7d5787b8..c6ea1b9c 100644 --- a/v3/examples/llm/go.mod +++ b/v3/examples/llm/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/llm -go 1.24.1 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/llm/go.sum b/v3/examples/llm/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/llm/go.sum +++ b/v3/examples/llm/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/llm/spin.toml b/v3/examples/llm/spin.toml index 48395efd..5f950978 100644 --- a/v3/examples/llm/spin.toml +++ b/v3/examples/llm/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] ai_models = ["llama2-chat", "all-minilm-l6-v2"] [component.llm.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/mqtt-outbound/README.md b/v3/examples/mqtt-outbound/README.md index c3c66c6a..53b480a9 100644 --- a/v3/examples/mqtt-outbound/README.md +++ b/v3/examples/mqtt-outbound/README.md @@ -1,9 +1,10 @@ # Requirements -- Latest version of [TinyGo](https://tinygo.org/getting-started/) -- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version # Usage - In one terminal window, run: ```sh # Note that the `-d` flag is intentionally omitted diff --git a/v3/examples/mqtt-outbound/go.mod b/v3/examples/mqtt-outbound/go.mod index 1aeb9a92..a552147e 100644 --- a/v3/examples/mqtt-outbound/go.mod +++ b/v3/examples/mqtt-outbound/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/mqtt-outbound -go 1.24 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/mqtt-outbound/go.sum b/v3/examples/mqtt-outbound/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/mqtt-outbound/go.sum +++ b/v3/examples/mqtt-outbound/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/mqtt-outbound/spin.toml b/v3/examples/mqtt-outbound/spin.toml index 44d39324..608f998b 100644 --- a/v3/examples/mqtt-outbound/spin.toml +++ b/v3/examples/mqtt-outbound/spin.toml @@ -16,5 +16,5 @@ source = "main.wasm" environment = { MQTT_ADDRESS = "mqtt://127.0.0.1:1883?client_id=client001", MQTT_USERNAME = "user", MQTT_PASSWORD = "password", MQTT_KEEP_ALIVE_INTERVAL = "30", MQTT_TOPIC = "telemetry" } allowed_outbound_hosts = ["mqtt://127.0.0.1:1883"] [component.mqtt-outbound.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/mysql-outbound/README.md b/v3/examples/mysql-outbound/README.md index 75105fca..6a2fbf77 100644 --- a/v3/examples/mysql-outbound/README.md +++ b/v3/examples/mysql-outbound/README.md @@ -1,9 +1,10 @@ # Requirements -- Latest version of [TinyGo](https://tinygo.org/getting-started/) -- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version # Usage - In a terminal window, use the below command to run MySQL: ```sh docker compose up -d @@ -27,4 +28,4 @@ You should see the output: To stop and clean up the MySQL container, run the following: ```sh docker compose down -v -``` \ No newline at end of file +``` diff --git a/v3/examples/mysql-outbound/go.mod b/v3/examples/mysql-outbound/go.mod index 3e780ed8..daad4959 100644 --- a/v3/examples/mysql-outbound/go.mod +++ b/v3/examples/mysql-outbound/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/mysql-outbound -go 1.24 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/mysql-outbound/go.sum b/v3/examples/mysql-outbound/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/mysql-outbound/go.sum +++ b/v3/examples/mysql-outbound/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/mysql-outbound/spin.toml b/v3/examples/mysql-outbound/spin.toml index 433b1a08..fb3b7954 100644 --- a/v3/examples/mysql-outbound/spin.toml +++ b/v3/examples/mysql-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } source = "main.wasm" allowed_outbound_hosts = ["mysql://127.0.0.1"] [component.mysql.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/redis-outbound/README.md b/v3/examples/redis-outbound/README.md index f29a426d..fccfb075 100644 --- a/v3/examples/redis-outbound/README.md +++ b/v3/examples/redis-outbound/README.md @@ -1,9 +1,10 @@ # Requirements -- Latest version of [TinyGo](https://tinygo.org/getting-started/) -- Latest version of [Docker](https://docs.docker.com/get-started/get-docker/) +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version # Usage - In one terminal window, you'll run a Redis container: ```sh docker run -p 6379:6379 redis:8.2 @@ -17,4 +18,11 @@ spin up --build In yet another terminal, you'll interact with the Spin app: ```sh curl localhost:3000 -``` \ No newline at end of file +``` + +You should see the following output: +``` +mykey value was: myvalue +spin-go-incr value: 1 +deleted keys num: 2 +``` diff --git a/v3/examples/redis-outbound/go.mod b/v3/examples/redis-outbound/go.mod index 67543678..626def1c 100644 --- a/v3/examples/redis-outbound/go.mod +++ b/v3/examples/redis-outbound/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/redis-outbound -go 1.24 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/redis-outbound/go.sum b/v3/examples/redis-outbound/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/redis-outbound/go.sum +++ b/v3/examples/redis-outbound/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/redis-outbound/spin.toml b/v3/examples/redis-outbound/spin.toml index 9f34b373..281a3cab 100644 --- a/v3/examples/redis-outbound/spin.toml +++ b/v3/examples/redis-outbound/spin.toml @@ -16,5 +16,5 @@ environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messa allowed_outbound_hosts = ["redis://localhost:6379"] [component.redis-outbound.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/variables/README.md b/v3/examples/variables/README.md new file mode 100644 index 00000000..83533238 --- /dev/null +++ b/v3/examples/variables/README.md @@ -0,0 +1,20 @@ +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version + +# Usage +Build and run the Spin app: +```sh +spin up --build +``` + +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello +``` + +You should receive the following output: +``` +message: I'm a teapot +``` diff --git a/v3/examples/variables/go.mod b/v3/examples/variables/go.mod index 428e0b6d..b2e036d5 100644 --- a/v3/examples/variables/go.mod +++ b/v3/examples/variables/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/variables -go 1.24.1 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/variables/go.sum b/v3/examples/variables/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/examples/variables/go.sum +++ b/v3/examples/variables/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/examples/variables/spin.toml b/v3/examples/variables/spin.toml index 0ca6a397..042d091e 100644 --- a/v3/examples/variables/spin.toml +++ b/v3/examples/variables/spin.toml @@ -3,7 +3,7 @@ spin_manifest_version = 2 [application] name = "variables-example" authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." version = "1.0.0" [variables] @@ -18,6 +18,5 @@ source = "main.wasm" [component.variables.variables] message = "I'm a {{object}}" -[component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" - +[component.variables.build] +command = "componentize-go --world http-trigger --wit-path ../../wit componentize" diff --git a/v3/go.mod b/v3/go.mod index 4610aa65..62e47277 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -1,8 +1,10 @@ module github.com/spinframework/spin-go-sdk/v3 -go 1.23.2 +go 1.25.5 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 github.com/julienschmidt/httprouter v1.3.0 - go.bytecodealliance.org/cm v0.2.2 ) + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/go.sum b/v3/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/go.sum +++ b/v3/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/http/client.go b/v3/http/client.go index b4ed4f8a..9e67dd48 100644 --- a/v3/http/client.go +++ b/v3/http/client.go @@ -5,9 +5,9 @@ import ( "io" "net/http" - outgoinghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/outgoing-handler" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" - "go.bytecodealliance.org/cm" + wit "github.com/bytecodealliance/wit-bindgen/wit_types" + outgoinghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_outgoing_handler" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" ) // NewTransport returns http.RoundTripper backed by Spin SDK @@ -36,8 +36,8 @@ func Send(req *http.Request) (*http.Response, error) { return nil, err } - result := outgoinghandler.Handle(or, cm.None[types.RequestOptions]()) - if result.Err() != nil { + result := outgoinghandler.Handle(&or, wit.None[*types.RequestOptions]()) + if result.IsErr() { return nil, fmt.Errorf("TODO: convert to readable error") } @@ -45,32 +45,28 @@ func Send(req *http.Request) (*http.Response, error) { return nil, fmt.Errorf("error is %v", result.Err()) } - okresult := result.OK() + okresult := result.Ok() //wait until resp is returned okresult.Subscribe().Block() incomingResp := okresult.Get() - if incomingResp.None() { + if incomingResp.IsNone() { return nil, fmt.Errorf("incoming resp is None") - } - - if incomingResp.Some().IsErr() { + } else if incomingResp.Some().IsErr() { return nil, fmt.Errorf("error is %v", incomingResp.Some().Err()) + } else if incomingResp.Some().Ok().IsErr() { + return nil, fmt.Errorf("error is %v", incomingResp.Some().Ok().Err()) } - if incomingResp.Some().OK().IsErr() { - return nil, fmt.Errorf("error is %v", incomingResp.Some().OK().Err()) - } - - okresp := incomingResp.Some().OK().OK() + 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 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()) + body = NewReadCloser(*streamResult.Ok()) } resp := &http.Response{ diff --git a/v3/http/convertor_incoming_request.go b/v3/http/convertor_incoming_request.go index 97d5fbb0..b92b2317 100644 --- a/v3/http/convertor_incoming_request.go +++ b/v3/http/convertor_incoming_request.go @@ -5,8 +5,7 @@ import ( "io" "net/http" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" - "go.bytecodealliance.org/cm" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" ) type IncomingRequest = types.IncomingRequest @@ -21,20 +20,20 @@ func NewHttpRequest(ir IncomingRequest) (req *http.Request, err error) { // convert the path with query to a url var url string - if pathWithQuery := ir.PathWithQuery(); pathWithQuery.None() { + if pathWithQuery := ir.PathWithQuery(); pathWithQuery.IsNone() { url = "" } else { - url = *pathWithQuery.Some() + 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 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()) + body = NewReader(*streamResult.Ok()) } // create a new request @@ -44,49 +43,42 @@ func NewHttpRequest(ir IncomingRequest) (req *http.Request, err error) { } // update additional fields - toHttpHeader(ir.Headers(), &req.Header) + toHttpHeader(*ir.Headers(), &req.Header) return req, nil } func methodToString(m types.Method) (string, error) { - if m.Connect() { + switch m.Tag() { + case types.MethodConnect: return "CONNECT", nil - } - if m.Delete() { + case types.MethodDelete: return "DELETE", nil - } - if m.Get() { + case types.MethodGet: return "GET", nil - } - if m.Head() { + case types.MethodHead: return "HEAD", nil - } - if m.Options() { + case types.MethodOptions: return "OPTIONS", nil - } - if m.Patch() { + case types.MethodPatch: return "PATCH", nil - } - if m.Post() { + case types.MethodPost: return "POST", nil - } - if m.Put() { + case types.MethodPut: return "PUT", nil - } - if m.Trace() { + case types.MethodTrace: return "TRACE", nil + case types.MethodOther: + return m.Other(), fmt.Errorf("unknown http method 'other'") + default: + return "", fmt.Errorf("failed to convert http method") } - 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()) + for _, f := range src.Entries() { + key := f.F0 + value := string(f.F1) dest.Add(key, value) } } diff --git a/v3/http/convertor_outgoing_request.go b/v3/http/convertor_outgoing_request.go index 738ec8c5..cc55da94 100644 --- a/v3/http/convertor_outgoing_request.go +++ b/v3/http/convertor_outgoing_request.go @@ -3,30 +3,30 @@ package http import ( "net/http" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" - "go.bytecodealliance.org/cm" + wit "github.com/bytecodealliance/wit-bindgen/wit_types" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" ) // convert the IncomingRequest to http.Request func NewOutgoingHttpRequest(req *http.Request) (types.OutgoingRequest, error) { - headers := types.NewFields() - toWasiHeader(req.Header, headers) + headers := types.MakeFields() + toWasiHeader(req.Header, *headers) - or := types.NewOutgoingRequest(headers) - or.SetAuthority(cm.Some(req.Host)) + or := types.MakeOutgoingRequest(headers) + or.SetAuthority(wit.Some(req.Host)) or.SetMethod(toWasiMethod(req.Method)) - or.SetPathWithQuery(cm.Some(req.URL.RawPath)) + or.SetPathWithQuery(wit.Some(req.URL.RawPath)) switch req.URL.Scheme { case "http": - or.SetScheme(cm.Some(types.SchemeHTTP())) + or.SetScheme(wit.Some(types.MakeSchemeHttp())) case "https": - or.SetScheme(cm.Some(types.SchemeHTTPS())) + or.SetScheme(wit.Some(types.MakeSchemeHttps())) default: - or.SetScheme(cm.Some(types.SchemeOther(req.URL.Scheme))) + or.SetScheme(wit.Some(types.MakeSchemeOther(req.URL.Scheme))) } - return or, nil + return *or, nil } func toWasiHeader(src http.Header, dest types.Fields) { @@ -35,35 +35,36 @@ func toWasiHeader(src http.Header, dest types.Fields) { fieldVals := []types.FieldValue{} for _, val := range v { - fieldVals = append(fieldVals, types.FieldValue(cm.ToList([]uint8(val)))) + fieldVals = append(fieldVals, types.FieldValue(val)) } - //TODO(rjindal): check error - _ = dest.Set(key, cm.ToList(fieldVals)) + if result := dest.Set(key, fieldVals); result.IsErr() { + panic("failed to set WASI headers") + } } } func toWasiMethod(s string) types.Method { switch s { case http.MethodConnect: - return types.MethodConnect() + return types.MakeMethodConnect() case http.MethodDelete: - return types.MethodDelete() + return types.MakeMethodDelete() case http.MethodGet: - return types.MethodGet() + return types.MakeMethodGet() case http.MethodHead: - return types.MethodHead() + return types.MakeMethodHead() case http.MethodOptions: - return types.MethodOptions() + return types.MakeMethodOptions() case http.MethodPatch: - return types.MethodPatch() + return types.MakeMethodPatch() case http.MethodPost: - return types.MethodPost() + return types.MakeMethodPost() case http.MethodPut: - return types.MethodPut() + return types.MakeMethodPut() case http.MethodTrace: - return types.MethodTrace() + return types.MakeMethodTrace() default: - return types.MethodOther(s) + return types.MakeMethodOther(s) } } diff --git a/v3/http/convertor_outgoing_response.go b/v3/http/convertor_outgoing_response.go index a8cfcea4..95d55be4 100644 --- a/v3/http/convertor_outgoing_response.go +++ b/v3/http/convertor_outgoing_response.go @@ -5,9 +5,9 @@ import ( "net/http" "strings" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" + wit "github.com/bytecodealliance/wit-bindgen/wit_types" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + streams "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" ) var _ http.ResponseWriter = &responseOutparamWriter{} @@ -50,16 +50,17 @@ func (row *responseOutparamWriter) Write(buf []byte) (int, error) { if bodyResult.IsErr() { return 0, fmt.Errorf("failed to acquire resource handle to response body: %s", bodyResult.Err()) } - row.body = bodyResult.OK() + 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() + row.stream = writeResult.Ok() - result := cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](row.response) - types.ResponseOutparamSet(row.outparam, result) + result := wit.Ok[*types.OutgoingResponse, types.ErrorCode](&row.response) + + types.ResponseOutparamSet(&row.outparam, result) } // //TODO: determine if we need to do these to fulfill the ResponseWriter contract @@ -67,10 +68,10 @@ func (row *responseOutparamWriter) Write(buf []byte) (int, error) { // // 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) + contents := buf writeResult := row.stream.Write(contents) if writeResult.IsErr() { - if writeResult.Err().Closed() { + if writeResult.Err().Tag() == streams.StreamErrorClosed { return 0, fmt.Errorf("failed to write to response body's stream: closed") } @@ -80,7 +81,7 @@ func (row *responseOutparamWriter) Write(buf []byte) (int, error) { row.stream.BlockingFlush() - return int(contents.Len()), nil + return len(contents), nil } func (row *responseOutparamWriter) WriteHeader(statusCode int) { @@ -93,11 +94,11 @@ func (row *responseOutparamWriter) reconcileHeaders() error { // convert each value distincly fieldVals := []types.FieldValue{} for _, val := range vals { - fieldVals = append(fieldVals, types.FieldValue(cm.ToList([]uint8(val)))) + fieldVals = append(fieldVals, types.FieldValue(val)) } - if result := row.wasiHeaders.Set(types.FieldKey(key), cm.ToList(fieldVals)); result.IsErr() { - switch *result.Err() { + if result := row.wasiHeaders.Set(types.FieldKey(key), fieldVals); result.IsErr() { + switch result.Err().Tag() { case types.HeaderErrorInvalidSyntax: return fmt.Errorf("failed to set header %s to [%s]: invalid syntax", key, strings.Join(vals, ",")) case types.HeaderErrorForbidden: @@ -120,7 +121,7 @@ func NewHttpResponseWriter(out types.ResponseOutparam) *responseOutparamWriter { row := &responseOutparamWriter{ outparam: out, httpHeaders: http.Header{}, - wasiHeaders: types.NewFields(), + wasiHeaders: *types.MakeFields(), } return row @@ -139,7 +140,7 @@ func (row *responseOutparamWriter) reconcile() error { } // setting any headers after this will cause panic - row.response = types.NewOutgoingResponse(row.wasiHeaders) + row.response = *types.MakeOutgoingResponse(&row.wasiHeaders) // set status code. default to 200 if row.statuscode == 0 { diff --git a/v3/http/http.go b/v3/http/http.go index 47c85aa6..dc7f5b49 100644 --- a/v3/http/http.go +++ b/v3/http/http.go @@ -8,8 +8,9 @@ import ( "os" "github.com/julienschmidt/httprouter" - incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/incoming-handler" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" + incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + _ "github.com/spinframework/spin-go-sdk/v3/internal/wit_exports" "github.com/spinframework/spin-go-sdk/v3/wit" ) @@ -78,9 +79,9 @@ func Handle(fn func(http.ResponseWriter, *http.Request)) { handler = fn } -var wasiHandle = func(request types.IncomingRequest, responseOut types.ResponseOutparam) { +var wasiHandle = func(request *types.IncomingRequest, responseOut *types.ResponseOutparam) { // convert the incoming request to go's net/http type - httpReq, err := NewHttpRequest(request) + 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) @@ -88,7 +89,7 @@ var wasiHandle = func(request types.IncomingRequest, responseOut types.ResponseO } // convert the response outparam to go's net/http type - httpRes := NewHttpResponseWriter(responseOut) + httpRes := NewHttpResponseWriter(*responseOut) // run the user's handler handler(httpRes, httpReq) diff --git a/v3/http/streams.go b/v3/http/streams.go index 8e1513fd..04b469d4 100644 --- a/v3/http/streams.go +++ b/v3/http/streams.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" + streams "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" ) type inputStreamReader struct { @@ -20,15 +20,15 @@ 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() { + if readErr.Tag() == streams.StreamErrorClosed { 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 + readList := readResult.Ok() + copy(p, readList) + return len(readList), nil } // create an io.Reader from the input stream diff --git a/v3/http/testdata/http-tinygo/go.sum b/v3/http/testdata/http-tinygo/go.sum deleted file mode 100644 index c1ebfdf4..00000000 --- a/v3/http/testdata/http-tinygo/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/http/testdata/http-tinygo/spin.toml b/v3/http/testdata/http-tinygo/spin.toml deleted file mode 100644 index cdf364bd..00000000 --- a/v3/http/testdata/http-tinygo/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -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/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" - diff --git a/v3/http/testdata/http-tinygo/go.mod b/v3/http/testdata/http/go.mod similarity index 53% rename from v3/http/testdata/http-tinygo/go.mod rename to v3/http/testdata/http/go.mod index 68be74b4..29ed955f 100644 --- a/v3/http/testdata/http-tinygo/go.mod +++ b/v3/http/testdata/http/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/http/testdata/http -go 1.23.2 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/http/testdata/http/go.sum b/v3/http/testdata/http/go.sum new file mode 100644 index 00000000..00db3b18 --- /dev/null +++ b/v3/http/testdata/http/go.sum @@ -0,0 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= +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/v3/http/testdata/http-tinygo/main.go b/v3/http/testdata/http/main.go similarity index 100% rename from v3/http/testdata/http-tinygo/main.go rename to v3/http/testdata/http/main.go diff --git a/v3/http/testdata/http/spin.toml b/v3/http/testdata/http/spin.toml new file mode 100644 index 00000000..ece1e99f --- /dev/null +++ b/v3/http/testdata/http/spin.toml @@ -0,0 +1,17 @@ +spin_manifest_version = 2 + +[application] +authors = ["Rajat Jindal "] +description = "A simple Spin application written in Go." +name = "hello-example" +version = "1.0.0" + +[[trigger.http]] +route = "/hello" +component = "hello" + +[component.hello] +source = "main.wasm" +[component.hello.build] +command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" + diff --git a/v3/integration_test.go b/v3/integration_test.go index 0fd458de..71c691e9 100644 --- a/v3/integration_test.go +++ b/v3/integration_test.go @@ -91,8 +91,8 @@ func buildApp(t *testing.T, dir string) { } } -func TestHTTPTriger(t *testing.T) { - spin := startSpin(t, "http/testdata/http-tinygo") +func TestHTTPTrigger(t *testing.T) { + spin := startSpin(t, "http/testdata/http") defer spin.cancel() resp := retryGet(t, spin.url+"/hello") @@ -175,7 +175,6 @@ func TestBuildExamples(t *testing.T) { t.Fatal(err) } for _, example := range examples { - example := example t.Run(example.Name(), func(t *testing.T) { t.Parallel() buildApp(t, filepath.Join("examples", example.Name())) diff --git a/v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go b/v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go new file mode 100644 index 00000000..6c58194a --- /dev/null +++ b/v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go @@ -0,0 +1,13 @@ +package export_wasi_http_0_2_0_incoming_handler + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" +) + +var Exports struct { + Handle func(request *wasi_http_0_2_0_types.IncomingRequest, responseOut *wasi_http_0_2_0_types.ResponseOutparam) +} + +func Handle(request *wasi_http_0_2_0_types.IncomingRequest, responseOut *wasi_http_0_2_0_types.ResponseOutparam) { + Exports.Handle(request, responseOut) +} diff --git a/v3/internal/fermyon/spin/config/abi.go b/v3/internal/fermyon/spin/config/abi.go deleted file mode 100644 index 9f91b71e..00000000 --- a/v3/internal/fermyon/spin/config/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package config - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/config/config.wasm.go b/v3/internal/fermyon/spin/config/config.wasm.go deleted file mode 100644 index 82a2db72..00000000 --- a/v3/internal/fermyon/spin/config/config.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package config - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/config/config.wit.go b/v3/internal/fermyon/spin/config/config.wit.go deleted file mode 100644 index 30e9f111..00000000 --- a/v3/internal/fermyon/spin/config/config.wit.go +++ /dev/null @@ -1,84 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package config represents the imported interface "fermyon:spin/config". -package config - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/config/empty.s b/v3/internal/fermyon/spin/config/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/config/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go deleted file mode 100644 index 258da3cc..00000000 --- a/v3/internal/fermyon/spin/http-trigger/http-trigger.wit.go +++ /dev/null @@ -1,4 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package httptrigger represents the world "fermyon:spin/http-trigger". -package httptrigger diff --git a/v3/internal/fermyon/spin/http-types/http-types.wit.go b/v3/internal/fermyon/spin/http-types/http-types.wit.go deleted file mode 100644 index f6145cc4..00000000 --- a/v3/internal/fermyon/spin/http-types/http-types.wit.go +++ /dev/null @@ -1,164 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package httptypes represents the imported interface "fermyon:spin/http-types". -package httptypes - -import ( - "go.bytecodealliance.org/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 _MethodStrings = [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 _MethodStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e Method) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *Method) UnmarshalText(text []byte) error { - return _MethodUnmarshalCase(e, text) -} - -var _MethodUnmarshalCase = cm.CaseUnmarshaler[Method](_MethodStrings[:]) - -// Request represents the record "fermyon:spin/http-types#request". -// -// record request { -// method: method, -// uri: uri, -// headers: headers, -// params: params, -// body: option, -// } -type Request struct { - _ cm.HostLayout `json:"-"` - Method Method `json:"method"` - URI URI `json:"uri"` - Headers Headers `json:"headers"` - Params Params `json:"params"` - Body cm.Option[Body] `json:"body"` -} - -// Response represents the record "fermyon:spin/http-types#response". -// -// record response { -// status: http-status, -// headers: option, -// body: option, -// } -type Response struct { - _ cm.HostLayout `json:"-"` - Status HTTPStatus `json:"status"` - Headers cm.Option[Headers] `json:"headers"` - Body cm.Option[Body] `json:"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 _HTTPErrorStrings = [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 _HTTPErrorStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e HTTPError) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *HTTPError) UnmarshalText(text []byte) error { - return _HTTPErrorUnmarshalCase(e, text) -} - -var _HTTPErrorUnmarshalCase = cm.CaseUnmarshaler[HTTPError](_HTTPErrorStrings[:]) diff --git a/v3/internal/fermyon/spin/http/abi.go b/v3/internal/fermyon/spin/http/abi.go deleted file mode 100644 index 39139618..00000000 --- a/v3/internal/fermyon/spin/http/abi.go +++ /dev/null @@ -1,35 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package http - -import ( - httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" - "go.bytecodealliance.org/cm" - "unsafe" -) - -// ResponseShape is used for storage in variant or result types. -type ResponseShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(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/v3/internal/fermyon/spin/http/empty.s b/v3/internal/fermyon/spin/http/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/http/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/http/http.wasm.go b/v3/internal/fermyon/spin/http/http.wasm.go deleted file mode 100644 index 89f8e2a0..00000000 --- a/v3/internal/fermyon/spin/http/http.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package http - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/http/http.wit.go b/v3/internal/fermyon/spin/http/http.wit.go deleted file mode 100644 index 63c3fb1d..00000000 --- a/v3/internal/fermyon/spin/http/http.wit.go +++ /dev/null @@ -1,35 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package http represents the imported interface "fermyon:spin/http". -package http - -import ( - httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" - "go.bytecodealliance.org/cm" -) - -// 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 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 -} diff --git a/v3/internal/fermyon/spin/inbound-http/abi.go b/v3/internal/fermyon/spin/inbound-http/abi.go deleted file mode 100644 index 0f09e935..00000000 --- a/v3/internal/fermyon/spin/inbound-http/abi.go +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package inboundhttp - -import ( - httptypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" - "go.bytecodealliance.org/cm" -) - -func lift_OptionBody(f0 uint32, f1 *uint8, f2 uint32) (v cm.Option[httptypes.Body]) { - if f0 == 0 { - return - } - 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) { - 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/v3/internal/fermyon/spin/inbound-http/empty.s b/v3/internal/fermyon/spin/inbound-http/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/inbound-http/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go deleted file mode 100644 index 059257b8..00000000 --- a/v3/internal/fermyon/spin/inbound-http/inbound-http.exports.go +++ /dev/null @@ -1,11 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package inboundhttp - -// 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 Request) (result Response) -} diff --git a/v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go deleted file mode 100644 index 09ece433..00000000 --- a/v3/internal/fermyon/spin/inbound-http/inbound-http.wasm.go +++ /dev/null @@ -1,14 +0,0 @@ -// 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/v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go b/v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go deleted file mode 100644 index aefeb211..00000000 --- a/v3/internal/fermyon/spin/inbound-http/inbound-http.wit.go +++ /dev/null @@ -1,18 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/fermyon/spin/http-types" -) - -// 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/v3/internal/fermyon/spin/key-value/abi.go b/v3/internal/fermyon/spin/key-value/abi.go deleted file mode 100644 index ab3e6c1e..00000000 --- a/v3/internal/fermyon/spin/key-value/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package keyvalue - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/key-value/empty.s b/v3/internal/fermyon/spin/key-value/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/key-value/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/key-value/key-value.wasm.go b/v3/internal/fermyon/spin/key-value/key-value.wasm.go deleted file mode 100644 index f49914bf..00000000 --- a/v3/internal/fermyon/spin/key-value/key-value.wasm.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package keyvalue - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/key-value/key-value.wit.go b/v3/internal/fermyon/spin/key-value/key-value.wit.go deleted file mode 100644 index 34157201..00000000 --- a/v3/internal/fermyon/spin/key-value/key-value.wit.go +++ /dev/null @@ -1,250 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package keyvalue represents the imported interface "fermyon:spin/key-value". -package keyvalue - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/llm/abi.go b/v3/internal/fermyon/spin/llm/abi.go deleted file mode 100644 index f9a3c279..00000000 --- a/v3/internal/fermyon/spin/llm/abi.go +++ /dev/null @@ -1,45 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package llm - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// InferencingResultShape is used for storage in variant or result types. -type InferencingResultShape struct { - _ cm.HostLayout - 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 { - _ cm.HostLayout - shape [unsafe.Sizeof(EmbeddingsResult{})]byte -} diff --git a/v3/internal/fermyon/spin/llm/empty.s b/v3/internal/fermyon/spin/llm/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/llm/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/llm/llm.wasm.go b/v3/internal/fermyon/spin/llm/llm.wasm.go deleted file mode 100644 index fc5cac72..00000000 --- a/v3/internal/fermyon/spin/llm/llm.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package llm - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/llm/llm.wit.go b/v3/internal/fermyon/spin/llm/llm.wit.go deleted file mode 100644 index 2663b90a..00000000 --- a/v3/internal/fermyon/spin/llm/llm.wit.go +++ /dev/null @@ -1,209 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 { - _ cm.HostLayout `json:"-"` - // The maximum tokens that should be inferred. - // - // Note: the backing implementation may return less tokens. - MaxTokens uint32 `json:"max-tokens"` - - // The amount the model should avoid repeating tokens. - RepeatPenalty float32 `json:"repeat-penalty"` - - // The number of tokens the model should apply the repeat penalty to. - RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` - - // The randomness with which the next token is selected. - Temperature float32 `json:"temperature"` - - // The number of possible next tokens the model will choose from. - TopK uint32 `json:"top-k"` - - // The probability total of next tokens the model will choose from. - TopP float32 `json:"top-p"` -} - -// 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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - // Number of tokens in the prompt - PromptTokenCount uint32 `json:"prompt-token-count"` - - // Number of tokens generated by the inferencing operation - GeneratedTokenCount uint32 `json:"generated-token-count"` -} - -// InferencingResult represents the record "fermyon:spin/llm#inferencing-result". -// -// An inferencing result -// -// record inferencing-result { -// text: string, -// usage: inferencing-usage, -// } -type InferencingResult struct { - _ cm.HostLayout `json:"-"` - // The text generated by the model - // TODO: this should be a stream - Text string `json:"text"` - - // Usage information about the inferencing request - Usage InferencingUsage `json:"usage"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // Number of tokens in the prompt - PromptTokenCount uint32 `json:"prompt-token-count"` -} - -// EmbeddingsResult represents the record "fermyon:spin/llm#embeddings-result". -// -// Result of generating embeddings -// -// record embeddings-result { -// embeddings: list>, -// usage: embeddings-usage, -// } -type EmbeddingsResult struct { - _ cm.HostLayout `json:"-"` - // The embeddings generated by the request - Embeddings cm.List[cm.List[float32]] `json:"embeddings"` - - // Usage related to the embeddings generation request - Usage EmbeddingsUsage `json:"usage"` -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/mysql/abi.go b/v3/internal/fermyon/spin/mysql/abi.go deleted file mode 100644 index 3fc15d55..00000000 --- a/v3/internal/fermyon/spin/mysql/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mysql - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// RowSetShape is used for storage in variant or result types. -type RowSetShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(RowSet{})]byte -} diff --git a/v3/internal/fermyon/spin/mysql/empty.s b/v3/internal/fermyon/spin/mysql/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/mysql/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/mysql/mysql.wasm.go b/v3/internal/fermyon/spin/mysql/mysql.wasm.go deleted file mode 100644 index 4b35da74..00000000 --- a/v3/internal/fermyon/spin/mysql/mysql.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mysql - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/mysql/mysql.wit.go b/v3/internal/fermyon/spin/mysql/mysql.wit.go deleted file mode 100644 index 91921384..00000000 --- a/v3/internal/fermyon/spin/mysql/mysql.wit.go +++ /dev/null @@ -1,140 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package mysql represents the imported interface "fermyon:spin/mysql". -package mysql - -import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/rdbms-types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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) -} - -var _MysqlErrorStrings = [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 _MysqlErrorStrings[v.Tag()] -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} diff --git a/v3/internal/fermyon/spin/postgres/abi.go b/v3/internal/fermyon/spin/postgres/abi.go deleted file mode 100644 index 5190ca2b..00000000 --- a/v3/internal/fermyon/spin/postgres/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// RowSetShape is used for storage in variant or result types. -type RowSetShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(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/v3/internal/fermyon/spin/postgres/empty.s b/v3/internal/fermyon/spin/postgres/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/postgres/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/postgres/postgres.wasm.go b/v3/internal/fermyon/spin/postgres/postgres.wasm.go deleted file mode 100644 index 9606b852..00000000 --- a/v3/internal/fermyon/spin/postgres/postgres.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/postgres/postgres.wit.go b/v3/internal/fermyon/spin/postgres/postgres.wit.go deleted file mode 100644 index d67ca9b8..00000000 --- a/v3/internal/fermyon/spin/postgres/postgres.wit.go +++ /dev/null @@ -1,140 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package postgres represents the imported interface "fermyon:spin/postgres". -package postgres - -import ( - rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/rdbms-types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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) -} - -var _PgErrorStrings = [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 _PgErrorStrings[v.Tag()] -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} diff --git a/v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go b/v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go deleted file mode 100644 index 0af33555..00000000 --- a/v3/internal/fermyon/spin/rdbms-types/rdbms-types.wit.go +++ /dev/null @@ -1,488 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package rdbmstypes represents the imported interface "fermyon:spin/rdbms-types". -package rdbmstypes - -import ( - "go.bytecodealliance.org/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 _DbDataTypeStrings = [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 _DbDataTypeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e DbDataType) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *DbDataType) UnmarshalText(text []byte) error { - return _DbDataTypeUnmarshalCase(e, text) -} - -var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) - -// 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 -} - -var _DbValueStrings = [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 _DbValueStrings[v.Tag()] -} - -// 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 -} - -var _ParameterValueStrings = [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 _ParameterValueStrings[v.Tag()] -} - -// Column represents the record "fermyon:spin/rdbms-types#column". -// -// record column { -// name: string, -// data-type: db-data-type, -// } -type Column struct { - _ cm.HostLayout `json:"-"` - Name string `json:"name"` - DataType DbDataType `json:"data-type"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - Columns cm.List[Column] `json:"columns"` - Rows cm.List[Row] `json:"rows"` -} diff --git a/v3/internal/fermyon/spin/redis-types/redis-types.wit.go b/v3/internal/fermyon/spin/redis-types/redis-types.wit.go deleted file mode 100644 index 9d4147ca..00000000 --- a/v3/internal/fermyon/spin/redis-types/redis-types.wit.go +++ /dev/null @@ -1,158 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package redistypes represents the imported interface "fermyon:spin/redis-types". -package redistypes - -import ( - "go.bytecodealliance.org/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 _ErrorStrings = [2]string{ - "success", - "error", -} - -// String implements [fmt.Stringer], returning the enum case name of e. -func (e Error) String() string { - return _ErrorStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e Error) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *Error) UnmarshalText(text []byte) error { - return _ErrorUnmarshalCase(e, text) -} - -var _ErrorUnmarshalCase = cm.CaseUnmarshaler[Error](_ErrorStrings[:]) - -// 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) -} - -var _RedisParameterStrings = [2]string{ - "int64", - "binary", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v RedisParameter) String() string { - return _RedisParameterStrings[v.Tag()] -} - -// 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) -} - -var _RedisResultStrings = [4]string{ - "nil", - "status", - "int64", - "binary", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v RedisResult) String() string { - return _RedisResultStrings[v.Tag()] -} diff --git a/v3/internal/fermyon/spin/redis/empty.s b/v3/internal/fermyon/spin/redis/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/redis/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/redis/redis.wasm.go b/v3/internal/fermyon/spin/redis/redis.wasm.go deleted file mode 100644 index b474f609..00000000 --- a/v3/internal/fermyon/spin/redis/redis.wasm.go +++ /dev/null @@ -1,45 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package redis - -import ( - "go.bytecodealliance.org/cm" -) - -// 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[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/v3/internal/fermyon/spin/redis/redis.wit.go b/v3/internal/fermyon/spin/redis/redis.wit.go deleted file mode 100644 index f4ff970c..00000000 --- a/v3/internal/fermyon/spin/redis/redis.wit.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package redis represents the imported interface "fermyon:spin/redis". -package redis - -import ( - redistypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/redis-types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// publish: func(address: string, channel: string, payload: payload) -> result<_, -// error> -// -//go:nosplit -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) - wasmimport_Publish((*uint8)(address0), (uint32)(address1), (*uint8)(channel0), (uint32)(channel1), (*uint8)(payload0), (uint32)(payload1), &result) - return -} - -// 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[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 -} - -// 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 Payload) (result cm.Result[Error, struct{}, 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 -} - -// 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, Error]) { - address0, address1 := cm.LowerString(address) - key0, key1 := cm.LowerString(key) - wasmimport_Incr((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// 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, Error]) { - address0, address1 := cm.LowerString(address) - keys0, keys1 := cm.LowerList(keys) - wasmimport_Del((*uint8)(address0), (uint32)(address1), (*string)(keys0), (uint32)(keys1), &result) - return -} - -// 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, 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 -} - -// 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], Error]) { - address0, address1 := cm.LowerString(address) - key0, key1 := cm.LowerString(key) - wasmimport_Smembers((*uint8)(address0), (uint32)(address1), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// 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, 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 -} - -// 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[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), (*RedisParameter)(arguments0), (uint32)(arguments1), &result) - return -} diff --git a/v3/internal/fermyon/spin/sqlite/abi.go b/v3/internal/fermyon/spin/sqlite/abi.go deleted file mode 100644 index 3790d14c..00000000 --- a/v3/internal/fermyon/spin/sqlite/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package sqlite - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/sqlite/empty.s b/v3/internal/fermyon/spin/sqlite/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/sqlite/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/sqlite/sqlite.wasm.go b/v3/internal/fermyon/spin/sqlite/sqlite.wasm.go deleted file mode 100644 index 9101eb48..00000000 --- a/v3/internal/fermyon/spin/sqlite/sqlite.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package sqlite - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/sqlite/sqlite.wit.go b/v3/internal/fermyon/spin/sqlite/sqlite.wit.go deleted file mode 100644 index 5e029b82..00000000 --- a/v3/internal/fermyon/spin/sqlite/sqlite.wit.go +++ /dev/null @@ -1,256 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package sqlite represents the imported interface "fermyon:spin/sqlite". -package sqlite - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 -} - -var _ValueStrings = [5]string{ - "integer", - "real", - "text", - "blob", - "null", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Value) String() string { - return _ValueStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - Values cm.List[Value] `json:"values"` -} - -// QueryResult represents the record "fermyon:spin/sqlite#query-result". -// -// A result of a query -// -// record query-result { -// columns: list, -// rows: list, -// } -type QueryResult struct { - _ cm.HostLayout `json:"-"` - // The names of the columns retrieved in the query - Columns cm.List[string] `json:"columns"` - - // the row results each containing the values for all the columns for a given row - Rows cm.List[RowResult] `json:"rows"` -} - -// 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 -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go deleted file mode 100644 index 5e2a11f9..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/http-trigger/http-trigger.wit.go +++ /dev/null @@ -1,6 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/key-value/abi.go b/v3/internal/fermyon/spin/v2.0.0/key-value/abi.go deleted file mode 100644 index 5dab0880..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/key-value/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package keyvalue - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// 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/v3/internal/fermyon/spin/v2.0.0/key-value/empty.s b/v3/internal/fermyon/spin/v2.0.0/key-value/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/key-value/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go b/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go deleted file mode 100644 index d2840431..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wasm.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package keyvalue - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go b/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go deleted file mode 100644 index bf8e7f74..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/key-value/key-value.wit.go +++ /dev/null @@ -1,194 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} diff --git a/v3/internal/fermyon/spin/v2.0.0/llm/abi.go b/v3/internal/fermyon/spin/v2.0.0/llm/abi.go deleted file mode 100644 index f9a3c279..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/llm/abi.go +++ /dev/null @@ -1,45 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package llm - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// InferencingResultShape is used for storage in variant or result types. -type InferencingResultShape struct { - _ cm.HostLayout - 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 { - _ cm.HostLayout - shape [unsafe.Sizeof(EmbeddingsResult{})]byte -} diff --git a/v3/internal/fermyon/spin/v2.0.0/llm/empty.s b/v3/internal/fermyon/spin/v2.0.0/llm/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/llm/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go b/v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go deleted file mode 100644 index 44caad36..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/llm/llm.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package llm - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go b/v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go deleted file mode 100644 index db7f1e02..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/llm/llm.wit.go +++ /dev/null @@ -1,209 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 { - _ cm.HostLayout `json:"-"` - // The maximum tokens that should be inferred. - // - // Note: the backing implementation may return less tokens. - MaxTokens uint32 `json:"max-tokens"` - - // The amount the model should avoid repeating tokens. - RepeatPenalty float32 `json:"repeat-penalty"` - - // The number of tokens the model should apply the repeat penalty to. - RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` - - // The randomness with which the next token is selected. - Temperature float32 `json:"temperature"` - - // The number of possible next tokens the model will choose from. - TopK uint32 `json:"top-k"` - - // The probability total of next tokens the model will choose from. - TopP float32 `json:"top-p"` -} - -// 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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - // Number of tokens in the prompt - PromptTokenCount uint32 `json:"prompt-token-count"` - - // Number of tokens generated by the inferencing operation - GeneratedTokenCount uint32 `json:"generated-token-count"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // The text generated by the model - // TODO: this should be a stream - Text string `json:"text"` - - // Usage information about the inferencing request - Usage InferencingUsage `json:"usage"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // Number of tokens in the prompt - PromptTokenCount uint32 `json:"prompt-token-count"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // The embeddings generated by the request - Embeddings cm.List[cm.List[float32]] `json:"embeddings"` - - // Usage related to the embeddings generation request - Usage EmbeddingsUsage `json:"usage"` -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go deleted file mode 100644 index 6dc79b7a..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mqtt/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mqtt - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s b/v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mqtt/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go deleted file mode 100644 index beada6f3..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mqtt - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go b/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go deleted file mode 100644 index 9ab2f882..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mqtt/mqtt.wit.go +++ /dev/null @@ -1,179 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package mqtt represents the imported interface "fermyon:spin/mqtt@2.0.0". -package mqtt - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 _QosStrings = [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 _QosStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e Qos) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *Qos) UnmarshalText(text []byte) error { - return _QosUnmarshalCase(e, text) -} - -var _QosUnmarshalCase = cm.CaseUnmarshaler[Qos](_QosStrings[:]) - -// 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 -} - -// 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 -} - -// 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 -} - -// 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/v3/internal/fermyon/spin/v2.0.0/mysql/abi.go b/v3/internal/fermyon/spin/v2.0.0/mysql/abi.go deleted file mode 100644 index 8cf2987f..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mysql/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mysql - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// ErrorShape is used for storage in variant or result types. -type ErrorShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(Error{})]byte -} - -// RowSetShape is used for storage in variant or result types. -type RowSetShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(RowSet{})]byte -} diff --git a/v3/internal/fermyon/spin/v2.0.0/mysql/empty.s b/v3/internal/fermyon/spin/v2.0.0/mysql/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mysql/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go b/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go deleted file mode 100644 index 53234f2d..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wasm.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package mysql - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go b/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go deleted file mode 100644 index 890b85f0..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/mysql/mysql.wit.go +++ /dev/null @@ -1,86 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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 -} - -// 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, Error]) { - address0, address1 := cm.LowerString(address) - wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} diff --git a/v3/internal/fermyon/spin/v2.0.0/postgres/abi.go b/v3/internal/fermyon/spin/v2.0.0/postgres/abi.go deleted file mode 100644 index 5f6c14f7..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/postgres/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// ErrorShape is used for storage in variant or result types. -type ErrorShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(Error{})]byte -} - -// RowSetShape is used for storage in variant or result types. -type RowSetShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(RowSet{})]byte -} diff --git a/v3/internal/fermyon/spin/v2.0.0/postgres/empty.s b/v3/internal/fermyon/spin/v2.0.0/postgres/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/postgres/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go b/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go deleted file mode 100644 index 74aed046..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wasm.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go b/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go deleted file mode 100644 index 112cf948..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/postgres/postgres.wit.go +++ /dev/null @@ -1,87 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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 -} - -// 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, Error]) { - address0, address1 := cm.LowerString(address) - wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} diff --git a/v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go b/v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go deleted file mode 100644 index 093b7e2d..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/rdbms-types/rdbms-types.wit.go +++ /dev/null @@ -1,576 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 _DbDataTypeStrings = [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 _DbDataTypeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e DbDataType) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *DbDataType) UnmarshalText(text []byte) error { - return _DbDataTypeUnmarshalCase(e, text) -} - -var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) - -// 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 -} - -var _DbValueStrings = [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 _DbValueStrings[v.Tag()] -} - -// 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 -} - -var _ParameterValueStrings = [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 _ParameterValueStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - Name string `json:"name"` - DataType DbDataType `json:"data-type"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - Columns cm.List[Column] `json:"columns"` - Rows cm.List[Row] `json:"rows"` -} diff --git a/v3/internal/fermyon/spin/v2.0.0/redis/abi.go b/v3/internal/fermyon/spin/v2.0.0/redis/abi.go deleted file mode 100644 index 3dd97e6d..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/redis/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package redis - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// 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/v3/internal/fermyon/spin/v2.0.0/redis/empty.s b/v3/internal/fermyon/spin/v2.0.0/redis/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/redis/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go b/v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go deleted file mode 100644 index 8a4b6592..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/redis/redis.wasm.go +++ /dev/null @@ -1,53 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package redis - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go b/v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go deleted file mode 100644 index 4a092f21..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/redis/redis.wit.go +++ /dev/null @@ -1,366 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package redis represents the imported interface "fermyon:spin/redis@2.0.0". -package redis - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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) -} - -var _RedisParameterStrings = [2]string{ - "int64", - "binary", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v RedisParameter) String() string { - return _RedisParameterStrings[v.Tag()] -} - -// 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) -} - -var _RedisResultStrings = [4]string{ - "nil", - "status", - "int64", - "binary", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v RedisResult) String() string { - return _RedisResultStrings[v.Tag()] -} diff --git a/v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go deleted file mode 100644 index 3790d14c..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/sqlite/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package sqlite - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s b/v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/sqlite/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go deleted file mode 100644 index 7d11ad95..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package sqlite - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go b/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go deleted file mode 100644 index a0feadd8..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/sqlite/sqlite.wit.go +++ /dev/null @@ -1,256 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package sqlite represents the imported interface "fermyon:spin/sqlite@2.0.0". -package sqlite - -import ( - "go.bytecodealliance.org/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 -} - -// 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 -} - -// 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 -} - -// 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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// 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 -} - -var _ValueStrings = [5]string{ - "integer", - "real", - "text", - "blob", - "null", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Value) String() string { - return _ValueStrings[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 -// -// record row-result { -// values: list, -// } -type RowResult struct { - _ cm.HostLayout `json:"-"` - Values cm.List[Value] `json:"values"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // The names of the columns retrieved in the query - Columns cm.List[string] `json:"columns"` - - // the row results each containing the values for all the columns for a given row - Rows cm.List[RowResult] `json:"rows"` -} diff --git a/v3/internal/fermyon/spin/v2.0.0/variables/abi.go b/v3/internal/fermyon/spin/v2.0.0/variables/abi.go deleted file mode 100644 index 1e4a7713..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/variables/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package variables - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/variables/empty.s b/v3/internal/fermyon/spin/v2.0.0/variables/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/variables/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go b/v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go deleted file mode 100644 index a0bc1b74..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/variables/variables.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package variables - -import ( - "go.bytecodealliance.org/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/v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go b/v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go deleted file mode 100644 index 1c406239..00000000 --- a/v3/internal/fermyon/spin/v2.0.0/variables/variables.wit.go +++ /dev/null @@ -1,95 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package variables represents the imported interface "fermyon:spin/variables@2.0.0". -package variables - -import ( - "go.bytecodealliance.org/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) -} - -var _ErrorStrings = [4]string{ - "invalid-name", - "undefined", - "provider", - "other", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Error) String() string { - return _ErrorStrings[v.Tag()] -} - -// 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 -} diff --git a/v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go b/v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go deleted file mode 100644 index b0cdd90d..00000000 --- a/v3/internal/fermyon/spin/v3.0.0/http-trigger/http-trigger.wit.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package httptrigger represents the world "fermyon:spin/http-trigger@3.0.0". -// -// The full world of a guest targeting an http-trigger -package httptrigger diff --git a/v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go new file mode 100644 index 00000000..bb4c051c --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go @@ -0,0 +1,438 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_key_value + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +//go:wasmimport fermyon:spin/key-value@2.0.0 [resource-drop]store +func resourceDropStore(handle int32) + +// An open key-value store +type Store struct { + handle *wit_runtime.Handle +} + +func (self *Store) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Store) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Store) Handle() int32 { + return self.handle.Use() +} + +func (self *Store) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropStore(handle) + } +} + +func StoreFromOwnHandle(handleValue int32) *Store { + handle := wit_runtime.MakeHandle(handleValue) + value := &Store{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropStore(handleValue) + } + }, 0) + return value +} + +func StoreFromBorrowHandle(handleValue int32) *Store { + return StoreFromOwnHandle(handleValue) +} + +const ( + // Too many stores have been opened simultaneously. Closing one or more + // stores prior to retrying may address this. + ErrorStoreTableFull uint8 = 0 + // The host does not recognize the store label requested. + ErrorNoSuchStore uint8 = 1 + // The requesting component does not have access to the specified store + // (which may or may not exist). + ErrorAccessDenied uint8 = 2 + // Some implementation-specific error has occurred (e.g. I/O) + ErrorOther uint8 = 3 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorStoreTableFull() Error { + return Error{ErrorStoreTableFull, nil} +} +func MakeErrorNoSuchStore() Error { + return Error{ErrorNoSuchStore, nil} +} +func MakeErrorAccessDenied() Error { + return Error{ErrorAccessDenied, nil} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [static]store.open +func wasm_import_static_store_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func StoreOpen(label string) wit_types.Result[*Store, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(label)) + pinner.Pin(utf8) + wasm_import_static_store_open(uintptr(utf8), uint32(len(label)), returnArea) + var result wit_types.Result[*Store, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Store, Error](StoreFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Store, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get +func wasm_import_method_store_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Store) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_store_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Option[[]uint8], Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[[]uint8]() + case 1: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + option = wit_types.Some[[]uint8](value) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.set +func wasm_import_method_store_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Store) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_method_store_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.delete +func wasm_import_method_store_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Store) Delete(key string) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_store_delete((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.exists +func wasm_import_method_store_exists(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Store) Exists(key string) wit_types.Result[bool, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_store_exists((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[bool, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[bool, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get-keys +func wasm_import_method_store_get_keys(arg0 int32, arg1 uintptr) + +func (self *Store) GetKeys() wit_types.Result[[]string, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_method_store_get_keys((self).Handle(), returnArea) + var result1 wit_types.Result[[]string, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result1 = wit_types.Ok[[]string, Error](result) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result1 = wit_types.Err[[]string, Error](variant) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go new file mode 100644 index 00000000..0e7129da --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go @@ -0,0 +1,277 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_llm + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +// A Large Language Model. +type InferencingModel = string + +// Inference request parameters +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 +} + +const ( + ErrorModelNotSupported uint8 = 0 + ErrorRuntimeError uint8 = 1 + ErrorInvalidInput uint8 = 2 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) RuntimeError() string { + if self.tag != ErrorRuntimeError { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) InvalidInput() string { + if self.tag != ErrorInvalidInput { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorModelNotSupported() Error { + return Error{ErrorModelNotSupported, nil} +} +func MakeErrorRuntimeError(value string) Error { + return Error{ErrorRuntimeError, value} +} +func MakeErrorInvalidInput(value string) Error { + return Error{ErrorInvalidInput, value} +} + +// Usage information related to the inferencing result +type InferencingUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 +} + +// An inferencing result +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 +} + +// The model used for generating embeddings +type EmbeddingModel = string + +// Usage related to an embeddings generation request +type EmbeddingsUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 +} + +// Result of generating embeddings +type EmbeddingsResult struct { + // The embeddings generated by the request + Embeddings [][]float32 + // Usage related to the embeddings generation request + Usage EmbeddingsUsage +} + +//go:wasmimport fermyon:spin/llm@2.0.0 infer +func wasm_import_infer(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 float32, arg7 int32, arg8 float32, arg9 int32, arg10 float32, arg11 uintptr) + +func Infer(model string, prompt string, params wit_types.Option[InferencingParams]) wit_types.Result[InferencingResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (8 + 3*4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(model)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(prompt)) + pinner.Pin(utf80) + var option int32 + var option1 int32 + var option2 float32 + var option3 int32 + var option4 float32 + var option5 int32 + var option6 float32 + switch params.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option1 = 0 + option2 = 0 + option3 = 0 + option4 = 0 + option5 = 0 + option6 = 0 + case wit_types.OptionSome: + payload := params.Some() + + option = int32(1) + option1 = int32((payload).MaxTokens) + option2 = (payload).RepeatPenalty + option3 = int32((payload).RepeatPenaltyLastNTokenCount) + option4 = (payload).Temperature + option5 = int32((payload).TopK) + option6 = (payload).TopP + default: + panic("unreachable") + } + wasm_import_infer(uintptr(utf8), uint32(len(model)), uintptr(utf80), uint32(len(prompt)), option, option1, option2, option3, option4, option5, option6, returnArea) + var result wit_types.Result[InferencingResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[InferencingResult, Error](InferencingResult{value, InferencingUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 3*4))))}}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorModelNotSupported() + + case 1: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorRuntimeError(value7) + + case 2: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidInput(value8) + + default: + panic("unreachable") + } + + result = wit_types.Err[InferencingResult, Error](variant) + default: + panic("unreachable") + } + result9 := result + return result9 + +} + +//go:wasmimport fermyon:spin/llm@2.0.0 generate-embeddings +func wasm_import_generate_embeddings(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func GenerateEmbeddings(model string, text []string) wit_types.Result[EmbeddingsResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(model)) + pinner.Pin(utf8) + slice := text + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf80 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + + } + + wasm_import_generate_embeddings(uintptr(utf8), uint32(len(model)), uintptr(result), length, returnArea) + var result4 wit_types.Result[EmbeddingsResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([][]float32, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.Slice((*float32)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result1 = append(result1, value) + } + + result4 = wit_types.Ok[EmbeddingsResult, Error](EmbeddingsResult{result1, EmbeddingsUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))}}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorModelNotSupported() + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorRuntimeError(value2) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidInput(value3) + + default: + panic("unreachable") + } + + result4 = wit_types.Err[EmbeddingsResult, Error](variant) + default: + panic("unreachable") + } + result5 := result4 + return result5 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go new file mode 100644 index 00000000..ef990edb --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go @@ -0,0 +1,246 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_mqtt + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + // An invalid address string + ErrorInvalidAddress uint8 = 0 + // There are too many open connections + ErrorTooManyConnections uint8 = 1 + // Connection failure e.g. address not allowed. + ErrorConnectionFailed uint8 = 2 + // Some other error occurred + ErrorOther uint8 = 3 +) + +// Errors related to interacting with Mqtt +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) ConnectionFailed() string { + if self.tag != ErrorConnectionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorInvalidAddress() Error { + return Error{ErrorInvalidAddress, nil} +} +func MakeErrorTooManyConnections() Error { + return Error{ErrorTooManyConnections, nil} +} +func MakeErrorConnectionFailed(value string) Error { + return Error{ErrorConnectionFailed, value} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +const ( + QosAtMostOnce uint8 = 0 + QosAtLeastOnce uint8 = 1 + QosExactlyOnce uint8 = 2 +) + +// QoS for publishing Mqtt messages +type Qos = uint8 + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +// The message payload. +type Payload = []uint8 + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 int64, arg7 uintptr) + +func ConnectionOpen(address string, username string, password string, keepAliveIntervalInSecs uint64) wit_types.Result[*Connection, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(username)) + pinner.Pin(utf80) + utf81 := unsafe.Pointer(unsafe.StringData(password)) + pinner.Pin(utf81) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(username)), uintptr(utf81), uint32(len(password)), int64(keepAliveIntervalInSecs), returnArea) + var result wit_types.Result[*Connection, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorConnectionFailed(value) + + case 3: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value2) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, Error](variant) + default: + panic("unreachable") + } + result3 := result + return result3 + +} + +//go:wasmimport fermyon:spin/mqtt@2.0.0 [method]connection.publish +func wasm_import_method_connection_publish(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 int32, arg6 uintptr) + +func (self *Connection) Publish(topic string, payload []uint8, qos Qos) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(topic)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + wasm_import_method_connection_publish((self).Handle(), uintptr(utf8), uint32(len(topic)), uintptr(data), uint32(len(payload)), int32(qos), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorConnectionFailed(value) + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go new file mode 100644 index 00000000..1b779266 --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go @@ -0,0 +1,533 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_mysql + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" + "runtime" + "unsafe" +) + +type ParameterValue = fermyon_spin_2_0_0_rdbms_types.ParameterValue +type RowSet = fermyon_spin_2_0_0_rdbms_types.RowSet +type Error = fermyon_spin_2_0_0_rdbms_types.Error + +//go:wasmimport fermyon:spin/mysql@2.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +// A connection to a MySQL database. +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) + var result wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value) + + case 1: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value0) + + case 2: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value1) + + case 3: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value2) + + case 4: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value3) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) + default: + panic("unreachable") + } + result4 := result + return result4 + +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.query +func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result13 wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result2 := make([]fermyon_spin_2_0_0_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result2 = append(result2, fermyon_spin_2_0_0_rdbms_types.Column{value, uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))}) + } + + result6 := make([][]fermyon_spin_2_0_0_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result5 := make([]fermyon_spin_2_0_0_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant fermyon_spin_2_0_0_rdbms_types.DbValue + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueBoolean((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))) != 0)) + + case 1: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt8(int8(int8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 2: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt16(int16(int16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 3: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 4: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 5: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint8(uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 6: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint16(uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 7: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint32(uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 8: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint64(uint64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 9: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueFloating32(*(*float32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 10: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueFloating64(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 11: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueStr(value3) + + case 12: + value4 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueBinary(value4) + + case 13: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueDbNull() + + case 14: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUnsupported() + + default: + panic("unreachable") + } + + result5 = append(result5, variant) + } + + result6 = append(result6, result5) + } + + result13 = wit_types.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) + case 1: + var variant12 fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value7) + + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value8) + + case 2: + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value9) + + case 3: + value10 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value10) + + case 4: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value11) + + default: + panic("unreachable") + } + + result13 = wit_types.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) + default: + panic("unreachable") + } + result14 := result13 + return result14 + +} + +//go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.execute +func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result6 wit_types.Result[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result6 = wit_types.Ok[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error](wit_types.Unit{}) + case 1: + var variant fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value) + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value2) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value3) + + case 3: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value4) + + case 4: + value5 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value5) + + default: + panic("unreachable") + } + + result6 = wit_types.Err[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error](variant) + default: + panic("unreachable") + } + result7 := result6 + return result7 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go new file mode 100644 index 00000000..fd44f571 --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go @@ -0,0 +1,533 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_postgres + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" + "runtime" + "unsafe" +) + +type ParameterValue = fermyon_spin_2_0_0_rdbms_types.ParameterValue +type RowSet = fermyon_spin_2_0_0_rdbms_types.RowSet +type Error = fermyon_spin_2_0_0_rdbms_types.Error + +//go:wasmimport fermyon:spin/postgres@2.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +// A connection to a postgres database. +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) + var result wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value) + + case 1: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value0) + + case 2: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value1) + + case 3: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value2) + + case 4: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value3) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) + default: + panic("unreachable") + } + result4 := result + return result4 + +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.query +func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result13 wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result2 := make([]fermyon_spin_2_0_0_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result2 = append(result2, fermyon_spin_2_0_0_rdbms_types.Column{value, uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))}) + } + + result6 := make([][]fermyon_spin_2_0_0_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result5 := make([]fermyon_spin_2_0_0_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant fermyon_spin_2_0_0_rdbms_types.DbValue + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueBoolean((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))) != 0)) + + case 1: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt8(int8(int8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 2: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt16(int16(int16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 3: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 4: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 5: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint8(uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 6: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint16(uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 7: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint32(uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 8: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUint64(uint64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 9: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueFloating32(*(*float32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 10: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueFloating64(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 11: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueStr(value3) + + case 12: + value4 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueBinary(value4) + + case 13: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueDbNull() + + case 14: + + variant = fermyon_spin_2_0_0_rdbms_types.MakeDbValueUnsupported() + + default: + panic("unreachable") + } + + result5 = append(result5, variant) + } + + result6 = append(result6, result5) + } + + result13 = wit_types.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) + case 1: + var variant12 fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value7) + + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value8) + + case 2: + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value9) + + case 3: + value10 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value10) + + case 4: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value11) + + default: + panic("unreachable") + } + + result13 = wit_types.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) + default: + panic("unreachable") + } + result14 := result13 + return result14 + +} + +//go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.execute +func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_2_0_0_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result6 wit_types.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result6 = wit_types.Ok[uint64, fermyon_spin_2_0_0_rdbms_types.Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant fermyon_spin_2_0_0_rdbms_types.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorConnectionFailed(value) + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorBadParameter(value2) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorQueryFailed(value3) + + case 3: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorValueConversionFailed(value4) + + case 4: + value5 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = fermyon_spin_2_0_0_rdbms_types.MakeErrorOther(value5) + + default: + panic("unreachable") + } + + result6 = wit_types.Err[uint64, fermyon_spin_2_0_0_rdbms_types.Error](variant) + default: + panic("unreachable") + } + result7 := result6 + return result7 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go new file mode 100644 index 00000000..aef7f08f --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go @@ -0,0 +1,436 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_rdbms_types + +import () + +const ( + ErrorConnectionFailed uint8 = 0 + ErrorBadParameter uint8 = 1 + ErrorQueryFailed uint8 = 2 + ErrorValueConversionFailed uint8 = 3 + ErrorOther uint8 = 4 +) + +// Errors related to interacting with a database. +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) ConnectionFailed() string { + if self.tag != ErrorConnectionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) BadParameter() string { + if self.tag != ErrorBadParameter { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) QueryFailed() string { + if self.tag != ErrorQueryFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) ValueConversionFailed() string { + if self.tag != ErrorValueConversionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorConnectionFailed(value string) Error { + return Error{ErrorConnectionFailed, value} +} +func MakeErrorBadParameter(value string) Error { + return Error{ErrorBadParameter, value} +} +func MakeErrorQueryFailed(value string) Error { + return Error{ErrorQueryFailed, value} +} +func MakeErrorValueConversionFailed(value string) Error { + return Error{ErrorValueConversionFailed, value} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +const ( + DbDataTypeBoolean uint8 = 0 + DbDataTypeInt8 uint8 = 1 + DbDataTypeInt16 uint8 = 2 + DbDataTypeInt32 uint8 = 3 + DbDataTypeInt64 uint8 = 4 + DbDataTypeUint8 uint8 = 5 + DbDataTypeUint16 uint8 = 6 + DbDataTypeUint32 uint8 = 7 + DbDataTypeUint64 uint8 = 8 + DbDataTypeFloating32 uint8 = 9 + DbDataTypeFloating64 uint8 = 10 + DbDataTypeStr uint8 = 11 + DbDataTypeBinary uint8 = 12 + DbDataTypeOther uint8 = 13 +) + +// Data types for a database column +type DbDataType = uint8 + +const ( + DbValueBoolean uint8 = 0 + DbValueInt8 uint8 = 1 + DbValueInt16 uint8 = 2 + DbValueInt32 uint8 = 3 + DbValueInt64 uint8 = 4 + DbValueUint8 uint8 = 5 + DbValueUint16 uint8 = 6 + DbValueUint32 uint8 = 7 + DbValueUint64 uint8 = 8 + DbValueFloating32 uint8 = 9 + DbValueFloating64 uint8 = 10 + DbValueStr uint8 = 11 + DbValueBinary uint8 = 12 + DbValueDbNull uint8 = 13 + DbValueUnsupported uint8 = 14 +) + +// Database values +type DbValue struct { + tag uint8 + value any +} + +func (self DbValue) Tag() uint8 { + return self.tag +} + +func (self DbValue) Boolean() bool { + if self.tag != DbValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self DbValue) Int8() int8 { + if self.tag != DbValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self DbValue) Int16() int16 { + if self.tag != DbValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self DbValue) Int32() int32 { + if self.tag != DbValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self DbValue) Int64() int64 { + if self.tag != DbValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self DbValue) Uint8() uint8 { + if self.tag != DbValueUint8 { + panic("tag mismatch") + } + return self.value.(uint8) +} +func (self DbValue) Uint16() uint16 { + if self.tag != DbValueUint16 { + panic("tag mismatch") + } + return self.value.(uint16) +} +func (self DbValue) Uint32() uint32 { + if self.tag != DbValueUint32 { + panic("tag mismatch") + } + return self.value.(uint32) +} +func (self DbValue) Uint64() uint64 { + if self.tag != DbValueUint64 { + panic("tag mismatch") + } + return self.value.(uint64) +} +func (self DbValue) Floating32() float32 { + if self.tag != DbValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self DbValue) Floating64() float64 { + if self.tag != DbValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self DbValue) Str() string { + if self.tag != DbValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self DbValue) Binary() []uint8 { + if self.tag != DbValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeDbValueBoolean(value bool) DbValue { + return DbValue{DbValueBoolean, value} +} +func MakeDbValueInt8(value int8) DbValue { + return DbValue{DbValueInt8, value} +} +func MakeDbValueInt16(value int16) DbValue { + return DbValue{DbValueInt16, value} +} +func MakeDbValueInt32(value int32) DbValue { + return DbValue{DbValueInt32, value} +} +func MakeDbValueInt64(value int64) DbValue { + return DbValue{DbValueInt64, value} +} +func MakeDbValueUint8(value uint8) DbValue { + return DbValue{DbValueUint8, value} +} +func MakeDbValueUint16(value uint16) DbValue { + return DbValue{DbValueUint16, value} +} +func MakeDbValueUint32(value uint32) DbValue { + return DbValue{DbValueUint32, value} +} +func MakeDbValueUint64(value uint64) DbValue { + return DbValue{DbValueUint64, value} +} +func MakeDbValueFloating32(value float32) DbValue { + return DbValue{DbValueFloating32, value} +} +func MakeDbValueFloating64(value float64) DbValue { + return DbValue{DbValueFloating64, value} +} +func MakeDbValueStr(value string) DbValue { + return DbValue{DbValueStr, value} +} +func MakeDbValueBinary(value []uint8) DbValue { + return DbValue{DbValueBinary, value} +} +func MakeDbValueDbNull() DbValue { + return DbValue{DbValueDbNull, nil} +} +func MakeDbValueUnsupported() DbValue { + return DbValue{DbValueUnsupported, nil} +} + +const ( + ParameterValueBoolean uint8 = 0 + ParameterValueInt8 uint8 = 1 + ParameterValueInt16 uint8 = 2 + ParameterValueInt32 uint8 = 3 + ParameterValueInt64 uint8 = 4 + ParameterValueUint8 uint8 = 5 + ParameterValueUint16 uint8 = 6 + ParameterValueUint32 uint8 = 7 + ParameterValueUint64 uint8 = 8 + ParameterValueFloating32 uint8 = 9 + ParameterValueFloating64 uint8 = 10 + ParameterValueStr uint8 = 11 + ParameterValueBinary uint8 = 12 + ParameterValueDbNull uint8 = 13 +) + +// Values used in parameterized queries +type ParameterValue struct { + tag uint8 + value any +} + +func (self ParameterValue) Tag() uint8 { + return self.tag +} + +func (self ParameterValue) Boolean() bool { + if self.tag != ParameterValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self ParameterValue) Int8() int8 { + if self.tag != ParameterValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self ParameterValue) Int16() int16 { + if self.tag != ParameterValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self ParameterValue) Int32() int32 { + if self.tag != ParameterValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self ParameterValue) Int64() int64 { + if self.tag != ParameterValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self ParameterValue) Uint8() uint8 { + if self.tag != ParameterValueUint8 { + panic("tag mismatch") + } + return self.value.(uint8) +} +func (self ParameterValue) Uint16() uint16 { + if self.tag != ParameterValueUint16 { + panic("tag mismatch") + } + return self.value.(uint16) +} +func (self ParameterValue) Uint32() uint32 { + if self.tag != ParameterValueUint32 { + panic("tag mismatch") + } + return self.value.(uint32) +} +func (self ParameterValue) Uint64() uint64 { + if self.tag != ParameterValueUint64 { + panic("tag mismatch") + } + return self.value.(uint64) +} +func (self ParameterValue) Floating32() float32 { + if self.tag != ParameterValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self ParameterValue) Floating64() float64 { + if self.tag != ParameterValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self ParameterValue) Str() string { + if self.tag != ParameterValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self ParameterValue) Binary() []uint8 { + if self.tag != ParameterValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeParameterValueBoolean(value bool) ParameterValue { + return ParameterValue{ParameterValueBoolean, value} +} +func MakeParameterValueInt8(value int8) ParameterValue { + return ParameterValue{ParameterValueInt8, value} +} +func MakeParameterValueInt16(value int16) ParameterValue { + return ParameterValue{ParameterValueInt16, value} +} +func MakeParameterValueInt32(value int32) ParameterValue { + return ParameterValue{ParameterValueInt32, value} +} +func MakeParameterValueInt64(value int64) ParameterValue { + return ParameterValue{ParameterValueInt64, value} +} +func MakeParameterValueUint8(value uint8) ParameterValue { + return ParameterValue{ParameterValueUint8, value} +} +func MakeParameterValueUint16(value uint16) ParameterValue { + return ParameterValue{ParameterValueUint16, value} +} +func MakeParameterValueUint32(value uint32) ParameterValue { + return ParameterValue{ParameterValueUint32, value} +} +func MakeParameterValueUint64(value uint64) ParameterValue { + return ParameterValue{ParameterValueUint64, value} +} +func MakeParameterValueFloating32(value float32) ParameterValue { + return ParameterValue{ParameterValueFloating32, value} +} +func MakeParameterValueFloating64(value float64) ParameterValue { + return ParameterValue{ParameterValueFloating64, value} +} +func MakeParameterValueStr(value string) ParameterValue { + return ParameterValue{ParameterValueStr, value} +} +func MakeParameterValueBinary(value []uint8) ParameterValue { + return ParameterValue{ParameterValueBinary, value} +} +func MakeParameterValueDbNull() ParameterValue { + return ParameterValue{ParameterValueDbNull, nil} +} + +// A database column +type Column struct { + Name string + DataType DbDataType +} + +// A database row +type Row = []DbValue + +// A set of database rows +type RowSet struct { + Columns []Column + Rows [][]DbValue +} diff --git a/v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go new file mode 100644 index 00000000..fca32af0 --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go @@ -0,0 +1,811 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_redis + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + // An invalid address string + ErrorInvalidAddress uint8 = 0 + // There are too many open connections + ErrorTooManyConnections uint8 = 1 + // A retrieved value was not of the correct type + ErrorTypeError uint8 = 2 + // Some other error occurred + ErrorOther uint8 = 3 +) + +// Errors related to interacting with Redis +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorInvalidAddress() Error { + return Error{ErrorInvalidAddress, nil} +} +func MakeErrorTooManyConnections() Error { + return Error{ErrorTooManyConnections, nil} +} +func MakeErrorTypeError() Error { + return Error{ErrorTypeError, nil} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +// The message payload. +type Payload = []uint8 + +const ( + RedisParameterInt64 uint8 = 0 + RedisParameterBinary uint8 = 1 +) + +// A parameter type for the general-purpose `execute` function. +type RedisParameter struct { + tag uint8 + value any +} + +func (self RedisParameter) Tag() uint8 { + return self.tag +} + +func (self RedisParameter) Int64() int64 { + if self.tag != RedisParameterInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self RedisParameter) Binary() []uint8 { + if self.tag != RedisParameterBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeRedisParameterInt64(value int64) RedisParameter { + return RedisParameter{RedisParameterInt64, value} +} +func MakeRedisParameterBinary(value []uint8) RedisParameter { + return RedisParameter{RedisParameterBinary, value} +} + +const ( + RedisResultNil uint8 = 0 + RedisResultStatus uint8 = 1 + RedisResultInt64 uint8 = 2 + RedisResultBinary uint8 = 3 +) + +// A return type for the general-purpose `execute` function. +type RedisResult struct { + tag uint8 + value any +} + +func (self RedisResult) Tag() uint8 { + return self.tag +} + +func (self RedisResult) Status() string { + if self.tag != RedisResultStatus { + panic("tag mismatch") + } + return self.value.(string) +} +func (self RedisResult) Int64() int64 { + if self.tag != RedisResultInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self RedisResult) Binary() []uint8 { + if self.tag != RedisResultBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeRedisResultNil() RedisResult { + return RedisResult{RedisResultNil, nil} +} +func MakeRedisResultStatus(value string) RedisResult { + return RedisResult{RedisResultStatus, value} +} +func MakeRedisResultInt64(value int64) RedisResult { + return RedisResult{RedisResultInt64, value} +} +func MakeRedisResultBinary(value []uint8) RedisResult { + return RedisResult{RedisResultBinary, value} +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) + var result wit_types.Result[*Connection, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.publish +func wasm_import_method_connection_publish(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Publish(channel string, payload []uint8) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(channel)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + wasm_import_method_connection_publish((self).Handle(), uintptr(utf8), uint32(len(channel)), uintptr(data), uint32(len(payload)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.get +func wasm_import_method_connection_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Connection) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_connection_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Option[[]uint8], Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[[]uint8]() + case 1: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + option = wit_types.Some[[]uint8](value) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.set +func wasm_import_method_connection_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_method_connection_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.incr +func wasm_import_method_connection_incr(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Connection) Incr(key string) wit_types.Result[int64, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_connection_incr((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[int64, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[int64, Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[int64, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.del +func wasm_import_method_connection_del(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Connection) Del(keys []string) wit_types.Result[uint32, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + slice := keys + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf8 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf8) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8))) + + } + + wasm_import_method_connection_del((self).Handle(), uintptr(result), length, returnArea) + var result0 wit_types.Result[uint32, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result0 = wit_types.Err[uint32, Error](variant) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.sadd +func wasm_import_method_connection_sadd(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Sadd(key string, values []string) wit_types.Result[uint32, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + slice := values + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf80 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + + } + + wasm_import_method_connection_sadd((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(result), length, returnArea) + var result1 wit_types.Result[uint32, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result1 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result1 = wit_types.Err[uint32, Error](variant) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.smembers +func wasm_import_method_connection_smembers(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Connection) Smembers(key string) wit_types.Result[[]string, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_connection_smembers((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result1 wit_types.Result[[]string, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result1 = wit_types.Ok[[]string, Error](result) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result1 = wit_types.Err[[]string, Error](variant) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.srem +func wasm_import_method_connection_srem(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Srem(key string, values []string) wit_types.Result[uint32, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + slice := values + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf80 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + + } + + wasm_import_method_connection_srem((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(result), length, returnArea) + var result1 wit_types.Result[uint32, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result1 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorInvalidAddress() + + case 1: + + variant = MakeErrorTooManyConnections() + + case 2: + + variant = MakeErrorTypeError() + + case 3: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result1 = wit_types.Err[uint32, Error](variant) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.execute +func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Execute(command string, arguments []RedisParameter) wit_types.Result[[]RedisResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(command)) + pinner.Pin(utf8) + slice := arguments + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result, index*(8+2*4)) + + switch element.Tag() { + case RedisParameterInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case RedisParameterBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(command)), uintptr(result), length, returnArea) + var result4 wit_types.Result[[]RedisResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([]RedisResult, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(8+2*4)) + var variant RedisResult + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = MakeRedisResultNil() + + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeRedisResultStatus(value) + + case 2: + + variant = MakeRedisResultInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 3: + value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeRedisResultBinary(value0) + + default: + panic("unreachable") + } + + result1 = append(result1, variant) + } + + result4 = wit_types.Ok[[]RedisResult, Error](result1) + case 1: + var variant3 Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant3 = MakeErrorInvalidAddress() + + case 1: + + variant3 = MakeErrorTooManyConnections() + + case 2: + + variant3 = MakeErrorTypeError() + + case 3: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant3 = MakeErrorOther(value2) + + default: + panic("unreachable") + } + + result4 = wit_types.Err[[]RedisResult, Error](variant3) + default: + panic("unreachable") + } + result5 := result4 + return result5 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go new file mode 100644 index 00000000..df77da17 --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go @@ -0,0 +1,396 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_sqlite + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +// A handle to an open sqlite instance +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +const ( + // The host does not recognize the database name requested. + ErrorNoSuchDatabase uint8 = 0 + // The requesting component does not have access to the specified database (which may or may not exist). + ErrorAccessDenied uint8 = 1 + // The provided connection is not valid + ErrorInvalidConnection uint8 = 2 + // The database has reached its capacity + ErrorDatabaseFull uint8 = 3 + // Some implementation-specific error has occurred (e.g. I/O) + ErrorIo uint8 = 4 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Io() string { + if self.tag != ErrorIo { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorNoSuchDatabase() Error { + return Error{ErrorNoSuchDatabase, nil} +} +func MakeErrorAccessDenied() Error { + return Error{ErrorAccessDenied, nil} +} +func MakeErrorInvalidConnection() Error { + return Error{ErrorInvalidConnection, nil} +} +func MakeErrorDatabaseFull() Error { + return Error{ErrorDatabaseFull, nil} +} +func MakeErrorIo(value string) Error { + return Error{ErrorIo, value} +} + +const ( + ValueInteger uint8 = 0 + ValueReal uint8 = 1 + ValueText uint8 = 2 + ValueBlob uint8 = 3 + ValueNull uint8 = 4 +) + +// A single column's result from a database query +type Value struct { + tag uint8 + value any +} + +func (self Value) Tag() uint8 { + return self.tag +} + +func (self Value) Integer() int64 { + if self.tag != ValueInteger { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self Value) Real() float64 { + if self.tag != ValueReal { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self Value) Text() string { + if self.tag != ValueText { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Value) Blob() []uint8 { + if self.tag != ValueBlob { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeValueInteger(value int64) Value { + return Value{ValueInteger, value} +} +func MakeValueReal(value float64) Value { + return Value{ValueReal, value} +} +func MakeValueText(value string) Value { + return Value{ValueText, value} +} +func MakeValueBlob(value []uint8) Value { + return Value{ValueBlob, value} +} +func MakeValueNull() Value { + return Value{ValueNull, nil} +} + +// A set of values for each of the columns in a query-result +type RowResult struct { + Values []Value +} + +// A result of a query +type QueryResult struct { + // The names of the columns retrieved in the query + Columns []string + // the row results each containing the values for all the columns for a given row + Rows []RowResult +} + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func ConnectionOpen(database string) wit_types.Result[*Connection, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(database)) + pinner.Pin(utf8) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(database)), returnArea) + var result wit_types.Result[*Connection, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchDatabase() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + + variant = MakeErrorInvalidConnection() + + case 3: + + variant = MakeErrorDatabaseFull() + + case 4: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/sqlite@2.0.0 [method]connection.execute +func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Execute(statement string, parameters []Value) wit_types.Result[QueryResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := parameters + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result, index*(8+2*4)) + + switch element.Tag() { + case ValueInteger: + payload := element.Integer() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ValueReal: + payload := element.Real() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ValueText: + payload := element.Text() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case ValueBlob: + payload := element.Blob() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case ValueNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result), length, returnArea) + var result8 wit_types.Result[QueryResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result1 = append(result1, value) + } + + result5 := make([]RowResult, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result4 := make([]Value, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant Value + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = MakeValueInteger(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 1: + + variant = MakeValueReal(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 2: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeValueText(value2) + + case 3: + value3 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeValueBlob(value3) + + case 4: + + variant = MakeValueNull() + + default: + panic("unreachable") + } + + result4 = append(result4, variant) + } + + result5 = append(result5, RowResult{result4}) + } + + result8 = wit_types.Ok[QueryResult, Error](QueryResult{result1, result5}) + case 1: + var variant7 Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant7 = MakeErrorNoSuchDatabase() + + case 1: + + variant7 = MakeErrorAccessDenied() + + case 2: + + variant7 = MakeErrorInvalidConnection() + + case 3: + + variant7 = MakeErrorDatabaseFull() + + case 4: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant7 = MakeErrorIo(value6) + + default: + panic("unreachable") + } + + result8 = wit_types.Err[QueryResult, Error](variant7) + default: + panic("unreachable") + } + result9 := result8 + return result9 + +} diff --git a/v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go b/v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go new file mode 100644 index 00000000..c3366a4c --- /dev/null +++ b/v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go @@ -0,0 +1,151 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_2_0_0_variables + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + // The provided variable name is invalid. + ErrorInvalidName uint8 = 0 + // The provided variable is undefined. + ErrorUndefined uint8 = 1 + // A variables provider specific error has occurred. + ErrorProvider uint8 = 2 + // Some implementation-specific error has occurred. + ErrorOther uint8 = 3 +) + +// The set of errors which may be raised by functions in this interface. +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) InvalidName() string { + if self.tag != ErrorInvalidName { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Undefined() string { + if self.tag != ErrorUndefined { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Provider() string { + if self.tag != ErrorProvider { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorInvalidName(value string) Error { + return Error{ErrorInvalidName, value} +} +func MakeErrorUndefined(value string) Error { + return Error{ErrorUndefined, value} +} +func MakeErrorProvider(value string) Error { + return Error{ErrorProvider, value} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +//go:wasmimport fermyon:spin/variables@2.0.0 get +func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Get(name string) wit_types.Result[string, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + wasm_import_get(uintptr(utf8), uint32(len(name)), returnArea) + var result wit_types.Result[string, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[string, Error](value) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidName(value0) + + case 1: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorUndefined(value1) + + case 2: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorProvider(value2) + + case 3: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value3) + + default: + panic("unreachable") + } + + result = wit_types.Err[string, Error](variant) + default: + panic("unreachable") + } + result4 := result + return result4 + +} diff --git a/v3/internal/spin/postgres/v3.0.0/postgres/abi.go b/v3/internal/spin/postgres/v3.0.0/postgres/abi.go deleted file mode 100644 index e388ef69..00000000 --- a/v3/internal/spin/postgres/v3.0.0/postgres/abi.go +++ /dev/null @@ -1,26 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// TupleS32U8U8U8U8U8U32Shape is used for storage in variant or result types. -type TupleS32U8U8U8U8U8U32Shape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]{})]byte -} - -// ErrorShape is used for storage in variant or result types. -type ErrorShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(Error{})]byte -} - -// RowSetShape is used for storage in variant or result types. -type RowSetShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(RowSet{})]byte -} diff --git a/v3/internal/spin/postgres/v3.0.0/postgres/empty.s b/v3/internal/spin/postgres/v3.0.0/postgres/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/spin/postgres/v3.0.0/postgres/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go b/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go deleted file mode 100644 index 96304e3e..00000000 --- a/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wasm.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package postgres - -import ( - "go.bytecodealliance.org/cm" -) - -// This file contains wasmimport and wasmexport declarations for "spin:postgres@3.0.0". - -//go:wasmimport spin:postgres/postgres@3.0.0 [resource-drop]connection -//go:noescape -func wasmimport_ConnectionResourceDrop(self0 uint32) - -//go:wasmimport spin:postgres/postgres@3.0.0 [static]connection.open -//go:noescape -func wasmimport_ConnectionOpen(address0 *uint8, address1 uint32, result *cm.Result[ErrorShape, Connection, Error]) - -//go:wasmimport spin:postgres/postgres@3.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 spin:postgres/postgres@3.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/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go b/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go deleted file mode 100644 index fe0bd785..00000000 --- a/v3/internal/spin/postgres/v3.0.0/postgres/postgres.wit.go +++ /dev/null @@ -1,657 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package postgres represents the imported interface "spin:postgres/postgres@3.0.0". -package postgres - -import ( - "go.bytecodealliance.org/cm" -) - -// Error represents the variant "spin:postgres/postgres@3.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) -} - -var _ErrorStrings = [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 _ErrorStrings[v.Tag()] -} - -// DbDataType represents the enum "spin:postgres/postgres@3.0.0#db-data-type". -// -// Data types for a database column -// -// enum db-data-type { -// boolean, -// int8, -// int16, -// int32, -// int64, -// floating32, -// floating64, -// str, -// binary, -// date, -// time, -// datetime, -// timestamp, -// other -// } -type DbDataType uint8 - -const ( - DbDataTypeBoolean DbDataType = iota - DbDataTypeInt8 - DbDataTypeInt16 - DbDataTypeInt32 - DbDataTypeInt64 - DbDataTypeFloating32 - DbDataTypeFloating64 - DbDataTypeStr - DbDataTypeBinary - DbDataTypeDate - DbDataTypeTime - DbDataTypeDateTime - DbDataTypeTimestamp - DbDataTypeOther -) - -var _DbDataTypeStrings = [14]string{ - "boolean", - "int8", - "int16", - "int32", - "int64", - "floating32", - "floating64", - "str", - "binary", - "date", - "time", - "datetime", - "timestamp", - "other", -} - -// String implements [fmt.Stringer], returning the enum case name of e. -func (e DbDataType) String() string { - return _DbDataTypeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e DbDataType) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *DbDataType) UnmarshalText(text []byte) error { - return _DbDataTypeUnmarshalCase(e, text) -} - -var _DbDataTypeUnmarshalCase = cm.CaseUnmarshaler[DbDataType](_DbDataTypeStrings[:]) - -// DbValue represents the variant "spin:postgres/postgres@3.0.0#db-value". -// -// Database values -// -// variant db-value { -// boolean(bool), -// int8(s8), -// int16(s16), -// int32(s32), -// int64(s64), -// floating32(f32), -// floating64(f64), -// str(string), -// binary(list), -// date(tuple), -// time(tuple), -// datetime(tuple), -// timestamp(s64), -// db-null, -// unsupported, -// } -type DbValue cm.Variant[uint8, TupleS32U8U8U8U8U8U32Shape, 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) -} - -// DbValueFloating32 returns a [DbValue] of case "floating32". -func DbValueFloating32(data float32) DbValue { - return cm.New[DbValue](5, data) -} - -// Floating32 returns a non-nil *[float32] if [DbValue] represents the variant case "floating32". -func (self *DbValue) Floating32() *float32 { - return cm.Case[float32](self, 5) -} - -// DbValueFloating64 returns a [DbValue] of case "floating64". -func DbValueFloating64(data float64) DbValue { - return cm.New[DbValue](6, data) -} - -// Floating64 returns a non-nil *[float64] if [DbValue] represents the variant case "floating64". -func (self *DbValue) Floating64() *float64 { - return cm.Case[float64](self, 6) -} - -// DbValueStr returns a [DbValue] of case "str". -func DbValueStr(data string) DbValue { - return cm.New[DbValue](7, data) -} - -// Str returns a non-nil *[string] if [DbValue] represents the variant case "str". -func (self *DbValue) Str() *string { - return cm.Case[string](self, 7) -} - -// DbValueBinary returns a [DbValue] of case "binary". -func DbValueBinary(data cm.List[uint8]) DbValue { - return cm.New[DbValue](8, 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, 8) -} - -// DbValueDate returns a [DbValue] of case "date". -func DbValueDate(data cm.Tuple3[int32, uint8, uint8]) DbValue { - return cm.New[DbValue](9, data) -} - -// Date returns a non-nil *[cm.Tuple3[int32, uint8, uint8]] if [DbValue] represents the variant case "date". -func (self *DbValue) Date() *cm.Tuple3[int32, uint8, uint8] { - return cm.Case[cm.Tuple3[int32, uint8, uint8]](self, 9) -} - -// DbValueTime returns a [DbValue] of case "time". -// -// (year, month, day) -func DbValueTime(data cm.Tuple4[uint8, uint8, uint8, uint32]) DbValue { - return cm.New[DbValue](10, data) -} - -// Time returns a non-nil *[cm.Tuple4[uint8, uint8, uint8, uint32]] if [DbValue] represents the variant case "time". -func (self *DbValue) Time() *cm.Tuple4[uint8, uint8, uint8, uint32] { - return cm.Case[cm.Tuple4[uint8, uint8, uint8, uint32]](self, 10) -} - -// DbValueDateTime returns a [DbValue] of case "datetime". -// -// (hour, minute, second, nanosecond) -// Date-time types are always treated as UTC (without timezone info). -// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) -// tuple. -func DbValueDateTime(data cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) DbValue { - return cm.New[DbValue](11, data) -} - -// DateTime returns a non-nil *[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]] if [DbValue] represents the variant case "datetime". -func (self *DbValue) DateTime() *cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { - return cm.Case[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]](self, 11) -} - -// DbValueTimestamp returns a [DbValue] of case "timestamp". -// -// Unix timestamp (seconds since epoch) -func DbValueTimestamp(data int64) DbValue { - return cm.New[DbValue](12, data) -} - -// Timestamp returns a non-nil *[int64] if [DbValue] represents the variant case "timestamp". -func (self *DbValue) Timestamp() *int64 { - return cm.Case[int64](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 -} - -var _DbValueStrings = [15]string{ - "boolean", - "int8", - "int16", - "int32", - "int64", - "floating32", - "floating64", - "str", - "binary", - "date", - "time", - "datetime", - "timestamp", - "db-null", - "unsupported", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v DbValue) String() string { - return _DbValueStrings[v.Tag()] -} - -// ParameterValue represents the variant "spin:postgres/postgres@3.0.0#parameter-value". -// -// Values used in parameterized queries -// -// variant parameter-value { -// boolean(bool), -// int8(s8), -// int16(s16), -// int32(s32), -// int64(s64), -// floating32(f32), -// floating64(f64), -// str(string), -// binary(list), -// date(tuple), -// time(tuple), -// datetime(tuple), -// timestamp(s64), -// db-null, -// } -type ParameterValue cm.Variant[uint8, TupleS32U8U8U8U8U8U32Shape, 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) -} - -// ParameterValueFloating32 returns a [ParameterValue] of case "floating32". -func ParameterValueFloating32(data float32) ParameterValue { - return cm.New[ParameterValue](5, data) -} - -// Floating32 returns a non-nil *[float32] if [ParameterValue] represents the variant case "floating32". -func (self *ParameterValue) Floating32() *float32 { - return cm.Case[float32](self, 5) -} - -// ParameterValueFloating64 returns a [ParameterValue] of case "floating64". -func ParameterValueFloating64(data float64) ParameterValue { - return cm.New[ParameterValue](6, data) -} - -// Floating64 returns a non-nil *[float64] if [ParameterValue] represents the variant case "floating64". -func (self *ParameterValue) Floating64() *float64 { - return cm.Case[float64](self, 6) -} - -// ParameterValueStr returns a [ParameterValue] of case "str". -func ParameterValueStr(data string) ParameterValue { - return cm.New[ParameterValue](7, data) -} - -// Str returns a non-nil *[string] if [ParameterValue] represents the variant case "str". -func (self *ParameterValue) Str() *string { - return cm.Case[string](self, 7) -} - -// ParameterValueBinary returns a [ParameterValue] of case "binary". -func ParameterValueBinary(data cm.List[uint8]) ParameterValue { - return cm.New[ParameterValue](8, 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, 8) -} - -// ParameterValueDate returns a [ParameterValue] of case "date". -func ParameterValueDate(data cm.Tuple3[int32, uint8, uint8]) ParameterValue { - return cm.New[ParameterValue](9, data) -} - -// Date returns a non-nil *[cm.Tuple3[int32, uint8, uint8]] if [ParameterValue] represents the variant case "date". -func (self *ParameterValue) Date() *cm.Tuple3[int32, uint8, uint8] { - return cm.Case[cm.Tuple3[int32, uint8, uint8]](self, 9) -} - -// ParameterValueTime returns a [ParameterValue] of case "time". -// -// (year, month, day) -func ParameterValueTime(data cm.Tuple4[uint8, uint8, uint8, uint32]) ParameterValue { - return cm.New[ParameterValue](10, data) -} - -// Time returns a non-nil *[cm.Tuple4[uint8, uint8, uint8, uint32]] if [ParameterValue] represents the variant case "time". -func (self *ParameterValue) Time() *cm.Tuple4[uint8, uint8, uint8, uint32] { - return cm.Case[cm.Tuple4[uint8, uint8, uint8, uint32]](self, 10) -} - -// ParameterValueDateTime returns a [ParameterValue] of case "datetime". -// -// (hour, minute, second, nanosecond) -// Date-time types are always treated as UTC (without timezone info). -// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) -// tuple. -func ParameterValueDateTime(data cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) ParameterValue { - return cm.New[ParameterValue](11, data) -} - -// DateTime returns a non-nil *[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]] if [ParameterValue] represents the variant case "datetime". -func (self *ParameterValue) DateTime() *cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { - return cm.Case[cm.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]](self, 11) -} - -// ParameterValueTimestamp returns a [ParameterValue] of case "timestamp". -// -// Unix timestamp (seconds since epoch) -func ParameterValueTimestamp(data int64) ParameterValue { - return cm.New[ParameterValue](12, data) -} - -// Timestamp returns a non-nil *[int64] if [ParameterValue] represents the variant case "timestamp". -func (self *ParameterValue) Timestamp() *int64 { - return cm.Case[int64](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 -} - -var _ParameterValueStrings = [14]string{ - "boolean", - "int8", - "int16", - "int32", - "int64", - "floating32", - "floating64", - "str", - "binary", - "date", - "time", - "datetime", - "timestamp", - "db-null", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v ParameterValue) String() string { - return _ParameterValueStrings[v.Tag()] -} - -// Column represents the record "spin:postgres/postgres@3.0.0#column". -// -// A database column -// -// record column { -// name: string, -// data-type: db-data-type, -// } -type Column struct { - _ cm.HostLayout `json:"-"` - Name string `json:"name"` - DataType DbDataType `json:"data-type"` -} - -// Row represents the list "spin:postgres/postgres@3.0.0#row". -// -// A database row -// -// type row = list -type Row cm.List[DbValue] - -// RowSet represents the record "spin:postgres/postgres@3.0.0#row-set". -// -// A set of database rows -// -// record row-set { -// columns: list, -// rows: list, -// } -type RowSet struct { - _ cm.HostLayout `json:"-"` - Columns cm.List[Column] `json:"columns"` - Rows cm.List[Row] `json:"rows"` -} - -// Connection represents the imported resource "spin:postgres/postgres@3.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 -} - -// 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, Error]) { - address0, address1 := cm.LowerString(address) - wasmimport_ConnectionOpen((*uint8)(address0), (uint32)(address1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} - -// 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[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), (*ParameterValue)(params0), (uint32)(params1), &result) - return -} diff --git a/v3/internal/spin_postgres_postgres/wit_bindings.go b/v3/internal/spin_postgres_postgres/wit_bindings.go new file mode 100644 index 00000000..2735bced --- /dev/null +++ b/v3/internal/spin_postgres_postgres/wit_bindings.go @@ -0,0 +1,962 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package spin_postgres_postgres + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + ErrorConnectionFailed uint8 = 0 + ErrorBadParameter uint8 = 1 + ErrorQueryFailed uint8 = 2 + ErrorValueConversionFailed uint8 = 3 + ErrorOther uint8 = 4 +) + +// Errors related to interacting with a database. +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) ConnectionFailed() string { + if self.tag != ErrorConnectionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) BadParameter() string { + if self.tag != ErrorBadParameter { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) QueryFailed() string { + if self.tag != ErrorQueryFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) ValueConversionFailed() string { + if self.tag != ErrorValueConversionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorConnectionFailed(value string) Error { + return Error{ErrorConnectionFailed, value} +} +func MakeErrorBadParameter(value string) Error { + return Error{ErrorBadParameter, value} +} +func MakeErrorQueryFailed(value string) Error { + return Error{ErrorQueryFailed, value} +} +func MakeErrorValueConversionFailed(value string) Error { + return Error{ErrorValueConversionFailed, value} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +const ( + DbDataTypeBoolean uint8 = 0 + DbDataTypeInt8 uint8 = 1 + DbDataTypeInt16 uint8 = 2 + DbDataTypeInt32 uint8 = 3 + DbDataTypeInt64 uint8 = 4 + DbDataTypeFloating32 uint8 = 5 + DbDataTypeFloating64 uint8 = 6 + DbDataTypeStr uint8 = 7 + DbDataTypeBinary uint8 = 8 + DbDataTypeDate uint8 = 9 + DbDataTypeTime uint8 = 10 + DbDataTypeDatetime uint8 = 11 + DbDataTypeTimestamp uint8 = 12 + DbDataTypeOther uint8 = 13 +) + +// Data types for a database column +type DbDataType = uint8 + +const ( + DbValueBoolean uint8 = 0 + DbValueInt8 uint8 = 1 + DbValueInt16 uint8 = 2 + DbValueInt32 uint8 = 3 + DbValueInt64 uint8 = 4 + DbValueFloating32 uint8 = 5 + DbValueFloating64 uint8 = 6 + DbValueStr uint8 = 7 + DbValueBinary uint8 = 8 + DbValueDate uint8 = 9 + // (year, month, day) + DbValueTime uint8 = 10 + // (hour, minute, second, nanosecond) + // Date-time types are always treated as UTC (without timezone info). + // The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. + DbValueDatetime uint8 = 11 + // Unix timestamp (seconds since epoch) + DbValueTimestamp uint8 = 12 + DbValueDbNull uint8 = 13 + DbValueUnsupported uint8 = 14 +) + +// Database values +type DbValue struct { + tag uint8 + value any +} + +func (self DbValue) Tag() uint8 { + return self.tag +} + +func (self DbValue) Boolean() bool { + if self.tag != DbValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self DbValue) Int8() int8 { + if self.tag != DbValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self DbValue) Int16() int16 { + if self.tag != DbValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self DbValue) Int32() int32 { + if self.tag != DbValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self DbValue) Int64() int64 { + if self.tag != DbValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self DbValue) Floating32() float32 { + if self.tag != DbValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self DbValue) Floating64() float64 { + if self.tag != DbValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self DbValue) Str() string { + if self.tag != DbValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self DbValue) Binary() []uint8 { + if self.tag != DbValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} +func (self DbValue) Date() wit_types.Tuple3[int32, uint8, uint8] { + if self.tag != DbValueDate { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple3[int32, uint8, uint8]) +} +func (self DbValue) Time() wit_types.Tuple4[uint8, uint8, uint8, uint32] { + if self.tag != DbValueTime { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint32]) +} +func (self DbValue) Datetime() wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { + if self.tag != DbValueDatetime { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) +} +func (self DbValue) Timestamp() int64 { + if self.tag != DbValueTimestamp { + panic("tag mismatch") + } + return self.value.(int64) +} + +func MakeDbValueBoolean(value bool) DbValue { + return DbValue{DbValueBoolean, value} +} +func MakeDbValueInt8(value int8) DbValue { + return DbValue{DbValueInt8, value} +} +func MakeDbValueInt16(value int16) DbValue { + return DbValue{DbValueInt16, value} +} +func MakeDbValueInt32(value int32) DbValue { + return DbValue{DbValueInt32, value} +} +func MakeDbValueInt64(value int64) DbValue { + return DbValue{DbValueInt64, value} +} +func MakeDbValueFloating32(value float32) DbValue { + return DbValue{DbValueFloating32, value} +} +func MakeDbValueFloating64(value float64) DbValue { + return DbValue{DbValueFloating64, value} +} +func MakeDbValueStr(value string) DbValue { + return DbValue{DbValueStr, value} +} +func MakeDbValueBinary(value []uint8) DbValue { + return DbValue{DbValueBinary, value} +} +func MakeDbValueDate(value wit_types.Tuple3[int32, uint8, uint8]) DbValue { + return DbValue{DbValueDate, value} +} +func MakeDbValueTime(value wit_types.Tuple4[uint8, uint8, uint8, uint32]) DbValue { + return DbValue{DbValueTime, value} +} +func MakeDbValueDatetime(value wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) DbValue { + return DbValue{DbValueDatetime, value} +} +func MakeDbValueTimestamp(value int64) DbValue { + return DbValue{DbValueTimestamp, value} +} +func MakeDbValueDbNull() DbValue { + return DbValue{DbValueDbNull, nil} +} +func MakeDbValueUnsupported() DbValue { + return DbValue{DbValueUnsupported, nil} +} + +const ( + ParameterValueBoolean uint8 = 0 + ParameterValueInt8 uint8 = 1 + ParameterValueInt16 uint8 = 2 + ParameterValueInt32 uint8 = 3 + ParameterValueInt64 uint8 = 4 + ParameterValueFloating32 uint8 = 5 + ParameterValueFloating64 uint8 = 6 + ParameterValueStr uint8 = 7 + ParameterValueBinary uint8 = 8 + ParameterValueDate uint8 = 9 + // (year, month, day) + ParameterValueTime uint8 = 10 + // (hour, minute, second, nanosecond) + // Date-time types are always treated as UTC (without timezone info). + // The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. + ParameterValueDatetime uint8 = 11 + // Unix timestamp (seconds since epoch) + ParameterValueTimestamp uint8 = 12 + ParameterValueDbNull uint8 = 13 +) + +// Values used in parameterized queries +type ParameterValue struct { + tag uint8 + value any +} + +func (self ParameterValue) Tag() uint8 { + return self.tag +} + +func (self ParameterValue) Boolean() bool { + if self.tag != ParameterValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self ParameterValue) Int8() int8 { + if self.tag != ParameterValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self ParameterValue) Int16() int16 { + if self.tag != ParameterValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self ParameterValue) Int32() int32 { + if self.tag != ParameterValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self ParameterValue) Int64() int64 { + if self.tag != ParameterValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self ParameterValue) Floating32() float32 { + if self.tag != ParameterValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self ParameterValue) Floating64() float64 { + if self.tag != ParameterValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self ParameterValue) Str() string { + if self.tag != ParameterValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self ParameterValue) Binary() []uint8 { + if self.tag != ParameterValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} +func (self ParameterValue) Date() wit_types.Tuple3[int32, uint8, uint8] { + if self.tag != ParameterValueDate { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple3[int32, uint8, uint8]) +} +func (self ParameterValue) Time() wit_types.Tuple4[uint8, uint8, uint8, uint32] { + if self.tag != ParameterValueTime { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint32]) +} +func (self ParameterValue) Datetime() wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { + if self.tag != ParameterValueDatetime { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) +} +func (self ParameterValue) Timestamp() int64 { + if self.tag != ParameterValueTimestamp { + panic("tag mismatch") + } + return self.value.(int64) +} + +func MakeParameterValueBoolean(value bool) ParameterValue { + return ParameterValue{ParameterValueBoolean, value} +} +func MakeParameterValueInt8(value int8) ParameterValue { + return ParameterValue{ParameterValueInt8, value} +} +func MakeParameterValueInt16(value int16) ParameterValue { + return ParameterValue{ParameterValueInt16, value} +} +func MakeParameterValueInt32(value int32) ParameterValue { + return ParameterValue{ParameterValueInt32, value} +} +func MakeParameterValueInt64(value int64) ParameterValue { + return ParameterValue{ParameterValueInt64, value} +} +func MakeParameterValueFloating32(value float32) ParameterValue { + return ParameterValue{ParameterValueFloating32, value} +} +func MakeParameterValueFloating64(value float64) ParameterValue { + return ParameterValue{ParameterValueFloating64, value} +} +func MakeParameterValueStr(value string) ParameterValue { + return ParameterValue{ParameterValueStr, value} +} +func MakeParameterValueBinary(value []uint8) ParameterValue { + return ParameterValue{ParameterValueBinary, value} +} +func MakeParameterValueDate(value wit_types.Tuple3[int32, uint8, uint8]) ParameterValue { + return ParameterValue{ParameterValueDate, value} +} +func MakeParameterValueTime(value wit_types.Tuple4[uint8, uint8, uint8, uint32]) ParameterValue { + return ParameterValue{ParameterValueTime, value} +} +func MakeParameterValueDatetime(value wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) ParameterValue { + return ParameterValue{ParameterValueDatetime, value} +} +func MakeParameterValueTimestamp(value int64) ParameterValue { + return ParameterValue{ParameterValueTimestamp, value} +} +func MakeParameterValueDbNull() ParameterValue { + return ParameterValue{ParameterValueDbNull, nil} +} + +// A database column +type Column struct { + Name string + DataType DbDataType +} + +// A database row +type Row = []DbValue + +// A set of database rows +type RowSet struct { + Columns []Column + Rows [][]DbValue +} + +//go:wasmimport spin:postgres/postgres@3.0.0 [resource-drop]connection +func resourceDropConnection(handle int32) + +// A connection to a postgres database. +type Connection struct { + handle *wit_runtime.Handle +} + +func (self *Connection) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Connection) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Connection) Handle() int32 { + return self.handle.Use() +} + +func (self *Connection) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropConnection(handle) + } +} + +func ConnectionFromOwnHandle(handleValue int32) *Connection { + handle := wit_runtime.MakeHandle(handleValue) + value := &Connection{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropConnection(handleValue) + } + }, 0) + return value +} + +func ConnectionFromBorrowHandle(handleValue int32) *Connection { + return ConnectionFromOwnHandle(handleValue) +} + +//go:wasmimport spin:postgres/postgres@3.0.0 [static]connection.open +func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) + var result wit_types.Result[*Connection, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorConnectionFailed(value) + + case 1: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorBadParameter(value0) + + case 2: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorQueryFailed(value1) + + case 3: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorValueConversionFailed(value2) + + case 4: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value3) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Connection, Error](variant) + default: + panic("unreachable") + } + result4 := result + return result4 + +} + +//go:wasmimport spin:postgres/postgres@3.0.0 [method]connection.query +func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Query(statement string, params []ParameterValue) wit_types.Result[RowSet, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*24), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*24) + + switch element.Tag() { + case ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case ParameterValueDate: + payload := element.Date() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = (payload).F0 + *(*int8)(unsafe.Add(unsafe.Pointer(base), 12)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 13)) = int8(int32((payload).F2)) + + case ParameterValueTime: + payload := element.Time() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32((payload).F0)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 9)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 10)) = int8(int32((payload).F2)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 12)) = int32((payload).F3) + + case ParameterValueDatetime: + payload := element.Datetime() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = (payload).F0 + *(*int8)(unsafe.Add(unsafe.Pointer(base), 12)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 13)) = int8(int32((payload).F2)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 14)) = int8(int32((payload).F3)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 15)) = int8(int32((payload).F4)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 16)) = int8(int32((payload).F5)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 20)) = int32((payload).F6) + + case ParameterValueTimestamp: + payload := element.Timestamp() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result13 wit_types.Result[RowSet, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result2 := make([]Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result2 = append(result2, Column{value, uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))}) + } + + result6 := make([][]DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result5 := make([]DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*24) + var variant DbValue + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = MakeDbValueBoolean((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))) != 0)) + + case 1: + + variant = MakeDbValueInt8(int8(int8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 2: + + variant = MakeDbValueInt16(int16(int16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 3: + + variant = MakeDbValueInt32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 4: + + variant = MakeDbValueInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 5: + + variant = MakeDbValueFloating32(*(*float32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 6: + + variant = MakeDbValueFloating64(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 7: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeDbValueStr(value3) + + case 8: + value4 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeDbValueBinary(value4) + + case 9: + + variant = MakeDbValueDate(wit_types.Tuple3[int32, uint8, uint8]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13))))}) + + case 10: + + variant = MakeDbValueTime(wit_types.Tuple4[uint8, uint8, uint8, uint32]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 9)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 10)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 12)))}) + + case 11: + + variant = MakeDbValueDatetime(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 14)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 15)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 16)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 20)))}) + + case 12: + + variant = MakeDbValueTimestamp(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 13: + + variant = MakeDbValueDbNull() + + case 14: + + variant = MakeDbValueUnsupported() + + default: + panic("unreachable") + } + + result5 = append(result5, variant) + } + + result6 = append(result6, result5) + } + + result13 = wit_types.Ok[RowSet, Error](RowSet{result2, result6}) + case 1: + var variant12 Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = MakeErrorConnectionFailed(value7) + + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = MakeErrorBadParameter(value8) + + case 2: + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = MakeErrorQueryFailed(value9) + + case 3: + value10 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = MakeErrorValueConversionFailed(value10) + + case 4: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant12 = MakeErrorOther(value11) + + default: + panic("unreachable") + } + + result13 = wit_types.Err[RowSet, Error](variant12) + default: + panic("unreachable") + } + result14 := result13 + return result14 + +} + +//go:wasmimport spin:postgres/postgres@3.0.0 [method]connection.execute +func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Connection) Execute(statement string, params []ParameterValue) wit_types.Result[uint64, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := params + length := uint32(len(slice)) + result1 := wit_runtime.Allocate(pinner, uintptr(length*24), 8) + for index, element := range slice { + base := unsafe.Add(result1, index*24) + + switch element.Tag() { + case ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case ParameterValueDate: + payload := element.Date() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = (payload).F0 + *(*int8)(unsafe.Add(unsafe.Pointer(base), 12)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 13)) = int8(int32((payload).F2)) + + case ParameterValueTime: + payload := element.Time() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32((payload).F0)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 9)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 10)) = int8(int32((payload).F2)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 12)) = int32((payload).F3) + + case ParameterValueDatetime: + payload := element.Datetime() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = (payload).F0 + *(*int8)(unsafe.Add(unsafe.Pointer(base), 12)) = int8(int32((payload).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 13)) = int8(int32((payload).F2)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 14)) = int8(int32((payload).F3)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 15)) = int8(int32((payload).F4)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 16)) = int8(int32((payload).F5)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 20)) = int32((payload).F6) + + case ParameterValueTimestamp: + payload := element.Timestamp() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) + var result6 wit_types.Result[uint64, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result6 = wit_types.Ok[uint64, Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorConnectionFailed(value) + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorBadParameter(value2) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorQueryFailed(value3) + + case 3: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorValueConversionFailed(value4) + + case 4: + value5 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakeErrorOther(value5) + + default: + panic("unreachable") + } + + result6 = wit_types.Err[uint64, Error](variant) + default: + panic("unreachable") + } + result7 := result6 + return result7 + +} diff --git a/v3/internal/wasi/cli/v0.2.0/environment/empty.s b/v3/internal/wasi/cli/v0.2.0/environment/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/environment/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go b/v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go deleted file mode 100644 index 89bb596b..00000000 --- a/v3/internal/wasi/cli/v0.2.0/environment/environment.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package environment - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go deleted file mode 100644 index 3a3b6247..00000000 --- a/v3/internal/wasi/cli/v0.2.0/environment/environment.wit.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package environment represents the imported interface "wasi:cli/environment@0.2.0". -package environment - -import ( - "go.bytecodealliance.org/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 -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/wasi/cli/v0.2.0/exit/empty.s b/v3/internal/wasi/cli/v0.2.0/exit/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/exit/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go b/v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go deleted file mode 100644 index 849d5f50..00000000 --- a/v3/internal/wasi/cli/v0.2.0/exit/exit.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go deleted file mode 100644 index 947fa253..00000000 --- a/v3/internal/wasi/cli/v0.2.0/exit/exit.wit.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package exit represents the imported interface "wasi:cli/exit@0.2.0". -package exit - -import ( - "go.bytecodealliance.org/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 := (uint32)(cm.BoolToU32(status)) - wasmimport_Exit((uint32)(status0)) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/stderr/empty.s b/v3/internal/wasi/cli/v0.2.0/stderr/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stderr/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go b/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go deleted file mode 100644 index 462cf172..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go deleted file mode 100644 index 07957121..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go +++ /dev/null @@ -1,25 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" -) - -// 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 OutputStream) { - result0 := wasmimport_GetStderr() - result = cm.Reinterpret[OutputStream]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/stdin/empty.s b/v3/internal/wasi/cli/v0.2.0/stdin/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdin/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go b/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go deleted file mode 100644 index 374eb253..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go deleted file mode 100644 index 96dbc47e..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go +++ /dev/null @@ -1,25 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" -) - -// 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 InputStream) { - result0 := wasmimport_GetStdin() - result = cm.Reinterpret[InputStream]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/stdout/empty.s b/v3/internal/wasi/cli/v0.2.0/stdout/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdout/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go b/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go deleted file mode 100644 index 68e4a3da..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go deleted file mode 100644 index 5e4487d5..00000000 --- a/v3/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go +++ /dev/null @@ -1,25 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" -) - -// 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 OutputStream) { - result0 := wasmimport_GetStdout() - result = cm.Reinterpret[OutputStream]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-input/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go deleted file mode 100644 index 1df3794f..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go deleted file mode 100644 index fa12e90c..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} diff --git a/v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-output/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go deleted file mode 100644 index fb35fc41..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go deleted file mode 100644 index 199e0cc0..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} diff --git a/v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stderr/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go deleted file mode 100644 index be9af72f..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package terminalstderr - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go deleted file mode 100644 index e62c6a51..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go +++ /dev/null @@ -1,30 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-output" - "go.bytecodealliance.org/cm" -) - -// 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 -// allowing further interaction with it. -// -// get-terminal-stderr: func() -> option -// -//go:nosplit -func GetTerminalStderr() (result cm.Option[TerminalOutput]) { - wasmimport_GetTerminalStderr(&result) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdin/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go deleted file mode 100644 index e3b3ac61..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package terminalstdin - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go deleted file mode 100644 index fc4c6f37..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go +++ /dev/null @@ -1,30 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-input" - "go.bytecodealliance.org/cm" -) - -// 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 -// allowing further interaction with it. -// -// get-terminal-stdin: func() -> option -// -//go:nosplit -func GetTerminalStdin() (result cm.Option[TerminalInput]) { - wasmimport_GetTerminalStdin(&result) - return -} diff --git a/v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdout/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go deleted file mode 100644 index fa750ad9..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package terminalstdout - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go deleted file mode 100644 index 0b8eea9f..00000000 --- a/v3/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go +++ /dev/null @@ -1,30 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/cli/v0.2.0/terminal-output" - "go.bytecodealliance.org/cm" -) - -// 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 -// allowing further interaction with it. -// -// get-terminal-stdout: func() -> option -// -//go:nosplit -func GetTerminalStdout() (result cm.Option[TerminalOutput]) { - wasmimport_GetTerminalStdout(&result) - return -} diff --git a/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go deleted file mode 100644 index 36a1720a..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// 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/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go deleted file mode 100644 index e70e42fd..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go +++ /dev/null @@ -1,102 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "go.bytecodealliance.org/cm" -) - -// 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 -// 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 -} - -// 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 -} - -// 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 Pollable) { - when0 := (uint64)(when) - result0 := wasmimport_SubscribeInstant((uint64)(when0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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 Pollable) { - when0 := (uint64)(when) - result0 := wasmimport_SubscribeDuration((uint64)(when0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s b/v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/wall-clock/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go b/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go deleted file mode 100644 index 321ff3f1..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// 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/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go b/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go deleted file mode 100644 index 9c0a9684..00000000 --- a/v3/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". -// -// WASI Wall Clock is a clock API intended to let users query the current -// time. The name "wall" makes an analogy to a "clock on the wall", which -// is not necessarily monotonic as it may be reset. -// -// It is intended to be portable at least between Unix-family platforms and -// Windows. -// -// A wall clock is a clock which measures the date and time according to -// some external reference. -// -// External references may be reset, so this clock is not necessarily -// monotonic, making it unsuitable for measuring elapsed time. -// -// It is intended for reporting the current date and time for humans. -package wallclock - -import ( - "go.bytecodealliance.org/cm" -) - -// DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". -// -// A time and date in seconds plus nanoseconds. -// -// record datetime { -// seconds: u64, -// nanoseconds: u32, -// } -type DateTime struct { - _ cm.HostLayout `json:"-"` - Seconds uint64 `json:"seconds"` - Nanoseconds uint32 `json:"nanoseconds"` -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go deleted file mode 100644 index b7ad11d2..00000000 --- a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package store - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// OptionStringShape is used for storage in variant or result types. -type OptionStringShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(cm.Option[string]{})]byte -} - -// ErrorShape is used for storage in variant or result types. -type ErrorShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(Error{})]byte -} diff --git a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go deleted file mode 100644 index abc3b560..00000000 --- a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package store - -import ( - "go.bytecodealliance.org/cm" -) - -// This file contains wasmimport and wasmexport declarations for "wasi:config@0.2.0-draft-2024-09-27". - -//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get -//go:noescape -func wasmimport_Get(key0 *uint8, key1 uint32, result *cm.Result[OptionStringShape, cm.Option[string], Error]) - -//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get-all -//go:noescape -func wasmimport_GetAll(result *cm.Result[ErrorShape, cm.List[[2]string], Error]) diff --git a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go b/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go deleted file mode 100644 index 15909a1a..00000000 --- a/v3/internal/wasi/config/v0.2.0-draft-2024-09-27/store/store.wit.go +++ /dev/null @@ -1,92 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package store represents the imported interface "wasi:config/store@0.2.0-draft-2024-09-27". -package store - -import ( - "go.bytecodealliance.org/cm" -) - -// Error represents the variant "wasi:config/store@0.2.0-draft-2024-09-27#error". -// -// An error type that encapsulates the different errors that can occur fetching configuration -// values. -// -// variant error { -// upstream(string), -// io(string), -// } -type Error cm.Variant[uint8, string, string] - -// ErrorUpstream returns a [Error] of case "upstream". -// -// This indicates an error from an "upstream" config source. -// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue -// buckets, etc), -// the error message is a string. -func ErrorUpstream(data string) Error { - return cm.New[Error](0, data) -} - -// Upstream returns a non-nil *[string] if [Error] represents the variant case "upstream". -func (self *Error) Upstream() *string { - return cm.Case[string](self, 0) -} - -// ErrorIO returns a [Error] of case "io". -// -// This indicates an error from an I/O operation. -// As this could be almost _anything_ (such as a file read, network connection, etc), -// the error message is a string. -// Depending on how this ends up being consumed, -// we may consider moving this to use the `wasi:io/error` type instead. -// For simplicity right now in supporting multiple implementations, it is being left -// as a string. -func ErrorIO(data string) Error { - return cm.New[Error](1, data) -} - -// IO returns a non-nil *[string] if [Error] represents the variant case "io". -func (self *Error) IO() *string { - return cm.Case[string](self, 1) -} - -var _ErrorStrings = [2]string{ - "upstream", - "io", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Error) String() string { - return _ErrorStrings[v.Tag()] -} - -// Get represents the imported function "get". -// -// Gets a configuration value of type `string` associated with the `key`. -// -// The value is returned as an `option`. If the key is not found, -// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned. -// -// get: func(key: string) -> result, error> -// -//go:nosplit -func Get(key string) (result cm.Result[OptionStringShape, cm.Option[string], Error]) { - key0, key1 := cm.LowerString(key) - wasmimport_Get((*uint8)(key0), (uint32)(key1), &result) - return -} - -// GetAll represents the imported function "get-all". -// -// Gets a list of configuration key-value pairs of type `string`. -// -// If an error occurs, an `Err(error)` is returned. -// -// get-all: func() -> result>, error> -// -//go:nosplit -func GetAll() (result cm.Result[ErrorShape, cm.List[[2]string], Error]) { - wasmimport_GetAll(&result) - return -} diff --git a/v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s b/v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/preopens/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go b/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go deleted file mode 100644 index 1bcd416a..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package preopens - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go deleted file mode 100644 index a54013a0..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go +++ /dev/null @@ -1,26 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/filesystem/v0.2.0/types" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// get-directories: func() -> list> -// -//go:nosplit -func GetDirectories() (result cm.List[cm.Tuple[Descriptor, string]]) { - wasmimport_GetDirectories(&result) - return -} diff --git a/v3/internal/wasi/filesystem/v0.2.0/types/abi.go b/v3/internal/wasi/filesystem/v0.2.0/types/abi.go deleted file mode 100644 index f9ca50b6..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/types/abi.go +++ /dev/null @@ -1,50 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package types - -import ( - wallclock "github.com/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/wall-clock" - "go.bytecodealliance.org/cm" - "unsafe" -) - -// 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 -} - -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(*cm.Case[DateTime](&v, 2)) - f1 = (uint64)(v1) - f2 = (uint32)(v2) - } - return -} - -// 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/v3/internal/wasi/filesystem/v0.2.0/types/empty.s b/v3/internal/wasi/filesystem/v0.2.0/types/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/types/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go b/v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go deleted file mode 100644 index b97dad84..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/types/types.wasm.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package types - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go deleted file mode 100644 index 6885fc45..00000000 --- a/v3/internal/wasi/filesystem/v0.2.0/types/types.wit.go +++ /dev/null @@ -1,1305 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/wall-clock" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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 _DescriptorTypeStrings = [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 _DescriptorTypeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e DescriptorType) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *DescriptorType) UnmarshalText(text []byte) error { - return _DescriptorTypeUnmarshalCase(e, text) -} - -var _DescriptorTypeUnmarshalCase = cm.CaseUnmarshaler[DescriptorType](_DescriptorTypeStrings[:]) - -// 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 { - _ cm.HostLayout `json:"-"` - // File type. - Type DescriptorType `json:"type"` - - // Number of hard links to the file. - LinkCount LinkCount `json:"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 `json:"size"` - - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - DataAccessTimestamp cm.Option[DateTime] `json:"data-access-timestamp"` - - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. - DataModificationTimestamp cm.Option[DateTime] `json:"data-modification-timestamp"` - - // 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[DateTime] `json:"status-change-timestamp"` -} - -// 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, DateTime, 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 DateTime) NewTimestamp { - return cm.New[NewTimestamp](2, data) -} - -// 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 _NewTimestampStrings = [3]string{ - "no-change", - "now", - "timestamp", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v NewTimestamp) String() string { - return _NewTimestampStrings[v.Tag()] -} - -// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". -// -// A directory entry. -// -// record directory-entry { -// %type: descriptor-type, -// name: string, -// } -type DirectoryEntry struct { - _ cm.HostLayout `json:"-"` - // The type of the file referred to by this directory entry. - Type DescriptorType `json:"type"` - - // The name of the object. - Name string `json:"name"` -} - -// 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 _ErrorCodeStrings = [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 _ErrorCodeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e ErrorCode) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *ErrorCode) UnmarshalText(text []byte) error { - return _ErrorCodeUnmarshalCase(e, text) -} - -var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:]) - -// 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 _AdviceStrings = [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 _AdviceStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e Advice) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *Advice) UnmarshalText(text []byte) error { - return _AdviceUnmarshalCase(e, text) -} - -var _AdviceUnmarshalCase = cm.CaseUnmarshaler[Advice](_AdviceStrings[:]) - -// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". -// -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -// -// record metadata-hash-value { -// lower: u64, -// upper: u64, -// } -type MetadataHashValue struct { - _ cm.HostLayout `json:"-"` - // 64 bits of a 128-bit hash value. - Lower uint64 `json:"lower"` - - // Another 64 bits of a 128-bit hash value. - Upper uint64 `json:"upper"` -} - -// 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 -} - -// 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 -} - -// 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[OutputStream, OutputStream, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 = (bool)(cm.U32ToBool((uint32)(result0))) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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[InputStream, InputStream, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - offset0 := (uint64)(offset) - wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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[OutputStream, OutputStream, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - offset0 := (uint64)(offset) - wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) - return -} - -// 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 -} - -// 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 -} - -// 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 Error) (result cm.Option[ErrorCode]) { - err0 := cm.Reinterpret[uint32](err) - wasmimport_FilesystemErrorCode((uint32)(err0), &result) - return -} diff --git a/v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s b/v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/http/v0.2.0/incoming-handler/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go deleted file mode 100644 index 673ccb48..00000000 --- a/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.exports.go +++ /dev/null @@ -1,22 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package incominghandler - -// 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 IncomingRequest, responseOut ResponseOutparam) -} diff --git a/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go deleted file mode 100644 index eae429f3..00000000 --- a/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wasm.go +++ /dev/null @@ -1,18 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package incominghandler - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go b/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go deleted file mode 100644 index b1d69596..00000000 --- a/v3/internal/wasi/http/v0.2.0/incoming-handler/incoming-handler.wit.go +++ /dev/null @@ -1,21 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" -) - -// 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/v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go deleted file mode 100644 index cdc17d0d..00000000 --- a/v3/internal/wasi/http/v0.2.0/outgoing-handler/abi.go +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package outgoinghandler - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// ErrorCodeShape is used for storage in variant or result types. -type ErrorCodeShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(ErrorCode{})]byte -} - -func lower_OptionRequestOptions(v cm.Option[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/v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s b/v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/http/v0.2.0/outgoing-handler/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go deleted file mode 100644 index 6b3f3828..00000000 --- a/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package outgoinghandler - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go b/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go deleted file mode 100644 index 6a4190e8..00000000 --- a/v3/internal/wasi/http/v0.2.0/outgoing-handler/outgoing-handler.wit.go +++ /dev/null @@ -1,56 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/http/v0.2.0/types" - "go.bytecodealliance.org/cm" -) - -// 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 -// 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 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 -} diff --git a/v3/internal/wasi/http/v0.2.0/types/abi.go b/v3/internal/wasi/http/v0.2.0/types/abi.go deleted file mode 100644 index 6ffb1fdd..00000000 --- a/v3/internal/wasi/http/v0.2.0/types/abi.go +++ /dev/null @@ -1,264 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package types - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// OptionFieldSizePayloadShape is used for storage in variant or result types. -type OptionFieldSizePayloadShape struct { - _ cm.HostLayout - 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(*cm.Case[string](&v, 9)) - 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(*cm.Case[string](&v, 2)) - 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[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 { - _ cm.HostLayout - 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(*cm.Case[DNSErrorPayload](&v, 1)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - f4 = (uint32)(v4) - f5 = (uint32)(v5) - case 14: // TLS-alert-received - v1, v2, v3, v4, v5 := lower_TLSAlertReceivedPayload(*cm.Case[TLSAlertReceivedPayload](&v, 14)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - f3 = (uint32)(v3) - f4 = (uint32)(cm.PointerToU32(v4)) - f5 = (uint32)(v5) - case 17: // HTTP-request-body-size - v1, v2 := lower_OptionU64(*cm.Case[cm.Option[uint64]](&v, 17)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 21: // HTTP-request-header-section-size - v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 21)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 22: // HTTP-request-header-size - v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*cm.Case[cm.Option[FieldSizePayload]](&v, 22)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - f3 = (uint32)(cm.PointerToU32(v3)) - f4 = (uint32)(v4) - f5 = (uint32)(v5) - f6 = (uint32)(v6) - case 23: // HTTP-request-trailer-section-size - v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 23)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 24: // HTTP-request-trailer-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 24)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - f4 = (uint32)(v4) - f5 = (uint32)(v5) - case 26: // HTTP-response-header-section-size - v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 26)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 27: // HTTP-response-header-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 27)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - f4 = (uint32)(v4) - f5 = (uint32)(v5) - case 28: // HTTP-response-body-size - v1, v2 := lower_OptionU64(*cm.Case[cm.Option[uint64]](&v, 28)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 29: // HTTP-response-trailer-section-size - v1, v2 := lower_OptionU32(*cm.Case[cm.Option[uint32]](&v, 29)) - f1 = (uint32)(v1) - f2 = (uint64)(v2) - case 30: // HTTP-response-trailer-size - v1, v2, v3, v4, v5 := lower_FieldSizePayload(*cm.Case[FieldSizePayload](&v, 30)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - f4 = (uint32)(v4) - f5 = (uint32)(v5) - case 31: // HTTP-response-transfer-coding - v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 31)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - case 32: // HTTP-response-content-coding - v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 32)) - f1 = (uint32)(v1) - f2 = (uint64)(cm.PointerToU64(v2)) - f3 = (uint32)(v3) - case 38: // internal-error - v1, v2, v3 := lower_OptionString(*cm.Case[cm.Option[string]](&v, 38)) - f1 = (uint32)(v1) - f2 = (uint64)(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 -} - -func lower_OptionTrailers(v cm.Option[Trailers]) (f0 uint32, f1 uint32) { - some := v.Some() - if some != nil { - f0 = 1 - v1 := cm.Reinterpret[uint32](*some) - f1 = (uint32)(v1) - } - return -} diff --git a/v3/internal/wasi/http/v0.2.0/types/empty.s b/v3/internal/wasi/http/v0.2.0/types/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/http/v0.2.0/types/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/http/v0.2.0/types/types.wasm.go b/v3/internal/wasi/http/v0.2.0/types/types.wasm.go deleted file mode 100644 index b025b2af..00000000 --- a/v3/internal/wasi/http/v0.2.0/types/types.wasm.go +++ /dev/null @@ -1,257 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package types - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/http/v0.2.0/types/types.wit.go b/v3/internal/wasi/http/v0.2.0/types/types.wit.go deleted file mode 100644 index fe72a34f..00000000 --- a/v3/internal/wasi/http/v0.2.0/types/types.wit.go +++ /dev/null @@ -1,2020 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/monotonic-clock" - ioerror "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/error" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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) -} - -var _MethodStrings = [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 _MethodStrings[v.Tag()] -} - -// 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) -} - -var _SchemeStrings = [3]string{ - "HTTP", - "HTTPS", - "other", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Scheme) String() string { - return _SchemeStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - Rcode cm.Option[string] `json:"rcode"` - InfoCode cm.Option[uint16] `json:"info-code"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - AlertID cm.Option[uint8] `json:"alert-id"` - AlertMessage cm.Option[string] `json:"alert-message"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - FieldName cm.Option[string] `json:"field-name"` - FieldSize cm.Option[uint32] `json:"field-size"` -} - -// 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) -} - -var _ErrorCodeStrings = [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 _ErrorCodeStrings[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 -// 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 _HeaderErrorStrings = [3]string{ - "invalid-syntax", - "forbidden", - "immutable", -} - -// String implements [fmt.Stringer], returning the enum case name of e. -func (e HeaderError) String() string { - return _HeaderErrorStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e HeaderError) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *HeaderError) UnmarshalText(text []byte) error { - return _HeaderErrorUnmarshalCase(e, text) -} - -var _HeaderErrorUnmarshalCase = cm.CaseUnmarshaler[HeaderError](_HeaderErrorStrings[:]) - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 = (bool)(cm.U32ToBool((uint32)(result0))) - return -} - -// 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 -} - -// 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". -// -// 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 -} - -// 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 -} - -// 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 -} - -// 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 Headers) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) - result = cm.Reinterpret[Headers]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 Headers) (result OutgoingRequest) { - headers0 := cm.Reinterpret[uint32](headers) - result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) - result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} - -// 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 Headers) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) - result = cm.Reinterpret[Headers]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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 -} - -// 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 -} - -// 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[Duration]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) - return -} - -// 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[Duration]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) - return -} - -// 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[Duration]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) - return -} - -// 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[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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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[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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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[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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 Headers) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) - result = cm.Reinterpret[Headers]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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[InputStream, InputStream, struct{}]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_IncomingBodyStream((uint32)(self0), &result) - return -} - -// 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 -} - -// 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[Trailers], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Trailers], ErrorCode], struct{}]]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_FutureTrailersGet((uint32)(self0), &result) - return -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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 -} - -// 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 Headers) (result OutgoingResponse) { - headers0 := cm.Reinterpret[uint32](headers) - result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) - result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) - return -} - -// 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 -} - -// 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 Headers) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) - result = cm.Reinterpret[Headers]((uint32)(result0)) - return -} - -// 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)((bool)(cm.U32ToBool((uint32)(result0)))) - return -} - -// 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 -} - -// 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 -} - -// 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[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 -} - -// 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[OutputStream, OutputStream, struct{}]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_OutgoingBodyWrite((uint32)(self0), &result) - return -} - -// 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 -} - -// 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 -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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) (result cm.Option[ErrorCode]) { - err0 := cm.Reinterpret[uint32](err) - wasmimport_HTTPErrorCode((uint32)(err0), &result) - return -} diff --git a/v3/internal/wasi/io/v0.2.0/error/empty.s b/v3/internal/wasi/io/v0.2.0/error/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/io/v0.2.0/error/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/io/v0.2.0/error/error.wasm.go b/v3/internal/wasi/io/v0.2.0/error/error.wasm.go deleted file mode 100644 index e254b5d8..00000000 --- a/v3/internal/wasi/io/v0.2.0/error/error.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// 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/v3/internal/wasi/io/v0.2.0/error/error.wit.go b/v3/internal/wasi/io/v0.2.0/error/error.wit.go deleted file mode 100644 index 24bad438..00000000 --- a/v3/internal/wasi/io/v0.2.0/error/error.wit.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package ioerror represents the imported interface "wasi:io/error@0.2.0". -package ioerror - -import ( - "go.bytecodealliance.org/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 -} - -// 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 -} diff --git a/v3/internal/wasi/io/v0.2.0/poll/empty.s b/v3/internal/wasi/io/v0.2.0/poll/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/io/v0.2.0/poll/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go b/v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go deleted file mode 100644 index f7c55c3d..00000000 --- a/v3/internal/wasi/io/v0.2.0/poll/poll.wasm.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package poll - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/io/v0.2.0/poll/poll.wit.go b/v3/internal/wasi/io/v0.2.0/poll/poll.wit.go deleted file mode 100644 index 10c0033b..00000000 --- a/v3/internal/wasi/io/v0.2.0/poll/poll.wit.go +++ /dev/null @@ -1,92 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} - -// 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 -} - -// 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 = (bool)(cm.U32ToBool((uint32)(result0))) - return -} - -// 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 -} diff --git a/v3/internal/wasi/io/v0.2.0/streams/empty.s b/v3/internal/wasi/io/v0.2.0/streams/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/io/v0.2.0/streams/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go b/v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go deleted file mode 100644 index eec56645..00000000 --- a/v3/internal/wasi/io/v0.2.0/streams/streams.wasm.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package streams - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/io/v0.2.0/streams/streams.wit.go b/v3/internal/wasi/io/v0.2.0/streams/streams.wit.go deleted file mode 100644 index d2807315..00000000 --- a/v3/internal/wasi/io/v0.2.0/streams/streams.wit.go +++ /dev/null @@ -1,471 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/error" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// variant stream-error { -// last-operation-failed(error), -// closed, -// } -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 Error) StreamError { - return cm.New[StreamError](0, data) -} - -// 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". -// -// 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 -} - -var _StreamErrorStrings = [2]string{ - "last-operation-failed", - "closed", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v StreamError) String() string { - return _StreamErrorStrings[v.Tag()] -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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 -} - -// 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 -} diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go deleted file mode 100644 index 20fb0c89..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/abi.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package atomics - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// 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/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go deleted file mode 100644 index a2357d75..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wasm.go +++ /dev/null @@ -1,29 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package atomics - -import ( - "go.bytecodealliance.org/cm" -) - -// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". - -//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [resource-drop]cas -//go:noescape -func wasmimport_CasResourceDrop(self0 uint32) - -//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [static]cas.new -//go:noescape -func wasmimport_CasNew(bucket0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, Cas, Error]) - -//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [method]cas.current -//go:noescape -func wasmimport_CasCurrent(self0 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) - -//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 increment -//go:noescape -func wasmimport_Increment(bucket0 uint32, key0 *uint8, key1 uint32, delta0 uint64, result *cm.Result[ErrorShape, int64, Error]) - -//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 swap -//go:noescape -func wasmimport_Swap(cas0 uint32, value0 *uint8, value1 uint32, result *cm.Result[CasError, struct{}, CasError]) diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go deleted file mode 100644 index f71e5638..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/atomics.wit.go +++ /dev/null @@ -1,171 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package atomics represents the imported interface "wasi:keyvalue/atomics@0.2.0-draft2". -// -// A keyvalue interface that provides atomic operations. -// -// Atomic operations are single, indivisible operations. When a fault causes an atomic -// operation to -// fail, it will appear to the invoker of the atomic operation that the action either -// completed -// successfully or did nothing at all. -// -// Please note that this interface is bare functions that take a reference to a bucket. -// This is to -// get around the current lack of a way to "extend" a resource with additional methods -// inside of -// wit. Future version of the interface will instead extend these methods on the base -// `bucket` -// resource. -package atomics - -import ( - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/keyvalue/v0.2.0-draft2/store" - "go.bytecodealliance.org/cm" -) - -// Bucket represents the imported type alias "wasi:keyvalue/atomics@0.2.0-draft2#bucket". -// -// See [store.Bucket] for more information. -type Bucket = store.Bucket - -// Error represents the type alias "wasi:keyvalue/atomics@0.2.0-draft2#error". -// -// See [store.Error] for more information. -type Error = store.Error - -// Cas represents the imported resource "wasi:keyvalue/atomics@0.2.0-draft2#cas". -// -// A handle to a CAS (compare-and-swap) operation. -// -// resource cas -type Cas cm.Resource - -// ResourceDrop represents the imported resource-drop for resource "cas". -// -// Drops a resource handle. -// -//go:nosplit -func (self Cas) ResourceDrop() { - self0 := cm.Reinterpret[uint32](self) - wasmimport_CasResourceDrop((uint32)(self0)) - return -} - -// CasNew represents the imported static function "new". -// -// Construct a new CAS operation. Implementors can map the underlying functionality -// (transactions, versions, etc) as desired. -// -// new: static func(bucket: borrow, key: string) -> result -// -//go:nosplit -func CasNew(bucket Bucket, key string) (result cm.Result[ErrorShape, Cas, Error]) { - bucket0 := cm.Reinterpret[uint32](bucket) - key0, key1 := cm.LowerString(key) - wasmimport_CasNew((uint32)(bucket0), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// Current represents the imported method "current". -// -// Get the current value of the key (if it exists). This allows for avoiding reads -// if all -// that is needed to ensure the atomicity of the operation -// -// current: func() -> result>, error> -// -//go:nosplit -func (self Cas) Current() (result cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_CasCurrent((uint32)(self0), &result) - return -} - -// CasError represents the imported variant "wasi:keyvalue/atomics@0.2.0-draft2#cas-error". -// -// The error returned by a CAS operation -// -// variant cas-error { -// store-error(error), -// cas-failed(cas), -// } -type CasError cm.Variant[uint8, ErrorShape, Error] - -// CasErrorStoreError returns a [CasError] of case "store-error". -// -// A store error occurred when performing the operation -func CasErrorStoreError(data Error) CasError { - return cm.New[CasError](0, data) -} - -// StoreError returns a non-nil *[Error] if [CasError] represents the variant case "store-error". -func (self *CasError) StoreError() *Error { - return cm.Case[Error](self, 0) -} - -// CasErrorCasFailed returns a [CasError] of case "cas-failed". -// -// The CAS operation failed because the value was too old. This returns a new CAS -// handle -// for easy retries. Implementors MUST return a CAS handle that has been updated to -// the -// latest version or transaction. -func CasErrorCasFailed(data Cas) CasError { - return cm.New[CasError](1, data) -} - -// CasFailed returns a non-nil *[Cas] if [CasError] represents the variant case "cas-failed". -func (self *CasError) CasFailed() *Cas { - return cm.Case[Cas](self, 1) -} - -var _CasErrorStrings = [2]string{ - "store-error", - "cas-failed", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v CasError) String() string { - return _CasErrorStrings[v.Tag()] -} - -// Increment represents the imported function "increment". -// -// Atomically increment the value associated with the key in the store by the given -// delta. It -// returns the new value. -// -// If the key does not exist in the store, it creates a new key-value pair with the -// value set -// to the given delta. -// -// If any other error occurs, it returns an `Err(error)`. -// -// increment: func(bucket: borrow, key: string, delta: s64) -> result -// -//go:nosplit -func Increment(bucket Bucket, key string, delta int64) (result cm.Result[ErrorShape, int64, Error]) { - bucket0 := cm.Reinterpret[uint32](bucket) - key0, key1 := cm.LowerString(key) - delta0 := (uint64)(delta) - wasmimport_Increment((uint32)(bucket0), (*uint8)(key0), (uint32)(key1), (uint64)(delta0), &result) - return -} - -// Swap represents the imported function "swap". -// -// Perform the swap on a CAS operation. This consumes the CAS handle and returns an -// error if -// the CAS operation failed. -// -// swap: func(cas: cas, value: list) -> result<_, cas-error> -// -//go:nosplit -func Swap(cas Cas, value cm.List[uint8]) (result cm.Result[CasError, struct{}, CasError]) { - cas0 := cm.Reinterpret[uint32](cas) - value0, value1 := cm.LowerList(value) - wasmimport_Swap((uint32)(cas0), (*uint8)(value0), (uint32)(value1), &result) - return -} diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/atomics/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go deleted file mode 100644 index 9b6592ee..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package batch - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go deleted file mode 100644 index ea801e79..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wasm.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package batch - -import ( - "go.bytecodealliance.org/cm" -) - -// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". - -//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 get-many -//go:noescape -func wasmimport_GetMany(bucket0 uint32, keys0 *string, keys1 uint32, result *cm.Result[ErrorShape, cm.List[cm.Tuple[string, cm.Option[cm.List[uint8]]]], Error]) - -//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 set-many -//go:noescape -func wasmimport_SetMany(bucket0 uint32, keyValues0 *cm.Tuple[string, cm.List[uint8]], keyValues1 uint32, result *cm.Result[Error, struct{}, Error]) - -//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 delete-many -//go:noescape -func wasmimport_DeleteMany(bucket0 uint32, keys0 *string, keys1 uint32, result *cm.Result[Error, struct{}, Error]) diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go deleted file mode 100644 index a934a1f0..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/batch.wit.go +++ /dev/null @@ -1,134 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package batch represents the imported interface "wasi:keyvalue/batch@0.2.0-draft2". -// -// A keyvalue interface that provides batch operations. -// -// A batch operation is an operation that operates on multiple keys at once. -// -// Batch operations are useful for reducing network round-trip time. For example, -// if you want to -// get the values associated with 100 keys, you can either do 100 get operations or -// you can do 1 -// batch get operation. The batch operation is faster because it only needs to make -// 1 network call -// instead of 100. -// -// A batch operation does not guarantee atomicity, meaning that if the batch operation -// fails, some -// of the keys may have been modified and some may not. -// -// This interface does has the same consistency guarantees as the `store` interface, -// meaning that -// you should be able to "read your writes." -// -// Please note that this interface is bare functions that take a reference to a bucket. -// This is to -// get around the current lack of a way to "extend" a resource with additional methods -// inside of -// wit. Future version of the interface will instead extend these methods on the base -// `bucket` -// resource. -package batch - -import ( - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/keyvalue/v0.2.0-draft2/store" - "go.bytecodealliance.org/cm" -) - -// Bucket represents the imported type alias "wasi:keyvalue/batch@0.2.0-draft2#bucket". -// -// See [store.Bucket] for more information. -type Bucket = store.Bucket - -// Error represents the type alias "wasi:keyvalue/batch@0.2.0-draft2#error". -// -// See [store.Error] for more information. -type Error = store.Error - -// GetMany represents the imported function "get-many". -// -// Get the key-value pairs associated with the keys in the store. It returns a list -// of -// key-value pairs. -// -// If any of the keys do not exist in the store, it returns a `none` value for that -// pair in the -// list. -// -// MAY show an out-of-date value if there are concurrent writes to the store. -// -// If any other error occurs, it returns an `Err(error)`. -// -// get-many: func(bucket: borrow, keys: list) -> result>>>, error> -// -//go:nosplit -func GetMany(bucket Bucket, keys cm.List[string]) (result cm.Result[ErrorShape, cm.List[cm.Tuple[string, cm.Option[cm.List[uint8]]]], Error]) { - bucket0 := cm.Reinterpret[uint32](bucket) - keys0, keys1 := cm.LowerList(keys) - wasmimport_GetMany((uint32)(bucket0), (*string)(keys0), (uint32)(keys1), &result) - return -} - -// SetMany represents the imported function "set-many". -// -// Set the values associated with the keys in the store. If the key already exists -// in the -// store, it overwrites the value. -// -// Note that the key-value pairs are not guaranteed to be set in the order they are -// provided. -// -// If any of the keys do not exist in the store, it creates a new key-value pair. -// -// If any other error occurs, it returns an `Err(error)`. When an error occurs, it -// does not -// rollback the key-value pairs that were already set. Thus, this batch operation -// does not -// guarantee atomicity, implying that some key-value pairs could be set while others -// might -// fail. -// -// Other concurrent operations may also be able to see the partial results. -// -// set-many: func(bucket: borrow, key-values: list>>) -// -> result<_, error> -// -//go:nosplit -func SetMany(bucket Bucket, keyValues cm.List[cm.Tuple[string, cm.List[uint8]]]) (result cm.Result[Error, struct{}, Error]) { - bucket0 := cm.Reinterpret[uint32](bucket) - keyValues0, keyValues1 := cm.LowerList(keyValues) - wasmimport_SetMany((uint32)(bucket0), (*cm.Tuple[string, cm.List[uint8]])(keyValues0), (uint32)(keyValues1), &result) - return -} - -// DeleteMany represents the imported function "delete-many". -// -// Delete the key-value pairs associated with the keys in the store. -// -// Note that the key-value pairs are not guaranteed to be deleted in the order they -// are -// provided. -// -// If any of the keys do not exist in the store, it skips the key. -// -// If any other error occurs, it returns an `Err(error)`. When an error occurs, it -// does not -// rollback the key-value pairs that were already deleted. Thus, this batch operation -// does not -// guarantee atomicity, implying that some key-value pairs could be deleted while -// others might -// fail. -// -// Other concurrent operations may also be able to see the partial results. -// -// delete-many: func(bucket: borrow, keys: list) -> result<_, error> -// -//go:nosplit -func DeleteMany(bucket Bucket, keys cm.List[string]) (result cm.Result[Error, struct{}, Error]) { - bucket0 := cm.Reinterpret[uint32](bucket) - keys0, keys1 := cm.LowerList(keys) - wasmimport_DeleteMany((uint32)(bucket0), (*string)(keys0), (uint32)(keys1), &result) - return -} diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/batch/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go deleted file mode 100644 index 8e92daf7..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/abi.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package store - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// 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 -} - -// KeyResponseShape is used for storage in variant or result types. -type KeyResponseShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(KeyResponse{})]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 -} diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go deleted file mode 100644 index 58f1a36b..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wasm.go +++ /dev/null @@ -1,37 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package store - -import ( - "go.bytecodealliance.org/cm" -) - -// This file contains wasmimport and wasmexport declarations for "wasi:keyvalue@0.2.0-draft2". - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [resource-drop]bucket -//go:noescape -func wasmimport_BucketResourceDrop(self0 uint32) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.delete -//go:noescape -func wasmimport_BucketDelete(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[Error, struct{}, Error]) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.exists -//go:noescape -func wasmimport_BucketExists(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[ErrorShape, bool, Error]) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.get -//go:noescape -func wasmimport_BucketGet(self0 uint32, key0 *uint8, key1 uint32, result *cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.list-keys -//go:noescape -func wasmimport_BucketListKeys(self0 uint32, cursor0 uint32, cursor1 *uint8, cursor2 uint32, result *cm.Result[KeyResponseShape, KeyResponse, Error]) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.set -//go:noescape -func wasmimport_BucketSet(self0 uint32, key0 *uint8, key1 uint32, value0 *uint8, value1 uint32, result *cm.Result[Error, struct{}, Error]) - -//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 open -//go:noescape -func wasmimport_Open(identifier0 *uint8, identifier1 uint32, result *cm.Result[ErrorShape, Bucket, Error]) diff --git a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go b/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go deleted file mode 100644 index 3aca4200..00000000 --- a/v3/internal/wasi/keyvalue/v0.2.0-draft2/store/store.wit.go +++ /dev/null @@ -1,294 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package store represents the imported interface "wasi:keyvalue/store@0.2.0-draft2". -// -// A keyvalue interface that provides eventually consistent key-value operations. -// -// Each of these operations acts on a single key-value pair. -// -// The value in the key-value pair is defined as a `u8` byte array and the intention -// is that it is -// the common denominator for all data types defined by different key-value stores -// to handle data, -// ensuring compatibility between different key-value stores. Note: the clients will -// be expecting -// serialization/deserialization overhead to be handled by the key-value store. The -// value could be -// a serialized object from JSON, HTML or vendor-specific data types like AWS S3 objects. -// -// Data consistency in a key value store refers to the guarantee that once a write -// operation -// completes, all subsequent read operations will return the value that was written. -// -// Any implementation of this interface must have enough consistency to guarantee -// "reading your -// writes." In particular, this means that the client should never get a value that -// is older than -// the one it wrote, but it MAY get a newer value if one was written around the same -// time. These -// guarantees only apply to the same client (which will likely be provided by the -// host or an -// external capability of some kind). In this context a "client" is referring to the -// caller or -// guest that is consuming this interface. Once a write request is committed by a -// specific client, -// all subsequent read requests by the same client will reflect that write or any -// subsequent -// writes. Another client running in a different context may or may not immediately -// see the result -// due to the replication lag. As an example of all of this, if a value at a given -// key is A, and -// the client writes B, then immediately reads, it should get B. If something else -// writes C in -// quick succession, then the client may get C. However, a client running in a separate -// context may -// still see A or B -package store - -import ( - "go.bytecodealliance.org/cm" -) - -// Error represents the variant "wasi:keyvalue/store@0.2.0-draft2#error". -// -// The set of errors which may be raised by functions in this package -// -// variant error { -// no-such-store, -// access-denied, -// other(string), -// } -type Error cm.Variant[uint8, string, string] - -// ErrorNoSuchStore returns a [Error] of case "no-such-store". -// -// The host does not recognize the store identifier requested. -func ErrorNoSuchStore() Error { - var data struct{} - return cm.New[Error](0, data) -} - -// NoSuchStore returns true if [Error] represents the variant case "no-such-store". -func (self *Error) NoSuchStore() bool { - return self.Tag() == 0 -} - -// 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](1, data) -} - -// AccessDenied returns true if [Error] represents the variant case "access-denied". -func (self *Error) AccessDenied() bool { - return self.Tag() == 1 -} - -// 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](2, data) -} - -// Other returns a non-nil *[string] if [Error] represents the variant case "other". -func (self *Error) Other() *string { - return cm.Case[string](self, 2) -} - -var _ErrorStrings = [3]string{ - "no-such-store", - "access-denied", - "other", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v Error) String() string { - return _ErrorStrings[v.Tag()] -} - -// KeyResponse represents the record "wasi:keyvalue/store@0.2.0-draft2#key-response". -// -// A response to a `list-keys` operation. -// -// record key-response { -// keys: list, -// cursor: option, -// } -type KeyResponse struct { - _ cm.HostLayout `json:"-"` - // The list of keys returned by the query. - Keys cm.List[string] `json:"keys"` - - // The continuation token to use to fetch the next page of keys. If this is `null`, - // then - // there are no more keys to fetch. - Cursor cm.Option[string] `json:"cursor"` -} - -// Bucket represents the imported resource "wasi:keyvalue/store@0.2.0-draft2#bucket". -// -// A bucket is a collection of key-value pairs. Each key-value pair is stored as a -// entry in the -// bucket, and the bucket itself acts as a collection of all these entries. -// -// It is worth noting that the exact terminology for bucket in key-value stores can -// very -// depending on the specific implementation. For example: -// -// 1. Amazon DynamoDB calls a collection of key-value pairs a table -// 2. Redis has hashes, sets, and sorted sets as different types of collections -// 3. Cassandra calls a collection of key-value pairs a column family -// 4. MongoDB calls a collection of key-value pairs a collection -// 5. Riak calls a collection of key-value pairs a bucket -// 6. Memcached calls a collection of key-value pairs a slab -// 7. Azure Cosmos DB calls a collection of key-value pairs a container -// -// In this interface, we use the term `bucket` to refer to a collection of key-value -// pairs -// -// resource bucket -type Bucket cm.Resource - -// ResourceDrop represents the imported resource-drop for resource "bucket". -// -// Drops a resource handle. -// -//go:nosplit -func (self Bucket) ResourceDrop() { - self0 := cm.Reinterpret[uint32](self) - wasmimport_BucketResourceDrop((uint32)(self0)) - return -} - -// Delete represents the imported method "delete". -// -// Delete the key-value pair associated with the key in the store. -// -// If the key does not exist in the store, it does nothing. -// -// If any other error occurs, it returns an `Err(error)`. -// -// delete: func(key: string) -> result<_, error> -// -//go:nosplit -func (self Bucket) Delete(key string) (result cm.Result[Error, struct{}, Error]) { - self0 := cm.Reinterpret[uint32](self) - key0, key1 := cm.LowerString(key) - wasmimport_BucketDelete((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// Exists represents the imported method "exists". -// -// Check if the key exists in the store. -// -// If the key exists in the store, it returns `Ok(true)`. If the key does -// not exist in the store, it returns `Ok(false)`. -// -// If any other error occurs, it returns an `Err(error)`. -// -// exists: func(key: string) -> result -// -//go:nosplit -func (self Bucket) Exists(key string) (result cm.Result[ErrorShape, bool, Error]) { - self0 := cm.Reinterpret[uint32](self) - key0, key1 := cm.LowerString(key) - wasmimport_BucketExists((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// Get represents the imported method "get". -// -// Get the value associated with the specified `key` -// -// The value is returned as an option. If the key-value pair exists in the -// store, it returns `Ok(value)`. If the key does not exist in the -// store, it returns `Ok(none)`. -// -// If any other error occurs, it returns an `Err(error)`. -// -// get: func(key: string) -> result>, error> -// -//go:nosplit -func (self Bucket) Get(key string) (result cm.Result[OptionListU8Shape, cm.Option[cm.List[uint8]], Error]) { - self0 := cm.Reinterpret[uint32](self) - key0, key1 := cm.LowerString(key) - wasmimport_BucketGet((uint32)(self0), (*uint8)(key0), (uint32)(key1), &result) - return -} - -// ListKeys represents the imported method "list-keys". -// -// Get all the keys in the store with an optional cursor (for use in pagination). -// It -// returns a list of keys. Please note that for most KeyValue implementations, this -// is a -// can be a very expensive operation and so it should be used judiciously. Implementations -// can return any number of keys in a single response, but they should never attempt -// to -// send more data than is reasonable (i.e. on a small edge device, this may only be -// a few -// KB, while on a large machine this could be several MB). Any response should also -// return -// a cursor that can be used to fetch the next page of keys. See the `key-response` -// record -// for more information. -// -// Note that the keys are not guaranteed to be returned in any particular order. -// -// If the store is empty, it returns an empty list. -// -// MAY show an out-of-date list of keys if there are concurrent writes to the store. -// -// If any error occurs, it returns an `Err(error)`. -// -// list-keys: func(cursor: option) -> result -// -//go:nosplit -func (self Bucket) ListKeys(cursor cm.Option[string]) (result cm.Result[KeyResponseShape, KeyResponse, Error]) { - self0 := cm.Reinterpret[uint32](self) - cursor0, cursor1, cursor2 := lower_OptionString(cursor) - wasmimport_BucketListKeys((uint32)(self0), (uint32)(cursor0), (*uint8)(cursor1), (uint32)(cursor2), &result) - return -} - -// Set represents the imported method "set". -// -// Set the value associated with the key in the store. If the key already -// exists in the store, it overwrites the value. -// -// If the key does not exist in the store, it creates a new key-value pair. -// -// If any other error occurs, it returns an `Err(error)`. -// -// set: func(key: string, value: list) -> result<_, error> -// -//go:nosplit -func (self Bucket) 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_BucketSet((uint32)(self0), (*uint8)(key0), (uint32)(key1), (*uint8)(value0), (uint32)(value1), &result) - return -} - -// Open represents the imported function "open". -// -// Get the bucket with the specified identifier. -// -// `identifier` must refer to a bucket provided by the host. -// -// `error::no-such-store` will be raised if the `identifier` is not recognized. -// -// open: func(identifier: string) -> result -// -//go:nosplit -func Open(identifier string) (result cm.Result[ErrorShape, Bucket, Error]) { - identifier0, identifier1 := cm.LowerString(identifier) - wasmimport_Open((*uint8)(identifier0), (uint32)(identifier1), &result) - return -} diff --git a/v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s b/v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure-seed/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go b/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go deleted file mode 100644 index e94356df..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go b/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go deleted file mode 100644 index 6f363673..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go +++ /dev/null @@ -1,37 +0,0 @@ -// 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 -} diff --git a/v3/internal/wasi/random/v0.2.0/insecure/empty.s b/v3/internal/wasi/random/v0.2.0/insecure/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go b/v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go deleted file mode 100644 index 498bfe4a..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure/insecure.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package insecure - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go deleted file mode 100644 index 295a1ada..00000000 --- a/v3/internal/wasi/random/v0.2.0/insecure/insecure.wit.go +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} - -// 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 -} diff --git a/v3/internal/wasi/random/v0.2.0/random/empty.s b/v3/internal/wasi/random/v0.2.0/random/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/random/v0.2.0/random/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/random/v0.2.0/random/random.wasm.go b/v3/internal/wasi/random/v0.2.0/random/random.wasm.go deleted file mode 100644 index 9096457b..00000000 --- a/v3/internal/wasi/random/v0.2.0/random/random.wasm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package random - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/random/v0.2.0/random/random.wit.go b/v3/internal/wasi/random/v0.2.0/random/random.wit.go deleted file mode 100644 index bb90e7e0..00000000 --- a/v3/internal/wasi/random/v0.2.0/random/random.wit.go +++ /dev/null @@ -1,53 +0,0 @@ -// 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 ( - "go.bytecodealliance.org/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 -} - -// 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 -} diff --git a/v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s b/v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/instance-network/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go b/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go deleted file mode 100644 index eb113e21..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go deleted file mode 100644 index 381b5cce..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go +++ /dev/null @@ -1,29 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// instance-network: func() -> network -// -//go:nosplit -func InstanceNetwork() (result Network) { - result0 := wasmimport_InstanceNetwork() - result = cm.Reinterpret[Network]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go deleted file mode 100644 index a63f0d01..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package ipnamelookup - -import ( - "go.bytecodealliance.org/cm" - "unsafe" -) - -// OptionIPAddressShape is used for storage in variant or result types. -type OptionIPAddressShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(cm.Option[IPAddress]{})]byte -} diff --git a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go deleted file mode 100644 index da5fb000..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wasm.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package ipnamelookup - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go deleted file mode 100644 index 96791c89..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go +++ /dev/null @@ -1,125 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" -) - -// 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 -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 -} - -// 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[IPAddress], ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) - return -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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, 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 -} diff --git a/v3/internal/wasi/sockets/v0.2.0/network/abi.go b/v3/internal/wasi/sockets/v0.2.0/network/abi.go deleted file mode 100644 index a088bd1d..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/network/abi.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package network - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/sockets/v0.2.0/network/empty.s b/v3/internal/wasi/sockets/v0.2.0/network/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/network/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go b/v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go deleted file mode 100644 index 012a79ff..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/network/network.wasm.go +++ /dev/null @@ -1,9 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/network/network.wit.go b/v3/internal/wasi/sockets/v0.2.0/network/network.wit.go deleted file mode 100644 index a37b5b9a..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/network/network.wit.go +++ /dev/null @@ -1,359 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -// Package network represents the imported interface "wasi:sockets/network@0.2.0". -package network - -import ( - "go.bytecodealliance.org/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 -} - -// 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 _ErrorCodeStrings = [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 _ErrorCodeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e ErrorCode) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *ErrorCode) UnmarshalText(text []byte) error { - return _ErrorCodeUnmarshalCase(e, text) -} - -var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:]) - -// 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 _IPAddressFamilyStrings = [2]string{ - "ipv4", - "ipv6", -} - -// String implements [fmt.Stringer], returning the enum case name of e. -func (e IPAddressFamily) String() string { - return _IPAddressFamilyStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e IPAddressFamily) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *IPAddressFamily) UnmarshalText(text []byte) error { - return _IPAddressFamilyUnmarshalCase(e, text) -} - -var _IPAddressFamilyUnmarshalCase = cm.CaseUnmarshaler[IPAddressFamily](_IPAddressFamilyStrings[:]) - -// 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) -} - -var _IPAddressStrings = [2]string{ - "ipv4", - "ipv6", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v IPAddress) String() string { - return _IPAddressStrings[v.Tag()] -} - -// 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 { - _ cm.HostLayout `json:"-"` - // sin_port - Port uint16 `json:"port"` - - // sin_addr - Address IPv4Address `json:"address"` -} - -// 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 { - _ cm.HostLayout `json:"-"` - // sin6_port - Port uint16 `json:"port"` - - // sin6_flowinfo - FlowInfo uint32 `json:"flow-info"` - - // sin6_addr - Address IPv6Address `json:"address"` - - // sin6_scope_id - ScopeID uint32 `json:"scope-id"` -} - -// 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) -} - -var _IPSocketAddressStrings = [2]string{ - "ipv4", - "ipv6", -} - -// String implements [fmt.Stringer], returning the variant case name of v. -func (v IPSocketAddress) String() string { - return _IPSocketAddressStrings[v.Tag()] -} diff --git a/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go deleted file mode 100644 index b7b43155..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package tcpcreatesocket - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go deleted file mode 100644 index 5d2c9837..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go +++ /dev/null @@ -1,68 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/tcp" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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 IPAddressFamily) (result cm.Result[TCPSocket, TCPSocket, ErrorCode]) { - addressFamily0 := (uint32)(addressFamily) - wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) - return -} diff --git a/v3/internal/wasi/sockets/v0.2.0/tcp/abi.go b/v3/internal/wasi/sockets/v0.2.0/tcp/abi.go deleted file mode 100644 index 665de00d..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package tcp - -import ( - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" - "unsafe" -) - -// TupleTCPSocketInputStreamOutputStreamShape is used for storage in variant or result types. -type TupleTCPSocketInputStreamOutputStreamShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(cm.Tuple3[TCPSocket, InputStream, OutputStream]{})]byte -} - -// TupleInputStreamOutputStreamShape is used for storage in variant or result types. -type TupleInputStreamOutputStreamShape struct { - _ 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(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(*cm.Case[network.IPv4SocketAddress](&v, 0)) - 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(*cm.Case[network.IPv6SocketAddress](&v, 1)) - 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/v3/internal/wasi/sockets/v0.2.0/tcp/empty.s b/v3/internal/wasi/sockets/v0.2.0/tcp/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go b/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go deleted file mode 100644 index d6e56c26..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wasm.go +++ /dev/null @@ -1,125 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package tcp - -import ( - "go.bytecodealliance.org/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[ErrorCode, 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/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go deleted file mode 100644 index 9f00f376..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go +++ /dev/null @@ -1,785 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/clocks/v0.2.0/monotonic-clock" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/streams" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" -) - -// 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 { -// 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 _ShutdownTypeStrings = [3]string{ - "receive", - "send", - "both", -} - -// String implements [fmt.Stringer], returning the enum case name of e. -func (e ShutdownType) String() string { - return _ShutdownTypeStrings[e] -} - -// MarshalText implements [encoding.TextMarshaler]. -func (e ShutdownType) MarshalText() ([]byte, error) { - return []byte(e.String()), nil -} - -// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum -// case. Returns an error if the supplied text is not one of the enum cases. -func (e *ShutdownType) UnmarshalText(text []byte) error { - return _ShutdownTypeUnmarshalCase(e, text) -} - -var _ShutdownTypeUnmarshalCase = cm.CaseUnmarshaler[ShutdownType](_ShutdownTypeStrings[:]) - -// 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 -} - -// 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, InputStream, OutputStream], ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketAccept((uint32)(self0), &result) - return -} - -// 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 IPAddressFamily) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) - result = (network.IPAddressFamily)((uint32)(result0)) - return -} - -// FinishBind represents the imported method "finish-bind". -// -// finish-bind: func() -> result<_, error-code> -// -//go:nosplit -func (self TCPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketFinishBind((uint32)(self0), &result) - return -} - -// 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[InputStream, OutputStream], ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) - return -} - -// FinishListen represents the imported method "finish-listen". -// -// finish-listen: func() -> result<_, error-code> -// -//go:nosplit -func (self TCPSocket) FinishListen() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketFinishListen((uint32)(self0), &result) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketHopLimit((uint32)(self0), &result) - return -} - -// 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 = (bool)(cm.U32ToBool((uint32)(result0))) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) - return -} - -// 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[ErrorCode, bool, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) - return -} - -// 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, Duration, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) - return -} - -// 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, Duration, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) - return -} - -// 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, IPSocketAddress, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) - return -} - -// 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, IPSocketAddress, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) - return -} - -// SendBufferSize represents the imported method "send-buffer-size". -// -// send-buffer-size: func() -> result -// -//go:nosplit -func (self TCPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint32)(value) - wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint32)(value) - wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint32)(cm.BoolToU32(value)) - wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) - return -} - -// 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 Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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 Duration) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - shutdownType0 := (uint32)(shutdownType) - wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) - return -} - -// 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, 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) - 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 -} - -// 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, 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) - 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 -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_TCPSocketStartListen((uint32)(self0), &result) - return -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go deleted file mode 100644 index 94b1ab67..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wasm.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package udpcreatesocket - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go deleted file mode 100644 index af9c0e94..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go +++ /dev/null @@ -1,68 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/udp" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// 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 IPAddressFamily) (result cm.Result[UDPSocket, UDPSocket, ErrorCode]) { - addressFamily0 := (uint32)(addressFamily) - wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) - return -} diff --git a/v3/internal/wasi/sockets/v0.2.0/udp/abi.go b/v3/internal/wasi/sockets/v0.2.0/udp/abi.go deleted file mode 100644 index 0d8d5995..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp/abi.go +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package udp - -import ( - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" - "unsafe" -) - -// IPSocketAddressShape is used for storage in variant or result types. -type IPSocketAddressShape struct { - _ cm.HostLayout - shape [unsafe.Sizeof(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(*cm.Case[network.IPv4SocketAddress](&v, 0)) - 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(*cm.Case[network.IPv6SocketAddress](&v, 1)) - 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 { - _ cm.HostLayout - shape [unsafe.Sizeof(cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream]{})]byte -} - -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 - 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/v3/internal/wasi/sockets/v0.2.0/udp/empty.s b/v3/internal/wasi/sockets/v0.2.0/udp/empty.s deleted file mode 100644 index 5444f200..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp/empty.s +++ /dev/null @@ -1,3 +0,0 @@ -// 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/v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go b/v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go deleted file mode 100644 index 83ce8ca7..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp/udp.wasm.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by wit-bindgen-go. DO NOT EDIT. - -package udp - -import ( - "go.bytecodealliance.org/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/v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go deleted file mode 100644 index 16f6ccd0..00000000 --- a/v3/internal/wasi/sockets/v0.2.0/udp/udp.wit.go +++ /dev/null @@ -1,584 +0,0 @@ -// 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/spinframework/spin-go-sdk/v3/internal/wasi/io/v0.2.0/poll" - "github.com/spinframework/spin-go-sdk/v3/internal/wasi/sockets/v0.2.0/network" - "go.bytecodealliance.org/cm" -) - -// 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. -// -// record incoming-datagram { -// data: list, -// remote-address: ip-socket-address, -// } -type IncomingDatagram struct { - _ cm.HostLayout `json:"-"` - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - Data cm.List[uint8] `json:"data"` - - // 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 IPSocketAddress `json:"remote-address"` -} - -// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". -// -// A datagram to be sent out. -// -// record outgoing-datagram { -// data: list, -// remote-address: option, -// } -type OutgoingDatagram struct { - _ cm.HostLayout `json:"-"` - // The payload. - Data cm.List[uint8] `json:"data"` - - // 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[IPSocketAddress] `json:"remote-address"` -} - -// 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 -} - -// 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 IPAddressFamily) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) - result = (network.IPAddressFamily)((uint32)(result0)) - return -} - -// FinishBind represents the imported method "finish-bind". -// -// finish-bind: func() -> result<_, error-code> -// -//go:nosplit -func (self UDPSocket) FinishBind() (result cm.Result[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketFinishBind((uint32)(self0), &result) - return -} - -// 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, IPSocketAddress, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) - return -} - -// 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, IPSocketAddress, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) - return -} - -// SendBufferSize represents the imported method "send-buffer-size". -// -// send-buffer-size: func() -> result -// -//go:nosplit -func (self UDPSocket) SendBufferSize() (result cm.Result[uint64, uint64, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint64)(value) - wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) - return -} - -// 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[ErrorCode, struct{}, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - value0 := (uint32)(value) - wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) - return -} - -// 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, 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) - 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 -} - -// 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[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 -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) - return -} - -// 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 -} - -// 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], ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - maxResults0 := (uint64)(maxResults) - wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) - return -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} - -// 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 -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) - return -} - -// 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, ErrorCode]) { - self0 := cm.Reinterpret[uint32](self) - datagrams0, datagrams1 := cm.LowerList(datagrams) - wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) - return -} - -// 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 Pollable) { - self0 := cm.Reinterpret[uint32](self) - result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) - result = cm.Reinterpret[Pollable]((uint32)(result0)) - return -} diff --git a/v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go new file mode 100644 index 00000000..3631afea --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go @@ -0,0 +1,110 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_environment + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:cli/environment@0.2.0 get-environment +func wasm_import_get_environment(arg0 uintptr) + +func GetEnvironment() []wit_types.Tuple2[string, string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_get_environment(returnArea) + result := make([]wit_types.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) + + result = append(result, wit_types.Tuple2[string, string]{value, value0}) + } + + result1 := result + return result1 + +} + +//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +func wasm_import_get_arguments(arg0 uintptr) + +func GetArguments() []string { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_get_arguments(returnArea) + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result0 := result + return result0 + +} + +//go:wasmimport wasi:cli/environment@0.2.0 initial-cwd +func wasm_import_initial_cwd(arg0 uintptr) + +func InitialCwd() wit_types.Option[string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_initial_cwd(returnArea) + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + result := option + return result + +} diff --git a/v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go new file mode 100644 index 00000000..57573cfb --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go @@ -0,0 +1,56 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_exit + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_types" +) + +//go:wasmimport wasi:cli/exit@0.2.0 exit +func wasm_import_exit(arg0 int32) + +func Exit(status wit_types.Result[wit_types.Unit, wit_types.Unit]) { + + var option int32 + switch status.Tag() { + case wit_types.ResultOk: + + option = int32(0) + case wit_types.ResultErr: + + option = int32(1) + default: + panic("unreachable") + } + wasm_import_exit(option) + +} diff --git a/v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go new file mode 100644 index 00000000..b4189111 --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go @@ -0,0 +1,48 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_stderr + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" +) + +type OutputStream = wasi_io_0_2_0_streams.OutputStream + +//go:wasmimport wasi:cli/stderr@0.2.0 get-stderr +func wasm_import_get_stderr() int32 + +func GetStderr() *wasi_io_0_2_0_streams.OutputStream { + + result := wasm_import_get_stderr() + return wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go new file mode 100644 index 00000000..9ae7b915 --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go @@ -0,0 +1,48 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_stdin + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" +) + +type InputStream = wasi_io_0_2_0_streams.InputStream + +//go:wasmimport wasi:cli/stdin@0.2.0 get-stdin +func wasm_import_get_stdin() int32 + +func GetStdin() *wasi_io_0_2_0_streams.InputStream { + + result := wasm_import_get_stdin() + return wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go new file mode 100644 index 00000000..ebb091aa --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go @@ -0,0 +1,48 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_stdout + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" +) + +type OutputStream = wasi_io_0_2_0_streams.OutputStream + +//go:wasmimport wasi:cli/stdout@0.2.0 get-stdout +func wasm_import_get_stdout() int32 + +func GetStdout() *wasi_io_0_2_0_streams.OutputStream { + + result := wasm_import_get_stdout() + return wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go new file mode 100644 index 00000000..4be6d299 --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go @@ -0,0 +1,80 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_terminal_input + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" +) + +//go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input +func resourceDropTerminalInput(handle int32) + +// The input side of a terminal. +type TerminalInput struct { + handle *wit_runtime.Handle +} + +func (self *TerminalInput) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *TerminalInput) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *TerminalInput) Handle() int32 { + return self.handle.Use() +} + +func (self *TerminalInput) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropTerminalInput(handle) + } +} + +func TerminalInputFromOwnHandle(handleValue int32) *TerminalInput { + handle := wit_runtime.MakeHandle(handleValue) + value := &TerminalInput{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropTerminalInput(handleValue) + } + }, 0) + return value +} + +func TerminalInputFromBorrowHandle(handleValue int32) *TerminalInput { + return TerminalInputFromOwnHandle(handleValue) +} diff --git a/v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go new file mode 100644 index 00000000..7dd81bc2 --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go @@ -0,0 +1,80 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_terminal_output + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" +) + +//go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output +func resourceDropTerminalOutput(handle int32) + +// The output side of a terminal. +type TerminalOutput struct { + handle *wit_runtime.Handle +} + +func (self *TerminalOutput) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *TerminalOutput) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *TerminalOutput) Handle() int32 { + return self.handle.Use() +} + +func (self *TerminalOutput) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropTerminalOutput(handle) + } +} + +func TerminalOutputFromOwnHandle(handleValue int32) *TerminalOutput { + handle := wit_runtime.MakeHandle(handleValue) + value := &TerminalOutput{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropTerminalOutput(handleValue) + } + }, 0) + return value +} + +func TerminalOutputFromBorrowHandle(handleValue int32) *TerminalOutput { + return TerminalOutputFromOwnHandle(handleValue) +} diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go new file mode 100644 index 00000000..9731e23e --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go @@ -0,0 +1,67 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_terminal_stderr + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_output" + "runtime" + "unsafe" +) + +type TerminalOutput = wasi_cli_0_2_0_terminal_output.TerminalOutput + +//go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr +func wasm_import_get_terminal_stderr(arg0 uintptr) + +func GetTerminalStderr() wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_get_terminal_stderr(returnArea) + var option wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() + case 1: + + option = wit_types.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + default: + panic("unreachable") + } + result := option + return result + +} diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go new file mode 100644 index 00000000..cc17659e --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go @@ -0,0 +1,67 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_terminal_stdin + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_input" + "runtime" + "unsafe" +) + +type TerminalInput = wasi_cli_0_2_0_terminal_input.TerminalInput + +//go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin +func wasm_import_get_terminal_stdin(arg0 uintptr) + +func GetTerminalStdin() wit_types.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_get_terminal_stdin(returnArea) + var option wit_types.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[*wasi_cli_0_2_0_terminal_input.TerminalInput]() + case 1: + + option = wit_types.Some[*wasi_cli_0_2_0_terminal_input.TerminalInput](wasi_cli_0_2_0_terminal_input.TerminalInputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + default: + panic("unreachable") + } + result := option + return result + +} diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go b/v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go new file mode 100644 index 00000000..bfe4e631 --- /dev/null +++ b/v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go @@ -0,0 +1,67 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_cli_0_2_0_terminal_stdout + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_output" + "runtime" + "unsafe" +) + +type TerminalOutput = wasi_cli_0_2_0_terminal_output.TerminalOutput + +//go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout +func wasm_import_get_terminal_stdout(arg0 uintptr) + +func GetTerminalStdout() wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_get_terminal_stdout(returnArea) + var option wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() + case 1: + + option = wit_types.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + default: + panic("unreachable") + } + result := option + return result + +} diff --git a/v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go b/v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go new file mode 100644 index 00000000..5e7fab74 --- /dev/null +++ b/v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go @@ -0,0 +1,86 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_clocks_0_2_0_monotonic_clock + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" +) + +type Pollable = wasi_io_0_2_0_poll.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 = uint64 + +// A duration of time, in nanoseconds. +type Duration = uint64 + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now +func wasm_import_now() int64 + +func Now() uint64 { + + result := wasm_import_now() + return uint64(result) + +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution +func wasm_import_resolution() int64 + +func Resolution() uint64 { + + result := wasm_import_resolution() + return uint64(result) + +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +func wasm_import_subscribe_instant(arg0 int64) int32 + +func SubscribeInstant(when uint64) *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_subscribe_instant(int64(when)) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +func wasm_import_subscribe_duration(arg0 int64) int32 + +func SubscribeDuration(when uint64) *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_subscribe_duration(int64(when)) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go b/v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go new file mode 100644 index 00000000..c1277fae --- /dev/null +++ b/v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go @@ -0,0 +1,72 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_clocks_0_2_0_wall_clock + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" + "unsafe" +) + +// A time and date in seconds plus nanoseconds. +type Datetime struct { + Seconds uint64 + Nanoseconds uint32 +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 now +func wasm_import_now(arg0 uintptr) + +func Now() Datetime { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_now(returnArea) + result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} + return result + +} + +//go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution +func wasm_import_resolution(arg0 uintptr) + +func Resolution() Datetime { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_resolution(returnArea) + result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} + return result + +} diff --git a/v3/internal/wasi_config_store/wit_bindings.go b/v3/internal/wasi_config_store/wit_bindings.go new file mode 100644 index 00000000..04d46033 --- /dev/null +++ b/v3/internal/wasi_config_store/wit_bindings.go @@ -0,0 +1,185 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_config_store + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + // This indicates an error from an "upstream" config source. + // As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), + // the error message is a string. + ErrorUpstream uint8 = 0 + // This indicates an error from an I/O operation. + // As this could be almost _anything_ (such as a file read, network connection, etc), + // the error message is a string. + // Depending on how this ends up being consumed, + // we may consider moving this to use the `wasi:io/error` type instead. + // For simplicity right now in supporting multiple implementations, it is being left as a string. + ErrorIo uint8 = 1 +) + +// An error type that encapsulates the different errors that can occur fetching configuration values. +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Upstream() string { + if self.tag != ErrorUpstream { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Io() string { + if self.tag != ErrorIo { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorUpstream(value string) Error { + return Error{ErrorUpstream, value} +} +func MakeErrorIo(value string) Error { + return Error{ErrorIo, value} +} + +//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get +func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Get(key string) wit_types.Result[wit_types.Option[string], Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Option[string], Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[string], Error](option) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorUpstream(value0) + + case 1: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value1) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[string], Error](variant) + default: + panic("unreachable") + } + result2 := result + return result2 + +} + +//go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get-all +func wasm_import_get_all(arg0 uintptr) + +func GetAll() wit_types.Result[[]wit_types.Tuple2[string, string], Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_get_all(returnArea) + var result3 wit_types.Result[[]wit_types.Tuple2[string, string], Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]wit_types.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(4*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) + + result = append(result, wit_types.Tuple2[string, string]{value, value0}) + } + + result3 = wit_types.Ok[[]wit_types.Tuple2[string, string], Error](result) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorUpstream(value1) + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value2) + + default: + panic("unreachable") + } + + result3 = wit_types.Err[[]wit_types.Tuple2[string, string], Error](variant) + default: + panic("unreachable") + } + result4 := result3 + return result4 + +} diff --git a/v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go b/v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go new file mode 100644 index 00000000..97873242 --- /dev/null +++ b/v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go @@ -0,0 +1,64 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_filesystem_0_2_0_preopens + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_filesystem_0_2_0_types" + "runtime" + "unsafe" +) + +type Descriptor = wasi_filesystem_0_2_0_types.Descriptor + +//go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories +func wasm_import_get_directories(arg0 uintptr) + +func GetDirectories() []wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_get_directories(returnArea) + result := make([]wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) + + result = append(result, wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string]{wasi_filesystem_0_2_0_types.DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(base), 0))))), value}) + } + + result0 := result + return result0 + +} diff --git a/v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go b/v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go new file mode 100644 index 00000000..a8eee20e --- /dev/null +++ b/v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go @@ -0,0 +1,1347 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_filesystem_0_2_0_types + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_clocks_0_2_0_wall_clock" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + "runtime" + "unsafe" +) + +type InputStream = wasi_io_0_2_0_streams.InputStream +type OutputStream = wasi_io_0_2_0_streams.OutputStream +type Error = wasi_io_0_2_0_error.Error +type Datetime = wasi_clocks_0_2_0_wall_clock.Datetime + +// File size or length of a region within a file. +type Filesize = uint64 + +const ( + // The type of the descriptor or file is unknown or is different from + // any of the other types specified. + DescriptorTypeUnknown uint8 = 0 + // The descriptor refers to a block device inode. + DescriptorTypeBlockDevice uint8 = 1 + // The descriptor refers to a character device inode. + DescriptorTypeCharacterDevice uint8 = 2 + // The descriptor refers to a directory inode. + DescriptorTypeDirectory uint8 = 3 + // The descriptor refers to a named pipe. + DescriptorTypeFifo uint8 = 4 + // The file refers to a symbolic link inode. + DescriptorTypeSymbolicLink uint8 = 5 + // The descriptor refers to a regular file inode. + DescriptorTypeRegularFile uint8 = 6 + // The descriptor refers to a socket. + DescriptorTypeSocket uint8 = 7 +) + +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. +type DescriptorType = uint8 + +const ( + // Read mode: Data can be read. + DescriptorFlagsRead uint8 = 1 << 0 + // Write mode: Data can be written to. + DescriptorFlagsWrite uint8 = 1 << 1 + // 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 uint8 = 1 << 2 + // 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 uint8 = 1 << 3 + // 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 uint8 = 1 << 4 + // 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 uint8 = 1 << 5 +) + +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. +type DescriptorFlags = uint8 + +const ( + // As long as the resolved path corresponds to a symbolic link, it is + // expanded. + PathFlagsSymlinkFollow uint8 = 1 << 0 +) + +// Flags determining the method of how paths are resolved. +type PathFlags = uint8 + +const ( + // Create file if it does not exist, similar to `O_CREAT` in POSIX. + OpenFlagsCreate uint8 = 1 << 0 + // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. + OpenFlagsDirectory uint8 = 1 << 1 + // Fail if file already exists, similar to `O_EXCL` in POSIX. + OpenFlagsExclusive uint8 = 1 << 2 + // Truncate file to size 0, similar to `O_TRUNC` in POSIX. + OpenFlagsTruncate uint8 = 1 << 3 +) + +// Open flags used by `open-at`. +type OpenFlags = uint8 + +// Number of hard links to an inode. +type LinkCount = uint64 + +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. +type DescriptorStat struct { + // File type. + Type DescriptorType + // Number of hard links to the file. + LinkCount uint64 + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + Size uint64 + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + DataAccessTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + DataModificationTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. + StatusChangeTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] +} + +const ( + // Leave the timestamp set to its previous value. + NewTimestampNoChange uint8 = 0 + // Set the timestamp to the current time of the system clock associated + // with the filesystem. + NewTimestampNow uint8 = 1 + // Set the timestamp to the given value. + NewTimestampTimestamp uint8 = 2 +) + +// When setting a timestamp, this gives the value to set it to. +type NewTimestamp struct { + tag uint8 + value any +} + +func (self NewTimestamp) Tag() uint8 { + return self.tag +} + +func (self NewTimestamp) Timestamp() wasi_clocks_0_2_0_wall_clock.Datetime { + if self.tag != NewTimestampTimestamp { + panic("tag mismatch") + } + return self.value.(wasi_clocks_0_2_0_wall_clock.Datetime) +} + +func MakeNewTimestampNoChange() NewTimestamp { + return NewTimestamp{NewTimestampNoChange, nil} +} +func MakeNewTimestampNow() NewTimestamp { + return NewTimestamp{NewTimestampNow, nil} +} +func MakeNewTimestampTimestamp(value wasi_clocks_0_2_0_wall_clock.Datetime) NewTimestamp { + return NewTimestamp{NewTimestampTimestamp, value} +} + +// A directory entry. +type DirectoryEntry struct { + // The type of the file referred to by this directory entry. + Type DescriptorType + // The name of the object. + Name string +} + +const ( + // Permission denied, similar to `EACCES` in POSIX. + ErrorCodeAccess uint8 = 0 + // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. + ErrorCodeWouldBlock uint8 = 1 + // Connection already in progress, similar to `EALREADY` in POSIX. + ErrorCodeAlready uint8 = 2 + // Bad descriptor, similar to `EBADF` in POSIX. + ErrorCodeBadDescriptor uint8 = 3 + // Device or resource busy, similar to `EBUSY` in POSIX. + ErrorCodeBusy uint8 = 4 + // Resource deadlock would occur, similar to `EDEADLK` in POSIX. + ErrorCodeDeadlock uint8 = 5 + // Storage quota exceeded, similar to `EDQUOT` in POSIX. + ErrorCodeQuota uint8 = 6 + // File exists, similar to `EEXIST` in POSIX. + ErrorCodeExist uint8 = 7 + // File too large, similar to `EFBIG` in POSIX. + ErrorCodeFileTooLarge uint8 = 8 + // Illegal byte sequence, similar to `EILSEQ` in POSIX. + ErrorCodeIllegalByteSequence uint8 = 9 + // Operation in progress, similar to `EINPROGRESS` in POSIX. + ErrorCodeInProgress uint8 = 10 + // Interrupted function, similar to `EINTR` in POSIX. + ErrorCodeInterrupted uint8 = 11 + // Invalid argument, similar to `EINVAL` in POSIX. + ErrorCodeInvalid uint8 = 12 + // I/O error, similar to `EIO` in POSIX. + ErrorCodeIo uint8 = 13 + // Is a directory, similar to `EISDIR` in POSIX. + ErrorCodeIsDirectory uint8 = 14 + // Too many levels of symbolic links, similar to `ELOOP` in POSIX. + ErrorCodeLoop uint8 = 15 + // Too many links, similar to `EMLINK` in POSIX. + ErrorCodeTooManyLinks uint8 = 16 + // Message too large, similar to `EMSGSIZE` in POSIX. + ErrorCodeMessageSize uint8 = 17 + // Filename too long, similar to `ENAMETOOLONG` in POSIX. + ErrorCodeNameTooLong uint8 = 18 + // No such device, similar to `ENODEV` in POSIX. + ErrorCodeNoDevice uint8 = 19 + // No such file or directory, similar to `ENOENT` in POSIX. + ErrorCodeNoEntry uint8 = 20 + // No locks available, similar to `ENOLCK` in POSIX. + ErrorCodeNoLock uint8 = 21 + // Not enough space, similar to `ENOMEM` in POSIX. + ErrorCodeInsufficientMemory uint8 = 22 + // No space left on device, similar to `ENOSPC` in POSIX. + ErrorCodeInsufficientSpace uint8 = 23 + // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. + ErrorCodeNotDirectory uint8 = 24 + // Directory not empty, similar to `ENOTEMPTY` in POSIX. + ErrorCodeNotEmpty uint8 = 25 + // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. + ErrorCodeNotRecoverable uint8 = 26 + // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. + ErrorCodeUnsupported uint8 = 27 + // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. + ErrorCodeNoTty uint8 = 28 + // No such device or address, similar to `ENXIO` in POSIX. + ErrorCodeNoSuchDevice uint8 = 29 + // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. + ErrorCodeOverflow uint8 = 30 + // Operation not permitted, similar to `EPERM` in POSIX. + ErrorCodeNotPermitted uint8 = 31 + // Broken pipe, similar to `EPIPE` in POSIX. + ErrorCodePipe uint8 = 32 + // Read-only file system, similar to `EROFS` in POSIX. + ErrorCodeReadOnly uint8 = 33 + // Invalid seek, similar to `ESPIPE` in POSIX. + ErrorCodeInvalidSeek uint8 = 34 + // Text file busy, similar to `ETXTBSY` in POSIX. + ErrorCodeTextFileBusy uint8 = 35 + // Cross-device link, similar to `EXDEV` in POSIX. + ErrorCodeCrossDevice uint8 = 36 +) + +// 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. +type ErrorCode = uint8 + +const ( + // The application has no advice to give on its behavior with respect + // to the specified data. + AdviceNormal uint8 = 0 + // The application expects to access the specified data sequentially + // from lower offsets to higher offsets. + AdviceSequential uint8 = 1 + // The application expects to access the specified data in a random + // order. + AdviceRandom uint8 = 2 + // The application expects to access the specified data in the near + // future. + AdviceWillNeed uint8 = 3 + // The application expects that it will not access the specified data + // in the near future. + AdviceDontNeed uint8 = 4 + // The application expects to access the specified data once and then + // not reuse it thereafter. + AdviceNoReuse uint8 = 5 +) + +// File or memory access pattern advisory information. +type Advice = uint8 + +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. +type MetadataHashValue struct { + // 64 bits of a 128-bit hash value. + Lower uint64 + // Another 64 bits of a 128-bit hash value. + Upper uint64 +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor +func resourceDropDescriptor(handle int32) + +// 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. +type Descriptor struct { + handle *wit_runtime.Handle +} + +func (self *Descriptor) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Descriptor) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Descriptor) Handle() int32 { + return self.handle.Use() +} + +func (self *Descriptor) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropDescriptor(handle) + } +} + +func DescriptorFromOwnHandle(handleValue int32) *Descriptor { + handle := wit_runtime.MakeHandle(handleValue) + value := &Descriptor{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropDescriptor(handleValue) + } + }, 0) + return value +} + +func DescriptorFromBorrowHandle(handleValue int32) *Descriptor { + return DescriptorFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +func resourceDropDirectoryEntryStream(handle int32) + +// A stream of directory entries. +type DirectoryEntryStream struct { + handle *wit_runtime.Handle +} + +func (self *DirectoryEntryStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *DirectoryEntryStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *DirectoryEntryStream) Handle() int32 { + return self.handle.Use() +} + +func (self *DirectoryEntryStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropDirectoryEntryStream(handle) + } +} + +func DirectoryEntryStreamFromOwnHandle(handleValue int32) *DirectoryEntryStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &DirectoryEntryStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropDirectoryEntryStream(handleValue) + } + }, 0) + return value +} + +func DirectoryEntryStreamFromBorrowHandle(handleValue int32) *DirectoryEntryStream { + return DirectoryEntryStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +func wasm_import_method_descriptor_read_via_stream(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *Descriptor) ReadViaStream(offset uint64) wit_types.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_descriptor_read_via_stream((self).Handle(), int64(offset), returnArea) + var result wit_types.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_io_0_2_0_streams.InputStream, ErrorCode](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_io_0_2_0_streams.InputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +func wasm_import_method_descriptor_write_via_stream(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *Descriptor) WriteViaStream(offset uint64) wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_descriptor_write_via_stream((self).Handle(), int64(offset), returnArea) + var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream +func wasm_import_method_descriptor_append_via_stream(arg0 int32, arg1 uintptr) + +func (self *Descriptor) AppendViaStream() wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_descriptor_append_via_stream((self).Handle(), returnArea) + var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise +func wasm_import_method_descriptor_advise(arg0 int32, arg1 int64, arg2 int64, arg3 int32, arg4 uintptr) + +func (self *Descriptor) Advise(offset uint64, length uint64, advice Advice) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_advise((self).Handle(), int64(offset), int64(length), int32(advice), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +func wasm_import_method_descriptor_sync_data(arg0 int32, arg1 uintptr) + +func (self *Descriptor) SyncData() wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_sync_data((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags +func wasm_import_method_descriptor_get_flags(arg0 int32, arg1 uintptr) + +func (self *Descriptor) GetFlags() wit_types.Result[DescriptorFlags, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_get_flags((self).Handle(), returnArea) + var result wit_types.Result[DescriptorFlags, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + case 1: + + result = wit_types.Err[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type +func wasm_import_method_descriptor_get_type(arg0 int32, arg1 uintptr) + +func (self *Descriptor) GetType() wit_types.Result[DescriptorType, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_get_type((self).Handle(), returnArea) + var result wit_types.Result[DescriptorType, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + case 1: + + result = wit_types.Err[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +func wasm_import_method_descriptor_set_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *Descriptor) SetSize(size uint64) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_set_size((self).Handle(), int64(size), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +func wasm_import_method_descriptor_set_times(arg0 int32, arg1 int32, arg2 int64, arg3 int32, arg4 int32, arg5 int64, arg6 int32, arg7 uintptr) + +func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + var variant int32 + var variant0 int64 + var variant1 int32 + switch dataAccessTimestamp.Tag() { + case NewTimestampNoChange: + + variant = int32(0) + variant0 = 0 + variant1 = 0 + + case NewTimestampNow: + + variant = int32(1) + variant0 = 0 + variant1 = 0 + + case NewTimestampTimestamp: + payload := dataAccessTimestamp.Timestamp() + + variant = int32(2) + variant0 = int64((payload).Seconds) + variant1 = int32((payload).Nanoseconds) + + default: + panic("unreachable") + } + var variant2 int32 + var variant3 int64 + var variant4 int32 + switch dataModificationTimestamp.Tag() { + case NewTimestampNoChange: + + variant2 = int32(0) + variant3 = 0 + variant4 = 0 + + case NewTimestampNow: + + variant2 = int32(1) + variant3 = 0 + variant4 = 0 + + case NewTimestampTimestamp: + payload := dataModificationTimestamp.Timestamp() + + variant2 = int32(2) + variant3 = int64((payload).Seconds) + variant4 = int32((payload).Nanoseconds) + + default: + panic("unreachable") + } + wasm_import_method_descriptor_set_times((self).Handle(), variant, variant0, variant1, variant2, variant3, variant4, returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result5 := result + return result5 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +func wasm_import_method_descriptor_read(arg0 int32, arg1 int64, arg2 int64, arg3 uintptr) + +func (self *Descriptor) Read(length uint64, offset uint64) wit_types.Result[wit_types.Tuple2[[]uint8, bool], ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_method_descriptor_read((self).Handle(), int64(length), int64(offset), returnArea) + var result wit_types.Result[wit_types.Tuple2[[]uint8, bool], ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[wit_types.Tuple2[[]uint8, bool], ErrorCode](wit_types.Tuple2[[]uint8, bool]{value, (uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) != 0)}) + case 1: + + result = wit_types.Err[wit_types.Tuple2[[]uint8, bool], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +func wasm_import_method_descriptor_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int64, arg4 uintptr) + +func (self *Descriptor) Write(buffer []uint8, offset uint64) wit_types.Result[uint64, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + data := unsafe.Pointer(unsafe.SliceData(buffer)) + pinner.Pin(data) + wasm_import_method_descriptor_write((self).Handle(), uintptr(data), uint32(len(buffer)), int64(offset), returnArea) + var result wit_types.Result[uint64, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +func wasm_import_method_descriptor_read_directory(arg0 int32, arg1 uintptr) + +func (self *Descriptor) ReadDirectory() wit_types.Result[*DirectoryEntryStream, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_descriptor_read_directory((self).Handle(), returnArea) + var result wit_types.Result[*DirectoryEntryStream, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*DirectoryEntryStream, ErrorCode](DirectoryEntryStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*DirectoryEntryStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +func wasm_import_method_descriptor_sync(arg0 int32, arg1 uintptr) + +func (self *Descriptor) Sync() wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_descriptor_sync((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at +func wasm_import_method_descriptor_create_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Descriptor) CreateDirectoryAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_create_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +func wasm_import_method_descriptor_stat(arg0 int32, arg1 uintptr) + +func (self *Descriptor) Stat() wit_types.Result[DescriptorStat, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 104, 8)) + wasm_import_method_descriptor_stat((self).Handle(), returnArea) + var result wit_types.Result[DescriptorStat, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) + default: + panic("unreachable") + } + var option0 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) { + case 0: + + option0 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option0 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) + default: + panic("unreachable") + } + var option1 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) { + case 0: + + option1 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option1 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) + default: + panic("unreachable") + } + + result = wit_types.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) + case 1: + + result = wit_types.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result2 := result + return result2 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +func wasm_import_method_descriptor_stat_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func (self *Descriptor) StatAt(pathFlags PathFlags, path string) wit_types.Result[DescriptorStat, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 104, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_stat_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[DescriptorStat, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) + default: + panic("unreachable") + } + var option0 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) { + case 0: + + option0 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option0 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) + default: + panic("unreachable") + } + var option1 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) { + case 0: + + option1 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + case 1: + + option1 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) + default: + panic("unreachable") + } + + result = wit_types.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) + case 1: + + result = wit_types.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result2 := result + return result2 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +func wasm_import_method_descriptor_set_times_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int64, arg6 int32, arg7 int32, arg8 int64, arg9 int32, arg10 uintptr) + +func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + var variant int32 + var variant0 int64 + var variant1 int32 + switch dataAccessTimestamp.Tag() { + case NewTimestampNoChange: + + variant = int32(0) + variant0 = 0 + variant1 = 0 + + case NewTimestampNow: + + variant = int32(1) + variant0 = 0 + variant1 = 0 + + case NewTimestampTimestamp: + payload := dataAccessTimestamp.Timestamp() + + variant = int32(2) + variant0 = int64((payload).Seconds) + variant1 = int32((payload).Nanoseconds) + + default: + panic("unreachable") + } + var variant2 int32 + var variant3 int64 + var variant4 int32 + switch dataModificationTimestamp.Tag() { + case NewTimestampNoChange: + + variant2 = int32(0) + variant3 = 0 + variant4 = 0 + + case NewTimestampNow: + + variant2 = int32(1) + variant3 = 0 + variant4 = 0 + + case NewTimestampTimestamp: + payload := dataModificationTimestamp.Timestamp() + + variant2 = int32(2) + variant3 = int64((payload).Seconds) + variant4 = int32((payload).Nanoseconds) + + default: + panic("unreachable") + } + wasm_import_method_descriptor_set_times_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), variant, variant0, variant1, variant2, variant3, variant4, returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result5 := result + return result5 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +func wasm_import_method_descriptor_link_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 uintptr, arg6 uint32, arg7 uintptr) + +func (self *Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor *Descriptor, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(newPath)) + pinner.Pin(utf80) + wasm_import_method_descriptor_link_at((self).Handle(), int32(oldPathFlags), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at +func wasm_import_method_descriptor_open_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 uintptr) + +func (self *Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) wit_types.Result[*Descriptor, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_open_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), int32(openFlags), int32(flags), returnArea) + var result wit_types.Result[*Descriptor, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Descriptor, ErrorCode](DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*Descriptor, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +func wasm_import_method_descriptor_readlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Descriptor) ReadlinkAt(path string) wit_types.Result[string, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_readlink_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[string, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[string, ErrorCode](value) + case 1: + + result = wit_types.Err[string, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +func wasm_import_method_descriptor_remove_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Descriptor) RemoveDirectoryAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_remove_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +func wasm_import_method_descriptor_rename_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func (self *Descriptor) RenameAt(oldPath string, newDescriptor *Descriptor, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(newPath)) + pinner.Pin(utf80) + wasm_import_method_descriptor_rename_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +func wasm_import_method_descriptor_symlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Descriptor) SymlinkAt(oldPath string, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(newPath)) + pinner.Pin(utf80) + wasm_import_method_descriptor_symlink_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), uintptr(utf80), uint32(len(newPath)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +func wasm_import_method_descriptor_unlink_file_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Descriptor) UnlinkFileAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_unlink_file_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object +func wasm_import_method_descriptor_is_same_object(arg0 int32, arg1 int32) int32 + +func (self *Descriptor) IsSameObject(other *Descriptor) bool { + + result := wasm_import_method_descriptor_is_same_object((self).Handle(), (other).Handle()) + return (result != 0) + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +func wasm_import_method_descriptor_metadata_hash(arg0 int32, arg1 uintptr) + +func (self *Descriptor) MetadataHash() wit_types.Result[MetadataHashValue, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 24, 8)) + wasm_import_method_descriptor_metadata_hash((self).Handle(), returnArea) + var result wit_types.Result[MetadataHashValue, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) + case 1: + + result = wit_types.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at +func wasm_import_method_descriptor_metadata_hash_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func (self *Descriptor) MetadataHashAt(pathFlags PathFlags, path string) wit_types.Result[MetadataHashValue, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 24, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(path)) + pinner.Pin(utf8) + wasm_import_method_descriptor_metadata_hash_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea) + var result wit_types.Result[MetadataHashValue, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) + case 1: + + result = wit_types.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +func wasm_import_method_directory_entry_stream_read_directory_entry(arg0 int32, arg1 uintptr) + +func (self *DirectoryEntryStream) ReadDirectoryEntry() wit_types.Result[wit_types.Option[DirectoryEntry], ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + wasm_import_method_directory_entry_stream_read_directory_entry((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Option[DirectoryEntry], ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[DirectoryEntry] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[DirectoryEntry]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + + option = wit_types.Some[DirectoryEntry](DirectoryEntry{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))), value}) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[DirectoryEntry], ErrorCode](option) + case 1: + + result = wit_types.Err[wit_types.Option[DirectoryEntry], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code +func wasm_import_filesystem_error_code(arg0 int32, arg1 uintptr) + +func FilesystemErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_filesystem_error_code((err).Handle(), returnArea) + var option wit_types.Option[ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[ErrorCode]() + case 1: + + option = wit_types.Some[ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result := option + return result + +} diff --git a/v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go b/v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go new file mode 100644 index 00000000..bda1d9fa --- /dev/null +++ b/v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go @@ -0,0 +1,39 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_http_0_2_0_incoming_handler + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" +) + +type IncomingRequest = wasi_http_0_2_0_types.IncomingRequest +type ResponseOutparam = wasi_http_0_2_0_types.ResponseOutparam diff --git a/v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go b/v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go new file mode 100644 index 00000000..ff4036af --- /dev/null +++ b/v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go @@ -0,0 +1,497 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_http_0_2_0_outgoing_handler + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + "runtime" + "unsafe" +) + +type OutgoingRequest = wasi_http_0_2_0_types.OutgoingRequest +type RequestOptions = wasi_http_0_2_0_types.RequestOptions +type FutureIncomingResponse = wasi_http_0_2_0_types.FutureIncomingResponse +type ErrorCode = wasi_http_0_2_0_types.ErrorCode + +//go:wasmimport wasi:http/outgoing-handler@0.2.0 handle +func wasm_import_handle(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr) + +func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Option[*wasi_http_0_2_0_types.RequestOptions]) wit_types.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + var option int32 + var option0 int32 + switch options.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + case wit_types.OptionSome: + payload := options.Some() + + option = int32(1) + option0 = (payload).TakeHandle() + default: + panic("unreachable") + } + wasm_import_handle((request).TakeHandle(), option, option0, returnArea) + var result wit_types.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](wasi_http_0_2_0_types.FutureIncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + case 1: + var variant wasi_http_0_2_0_types.ErrorCode + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = wasi_http_0_2_0_types.MakeErrorCodeDnsTimeout() + + case 1: + var option1 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option1 = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option1 = wit_types.Some[string](value) + default: + panic("unreachable") + } + var option2 wit_types.Option[uint16] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option2 = wit_types.None[uint16]() + case 1: + + option2 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeDnsError(wasi_http_0_2_0_types.DnsErrorPayload{option1, option2}) + + case 2: + + variant = wasi_http_0_2_0_types.MakeErrorCodeDestinationNotFound() + + case 3: + + variant = wasi_http_0_2_0_types.MakeErrorCodeDestinationUnavailable() + + case 4: + + variant = wasi_http_0_2_0_types.MakeErrorCodeDestinationIpProhibited() + + case 5: + + variant = wasi_http_0_2_0_types.MakeErrorCodeDestinationIpUnroutable() + + case 6: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionRefused() + + case 7: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionTerminated() + + case 8: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionTimeout() + + case 9: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionReadTimeout() + + case 10: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionWriteTimeout() + + case 11: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConnectionLimitReached() + + case 12: + + variant = wasi_http_0_2_0_types.MakeErrorCodeTlsProtocolError() + + case 13: + + variant = wasi_http_0_2_0_types.MakeErrorCodeTlsCertificateError() + + case 14: + var option3 wit_types.Option[uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option3 = wit_types.None[uint8]() + case 1: + + option3 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + default: + panic("unreachable") + } + var option5 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option5 = wit_types.None[string]() + case 1: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option5 = wit_types.Some[string](value4) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeTlsAlertReceived(wasi_http_0_2_0_types.TlsAlertReceivedPayload{option3, option5}) + + case 15: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestDenied() + + case 16: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestLengthRequired() + + case 17: + var option6 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option6 = wit_types.None[uint64]() + case 1: + + option6 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestBodySize(option6) + + case 18: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestMethodInvalid() + + case 19: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestUriInvalid() + + case 20: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestUriTooLong() + + case 21: + var option7 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option7 = wit_types.None[uint32]() + case 1: + + option7 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestHeaderSectionSize(option7) + + case 22: + var option11 wit_types.Option[wasi_http_0_2_0_types.FieldSizePayload] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option11 = wit_types.None[wasi_http_0_2_0_types.FieldSizePayload]() + case 1: + var option9 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option9 = wit_types.None[string]() + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option9 = wit_types.Some[string](value8) + default: + panic("unreachable") + } + var option10 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { + case 0: + + option10 = wit_types.None[uint32]() + case 1: + + option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + default: + panic("unreachable") + } + + option11 = wit_types.Some[wasi_http_0_2_0_types.FieldSizePayload](wasi_http_0_2_0_types.FieldSizePayload{option9, option10}) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestHeaderSize(option11) + + case 23: + var option12 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option12 = wit_types.None[uint32]() + case 1: + + option12 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestTrailerSectionSize(option12) + + case 24: + var option14 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option14 = wit_types.None[string]() + case 1: + value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option14 = wit_types.Some[string](value13) + default: + panic("unreachable") + } + var option15 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option15 = wit_types.None[uint32]() + case 1: + + option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestTrailerSize(wasi_http_0_2_0_types.FieldSizePayload{option14, option15}) + + case 25: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseIncomplete() + + case 26: + var option16 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option16 = wit_types.None[uint32]() + case 1: + + option16 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseHeaderSectionSize(option16) + + case 27: + var option18 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option18 = wit_types.None[string]() + case 1: + value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option18 = wit_types.Some[string](value17) + default: + panic("unreachable") + } + var option19 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option19 = wit_types.None[uint32]() + case 1: + + option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseHeaderSize(wasi_http_0_2_0_types.FieldSizePayload{option18, option19}) + + case 28: + var option20 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option20 = wit_types.None[uint64]() + case 1: + + option20 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseBodySize(option20) + + case 29: + var option21 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option21 = wit_types.None[uint32]() + case 1: + + option21 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTrailerSectionSize(option21) + + case 30: + var option23 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option23 = wit_types.None[string]() + case 1: + value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option23 = wit_types.Some[string](value22) + default: + panic("unreachable") + } + var option24 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option24 = wit_types.None[uint32]() + case 1: + + option24 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTrailerSize(wasi_http_0_2_0_types.FieldSizePayload{option23, option24}) + + case 31: + var option26 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option26 = wit_types.None[string]() + case 1: + value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option26 = wit_types.Some[string](value25) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTransferCoding(option26) + + case 32: + var option28 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option28 = wit_types.None[string]() + case 1: + value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option28 = wit_types.Some[string](value27) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseContentCoding(option28) + + case 33: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTimeout() + + case 34: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpUpgradeFailed() + + case 35: + + variant = wasi_http_0_2_0_types.MakeErrorCodeHttpProtocolError() + + case 36: + + variant = wasi_http_0_2_0_types.MakeErrorCodeLoopDetected() + + case 37: + + variant = wasi_http_0_2_0_types.MakeErrorCodeConfigurationError() + + case 38: + var option30 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option30 = wit_types.None[string]() + case 1: + value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option30 = wit_types.Some[string](value29) + default: + panic("unreachable") + } + + variant = wasi_http_0_2_0_types.MakeErrorCodeInternalError(option30) + + default: + panic("unreachable") + } + + result = wit_types.Err[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](variant) + default: + panic("unreachable") + } + result31 := result + return result31 + +} diff --git a/v3/internal/wasi_http_0_2_0_types/wit_bindings.go b/v3/internal/wasi_http_0_2_0_types/wit_bindings.go new file mode 100644 index 00000000..ff5988cf --- /dev/null +++ b/v3/internal/wasi_http_0_2_0_types/wit_bindings.go @@ -0,0 +1,4986 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_http_0_2_0_types + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + "runtime" + "unsafe" +) + +type Duration = uint64 +type InputStream = wasi_io_0_2_0_streams.InputStream +type OutputStream = wasi_io_0_2_0_streams.OutputStream +type IoError = wasi_io_0_2_0_error.Error +type Pollable = wasi_io_0_2_0_poll.Pollable + +const ( + MethodGet uint8 = 0 + MethodHead uint8 = 1 + MethodPost uint8 = 2 + MethodPut uint8 = 3 + MethodDelete uint8 = 4 + MethodConnect uint8 = 5 + MethodOptions uint8 = 6 + MethodTrace uint8 = 7 + MethodPatch uint8 = 8 + MethodOther uint8 = 9 +) + +// This type corresponds to HTTP standard Methods. +type Method struct { + tag uint8 + value any +} + +func (self Method) Tag() uint8 { + return self.tag +} + +func (self Method) Other() string { + if self.tag != MethodOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeMethodGet() Method { + return Method{MethodGet, nil} +} +func MakeMethodHead() Method { + return Method{MethodHead, nil} +} +func MakeMethodPost() Method { + return Method{MethodPost, nil} +} +func MakeMethodPut() Method { + return Method{MethodPut, nil} +} +func MakeMethodDelete() Method { + return Method{MethodDelete, nil} +} +func MakeMethodConnect() Method { + return Method{MethodConnect, nil} +} +func MakeMethodOptions() Method { + return Method{MethodOptions, nil} +} +func MakeMethodTrace() Method { + return Method{MethodTrace, nil} +} +func MakeMethodPatch() Method { + return Method{MethodPatch, nil} +} +func MakeMethodOther(value string) Method { + return Method{MethodOther, value} +} + +const ( + SchemeHttp uint8 = 0 + SchemeHttps uint8 = 1 + SchemeOther uint8 = 2 +) + +// This type corresponds to HTTP standard Related Schemes. +type Scheme struct { + tag uint8 + value any +} + +func (self Scheme) Tag() uint8 { + return self.tag +} + +func (self Scheme) Other() string { + if self.tag != SchemeOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeSchemeHttp() Scheme { + return Scheme{SchemeHttp, nil} +} +func MakeSchemeHttps() Scheme { + return Scheme{SchemeHttps, nil} +} +func MakeSchemeOther(value string) Scheme { + return Scheme{SchemeOther, value} +} + +// Defines the case payload type for `DNS-error` above: +type DnsErrorPayload struct { + Rcode wit_types.Option[string] + InfoCode wit_types.Option[uint16] +} + +// Defines the case payload type for `TLS-alert-received` above: +type TlsAlertReceivedPayload struct { + AlertId wit_types.Option[uint8] + AlertMessage wit_types.Option[string] +} + +// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: +type FieldSizePayload struct { + FieldName wit_types.Option[string] + FieldSize wit_types.Option[uint32] +} + +const ( + ErrorCodeDnsTimeout uint8 = 0 + ErrorCodeDnsError uint8 = 1 + ErrorCodeDestinationNotFound uint8 = 2 + ErrorCodeDestinationUnavailable uint8 = 3 + ErrorCodeDestinationIpProhibited uint8 = 4 + ErrorCodeDestinationIpUnroutable uint8 = 5 + ErrorCodeConnectionRefused uint8 = 6 + ErrorCodeConnectionTerminated uint8 = 7 + ErrorCodeConnectionTimeout uint8 = 8 + ErrorCodeConnectionReadTimeout uint8 = 9 + ErrorCodeConnectionWriteTimeout uint8 = 10 + ErrorCodeConnectionLimitReached uint8 = 11 + ErrorCodeTlsProtocolError uint8 = 12 + ErrorCodeTlsCertificateError uint8 = 13 + ErrorCodeTlsAlertReceived uint8 = 14 + ErrorCodeHttpRequestDenied uint8 = 15 + ErrorCodeHttpRequestLengthRequired uint8 = 16 + ErrorCodeHttpRequestBodySize uint8 = 17 + ErrorCodeHttpRequestMethodInvalid uint8 = 18 + ErrorCodeHttpRequestUriInvalid uint8 = 19 + ErrorCodeHttpRequestUriTooLong uint8 = 20 + ErrorCodeHttpRequestHeaderSectionSize uint8 = 21 + ErrorCodeHttpRequestHeaderSize uint8 = 22 + ErrorCodeHttpRequestTrailerSectionSize uint8 = 23 + ErrorCodeHttpRequestTrailerSize uint8 = 24 + ErrorCodeHttpResponseIncomplete uint8 = 25 + ErrorCodeHttpResponseHeaderSectionSize uint8 = 26 + ErrorCodeHttpResponseHeaderSize uint8 = 27 + ErrorCodeHttpResponseBodySize uint8 = 28 + ErrorCodeHttpResponseTrailerSectionSize uint8 = 29 + ErrorCodeHttpResponseTrailerSize uint8 = 30 + ErrorCodeHttpResponseTransferCoding uint8 = 31 + ErrorCodeHttpResponseContentCoding uint8 = 32 + ErrorCodeHttpResponseTimeout uint8 = 33 + ErrorCodeHttpUpgradeFailed uint8 = 34 + ErrorCodeHttpProtocolError uint8 = 35 + ErrorCodeLoopDetected uint8 = 36 + ErrorCodeConfigurationError uint8 = 37 + // 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. + ErrorCodeInternalError uint8 = 38 +) + +// 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 +type ErrorCode struct { + tag uint8 + value any +} + +func (self ErrorCode) Tag() uint8 { + return self.tag +} + +func (self ErrorCode) DnsError() DnsErrorPayload { + if self.tag != ErrorCodeDnsError { + panic("tag mismatch") + } + return self.value.(DnsErrorPayload) +} +func (self ErrorCode) TlsAlertReceived() TlsAlertReceivedPayload { + if self.tag != ErrorCodeTlsAlertReceived { + panic("tag mismatch") + } + return self.value.(TlsAlertReceivedPayload) +} +func (self ErrorCode) HttpRequestBodySize() wit_types.Option[uint64] { + if self.tag != ErrorCodeHttpRequestBodySize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint64]) +} +func (self ErrorCode) HttpRequestHeaderSectionSize() wit_types.Option[uint32] { + if self.tag != ErrorCodeHttpRequestHeaderSectionSize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint32]) +} +func (self ErrorCode) HttpRequestHeaderSize() wit_types.Option[FieldSizePayload] { + if self.tag != ErrorCodeHttpRequestHeaderSize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[FieldSizePayload]) +} +func (self ErrorCode) HttpRequestTrailerSectionSize() wit_types.Option[uint32] { + if self.tag != ErrorCodeHttpRequestTrailerSectionSize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint32]) +} +func (self ErrorCode) HttpRequestTrailerSize() FieldSizePayload { + if self.tag != ErrorCodeHttpRequestTrailerSize { + panic("tag mismatch") + } + return self.value.(FieldSizePayload) +} +func (self ErrorCode) HttpResponseHeaderSectionSize() wit_types.Option[uint32] { + if self.tag != ErrorCodeHttpResponseHeaderSectionSize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint32]) +} +func (self ErrorCode) HttpResponseHeaderSize() FieldSizePayload { + if self.tag != ErrorCodeHttpResponseHeaderSize { + panic("tag mismatch") + } + return self.value.(FieldSizePayload) +} +func (self ErrorCode) HttpResponseBodySize() wit_types.Option[uint64] { + if self.tag != ErrorCodeHttpResponseBodySize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint64]) +} +func (self ErrorCode) HttpResponseTrailerSectionSize() wit_types.Option[uint32] { + if self.tag != ErrorCodeHttpResponseTrailerSectionSize { + panic("tag mismatch") + } + return self.value.(wit_types.Option[uint32]) +} +func (self ErrorCode) HttpResponseTrailerSize() FieldSizePayload { + if self.tag != ErrorCodeHttpResponseTrailerSize { + panic("tag mismatch") + } + return self.value.(FieldSizePayload) +} +func (self ErrorCode) HttpResponseTransferCoding() wit_types.Option[string] { + if self.tag != ErrorCodeHttpResponseTransferCoding { + panic("tag mismatch") + } + return self.value.(wit_types.Option[string]) +} +func (self ErrorCode) HttpResponseContentCoding() wit_types.Option[string] { + if self.tag != ErrorCodeHttpResponseContentCoding { + panic("tag mismatch") + } + return self.value.(wit_types.Option[string]) +} +func (self ErrorCode) InternalError() wit_types.Option[string] { + if self.tag != ErrorCodeInternalError { + panic("tag mismatch") + } + return self.value.(wit_types.Option[string]) +} + +func MakeErrorCodeDnsTimeout() ErrorCode { + return ErrorCode{ErrorCodeDnsTimeout, nil} +} +func MakeErrorCodeDnsError(value DnsErrorPayload) ErrorCode { + return ErrorCode{ErrorCodeDnsError, value} +} +func MakeErrorCodeDestinationNotFound() ErrorCode { + return ErrorCode{ErrorCodeDestinationNotFound, nil} +} +func MakeErrorCodeDestinationUnavailable() ErrorCode { + return ErrorCode{ErrorCodeDestinationUnavailable, nil} +} +func MakeErrorCodeDestinationIpProhibited() ErrorCode { + return ErrorCode{ErrorCodeDestinationIpProhibited, nil} +} +func MakeErrorCodeDestinationIpUnroutable() ErrorCode { + return ErrorCode{ErrorCodeDestinationIpUnroutable, nil} +} +func MakeErrorCodeConnectionRefused() ErrorCode { + return ErrorCode{ErrorCodeConnectionRefused, nil} +} +func MakeErrorCodeConnectionTerminated() ErrorCode { + return ErrorCode{ErrorCodeConnectionTerminated, nil} +} +func MakeErrorCodeConnectionTimeout() ErrorCode { + return ErrorCode{ErrorCodeConnectionTimeout, nil} +} +func MakeErrorCodeConnectionReadTimeout() ErrorCode { + return ErrorCode{ErrorCodeConnectionReadTimeout, nil} +} +func MakeErrorCodeConnectionWriteTimeout() ErrorCode { + return ErrorCode{ErrorCodeConnectionWriteTimeout, nil} +} +func MakeErrorCodeConnectionLimitReached() ErrorCode { + return ErrorCode{ErrorCodeConnectionLimitReached, nil} +} +func MakeErrorCodeTlsProtocolError() ErrorCode { + return ErrorCode{ErrorCodeTlsProtocolError, nil} +} +func MakeErrorCodeTlsCertificateError() ErrorCode { + return ErrorCode{ErrorCodeTlsCertificateError, nil} +} +func MakeErrorCodeTlsAlertReceived(value TlsAlertReceivedPayload) ErrorCode { + return ErrorCode{ErrorCodeTlsAlertReceived, value} +} +func MakeErrorCodeHttpRequestDenied() ErrorCode { + return ErrorCode{ErrorCodeHttpRequestDenied, nil} +} +func MakeErrorCodeHttpRequestLengthRequired() ErrorCode { + return ErrorCode{ErrorCodeHttpRequestLengthRequired, nil} +} +func MakeErrorCodeHttpRequestBodySize(value wit_types.Option[uint64]) ErrorCode { + return ErrorCode{ErrorCodeHttpRequestBodySize, value} +} +func MakeErrorCodeHttpRequestMethodInvalid() ErrorCode { + return ErrorCode{ErrorCodeHttpRequestMethodInvalid, nil} +} +func MakeErrorCodeHttpRequestUriInvalid() ErrorCode { + return ErrorCode{ErrorCodeHttpRequestUriInvalid, nil} +} +func MakeErrorCodeHttpRequestUriTooLong() ErrorCode { + return ErrorCode{ErrorCodeHttpRequestUriTooLong, nil} +} +func MakeErrorCodeHttpRequestHeaderSectionSize(value wit_types.Option[uint32]) ErrorCode { + return ErrorCode{ErrorCodeHttpRequestHeaderSectionSize, value} +} +func MakeErrorCodeHttpRequestHeaderSize(value wit_types.Option[FieldSizePayload]) ErrorCode { + return ErrorCode{ErrorCodeHttpRequestHeaderSize, value} +} +func MakeErrorCodeHttpRequestTrailerSectionSize(value wit_types.Option[uint32]) ErrorCode { + return ErrorCode{ErrorCodeHttpRequestTrailerSectionSize, value} +} +func MakeErrorCodeHttpRequestTrailerSize(value FieldSizePayload) ErrorCode { + return ErrorCode{ErrorCodeHttpRequestTrailerSize, value} +} +func MakeErrorCodeHttpResponseIncomplete() ErrorCode { + return ErrorCode{ErrorCodeHttpResponseIncomplete, nil} +} +func MakeErrorCodeHttpResponseHeaderSectionSize(value wit_types.Option[uint32]) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseHeaderSectionSize, value} +} +func MakeErrorCodeHttpResponseHeaderSize(value FieldSizePayload) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseHeaderSize, value} +} +func MakeErrorCodeHttpResponseBodySize(value wit_types.Option[uint64]) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseBodySize, value} +} +func MakeErrorCodeHttpResponseTrailerSectionSize(value wit_types.Option[uint32]) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseTrailerSectionSize, value} +} +func MakeErrorCodeHttpResponseTrailerSize(value FieldSizePayload) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseTrailerSize, value} +} +func MakeErrorCodeHttpResponseTransferCoding(value wit_types.Option[string]) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseTransferCoding, value} +} +func MakeErrorCodeHttpResponseContentCoding(value wit_types.Option[string]) ErrorCode { + return ErrorCode{ErrorCodeHttpResponseContentCoding, value} +} +func MakeErrorCodeHttpResponseTimeout() ErrorCode { + return ErrorCode{ErrorCodeHttpResponseTimeout, nil} +} +func MakeErrorCodeHttpUpgradeFailed() ErrorCode { + return ErrorCode{ErrorCodeHttpUpgradeFailed, nil} +} +func MakeErrorCodeHttpProtocolError() ErrorCode { + return ErrorCode{ErrorCodeHttpProtocolError, nil} +} +func MakeErrorCodeLoopDetected() ErrorCode { + return ErrorCode{ErrorCodeLoopDetected, nil} +} +func MakeErrorCodeConfigurationError() ErrorCode { + return ErrorCode{ErrorCodeConfigurationError, nil} +} +func MakeErrorCodeInternalError(value wit_types.Option[string]) ErrorCode { + return ErrorCode{ErrorCodeInternalError, value} +} + +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 uint8 = 0 + // This error indicates that a forbidden `field-key` was used when trying + // to set a header in a `fields`. + HeaderErrorForbidden uint8 = 1 + // This error indicates that the operation on the `fields` was not + // permitted because the fields are immutable. + HeaderErrorImmutable uint8 = 2 +) + +// This type enumerates the different kinds of errors that may occur when +// setting or appending to a `fields` resource. +type HeaderError struct { + tag uint8 + value any +} + +func (self HeaderError) Tag() uint8 { + return self.tag +} + +func MakeHeaderErrorInvalidSyntax() HeaderError { + return HeaderError{HeaderErrorInvalidSyntax, nil} +} +func MakeHeaderErrorForbidden() HeaderError { + return HeaderError{HeaderErrorForbidden, nil} +} +func MakeHeaderErrorImmutable() HeaderError { + return HeaderError{HeaderErrorImmutable, nil} +} + +// Field keys are always strings. +type FieldKey = 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 FieldValue = []uint8 + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields +func resourceDropFields(handle int32) + +// 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`. +type Fields struct { + handle *wit_runtime.Handle +} + +func (self *Fields) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Fields) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Fields) Handle() int32 { + return self.handle.Use() +} + +func (self *Fields) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropFields(handle) + } +} + +func FieldsFromOwnHandle(handleValue int32) *Fields { + handle := wit_runtime.MakeHandle(handleValue) + value := &Fields{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropFields(handleValue) + } + }, 0) + return value +} + +func FieldsFromBorrowHandle(handleValue int32) *Fields { + return FieldsFromOwnHandle(handleValue) +} + +// Headers is an alias for Fields. +type Headers = Fields + +// Trailers is an alias for Fields. +type Trailers = Fields + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request +func resourceDropIncomingRequest(handle int32) + +// Represents an incoming HTTP Request. +type IncomingRequest struct { + handle *wit_runtime.Handle +} + +func (self *IncomingRequest) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *IncomingRequest) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *IncomingRequest) Handle() int32 { + return self.handle.Use() +} + +func (self *IncomingRequest) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropIncomingRequest(handle) + } +} + +func IncomingRequestFromOwnHandle(handleValue int32) *IncomingRequest { + handle := wit_runtime.MakeHandle(handleValue) + value := &IncomingRequest{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropIncomingRequest(handleValue) + } + }, 0) + return value +} + +func IncomingRequestFromBorrowHandle(handleValue int32) *IncomingRequest { + return IncomingRequestFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request +func resourceDropOutgoingRequest(handle int32) + +// Represents an outgoing HTTP Request. +type OutgoingRequest struct { + handle *wit_runtime.Handle +} + +func (self *OutgoingRequest) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *OutgoingRequest) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *OutgoingRequest) Handle() int32 { + return self.handle.Use() +} + +func (self *OutgoingRequest) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropOutgoingRequest(handle) + } +} + +func OutgoingRequestFromOwnHandle(handleValue int32) *OutgoingRequest { + handle := wit_runtime.MakeHandle(handleValue) + value := &OutgoingRequest{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropOutgoingRequest(handleValue) + } + }, 0) + return value +} + +func OutgoingRequestFromBorrowHandle(handleValue int32) *OutgoingRequest { + return OutgoingRequestFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options +func resourceDropRequestOptions(handle int32) + +// 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`. +type RequestOptions struct { + handle *wit_runtime.Handle +} + +func (self *RequestOptions) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *RequestOptions) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *RequestOptions) Handle() int32 { + return self.handle.Use() +} + +func (self *RequestOptions) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropRequestOptions(handle) + } +} + +func RequestOptionsFromOwnHandle(handleValue int32) *RequestOptions { + handle := wit_runtime.MakeHandle(handleValue) + value := &RequestOptions{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropRequestOptions(handleValue) + } + }, 0) + return value +} + +func RequestOptionsFromBorrowHandle(handleValue int32) *RequestOptions { + return RequestOptionsFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam +func resourceDropResponseOutparam(handle int32) + +// 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`. +type ResponseOutparam struct { + handle *wit_runtime.Handle +} + +func (self *ResponseOutparam) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *ResponseOutparam) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *ResponseOutparam) Handle() int32 { + return self.handle.Use() +} + +func (self *ResponseOutparam) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropResponseOutparam(handle) + } +} + +func ResponseOutparamFromOwnHandle(handleValue int32) *ResponseOutparam { + handle := wit_runtime.MakeHandle(handleValue) + value := &ResponseOutparam{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropResponseOutparam(handleValue) + } + }, 0) + return value +} + +func ResponseOutparamFromBorrowHandle(handleValue int32) *ResponseOutparam { + return ResponseOutparamFromOwnHandle(handleValue) +} + +// This type corresponds to the HTTP standard Status Code. +type StatusCode = uint16 + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response +func resourceDropIncomingResponse(handle int32) + +// Represents an incoming HTTP Response. +type IncomingResponse struct { + handle *wit_runtime.Handle +} + +func (self *IncomingResponse) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *IncomingResponse) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *IncomingResponse) Handle() int32 { + return self.handle.Use() +} + +func (self *IncomingResponse) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropIncomingResponse(handle) + } +} + +func IncomingResponseFromOwnHandle(handleValue int32) *IncomingResponse { + handle := wit_runtime.MakeHandle(handleValue) + value := &IncomingResponse{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropIncomingResponse(handleValue) + } + }, 0) + return value +} + +func IncomingResponseFromBorrowHandle(handleValue int32) *IncomingResponse { + return IncomingResponseFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body +func resourceDropIncomingBody(handle int32) + +// 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. +type IncomingBody struct { + handle *wit_runtime.Handle +} + +func (self *IncomingBody) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *IncomingBody) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *IncomingBody) Handle() int32 { + return self.handle.Use() +} + +func (self *IncomingBody) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropIncomingBody(handle) + } +} + +func IncomingBodyFromOwnHandle(handleValue int32) *IncomingBody { + handle := wit_runtime.MakeHandle(handleValue) + value := &IncomingBody{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropIncomingBody(handleValue) + } + }, 0) + return value +} + +func IncomingBodyFromBorrowHandle(handleValue int32) *IncomingBody { + return IncomingBodyFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers +func resourceDropFutureTrailers(handle int32) + +// 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. +type FutureTrailers struct { + handle *wit_runtime.Handle +} + +func (self *FutureTrailers) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *FutureTrailers) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *FutureTrailers) Handle() int32 { + return self.handle.Use() +} + +func (self *FutureTrailers) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropFutureTrailers(handle) + } +} + +func FutureTrailersFromOwnHandle(handleValue int32) *FutureTrailers { + handle := wit_runtime.MakeHandle(handleValue) + value := &FutureTrailers{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropFutureTrailers(handleValue) + } + }, 0) + return value +} + +func FutureTrailersFromBorrowHandle(handleValue int32) *FutureTrailers { + return FutureTrailersFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response +func resourceDropOutgoingResponse(handle int32) + +// Represents an outgoing HTTP Response. +type OutgoingResponse struct { + handle *wit_runtime.Handle +} + +func (self *OutgoingResponse) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *OutgoingResponse) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *OutgoingResponse) Handle() int32 { + return self.handle.Use() +} + +func (self *OutgoingResponse) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropOutgoingResponse(handle) + } +} + +func OutgoingResponseFromOwnHandle(handleValue int32) *OutgoingResponse { + handle := wit_runtime.MakeHandle(handleValue) + value := &OutgoingResponse{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropOutgoingResponse(handleValue) + } + }, 0) + return value +} + +func OutgoingResponseFromBorrowHandle(handleValue int32) *OutgoingResponse { + return OutgoingResponseFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body +func resourceDropOutgoingBody(handle int32) + +// 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. +type OutgoingBody struct { + handle *wit_runtime.Handle +} + +func (self *OutgoingBody) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *OutgoingBody) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *OutgoingBody) Handle() int32 { + return self.handle.Use() +} + +func (self *OutgoingBody) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropOutgoingBody(handle) + } +} + +func OutgoingBodyFromOwnHandle(handleValue int32) *OutgoingBody { + handle := wit_runtime.MakeHandle(handleValue) + value := &OutgoingBody{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropOutgoingBody(handleValue) + } + }, 0) + return value +} + +func OutgoingBodyFromBorrowHandle(handleValue int32) *OutgoingBody { + return OutgoingBodyFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response +func resourceDropFutureIncomingResponse(handle int32) + +// 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. +type FutureIncomingResponse struct { + handle *wit_runtime.Handle +} + +func (self *FutureIncomingResponse) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *FutureIncomingResponse) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *FutureIncomingResponse) Handle() int32 { + return self.handle.Use() +} + +func (self *FutureIncomingResponse) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropFutureIncomingResponse(handle) + } +} + +func FutureIncomingResponseFromOwnHandle(handleValue int32) *FutureIncomingResponse { + handle := wit_runtime.MakeHandle(handleValue) + value := &FutureIncomingResponse{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropFutureIncomingResponse(handleValue) + } + }, 0) + return value +} + +func FutureIncomingResponseFromBorrowHandle(handleValue int32) *FutureIncomingResponse { + return FutureIncomingResponseFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:http/types@0.2.0 http-error-code +func wasm_import_http_error_code(arg0 int32, arg1 uintptr) + +func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + wasm_import_http_error_code((err).Handle(), returnArea) + var option29 wit_types.Option[ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option29 = wit_types.None[ErrorCode]() + case 1: + var variant ErrorCode + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeErrorCodeDnsTimeout() + + case 1: + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + var option0 wit_types.Option[uint16] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option0 = wit_types.None[uint16]() + case 1: + + option0 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeDnsError(DnsErrorPayload{option, option0}) + + case 2: + + variant = MakeErrorCodeDestinationNotFound() + + case 3: + + variant = MakeErrorCodeDestinationUnavailable() + + case 4: + + variant = MakeErrorCodeDestinationIpProhibited() + + case 5: + + variant = MakeErrorCodeDestinationIpUnroutable() + + case 6: + + variant = MakeErrorCodeConnectionRefused() + + case 7: + + variant = MakeErrorCodeConnectionTerminated() + + case 8: + + variant = MakeErrorCodeConnectionTimeout() + + case 9: + + variant = MakeErrorCodeConnectionReadTimeout() + + case 10: + + variant = MakeErrorCodeConnectionWriteTimeout() + + case 11: + + variant = MakeErrorCodeConnectionLimitReached() + + case 12: + + variant = MakeErrorCodeTlsProtocolError() + + case 13: + + variant = MakeErrorCodeTlsCertificateError() + + case 14: + var option1 wit_types.Option[uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option1 = wit_types.None[uint8]() + case 1: + + option1 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + default: + panic("unreachable") + } + var option3 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option3 = wit_types.None[string]() + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option3 = wit_types.Some[string](value2) + default: + panic("unreachable") + } + + variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option1, option3}) + + case 15: + + variant = MakeErrorCodeHttpRequestDenied() + + case 16: + + variant = MakeErrorCodeHttpRequestLengthRequired() + + case 17: + var option4 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option4 = wit_types.None[uint64]() + case 1: + + option4 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestBodySize(option4) + + case 18: + + variant = MakeErrorCodeHttpRequestMethodInvalid() + + case 19: + + variant = MakeErrorCodeHttpRequestUriInvalid() + + case 20: + + variant = MakeErrorCodeHttpRequestUriTooLong() + + case 21: + var option5 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option5 = wit_types.None[uint32]() + case 1: + + option5 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5) + + case 22: + var option9 wit_types.Option[FieldSizePayload] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option9 = wit_types.None[FieldSizePayload]() + case 1: + var option7 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option7 = wit_types.None[string]() + case 1: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option7 = wit_types.Some[string](value6) + default: + panic("unreachable") + } + var option8 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { + case 0: + + option8 = wit_types.None[uint32]() + case 1: + + option8 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + default: + panic("unreachable") + } + + option9 = wit_types.Some[FieldSizePayload](FieldSizePayload{option7, option8}) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSize(option9) + + case 23: + var option10 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option10 = wit_types.None[uint32]() + case 1: + + option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10) + + case 24: + var option12 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option12 = wit_types.None[string]() + case 1: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option12 = wit_types.Some[string](value11) + default: + panic("unreachable") + } + var option13 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option13 = wit_types.None[uint32]() + case 1: + + option13 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option12, option13}) + + case 25: + + variant = MakeErrorCodeHttpResponseIncomplete() + + case 26: + var option14 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option14 = wit_types.None[uint32]() + case 1: + + option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14) + + case 27: + var option16 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option16 = wit_types.None[string]() + case 1: + value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option16 = wit_types.Some[string](value15) + default: + panic("unreachable") + } + var option17 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option17 = wit_types.None[uint32]() + case 1: + + option17 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17}) + + case 28: + var option18 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option18 = wit_types.None[uint64]() + case 1: + + option18 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseBodySize(option18) + + case 29: + var option19 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option19 = wit_types.None[uint32]() + case 1: + + option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19) + + case 30: + var option21 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option21 = wit_types.None[string]() + case 1: + value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option21 = wit_types.Some[string](value20) + default: + panic("unreachable") + } + var option22 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option22 = wit_types.None[uint32]() + case 1: + + option22 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22}) + + case 31: + var option24 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option24 = wit_types.None[string]() + case 1: + value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option24 = wit_types.Some[string](value23) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTransferCoding(option24) + + case 32: + var option26 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option26 = wit_types.None[string]() + case 1: + value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option26 = wit_types.Some[string](value25) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseContentCoding(option26) + + case 33: + + variant = MakeErrorCodeHttpResponseTimeout() + + case 34: + + variant = MakeErrorCodeHttpUpgradeFailed() + + case 35: + + variant = MakeErrorCodeHttpProtocolError() + + case 36: + + variant = MakeErrorCodeLoopDetected() + + case 37: + + variant = MakeErrorCodeConfigurationError() + + case 38: + var option28 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option28 = wit_types.None[string]() + case 1: + value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option28 = wit_types.Some[string](value27) + default: + panic("unreachable") + } + + variant = MakeErrorCodeInternalError(option28) + + default: + panic("unreachable") + } + + option29 = wit_types.Some[ErrorCode](variant) + default: + panic("unreachable") + } + result := option29 + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]fields +func wasm_import_constructor_fields() int32 + +func MakeFields() *Fields { + + result := wasm_import_constructor_fields() + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list +func wasm_import_static_fields_from_list(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func FieldsFromList(entries []wit_types.Tuple2[string, []uint8]) wit_types.Result[*Fields, HeaderError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + slice := entries + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(4*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(4*4)) + utf8 := unsafe.Pointer(unsafe.StringData((element).F0)) + pinner.Pin(utf8) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8))) + data := unsafe.Pointer(unsafe.SliceData((element).F1)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(data))) + + } + + wasm_import_static_fields_from_list(uintptr(result), length, returnArea) + var result0 wit_types.Result[*Fields, HeaderError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[*Fields, HeaderError](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant HeaderError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeHeaderErrorInvalidSyntax() + + case 1: + + variant = MakeHeaderErrorForbidden() + + case 2: + + variant = MakeHeaderErrorImmutable() + + default: + panic("unreachable") + } + + result0 = wit_types.Err[*Fields, HeaderError](variant) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.get +func wasm_import_method_fields_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Fields) Get(name string) [][]uint8 { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + wasm_import_method_fields_get((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea) + result := make([][]uint8, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(2*4)) + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.has +func wasm_import_method_fields_has(arg0 int32, arg1 uintptr, arg2 uint32) int32 + +func (self *Fields) Has(name string) bool { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + result := wasm_import_method_fields_has((self).Handle(), uintptr(utf8), uint32(len(name))) + return (result != 0) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.set +func wasm_import_method_fields_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Fields) Set(name string, value [][]uint8) wit_types.Result[wit_types.Unit, HeaderError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + slice := value + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + data := unsafe.Pointer(unsafe.SliceData(element)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data))) + + } + + wasm_import_method_fields_set((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(result), length, returnArea) + var result0 wit_types.Result[wit_types.Unit, HeaderError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + case 1: + var variant HeaderError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { + case 0: + + variant = MakeHeaderErrorInvalidSyntax() + + case 1: + + variant = MakeHeaderErrorForbidden() + + case 2: + + variant = MakeHeaderErrorImmutable() + + default: + panic("unreachable") + } + + result0 = wit_types.Err[wit_types.Unit, HeaderError](variant) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.delete +func wasm_import_method_fields_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Fields) Delete(name string) wit_types.Result[wit_types.Unit, HeaderError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + wasm_import_method_fields_delete((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea) + var result wit_types.Result[wit_types.Unit, HeaderError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + case 1: + var variant HeaderError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { + case 0: + + variant = MakeHeaderErrorInvalidSyntax() + + case 1: + + variant = MakeHeaderErrorForbidden() + + case 2: + + variant = MakeHeaderErrorImmutable() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, HeaderError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.append +func wasm_import_method_fields_append(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Fields) Append(name string, value []uint8) wit_types.Result[wit_types.Unit, HeaderError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_method_fields_append((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(data), uint32(len(value)), returnArea) + var result wit_types.Result[wit_types.Unit, HeaderError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + case 1: + var variant HeaderError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { + case 0: + + variant = MakeHeaderErrorInvalidSyntax() + + case 1: + + variant = MakeHeaderErrorForbidden() + + case 2: + + variant = MakeHeaderErrorImmutable() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, HeaderError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.entries +func wasm_import_method_fields_entries(arg0 int32, arg1 uintptr) + +func (self *Fields) Entries() []wit_types.Tuple2[string, []uint8] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_method_fields_entries((self).Handle(), returnArea) + result := make([]wit_types.Tuple2[string, []uint8], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) + + result = append(result, wit_types.Tuple2[string, []uint8]{value, value0}) + } + + result1 := result + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]fields.clone +func wasm_import_method_fields_clone(arg0 int32) int32 + +func (self *Fields) Clone() *Fields { + + result := wasm_import_method_fields_clone((self).Handle()) + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method +func wasm_import_method_incoming_request_method(arg0 int32, arg1 uintptr) + +func (self *IncomingRequest) Method() Method { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_incoming_request_method((self).Handle(), returnArea) + var variant Method + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + variant = MakeMethodGet() + + case 1: + + variant = MakeMethodHead() + + case 2: + + variant = MakeMethodPost() + + case 3: + + variant = MakeMethodPut() + + case 4: + + variant = MakeMethodDelete() + + case 5: + + variant = MakeMethodConnect() + + case 6: + + variant = MakeMethodOptions() + + case 7: + + variant = MakeMethodTrace() + + case 8: + + variant = MakeMethodPatch() + + case 9: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + variant = MakeMethodOther(value) + + default: + panic("unreachable") + } + result := variant + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query +func wasm_import_method_incoming_request_path_with_query(arg0 int32, arg1 uintptr) + +func (self *IncomingRequest) PathWithQuery() wit_types.Option[string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_incoming_request_path_with_query((self).Handle(), returnArea) + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme +func wasm_import_method_incoming_request_scheme(arg0 int32, arg1 uintptr) + +func (self *IncomingRequest) Scheme() wit_types.Option[Scheme] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_method_incoming_request_scheme((self).Handle(), returnArea) + var option wit_types.Option[Scheme] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[Scheme]() + case 1: + var variant Scheme + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeSchemeHttp() + + case 1: + + variant = MakeSchemeHttps() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeSchemeOther(value) + + default: + panic("unreachable") + } + + option = wit_types.Some[Scheme](variant) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority +func wasm_import_method_incoming_request_authority(arg0 int32, arg1 uintptr) + +func (self *IncomingRequest) Authority() wit_types.Option[string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_incoming_request_authority((self).Handle(), returnArea) + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers +func wasm_import_method_incoming_request_headers(arg0 int32) int32 + +func (self *IncomingRequest) Headers() *Fields { + + result := wasm_import_method_incoming_request_headers((self).Handle()) + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume +func wasm_import_method_incoming_request_consume(arg0 int32, arg1 uintptr) + +func (self *IncomingRequest) Consume() wit_types.Result[*IncomingBody, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_incoming_request_consume((self).Handle(), returnArea) + var result wit_types.Result[*IncomingBody, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*IncomingBody, wit_types.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*IncomingBody, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request +func wasm_import_constructor_outgoing_request(arg0 int32) int32 + +func MakeOutgoingRequest(headers *Fields) *OutgoingRequest { + + result := wasm_import_constructor_outgoing_request((headers).TakeHandle()) + return OutgoingRequestFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body +func wasm_import_method_outgoing_request_body(arg0 int32, arg1 uintptr) + +func (self *OutgoingRequest) Body() wit_types.Result[*OutgoingBody, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_outgoing_request_body((self).Handle(), returnArea) + var result wit_types.Result[*OutgoingBody, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*OutgoingBody, wit_types.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*OutgoingBody, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method +func wasm_import_method_outgoing_request_method(arg0 int32, arg1 uintptr) + +func (self *OutgoingRequest) Method() Method { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_outgoing_request_method((self).Handle(), returnArea) + var variant Method + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + variant = MakeMethodGet() + + case 1: + + variant = MakeMethodHead() + + case 2: + + variant = MakeMethodPost() + + case 3: + + variant = MakeMethodPut() + + case 4: + + variant = MakeMethodDelete() + + case 5: + + variant = MakeMethodConnect() + + case 6: + + variant = MakeMethodOptions() + + case 7: + + variant = MakeMethodTrace() + + case 8: + + variant = MakeMethodPatch() + + case 9: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + variant = MakeMethodOther(value) + + default: + panic("unreachable") + } + result := variant + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method +func wasm_import_method_outgoing_request_set_method(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 + +func (self *OutgoingRequest) SetMethod(method Method) wit_types.Result[wit_types.Unit, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + var variant int32 + var variant0 uintptr + var variant1 uint32 + switch method.Tag() { + case MethodGet: + + variant = int32(0) + variant0 = 0 + variant1 = 0 + + case MethodHead: + + variant = int32(1) + variant0 = 0 + variant1 = 0 + + case MethodPost: + + variant = int32(2) + variant0 = 0 + variant1 = 0 + + case MethodPut: + + variant = int32(3) + variant0 = 0 + variant1 = 0 + + case MethodDelete: + + variant = int32(4) + variant0 = 0 + variant1 = 0 + + case MethodConnect: + + variant = int32(5) + variant0 = 0 + variant1 = 0 + + case MethodOptions: + + variant = int32(6) + variant0 = 0 + variant1 = 0 + + case MethodTrace: + + variant = int32(7) + variant0 = 0 + variant1 = 0 + + case MethodPatch: + + variant = int32(8) + variant0 = 0 + variant1 = 0 + + case MethodOther: + payload := method.Other() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + variant = int32(9) + variant0 = uintptr(utf8) + variant1 = uint32(len(payload)) + + default: + panic("unreachable") + } + result := wasm_import_method_outgoing_request_set_method((self).Handle(), variant, variant0, variant1) + var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result2 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query +func wasm_import_method_outgoing_request_path_with_query(arg0 int32, arg1 uintptr) + +func (self *OutgoingRequest) PathWithQuery() wit_types.Option[string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_outgoing_request_path_with_query((self).Handle(), returnArea) + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query +func wasm_import_method_outgoing_request_set_path_with_query(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 + +func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery wit_types.Option[string]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + var option int32 + var option0 uintptr + var option1 uint32 + switch pathWithQuery.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + option1 = 0 + case wit_types.OptionSome: + payload := pathWithQuery.Some() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + option = int32(1) + option0 = uintptr(utf8) + option1 = uint32(len(payload)) + default: + panic("unreachable") + } + result := wasm_import_method_outgoing_request_set_path_with_query((self).Handle(), option, option0, option1) + var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result2 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme +func wasm_import_method_outgoing_request_scheme(arg0 int32, arg1 uintptr) + +func (self *OutgoingRequest) Scheme() wit_types.Option[Scheme] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_method_outgoing_request_scheme((self).Handle(), returnArea) + var option wit_types.Option[Scheme] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[Scheme]() + case 1: + var variant Scheme + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeSchemeHttp() + + case 1: + + variant = MakeSchemeHttps() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeSchemeOther(value) + + default: + panic("unreachable") + } + + option = wit_types.Some[Scheme](variant) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme +func wasm_import_method_outgoing_request_set_scheme(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr, arg4 uint32) int32 + +func (self *OutgoingRequest) SetScheme(scheme wit_types.Option[Scheme]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + var option int32 + var option2 int32 + var option3 uintptr + var option4 uint32 + switch scheme.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option2 = 0 + option3 = 0 + option4 = 0 + case wit_types.OptionSome: + payload := scheme.Some() + var variant int32 + var variant0 uintptr + var variant1 uint32 + switch payload.Tag() { + case SchemeHttp: + + variant = int32(0) + variant0 = 0 + variant1 = 0 + + case SchemeHttps: + + variant = int32(1) + variant0 = 0 + variant1 = 0 + + case SchemeOther: + payload := payload.Other() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + variant = int32(2) + variant0 = uintptr(utf8) + variant1 = uint32(len(payload)) + + default: + panic("unreachable") + } + + option = int32(1) + option2 = variant + option3 = variant0 + option4 = variant1 + default: + panic("unreachable") + } + result := wasm_import_method_outgoing_request_set_scheme((self).Handle(), option, option2, option3, option4) + var result5 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result5 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result5 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result5 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority +func wasm_import_method_outgoing_request_authority(arg0 int32, arg1 uintptr) + +func (self *OutgoingRequest) Authority() wit_types.Option[string] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_outgoing_request_authority((self).Handle(), returnArea) + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority +func wasm_import_method_outgoing_request_set_authority(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 + +func (self *OutgoingRequest) SetAuthority(authority wit_types.Option[string]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + var option int32 + var option0 uintptr + var option1 uint32 + switch authority.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + option1 = 0 + case wit_types.OptionSome: + payload := authority.Some() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + option = int32(1) + option0 = uintptr(utf8) + option1 = uint32(len(payload)) + default: + panic("unreachable") + } + result := wasm_import_method_outgoing_request_set_authority((self).Handle(), option, option0, option1) + var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result2 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers +func wasm_import_method_outgoing_request_headers(arg0 int32) int32 + +func (self *OutgoingRequest) Headers() *Fields { + + result := wasm_import_method_outgoing_request_headers((self).Handle()) + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]request-options +func wasm_import_constructor_request_options() int32 + +func MakeRequestOptions() *RequestOptions { + + result := wasm_import_constructor_request_options() + return RequestOptionsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout +func wasm_import_method_request_options_connect_timeout(arg0 int32, arg1 uintptr) + +func (self *RequestOptions) ConnectTimeout() wit_types.Option[uint64] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_request_options_connect_timeout((self).Handle(), returnArea) + var option wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[uint64]() + case 1: + + option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout +func wasm_import_method_request_options_set_connect_timeout(arg0 int32, arg1 int32, arg2 int64) int32 + +func (self *RequestOptions) SetConnectTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + + var option int32 + var option0 int64 + switch duration.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + case wit_types.OptionSome: + payload := duration.Some() + + option = int32(1) + option0 = int64(payload) + default: + panic("unreachable") + } + result := wasm_import_method_request_options_set_connect_timeout((self).Handle(), option, option0) + var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout +func wasm_import_method_request_options_first_byte_timeout(arg0 int32, arg1 uintptr) + +func (self *RequestOptions) FirstByteTimeout() wit_types.Option[uint64] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_request_options_first_byte_timeout((self).Handle(), returnArea) + var option wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[uint64]() + case 1: + + option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout +func wasm_import_method_request_options_set_first_byte_timeout(arg0 int32, arg1 int32, arg2 int64) int32 + +func (self *RequestOptions) SetFirstByteTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + + var option int32 + var option0 int64 + switch duration.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + case wit_types.OptionSome: + payload := duration.Some() + + option = int32(1) + option0 = int64(payload) + default: + panic("unreachable") + } + result := wasm_import_method_request_options_set_first_byte_timeout((self).Handle(), option, option0) + var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout +func wasm_import_method_request_options_between_bytes_timeout(arg0 int32, arg1 uintptr) + +func (self *RequestOptions) BetweenBytesTimeout() wit_types.Option[uint64] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_request_options_between_bytes_timeout((self).Handle(), returnArea) + var option wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option = wit_types.None[uint64]() + case 1: + + option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + default: + panic("unreachable") + } + result := option + return result + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout +func wasm_import_method_request_options_set_between_bytes_timeout(arg0 int32, arg1 int32, arg2 int64) int32 + +func (self *RequestOptions) SetBetweenBytesTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { + + var option int32 + var option0 int64 + switch duration.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + case wit_types.OptionSome: + payload := duration.Some() + + option = int32(1) + option0 = int64(payload) + default: + panic("unreachable") + } + result := wasm_import_method_request_options_set_between_bytes_timeout((self).Handle(), option, option0) + var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result1 + +} + +//go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set +func wasm_import_static_response_outparam_set(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int64, arg5 uintptr, arg6 uintptr, arg7 uint32, arg8 int32) + +func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*OutgoingResponse, ErrorCode]) { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + var option70 int32 + var option71 int32 + var option72 int32 + var option73 int64 + var option74 uintptr + var option75 uintptr + var option76 uint32 + var option77 int32 + switch response.Tag() { + case wit_types.ResultOk: + payload := response.Ok() + + option70 = int32(0) + option71 = (payload).TakeHandle() + option72 = 0 + option73 = 0 + option74 = 0 + option75 = 0 + option76 = 0 + option77 = 0 + case wit_types.ResultErr: + payload := response.Err() + var variant int32 + var variant64 int32 + var variant65 int64 + var variant66 uintptr + var variant67 uintptr + var variant68 uint32 + var variant69 int32 + switch payload.Tag() { + case ErrorCodeDnsTimeout: + + variant = int32(0) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeDnsError: + payload := payload.DnsError() + var option int32 + var option0 uintptr + var option1 uint32 + switch (payload).Rcode.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + option1 = 0 + case wit_types.OptionSome: + payload := (payload).Rcode.Some() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + option = int32(1) + option0 = uintptr(utf8) + option1 = uint32(len(payload)) + default: + panic("unreachable") + } + var option2 int32 + var option3 int32 + switch (payload).InfoCode.Tag() { + case wit_types.OptionNone: + + option2 = int32(0) + option3 = 0 + case wit_types.OptionSome: + payload := (payload).InfoCode.Some() + + option2 = int32(1) + option3 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(1) + variant64 = option + variant65 = int64(option0) + variant66 = uintptr(option1) + variant67 = uintptr(option2) + variant68 = uint32(option3) + variant69 = 0 + + case ErrorCodeDestinationNotFound: + + variant = int32(2) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeDestinationUnavailable: + + variant = int32(3) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeDestinationIpProhibited: + + variant = int32(4) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeDestinationIpUnroutable: + + variant = int32(5) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionRefused: + + variant = int32(6) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionTerminated: + + variant = int32(7) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionTimeout: + + variant = int32(8) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionReadTimeout: + + variant = int32(9) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionWriteTimeout: + + variant = int32(10) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConnectionLimitReached: + + variant = int32(11) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeTlsProtocolError: + + variant = int32(12) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeTlsCertificateError: + + variant = int32(13) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeTlsAlertReceived: + payload := payload.TlsAlertReceived() + var option4 int32 + var option5 int32 + switch (payload).AlertId.Tag() { + case wit_types.OptionNone: + + option4 = int32(0) + option5 = 0 + case wit_types.OptionSome: + payload := (payload).AlertId.Some() + + option4 = int32(1) + option5 = int32(payload) + default: + panic("unreachable") + } + var option7 int32 + var option8 uintptr + var option9 uint32 + switch (payload).AlertMessage.Tag() { + case wit_types.OptionNone: + + option7 = int32(0) + option8 = 0 + option9 = 0 + case wit_types.OptionSome: + payload := (payload).AlertMessage.Some() + utf86 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf86) + + option7 = int32(1) + option8 = uintptr(utf86) + option9 = uint32(len(payload)) + default: + panic("unreachable") + } + + variant = int32(14) + variant64 = option4 + variant65 = int64(option5) + variant66 = uintptr(option7) + variant67 = option8 + variant68 = option9 + variant69 = 0 + + case ErrorCodeHttpRequestDenied: + + variant = int32(15) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestLengthRequired: + + variant = int32(16) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestBodySize: + payload := payload.HttpRequestBodySize() + var option10 int32 + var option11 int64 + switch payload.Tag() { + case wit_types.OptionNone: + + option10 = int32(0) + option11 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option10 = int32(1) + option11 = int64(payload) + default: + panic("unreachable") + } + + variant = int32(17) + variant64 = option10 + variant65 = option11 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestMethodInvalid: + + variant = int32(18) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestUriInvalid: + + variant = int32(19) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestUriTooLong: + + variant = int32(20) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestHeaderSectionSize: + payload := payload.HttpRequestHeaderSectionSize() + var option12 int32 + var option13 int32 + switch payload.Tag() { + case wit_types.OptionNone: + + option12 = int32(0) + option13 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option12 = int32(1) + option13 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(21) + variant64 = option12 + variant65 = int64(option13) + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestHeaderSize: + payload := payload.HttpRequestHeaderSize() + var option20 int32 + var option21 int32 + var option22 uintptr + var option23 uint32 + var option24 int32 + var option25 int32 + switch payload.Tag() { + case wit_types.OptionNone: + + option20 = int32(0) + option21 = 0 + option22 = 0 + option23 = 0 + option24 = 0 + option25 = 0 + case wit_types.OptionSome: + payload := payload.Some() + var option15 int32 + var option16 uintptr + var option17 uint32 + switch (payload).FieldName.Tag() { + case wit_types.OptionNone: + + option15 = int32(0) + option16 = 0 + option17 = 0 + case wit_types.OptionSome: + payload := (payload).FieldName.Some() + utf814 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf814) + + option15 = int32(1) + option16 = uintptr(utf814) + option17 = uint32(len(payload)) + default: + panic("unreachable") + } + var option18 int32 + var option19 int32 + switch (payload).FieldSize.Tag() { + case wit_types.OptionNone: + + option18 = int32(0) + option19 = 0 + case wit_types.OptionSome: + payload := (payload).FieldSize.Some() + + option18 = int32(1) + option19 = int32(payload) + default: + panic("unreachable") + } + + option20 = int32(1) + option21 = option15 + option22 = option16 + option23 = option17 + option24 = option18 + option25 = option19 + default: + panic("unreachable") + } + + variant = int32(22) + variant64 = option20 + variant65 = int64(option21) + variant66 = option22 + variant67 = uintptr(option23) + variant68 = uint32(option24) + variant69 = option25 + + case ErrorCodeHttpRequestTrailerSectionSize: + payload := payload.HttpRequestTrailerSectionSize() + var option26 int32 + var option27 int32 + switch payload.Tag() { + case wit_types.OptionNone: + + option26 = int32(0) + option27 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option26 = int32(1) + option27 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(23) + variant64 = option26 + variant65 = int64(option27) + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpRequestTrailerSize: + payload := payload.HttpRequestTrailerSize() + var option29 int32 + var option30 uintptr + var option31 uint32 + switch (payload).FieldName.Tag() { + case wit_types.OptionNone: + + option29 = int32(0) + option30 = 0 + option31 = 0 + case wit_types.OptionSome: + payload := (payload).FieldName.Some() + utf828 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf828) + + option29 = int32(1) + option30 = uintptr(utf828) + option31 = uint32(len(payload)) + default: + panic("unreachable") + } + var option32 int32 + var option33 int32 + switch (payload).FieldSize.Tag() { + case wit_types.OptionNone: + + option32 = int32(0) + option33 = 0 + case wit_types.OptionSome: + payload := (payload).FieldSize.Some() + + option32 = int32(1) + option33 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(24) + variant64 = option29 + variant65 = int64(option30) + variant66 = uintptr(option31) + variant67 = uintptr(option32) + variant68 = uint32(option33) + variant69 = 0 + + case ErrorCodeHttpResponseIncomplete: + + variant = int32(25) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseHeaderSectionSize: + payload := payload.HttpResponseHeaderSectionSize() + var option34 int32 + var option35 int32 + switch payload.Tag() { + case wit_types.OptionNone: + + option34 = int32(0) + option35 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option34 = int32(1) + option35 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(26) + variant64 = option34 + variant65 = int64(option35) + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseHeaderSize: + payload := payload.HttpResponseHeaderSize() + var option37 int32 + var option38 uintptr + var option39 uint32 + switch (payload).FieldName.Tag() { + case wit_types.OptionNone: + + option37 = int32(0) + option38 = 0 + option39 = 0 + case wit_types.OptionSome: + payload := (payload).FieldName.Some() + utf836 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf836) + + option37 = int32(1) + option38 = uintptr(utf836) + option39 = uint32(len(payload)) + default: + panic("unreachable") + } + var option40 int32 + var option41 int32 + switch (payload).FieldSize.Tag() { + case wit_types.OptionNone: + + option40 = int32(0) + option41 = 0 + case wit_types.OptionSome: + payload := (payload).FieldSize.Some() + + option40 = int32(1) + option41 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(27) + variant64 = option37 + variant65 = int64(option38) + variant66 = uintptr(option39) + variant67 = uintptr(option40) + variant68 = uint32(option41) + variant69 = 0 + + case ErrorCodeHttpResponseBodySize: + payload := payload.HttpResponseBodySize() + var option42 int32 + var option43 int64 + switch payload.Tag() { + case wit_types.OptionNone: + + option42 = int32(0) + option43 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option42 = int32(1) + option43 = int64(payload) + default: + panic("unreachable") + } + + variant = int32(28) + variant64 = option42 + variant65 = option43 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseTrailerSectionSize: + payload := payload.HttpResponseTrailerSectionSize() + var option44 int32 + var option45 int32 + switch payload.Tag() { + case wit_types.OptionNone: + + option44 = int32(0) + option45 = 0 + case wit_types.OptionSome: + payload := payload.Some() + + option44 = int32(1) + option45 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(29) + variant64 = option44 + variant65 = int64(option45) + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseTrailerSize: + payload := payload.HttpResponseTrailerSize() + var option47 int32 + var option48 uintptr + var option49 uint32 + switch (payload).FieldName.Tag() { + case wit_types.OptionNone: + + option47 = int32(0) + option48 = 0 + option49 = 0 + case wit_types.OptionSome: + payload := (payload).FieldName.Some() + utf846 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf846) + + option47 = int32(1) + option48 = uintptr(utf846) + option49 = uint32(len(payload)) + default: + panic("unreachable") + } + var option50 int32 + var option51 int32 + switch (payload).FieldSize.Tag() { + case wit_types.OptionNone: + + option50 = int32(0) + option51 = 0 + case wit_types.OptionSome: + payload := (payload).FieldSize.Some() + + option50 = int32(1) + option51 = int32(payload) + default: + panic("unreachable") + } + + variant = int32(30) + variant64 = option47 + variant65 = int64(option48) + variant66 = uintptr(option49) + variant67 = uintptr(option50) + variant68 = uint32(option51) + variant69 = 0 + + case ErrorCodeHttpResponseTransferCoding: + payload := payload.HttpResponseTransferCoding() + var option53 int32 + var option54 uintptr + var option55 uint32 + switch payload.Tag() { + case wit_types.OptionNone: + + option53 = int32(0) + option54 = 0 + option55 = 0 + case wit_types.OptionSome: + payload := payload.Some() + utf852 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf852) + + option53 = int32(1) + option54 = uintptr(utf852) + option55 = uint32(len(payload)) + default: + panic("unreachable") + } + + variant = int32(31) + variant64 = option53 + variant65 = int64(option54) + variant66 = uintptr(option55) + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseContentCoding: + payload := payload.HttpResponseContentCoding() + var option57 int32 + var option58 uintptr + var option59 uint32 + switch payload.Tag() { + case wit_types.OptionNone: + + option57 = int32(0) + option58 = 0 + option59 = 0 + case wit_types.OptionSome: + payload := payload.Some() + utf856 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf856) + + option57 = int32(1) + option58 = uintptr(utf856) + option59 = uint32(len(payload)) + default: + panic("unreachable") + } + + variant = int32(32) + variant64 = option57 + variant65 = int64(option58) + variant66 = uintptr(option59) + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpResponseTimeout: + + variant = int32(33) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpUpgradeFailed: + + variant = int32(34) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeHttpProtocolError: + + variant = int32(35) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeLoopDetected: + + variant = int32(36) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeConfigurationError: + + variant = int32(37) + variant64 = 0 + variant65 = 0 + variant66 = 0 + variant67 = 0 + variant68 = 0 + variant69 = 0 + + case ErrorCodeInternalError: + payload := payload.InternalError() + var option61 int32 + var option62 uintptr + var option63 uint32 + switch payload.Tag() { + case wit_types.OptionNone: + + option61 = int32(0) + option62 = 0 + option63 = 0 + case wit_types.OptionSome: + payload := payload.Some() + utf860 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf860) + + option61 = int32(1) + option62 = uintptr(utf860) + option63 = uint32(len(payload)) + default: + panic("unreachable") + } + + variant = int32(38) + variant64 = option61 + variant65 = int64(option62) + variant66 = uintptr(option63) + variant67 = 0 + variant68 = 0 + variant69 = 0 + + default: + panic("unreachable") + } + + option70 = int32(1) + option71 = variant + option72 = variant64 + option73 = variant65 + option74 = variant66 + option75 = variant67 + option76 = variant68 + option77 = variant69 + default: + panic("unreachable") + } + wasm_import_static_response_outparam_set((param).TakeHandle(), option70, option71, option72, option73, option74, option75, option76, option77) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status +func wasm_import_method_incoming_response_status(arg0 int32) int32 + +func (self *IncomingResponse) Status() uint16 { + + result := wasm_import_method_incoming_response_status((self).Handle()) + return uint16(result) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers +func wasm_import_method_incoming_response_headers(arg0 int32) int32 + +func (self *IncomingResponse) Headers() *Fields { + + result := wasm_import_method_incoming_response_headers((self).Handle()) + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume +func wasm_import_method_incoming_response_consume(arg0 int32, arg1 uintptr) + +func (self *IncomingResponse) Consume() wit_types.Result[*IncomingBody, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_incoming_response_consume((self).Handle(), returnArea) + var result wit_types.Result[*IncomingBody, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*IncomingBody, wit_types.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*IncomingBody, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream +func wasm_import_method_incoming_body_stream(arg0 int32, arg1 uintptr) + +func (self *IncomingBody) Stream() wit_types.Result[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_incoming_body_stream((self).Handle(), returnArea) + var result wit_types.Result[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish +func wasm_import_static_incoming_body_finish(arg0 int32) int32 + +func IncomingBodyFinish(this *IncomingBody) *FutureTrailers { + + result := wasm_import_static_incoming_body_finish((this).TakeHandle()) + return FutureTrailersFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe +func wasm_import_method_future_trailers_subscribe(arg0 int32) int32 + +func (self *FutureTrailers) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_future_trailers_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get +func wasm_import_method_future_trailers_get(arg0 int32, arg1 uintptr) + +func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (40 + 4*4), 8)) + wasm_import_method_future_trailers_get((self).Handle(), returnArea) + var option31 wit_types.Option[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option31 = wit_types.None[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]]() + case 1: + var result30 wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + var result wit_types.Result[wit_types.Option[*Fields], ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + var option wit_types.Option[*Fields] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { + case 0: + + option = wit_types.None[*Fields]() + case 1: + + option = wit_types.Some[*Fields](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))))) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[*Fields], ErrorCode](option) + case 1: + var variant ErrorCode + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { + case 0: + + variant = MakeErrorCodeDnsTimeout() + + case 1: + var option0 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option0 = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option0 = wit_types.Some[string](value) + default: + panic("unreachable") + } + var option1 wit_types.Option[uint16] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option1 = wit_types.None[uint16]() + case 1: + + option1 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeDnsError(DnsErrorPayload{option0, option1}) + + case 2: + + variant = MakeErrorCodeDestinationNotFound() + + case 3: + + variant = MakeErrorCodeDestinationUnavailable() + + case 4: + + variant = MakeErrorCodeDestinationIpProhibited() + + case 5: + + variant = MakeErrorCodeDestinationIpUnroutable() + + case 6: + + variant = MakeErrorCodeConnectionRefused() + + case 7: + + variant = MakeErrorCodeConnectionTerminated() + + case 8: + + variant = MakeErrorCodeConnectionTimeout() + + case 9: + + variant = MakeErrorCodeConnectionReadTimeout() + + case 10: + + variant = MakeErrorCodeConnectionWriteTimeout() + + case 11: + + variant = MakeErrorCodeConnectionLimitReached() + + case 12: + + variant = MakeErrorCodeTlsProtocolError() + + case 13: + + variant = MakeErrorCodeTlsCertificateError() + + case 14: + var option2 wit_types.Option[uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option2 = wit_types.None[uint8]() + case 1: + + option2 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) + default: + panic("unreachable") + } + var option4 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { + case 0: + + option4 = wit_types.None[string]() + case 1: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) + + option4 = wit_types.Some[string](value3) + default: + panic("unreachable") + } + + variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option2, option4}) + + case 15: + + variant = MakeErrorCodeHttpRequestDenied() + + case 16: + + variant = MakeErrorCodeHttpRequestLengthRequired() + + case 17: + var option5 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option5 = wit_types.None[uint64]() + case 1: + + option5 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestBodySize(option5) + + case 18: + + variant = MakeErrorCodeHttpRequestMethodInvalid() + + case 19: + + variant = MakeErrorCodeHttpRequestUriInvalid() + + case 20: + + variant = MakeErrorCodeHttpRequestUriTooLong() + + case 21: + var option6 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option6 = wit_types.None[uint32]() + case 1: + + option6 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSectionSize(option6) + + case 22: + var option10 wit_types.Option[FieldSizePayload] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option10 = wit_types.None[FieldSizePayload]() + case 1: + var option8 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { + case 0: + + option8 = wit_types.None[string]() + case 1: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) + + option8 = wit_types.Some[string](value7) + default: + panic("unreachable") + } + var option9 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) { + case 0: + + option9 = wit_types.None[uint32]() + case 1: + + option9 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) + default: + panic("unreachable") + } + + option10 = wit_types.Some[FieldSizePayload](FieldSizePayload{option8, option9}) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSize(option10) + + case 23: + var option11 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option11 = wit_types.None[uint32]() + case 1: + + option11 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSectionSize(option11) + + case 24: + var option13 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option13 = wit_types.None[string]() + case 1: + value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option13 = wit_types.Some[string](value12) + default: + panic("unreachable") + } + var option14 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option14 = wit_types.None[uint32]() + case 1: + + option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option13, option14}) + + case 25: + + variant = MakeErrorCodeHttpResponseIncomplete() + + case 26: + var option15 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option15 = wit_types.None[uint32]() + case 1: + + option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSectionSize(option15) + + case 27: + var option17 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option17 = wit_types.None[string]() + case 1: + value16 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option17 = wit_types.Some[string](value16) + default: + panic("unreachable") + } + var option18 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option18 = wit_types.None[uint32]() + case 1: + + option18 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option17, option18}) + + case 28: + var option19 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option19 = wit_types.None[uint64]() + case 1: + + option19 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseBodySize(option19) + + case 29: + var option20 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option20 = wit_types.None[uint32]() + case 1: + + option20 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSectionSize(option20) + + case 30: + var option22 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option22 = wit_types.None[string]() + case 1: + value21 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option22 = wit_types.Some[string](value21) + default: + panic("unreachable") + } + var option23 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option23 = wit_types.None[uint32]() + case 1: + + option23 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option22, option23}) + + case 31: + var option25 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option25 = wit_types.None[string]() + case 1: + value24 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option25 = wit_types.Some[string](value24) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTransferCoding(option25) + + case 32: + var option27 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option27 = wit_types.None[string]() + case 1: + value26 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option27 = wit_types.Some[string](value26) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseContentCoding(option27) + + case 33: + + variant = MakeErrorCodeHttpResponseTimeout() + + case 34: + + variant = MakeErrorCodeHttpUpgradeFailed() + + case 35: + + variant = MakeErrorCodeHttpProtocolError() + + case 36: + + variant = MakeErrorCodeLoopDetected() + + case 37: + + variant = MakeErrorCodeConfigurationError() + + case 38: + var option29 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option29 = wit_types.None[string]() + case 1: + value28 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option29 = wit_types.Some[string](value28) + default: + panic("unreachable") + } + + variant = MakeErrorCodeInternalError(option29) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[*Fields], ErrorCode](variant) + default: + panic("unreachable") + } + + result30 = wit_types.Ok[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit](result) + case 1: + + result30 = wit_types.Err[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + + option31 = wit_types.Some[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]](result30) + default: + panic("unreachable") + } + result32 := option31 + return result32 + +} + +//go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response +func wasm_import_constructor_outgoing_response(arg0 int32) int32 + +func MakeOutgoingResponse(headers *Fields) *OutgoingResponse { + + result := wasm_import_constructor_outgoing_response((headers).TakeHandle()) + return OutgoingResponseFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code +func wasm_import_method_outgoing_response_status_code(arg0 int32) int32 + +func (self *OutgoingResponse) StatusCode() uint16 { + + result := wasm_import_method_outgoing_response_status_code((self).Handle()) + return uint16(result) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code +func wasm_import_method_outgoing_response_set_status_code(arg0 int32, arg1 int32) int32 + +func (self *OutgoingResponse) SetStatusCode(statusCode uint16) wit_types.Result[wit_types.Unit, wit_types.Unit] { + + result := wasm_import_method_outgoing_response_set_status_code((self).Handle(), int32(statusCode)) + var result0 wit_types.Result[wit_types.Unit, wit_types.Unit] + switch result { + case 0: + + result0 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + case 1: + + result0 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers +func wasm_import_method_outgoing_response_headers(arg0 int32) int32 + +func (self *OutgoingResponse) Headers() *Fields { + + result := wasm_import_method_outgoing_response_headers((self).Handle()) + return FieldsFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body +func wasm_import_method_outgoing_response_body(arg0 int32, arg1 uintptr) + +func (self *OutgoingResponse) Body() wit_types.Result[*OutgoingBody, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_outgoing_response_body((self).Handle(), returnArea) + var result wit_types.Result[*OutgoingBody, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*OutgoingBody, wit_types.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*OutgoingBody, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write +func wasm_import_method_outgoing_body_write(arg0 int32, arg1 uintptr) + +func (self *OutgoingBody) Write() wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_outgoing_body_write((self).Handle(), returnArea) + var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish +func wasm_import_static_outgoing_body_finish(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr) + +func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) wit_types.Result[wit_types.Unit, ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + var option int32 + var option0 int32 + switch trailers.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + case wit_types.OptionSome: + payload := trailers.Some() + + option = int32(1) + option0 = (payload).TakeHandle() + default: + panic("unreachable") + } + wasm_import_static_outgoing_body_finish((this).TakeHandle(), option, option0, returnArea) + var result wit_types.Result[wit_types.Unit, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + case 1: + var variant ErrorCode + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeErrorCodeDnsTimeout() + + case 1: + var option1 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option1 = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option1 = wit_types.Some[string](value) + default: + panic("unreachable") + } + var option2 wit_types.Option[uint16] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option2 = wit_types.None[uint16]() + case 1: + + option2 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeDnsError(DnsErrorPayload{option1, option2}) + + case 2: + + variant = MakeErrorCodeDestinationNotFound() + + case 3: + + variant = MakeErrorCodeDestinationUnavailable() + + case 4: + + variant = MakeErrorCodeDestinationIpProhibited() + + case 5: + + variant = MakeErrorCodeDestinationIpUnroutable() + + case 6: + + variant = MakeErrorCodeConnectionRefused() + + case 7: + + variant = MakeErrorCodeConnectionTerminated() + + case 8: + + variant = MakeErrorCodeConnectionTimeout() + + case 9: + + variant = MakeErrorCodeConnectionReadTimeout() + + case 10: + + variant = MakeErrorCodeConnectionWriteTimeout() + + case 11: + + variant = MakeErrorCodeConnectionLimitReached() + + case 12: + + variant = MakeErrorCodeTlsProtocolError() + + case 13: + + variant = MakeErrorCodeTlsCertificateError() + + case 14: + var option3 wit_types.Option[uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option3 = wit_types.None[uint8]() + case 1: + + option3 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + default: + panic("unreachable") + } + var option5 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option5 = wit_types.None[string]() + case 1: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option5 = wit_types.Some[string](value4) + default: + panic("unreachable") + } + + variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option3, option5}) + + case 15: + + variant = MakeErrorCodeHttpRequestDenied() + + case 16: + + variant = MakeErrorCodeHttpRequestLengthRequired() + + case 17: + var option6 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option6 = wit_types.None[uint64]() + case 1: + + option6 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestBodySize(option6) + + case 18: + + variant = MakeErrorCodeHttpRequestMethodInvalid() + + case 19: + + variant = MakeErrorCodeHttpRequestUriInvalid() + + case 20: + + variant = MakeErrorCodeHttpRequestUriTooLong() + + case 21: + var option7 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option7 = wit_types.None[uint32]() + case 1: + + option7 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSectionSize(option7) + + case 22: + var option11 wit_types.Option[FieldSizePayload] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option11 = wit_types.None[FieldSizePayload]() + case 1: + var option9 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { + case 0: + + option9 = wit_types.None[string]() + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) + + option9 = wit_types.Some[string](value8) + default: + panic("unreachable") + } + var option10 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { + case 0: + + option10 = wit_types.None[uint32]() + case 1: + + option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + default: + panic("unreachable") + } + + option11 = wit_types.Some[FieldSizePayload](FieldSizePayload{option9, option10}) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSize(option11) + + case 23: + var option12 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option12 = wit_types.None[uint32]() + case 1: + + option12 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSectionSize(option12) + + case 24: + var option14 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option14 = wit_types.None[string]() + case 1: + value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option14 = wit_types.Some[string](value13) + default: + panic("unreachable") + } + var option15 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option15 = wit_types.None[uint32]() + case 1: + + option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option14, option15}) + + case 25: + + variant = MakeErrorCodeHttpResponseIncomplete() + + case 26: + var option16 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option16 = wit_types.None[uint32]() + case 1: + + option16 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSectionSize(option16) + + case 27: + var option18 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option18 = wit_types.None[string]() + case 1: + value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option18 = wit_types.Some[string](value17) + default: + panic("unreachable") + } + var option19 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option19 = wit_types.None[uint32]() + case 1: + + option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option18, option19}) + + case 28: + var option20 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option20 = wit_types.None[uint64]() + case 1: + + option20 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseBodySize(option20) + + case 29: + var option21 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option21 = wit_types.None[uint32]() + case 1: + + option21 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSectionSize(option21) + + case 30: + var option23 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option23 = wit_types.None[string]() + case 1: + value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option23 = wit_types.Some[string](value22) + default: + panic("unreachable") + } + var option24 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { + case 0: + + option24 = wit_types.None[uint32]() + case 1: + + option24 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option23, option24}) + + case 31: + var option26 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option26 = wit_types.None[string]() + case 1: + value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option26 = wit_types.Some[string](value25) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTransferCoding(option26) + + case 32: + var option28 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option28 = wit_types.None[string]() + case 1: + value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option28 = wit_types.Some[string](value27) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseContentCoding(option28) + + case 33: + + variant = MakeErrorCodeHttpResponseTimeout() + + case 34: + + variant = MakeErrorCodeHttpUpgradeFailed() + + case 35: + + variant = MakeErrorCodeHttpProtocolError() + + case 36: + + variant = MakeErrorCodeLoopDetected() + + case 37: + + variant = MakeErrorCodeConfigurationError() + + case 38: + var option30 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + option30 = wit_types.None[string]() + case 1: + value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) + + option30 = wit_types.Some[string](value29) + default: + panic("unreachable") + } + + variant = MakeErrorCodeInternalError(option30) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, ErrorCode](variant) + default: + panic("unreachable") + } + result31 := result + return result31 + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe +func wasm_import_method_future_incoming_response_subscribe(arg0 int32) int32 + +func (self *FutureIncomingResponse) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_future_incoming_response_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get +func wasm_import_method_future_incoming_response_get(arg0 int32, arg1 uintptr) + +func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (40 + 4*4), 8)) + wasm_import_method_future_incoming_response_get((self).Handle(), returnArea) + var option30 wit_types.Option[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + option30 = wit_types.None[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]]() + case 1: + var result29 wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + var result wit_types.Result[*IncomingResponse, ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { + case 0: + + result = wit_types.Ok[*IncomingResponse, ErrorCode](IncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))))) + case 1: + var variant ErrorCode + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { + case 0: + + variant = MakeErrorCodeDnsTimeout() + + case 1: + var option wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option = wit_types.None[string]() + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option = wit_types.Some[string](value) + default: + panic("unreachable") + } + var option0 wit_types.Option[uint16] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option0 = wit_types.None[uint16]() + case 1: + + option0 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeDnsError(DnsErrorPayload{option, option0}) + + case 2: + + variant = MakeErrorCodeDestinationNotFound() + + case 3: + + variant = MakeErrorCodeDestinationUnavailable() + + case 4: + + variant = MakeErrorCodeDestinationIpProhibited() + + case 5: + + variant = MakeErrorCodeDestinationIpUnroutable() + + case 6: + + variant = MakeErrorCodeConnectionRefused() + + case 7: + + variant = MakeErrorCodeConnectionTerminated() + + case 8: + + variant = MakeErrorCodeConnectionTimeout() + + case 9: + + variant = MakeErrorCodeConnectionReadTimeout() + + case 10: + + variant = MakeErrorCodeConnectionWriteTimeout() + + case 11: + + variant = MakeErrorCodeConnectionLimitReached() + + case 12: + + variant = MakeErrorCodeTlsProtocolError() + + case 13: + + variant = MakeErrorCodeTlsCertificateError() + + case 14: + var option1 wit_types.Option[uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option1 = wit_types.None[uint8]() + case 1: + + option1 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) + default: + panic("unreachable") + } + var option3 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { + case 0: + + option3 = wit_types.None[string]() + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) + + option3 = wit_types.Some[string](value2) + default: + panic("unreachable") + } + + variant = MakeErrorCodeTlsAlertReceived(TlsAlertReceivedPayload{option1, option3}) + + case 15: + + variant = MakeErrorCodeHttpRequestDenied() + + case 16: + + variant = MakeErrorCodeHttpRequestLengthRequired() + + case 17: + var option4 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option4 = wit_types.None[uint64]() + case 1: + + option4 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestBodySize(option4) + + case 18: + + variant = MakeErrorCodeHttpRequestMethodInvalid() + + case 19: + + variant = MakeErrorCodeHttpRequestUriInvalid() + + case 20: + + variant = MakeErrorCodeHttpRequestUriTooLong() + + case 21: + var option5 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option5 = wit_types.None[uint32]() + case 1: + + option5 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5) + + case 22: + var option9 wit_types.Option[FieldSizePayload] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option9 = wit_types.None[FieldSizePayload]() + case 1: + var option7 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { + case 0: + + option7 = wit_types.None[string]() + case 1: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) + + option7 = wit_types.Some[string](value6) + default: + panic("unreachable") + } + var option8 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) { + case 0: + + option8 = wit_types.None[uint32]() + case 1: + + option8 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) + default: + panic("unreachable") + } + + option9 = wit_types.Some[FieldSizePayload](FieldSizePayload{option7, option8}) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestHeaderSize(option9) + + case 23: + var option10 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option10 = wit_types.None[uint32]() + case 1: + + option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10) + + case 24: + var option12 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option12 = wit_types.None[string]() + case 1: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option12 = wit_types.Some[string](value11) + default: + panic("unreachable") + } + var option13 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option13 = wit_types.None[uint32]() + case 1: + + option13 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpRequestTrailerSize(FieldSizePayload{option12, option13}) + + case 25: + + variant = MakeErrorCodeHttpResponseIncomplete() + + case 26: + var option14 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option14 = wit_types.None[uint32]() + case 1: + + option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14) + + case 27: + var option16 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option16 = wit_types.None[string]() + case 1: + value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option16 = wit_types.Some[string](value15) + default: + panic("unreachable") + } + var option17 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option17 = wit_types.None[uint32]() + case 1: + + option17 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17}) + + case 28: + var option18 wit_types.Option[uint64] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option18 = wit_types.None[uint64]() + case 1: + + option18 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseBodySize(option18) + + case 29: + var option19 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option19 = wit_types.None[uint32]() + case 1: + + option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19) + + case 30: + var option21 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option21 = wit_types.None[string]() + case 1: + value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option21 = wit_types.Some[string](value20) + default: + panic("unreachable") + } + var option22 wit_types.Option[uint32] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { + case 0: + + option22 = wit_types.None[uint32]() + case 1: + + option22 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22}) + + case 31: + var option24 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option24 = wit_types.None[string]() + case 1: + value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option24 = wit_types.Some[string](value23) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseTransferCoding(option24) + + case 32: + var option26 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option26 = wit_types.None[string]() + case 1: + value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option26 = wit_types.Some[string](value25) + default: + panic("unreachable") + } + + variant = MakeErrorCodeHttpResponseContentCoding(option26) + + case 33: + + variant = MakeErrorCodeHttpResponseTimeout() + + case 34: + + variant = MakeErrorCodeHttpUpgradeFailed() + + case 35: + + variant = MakeErrorCodeHttpProtocolError() + + case 36: + + variant = MakeErrorCodeLoopDetected() + + case 37: + + variant = MakeErrorCodeConfigurationError() + + case 38: + var option28 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { + case 0: + + option28 = wit_types.None[string]() + case 1: + value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) + + option28 = wit_types.Some[string](value27) + default: + panic("unreachable") + } + + variant = MakeErrorCodeInternalError(option28) + + default: + panic("unreachable") + } + + result = wit_types.Err[*IncomingResponse, ErrorCode](variant) + default: + panic("unreachable") + } + + result29 = wit_types.Ok[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit](result) + case 1: + + result29 = wit_types.Err[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit](wit_types.Unit{}) + default: + panic("unreachable") + } + + option30 = wit_types.Some[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]](result29) + default: + panic("unreachable") + } + result31 := option30 + return result31 + +} diff --git a/v3/internal/wasi_io_0_2_0_error/wit_bindings.go b/v3/internal/wasi_io_0_2_0_error/wit_bindings.go new file mode 100644 index 00000000..b970e003 --- /dev/null +++ b/v3/internal/wasi_io_0_2_0_error/wit_bindings.go @@ -0,0 +1,114 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_io_0_2_0_error + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:io/error@0.2.0 [resource-drop]error +func resourceDropError(handle int32) + +// 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. +type Error struct { + handle *wit_runtime.Handle +} + +func (self *Error) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Error) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Error) Handle() int32 { + return self.handle.Use() +} + +func (self *Error) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropError(handle) + } +} + +func ErrorFromOwnHandle(handleValue int32) *Error { + handle := wit_runtime.MakeHandle(handleValue) + value := &Error{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropError(handleValue) + } + }, 0) + return value +} + +func ErrorFromBorrowHandle(handleValue int32) *Error { + return ErrorFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string +func wasm_import_method_error_to_debug_string(arg0 int32, arg1 uintptr) + +func (self *Error) ToDebugString() string { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_method_error_to_debug_string((self).Handle(), returnArea) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := value + return result + +} diff --git a/v3/internal/wasi_io_0_2_0_poll/wit_bindings.go b/v3/internal/wasi_io_0_2_0_poll/wit_bindings.go new file mode 100644 index 00000000..4ee0d1e8 --- /dev/null +++ b/v3/internal/wasi_io_0_2_0_poll/wit_bindings.go @@ -0,0 +1,124 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_io_0_2_0_poll + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable +func resourceDropPollable(handle int32) + +// `pollable` represents a single I/O event which may be ready, or not. +type Pollable struct { + handle *wit_runtime.Handle +} + +func (self *Pollable) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Pollable) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Pollable) Handle() int32 { + return self.handle.Use() +} + +func (self *Pollable) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropPollable(handle) + } +} + +func PollableFromOwnHandle(handleValue int32) *Pollable { + handle := wit_runtime.MakeHandle(handleValue) + value := &Pollable{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropPollable(handleValue) + } + }, 0) + return value +} + +func PollableFromBorrowHandle(handleValue int32) *Pollable { + return PollableFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready +func wasm_import_method_pollable_ready(arg0 int32) int32 + +func (self *Pollable) Ready() bool { + + result := wasm_import_method_pollable_ready((self).Handle()) + return (result != 0) + +} + +//go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block +func wasm_import_method_pollable_block(arg0 int32) + +func (self *Pollable) Block() { + + wasm_import_method_pollable_block((self).Handle()) + +} + +//go:wasmimport wasi:io/poll@0.2.0 poll +func wasm_import_poll(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Poll(in []*Pollable) []uint32 { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + slice := in + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*4), 4) + for index, element := range slice { + base := unsafe.Add(result, index*4) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 0)) = (element).Handle() + + } + + wasm_import_poll(uintptr(result), length, returnArea) + value := unsafe.Slice((*uint32)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result0 := value + return result0 + +} diff --git a/v3/internal/wasi_io_0_2_0_streams/wit_bindings.go b/v3/internal/wasi_io_0_2_0_streams/wit_bindings.go new file mode 100644 index 00000000..f60b6039 --- /dev/null +++ b/v3/internal/wasi_io_0_2_0_streams/wit_bindings.go @@ -0,0 +1,699 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_io_0_2_0_streams + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + "runtime" + "unsafe" +) + +type Error = wasi_io_0_2_0_error.Error +type Pollable = wasi_io_0_2_0_poll.Pollable + +const ( + // The last operation (a write or flush) failed before completion. + // + // More information is available in the `error` payload. + StreamErrorLastOperationFailed uint8 = 0 + // 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. + StreamErrorClosed uint8 = 1 +) + +// An error for input-stream and output-stream operations. +type StreamError struct { + tag uint8 + value any +} + +func (self StreamError) Tag() uint8 { + return self.tag +} + +func (self StreamError) LastOperationFailed() *wasi_io_0_2_0_error.Error { + if self.tag != StreamErrorLastOperationFailed { + panic("tag mismatch") + } + return self.value.(*wasi_io_0_2_0_error.Error) +} + +func MakeStreamErrorLastOperationFailed(value *wasi_io_0_2_0_error.Error) StreamError { + return StreamError{StreamErrorLastOperationFailed, value} +} +func MakeStreamErrorClosed() StreamError { + return StreamError{StreamErrorClosed, nil} +} + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream +func resourceDropInputStream(handle int32) + +// 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`. +type InputStream struct { + handle *wit_runtime.Handle +} + +func (self *InputStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *InputStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *InputStream) Handle() int32 { + return self.handle.Use() +} + +func (self *InputStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropInputStream(handle) + } +} + +func InputStreamFromOwnHandle(handleValue int32) *InputStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &InputStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropInputStream(handleValue) + } + }, 0) + return value +} + +func InputStreamFromBorrowHandle(handleValue int32) *InputStream { + return InputStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream +func resourceDropOutputStream(handle int32) + +// 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`. +type OutputStream struct { + handle *wit_runtime.Handle +} + +func (self *OutputStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *OutputStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *OutputStream) Handle() int32 { + return self.handle.Use() +} + +func (self *OutputStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropOutputStream(handle) + } +} + +func OutputStreamFromOwnHandle(handleValue int32) *OutputStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &OutputStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropOutputStream(handleValue) + } + }, 0) + return value +} + +func OutputStreamFromBorrowHandle(handleValue int32) *OutputStream { + return OutputStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read +func wasm_import_method_input_stream_read(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *InputStream) Read(len uint64) wit_types.Result[[]uint8, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_input_stream_read((self).Handle(), int64(len), returnArea) + var result wit_types.Result[[]uint8, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[[]uint8, StreamError](value) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 1*4))))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[[]uint8, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read +func wasm_import_method_input_stream_blocking_read(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *InputStream) BlockingRead(len uint64) wit_types.Result[[]uint8, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_input_stream_blocking_read((self).Handle(), int64(len), returnArea) + var result wit_types.Result[[]uint8, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = wit_types.Ok[[]uint8, StreamError](value) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 1*4))))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[[]uint8, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip +func wasm_import_method_input_stream_skip(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *InputStream) Skip(len uint64) wit_types.Result[uint64, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_input_stream_skip((self).Handle(), int64(len), returnArea) + var result wit_types.Result[uint64, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[uint64, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip +func wasm_import_method_input_stream_blocking_skip(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *InputStream) BlockingSkip(len uint64) wit_types.Result[uint64, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_input_stream_blocking_skip((self).Handle(), int64(len), returnArea) + var result wit_types.Result[uint64, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[uint64, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe +func wasm_import_method_input_stream_subscribe(arg0 int32) int32 + +func (self *InputStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_input_stream_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write +func wasm_import_method_output_stream_check_write(arg0 int32, arg1 uintptr) + +func (self *OutputStream) CheckWrite() wit_types.Result[uint64, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_output_stream_check_write((self).Handle(), returnArea) + var result wit_types.Result[uint64, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[uint64, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write +func wasm_import_method_output_stream_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *OutputStream) Write(contents []uint8) wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + data := unsafe.Pointer(unsafe.SliceData(contents)) + pinner.Pin(data) + wasm_import_method_output_stream_write((self).Handle(), uintptr(data), uint32(len(contents)), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush +func wasm_import_method_output_stream_blocking_write_and_flush(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + data := unsafe.Pointer(unsafe.SliceData(contents)) + pinner.Pin(data) + wasm_import_method_output_stream_blocking_write_and_flush((self).Handle(), uintptr(data), uint32(len(contents)), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush +func wasm_import_method_output_stream_flush(arg0 int32, arg1 uintptr) + +func (self *OutputStream) Flush() wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + wasm_import_method_output_stream_flush((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush +func wasm_import_method_output_stream_blocking_flush(arg0 int32, arg1 uintptr) + +func (self *OutputStream) BlockingFlush() wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + wasm_import_method_output_stream_blocking_flush((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe +func wasm_import_method_output_stream_subscribe(arg0 int32) int32 + +func (self *OutputStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_output_stream_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes +func wasm_import_method_output_stream_write_zeroes(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *OutputStream) WriteZeroes(len uint64) wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + wasm_import_method_output_stream_write_zeroes((self).Handle(), int64(len), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush +func wasm_import_method_output_stream_blocking_write_zeroes_and_flush(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) wit_types.Result[wit_types.Unit, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + wasm_import_method_output_stream_blocking_write_zeroes_and_flush((self).Handle(), int64(len), returnArea) + var result wit_types.Result[wit_types.Unit, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice +func wasm_import_method_output_stream_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr) + +func (self *OutputStream) Splice(src *InputStream, len uint64) wit_types.Result[uint64, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_output_stream_splice((self).Handle(), (src).Handle(), int64(len), returnArea) + var result wit_types.Result[uint64, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[uint64, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice +func wasm_import_method_output_stream_blocking_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr) + +func (self *OutputStream) BlockingSplice(src *InputStream, len uint64) wit_types.Result[uint64, StreamError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_output_stream_blocking_splice((self).Handle(), (src).Handle(), int64(len), returnArea) + var result wit_types.Result[uint64, StreamError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant StreamError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakeStreamErrorLastOperationFailed(wasi_io_0_2_0_error.ErrorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))) + + case 1: + + variant = MakeStreamErrorClosed() + + default: + panic("unreachable") + } + + result = wit_types.Err[uint64, StreamError](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} diff --git a/v3/internal/wasi_keyvalue_atomics/wit_bindings.go b/v3/internal/wasi_keyvalue_atomics/wit_bindings.go new file mode 100644 index 00000000..ebfb887e --- /dev/null +++ b/v3/internal/wasi_keyvalue_atomics/wit_bindings.go @@ -0,0 +1,328 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_keyvalue_atomics + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_keyvalue_store" + "runtime" + "unsafe" +) + +type Bucket = wasi_keyvalue_store.Bucket +type Error = wasi_keyvalue_store.Error + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [resource-drop]cas +func resourceDropCas(handle int32) + +// A handle to a CAS (compare-and-swap) operation. +type Cas struct { + handle *wit_runtime.Handle +} + +func (self *Cas) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Cas) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Cas) Handle() int32 { + return self.handle.Use() +} + +func (self *Cas) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropCas(handle) + } +} + +func CasFromOwnHandle(handleValue int32) *Cas { + handle := wit_runtime.MakeHandle(handleValue) + value := &Cas{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropCas(handleValue) + } + }, 0) + return value +} + +func CasFromBorrowHandle(handleValue int32) *Cas { + return CasFromOwnHandle(handleValue) +} + +const ( + // A store error occurred when performing the operation + CasErrorStoreError uint8 = 0 + // The CAS operation failed because the value was too old. This returns a new CAS handle + // for easy retries. Implementors MUST return a CAS handle that has been updated to the + // latest version or transaction. + CasErrorCasFailed uint8 = 1 +) + +// The error returned by a CAS operation +type CasError struct { + tag uint8 + value any +} + +func (self CasError) Tag() uint8 { + return self.tag +} + +func (self CasError) StoreError() wasi_keyvalue_store.Error { + if self.tag != CasErrorStoreError { + panic("tag mismatch") + } + return self.value.(wasi_keyvalue_store.Error) +} +func (self CasError) CasFailed() *Cas { + if self.tag != CasErrorCasFailed { + panic("tag mismatch") + } + return self.value.(*Cas) +} + +func MakeCasErrorStoreError(value wasi_keyvalue_store.Error) CasError { + return CasError{CasErrorStoreError, value} +} +func MakeCasErrorCasFailed(value *Cas) CasError { + return CasError{CasErrorCasFailed, value} +} + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [static]cas.new +func wasm_import_static_cas_new(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func CasNew(bucket *wasi_keyvalue_store.Bucket, key string) wit_types.Result[*Cas, wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_static_cas_new((bucket).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[*Cas, wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Cas, wasi_keyvalue_store.Error](CasFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Cas, wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [method]cas.current +func wasm_import_method_cas_current(arg0 int32, arg1 uintptr) + +func (self *Cas) Current() wit_types.Result[wit_types.Option[[]uint8], wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + wasm_import_method_cas_current((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Option[[]uint8], wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[[]uint8]() + case 1: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + option = wit_types.Some[[]uint8](value) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[[]uint8], wasi_keyvalue_store.Error](option) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[[]uint8], wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 increment +func wasm_import_increment(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int64, arg4 uintptr) + +func Increment(bucket *wasi_keyvalue_store.Bucket, key string, delta int64) wit_types.Result[int64, wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_increment((bucket).Handle(), uintptr(utf8), uint32(len(key)), delta, returnArea) + var result wit_types.Result[int64, wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[int64, wasi_keyvalue_store.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[int64, wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 swap +func wasm_import_swap(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func Swap(cas *Cas, value []uint8) wit_types.Result[wit_types.Unit, CasError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_swap((cas).TakeHandle(), uintptr(data), uint32(len(value)), returnArea) + var result wit_types.Result[wit_types.Unit, CasError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, CasError](wit_types.Unit{}) + case 1: + var variant1 CasError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value0) + + default: + panic("unreachable") + } + + variant1 = MakeCasErrorStoreError(variant) + + case 1: + + variant1 = MakeCasErrorCasFailed(CasFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))))) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, CasError](variant1) + default: + panic("unreachable") + } + result2 := result + return result2 + +} diff --git a/v3/internal/wasi_keyvalue_batch/wit_bindings.go b/v3/internal/wasi_keyvalue_batch/wit_bindings.go new file mode 100644 index 00000000..5f44efa6 --- /dev/null +++ b/v3/internal/wasi_keyvalue_batch/wit_bindings.go @@ -0,0 +1,231 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_keyvalue_batch + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_keyvalue_store" + "runtime" + "unsafe" +) + +type Bucket = wasi_keyvalue_store.Bucket +type Error = wasi_keyvalue_store.Error + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 get-many +func wasm_import_get_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + slice := keys + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf8 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf8) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8))) + + } + + wasm_import_get_many((bucket).Handle(), uintptr(result), length, returnArea) + var result3 wit_types.Result[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([]wit_types.Tuple2[string, wit_types.Option[[]uint8]], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(5*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + var option wit_types.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) { + case 0: + + option = wit_types.None[[]uint8]() + case 1: + value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 * 4)))) + + option = wit_types.Some[[]uint8](value0) + default: + panic("unreachable") + } + + result1 = append(result1, wit_types.Tuple2[string, wit_types.Option[[]uint8]]{value, option}) + } + + result3 = wit_types.Ok[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error](result1) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value2) + + default: + panic("unreachable") + } + + result3 = wit_types.Err[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result4 := result3 + return result4 + +} + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 set-many +func wasm_import_set_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []wit_types.Tuple2[string, []uint8]) wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + slice := keyValues + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(4*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(4*4)) + utf8 := unsafe.Pointer(unsafe.StringData((element).F0)) + pinner.Pin(utf8) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8))) + data := unsafe.Pointer(unsafe.SliceData((element).F1)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(data))) + + } + + wasm_import_set_many((bucket).Handle(), uintptr(result), length, returnArea) + var result0 wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[wit_types.Unit, wasi_keyvalue_store.Error](wit_types.Unit{}) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value) + + default: + panic("unreachable") + } + + result0 = wit_types.Err[wit_types.Unit, wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 delete-many +func wasm_import_delete_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func DeleteMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + slice := keys + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf8 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf8) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8))) + + } + + wasm_import_delete_many((bucket).Handle(), uintptr(result), length, returnArea) + var result0 wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[wit_types.Unit, wasi_keyvalue_store.Error](wit_types.Unit{}) + case 1: + var variant wasi_keyvalue_store.Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_keyvalue_store.MakeErrorNoSuchStore() + + case 1: + + variant = wasi_keyvalue_store.MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = wasi_keyvalue_store.MakeErrorOther(value) + + default: + panic("unreachable") + } + + result0 = wit_types.Err[wit_types.Unit, wasi_keyvalue_store.Error](variant) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} diff --git a/v3/internal/wasi_keyvalue_store/wit_bindings.go b/v3/internal/wasi_keyvalue_store/wit_bindings.go new file mode 100644 index 00000000..76f39787 --- /dev/null +++ b/v3/internal/wasi_keyvalue_store/wit_bindings.go @@ -0,0 +1,464 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_keyvalue_store + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +const ( + // The host does not recognize the store identifier requested. + ErrorNoSuchStore uint8 = 0 + // The requesting component does not have access to the specified store + // (which may or may not exist). + ErrorAccessDenied uint8 = 1 + // Some implementation-specific error has occurred (e.g. I/O) + ErrorOther uint8 = 2 +) + +// The set of errors which may be raised by functions in this package +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorNoSuchStore() Error { + return Error{ErrorNoSuchStore, nil} +} +func MakeErrorAccessDenied() Error { + return Error{ErrorAccessDenied, nil} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +// A response to a `list-keys` operation. +type KeyResponse struct { + // The list of keys returned by the query. + Keys []string + // The continuation token to use to fetch the next page of keys. If this is `null`, then + // there are no more keys to fetch. + Cursor wit_types.Option[string] +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [resource-drop]bucket +func resourceDropBucket(handle int32) + +// A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the +// bucket, and the bucket itself acts as a collection of all these entries. +// +// It is worth noting that the exact terminology for bucket in key-value stores can very +// depending on the specific implementation. For example: +// +// 1. Amazon DynamoDB calls a collection of key-value pairs a table +// 2. Redis has hashes, sets, and sorted sets as different types of collections +// 3. Cassandra calls a collection of key-value pairs a column family +// 4. MongoDB calls a collection of key-value pairs a collection +// 5. Riak calls a collection of key-value pairs a bucket +// 6. Memcached calls a collection of key-value pairs a slab +// 7. Azure Cosmos DB calls a collection of key-value pairs a container +// +// In this interface, we use the term `bucket` to refer to a collection of key-value pairs +type Bucket struct { + handle *wit_runtime.Handle +} + +func (self *Bucket) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Bucket) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Bucket) Handle() int32 { + return self.handle.Use() +} + +func (self *Bucket) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropBucket(handle) + } +} + +func BucketFromOwnHandle(handleValue int32) *Bucket { + handle := wit_runtime.MakeHandle(handleValue) + value := &Bucket{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropBucket(handleValue) + } + }, 0) + return value +} + +func BucketFromBorrowHandle(handleValue int32) *Bucket { + return BucketFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 open +func wasm_import_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Open(identifier string) wit_types.Result[*Bucket, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(identifier)) + pinner.Pin(utf8) + wasm_import_open(uintptr(utf8), uint32(len(identifier)), returnArea) + var result wit_types.Result[*Bucket, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*Bucket, Error](BucketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[*Bucket, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.get +func wasm_import_method_bucket_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Bucket) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_bucket_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Option[[]uint8], Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + option = wit_types.None[[]uint8]() + case 1: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + option = wit_types.Some[[]uint8](value) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.set +func wasm_import_method_bucket_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func (self *Bucket) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_method_bucket_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value0) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.delete +func wasm_import_method_bucket_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Bucket) Delete(key string) wit_types.Result[wit_types.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_bucket_delete((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[wit_types.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[wit_types.Unit, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.exists +func wasm_import_method_bucket_exists(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *Bucket) Exists(key string) wit_types.Result[bool, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_method_bucket_exists((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) + var result wit_types.Result[bool, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value) + + default: + panic("unreachable") + } + + result = wit_types.Err[bool, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.list-keys +func wasm_import_method_bucket_list_keys(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func (self *Bucket) ListKeys(cursor wit_types.Option[string]) wit_types.Result[KeyResponse, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (6 * 4), 4)) + var option int32 + var option0 uintptr + var option1 uint32 + switch cursor.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option0 = 0 + option1 = 0 + case wit_types.OptionSome: + payload := cursor.Some() + utf8 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf8) + + option = int32(1) + option0 = uintptr(utf8) + option1 = uint32(len(payload)) + default: + panic("unreachable") + } + wasm_import_method_bucket_list_keys((self).Handle(), option, option0, option1, returnArea) + var result5 wit_types.Result[KeyResponse, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + var option3 wit_types.Option[string] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) { + case 0: + + option3 = wit_types.None[string]() + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (5 * 4)))) + + option3 = wit_types.Some[string](value2) + default: + panic("unreachable") + } + + result5 = wit_types.Ok[KeyResponse, Error](KeyResponse{result, option3}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchStore() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value4) + + default: + panic("unreachable") + } + + result5 = wit_types.Err[KeyResponse, Error](variant) + default: + panic("unreachable") + } + result6 := result5 + return result6 + +} diff --git a/v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go b/v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go new file mode 100644 index 00000000..fd1d6118 --- /dev/null +++ b/v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go @@ -0,0 +1,63 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_random_0_2_0_insecure + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes +func wasm_import_get_insecure_random_bytes(arg0 int64, arg1 uintptr) + +func GetInsecureRandomBytes(len uint64) []uint8 { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_get_insecure_random_bytes(int64(len), returnArea) + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := value + return result + +} + +//go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 +func wasm_import_get_insecure_random_u64() int64 + +func GetInsecureRandomU64() uint64 { + + result := wasm_import_get_insecure_random_u64() + return uint64(result) + +} diff --git a/v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go b/v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go new file mode 100644 index 00000000..309d7237 --- /dev/null +++ b/v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go @@ -0,0 +1,54 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_random_0_2_0_insecure_seed + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed +func wasm_import_insecure_seed(arg0 uintptr) + +func InsecureSeed() (uint64, uint64) { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_insecure_seed(returnArea) + result := wit_types.Tuple2[uint64, uint64]{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} + tuple := result + return tuple.F0, tuple.F1 + +} diff --git a/v3/internal/wasi_random_0_2_0_random/wit_bindings.go b/v3/internal/wasi_random_0_2_0_random/wit_bindings.go new file mode 100644 index 00000000..71fbf034 --- /dev/null +++ b/v3/internal/wasi_random_0_2_0_random/wit_bindings.go @@ -0,0 +1,63 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_random_0_2_0_random + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "runtime" + "unsafe" +) + +//go:wasmimport wasi:random/random@0.2.0 get-random-bytes +func wasm_import_get_random_bytes(arg0 int64, arg1 uintptr) + +func GetRandomBytes(len uint64) []uint8 { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + wasm_import_get_random_bytes(int64(len), returnArea) + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := value + return result + +} + +//go:wasmimport wasi:random/random@0.2.0 get-random-u64 +func wasm_import_get_random_u64() int64 + +func GetRandomU64() uint64 { + + result := wasm_import_get_random_u64() + return uint64(result) + +} diff --git a/v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go new file mode 100644 index 00000000..d7a4cd8e --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go @@ -0,0 +1,48 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_instance_network + +import ( + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" +) + +type Network = wasi_sockets_0_2_0_network.Network + +//go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network +func wasm_import_instance_network() int32 + +func InstanceNetwork() *wasi_sockets_0_2_0_network.Network { + + result := wasm_import_instance_network() + return wasi_sockets_0_2_0_network.NetworkFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go new file mode 100644 index 00000000..ddf5b6ad --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go @@ -0,0 +1,174 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_ip_name_lookup + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + "runtime" + "unsafe" +) + +type Pollable = wasi_io_0_2_0_poll.Pollable +type Network = wasi_sockets_0_2_0_network.Network +type ErrorCode = wasi_sockets_0_2_0_network.ErrorCode +type IpAddress = wasi_sockets_0_2_0_network.IpAddress + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream +func resourceDropResolveAddressStream(handle int32) + +type ResolveAddressStream struct { + handle *wit_runtime.Handle +} + +func (self *ResolveAddressStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *ResolveAddressStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *ResolveAddressStream) Handle() int32 { + return self.handle.Use() +} + +func (self *ResolveAddressStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropResolveAddressStream(handle) + } +} + +func ResolveAddressStreamFromOwnHandle(handleValue int32) *ResolveAddressStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &ResolveAddressStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropResolveAddressStream(handleValue) + } + }, 0) + return value +} + +func ResolveAddressStreamFromBorrowHandle(handleValue int32) *ResolveAddressStream { + return ResolveAddressStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses +func wasm_import_resolve_addresses(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func ResolveAddresses(network *wasi_sockets_0_2_0_network.Network, name string) wit_types.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + wasm_import_resolve_addresses((network).Handle(), uintptr(utf8), uint32(len(name)), returnArea) + var result wit_types.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](ResolveAddressStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address +func wasm_import_method_resolve_address_stream_resolve_next_address(arg0 int32, arg1 uintptr) + +func (self *ResolveAddressStream) ResolveNextAddress() wit_types.Result[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 22, 2)) + wasm_import_method_resolve_address_stream_resolve_next_address((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option wit_types.Option[wasi_sockets_0_2_0_network.IpAddress] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))) { + case 0: + + option = wit_types.None[wasi_sockets_0_2_0_network.IpAddress]() + case 1: + var variant wasi_sockets_0_2_0_network.IpAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv4(wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 7)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 9))))}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv6(wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 14)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))}) + + default: + panic("unreachable") + } + + option = wit_types.Some[wasi_sockets_0_2_0_network.IpAddress](variant) + default: + panic("unreachable") + } + + result = wit_types.Ok[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](option) + case 1: + + result = wit_types.Err[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe +func wasm_import_method_resolve_address_stream_subscribe(arg0 int32) int32 + +func (self *ResolveAddressStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_resolve_address_stream_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go new file mode 100644 index 00000000..2d29c1f9 --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go @@ -0,0 +1,256 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_network + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "runtime" +) + +//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +func resourceDropNetwork(handle int32) + +// 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. +type Network struct { + handle *wit_runtime.Handle +} + +func (self *Network) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *Network) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *Network) Handle() int32 { + return self.handle.Use() +} + +func (self *Network) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropNetwork(handle) + } +} + +func NetworkFromOwnHandle(handleValue int32) *Network { + handle := wit_runtime.MakeHandle(handleValue) + value := &Network{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropNetwork(handleValue) + } + }, 0) + return value +} + +func NetworkFromBorrowHandle(handleValue int32) *Network { + return NetworkFromOwnHandle(handleValue) +} + +const ( + // Unknown error + ErrorCodeUnknown uint8 = 0 + // Access denied. + // + // POSIX equivalent: EACCES, EPERM + ErrorCodeAccessDenied uint8 = 1 + // The operation is not supported. + // + // POSIX equivalent: EOPNOTSUPP + ErrorCodeNotSupported uint8 = 2 + // One of the arguments is invalid. + // + // POSIX equivalent: EINVAL + ErrorCodeInvalidArgument uint8 = 3 + // Not enough memory to complete the operation. + // + // POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY + ErrorCodeOutOfMemory uint8 = 4 + // The operation timed out before it could finish completely. + ErrorCodeTimeout uint8 = 5 + // This operation is incompatible with another asynchronous operation that is already in progress. + // + // POSIX equivalent: EALREADY + ErrorCodeConcurrencyConflict uint8 = 6 + // 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 uint8 = 7 + // 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 uint8 = 8 + // The operation is not valid in the socket's current state. + ErrorCodeInvalidState uint8 = 9 + // A new socket resource could not be created because of a system limit. + ErrorCodeNewSocketLimit uint8 = 10 + // A bind operation failed because the provided address is not an address that the `network` can bind to. + ErrorCodeAddressNotBindable uint8 = 11 + // A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. + ErrorCodeAddressInUse uint8 = 12 + // The remote address is not reachable + ErrorCodeRemoteUnreachable uint8 = 13 + // The TCP connection was forcefully rejected + ErrorCodeConnectionRefused uint8 = 14 + // The TCP connection was reset. + ErrorCodeConnectionReset uint8 = 15 + // A TCP connection was aborted. + ErrorCodeConnectionAborted uint8 = 16 + // The size of a datagram sent to a UDP socket exceeded the maximum + // supported size. + ErrorCodeDatagramTooLarge uint8 = 17 + // Name does not exist or has no suitable associated IP addresses. + ErrorCodeNameUnresolvable uint8 = 18 + // A temporary failure in name resolution occurred. + ErrorCodeTemporaryResolverFailure uint8 = 19 + // A permanent failure in name resolution occurred. + ErrorCodePermanentResolverFailure uint8 = 20 +) + +// 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. +type ErrorCode = uint8 + +const ( + // Similar to `AF_INET` in POSIX. + IpAddressFamilyIpv4 uint8 = 0 + // Similar to `AF_INET6` in POSIX. + IpAddressFamilyIpv6 uint8 = 1 +) + +type IpAddressFamily = uint8 +type Ipv4Address = wit_types.Tuple4[uint8, uint8, uint8, uint8] +type Ipv6Address = wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] + +const ( + IpAddressIpv4 uint8 = 0 + IpAddressIpv6 uint8 = 1 +) + +type IpAddress struct { + tag uint8 + value any +} + +func (self IpAddress) Tag() uint8 { + return self.tag +} + +func (self IpAddress) Ipv4() wit_types.Tuple4[uint8, uint8, uint8, uint8] { + if self.tag != IpAddressIpv4 { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint8]) +} +func (self IpAddress) Ipv6() wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] { + if self.tag != IpAddressIpv6 { + panic("tag mismatch") + } + return self.value.(wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) +} + +func MakeIpAddressIpv4(value wit_types.Tuple4[uint8, uint8, uint8, uint8]) IpAddress { + return IpAddress{IpAddressIpv4, value} +} +func MakeIpAddressIpv6(value wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) IpAddress { + return IpAddress{IpAddressIpv6, value} +} + +type Ipv4SocketAddress struct { + // sin_port + Port uint16 + // sin_addr + Address wit_types.Tuple4[uint8, uint8, uint8, uint8] +} + +type Ipv6SocketAddress struct { + // sin6_port + Port uint16 + // sin6_flowinfo + FlowInfo uint32 + // sin6_addr + Address wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] + // sin6_scope_id + ScopeId uint32 +} + +const ( + IpSocketAddressIpv4 uint8 = 0 + IpSocketAddressIpv6 uint8 = 1 +) + +type IpSocketAddress struct { + tag uint8 + value any +} + +func (self IpSocketAddress) Tag() uint8 { + return self.tag +} + +func (self IpSocketAddress) Ipv4() Ipv4SocketAddress { + if self.tag != IpSocketAddressIpv4 { + panic("tag mismatch") + } + return self.value.(Ipv4SocketAddress) +} +func (self IpSocketAddress) Ipv6() Ipv6SocketAddress { + if self.tag != IpSocketAddressIpv6 { + panic("tag mismatch") + } + return self.value.(Ipv6SocketAddress) +} + +func MakeIpSocketAddressIpv4(value Ipv4SocketAddress) IpSocketAddress { + return IpSocketAddress{IpSocketAddressIpv4, value} +} +func MakeIpSocketAddressIpv6(value Ipv6SocketAddress) IpSocketAddress { + return IpSocketAddress{IpSocketAddressIpv6, value} +} diff --git a/v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go new file mode 100644 index 00000000..a1421766 --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go @@ -0,0 +1,908 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_tcp + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + "runtime" + "unsafe" +) + +type InputStream = wasi_io_0_2_0_streams.InputStream +type OutputStream = wasi_io_0_2_0_streams.OutputStream +type Pollable = wasi_io_0_2_0_poll.Pollable +type Duration = uint64 +type Network = wasi_sockets_0_2_0_network.Network +type ErrorCode = wasi_sockets_0_2_0_network.ErrorCode +type IpSocketAddress = wasi_sockets_0_2_0_network.IpSocketAddress +type IpAddressFamily = wasi_sockets_0_2_0_network.IpAddressFamily + +const ( + // Similar to `SHUT_RD` in POSIX. + ShutdownTypeReceive uint8 = 0 + // Similar to `SHUT_WR` in POSIX. + ShutdownTypeSend uint8 = 1 + // Similar to `SHUT_RDWR` in POSIX. + ShutdownTypeBoth uint8 = 2 +) + +type ShutdownType = uint8 + +//go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket +func resourceDropTcpSocket(handle int32) + +// 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. +type TcpSocket struct { + handle *wit_runtime.Handle +} + +func (self *TcpSocket) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *TcpSocket) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *TcpSocket) Handle() int32 { + return self.handle.Use() +} + +func (self *TcpSocket) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropTcpSocket(handle) + } +} + +func TcpSocketFromOwnHandle(handleValue int32) *TcpSocket { + handle := wit_runtime.MakeHandle(handleValue) + value := &TcpSocket{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropTcpSocket(handleValue) + } + }, 0) + return value +} + +func TcpSocketFromBorrowHandle(handleValue int32) *TcpSocket { + return TcpSocketFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind +func wasm_import_method_tcp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) + +func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + var variant int32 + var variant0 int32 + var variant1 int32 + var variant2 int32 + var variant3 int32 + var variant4 int32 + var variant5 int32 + var variant6 int32 + var variant7 int32 + var variant8 int32 + var variant9 int32 + var variant10 int32 + switch localAddress.Tag() { + case wasi_sockets_0_2_0_network.IpSocketAddressIpv4: + payload := localAddress.Ipv4() + + variant = int32(0) + variant0 = int32((payload).Port) + variant1 = int32(((payload).Address).F0) + variant2 = int32(((payload).Address).F1) + variant3 = int32(((payload).Address).F2) + variant4 = int32(((payload).Address).F3) + variant5 = 0 + variant6 = 0 + variant7 = 0 + variant8 = 0 + variant9 = 0 + variant10 = 0 + + case wasi_sockets_0_2_0_network.IpSocketAddressIpv6: + payload := localAddress.Ipv6() + + variant = int32(1) + variant0 = int32((payload).Port) + variant1 = int32((payload).FlowInfo) + variant2 = int32(((payload).Address).F0) + variant3 = int32(((payload).Address).F1) + variant4 = int32(((payload).Address).F2) + variant5 = int32(((payload).Address).F3) + variant6 = int32(((payload).Address).F4) + variant7 = int32(((payload).Address).F5) + variant8 = int32(((payload).Address).F6) + variant9 = int32(((payload).Address).F7) + variant10 = int32((payload).ScopeId) + + default: + panic("unreachable") + } + wasm_import_method_tcp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result11 := result + return result11 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind +func wasm_import_method_tcp_socket_finish_bind(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_finish_bind((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect +func wasm_import_method_tcp_socket_start_connect(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) + +func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_0_network.Network, remoteAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + var variant int32 + var variant0 int32 + var variant1 int32 + var variant2 int32 + var variant3 int32 + var variant4 int32 + var variant5 int32 + var variant6 int32 + var variant7 int32 + var variant8 int32 + var variant9 int32 + var variant10 int32 + switch remoteAddress.Tag() { + case wasi_sockets_0_2_0_network.IpSocketAddressIpv4: + payload := remoteAddress.Ipv4() + + variant = int32(0) + variant0 = int32((payload).Port) + variant1 = int32(((payload).Address).F0) + variant2 = int32(((payload).Address).F1) + variant3 = int32(((payload).Address).F2) + variant4 = int32(((payload).Address).F3) + variant5 = 0 + variant6 = 0 + variant7 = 0 + variant8 = 0 + variant9 = 0 + variant10 = 0 + + case wasi_sockets_0_2_0_network.IpSocketAddressIpv6: + payload := remoteAddress.Ipv6() + + variant = int32(1) + variant0 = int32((payload).Port) + variant1 = int32((payload).FlowInfo) + variant2 = int32(((payload).Address).F0) + variant3 = int32(((payload).Address).F1) + variant4 = int32(((payload).Address).F2) + variant5 = int32(((payload).Address).F3) + variant6 = int32(((payload).Address).F4) + variant7 = int32(((payload).Address).F5) + variant8 = int32(((payload).Address).F6) + variant9 = int32(((payload).Address).F7) + variant10 = int32((payload).ScopeId) + + default: + panic("unreachable") + } + wasm_import_method_tcp_socket_start_connect((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result11 := result + return result11 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect +func wasm_import_method_tcp_socket_finish_connect(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) FinishConnect() wit_types.Result[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + wasm_import_method_tcp_socket_finish_connect((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) + case 1: + + result = wit_types.Err[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen +func wasm_import_method_tcp_socket_start_listen(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) StartListen() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_start_listen((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen +func wasm_import_method_tcp_socket_finish_listen(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) FinishListen() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_finish_listen((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept +func wasm_import_method_tcp_socket_accept(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) Accept() wit_types.Result[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 4)) + wasm_import_method_tcp_socket_accept((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))}) + case 1: + + result = wit_types.Err[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address +func wasm_import_method_tcp_socket_local_address(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + wasm_import_method_tcp_socket_local_address((self).Handle(), returnArea) + var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var variant wasi_sockets_0_2_0_network.IpSocketAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + + default: + panic("unreachable") + } + + result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + case 1: + + result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address +func wasm_import_method_tcp_socket_remote_address(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) RemoteAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + wasm_import_method_tcp_socket_remote_address((self).Handle(), returnArea) + var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var variant wasi_sockets_0_2_0_network.IpSocketAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + + default: + panic("unreachable") + } + + result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + case 1: + + result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening +func wasm_import_method_tcp_socket_is_listening(arg0 int32) int32 + +func (self *TcpSocket) IsListening() bool { + + result := wasm_import_method_tcp_socket_is_listening((self).Handle()) + return (result != 0) + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family +func wasm_import_method_tcp_socket_address_family(arg0 int32) int32 + +func (self *TcpSocket) AddressFamily() wasi_sockets_0_2_0_network.IpAddressFamily { + + result := wasm_import_method_tcp_socket_address_family((self).Handle()) + return uint8(result) + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size +func wasm_import_method_tcp_socket_set_listen_backlog_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *TcpSocket) SetListenBacklogSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_listen_backlog_size((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled +func wasm_import_method_tcp_socket_keep_alive_enabled(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) KeepAliveEnabled() wit_types.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_keep_alive_enabled((self).Handle(), returnArea) + var result wit_types.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[bool, wasi_sockets_0_2_0_network.ErrorCode]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) != 0)) + case 1: + + result = wit_types.Err[bool, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled +func wasm_import_method_tcp_socket_set_keep_alive_enabled(arg0 int32, arg1 int32, arg2 uintptr) + +func (self *TcpSocket) SetKeepAliveEnabled(value bool) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + var result int32 + if value { + result = 1 + } else { + result = 0 + } + wasm_import_method_tcp_socket_set_keep_alive_enabled((self).Handle(), result, returnArea) + var result0 wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result0 = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time +func wasm_import_method_tcp_socket_keep_alive_idle_time(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) KeepAliveIdleTime() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_tcp_socket_keep_alive_idle_time((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time +func wasm_import_method_tcp_socket_set_keep_alive_idle_time(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *TcpSocket) SetKeepAliveIdleTime(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_keep_alive_idle_time((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval +func wasm_import_method_tcp_socket_keep_alive_interval(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) KeepAliveInterval() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_tcp_socket_keep_alive_interval((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval +func wasm_import_method_tcp_socket_set_keep_alive_interval(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *TcpSocket) SetKeepAliveInterval(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_keep_alive_interval((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count +func wasm_import_method_tcp_socket_keep_alive_count(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) KeepAliveCount() wit_types.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_method_tcp_socket_keep_alive_count((self).Handle(), returnArea) + var result wit_types.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + + result = wit_types.Err[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count +func wasm_import_method_tcp_socket_set_keep_alive_count(arg0 int32, arg1 int32, arg2 uintptr) + +func (self *TcpSocket) SetKeepAliveCount(value uint32) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_keep_alive_count((self).Handle(), int32(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit +func wasm_import_method_tcp_socket_hop_limit(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) HopLimit() wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_hop_limit((self).Handle(), returnArea) + var result wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + case 1: + + result = wit_types.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit +func wasm_import_method_tcp_socket_set_hop_limit(arg0 int32, arg1 int32, arg2 uintptr) + +func (self *TcpSocket) SetHopLimit(value uint8) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_hop_limit((self).Handle(), int32(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size +func wasm_import_method_tcp_socket_receive_buffer_size(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_tcp_socket_receive_buffer_size((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size +func wasm_import_method_tcp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *TcpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size +func wasm_import_method_tcp_socket_send_buffer_size(arg0 int32, arg1 uintptr) + +func (self *TcpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_tcp_socket_send_buffer_size((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size +func wasm_import_method_tcp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *TcpSocket) SetSendBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe +func wasm_import_method_tcp_socket_subscribe(arg0 int32) int32 + +func (self *TcpSocket) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_tcp_socket_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown +func wasm_import_method_tcp_socket_shutdown(arg0 int32, arg1 int32, arg2 uintptr) + +func (self *TcpSocket) Shutdown(shutdownType ShutdownType) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_tcp_socket_shutdown((self).Handle(), int32(shutdownType), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} diff --git a/v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go new file mode 100644 index 00000000..6649ccbe --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go @@ -0,0 +1,71 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_tcp_create_socket + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_tcp" + "runtime" + "unsafe" +) + +type Network = wasi_sockets_0_2_0_network.Network +type ErrorCode = wasi_sockets_0_2_0_network.ErrorCode +type IpAddressFamily = wasi_sockets_0_2_0_network.IpAddressFamily +type TcpSocket = wasi_sockets_0_2_0_tcp.TcpSocket + +//go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket +func wasm_import_create_tcp_socket(arg0 int32, arg1 uintptr) + +func CreateTcpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) wit_types.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_create_tcp_socket(int32(addressFamily), returnArea) + var result wit_types.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_tcp.TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} diff --git a/v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go new file mode 100644 index 00000000..f6850295 --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go @@ -0,0 +1,835 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_udp + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + "runtime" + "unsafe" +) + +type Pollable = wasi_io_0_2_0_poll.Pollable +type Network = wasi_sockets_0_2_0_network.Network +type ErrorCode = wasi_sockets_0_2_0_network.ErrorCode +type IpSocketAddress = wasi_sockets_0_2_0_network.IpSocketAddress +type IpAddressFamily = wasi_sockets_0_2_0_network.IpAddressFamily + +// A received datagram. +type IncomingDatagram struct { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + Data []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 wasi_sockets_0_2_0_network.IpSocketAddress +} + +// A datagram to be sent out. +type OutgoingDatagram struct { + // The payload. + Data []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 wit_types.Option[wasi_sockets_0_2_0_network.IpSocketAddress] +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket +func resourceDropUdpSocket(handle int32) + +// A UDP socket handle. +type UdpSocket struct { + handle *wit_runtime.Handle +} + +func (self *UdpSocket) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *UdpSocket) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *UdpSocket) Handle() int32 { + return self.handle.Use() +} + +func (self *UdpSocket) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropUdpSocket(handle) + } +} + +func UdpSocketFromOwnHandle(handleValue int32) *UdpSocket { + handle := wit_runtime.MakeHandle(handleValue) + value := &UdpSocket{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropUdpSocket(handleValue) + } + }, 0) + return value +} + +func UdpSocketFromBorrowHandle(handleValue int32) *UdpSocket { + return UdpSocketFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +func resourceDropIncomingDatagramStream(handle int32) + +type IncomingDatagramStream struct { + handle *wit_runtime.Handle +} + +func (self *IncomingDatagramStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *IncomingDatagramStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *IncomingDatagramStream) Handle() int32 { + return self.handle.Use() +} + +func (self *IncomingDatagramStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropIncomingDatagramStream(handle) + } +} + +func IncomingDatagramStreamFromOwnHandle(handleValue int32) *IncomingDatagramStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &IncomingDatagramStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropIncomingDatagramStream(handleValue) + } + }, 0) + return value +} + +func IncomingDatagramStreamFromBorrowHandle(handleValue int32) *IncomingDatagramStream { + return IncomingDatagramStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +func resourceDropOutgoingDatagramStream(handle int32) + +type OutgoingDatagramStream struct { + handle *wit_runtime.Handle +} + +func (self *OutgoingDatagramStream) TakeHandle() int32 { + return self.handle.Take() +} + +func (self *OutgoingDatagramStream) SetHandle(handle int32) { + self.handle.Set(handle) +} + +func (self *OutgoingDatagramStream) Handle() int32 { + return self.handle.Use() +} + +func (self *OutgoingDatagramStream) Drop() { + handle := self.handle.TakeOrNil() + if handle != 0 { + resourceDropOutgoingDatagramStream(handle) + } +} + +func OutgoingDatagramStreamFromOwnHandle(handleValue int32) *OutgoingDatagramStream { + handle := wit_runtime.MakeHandle(handleValue) + value := &OutgoingDatagramStream{handle} + runtime.AddCleanup(value, func(_ int) { + handleValue := handle.TakeOrNil() + if handleValue != 0 { + resourceDropOutgoingDatagramStream(handleValue) + } + }, 0) + return value +} + +func OutgoingDatagramStreamFromBorrowHandle(handleValue int32) *OutgoingDatagramStream { + return OutgoingDatagramStreamFromOwnHandle(handleValue) +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind +func wasm_import_method_udp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) + +func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + var variant int32 + var variant0 int32 + var variant1 int32 + var variant2 int32 + var variant3 int32 + var variant4 int32 + var variant5 int32 + var variant6 int32 + var variant7 int32 + var variant8 int32 + var variant9 int32 + var variant10 int32 + switch localAddress.Tag() { + case wasi_sockets_0_2_0_network.IpSocketAddressIpv4: + payload := localAddress.Ipv4() + + variant = int32(0) + variant0 = int32((payload).Port) + variant1 = int32(((payload).Address).F0) + variant2 = int32(((payload).Address).F1) + variant3 = int32(((payload).Address).F2) + variant4 = int32(((payload).Address).F3) + variant5 = 0 + variant6 = 0 + variant7 = 0 + variant8 = 0 + variant9 = 0 + variant10 = 0 + + case wasi_sockets_0_2_0_network.IpSocketAddressIpv6: + payload := localAddress.Ipv6() + + variant = int32(1) + variant0 = int32((payload).Port) + variant1 = int32((payload).FlowInfo) + variant2 = int32(((payload).Address).F0) + variant3 = int32(((payload).Address).F1) + variant4 = int32(((payload).Address).F2) + variant5 = int32(((payload).Address).F3) + variant6 = int32(((payload).Address).F4) + variant7 = int32(((payload).Address).F5) + variant8 = int32(((payload).Address).F6) + variant9 = int32(((payload).Address).F7) + variant10 = int32((payload).ScopeId) + + default: + panic("unreachable") + } + wasm_import_method_udp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result11 := result + return result11 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind +func wasm_import_method_udp_socket_finish_bind(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_udp_socket_finish_bind((self).Handle(), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream +func wasm_import_method_udp_socket_stream(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) + +func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_network.IpSocketAddress]) wit_types.Result[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + var option int32 + var option11 int32 + var option12 int32 + var option13 int32 + var option14 int32 + var option15 int32 + var option16 int32 + var option17 int32 + var option18 int32 + var option19 int32 + var option20 int32 + var option21 int32 + var option22 int32 + switch remoteAddress.Tag() { + case wit_types.OptionNone: + + option = int32(0) + option11 = 0 + option12 = 0 + option13 = 0 + option14 = 0 + option15 = 0 + option16 = 0 + option17 = 0 + option18 = 0 + option19 = 0 + option20 = 0 + option21 = 0 + option22 = 0 + case wit_types.OptionSome: + payload := remoteAddress.Some() + var variant int32 + var variant0 int32 + var variant1 int32 + var variant2 int32 + var variant3 int32 + var variant4 int32 + var variant5 int32 + var variant6 int32 + var variant7 int32 + var variant8 int32 + var variant9 int32 + var variant10 int32 + switch payload.Tag() { + case wasi_sockets_0_2_0_network.IpSocketAddressIpv4: + payload := payload.Ipv4() + + variant = int32(0) + variant0 = int32((payload).Port) + variant1 = int32(((payload).Address).F0) + variant2 = int32(((payload).Address).F1) + variant3 = int32(((payload).Address).F2) + variant4 = int32(((payload).Address).F3) + variant5 = 0 + variant6 = 0 + variant7 = 0 + variant8 = 0 + variant9 = 0 + variant10 = 0 + + case wasi_sockets_0_2_0_network.IpSocketAddressIpv6: + payload := payload.Ipv6() + + variant = int32(1) + variant0 = int32((payload).Port) + variant1 = int32((payload).FlowInfo) + variant2 = int32(((payload).Address).F0) + variant3 = int32(((payload).Address).F1) + variant4 = int32(((payload).Address).F2) + variant5 = int32(((payload).Address).F3) + variant6 = int32(((payload).Address).F4) + variant7 = int32(((payload).Address).F5) + variant8 = int32(((payload).Address).F6) + variant9 = int32(((payload).Address).F7) + variant10 = int32((payload).ScopeId) + + default: + panic("unreachable") + } + + option = int32(1) + option11 = variant + option12 = variant0 + option13 = variant1 + option14 = variant2 + option15 = variant3 + option16 = variant4 + option17 = variant5 + option18 = variant6 + option19 = variant7 + option20 = variant8 + option21 = variant9 + option22 = variant10 + default: + panic("unreachable") + } + wasm_import_method_udp_socket_stream((self).Handle(), option, option11, option12, option13, option14, option15, option16, option17, option18, option19, option20, option21, option22, returnArea) + var result wit_types.Result[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream]{IncomingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), OutgoingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) + case 1: + + result = wit_types.Err[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result23 := result + return result23 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address +func wasm_import_method_udp_socket_local_address(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + wasm_import_method_udp_socket_local_address((self).Handle(), returnArea) + var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var variant wasi_sockets_0_2_0_network.IpSocketAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + + default: + panic("unreachable") + } + + result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + case 1: + + result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address +func wasm_import_method_udp_socket_remote_address(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) RemoteAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + wasm_import_method_udp_socket_remote_address((self).Handle(), returnArea) + var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var variant wasi_sockets_0_2_0_network.IpSocketAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + + default: + panic("unreachable") + } + + result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + case 1: + + result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family +func wasm_import_method_udp_socket_address_family(arg0 int32) int32 + +func (self *UdpSocket) AddressFamily() wasi_sockets_0_2_0_network.IpAddressFamily { + + result := wasm_import_method_udp_socket_address_family((self).Handle()) + return uint8(result) + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit +func wasm_import_method_udp_socket_unicast_hop_limit(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) UnicastHopLimit() wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_udp_socket_unicast_hop_limit((self).Handle(), returnArea) + var result wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + case 1: + + result = wit_types.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit +func wasm_import_method_udp_socket_set_unicast_hop_limit(arg0 int32, arg1 int32, arg2 uintptr) + +func (self *UdpSocket) SetUnicastHopLimit(value uint8) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_udp_socket_set_unicast_hop_limit((self).Handle(), int32(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size +func wasm_import_method_udp_socket_receive_buffer_size(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_udp_socket_receive_buffer_size((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size +func wasm_import_method_udp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *UdpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_udp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size +func wasm_import_method_udp_socket_send_buffer_size(arg0 int32, arg1 uintptr) + +func (self *UdpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_udp_socket_send_buffer_size((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size +func wasm_import_method_udp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *UdpSocket) SetSendBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + wasm_import_method_udp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea) + var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + case 1: + + result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe +func wasm_import_method_udp_socket_subscribe(arg0 int32) int32 + +func (self *UdpSocket) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_udp_socket_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +func wasm_import_method_incoming_datagram_stream_receive(arg0 int32, arg1 int64, arg2 uintptr) + +func (self *IncomingDatagramStream) Receive(maxResults uint64) wit_types.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + wasm_import_method_incoming_datagram_stream_receive((self).Handle(), int64(maxResults), returnArea) + var result0 wit_types.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]IncomingDatagram, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(32+2*4)) + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + var variant wasi_sockets_0_2_0_network.IpSocketAddress + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) { + case 0: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (6 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (7 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (9 + 2*4)))))}}) + + case 1: + + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4)))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (14 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4)))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))))}) + + default: + panic("unreachable") + } + + result = append(result, IncomingDatagram{value, variant}) + } + + result0 = wit_types.Ok[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](result) + case 1: + + result0 = wit_types.Err[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +func wasm_import_method_incoming_datagram_stream_subscribe(arg0 int32) int32 + +func (self *IncomingDatagramStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_incoming_datagram_stream_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +func wasm_import_method_outgoing_datagram_stream_check_send(arg0 int32, arg1 uintptr) + +func (self *OutgoingDatagramStream) CheckSend() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + wasm_import_method_outgoing_datagram_stream_check_send((self).Handle(), returnArea) + var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +func wasm_import_method_outgoing_datagram_stream_send(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + slice := datagrams + length := uint32(len(slice)) + result := wit_runtime.Allocate(pinner, uintptr(length*(32+3*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(32+3*4)) + data := unsafe.Pointer(unsafe.SliceData((element).Data)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).Data))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data))) + + switch (element).RemoteAddress.Tag() { + case wit_types.OptionNone: + *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(0)) + + case wit_types.OptionSome: + payload := (element).RemoteAddress.Some() + *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(1)) + + switch payload.Tag() { + case wasi_sockets_0_2_0_network.IpSocketAddressIpv4: + payload := payload.Ipv4() + *(*int8)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))) = int8(int32(0)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))) = int16(int32((payload).Port)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), (10 + 2*4))) = int8(int32(((payload).Address).F0)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), (11 + 2*4))) = int8(int32(((payload).Address).F1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))) = int8(int32(((payload).Address).F2)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), (13 + 2*4))) = int8(int32(((payload).Address).F3)) + + case wasi_sockets_0_2_0_network.IpSocketAddressIpv6: + payload := payload.Ipv6() + *(*int8)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))) = int8(int32(1)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))) = int16(int32((payload).Port)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))) = int32((payload).FlowInfo) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))) = int16(int32(((payload).Address).F0)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))) = int16(int32(((payload).Address).F1)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))) = int16(int32(((payload).Address).F2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))) = int16(int32(((payload).Address).F3)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))) = int16(int32(((payload).Address).F4)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4))) = int16(int32(((payload).Address).F5)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))) = int16(int32(((payload).Address).F6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), (30 + 2*4))) = int16(int32(((payload).Address).F7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), (32 + 2*4))) = int32((payload).ScopeId) + + default: + panic("unreachable") + } + + default: + panic("unreachable") + } + + } + + wasm_import_method_outgoing_datagram_stream_send((self).Handle(), uintptr(result), length, returnArea) + var result0 wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result0 = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + + result0 = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result1 := result0 + return result1 + +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +func wasm_import_method_outgoing_datagram_stream_subscribe(arg0 int32) int32 + +func (self *OutgoingDatagramStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { + + result := wasm_import_method_outgoing_datagram_stream_subscribe((self).Handle()) + return wasi_io_0_2_0_poll.PollableFromOwnHandle(int32(uintptr(result))) + +} diff --git a/v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go b/v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go new file mode 100644 index 00000000..4b570111 --- /dev/null +++ b/v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go @@ -0,0 +1,71 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wasi_sockets_0_2_0_udp_create_socket + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/bytecodealliance/wit-bindgen/wit_types" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_udp" + "runtime" + "unsafe" +) + +type Network = wasi_sockets_0_2_0_network.Network +type ErrorCode = wasi_sockets_0_2_0_network.ErrorCode +type IpAddressFamily = wasi_sockets_0_2_0_network.IpAddressFamily +type UdpSocket = wasi_sockets_0_2_0_udp.UdpSocket + +//go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket +func wasm_import_create_udp_socket(arg0 int32, arg1 uintptr) + +func CreateUdpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) wit_types.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + wasm_import_create_udp_socket(int32(addressFamily), returnArea) + var result wit_types.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = wit_types.Ok[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_udp.UdpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + case 1: + + result = wit_types.Err[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result0 := result + return result0 + +} diff --git a/v3/internal/wit_exports/wit_exports.go b/v3/internal/wit_exports/wit_exports.go new file mode 100644 index 00000000..6da69cee --- /dev/null +++ b/v3/internal/wit_exports/wit_exports.go @@ -0,0 +1,50 @@ +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wit_exports + +import ( + "github.com/bytecodealliance/wit-bindgen/wit_runtime" + "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" + "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + "runtime" +) + +var staticPinner = runtime.Pinner{} +var exportReturnArea = uintptr(wit_runtime.Allocate(&staticPinner, 0, 1)) +var syncExportPinner = runtime.Pinner{} + +//go:wasmexport wasi:http/incoming-handler@0.2.0#handle +func wasm_export_wasi_http_0_2_0_incoming_handler_handle(arg0 int32, arg1 int32) { + + export_wasi_http_0_2_0_incoming_handler.Handle(wasi_http_0_2_0_types.IncomingRequestFromOwnHandle(int32(uintptr(arg0))), wasi_http_0_2_0_types.ResponseOutparamFromOwnHandle(int32(uintptr(arg1)))) + +} diff --git a/v3/kv/kv.go b/v3/kv/kv.go index a381c4f0..e45af711 100644 --- a/v3/kv/kv.go +++ b/v3/kv/kv.go @@ -3,8 +3,7 @@ package kv import ( "fmt" - keyvalue "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/key-value" - "go.bytecodealliance.org/cm" + keyvalue "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_key_value" ) type Store struct { @@ -15,11 +14,11 @@ type Store struct { func Open(label string) (*Store, error) { result := keyvalue.StoreOpen(label) if result.IsErr() { - return nil, errorVariantToError(*result.Err()) + return nil, errorVariantToError(result.Err()) } return &Store{ - store: result.OK(), + store: result.Ok(), }, nil } @@ -32,9 +31,9 @@ func OpenDefault() (*Store, error) { // Set the key/value pair in store func (s *Store) Set(key string, value []byte) error { - result := s.store.Set(key, cm.ToList(value)) + result := s.store.Set(key, value) if result.IsErr() { - return errorVariantToError(*result.Err()) + return errorVariantToError(result.Err()) } return nil @@ -44,22 +43,22 @@ func (s *Store) Set(key string, value []byte) error { func (s *Store) Get(key string) ([]byte, error) { result := s.store.Get(key) if result.IsErr() { - return nil, errorVariantToError(*result.Err()) + return nil, errorVariantToError(result.Err()) } - value := result.OK() - if value.None() { + value := result.Ok() + if value.IsNone() { return []byte(""), nil } - return value.Some().Slice(), nil + return value.Some(), nil } // Delete the given key/value from the store func (s *Store) Delete(key string) error { result := s.store.Delete(key) if result.IsErr() { - return errorVariantToError(*result.Err()) + return errorVariantToError(result.Err()) } return nil @@ -69,35 +68,33 @@ func (s *Store) Delete(key string) error { func (s *Store) Exists(key string) (bool, error) { result := s.store.Exists(key) if result.IsErr() { - return false, errorVariantToError(*result.Err()) + return false, errorVariantToError(result.Err()) } - return *result.OK(), nil + return result.Ok(), nil } // GetKets returns all the keys from the store func (s *Store) GetKeys() ([]string, error) { result := s.store.GetKeys() if result.IsErr() { - return nil, errorVariantToError(*result.Err()) + return nil, errorVariantToError(result.Err()) } - return result.OK().Slice(), nil + return result.Ok(), nil } func errorVariantToError(code keyvalue.Error) error { - switch code { - case keyvalue.ErrorAccessDenied(): + switch code.Tag() { + case keyvalue.ErrorAccessDenied: return fmt.Errorf("access denied") - case keyvalue.ErrorNoSuchStore(): + case keyvalue.ErrorNoSuchStore: return fmt.Errorf("no such store") - case keyvalue.ErrorStoreTableFull(): + case keyvalue.ErrorStoreTableFull: return fmt.Errorf("store table full") + case keyvalue.ErrorOther: + return fmt.Errorf("%v", code.Other()) default: - if code.Other() != nil { - return fmt.Errorf(*code.Other()) - } - return fmt.Errorf("no error provided by host implementation") } } diff --git a/v3/kv/testdata/key-value/go.mod b/v3/kv/testdata/key-value/go.mod index 7eaae3f7..729b6996 100644 --- a/v3/kv/testdata/key-value/go.mod +++ b/v3/kv/testdata/key-value/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/http/testdata/kv -go 1.24.1 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/kv/testdata/key-value/go.sum b/v3/kv/testdata/key-value/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/kv/testdata/key-value/go.sum +++ b/v3/kv/testdata/key-value/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/kv/testdata/key-value/spin.toml b/v3/kv/testdata/key-value/spin.toml index ea812110..3fecd43a 100644 --- a/v3/kv/testdata/key-value/spin.toml +++ b/v3/kv/testdata/key-value/spin.toml @@ -2,7 +2,7 @@ spin_manifest_version = 2 [application] authors = ["Rajat Jindal "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." name = "key-value" version = "1.0.0" @@ -14,5 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" diff --git a/v3/llm/llm.go b/v3/llm/llm.go index b634c390..59ad7423 100644 --- a/v3/llm/llm.go +++ b/v3/llm/llm.go @@ -3,8 +3,8 @@ package llm import ( "fmt" - "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/llm" - "go.bytecodealliance.org/cm" + "github.com/bytecodealliance/wit-bindgen/wit_types" + llm "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_llm" ) // The model use for inferencing @@ -46,7 +46,9 @@ type InferencingResult struct { // Usage information related to the inferencing result type InferencingUsage struct { - _ cm.HostLayout `json:"-"` + // TODO: It's not clear whether this is important. + // _ cm.HostLayout `json:"-"` + // Number of tokens in the prompt PromptTokenCount uint32 `json:"prompt-token-count"` @@ -75,9 +77,9 @@ type EmbeddingsUsage struct { // Infer performs inferencing using the provided model and prompt with the // given optional parameters. func Infer(model string, prompt string, params *InferencingParams) (InferencingResult, error) { - iparams := cm.None[llm.InferencingParams]() + iparams := wit_types.None[llm.InferencingParams]() if params != nil { - iparams = cm.Some(llm.InferencingParams{ + iparams = wit_types.Some(llm.InferencingParams{ MaxTokens: params.MaxTokens, RepeatPenalty: params.RepeatPenalty, RepeatPenaltyLastNTokenCount: params.RepeatPenaltyLastNTokenCount, @@ -89,46 +91,46 @@ func Infer(model string, prompt string, params *InferencingParams) (InferencingR result := llm.Infer(llm.InferencingModel(model), prompt, iparams) if result.IsErr() { - return InferencingResult{}, errorVariantToError(*result.Err()) + return InferencingResult{}, errorVariantToError(result.Err()) } return InferencingResult{ - Text: result.OK().Text, + Text: result.Ok().Text, Usage: InferencingUsage{ - PromptTokenCount: result.OK().Usage.PromptTokenCount, - GeneratedTokenCount: result.OK().Usage.GeneratedTokenCount, + PromptTokenCount: result.Ok().Usage.PromptTokenCount, + GeneratedTokenCount: result.Ok().Usage.GeneratedTokenCount, }, }, nil } // GenerateEmbeddings generates the embeddings for the supplied list of text. func GenerateEmbeddings(model EmbeddingModel, text []string) (*EmbeddingsResult, error) { - result := llm.GenerateEmbeddings(llm.EmbeddingModel(model), cm.ToList(text)) + result := llm.GenerateEmbeddings(llm.EmbeddingModel(model), text) if result.IsErr() { - return &EmbeddingsResult{}, errorVariantToError(*result.Err()) + return &EmbeddingsResult{}, errorVariantToError(result.Err()) } embeddings := [][]float32{} - for _, l := range result.OK().Embeddings.Slice() { - embeddings = append(embeddings, l.Slice()) + for _, l := range result.Ok().Embeddings { + embeddings = append(embeddings, l) } return &EmbeddingsResult{ Embeddings: embeddings, Usage: &EmbeddingsUsage{ - PromptTokenCount: int(result.OK().Usage.PromptTokenCount), + PromptTokenCount: int(result.Ok().Usage.PromptTokenCount), }, }, nil } func errorVariantToError(err llm.Error) error { - switch { - case llm.ErrorModelNotSupported() == err: + switch err.Tag() { + case llm.ErrorModelNotSupported: return fmt.Errorf("model not supported") - case err.RuntimeError() != nil: - return fmt.Errorf("runtime error %s", *err.RuntimeError()) - case err.InvalidInput() != nil: - return fmt.Errorf("invalid input %s", *err.InvalidInput()) + case llm.ErrorRuntimeError: + return fmt.Errorf("runtime error %s", err.RuntimeError()) + case llm.ErrorInvalidInput: + return fmt.Errorf("invalid input %s", err.InvalidInput()) default: return fmt.Errorf("no error provided by host implementation") } diff --git a/v3/mqtt/mqtt.go b/v3/mqtt/mqtt.go index 8a56b5f9..0430e011 100644 --- a/v3/mqtt/mqtt.go +++ b/v3/mqtt/mqtt.go @@ -1,11 +1,9 @@ package mqtt import ( - "errors" "fmt" - "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/mqtt" - "go.bytecodealliance.org/cm" + mqtt "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_mqtt" ) type Connection struct { @@ -14,19 +12,19 @@ type Connection struct { // OpenConnection initializes an MQTT connection func OpenConnection(address, username, password string, keepAliveIntervalInSecs uint64) (Connection, error) { - conn, err, isErr := mqtt.ConnectionOpen(address, username, password, keepAliveIntervalInSecs).Result() - if isErr { - return Connection{}, toError(&err) + result := mqtt.ConnectionOpen(address, username, password, keepAliveIntervalInSecs) + if result.IsErr() { + return Connection{}, toError(result.Err()) } - return Connection{conn: conn}, nil + return Connection{conn: *result.Ok()}, nil } // Publish publishes an MQTT message func (c *Connection) Publish(topic string, payload []byte, qos QoS) error { - _, err, isErr := c.conn.Publish(topic, mqtt.Payload(cm.ToList(payload)), mqtt.Qos(qos)).Result() - if isErr { - return toError(&err) + result := c.conn.Publish(topic, mqtt.Payload(payload), mqtt.Qos(qos)) + if result.IsErr() { + return toError(result.Err()) } return nil @@ -41,18 +39,11 @@ const ( QosExactlyOnce = mqtt.QosExactlyOnce ) -func toError(err *mqtt.Error) error { - if err == nil { - return nil +func toError(err mqtt.Error) error { + switch err.Tag() { + case mqtt.ErrorConnectionFailed: + return fmt.Errorf("connection-failed: %s", err.ConnectionFailed()) + default: + return fmt.Errorf("%s", err.Other()) } - - if err.String() == "connection-failed" { - return fmt.Errorf("connection-failed: %s", *err.ConnectionFailed()) - } - - if err.String() == "other" { - return fmt.Errorf(*err.Other()) - } - - return errors.New(err.String()) } diff --git a/v3/mysql/mysql.go b/v3/mysql/mysql.go index 6d1729df..d3a65e02 100644 --- a/v3/mysql/mysql.go +++ b/v3/mysql/mysql.go @@ -9,9 +9,8 @@ import ( "reflect" spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" - "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/mysql" - rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/rdbms-types" - "go.bytecodealliance.org/cm" + mysql "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_mysql" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" ) // Open returns a new connection to the database. @@ -56,7 +55,7 @@ func (d *connector) Open(name string) (driver.Conn, error) { if results.IsErr() { return nil, toError(results.Err()) } - d.conn = &conn{spinConn: *results.OK()} + d.conn = &conn{spinConn: *results.Ok()} return d.conn, nil } @@ -156,9 +155,9 @@ func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { wasiParams[i] = toWasiParameterValue(v) } - _, err, isErr := s.conn.spinConn.Execute(s.query, cm.ToList(wasiParams)).Result() - if isErr { - return &result{}, toError(&err) + queryResult := s.conn.spinConn.Execute(s.query, wasiParams) + if queryResult.IsErr() { + return &result{}, toError(queryResult.Err()) } return &result{}, nil @@ -171,18 +170,18 @@ func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { wasiParams[i] = toWasiParameterValue(v) } - results, err, isErr := s.conn.spinConn.Query(s.query, cm.ToList(wasiParams)).Result() - if isErr { - return nil, toError(&err) + results := s.conn.spinConn.Query(s.query, wasiParams) + if results.IsErr() { + return nil, toError(results.Err()) } - rowLen := results.Rows.Len() + rowLen := len(results.Ok().Rows) allRows := make([][]any, rowLen) - for rowNum, row := range results.Rows.Slice() { - allRows[rowNum] = toRow(row.Slice()) + for rowNum, row := range results.Ok().Rows { + allRows[rowNum] = toRow(row) } - cols := results.Columns.Slice() + cols := results.Ok().Columns colNames := make([]string, len(cols)) colTypes := make([]uint8, len(cols)) for i, c := range cols { @@ -202,91 +201,87 @@ func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { func toWasiParameterValue(x any) mysql.ParameterValue { switch v := x.(type) { case bool: - return rdbmstypes.ParameterValueBoolean(v) + return rdbmstypes.MakeParameterValueBoolean(v) case int8: - return rdbmstypes.ParameterValueInt8(v) + return rdbmstypes.MakeParameterValueInt8(v) case int16: - return rdbmstypes.ParameterValueInt16(v) + return rdbmstypes.MakeParameterValueInt16(v) case int32: - return rdbmstypes.ParameterValueInt32(v) + return rdbmstypes.MakeParameterValueInt32(v) case int64: - return rdbmstypes.ParameterValueInt64(v) + return rdbmstypes.MakeParameterValueInt64(v) case int: - return rdbmstypes.ParameterValueInt64(int64(v)) + return rdbmstypes.MakeParameterValueInt64(int64(v)) case uint8: - return rdbmstypes.ParameterValueUint8(v) + return rdbmstypes.MakeParameterValueUint8(v) case uint16: - return rdbmstypes.ParameterValueUint16(v) + return rdbmstypes.MakeParameterValueUint16(v) case uint32: - return rdbmstypes.ParameterValueUint32(v) + return rdbmstypes.MakeParameterValueUint32(v) case uint64: - return rdbmstypes.ParameterValueUint64(v) + return rdbmstypes.MakeParameterValueUint64(v) case float32: - return rdbmstypes.ParameterValueFloating32(v) + return rdbmstypes.MakeParameterValueFloating32(v) case float64: - return rdbmstypes.ParameterValueFloating64(v) + return rdbmstypes.MakeParameterValueFloating64(v) case string: - return rdbmstypes.ParameterValueStr(v) + return rdbmstypes.MakeParameterValueStr(v) case []byte: - return rdbmstypes.ParameterValueBinary(cm.ToList([]uint8(v))) + return rdbmstypes.MakeParameterValueBinary(v) case nil: - return rdbmstypes.ParameterValueDbNull() + return rdbmstypes.MakeParameterValueDbNull() default: panic("unknown value type") } } -func toError(err *mysql.Error) error { - if err == nil { - return nil - } - - switch err.String() { - case "bad-parameter": - return errors.New(*err.BadParameter()) - case "connection-failed": - return errors.New(*err.ConnectionFailed()) - case "query-failed": - return errors.New(*err.QueryFailed()) - case "value-conversion-failed": - return errors.New(*err.ValueConversionFailed()) +func toError(err mysql.Error) error { + switch err.Tag() { + case rdbmstypes.ErrorBadParameter: + return errors.New(err.BadParameter()) + case rdbmstypes.ErrorConnectionFailed: + return errors.New(err.ConnectionFailed()) + case rdbmstypes.ErrorQueryFailed: + return errors.New(err.QueryFailed()) + case rdbmstypes.ErrorValueConversionFailed: + return errors.New(err.ValueConversionFailed()) default: // TODO: not sure if using "Other" as the default is appropriate - return errors.New(*err.Other()) + return errors.New(err.Other()) } } func toRow(row []rdbmstypes.DbValue) []any { result := make([]any, len(row)) for i, v := range row { - switch v.String() { - case "boolean": - result[i] = *v.Boolean() - case "int8": - result[i] = *v.Int8() - case "int16": - result[i] = *v.Int16() - case "int32": - result[i] = *v.Int32() - case "int64": - result[i] = *v.Int64() - case "uint8": - result[i] = *v.Uint8() - case "uint16": - result[i] = *v.Uint16() - case "uint32": - result[i] = *v.Uint32() - case "uint64": - result[i] = *v.Uint64() - case "floating32": - result[i] = *v.Floating32() - case "floating64": - result[i] = *v.Floating64() - case "str": - result[i] = *v.Str() - case "binary": - result[i] = *v.Binary() - case "db-null": + switch v.Tag() { + case rdbmstypes.DbValueBoolean: + result[i] = v.Boolean() + case rdbmstypes.DbValueInt8: + result[i] = v.Int8() + case rdbmstypes.DbValueInt16: + result[i] = v.Int16() + case rdbmstypes.DbValueInt32: + result[i] = v.Int32() + case rdbmstypes.DbValueInt64: + result[i] = v.Int64() + case rdbmstypes.DbValueUint8: + result[i] = v.Uint8() + case rdbmstypes.DbValueUint16: + result[i] = v.Uint16() + case rdbmstypes.DbValueUint32: + result[i] = v.Uint32() + case rdbmstypes.DbValueUint64: + result[i] = v.Uint64() + case rdbmstypes.DbValueFloating32: + result[i] = v.Floating32() + case rdbmstypes.DbValueFloating64: + result[i] = v.Floating64() + case rdbmstypes.DbValueStr: + result[i] = v.Str() + case rdbmstypes.DbValueBinary: + result[i] = v.Binary() + case rdbmstypes.DbValueDbNull: result[i] = nil default: panic("unknown value type") diff --git a/v3/redis/redis.go b/v3/redis/redis.go index 0d6ce01f..f7377191 100644 --- a/v3/redis/redis.go +++ b/v3/redis/redis.go @@ -4,11 +4,9 @@ package redis import ( - "errors" "fmt" - "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/redis" - "go.bytecodealliance.org/cm" + redis "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_redis" ) // Client is a Redis client. @@ -18,19 +16,19 @@ type Client struct { // NewClient returns a Redis client. func NewClient(address string) (Client, error) { - conn, err, isErr := redis.ConnectionOpen(address).Result() - if isErr { - return Client{}, toError(err) + result := redis.ConnectionOpen(address) + if result.IsErr() { + return Client{}, toError(result.Err()) } - return Client{conn: conn}, nil + return Client{conn: *result.Ok()}, nil } // Publish a Redis message to the specified channel. func (c *Client) Publish(channel string, payload []byte) error { - _, err, isErr := c.conn.Publish(channel, redis.Payload(cm.ToList(payload))).Result() - if isErr { - return toError(err) + result := c.conn.Publish(channel, redis.Payload(payload)) + if result.IsErr() { + return toError(result.Err()) } return nil @@ -38,25 +36,25 @@ func (c *Client) Publish(channel string, payload []byte) error { // Get the value of a key. func (c *Client) Get(key string) ([]byte, error) { - payload, err, isErr := c.conn.Get(key).Result() - if isErr { - return nil, toError(err) + result := c.conn.Get(key) + if result.IsErr() { + return nil, toError(result.Err()) } - if payload.None() { + if result.Ok().IsNone() { return nil, nil } - return payload.Some().Slice(), nil + return result.Ok().Some(), nil } // Set key to value. // // If key already holds a value, it is overwritten. func (c *Client) Set(key string, payload []byte) error { - _, err, isErr := c.conn.Set(key, redis.Payload(cm.ToList(payload))).Result() - if isErr { - return toError(err) + result := c.conn.Set(key, redis.Payload(payload)) + if result.IsErr() { + return toError(result.Err()) } return nil @@ -68,54 +66,54 @@ func (c *Client) Set(key string, payload []byte) error { // 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. func (c *Client) Incr(key string) (int64, error) { - incrementedNum, err, isErr := c.conn.Incr(key).Result() - if isErr { - return 0, toError(err) + result := c.conn.Incr(key) + if result.IsErr() { + return 0, toError(result.Err()) } - return incrementedNum, nil + return result.Ok(), nil } // Removes the specified keys. // // A key is ignored if it does not exist. Returns the number of keys deleted. func (c *Client) Del(keys ...string) (uint32, error) { - numKeysDeleted, err, isErr := c.conn.Del(cm.ToList(keys)).Result() - if isErr { - return 0, toError(err) + result := c.conn.Del(keys) + if result.IsErr() { + return 0, toError(result.Err()) } - return numKeysDeleted, nil + return result.Ok(), nil } // Add the specified `values` to the set named `key`, returning the number of newly-added values. func (c *Client) Sadd(key string, values ...string) (uint32, error) { - numValuesAdded, err, isErr := c.conn.Sadd(key, cm.ToList(values)).Result() - if isErr { - return 0, toError(err) + result := c.conn.Sadd(key, values) + if result.IsErr() { + return 0, toError(result.Err()) } - return numValuesAdded, nil + return result.Ok(), nil } // Retrieve the contents of the set named `key`. func (c *Client) Smembers(key string) ([]string, error) { - setValues, err, isErr := c.conn.Smembers(key).Result() - if isErr { - return nil, toError(err) + result := c.conn.Smembers(key) + if result.IsErr() { + return nil, toError(result.Err()) } - return setValues.Slice(), nil + return result.Ok(), nil } // Remove the specified `values` from the set named `key`, returning the number of newly-removed values. func (c *Client) Srem(key string, values ...string) (uint32, error) { - valuesRemoved, err, isErr := c.conn.Srem(key, cm.ToList(values)).Result() - if isErr { - return 0, toError(err) + result := c.conn.Srem(key, values) + if result.IsErr() { + return 0, toError(result.Err()) } - return valuesRemoved, nil + return result.Ok(), nil } // ResultKind represents a result type returned from executing a Redis command. @@ -168,13 +166,13 @@ func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { params = append(params, p) } - redisResults, err, isErr := c.conn.Execute(command, cm.ToList(params)).Result() - if isErr { - return nil, toError(err) + result := c.conn.Execute(command, params) + if result.IsErr() { + return nil, toError(result.Err()) } var results []*Result - for _, r := range redisResults.Slice() { + for _, r := range result.Ok() { results = append(results, toResult(r)) } @@ -184,49 +182,45 @@ func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { func createParameter(x any) (redis.RedisParameter, error) { switch v := x.(type) { case int: - return redis.RedisParameterInt64(int64(v)), nil + return redis.MakeRedisParameterInt64(int64(v)), nil case int64: - return redis.RedisParameterInt64(v), nil + return redis.MakeRedisParameterInt64(v), nil case int32: - return redis.RedisParameterInt64(int64(v)), nil + return redis.MakeRedisParameterInt64(int64(v)), nil case []byte: - return redis.RedisParameterBinary(redis.Payload(cm.ToList(v))), nil + return redis.MakeRedisParameterBinary(redis.Payload(v)), nil case string: - return redis.RedisParameterBinary(redis.Payload(cm.ToList([]byte(v)))), nil + return redis.MakeRedisParameterBinary(redis.Payload(v)), nil default: return redis.RedisParameter{}, fmt.Errorf("invalid type %T; must be string, []byte, int, int64, or int32", v) } } func toResult(param redis.RedisResult) *Result { - switch { - case param.Status() != nil: + switch param.Tag() { + case redis.RedisResultStatus: return &Result{ Kind: ResultKindStatus, Val: param.Status(), } - case param.Int64() != nil: + case redis.RedisResultInt64: return &Result{ Kind: ResultKindInt64, Val: param.Int64(), } - case param.Binary() != nil: + case redis.RedisResultBinary: return &Result{ Kind: ResultKindBinary, - Val: param.Binary().Slice(), + Val: param.Binary(), } default: return &Result{ Kind: ResultKindNil, - Val: param.Nil(), + Val: nil, } } } func toError(e redis.Error) error { - if e.String() == "other" { - return fmt.Errorf(*e.Other()) - } - - return errors.New(e.String()) + return fmt.Errorf("%v", e.Other()) } diff --git a/v3/variables/testdata/variables/go.mod b/v3/variables/testdata/variables/go.mod index 6c5be5e0..fd8eeae6 100644 --- a/v3/variables/testdata/variables/go.mod +++ b/v3/variables/testdata/variables/go.mod @@ -1,12 +1,14 @@ module github.com/spinframework/spin-go-sdk/v3/examples/variables -go 1.24.1 +go 1.25.5 require github.com/spinframework/spin-go-sdk/v3 v3.0.0 require ( + github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect - go.bytecodealliance.org/cm v0.2.2 // indirect ) replace github.com/spinframework/spin-go-sdk/v3 => ../../../ + +replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/variables/testdata/variables/go.sum b/v3/variables/testdata/variables/go.sum index c1ebfdf4..00db3b18 100644 --- a/v3/variables/testdata/variables/go.sum +++ b/v3/variables/testdata/variables/go.sum @@ -1,4 +1,4 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA= -go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= diff --git a/v3/variables/testdata/variables/spin.toml b/v3/variables/testdata/variables/spin.toml index 58959765..1ab5cd44 100644 --- a/v3/variables/testdata/variables/spin.toml +++ b/v3/variables/testdata/variables/spin.toml @@ -3,7 +3,7 @@ spin_manifest_version = 2 [application] name = "variables-example" authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." version = "1.0.0" [variables] @@ -19,5 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "tinygo build -target=wasip2 --wit-package $(go list -mod=readonly -m -f '{{.Dir}}' github.com/spinframework/spin-go-sdk/v3)/wit --wit-world http-trigger -gc=leaking -no-debug -o main.wasm main.go" +command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" diff --git a/v3/variables/variables.go b/v3/variables/variables.go index 87fbd5b5..8d70b792 100644 --- a/v3/variables/variables.go +++ b/v3/variables/variables.go @@ -3,7 +3,7 @@ package variables import ( "fmt" - "github.com/spinframework/spin-go-sdk/v3/internal/fermyon/spin/v2.0.0/variables" + variables "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_variables" ) // Get an application variable value for the current component. @@ -12,25 +12,23 @@ import ( func Get(key string) (string, error) { result := variables.Get(key) if result.IsErr() { - return "", errorVariantToError(*result.Err()) + return "", errorVariantToError(result.Err()) } - return *result.OK(), nil + return result.Ok(), nil } func errorVariantToError(err variables.Error) error { - switch { - case err.InvalidName() != nil: - return fmt.Errorf(*err.InvalidName()) - case err.Provider() != nil: - return fmt.Errorf(*err.Provider()) - case err.Undefined() != nil: - return fmt.Errorf(*err.Undefined()) + switch err.Tag() { + case variables.ErrorInvalidName: + return fmt.Errorf("%v", err.InvalidName()) + case variables.ErrorProvider: + return fmt.Errorf("%v", err.Provider()) + case variables.ErrorUndefined: + return fmt.Errorf("%v", err.Undefined()) + case variables.ErrorOther: + return fmt.Errorf("%v", err.Other()) default: - if err.Other() != nil { - return fmt.Errorf(*err.Other()) - } - return fmt.Errorf("no error provided by host implementation") } } From af71a11ab0e48cab66973c3361101c104d8af73b Mon Sep 17 00:00:00 2001 From: Andrew Steurer <94206073+asteurer@users.noreply.github.com> Date: Tue, 27 Jan 2026 15:14:34 -0600 Subject: [PATCH 12/22] fix: update componentize-go endpoint Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com> --- .github/workflows/pr.yaml | 2 +- v3/README.md | 2 +- v3/examples/http/README.md | 2 +- v3/examples/kv/README.md | 2 +- v3/examples/mqtt-outbound/README.md | 2 +- v3/examples/mysql-outbound/README.md | 2 +- v3/examples/redis-outbound/README.md | 2 +- v3/examples/variables/README.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 8e6b0809..be1448d0 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -20,7 +20,7 @@ jobs: - name: Setup componentize-go run: | - curl -LO https://github.com/asteurer/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz + curl -LO https://github.com/bytecodealliance/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz echo "27fc32998f023a88a6a1f44524631a705163f23ce2a02fc14987726897360027 componentize-go-linux-amd64.tar.gz" | sha256sum --check tar -xf componentize-go-linux-amd64.tar.gz chmod +x componentize-go diff --git a/v3/README.md b/v3/README.md index e81e93c7..1bd0c4d9 100644 --- a/v3/README.md +++ b/v3/README.md @@ -5,7 +5,7 @@ The `wasip2` implementation of the Spinframework Go SDK. Whenever WIT files are changed/added to the `v3/wit` directory, the bindings in `v3/wit_component` need to be regenerated. ### Prerequisites -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version ### Run ```sh diff --git a/v3/examples/http/README.md b/v3/examples/http/README.md index ede89d35..72ecc137 100644 --- a/v3/examples/http/README.md +++ b/v3/examples/http/README.md @@ -1,7 +1,7 @@ # Requirements - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage Build and run the Spin app: diff --git a/v3/examples/kv/README.md b/v3/examples/kv/README.md index 5f10f34d..40751739 100644 --- a/v3/examples/kv/README.md +++ b/v3/examples/kv/README.md @@ -1,7 +1,7 @@ # Requirements - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage Build and run the Spin app: diff --git a/v3/examples/mqtt-outbound/README.md b/v3/examples/mqtt-outbound/README.md index 53b480a9..1c8b2054 100644 --- a/v3/examples/mqtt-outbound/README.md +++ b/v3/examples/mqtt-outbound/README.md @@ -2,7 +2,7 @@ - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version - [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage In one terminal window, run: diff --git a/v3/examples/mysql-outbound/README.md b/v3/examples/mysql-outbound/README.md index 6a2fbf77..dc11e9bf 100644 --- a/v3/examples/mysql-outbound/README.md +++ b/v3/examples/mysql-outbound/README.md @@ -2,7 +2,7 @@ - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version - [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage In a terminal window, use the below command to run MySQL: diff --git a/v3/examples/redis-outbound/README.md b/v3/examples/redis-outbound/README.md index fccfb075..17dd7746 100644 --- a/v3/examples/redis-outbound/README.md +++ b/v3/examples/redis-outbound/README.md @@ -2,7 +2,7 @@ - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version - [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage In one terminal window, you'll run a Redis container: diff --git a/v3/examples/variables/README.md b/v3/examples/variables/README.md index 83533238..ca75f048 100644 --- a/v3/examples/variables/README.md +++ b/v3/examples/variables/README.md @@ -1,7 +1,7 @@ # Requirements - [**go**](https://go.dev/dl/) - v1.25+ - [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/asteurer/componentize-go) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version # Usage Build and run the Spin app: From d172d4b0a6e5c8903a7cd87576d80de830fcf78b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 24 Mar 2026 16:29:52 -0600 Subject: [PATCH 13/22] revert mysql.go changes which caused test regression Signed-off-by: Joel Dice --- mysql/mysql.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mysql/mysql.go b/mysql/mysql.go index 3979d53c..40b668d8 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -115,8 +115,9 @@ type rows struct { columns []string columnType []uint8 pos int - numRows int + len int rows [][]any + closed bool } var _ driver.Rows = (*rows)(nil) @@ -132,7 +133,8 @@ func (r *rows) Columns() []string { func (r *rows) Close() error { r.rows = nil r.pos = 0 - r.numRows = 0 + r.len = 0 + r.closed = true return nil } @@ -151,7 +153,7 @@ func (r *rows) Next(dest []driver.Value) error { // HasNextResultSet is called at the end of the current result set and // reports whether there is another result set after the current one. func (r *rows) HasNextResultSet() bool { - return r.pos < r.numRows + return r.pos < r.len } // NextResultSet advances the driver to the next result set even From 593ea4526df407894486a660e80867dd59cd1738 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 12:25:52 -0600 Subject: [PATCH 14/22] move v3 into root, fix broken stuff, etc. - move v3/* into the root of the repo - update the v2 packages (e.g. `sqlite`, `pg-outbound`, etc.) to v3 - remove obsolete C-based binding generation - fix broken tests and examples Signed-off-by: Joel Dice --- .github/workflows/build.yml | 27 +- .github/workflows/pr.yaml | 38 - CONTRIBUTING.md | 14 + Makefile | 115 +- README.md | 26 + examples/http-outbound/README.md | 34 +- examples/http-outbound/hello/go.mod | 14 +- examples/http-outbound/hello/go.sum | 2 + examples/http-outbound/hello/main.go | 2 +- .../http-outbound/http-to-same-app/go.mod | 14 +- .../http-outbound/http-to-same-app/go.sum | 2 + .../http-outbound/http-to-same-app/main.go | 2 +- examples/http-outbound/spin.toml | 7 +- examples/http-router/README.md | 5 +- examples/http-router/go.mod | 14 +- examples/http-router/go.sum | 4 + examples/http-router/main.go | 2 +- examples/http-router/spin.toml | 4 +- examples/http/README.md | 44 +- examples/http/go.mod | 14 +- examples/http/go.sum | 4 + examples/http/main.go | 22 +- examples/http/spin.toml | 6 +- examples/key-value/README.md | 48 +- examples/key-value/go.mod | 14 +- examples/key-value/go.sum | 4 + examples/key-value/main.go | 69 +- examples/key-value/spin.toml | 17 +- examples/llm/go.mod | 14 +- examples/llm/go.sum | 4 + examples/llm/main.go | 4 +- examples/llm/spin.toml | 2 +- .../llm => examples/mqtt-outbound}/.gitignore | 0 .../mqtt-outbound/README.md | 0 .../mqtt-outbound/compose.yaml | 0 examples/mqtt-outbound/go.mod | 11 + .../http => examples/mqtt-outbound}/go.sum | 2 + .../mqtt-outbound/main.go | 0 .../mqtt-outbound/spin.toml | 2 +- .../mysql-outbound/README.md | 0 .../mysql-outbound/compose.yaml | 0 examples/mysql-outbound/db/pets.sql | 4 - examples/mysql-outbound/go.mod | 14 +- examples/mysql-outbound/go.sum | 4 + .../mysql-outbound/init.sql | 0 examples/mysql-outbound/main.go | 12 +- examples/mysql-outbound/spin.toml | 10 +- examples/pg-outbound/go.mod | 14 +- examples/pg-outbound/go.sum | 4 + examples/pg-outbound/main.go | 4 +- examples/pg-outbound/spin.toml | 2 +- examples/redis-outbound/README.md | 29 +- examples/redis-outbound/go.mod | 14 +- examples/redis-outbound/go.sum | 4 + examples/redis-outbound/main.go | 14 +- examples/redis-outbound/spin.toml | 21 +- examples/redis/README.md | 4 +- examples/redis/go.mod | 14 +- examples/redis/go.sum | 6 + examples/redis/main.go | 6 +- examples/redis/spin.toml | 3 +- examples/sqlite/go.mod | 14 +- examples/sqlite/go.sum | 4 + examples/sqlite/main.go | 4 +- examples/sqlite/spin.toml | 2 +- examples/variables/README.md | 25 +- examples/variables/go.mod | 14 +- examples/variables/go.sum | 4 + examples/variables/main.go | 4 +- examples/variables/spin.toml | 5 +- go.mod | 10 +- go.sum | 2 + {v3/http => http}/client.go | 2 +- .../convertor_incoming_request.go | 0 .../convertor_outgoing_request.go | 2 +- .../convertor_outgoing_response.go | 2 +- http/http.go | 71 +- http/internals.go | 140 -- http/outbound_internals.go | 196 --- http/response.go | 39 - http/spin-http.c | 141 -- http/spin-http.h | 85 -- {v3/http => http}/streams.go | 0 http/testdata/http-tinygo/Makefile | 3 - http/testdata/http-tinygo/main.go | 29 - http/testdata/http-tinygo/spin.toml | 18 - http/testdata/http/go.mod | 11 + {v3/examples/kv => http/testdata/http}/go.sum | 2 + {v3/http => http}/testdata/http/main.go | 0 {v3/examples => http/testdata}/http/spin.toml | 3 +- http/testdata/spin-roundtrip/Makefile | 3 - http/testdata/spin-roundtrip/main.go | 32 - http/testdata/spin-roundtrip/spin.toml | 18 - http/wasi-outbound-http.c | 166 --- http/wasi-outbound-http.h | 85 -- inbound_redis/inbound_redis.go | 25 + integration_test.go | 51 +- internal/db/driver.go | 4 +- .../wit_bindings.go | 0 .../wit_bindings.go | 79 +- .../fermyon_spin_2_0_0_llm/wit_bindings.go | 32 +- .../fermyon_spin_2_0_0_mqtt/wit_bindings.go | 33 +- .../fermyon_spin_2_0_0_mysql/wit_bindings.go | 47 +- .../wit_bindings.go | 47 +- .../wit_bindings.go | 2 +- .../fermyon_spin_2_0_0_redis/wit_bindings.go | 127 +- .../fermyon_spin_2_0_0_sqlite/wit_bindings.go | 35 +- .../wit_bindings.go | 16 +- .../spin_postgres_postgres/wit_bindings.go | 89 +- .../wit_bindings.go | 26 +- .../wasi_cli_0_2_0_exit/wit_bindings.go | 10 +- .../wasi_cli_0_2_0_stderr/wit_bindings.go | 2 +- .../wasi_cli_0_2_0_stdin/wit_bindings.go | 2 +- .../wasi_cli_0_2_0_stdout/wit_bindings.go | 2 +- .../wit_bindings.go | 11 +- .../wit_bindings.go | 11 +- .../wit_bindings.go | 16 +- .../wit_bindings.go | 16 +- .../wit_bindings.go | 16 +- .../wit_bindings.go | 2 +- .../wit_bindings.go | 8 +- .../wasi_config_store/wit_bindings.go | 36 +- .../wit_bindings.go | 14 +- .../wit_bindings.go | 348 ++--- .../wit_bindings.go | 2 +- .../wit_bindings.go | 152 +-- .../wasi_http_0_2_0_types/wit_bindings.go | 1147 +++++++++-------- .../wasi_io_0_2_0_error/wit_bindings.go | 13 +- .../wasi_io_0_2_0_poll/wit_bindings.go | 15 +- .../wasi_io_0_2_0_streams/wit_bindings.go | 150 +-- .../wasi_keyvalue_atomics/wit_bindings.go | 59 +- .../wasi_keyvalue_batch/wit_bindings.go | 52 +- .../wasi_keyvalue_store/wit_bindings.go | 91 +- .../wit_bindings.go | 6 +- .../wit_bindings.go | 10 +- .../wasi_random_0_2_0_random/wit_bindings.go | 6 +- .../wit_bindings.go | 2 +- .../wit_bindings.go | 43 +- .../wit_bindings.go | 33 +- .../wasi_sockets_0_2_0_tcp/wit_bindings.go | 271 ++-- .../wit_bindings.go | 16 +- .../wasi_sockets_0_2_0_udp/wit_bindings.go | 191 +-- .../wit_bindings.go | 16 +- .../wit_exports/wit_exports.go | 6 +- kv/key-value.c | 367 ------ kv/key-value.h | 92 -- kv/kv.go | 170 +-- kv/testdata/key-value/go.mod | 11 + .../llm => kv/testdata/key-value}/go.sum | 2 + .../kv => kv/testdata/key-value}/main.go | 0 {v3/kv => kv}/testdata/key-value/spin.toml | 2 +- llm/internals.go | 131 -- llm/llm.c | 213 --- llm/llm.go | 151 ++- llm/llm.h | 107 -- {v3/mqtt => mqtt}/mqtt.go | 0 mysql/internals.go | 325 ----- mysql/mysql.go | 313 +++-- mysql/outbound-mysql.c | 243 ---- mysql/outbound-mysql.h | 181 --- pg/internals.go | 325 ----- pg/outbound-pg.c | 243 ---- pg/outbound-pg.h | 174 --- pg/pg.go | 203 ++- readme.md | 21 - redis/internals.go | 241 ---- redis/internals_test.go | 40 - redis/outbound-redis.c | 320 ----- redis/outbound-redis.h | 77 -- redis/redis.go | 192 ++- redis/spin-redis.c | 105 -- redis/spin-redis.h | 54 - .../wit_bindings.go | 14 + .../fermyon_spin_config/wit_bindings.go | 146 +++ .../fermyon_spin_http/wit_bindings.go | 154 +++ .../fermyon_spin_http_types/wit_bindings.go | 79 ++ .../wit_bindings.go | 39 + .../fermyon_spin_key_value/wit_bindings.go | 458 +++++++ .../fermyon_spin_llm/wit_bindings.go | 277 ++++ .../fermyon_spin_mysql/wit_bindings.go | 513 ++++++++ .../fermyon_spin_postgres/wit_bindings.go | 513 ++++++++ .../fermyon_spin_rdbms_types/wit_bindings.go | 364 ++++++ .../fermyon_spin_redis/wit_bindings.go | 407 ++++++ .../fermyon_spin_redis_types/wit_bindings.go | 129 ++ .../fermyon_spin_sqlite/wit_bindings.go | 364 ++++++ redis_internal/wit_exports/wit_exports.go | 68 + sqlite/internals.go | 169 --- sqlite/internals_test.go | 38 - sqlite/sqlite.c | 200 --- sqlite/sqlite.go | 142 +- sqlite/sqlite.h | 98 -- v3/README.md | 24 - v3/examples/http/README.md | 15 - v3/examples/http/go.mod | 14 - v3/examples/http/main.go | 22 - v3/examples/kv/README.md | 20 - v3/examples/kv/go.mod | 14 - v3/examples/kv/spin.toml | 17 - v3/examples/llm/go.mod | 14 - v3/examples/llm/main.go | 34 - v3/examples/llm/spin.toml | 19 - v3/examples/mqtt-outbound/.gitignore | 2 - v3/examples/mqtt-outbound/go.mod | 14 - v3/examples/mysql-outbound/.gitignore | 2 - v3/examples/mysql-outbound/go.mod | 14 - v3/examples/mysql-outbound/go.sum | 4 - v3/examples/mysql-outbound/main.go | 58 - v3/examples/mysql-outbound/spin.toml | 19 - v3/examples/redis-outbound/README.md | 28 - v3/examples/redis-outbound/go.mod | 14 - v3/examples/redis-outbound/go.sum | 4 - v3/examples/redis-outbound/main.go | 155 --- v3/examples/redis-outbound/spin.toml | 20 - v3/examples/variables/README.md | 20 - v3/examples/variables/go.mod | 14 - v3/examples/variables/go.sum | 4 - v3/examples/variables/main.go | 24 - v3/go.mod | 10 - v3/go.sum | 4 - v3/http/http.go | 99 -- v3/http/testdata/http/go.mod | 14 - v3/http/testdata/http/go.sum | 4 - v3/http/testdata/http/spin.toml | 17 - v3/integration_test.go | 199 --- v3/internal/db/driver.go | 15 - v3/kv/kv.go | 100 -- v3/kv/testdata/key-value/go.mod | 14 - v3/kv/testdata/key-value/go.sum | 4 - v3/kv/testdata/key-value/main.go | 50 - v3/llm/llm.go | 137 -- v3/mysql/mysql.go | 337 ----- v3/redis/redis.go | 226 ---- v3/variables/testdata/variables/go.mod | 14 - v3/variables/testdata/variables/go.sum | 4 - v3/variables/testdata/variables/spin.toml | 23 - v3/variables/variables.go | 34 - variables/internals.go | 42 - variables/spin-config.c | 117 -- variables/spin-config.h | 45 - variables/testdata/variables/go.mod | 11 + .../testdata/variables}/go.sum | 2 + .../testdata/variables/main.go | 0 .../testdata}/variables/spin.toml | 3 +- variables/variables.go | 28 +- .../deps/cli-2023-10-18/command.wit | 0 .../deps/cli-2023-10-18/environment.wit | 0 {v3/wit => wit}/deps/cli-2023-10-18/exit.wit | 0 .../deps/cli-2023-10-18/reactor.wit | 0 {v3/wit => wit}/deps/cli-2023-10-18/run.wit | 0 {v3/wit => wit}/deps/cli-2023-10-18/stdio.wit | 0 .../deps/cli-2023-10-18/terminal.wit | 0 .../deps/cli-2023-11-10/command.wit | 0 .../deps/cli-2023-11-10/environment.wit | 0 {v3/wit => wit}/deps/cli-2023-11-10/exit.wit | 0 .../deps/cli-2023-11-10/reactor.wit | 0 {v3/wit => wit}/deps/cli-2023-11-10/run.wit | 0 {v3/wit => wit}/deps/cli-2023-11-10/stdio.wit | 0 .../deps/cli-2023-11-10/terminal.wit | 0 {v3/wit => wit}/deps/cli/command.wit | 0 {v3/wit => wit}/deps/cli/environment.wit | 0 {v3/wit => wit}/deps/cli/exit.wit | 0 {v3/wit => wit}/deps/cli/imports.wit | 0 {v3/wit => wit}/deps/cli/run.wit | 0 {v3/wit => wit}/deps/cli/stdio.wit | 0 {v3/wit => wit}/deps/cli/terminal.wit | 0 .../clocks-2023-10-18/monotonic-clock.wit | 0 .../deps/clocks-2023-10-18/timezone.wit | 0 .../deps/clocks-2023-10-18/wall-clock.wit | 0 .../deps/clocks-2023-10-18/world.wit | 0 .../clocks-2023-11-10/monotonic-clock.wit | 0 .../deps/clocks-2023-11-10/wall-clock.wit | 0 .../deps/clocks-2023-11-10/world.wit | 0 .../deps/clocks/monotonic-clock.wit | 0 {v3/wit => wit}/deps/clocks/wall-clock.wit | 0 {v3/wit => wit}/deps/clocks/world.wit | 0 .../deps/filesystem-2023-10-18/preopens.wit | 0 .../deps/filesystem-2023-10-18/types.wit | 0 .../deps/filesystem-2023-10-18/world.wit | 0 .../deps/filesystem-2023-11-10/preopens.wit | 0 .../deps/filesystem-2023-11-10/types.wit | 0 .../deps/filesystem-2023-11-10/world.wit | 0 {v3/wit => wit}/deps/filesystem/preopens.wit | 0 {v3/wit => wit}/deps/filesystem/types.wit | 0 {v3/wit => wit}/deps/filesystem/world.wit | 0 .../deps/http-2023-10-18/incoming-handler.wit | 0 .../deps/http-2023-10-18/outgoing-handler.wit | 0 .../deps/http-2023-10-18/proxy.wit | 0 .../deps/http-2023-10-18/types.wit | 0 .../deps/http-2023-11-10/handler.wit | 0 .../deps/http-2023-11-10/proxy.wit | 0 .../deps/http-2023-11-10/types.wit | 0 {v3/wit => wit}/deps/http/handler.wit | 0 {v3/wit => wit}/deps/http/proxy.wit | 0 {v3/wit => wit}/deps/http/types.wit | 0 {v3/wit => wit}/deps/io-2023-10-18/poll.wit | 0 .../deps/io-2023-10-18/streams.wit | 0 {v3/wit => wit}/deps/io-2023-10-18/world.wit | 0 {v3/wit => wit}/deps/io-2023-11-10/error.wit | 0 {v3/wit => wit}/deps/io-2023-11-10/poll.wit | 0 .../deps/io-2023-11-10/streams.wit | 0 {v3/wit => wit}/deps/io-2023-11-10/world.wit | 0 {v3/wit => wit}/deps/io/error.wit | 0 {v3/wit => wit}/deps/io/poll.wit | 0 {v3/wit => wit}/deps/io/streams.wit | 0 {v3/wit => wit}/deps/io/world.wit | 0 .../deps/keyvalue-2024-10-17/atomic.wit | 0 .../deps/keyvalue-2024-10-17/batch.wit | 0 .../deps/keyvalue-2024-10-17/store.wit | 0 .../deps/keyvalue-2024-10-17/watch.wit | 0 .../deps/keyvalue-2024-10-17/world.wit | 0 .../deps/random-2023-10-18/insecure-seed.wit | 0 .../deps/random-2023-10-18/insecure.wit | 0 .../deps/random-2023-10-18/random.wit | 0 .../deps/random-2023-10-18/world.wit | 0 .../deps/random-2023-11-10/insecure-seed.wit | 0 .../deps/random-2023-11-10/insecure.wit | 0 .../deps/random-2023-11-10/random.wit | 0 .../deps/random-2023-11-10/world.wit | 0 {v3/wit => wit}/deps/random/insecure-seed.wit | 0 {v3/wit => wit}/deps/random/insecure.wit | 0 {v3/wit => wit}/deps/random/random.wit | 0 {v3/wit => wit}/deps/random/world.wit | 0 .../sockets-2023-10-18/instance-network.wit | 0 .../sockets-2023-10-18/ip-name-lookup.wit | 0 .../deps/sockets-2023-10-18/network.wit | 0 .../sockets-2023-10-18/tcp-create-socket.wit | 0 .../deps/sockets-2023-10-18/tcp.wit | 0 .../sockets-2023-10-18/udp-create-socket.wit | 0 .../deps/sockets-2023-10-18/udp.wit | 0 .../deps/sockets-2023-10-18/world.wit | 0 .../sockets-2023-11-10/instance-network.wit | 0 .../sockets-2023-11-10/ip-name-lookup.wit | 0 .../deps/sockets-2023-11-10/network.wit | 0 .../sockets-2023-11-10/tcp-create-socket.wit | 0 .../deps/sockets-2023-11-10/tcp.wit | 0 .../sockets-2023-11-10/udp-create-socket.wit | 0 .../deps/sockets-2023-11-10/udp.wit | 0 .../deps/sockets-2023-11-10/world.wit | 0 .../deps/sockets/instance-network.wit | 0 .../deps/sockets/ip-name-lookup.wit | 0 {v3/wit => wit}/deps/sockets/network.wit | 0 .../deps/sockets/tcp-create-socket.wit | 0 {v3/wit => wit}/deps/sockets/tcp.wit | 0 .../deps/sockets/udp-create-socket.wit | 0 {v3/wit => wit}/deps/sockets/udp.wit | 0 {v3/wit => wit}/deps/sockets/world.wit | 0 .../deps/spin-postgres@3.0.0/postgres.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/key-value.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/llm.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/mqtt.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/mysql.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/postgres.wit | 0 .../deps/spin@2.0.0/rdbms-types.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/redis.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/sqlite.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/variables.wit | 0 {v3/wit => wit}/deps/spin@2.0.0/world.wit | 0 .../deps/spin@unversioned/config.wit | 0 .../deps/spin@unversioned/http-types.wit | 0 .../deps/spin@unversioned/http.wit | 0 .../deps/spin@unversioned/inbound-http.wit | 0 .../deps/spin@unversioned/inbound-redis.wit | 0 .../deps/spin@unversioned/key-value.wit | 0 {v3/wit => wit}/deps/spin@unversioned/llm.wit | 0 .../deps/spin@unversioned/mysql.wit | 0 .../deps/spin@unversioned/postgres.wit | 0 .../deps/spin@unversioned/rdbms-types.wit | 0 .../deps/spin@unversioned/redis-types.wit | 0 .../deps/spin@unversioned/redis.wit | 0 .../deps/spin@unversioned/sqlite.wit | 0 .../deps/spin@unversioned/world.wit | 0 .../wasi-runtime-config-2024-09-27/store.wit | 0 .../wasi-runtime-config-2024-09-27/world.wit | 0 wit/http-types.wit | 59 - wit/key-value.wit | 78 -- wit/mysql-types.wit | 10 - wit/outbound-mysql.wit | 8 - wit/outbound-pg.wit | 8 - wit/outbound-redis.wit | 29 - wit/pg-types.wit | 9 - wit/rdbms-types.wit | 63 - wit/redis-types.wit | 22 - wit/spin-config.wit | 10 - wit/spin-http.wit | 4 - wit/spin-redis.wit | 4 - wit/sqlite.wit | 50 - wit/wasi-outbound-http.wit | 4 - {v3/wit => wit}/wit.go | 0 {v3/wit => wit}/world.wit | 0 389 files changed, 6632 insertions(+), 9657 deletions(-) delete mode 100644 .github/workflows/pr.yaml create mode 100644 CONTRIBUTING.md create mode 100644 README.md rename {v3/examples/llm => examples/mqtt-outbound}/.gitignore (100%) rename {v3/examples => examples}/mqtt-outbound/README.md (100%) rename {v3/examples => examples}/mqtt-outbound/compose.yaml (100%) create mode 100644 examples/mqtt-outbound/go.mod rename {v3/examples/http => examples/mqtt-outbound}/go.sum (71%) rename {v3/examples => examples}/mqtt-outbound/main.go (100%) rename {v3/examples => examples}/mqtt-outbound/spin.toml (97%) rename {v3/examples => examples}/mysql-outbound/README.md (100%) rename {v3/examples => examples}/mysql-outbound/compose.yaml (100%) delete mode 100644 examples/mysql-outbound/db/pets.sql rename {v3/examples => examples}/mysql-outbound/init.sql (100%) rename {v3/http => http}/client.go (97%) rename {v3/http => http}/convertor_incoming_request.go (100%) rename {v3/http => http}/convertor_outgoing_request.go (96%) rename {v3/http => http}/convertor_outgoing_response.go (98%) delete mode 100644 http/internals.go delete mode 100644 http/outbound_internals.go delete mode 100644 http/response.go delete mode 100644 http/spin-http.c delete mode 100644 http/spin-http.h rename {v3/http => http}/streams.go (100%) delete mode 100644 http/testdata/http-tinygo/Makefile delete mode 100644 http/testdata/http-tinygo/main.go delete mode 100644 http/testdata/http-tinygo/spin.toml create mode 100644 http/testdata/http/go.mod rename {v3/examples/kv => http/testdata/http}/go.sum (71%) rename {v3/http => http}/testdata/http/main.go (100%) rename {v3/examples => http/testdata}/http/spin.toml (95%) delete mode 100644 http/testdata/spin-roundtrip/Makefile delete mode 100644 http/testdata/spin-roundtrip/main.go delete mode 100644 http/testdata/spin-roundtrip/spin.toml delete mode 100644 http/wasi-outbound-http.c delete mode 100644 http/wasi-outbound-http.h create mode 100644 inbound_redis/inbound_redis.go rename {v3/internal => internal}/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go (100%) rename {v3/internal => internal}/fermyon_spin_2_0_0_key_value/wit_bindings.go (80%) rename {v3/internal => internal}/fermyon_spin_2_0_0_llm/wit_bindings.go (85%) rename {v3/internal => internal}/fermyon_spin_2_0_0_mqtt/wit_bindings.go (86%) rename {v3/internal => internal}/fermyon_spin_2_0_0_mysql/wit_bindings.go (90%) rename {v3/internal => internal}/fermyon_spin_2_0_0_postgres/wit_bindings.go (91%) rename {v3/internal => internal}/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go (99%) rename {v3/internal => internal}/fermyon_spin_2_0_0_redis/wit_bindings.go (83%) rename {v3/internal => internal}/fermyon_spin_2_0_0_sqlite/wit_bindings.go (90%) rename {v3/internal => internal}/fermyon_spin_2_0_0_variables/wit_bindings.go (90%) rename {v3/internal => internal}/spin_postgres_postgres/wit_bindings.go (87%) rename {v3/internal => internal}/wasi_cli_0_2_0_environment/wit_bindings.go (80%) rename {v3/internal => internal}/wasi_cli_0_2_0_exit/wit_bindings.go (84%) rename {v3/internal => internal}/wasi_cli_0_2_0_stderr/wit_bindings.go (96%) rename {v3/internal => internal}/wasi_cli_0_2_0_stdin/wit_bindings.go (96%) rename {v3/internal => internal}/wasi_cli_0_2_0_stdout/wit_bindings.go (96%) rename {v3/internal => internal}/wasi_cli_0_2_0_terminal_input/wit_bindings.go (88%) rename {v3/internal => internal}/wasi_cli_0_2_0_terminal_output/wit_bindings.go (88%) rename {v3/internal => internal}/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go (69%) rename {v3/internal => internal}/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go (70%) rename {v3/internal => internal}/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go (69%) rename {v3/internal => internal}/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go (97%) rename {v3/internal => internal}/wasi_clocks_0_2_0_wall_clock/wit_bindings.go (89%) rename {v3/internal => internal}/wasi_config_store/wit_bindings.go (81%) rename {v3/internal => internal}/wasi_filesystem_0_2_0_preopens/wit_bindings.go (72%) rename {v3/internal => internal}/wasi_filesystem_0_2_0_types/wit_bindings.go (68%) rename {v3/internal => internal}/wasi_http_0_2_0_incoming_handler/wit_bindings.go (95%) rename {v3/internal => internal}/wasi_http_0_2_0_outgoing_handler/wit_bindings.go (70%) rename {v3/internal => internal}/wasi_http_0_2_0_types/wit_bindings.go (76%) rename {v3/internal => internal}/wasi_io_0_2_0_error/wit_bindings.go (90%) rename {v3/internal => internal}/wasi_io_0_2_0_poll/wit_bindings.go (88%) rename {v3/internal => internal}/wasi_io_0_2_0_streams/wit_bindings.go (78%) rename {v3/internal => internal}/wasi_keyvalue_atomics/wit_bindings.go (79%) rename {v3/internal => internal}/wasi_keyvalue_batch/wit_bindings.go (76%) rename {v3/internal => internal}/wasi_keyvalue_store/wit_bindings.go (81%) rename {v3/internal => internal}/wasi_random_0_2_0_insecure/wit_bindings.go (91%) rename {v3/internal => internal}/wasi_random_0_2_0_insecure_seed/wit_bindings.go (77%) rename {v3/internal => internal}/wasi_random_0_2_0_random/wit_bindings.go (90%) rename {v3/internal => internal}/wasi_sockets_0_2_0_instance_network/wit_bindings.go (96%) rename {v3/internal => internal}/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go (59%) rename {v3/internal => internal}/wasi_sockets_0_2_0_network/wit_bindings.go (84%) rename {v3/internal => internal}/wasi_sockets_0_2_0_tcp/wit_bindings.go (55%) rename {v3/internal => internal}/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go (69%) rename {v3/internal => internal}/wasi_sockets_0_2_0_udp/wit_bindings.go (65%) rename {v3/internal => internal}/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go (69%) rename {v3/internal => internal}/wit_exports/wit_exports.go (89%) delete mode 100644 kv/key-value.c delete mode 100644 kv/key-value.h create mode 100644 kv/testdata/key-value/go.mod rename {v3/examples/llm => kv/testdata/key-value}/go.sum (71%) rename {v3/examples/kv => kv/testdata/key-value}/main.go (100%) rename {v3/kv => kv}/testdata/key-value/spin.toml (94%) delete mode 100644 llm/internals.go delete mode 100644 llm/llm.c delete mode 100644 llm/llm.h rename {v3/mqtt => mqtt}/mqtt.go (100%) delete mode 100644 mysql/internals.go delete mode 100644 mysql/outbound-mysql.c delete mode 100644 mysql/outbound-mysql.h delete mode 100644 pg/internals.go delete mode 100644 pg/outbound-pg.c delete mode 100644 pg/outbound-pg.h delete mode 100644 readme.md delete mode 100644 redis/internals.go delete mode 100644 redis/internals_test.go delete mode 100644 redis/outbound-redis.c delete mode 100644 redis/outbound-redis.h delete mode 100644 redis/spin-redis.c delete mode 100644 redis/spin-redis.h create mode 100644 redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_config/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_http/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_http_types/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_inbound_redis/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_key_value/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_llm/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_mysql/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_postgres/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_rdbms_types/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_redis/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_redis_types/wit_bindings.go create mode 100644 redis_internal/fermyon_spin_sqlite/wit_bindings.go create mode 100644 redis_internal/wit_exports/wit_exports.go delete mode 100644 sqlite/internals.go delete mode 100644 sqlite/internals_test.go delete mode 100644 sqlite/sqlite.c delete mode 100644 sqlite/sqlite.h delete mode 100644 v3/README.md delete mode 100644 v3/examples/http/README.md delete mode 100644 v3/examples/http/go.mod delete mode 100644 v3/examples/http/main.go delete mode 100644 v3/examples/kv/README.md delete mode 100644 v3/examples/kv/go.mod delete mode 100644 v3/examples/kv/spin.toml delete mode 100644 v3/examples/llm/go.mod delete mode 100644 v3/examples/llm/main.go delete mode 100644 v3/examples/llm/spin.toml delete mode 100644 v3/examples/mqtt-outbound/.gitignore delete mode 100644 v3/examples/mqtt-outbound/go.mod delete mode 100644 v3/examples/mysql-outbound/.gitignore delete mode 100644 v3/examples/mysql-outbound/go.mod delete mode 100644 v3/examples/mysql-outbound/go.sum delete mode 100644 v3/examples/mysql-outbound/main.go delete mode 100644 v3/examples/mysql-outbound/spin.toml delete mode 100644 v3/examples/redis-outbound/README.md delete mode 100644 v3/examples/redis-outbound/go.mod delete mode 100644 v3/examples/redis-outbound/go.sum delete mode 100644 v3/examples/redis-outbound/main.go delete mode 100644 v3/examples/redis-outbound/spin.toml delete mode 100644 v3/examples/variables/README.md delete mode 100644 v3/examples/variables/go.mod delete mode 100644 v3/examples/variables/go.sum delete mode 100644 v3/examples/variables/main.go delete mode 100644 v3/go.mod delete mode 100644 v3/go.sum delete mode 100644 v3/http/http.go delete mode 100644 v3/http/testdata/http/go.mod delete mode 100644 v3/http/testdata/http/go.sum delete mode 100644 v3/http/testdata/http/spin.toml delete mode 100644 v3/integration_test.go delete mode 100644 v3/internal/db/driver.go delete mode 100644 v3/kv/kv.go delete mode 100644 v3/kv/testdata/key-value/go.mod delete mode 100644 v3/kv/testdata/key-value/go.sum delete mode 100644 v3/kv/testdata/key-value/main.go delete mode 100644 v3/llm/llm.go delete mode 100644 v3/mysql/mysql.go delete mode 100644 v3/redis/redis.go delete mode 100644 v3/variables/testdata/variables/go.mod delete mode 100644 v3/variables/testdata/variables/go.sum delete mode 100644 v3/variables/testdata/variables/spin.toml delete mode 100644 v3/variables/variables.go delete mode 100644 variables/internals.go delete mode 100644 variables/spin-config.c delete mode 100644 variables/spin-config.h create mode 100644 variables/testdata/variables/go.mod rename {v3/examples/mqtt-outbound => variables/testdata/variables}/go.sum (71%) rename {v3/variables => variables}/testdata/variables/main.go (100%) rename {v3/examples => variables/testdata}/variables/spin.toml (96%) rename {v3/wit => wit}/deps/cli-2023-10-18/command.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/environment.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/exit.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/reactor.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/run.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/stdio.wit (100%) rename {v3/wit => wit}/deps/cli-2023-10-18/terminal.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/command.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/environment.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/exit.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/reactor.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/run.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/stdio.wit (100%) rename {v3/wit => wit}/deps/cli-2023-11-10/terminal.wit (100%) rename {v3/wit => wit}/deps/cli/command.wit (100%) rename {v3/wit => wit}/deps/cli/environment.wit (100%) rename {v3/wit => wit}/deps/cli/exit.wit (100%) rename {v3/wit => wit}/deps/cli/imports.wit (100%) rename {v3/wit => wit}/deps/cli/run.wit (100%) rename {v3/wit => wit}/deps/cli/stdio.wit (100%) rename {v3/wit => wit}/deps/cli/terminal.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-10-18/monotonic-clock.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-10-18/timezone.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-10-18/wall-clock.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-10-18/world.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-11-10/monotonic-clock.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-11-10/wall-clock.wit (100%) rename {v3/wit => wit}/deps/clocks-2023-11-10/world.wit (100%) rename {v3/wit => wit}/deps/clocks/monotonic-clock.wit (100%) rename {v3/wit => wit}/deps/clocks/wall-clock.wit (100%) rename {v3/wit => wit}/deps/clocks/world.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-10-18/preopens.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-10-18/types.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-10-18/world.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-11-10/preopens.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-11-10/types.wit (100%) rename {v3/wit => wit}/deps/filesystem-2023-11-10/world.wit (100%) rename {v3/wit => wit}/deps/filesystem/preopens.wit (100%) rename {v3/wit => wit}/deps/filesystem/types.wit (100%) rename {v3/wit => wit}/deps/filesystem/world.wit (100%) rename {v3/wit => wit}/deps/http-2023-10-18/incoming-handler.wit (100%) rename {v3/wit => wit}/deps/http-2023-10-18/outgoing-handler.wit (100%) rename {v3/wit => wit}/deps/http-2023-10-18/proxy.wit (100%) rename {v3/wit => wit}/deps/http-2023-10-18/types.wit (100%) rename {v3/wit => wit}/deps/http-2023-11-10/handler.wit (100%) rename {v3/wit => wit}/deps/http-2023-11-10/proxy.wit (100%) rename {v3/wit => wit}/deps/http-2023-11-10/types.wit (100%) rename {v3/wit => wit}/deps/http/handler.wit (100%) rename {v3/wit => wit}/deps/http/proxy.wit (100%) rename {v3/wit => wit}/deps/http/types.wit (100%) rename {v3/wit => wit}/deps/io-2023-10-18/poll.wit (100%) rename {v3/wit => wit}/deps/io-2023-10-18/streams.wit (100%) rename {v3/wit => wit}/deps/io-2023-10-18/world.wit (100%) rename {v3/wit => wit}/deps/io-2023-11-10/error.wit (100%) rename {v3/wit => wit}/deps/io-2023-11-10/poll.wit (100%) rename {v3/wit => wit}/deps/io-2023-11-10/streams.wit (100%) rename {v3/wit => wit}/deps/io-2023-11-10/world.wit (100%) rename {v3/wit => wit}/deps/io/error.wit (100%) rename {v3/wit => wit}/deps/io/poll.wit (100%) rename {v3/wit => wit}/deps/io/streams.wit (100%) rename {v3/wit => wit}/deps/io/world.wit (100%) rename {v3/wit => wit}/deps/keyvalue-2024-10-17/atomic.wit (100%) rename {v3/wit => wit}/deps/keyvalue-2024-10-17/batch.wit (100%) rename {v3/wit => wit}/deps/keyvalue-2024-10-17/store.wit (100%) rename {v3/wit => wit}/deps/keyvalue-2024-10-17/watch.wit (100%) rename {v3/wit => wit}/deps/keyvalue-2024-10-17/world.wit (100%) rename {v3/wit => wit}/deps/random-2023-10-18/insecure-seed.wit (100%) rename {v3/wit => wit}/deps/random-2023-10-18/insecure.wit (100%) rename {v3/wit => wit}/deps/random-2023-10-18/random.wit (100%) rename {v3/wit => wit}/deps/random-2023-10-18/world.wit (100%) rename {v3/wit => wit}/deps/random-2023-11-10/insecure-seed.wit (100%) rename {v3/wit => wit}/deps/random-2023-11-10/insecure.wit (100%) rename {v3/wit => wit}/deps/random-2023-11-10/random.wit (100%) rename {v3/wit => wit}/deps/random-2023-11-10/world.wit (100%) rename {v3/wit => wit}/deps/random/insecure-seed.wit (100%) rename {v3/wit => wit}/deps/random/insecure.wit (100%) rename {v3/wit => wit}/deps/random/random.wit (100%) rename {v3/wit => wit}/deps/random/world.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/instance-network.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/ip-name-lookup.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/network.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/tcp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/tcp.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/udp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/udp.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-10-18/world.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/instance-network.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/ip-name-lookup.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/network.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/tcp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/tcp.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/udp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/udp.wit (100%) rename {v3/wit => wit}/deps/sockets-2023-11-10/world.wit (100%) rename {v3/wit => wit}/deps/sockets/instance-network.wit (100%) rename {v3/wit => wit}/deps/sockets/ip-name-lookup.wit (100%) rename {v3/wit => wit}/deps/sockets/network.wit (100%) rename {v3/wit => wit}/deps/sockets/tcp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets/tcp.wit (100%) rename {v3/wit => wit}/deps/sockets/udp-create-socket.wit (100%) rename {v3/wit => wit}/deps/sockets/udp.wit (100%) rename {v3/wit => wit}/deps/sockets/world.wit (100%) rename {v3/wit => wit}/deps/spin-postgres@3.0.0/postgres.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/key-value.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/llm.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/mqtt.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/mysql.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/postgres.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/rdbms-types.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/redis.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/sqlite.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/variables.wit (100%) rename {v3/wit => wit}/deps/spin@2.0.0/world.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/config.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/http-types.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/http.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/inbound-http.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/inbound-redis.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/key-value.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/llm.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/mysql.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/postgres.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/rdbms-types.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/redis-types.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/redis.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/sqlite.wit (100%) rename {v3/wit => wit}/deps/spin@unversioned/world.wit (100%) rename {v3/wit => wit}/deps/wasi-runtime-config-2024-09-27/store.wit (100%) rename {v3/wit => wit}/deps/wasi-runtime-config-2024-09-27/world.wit (100%) delete mode 100644 wit/http-types.wit delete mode 100644 wit/key-value.wit delete mode 100644 wit/mysql-types.wit delete mode 100644 wit/outbound-mysql.wit delete mode 100644 wit/outbound-pg.wit delete mode 100644 wit/outbound-redis.wit delete mode 100644 wit/pg-types.wit delete mode 100644 wit/rdbms-types.wit delete mode 100644 wit/redis-types.wit delete mode 100644 wit/spin-config.wit delete mode 100644 wit/spin-http.wit delete mode 100644 wit/spin-redis.wit delete mode 100644 wit/sqlite.wit delete mode 100644 wit/wasi-outbound-http.wit rename {v3/wit => wit}/wit.go (100%) rename {v3/wit => wit}/world.wit (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42befb43..06fa7061 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,25 +16,22 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.23' - - - name: Setup TinyGo - uses: acifani/setup-tinygo@v2 - with: - tinygo-version: '0.35.0' + go-version: '1.25' + + - name: Setup componentize-go + run: | + curl -LO https://github.com/bytecodealliance/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz + echo "27fc32998f023a88a6a1f44524631a705163f23ce2a02fc14987726897360027 componentize-go-linux-amd64.tar.gz" | sha256sum --check + tar -xf componentize-go-linux-amd64.tar.gz + chmod +x componentize-go + mkdir -p $HOME/.local/bin + mv componentize-go $HOME/.local/bin/componentize-go + echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Setup Spin uses: fermyon/actions/spin/setup@v1 with: - version: "v3.1.2" - - - name: Setup Wasmtime - uses: bytecodealliance/actions/wasmtime/setup@v1 - with: - version: "28.0.0" - - - name: Run unit tests - run: make test + version: "v3.6.2" - name: Run integration tests run: make test-integration diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml deleted file mode 100644 index be1448d0..00000000 --- a/.github/workflows/pr.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Run Integration tests -on: - pull_request: - branches: - - wasip2 - - workflow_dispatch: {} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v6 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: '1.25' - - - name: Setup componentize-go - run: | - curl -LO https://github.com/bytecodealliance/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz - echo "27fc32998f023a88a6a1f44524631a705163f23ce2a02fc14987726897360027 componentize-go-linux-amd64.tar.gz" | sha256sum --check - tar -xf componentize-go-linux-amd64.tar.gz - chmod +x componentize-go - mkdir -p $HOME/.local/bin - mv componentize-go $HOME/.local/bin/componentize-go - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Setup Spin - uses: fermyon/actions/spin/setup@v1 - with: - version: "v3.5.1" - - - name: Run wasip2 integration tests - run: make test-integration-wasip2 - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..b73c13d3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,14 @@ +## Generating the WIT bindings + +Whenever WIT files are changed, added to, or removed from the `wit` directory, the bindings in `internal` should be regenerated. + +### Prerequisites + +- Make +- BASH or compatible shell +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version + +### Run +```sh +make regenerate-bindings +``` diff --git a/Makefile b/Makefile index ae042003..8916f6aa 100644 --- a/Makefile +++ b/Makefile @@ -1,98 +1,25 @@ -VERSION = 2.3.0-pre0 - -# ---------------------------------------------------------------------- -# Test -# ---------------------------------------------------------------------- -.PHONY: test -test: - tinygo test -target=wasip1 -gc=leaking -buildmode=c-shared -v ./http - tinygo test -target=wasip1 -gc=leaking -buildmode=c-shared -v ./redis - .PHONY: test-integration test-integration: go test -v -count=1 . -.PHONY: test-integration-wasip2 -test-integration-wasip2: - cd v3 && go test -v -count=1 . - -# ---------------------------------------------------------------------- -# Generate C bindings -# ---------------------------------------------------------------------- -GENERATED_SPIN_VARIABLES = variables/spin-config.c variables/spin-config.h -GENERATED_OUTBOUND_HTTP = http/wasi-outbound-http.c http/wasi-outbound-http.h -GENERATED_SPIN_HTTP = http/spin-http.c http/spin-http.h -GENERATED_OUTBOUND_REDIS = redis/outbound-redis.c redis/outbound-redis.h -GENERATED_SPIN_REDIS = redis/spin-redis.c redis/spin-redis.h -GENERATED_KEY_VALUE = kv/key-value.c kv/key-value.h -GENERATED_SQLITE = sqlite/sqlite.c sqlite/sqlite.h -GENERATED_LLM = llm/llm.c llm/llm.h -GENERATED_OUTBOUND_MYSQL = mysql/outbound-mysql.c mysql/outbound-mysql.h -GENERATED_OUTBOUND_PG = pg/outbound-pg.c pg/outbound-pg.h - -SDK_VERSION_SOURCE_FILE = sdk_version/sdk-version-go-template.c - -# NOTE: Please update this list if you add a new directory to the SDK: -SDK_VERSION_DEST_FILES = variables/sdk-version-go.c http/sdk-version-go.c \ - kv/sdk-version-go.c redis/sdk-version-go.c \ - sqlite/sdk-version-go.c llm/sdk-version-go.c - -# NOTE: To generate the C bindings you need to install a forked version of wit-bindgen. -# -# cargo install wit-bindgen-cli --git https://github.com/fermyon/wit-bindgen-backport --rev "b89d5079ba5b07b319631a1b191d2139f126c976" -# -.PHONY: generate -generate: $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP) -generate: $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS) -generate: $(GENERATED_SPIN_VARIABLES) $(GENERATED_KEY_VALUE) -generate: $(GENERATED_SQLITE) $(GENERATED_LLM) -generate: $(GENERATED_OUTBOUND_MYSQL) $(GENERATED_OUTBOUND_PG) -generate: $(SDK_VERSION_DEST_FILES) - -$(SDK_VERSION_DEST_FILES): $(SDK_VERSION_SOURCE_FILE) - export commit="$$(git rev-parse HEAD)"; \ - sed -e "s/{{VERSION}}/${VERSION}/" -e "s/{{COMMIT}}/$${commit}/" < $< > $@ - -$(GENERATED_SPIN_VARIABLES): - wit-bindgen c --import wit/spin-config.wit --out-dir ./variables - -$(GENERATED_OUTBOUND_HTTP): - wit-bindgen c --import wit/wasi-outbound-http.wit --out-dir ./http - -$(GENERATED_SPIN_HTTP): - wit-bindgen c --export wit/spin-http.wit --out-dir ./http - -$(GENERATED_OUTBOUND_REDIS): - wit-bindgen c --import wit/outbound-redis.wit --out-dir ./redis - -$(GENERATED_SPIN_REDIS): - wit-bindgen c --export wit/spin-redis.wit --out-dir ./redis - -$(GENERATED_KEY_VALUE): - wit-bindgen c --import wit/key-value.wit --out-dir ./kv - -$(GENERATED_SQLITE): - wit-bindgen c --import wit/sqlite.wit --out-dir ./sqlite - -$(GENERATED_LLM): - wit-bindgen c --import wit/llm.wit --out-dir ./llm - -$(GENERATED_OUTBOUND_MYSQL): - wit-bindgen c --import wit/outbound-mysql.wit --out-dir ./mysql - -$(GENERATED_OUTBOUND_PG): - wit-bindgen c --import wit/outbound-pg.wit --out-dir ./pg - -# ---------------------------------------------------------------------- -# Cleanup -# ---------------------------------------------------------------------- -.PHONY: clean -clean: - rm -f $(GENERATED_SPIN_CONFIG) - rm -f $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP) - rm -f $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS) - rm -f $(GENERATED_KEY_VALUE) $(GENERATED_SQLITE) - rm -f $(GENERATED_LLM) - rm -f $(GENERATED_OUTBOUND_MYSQL) - rm -f $(GENERATED_SDK_VERSION) - rm -f $(SDK_VERSION_DEST_FILES) +.PHONY: build-examples +build-examples: + for x in examples/*; do echo $$x && (cd $$x && spin build) || exit 1; done + +.PHONY: regenerate-bindings +regenerate-bindings: + find $$(pwd)/internal/ \ + -mindepth 1 \ + -maxdepth 1 \ + -type d \ + ! -name 'db' \ + ! -name 'export_wasi_http_0_2_0_incoming_handler' \ + -exec rm -rf {} + + componentize-go -w http-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal + find $$(pwd)/redis_internal/ \ + -mindepth 1 \ + -maxdepth 1 \ + -type d \ + ! -name 'export_fermyon_spin_inbound_redis' \ + -exec rm -rf {} + + componentize-go -w fermyon:spin/redis-trigger -d ./wit bindings --format -o redis_internal --pkg-name github.com/spinframework/spin-go-sdk/v3/redis_internal diff --git a/README.md b/README.md new file mode 100644 index 00000000..32ec181e --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +## The Go SDK for Spin + +This is an SDK for developing [Spin](https://github.com/spinframework/spin) applications using the Go programming language. + +## Example + +```go +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello, Spin!") + }) +} + +func main() {} +``` + +See the [examples](./examples) directory for more examples. diff --git a/examples/http-outbound/README.md b/examples/http-outbound/README.md index 974491a8..df6eeda6 100644 --- a/examples/http-outbound/README.md +++ b/examples/http-outbound/README.md @@ -1,25 +1,19 @@ -# Making outbound HTTP requests from TinyGo Spin components +# Making outbound HTTP requests from Go Spin components -The TinyGo SDK for building Spin components allows us to granularly allow -components to send HTTP requests to certain hosts. This is configured in -`spin.toml`. - -> For more information and examples for using TinyGo with WebAssembly, check -> [the official TinyGo documentation](https://tinygo.org/docs/guides/webassembly/) -> and -> [the Wasm examples](https://github.com/tinygo-org/tinygo/tree/release/src/examples/wasm). +The Go SDK for building Spin components allows us to granularly allow components +to send HTTP requests to certain hosts. This is configured in `spin.toml`. Creating and sending HTTP requests from Spin components closely follows the Go -`net/http` API. See [tinygo-hello/main.go](./tinygo-hello/main.go). +`net/http` API. See [hello/main.go](./hello/main.go). -Building this as a WebAssembly module can be done using the `tinygo` compiler: +Building this as a WebAssembly module can be done using `spin build`: ```shell $ spin build -Building component outbound-http-to-same-app with `tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm .` -Working directory: "./outbound-http-to-same-app" -Building component tinygo-hello with `tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm .` -Working directory: "./tinygo-hello" +Building component http-to-same-app with `componentize-go --world http-trigger --wit-path ../../../wit build` +Working directory: "./http-to-same-app" +Building component hello with `componentize-go --world http-trigger --wit-path ../../../wit build` +Working directory: "./hello" Finished building all Spin components ``` @@ -30,11 +24,11 @@ HTTP requests to, otherwise sending the request results in an error: Cannot send HTTP request: Destination not allowed: ``` -The `tinygo-hello` component has the following allowed hosts set: +The `hello` component has the following allowed hosts set: ```toml -[component.tinygo-hello] -source = "tinygo-hello/main.wasm" +[component.hello] +source = "hello/main.wasm" allowed_outbound_hosts = [ "https://random-data-api.fermyon.app", "https://postman-echo.com", @@ -43,7 +37,7 @@ allowed_outbound_hosts = [ And the `outbound-http-to-same-app` uses the dedicated `self` keyword to enable making a request to another component in this same app, via a relative path (in this case, the component -is `tinygo-hello` at `/hello`): +is `hello` at `/hello`): ```toml [component.outbound-http-to-same-app] @@ -70,7 +64,7 @@ date: Thu, 26 Oct 2023 18:26:17 GMT ... ``` -As well as via the `/outbound-http-to-same-app` path to verify outbound http to the `tinygo-hello` component: +As well as via the `/outbound-http-to-same-app` path to verify outbound http to the `hello` component: ```shell $ curl -i localhost:3000/outbound-http-to-same-app diff --git a/examples/http-outbound/hello/go.mod b/examples/http-outbound/hello/go.mod index 6d0204ed..b52d93a6 100644 --- a/examples/http-outbound/hello/go.mod +++ b/examples/http-outbound/hello/go.mod @@ -1,9 +1,11 @@ -module examples/http-outbound/hello +module github.com/spinframework/spin-go-sdk/v3/examples/http-outbound/hello -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/examples/http-outbound/hello/go.sum b/examples/http-outbound/hello/go.sum index 096c54e6..7b8de78d 100644 --- a/examples/http-outbound/hello/go.sum +++ b/examples/http-outbound/hello/go.sum @@ -1,2 +1,4 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/http-outbound/hello/main.go b/examples/http-outbound/hello/main.go index d03faa5e..059ffab0 100644 --- a/examples/http-outbound/hello/main.go +++ b/examples/http-outbound/hello/main.go @@ -6,7 +6,7 @@ import ( "net/http" "os" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { diff --git a/examples/http-outbound/http-to-same-app/go.mod b/examples/http-outbound/http-to-same-app/go.mod index 3ced5b01..b52d93a6 100644 --- a/examples/http-outbound/http-to-same-app/go.mod +++ b/examples/http-outbound/http-to-same-app/go.mod @@ -1,9 +1,11 @@ -module examples/http-outbound/http-to-same-app +module github.com/spinframework/spin-go-sdk/v3/examples/http-outbound/hello -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/examples/http-outbound/http-to-same-app/go.sum b/examples/http-outbound/http-to-same-app/go.sum index 096c54e6..7b8de78d 100644 --- a/examples/http-outbound/http-to-same-app/go.sum +++ b/examples/http-outbound/http-to-same-app/go.sum @@ -1,2 +1,4 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/http-outbound/http-to-same-app/main.go b/examples/http-outbound/http-to-same-app/main.go index 27c9c89d..24eb804b 100644 --- a/examples/http-outbound/http-to-same-app/main.go +++ b/examples/http-outbound/http-to-same-app/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { diff --git a/examples/http-outbound/spin.toml b/examples/http-outbound/spin.toml index 3b5f585b..13e229c6 100644 --- a/examples/http-outbound/spin.toml +++ b/examples/http-outbound/spin.toml @@ -2,7 +2,7 @@ spin_manifest_version = 2 [application] authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests." +description = "A simple Spin application written in Go that performs outbound HTTP requests." name = "http-outbound-example" version = "1.0.0" @@ -22,7 +22,7 @@ allowed_outbound_hosts = [ ] [component.hello.build] workdir = "hello" -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../../wit build" [component.http-to-same-app] source = "http-to-same-app/main.wasm" @@ -30,4 +30,5 @@ source = "http-to-same-app/main.wasm" allowed_outbound_hosts = ["http://self"] [component.http-to-same-app.build] workdir = "http-to-same-app" -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../../wit build" + diff --git a/examples/http-router/README.md b/examples/http-router/README.md index 1a138fe9..3bd50626 100644 --- a/examples/http-router/README.md +++ b/examples/http-router/README.md @@ -1,8 +1,7 @@ -# Spin component in TinyGo using the Spin router +# Spin component in Go using the Spin router ```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up +$ spin build --up ``` The application can now receive requests on `http://localhost:3000`: diff --git a/examples/http-router/go.mod b/examples/http-router/go.mod index 7856c3ba..4a0b91cd 100644 --- a/examples/http-router/go.mod +++ b/examples/http-router/go.mod @@ -1,9 +1,11 @@ -module examples/http-router +module github.com/spinframework/spin-go-sdk/v3/examples/http-router -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/http-router/go.sum b/examples/http-router/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/http-router/go.sum +++ b/examples/http-router/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/http-router/main.go b/examples/http-router/main.go index 3c4fd482..41bd03a1 100644 --- a/examples/http-router/main.go +++ b/examples/http-router/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { diff --git a/examples/http-router/spin.toml b/examples/http-router/spin.toml index 99630052..ea8bf97c 100644 --- a/examples/http-router/spin.toml +++ b/examples/http-router/spin.toml @@ -2,7 +2,7 @@ spin_manifest_version = 2 [application] authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." name = "hello-router-example" version = "1.0.0" @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" diff --git a/examples/http/README.md b/examples/http/README.md index 741cddc6..72ecc137 100644 --- a/examples/http/README.md +++ b/examples/http/README.md @@ -1,35 +1,15 @@ -# Spin component in TinyGo - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version + +# Usage +Build and run the Spin app: +```sh +spin up --build ``` -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i localhost:3000/hello -HTTP/1.1 200 OK -content-type: text/plain -foo: bar -content-length: 440 -date: Thu, 26 Oct 2023 18:18:19 GMT - -== REQUEST == -URL: http://localhost:3000/hello -Method: GET -Headers: - "Host": "localhost:3000" - "User-Agent": "curl/8.1.2" - "Spin-Full-Url": "http://localhost:3000/hello" - "Spin-Base-Path": "/" - "Spin-Client-Addr": "127.0.0.1:52164" - "Accept": "*/*" - "Spin-Path-Info": "" - "Spin-Matched-Route": "/hello" - "Spin-Raw-Component-Route": "/hello" - "Spin-Component-Route": "/hello" -Body: -== RESPONSE == -Hello Fermyon! +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello ``` diff --git a/examples/http/go.mod b/examples/http/go.mod index c3c31c53..3ab20ea5 100644 --- a/examples/http/go.mod +++ b/examples/http/go.mod @@ -1,9 +1,11 @@ -module examples/http +module github.com/spinframework/spin-go-sdk/v3/examples/http -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/http/go.sum b/examples/http/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/http/go.sum +++ b/examples/http/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/http/main.go b/examples/http/main.go index 50212816..d3f99656 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -2,10 +2,9 @@ package main import ( "fmt" - "io" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" ) func init() { @@ -13,23 +12,10 @@ func init() { w.Header().Set("Content-Type", "text/plain") w.Header().Set("foo", "bar") - fmt.Fprintln(w, "== REQUEST ==") - fmt.Fprintln(w, "URL: ", r.URL) - fmt.Fprintln(w, "Method: ", r.Method) - fmt.Fprintln(w, "Headers:") - for k, v := range r.Header { - fmt.Fprintf(w, " %q: %q \n", k, v[0]) - } - - body, err := io.ReadAll(r.Body) - if err != nil { - fmt.Fprintln(w, "Body Error: ", err) - } else { - fmt.Fprintln(w, "Body: ", string(body)) - } - + w.WriteHeader(http.StatusOK) fmt.Fprintln(w, "== RESPONSE ==") - fmt.Fprintln(w, "Hello Fermyon!") + fmt.Fprintln(w, "Hello spinframework!") + fmt.Fprintln(w, "Hello again spinframework!") }) } diff --git a/examples/http/spin.toml b/examples/http/spin.toml index 72a0d5df..cf19e967 100644 --- a/examples/http/spin.toml +++ b/examples/http/spin.toml @@ -1,8 +1,8 @@ spin_manifest_version = 2 [application] -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." +authors = ["Rajat Jindal "] +description = "A simple Spin application written in Go." name = "hello-example" version = "1.0.0" @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" diff --git a/examples/key-value/README.md b/examples/key-value/README.md index 11487602..40751739 100644 --- a/examples/key-value/README.md +++ b/examples/key-value/README.md @@ -1,36 +1,20 @@ -# Spin Key Value component in TinyGo - -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version + +# Usage +Build and run the Spin app: +```sh +spin up --build ``` -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i -X POST -d "ok!" localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:25:43 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 200 OK -content-length: 3 -date: Tue, 25 Apr 2023 14:25:54 GMT - -ok! - -$ curl -i -X DELETE localhost:3000/test -HTTP/1.1 200 OK -content-length: 0 -date: Tue, 25 Apr 2023 14:26:30 GMT - -$ curl -i -X GET localhost:3000/test -HTTP/1.1 500 Internal Server Error -content-type: text/plain; charset=utf-8 -x-content-type-options: nosniff -content-length: 12 -date: Tue, 25 Apr 2023 14:26:32 GMT +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello +``` -no such key +You should receive the following output: +``` +["foo"] ``` diff --git a/examples/key-value/go.mod b/examples/key-value/go.mod index fa7b05b3..9cf933b2 100644 --- a/examples/key-value/go.mod +++ b/examples/key-value/go.mod @@ -1,9 +1,11 @@ -module examples/key-value +module github.com/spinframework/spin-go-sdk/v3/examples/key-value -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/key-value/go.sum b/examples/key-value/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/key-value/go.sum +++ b/examples/key-value/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/key-value/main.go b/examples/key-value/main.go index b61b63df..4cfc8be5 100644 --- a/examples/key-value/main.go +++ b/examples/key-value/main.go @@ -1,70 +1,49 @@ package main import ( - "io" + "encoding/json" + "fmt" "net/http" - spin_http "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/kv" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/kv" ) func init() { - // handler for the http trigger - spin_http.Handle(func(w http.ResponseWriter, r *http.Request) { - store, err := kv.OpenStore("default") + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + store, err := kv.OpenDefault() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - defer store.Close() - body, err := io.ReadAll(r.Body) + err = store.Set("foo", []byte("bar")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - switch r.Method { - case http.MethodPost: - err := store.Set(r.URL.Path, body) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) - case http.MethodGet: - value, err := store.Get(r.URL.Path) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + value, err := store.Get("foo") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } - w.WriteHeader(http.StatusOK) - w.Write(value) - case http.MethodDelete: - if err := store.Delete(r.URL.Path); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + if string(value) != "bar" { + http.Error(w, fmt.Sprintf("expected: %q, got: %q", "bar", value), http.StatusInternalServerError) + return + } - w.WriteHeader(http.StatusOK) - case http.MethodHead: - exists, err := store.Exists(r.URL.Path) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + keys, err := store.GetKeys() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } - if exists { - w.WriteHeader(http.StatusOK) - return - } + w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusNotFound) - default: - http.Error(w, "method not allowed", http.StatusMethodNotAllowed) - } + w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(keys) }) } diff --git a/examples/key-value/spin.toml b/examples/key-value/spin.toml index 3bda7ec2..411c95be 100644 --- a/examples/key-value/spin.toml +++ b/examples/key-value/spin.toml @@ -1,16 +1,17 @@ spin_manifest_version = 2 [application] -authors = ["Fermyon Engineering "] -name = "key-value-example" -version = "0.1.0" +authors = ["Rajat Jindal "] +description = "A simple Spin application written in Go." +name = "hello-kv" +version = "1.0.0" [[trigger.http]] -route = "/..." -component = "key-value" +route = "/hello" +component = "hello" -[component.key-value] +[component.hello] source = "main.wasm" key_value_stores = ["default"] -[component.key-value.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +[component.hello.build] +command = "componentize-go --world http-trigger --wit-path ../../wit build" diff --git a/examples/llm/go.mod b/examples/llm/go.mod index fd0c993e..3e71047b 100644 --- a/examples/llm/go.mod +++ b/examples/llm/go.mod @@ -1,9 +1,11 @@ -module examples/llm +module github.com/spinframework/spin-go-sdk/v3/examples/llm -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/llm/go.sum b/examples/llm/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/llm/go.sum +++ b/examples/llm/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/llm/main.go b/examples/llm/main.go index 55dae4ec..c0712980 100644 --- a/examples/llm/main.go +++ b/examples/llm/main.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/llm" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/llm" ) func init() { diff --git a/examples/llm/spin.toml b/examples/llm/spin.toml index 218c2dfe..32cf0545 100644 --- a/examples/llm/spin.toml +++ b/examples/llm/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] ai_models = ["llama2-chat", "all-minilm-l6-v2"] [component.llm.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/llm/.gitignore b/examples/mqtt-outbound/.gitignore similarity index 100% rename from v3/examples/llm/.gitignore rename to examples/mqtt-outbound/.gitignore diff --git a/v3/examples/mqtt-outbound/README.md b/examples/mqtt-outbound/README.md similarity index 100% rename from v3/examples/mqtt-outbound/README.md rename to examples/mqtt-outbound/README.md diff --git a/v3/examples/mqtt-outbound/compose.yaml b/examples/mqtt-outbound/compose.yaml similarity index 100% rename from v3/examples/mqtt-outbound/compose.yaml rename to examples/mqtt-outbound/compose.yaml diff --git a/examples/mqtt-outbound/go.mod b/examples/mqtt-outbound/go.mod new file mode 100644 index 00000000..38f5229a --- /dev/null +++ b/examples/mqtt-outbound/go.mod @@ -0,0 +1,11 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/mqtt-outbound + +go 1.25.5 + +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/v3/examples/http/go.sum b/examples/mqtt-outbound/go.sum similarity index 71% rename from v3/examples/http/go.sum rename to examples/mqtt-outbound/go.sum index 00db3b18..b5bca15f 100644 --- a/v3/examples/http/go.sum +++ b/examples/mqtt-outbound/go.sum @@ -2,3 +2,5 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/examples/mqtt-outbound/main.go b/examples/mqtt-outbound/main.go similarity index 100% rename from v3/examples/mqtt-outbound/main.go rename to examples/mqtt-outbound/main.go diff --git a/v3/examples/mqtt-outbound/spin.toml b/examples/mqtt-outbound/spin.toml similarity index 97% rename from v3/examples/mqtt-outbound/spin.toml rename to examples/mqtt-outbound/spin.toml index 608f998b..aa91dadc 100644 --- a/v3/examples/mqtt-outbound/spin.toml +++ b/examples/mqtt-outbound/spin.toml @@ -16,5 +16,5 @@ source = "main.wasm" environment = { MQTT_ADDRESS = "mqtt://127.0.0.1:1883?client_id=client001", MQTT_USERNAME = "user", MQTT_PASSWORD = "password", MQTT_KEEP_ALIVE_INTERVAL = "30", MQTT_TOPIC = "telemetry" } allowed_outbound_hosts = ["mqtt://127.0.0.1:1883"] [component.mqtt-outbound.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" +command = "componentize-go --world http-trigger --wit-path ../../wit build" watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/mysql-outbound/README.md b/examples/mysql-outbound/README.md similarity index 100% rename from v3/examples/mysql-outbound/README.md rename to examples/mysql-outbound/README.md diff --git a/v3/examples/mysql-outbound/compose.yaml b/examples/mysql-outbound/compose.yaml similarity index 100% rename from v3/examples/mysql-outbound/compose.yaml rename to examples/mysql-outbound/compose.yaml diff --git a/examples/mysql-outbound/db/pets.sql b/examples/mysql-outbound/db/pets.sql deleted file mode 100644 index bbf91d68..00000000 --- a/examples/mysql-outbound/db/pets.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE pets (id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, prey VARCHAR(100), is_finicky BOOL NOT NULL); -INSERT INTO pets VALUES (1, 'Splodge', NULL, false); -INSERT INTO pets VALUES (2, 'Kiki', 'Cicadas', false); -INSERT INTO pets VALUES (3, 'Slats', 'Temptations', true); diff --git a/examples/mysql-outbound/go.mod b/examples/mysql-outbound/go.mod index 3806168e..03746c62 100644 --- a/examples/mysql-outbound/go.mod +++ b/examples/mysql-outbound/go.mod @@ -1,9 +1,11 @@ -module examples/mysql-outbound +module github.com/spinframework/spin-go-sdk/v3/examples/mysql-outbound -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/mysql-outbound/go.sum b/examples/mysql-outbound/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/mysql-outbound/go.sum +++ b/examples/mysql-outbound/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/examples/mysql-outbound/init.sql b/examples/mysql-outbound/init.sql similarity index 100% rename from v3/examples/mysql-outbound/init.sql rename to examples/mysql-outbound/init.sql diff --git a/examples/mysql-outbound/main.go b/examples/mysql-outbound/main.go index 08c49e7c..f20e9091 100644 --- a/examples/mysql-outbound/main.go +++ b/examples/mysql-outbound/main.go @@ -6,8 +6,8 @@ import ( "net/http" "os" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/mysql" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/mysql" ) type Pet struct { @@ -27,8 +27,12 @@ func init() { db := mysql.Open(addr) defer db.Close() - _, err := db.Query("REPLACE INTO pets VALUES (?, 'Maya', ?, ?);", 4, "bananas", true) - if err != nil { + if _, err := db.Query("REPLACE INTO pets VALUES (?, 'Maya', ?, ?);", 4, "bananas", true); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if _, err := db.Exec("INSERT INTO pets VALUES (?, ?, ?, ?)", 5, "Copper", "Foxes", false); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/examples/mysql-outbound/spin.toml b/examples/mysql-outbound/spin.toml index dcb15df9..a9b7233b 100644 --- a/examples/mysql-outbound/spin.toml +++ b/examples/mysql-outbound/spin.toml @@ -1,19 +1,19 @@ spin_manifest_version = 2 [application] -authors = ["Patrick Jiang "] -description = "" -name = "mysql-outbound-example" +name = "go-mysql-outbound-example" version = "0.1.0" +authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] +description = "Using Spin with MySQL" [[trigger.http]] route = "/..." component = "mysql" [component.mysql] -environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_dev" } +environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } source = "main.wasm" allowed_outbound_hosts = ["mysql://127.0.0.1"] [component.mysql.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" watch = ["**/*.go", "go.mod"] diff --git a/examples/pg-outbound/go.mod b/examples/pg-outbound/go.mod index adcf1136..bcb32f67 100644 --- a/examples/pg-outbound/go.mod +++ b/examples/pg-outbound/go.mod @@ -1,9 +1,11 @@ -module examples/pg-outbound +module github.com/spinframework/spin-go-sdk/v3/examples/pg-outbound -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/pg-outbound/go.sum b/examples/pg-outbound/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/pg-outbound/go.sum +++ b/examples/pg-outbound/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/pg-outbound/main.go b/examples/pg-outbound/main.go index 0f897305..ef2ab975 100644 --- a/examples/pg-outbound/main.go +++ b/examples/pg-outbound/main.go @@ -6,8 +6,8 @@ import ( "net/http" "os" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/pg" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/pg" ) type Pet struct { diff --git a/examples/pg-outbound/spin.toml b/examples/pg-outbound/spin.toml index ca8739b2..a14edc58 100644 --- a/examples/pg-outbound/spin.toml +++ b/examples/pg-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "host=localhost user=postgres dbname=spin_dev" } source = "main.wasm" allowed_outbound_hosts = ["postgres://localhost"] [component.pg-outbound.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" watch = ["**/*.go", "go.mod"] diff --git a/examples/redis-outbound/README.md b/examples/redis-outbound/README.md index fdcb43cf..17dd7746 100644 --- a/examples/redis-outbound/README.md +++ b/examples/redis-outbound/README.md @@ -1,18 +1,27 @@ -# Spin component in TinyGo making an outbound http call to Redis +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up +# Usage +In one terminal window, you'll run a Redis container: +```sh +docker run -p 6379:6379 redis:8.2 ``` -The application can now receive requests on `http://localhost:3000/publish`: +In another terminal, you'll run your Spin app: +```sh +spin up --build +``` -```shell -$ curl -i localhost:3000/publish -HTTP/1.1 200 OK -content-length: 67 -date: Tue, 29 Nov 2022 07:03:52 GMT +In yet another terminal, you'll interact with the Spin app: +```sh +curl localhost:3000 +``` +You should see the following output: +``` mykey value was: myvalue spin-go-incr value: 1 deleted keys num: 2 diff --git a/examples/redis-outbound/go.mod b/examples/redis-outbound/go.mod index 6cdd8e89..d96fe05d 100644 --- a/examples/redis-outbound/go.mod +++ b/examples/redis-outbound/go.mod @@ -1,9 +1,11 @@ -module examples/redis-outbound +module github.com/spinframework/spin-go-sdk/v3/examples/redis-outbound -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/redis-outbound/go.sum b/examples/redis-outbound/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/redis-outbound/go.sum +++ b/examples/redis-outbound/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/redis-outbound/main.go b/examples/redis-outbound/main.go index 824bdbde..3c0a431b 100644 --- a/examples/redis-outbound/main.go +++ b/examples/redis-outbound/main.go @@ -8,8 +8,8 @@ import ( "sort" "strconv" - spin_http "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/redis" + spin_http "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/redis" ) func init() { @@ -28,7 +28,11 @@ func init() { // payload is the data publish to the redis channel. payload := []byte(`Hello redis from tinygo!`) - rdb := redis.NewClient(addr) + rdb, err := redis.NewClient(addr) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } if err := rdb.Publish(channel, payload); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -66,7 +70,7 @@ func init() { http.Error(w, err.Error(), http.StatusInternalServerError) } else { w.Write([]byte("deleted keys num: ")) - w.Write([]byte(strconv.FormatInt(payload, 10))) + w.Write([]byte(strconv.FormatInt(int64(payload), 10))) w.Write([]byte("\n")) } @@ -140,7 +144,9 @@ func init() { Kind: redis.ResultKindBinary, Val: []byte("hello world"), }}) { + http.Error(w, "unexpected GET result", http.StatusInternalServerError) + fmt.Println() return } }) diff --git a/examples/redis-outbound/spin.toml b/examples/redis-outbound/spin.toml index 80400543..c8b314af 100644 --- a/examples/redis-outbound/spin.toml +++ b/examples/redis-outbound/spin.toml @@ -1,17 +1,20 @@ spin_manifest_version = 2 [application] -authors = ["Fermyon Engineering "] -name = "redis-outbound-example" +name = "go-redis-outbound-example" version = "0.1.0" +authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] +description = "Using Spin with Redis" [[trigger.http]] -route = "/publish" -component = "outbound-redis" +route = "/" +component = "redis-outbound" -[component.outbound-redis] +[component.redis-outbound] source = "main.wasm" -environment = { REDIS_ADDRESS = "redis://127.0.0.1:6379", REDIS_CHANNEL = "messages" } -allowed_outbound_hosts = ["redis://127.0.0.1"] -[component.outbound-redis.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messages" } +allowed_outbound_hosts = ["redis://localhost:6379"] + +[component.redis-outbound.build] +command = "componentize-go --world http-trigger --wit-path ../../wit build" +watch = ["**/*.go", "go.mod"] diff --git a/examples/redis/README.md b/examples/redis/README.md index 67a7174c..d1276828 100644 --- a/examples/redis/README.md +++ b/examples/redis/README.md @@ -1,7 +1,7 @@ -# Spin component in TinyGo using the Redis trigger +# Spin component in Go using the Redis trigger ```shell -$ RUST_LOG=spin=trace spin build --up +$ spin build --up ``` ```shell diff --git a/examples/redis/go.mod b/examples/redis/go.mod index 5f777f66..1b67c8d7 100644 --- a/examples/redis/go.mod +++ b/examples/redis/go.mod @@ -1,9 +1,11 @@ -module examples/redis +module github.com/spinframework/spin-go-sdk/v3/examples/redis -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/redis/go.sum b/examples/redis/go.sum index e69de29b..b5bca15f 100644 --- a/examples/redis/go.sum +++ b/examples/redis/go.sum @@ -0,0 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/redis/main.go b/examples/redis/main.go index db709a97..4c22eec4 100644 --- a/examples/redis/main.go +++ b/examples/redis/main.go @@ -3,12 +3,12 @@ package main import ( "fmt" - "github.com/spinframework/spin-go-sdk/v2/redis" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis" ) func init() { - // redis.Handle() must be called in the init() function. - redis.Handle(func(payload []byte) error { + // inbound_redis.Handle() must be called in the init() function. + inbound_redis.Handle(func(payload []byte) error { fmt.Println("Payload::::") fmt.Println(string(payload)) return nil diff --git a/examples/redis/spin.toml b/examples/redis/spin.toml index 2c1458f6..01f141b9 100644 --- a/examples/redis/spin.toml +++ b/examples/redis/spin.toml @@ -16,4 +16,5 @@ component = "echo-message" [component.echo-message] source = "main.wasm" [component.echo-message.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world fermyon:spin/redis-trigger --wit-path ../../wit build" + diff --git a/examples/sqlite/go.mod b/examples/sqlite/go.mod index 6f24121b..65b8592b 100644 --- a/examples/sqlite/go.mod +++ b/examples/sqlite/go.mod @@ -1,9 +1,11 @@ -module examples/sqlite +module github.com/spinframework/spin-go-sdk/v3/examples/sqlite -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/sqlite/go.sum b/examples/sqlite/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/sqlite/go.sum +++ b/examples/sqlite/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/sqlite/main.go b/examples/sqlite/main.go index b63426c9..36548d70 100644 --- a/examples/sqlite/main.go +++ b/examples/sqlite/main.go @@ -5,8 +5,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/sqlite" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/sqlite" ) type Pet struct { diff --git a/examples/sqlite/spin.toml b/examples/sqlite/spin.toml index 205483c4..144700c4 100644 --- a/examples/sqlite/spin.toml +++ b/examples/sqlite/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] sqlite_databases = ["default"] [component.sqlite.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" watch = ["**/*.go", "go.mod"] diff --git a/examples/variables/README.md b/examples/variables/README.md index e56da555..ca75f048 100644 --- a/examples/variables/README.md +++ b/examples/variables/README.md @@ -1,17 +1,20 @@ -# Spin component in TinyGo using variables +# Requirements +- [**go**](https://go.dev/dl/) - v1.25+ +- [**spin**](https://github.com/spinframework/spin) - Latest version +- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version -```shell -$ go mod tidy -$ RUST_LOG=spin=trace spin build --up +# Usage +Build and run the Spin app: +```sh +spin up --build ``` -The application can now receive requests on `http://localhost:3000`: - -```shell -$ curl -i localhost:3000 -HTTP/1.1 200 OK -content-length: 23 -date: Tue, 29 Nov 2022 06:59:24 GMT +In another terminal window, you can interact with the Spin app: +```sh +curl localhost:3000/hello +``` +You should receive the following output: +``` message: I'm a teapot ``` diff --git a/examples/variables/go.mod b/examples/variables/go.mod index 3b8d9f44..c85e5eaf 100644 --- a/examples/variables/go.mod +++ b/examples/variables/go.mod @@ -1,9 +1,11 @@ -module examples/variables +module github.com/spinframework/spin-go-sdk/v3/examples/variables -go 1.20 +go 1.25.5 -require github.com/spinframework/spin-go-sdk/v2 v2.2.1 +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) -require github.com/julienschmidt/httprouter v1.3.0 // indirect - -replace github.com/spinframework/spin-go-sdk/v2 v2.2.1 => ../../ +replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/variables/go.sum b/examples/variables/go.sum index 096c54e6..b5bca15f 100644 --- a/examples/variables/go.sum +++ b/examples/variables/go.sum @@ -1,2 +1,6 @@ +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= +github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/variables/main.go b/examples/variables/main.go index e0a4091d..4791c8b1 100644 --- a/examples/variables/main.go +++ b/examples/variables/main.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" - "github.com/spinframework/spin-go-sdk/v2/variables" + spinhttp "github.com/spinframework/spin-go-sdk/v3/http" + "github.com/spinframework/spin-go-sdk/v3/variables" ) func init() { diff --git a/examples/variables/spin.toml b/examples/variables/spin.toml index 5f5c91e6..a42df893 100644 --- a/examples/variables/spin.toml +++ b/examples/variables/spin.toml @@ -3,7 +3,7 @@ spin_manifest_version = 2 [application] name = "variables-example" authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." +description = "A simple Spin application written in Go." version = "1.0.0" [variables] @@ -17,5 +17,6 @@ component = "variables" source = "main.wasm" [component.variables.variables] message = "I'm a {{object}}" + [component.variables.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." +command = "componentize-go --world http-trigger --wit-path ../../wit build" diff --git a/go.mod b/go.mod index 003ac4f2..d12c6b20 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ -module github.com/spinframework/spin-go-sdk/v2 +module github.com/spinframework/spin-go-sdk/v3 -go 1.20 +go 1.25.5 + +require ( + go.bytecodealliance.org/pkg v0.2.1 + github.com/julienschmidt/httprouter v1.3.0 +) -require github.com/julienschmidt/httprouter v1.3.0 diff --git a/go.sum b/go.sum index 096c54e6..7b8de78d 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/http/client.go b/http/client.go similarity index 97% rename from v3/http/client.go rename to http/client.go index 9e67dd48..77960964 100644 --- a/v3/http/client.go +++ b/http/client.go @@ -5,9 +5,9 @@ import ( "io" "net/http" - wit "github.com/bytecodealliance/wit-bindgen/wit_types" outgoinghandler "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_outgoing_handler" types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + wit "go.bytecodealliance.org/pkg/wit/types" ) // NewTransport returns http.RoundTripper backed by Spin SDK diff --git a/v3/http/convertor_incoming_request.go b/http/convertor_incoming_request.go similarity index 100% rename from v3/http/convertor_incoming_request.go rename to http/convertor_incoming_request.go diff --git a/v3/http/convertor_outgoing_request.go b/http/convertor_outgoing_request.go similarity index 96% rename from v3/http/convertor_outgoing_request.go rename to http/convertor_outgoing_request.go index cc55da94..99a6c8b0 100644 --- a/v3/http/convertor_outgoing_request.go +++ b/http/convertor_outgoing_request.go @@ -3,8 +3,8 @@ package http import ( "net/http" - wit "github.com/bytecodealliance/wit-bindgen/wit_types" types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + wit "go.bytecodealliance.org/pkg/wit/types" ) // convert the IncomingRequest to http.Request diff --git a/v3/http/convertor_outgoing_response.go b/http/convertor_outgoing_response.go similarity index 98% rename from v3/http/convertor_outgoing_response.go rename to http/convertor_outgoing_response.go index 95d55be4..c9a828f8 100644 --- a/v3/http/convertor_outgoing_response.go +++ b/http/convertor_outgoing_response.go @@ -5,9 +5,9 @@ import ( "net/http" "strings" - wit "github.com/bytecodealliance/wit-bindgen/wit_types" types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" streams "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + wit "go.bytecodealliance.org/pkg/wit/types" ) var _ http.ResponseWriter = &responseOutparamWriter{} diff --git a/http/http.go b/http/http.go index ba4a22c2..15d0ad67 100644 --- a/http/http.go +++ b/http/http.go @@ -1,16 +1,26 @@ // Package http contains the helper functions for writing Spin HTTP components -// in TinyGo, as well as for sending outbound HTTP requests. +// in Go, as well as for sending outbound HTTP requests. package http import ( "fmt" - "io" "net/http" "os" "github.com/julienschmidt/httprouter" + incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" + types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + _ "github.com/spinframework/spin-go-sdk/v3/internal/wit_exports" + "github.com/spinframework/spin-go-sdk/v3/wit" ) +// 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" @@ -31,11 +41,6 @@ const ( HeaderClientAddr = "spin-client-addr" ) -// Override the default HTTP client to be compatible with the Spin SDK. -func init() { - http.DefaultClient = NewClient() -} - // Router is a http.Handler which can be used to dispatch requests to different // handler functions via configurable routes type Router = httprouter.Router @@ -59,26 +64,6 @@ func NewRouter() *Router { return httprouter.New() } -// 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{}, - } -} - // handler is the function that will be called by the http trigger in Spin. var handler = defaultHandler @@ -94,23 +79,21 @@ func Handle(fn func(http.ResponseWriter, *http.Request)) { handler = fn } -// Get creates a GET HTTP request to a given URL and returns the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Get(url string) (*http.Response, error) { - return get(url) -} +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 + } -// Post creates a POST HTTP request and returns the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Post(url string, contentType string, body io.Reader) (*http.Response, error) { - return post(url, contentType, body) -} + // convert the response outparam to go's net/http type + httpRes := NewHttpResponseWriter(*responseOut) + + // run the user's handler + handler(httpRes, httpReq) -// Send sends an HTTP request and return the HTTP response. -// The destination of the request must be explicitly allowed in the Spin application -// configuration, otherwise the request will not be sent. -func Send(req *http.Request) (*http.Response, error) { - return send(req) + // ensure default status ok and response body are set + _ = httpRes.reconcile() } diff --git a/http/internals.go b/http/internals.go deleted file mode 100644 index 8256a2a4..00000000 --- a/http/internals.go +++ /dev/null @@ -1,140 +0,0 @@ -package http - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include -// #include -import "C" -import ( - "bytes" - "fmt" - "io" - "net/http" - "os" - "unsafe" -) - -//export spin_http_handle_http_request -func handle_http_request(req *C.spin_http_request_t, res *C.spin_http_response_t) { - var body []byte - if req.body.is_some { - body = C.GoBytes(unsafe.Pointer(req.body.val.ptr), C.int(req.body.val.len)) - } - method := methods[req.method] - header := fromSpinHeaders(&req.headers) - url := header.Get(HeaderFullUrl) - - r, err := http.NewRequest(method, url, bytes.NewReader(body)) - if err != nil { - fmt.Fprintln(os.Stderr, err) - res.status = C.uint16_t(http.StatusInternalServerError) - return - } - - r.Header = header - r.Host = r.Header.Get("Host") - r.RequestURI = C.GoStringN(req.uri.ptr, C.int(req.uri.len)) - r.RemoteAddr = r.Header.Get(HeaderClientAddr) - - w := newResponse() - - // call user function - handler(w, r) - - res.status = C.uint16_t(w.status) - if len(w.header) > 0 { - res.headers = C.spin_http_option_headers_t{ - is_some: true, - val: toSpinHeaders(w.header), - } - } else { - res.headers = C.spin_http_option_headers_t{is_some: false} - } - - res.body, err = toSpinBody(w.w) - if err != nil { - fmt.Fprintln(os.Stderr, err) - } -} - -func toSpinHeaders(hm http.Header) C.spin_http_headers_t { - var reqHeaders C.spin_http_headers_t - - headersLen := len(hm) - - if headersLen > 0 { - reqHeaders.len = C.ulong(headersLen) - var x C.spin_http_tuple2_string_string_t - reqHeaders.ptr = (*C.spin_http_tuple2_string_string_t)(C.malloc(C.size_t(headersLen) * C.size_t(unsafe.Sizeof(x)))) - headers := unsafe.Slice(reqHeaders.ptr, headersLen) - - idx := 0 - for k, v := range hm { - headers[idx] = newSpinHeader(k, v[0]) - idx++ - } - } - return reqHeaders -} - -func toSpinBody(body io.Reader) (C.spin_http_option_body_t, error) { - var spinBody C.spin_http_option_body_t - spinBody.is_some = false - - if body == nil { - return spinBody, nil - } - - buf := new(bytes.Buffer) - len, err := buf.ReadFrom(body) - if err != nil { - return spinBody, err - } - - if len > 0 { - bodyPtr := (*C.uint8_t)(C.malloc(C.size_t(len))) - copy(unsafe.Slice(bodyPtr, len), buf.Bytes()) - - spinBody.is_some = true - spinBody.val = C.spin_http_body_t{ - ptr: bodyPtr, - len: C.size_t(len), - } - } - - return spinBody, nil -} - -// newSpinHeader creates a new spinHeader with the given key/value. -func newSpinHeader(k, v string) C.spin_http_tuple2_string_string_t { - return C.spin_http_tuple2_string_string_t{ - f0: C.spin_http_string_t{ptr: C.CString(k), len: C.size_t(len(k))}, - f1: C.spin_http_string_t{ptr: C.CString(v), len: C.size_t(len(v))}, - } -} - -var methods = [...]string{ - "GET", - "POST", - "PUT", - "DELETE", - "PATCH", - "HEAD", - "OPTIONS", -} - -func fromSpinHeaders(hm *C.spin_http_headers_t) http.Header { - headersLen := int(hm.len) - headers := make(http.Header, headersLen) - - var headersArr *C.spin_http_tuple2_string_string_t = hm.ptr - headersSlice := unsafe.Slice(headersArr, headersLen) - for i := 0; i < headersLen; i++ { - tuple := headersSlice[i] - k := C.GoStringN(tuple.f0.ptr, C.int(tuple.f0.len)) - v := C.GoStringN(tuple.f1.ptr, C.int(tuple.f1.len)) - - headers.Add(k, v) - } - - return headers -} diff --git a/http/outbound_internals.go b/http/outbound_internals.go deleted file mode 100644 index c371f673..00000000 --- a/http/outbound_internals.go +++ /dev/null @@ -1,196 +0,0 @@ -//nolint:staticcheck - -// This file contains the manual conversions between Go HTTP objects -// and Spin HTTP objects, through the auto-generated C bindings for -// the outbound HTTP API. - -package http - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include "wasi-outbound-http.h" -// #include -import "C" - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "net/http" - "strings" - "unsafe" -) - -func get(url string) (*http.Response, error) { - req, err := http.NewRequest("GET", 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("POST", url, body) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", contentType) - - return send(req) -} - -func send(req *http.Request) (*http.Response, error) { - var spinReq C.wasi_outbound_http_request_t - var spinRes C.wasi_outbound_http_response_t - - m, err := method(req.Method) - if err != nil { - return nil, err - } - spinReq.method = uint8(m) - spinReq.uri = C.wasi_outbound_http_uri_t{ - ptr: C.CString(req.URL.String()), - len: C.ulong(len(req.URL.String())), - } - spinReq.headers = toOutboundHeaders(req.Header) - spinReq.body, err = toOutboundReqBody(req.Body) - if err != nil { - return nil, err - } - - code := C.wasi_outbound_http_request(&spinReq, &spinRes) - - if err := toErr(code, req.URL.String()); err != nil { - return nil, err - } - return toResponse(&spinRes) -} - -func method(m string) (int, error) { - switch strings.ToUpper(m) { - case "GET": - return 0, nil - case "POST": - return 1, nil - case "PUT": - return 2, nil - case "DELETE": - return 3, nil - case "PATCH": - return 4, nil - case "HEAD": - return 5, nil - case "OPTIONS": - return 6, nil - default: - return -1, fmt.Errorf("Unknown HTTP method %v", m) - } -} - -// Transform a C outbound HTTP response to a Go *http.Response. -func toResponse(res *C.wasi_outbound_http_response_t) (*http.Response, error) { - var body []byte - if res.body.is_some { - body = C.GoBytes(unsafe.Pointer(res.body.val.ptr), C.int(res.body.val.len)) - } - - t := &http.Response{ - Status: fmt.Sprintf("%v %v", res.status, http.StatusText(int(res.status))), - StatusCode: int(res.status), - Proto: "HTTP/1.1", - ProtoMajor: 1, - ProtoMinor: 1, - Body: ioutil.NopCloser(bytes.NewBuffer(body)), - ContentLength: int64(len(body)), - Request: nil, // we don't really have a request to populate with here - Header: toHeaders(&res.headers), - } - return t, nil -} - -func toOutboundHeaders(hm http.Header) C.wasi_outbound_http_headers_t { - var reqHeaders C.wasi_outbound_http_headers_t - - headersLen := len(hm) - - if headersLen > 0 { - reqHeaders.len = C.ulong(headersLen) - var x C.wasi_outbound_http_tuple2_string_string_t - reqHeaders.ptr = (*C.wasi_outbound_http_tuple2_string_string_t)(C.malloc(C.size_t(headersLen) * C.size_t(unsafe.Sizeof(x)))) - headers := unsafe.Slice(reqHeaders.ptr, headersLen) - - idx := 0 - for k, v := range hm { - headers[idx] = newOutboundHeader(k, v[0]) - idx++ - } - } - return reqHeaders -} - -func toOutboundReqBody(body io.Reader) (C.wasi_outbound_http_option_body_t, error) { - var spinBody C.wasi_outbound_http_option_body_t - spinBody.is_some = false - - if body != nil { - buf := new(bytes.Buffer) - len, err := buf.ReadFrom(body) - if err != nil { - return spinBody, err - } - - if len > 0 { - spinBody.is_some = true - spinBody.val = C.wasi_outbound_http_body_t{ - ptr: &buf.Bytes()[0], - len: C.size_t(len), - } - } - } - - return spinBody, nil -} - -func toHeaders(hm *C.wasi_outbound_http_option_headers_t) http.Header { - if !hm.is_some { - return make(map[string][]string, 0) - } - headersLen := int(hm.val.len) - headers := make(http.Header, headersLen) - - var headersArr *C.wasi_outbound_http_tuple2_string_string_t = hm.val.ptr - headersSlice := unsafe.Slice(headersArr, headersLen) - for i := 0; i < headersLen; i++ { - tuple := headersSlice[i] - k := C.GoStringN(tuple.f0.ptr, C.int(tuple.f0.len)) - v := C.GoStringN(tuple.f1.ptr, C.int(tuple.f1.len)) - - headers.Add(k, v) - } - - return headers -} - -func toErr(code C.uint8_t, url string) error { - switch code { - case 1: - return fmt.Errorf("Destination not allowed: %v", url) - case 2: - return fmt.Errorf("Invalid URL: %v", url) - case 3: - return fmt.Errorf("Error sending request to URL: %v", url) - case 4: - return fmt.Errorf("Runtime error") - default: - return nil - } -} - -// newOutboundHeader creates a new outboundHeader with the given key/value. -func newOutboundHeader(k, v string) C.wasi_outbound_http_tuple2_string_string_t { - return C.wasi_outbound_http_tuple2_string_string_t{ - f0: C.wasi_outbound_http_string_t{ptr: C.CString(k), len: C.size_t(len(k))}, - f1: C.wasi_outbound_http_string_t{ptr: C.CString(v), len: C.size_t(len(v))}, - } -} diff --git a/http/response.go b/http/response.go deleted file mode 100644 index a1b2559c..00000000 --- a/http/response.go +++ /dev/null @@ -1,39 +0,0 @@ -package http - -import ( - "bytes" - "net/http" -) - -var _ http.ResponseWriter = (*response)(nil) - -// response implements http.ResponseWriter -type response struct { - // status code passed to WriteHeader - status int - - header http.Header - w *bytes.Buffer -} - -func newResponse() *response { - return &response{ - // set default status to StatusOK - status: http.StatusOK, - - header: make(http.Header), - w: new(bytes.Buffer), - } -} - -func (r *response) Header() http.Header { - return r.header -} - -func (r *response) WriteHeader(statusCode int) { - r.status = statusCode -} - -func (r *response) Write(data []byte) (int, error) { - return r.w.Write(data) -} diff --git a/http/spin-http.c b/http/spin-http.c deleted file mode 100644 index 780a4adf..00000000 --- a/http/spin-http.c +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_http_string_set(spin_http_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_http_string_dup(spin_http_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_http_string_free(spin_http_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_http_body_free(spin_http_body_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void spin_http_tuple2_string_string_free(spin_http_tuple2_string_string_t *ptr) { - spin_http_string_free(&ptr->f0); - spin_http_string_free(&ptr->f1); -} -void spin_http_headers_free(spin_http_headers_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - spin_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void spin_http_params_free(spin_http_params_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - spin_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void spin_http_uri_free(spin_http_uri_t *ptr) { - spin_http_string_free(ptr); -} -void spin_http_option_body_free(spin_http_option_body_t *ptr) { - if (ptr->is_some) { - spin_http_body_free(&ptr->val); - } -} -void spin_http_request_free(spin_http_request_t *ptr) { - spin_http_uri_free(&ptr->uri); - spin_http_headers_free(&ptr->headers); - spin_http_params_free(&ptr->params); - spin_http_option_body_free(&ptr->body); -} -void spin_http_option_headers_free(spin_http_option_headers_t *ptr) { - if (ptr->is_some) { - spin_http_headers_free(&ptr->val); - } -} -void spin_http_response_free(spin_http_response_t *ptr) { - spin_http_option_headers_free(&ptr->headers); - spin_http_option_body_free(&ptr->body); -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[28]; -__attribute__((export_name("handle-http-request"))) -int32_t __wasm_export_spin_http_handle_http_request(int32_t arg, int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5, int32_t arg6, int32_t arg7, int32_t arg8) { - spin_http_option_body_t option; - switch (arg6) { - case 0: { - option.is_some = false; - - break; - } - case 1: { - option.is_some = true; - - option.val = (spin_http_body_t) { (uint8_t*)(arg7), (size_t)(arg8) }; - break; - } - }spin_http_request_t arg9 = (spin_http_request_t) { - arg, - (spin_http_string_t) { (char*)(arg0), (size_t)(arg1) }, - (spin_http_headers_t) { (spin_http_tuple2_string_string_t*)(arg2), (size_t)(arg3) }, - (spin_http_params_t) { (spin_http_tuple2_string_string_t*)(arg4), (size_t)(arg5) }, - option, - }; - spin_http_response_t ret; - spin_http_handle_http_request(&arg9, &ret); - int32_t ptr = (int32_t) &RET_AREA; - *((int16_t*)(ptr + 0)) = (int32_t) ((ret).status); - - if (((ret).headers).is_some) { - const spin_http_headers_t *payload10 = &((ret).headers).val; - *((int8_t*)(ptr + 4)) = 1; - *((int32_t*)(ptr + 12)) = (int32_t) (*payload10).len; - *((int32_t*)(ptr + 8)) = (int32_t) (*payload10).ptr; - - } else { - *((int8_t*)(ptr + 4)) = 0; - - } - - if (((ret).body).is_some) { - const spin_http_body_t *payload12 = &((ret).body).val; - *((int8_t*)(ptr + 16)) = 1; - *((int32_t*)(ptr + 24)) = (int32_t) (*payload12).len; - *((int32_t*)(ptr + 20)) = (int32_t) (*payload12).ptr; - - } else { - *((int8_t*)(ptr + 16)) = 0; - - } - return ptr; -} diff --git a/http/spin-http.h b/http/spin-http.h deleted file mode 100644 index cd47c95c..00000000 --- a/http/spin-http.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __BINDINGS_SPIN_HTTP_H -#define __BINDINGS_SPIN_HTTP_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_http_string_t; - - void spin_http_string_set(spin_http_string_t *ret, const char *s); - void spin_http_string_dup(spin_http_string_t *ret, const char *s); - void spin_http_string_free(spin_http_string_t *ret); - typedef struct { - uint8_t *ptr; - size_t len; - } spin_http_body_t; - void spin_http_body_free(spin_http_body_t *ptr); - typedef struct { - spin_http_string_t f0; - spin_http_string_t f1; - } spin_http_tuple2_string_string_t; - void spin_http_tuple2_string_string_free(spin_http_tuple2_string_string_t *ptr); - typedef struct { - spin_http_tuple2_string_string_t *ptr; - size_t len; - } spin_http_headers_t; - void spin_http_headers_free(spin_http_headers_t *ptr); - typedef uint8_t spin_http_http_error_t; - #define SPIN_HTTP_HTTP_ERROR_SUCCESS 0 - #define SPIN_HTTP_HTTP_ERROR_DESTINATION_NOT_ALLOWED 1 - #define SPIN_HTTP_HTTP_ERROR_INVALID_URL 2 - #define SPIN_HTTP_HTTP_ERROR_REQUEST_ERROR 3 - #define SPIN_HTTP_HTTP_ERROR_RUNTIME_ERROR 4 - #define SPIN_HTTP_HTTP_ERROR_TOO_MANY_REQUESTS 5 - typedef uint16_t spin_http_http_status_t; - typedef uint8_t spin_http_method_t; - #define SPIN_HTTP_METHOD_GET 0 - #define SPIN_HTTP_METHOD_POST 1 - #define SPIN_HTTP_METHOD_PUT 2 - #define SPIN_HTTP_METHOD_DELETE 3 - #define SPIN_HTTP_METHOD_PATCH 4 - #define SPIN_HTTP_METHOD_HEAD 5 - #define SPIN_HTTP_METHOD_OPTIONS 6 - typedef struct { - spin_http_tuple2_string_string_t *ptr; - size_t len; - } spin_http_params_t; - void spin_http_params_free(spin_http_params_t *ptr); - typedef spin_http_string_t spin_http_uri_t; - void spin_http_uri_free(spin_http_uri_t *ptr); - typedef struct { - bool is_some; - spin_http_body_t val; - } spin_http_option_body_t; - void spin_http_option_body_free(spin_http_option_body_t *ptr); - typedef struct { - spin_http_method_t method; - spin_http_uri_t uri; - spin_http_headers_t headers; - spin_http_params_t params; - spin_http_option_body_t body; - } spin_http_request_t; - void spin_http_request_free(spin_http_request_t *ptr); - typedef struct { - bool is_some; - spin_http_headers_t val; - } spin_http_option_headers_t; - void spin_http_option_headers_free(spin_http_option_headers_t *ptr); - typedef struct { - spin_http_http_status_t status; - spin_http_option_headers_t headers; - spin_http_option_body_t body; - } spin_http_response_t; - void spin_http_response_free(spin_http_response_t *ptr); - void spin_http_handle_http_request(spin_http_request_t *req, spin_http_response_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/v3/http/streams.go b/http/streams.go similarity index 100% rename from v3/http/streams.go rename to http/streams.go diff --git a/http/testdata/http-tinygo/Makefile b/http/testdata/http-tinygo/Makefile deleted file mode 100644 index b905087a..00000000 --- a/http/testdata/http-tinygo/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -.PHONY: build -build: - tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm . diff --git a/http/testdata/http-tinygo/main.go b/http/testdata/http-tinygo/main.go deleted file mode 100644 index b5a715a6..00000000 --- a/http/testdata/http-tinygo/main.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Spin-Raw-Component-Route") != "/hello/..." { - http.Error(w, "Spin-Raw-Component-Route is not /hello/...", http.StatusInternalServerError) - return - } - - if r.Method != "GET" { - http.Error(w, "Method should be GET", http.StatusInternalServerError) - return - } - - w.Header().Set("spin-path-info", r.Header.Get("spin-path-info")) - w.Header().Set("foo", "bar") - - fmt.Fprintln(w, "Hello world!") - }) -} - -func main() {} diff --git a/http/testdata/http-tinygo/spin.toml b/http/testdata/http-tinygo/spin.toml deleted file mode 100644 index f132116d..00000000 --- a/http/testdata/http-tinygo/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "spin-http-tinygo-test" -version = "0.1.0" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." - -[[trigger.http]] -route = "/hello/..." -component = "http-test" - -[component.http-test] -source = "main.wasm" -allowed_outbound_hosts = [] -[component.http-test.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." -watch = ["**/*.go", "go.mod"] diff --git a/http/testdata/http/go.mod b/http/testdata/http/go.mod new file mode 100644 index 00000000..fb6e93c5 --- /dev/null +++ b/http/testdata/http/go.mod @@ -0,0 +1,11 @@ +module github.com/spinframework/spin-go-sdk/v3/http/testdata/http + +go 1.25.5 + +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v3/examples/kv/go.sum b/http/testdata/http/go.sum similarity index 71% rename from v3/examples/kv/go.sum rename to http/testdata/http/go.sum index 00db3b18..b5bca15f 100644 --- a/v3/examples/kv/go.sum +++ b/http/testdata/http/go.sum @@ -2,3 +2,5 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/http/testdata/http/main.go b/http/testdata/http/main.go similarity index 100% rename from v3/http/testdata/http/main.go rename to http/testdata/http/main.go diff --git a/v3/examples/http/spin.toml b/http/testdata/http/spin.toml similarity index 95% rename from v3/examples/http/spin.toml rename to http/testdata/http/spin.toml index 6e15433a..c635e8c6 100644 --- a/v3/examples/http/spin.toml +++ b/http/testdata/http/spin.toml @@ -13,4 +13,5 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" +command = "componentize-go --world http-trigger --wit-path ../../../wit build" + diff --git a/http/testdata/spin-roundtrip/Makefile b/http/testdata/spin-roundtrip/Makefile deleted file mode 100644 index b905087a..00000000 --- a/http/testdata/spin-roundtrip/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -.PHONY: build -build: - tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm . diff --git a/http/testdata/spin-roundtrip/main.go b/http/testdata/spin-roundtrip/main.go deleted file mode 100644 index d1548280..00000000 --- a/http/testdata/spin-roundtrip/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - transport := spinhttp.NewTransport() - - // or you can also do client := spinhttp.NewClient() - client := &http.Client{ - Transport: transport, - } - - resp, err := client.Get("https://example.com") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.WriteHeader(resp.StatusCode) - w.Header().Set("spin-path-info", r.Header.Get("spin-path-info")) - w.Header().Set("foo", "bar") - fmt.Fprintln(w, "Hello world!") - }) -} - -func main() {} diff --git a/http/testdata/spin-roundtrip/spin.toml b/http/testdata/spin-roundtrip/spin.toml deleted file mode 100644 index 66b38805..00000000 --- a/http/testdata/spin-roundtrip/spin.toml +++ /dev/null @@ -1,18 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "spin-roundtrip-test" -version = "0.1.0" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in (Tiny)Go." - -[[trigger.http]] -route = "/hello/..." -component = "http-roundtrip-test" - -[component.http-roundtrip-test] -source = "main.wasm" -allowed_outbound_hosts = ["https://example.com"] -[component.http-roundtrip-test.build] -command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ." -watch = ["**/*.go", "go.mod"] diff --git a/http/wasi-outbound-http.c b/http/wasi-outbound-http.c deleted file mode 100644 index f7675850..00000000 --- a/http/wasi-outbound-http.c +++ /dev/null @@ -1,166 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void wasi_outbound_http_string_set(wasi_outbound_http_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void wasi_outbound_http_string_dup(wasi_outbound_http_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void wasi_outbound_http_string_free(wasi_outbound_http_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void wasi_outbound_http_body_free(wasi_outbound_http_body_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void wasi_outbound_http_tuple2_string_string_free(wasi_outbound_http_tuple2_string_string_t *ptr) { - wasi_outbound_http_string_free(&ptr->f0); - wasi_outbound_http_string_free(&ptr->f1); -} -void wasi_outbound_http_headers_free(wasi_outbound_http_headers_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - wasi_outbound_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void wasi_outbound_http_params_free(wasi_outbound_http_params_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - wasi_outbound_http_tuple2_string_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 4); -} -void wasi_outbound_http_uri_free(wasi_outbound_http_uri_t *ptr) { - wasi_outbound_http_string_free(ptr); -} -void wasi_outbound_http_option_body_free(wasi_outbound_http_option_body_t *ptr) { - if (ptr->is_some) { - wasi_outbound_http_body_free(&ptr->val); - } -} -void wasi_outbound_http_request_free(wasi_outbound_http_request_t *ptr) { - wasi_outbound_http_uri_free(&ptr->uri); - wasi_outbound_http_headers_free(&ptr->headers); - wasi_outbound_http_params_free(&ptr->params); - wasi_outbound_http_option_body_free(&ptr->body); -} -void wasi_outbound_http_option_headers_free(wasi_outbound_http_option_headers_t *ptr) { - if (ptr->is_some) { - wasi_outbound_http_headers_free(&ptr->val); - } -} -void wasi_outbound_http_response_free(wasi_outbound_http_response_t *ptr) { - wasi_outbound_http_option_headers_free(&ptr->headers); - wasi_outbound_http_option_body_free(&ptr->body); -} -typedef struct { - bool is_err; - union { - wasi_outbound_http_response_t ok; - wasi_outbound_http_http_error_t err; - } val; -} wasi_outbound_http_expected_response_http_error_t; - -__attribute__((aligned(4))) -static uint8_t RET_AREA[32]; -__attribute__((import_module("wasi-outbound-http"), import_name("request"))) -void __wasm_import_wasi_outbound_http_request(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -wasi_outbound_http_http_error_t wasi_outbound_http_request(wasi_outbound_http_request_t *req, wasi_outbound_http_response_t *ret0) { - int32_t option; - int32_t option1; - int32_t option2; - - if (((*req).body).is_some) { - const wasi_outbound_http_body_t *payload0 = &((*req).body).val; - option = 1; - option1 = (int32_t) (*payload0).ptr; - option2 = (int32_t) (*payload0).len; - - } else { - option = 0; - option1 = 0; - option2 = 0; - - } - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_wasi_outbound_http_request((int32_t) (*req).method, (int32_t) ((*req).uri).ptr, (int32_t) ((*req).uri).len, (int32_t) ((*req).headers).ptr, (int32_t) ((*req).headers).len, (int32_t) ((*req).params).ptr, (int32_t) ((*req).params).len, option, option1, option2, ptr); - wasi_outbound_http_expected_response_http_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - wasi_outbound_http_option_headers_t option3; - switch ((int32_t) (*((uint8_t*) (ptr + 8)))) { - case 0: { - option3.is_some = false; - - break; - } - case 1: { - option3.is_some = true; - - option3.val = (wasi_outbound_http_headers_t) { (wasi_outbound_http_tuple2_string_string_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - }wasi_outbound_http_option_body_t option4; - switch ((int32_t) (*((uint8_t*) (ptr + 20)))) { - case 0: { - option4.is_some = false; - - break; - } - case 1: { - option4.is_some = true; - - option4.val = (wasi_outbound_http_body_t) { (uint8_t*)(*((int32_t*) (ptr + 24))), (size_t)(*((int32_t*) (ptr + 28))) }; - break; - } - } - expected.val.ok = (wasi_outbound_http_response_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 4)))), - option3, - option4, - }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} diff --git a/http/wasi-outbound-http.h b/http/wasi-outbound-http.h deleted file mode 100644 index ccaac543..00000000 --- a/http/wasi-outbound-http.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __BINDINGS_WASI_OUTBOUND_HTTP_H -#define __BINDINGS_WASI_OUTBOUND_HTTP_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } wasi_outbound_http_string_t; - - void wasi_outbound_http_string_set(wasi_outbound_http_string_t *ret, const char *s); - void wasi_outbound_http_string_dup(wasi_outbound_http_string_t *ret, const char *s); - void wasi_outbound_http_string_free(wasi_outbound_http_string_t *ret); - typedef struct { - uint8_t *ptr; - size_t len; - } wasi_outbound_http_body_t; - void wasi_outbound_http_body_free(wasi_outbound_http_body_t *ptr); - typedef struct { - wasi_outbound_http_string_t f0; - wasi_outbound_http_string_t f1; - } wasi_outbound_http_tuple2_string_string_t; - void wasi_outbound_http_tuple2_string_string_free(wasi_outbound_http_tuple2_string_string_t *ptr); - typedef struct { - wasi_outbound_http_tuple2_string_string_t *ptr; - size_t len; - } wasi_outbound_http_headers_t; - void wasi_outbound_http_headers_free(wasi_outbound_http_headers_t *ptr); - typedef uint8_t wasi_outbound_http_http_error_t; - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_SUCCESS 0 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_DESTINATION_NOT_ALLOWED 1 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_INVALID_URL 2 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_REQUEST_ERROR 3 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_RUNTIME_ERROR 4 - #define WASI_OUTBOUND_HTTP_HTTP_ERROR_TOO_MANY_REQUESTS 5 - typedef uint16_t wasi_outbound_http_http_status_t; - typedef uint8_t wasi_outbound_http_method_t; - #define WASI_OUTBOUND_HTTP_METHOD_GET 0 - #define WASI_OUTBOUND_HTTP_METHOD_POST 1 - #define WASI_OUTBOUND_HTTP_METHOD_PUT 2 - #define WASI_OUTBOUND_HTTP_METHOD_DELETE 3 - #define WASI_OUTBOUND_HTTP_METHOD_PATCH 4 - #define WASI_OUTBOUND_HTTP_METHOD_HEAD 5 - #define WASI_OUTBOUND_HTTP_METHOD_OPTIONS 6 - typedef struct { - wasi_outbound_http_tuple2_string_string_t *ptr; - size_t len; - } wasi_outbound_http_params_t; - void wasi_outbound_http_params_free(wasi_outbound_http_params_t *ptr); - typedef wasi_outbound_http_string_t wasi_outbound_http_uri_t; - void wasi_outbound_http_uri_free(wasi_outbound_http_uri_t *ptr); - typedef struct { - bool is_some; - wasi_outbound_http_body_t val; - } wasi_outbound_http_option_body_t; - void wasi_outbound_http_option_body_free(wasi_outbound_http_option_body_t *ptr); - typedef struct { - wasi_outbound_http_method_t method; - wasi_outbound_http_uri_t uri; - wasi_outbound_http_headers_t headers; - wasi_outbound_http_params_t params; - wasi_outbound_http_option_body_t body; - } wasi_outbound_http_request_t; - void wasi_outbound_http_request_free(wasi_outbound_http_request_t *ptr); - typedef struct { - bool is_some; - wasi_outbound_http_headers_t val; - } wasi_outbound_http_option_headers_t; - void wasi_outbound_http_option_headers_free(wasi_outbound_http_option_headers_t *ptr); - typedef struct { - wasi_outbound_http_http_status_t status; - wasi_outbound_http_option_headers_t headers; - wasi_outbound_http_option_body_t body; - } wasi_outbound_http_response_t; - void wasi_outbound_http_response_free(wasi_outbound_http_response_t *ptr); - wasi_outbound_http_http_error_t wasi_outbound_http_request(wasi_outbound_http_request_t *req, wasi_outbound_http_response_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/inbound_redis/inbound_redis.go b/inbound_redis/inbound_redis.go new file mode 100644 index 00000000..16d492ef --- /dev/null +++ b/inbound_redis/inbound_redis.go @@ -0,0 +1,25 @@ +// Package inbound_redis provides a handler for inbound Redis messages + +package inbound_redis + +import ( + incominghandler "github.com/spinframework/spin-go-sdk/v3/redis_internal/export_fermyon_spin_inbound_redis" + redis_types "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + _ "github.com/spinframework/spin-go-sdk/v3/redis_internal/wit_exports" + wit_dir "github.com/spinframework/spin-go-sdk/v3/wit" + wit "go.bytecodealliance.org/pkg/wit/types" +) + +// force wit files to be shipped with sdk dependency +var _ = wit_dir.Wit + +func Handle(handle func(message []byte) error) { + incominghandler.Exports.Handle = func(message []byte) wit.Result[wit.Unit, redis_types.Error] { + err := handle(message) + if err == nil { + return wit.Err[wit.Unit, redis_types.Error](redis_types.ErrorError) + } else { + return wit.Ok[wit.Unit, redis_types.Error](wit.Unit{}) + } + } +} diff --git a/integration_test.go b/integration_test.go index ca01722b..2356f0c3 100644 --- a/integration_test.go +++ b/integration_test.go @@ -42,7 +42,7 @@ type testSpin struct { cmd *exec.Cmd } -func startSpin(t *testing.T, dir string) *testSpin { +func startSpin(t *testing.T, dir string, extraArgs ...string) *testSpin { buildApp(t, dir) url := getFreePort(t) @@ -50,7 +50,7 @@ func startSpin(t *testing.T, dir string) *testSpin { // long timeout because... ci ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - cmd := exec.CommandContext(ctx, spinBinary, "up", "--listen", url) + cmd := exec.CommandContext(ctx, spinBinary, append([]string{"up", "--listen", url}, extraArgs...)...) cmd.Dir = dir stderr := new(bytes.Buffer) cmd.Stderr = stderr @@ -60,7 +60,7 @@ func startSpin(t *testing.T, dir string) *testSpin { } go func() { - cmd.Wait() + _ = cmd.Wait() if ctx.Err() == nil { t.Log("spin exited before the test finished:", cmd.ProcessState) t.Log("stderr:\n", stderr.String()) @@ -91,8 +91,8 @@ func buildApp(t *testing.T, dir string) { } } -func TestSpinRoundTrip(t *testing.T) { - spin := startSpin(t, "http/testdata/spin-roundtrip") +func TestHTTPTrigger(t *testing.T) { + spin := startSpin(t, "http/testdata/http") defer spin.cancel() resp := retryGet(t, spin.url+"/hello") @@ -108,15 +108,20 @@ func TestSpinRoundTrip(t *testing.T) { } // assert response body - want := "Hello world!\n" + want := "== RESPONSE ==\nHello spinframework!\nHello again spinframework!\n" got := string(b) if want != got { t.Fatalf("body is not equal: want = %q got = %q", want, got) } + + // assert response header + if resp.Header.Get("foo") != "bar" { + t.Fatal("header 'foo' was not set") + } } -func TestHTTPTriger(t *testing.T) { - spin := startSpin(t, "http/testdata/http-tinygo") +func TestKeyValue(t *testing.T) { + spin := startSpin(t, "kv/testdata/key-value") defer spin.cancel() resp := retryGet(t, spin.url+"/hello") @@ -132,26 +137,44 @@ func TestHTTPTriger(t *testing.T) { } // assert response body - want := "Hello world!\n" + want := "[\"foo\"]\n" got := string(b) if want != got { t.Fatalf("body is not equal: want = %q got = %q", want, got) } +} - // assert response header - if resp.Header.Get("foo") != "bar" { - t.Fatal("header 'foo' was not set") +func TestVariables(t *testing.T) { + spin := startSpin(t, "variables/testdata/variables") + defer spin.cancel() + + resp := retryGet(t, spin.url) + spin.cancel() + if resp.Body == nil { + t.Fatal("body is nil") + } + t.Log(resp.Status) + b, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + t.Fatal(err) + } + + // assert response body + want := "message: I'm a teapot\n" + got := string(b) + if want != got { + t.Fatalf("body is not equal: want = %q got = %q", want, got) } } -// TestBuildExamples ensures that the tinygo examples will build successfully. +// TestBuildExamples ensures that the Go examples will build successfully. func TestBuildExamples(t *testing.T) { examples, err := os.ReadDir("examples") if err != nil { t.Fatal(err) } for _, example := range examples { - example := example t.Run(example.Name(), func(t *testing.T) { t.Parallel() buildApp(t, filepath.Join("examples", example.Name())) diff --git a/internal/db/driver.go b/internal/db/driver.go index 2b3ab757..e1c99051 100644 --- a/internal/db/driver.go +++ b/internal/db/driver.go @@ -1,8 +1,6 @@ package db -import ( - "database/sql/driver" -) +import "database/sql/driver" // GlobalParameterConverter is a global valueConverter instance to convert parameters. var GlobalParameterConverter = &valueConverter{} diff --git a/v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go b/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go similarity index 100% rename from v3/internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go rename to internal/export_wasi_http_0_2_0_incoming_handler/wit_bindings.go diff --git a/v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go b/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go similarity index 80% rename from v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go rename to internal/fermyon_spin_2_0_0_key_value/wit_bindings.go index bb4c051c..116aca92 100644 --- a/v3/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_key_value import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -43,7 +43,7 @@ func resourceDropStore(handle int32) // An open key-value store type Store struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Store) TakeHandle() int32 { @@ -66,7 +66,7 @@ func (self *Store) Drop() { } func StoreFromOwnHandle(handleValue int32) *Store { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Store{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -78,7 +78,8 @@ func StoreFromOwnHandle(handleValue int32) *Store { } func StoreFromBorrowHandle(handleValue int32) *Store { - return StoreFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Store{handle} } const ( @@ -127,19 +128,19 @@ func MakeErrorOther(value string) Error { //go:wasmimport fermyon:spin/key-value@2.0.0 [static]store.open func wasm_import_static_store_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func StoreOpen(label string) wit_types.Result[*Store, Error] { +func StoreOpen(label string) witTypes.Result[*Store, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(label)) pinner.Pin(utf8) wasm_import_static_store_open(uintptr(utf8), uint32(len(label)), returnArea) - var result wit_types.Result[*Store, Error] + var result witTypes.Result[*Store, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Store, Error](StoreFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Store, Error](StoreFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -164,7 +165,7 @@ func StoreOpen(label string) wit_types.Result[*Store, Error] { panic("unreachable") } - result = wit_types.Err[*Store, Error](variant) + result = witTypes.Err[*Store, Error](variant) default: panic("unreachable") } @@ -176,31 +177,31 @@ func StoreOpen(label string) wit_types.Result[*Store, Error] { //go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get func wasm_import_method_store_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Store) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { +func (self *Store) Get(key string) witTypes.Result[witTypes.Option[[]uint8], Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_store_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Option[[]uint8], Error] + var result witTypes.Result[witTypes.Option[[]uint8], Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[[]uint8] + var option witTypes.Option[[]uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[[]uint8]() + option = witTypes.None[[]uint8]() case 1: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) - option = wit_types.Some[[]uint8](value) + option = witTypes.Some[[]uint8](value) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + result = witTypes.Ok[witTypes.Option[[]uint8], Error](option) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -225,7 +226,7 @@ func (self *Store) Get(key string) wit_types.Result[wit_types.Option[[]uint8], E panic("unreachable") } - result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + result = witTypes.Err[witTypes.Option[[]uint8], Error](variant) default: panic("unreachable") } @@ -237,21 +238,21 @@ func (self *Store) Get(key string) wit_types.Result[wit_types.Option[[]uint8], E //go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.set func wasm_import_method_store_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Store) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { +func (self *Store) Set(key string, value []uint8) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(value)) pinner.Pin(data) wasm_import_method_store_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -276,7 +277,7 @@ func (self *Store) Set(key string, value []uint8) wit_types.Result[wit_types.Uni panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -288,19 +289,19 @@ func (self *Store) Set(key string, value []uint8) wit_types.Result[wit_types.Uni //go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.delete func wasm_import_method_store_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Store) Delete(key string) wit_types.Result[wit_types.Unit, Error] { +func (self *Store) Delete(key string) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_store_delete((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -325,7 +326,7 @@ func (self *Store) Delete(key string) wit_types.Result[wit_types.Unit, Error] { panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -337,19 +338,19 @@ func (self *Store) Delete(key string) wit_types.Result[wit_types.Unit, Error] { //go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.exists func wasm_import_method_store_exists(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Store) Exists(key string) wit_types.Result[bool, Error] { +func (self *Store) Exists(key string) witTypes.Result[bool, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_store_exists((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[bool, Error] + var result witTypes.Result[bool, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) + result = witTypes.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -374,7 +375,7 @@ func (self *Store) Exists(key string) wit_types.Result[bool, Error] { panic("unreachable") } - result = wit_types.Err[bool, Error](variant) + result = witTypes.Err[bool, Error](variant) default: panic("unreachable") } @@ -386,13 +387,13 @@ func (self *Store) Exists(key string) wit_types.Result[bool, Error] { //go:wasmimport fermyon:spin/key-value@2.0.0 [method]store.get-keys func wasm_import_method_store_get_keys(arg0 int32, arg1 uintptr) -func (self *Store) GetKeys() wit_types.Result[[]string, Error] { +func (self *Store) GetKeys() witTypes.Result[[]string, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_method_store_get_keys((self).Handle(), returnArea) - var result1 wit_types.Result[[]string, Error] + var result1 witTypes.Result[[]string, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -403,7 +404,7 @@ func (self *Store) GetKeys() wit_types.Result[[]string, Error] { result = append(result, value) } - result1 = wit_types.Ok[[]string, Error](result) + result1 = witTypes.Ok[[]string, Error](result) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -428,7 +429,7 @@ func (self *Store) GetKeys() wit_types.Result[[]string, Error] { panic("unreachable") } - result1 = wit_types.Err[[]string, Error](variant) + result1 = witTypes.Err[[]string, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go b/internal/fermyon_spin_2_0_0_llm/wit_bindings.go similarity index 85% rename from v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go rename to internal/fermyon_spin_2_0_0_llm/wit_bindings.go index 0e7129da..ea3ac826 100644 --- a/v3/internal/fermyon_spin_2_0_0_llm/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_llm/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_llm import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -135,11 +135,11 @@ type EmbeddingsResult struct { //go:wasmimport fermyon:spin/llm@2.0.0 infer func wasm_import_infer(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 float32, arg7 int32, arg8 float32, arg9 int32, arg10 float32, arg11 uintptr) -func Infer(model string, prompt string, params wit_types.Option[InferencingParams]) wit_types.Result[InferencingResult, Error] { +func Infer(model string, prompt string, params witTypes.Option[InferencingParams]) witTypes.Result[InferencingResult, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (8 + 3*4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (8 + 3*4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(model)) pinner.Pin(utf8) utf80 := unsafe.Pointer(unsafe.StringData(prompt)) @@ -152,7 +152,7 @@ func Infer(model string, prompt string, params wit_types.Option[InferencingParam var option5 int32 var option6 float32 switch params.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option1 = 0 @@ -161,7 +161,7 @@ func Infer(model string, prompt string, params wit_types.Option[InferencingParam option4 = 0 option5 = 0 option6 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := params.Some() option = int32(1) @@ -175,12 +175,12 @@ func Infer(model string, prompt string, params wit_types.Option[InferencingParam panic("unreachable") } wasm_import_infer(uintptr(utf8), uint32(len(model)), uintptr(utf80), uint32(len(prompt)), option, option1, option2, option3, option4, option5, option6, returnArea) - var result wit_types.Result[InferencingResult, Error] + var result witTypes.Result[InferencingResult, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[InferencingResult, Error](InferencingResult{value, InferencingUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 3*4))))}}) + result = witTypes.Ok[InferencingResult, Error](InferencingResult{value, InferencingUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 3*4))))}}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -202,7 +202,7 @@ func Infer(model string, prompt string, params wit_types.Option[InferencingParam panic("unreachable") } - result = wit_types.Err[InferencingResult, Error](variant) + result = witTypes.Err[InferencingResult, Error](variant) default: panic("unreachable") } @@ -214,16 +214,16 @@ func Infer(model string, prompt string, params wit_types.Option[InferencingParam //go:wasmimport fermyon:spin/llm@2.0.0 generate-embeddings func wasm_import_generate_embeddings(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) -func GenerateEmbeddings(model string, text []string) wit_types.Result[EmbeddingsResult, Error] { +func GenerateEmbeddings(model string, text []string) witTypes.Result[EmbeddingsResult, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(model)) pinner.Pin(utf8) slice := text length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf80 := unsafe.Pointer(unsafe.StringData(element)) @@ -234,7 +234,7 @@ func GenerateEmbeddings(model string, text []string) wit_types.Result[Embeddings } wasm_import_generate_embeddings(uintptr(utf8), uint32(len(model)), uintptr(result), length, returnArea) - var result4 wit_types.Result[EmbeddingsResult, Error] + var result4 witTypes.Result[EmbeddingsResult, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result1 := make([][]float32, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -245,7 +245,7 @@ func GenerateEmbeddings(model string, text []string) wit_types.Result[Embeddings result1 = append(result1, value) } - result4 = wit_types.Ok[EmbeddingsResult, Error](EmbeddingsResult{result1, EmbeddingsUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))}}) + result4 = witTypes.Ok[EmbeddingsResult, Error](EmbeddingsResult{result1, EmbeddingsUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))}}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -267,7 +267,7 @@ func GenerateEmbeddings(model string, text []string) wit_types.Result[Embeddings panic("unreachable") } - result4 = wit_types.Err[EmbeddingsResult, Error](variant) + result4 = witTypes.Err[EmbeddingsResult, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go b/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go similarity index 86% rename from v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go rename to internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go index ef990edb..feb44c81 100644 --- a/v3/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_mqtt import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -98,7 +98,7 @@ type Qos = uint8 func resourceDropConnection(handle int32) type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -121,7 +121,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -133,7 +133,8 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } // The message payload. @@ -142,11 +143,11 @@ type Payload = []uint8 //go:wasmimport fermyon:spin/mqtt@2.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 int64, arg7 uintptr) -func ConnectionOpen(address string, username string, password string, keepAliveIntervalInSecs uint64) wit_types.Result[*Connection, Error] { +func ConnectionOpen(address string, username string, password string, keepAliveIntervalInSecs uint64) witTypes.Result[*Connection, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(address)) pinner.Pin(utf8) utf80 := unsafe.Pointer(unsafe.StringData(username)) @@ -154,11 +155,11 @@ func ConnectionOpen(address string, username string, password string, keepAliveI utf81 := unsafe.Pointer(unsafe.StringData(password)) pinner.Pin(utf81) wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(username)), uintptr(utf81), uint32(len(password)), int64(keepAliveIntervalInSecs), returnArea) - var result wit_types.Result[*Connection, Error] + var result witTypes.Result[*Connection, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -184,7 +185,7 @@ func ConnectionOpen(address string, username string, password string, keepAliveI panic("unreachable") } - result = wit_types.Err[*Connection, Error](variant) + result = witTypes.Err[*Connection, Error](variant) default: panic("unreachable") } @@ -196,21 +197,21 @@ func ConnectionOpen(address string, username string, password string, keepAliveI //go:wasmimport fermyon:spin/mqtt@2.0.0 [method]connection.publish func wasm_import_method_connection_publish(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 int32, arg6 uintptr) -func (self *Connection) Publish(topic string, payload []uint8, qos Qos) wit_types.Result[wit_types.Unit, Error] { +func (self *Connection) Publish(topic string, payload []uint8, qos Qos) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(topic)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(payload)) pinner.Pin(data) wasm_import_method_connection_publish((self).Handle(), uintptr(utf8), uint32(len(topic)), uintptr(data), uint32(len(payload)), int32(qos), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -236,7 +237,7 @@ func (self *Connection) Publish(topic string, payload []uint8, qos Qos) wit_type panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go b/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go similarity index 90% rename from v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go rename to internal/fermyon_spin_2_0_0_mysql/wit_bindings.go index 1b779266..2831dd3c 100644 --- a/v3/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package fermyon_spin_2_0_0_mysql import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -48,7 +48,7 @@ func resourceDropConnection(handle int32) // A connection to a MySQL database. type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -71,7 +71,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -83,25 +83,26 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } //go:wasmimport fermyon:spin/mysql@2.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { +func ConnectionOpen(address string) witTypes.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(address)) pinner.Pin(utf8) wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) - var result wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] + var result witTypes.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -134,7 +135,7 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2 panic("unreachable") } - result = wit_types.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) + result = witTypes.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) default: panic("unreachable") } @@ -146,16 +147,16 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2 //go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.query func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { +func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) witTypes.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result1, index*(8+2*4)) @@ -248,7 +249,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm } wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result13 wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] + var result13 witTypes.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result2 := make([]fermyon_spin_2_0_0_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -339,7 +340,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm result6 = append(result6, result5) } - result13 = wit_types.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) + result13 = witTypes.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) case 1: var variant12 fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -372,7 +373,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm panic("unreachable") } - result13 = wit_types.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) + result13 = witTypes.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) default: panic("unreachable") } @@ -384,16 +385,16 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm //go:wasmimport fermyon:spin/mysql@2.0.0 [method]connection.execute func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error] { +func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) witTypes.Result[witTypes.Unit, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result1, index*(8+2*4)) @@ -486,11 +487,11 @@ func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rd } wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result6 wit_types.Result[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error] + var result6 witTypes.Result[witTypes.Unit, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result6 = wit_types.Ok[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error](wit_types.Unit{}) + result6 = witTypes.Ok[witTypes.Unit, fermyon_spin_2_0_0_rdbms_types.Error](witTypes.Unit{}) case 1: var variant fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -523,7 +524,7 @@ func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rd panic("unreachable") } - result6 = wit_types.Err[wit_types.Unit, fermyon_spin_2_0_0_rdbms_types.Error](variant) + result6 = witTypes.Err[witTypes.Unit, fermyon_spin_2_0_0_rdbms_types.Error](variant) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go b/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go similarity index 91% rename from v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go rename to internal/fermyon_spin_2_0_0_postgres/wit_bindings.go index fd44f571..43e448e9 100644 --- a/v3/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package fermyon_spin_2_0_0_postgres import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -48,7 +48,7 @@ func resourceDropConnection(handle int32) // A connection to a postgres database. type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -71,7 +71,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -83,25 +83,26 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } //go:wasmimport fermyon:spin/postgres@2.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { +func ConnectionOpen(address string) witTypes.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(address)) pinner.Pin(utf8) wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) - var result wit_types.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] + var result witTypes.Result[*Connection, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -134,7 +135,7 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2 panic("unreachable") } - result = wit_types.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) + result = witTypes.Err[*Connection, fermyon_spin_2_0_0_rdbms_types.Error](variant) default: panic("unreachable") } @@ -146,16 +147,16 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, fermyon_spin_2 //go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.query func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { +func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) witTypes.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result1, index*(8+2*4)) @@ -248,7 +249,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm } wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result13 wit_types.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] + var result13 witTypes.Result[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result2 := make([]fermyon_spin_2_0_0_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -339,7 +340,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm result6 = append(result6, result5) } - result13 = wit_types.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) + result13 = witTypes.Ok[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](fermyon_spin_2_0_0_rdbms_types.RowSet{result2, result6}) case 1: var variant12 fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -372,7 +373,7 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm panic("unreachable") } - result13 = wit_types.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) + result13 = witTypes.Err[fermyon_spin_2_0_0_rdbms_types.RowSet, fermyon_spin_2_0_0_rdbms_types.Error](variant12) default: panic("unreachable") } @@ -384,16 +385,16 @@ func (self *Connection) Query(statement string, params []fermyon_spin_2_0_0_rdbm //go:wasmimport fermyon:spin/postgres@2.0.0 [method]connection.execute func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) wit_types.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] { +func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rdbms_types.ParameterValue) witTypes.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (16 + 2*4), 8)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result1, index*(8+2*4)) @@ -486,11 +487,11 @@ func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rd } wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result6 wit_types.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] + var result6 witTypes.Result[uint64, fermyon_spin_2_0_0_rdbms_types.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result6 = wit_types.Ok[uint64, fermyon_spin_2_0_0_rdbms_types.Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result6 = witTypes.Ok[uint64, fermyon_spin_2_0_0_rdbms_types.Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant fermyon_spin_2_0_0_rdbms_types.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -523,7 +524,7 @@ func (self *Connection) Execute(statement string, params []fermyon_spin_2_0_0_rd panic("unreachable") } - result6 = wit_types.Err[uint64, fermyon_spin_2_0_0_rdbms_types.Error](variant) + result6 = witTypes.Err[uint64, fermyon_spin_2_0_0_rdbms_types.Error](variant) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go b/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go similarity index 99% rename from v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go rename to internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go index aef7f08f..89d06119 100644 --- a/v3/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go b/internal/fermyon_spin_2_0_0_redis/wit_bindings.go similarity index 83% rename from v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go rename to internal/fermyon_spin_2_0_0_redis/wit_bindings.go index fca32af0..a50912a3 100644 --- a/v3/internal/fermyon_spin_2_0_0_redis/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_redis/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_redis import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -83,7 +83,7 @@ func MakeErrorOther(value string) Error { func resourceDropConnection(handle int32) type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -106,7 +106,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -118,7 +118,8 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } // The message payload. @@ -211,19 +212,19 @@ func MakeRedisResultBinary(value []uint8) RedisResult { //go:wasmimport fermyon:spin/redis@2.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { +func ConnectionOpen(address string) witTypes.Result[*Connection, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(address)) pinner.Pin(utf8) wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) - var result wit_types.Result[*Connection, Error] + var result witTypes.Result[*Connection, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -248,7 +249,7 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { panic("unreachable") } - result = wit_types.Err[*Connection, Error](variant) + result = witTypes.Err[*Connection, Error](variant) default: panic("unreachable") } @@ -260,21 +261,21 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.publish func wasm_import_method_connection_publish(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Publish(channel string, payload []uint8) wit_types.Result[wit_types.Unit, Error] { +func (self *Connection) Publish(channel string, payload []uint8) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(channel)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(payload)) pinner.Pin(data) wasm_import_method_connection_publish((self).Handle(), uintptr(utf8), uint32(len(channel)), uintptr(data), uint32(len(payload)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -299,7 +300,7 @@ func (self *Connection) Publish(channel string, payload []uint8) wit_types.Resul panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -311,31 +312,31 @@ func (self *Connection) Publish(channel string, payload []uint8) wit_types.Resul //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.get func wasm_import_method_connection_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Connection) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { +func (self *Connection) Get(key string) witTypes.Result[witTypes.Option[[]uint8], Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_connection_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Option[[]uint8], Error] + var result witTypes.Result[witTypes.Option[[]uint8], Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[[]uint8] + var option witTypes.Option[[]uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[[]uint8]() + option = witTypes.None[[]uint8]() case 1: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) - option = wit_types.Some[[]uint8](value) + option = witTypes.Some[[]uint8](value) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + result = witTypes.Ok[witTypes.Option[[]uint8], Error](option) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -360,7 +361,7 @@ func (self *Connection) Get(key string) wit_types.Result[wit_types.Option[[]uint panic("unreachable") } - result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + result = witTypes.Err[witTypes.Option[[]uint8], Error](variant) default: panic("unreachable") } @@ -372,21 +373,21 @@ func (self *Connection) Get(key string) wit_types.Result[wit_types.Option[[]uint //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.set func wasm_import_method_connection_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { +func (self *Connection) Set(key string, value []uint8) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(value)) pinner.Pin(data) wasm_import_method_connection_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -411,7 +412,7 @@ func (self *Connection) Set(key string, value []uint8) wit_types.Result[wit_type panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -423,19 +424,19 @@ func (self *Connection) Set(key string, value []uint8) wit_types.Result[wit_type //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.incr func wasm_import_method_connection_incr(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Connection) Incr(key string) wit_types.Result[int64, Error] { +func (self *Connection) Incr(key string) witTypes.Result[int64, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (16 + 2*4), 8)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_connection_incr((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[int64, Error] + var result witTypes.Result[int64, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[int64, Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + result = witTypes.Ok[int64, Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -460,7 +461,7 @@ func (self *Connection) Incr(key string) wit_types.Result[int64, Error] { panic("unreachable") } - result = wit_types.Err[int64, Error](variant) + result = witTypes.Err[int64, Error](variant) default: panic("unreachable") } @@ -472,14 +473,14 @@ func (self *Connection) Incr(key string) wit_types.Result[int64, Error] { //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.del func wasm_import_method_connection_del(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Connection) Del(keys []string) wit_types.Result[uint32, Error] { +func (self *Connection) Del(keys []string) witTypes.Result[uint32, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) slice := keys length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf8 := unsafe.Pointer(unsafe.StringData(element)) @@ -490,11 +491,11 @@ func (self *Connection) Del(keys []string) wit_types.Result[uint32, Error] { } wasm_import_method_connection_del((self).Handle(), uintptr(result), length, returnArea) - var result0 wit_types.Result[uint32, Error] + var result0 witTypes.Result[uint32, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + result0 = witTypes.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -519,7 +520,7 @@ func (self *Connection) Del(keys []string) wit_types.Result[uint32, Error] { panic("unreachable") } - result0 = wit_types.Err[uint32, Error](variant) + result0 = witTypes.Err[uint32, Error](variant) default: panic("unreachable") } @@ -531,16 +532,16 @@ func (self *Connection) Del(keys []string) wit_types.Result[uint32, Error] { //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.sadd func wasm_import_method_connection_sadd(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Sadd(key string, values []string) wit_types.Result[uint32, Error] { +func (self *Connection) Sadd(key string, values []string) witTypes.Result[uint32, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) slice := values length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf80 := unsafe.Pointer(unsafe.StringData(element)) @@ -551,11 +552,11 @@ func (self *Connection) Sadd(key string, values []string) wit_types.Result[uint3 } wasm_import_method_connection_sadd((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(result), length, returnArea) - var result1 wit_types.Result[uint32, Error] + var result1 witTypes.Result[uint32, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result1 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + result1 = witTypes.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -580,7 +581,7 @@ func (self *Connection) Sadd(key string, values []string) wit_types.Result[uint3 panic("unreachable") } - result1 = wit_types.Err[uint32, Error](variant) + result1 = witTypes.Err[uint32, Error](variant) default: panic("unreachable") } @@ -592,15 +593,15 @@ func (self *Connection) Sadd(key string, values []string) wit_types.Result[uint3 //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.smembers func wasm_import_method_connection_smembers(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Connection) Smembers(key string) wit_types.Result[[]string, Error] { +func (self *Connection) Smembers(key string) witTypes.Result[[]string, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_connection_smembers((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result1 wit_types.Result[[]string, Error] + var result1 witTypes.Result[[]string, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -611,7 +612,7 @@ func (self *Connection) Smembers(key string) wit_types.Result[[]string, Error] { result = append(result, value) } - result1 = wit_types.Ok[[]string, Error](result) + result1 = witTypes.Ok[[]string, Error](result) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -636,7 +637,7 @@ func (self *Connection) Smembers(key string) wit_types.Result[[]string, Error] { panic("unreachable") } - result1 = wit_types.Err[[]string, Error](variant) + result1 = witTypes.Err[[]string, Error](variant) default: panic("unreachable") } @@ -648,16 +649,16 @@ func (self *Connection) Smembers(key string) wit_types.Result[[]string, Error] { //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.srem func wasm_import_method_connection_srem(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Srem(key string, values []string) wit_types.Result[uint32, Error] { +func (self *Connection) Srem(key string, values []string) witTypes.Result[uint32, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) slice := values length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf80 := unsafe.Pointer(unsafe.StringData(element)) @@ -668,11 +669,11 @@ func (self *Connection) Srem(key string, values []string) wit_types.Result[uint3 } wasm_import_method_connection_srem((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(result), length, returnArea) - var result1 wit_types.Result[uint32, Error] + var result1 witTypes.Result[uint32, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result1 = wit_types.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + result1 = witTypes.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -697,7 +698,7 @@ func (self *Connection) Srem(key string, values []string) wit_types.Result[uint3 panic("unreachable") } - result1 = wit_types.Err[uint32, Error](variant) + result1 = witTypes.Err[uint32, Error](variant) default: panic("unreachable") } @@ -709,16 +710,16 @@ func (self *Connection) Srem(key string, values []string) wit_types.Result[uint3 //go:wasmimport fermyon:spin/redis@2.0.0 [method]connection.execute func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Execute(command string, arguments []RedisParameter) wit_types.Result[[]RedisResult, Error] { +func (self *Connection) Execute(command string, arguments []RedisParameter) witTypes.Result[[]RedisResult, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(command)) pinner.Pin(utf8) slice := arguments length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result, index*(8+2*4)) @@ -743,7 +744,7 @@ func (self *Connection) Execute(command string, arguments []RedisParameter) wit_ } wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(command)), uintptr(result), length, returnArea) - var result4 wit_types.Result[[]RedisResult, Error] + var result4 witTypes.Result[[]RedisResult, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result1 := make([]RedisResult, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -776,7 +777,7 @@ func (self *Connection) Execute(command string, arguments []RedisParameter) wit_ result1 = append(result1, variant) } - result4 = wit_types.Ok[[]RedisResult, Error](result1) + result4 = witTypes.Ok[[]RedisResult, Error](result1) case 1: var variant3 Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -801,7 +802,7 @@ func (self *Connection) Execute(command string, arguments []RedisParameter) wit_ panic("unreachable") } - result4 = wit_types.Err[[]RedisResult, Error](variant3) + result4 = witTypes.Err[[]RedisResult, Error](variant3) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go b/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go similarity index 90% rename from v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go rename to internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go index df77da17..0afd122a 100644 --- a/v3/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_sqlite import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -43,7 +43,7 @@ func resourceDropConnection(handle int32) // A handle to an open sqlite instance type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -66,7 +66,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -78,7 +78,8 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } const ( @@ -202,19 +203,19 @@ type QueryResult struct { //go:wasmimport fermyon:spin/sqlite@2.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func ConnectionOpen(database string) wit_types.Result[*Connection, Error] { +func ConnectionOpen(database string) witTypes.Result[*Connection, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(database)) pinner.Pin(utf8) wasm_import_static_connection_open(uintptr(utf8), uint32(len(database)), returnArea) - var result wit_types.Result[*Connection, Error] + var result witTypes.Result[*Connection, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -243,7 +244,7 @@ func ConnectionOpen(database string) wit_types.Result[*Connection, Error] { panic("unreachable") } - result = wit_types.Err[*Connection, Error](variant) + result = witTypes.Err[*Connection, Error](variant) default: panic("unreachable") } @@ -255,16 +256,16 @@ func ConnectionOpen(database string) wit_types.Result[*Connection, Error] { //go:wasmimport fermyon:spin/sqlite@2.0.0 [method]connection.execute func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Execute(statement string, parameters []Value) wit_types.Result[QueryResult, Error] { +func (self *Connection) Execute(statement string, parameters []Value) witTypes.Result[QueryResult, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := parameters length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + result := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) for index, element := range slice { base := unsafe.Add(result, index*(8+2*4)) @@ -306,7 +307,7 @@ func (self *Connection) Execute(statement string, parameters []Value) wit_types. } wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result), length, returnArea) - var result8 wit_types.Result[QueryResult, Error] + var result8 witTypes.Result[QueryResult, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result1 := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -357,7 +358,7 @@ func (self *Connection) Execute(statement string, parameters []Value) wit_types. result5 = append(result5, RowResult{result4}) } - result8 = wit_types.Ok[QueryResult, Error](QueryResult{result1, result5}) + result8 = witTypes.Ok[QueryResult, Error](QueryResult{result1, result5}) case 1: var variant7 Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -386,7 +387,7 @@ func (self *Connection) Execute(statement string, parameters []Value) wit_types. panic("unreachable") } - result8 = wit_types.Err[QueryResult, Error](variant7) + result8 = witTypes.Err[QueryResult, Error](variant7) default: panic("unreachable") } diff --git a/v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go b/internal/fermyon_spin_2_0_0_variables/wit_bindings.go similarity index 90% rename from v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go rename to internal/fermyon_spin_2_0_0_variables/wit_bindings.go index c3366a4c..b5fc6e1c 100644 --- a/v3/internal/fermyon_spin_2_0_0_variables/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_variables/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package fermyon_spin_2_0_0_variables import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -100,20 +100,20 @@ func MakeErrorOther(value string) Error { //go:wasmimport fermyon:spin/variables@2.0.0 get func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr) -func Get(name string) wit_types.Result[string, Error] { +func Get(name string) witTypes.Result[string, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) wasm_import_get(uintptr(utf8), uint32(len(name)), returnArea) - var result wit_types.Result[string, Error] + var result witTypes.Result[string, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[string, Error](value) + result = witTypes.Ok[string, Error](value) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -141,7 +141,7 @@ func Get(name string) wit_types.Result[string, Error] { panic("unreachable") } - result = wit_types.Err[string, Error](variant) + result = witTypes.Err[string, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/spin_postgres_postgres/wit_bindings.go b/internal/spin_postgres_postgres/wit_bindings.go similarity index 87% rename from v3/internal/spin_postgres_postgres/wit_bindings.go rename to internal/spin_postgres_postgres/wit_bindings.go index 2735bced..ff1abe3c 100644 --- a/v3/internal/spin_postgres_postgres/wit_bindings.go +++ b/internal/spin_postgres_postgres/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package spin_postgres_postgres import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -210,23 +210,23 @@ func (self DbValue) Binary() []uint8 { } return self.value.([]uint8) } -func (self DbValue) Date() wit_types.Tuple3[int32, uint8, uint8] { +func (self DbValue) Date() witTypes.Tuple3[int32, uint8, uint8] { if self.tag != DbValueDate { panic("tag mismatch") } - return self.value.(wit_types.Tuple3[int32, uint8, uint8]) + return self.value.(witTypes.Tuple3[int32, uint8, uint8]) } -func (self DbValue) Time() wit_types.Tuple4[uint8, uint8, uint8, uint32] { +func (self DbValue) Time() witTypes.Tuple4[uint8, uint8, uint8, uint32] { if self.tag != DbValueTime { panic("tag mismatch") } - return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint32]) + return self.value.(witTypes.Tuple4[uint8, uint8, uint8, uint32]) } -func (self DbValue) Datetime() wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { +func (self DbValue) Datetime() witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { if self.tag != DbValueDatetime { panic("tag mismatch") } - return self.value.(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) + return self.value.(witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) } func (self DbValue) Timestamp() int64 { if self.tag != DbValueTimestamp { @@ -262,13 +262,13 @@ func MakeDbValueStr(value string) DbValue { func MakeDbValueBinary(value []uint8) DbValue { return DbValue{DbValueBinary, value} } -func MakeDbValueDate(value wit_types.Tuple3[int32, uint8, uint8]) DbValue { +func MakeDbValueDate(value witTypes.Tuple3[int32, uint8, uint8]) DbValue { return DbValue{DbValueDate, value} } -func MakeDbValueTime(value wit_types.Tuple4[uint8, uint8, uint8, uint32]) DbValue { +func MakeDbValueTime(value witTypes.Tuple4[uint8, uint8, uint8, uint32]) DbValue { return DbValue{DbValueTime, value} } -func MakeDbValueDatetime(value wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) DbValue { +func MakeDbValueDatetime(value witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) DbValue { return DbValue{DbValueDatetime, value} } func MakeDbValueTimestamp(value int64) DbValue { @@ -367,23 +367,23 @@ func (self ParameterValue) Binary() []uint8 { } return self.value.([]uint8) } -func (self ParameterValue) Date() wit_types.Tuple3[int32, uint8, uint8] { +func (self ParameterValue) Date() witTypes.Tuple3[int32, uint8, uint8] { if self.tag != ParameterValueDate { panic("tag mismatch") } - return self.value.(wit_types.Tuple3[int32, uint8, uint8]) + return self.value.(witTypes.Tuple3[int32, uint8, uint8]) } -func (self ParameterValue) Time() wit_types.Tuple4[uint8, uint8, uint8, uint32] { +func (self ParameterValue) Time() witTypes.Tuple4[uint8, uint8, uint8, uint32] { if self.tag != ParameterValueTime { panic("tag mismatch") } - return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint32]) + return self.value.(witTypes.Tuple4[uint8, uint8, uint8, uint32]) } -func (self ParameterValue) Datetime() wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { +func (self ParameterValue) Datetime() witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32] { if self.tag != ParameterValueDatetime { panic("tag mismatch") } - return self.value.(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) + return self.value.(witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) } func (self ParameterValue) Timestamp() int64 { if self.tag != ParameterValueTimestamp { @@ -419,13 +419,13 @@ func MakeParameterValueStr(value string) ParameterValue { func MakeParameterValueBinary(value []uint8) ParameterValue { return ParameterValue{ParameterValueBinary, value} } -func MakeParameterValueDate(value wit_types.Tuple3[int32, uint8, uint8]) ParameterValue { +func MakeParameterValueDate(value witTypes.Tuple3[int32, uint8, uint8]) ParameterValue { return ParameterValue{ParameterValueDate, value} } -func MakeParameterValueTime(value wit_types.Tuple4[uint8, uint8, uint8, uint32]) ParameterValue { +func MakeParameterValueTime(value witTypes.Tuple4[uint8, uint8, uint8, uint32]) ParameterValue { return ParameterValue{ParameterValueTime, value} } -func MakeParameterValueDatetime(value wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) ParameterValue { +func MakeParameterValueDatetime(value witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]) ParameterValue { return ParameterValue{ParameterValueDatetime, value} } func MakeParameterValueTimestamp(value int64) ParameterValue { @@ -455,7 +455,7 @@ func resourceDropConnection(handle int32) // A connection to a postgres database. type Connection struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Connection) TakeHandle() int32 { @@ -478,7 +478,7 @@ func (self *Connection) Drop() { } func ConnectionFromOwnHandle(handleValue int32) *Connection { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Connection{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -490,25 +490,26 @@ func ConnectionFromOwnHandle(handleValue int32) *Connection { } func ConnectionFromBorrowHandle(handleValue int32) *Connection { - return ConnectionFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Connection{handle} } //go:wasmimport spin:postgres/postgres@3.0.0 [static]connection.open func wasm_import_static_connection_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { +func ConnectionOpen(address string) witTypes.Result[*Connection, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(address)) pinner.Pin(utf8) wasm_import_static_connection_open(uintptr(utf8), uint32(len(address)), returnArea) - var result wit_types.Result[*Connection, Error] + var result witTypes.Result[*Connection, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Connection, Error](ConnectionFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -541,7 +542,7 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { panic("unreachable") } - result = wit_types.Err[*Connection, Error](variant) + result = witTypes.Err[*Connection, Error](variant) default: panic("unreachable") } @@ -553,16 +554,16 @@ func ConnectionOpen(address string) wit_types.Result[*Connection, Error] { //go:wasmimport spin:postgres/postgres@3.0.0 [method]connection.query func wasm_import_method_connection_query(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Query(statement string, params []ParameterValue) wit_types.Result[RowSet, Error] { +func (self *Connection) Query(statement string, params []ParameterValue) witTypes.Result[RowSet, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*24), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*24), 8) for index, element := range slice { base := unsafe.Add(result1, index*24) @@ -666,7 +667,7 @@ func (self *Connection) Query(statement string, params []ParameterValue) wit_typ } wasm_import_method_connection_query((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result13 wit_types.Result[RowSet, Error] + var result13 witTypes.Result[RowSet, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result2 := make([]Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -725,15 +726,15 @@ func (self *Connection) Query(statement string, params []ParameterValue) wit_typ case 9: - variant = MakeDbValueDate(wit_types.Tuple3[int32, uint8, uint8]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13))))}) + variant = MakeDbValueDate(witTypes.Tuple3[int32, uint8, uint8]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13))))}) case 10: - variant = MakeDbValueTime(wit_types.Tuple4[uint8, uint8, uint8, uint32]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 9)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 10)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 12)))}) + variant = MakeDbValueTime(witTypes.Tuple4[uint8, uint8, uint8, uint32]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 9)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 10)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 12)))}) case 11: - variant = MakeDbValueDatetime(wit_types.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 14)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 15)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 16)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 20)))}) + variant = MakeDbValueDatetime(witTypes.Tuple7[int32, uint8, uint8, uint8, uint8, uint8, uint32]{*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 13)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 14)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 15)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 16)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 20)))}) case 12: @@ -757,7 +758,7 @@ func (self *Connection) Query(statement string, params []ParameterValue) wit_typ result6 = append(result6, result5) } - result13 = wit_types.Ok[RowSet, Error](RowSet{result2, result6}) + result13 = witTypes.Ok[RowSet, Error](RowSet{result2, result6}) case 1: var variant12 Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -790,7 +791,7 @@ func (self *Connection) Query(statement string, params []ParameterValue) wit_typ panic("unreachable") } - result13 = wit_types.Err[RowSet, Error](variant12) + result13 = witTypes.Err[RowSet, Error](variant12) default: panic("unreachable") } @@ -802,16 +803,16 @@ func (self *Connection) Query(statement string, params []ParameterValue) wit_typ //go:wasmimport spin:postgres/postgres@3.0.0 [method]connection.execute func wasm_import_method_connection_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Connection) Execute(statement string, params []ParameterValue) wit_types.Result[uint64, Error] { +func (self *Connection) Execute(statement string, params []ParameterValue) witTypes.Result[uint64, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (16 + 2*4), 8)) utf8 := unsafe.Pointer(unsafe.StringData(statement)) pinner.Pin(utf8) slice := params length := uint32(len(slice)) - result1 := wit_runtime.Allocate(pinner, uintptr(length*24), 8) + result1 := witRuntime.Allocate(pinner, uintptr(length*24), 8) for index, element := range slice { base := unsafe.Add(result1, index*24) @@ -915,11 +916,11 @@ func (self *Connection) Execute(statement string, params []ParameterValue) wit_t } wasm_import_method_connection_execute((self).Handle(), uintptr(utf8), uint32(len(statement)), uintptr(result1), length, returnArea) - var result6 wit_types.Result[uint64, Error] + var result6 witTypes.Result[uint64, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result6 = wit_types.Ok[uint64, Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result6 = witTypes.Ok[uint64, Error](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -952,7 +953,7 @@ func (self *Connection) Execute(statement string, params []ParameterValue) wit_t panic("unreachable") } - result6 = wit_types.Err[uint64, Error](variant) + result6 = witTypes.Err[uint64, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go b/internal/wasi_cli_0_2_0_environment/wit_bindings.go similarity index 80% rename from v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go rename to internal/wasi_cli_0_2_0_environment/wit_bindings.go index 3631afea..300ce98b 100644 --- a/v3/internal/wasi_cli_0_2_0_environment/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_environment/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package wasi_cli_0_2_0_environment import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -41,19 +41,19 @@ import ( //go:wasmimport wasi:cli/environment@0.2.0 get-environment func wasm_import_get_environment(arg0 uintptr) -func GetEnvironment() []wit_types.Tuple2[string, string] { +func GetEnvironment() []witTypes.Tuple2[string, string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_get_environment(returnArea) - result := make([]wit_types.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := make([]witTypes.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4)) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) - result = append(result, wit_types.Tuple2[string, string]{value, value0}) + result = append(result, witTypes.Tuple2[string, string]{value, value0}) } result1 := result @@ -68,7 +68,7 @@ func GetArguments() []string { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_get_arguments(returnArea) result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { @@ -86,21 +86,21 @@ func GetArguments() []string { //go:wasmimport wasi:cli/environment@0.2.0 initial-cwd func wasm_import_initial_cwd(arg0 uintptr) -func InitialCwd() wit_types.Option[string] { +func InitialCwd() witTypes.Option[string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_initial_cwd(returnArea) - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } diff --git a/v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go b/internal/wasi_cli_0_2_0_exit/wit_bindings.go similarity index 84% rename from v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go rename to internal/wasi_cli_0_2_0_exit/wit_bindings.go index 57573cfb..7ae778c6 100644 --- a/v3/internal/wasi_cli_0_2_0_exit/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_exit/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,20 +32,20 @@ package wasi_cli_0_2_0_exit import ( - "github.com/bytecodealliance/wit-bindgen/wit_types" + witTypes "go.bytecodealliance.org/pkg/wit/types" ) //go:wasmimport wasi:cli/exit@0.2.0 exit func wasm_import_exit(arg0 int32) -func Exit(status wit_types.Result[wit_types.Unit, wit_types.Unit]) { +func Exit(status witTypes.Result[witTypes.Unit, witTypes.Unit]) { var option int32 switch status.Tag() { - case wit_types.ResultOk: + case witTypes.ResultOk: option = int32(0) - case wit_types.ResultErr: + case witTypes.ResultErr: option = int32(1) default: diff --git a/v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go b/internal/wasi_cli_0_2_0_stderr/wit_bindings.go similarity index 96% rename from v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go rename to internal/wasi_cli_0_2_0_stderr/wit_bindings.go index b4189111..067fd0f3 100644 --- a/v3/internal/wasi_cli_0_2_0_stderr/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stderr/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go b/internal/wasi_cli_0_2_0_stdin/wit_bindings.go similarity index 96% rename from v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go rename to internal/wasi_cli_0_2_0_stdin/wit_bindings.go index 9ae7b915..3dda1091 100644 --- a/v3/internal/wasi_cli_0_2_0_stdin/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stdin/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go b/internal/wasi_cli_0_2_0_stdout/wit_bindings.go similarity index 96% rename from v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go rename to internal/wasi_cli_0_2_0_stdout/wit_bindings.go index ebb091aa..34b5960c 100644 --- a/v3/internal/wasi_cli_0_2_0_stdout/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stdout/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go similarity index 88% rename from v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go rename to internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go index 4be6d299..d1503012 100644 --- a/v3/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_cli_0_2_0_terminal_input import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" ) @@ -41,7 +41,7 @@ func resourceDropTerminalInput(handle int32) // The input side of a terminal. type TerminalInput struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *TerminalInput) TakeHandle() int32 { @@ -64,7 +64,7 @@ func (self *TerminalInput) Drop() { } func TerminalInputFromOwnHandle(handleValue int32) *TerminalInput { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &TerminalInput{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -76,5 +76,6 @@ func TerminalInputFromOwnHandle(handleValue int32) *TerminalInput { } func TerminalInputFromBorrowHandle(handleValue int32) *TerminalInput { - return TerminalInputFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &TerminalInput{handle} } diff --git a/v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go similarity index 88% rename from v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go rename to internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go index 7dd81bc2..44cfaa8f 100644 --- a/v3/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_cli_0_2_0_terminal_output import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" ) @@ -41,7 +41,7 @@ func resourceDropTerminalOutput(handle int32) // The output side of a terminal. type TerminalOutput struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *TerminalOutput) TakeHandle() int32 { @@ -64,7 +64,7 @@ func (self *TerminalOutput) Drop() { } func TerminalOutputFromOwnHandle(handleValue int32) *TerminalOutput { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &TerminalOutput{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -76,5 +76,6 @@ func TerminalOutputFromOwnHandle(handleValue int32) *TerminalOutput { } func TerminalOutputFromBorrowHandle(handleValue int32) *TerminalOutput { - return TerminalOutputFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &TerminalOutput{handle} } diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go similarity index 69% rename from v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go rename to internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go index 9731e23e..9f93b6b1 100644 --- a/v3/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_cli_0_2_0_terminal_stderr import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_output" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -44,20 +44,20 @@ type TerminalOutput = wasi_cli_0_2_0_terminal_output.TerminalOutput //go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr func wasm_import_get_terminal_stderr(arg0 uintptr) -func GetTerminalStderr() wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { +func GetTerminalStderr() witTypes.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_get_terminal_stderr(returnArea) - var option wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] + var option witTypes.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() + option = witTypes.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() case 1: - option = wit_types.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + option = witTypes.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go similarity index 70% rename from v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go rename to internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go index cc17659e..ef7792e7 100644 --- a/v3/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_cli_0_2_0_terminal_stdin import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_input" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -44,20 +44,20 @@ type TerminalInput = wasi_cli_0_2_0_terminal_input.TerminalInput //go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin func wasm_import_get_terminal_stdin(arg0 uintptr) -func GetTerminalStdin() wit_types.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] { +func GetTerminalStdin() witTypes.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_get_terminal_stdin(returnArea) - var option wit_types.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] + var option witTypes.Option[*wasi_cli_0_2_0_terminal_input.TerminalInput] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[*wasi_cli_0_2_0_terminal_input.TerminalInput]() + option = witTypes.None[*wasi_cli_0_2_0_terminal_input.TerminalInput]() case 1: - option = wit_types.Some[*wasi_cli_0_2_0_terminal_input.TerminalInput](wasi_cli_0_2_0_terminal_input.TerminalInputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + option = witTypes.Some[*wasi_cli_0_2_0_terminal_input.TerminalInput](wasi_cli_0_2_0_terminal_input.TerminalInputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go similarity index 69% rename from v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go rename to internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go index bfe4e631..838c92b7 100644 --- a/v3/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_cli_0_2_0_terminal_stdout import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_cli_0_2_0_terminal_output" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -44,20 +44,20 @@ type TerminalOutput = wasi_cli_0_2_0_terminal_output.TerminalOutput //go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout func wasm_import_get_terminal_stdout(arg0 uintptr) -func GetTerminalStdout() wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { +func GetTerminalStdout() witTypes.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_get_terminal_stdout(returnArea) - var option wit_types.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] + var option witTypes.Option[*wasi_cli_0_2_0_terminal_output.TerminalOutput] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() + option = witTypes.None[*wasi_cli_0_2_0_terminal_output.TerminalOutput]() case 1: - option = wit_types.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + option = witTypes.Some[*wasi_cli_0_2_0_terminal_output.TerminalOutput](wasi_cli_0_2_0_terminal_output.TerminalOutputFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go b/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go similarity index 97% rename from v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go rename to internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go index 5e7fab74..a247cf8c 100644 --- a/v3/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go +++ b/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go b/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go similarity index 89% rename from v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go rename to internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go index c1277fae..bcd85337 100644 --- a/v3/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go +++ b/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_clocks_0_2_0_wall_clock import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" "unsafe" ) @@ -50,7 +50,7 @@ func Now() Datetime { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_now(returnArea) result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} return result @@ -64,7 +64,7 @@ func Resolution() Datetime { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_resolution(returnArea) result := Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} return result diff --git a/v3/internal/wasi_config_store/wit_bindings.go b/internal/wasi_config_store/wit_bindings.go similarity index 81% rename from v3/internal/wasi_config_store/wit_bindings.go rename to internal/wasi_config_store/wit_bindings.go index 04d46033..63820e2b 100644 --- a/v3/internal/wasi_config_store/wit_bindings.go +++ b/internal/wasi_config_store/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package wasi_config_store import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -85,31 +85,31 @@ func MakeErrorIo(value string) Error { //go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr) -func Get(key string) wit_types.Result[wit_types.Option[string], Error] { +func Get(key string) witTypes.Result[witTypes.Option[string], Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Option[string], Error] + var result witTypes.Result[witTypes.Option[string], Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[string], Error](option) + result = witTypes.Ok[witTypes.Option[string], Error](option) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -127,7 +127,7 @@ func Get(key string) wit_types.Result[wit_types.Option[string], Error] { panic("unreachable") } - result = wit_types.Err[wit_types.Option[string], Error](variant) + result = witTypes.Err[witTypes.Option[string], Error](variant) default: panic("unreachable") } @@ -139,25 +139,25 @@ func Get(key string) wit_types.Result[wit_types.Option[string], Error] { //go:wasmimport wasi:config/store@0.2.0-draft-2024-09-27 get-all func wasm_import_get_all(arg0 uintptr) -func GetAll() wit_types.Result[[]wit_types.Tuple2[string, string], Error] { +func GetAll() witTypes.Result[[]witTypes.Tuple2[string, string], Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_get_all(returnArea) - var result3 wit_types.Result[[]wit_types.Tuple2[string, string], Error] + var result3 witTypes.Result[[]witTypes.Tuple2[string, string], Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result := make([]wit_types.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + result := make([]witTypes.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(4*4)) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) - result = append(result, wit_types.Tuple2[string, string]{value, value0}) + result = append(result, witTypes.Tuple2[string, string]{value, value0}) } - result3 = wit_types.Ok[[]wit_types.Tuple2[string, string], Error](result) + result3 = witTypes.Ok[[]witTypes.Tuple2[string, string], Error](result) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -175,7 +175,7 @@ func GetAll() wit_types.Result[[]wit_types.Tuple2[string, string], Error] { panic("unreachable") } - result3 = wit_types.Err[[]wit_types.Tuple2[string, string], Error](variant) + result3 = witTypes.Err[[]witTypes.Tuple2[string, string], Error](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go b/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go similarity index 72% rename from v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go rename to internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go index 97873242..ae00591b 100644 --- a/v3/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go +++ b/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_filesystem_0_2_0_preopens import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_filesystem_0_2_0_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -44,18 +44,18 @@ type Descriptor = wasi_filesystem_0_2_0_types.Descriptor //go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories func wasm_import_get_directories(arg0 uintptr) -func GetDirectories() []wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string] { +func GetDirectories() []witTypes.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_get_directories(returnArea) - result := make([]wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := make([]witTypes.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(3*4)) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) - result = append(result, wit_types.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string]{wasi_filesystem_0_2_0_types.DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(base), 0))))), value}) + result = append(result, witTypes.Tuple2[*wasi_filesystem_0_2_0_types.Descriptor, string]{wasi_filesystem_0_2_0_types.DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(base), 0))))), value}) } result0 := result diff --git a/v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go b/internal/wasi_filesystem_0_2_0_types/wit_bindings.go similarity index 68% rename from v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go rename to internal/wasi_filesystem_0_2_0_types/wit_bindings.go index a8eee20e..749b0d5f 100644 --- a/v3/internal/wasi_filesystem_0_2_0_types/wit_bindings.go +++ b/internal/wasi_filesystem_0_2_0_types/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,11 +32,11 @@ package wasi_filesystem_0_2_0_types import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_clocks_0_2_0_wall_clock" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -160,17 +160,17 @@ type DescriptorStat struct { // // If the `option` is none, the platform doesn't maintain an access // timestamp for this file. - DataAccessTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + DataAccessTimestamp witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] // Last data modification timestamp. // // If the `option` is none, the platform doesn't maintain a // modification timestamp for this file. - DataModificationTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + DataModificationTimestamp witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] // Last file status-change timestamp. // // If the `option` is none, the platform doesn't maintain a // status-change timestamp for this file. - StatusChangeTimestamp wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + StatusChangeTimestamp witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] } const ( @@ -341,7 +341,7 @@ func resourceDropDescriptor(handle int32) // directory, named pipe, special file, or other object on which filesystem // calls may be made. type Descriptor struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Descriptor) TakeHandle() int32 { @@ -364,7 +364,7 @@ func (self *Descriptor) Drop() { } func DescriptorFromOwnHandle(handleValue int32) *Descriptor { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Descriptor{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -376,7 +376,8 @@ func DescriptorFromOwnHandle(handleValue int32) *Descriptor { } func DescriptorFromBorrowHandle(handleValue int32) *Descriptor { - return DescriptorFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Descriptor{handle} } //go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream @@ -384,7 +385,7 @@ func resourceDropDirectoryEntryStream(handle int32) // A stream of directory entries. type DirectoryEntryStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *DirectoryEntryStream) TakeHandle() int32 { @@ -407,7 +408,7 @@ func (self *DirectoryEntryStream) Drop() { } func DirectoryEntryStreamFromOwnHandle(handleValue int32) *DirectoryEntryStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &DirectoryEntryStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -419,26 +420,27 @@ func DirectoryEntryStreamFromOwnHandle(handleValue int32) *DirectoryEntryStream } func DirectoryEntryStreamFromBorrowHandle(handleValue int32) *DirectoryEntryStream { - return DirectoryEntryStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &DirectoryEntryStream{handle} } //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream func wasm_import_method_descriptor_read_via_stream(arg0 int32, arg1 int64, arg2 uintptr) -func (self *Descriptor) ReadViaStream(offset uint64) wit_types.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] { +func (self *Descriptor) ReadViaStream(offset uint64) witTypes.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_descriptor_read_via_stream((self).Handle(), int64(offset), returnArea) - var result wit_types.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] + var result witTypes.Result[*wasi_io_0_2_0_streams.InputStream, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_io_0_2_0_streams.InputStream, ErrorCode](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_io_0_2_0_streams.InputStream, ErrorCode](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_io_0_2_0_streams.InputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*wasi_io_0_2_0_streams.InputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -450,20 +452,20 @@ func (self *Descriptor) ReadViaStream(offset uint64) wit_types.Result[*wasi_io_0 //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream func wasm_import_method_descriptor_write_via_stream(arg0 int32, arg1 int64, arg2 uintptr) -func (self *Descriptor) WriteViaStream(offset uint64) wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { +func (self *Descriptor) WriteViaStream(offset uint64) witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_descriptor_write_via_stream((self).Handle(), int64(offset), returnArea) - var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] + var result witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -475,20 +477,20 @@ func (self *Descriptor) WriteViaStream(offset uint64) wit_types.Result[*wasi_io_ //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream func wasm_import_method_descriptor_append_via_stream(arg0 int32, arg1 uintptr) -func (self *Descriptor) AppendViaStream() wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { +func (self *Descriptor) AppendViaStream() witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_descriptor_append_via_stream((self).Handle(), returnArea) - var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] + var result witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*wasi_io_0_2_0_streams.OutputStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -500,20 +502,20 @@ func (self *Descriptor) AppendViaStream() wit_types.Result[*wasi_io_0_2_0_stream //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise func wasm_import_method_descriptor_advise(arg0 int32, arg1 int64, arg2 int64, arg3 int32, arg4 uintptr) -func (self *Descriptor) Advise(offset uint64, length uint64, advice Advice) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) Advise(offset uint64, length uint64, advice Advice) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_advise((self).Handle(), int64(offset), int64(length), int32(advice), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -525,20 +527,20 @@ func (self *Descriptor) Advise(offset uint64, length uint64, advice Advice) wit_ //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data func wasm_import_method_descriptor_sync_data(arg0 int32, arg1 uintptr) -func (self *Descriptor) SyncData() wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) SyncData() witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_sync_data((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -550,20 +552,20 @@ func (self *Descriptor) SyncData() wit_types.Result[wit_types.Unit, ErrorCode] { //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags func wasm_import_method_descriptor_get_flags(arg0 int32, arg1 uintptr) -func (self *Descriptor) GetFlags() wit_types.Result[DescriptorFlags, ErrorCode] { +func (self *Descriptor) GetFlags() witTypes.Result[DescriptorFlags, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_get_flags((self).Handle(), returnArea) - var result wit_types.Result[DescriptorFlags, ErrorCode] + var result witTypes.Result[DescriptorFlags, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Ok[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) case 1: - result = wit_types.Err[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[DescriptorFlags, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -575,20 +577,20 @@ func (self *Descriptor) GetFlags() wit_types.Result[DescriptorFlags, ErrorCode] //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type func wasm_import_method_descriptor_get_type(arg0 int32, arg1 uintptr) -func (self *Descriptor) GetType() wit_types.Result[DescriptorType, ErrorCode] { +func (self *Descriptor) GetType() witTypes.Result[DescriptorType, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_get_type((self).Handle(), returnArea) - var result wit_types.Result[DescriptorType, ErrorCode] + var result witTypes.Result[DescriptorType, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Ok[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) case 1: - result = wit_types.Err[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[DescriptorType, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -600,20 +602,20 @@ func (self *Descriptor) GetType() wit_types.Result[DescriptorType, ErrorCode] { //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size func wasm_import_method_descriptor_set_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *Descriptor) SetSize(size uint64) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) SetSize(size uint64) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_set_size((self).Handle(), int64(size), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -625,11 +627,11 @@ func (self *Descriptor) SetSize(size uint64) wit_types.Result[wit_types.Unit, Er //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times func wasm_import_method_descriptor_set_times(arg0 int32, arg1 int32, arg2 int64, arg3 int32, arg4 int32, arg5 int64, arg6 int32, arg7 uintptr) -func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) var variant int32 var variant0 int64 var variant1 int32 @@ -683,14 +685,14 @@ func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificat panic("unreachable") } wasm_import_method_descriptor_set_times((self).Handle(), variant, variant0, variant1, variant2, variant3, variant4, returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -702,21 +704,21 @@ func (self *Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificat //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read func wasm_import_method_descriptor_read(arg0 int32, arg1 int64, arg2 int64, arg3 uintptr) -func (self *Descriptor) Read(length uint64, offset uint64) wit_types.Result[wit_types.Tuple2[[]uint8, bool], ErrorCode] { +func (self *Descriptor) Read(length uint64, offset uint64) witTypes.Result[witTypes.Tuple2[[]uint8, bool], ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_method_descriptor_read((self).Handle(), int64(length), int64(offset), returnArea) - var result wit_types.Result[wit_types.Tuple2[[]uint8, bool], ErrorCode] + var result witTypes.Result[witTypes.Tuple2[[]uint8, bool], ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[wit_types.Tuple2[[]uint8, bool], ErrorCode](wit_types.Tuple2[[]uint8, bool]{value, (uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) != 0)}) + result = witTypes.Ok[witTypes.Tuple2[[]uint8, bool], ErrorCode](witTypes.Tuple2[[]uint8, bool]{value, (uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) != 0)}) case 1: - result = wit_types.Err[wit_types.Tuple2[[]uint8, bool], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[witTypes.Tuple2[[]uint8, bool], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -728,22 +730,22 @@ func (self *Descriptor) Read(length uint64, offset uint64) wit_types.Result[wit_ //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write func wasm_import_method_descriptor_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int64, arg4 uintptr) -func (self *Descriptor) Write(buffer []uint8, offset uint64) wit_types.Result[uint64, ErrorCode] { +func (self *Descriptor) Write(buffer []uint8, offset uint64) witTypes.Result[uint64, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) data := unsafe.Pointer(unsafe.SliceData(buffer)) pinner.Pin(data) wasm_import_method_descriptor_write((self).Handle(), uintptr(data), uint32(len(buffer)), int64(offset), returnArea) - var result wit_types.Result[uint64, ErrorCode] + var result witTypes.Result[uint64, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -755,20 +757,20 @@ func (self *Descriptor) Write(buffer []uint8, offset uint64) wit_types.Result[ui //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory func wasm_import_method_descriptor_read_directory(arg0 int32, arg1 uintptr) -func (self *Descriptor) ReadDirectory() wit_types.Result[*DirectoryEntryStream, ErrorCode] { +func (self *Descriptor) ReadDirectory() witTypes.Result[*DirectoryEntryStream, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_descriptor_read_directory((self).Handle(), returnArea) - var result wit_types.Result[*DirectoryEntryStream, ErrorCode] + var result witTypes.Result[*DirectoryEntryStream, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*DirectoryEntryStream, ErrorCode](DirectoryEntryStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*DirectoryEntryStream, ErrorCode](DirectoryEntryStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*DirectoryEntryStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*DirectoryEntryStream, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -780,20 +782,20 @@ func (self *Descriptor) ReadDirectory() wit_types.Result[*DirectoryEntryStream, //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync func wasm_import_method_descriptor_sync(arg0 int32, arg1 uintptr) -func (self *Descriptor) Sync() wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) Sync() witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_descriptor_sync((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -805,22 +807,22 @@ func (self *Descriptor) Sync() wit_types.Result[wit_types.Unit, ErrorCode] { //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at func wasm_import_method_descriptor_create_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Descriptor) CreateDirectoryAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) CreateDirectoryAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_create_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -832,53 +834,53 @@ func (self *Descriptor) CreateDirectoryAt(path string) wit_types.Result[wit_type //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat func wasm_import_method_descriptor_stat(arg0 int32, arg1 uintptr) -func (self *Descriptor) Stat() wit_types.Result[DescriptorStat, ErrorCode] { +func (self *Descriptor) Stat() witTypes.Result[DescriptorStat, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 104, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 104, 8)) wasm_import_method_descriptor_stat((self).Handle(), returnArea) - var result wit_types.Result[DescriptorStat, ErrorCode] + var result witTypes.Result[DescriptorStat, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) + option = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) default: panic("unreachable") } - var option0 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option0 witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) { case 0: - option0 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option0 = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option0 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) + option0 = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) default: panic("unreachable") } - var option1 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option1 witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) { case 0: - option1 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option1 = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option1 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) + option1 = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) default: panic("unreachable") } - result = wit_types.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) + result = witTypes.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) case 1: - result = wit_types.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -890,55 +892,55 @@ func (self *Descriptor) Stat() wit_types.Result[DescriptorStat, ErrorCode] { //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at func wasm_import_method_descriptor_stat_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) -func (self *Descriptor) StatAt(pathFlags PathFlags, path string) wit_types.Result[DescriptorStat, ErrorCode] { +func (self *Descriptor) StatAt(pathFlags PathFlags, path string) witTypes.Result[DescriptorStat, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 104, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 104, 8)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_stat_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[DescriptorStat, ErrorCode] + var result witTypes.Result[DescriptorStat, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) + option = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 48)))}) default: panic("unreachable") } - var option0 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option0 witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 56))) { case 0: - option0 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option0 = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option0 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) + option0 = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 64))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 72)))}) default: panic("unreachable") } - var option1 wit_types.Option[wasi_clocks_0_2_0_wall_clock.Datetime] + var option1 witTypes.Option[wasi_clocks_0_2_0_wall_clock.Datetime] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 80))) { case 0: - option1 = wit_types.None[wasi_clocks_0_2_0_wall_clock.Datetime]() + option1 = witTypes.None[wasi_clocks_0_2_0_wall_clock.Datetime]() case 1: - option1 = wit_types.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) + option1 = witTypes.Some[wasi_clocks_0_2_0_wall_clock.Datetime](wasi_clocks_0_2_0_wall_clock.Datetime{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 88))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 96)))}) default: panic("unreachable") } - result = wit_types.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) + result = witTypes.Ok[DescriptorStat, ErrorCode](DescriptorStat{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24))), option, option0, option1}) case 1: - result = wit_types.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[DescriptorStat, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -950,11 +952,11 @@ func (self *Descriptor) StatAt(pathFlags PathFlags, path string) wit_types.Resul //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at func wasm_import_method_descriptor_set_times_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int64, arg6 int32, arg7 int32, arg8 int64, arg9 int32, arg10 uintptr) -func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) var variant int32 @@ -1010,14 +1012,14 @@ func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessT panic("unreachable") } wasm_import_method_descriptor_set_times_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), variant, variant0, variant1, variant2, variant3, variant4, returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1029,24 +1031,24 @@ func (self *Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessT //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at func wasm_import_method_descriptor_link_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 uintptr, arg6 uint32, arg7 uintptr) -func (self *Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor *Descriptor, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor *Descriptor, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) pinner.Pin(utf8) utf80 := unsafe.Pointer(unsafe.StringData(newPath)) pinner.Pin(utf80) wasm_import_method_descriptor_link_at((self).Handle(), int32(oldPathFlags), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1058,22 +1060,22 @@ func (self *Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescri //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at func wasm_import_method_descriptor_open_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 uintptr) -func (self *Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) wit_types.Result[*Descriptor, ErrorCode] { +func (self *Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) witTypes.Result[*Descriptor, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_open_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), int32(openFlags), int32(flags), returnArea) - var result wit_types.Result[*Descriptor, ErrorCode] + var result witTypes.Result[*Descriptor, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Descriptor, ErrorCode](DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Descriptor, ErrorCode](DescriptorFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*Descriptor, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*Descriptor, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -1085,23 +1087,23 @@ func (self *Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenF //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at func wasm_import_method_descriptor_readlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Descriptor) ReadlinkAt(path string) wit_types.Result[string, ErrorCode] { +func (self *Descriptor) ReadlinkAt(path string) witTypes.Result[string, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_readlink_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[string, ErrorCode] + var result witTypes.Result[string, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[string, ErrorCode](value) + result = witTypes.Ok[string, ErrorCode](value) case 1: - result = wit_types.Err[string, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[string, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -1113,22 +1115,22 @@ func (self *Descriptor) ReadlinkAt(path string) wit_types.Result[string, ErrorCo //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at func wasm_import_method_descriptor_remove_directory_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Descriptor) RemoveDirectoryAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) RemoveDirectoryAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_remove_directory_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1140,24 +1142,24 @@ func (self *Descriptor) RemoveDirectoryAt(path string) wit_types.Result[wit_type //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at func wasm_import_method_descriptor_rename_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int32, arg4 uintptr, arg5 uint32, arg6 uintptr) -func (self *Descriptor) RenameAt(oldPath string, newDescriptor *Descriptor, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) RenameAt(oldPath string, newDescriptor *Descriptor, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) pinner.Pin(utf8) utf80 := unsafe.Pointer(unsafe.StringData(newPath)) pinner.Pin(utf80) wasm_import_method_descriptor_rename_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), (newDescriptor).Handle(), uintptr(utf80), uint32(len(newPath)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1169,24 +1171,24 @@ func (self *Descriptor) RenameAt(oldPath string, newDescriptor *Descriptor, newP //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at func wasm_import_method_descriptor_symlink_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Descriptor) SymlinkAt(oldPath string, newPath string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) SymlinkAt(oldPath string, newPath string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(oldPath)) pinner.Pin(utf8) utf80 := unsafe.Pointer(unsafe.StringData(newPath)) pinner.Pin(utf80) wasm_import_method_descriptor_symlink_at((self).Handle(), uintptr(utf8), uint32(len(oldPath)), uintptr(utf80), uint32(len(newPath)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1198,22 +1200,22 @@ func (self *Descriptor) SymlinkAt(oldPath string, newPath string) wit_types.Resu //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at func wasm_import_method_descriptor_unlink_file_at(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Descriptor) UnlinkFileAt(path string) wit_types.Result[wit_types.Unit, ErrorCode] { +func (self *Descriptor) UnlinkFileAt(path string) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_unlink_file_at((self).Handle(), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -1235,20 +1237,20 @@ func (self *Descriptor) IsSameObject(other *Descriptor) bool { //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash func wasm_import_method_descriptor_metadata_hash(arg0 int32, arg1 uintptr) -func (self *Descriptor) MetadataHash() wit_types.Result[MetadataHashValue, ErrorCode] { +func (self *Descriptor) MetadataHash() witTypes.Result[MetadataHashValue, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 24, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 24, 8)) wasm_import_method_descriptor_metadata_hash((self).Handle(), returnArea) - var result wit_types.Result[MetadataHashValue, ErrorCode] + var result witTypes.Result[MetadataHashValue, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) + result = witTypes.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) case 1: - result = wit_types.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -1260,22 +1262,22 @@ func (self *Descriptor) MetadataHash() wit_types.Result[MetadataHashValue, Error //go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at func wasm_import_method_descriptor_metadata_hash_at(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) -func (self *Descriptor) MetadataHashAt(pathFlags PathFlags, path string) wit_types.Result[MetadataHashValue, ErrorCode] { +func (self *Descriptor) MetadataHashAt(pathFlags PathFlags, path string) witTypes.Result[MetadataHashValue, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 24, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 24, 8)) utf8 := unsafe.Pointer(unsafe.StringData(path)) pinner.Pin(utf8) wasm_import_method_descriptor_metadata_hash_at((self).Handle(), int32(pathFlags), uintptr(utf8), uint32(len(path)), returnArea) - var result wit_types.Result[MetadataHashValue, ErrorCode] + var result witTypes.Result[MetadataHashValue, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) + result = witTypes.Ok[MetadataHashValue, ErrorCode](MetadataHashValue{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 16)))}) case 1: - result = wit_types.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[MetadataHashValue, ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -1287,32 +1289,32 @@ func (self *Descriptor) MetadataHashAt(pathFlags PathFlags, path string) wit_typ //go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry func wasm_import_method_directory_entry_stream_read_directory_entry(arg0 int32, arg1 uintptr) -func (self *DirectoryEntryStream) ReadDirectoryEntry() wit_types.Result[wit_types.Option[DirectoryEntry], ErrorCode] { +func (self *DirectoryEntryStream) ReadDirectoryEntry() witTypes.Result[witTypes.Option[DirectoryEntry], ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) wasm_import_method_directory_entry_stream_read_directory_entry((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Option[DirectoryEntry], ErrorCode] + var result witTypes.Result[witTypes.Option[DirectoryEntry], ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[DirectoryEntry] + var option witTypes.Option[DirectoryEntry] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[DirectoryEntry]() + option = witTypes.None[DirectoryEntry]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) - option = wit_types.Some[DirectoryEntry](DirectoryEntry{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))), value}) + option = witTypes.Some[DirectoryEntry](DirectoryEntry{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4))))), value}) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[DirectoryEntry], ErrorCode](option) + result = witTypes.Ok[witTypes.Option[DirectoryEntry], ErrorCode](option) case 1: - result = wit_types.Err[wit_types.Option[DirectoryEntry], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[witTypes.Option[DirectoryEntry], ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -1324,20 +1326,20 @@ func (self *DirectoryEntryStream) ReadDirectoryEntry() wit_types.Result[wit_type //go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code func wasm_import_filesystem_error_code(arg0 int32, arg1 uintptr) -func FilesystemErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { +func FilesystemErrorCode(err *wasi_io_0_2_0_error.Error) witTypes.Option[ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_filesystem_error_code((err).Handle(), returnArea) - var option wit_types.Option[ErrorCode] + var option witTypes.Option[ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[ErrorCode]() + option = witTypes.None[ErrorCode]() case 1: - option = wit_types.Some[ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + option = witTypes.Some[ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go b/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go similarity index 95% rename from v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go rename to internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go index bda1d9fa..f62f2417 100644 --- a/v3/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go +++ b/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go b/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go similarity index 70% rename from v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go rename to internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go index ff4036af..9ebb5b3e 100644 --- a/v3/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go +++ b/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_http_0_2_0_outgoing_handler import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -47,19 +47,19 @@ type ErrorCode = wasi_http_0_2_0_types.ErrorCode //go:wasmimport wasi:http/outgoing-handler@0.2.0 handle func wasm_import_handle(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr) -func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Option[*wasi_http_0_2_0_types.RequestOptions]) wit_types.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] { +func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options witTypes.Option[*wasi_http_0_2_0_types.RequestOptions]) witTypes.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8)) var option int32 var option0 int32 switch options.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := options.Some() option = int32(1) @@ -68,11 +68,11 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op panic("unreachable") } wasm_import_handle((request).TakeHandle(), option, option0, returnArea) - var result wit_types.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] + var result witTypes.Result[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](wasi_http_0_2_0_types.FutureIncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) + result = witTypes.Ok[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](wasi_http_0_2_0_types.FutureIncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))) case 1: var variant wasi_http_0_2_0_types.ErrorCode switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -81,26 +81,26 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeDnsTimeout() case 1: - var option1 wit_types.Option[string] + var option1 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option1 = wit_types.None[string]() + option1 = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option1 = wit_types.Some[string](value) + option1 = witTypes.Some[string](value) default: panic("unreachable") } - var option2 wit_types.Option[uint16] + var option2 witTypes.Option[uint16] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option2 = wit_types.None[uint16]() + option2 = witTypes.None[uint16]() case 1: - option2 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + option2 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) default: panic("unreachable") } @@ -156,26 +156,26 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeTlsCertificateError() case 14: - var option3 wit_types.Option[uint8] + var option3 witTypes.Option[uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option3 = wit_types.None[uint8]() + option3 = witTypes.None[uint8]() case 1: - option3 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + option3 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) default: panic("unreachable") } - var option5 wit_types.Option[string] + var option5 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option5 = wit_types.None[string]() + option5 = witTypes.None[string]() case 1: value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option5 = wit_types.Some[string](value4) + option5 = witTypes.Some[string](value4) default: panic("unreachable") } @@ -191,14 +191,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestLengthRequired() case 17: - var option6 wit_types.Option[uint64] + var option6 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option6 = wit_types.None[uint64]() + option6 = witTypes.None[uint64]() case 1: - option6 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option6 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -218,14 +218,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestUriTooLong() case 21: - var option7 wit_types.Option[uint32] + var option7 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option7 = wit_types.None[uint32]() + option7 = witTypes.None[uint32]() case 1: - option7 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option7 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -233,37 +233,37 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestHeaderSectionSize(option7) case 22: - var option11 wit_types.Option[wasi_http_0_2_0_types.FieldSizePayload] + var option11 witTypes.Option[wasi_http_0_2_0_types.FieldSizePayload] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option11 = wit_types.None[wasi_http_0_2_0_types.FieldSizePayload]() + option11 = witTypes.None[wasi_http_0_2_0_types.FieldSizePayload]() case 1: - var option9 wit_types.Option[string] + var option9 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option9 = wit_types.None[string]() + option9 = witTypes.None[string]() case 1: value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option9 = wit_types.Some[string](value8) + option9 = witTypes.Some[string](value8) default: panic("unreachable") } - var option10 wit_types.Option[uint32] + var option10 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { case 0: - option10 = wit_types.None[uint32]() + option10 = witTypes.None[uint32]() case 1: - option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) default: panic("unreachable") } - option11 = wit_types.Some[wasi_http_0_2_0_types.FieldSizePayload](wasi_http_0_2_0_types.FieldSizePayload{option9, option10}) + option11 = witTypes.Some[wasi_http_0_2_0_types.FieldSizePayload](wasi_http_0_2_0_types.FieldSizePayload{option9, option10}) default: panic("unreachable") } @@ -271,14 +271,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestHeaderSize(option11) case 23: - var option12 wit_types.Option[uint32] + var option12 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option12 = wit_types.None[uint32]() + option12 = witTypes.None[uint32]() case 1: - option12 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option12 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -286,26 +286,26 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpRequestTrailerSectionSize(option12) case 24: - var option14 wit_types.Option[string] + var option14 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option14 = wit_types.None[string]() + option14 = witTypes.None[string]() case 1: value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option14 = wit_types.Some[string](value13) + option14 = witTypes.Some[string](value13) default: panic("unreachable") } - var option15 wit_types.Option[uint32] + var option15 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option15 = wit_types.None[uint32]() + option15 = witTypes.None[uint32]() case 1: - option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -317,14 +317,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseIncomplete() case 26: - var option16 wit_types.Option[uint32] + var option16 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option16 = wit_types.None[uint32]() + option16 = witTypes.None[uint32]() case 1: - option16 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option16 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -332,26 +332,26 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseHeaderSectionSize(option16) case 27: - var option18 wit_types.Option[string] + var option18 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option18 = wit_types.None[string]() + option18 = witTypes.None[string]() case 1: value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option18 = wit_types.Some[string](value17) + option18 = witTypes.Some[string](value17) default: panic("unreachable") } - var option19 wit_types.Option[uint32] + var option19 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option19 = wit_types.None[uint32]() + option19 = witTypes.None[uint32]() case 1: - option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -359,14 +359,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseHeaderSize(wasi_http_0_2_0_types.FieldSizePayload{option18, option19}) case 28: - var option20 wit_types.Option[uint64] + var option20 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option20 = wit_types.None[uint64]() + option20 = witTypes.None[uint64]() case 1: - option20 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option20 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -374,14 +374,14 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseBodySize(option20) case 29: - var option21 wit_types.Option[uint32] + var option21 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option21 = wit_types.None[uint32]() + option21 = witTypes.None[uint32]() case 1: - option21 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option21 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -389,26 +389,26 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTrailerSectionSize(option21) case 30: - var option23 wit_types.Option[string] + var option23 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option23 = wit_types.None[string]() + option23 = witTypes.None[string]() case 1: value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option23 = wit_types.Some[string](value22) + option23 = witTypes.Some[string](value22) default: panic("unreachable") } - var option24 wit_types.Option[uint32] + var option24 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option24 = wit_types.None[uint32]() + option24 = witTypes.None[uint32]() case 1: - option24 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option24 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -416,15 +416,15 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTrailerSize(wasi_http_0_2_0_types.FieldSizePayload{option23, option24}) case 31: - var option26 wit_types.Option[string] + var option26 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option26 = wit_types.None[string]() + option26 = witTypes.None[string]() case 1: value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option26 = wit_types.Some[string](value25) + option26 = witTypes.Some[string](value25) default: panic("unreachable") } @@ -432,15 +432,15 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeHttpResponseTransferCoding(option26) case 32: - var option28 wit_types.Option[string] + var option28 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option28 = wit_types.None[string]() + option28 = witTypes.None[string]() case 1: value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option28 = wit_types.Some[string](value27) + option28 = witTypes.Some[string](value27) default: panic("unreachable") } @@ -468,15 +468,15 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op variant = wasi_http_0_2_0_types.MakeErrorCodeConfigurationError() case 38: - var option30 wit_types.Option[string] + var option30 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option30 = wit_types.None[string]() + option30 = witTypes.None[string]() case 1: value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option30 = wit_types.Some[string](value29) + option30 = witTypes.Some[string](value29) default: panic("unreachable") } @@ -487,7 +487,7 @@ func Handle(request *wasi_http_0_2_0_types.OutgoingRequest, options wit_types.Op panic("unreachable") } - result = wit_types.Err[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](variant) + result = witTypes.Err[*wasi_http_0_2_0_types.FutureIncomingResponse, wasi_http_0_2_0_types.ErrorCode](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_http_0_2_0_types/wit_bindings.go b/internal/wasi_http_0_2_0_types/wit_bindings.go similarity index 76% rename from v3/internal/wasi_http_0_2_0_types/wit_bindings.go rename to internal/wasi_http_0_2_0_types/wit_bindings.go index ff5988cf..36de288d 100644 --- a/v3/internal/wasi_http_0_2_0_types/wit_bindings.go +++ b/internal/wasi_http_0_2_0_types/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,11 +32,11 @@ package wasi_http_0_2_0_types import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -143,20 +143,20 @@ func MakeSchemeOther(value string) Scheme { // Defines the case payload type for `DNS-error` above: type DnsErrorPayload struct { - Rcode wit_types.Option[string] - InfoCode wit_types.Option[uint16] + Rcode witTypes.Option[string] + InfoCode witTypes.Option[uint16] } // Defines the case payload type for `TLS-alert-received` above: type TlsAlertReceivedPayload struct { - AlertId wit_types.Option[uint8] - AlertMessage wit_types.Option[string] + AlertId witTypes.Option[uint8] + AlertMessage witTypes.Option[string] } // Defines the case payload type for `HTTP-response-{header,trailer}-size` above: type FieldSizePayload struct { - FieldName wit_types.Option[string] - FieldSize wit_types.Option[uint32] + FieldName witTypes.Option[string] + FieldSize witTypes.Option[uint32] } const ( @@ -230,29 +230,29 @@ func (self ErrorCode) TlsAlertReceived() TlsAlertReceivedPayload { } return self.value.(TlsAlertReceivedPayload) } -func (self ErrorCode) HttpRequestBodySize() wit_types.Option[uint64] { +func (self ErrorCode) HttpRequestBodySize() witTypes.Option[uint64] { if self.tag != ErrorCodeHttpRequestBodySize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint64]) + return self.value.(witTypes.Option[uint64]) } -func (self ErrorCode) HttpRequestHeaderSectionSize() wit_types.Option[uint32] { +func (self ErrorCode) HttpRequestHeaderSectionSize() witTypes.Option[uint32] { if self.tag != ErrorCodeHttpRequestHeaderSectionSize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint32]) + return self.value.(witTypes.Option[uint32]) } -func (self ErrorCode) HttpRequestHeaderSize() wit_types.Option[FieldSizePayload] { +func (self ErrorCode) HttpRequestHeaderSize() witTypes.Option[FieldSizePayload] { if self.tag != ErrorCodeHttpRequestHeaderSize { panic("tag mismatch") } - return self.value.(wit_types.Option[FieldSizePayload]) + return self.value.(witTypes.Option[FieldSizePayload]) } -func (self ErrorCode) HttpRequestTrailerSectionSize() wit_types.Option[uint32] { +func (self ErrorCode) HttpRequestTrailerSectionSize() witTypes.Option[uint32] { if self.tag != ErrorCodeHttpRequestTrailerSectionSize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint32]) + return self.value.(witTypes.Option[uint32]) } func (self ErrorCode) HttpRequestTrailerSize() FieldSizePayload { if self.tag != ErrorCodeHttpRequestTrailerSize { @@ -260,11 +260,11 @@ func (self ErrorCode) HttpRequestTrailerSize() FieldSizePayload { } return self.value.(FieldSizePayload) } -func (self ErrorCode) HttpResponseHeaderSectionSize() wit_types.Option[uint32] { +func (self ErrorCode) HttpResponseHeaderSectionSize() witTypes.Option[uint32] { if self.tag != ErrorCodeHttpResponseHeaderSectionSize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint32]) + return self.value.(witTypes.Option[uint32]) } func (self ErrorCode) HttpResponseHeaderSize() FieldSizePayload { if self.tag != ErrorCodeHttpResponseHeaderSize { @@ -272,17 +272,17 @@ func (self ErrorCode) HttpResponseHeaderSize() FieldSizePayload { } return self.value.(FieldSizePayload) } -func (self ErrorCode) HttpResponseBodySize() wit_types.Option[uint64] { +func (self ErrorCode) HttpResponseBodySize() witTypes.Option[uint64] { if self.tag != ErrorCodeHttpResponseBodySize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint64]) + return self.value.(witTypes.Option[uint64]) } -func (self ErrorCode) HttpResponseTrailerSectionSize() wit_types.Option[uint32] { +func (self ErrorCode) HttpResponseTrailerSectionSize() witTypes.Option[uint32] { if self.tag != ErrorCodeHttpResponseTrailerSectionSize { panic("tag mismatch") } - return self.value.(wit_types.Option[uint32]) + return self.value.(witTypes.Option[uint32]) } func (self ErrorCode) HttpResponseTrailerSize() FieldSizePayload { if self.tag != ErrorCodeHttpResponseTrailerSize { @@ -290,23 +290,23 @@ func (self ErrorCode) HttpResponseTrailerSize() FieldSizePayload { } return self.value.(FieldSizePayload) } -func (self ErrorCode) HttpResponseTransferCoding() wit_types.Option[string] { +func (self ErrorCode) HttpResponseTransferCoding() witTypes.Option[string] { if self.tag != ErrorCodeHttpResponseTransferCoding { panic("tag mismatch") } - return self.value.(wit_types.Option[string]) + return self.value.(witTypes.Option[string]) } -func (self ErrorCode) HttpResponseContentCoding() wit_types.Option[string] { +func (self ErrorCode) HttpResponseContentCoding() witTypes.Option[string] { if self.tag != ErrorCodeHttpResponseContentCoding { panic("tag mismatch") } - return self.value.(wit_types.Option[string]) + return self.value.(witTypes.Option[string]) } -func (self ErrorCode) InternalError() wit_types.Option[string] { +func (self ErrorCode) InternalError() witTypes.Option[string] { if self.tag != ErrorCodeInternalError { panic("tag mismatch") } - return self.value.(wit_types.Option[string]) + return self.value.(witTypes.Option[string]) } func MakeErrorCodeDnsTimeout() ErrorCode { @@ -360,7 +360,7 @@ func MakeErrorCodeHttpRequestDenied() ErrorCode { func MakeErrorCodeHttpRequestLengthRequired() ErrorCode { return ErrorCode{ErrorCodeHttpRequestLengthRequired, nil} } -func MakeErrorCodeHttpRequestBodySize(value wit_types.Option[uint64]) ErrorCode { +func MakeErrorCodeHttpRequestBodySize(value witTypes.Option[uint64]) ErrorCode { return ErrorCode{ErrorCodeHttpRequestBodySize, value} } func MakeErrorCodeHttpRequestMethodInvalid() ErrorCode { @@ -372,13 +372,13 @@ func MakeErrorCodeHttpRequestUriInvalid() ErrorCode { func MakeErrorCodeHttpRequestUriTooLong() ErrorCode { return ErrorCode{ErrorCodeHttpRequestUriTooLong, nil} } -func MakeErrorCodeHttpRequestHeaderSectionSize(value wit_types.Option[uint32]) ErrorCode { +func MakeErrorCodeHttpRequestHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode { return ErrorCode{ErrorCodeHttpRequestHeaderSectionSize, value} } -func MakeErrorCodeHttpRequestHeaderSize(value wit_types.Option[FieldSizePayload]) ErrorCode { +func MakeErrorCodeHttpRequestHeaderSize(value witTypes.Option[FieldSizePayload]) ErrorCode { return ErrorCode{ErrorCodeHttpRequestHeaderSize, value} } -func MakeErrorCodeHttpRequestTrailerSectionSize(value wit_types.Option[uint32]) ErrorCode { +func MakeErrorCodeHttpRequestTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode { return ErrorCode{ErrorCodeHttpRequestTrailerSectionSize, value} } func MakeErrorCodeHttpRequestTrailerSize(value FieldSizePayload) ErrorCode { @@ -387,25 +387,25 @@ func MakeErrorCodeHttpRequestTrailerSize(value FieldSizePayload) ErrorCode { func MakeErrorCodeHttpResponseIncomplete() ErrorCode { return ErrorCode{ErrorCodeHttpResponseIncomplete, nil} } -func MakeErrorCodeHttpResponseHeaderSectionSize(value wit_types.Option[uint32]) ErrorCode { +func MakeErrorCodeHttpResponseHeaderSectionSize(value witTypes.Option[uint32]) ErrorCode { return ErrorCode{ErrorCodeHttpResponseHeaderSectionSize, value} } func MakeErrorCodeHttpResponseHeaderSize(value FieldSizePayload) ErrorCode { return ErrorCode{ErrorCodeHttpResponseHeaderSize, value} } -func MakeErrorCodeHttpResponseBodySize(value wit_types.Option[uint64]) ErrorCode { +func MakeErrorCodeHttpResponseBodySize(value witTypes.Option[uint64]) ErrorCode { return ErrorCode{ErrorCodeHttpResponseBodySize, value} } -func MakeErrorCodeHttpResponseTrailerSectionSize(value wit_types.Option[uint32]) ErrorCode { +func MakeErrorCodeHttpResponseTrailerSectionSize(value witTypes.Option[uint32]) ErrorCode { return ErrorCode{ErrorCodeHttpResponseTrailerSectionSize, value} } func MakeErrorCodeHttpResponseTrailerSize(value FieldSizePayload) ErrorCode { return ErrorCode{ErrorCodeHttpResponseTrailerSize, value} } -func MakeErrorCodeHttpResponseTransferCoding(value wit_types.Option[string]) ErrorCode { +func MakeErrorCodeHttpResponseTransferCoding(value witTypes.Option[string]) ErrorCode { return ErrorCode{ErrorCodeHttpResponseTransferCoding, value} } -func MakeErrorCodeHttpResponseContentCoding(value wit_types.Option[string]) ErrorCode { +func MakeErrorCodeHttpResponseContentCoding(value witTypes.Option[string]) ErrorCode { return ErrorCode{ErrorCodeHttpResponseContentCoding, value} } func MakeErrorCodeHttpResponseTimeout() ErrorCode { @@ -423,7 +423,7 @@ func MakeErrorCodeLoopDetected() ErrorCode { func MakeErrorCodeConfigurationError() ErrorCode { return ErrorCode{ErrorCodeConfigurationError, nil} } -func MakeErrorCodeInternalError(value wit_types.Option[string]) ErrorCode { +func MakeErrorCodeInternalError(value witTypes.Option[string]) ErrorCode { return ErrorCode{ErrorCodeInternalError, value} } @@ -483,7 +483,7 @@ func resourceDropFields(handle int32) // immutable. In an immutable fields, the `set`, `append`, and `delete` // operations will fail with `header-error.immutable`. type Fields struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Fields) TakeHandle() int32 { @@ -506,7 +506,7 @@ func (self *Fields) Drop() { } func FieldsFromOwnHandle(handleValue int32) *Fields { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Fields{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -518,7 +518,8 @@ func FieldsFromOwnHandle(handleValue int32) *Fields { } func FieldsFromBorrowHandle(handleValue int32) *Fields { - return FieldsFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Fields{handle} } // Headers is an alias for Fields. @@ -532,7 +533,7 @@ func resourceDropIncomingRequest(handle int32) // Represents an incoming HTTP Request. type IncomingRequest struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *IncomingRequest) TakeHandle() int32 { @@ -555,7 +556,7 @@ func (self *IncomingRequest) Drop() { } func IncomingRequestFromOwnHandle(handleValue int32) *IncomingRequest { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &IncomingRequest{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -567,7 +568,8 @@ func IncomingRequestFromOwnHandle(handleValue int32) *IncomingRequest { } func IncomingRequestFromBorrowHandle(handleValue int32) *IncomingRequest { - return IncomingRequestFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &IncomingRequest{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request @@ -575,7 +577,7 @@ func resourceDropOutgoingRequest(handle int32) // Represents an outgoing HTTP Request. type OutgoingRequest struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *OutgoingRequest) TakeHandle() int32 { @@ -598,7 +600,7 @@ func (self *OutgoingRequest) Drop() { } func OutgoingRequestFromOwnHandle(handleValue int32) *OutgoingRequest { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &OutgoingRequest{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -610,7 +612,8 @@ func OutgoingRequestFromOwnHandle(handleValue int32) *OutgoingRequest { } func OutgoingRequestFromBorrowHandle(handleValue int32) *OutgoingRequest { - return OutgoingRequestFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &OutgoingRequest{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options @@ -623,7 +626,7 @@ func resourceDropRequestOptions(handle int32) // These timeouts are separate from any the user may use to bound a // blocking call to `wasi:io/poll.poll`. type RequestOptions struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *RequestOptions) TakeHandle() int32 { @@ -646,7 +649,7 @@ func (self *RequestOptions) Drop() { } func RequestOptionsFromOwnHandle(handleValue int32) *RequestOptions { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &RequestOptions{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -658,7 +661,8 @@ func RequestOptionsFromOwnHandle(handleValue int32) *RequestOptions { } func RequestOptionsFromBorrowHandle(handleValue int32) *RequestOptions { - return RequestOptionsFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &RequestOptions{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam @@ -670,7 +674,7 @@ func resourceDropResponseOutparam(handle int32) // allow a Response to be sent corresponding to the Request provided as the // other argument to `incoming-handler.handle`. type ResponseOutparam struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *ResponseOutparam) TakeHandle() int32 { @@ -693,7 +697,7 @@ func (self *ResponseOutparam) Drop() { } func ResponseOutparamFromOwnHandle(handleValue int32) *ResponseOutparam { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &ResponseOutparam{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -705,7 +709,8 @@ func ResponseOutparamFromOwnHandle(handleValue int32) *ResponseOutparam { } func ResponseOutparamFromBorrowHandle(handleValue int32) *ResponseOutparam { - return ResponseOutparamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &ResponseOutparam{handle} } // This type corresponds to the HTTP standard Status Code. @@ -716,7 +721,7 @@ func resourceDropIncomingResponse(handle int32) // Represents an incoming HTTP Response. type IncomingResponse struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *IncomingResponse) TakeHandle() int32 { @@ -739,7 +744,7 @@ func (self *IncomingResponse) Drop() { } func IncomingResponseFromOwnHandle(handleValue int32) *IncomingResponse { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &IncomingResponse{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -751,7 +756,8 @@ func IncomingResponseFromOwnHandle(handleValue int32) *IncomingResponse { } func IncomingResponseFromBorrowHandle(handleValue int32) *IncomingResponse { - return IncomingResponseFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &IncomingResponse{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body @@ -766,7 +772,7 @@ func resourceDropIncomingBody(handle int32) // and ensures that the user of this interface may only be consuming either // the body contents or waiting on trailers at any given time. type IncomingBody struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *IncomingBody) TakeHandle() int32 { @@ -789,7 +795,7 @@ func (self *IncomingBody) Drop() { } func IncomingBodyFromOwnHandle(handleValue int32) *IncomingBody { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &IncomingBody{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -801,7 +807,8 @@ func IncomingBodyFromOwnHandle(handleValue int32) *IncomingBody { } func IncomingBodyFromBorrowHandle(handleValue int32) *IncomingBody { - return IncomingBodyFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &IncomingBody{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers @@ -813,7 +820,7 @@ func resourceDropFutureTrailers(handle int32) // trailers, this future will resolve to the empty set of trailers once the // complete Request or Response body has been received. type FutureTrailers struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *FutureTrailers) TakeHandle() int32 { @@ -836,7 +843,7 @@ func (self *FutureTrailers) Drop() { } func FutureTrailersFromOwnHandle(handleValue int32) *FutureTrailers { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &FutureTrailers{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -848,7 +855,8 @@ func FutureTrailersFromOwnHandle(handleValue int32) *FutureTrailers { } func FutureTrailersFromBorrowHandle(handleValue int32) *FutureTrailers { - return FutureTrailersFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &FutureTrailers{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response @@ -856,7 +864,7 @@ func resourceDropOutgoingResponse(handle int32) // Represents an outgoing HTTP Response. type OutgoingResponse struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *OutgoingResponse) TakeHandle() int32 { @@ -879,7 +887,7 @@ func (self *OutgoingResponse) Drop() { } func OutgoingResponseFromOwnHandle(handleValue int32) *OutgoingResponse { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &OutgoingResponse{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -891,7 +899,8 @@ func OutgoingResponseFromOwnHandle(handleValue int32) *OutgoingResponse { } func OutgoingResponseFromBorrowHandle(handleValue int32) *OutgoingResponse { - return OutgoingResponseFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &OutgoingResponse{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body @@ -914,7 +923,7 @@ func resourceDropOutgoingBody(handle int32) // including: corrupting the body on the wire, aborting the associated // Request, or sending a late status code for the Response. type OutgoingBody struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *OutgoingBody) TakeHandle() int32 { @@ -937,7 +946,7 @@ func (self *OutgoingBody) Drop() { } func OutgoingBodyFromOwnHandle(handleValue int32) *OutgoingBody { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &OutgoingBody{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -949,7 +958,8 @@ func OutgoingBodyFromOwnHandle(handleValue int32) *OutgoingBody { } func OutgoingBodyFromBorrowHandle(handleValue int32) *OutgoingBody { - return OutgoingBodyFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &OutgoingBody{handle} } //go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response @@ -961,7 +971,7 @@ func resourceDropFutureIncomingResponse(handle int32) // This resource is returned by the `wasi:http/outgoing-handler` interface to // provide the HTTP Response corresponding to the sent Request. type FutureIncomingResponse struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *FutureIncomingResponse) TakeHandle() int32 { @@ -984,7 +994,7 @@ func (self *FutureIncomingResponse) Drop() { } func FutureIncomingResponseFromOwnHandle(handleValue int32) *FutureIncomingResponse { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &FutureIncomingResponse{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -996,23 +1006,24 @@ func FutureIncomingResponseFromOwnHandle(handleValue int32) *FutureIncomingRespo } func FutureIncomingResponseFromBorrowHandle(handleValue int32) *FutureIncomingResponse { - return FutureIncomingResponseFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &FutureIncomingResponse{handle} } //go:wasmimport wasi:http/types@0.2.0 http-error-code func wasm_import_http_error_code(arg0 int32, arg1 uintptr) -func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { +func HttpErrorCode(err *wasi_io_0_2_0_error.Error) witTypes.Option[ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8)) wasm_import_http_error_code((err).Handle(), returnArea) - var option29 wit_types.Option[ErrorCode] + var option29 witTypes.Option[ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option29 = wit_types.None[ErrorCode]() + option29 = witTypes.None[ErrorCode]() case 1: var variant ErrorCode switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -1021,26 +1032,26 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeDnsTimeout() case 1: - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } - var option0 wit_types.Option[uint16] + var option0 witTypes.Option[uint16] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option0 = wit_types.None[uint16]() + option0 = witTypes.None[uint16]() case 1: - option0 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) default: panic("unreachable") } @@ -1096,26 +1107,26 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeTlsCertificateError() case 14: - var option1 wit_types.Option[uint8] + var option1 witTypes.Option[uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option1 = wit_types.None[uint8]() + option1 = witTypes.None[uint8]() case 1: - option1 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) default: panic("unreachable") } - var option3 wit_types.Option[string] + var option3 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option3 = wit_types.None[string]() + option3 = witTypes.None[string]() case 1: value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option3 = wit_types.Some[string](value2) + option3 = witTypes.Some[string](value2) default: panic("unreachable") } @@ -1131,14 +1142,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpRequestLengthRequired() case 17: - var option4 wit_types.Option[uint64] + var option4 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option4 = wit_types.None[uint64]() + option4 = witTypes.None[uint64]() case 1: - option4 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -1158,14 +1169,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpRequestUriTooLong() case 21: - var option5 wit_types.Option[uint32] + var option5 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option5 = wit_types.None[uint32]() + option5 = witTypes.None[uint32]() case 1: - option5 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -1173,37 +1184,37 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5) case 22: - var option9 wit_types.Option[FieldSizePayload] + var option9 witTypes.Option[FieldSizePayload] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option9 = wit_types.None[FieldSizePayload]() + option9 = witTypes.None[FieldSizePayload]() case 1: - var option7 wit_types.Option[string] + var option7 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option7 = wit_types.None[string]() + option7 = witTypes.None[string]() case 1: value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option7 = wit_types.Some[string](value6) + option7 = witTypes.Some[string](value6) default: panic("unreachable") } - var option8 wit_types.Option[uint32] + var option8 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { case 0: - option8 = wit_types.None[uint32]() + option8 = witTypes.None[uint32]() case 1: - option8 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) default: panic("unreachable") } - option9 = wit_types.Some[FieldSizePayload](FieldSizePayload{option7, option8}) + option9 = witTypes.Some[FieldSizePayload](FieldSizePayload{option7, option8}) default: panic("unreachable") } @@ -1211,14 +1222,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpRequestHeaderSize(option9) case 23: - var option10 wit_types.Option[uint32] + var option10 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option10 = wit_types.None[uint32]() + option10 = witTypes.None[uint32]() case 1: - option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -1226,26 +1237,26 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10) case 24: - var option12 wit_types.Option[string] + var option12 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option12 = wit_types.None[string]() + option12 = witTypes.None[string]() case 1: value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option12 = wit_types.Some[string](value11) + option12 = witTypes.Some[string](value11) default: panic("unreachable") } - var option13 wit_types.Option[uint32] + var option13 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option13 = wit_types.None[uint32]() + option13 = witTypes.None[uint32]() case 1: - option13 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -1257,14 +1268,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseIncomplete() case 26: - var option14 wit_types.Option[uint32] + var option14 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option14 = wit_types.None[uint32]() + option14 = witTypes.None[uint32]() case 1: - option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -1272,26 +1283,26 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14) case 27: - var option16 wit_types.Option[string] + var option16 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option16 = wit_types.None[string]() + option16 = witTypes.None[string]() case 1: value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option16 = wit_types.Some[string](value15) + option16 = witTypes.Some[string](value15) default: panic("unreachable") } - var option17 wit_types.Option[uint32] + var option17 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option17 = wit_types.None[uint32]() + option17 = witTypes.None[uint32]() case 1: - option17 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -1299,14 +1310,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17}) case 28: - var option18 wit_types.Option[uint64] + var option18 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option18 = wit_types.None[uint64]() + option18 = witTypes.None[uint64]() case 1: - option18 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -1314,14 +1325,14 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseBodySize(option18) case 29: - var option19 wit_types.Option[uint32] + var option19 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option19 = wit_types.None[uint32]() + option19 = witTypes.None[uint32]() case 1: - option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -1329,26 +1340,26 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19) case 30: - var option21 wit_types.Option[string] + var option21 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option21 = wit_types.None[string]() + option21 = witTypes.None[string]() case 1: value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option21 = wit_types.Some[string](value20) + option21 = witTypes.Some[string](value20) default: panic("unreachable") } - var option22 wit_types.Option[uint32] + var option22 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option22 = wit_types.None[uint32]() + option22 = witTypes.None[uint32]() case 1: - option22 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -1356,15 +1367,15 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22}) case 31: - var option24 wit_types.Option[string] + var option24 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option24 = wit_types.None[string]() + option24 = witTypes.None[string]() case 1: value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option24 = wit_types.Some[string](value23) + option24 = witTypes.Some[string](value23) default: panic("unreachable") } @@ -1372,15 +1383,15 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeHttpResponseTransferCoding(option24) case 32: - var option26 wit_types.Option[string] + var option26 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option26 = wit_types.None[string]() + option26 = witTypes.None[string]() case 1: value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option26 = wit_types.Some[string](value25) + option26 = witTypes.Some[string](value25) default: panic("unreachable") } @@ -1408,15 +1419,15 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { variant = MakeErrorCodeConfigurationError() case 38: - var option28 wit_types.Option[string] + var option28 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option28 = wit_types.None[string]() + option28 = witTypes.None[string]() case 1: value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option28 = wit_types.Some[string](value27) + option28 = witTypes.Some[string](value27) default: panic("unreachable") } @@ -1427,7 +1438,7 @@ func HttpErrorCode(err *wasi_io_0_2_0_error.Error) wit_types.Option[ErrorCode] { panic("unreachable") } - option29 = wit_types.Some[ErrorCode](variant) + option29 = witTypes.Some[ErrorCode](variant) default: panic("unreachable") } @@ -1449,14 +1460,14 @@ func MakeFields() *Fields { //go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list func wasm_import_static_fields_from_list(arg0 uintptr, arg1 uint32, arg2 uintptr) -func FieldsFromList(entries []wit_types.Tuple2[string, []uint8]) wit_types.Result[*Fields, HeaderError] { +func FieldsFromList(entries []witTypes.Tuple2[string, []uint8]) witTypes.Result[*Fields, HeaderError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) slice := entries length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(4*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(4*4)) utf8 := unsafe.Pointer(unsafe.StringData((element).F0)) @@ -1471,11 +1482,11 @@ func FieldsFromList(entries []wit_types.Tuple2[string, []uint8]) wit_types.Resul } wasm_import_static_fields_from_list(uintptr(result), length, returnArea) - var result0 wit_types.Result[*Fields, HeaderError] + var result0 witTypes.Result[*Fields, HeaderError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[*Fields, HeaderError](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result0 = witTypes.Ok[*Fields, HeaderError](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant HeaderError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -1495,7 +1506,7 @@ func FieldsFromList(entries []wit_types.Tuple2[string, []uint8]) wit_types.Resul panic("unreachable") } - result0 = wit_types.Err[*Fields, HeaderError](variant) + result0 = witTypes.Err[*Fields, HeaderError](variant) default: panic("unreachable") } @@ -1511,7 +1522,7 @@ func (self *Fields) Get(name string) [][]uint8 { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) wasm_import_method_fields_get((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea) @@ -1545,16 +1556,16 @@ func (self *Fields) Has(name string) bool { //go:wasmimport wasi:http/types@0.2.0 [method]fields.set func wasm_import_method_fields_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Fields) Set(name string, value [][]uint8) wit_types.Result[wit_types.Unit, HeaderError] { +func (self *Fields) Set(name string, value [][]uint8) witTypes.Result[witTypes.Unit, HeaderError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) slice := value length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) data := unsafe.Pointer(unsafe.SliceData(element)) @@ -1565,11 +1576,11 @@ func (self *Fields) Set(name string, value [][]uint8) wit_types.Result[wit_types } wasm_import_method_fields_set((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(result), length, returnArea) - var result0 wit_types.Result[wit_types.Unit, HeaderError] + var result0 witTypes.Result[witTypes.Unit, HeaderError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + result0 = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{}) case 1: var variant HeaderError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { @@ -1589,7 +1600,7 @@ func (self *Fields) Set(name string, value [][]uint8) wit_types.Result[wit_types panic("unreachable") } - result0 = wit_types.Err[wit_types.Unit, HeaderError](variant) + result0 = witTypes.Err[witTypes.Unit, HeaderError](variant) default: panic("unreachable") } @@ -1601,19 +1612,19 @@ func (self *Fields) Set(name string, value [][]uint8) wit_types.Result[wit_types //go:wasmimport wasi:http/types@0.2.0 [method]fields.delete func wasm_import_method_fields_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Fields) Delete(name string) wit_types.Result[wit_types.Unit, HeaderError] { +func (self *Fields) Delete(name string) witTypes.Result[witTypes.Unit, HeaderError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) wasm_import_method_fields_delete((self).Handle(), uintptr(utf8), uint32(len(name)), returnArea) - var result wit_types.Result[wit_types.Unit, HeaderError] + var result witTypes.Result[witTypes.Unit, HeaderError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{}) case 1: var variant HeaderError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { @@ -1633,7 +1644,7 @@ func (self *Fields) Delete(name string) wit_types.Result[wit_types.Unit, HeaderE panic("unreachable") } - result = wit_types.Err[wit_types.Unit, HeaderError](variant) + result = witTypes.Err[witTypes.Unit, HeaderError](variant) default: panic("unreachable") } @@ -1645,21 +1656,21 @@ func (self *Fields) Delete(name string) wit_types.Result[wit_types.Unit, HeaderE //go:wasmimport wasi:http/types@0.2.0 [method]fields.append func wasm_import_method_fields_append(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Fields) Append(name string, value []uint8) wit_types.Result[wit_types.Unit, HeaderError] { +func (self *Fields) Append(name string, value []uint8) witTypes.Result[witTypes.Unit, HeaderError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(value)) pinner.Pin(data) wasm_import_method_fields_append((self).Handle(), uintptr(utf8), uint32(len(name)), uintptr(data), uint32(len(value)), returnArea) - var result wit_types.Result[wit_types.Unit, HeaderError] + var result witTypes.Result[witTypes.Unit, HeaderError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, HeaderError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, HeaderError](witTypes.Unit{}) case 1: var variant HeaderError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) { @@ -1679,7 +1690,7 @@ func (self *Fields) Append(name string, value []uint8) wit_types.Result[wit_type panic("unreachable") } - result = wit_types.Err[wit_types.Unit, HeaderError](variant) + result = witTypes.Err[witTypes.Unit, HeaderError](variant) default: panic("unreachable") } @@ -1691,19 +1702,19 @@ func (self *Fields) Append(name string, value []uint8) wit_types.Result[wit_type //go:wasmimport wasi:http/types@0.2.0 [method]fields.entries func wasm_import_method_fields_entries(arg0 int32, arg1 uintptr) -func (self *Fields) Entries() []wit_types.Tuple2[string, []uint8] { +func (self *Fields) Entries() []witTypes.Tuple2[string, []uint8] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_method_fields_entries((self).Handle(), returnArea) - result := make([]wit_types.Tuple2[string, []uint8], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) + result := make([]witTypes.Tuple2[string, []uint8], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))); index++ { base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0)))), index*(4*4)) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) - result = append(result, wit_types.Tuple2[string, []uint8]{value, value0}) + result = append(result, witTypes.Tuple2[string, []uint8]{value, value0}) } result1 := result @@ -1728,7 +1739,7 @@ func (self *IncomingRequest) Method() Method { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_incoming_request_method((self).Handle(), returnArea) var variant Method switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { @@ -1784,21 +1795,21 @@ func (self *IncomingRequest) Method() Method { //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query func wasm_import_method_incoming_request_path_with_query(arg0 int32, arg1 uintptr) -func (self *IncomingRequest) PathWithQuery() wit_types.Option[string] { +func (self *IncomingRequest) PathWithQuery() witTypes.Option[string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_incoming_request_path_with_query((self).Handle(), returnArea) - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } @@ -1810,17 +1821,17 @@ func (self *IncomingRequest) PathWithQuery() wit_types.Option[string] { //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme func wasm_import_method_incoming_request_scheme(arg0 int32, arg1 uintptr) -func (self *IncomingRequest) Scheme() wit_types.Option[Scheme] { +func (self *IncomingRequest) Scheme() witTypes.Option[Scheme] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_method_incoming_request_scheme((self).Handle(), returnArea) - var option wit_types.Option[Scheme] + var option witTypes.Option[Scheme] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[Scheme]() + option = witTypes.None[Scheme]() case 1: var variant Scheme switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -1841,7 +1852,7 @@ func (self *IncomingRequest) Scheme() wit_types.Option[Scheme] { panic("unreachable") } - option = wit_types.Some[Scheme](variant) + option = witTypes.Some[Scheme](variant) default: panic("unreachable") } @@ -1853,21 +1864,21 @@ func (self *IncomingRequest) Scheme() wit_types.Option[Scheme] { //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority func wasm_import_method_incoming_request_authority(arg0 int32, arg1 uintptr) -func (self *IncomingRequest) Authority() wit_types.Option[string] { +func (self *IncomingRequest) Authority() witTypes.Option[string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_incoming_request_authority((self).Handle(), returnArea) - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } @@ -1889,20 +1900,20 @@ func (self *IncomingRequest) Headers() *Fields { //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume func wasm_import_method_incoming_request_consume(arg0 int32, arg1 uintptr) -func (self *IncomingRequest) Consume() wit_types.Result[*IncomingBody, wit_types.Unit] { +func (self *IncomingRequest) Consume() witTypes.Result[*IncomingBody, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_incoming_request_consume((self).Handle(), returnArea) - var result wit_types.Result[*IncomingBody, wit_types.Unit] + var result witTypes.Result[*IncomingBody, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*IncomingBody, wit_types.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*IncomingBody, witTypes.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*IncomingBody, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*IncomingBody, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -1924,20 +1935,20 @@ func MakeOutgoingRequest(headers *Fields) *OutgoingRequest { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body func wasm_import_method_outgoing_request_body(arg0 int32, arg1 uintptr) -func (self *OutgoingRequest) Body() wit_types.Result[*OutgoingBody, wit_types.Unit] { +func (self *OutgoingRequest) Body() witTypes.Result[*OutgoingBody, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_outgoing_request_body((self).Handle(), returnArea) - var result wit_types.Result[*OutgoingBody, wit_types.Unit] + var result witTypes.Result[*OutgoingBody, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*OutgoingBody, wit_types.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*OutgoingBody, witTypes.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*OutgoingBody, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*OutgoingBody, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -1953,7 +1964,7 @@ func (self *OutgoingRequest) Method() Method { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_outgoing_request_method((self).Handle(), returnArea) var variant Method switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { @@ -2009,7 +2020,7 @@ func (self *OutgoingRequest) Method() Method { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method func wasm_import_method_outgoing_request_set_method(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 -func (self *OutgoingRequest) SetMethod(method Method) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *OutgoingRequest) SetMethod(method Method) witTypes.Result[witTypes.Unit, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() @@ -2084,14 +2095,14 @@ func (self *OutgoingRequest) SetMethod(method Method) wit_types.Result[wit_types panic("unreachable") } result := wasm_import_method_outgoing_request_set_method((self).Handle(), variant, variant0, variant1) - var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result2 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2102,21 +2113,21 @@ func (self *OutgoingRequest) SetMethod(method Method) wit_types.Result[wit_types //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query func wasm_import_method_outgoing_request_path_with_query(arg0 int32, arg1 uintptr) -func (self *OutgoingRequest) PathWithQuery() wit_types.Option[string] { +func (self *OutgoingRequest) PathWithQuery() witTypes.Option[string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_outgoing_request_path_with_query((self).Handle(), returnArea) - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } @@ -2128,7 +2139,7 @@ func (self *OutgoingRequest) PathWithQuery() wit_types.Option[string] { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query func wasm_import_method_outgoing_request_set_path_with_query(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 -func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery wit_types.Option[string]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() @@ -2136,12 +2147,12 @@ func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery wit_types.Option[str var option0 uintptr var option1 uint32 switch pathWithQuery.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 option1 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := pathWithQuery.Some() utf8 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf8) @@ -2153,14 +2164,14 @@ func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery wit_types.Option[str panic("unreachable") } result := wasm_import_method_outgoing_request_set_path_with_query((self).Handle(), option, option0, option1) - var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result2 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2171,17 +2182,17 @@ func (self *OutgoingRequest) SetPathWithQuery(pathWithQuery wit_types.Option[str //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme func wasm_import_method_outgoing_request_scheme(arg0 int32, arg1 uintptr) -func (self *OutgoingRequest) Scheme() wit_types.Option[Scheme] { +func (self *OutgoingRequest) Scheme() witTypes.Option[Scheme] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_method_outgoing_request_scheme((self).Handle(), returnArea) - var option wit_types.Option[Scheme] + var option witTypes.Option[Scheme] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[Scheme]() + option = witTypes.None[Scheme]() case 1: var variant Scheme switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -2202,7 +2213,7 @@ func (self *OutgoingRequest) Scheme() wit_types.Option[Scheme] { panic("unreachable") } - option = wit_types.Some[Scheme](variant) + option = witTypes.Some[Scheme](variant) default: panic("unreachable") } @@ -2214,7 +2225,7 @@ func (self *OutgoingRequest) Scheme() wit_types.Option[Scheme] { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme func wasm_import_method_outgoing_request_set_scheme(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr, arg4 uint32) int32 -func (self *OutgoingRequest) SetScheme(scheme wit_types.Option[Scheme]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *OutgoingRequest) SetScheme(scheme witTypes.Option[Scheme]) witTypes.Result[witTypes.Unit, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() @@ -2223,13 +2234,13 @@ func (self *OutgoingRequest) SetScheme(scheme wit_types.Option[Scheme]) wit_type var option3 uintptr var option4 uint32 switch scheme.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option2 = 0 option3 = 0 option4 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := scheme.Some() var variant int32 var variant0 uintptr @@ -2268,14 +2279,14 @@ func (self *OutgoingRequest) SetScheme(scheme wit_types.Option[Scheme]) wit_type panic("unreachable") } result := wasm_import_method_outgoing_request_set_scheme((self).Handle(), option, option2, option3, option4) - var result5 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result5 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result5 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result5 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result5 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result5 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2286,21 +2297,21 @@ func (self *OutgoingRequest) SetScheme(scheme wit_types.Option[Scheme]) wit_type //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority func wasm_import_method_outgoing_request_authority(arg0 int32, arg1 uintptr) -func (self *OutgoingRequest) Authority() wit_types.Option[string] { +func (self *OutgoingRequest) Authority() witTypes.Option[string] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_outgoing_request_authority((self).Handle(), returnArea) - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } @@ -2312,7 +2323,7 @@ func (self *OutgoingRequest) Authority() wit_types.Option[string] { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority func wasm_import_method_outgoing_request_set_authority(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32) int32 -func (self *OutgoingRequest) SetAuthority(authority wit_types.Option[string]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *OutgoingRequest) SetAuthority(authority witTypes.Option[string]) witTypes.Result[witTypes.Unit, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() @@ -2320,12 +2331,12 @@ func (self *OutgoingRequest) SetAuthority(authority wit_types.Option[string]) wi var option0 uintptr var option1 uint32 switch authority.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 option1 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := authority.Some() utf8 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf8) @@ -2337,14 +2348,14 @@ func (self *OutgoingRequest) SetAuthority(authority wit_types.Option[string]) wi panic("unreachable") } result := wasm_import_method_outgoing_request_set_authority((self).Handle(), option, option0, option1) - var result2 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result2 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result2 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result2 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result2 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2375,20 +2386,20 @@ func MakeRequestOptions() *RequestOptions { //go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout func wasm_import_method_request_options_connect_timeout(arg0 int32, arg1 uintptr) -func (self *RequestOptions) ConnectTimeout() wit_types.Option[uint64] { +func (self *RequestOptions) ConnectTimeout() witTypes.Option[uint64] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_request_options_connect_timeout((self).Handle(), returnArea) - var option wit_types.Option[uint64] + var option witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[uint64]() + option = witTypes.None[uint64]() case 1: - option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) default: panic("unreachable") } @@ -2400,16 +2411,16 @@ func (self *RequestOptions) ConnectTimeout() wit_types.Option[uint64] { //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout func wasm_import_method_request_options_set_connect_timeout(arg0 int32, arg1 int32, arg2 int64) int32 -func (self *RequestOptions) SetConnectTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *RequestOptions) SetConnectTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] { var option int32 var option0 int64 switch duration.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := duration.Some() option = int32(1) @@ -2418,14 +2429,14 @@ func (self *RequestOptions) SetConnectTimeout(duration wit_types.Option[uint64]) panic("unreachable") } result := wasm_import_method_request_options_set_connect_timeout((self).Handle(), option, option0) - var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result1 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2436,20 +2447,20 @@ func (self *RequestOptions) SetConnectTimeout(duration wit_types.Option[uint64]) //go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout func wasm_import_method_request_options_first_byte_timeout(arg0 int32, arg1 uintptr) -func (self *RequestOptions) FirstByteTimeout() wit_types.Option[uint64] { +func (self *RequestOptions) FirstByteTimeout() witTypes.Option[uint64] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_request_options_first_byte_timeout((self).Handle(), returnArea) - var option wit_types.Option[uint64] + var option witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[uint64]() + option = witTypes.None[uint64]() case 1: - option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) default: panic("unreachable") } @@ -2461,16 +2472,16 @@ func (self *RequestOptions) FirstByteTimeout() wit_types.Option[uint64] { //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout func wasm_import_method_request_options_set_first_byte_timeout(arg0 int32, arg1 int32, arg2 int64) int32 -func (self *RequestOptions) SetFirstByteTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *RequestOptions) SetFirstByteTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] { var option int32 var option0 int64 switch duration.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := duration.Some() option = int32(1) @@ -2479,14 +2490,14 @@ func (self *RequestOptions) SetFirstByteTimeout(duration wit_types.Option[uint64 panic("unreachable") } result := wasm_import_method_request_options_set_first_byte_timeout((self).Handle(), option, option0) - var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result1 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2497,20 +2508,20 @@ func (self *RequestOptions) SetFirstByteTimeout(duration wit_types.Option[uint64 //go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout func wasm_import_method_request_options_between_bytes_timeout(arg0 int32, arg1 uintptr) -func (self *RequestOptions) BetweenBytesTimeout() wit_types.Option[uint64] { +func (self *RequestOptions) BetweenBytesTimeout() witTypes.Option[uint64] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_request_options_between_bytes_timeout((self).Handle(), returnArea) - var option wit_types.Option[uint64] + var option witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option = wit_types.None[uint64]() + option = witTypes.None[uint64]() case 1: - option = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + option = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) default: panic("unreachable") } @@ -2522,16 +2533,16 @@ func (self *RequestOptions) BetweenBytesTimeout() wit_types.Option[uint64] { //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout func wasm_import_method_request_options_set_between_bytes_timeout(arg0 int32, arg1 int32, arg2 int64) int32 -func (self *RequestOptions) SetBetweenBytesTimeout(duration wit_types.Option[uint64]) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *RequestOptions) SetBetweenBytesTimeout(duration witTypes.Option[uint64]) witTypes.Result[witTypes.Unit, witTypes.Unit] { var option int32 var option0 int64 switch duration.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := duration.Some() option = int32(1) @@ -2540,14 +2551,14 @@ func (self *RequestOptions) SetBetweenBytesTimeout(duration wit_types.Option[uin panic("unreachable") } result := wasm_import_method_request_options_set_between_bytes_timeout((self).Handle(), option, option0) - var result1 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result1 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result1 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result1 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result1 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -2558,7 +2569,7 @@ func (self *RequestOptions) SetBetweenBytesTimeout(duration wit_types.Option[uin //go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set func wasm_import_static_response_outparam_set(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int64, arg5 uintptr, arg6 uintptr, arg7 uint32, arg8 int32) -func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*OutgoingResponse, ErrorCode]) { +func ResponseOutparamSet(param *ResponseOutparam, response witTypes.Result[*OutgoingResponse, ErrorCode]) { pinner := &runtime.Pinner{} defer pinner.Unpin() @@ -2571,7 +2582,7 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option76 uint32 var option77 int32 switch response.Tag() { - case wit_types.ResultOk: + case witTypes.ResultOk: payload := response.Ok() option70 = int32(0) @@ -2582,7 +2593,7 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out option75 = 0 option76 = 0 option77 = 0 - case wit_types.ResultErr: + case witTypes.ResultErr: payload := response.Err() var variant int32 var variant64 int32 @@ -2608,12 +2619,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option0 uintptr var option1 uint32 switch (payload).Rcode.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 option1 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).Rcode.Some() utf8 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf8) @@ -2627,11 +2638,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option2 int32 var option3 int32 switch (payload).InfoCode.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option2 = int32(0) option3 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).InfoCode.Some() option2 = int32(1) @@ -2773,11 +2784,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option4 int32 var option5 int32 switch (payload).AlertId.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option4 = int32(0) option5 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).AlertId.Some() option4 = int32(1) @@ -2789,12 +2800,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option8 uintptr var option9 uint32 switch (payload).AlertMessage.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option7 = int32(0) option8 = 0 option9 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).AlertMessage.Some() utf86 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf86) @@ -2839,11 +2850,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option10 int32 var option11 int64 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option10 = int32(0) option11 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option10 = int32(1) @@ -2895,11 +2906,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option12 int32 var option13 int32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option12 = int32(0) option13 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option12 = int32(1) @@ -2925,7 +2936,7 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option24 int32 var option25 int32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option20 = int32(0) option21 = 0 @@ -2933,18 +2944,18 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out option23 = 0 option24 = 0 option25 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() var option15 int32 var option16 uintptr var option17 uint32 switch (payload).FieldName.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option15 = int32(0) option16 = 0 option17 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldName.Some() utf814 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf814) @@ -2958,11 +2969,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option18 int32 var option19 int32 switch (payload).FieldSize.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option18 = int32(0) option19 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldSize.Some() option18 = int32(1) @@ -2994,11 +3005,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option26 int32 var option27 int32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option26 = int32(0) option27 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option26 = int32(1) @@ -3021,12 +3032,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option30 uintptr var option31 uint32 switch (payload).FieldName.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option29 = int32(0) option30 = 0 option31 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldName.Some() utf828 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf828) @@ -3040,11 +3051,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option32 int32 var option33 int32 switch (payload).FieldSize.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option32 = int32(0) option33 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldSize.Some() option32 = int32(1) @@ -3076,11 +3087,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option34 int32 var option35 int32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option34 = int32(0) option35 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option34 = int32(1) @@ -3103,12 +3114,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option38 uintptr var option39 uint32 switch (payload).FieldName.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option37 = int32(0) option38 = 0 option39 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldName.Some() utf836 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf836) @@ -3122,11 +3133,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option40 int32 var option41 int32 switch (payload).FieldSize.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option40 = int32(0) option41 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldSize.Some() option40 = int32(1) @@ -3148,11 +3159,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option42 int32 var option43 int64 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option42 = int32(0) option43 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option42 = int32(1) @@ -3174,11 +3185,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option44 int32 var option45 int32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option44 = int32(0) option45 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() option44 = int32(1) @@ -3201,12 +3212,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option48 uintptr var option49 uint32 switch (payload).FieldName.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option47 = int32(0) option48 = 0 option49 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldName.Some() utf846 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf846) @@ -3220,11 +3231,11 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option50 int32 var option51 int32 switch (payload).FieldSize.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option50 = int32(0) option51 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (payload).FieldSize.Some() option50 = int32(1) @@ -3247,12 +3258,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option54 uintptr var option55 uint32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option53 = int32(0) option54 = 0 option55 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() utf852 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf852) @@ -3278,12 +3289,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option58 uintptr var option59 uint32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option57 = int32(0) option58 = 0 option59 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() utf856 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf856) @@ -3359,12 +3370,12 @@ func ResponseOutparamSet(param *ResponseOutparam, response wit_types.Result[*Out var option62 uintptr var option63 uint32 switch payload.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option61 = int32(0) option62 = 0 option63 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := payload.Some() utf860 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf860) @@ -3426,20 +3437,20 @@ func (self *IncomingResponse) Headers() *Fields { //go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume func wasm_import_method_incoming_response_consume(arg0 int32, arg1 uintptr) -func (self *IncomingResponse) Consume() wit_types.Result[*IncomingBody, wit_types.Unit] { +func (self *IncomingResponse) Consume() witTypes.Result[*IncomingBody, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_incoming_response_consume((self).Handle(), returnArea) - var result wit_types.Result[*IncomingBody, wit_types.Unit] + var result witTypes.Result[*IncomingBody, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*IncomingBody, wit_types.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*IncomingBody, witTypes.Unit](IncomingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*IncomingBody, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*IncomingBody, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -3451,20 +3462,20 @@ func (self *IncomingResponse) Consume() wit_types.Result[*IncomingBody, wit_type //go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream func wasm_import_method_incoming_body_stream(arg0 int32, arg1 uintptr) -func (self *IncomingBody) Stream() wit_types.Result[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit] { +func (self *IncomingBody) Stream() witTypes.Result[*wasi_io_0_2_0_streams.InputStream, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_incoming_body_stream((self).Handle(), returnArea) - var result wit_types.Result[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit] + var result witTypes.Result[*wasi_io_0_2_0_streams.InputStream, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_io_0_2_0_streams.InputStream, witTypes.Unit](wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_io_0_2_0_streams.InputStream, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*wasi_io_0_2_0_streams.InputStream, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -3496,37 +3507,37 @@ func (self *FutureTrailers) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get func wasm_import_method_future_trailers_get(arg0 int32, arg1 uintptr) -func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]] { +func (self *FutureTrailers) Get() witTypes.Option[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (40 + 4*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (40 + 4*4), 8)) wasm_import_method_future_trailers_get((self).Handle(), returnArea) - var option31 wit_types.Option[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]] + var option31 witTypes.Option[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option31 = wit_types.None[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]]() + option31 = witTypes.None[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]]() case 1: - var result30 wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit] + var result30 witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { case 0: - var result wit_types.Result[wit_types.Option[*Fields], ErrorCode] + var result witTypes.Result[witTypes.Option[*Fields], ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - var option wit_types.Option[*Fields] + var option witTypes.Option[*Fields] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { case 0: - option = wit_types.None[*Fields]() + option = witTypes.None[*Fields]() case 1: - option = wit_types.Some[*Fields](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))))) + option = witTypes.Some[*Fields](FieldsFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))))) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[*Fields], ErrorCode](option) + result = witTypes.Ok[witTypes.Option[*Fields], ErrorCode](option) case 1: var variant ErrorCode switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { @@ -3535,26 +3546,26 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeDnsTimeout() case 1: - var option0 wit_types.Option[string] + var option0 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option0 = wit_types.None[string]() + option0 = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option0 = wit_types.Some[string](value) + option0 = witTypes.Some[string](value) default: panic("unreachable") } - var option1 wit_types.Option[uint16] + var option1 witTypes.Option[uint16] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option1 = wit_types.None[uint16]() + option1 = witTypes.None[uint16]() case 1: - option1 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) + option1 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) default: panic("unreachable") } @@ -3610,26 +3621,26 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeTlsCertificateError() case 14: - var option2 wit_types.Option[uint8] + var option2 witTypes.Option[uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option2 = wit_types.None[uint8]() + option2 = witTypes.None[uint8]() case 1: - option2 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) + option2 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) default: panic("unreachable") } - var option4 wit_types.Option[string] + var option4 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { case 0: - option4 = wit_types.None[string]() + option4 = witTypes.None[string]() case 1: value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) - option4 = wit_types.Some[string](value3) + option4 = witTypes.Some[string](value3) default: panic("unreachable") } @@ -3645,14 +3656,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpRequestLengthRequired() case 17: - var option5 wit_types.Option[uint64] + var option5 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option5 = wit_types.None[uint64]() + option5 = witTypes.None[uint64]() case 1: - option5 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + option5 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) default: panic("unreachable") } @@ -3672,14 +3683,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpRequestUriTooLong() case 21: - var option6 wit_types.Option[uint32] + var option6 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option6 = wit_types.None[uint32]() + option6 = witTypes.None[uint32]() case 1: - option6 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option6 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -3687,37 +3698,37 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpRequestHeaderSectionSize(option6) case 22: - var option10 wit_types.Option[FieldSizePayload] + var option10 witTypes.Option[FieldSizePayload] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option10 = wit_types.None[FieldSizePayload]() + option10 = witTypes.None[FieldSizePayload]() case 1: - var option8 wit_types.Option[string] + var option8 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { case 0: - option8 = wit_types.None[string]() + option8 = witTypes.None[string]() case 1: value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) - option8 = wit_types.Some[string](value7) + option8 = witTypes.Some[string](value7) default: panic("unreachable") } - var option9 wit_types.Option[uint32] + var option9 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) { case 0: - option9 = wit_types.None[uint32]() + option9 = witTypes.None[uint32]() case 1: - option9 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) + option9 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) default: panic("unreachable") } - option10 = wit_types.Some[FieldSizePayload](FieldSizePayload{option8, option9}) + option10 = witTypes.Some[FieldSizePayload](FieldSizePayload{option8, option9}) default: panic("unreachable") } @@ -3725,14 +3736,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpRequestHeaderSize(option10) case 23: - var option11 wit_types.Option[uint32] + var option11 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option11 = wit_types.None[uint32]() + option11 = witTypes.None[uint32]() case 1: - option11 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option11 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -3740,26 +3751,26 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpRequestTrailerSectionSize(option11) case 24: - var option13 wit_types.Option[string] + var option13 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option13 = wit_types.None[string]() + option13 = witTypes.None[string]() case 1: value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option13 = wit_types.Some[string](value12) + option13 = witTypes.Some[string](value12) default: panic("unreachable") } - var option14 wit_types.Option[uint32] + var option14 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option14 = wit_types.None[uint32]() + option14 = witTypes.None[uint32]() case 1: - option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -3771,14 +3782,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseIncomplete() case 26: - var option15 wit_types.Option[uint32] + var option15 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option15 = wit_types.None[uint32]() + option15 = witTypes.None[uint32]() case 1: - option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -3786,26 +3797,26 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseHeaderSectionSize(option15) case 27: - var option17 wit_types.Option[string] + var option17 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option17 = wit_types.None[string]() + option17 = witTypes.None[string]() case 1: value16 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option17 = wit_types.Some[string](value16) + option17 = witTypes.Some[string](value16) default: panic("unreachable") } - var option18 wit_types.Option[uint32] + var option18 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option18 = wit_types.None[uint32]() + option18 = witTypes.None[uint32]() case 1: - option18 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option18 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -3813,14 +3824,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option17, option18}) case 28: - var option19 wit_types.Option[uint64] + var option19 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option19 = wit_types.None[uint64]() + option19 = witTypes.None[uint64]() case 1: - option19 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + option19 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) default: panic("unreachable") } @@ -3828,14 +3839,14 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseBodySize(option19) case 29: - var option20 wit_types.Option[uint32] + var option20 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option20 = wit_types.None[uint32]() + option20 = witTypes.None[uint32]() case 1: - option20 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option20 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -3843,26 +3854,26 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseTrailerSectionSize(option20) case 30: - var option22 wit_types.Option[string] + var option22 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option22 = wit_types.None[string]() + option22 = witTypes.None[string]() case 1: value21 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option22 = wit_types.Some[string](value21) + option22 = witTypes.Some[string](value21) default: panic("unreachable") } - var option23 wit_types.Option[uint32] + var option23 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option23 = wit_types.None[uint32]() + option23 = witTypes.None[uint32]() case 1: - option23 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option23 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -3870,15 +3881,15 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option22, option23}) case 31: - var option25 wit_types.Option[string] + var option25 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option25 = wit_types.None[string]() + option25 = witTypes.None[string]() case 1: value24 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option25 = wit_types.Some[string](value24) + option25 = witTypes.Some[string](value24) default: panic("unreachable") } @@ -3886,15 +3897,15 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeHttpResponseTransferCoding(option25) case 32: - var option27 wit_types.Option[string] + var option27 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option27 = wit_types.None[string]() + option27 = witTypes.None[string]() case 1: value26 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option27 = wit_types.Some[string](value26) + option27 = witTypes.Some[string](value26) default: panic("unreachable") } @@ -3922,15 +3933,15 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re variant = MakeErrorCodeConfigurationError() case 38: - var option29 wit_types.Option[string] + var option29 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option29 = wit_types.None[string]() + option29 = witTypes.None[string]() case 1: value28 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option29 = wit_types.Some[string](value28) + option29 = witTypes.Some[string](value28) default: panic("unreachable") } @@ -3941,20 +3952,20 @@ func (self *FutureTrailers) Get() wit_types.Option[wit_types.Result[wit_types.Re panic("unreachable") } - result = wit_types.Err[wit_types.Option[*Fields], ErrorCode](variant) + result = witTypes.Err[witTypes.Option[*Fields], ErrorCode](variant) default: panic("unreachable") } - result30 = wit_types.Ok[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit](result) + result30 = witTypes.Ok[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit](result) case 1: - result30 = wit_types.Err[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit](wit_types.Unit{}) + result30 = witTypes.Err[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } - option31 = wit_types.Some[wit_types.Result[wit_types.Result[wit_types.Option[*Fields], ErrorCode], wit_types.Unit]](result30) + option31 = witTypes.Some[witTypes.Result[witTypes.Result[witTypes.Option[*Fields], ErrorCode], witTypes.Unit]](result30) default: panic("unreachable") } @@ -3986,17 +3997,17 @@ func (self *OutgoingResponse) StatusCode() uint16 { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code func wasm_import_method_outgoing_response_set_status_code(arg0 int32, arg1 int32) int32 -func (self *OutgoingResponse) SetStatusCode(statusCode uint16) wit_types.Result[wit_types.Unit, wit_types.Unit] { +func (self *OutgoingResponse) SetStatusCode(statusCode uint16) witTypes.Result[witTypes.Unit, witTypes.Unit] { result := wasm_import_method_outgoing_response_set_status_code((self).Handle(), int32(statusCode)) - var result0 wit_types.Result[wit_types.Unit, wit_types.Unit] + var result0 witTypes.Result[witTypes.Unit, witTypes.Unit] switch result { case 0: - result0 = wit_types.Ok[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result0 = witTypes.Ok[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) case 1: - result0 = wit_types.Err[wit_types.Unit, wit_types.Unit](wit_types.Unit{}) + result0 = witTypes.Err[witTypes.Unit, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -4017,20 +4028,20 @@ func (self *OutgoingResponse) Headers() *Fields { //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body func wasm_import_method_outgoing_response_body(arg0 int32, arg1 uintptr) -func (self *OutgoingResponse) Body() wit_types.Result[*OutgoingBody, wit_types.Unit] { +func (self *OutgoingResponse) Body() witTypes.Result[*OutgoingBody, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_outgoing_response_body((self).Handle(), returnArea) - var result wit_types.Result[*OutgoingBody, wit_types.Unit] + var result witTypes.Result[*OutgoingBody, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*OutgoingBody, wit_types.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*OutgoingBody, witTypes.Unit](OutgoingBodyFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*OutgoingBody, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*OutgoingBody, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -4042,20 +4053,20 @@ func (self *OutgoingResponse) Body() wit_types.Result[*OutgoingBody, wit_types.U //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write func wasm_import_method_outgoing_body_write(arg0 int32, arg1 uintptr) -func (self *OutgoingBody) Write() wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit] { +func (self *OutgoingBody) Write() witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, witTypes.Unit] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_outgoing_body_write((self).Handle(), returnArea) - var result wit_types.Result[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit] + var result witTypes.Result[*wasi_io_0_2_0_streams.OutputStream, witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_io_0_2_0_streams.OutputStream, witTypes.Unit](wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_io_0_2_0_streams.OutputStream, wit_types.Unit](wit_types.Unit{}) + result = witTypes.Err[*wasi_io_0_2_0_streams.OutputStream, witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } @@ -4067,19 +4078,19 @@ func (self *OutgoingBody) Write() wit_types.Result[*wasi_io_0_2_0_streams.Output //go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish func wasm_import_static_outgoing_body_finish(arg0 int32, arg1 int32, arg2 int32, arg3 uintptr) -func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) wit_types.Result[wit_types.Unit, ErrorCode] { +func OutgoingBodyFinish(this *OutgoingBody, trailers witTypes.Option[*Fields]) witTypes.Result[witTypes.Unit, ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (24 + 4*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (24 + 4*4), 8)) var option int32 var option0 int32 switch trailers.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := trailers.Some() option = int32(1) @@ -4088,11 +4099,11 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) panic("unreachable") } wasm_import_static_outgoing_body_finish((this).TakeHandle(), option, option0, returnArea) - var result wit_types.Result[wit_types.Unit, ErrorCode] + var result witTypes.Result[witTypes.Unit, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, ErrorCode](witTypes.Unit{}) case 1: var variant ErrorCode switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -4101,26 +4112,26 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeDnsTimeout() case 1: - var option1 wit_types.Option[string] + var option1 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option1 = wit_types.None[string]() + option1 = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option1 = wit_types.Some[string](value) + option1 = witTypes.Some[string](value) default: panic("unreachable") } - var option2 wit_types.Option[uint16] + var option2 witTypes.Option[uint16] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option2 = wit_types.None[uint16]() + option2 = witTypes.None[uint16]() case 1: - option2 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) + option2 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (18 + 3*4)))))) default: panic("unreachable") } @@ -4176,26 +4187,26 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeTlsCertificateError() case 14: - var option3 wit_types.Option[uint8] + var option3 witTypes.Option[uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option3 = wit_types.None[uint8]() + option3 = witTypes.None[uint8]() case 1: - option3 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) + option3 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 17))))) default: panic("unreachable") } - var option5 wit_types.Option[string] + var option5 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option5 = wit_types.None[string]() + option5 = witTypes.None[string]() case 1: value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option5 = wit_types.Some[string](value4) + option5 = witTypes.Some[string](value4) default: panic("unreachable") } @@ -4211,14 +4222,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpRequestLengthRequired() case 17: - var option6 wit_types.Option[uint64] + var option6 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option6 = wit_types.None[uint64]() + option6 = witTypes.None[uint64]() case 1: - option6 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option6 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -4238,14 +4249,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpRequestUriTooLong() case 21: - var option7 wit_types.Option[uint32] + var option7 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option7 = wit_types.None[uint32]() + option7 = witTypes.None[uint32]() case 1: - option7 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option7 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -4253,37 +4264,37 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpRequestHeaderSectionSize(option7) case 22: - var option11 wit_types.Option[FieldSizePayload] + var option11 witTypes.Option[FieldSizePayload] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option11 = wit_types.None[FieldSizePayload]() + option11 = witTypes.None[FieldSizePayload]() case 1: - var option9 wit_types.Option[string] + var option9 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))) { case 0: - option9 = wit_types.None[string]() + option9 = witTypes.None[string]() case 1: value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) - option9 = wit_types.Some[string](value8) + option9 = witTypes.Some[string](value8) default: panic("unreachable") } - var option10 wit_types.Option[uint32] + var option10 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 4*4)))) { case 0: - option10 = wit_types.None[uint32]() + option10 = witTypes.None[uint32]() case 1: - option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) + option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 4*4))))) default: panic("unreachable") } - option11 = wit_types.Some[FieldSizePayload](FieldSizePayload{option9, option10}) + option11 = witTypes.Some[FieldSizePayload](FieldSizePayload{option9, option10}) default: panic("unreachable") } @@ -4291,14 +4302,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpRequestHeaderSize(option11) case 23: - var option12 wit_types.Option[uint32] + var option12 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option12 = wit_types.None[uint32]() + option12 = witTypes.None[uint32]() case 1: - option12 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option12 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -4306,26 +4317,26 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpRequestTrailerSectionSize(option12) case 24: - var option14 wit_types.Option[string] + var option14 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option14 = wit_types.None[string]() + option14 = witTypes.None[string]() case 1: value13 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option14 = wit_types.Some[string](value13) + option14 = witTypes.Some[string](value13) default: panic("unreachable") } - var option15 wit_types.Option[uint32] + var option15 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option15 = wit_types.None[uint32]() + option15 = witTypes.None[uint32]() case 1: - option15 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option15 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -4337,14 +4348,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseIncomplete() case 26: - var option16 wit_types.Option[uint32] + var option16 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option16 = wit_types.None[uint32]() + option16 = witTypes.None[uint32]() case 1: - option16 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option16 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -4352,26 +4363,26 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseHeaderSectionSize(option16) case 27: - var option18 wit_types.Option[string] + var option18 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option18 = wit_types.None[string]() + option18 = witTypes.None[string]() case 1: value17 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option18 = wit_types.Some[string](value17) + option18 = witTypes.Some[string](value17) default: panic("unreachable") } - var option19 wit_types.Option[uint32] + var option19 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option19 = wit_types.None[uint32]() + option19 = witTypes.None[uint32]() case 1: - option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -4379,14 +4390,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option18, option19}) case 28: - var option20 wit_types.Option[uint64] + var option20 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option20 = wit_types.None[uint64]() + option20 = witTypes.None[uint64]() case 1: - option20 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) + option20 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 24)))) default: panic("unreachable") } @@ -4394,14 +4405,14 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseBodySize(option20) case 29: - var option21 wit_types.Option[uint32] + var option21 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option21 = wit_types.None[uint32]() + option21 = witTypes.None[uint32]() case 1: - option21 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) + option21 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))) default: panic("unreachable") } @@ -4409,26 +4420,26 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseTrailerSectionSize(option21) case 30: - var option23 wit_types.Option[string] + var option23 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option23 = wit_types.None[string]() + option23 = witTypes.None[string]() case 1: value22 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option23 = wit_types.Some[string](value22) + option23 = witTypes.Some[string](value22) default: panic("unreachable") } - var option24 wit_types.Option[uint32] + var option24 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 3*4)))) { case 0: - option24 = wit_types.None[uint32]() + option24 = witTypes.None[uint32]() case 1: - option24 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) + option24 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (20 + 3*4))))) default: panic("unreachable") } @@ -4436,15 +4447,15 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option23, option24}) case 31: - var option26 wit_types.Option[string] + var option26 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option26 = wit_types.None[string]() + option26 = witTypes.None[string]() case 1: value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option26 = wit_types.Some[string](value25) + option26 = witTypes.Some[string](value25) default: panic("unreachable") } @@ -4452,15 +4463,15 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeHttpResponseTransferCoding(option26) case 32: - var option28 wit_types.Option[string] + var option28 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option28 = wit_types.None[string]() + option28 = witTypes.None[string]() case 1: value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option28 = wit_types.Some[string](value27) + option28 = witTypes.Some[string](value27) default: panic("unreachable") } @@ -4488,15 +4499,15 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) variant = MakeErrorCodeConfigurationError() case 38: - var option30 wit_types.Option[string] + var option30 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - option30 = wit_types.None[string]() + option30 = witTypes.None[string]() case 1: value29 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (16 + 2*4)))) - option30 = wit_types.Some[string](value29) + option30 = witTypes.Some[string](value29) default: panic("unreachable") } @@ -4507,7 +4518,7 @@ func OutgoingBodyFinish(this *OutgoingBody, trailers wit_types.Option[*Fields]) panic("unreachable") } - result = wit_types.Err[wit_types.Unit, ErrorCode](variant) + result = witTypes.Err[witTypes.Unit, ErrorCode](variant) default: panic("unreachable") } @@ -4529,26 +4540,26 @@ func (self *FutureIncomingResponse) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get func wasm_import_method_future_incoming_response_get(arg0 int32, arg1 uintptr) -func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]] { +func (self *FutureIncomingResponse) Get() witTypes.Option[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (40 + 4*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (40 + 4*4), 8)) wasm_import_method_future_incoming_response_get((self).Handle(), returnArea) - var option30 wit_types.Option[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]] + var option30 witTypes.Option[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - option30 = wit_types.None[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]]() + option30 = witTypes.None[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]]() case 1: - var result29 wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit] + var result29 witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { case 0: - var result wit_types.Result[*IncomingResponse, ErrorCode] + var result witTypes.Result[*IncomingResponse, ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16))) { case 0: - result = wit_types.Ok[*IncomingResponse, ErrorCode](IncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))))) + result = witTypes.Ok[*IncomingResponse, ErrorCode](IncomingResponseFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))))) case 1: var variant ErrorCode switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24))) { @@ -4557,26 +4568,26 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeDnsTimeout() case 1: - var option wit_types.Option[string] + var option witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option = wit_types.None[string]() + option = witTypes.None[string]() case 1: value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option = wit_types.Some[string](value) + option = witTypes.Some[string](value) default: panic("unreachable") } - var option0 wit_types.Option[uint16] + var option0 witTypes.Option[uint16] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option0 = wit_types.None[uint16]() + option0 = witTypes.None[uint16]() case 1: - option0 = wit_types.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) + option0 = witTypes.Some[uint16](uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (34 + 3*4)))))) default: panic("unreachable") } @@ -4632,26 +4643,26 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeTlsCertificateError() case 14: - var option1 wit_types.Option[uint8] + var option1 witTypes.Option[uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option1 = wit_types.None[uint8]() + option1 = witTypes.None[uint8]() case 1: - option1 = wit_types.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) + option1 = witTypes.Some[uint8](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 33))))) default: panic("unreachable") } - var option3 wit_types.Option[string] + var option3 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { case 0: - option3 = wit_types.None[string]() + option3 = witTypes.None[string]() case 1: value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) - option3 = wit_types.Some[string](value2) + option3 = witTypes.Some[string](value2) default: panic("unreachable") } @@ -4667,14 +4678,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpRequestLengthRequired() case 17: - var option4 wit_types.Option[uint64] + var option4 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option4 = wit_types.None[uint64]() + option4 = witTypes.None[uint64]() case 1: - option4 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + option4 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) default: panic("unreachable") } @@ -4694,14 +4705,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpRequestUriTooLong() case 21: - var option5 wit_types.Option[uint32] + var option5 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option5 = wit_types.None[uint32]() + option5 = witTypes.None[uint32]() case 1: - option5 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option5 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -4709,37 +4720,37 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpRequestHeaderSectionSize(option5) case 22: - var option9 wit_types.Option[FieldSizePayload] + var option9 witTypes.Option[FieldSizePayload] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option9 = wit_types.None[FieldSizePayload]() + option9 = witTypes.None[FieldSizePayload]() case 1: - var option7 wit_types.Option[string] + var option7 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))) { case 0: - option7 = wit_types.None[string]() + option7 = witTypes.None[string]() case 1: value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) - option7 = wit_types.Some[string](value6) + option7 = witTypes.Some[string](value6) default: panic("unreachable") } - var option8 wit_types.Option[uint32] + var option8 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 4*4)))) { case 0: - option8 = wit_types.None[uint32]() + option8 = witTypes.None[uint32]() case 1: - option8 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) + option8 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 4*4))))) default: panic("unreachable") } - option9 = wit_types.Some[FieldSizePayload](FieldSizePayload{option7, option8}) + option9 = witTypes.Some[FieldSizePayload](FieldSizePayload{option7, option8}) default: panic("unreachable") } @@ -4747,14 +4758,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpRequestHeaderSize(option9) case 23: - var option10 wit_types.Option[uint32] + var option10 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option10 = wit_types.None[uint32]() + option10 = witTypes.None[uint32]() case 1: - option10 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option10 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -4762,26 +4773,26 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpRequestTrailerSectionSize(option10) case 24: - var option12 wit_types.Option[string] + var option12 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option12 = wit_types.None[string]() + option12 = witTypes.None[string]() case 1: value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option12 = wit_types.Some[string](value11) + option12 = witTypes.Some[string](value11) default: panic("unreachable") } - var option13 wit_types.Option[uint32] + var option13 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option13 = wit_types.None[uint32]() + option13 = witTypes.None[uint32]() case 1: - option13 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option13 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -4793,14 +4804,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseIncomplete() case 26: - var option14 wit_types.Option[uint32] + var option14 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option14 = wit_types.None[uint32]() + option14 = witTypes.None[uint32]() case 1: - option14 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option14 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -4808,26 +4819,26 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseHeaderSectionSize(option14) case 27: - var option16 wit_types.Option[string] + var option16 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option16 = wit_types.None[string]() + option16 = witTypes.None[string]() case 1: value15 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option16 = wit_types.Some[string](value15) + option16 = witTypes.Some[string](value15) default: panic("unreachable") } - var option17 wit_types.Option[uint32] + var option17 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option17 = wit_types.None[uint32]() + option17 = witTypes.None[uint32]() case 1: - option17 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option17 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -4835,14 +4846,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseHeaderSize(FieldSizePayload{option16, option17}) case 28: - var option18 wit_types.Option[uint64] + var option18 witTypes.Option[uint64] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option18 = wit_types.None[uint64]() + option18 = witTypes.None[uint64]() case 1: - option18 = wit_types.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) + option18 = witTypes.Some[uint64](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 40)))) default: panic("unreachable") } @@ -4850,14 +4861,14 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseBodySize(option18) case 29: - var option19 wit_types.Option[uint32] + var option19 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option19 = wit_types.None[uint32]() + option19 = witTypes.None[uint32]() case 1: - option19 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) + option19 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 36)))) default: panic("unreachable") } @@ -4865,26 +4876,26 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseTrailerSectionSize(option19) case 30: - var option21 wit_types.Option[string] + var option21 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option21 = wit_types.None[string]() + option21 = witTypes.None[string]() case 1: value20 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option21 = wit_types.Some[string](value20) + option21 = witTypes.Some[string](value20) default: panic("unreachable") } - var option22 wit_types.Option[uint32] + var option22 witTypes.Option[uint32] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 3*4)))) { case 0: - option22 = wit_types.None[uint32]() + option22 = witTypes.None[uint32]() case 1: - option22 = wit_types.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) + option22 = witTypes.Some[uint32](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (36 + 3*4))))) default: panic("unreachable") } @@ -4892,15 +4903,15 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseTrailerSize(FieldSizePayload{option21, option22}) case 31: - var option24 wit_types.Option[string] + var option24 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option24 = wit_types.None[string]() + option24 = witTypes.None[string]() case 1: value23 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option24 = wit_types.Some[string](value23) + option24 = witTypes.Some[string](value23) default: panic("unreachable") } @@ -4908,15 +4919,15 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeHttpResponseTransferCoding(option24) case 32: - var option26 wit_types.Option[string] + var option26 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option26 = wit_types.None[string]() + option26 = witTypes.None[string]() case 1: value25 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option26 = wit_types.Some[string](value25) + option26 = witTypes.Some[string](value25) default: panic("unreachable") } @@ -4944,15 +4955,15 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ variant = MakeErrorCodeConfigurationError() case 38: - var option28 wit_types.Option[string] + var option28 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 32))) { case 0: - option28 = wit_types.None[string]() + option28 = witTypes.None[string]() case 1: value27 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (32 + 2*4)))) - option28 = wit_types.Some[string](value27) + option28 = witTypes.Some[string](value27) default: panic("unreachable") } @@ -4963,20 +4974,20 @@ func (self *FutureIncomingResponse) Get() wit_types.Option[wit_types.Result[wit_ panic("unreachable") } - result = wit_types.Err[*IncomingResponse, ErrorCode](variant) + result = witTypes.Err[*IncomingResponse, ErrorCode](variant) default: panic("unreachable") } - result29 = wit_types.Ok[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit](result) + result29 = witTypes.Ok[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit](result) case 1: - result29 = wit_types.Err[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit](wit_types.Unit{}) + result29 = witTypes.Err[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit](witTypes.Unit{}) default: panic("unreachable") } - option30 = wit_types.Some[wit_types.Result[wit_types.Result[*IncomingResponse, ErrorCode], wit_types.Unit]](result29) + option30 = witTypes.Some[witTypes.Result[witTypes.Result[*IncomingResponse, ErrorCode], witTypes.Unit]](result29) default: panic("unreachable") } diff --git a/v3/internal/wasi_io_0_2_0_error/wit_bindings.go b/internal/wasi_io_0_2_0_error/wit_bindings.go similarity index 90% rename from v3/internal/wasi_io_0_2_0_error/wit_bindings.go rename to internal/wasi_io_0_2_0_error/wit_bindings.go index b970e003..855d99e7 100644 --- a/v3/internal/wasi_io_0_2_0_error/wit_bindings.go +++ b/internal/wasi_io_0_2_0_error/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_io_0_2_0_error import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" "unsafe" ) @@ -60,7 +60,7 @@ func resourceDropError(handle int32) // The set of functions which can "downcast" an `error` into a more // concrete type is open. type Error struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Error) TakeHandle() int32 { @@ -83,7 +83,7 @@ func (self *Error) Drop() { } func ErrorFromOwnHandle(handleValue int32) *Error { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Error{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -95,7 +95,8 @@ func ErrorFromOwnHandle(handleValue int32) *Error { } func ErrorFromBorrowHandle(handleValue int32) *Error { - return ErrorFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Error{handle} } //go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string @@ -105,7 +106,7 @@ func (self *Error) ToDebugString() string { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_method_error_to_debug_string((self).Handle(), returnArea) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) result := value diff --git a/v3/internal/wasi_io_0_2_0_poll/wit_bindings.go b/internal/wasi_io_0_2_0_poll/wit_bindings.go similarity index 88% rename from v3/internal/wasi_io_0_2_0_poll/wit_bindings.go rename to internal/wasi_io_0_2_0_poll/wit_bindings.go index 4ee0d1e8..9456635f 100644 --- a/v3/internal/wasi_io_0_2_0_poll/wit_bindings.go +++ b/internal/wasi_io_0_2_0_poll/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_io_0_2_0_poll import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" "unsafe" ) @@ -42,7 +42,7 @@ func resourceDropPollable(handle int32) // `pollable` represents a single I/O event which may be ready, or not. type Pollable struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Pollable) TakeHandle() int32 { @@ -65,7 +65,7 @@ func (self *Pollable) Drop() { } func PollableFromOwnHandle(handleValue int32) *Pollable { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Pollable{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -77,7 +77,8 @@ func PollableFromOwnHandle(handleValue int32) *Pollable { } func PollableFromBorrowHandle(handleValue int32) *Pollable { - return PollableFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Pollable{handle} } //go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready @@ -106,10 +107,10 @@ func Poll(in []*Pollable) []uint32 { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) slice := in length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*4), 4) + result := witRuntime.Allocate(pinner, uintptr(length*4), 4) for index, element := range slice { base := unsafe.Add(result, index*4) *(*int32)(unsafe.Add(unsafe.Pointer(base), 0)) = (element).Handle() diff --git a/v3/internal/wasi_io_0_2_0_streams/wit_bindings.go b/internal/wasi_io_0_2_0_streams/wit_bindings.go similarity index 78% rename from v3/internal/wasi_io_0_2_0_streams/wit_bindings.go rename to internal/wasi_io_0_2_0_streams/wit_bindings.go index f60b6039..59c6791b 100644 --- a/v3/internal/wasi_io_0_2_0_streams/wit_bindings.go +++ b/internal/wasi_io_0_2_0_streams/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,10 +32,10 @@ package wasi_io_0_2_0_streams import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_error" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -90,7 +90,7 @@ func resourceDropInputStream(handle int32) // use the `subscribe` function to obtain a `pollable` which can be polled // for using `wasi:io/poll`. type InputStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *InputStream) TakeHandle() int32 { @@ -113,7 +113,7 @@ func (self *InputStream) Drop() { } func InputStreamFromOwnHandle(handleValue int32) *InputStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &InputStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -125,7 +125,8 @@ func InputStreamFromOwnHandle(handleValue int32) *InputStream { } func InputStreamFromBorrowHandle(handleValue int32) *InputStream { - return InputStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &InputStream{handle} } //go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream @@ -140,7 +141,7 @@ func resourceDropOutputStream(handle int32) // accept data, the `subscribe` function to obtain a `pollable` which can be // polled for using `wasi:io/poll`. type OutputStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *OutputStream) TakeHandle() int32 { @@ -163,7 +164,7 @@ func (self *OutputStream) Drop() { } func OutputStreamFromOwnHandle(handleValue int32) *OutputStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &OutputStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -175,24 +176,25 @@ func OutputStreamFromOwnHandle(handleValue int32) *OutputStream { } func OutputStreamFromBorrowHandle(handleValue int32) *OutputStream { - return OutputStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &OutputStream{handle} } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read func wasm_import_method_input_stream_read(arg0 int32, arg1 int64, arg2 uintptr) -func (self *InputStream) Read(len uint64) wit_types.Result[[]uint8, StreamError] { +func (self *InputStream) Read(len uint64) witTypes.Result[[]uint8, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_input_stream_read((self).Handle(), int64(len), returnArea) - var result wit_types.Result[[]uint8, StreamError] + var result witTypes.Result[[]uint8, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[[]uint8, StreamError](value) + result = witTypes.Ok[[]uint8, StreamError](value) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -208,7 +210,7 @@ func (self *InputStream) Read(len uint64) wit_types.Result[[]uint8, StreamError] panic("unreachable") } - result = wit_types.Err[[]uint8, StreamError](variant) + result = witTypes.Err[[]uint8, StreamError](variant) default: panic("unreachable") } @@ -220,18 +222,18 @@ func (self *InputStream) Read(len uint64) wit_types.Result[[]uint8, StreamError] //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read func wasm_import_method_input_stream_blocking_read(arg0 int32, arg1 int64, arg2 uintptr) -func (self *InputStream) BlockingRead(len uint64) wit_types.Result[[]uint8, StreamError] { +func (self *InputStream) BlockingRead(len uint64) witTypes.Result[[]uint8, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_input_stream_blocking_read((self).Handle(), int64(len), returnArea) - var result wit_types.Result[[]uint8, StreamError] + var result witTypes.Result[[]uint8, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) - result = wit_types.Ok[[]uint8, StreamError](value) + result = witTypes.Ok[[]uint8, StreamError](value) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -247,7 +249,7 @@ func (self *InputStream) BlockingRead(len uint64) wit_types.Result[[]uint8, Stre panic("unreachable") } - result = wit_types.Err[[]uint8, StreamError](variant) + result = witTypes.Err[[]uint8, StreamError](variant) default: panic("unreachable") } @@ -259,17 +261,17 @@ func (self *InputStream) BlockingRead(len uint64) wit_types.Result[[]uint8, Stre //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip func wasm_import_method_input_stream_skip(arg0 int32, arg1 int64, arg2 uintptr) -func (self *InputStream) Skip(len uint64) wit_types.Result[uint64, StreamError] { +func (self *InputStream) Skip(len uint64) witTypes.Result[uint64, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_input_stream_skip((self).Handle(), int64(len), returnArea) - var result wit_types.Result[uint64, StreamError] + var result witTypes.Result[uint64, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -285,7 +287,7 @@ func (self *InputStream) Skip(len uint64) wit_types.Result[uint64, StreamError] panic("unreachable") } - result = wit_types.Err[uint64, StreamError](variant) + result = witTypes.Err[uint64, StreamError](variant) default: panic("unreachable") } @@ -297,17 +299,17 @@ func (self *InputStream) Skip(len uint64) wit_types.Result[uint64, StreamError] //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip func wasm_import_method_input_stream_blocking_skip(arg0 int32, arg1 int64, arg2 uintptr) -func (self *InputStream) BlockingSkip(len uint64) wit_types.Result[uint64, StreamError] { +func (self *InputStream) BlockingSkip(len uint64) witTypes.Result[uint64, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_input_stream_blocking_skip((self).Handle(), int64(len), returnArea) - var result wit_types.Result[uint64, StreamError] + var result witTypes.Result[uint64, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -323,7 +325,7 @@ func (self *InputStream) BlockingSkip(len uint64) wit_types.Result[uint64, Strea panic("unreachable") } - result = wit_types.Err[uint64, StreamError](variant) + result = witTypes.Err[uint64, StreamError](variant) default: panic("unreachable") } @@ -345,17 +347,17 @@ func (self *InputStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write func wasm_import_method_output_stream_check_write(arg0 int32, arg1 uintptr) -func (self *OutputStream) CheckWrite() wit_types.Result[uint64, StreamError] { +func (self *OutputStream) CheckWrite() witTypes.Result[uint64, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_output_stream_check_write((self).Handle(), returnArea) - var result wit_types.Result[uint64, StreamError] + var result witTypes.Result[uint64, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -371,7 +373,7 @@ func (self *OutputStream) CheckWrite() wit_types.Result[uint64, StreamError] { panic("unreachable") } - result = wit_types.Err[uint64, StreamError](variant) + result = witTypes.Err[uint64, StreamError](variant) default: panic("unreachable") } @@ -383,19 +385,19 @@ func (self *OutputStream) CheckWrite() wit_types.Result[uint64, StreamError] { //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write func wasm_import_method_output_stream_write(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *OutputStream) Write(contents []uint8) wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) Write(contents []uint8) witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) data := unsafe.Pointer(unsafe.SliceData(contents)) pinner.Pin(data) wasm_import_method_output_stream_write((self).Handle(), uintptr(data), uint32(len(contents)), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -411,7 +413,7 @@ func (self *OutputStream) Write(contents []uint8) wit_types.Result[wit_types.Uni panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -423,19 +425,19 @@ func (self *OutputStream) Write(contents []uint8) wit_types.Result[wit_types.Uni //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush func wasm_import_method_output_stream_blocking_write_and_flush(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) data := unsafe.Pointer(unsafe.SliceData(contents)) pinner.Pin(data) wasm_import_method_output_stream_blocking_write_and_flush((self).Handle(), uintptr(data), uint32(len(contents)), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -451,7 +453,7 @@ func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) wit_types.Resu panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -463,17 +465,17 @@ func (self *OutputStream) BlockingWriteAndFlush(contents []uint8) wit_types.Resu //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush func wasm_import_method_output_stream_flush(arg0 int32, arg1 uintptr) -func (self *OutputStream) Flush() wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) Flush() witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) wasm_import_method_output_stream_flush((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -489,7 +491,7 @@ func (self *OutputStream) Flush() wit_types.Result[wit_types.Unit, StreamError] panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -501,17 +503,17 @@ func (self *OutputStream) Flush() wit_types.Result[wit_types.Unit, StreamError] //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush func wasm_import_method_output_stream_blocking_flush(arg0 int32, arg1 uintptr) -func (self *OutputStream) BlockingFlush() wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) BlockingFlush() witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) wasm_import_method_output_stream_blocking_flush((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -527,7 +529,7 @@ func (self *OutputStream) BlockingFlush() wit_types.Result[wit_types.Unit, Strea panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -549,17 +551,17 @@ func (self *OutputStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes func wasm_import_method_output_stream_write_zeroes(arg0 int32, arg1 int64, arg2 uintptr) -func (self *OutputStream) WriteZeroes(len uint64) wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) WriteZeroes(len uint64) witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) wasm_import_method_output_stream_write_zeroes((self).Handle(), int64(len), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -575,7 +577,7 @@ func (self *OutputStream) WriteZeroes(len uint64) wit_types.Result[wit_types.Uni panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -587,17 +589,17 @@ func (self *OutputStream) WriteZeroes(len uint64) wit_types.Result[wit_types.Uni //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush func wasm_import_method_output_stream_blocking_write_zeroes_and_flush(arg0 int32, arg1 int64, arg2 uintptr) -func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) wit_types.Result[wit_types.Unit, StreamError] { +func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) witTypes.Result[witTypes.Unit, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) wasm_import_method_output_stream_blocking_write_zeroes_and_flush((self).Handle(), int64(len), returnArea) - var result wit_types.Result[wit_types.Unit, StreamError] + var result witTypes.Result[witTypes.Unit, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, StreamError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, StreamError](witTypes.Unit{}) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -613,7 +615,7 @@ func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) wit_types.Resu panic("unreachable") } - result = wit_types.Err[wit_types.Unit, StreamError](variant) + result = witTypes.Err[witTypes.Unit, StreamError](variant) default: panic("unreachable") } @@ -625,17 +627,17 @@ func (self *OutputStream) BlockingWriteZeroesAndFlush(len uint64) wit_types.Resu //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice func wasm_import_method_output_stream_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr) -func (self *OutputStream) Splice(src *InputStream, len uint64) wit_types.Result[uint64, StreamError] { +func (self *OutputStream) Splice(src *InputStream, len uint64) witTypes.Result[uint64, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_output_stream_splice((self).Handle(), (src).Handle(), int64(len), returnArea) - var result wit_types.Result[uint64, StreamError] + var result witTypes.Result[uint64, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -651,7 +653,7 @@ func (self *OutputStream) Splice(src *InputStream, len uint64) wit_types.Result[ panic("unreachable") } - result = wit_types.Err[uint64, StreamError](variant) + result = witTypes.Err[uint64, StreamError](variant) default: panic("unreachable") } @@ -663,17 +665,17 @@ func (self *OutputStream) Splice(src *InputStream, len uint64) wit_types.Result[ //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice func wasm_import_method_output_stream_blocking_splice(arg0 int32, arg1 int32, arg2 int64, arg3 uintptr) -func (self *OutputStream) BlockingSplice(src *InputStream, len uint64) wit_types.Result[uint64, StreamError] { +func (self *OutputStream) BlockingSplice(src *InputStream, len uint64) witTypes.Result[uint64, StreamError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_output_stream_blocking_splice((self).Handle(), (src).Handle(), int64(len), returnArea) - var result wit_types.Result[uint64, StreamError] + var result witTypes.Result[uint64, StreamError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, StreamError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: var variant StreamError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -689,7 +691,7 @@ func (self *OutputStream) BlockingSplice(src *InputStream, len uint64) wit_types panic("unreachable") } - result = wit_types.Err[uint64, StreamError](variant) + result = witTypes.Err[uint64, StreamError](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_keyvalue_atomics/wit_bindings.go b/internal/wasi_keyvalue_atomics/wit_bindings.go similarity index 79% rename from v3/internal/wasi_keyvalue_atomics/wit_bindings.go rename to internal/wasi_keyvalue_atomics/wit_bindings.go index ebfb887e..d49618bc 100644 --- a/v3/internal/wasi_keyvalue_atomics/wit_bindings.go +++ b/internal/wasi_keyvalue_atomics/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_keyvalue_atomics import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_keyvalue_store" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -47,7 +47,7 @@ func resourceDropCas(handle int32) // A handle to a CAS (compare-and-swap) operation. type Cas struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Cas) TakeHandle() int32 { @@ -70,7 +70,7 @@ func (self *Cas) Drop() { } func CasFromOwnHandle(handleValue int32) *Cas { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Cas{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -82,7 +82,8 @@ func CasFromOwnHandle(handleValue int32) *Cas { } func CasFromBorrowHandle(handleValue int32) *Cas { - return CasFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Cas{handle} } const ( @@ -127,19 +128,19 @@ func MakeCasErrorCasFailed(value *Cas) CasError { //go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [static]cas.new func wasm_import_static_cas_new(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func CasNew(bucket *wasi_keyvalue_store.Bucket, key string) wit_types.Result[*Cas, wasi_keyvalue_store.Error] { +func CasNew(bucket *wasi_keyvalue_store.Bucket, key string) witTypes.Result[*Cas, wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_static_cas_new((bucket).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[*Cas, wasi_keyvalue_store.Error] + var result witTypes.Result[*Cas, wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Cas, wasi_keyvalue_store.Error](CasFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Cas, wasi_keyvalue_store.Error](CasFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -160,7 +161,7 @@ func CasNew(bucket *wasi_keyvalue_store.Bucket, key string) wit_types.Result[*Ca panic("unreachable") } - result = wit_types.Err[*Cas, wasi_keyvalue_store.Error](variant) + result = witTypes.Err[*Cas, wasi_keyvalue_store.Error](variant) default: panic("unreachable") } @@ -172,29 +173,29 @@ func CasNew(bucket *wasi_keyvalue_store.Bucket, key string) wit_types.Result[*Ca //go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 [method]cas.current func wasm_import_method_cas_current(arg0 int32, arg1 uintptr) -func (self *Cas) Current() wit_types.Result[wit_types.Option[[]uint8], wasi_keyvalue_store.Error] { +func (self *Cas) Current() witTypes.Result[witTypes.Option[[]uint8], wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) wasm_import_method_cas_current((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Option[[]uint8], wasi_keyvalue_store.Error] + var result witTypes.Result[witTypes.Option[[]uint8], wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[[]uint8] + var option witTypes.Option[[]uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[[]uint8]() + option = witTypes.None[[]uint8]() case 1: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) - option = wit_types.Some[[]uint8](value) + option = witTypes.Some[[]uint8](value) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[[]uint8], wasi_keyvalue_store.Error](option) + result = witTypes.Ok[witTypes.Option[[]uint8], wasi_keyvalue_store.Error](option) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -215,7 +216,7 @@ func (self *Cas) Current() wit_types.Result[wit_types.Option[[]uint8], wasi_keyv panic("unreachable") } - result = wit_types.Err[wit_types.Option[[]uint8], wasi_keyvalue_store.Error](variant) + result = witTypes.Err[witTypes.Option[[]uint8], wasi_keyvalue_store.Error](variant) default: panic("unreachable") } @@ -227,19 +228,19 @@ func (self *Cas) Current() wit_types.Result[wit_types.Option[[]uint8], wasi_keyv //go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 increment func wasm_import_increment(arg0 int32, arg1 uintptr, arg2 uint32, arg3 int64, arg4 uintptr) -func Increment(bucket *wasi_keyvalue_store.Bucket, key string, delta int64) wit_types.Result[int64, wasi_keyvalue_store.Error] { +func Increment(bucket *wasi_keyvalue_store.Bucket, key string, delta int64) witTypes.Result[int64, wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (16 + 2*4), 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, (16 + 2*4), 8)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_increment((bucket).Handle(), uintptr(utf8), uint32(len(key)), delta, returnArea) - var result wit_types.Result[int64, wasi_keyvalue_store.Error] + var result witTypes.Result[int64, wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[int64, wasi_keyvalue_store.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + result = witTypes.Ok[int64, wasi_keyvalue_store.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { @@ -260,7 +261,7 @@ func Increment(bucket *wasi_keyvalue_store.Bucket, key string, delta int64) wit_ panic("unreachable") } - result = wit_types.Err[int64, wasi_keyvalue_store.Error](variant) + result = witTypes.Err[int64, wasi_keyvalue_store.Error](variant) default: panic("unreachable") } @@ -272,19 +273,19 @@ func Increment(bucket *wasi_keyvalue_store.Bucket, key string, delta int64) wit_ //go:wasmimport wasi:keyvalue/atomics@0.2.0-draft2 swap func wasm_import_swap(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func Swap(cas *Cas, value []uint8) wit_types.Result[wit_types.Unit, CasError] { +func Swap(cas *Cas, value []uint8) witTypes.Result[witTypes.Unit, CasError] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (5 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) data := unsafe.Pointer(unsafe.SliceData(value)) pinner.Pin(data) wasm_import_swap((cas).TakeHandle(), uintptr(data), uint32(len(value)), returnArea) - var result wit_types.Result[wit_types.Unit, CasError] + var result witTypes.Result[witTypes.Unit, CasError] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, CasError](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, CasError](witTypes.Unit{}) case 1: var variant1 CasError switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -318,7 +319,7 @@ func Swap(cas *Cas, value []uint8) wit_types.Result[wit_types.Unit, CasError] { panic("unreachable") } - result = wit_types.Err[wit_types.Unit, CasError](variant1) + result = witTypes.Err[witTypes.Unit, CasError](variant1) default: panic("unreachable") } diff --git a/v3/internal/wasi_keyvalue_batch/wit_bindings.go b/internal/wasi_keyvalue_batch/wit_bindings.go similarity index 76% rename from v3/internal/wasi_keyvalue_batch/wit_bindings.go rename to internal/wasi_keyvalue_batch/wit_bindings.go index 5f44efa6..285e10f9 100644 --- a/v3/internal/wasi_keyvalue_batch/wit_bindings.go +++ b/internal/wasi_keyvalue_batch/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,9 +32,9 @@ package wasi_keyvalue_batch import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_keyvalue_store" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -45,14 +45,14 @@ type Error = wasi_keyvalue_store.Error //go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 get-many func wasm_import_get_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error] { +func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) witTypes.Result[[]witTypes.Tuple2[string, witTypes.Option[[]uint8]], wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) slice := keys length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf8 := unsafe.Pointer(unsafe.StringData(element)) @@ -63,30 +63,30 @@ func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result } wasm_import_get_many((bucket).Handle(), uintptr(result), length, returnArea) - var result3 wit_types.Result[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error] + var result3 witTypes.Result[[]witTypes.Tuple2[string, witTypes.Option[[]uint8]], wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result1 := make([]wit_types.Tuple2[string, wit_types.Option[[]uint8]], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + result1 := make([]witTypes.Tuple2[string, witTypes.Option[[]uint8]], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(5*4)) value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) - var option wit_types.Option[[]uint8] + var option witTypes.Option[[]uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) { case 0: - option = wit_types.None[[]uint8]() + option = witTypes.None[[]uint8]() case 1: value0 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 * 4)))) - option = wit_types.Some[[]uint8](value0) + option = witTypes.Some[[]uint8](value0) default: panic("unreachable") } - result1 = append(result1, wit_types.Tuple2[string, wit_types.Option[[]uint8]]{value, option}) + result1 = append(result1, witTypes.Tuple2[string, witTypes.Option[[]uint8]]{value, option}) } - result3 = wit_types.Ok[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error](result1) + result3 = witTypes.Ok[[]witTypes.Tuple2[string, witTypes.Option[[]uint8]], wasi_keyvalue_store.Error](result1) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -107,7 +107,7 @@ func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result panic("unreachable") } - result3 = wit_types.Err[[]wit_types.Tuple2[string, wit_types.Option[[]uint8]], wasi_keyvalue_store.Error](variant) + result3 = witTypes.Err[[]witTypes.Tuple2[string, witTypes.Option[[]uint8]], wasi_keyvalue_store.Error](variant) default: panic("unreachable") } @@ -119,14 +119,14 @@ func GetMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result //go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 set-many func wasm_import_set_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []wit_types.Tuple2[string, []uint8]) wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] { +func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []witTypes.Tuple2[string, []uint8]) witTypes.Result[witTypes.Unit, wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) slice := keyValues length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(4*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(4*4)) utf8 := unsafe.Pointer(unsafe.StringData((element).F0)) @@ -141,11 +141,11 @@ func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []wit_types.Tuple2[st } wasm_import_set_many((bucket).Handle(), uintptr(result), length, returnArea) - var result0 wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] + var result0 witTypes.Result[witTypes.Unit, wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[wit_types.Unit, wasi_keyvalue_store.Error](wit_types.Unit{}) + result0 = witTypes.Ok[witTypes.Unit, wasi_keyvalue_store.Error](witTypes.Unit{}) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -166,7 +166,7 @@ func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []wit_types.Tuple2[st panic("unreachable") } - result0 = wit_types.Err[wit_types.Unit, wasi_keyvalue_store.Error](variant) + result0 = witTypes.Err[witTypes.Unit, wasi_keyvalue_store.Error](variant) default: panic("unreachable") } @@ -178,14 +178,14 @@ func SetMany(bucket *wasi_keyvalue_store.Bucket, keyValues []wit_types.Tuple2[st //go:wasmimport wasi:keyvalue/batch@0.2.0-draft2 delete-many func wasm_import_delete_many(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func DeleteMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] { +func DeleteMany(bucket *wasi_keyvalue_store.Bucket, keys []string) witTypes.Result[witTypes.Unit, wasi_keyvalue_store.Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) slice := keys length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(2*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(2*4)) utf8 := unsafe.Pointer(unsafe.StringData(element)) @@ -196,11 +196,11 @@ func DeleteMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Res } wasm_import_delete_many((bucket).Handle(), uintptr(result), length, returnArea) - var result0 wit_types.Result[wit_types.Unit, wasi_keyvalue_store.Error] + var result0 witTypes.Result[witTypes.Unit, wasi_keyvalue_store.Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[wit_types.Unit, wasi_keyvalue_store.Error](wit_types.Unit{}) + result0 = witTypes.Ok[witTypes.Unit, wasi_keyvalue_store.Error](witTypes.Unit{}) case 1: var variant wasi_keyvalue_store.Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -221,7 +221,7 @@ func DeleteMany(bucket *wasi_keyvalue_store.Bucket, keys []string) wit_types.Res panic("unreachable") } - result0 = wit_types.Err[wit_types.Unit, wasi_keyvalue_store.Error](variant) + result0 = witTypes.Err[witTypes.Unit, wasi_keyvalue_store.Error](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_keyvalue_store/wit_bindings.go b/internal/wasi_keyvalue_store/wit_bindings.go similarity index 81% rename from v3/internal/wasi_keyvalue_store/wit_bindings.go rename to internal/wasi_keyvalue_store/wit_bindings.go index 76f39787..8d5d5403 100644 --- a/v3/internal/wasi_keyvalue_store/wit_bindings.go +++ b/internal/wasi_keyvalue_store/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package wasi_keyvalue_store import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -81,7 +81,7 @@ type KeyResponse struct { Keys []string // The continuation token to use to fetch the next page of keys. If this is `null`, then // there are no more keys to fetch. - Cursor wit_types.Option[string] + Cursor witTypes.Option[string] } //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [resource-drop]bucket @@ -103,7 +103,7 @@ func resourceDropBucket(handle int32) // // In this interface, we use the term `bucket` to refer to a collection of key-value pairs type Bucket struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Bucket) TakeHandle() int32 { @@ -126,7 +126,7 @@ func (self *Bucket) Drop() { } func BucketFromOwnHandle(handleValue int32) *Bucket { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Bucket{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -138,25 +138,26 @@ func BucketFromOwnHandle(handleValue int32) *Bucket { } func BucketFromBorrowHandle(handleValue int32) *Bucket { - return BucketFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Bucket{handle} } //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 open func wasm_import_open(arg0 uintptr, arg1 uint32, arg2 uintptr) -func Open(identifier string) wit_types.Result[*Bucket, Error] { +func Open(identifier string) witTypes.Result[*Bucket, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(identifier)) pinner.Pin(utf8) wasm_import_open(uintptr(utf8), uint32(len(identifier)), returnArea) - var result wit_types.Result[*Bucket, Error] + var result witTypes.Result[*Bucket, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*Bucket, Error](BucketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*Bucket, Error](BucketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -177,7 +178,7 @@ func Open(identifier string) wit_types.Result[*Bucket, Error] { panic("unreachable") } - result = wit_types.Err[*Bucket, Error](variant) + result = witTypes.Err[*Bucket, Error](variant) default: panic("unreachable") } @@ -189,31 +190,31 @@ func Open(identifier string) wit_types.Result[*Bucket, Error] { //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.get func wasm_import_method_bucket_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Bucket) Get(key string) wit_types.Result[wit_types.Option[[]uint8], Error] { +func (self *Bucket) Get(key string) witTypes.Result[witTypes.Option[[]uint8], Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_bucket_get((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Option[[]uint8], Error] + var result witTypes.Result[witTypes.Option[[]uint8], Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[[]uint8] + var option witTypes.Option[[]uint8] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - option = wit_types.None[[]uint8]() + option = witTypes.None[[]uint8]() case 1: value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) - option = wit_types.Some[[]uint8](value) + option = witTypes.Some[[]uint8](value) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[[]uint8], Error](option) + result = witTypes.Ok[witTypes.Option[[]uint8], Error](option) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -234,7 +235,7 @@ func (self *Bucket) Get(key string) wit_types.Result[wit_types.Option[[]uint8], panic("unreachable") } - result = wit_types.Err[wit_types.Option[[]uint8], Error](variant) + result = witTypes.Err[witTypes.Option[[]uint8], Error](variant) default: panic("unreachable") } @@ -246,21 +247,21 @@ func (self *Bucket) Get(key string) wit_types.Result[wit_types.Option[[]uint8], //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.set func wasm_import_method_bucket_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) -func (self *Bucket) Set(key string, value []uint8) wit_types.Result[wit_types.Unit, Error] { +func (self *Bucket) Set(key string, value []uint8) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) data := unsafe.Pointer(unsafe.SliceData(value)) pinner.Pin(data) wasm_import_method_bucket_set((self).Handle(), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -281,7 +282,7 @@ func (self *Bucket) Set(key string, value []uint8) wit_types.Result[wit_types.Un panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -293,19 +294,19 @@ func (self *Bucket) Set(key string, value []uint8) wit_types.Result[wit_types.Un //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.delete func wasm_import_method_bucket_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Bucket) Delete(key string) wit_types.Result[wit_types.Unit, Error] { +func (self *Bucket) Delete(key string) witTypes.Result[witTypes.Unit, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_bucket_delete((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[wit_types.Unit, Error] + var result witTypes.Result[witTypes.Unit, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, Error](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -326,7 +327,7 @@ func (self *Bucket) Delete(key string) wit_types.Result[wit_types.Unit, Error] { panic("unreachable") } - result = wit_types.Err[wit_types.Unit, Error](variant) + result = witTypes.Err[witTypes.Unit, Error](variant) default: panic("unreachable") } @@ -338,19 +339,19 @@ func (self *Bucket) Delete(key string) wit_types.Result[wit_types.Unit, Error] { //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.exists func wasm_import_method_bucket_exists(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *Bucket) Exists(key string) wit_types.Result[bool, Error] { +func (self *Bucket) Exists(key string) witTypes.Result[bool, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (4 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) utf8 := unsafe.Pointer(unsafe.StringData(key)) pinner.Pin(utf8) wasm_import_method_bucket_exists((self).Handle(), uintptr(utf8), uint32(len(key)), returnArea) - var result wit_types.Result[bool, Error] + var result witTypes.Result[bool, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) + result = witTypes.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -371,7 +372,7 @@ func (self *Bucket) Exists(key string) wit_types.Result[bool, Error] { panic("unreachable") } - result = wit_types.Err[bool, Error](variant) + result = witTypes.Err[bool, Error](variant) default: panic("unreachable") } @@ -383,21 +384,21 @@ func (self *Bucket) Exists(key string) wit_types.Result[bool, Error] { //go:wasmimport wasi:keyvalue/store@0.2.0-draft2 [method]bucket.list-keys func wasm_import_method_bucket_list_keys(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr) -func (self *Bucket) ListKeys(cursor wit_types.Option[string]) wit_types.Result[KeyResponse, Error] { +func (self *Bucket) ListKeys(cursor witTypes.Option[string]) witTypes.Result[KeyResponse, Error] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (6 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (6 * 4), 4)) var option int32 var option0 uintptr var option1 uint32 switch cursor.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option0 = 0 option1 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := cursor.Some() utf8 := unsafe.Pointer(unsafe.StringData(payload)) pinner.Pin(utf8) @@ -409,7 +410,7 @@ func (self *Bucket) ListKeys(cursor wit_types.Option[string]) wit_types.Result[K panic("unreachable") } wasm_import_method_bucket_list_keys((self).Handle(), option, option0, option1, returnArea) - var result5 wit_types.Result[KeyResponse, Error] + var result5 witTypes.Result[KeyResponse, Error] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -420,20 +421,20 @@ func (self *Bucket) ListKeys(cursor wit_types.Option[string]) wit_types.Result[K result = append(result, value) } - var option3 wit_types.Option[string] + var option3 witTypes.Option[string] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) { case 0: - option3 = wit_types.None[string]() + option3 = witTypes.None[string]() case 1: value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (5 * 4)))) - option3 = wit_types.Some[string](value2) + option3 = witTypes.Some[string](value2) default: panic("unreachable") } - result5 = wit_types.Ok[KeyResponse, Error](KeyResponse{result, option3}) + result5 = witTypes.Ok[KeyResponse, Error](KeyResponse{result, option3}) case 1: var variant Error switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { @@ -454,7 +455,7 @@ func (self *Bucket) ListKeys(cursor wit_types.Option[string]) wit_types.Result[K panic("unreachable") } - result5 = wit_types.Err[KeyResponse, Error](variant) + result5 = witTypes.Err[KeyResponse, Error](variant) default: panic("unreachable") } diff --git a/v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go b/internal/wasi_random_0_2_0_insecure/wit_bindings.go similarity index 91% rename from v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go rename to internal/wasi_random_0_2_0_insecure/wit_bindings.go index fd1d6118..bea902cb 100644 --- a/v3/internal/wasi_random_0_2_0_insecure/wit_bindings.go +++ b/internal/wasi_random_0_2_0_insecure/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_random_0_2_0_insecure import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" "unsafe" ) @@ -44,7 +44,7 @@ func GetInsecureRandomBytes(len uint64) []uint8 { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_get_insecure_random_bytes(int64(len), returnArea) value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) result := value diff --git a/v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go b/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go similarity index 77% rename from v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go rename to internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go index 309d7237..7dac2aea 100644 --- a/v3/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go +++ b/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package wasi_random_0_2_0_insecure_seed import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -45,9 +45,9 @@ func InsecureSeed() (uint64, uint64) { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_insecure_seed(returnArea) - result := wit_types.Tuple2[uint64, uint64]{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} + result := witTypes.Tuple2[uint64, uint64]{uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 0))), uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))} tuple := result return tuple.F0, tuple.F1 diff --git a/v3/internal/wasi_random_0_2_0_random/wit_bindings.go b/internal/wasi_random_0_2_0_random/wit_bindings.go similarity index 90% rename from v3/internal/wasi_random_0_2_0_random/wit_bindings.go rename to internal/wasi_random_0_2_0_random/wit_bindings.go index 71fbf034..985fae86 100644 --- a/v3/internal/wasi_random_0_2_0_random/wit_bindings.go +++ b/internal/wasi_random_0_2_0_random/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,7 +32,7 @@ package wasi_random_0_2_0_random import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" "unsafe" ) @@ -44,7 +44,7 @@ func GetRandomBytes(len uint64) []uint8 { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (2 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4)) wasm_import_get_random_bytes(int64(len), returnArea) value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) result := value diff --git a/v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go b/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go similarity index 96% rename from v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go rename to internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go index d7a4cd8e..912f0e2c 100644 --- a/v3/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin diff --git a/v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go b/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go similarity index 59% rename from v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go rename to internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go index ddf5b6ad..1eb1ec32 100644 --- a/v3/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,10 +32,10 @@ package wasi_sockets_0_2_0_ip_name_lookup import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -49,7 +49,7 @@ type IpAddress = wasi_sockets_0_2_0_network.IpAddress func resourceDropResolveAddressStream(handle int32) type ResolveAddressStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *ResolveAddressStream) TakeHandle() int32 { @@ -72,7 +72,7 @@ func (self *ResolveAddressStream) Drop() { } func ResolveAddressStreamFromOwnHandle(handleValue int32) *ResolveAddressStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &ResolveAddressStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -84,28 +84,29 @@ func ResolveAddressStreamFromOwnHandle(handleValue int32) *ResolveAddressStream } func ResolveAddressStreamFromBorrowHandle(handleValue int32) *ResolveAddressStream { - return ResolveAddressStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &ResolveAddressStream{handle} } //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses func wasm_import_resolve_addresses(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func ResolveAddresses(network *wasi_sockets_0_2_0_network.Network, name string) wit_types.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] { +func ResolveAddresses(network *wasi_sockets_0_2_0_network.Network, name string) witTypes.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) utf8 := unsafe.Pointer(unsafe.StringData(name)) pinner.Pin(utf8) wasm_import_resolve_addresses((network).Handle(), uintptr(utf8), uint32(len(name)), returnArea) - var result wit_types.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](ResolveAddressStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](ResolveAddressStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*ResolveAddressStream, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -117,44 +118,44 @@ func ResolveAddresses(network *wasi_sockets_0_2_0_network.Network, name string) //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address func wasm_import_method_resolve_address_stream_resolve_next_address(arg0 int32, arg1 uintptr) -func (self *ResolveAddressStream) ResolveNextAddress() wit_types.Result[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] { +func (self *ResolveAddressStream) ResolveNextAddress() witTypes.Result[witTypes.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 22, 2)) + returnArea := uintptr(witRuntime.Allocate(pinner, 22, 2)) wasm_import_method_resolve_address_stream_resolve_next_address((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - var option wit_types.Option[wasi_sockets_0_2_0_network.IpAddress] + var option witTypes.Option[wasi_sockets_0_2_0_network.IpAddress] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))) { case 0: - option = wit_types.None[wasi_sockets_0_2_0_network.IpAddress]() + option = witTypes.None[wasi_sockets_0_2_0_network.IpAddress]() case 1: var variant wasi_sockets_0_2_0_network.IpAddress switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv4(wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 7)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 9))))}) + variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv4(witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 7)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 9))))}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv6(wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 14)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))}) + variant = wasi_sockets_0_2_0_network.MakeIpAddressIpv6(witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 6)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 14)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20))))}) default: panic("unreachable") } - option = wit_types.Some[wasi_sockets_0_2_0_network.IpAddress](variant) + option = witTypes.Some[wasi_sockets_0_2_0_network.IpAddress](variant) default: panic("unreachable") } - result = wit_types.Ok[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](option) + result = witTypes.Ok[witTypes.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](option) case 1: - result = wit_types.Err[wit_types.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))))) + result = witTypes.Err[witTypes.Option[wasi_sockets_0_2_0_network.IpAddress], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 2))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go b/internal/wasi_sockets_0_2_0_network/wit_bindings.go similarity index 84% rename from v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go rename to internal/wasi_sockets_0_2_0_network/wit_bindings.go index 2d29c1f9..d791f8cc 100644 --- a/v3/internal/wasi_sockets_0_2_0_network/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_network/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,8 +32,8 @@ package wasi_sockets_0_2_0_network import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" ) @@ -44,7 +44,7 @@ func resourceDropNetwork(handle int32) // This enables context-based security for networking. // There is no need for this to map 1:1 to a physical network interface. type Network struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *Network) TakeHandle() int32 { @@ -67,7 +67,7 @@ func (self *Network) Drop() { } func NetworkFromOwnHandle(handleValue int32) *Network { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &Network{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -79,7 +79,8 @@ func NetworkFromOwnHandle(handleValue int32) *Network { } func NetworkFromBorrowHandle(handleValue int32) *Network { - return NetworkFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &Network{handle} } const ( @@ -166,8 +167,8 @@ const ( ) type IpAddressFamily = uint8 -type Ipv4Address = wit_types.Tuple4[uint8, uint8, uint8, uint8] -type Ipv6Address = wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] +type Ipv4Address = witTypes.Tuple4[uint8, uint8, uint8, uint8] +type Ipv6Address = witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] const ( IpAddressIpv4 uint8 = 0 @@ -183,23 +184,23 @@ func (self IpAddress) Tag() uint8 { return self.tag } -func (self IpAddress) Ipv4() wit_types.Tuple4[uint8, uint8, uint8, uint8] { +func (self IpAddress) Ipv4() witTypes.Tuple4[uint8, uint8, uint8, uint8] { if self.tag != IpAddressIpv4 { panic("tag mismatch") } - return self.value.(wit_types.Tuple4[uint8, uint8, uint8, uint8]) + return self.value.(witTypes.Tuple4[uint8, uint8, uint8, uint8]) } -func (self IpAddress) Ipv6() wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] { +func (self IpAddress) Ipv6() witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] { if self.tag != IpAddressIpv6 { panic("tag mismatch") } - return self.value.(wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) + return self.value.(witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) } -func MakeIpAddressIpv4(value wit_types.Tuple4[uint8, uint8, uint8, uint8]) IpAddress { +func MakeIpAddressIpv4(value witTypes.Tuple4[uint8, uint8, uint8, uint8]) IpAddress { return IpAddress{IpAddressIpv4, value} } -func MakeIpAddressIpv6(value wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) IpAddress { +func MakeIpAddressIpv6(value witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]) IpAddress { return IpAddress{IpAddressIpv6, value} } @@ -207,7 +208,7 @@ type Ipv4SocketAddress struct { // sin_port Port uint16 // sin_addr - Address wit_types.Tuple4[uint8, uint8, uint8, uint8] + Address witTypes.Tuple4[uint8, uint8, uint8, uint8] } type Ipv6SocketAddress struct { @@ -216,7 +217,7 @@ type Ipv6SocketAddress struct { // sin6_flowinfo FlowInfo uint32 // sin6_addr - Address wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] + Address witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16] // sin6_scope_id ScopeId uint32 } diff --git a/v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go b/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go similarity index 55% rename from v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go rename to internal/wasi_sockets_0_2_0_tcp/wit_bindings.go index a1421766..8bdfacbf 100644 --- a/v3/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,11 +32,11 @@ package wasi_sockets_0_2_0_tcp import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_streams" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -86,7 +86,7 @@ func resourceDropTcpSocket(handle int32) // `network::error-code` type, TCP socket methods may always return // `error(invalid-state)` when in the `closed` state. type TcpSocket struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *TcpSocket) TakeHandle() int32 { @@ -109,7 +109,7 @@ func (self *TcpSocket) Drop() { } func TcpSocketFromOwnHandle(handleValue int32) *TcpSocket { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &TcpSocket{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -121,17 +121,18 @@ func TcpSocketFromOwnHandle(handleValue int32) *TcpSocket { } func TcpSocketFromBorrowHandle(handleValue int32) *TcpSocket { - return TcpSocketFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &TcpSocket{handle} } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind func wasm_import_method_tcp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) -func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) var variant int32 var variant0 int32 var variant1 int32 @@ -181,14 +182,14 @@ func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, lo panic("unreachable") } wasm_import_method_tcp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -200,20 +201,20 @@ func (self *TcpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, lo //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind func wasm_import_method_tcp_socket_finish_bind(arg0 int32, arg1 uintptr) -func (self *TcpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) FinishBind() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_finish_bind((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -225,11 +226,11 @@ func (self *TcpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_socket //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect func wasm_import_method_tcp_socket_start_connect(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) -func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_0_network.Network, remoteAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_0_network.Network, remoteAddress wasi_sockets_0_2_0_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) var variant int32 var variant0 int32 var variant1 int32 @@ -279,14 +280,14 @@ func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_0_network.Network, panic("unreachable") } wasm_import_method_tcp_socket_start_connect((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -298,20 +299,20 @@ func (self *TcpSocket) StartConnect(network *wasi_sockets_0_2_0_network.Network, //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect func wasm_import_method_tcp_socket_finish_connect(arg0 int32, arg1 uintptr) -func (self *TcpSocket) FinishConnect() wit_types.Result[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) FinishConnect() witTypes.Result[witTypes.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) wasm_import_method_tcp_socket_finish_connect((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) + result = witTypes.Ok[witTypes.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](witTypes.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) case 1: - result = wit_types.Err[wit_types.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[witTypes.Tuple2[*wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -323,20 +324,20 @@ func (self *TcpSocket) FinishConnect() wit_types.Result[wit_types.Tuple2[*wasi_i //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen func wasm_import_method_tcp_socket_start_listen(arg0 int32, arg1 uintptr) -func (self *TcpSocket) StartListen() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) StartListen() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_start_listen((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -348,20 +349,20 @@ func (self *TcpSocket) StartListen() wit_types.Result[wit_types.Unit, wasi_socke //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen func wasm_import_method_tcp_socket_finish_listen(arg0 int32, arg1 uintptr) -func (self *TcpSocket) FinishListen() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) FinishListen() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_finish_listen((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -373,20 +374,20 @@ func (self *TcpSocket) FinishListen() wit_types.Result[wit_types.Unit, wasi_sock //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept func wasm_import_method_tcp_socket_accept(arg0 int32, arg1 uintptr) -func (self *TcpSocket) Accept() wit_types.Result[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) Accept() witTypes.Result[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 4)) wasm_import_method_tcp_socket_accept((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))}) + result = witTypes.Ok[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream]{TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), wasi_io_0_2_0_streams.InputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))), wasi_io_0_2_0_streams.OutputStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))))}) case 1: - result = wit_types.Err[wit_types.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[witTypes.Tuple3[*TcpSocket, *wasi_io_0_2_0_streams.InputStream, *wasi_io_0_2_0_streams.OutputStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -398,33 +399,33 @@ func (self *TcpSocket) Accept() wit_types.Result[wit_types.Tuple3[*TcpSocket, *w //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address func wasm_import_method_tcp_socket_local_address(arg0 int32, arg1 uintptr) -func (self *TcpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) LocalAddress() witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4)) wasm_import_method_tcp_socket_local_address((self).Handle(), returnArea) - var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: var variant wasi_sockets_0_2_0_network.IpSocketAddress switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) default: panic("unreachable") } - result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + result = witTypes.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) case 1: - result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -436,33 +437,33 @@ func (self *TcpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_networ //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address func wasm_import_method_tcp_socket_remote_address(arg0 int32, arg1 uintptr) -func (self *TcpSocket) RemoteAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) RemoteAddress() witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4)) wasm_import_method_tcp_socket_remote_address((self).Handle(), returnArea) - var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: var variant wasi_sockets_0_2_0_network.IpSocketAddress switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) default: panic("unreachable") } - result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + result = witTypes.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) case 1: - result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -494,20 +495,20 @@ func (self *TcpSocket) AddressFamily() wasi_sockets_0_2_0_network.IpAddressFamil //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size func wasm_import_method_tcp_socket_set_listen_backlog_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *TcpSocket) SetListenBacklogSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetListenBacklogSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_listen_backlog_size((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -519,20 +520,20 @@ func (self *TcpSocket) SetListenBacklogSize(value uint64) wit_types.Result[wit_t //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled func wasm_import_method_tcp_socket_keep_alive_enabled(arg0 int32, arg1 uintptr) -func (self *TcpSocket) KeepAliveEnabled() wit_types.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) KeepAliveEnabled() witTypes.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_keep_alive_enabled((self).Handle(), returnArea) - var result wit_types.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[bool, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[bool, wasi_sockets_0_2_0_network.ErrorCode]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) != 0)) + result = witTypes.Ok[bool, wasi_sockets_0_2_0_network.ErrorCode]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))) != 0)) case 1: - result = wit_types.Err[bool, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[bool, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -544,11 +545,11 @@ func (self *TcpSocket) KeepAliveEnabled() wit_types.Result[bool, wasi_sockets_0_ //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled func wasm_import_method_tcp_socket_set_keep_alive_enabled(arg0 int32, arg1 int32, arg2 uintptr) -func (self *TcpSocket) SetKeepAliveEnabled(value bool) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetKeepAliveEnabled(value bool) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) var result int32 if value { result = 1 @@ -556,14 +557,14 @@ func (self *TcpSocket) SetKeepAliveEnabled(value bool) wit_types.Result[wit_type result = 0 } wasm_import_method_tcp_socket_set_keep_alive_enabled((self).Handle(), result, returnArea) - var result0 wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result0 witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result0 = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result0 = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result0 = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -575,20 +576,20 @@ func (self *TcpSocket) SetKeepAliveEnabled(value bool) wit_types.Result[wit_type //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time func wasm_import_method_tcp_socket_keep_alive_idle_time(arg0 int32, arg1 uintptr) -func (self *TcpSocket) KeepAliveIdleTime() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) KeepAliveIdleTime() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_tcp_socket_keep_alive_idle_time((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -600,20 +601,20 @@ func (self *TcpSocket) KeepAliveIdleTime() wit_types.Result[uint64, wasi_sockets //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time func wasm_import_method_tcp_socket_set_keep_alive_idle_time(arg0 int32, arg1 int64, arg2 uintptr) -func (self *TcpSocket) SetKeepAliveIdleTime(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetKeepAliveIdleTime(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_keep_alive_idle_time((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -625,20 +626,20 @@ func (self *TcpSocket) SetKeepAliveIdleTime(value uint64) wit_types.Result[wit_t //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval func wasm_import_method_tcp_socket_keep_alive_interval(arg0 int32, arg1 uintptr) -func (self *TcpSocket) KeepAliveInterval() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) KeepAliveInterval() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_tcp_socket_keep_alive_interval((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -650,20 +651,20 @@ func (self *TcpSocket) KeepAliveInterval() wit_types.Result[uint64, wasi_sockets //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval func wasm_import_method_tcp_socket_set_keep_alive_interval(arg0 int32, arg1 int64, arg2 uintptr) -func (self *TcpSocket) SetKeepAliveInterval(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetKeepAliveInterval(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_keep_alive_interval((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -675,20 +676,20 @@ func (self *TcpSocket) SetKeepAliveInterval(value uint64) wit_types.Result[wit_t //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count func wasm_import_method_tcp_socket_keep_alive_count(arg0 int32, arg1 uintptr) -func (self *TcpSocket) KeepAliveCount() wit_types.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) KeepAliveCount() witTypes.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_method_tcp_socket_keep_alive_count((self).Handle(), returnArea) - var result wit_types.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint32, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + result = witTypes.Ok[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) case 1: - result = wit_types.Err[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[uint32, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -700,20 +701,20 @@ func (self *TcpSocket) KeepAliveCount() wit_types.Result[uint32, wasi_sockets_0_ //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count func wasm_import_method_tcp_socket_set_keep_alive_count(arg0 int32, arg1 int32, arg2 uintptr) -func (self *TcpSocket) SetKeepAliveCount(value uint32) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetKeepAliveCount(value uint32) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_keep_alive_count((self).Handle(), int32(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -725,20 +726,20 @@ func (self *TcpSocket) SetKeepAliveCount(value uint32) wit_types.Result[wit_type //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit func wasm_import_method_tcp_socket_hop_limit(arg0 int32, arg1 uintptr) -func (self *TcpSocket) HopLimit() wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) HopLimit() witTypes.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_hop_limit((self).Handle(), returnArea) - var result wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) case 1: - result = wit_types.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -750,20 +751,20 @@ func (self *TcpSocket) HopLimit() wit_types.Result[uint8, wasi_sockets_0_2_0_net //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit func wasm_import_method_tcp_socket_set_hop_limit(arg0 int32, arg1 int32, arg2 uintptr) -func (self *TcpSocket) SetHopLimit(value uint8) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetHopLimit(value uint8) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_hop_limit((self).Handle(), int32(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -775,20 +776,20 @@ func (self *TcpSocket) SetHopLimit(value uint8) wit_types.Result[wit_types.Unit, //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size func wasm_import_method_tcp_socket_receive_buffer_size(arg0 int32, arg1 uintptr) -func (self *TcpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) ReceiveBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_tcp_socket_receive_buffer_size((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -800,20 +801,20 @@ func (self *TcpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size func wasm_import_method_tcp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *TcpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetReceiveBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -825,20 +826,20 @@ func (self *TcpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_t //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size func wasm_import_method_tcp_socket_send_buffer_size(arg0 int32, arg1 uintptr) -func (self *TcpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SendBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_tcp_socket_send_buffer_size((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -850,20 +851,20 @@ func (self *TcpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_ //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size func wasm_import_method_tcp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *TcpSocket) SetSendBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) SetSendBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -885,20 +886,20 @@ func (self *TcpSocket) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown func wasm_import_method_tcp_socket_shutdown(arg0 int32, arg1 int32, arg2 uintptr) -func (self *TcpSocket) Shutdown(shutdownType ShutdownType) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *TcpSocket) Shutdown(shutdownType ShutdownType) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_tcp_socket_shutdown((self).Handle(), int32(shutdownType), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go b/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go similarity index 69% rename from v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go rename to internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go index 6649ccbe..b9b0aca2 100644 --- a/v3/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,10 +32,10 @@ package wasi_sockets_0_2_0_tcp_create_socket import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_tcp" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -48,20 +48,20 @@ type TcpSocket = wasi_sockets_0_2_0_tcp.TcpSocket //go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket func wasm_import_create_tcp_socket(arg0 int32, arg1 uintptr) -func CreateTcpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) wit_types.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] { +func CreateTcpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) witTypes.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_create_tcp_socket(int32(addressFamily), returnArea) - var result wit_types.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_tcp.TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_tcp.TcpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*wasi_sockets_0_2_0_tcp.TcpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go b/internal/wasi_sockets_0_2_0_udp/wit_bindings.go similarity index 65% rename from v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go rename to internal/wasi_sockets_0_2_0_udp/wit_bindings.go index f6850295..a8f9510d 100644 --- a/v3/internal/wasi_sockets_0_2_0_udp/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_udp/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,10 +32,10 @@ package wasi_sockets_0_2_0_udp import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_io_0_2_0_poll" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -71,7 +71,7 @@ type OutgoingDatagram struct { // - 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 wit_types.Option[wasi_sockets_0_2_0_network.IpSocketAddress] + RemoteAddress witTypes.Option[wasi_sockets_0_2_0_network.IpSocketAddress] } //go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket @@ -79,7 +79,7 @@ func resourceDropUdpSocket(handle int32) // A UDP socket handle. type UdpSocket struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *UdpSocket) TakeHandle() int32 { @@ -102,7 +102,7 @@ func (self *UdpSocket) Drop() { } func UdpSocketFromOwnHandle(handleValue int32) *UdpSocket { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &UdpSocket{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -114,14 +114,15 @@ func UdpSocketFromOwnHandle(handleValue int32) *UdpSocket { } func UdpSocketFromBorrowHandle(handleValue int32) *UdpSocket { - return UdpSocketFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &UdpSocket{handle} } //go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream func resourceDropIncomingDatagramStream(handle int32) type IncomingDatagramStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *IncomingDatagramStream) TakeHandle() int32 { @@ -144,7 +145,7 @@ func (self *IncomingDatagramStream) Drop() { } func IncomingDatagramStreamFromOwnHandle(handleValue int32) *IncomingDatagramStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &IncomingDatagramStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -156,14 +157,15 @@ func IncomingDatagramStreamFromOwnHandle(handleValue int32) *IncomingDatagramStr } func IncomingDatagramStreamFromBorrowHandle(handleValue int32) *IncomingDatagramStream { - return IncomingDatagramStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &IncomingDatagramStream{handle} } //go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream func resourceDropOutgoingDatagramStream(handle int32) type OutgoingDatagramStream struct { - handle *wit_runtime.Handle + handle *witRuntime.Handle } func (self *OutgoingDatagramStream) TakeHandle() int32 { @@ -186,7 +188,7 @@ func (self *OutgoingDatagramStream) Drop() { } func OutgoingDatagramStreamFromOwnHandle(handleValue int32) *OutgoingDatagramStream { - handle := wit_runtime.MakeHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) value := &OutgoingDatagramStream{handle} runtime.AddCleanup(value, func(_ int) { handleValue := handle.TakeOrNil() @@ -198,17 +200,18 @@ func OutgoingDatagramStreamFromOwnHandle(handleValue int32) *OutgoingDatagramStr } func OutgoingDatagramStreamFromBorrowHandle(handleValue int32) *OutgoingDatagramStream { - return OutgoingDatagramStreamFromOwnHandle(handleValue) + handle := witRuntime.MakeHandle(handleValue) + return &OutgoingDatagramStream{handle} } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind func wasm_import_method_udp_socket_start_bind(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) -func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, localAddress wasi_sockets_0_2_0_network.IpSocketAddress) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) var variant int32 var variant0 int32 var variant1 int32 @@ -258,14 +261,14 @@ func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, lo panic("unreachable") } wasm_import_method_udp_socket_start_bind((self).Handle(), (network).Handle(), variant, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -277,20 +280,20 @@ func (self *UdpSocket) StartBind(network *wasi_sockets_0_2_0_network.Network, lo //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind func wasm_import_method_udp_socket_finish_bind(arg0 int32, arg1 uintptr) -func (self *UdpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) FinishBind() witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_udp_socket_finish_bind((self).Handle(), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -302,11 +305,11 @@ func (self *UdpSocket) FinishBind() wit_types.Result[wit_types.Unit, wasi_socket //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream func wasm_import_method_udp_socket_stream(arg0 int32, arg1 int32, arg2 int32, arg3 int32, arg4 int32, arg5 int32, arg6 int32, arg7 int32, arg8 int32, arg9 int32, arg10 int32, arg11 int32, arg12 int32, arg13 int32, arg14 uintptr) -func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_network.IpSocketAddress]) wit_types.Result[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) Stream(remoteAddress witTypes.Option[wasi_sockets_0_2_0_network.IpSocketAddress]) witTypes.Result[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 12, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 12, 4)) var option int32 var option11 int32 var option12 int32 @@ -321,7 +324,7 @@ func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_ var option21 int32 var option22 int32 switch remoteAddress.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: option = int32(0) option11 = 0 @@ -336,7 +339,7 @@ func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_ option20 = 0 option21 = 0 option22 = 0 - case wit_types.OptionSome: + case witTypes.OptionSome: payload := remoteAddress.Some() var variant int32 var variant0 int32 @@ -404,14 +407,14 @@ func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_ panic("unreachable") } wasm_import_method_udp_socket_stream((self).Handle(), option, option11, option12, option13, option14, option15, option16, option17, option18, option19, option20, option21, option22, returnArea) - var result wit_types.Result[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream]{IncomingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), OutgoingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) + result = witTypes.Ok[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream]{IncomingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), OutgoingDatagramStreamFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))))}) case 1: - result = wit_types.Err[wit_types.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[witTypes.Tuple2[*IncomingDatagramStream, *OutgoingDatagramStream], wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -423,33 +426,33 @@ func (self *UdpSocket) Stream(remoteAddress wit_types.Option[wasi_sockets_0_2_0_ //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address func wasm_import_method_udp_socket_local_address(arg0 int32, arg1 uintptr) -func (self *UdpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) LocalAddress() witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4)) wasm_import_method_udp_socket_local_address((self).Handle(), returnArea) - var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: var variant wasi_sockets_0_2_0_network.IpSocketAddress switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) default: panic("unreachable") } - result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + result = witTypes.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) case 1: - result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -461,33 +464,33 @@ func (self *UdpSocket) LocalAddress() wit_types.Result[wasi_sockets_0_2_0_networ //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address func wasm_import_method_udp_socket_remote_address(arg0 int32, arg1 uintptr) -func (self *UdpSocket) RemoteAddress() wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) RemoteAddress() witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 36, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 36, 4)) wasm_import_method_udp_socket_remote_address((self).Handle(), returnArea) - var result wit_types.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: var variant wasi_sockets_0_2_0_network.IpSocketAddress switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 10)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 11)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 12)))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 13))))}}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 12))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 16)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 18)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 20)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 22)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 24)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 26)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 28)))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 30))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 32)))}) default: panic("unreachable") } - result = wit_types.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) + result = witTypes.Ok[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](variant) case 1: - result = wit_types.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[wasi_sockets_0_2_0_network.IpSocketAddress, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -509,20 +512,20 @@ func (self *UdpSocket) AddressFamily() wasi_sockets_0_2_0_network.IpAddressFamil //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit func wasm_import_method_udp_socket_unicast_hop_limit(arg0 int32, arg1 uintptr) -func (self *UdpSocket) UnicastHopLimit() wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) UnicastHopLimit() witTypes.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_udp_socket_unicast_hop_limit((self).Handle(), returnArea) - var result wit_types.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint8, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Ok[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) case 1: - result = wit_types.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[uint8, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -534,20 +537,20 @@ func (self *UdpSocket) UnicastHopLimit() wit_types.Result[uint8, wasi_sockets_0_ //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit func wasm_import_method_udp_socket_set_unicast_hop_limit(arg0 int32, arg1 int32, arg2 uintptr) -func (self *UdpSocket) SetUnicastHopLimit(value uint8) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) SetUnicastHopLimit(value uint8) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_udp_socket_set_unicast_hop_limit((self).Handle(), int32(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -559,20 +562,20 @@ func (self *UdpSocket) SetUnicastHopLimit(value uint8) wit_types.Result[wit_type //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size func wasm_import_method_udp_socket_receive_buffer_size(arg0 int32, arg1 uintptr) -func (self *UdpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) ReceiveBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_udp_socket_receive_buffer_size((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -584,20 +587,20 @@ func (self *UdpSocket) ReceiveBufferSize() wit_types.Result[uint64, wasi_sockets //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size func wasm_import_method_udp_socket_set_receive_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *UdpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) SetReceiveBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_udp_socket_set_receive_buffer_size((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -609,20 +612,20 @@ func (self *UdpSocket) SetReceiveBufferSize(value uint64) wit_types.Result[wit_t //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size func wasm_import_method_udp_socket_send_buffer_size(arg0 int32, arg1 uintptr) -func (self *UdpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) SendBufferSize() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_udp_socket_send_buffer_size((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -634,20 +637,20 @@ func (self *UdpSocket) SendBufferSize() wit_types.Result[uint64, wasi_sockets_0_ //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size func wasm_import_method_udp_socket_set_send_buffer_size(arg0 int32, arg1 int64, arg2 uintptr) -func (self *UdpSocket) SetSendBufferSize(value uint64) wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *UdpSocket) SetSendBufferSize(value uint64) witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 2, 1)) + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) wasm_import_method_udp_socket_set_send_buffer_size((self).Handle(), int64(value), returnArea) - var result wit_types.Result[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](wit_types.Unit{}) + result = witTypes.Ok[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](witTypes.Unit{}) case 1: - result = wit_types.Err[wit_types.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + result = witTypes.Err[witTypes.Unit, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) default: panic("unreachable") } @@ -669,13 +672,13 @@ func (self *UdpSocket) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive func wasm_import_method_incoming_datagram_stream_receive(arg0 int32, arg1 int64, arg2 uintptr) -func (self *IncomingDatagramStream) Receive(maxResults uint64) wit_types.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *IncomingDatagramStream) Receive(maxResults uint64) witTypes.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, (3 * 4), 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) wasm_import_method_incoming_datagram_stream_receive((self).Handle(), int64(maxResults), returnArea) - var result0 wit_types.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] + var result0 witTypes.Result[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: result := make([]IncomingDatagram, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) @@ -686,11 +689,11 @@ func (self *IncomingDatagramStream) Receive(maxResults uint64) wit_types.Result[ switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))) { case 0: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), wit_types.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (6 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (7 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (9 + 2*4)))))}}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv4(wasi_sockets_0_2_0_network.Ipv4SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), witTypes.Tuple4[uint8, uint8, uint8, uint8]{uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (6 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (7 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4))))), uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (9 + 2*4)))))}}) case 1: - variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4)))), wit_types.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (14 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4)))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))))}) + variant = wasi_sockets_0_2_0_network.MakeIpSocketAddressIpv6(wasi_sockets_0_2_0_network.Ipv6SocketAddress{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (4 + 2*4))))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (8 + 2*4)))), witTypes.Tuple8[uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16]{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (12 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (14 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (16 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (18 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (20 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (22 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (24 + 2*4))))), uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (26 + 2*4)))))}, uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), (28 + 2*4))))}) default: panic("unreachable") @@ -699,10 +702,10 @@ func (self *IncomingDatagramStream) Receive(maxResults uint64) wit_types.Result[ result = append(result, IncomingDatagram{value, variant}) } - result0 = wit_types.Ok[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](result) + result0 = witTypes.Ok[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](result) case 1: - result0 = wit_types.Err[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result0 = witTypes.Err[[]IncomingDatagram, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } @@ -724,20 +727,20 @@ func (self *IncomingDatagramStream) Subscribe() *wasi_io_0_2_0_poll.Pollable { //go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send func wasm_import_method_outgoing_datagram_stream_check_send(arg0 int32, arg1 uintptr) -func (self *OutgoingDatagramStream) CheckSend() wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *OutgoingDatagramStream) CheckSend() witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) wasm_import_method_outgoing_datagram_stream_check_send((self).Handle(), returnArea) - var result wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } @@ -749,14 +752,14 @@ func (self *OutgoingDatagramStream) CheckSend() wit_types.Result[uint64, wasi_so //go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send func wasm_import_method_outgoing_datagram_stream_send(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) -func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { +func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 16, 8)) + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) slice := datagrams length := uint32(len(slice)) - result := wit_runtime.Allocate(pinner, uintptr(length*(32+3*4)), 4) + result := witRuntime.Allocate(pinner, uintptr(length*(32+3*4)), 4) for index, element := range slice { base := unsafe.Add(result, index*(32+3*4)) data := unsafe.Pointer(unsafe.SliceData((element).Data)) @@ -765,10 +768,10 @@ func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) wit_types *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(data))) switch (element).RemoteAddress.Tag() { - case wit_types.OptionNone: + case witTypes.OptionNone: *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(0)) - case wit_types.OptionSome: + case witTypes.OptionSome: payload := (element).RemoteAddress.Some() *(*int8)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = int8(int32(1)) @@ -808,14 +811,14 @@ func (self *OutgoingDatagramStream) Send(datagrams []OutgoingDatagram) wit_types } wasm_import_method_outgoing_datagram_stream_send((self).Handle(), uintptr(result), length, returnArea) - var result0 wit_types.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] + var result0 witTypes.Result[uint64, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result0 = wit_types.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + result0 = witTypes.Ok[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) case 1: - result0 = wit_types.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + result0 = witTypes.Err[uint64, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) default: panic("unreachable") } diff --git a/v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go b/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go similarity index 69% rename from v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go rename to internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go index 4b570111..93b61729 100644 --- a/v3/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,10 +32,10 @@ package wasi_sockets_0_2_0_udp_create_socket import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" - "github.com/bytecodealliance/wit-bindgen/wit_types" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_network" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_sockets_0_2_0_udp" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" "unsafe" ) @@ -48,20 +48,20 @@ type UdpSocket = wasi_sockets_0_2_0_udp.UdpSocket //go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket func wasm_import_create_udp_socket(arg0 int32, arg1 uintptr) -func CreateUdpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) wit_types.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] { +func CreateUdpSocket(addressFamily wasi_sockets_0_2_0_network.IpAddressFamily) witTypes.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] { pinner := &runtime.Pinner{} defer pinner.Unpin() - returnArea := uintptr(wit_runtime.Allocate(pinner, 8, 4)) + returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4)) wasm_import_create_udp_socket(int32(addressFamily), returnArea) - var result wit_types.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] + var result witTypes.Result[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode] switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { case 0: - result = wit_types.Ok[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_udp.UdpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) + result = witTypes.Ok[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](wasi_sockets_0_2_0_udp.UdpSocketFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))))) case 1: - result = wit_types.Err[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + result = witTypes.Err[*wasi_sockets_0_2_0_udp.UdpSocket, wasi_sockets_0_2_0_network.ErrorCode](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) default: panic("unreachable") } diff --git a/v3/internal/wit_exports/wit_exports.go b/internal/wit_exports/wit_exports.go similarity index 89% rename from v3/internal/wit_exports/wit_exports.go rename to internal/wit_exports/wit_exports.go index 6da69cee..a50c6d48 100644 --- a/v3/internal/wit_exports/wit_exports.go +++ b/internal/wit_exports/wit_exports.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! // // This code was generated from the following packages: // fermyon:spin @@ -32,14 +32,14 @@ package wit_exports import ( - "github.com/bytecodealliance/wit-bindgen/wit_runtime" "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" "runtime" ) var staticPinner = runtime.Pinner{} -var exportReturnArea = uintptr(wit_runtime.Allocate(&staticPinner, 0, 1)) +var exportReturnArea = uintptr(witRuntime.Allocate(&staticPinner, 0, 1)) var syncExportPinner = runtime.Pinner{} //go:wasmexport wasi:http/incoming-handler@0.2.0#handle diff --git a/kv/key-value.c b/kv/key-value.c deleted file mode 100644 index bcb03cc8..00000000 --- a/kv/key-value.c +++ /dev/null @@ -1,367 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void key_value_string_set(key_value_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void key_value_string_dup(key_value_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void key_value_string_free(key_value_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void key_value_error_free(key_value_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 5: { - key_value_string_free(&ptr->val.io); - break; - } - } -} -void key_value_expected_store_error_free(key_value_expected_store_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_list_u8_free(key_value_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void key_value_expected_list_u8_error_free(key_value_expected_list_u8_error_t *ptr) { - if (!ptr->is_err) { - key_value_list_u8_free(&ptr->val.ok); - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_expected_unit_error_free(key_value_expected_unit_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_expected_bool_error_free(key_value_expected_bool_error_t *ptr) { - if (!ptr->is_err) { - } else { - key_value_error_free(&ptr->val.err); - } -} -void key_value_list_string_free(key_value_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - key_value_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void key_value_expected_list_string_error_free(key_value_expected_list_string_error_t *ptr) { - if (!ptr->is_err) { - key_value_list_string_free(&ptr->val.ok); - } else { - key_value_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("key-value"), import_name("open"))) -void __wasm_import_key_value_open(int32_t, int32_t, int32_t); -void key_value_open(key_value_string_t *name, key_value_expected_store_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_open((int32_t) (*name).ptr, (int32_t) (*name).len, ptr); - key_value_expected_store_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint32_t) (*((int32_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("get"))) -void __wasm_import_key_value_get(int32_t, int32_t, int32_t, int32_t); -void key_value_get(key_value_store_t store, key_value_string_t *key, key_value_expected_list_u8_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_get((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_list_u8_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (key_value_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("set"))) -void __wasm_import_key_value_set(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void key_value_set(key_value_store_t store, key_value_string_t *key, key_value_list_u8_t *value, key_value_expected_unit_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_set((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*value).ptr, (int32_t) (*value).len, ptr); - key_value_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("delete"))) -void __wasm_import_key_value_delete(int32_t, int32_t, int32_t, int32_t); -void key_value_delete(key_value_store_t store, key_value_string_t *key, key_value_expected_unit_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_delete((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("exists"))) -void __wasm_import_key_value_exists(int32_t, int32_t, int32_t, int32_t); -void key_value_exists(key_value_store_t store, key_value_string_t *key, key_value_expected_bool_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_exists((int32_t) (store), (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - key_value_expected_bool_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("get-keys"))) -void __wasm_import_key_value_get_keys(int32_t, int32_t); -void key_value_get_keys(key_value_store_t store, key_value_expected_list_string_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_key_value_get_keys((int32_t) (store), ptr); - key_value_expected_list_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (key_value_list_string_t) { (key_value_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - key_value_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - break; - } - case 5: { - variant.val.io = (key_value_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("key-value"), import_name("close"))) -void __wasm_import_key_value_close(int32_t); -void key_value_close(key_value_store_t store) { - __wasm_import_key_value_close((int32_t) (store)); -} diff --git a/kv/key-value.h b/kv/key-value.h deleted file mode 100644 index 7b78b032..00000000 --- a/kv/key-value.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef __BINDINGS_KEY_VALUE_H -#define __BINDINGS_KEY_VALUE_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } key_value_string_t; - - void key_value_string_set(key_value_string_t *ret, const char *s); - void key_value_string_dup(key_value_string_t *ret, const char *s); - void key_value_string_free(key_value_string_t *ret); - typedef uint32_t key_value_store_t; - typedef struct { - uint8_t tag; - union { - key_value_string_t io; - } val; - } key_value_error_t; - #define KEY_VALUE_ERROR_STORE_TABLE_FULL 0 - #define KEY_VALUE_ERROR_NO_SUCH_STORE 1 - #define KEY_VALUE_ERROR_ACCESS_DENIED 2 - #define KEY_VALUE_ERROR_INVALID_STORE 3 - #define KEY_VALUE_ERROR_NO_SUCH_KEY 4 - #define KEY_VALUE_ERROR_IO 5 - void key_value_error_free(key_value_error_t *ptr); - typedef struct { - bool is_err; - union { - key_value_store_t ok; - key_value_error_t err; - } val; - } key_value_expected_store_error_t; - void key_value_expected_store_error_free(key_value_expected_store_error_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } key_value_list_u8_t; - void key_value_list_u8_free(key_value_list_u8_t *ptr); - typedef struct { - bool is_err; - union { - key_value_list_u8_t ok; - key_value_error_t err; - } val; - } key_value_expected_list_u8_error_t; - void key_value_expected_list_u8_error_free(key_value_expected_list_u8_error_t *ptr); - typedef struct { - bool is_err; - union { - key_value_error_t err; - } val; - } key_value_expected_unit_error_t; - void key_value_expected_unit_error_free(key_value_expected_unit_error_t *ptr); - typedef struct { - bool is_err; - union { - bool ok; - key_value_error_t err; - } val; - } key_value_expected_bool_error_t; - void key_value_expected_bool_error_free(key_value_expected_bool_error_t *ptr); - typedef struct { - key_value_string_t *ptr; - size_t len; - } key_value_list_string_t; - void key_value_list_string_free(key_value_list_string_t *ptr); - typedef struct { - bool is_err; - union { - key_value_list_string_t ok; - key_value_error_t err; - } val; - } key_value_expected_list_string_error_t; - void key_value_expected_list_string_error_free(key_value_expected_list_string_error_t *ptr); - void key_value_open(key_value_string_t *name, key_value_expected_store_error_t *ret0); - void key_value_get(key_value_store_t store, key_value_string_t *key, key_value_expected_list_u8_error_t *ret0); - void key_value_set(key_value_store_t store, key_value_string_t *key, key_value_list_u8_t *value, key_value_expected_unit_error_t *ret0); - void key_value_delete(key_value_store_t store, key_value_string_t *key, key_value_expected_unit_error_t *ret0); - void key_value_exists(key_value_store_t store, key_value_string_t *key, key_value_expected_bool_error_t *ret0); - void key_value_get_keys(key_value_store_t store, key_value_expected_list_string_error_t *ret0); - void key_value_close(key_value_store_t store); - #ifdef __cplusplus -} -#endif -#endif diff --git a/kv/kv.go b/kv/kv.go index c5216600..e45af711 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -1,148 +1,100 @@ -// Package kv provides access to key value stores within Spin -// components. package kv -// #include "key-value.h" -import "C" import ( - "errors" "fmt" - "unsafe" + + keyvalue "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_key_value" ) -// Store is the Key/Value backend storage. type Store struct { - name string - active bool - ptr C.key_value_store_t -} - -// OpenStore creates a new instance of Store and opens a connection. -func OpenStore(name string) (*Store, error) { - s := &Store{name: name} - if err := s.open(); err != nil { - return nil, err - } - return s, nil + store *keyvalue.Store } -// Close terminates the connection to Store. -func (s *Store) Close() { - if s.active { - C.key_value_close(C.uint32_t(s.ptr)) +// Open the store with the label. +func Open(label string) (*Store, error) { + result := keyvalue.StoreOpen(label) + if result.IsErr() { + return nil, errorVariantToError(result.Err()) } - s.active = false -} -// Get retrieves a value from Store. -func (s *Store) Get(key string) ([]byte, error) { - ckey := toCStr(key) - var ret C.key_value_expected_list_u8_error_t - C.key_value_get(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return nil, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - list := (*C.key_value_list_u8_t)(unsafe.Pointer(&ret.val)) - return C.GoBytes(unsafe.Pointer(list.ptr), C.int(list.len)), nil + return &Store{ + store: result.Ok(), + }, nil } -// Delete removes a value from Store. -func (s *Store) Delete(key string) error { - ckey := toCStr(key) - var ret C.key_value_expected_unit_error_t - C.key_value_delete(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) - } - return nil +// Open the default store. +// +// This is equivalent to `kv.Open("default")`. +func OpenDefault() (*Store, error) { + return Open("default") } -// Set creates a new key/value in Store. +// Set the key/value pair in store func (s *Store) Set(key string, value []byte) error { - ckey := toCStr(key) - cbytes := toCBytes(value) - var ret C.key_value_expected_unit_error_t - C.key_value_set(C.uint32_t(s.ptr), &ckey, &cbytes, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) + result := s.store.Set(key, value) + if result.IsErr() { + return errorVariantToError(result.Err()) } + return nil } -// Exists checks if a key exists within Store. -func (s *Store) Exists(key string) (bool, error) { - ckey := toCStr(key) - var ret C.key_value_expected_bool_error_t - C.key_value_exists(C.uint32_t(s.ptr), &ckey, &ret) - if ret.is_err { - return false, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) +// Get the value of provided key from the store +func (s *Store) Get(key string) ([]byte, error) { + result := s.store.Get(key) + if result.IsErr() { + return nil, errorVariantToError(result.Err()) } - return *(*bool)(unsafe.Pointer(&ret.val)), nil -} -// GetKeys retrieves the list of keys from Store. -func (s *Store) GetKeys() ([]string, error) { - var ret C.key_value_expected_list_string_error_t - C.key_value_get_keys(C.uint32_t(s.ptr), &ret) - if ret.is_err { - return nil, toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) + value := result.Ok() + if value.IsNone() { + return []byte(""), nil } - list := (*C.key_value_list_string_t)(unsafe.Pointer(&ret.val)) - return fromCStrList(list), nil + + return value.Some(), nil } -func (s *Store) open() error { - if s.active { - return nil - } - cname := toCStr(s.name) - var ret C.key_value_expected_store_error_t - C.key_value_open(&cname, &ret) - if ret.is_err { - return toErr((*C.key_value_error_t)(unsafe.Pointer(&ret.val))) +// Delete the given key/value from the store +func (s *Store) Delete(key string) error { + result := s.store.Delete(key) + if result.IsErr() { + return errorVariantToError(result.Err()) } - s.ptr = *(*C.key_value_store_t)(unsafe.Pointer(&ret.val)) - s.active = true + return nil } -func toCBytes(x []byte) C.key_value_list_u8_t { - return C.key_value_list_u8_t{ptr: (*C.uint8_t)(unsafe.Pointer(&x[0])), len: C.size_t(len(x))} -} +// Exists check if a given key exist in the store +func (s *Store) Exists(key string) (bool, error) { + result := s.store.Exists(key) + if result.IsErr() { + return false, errorVariantToError(result.Err()) + } -func toCStr(x string) C.key_value_string_t { - return C.key_value_string_t{ptr: C.CString(x), len: C.size_t(len(x))} + return result.Ok(), nil } -func fromCStrList(list *C.key_value_list_string_t) []string { - var result []string - - listLen := int(list.len) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - result = append(result, C.GoStringN(str.ptr, C.int(str.len))) +// GetKets returns all the keys from the store +func (s *Store) GetKeys() ([]string, error) { + result := s.store.GetKeys() + if result.IsErr() { + return nil, errorVariantToError(result.Err()) } - return result + return result.Ok(), nil } -func toErr(err *C.key_value_error_t) error { - switch err.tag { - case 0: - return errors.New("store table full") - case 1: - return errors.New("no such store") - case 2: - return errors.New("access denied") - case 3: - return errors.New("invalid store") - case 4: - return errors.New("no such key") - case 5: - str := (*C.key_value_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("io error: %s", C.GoStringN(str.ptr, C.int(str.len))) +func errorVariantToError(code keyvalue.Error) error { + switch code.Tag() { + case keyvalue.ErrorAccessDenied: + return fmt.Errorf("access denied") + case keyvalue.ErrorNoSuchStore: + return fmt.Errorf("no such store") + case keyvalue.ErrorStoreTableFull: + return fmt.Errorf("store table full") + case keyvalue.ErrorOther: + return fmt.Errorf("%v", code.Other()) default: - return fmt.Errorf("unrecognized error: %v", err.tag) + return fmt.Errorf("no error provided by host implementation") } } diff --git a/kv/testdata/key-value/go.mod b/kv/testdata/key-value/go.mod new file mode 100644 index 00000000..0063085a --- /dev/null +++ b/kv/testdata/key-value/go.mod @@ -0,0 +1,11 @@ +module github.com/spinframework/spin-go-sdk/v3/http/testdata/kv + +go 1.25.5 + +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v3/examples/llm/go.sum b/kv/testdata/key-value/go.sum similarity index 71% rename from v3/examples/llm/go.sum rename to kv/testdata/key-value/go.sum index 00db3b18..b5bca15f 100644 --- a/v3/examples/llm/go.sum +++ b/kv/testdata/key-value/go.sum @@ -2,3 +2,5 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/examples/kv/main.go b/kv/testdata/key-value/main.go similarity index 100% rename from v3/examples/kv/main.go rename to kv/testdata/key-value/main.go diff --git a/v3/kv/testdata/key-value/spin.toml b/kv/testdata/key-value/spin.toml similarity index 94% rename from v3/kv/testdata/key-value/spin.toml rename to kv/testdata/key-value/spin.toml index 3fecd43a..b9a7e2d3 100644 --- a/v3/kv/testdata/key-value/spin.toml +++ b/kv/testdata/key-value/spin.toml @@ -14,5 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" +command = "componentize-go --world http-trigger --wit-path ../../../wit build" diff --git a/llm/internals.go b/llm/internals.go deleted file mode 100644 index 4c644273..00000000 --- a/llm/internals.go +++ /dev/null @@ -1,131 +0,0 @@ -package llm - -// #include "llm.h" -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func infer(model, prompt string, params *InferencingParams) (*InferencingResult, error) { - llmModel := toLLMModel(model) - llmPrompt := toLLMString(prompt) - llmParams := toLLMInferencingParams(params) - - var ret C.llm_expected_inferencing_result_error_t - defer C.llm_expected_inferencing_result_error_free(&ret) - - C.llm_infer(&llmModel, &llmPrompt, &llmParams, &ret) - if ret.is_err { - return nil, toErr((*C.llm_error_t)(unsafe.Pointer(&ret.val))) - } - - result := (*C.llm_inferencing_result_t)(unsafe.Pointer(&ret.val)) - - r := &InferencingResult{ - Text: C.GoStringN(result.text.ptr, C.int(result.text.len)), - Usage: &InferencingUsage{ - PromptTokenCount: int(result.usage.prompt_token_count), - GeneratedTokenCount: int(result.usage.generated_token_count), - }, - } - return r, nil -} - -func toErr(err *C.llm_error_t) error { - switch err.tag { - case 0: - return errors.New("model not supported") - case 1: - str := (*C.llm_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("runtime error: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.llm_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("invalid input error: %s", C.GoStringN(str.ptr, C.int(str.len))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -func toLLMModel(name string) C.llm_inferencing_model_t { - llmString := toLLMString(name) - return *(*C.llm_inferencing_model_t)(unsafe.Pointer(&llmString.ptr)) -} - -func toLLMString(x string) C.llm_string_t { - return C.llm_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toLLMInferencingParams(p *InferencingParams) C.llm_option_inferencing_params_t { - if p == nil { - return C.llm_option_inferencing_params_t{is_some: false} - } - llmParams := C.llm_inferencing_params_t{ - max_tokens: C.uint32_t(p.MaxTokens), - repeat_penalty: C.float(p.RepeatPenalty), - repeat_penalty_last_n_token_count: C.uint32_t(p.RepeatPenaltyLastNTokenCount), - temperature: C.float(p.Temperature), - top_k: C.uint32_t(p.TopK), - top_p: C.float(p.TopP), - } - return C.llm_option_inferencing_params_t{is_some: true, val: llmParams} -} - -func generateEmbeddings(model string, text []string) (*EmbeddingsResult, error) { - llmModel := toLLMEmbeddingModel(model) - llmListString := toLLMListString(text) - - var ret C.llm_expected_embeddings_result_error_t - defer C.llm_expected_embeddings_result_error_free(&ret) - - C.llm_generate_embeddings(&llmModel, &llmListString, &ret) - if ret.is_err { - return nil, toErr((*C.llm_error_t)(unsafe.Pointer(&ret.val))) - } - - result := (*C.llm_embeddings_result_t)(unsafe.Pointer(&ret.val)) - - r := &EmbeddingsResult{ - Embeddings: fromLLMListListFloat32(result.embeddings), - Usage: &EmbeddingsUsage{ - PromptTokenCount: int(result.usage.prompt_token_count), - }, - } - return r, nil -} - -func toLLMEmbeddingModel(name string) C.llm_embedding_model_t { - llmString := toLLMString(name) - return *(*C.llm_embedding_model_t)(unsafe.Pointer(&llmString.ptr)) -} - -func toLLMListString(xs []string) C.llm_list_string_t { - cxs := make([]C.llm_string_t, len(xs)) - for i := 0; i < len(xs); i++ { - cxs[i] = toLLMString(xs[i]) - } - return C.llm_list_string_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromLLMListListFloat32(list C.llm_list_list_float32_t) [][]float32 { - listLen := int(list.len) - ret := make([][]float32, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.llm_list_float32_t)(unsafe.Pointer(&slice[i]))) - ret[i] = fromLLMListFloat32(row) - } - return ret -} - -func fromLLMListFloat32(list C.llm_list_float32_t) []float32 { - listLen := int(list.len) - ret := make([]float32, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - v := *((*C.float)(unsafe.Pointer(&slice[i]))) - ret[i] = float32(v) - } - return ret -} diff --git a/llm/llm.c b/llm/llm.c deleted file mode 100644 index 47420298..00000000 --- a/llm/llm.c +++ /dev/null @@ -1,213 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void llm_string_set(llm_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void llm_string_dup(llm_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void llm_string_free(llm_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void llm_inferencing_model_free(llm_inferencing_model_t *ptr) { - llm_string_free(ptr); -} -void llm_error_free(llm_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - llm_string_free(&ptr->val.runtime_error); - break; - } - case 2: { - llm_string_free(&ptr->val.invalid_input); - break; - } - } -} -void llm_inferencing_result_free(llm_inferencing_result_t *ptr) { - llm_string_free(&ptr->text); -} -void llm_embedding_model_free(llm_embedding_model_t *ptr) { - llm_string_free(ptr); -} -void llm_list_float32_free(llm_list_float32_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 4, 4); -} -void llm_list_list_float32_free(llm_list_list_float32_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - llm_list_float32_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void llm_embeddings_result_free(llm_embeddings_result_t *ptr) { - llm_list_list_float32_free(&ptr->embeddings); -} -void llm_expected_inferencing_result_error_free(llm_expected_inferencing_result_error_t *ptr) { - if (!ptr->is_err) { - llm_inferencing_result_free(&ptr->val.ok); - } else { - llm_error_free(&ptr->val.err); - } -} -void llm_list_string_free(llm_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - llm_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void llm_expected_embeddings_result_error_free(llm_expected_embeddings_result_error_t *ptr) { - if (!ptr->is_err) { - llm_embeddings_result_free(&ptr->val.ok); - } else { - llm_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("llm"), import_name("infer"))) -void __wasm_import_llm_infer(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, float, int32_t, float, int32_t, float, int32_t); -void llm_infer(llm_inferencing_model_t *model, llm_string_t *prompt, llm_option_inferencing_params_t *params, llm_expected_inferencing_result_error_t *ret0) { - int32_t option; - int32_t option1; - float option2; - int32_t option3; - float option4; - int32_t option5; - float option6; - - if ((*params).is_some) { - const llm_inferencing_params_t *payload0 = &(*params).val; - option = 1; - option1 = (int32_t) ((*payload0).max_tokens); - option2 = (*payload0).repeat_penalty; - option3 = (int32_t) ((*payload0).repeat_penalty_last_n_token_count); - option4 = (*payload0).temperature; - option5 = (int32_t) ((*payload0).top_k); - option6 = (*payload0).top_p; - - } else { - option = 0; - option1 = 0; - option2 = 0; - option3 = 0; - option4 = 0; - option5 = 0; - option6 = 0; - - } - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_llm_infer((int32_t) (*model).ptr, (int32_t) (*model).len, (int32_t) (*prompt).ptr, (int32_t) (*prompt).len, option, option1, option2, option3, option4, option5, option6, ptr); - llm_expected_inferencing_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (llm_inferencing_result_t) { - (llm_string_t) { (char*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (llm_inferencing_usage_t) { - (uint32_t) (*((int32_t*) (ptr + 12))), - (uint32_t) (*((int32_t*) (ptr + 16))), - }, - }; - break; - } - case 1: { - expected.is_err = true; - llm_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.runtime_error = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_input = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("llm"), import_name("generate-embeddings"))) -void __wasm_import_llm_generate_embeddings(int32_t, int32_t, int32_t, int32_t, int32_t); -void llm_generate_embeddings(llm_embedding_model_t *model, llm_list_string_t *text, llm_expected_embeddings_result_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_llm_generate_embeddings((int32_t) (*model).ptr, (int32_t) (*model).len, (int32_t) (*text).ptr, (int32_t) (*text).len, ptr); - llm_expected_embeddings_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (llm_embeddings_result_t) { - (llm_list_list_float32_t) { (llm_list_float32_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (llm_embeddings_usage_t) { - (uint32_t) (*((int32_t*) (ptr + 12))), - }, - }; - break; - } - case 1: { - expected.is_err = true; - llm_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.runtime_error = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_input = (llm_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/llm/llm.go b/llm/llm.go index 292c9068..decd0981 100644 --- a/llm/llm.go +++ b/llm/llm.go @@ -1,56 +1,67 @@ -// Package llm provides the interface to use Large Language Models in Spin. package llm -// InferenceParams is the optional request parameters. +import ( + "fmt" + + llm "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_llm" + wit "go.bytecodealliance.org/pkg/wit/types" +) + +// The model use for inferencing +const ( + Llama2Chat InferencingModel = "llama2-chat" + CodellamaInstruct InferencingModel = "codellama-instruct" +) + type InferencingParams struct { - // MaxTokens is the maximum tokens that should be inferred. - // Default: 100 + // The maximum tokens that should be inferred. // // Note: the backing implementation may return less tokens. - MaxTokens int32 - // RepeatPenalty is the amount the model should avoid repeating tokens. - // Default: 1.1 - RepeatPenalty float32 - // RepeatPenaltyLastNTokenCount the number of tokens the model should - // apply the repeat penalty to. - // Default: 64 - RepeatPenaltyLastNTokenCount int32 - // Temperature is the randomness with which the next token is selected. - // Default: 0.8 - Temperature float32 - // TopK is the number of possible next tokens the model will choose from. - // Default: 40 - TopK int32 - // TopP is the probability total of next tokens the model will choose - // from. - // Default: 0.9 - TopP float32 + MaxTokens uint32 `json:"max-tokens"` + + // The amount the model should avoid repeating tokens. + RepeatPenalty float32 `json:"repeat-penalty"` + + // The number of tokens the model should apply the repeat penalty to. + RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` + + // The randomness with which the next token is selected. + Temperature float32 `json:"temperature"` + + // The number of possible next tokens the model will choose from. + TopK uint32 `json:"top-k"` + + // The probability total of next tokens the model will choose from. + TopP float32 `json:"top-p"` } -// InferencingResult is the result of an inference. type InferencingResult struct { - // Text is the text generated by the model. - Text string - // Usage is information about the inferencing request. - Usage *InferencingUsage + // The text generated by the model + // TODO: this should be a stream + Text string `json:"text"` + + // Usage information about the inferencing request + Usage InferencingUsage `json:"usage"` } -// InferencingUsage represents information related to the inferencing result. +// Usage information related to the inferencing result type InferencingUsage struct { - // PromptTokenCount is the number of tokens in the prompt. - PromptTokenCount int - // GeneratedTokenCount is the number of tokens generated by the - // inferencing operation. - GeneratedTokenCount int -} + // TODO: It's not clear whether this is important. + // _ cm.HostLayout `json:"-"` -// Infer performs inferencing using the provided model and prompt with the -// given optional parameters. -func Infer(model, prompt string, params *InferencingParams) (*InferencingResult, error) { - return infer(model, prompt, params) + // Number of tokens in the prompt + PromptTokenCount uint32 `json:"prompt-token-count"` + + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 `json:"generated-token-count"` } -// EmbeddingsResult of generating embeddings. +// A Large Language Model. +type InferencingModel string + +// The model used for generating embeddings +type EmbeddingModel string + type EmbeddingsResult struct { // Embeddings are the embeddings generated by the request. Embeddings [][]float32 @@ -58,13 +69,69 @@ type EmbeddingsResult struct { Usage *EmbeddingsUsage } -// Embeddings is usage related to an embeddings generation request. type EmbeddingsUsage struct { // PromptTokenCount is number of tokens in the prompt. PromptTokenCount int } +// Infer performs inferencing using the provided model and prompt with the +// given optional parameters. +func Infer(model string, prompt string, params *InferencingParams) (InferencingResult, error) { + iparams := wit.None[llm.InferencingParams]() + if params != nil { + iparams = wit.Some(llm.InferencingParams{ + MaxTokens: params.MaxTokens, + RepeatPenalty: params.RepeatPenalty, + RepeatPenaltyLastNTokenCount: params.RepeatPenaltyLastNTokenCount, + Temperature: params.Temperature, + TopK: params.TopK, + TopP: params.TopP, + }) + } + + result := llm.Infer(llm.InferencingModel(model), prompt, iparams) + if result.IsErr() { + return InferencingResult{}, errorVariantToError(result.Err()) + } + + return InferencingResult{ + Text: result.Ok().Text, + Usage: InferencingUsage{ + PromptTokenCount: result.Ok().Usage.PromptTokenCount, + GeneratedTokenCount: result.Ok().Usage.GeneratedTokenCount, + }, + }, nil +} + // GenerateEmbeddings generates the embeddings for the supplied list of text. -func GenerateEmbeddings(model string, text []string) (*EmbeddingsResult, error) { - return generateEmbeddings(model, text) +func GenerateEmbeddings(model EmbeddingModel, text []string) (*EmbeddingsResult, error) { + result := llm.GenerateEmbeddings(llm.EmbeddingModel(model), text) + if result.IsErr() { + return &EmbeddingsResult{}, errorVariantToError(result.Err()) + } + + embeddings := [][]float32{} + for _, l := range result.Ok().Embeddings { + embeddings = append(embeddings, l) + } + + return &EmbeddingsResult{ + Embeddings: embeddings, + Usage: &EmbeddingsUsage{ + PromptTokenCount: int(result.Ok().Usage.PromptTokenCount), + }, + }, nil +} + +func errorVariantToError(err llm.Error) error { + switch err.Tag() { + case llm.ErrorModelNotSupported: + return fmt.Errorf("model not supported") + case llm.ErrorRuntimeError: + return fmt.Errorf("runtime error %s", err.RuntimeError()) + case llm.ErrorInvalidInput: + return fmt.Errorf("invalid input %s", err.InvalidInput()) + default: + return fmt.Errorf("no error provided by host implementation") + } } diff --git a/llm/llm.h b/llm/llm.h deleted file mode 100644 index 57c5a49f..00000000 --- a/llm/llm.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef __BINDINGS_LLM_H -#define __BINDINGS_LLM_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } llm_string_t; - - void llm_string_set(llm_string_t *ret, const char *s); - void llm_string_dup(llm_string_t *ret, const char *s); - void llm_string_free(llm_string_t *ret); - // A Large Language Model. - typedef llm_string_t llm_inferencing_model_t; - void llm_inferencing_model_free(llm_inferencing_model_t *ptr); - // Inference request parameters - typedef struct { - uint32_t max_tokens; - float repeat_penalty; - uint32_t repeat_penalty_last_n_token_count; - float temperature; - uint32_t top_k; - float top_p; - } llm_inferencing_params_t; - // The set of errors which may be raised by functions in this interface - typedef struct { - uint8_t tag; - union { - llm_string_t runtime_error; - llm_string_t invalid_input; - } val; - } llm_error_t; - #define LLM_ERROR_MODEL_NOT_SUPPORTED 0 - #define LLM_ERROR_RUNTIME_ERROR 1 - #define LLM_ERROR_INVALID_INPUT 2 - void llm_error_free(llm_error_t *ptr); - // Usage information related to the inferencing result - typedef struct { - uint32_t prompt_token_count; - uint32_t generated_token_count; - } llm_inferencing_usage_t; - // An inferencing result - typedef struct { - llm_string_t text; - llm_inferencing_usage_t usage; - } llm_inferencing_result_t; - void llm_inferencing_result_free(llm_inferencing_result_t *ptr); - // The model used for generating embeddings - typedef llm_string_t llm_embedding_model_t; - void llm_embedding_model_free(llm_embedding_model_t *ptr); - typedef struct { - float *ptr; - size_t len; - } llm_list_float32_t; - void llm_list_float32_free(llm_list_float32_t *ptr); - typedef struct { - llm_list_float32_t *ptr; - size_t len; - } llm_list_list_float32_t; - void llm_list_list_float32_free(llm_list_list_float32_t *ptr); - // Usage related to an embeddings generation request - typedef struct { - uint32_t prompt_token_count; - } llm_embeddings_usage_t; - // Result of generating embeddings - typedef struct { - llm_list_list_float32_t embeddings; - llm_embeddings_usage_t usage; - } llm_embeddings_result_t; - void llm_embeddings_result_free(llm_embeddings_result_t *ptr); - typedef struct { - bool is_some; - llm_inferencing_params_t val; - } llm_option_inferencing_params_t; - typedef struct { - bool is_err; - union { - llm_inferencing_result_t ok; - llm_error_t err; - } val; - } llm_expected_inferencing_result_error_t; - void llm_expected_inferencing_result_error_free(llm_expected_inferencing_result_error_t *ptr); - typedef struct { - llm_string_t *ptr; - size_t len; - } llm_list_string_t; - void llm_list_string_free(llm_list_string_t *ptr); - typedef struct { - bool is_err; - union { - llm_embeddings_result_t ok; - llm_error_t err; - } val; - } llm_expected_embeddings_result_error_t; - void llm_expected_embeddings_result_error_free(llm_expected_embeddings_result_error_t *ptr); - void llm_infer(llm_inferencing_model_t *model, llm_string_t *prompt, llm_option_inferencing_params_t *params, llm_expected_inferencing_result_error_t *ret0); - void llm_generate_embeddings(llm_embedding_model_t *model, llm_list_string_t *text, llm_expected_embeddings_result_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/v3/mqtt/mqtt.go b/mqtt/mqtt.go similarity index 100% rename from v3/mqtt/mqtt.go rename to mqtt/mqtt.go diff --git a/mysql/internals.go b/mysql/internals.go deleted file mode 100644 index 9b033310..00000000 --- a/mysql/internals.go +++ /dev/null @@ -1,325 +0,0 @@ -package mysql - -// #include "outbound-mysql.h" -// #include -import "C" -import ( - "errors" - "fmt" - "reflect" - "unsafe" -) - -func execute(address string, statement string, args []any) error { - var ret C.outbound_mysql_expected_unit_mysql_error_t - defer C.outbound_mysql_expected_unit_mysql_error_free(&ret) - - mysqlAddress := outboundMysqlStr(address) - mysqlStatement := outboundMysqlStr(statement) - params := toOutboundMysqlParameterListValue(args) - - C.outbound_mysql_execute(&mysqlAddress, &mysqlStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_mysql_mysql_error_t)(unsafe.Pointer(&ret.val)) - return toErr(spinErr) - } - - return nil -} - -func query(address string, statement string, args []any) (*rows, error) { - var ret C.outbound_mysql_expected_row_set_mysql_error_t - defer C.outbound_mysql_expected_row_set_mysql_error_free(&ret) - - mysqlAddress := outboundMysqlStr(address) - mysqlStatement := outboundMysqlStr(statement) - params := toOutboundMysqlParameterListValue(args) - - C.outbound_mysql_query(&mysqlAddress, &mysqlStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_mysql_mysql_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.outbound_mysql_row_set_t)(unsafe.Pointer(&ret.val)) - - columns, columnType := fromOutboundMysqlListColoum(qr.columns) - - rs, err := fromOutboundMysqlListRow(qr.rows) - if err != nil { - return nil, err - } - - result := &rows{ - columns: columns, - columnType: columnType, - rows: rs, - len: int(qr.rows.len), - } - - return result, nil -} - -func fromOutboundMysqlListRow(list C.outbound_mysql_list_row_t) ([][]any, error) { - var err error - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.outbound_mysql_row_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundMysqlRow(row) - if err != nil { - return nil, err - } - } - return ret, nil - -} - -func fromOutboundMysqlRow(row C.outbound_mysql_row_t) ([]any, error) { - var err error - rowLen := int(row.len) - ret := make([]any, rowLen) - slice := unsafe.Slice(row.ptr, rowLen) - for i := 0; i < rowLen; i++ { - value := *((*C.outbound_mysql_db_value_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundMysqlDbValue(value) - if err != nil { - return nil, err - } - } - return ret, err -} - -func fromOutboundMysqlListColoum(list C.outbound_mysql_list_column_t) ([]string, []uint8) { - coloumLen := int(list.len) - ret := make([]string, coloumLen) - retType := make([]uint8, coloumLen) - slice := unsafe.Slice(list.ptr, coloumLen) - for i := 0; i < coloumLen; i++ { - column := *((*C.outbound_mysql_column_t)(unsafe.Pointer(&slice[i]))) - ret[i], retType[i] = fromOutboundMysqlDbColumn(column) - } - return ret, retType -} - -func fromOutboundMysqlDbColumn(c C.outbound_mysql_column_t) (string, uint8) { - return C.GoStringN(c.name.ptr, C.int(c.name.len)), uint8(*(*C.uint8_t)(unsafe.Pointer(&c.data_type))) -} - -func outboundMysqlStr(x string) C.outbound_mysql_string_t { - return C.outbound_mysql_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toOutboundMysqlParameterListValue(xv []any) C.outbound_mysql_list_parameter_value_t { - if len(xv) == 0 { - return C.outbound_mysql_list_parameter_value_t{} - } - cxv := make([]C.outbound_mysql_parameter_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toOutboundMysqlParameterValue(xv[i]) - } - return C.outbound_mysql_list_parameter_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -const ( - dbValueBoolean uint8 = iota - dbValueInt8 - dbValueInt16 - dbValueInt32 - dbValueInt64 - dbValueUint8 - dbValueUint16 - dbValueUint32 - dbValueUint64 - dbValueFloat32 - dbValueFloat64 - dbValueStr - dbValueBinary - dbValueNull - dbValueUnsupported -) - -func fromOutboundMysqlDbValue(x C.outbound_mysql_db_value_t) (any, error) { - switch x.tag { - case dbValueBoolean: - return *(*bool)(unsafe.Pointer(&x.val)), nil - case dbValueInt8: - return int8(*(*C.int8_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt16: - return int16(*(*C.int16_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt32: - return int32(*(*C.int32_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt64: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint8: - return uint8(*(*C.uint8_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint16: - return uint16(*(*C.uint16_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint32: - return uint32(*(*C.uint32_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint64: - return uint64(*(*C.uint64_t)(unsafe.Pointer(&x.val))), nil - case dbValueFloat32: - return float32(*(*C.float)(unsafe.Pointer(&x.val))), nil - case dbValueFloat64: - return float64(*(*C.double)(unsafe.Pointer(&x.val))), nil - case dbValueBinary: - blob := (*C.outbound_mysql_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)), nil - case dbValueStr: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)), nil - case dbValueNull: - return nil, nil - case dbValueUnsupported: - return nil, errors.New("db return value type unsupported") - } - return nil, errors.New("db return value unknown type") -} - -const ( - paramValueBoolean uint8 = iota - paramValueInt8 - paramValueInt16 - paramValueInt32 - paramValueInt64 - paramValueUint8 - paramValueUint16 - paramValueUint32 - paramValueUint64 - paramValueFloat32 - paramValueFloat64 - paramValueStr - paramValueBinary - paramValueNull - paramValueUnspported -) - -func toOutboundMysqlParameterValue(x any) C.outbound_mysql_parameter_value_t { - var ret C.outbound_mysql_parameter_value_t - switch v := x.(type) { - case bool: - *(*bool)(unsafe.Pointer(&ret.val)) = bool(v) - ret.tag = paramValueBoolean - case int8: - *(*C.int8_t)(unsafe.Pointer(&ret.val)) = int8(v) - ret.tag = paramValueInt8 - case int16: - *(*C.int16_t)(unsafe.Pointer(&ret.val)) = int16(v) - ret.tag = paramValueInt16 - case int32: - *(*C.int32_t)(unsafe.Pointer(&ret.val)) = int32(v) - ret.tag = paramValueInt32 - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case uint8: - *(*C.uint8_t)(unsafe.Pointer(&ret.val)) = uint8(v) - ret.tag = paramValueUint8 - case uint16: - *(*C.uint16_t)(unsafe.Pointer(&ret.val)) = uint16(v) - ret.tag = paramValueUint16 - case uint32: - *(*C.uint32_t)(unsafe.Pointer(&ret.val)) = uint32(v) - ret.tag = paramValueUint32 - case uint64: - *(*C.uint64_t)(unsafe.Pointer(&ret.val)) = uint64(v) - ret.tag = paramValueUint64 - case float32: - *(*C.float)(unsafe.Pointer(&ret.val)) = float32(v) - ret.tag = paramValueFloat32 - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = float64(v) - ret.tag = paramValueFloat64 - case string: - str := outboundMysqlStr(v) - *(*C.outbound_mysql_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = paramValueStr - case []byte: - blob := C.outbound_mysql_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.outbound_mysql_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = paramValueBinary - case nil: - ret.tag = paramValueNull - default: - ret.tag = paramValueUnspported - } - return ret -} - -func toErr(err *C.outbound_mysql_mysql_error_t) error { - switch err.tag { - case 0: - return nil - case 1: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("connection failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("bad parameter: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 3: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("query failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 4: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("value conversion failed: %s", C.GoStringN(str.ptr, C.int(str.len)))) - case 5: - str := (*C.outbound_mysql_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("other error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -const ( - dbDataTypeBoolean uint8 = iota - dbDataTypeInt8 - dbDataTypeInt16 - dbDataTypeInt32 - dbDataTypeInt64 - dbDataTypeUint8 - dbDataTypeUint16 - dbDataTypeUint32 - dbDataTypeUint64 - dbDataTypeFloating32 - dbDataTypeFloating64 - dbDataTypeStr - dbDataTypeBinary - dbDataTypeOther -) - -func colTypeToReflectType(typ uint8) reflect.Type { - switch typ { - case dbDataTypeBoolean: - return reflect.TypeOf(false) - case dbDataTypeInt8: - return reflect.TypeOf(int8(0)) - case dbDataTypeInt16: - return reflect.TypeOf(int16(0)) - case dbDataTypeInt32: - return reflect.TypeOf(int32(0)) - case dbDataTypeInt64: - return reflect.TypeOf(int64(0)) - case dbDataTypeUint8: - return reflect.TypeOf(uint8(0)) - case dbDataTypeUint16: - return reflect.TypeOf(uint16(0)) - case dbDataTypeUint32: - return reflect.TypeOf(uint32(0)) - case dbDataTypeUint64: - return reflect.TypeOf(uint64(0)) - case dbDataTypeStr: - return reflect.TypeOf("") - case dbDataTypeBinary: - return reflect.TypeOf(new([]byte)) - case dbDataTypeOther: - return reflect.TypeOf(new(any)).Elem() - } - panic("invalid db column type of " + string(typ)) -} diff --git a/mysql/mysql.go b/mysql/mysql.go index 40b668d8..d3a65e02 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -1,4 +1,3 @@ -// Package mysql provides access to MySQL within Spin components. package mysql import ( @@ -9,106 +8,62 @@ import ( "io" "reflect" - spindb "github.com/spinframework/spin-go-sdk/v2/internal/db" + spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" + mysql "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_mysql" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" ) // Open returns a new connection to the database. -func Open(address string) *sql.DB { - return sql.OpenDB(&connector{address}) +func Open(name string) *sql.DB { + return sql.OpenDB(&connector{name: name}) } -// connector implements driver.Connector. -type connector struct { - address string -} - -// Connect returns a connection to the database. -func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - return d.Open(d.address) -} - -// Driver returns the underlying Driver of the Connector. -func (d *connector) Driver() driver.Driver { - return d -} - -// Open returns a new connection to the database. -func (d *connector) Open(address string) (driver.Conn, error) { - return &conn{address: address}, nil -} - -// conn implements driver.Conn type conn struct { - address string -} - -var _ driver.Conn = (*conn)(nil) - -// Prepare returns a prepared statement, bound to this connection. -func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil + spinConn mysql.Connection } func (c *conn) Close() error { return nil } +func (c *conn) Prepare(query string) (driver.Stmt, error) { + return &stmt{conn: c, query: query}, nil +} + func (c *conn) Begin() (driver.Tx, error) { return nil, errors.New("transactions are unsupported by this driver") } -type stmt struct { - c *conn - query string +type connector struct { + conn *conn + name string } -var _ driver.Stmt = (*stmt)(nil) -var _ driver.ColumnConverter = (*stmt)(nil) - -// Close closes the statement. -func (s *stmt) Close() error { - return nil +func (d *connector) Connect(_ context.Context) (driver.Conn, error) { + if d.conn != nil { + return d.conn, nil + } + return d.Open(d.name) } -// NumInput returns the number of placeholder parameters. -func (s *stmt) NumInput() int { - // Golang sql won't sanity check argument counts before Query. - return -1 +func (d *connector) Driver() driver.Driver { + return d } -// Query executes a query that may return rows, such as a SELECT. -func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] +func (d *connector) Open(name string) (driver.Conn, error) { + results := mysql.ConnectionOpen(name) + if results.IsErr() { + return nil, toError(results.Err()) } - return query(s.c.address, s.query, params) + d.conn = &conn{spinConn: *results.Ok()} + return d.conn, nil } -// Exec executes a query that doesn't return rows, such as an INSERT or -// UPDATE. -func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] +func (d *connector) Close() error { + if d.conn != nil { + d.conn.Close() } - err := execute(s.c.address, s.query, params) - return &result{}, err -} - -// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. -func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { - return spindb.GlobalParameterConverter -} - -type result struct{} - -func (r result) LastInsertId() (int64, error) { - return -1, errors.New("LastInsertId is unsupported by this driver") -} - -func (r result) RowsAffected() (int64, error) { - return -1, errors.New("RowsAffected is unsupported by this driver") + return nil } type rows struct { @@ -172,3 +127,211 @@ func (r *rows) NextResultSet() error { func (r *rows) ColumnTypeScanType(index int) reflect.Type { return colTypeToReflectType(r.columnType[index]) } + +type stmt struct { + conn *conn + query string +} + +var _ driver.Stmt = (*stmt)(nil) +var _ driver.ColumnConverter = (*stmt)(nil) + +// Close closes the statement. +func (s *stmt) Close() error { + return nil +} + +// NumInput returns the number of placeholder parameters. +func (s *stmt) NumInput() int { + // Golang sql won't sanity check argument counts before Query. + return -1 +} + +// Exec executes a query that doesn't return rows, such as an INSERT or +// UPDATE. +func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { + wasiParams := make([]mysql.ParameterValue, len(args)) + for i, v := range args { + wasiParams[i] = toWasiParameterValue(v) + } + + queryResult := s.conn.spinConn.Execute(s.query, wasiParams) + if queryResult.IsErr() { + return &result{}, toError(queryResult.Err()) + } + + return &result{}, nil +} + +// Query executes a query that may return rows, such as a SELECT. +func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { + wasiParams := make([]mysql.ParameterValue, len(args)) + for i, v := range args { + wasiParams[i] = toWasiParameterValue(v) + } + + results := s.conn.spinConn.Query(s.query, wasiParams) + if results.IsErr() { + return nil, toError(results.Err()) + } + + rowLen := len(results.Ok().Rows) + allRows := make([][]any, rowLen) + for rowNum, row := range results.Ok().Rows { + allRows[rowNum] = toRow(row) + } + + cols := results.Ok().Columns + colNames := make([]string, len(cols)) + colTypes := make([]uint8, len(cols)) + for i, c := range cols { + colNames[i] = c.Name + colTypes[i] = uint8(c.DataType) + } + + rows := &rows{ + columns: colNames, + columnType: colTypes, + rows: allRows, + len: int(rowLen), + } + return rows, nil +} + +func toWasiParameterValue(x any) mysql.ParameterValue { + switch v := x.(type) { + case bool: + return rdbmstypes.MakeParameterValueBoolean(v) + case int8: + return rdbmstypes.MakeParameterValueInt8(v) + case int16: + return rdbmstypes.MakeParameterValueInt16(v) + case int32: + return rdbmstypes.MakeParameterValueInt32(v) + case int64: + return rdbmstypes.MakeParameterValueInt64(v) + case int: + return rdbmstypes.MakeParameterValueInt64(int64(v)) + case uint8: + return rdbmstypes.MakeParameterValueUint8(v) + case uint16: + return rdbmstypes.MakeParameterValueUint16(v) + case uint32: + return rdbmstypes.MakeParameterValueUint32(v) + case uint64: + return rdbmstypes.MakeParameterValueUint64(v) + case float32: + return rdbmstypes.MakeParameterValueFloating32(v) + case float64: + return rdbmstypes.MakeParameterValueFloating64(v) + case string: + return rdbmstypes.MakeParameterValueStr(v) + case []byte: + return rdbmstypes.MakeParameterValueBinary(v) + case nil: + return rdbmstypes.MakeParameterValueDbNull() + default: + panic("unknown value type") + } +} + +func toError(err mysql.Error) error { + switch err.Tag() { + case rdbmstypes.ErrorBadParameter: + return errors.New(err.BadParameter()) + case rdbmstypes.ErrorConnectionFailed: + return errors.New(err.ConnectionFailed()) + case rdbmstypes.ErrorQueryFailed: + return errors.New(err.QueryFailed()) + case rdbmstypes.ErrorValueConversionFailed: + return errors.New(err.ValueConversionFailed()) + default: + // TODO: not sure if using "Other" as the default is appropriate + return errors.New(err.Other()) + } +} + +func toRow(row []rdbmstypes.DbValue) []any { + result := make([]any, len(row)) + for i, v := range row { + switch v.Tag() { + case rdbmstypes.DbValueBoolean: + result[i] = v.Boolean() + case rdbmstypes.DbValueInt8: + result[i] = v.Int8() + case rdbmstypes.DbValueInt16: + result[i] = v.Int16() + case rdbmstypes.DbValueInt32: + result[i] = v.Int32() + case rdbmstypes.DbValueInt64: + result[i] = v.Int64() + case rdbmstypes.DbValueUint8: + result[i] = v.Uint8() + case rdbmstypes.DbValueUint16: + result[i] = v.Uint16() + case rdbmstypes.DbValueUint32: + result[i] = v.Uint32() + case rdbmstypes.DbValueUint64: + result[i] = v.Uint64() + case rdbmstypes.DbValueFloating32: + result[i] = v.Floating32() + case rdbmstypes.DbValueFloating64: + result[i] = v.Floating64() + case rdbmstypes.DbValueStr: + result[i] = v.Str() + case rdbmstypes.DbValueBinary: + result[i] = v.Binary() + case rdbmstypes.DbValueDbNull: + result[i] = nil + default: + panic("unknown value type") + } + } + + return result +} + +// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. +func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { + return spindb.GlobalParameterConverter +} + +type result struct{} + +func (r result) LastInsertId() (int64, error) { + return -1, errors.New("LastInsertId is unsupported by this driver") +} + +func (r result) RowsAffected() (int64, error) { + return -1, errors.New("RowsAffected is unsupported by this driver") +} + +func colTypeToReflectType(typ uint8) reflect.Type { + switch typ { + case uint8(rdbmstypes.DbDataTypeBoolean): + return reflect.TypeOf(false) + case uint8(rdbmstypes.DbDataTypeInt8): + return reflect.TypeOf(int8(0)) + case uint8(rdbmstypes.DbDataTypeInt16): + return reflect.TypeOf(int16(0)) + case uint8(rdbmstypes.DbDataTypeInt32): + return reflect.TypeOf(int32(0)) + case uint8(rdbmstypes.DbDataTypeInt64): + return reflect.TypeOf(int64(0)) + case uint8(rdbmstypes.DbDataTypeUint8): + return reflect.TypeOf(uint8(0)) + case uint8(rdbmstypes.DbDataTypeUint16): + return reflect.TypeOf(uint16(0)) + case uint8(rdbmstypes.DbDataTypeUint32): + return reflect.TypeOf(uint32(0)) + case uint8(rdbmstypes.DbDataTypeUint64): + return reflect.TypeOf(uint64(0)) + case uint8(rdbmstypes.DbDataTypeStr): + return reflect.TypeOf("") + case uint8(rdbmstypes.DbDataTypeBinary): + return reflect.TypeOf(new([]byte)) + case uint8(rdbmstypes.DbDataTypeOther): + return reflect.TypeOf(new(any)).Elem() + } + panic("invalid db column type of " + string(typ)) +} diff --git a/mysql/outbound-mysql.c b/mysql/outbound-mysql.c deleted file mode 100644 index f83753f2..00000000 --- a/mysql/outbound-mysql.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_mysql_string_set(outbound_mysql_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_mysql_string_dup(outbound_mysql_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_mysql_string_free(outbound_mysql_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_mysql_mysql_error_free(outbound_mysql_mysql_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_mysql_string_free(&ptr->val.connection_failed); - break; - } - case 2: { - outbound_mysql_string_free(&ptr->val.bad_parameter); - break; - } - case 3: { - outbound_mysql_string_free(&ptr->val.query_failed); - break; - } - case 4: { - outbound_mysql_string_free(&ptr->val.value_conversion_failed); - break; - } - case 5: { - outbound_mysql_string_free(&ptr->val.other_error); - break; - } - } -} -void outbound_mysql_column_free(outbound_mysql_column_t *ptr) { - outbound_mysql_string_free(&ptr->name); -} -void outbound_mysql_list_u8_free(outbound_mysql_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_mysql_db_value_free(outbound_mysql_db_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_mysql_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_mysql_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_mysql_parameter_value_free(outbound_mysql_parameter_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_mysql_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_mysql_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_mysql_row_free(outbound_mysql_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_db_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_mysql_list_column_free(outbound_mysql_list_column_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_column_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 12, 4); -} -void outbound_mysql_list_row_free(outbound_mysql_list_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_row_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void outbound_mysql_row_set_free(outbound_mysql_row_set_t *ptr) { - outbound_mysql_list_column_free(&ptr->columns); - outbound_mysql_list_row_free(&ptr->rows); -} -void outbound_mysql_list_parameter_value_free(outbound_mysql_list_parameter_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_mysql_parameter_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_mysql_expected_row_set_mysql_error_free(outbound_mysql_expected_row_set_mysql_error_t *ptr) { - if (!ptr->is_err) { - outbound_mysql_row_set_free(&ptr->val.ok); - } else { - outbound_mysql_mysql_error_free(&ptr->val.err); - } -} -void outbound_mysql_expected_unit_mysql_error_free(outbound_mysql_expected_unit_mysql_error_t *ptr) { - if (!ptr->is_err) { - } else { - outbound_mysql_mysql_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("outbound-mysql"), import_name("query"))) -void __wasm_import_outbound_mysql_query(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_mysql_query(outbound_mysql_string_t *address, outbound_mysql_string_t *statement, outbound_mysql_list_parameter_value_t *params, outbound_mysql_expected_row_set_mysql_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_mysql_query((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_mysql_expected_row_set_mysql_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_mysql_row_set_t) { - (outbound_mysql_list_column_t) { (outbound_mysql_column_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (outbound_mysql_list_row_t) { (outbound_mysql_row_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - outbound_mysql_mysql_error_t variant13; - variant13.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant13.tag) { - case 0: { - break; - } - case 1: { - variant13.val.connection_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant13.val.bad_parameter = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant13.val.query_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant13.val.value_conversion_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant13.val.other_error = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant13; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("outbound-mysql"), import_name("execute"))) -void __wasm_import_outbound_mysql_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_mysql_execute(outbound_mysql_string_t *address, outbound_mysql_string_t *statement, outbound_mysql_list_parameter_value_t *params, outbound_mysql_expected_unit_mysql_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_mysql_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_mysql_expected_unit_mysql_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - outbound_mysql_mysql_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.connection_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.bad_parameter = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant.val.query_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant.val.value_conversion_failed = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant.val.other_error = (outbound_mysql_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/mysql/outbound-mysql.h b/mysql/outbound-mysql.h deleted file mode 100644 index 2615ff71..00000000 --- a/mysql/outbound-mysql.h +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_MYSQL_H -#define __BINDINGS_OUTBOUND_MYSQL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct { - char *ptr; - size_t len; -} outbound_mysql_string_t; - -void outbound_mysql_string_set(outbound_mysql_string_t *ret, const char *s); -void outbound_mysql_string_dup(outbound_mysql_string_t *ret, const char *s); -void outbound_mysql_string_free(outbound_mysql_string_t *ret); -typedef struct { - uint8_t tag; - union { - outbound_mysql_string_t connection_failed; - outbound_mysql_string_t bad_parameter; - outbound_mysql_string_t query_failed; - outbound_mysql_string_t value_conversion_failed; - outbound_mysql_string_t other_error; - } val; -} outbound_mysql_mysql_error_t; -#define OUTBOUND_MYSQL_MYSQL_ERROR_SUCCESS 0 -#define OUTBOUND_MYSQL_MYSQL_ERROR_CONNECTION_FAILED 1 -#define OUTBOUND_MYSQL_MYSQL_ERROR_BAD_PARAMETER 2 -#define OUTBOUND_MYSQL_MYSQL_ERROR_QUERY_FAILED 3 -#define OUTBOUND_MYSQL_MYSQL_ERROR_VALUE_CONVERSION_FAILED 4 -#define OUTBOUND_MYSQL_MYSQL_ERROR_OTHER_ERROR 5 -void outbound_mysql_mysql_error_free(outbound_mysql_mysql_error_t *ptr); -typedef uint8_t outbound_mysql_db_data_type_t; -#define OUTBOUND_MYSQL_DB_DATA_TYPE_BOOLEAN 0 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT8 1 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT16 2 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT32 3 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_INT64 4 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT8 5 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT16 6 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT32 7 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_UINT64 8 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_FLOATING32 9 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_FLOATING64 10 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_STR 11 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_BINARY 12 -#define OUTBOUND_MYSQL_DB_DATA_TYPE_OTHER 13 -typedef struct { - outbound_mysql_string_t name; - outbound_mysql_db_data_type_t data_type; -} outbound_mysql_column_t; -void outbound_mysql_column_free(outbound_mysql_column_t *ptr); -typedef struct { - uint8_t *ptr; - size_t len; -} outbound_mysql_list_u8_t; -void outbound_mysql_list_u8_free(outbound_mysql_list_u8_t *ptr); -typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_mysql_string_t str; - outbound_mysql_list_u8_t binary; - } val; -} outbound_mysql_db_value_t; -#define OUTBOUND_MYSQL_DB_VALUE_BOOLEAN 0 -#define OUTBOUND_MYSQL_DB_VALUE_INT8 1 -#define OUTBOUND_MYSQL_DB_VALUE_INT16 2 -#define OUTBOUND_MYSQL_DB_VALUE_INT32 3 -#define OUTBOUND_MYSQL_DB_VALUE_INT64 4 -#define OUTBOUND_MYSQL_DB_VALUE_UINT8 5 -#define OUTBOUND_MYSQL_DB_VALUE_UINT16 6 -#define OUTBOUND_MYSQL_DB_VALUE_UINT32 7 -#define OUTBOUND_MYSQL_DB_VALUE_UINT64 8 -#define OUTBOUND_MYSQL_DB_VALUE_FLOATING32 9 -#define OUTBOUND_MYSQL_DB_VALUE_FLOATING64 10 -#define OUTBOUND_MYSQL_DB_VALUE_STR 11 -#define OUTBOUND_MYSQL_DB_VALUE_BINARY 12 -#define OUTBOUND_MYSQL_DB_VALUE_DB_NULL 13 -#define OUTBOUND_MYSQL_DB_VALUE_UNSUPPORTED 14 -void outbound_mysql_db_value_free(outbound_mysql_db_value_t *ptr); -typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_mysql_string_t str; - outbound_mysql_list_u8_t binary; - } val; -} outbound_mysql_parameter_value_t; -#define OUTBOUND_MYSQL_PARAMETER_VALUE_BOOLEAN 0 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT8 1 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT16 2 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT32 3 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_INT64 4 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT8 5 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT16 6 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT32 7 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_UINT64 8 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_FLOATING32 9 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_FLOATING64 10 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_STR 11 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_BINARY 12 -#define OUTBOUND_MYSQL_PARAMETER_VALUE_DB_NULL 13 -void outbound_mysql_parameter_value_free(outbound_mysql_parameter_value_t *ptr); -typedef struct { - outbound_mysql_db_value_t *ptr; - size_t len; -} outbound_mysql_row_t; -void outbound_mysql_row_free(outbound_mysql_row_t *ptr); -typedef struct { - outbound_mysql_column_t *ptr; - size_t len; -} outbound_mysql_list_column_t; -void outbound_mysql_list_column_free(outbound_mysql_list_column_t *ptr); -typedef struct { - outbound_mysql_row_t *ptr; - size_t len; -} outbound_mysql_list_row_t; -void outbound_mysql_list_row_free(outbound_mysql_list_row_t *ptr); -typedef struct { - outbound_mysql_list_column_t columns; - outbound_mysql_list_row_t rows; -} outbound_mysql_row_set_t; -void outbound_mysql_row_set_free(outbound_mysql_row_set_t *ptr); -typedef struct { - outbound_mysql_parameter_value_t *ptr; - size_t len; -} outbound_mysql_list_parameter_value_t; -void outbound_mysql_list_parameter_value_free( - outbound_mysql_list_parameter_value_t *ptr); -typedef struct { - bool is_err; - union { - outbound_mysql_row_set_t ok; - outbound_mysql_mysql_error_t err; - } val; -} outbound_mysql_expected_row_set_mysql_error_t; -void outbound_mysql_expected_row_set_mysql_error_free( - outbound_mysql_expected_row_set_mysql_error_t *ptr); -typedef struct { - bool is_err; - union { - outbound_mysql_mysql_error_t err; - } val; -} outbound_mysql_expected_unit_mysql_error_t; -void outbound_mysql_expected_unit_mysql_error_free( - outbound_mysql_expected_unit_mysql_error_t *ptr); -void outbound_mysql_query(outbound_mysql_string_t *address, - outbound_mysql_string_t *statement, - outbound_mysql_list_parameter_value_t *params, - outbound_mysql_expected_row_set_mysql_error_t *ret0); -void outbound_mysql_execute(outbound_mysql_string_t *address, - outbound_mysql_string_t *statement, - outbound_mysql_list_parameter_value_t *params, - outbound_mysql_expected_unit_mysql_error_t *ret0); -#ifdef __cplusplus -} -#endif -#endif diff --git a/pg/internals.go b/pg/internals.go deleted file mode 100644 index 959626ea..00000000 --- a/pg/internals.go +++ /dev/null @@ -1,325 +0,0 @@ -package pg - -// #include "outbound-pg.h" -// #include -import "C" - -import ( - "errors" - "fmt" - "reflect" - "unsafe" -) - -func execute(address string, statement string, args []any) (uint64, error) { - var ret C.outbound_pg_expected_u64_pg_error_t - defer C.outbound_pg_expected_u64_pg_error_free(&ret) - - pgAddress := outboundPgStr(address) - pgStatement := outboundPgStr(statement) - params := toOutboundPgParameterListValue(args) - - C.outbound_pg_execute(&pgAddress, &pgStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_pg_pg_error_t)(unsafe.Pointer(&ret.val)) - return 0, toErr(spinErr) - } - return uint64(*(*C.uint64_t)(unsafe.Pointer(&ret.val))), nil -} - -func query(address string, statement string, args []any) (*rows, error) { - var ret C.outbound_pg_expected_row_set_pg_error_t - defer C.outbound_pg_expected_row_set_pg_error_free(&ret) - - pgAddress := outboundPgStr(address) - pgStatement := outboundPgStr(statement) - params := toOutboundPgParameterListValue(args) - - C.outbound_pg_query(&pgAddress, &pgStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.outbound_pg_pg_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.outbound_pg_row_set_t)(unsafe.Pointer(&ret.val)) - - columns, columnType := fromOutboundPgListColoum(qr.columns) - - rs, err := fromOutboundPgListRow(qr.rows) - if err != nil { - return nil, err - } - - result := &rows{ - columns: columns, - columnType: columnType, - rows: rs, - len: int(qr.rows.len), - } - - return result, nil -} - -func fromOutboundPgListRow(list C.outbound_pg_list_row_t) ([][]any, error) { - var err error - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.outbound_pg_row_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundPgRow(row) - if err != nil { - return nil, err - } - } - return ret, nil - -} - -func fromOutboundPgRow(row C.outbound_pg_row_t) ([]any, error) { - var err error - rowLen := int(row.len) - ret := make([]any, rowLen) - slice := unsafe.Slice(row.ptr, rowLen) - for i := 0; i < rowLen; i++ { - value := *((*C.outbound_pg_db_value_t)(unsafe.Pointer(&slice[i]))) - ret[i], err = fromOutboundPgDbValue(value) - if err != nil { - return nil, err - } - } - return ret, err -} - -func fromOutboundPgListColoum(list C.outbound_pg_list_column_t) ([]string, []uint8) { - coloumLen := int(list.len) - ret := make([]string, coloumLen) - retType := make([]uint8, coloumLen) - slice := unsafe.Slice(list.ptr, coloumLen) - for i := 0; i < coloumLen; i++ { - column := *((*C.outbound_pg_column_t)(unsafe.Pointer(&slice[i]))) - ret[i], retType[i] = fromOutboundPgDbColumn(column) - } - return ret, retType -} - -func fromOutboundPgDbColumn(c C.outbound_pg_column_t) (string, uint8) { - return C.GoStringN(c.name.ptr, C.int(c.name.len)), uint8(*(*C.uint8_t)(unsafe.Pointer(&c.data_type))) -} - -func toOutboundPgParameterListValue(xv []any) C.outbound_pg_list_parameter_value_t { - if len(xv) == 0 { - return C.outbound_pg_list_parameter_value_t{} - } - cxv := make([]C.outbound_pg_parameter_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toOutboundPgParameterValue(xv[i]) - } - return C.outbound_pg_list_parameter_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -func outboundPgStr(x string) C.outbound_pg_string_t { - return C.outbound_pg_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toErr(err *C.outbound_pg_pg_error_t) error { - switch err.tag { - case 0: - return nil - case 1: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("connection failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 2: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("bad parameter: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 3: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf("query failed: %s", C.GoStringN(str.ptr, C.int(str.len))) - case 4: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("value conversion failed: %s", C.GoStringN(str.ptr, C.int(str.len)))) - case 5: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&err.val)) - return fmt.Errorf(fmt.Sprintf("other error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return fmt.Errorf("unrecognized error: %v", err.tag) - } -} - -const ( - dbValueBoolean uint8 = iota - dbValueInt8 - dbValueInt16 - dbValueInt32 - dbValueInt64 - dbValueUint8 - dbValueUint16 - dbValueUint32 - dbValueUint64 - dbValueFloat32 - dbValueFloat64 - dbValueStr - dbValueBinary - dbValueNull - dbValueUnsupported -) - -func fromOutboundPgDbValue(x C.outbound_pg_db_value_t) (any, error) { - switch x.tag { - case dbValueBoolean: - return *(*bool)(unsafe.Pointer(&x.val)), nil - case dbValueInt8: - return int8(*(*C.int8_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt16: - return int16(*(*C.int16_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt32: - return int32(*(*C.int32_t)(unsafe.Pointer(&x.val))), nil - case dbValueInt64: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint8: - return uint8(*(*C.uint8_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint16: - return uint16(*(*C.uint16_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint32: - return uint32(*(*C.uint32_t)(unsafe.Pointer(&x.val))), nil - case dbValueUint64: - return uint64(*(*C.uint64_t)(unsafe.Pointer(&x.val))), nil - case dbValueFloat32: - return float32(*(*C.float)(unsafe.Pointer(&x.val))), nil - case dbValueFloat64: - return float64(*(*C.double)(unsafe.Pointer(&x.val))), nil - case dbValueBinary: - blob := (*C.outbound_pg_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)), nil - case dbValueStr: - str := (*C.outbound_pg_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)), nil - case dbValueNull: - return nil, nil - case dbValueUnsupported: - return nil, errors.New("db return value type unsupported") - } - return nil, errors.New("db return value unknown type") -} - -const ( - paramValueBoolean uint8 = iota - paramValueInt8 - paramValueInt16 - paramValueInt32 - paramValueInt64 - paramValueUint8 - paramValueUint16 - paramValueUint32 - paramValueUint64 - paramValueFloat32 - paramValueFloat64 - paramValueStr - paramValueBinary - paramValueNull - paramValueUnspported -) - -func toOutboundPgParameterValue(x any) C.outbound_pg_parameter_value_t { - var ret C.outbound_pg_parameter_value_t - switch v := x.(type) { - case bool: - *(*bool)(unsafe.Pointer(&ret.val)) = bool(v) - ret.tag = paramValueBoolean - case int8: - *(*C.int8_t)(unsafe.Pointer(&ret.val)) = int8(v) - ret.tag = paramValueInt8 - case int16: - *(*C.int16_t)(unsafe.Pointer(&ret.val)) = int16(v) - ret.tag = paramValueInt16 - case int32: - *(*C.int32_t)(unsafe.Pointer(&ret.val)) = int32(v) - ret.tag = paramValueInt32 - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = paramValueInt64 - case uint8: - *(*C.uint8_t)(unsafe.Pointer(&ret.val)) = uint8(v) - ret.tag = paramValueUint8 - case uint16: - *(*C.uint16_t)(unsafe.Pointer(&ret.val)) = uint16(v) - ret.tag = paramValueUint16 - case uint32: - *(*C.uint32_t)(unsafe.Pointer(&ret.val)) = uint32(v) - ret.tag = paramValueUint32 - case uint64: - *(*C.uint64_t)(unsafe.Pointer(&ret.val)) = uint64(v) - ret.tag = paramValueUint64 - case float32: - *(*C.float)(unsafe.Pointer(&ret.val)) = float32(v) - ret.tag = paramValueFloat32 - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = float64(v) - ret.tag = paramValueFloat64 - case string: - str := outboundPgStr(v) - *(*C.outbound_pg_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = paramValueStr - case []byte: - blob := C.outbound_pg_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.outbound_pg_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = paramValueBinary - case nil: - ret.tag = paramValueNull - default: - ret.tag = paramValueUnspported - } - return ret -} - -const ( - dbDataTypeBoolean uint8 = iota - dbDataTypeInt8 - dbDataTypeInt16 - dbDataTypeInt32 - dbDataTypeInt64 - dbDataTypeUint8 - dbDataTypeUint16 - dbDataTypeUint32 - dbDataTypeUint64 - dbDataTypeFloating32 - dbDataTypeFloating64 - dbDataTypeStr - dbDataTypeBinary - dbDataTypeOther -) - -func colTypeToReflectType(typ uint8) reflect.Type { - switch typ { - case dbDataTypeBoolean: - return reflect.TypeOf(false) - case dbDataTypeInt8: - return reflect.TypeOf(int8(0)) - case dbDataTypeInt16: - return reflect.TypeOf(int16(0)) - case dbDataTypeInt32: - return reflect.TypeOf(int32(0)) - case dbDataTypeInt64: - return reflect.TypeOf(int64(0)) - case dbDataTypeUint8: - return reflect.TypeOf(uint8(0)) - case dbDataTypeUint16: - return reflect.TypeOf(uint16(0)) - case dbDataTypeUint32: - return reflect.TypeOf(uint32(0)) - case dbDataTypeUint64: - return reflect.TypeOf(uint64(0)) - case dbDataTypeStr: - return reflect.TypeOf("") - case dbDataTypeBinary: - return reflect.TypeOf(new([]byte)) - case dbDataTypeOther: - return reflect.TypeOf(new(any)).Elem() - } - panic("invalid db column type of " + string(typ)) -} diff --git a/pg/outbound-pg.c b/pg/outbound-pg.c deleted file mode 100644 index 151867af..00000000 --- a/pg/outbound-pg.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_pg_string_set(outbound_pg_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_pg_string_dup(outbound_pg_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_pg_string_free(outbound_pg_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_pg_pg_error_free(outbound_pg_pg_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_pg_string_free(&ptr->val.connection_failed); - break; - } - case 2: { - outbound_pg_string_free(&ptr->val.bad_parameter); - break; - } - case 3: { - outbound_pg_string_free(&ptr->val.query_failed); - break; - } - case 4: { - outbound_pg_string_free(&ptr->val.value_conversion_failed); - break; - } - case 5: { - outbound_pg_string_free(&ptr->val.other_error); - break; - } - } -} -void outbound_pg_column_free(outbound_pg_column_t *ptr) { - outbound_pg_string_free(&ptr->name); -} -void outbound_pg_list_u8_free(outbound_pg_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_pg_db_value_free(outbound_pg_db_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_pg_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_pg_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_pg_parameter_value_free(outbound_pg_parameter_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 11: { - outbound_pg_string_free(&ptr->val.str); - break; - } - case 12: { - outbound_pg_list_u8_free(&ptr->val.binary); - break; - } - } -} -void outbound_pg_row_free(outbound_pg_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_db_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_pg_list_column_free(outbound_pg_list_column_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_column_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 12, 4); -} -void outbound_pg_list_row_free(outbound_pg_list_row_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_row_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void outbound_pg_row_set_free(outbound_pg_row_set_t *ptr) { - outbound_pg_list_column_free(&ptr->columns); - outbound_pg_list_row_free(&ptr->rows); -} -void outbound_pg_list_parameter_value_free(outbound_pg_list_parameter_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_pg_parameter_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_pg_expected_row_set_pg_error_free(outbound_pg_expected_row_set_pg_error_t *ptr) { - if (!ptr->is_err) { - outbound_pg_row_set_free(&ptr->val.ok); - } else { - outbound_pg_pg_error_free(&ptr->val.err); - } -} -void outbound_pg_expected_u64_pg_error_free(outbound_pg_expected_u64_pg_error_t *ptr) { - if (!ptr->is_err) { - } else { - outbound_pg_pg_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(8))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("outbound-pg"), import_name("query"))) -void __wasm_import_outbound_pg_query(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_pg_query(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_row_set_pg_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_pg_query((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_pg_expected_row_set_pg_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_pg_row_set_t) { - (outbound_pg_list_column_t) { (outbound_pg_column_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (outbound_pg_list_row_t) { (outbound_pg_row_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - outbound_pg_pg_error_t variant13; - variant13.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant13.tag) { - case 0: { - break; - } - case 1: { - variant13.val.connection_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant13.val.bad_parameter = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant13.val.query_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 4: { - variant13.val.value_conversion_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 5: { - variant13.val.other_error = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant13; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("outbound-pg"), import_name("execute"))) -void __wasm_import_outbound_pg_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void outbound_pg_execute(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_u64_pg_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_pg_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*params).ptr, (int32_t) (*params).len, ptr); - outbound_pg_expected_u64_pg_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); - break; - } - case 1: { - expected.is_err = true; - outbound_pg_pg_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - variant.val.connection_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 2: { - variant.val.bad_parameter = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 3: { - variant.val.query_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 4: { - variant.val.value_conversion_failed = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - case 5: { - variant.val.other_error = (outbound_pg_string_t) { (char*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/pg/outbound-pg.h b/pg/outbound-pg.h deleted file mode 100644 index 4284e161..00000000 --- a/pg/outbound-pg.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_PG_H -#define __BINDINGS_OUTBOUND_PG_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } outbound_pg_string_t; - - void outbound_pg_string_set(outbound_pg_string_t *ret, const char *s); - void outbound_pg_string_dup(outbound_pg_string_t *ret, const char *s); - void outbound_pg_string_free(outbound_pg_string_t *ret); - typedef struct { - uint8_t tag; - union { - outbound_pg_string_t connection_failed; - outbound_pg_string_t bad_parameter; - outbound_pg_string_t query_failed; - outbound_pg_string_t value_conversion_failed; - outbound_pg_string_t other_error; - } val; - } outbound_pg_pg_error_t; - #define OUTBOUND_PG_PG_ERROR_SUCCESS 0 - #define OUTBOUND_PG_PG_ERROR_CONNECTION_FAILED 1 - #define OUTBOUND_PG_PG_ERROR_BAD_PARAMETER 2 - #define OUTBOUND_PG_PG_ERROR_QUERY_FAILED 3 - #define OUTBOUND_PG_PG_ERROR_VALUE_CONVERSION_FAILED 4 - #define OUTBOUND_PG_PG_ERROR_OTHER_ERROR 5 - void outbound_pg_pg_error_free(outbound_pg_pg_error_t *ptr); - typedef uint8_t outbound_pg_db_data_type_t; - #define OUTBOUND_PG_DB_DATA_TYPE_BOOLEAN 0 - #define OUTBOUND_PG_DB_DATA_TYPE_INT8 1 - #define OUTBOUND_PG_DB_DATA_TYPE_INT16 2 - #define OUTBOUND_PG_DB_DATA_TYPE_INT32 3 - #define OUTBOUND_PG_DB_DATA_TYPE_INT64 4 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT8 5 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT16 6 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT32 7 - #define OUTBOUND_PG_DB_DATA_TYPE_UINT64 8 - #define OUTBOUND_PG_DB_DATA_TYPE_FLOATING32 9 - #define OUTBOUND_PG_DB_DATA_TYPE_FLOATING64 10 - #define OUTBOUND_PG_DB_DATA_TYPE_STR 11 - #define OUTBOUND_PG_DB_DATA_TYPE_BINARY 12 - #define OUTBOUND_PG_DB_DATA_TYPE_OTHER 13 - typedef struct { - outbound_pg_string_t name; - outbound_pg_db_data_type_t data_type; - } outbound_pg_column_t; - void outbound_pg_column_free(outbound_pg_column_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } outbound_pg_list_u8_t; - void outbound_pg_list_u8_free(outbound_pg_list_u8_t *ptr); - typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_pg_string_t str; - outbound_pg_list_u8_t binary; - } val; - } outbound_pg_db_value_t; - #define OUTBOUND_PG_DB_VALUE_BOOLEAN 0 - #define OUTBOUND_PG_DB_VALUE_INT8 1 - #define OUTBOUND_PG_DB_VALUE_INT16 2 - #define OUTBOUND_PG_DB_VALUE_INT32 3 - #define OUTBOUND_PG_DB_VALUE_INT64 4 - #define OUTBOUND_PG_DB_VALUE_UINT8 5 - #define OUTBOUND_PG_DB_VALUE_UINT16 6 - #define OUTBOUND_PG_DB_VALUE_UINT32 7 - #define OUTBOUND_PG_DB_VALUE_UINT64 8 - #define OUTBOUND_PG_DB_VALUE_FLOATING32 9 - #define OUTBOUND_PG_DB_VALUE_FLOATING64 10 - #define OUTBOUND_PG_DB_VALUE_STR 11 - #define OUTBOUND_PG_DB_VALUE_BINARY 12 - #define OUTBOUND_PG_DB_VALUE_DB_NULL 13 - #define OUTBOUND_PG_DB_VALUE_UNSUPPORTED 14 - void outbound_pg_db_value_free(outbound_pg_db_value_t *ptr); - typedef struct { - uint8_t tag; - union { - bool boolean; - int8_t int8; - int16_t int16; - int32_t int32; - int64_t int64; - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - float floating32; - double floating64; - outbound_pg_string_t str; - outbound_pg_list_u8_t binary; - } val; - } outbound_pg_parameter_value_t; - #define OUTBOUND_PG_PARAMETER_VALUE_BOOLEAN 0 - #define OUTBOUND_PG_PARAMETER_VALUE_INT8 1 - #define OUTBOUND_PG_PARAMETER_VALUE_INT16 2 - #define OUTBOUND_PG_PARAMETER_VALUE_INT32 3 - #define OUTBOUND_PG_PARAMETER_VALUE_INT64 4 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT8 5 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT16 6 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT32 7 - #define OUTBOUND_PG_PARAMETER_VALUE_UINT64 8 - #define OUTBOUND_PG_PARAMETER_VALUE_FLOATING32 9 - #define OUTBOUND_PG_PARAMETER_VALUE_FLOATING64 10 - #define OUTBOUND_PG_PARAMETER_VALUE_STR 11 - #define OUTBOUND_PG_PARAMETER_VALUE_BINARY 12 - #define OUTBOUND_PG_PARAMETER_VALUE_DB_NULL 13 - void outbound_pg_parameter_value_free(outbound_pg_parameter_value_t *ptr); - typedef struct { - outbound_pg_db_value_t *ptr; - size_t len; - } outbound_pg_row_t; - void outbound_pg_row_free(outbound_pg_row_t *ptr); - typedef struct { - outbound_pg_column_t *ptr; - size_t len; - } outbound_pg_list_column_t; - void outbound_pg_list_column_free(outbound_pg_list_column_t *ptr); - typedef struct { - outbound_pg_row_t *ptr; - size_t len; - } outbound_pg_list_row_t; - void outbound_pg_list_row_free(outbound_pg_list_row_t *ptr); - typedef struct { - outbound_pg_list_column_t columns; - outbound_pg_list_row_t rows; - } outbound_pg_row_set_t; - void outbound_pg_row_set_free(outbound_pg_row_set_t *ptr); - typedef struct { - outbound_pg_parameter_value_t *ptr; - size_t len; - } outbound_pg_list_parameter_value_t; - void outbound_pg_list_parameter_value_free(outbound_pg_list_parameter_value_t *ptr); - typedef struct { - bool is_err; - union { - outbound_pg_row_set_t ok; - outbound_pg_pg_error_t err; - } val; - } outbound_pg_expected_row_set_pg_error_t; - void outbound_pg_expected_row_set_pg_error_free(outbound_pg_expected_row_set_pg_error_t *ptr); - typedef struct { - bool is_err; - union { - uint64_t ok; - outbound_pg_pg_error_t err; - } val; - } outbound_pg_expected_u64_pg_error_t; - void outbound_pg_expected_u64_pg_error_free(outbound_pg_expected_u64_pg_error_t *ptr); - void outbound_pg_query(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_row_set_pg_error_t *ret0); - void outbound_pg_execute(outbound_pg_string_t *address, outbound_pg_string_t *statement, outbound_pg_list_parameter_value_t *params, outbound_pg_expected_u64_pg_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/pg/pg.go b/pg/pg.go index 956f1883..002f4f3b 100644 --- a/pg/pg.go +++ b/pg/pg.go @@ -8,22 +8,28 @@ import ( "io" "reflect" - spindb "github.com/spinframework/spin-go-sdk/v2/internal/db" + spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" + pg "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_postgres" + rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" ) // Open returns a new connection to the database. -func Open(address string) *sql.DB { - return sql.OpenDB(&connector{address}) +func Open(name string) *sql.DB { + return sql.OpenDB(&connector{name: name}) } // connector implements driver.Connector. type connector struct { - address string + conn *conn + name string } // Connect returns a connection to the database. func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - return d.Open(d.address) + if d.conn != nil { + return d.conn, nil + } + return d.Open(d.name) } // Driver returns the underlying Driver of the Connector. @@ -32,20 +38,25 @@ func (d *connector) Driver() driver.Driver { } // Open returns a new connection to the database. -func (d *connector) Open(address string) (driver.Conn, error) { - return &conn{address: address}, nil +func (d *connector) Open(name string) (driver.Conn, error) { + results := pg.ConnectionOpen(name) + if results.IsErr() { + return nil, toError(results.Err()) + } + d.conn = &conn{spinConn: *results.Ok()} + return d.conn, nil } // conn implements driver.Conn type conn struct { - address string + spinConn pg.Connection } var _ driver.Conn = (*conn)(nil) // Prepare returns a prepared statement, bound to this connection. func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil + return &stmt{conn: c, query: query}, nil } func (c *conn) Close() error { @@ -57,7 +68,7 @@ func (c *conn) Begin() (driver.Tx, error) { } type stmt struct { - c *conn + conn *conn query string } @@ -77,22 +88,53 @@ func (s *stmt) NumInput() int { // Query executes a query that may return rows, such as a SELECT. func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] + rdbmsParams := make([]pg.ParameterValue, len(args)) + for i, v := range args { + rdbmsParams[i] = toRdbmsParameterValue(v) + } + + results := s.conn.spinConn.Query(s.query, rdbmsParams) + if results.IsErr() { + return nil, toError(results.Err()) } - return query(s.c.address, s.query, params) + + rowLen := len(results.Ok().Rows) + allRows := make([][]any, rowLen) + for rowNum, row := range results.Ok().Rows { + allRows[rowNum] = toRow(row) + } + + cols := results.Ok().Columns + colNames := make([]string, len(cols)) + colTypes := make([]uint8, len(cols)) + for i, c := range cols { + colNames[i] = c.Name + colTypes[i] = uint8(c.DataType) + } + + rows := &rows{ + columns: colNames, + columnType: colTypes, + rows: allRows, + len: int(rowLen), + } + return rows, nil } // Exec executes a query that doesn't return rows, such as an INSERT or // UPDATE. func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] + rdbmsParams := make([]pg.ParameterValue, len(args)) + for i, v := range args { + rdbmsParams[i] = toRdbmsParameterValue(v) } - n, err := execute(s.c.address, s.query, params) - return &result{rowsAffected: int64(n)}, err + + queryResult := s.conn.spinConn.Execute(s.query, rdbmsParams) + if queryResult.IsErr() { + return &result{}, toError(queryResult.Err()) + } + + return &result{}, nil } // ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. @@ -173,3 +215,126 @@ func (r *rows) NextResultSet() error { func (r *rows) ColumnTypeScanType(index int) reflect.Type { return colTypeToReflectType(r.columnType[index]) } + +func toRdbmsParameterValue(x any) pg.ParameterValue { + switch v := x.(type) { + case bool: + return rdbmstypes.MakeParameterValueBoolean(v) + case int8: + return rdbmstypes.MakeParameterValueInt8(v) + case int16: + return rdbmstypes.MakeParameterValueInt16(v) + case int32: + return rdbmstypes.MakeParameterValueInt32(v) + case int64: + return rdbmstypes.MakeParameterValueInt64(v) + case int: + return rdbmstypes.MakeParameterValueInt64(int64(v)) + case uint8: + return rdbmstypes.MakeParameterValueUint8(v) + case uint16: + return rdbmstypes.MakeParameterValueUint16(v) + case uint32: + return rdbmstypes.MakeParameterValueUint32(v) + case uint64: + return rdbmstypes.MakeParameterValueUint64(v) + case float32: + return rdbmstypes.MakeParameterValueFloating32(v) + case float64: + return rdbmstypes.MakeParameterValueFloating64(v) + case string: + return rdbmstypes.MakeParameterValueStr(v) + case []byte: + return rdbmstypes.MakeParameterValueBinary(v) + case nil: + return rdbmstypes.MakeParameterValueDbNull() + default: + panic("unknown value type") + } +} + +func toError(err pg.Error) error { + switch err.Tag() { + case rdbmstypes.ErrorBadParameter: + return errors.New(err.BadParameter()) + case rdbmstypes.ErrorConnectionFailed: + return errors.New(err.ConnectionFailed()) + case rdbmstypes.ErrorQueryFailed: + return errors.New(err.QueryFailed()) + case rdbmstypes.ErrorValueConversionFailed: + return errors.New(err.ValueConversionFailed()) + default: + // TODO: not sure if using "Other" as the default is appropriate + return errors.New(err.Other()) + } +} + +func toRow(row []rdbmstypes.DbValue) []any { + result := make([]any, len(row)) + for i, v := range row { + switch v.Tag() { + case rdbmstypes.DbValueBoolean: + result[i] = v.Boolean() + case rdbmstypes.DbValueInt8: + result[i] = v.Int8() + case rdbmstypes.DbValueInt16: + result[i] = v.Int16() + case rdbmstypes.DbValueInt32: + result[i] = v.Int32() + case rdbmstypes.DbValueInt64: + result[i] = v.Int64() + case rdbmstypes.DbValueUint8: + result[i] = v.Uint8() + case rdbmstypes.DbValueUint16: + result[i] = v.Uint16() + case rdbmstypes.DbValueUint32: + result[i] = v.Uint32() + case rdbmstypes.DbValueUint64: + result[i] = v.Uint64() + case rdbmstypes.DbValueFloating32: + result[i] = v.Floating32() + case rdbmstypes.DbValueFloating64: + result[i] = v.Floating64() + case rdbmstypes.DbValueStr: + result[i] = v.Str() + case rdbmstypes.DbValueBinary: + result[i] = v.Binary() + case rdbmstypes.DbValueDbNull: + result[i] = nil + default: + panic("unknown value type") + } + } + + return result +} + +func colTypeToReflectType(typ uint8) reflect.Type { + switch typ { + case uint8(rdbmstypes.DbDataTypeBoolean): + return reflect.TypeOf(false) + case uint8(rdbmstypes.DbDataTypeInt8): + return reflect.TypeOf(int8(0)) + case uint8(rdbmstypes.DbDataTypeInt16): + return reflect.TypeOf(int16(0)) + case uint8(rdbmstypes.DbDataTypeInt32): + return reflect.TypeOf(int32(0)) + case uint8(rdbmstypes.DbDataTypeInt64): + return reflect.TypeOf(int64(0)) + case uint8(rdbmstypes.DbDataTypeUint8): + return reflect.TypeOf(uint8(0)) + case uint8(rdbmstypes.DbDataTypeUint16): + return reflect.TypeOf(uint16(0)) + case uint8(rdbmstypes.DbDataTypeUint32): + return reflect.TypeOf(uint32(0)) + case uint8(rdbmstypes.DbDataTypeUint64): + return reflect.TypeOf(uint64(0)) + case uint8(rdbmstypes.DbDataTypeStr): + return reflect.TypeOf("") + case uint8(rdbmstypes.DbDataTypeBinary): + return reflect.TypeOf(new([]byte)) + case uint8(rdbmstypes.DbDataTypeOther): + return reflect.TypeOf(new(any)).Elem() + } + panic("invalid db column type of " + string(typ)) +} diff --git a/readme.md b/readme.md deleted file mode 100644 index dc34f3e7..00000000 --- a/readme.md +++ /dev/null @@ -1,21 +0,0 @@ -# The (Tiny)Go SDK for Spin - -This package contains an SDK that facilitates building Spin components in -(Tiny)Go. It allows building HTTP components that target the Spin -executor. - -```go -import ( - "fmt" - spinhttp "github.com/spinframework/spin-go-sdk/v2/http" -) - -func init() { - // call the Handle function - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello, Fermyon!") - }) -} - -func main() {} -``` diff --git a/redis/internals.go b/redis/internals.go deleted file mode 100644 index 4b71ab63..00000000 --- a/redis/internals.go +++ /dev/null @@ -1,241 +0,0 @@ -package redis - -// #include "outbound-redis.h" -// #include "spin-redis.h" -// #include -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -// argumentKind represents a type of a argument for executing a Redis command. -type argumentKind uint8 - -const ( - argumentKindInt argumentKind = iota - argumentKindBinary -) - -// argument represents an argument for a Redis command. -type argument struct { - kind argumentKind - val any -} - -func createParameter(x any) (*argument, error) { - var p argument - switch v := x.(type) { - case int: - p.kind = argumentKindInt - p.val = int64(v) - case int32: - p.kind = argumentKindInt - p.val = int64(v) - case int64: - p.kind = argumentKindInt - p.val = v - case string: - p.kind = argumentKindBinary - p.val = []byte(v) - case []byte: - p.kind = argumentKindBinary - p.val = v - default: - return &p, fmt.Errorf("unsupported parameter type: %T", x) - } - return &p, nil -} - -//export spin_redis_handle_redis_message -func handleRedisMessage(payload *C.spin_redis_payload_t) C.spin_redis_error_t { - bytes := C.GoBytes(unsafe.Pointer(payload.ptr), C.int(payload.len)) - if err := handler(bytes); err != nil { - return C.uint8_t(1) - - } - return C.uint8_t(0) -} - -func publish(addr, channel string, payload []byte) error { - caddr := redisStr(addr) - cchannel := redisStr(channel) - cpayload := C.outbound_redis_payload_t{ptr: &payload[0], len: C.size_t(len(payload))} - - err := C.outbound_redis_publish(&caddr, &cchannel, &cpayload) - return toErr(err) -} - -func get(addr, key string) ([]byte, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.outbound_redis_payload_t - - err := C.outbound_redis_get(&caddr, &ckey, &cpayload) - payload := C.GoBytes(unsafe.Pointer(cpayload.ptr), C.int(cpayload.len)) - return payload, toErr(err) -} - -func set(addr, key string, payload []byte) error { - caddr := redisStr(addr) - ckey := redisStr(key) - cpayload := C.outbound_redis_payload_t{ptr: &payload[0], len: C.size_t(len(payload))} - - err := C.outbound_redis_set(&caddr, &ckey, &cpayload) - return toErr(err) -} - -func incr(addr, key string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.int64_t - - err := C.outbound_redis_incr(&caddr, &ckey, &cpayload) - return int64(cpayload), toErr(err) -} - -func del(addr string, keys []string) (int64, error) { - caddr := redisStr(addr) - ckeys := redisListStr(keys) - - var cpayload C.int64_t - - err := C.outbound_redis_del(&caddr, &ckeys, &cpayload) - return int64(cpayload), toErr(err) -} - -func sadd(addr, key string, values []string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - cvalues := redisListStr(values) - - var cpayload C.int64_t - - err := C.outbound_redis_sadd(&caddr, &ckey, &cvalues, &cpayload) - return int64(cpayload), toErr(err) -} - -func smembers(addr, key string) ([]string, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - - var cpayload C.outbound_redis_list_string_t - - err := C.outbound_redis_smembers(&caddr, &ckey, &cpayload) - return fromRedisListStr(&cpayload), toErr(err) -} - -func srem(addr, key string, values []string) (int64, error) { - caddr := redisStr(addr) - ckey := redisStr(key) - cvalues := redisListStr(values) - - var cpayload C.int64_t - - err := C.outbound_redis_srem(&caddr, &ckey, &cvalues, &cpayload) - return int64(cpayload), toErr(err) -} - -func execute(addr, command string, arguments []*argument) ([]*Result, error) { - caddr := redisStr(addr) - ccommand := redisStr(command) - carguments := redisListParameter(arguments) - - var cpayload C.outbound_redis_list_redis_result_t - - err := C.outbound_redis_execute(&caddr, &ccommand, &carguments, &cpayload) - return fromRedisListResult(&cpayload), toErr(err) -} - -func redisStr(x string) C.outbound_redis_string_t { - return C.outbound_redis_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func redisListStr(xs []string) C.outbound_redis_list_string_t { - if len(xs) == 0 { - return C.outbound_redis_list_string_t{} - } - cxs := make([]C.outbound_redis_string_t, 0, len(xs)) - for i := 0; i < len(xs); i++ { - cxs = append(cxs, redisStr(xs[i])) - } - return C.outbound_redis_list_string_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromRedisListStr(list *C.outbound_redis_list_string_t) []string { - listLen := int(list.len) - result := make([]string, 0, listLen) - - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - result = append(result, C.GoStringN(str.ptr, C.int(str.len))) - } - return result -} - -func redisParameter(x *argument) C.outbound_redis_redis_parameter_t { - var ret C.outbound_redis_redis_parameter_t - switch x.kind { - case argumentKindInt: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = x.val.(int64) - case argumentKindBinary: - value := x.val.([]byte) - payload := C.outbound_redis_payload_t{ptr: &value[0], len: C.size_t(len(value))} - *(*C.outbound_redis_payload_t)(unsafe.Pointer(&ret.val)) = payload - } - ret.tag = C.uint8_t(x.kind) - return ret -} - -func redisListParameter(xs []*argument) C.outbound_redis_list_redis_parameter_t { - if len(xs) == 0 { - return C.outbound_redis_list_redis_parameter_t{} - } - - cxs := make([]C.outbound_redis_redis_parameter_t, 0, len(xs)) - for i := 0; i < len(xs); i++ { - cxs = append(cxs, redisParameter(xs[i])) - } - return C.outbound_redis_list_redis_parameter_t{ptr: &cxs[0], len: C.size_t(len(cxs))} -} - -func fromRedisResult(result *C.outbound_redis_redis_result_t) *Result { - var val any - switch ResultKind(result.tag) { - case ResultKindNil: - val = nil - case ResultKindStatus: - str := (*C.outbound_redis_string_t)(unsafe.Pointer(&result.val)) - val = C.GoStringN(str.ptr, C.int(str.len)) - case ResultKindInt64: - val = int64(*(*C.int64_t)(unsafe.Pointer(&result.val))) - case ResultKindBinary: - payload := (*C.outbound_redis_payload_t)(unsafe.Pointer(&result.val)) - val = C.GoBytes(unsafe.Pointer(payload.ptr), C.int(payload.len)) - } - - return &Result{Kind: ResultKind(result.tag), Val: val} -} - -func fromRedisListResult(list *C.outbound_redis_list_redis_result_t) []*Result { - listLen := int(list.len) - result := make([]*Result, 0, listLen) - - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - result = append(result, fromRedisResult(&slice[i])) - } - - return result -} - -func toErr(code C.uint8_t) error { - if code == 1 { - return errors.New("internal server error") - } - return nil -} diff --git a/redis/internals_test.go b/redis/internals_test.go deleted file mode 100644 index 191fa6ee..00000000 --- a/redis/internals_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package redis - -import ( - "reflect" - "testing" -) - -func TestCreateParameter(t *testing.T) { - tests := []struct { - in any - want argumentKind - }{ - {in: "a", want: argumentKindBinary}, - {in: []byte("b"), want: argumentKindBinary}, - {in: 1, want: argumentKindInt}, - {in: int64(2), want: argumentKindInt}, - {in: int32(3), want: argumentKindInt}, - } - - for _, tc := range tests { - p, err := createParameter(tc.in) - if err != nil { - t.Error(err) - } - if p.kind != tc.want { - t.Errorf("want %s, got %s", tc.want, p.kind) - } - } -} - -func TestRedisListString(t *testing.T) { - list := []string{"a", "b", "c"} - - rlist := redisListStr(list) - got := fromRedisListStr(&rlist) - - if !reflect.DeepEqual(list, got) { - t.Errorf("want %s, got %s", list, got) - } -} diff --git a/redis/outbound-redis.c b/redis/outbound-redis.c deleted file mode 100644 index 40feb726..00000000 --- a/redis/outbound-redis.c +++ /dev/null @@ -1,320 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void outbound_redis_string_set(outbound_redis_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void outbound_redis_string_dup(outbound_redis_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void outbound_redis_string_free(outbound_redis_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void outbound_redis_payload_free(outbound_redis_payload_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void outbound_redis_redis_parameter_free(outbound_redis_redis_parameter_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_redis_payload_free(&ptr->val.binary); - break; - } - } -} -void outbound_redis_redis_result_free(outbound_redis_redis_result_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - outbound_redis_string_free(&ptr->val.status); - break; - } - case 3: { - outbound_redis_payload_free(&ptr->val.binary); - break; - } - } -} -typedef struct { - bool is_err; - union { - outbound_redis_error_t err; - } val; -} outbound_redis_expected_unit_error_t; -typedef struct { - bool is_err; - union { - outbound_redis_payload_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_payload_error_t; -typedef struct { - bool is_err; - union { - int64_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_s64_error_t; -void outbound_redis_list_string_free(outbound_redis_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -typedef struct { - bool is_err; - union { - outbound_redis_list_string_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_list_string_error_t; -void outbound_redis_list_redis_parameter_free(outbound_redis_list_redis_parameter_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_redis_parameter_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void outbound_redis_list_redis_result_free(outbound_redis_list_redis_result_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - outbound_redis_redis_result_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -typedef struct { - bool is_err; - union { - outbound_redis_list_redis_result_t ok; - outbound_redis_error_t err; - } val; -} outbound_redis_expected_list_redis_result_error_t; - -__attribute__((aligned(8))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("outbound-redis"), import_name("publish"))) -void __wasm_import_outbound_redis_publish(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_publish(outbound_redis_string_t *address, outbound_redis_string_t *channel, outbound_redis_payload_t *payload) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_publish((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*channel).ptr, (int32_t) (*channel).len, (int32_t) (*payload).ptr, (int32_t) (*payload).len, ptr); - outbound_redis_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 1))); - break; - } - }return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("get"))) -void __wasm_import_outbound_redis_get(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_get(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_get((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_payload_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_payload_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("set"))) -void __wasm_import_outbound_redis_set(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_set(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *value) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_set((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*value).ptr, (int32_t) (*value).len, ptr); - outbound_redis_expected_unit_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 1))); - break; - } - }return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("incr"))) -void __wasm_import_outbound_redis_incr(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_incr(outbound_redis_string_t *address, outbound_redis_string_t *key, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_incr((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("del"))) -void __wasm_import_outbound_redis_del(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_del(outbound_redis_string_t *address, outbound_redis_list_string_t *keys, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_del((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*keys).ptr, (int32_t) (*keys).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("sadd"))) -void __wasm_import_outbound_redis_sadd(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_sadd(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_sadd((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*values).ptr, (int32_t) (*values).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("smembers"))) -void __wasm_import_outbound_redis_smembers(int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_smembers(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_smembers((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - outbound_redis_expected_list_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_list_string_t) { (outbound_redis_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("srem"))) -void __wasm_import_outbound_redis_srem(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_srem(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_srem((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*key).ptr, (int32_t) (*key).len, (int32_t) (*values).ptr, (int32_t) (*values).len, ptr); - outbound_redis_expected_s64_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = *((int64_t*) (ptr + 8)); - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 8))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} -__attribute__((import_module("outbound-redis"), import_name("execute"))) -void __wasm_import_outbound_redis_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -outbound_redis_error_t outbound_redis_execute(outbound_redis_string_t *address, outbound_redis_string_t *command, outbound_redis_list_redis_parameter_t *arguments, outbound_redis_list_redis_result_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_outbound_redis_execute((int32_t) (*address).ptr, (int32_t) (*address).len, (int32_t) (*command).ptr, (int32_t) (*command).len, (int32_t) (*arguments).ptr, (int32_t) (*arguments).len, ptr); - outbound_redis_expected_list_redis_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (outbound_redis_list_redis_result_t) { (outbound_redis_redis_result_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - - expected.val.err = (int32_t) (*((uint8_t*) (ptr + 4))); - break; - } - }*ret0 = expected.val.ok; - return expected.is_err ? expected.val.err : -1; -} diff --git a/redis/outbound-redis.h b/redis/outbound-redis.h deleted file mode 100644 index 4281bd97..00000000 --- a/redis/outbound-redis.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __BINDINGS_OUTBOUND_REDIS_H -#define __BINDINGS_OUTBOUND_REDIS_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } outbound_redis_string_t; - - void outbound_redis_string_set(outbound_redis_string_t *ret, const char *s); - void outbound_redis_string_dup(outbound_redis_string_t *ret, const char *s); - void outbound_redis_string_free(outbound_redis_string_t *ret); - typedef uint8_t outbound_redis_error_t; - #define OUTBOUND_REDIS_ERROR_SUCCESS 0 - #define OUTBOUND_REDIS_ERROR_ERROR 1 - typedef struct { - uint8_t *ptr; - size_t len; - } outbound_redis_payload_t; - void outbound_redis_payload_free(outbound_redis_payload_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t int64; - outbound_redis_payload_t binary; - } val; - } outbound_redis_redis_parameter_t; - #define OUTBOUND_REDIS_REDIS_PARAMETER_INT64 0 - #define OUTBOUND_REDIS_REDIS_PARAMETER_BINARY 1 - void outbound_redis_redis_parameter_free(outbound_redis_redis_parameter_t *ptr); - typedef struct { - uint8_t tag; - union { - outbound_redis_string_t status; - int64_t int64; - outbound_redis_payload_t binary; - } val; - } outbound_redis_redis_result_t; - #define OUTBOUND_REDIS_REDIS_RESULT_NIL 0 - #define OUTBOUND_REDIS_REDIS_RESULT_STATUS 1 - #define OUTBOUND_REDIS_REDIS_RESULT_INT64 2 - #define OUTBOUND_REDIS_REDIS_RESULT_BINARY 3 - void outbound_redis_redis_result_free(outbound_redis_redis_result_t *ptr); - typedef struct { - outbound_redis_string_t *ptr; - size_t len; - } outbound_redis_list_string_t; - void outbound_redis_list_string_free(outbound_redis_list_string_t *ptr); - typedef struct { - outbound_redis_redis_parameter_t *ptr; - size_t len; - } outbound_redis_list_redis_parameter_t; - void outbound_redis_list_redis_parameter_free(outbound_redis_list_redis_parameter_t *ptr); - typedef struct { - outbound_redis_redis_result_t *ptr; - size_t len; - } outbound_redis_list_redis_result_t; - void outbound_redis_list_redis_result_free(outbound_redis_list_redis_result_t *ptr); - outbound_redis_error_t outbound_redis_publish(outbound_redis_string_t *address, outbound_redis_string_t *channel, outbound_redis_payload_t *payload); - outbound_redis_error_t outbound_redis_get(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *ret0); - outbound_redis_error_t outbound_redis_set(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_payload_t *value); - outbound_redis_error_t outbound_redis_incr(outbound_redis_string_t *address, outbound_redis_string_t *key, int64_t *ret0); - outbound_redis_error_t outbound_redis_del(outbound_redis_string_t *address, outbound_redis_list_string_t *keys, int64_t *ret0); - outbound_redis_error_t outbound_redis_sadd(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0); - outbound_redis_error_t outbound_redis_smembers(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *ret0); - outbound_redis_error_t outbound_redis_srem(outbound_redis_string_t *address, outbound_redis_string_t *key, outbound_redis_list_string_t *values, int64_t *ret0); - outbound_redis_error_t outbound_redis_execute(outbound_redis_string_t *address, outbound_redis_string_t *command, outbound_redis_list_redis_parameter_t *arguments, outbound_redis_list_redis_result_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/redis/redis.go b/redis/redis.go index a5b03736..a32a1595 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -1,89 +1,118 @@ -// Package redis provides the handler function for the Redis trigger, as well -// as access to Redis within Spin components. +// Package redis provides access to Redis within Spin components. + package redis import ( - "errors" "fmt" - "os" -) -// handler is the function that will be called by the Redis trigger in Spin. -var handler = defaultHandler - -// defaultHandler is a placeholder for returning a useful error to stdout when -// the handler is not set. -var defaultHandler = func(payload []byte) error { - fmt.Fprintln(os.Stderr, "redis handler undefined") - return nil -} - -// Handle sets the handler function for redis. -// It must be set in an init() function. -func Handle(fn func(payload []byte) error) { - handler = fn -} + redis "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_redis" +) // Client is a Redis client. type Client struct { - addr string + conn redis.Connection } // NewClient returns a Redis client. -func NewClient(address string) *Client { - return &Client{addr: address} +func NewClient(address string) (Client, error) { + result := redis.ConnectionOpen(address) + if result.IsErr() { + return Client{}, toError(result.Err()) + } + + return Client{conn: *result.Ok()}, nil } // Publish a Redis message to the specified channel. func (c *Client) Publish(channel string, payload []byte) error { - if len(payload) == 0 { - return errors.New("payload is empty") + result := c.conn.Publish(channel, redis.Payload(payload)) + if result.IsErr() { + return toError(result.Err()) } - return publish(c.addr, channel, payload) + + return nil } -// Get the value of a key. An error is returned if the value stored at key is -// not a string. +// Get the value of a key. func (c *Client) Get(key string) ([]byte, error) { - return get(c.addr, key) + result := c.conn.Get(key) + if result.IsErr() { + return nil, toError(result.Err()) + } + + if result.Ok().IsNone() { + return nil, nil + } + + return result.Ok().Some(), nil } -// Set key to value. If key alreads holds a value, it is overwritten. +// Set key to value. +// +// If key already holds a value, it is overwritten. func (c *Client) Set(key string, payload []byte) error { - if len(payload) == 0 { - return errors.New("payload is empty") + result := c.conn.Set(key, redis.Payload(payload)) + if result.IsErr() { + return toError(result.Err()) } - return set(c.addr, key, payload) + + return nil } -// 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. +// 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. func (c *Client) Incr(key string) (int64, error) { - return incr(c.addr, key) + result := c.conn.Incr(key) + if result.IsErr() { + return 0, toError(result.Err()) + } + + return result.Ok(), nil } -// Del removes the specified keys. A key is ignored if it does not exist. -func (c *Client) Del(keys ...string) (int64, error) { - return del(c.addr, keys) +// Removes the specified keys. +// +// A key is ignored if it does not exist. Returns the number of keys deleted. +func (c *Client) Del(keys ...string) (uint32, error) { + result := c.conn.Del(keys) + if result.IsErr() { + return 0, toError(result.Err()) + } + + return result.Ok(), nil } -// Sadd adds the specified values to the set for the specified key, creating -// it if it does not already exist. -func (c *Client) Sadd(key string, values ...string) (int64, error) { - return sadd(c.addr, key, values) +// Add the specified `values` to the set named `key`, returning the number of newly-added values. +func (c *Client) Sadd(key string, values ...string) (uint32, error) { + result := c.conn.Sadd(key, values) + if result.IsErr() { + return 0, toError(result.Err()) + } + + return result.Ok(), nil } -// Smembers gets the elements of the set for the specified key. +// Retrieve the contents of the set named `key`. func (c *Client) Smembers(key string) ([]string, error) { - return smembers(c.addr, key) + result := c.conn.Smembers(key) + if result.IsErr() { + return nil, toError(result.Err()) + } + + return result.Ok(), nil } -// Srem removes the specified elements from the set for the specified key. -// This has no effect if the key does not exist. -func (c *Client) Srem(key string, values ...string) (int64, error) { - return srem(c.addr, key, values) +// Remove the specified `values` from the set named `key`, returning the number of newly-removed values. +func (c *Client) Srem(key string, values ...string) (uint32, error) { + result := c.conn.Srem(key, values) + if result.IsErr() { + return 0, toError(result.Err()) + } + + return result.Ok(), nil } // ResultKind represents a result type returned from executing a Redis command. @@ -127,7 +156,7 @@ type Result struct { // // Arguments must be string, []byte, int, int64, or int32. func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { - var params []*argument + var params []redis.RedisParameter for _, a := range arguments { p, err := createParameter(a) if err != nil { @@ -135,5 +164,62 @@ func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { } params = append(params, p) } - return execute(c.addr, command, params) + + result := c.conn.Execute(command, params) + if result.IsErr() { + return nil, toError(result.Err()) + } + + var results []*Result + for _, r := range result.Ok() { + results = append(results, toResult(r)) + } + + return results, nil +} + +func createParameter(x any) (redis.RedisParameter, error) { + switch v := x.(type) { + case int: + return redis.MakeRedisParameterInt64(int64(v)), nil + case int64: + return redis.MakeRedisParameterInt64(v), nil + case int32: + return redis.MakeRedisParameterInt64(int64(v)), nil + case []byte: + return redis.MakeRedisParameterBinary(redis.Payload(v)), nil + case string: + return redis.MakeRedisParameterBinary(redis.Payload(v)), nil + default: + return redis.RedisParameter{}, fmt.Errorf("invalid type %T; must be string, []byte, int, int64, or int32", v) + } +} + +func toResult(param redis.RedisResult) *Result { + switch param.Tag() { + case redis.RedisResultStatus: + return &Result{ + Kind: ResultKindStatus, + Val: param.Status(), + } + case redis.RedisResultInt64: + return &Result{ + Kind: ResultKindInt64, + Val: param.Int64(), + } + case redis.RedisResultBinary: + return &Result{ + Kind: ResultKindBinary, + Val: param.Binary(), + } + default: + return &Result{ + Kind: ResultKindNil, + Val: nil, + } + } +} + +func toError(e redis.Error) error { + return fmt.Errorf("%v", e.Other()) } diff --git a/redis/spin-redis.c b/redis/spin-redis.c deleted file mode 100644 index 665d4ebd..00000000 --- a/redis/spin-redis.c +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_redis_string_set(spin_redis_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_redis_string_dup(spin_redis_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_redis_string_free(spin_redis_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_redis_payload_free(spin_redis_payload_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void spin_redis_redis_parameter_free(spin_redis_redis_parameter_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - spin_redis_payload_free(&ptr->val.binary); - break; - } - } -} -void spin_redis_redis_result_free(spin_redis_redis_result_t *ptr) { - switch ((int32_t) ptr->tag) { - case 1: { - spin_redis_string_free(&ptr->val.status); - break; - } - case 3: { - spin_redis_payload_free(&ptr->val.binary); - break; - } - } -} -typedef struct { - bool is_err; - union { - spin_redis_error_t err; - } val; -} spin_redis_expected_unit_error_t; - -__attribute__((aligned(1))) -static uint8_t RET_AREA[2]; -__attribute__((export_name("handle-redis-message"))) -int32_t __wasm_export_spin_redis_handle_redis_message(int32_t arg, int32_t arg0) { - spin_redis_payload_t arg1 = (spin_redis_payload_t) { (uint8_t*)(arg), (size_t)(arg0) }; - spin_redis_error_t ret = spin_redis_handle_redis_message(&arg1); - - spin_redis_expected_unit_error_t ret2; - if (ret <= 2) { - ret2.is_err = true; - ret2.val.err = ret; - } else { - ret2.is_err = false; - - } - int32_t ptr = (int32_t) &RET_AREA; - - if ((ret2).is_err) { - const spin_redis_error_t *payload3 = &(ret2).val.err; - *((int8_t*)(ptr + 0)) = 1; - *((int8_t*)(ptr + 1)) = (int32_t) *payload3; - - } else { - - *((int8_t*)(ptr + 0)) = 0; - - } - return ptr; -} diff --git a/redis/spin-redis.h b/redis/spin-redis.h deleted file mode 100644 index 9f73ba40..00000000 --- a/redis/spin-redis.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef __BINDINGS_SPIN_REDIS_H -#define __BINDINGS_SPIN_REDIS_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_redis_string_t; - - void spin_redis_string_set(spin_redis_string_t *ret, const char *s); - void spin_redis_string_dup(spin_redis_string_t *ret, const char *s); - void spin_redis_string_free(spin_redis_string_t *ret); - typedef uint8_t spin_redis_error_t; - #define SPIN_REDIS_ERROR_SUCCESS 0 - #define SPIN_REDIS_ERROR_ERROR 1 - typedef struct { - uint8_t *ptr; - size_t len; - } spin_redis_payload_t; - void spin_redis_payload_free(spin_redis_payload_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t int64; - spin_redis_payload_t binary; - } val; - } spin_redis_redis_parameter_t; - #define SPIN_REDIS_REDIS_PARAMETER_INT64 0 - #define SPIN_REDIS_REDIS_PARAMETER_BINARY 1 - void spin_redis_redis_parameter_free(spin_redis_redis_parameter_t *ptr); - typedef struct { - uint8_t tag; - union { - spin_redis_string_t status; - int64_t int64; - spin_redis_payload_t binary; - } val; - } spin_redis_redis_result_t; - #define SPIN_REDIS_REDIS_RESULT_NIL 0 - #define SPIN_REDIS_REDIS_RESULT_STATUS 1 - #define SPIN_REDIS_REDIS_RESULT_INT64 2 - #define SPIN_REDIS_REDIS_RESULT_BINARY 3 - void spin_redis_redis_result_free(spin_redis_redis_result_t *ptr); - spin_redis_error_t spin_redis_handle_redis_message(spin_redis_payload_t *message); - #ifdef __cplusplus -} -#endif -#endif diff --git a/redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go b/redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go new file mode 100644 index 00000000..3cf5b75b --- /dev/null +++ b/redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go @@ -0,0 +1,14 @@ +package export_fermyon_spin_inbound_redis + +import ( + redis_types "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + wit "go.bytecodealliance.org/pkg/wit/types" +) + +var Exports struct { + Handle func(message []byte) wit.Result[wit.Unit, redis_types.Error] +} + +func HandleMessage(message []byte) wit.Result[wit.Unit, redis_types.Error] { + return Exports.Handle(message) +} diff --git a/redis_internal/fermyon_spin_config/wit_bindings.go b/redis_internal/fermyon_spin_config/wit_bindings.go new file mode 100644 index 00000000..3a22bad4 --- /dev/null +++ b/redis_internal/fermyon_spin_config/wit_bindings.go @@ -0,0 +1,146 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_config + +import ( + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +const ( + ErrorProvider uint8 = 0 + ErrorInvalidKey uint8 = 1 + ErrorInvalidSchema uint8 = 2 + ErrorOther uint8 = 3 +) + +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Provider() string { + if self.tag != ErrorProvider { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) InvalidKey() string { + if self.tag != ErrorInvalidKey { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) InvalidSchema() string { + if self.tag != ErrorInvalidSchema { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) Other() string { + if self.tag != ErrorOther { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorProvider(value string) Error { + return Error{ErrorProvider, value} +} +func MakeErrorInvalidKey(value string) Error { + return Error{ErrorInvalidKey, value} +} +func MakeErrorInvalidSchema(value string) Error { + return Error{ErrorInvalidSchema, value} +} +func MakeErrorOther(value string) Error { + return Error{ErrorOther, value} +} + +//go:wasmimport fermyon:spin/config get-config +func wasm_import_get_config(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func GetConfig(key string) witTypes.Result[string, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_get_config(uintptr(utf8), uint32(len(key)), returnArea) + var result witTypes.Result[string, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = witTypes.Ok[string, Error](value) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorProvider(value0) + + case 1: + value1 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidKey(value1) + + case 2: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidSchema(value2) + + case 3: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorOther(value3) + + default: + panic("unreachable") + } + + result = witTypes.Err[string, Error](variant) + default: + panic("unreachable") + } + result4 := result + return result4 + +} diff --git a/redis_internal/fermyon_spin_http/wit_bindings.go b/redis_internal/fermyon_spin_http/wit_bindings.go new file mode 100644 index 00000000..b3585e87 --- /dev/null +++ b/redis_internal/fermyon_spin_http/wit_bindings.go @@ -0,0 +1,154 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_http + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_http_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +type Request = fermyon_spin_http_types.Request +type Response = fermyon_spin_http_types.Response +type HttpError = fermyon_spin_http_types.HttpError + +//go:wasmimport fermyon:spin/http send-request +func wasm_import_send_request(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr, arg6 uint32, arg7 int32, arg8 uintptr, arg9 uint32, arg10 uintptr) + +func SendRequest(req fermyon_spin_http_types.Request) witTypes.Result[fermyon_spin_http_types.Response, fermyon_spin_http_types.HttpError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (8 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData((req).Uri)) + pinner.Pin(utf8) + slice := (req).Headers + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(4*4)) + utf80 := unsafe.Pointer(unsafe.StringData((element).F0)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + utf81 := unsafe.Pointer(unsafe.StringData((element).F1)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(utf81))) + + } + + slice4 := (req).Params + length6 := uint32(len(slice4)) + result5 := witRuntime.Allocate(pinner, uintptr(length6*(4*4)), 4) + for index, element := range slice4 { + base := unsafe.Add(result5, index*(4*4)) + utf82 := unsafe.Pointer(unsafe.StringData((element).F0)) + pinner.Pin(utf82) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf82))) + utf83 := unsafe.Pointer(unsafe.StringData((element).F1)) + pinner.Pin(utf83) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(utf83))) + + } + + var option int32 + var option7 uintptr + var option8 uint32 + switch (req).Body.Tag() { + case witTypes.OptionNone: + + option = int32(0) + option7 = 0 + option8 = 0 + case witTypes.OptionSome: + payload := (req).Body.Some() + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + + option = int32(1) + option7 = uintptr(data) + option8 = uint32(len(payload)) + default: + panic("unreachable") + } + wasm_import_send_request(int32((req).Method), uintptr(utf8), uint32(len((req).Uri)), uintptr(result), length, uintptr(result5), length6, option, option7, option8, returnArea) + var result14 witTypes.Result[fermyon_spin_http_types.Response, fermyon_spin_http_types.HttpError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + var option11 witTypes.Option[[]witTypes.Tuple2[string, string]] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) { + case 0: + + option11 = witTypes.None[[]witTypes.Tuple2[string, string]]() + case 1: + result10 := make([]witTypes.Tuple2[string, string], 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(4*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4)))) + + result10 = append(result10, witTypes.Tuple2[string, string]{value, value9}) + } + + option11 = witTypes.Some[[]witTypes.Tuple2[string, string]](result10) + default: + panic("unreachable") + } + var option13 witTypes.Option[[]uint8] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (5 * 4)))) { + case 0: + + option13 = witTypes.None[[]uint8]() + case 1: + value12 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (6 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (7 * 4)))) + + option13 = witTypes.Some[[]uint8](value12) + default: + panic("unreachable") + } + + result14 = witTypes.Ok[fermyon_spin_http_types.Response, fermyon_spin_http_types.HttpError](fermyon_spin_http_types.Response{uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), option11, option13}) + case 1: + + result14 = witTypes.Err[fermyon_spin_http_types.Response, fermyon_spin_http_types.HttpError](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result15 := result14 + return result15 + +} diff --git a/redis_internal/fermyon_spin_http_types/wit_bindings.go b/redis_internal/fermyon_spin_http_types/wit_bindings.go new file mode 100644 index 00000000..df90da65 --- /dev/null +++ b/redis_internal/fermyon_spin_http_types/wit_bindings.go @@ -0,0 +1,79 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_http_types + +import ( + witTypes "go.bytecodealliance.org/pkg/wit/types" +) + +type HttpStatus = uint16 +type Body = []uint8 +type Headers = []witTypes.Tuple2[string, string] +type Params = []witTypes.Tuple2[string, string] +type Uri = string + +const ( + MethodGet uint8 = 0 + MethodPost uint8 = 1 + MethodPut uint8 = 2 + MethodDelete uint8 = 3 + MethodPatch uint8 = 4 + MethodHead uint8 = 5 + MethodOptions uint8 = 6 +) + +type Method = uint8 + +type Request struct { + Method Method + Uri string + Headers []witTypes.Tuple2[string, string] + Params []witTypes.Tuple2[string, string] + Body witTypes.Option[[]uint8] +} + +type Response struct { + Status uint16 + Headers witTypes.Option[[]witTypes.Tuple2[string, string]] + Body witTypes.Option[[]uint8] +} + +const ( + HttpErrorSuccess uint8 = 0 + HttpErrorDestinationNotAllowed uint8 = 1 + HttpErrorInvalidUrl uint8 = 2 + HttpErrorRequestError uint8 = 3 + HttpErrorRuntimeError uint8 = 4 + HttpErrorTooManyRequests uint8 = 5 +) + +type HttpError = uint8 diff --git a/redis_internal/fermyon_spin_inbound_redis/wit_bindings.go b/redis_internal/fermyon_spin_inbound_redis/wit_bindings.go new file mode 100644 index 00000000..c30e3dc9 --- /dev/null +++ b/redis_internal/fermyon_spin_inbound_redis/wit_bindings.go @@ -0,0 +1,39 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_inbound_redis + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" +) + +type Payload = []uint8 +type Error = fermyon_spin_redis_types.Error diff --git a/redis_internal/fermyon_spin_key_value/wit_bindings.go b/redis_internal/fermyon_spin_key_value/wit_bindings.go new file mode 100644 index 00000000..22c77c2e --- /dev/null +++ b/redis_internal/fermyon_spin_key_value/wit_bindings.go @@ -0,0 +1,458 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_key_value + +import ( + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +// A handle to an open key-value store +type Store = uint32 + +const ( + // Too many stores have been opened simultaneously. Closing one or more + // stores prior to retrying may address this. + ErrorStoreTableFull uint8 = 0 + // 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. + ErrorNoSuchStore uint8 = 1 + // The requesting component does not have access to the specified store + // (which may or may not exist). + ErrorAccessDenied uint8 = 2 + // The store handle provided is not recognized, i.e. it was either never + // opened or has been closed. + ErrorInvalidStore uint8 = 3 + // No key-value tuple exists for the specified key in the specified + // store. + ErrorNoSuchKey uint8 = 4 + // Some implementation-specific error has occurred (e.g. I/O) + ErrorIo uint8 = 5 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Io() string { + if self.tag != ErrorIo { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorStoreTableFull() Error { + return Error{ErrorStoreTableFull, nil} +} +func MakeErrorNoSuchStore() Error { + return Error{ErrorNoSuchStore, nil} +} +func MakeErrorAccessDenied() Error { + return Error{ErrorAccessDenied, nil} +} +func MakeErrorInvalidStore() Error { + return Error{ErrorInvalidStore, nil} +} +func MakeErrorNoSuchKey() Error { + return Error{ErrorNoSuchKey, nil} +} +func MakeErrorIo(value string) Error { + return Error{ErrorIo, value} +} + +//go:wasmimport fermyon:spin/key-value open +func wasm_import_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Open(name string) witTypes.Result[uint32, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(name)) + pinner.Pin(utf8) + wasm_import_open(uintptr(utf8), uint32(len(name)), returnArea) + var result witTypes.Result[uint32, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value) + + default: + panic("unreachable") + } + + result = witTypes.Err[uint32, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value get +func wasm_import_get(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func Get(store uint32, key string) witTypes.Result[[]uint8, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_get(int32(store), uintptr(utf8), uint32(len(key)), returnArea) + var result witTypes.Result[[]uint8, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = witTypes.Ok[[]uint8, Error](value) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value0) + + default: + panic("unreachable") + } + + result = witTypes.Err[[]uint8, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/key-value set +func wasm_import_set(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func Set(store uint32, key string, value []uint8) witTypes.Result[witTypes.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_set(int32(store), uintptr(utf8), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) + var result witTypes.Result[witTypes.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value0) + + default: + panic("unreachable") + } + + result = witTypes.Err[witTypes.Unit, Error](variant) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/key-value delete +func wasm_import_delete(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func Delete(store uint32, key string) witTypes.Result[witTypes.Unit, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_delete(int32(store), uintptr(utf8), uint32(len(key)), returnArea) + var result witTypes.Result[witTypes.Unit, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[witTypes.Unit, Error](witTypes.Unit{}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value) + + default: + panic("unreachable") + } + + result = witTypes.Err[witTypes.Unit, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value exists +func wasm_import_exists(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr) + +func Exists(store uint32, key string) witTypes.Result[bool, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf8) + wasm_import_exists(int32(store), uintptr(utf8), uint32(len(key)), returnArea) + var result witTypes.Result[bool, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[bool, Error]((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) != 0)) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value) + + default: + panic("unreachable") + } + + result = witTypes.Err[bool, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/key-value get-keys +func wasm_import_get_keys(arg0 int32, arg1 uintptr) + +func GetKeys(store uint32) witTypes.Result[[]string, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + wasm_import_get_keys(int32(store), returnArea) + var result1 witTypes.Result[[]string, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result1 = witTypes.Ok[[]string, Error](result) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorStoreTableFull() + + case 1: + + variant = MakeErrorNoSuchStore() + + case 2: + + variant = MakeErrorAccessDenied() + + case 3: + + variant = MakeErrorInvalidStore() + + case 4: + + variant = MakeErrorNoSuchKey() + + case 5: + value0 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value0) + + default: + panic("unreachable") + } + + result1 = witTypes.Err[[]string, Error](variant) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/key-value close +func wasm_import_close(arg0 int32) + +func Close(store uint32) { + + wasm_import_close(int32(store)) + +} diff --git a/redis_internal/fermyon_spin_llm/wit_bindings.go b/redis_internal/fermyon_spin_llm/wit_bindings.go new file mode 100644 index 00000000..a3a518ee --- /dev/null +++ b/redis_internal/fermyon_spin_llm/wit_bindings.go @@ -0,0 +1,277 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_llm + +import ( + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +// A Large Language Model. +type InferencingModel = string + +// Inference request parameters +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 +} + +const ( + ErrorModelNotSupported uint8 = 0 + ErrorRuntimeError uint8 = 1 + ErrorInvalidInput uint8 = 2 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) RuntimeError() string { + if self.tag != ErrorRuntimeError { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Error) InvalidInput() string { + if self.tag != ErrorInvalidInput { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorModelNotSupported() Error { + return Error{ErrorModelNotSupported, nil} +} +func MakeErrorRuntimeError(value string) Error { + return Error{ErrorRuntimeError, value} +} +func MakeErrorInvalidInput(value string) Error { + return Error{ErrorInvalidInput, value} +} + +// Usage information related to the inferencing result +type InferencingUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 + // Number of tokens generated by the inferencing operation + GeneratedTokenCount uint32 +} + +// An inferencing result +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 +} + +// The model used for generating embeddings +type EmbeddingModel = string + +// Usage related to an embeddings generation request +type EmbeddingsUsage struct { + // Number of tokens in the prompt + PromptTokenCount uint32 +} + +// Result of generating embeddings +type EmbeddingsResult struct { + // The embeddings generated by the request + Embeddings [][]float32 + // Usage related to the embeddings generation request + Usage EmbeddingsUsage +} + +//go:wasmimport fermyon:spin/llm infer +func wasm_import_infer(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 int32, arg5 int32, arg6 float32, arg7 int32, arg8 float32, arg9 int32, arg10 float32, arg11 uintptr) + +func Infer(model string, prompt string, params witTypes.Option[InferencingParams]) witTypes.Result[InferencingResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (8 + 3*4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(model)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(prompt)) + pinner.Pin(utf80) + var option int32 + var option1 int32 + var option2 float32 + var option3 int32 + var option4 float32 + var option5 int32 + var option6 float32 + switch params.Tag() { + case witTypes.OptionNone: + + option = int32(0) + option1 = 0 + option2 = 0 + option3 = 0 + option4 = 0 + option5 = 0 + option6 = 0 + case witTypes.OptionSome: + payload := params.Some() + + option = int32(1) + option1 = int32((payload).MaxTokens) + option2 = (payload).RepeatPenalty + option3 = int32((payload).RepeatPenaltyLastNTokenCount) + option4 = (payload).Temperature + option5 = int32((payload).TopK) + option6 = (payload).TopP + default: + panic("unreachable") + } + wasm_import_infer(uintptr(utf8), uint32(len(model)), uintptr(utf80), uint32(len(prompt)), option, option1, option2, option3, option4, option5, option6, returnArea) + var result witTypes.Result[InferencingResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = witTypes.Ok[InferencingResult, Error](InferencingResult{value, InferencingUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))), uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (4 + 3*4))))}}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorModelNotSupported() + + case 1: + value7 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorRuntimeError(value7) + + case 2: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidInput(value8) + + default: + panic("unreachable") + } + + result = witTypes.Err[InferencingResult, Error](variant) + default: + panic("unreachable") + } + result9 := result + return result9 + +} + +//go:wasmimport fermyon:spin/llm generate-embeddings +func wasm_import_generate_embeddings(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func GenerateEmbeddings(model string, text []string) witTypes.Result[EmbeddingsResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(model)) + pinner.Pin(utf8) + slice := text + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf80 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + + } + + wasm_import_generate_embeddings(uintptr(utf8), uint32(len(model)), uintptr(result), length, returnArea) + var result4 witTypes.Result[EmbeddingsResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([][]float32, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.Slice((*float32)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result1 = append(result1, value) + } + + result4 = witTypes.Ok[EmbeddingsResult, Error](EmbeddingsResult{result1, EmbeddingsUsage{uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))}}) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorModelNotSupported() + + case 1: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorRuntimeError(value2) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorInvalidInput(value3) + + default: + panic("unreachable") + } + + result4 = witTypes.Err[EmbeddingsResult, Error](variant) + default: + panic("unreachable") + } + result5 := result4 + return result5 + +} diff --git a/redis_internal/fermyon_spin_mysql/wit_bindings.go b/redis_internal/fermyon_spin_mysql/wit_bindings.go new file mode 100644 index 00000000..acbd257e --- /dev/null +++ b/redis_internal/fermyon_spin_mysql/wit_bindings.go @@ -0,0 +1,513 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_mysql + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_rdbms_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +type ParameterValue = fermyon_spin_rdbms_types.ParameterValue +type RowSet = fermyon_spin_rdbms_types.RowSet + +const ( + MysqlErrorSuccess uint8 = 0 + MysqlErrorConnectionFailed uint8 = 1 + MysqlErrorBadParameter uint8 = 2 + MysqlErrorQueryFailed uint8 = 3 + MysqlErrorValueConversionFailed uint8 = 4 + MysqlErrorOtherError uint8 = 5 +) + +// General purpose error. +type MysqlError struct { + tag uint8 + value any +} + +func (self MysqlError) Tag() uint8 { + return self.tag +} + +func (self MysqlError) ConnectionFailed() string { + if self.tag != MysqlErrorConnectionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self MysqlError) BadParameter() string { + if self.tag != MysqlErrorBadParameter { + panic("tag mismatch") + } + return self.value.(string) +} +func (self MysqlError) QueryFailed() string { + if self.tag != MysqlErrorQueryFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self MysqlError) ValueConversionFailed() string { + if self.tag != MysqlErrorValueConversionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self MysqlError) OtherError() string { + if self.tag != MysqlErrorOtherError { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeMysqlErrorSuccess() MysqlError { + return MysqlError{MysqlErrorSuccess, nil} +} +func MakeMysqlErrorConnectionFailed(value string) MysqlError { + return MysqlError{MysqlErrorConnectionFailed, value} +} +func MakeMysqlErrorBadParameter(value string) MysqlError { + return MysqlError{MysqlErrorBadParameter, value} +} +func MakeMysqlErrorQueryFailed(value string) MysqlError { + return MysqlError{MysqlErrorQueryFailed, value} +} +func MakeMysqlErrorValueConversionFailed(value string) MysqlError { + return MysqlError{MysqlErrorValueConversionFailed, value} +} +func MakeMysqlErrorOtherError(value string) MysqlError { + return MysqlError{MysqlErrorOtherError, value} +} + +//go:wasmimport fermyon:spin/mysql query +func wasm_import_query(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Query(address string, statement string, params []fermyon_spin_rdbms_types.ParameterValue) witTypes.Result[fermyon_spin_rdbms_types.RowSet, MysqlError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf80) + slice := params + length := uint32(len(slice)) + result2 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result2, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf81 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf81))) + + case fermyon_spin_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_query(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(statement)), uintptr(result2), length, returnArea) + var result14 witTypes.Result[fermyon_spin_rdbms_types.RowSet, MysqlError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result3 := make([]fermyon_spin_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result3 = append(result3, fermyon_spin_rdbms_types.Column{value, uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))}) + } + + result7 := make([][]fermyon_spin_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result6 := make([]fermyon_spin_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant fermyon_spin_rdbms_types.DbValue + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = fermyon_spin_rdbms_types.MakeDbValueBoolean((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))) != 0)) + + case 1: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt8(int8(int8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 2: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt16(int16(int16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 3: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 4: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 5: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint8(uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 6: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint16(uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 7: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint32(uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 8: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint64(uint64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 9: + + variant = fermyon_spin_rdbms_types.MakeDbValueFloating32(*(*float32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 10: + + variant = fermyon_spin_rdbms_types.MakeDbValueFloating64(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 11: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_rdbms_types.MakeDbValueStr(value4) + + case 12: + value5 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_rdbms_types.MakeDbValueBinary(value5) + + case 13: + + variant = fermyon_spin_rdbms_types.MakeDbValueDbNull() + + case 14: + + variant = fermyon_spin_rdbms_types.MakeDbValueUnsupported() + + default: + panic("unreachable") + } + + result6 = append(result6, variant) + } + + result7 = append(result7, result6) + } + + result14 = witTypes.Ok[fermyon_spin_rdbms_types.RowSet, MysqlError](fermyon_spin_rdbms_types.RowSet{result3, result7}) + case 1: + var variant13 MysqlError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant13 = MakeMysqlErrorSuccess() + + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakeMysqlErrorConnectionFailed(value8) + + case 2: + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakeMysqlErrorBadParameter(value9) + + case 3: + value10 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakeMysqlErrorQueryFailed(value10) + + case 4: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakeMysqlErrorValueConversionFailed(value11) + + case 5: + value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakeMysqlErrorOtherError(value12) + + default: + panic("unreachable") + } + + result14 = witTypes.Err[fermyon_spin_rdbms_types.RowSet, MysqlError](variant13) + default: + panic("unreachable") + } + result15 := result14 + return result15 + +} + +//go:wasmimport fermyon:spin/mysql execute +func wasm_import_execute(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Execute(address string, statement string, params []fermyon_spin_rdbms_types.ParameterValue) witTypes.Result[witTypes.Unit, MysqlError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf80) + slice := params + length := uint32(len(slice)) + result2 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result2, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf81 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf81))) + + case fermyon_spin_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_execute(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(statement)), uintptr(result2), length, returnArea) + var result7 witTypes.Result[witTypes.Unit, MysqlError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result7 = witTypes.Ok[witTypes.Unit, MysqlError](witTypes.Unit{}) + case 1: + var variant MysqlError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeMysqlErrorSuccess() + + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeMysqlErrorConnectionFailed(value) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeMysqlErrorBadParameter(value3) + + case 3: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeMysqlErrorQueryFailed(value4) + + case 4: + value5 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeMysqlErrorValueConversionFailed(value5) + + case 5: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeMysqlErrorOtherError(value6) + + default: + panic("unreachable") + } + + result7 = witTypes.Err[witTypes.Unit, MysqlError](variant) + default: + panic("unreachable") + } + result8 := result7 + return result8 + +} diff --git a/redis_internal/fermyon_spin_postgres/wit_bindings.go b/redis_internal/fermyon_spin_postgres/wit_bindings.go new file mode 100644 index 00000000..730bb1d4 --- /dev/null +++ b/redis_internal/fermyon_spin_postgres/wit_bindings.go @@ -0,0 +1,513 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_postgres + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_rdbms_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +type ParameterValue = fermyon_spin_rdbms_types.ParameterValue +type RowSet = fermyon_spin_rdbms_types.RowSet + +const ( + PgErrorSuccess uint8 = 0 + PgErrorConnectionFailed uint8 = 1 + PgErrorBadParameter uint8 = 2 + PgErrorQueryFailed uint8 = 3 + PgErrorValueConversionFailed uint8 = 4 + PgErrorOtherError uint8 = 5 +) + +// General purpose error. +type PgError struct { + tag uint8 + value any +} + +func (self PgError) Tag() uint8 { + return self.tag +} + +func (self PgError) ConnectionFailed() string { + if self.tag != PgErrorConnectionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self PgError) BadParameter() string { + if self.tag != PgErrorBadParameter { + panic("tag mismatch") + } + return self.value.(string) +} +func (self PgError) QueryFailed() string { + if self.tag != PgErrorQueryFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self PgError) ValueConversionFailed() string { + if self.tag != PgErrorValueConversionFailed { + panic("tag mismatch") + } + return self.value.(string) +} +func (self PgError) OtherError() string { + if self.tag != PgErrorOtherError { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakePgErrorSuccess() PgError { + return PgError{PgErrorSuccess, nil} +} +func MakePgErrorConnectionFailed(value string) PgError { + return PgError{PgErrorConnectionFailed, value} +} +func MakePgErrorBadParameter(value string) PgError { + return PgError{PgErrorBadParameter, value} +} +func MakePgErrorQueryFailed(value string) PgError { + return PgError{PgErrorQueryFailed, value} +} +func MakePgErrorValueConversionFailed(value string) PgError { + return PgError{PgErrorValueConversionFailed, value} +} +func MakePgErrorOtherError(value string) PgError { + return PgError{PgErrorOtherError, value} +} + +//go:wasmimport fermyon:spin/postgres query +func wasm_import_query(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Query(address string, statement string, params []fermyon_spin_rdbms_types.ParameterValue) witTypes.Result[fermyon_spin_rdbms_types.RowSet, PgError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf80) + slice := params + length := uint32(len(slice)) + result2 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result2, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf81 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf81))) + + case fermyon_spin_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_query(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(statement)), uintptr(result2), length, returnArea) + var result14 witTypes.Result[fermyon_spin_rdbms_types.RowSet, PgError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result3 := make([]fermyon_spin_rdbms_types.Column, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(3*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result3 = append(result3, fermyon_spin_rdbms_types.Column{value, uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4)))))}) + } + + result7 := make([][]fermyon_spin_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result6 := make([]fermyon_spin_rdbms_types.DbValue, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant fermyon_spin_rdbms_types.DbValue + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = fermyon_spin_rdbms_types.MakeDbValueBoolean((uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))) != 0)) + + case 1: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt8(int8(int8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 2: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt16(int16(int16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 3: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 4: + + variant = fermyon_spin_rdbms_types.MakeDbValueInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 5: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint8(uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 6: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint16(uint16(uint16(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))) + + case 7: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint32(uint32(*(*int32)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 8: + + variant = fermyon_spin_rdbms_types.MakeDbValueUint64(uint64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8)))) + + case 9: + + variant = fermyon_spin_rdbms_types.MakeDbValueFloating32(*(*float32)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 10: + + variant = fermyon_spin_rdbms_types.MakeDbValueFloating64(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 11: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_rdbms_types.MakeDbValueStr(value4) + + case 12: + value5 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_rdbms_types.MakeDbValueBinary(value5) + + case 13: + + variant = fermyon_spin_rdbms_types.MakeDbValueDbNull() + + case 14: + + variant = fermyon_spin_rdbms_types.MakeDbValueUnsupported() + + default: + panic("unreachable") + } + + result6 = append(result6, variant) + } + + result7 = append(result7, result6) + } + + result14 = witTypes.Ok[fermyon_spin_rdbms_types.RowSet, PgError](fermyon_spin_rdbms_types.RowSet{result3, result7}) + case 1: + var variant13 PgError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant13 = MakePgErrorSuccess() + + case 1: + value8 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakePgErrorConnectionFailed(value8) + + case 2: + value9 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakePgErrorBadParameter(value9) + + case 3: + value10 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakePgErrorQueryFailed(value10) + + case 4: + value11 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakePgErrorValueConversionFailed(value11) + + case 5: + value12 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant13 = MakePgErrorOtherError(value12) + + default: + panic("unreachable") + } + + result14 = witTypes.Err[fermyon_spin_rdbms_types.RowSet, PgError](variant13) + default: + panic("unreachable") + } + result15 := result14 + return result15 + +} + +//go:wasmimport fermyon:spin/postgres execute +func wasm_import_execute(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Execute(address string, statement string, params []fermyon_spin_rdbms_types.ParameterValue) witTypes.Result[uint64, PgError] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (16 + 2*4), 8)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf80) + slice := params + length := uint32(len(slice)) + result2 := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result2, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_rdbms_types.ParameterValueBoolean: + payload := element.Boolean() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + var result int32 + if payload { + result = 1 + } else { + result = 0 + } + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(result) + + case fermyon_spin_rdbms_types.ParameterValueInt8: + payload := element.Int8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt16: + payload := element.Int16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueInt32: + payload := element.Int32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueUint8: + payload := element.Uint8() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(5)) + *(*int8)(unsafe.Add(unsafe.Pointer(base), 8)) = int8(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint16: + payload := element.Uint16() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(6)) + *(*int16)(unsafe.Add(unsafe.Pointer(base), 8)) = int16(int32(payload)) + + case fermyon_spin_rdbms_types.ParameterValueUint32: + payload := element.Uint32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(7)) + *(*int32)(unsafe.Add(unsafe.Pointer(base), 8)) = int32(payload) + + case fermyon_spin_rdbms_types.ParameterValueUint64: + payload := element.Uint64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(8)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = int64(payload) + + case fermyon_spin_rdbms_types.ParameterValueFloating32: + payload := element.Floating32() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(9)) + *(*float32)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueFloating64: + payload := element.Floating64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(10)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_rdbms_types.ParameterValueStr: + payload := element.Str() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(11)) + utf81 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf81))) + + case fermyon_spin_rdbms_types.ParameterValueBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(12)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case fermyon_spin_rdbms_types.ParameterValueDbNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(13)) + + default: + panic("unreachable") + } + + } + + wasm_import_execute(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(statement)), uintptr(result2), length, returnArea) + var result7 witTypes.Result[uint64, PgError] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result7 = witTypes.Ok[uint64, PgError](uint64(*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8)))) + case 1: + var variant PgError + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))) { + case 0: + + variant = MakePgErrorSuccess() + + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakePgErrorConnectionFailed(value) + + case 2: + value3 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakePgErrorBadParameter(value3) + + case 3: + value4 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakePgErrorQueryFailed(value4) + + case 4: + value5 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakePgErrorValueConversionFailed(value5) + + case 5: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 1*4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (8 + 2*4)))) + + variant = MakePgErrorOtherError(value6) + + default: + panic("unreachable") + } + + result7 = witTypes.Err[uint64, PgError](variant) + default: + panic("unreachable") + } + result8 := result7 + return result8 + +} diff --git a/redis_internal/fermyon_spin_rdbms_types/wit_bindings.go b/redis_internal/fermyon_spin_rdbms_types/wit_bindings.go new file mode 100644 index 00000000..656259a3 --- /dev/null +++ b/redis_internal/fermyon_spin_rdbms_types/wit_bindings.go @@ -0,0 +1,364 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_rdbms_types + +import () + +const ( + DbDataTypeBoolean uint8 = 0 + DbDataTypeInt8 uint8 = 1 + DbDataTypeInt16 uint8 = 2 + DbDataTypeInt32 uint8 = 3 + DbDataTypeInt64 uint8 = 4 + DbDataTypeUint8 uint8 = 5 + DbDataTypeUint16 uint8 = 6 + DbDataTypeUint32 uint8 = 7 + DbDataTypeUint64 uint8 = 8 + DbDataTypeFloating32 uint8 = 9 + DbDataTypeFloating64 uint8 = 10 + DbDataTypeStr uint8 = 11 + DbDataTypeBinary uint8 = 12 + DbDataTypeOther uint8 = 13 +) + +type DbDataType = uint8 + +const ( + DbValueBoolean uint8 = 0 + DbValueInt8 uint8 = 1 + DbValueInt16 uint8 = 2 + DbValueInt32 uint8 = 3 + DbValueInt64 uint8 = 4 + DbValueUint8 uint8 = 5 + DbValueUint16 uint8 = 6 + DbValueUint32 uint8 = 7 + DbValueUint64 uint8 = 8 + DbValueFloating32 uint8 = 9 + DbValueFloating64 uint8 = 10 + DbValueStr uint8 = 11 + DbValueBinary uint8 = 12 + DbValueDbNull uint8 = 13 + DbValueUnsupported uint8 = 14 +) + +type DbValue struct { + tag uint8 + value any +} + +func (self DbValue) Tag() uint8 { + return self.tag +} + +func (self DbValue) Boolean() bool { + if self.tag != DbValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self DbValue) Int8() int8 { + if self.tag != DbValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self DbValue) Int16() int16 { + if self.tag != DbValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self DbValue) Int32() int32 { + if self.tag != DbValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self DbValue) Int64() int64 { + if self.tag != DbValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self DbValue) Uint8() uint8 { + if self.tag != DbValueUint8 { + panic("tag mismatch") + } + return self.value.(uint8) +} +func (self DbValue) Uint16() uint16 { + if self.tag != DbValueUint16 { + panic("tag mismatch") + } + return self.value.(uint16) +} +func (self DbValue) Uint32() uint32 { + if self.tag != DbValueUint32 { + panic("tag mismatch") + } + return self.value.(uint32) +} +func (self DbValue) Uint64() uint64 { + if self.tag != DbValueUint64 { + panic("tag mismatch") + } + return self.value.(uint64) +} +func (self DbValue) Floating32() float32 { + if self.tag != DbValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self DbValue) Floating64() float64 { + if self.tag != DbValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self DbValue) Str() string { + if self.tag != DbValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self DbValue) Binary() []uint8 { + if self.tag != DbValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeDbValueBoolean(value bool) DbValue { + return DbValue{DbValueBoolean, value} +} +func MakeDbValueInt8(value int8) DbValue { + return DbValue{DbValueInt8, value} +} +func MakeDbValueInt16(value int16) DbValue { + return DbValue{DbValueInt16, value} +} +func MakeDbValueInt32(value int32) DbValue { + return DbValue{DbValueInt32, value} +} +func MakeDbValueInt64(value int64) DbValue { + return DbValue{DbValueInt64, value} +} +func MakeDbValueUint8(value uint8) DbValue { + return DbValue{DbValueUint8, value} +} +func MakeDbValueUint16(value uint16) DbValue { + return DbValue{DbValueUint16, value} +} +func MakeDbValueUint32(value uint32) DbValue { + return DbValue{DbValueUint32, value} +} +func MakeDbValueUint64(value uint64) DbValue { + return DbValue{DbValueUint64, value} +} +func MakeDbValueFloating32(value float32) DbValue { + return DbValue{DbValueFloating32, value} +} +func MakeDbValueFloating64(value float64) DbValue { + return DbValue{DbValueFloating64, value} +} +func MakeDbValueStr(value string) DbValue { + return DbValue{DbValueStr, value} +} +func MakeDbValueBinary(value []uint8) DbValue { + return DbValue{DbValueBinary, value} +} +func MakeDbValueDbNull() DbValue { + return DbValue{DbValueDbNull, nil} +} +func MakeDbValueUnsupported() DbValue { + return DbValue{DbValueUnsupported, nil} +} + +const ( + ParameterValueBoolean uint8 = 0 + ParameterValueInt8 uint8 = 1 + ParameterValueInt16 uint8 = 2 + ParameterValueInt32 uint8 = 3 + ParameterValueInt64 uint8 = 4 + ParameterValueUint8 uint8 = 5 + ParameterValueUint16 uint8 = 6 + ParameterValueUint32 uint8 = 7 + ParameterValueUint64 uint8 = 8 + ParameterValueFloating32 uint8 = 9 + ParameterValueFloating64 uint8 = 10 + ParameterValueStr uint8 = 11 + ParameterValueBinary uint8 = 12 + ParameterValueDbNull uint8 = 13 +) + +type ParameterValue struct { + tag uint8 + value any +} + +func (self ParameterValue) Tag() uint8 { + return self.tag +} + +func (self ParameterValue) Boolean() bool { + if self.tag != ParameterValueBoolean { + panic("tag mismatch") + } + return self.value.(bool) +} +func (self ParameterValue) Int8() int8 { + if self.tag != ParameterValueInt8 { + panic("tag mismatch") + } + return self.value.(int8) +} +func (self ParameterValue) Int16() int16 { + if self.tag != ParameterValueInt16 { + panic("tag mismatch") + } + return self.value.(int16) +} +func (self ParameterValue) Int32() int32 { + if self.tag != ParameterValueInt32 { + panic("tag mismatch") + } + return self.value.(int32) +} +func (self ParameterValue) Int64() int64 { + if self.tag != ParameterValueInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self ParameterValue) Uint8() uint8 { + if self.tag != ParameterValueUint8 { + panic("tag mismatch") + } + return self.value.(uint8) +} +func (self ParameterValue) Uint16() uint16 { + if self.tag != ParameterValueUint16 { + panic("tag mismatch") + } + return self.value.(uint16) +} +func (self ParameterValue) Uint32() uint32 { + if self.tag != ParameterValueUint32 { + panic("tag mismatch") + } + return self.value.(uint32) +} +func (self ParameterValue) Uint64() uint64 { + if self.tag != ParameterValueUint64 { + panic("tag mismatch") + } + return self.value.(uint64) +} +func (self ParameterValue) Floating32() float32 { + if self.tag != ParameterValueFloating32 { + panic("tag mismatch") + } + return self.value.(float32) +} +func (self ParameterValue) Floating64() float64 { + if self.tag != ParameterValueFloating64 { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self ParameterValue) Str() string { + if self.tag != ParameterValueStr { + panic("tag mismatch") + } + return self.value.(string) +} +func (self ParameterValue) Binary() []uint8 { + if self.tag != ParameterValueBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeParameterValueBoolean(value bool) ParameterValue { + return ParameterValue{ParameterValueBoolean, value} +} +func MakeParameterValueInt8(value int8) ParameterValue { + return ParameterValue{ParameterValueInt8, value} +} +func MakeParameterValueInt16(value int16) ParameterValue { + return ParameterValue{ParameterValueInt16, value} +} +func MakeParameterValueInt32(value int32) ParameterValue { + return ParameterValue{ParameterValueInt32, value} +} +func MakeParameterValueInt64(value int64) ParameterValue { + return ParameterValue{ParameterValueInt64, value} +} +func MakeParameterValueUint8(value uint8) ParameterValue { + return ParameterValue{ParameterValueUint8, value} +} +func MakeParameterValueUint16(value uint16) ParameterValue { + return ParameterValue{ParameterValueUint16, value} +} +func MakeParameterValueUint32(value uint32) ParameterValue { + return ParameterValue{ParameterValueUint32, value} +} +func MakeParameterValueUint64(value uint64) ParameterValue { + return ParameterValue{ParameterValueUint64, value} +} +func MakeParameterValueFloating32(value float32) ParameterValue { + return ParameterValue{ParameterValueFloating32, value} +} +func MakeParameterValueFloating64(value float64) ParameterValue { + return ParameterValue{ParameterValueFloating64, value} +} +func MakeParameterValueStr(value string) ParameterValue { + return ParameterValue{ParameterValueStr, value} +} +func MakeParameterValueBinary(value []uint8) ParameterValue { + return ParameterValue{ParameterValueBinary, value} +} +func MakeParameterValueDbNull() ParameterValue { + return ParameterValue{ParameterValueDbNull, nil} +} + +type Column struct { + Name string + DataType DbDataType +} +type Row = []DbValue + +type RowSet struct { + Columns []Column + Rows [][]DbValue +} diff --git a/redis_internal/fermyon_spin_redis/wit_bindings.go b/redis_internal/fermyon_spin_redis/wit_bindings.go new file mode 100644 index 00000000..1e97392d --- /dev/null +++ b/redis_internal/fermyon_spin_redis/wit_bindings.go @@ -0,0 +1,407 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_redis + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +type Payload = []uint8 +type RedisParameter = fermyon_spin_redis_types.RedisParameter +type RedisResult = fermyon_spin_redis_types.RedisResult +type Error = fermyon_spin_redis_types.Error + +//go:wasmimport fermyon:spin/redis publish +func wasm_import_publish(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Publish(address string, channel string, payload []uint8) witTypes.Result[witTypes.Unit, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(channel)) + pinner.Pin(utf80) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + wasm_import_publish(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(channel)), uintptr(data), uint32(len(payload)), returnArea) + var result witTypes.Result[witTypes.Unit, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[witTypes.Unit, fermyon_spin_redis_types.Error](witTypes.Unit{}) + case 1: + + result = witTypes.Err[witTypes.Unit, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis get +func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func Get(address string, key string) witTypes.Result[[]uint8, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + wasm_import_get(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), returnArea) + var result witTypes.Result[[]uint8, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + value := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + + result = witTypes.Ok[[]uint8, fermyon_spin_redis_types.Error](value) + case 1: + + result = witTypes.Err[[]uint8, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis set +func wasm_import_set(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Set(address string, key string, value []uint8) witTypes.Result[witTypes.Unit, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 2, 1)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + data := unsafe.Pointer(unsafe.SliceData(value)) + pinner.Pin(data) + wasm_import_set(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), uintptr(data), uint32(len(value)), returnArea) + var result witTypes.Result[witTypes.Unit, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[witTypes.Unit, fermyon_spin_redis_types.Error](witTypes.Unit{}) + case 1: + + result = witTypes.Err[witTypes.Unit, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 1))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis incr +func wasm_import_incr(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func Incr(address string, key string) witTypes.Result[int64, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + wasm_import_incr(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), returnArea) + var result witTypes.Result[int64, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[int64, fermyon_spin_redis_types.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + + result = witTypes.Err[int64, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result1 := result + return result1 + +} + +//go:wasmimport fermyon:spin/redis del +func wasm_import_del(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func Del(address string, keys []string) witTypes.Result[int64, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + slice := keys + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf80 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf80))) + + } + + wasm_import_del(uintptr(utf8), uint32(len(address)), uintptr(result), length, returnArea) + var result1 witTypes.Result[int64, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result1 = witTypes.Ok[int64, fermyon_spin_redis_types.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + + result1 = witTypes.Err[int64, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/redis sadd +func wasm_import_sadd(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Sadd(address string, key string, values []string) witTypes.Result[int64, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + slice := values + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf81 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf81))) + + } + + wasm_import_sadd(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), uintptr(result), length, returnArea) + var result2 witTypes.Result[int64, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result2 = witTypes.Ok[int64, fermyon_spin_redis_types.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + + result2 = witTypes.Err[int64, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result3 := result2 + return result3 + +} + +//go:wasmimport fermyon:spin/redis smembers +func wasm_import_smembers(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr) + +func Smembers(address string, key string) witTypes.Result[[]string, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + wasm_import_smembers(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), returnArea) + var result1 witTypes.Result[[]string, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result = append(result, value) + } + + result1 = witTypes.Ok[[]string, fermyon_spin_redis_types.Error](result) + case 1: + + result1 = witTypes.Err[[]string, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result2 := result1 + return result2 + +} + +//go:wasmimport fermyon:spin/redis srem +func wasm_import_srem(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Srem(address string, key string, values []string) witTypes.Result[int64, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, 16, 8)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(key)) + pinner.Pin(utf80) + slice := values + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4) + for index, element := range slice { + base := unsafe.Add(result, index*(2*4)) + utf81 := unsafe.Pointer(unsafe.StringData(element)) + pinner.Pin(utf81) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf81))) + + } + + wasm_import_srem(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(key)), uintptr(result), length, returnArea) + var result2 witTypes.Result[int64, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result2 = witTypes.Ok[int64, fermyon_spin_redis_types.Error](*(*int64)(unsafe.Add(unsafe.Pointer(returnArea), 8))) + case 1: + + result2 = witTypes.Err[int64, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 8))))) + default: + panic("unreachable") + } + result3 := result2 + return result3 + +} + +//go:wasmimport fermyon:spin/redis execute +func wasm_import_execute(arg0 uintptr, arg1 uint32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32, arg6 uintptr) + +func Execute(address string, command string, arguments []fermyon_spin_redis_types.RedisParameter) witTypes.Result[[]fermyon_spin_redis_types.RedisResult, fermyon_spin_redis_types.Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (3 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(address)) + pinner.Pin(utf8) + utf80 := unsafe.Pointer(unsafe.StringData(command)) + pinner.Pin(utf80) + slice := arguments + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result, index*(8+2*4)) + + switch element.Tag() { + case fermyon_spin_redis_types.RedisParameterInt64: + payload := element.Int64() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case fermyon_spin_redis_types.RedisParameterBinary: + payload := element.Binary() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + default: + panic("unreachable") + } + + } + + wasm_import_execute(uintptr(utf8), uint32(len(address)), uintptr(utf80), uint32(len(command)), uintptr(result), length, returnArea) + var result3 witTypes.Result[[]fermyon_spin_redis_types.RedisResult, fermyon_spin_redis_types.Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result2 := make([]fermyon_spin_redis_types.RedisResult, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(8+2*4)) + var variant fermyon_spin_redis_types.RedisResult + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = fermyon_spin_redis_types.MakeRedisResultNil() + + case 1: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_redis_types.MakeRedisResultStatus(value) + + case 2: + + variant = fermyon_spin_redis_types.MakeRedisResultInt64(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 3: + value1 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = fermyon_spin_redis_types.MakeRedisResultBinary(value1) + + default: + panic("unreachable") + } + + result2 = append(result2, variant) + } + + result3 = witTypes.Ok[[]fermyon_spin_redis_types.RedisResult, fermyon_spin_redis_types.Error](result2) + case 1: + + result3 = witTypes.Err[[]fermyon_spin_redis_types.RedisResult, fermyon_spin_redis_types.Error](uint8(uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))) + default: + panic("unreachable") + } + result4 := result3 + return result4 + +} diff --git a/redis_internal/fermyon_spin_redis_types/wit_bindings.go b/redis_internal/fermyon_spin_redis_types/wit_bindings.go new file mode 100644 index 00000000..74955910 --- /dev/null +++ b/redis_internal/fermyon_spin_redis_types/wit_bindings.go @@ -0,0 +1,129 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_redis_types + +import () + +const ( + ErrorSuccess uint8 = 0 + ErrorError uint8 = 1 +) + +// General purpose error. +type Error = uint8 + +// The message payload. +type Payload = []uint8 + +const ( + RedisParameterInt64 uint8 = 0 + RedisParameterBinary uint8 = 1 +) + +// A parameter type for the general-purpose `execute` function. +type RedisParameter struct { + tag uint8 + value any +} + +func (self RedisParameter) Tag() uint8 { + return self.tag +} + +func (self RedisParameter) Int64() int64 { + if self.tag != RedisParameterInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self RedisParameter) Binary() []uint8 { + if self.tag != RedisParameterBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeRedisParameterInt64(value int64) RedisParameter { + return RedisParameter{RedisParameterInt64, value} +} +func MakeRedisParameterBinary(value []uint8) RedisParameter { + return RedisParameter{RedisParameterBinary, value} +} + +const ( + RedisResultNil uint8 = 0 + RedisResultStatus uint8 = 1 + RedisResultInt64 uint8 = 2 + RedisResultBinary uint8 = 3 +) + +// A return type for the general-purpose `execute` function. +type RedisResult struct { + tag uint8 + value any +} + +func (self RedisResult) Tag() uint8 { + return self.tag +} + +func (self RedisResult) Status() string { + if self.tag != RedisResultStatus { + panic("tag mismatch") + } + return self.value.(string) +} +func (self RedisResult) Int64() int64 { + if self.tag != RedisResultInt64 { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self RedisResult) Binary() []uint8 { + if self.tag != RedisResultBinary { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeRedisResultNil() RedisResult { + return RedisResult{RedisResultNil, nil} +} +func MakeRedisResultStatus(value string) RedisResult { + return RedisResult{RedisResultStatus, value} +} +func MakeRedisResultInt64(value int64) RedisResult { + return RedisResult{RedisResultInt64, value} +} +func MakeRedisResultBinary(value []uint8) RedisResult { + return RedisResult{RedisResultBinary, value} +} diff --git a/redis_internal/fermyon_spin_sqlite/wit_bindings.go b/redis_internal/fermyon_spin_sqlite/wit_bindings.go new file mode 100644 index 00000000..ca14d91b --- /dev/null +++ b/redis_internal/fermyon_spin_sqlite/wit_bindings.go @@ -0,0 +1,364 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package fermyon_spin_sqlite + +import ( + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +// A handle to an open sqlite instance +type Connection = uint32 + +const ( + // The host does not recognize the database name requested. + ErrorNoSuchDatabase uint8 = 0 + // The requesting component does not have access to the specified database (which may or may not exist). + ErrorAccessDenied uint8 = 1 + // The provided connection is not valid + ErrorInvalidConnection uint8 = 2 + // The database has reached its capacity + ErrorDatabaseFull uint8 = 3 + // Some implementation-specific error has occurred (e.g. I/O) + ErrorIo uint8 = 4 +) + +// The set of errors which may be raised by functions in this interface +type Error struct { + tag uint8 + value any +} + +func (self Error) Tag() uint8 { + return self.tag +} + +func (self Error) Io() string { + if self.tag != ErrorIo { + panic("tag mismatch") + } + return self.value.(string) +} + +func MakeErrorNoSuchDatabase() Error { + return Error{ErrorNoSuchDatabase, nil} +} +func MakeErrorAccessDenied() Error { + return Error{ErrorAccessDenied, nil} +} +func MakeErrorInvalidConnection() Error { + return Error{ErrorInvalidConnection, nil} +} +func MakeErrorDatabaseFull() Error { + return Error{ErrorDatabaseFull, nil} +} +func MakeErrorIo(value string) Error { + return Error{ErrorIo, value} +} + +const ( + ValueInteger uint8 = 0 + ValueReal uint8 = 1 + ValueText uint8 = 2 + ValueBlob uint8 = 3 + ValueNull uint8 = 4 +) + +type Value struct { + tag uint8 + value any +} + +func (self Value) Tag() uint8 { + return self.tag +} + +func (self Value) Integer() int64 { + if self.tag != ValueInteger { + panic("tag mismatch") + } + return self.value.(int64) +} +func (self Value) Real() float64 { + if self.tag != ValueReal { + panic("tag mismatch") + } + return self.value.(float64) +} +func (self Value) Text() string { + if self.tag != ValueText { + panic("tag mismatch") + } + return self.value.(string) +} +func (self Value) Blob() []uint8 { + if self.tag != ValueBlob { + panic("tag mismatch") + } + return self.value.([]uint8) +} + +func MakeValueInteger(value int64) Value { + return Value{ValueInteger, value} +} +func MakeValueReal(value float64) Value { + return Value{ValueReal, value} +} +func MakeValueText(value string) Value { + return Value{ValueText, value} +} +func MakeValueBlob(value []uint8) Value { + return Value{ValueBlob, value} +} +func MakeValueNull() Value { + return Value{ValueNull, nil} +} + +// A set of values for each of the columns in a query-result +type RowResult struct { + Values []Value +} + +// A result of a query +type QueryResult struct { + // The names of the columns retrieved in the query + Columns []string + // the row results each containing the values for all the columns for a given row + Rows []RowResult +} + +//go:wasmimport fermyon:spin/sqlite open +func wasm_import_open(arg0 uintptr, arg1 uint32, arg2 uintptr) + +func Open(database string) witTypes.Result[uint32, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (4 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(database)) + pinner.Pin(utf8) + wasm_import_open(uintptr(utf8), uint32(len(database)), returnArea) + var result witTypes.Result[uint32, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + + result = witTypes.Ok[uint32, Error](uint32(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))) + case 1: + var variant Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant = MakeErrorNoSuchDatabase() + + case 1: + + variant = MakeErrorAccessDenied() + + case 2: + + variant = MakeErrorInvalidConnection() + + case 3: + + variant = MakeErrorDatabaseFull() + + case 4: + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant = MakeErrorIo(value) + + default: + panic("unreachable") + } + + result = witTypes.Err[uint32, Error](variant) + default: + panic("unreachable") + } + result0 := result + return result0 + +} + +//go:wasmimport fermyon:spin/sqlite execute +func wasm_import_execute(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr) + +func Execute(conn uint32, statement string, parameters []Value) witTypes.Result[QueryResult, Error] { + pinner := &runtime.Pinner{} + defer pinner.Unpin() + + returnArea := uintptr(witRuntime.Allocate(pinner, (5 * 4), 4)) + utf8 := unsafe.Pointer(unsafe.StringData(statement)) + pinner.Pin(utf8) + slice := parameters + length := uint32(len(slice)) + result := witRuntime.Allocate(pinner, uintptr(length*(8+2*4)), 8) + for index, element := range slice { + base := unsafe.Add(result, index*(8+2*4)) + + switch element.Tag() { + case ValueInteger: + payload := element.Integer() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0)) + *(*int64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ValueReal: + payload := element.Real() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1)) + *(*float64)(unsafe.Add(unsafe.Pointer(base), 8)) = payload + + case ValueText: + payload := element.Text() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2)) + utf80 := unsafe.Pointer(unsafe.StringData(payload)) + pinner.Pin(utf80) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(utf80))) + + case ValueBlob: + payload := element.Blob() + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3)) + data := unsafe.Pointer(unsafe.SliceData(payload)) + pinner.Pin(data) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4))) = uint32(uint32(len(payload))) + *(*uint32)(unsafe.Add(unsafe.Pointer(base), 8)) = uint32(uintptr(uintptr(data))) + + case ValueNull: + + *(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(4)) + + default: + panic("unreachable") + } + + } + + wasm_import_execute(int32(conn), uintptr(utf8), uint32(len(statement)), uintptr(result), length, returnArea) + var result8 witTypes.Result[QueryResult, Error] + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) { + case 0: + result1 := make([]string, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))), index*(2*4)) + value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + + result1 = append(result1, value) + } + + result5 := make([]RowResult, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (4 * 4)))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4))))), index*(2*4)) + result4 := make([]Value, 0, *(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))) + for index := 0; index < int(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4))); index++ { + base := unsafe.Add(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)))), index*(8+2*4)) + var variant Value + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0))) { + case 0: + + variant = MakeValueInteger(*(*int64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 1: + + variant = MakeValueReal(*(*float64)(unsafe.Add(unsafe.Pointer(base), 8))) + + case 2: + value2 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeValueText(value2) + + case 3: + value3 := unsafe.Slice((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(base), 8))))), *(*uint32)(unsafe.Add(unsafe.Pointer(base), (8 + 1*4)))) + + variant = MakeValueBlob(value3) + + case 4: + + variant = MakeValueNull() + + default: + panic("unreachable") + } + + result4 = append(result4, variant) + } + + result5 = append(result5, RowResult{result4}) + } + + result8 = witTypes.Ok[QueryResult, Error](QueryResult{result1, result5}) + case 1: + var variant7 Error + switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4))) { + case 0: + + variant7 = MakeErrorNoSuchDatabase() + + case 1: + + variant7 = MakeErrorAccessDenied() + + case 2: + + variant7 = MakeErrorInvalidConnection() + + case 3: + + variant7 = MakeErrorDatabaseFull() + + case 4: + value6 := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (2 * 4)))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), (3 * 4)))) + + variant7 = MakeErrorIo(value6) + + default: + panic("unreachable") + } + + result8 = witTypes.Err[QueryResult, Error](variant7) + default: + panic("unreachable") + } + result9 := result8 + return result9 + +} + +//go:wasmimport fermyon:spin/sqlite close +func wasm_import_close(arg0 int32) + +func Close(conn uint32) { + + wasm_import_close(int32(conn)) + +} diff --git a/redis_internal/wit_exports/wit_exports.go b/redis_internal/wit_exports/wit_exports.go new file mode 100644 index 00000000..f602e8b8 --- /dev/null +++ b/redis_internal/wit_exports/wit_exports.go @@ -0,0 +1,68 @@ +// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! +// +// This code was generated from the following packages: +// fermyon:spin +// wasi:io@0.2.0 +// wasi:clocks@0.2.0 +// wasi:random@0.2.0 +// wasi:filesystem@0.2.0 +// wasi:sockets@0.2.0 +// wasi:cli@0.2.0 +// wasi:http@0.2.0 +// wasi:io@0.2.0-rc-2023-10-18 +// wasi:clocks@0.2.0-rc-2023-10-18 +// wasi:random@0.2.0-rc-2023-10-18 +// wasi:filesystem@0.2.0-rc-2023-10-18 +// wasi:sockets@0.2.0-rc-2023-10-18 +// wasi:cli@0.2.0-rc-2023-10-18 +// wasi:http@0.2.0-rc-2023-10-18 +// fermyon:spin@2.0.0 +// wasi:keyvalue@0.2.0-draft2 +// spin:postgres@3.0.0 +// wasi:config@0.2.0-draft-2024-09-27 +// fermyon:spin@3.0.0 +// wasi:io@0.2.0-rc-2023-11-10 +// wasi:clocks@0.2.0-rc-2023-11-10 +// wasi:filesystem@0.2.0-rc-2023-11-10 +// wasi:sockets@0.2.0-rc-2023-11-10 +// wasi:random@0.2.0-rc-2023-11-10 +// wasi:cli@0.2.0-rc-2023-11-10 +// wasi:http@0.2.0-rc-2023-11-10 + +package wit_exports + +import ( + "github.com/spinframework/spin-go-sdk/v3/redis_internal/export_fermyon_spin_inbound_redis" + witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" + "runtime" + "unsafe" +) + +var staticPinner = runtime.Pinner{} +var exportReturnArea = uintptr(witRuntime.Allocate(&staticPinner, 2, 1)) +var syncExportPinner = runtime.Pinner{} + +//go:wasmexport fermyon:spin/inbound-redis#handle-message +func wasm_export_fermyon_spin_inbound_redis_handle_message(arg0 uintptr, arg1 uint32) uintptr { + + value := unsafe.Slice((*uint8)(unsafe.Pointer(arg0)), arg1) + witRuntime.Unpin() + result := export_fermyon_spin_inbound_redis.HandleMessage(value) + + switch result.Tag() { + case witTypes.ResultOk: + + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(0)) + + case witTypes.ResultErr: + payload := result.Err() + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 1)) = int8(int32(payload)) + + default: + panic("unreachable") + } + return exportReturnArea + +} diff --git a/sqlite/internals.go b/sqlite/internals.go deleted file mode 100644 index 441710f3..00000000 --- a/sqlite/internals.go +++ /dev/null @@ -1,169 +0,0 @@ -package sqlite - -// #include "sqlite.h" -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -func open(name string) (*conn, error) { - var dbname C.sqlite_string_t - var ret C.sqlite_expected_connection_error_t - - dbname = sqliteStr(name) - C.sqlite_open(&dbname, &ret) - - if ret.is_err { - return nil, toErr((*C.sqlite_error_t)(unsafe.Pointer(&ret.val))) - } - - sqliteConn := *((*C.sqlite_connection_t)(unsafe.Pointer(&ret.val))) - return &conn{_ptr: sqliteConn}, nil -} - -func (db *conn) close() { - C.sqlite_close(db._ptr) -} - -func (db *conn) execute(statement string, args []any) (*rows, error) { - var ret C.sqlite_expected_query_result_error_t - defer C.sqlite_expected_query_result_error_free(&ret) - - sqliteStatement := sqliteStr(statement) - params := toSqliteListValue(args) - - C.sqlite_execute(db._ptr, &sqliteStatement, ¶ms, &ret) - - if ret.is_err { - spinErr := (*C.sqlite_error_t)(unsafe.Pointer(&ret.val)) - return nil, toErr(spinErr) - } - - qr := (*C.sqlite_query_result_t)(unsafe.Pointer(&ret.val)) - - result := &rows{ - columns: fromSqliteListString(qr.columns), - rows: fromSqliteListRowResult(qr.rows), - len: int(qr.rows.len), - } - - return result, nil -} - -func fromSqliteListRowResult(list C.sqlite_list_row_result_t) [][]any { - listLen := int(list.len) - ret := make([][]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - row := *((*C.sqlite_list_value_t)(unsafe.Pointer(&slice[i]))) - ret[i] = fromSqliteListValue(row) - } - return ret - -} - -func fromSqliteListString(list C.sqlite_list_string_t) []string { - listLen := int(list.len) - ret := make([]string, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - str := slice[i] - ret[i] = C.GoStringN(str.ptr, C.int(str.len)) - } - return ret -} - -func fromSqliteListValue(list C.sqlite_list_value_t) []any { - listLen := int(list.len) - ret := make([]any, listLen) - slice := unsafe.Slice(list.ptr, listLen) - for i := 0; i < listLen; i++ { - ret[i] = fromSqliteValue(slice[i]) - } - return ret -} - -func toSqliteListValue(xv []any) C.sqlite_list_value_t { - if len(xv) == 0 { - return C.sqlite_list_value_t{} - } - cxv := make([]C.sqlite_value_t, len(xv)) - for i := 0; i < len(xv); i++ { - cxv[i] = toSqliteValue(xv[i]) - } - return C.sqlite_list_value_t{ptr: &cxv[0], len: C.size_t(len(cxv))} -} - -const ( - valueInt uint8 = iota - valueReal - valueText - valueBlob - valueNull -) - -func toSqliteValue(x any) C.sqlite_value_t { - var ret C.sqlite_value_t - switch v := x.(type) { - case int: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = int64(v) - ret.tag = valueInt - case int64: - *(*C.int64_t)(unsafe.Pointer(&ret.val)) = v - ret.tag = valueInt - case float64: - *(*C.double)(unsafe.Pointer(&ret.val)) = v - ret.tag = valueReal - case string: - str := sqliteStr(v) - *(*C.sqlite_string_t)(unsafe.Pointer(&ret.val)) = str - ret.tag = valueText - case []byte: - blob := C.sqlite_list_u8_t{ptr: &v[0], len: C.size_t(len(v))} - *(*C.sqlite_list_u8_t)(unsafe.Pointer(&ret.val)) = blob - ret.tag = valueBlob - default: - ret.tag = valueNull - } - return ret -} - -func fromSqliteValue(x C.sqlite_value_t) any { - switch x.tag { - case valueInt: - return int64(*(*C.int64_t)(unsafe.Pointer(&x.val))) - case valueReal: - return float64(*(*C.double)(unsafe.Pointer(&x.val))) - case valueBlob: - blob := (*C.sqlite_list_u8_t)(unsafe.Pointer(&x.val)) - return C.GoBytes(unsafe.Pointer(blob.ptr), C.int(blob.len)) - case valueText: - str := (*C.sqlite_string_t)(unsafe.Pointer(&x.val)) - return C.GoStringN(str.ptr, C.int(str.len)) - } - return nil -} - -func sqliteStr(x string) C.sqlite_string_t { - return C.sqlite_string_t{ptr: C.CString(x), len: C.size_t(len(x))} -} - -func toErr(err *C.sqlite_error_t) error { - switch err.tag { - case 0: - return errors.New("no such database") - case 1: - return errors.New("access denied") - case 2: - return errors.New("invalid connection") - case 3: - return errors.New("database full") - case 4: - str := (*C.sqlite_string_t)(unsafe.Pointer(&err.val)) - return errors.New(fmt.Sprintf("io error: %s", C.GoStringN(str.ptr, C.int(str.len)))) - default: - return errors.New(fmt.Sprintf("unrecognized error: %v", err.tag)) - } -} diff --git a/sqlite/internals_test.go b/sqlite/internals_test.go deleted file mode 100644 index 7e85bb05..00000000 --- a/sqlite/internals_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package sqlite - -import ( - "reflect" - "testing" -) - -func TestValue(t *testing.T) { - tests := []any{ - int64(1234), - 3.14, - "foo", - []byte("bar"), - nil, - } - - for _, tc := range tests { - got := fromSqliteValue(toSqliteValue(tc)) - if !reflect.DeepEqual(tc, got) { - t.Errorf("want %T(%#v), got %T(%#v)", tc, tc, got, got) - } - } -} - -func TestValueList(t *testing.T) { - tc := []any{ - int64(1234), - 3.14, - "foo", - []byte("bar"), - nil, - } - - got := fromSqliteListValue(toSqliteListValue(tc)) - if !reflect.DeepEqual(tc, got) { - t.Errorf("want %v, got %v", tc, got) - } -} diff --git a/sqlite/sqlite.c b/sqlite/sqlite.c deleted file mode 100644 index 62e08af8..00000000 --- a/sqlite/sqlite.c +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void sqlite_string_set(sqlite_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void sqlite_string_dup(sqlite_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void sqlite_string_free(sqlite_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void sqlite_error_free(sqlite_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 4: { - sqlite_string_free(&ptr->val.io); - break; - } - } -} -void sqlite_list_string_free(sqlite_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_string_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void sqlite_list_u8_free(sqlite_list_u8_t *ptr) { - canonical_abi_free(ptr->ptr, ptr->len * 1, 1); -} -void sqlite_value_free(sqlite_value_t *ptr) { - switch ((int32_t) ptr->tag) { - case 2: { - sqlite_string_free(&ptr->val.text); - break; - } - case 3: { - sqlite_list_u8_free(&ptr->val.blob); - break; - } - } -} -void sqlite_list_value_free(sqlite_list_value_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_value_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 16, 8); -} -void sqlite_row_result_free(sqlite_row_result_t *ptr) { - sqlite_list_value_free(&ptr->values); -} -void sqlite_list_row_result_free(sqlite_list_row_result_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - sqlite_row_result_free(&ptr->ptr[i]); - } - canonical_abi_free(ptr->ptr, ptr->len * 8, 4); -} -void sqlite_query_result_free(sqlite_query_result_t *ptr) { - sqlite_list_string_free(&ptr->columns); - sqlite_list_row_result_free(&ptr->rows); -} -void sqlite_expected_connection_error_free(sqlite_expected_connection_error_t *ptr) { - if (!ptr->is_err) { - } else { - sqlite_error_free(&ptr->val.err); - } -} -void sqlite_expected_query_result_error_free(sqlite_expected_query_result_error_t *ptr) { - if (!ptr->is_err) { - sqlite_query_result_free(&ptr->val.ok); - } else { - sqlite_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[20]; -__attribute__((import_module("sqlite"), import_name("open"))) -void __wasm_import_sqlite_open(int32_t, int32_t, int32_t); -void sqlite_open(sqlite_string_t *name, sqlite_expected_connection_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_sqlite_open((int32_t) (*name).ptr, (int32_t) (*name).len, ptr); - sqlite_expected_connection_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (uint32_t) (*((int32_t*) (ptr + 4))); - break; - } - case 1: { - expected.is_err = true; - sqlite_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - variant.val.io = (sqlite_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("sqlite"), import_name("execute"))) -void __wasm_import_sqlite_execute(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -void sqlite_execute(sqlite_connection_t conn, sqlite_string_t *statement, sqlite_list_value_t *parameters, sqlite_expected_query_result_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_sqlite_execute((int32_t) (conn), (int32_t) (*statement).ptr, (int32_t) (*statement).len, (int32_t) (*parameters).ptr, (int32_t) (*parameters).len, ptr); - sqlite_expected_query_result_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (sqlite_query_result_t) { - (sqlite_list_string_t) { (sqlite_string_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (sqlite_list_row_result_t) { (sqlite_row_result_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - case 1: { - expected.is_err = true; - sqlite_error_t variant4; - variant4.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant4.tag) { - case 0: { - break; - } - case 1: { - break; - } - case 2: { - break; - } - case 3: { - break; - } - case 4: { - variant4.val.io = (sqlite_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant4; - break; - } - }*ret0 = expected; -} -__attribute__((import_module("sqlite"), import_name("close"))) -void __wasm_import_sqlite_close(int32_t); -void sqlite_close(sqlite_connection_t conn) { - __wasm_import_sqlite_close((int32_t) (conn)); -} diff --git a/sqlite/sqlite.go b/sqlite/sqlite.go index 5f783baa..5b7ea938 100644 --- a/sqlite/sqlite.go +++ b/sqlite/sqlite.go @@ -7,7 +7,8 @@ import ( "errors" "io" - spindb "github.com/spinframework/spin-go-sdk/v2/internal/db" + spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" + sqlite "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_sqlite" ) // Open returns a new connection to the database. @@ -17,18 +18,17 @@ func Open(name string) *sql.DB { // conn represents a database connection. type conn struct { - _ptr uint32 + spinConn sqlite.Connection } // Close the connection. func (c *conn) Close() error { - c.close() return nil } // Prepare returns a prepared statement, bound to this connection. func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{c: c, query: query}, nil + return &stmt{conn: c, query: query}, nil } // Begin isn't supported. @@ -58,14 +58,12 @@ func (d *connector) Driver() driver.Driver { // Open returns a new connection to the database. func (d *connector) Open(name string) (driver.Conn, error) { - conn, err := open(name) - if err != nil { - return nil, err + results := sqlite.ConnectionOpen(name) + if results.IsErr() { + return nil, toError(results.Err()) } - - d.conn = conn - - return conn, err + d.conn = &conn{spinConn: *results.Ok()} + return d.conn, nil } // Close closes the connection to the database. @@ -132,7 +130,7 @@ func (r *rows) NextResultSet() error { } type stmt struct { - c *conn + conn *conn query string } @@ -152,22 +150,50 @@ func (s *stmt) NumInput() int { // Query executes a query that may return rows, such as a SELECT. func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] + sqliteParams := make([]sqlite.Value, len(args)) + for i, v := range args { + sqliteParams[i] = toSqliteValue(v) + } + + results := s.conn.spinConn.Execute(s.query, sqliteParams) + if results.IsErr() { + return nil, toError(results.Err()) + } + + rowLen := len(results.Ok().Rows) + allRows := make([][]any, rowLen) + for rowNum, row := range results.Ok().Rows { + allRows[rowNum] = toRow(row.Values) } - return s.c.execute(s.query, params) + + cols := results.Ok().Columns + colNames := make([]string, len(cols)) + for i, c := range cols { + colNames[i] = c + } + + rows := &rows{ + columns: colNames, + rows: allRows, + len: int(rowLen), + } + return rows, nil } // Exec executes a query that doesn't return rows, such as an INSERT or // UPDATE. func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - params := make([]any, len(args)) - for i := range args { - params[i] = args[i] + sqliteParams := make([]sqlite.Value, len(args)) + for i, v := range args { + sqliteParams[i] = toSqliteValue(v) + } + + queryResult := s.conn.spinConn.Execute(s.query, sqliteParams) + if queryResult.IsErr() { + return &result{}, toError(queryResult.Err()) } - _, err := s.c.execute(s.query, params) - return &result{}, err + + return &result{}, nil } // ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. @@ -184,3 +210,77 @@ func (r result) LastInsertId() (int64, error) { func (r result) RowsAffected() (int64, error) { return -1, errors.New("RowsAffected is unsupported by this driver") } + +func toSqliteValue(x any) sqlite.Value { + switch v := x.(type) { + case int8: + return sqlite.MakeValueInteger(int64(v)) + case int16: + return sqlite.MakeValueInteger(int64(v)) + case int32: + return sqlite.MakeValueInteger(int64(v)) + case int64: + return sqlite.MakeValueInteger(v) + case int: + return sqlite.MakeValueInteger(int64(v)) + case uint8: + return sqlite.MakeValueInteger(int64(v)) + case uint16: + return sqlite.MakeValueInteger(int64(v)) + case uint32: + return sqlite.MakeValueInteger(int64(v)) + case uint64: + return sqlite.MakeValueInteger(int64(v)) + case float32: + return sqlite.MakeValueReal(float64(v)) + case float64: + return sqlite.MakeValueReal(v) + case string: + return sqlite.MakeValueText(v) + case []byte: + return sqlite.MakeValueBlob(v) + case nil: + return sqlite.MakeValueNull() + default: + panic("unknown value type") + } +} + +func toError(err sqlite.Error) error { + switch err.Tag() { + case sqlite.ErrorNoSuchDatabase: + return errors.New("no such database") + case sqlite.ErrorAccessDenied: + return errors.New("access denied") + case sqlite.ErrorInvalidConnection: + return errors.New("invalid connection") + case sqlite.ErrorDatabaseFull: + return errors.New("database full") + case sqlite.ErrorIo: + return errors.New(err.Io()) + default: + panic("unreachable code") + } +} + +func toRow(row []sqlite.Value) []any { + result := make([]any, len(row)) + for i, v := range row { + switch v.Tag() { + case sqlite.ValueInteger: + result[i] = v.Integer() + case sqlite.ValueReal: + result[i] = v.Real() + case sqlite.ValueText: + result[i] = v.Text() + case sqlite.ValueBlob: + result[i] = v.Blob() + case sqlite.ValueNull: + result[i] = nil + default: + panic("unreachable code") + } + } + + return result +} diff --git a/sqlite/sqlite.h b/sqlite/sqlite.h deleted file mode 100644 index 7d2e0cd2..00000000 --- a/sqlite/sqlite.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef __BINDINGS_SQLITE_H -#define __BINDINGS_SQLITE_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } sqlite_string_t; - - void sqlite_string_set(sqlite_string_t *ret, const char *s); - void sqlite_string_dup(sqlite_string_t *ret, const char *s); - void sqlite_string_free(sqlite_string_t *ret); - typedef uint32_t sqlite_connection_t; - typedef struct { - uint8_t tag; - union { - sqlite_string_t io; - } val; - } sqlite_error_t; - #define SQLITE_ERROR_NO_SUCH_DATABASE 0 - #define SQLITE_ERROR_ACCESS_DENIED 1 - #define SQLITE_ERROR_INVALID_CONNECTION 2 - #define SQLITE_ERROR_DATABASE_FULL 3 - #define SQLITE_ERROR_IO 4 - void sqlite_error_free(sqlite_error_t *ptr); - typedef struct { - sqlite_string_t *ptr; - size_t len; - } sqlite_list_string_t; - void sqlite_list_string_free(sqlite_list_string_t *ptr); - typedef struct { - uint8_t *ptr; - size_t len; - } sqlite_list_u8_t; - void sqlite_list_u8_free(sqlite_list_u8_t *ptr); - typedef struct { - uint8_t tag; - union { - int64_t integer; - double real; - sqlite_string_t text; - sqlite_list_u8_t blob; - } val; - } sqlite_value_t; - #define SQLITE_VALUE_INTEGER 0 - #define SQLITE_VALUE_REAL 1 - #define SQLITE_VALUE_TEXT 2 - #define SQLITE_VALUE_BLOB 3 - #define SQLITE_VALUE_NULL 4 - void sqlite_value_free(sqlite_value_t *ptr); - typedef struct { - sqlite_value_t *ptr; - size_t len; - } sqlite_list_value_t; - void sqlite_list_value_free(sqlite_list_value_t *ptr); - typedef struct { - sqlite_list_value_t values; - } sqlite_row_result_t; - void sqlite_row_result_free(sqlite_row_result_t *ptr); - typedef struct { - sqlite_row_result_t *ptr; - size_t len; - } sqlite_list_row_result_t; - void sqlite_list_row_result_free(sqlite_list_row_result_t *ptr); - typedef struct { - sqlite_list_string_t columns; - sqlite_list_row_result_t rows; - } sqlite_query_result_t; - void sqlite_query_result_free(sqlite_query_result_t *ptr); - typedef struct { - bool is_err; - union { - sqlite_connection_t ok; - sqlite_error_t err; - } val; - } sqlite_expected_connection_error_t; - void sqlite_expected_connection_error_free(sqlite_expected_connection_error_t *ptr); - typedef struct { - bool is_err; - union { - sqlite_query_result_t ok; - sqlite_error_t err; - } val; - } sqlite_expected_query_result_error_t; - void sqlite_expected_query_result_error_free(sqlite_expected_query_result_error_t *ptr); - void sqlite_open(sqlite_string_t *name, sqlite_expected_connection_error_t *ret0); - void sqlite_execute(sqlite_connection_t conn, sqlite_string_t *statement, sqlite_list_value_t *parameters, sqlite_expected_query_result_error_t *ret0); - void sqlite_close(sqlite_connection_t conn); - #ifdef __cplusplus -} -#endif -#endif diff --git a/v3/README.md b/v3/README.md deleted file mode 100644 index 1bd0c4d9..00000000 --- a/v3/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Overview -The `wasip2` implementation of the Spinframework Go SDK. - -## Generating the WIT bindings -Whenever WIT files are changed/added to the `v3/wit` directory, the bindings in `v3/wit_component` need to be regenerated. - -### Prerequisites -- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version - -### Run -```sh -cd v3 - -# Delete all non-handwritten code -find $(pwd)/internal/ \ - -mindepth 1 \ - -maxdepth 1 \ - -type d \ - ! -name 'db' \ - ! -name 'export_wasi_http_0_2_0_incoming_handler' \ - -exec rm -rf {} + - -componentize-go -w http-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal -``` diff --git a/v3/examples/http/README.md b/v3/examples/http/README.md deleted file mode 100644 index 72ecc137..00000000 --- a/v3/examples/http/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Requirements -- [**go**](https://go.dev/dl/) - v1.25+ -- [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version - -# Usage -Build and run the Spin app: -```sh -spin up --build -``` - -In another terminal window, you can interact with the Spin app: -```sh -curl localhost:3000/hello -``` diff --git a/v3/examples/http/go.mod b/v3/examples/http/go.mod deleted file mode 100644 index 915928c9..00000000 --- a/v3/examples/http/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/http - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/http/main.go b/v3/examples/http/main.go deleted file mode 100644 index d3f99656..00000000 --- a/v3/examples/http/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v3/http" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - w.Header().Set("foo", "bar") - - w.WriteHeader(http.StatusOK) - fmt.Fprintln(w, "== RESPONSE ==") - fmt.Fprintln(w, "Hello spinframework!") - fmt.Fprintln(w, "Hello again spinframework!") - }) -} - -func main() {} diff --git a/v3/examples/kv/README.md b/v3/examples/kv/README.md deleted file mode 100644 index 40751739..00000000 --- a/v3/examples/kv/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Requirements -- [**go**](https://go.dev/dl/) - v1.25+ -- [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version - -# Usage -Build and run the Spin app: -```sh -spin up --build -``` - -In another terminal window, you can interact with the Spin app: -```sh -curl localhost:3000/hello -``` - -You should receive the following output: -``` -["foo"] -``` diff --git a/v3/examples/kv/go.mod b/v3/examples/kv/go.mod deleted file mode 100644 index 13a16a52..00000000 --- a/v3/examples/kv/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/kv - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/kv/spin.toml b/v3/examples/kv/spin.toml deleted file mode 100644 index 7a9c0ea6..00000000 --- a/v3/examples/kv/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Rajat Jindal "] -description = "A simple Spin application written in Go." -name = "hello-kv" -version = "1.0.0" - -[[trigger.http]] -route = "/hello" -component = "hello" - -[component.hello] -source = "main.wasm" -key_value_stores = ["default"] -[component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" diff --git a/v3/examples/llm/go.mod b/v3/examples/llm/go.mod deleted file mode 100644 index c6ea1b9c..00000000 --- a/v3/examples/llm/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/llm - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/llm/main.go b/v3/examples/llm/main.go deleted file mode 100644 index c0712980..00000000 --- a/v3/examples/llm/main.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v3/http" - "github.com/spinframework/spin-go-sdk/v3/llm" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - result, err := llm.Infer("llama2-chat", "Tell me a joke", nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Printf("Prompt tokens: %d\n", result.Usage.PromptTokenCount) - fmt.Printf("Generated tokens: %d\n", result.Usage.GeneratedTokenCount) - fmt.Fprint(w, result.Text) - fmt.Fprintf(w, "\n\n") - - embeddings, err := llm.GenerateEmbeddings("all-minilm-l6-v2", []string{"Hello world"}) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Printf("%d\n", len(embeddings.Embeddings[0])) - fmt.Printf("Prompt Tokens: %d\n", embeddings.Usage.PromptTokenCount) - - }) -} - -func main() {} diff --git a/v3/examples/llm/spin.toml b/v3/examples/llm/spin.toml deleted file mode 100644 index 5f950978..00000000 --- a/v3/examples/llm/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Fermyon Engineering "] -description = "Simple example using the llm sdk." -name = "llm-example" -version = "0.1.0" - -[[trigger.http]] -route = "/..." -component = "llm" - -[component.llm] -source = "main.wasm" -allowed_outbound_hosts = [] -ai_models = ["llama2-chat", "all-minilm-l6-v2"] -[component.llm.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" -watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/mqtt-outbound/.gitignore b/v3/examples/mqtt-outbound/.gitignore deleted file mode 100644 index b5650104..00000000 --- a/v3/examples/mqtt-outbound/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.wasm -.spin/ diff --git a/v3/examples/mqtt-outbound/go.mod b/v3/examples/mqtt-outbound/go.mod deleted file mode 100644 index a552147e..00000000 --- a/v3/examples/mqtt-outbound/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/mqtt-outbound - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/mysql-outbound/.gitignore b/v3/examples/mysql-outbound/.gitignore deleted file mode 100644 index b5650104..00000000 --- a/v3/examples/mysql-outbound/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.wasm -.spin/ diff --git a/v3/examples/mysql-outbound/go.mod b/v3/examples/mysql-outbound/go.mod deleted file mode 100644 index daad4959..00000000 --- a/v3/examples/mysql-outbound/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/mysql-outbound - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/mysql-outbound/go.sum b/v3/examples/mysql-outbound/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/examples/mysql-outbound/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/examples/mysql-outbound/main.go b/v3/examples/mysql-outbound/main.go deleted file mode 100644 index f20e9091..00000000 --- a/v3/examples/mysql-outbound/main.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "os" - - spinhttp "github.com/spinframework/spin-go-sdk/v3/http" - "github.com/spinframework/spin-go-sdk/v3/mysql" -) - -type Pet struct { - ID int64 - Name string - Prey *string // nullable field must be a pointer - IsFinicky bool -} - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - - // addr is the environment variable set in `spin.toml` that points to the - // address of the Mysql server. - addr := os.Getenv("DB_URL") - - db := mysql.Open(addr) - defer db.Close() - - if _, err := db.Query("REPLACE INTO pets VALUES (?, 'Maya', ?, ?);", 4, "bananas", true); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if _, err := db.Exec("INSERT INTO pets VALUES (?, ?, ?, ?)", 5, "Copper", "Foxes", false); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - rows, err := db.Query("SELECT * FROM pets") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - var pets []*Pet - for rows.Next() { - var pet Pet - if err := rows.Scan(&pet.ID, &pet.Name, &pet.Prey, &pet.IsFinicky); err != nil { - fmt.Println(err) - } - pets = append(pets, &pet) - } - json.NewEncoder(w).Encode(pets) - }) -} - -func main() {} diff --git a/v3/examples/mysql-outbound/spin.toml b/v3/examples/mysql-outbound/spin.toml deleted file mode 100644 index fb3b7954..00000000 --- a/v3/examples/mysql-outbound/spin.toml +++ /dev/null @@ -1,19 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "go-mysql-outbound-example" -version = "0.1.0" -authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] -description = "Using Spin with MySQL" - -[[trigger.http]] -route = "/..." -component = "mysql" - -[component.mysql] -environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } -source = "main.wasm" -allowed_outbound_hosts = ["mysql://127.0.0.1"] -[component.mysql.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" -watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/redis-outbound/README.md b/v3/examples/redis-outbound/README.md deleted file mode 100644 index 17dd7746..00000000 --- a/v3/examples/redis-outbound/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Requirements -- [**go**](https://go.dev/dl/) - v1.25+ -- [**spin**](https://github.com/spinframework/spin) - Latest version -- [**docker**](https://docs.docker.com/get-started/get-docker/) - Latest version -- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version - -# Usage -In one terminal window, you'll run a Redis container: -```sh -docker run -p 6379:6379 redis:8.2 -``` - -In another terminal, you'll run your Spin app: -```sh -spin up --build -``` - -In yet another terminal, you'll interact with the Spin app: -```sh -curl localhost:3000 -``` - -You should see the following output: -``` -mykey value was: myvalue -spin-go-incr value: 1 -deleted keys num: 2 -``` diff --git a/v3/examples/redis-outbound/go.mod b/v3/examples/redis-outbound/go.mod deleted file mode 100644 index 626def1c..00000000 --- a/v3/examples/redis-outbound/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/redis-outbound - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/redis-outbound/go.sum b/v3/examples/redis-outbound/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/examples/redis-outbound/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/examples/redis-outbound/main.go b/v3/examples/redis-outbound/main.go deleted file mode 100644 index 3c0a431b..00000000 --- a/v3/examples/redis-outbound/main.go +++ /dev/null @@ -1,155 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "os" - "reflect" - "sort" - "strconv" - - spin_http "github.com/spinframework/spin-go-sdk/v3/http" - "github.com/spinframework/spin-go-sdk/v3/redis" -) - -func init() { - - // handler for the http trigger - spin_http.Handle(func(w http.ResponseWriter, _ *http.Request) { - - // addr is the environment variable set in `spin.toml` that points to the - // address of the Redis server. - addr := os.Getenv("REDIS_ADDRESS") - - // channel is the environment variable set in `spin.toml` that specifies - // the Redis channel that the component will publish to. - channel := os.Getenv("REDIS_CHANNEL") - - // payload is the data publish to the redis channel. - payload := []byte(`Hello redis from tinygo!`) - - rdb, err := redis.NewClient(addr) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if err := rdb.Publish(channel, payload); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // set redis `mykey` = `myvalue` - if err := rdb.Set("mykey", []byte("myvalue")); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // get redis payload for `mykey` - if payload, err := rdb.Get("mykey"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else { - w.Write([]byte("mykey value was: ")) - w.Write(payload) - w.Write([]byte("\n")) - } - - // incr `spin-go-incr` by 1 - if payload, err := rdb.Incr("spin-go-incr"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else { - w.Write([]byte("spin-go-incr value: ")) - w.Write([]byte(strconv.FormatInt(payload, 10))) - w.Write([]byte("\n")) - } - - // delete `spin-go-incr` and `mykey` - if payload, err := rdb.Del("spin-go-incr", "mykey", "non-existing-key"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } else { - w.Write([]byte("deleted keys num: ")) - w.Write([]byte(strconv.FormatInt(int64(payload), 10))) - w.Write([]byte("\n")) - } - - if _, err := rdb.Sadd("myset", "foo", "bar"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - { - expected := []string{"bar", "foo"} - payload, err := rdb.Smembers("myset") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - sort.Strings(payload) - if !reflect.DeepEqual(payload, expected) { - http.Error( - w, - fmt.Sprintf( - "unexpected SMEMBERS result: expected %v, got %v", - expected, - payload, - ), - http.StatusInternalServerError, - ) - return - } - } - - if _, err := rdb.Srem("myset", "bar"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - { - expected := []string{"foo"} - if payload, err := rdb.Smembers("myset"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else if !reflect.DeepEqual(payload, expected) { - http.Error( - w, - fmt.Sprintf( - "unexpected SMEMBERS result: expected %v, got %v", - expected, - payload, - ), - http.StatusInternalServerError, - ) - return - } - } - - if _, err := rdb.Execute("set", "message", "hello"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if _, err := rdb.Execute("append", "message", " world"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if payload, err := rdb.Execute("get", "message"); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else if !reflect.DeepEqual( - payload, - []*redis.Result{{ - Kind: redis.ResultKindBinary, - Val: []byte("hello world"), - }}) { - - http.Error(w, "unexpected GET result", http.StatusInternalServerError) - fmt.Println() - return - } - }) -} - -func main() {} diff --git a/v3/examples/redis-outbound/spin.toml b/v3/examples/redis-outbound/spin.toml deleted file mode 100644 index 281a3cab..00000000 --- a/v3/examples/redis-outbound/spin.toml +++ /dev/null @@ -1,20 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "go-redis-outbound-example" -version = "0.1.0" -authors = ["Andrew Steurer <94206073+asteurer@users.noreply.github.com>"] -description = "Using Spin with Redis" - -[[trigger.http]] -route = "/" -component = "redis-outbound" - -[component.redis-outbound] -source = "main.wasm" -environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messages" } -allowed_outbound_hosts = ["redis://localhost:6379"] - -[component.redis-outbound.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" -watch = ["**/*.go", "go.mod"] diff --git a/v3/examples/variables/README.md b/v3/examples/variables/README.md deleted file mode 100644 index ca75f048..00000000 --- a/v3/examples/variables/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Requirements -- [**go**](https://go.dev/dl/) - v1.25+ -- [**spin**](https://github.com/spinframework/spin) - Latest version -- [**componentize-go**](https://github.com/bytecodealliance/componentize-go) - Latest version - -# Usage -Build and run the Spin app: -```sh -spin up --build -``` - -In another terminal window, you can interact with the Spin app: -```sh -curl localhost:3000/hello -``` - -You should receive the following output: -``` -message: I'm a teapot -``` diff --git a/v3/examples/variables/go.mod b/v3/examples/variables/go.mod deleted file mode 100644 index b2e036d5..00000000 --- a/v3/examples/variables/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/variables - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/examples/variables/go.sum b/v3/examples/variables/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/examples/variables/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/examples/variables/main.go b/v3/examples/variables/main.go deleted file mode 100644 index 4791c8b1..00000000 --- a/v3/examples/variables/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v3/http" - "github.com/spinframework/spin-go-sdk/v3/variables" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - - // Get variable value `message` defined in spin.toml. - val, err := variables.Get("message") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Fprintln(w, "message: ", val) - }) -} - -func main() {} diff --git a/v3/go.mod b/v3/go.mod deleted file mode 100644 index 62e47277..00000000 --- a/v3/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3 - -go 1.25.5 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 - github.com/julienschmidt/httprouter v1.3.0 -) - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/go.sum b/v3/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/http/http.go b/v3/http/http.go deleted file mode 100644 index dc7f5b49..00000000 --- a/v3/http/http.go +++ /dev/null @@ -1,99 +0,0 @@ -// 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" - - "github.com/julienschmidt/httprouter" - incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" - types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" - _ "github.com/spinframework/spin-go-sdk/v3/internal/wit_exports" - "github.com/spinframework/spin-go-sdk/v3/wit" -) - -// 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/v3/http/testdata/http/go.mod b/v3/http/testdata/http/go.mod deleted file mode 100644 index 29ed955f..00000000 --- a/v3/http/testdata/http/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/http/testdata/http - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/http/testdata/http/go.sum b/v3/http/testdata/http/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/http/testdata/http/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/http/testdata/http/spin.toml b/v3/http/testdata/http/spin.toml deleted file mode 100644 index ece1e99f..00000000 --- a/v3/http/testdata/http/spin.toml +++ /dev/null @@ -1,17 +0,0 @@ -spin_manifest_version = 2 - -[application] -authors = ["Rajat Jindal "] -description = "A simple Spin application written in Go." -name = "hello-example" -version = "1.0.0" - -[[trigger.http]] -route = "/hello" -component = "hello" - -[component.hello] -source = "main.wasm" -[component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" - diff --git a/v3/integration_test.go b/v3/integration_test.go deleted file mode 100644 index 71c691e9..00000000 --- a/v3/integration_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package http - -import ( - "bytes" - "context" - "fmt" - "io" - "net" - "net/http" - "os" - "os/exec" - "path/filepath" - "testing" - "time" -) - -const spinBinary = "spin" - -func retryGet(t *testing.T, url string) *http.Response { - t.Helper() - - const maxTries = 600 // (10min) - for i := 1; i < maxTries; i++ { - // Catch call to `Fail` in other goroutine - if t.Failed() { - t.FailNow() - } - if res, err := http.Get(url); err != nil { - t.Log(err) - } else { - return res - } - time.Sleep(1 * time.Second) - } - t.Fatal("Get request timeout: ", url) - return nil -} - -type testSpin struct { - cancel func() - url string - cmd *exec.Cmd -} - -func startSpin(t *testing.T, dir string, extraArgs ...string) *testSpin { - buildApp(t, dir) - - url := getFreePort(t) - - // long timeout because... ci - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - - cmd := exec.CommandContext(ctx, spinBinary, append([]string{"up", "--listen", url}, extraArgs...)...) - cmd.Dir = dir - stderr := new(bytes.Buffer) - cmd.Stderr = stderr - if err := cmd.Start(); err != nil { - t.Log(stderr.String()) - t.Fatal(err) - } - - go func() { - _ = cmd.Wait() - if ctx.Err() == nil { - t.Log("spin exited before the test finished:", cmd.ProcessState) - t.Log("stderr:\n", stderr.String()) - t.Fail() - } - }() - - return &testSpin{ - cancel: cancel, - url: fmt.Sprintf("http://%s", url), - cmd: cmd, - } -} - -func buildApp(t *testing.T, dir string) { - t.Helper() - - t.Log("building application:", dir) - - cmd := exec.Command(spinBinary, "build") - cmd.Dir = dir - - stderr := new(bytes.Buffer) - cmd.Stderr = stderr - if err := cmd.Run(); err != nil { - t.Log(stderr.String()) - t.Errorf("Failed to build %q, %v", dir, err) - } -} - -func TestHTTPTrigger(t *testing.T) { - spin := startSpin(t, "http/testdata/http") - defer spin.cancel() - - resp := retryGet(t, spin.url+"/hello") - spin.cancel() - if resp.Body == nil { - t.Fatal("body is nil") - } - t.Log(resp.Status) - b, err := io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - - // assert response body - want := "== RESPONSE ==\nHello spinframework!\nHello again spinframework!\n" - got := string(b) - if want != got { - t.Fatalf("body is not equal: want = %q got = %q", want, got) - } - - // assert response header - if resp.Header.Get("foo") != "bar" { - t.Fatal("header 'foo' was not set") - } -} - -func TestKeyValue(t *testing.T) { - spin := startSpin(t, "kv/testdata/key-value") - defer spin.cancel() - - resp := retryGet(t, spin.url+"/hello") - spin.cancel() - if resp.Body == nil { - t.Fatal("body is nil") - } - t.Log(resp.Status) - b, err := io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - - // assert response body - want := "[\"foo\"]\n" - got := string(b) - if want != got { - t.Fatalf("body is not equal: want = %q got = %q", want, got) - } -} - -func TestVariables(t *testing.T) { - spin := startSpin(t, "variables/testdata/variables") - defer spin.cancel() - - resp := retryGet(t, spin.url) - spin.cancel() - if resp.Body == nil { - t.Fatal("body is nil") - } - t.Log(resp.Status) - b, err := io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - t.Fatal(err) - } - - // assert response body - want := "message: I'm a teapot\n" - got := string(b) - if want != got { - t.Fatalf("body is not equal: want = %q got = %q", want, got) - } -} - -// TestBuildExamples ensures that the tinygo examples will build successfully. -func TestBuildExamples(t *testing.T) { - examples, err := os.ReadDir("examples") - if err != nil { - t.Fatal(err) - } - for _, example := range examples { - t.Run(example.Name(), func(t *testing.T) { - t.Parallel() - buildApp(t, filepath.Join("examples", example.Name())) - }) - } -} - -func getFreePort(t *testing.T) string { - t.Helper() - - a, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0") - if err != nil { - t.Fatal("failed to get free port: ", err) - } - - l, err := net.ListenTCP("tcp", a) - if err != nil { - t.Fatal("failed to get free port: ", err) - } - l.Close() - return l.Addr().String() -} diff --git a/v3/internal/db/driver.go b/v3/internal/db/driver.go deleted file mode 100644 index e1c99051..00000000 --- a/v3/internal/db/driver.go +++ /dev/null @@ -1,15 +0,0 @@ -package db - -import "database/sql/driver" - -// GlobalParameterConverter is a global valueConverter instance to convert parameters. -var GlobalParameterConverter = &valueConverter{} - -var _ driver.ValueConverter = (*valueConverter)(nil) - -// valueConverter is a no-op value converter. -type valueConverter struct{} - -func (c *valueConverter) ConvertValue(v any) (driver.Value, error) { - return driver.Value(v), nil -} diff --git a/v3/kv/kv.go b/v3/kv/kv.go deleted file mode 100644 index e45af711..00000000 --- a/v3/kv/kv.go +++ /dev/null @@ -1,100 +0,0 @@ -package kv - -import ( - "fmt" - - keyvalue "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_key_value" -) - -type Store struct { - store *keyvalue.Store -} - -// Open the store with the label. -func Open(label string) (*Store, error) { - result := keyvalue.StoreOpen(label) - if result.IsErr() { - return nil, errorVariantToError(result.Err()) - } - - return &Store{ - store: result.Ok(), - }, nil -} - -// Open the default store. -// -// This is equivalent to `kv.Open("default")`. -func OpenDefault() (*Store, error) { - return Open("default") -} - -// Set the key/value pair in store -func (s *Store) Set(key string, value []byte) error { - result := s.store.Set(key, value) - if result.IsErr() { - return errorVariantToError(result.Err()) - } - - return nil -} - -// Get the value of provided key from the store -func (s *Store) Get(key string) ([]byte, error) { - result := s.store.Get(key) - if result.IsErr() { - return nil, errorVariantToError(result.Err()) - } - - value := result.Ok() - if value.IsNone() { - return []byte(""), nil - } - - return value.Some(), nil -} - -// Delete the given key/value from the store -func (s *Store) Delete(key string) error { - result := s.store.Delete(key) - if result.IsErr() { - return errorVariantToError(result.Err()) - } - - return nil -} - -// Exists check if a given key exist in the store -func (s *Store) Exists(key string) (bool, error) { - result := s.store.Exists(key) - if result.IsErr() { - return false, errorVariantToError(result.Err()) - } - - return result.Ok(), nil -} - -// GetKets returns all the keys from the store -func (s *Store) GetKeys() ([]string, error) { - result := s.store.GetKeys() - if result.IsErr() { - return nil, errorVariantToError(result.Err()) - } - - return result.Ok(), nil -} - -func errorVariantToError(code keyvalue.Error) error { - switch code.Tag() { - case keyvalue.ErrorAccessDenied: - return fmt.Errorf("access denied") - case keyvalue.ErrorNoSuchStore: - return fmt.Errorf("no such store") - case keyvalue.ErrorStoreTableFull: - return fmt.Errorf("store table full") - case keyvalue.ErrorOther: - return fmt.Errorf("%v", code.Other()) - default: - return fmt.Errorf("no error provided by host implementation") - } -} diff --git a/v3/kv/testdata/key-value/go.mod b/v3/kv/testdata/key-value/go.mod deleted file mode 100644 index 729b6996..00000000 --- a/v3/kv/testdata/key-value/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/http/testdata/kv - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/kv/testdata/key-value/go.sum b/v3/kv/testdata/key-value/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/kv/testdata/key-value/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/kv/testdata/key-value/main.go b/v3/kv/testdata/key-value/main.go deleted file mode 100644 index 4cfc8be5..00000000 --- a/v3/kv/testdata/key-value/main.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - - spinhttp "github.com/spinframework/spin-go-sdk/v3/http" - "github.com/spinframework/spin-go-sdk/v3/kv" -) - -func init() { - spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { - store, err := kv.OpenDefault() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - err = store.Set("foo", []byte("bar")) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - value, err := store.Get("foo") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - if string(value) != "bar" { - http.Error(w, fmt.Sprintf("expected: %q, got: %q", "bar", value), http.StatusInternalServerError) - return - } - - keys, err := store.GetKeys() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - - w.WriteHeader(http.StatusOK) - _ = json.NewEncoder(w).Encode(keys) - }) -} - -func main() {} diff --git a/v3/llm/llm.go b/v3/llm/llm.go deleted file mode 100644 index 59ad7423..00000000 --- a/v3/llm/llm.go +++ /dev/null @@ -1,137 +0,0 @@ -package llm - -import ( - "fmt" - - "github.com/bytecodealliance/wit-bindgen/wit_types" - llm "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_llm" -) - -// The model use for inferencing -const ( - Llama2Chat InferencingModel = "llama2-chat" - CodellamaInstruct InferencingModel = "codellama-instruct" -) - -type InferencingParams struct { - // The maximum tokens that should be inferred. - // - // Note: the backing implementation may return less tokens. - MaxTokens uint32 `json:"max-tokens"` - - // The amount the model should avoid repeating tokens. - RepeatPenalty float32 `json:"repeat-penalty"` - - // The number of tokens the model should apply the repeat penalty to. - RepeatPenaltyLastNTokenCount uint32 `json:"repeat-penalty-last-n-token-count"` - - // The randomness with which the next token is selected. - Temperature float32 `json:"temperature"` - - // The number of possible next tokens the model will choose from. - TopK uint32 `json:"top-k"` - - // The probability total of next tokens the model will choose from. - TopP float32 `json:"top-p"` -} - -type InferencingResult struct { - // The text generated by the model - // TODO: this should be a stream - Text string `json:"text"` - - // Usage information about the inferencing request - Usage InferencingUsage `json:"usage"` -} - -// Usage information related to the inferencing result -type InferencingUsage struct { - // TODO: It's not clear whether this is important. - // _ cm.HostLayout `json:"-"` - - // Number of tokens in the prompt - PromptTokenCount uint32 `json:"prompt-token-count"` - - // Number of tokens generated by the inferencing operation - GeneratedTokenCount uint32 `json:"generated-token-count"` -} - -// A Large Language Model. -type InferencingModel string - -// The model used for generating embeddings -type EmbeddingModel string - -type EmbeddingsResult struct { - // Embeddings are the embeddings generated by the request. - Embeddings [][]float32 - // Usage is usage related to an embeddings generation request. - Usage *EmbeddingsUsage -} - -type EmbeddingsUsage struct { - // PromptTokenCount is number of tokens in the prompt. - PromptTokenCount int -} - -// Infer performs inferencing using the provided model and prompt with the -// given optional parameters. -func Infer(model string, prompt string, params *InferencingParams) (InferencingResult, error) { - iparams := wit_types.None[llm.InferencingParams]() - if params != nil { - iparams = wit_types.Some(llm.InferencingParams{ - MaxTokens: params.MaxTokens, - RepeatPenalty: params.RepeatPenalty, - RepeatPenaltyLastNTokenCount: params.RepeatPenaltyLastNTokenCount, - Temperature: params.Temperature, - TopK: params.TopK, - TopP: params.TopP, - }) - } - - result := llm.Infer(llm.InferencingModel(model), prompt, iparams) - if result.IsErr() { - return InferencingResult{}, errorVariantToError(result.Err()) - } - - return InferencingResult{ - Text: result.Ok().Text, - Usage: InferencingUsage{ - PromptTokenCount: result.Ok().Usage.PromptTokenCount, - GeneratedTokenCount: result.Ok().Usage.GeneratedTokenCount, - }, - }, nil -} - -// GenerateEmbeddings generates the embeddings for the supplied list of text. -func GenerateEmbeddings(model EmbeddingModel, text []string) (*EmbeddingsResult, error) { - result := llm.GenerateEmbeddings(llm.EmbeddingModel(model), text) - if result.IsErr() { - return &EmbeddingsResult{}, errorVariantToError(result.Err()) - } - - embeddings := [][]float32{} - for _, l := range result.Ok().Embeddings { - embeddings = append(embeddings, l) - } - - return &EmbeddingsResult{ - Embeddings: embeddings, - Usage: &EmbeddingsUsage{ - PromptTokenCount: int(result.Ok().Usage.PromptTokenCount), - }, - }, nil -} - -func errorVariantToError(err llm.Error) error { - switch err.Tag() { - case llm.ErrorModelNotSupported: - return fmt.Errorf("model not supported") - case llm.ErrorRuntimeError: - return fmt.Errorf("runtime error %s", err.RuntimeError()) - case llm.ErrorInvalidInput: - return fmt.Errorf("invalid input %s", err.InvalidInput()) - default: - return fmt.Errorf("no error provided by host implementation") - } -} diff --git a/v3/mysql/mysql.go b/v3/mysql/mysql.go deleted file mode 100644 index d3a65e02..00000000 --- a/v3/mysql/mysql.go +++ /dev/null @@ -1,337 +0,0 @@ -package mysql - -import ( - "context" - "database/sql" - "database/sql/driver" - "errors" - "io" - "reflect" - - spindb "github.com/spinframework/spin-go-sdk/v3/internal/db" - mysql "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_mysql" - rdbmstypes "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_rdbms_types" -) - -// Open returns a new connection to the database. -func Open(name string) *sql.DB { - return sql.OpenDB(&connector{name: name}) -} - -type conn struct { - spinConn mysql.Connection -} - -func (c *conn) Close() error { - return nil -} - -func (c *conn) Prepare(query string) (driver.Stmt, error) { - return &stmt{conn: c, query: query}, nil -} - -func (c *conn) Begin() (driver.Tx, error) { - return nil, errors.New("transactions are unsupported by this driver") -} - -type connector struct { - conn *conn - name string -} - -func (d *connector) Connect(_ context.Context) (driver.Conn, error) { - if d.conn != nil { - return d.conn, nil - } - return d.Open(d.name) -} - -func (d *connector) Driver() driver.Driver { - return d -} - -func (d *connector) Open(name string) (driver.Conn, error) { - results := mysql.ConnectionOpen(name) - if results.IsErr() { - return nil, toError(results.Err()) - } - d.conn = &conn{spinConn: *results.Ok()} - return d.conn, nil -} - -func (d *connector) Close() error { - if d.conn != nil { - d.conn.Close() - } - return nil -} - -type rows struct { - columns []string - columnType []uint8 - pos int - len int - rows [][]any - closed bool -} - -var _ driver.Rows = (*rows)(nil) -var _ driver.RowsColumnTypeScanType = (*rows)(nil) -var _ driver.RowsNextResultSet = (*rows)(nil) - -// Columns return column names. -func (r *rows) Columns() []string { - return r.columns -} - -// Close closes the rows iterator. -func (r *rows) Close() error { - r.rows = nil - r.pos = 0 - r.len = 0 - r.closed = true - return nil -} - -// Next moves the cursor to the next row. -func (r *rows) Next(dest []driver.Value) error { - if !r.HasNextResultSet() { - return io.EOF - } - for i := 0; i != len(r.columns); i++ { - dest[i] = driver.Value(r.rows[r.pos][i]) - } - r.pos++ - return nil -} - -// HasNextResultSet is called at the end of the current result set and -// reports whether there is another result set after the current one. -func (r *rows) HasNextResultSet() bool { - return r.pos < r.len -} - -// NextResultSet advances the driver to the next result set even -// if there are remaining rows in the current result set. -// -// NextResultSet should return io.EOF when there are no more result sets. -func (r *rows) NextResultSet() error { - if r.HasNextResultSet() { - r.pos++ - return nil - } - return io.EOF // Per interface spec. -} - -// ColumnTypeScanType return the value type that can be used to scan types into. -func (r *rows) ColumnTypeScanType(index int) reflect.Type { - return colTypeToReflectType(r.columnType[index]) -} - -type stmt struct { - conn *conn - query string -} - -var _ driver.Stmt = (*stmt)(nil) -var _ driver.ColumnConverter = (*stmt)(nil) - -// Close closes the statement. -func (s *stmt) Close() error { - return nil -} - -// NumInput returns the number of placeholder parameters. -func (s *stmt) NumInput() int { - // Golang sql won't sanity check argument counts before Query. - return -1 -} - -// Exec executes a query that doesn't return rows, such as an INSERT or -// UPDATE. -func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { - wasiParams := make([]mysql.ParameterValue, len(args)) - for i, v := range args { - wasiParams[i] = toWasiParameterValue(v) - } - - queryResult := s.conn.spinConn.Execute(s.query, wasiParams) - if queryResult.IsErr() { - return &result{}, toError(queryResult.Err()) - } - - return &result{}, nil -} - -// Query executes a query that may return rows, such as a SELECT. -func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { - wasiParams := make([]mysql.ParameterValue, len(args)) - for i, v := range args { - wasiParams[i] = toWasiParameterValue(v) - } - - results := s.conn.spinConn.Query(s.query, wasiParams) - if results.IsErr() { - return nil, toError(results.Err()) - } - - rowLen := len(results.Ok().Rows) - allRows := make([][]any, rowLen) - for rowNum, row := range results.Ok().Rows { - allRows[rowNum] = toRow(row) - } - - cols := results.Ok().Columns - colNames := make([]string, len(cols)) - colTypes := make([]uint8, len(cols)) - for i, c := range cols { - colNames[i] = c.Name - colTypes[i] = uint8(c.DataType) - } - - rows := &rows{ - columns: colNames, - columnType: colTypes, - rows: allRows, - len: int(rowLen), - } - return rows, nil -} - -func toWasiParameterValue(x any) mysql.ParameterValue { - switch v := x.(type) { - case bool: - return rdbmstypes.MakeParameterValueBoolean(v) - case int8: - return rdbmstypes.MakeParameterValueInt8(v) - case int16: - return rdbmstypes.MakeParameterValueInt16(v) - case int32: - return rdbmstypes.MakeParameterValueInt32(v) - case int64: - return rdbmstypes.MakeParameterValueInt64(v) - case int: - return rdbmstypes.MakeParameterValueInt64(int64(v)) - case uint8: - return rdbmstypes.MakeParameterValueUint8(v) - case uint16: - return rdbmstypes.MakeParameterValueUint16(v) - case uint32: - return rdbmstypes.MakeParameterValueUint32(v) - case uint64: - return rdbmstypes.MakeParameterValueUint64(v) - case float32: - return rdbmstypes.MakeParameterValueFloating32(v) - case float64: - return rdbmstypes.MakeParameterValueFloating64(v) - case string: - return rdbmstypes.MakeParameterValueStr(v) - case []byte: - return rdbmstypes.MakeParameterValueBinary(v) - case nil: - return rdbmstypes.MakeParameterValueDbNull() - default: - panic("unknown value type") - } -} - -func toError(err mysql.Error) error { - switch err.Tag() { - case rdbmstypes.ErrorBadParameter: - return errors.New(err.BadParameter()) - case rdbmstypes.ErrorConnectionFailed: - return errors.New(err.ConnectionFailed()) - case rdbmstypes.ErrorQueryFailed: - return errors.New(err.QueryFailed()) - case rdbmstypes.ErrorValueConversionFailed: - return errors.New(err.ValueConversionFailed()) - default: - // TODO: not sure if using "Other" as the default is appropriate - return errors.New(err.Other()) - } -} - -func toRow(row []rdbmstypes.DbValue) []any { - result := make([]any, len(row)) - for i, v := range row { - switch v.Tag() { - case rdbmstypes.DbValueBoolean: - result[i] = v.Boolean() - case rdbmstypes.DbValueInt8: - result[i] = v.Int8() - case rdbmstypes.DbValueInt16: - result[i] = v.Int16() - case rdbmstypes.DbValueInt32: - result[i] = v.Int32() - case rdbmstypes.DbValueInt64: - result[i] = v.Int64() - case rdbmstypes.DbValueUint8: - result[i] = v.Uint8() - case rdbmstypes.DbValueUint16: - result[i] = v.Uint16() - case rdbmstypes.DbValueUint32: - result[i] = v.Uint32() - case rdbmstypes.DbValueUint64: - result[i] = v.Uint64() - case rdbmstypes.DbValueFloating32: - result[i] = v.Floating32() - case rdbmstypes.DbValueFloating64: - result[i] = v.Floating64() - case rdbmstypes.DbValueStr: - result[i] = v.Str() - case rdbmstypes.DbValueBinary: - result[i] = v.Binary() - case rdbmstypes.DbValueDbNull: - result[i] = nil - default: - panic("unknown value type") - } - } - - return result -} - -// ColumnConverter returns GlobalParameterConverter to prevent using driver.DefaultParameterConverter. -func (s *stmt) ColumnConverter(_ int) driver.ValueConverter { - return spindb.GlobalParameterConverter -} - -type result struct{} - -func (r result) LastInsertId() (int64, error) { - return -1, errors.New("LastInsertId is unsupported by this driver") -} - -func (r result) RowsAffected() (int64, error) { - return -1, errors.New("RowsAffected is unsupported by this driver") -} - -func colTypeToReflectType(typ uint8) reflect.Type { - switch typ { - case uint8(rdbmstypes.DbDataTypeBoolean): - return reflect.TypeOf(false) - case uint8(rdbmstypes.DbDataTypeInt8): - return reflect.TypeOf(int8(0)) - case uint8(rdbmstypes.DbDataTypeInt16): - return reflect.TypeOf(int16(0)) - case uint8(rdbmstypes.DbDataTypeInt32): - return reflect.TypeOf(int32(0)) - case uint8(rdbmstypes.DbDataTypeInt64): - return reflect.TypeOf(int64(0)) - case uint8(rdbmstypes.DbDataTypeUint8): - return reflect.TypeOf(uint8(0)) - case uint8(rdbmstypes.DbDataTypeUint16): - return reflect.TypeOf(uint16(0)) - case uint8(rdbmstypes.DbDataTypeUint32): - return reflect.TypeOf(uint32(0)) - case uint8(rdbmstypes.DbDataTypeUint64): - return reflect.TypeOf(uint64(0)) - case uint8(rdbmstypes.DbDataTypeStr): - return reflect.TypeOf("") - case uint8(rdbmstypes.DbDataTypeBinary): - return reflect.TypeOf(new([]byte)) - case uint8(rdbmstypes.DbDataTypeOther): - return reflect.TypeOf(new(any)).Elem() - } - panic("invalid db column type of " + string(typ)) -} diff --git a/v3/redis/redis.go b/v3/redis/redis.go deleted file mode 100644 index f7377191..00000000 --- a/v3/redis/redis.go +++ /dev/null @@ -1,226 +0,0 @@ -// Package redis provides the handler function for the Redis trigger, as well -// as access to Redis within Spin components. - -package redis - -import ( - "fmt" - - redis "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_redis" -) - -// Client is a Redis client. -type Client struct { - conn redis.Connection -} - -// NewClient returns a Redis client. -func NewClient(address string) (Client, error) { - result := redis.ConnectionOpen(address) - if result.IsErr() { - return Client{}, toError(result.Err()) - } - - return Client{conn: *result.Ok()}, nil -} - -// Publish a Redis message to the specified channel. -func (c *Client) Publish(channel string, payload []byte) error { - result := c.conn.Publish(channel, redis.Payload(payload)) - if result.IsErr() { - return toError(result.Err()) - } - - return nil -} - -// Get the value of a key. -func (c *Client) Get(key string) ([]byte, error) { - result := c.conn.Get(key) - if result.IsErr() { - return nil, toError(result.Err()) - } - - if result.Ok().IsNone() { - return nil, nil - } - - return result.Ok().Some(), nil -} - -// Set key to value. -// -// If key already holds a value, it is overwritten. -func (c *Client) Set(key string, payload []byte) error { - result := c.conn.Set(key, redis.Payload(payload)) - if result.IsErr() { - return toError(result.Err()) - } - - return nil -} - -// 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. -func (c *Client) Incr(key string) (int64, error) { - result := c.conn.Incr(key) - if result.IsErr() { - return 0, toError(result.Err()) - } - - return result.Ok(), nil -} - -// Removes the specified keys. -// -// A key is ignored if it does not exist. Returns the number of keys deleted. -func (c *Client) Del(keys ...string) (uint32, error) { - result := c.conn.Del(keys) - if result.IsErr() { - return 0, toError(result.Err()) - } - - return result.Ok(), nil -} - -// Add the specified `values` to the set named `key`, returning the number of newly-added values. -func (c *Client) Sadd(key string, values ...string) (uint32, error) { - result := c.conn.Sadd(key, values) - if result.IsErr() { - return 0, toError(result.Err()) - } - - return result.Ok(), nil -} - -// Retrieve the contents of the set named `key`. -func (c *Client) Smembers(key string) ([]string, error) { - result := c.conn.Smembers(key) - if result.IsErr() { - return nil, toError(result.Err()) - } - - return result.Ok(), nil -} - -// Remove the specified `values` from the set named `key`, returning the number of newly-removed values. -func (c *Client) Srem(key string, values ...string) (uint32, error) { - result := c.conn.Srem(key, values) - if result.IsErr() { - return 0, toError(result.Err()) - } - - return result.Ok(), nil -} - -// ResultKind represents a result type returned from executing a Redis command. -type ResultKind uint8 - -const ( - ResultKindNil ResultKind = iota - ResultKindStatus - ResultKindInt64 - ResultKindBinary -) - -// String implements fmt.Stringer. -func (r ResultKind) String() string { - switch r { - case ResultKindNil: - return "nil" - case ResultKindStatus: - return "status" - case ResultKindInt64: - return "int64" - case ResultKindBinary: - return "binary" - default: - return "unknown" - } -} - -// GoString implements fmt.GoStringer. -func (r ResultKind) GoString() string { return r.String() } - -// Result represents a value returned from a Redis command. -type Result struct { - Kind ResultKind - Val any -} - -// Execute runs the specified Redis command with the specified arguments, -// returning zero or more results. This is a general-purpose function which -// should work with any Redis command. -// -// Arguments must be string, []byte, int, int64, or int32. -func (c *Client) Execute(command string, arguments ...any) ([]*Result, error) { - var params []redis.RedisParameter - for _, a := range arguments { - p, err := createParameter(a) - if err != nil { - return nil, err - } - params = append(params, p) - } - - result := c.conn.Execute(command, params) - if result.IsErr() { - return nil, toError(result.Err()) - } - - var results []*Result - for _, r := range result.Ok() { - results = append(results, toResult(r)) - } - - return results, nil -} - -func createParameter(x any) (redis.RedisParameter, error) { - switch v := x.(type) { - case int: - return redis.MakeRedisParameterInt64(int64(v)), nil - case int64: - return redis.MakeRedisParameterInt64(v), nil - case int32: - return redis.MakeRedisParameterInt64(int64(v)), nil - case []byte: - return redis.MakeRedisParameterBinary(redis.Payload(v)), nil - case string: - return redis.MakeRedisParameterBinary(redis.Payload(v)), nil - default: - return redis.RedisParameter{}, fmt.Errorf("invalid type %T; must be string, []byte, int, int64, or int32", v) - } -} - -func toResult(param redis.RedisResult) *Result { - switch param.Tag() { - case redis.RedisResultStatus: - return &Result{ - Kind: ResultKindStatus, - Val: param.Status(), - } - case redis.RedisResultInt64: - return &Result{ - Kind: ResultKindInt64, - Val: param.Int64(), - } - case redis.RedisResultBinary: - return &Result{ - Kind: ResultKindBinary, - Val: param.Binary(), - } - default: - return &Result{ - Kind: ResultKindNil, - Val: nil, - } - } -} - -func toError(e redis.Error) error { - return fmt.Errorf("%v", e.Other()) -} diff --git a/v3/variables/testdata/variables/go.mod b/v3/variables/testdata/variables/go.mod deleted file mode 100644 index fd8eeae6..00000000 --- a/v3/variables/testdata/variables/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/spinframework/spin-go-sdk/v3/examples/variables - -go 1.25.5 - -require github.com/spinframework/spin-go-sdk/v3 v3.0.0 - -require ( - github.com/bytecodealliance/wit-bindgen v0.0.0-00010101000000-000000000000 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect -) - -replace github.com/spinframework/spin-go-sdk/v3 => ../../../ - -replace github.com/bytecodealliance/wit-bindgen => github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 diff --git a/v3/variables/testdata/variables/go.sum b/v3/variables/testdata/variables/go.sum deleted file mode 100644 index 00db3b18..00000000 --- a/v3/variables/testdata/variables/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAmU6eZnDQpBHrdQwPXi5atE0KSfjU8zwFkClnw= -github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= -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/v3/variables/testdata/variables/spin.toml b/v3/variables/testdata/variables/spin.toml deleted file mode 100644 index 1ab5cd44..00000000 --- a/v3/variables/testdata/variables/spin.toml +++ /dev/null @@ -1,23 +0,0 @@ -spin_manifest_version = 2 - -[application] -name = "variables-example" -authors = ["Fermyon Engineering "] -description = "A simple Spin application written in Go." -version = "1.0.0" - -[variables] -object = { default = "teapot" } - -[[trigger.http]] -route = "/..." -component = "variables" - -[component.variables] -source = "main.wasm" -[component.variables.variables] -message = "I'm a {{object}}" - -[component.variables.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit componentize" - diff --git a/v3/variables/variables.go b/v3/variables/variables.go deleted file mode 100644 index 8d70b792..00000000 --- a/v3/variables/variables.go +++ /dev/null @@ -1,34 +0,0 @@ -package variables - -import ( - "fmt" - - variables "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_variables" -) - -// Get an application variable value for the current component. -// -// The name must match one defined in in the component manifest. -func Get(key string) (string, error) { - result := variables.Get(key) - if result.IsErr() { - return "", errorVariantToError(result.Err()) - } - - return result.Ok(), nil -} - -func errorVariantToError(err variables.Error) error { - switch err.Tag() { - case variables.ErrorInvalidName: - return fmt.Errorf("%v", err.InvalidName()) - case variables.ErrorProvider: - return fmt.Errorf("%v", err.Provider()) - case variables.ErrorUndefined: - return fmt.Errorf("%v", err.Undefined()) - case variables.ErrorOther: - return fmt.Errorf("%v", err.Other()) - default: - return fmt.Errorf("no error provided by host implementation") - } -} diff --git a/variables/internals.go b/variables/internals.go deleted file mode 100644 index 97ab580b..00000000 --- a/variables/internals.go +++ /dev/null @@ -1,42 +0,0 @@ -package variables - -// #cgo CFLAGS: -Wno-unused-parameter -Wno-switch-bool -// #include -// #include -import "C" -import ( - "errors" - "unsafe" -) - -func get(key string) (string, error) { - var spinResponse C.spin_config_expected_string_error_t - - spinKey := C.spin_config_string_t{ptr: C.CString(key), len: C.size_t(len(key))} - defer func() { - C.spin_config_expected_string_error_free(&spinResponse) - C.spin_config_string_free(&spinKey) - }() - - C.spin_config_get_config(&spinKey, &spinResponse) - - if spinResponse.is_err { // error response from spin - spinErr := (*C.spin_config_error_t)(unsafe.Pointer(&spinResponse.val)) - return "", toError(spinErr) - } - - ok := (*spinString)(unsafe.Pointer(&spinResponse.val)) - return ok.String(), nil -} - -func toError(err *C.spin_config_error_t) error { - spinErr := (*spinString)(unsafe.Pointer(&err.val)) - return errors.New(spinErr.String()) -} - -type spinString C.spin_config_string_t - -// String returns the spinString as a go string. -func (ss spinString) String() string { - return C.GoStringN(ss.ptr, C.int(ss.len)) -} diff --git a/variables/spin-config.c b/variables/spin-config.c deleted file mode 100644 index b2d1ab02..00000000 --- a/variables/spin-config.c +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include - -__attribute__((weak, export_name("canonical_abi_realloc"))) -void *canonical_abi_realloc( -void *ptr, -size_t orig_size, -size_t align, -size_t new_size -) { - if (new_size == 0) - return (void*) align; - void *ret = realloc(ptr, new_size); - if (!ret) - abort(); - return ret; -} - -__attribute__((weak, export_name("canonical_abi_free"))) -void canonical_abi_free( -void *ptr, -size_t size, -size_t align -) { - if (size == 0) - return; - free(ptr); -} -#include - -void spin_config_string_set(spin_config_string_t *ret, const char *s) { - ret->ptr = (char*) s; - ret->len = strlen(s); -} - -void spin_config_string_dup(spin_config_string_t *ret, const char *s) { - ret->len = strlen(s); - ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len); - memcpy(ret->ptr, s, ret->len); -} - -void spin_config_string_free(spin_config_string_t *ret) { - canonical_abi_free(ret->ptr, ret->len, 1); - ret->ptr = NULL; - ret->len = 0; -} -void spin_config_error_free(spin_config_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 0: { - spin_config_string_free(&ptr->val.provider); - break; - } - case 1: { - spin_config_string_free(&ptr->val.invalid_key); - break; - } - case 2: { - spin_config_string_free(&ptr->val.invalid_schema); - break; - } - case 3: { - spin_config_string_free(&ptr->val.other); - break; - } - } -} -void spin_config_expected_string_error_free(spin_config_expected_string_error_t *ptr) { - if (!ptr->is_err) { - spin_config_string_free(&ptr->val.ok); - } else { - spin_config_error_free(&ptr->val.err); - } -} - -__attribute__((aligned(4))) -static uint8_t RET_AREA[16]; -__attribute__((import_module("spin-config"), import_name("get-config"))) -void __wasm_import_spin_config_get_config(int32_t, int32_t, int32_t); -void spin_config_get_config(spin_config_string_t *key, spin_config_expected_string_error_t *ret0) { - int32_t ptr = (int32_t) &RET_AREA; - __wasm_import_spin_config_get_config((int32_t) (*key).ptr, (int32_t) (*key).len, ptr); - spin_config_expected_string_error_t expected; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - expected.is_err = false; - - expected.val.ok = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - expected.is_err = true; - spin_config_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.provider = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 1: { - variant.val.invalid_key = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 2: { - variant.val.invalid_schema = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - case 3: { - variant.val.other = (spin_config_string_t) { (char*)(*((int32_t*) (ptr + 8))), (size_t)(*((int32_t*) (ptr + 12))) }; - break; - } - } - - expected.val.err = variant; - break; - } - }*ret0 = expected; -} diff --git a/variables/spin-config.h b/variables/spin-config.h deleted file mode 100644 index 46be58d4..00000000 --- a/variables/spin-config.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __BINDINGS_SPIN_CONFIG_H -#define __BINDINGS_SPIN_CONFIG_H -#ifdef __cplusplus -extern "C" -{ - #endif - - #include - #include - - typedef struct { - char *ptr; - size_t len; - } spin_config_string_t; - - void spin_config_string_set(spin_config_string_t *ret, const char *s); - void spin_config_string_dup(spin_config_string_t *ret, const char *s); - void spin_config_string_free(spin_config_string_t *ret); - typedef struct { - uint8_t tag; - union { - spin_config_string_t provider; - spin_config_string_t invalid_key; - spin_config_string_t invalid_schema; - spin_config_string_t other; - } val; - } spin_config_error_t; - #define SPIN_CONFIG_ERROR_PROVIDER 0 - #define SPIN_CONFIG_ERROR_INVALID_KEY 1 - #define SPIN_CONFIG_ERROR_INVALID_SCHEMA 2 - #define SPIN_CONFIG_ERROR_OTHER 3 - void spin_config_error_free(spin_config_error_t *ptr); - typedef struct { - bool is_err; - union { - spin_config_string_t ok; - spin_config_error_t err; - } val; - } spin_config_expected_string_error_t; - void spin_config_expected_string_error_free(spin_config_expected_string_error_t *ptr); - void spin_config_get_config(spin_config_string_t *key, spin_config_expected_string_error_t *ret0); - #ifdef __cplusplus -} -#endif -#endif diff --git a/variables/testdata/variables/go.mod b/variables/testdata/variables/go.mod new file mode 100644 index 00000000..fa6b0b8f --- /dev/null +++ b/variables/testdata/variables/go.mod @@ -0,0 +1,11 @@ +module github.com/spinframework/spin-go-sdk/v3/examples/variables + +go 1.25.5 + +require ( + github.com/spinframework/spin-go-sdk/v3 v3.0.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + go.bytecodealliance.org/pkg v0.2.1 +) + +replace github.com/spinframework/spin-go-sdk/v3 => ../../../ diff --git a/v3/examples/mqtt-outbound/go.sum b/variables/testdata/variables/go.sum similarity index 71% rename from v3/examples/mqtt-outbound/go.sum rename to variables/testdata/variables/go.sum index 00db3b18..b5bca15f 100644 --- a/v3/examples/mqtt-outbound/go.sum +++ b/variables/testdata/variables/go.sum @@ -2,3 +2,5 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= +go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/v3/variables/testdata/variables/main.go b/variables/testdata/variables/main.go similarity index 100% rename from v3/variables/testdata/variables/main.go rename to variables/testdata/variables/main.go diff --git a/v3/examples/variables/spin.toml b/variables/testdata/variables/spin.toml similarity index 96% rename from v3/examples/variables/spin.toml rename to variables/testdata/variables/spin.toml index 042d091e..7a296939 100644 --- a/v3/examples/variables/spin.toml +++ b/variables/testdata/variables/spin.toml @@ -19,4 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "componentize-go --world http-trigger --wit-path ../../wit componentize" +command = "componentize-go --world http-trigger --wit-path ../../../wit build" + diff --git a/variables/variables.go b/variables/variables.go index 5a669a14..8d70b792 100644 --- a/variables/variables.go +++ b/variables/variables.go @@ -1,8 +1,34 @@ package variables +import ( + "fmt" + + variables "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_variables" +) + // Get an application variable value for the current component. // // The name must match one defined in in the component manifest. func Get(key string) (string, error) { - return get(key) + result := variables.Get(key) + if result.IsErr() { + return "", errorVariantToError(result.Err()) + } + + return result.Ok(), nil +} + +func errorVariantToError(err variables.Error) error { + switch err.Tag() { + case variables.ErrorInvalidName: + return fmt.Errorf("%v", err.InvalidName()) + case variables.ErrorProvider: + return fmt.Errorf("%v", err.Provider()) + case variables.ErrorUndefined: + return fmt.Errorf("%v", err.Undefined()) + case variables.ErrorOther: + return fmt.Errorf("%v", err.Other()) + default: + return fmt.Errorf("no error provided by host implementation") + } } diff --git a/v3/wit/deps/cli-2023-10-18/command.wit b/wit/deps/cli-2023-10-18/command.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/command.wit rename to wit/deps/cli-2023-10-18/command.wit diff --git a/v3/wit/deps/cli-2023-10-18/environment.wit b/wit/deps/cli-2023-10-18/environment.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/environment.wit rename to wit/deps/cli-2023-10-18/environment.wit diff --git a/v3/wit/deps/cli-2023-10-18/exit.wit b/wit/deps/cli-2023-10-18/exit.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/exit.wit rename to wit/deps/cli-2023-10-18/exit.wit diff --git a/v3/wit/deps/cli-2023-10-18/reactor.wit b/wit/deps/cli-2023-10-18/reactor.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/reactor.wit rename to wit/deps/cli-2023-10-18/reactor.wit diff --git a/v3/wit/deps/cli-2023-10-18/run.wit b/wit/deps/cli-2023-10-18/run.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/run.wit rename to wit/deps/cli-2023-10-18/run.wit diff --git a/v3/wit/deps/cli-2023-10-18/stdio.wit b/wit/deps/cli-2023-10-18/stdio.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/stdio.wit rename to wit/deps/cli-2023-10-18/stdio.wit diff --git a/v3/wit/deps/cli-2023-10-18/terminal.wit b/wit/deps/cli-2023-10-18/terminal.wit similarity index 100% rename from v3/wit/deps/cli-2023-10-18/terminal.wit rename to wit/deps/cli-2023-10-18/terminal.wit diff --git a/v3/wit/deps/cli-2023-11-10/command.wit b/wit/deps/cli-2023-11-10/command.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/command.wit rename to wit/deps/cli-2023-11-10/command.wit diff --git a/v3/wit/deps/cli-2023-11-10/environment.wit b/wit/deps/cli-2023-11-10/environment.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/environment.wit rename to wit/deps/cli-2023-11-10/environment.wit diff --git a/v3/wit/deps/cli-2023-11-10/exit.wit b/wit/deps/cli-2023-11-10/exit.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/exit.wit rename to wit/deps/cli-2023-11-10/exit.wit diff --git a/v3/wit/deps/cli-2023-11-10/reactor.wit b/wit/deps/cli-2023-11-10/reactor.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/reactor.wit rename to wit/deps/cli-2023-11-10/reactor.wit diff --git a/v3/wit/deps/cli-2023-11-10/run.wit b/wit/deps/cli-2023-11-10/run.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/run.wit rename to wit/deps/cli-2023-11-10/run.wit diff --git a/v3/wit/deps/cli-2023-11-10/stdio.wit b/wit/deps/cli-2023-11-10/stdio.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/stdio.wit rename to wit/deps/cli-2023-11-10/stdio.wit diff --git a/v3/wit/deps/cli-2023-11-10/terminal.wit b/wit/deps/cli-2023-11-10/terminal.wit similarity index 100% rename from v3/wit/deps/cli-2023-11-10/terminal.wit rename to wit/deps/cli-2023-11-10/terminal.wit diff --git a/v3/wit/deps/cli/command.wit b/wit/deps/cli/command.wit similarity index 100% rename from v3/wit/deps/cli/command.wit rename to wit/deps/cli/command.wit diff --git a/v3/wit/deps/cli/environment.wit b/wit/deps/cli/environment.wit similarity index 100% rename from v3/wit/deps/cli/environment.wit rename to wit/deps/cli/environment.wit diff --git a/v3/wit/deps/cli/exit.wit b/wit/deps/cli/exit.wit similarity index 100% rename from v3/wit/deps/cli/exit.wit rename to wit/deps/cli/exit.wit diff --git a/v3/wit/deps/cli/imports.wit b/wit/deps/cli/imports.wit similarity index 100% rename from v3/wit/deps/cli/imports.wit rename to wit/deps/cli/imports.wit diff --git a/v3/wit/deps/cli/run.wit b/wit/deps/cli/run.wit similarity index 100% rename from v3/wit/deps/cli/run.wit rename to wit/deps/cli/run.wit diff --git a/v3/wit/deps/cli/stdio.wit b/wit/deps/cli/stdio.wit similarity index 100% rename from v3/wit/deps/cli/stdio.wit rename to wit/deps/cli/stdio.wit diff --git a/v3/wit/deps/cli/terminal.wit b/wit/deps/cli/terminal.wit similarity index 100% rename from v3/wit/deps/cli/terminal.wit rename to wit/deps/cli/terminal.wit diff --git a/v3/wit/deps/clocks-2023-10-18/monotonic-clock.wit b/wit/deps/clocks-2023-10-18/monotonic-clock.wit similarity index 100% rename from v3/wit/deps/clocks-2023-10-18/monotonic-clock.wit rename to wit/deps/clocks-2023-10-18/monotonic-clock.wit diff --git a/v3/wit/deps/clocks-2023-10-18/timezone.wit b/wit/deps/clocks-2023-10-18/timezone.wit similarity index 100% rename from v3/wit/deps/clocks-2023-10-18/timezone.wit rename to wit/deps/clocks-2023-10-18/timezone.wit diff --git a/v3/wit/deps/clocks-2023-10-18/wall-clock.wit b/wit/deps/clocks-2023-10-18/wall-clock.wit similarity index 100% rename from v3/wit/deps/clocks-2023-10-18/wall-clock.wit rename to wit/deps/clocks-2023-10-18/wall-clock.wit diff --git a/v3/wit/deps/clocks-2023-10-18/world.wit b/wit/deps/clocks-2023-10-18/world.wit similarity index 100% rename from v3/wit/deps/clocks-2023-10-18/world.wit rename to wit/deps/clocks-2023-10-18/world.wit diff --git a/v3/wit/deps/clocks-2023-11-10/monotonic-clock.wit b/wit/deps/clocks-2023-11-10/monotonic-clock.wit similarity index 100% rename from v3/wit/deps/clocks-2023-11-10/monotonic-clock.wit rename to wit/deps/clocks-2023-11-10/monotonic-clock.wit diff --git a/v3/wit/deps/clocks-2023-11-10/wall-clock.wit b/wit/deps/clocks-2023-11-10/wall-clock.wit similarity index 100% rename from v3/wit/deps/clocks-2023-11-10/wall-clock.wit rename to wit/deps/clocks-2023-11-10/wall-clock.wit diff --git a/v3/wit/deps/clocks-2023-11-10/world.wit b/wit/deps/clocks-2023-11-10/world.wit similarity index 100% rename from v3/wit/deps/clocks-2023-11-10/world.wit rename to wit/deps/clocks-2023-11-10/world.wit diff --git a/v3/wit/deps/clocks/monotonic-clock.wit b/wit/deps/clocks/monotonic-clock.wit similarity index 100% rename from v3/wit/deps/clocks/monotonic-clock.wit rename to wit/deps/clocks/monotonic-clock.wit diff --git a/v3/wit/deps/clocks/wall-clock.wit b/wit/deps/clocks/wall-clock.wit similarity index 100% rename from v3/wit/deps/clocks/wall-clock.wit rename to wit/deps/clocks/wall-clock.wit diff --git a/v3/wit/deps/clocks/world.wit b/wit/deps/clocks/world.wit similarity index 100% rename from v3/wit/deps/clocks/world.wit rename to wit/deps/clocks/world.wit diff --git a/v3/wit/deps/filesystem-2023-10-18/preopens.wit b/wit/deps/filesystem-2023-10-18/preopens.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-10-18/preopens.wit rename to wit/deps/filesystem-2023-10-18/preopens.wit diff --git a/v3/wit/deps/filesystem-2023-10-18/types.wit b/wit/deps/filesystem-2023-10-18/types.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-10-18/types.wit rename to wit/deps/filesystem-2023-10-18/types.wit diff --git a/v3/wit/deps/filesystem-2023-10-18/world.wit b/wit/deps/filesystem-2023-10-18/world.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-10-18/world.wit rename to wit/deps/filesystem-2023-10-18/world.wit diff --git a/v3/wit/deps/filesystem-2023-11-10/preopens.wit b/wit/deps/filesystem-2023-11-10/preopens.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-11-10/preopens.wit rename to wit/deps/filesystem-2023-11-10/preopens.wit diff --git a/v3/wit/deps/filesystem-2023-11-10/types.wit b/wit/deps/filesystem-2023-11-10/types.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-11-10/types.wit rename to wit/deps/filesystem-2023-11-10/types.wit diff --git a/v3/wit/deps/filesystem-2023-11-10/world.wit b/wit/deps/filesystem-2023-11-10/world.wit similarity index 100% rename from v3/wit/deps/filesystem-2023-11-10/world.wit rename to wit/deps/filesystem-2023-11-10/world.wit diff --git a/v3/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit similarity index 100% rename from v3/wit/deps/filesystem/preopens.wit rename to wit/deps/filesystem/preopens.wit diff --git a/v3/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit similarity index 100% rename from v3/wit/deps/filesystem/types.wit rename to wit/deps/filesystem/types.wit diff --git a/v3/wit/deps/filesystem/world.wit b/wit/deps/filesystem/world.wit similarity index 100% rename from v3/wit/deps/filesystem/world.wit rename to wit/deps/filesystem/world.wit diff --git a/v3/wit/deps/http-2023-10-18/incoming-handler.wit b/wit/deps/http-2023-10-18/incoming-handler.wit similarity index 100% rename from v3/wit/deps/http-2023-10-18/incoming-handler.wit rename to wit/deps/http-2023-10-18/incoming-handler.wit diff --git a/v3/wit/deps/http-2023-10-18/outgoing-handler.wit b/wit/deps/http-2023-10-18/outgoing-handler.wit similarity index 100% rename from v3/wit/deps/http-2023-10-18/outgoing-handler.wit rename to wit/deps/http-2023-10-18/outgoing-handler.wit diff --git a/v3/wit/deps/http-2023-10-18/proxy.wit b/wit/deps/http-2023-10-18/proxy.wit similarity index 100% rename from v3/wit/deps/http-2023-10-18/proxy.wit rename to wit/deps/http-2023-10-18/proxy.wit diff --git a/v3/wit/deps/http-2023-10-18/types.wit b/wit/deps/http-2023-10-18/types.wit similarity index 100% rename from v3/wit/deps/http-2023-10-18/types.wit rename to wit/deps/http-2023-10-18/types.wit diff --git a/v3/wit/deps/http-2023-11-10/handler.wit b/wit/deps/http-2023-11-10/handler.wit similarity index 100% rename from v3/wit/deps/http-2023-11-10/handler.wit rename to wit/deps/http-2023-11-10/handler.wit diff --git a/v3/wit/deps/http-2023-11-10/proxy.wit b/wit/deps/http-2023-11-10/proxy.wit similarity index 100% rename from v3/wit/deps/http-2023-11-10/proxy.wit rename to wit/deps/http-2023-11-10/proxy.wit diff --git a/v3/wit/deps/http-2023-11-10/types.wit b/wit/deps/http-2023-11-10/types.wit similarity index 100% rename from v3/wit/deps/http-2023-11-10/types.wit rename to wit/deps/http-2023-11-10/types.wit diff --git a/v3/wit/deps/http/handler.wit b/wit/deps/http/handler.wit similarity index 100% rename from v3/wit/deps/http/handler.wit rename to wit/deps/http/handler.wit diff --git a/v3/wit/deps/http/proxy.wit b/wit/deps/http/proxy.wit similarity index 100% rename from v3/wit/deps/http/proxy.wit rename to wit/deps/http/proxy.wit diff --git a/v3/wit/deps/http/types.wit b/wit/deps/http/types.wit similarity index 100% rename from v3/wit/deps/http/types.wit rename to wit/deps/http/types.wit diff --git a/v3/wit/deps/io-2023-10-18/poll.wit b/wit/deps/io-2023-10-18/poll.wit similarity index 100% rename from v3/wit/deps/io-2023-10-18/poll.wit rename to wit/deps/io-2023-10-18/poll.wit diff --git a/v3/wit/deps/io-2023-10-18/streams.wit b/wit/deps/io-2023-10-18/streams.wit similarity index 100% rename from v3/wit/deps/io-2023-10-18/streams.wit rename to wit/deps/io-2023-10-18/streams.wit diff --git a/v3/wit/deps/io-2023-10-18/world.wit b/wit/deps/io-2023-10-18/world.wit similarity index 100% rename from v3/wit/deps/io-2023-10-18/world.wit rename to wit/deps/io-2023-10-18/world.wit diff --git a/v3/wit/deps/io-2023-11-10/error.wit b/wit/deps/io-2023-11-10/error.wit similarity index 100% rename from v3/wit/deps/io-2023-11-10/error.wit rename to wit/deps/io-2023-11-10/error.wit diff --git a/v3/wit/deps/io-2023-11-10/poll.wit b/wit/deps/io-2023-11-10/poll.wit similarity index 100% rename from v3/wit/deps/io-2023-11-10/poll.wit rename to wit/deps/io-2023-11-10/poll.wit diff --git a/v3/wit/deps/io-2023-11-10/streams.wit b/wit/deps/io-2023-11-10/streams.wit similarity index 100% rename from v3/wit/deps/io-2023-11-10/streams.wit rename to wit/deps/io-2023-11-10/streams.wit diff --git a/v3/wit/deps/io-2023-11-10/world.wit b/wit/deps/io-2023-11-10/world.wit similarity index 100% rename from v3/wit/deps/io-2023-11-10/world.wit rename to wit/deps/io-2023-11-10/world.wit diff --git a/v3/wit/deps/io/error.wit b/wit/deps/io/error.wit similarity index 100% rename from v3/wit/deps/io/error.wit rename to wit/deps/io/error.wit diff --git a/v3/wit/deps/io/poll.wit b/wit/deps/io/poll.wit similarity index 100% rename from v3/wit/deps/io/poll.wit rename to wit/deps/io/poll.wit diff --git a/v3/wit/deps/io/streams.wit b/wit/deps/io/streams.wit similarity index 100% rename from v3/wit/deps/io/streams.wit rename to wit/deps/io/streams.wit diff --git a/v3/wit/deps/io/world.wit b/wit/deps/io/world.wit similarity index 100% rename from v3/wit/deps/io/world.wit rename to wit/deps/io/world.wit diff --git a/v3/wit/deps/keyvalue-2024-10-17/atomic.wit b/wit/deps/keyvalue-2024-10-17/atomic.wit similarity index 100% rename from v3/wit/deps/keyvalue-2024-10-17/atomic.wit rename to wit/deps/keyvalue-2024-10-17/atomic.wit diff --git a/v3/wit/deps/keyvalue-2024-10-17/batch.wit b/wit/deps/keyvalue-2024-10-17/batch.wit similarity index 100% rename from v3/wit/deps/keyvalue-2024-10-17/batch.wit rename to wit/deps/keyvalue-2024-10-17/batch.wit diff --git a/v3/wit/deps/keyvalue-2024-10-17/store.wit b/wit/deps/keyvalue-2024-10-17/store.wit similarity index 100% rename from v3/wit/deps/keyvalue-2024-10-17/store.wit rename to wit/deps/keyvalue-2024-10-17/store.wit diff --git a/v3/wit/deps/keyvalue-2024-10-17/watch.wit b/wit/deps/keyvalue-2024-10-17/watch.wit similarity index 100% rename from v3/wit/deps/keyvalue-2024-10-17/watch.wit rename to wit/deps/keyvalue-2024-10-17/watch.wit diff --git a/v3/wit/deps/keyvalue-2024-10-17/world.wit b/wit/deps/keyvalue-2024-10-17/world.wit similarity index 100% rename from v3/wit/deps/keyvalue-2024-10-17/world.wit rename to wit/deps/keyvalue-2024-10-17/world.wit diff --git a/v3/wit/deps/random-2023-10-18/insecure-seed.wit b/wit/deps/random-2023-10-18/insecure-seed.wit similarity index 100% rename from v3/wit/deps/random-2023-10-18/insecure-seed.wit rename to wit/deps/random-2023-10-18/insecure-seed.wit diff --git a/v3/wit/deps/random-2023-10-18/insecure.wit b/wit/deps/random-2023-10-18/insecure.wit similarity index 100% rename from v3/wit/deps/random-2023-10-18/insecure.wit rename to wit/deps/random-2023-10-18/insecure.wit diff --git a/v3/wit/deps/random-2023-10-18/random.wit b/wit/deps/random-2023-10-18/random.wit similarity index 100% rename from v3/wit/deps/random-2023-10-18/random.wit rename to wit/deps/random-2023-10-18/random.wit diff --git a/v3/wit/deps/random-2023-10-18/world.wit b/wit/deps/random-2023-10-18/world.wit similarity index 100% rename from v3/wit/deps/random-2023-10-18/world.wit rename to wit/deps/random-2023-10-18/world.wit diff --git a/v3/wit/deps/random-2023-11-10/insecure-seed.wit b/wit/deps/random-2023-11-10/insecure-seed.wit similarity index 100% rename from v3/wit/deps/random-2023-11-10/insecure-seed.wit rename to wit/deps/random-2023-11-10/insecure-seed.wit diff --git a/v3/wit/deps/random-2023-11-10/insecure.wit b/wit/deps/random-2023-11-10/insecure.wit similarity index 100% rename from v3/wit/deps/random-2023-11-10/insecure.wit rename to wit/deps/random-2023-11-10/insecure.wit diff --git a/v3/wit/deps/random-2023-11-10/random.wit b/wit/deps/random-2023-11-10/random.wit similarity index 100% rename from v3/wit/deps/random-2023-11-10/random.wit rename to wit/deps/random-2023-11-10/random.wit diff --git a/v3/wit/deps/random-2023-11-10/world.wit b/wit/deps/random-2023-11-10/world.wit similarity index 100% rename from v3/wit/deps/random-2023-11-10/world.wit rename to wit/deps/random-2023-11-10/world.wit diff --git a/v3/wit/deps/random/insecure-seed.wit b/wit/deps/random/insecure-seed.wit similarity index 100% rename from v3/wit/deps/random/insecure-seed.wit rename to wit/deps/random/insecure-seed.wit diff --git a/v3/wit/deps/random/insecure.wit b/wit/deps/random/insecure.wit similarity index 100% rename from v3/wit/deps/random/insecure.wit rename to wit/deps/random/insecure.wit diff --git a/v3/wit/deps/random/random.wit b/wit/deps/random/random.wit similarity index 100% rename from v3/wit/deps/random/random.wit rename to wit/deps/random/random.wit diff --git a/v3/wit/deps/random/world.wit b/wit/deps/random/world.wit similarity index 100% rename from v3/wit/deps/random/world.wit rename to wit/deps/random/world.wit diff --git a/v3/wit/deps/sockets-2023-10-18/instance-network.wit b/wit/deps/sockets-2023-10-18/instance-network.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/instance-network.wit rename to wit/deps/sockets-2023-10-18/instance-network.wit diff --git a/v3/wit/deps/sockets-2023-10-18/ip-name-lookup.wit b/wit/deps/sockets-2023-10-18/ip-name-lookup.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/ip-name-lookup.wit rename to wit/deps/sockets-2023-10-18/ip-name-lookup.wit diff --git a/v3/wit/deps/sockets-2023-10-18/network.wit b/wit/deps/sockets-2023-10-18/network.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/network.wit rename to wit/deps/sockets-2023-10-18/network.wit diff --git a/v3/wit/deps/sockets-2023-10-18/tcp-create-socket.wit b/wit/deps/sockets-2023-10-18/tcp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/tcp-create-socket.wit rename to wit/deps/sockets-2023-10-18/tcp-create-socket.wit diff --git a/v3/wit/deps/sockets-2023-10-18/tcp.wit b/wit/deps/sockets-2023-10-18/tcp.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/tcp.wit rename to wit/deps/sockets-2023-10-18/tcp.wit diff --git a/v3/wit/deps/sockets-2023-10-18/udp-create-socket.wit b/wit/deps/sockets-2023-10-18/udp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/udp-create-socket.wit rename to wit/deps/sockets-2023-10-18/udp-create-socket.wit diff --git a/v3/wit/deps/sockets-2023-10-18/udp.wit b/wit/deps/sockets-2023-10-18/udp.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/udp.wit rename to wit/deps/sockets-2023-10-18/udp.wit diff --git a/v3/wit/deps/sockets-2023-10-18/world.wit b/wit/deps/sockets-2023-10-18/world.wit similarity index 100% rename from v3/wit/deps/sockets-2023-10-18/world.wit rename to wit/deps/sockets-2023-10-18/world.wit diff --git a/v3/wit/deps/sockets-2023-11-10/instance-network.wit b/wit/deps/sockets-2023-11-10/instance-network.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/instance-network.wit rename to wit/deps/sockets-2023-11-10/instance-network.wit diff --git a/v3/wit/deps/sockets-2023-11-10/ip-name-lookup.wit b/wit/deps/sockets-2023-11-10/ip-name-lookup.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/ip-name-lookup.wit rename to wit/deps/sockets-2023-11-10/ip-name-lookup.wit diff --git a/v3/wit/deps/sockets-2023-11-10/network.wit b/wit/deps/sockets-2023-11-10/network.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/network.wit rename to wit/deps/sockets-2023-11-10/network.wit diff --git a/v3/wit/deps/sockets-2023-11-10/tcp-create-socket.wit b/wit/deps/sockets-2023-11-10/tcp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/tcp-create-socket.wit rename to wit/deps/sockets-2023-11-10/tcp-create-socket.wit diff --git a/v3/wit/deps/sockets-2023-11-10/tcp.wit b/wit/deps/sockets-2023-11-10/tcp.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/tcp.wit rename to wit/deps/sockets-2023-11-10/tcp.wit diff --git a/v3/wit/deps/sockets-2023-11-10/udp-create-socket.wit b/wit/deps/sockets-2023-11-10/udp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/udp-create-socket.wit rename to wit/deps/sockets-2023-11-10/udp-create-socket.wit diff --git a/v3/wit/deps/sockets-2023-11-10/udp.wit b/wit/deps/sockets-2023-11-10/udp.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/udp.wit rename to wit/deps/sockets-2023-11-10/udp.wit diff --git a/v3/wit/deps/sockets-2023-11-10/world.wit b/wit/deps/sockets-2023-11-10/world.wit similarity index 100% rename from v3/wit/deps/sockets-2023-11-10/world.wit rename to wit/deps/sockets-2023-11-10/world.wit diff --git a/v3/wit/deps/sockets/instance-network.wit b/wit/deps/sockets/instance-network.wit similarity index 100% rename from v3/wit/deps/sockets/instance-network.wit rename to wit/deps/sockets/instance-network.wit diff --git a/v3/wit/deps/sockets/ip-name-lookup.wit b/wit/deps/sockets/ip-name-lookup.wit similarity index 100% rename from v3/wit/deps/sockets/ip-name-lookup.wit rename to wit/deps/sockets/ip-name-lookup.wit diff --git a/v3/wit/deps/sockets/network.wit b/wit/deps/sockets/network.wit similarity index 100% rename from v3/wit/deps/sockets/network.wit rename to wit/deps/sockets/network.wit diff --git a/v3/wit/deps/sockets/tcp-create-socket.wit b/wit/deps/sockets/tcp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets/tcp-create-socket.wit rename to wit/deps/sockets/tcp-create-socket.wit diff --git a/v3/wit/deps/sockets/tcp.wit b/wit/deps/sockets/tcp.wit similarity index 100% rename from v3/wit/deps/sockets/tcp.wit rename to wit/deps/sockets/tcp.wit diff --git a/v3/wit/deps/sockets/udp-create-socket.wit b/wit/deps/sockets/udp-create-socket.wit similarity index 100% rename from v3/wit/deps/sockets/udp-create-socket.wit rename to wit/deps/sockets/udp-create-socket.wit diff --git a/v3/wit/deps/sockets/udp.wit b/wit/deps/sockets/udp.wit similarity index 100% rename from v3/wit/deps/sockets/udp.wit rename to wit/deps/sockets/udp.wit diff --git a/v3/wit/deps/sockets/world.wit b/wit/deps/sockets/world.wit similarity index 100% rename from v3/wit/deps/sockets/world.wit rename to wit/deps/sockets/world.wit diff --git a/v3/wit/deps/spin-postgres@3.0.0/postgres.wit b/wit/deps/spin-postgres@3.0.0/postgres.wit similarity index 100% rename from v3/wit/deps/spin-postgres@3.0.0/postgres.wit rename to wit/deps/spin-postgres@3.0.0/postgres.wit diff --git a/v3/wit/deps/spin@2.0.0/key-value.wit b/wit/deps/spin@2.0.0/key-value.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/key-value.wit rename to wit/deps/spin@2.0.0/key-value.wit diff --git a/v3/wit/deps/spin@2.0.0/llm.wit b/wit/deps/spin@2.0.0/llm.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/llm.wit rename to wit/deps/spin@2.0.0/llm.wit diff --git a/v3/wit/deps/spin@2.0.0/mqtt.wit b/wit/deps/spin@2.0.0/mqtt.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/mqtt.wit rename to wit/deps/spin@2.0.0/mqtt.wit diff --git a/v3/wit/deps/spin@2.0.0/mysql.wit b/wit/deps/spin@2.0.0/mysql.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/mysql.wit rename to wit/deps/spin@2.0.0/mysql.wit diff --git a/v3/wit/deps/spin@2.0.0/postgres.wit b/wit/deps/spin@2.0.0/postgres.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/postgres.wit rename to wit/deps/spin@2.0.0/postgres.wit diff --git a/v3/wit/deps/spin@2.0.0/rdbms-types.wit b/wit/deps/spin@2.0.0/rdbms-types.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/rdbms-types.wit rename to wit/deps/spin@2.0.0/rdbms-types.wit diff --git a/v3/wit/deps/spin@2.0.0/redis.wit b/wit/deps/spin@2.0.0/redis.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/redis.wit rename to wit/deps/spin@2.0.0/redis.wit diff --git a/v3/wit/deps/spin@2.0.0/sqlite.wit b/wit/deps/spin@2.0.0/sqlite.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/sqlite.wit rename to wit/deps/spin@2.0.0/sqlite.wit diff --git a/v3/wit/deps/spin@2.0.0/variables.wit b/wit/deps/spin@2.0.0/variables.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/variables.wit rename to wit/deps/spin@2.0.0/variables.wit diff --git a/v3/wit/deps/spin@2.0.0/world.wit b/wit/deps/spin@2.0.0/world.wit similarity index 100% rename from v3/wit/deps/spin@2.0.0/world.wit rename to wit/deps/spin@2.0.0/world.wit diff --git a/v3/wit/deps/spin@unversioned/config.wit b/wit/deps/spin@unversioned/config.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/config.wit rename to wit/deps/spin@unversioned/config.wit diff --git a/v3/wit/deps/spin@unversioned/http-types.wit b/wit/deps/spin@unversioned/http-types.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/http-types.wit rename to wit/deps/spin@unversioned/http-types.wit diff --git a/v3/wit/deps/spin@unversioned/http.wit b/wit/deps/spin@unversioned/http.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/http.wit rename to wit/deps/spin@unversioned/http.wit diff --git a/v3/wit/deps/spin@unversioned/inbound-http.wit b/wit/deps/spin@unversioned/inbound-http.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/inbound-http.wit rename to wit/deps/spin@unversioned/inbound-http.wit diff --git a/v3/wit/deps/spin@unversioned/inbound-redis.wit b/wit/deps/spin@unversioned/inbound-redis.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/inbound-redis.wit rename to wit/deps/spin@unversioned/inbound-redis.wit diff --git a/v3/wit/deps/spin@unversioned/key-value.wit b/wit/deps/spin@unversioned/key-value.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/key-value.wit rename to wit/deps/spin@unversioned/key-value.wit diff --git a/v3/wit/deps/spin@unversioned/llm.wit b/wit/deps/spin@unversioned/llm.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/llm.wit rename to wit/deps/spin@unversioned/llm.wit diff --git a/v3/wit/deps/spin@unversioned/mysql.wit b/wit/deps/spin@unversioned/mysql.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/mysql.wit rename to wit/deps/spin@unversioned/mysql.wit diff --git a/v3/wit/deps/spin@unversioned/postgres.wit b/wit/deps/spin@unversioned/postgres.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/postgres.wit rename to wit/deps/spin@unversioned/postgres.wit diff --git a/v3/wit/deps/spin@unversioned/rdbms-types.wit b/wit/deps/spin@unversioned/rdbms-types.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/rdbms-types.wit rename to wit/deps/spin@unversioned/rdbms-types.wit diff --git a/v3/wit/deps/spin@unversioned/redis-types.wit b/wit/deps/spin@unversioned/redis-types.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/redis-types.wit rename to wit/deps/spin@unversioned/redis-types.wit diff --git a/v3/wit/deps/spin@unversioned/redis.wit b/wit/deps/spin@unversioned/redis.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/redis.wit rename to wit/deps/spin@unversioned/redis.wit diff --git a/v3/wit/deps/spin@unversioned/sqlite.wit b/wit/deps/spin@unversioned/sqlite.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/sqlite.wit rename to wit/deps/spin@unversioned/sqlite.wit diff --git a/v3/wit/deps/spin@unversioned/world.wit b/wit/deps/spin@unversioned/world.wit similarity index 100% rename from v3/wit/deps/spin@unversioned/world.wit rename to wit/deps/spin@unversioned/world.wit diff --git a/v3/wit/deps/wasi-runtime-config-2024-09-27/store.wit b/wit/deps/wasi-runtime-config-2024-09-27/store.wit similarity index 100% rename from v3/wit/deps/wasi-runtime-config-2024-09-27/store.wit rename to wit/deps/wasi-runtime-config-2024-09-27/store.wit diff --git a/v3/wit/deps/wasi-runtime-config-2024-09-27/world.wit b/wit/deps/wasi-runtime-config-2024-09-27/world.wit similarity index 100% rename from v3/wit/deps/wasi-runtime-config-2024-09-27/world.wit rename to wit/deps/wasi-runtime-config-2024-09-27/world.wit diff --git a/wit/http-types.wit b/wit/http-types.wit deleted file mode 100644 index e0626954..00000000 --- a/wit/http-types.wit +++ /dev/null @@ -1,59 +0,0 @@ -// This is a temporary workaround very similar to https://github.com/deislabs/wasi-experimental-http. -// Once asynchronous functions, streams, and the upstream HTTP API are available, this should be removed. - -// The HTTP status code. -// This is currently an unsigned 16-bit integer, -// but it could be represented as an enum containing -// all possible HTTP status codes. -type http-status = u16 - -// The HTTP body. -// Currently, this is a synchonous byte array, but it should be -// possible to have a stream for both request and response bodies. -type body = list - -// The HTTP headers represented as a list of (name, value) pairs. -type headers = list> - -// The HTTP parameter queries, represented as a list of (name, value) pairs. -type params = list> - -// The HTTP URI of the current request. -type uri = string - -// The HTTP method. -enum method { - get, - post, - put, - delete, - patch, - head, - options, -} - -// An HTTP request. -record request { - method: method, - uri: uri, - headers: headers, - params: params, - body: option, -} - -// An HTTP response. -record response { - status: http-status, - headers: option, - body: option, -} - -// HTTP errors returned by the runtime. -enum http-error { - success, - destination-not-allowed, - invalid-url, - request-error, - runtime-error, - too-many-requests, -} diff --git a/wit/key-value.wit b/wit/key-value.wit deleted file mode 100644 index a37b1d48..00000000 --- a/wit/key-value.wit +++ /dev/null @@ -1,78 +0,0 @@ -// 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) -> expected - -// 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) -> expected, 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) -> expected - -// 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) -> expected - -// 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) -> expected - -// 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) -> expected, 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/wit/mysql-types.wit b/wit/mysql-types.wit deleted file mode 100644 index a18f5d73..00000000 --- a/wit/mysql-types.wit +++ /dev/null @@ -1,10 +0,0 @@ -// General purpose error. -// TODO: We can provide richer info than this: https://docs.rs/mysql/latest/mysql/error/enum.Error.html -variant mysql-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) -} diff --git a/wit/outbound-mysql.wit b/wit/outbound-mysql.wit deleted file mode 100644 index 8cd07277..00000000 --- a/wit/outbound-mysql.wit +++ /dev/null @@ -1,8 +0,0 @@ -use * from mysql-types -use * from rdbms-types - -// query the database: select -query: func(address: string, statement: string, params: list) -> expected - -// execute command to the database: insert, update, delete -execute: func(address: string, statement: string, params: list) -> expected diff --git a/wit/outbound-pg.wit b/wit/outbound-pg.wit deleted file mode 100644 index 94a7c799..00000000 --- a/wit/outbound-pg.wit +++ /dev/null @@ -1,8 +0,0 @@ -use * from pg-types -use * from rdbms-types - -// query the database: select -query: func(address: string, statement: string, params: list) -> expected - -// execute command to the database: insert, update, delete -execute: func(address: string, statement: string, params: list) -> expected diff --git a/wit/outbound-redis.wit b/wit/outbound-redis.wit deleted file mode 100644 index 5a7cbd4c..00000000 --- a/wit/outbound-redis.wit +++ /dev/null @@ -1,29 +0,0 @@ -use * from redis-types - -// Publish a Redis message to the specificed channel and return an error, if any. -publish: func(address: string, channel: string, payload: payload) -> expected - -// Get the value of a key. -get: func(address: string, key: string) -> expected - -// Set key to value. If key alreads holds a value, it is overwritten. -set: func(address: string, key: string, value: payload) -> expected - -// 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) -> expected - -// Removes the specified keys. A key is ignored if it does not exist. -del: func(address: string, keys: list) -> expected - -// Add the specified `values` to the set named `key`, returning the number of newly-added values. -sadd: func(address: string, key: string, values: list) -> expected - -// Retrieve the contents of the set named `key`. -smembers: func(address: string, key: string) -> expected, 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) -> expected - -// Execute an arbitrary Redis command and receive the result. -execute: func(address: string, command: string, arguments: list) -> expected, error> diff --git a/wit/pg-types.wit b/wit/pg-types.wit deleted file mode 100644 index 8e0336b6..00000000 --- a/wit/pg-types.wit +++ /dev/null @@ -1,9 +0,0 @@ -// General purpose error. -variant pg-error { - success, - connection-failed(string), - bad-parameter(string), - query-failed(string), - value-conversion-failed(string), - other-error(string) -} diff --git a/wit/rdbms-types.wit b/wit/rdbms-types.wit deleted file mode 100644 index 393479ae..00000000 --- a/wit/rdbms-types.wit +++ /dev/null @@ -1,63 +0,0 @@ -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/wit/redis-types.wit b/wit/redis-types.wit deleted file mode 100644 index 2f45ddff..00000000 --- a/wit/redis-types.wit +++ /dev/null @@ -1,22 +0,0 @@ -// 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/wit/spin-config.wit b/wit/spin-config.wit deleted file mode 100644 index d4788522..00000000 --- a/wit/spin-config.wit +++ /dev/null @@ -1,10 +0,0 @@ -// 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) -> expected - -variant error { - provider(string), - invalid-key(string), - invalid-schema(string), - other(string), -} \ No newline at end of file diff --git a/wit/spin-http.wit b/wit/spin-http.wit deleted file mode 100644 index 27da7427..00000000 --- a/wit/spin-http.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from http-types - -// The entrypoint for an HTTP handler. -handle-http-request: func(req: request) -> response diff --git a/wit/spin-redis.wit b/wit/spin-redis.wit deleted file mode 100644 index c51c3b47..00000000 --- a/wit/spin-redis.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from redis-types - -// The entrypoint for a Redis handler. -handle-redis-message: func(message: payload) -> expected diff --git a/wit/sqlite.wit b/wit/sqlite.wit deleted file mode 100644 index 8bf9384b..00000000 --- a/wit/sqlite.wit +++ /dev/null @@ -1,50 +0,0 @@ -// 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(name: string) -> expected - -// Execute a statement -execute: func(conn: connection, statement: string, parameters: list) -> expected - -// 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/wit/wasi-outbound-http.wit b/wit/wasi-outbound-http.wit deleted file mode 100644 index 0502129d..00000000 --- a/wit/wasi-outbound-http.wit +++ /dev/null @@ -1,4 +0,0 @@ -use * from http-types - -// Send an HTTP request and return a response or a potential error. -request: func(req: request) -> expected diff --git a/v3/wit/wit.go b/wit/wit.go similarity index 100% rename from v3/wit/wit.go rename to wit/wit.go diff --git a/v3/wit/world.wit b/wit/world.wit similarity index 100% rename from v3/wit/world.wit rename to wit/world.wit From 9c9da3b86d0d8daf44b2aba54b278bc0c30f690b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 12:35:45 -0600 Subject: [PATCH 15/22] update componentize-go for CI Signed-off-by: Joel Dice --- .github/workflows/build.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 06fa7061..387536bb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,22 +13,19 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Go + - name: Install Go uses: actions/setup-go@v5 with: go-version: '1.25' - - name: Setup componentize-go - run: | - curl -LO https://github.com/bytecodealliance/componentize-go/releases/download/v0.2.0/componentize-go-linux-amd64.tar.gz - echo "27fc32998f023a88a6a1f44524631a705163f23ce2a02fc14987726897360027 componentize-go-linux-amd64.tar.gz" | sha256sum --check - tar -xf componentize-go-linux-amd64.tar.gz - chmod +x componentize-go - mkdir -p $HOME/.local/bin - mv componentize-go $HOME/.local/bin/componentize-go - echo "$HOME/.local/bin" >> $GITHUB_PATH + - name: Install latest Rust stable toolchain + uses: dtolnay/rust-toolchain@stable - - name: Setup Spin + - name: Install componentize-go + # TODO: Switch to pre-built release once new one is available (i.e. post-v0.2.0): + run: cargo install --locked --git https://github.com/bytecodealliance/componentize-go --rev 94413331 + + - name: Install Spin uses: fermyon/actions/spin/setup@v1 with: version: "v3.6.2" From 419156bf1d9c39ee731ee3a0408c2041927e8c43 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 13:03:52 -0600 Subject: [PATCH 16/22] remove unused file Signed-off-by: Joel Dice --- sdk_version/sdk-version-go-template.c | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 sdk_version/sdk-version-go-template.c diff --git a/sdk_version/sdk-version-go-template.c b/sdk_version/sdk-version-go-template.c deleted file mode 100644 index ebddb4b1..00000000 --- a/sdk_version/sdk-version-go-template.c +++ /dev/null @@ -1,14 +0,0 @@ -__attribute__((weak, export_name("spin-sdk-version-{{VERSION}}"))) -void __spin_sdk_version(void) { - -} - -__attribute__((weak, export_name("spin-sdk-language-go"))) -void __spin_sdk_language(void) { - -} - -__attribute__((weak, export_name("spin-sdk-commit-{{COMMIT}}"))) -void __spin_sdk_commit(void) { - -} From d881ce56f6d2b067da1eab82da8689db69abe769 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 13:42:21 -0600 Subject: [PATCH 17/22] move redis_internal to inbound_redis/internal Signed-off-by: Joel Dice --- Makefile | 4 ++-- inbound_redis/inbound_redis.go | 6 +++--- .../export_fermyon_spin_inbound_redis/wit_bindings.go | 2 +- .../internal}/fermyon_spin_config/wit_bindings.go | 0 .../internal}/fermyon_spin_http/wit_bindings.go | 2 +- .../internal}/fermyon_spin_http_types/wit_bindings.go | 0 .../internal}/fermyon_spin_inbound_redis/wit_bindings.go | 2 +- .../internal}/fermyon_spin_key_value/wit_bindings.go | 0 .../internal}/fermyon_spin_llm/wit_bindings.go | 0 .../internal}/fermyon_spin_mysql/wit_bindings.go | 2 +- .../internal}/fermyon_spin_postgres/wit_bindings.go | 2 +- .../internal}/fermyon_spin_rdbms_types/wit_bindings.go | 0 .../internal}/fermyon_spin_redis/wit_bindings.go | 2 +- .../internal}/fermyon_spin_redis_types/wit_bindings.go | 0 .../internal}/fermyon_spin_sqlite/wit_bindings.go | 0 .../internal}/wit_exports/wit_exports.go | 2 +- 16 files changed, 12 insertions(+), 12 deletions(-) rename {redis_internal => inbound_redis/internal}/export_fermyon_spin_inbound_redis/wit_bindings.go (74%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_config/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_http/wit_bindings.go (98%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_http_types/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_inbound_redis/wit_bindings.go (92%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_key_value/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_llm/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_mysql/wit_bindings.go (99%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_postgres/wit_bindings.go (99%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_rdbms_types/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_redis/wit_bindings.go (99%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_redis_types/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/fermyon_spin_sqlite/wit_bindings.go (100%) rename {redis_internal => inbound_redis/internal}/wit_exports/wit_exports.go (95%) diff --git a/Makefile b/Makefile index 8916f6aa..393e7920 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,10 @@ regenerate-bindings: ! -name 'export_wasi_http_0_2_0_incoming_handler' \ -exec rm -rf {} + componentize-go -w http-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal - find $$(pwd)/redis_internal/ \ + find $$(pwd)/inbound_redis/internal/ \ -mindepth 1 \ -maxdepth 1 \ -type d \ ! -name 'export_fermyon_spin_inbound_redis' \ -exec rm -rf {} + - componentize-go -w fermyon:spin/redis-trigger -d ./wit bindings --format -o redis_internal --pkg-name github.com/spinframework/spin-go-sdk/v3/redis_internal + componentize-go -w fermyon:spin/redis-trigger -d ./wit bindings --format -o inbound_redis/internal --pkg-name github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal diff --git a/inbound_redis/inbound_redis.go b/inbound_redis/inbound_redis.go index 16d492ef..e826f438 100644 --- a/inbound_redis/inbound_redis.go +++ b/inbound_redis/inbound_redis.go @@ -3,9 +3,9 @@ package inbound_redis import ( - incominghandler "github.com/spinframework/spin-go-sdk/v3/redis_internal/export_fermyon_spin_inbound_redis" - redis_types "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" - _ "github.com/spinframework/spin-go-sdk/v3/redis_internal/wit_exports" + incominghandler "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/export_fermyon_spin_inbound_redis" + redis_types "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" + _ "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/wit_exports" wit_dir "github.com/spinframework/spin-go-sdk/v3/wit" wit "go.bytecodealliance.org/pkg/wit/types" ) diff --git a/redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go b/inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go similarity index 74% rename from redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go rename to inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go index 3cf5b75b..0ebebfe3 100644 --- a/redis_internal/export_fermyon_spin_inbound_redis/wit_bindings.go +++ b/inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go @@ -1,7 +1,7 @@ package export_fermyon_spin_inbound_redis import ( - redis_types "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + redis_types "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" wit "go.bytecodealliance.org/pkg/wit/types" ) diff --git a/redis_internal/fermyon_spin_config/wit_bindings.go b/inbound_redis/internal/fermyon_spin_config/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_config/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_config/wit_bindings.go diff --git a/redis_internal/fermyon_spin_http/wit_bindings.go b/inbound_redis/internal/fermyon_spin_http/wit_bindings.go similarity index 98% rename from redis_internal/fermyon_spin_http/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_http/wit_bindings.go index b3585e87..5d66e657 100644 --- a/redis_internal/fermyon_spin_http/wit_bindings.go +++ b/inbound_redis/internal/fermyon_spin_http/wit_bindings.go @@ -32,7 +32,7 @@ package fermyon_spin_http import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_http_types" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_http_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/redis_internal/fermyon_spin_http_types/wit_bindings.go b/inbound_redis/internal/fermyon_spin_http_types/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_http_types/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_http_types/wit_bindings.go diff --git a/redis_internal/fermyon_spin_inbound_redis/wit_bindings.go b/inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go similarity index 92% rename from redis_internal/fermyon_spin_inbound_redis/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go index c30e3dc9..868579ae 100644 --- a/redis_internal/fermyon_spin_inbound_redis/wit_bindings.go +++ b/inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go @@ -32,7 +32,7 @@ package fermyon_spin_inbound_redis import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" ) type Payload = []uint8 diff --git a/redis_internal/fermyon_spin_key_value/wit_bindings.go b/inbound_redis/internal/fermyon_spin_key_value/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_key_value/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_key_value/wit_bindings.go diff --git a/redis_internal/fermyon_spin_llm/wit_bindings.go b/inbound_redis/internal/fermyon_spin_llm/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_llm/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_llm/wit_bindings.go diff --git a/redis_internal/fermyon_spin_mysql/wit_bindings.go b/inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go similarity index 99% rename from redis_internal/fermyon_spin_mysql/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go index acbd257e..801c2430 100644 --- a/redis_internal/fermyon_spin_mysql/wit_bindings.go +++ b/inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go @@ -32,7 +32,7 @@ package fermyon_spin_mysql import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_rdbms_types" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_rdbms_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/redis_internal/fermyon_spin_postgres/wit_bindings.go b/inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go similarity index 99% rename from redis_internal/fermyon_spin_postgres/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go index 730bb1d4..cfbf9494 100644 --- a/redis_internal/fermyon_spin_postgres/wit_bindings.go +++ b/inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go @@ -32,7 +32,7 @@ package fermyon_spin_postgres import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_rdbms_types" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_rdbms_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/redis_internal/fermyon_spin_rdbms_types/wit_bindings.go b/inbound_redis/internal/fermyon_spin_rdbms_types/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_rdbms_types/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_rdbms_types/wit_bindings.go diff --git a/redis_internal/fermyon_spin_redis/wit_bindings.go b/inbound_redis/internal/fermyon_spin_redis/wit_bindings.go similarity index 99% rename from redis_internal/fermyon_spin_redis/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_redis/wit_bindings.go index 1e97392d..2e34caf5 100644 --- a/redis_internal/fermyon_spin_redis/wit_bindings.go +++ b/inbound_redis/internal/fermyon_spin_redis/wit_bindings.go @@ -32,7 +32,7 @@ package fermyon_spin_redis import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/fermyon_spin_redis_types" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/redis_internal/fermyon_spin_redis_types/wit_bindings.go b/inbound_redis/internal/fermyon_spin_redis_types/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_redis_types/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_redis_types/wit_bindings.go diff --git a/redis_internal/fermyon_spin_sqlite/wit_bindings.go b/inbound_redis/internal/fermyon_spin_sqlite/wit_bindings.go similarity index 100% rename from redis_internal/fermyon_spin_sqlite/wit_bindings.go rename to inbound_redis/internal/fermyon_spin_sqlite/wit_bindings.go diff --git a/redis_internal/wit_exports/wit_exports.go b/inbound_redis/internal/wit_exports/wit_exports.go similarity index 95% rename from redis_internal/wit_exports/wit_exports.go rename to inbound_redis/internal/wit_exports/wit_exports.go index f602e8b8..a0df3a82 100644 --- a/redis_internal/wit_exports/wit_exports.go +++ b/inbound_redis/internal/wit_exports/wit_exports.go @@ -32,7 +32,7 @@ package wit_exports import ( - "github.com/spinframework/spin-go-sdk/v3/redis_internal/export_fermyon_spin_inbound_redis" + "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/export_fermyon_spin_inbound_redis" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" From 4e50c992de3499cb168ff52a5a4656e906903be0 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 13:53:10 -0600 Subject: [PATCH 18/22] s/tinygo/Go/ in redis-outbound example Signed-off-by: Joel Dice --- examples/redis-outbound/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/redis-outbound/main.go b/examples/redis-outbound/main.go index 3c0a431b..2a09a371 100644 --- a/examples/redis-outbound/main.go +++ b/examples/redis-outbound/main.go @@ -26,7 +26,7 @@ func init() { channel := os.Getenv("REDIS_CHANNEL") // payload is the data publish to the redis channel. - payload := []byte(`Hello redis from tinygo!`) + payload := []byte(`Hello redis from Go!`) rdb, err := redis.NewClient(addr) if err != nil { From e4867dc69d8b387d6063ce386e12302ad3c005a6 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 25 Mar 2026 17:37:17 -0600 Subject: [PATCH 19/22] update `componentize-go` and make use of new features Per https://github.com/bytecodealliance/componentize-go/pull/35, Spin applications can now refer to WIT files by way of the `github.com/spinframework/spin-go-sdk/v3` source package; no need for the application to supply them itself. That PR also allows us to pass multiple `--world` flags to `componentize-go`, allowing us to target e.g. the `fermyon:spin/redis-trigger` _and_ `spin:up/platform` worlds at the same time (which is what Spin actually implements for Redis triggers). Signed-off-by: Joel Dice --- .github/workflows/build.yml | 6 +- Makefile | 10 +-- examples/http-outbound/README.md | 4 +- examples/http-outbound/spin.toml | 4 +- examples/http-router/spin.toml | 2 +- examples/http/spin.toml | 2 +- examples/key-value/spin.toml | 2 +- examples/llm/spin.toml | 2 +- examples/mqtt-outbound/spin.toml | 2 +- examples/mysql-outbound/spin.toml | 2 +- examples/pg-outbound/spin.toml | 2 +- examples/redis-outbound/spin.toml | 2 +- examples/redis/main.go | 6 +- examples/redis/spin.toml | 2 +- examples/sqlite/spin.toml | 2 +- examples/variables/go.mod | 6 +- examples/variables/go.sum | 2 + examples/variables/spin.toml | 2 +- http/http.go | 4 -- http/testdata/http/spin.toml | 2 +- inbound_redis/inbound_redis.go | 25 ------- .../internal/wit_exports/wit_exports.go | 68 ------------------- .../wit_bindings.go | 2 +- .../wit_bindings.go | 1 + .../fermyon_spin_2_0_0_llm/wit_bindings.go | 1 + .../fermyon_spin_2_0_0_mqtt/wit_bindings.go | 1 + .../fermyon_spin_2_0_0_mysql/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../fermyon_spin_2_0_0_redis/wit_bindings.go | 1 + .../fermyon_spin_2_0_0_sqlite/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../fermyon_spin_config/wit_bindings.go | 1 + .../fermyon_spin_http/wit_bindings.go | 3 +- .../fermyon_spin_http_types/wit_bindings.go | 1 + .../wit_bindings.go | 3 +- .../fermyon_spin_key_value/wit_bindings.go | 1 + .../fermyon_spin_llm/wit_bindings.go | 1 + .../fermyon_spin_mysql/wit_bindings.go | 3 +- .../fermyon_spin_postgres/wit_bindings.go | 3 +- .../fermyon_spin_rdbms_types/wit_bindings.go | 1 + .../fermyon_spin_redis/wit_bindings.go | 3 +- .../fermyon_spin_redis_types/wit_bindings.go | 1 + .../fermyon_spin_sqlite/wit_bindings.go | 1 + .../spin_postgres_postgres/wit_bindings.go | 1 + .../wit_bindings.go | 1 + internal/wasi_cli_0_2_0_exit/wit_bindings.go | 1 + .../wasi_cli_0_2_0_stderr/wit_bindings.go | 1 + internal/wasi_cli_0_2_0_stdin/wit_bindings.go | 1 + .../wasi_cli_0_2_0_stdout/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + internal/wasi_config_store/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wasi_http_0_2_0_types/wit_bindings.go | 1 + internal/wasi_io_0_2_0_error/wit_bindings.go | 1 + internal/wasi_io_0_2_0_poll/wit_bindings.go | 1 + .../wasi_io_0_2_0_streams/wit_bindings.go | 1 + .../wasi_keyvalue_atomics/wit_bindings.go | 1 + internal/wasi_keyvalue_batch/wit_bindings.go | 1 + internal/wasi_keyvalue_store/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wasi_random_0_2_0_random/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wasi_sockets_0_2_0_tcp/wit_bindings.go | 1 + .../wit_bindings.go | 1 + .../wasi_sockets_0_2_0_udp/wit_bindings.go | 1 + .../wit_bindings.go | 1 + internal/wit_exports/wit_exports.go | 30 +++++++- kv/testdata/key-value/spin.toml | 2 +- redis/redis.go | 18 ++++- variables/testdata/variables/spin.toml | 2 +- wit/wit.go | 6 -- 84 files changed, 142 insertions(+), 143 deletions(-) delete mode 100644 inbound_redis/inbound_redis.go delete mode 100644 inbound_redis/internal/wit_exports/wit_exports.go rename {inbound_redis/internal => internal}/export_fermyon_spin_inbound_redis/wit_bindings.go (74%) rename {inbound_redis/internal => internal}/fermyon_spin_config/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_http/wit_bindings.go (98%) rename {inbound_redis/internal => internal}/fermyon_spin_http_types/wit_bindings.go (98%) rename {inbound_redis/internal => internal}/fermyon_spin_inbound_redis/wit_bindings.go (91%) rename {inbound_redis/internal => internal}/fermyon_spin_key_value/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_llm/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_mysql/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_postgres/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_rdbms_types/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_redis/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_redis_types/wit_bindings.go (99%) rename {inbound_redis/internal => internal}/fermyon_spin_sqlite/wit_bindings.go (99%) delete mode 100644 wit/wit.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 387536bb..2eb1e48f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,8 +22,10 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Install componentize-go - # TODO: Switch to pre-built release once new one is available (i.e. post-v0.2.0): - run: cargo install --locked --git https://github.com/bytecodealliance/componentize-go --rev 94413331 + # TODO: Switch to an upstream (pre-built) release once new one is + # available and includes + # https://github.com/bytecodealliance/componentize-go/pull/35 + run: cargo install --locked --git https://github.com/dicej/componentize-go --rev aa2645d2 - name: Install Spin uses: fermyon/actions/spin/setup@v1 diff --git a/Makefile b/Makefile index 393e7920..0dbf25b0 100644 --- a/Makefile +++ b/Makefile @@ -13,13 +13,7 @@ regenerate-bindings: -maxdepth 1 \ -type d \ ! -name 'db' \ - ! -name 'export_wasi_http_0_2_0_incoming_handler' \ - -exec rm -rf {} + - componentize-go -w http-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal - find $$(pwd)/inbound_redis/internal/ \ - -mindepth 1 \ - -maxdepth 1 \ - -type d \ ! -name 'export_fermyon_spin_inbound_redis' \ + ! -name 'export_wasi_http_0_2_0_incoming_handler' \ -exec rm -rf {} + - componentize-go -w fermyon:spin/redis-trigger -d ./wit bindings --format -o inbound_redis/internal --pkg-name github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal + componentize-go -w http-trigger -w fermyon:spin/redis-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal diff --git a/examples/http-outbound/README.md b/examples/http-outbound/README.md index df6eeda6..ab53f28b 100644 --- a/examples/http-outbound/README.md +++ b/examples/http-outbound/README.md @@ -10,9 +10,9 @@ Building this as a WebAssembly module can be done using `spin build`: ```shell $ spin build -Building component http-to-same-app with `componentize-go --world http-trigger --wit-path ../../../wit build` +Building component http-to-same-app with `componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build` Working directory: "./http-to-same-app" -Building component hello with `componentize-go --world http-trigger --wit-path ../../../wit build` +Building component hello with `componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build` Working directory: "./hello" Finished building all Spin components ``` diff --git a/examples/http-outbound/spin.toml b/examples/http-outbound/spin.toml index 13e229c6..582ca264 100644 --- a/examples/http-outbound/spin.toml +++ b/examples/http-outbound/spin.toml @@ -22,7 +22,7 @@ allowed_outbound_hosts = [ ] [component.hello.build] workdir = "hello" -command = "componentize-go --world http-trigger --wit-path ../../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" [component.http-to-same-app] source = "http-to-same-app/main.wasm" @@ -30,5 +30,5 @@ source = "http-to-same-app/main.wasm" allowed_outbound_hosts = ["http://self"] [component.http-to-same-app.build] workdir = "http-to-same-app" -command = "componentize-go --world http-trigger --wit-path ../../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/examples/http-router/spin.toml b/examples/http-router/spin.toml index ea8bf97c..93904713 100644 --- a/examples/http-router/spin.toml +++ b/examples/http-router/spin.toml @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/examples/http/spin.toml b/examples/http/spin.toml index cf19e967..fd4e6a3c 100644 --- a/examples/http/spin.toml +++ b/examples/http/spin.toml @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/examples/key-value/spin.toml b/examples/key-value/spin.toml index 411c95be..76a55e84 100644 --- a/examples/key-value/spin.toml +++ b/examples/key-value/spin.toml @@ -14,4 +14,4 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/examples/llm/spin.toml b/examples/llm/spin.toml index 32cf0545..2655efa6 100644 --- a/examples/llm/spin.toml +++ b/examples/llm/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] ai_models = ["llama2-chat", "all-minilm-l6-v2"] [component.llm.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/mqtt-outbound/spin.toml b/examples/mqtt-outbound/spin.toml index aa91dadc..3e1a9a1b 100644 --- a/examples/mqtt-outbound/spin.toml +++ b/examples/mqtt-outbound/spin.toml @@ -16,5 +16,5 @@ source = "main.wasm" environment = { MQTT_ADDRESS = "mqtt://127.0.0.1:1883?client_id=client001", MQTT_USERNAME = "user", MQTT_PASSWORD = "password", MQTT_KEEP_ALIVE_INTERVAL = "30", MQTT_TOPIC = "telemetry" } allowed_outbound_hosts = ["mqtt://127.0.0.1:1883"] [component.mqtt-outbound.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/mysql-outbound/spin.toml b/examples/mysql-outbound/spin.toml index a9b7233b..a86d8544 100644 --- a/examples/mysql-outbound/spin.toml +++ b/examples/mysql-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } source = "main.wasm" allowed_outbound_hosts = ["mysql://127.0.0.1"] [component.mysql.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/pg-outbound/spin.toml b/examples/pg-outbound/spin.toml index a14edc58..900c2b40 100644 --- a/examples/pg-outbound/spin.toml +++ b/examples/pg-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "host=localhost user=postgres dbname=spin_dev" } source = "main.wasm" allowed_outbound_hosts = ["postgres://localhost"] [component.pg-outbound.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/redis-outbound/spin.toml b/examples/redis-outbound/spin.toml index c8b314af..c478c033 100644 --- a/examples/redis-outbound/spin.toml +++ b/examples/redis-outbound/spin.toml @@ -16,5 +16,5 @@ environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messa allowed_outbound_hosts = ["redis://localhost:6379"] [component.redis-outbound.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/redis/main.go b/examples/redis/main.go index 4c22eec4..32511798 100644 --- a/examples/redis/main.go +++ b/examples/redis/main.go @@ -3,12 +3,12 @@ package main import ( "fmt" - "github.com/spinframework/spin-go-sdk/v3/inbound_redis" + "github.com/spinframework/spin-go-sdk/v3/redis" ) func init() { - // inbound_redis.Handle() must be called in the init() function. - inbound_redis.Handle(func(payload []byte) error { + // redis.Handle() must be called in the init() function. + redis.Handle(func(payload []byte) error { fmt.Println("Payload::::") fmt.Println(string(payload)) return nil diff --git a/examples/redis/spin.toml b/examples/redis/spin.toml index 01f141b9..e845c3c2 100644 --- a/examples/redis/spin.toml +++ b/examples/redis/spin.toml @@ -16,5 +16,5 @@ component = "echo-message" [component.echo-message] source = "main.wasm" [component.echo-message.build] -command = "componentize-go --world fermyon:spin/redis-trigger --wit-path ../../wit build" +command = "componentize-go --world fermyon:spin/redis-trigger --world platform --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/examples/sqlite/spin.toml b/examples/sqlite/spin.toml index 144700c4..851e796d 100644 --- a/examples/sqlite/spin.toml +++ b/examples/sqlite/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] sqlite_databases = ["default"] [component.sqlite.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" watch = ["**/*.go", "go.mod"] diff --git a/examples/variables/go.mod b/examples/variables/go.mod index c85e5eaf..66dc57c4 100644 --- a/examples/variables/go.mod +++ b/examples/variables/go.mod @@ -4,8 +4,12 @@ go 1.25.5 require ( github.com/spinframework/spin-go-sdk/v3 v3.0.0 - github.com/julienschmidt/httprouter v1.3.0 // indirect go.bytecodealliance.org/pkg v0.2.1 ) +require ( + github.com/julienschmidt/httprouter v1.3.0 // indirect + github.com/spinframework/spin-go-sdk/v2 v2.2.1 // indirect +) + replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/variables/go.sum b/examples/variables/go.sum index b5bca15f..a65c29f7 100644 --- a/examples/variables/go.sum +++ b/examples/variables/go.sum @@ -2,5 +2,7 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/spinframework/spin-go-sdk/v2 v2.2.1 h1:ceAbRU+D3xmyZ8ScDLeFoT763ikFIUEmSjgsrD11v8k= +github.com/spinframework/spin-go-sdk/v2 v2.2.1/go.mod h1:vocVZB4qlTG8C5yoliKIAJCuv4x7sqK0GmVkWeD9N/A= go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/variables/spin.toml b/examples/variables/spin.toml index a42df893..512d00f5 100644 --- a/examples/variables/spin.toml +++ b/examples/variables/spin.toml @@ -19,4 +19,4 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "componentize-go --world http-trigger --wit-path ../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/http/http.go b/http/http.go index 15d0ad67..a8265ef3 100644 --- a/http/http.go +++ b/http/http.go @@ -11,12 +11,8 @@ import ( incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" types "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" _ "github.com/spinframework/spin-go-sdk/v3/internal/wit_exports" - "github.com/spinframework/spin-go-sdk/v3/wit" ) -// force wit files to be shipped with sdk dependency -var _ = wit.Wit - func init() { incominghandler.Exports.Handle = wasiHandle } diff --git a/http/testdata/http/spin.toml b/http/testdata/http/spin.toml index c635e8c6..3ad26434 100644 --- a/http/testdata/http/spin.toml +++ b/http/testdata/http/spin.toml @@ -13,5 +13,5 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/inbound_redis/inbound_redis.go b/inbound_redis/inbound_redis.go deleted file mode 100644 index e826f438..00000000 --- a/inbound_redis/inbound_redis.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package inbound_redis provides a handler for inbound Redis messages - -package inbound_redis - -import ( - incominghandler "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/export_fermyon_spin_inbound_redis" - redis_types "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" - _ "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/wit_exports" - wit_dir "github.com/spinframework/spin-go-sdk/v3/wit" - wit "go.bytecodealliance.org/pkg/wit/types" -) - -// force wit files to be shipped with sdk dependency -var _ = wit_dir.Wit - -func Handle(handle func(message []byte) error) { - incominghandler.Exports.Handle = func(message []byte) wit.Result[wit.Unit, redis_types.Error] { - err := handle(message) - if err == nil { - return wit.Err[wit.Unit, redis_types.Error](redis_types.ErrorError) - } else { - return wit.Ok[wit.Unit, redis_types.Error](wit.Unit{}) - } - } -} diff --git a/inbound_redis/internal/wit_exports/wit_exports.go b/inbound_redis/internal/wit_exports/wit_exports.go deleted file mode 100644 index a0df3a82..00000000 --- a/inbound_redis/internal/wit_exports/wit_exports.go +++ /dev/null @@ -1,68 +0,0 @@ -// Generated by `wit-bindgen` 0.53.1. DO NOT EDIT! -// -// This code was generated from the following packages: -// fermyon:spin -// wasi:io@0.2.0 -// wasi:clocks@0.2.0 -// wasi:random@0.2.0 -// wasi:filesystem@0.2.0 -// wasi:sockets@0.2.0 -// wasi:cli@0.2.0 -// wasi:http@0.2.0 -// wasi:io@0.2.0-rc-2023-10-18 -// wasi:clocks@0.2.0-rc-2023-10-18 -// wasi:random@0.2.0-rc-2023-10-18 -// wasi:filesystem@0.2.0-rc-2023-10-18 -// wasi:sockets@0.2.0-rc-2023-10-18 -// wasi:cli@0.2.0-rc-2023-10-18 -// wasi:http@0.2.0-rc-2023-10-18 -// fermyon:spin@2.0.0 -// wasi:keyvalue@0.2.0-draft2 -// spin:postgres@3.0.0 -// wasi:config@0.2.0-draft-2024-09-27 -// fermyon:spin@3.0.0 -// wasi:io@0.2.0-rc-2023-11-10 -// wasi:clocks@0.2.0-rc-2023-11-10 -// wasi:filesystem@0.2.0-rc-2023-11-10 -// wasi:sockets@0.2.0-rc-2023-11-10 -// wasi:random@0.2.0-rc-2023-11-10 -// wasi:cli@0.2.0-rc-2023-11-10 -// wasi:http@0.2.0-rc-2023-11-10 - -package wit_exports - -import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/export_fermyon_spin_inbound_redis" - witRuntime "go.bytecodealliance.org/pkg/wit/runtime" - witTypes "go.bytecodealliance.org/pkg/wit/types" - "runtime" - "unsafe" -) - -var staticPinner = runtime.Pinner{} -var exportReturnArea = uintptr(witRuntime.Allocate(&staticPinner, 2, 1)) -var syncExportPinner = runtime.Pinner{} - -//go:wasmexport fermyon:spin/inbound-redis#handle-message -func wasm_export_fermyon_spin_inbound_redis_handle_message(arg0 uintptr, arg1 uint32) uintptr { - - value := unsafe.Slice((*uint8)(unsafe.Pointer(arg0)), arg1) - witRuntime.Unpin() - result := export_fermyon_spin_inbound_redis.HandleMessage(value) - - switch result.Tag() { - case witTypes.ResultOk: - - *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(0)) - - case witTypes.ResultErr: - payload := result.Err() - *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(1)) - *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 1)) = int8(int32(payload)) - - default: - panic("unreachable") - } - return exportReturnArea - -} diff --git a/inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go b/internal/export_fermyon_spin_inbound_redis/wit_bindings.go similarity index 74% rename from inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go rename to internal/export_fermyon_spin_inbound_redis/wit_bindings.go index 0ebebfe3..9d10b9b5 100644 --- a/inbound_redis/internal/export_fermyon_spin_inbound_redis/wit_bindings.go +++ b/internal/export_fermyon_spin_inbound_redis/wit_bindings.go @@ -1,7 +1,7 @@ package export_fermyon_spin_inbound_redis import ( - redis_types "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" + redis_types "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_redis_types" wit "go.bytecodealliance.org/pkg/wit/types" ) diff --git a/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go b/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go index 116aca92..f463a80e 100644 --- a/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_key_value/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_key_value diff --git a/internal/fermyon_spin_2_0_0_llm/wit_bindings.go b/internal/fermyon_spin_2_0_0_llm/wit_bindings.go index ea3ac826..ffe5b8fb 100644 --- a/internal/fermyon_spin_2_0_0_llm/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_llm/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_llm diff --git a/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go b/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go index feb44c81..b4318091 100644 --- a/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_mqtt/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_mqtt diff --git a/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go b/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go index 2831dd3c..ed7fdb65 100644 --- a/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_mysql/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_mysql diff --git a/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go b/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go index 43e448e9..bbc4bd35 100644 --- a/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_postgres/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_postgres diff --git a/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go b/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go index 89d06119..55cb3bb2 100644 --- a/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_rdbms_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_rdbms_types diff --git a/internal/fermyon_spin_2_0_0_redis/wit_bindings.go b/internal/fermyon_spin_2_0_0_redis/wit_bindings.go index a50912a3..5b56e8af 100644 --- a/internal/fermyon_spin_2_0_0_redis/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_redis/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_redis diff --git a/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go b/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go index 0afd122a..cea653f3 100644 --- a/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_sqlite/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_sqlite diff --git a/internal/fermyon_spin_2_0_0_variables/wit_bindings.go b/internal/fermyon_spin_2_0_0_variables/wit_bindings.go index b5fc6e1c..93ee5451 100644 --- a/internal/fermyon_spin_2_0_0_variables/wit_bindings.go +++ b/internal/fermyon_spin_2_0_0_variables/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_2_0_0_variables diff --git a/inbound_redis/internal/fermyon_spin_config/wit_bindings.go b/internal/fermyon_spin_config/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_config/wit_bindings.go rename to internal/fermyon_spin_config/wit_bindings.go index 3a22bad4..4935e77a 100644 --- a/inbound_redis/internal/fermyon_spin_config/wit_bindings.go +++ b/internal/fermyon_spin_config/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_config diff --git a/inbound_redis/internal/fermyon_spin_http/wit_bindings.go b/internal/fermyon_spin_http/wit_bindings.go similarity index 98% rename from inbound_redis/internal/fermyon_spin_http/wit_bindings.go rename to internal/fermyon_spin_http/wit_bindings.go index 5d66e657..ab485e1a 100644 --- a/inbound_redis/internal/fermyon_spin_http/wit_bindings.go +++ b/internal/fermyon_spin_http/wit_bindings.go @@ -28,11 +28,12 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_http import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_http_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_http_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/inbound_redis/internal/fermyon_spin_http_types/wit_bindings.go b/internal/fermyon_spin_http_types/wit_bindings.go similarity index 98% rename from inbound_redis/internal/fermyon_spin_http_types/wit_bindings.go rename to internal/fermyon_spin_http_types/wit_bindings.go index df90da65..48efbe47 100644 --- a/inbound_redis/internal/fermyon_spin_http_types/wit_bindings.go +++ b/internal/fermyon_spin_http_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_http_types diff --git a/inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go b/internal/fermyon_spin_inbound_redis/wit_bindings.go similarity index 91% rename from inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go rename to internal/fermyon_spin_inbound_redis/wit_bindings.go index 868579ae..98492a17 100644 --- a/inbound_redis/internal/fermyon_spin_inbound_redis/wit_bindings.go +++ b/internal/fermyon_spin_inbound_redis/wit_bindings.go @@ -28,11 +28,12 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_inbound_redis import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_redis_types" ) type Payload = []uint8 diff --git a/inbound_redis/internal/fermyon_spin_key_value/wit_bindings.go b/internal/fermyon_spin_key_value/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_key_value/wit_bindings.go rename to internal/fermyon_spin_key_value/wit_bindings.go index 22c77c2e..72881e36 100644 --- a/inbound_redis/internal/fermyon_spin_key_value/wit_bindings.go +++ b/internal/fermyon_spin_key_value/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_key_value diff --git a/inbound_redis/internal/fermyon_spin_llm/wit_bindings.go b/internal/fermyon_spin_llm/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_llm/wit_bindings.go rename to internal/fermyon_spin_llm/wit_bindings.go index a3a518ee..536cd28f 100644 --- a/inbound_redis/internal/fermyon_spin_llm/wit_bindings.go +++ b/internal/fermyon_spin_llm/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_llm diff --git a/inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go b/internal/fermyon_spin_mysql/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go rename to internal/fermyon_spin_mysql/wit_bindings.go index 801c2430..141f38ae 100644 --- a/inbound_redis/internal/fermyon_spin_mysql/wit_bindings.go +++ b/internal/fermyon_spin_mysql/wit_bindings.go @@ -28,11 +28,12 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_mysql import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_rdbms_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_rdbms_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go b/internal/fermyon_spin_postgres/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go rename to internal/fermyon_spin_postgres/wit_bindings.go index cfbf9494..31424ed2 100644 --- a/inbound_redis/internal/fermyon_spin_postgres/wit_bindings.go +++ b/internal/fermyon_spin_postgres/wit_bindings.go @@ -28,11 +28,12 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_postgres import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_rdbms_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_rdbms_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/inbound_redis/internal/fermyon_spin_rdbms_types/wit_bindings.go b/internal/fermyon_spin_rdbms_types/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_rdbms_types/wit_bindings.go rename to internal/fermyon_spin_rdbms_types/wit_bindings.go index 656259a3..da16fa0c 100644 --- a/inbound_redis/internal/fermyon_spin_rdbms_types/wit_bindings.go +++ b/internal/fermyon_spin_rdbms_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_rdbms_types diff --git a/inbound_redis/internal/fermyon_spin_redis/wit_bindings.go b/internal/fermyon_spin_redis/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_redis/wit_bindings.go rename to internal/fermyon_spin_redis/wit_bindings.go index 2e34caf5..359fd54c 100644 --- a/inbound_redis/internal/fermyon_spin_redis/wit_bindings.go +++ b/internal/fermyon_spin_redis/wit_bindings.go @@ -28,11 +28,12 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_redis import ( - "github.com/spinframework/spin-go-sdk/v3/inbound_redis/internal/fermyon_spin_redis_types" + "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_redis_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" diff --git a/inbound_redis/internal/fermyon_spin_redis_types/wit_bindings.go b/internal/fermyon_spin_redis_types/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_redis_types/wit_bindings.go rename to internal/fermyon_spin_redis_types/wit_bindings.go index 74955910..e9803f3b 100644 --- a/inbound_redis/internal/fermyon_spin_redis_types/wit_bindings.go +++ b/internal/fermyon_spin_redis_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_redis_types diff --git a/inbound_redis/internal/fermyon_spin_sqlite/wit_bindings.go b/internal/fermyon_spin_sqlite/wit_bindings.go similarity index 99% rename from inbound_redis/internal/fermyon_spin_sqlite/wit_bindings.go rename to internal/fermyon_spin_sqlite/wit_bindings.go index ca14d91b..a0893809 100644 --- a/inbound_redis/internal/fermyon_spin_sqlite/wit_bindings.go +++ b/internal/fermyon_spin_sqlite/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package fermyon_spin_sqlite diff --git a/internal/spin_postgres_postgres/wit_bindings.go b/internal/spin_postgres_postgres/wit_bindings.go index ff1abe3c..2c5896d3 100644 --- a/internal/spin_postgres_postgres/wit_bindings.go +++ b/internal/spin_postgres_postgres/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package spin_postgres_postgres diff --git a/internal/wasi_cli_0_2_0_environment/wit_bindings.go b/internal/wasi_cli_0_2_0_environment/wit_bindings.go index 300ce98b..821bc125 100644 --- a/internal/wasi_cli_0_2_0_environment/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_environment/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_environment diff --git a/internal/wasi_cli_0_2_0_exit/wit_bindings.go b/internal/wasi_cli_0_2_0_exit/wit_bindings.go index 7ae778c6..802c5f5f 100644 --- a/internal/wasi_cli_0_2_0_exit/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_exit/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_exit diff --git a/internal/wasi_cli_0_2_0_stderr/wit_bindings.go b/internal/wasi_cli_0_2_0_stderr/wit_bindings.go index 067fd0f3..181eeba0 100644 --- a/internal/wasi_cli_0_2_0_stderr/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stderr/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_stderr diff --git a/internal/wasi_cli_0_2_0_stdin/wit_bindings.go b/internal/wasi_cli_0_2_0_stdin/wit_bindings.go index 3dda1091..2918d3f1 100644 --- a/internal/wasi_cli_0_2_0_stdin/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stdin/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_stdin diff --git a/internal/wasi_cli_0_2_0_stdout/wit_bindings.go b/internal/wasi_cli_0_2_0_stdout/wit_bindings.go index 34b5960c..e0c2e410 100644 --- a/internal/wasi_cli_0_2_0_stdout/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_stdout/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_stdout diff --git a/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go index d1503012..222c4cd6 100644 --- a/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_input/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_terminal_input diff --git a/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go index 44cfaa8f..76bac657 100644 --- a/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_output/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_terminal_output diff --git a/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go index 9f93b6b1..e42e0d03 100644 --- a/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stderr/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_terminal_stderr diff --git a/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go index ef7792e7..60a61361 100644 --- a/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stdin/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_terminal_stdin diff --git a/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go b/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go index 838c92b7..261a5ec0 100644 --- a/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go +++ b/internal/wasi_cli_0_2_0_terminal_stdout/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_cli_0_2_0_terminal_stdout diff --git a/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go b/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go index a247cf8c..fce5081a 100644 --- a/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go +++ b/internal/wasi_clocks_0_2_0_monotonic_clock/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_clocks_0_2_0_monotonic_clock diff --git a/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go b/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go index bcd85337..e6810956 100644 --- a/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go +++ b/internal/wasi_clocks_0_2_0_wall_clock/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_clocks_0_2_0_wall_clock diff --git a/internal/wasi_config_store/wit_bindings.go b/internal/wasi_config_store/wit_bindings.go index 63820e2b..45b93e7c 100644 --- a/internal/wasi_config_store/wit_bindings.go +++ b/internal/wasi_config_store/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_config_store diff --git a/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go b/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go index ae00591b..15767056 100644 --- a/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go +++ b/internal/wasi_filesystem_0_2_0_preopens/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_filesystem_0_2_0_preopens diff --git a/internal/wasi_filesystem_0_2_0_types/wit_bindings.go b/internal/wasi_filesystem_0_2_0_types/wit_bindings.go index 749b0d5f..0173f6ee 100644 --- a/internal/wasi_filesystem_0_2_0_types/wit_bindings.go +++ b/internal/wasi_filesystem_0_2_0_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_filesystem_0_2_0_types diff --git a/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go b/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go index f62f2417..a7424149 100644 --- a/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go +++ b/internal/wasi_http_0_2_0_incoming_handler/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_http_0_2_0_incoming_handler diff --git a/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go b/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go index 9ebb5b3e..e75c926a 100644 --- a/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go +++ b/internal/wasi_http_0_2_0_outgoing_handler/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_http_0_2_0_outgoing_handler diff --git a/internal/wasi_http_0_2_0_types/wit_bindings.go b/internal/wasi_http_0_2_0_types/wit_bindings.go index 36de288d..f703a314 100644 --- a/internal/wasi_http_0_2_0_types/wit_bindings.go +++ b/internal/wasi_http_0_2_0_types/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_http_0_2_0_types diff --git a/internal/wasi_io_0_2_0_error/wit_bindings.go b/internal/wasi_io_0_2_0_error/wit_bindings.go index 855d99e7..710ed7b0 100644 --- a/internal/wasi_io_0_2_0_error/wit_bindings.go +++ b/internal/wasi_io_0_2_0_error/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_io_0_2_0_error diff --git a/internal/wasi_io_0_2_0_poll/wit_bindings.go b/internal/wasi_io_0_2_0_poll/wit_bindings.go index 9456635f..112a5542 100644 --- a/internal/wasi_io_0_2_0_poll/wit_bindings.go +++ b/internal/wasi_io_0_2_0_poll/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_io_0_2_0_poll diff --git a/internal/wasi_io_0_2_0_streams/wit_bindings.go b/internal/wasi_io_0_2_0_streams/wit_bindings.go index 59c6791b..a0d3be84 100644 --- a/internal/wasi_io_0_2_0_streams/wit_bindings.go +++ b/internal/wasi_io_0_2_0_streams/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_io_0_2_0_streams diff --git a/internal/wasi_keyvalue_atomics/wit_bindings.go b/internal/wasi_keyvalue_atomics/wit_bindings.go index d49618bc..83749052 100644 --- a/internal/wasi_keyvalue_atomics/wit_bindings.go +++ b/internal/wasi_keyvalue_atomics/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_keyvalue_atomics diff --git a/internal/wasi_keyvalue_batch/wit_bindings.go b/internal/wasi_keyvalue_batch/wit_bindings.go index 285e10f9..92ed39e3 100644 --- a/internal/wasi_keyvalue_batch/wit_bindings.go +++ b/internal/wasi_keyvalue_batch/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_keyvalue_batch diff --git a/internal/wasi_keyvalue_store/wit_bindings.go b/internal/wasi_keyvalue_store/wit_bindings.go index 8d5d5403..fff847a1 100644 --- a/internal/wasi_keyvalue_store/wit_bindings.go +++ b/internal/wasi_keyvalue_store/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_keyvalue_store diff --git a/internal/wasi_random_0_2_0_insecure/wit_bindings.go b/internal/wasi_random_0_2_0_insecure/wit_bindings.go index bea902cb..a6f368bb 100644 --- a/internal/wasi_random_0_2_0_insecure/wit_bindings.go +++ b/internal/wasi_random_0_2_0_insecure/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_random_0_2_0_insecure diff --git a/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go b/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go index 7dac2aea..fe271963 100644 --- a/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go +++ b/internal/wasi_random_0_2_0_insecure_seed/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_random_0_2_0_insecure_seed diff --git a/internal/wasi_random_0_2_0_random/wit_bindings.go b/internal/wasi_random_0_2_0_random/wit_bindings.go index 985fae86..49405a54 100644 --- a/internal/wasi_random_0_2_0_random/wit_bindings.go +++ b/internal/wasi_random_0_2_0_random/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_random_0_2_0_random diff --git a/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go b/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go index 912f0e2c..02caf1ba 100644 --- a/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_instance_network/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_instance_network diff --git a/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go b/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go index 1eb1ec32..a1fa42c3 100644 --- a/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_ip_name_lookup/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_ip_name_lookup diff --git a/internal/wasi_sockets_0_2_0_network/wit_bindings.go b/internal/wasi_sockets_0_2_0_network/wit_bindings.go index d791f8cc..16c7a9f6 100644 --- a/internal/wasi_sockets_0_2_0_network/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_network/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_network diff --git a/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go b/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go index 8bdfacbf..90726c9d 100644 --- a/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_tcp/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_tcp diff --git a/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go b/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go index b9b0aca2..b43187f3 100644 --- a/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_tcp_create_socket/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_tcp_create_socket diff --git a/internal/wasi_sockets_0_2_0_udp/wit_bindings.go b/internal/wasi_sockets_0_2_0_udp/wit_bindings.go index a8f9510d..4bf25e6e 100644 --- a/internal/wasi_sockets_0_2_0_udp/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_udp/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_udp diff --git a/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go b/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go index 93b61729..c33872c8 100644 --- a/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go +++ b/internal/wasi_sockets_0_2_0_udp_create_socket/wit_bindings.go @@ -28,6 +28,7 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wasi_sockets_0_2_0_udp_create_socket diff --git a/internal/wit_exports/wit_exports.go b/internal/wit_exports/wit_exports.go index a50c6d48..4b1b650d 100644 --- a/internal/wit_exports/wit_exports.go +++ b/internal/wit_exports/wit_exports.go @@ -28,18 +28,22 @@ // wasi:random@0.2.0-rc-2023-11-10 // wasi:cli@0.2.0-rc-2023-11-10 // wasi:http@0.2.0-rc-2023-11-10 +// componentize-go:union package wit_exports import ( + "github.com/spinframework/spin-go-sdk/v3/internal/export_fermyon_spin_inbound_redis" "github.com/spinframework/spin-go-sdk/v3/internal/export_wasi_http_0_2_0_incoming_handler" "github.com/spinframework/spin-go-sdk/v3/internal/wasi_http_0_2_0_types" witRuntime "go.bytecodealliance.org/pkg/wit/runtime" + witTypes "go.bytecodealliance.org/pkg/wit/types" "runtime" + "unsafe" ) var staticPinner = runtime.Pinner{} -var exportReturnArea = uintptr(witRuntime.Allocate(&staticPinner, 0, 1)) +var exportReturnArea = uintptr(witRuntime.Allocate(&staticPinner, 2, 1)) var syncExportPinner = runtime.Pinner{} //go:wasmexport wasi:http/incoming-handler@0.2.0#handle @@ -48,3 +52,27 @@ func wasm_export_wasi_http_0_2_0_incoming_handler_handle(arg0 int32, arg1 int32) export_wasi_http_0_2_0_incoming_handler.Handle(wasi_http_0_2_0_types.IncomingRequestFromOwnHandle(int32(uintptr(arg0))), wasi_http_0_2_0_types.ResponseOutparamFromOwnHandle(int32(uintptr(arg1)))) } + +//go:wasmexport fermyon:spin/inbound-redis#handle-message +func wasm_export_fermyon_spin_inbound_redis_handle_message(arg0 uintptr, arg1 uint32) uintptr { + + value := unsafe.Slice((*uint8)(unsafe.Pointer(arg0)), arg1) + witRuntime.Unpin() + result := export_fermyon_spin_inbound_redis.HandleMessage(value) + + switch result.Tag() { + case witTypes.ResultOk: + + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(0)) + + case witTypes.ResultErr: + payload := result.Err() + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 0)) = int8(int32(1)) + *(*int8)(unsafe.Add(unsafe.Pointer(exportReturnArea), 1)) = int8(int32(payload)) + + default: + panic("unreachable") + } + return exportReturnArea + +} diff --git a/kv/testdata/key-value/spin.toml b/kv/testdata/key-value/spin.toml index b9a7e2d3..26c92357 100644 --- a/kv/testdata/key-value/spin.toml +++ b/kv/testdata/key-value/spin.toml @@ -14,5 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/redis/redis.go b/redis/redis.go index a32a1595..56ac1bea 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -1,13 +1,29 @@ -// Package redis provides access to Redis within Spin components. +// Package redis provides access to Redis within Spin components, as well as a +// handler for inbound Redis messages. package redis import ( "fmt" + incominghandler "github.com/spinframework/spin-go-sdk/v3/internal/export_fermyon_spin_inbound_redis" redis "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_2_0_0_redis" + redis_types "github.com/spinframework/spin-go-sdk/v3/internal/fermyon_spin_redis_types" + _ "github.com/spinframework/spin-go-sdk/v3/internal/wit_exports" + wit "go.bytecodealliance.org/pkg/wit/types" ) +func Handle(handle func(message []byte) error) { + incominghandler.Exports.Handle = func(message []byte) wit.Result[wit.Unit, redis_types.Error] { + err := handle(message) + if err == nil { + return wit.Err[wit.Unit, redis_types.Error](redis_types.ErrorError) + } else { + return wit.Ok[wit.Unit, redis_types.Error](wit.Unit{}) + } + } +} + // Client is a Redis client. type Client struct { conn redis.Connection diff --git a/variables/testdata/variables/spin.toml b/variables/testdata/variables/spin.toml index 7a296939..f7d09438 100644 --- a/variables/testdata/variables/spin.toml +++ b/variables/testdata/variables/spin.toml @@ -19,5 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "componentize-go --world http-trigger --wit-path ../../../wit build" +command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" diff --git a/wit/wit.go b/wit/wit.go deleted file mode 100644 index 30251b11..00000000 --- a/wit/wit.go +++ /dev/null @@ -1,6 +0,0 @@ -package wit - -import "embed" - -//go:embed * -var Wit embed.FS From 5b1210e8373b245c7c62d68fdcdcd4e7a765eaea Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 26 Mar 2026 11:04:00 -0600 Subject: [PATCH 20/22] upgrade `componentize-go` again to further simplify examples and tests Signed-off-by: Joel Dice --- .github/workflows/build.yml | 2 +- Makefile | 10 +++++++++- componentize-go.toml | 2 ++ examples/http-outbound/README.md | 4 ++-- examples/http-outbound/spin.toml | 4 ++-- examples/http-router/spin.toml | 2 +- examples/http/spin.toml | 2 +- examples/key-value/spin.toml | 2 +- examples/llm/spin.toml | 2 +- examples/mqtt-outbound/spin.toml | 2 +- examples/mysql-outbound/spin.toml | 2 +- examples/pg-outbound/spin.toml | 2 +- examples/redis-outbound/spin.toml | 2 +- examples/redis/spin.toml | 2 +- examples/sqlite/spin.toml | 2 +- examples/variables/go.mod | 6 +----- examples/variables/go.sum | 2 -- examples/variables/spin.toml | 2 +- http/testdata/http/spin.toml | 2 +- kv/testdata/key-value/spin.toml | 2 +- variables/testdata/variables/spin.toml | 2 +- 21 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 componentize-go.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2eb1e48f..9728b104 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: # TODO: Switch to an upstream (pre-built) release once new one is # available and includes # https://github.com/bytecodealliance/componentize-go/pull/35 - run: cargo install --locked --git https://github.com/dicej/componentize-go --rev aa2645d2 + run: cargo install --locked --git https://github.com/dicej/componentize-go --rev fad2c00f - name: Install Spin uses: fermyon/actions/spin/setup@v1 diff --git a/Makefile b/Makefile index 0dbf25b0..61f286d0 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,12 @@ regenerate-bindings: ! -name 'export_fermyon_spin_inbound_redis' \ ! -name 'export_wasi_http_0_2_0_incoming_handler' \ -exec rm -rf {} + - componentize-go -w http-trigger -w fermyon:spin/redis-trigger -d ./wit bindings --format -o internal --pkg-name github.com/spinframework/spin-go-sdk/v3/internal + componentize-go \ + --ignore-toml-files \ + -w "fermyon:spin/http-trigger@3.0.0" \ + -w "fermyon:spin/redis-trigger" \ + -d ./wit \ + bindings \ + --format \ + -o internal \ + --pkg-name github.com/spinframework/spin-go-sdk/v3/internal diff --git a/componentize-go.toml b/componentize-go.toml new file mode 100644 index 00000000..7b1985d5 --- /dev/null +++ b/componentize-go.toml @@ -0,0 +1,2 @@ +worlds = [ "fermyon:spin/http-trigger@3.0.0" ] +wit_paths = [ "wit" ] diff --git a/examples/http-outbound/README.md b/examples/http-outbound/README.md index ab53f28b..c99bfdc8 100644 --- a/examples/http-outbound/README.md +++ b/examples/http-outbound/README.md @@ -10,9 +10,9 @@ Building this as a WebAssembly module can be done using `spin build`: ```shell $ spin build -Building component http-to-same-app with `componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build` +Building component http-to-same-app with `componentize-go --world http-trigger build` Working directory: "./http-to-same-app" -Building component hello with `componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build` +Building component hello with `componentize-go --world http-trigger build` Working directory: "./hello" Finished building all Spin components ``` diff --git a/examples/http-outbound/spin.toml b/examples/http-outbound/spin.toml index 582ca264..05764eb7 100644 --- a/examples/http-outbound/spin.toml +++ b/examples/http-outbound/spin.toml @@ -22,7 +22,7 @@ allowed_outbound_hosts = [ ] [component.hello.build] workdir = "hello" -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" [component.http-to-same-app] source = "http-to-same-app/main.wasm" @@ -30,5 +30,5 @@ source = "http-to-same-app/main.wasm" allowed_outbound_hosts = ["http://self"] [component.http-to-same-app.build] workdir = "http-to-same-app" -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/examples/http-router/spin.toml b/examples/http-router/spin.toml index 93904713..162c6c1a 100644 --- a/examples/http-router/spin.toml +++ b/examples/http-router/spin.toml @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/examples/http/spin.toml b/examples/http/spin.toml index fd4e6a3c..c4403dc9 100644 --- a/examples/http/spin.toml +++ b/examples/http/spin.toml @@ -13,4 +13,4 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/examples/key-value/spin.toml b/examples/key-value/spin.toml index 76a55e84..a6c0ecfa 100644 --- a/examples/key-value/spin.toml +++ b/examples/key-value/spin.toml @@ -14,4 +14,4 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/examples/llm/spin.toml b/examples/llm/spin.toml index 2655efa6..bdfe3bb7 100644 --- a/examples/llm/spin.toml +++ b/examples/llm/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] ai_models = ["llama2-chat", "all-minilm-l6-v2"] [component.llm.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/mqtt-outbound/spin.toml b/examples/mqtt-outbound/spin.toml index 3e1a9a1b..ee7f6fef 100644 --- a/examples/mqtt-outbound/spin.toml +++ b/examples/mqtt-outbound/spin.toml @@ -16,5 +16,5 @@ source = "main.wasm" environment = { MQTT_ADDRESS = "mqtt://127.0.0.1:1883?client_id=client001", MQTT_USERNAME = "user", MQTT_PASSWORD = "password", MQTT_KEEP_ALIVE_INTERVAL = "30", MQTT_TOPIC = "telemetry" } allowed_outbound_hosts = ["mqtt://127.0.0.1:1883"] [component.mqtt-outbound.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/mysql-outbound/spin.toml b/examples/mysql-outbound/spin.toml index a86d8544..6c57bd93 100644 --- a/examples/mysql-outbound/spin.toml +++ b/examples/mysql-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "mysql://spin:spin@127.0.0.1/spin_data" } source = "main.wasm" allowed_outbound_hosts = ["mysql://127.0.0.1"] [component.mysql.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/pg-outbound/spin.toml b/examples/pg-outbound/spin.toml index 900c2b40..80005a55 100644 --- a/examples/pg-outbound/spin.toml +++ b/examples/pg-outbound/spin.toml @@ -15,5 +15,5 @@ environment = { DB_URL = "host=localhost user=postgres dbname=spin_dev" } source = "main.wasm" allowed_outbound_hosts = ["postgres://localhost"] [component.pg-outbound.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/redis-outbound/spin.toml b/examples/redis-outbound/spin.toml index c478c033..35066139 100644 --- a/examples/redis-outbound/spin.toml +++ b/examples/redis-outbound/spin.toml @@ -16,5 +16,5 @@ environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messa allowed_outbound_hosts = ["redis://localhost:6379"] [component.redis-outbound.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/redis/spin.toml b/examples/redis/spin.toml index e845c3c2..ca563c15 100644 --- a/examples/redis/spin.toml +++ b/examples/redis/spin.toml @@ -16,5 +16,5 @@ component = "echo-message" [component.echo-message] source = "main.wasm" [component.echo-message.build] -command = "componentize-go --world fermyon:spin/redis-trigger --world platform --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go --world fermyon:spin/redis-trigger build" diff --git a/examples/sqlite/spin.toml b/examples/sqlite/spin.toml index 851e796d..e35e72cf 100644 --- a/examples/sqlite/spin.toml +++ b/examples/sqlite/spin.toml @@ -15,5 +15,5 @@ source = "main.wasm" allowed_outbound_hosts = [] sqlite_databases = ["default"] [component.sqlite.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" watch = ["**/*.go", "go.mod"] diff --git a/examples/variables/go.mod b/examples/variables/go.mod index 66dc57c4..c85e5eaf 100644 --- a/examples/variables/go.mod +++ b/examples/variables/go.mod @@ -4,12 +4,8 @@ go 1.25.5 require ( github.com/spinframework/spin-go-sdk/v3 v3.0.0 - go.bytecodealliance.org/pkg v0.2.1 -) - -require ( github.com/julienschmidt/httprouter v1.3.0 // indirect - github.com/spinframework/spin-go-sdk/v2 v2.2.1 // indirect + go.bytecodealliance.org/pkg v0.2.1 ) replace github.com/spinframework/spin-go-sdk/v3 => ../../ diff --git a/examples/variables/go.sum b/examples/variables/go.sum index a65c29f7..b5bca15f 100644 --- a/examples/variables/go.sum +++ b/examples/variables/go.sum @@ -2,7 +2,5 @@ github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0 h1:fbwpkAm github.com/bytecodealliance/wit-bindgen/crates/go/src/package v0.51.0/go.mod h1:MUXxhOBN0hAtqHjc9/9XAEiXcGhcwYL6PeDXkKwVZN0= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/spinframework/spin-go-sdk/v2 v2.2.1 h1:ceAbRU+D3xmyZ8ScDLeFoT763ikFIUEmSjgsrD11v8k= -github.com/spinframework/spin-go-sdk/v2 v2.2.1/go.mod h1:vocVZB4qlTG8C5yoliKIAJCuv4x7sqK0GmVkWeD9N/A= go.bytecodealliance.org/pkg v0.2.1 h1:TdRagooIcCW3UmlKqVO4cDR3GNDyfDnbiBzGI6TOvyg= go.bytecodealliance.org/pkg v0.2.1/go.mod h1:OjA+V8g3uUFixeCKFfamm6sYhTJdg8fvwEdJ2GO0GSk= diff --git a/examples/variables/spin.toml b/examples/variables/spin.toml index 512d00f5..c289a444 100644 --- a/examples/variables/spin.toml +++ b/examples/variables/spin.toml @@ -19,4 +19,4 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/http/testdata/http/spin.toml b/http/testdata/http/spin.toml index 3ad26434..a951d46c 100644 --- a/http/testdata/http/spin.toml +++ b/http/testdata/http/spin.toml @@ -13,5 +13,5 @@ component = "hello" [component.hello] source = "main.wasm" [component.hello.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/kv/testdata/key-value/spin.toml b/kv/testdata/key-value/spin.toml index 26c92357..16bef71d 100644 --- a/kv/testdata/key-value/spin.toml +++ b/kv/testdata/key-value/spin.toml @@ -14,5 +14,5 @@ component = "hello" source = "main.wasm" key_value_stores = ["default"] [component.hello.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" diff --git a/variables/testdata/variables/spin.toml b/variables/testdata/variables/spin.toml index f7d09438..759589e3 100644 --- a/variables/testdata/variables/spin.toml +++ b/variables/testdata/variables/spin.toml @@ -19,5 +19,5 @@ source = "main.wasm" message = "I'm a {{object}}" [component.variables.build] -command = "componentize-go --world http-trigger --wit-module github.com/spinframework/spin-go-sdk/v3 build" +command = "componentize-go build" From 65425aa8f30e9662843ea244957a52540bcce3e3 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 26 Mar 2026 11:21:19 -0600 Subject: [PATCH 21/22] remove unnecessary WriteHeader statements Signed-off-by: Joel Dice --- examples/http/main.go | 1 - examples/key-value/main.go | 1 - examples/mqtt-outbound/main.go | 1 - http/testdata/http/main.go | 2 -- kv/testdata/key-value/main.go | 1 - 5 files changed, 6 deletions(-) diff --git a/examples/http/main.go b/examples/http/main.go index d3f99656..596779e3 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -12,7 +12,6 @@ func init() { w.Header().Set("Content-Type", "text/plain") w.Header().Set("foo", "bar") - w.WriteHeader(http.StatusOK) fmt.Fprintln(w, "== RESPONSE ==") fmt.Fprintln(w, "Hello spinframework!") fmt.Fprintln(w, "Hello again spinframework!") diff --git a/examples/key-value/main.go b/examples/key-value/main.go index 4cfc8be5..9ac000e8 100644 --- a/examples/key-value/main.go +++ b/examples/key-value/main.go @@ -42,7 +42,6 @@ func init() { w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(keys) }) } diff --git a/examples/mqtt-outbound/main.go b/examples/mqtt-outbound/main.go index 391628f2..c515959c 100644 --- a/examples/mqtt-outbound/main.go +++ b/examples/mqtt-outbound/main.go @@ -38,7 +38,6 @@ func init() { w.Write([]byte(err.Error())) } - w.WriteHeader(200) w.Write([]byte("Message successfully published!\n")) }) } diff --git a/http/testdata/http/main.go b/http/testdata/http/main.go index cc986078..596779e3 100644 --- a/http/testdata/http/main.go +++ b/http/testdata/http/main.go @@ -12,8 +12,6 @@ func init() { 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 spinframework!") fmt.Fprintln(w, "Hello again spinframework!") diff --git a/kv/testdata/key-value/main.go b/kv/testdata/key-value/main.go index 4cfc8be5..9ac000e8 100644 --- a/kv/testdata/key-value/main.go +++ b/kv/testdata/key-value/main.go @@ -42,7 +42,6 @@ func init() { w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(keys) }) } From aca9fe23ad0ae292130690e808e7f5b82e953e04 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 27 Mar 2026 09:45:49 -0600 Subject: [PATCH 22/22] add note to readme about temporary `componentize-go` fork Signed-off-by: Joel Dice --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 32ec181e..20fe9432 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This is an SDK for developing [Spin](https://github.com/spinframework/spin) applications using the Go programming language. +> Note: This SDK temporarily relies on [a fork](https://github.com/dicej/componentize-go) of [componentize-go](https://github.com/bytecodealliance/componentize-go) until [this PR](https://github.com/bytecodealliance/componentize-go/pull/35) has been accepted. For the time being, please install [this build](https://github.com/dicej/componentize-go/releases/tag/canary). + ## Example ```go