File

libs/core/src/lib/models/validation-config.model.ts

Extends

BasicValidationRule

Index

Properties

Properties

min
Type ResourceObject
Description

PFE_STORE_QUERY object to fetch minimal value number

type
Description

Specifies the type of the validator as DYNAMIC_MIN.

import { JsonValue } from '@angular-devkit/core';
import { ResourceObject } from './resource-object.model';

// Careful: Whenever this list changes, the configuration
// migration for validations also has to be updated here:
// libs/sdk/src/lib/journey/config/migrations/bb-plugin-validation-configs/bb-plugin-validation-configs.ts

// If this counter reaches 7, we'll introduces a sophisticated automatic way
// to extract the list from the ValidationRule type.
// Change counter: 0

export type ValidationRule =
  | RequiredValidatorRule
  | RequiredTrueValidatorRule
  | EmailValidatorRule
  | MinValidatorRule
  | DynamicMinValidatorRule
  | MaxValidatorRule
  | DynamicMaxValidatorRule
  | MinDateValidatorRule
  | MaxDateValidatorRule
  | MinLengthValidatorRule
  | MaxLengthValidatorRule
  | PatternValidatorRule
  | PluginValidationRule;

// This Typescript magic applies the Omit to all types within the intersection union:
//  https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
// It is used to remove the id attribute from all validation configuration data models, as this one is not required
// within the Dynamic Form
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;

export type DynamicFormValidationConfig = DistributiveOmit<ValidationRule, 'id'>;

interface BasicValidationRule {
  /**
   * Optional error message to be shown. If provided it will be the default translation for the error message, otherwise a default for the given validation type is used.
   */
  errorMessage?: string;
  /**
   * This value depends on the implementation of the given Building Block and usually refers to a form control path or name.
   * @examples ["myControl", "someFormGroup.field"]
   */
  id: string;
  /**
   * The type of validator to use. Can be any of the built-in validators as well as validators from plugins.
   * See the documentation for details: https://itmp-bb-library.frameworks.allianz.io/my-viewer/guides/integration-guide#building-blocks-needs-some-validation-config
   * @examples ["REQUIRED", "MIN_DATE", "PLUGIN_POSTCODE_VALIDATOR"]
   */
  type: string;
}

export interface RequiredValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `REQUIRED`.
   */
  type: 'REQUIRED';
}

export interface RequiredTrueValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `REQUIRED_TRUE`.
   */
  type: 'REQUIRED_TRUE';
}

export interface EmailValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `EMAIL`.
   */
  type: 'EMAIL';
}

export interface MinValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MIN`.
   */
  type: 'MIN';
  /**
   * Minimal value number
   */
  min: number;
}

export interface DynamicMinValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `DYNAMIC_MIN`.
   */
  type: 'DYNAMIC_MIN';
  /**
   * PFE_STORE_QUERY object to fetch minimal value number
   * @examples [{"type": "PFE_STORE_QUERY", "query": "$.minValue"}]
   */
  min: ResourceObject;
}

export interface MaxValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MAX`.
   */
  type: 'MAX';
  /**
   * Maximum value number
   */
  max: number;
}

export interface DynamicMaxValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `DYNAMIC_MAX`.
   */
  type: 'DYNAMIC_MAX';
  /**
   * PFE_STORE_QUERY object to fetch maximum value number
   * @examples [{"type": "PFE_STORE_QUERY", "query": "$.maxValue"}]
   */
  max: ResourceObject;
}

export interface MinDateValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MIN_DATE`.
   */
  type: 'MIN_DATE';
  /**
   * RFC-3339 string (i.e. 'yyyy-mm-dd') or a natural date string (e.g. 'today+2days')
   */
  minDate: string;
}

export interface MaxDateValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MAX_DATE`.
   */
  type: 'MAX_DATE';
  /**
   * RFC-3339 string (i.e. 'yyyy-mm-dd') or a natural date string (e.g. 'today+2days').
   */
  maxDate: string;
}

export interface MinLengthValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MIN_LENGTH`.
   */
  type: 'MIN_LENGTH';
  /**
   * Minimal length of characters
   */
  minLength: number;
}

export interface MaxLengthValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `MAX_LENGTH`.
   */
  type: 'MAX_LENGTH';
  /**
   * Maximum length of characters
   */
  maxLength: number;
}

export interface PatternValidatorRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `PATTERN`.
   */
  type: 'PATTERN';
  /**
   * Regex pattern.
   */
  pattern: string;
}

export interface PluginValidationRule extends BasicValidationRule {
  /**
   * Specifies the type of the validator as `PLUGIN`.
   */
  type: 'PLUGIN';
  /**
   * The name of the validator. It should match the value of the `type` field in the plugin validator implementation
   */
  name: string;
  /**
   * A validation parameter to be consumed by the validation function of the plugin validator.
   */
  validationParam?: ValidationParam;
}

export type ValidationParam = JsonValue | Record<string, unknown> | unknown[];

results matching ""

    No results matching ""