MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_eval

Function try_eval

nodedb-query/src/functions/id.rs:8–45  ·  view source on GitHub ↗
(name: &str, args: &[Value])

Source from the content-addressed store, hash-verified

6use nodedb_types::Value;
7
8pub(super) fn try_eval(name: &str, args: &[Value]) -> Option<Value> {
9 let v = match name {
10 "uuid" | "uuid_v4" | "gen_random_uuid" => Value::String(nodedb_types::id_gen::uuid_v4()),
11 "uuid_v7" => Value::String(nodedb_types::id_gen::uuid_v7()),
12 "ulid" => Value::String(nodedb_types::id_gen::ulid()),
13 "cuid2" => Value::String(nodedb_types::id_gen::cuid2()),
14 "nanoid" => {
15 let len = num_arg(args, 0).map(|n| n as usize);
16 match len {
17 Some(l) => Value::String(nodedb_types::id_gen::nanoid_with_length(l)),
18 None => Value::String(nodedb_types::id_gen::nanoid()),
19 }
20 }
21 "is_uuid" => bool_id_check(args, nodedb_types::id_gen::is_uuid),
22 "is_ulid" => bool_id_check(args, nodedb_types::id_gen::is_ulid),
23 "is_cuid2" => bool_id_check(args, nodedb_types::id_gen::is_cuid2),
24 "is_nanoid" => bool_id_check(args, nodedb_types::id_gen::is_nanoid),
25 "id_type" => args
26 .first()
27 .and_then(|v| v.as_str())
28 .map_or(Value::String("custom".into()), |s| {
29 Value::String(nodedb_types::id_gen::detect_id_type(s).as_str().to_string())
30 }),
31 "uuid_version" => args
32 .first()
33 .and_then(|v| v.as_str())
34 .map_or(Value::Integer(0), |s| {
35 Value::Integer(nodedb_types::id_gen::uuid_version(s) as i64)
36 }),
37 "ulid_timestamp" => args
38 .first()
39 .and_then(|v| v.as_str())
40 .and_then(nodedb_types::id_gen::ulid_timestamp_ms)
41 .map_or(Value::Null, |ms| Value::Integer(ms as i64)),
42 _ => return None,
43 };
44 Some(v)
45}

Callers 1

eval_functionFunction · 0.70

Calls 13

uuid_v4Function · 0.85
uuid_v7Function · 0.85
ulidFunction · 0.85
cuid2Function · 0.85
nanoid_with_lengthFunction · 0.85
nanoidFunction · 0.85
bool_id_checkFunction · 0.85
detect_id_typeFunction · 0.85
uuid_versionFunction · 0.85
firstMethod · 0.80
to_stringMethod · 0.80
num_argFunction · 0.70

Tested by

no test coverage detected