in packages/azure-kusto-data/src/client.ts [139:211]
async _execute(
endpoint: string,
executionType: ExecutionType,
db: string | null,
entity: RequestEntity,
properties?: ClientRequestProperties | null,
): Promise<KustoResponseDataSet> {
this.ensureOpen();
kustoTrustedEndpoints.validateTrustedEndpoint(endpoint, (await CloudSettings.getCloudInfoForCluster(this.cluster)).LoginEndpoint);
db = this.getDb(db);
const headers: { [header: string]: string } = {};
let payload: { db: string; csl: string; properties?: any };
let clientRequestPrefix = "";
const timeout = this._getClientTimeout(executionType, properties);
let payloadContent: any = "";
if ("query" in entity) {
payload = {
db,
csl: entity.query,
};
if (properties != null) {
payload.properties = properties.toJSON();
}
payloadContent = JSON.stringify(payload);
headers["Content-Type"] = "application/json; charset=utf-8";
clientRequestPrefix = "KNC.execute;";
} else if ("stream" in entity) {
payloadContent = entity.stream;
clientRequestPrefix = "KNC.executeStreamingIngest;";
if (isNode) {
headers["Content-Encoding"] = "gzip";
headers["Content-Type"] = "application/octet-stream";
} else {
headers["Content-Type"] = "application/json";
}
} else if ("blob" in entity) {
payloadContent = {
sourceUri: entity.blob,
};
clientRequestPrefix = "KNC.executeStreamingIngestFromBlob;";
headers["Content-Type"] = "application/json";
} else {
throw new Error("Invalid parameters - expected query or streaming ingest");
}
let kustoHeaders = this.connectionString.clientDetails().getHeaders();
kustoHeaders["x-ms-client-request-id"] = `${clientRequestPrefix}${uuidv4()}`;
if (properties != null) {
kustoHeaders = {
...kustoHeaders,
...properties.getHeaders(),
};
}
for (const key of Object.keys(kustoHeaders) as Iterable<keyof KustoHeaders>) {
if (kustoHeaders[key]) {
headers[key] = kustoHeaders[key] as string;
}
}
const authHeader = await this.aadHelper.getAuthHeader();
if (authHeader != null) {
headers.Authorization = authHeader;
}
return this._doRequest(endpoint, executionType, headers, payloadContent, timeout, properties);
}