Interface ICondition

The basis for any condition that you want to work with these validators. There are a number of implementations based on its subclass IConditionCore, all which allow a Config approach of configuration. Implement this directly when you want to handle all of the work in the evaluate() function yourself, and supply your own way of configuring.

NOTE: Classes that implement ICondition can introduce IDisposable knowing the dispose function will be called as a Validator is disposed. Conditions that reference other conditions should call toDisposable(cond)?.dispose() in response.

interface ICondition {
    conditionType: string;
    category: ConditionCategory;
    evaluate(valueHost, valueHostsManager): ConditionEvaluateResult | Promise<ConditionEvaluateResult>;
}

Hierarchy (view full)

Implemented by

Properties

Methods

Properties

conditionType: string

A unique identifier for the specific implementation, like "RequireText" or "Range". Its value appears in the IssueFound.errorCode property unless overridden in ValidatorConfig.errorCode. It allows the consumer of both to correlate those instances with the specific condition. When defining conditions through a ConditionConfig, the conditionType property must be assigned with a valid ConditionType.

Helps identify the purpose of the Condition. Impacts:

  • Sort order of the list of Conditions evaluated by an Validator, placing Require first and DataTypeCheck second.
  • Sets InputValueHostConfig.requiresInput.
  • Sets ValidatorConfig.severity when undefined, where Require and DataTypeCheck will use Severe. Others will use Error. Many Conditions have this value predefined. However, all will let the user override it with ConditionConfig.category.

Methods

  • Evaluate something against the rules defined in the implementation. Return whether the data was consistent or violates the rules, or the data couldn't be used to run the rule.

    Parameters

    • valueHost: null | IValueHost

      Most values are found amongst the ValueHosts in the ValueHostsManager. Conditions can look them up using ValueHostsManager.getValueHost().getValue() or getInputValue(). This parameter is used as an optimization, both to avoid that lookup and to avoid the user typing in a ValueHostName when creating the Condition instance. Validator.validate() knows to pass the ValueHostName that hosts the Validator. Expect this to be null in other cases, such as when Condition is a child of the AllMatchCondition and its peers. In otherwords, support both ways.

    • valueHostsManager: IValueHostsManager

      Its primary use is to lookup ValueHosts to get their data.

    Returns ConditionEvaluateResult | Promise<ConditionEvaluateResult>

    Any of these values:

    • Match - consistent with the rule
    • NoMatch - violates the rule
    • Undetermined - Cannot invoke the rule. Usually data incompatible with use within the rule, like the value is null, undefined, or the wrong data type.

Generated using TypeDoc v0.25.12