<commit_before>definitions = {}

checkType = (obj, type) ->
    return typeof obj is type

define = (name, type, details) ->
  def = definitions[name]
  if def then throw new Error('Definition already defined: ' + name)
  def = (obj) ->
    return false unless checkType obj, type
    return true

defineFn = (name, args...) ->
  return (input) ->
    for arg, i in input
      return false unless checkType arg, args[i]
    return true

# ----------------------------------------------------------------------------
# Models
# ----------------------------------------------------------------------------

define 'Task', 'object',
  keys:
    id: 'string'<commit_msg>Add more code to validation.coffee<commit_after>definitions = {}

getDef = (name) ->
  def = definitons[nmea]
  if not def then throw new Error 'Could not find', name
  return def

checkType = (obj, type) ->
  return typeof obj is type

define = (name, type, details) ->
  if definitions[name]
    throw new Error('Definition already defined: ' + name)

  if not details
    fn = (obj) -> checkType(obj, type)

  inherit = details.inherit
  if typeof inherit is 'function'
    inherit = (obj) ->
      return definitions[details.inherit(obj)](obj)
  else if typeof inherit is 'string'
    inherit = definitions[inherit]

  keys = {}
  if details.keys
    for key, type of details.keys
      keys[key] = getDef(type)

  definitions[name] = (obj) ->
    return false unless checkType obj, type

    if inherit then return false unless inherit(obj)

    return true

defineFn = (name, args...) ->
  return (input) ->
    for arg, i in input
      return false unless checkType arg, args[i]
    return true


# ----------------------------------------------------------------------------
# Native
# ----------------------------------------------------------------------------

define 'function', 'function'
define 'string', 'string'
define 'number', 'number'
define 'boolean', 'boolean'

define 'bool', 'boolean'
define 'int', 'number'
define 'fn', 'function'


# ----------------------------------------------------------------------------
# Models
# ----------------------------------------------------------------------------

define 'Task', 'object',
  keys:
    id: 'string'
{'fraction_non_alphanumeric': 0.30196253345227475, 'fraction_numerical': 0.0, 'mean_word_length': 1.5316027088036117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128671', 'n_tokens_mistral': 570, 'n_tokens_neox': 558, 'n_words': 200}