OCA Validator
OCA Validator enables entry (or an array of entries) verification against predefined rules, given by the OCA Bundle . The verification executed on an entry, that is a map of key-value pairs, encompasses:
- type checking, so whether a value matches the expected type (defined in Capture Base) or can be implicitly coerced to it;
- task (overlay) specific verification, including:
Installation
Rust
[dependencies]
oca_conductor = "0.2.6"
oca_zip_resolver = "0.2.6"
Typescript and JavaScript (Node.JS based)
npm i oca-data-validator
Usage
Rust
use oca_conductor::data_set::DataSet;
use oca_conductor::data_set::JSONDataSet;
use oca_conductor::Validator;
use oca_zip_resolver::resolve_from_zip;
fn main() {
let oca_result = resolve_from_zip("oca_bundle.zip");
let mut validator = Validator::new(oca_result.unwrap());
validator.add_data_set(JSONDataSet::new(
r#"{ "email": "test@example.com", "licensess": ["A"] }"#.to_string(),
));
let validation_result = validator.validate();
println!("{:?}", validation_result); // Ok(())
}
See also tests available for validator
module.
Typescript and JavaScript (Node.JS based)
import { resolveFromZip, Validator } from "oca-data-validator";
const oca = resolveFromZip(`oca_bundle.zip`);
let validator = new Validator(oca);
const result = validator.validate({
'email': 'test@example.com',
'licenses': ["A"],
});
console.log(result); // true
See also here for more integration tests.