golem-cli 1.3.1

Command line interface for Golem.
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
///|
pub fn extract_tuple(value : @common.DataValue) -> Array[@common.ElementValue] {
  match value {
    @common.DataValue::Tuple(elements) => elements
    _ => panic()
  }
}

///|
pub fn extract_multimodal(value: @common.DataValue) -> Array[(String, @common.ElementValue)] {
  match value {
    @common.DataValue::Multimodal(elements) => elements
    _ => panic()
  }
}

///|
pub fn expect_single_element(
  values : Array[@common.ElementValue],
) -> @common.ElementValue {
  if values.length() != 1 {
    panic()
  }
  values[0]
}

///|
pub fn extract_component_model_value(
  element : @common.ElementValue,
) -> &Extractor {
  match element {
    @common.ElementValue::ComponentModel(model) => extract(model)
    _ => panic()
  }
}

pub fn extract_unstructured_text(
    element : @common.ElementValue,
    ) -> @common.TextReference {
    match element {
        @common.ElementValue::UnstructuredText(text) => text
        _ => panic()
    }
}

pub fn extract_unstructured_binary(
    element : @common.ElementValue,
) -> @common.BinaryReference {
    match element {
        @common.ElementValue::UnstructuredBinary(data) => data
        _ => panic()
    }
}

///|
pub fn extract(value : @types.WitValue) -> &Extractor {
  WitValueExtractor::{ value, }
}

///|
priv struct WitValueExtractor {
  value : @types.WitValue
}

