constructor()

in packages/azure-kusto-data/src/client.ts [43:89]


    constructor(kcsb: string | ConnectionStringBuilder) {
        this.connectionString = typeof kcsb === "string" ? new ConnectionStringBuilder(kcsb) : kcsb;
        if (!this.connectionString.dataSource) {
            throw new Error("Cluster url is required");
        }
        const url = new URL(this.connectionString.dataSource);
        this.cluster = url.toString();
        if (this.cluster.endsWith("/")) {
            this.cluster = this.cluster.slice(0, -1);
        }
        this.defaultDatabase = this.connectionString.initialCatalog;
        this.endpoints = {
            [ExecutionType.Mgmt]: `${this.cluster}/v1/rest/mgmt`,
            [ExecutionType.Query]: `${this.cluster}/v2/rest/query`,
            [ExecutionType.Ingest]: `${this.cluster}/v1/rest/ingest`,
            [ExecutionType.QueryV1]: `${this.cluster}/v1/rest/query`,
        };
        this.aadHelper = new AadHelper(this.connectionString);

        let headers: RawAxiosRequestHeaders = {
            Accept: "application/json",
        };

        if (isNode) {
            headers = {
                ...headers,
                "Accept-Encoding": "gzip,deflate",
                Connection: "Keep-Alive",
            };
        }
        const axiosProps: AxiosRequestConfig = {
            headers,
            validateStatus: (status: number) => status === 200,
            maxBodyLength: Infinity,
            maxContentLength: Infinity,
            maxRedirects: 0,
        };
        // http and https are Node modules and are not found in browsers
        if (isNode) {
            // keepAlive pools and reuses TCP connections, so it's faster
            axiosProps.httpAgent = new http.Agent({ keepAlive: true });
            axiosProps.httpsAgent = new https.Agent({ keepAlive: true });
        }
        axiosProps.cancelToken = this.cancelToken.token;

        this.axiosInstance = axios.create(axiosProps);
    }