A service for changing the original value into something that you want a condition to evaluate using IDataTypeConverter instances.

This is essential for comparison Conditions. Comparison works automatically with string, number, and boolean native types. Converters exist to take a Date or user defined class to a string, number, or boolean. They are built on IDataTypeConverter.

Hierarchy (view full)

Implements

Constructors

Accessors

Methods

  • Return the value converted from the original value to the desired resultLookupKey. It may be a reworking of the original value, such as a Date object converted to a number of seconds, or a number rounded to an integer. Return null if the value represents null. Return undefined if the value was unconvertable. See also convertUntilResult() for a more complex conversion.

    Parameters

    • valueToConvert: any

      The value to be converted. Check its type and possibly its content.

    • sourceLookupKey: null | string

      The value can represent several other values, such as a Date represents date, time, etc. Use this when you need to distinguish between them. If null or '', evaluate the value itself, such as checking its class (using 'instanceof') or for properties of an interface that you are using. This is often the dataType property of the ValueHost.

    • resultLookupKey: string

    Returns ConversionResult

    An object identifying the converter used and the converted value. Its value parameter is undefined when the value was not converted. Its converterUsed parameter is undefined when no DataTypeConverter could be found to try the conversion. Note that DataTypeConverter.convert() can return undefined, allowing for value=undefined and converterUsed=assigned.

  • Applies a converter specific to the value based on the desired result lookup key. If the result is an object (like Date or custom), it repeats with the new value, hopefully resulting in a primitive value for use by the DefaultComparer. Date -> number using UTCDateConverter RelativeDate class with getDate(): Date property -> Date -> number using RelativeDateConverter and UTCDateConverter.

    Parameters

    • valueToConvert: any

      The value to be converted. Check its type and possibly its content.

    • sourceLookupKey: null | string

      The value can represent several other values, such as a Date represents date, time, etc. Use this when you need to distinguish between them. If null or '', evaluate the value itself, such as checking its class (using 'instanceof') or for properties of an interface that you are using. This is often the dataType property of the ValueHost.

    • resultLookupKey: string

    Returns ConversionResult

    An object identifying the converter used and the converted value. Its value parameter is undefined when the value was not converted. Its converterUsed parameter is undefined when no DataTypeConverter could be found to try the conversion. Note that DataTypeConverter.convert() can return undefined, allowing for value=undefined and converterUsed=assigned.

    Result Lookup Key

    • The lookup key that the result should be. When handling conditions, this is usually from conditionConfig.conversionLookupKey or secondConversionLookupKey.
  • This function attempts to convert a given value to a target lookup key specified by resultLookupKey, potentially through multiple intermediate conversion steps. It operates recursively, attempting to find a chain of converters that collectively can transform the input value into the desired output format.

    Each converter is capable of converting values to one or more output lookup keys, identified by DataTypeConverter.supportsResultLookupKeys.

    The function starts with the initial value and a sourceLookupKey (if applicable), trying to apply a converter that can handle this input. If successful, it checks if the output format matches the desired resultLookupKey. If not, it recursively attempts to find and apply a subsequent converter that can take this intermediate result closer to the target lookup key. This process repeats until either the target lookup key is achieved, or no suitable converter can be found.

    A DataTypeConverter can return values with these use cases:

    • undefined - The converter was the correct choice to use, but it could not convert the value. This is a valid result. It stops conversion when on the final step (resultLookupKey) and the value is undefined. Otherwise, it continues to try other converters.
    • null - The converter was the correct choice to use, and it successfully converted the value to null. This is a valid result. It stops conversion with this as a result. A null value can be returned by an intermediate step and still cause the result to be null. Supposed that you have 3 steps and on step 2, you get a null value. We have enough information to know that the final result will be null. We don't need to continue to step 3.
    • a value - The converter was the correct choice to use, and it successfully converted the value. This is a valid result. It stops conversion.

    A ConversionResult object is created and updated throughout this process to track the progress of the conversion, including any intermediate results obtained. If at any point a converter successfully processes the value, the ConversionResult.earlierResult property is updated, signaling that a valid conversion path exists up to that point. This property is used by callers of this function to determine whether a successful conversion chain has been established, and they should join in the chain.

    Exception handling for the conversion process is managed by the caller, specifically by the convertUntilResult function, to centralize error management and streamline the recursive logic. We want a failure deep in the recursion to bubble up to the top level, where it can be logged. We also want to retain the converter that failed. So we modify the Error object to include it in a property called 'converter'.

    Design note: This function travels deep first, going down a path until its either the right one or proven wrong. It then backtracks to try another path. In a multithreaded language, this would be better implemented as a breadth-first search. using threads.

    Parameters

    • valueToConvert: any

      The value to be converted.

    • sourceLookupKey: null | string

      The lookup key of the source format, or null if not applicable.

    • resultLookupKey: string

      The lookup key of the target format to achieve through conversion.

    • intermediateResultLK: null | string

      Intermediate lookup key used in recursive calls to track progress.

    • alreadyCheckedResultLK: Set<string>

      Lookup keys already checked, to avoid redundant conversions.

    Returns ConversionResult

    A ConversionResult object detailing the outcome of the conversion attempt.

Generated using TypeDoc v0.25.12