text: "use strict";
  /*
  * indicative-rules
  *
  * (c) Harminder Virk <virk@adonisjs.com>
  *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
  Object.defineProperty(exports, "__esModule", { value: true });
  const indicative_utils_1 = require("indicative-utils");
  const MISSING_VALUE = 'max: make sure to define max length';
  const INVALID_TYPE = 'max: length must be defined as an integer';
  /**
   * Enforces the value to have maximum length as per defined by the rule. The
   * value type has to be a `string` or `array`, otherwise validation will
   * fail.
   *
   * ```ts
   * import { validations } from 'indicative/validator'
   *
   * const rules = {
   *   username: 'max:40'
   * }
   *
   * // or
   * const rules = {
   *   username: [
   *     validations.max([40])
   *   ]
   * }
   * ```
   */
  const validation = {
      async: false,
      /**
       * Cleaning up user arguments to make sure that they are
       * useable at runtime
       */
      compile(args) {
          indicative_utils_1.ensureLength(args, MISSING_VALUE, 1);
          const maxLength = indicative_utils_1.cast(args[0], 'integer', INVALID_TYPE);
          return [maxLength];
      },
      /**
       * Validating runtime data
       */
      validate: (data, field, [maxLength], config) => {
          const fieldValue = indicative_utils_1.getValue(data, field);
          if (indicative_utils_1.skippable(fieldValue, field, config)) {
              return true;
          }
          if (Array.isArray(fieldValue) || typeof (fieldValue) === 'string') {
              return fieldValue.length <= maxLength;
          }
          return false;
      },
  };
  exports.default = validation;
  