@@ -14,7 +14,14 @@ import { defaultSigmaSettings } from "../framework/graph-visualiser/defaults";
1414import { newVisualGraph } from "../framework/graph-visualiser/graph" ;
1515import { Layouts } from "../framework/graph-visualiser/layouts" ;
1616import { Concept , Value } from "../framework/typedb-driver/concept" ;
17- import { ApiResponse , ConceptDocument , ConceptRow , isApiErrorResponse , QueryResponse } from "../framework/typedb-driver/response" ;
17+ import {
18+ ApiResponse ,
19+ ConceptDocument ,
20+ ConceptRow ,
21+ ConceptRowAnswer ,
22+ isApiErrorResponse ,
23+ QueryResponse
24+ } from "../framework/typedb-driver/response" ;
1825import { INTERNAL_ERROR } from "../framework/util/strings" ;
1926import { DriverState } from "./driver-state.service" ;
2027import { SchemaState , Schema , SchemaAttribute , SchemaRole , SchemaConcept } from "./schema-state.service" ;
@@ -326,64 +333,62 @@ export class LogOutputState {
326333 }
327334
328335 appendQueryResult ( res : ApiResponse < QueryResponse > ) {
336+ let lines : string [ ] = [ ] ;
329337 if ( isApiErrorResponse ( res ) ) {
330- this . appendLines ( `${ RESULT } ${ ERROR } ` , `` , res . err . message ) ;
338+ lines . push ( `${ RESULT } ${ ERROR } ` , `` , res . err . message ) ;
331339 return ;
332340 }
333341
334- this . appendLines ( `${ RESULT } ${ SUCCESS } ` , `` ) ;
342+ lines . push ( `${ RESULT } ${ SUCCESS } ` , `` ) ;
335343
336344 switch ( res . ok . answerType ) {
337345 case "ok" : {
338- this . appendLines ( `Finished ${ res . ok . queryType } query.` ) ;
346+ lines . push ( `Finished ${ res . ok . queryType } query.` ) ;
339347 break ;
340348 }
341349 case "conceptRows" : {
342- this . appendLines ( `Finished ${ res . ok . queryType } query compilation and validation...` ) ;
343- if ( res . ok . queryType === "write" ) this . appendLines ( `Finished writes. Printing rows...` ) ;
344- else this . appendLines ( `Printing rows...` ) ;
350+ lines . push ( `Finished ${ res . ok . queryType } query compilation and validation...` ) ;
351+ if ( res . ok . queryType === "write" ) lines . push ( `Finished writes. Printing rows...` ) ;
352+ else lines . push ( `Printing rows...` ) ;
345353
346354 if ( res . ok . answers . length ) {
347355 const varNames = Object . keys ( res . ok . answers [ 0 ] ) ;
348356 if ( varNames . length ) {
349- res . ok . answers . forEach ( ( ( x , idx ) => this . appendConceptRow ( x . data , idx === 0 ) ) ) ;
350- } else this . appendLines ( `No columns to show.` ) ;
357+ const columnNames = Object . keys ( res . ok . answers [ 0 ] . data ) ;
358+ const variableColumnWidth = columnNames . length > 0 ? Math . max ( ...columnNames . map ( s => s . length ) ) : 0 ;
359+ res . ok . answers . forEach ( ( rowAnswer , idx ) => {
360+ if ( idx == 0 ) lines . push ( this . lineDashSeparator ( variableColumnWidth ) ) ;
361+ lines . push ( this . conceptRowDisplayString ( rowAnswer . data , variableColumnWidth ) )
362+ } )
363+ } else lines . push ( `No columns to show.` ) ;
351364 }
352365
353- this . appendLines ( `Finished. Total rows: ${ res . ok . answers . length } ` ) ;
366+ lines . push ( `Finished. Total rows: ${ res . ok . answers . length } ` ) ;
354367 break ;
355368 }
356369 case "conceptDocuments" : {
357- this . appendLines ( `Finished ${ res . ok . queryType } query compilation and validation...` ) ;
358- if ( res . ok . queryType === "write" ) this . appendLines ( `Finished writes. Printing documents...` ) ;
359- else this . appendLines ( `Printing documents...` ) ;
360- res . ok . answers . forEach ( x => this . appendConceptDocument ( x ) ) ;
361- this . appendLines ( `Finished. Total documents: ${ res . ok . answers . length } ` ) ;
370+ lines . push ( `Finished ${ res . ok . queryType } query compilation and validation...` ) ;
371+ if ( res . ok . queryType === "write" ) lines . push ( `Finished writes. Printing documents...` ) ;
372+ else lines . push ( `Printing documents...` ) ;
373+ res . ok . answers . forEach ( x => lines . push ( this . conceptDocumentDisplayString ( x ) ) ) ;
374+ lines . push ( `Finished. Total documents: ${ res . ok . answers . length } ` ) ;
362375 break ;
363376 }
364377 default :
365378 throw INTERNAL_ERROR ;
366379 }
367-
380+ this . appendLines ( ... lines ) ;
368381 this . appendBlankLine ( ) ;
369382 }
370383
371- private appendConceptDocument ( document : ConceptDocument ) {
384+ private conceptDocumentDisplayString ( document : ConceptDocument ) : string {
372385 try {
373- const pretty = JSON . stringify ( document , null , 2 ) ;
374- this . appendLines ( pretty ) ;
386+ return JSON . stringify ( document , null , 2 ) ;
375387 } catch ( err ) {
376- this . appendLines ( `Error trying to print JSON: ${ err } ` ) ;
388+ return `Error trying to print JSON: ${ err } ` ;
377389 }
378390 }
379391
380- private appendConceptRow ( row : ConceptRow , isFirst : boolean ) {
381- const columnNames = Object . keys ( row ) ;
382- const variableColumnWidth = columnNames . length > 0 ? Math . max ( ...columnNames . map ( s => s . length ) ) : 0 ;
383- if ( isFirst ) this . appendLines ( this . lineDashSeparator ( variableColumnWidth ) ) ;
384- this . appendLines ( this . conceptRowDisplayString ( row , variableColumnWidth ) ) ;
385- }
386-
387392 private conceptRowDisplayString ( row : ConceptRow , variableColumnWidth : number ) {
388393 const columnNames = Object . keys ( row ) ;
389394 const contents = columnNames . map ( ( columnName ) =>
0 commit comments