import * as ts from '@terascope/utils' ; import registerApis from './api' ; import * as i from './interfaces' ; /**
 * CoreContext
*/ export class CoreContext < S = Record < string , any > , A = Record < string , any > , D extends string = string > implements i . FoundationContext < S , A , D > { readonly cluster : i . Cluster ; readonly sysconfig : i . FoundationSysConfig < S > ; readonly apis ! : i . ContextAPIs & A ; readonly foundation ! : i . LegacyFoundationApis ; readonly logger ! : ts . Logger ; readonly name : string ; readonly arch = process . arch ; readonly platform = process . platform ; assignment : D ; cluster_name ? : string ; constructor ( config , cluster , sysconfig , assignment ? ) { this . sysconfig = sysconfig ; this . cluster = cluster ; this . name = config . name || 'terafoundation' ; this . assignment = assignment || ( process . env . NODE_TYPE || process . env . assignment || process . env . ASSIGNMENT ) as D ; if ( config . name && this . assignment ) { const separator = this . assignment . includes ( '-' ) ? '-' : '_' ; process . title = `${ config . name }${ separator }${ this . assignment }` ; } else if ( config . name ) { process . title = config . name ; } if ( ts . isFunction ( config . cluster_name ) ) { this . cluster_name = config . cluster_name ( this . sysconfig ) ; } if ( ts . isString ( config . cluster_name ) ) { this . cluster_name = config . cluster_name ; } registerApis ( this ) ; } } export function handleStdStreams ( ) { function handleStdError ( err ) { if ( err . code === 'EPIPE' || err . code === 'ERR_STREAM_DESTROYED' ) { } else { throw err ; } } process . stdout . on ( 'error' , handleStdError ) ; process . stderr . on ( 'error' , handleStdError ) ; }