Skip to content

Commit 6e6acee

Browse files
authored
Merge pull request #2058 from fermyon/wit-improvements
Wit improvements
2 parents be5b136 + 07ffc2d commit 6e6acee

15 files changed

+368
-10
lines changed

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,34 @@ $(SDK_VERSION_DEST_FILES): $(SDK_VERSION_SOURCE_FILE)
7575
sed -e "s/{{VERSION}}/$${version}/" -e "s/{{COMMIT}}/$${commit}/" < $< > $@
7676

7777
$(GENERATED_SPIN_VARIABLES):
78-
wit-bindgen c --import ../../wit/ephemeral/spin-config.wit --out-dir ./variables
78+
wit-bindgen c --import wit/spin-config.wit --out-dir ./variables
7979

8080
$(GENERATED_OUTBOUND_HTTP):
81-
wit-bindgen c --import ../../wit/ephemeral/wasi-outbound-http.wit --out-dir ./http
81+
wit-bindgen c --import wit/wasi-outbound-http.wit --out-dir ./http
8282

8383
$(GENERATED_SPIN_HTTP):
84-
wit-bindgen c --export ../../wit/ephemeral/spin-http.wit --out-dir ./http
84+
wit-bindgen c --export wit/spin-http.wit --out-dir ./http
8585

8686
$(GENERATED_OUTBOUND_REDIS):
87-
wit-bindgen c --import ../../wit/ephemeral/outbound-redis.wit --out-dir ./redis
87+
wit-bindgen c --import wit/outbound-redis.wit --out-dir ./redis
8888

8989
$(GENERATED_SPIN_REDIS):
90-
wit-bindgen c --export ../../wit/ephemeral/spin-redis.wit --out-dir ./redis
90+
wit-bindgen c --export wit/spin-redis.wit --out-dir ./redis
9191

9292
$(GENERATED_KEY_VALUE):
93-
wit-bindgen c --import ../../wit/ephemeral/key-value.wit --out-dir ./kv
93+
wit-bindgen c --import wit/key-value.wit --out-dir ./kv
9494

9595
$(GENERATED_SQLITE):
96-
wit-bindgen c --import ../../wit/ephemeral/sqlite.wit --out-dir ./sqlite
96+
wit-bindgen c --import wit/sqlite.wit --out-dir ./sqlite
9797

9898
$(GENERATED_LLM):
99-
wit-bindgen c --import ../../wit/ephemeral/llm.wit --out-dir ./llm
99+
wit-bindgen c --import wit/llm.wit --out-dir ./llm
100100

101101
$(GENERATED_OUTBOUND_MYSQL):
102-
wit-bindgen c --import ../../wit/ephemeral/outbound-mysql.wit --out-dir ./mysql
102+
wit-bindgen c --import wit/outbound-mysql.wit --out-dir ./mysql
103103

104104
$(GENERATED_OUTBOUND_PG):
105-
wit-bindgen c --import ../../wit/ephemeral/outbound-pg.wit --out-dir ./pg
105+
wit-bindgen c --import wit/outbound-pg.wit --out-dir ./pg
106106

107107
# ----------------------------------------------------------------------
108108
# Cleanup

wit/http-types.wit

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This is a temporary workaround very similar to https://github.com/deislabs/wasi-experimental-http.
2+
// Once asynchronous functions, streams, and the upstream HTTP API are available, this should be removed.
3+
4+
// The HTTP status code.
5+
// This is currently an unsigned 16-bit integer,
6+
// but it could be represented as an enum containing
7+
// all possible HTTP status codes.
8+
type http-status = u16
9+
10+
// The HTTP body.
11+
// Currently, this is a synchonous byte array, but it should be
12+
// possible to have a stream for both request and response bodies.
13+
type body = list<u8>
14+
15+
// The HTTP headers represented as a list of (name, value) pairs.
16+
type headers = list<tuple<string, string>>
17+
18+
// The HTTP parameter queries, represented as a list of (name, value) pairs.
19+
type params = list<tuple<string, string>>
20+
21+
// The HTTP URI of the current request.
22+
type uri = string
23+
24+
// The HTTP method.
25+
enum method {
26+
get,
27+
post,
28+
put,
29+
delete,
30+
patch,
31+
head,
32+
options,
33+
}
34+
35+
// An HTTP request.
36+
record request {
37+
method: method,
38+
uri: uri,
39+
headers: headers,
40+
params: params,
41+
body: option<body>,
42+
}
43+
44+
// An HTTP response.
45+
record response {
46+
status: http-status,
47+
headers: option<headers>,
48+
body: option<body>,
49+
}
50+
51+
// HTTP errors returned by the runtime.
52+
enum http-error {
53+
success,
54+
destination-not-allowed,
55+
invalid-url,
56+
request-error,
57+
runtime-error,
58+
too-many-requests,
59+
}

