import { Event , EventHint , Options , Transport } from '../types' ; import { BeidouError , logger } from '../utils' ; import { NoopTransport } from './transports/noop' ; export interface Backend { /** Creates a  Event from an exception.  eventFromException ( exception , hint ? ) : PromiseLike < Event > ; /** Creates a  Event from a plain message.  eventFromMessage ( message , hint ? ) : PromiseLike < Event > ; /** Submits the event to Beidou */ sendEvent ( event ) : void ; returns getTransport ( ) : Transport ; } hidden export type BackendClass < B extends Backend , O extends Options > = new ( options ) => B ; hidden export abstract class BaseBackend < O extends Options > implements Backend { /** Options passed to the SDK. */ protected readonly _options : O ; /** Cached transport used internally. */ protected _transport : Transport ; /** Creates a new backend instance. */ public constructor ( options ) { this . _options = options ; this . _transport = this . _setupTransport ( ) ; } inheritDoc public eventFromException ( _exception , _hint ? ) { throw new BeidouError ( 'Backend has to implement `eventFromException` method' ) ; } inheritDoc public eventFromMessage ( _message , _hint ? ) { throw new BeidouError ( 'Backend has to implement `eventFromMessage` method' ) ; } inheritDoc public sendEvent ( event ) { this . _transport . sendEvent ( event ) . then ( null , reason => { logger . error ( `Error while sending event: ${ reason }` ) ; } ) ; } inheritDoc public getTransport ( ) { return this . _transport ; } /**
     * Sets up the transport so it can be used later to send requests.
     */ protected _setupTransport ( ) { return new NoopTransport ( ) ; } }