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