@nsshunt/stsobservability 1.0.147 → 1.0.148

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.
package/dist/index.mjs CHANGED
@@ -1,2206 +1,1758 @@
1
1
  import _cloneDeep from "lodash.clonedeep";
2
2
  import isNode from "detect-node";
3
- var Gauge = /* @__PURE__ */ ((Gauge2) => {
4
- Gauge2["ACTIVE_REQUEST_GAUGE"] = "a";
5
- Gauge2["AUTHENTICATION_COUNT_GAUGE"] = "b";
6
- Gauge2["AUTHENTICATION_ERROR_COUNT_GAUGE"] = "aa";
7
- Gauge2["AUTHENTICATION_RETRY_COUNT_GAUGE"] = "ab";
8
- Gauge2["CONNECTION_POOL_IDLE_GAUGE"] = "c";
9
- Gauge2["CONNECTION_POOL_TOTAL_GAUGE"] = "d";
10
- Gauge2["CONNECTION_POOL_WAITING_GAUGE"] = "e";
11
- Gauge2["CPU_LOAD_GAUGE"] = "f";
12
- Gauge2["CPU_SYSTEM_LOAD_GAUGE"] = "g";
13
- Gauge2["DURATION_GAUGE"] = "h";
14
- Gauge2["DURATION_HISTOGRAM_GAUGE"] = "i";
15
- Gauge2["ERROR_COUNT_GAUGE"] = "j";
16
- Gauge2["LATENCY_GAUGE"] = "k";
17
- Gauge2["LATENCY_HISTOGRAM_GAUGE"] = "l";
18
- Gauge2["LOGGER"] = "m";
19
- Gauge2["LOGGER_COPY"] = "n";
20
- Gauge2["NETWORK_RX_GAUGE"] = "o";
21
- Gauge2["NETWORK_TX_GAUGE"] = "p";
22
- Gauge2["REQUEST_COUNT_GAUGE"] = "q";
23
- Gauge2["RETRY_COUNT_GAUGE"] = "r";
24
- Gauge2["TIMER_GAUGE"] = "s";
25
- Gauge2["VELOCITY_GAUGE"] = "t";
26
- Gauge2["CONNECTION_COUNT_GAUGE"] = "u";
27
- Gauge2["OBJECT_GAUGE"] = "v";
28
- Gauge2["PAYLOAD_SIZE"] = "w";
29
- Gauge2["CORE_COUNT_GAUGE"] = "x";
30
- Gauge2["CHILD_COUNT"] = "y";
31
- Gauge2["UNKNOWN"] = "z";
32
- return Gauge2;
33
- })(Gauge || {});
34
- var GaugeTypes = /* @__PURE__ */ ((GaugeTypes2) => {
35
- GaugeTypes2["GAUGE_TYPE"] = "_";
36
- GaugeTypes2["INSTRUMENT_GAUGE"] = "a";
37
- GaugeTypes2["INSTRUMENT_VELOCITY"] = "b";
38
- GaugeTypes2["INSTRUMENT_HISTOGRAM"] = "c";
39
- GaugeTypes2["INSTRUMENT_LOG"] = "d";
40
- GaugeTypes2["INSTRUMENT_TIMER"] = "e";
41
- GaugeTypes2["INSTRUMENT_OBJECT"] = "f";
42
- return GaugeTypes2;
43
- })(GaugeTypes || {});
44
- class InstrumentBaseOptions {
45
- fixedSize;
46
- padLength;
47
- label;
48
- }
49
- class InstrumentBaseTelemetry {
50
- }
51
- class InstrumentBase {
52
- #label = "";
53
- #options = null;
54
- #data = {};
55
- // Use for copy objects only.
56
- //protected _data: Record<string, any> = { };
57
- constructor(options = {}) {
58
- if (typeof options === "string" || options instanceof String) {
59
- throw new Error("Instrument parameter must be an options object.");
60
- }
61
- this.#options = options;
62
- if (options.label) {
63
- this.#label = options.label;
64
- } else {
65
- this.#label = "InstrumentGauge";
66
- }
67
- }
68
- [GaugeTypes.GAUGE_TYPE] = GaugeTypes.INSTRUMENT_OBJECT;
69
- // Default Gauge type
70
- val;
71
- WithLabel(label) {
72
- this.label = label;
73
- return this;
74
- }
75
- DefineCopyProperties(propertyNames) {
76
- propertyNames.forEach((propertyName) => {
77
- Object.defineProperty(this, propertyName, {
78
- enumerable: true,
79
- get: () => this.#data[propertyName],
80
- set: (value) => {
81
- if (value === void 0) {
82
- return;
83
- }
84
- this.#data[propertyName] = value;
85
- }
86
- });
87
- });
88
- }
89
- GetNumber(val) {
90
- if (Number.isInteger(val)) {
91
- return val;
92
- } else {
93
- return Math.round((val + Number.EPSILON) * 100) / 100;
94
- }
95
- }
96
- get options() {
97
- return this.#options;
98
- }
99
- set options(optionsValue) {
100
- this.#options = optionsValue;
101
- }
102
- get label() {
103
- return this.#label;
104
- }
105
- set label(labelValue) {
106
- this.#label = labelValue;
107
- }
108
- StopTimer() {
109
- }
110
- ProcessTelemetry(telemetry) {
111
- throw new Error(`Must override in extended class: [ProcessTelemetry]: [${telemetry}].`);
112
- }
113
- /*
114
- toJSON()
115
- {
116
- return this._serialValue;
117
- }
118
- */
119
- /*
120
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
121
- [Symbol.iterator]() {
122
- // Use a new index for each iterator. This makes multiple
123
- // iterations over the iterable safe for non-trivial cases,
124
- // such as use of break or nested looping over the same iterable.
125
- let index = 0;
126
-
127
- return {
128
- next: () => {
129
- if (index < 1) {
130
- return {value: this.GetFormatted(), done: false}
131
- } else {
132
- return {done: true}
133
- }
134
- }
135
- }
136
- }
137
- */
138
- }
139
- class InstrumentVelocityOptions extends InstrumentBaseOptions {
140
- interval;
141
- valStackMaxLength;
142
- maxAverageValStack;
143
- maxAverageIterations;
144
- fromJSON;
145
- initValue;
146
- autoComputeVelocity;
147
- velocityTimeDiff;
148
- vaTimeDiff;
149
- autoComputeVelocityTimeout;
150
- }
151
- class InstrumentVelocityTelemetry extends InstrumentBaseTelemetry {
152
- val;
153
- Inc;
154
- }
155
- class InstrumentVelocity extends InstrumentBase {
156
- // eslint-disable-next-line @/no-unused-private-class-members
157
- #val = 0;
158
- #interval = null;
159
- #timeoutComputeVelocity = null;
160
- // eslint-disable-next-line @/no-unused-private-class-members
161
- #lastVelocity = 0;
162
- #delta = 0;
163
- #maxVelocity = 0;
164
- #timerInterval = 0;
165
- #copy = false;
166
- #velocity = 0;
167
- #velocityVal = 0;
168
- #valStack = [];
169
- #averageValStack = [];
170
- #maxAverageValStack = 0;
171
- #maxAverageIterations = 0;
172
- // eslint-disable-next-line @/no-unused-private-class-members
173
- #valStackMaxLength = 0;
174
- #valStackAverage = 0;
175
- #timeStamp = 0;
176
- #maxTimeDiff = 0;
177
- #vaTimeDiff = 0;
178
- #velocityTimeDiff = 0;
179
- #autoComputeVelocity = false;
180
- #autoComputeVelocityTimeout = 0;
181
- // 50ms to auto computer after an update when not in auto compute mode.
182
- #countDiff = 0;
183
- #timeDiff = 0;
184
- #deltaCountDiff = 0;
185
- #deltaTimeDif = 0;
186
- #minTimeForReporting = 0;
187
- #averageVelocity = [];
188
- // timeWindow = Number of intervals to use as the sliding time window same size. Uses average value within the time window. Larger window produces a smooth (more laggy) curve. Shorter time
189
- // window may be "spikey" depending on the volatility of the data being recorded.
190
- constructor(options = {}) {
191
- super(options);
192
- if (typeof options.label === "undefined") {
193
- this.label = "InstrumentVelocity";
194
- } else {
195
- this.label = options.label;
196
- }
197
- if (typeof options.interval === "undefined") {
198
- this.#timerInterval = 1e3;
199
- } else {
200
- this.#timerInterval = options.interval;
201
- }
202
- if (typeof options.valStackMaxLength === "undefined") {
203
- this.#valStackMaxLength = 100;
204
- } else {
205
- this.#valStackMaxLength = options.valStackMaxLength;
206
- }
207
- if (typeof options.fromJSON === "undefined") {
208
- this.#copy = false;
209
- } else {
210
- this.#copy = true;
211
- }
212
- if (typeof options.autoComputeVelocity === "undefined") {
213
- this.#autoComputeVelocity = false;
214
- } else {
215
- this.#autoComputeVelocity = options.autoComputeVelocity;
216
- }
217
- if (typeof options.maxAverageValStack === "undefined") {
218
- this.#maxAverageValStack = 5;
219
- } else {
220
- this.#maxAverageValStack = options.maxAverageValStack;
221
- }
222
- if (typeof options.maxAverageIterations === "undefined") {
223
- this.#maxAverageIterations = 3;
224
- } else {
225
- this.#maxAverageIterations = options.maxAverageIterations;
226
- }
227
- if (typeof options.velocityTimeDiff === "undefined") {
228
- this.#velocityTimeDiff = 5e3;
229
- } else {
230
- this.#velocityTimeDiff = options.velocityTimeDiff;
231
- }
232
- if (typeof options.vaTimeDiff === "undefined") {
233
- this.#vaTimeDiff = 1e4;
234
- } else {
235
- this.#vaTimeDiff = options.vaTimeDiff;
236
- }
237
- if (typeof options.autoComputeVelocityTimeout === "undefined") {
238
- this.#autoComputeVelocityTimeout = 50;
239
- } else {
240
- this.#autoComputeVelocityTimeout = options.autoComputeVelocityTimeout;
241
- }
242
- this.#maxTimeDiff = this.#vaTimeDiff * 2;
243
- this.#minTimeForReporting = this.#vaTimeDiff + 2e3;
244
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
245
- enumerable: true,
246
- get: () => GaugeTypes.INSTRUMENT_VELOCITY
247
- });
248
- if (this.#copy) {
249
- this.DefineCopyProperties([
250
- "val",
251
- "maxVelocity",
252
- "delta",
253
- "velocity",
254
- "va",
255
- "timeStamp",
256
- "deltaTimeDif",
257
- "deltaCountDiff",
258
- "timeDiff",
259
- "countDiff",
260
- "averageVelocity"
261
- ]);
262
- } else {
263
- Object.defineProperty(this, "val", {
264
- enumerable: true,
265
- get: () => this.#GetVal(),
266
- set: (value) => {
267
- this.#SetVal(value);
268
- }
269
- });
270
- Object.defineProperty(this, "maxVelocity", {
271
- enumerable: true,
272
- get: () => this.#GetMaxVelocity()
273
- });
274
- Object.defineProperty(this, "delta", {
275
- enumerable: true,
276
- get: () => this.#GetDelta()
277
- });
278
- Object.defineProperty(this, "velocity", {
279
- enumerable: true,
280
- get: () => this.#GetVelocity()
281
- });
282
- Object.defineProperty(this, "va", {
283
- enumerable: true,
284
- get: () => this.#GetVelocityStackAverage()
285
- });
286
- Object.defineProperty(this, "timeStamp", {
287
- enumerable: true,
288
- get: () => this.#GetTimeStamp()
289
- });
290
- Object.defineProperty(this, "countDiff", {
291
- enumerable: true,
292
- get: () => this.#GetCountDiff()
293
- });
294
- Object.defineProperty(this, "timeDiff", {
295
- enumerable: true,
296
- get: () => this.#GetTimeDiff()
297
- });
298
- Object.defineProperty(this, "deltaCountDiff", {
299
- enumerable: true,
300
- get: () => this.#GetDeltaCountDiff()
301
- });
302
- Object.defineProperty(this, "deltaTimeDif", {
303
- enumerable: true,
304
- get: () => this.#GetDeltaTimeDif()
305
- });
306
- Object.defineProperty(this, "averageVelocity", {
307
- enumerable: true,
308
- get: () => this.#GetAverageVelocity()
309
- });
310
- if (this.#timerInterval > 0 && this.#autoComputeVelocity === false) {
311
- this._StartTimer();
312
- }
313
- }
314
- if (typeof options.initValue !== "undefined") {
315
- this.val = options.initValue;
316
- }
317
- if (typeof options.fromJSON !== "undefined") {
318
- const result = _cloneDeep(options.fromJSON);
319
- this.val = result.val;
320
- this.velocity = result.velocity;
321
- this.maxVelocity = result.maxVelocity;
322
- this.delta = result.delta;
323
- this.va = result.va;
324
- this.timeStamp = result.timeStamp;
325
- this.countDiff = result.countDiff;
326
- this.timeDiff = result.timeDiff;
327
- this.deltaCountDiff = result.deltaCountDiff;
328
- this.deltaTimeDif = result.deltaTimeDif;
329
- this.averageVelocity = _cloneDeep(result.averageVelocity);
330
- }
331
- }
332
- maxVelocity = 0;
333
- delta = 0;
334
- velocity = 0;
335
- va = 0;
336
- timeStamp = 0;
337
- countDiff = 0;
338
- timeDiff = 0;
339
- deltaCountDiff = 0;
340
- deltaTimeDif = 0;
341
- averageVelocity = [];
342
- val = 0;
343
- WithValStackMaxLength(valStackMaxLength) {
344
- this.#valStackMaxLength = valStackMaxLength;
345
- this.#valStack = [];
346
- return this;
347
- }
348
- _StartTimer() {
349
- this.#interval = setInterval(() => {
350
- this.#ComputeVelocity();
351
- let pushVal = this.#velocity;
352
- for (let i = 0; i < this.#maxAverageIterations; i++) {
353
- if (!this.#averageValStack[i]) {
354
- this.#averageValStack[i] = [];
355
- }
356
- this.#averageValStack[i].push(pushVal);
357
- if (this.#averageValStack[i].length > this.#maxAverageValStack) {
358
- this.#averageValStack[i].shift();
359
- }
360
- pushVal = this.#averageValStack[i].reduce((prev, current) => prev + current) / this.#averageValStack[i].length;
361
- this.#averageVelocity[i] = pushVal;
362
- }
363
- }, this.#timerInterval);
364
- if (isNode) {
365
- this.#interval.unref();
366
- }
367
- }
368
- #ComputeVelocityByTimeDiff(checkTimeDiff, checkDeltaTimeDiff) {
369
- let val = 0;
370
- let deltaVal = 0;
371
- let countDiff = 0;
372
- let timeDiff = 0;
373
- let deltaCountDiff = 0;
374
- let deltaTimeDiff = 0;
375
- if (this.#valStack.length > 1 && this.#valStack[this.#valStack.length - 1].timeStamp - this.#valStack[0].timeStamp > this.#minTimeForReporting) {
376
- const dp = this.#valStack[this.#valStack.length - 1];
377
- let timeDiffPos = -1;
378
- let deltaDiffPos = -1;
379
- for (let i = this.#valStack.length - 2; i > -1; i--) {
380
- if (timeDiffPos === -1 && this.#timeStamp - this.#valStack[i].timeStamp >= checkTimeDiff) {
381
- timeDiffPos = i;
382
- if (checkDeltaTimeDiff === 0) {
383
- break;
384
- }
385
- }
386
- if (deltaDiffPos === -1 && this.#timeStamp - this.#valStack[i].timeStamp >= checkDeltaTimeDiff) {
387
- deltaDiffPos = i;
388
- }
389
- if (timeDiffPos !== -1 && deltaDiffPos !== -1) {
390
- break;
391
- }
392
- }
393
- if (timeDiffPos > -1) {
394
- countDiff = dp.count - this.#valStack[timeDiffPos].count;
395
- if (countDiff > 0) {
396
- timeDiff = dp.timeStamp - this.#valStack[timeDiffPos].timeStamp;
397
- if (timeDiff > 0) {
398
- val = 1e3 / timeDiff * countDiff;
399
- } else {
400
- val = 0;
401
- }
402
- } else {
403
- val = 0;
404
- }
405
- } else {
406
- val = 0;
407
- }
408
- if (deltaDiffPos > -1) {
409
- deltaCountDiff = this.#valStack[timeDiffPos].count - this.#valStack[deltaDiffPos].count;
410
- if (deltaCountDiff > 0) {
411
- deltaTimeDiff = this.#valStack[timeDiffPos].timeStamp - this.#valStack[deltaDiffPos].timeStamp;
412
- if (deltaTimeDiff > 0) {
413
- deltaVal = 1e3 / deltaTimeDiff * deltaTimeDiff;
414
- } else {
415
- deltaVal = 0;
416
- }
417
- } else {
418
- deltaVal = 0;
419
- }
420
- } else {
421
- deltaVal = 0;
422
- }
423
- }
424
- return {
425
- val,
426
- countDiff,
427
- timeDiff,
428
- deltaVal,
429
- deltaCountDiff,
430
- deltaTimeDiff
431
- };
432
- }
433
- #ComputeVelocity() {
434
- const dp = {
435
- timeStamp: performance.now(),
436
- count: this.#velocityVal
437
- };
438
- this.#valStack.push(dp);
439
- this.#timeStamp = dp.timeStamp;
440
- while (this.#valStack.length > 0 && this.#timeStamp - this.#valStack[0].timeStamp > this.#maxTimeDiff) {
441
- this.#valStack.shift();
442
- }
443
- const valStackAverageDataPoint = this.#ComputeVelocityByTimeDiff(this.#vaTimeDiff, 0);
444
- this.#valStackAverage = valStackAverageDataPoint.val;
445
- const velocityDataPoint = this.#ComputeVelocityByTimeDiff(this.#velocityTimeDiff, this.#velocityTimeDiff * 2);
446
- this.#velocity = velocityDataPoint.val;
447
- this.#delta = velocityDataPoint.val - velocityDataPoint.deltaVal;
448
- this.#countDiff = velocityDataPoint.countDiff;
449
- this.#timeDiff = velocityDataPoint.timeDiff;
450
- this.#deltaCountDiff = velocityDataPoint.deltaCountDiff;
451
- this.#deltaTimeDif = velocityDataPoint.deltaTimeDiff;
452
- this.#lastVelocity = this.#velocity;
453
- if (this.#velocity > this.#maxVelocity) {
454
- this.#maxVelocity = this.#velocity;
455
- }
456
- }
457
- #SetupAutoComputeVelocity() {
458
- if (this.#timeoutComputeVelocity) {
459
- clearTimeout(this.#timeoutComputeVelocity);
460
- }
461
- this.#timeoutComputeVelocity = setTimeout(() => {
462
- this.#ComputeVelocity();
463
- }, this.#autoComputeVelocityTimeout);
464
- }
465
- #GetVelocityStackAverage() {
466
- return this.GetNumber(this.#valStackAverage);
467
- }
468
- Inc(incVal = 1) {
469
- this.#velocityVal += incVal;
470
- if (this.#autoComputeVelocity) {
471
- this.#ComputeVelocity();
472
- } else {
473
- this.#SetupAutoComputeVelocity();
474
- }
475
- }
476
- #GetVal() {
477
- return this.GetNumber(this.#velocityVal);
478
- }
479
- #SetVal(updatedValue) {
480
- this.#velocityVal = updatedValue;
481
- if (this.#autoComputeVelocity) {
482
- this.#ComputeVelocity();
483
- } else {
484
- this.#SetupAutoComputeVelocity();
485
- }
486
- }
487
- #GetVelocity() {
488
- return this.GetNumber(this.#velocity);
489
- }
490
- #GetMaxVelocity() {
491
- return this.GetNumber(this.#maxVelocity);
492
- }
493
- #GetDelta() {
494
- return this.GetNumber(this.#delta);
495
- }
496
- #GetTimeStamp() {
497
- return this.GetNumber(this.#timeStamp);
498
- }
499
- #GetCountDiff() {
500
- return this.GetNumber(this.#countDiff);
501
- }
502
- #GetTimeDiff() {
503
- return this.GetNumber(this.#timeDiff);
504
- }
505
- #GetDeltaCountDiff() {
506
- return this.GetNumber(this.#deltaCountDiff);
507
- }
508
- #GetDeltaTimeDif() {
509
- return this.GetNumber(this.#deltaTimeDif);
510
- }
511
- #GetAverageVelocity() {
512
- return this.#averageVelocity;
513
- }
514
- StopTimer() {
515
- if (this.#interval !== null) {
516
- clearTimeout(this.#interval);
517
- this.#interval = null;
518
- }
519
- }
520
- ProcessTelemetry(telemetry) {
521
- if (telemetry.Inc !== void 0) {
522
- this.Inc(telemetry.Inc);
523
- }
524
- if (telemetry.val !== void 0) {
525
- this.val = telemetry.val;
526
- }
527
- }
528
- }
529
- var HistogramDataElementPos = /* @__PURE__ */ ((HistogramDataElementPos2) => {
530
- HistogramDataElementPos2[HistogramDataElementPos2["val"] = 0] = "val";
531
- HistogramDataElementPos2[HistogramDataElementPos2["label"] = 1] = "label";
532
- HistogramDataElementPos2[HistogramDataElementPos2["breakPoint"] = 2] = "breakPoint";
533
- return HistogramDataElementPos2;
534
- })(HistogramDataElementPos || {});
535
- class InstrumentHistogramOptions extends InstrumentBaseOptions {
536
- histogramData;
537
- initValue;
538
- fromJSON;
539
- }
540
- class InstrumentHistogramTelemetry extends InstrumentBaseTelemetry {
541
- val;
542
- }
543
- class InstrumentHistogram extends InstrumentBase {
544
- #histogramData = [];
545
- #val = 0;
546
- #copy = false;
547
- constructor(options = {}) {
548
- super(options);
549
- if (typeof options.label === "undefined") {
550
- this.label = "InstrumentHistogram";
551
- } else {
552
- this.label = options.label;
553
- }
554
- let histogramData = null;
555
- if (typeof options.histogramData === "undefined") {
556
- histogramData = null;
557
- } else {
558
- histogramData = options.histogramData;
559
- }
560
- if (typeof options.fromJSON === "undefined") {
561
- this.#copy = false;
562
- } else {
563
- this.#copy = true;
564
- }
565
- if (histogramData === null) {
566
- this.#histogramData = [
567
- [0, "10", 10],
568
- [0, "20", 20],
569
- [0, "50", 50],
570
- [0, "100", 100],
571
- [0, "1000", 1e3],
572
- [0, "5000", 5e3],
573
- [0, "EE", 0]
574
- ];
575
- } else if (Array.isArray(histogramData)) {
576
- this.#histogramData = [];
577
- for (let i = 0; i < histogramData.length; i++) {
578
- this.#histogramData.push([0, "" + histogramData[i], parseFloat(histogramData[i].toString())]);
579
- }
580
- this.#histogramData.push([0, "EE", 0]);
581
- } else {
582
- throw new Error(`Passed [${histogramData}] must be an array.`);
583
- }
584
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
585
- enumerable: true,
586
- get: () => GaugeTypes.INSTRUMENT_HISTOGRAM
587
- });
588
- if (this.#copy) {
589
- this.DefineCopyProperties([
590
- "val",
591
- "hist"
592
- ]);
593
- } else {
594
- Object.defineProperty(this, "val", {
595
- enumerable: true,
596
- get: () => this.#GetVal(),
597
- set: (value) => {
598
- this.#SetVal(value);
599
- }
600
- });
601
- Object.defineProperty(this, "hist", {
602
- enumerable: true,
603
- get: () => this.#GetHistogramData(),
604
- set: (value) => {
605
- this.#SetHistogramData(value);
606
- }
607
- });
608
- }
609
- if (typeof options.initValue !== "undefined") {
610
- this.#val = options.initValue;
611
- }
612
- if (typeof options.fromJSON !== "undefined") {
613
- const result = _cloneDeep(options.fromJSON);
614
- this.#val = result.val;
615
- this.hist = result.hist;
616
- }
617
- }
618
- hist = [];
619
- val = 0;
620
- WithInitVal(initVal) {
621
- this.#val = initVal;
622
- return this;
623
- }
624
- ResetHistogramData() {
625
- for (let i = 0; i < this.hist.length; i++) {
626
- this.hist[i][0] = 0;
627
- }
628
- }
629
- AddObservation(updateValue) {
630
- if (this.#copy) {
631
- throw new Error("Cannot add observations from the copy version of this class.");
632
- }
633
- let i = 0;
634
- for (; i < this.#histogramData.length - 1; i++) {
635
- if (updateValue <= this.#histogramData[i][
636
- 2
637
- /* breakPoint */
638
- ]) {
639
- this.#histogramData[i][
640
- 0
641
- /* val */
642
- ]++;
643
- return;
644
- }
645
- }
646
- this.#histogramData[i][
647
- 0
648
- /* val */
649
- ]++;
650
- }
651
- #GetVal() {
652
- return this.GetNumber(this.#val);
653
- }
654
- #SetVal(value) {
655
- this.#val = value;
656
- this.AddObservation(value);
657
- }
658
- get formattedHistogramData() {
659
- let retVal = "";
660
- let sep = "";
661
- for (let i = 0; i < this.hist.length; i++) {
662
- retVal += sep + "[" + (this.hist[i][
663
- 0
664
- /* val */
665
- ] + "/" + this.hist[i][
666
- 1
667
- /* label */
668
- ]).padStart(10, " ") + "]";
669
- sep = " ";
670
- }
671
- return retVal;
672
- }
673
- #GetHistogramData() {
674
- return this.#histogramData;
675
- }
676
- #SetHistogramData(value) {
677
- this.#histogramData = value;
678
- }
679
- static AddHistogramDataEx(histoA, histoB) {
680
- if (histoA === null) {
681
- return _cloneDeep(histoB);
682
- }
683
- const result = _cloneDeep(histoA);
684
- const histogramAData = result.hist;
685
- const histogramBData = histoB.hist;
686
- if (histogramAData.length !== histogramBData.length) {
687
- throw new Error("Invalid HistogramData. HistogramData bucket lengths must be the same.");
688
- }
689
- for (let i = 0; i < histogramAData.length; i++) {
690
- if (histogramAData[i][
691
- 2
692
- /* breakPoint */
693
- ] !== histogramBData[i][
694
- 2
695
- /* breakPoint */
696
- ]) {
697
- throw new Error(`Invalid HistogramData. HistogramData bucket break-point at index [${i}] must be the same.`);
698
- }
699
- if (histogramAData[i][
700
- 1
701
- /* label */
702
- ] !== histogramBData[i][
703
- 1
704
- /* label */
705
- ]) {
706
- throw new Error(`Invalid HistogramData. HistogramData bucket label at index [${i}] must be the same.`);
707
- }
708
- histogramAData[i][
709
- 0
710
- /* val */
711
- ] += histogramBData[i][
712
- 0
713
- /* val */
714
- ];
715
- }
716
- return result;
717
- }
718
- /**
719
- * Adds a value object (from GetFormatted()) to this instance.
720
- * @param {*} value
721
- */
722
- AddHistogramData(histogramData) {
723
- if (histogramData === null) {
724
- return;
725
- }
726
- if (this.hist.length !== histogramData.hist.length) {
727
- throw new Error("Invalid HistogramData. HistogramData bucket lengths must be the same.");
728
- }
729
- for (let i = 0; i < histogramData.hist.length; i++) {
730
- if (this.hist[i][
731
- 2
732
- /* breakPoint */
733
- ] !== histogramData.hist[i][
734
- 2
735
- /* breakPoint */
736
- ]) {
737
- throw new Error(`Invalid HistogramData. HistogramData bucket break-point at index [${i}] must be the same.`);
738
- }
739
- if (this.hist[i][
740
- 1
741
- /* label */
742
- ] !== histogramData.hist[i][
743
- 1
744
- /* label */
745
- ]) {
746
- throw new Error(`Invalid HistogramData. HistogramData bucket label at index [${i}] must be the same.`);
747
- }
748
- this.hist[i][
749
- 0
750
- /* val */
751
- ] += histogramData.hist[i][
752
- 0
753
- /* val */
754
- ];
755
- }
756
- }
757
- ProcessTelemetry(telemetry) {
758
- if (telemetry.val !== void 0) {
759
- this.val = telemetry.val;
760
- }
761
- }
762
- }
763
- class InstrumentLogOptions extends InstrumentBaseOptions {
764
- maxSize;
765
- useLatestMessages;
766
- consoleLogging;
767
- instrumentLogging;
768
- winstonLogging;
769
- fromJSON;
770
- initValue;
771
- logger;
772
- }
773
- class InstrumentLogTelemetry extends InstrumentBaseTelemetry {
774
- Append;
775
- LogMessage;
776
- val;
777
- ResetLog;
778
- }
779
- class InstrumentLog extends InstrumentBase {
780
- #messages = [];
781
- #readPos = 0;
782
- #maxSize = 200;
783
- // Max length of cached log messages
784
- #copy = false;
785
- #useLatestMessages = false;
786
- #consoleLogging = false;
787
- #instrumentLogging = true;
788
- #winstonLogging = false;
789
- #stsLogger;
790
- constructor(options = {}) {
791
- super(options);
792
- if (typeof options.label === "undefined") {
793
- this.label = "InstrumentLog";
794
- } else {
795
- this.label = options.label;
796
- }
797
- if (typeof options.maxSize === "undefined") {
798
- this.#maxSize = 200;
799
- } else {
800
- this.#maxSize = options.maxSize;
801
- }
802
- if (typeof options.fromJSON === "undefined") {
803
- this.#copy = false;
804
- } else {
805
- this.#copy = true;
806
- }
807
- if (typeof options.useLatestMessages === "undefined") {
808
- this.#useLatestMessages = false;
809
- } else {
810
- this.#useLatestMessages = options.useLatestMessages;
811
- }
812
- if (typeof options.consoleLogging === "undefined") {
813
- this.#consoleLogging = false;
814
- } else {
815
- this.#consoleLogging = options.consoleLogging;
816
- }
817
- if (typeof options.instrumentLogging === "undefined") {
818
- this.#instrumentLogging = true;
819
- } else {
820
- this.#instrumentLogging = options.instrumentLogging;
821
- }
822
- if (typeof options.winstonLogging === "undefined") {
823
- this.#winstonLogging = false;
824
- } else {
825
- this.#winstonLogging = options.winstonLogging;
826
- }
827
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
828
- enumerable: true,
829
- get: () => GaugeTypes.INSTRUMENT_LOG
830
- });
831
- if (this.#copy) {
832
- this.DefineCopyProperties([
833
- "val"
834
- ]);
835
- } else {
836
- Object.defineProperty(this, "val", {
837
- enumerable: true,
838
- get: () => _cloneDeep(this.#GetVal()),
839
- set: (value) => {
840
- this.#SetVal(value);
841
- }
842
- });
843
- }
844
- if (typeof options.initValue !== "undefined") {
845
- this.val = options.initValue;
846
- }
847
- if (typeof options.fromJSON !== "undefined") {
848
- const result = _cloneDeep(options.fromJSON);
849
- this.val = result.val;
850
- }
851
- }
852
- val = [];
853
- WithMaxSize(maxSize) {
854
- this.#maxSize = maxSize;
855
- return this;
856
- }
857
- WithUseLatestMessages(useLatestMessages) {
858
- this.#useLatestMessages = useLatestMessages;
859
- return this;
860
- }
861
- WithConsoleLogging(consoleLogging) {
862
- this.#consoleLogging = consoleLogging;
863
- return this;
864
- }
865
- WithInstrumentLogging(instrumentLogging) {
866
- this.#instrumentLogging = instrumentLogging;
867
- return this;
868
- }
869
- get MaxSize() {
870
- return this.#maxSize;
871
- }
872
- set MaxSize(maxSize) {
873
- this.#maxSize = maxSize;
874
- }
875
- #DumpToConsole() {
876
- const logReport = this.GetMessagesSinceLastRead();
877
- for (let i = 0; i < logReport.length; i++) {
878
- console.log(logReport[i]);
879
- }
880
- }
881
- get consoleLogging() {
882
- return this.#consoleLogging;
883
- }
884
- set consoleLogging(value) {
885
- this.#consoleLogging = value;
886
- if (value === true) {
887
- this.#DumpToConsole();
888
- }
889
- }
890
- get instrumentLogging() {
891
- return this.#instrumentLogging;
892
- }
893
- set instrumentLogging(value) {
894
- this.#instrumentLogging = value;
895
- }
896
- Append(messageArray) {
897
- for (let i = 0; i < messageArray.length; i++) {
898
- this.LogMessage(messageArray[i]);
899
- }
900
- }
901
- error(message) {
902
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.error(message);
903
- }
904
- warn(message) {
905
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.warn(message);
906
- }
907
- info(message) {
908
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.info(message);
909
- }
910
- http(message) {
911
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.http(message);
912
- }
913
- verbose(message) {
914
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.verbose(message);
915
- }
916
- debug(message) {
917
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.debug(message);
918
- }
919
- silly(message) {
920
- if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.silly(message);
921
- }
922
- LogMessage(message) {
923
- if (this.#copy) {
924
- throw new Error("Cannot add log messages from the copy version of this class.");
925
- }
926
- if (this.#consoleLogging === true) {
927
- console.log(message);
928
- }
929
- if (this.#instrumentLogging === false) {
930
- return;
931
- }
932
- this.#messages.push(message);
933
- if (this.#messages.length > this.#maxSize) {
934
- this.#messages.shift();
935
- this.#readPos = this.#readPos > 0 ? this.#readPos - 1 : 0;
936
- }
937
- }
938
- #GetVal() {
939
- if (this.#useLatestMessages) {
940
- return this.GetMessagesSinceLastRead();
941
- } else {
942
- return this.#messages;
943
- }
944
- }
945
- #SetVal(updatedValue) {
946
- this.#messages = updatedValue;
947
- this.#readPos = 0;
948
- }
949
- GetMessagesNoUpdate() {
950
- return this.#messages.slice(this.#readPos);
951
- }
952
- // This will return only those messages that have been added since the last read
953
- GetMessagesSinceLastRead() {
954
- const retVal = this.#messages.slice(this.#readPos);
955
- this.#readPos = this.#messages.length;
956
- return retVal;
957
- }
958
- ResetLog() {
959
- this.#messages = [];
960
- this.#readPos = 0;
961
- }
962
- ProcessTelemetry(telemetry) {
963
- if (telemetry.val !== void 0) {
964
- this.val = telemetry.val;
965
- }
966
- if (telemetry.Append !== void 0) {
967
- this.Append(telemetry.Append);
968
- }
969
- if (telemetry.LogMessage !== void 0) {
970
- this.LogMessage(telemetry.LogMessage);
971
- }
972
- if (telemetry.ResetLog !== void 0 && telemetry.ResetLog === true) {
973
- this.ResetLog();
974
- }
975
- }
976
- }
977
- class InstrumentTimerOptions extends InstrumentBaseOptions {
978
- fromJSON;
979
- initValue;
980
- }
981
- class InstrumentTimerTelemetry extends InstrumentBaseTelemetry {
982
- val;
983
- Pause;
984
- Resume;
985
- Reset;
986
- }
987
- class InstrumentTimerGauge extends InstrumentBase {
988
- #start = 0;
989
- #copy = false;
990
- #pauseVal = 0;
991
- constructor(options = {}) {
992
- super(options);
993
- if (typeof options.label === "undefined") {
994
- this.label = "InstrumentTimerGauge";
995
- } else {
996
- this.label = options.label;
997
- }
998
- if (typeof options.fromJSON === "undefined") {
999
- this.#copy = false;
1000
- } else {
1001
- this.#copy = true;
1002
- }
1003
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
1004
- enumerable: true,
1005
- get: () => GaugeTypes.INSTRUMENT_TIMER
1006
- });
1007
- if (this.#copy) {
1008
- this.DefineCopyProperties([
1009
- "val"
1010
- ]);
1011
- } else {
1012
- Object.defineProperty(this, "val", {
1013
- enumerable: true,
1014
- get: () => this.#GetVal(),
1015
- set: (value) => {
1016
- this.#SetVal(value);
1017
- }
1018
- });
1019
- }
1020
- if (typeof options.initValue !== "undefined") {
1021
- this.val = options.initValue;
1022
- }
1023
- if (typeof options.fromJSON !== "undefined") {
1024
- const result = _cloneDeep(options.fromJSON);
1025
- this.val = result.val;
1026
- }
1027
- this.Reset();
1028
- }
1029
- val = 0;
1030
- // Take a snap shot of the current elapsed time. The 'clock' will still keep running.
1031
- Pause() {
1032
- this.#pauseVal = this.val;
1033
- }
1034
- Resume() {
1035
- this.#pauseVal = 0;
1036
- }
1037
- Reset() {
1038
- this.#start = performance.now();
1039
- }
1040
- #GetVal() {
1041
- if (this.#pauseVal !== 0) {
1042
- return this.GetNumber(this.#pauseVal);
1043
- }
1044
- return this.GetNumber(performance.now() - this.#start);
1045
- }
1046
- #SetVal(updatedValue) {
1047
- this.#start = performance.now() - updatedValue;
1048
- }
1049
- get start() {
1050
- return this.#start;
1051
- }
1052
- /*
1053
- #convertMS(ms: number): string {
1054
- //let d, h, m, s;
1055
- let s = Math.floor(ms / 1000);
1056
- let m = Math.floor(s / 60);
1057
- s = s % 60;
1058
- let h = Math.floor(m / 60);
1059
- m = m % 60;
1060
- const d = Math.floor(h / 24);
1061
- h = h % 24;
1062
-
1063
- const pad: (n: number) => string = function(n: number) { return n < 10 ? '0' + n : n.toString(); };
1064
-
1065
- return (d + '.' + pad(h) + ':' + pad(m) + ':' + pad(s)).padStart(12);
1066
- }
1067
- */
1068
- ProcessTelemetry(telemetry) {
1069
- if (telemetry.val !== void 0) {
1070
- this.val = telemetry.val;
1071
- }
1072
- if (telemetry.Pause !== void 0 && telemetry.Pause === true) {
1073
- this.Pause();
1074
- }
1075
- if (telemetry.Resume !== void 0 && telemetry.Resume === true) {
1076
- this.Resume();
1077
- }
1078
- if (telemetry.Reset !== void 0 && telemetry.Reset === true) {
1079
- this.Reset();
1080
- }
1081
- }
1082
- }
1083
- function getDefaultExportFromCjs(x) {
1084
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
1085
- }
1086
- var timsort$1 = {};
1087
- var hasRequiredTimsort$1;
1088
- function requireTimsort$1() {
1089
- if (hasRequiredTimsort$1) return timsort$1;
1090
- hasRequiredTimsort$1 = 1;
1091
- (function(exports$1) {
1092
- (function(global, factory) {
1093
- {
1094
- factory(exports$1);
1095
- }
1096
- })(timsort$1, function(exports$12) {
1097
- exports$12.__esModule = true;
1098
- exports$12.sort = sort;
1099
- function _classCallCheck(instance, Constructor) {
1100
- if (!(instance instanceof Constructor)) {
1101
- throw new TypeError("Cannot call a class as a function");
1102
- }
1103
- }
1104
- var DEFAULT_MIN_MERGE = 32;
1105
- var DEFAULT_MIN_GALLOPING = 7;
1106
- var DEFAULT_TMP_STORAGE_LENGTH = 256;
1107
- var POWERS_OF_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9];
1108
- function log10(x) {
1109
- if (x < 1e5) {
1110
- if (x < 100) {
1111
- return x < 10 ? 0 : 1;
1112
- }
1113
- if (x < 1e4) {
1114
- return x < 1e3 ? 2 : 3;
1115
- }
1116
- return 4;
1117
- }
1118
- if (x < 1e7) {
1119
- return x < 1e6 ? 5 : 6;
1120
- }
1121
- if (x < 1e9) {
1122
- return x < 1e8 ? 7 : 8;
1123
- }
1124
- return 9;
1125
- }
1126
- function alphabeticalCompare(a, b) {
1127
- if (a === b) {
1128
- return 0;
1129
- }
1130
- if (~~a === a && ~~b === b) {
1131
- if (a === 0 || b === 0) {
1132
- return a < b ? -1 : 1;
1133
- }
1134
- if (a < 0 || b < 0) {
1135
- if (b >= 0) {
1136
- return -1;
1137
- }
1138
- if (a >= 0) {
1139
- return 1;
1140
- }
1141
- a = -a;
1142
- b = -b;
1143
- }
1144
- var al = log10(a);
1145
- var bl = log10(b);
1146
- var t = 0;
1147
- if (al < bl) {
1148
- a *= POWERS_OF_TEN[bl - al - 1];
1149
- b /= 10;
1150
- t = -1;
1151
- } else if (al > bl) {
1152
- b *= POWERS_OF_TEN[al - bl - 1];
1153
- a /= 10;
1154
- t = 1;
1155
- }
1156
- if (a === b) {
1157
- return t;
1158
- }
1159
- return a < b ? -1 : 1;
1160
- }
1161
- var aStr = String(a);
1162
- var bStr = String(b);
1163
- if (aStr === bStr) {
1164
- return 0;
1165
- }
1166
- return aStr < bStr ? -1 : 1;
1167
- }
1168
- function minRunLength(n) {
1169
- var r = 0;
1170
- while (n >= DEFAULT_MIN_MERGE) {
1171
- r |= n & 1;
1172
- n >>= 1;
1173
- }
1174
- return n + r;
1175
- }
1176
- function makeAscendingRun(array, lo, hi, compare) {
1177
- var runHi = lo + 1;
1178
- if (runHi === hi) {
1179
- return 1;
1180
- }
1181
- if (compare(array[runHi++], array[lo]) < 0) {
1182
- while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
1183
- runHi++;
1184
- }
1185
- reverseRun(array, lo, runHi);
1186
- } else {
1187
- while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
1188
- runHi++;
1189
- }
1190
- }
1191
- return runHi - lo;
1192
- }
1193
- function reverseRun(array, lo, hi) {
1194
- hi--;
1195
- while (lo < hi) {
1196
- var t = array[lo];
1197
- array[lo++] = array[hi];
1198
- array[hi--] = t;
1199
- }
1200
- }
1201
- function binaryInsertionSort(array, lo, hi, start, compare) {
1202
- if (start === lo) {
1203
- start++;
1204
- }
1205
- for (; start < hi; start++) {
1206
- var pivot = array[start];
1207
- var left = lo;
1208
- var right = start;
1209
- while (left < right) {
1210
- var mid = left + right >>> 1;
1211
- if (compare(pivot, array[mid]) < 0) {
1212
- right = mid;
1213
- } else {
1214
- left = mid + 1;
1215
- }
1216
- }
1217
- var n = start - left;
1218
- switch (n) {
1219
- case 3:
1220
- array[left + 3] = array[left + 2];
1221
- case 2:
1222
- array[left + 2] = array[left + 1];
1223
- case 1:
1224
- array[left + 1] = array[left];
1225
- break;
1226
- default:
1227
- while (n > 0) {
1228
- array[left + n] = array[left + n - 1];
1229
- n--;
1230
- }
1231
- }
1232
- array[left] = pivot;
1233
- }
1234
- }
1235
- function gallopLeft(value, array, start, length, hint, compare) {
1236
- var lastOffset = 0;
1237
- var maxOffset = 0;
1238
- var offset = 1;
1239
- if (compare(value, array[start + hint]) > 0) {
1240
- maxOffset = length - hint;
1241
- while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
1242
- lastOffset = offset;
1243
- offset = (offset << 1) + 1;
1244
- if (offset <= 0) {
1245
- offset = maxOffset;
1246
- }
1247
- }
1248
- if (offset > maxOffset) {
1249
- offset = maxOffset;
1250
- }
1251
- lastOffset += hint;
1252
- offset += hint;
1253
- } else {
1254
- maxOffset = hint + 1;
1255
- while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
1256
- lastOffset = offset;
1257
- offset = (offset << 1) + 1;
1258
- if (offset <= 0) {
1259
- offset = maxOffset;
1260
- }
1261
- }
1262
- if (offset > maxOffset) {
1263
- offset = maxOffset;
1264
- }
1265
- var tmp = lastOffset;
1266
- lastOffset = hint - offset;
1267
- offset = hint - tmp;
1268
- }
1269
- lastOffset++;
1270
- while (lastOffset < offset) {
1271
- var m = lastOffset + (offset - lastOffset >>> 1);
1272
- if (compare(value, array[start + m]) > 0) {
1273
- lastOffset = m + 1;
1274
- } else {
1275
- offset = m;
1276
- }
1277
- }
1278
- return offset;
1279
- }
1280
- function gallopRight(value, array, start, length, hint, compare) {
1281
- var lastOffset = 0;
1282
- var maxOffset = 0;
1283
- var offset = 1;
1284
- if (compare(value, array[start + hint]) < 0) {
1285
- maxOffset = hint + 1;
1286
- while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
1287
- lastOffset = offset;
1288
- offset = (offset << 1) + 1;
1289
- if (offset <= 0) {
1290
- offset = maxOffset;
1291
- }
1292
- }
1293
- if (offset > maxOffset) {
1294
- offset = maxOffset;
1295
- }
1296
- var tmp = lastOffset;
1297
- lastOffset = hint - offset;
1298
- offset = hint - tmp;
1299
- } else {
1300
- maxOffset = length - hint;
1301
- while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
1302
- lastOffset = offset;
1303
- offset = (offset << 1) + 1;
1304
- if (offset <= 0) {
1305
- offset = maxOffset;
1306
- }
1307
- }
1308
- if (offset > maxOffset) {
1309
- offset = maxOffset;
1310
- }
1311
- lastOffset += hint;
1312
- offset += hint;
1313
- }
1314
- lastOffset++;
1315
- while (lastOffset < offset) {
1316
- var m = lastOffset + (offset - lastOffset >>> 1);
1317
- if (compare(value, array[start + m]) < 0) {
1318
- offset = m;
1319
- } else {
1320
- lastOffset = m + 1;
1321
- }
1322
- }
1323
- return offset;
1324
- }
1325
- var TimSort = (function() {
1326
- function TimSort2(array, compare) {
1327
- _classCallCheck(this, TimSort2);
1328
- this.array = null;
1329
- this.compare = null;
1330
- this.minGallop = DEFAULT_MIN_GALLOPING;
1331
- this.length = 0;
1332
- this.tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;
1333
- this.stackLength = 0;
1334
- this.runStart = null;
1335
- this.runLength = null;
1336
- this.stackSize = 0;
1337
- this.array = array;
1338
- this.compare = compare;
1339
- this.length = array.length;
1340
- if (this.length < 2 * DEFAULT_TMP_STORAGE_LENGTH) {
1341
- this.tmpStorageLength = this.length >>> 1;
1342
- }
1343
- this.tmp = new Array(this.tmpStorageLength);
1344
- this.stackLength = this.length < 120 ? 5 : this.length < 1542 ? 10 : this.length < 119151 ? 19 : 40;
1345
- this.runStart = new Array(this.stackLength);
1346
- this.runLength = new Array(this.stackLength);
1347
- }
1348
- TimSort2.prototype.pushRun = function pushRun(runStart, runLength) {
1349
- this.runStart[this.stackSize] = runStart;
1350
- this.runLength[this.stackSize] = runLength;
1351
- this.stackSize += 1;
1352
- };
1353
- TimSort2.prototype.mergeRuns = function mergeRuns() {
1354
- while (this.stackSize > 1) {
1355
- var n = this.stackSize - 2;
1356
- if (n >= 1 && this.runLength[n - 1] <= this.runLength[n] + this.runLength[n + 1] || n >= 2 && this.runLength[n - 2] <= this.runLength[n] + this.runLength[n - 1]) {
1357
- if (this.runLength[n - 1] < this.runLength[n + 1]) {
1358
- n--;
1359
- }
1360
- } else if (this.runLength[n] > this.runLength[n + 1]) {
1361
- break;
1362
- }
1363
- this.mergeAt(n);
1364
- }
1365
- };
1366
- TimSort2.prototype.forceMergeRuns = function forceMergeRuns() {
1367
- while (this.stackSize > 1) {
1368
- var n = this.stackSize - 2;
1369
- if (n > 0 && this.runLength[n - 1] < this.runLength[n + 1]) {
1370
- n--;
1371
- }
1372
- this.mergeAt(n);
1373
- }
1374
- };
1375
- TimSort2.prototype.mergeAt = function mergeAt(i) {
1376
- var compare = this.compare;
1377
- var array = this.array;
1378
- var start1 = this.runStart[i];
1379
- var length1 = this.runLength[i];
1380
- var start2 = this.runStart[i + 1];
1381
- var length2 = this.runLength[i + 1];
1382
- this.runLength[i] = length1 + length2;
1383
- if (i === this.stackSize - 3) {
1384
- this.runStart[i + 1] = this.runStart[i + 2];
1385
- this.runLength[i + 1] = this.runLength[i + 2];
1386
- }
1387
- this.stackSize--;
1388
- var k = gallopRight(array[start2], array, start1, length1, 0, compare);
1389
- start1 += k;
1390
- length1 -= k;
1391
- if (length1 === 0) {
1392
- return;
1393
- }
1394
- length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
1395
- if (length2 === 0) {
1396
- return;
1397
- }
1398
- if (length1 <= length2) {
1399
- this.mergeLow(start1, length1, start2, length2);
1400
- } else {
1401
- this.mergeHigh(start1, length1, start2, length2);
1402
- }
1403
- };
1404
- TimSort2.prototype.mergeLow = function mergeLow(start1, length1, start2, length2) {
1405
- var compare = this.compare;
1406
- var array = this.array;
1407
- var tmp = this.tmp;
1408
- var i = 0;
1409
- for (i = 0; i < length1; i++) {
1410
- tmp[i] = array[start1 + i];
1411
- }
1412
- var cursor1 = 0;
1413
- var cursor2 = start2;
1414
- var dest = start1;
1415
- array[dest++] = array[cursor2++];
1416
- if (--length2 === 0) {
1417
- for (i = 0; i < length1; i++) {
1418
- array[dest + i] = tmp[cursor1 + i];
1419
- }
1420
- return;
1421
- }
1422
- if (length1 === 1) {
1423
- for (i = 0; i < length2; i++) {
1424
- array[dest + i] = array[cursor2 + i];
1425
- }
1426
- array[dest + length2] = tmp[cursor1];
1427
- return;
1428
- }
1429
- var minGallop = this.minGallop;
1430
- while (true) {
1431
- var count1 = 0;
1432
- var count2 = 0;
1433
- var exit = false;
1434
- do {
1435
- if (compare(array[cursor2], tmp[cursor1]) < 0) {
1436
- array[dest++] = array[cursor2++];
1437
- count2++;
1438
- count1 = 0;
1439
- if (--length2 === 0) {
1440
- exit = true;
1441
- break;
1442
- }
1443
- } else {
1444
- array[dest++] = tmp[cursor1++];
1445
- count1++;
1446
- count2 = 0;
1447
- if (--length1 === 1) {
1448
- exit = true;
1449
- break;
1450
- }
1451
- }
1452
- } while ((count1 | count2) < minGallop);
1453
- if (exit) {
1454
- break;
1455
- }
1456
- do {
1457
- count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
1458
- if (count1 !== 0) {
1459
- for (i = 0; i < count1; i++) {
1460
- array[dest + i] = tmp[cursor1 + i];
1461
- }
1462
- dest += count1;
1463
- cursor1 += count1;
1464
- length1 -= count1;
1465
- if (length1 <= 1) {
1466
- exit = true;
1467
- break;
1468
- }
1469
- }
1470
- array[dest++] = array[cursor2++];
1471
- if (--length2 === 0) {
1472
- exit = true;
1473
- break;
1474
- }
1475
- count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
1476
- if (count2 !== 0) {
1477
- for (i = 0; i < count2; i++) {
1478
- array[dest + i] = array[cursor2 + i];
1479
- }
1480
- dest += count2;
1481
- cursor2 += count2;
1482
- length2 -= count2;
1483
- if (length2 === 0) {
1484
- exit = true;
1485
- break;
1486
- }
1487
- }
1488
- array[dest++] = tmp[cursor1++];
1489
- if (--length1 === 1) {
1490
- exit = true;
1491
- break;
1492
- }
1493
- minGallop--;
1494
- } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
1495
- if (exit) {
1496
- break;
1497
- }
1498
- if (minGallop < 0) {
1499
- minGallop = 0;
1500
- }
1501
- minGallop += 2;
1502
- }
1503
- this.minGallop = minGallop;
1504
- if (minGallop < 1) {
1505
- this.minGallop = 1;
1506
- }
1507
- if (length1 === 1) {
1508
- for (i = 0; i < length2; i++) {
1509
- array[dest + i] = array[cursor2 + i];
1510
- }
1511
- array[dest + length2] = tmp[cursor1];
1512
- } else if (length1 === 0) {
1513
- throw new Error("mergeLow preconditions were not respected");
1514
- } else {
1515
- for (i = 0; i < length1; i++) {
1516
- array[dest + i] = tmp[cursor1 + i];
1517
- }
1518
- }
1519
- };
1520
- TimSort2.prototype.mergeHigh = function mergeHigh(start1, length1, start2, length2) {
1521
- var compare = this.compare;
1522
- var array = this.array;
1523
- var tmp = this.tmp;
1524
- var i = 0;
1525
- for (i = 0; i < length2; i++) {
1526
- tmp[i] = array[start2 + i];
1527
- }
1528
- var cursor1 = start1 + length1 - 1;
1529
- var cursor2 = length2 - 1;
1530
- var dest = start2 + length2 - 1;
1531
- var customCursor = 0;
1532
- var customDest = 0;
1533
- array[dest--] = array[cursor1--];
1534
- if (--length1 === 0) {
1535
- customCursor = dest - (length2 - 1);
1536
- for (i = 0; i < length2; i++) {
1537
- array[customCursor + i] = tmp[i];
1538
- }
1539
- return;
1540
- }
1541
- if (length2 === 1) {
1542
- dest -= length1;
1543
- cursor1 -= length1;
1544
- customDest = dest + 1;
1545
- customCursor = cursor1 + 1;
1546
- for (i = length1 - 1; i >= 0; i--) {
1547
- array[customDest + i] = array[customCursor + i];
1548
- }
1549
- array[dest] = tmp[cursor2];
1550
- return;
1551
- }
1552
- var minGallop = this.minGallop;
1553
- while (true) {
1554
- var count1 = 0;
1555
- var count2 = 0;
1556
- var exit = false;
1557
- do {
1558
- if (compare(tmp[cursor2], array[cursor1]) < 0) {
1559
- array[dest--] = array[cursor1--];
1560
- count1++;
1561
- count2 = 0;
1562
- if (--length1 === 0) {
1563
- exit = true;
1564
- break;
1565
- }
1566
- } else {
1567
- array[dest--] = tmp[cursor2--];
1568
- count2++;
1569
- count1 = 0;
1570
- if (--length2 === 1) {
1571
- exit = true;
1572
- break;
1573
- }
1574
- }
1575
- } while ((count1 | count2) < minGallop);
1576
- if (exit) {
1577
- break;
1578
- }
1579
- do {
1580
- count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
1581
- if (count1 !== 0) {
1582
- dest -= count1;
1583
- cursor1 -= count1;
1584
- length1 -= count1;
1585
- customDest = dest + 1;
1586
- customCursor = cursor1 + 1;
1587
- for (i = count1 - 1; i >= 0; i--) {
1588
- array[customDest + i] = array[customCursor + i];
1589
- }
1590
- if (length1 === 0) {
1591
- exit = true;
1592
- break;
1593
- }
1594
- }
1595
- array[dest--] = tmp[cursor2--];
1596
- if (--length2 === 1) {
1597
- exit = true;
1598
- break;
1599
- }
1600
- count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
1601
- if (count2 !== 0) {
1602
- dest -= count2;
1603
- cursor2 -= count2;
1604
- length2 -= count2;
1605
- customDest = dest + 1;
1606
- customCursor = cursor2 + 1;
1607
- for (i = 0; i < count2; i++) {
1608
- array[customDest + i] = tmp[customCursor + i];
1609
- }
1610
- if (length2 <= 1) {
1611
- exit = true;
1612
- break;
1613
- }
1614
- }
1615
- array[dest--] = array[cursor1--];
1616
- if (--length1 === 0) {
1617
- exit = true;
1618
- break;
1619
- }
1620
- minGallop--;
1621
- } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
1622
- if (exit) {
1623
- break;
1624
- }
1625
- if (minGallop < 0) {
1626
- minGallop = 0;
1627
- }
1628
- minGallop += 2;
1629
- }
1630
- this.minGallop = minGallop;
1631
- if (minGallop < 1) {
1632
- this.minGallop = 1;
1633
- }
1634
- if (length2 === 1) {
1635
- dest -= length1;
1636
- cursor1 -= length1;
1637
- customDest = dest + 1;
1638
- customCursor = cursor1 + 1;
1639
- for (i = length1 - 1; i >= 0; i--) {
1640
- array[customDest + i] = array[customCursor + i];
1641
- }
1642
- array[dest] = tmp[cursor2];
1643
- } else if (length2 === 0) {
1644
- throw new Error("mergeHigh preconditions were not respected");
1645
- } else {
1646
- customCursor = dest - (length2 - 1);
1647
- for (i = 0; i < length2; i++) {
1648
- array[customCursor + i] = tmp[i];
1649
- }
1650
- }
1651
- };
1652
- return TimSort2;
1653
- })();
1654
- function sort(array, compare, lo, hi) {
1655
- if (!Array.isArray(array)) {
1656
- throw new TypeError("Can only sort arrays");
1657
- }
1658
- if (!compare) {
1659
- compare = alphabeticalCompare;
1660
- } else if (typeof compare !== "function") {
1661
- hi = lo;
1662
- lo = compare;
1663
- compare = alphabeticalCompare;
1664
- }
1665
- if (!lo) {
1666
- lo = 0;
1667
- }
1668
- if (!hi) {
1669
- hi = array.length;
1670
- }
1671
- var remaining = hi - lo;
1672
- if (remaining < 2) {
1673
- return;
1674
- }
1675
- var runLength = 0;
1676
- if (remaining < DEFAULT_MIN_MERGE) {
1677
- runLength = makeAscendingRun(array, lo, hi, compare);
1678
- binaryInsertionSort(array, lo, hi, lo + runLength, compare);
1679
- return;
1680
- }
1681
- var ts = new TimSort(array, compare);
1682
- var minRun = minRunLength(remaining);
1683
- do {
1684
- runLength = makeAscendingRun(array, lo, hi, compare);
1685
- if (runLength < minRun) {
1686
- var force = remaining;
1687
- if (force > minRun) {
1688
- force = minRun;
1689
- }
1690
- binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
1691
- runLength = force;
1692
- }
1693
- ts.pushRun(lo, runLength);
1694
- ts.mergeRuns();
1695
- remaining -= runLength;
1696
- lo += runLength;
1697
- } while (remaining !== 0);
1698
- ts.forceMergeRuns();
1699
- }
1700
- });
1701
- })(timsort$1);
1702
- return timsort$1;
1703
- }
1704
- var timsort;
1705
- var hasRequiredTimsort;
1706
- function requireTimsort() {
1707
- if (hasRequiredTimsort) return timsort;
1708
- hasRequiredTimsort = 1;
1709
- timsort = requireTimsort$1();
1710
- return timsort;
1711
- }
1712
- var timsortExports = requireTimsort();
1713
- var lib;
1714
- var hasRequiredLib;
1715
- function requireLib() {
1716
- if (hasRequiredLib) return lib;
1717
- hasRequiredLib = 1;
1718
- function lessThanZeroError(p) {
1719
- return 'Expect percentile to be >= 0 but given "' + p + '" and its type is "' + typeof p + '".';
1720
- }
1721
- function greaterThanHundredError(p) {
1722
- return 'Expect percentile to be <= 100 but given "' + p + '" and its type is "' + typeof p + '".';
1723
- }
1724
- function nanError(p) {
1725
- return 'Expect percentile to be a number but given "' + p + '" and its type is "' + typeof p + '".';
1726
- }
1727
- function validateInput(ps) {
1728
- return ps.reduce(function(errors, p) {
1729
- if (isNaN(Number(p))) {
1730
- errors.push(nanError(p));
1731
- } else if (p < 0) {
1732
- errors.push(lessThanZeroError(p));
1733
- } else if (p > 100) {
1734
- errors.push(greaterThanHundredError(p));
1735
- }
1736
- return errors;
1737
- }, []);
1738
- }
1739
- function getPsValue(p, list) {
1740
- if (p === 0) return list[0];
1741
- var kIndex = Math.ceil(list.length * (p / 100)) - 1;
1742
- return list[kIndex];
1743
- }
1744
- function percentile2(pOrPs, list, fn) {
1745
- var ps = Array.isArray(pOrPs) ? pOrPs : [pOrPs];
1746
- var validationErrors = validateInput(ps);
1747
- if (validationErrors.length) {
1748
- throw new Error(validationErrors.join(" "));
1749
- }
1750
- list = list.slice().sort(function(a, b) {
1751
- if (fn) {
1752
- a = fn(a);
1753
- b = fn(b);
1754
- }
1755
- a = Number.isNaN(a) ? Number.NEGATIVE_INFINITY : a;
1756
- b = Number.isNaN(b) ? Number.NEGATIVE_INFINITY : b;
1757
- if (a > b) return 1;
1758
- if (a < b) return -1;
1759
- return 0;
1760
- });
1761
- if (ps.length === 1) {
1762
- return getPsValue(ps[0], list);
1763
- }
1764
- return ps.map(function(p) {
1765
- return getPsValue(p, list);
1766
- });
1767
- }
1768
- lib = percentile2;
1769
- return lib;
1770
- }
1771
- var libExports = requireLib();
1772
- const percentile = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
1773
- class InstrumentGaugeOptions extends InstrumentBaseOptions {
1774
- interval;
1775
- sampleSize;
1776
- fromJSON;
1777
- initValue;
1778
- }
1779
- class InstrumentGaugeTelemetry extends InstrumentBaseTelemetry {
1780
- val;
1781
- Inc;
1782
- Dec;
1783
- }
1784
- class InstrumentGauge extends InstrumentBase {
1785
- #val = 0;
1786
- #maxval = null;
1787
- #lastObservedValue = 0;
1788
- #timeSeriesList = [];
1789
- #maxSampleSize = 0;
1790
- #timerInterval = 0;
1791
- #observer = null;
1792
- //@@ extras
1793
- #min = null;
1794
- #max = 0;
1795
- #observations = 0;
1796
- #total = 0;
1797
- #copy = false;
1798
- constructor(options = {}) {
1799
- super(options);
1800
- if (!options.label) {
1801
- this.label = "InstrumentGauge";
1802
- } else {
1803
- this.label = options.label;
1804
- }
1805
- if (typeof options.interval === "undefined") {
1806
- this.#timerInterval = 0;
1807
- } else {
1808
- this.#timerInterval = options.interval;
1809
- }
1810
- if (typeof options.sampleSize === "undefined") {
1811
- this.#maxSampleSize = 600;
1812
- } else {
1813
- this.#maxSampleSize = options.sampleSize;
1814
- }
1815
- if (typeof options.fromJSON === "undefined") {
1816
- this.#copy = false;
1817
- } else {
1818
- this.#copy = true;
1819
- }
1820
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
1821
- enumerable: true,
1822
- get: () => GaugeTypes.INSTRUMENT_GAUGE
1823
- });
1824
- if (this.#copy) {
1825
- this.DefineCopyProperties([
1826
- "val",
1827
- "min",
1828
- "max",
1829
- "avg",
1830
- "percentile"
1831
- ]);
1832
- } else {
1833
- Object.defineProperty(this, "val", {
1834
- enumerable: true,
1835
- get: () => this.#GetVal(),
1836
- set: (value) => {
1837
- this.#SetVal(value);
1838
- }
1839
- });
1840
- if (this.#timerInterval > 0) {
1841
- Object.defineProperty(this, "percentile", {
1842
- enumerable: true,
1843
- get: () => this.#GetPercentileData()
1844
- });
1845
- this._StartTimer();
1846
- }
1847
- }
1848
- if (typeof options.initValue !== "undefined") {
1849
- this.val = options.initValue;
1850
- }
1851
- if (typeof options.fromJSON !== "undefined") {
1852
- const result = _cloneDeep(options.fromJSON);
1853
- this.val = result.val;
1854
- if (result.percentile) {
1855
- this.percentile = result.percentile;
1856
- }
1857
- if (result.min) {
1858
- this.min = result.min;
1859
- }
1860
- if (result.max) {
1861
- this.max = result.max;
1862
- }
1863
- if (result.avg) {
1864
- this.avg = result.avg;
1865
- }
1866
- }
1867
- }
1868
- percentile;
1869
- min;
1870
- max;
1871
- avg;
1872
- val = 0;
1873
- WithInitVal(initVal) {
1874
- this.val = initVal;
1875
- return this;
1876
- }
1877
- WithMin() {
1878
- Object.defineProperty(this, "min", {
1879
- enumerable: true,
1880
- get: () => this.#GetMin()
1881
- });
1882
- return this;
1883
- }
1884
- WithMax() {
1885
- Object.defineProperty(this, "max", {
1886
- enumerable: true,
1887
- get: () => this.#GetMax()
1888
- });
1889
- return this;
1890
- }
1891
- WithAverage() {
1892
- Object.defineProperty(this, "avg", {
1893
- enumerable: true,
1894
- get: () => this.#GetAverage()
1895
- });
1896
- return this;
1897
- }
1898
- _StartTimer() {
1899
- if (this.#timerInterval > 0) {
1900
- this.#timeSeriesList = [];
1901
- this.#observer = setInterval(() => {
1902
- if (this.#timeSeriesList.length > this.#maxSampleSize) {
1903
- this.#timeSeriesList.shift();
1904
- }
1905
- const maxval = this.#GetAndResetMaxVal();
1906
- this.#timeSeriesList.push(maxval);
1907
- }, this.#timerInterval);
1908
- if (isNode) {
1909
- this.#observer.unref();
1910
- }
1911
- } else {
1912
- throw new Error(`Unable to StartTimer for this instrument. The interval is set to <= 0.`);
1913
- }
1914
- }
1915
- StopTimer() {
1916
- if (this.#observer) {
1917
- clearTimeout(this.#observer);
1918
- this.#observer = null;
1919
- this.#timeSeriesList = [];
1920
- }
1921
- }
1922
- /**
1923
- * If the gauge is being monitored as part of a time series, get the most recent recorded value (max value) from within the time interval
1924
- * otherwise, just return the current instant value.
1925
- */
1926
- #GetVal() {
1927
- if (this.#timerInterval > 0 && this.#observer !== null) {
1928
- if (this.#maxval === null) {
1929
- return this.GetNumber(this.#lastObservedValue);
1930
- } else {
1931
- return this.GetNumber(this.#maxval);
1932
- }
1933
- }
1934
- return this.GetNumber(this.#val);
1935
- }
1936
- #SetVal(updatedValue) {
1937
- this.#val = updatedValue;
1938
- this.#observations++;
1939
- this.#total += updatedValue;
1940
- if (this.#val > this.#max) {
1941
- this.#max = this.#val;
1942
- }
1943
- if (this.#min !== null) {
1944
- if (this.#val < this.#min) {
1945
- this.#min = this.#val;
1946
- }
1947
- } else {
1948
- this.#min = this.#val;
1949
- }
1950
- if (this.#timerInterval > 0) {
1951
- this.#lastObservedValue = updatedValue;
1952
- if (this.#maxval === null) {
1953
- this.#maxval = this.#val;
1954
- } else if (this.#val > this.#maxval) {
1955
- this.#maxval = this.#val;
1956
- }
1957
- }
1958
- }
1959
- #GetMin() {
1960
- if (this.#min !== null) {
1961
- return this.#min;
1962
- }
1963
- return 0;
1964
- }
1965
- #GetMax() {
1966
- return this.#max;
1967
- }
1968
- #GetAverage() {
1969
- if (this.#observations > 0) {
1970
- return this.#total / this.#observations;
1971
- }
1972
- return 0;
1973
- }
1974
- Reset() {
1975
- this.StopTimer();
1976
- this.#maxval = 0;
1977
- this.#lastObservedValue = 0;
1978
- this.#val = 0;
1979
- this.#min = null;
1980
- this.#max = 0;
1981
- this.#observations = 0;
1982
- this.#total = 0;
1983
- if (this.#timerInterval > 0) {
1984
- this._StartTimer();
1985
- }
1986
- }
1987
- #GetAndResetMaxVal() {
1988
- if (this.#maxval === null) {
1989
- return this.#lastObservedValue;
1990
- }
1991
- const retVal = this.#maxval;
1992
- this.#maxval = null;
1993
- return retVal;
1994
- }
1995
- Inc(incVal = 1) {
1996
- this.#SetVal(this.#val + incVal);
1997
- }
1998
- Dec(decVal = 1) {
1999
- this.#SetVal(this.#val - decVal);
2000
- }
2001
- #NumberCompare(a, b) {
2002
- return a - b;
2003
- }
2004
- #GetPercentileData() {
2005
- const sortedList = this.#timeSeriesList.slice(0);
2006
- timsortExports.sort(sortedList, this.#NumberCompare);
2007
- return percentile([50, 80, 90, 95, 99, 99.95], sortedList);
2008
- }
2009
- ProcessTelemetry(telemetry) {
2010
- if (telemetry.Inc !== void 0) {
2011
- this.Inc(telemetry.Inc);
2012
- }
2013
- if (telemetry.Dec !== void 0) {
2014
- this.Dec(telemetry.Dec);
2015
- }
2016
- if (telemetry.val !== void 0) {
2017
- this.val = telemetry.val;
2018
- }
2019
- }
2020
- }
2021
- class InstrumentObjectOptions extends InstrumentBaseOptions {
2022
- fromJSON;
2023
- initValue;
2024
- }
2025
- class InstrumentObjectTelemetry extends InstrumentBaseTelemetry {
2026
- val;
2027
- }
2028
- class InstrumentObject extends InstrumentBase {
2029
- #val = {};
2030
- #copy = false;
2031
- constructor(options = {}) {
2032
- super(options);
2033
- if (typeof options.label === "undefined") {
2034
- this.label = "InstrumentObject";
2035
- } else {
2036
- this.label = options.label;
2037
- }
2038
- if (typeof options.fromJSON === "undefined") {
2039
- this.#copy = false;
2040
- } else {
2041
- this.#copy = true;
2042
- }
2043
- Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
2044
- enumerable: true,
2045
- get: () => GaugeTypes.INSTRUMENT_OBJECT
2046
- });
2047
- if (this.#copy) {
2048
- this.DefineCopyProperties([
2049
- "val"
2050
- ]);
2051
- } else {
2052
- Object.defineProperty(this, "val", {
2053
- enumerable: true,
2054
- get: () => this.#GetVal(),
2055
- set: (value) => {
2056
- this.#SetVal(value);
2057
- }
2058
- });
2059
- }
2060
- if (typeof options.initValue !== "undefined") {
2061
- this.val = options.initValue;
2062
- } else {
2063
- this.val = {};
2064
- }
2065
- if (typeof options.fromJSON !== "undefined") {
2066
- const result = _cloneDeep(options.fromJSON);
2067
- this.val = result.val;
2068
- }
2069
- }
2070
- val;
2071
- WithInitVal(initVal) {
2072
- this.val = initVal;
2073
- return this;
2074
- }
2075
- #GetVal() {
2076
- return this.#val;
2077
- }
2078
- #SetVal(updatedValue) {
2079
- this.#val = updatedValue;
2080
- }
2081
- ProcessTelemetry(telemetry) {
2082
- if (telemetry.val !== void 0) {
2083
- this.val = telemetry.val;
2084
- }
2085
- }
2086
- }
3
+ //#region \0rolldown/runtime.js
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ //#endregion
26
+ //#region src/instrumentation/instrumentDefs.ts
27
+ var Gauge = /* @__PURE__ */ function(Gauge) {
28
+ Gauge["ACTIVE_REQUEST_GAUGE"] = "a";
29
+ Gauge["AUTHENTICATION_COUNT_GAUGE"] = "b";
30
+ Gauge["AUTHENTICATION_ERROR_COUNT_GAUGE"] = "aa";
31
+ Gauge["AUTHENTICATION_RETRY_COUNT_GAUGE"] = "ab";
32
+ Gauge["CONNECTION_POOL_IDLE_GAUGE"] = "c";
33
+ Gauge["CONNECTION_POOL_TOTAL_GAUGE"] = "d";
34
+ Gauge["CONNECTION_POOL_WAITING_GAUGE"] = "e";
35
+ Gauge["CPU_LOAD_GAUGE"] = "f";
36
+ Gauge["CPU_SYSTEM_LOAD_GAUGE"] = "g";
37
+ Gauge["DURATION_GAUGE"] = "h";
38
+ Gauge["DURATION_HISTOGRAM_GAUGE"] = "i";
39
+ Gauge["ERROR_COUNT_GAUGE"] = "j";
40
+ Gauge["LATENCY_GAUGE"] = "k";
41
+ Gauge["LATENCY_HISTOGRAM_GAUGE"] = "l";
42
+ Gauge["LOGGER"] = "m";
43
+ Gauge["LOGGER_COPY"] = "n";
44
+ Gauge["NETWORK_RX_GAUGE"] = "o";
45
+ Gauge["NETWORK_TX_GAUGE"] = "p";
46
+ Gauge["REQUEST_COUNT_GAUGE"] = "q";
47
+ Gauge["RETRY_COUNT_GAUGE"] = "r";
48
+ Gauge["TIMER_GAUGE"] = "s";
49
+ Gauge["VELOCITY_GAUGE"] = "t";
50
+ Gauge["CONNECTION_COUNT_GAUGE"] = "u";
51
+ Gauge["OBJECT_GAUGE"] = "v";
52
+ Gauge["PAYLOAD_SIZE"] = "w";
53
+ Gauge["CORE_COUNT_GAUGE"] = "x";
54
+ Gauge["CHILD_COUNT"] = "y";
55
+ Gauge["UNKNOWN"] = "z";
56
+ return Gauge;
57
+ }({});
58
+ var GaugeTypes = /* @__PURE__ */ function(GaugeTypes) {
59
+ GaugeTypes["GAUGE_TYPE"] = "_";
60
+ GaugeTypes["INSTRUMENT_GAUGE"] = "a";
61
+ GaugeTypes["INSTRUMENT_VELOCITY"] = "b";
62
+ GaugeTypes["INSTRUMENT_HISTOGRAM"] = "c";
63
+ GaugeTypes["INSTRUMENT_LOG"] = "d";
64
+ GaugeTypes["INSTRUMENT_TIMER"] = "e";
65
+ GaugeTypes["INSTRUMENT_OBJECT"] = "f";
66
+ return GaugeTypes;
67
+ }({});
68
+ //#endregion
69
+ //#region src/instrumentation/instruments/instrumentBase.ts
70
+ var InstrumentBaseOptions = class {
71
+ fixedSize;
72
+ padLength;
73
+ label;
74
+ };
75
+ var InstrumentBaseTelemetry = class {};
76
+ var InstrumentBase = class {
77
+ #label = "";
78
+ #options = null;
79
+ #data = {};
80
+ constructor(options = {}) {
81
+ if (typeof options === "string" || options instanceof String) throw new Error("Instrument parameter must be an options object.");
82
+ this.#options = options;
83
+ if (options.label) this.#label = options.label;
84
+ else this.#label = "InstrumentGauge";
85
+ }
86
+ [GaugeTypes.GAUGE_TYPE] = GaugeTypes.INSTRUMENT_OBJECT;
87
+ val;
88
+ WithLabel(label) {
89
+ this.label = label;
90
+ return this;
91
+ }
92
+ DefineCopyProperties(propertyNames) {
93
+ propertyNames.forEach((propertyName) => {
94
+ Object.defineProperty(this, propertyName, {
95
+ enumerable: true,
96
+ get: () => this.#data[propertyName],
97
+ set: (value) => {
98
+ if (value === void 0) return;
99
+ this.#data[propertyName] = value;
100
+ }
101
+ });
102
+ });
103
+ }
104
+ GetNumber(val) {
105
+ if (Number.isInteger(val)) return val;
106
+ else return Math.round((val + Number.EPSILON) * 100) / 100;
107
+ }
108
+ get options() {
109
+ return this.#options;
110
+ }
111
+ set options(optionsValue) {
112
+ this.#options = optionsValue;
113
+ }
114
+ get label() {
115
+ return this.#label;
116
+ }
117
+ set label(labelValue) {
118
+ this.#label = labelValue;
119
+ }
120
+ StopTimer() {}
121
+ ProcessTelemetry(telemetry) {
122
+ throw new Error(`Must override in extended class: [ProcessTelemetry]: [${telemetry}].`);
123
+ }
124
+ };
125
+ //#endregion
126
+ //#region src/instrumentation/instruments/instrumentVelocity.ts
127
+ var InstrumentVelocityOptions = class extends InstrumentBaseOptions {
128
+ interval;
129
+ valStackMaxLength;
130
+ maxAverageValStack;
131
+ maxAverageIterations;
132
+ fromJSON;
133
+ initValue;
134
+ autoComputeVelocity;
135
+ velocityTimeDiff;
136
+ vaTimeDiff;
137
+ autoComputeVelocityTimeout;
138
+ };
139
+ var InstrumentVelocityTelemetry = class extends InstrumentBaseTelemetry {
140
+ val;
141
+ Inc;
142
+ };
143
+ var InstrumentVelocity = class extends InstrumentBase {
144
+ #val = 0;
145
+ #interval = null;
146
+ #timeoutComputeVelocity = null;
147
+ #lastVelocity = 0;
148
+ #delta = 0;
149
+ #maxVelocity = 0;
150
+ #timerInterval = 0;
151
+ #copy = false;
152
+ #velocity = 0;
153
+ #velocityVal = 0;
154
+ #valStack = [];
155
+ #averageValStack = [];
156
+ #maxAverageValStack = 0;
157
+ #maxAverageIterations = 0;
158
+ #valStackMaxLength = 0;
159
+ #valStackAverage = 0;
160
+ #timeStamp = 0;
161
+ #maxTimeDiff = 0;
162
+ #vaTimeDiff = 0;
163
+ #velocityTimeDiff = 0;
164
+ #autoComputeVelocity = false;
165
+ #autoComputeVelocityTimeout = 0;
166
+ #countDiff = 0;
167
+ #timeDiff = 0;
168
+ #deltaCountDiff = 0;
169
+ #deltaTimeDif = 0;
170
+ #minTimeForReporting = 0;
171
+ #averageVelocity = [];
172
+ constructor(options = {}) {
173
+ super(options);
174
+ if (typeof options.label === "undefined") this.label = "InstrumentVelocity";
175
+ else this.label = options.label;
176
+ if (typeof options.interval === "undefined") this.#timerInterval = 1e3;
177
+ else this.#timerInterval = options.interval;
178
+ if (typeof options.valStackMaxLength === "undefined") this.#valStackMaxLength = 100;
179
+ else this.#valStackMaxLength = options.valStackMaxLength;
180
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
181
+ else this.#copy = true;
182
+ if (typeof options.autoComputeVelocity === "undefined") this.#autoComputeVelocity = false;
183
+ else this.#autoComputeVelocity = options.autoComputeVelocity;
184
+ if (typeof options.maxAverageValStack === "undefined") this.#maxAverageValStack = 5;
185
+ else this.#maxAverageValStack = options.maxAverageValStack;
186
+ if (typeof options.maxAverageIterations === "undefined") this.#maxAverageIterations = 3;
187
+ else this.#maxAverageIterations = options.maxAverageIterations;
188
+ if (typeof options.velocityTimeDiff === "undefined") this.#velocityTimeDiff = 5e3;
189
+ else this.#velocityTimeDiff = options.velocityTimeDiff;
190
+ if (typeof options.vaTimeDiff === "undefined") this.#vaTimeDiff = 1e4;
191
+ else this.#vaTimeDiff = options.vaTimeDiff;
192
+ if (typeof options.autoComputeVelocityTimeout === "undefined") this.#autoComputeVelocityTimeout = 50;
193
+ else this.#autoComputeVelocityTimeout = options.autoComputeVelocityTimeout;
194
+ this.#maxTimeDiff = this.#vaTimeDiff * 2;
195
+ this.#minTimeForReporting = this.#vaTimeDiff + 2e3;
196
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
197
+ enumerable: true,
198
+ get: () => GaugeTypes.INSTRUMENT_VELOCITY
199
+ });
200
+ if (this.#copy) this.DefineCopyProperties([
201
+ "val",
202
+ "maxVelocity",
203
+ "delta",
204
+ "velocity",
205
+ "va",
206
+ "timeStamp",
207
+ "deltaTimeDif",
208
+ "deltaCountDiff",
209
+ "timeDiff",
210
+ "countDiff",
211
+ "averageVelocity"
212
+ ]);
213
+ else {
214
+ Object.defineProperty(this, "val", {
215
+ enumerable: true,
216
+ get: () => this.#GetVal(),
217
+ set: (value) => {
218
+ this.#SetVal(value);
219
+ }
220
+ });
221
+ Object.defineProperty(this, "maxVelocity", {
222
+ enumerable: true,
223
+ get: () => this.#GetMaxVelocity()
224
+ });
225
+ Object.defineProperty(this, "delta", {
226
+ enumerable: true,
227
+ get: () => this.#GetDelta()
228
+ });
229
+ Object.defineProperty(this, "velocity", {
230
+ enumerable: true,
231
+ get: () => this.#GetVelocity()
232
+ });
233
+ Object.defineProperty(this, "va", {
234
+ enumerable: true,
235
+ get: () => this.#GetVelocityStackAverage()
236
+ });
237
+ Object.defineProperty(this, "timeStamp", {
238
+ enumerable: true,
239
+ get: () => this.#GetTimeStamp()
240
+ });
241
+ Object.defineProperty(this, "countDiff", {
242
+ enumerable: true,
243
+ get: () => this.#GetCountDiff()
244
+ });
245
+ Object.defineProperty(this, "timeDiff", {
246
+ enumerable: true,
247
+ get: () => this.#GetTimeDiff()
248
+ });
249
+ Object.defineProperty(this, "deltaCountDiff", {
250
+ enumerable: true,
251
+ get: () => this.#GetDeltaCountDiff()
252
+ });
253
+ Object.defineProperty(this, "deltaTimeDif", {
254
+ enumerable: true,
255
+ get: () => this.#GetDeltaTimeDif()
256
+ });
257
+ Object.defineProperty(this, "averageVelocity", {
258
+ enumerable: true,
259
+ get: () => this.#GetAverageVelocity()
260
+ });
261
+ if (this.#timerInterval > 0 && this.#autoComputeVelocity === false) this._StartTimer();
262
+ }
263
+ if (typeof options.initValue !== "undefined") this.val = options.initValue;
264
+ if (typeof options.fromJSON !== "undefined") {
265
+ const result = _cloneDeep(options.fromJSON);
266
+ this.val = result.val;
267
+ this.velocity = result.velocity;
268
+ this.maxVelocity = result.maxVelocity;
269
+ this.delta = result.delta;
270
+ this.va = result.va;
271
+ this.timeStamp = result.timeStamp;
272
+ this.countDiff = result.countDiff;
273
+ this.timeDiff = result.timeDiff;
274
+ this.deltaCountDiff = result.deltaCountDiff;
275
+ this.deltaTimeDif = result.deltaTimeDif;
276
+ this.averageVelocity = _cloneDeep(result.averageVelocity);
277
+ }
278
+ }
279
+ maxVelocity = 0;
280
+ delta = 0;
281
+ velocity = 0;
282
+ va = 0;
283
+ timeStamp = 0;
284
+ countDiff = 0;
285
+ timeDiff = 0;
286
+ deltaCountDiff = 0;
287
+ deltaTimeDif = 0;
288
+ averageVelocity = [];
289
+ val = 0;
290
+ WithValStackMaxLength(valStackMaxLength) {
291
+ this.#valStackMaxLength = valStackMaxLength;
292
+ this.#valStack = [];
293
+ return this;
294
+ }
295
+ _StartTimer() {
296
+ this.#interval = setInterval(() => {
297
+ this.#ComputeVelocity();
298
+ let pushVal = this.#velocity;
299
+ for (let i = 0; i < this.#maxAverageIterations; i++) {
300
+ if (!this.#averageValStack[i]) this.#averageValStack[i] = [];
301
+ this.#averageValStack[i].push(pushVal);
302
+ if (this.#averageValStack[i].length > this.#maxAverageValStack) this.#averageValStack[i].shift();
303
+ pushVal = this.#averageValStack[i].reduce((prev, current) => prev + current) / this.#averageValStack[i].length;
304
+ this.#averageVelocity[i] = pushVal;
305
+ }
306
+ }, this.#timerInterval);
307
+ if (isNode) this.#interval.unref();
308
+ }
309
+ #ComputeVelocityByTimeDiff(checkTimeDiff, checkDeltaTimeDiff) {
310
+ let val = 0;
311
+ let deltaVal = 0;
312
+ let countDiff = 0;
313
+ let timeDiff = 0;
314
+ let deltaCountDiff = 0;
315
+ let deltaTimeDiff = 0;
316
+ if (this.#valStack.length > 1 && this.#valStack[this.#valStack.length - 1].timeStamp - this.#valStack[0].timeStamp > this.#minTimeForReporting) {
317
+ const dp = this.#valStack[this.#valStack.length - 1];
318
+ let timeDiffPos = -1;
319
+ let deltaDiffPos = -1;
320
+ for (let i = this.#valStack.length - 2; i > -1; i--) {
321
+ if (timeDiffPos === -1 && this.#timeStamp - this.#valStack[i].timeStamp >= checkTimeDiff) {
322
+ timeDiffPos = i;
323
+ if (checkDeltaTimeDiff === 0) break;
324
+ }
325
+ if (deltaDiffPos === -1 && this.#timeStamp - this.#valStack[i].timeStamp >= checkDeltaTimeDiff) deltaDiffPos = i;
326
+ if (timeDiffPos !== -1 && deltaDiffPos !== -1) break;
327
+ }
328
+ if (timeDiffPos > -1) {
329
+ countDiff = dp.count - this.#valStack[timeDiffPos].count;
330
+ if (countDiff > 0) {
331
+ timeDiff = dp.timeStamp - this.#valStack[timeDiffPos].timeStamp;
332
+ if (timeDiff > 0) val = 1e3 / timeDiff * countDiff;
333
+ else val = 0;
334
+ } else val = 0;
335
+ } else val = 0;
336
+ if (deltaDiffPos > -1) {
337
+ deltaCountDiff = this.#valStack[timeDiffPos].count - this.#valStack[deltaDiffPos].count;
338
+ if (deltaCountDiff > 0) {
339
+ deltaTimeDiff = this.#valStack[timeDiffPos].timeStamp - this.#valStack[deltaDiffPos].timeStamp;
340
+ if (deltaTimeDiff > 0) deltaVal = 1e3 / deltaTimeDiff * deltaTimeDiff;
341
+ else deltaVal = 0;
342
+ } else deltaVal = 0;
343
+ } else deltaVal = 0;
344
+ }
345
+ return {
346
+ val,
347
+ countDiff,
348
+ timeDiff,
349
+ deltaVal,
350
+ deltaCountDiff,
351
+ deltaTimeDiff
352
+ };
353
+ }
354
+ #ComputeVelocity() {
355
+ const dp = {
356
+ timeStamp: performance.now(),
357
+ count: this.#velocityVal
358
+ };
359
+ this.#valStack.push(dp);
360
+ this.#timeStamp = dp.timeStamp;
361
+ while (this.#valStack.length > 0 && this.#timeStamp - this.#valStack[0].timeStamp > this.#maxTimeDiff) this.#valStack.shift();
362
+ this.#valStackAverage = this.#ComputeVelocityByTimeDiff(this.#vaTimeDiff, 0).val;
363
+ const velocityDataPoint = this.#ComputeVelocityByTimeDiff(this.#velocityTimeDiff, this.#velocityTimeDiff * 2);
364
+ this.#velocity = velocityDataPoint.val;
365
+ this.#delta = velocityDataPoint.val - velocityDataPoint.deltaVal;
366
+ this.#countDiff = velocityDataPoint.countDiff;
367
+ this.#timeDiff = velocityDataPoint.timeDiff;
368
+ this.#deltaCountDiff = velocityDataPoint.deltaCountDiff;
369
+ this.#deltaTimeDif = velocityDataPoint.deltaTimeDiff;
370
+ this.#lastVelocity = this.#velocity;
371
+ if (this.#velocity > this.#maxVelocity) this.#maxVelocity = this.#velocity;
372
+ }
373
+ #SetupAutoComputeVelocity() {
374
+ if (this.#timeoutComputeVelocity) clearTimeout(this.#timeoutComputeVelocity);
375
+ this.#timeoutComputeVelocity = setTimeout(() => {
376
+ this.#ComputeVelocity();
377
+ }, this.#autoComputeVelocityTimeout);
378
+ }
379
+ #GetVelocityStackAverage() {
380
+ return this.GetNumber(this.#valStackAverage);
381
+ }
382
+ Inc(incVal = 1) {
383
+ this.#velocityVal += incVal;
384
+ if (this.#autoComputeVelocity) this.#ComputeVelocity();
385
+ else this.#SetupAutoComputeVelocity();
386
+ }
387
+ #GetVal() {
388
+ return this.GetNumber(this.#velocityVal);
389
+ }
390
+ #SetVal(updatedValue) {
391
+ this.#velocityVal = updatedValue;
392
+ if (this.#autoComputeVelocity) this.#ComputeVelocity();
393
+ else this.#SetupAutoComputeVelocity();
394
+ }
395
+ #GetVelocity() {
396
+ return this.GetNumber(this.#velocity);
397
+ }
398
+ #GetMaxVelocity() {
399
+ return this.GetNumber(this.#maxVelocity);
400
+ }
401
+ #GetDelta() {
402
+ return this.GetNumber(this.#delta);
403
+ }
404
+ #GetTimeStamp() {
405
+ return this.GetNumber(this.#timeStamp);
406
+ }
407
+ #GetCountDiff() {
408
+ return this.GetNumber(this.#countDiff);
409
+ }
410
+ #GetTimeDiff() {
411
+ return this.GetNumber(this.#timeDiff);
412
+ }
413
+ #GetDeltaCountDiff() {
414
+ return this.GetNumber(this.#deltaCountDiff);
415
+ }
416
+ #GetDeltaTimeDif() {
417
+ return this.GetNumber(this.#deltaTimeDif);
418
+ }
419
+ #GetAverageVelocity() {
420
+ return this.#averageVelocity;
421
+ }
422
+ StopTimer() {
423
+ if (this.#interval !== null) {
424
+ clearTimeout(this.#interval);
425
+ this.#interval = null;
426
+ }
427
+ }
428
+ ProcessTelemetry(telemetry) {
429
+ if (telemetry.Inc !== void 0) this.Inc(telemetry.Inc);
430
+ if (telemetry.val !== void 0) this.val = telemetry.val;
431
+ }
432
+ };
433
+ //#endregion
434
+ //#region src/instrumentation/instruments/instrumentHistogram.ts
435
+ var HistogramDataElementPos = /* @__PURE__ */ function(HistogramDataElementPos) {
436
+ HistogramDataElementPos[HistogramDataElementPos["val"] = 0] = "val";
437
+ HistogramDataElementPos[HistogramDataElementPos["label"] = 1] = "label";
438
+ HistogramDataElementPos[HistogramDataElementPos["breakPoint"] = 2] = "breakPoint";
439
+ return HistogramDataElementPos;
440
+ }({});
441
+ var InstrumentHistogramOptions = class extends InstrumentBaseOptions {
442
+ histogramData;
443
+ initValue;
444
+ fromJSON;
445
+ };
446
+ var InstrumentHistogramTelemetry = class extends InstrumentBaseTelemetry {
447
+ val;
448
+ };
449
+ var InstrumentHistogram = class extends InstrumentBase {
450
+ #histogramData = [];
451
+ #val = 0;
452
+ #copy = false;
453
+ constructor(options = {}) {
454
+ super(options);
455
+ if (typeof options.label === "undefined") this.label = "InstrumentHistogram";
456
+ else this.label = options.label;
457
+ let histogramData = null;
458
+ if (typeof options.histogramData === "undefined") histogramData = null;
459
+ else histogramData = options.histogramData;
460
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
461
+ else this.#copy = true;
462
+ if (histogramData === null) this.#histogramData = [
463
+ [
464
+ 0,
465
+ "10",
466
+ 10
467
+ ],
468
+ [
469
+ 0,
470
+ "20",
471
+ 20
472
+ ],
473
+ [
474
+ 0,
475
+ "50",
476
+ 50
477
+ ],
478
+ [
479
+ 0,
480
+ "100",
481
+ 100
482
+ ],
483
+ [
484
+ 0,
485
+ "1000",
486
+ 1e3
487
+ ],
488
+ [
489
+ 0,
490
+ "5000",
491
+ 5e3
492
+ ],
493
+ [
494
+ 0,
495
+ "EE",
496
+ 0
497
+ ]
498
+ ];
499
+ else if (Array.isArray(histogramData)) {
500
+ this.#histogramData = [];
501
+ for (let i = 0; i < histogramData.length; i++) this.#histogramData.push([
502
+ 0,
503
+ "" + histogramData[i],
504
+ parseFloat(histogramData[i].toString())
505
+ ]);
506
+ this.#histogramData.push([
507
+ 0,
508
+ "EE",
509
+ 0
510
+ ]);
511
+ } else throw new Error(`Passed [${histogramData}] must be an array.`);
512
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
513
+ enumerable: true,
514
+ get: () => GaugeTypes.INSTRUMENT_HISTOGRAM
515
+ });
516
+ if (this.#copy) this.DefineCopyProperties(["val", "hist"]);
517
+ else {
518
+ Object.defineProperty(this, "val", {
519
+ enumerable: true,
520
+ get: () => this.#GetVal(),
521
+ set: (value) => {
522
+ this.#SetVal(value);
523
+ }
524
+ });
525
+ Object.defineProperty(this, "hist", {
526
+ enumerable: true,
527
+ get: () => this.#GetHistogramData(),
528
+ set: (value) => {
529
+ this.#SetHistogramData(value);
530
+ }
531
+ });
532
+ }
533
+ if (typeof options.initValue !== "undefined") this.#val = options.initValue;
534
+ if (typeof options.fromJSON !== "undefined") {
535
+ const result = _cloneDeep(options.fromJSON);
536
+ this.#val = result.val;
537
+ this.hist = result.hist;
538
+ }
539
+ }
540
+ hist = [];
541
+ val = 0;
542
+ WithInitVal(initVal) {
543
+ this.#val = initVal;
544
+ return this;
545
+ }
546
+ ResetHistogramData() {
547
+ for (let i = 0; i < this.hist.length; i++) this.hist[i][0] = 0;
548
+ }
549
+ AddObservation(updateValue) {
550
+ if (this.#copy) throw new Error("Cannot add observations from the copy version of this class.");
551
+ let i = 0;
552
+ for (; i < this.#histogramData.length - 1; i++) if (updateValue <= this.#histogramData[i][HistogramDataElementPos.breakPoint]) {
553
+ this.#histogramData[i][HistogramDataElementPos.val]++;
554
+ return;
555
+ }
556
+ this.#histogramData[i][HistogramDataElementPos.val]++;
557
+ }
558
+ #GetVal() {
559
+ return this.GetNumber(this.#val);
560
+ }
561
+ #SetVal(value) {
562
+ this.#val = value;
563
+ this.AddObservation(value);
564
+ }
565
+ get formattedHistogramData() {
566
+ let retVal = "";
567
+ let sep = "";
568
+ for (let i = 0; i < this.hist.length; i++) {
569
+ retVal += sep + "[" + (this.hist[i][HistogramDataElementPos.val] + "/" + this.hist[i][HistogramDataElementPos.label]).padStart(10, " ") + "]";
570
+ sep = " ";
571
+ }
572
+ return retVal;
573
+ }
574
+ #GetHistogramData() {
575
+ return this.#histogramData;
576
+ }
577
+ #SetHistogramData(value) {
578
+ this.#histogramData = value;
579
+ }
580
+ static AddHistogramDataEx(histoA, histoB) {
581
+ if (histoA === null) return _cloneDeep(histoB);
582
+ const result = _cloneDeep(histoA);
583
+ const histogramAData = result.hist;
584
+ const histogramBData = histoB.hist;
585
+ if (histogramAData.length !== histogramBData.length) throw new Error("Invalid HistogramData. HistogramData bucket lengths must be the same.");
586
+ for (let i = 0; i < histogramAData.length; i++) {
587
+ if (histogramAData[i][HistogramDataElementPos.breakPoint] !== histogramBData[i][HistogramDataElementPos.breakPoint]) throw new Error(`Invalid HistogramData. HistogramData bucket break-point at index [${i}] must be the same.`);
588
+ if (histogramAData[i][HistogramDataElementPos.label] !== histogramBData[i][HistogramDataElementPos.label]) throw new Error(`Invalid HistogramData. HistogramData bucket label at index [${i}] must be the same.`);
589
+ histogramAData[i][HistogramDataElementPos.val] += histogramBData[i][HistogramDataElementPos.val];
590
+ }
591
+ return result;
592
+ }
593
+ /**
594
+ * Adds a value object (from GetFormatted()) to this instance.
595
+ * @param {*} value
596
+ */
597
+ AddHistogramData(histogramData) {
598
+ if (histogramData === null) return;
599
+ if (this.hist.length !== histogramData.hist.length) throw new Error("Invalid HistogramData. HistogramData bucket lengths must be the same.");
600
+ for (let i = 0; i < histogramData.hist.length; i++) {
601
+ if (this.hist[i][HistogramDataElementPos.breakPoint] !== histogramData.hist[i][HistogramDataElementPos.breakPoint]) throw new Error(`Invalid HistogramData. HistogramData bucket break-point at index [${i}] must be the same.`);
602
+ if (this.hist[i][HistogramDataElementPos.label] !== histogramData.hist[i][HistogramDataElementPos.label]) throw new Error(`Invalid HistogramData. HistogramData bucket label at index [${i}] must be the same.`);
603
+ this.hist[i][HistogramDataElementPos.val] += histogramData.hist[i][HistogramDataElementPos.val];
604
+ }
605
+ }
606
+ ProcessTelemetry(telemetry) {
607
+ if (telemetry.val !== void 0) this.val = telemetry.val;
608
+ }
609
+ };
610
+ //#endregion
611
+ //#region src/instrumentation/instruments/instrumentLog.ts
612
+ var InstrumentLogOptions = class extends InstrumentBaseOptions {
613
+ maxSize;
614
+ useLatestMessages;
615
+ consoleLogging;
616
+ instrumentLogging;
617
+ winstonLogging;
618
+ fromJSON;
619
+ initValue;
620
+ logger;
621
+ };
622
+ var InstrumentLogTelemetry = class extends InstrumentBaseTelemetry {
623
+ Append;
624
+ LogMessage;
625
+ val;
626
+ ResetLog;
627
+ };
628
+ var InstrumentLog = class extends InstrumentBase {
629
+ #messages = [];
630
+ #readPos = 0;
631
+ #maxSize = 200;
632
+ #copy = false;
633
+ #useLatestMessages = false;
634
+ #consoleLogging = false;
635
+ #instrumentLogging = true;
636
+ #winstonLogging = false;
637
+ #stsLogger;
638
+ constructor(options = {}) {
639
+ super(options);
640
+ if (typeof options.label === "undefined") this.label = "InstrumentLog";
641
+ else this.label = options.label;
642
+ if (typeof options.maxSize === "undefined") this.#maxSize = 200;
643
+ else this.#maxSize = options.maxSize;
644
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
645
+ else this.#copy = true;
646
+ if (typeof options.useLatestMessages === "undefined") this.#useLatestMessages = false;
647
+ else this.#useLatestMessages = options.useLatestMessages;
648
+ if (typeof options.consoleLogging === "undefined") this.#consoleLogging = false;
649
+ else this.#consoleLogging = options.consoleLogging;
650
+ if (typeof options.instrumentLogging === "undefined") this.#instrumentLogging = true;
651
+ else this.#instrumentLogging = options.instrumentLogging;
652
+ if (typeof options.winstonLogging === "undefined") this.#winstonLogging = false;
653
+ else this.#winstonLogging = options.winstonLogging;
654
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
655
+ enumerable: true,
656
+ get: () => GaugeTypes.INSTRUMENT_LOG
657
+ });
658
+ if (this.#copy) this.DefineCopyProperties(["val"]);
659
+ else Object.defineProperty(this, "val", {
660
+ enumerable: true,
661
+ get: () => _cloneDeep(this.#GetVal()),
662
+ set: (value) => {
663
+ this.#SetVal(value);
664
+ }
665
+ });
666
+ if (typeof options.initValue !== "undefined") this.val = options.initValue;
667
+ if (typeof options.fromJSON !== "undefined") this.val = _cloneDeep(options.fromJSON).val;
668
+ }
669
+ val = [];
670
+ WithMaxSize(maxSize) {
671
+ this.#maxSize = maxSize;
672
+ return this;
673
+ }
674
+ WithUseLatestMessages(useLatestMessages) {
675
+ this.#useLatestMessages = useLatestMessages;
676
+ return this;
677
+ }
678
+ WithConsoleLogging(consoleLogging) {
679
+ this.#consoleLogging = consoleLogging;
680
+ return this;
681
+ }
682
+ WithInstrumentLogging(instrumentLogging) {
683
+ this.#instrumentLogging = instrumentLogging;
684
+ return this;
685
+ }
686
+ get MaxSize() {
687
+ return this.#maxSize;
688
+ }
689
+ set MaxSize(maxSize) {
690
+ this.#maxSize = maxSize;
691
+ }
692
+ #DumpToConsole() {
693
+ const logReport = this.GetMessagesSinceLastRead();
694
+ for (let i = 0; i < logReport.length; i++) console.log(logReport[i]);
695
+ }
696
+ get consoleLogging() {
697
+ return this.#consoleLogging;
698
+ }
699
+ set consoleLogging(value) {
700
+ this.#consoleLogging = value;
701
+ if (value === true) this.#DumpToConsole();
702
+ }
703
+ get instrumentLogging() {
704
+ return this.#instrumentLogging;
705
+ }
706
+ set instrumentLogging(value) {
707
+ this.#instrumentLogging = value;
708
+ }
709
+ Append(messageArray) {
710
+ for (let i = 0; i < messageArray.length; i++) this.LogMessage(messageArray[i]);
711
+ }
712
+ error(message) {
713
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.error(message);
714
+ }
715
+ warn(message) {
716
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.warn(message);
717
+ }
718
+ info(message) {
719
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.info(message);
720
+ }
721
+ http(message) {
722
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.http(message);
723
+ }
724
+ verbose(message) {
725
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.verbose(message);
726
+ }
727
+ debug(message) {
728
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.debug(message);
729
+ }
730
+ silly(message) {
731
+ if (this.#winstonLogging && this.#stsLogger) this.#stsLogger.silly(message);
732
+ }
733
+ LogMessage(message) {
734
+ if (this.#copy) throw new Error("Cannot add log messages from the copy version of this class.");
735
+ if (this.#consoleLogging === true) console.log(message);
736
+ if (this.#instrumentLogging === false) return;
737
+ this.#messages.push(message);
738
+ if (this.#messages.length > this.#maxSize) {
739
+ this.#messages.shift();
740
+ this.#readPos = this.#readPos > 0 ? this.#readPos - 1 : 0;
741
+ }
742
+ }
743
+ #GetVal() {
744
+ if (this.#useLatestMessages) return this.GetMessagesSinceLastRead();
745
+ else return this.#messages;
746
+ }
747
+ #SetVal(updatedValue) {
748
+ this.#messages = updatedValue;
749
+ this.#readPos = 0;
750
+ }
751
+ GetMessagesNoUpdate() {
752
+ return this.#messages.slice(this.#readPos);
753
+ }
754
+ GetMessagesSinceLastRead() {
755
+ const retVal = this.#messages.slice(this.#readPos);
756
+ this.#readPos = this.#messages.length;
757
+ return retVal;
758
+ }
759
+ ResetLog() {
760
+ this.#messages = [];
761
+ this.#readPos = 0;
762
+ }
763
+ ProcessTelemetry(telemetry) {
764
+ if (telemetry.val !== void 0) this.val = telemetry.val;
765
+ if (telemetry.Append !== void 0) this.Append(telemetry.Append);
766
+ if (telemetry.LogMessage !== void 0) this.LogMessage(telemetry.LogMessage);
767
+ if (telemetry.ResetLog !== void 0 && telemetry.ResetLog === true) this.ResetLog();
768
+ }
769
+ };
770
+ //#endregion
771
+ //#region src/instrumentation/instruments/instrumentTimerGauge.ts
772
+ var InstrumentTimerOptions = class extends InstrumentBaseOptions {
773
+ fromJSON;
774
+ initValue;
775
+ };
776
+ var InstrumentTimerTelemetry = class extends InstrumentBaseTelemetry {
777
+ val;
778
+ Pause;
779
+ Resume;
780
+ Reset;
781
+ };
782
+ var InstrumentTimerGauge = class extends InstrumentBase {
783
+ #start = 0;
784
+ #copy = false;
785
+ #pauseVal = 0;
786
+ constructor(options = {}) {
787
+ super(options);
788
+ if (typeof options.label === "undefined") this.label = "InstrumentTimerGauge";
789
+ else this.label = options.label;
790
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
791
+ else this.#copy = true;
792
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
793
+ enumerable: true,
794
+ get: () => GaugeTypes.INSTRUMENT_TIMER
795
+ });
796
+ if (this.#copy) this.DefineCopyProperties(["val"]);
797
+ else Object.defineProperty(this, "val", {
798
+ enumerable: true,
799
+ get: () => this.#GetVal(),
800
+ set: (value) => {
801
+ this.#SetVal(value);
802
+ }
803
+ });
804
+ if (typeof options.initValue !== "undefined") this.val = options.initValue;
805
+ if (typeof options.fromJSON !== "undefined") this.val = _cloneDeep(options.fromJSON).val;
806
+ this.Reset();
807
+ }
808
+ val = 0;
809
+ Pause() {
810
+ this.#pauseVal = this.val;
811
+ }
812
+ Resume() {
813
+ this.#pauseVal = 0;
814
+ }
815
+ Reset() {
816
+ this.#start = performance.now();
817
+ }
818
+ #GetVal() {
819
+ if (this.#pauseVal !== 0) return this.GetNumber(this.#pauseVal);
820
+ return this.GetNumber(performance.now() - this.#start);
821
+ }
822
+ #SetVal(updatedValue) {
823
+ this.#start = performance.now() - updatedValue;
824
+ }
825
+ get start() {
826
+ return this.#start;
827
+ }
828
+ ProcessTelemetry(telemetry) {
829
+ if (telemetry.val !== void 0) this.val = telemetry.val;
830
+ if (telemetry.Pause !== void 0 && telemetry.Pause === true) this.Pause();
831
+ if (telemetry.Resume !== void 0 && telemetry.Resume === true) this.Resume();
832
+ if (telemetry.Reset !== void 0 && telemetry.Reset === true) this.Reset();
833
+ }
834
+ };
835
+ //#endregion
836
+ //#region node_modules/timsort/build/timsort.js
837
+ var require_timsort$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
838
+ /****
839
+ * The MIT License
840
+ *
841
+ * Copyright (c) 2015 Marco Ziccardi
842
+ *
843
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
844
+ * of this software and associated documentation files (the "Software"), to deal
845
+ * in the Software without restriction, including without limitation the rights
846
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
847
+ * copies of the Software, and to permit persons to whom the Software is
848
+ * furnished to do so, subject to the following conditions:
849
+ *
850
+ * The above copyright notice and this permission notice shall be included in
851
+ * all copies or substantial portions of the Software.
852
+ *
853
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
854
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
855
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
856
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
857
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
858
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
859
+ * THE SOFTWARE.
860
+ *
861
+ ****/
862
+ (function(global, factory) {
863
+ if (typeof define === "function" && define.amd) define("timsort", ["exports"], factory);
864
+ else if (typeof exports !== "undefined") factory(exports);
865
+ else {
866
+ var mod = { exports: {} };
867
+ factory(mod.exports);
868
+ global.timsort = mod.exports;
869
+ }
870
+ })(exports, function(exports$1) {
871
+ "use strict";
872
+ exports$1.__esModule = true;
873
+ exports$1.sort = sort;
874
+ function _classCallCheck(instance, Constructor) {
875
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
876
+ }
877
+ var DEFAULT_MIN_MERGE = 32;
878
+ var DEFAULT_MIN_GALLOPING = 7;
879
+ var DEFAULT_TMP_STORAGE_LENGTH = 256;
880
+ var POWERS_OF_TEN = [
881
+ 1,
882
+ 10,
883
+ 100,
884
+ 1e3,
885
+ 1e4,
886
+ 1e5,
887
+ 1e6,
888
+ 1e7,
889
+ 1e8,
890
+ 1e9
891
+ ];
892
+ function log10(x) {
893
+ if (x < 1e5) {
894
+ if (x < 100) return x < 10 ? 0 : 1;
895
+ if (x < 1e4) return x < 1e3 ? 2 : 3;
896
+ return 4;
897
+ }
898
+ if (x < 1e7) return x < 1e6 ? 5 : 6;
899
+ if (x < 1e9) return x < 1e8 ? 7 : 8;
900
+ return 9;
901
+ }
902
+ function alphabeticalCompare(a, b) {
903
+ if (a === b) return 0;
904
+ if (~~a === a && ~~b === b) {
905
+ if (a === 0 || b === 0) return a < b ? -1 : 1;
906
+ if (a < 0 || b < 0) {
907
+ if (b >= 0) return -1;
908
+ if (a >= 0) return 1;
909
+ a = -a;
910
+ b = -b;
911
+ }
912
+ var al = log10(a);
913
+ var bl = log10(b);
914
+ var t = 0;
915
+ if (al < bl) {
916
+ a *= POWERS_OF_TEN[bl - al - 1];
917
+ b /= 10;
918
+ t = -1;
919
+ } else if (al > bl) {
920
+ b *= POWERS_OF_TEN[al - bl - 1];
921
+ a /= 10;
922
+ t = 1;
923
+ }
924
+ if (a === b) return t;
925
+ return a < b ? -1 : 1;
926
+ }
927
+ var aStr = String(a);
928
+ var bStr = String(b);
929
+ if (aStr === bStr) return 0;
930
+ return aStr < bStr ? -1 : 1;
931
+ }
932
+ function minRunLength(n) {
933
+ var r = 0;
934
+ while (n >= DEFAULT_MIN_MERGE) {
935
+ r |= n & 1;
936
+ n >>= 1;
937
+ }
938
+ return n + r;
939
+ }
940
+ function makeAscendingRun(array, lo, hi, compare) {
941
+ var runHi = lo + 1;
942
+ if (runHi === hi) return 1;
943
+ if (compare(array[runHi++], array[lo]) < 0) {
944
+ while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) runHi++;
945
+ reverseRun(array, lo, runHi);
946
+ } else while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) runHi++;
947
+ return runHi - lo;
948
+ }
949
+ function reverseRun(array, lo, hi) {
950
+ hi--;
951
+ while (lo < hi) {
952
+ var t = array[lo];
953
+ array[lo++] = array[hi];
954
+ array[hi--] = t;
955
+ }
956
+ }
957
+ function binaryInsertionSort(array, lo, hi, start, compare) {
958
+ if (start === lo) start++;
959
+ for (; start < hi; start++) {
960
+ var pivot = array[start];
961
+ var left = lo;
962
+ var right = start;
963
+ while (left < right) {
964
+ var mid = left + right >>> 1;
965
+ if (compare(pivot, array[mid]) < 0) right = mid;
966
+ else left = mid + 1;
967
+ }
968
+ var n = start - left;
969
+ switch (n) {
970
+ case 3: array[left + 3] = array[left + 2];
971
+ case 2: array[left + 2] = array[left + 1];
972
+ case 1:
973
+ array[left + 1] = array[left];
974
+ break;
975
+ default: while (n > 0) {
976
+ array[left + n] = array[left + n - 1];
977
+ n--;
978
+ }
979
+ }
980
+ array[left] = pivot;
981
+ }
982
+ }
983
+ function gallopLeft(value, array, start, length, hint, compare) {
984
+ var lastOffset = 0;
985
+ var maxOffset = 0;
986
+ var offset = 1;
987
+ if (compare(value, array[start + hint]) > 0) {
988
+ maxOffset = length - hint;
989
+ while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
990
+ lastOffset = offset;
991
+ offset = (offset << 1) + 1;
992
+ if (offset <= 0) offset = maxOffset;
993
+ }
994
+ if (offset > maxOffset) offset = maxOffset;
995
+ lastOffset += hint;
996
+ offset += hint;
997
+ } else {
998
+ maxOffset = hint + 1;
999
+ while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
1000
+ lastOffset = offset;
1001
+ offset = (offset << 1) + 1;
1002
+ if (offset <= 0) offset = maxOffset;
1003
+ }
1004
+ if (offset > maxOffset) offset = maxOffset;
1005
+ var tmp = lastOffset;
1006
+ lastOffset = hint - offset;
1007
+ offset = hint - tmp;
1008
+ }
1009
+ lastOffset++;
1010
+ while (lastOffset < offset) {
1011
+ var m = lastOffset + (offset - lastOffset >>> 1);
1012
+ if (compare(value, array[start + m]) > 0) lastOffset = m + 1;
1013
+ else offset = m;
1014
+ }
1015
+ return offset;
1016
+ }
1017
+ function gallopRight(value, array, start, length, hint, compare) {
1018
+ var lastOffset = 0;
1019
+ var maxOffset = 0;
1020
+ var offset = 1;
1021
+ if (compare(value, array[start + hint]) < 0) {
1022
+ maxOffset = hint + 1;
1023
+ while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
1024
+ lastOffset = offset;
1025
+ offset = (offset << 1) + 1;
1026
+ if (offset <= 0) offset = maxOffset;
1027
+ }
1028
+ if (offset > maxOffset) offset = maxOffset;
1029
+ var tmp = lastOffset;
1030
+ lastOffset = hint - offset;
1031
+ offset = hint - tmp;
1032
+ } else {
1033
+ maxOffset = length - hint;
1034
+ while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
1035
+ lastOffset = offset;
1036
+ offset = (offset << 1) + 1;
1037
+ if (offset <= 0) offset = maxOffset;
1038
+ }
1039
+ if (offset > maxOffset) offset = maxOffset;
1040
+ lastOffset += hint;
1041
+ offset += hint;
1042
+ }
1043
+ lastOffset++;
1044
+ while (lastOffset < offset) {
1045
+ var m = lastOffset + (offset - lastOffset >>> 1);
1046
+ if (compare(value, array[start + m]) < 0) offset = m;
1047
+ else lastOffset = m + 1;
1048
+ }
1049
+ return offset;
1050
+ }
1051
+ var TimSort = (function() {
1052
+ function TimSort(array, compare) {
1053
+ _classCallCheck(this, TimSort);
1054
+ this.array = null;
1055
+ this.compare = null;
1056
+ this.minGallop = DEFAULT_MIN_GALLOPING;
1057
+ this.length = 0;
1058
+ this.tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;
1059
+ this.stackLength = 0;
1060
+ this.runStart = null;
1061
+ this.runLength = null;
1062
+ this.stackSize = 0;
1063
+ this.array = array;
1064
+ this.compare = compare;
1065
+ this.length = array.length;
1066
+ if (this.length < 2 * DEFAULT_TMP_STORAGE_LENGTH) this.tmpStorageLength = this.length >>> 1;
1067
+ this.tmp = new Array(this.tmpStorageLength);
1068
+ this.stackLength = this.length < 120 ? 5 : this.length < 1542 ? 10 : this.length < 119151 ? 19 : 40;
1069
+ this.runStart = new Array(this.stackLength);
1070
+ this.runLength = new Array(this.stackLength);
1071
+ }
1072
+ TimSort.prototype.pushRun = function pushRun(runStart, runLength) {
1073
+ this.runStart[this.stackSize] = runStart;
1074
+ this.runLength[this.stackSize] = runLength;
1075
+ this.stackSize += 1;
1076
+ };
1077
+ TimSort.prototype.mergeRuns = function mergeRuns() {
1078
+ while (this.stackSize > 1) {
1079
+ var n = this.stackSize - 2;
1080
+ if (n >= 1 && this.runLength[n - 1] <= this.runLength[n] + this.runLength[n + 1] || n >= 2 && this.runLength[n - 2] <= this.runLength[n] + this.runLength[n - 1]) {
1081
+ if (this.runLength[n - 1] < this.runLength[n + 1]) n--;
1082
+ } else if (this.runLength[n] > this.runLength[n + 1]) break;
1083
+ this.mergeAt(n);
1084
+ }
1085
+ };
1086
+ TimSort.prototype.forceMergeRuns = function forceMergeRuns() {
1087
+ while (this.stackSize > 1) {
1088
+ var n = this.stackSize - 2;
1089
+ if (n > 0 && this.runLength[n - 1] < this.runLength[n + 1]) n--;
1090
+ this.mergeAt(n);
1091
+ }
1092
+ };
1093
+ TimSort.prototype.mergeAt = function mergeAt(i) {
1094
+ var compare = this.compare;
1095
+ var array = this.array;
1096
+ var start1 = this.runStart[i];
1097
+ var length1 = this.runLength[i];
1098
+ var start2 = this.runStart[i + 1];
1099
+ var length2 = this.runLength[i + 1];
1100
+ this.runLength[i] = length1 + length2;
1101
+ if (i === this.stackSize - 3) {
1102
+ this.runStart[i + 1] = this.runStart[i + 2];
1103
+ this.runLength[i + 1] = this.runLength[i + 2];
1104
+ }
1105
+ this.stackSize--;
1106
+ var k = gallopRight(array[start2], array, start1, length1, 0, compare);
1107
+ start1 += k;
1108
+ length1 -= k;
1109
+ if (length1 === 0) return;
1110
+ length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
1111
+ if (length2 === 0) return;
1112
+ if (length1 <= length2) this.mergeLow(start1, length1, start2, length2);
1113
+ else this.mergeHigh(start1, length1, start2, length2);
1114
+ };
1115
+ TimSort.prototype.mergeLow = function mergeLow(start1, length1, start2, length2) {
1116
+ var compare = this.compare;
1117
+ var array = this.array;
1118
+ var tmp = this.tmp;
1119
+ var i = 0;
1120
+ for (i = 0; i < length1; i++) tmp[i] = array[start1 + i];
1121
+ var cursor1 = 0;
1122
+ var cursor2 = start2;
1123
+ var dest = start1;
1124
+ array[dest++] = array[cursor2++];
1125
+ if (--length2 === 0) {
1126
+ for (i = 0; i < length1; i++) array[dest + i] = tmp[cursor1 + i];
1127
+ return;
1128
+ }
1129
+ if (length1 === 1) {
1130
+ for (i = 0; i < length2; i++) array[dest + i] = array[cursor2 + i];
1131
+ array[dest + length2] = tmp[cursor1];
1132
+ return;
1133
+ }
1134
+ var minGallop = this.minGallop;
1135
+ while (true) {
1136
+ var count1 = 0;
1137
+ var count2 = 0;
1138
+ var exit = false;
1139
+ do
1140
+ if (compare(array[cursor2], tmp[cursor1]) < 0) {
1141
+ array[dest++] = array[cursor2++];
1142
+ count2++;
1143
+ count1 = 0;
1144
+ if (--length2 === 0) {
1145
+ exit = true;
1146
+ break;
1147
+ }
1148
+ } else {
1149
+ array[dest++] = tmp[cursor1++];
1150
+ count1++;
1151
+ count2 = 0;
1152
+ if (--length1 === 1) {
1153
+ exit = true;
1154
+ break;
1155
+ }
1156
+ }
1157
+ while ((count1 | count2) < minGallop);
1158
+ if (exit) break;
1159
+ do {
1160
+ count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
1161
+ if (count1 !== 0) {
1162
+ for (i = 0; i < count1; i++) array[dest + i] = tmp[cursor1 + i];
1163
+ dest += count1;
1164
+ cursor1 += count1;
1165
+ length1 -= count1;
1166
+ if (length1 <= 1) {
1167
+ exit = true;
1168
+ break;
1169
+ }
1170
+ }
1171
+ array[dest++] = array[cursor2++];
1172
+ if (--length2 === 0) {
1173
+ exit = true;
1174
+ break;
1175
+ }
1176
+ count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
1177
+ if (count2 !== 0) {
1178
+ for (i = 0; i < count2; i++) array[dest + i] = array[cursor2 + i];
1179
+ dest += count2;
1180
+ cursor2 += count2;
1181
+ length2 -= count2;
1182
+ if (length2 === 0) {
1183
+ exit = true;
1184
+ break;
1185
+ }
1186
+ }
1187
+ array[dest++] = tmp[cursor1++];
1188
+ if (--length1 === 1) {
1189
+ exit = true;
1190
+ break;
1191
+ }
1192
+ minGallop--;
1193
+ } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
1194
+ if (exit) break;
1195
+ if (minGallop < 0) minGallop = 0;
1196
+ minGallop += 2;
1197
+ }
1198
+ this.minGallop = minGallop;
1199
+ if (minGallop < 1) this.minGallop = 1;
1200
+ if (length1 === 1) {
1201
+ for (i = 0; i < length2; i++) array[dest + i] = array[cursor2 + i];
1202
+ array[dest + length2] = tmp[cursor1];
1203
+ } else if (length1 === 0) throw new Error("mergeLow preconditions were not respected");
1204
+ else for (i = 0; i < length1; i++) array[dest + i] = tmp[cursor1 + i];
1205
+ };
1206
+ TimSort.prototype.mergeHigh = function mergeHigh(start1, length1, start2, length2) {
1207
+ var compare = this.compare;
1208
+ var array = this.array;
1209
+ var tmp = this.tmp;
1210
+ var i = 0;
1211
+ for (i = 0; i < length2; i++) tmp[i] = array[start2 + i];
1212
+ var cursor1 = start1 + length1 - 1;
1213
+ var cursor2 = length2 - 1;
1214
+ var dest = start2 + length2 - 1;
1215
+ var customCursor = 0;
1216
+ var customDest = 0;
1217
+ array[dest--] = array[cursor1--];
1218
+ if (--length1 === 0) {
1219
+ customCursor = dest - (length2 - 1);
1220
+ for (i = 0; i < length2; i++) array[customCursor + i] = tmp[i];
1221
+ return;
1222
+ }
1223
+ if (length2 === 1) {
1224
+ dest -= length1;
1225
+ cursor1 -= length1;
1226
+ customDest = dest + 1;
1227
+ customCursor = cursor1 + 1;
1228
+ for (i = length1 - 1; i >= 0; i--) array[customDest + i] = array[customCursor + i];
1229
+ array[dest] = tmp[cursor2];
1230
+ return;
1231
+ }
1232
+ var minGallop = this.minGallop;
1233
+ while (true) {
1234
+ var count1 = 0;
1235
+ var count2 = 0;
1236
+ var exit = false;
1237
+ do
1238
+ if (compare(tmp[cursor2], array[cursor1]) < 0) {
1239
+ array[dest--] = array[cursor1--];
1240
+ count1++;
1241
+ count2 = 0;
1242
+ if (--length1 === 0) {
1243
+ exit = true;
1244
+ break;
1245
+ }
1246
+ } else {
1247
+ array[dest--] = tmp[cursor2--];
1248
+ count2++;
1249
+ count1 = 0;
1250
+ if (--length2 === 1) {
1251
+ exit = true;
1252
+ break;
1253
+ }
1254
+ }
1255
+ while ((count1 | count2) < minGallop);
1256
+ if (exit) break;
1257
+ do {
1258
+ count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
1259
+ if (count1 !== 0) {
1260
+ dest -= count1;
1261
+ cursor1 -= count1;
1262
+ length1 -= count1;
1263
+ customDest = dest + 1;
1264
+ customCursor = cursor1 + 1;
1265
+ for (i = count1 - 1; i >= 0; i--) array[customDest + i] = array[customCursor + i];
1266
+ if (length1 === 0) {
1267
+ exit = true;
1268
+ break;
1269
+ }
1270
+ }
1271
+ array[dest--] = tmp[cursor2--];
1272
+ if (--length2 === 1) {
1273
+ exit = true;
1274
+ break;
1275
+ }
1276
+ count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
1277
+ if (count2 !== 0) {
1278
+ dest -= count2;
1279
+ cursor2 -= count2;
1280
+ length2 -= count2;
1281
+ customDest = dest + 1;
1282
+ customCursor = cursor2 + 1;
1283
+ for (i = 0; i < count2; i++) array[customDest + i] = tmp[customCursor + i];
1284
+ if (length2 <= 1) {
1285
+ exit = true;
1286
+ break;
1287
+ }
1288
+ }
1289
+ array[dest--] = array[cursor1--];
1290
+ if (--length1 === 0) {
1291
+ exit = true;
1292
+ break;
1293
+ }
1294
+ minGallop--;
1295
+ } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
1296
+ if (exit) break;
1297
+ if (minGallop < 0) minGallop = 0;
1298
+ minGallop += 2;
1299
+ }
1300
+ this.minGallop = minGallop;
1301
+ if (minGallop < 1) this.minGallop = 1;
1302
+ if (length2 === 1) {
1303
+ dest -= length1;
1304
+ cursor1 -= length1;
1305
+ customDest = dest + 1;
1306
+ customCursor = cursor1 + 1;
1307
+ for (i = length1 - 1; i >= 0; i--) array[customDest + i] = array[customCursor + i];
1308
+ array[dest] = tmp[cursor2];
1309
+ } else if (length2 === 0) throw new Error("mergeHigh preconditions were not respected");
1310
+ else {
1311
+ customCursor = dest - (length2 - 1);
1312
+ for (i = 0; i < length2; i++) array[customCursor + i] = tmp[i];
1313
+ }
1314
+ };
1315
+ return TimSort;
1316
+ })();
1317
+ function sort(array, compare, lo, hi) {
1318
+ if (!Array.isArray(array)) throw new TypeError("Can only sort arrays");
1319
+ if (!compare) compare = alphabeticalCompare;
1320
+ else if (typeof compare !== "function") {
1321
+ hi = lo;
1322
+ lo = compare;
1323
+ compare = alphabeticalCompare;
1324
+ }
1325
+ if (!lo) lo = 0;
1326
+ if (!hi) hi = array.length;
1327
+ var remaining = hi - lo;
1328
+ if (remaining < 2) return;
1329
+ var runLength = 0;
1330
+ if (remaining < DEFAULT_MIN_MERGE) {
1331
+ runLength = makeAscendingRun(array, lo, hi, compare);
1332
+ binaryInsertionSort(array, lo, hi, lo + runLength, compare);
1333
+ return;
1334
+ }
1335
+ var ts = new TimSort(array, compare);
1336
+ var minRun = minRunLength(remaining);
1337
+ do {
1338
+ runLength = makeAscendingRun(array, lo, hi, compare);
1339
+ if (runLength < minRun) {
1340
+ var force = remaining;
1341
+ if (force > minRun) force = minRun;
1342
+ binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
1343
+ runLength = force;
1344
+ }
1345
+ ts.pushRun(lo, runLength);
1346
+ ts.mergeRuns();
1347
+ remaining -= runLength;
1348
+ lo += runLength;
1349
+ } while (remaining !== 0);
1350
+ ts.forceMergeRuns();
1351
+ }
1352
+ });
1353
+ }));
1354
+ //#endregion
1355
+ //#region node_modules/timsort/index.js
1356
+ var require_timsort = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1357
+ module.exports = require_timsort$1();
1358
+ }));
1359
+ //#endregion
1360
+ //#region node_modules/percentile/lib/index.js
1361
+ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1362
+ /**
1363
+ @typedef {(Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array)} TypedArray
1364
+ */
1365
+ /**
1366
+ * Error message for a case when percentile is less than 0.
1367
+ *
1368
+ * @param {Number} p
1369
+ *
1370
+ * @return {String}
1371
+ */
1372
+ function lessThanZeroError(p) {
1373
+ return "Expect percentile to be >= 0 but given \"" + p + "\" and its type is \"" + typeof p + "\".";
1374
+ }
1375
+ /**
1376
+ * Error message for a case when percentile is greater than 100.
1377
+ *
1378
+ * @param {Number} p
1379
+ *
1380
+ * @return {String}
1381
+ */
1382
+ function greaterThanHundredError(p) {
1383
+ return "Expect percentile to be <= 100 but given \"" + p + "\" and its type is \"" + typeof p + "\".";
1384
+ }
1385
+ /**
1386
+ * Error message for a case when percentile is not a number (NaN).
1387
+ *
1388
+ * @param {Number} p
1389
+ *
1390
+ * @return {String}
1391
+ */
1392
+ function nanError(p) {
1393
+ return "Expect percentile to be a number but given \"" + p + "\" and its type is \"" + typeof p + "\".";
1394
+ }
1395
+ /**
1396
+ * Checks that a list of percentiles are all numbers and they lie in range 0..100.
1397
+ *
1398
+ * @param {Array<Number>} ps - percentiles to calculate
1399
+ *
1400
+ * @return {Array} List of errors
1401
+ */
1402
+ function validateInput(ps) {
1403
+ return ps.reduce(function(errors, p) {
1404
+ if (isNaN(Number(p))) errors.push(nanError(p));
1405
+ else if (p < 0) errors.push(lessThanZeroError(p));
1406
+ else if (p > 100) errors.push(greaterThanHundredError(p));
1407
+ return errors;
1408
+ }, []);
1409
+ }
1410
+ /**
1411
+ * Get percentile value from an array.
1412
+ *
1413
+ * @param {Number} p - percentile
1414
+ * @param {Array|TypedArray} list - list of values
1415
+ *
1416
+ * @return {*}
1417
+ */
1418
+ function getPsValue(p, list) {
1419
+ if (p === 0) return list[0];
1420
+ return list[Math.ceil(list.length * (p / 100)) - 1];
1421
+ }
1422
+ /**
1423
+ * Calculate percentile for given array of values.
1424
+ *
1425
+ * @template T
1426
+ * @param {Number|Array<Number>} pOrPs - percentile or a list of percentiles
1427
+ * @param {Array<T>|Array<Number>|TypedArray} list - array of values
1428
+ * @param {function(T): Number} [fn] - optional function to extract a value from an array item
1429
+ *
1430
+ * @return {Number|T|Array<Number>|Array<T>}
1431
+ */
1432
+ function percentile(pOrPs, list, fn) {
1433
+ var ps = Array.isArray(pOrPs) ? pOrPs : [pOrPs];
1434
+ var validationErrors = validateInput(ps);
1435
+ if (validationErrors.length) throw new Error(validationErrors.join(" "));
1436
+ list = list.slice().sort(function(a, b) {
1437
+ if (fn) {
1438
+ a = fn(a);
1439
+ b = fn(b);
1440
+ }
1441
+ a = Number.isNaN(a) ? Number.NEGATIVE_INFINITY : a;
1442
+ b = Number.isNaN(b) ? Number.NEGATIVE_INFINITY : b;
1443
+ if (a > b) return 1;
1444
+ if (a < b) return -1;
1445
+ return 0;
1446
+ });
1447
+ if (ps.length === 1) return getPsValue(ps[0], list);
1448
+ return ps.map(function(p) {
1449
+ return getPsValue(p, list);
1450
+ });
1451
+ }
1452
+ module.exports = percentile;
1453
+ }));
1454
+ //#endregion
1455
+ //#region src/instrumentation/instruments/instrumentGauge.ts
1456
+ var import_timsort = /* @__PURE__ */ __toESM(require_timsort());
1457
+ var import_lib = /* @__PURE__ */ __toESM(require_lib());
1458
+ var InstrumentGaugeOptions = class extends InstrumentBaseOptions {
1459
+ interval;
1460
+ sampleSize;
1461
+ fromJSON;
1462
+ initValue;
1463
+ };
1464
+ var InstrumentGaugeTelemetry = class extends InstrumentBaseTelemetry {
1465
+ val;
1466
+ Inc;
1467
+ Dec;
1468
+ };
1469
+ var InstrumentGauge = class extends InstrumentBase {
1470
+ #val = 0;
1471
+ #maxval = null;
1472
+ #lastObservedValue = 0;
1473
+ #timeSeriesList = [];
1474
+ #maxSampleSize = 0;
1475
+ #timerInterval = 0;
1476
+ #observer = null;
1477
+ #min = null;
1478
+ #max = 0;
1479
+ #observations = 0;
1480
+ #total = 0;
1481
+ #copy = false;
1482
+ constructor(options = {}) {
1483
+ super(options);
1484
+ if (!options.label) this.label = "InstrumentGauge";
1485
+ else this.label = options.label;
1486
+ if (typeof options.interval === "undefined") this.#timerInterval = 0;
1487
+ else this.#timerInterval = options.interval;
1488
+ if (typeof options.sampleSize === "undefined") this.#maxSampleSize = 600;
1489
+ else this.#maxSampleSize = options.sampleSize;
1490
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
1491
+ else this.#copy = true;
1492
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
1493
+ enumerable: true,
1494
+ get: () => GaugeTypes.INSTRUMENT_GAUGE
1495
+ });
1496
+ if (this.#copy) this.DefineCopyProperties([
1497
+ "val",
1498
+ "min",
1499
+ "max",
1500
+ "avg",
1501
+ "percentile"
1502
+ ]);
1503
+ else {
1504
+ Object.defineProperty(this, "val", {
1505
+ enumerable: true,
1506
+ get: () => this.#GetVal(),
1507
+ set: (value) => {
1508
+ this.#SetVal(value);
1509
+ }
1510
+ });
1511
+ if (this.#timerInterval > 0) {
1512
+ Object.defineProperty(this, "percentile", {
1513
+ enumerable: true,
1514
+ get: () => this.#GetPercentileData()
1515
+ });
1516
+ this._StartTimer();
1517
+ }
1518
+ }
1519
+ if (typeof options.initValue !== "undefined") this.val = options.initValue;
1520
+ if (typeof options.fromJSON !== "undefined") {
1521
+ const result = _cloneDeep(options.fromJSON);
1522
+ this.val = result.val;
1523
+ if (result.percentile) this.percentile = result.percentile;
1524
+ if (result.min) this.min = result.min;
1525
+ if (result.max) this.max = result.max;
1526
+ if (result.avg) this.avg = result.avg;
1527
+ }
1528
+ }
1529
+ percentile;
1530
+ min;
1531
+ max;
1532
+ avg;
1533
+ val = 0;
1534
+ WithInitVal(initVal) {
1535
+ this.val = initVal;
1536
+ return this;
1537
+ }
1538
+ WithMin() {
1539
+ Object.defineProperty(this, "min", {
1540
+ enumerable: true,
1541
+ get: () => this.#GetMin()
1542
+ });
1543
+ return this;
1544
+ }
1545
+ WithMax() {
1546
+ Object.defineProperty(this, "max", {
1547
+ enumerable: true,
1548
+ get: () => this.#GetMax()
1549
+ });
1550
+ return this;
1551
+ }
1552
+ WithAverage() {
1553
+ Object.defineProperty(this, "avg", {
1554
+ enumerable: true,
1555
+ get: () => this.#GetAverage()
1556
+ });
1557
+ return this;
1558
+ }
1559
+ _StartTimer() {
1560
+ if (this.#timerInterval > 0) {
1561
+ this.#timeSeriesList = [];
1562
+ this.#observer = setInterval(() => {
1563
+ if (this.#timeSeriesList.length > this.#maxSampleSize) this.#timeSeriesList.shift();
1564
+ const maxval = this.#GetAndResetMaxVal();
1565
+ this.#timeSeriesList.push(maxval);
1566
+ }, this.#timerInterval);
1567
+ if (isNode) this.#observer.unref();
1568
+ } else throw new Error(`Unable to StartTimer for this instrument. The interval is set to <= 0.`);
1569
+ }
1570
+ StopTimer() {
1571
+ if (this.#observer) {
1572
+ clearTimeout(this.#observer);
1573
+ this.#observer = null;
1574
+ this.#timeSeriesList = [];
1575
+ }
1576
+ }
1577
+ /**
1578
+ * If the gauge is being monitored as part of a time series, get the most recent recorded value (max value) from within the time interval
1579
+ * otherwise, just return the current instant value.
1580
+ */
1581
+ #GetVal() {
1582
+ if (this.#timerInterval > 0 && this.#observer !== null) if (this.#maxval === null) return this.GetNumber(this.#lastObservedValue);
1583
+ else return this.GetNumber(this.#maxval);
1584
+ return this.GetNumber(this.#val);
1585
+ }
1586
+ #SetVal(updatedValue) {
1587
+ this.#val = updatedValue;
1588
+ this.#observations++;
1589
+ this.#total += updatedValue;
1590
+ if (this.#val > this.#max) this.#max = this.#val;
1591
+ if (this.#min !== null) {
1592
+ if (this.#val < this.#min) this.#min = this.#val;
1593
+ } else this.#min = this.#val;
1594
+ if (this.#timerInterval > 0) {
1595
+ this.#lastObservedValue = updatedValue;
1596
+ if (this.#maxval === null) this.#maxval = this.#val;
1597
+ else if (this.#val > this.#maxval) this.#maxval = this.#val;
1598
+ }
1599
+ }
1600
+ #GetMin() {
1601
+ if (this.#min !== null) return this.#min;
1602
+ return 0;
1603
+ }
1604
+ #GetMax() {
1605
+ return this.#max;
1606
+ }
1607
+ #GetAverage() {
1608
+ if (this.#observations > 0) return this.#total / this.#observations;
1609
+ return 0;
1610
+ }
1611
+ Reset() {
1612
+ this.StopTimer();
1613
+ this.#maxval = 0;
1614
+ this.#lastObservedValue = 0;
1615
+ this.#val = 0;
1616
+ this.#min = null;
1617
+ this.#max = 0;
1618
+ this.#observations = 0;
1619
+ this.#total = 0;
1620
+ if (this.#timerInterval > 0) this._StartTimer();
1621
+ }
1622
+ #GetAndResetMaxVal() {
1623
+ if (this.#maxval === null) return this.#lastObservedValue;
1624
+ const retVal = this.#maxval;
1625
+ this.#maxval = null;
1626
+ return retVal;
1627
+ }
1628
+ Inc(incVal = 1) {
1629
+ this.#SetVal(this.#val + incVal);
1630
+ }
1631
+ Dec(decVal = 1) {
1632
+ this.#SetVal(this.#val - decVal);
1633
+ }
1634
+ #NumberCompare(a, b) {
1635
+ return a - b;
1636
+ }
1637
+ #GetPercentileData() {
1638
+ const sortedList = this.#timeSeriesList.slice(0);
1639
+ import_timsort.sort(sortedList, this.#NumberCompare);
1640
+ return (0, import_lib.default)([
1641
+ 50,
1642
+ 80,
1643
+ 90,
1644
+ 95,
1645
+ 99,
1646
+ 99.95
1647
+ ], sortedList);
1648
+ }
1649
+ ProcessTelemetry(telemetry) {
1650
+ if (telemetry.Inc !== void 0) this.Inc(telemetry.Inc);
1651
+ if (telemetry.Dec !== void 0) this.Dec(telemetry.Dec);
1652
+ if (telemetry.val !== void 0) this.val = telemetry.val;
1653
+ }
1654
+ };
1655
+ //#endregion
1656
+ //#region src/instrumentation/instruments/instrumentObject.ts
1657
+ var InstrumentObjectOptions = class extends InstrumentBaseOptions {
1658
+ fromJSON;
1659
+ initValue;
1660
+ };
1661
+ var InstrumentObjectTelemetry = class extends InstrumentBaseTelemetry {
1662
+ val;
1663
+ };
1664
+ var InstrumentObject = class extends InstrumentBase {
1665
+ #val = {};
1666
+ #copy = false;
1667
+ constructor(options = {}) {
1668
+ super(options);
1669
+ if (typeof options.label === "undefined") this.label = "InstrumentObject";
1670
+ else this.label = options.label;
1671
+ if (typeof options.fromJSON === "undefined") this.#copy = false;
1672
+ else this.#copy = true;
1673
+ Object.defineProperty(this, GaugeTypes.GAUGE_TYPE, {
1674
+ enumerable: true,
1675
+ get: () => GaugeTypes.INSTRUMENT_OBJECT
1676
+ });
1677
+ if (this.#copy) this.DefineCopyProperties(["val"]);
1678
+ else Object.defineProperty(this, "val", {
1679
+ enumerable: true,
1680
+ get: () => this.#GetVal(),
1681
+ set: (value) => {
1682
+ this.#SetVal(value);
1683
+ }
1684
+ });
1685
+ if (typeof options.initValue !== "undefined") this.val = options.initValue;
1686
+ else this.val = {};
1687
+ if (typeof options.fromJSON !== "undefined") this.val = _cloneDeep(options.fromJSON).val;
1688
+ }
1689
+ val;
1690
+ WithInitVal(initVal) {
1691
+ this.val = initVal;
1692
+ return this;
1693
+ }
1694
+ #GetVal() {
1695
+ return this.#val;
1696
+ }
1697
+ #SetVal(updatedValue) {
1698
+ this.#val = updatedValue;
1699
+ }
1700
+ ProcessTelemetry(telemetry) {
1701
+ if (telemetry.val !== void 0) this.val = telemetry.val;
1702
+ }
1703
+ };
1704
+ //#endregion
1705
+ //#region src/instrumentation/instrumentUtils.ts
2087
1706
  function CreateInstrument(sourceInstrument) {
2088
- switch (sourceInstrument[GaugeTypes.GAUGE_TYPE]) {
2089
- case GaugeTypes.INSTRUMENT_GAUGE:
2090
- return new InstrumentGauge({ fromJSON: sourceInstrument });
2091
- case GaugeTypes.INSTRUMENT_VELOCITY:
2092
- return new InstrumentVelocity({ fromJSON: sourceInstrument });
2093
- case GaugeTypes.INSTRUMENT_HISTOGRAM:
2094
- return new InstrumentHistogram({ fromJSON: sourceInstrument });
2095
- case GaugeTypes.INSTRUMENT_LOG:
2096
- return new InstrumentLog({ fromJSON: sourceInstrument });
2097
- case GaugeTypes.INSTRUMENT_TIMER:
2098
- return new InstrumentTimerGauge({ fromJSON: sourceInstrument });
2099
- case GaugeTypes.INSTRUMENT_OBJECT:
2100
- return new InstrumentObject({ fromJSON: sourceInstrument });
2101
- }
2102
- throw new Error(`Cannot create instrument from type: [${sourceInstrument[GaugeTypes.GAUGE_TYPE]}]`);
1707
+ switch (sourceInstrument[GaugeTypes.GAUGE_TYPE]) {
1708
+ case GaugeTypes.INSTRUMENT_GAUGE: return new InstrumentGauge({ fromJSON: sourceInstrument });
1709
+ case GaugeTypes.INSTRUMENT_VELOCITY: return new InstrumentVelocity({ fromJSON: sourceInstrument });
1710
+ case GaugeTypes.INSTRUMENT_HISTOGRAM: return new InstrumentHistogram({ fromJSON: sourceInstrument });
1711
+ case GaugeTypes.INSTRUMENT_LOG: return new InstrumentLog({ fromJSON: sourceInstrument });
1712
+ case GaugeTypes.INSTRUMENT_TIMER: return new InstrumentTimerGauge({ fromJSON: sourceInstrument });
1713
+ case GaugeTypes.INSTRUMENT_OBJECT: return new InstrumentObject({ fromJSON: sourceInstrument });
1714
+ }
1715
+ throw new Error(`Cannot create instrument from type: [${sourceInstrument[GaugeTypes.GAUGE_TYPE]}]`);
2103
1716
  }
2104
1717
  function GetInstrumentName(gauge) {
2105
- switch (gauge) {
2106
- case Gauge.ACTIVE_REQUEST_GAUGE:
2107
- return "Active Requests";
2108
- case Gauge.AUTHENTICATION_COUNT_GAUGE:
2109
- return "Authentication Count";
2110
- case Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE:
2111
- return "Authentication Error Count";
2112
- case Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE:
2113
- return "Authentication Retry Count";
2114
- case Gauge.CONNECTION_POOL_IDLE_GAUGE:
2115
- return "Connection Pool Idle";
2116
- case Gauge.CONNECTION_POOL_TOTAL_GAUGE:
2117
- return "Connection Pool Total";
2118
- case Gauge.CONNECTION_POOL_WAITING_GAUGE:
2119
- return "Connection Pool Waiting";
2120
- case Gauge.CPU_LOAD_GAUGE:
2121
- return "CPU Load";
2122
- case Gauge.CPU_SYSTEM_LOAD_GAUGE:
2123
- return "CPU SYstem Load";
2124
- case Gauge.DURATION_GAUGE:
2125
- return "Duration";
2126
- case Gauge.DURATION_HISTOGRAM_GAUGE:
2127
- return "Diration Histogram";
2128
- case Gauge.ERROR_COUNT_GAUGE:
2129
- return "Errors";
2130
- case Gauge.LATENCY_GAUGE:
2131
- return "Latency";
2132
- case Gauge.LATENCY_HISTOGRAM_GAUGE:
2133
- return "Latency Histogram";
2134
- case Gauge.LOGGER:
2135
- return "Logger";
2136
- case Gauge.LOGGER_COPY:
2137
- return "_Logger";
2138
- case Gauge.NETWORK_RX_GAUGE:
2139
- return "Network Receive";
2140
- case Gauge.NETWORK_TX_GAUGE:
2141
- return "Network Transmit";
2142
- case Gauge.REQUEST_COUNT_GAUGE:
2143
- return "Requests";
2144
- case Gauge.RETRY_COUNT_GAUGE:
2145
- return "Retries";
2146
- case Gauge.TIMER_GAUGE:
2147
- return "Timer";
2148
- case Gauge.VELOCITY_GAUGE:
2149
- return "Velocity";
2150
- case Gauge.CONNECTION_COUNT_GAUGE:
2151
- return "TCP Connection";
2152
- case Gauge.OBJECT_GAUGE:
2153
- return "Object";
2154
- case Gauge.CORE_COUNT_GAUGE:
2155
- return "Core Count";
2156
- default:
2157
- return "Unknown";
2158
- }
1718
+ switch (gauge) {
1719
+ case Gauge.ACTIVE_REQUEST_GAUGE: return "Active Requests";
1720
+ case Gauge.AUTHENTICATION_COUNT_GAUGE: return "Authentication Count";
1721
+ case Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE: return "Authentication Error Count";
1722
+ case Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE: return "Authentication Retry Count";
1723
+ case Gauge.CONNECTION_POOL_IDLE_GAUGE: return "Connection Pool Idle";
1724
+ case Gauge.CONNECTION_POOL_TOTAL_GAUGE: return "Connection Pool Total";
1725
+ case Gauge.CONNECTION_POOL_WAITING_GAUGE: return "Connection Pool Waiting";
1726
+ case Gauge.CPU_LOAD_GAUGE: return "CPU Load";
1727
+ case Gauge.CPU_SYSTEM_LOAD_GAUGE: return "CPU SYstem Load";
1728
+ case Gauge.DURATION_GAUGE: return "Duration";
1729
+ case Gauge.DURATION_HISTOGRAM_GAUGE: return "Diration Histogram";
1730
+ case Gauge.ERROR_COUNT_GAUGE: return "Errors";
1731
+ case Gauge.LATENCY_GAUGE: return "Latency";
1732
+ case Gauge.LATENCY_HISTOGRAM_GAUGE: return "Latency Histogram";
1733
+ case Gauge.LOGGER: return "Logger";
1734
+ case Gauge.LOGGER_COPY: return "_Logger";
1735
+ case Gauge.NETWORK_RX_GAUGE: return "Network Receive";
1736
+ case Gauge.NETWORK_TX_GAUGE: return "Network Transmit";
1737
+ case Gauge.REQUEST_COUNT_GAUGE: return "Requests";
1738
+ case Gauge.RETRY_COUNT_GAUGE: return "Retries";
1739
+ case Gauge.TIMER_GAUGE: return "Timer";
1740
+ case Gauge.VELOCITY_GAUGE: return "Velocity";
1741
+ case Gauge.CONNECTION_COUNT_GAUGE: return "TCP Connection";
1742
+ case Gauge.OBJECT_GAUGE: return "Object";
1743
+ case Gauge.CORE_COUNT_GAUGE: return "Core Count";
1744
+ default: return "Unknown";
1745
+ }
2159
1746
  }
2160
1747
  function StopInstruments(instruments) {
2161
- if (instruments) {
2162
- if (Array.isArray(instruments)) {
2163
- instruments.forEach((instrument) => {
2164
- if (instrument.StopTimer) {
2165
- instrument.StopTimer();
2166
- }
2167
- });
2168
- } else {
2169
- for (const [, value] of Object.entries(instruments)) {
2170
- if (value.StopTimer) {
2171
- value.StopTimer();
2172
- }
2173
- }
2174
- }
2175
- }
1748
+ if (instruments) {
1749
+ if (Array.isArray(instruments)) instruments.forEach((instrument) => {
1750
+ if (instrument.StopTimer) instrument.StopTimer();
1751
+ });
1752
+ else for (const [, value] of Object.entries(instruments)) if (value.StopTimer) value.StopTimer();
1753
+ }
2176
1754
  }
2177
- export {
2178
- CreateInstrument,
2179
- Gauge,
2180
- GaugeTypes,
2181
- GetInstrumentName,
2182
- HistogramDataElementPos,
2183
- InstrumentBase,
2184
- InstrumentBaseOptions,
2185
- InstrumentBaseTelemetry,
2186
- InstrumentGauge,
2187
- InstrumentGaugeOptions,
2188
- InstrumentGaugeTelemetry,
2189
- InstrumentHistogram,
2190
- InstrumentHistogramOptions,
2191
- InstrumentHistogramTelemetry,
2192
- InstrumentLog,
2193
- InstrumentLogOptions,
2194
- InstrumentLogTelemetry,
2195
- InstrumentObject,
2196
- InstrumentObjectOptions,
2197
- InstrumentObjectTelemetry,
2198
- InstrumentTimerGauge,
2199
- InstrumentTimerOptions,
2200
- InstrumentTimerTelemetry,
2201
- InstrumentVelocity,
2202
- InstrumentVelocityOptions,
2203
- InstrumentVelocityTelemetry,
2204
- StopInstruments
2205
- };
2206
- //# sourceMappingURL=index.mjs.map
1755
+ //#endregion
1756
+ export { CreateInstrument, Gauge, GaugeTypes, GetInstrumentName, HistogramDataElementPos, InstrumentBase, InstrumentBaseOptions, InstrumentBaseTelemetry, InstrumentGauge, InstrumentGaugeOptions, InstrumentGaugeTelemetry, InstrumentHistogram, InstrumentHistogramOptions, InstrumentHistogramTelemetry, InstrumentLog, InstrumentLogOptions, InstrumentLogTelemetry, InstrumentObject, InstrumentObjectOptions, InstrumentObjectTelemetry, InstrumentTimerGauge, InstrumentTimerOptions, InstrumentTimerTelemetry, InstrumentVelocity, InstrumentVelocityOptions, InstrumentVelocityTelemetry, StopInstruments };
1757
+
1758
+ //# sourceMappingURL=index.mjs.map