MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / validate_property_constraint

Method validate_property_constraint

graphlite/src/schema/validator.rs:332–406  ·  view source on GitHub ↗

ROADMAP v0.4.0 - Property constraint validation (UNIQUE, CHECK, RANGE) for graph types

(
        &self,
        value: &Value,
        constraint: &Constraint,
    )

Source from the content-addressed store, hash-verified

330 /// Validate node constraints
331 #[allow(dead_code)] // ROADMAP v0.4.0 - Property constraint validation (UNIQUE, CHECK, RANGE) for graph types
332 fn validate_property_constraint(
333 &self,
334 value: &Value,
335 constraint: &Constraint,
336 ) -> Result<(), ValidationError> {
337 match constraint {
338 Constraint::MinLength(min) => {
339 if let Value::String(s) = value {
340 if s.len() < *min {
341 return Err(ValidationError::ConstraintViolation {
342 constraint: "MinLength".to_string(),
343 message: format!(
344 "String length {} is less than minimum {}",
345 s.len(),
346 min
347 ),
348 });
349 }
350 }
351 }
352 Constraint::MaxLength(max) => {
353 if let Value::String(s) = value {
354 if s.len() > *max {
355 return Err(ValidationError::ConstraintViolation {
356 constraint: "MaxLength".to_string(),
357 message: format!("String length {} exceeds maximum {}", s.len(), max),
358 });
359 }
360 }
361 }
362 Constraint::Pattern(pattern) => {
363 if let Value::String(s) = value {
364 let regex = regex::Regex::new(pattern)
365 .map_err(|e| ValidationError::InvalidValue(e.to_string()))?;
366 if !regex.is_match(s) {
367 return Err(ValidationError::ConstraintViolation {
368 constraint: "Pattern".to_string(),
369 message: format!("Value '{}' does not match pattern '{}'", s, pattern),
370 });
371 }
372 }
373 }
374 Constraint::MinValue(min) => {
375 if let Value::Number(n) = value {
376 if let Some(num_val) = n.as_f64() {
377 if num_val < *min {
378 return Err(ValidationError::ConstraintViolation {
379 constraint: "MinValue".to_string(),
380 message: format!("Value {} is less than minimum {}", num_val, min),
381 });
382 }
383 }
384 }
385 }
386 Constraint::MaxValue(max) => {
387 if let Value::Number(n) = value {
388 if let Some(num_val) = n.as_f64() {
389 if num_val > *max {

Callers 1

validate_partial_nodeMethod · 0.80

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected