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