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
use option_utils::OptionUtils;
mod lockdown;
mod tests;

use crate::config::{self, test_config, types_config, ComponentConfiguration};
use crate::error::ManifestError;
use crate::utils::VecTryMapInto;
use crate::{v1, Result, WickConfiguration};

impl TryFrom<v1::WickConfig> for WickConfiguration {
  type Error = ManifestError;

  fn try_from(def: v1::WickConfig) -> Result<Self> {
    let new = match def {
      v1::WickConfig::AppConfiguration(v) => WickConfiguration::App(v.try_into()?),
      v1::WickConfig::ComponentConfiguration(v) => WickConfiguration::Component(v.try_into()?),
      v1::WickConfig::TypesConfiguration(v) => WickConfiguration::Types(v.try_into()?),
      v1::WickConfig::TestConfiguration(v) => WickConfiguration::Tests(v.try_into()?),
      v1::WickConfig::LockdownConfiguration(v) => WickConfiguration::Lockdown(v.try_into()?),
    };
    Ok(new)
  }
}

impl TryFrom<v1::TestConfiguration> for test_config::TestConfiguration {
  type Error = ManifestError;

  fn try_from(value: v1::TestConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      cases: value.cases.try_map_into()?,
      config: value.with.map_into(),
      name: value.name,
      source: None,
      env: Default::default(),
    })
  }
}

impl TryFrom<config::TestConfiguration> for v1::TestConfiguration {
  type Error = ManifestError;

  fn try_from(value: config::TestConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      name: value.name,
      with: value.config.map_into(),
      cases: value.cases.try_map_into()?,
    })
  }
}

impl TryFrom<v1::TypesConfiguration> for types_config::TypesConfiguration {
  type Error = ManifestError;

  fn try_from(value: v1::TypesConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      name: value.name,
      metadata: value.metadata.try_map_into()?,
      types: value.types.try_map_into()?,
      operations: value.operations.try_map_into()?,
      source: None,
      package: value.package.try_map_into()?,
    })
  }
}

impl TryFrom<types_config::TypesConfiguration> for v1::TypesConfiguration {
  type Error = ManifestError;

  fn try_from(value: types_config::TypesConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      name: value.name,
      metadata: value.metadata.try_map_into()?,
      types: value.types.try_map_into()?,
      operations: value.operations.try_map_into()?,
      package: value.package.try_map_into()?,
    })
  }
}

impl TryFrom<v1::ComponentConfiguration> for ComponentConfiguration {
  type Error = ManifestError;

  fn try_from(def: v1::ComponentConfiguration) -> Result<Self> {
    Ok(ComponentConfiguration {
      source: None,
      metadata: def.metadata.try_map_into()?,
      host: def.host.try_map_into()?,
      name: def.name,
      tests: def.tests.try_map_into()?,
      component: def.component.try_into()?,
      types: def.types.try_map_into()?,
      requires: def.requires.try_map_into()?,
      import: def.import.try_map_into()?,
      resources: def.resources.try_map_into()?,
      cached_types: Default::default(),
      type_cache: Default::default(),
      package: def.package.try_map_into()?,
      root_config: Default::default(),
    })
  }
}

impl TryFrom<ComponentConfiguration> for v1::ComponentConfiguration {
  type Error = ManifestError;

  fn try_from(def: ComponentConfiguration) -> Result<Self> {
    Ok(v1::ComponentConfiguration {
      metadata: def.metadata.try_map_into()?,
      host: def.host.try_map_into()?,
      name: def.name,
      requires: def.requires.try_map_into()?,
      import: def.import.try_map_into()?,
      types: def.types.try_map_into()?,
      resources: def.resources.try_map_into()?,
      tests: def.tests.try_map_into()?,
      component: def.component.try_into()?,
      package: def.package.try_map_into()?,
    })
  }
}

impl TryFrom<v1::LockdownConfiguration> for config::LockdownConfiguration {
  type Error = ManifestError;

  fn try_from(value: v1::LockdownConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      resources: value.resources.try_map_into()?,
      metadata: value.metadata.try_map_into()?,
      source: None,
      env: None,
    })
  }
}

impl TryFrom<config::LockdownConfiguration> for v1::LockdownConfiguration {
  type Error = ManifestError;

  fn try_from(value: config::LockdownConfiguration) -> std::result::Result<Self, Self::Error> {
    Ok(Self {
      resources: value.resources.try_map_into()?,
      metadata: value.metadata.try_map_into()?,
    })
  }
}