elvwasm 1.0.0

Contains and collects the bitcode extension API for the Eluvio content fabric
Documentation
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate thiserror;
extern crate wapc_guest as guest;

use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::Debug;
use std::str;
use wapc_guest::CallResult;

/// Q is a bitcode representation of an individual piece of content from the fabric
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct Q {
    pub id: String,
    pub hash: String,
    #[serde(default)]
    pub write_token: String,
    #[serde(rename = "type")]
    pub q_type: String,
    pub qlib_id: String,
    #[serde(default)]
    pub meta: serde_json::Value,
    #[serde(default)]
    pub size_stats: SizeStats,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct SizeStats {
    pub parts: i32,
    #[serde(default)]
    pub size: String,
    pub size_bytes: i64,
}

/// Bitcode representation of a fabric size error
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QError {
    pub error: String,
    #[serde(default)]
    pub item: Q,
}

/// QRef is a bitcode representation of versioned content from the fabric
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct QRef {
    pub id: String,
    pub versions: Vec<Q>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ReadResult {
    pub result: String,
    #[serde(rename = "return", default)]
    pub ret: String,
}

impl TryFrom<CallResult> for ReadResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<ReadResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct WritePartResult {
    pub written: usize,
}

impl TryFrom<CallResult> for WritePartResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<WritePartResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct CreateResult {
    pub qid: String,
    pub qwtoken: String,
}

impl TryFrom<CallResult> for CreateResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<CreateResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct CreatePartResult {
    pub qphash: String,
    pub size: i64,
}

impl TryFrom<CallResult> for CreatePartResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<CreatePartResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct SystemTimeResult {
    pub time: u64,
}

impl TryFrom<CallResult> for SystemTimeResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<SystemTimeResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ExternalCallResult {
    pub function_return: serde_json::Value,
    pub fout: String,
    pub format: String,
}

impl TryFrom<CallResult> for ExternalCallResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<ExternalCallResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct FinalizeCallResult {
    pub qid: String,
    pub qhash: String,
}

impl TryFrom<CallResult> for FinalizeCallResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<FinalizeCallResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

/// Bitcode representation of a full content listing given an optional filter
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QList {
    #[serde(default)]
    pub filter: String,
    pub contents: Vec<QRef>,
    #[serde(default)]
    pub errors: Vec<QError>,
}

impl TryFrom<CallResult> for QList {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<QList, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

/// Bitcode representation of a fabric FileStream
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FileStream {
    /// bitcode stream handle
    pub stream_id: String,
    /// fabric file path
    pub file_name: String,
}

impl TryFrom<CallResult> for FileStream {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<FileStream, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}
/// Bitcode representation of the size of a fabric stream
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FileStreamSize {
    pub file_size: usize,
}

impl TryFrom<CallResult> for FileStreamSize {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<FileStreamSize, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

/// Bitcode representation of the JPC (JSON Procedure Call) parameters from a client request
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct JpcParams {
    pub http: HttpParams,
}

/// Bitcode representation of the http parameters from a client request
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct HttpParams {
    #[serde(default)]
    pub headers: HashMap<String, Vec<String>>,
    pub path: String,
    #[serde(default)]
    pub query: HashMap<String, Vec<String>>,
    pub verb: String,
    #[serde(default)]
    pub fragment: String,
    #[serde(default)]
    pub content_length: usize,
    #[serde(default)]
    pub client_ip: String,
    #[serde(default)]
    pub self_url: String,
    #[serde(default)]
    pub proto: String,
    #[serde(default)]
    pub host: String,
}

/// Bitcode representation of a content sans meta data
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct QInfo {
    #[serde(default)]
    pub hash: String,
    #[serde(default)]
    pub id: String,
    pub qlib_id: String,
    #[serde(rename = "type")]
    pub qtype: String,
    #[serde(default)]
    pub write_token: String,
}

impl QInfo {
    pub fn qhot(&self) -> String {
        let s: String = if !self.write_token.is_empty() {
            self.write_token.to_string()
        } else {
            self.hash.to_string()
        };
        s
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QPart {
    #[serde(default)]
    pub write_token: String,
    #[serde(default)]
    pub hash: String,
    #[serde(default)]
    pub size: i64,
}

impl TryFrom<CallResult> for QPart {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<QPart, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QPartListContents {
    #[serde(default)]
    pub content: Q,
    #[serde(default)]
    pub parts: Vec<QPart>,
}

impl TryFrom<CallResult> for QPartListContents {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<QPartListContents, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QPartList {
    pub part_list: QPartListContents,
}

impl TryFrom<CallResult> for QPartList {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<QPartList, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct QPartInfo {
    pub content: Q,
    pub part: QPart,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WriteResult {
    #[serde(default)]
    pub written: usize,
}

impl TryFrom<CallResult> for WriteResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<WriteResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ModifyResult {
    #[serde(default)]
    pub qwtoken: String,
}
impl TryFrom<CallResult> for ModifyResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<ModifyResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

/// Bitcode representation of a incomming client request
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct Request {
    pub id: String,
    pub jpc: String,
    pub method: String,
    pub params: JpcParams,
    #[serde(rename = "qinfo")]
    pub q_info: QInfo,
}

/// Bitcode representation of a request back to the fabric as a consequnce of processing the request
/// In order for bitcode to respond to a primary request from a client, the bitcode must gather info
/// from the fabric for processing.  This structure represents the data to such a call.
#[derive(Serialize, Deserialize)]
pub struct Response {
    pub jpc: String,
    pub params: serde_json::Value,
    pub id: String,
    pub module: String,
    pub method: String,
}

/// Bitcode representation of a result from new_stream
/// ```
/// fn do_something<'s>(bcc: &'s mut elvwasm::BitcodeContext) -> wapc_guest::CallResult {
///   let res = bcc.new_stream()?;
///   let stream1:elvwasm::NewStreamResult = serde_json::from_slice(&res)?;
///   // stream1.stream_id has new id
///   Ok(res)
/// }
/// ```
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NewStreamResult {
    pub stream_id: String,
}

impl TryFrom<CallResult> for NewStreamResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<NewStreamResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

/// Bitcode representation of a result from read_stream
/// ```
/// fn do_something<'s>(bcc: &'s mut elvwasm::BitcodeContext) -> wapc_guest::CallResult {
///   let res = bcc.new_stream()?;
///   let stream1:elvwasm::NewStreamResult = serde_json::from_slice(&res)?;
///   // stream1.stream_id has new id
///   Ok(res)
/// }
/// ```
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ReadStreamResult {
    #[serde(rename = "return")]
    pub retval: String,
    pub result: String,
}

impl TryFrom<CallResult> for ReadStreamResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<ReadStreamResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LROResult {
    pub lro_handle: String,
}

impl TryFrom<CallResult> for LROResult {
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    fn try_from(
        cr: CallResult,
    ) -> Result<LROResult, Box<dyn std::error::Error + Sync + Send + 'static>> {
        Ok(serde_json::from_slice(&cr?)?)
    }
}