lib/record_type/validate.js
function validateField (fields, key) {
  var value = fields[key] = castShorthand(fields[key])

  if (typeof value !== 'object')
    throw new TypeError('The definition of "' + key + '" must be an object.')

  if (key === primaryKey)
    throw new Error('Can not define primary key "' + primaryKey + '".')

  if (key in plainObject)
    throw new Error('Can not define field name "' + key +
      '" which is in Object.prototype.')

  if (!value[typeKey] && !value[linkKey])
    throw new Error('The definition of "' + key + '" must contain either ' +
      'the "' + typeKey + '" or "' + linkKey + '" property.')

  if (value[typeKey] && value[linkKey])
    throw new Error('Can not define both "' + typeKey + '" and "' + linkKey +
      '" on "' + key + '".')

  if (value[typeKey]) {
    if (typeof value[typeKey] === 'string')
      value[typeKey] = nativeTypes[
        stringifiedTypes.indexOf(value[typeKey].toLowerCase())]

    if (typeof value[typeKey] !== 'function')
      throw new Error('The "' + typeKey + '" on "' + key +
        '" must be a function.')

    if (!find(nativeTypes, function (type) {
      var hasMatch = type === value[typeKey] ||
        type.name === value[typeKey].name

      // In case this errors due to security sandboxing, just skip this check.
      if (!hasMatch)
        try {
          hasMatch = Object.create(value[typeKey]) instanceof type
        }
        catch (e) {
          hasMatch = true
        }

      return hasMatch
    }))
      throw new Error('The "' + typeKey + '" on "' + key + '" must be or ' +
        'inherit from a valid native type.')

    if (value[inverseKey])
      throw new Error('The field "' + inverseKey + '" may not be defined ' +
        'on "' + key + '".')
  }

  if (value[linkKey]) {
    if (typeof value[linkKey] !== 'string')
      throw new TypeError('The "' + linkKey + '" on "' + key +
        '" must be a string.')

    if (value[inverseKey] && typeof value[inverseKey] !== 'string')
      throw new TypeError('The "' + inverseKey + '" on "' + key + '" ' +
        'must be a string.')
  }

  if (value[isArrayKey] && typeof value[isArrayKey] !== 'boolean')
    throw new TypeError('The key "' + isArrayKey + '" on "' + key + '" ' +
        'must be a boolean.')
}
function validateField (fields, key) {
  var value = fields[key] = castShorthand(fields[key])

  if (typeof value !== 'object')
    throw new TypeError('The definition of "' + key + '" must be an object.')

  if (key === primaryKey)
    throw new Error('Can not define primary key "' + primaryKey + '".')

  if (key in plainObject)
    throw new Error('Can not define field name "' + key +
      '" which is in Object.prototype.')

  if (!value[typeKey] && !value[linkKey])
    throw new Error('The definition of "' + key + '" must contain either ' +
      'the "' + typeKey + '" or "' + linkKey + '" property.')

  if (value[typeKey] && value[linkKey])
    throw new Error('Can not define both "' + typeKey + '" and "' + linkKey +
      '" on "' + key + '".')

  if (value[typeKey]) {
    if (typeof value[typeKey] === 'string')
      value[typeKey] = nativeTypes[
        stringifiedTypes.indexOf(value[typeKey].toLowerCase())]

    if (typeof value[typeKey] !== 'function')
      throw new Error('The "' + typeKey + '" on "' + key +
        '" must be a function.')

    if (!find(nativeTypes, function (type) {
      var hasMatch = type === value[typeKey] ||
        type.name === value[typeKey].name

      // In case this errors due to security sandboxing, just skip this check.
      if (!hasMatch)
        try {
          hasMatch = Object.create(value[typeKey]) instanceof type
        }
        catch (e) {
          hasMatch = true
        }

      return hasMatch
    }))
      throw new Error('The "' + typeKey + '" on "' + key + '" must be or ' +
        'inherit from a valid native type.')

    if (value[inverseKey])
      throw new Error('The field "' + inverseKey + '" may not be defined ' +
        'on "' + key + '".')
  }

  if (value[linkKey]) {
    if (typeof value[linkKey] !== 'string')
      throw new TypeError('The "' + linkKey + '" on "' + key +
        '" must be a string.')

    if (value[inverseKey] && typeof value[inverseKey] !== 'string')
      throw new TypeError('The "' + inverseKey + '" on "' + key + '" ' +
        'must be a string.')
  }

  if (value[isArrayKey] && typeof value[isArrayKey] !== 'boolean')
    throw new TypeError('The key "' + isArrayKey + '" on "' + key + '" ' +
        'must be a boolean.')
}
function validateField ( fields , key ) { var value = fields [ key ] = castShorthand ( fields [ key ] ) if ( typeof value !== 'object' ) throw new TypeError ( 'The definition of "' + key + '" must be an object.' ) if ( key === primaryKey ) throw new Error ( 'Can not define primary key "' + primaryKey + '".' ) if ( key in plainObject ) throw new Error ( 'Can not define field name "' + key + '" which is in Object.prototype.' ) if ( ! value [ typeKey ] && ! value [ linkKey ] ) throw new Error ( 'The definition of "' + key + '" must contain either ' + 'the "' + typeKey + '" or "' + linkKey + '" property.' ) if ( value [ typeKey ] && value [ linkKey ] ) throw new Error ( 'Can not define both "' + typeKey + '" and "' + linkKey + '" on "' + key + '".' ) if ( value [ typeKey ] ) { if ( typeof value [ typeKey ] === 'string' ) value [ typeKey ] = nativeTypes [ stringifiedTypes . indexOf ( value [ typeKey ] . toLowerCase ( ) ) ] if ( typeof value [ typeKey ] !== 'function' ) throw new Error ( 'The "' + typeKey + '" on "' + key + '" must be a function.' ) if ( ! find ( nativeTypes , function ( type ) { var hasMatch = type === value [ typeKey ] || type . name === value [ typeKey ] . name // In case this errors due to security sandboxing, just skip this check. if ( ! hasMatch ) try { hasMatch = Object . create ( value [ typeKey ] ) instanceof type } catch ( e ) { hasMatch = true } return hasMatch } ) ) throw new Error ( 'The "' + typeKey + '" on "' + key + '" must be or ' + 'inherit from a valid native type.' ) if ( value [ inverseKey ] ) throw new Error ( 'The field "' + inverseKey + '" may not be defined ' + 'on "' + key + '".' ) } if ( value [ linkKey ] ) { if ( typeof value [ linkKey ] !== 'string' ) throw new TypeError ( 'The "' + linkKey + '" on "' + key + '" must be a string.' ) if ( value [ inverseKey ] && typeof value [ inverseKey ] !== 'string' ) throw new TypeError ( 'The "' + inverseKey + '" on "' + key + '" ' + 'must be a string.' ) } if ( value [ isArrayKey ] && typeof value [ isArrayKey ] !== 'boolean' ) throw new TypeError ( 'The key "' + isArrayKey + '" on "' + key + '" ' + 'must be a boolean.' ) }
Parse a field definition.

@param {Object} fields
@param {String} key
Parse a field definition .