<commit_before>require! path
require! machine

{syntax-validator} = require '../lib/syntax'

export function ensured-component-options(options)
  #@TODO: check component options.
  return options

export function ensured-component(component)
  validate = syntax-validator 'Component'
  if validate component
    # JSON Schema does not support function type, we need 
    # check it by ourself.
    if typeof component.fn is 'function'
      #@TODO: check component function signature.
      return component
    else
      throw new Error "component.fn is not a function."
  else
    throw validate.errors

export function load-component(fpath, options)
  mod = require path.resolve fpath  
  unless mod.provide-component?
    throw "module loaded from #{path} does not have provideComponent function."
  options = ensured-component-options options 
  defs = mod.provide-component options
  # @TODO: check definition
  return defs <<< do
    inports: defs.inputs
    outports: defs.outputs
    machine: machine.build defs<commit_msg>fix typo.<commit_after>require! path
require! machine

{syntax-validator} = require '../lib/syntax'

export function ensured-component-options(options)
  #@TODO: check component options.
  return options

export function ensured-component(component)
  validate = syntax-validator 'Component'
  if validate component
    # JSON Schema does not support function type, we need 
    # check it by ourself.
    if typeof component.fn is 'function'
      #@TODO: check component function signature.
      return component
    else
      throw new Error "component.fn is not a function."
  else
    throw validate.errors

export function load-component(fpath, options)
  mod = require path.resolve fpath  
  unless mod.provide-component?
    throw "module loaded from #{fpath} does not have provideComponent function."
  options = ensured-component-options options 
  defs = mod.provide-component options
  # @TODO: check definition
  return defs <<< do
    inports: defs.inputs
    outports: defs.outputs
    machine: machine.build defs
{'fraction_non_alphanumeric': 0.07707222491517209, 'fraction_numerical': 0.0, 'mean_word_length': 3.6382022471910114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '460012', 'n_tokens_mistral': 564, 'n_tokens_neox': 549, 'n_words': 202}