@function requireValidColumn

validate column from model specification

@param {string} name
@param {object} spec

@returns {object}

@throws {Error}
967670
function requireValidColumn (name, spec) {
    // if spec is a string then convert to object using string
    // as type and name as the path for getting value from data
    if (typeof spec === 'string') {
        // capture type
        var type = spec
        // create new spec with default spect
        spec = _.cloneDeep(defaultColumnSpec)
        // set type
        spec.type = type
        // use the column name as path
        spec.path = name
    }
    // require object
    assert(spec && typeof spec === 'object', 'column spec must be obect for '+name)
    // default path to name
    if (typeof spec.path !== 'string') {
        spec.path = name
    }
    // if column is unique and firstOnly is not defined then default true
    if (spec.unique && spec.firstOnly === undefined) {
        spec.firstOnly = true
    }
    // if firstOnly is true then colum must be nullable
    if (spec.firstOnly && spec.null === 'false') {
        throw new Error(name+' must be nullable')
    }
    // require valid type
    assert.ok(sql.columnTypes[spec.type], name+' invalid type: '+spec.type)
    // return validated spec
    return spec
}
417569
public static void requireArgValid(@NotNull final String name, @NotNull final String value) throws ConstraintViolationException {
        // CHECKSTYLE:ON

        final String trimmedLowerCaseValue = value.trim().toLowerCase();
        if (!isValid(trimmedLowerCaseValue)) {
            throw new ConstraintViolationException("The argument '" + name + "' is not valid: '" + trimmedLowerCaseValue + "'");
        }

    }
705463
function validate (schema, data, key) {
  let value = data[key]
  const bool = value == null || value === ''
  const { required, type, validate, transform, elements } = schema
  const def = schema['default']
  // trigger error if undefined but required
  if (required && bool) throw new Error(`field ${key} is missing`)
  // coerce to type
  if (type && !bool) {
    let before = coerce(type, key, value)
    data[key] = elements
      ? (type === 'object' ? validator(before, elements) : before.map(item => validator(item, elements)))
      : before
  }
  // validate value
  if (validate) {
    const cb = check(validate, key)
    if (type === 'array') value.map(cb)
    else cb(value)
  }
  // apply default value
  if (def && bool) data[key] = def
  // apply transform
  if (transform && def == null) {
    data[key] = typeof transform === 'function'
      ? (type === 'array' ? value.map(transform) : transform(value))
      : transform
  }
}
1069965
def spec(name, type = nil, mode = nil, &block)
      return specs(name, type) unless block_given?
      fail 'A type argument is required when defining a spec!' unless type
      _specs
      name = name_audit(name)
      fail 'Specification names must be of SPEC_TYPES Symbol or String and cannot start with a number' if name.nil?
      fail "Spec type must be one of #{SPEC_TYPES.join(', ')}" unless SPEC_TYPES.include? type
      type = type
      mode = get_mode if mode.nil?
      owner_name = ''
      if self.respond_to?(:name) && send(:name)
        owner_name = self.name.to_s.downcase.to_sym
      elsif self == Origen.top_level
        owner_name = self.class.to_s.split('::').last.downcase.to_sym
      else
        owner_name = self.class.to_s.split('::').last.downcase.to_sym
      end
      spec_placeholder = Spec
                         .new(name, type, mode, owner_name, &block)
      # Check if the spec already exists
      if has_spec?(name, type: type, mode: mode, sub_type: spec_placeholder.sub_type, creating_spec: true)
        # Spec already exists.  Go ahead flag error and drop processing.
        # This is a fatal error.
        fail "Spec already exists for name: #{name}, type: #{type}, mode: #{mode} for object #{self}"
      end
      @_specs[name][mode][type][spec_placeholder.sub_type] = spec_placeholder
    end
266951
function validateMetaType(name, metaType) {
        assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
        assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
        assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType });

        // Enum MetaType
        if (metaType.kind === "enum") {
            var lits = metaType.literals;
            assert(Array.isArray(lits) && lits.length > 0, ERR_ENUM_HAS_LITERALS, { metaType: metaType });

            // Check duplicated literal
            _.each(lits, function (lit1) {
                var len = _.filter(lits, function (lit2) { return lit2 === lit1; }).length;
                assert(len === 1, ERR_DUPLICATED_LITERAL, { metaType: metaType, literal: lit1 });
            });
        }

        // Class MetaType
        if (metaType.kind === "class") {

            // Check .super
            if (metaType.super) {
                assert(metaType.super && _global.meta[metaType.super], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: metaType.super, field: "super" });
            }

            // Check Attributes
            if (metaType.attributes) {
                assert(Array.isArray(metaType.attributes), ERR_FIELD_TYPE, { metaType: metaType, field: "attributes", type: "Array" });
                _.each(metaType.attributes, function (attribute) {

                    // check 'name'
                    assert(attribute.name, ERR_UNNAMED_ATTRIBUTE, { metaType: metaType });

                    // Check 'kind'
                    assert(_.contains(["prim", "enum", "var", "ref", "refs", "obj", "objs", "custom"], attribute.kind), ERR_ATTRIBUTE_KIND, { metaType: metaType, attribute: attribute });

                    // Check 'type'
                    if (attribute.kind === "prim") {
                        assert(_.contains(["Integer", "String", "Boolean", "Real"], attribute.type), ERR_ATTRIBUTE_PRIM_TYPE, { metaType: metaType, attribute: attribute });
                    } else if (attribute.kind !== "custom") {
                        assert(_global.meta[attribute.type], ERR_TYPE_NOT_FOUND, { metaType: metaType, type: attribute.type, field: attribute.name + ".type" });
                    }

                    // Check duplicated attribute in all inherited attributes
                    var len = _.filter(getMetaAttributes(metaType.name), function (attr) { return attr.name === attribute.name; }).length;
                    assert(len === 1, ERR_DUPLICATED_ATTRIBUTE, { metaType: metaType, attribute: attribute });
                });
            }
        }
    }
