1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#[macro_use]
extern crate serde_derive;
pub mod http {
include!(concat!(env!("OUT_DIR"), "/http.rs"));
use prost::Message;
use serde::ser::Serialize;
use std::collections::HashMap;
pub const OP_PERFORM_REQUEST: &str = "wascap:httpclient!PerformRequest";
pub const OP_HANDLE_REQUEST: &str = "wascap:httpserver!HandleRequest";
impl Into<Request> for &[u8] {
fn into(self) -> Request {
Request::decode(self).unwrap()
}
}
impl Into<Response> for &[u8] {
fn into(self) -> Response {
Response::decode(self).unwrap()
}
}
impl Response {
pub fn json<T>(payload: T, status_code: u32, status: &str) -> Response
where
T: Serialize,
{
Response {
body: serde_json::to_string(&payload).unwrap().into_bytes(),
header: HashMap::new(),
status: status.to_string(),
status_code,
}
}
pub fn not_found() -> Response {
Response {
status: "Not Found".to_string(),
status_code: 404,
..Default::default()
}
}
pub fn ok() -> Response {
Response {
status: "OK".to_string(),
status_code: 200,
..Default::default()
}
}
pub fn internal_server_error(msg: &str) -> Response {
Response {
status: "Internal Server Error".to_string(),
status_code: 500,
body: msg.to_string().as_bytes().into(),
..Default::default()
}
}
pub fn bad_request() -> Response {
Response {
status: "Bad Request".to_string(),
status_code: 400,
..Default::default()
}
}
}
}
pub mod core {
include!(concat!(env!("OUT_DIR"), "/core.rs"));
pub const OP_PERFORM_LIVE_UPDATE: &str = "wascap:httpsrv!PerformLiveUpdate";
pub const OP_HEALTH_REQUEST: &str = "wascap:httpsrv!HealthRequest";
}
pub mod messaging {
use prost::Message;
include!(concat!(env!("OUT_DIR"), "/messaging.rs"));
pub const OP_PUBLISH_MESSAGE: &str = "wascap:messaging!Publish";
pub const OP_DELIVER_MESSAGE: &str = "wascap:messaging!DeliverMessage";
pub const OP_PERFORM_REQUEST: &str = "wascap:messaging!Request";
impl Into<DeliverMessage> for &[u8] {
fn into(self) -> DeliverMessage {
DeliverMessage::decode(self).unwrap()
}
}
impl Into<PublishMessage> for &[u8] {
fn into(self) -> PublishMessage {
PublishMessage::decode(self).unwrap()
}
}
impl Into<RequestMessage> for &[u8] {
fn into(self) -> RequestMessage {
RequestMessage::decode(self).unwrap()
}
}
}
pub mod keyvalue {
include!(concat!(env!("OUT_DIR"), "/keyvalue.rs"));
pub const OP_ADD: &str = "wascap:keyvalue!Add";
pub const OP_GET: &str = "wascap:keyvalue!Get";
pub const OP_SET: &str = "wascap:keyvalue!Set";
pub const OP_DEL: &str = "wascap:keyvalue!Del";
pub const OP_CLEAR: &str = "wascap:keyvalue!Clear";
pub const OP_RANGE: &str = "wascap:keyvalue!Range";
pub const OP_PUSH: &str = "wascap:keyvalue!Push";
pub const OP_LIST_DEL: &str = "wascap:keyvalue!ListItemDelete";
pub const OP_SET_ADD: &str = "wascap:keyvalue!SetAdd";
pub const OP_SET_REMOVE: &str = "wascap:keyvalue!SetRemove";
pub const OP_SET_UNION: &str = "wascap:keyvalue!SetUnion";
pub const OP_SET_INTERSECT: &str = "wascap:keyvalue!SetIntersection";
pub const OP_SET_QUERY: &str = "wascap:keyvalue!SetQuery";
pub const OP_KEY_EXISTS: &str = "wascap:keyvalue!KeyExists";
}
pub mod capabilities;