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AM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;YACnD,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC;IAnCD,gDAmCC;IAKY,QAAA,YAAY,GAAG,kBAAkB,EAAE,CAAC;IAiBjD,SAAS,UAAU;QACjB,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YAClC,OAAO,OAAO,CAAC;SAChB;QAED,OAAgB;YACd,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI;YACX,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;YACf,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;IAED,SAAS,IAAI;IAEb,CAAC","sourcesContent":["import { global } from '@theintern/common';\n\nimport { Events, Executor, NoDataEvents, Handle } from '../executors/Executor';\nimport { ErrorFormatOptions } from '../common/ErrorFormatter';\n\n/**\n * This is a base class for reporters that provides convenienience features such\n * as event handler registration and a default console.\n */\nexport default class Reporter implements ReporterProperties {\n readonly executor: Executor;\n\n protected _console: Console | undefined;\n protected _executor: Executor | undefined;\n protected _handles: Handle[] | undefined;\n protected _output: ReporterOutput | undefined;\n\n /**\n * A mapping from event names to the names of methods on this object. This\n * property should be defined on the class prototype. It is automatically\n * created by the @eventHandler decorator.\n */\n protected _eventHandlers: { [eventName: string]: string } | undefined;\n\n constructor(executor: Executor, options: ReporterOptions = {}) {\n if (options.output) {\n this.output = options.output;\n }\n if (options.console) {\n this.console = options.console;\n }\n this.executor = executor;\n this._registerEventHandlers();\n }\n\n get console() {\n if (!this._console) {\n this._console = getConsole();\n }\n return this._console;\n }\n\n set console(value: Console) {\n this._console = value;\n }\n\n get output() {\n if (!this._output) {\n // Use process.stdout in a Node.js environment, otherwise construct\n // a writable-like object that outputs to the console.\n if (global.process != null) {\n return global.process.stdout;\n } else {\n const _console = this.console;\n this._output = {\n write(chunk: string, _encoding: string, callback: Function) {\n _console.log(chunk);\n callback();\n },\n end(chunk: string, _encoding: string, callback: Function) {\n _console.log(chunk);\n callback();\n }\n };\n }\n }\n return this._output;\n }\n\n set output(value: ReporterOutput) {\n this._output = value;\n }\n\n formatError(error: Error, options?: ErrorFormatOptions) {\n return this.executor.formatError(error, options);\n }\n\n /**\n * Register any handlers added to the class event handlers map\n */\n protected _registerEventHandlers() {\n if (!this._eventHandlers) {\n return;\n }\n\n // Use a for..in loop because _eventHandlers may inherit from a parent\n for (let name in this._eventHandlers) {\n this.executor.on(<keyof Events>name, (...args: any[]) => {\n const handler = this._eventHandlers![name];\n return (<any>this)[handler](...args);\n });\n }\n }\n}\n\n/**\n * Create a decorator that will add a decorated method to a class's list of\n * event handlers.\n */\nexport function createEventHandler<\n E extends Events,\n N extends NoDataEvents = NoDataEvents\n>() {\n return function() {\n function decorate(\n target: any,\n propertyKey: N,\n _descriptor: TypedPropertyDescriptor<() => void | Promise<any>>\n ): void;\n function decorate<T extends keyof E>(\n target: any,\n propertyKey: T,\n _descriptor: TypedPropertyDescriptor<(data: E[T]) => void | Promise<any>>\n ): void;\n function decorate<T extends keyof E>(\n target: any,\n propertyKey: T,\n _descriptor:\n | TypedPropertyDescriptor<(data: E[T]) => void | Promise<any>>\n | TypedPropertyDescriptor<() => void | Promise<any>>\n ) {\n if (!target.hasOwnProperty('_eventHandlers')) {\n if (target._eventHandlers != null) {\n // If there's an _eventHandlers property on a parent,\n // inherit from it\n target._eventHandlers = Object.create(target._eventHandlers);\n } else {\n target._eventHandlers = {};\n }\n }\n target._eventHandlers[propertyKey] = propertyKey;\n }\n return decorate;\n };\n}\n\n/**\n * The default event handler decorator.\n */\nexport const eventHandler = createEventHandler();\n\nexport interface ReporterProperties {\n output: ReporterOutput;\n console: Console;\n}\n\nexport type ReporterOptions = Partial<ReporterProperties>;\n\n/**\n * A stream that reporters can write to\n */\nexport interface ReporterOutput {\n write(chunk: string | Buffer, encoding?: string, callback?: Function): void;\n end(chunk: string | Buffer, encoding?: string, callback?: Function): void;\n}\n\nfunction getConsole() {\n if (typeof console !== 'undefined') {\n return console;\n }\n\n return <Console>{\n assert: noop,\n count: noop,\n dir: noop,\n error: noop,\n exception: noop,\n info: noop,\n log: noop,\n table: noop,\n time: noop,\n timeEnd: noop,\n trace: noop,\n warn: noop\n };\n}\n\nfunction noop() {\n // do nothing\n}\n"]} |