/**
 * This file contains common types that need to be used across the frontend
 */ type ViewName = 'compareView' | 'dbView' | 'queryView' | 'quickStartView' | 'newSchemaView' ; export interface AppState { selectedView : ViewName ; setSelectedView : ( selView : ViewName ) => void ; selectedDb : string ; setSelectedDb : ( selDb : string ) => void ; workingQuery : QueryData | undefined ; setWorkingQuery : ( selQuery : QueryData | undefined ) => void ; queries : Record < string , QueryData > ; setQueries : ( queries : Record < string , QueryData > ) => void ; comparedQueries : Record < string , QueryData > ; setComparedQueries : ( comparedQueries : Record < string , QueryData > ) => void ; setSidebarHidden : ( isHidden : boolean ) => void ; sidebarIsHidden : boolean ; } export type CreateNewQuery = ( query : QueryData ) => void ; export interface QueryData { /**
     * SQL string as inputted by user
     */ sqlString : string ; /**
     * pg rows returned from running query on db.
     */ returnedRows ? : Record < string , unknown > [ ] ; /**
     * Execution Plan. Result of running EXPLAIN (FORMAT JSON, ANALYZE)
     */ executionPlan ? : ExplainJson ; /**
     * Name of PG database that this query is run on
     */ db : string ; /**
     * User given label that identifies query
     */ label : string ; } export type ValidTabs = 'Results' | 'Execution Plan' ; export type FeedbackSeverity = 'error' | 'success' | 'info' | 'warning' ; export interface Feedback { type : FeedbackSeverity ; message : string | Record < string , unknown > ; } export interface Thresholds { percentDuration : number ; rowsAccuracy : number ; } /**
 * Fake type guard that asserts a type to simplify tests inside real type guards
 */ function assumeType < T > ( x ) { } export interface DatabaseInfo { /**
     * Database name as available in Postgres
     */ db_name : string ; /**
     * Pretty string of database size
     */ db_size : string ; } export interface TableColumn { /**
     * Column name as available in Postgres
     */ column_name : string ; /**
     * Type of data that can be inserted into Column
     */ data_type : string ; /**
     * Maximum char length if data type is char and length is defined. Otherwise null
     */ character_maximum_length : number | null ; /**
     * Can this column receive Null values or not?
     */ is_nullable : 'yes' | 'no' ; } export interface TableInfo { /**
     * Table name as available in Postgres
     */ table_name : string ; /**
     * Database that contains this table
     */ table_catalog : string ; /**
     * Schema that owns this table
     */ table_schema : string ; /**
     * Is table read only?
     */ is_insertable_into : 'yes' | 'no' ; columns : TableColumn [ ] ; } export interface DbLists { databaseList : DatabaseInfo [ ] ; tableList : TableInfo [ ] ; } /**
 * Type guard that checks if obj is compatible with type DbLists
 */ export const isDbLists = ( obj ) : obj is DbLists => { try { assumeType < DbLists > ( obj ) ; if ( ! obj . databaseList || ! obj . tableList ) return false ; if ( ! Array . isArray ( obj . databaseList ) || ! Array . isArray ( obj . tableList ) ) return false ; if ( obj . databaseList [ 0 ] && typeof obj . databaseList [ 0 ] . db_name !== 'string' ) return false ; if ( obj . databaseList [ 0 ] && typeof obj . databaseList [ 0 ] . db_size !== 'string' ) return false ; if ( obj . tableList [ 0 ] && typeof obj . tableList [ 0 ] . table_name !== 'string' ) return false ; if ( obj . tableList [ 0 ] && typeof obj . tableList [ 0 ] . table_catalog !== 'string' ) return false ; if ( obj . tableList [ 0 ] && typeof obj . tableList [ 0 ] . table_schema !== 'string' ) return false ; } catch ( e ) { return false ; } return true ; } ; export interface PlanNode { 'Node Type' : string ; 'Join Type' ? : string ; 'Startup Cost' : number ; 'Total Cost' : number ; 'Plan Rows' : number ; 'Plan Width' : number ; 'Actual Startup Time' : number ; 'Actual Total Time' : number ; 'Actual Rows' : number ; 'Actual Loops' ? : number ; 'Inner Unique' ? : boolean ; /**
     * Condition for Hash Operation
     *
     * ex: SELECT name FROM people p JOIN species s ON  **p.species_id = s._id**
     */ 'Hash Cond' ? : string ; /**
     * Name of relation plan operates on. i.e. table name
     */ 'Relation Name' ? : string ; /**
     * Alias given to relation in query.
     *
     * ex: SELECT name FROM people **p**
     */ Alias ? : string ; Plans ? : PlanNode [ ] ; } export interface ExplainJson { Plan : PlanNode ; 'Planning Time' : number ; 'Execution Time' : number ; }