423405
function checkValidators(spec) {
  if (!spec.validate) return;

  let text;
  if (spec.validate.body) {
    text = 'validate.type must be declared when using validate.body';
    assert(/json|form/.test(spec.validate.type), text);
  }

  if (spec.validate.type) {
    text = 'validate.type must be either json, form, multipart or stream';
    assert(/json|form|multipart|stream/i.test(spec.validate.type), text);
  }

  if (spec.validate.output) {
    spec.validate._outputValidator = new OutputValidator(spec.validate.output);
  }

  // default HTTP status code for failures
  if (!spec.validate.failure) {
    spec.validate.failure = 400;
  }
}
347859
function loadModel(modelSpecPath, name) {
  return plugin.myrmex.fire('beforeModelLoad', modelSpecPath, name)
  .spread(() => {
    // Because we use require() to get the spec, it could either be a JSON file
    // or the content exported by a node module
    // But because require() caches the content it loads, we clone the result to avoid bugs
    // if the function is called twice
    const modelSpec = _.cloneDeep(require(modelSpecPath));

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./model
    const Model = require('./model');
    return Promise.resolve(new Model(name, modelSpec));
  })
  .then(model => {
    // This event allows to inject code to alter the model specification
    return plugin.myrmex.fire('afterModelLoad', model);
  })
  .spread((model) => {
    return Promise.resolve(model);
  });
}
521813
function getColumnName(columnDefinitions, property) {
    Validate.isObject(columnDefinitions);
    Validate.notNull(columnDefinitions);
    Validate.isString(property);
    Validate.notNullOrEmpty(property);

    for (var column in columnDefinitions) {
        if (column.toLowerCase() === property.toLowerCase()) {
            return column;
        }
    }

    return property; // If no definition found for property, simply returns the column name as is
}
1177057
function validateColumns(columns) {
  if (!columns) {
    return;
  }

  // check IDs
  var ids = {};
  columns.forEach(function (column, i) {
    var id = column.id;

    if (!ids[id]) {
      ids[id] = [i];
    } else {
      ids[id].push(i);
    }
  });
  Object.keys(ids).forEach(function (id) {
    if (ids[id].length > 1) {
      console.warn('Column ID \'' + id + '\' used in multiple columns ' + ids[id].join(', '), ids[id].map(function (index) {
        return columns[index];
      }));
    }
  });
}
157667
public static function require_field($table, $field, $spec)
    {
        self::get_schema()->requireField($table, $field, $spec);
    }
78570
public void expectValue(String name, String message) {
        String value = Optional.ofNullable(get(name)).orElse("");

        if (StringUtils.isBlank(StringUtils.trimToNull(value))) {
            addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.REQUIRED_KEY.name(), name)));
        }
    }
882717
function validateRequired(config, commandSpec) {
  var errors = '';
  
  if (commandSpec.parameters) {
    commandSpec.parameters.forEach(function(param) {
      if (param.required == true
      && (config[param.name] == '' || config[param.name] == []) ) {
        errors += 'Parameter ' + param.name + ' is required\n';
      }
    })
  }
  
  if (commandSpec.options) {
    for (var i=0;i<commandSpec.options.length;i++) {
      if (commandSpec.options[i].required
      && commandSpec.options[i].required == true
      && config.options[commandSpec.options[i].option] == '') {
        errors += 'Option ' + commandSpec.options[i].option + ' is required\n';
      }
    }
  }
  
  if (commandSpec.environment) {
    for (var i=0;i<commandSpec.environment.length;i++) {
      if (commandSpec.environment[i].required
      && commandSpec.environment[i].required == true
      && config.environment[commandSpec.environment[i].parameter] == '') {
        errors += 'Environment ' + commandSpec.environment[i].parameter + ' is required\n';
      }      
    }
  }
  
  if (errors != '') errors = errors.substring(0, errors.length-1);   //remove trailing newline
  return errors;
}
1264152
function create (id, spec) {
  validateModifiers(id, spec, [])
  const entity = {}
  entity.spec = spec
  return entity
}
1309940
function tv4_validate(typename, query) {
        var id = getSchemaIDFromTypename(typename);
        var schema = tv4.getSchema(id);
        if (schema == null) {
            var error = { code: 0, message: 'Schema not found', dataPath: '', schemaPath: id };
            return { valid: false, missing: [], errors: [error] };
        }
        var report = tv4.validateMultiple(query, schema);
        return report;
    }
1244329
private String ensureUnqualified(String name) {
        if (name.startsWith(String.format("%s.", this.modelInfo.getName()))) {
            return name.substring(name.indexOf('.') + 1);
        }

        return name;
    }
844685
function (name) {
        var
            idx;
        if (0 === name.length
            || -1 === _firstValidChar.indexOf(name.charAt(0))) {
            return false;
        }
        for (idx = 1; idx < name.length; ++idx) {
            if (-1 === _otherValidChars.indexOf(name.charAt(idx))) {
                return false;
            }
        }
        return true;
    }
541840
function requireValidIndexes (indexes) {
    // throw error on invalid indexes option
    assert.ok(Array.isArray(indexes), 'indexes must be array')
    // validate each index spec
    _.each(indexes, index => {
        // require columns to be array
        assert.ok(Array.isArray(index.columns), 'index columns must be array')
        // require multiple columns
        assert.ok(index.columns.length > 1, 'index must have at least 2 columns')
    })
    // return validated indexes
    return indexes
}