server/drivers/index.js
function requireValidate(path, optional = false) {
  let driver;

  try {
    driver = require(path);
  } catch (er) {
    if (optional) {
      console.log('optional driver ' + path + ' not available');
      return;
    } else {
      // rethrow
      throw er;
    }
  }

  if (!driver.id) {
    console.error(`${path} must export a unique id`);
    process.exit(1);
  }

  if (!driver.name) {
    console.error(`${path} must export a name`);
    process.exit(1);
  }

  if (drivers[driver.id]) {
    console.error(`Driver with id ${driver.id} already loaded`);
    console.error(`Ensure ${path} has a unique id exported`);
    process.exit(1);
  }

  validateFunction(path, driver, 'getSchema');
  validateFunction(path, driver, 'runQuery');
  validateFunction(path, driver, 'testConnection');
  validateArray(path, driver, 'fields');

  driver.fieldsByKey = {};

  driver.fields.forEach(field => {
    driver.fieldsByKey[field.key] = field;
  });

  drivers[driver.id] = driver;
}
function requireValidate(path, optional = false) {
  let driver;

  try {
    driver = require(path);
  } catch (er) {
    if (optional) {
      console.log('optional driver ' + path + ' not available');
      return;
    } else {
      // rethrow
      throw er;
    }
  }

  if (!driver.id) {
    console.error(`${path} must export a unique id`);
    process.exit(1);
  }

  if (!driver.name) {
    console.error(`${path} must export a name`);
    process.exit(1);
  }

  if (drivers[driver.id]) {
    console.error(`Driver with id ${driver.id} already loaded`);
    console.error(`Ensure ${path} has a unique id exported`);
    process.exit(1);
  }

  validateFunction(path, driver, 'getSchema');
  validateFunction(path, driver, 'runQuery');
  validateFunction(path, driver, 'testConnection');
  validateArray(path, driver, 'fields');

  driver.fieldsByKey = {};

  driver.fields.forEach(field => {
    driver.fieldsByKey[field.key] = field;
  });

  drivers[driver.id] = driver;
}
function requireValidate ( path , optional = false ) { let driver ; try { driver = require ( path ) ; } catch ( er ) { if ( optional ) { console . log ( 'optional driver ' + path + ' not available' ) ; return ; } else { // rethrow throw er ; } } if ( ! driver . id ) { console . error ( ` ${ path } ` ) ; process . exit ( 1 ) ; } if ( ! driver . name ) { console . error ( ` ${ path } ` ) ; process . exit ( 1 ) ; } if ( drivers [ driver . id ] ) { console . error ( ` ${ driver . id } ` ) ; console . error ( ` ${ path } ` ) ; process . exit ( 1 ) ; } validateFunction ( path , driver , 'getSchema' ) ; validateFunction ( path , driver , 'runQuery' ) ; validateFunction ( path , driver , 'testConnection' ) ; validateArray ( path , driver , 'fields' ) ; driver . fieldsByKey = { } ; driver . fields . forEach ( field => { driver . fieldsByKey [ field . key ] = field ; } ) ; drivers [ driver . id ] = driver ; }
Require driver implementation for provided path
and validate that it meets implementation spec as possible
@param {string} path
Require driver implementation for provided path and validate that it meets implementation spec as possible