wick_config/v1/conversions/
root_configs.rs1use option_utils::OptionUtils;
2mod lockdown;
3mod tests;
4
5use crate::config::{self, test_config, types_config, ComponentConfiguration};
6use crate::error::ManifestError;
7use crate::utils::VecTryMapInto;
8use crate::{v1, Result, WickConfiguration};
9
10impl TryFrom<v1::WickConfig> for WickConfiguration {
11 type Error = ManifestError;
12
13 fn try_from(def: v1::WickConfig) -> Result<Self> {
14 let new = match def {
15 v1::WickConfig::AppConfiguration(v) => WickConfiguration::App(v.try_into()?),
16 v1::WickConfig::ComponentConfiguration(v) => WickConfiguration::Component(v.try_into()?),
17 v1::WickConfig::TypesConfiguration(v) => WickConfiguration::Types(v.try_into()?),
18 v1::WickConfig::TestConfiguration(v) => WickConfiguration::Tests(v.try_into()?),
19 v1::WickConfig::LockdownConfiguration(v) => WickConfiguration::Lockdown(v.try_into()?),
20 };
21 Ok(new)
22 }
23}
24
25impl TryFrom<v1::TestConfiguration> for test_config::TestConfiguration {
26 type Error = ManifestError;
27
28 fn try_from(value: v1::TestConfiguration) -> std::result::Result<Self, Self::Error> {
29 Ok(Self {
30 cases: value.cases.try_map_into()?,
31 config: value.with.map_into(),
32 name: value.name,
33 source: None,
34 env: Default::default(),
35 })
36 }
37}
38
39impl TryFrom<config::TestConfiguration> for v1::TestConfiguration {
40 type Error = ManifestError;
41
42 fn try_from(value: config::TestConfiguration) -> std::result::Result<Self, Self::Error> {
43 Ok(Self {
44 name: value.name,
45 with: value.config.map_into(),
46 cases: value.cases.try_map_into()?,
47 })
48 }
49}
50
51impl TryFrom<v1::TypesConfiguration> for types_config::TypesConfiguration {
52 type Error = ManifestError;
53
54 fn try_from(value: v1::TypesConfiguration) -> std::result::Result<Self, Self::Error> {
55 Ok(Self {
56 name: value.name,
57 metadata: value.metadata.try_map_into()?,
58 types: value.types.try_map_into()?,
59 operations: value.operations.try_map_into()?,
60 source: None,
61 package: value.package.try_map_into()?,
62 })
63 }
64}
65
66impl TryFrom<types_config::TypesConfiguration> for v1::TypesConfiguration {
67 type Error = ManifestError;
68
69 fn try_from(value: types_config::TypesConfiguration) -> std::result::Result<Self, Self::Error> {
70 Ok(Self {
71 name: value.name,
72 metadata: value.metadata.try_map_into()?,
73 types: value.types.try_map_into()?,
74 operations: value.operations.try_map_into()?,
75 package: value.package.try_map_into()?,
76 })
77 }
78}
79
80impl TryFrom<v1::ComponentConfiguration> for ComponentConfiguration {
81 type Error = ManifestError;
82
83 fn try_from(def: v1::ComponentConfiguration) -> Result<Self> {
84 Ok(ComponentConfiguration {
85 source: None,
86 metadata: def.metadata.try_map_into()?,
87 host: def.host.try_map_into()?,
88 name: def.name,
89 tests: def.tests.try_map_into()?,
90 component: def.component.try_into()?,
91 types: def.types.try_map_into()?,
92 requires: def.requires.try_map_into()?,
93 import: def.import.try_map_into()?,
94 resources: def.resources.try_map_into()?,
95 cached_types: Default::default(),
96 type_cache: Default::default(),
97 package: def.package.try_map_into()?,
98 root_config: Default::default(),
99 })
100 }
101}
102
103impl TryFrom<ComponentConfiguration> for v1::ComponentConfiguration {
104 type Error = ManifestError;
105
106 fn try_from(def: ComponentConfiguration) -> Result<Self> {
107 Ok(v1::ComponentConfiguration {
108 metadata: def.metadata.try_map_into()?,
109 host: def.host.try_map_into()?,
110 name: def.name,
111 requires: def.requires.try_map_into()?,
112 import: def.import.try_map_into()?,
113 types: def.types.try_map_into()?,
114 resources: def.resources.try_map_into()?,
115 tests: def.tests.try_map_into()?,
116 component: def.component.try_into()?,
117 package: def.package.try_map_into()?,
118 })
119 }
120}
121
122impl TryFrom<v1::LockdownConfiguration> for config::LockdownConfiguration {
123 type Error = ManifestError;
124
125 fn try_from(value: v1::LockdownConfiguration) -> std::result::Result<Self, Self::Error> {
126 Ok(Self {
127 resources: value.resources.try_map_into()?,
128 metadata: value.metadata.try_map_into()?,
129 source: None,
130 env: None,
131 })
132 }
133}
134
135impl TryFrom<config::LockdownConfiguration> for v1::LockdownConfiguration {
136 type Error = ManifestError;
137
138 fn try_from(value: config::LockdownConfiguration) -> std::result::Result<Self, Self::Error> {
139 Ok(Self {
140 resources: value.resources.try_map_into()?,
141 metadata: value.metadata.try_map_into()?,
142 })
143 }
144}