@curium.rocks/data-emitter-base
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -1,3 +0,5 @@ | ||
import { ICommand, IDataEmitter, IDataEvent, IDataEventListener, IDataEventListenerFunc, IDisposable, IEmitterDescription, IExecutionResult, IFormatSettings, ISettings, IStatusChangeListener, IStatusChangeListenerFunc, IStatusEvent, ITraceableAction } from "./dataEmitter"; | ||
import { LoggerFacade, LogLevel } from "./loggerFacade"; | ||
/// <reference types="node" /> | ||
import { ICommand, IDataEmitter, IDataEvent, IDataEventListener, IDataEventListenerFunc, IDisposable, IEmitterDescription, IExecutionResult, IFormatSettings, ISettings, IStatusChangeListener, IStatusChangeListenerFunc, IStatusEvent, ITraceableAction } from './dataEmitter'; | ||
import { LoggerFacade, LogLevel } from './loggerFacade'; | ||
import EventEmitter from 'events'; | ||
/** | ||
@@ -12,12 +14,12 @@ * | ||
/** | ||
* | ||
* @param {boolean} connected | ||
* @param {boolean} bit | ||
* @param {IDataEmitter} emitter | ||
* @param {Date} timestamp | ||
*/ | ||
* | ||
* @param {boolean} connected | ||
* @param {boolean} bit | ||
* @param {IDataEmitter} emitter | ||
* @param {Date} timestamp | ||
*/ | ||
constructor(connected: boolean, bit: boolean, emitter: IDataEmitter, timestamp?: Date); | ||
/** | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON(): Record<string, unknown>; | ||
@@ -34,12 +36,12 @@ } | ||
/** | ||
* Create a data event object | ||
* @param {IDataEmitter} emitter | ||
* @param {unknown} data | ||
* @param {unknown} meta | ||
*/ | ||
* Create a data event object | ||
* @param {IDataEmitter} emitter | ||
* @param {unknown} data | ||
* @param {unknown} meta | ||
*/ | ||
constructor(emitter: IDataEmitter, data: unknown, meta: unknown); | ||
/** | ||
* Converts the object into a JSON friendly object | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* Converts the object into a JSON friendly object | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON(): Record<string, unknown>; | ||
@@ -51,3 +53,3 @@ } | ||
*/ | ||
export declare abstract class BaseEmitter implements IDataEmitter, IDisposable { | ||
export declare abstract class BaseEmitter extends EventEmitter implements IDataEmitter, IDisposable { | ||
private _id; | ||
@@ -58,178 +60,178 @@ private _name; | ||
/** | ||
* Listener collection for data change listeners | ||
*/ | ||
* Listener collection for data change listeners | ||
*/ | ||
private readonly _dataListeners; | ||
/** | ||
* Listener collection for status change listeners | ||
*/ | ||
* Listener collection for status change listeners | ||
*/ | ||
private readonly _statusListeners; | ||
/** | ||
* connected state | ||
*/ | ||
* connected state | ||
*/ | ||
private _connected; | ||
/** | ||
* faulted state | ||
*/ | ||
* faulted state | ||
*/ | ||
private _faulted; | ||
/** | ||
* DC check interval handle | ||
* @private | ||
*/ | ||
* DC check interval handle | ||
* @private | ||
*/ | ||
private _dcInterval?; | ||
/** | ||
* amount of time between dc checks | ||
* @private | ||
*/ | ||
* amount of time between dc checks | ||
* @private | ||
*/ | ||
private _dcIntervalms?; | ||
/** | ||
* amount of time since successful message emission till we consider | ||
* the state to be disconnected | ||
* @private | ||
*/ | ||
* amount of time since successful message emission till we consider | ||
* the state to be disconnected | ||
* @private | ||
*/ | ||
private _dcThresholdMs; | ||
/** | ||
* The last time the source has successfully produced data | ||
* @private | ||
*/ | ||
* The last time the source has successfully produced data | ||
* @private | ||
*/ | ||
private _dcLastHeardTime?; | ||
/** | ||
* @return {string} unique id for emitter | ||
*/ | ||
* @return {string} unique id for emitter | ||
*/ | ||
get id(): string; | ||
/** | ||
* @return {string} emitter name | ||
*/ | ||
* @return {string} emitter name | ||
*/ | ||
get name(): string; | ||
/** | ||
* @return {string} communication link description | ||
*/ | ||
* @return {string} communication link description | ||
*/ | ||
get description(): string; | ||
/** | ||
* | ||
* @param {string} _id | ||
* @param {string} _name | ||
* @param {string} _description | ||
* @param {LoggerFacade|undefined} _logger | ||
*/ | ||
* | ||
* @param {string} _id | ||
* @param {string} _name | ||
* @param {string} _description | ||
* @param {LoggerFacade|undefined} _logger | ||
*/ | ||
constructor(_id: string, _name: string, _description: string, _logger?: LoggerFacade | undefined); | ||
/** | ||
* serialize the important data that is needed to be able to recreate this emitter in it's current state | ||
* @param {IFormatSettings} settings used to specify expected format of the serialization | ||
* @return {Promise<string>} | ||
*/ | ||
* serialize the important data that is needed to be able to recreate this emitter in it's current state | ||
* @param {IFormatSettings} settings used to specify expected format of the serialization | ||
* @return {Promise<string>} | ||
*/ | ||
serializeState(settings: IFormatSettings): Promise<string>; | ||
/** | ||
* Control serialized properties when JSON.stringify is called | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* Control serialized properties when JSON.stringify is called | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON(): Record<string, unknown>; | ||
/** | ||
* | ||
* @param {IDataEvent} evt | ||
*/ | ||
* | ||
* @param {IDataEvent} evt | ||
*/ | ||
protected notifyDataListeners(evt: IDataEvent): void; | ||
/** | ||
* | ||
* @param {IDataEventListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
* | ||
* @param {IDataEventListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
onData(listener: IDataEventListener | IDataEventListenerFunc): IDisposable; | ||
/** | ||
* | ||
* @param {IStatusEvent} evt | ||
*/ | ||
* | ||
* @param {IStatusEvent} evt | ||
*/ | ||
protected notifyStatusListeners(evt: IStatusEvent): void; | ||
/** | ||
* | ||
* @param {string} name | ||
*/ | ||
* | ||
* @param {string} name | ||
*/ | ||
protected setName(name: string): void; | ||
/** | ||
* | ||
* @param {string} description | ||
*/ | ||
* | ||
* @param {string} description | ||
*/ | ||
protected setDescription(description: string): void; | ||
/** | ||
* Set the unique identifier for the emitter | ||
* @param {string} id | ||
*/ | ||
* Set the unique identifier for the emitter | ||
* @param {string} id | ||
*/ | ||
protected setId(id: string): void; | ||
/** | ||
* Takes a simple function listener parameter and turns it into the listener interface | ||
* format | ||
* @param {IStatusChangeListenerFunc} listener | ||
* @return {IStatusChangeListener} | ||
*/ | ||
* Takes a simple function listener parameter and turns it into the listener interface | ||
* format | ||
* @param {IStatusChangeListenerFunc} listener | ||
* @return {IStatusChangeListener} | ||
*/ | ||
protected wrapStatusListener(listener: IStatusChangeListenerFunc): IStatusChangeListener; | ||
/** | ||
* Wrap a data listener function into a {IDataEventListener} | ||
* @param {IDataEventListenerFunc} listener | ||
* @return {IDataEventListener} | ||
*/ | ||
* Wrap a data listener function into a {IDataEventListener} | ||
* @param {IDataEventListenerFunc} listener | ||
* @return {IDataEventListener} | ||
*/ | ||
protected wrapDataListener(listener: IDataEventListenerFunc): IDataEventListener; | ||
/** | ||
* | ||
* @param {IStatusChangeListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
* | ||
* @param {IStatusChangeListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
onStatus(listener: IStatusChangeListener | IStatusChangeListenerFunc): IDisposable; | ||
/** | ||
* Clear any faults and notify listeners of change if change | ||
*/ | ||
* Clear any faults and notify listeners of change if change | ||
*/ | ||
protected clearIfFaulted(): void; | ||
/** | ||
* faulted | ||
*/ | ||
* faulted | ||
*/ | ||
protected faulted(): void; | ||
/** | ||
* connected | ||
*/ | ||
* connected | ||
*/ | ||
protected connected(): void; | ||
/** | ||
* disconnected | ||
*/ | ||
* disconnected | ||
*/ | ||
protected disconnected(): void; | ||
/** | ||
* build a status event | ||
* @return {IStatusEvent} | ||
*/ | ||
* build a status event | ||
* @return {IStatusEvent} | ||
*/ | ||
protected buildStatusEvent(): IStatusEvent; | ||
/** | ||
* build a data event | ||
* @param {unknown} data | ||
* @return {IDataEvent} | ||
*/ | ||
* build a data event | ||
* @param {unknown} data | ||
* @return {IDataEvent} | ||
*/ | ||
protected buildDataEvent(data: unknown): IDataEvent; | ||
/** | ||
* Sets how frequently the dc check is executed | ||
* @param {number} checkInterval | ||
* @param {number} threshold | ||
* @protected | ||
*/ | ||
* Sets how frequently the dc check is executed | ||
* @param {number} checkInterval | ||
* @param {number} threshold | ||
* @protected | ||
*/ | ||
protected setDCCheckInterval(checkInterval: number, threshold: number): void; | ||
/** | ||
* Execute logic to detect disconnections and notify listeners | ||
* @private | ||
*/ | ||
* Execute logic to detect disconnections and notify listeners | ||
* @private | ||
*/ | ||
private dcHandler; | ||
/** | ||
* Apply settings to the emitter, this could be emitter settings | ||
* such as poll intervel, d/c threshold, or use the additional | ||
* property to apply settings to the underlying source | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResul>} | ||
*/ | ||
* Apply settings to the emitter, this could be emitter settings | ||
* such as poll intervel, d/c threshold, or use the additional | ||
* property to apply settings to the underlying source | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResul>} | ||
*/ | ||
applySettings(settings: ISettings & ITraceableAction): Promise<IExecutionResult>; | ||
/** | ||
* Prefix a log message with information about the emitter | ||
* @param {string} msg | ||
* @return {string} | ||
*/ | ||
* Prefix a log message with information about the emitter | ||
* @param {string} msg | ||
* @return {string} | ||
*/ | ||
protected prefixLogMessage(msg: string): string; | ||
/** | ||
* Log information | ||
* @param {LogLevel} level | ||
* @param {String} msg | ||
* @return {void} | ||
*/ | ||
* Log information | ||
* @param {LogLevel} level | ||
* @param {String} msg | ||
* @return {void} | ||
*/ | ||
protected log(level: LogLevel, msg: string): void; | ||
@@ -236,0 +238,0 @@ /** |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,2 +11,3 @@ exports.BaseEmitter = exports.BaseDataEvent = exports.BaseStatusEvent = void 0; | ||
const chronicler_1 = require("./chronicler"); | ||
const events_1 = __importDefault(require("events")); | ||
/** | ||
@@ -14,8 +18,8 @@ * | ||
/** | ||
* | ||
* @param {boolean} connected | ||
* @param {boolean} bit | ||
* @param {IDataEmitter} emitter | ||
* @param {Date} timestamp | ||
*/ | ||
* | ||
* @param {boolean} connected | ||
* @param {boolean} bit | ||
* @param {IDataEmitter} emitter | ||
* @param {Date} timestamp | ||
*/ | ||
constructor(connected, bit, emitter, timestamp) { | ||
@@ -28,4 +32,4 @@ this.connected = connected; | ||
/** | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON() { | ||
@@ -45,7 +49,7 @@ return { | ||
/** | ||
* Create a data event object | ||
* @param {IDataEmitter} emitter | ||
* @param {unknown} data | ||
* @param {unknown} meta | ||
*/ | ||
* Create a data event object | ||
* @param {IDataEmitter} emitter | ||
* @param {unknown} data | ||
* @param {unknown} meta | ||
*/ | ||
constructor(emitter, data, meta) { | ||
@@ -58,5 +62,5 @@ this.emitter = emitter; | ||
/** | ||
* Converts the object into a JSON friendly object | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* Converts the object into a JSON friendly object | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON() { | ||
@@ -83,11 +87,12 @@ const ret = { | ||
*/ | ||
class BaseEmitter { | ||
class BaseEmitter extends events_1.default { | ||
/** | ||
* | ||
* @param {string} _id | ||
* @param {string} _name | ||
* @param {string} _description | ||
* @param {LoggerFacade|undefined} _logger | ||
*/ | ||
* | ||
* @param {string} _id | ||
* @param {string} _name | ||
* @param {string} _description | ||
* @param {LoggerFacade|undefined} _logger | ||
*/ | ||
constructor(_id, _name, _description, _logger = undefined) { | ||
super(); | ||
this._id = _id; | ||
@@ -98,28 +103,28 @@ this._name = _name; | ||
/** | ||
* Listener collection for data change listeners | ||
*/ | ||
* Listener collection for data change listeners | ||
*/ | ||
this._dataListeners = new Set(); | ||
/** | ||
* Listener collection for status change listeners | ||
*/ | ||
* Listener collection for status change listeners | ||
*/ | ||
this._statusListeners = new Set(); | ||
/** | ||
* connected state | ||
*/ | ||
* connected state | ||
*/ | ||
this._connected = false; | ||
/** | ||
* faulted state | ||
*/ | ||
* faulted state | ||
*/ | ||
this._faulted = false; | ||
/** | ||
* amount of time since successful message emission till we consider | ||
* the state to be disconnected | ||
* @private | ||
*/ | ||
* amount of time since successful message emission till we consider | ||
* the state to be disconnected | ||
* @private | ||
*/ | ||
this._dcThresholdMs = 60000; | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Creating BaseEmitter"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Creating BaseEmitter'); | ||
} | ||
/** | ||
* @return {string} unique id for emitter | ||
*/ | ||
* @return {string} unique id for emitter | ||
*/ | ||
get id() { | ||
@@ -129,4 +134,4 @@ return this._id; | ||
/** | ||
* @return {string} emitter name | ||
*/ | ||
* @return {string} emitter name | ||
*/ | ||
get name() { | ||
@@ -136,4 +141,4 @@ return this._name; | ||
/** | ||
* @return {string} communication link description | ||
*/ | ||
* @return {string} communication link description | ||
*/ | ||
get description() { | ||
@@ -143,6 +148,6 @@ return this._description; | ||
/** | ||
* serialize the important data that is needed to be able to recreate this emitter in it's current state | ||
* @param {IFormatSettings} settings used to specify expected format of the serialization | ||
* @return {Promise<string>} | ||
*/ | ||
* serialize the important data that is needed to be able to recreate this emitter in it's current state | ||
* @param {IFormatSettings} settings used to specify expected format of the serialization | ||
* @return {Promise<string>} | ||
*/ | ||
serializeState(settings) { | ||
@@ -157,5 +162,5 @@ if (!settings.encrypted) { | ||
/** | ||
* Control serialized properties when JSON.stringify is called | ||
* @return {Record<string, unknown>} | ||
*/ | ||
* Control serialized properties when JSON.stringify is called | ||
* @return {Record<string, unknown>} | ||
*/ | ||
toJSON() { | ||
@@ -169,19 +174,20 @@ return { | ||
/** | ||
* | ||
* @param {IDataEvent} evt | ||
*/ | ||
* | ||
* @param {IDataEvent} evt | ||
*/ | ||
notifyDataListeners(evt) { | ||
this.log(loggerFacade_1.LogLevel.TRACE, "Notifying data listeners"); | ||
this.log(loggerFacade_1.LogLevel.TRACE, 'Notifying data listeners'); | ||
this._dataListeners.forEach((listener) => { | ||
listener.onData(evt); | ||
}); | ||
this.emit('data', evt); | ||
} | ||
/** | ||
* | ||
* @param {IDataEventListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
* | ||
* @param {IDataEventListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
onData(listener) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "adding data listener"); | ||
if (typeof listener == 'function') | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'adding data listener'); | ||
if (typeof listener === 'function') | ||
listener = this.wrapDataListener(listener); | ||
@@ -191,6 +197,6 @@ this._dataListeners.add(listener); | ||
/** | ||
* remove the listener from the set | ||
*/ | ||
* remove the listener from the set | ||
*/ | ||
dispose: () => { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Removing data listener"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Removing data listener'); | ||
this._dataListeners.delete(listener); | ||
@@ -201,5 +207,5 @@ } | ||
/** | ||
* | ||
* @param {IStatusEvent} evt | ||
*/ | ||
* | ||
* @param {IStatusEvent} evt | ||
*/ | ||
notifyStatusListeners(evt) { | ||
@@ -210,7 +216,8 @@ this.log(loggerFacade_1.LogLevel.DEBUG, `Notifying ${this._statusListeners.size} listeners of a status change`); | ||
}); | ||
this.emit('status', evt); | ||
} | ||
/** | ||
* | ||
* @param {string} name | ||
*/ | ||
* | ||
* @param {string} name | ||
*/ | ||
setName(name) { | ||
@@ -220,5 +227,5 @@ this._name = name; | ||
/** | ||
* | ||
* @param {string} description | ||
*/ | ||
* | ||
* @param {string} description | ||
*/ | ||
setDescription(description) { | ||
@@ -228,5 +235,5 @@ this._description = description; | ||
/** | ||
* Set the unique identifier for the emitter | ||
* @param {string} id | ||
*/ | ||
* Set the unique identifier for the emitter | ||
* @param {string} id | ||
*/ | ||
setId(id) { | ||
@@ -236,7 +243,7 @@ this._id = id; | ||
/** | ||
* Takes a simple function listener parameter and turns it into the listener interface | ||
* format | ||
* @param {IStatusChangeListenerFunc} listener | ||
* @return {IStatusChangeListener} | ||
*/ | ||
* Takes a simple function listener parameter and turns it into the listener interface | ||
* format | ||
* @param {IStatusChangeListenerFunc} listener | ||
* @return {IStatusChangeListener} | ||
*/ | ||
wrapStatusListener(listener) { | ||
@@ -248,6 +255,6 @@ return { | ||
/** | ||
* Wrap a data listener function into a {IDataEventListener} | ||
* @param {IDataEventListenerFunc} listener | ||
* @return {IDataEventListener} | ||
*/ | ||
* Wrap a data listener function into a {IDataEventListener} | ||
* @param {IDataEventListenerFunc} listener | ||
* @return {IDataEventListener} | ||
*/ | ||
wrapDataListener(listener) { | ||
@@ -259,9 +266,9 @@ return { | ||
/** | ||
* | ||
* @param {IStatusChangeListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
* | ||
* @param {IStatusChangeListener} listener | ||
* @return {IDisposable} | ||
*/ | ||
onStatus(listener) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Adding status listener"); | ||
if (typeof listener == 'function') | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Adding status listener'); | ||
if (typeof listener === 'function') | ||
listener = this.wrapStatusListener(listener); | ||
@@ -271,3 +278,3 @@ this._statusListeners.add(listener); | ||
dispose: () => { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Removing status listener"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Removing status listener'); | ||
this._statusListeners.delete(listener); | ||
@@ -278,4 +285,4 @@ } | ||
/** | ||
* Clear any faults and notify listeners of change if change | ||
*/ | ||
* Clear any faults and notify listeners of change if change | ||
*/ | ||
clearIfFaulted() { | ||
@@ -288,4 +295,4 @@ if (this._faulted) { | ||
/** | ||
* faulted | ||
*/ | ||
* faulted | ||
*/ | ||
faulted() { | ||
@@ -298,4 +305,4 @@ if (!this._faulted) { | ||
/** | ||
* connected | ||
*/ | ||
* connected | ||
*/ | ||
connected() { | ||
@@ -308,4 +315,4 @@ if (!this._connected) { | ||
/** | ||
* disconnected | ||
*/ | ||
* disconnected | ||
*/ | ||
disconnected() { | ||
@@ -318,5 +325,5 @@ if (this._connected) { | ||
/** | ||
* build a status event | ||
* @return {IStatusEvent} | ||
*/ | ||
* build a status event | ||
* @return {IStatusEvent} | ||
*/ | ||
buildStatusEvent() { | ||
@@ -326,6 +333,6 @@ return new BaseStatusEvent(this._connected, this._faulted, this); | ||
/** | ||
* build a data event | ||
* @param {unknown} data | ||
* @return {IDataEvent} | ||
*/ | ||
* build a data event | ||
* @param {unknown} data | ||
* @return {IDataEvent} | ||
*/ | ||
buildDataEvent(data) { | ||
@@ -335,7 +342,7 @@ return new BaseDataEvent(this, data, this.getMetaData()); | ||
/** | ||
* Sets how frequently the dc check is executed | ||
* @param {number} checkInterval | ||
* @param {number} threshold | ||
* @protected | ||
*/ | ||
* Sets how frequently the dc check is executed | ||
* @param {number} checkInterval | ||
* @param {number} threshold | ||
* @protected | ||
*/ | ||
setDCCheckInterval(checkInterval, threshold) { | ||
@@ -350,5 +357,5 @@ this.log(loggerFacade_1.LogLevel.DEBUG, `setting the d/c check interval to ${checkInterval}ms with a threshold of ${threshold}ms`); | ||
/** | ||
* Execute logic to detect disconnections and notify listeners | ||
* @private | ||
*/ | ||
* Execute logic to detect disconnections and notify listeners | ||
* @private | ||
*/ | ||
dcHandler() { | ||
@@ -370,10 +377,10 @@ this._logger?.debug('checking if emitter is disconnected'); | ||
/** | ||
* Apply settings to the emitter, this could be emitter settings | ||
* such as poll intervel, d/c threshold, or use the additional | ||
* property to apply settings to the underlying source | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResul>} | ||
*/ | ||
* Apply settings to the emitter, this could be emitter settings | ||
* such as poll intervel, d/c threshold, or use the additional | ||
* property to apply settings to the underlying source | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResul>} | ||
*/ | ||
applySettings(settings) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Applying Settings"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Applying Settings'); | ||
this.setName(settings.name); | ||
@@ -388,6 +395,6 @@ this.setId(settings.id); | ||
/** | ||
* Prefix a log message with information about the emitter | ||
* @param {string} msg | ||
* @return {string} | ||
*/ | ||
* Prefix a log message with information about the emitter | ||
* @param {string} msg | ||
* @return {string} | ||
*/ | ||
prefixLogMessage(msg) { | ||
@@ -397,7 +404,7 @@ return `${this.getType()}|${this.name}|${this.id}| ${msg}`; | ||
/** | ||
* Log information | ||
* @param {LogLevel} level | ||
* @param {String} msg | ||
* @return {void} | ||
*/ | ||
* Log information | ||
* @param {LogLevel} level | ||
* @param {String} msg | ||
* @return {void} | ||
*/ | ||
log(level, msg) { | ||
@@ -462,3 +469,3 @@ if (this._logger != null) { | ||
dispose() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Disposing"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Disposing'); | ||
if (this._dcInterval != null) | ||
@@ -465,0 +472,0 @@ clearInterval(this._dcInterval); |
@@ -1,3 +0,3 @@ | ||
import { ISerializableState } from "./common"; | ||
import { IChroniclerDescription, IClassifier, IDataEvent, IDisposableAsync, IFormatSettings, IStatusEvent } from "./dataEmitter"; | ||
import { ISerializableState } from './common'; | ||
import { IChroniclerDescription, IClassifier, IDataEvent, IDisposableAsync, IFormatSettings, IStatusEvent } from './dataEmitter'; | ||
/** | ||
@@ -69,17 +69,17 @@ * Check if any object conforms to the IJsonSerializable interface | ||
/** | ||
* Unique id of the chronicler | ||
*/ | ||
* Unique id of the chronicler | ||
*/ | ||
get id(): string; | ||
/** | ||
* Name of the chronicler | ||
*/ | ||
* Name of the chronicler | ||
*/ | ||
get name(): string; | ||
/** | ||
* Description of the chronicler | ||
*/ | ||
* Description of the chronicler | ||
*/ | ||
get description(): string; | ||
/** | ||
* | ||
* @param {IChroniclerDescription} desc | ||
*/ | ||
* | ||
* @param {IChroniclerDescription} desc | ||
*/ | ||
constructor(desc: IChroniclerDescription); | ||
@@ -86,0 +86,0 @@ /** |
@@ -26,5 +26,5 @@ "use strict"; | ||
/** | ||
* | ||
* @param {IChroniclerDescription} desc | ||
*/ | ||
* | ||
* @param {IChroniclerDescription} desc | ||
*/ | ||
constructor(desc) { | ||
@@ -36,4 +36,4 @@ this._id = desc.id; | ||
/** | ||
* Unique id of the chronicler | ||
*/ | ||
* Unique id of the chronicler | ||
*/ | ||
get id() { | ||
@@ -43,4 +43,4 @@ return this._id; | ||
/** | ||
* Name of the chronicler | ||
*/ | ||
* Name of the chronicler | ||
*/ | ||
get name() { | ||
@@ -50,4 +50,4 @@ return this._name; | ||
/** | ||
* Description of the chronicler | ||
*/ | ||
* Description of the chronicler | ||
*/ | ||
get description() { | ||
@@ -54,0 +54,0 @@ return this._description; |
@@ -1,2 +0,2 @@ | ||
import { IFormatSettings } from "./lib"; | ||
import { IFormatSettings } from './lib'; | ||
export interface ISerializableState { | ||
@@ -3,0 +3,0 @@ /** |
@@ -17,5 +17,5 @@ "use strict"; | ||
return false; | ||
if (typeof obj == 'object') { | ||
if (typeof obj === 'object') { | ||
const val = obj; | ||
return typeof val[methodName] == 'function'; | ||
return typeof val[methodName] === 'function'; | ||
} | ||
@@ -49,3 +49,3 @@ return false; | ||
async function encrypt(json, settings) { | ||
if (settings.algorithm.toLowerCase().indexOf('gcm') != -1) { | ||
if (settings.algorithm.toLowerCase().indexOf('gcm') !== -1) { | ||
const gcmCipher = crypto_1.default.createCipheriv(settings.algorithm, Buffer.from(settings.key, 'base64'), Buffer.from(settings.iv, 'base64'), { | ||
@@ -71,3 +71,3 @@ authTagLength: 16 | ||
async function decrypt(base64CipherText, settings) { | ||
if (settings.algorithm.toLowerCase().indexOf('gcm') != -1) { | ||
if (settings.algorithm.toLowerCase().indexOf('gcm') !== -1) { | ||
const gcmCipher = crypto_1.default.createDecipheriv(settings.algorithm, Buffer.from(settings.key, 'base64'), Buffer.from(settings.iv, 'base64')); | ||
@@ -74,0 +74,0 @@ const buffer = Buffer.from(base64CipherText, 'base64'); |
@@ -1,4 +0,20 @@ | ||
import { IChronicler, IJsonSerializable } from "./chronicler"; | ||
import { ISerializableState } from "./common"; | ||
import { LoggerFacade } from "./loggerFacade"; | ||
/// <reference types="node" /> | ||
import EventEmitter from 'events'; | ||
import { IChronicler, IJsonSerializable } from './chronicler'; | ||
import { ISerializableState } from './common'; | ||
import { LoggerFacade } from './loggerFacade'; | ||
export interface IEmitterDescription { | ||
emitterProperties: unknown; | ||
type: string; | ||
name: string; | ||
id: string; | ||
description: string; | ||
} | ||
export interface IChroniclerDescription { | ||
chroniclerProperties: unknown; | ||
type: string; | ||
name: string; | ||
id: string; | ||
description: string; | ||
} | ||
/** | ||
@@ -167,3 +183,3 @@ * A action with a unique identifier, the identifier | ||
*/ | ||
export interface IDataEmitter extends IJsonSerializable, IClassifier, ISerializableState { | ||
export interface IDataEmitter extends IJsonSerializable, IClassifier, ISerializableState, EventEmitter { | ||
/** | ||
@@ -243,2 +259,7 @@ * Register a data listener that will receive events on new data | ||
} | ||
export interface IEmitterFactory { | ||
buildEmitter(description: IEmitterDescription): Promise<IDataEmitter>; | ||
recreateEmitter(base64StateData: string, formatSettings: IFormatSettings): Promise<IDataEmitter>; | ||
setLoggerFacade(loggerFacade: LoggerFacade): void; | ||
} | ||
export interface IEmitterProvider extends IEmitterFactory { | ||
@@ -249,5 +270,5 @@ registerEmitterFactory(type: string, factory: IEmitterFactory): void; | ||
} | ||
export interface IEmitterFactory { | ||
buildEmitter(description: IEmitterDescription): Promise<IDataEmitter>; | ||
recreateEmitter(base64StateData: string, formatSettings: IFormatSettings): Promise<IDataEmitter>; | ||
export interface IChroniclerFactory { | ||
buildChronicler(description: IChroniclerDescription): Promise<IChronicler>; | ||
recreateChronicler(base64StateData: string, formatSettings: IFormatSettings): Promise<IChronicler>; | ||
setLoggerFacade(loggerFacade: LoggerFacade): void; | ||
@@ -260,20 +281,1 @@ } | ||
} | ||
export interface IChroniclerFactory { | ||
buildChronicler(description: IChroniclerDescription): Promise<IChronicler>; | ||
recreateChronicler(base64StateData: string, formatSettings: IFormatSettings): Promise<IChronicler>; | ||
setLoggerFacade(loggerFacade: LoggerFacade): void; | ||
} | ||
export interface IEmitterDescription { | ||
emitterProperties: unknown; | ||
type: string; | ||
name: string; | ||
id: string; | ||
description: string; | ||
} | ||
export interface IChroniclerDescription { | ||
chroniclerProperties: unknown; | ||
type: string; | ||
name: string; | ||
id: string; | ||
description: string; | ||
} |
@@ -12,3 +12,3 @@ "use strict"; | ||
return false; | ||
if (typeof obj != 'object') | ||
if (typeof obj !== 'object') | ||
return false; | ||
@@ -28,3 +28,3 @@ const record = obj; | ||
return false; | ||
if (typeof obj != 'object') | ||
if (typeof obj !== 'object') | ||
return false; | ||
@@ -31,0 +31,0 @@ const record = obj; |
@@ -1,4 +0,4 @@ | ||
import { IChronicler } from "./chronicler"; | ||
import { IChroniclerDescription, IChroniclerFactory, IDataEmitter, IEmitterDescription, IEmitterFactory, IFormatSettings } from "./dataEmitter"; | ||
import { LoggerFacade } from "./loggerFacade"; | ||
import { IChronicler } from './chronicler'; | ||
import { IChroniclerDescription, IChroniclerFactory, IDataEmitter, IEmitterDescription, IEmitterFactory, IFormatSettings } from './dataEmitter'; | ||
import { LoggerFacade } from './loggerFacade'; | ||
/** | ||
@@ -10,5 +10,5 @@ * | ||
/** | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
setLoggerFacade(loggerFacade: LoggerFacade): void; | ||
@@ -15,0 +15,0 @@ } |
@@ -11,5 +11,5 @@ "use strict"; | ||
/** | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
setLoggerFacade(loggerFacade) { | ||
@@ -16,0 +16,0 @@ this.loggerFacade = loggerFacade; |
@@ -6,9 +6,15 @@ "use strict"; | ||
(function (LogLevel) { | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["TRACE"] = 0] = "TRACE"; | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG"; | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["INFO"] = 2] = "INFO"; | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["WARN"] = 3] = "WARN"; | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["ERROR"] = 4] = "ERROR"; | ||
// eslint-disable-next-line no-unused-vars | ||
LogLevel[LogLevel["CRITICAL"] = 5] = "CRITICAL"; | ||
})(LogLevel = exports.LogLevel || (exports.LogLevel = {})); | ||
//# sourceMappingURL=loggerFacade.js.map |
@@ -1,4 +0,4 @@ | ||
import { IClassifier, IDataEmitter, IDisposable } from "./dataEmitter"; | ||
import { IChronicler } from "./chronicler"; | ||
import { IChroniclerDescription, IDisposableAsync, IEmitterDescription } from "./lib"; | ||
import { IClassifier, IDataEmitter, IDisposable } from './dataEmitter'; | ||
import { IChronicler } from './chronicler'; | ||
import { IChroniclerDescription, IDisposableAsync, IEmitterDescription } from './lib'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Methods to start and stop a service, |
@@ -12,5 +12,5 @@ "use strict"; | ||
return false; | ||
if (typeof obj == 'object') { | ||
if (typeof obj === 'object') { | ||
const castedObj = obj; | ||
return typeof castedObj.stop == 'function' && typeof castedObj.start == 'function'; | ||
return typeof castedObj.stop === 'function' && typeof castedObj.start === 'function'; | ||
} | ||
@@ -17,0 +17,0 @@ return false; |
/// <reference types="node" /> | ||
import { BaseEmitter } from "./baseEmitter"; | ||
import { IDataEvent, IExecutionResult, ISettings, IStatusEvent, ITraceableAction } from "./dataEmitter"; | ||
import { LoggerFacade } from "./loggerFacade"; | ||
import { IService } from "./maestro"; | ||
import { BaseEmitter } from './baseEmitter'; | ||
import { IDataEvent, IExecutionResult, ISettings, IStatusEvent, ITraceableAction } from './dataEmitter'; | ||
import { LoggerFacade } from './loggerFacade'; | ||
import { IService } from './maestro'; | ||
export interface IPollingSettings { | ||
@@ -19,48 +19,48 @@ interval: number; | ||
/** | ||
* | ||
* @param {string} id | ||
* @param {string} name | ||
* @param {string} desc | ||
* @param {number} interval | ||
* @param {LoggerFacade|undefined} logger | ||
*/ | ||
* | ||
* @param {string} id | ||
* @param {string} name | ||
* @param {string} desc | ||
* @param {number} interval | ||
* @param {LoggerFacade|undefined} logger | ||
*/ | ||
constructor(id: string, name: string, desc: string, _interval: number, logger?: LoggerFacade | undefined); | ||
/** | ||
* Execute the poll and emit the result | ||
* @return {Promise<void>} | ||
*/ | ||
* Execute the poll and emit the result | ||
* @return {Promise<void>} | ||
*/ | ||
protected pollExecutor(): Promise<void>; | ||
/** | ||
* Start polling | ||
*/ | ||
* Start polling | ||
*/ | ||
startPolling(): void; | ||
/** | ||
* Stop polling | ||
*/ | ||
* Stop polling | ||
*/ | ||
stopPolling(): void; | ||
/** | ||
* Start polling | ||
* @return {Promise<void>} | ||
*/ | ||
* Start polling | ||
* @return {Promise<void>} | ||
*/ | ||
start(): Promise<void>; | ||
/** | ||
* Stop Polling | ||
* @return {Promise<void>} | ||
*/ | ||
* Stop Polling | ||
* @return {Promise<void>} | ||
*/ | ||
stop(): Promise<void>; | ||
/** | ||
* probe current data | ||
* @return {IDataEvent} | ||
*/ | ||
* probe current data | ||
* @return {IDataEvent} | ||
*/ | ||
probeCurrentData(): Promise<IDataEvent>; | ||
/** | ||
* probe the status | ||
* @return {IStatusEvent} | ||
*/ | ||
* probe the status | ||
* @return {IStatusEvent} | ||
*/ | ||
probeStatus(): Promise<IStatusEvent>; | ||
/** | ||
* set settings | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResult>} | ||
*/ | ||
* set settings | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResult>} | ||
*/ | ||
applySettings(settings: ISettings & ITraceableAction & IPollingSettings): Promise<IExecutionResult>; | ||
@@ -82,5 +82,5 @@ /** | ||
/** | ||
* Execute the poll and emit the result if there has been a change | ||
* @return {Promise<void>} | ||
*/ | ||
* Execute the poll and emit the result if there has been a change | ||
* @return {Promise<void>} | ||
*/ | ||
protected pollExecutor(): Promise<void>; | ||
@@ -87,0 +87,0 @@ /** |
@@ -12,20 +12,20 @@ "use strict"; | ||
/** | ||
* | ||
* @param {string} id | ||
* @param {string} name | ||
* @param {string} desc | ||
* @param {number} interval | ||
* @param {LoggerFacade|undefined} logger | ||
*/ | ||
* | ||
* @param {string} id | ||
* @param {string} name | ||
* @param {string} desc | ||
* @param {number} interval | ||
* @param {LoggerFacade|undefined} logger | ||
*/ | ||
constructor(id, name, desc, _interval, logger = undefined) { | ||
super(id, name, desc, logger); | ||
this._interval = _interval; | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Creating PollingEmitter"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Creating PollingEmitter'); | ||
} | ||
/** | ||
* Execute the poll and emit the result | ||
* @return {Promise<void>} | ||
*/ | ||
* Execute the poll and emit the result | ||
* @return {Promise<void>} | ||
*/ | ||
pollExecutor() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, `polling data source`); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'polling data source'); | ||
return this.poll().then((res) => { | ||
@@ -43,6 +43,6 @@ this.log(loggerFacade_1.LogLevel.DEBUG, `finished polling data source, result = ${res}`); | ||
/** | ||
* Start polling | ||
*/ | ||
* Start polling | ||
*/ | ||
startPolling() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Starting Polling"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Starting Polling'); | ||
this.stopPolling(); | ||
@@ -52,7 +52,7 @@ this._intervalTimer = setInterval(this.pollExecutor.bind(this), this._interval); | ||
/** | ||
* Stop polling | ||
*/ | ||
* Stop polling | ||
*/ | ||
stopPolling() { | ||
if (this._intervalTimer != null) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Stopping Polling"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Stopping Polling'); | ||
clearInterval(this._intervalTimer); | ||
@@ -63,5 +63,5 @@ } | ||
/** | ||
* Start polling | ||
* @return {Promise<void>} | ||
*/ | ||
* Start polling | ||
* @return {Promise<void>} | ||
*/ | ||
start() { | ||
@@ -72,5 +72,5 @@ this.startPolling(); | ||
/** | ||
* Stop Polling | ||
* @return {Promise<void>} | ||
*/ | ||
* Stop Polling | ||
* @return {Promise<void>} | ||
*/ | ||
stop() { | ||
@@ -81,7 +81,7 @@ this.stopPolling(); | ||
/** | ||
* probe current data | ||
* @return {IDataEvent} | ||
*/ | ||
* probe current data | ||
* @return {IDataEvent} | ||
*/ | ||
probeCurrentData() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Probe current data"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Probe current data'); | ||
if (this._lastDataEvent) | ||
@@ -92,7 +92,7 @@ return Promise.resolve(this._lastDataEvent); | ||
/** | ||
* probe the status | ||
* @return {IStatusEvent} | ||
*/ | ||
* probe the status | ||
* @return {IStatusEvent} | ||
*/ | ||
probeStatus() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Probe current status"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Probe current status'); | ||
if (this._lastStatusEvent) | ||
@@ -103,8 +103,8 @@ return Promise.resolve(this._lastStatusEvent); | ||
/** | ||
* set settings | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResult>} | ||
*/ | ||
* set settings | ||
* @param {ISettings} settings | ||
* @return {Promise<IExecutionResult>} | ||
*/ | ||
async applySettings(settings) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Applying Settings"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Applying Settings'); | ||
const result = await super.applySettings(settings); | ||
@@ -124,3 +124,3 @@ if (!result.success) | ||
dispose() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Disposing"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Disposing'); | ||
super.dispose(); | ||
@@ -138,9 +138,9 @@ if (this._intervalTimer != null) | ||
/** | ||
* Execute the poll and emit the result if there has been a change | ||
* @return {Promise<void>} | ||
*/ | ||
* Execute the poll and emit the result if there has been a change | ||
* @return {Promise<void>} | ||
*/ | ||
pollExecutor() { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Polling"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Polling'); | ||
return this.poll().then((res) => { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Retrieved result from data source"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Retrieved result from data source'); | ||
this.connected(); | ||
@@ -150,3 +150,3 @@ this.clearIfFaulted(); | ||
if (this.hasChanged(dataEvt)) { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Publishing event"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Publishing event'); | ||
this._lastDataEvent = dataEvt; | ||
@@ -156,3 +156,3 @@ this.notifyDataListeners(this._lastDataEvent); | ||
else { | ||
this.log(loggerFacade_1.LogLevel.DEBUG, "Data has not changed"); | ||
this.log(loggerFacade_1.LogLevel.DEBUG, 'Data has not changed'); | ||
} | ||
@@ -159,0 +159,0 @@ }).catch((err) => { |
@@ -1,4 +0,4 @@ | ||
import { IChronicler } from "./chronicler"; | ||
import { IChroniclerDescription, IChroniclerFactory, IChroniclerProvider, IDataEmitter, IEmitterDescription, IEmitterFactory, IEmitterProvider, IFormatSettings } from "./dataEmitter"; | ||
import { LoggerFacade } from "./loggerFacade"; | ||
import { IChronicler } from './chronicler'; | ||
import { IChroniclerDescription, IChroniclerFactory, IChroniclerProvider, IDataEmitter, IEmitterDescription, IEmitterFactory, IEmitterProvider, IFormatSettings } from './dataEmitter'; | ||
import { LoggerFacade } from './loggerFacade'; | ||
/** | ||
@@ -15,76 +15,76 @@ * Central provider for emitters and chroniclers, factories are registered | ||
/** | ||
* | ||
* @param {string} type | ||
* @param {IEmitterFactory} factory | ||
*/ | ||
* | ||
* @param {string} type | ||
* @param {IEmitterFactory} factory | ||
*/ | ||
registerEmitterFactory(type: string, factory: IEmitterFactory): void; | ||
/** | ||
* | ||
* @param {EmitterDescription} description | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
* | ||
* @param {EmitterDescription} description | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
buildEmitter(description: IEmitterDescription): Promise<IDataEmitter>; | ||
/** | ||
* | ||
* @param {string} base64StateData | ||
* @param {IFormatSettings} formatSettings | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
* | ||
* @param {string} base64StateData | ||
* @param {IFormatSettings} formatSettings | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
recreateEmitter(base64StateData: string, formatSettings: IFormatSettings): Promise<IDataEmitter>; | ||
/** | ||
* | ||
* @param {string} stateData if encrypted, base64 encoded cipher text, otherwise a json string | ||
* @param {IFormatSettings} formatSettings the format settings describing the state data is encrypted | ||
* and if so what cipher type etc. | ||
* @return {IChronicler} | ||
*/ | ||
* | ||
* @param {string} stateData if encrypted, base64 encoded cipher text, otherwise a json string | ||
* @param {IFormatSettings} formatSettings the format settings describing the state data is encrypted | ||
* and if so what cipher type etc. | ||
* @return {IChronicler} | ||
*/ | ||
recreateChronicler(stateData: string, formatSettings: IFormatSettings): Promise<IChronicler>; | ||
/** | ||
* | ||
* @param {string} type | ||
* @param {IChroniclerFactory} factory | ||
*/ | ||
* | ||
* @param {string} type | ||
* @param {IChroniclerFactory} factory | ||
*/ | ||
registerChroniclerFactory(type: string, factory: IChroniclerFactory): void; | ||
/** | ||
* | ||
* @param {IChroniclerDescription} description | ||
* @return {Promise<IChronicler>} | ||
*/ | ||
* | ||
* @param {IChroniclerDescription} description | ||
* @return {Promise<IChronicler>} | ||
*/ | ||
buildChronicler(description: IChroniclerDescription): Promise<IChronicler>; | ||
/** | ||
* | ||
* @param {string} type | ||
*/ | ||
* | ||
* @param {string} type | ||
*/ | ||
removeChroniclerFactory(type: string): void; | ||
/** | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
hasChroniclerFactory(type: string): boolean; | ||
/** | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
getChroniclerFactoryTypes(): string[]; | ||
/** | ||
* | ||
* @param {string} type | ||
*/ | ||
* | ||
* @param {string} type | ||
*/ | ||
removeEmitterFactory(type: string): void; | ||
/** | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
hasEmitterFactory(type: string): boolean; | ||
/** | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
getEmitterFactoryTypes(): string[]; | ||
/** | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
setLoggerFacade(loggerFacade: LoggerFacade): void; | ||
@@ -98,7 +98,7 @@ } | ||
/** | ||
* | ||
* @return {Provider} | ||
*/ | ||
* | ||
* @return {Provider} | ||
*/ | ||
static getInstance(): Provider; | ||
} | ||
export {}; |
@@ -16,6 +16,6 @@ "use strict"; | ||
/** | ||
* | ||
* @param {string} type | ||
* @param {IEmitterFactory} factory | ||
*/ | ||
* | ||
* @param {string} type | ||
* @param {IEmitterFactory} factory | ||
*/ | ||
registerEmitterFactory(type, factory) { | ||
@@ -27,6 +27,6 @@ if (this.logger) | ||
/** | ||
* | ||
* @param {EmitterDescription} description | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
* | ||
* @param {EmitterDescription} description | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
buildEmitter(description) { | ||
@@ -43,7 +43,7 @@ const key = description.type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} base64StateData | ||
* @param {IFormatSettings} formatSettings | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
* | ||
* @param {string} base64StateData | ||
* @param {IFormatSettings} formatSettings | ||
* @return {Promise<IDataEmitter>} | ||
*/ | ||
recreateEmitter(base64StateData, formatSettings) { | ||
@@ -60,8 +60,8 @@ const key = formatSettings.type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} stateData if encrypted, base64 encoded cipher text, otherwise a json string | ||
* @param {IFormatSettings} formatSettings the format settings describing the state data is encrypted | ||
* and if so what cipher type etc. | ||
* @return {IChronicler} | ||
*/ | ||
* | ||
* @param {string} stateData if encrypted, base64 encoded cipher text, otherwise a json string | ||
* @param {IFormatSettings} formatSettings the format settings describing the state data is encrypted | ||
* and if so what cipher type etc. | ||
* @return {IChronicler} | ||
*/ | ||
recreateChronicler(stateData, formatSettings) { | ||
@@ -78,6 +78,6 @@ const key = formatSettings.type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} type | ||
* @param {IChroniclerFactory} factory | ||
*/ | ||
* | ||
* @param {string} type | ||
* @param {IChroniclerFactory} factory | ||
*/ | ||
registerChroniclerFactory(type, factory) { | ||
@@ -89,6 +89,6 @@ if (this.logger) | ||
/** | ||
* | ||
* @param {IChroniclerDescription} description | ||
* @return {Promise<IChronicler>} | ||
*/ | ||
* | ||
* @param {IChroniclerDescription} description | ||
* @return {Promise<IChronicler>} | ||
*/ | ||
buildChronicler(description) { | ||
@@ -105,5 +105,5 @@ const key = description.type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} type | ||
*/ | ||
* | ||
* @param {string} type | ||
*/ | ||
removeChroniclerFactory(type) { | ||
@@ -115,6 +115,6 @@ const key = type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
hasChroniclerFactory(type) { | ||
@@ -124,5 +124,5 @@ return this._chroncilerFactories.has(type.toLowerCase()); | ||
/** | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
getChroniclerFactoryTypes() { | ||
@@ -132,5 +132,5 @@ return Array.from(this._chroncilerFactories.keys()); | ||
/** | ||
* | ||
* @param {string} type | ||
*/ | ||
* | ||
* @param {string} type | ||
*/ | ||
removeEmitterFactory(type) { | ||
@@ -142,6 +142,6 @@ const key = type.toLowerCase(); | ||
/** | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
hasEmitterFactory(type) { | ||
@@ -151,5 +151,5 @@ return this._emitterFactories.has(type.toLowerCase()); | ||
/** | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
* | ||
* @return {Array<string>} | ||
*/ | ||
getEmitterFactoryTypes() { | ||
@@ -159,5 +159,5 @@ return Array.from(this._emitterFactories.keys()); | ||
/** | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
* | ||
* @param {LoggerFacade} loggerFacade | ||
*/ | ||
setLoggerFacade(loggerFacade) { | ||
@@ -178,3 +178,3 @@ this.logger = loggerFacade; | ||
class ProviderSingleton { | ||
// eslint-disable-next-line require-jsdoc, @typescript-eslint/no-empty-function | ||
// eslint-disable-next-line require-jsdoc, @typescript-eslint/no-empty-function, no-useless-constructor | ||
constructor() { | ||
@@ -184,5 +184,5 @@ // This is intentional | ||
/** | ||
* | ||
* @return {Provider} | ||
*/ | ||
* | ||
* @return {Provider} | ||
*/ | ||
static getInstance() { | ||
@@ -189,0 +189,0 @@ return provider; |
{ | ||
"name": "@curium.rocks/data-emitter-base", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A collection of typescript class interfaces and base classes that specify generic contracts with things that emit data", | ||
@@ -10,2 +10,3 @@ "main": "build/src/lib.js", | ||
"lint": "eslint src --ext .ts", | ||
"lint:fix": "eslint --ext .ts src --fix", | ||
"clean": "rm -fr build", | ||
@@ -26,6 +27,7 @@ "prepare": "npm run build", | ||
"devDependencies": { | ||
"@types/chai": "4.3.3", | ||
"@types/mocha": "9.1.1", | ||
"@types/chai": "^4.3.3", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "18.7.6", | ||
"@typescript-eslint/eslint-plugin": "5.33.1", | ||
"@typescript-eslint/parser": "^5.15.0", | ||
"chai": "4.3.6", | ||
@@ -35,7 +37,12 @@ "eslint": "8.22.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-plugin-chai-friendly": "^0.7.2", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"madge": "5.0.1", | ||
"mocha": "10.0.0", | ||
"nyc": "15.1.0", | ||
"rxjs": "^7.5.6", | ||
"ts-node": "10.9.1", | ||
@@ -42,0 +49,0 @@ "typedoc": "0.23.10", |
@@ -48,2 +48,39 @@ # data-emitter-base | ||
#### Using RxJS | ||
```typescript | ||
import {IDataEmitter} from '@curium.rocks/data-emitter-base'; | ||
import {fromEvent} from 'rxjs'; | ||
// replace new ADataEmitterImplementation() with your code | ||
// to get a object IDataEmitter that implements | ||
// the IDataEmitter interface | ||
const emitter: IDataEmitter = new ADataEmitterImplementation(); | ||
const rxDataObservable = fromEvent(emitter, 'data'); | ||
const rxStatusObservable = fromEvent(emitter, 'status'); | ||
const dataSub = rxDataObservable.subscribe((evt) => { | ||
if(evt.data instanceof string){ | ||
console.log(`data: ${evt.data}`) | ||
} | ||
}) | ||
const statusSub = rxStatusObservable.subscribe((evt) => { | ||
if(evt.bit) { | ||
console.log("emitter is in a failed state"); | ||
} else { | ||
console.log("emitter is in a healthy state"); | ||
} | ||
if(evt.connected) { | ||
console.log("emitter is connected to it's data source"); | ||
} else { | ||
console.log("emitter is disconnected from it's data source"); | ||
} | ||
}) | ||
// cleanup | ||
dataSub.unsubscribe(); | ||
statusSub.unsubscribe(); | ||
``` | ||
#### On demand fetch | ||
@@ -230,4 +267,3 @@ | ||
``` | ||
## Integrations | ||
Check [here](https://www.npmjs.com/search?q=%40curium.rocks) for more integrations that implement these interfaces. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
103148
2176
267
22