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
mod grpcurl;
mod http_client;
mod manifest;
mod native;
mod reference;
mod sql;
mod types;
mod wasm;

use std::borrow::Cow;

pub use grpcurl::*;
pub use http_client::*;
pub use manifest::*;
pub use native::*;
pub use reference::*;
pub use sql::*;
pub use types::*;
pub use wasm::*;
use wick_interface_types::{Field, OperationSignatures};

pub trait OperationConfig {
  /// The name of the operation.
  fn name(&self) -> &str;

  /// The inputs to the operation.
  fn inputs(&self) -> Cow<Vec<Field>>;

  /// The outpus to the operation.
  fn outputs(&self) -> Cow<Vec<Field>>;
}

pub trait ComponentConfig: OperationSignatures {
  type Operation: OperationConfig;

  /// Get the operations defined by this configuration.
  fn operations(&self) -> &[Self::Operation];

  /// Get the operations defined by this configuration.
  fn operations_mut(&mut self) -> &mut Vec<Self::Operation>;

  /// Get an operation definition by name.
  fn get_operation(&self, name: &str) -> Option<&Self::Operation> {
    self.operations().iter().find(|o| o.name() == name)
  }
}