fix: metrics stats and moving averages types (#915)

* fix: give stats initial values

Otherwise the compiler cannot derive the type and thinks `stats.snapshot` returns `{}`

* fix: add type shape to moving averages as well
This commit is contained in:
Alex Potsides 2021-04-16 16:10:22 +01:00 committed by GitHub
parent 55ee332907
commit 3d0a79eff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
'use strict'
const EventEmitter = require('events')
const Big = require('bignumber.js')
const { BigNumber: Big } = require('bignumber.js')
const MovingAverage = require('moving-average')
const retimer = require('retimer')
@ -19,11 +19,17 @@ class Stats extends EventEmitter {
this._options = options
this._queue = []
this._stats = {}
/** @type {{ dataReceived: Big, dataSent: Big }} */
this._stats = {
dataReceived: Big(0),
dataSent: Big(0)
}
this._frequencyLastTime = Date.now()
this._frequencyAccumulators = {}
/** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */
this._movingAverages = {}
this._update = this._update.bind(this)