wit/key-value.wit

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// A handle to an open key-value store
2+
type store = u32
3+
4+
// The set of errors which may be raised by functions in this interface
5+
variant error {
6+
// Too many stores have been opened simultaneously. Closing one or more
7+
// stores prior to retrying may address this.
8+
store-table-full,
9+
10+
// The host does not recognize the store name requested. Defining and
11+
// configuring a store with that name in a runtime configuration file
12+
// may address this.
13+
no-such-store,
14+
15+
// The requesting component does not have access to the specified store
16+
// (which may or may not exist).
17+
access-denied,
18+
19+
// The store handle provided is not recognized, i.e. it was either never
20+
// opened or has been closed.
21+
invalid-store,
22+
23+
// No key-value tuple exists for the specified key in the specified
24+
// store.
25+
no-such-key,
26+
27+
// Some implementation-specific error has occurred (e.g. I/O)
28+
io(string)
29+
}
30+
31+
// Open the store with the specified name.
32+
//
33+
// If `name` is "default", the default store is opened. Otherwise,
34+
// `name` must refer to a store defined and configured in a runtime
35+
// configuration file supplied with the application.
36+
//
37+
// `error::no-such-store` will be raised if the `name` is not recognized.
38+
open: func(name: string) -> expected<store, error>
39+
40+
// Get the value associated with the specified `key` from the specified
41+
// `store`.
42+
//
43+
// `error::invalid-store` will be raised if `store` is not a valid handle
44+
// to an open store, and `error::no-such-key` will be raised if there is no
45+
// tuple for `key` in `store`.
46+
get: func(store: store, key: string) -> expected<list<u8>, error>
47+
48+
// Set the `value` associated with the specified `key` in the specified
49+
// `store`, overwriting any existing value.
50+
//
51+
// `error::invalid-store` will be raised if `store` is not a valid handle
52+
// to an open store.
53+
set: func(store: store, key: string, value: list<u8>) -> expected<unit, error>
54+
55+
// Delete the tuple with the specified `key` from the specified `store`.
56+
//
57+
// `error::invalid-store` will be raised if `store` is not a valid handle
58+
// to an open store. No error is raised if a tuple did not previously
59+
// exist for `key`.
60+
delete: func(store: store, key: string) -> expected<unit, error>
61+
62+
// Return whether a tuple exists for the specified `key` in the specified
63+
// `store`.
64+
//
65+
// `error::invalid-store` will be raised if `store` is not a valid handle
66+
// to an open store.
67+
exists: func(store: store, key: string) -> expected<bool, error>
68+
69+
// Return a list of all the keys in the specified `store`.
70+
//
71+
// `error::invalid-store` will be raised if `store` is not a valid handle
72+
// to an open store.
73+
get-keys: func(store: store) -> expected<list<string>, error>
74+
75+
// Close the specified `store`.
76+
//
77+
// This has no effect if `store` is not a valid handle to an open store.
78+
close: func(store: store)

wit/mysql-types.wit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// General purpose error.
2+
// TODO: We can provide richer info than this: https://docs.rs/mysql/latest/mysql/error/enum.Error.html
3+
variant mysql-error {
4+
success,
5+
connection-failed(string),
6+
bad-parameter(string),
7+
query-failed(string),
8+
value-conversion-failed(string),
9+
other-error(string)
10+
}

wit/outbound-mysql.wit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use * from mysql-types
2+
use * from rdbms-types
3+
4+
// query the database: select
5+
query: func(address: string, statement: string, params: list<parameter-value>) -> expected<row-set, mysql-error>
6+
7+
// execute command to the database: insert, update, delete
8+
execute: func(address: string, statement: string, params: list<parameter-value>) -> expected<unit, mysql-error>

