-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
clientSideMetrics.ts
32 lines (25 loc) · 1006 Bytes
/
clientSideMetrics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export class ClientSideMetrics {
constructor(public readonly requestCharge: number) {}
/**
* Adds one or more ClientSideMetrics to a copy of this instance and returns the result.
*/
public add(...clientSideMetricsArray: ClientSideMetrics[]) {
let requestCharge = this.requestCharge;
for (const clientSideMetrics of clientSideMetricsArray) {
if (clientSideMetrics == null) {
throw new Error("clientSideMetrics has null or undefined item(s)");
}
requestCharge += clientSideMetrics.requestCharge;
}
return new ClientSideMetrics(requestCharge);
}
public static readonly zero = new ClientSideMetrics(0);
public static createFromArray(...clientSideMetricsArray: ClientSideMetrics[]) {
if (clientSideMetricsArray == null) {
throw new Error("clientSideMetricsArray is null or undefined item(s)");
}
return this.zero.add(...clientSideMetricsArray);
}
}