lib/core.js
function Core(options)
{
  // validate input
  Errors.assertInternal(Util.isObject(options));
  Errors.assertInternal(
      Util.exists(options.httpClient || options.httpClientClass));
  Errors.assertInternal(Util.exists(options.loggerClass));

  // set the logger instance
  Logger.setInstance(new (options.loggerClass)());

  // if a connection class is specified, it must be an object or function
  var connectionClass = options.connectionClass;
  if (Util.exists(connectionClass))
  {
    Errors.assertInternal(
        Util.isObject(connectionClass) || Util.isFunction(connectionClass));
  }
  else
  {
    // fall back to Connection
    connectionClass = Connection;
  }

  var qaMode     = options.qaMode;
  var clientInfo = options.client;

  /**
   * Creates a new Connection instance.
   *
   * @param {Object} connectionOptions
   * @param {Object} [config]
   *
   * @returns {Object}
   */
  var createConnection = function createConnection(connectionOptions, config)
  {
    // create a new ConnectionConfig and skip credential-validation if a config
    // object has been specified; this is because if a config object has been
    // specified, we're trying to deserialize a connection and the account name,
    // username and password don't need to be specified because the config
    // object already contains the tokens we need
    var connectionConfig =
        new ConnectionConfig(connectionOptions, !config, qaMode, clientInfo);

    // if an http client was specified in the options passed to the module, use
    // it, otherwise create a new HttpClient
    var httpClient = options.httpClient ||
            new options.httpClientClass(connectionConfig);

    return new connectionClass(
        new ConnectionContext(connectionConfig, httpClient, config));
  };

  var instance =
  {
    /**
     * Creates a connection object that can be used to communicate with
     * Snowflake.
     *
     * @param {Object} options
     *
     * @returns {Object}
     */
    createConnection: function(options)
    {
      return createConnection(options);
    },

    /**
     * Deserializes a serialized connection.
     *
     * @param {Object} options
     * @param {String} serializedConnection
     *
     * @returns {Object}
     */
    deserializeConnection: function(options, serializedConnection)
    {
      // check for missing serializedConfig
      Errors.checkArgumentExists(Util.exists(serializedConnection),
          ErrorCodes.ERR_CONN_DESERIALIZE_MISSING_CONFIG);

      // check for invalid serializedConfig
      Errors.checkArgumentValid(Util.isString(serializedConnection),
          ErrorCodes.ERR_CONN_DESERIALIZE_INVALID_CONFIG_TYPE);

      // try to json-parse serializedConfig
      var config;
      try
      {
        config = JSON.parse(serializedConnection);
      }
      catch (err) {}
      finally
      {
        // if serializedConfig can't be parsed to json, throw an error
        Errors.checkArgumentValid(Util.isObject(config),
            ErrorCodes.ERR_CONN_DESERIALIZE_INVALID_CONFIG_FORM);
      }

      return createConnection(options, config);
    },

    /**
     * Serializes a given connection.
     *
     * @param {Object} connection
     *
     * @returns {String} a serialized version of the connection.
     */
    serializeConnection: function(connection)
    {
      return connection ? connection.serialize() : connection;
    },

    /**
     * Configures this instance of the Snowflake core module.
     *
     * @param {Object} options
     */
    configure: function(options)
    {
      var logTag = options.logLevel;
      if (Util.exists(logTag))
      {
        // check that the specified value is a valid tag
        Errors.checkArgumentValid(LoggerCore.isValidLogTag(logTag),
            ErrorCodes.ERR_GLOGAL_CONFIGURE_INVALID_LOG_LEVEL);

        Logger.getInstance().configure(
        {
          level: LoggerCore.logTagToLevel(logTag)
        });
      }

      var insecureConnect = options.insecureConnect;
      if (Util.exists(insecureConnect))
      {
        // check that the specified value is a boolean
        Errors.checkArgumentValid(Util.isBoolean(insecureConnect),
            ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_INSECURE_CONNECT);

        GlobalConfig.setInsecureConnect(insecureConnect);
      }
    }
  };

  // add some read-only constants
  var nativeTypeValues = DataTypes.NativeTypes.values;
  Object.defineProperties(instance,
  {
    STRING  : { value: nativeTypeValues.STRING  },
    BOOLEAN : { value: nativeTypeValues.BOOLEAN },
    NUMBER  : { value: nativeTypeValues.NUMBER  },
    DATE    : { value: nativeTypeValues.DATE    },
    JSON    : { value: nativeTypeValues.JSON    }
  });

  return instance;
}
function Core(options)
{
  // validate input
  Errors.assertInternal(Util.isObject(options));
  Errors.assertInternal(
      Util.exists(options.httpClient || options.httpClientClass));
  Errors.assertInternal(Util.exists(options.loggerClass));

  // set the logger instance
  Logger.setInstance(new (options.loggerClass)());

  // if a connection class is specified, it must be an object or function
  var connectionClass = options.connectionClass;
  if (Util.exists(connectionClass))
  {
    Errors.assertInternal(
        Util.isObject(connectionClass) || Util.isFunction(connectionClass));
  }
  else
  {
    // fall back to Connection
    connectionClass = Connection;
  }

  var qaMode     = options.qaMode;
  var clientInfo = options.client;

  /**
   * Creates a new Connection instance.
   *
   * @param {Object} connectionOptions
   * @param {Object} [config]
   *
   * @returns {Object}
   */
  var createConnection = function createConnection(connectionOptions, config)
  {
    // create a new ConnectionConfig and skip credential-validation if a config
    // object has been specified; this is because if a config object has been
    // specified, we're trying to deserialize a connection and the account name,
    // username and password don't need to be specified because the config
    // object already contains the tokens we need
    var connectionConfig =
        new ConnectionConfig(connectionOptions, !config, qaMode, clientInfo);

    // if an http client was specified in the options passed to the module, use
    // it, otherwise create a new HttpClient
    var httpClient = options.httpClient ||
            new options.httpClientClass(connectionConfig);

    return new connectionClass(
        new ConnectionContext(connectionConfig, httpClient, config));
  };

  var instance =
  {
    /**
     * Creates a connection object that can be used to communicate with
     * Snowflake.
     *
     * @param {Object} options
     *
     * @returns {Object}
     */
    createConnection: function(options)
    {
      return createConnection(options);
    },

    /**
     * Deserializes a serialized connection.
     *
     * @param {Object} options
     * @param {String} serializedConnection
     *
     * @returns {Object}
     */
    deserializeConnection: function(options, serializedConnection)
    {
      // check for missing serializedConfig
      Errors.checkArgumentExists(Util.exists(serializedConnection),
          ErrorCodes.ERR_CONN_DESERIALIZE_MISSING_CONFIG);

      // check for invalid serializedConfig
      Errors.checkArgumentValid(Util.isString(serializedConnection),
          ErrorCodes.ERR_CONN_DESERIALIZE_INVALID_CONFIG_TYPE);

      // try to json-parse serializedConfig
      var config;
      try
      {
        config = JSON.parse(serializedConnection);
      }
      catch (err) {}
      finally
      {
        // if serializedConfig can't be parsed to json, throw an error
        Errors.checkArgumentValid(Util.isObject(config),
            ErrorCodes.ERR_CONN_DESERIALIZE_INVALID_CONFIG_FORM);
      }

      return createConnection(options, config);
    },

    /**
     * Serializes a given connection.
     *
     * @param {Object} connection
     *
     * @returns {String} a serialized version of the connection.
     */
    serializeConnection: function(connection)
    {
      return connection ? connection.serialize() : connection;
    },

    /**
     * Configures this instance of the Snowflake core module.
     *
     * @param {Object} options
     */
    configure: function(options)
    {
      var logTag = options.logLevel;
      if (Util.exists(logTag))
      {
        // check that the specified value is a valid tag
        Errors.checkArgumentValid(LoggerCore.isValidLogTag(logTag),
            ErrorCodes.ERR_GLOGAL_CONFIGURE_INVALID_LOG_LEVEL);

        Logger.getInstance().configure(
        {
          level: LoggerCore.logTagToLevel(logTag)
        });
      }

      var insecureConnect = options.insecureConnect;
      if (Util.exists(insecureConnect))
      {
        // check that the specified value is a boolean
        Errors.checkArgumentValid(Util.isBoolean(insecureConnect),
            ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_INSECURE_CONNECT);

        GlobalConfig.setInsecureConnect(insecureConnect);
      }
    }
  };

  // add some read-only constants
  var nativeTypeValues = DataTypes.NativeTypes.values;
  Object.defineProperties(instance,
  {
    STRING  : { value: nativeTypeValues.STRING  },
    BOOLEAN : { value: nativeTypeValues.BOOLEAN },
    NUMBER  : { value: nativeTypeValues.NUMBER  },
    DATE    : { value: nativeTypeValues.DATE    },
    JSON    : { value: nativeTypeValues.JSON    }
  });

  return instance;
}
function Core ( options ) { // validate input Errors . assertInternal ( Util . isObject ( options ) ) ; Errors . assertInternal ( Util . exists ( options . httpClient || options . httpClientClass ) ) ; Errors . assertInternal ( Util . exists ( options . loggerClass ) ) ; // set the logger instance Logger . setInstance ( new ( options . loggerClass ) ( ) ) ; // if a connection class is specified, it must be an object or function var connectionClass = options . connectionClass ; if ( Util . exists ( connectionClass ) ) { Errors . assertInternal ( Util . isObject ( connectionClass ) || Util . isFunction ( connectionClass ) ) ; } else { // fall back to Connection connectionClass = Connection ; } var qaMode = options . qaMode ; var clientInfo = options . client ; /**
   * Creates a new Connection instance.
   *
   * @param {Object} connectionOptions
   * @param {Object} [config]
   *
   * @returns {Object}
   */ var createConnection = function createConnection ( connectionOptions , config ) { // create a new ConnectionConfig and skip credential-validation if a config // object has been specified; this is because if a config object has been // specified, we're trying to deserialize a connection and the account name, // username and password don't need to be specified because the config // object already contains the tokens we need var connectionConfig = new ConnectionConfig ( connectionOptions , ! config , qaMode , clientInfo ) ; // if an http client was specified in the options passed to the module, use // it, otherwise create a new HttpClient var httpClient = options . httpClient || new options . httpClientClass ( connectionConfig ) ; return new connectionClass ( new ConnectionContext ( connectionConfig , httpClient , config ) ) ; } ; var instance = { /**
     * Creates a connection object that can be used to communicate with
     * Snowflake.
     *
     * @param {Object} options
     *
     * @returns {Object}
     */ createConnection : function ( options ) { return createConnection ( options ) ; } , /**
     * Deserializes a serialized connection.
     *
     * @param {Object} options
     * @param {String} serializedConnection
     *
     * @returns {Object}
     */ deserializeConnection : function ( options , serializedConnection ) { // check for missing serializedConfig Errors . checkArgumentExists ( Util . exists ( serializedConnection ) , ErrorCodes . ERR_CONN_DESERIALIZE_MISSING_CONFIG ) ; // check for invalid serializedConfig Errors . checkArgumentValid ( Util . isString ( serializedConnection ) , ErrorCodes . ERR_CONN_DESERIALIZE_INVALID_CONFIG_TYPE ) ; // try to json-parse serializedConfig var config ; try { config = JSON . parse ( serializedConnection ) ; } catch ( err ) { } finally { // if serializedConfig can't be parsed to json, throw an error Errors . checkArgumentValid ( Util . isObject ( config ) , ErrorCodes . ERR_CONN_DESERIALIZE_INVALID_CONFIG_FORM ) ; } return createConnection ( options , config ) ; } , /**
     * Serializes a given connection.
     *
     * @param {Object} connection
     *
     * @returns {String} a serialized version of the connection.
     */ serializeConnection : function ( connection ) { return connection ? connection . serialize ( ) : connection ; } , /**
     * Configures this instance of the Snowflake core module.
     *
     * @param {Object} options
     */ configure : function ( options ) { var logTag = options . logLevel ; if ( Util . exists ( logTag ) ) { // check that the specified value is a valid tag Errors . checkArgumentValid ( LoggerCore . isValidLogTag ( logTag ) , ErrorCodes . ERR_GLOGAL_CONFIGURE_INVALID_LOG_LEVEL ) ; Logger . getInstance ( ) . configure ( { level : LoggerCore . logTagToLevel ( logTag ) } ) ; } var insecureConnect = options . insecureConnect ; if ( Util . exists ( insecureConnect ) ) { // check that the specified value is a boolean Errors . checkArgumentValid ( Util . isBoolean ( insecureConnect ) , ErrorCodes . ERR_GLOBAL_CONFIGURE_INVALID_INSECURE_CONNECT ) ; GlobalConfig . setInsecureConnect ( insecureConnect ) ; } } } ; // add some read-only constants var nativeTypeValues = DataTypes . NativeTypes . values ; Object . defineProperties ( instance , { STRING : { value : nativeTypeValues . STRING } , BOOLEAN : { value : nativeTypeValues . BOOLEAN } , NUMBER : { value : nativeTypeValues . NUMBER } , DATE : { value : nativeTypeValues . DATE } , JSON : { value : nativeTypeValues . JSON } } ) ; return instance ; }
Creates a new instance of the Snowflake core module.

@param {Object} options

@returns {Object}
@constructor
Creates a new instance of the Snowflake core module .