nectar/wit/uqbar.wit

187 lines
5.8 KiB
Plaintext
Raw Normal View History

package uqbar:process@0.3.0
2023-10-02 23:02:53 +03:00
interface standard {
2023-10-02 23:02:53 +03:00
// JSON is passed over WASM boundary as a string.
type json = string
type node-id = string
// context, like ipc, is a protocol-defined serialized byte array.
2023-10-02 23:02:53 +03:00
// it is used when building a Request to save information
// that will not be part of a Response, in order to more
// easily handle ("contextualize") that Response.
2023-10-26 07:11:03 +03:00
type context = list<u8>
2023-10-02 23:02:53 +03:00
record process-id {
process-name: string,
package-name: string,
publisher-node: node-id,
2023-10-02 23:02:53 +03:00
}
// TODO better name for this
record address {
node: node-id,
2023-10-02 23:02:53 +03:00
process: process-id,
}
record payload {
mime: option<string>,
bytes: list<u8>,
}
record request {
// if true, this request inherits context AND payload of incipient
// request, and cannot have its own context.
inherit: bool,
// if Some, this request expects a response in the number of seconds given
expects-response: option<u64>,
2023-10-26 07:11:03 +03:00
ipc: list<u8>,
2023-10-02 23:02:53 +03:00
metadata: option<json>,
// to grab payload, use get_payload()
}
record response {
inherit: bool,
2023-10-26 07:11:03 +03:00
ipc: list<u8>,
2023-10-02 23:02:53 +03:00
metadata: option<json>,
// to grab payload, use get_payload()
}
// a message can be a request or a response.
// within a response, there is a result which surfaces any error
// that happened because of a request.
// a successful response will contain the context of the request
// it matches, if any was set.
variant message {
request(request),
response(tuple<response, option<context>>),
}
variant capabilities {
none,
all,
some(list<signed-capability>),
}
record signed-capability {
issuer: address,
params: json,
signature: list<u8>,
}
// on-panic is a setting that determines what happens when a process panics.
// NOTE: requests should have expects-response set to false, will always be set to that by kernel
variant on-panic {
none,
restart,
requests(list<tuple<address, request, option<payload>>>),
}
2023-10-02 23:02:53 +03:00
// network errors come from trying to send a message to another node.
// a message can fail by timing out, or by the node being entirely unreachable (offline).
// in either case, the message is not delivered, and the process that sent it
// receives that message along with any assigned context and/or payload,
// and is free to handle it as it sees fit.
// note that if the message is a response, the process can issue a response again,
// and it will be directed to the same (remote) request as the original.
record send-error {
kind: send-error-kind,
message: message,
payload: option<payload>,
}
enum send-error-kind {
offline,
timeout,
}
enum spawn-error {
name-taken,
no-file-at-path,
// TODO more here?
2023-10-02 23:02:53 +03:00
}
// system utils:
2023-11-02 22:35:35 +03:00
print-to-terminal: func(verbosity: u8, message: string)
// **more will be added here with regard to blockchains**
2023-11-02 22:35:35 +03:00
get-eth-block: func() -> u64
2023-10-02 23:02:53 +03:00
// process management:
2023-11-02 22:35:35 +03:00
set-on-panic: func(on-panic: on-panic)
2023-10-02 23:02:53 +03:00
2023-11-02 22:35:35 +03:00
get-state: func() -> option<list<u8>>
2023-10-05 22:03:42 +03:00
2023-11-02 22:35:35 +03:00
set-state: func(bytes: list<u8>)
2023-10-05 22:03:42 +03:00
2023-11-02 22:35:35 +03:00
clear-state: func()
2023-10-05 22:03:42 +03:00
2023-11-02 22:35:35 +03:00
spawn: func(
name: option<string>,
wasm-path: string, // must be located within package's drive
on-panic: on-panic,
capabilities: capabilities,
public: bool
) -> result<process-id, spawn-error>
2023-10-02 23:02:53 +03:00
// capabilities management
// gives us all our signed capabilities so we can send them to others
2023-11-02 22:35:35 +03:00
get-capabilities: func() -> list<signed-capability>
2023-10-02 23:02:53 +03:00
// gets a single specific capability
2023-11-02 22:35:35 +03:00
get-capability: func(issuer: address, params: json) -> option<signed-capability>
2023-10-02 23:02:53 +03:00
// attaches a specific signed capability to our next message
2023-11-02 22:35:35 +03:00
attach-capability: func(capability: signed-capability)
2023-10-02 23:02:53 +03:00
// saves capabilities to our store, so we can use them
2023-11-02 22:35:35 +03:00
save-capabilities: func(capabilities: list<signed-capability>)
2023-10-02 23:02:53 +03:00
// check to see if the sender of a prompting message has a given capability, issued by us
// if the prompting message has a remote source, they must have attached it.
2023-11-02 22:35:35 +03:00
has-capability: func(params: json) -> bool
2023-10-02 23:02:53 +03:00
// generates a new capability with our process as the issuer and gives it to the target,
// which must be a locally-running process.
2023-11-02 22:35:35 +03:00
create-capability: func(to: process-id, params: json)
// take a signed capability and save it to a given locally-running process
2023-11-02 22:35:35 +03:00
share-capability: func(to: process-id, capability: signed-capability)
2023-10-02 23:02:53 +03:00
// message I/O:
// ingest next message when it arrives along with its source.
// almost all long-running processes will call this in a loop
2023-11-02 22:35:35 +03:00
receive: func() -> result<tuple<address, message>, tuple<send-error, option<context>>>
2023-10-02 23:02:53 +03:00
// gets payload, if any, of the message we just received
2023-11-02 22:35:35 +03:00
get-payload: func() -> option<payload>
2023-10-02 23:02:53 +03:00
// send message(s) to target(s)
2023-11-02 22:35:35 +03:00
send-request:
2023-10-02 23:02:53 +03:00
func(target: address, request: request, context: option<context>, payload: option<payload>)
2023-11-02 22:35:35 +03:00
send-requests:
2023-10-02 23:02:53 +03:00
func(requests: list<tuple<address, request, option<context>, option<payload>>>)
2023-11-02 22:35:35 +03:00
send-response:
2023-10-02 23:02:53 +03:00
func(response: response, payload: option<payload>)
// send a single request, then block (internally) until its response
// the type is Message but will always contain Response
2023-11-02 22:35:35 +03:00
send-and-await-response:
2023-10-02 23:02:53 +03:00
func(target: address, request: request, payload: option<payload>) ->
result<tuple<address, message>, send-error>
}
2023-11-02 22:35:35 +03:00
world lib {
import standard
2023-11-02 22:35:35 +03:00
}
world process {
include lib
2023-11-02 22:35:35 +03:00
export init: func(our: string)
}