Member Junction
    Preparing search index...

    Abstract base class for semantic validators

    All semantic validators must extend this class and implement the validate() method.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get EvaluatesAbsentProp(): boolean

      Whether this validator also runs when the parent does not pass the property at all.

      By default a constraint is checked only against a prop the element actually passes, because most constraints describe a value ("these are field names on the entity") and have nothing to say about a missing one. A validator whose rule is about absence — "this prop must be set", "this prop must be set when another one is" — overrides this to return true. It is then also called for a missing prop, with context.PropertyPresent === false and context.propertyValue === undefined, and must handle that case.

      It is still not called for a missing prop when the element spreads props (<Grid {...props} />), since the spread may supply it.

      Returns boolean

    Methods

    • Apply custom error template

      If the constraint has an errorTemplate, applies it by replacing template variables with actual values.

      Template variables:

      • {property} - Property name from context
      • {value} - Property value from context
      • {constraint} - Constraint type
      • Custom variables from templateVars parameter

      Parameters

      • constraint: PropertyConstraint

        Constraint definition

      • context: ValidationContext

        Validation context

      • defaultMessage: string

        Default message to use if no template

      • templateVars: Record<string, any> = {}

        Additional template variables

      Returns string

      Formatted message

      // Constraint: { errorTemplate: "Field '{field}' not found on {entityName}" }
      const message = this.applyErrorTemplate(
      constraint,
      context,
      `Field '${field}' does not exist`,
      { field: 'FullName', entityName: 'Members' }
      );
      // => "Field 'FullName' not found on Members"
    • Create a violation with consistent formatting

      Helper method to create ConstraintViolation objects with common fields populated.

      Parameters

      • type: string

        Violation type (e.g., 'invalid-field', 'type-mismatch')

      • message: string

        Error message

      • severity: "critical" | "high" | "medium" | "low" = 'high'

        Severity level (default: 'high')

      • Optionalsuggestion: string

        Optional fix suggestion

      • Optionalmetadata: Record<string, any>

        Optional additional metadata

      Returns ConstraintViolation

      ConstraintViolation object

      return [
      this.createViolation(
      'invalid-field',
      `Field '${field}' does not exist on entity '${entityName}'`,
      'critical',
      `Use one of: ${validFields.join(', ')}`,
      { field, entityName, validFields }
      )
      ];
    • Find similar strings using Levenshtein distance

      Returns strings sorted by similarity (most similar first).

      Parameters

      • target: string

        The target string to find matches for

      • candidates: string[]

        Array of candidate strings

      • maxResults: number = 3

        Maximum number of results (default: 3)

      • maxDistance: number = 3

        Maximum edit distance to consider (default: 3)

      Returns string[]

      Array of similar strings, sorted by distance

      const fields = ['FirstName', 'LastName', 'Email', 'Status'];
      const similar = this.findSimilar('FristName', fields, 2);
      // => ['FirstName'] (edit distance 1)
    • Format a list of values for error messages

      Truncates long lists with "..." and formats values nicely.

      Parameters

      • values: any[]

        Array of values

      • maxItems: number = 10

        Maximum items to show (default: 10)

      Returns string

      Formatted string

      const fields = ['FirstName', 'LastName', 'Email', ...]; // 50 fields
      const formatted = this.formatValueList(fields, 5);
      // => "FirstName, LastName, Email, Status, JoinDate... (45 more)"