Class ConditionBase<TConditionConfig>Abstract

Base implementation of ICondition. Subclass to build a business rule that will evaluate value(s). Conditions exist for each business rule pattern, such as required, string matches the data type, compare value to another. Instances should be registered in the ConditionFactory.

Type Parameters

Hierarchy (view full)

Implements

Constructors

Accessors

  • get conditionType(): string
  • A unique identifier for the specific implementation, like "RequireText" or "Range". Its value appears in the IssueFound that comes from Validation, and in IssueFound that comes from retrieving a list of errors to display. It allows the consumer of both to correlate those instances with the specific condition. When defining conditions through a ConditionConfig, the Type property must be assigned with a valid ConditionType. This property always returns what the user supplied in the Config.conditionType, not the default conditiontype. That allows multiple instances of the same condition Class to participate in one validator's list of conditions, because each has a unique ConditionType.

    Returns string

  • get category(): ConditionCategory
  • 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.

    Returns ConditionCategory

Methods

  • Implementation for IMessageTokenSource. Conditions havea number of values that are appropriate for tokens on the ConditionConfig. Examples:

    • In RangeCondition, Minimum and Maximum properties become {Mininum} and {Maximum} tokens.
    • In CompareToValueCondition, secondValueHostName property is the source for the {CompareTo} token. This implementation feels like it violates Single Responsibility pattern. But keeping this feature separate from conditions greatly increases complexity.

    Parameters

    Returns TokenLabelAndValue[]

    An array. If an empty array if there are no token to offer. This base class has no tokens to offer.

  • Converts the given value and lookup key using the provided conversion lookup key. If the conversion fails, a warning log is generated. Takes no action if the conversionLookupKey is null.

    Parameters

    • value: any

      The value to be converted.

    • valueLookupKey: undefined | null | string

      The lookup key associated with the value. Often this should be assigned to valueHost.getDataType().

    • conversionLookupKey: undefined | null | string

      The conversion lookup key to be used for conversion. Often this comes from conversionLookupKey or secondConversionLookupKey found on the Config object.

    • services: IValueHostsServices

      The services

    Returns {
        value?: any;
        lookupKey?: null | string;
        failed: boolean;
    }

    An object containing the converted value, lookup key, and a flag indicating if the conversion failed.

    • Optional value?: any
    • Optional lookupKey?: null | string
    • failed: boolean
  • Logs the invalid property data and throws a CodingError.

    Parameters

    • propertyName: string

      The name of the invalid property.

    • errorMessage: string

      The error message describing the invalid property data.

    • services: IValueHostsServices

      The value host services.

    Returns void

    Throws

    • Throws a CodingError with the specified error message.

Generated using TypeDoc v0.25.12