use relate_core::PreviewFeature;
use relate_ontology::MAX_SUPPORTED_SPEC_VERSION;
use crate::procedure_registry::is_ontology_procedure;
pub fn procedure_preview_feature(name: &str) -> Option<PreviewFeature> {
is_ontology_procedure(name).then_some(PreviewFeature::Ontology)
}
pub struct GatedCapability {
pub feature: PreviewFeature,
pub name: &'static str,
pub description: &'static str,
pub value: &'static str,
}
pub const GATED_CAPABILITIES: &[GatedCapability] = &[GatedCapability {
feature: PreviewFeature::Ontology,
name: "ontology.supported.version",
description: "The latest version of the Neo4j ontology graph spec supported by this DBMS.",
value: MAX_SUPPORTED_SPEC_VERSION,
}];
#[cfg(test)]
mod tests {
use super::*;
use crate::procedure_registry::BUILTIN_PROCEDURE_SIGNATURES;
#[test]
fn the_ontology_family_is_the_only_gated_procedure_family() {
let family = [
("db.ontology.set", Some(PreviewFeature::Ontology)),
("db.ontology.get", Some(PreviewFeature::Ontology)),
("db.ontology.drop", Some(PreviewFeature::Ontology)),
("db.ontology.apply", Some(PreviewFeature::Ontology)),
];
for (name, expected) in family {
assert_eq!(procedure_preview_feature(name), expected, "{name}");
}
assert_eq!(procedure_preview_feature("db.labels"), None);
assert_eq!(procedure_preview_feature("db.ontology.custom"), None);
let gated: Vec<&str> = BUILTIN_PROCEDURE_SIGNATURES
.iter()
.filter(|signature| procedure_preview_feature(signature.name).is_some())
.map(|signature| signature.name)
.collect();
assert_eq!(
gated,
[
"db.ontology.apply",
"db.ontology.drop",
"db.ontology.get",
"db.ontology.set"
]
);
}
#[test]
fn the_capability_table_is_the_one_mirrored_row() {
assert_eq!(GATED_CAPABILITIES.len(), 1);
let row = &GATED_CAPABILITIES[0];
assert!(matches!(row.feature, PreviewFeature::Ontology));
assert_eq!(row.name, "ontology.supported.version");
assert!(!row.description.is_empty());
}
}