wit/outbound-pg.wit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use * from pg-types
2+
use * from rdbms-types
3+
4+
// query the database: select
5+
query: func(address: string, statement: string, params: list<parameter-value>) -> expected<row-set, pg-error>
6+
7+
// execute command to the database: insert, update, delete
8+
execute: func(address: string, statement: string, params: list<parameter-value>) -> expected<u64, pg-error>

wit/outbound-redis.wit

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use * from redis-types
2+
3+
// Publish a Redis message to the specificed channel and return an error, if any.
4+
publish: func(address: string, channel: string, payload: payload) -> expected<unit, error>
5+
6+
// Get the value of a key.
7+
get: func(address: string, key: string) -> expected<payload, error>
8+
9+
// Set key to value. If key alreads holds a value, it is overwritten.
10+
set: func(address: string, key: string, value: payload) -> expected<unit, error>
11+
12+
// Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
13+
// 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.
14+
incr: func(address: string, key: string) -> expected<s64, error>
15+
16+
// Removes the specified keys. A key is ignored if it does not exist.
17+
del: func(address: string, keys: list<string>) -> expected<s64, error>
18+
19+
// Add the specified `values` to the set named `key`, returning the number of newly-added values.
20+
sadd: func(address: string, key: string, values: list<string>) -> expected<s64, error>
21+
22+
// Retrieve the contents of the set named `key`.
23+
smembers: func(address: string, key: string) -> expected<list<string>, error>
24+
25+
// Remove the specified `values` from the set named `key`, returning the number of newly-removed values.
26+
srem: func(address: string, key: string, values: list<string>) -> expected<s64, error>
27+
28+
// Execute an arbitrary Redis command and receive the result.
29+
execute: func(address: string, command: string, arguments: list<redis-parameter>) -> expected<list<redis-result>, error>

wit/pg-types.wit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// General purpose error.
2+
variant pg-error {
3+
success,
4+
connection-failed(string),
5+
bad-parameter(string),
6+
query-failed(string),
7+
value-conversion-failed(string),
8+
other-error(string)
9+
}

wit/rdbms-types.wit

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
enum db-data-type {
2+
boolean,
3+
int8,
4+
int16,
5+
int32,
6+
int64,
7+
uint8,
8+
uint16,
9+
uint32,
10+
uint64,
11+
floating32,
12+
floating64,
13+
str,
14+
binary,
15+
other,
16+
}
17+
18+
variant db-value {
19+
boolean(bool),
20+
int8(s8),
21+
int16(s16),
22+
int32(s32),
23+
int64(s64),
24+
uint8(u8),
25+
uint16(u16),
26+
uint32(u32),
27+
uint64(u64),
28+
floating32(float32),
29+
floating64(float64),
30+
str(string),
31+
binary(list<u8>),
32+
db-null,
33+
unsupported,
34+
}
35+
36+
variant parameter-value {
37+
boolean(bool),
38+
int8(s8),
39+
int16(s16),
40+
int32(s32),
41+
int64(s64),
42+
uint8(u8),
43+
uint16(u16),
44+
uint32(u32),
45+
uint64(u64),
46+
floating32(float32),
47+
floating64(float64),
48+
str(string),
49+
binary(list<u8>),
50+
db-null,
51+
}
52+
53+
record column {
54+
name: string,
55+
data-type: db-data-type,
56+
}
57+
58+
type row = list<db-value>
59+
60+
record row-set {
61+
columns: list<column>,
62+
rows: list<row>,
63+
}

wit/redis-types.wit

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// General purpose error.
2+
enum error {
3+
success,
4+
error,
5+
}
6+
7+
// The message payload.
8+
type payload = list<u8>
9+
10+
// A parameter type for the general-purpose `execute` function.
11+
variant redis-parameter {
12+
int64(s64),
13+
binary(payload)
14+
}
15+
16+
// A return type for the general-purpose `execute` function.
17+
variant redis-result {
18+
nil,
19+
status(string),
20+
int64(s64),
21+
binary(payload)
22+
}

0 commit comments

Comments
 (0)