server/drivers/index.js
function validateConnection(connection) {
  const coreFields = ['_id', 'name', 'driver', 'createdDate', 'modifiedDate'];
  if (!connection.name) {
    throw new Error('connection.name required');
  }
  if (!connection.driver) {
    throw new Error('connection.driver required');
  }
  const driver = drivers[connection.driver];
  if (!driver) {
    throw new Error(`driver implementation ${connection.driver} not found`);
  }
  const validFields = driver.fields.map(field => field.key).concat(coreFields);
  const cleanedConnection = validFields.reduce(
    (cleanedConnection, fieldKey) => {
      if (connection.hasOwnProperty(fieldKey)) {
        let value = connection[fieldKey];
        const fieldDefinition =
          drivers[connection.driver].fieldsByKey[fieldKey];

        // field definition may not exist since
        // this could be a core field like _id, name
        if (fieldDefinition) {
          if (fieldDefinition.formType === 'CHECKBOX') {
            value = utils.ensureBoolean(value);
          }
        }

        cleanedConnection[fieldKey] = value;
      }
      return cleanedConnection;
    },
    {}
  );

  return cleanedConnection;
}
function validateConnection(connection) {
  const coreFields = ['_id', 'name', 'driver', 'createdDate', 'modifiedDate'];
  if (!connection.name) {
    throw new Error('connection.name required');
  }
  if (!connection.driver) {
    throw new Error('connection.driver required');
  }
  const driver = drivers[connection.driver];
  if (!driver) {
    throw new Error(`driver implementation ${connection.driver} not found`);
  }
  const validFields = driver.fields.map(field => field.key).concat(coreFields);
  const cleanedConnection = validFields.reduce(
    (cleanedConnection, fieldKey) => {
      if (connection.hasOwnProperty(fieldKey)) {
        let value = connection[fieldKey];
        const fieldDefinition =
          drivers[connection.driver].fieldsByKey[fieldKey];

        // field definition may not exist since
        // this could be a core field like _id, name
        if (fieldDefinition) {
          if (fieldDefinition.formType === 'CHECKBOX') {
            value = utils.ensureBoolean(value);
          }
        }

        cleanedConnection[fieldKey] = value;
      }
      return cleanedConnection;
    },
    {}
  );

  return cleanedConnection;
}
function validateConnection ( connection ) { const coreFields = [ '_id' , 'name' , 'driver' , 'createdDate' , 'modifiedDate' ] ; if ( ! connection . name ) { throw new Error ( 'connection.name required' ) ; } if ( ! connection . driver ) { throw new Error ( 'connection.driver required' ) ; } const driver = drivers [ connection . driver ] ; if ( ! driver ) { throw new Error ( ` ${ connection . driver } ` ) ; } const validFields = driver . fields . map ( field => field . key ) . concat ( coreFields ) ; const cleanedConnection = validFields . reduce ( ( cleanedConnection , fieldKey ) => { if ( connection . hasOwnProperty ( fieldKey ) ) { let value = connection [ fieldKey ] ; const fieldDefinition = drivers [ connection . driver ] . fieldsByKey [ fieldKey ] ; // field definition may not exist since // this could be a core field like _id, name if ( fieldDefinition ) { if ( fieldDefinition . formType === 'CHECKBOX' ) { value = utils . ensureBoolean ( value ) ; } } cleanedConnection [ fieldKey ] = value ; } return cleanedConnection ; } , { } ) ; return cleanedConnection ; }
Validates connection object based on its driver
Unnecessary fields will be stripped out
@param {object} connection
Validates connection object based on its driver Unnecessary fields will be stripped out