@svta/cml-throughput 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ThroughputEstimator.ts","../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimatorOptions.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":[],"mappings":";;;;;;AAQA;;;;ACEa,KDFD,mBAAA,GCEC;EAAA;;;;;iBDIG;;AERhB;;;;ECAA,WAAY,EAAA,EAAA,MAAA;;;;;AHEZ;;;;ACEA;AAAa,cAAA,uBAAA,YAAmC,mBAAnC,CAAA;UAGU,OAAA;QAHyB,CAAA,MAAA,EAGzB,cAHyB,CAAA,EAAA,IAAA;EAAA,WAAA,CAAA,CAAA,EAAA,MAAA;;;;;;;ADFhD;;;cEFa,IAAA;EDIb,QAAa,KAAA;EAAA,QAAA,QAAA;UAGU,aAAA;aAHyB,CAAA,KAAA,EAAA,MAAA;EAAA;;;;ECJhD;;;;ACAA;;;;ACMA;;kBAQ6B,CAAA,CAAA,EAAA,MAAA;;;;;;;AJZ7B;;;KGFY,oBAAA;EFIZ,eAAa,CAAA,EAAA,MAAA;EAAA,aAAA,CAAA,EAAA,MAAA;aAGU,CAAA,EAAA,MAAA;cAHyB,EAAA,MAAA;EAAA,YAAA,EAAA,MAAA;;;;ADFhD;;;;ACEA;;AAGuB,cGDV,aAAA,YAAyB,mBHCf,CAAA;UAHyB,eAAA;EAAA,QAAA,aAAA;;;;ECJhD,QAAa,QAAA;uBEcgB;iBAcN;;AD5BvB;;;;AHEA;;;;ACEA;AAAa,cIAA,qBAAA,YAAiC,mBJAjC,CAAA;UAGU,OAAA;QAHyB,CAAA,MAAA,EIGzB,cJHyB,CAAA,EAAA,IAAA;EAAA,WAAA,CAAA,CAAA,EAAA,MAAA;;;;;ADFhD;;;;ACEA;AAAa,cKAA,cAAA,YAA0B,mBLA1B,CAAA;UAGU,OAAA;QAHyB,CAAA,MAAA,EKGzB,cLHyB,CAAA,EAAA,IAAA;EAAA,WAAA,CAAA,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ThroughputEstimator.ts","../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimatorOptions.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":[],"mappings":";;;;;;AAQA;;;;ACEa,KDFD,mBAAA,GCEC;;;;ACJb;;iBFQgB;;AGRhB;;;;ECMA,WAAa,EAAA,EAAA,MAAA;CAQgB;;;;AJZ7B;;;;ACEA;cAAa,uBAAA,YAAmC;;iBAGzB;ECPvB,WAAa,CAAA,CAAA,EAAA,MAAA;;;;;;;AFEb;;;cEFa,IAAA;EDIb,QAAa,KAAA;;;;ECJb;;;;ECAA;;;;ACMA;;EAsBuB,WAAA,CAAA,CAAA,EAAA,MAAA;EAtBe;;;;;;;;;;AJJtC;;;KGFY,oBAAA;EFIZ,eAAa,CAAA,EAAA,MAAA;;;;ECJb,YAAa,EAAA,MAAA;;;;AFEb;;;;ACEA;;cGEa,aAAA,YAAyB;;EFNtC,QAAa,aAAA;;;;ECAb,QAAY,QAAA;uBCciB;iBAcN;;AAtBvB;;;;AJJA;;;;ACEA;cIAa,qBAAA,YAAiC;;iBAGvB;EHPvB,WAAa,CAAA,CAAA,EAAA,MAAA;;;;;AFEb;;;;ACEA;cKAa,cAAA,YAA0B;;iBAGhB;EJPvB,WAAa,CAAA,CAAA,EAAA,MAAA"}
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ var ArithmeticMeanEstimator = class {
16
16
  }
17
17
  getEstimate() {
18
18
  let value = 0;
19
- for (let i = 0; i < this.samples.length; i++) value += getBandwidthBps(this.samples[i]);
19
+ for (const sample of this.samples) value += getBandwidthBps(sample);
20
20
  return value / this.samples.length;
21
21
  }
22
22
  };
@@ -115,7 +115,7 @@ var HarmonicMeanEstimator = class {
115
115
  }
