import { Database , DbType , DbProtocol } from './types' ; export default function makeDatabase ( json ) { const { name , desc , protocol , type } = json ; const labels = json . labels || [ ] ; return { name , desc , title : formatDatabaseInfo ( type , protocol ) . title , protocol , tags : labels . map ( label => `${ label . name }: ${ label . value }` ) , } ; } export const formatDatabaseInfo = ( type , protocol ) => { const output = { type , protocol , title : '' } ; switch ( type ) { case 'rds' : output . title = `RDS ${ formatProtocol ( protocol ) }` ; return output ; case 'redshift' : output . title = 'Redshift' ; return output ; case 'self-hosted' : output . title = `Self-hosted ${ formatProtocol ( protocol ) }` ; return output ; case 'gcp' : output . title = `Cloud SQL ${ formatProtocol ( protocol ) }` ; return output ; default : output . title = `${ type } ${ formatProtocol ( protocol ) }` ; return output ; } } ; const formatProtocol = ( input ) => { switch ( input ) { case 'postgres' : return 'PostgreSQL' ; case 'mysql' : return 'MySQL' ; case 'mongodb' : return 'MongoDB' ; default : return input ; } } ; export type DatabaseInfo = ReturnType < typeof formatDatabaseInfo > ;