LegacyManifest finished
@@ -11,6 +11,14 @@ pub enum LegacyIdProperty {
Many(Vec<String>),
}
+#[derive(Deserialize)]
+pub struct LegacySort {
+ name: Option<String>,
+ #[serde(rename = "prop")]
+ id: String,
+ types: Option<Vec<String>>,
+}
+
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LegacyManifest {
@@ -24,15 +32,44 @@ pub struct LegacyManifest {
types: Vec<String>,
contact_email: Option<String>,
id_property: Option<LegacyIdProperty>,
- // @TODO sorts
+ sorts: Option<Vec<LegacySort>>,
}
impl From<LegacyManifest> for Manifest {
fn from(m: LegacyManifest) -> Self {
- let mut resources: Vec<ManifestResource> = vec![];
- let mut catalogs: Vec<ManifestCatalog> = vec![];
- let id_prefixes = m
- .id_property
- .map(|id_property| {
+ // Catalogs: if there are sorts, add a catalog for each type for each sort
+ // if there are no sorts, do that just for the types
+ let types = m.types.to_owned();
+ let catalogs: Vec<ManifestCatalog> = if m.methods.iter().any(|x| x == "meta.find") {
+ match m.sorts {
+ Some(sorts) => sorts
+ .iter()
+ .flat_map(|sort| {
+ let types = sort.types.as_ref().unwrap_or(&types);
+ types.iter().cloned().map(move |t| ManifestCatalog {
+ type_name: t,
+ id: sort.id.to_owned(),
+ name: sort.name.to_owned(),
+ extra: Default::default(),
+ })
+ })
+ .collect(),
+ None => types
+ .iter()
+ .map(|t| ManifestCatalog {
+ type_name: t.to_owned(),
+ id: "top".to_owned(),
+ name: None,
+ extra: Default::default(),
+ })
+ .collect(),
+ }
+ } else {
+ vec![]
+ };
+
+ // id_prefixes: the previous id_property is pretty much equivalent,
+ // with the following differences:
+ let id_prefixes = m.id_property.map(|id_property| {
let all = match id_property {
LegacyIdProperty::One(s) => vec![s],
LegacyIdProperty::Many(m) => m,
@@ -45,13 +82,16 @@ impl From<LegacyManifest> for Manifest {
})
.collect()
});
- // @TODO catalogs
+
+ // resources: only those two are supported by the legacy mapper
+ let mut resources: Vec<ManifestResource> = vec![];
if m.methods.iter().any(|x| x == "meta.get") {
resources.push(ManifestResource::Short("meta".into()))
}
if m.methods.iter().any(|x| x == "stream.find") {
resources.push(ManifestResource::Short("stream".into()))
}
+
Manifest {
id: m.id,
name: m.name,
