import { Connection } from '@salesforce/core' ; import { JsonMap } from '@salesforce/ts-types' ; import { QueryResult } from 'jsforce' ; import * as vscode from 'vscode' ; import { nls } from '../messages' ; import { soqlComments } from '@salesforce/soql-common' ; export class QueryRunner { constructor ( private connection ) { } public async runQuery ( queryText , options = { showErrors : true } ) { const pureSOQLText = soqlComments . parseHeaderComments ( queryText ) . soqlText ; try { const rawQueryData = ( await this . connection . query ( pureSOQLText ) ) as QueryResult < JsonMap > ; const cleanQueryData = { ... rawQueryData , records : this . flattenQueryRecords ( rawQueryData . records ) } ; return cleanQueryData ; } catch ( error ) { if ( options . showErrors ) { const message = nls . localize ( 'error_run_soql_query' , error . message ) ; vscode . window . showErrorMessage ( message ) ; } throw error ; } } private flattenQueryRecords ( rawQueryRecords ) { return rawQueryRecords . map ( ( { attributes , ... cleanRecords } ) => cleanRecords ) ; } }