116
116
  getEstimate() {
117
117
  let value = 0;
118
- for (let i = 0; i < this.samples.length; i++) value += 1 / getBandwidthBps(this.samples[i]);
118
+ for (const sample of this.samples) value += 1 / getBandwidthBps(sample);
119
119
  return this.samples.length / value;
120
120
  }
121
121
  };
@@ -140,8 +140,8 @@ var ZlemaEstimator = class {
140
140
  const alpha = 2 / (this.samples.length + 1);
141
141
  let ema, zlema;
142
142
  ema = zlema = getBandwidthBps(this.samples[this.samples.length - 1]);
143
- for (let i = 0; i < this.samples.length; i++) {
144
- ema = alpha * getBandwidthBps(this.samples[i]) + (1 - alpha) * ema;
143
+ for (const sample of this.samples) {
144
+ ema = alpha * getBandwidthBps(sample) + (1 - alpha) * ema;
145
145
  zlema = alpha * ema + (1 - alpha) * zlema;
146
146
  }
147
147
  return zlema;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["value: number","value: number","ema: number","zlema: number"],"sources":["../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":["import type { ResourceTiming } from '@svta/cml-utils';\nimport { getBandwidthBps } from '@svta/cml-utils';\nimport type { ThroughputEstimator } from './ThroughputEstimator.js';\n\n/**\n * Arithmetic Mean throughput estimator\n *\n *\n * @beta\n */\nexport class ArithmeticMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = [];\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample);\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0;\n\n\t\tfor (let i = 0; i < this.samples.length; i++) {\n\t\t\tvalue += getBandwidthBps(this.samples[i]);\n\t\t}\n\n\t\treturn value / this.samples.length;\n\t}\n}\n","/**\n * Exponential Weighted Moving Average (EWMA)\n *\n *\n * @beta\n */\nexport class Ewma {\n\t// The smoothing factor for the EWMA\n\tprivate alpha: number;\n\t// The current estimate of the throughput (in bits per second)\n\tprivate estimate: number;\n\t// The total duration of the resource (in seconds)\n\tprivate totalDuration: number;\n\n\tconstructor(alpha: number) {\n\t\tthis.alpha = alpha;\n\t\tthis.estimate = 0;\n\t\tthis.totalDuration = 0;\n\t}\n\n\t/**\n\t * Samples the value of the resource and updates the estimate.\n\t */\n\tpublic sample(weight: number, value: number): void {\n\t\tconst adjustedAlpha = Math.pow(this.alpha, weight);\n\t\tthis.estimate = adjustedAlpha * value + (1 - adjustedAlpha) * this.estimate;\n\t\tthis.totalDuration += weight;\n\t}\n\n\t/**\n\t * Returns the estimate of the value (in units, as `value` during sampling)\n\t *\n\t * For example, if the value is throughput (in bits per seconds), the estimate\n\t * will also be in bits per seconds.\n\t */\n\tpublic getEstimate(): number {\n\t\tconst zeroFactor = 1 - Math.pow(this.alpha, this.totalDuration);\n\t\treturn this.estimate / zeroFactor;\n\t}\n\n\t/**\n\t * Returns the total duration of the resource (in units, as `weight` during sampling)\n\t */\n\tpublic getTotalDuration(): number {\n\t\treturn this.totalDuration;\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils';\nimport { getBandwidthBps } from '@svta/cml-utils';\nimport { Ewma } from './Ewma.js';\nimport type { EwmaEstimatorOptions } from './EwmaEstimatorOptions.js';\nimport type { ThroughputEstimator } from './ThroughputEstimator.js';\n\n/**\n * Exponential Weighted Moving Average (EWMA) throughput estimator based on 2 half-lives\n *\n *\n * @beta\n */\nexport class EwmaEstimator implements ThroughputEstimator {\n\tprivate defaultEstimate: number;\n\tprivate minTotalBytes: number;\n\tprivate minBodySize: number;\n\tprivate totalBytes: number = 0;\n\tprivate fastEwma: Ewma;\n\tprivate slowEwma: Ewma;\n\n\tpublic constructor(options: EwmaEstimatorOptions) {\n\t\tthis.minTotalBytes = options.minTotalBytes || 0;\n\t\tthis.minBodySize = options.minBodySize || 0;\n\t\tthis.defaultEstimate = options.defaultEstimate ?? NaN;\n\n\t\tthis.slowEwma = new Ewma(options.slowHalfLife);\n\t\tthis.fastEwma = new Ewma(options.fastHalfLife);\n\n\t\tif (!isNaN(this.defaultEstimate)) {\n\t\t\tthis.fastEwma.sample(1, this.defaultEstimate);\n\t\t\tthis.slowEwma.sample(1, this.defaultEstimate);\n\t\t}\n\t}\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tconst { encodedBodySize, duration } = sample;\n\n\t\tif (!Number.isFinite(encodedBodySize) || !Number.isFinite(duration)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (encodedBodySize < this.minBodySize) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst durationSeconds = sample.duration / 1000;\n\t\tconst bandwidthBps = getBandwidthBps(sample);\n\t\tthis.totalBytes += encodedBodySize;\n\n\t\tthis.slowEwma.sample(durationSeconds, bandwidthBps);\n\t\tthis.fastEwma.sample(durationSeconds, bandwidthBps);\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.totalBytes < this.minTotalBytes) {\n\t\t\treturn this.defaultEstimate;\n\t\t}\n\n\t\treturn Math.floor(Math.min(this.fastEwma.getEstimate(), this.slowEwma.getEstimate()));\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils';\nimport { getBandwidthBps } from '@svta/cml-utils';\nimport type { ThroughputEstimator } from './ThroughputEstimator.js';\n\n/**\n * Harmonic Mean throughput estimator\n *\n *\n * @beta\n */\nexport class HarmonicMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = [];\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample);\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0;\n\n\t\tfor (let i = 0; i < this.samples.length; i++) {\n\t\t\tvalue += 1 / getBandwidthBps(this.samples[i]);\n\t\t}\n\n\t\treturn this.samples.length / value;\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils';\nimport { getBandwidthBps } from '@svta/cml-utils';\nimport type { ThroughputEstimator } from './ThroughputEstimator.js';\n\n/**\n * Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator\n *\n *\n * @beta\n */\nexport class ZlemaEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = [];\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample);\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.samples.length === 0) {\n\t\t\treturn NaN;\n\t\t}\n\n\t\tconst alpha = 2 / (this.samples.length + 1);\n\n\t\tlet ema: number, zlema: number;\n\n\t\tema = zlema = getBandwidthBps(this.samples[this.samples.length - 1]);\n\n\t\tfor (let i = 0; i < this.samples.length; i++) {\n\t\t\tema = alpha * getBandwidthBps(this.samples[i]) + (1 - alpha) * ema;\n\t\t\tzlema = alpha * ema + (1 - alpha) * zlema;\n\t\t}\n\n\t\treturn zlema;\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,0BAAb,MAAoE;;iBAC/B,EAAE;;CAEtC,AAAO,OAAO,QAA8B;AAC3C,OAAK,QAAQ,KAAK,OAAO;;CAG1B,AAAO,cAAsB;EAC5B,IAAIA,QAAgB;AAEpB,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,IACxC,UAAS,gBAAgB,KAAK,QAAQ,GAAG;AAG1C,SAAO,QAAQ,KAAK,QAAQ;;;;;;;;;;;;AClB9B,IAAa,OAAb,MAAkB;CAQjB,YAAY,OAAe;AAC1B,OAAK,QAAQ;AACb,OAAK,WAAW;AAChB,OAAK,gBAAgB;;;;;CAMtB,AAAO,OAAO,QAAgB,OAAqB;EAClD,MAAM,gBAAgB,KAAK,IAAI,KAAK,OAAO,OAAO;AAClD,OAAK,WAAW,gBAAgB,SAAS,IAAI,iBAAiB,KAAK;AACnE,OAAK,iBAAiB;;;;;;;;CASvB,AAAO,cAAsB;EAC5B,MAAM,aAAa,IAAI,KAAK,IAAI,KAAK,OAAO,KAAK,cAAc;AAC/D,SAAO,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AAO,KAAK,QAAQ,SAAS;;;;;;;;;;;;ACd/B,IAAa,iBAAb,MAA2D;;iBACtB,EAAE;;CAEtC,AAAO,OAAO,QAA8B;AAC3C,OAAK,QAAQ,KAAK,OAAO;;CAG1B,AAAO,cAAsB;AAC5B,MAAI,KAAK,QAAQ,WAAW,EAC3B,QAAO;EAGR,MAAM,QAAQ,KAAK,KAAK,QAAQ,SAAS;EAEzC,IAAIC,KAAaC;AAEjB,QAAM,QAAQ,gBAAgB,KAAK,QAAQ,KAAK,QAAQ,SAAS,GAAG;AAEpE,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK;AAC7C,SAAM,QAAQ,gBAAgB,KAAK,QAAQ,GAAG,IAAI,IAAI,SAAS;AAC/D,WAAQ,QAAQ,OAAO,IAAI,SAAS;;AAGrC,SAAO"}
1
+ {"version":3,"file":"index.js","names":["value: number","value: number","ema: number","zlema: number"],"sources":["../src/ArithmeticMeanEstimator.ts","../src/Ewma.ts","../src/EwmaEstimator.ts","../src/HarmonicMeanEstimator.ts","../src/ZlemaEstimator.ts"],"sourcesContent":["import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Arithmetic Mean throughput estimator\n *\n *\n * @beta\n */\nexport class ArithmeticMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0\n\n\t\tfor (const sample of this.samples) {\n\t\t\tvalue += getBandwidthBps(sample)\n\t\t}\n\n\t\treturn value / this.samples.length\n\t}\n}\n","/**\n * Exponential Weighted Moving Average (EWMA)\n *\n *\n * @beta\n */\nexport class Ewma {\n\t// The smoothing factor for the EWMA\n\tprivate alpha: number\n\t// The current estimate of the throughput (in bits per second)\n\tprivate estimate: number\n\t// The total duration of the resource (in seconds)\n\tprivate totalDuration: number\n\n\tconstructor(alpha: number) {\n\t\tthis.alpha = alpha\n\t\tthis.estimate = 0\n\t\tthis.totalDuration = 0\n\t}\n\n\t/**\n\t * Samples the value of the resource and updates the estimate.\n\t */\n\tpublic sample(weight: number, value: number): void {\n\t\tconst adjustedAlpha = Math.pow(this.alpha, weight)\n\t\tthis.estimate = adjustedAlpha * value + (1 - adjustedAlpha) * this.estimate\n\t\tthis.totalDuration += weight\n\t}\n\n\t/**\n\t * Returns the estimate of the value (in units, as `value` during sampling)\n\t *\n\t * For example, if the value is throughput (in bits per seconds), the estimate\n\t * will also be in bits per seconds.\n\t */\n\tpublic getEstimate(): number {\n\t\tconst zeroFactor = 1 - Math.pow(this.alpha, this.totalDuration)\n\t\treturn this.estimate / zeroFactor\n\t}\n\n\t/**\n\t * Returns the total duration of the resource (in units, as `weight` during sampling)\n\t */\n\tpublic getTotalDuration(): number {\n\t\treturn this.totalDuration\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport { Ewma } from './Ewma.ts'\nimport type { EwmaEstimatorOptions } from './EwmaEstimatorOptions.ts'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Exponential Weighted Moving Average (EWMA) throughput estimator based on 2 half-lives\n *\n *\n * @beta\n */\nexport class EwmaEstimator implements ThroughputEstimator {\n\tprivate defaultEstimate: number\n\tprivate minTotalBytes: number\n\tprivate minBodySize: number\n\tprivate totalBytes: number = 0\n\tprivate fastEwma: Ewma\n\tprivate slowEwma: Ewma\n\n\tpublic constructor(options: EwmaEstimatorOptions) {\n\t\tthis.minTotalBytes = options.minTotalBytes || 0\n\t\tthis.minBodySize = options.minBodySize || 0\n\t\tthis.defaultEstimate = options.defaultEstimate ?? NaN\n\n\t\tthis.slowEwma = new Ewma(options.slowHalfLife)\n\t\tthis.fastEwma = new Ewma(options.fastHalfLife)\n\n\t\tif (!isNaN(this.defaultEstimate)) {\n\t\t\tthis.fastEwma.sample(1, this.defaultEstimate)\n\t\t\tthis.slowEwma.sample(1, this.defaultEstimate)\n\t\t}\n\t}\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tconst { encodedBodySize, duration } = sample\n\n\t\tif (!Number.isFinite(encodedBodySize) || !Number.isFinite(duration)) {\n\t\t\treturn\n\t\t}\n\n\t\tif (encodedBodySize < this.minBodySize) {\n\t\t\treturn\n\t\t}\n\n\t\tconst durationSeconds = sample.duration / 1000\n\t\tconst bandwidthBps = getBandwidthBps(sample)\n\t\tthis.totalBytes += encodedBodySize\n\n\t\tthis.slowEwma.sample(durationSeconds, bandwidthBps)\n\t\tthis.fastEwma.sample(durationSeconds, bandwidthBps)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.totalBytes < this.minTotalBytes) {\n\t\t\treturn this.defaultEstimate\n\t\t}\n\n\t\treturn Math.floor(Math.min(this.fastEwma.getEstimate(), this.slowEwma.getEstimate()))\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Harmonic Mean throughput estimator\n *\n *\n * @beta\n */\nexport class HarmonicMeanEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tlet value: number = 0\n\n\t\tfor (const sample of this.samples) {\n\t\t\tvalue += 1 / getBandwidthBps(sample)\n\t\t}\n\n\t\treturn this.samples.length / value\n\t}\n}\n","import type { ResourceTiming } from '@svta/cml-utils'\nimport { getBandwidthBps } from '@svta/cml-utils'\nimport type { ThroughputEstimator } from './ThroughputEstimator.ts'\n\n/**\n * Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator\n *\n *\n * @beta\n */\nexport class ZlemaEstimator implements ThroughputEstimator {\n\tprivate samples: ResourceTiming[] = []\n\n\tpublic sample(sample: ResourceTiming): void {\n\t\tthis.samples.push(sample)\n\t}\n\n\tpublic getEstimate(): number {\n\t\tif (this.samples.length === 0) {\n\t\t\treturn NaN\n\t\t}\n\n\t\tconst alpha = 2 / (this.samples.length + 1)\n\n\t\tlet ema: number, zlema: number\n\n\t\tema = zlema = getBandwidthBps(this.samples[this.samples.length - 1])\n\n\t\tfor (const sample of this.samples) {\n\t\t\tema = alpha * getBandwidthBps(sample) + (1 - alpha) * ema\n\t\t\tzlema = alpha * ema + (1 - alpha) * zlema\n\t\t}\n\n\t\treturn zlema\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,0BAAb,MAAoE;;iBAC/B,EAAE;;CAEtC,AAAO,OAAO,QAA8B;AAC3C,OAAK,QAAQ,KAAK,OAAO;;CAG1B,AAAO,cAAsB;EAC5B,IAAIA,QAAgB;AAEpB,OAAK,MAAM,UAAU,KAAK,QACzB,UAAS,gBAAgB,OAAO;AAGjC,SAAO,QAAQ,KAAK,QAAQ;;;;;;;;;;;;AClB9B,IAAa,OAAb,MAAkB;CAQjB,YAAY,OAAe;AAC1B,OAAK,QAAQ;AACb,OAAK,WAAW;AAChB,OAAK,gBAAgB;;;;;CAMtB,AAAO,OAAO,QAAgB,OAAqB;EAClD,MAAM,gBAAgB,KAAK,IAAI,KAAK,OAAO,OAAO;AAClD,OAAK,WAAW,gBAAgB,SAAS,IAAI,iBAAiB,KAAK;AACnE,OAAK,iBAAiB;;;;;;;;CASvB,AAAO,cAAsB;EAC5B,MAAM,aAAa,IAAI,KAAK,IAAI,KAAK,OAAO,KAAK,cAAc;AAC/D,SAAO,KAAK,WAAW;;;;;CAMxB,AAAO,mBAA2B;AACjC,SAAO,KAAK;;;;;;;;;;;;AChCd,IAAa,gBAAb,MAA0D;CAQzD,AAAO,YAAY,SAA+B;oBAJrB;AAK5B,OAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,OAAK,cAAc,QAAQ,eAAe;AAC1C,OAAK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AEzC,IAAIC,KAAaC;AAEjB,QAAM,QAAQ,gBAAgB,KAAK,QAAQ,KAAK,QAAQ,SAAS,GAAG;AAEpE,OAAK,MAAM,UAAU,KAAK,SAAS;AAClC,SAAM,QAAQ,gBAAgB,OAAO,IAAI,IAAI,SAAS;AACtD,WAAQ,QAAQ,OAAO,IAAI,SAAS;;AAGrC,SAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svta/cml-throughput",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Throughput estimation functionality",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -51,6 +51,6 @@
51
51
  }
52
52
  },
53
53
  "peerDependencies": {
54
- "@svta/cml-utils": "0.20.0"
54
+ "@svta/cml-utils": "*"
55
55
  }
56
56
  }