///|
impl Extractor for WitValueExtractor with u8(self : WitValueExtractor) -> Byte? {
  self.value.nodes.get(0).bind(node => Extractor::u8(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with u16(self : WitValueExtractor) -> UInt? {
  self.value.nodes.get(0).bind(node => Extractor::u16(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with u32(self : WitValueExtractor) -> UInt? {
  self.value.nodes.get(0).bind(node => Extractor::u32(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with u64(self : WitValueExtractor) -> UInt64? {
  self.value.nodes.get(0).bind(node => Extractor::u64(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with s8(self : WitValueExtractor) -> Int? {
  self.value.nodes.get(0).bind(node => Extractor::s8(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with s16(self : WitValueExtractor) -> Int? {
  self.value.nodes.get(0).bind(node => Extractor::s16(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with s32(self : WitValueExtractor) -> Int? {
  self.value.nodes.get(0).bind(node => Extractor::s32(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with s64(self : WitValueExtractor) -> Int64? {
  self.value.nodes.get(0).bind(node => Extractor::s64(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with f32(self : WitValueExtractor) -> Float? {
  self.value.nodes.get(0).bind(node => Extractor::f32(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with f64(self : WitValueExtractor) -> Double? {
  self.value.nodes.get(0).bind(node => Extractor::f64(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with bool(self : WitValueExtractor) -> Bool? {
  self.value.nodes.get(0).bind(node => Extractor::bool(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with string(self : WitValueExtractor) -> String? {
  self.value.nodes.get(0).bind(node => Extractor::string(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with field(
  self : WitValueExtractor,
  field_idx : Int,
) -> &Extractor? {
  self.value.nodes
  .get(0)
  .bind(node => Extractor::field(self.extract(node), field_idx))
}

///|
impl Extractor for WitValueExtractor with variant(self : WitValueExtractor) -> (
  UInt,
  &Extractor?,
)? {
  self.value.nodes.get(0).bind(node => Extractor::variant(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with enum_value(self : WitValueExtractor) -> UInt? {
  self.value.nodes
  .get(0)
  .bind(node => Extractor::enum_value(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with flags(self : WitValueExtractor) -> Array[
  Bool,
]? {
  self.value.nodes.get(0).bind(node => Extractor::flags(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with tuple_element(
  self : WitValueExtractor,
  element_idx : Int,
) -> &Extractor? {
  self.value.nodes
  .get(0)
  .bind(node => Extractor::tuple_element(self.extract(node), element_idx))
}

///|
impl Extractor for WitValueExtractor with list_elements(
  self : WitValueExtractor,
) -> Array[&Extractor]? {
  self.value.nodes
  .get(0)
  .bind(node => Extractor::list_elements(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with option(self : WitValueExtractor) -> &Extractor?? {
  self.value.nodes.get(0).bind(node => Extractor::option(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with result(self : WitValueExtractor) -> Result[
  &Extractor?,
  &Extractor?,
]? {
  self.value.nodes.get(0).bind(node => Extractor::result(self.extract(node)))
}

///|
impl Extractor for WitValueExtractor with handle(self : WitValueExtractor) -> (
  @types.Uri,
  UInt64,
)? {
  self.value.nodes.get(0).bind(node => Extractor::handle(self.extract(node)))
}

///|
fn WitValueExtractor::extract(
  self : WitValueExtractor,
  node : @types.WitNode,
) -> NodeExtractor {
  { node, context: self.value }
}

///|
priv struct NodeExtractor {
  node : @types.WitNode
  context : @types.WitValue
}

///|
impl Extractor for NodeExtractor with u8(self : NodeExtractor) -> Byte? {
  match self.node {
    PrimU8(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with u16(self : NodeExtractor) -> UInt? {
  match self.node {
    PrimU16(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with u32(self : NodeExtractor) -> UInt? {
  match self.node {
    PrimU32(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with u64(self : NodeExtractor) -> UInt64? {
  match self.node {
    PrimU64(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with s8(self : NodeExtractor) -> Int? {
  match self.node {
    PrimS8(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with s16(self : NodeExtractor) -> Int? {
  match self.node {
    PrimS16(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with s32(self : NodeExtractor) -> Int? {
  match self.node {
    PrimS32(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with s64(self : NodeExtractor) -> Int64? {
  match self.node {
    PrimS64(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with f32(self : NodeExtractor) -> Float? {
  match self.node {
    PrimFloat32(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with f64(self : NodeExtractor) -> Double? {
  match self.node {
    PrimFloat64(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with bool(self : NodeExtractor) -> Bool? {
  match self.node {
    PrimBool(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with string(self : NodeExtractor) -> String? {
  match self.node {
    PrimString(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with field(
  self : NodeExtractor,
  field_idx : Int,
) -> &Extractor? {
  match self.node {
    RecordValue(fields) =>
      fields.get(field_idx).bind(node_idx => self.extract(node_idx))
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with variant(self : NodeExtractor) -> (
  UInt,
  &Extractor?,
)? {
  match self.node {
    VariantValue((case_idx, value)) =>
      Some((case_idx, value.bind(node_idx => self.extract(node_idx))))
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with enum_value(self : NodeExtractor) -> UInt? {
  match self.node {
    EnumValue(value) => Some(value)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with flags(self : NodeExtractor) -> Array[Bool]? {
  match self.node {
    FlagsValue(flags) => Some(flags)
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with tuple_element(
  self : NodeExtractor,
  element_idx : Int,
) -> &Extractor? {
  match self.node {
    TupleValue(elements) =>
      elements.get(element_idx).bind(node_idx => self.extract(node_idx))
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with list_elements(self : NodeExtractor) -> Array[
  &Extractor,
]? {
  match self.node {
    ListValue(elements) => {
      let result : Array[&Extractor] = []
      let mut failing = false
      for node_idx in elements {
        match self.extract(node_idx) {
          None => {
            failing = true
            break
          }
          Some(extractor) => result.push(extractor)
        }
      }
      if not(failing) {
        Some(result)
      } else {
        None
      }
    }
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with option(self : NodeExtractor) -> &Extractor?? {
  match self.node {
    OptionValue(value) =>
      match value {
        Some(node_idx) =>
          self.extract(node_idx).map(extractor => Some(extractor))
        None => Some(None)
      }
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with result(self : NodeExtractor) -> Result[
  &Extractor?,
  &Extractor?,
]? {
  match self.node {
    ResultValue(Ok(node_idx)) =>
      match node_idx {
        Some(idx) => self.extract(idx).map(extractor => Ok(Some(extractor)))
        None => Some(Ok(None))
      }
    ResultValue(Err(node_idx)) =>
      match node_idx {
        Some(idx) => self.extract(idx).map(extractor => Err(Some(extractor)))
        None => Some(Err(None))
      }
    _ => None
  }
}

///|
impl Extractor for NodeExtractor with handle(self : NodeExtractor) -> (
  @types.Uri,
  UInt64,
)? {
  match self.node {
    Handle((uri, value)) => Some((uri, value))
    _ => None
  }
}

///|
fn NodeExtractor::extract(self : NodeExtractor, node_idx : Int) -> &Extractor? {
  self.context.nodes
  .get(node_idx)
  .map(node => NodeExtractor::{ node, context: self.context })
}

///|
pub(open) trait Extractor {
  u8(Self) -> Byte?
  u16(Self) -> UInt?
  u32(Self) -> UInt?
  u64(Self) -> UInt64?
  s8(Self) -> Int?
  s16(Self) -> Int?
  s32(Self) -> Int?
  s64(Self) -> Int64?
  f32(Self) -> Float?
  f64(Self) -> Double?
  bool(Self) -> Bool?
  string(Self) -> String?
  field(Self, field_idx : Int) -> &Extractor?
  variant(Self) -> (UInt, &Extractor?)?
  enum_value(Self) -> UInt?
  flags(Self) -> Array[Bool]?
  tuple_element(Self, element_idx : Int) -> &Extractor?
  list_elements(Self) -> Array[&Extractor]?
  option(Self) -> &Extractor??
  result(Self) -> Result[&Extractor?, &Extractor?]?
  handle(Self) -> (@types.Uri, UInt64)?
}