diff --git a/cozo-core/src/data/expr.rs b/cozo-core/src/data/expr.rs index fe379170..fb230b3b 100644 --- a/cozo-core/src/data/expr.rs +++ b/cozo-core/src/data/expr.rs @@ -895,6 +895,7 @@ pub(crate) fn get_op(name: &str) -> Option<&'static Op> { "rand_uuid_v1" => &OP_RAND_UUID_V1, "rand_uuid_v4" => &OP_RAND_UUID_V4, "uuid_timestamp" => &OP_UUID_TIMESTAMP, + "validity" => &OP_VALIDITY, "now" => &OP_NOW, "format_timestamp" => &OP_FORMAT_TIMESTAMP, "parse_timestamp" => &OP_PARSE_TIMESTAMP, diff --git a/cozo-core/src/data/functions.rs b/cozo-core/src/data/functions.rs index b973484d..e65a80bd 100644 --- a/cozo-core/src/data/functions.rs +++ b/cozo-core/src/data/functions.rs @@ -1780,9 +1780,7 @@ fn get_impl(args: &[DataValue]) -> Result { .ok_or_else(|| miette!("index '{}' not found in json", i))? .clone() } - DataValue::List(l) => { - get_json_path_immutable(json, l)?.clone() - } + DataValue::List(l) => get_json_path_immutable(json, l)?.clone(), _ => bail!("second argument to 'get' mut be a string or integer"), }; let res = json2val(res); @@ -2526,3 +2524,21 @@ pub(crate) fn op_uuid_timestamp(args: &[DataValue]) -> Result { _ => bail!("not an UUID"), }) } + +define_op!(OP_VALIDITY, 1, true); +pub(crate) fn op_validity(args: &[DataValue]) -> Result { + let ts = args[0] + .get_int() + .ok_or_else(|| miette!("'validity' expects an integer"))?; + let is_assert = if args.len() == 1 { + true + } else { + args[1] + .get_bool() + .ok_or_else(|| miette!("'validity' expects a boolean as second argument"))? + }; + Ok(DataValue::Validity(Validity { + timestamp: ValidityTs(Reverse(ts)), + is_assert: Reverse(is_assert), + })) +}