UNPKG

snowflake-sdk

Version:
85 lines (76 loc) 2.16 kB
/* * Copyright (c) 2015-2024 Snowflake Computing Inc. All rights reserved. */ const Util = require('../util'); const Errors = require('../errors'); const SfService = require('../services/sf'); const LargeResultSetService = require('../services/large_result_set'); /** * Creates a new ConnectionContext. * * @param {ConnectionConfig} connectionConfig * @param {Object} httpClient * @param {Object} config * * @constructor */ function ConnectionContext(connectionConfig, httpClient, config) { // validate input Errors.assertInternal(Util.isObject(connectionConfig)); Errors.assertInternal(Util.isObject(httpClient)); // if a config object was specified, verify // that it has all the information we need let sfServiceConfig; if (Util.exists(config)) { Errors.assertInternal(Util.isObject(config)); Errors.assertInternal(Util.isObject(config.services)); Errors.assertInternal(Util.isObject(config.services.sf)); sfServiceConfig = config.services.sf; } // create a map that contains all the services we'll be using const services = { sf: new SfService(connectionConfig, httpClient, sfServiceConfig), largeResultSet: new LargeResultSetService(connectionConfig, httpClient) }; /** * Returns the ConnectionConfig for use by the connection. * * @returns {ConnectionConfig} */ this.getConnectionConfig = function () { return connectionConfig; }; /** * Returns a map that contains all the available services. * * @returns {Object} */ this.getServices = function () { return services; }; /** * Returns a configuration object that can be passed as an optional argument * to the ConnectionContext constructor to create a new object that has the * same state as this ConnectionContext instance. * * @returns {Object} */ this.getConfig = function () { return { services: { sf: services.sf.getConfig() } }; }; /** * Returns instance of httpClient * * @returns {NodeHttpClient} */ this.getHttpClient = function () { return httpClient; }; } module.exports = ConnectionContext;