@oino-ts/common 0.21.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +183 -0
  2. package/dist/cjs/OINOApi.js +322 -0
  3. package/dist/cjs/OINOBenchmark.js +3 -4
  4. package/dist/cjs/OINOConfig.js +104 -0
  5. package/dist/cjs/OINOConstants.js +42 -0
  6. package/dist/cjs/OINODataField.js +346 -0
  7. package/dist/cjs/OINODataModel.js +182 -0
  8. package/dist/cjs/OINODataSource.js +165 -0
  9. package/dist/cjs/OINOFormatter.js +6 -5
  10. package/dist/cjs/OINOHtmlTemplate.js +21 -18
  11. package/dist/cjs/OINOModelSet.js +333 -0
  12. package/dist/cjs/OINOParser.js +448 -0
  13. package/dist/cjs/OINOQueryParams.js +434 -0
  14. package/dist/cjs/OINORequest.js +21 -13
  15. package/dist/cjs/OINOResult.js +13 -12
  16. package/dist/cjs/OINOStr.js +11 -11
  17. package/dist/cjs/OINOSwagger.js +205 -0
  18. package/dist/cjs/index.js +57 -39
  19. package/dist/esm/OINOApi.js +315 -0
  20. package/dist/esm/OINOBenchmark.js +3 -4
  21. package/dist/esm/OINOConfig.js +100 -0
  22. package/dist/esm/OINOConstants.js +39 -0
  23. package/dist/esm/OINODataField.js +337 -0
  24. package/dist/esm/OINODataModel.js +178 -0
  25. package/dist/esm/OINODataSource.js +159 -0
  26. package/dist/esm/OINOFormatter.js +2 -1
  27. package/dist/esm/OINOHtmlTemplate.js +4 -1
  28. package/dist/esm/OINOModelSet.js +329 -0
  29. package/dist/esm/OINOParser.js +444 -0
  30. package/dist/esm/OINOQueryParams.js +426 -0
  31. package/dist/esm/OINORequest.js +9 -1
  32. package/dist/esm/OINOResult.js +2 -1
  33. package/dist/esm/OINOStr.js +1 -1
  34. package/dist/esm/OINOSwagger.js +201 -0
  35. package/dist/esm/index.js +14 -32
  36. package/dist/types/OINOApi.d.ts +191 -0
  37. package/dist/types/OINOBenchmark.d.ts +1 -1
  38. package/dist/types/OINOConfig.d.ts +63 -0
  39. package/dist/types/OINOConstants.d.ts +51 -0
  40. package/dist/types/OINODataField.d.ts +209 -0
  41. package/dist/types/OINODataModel.d.ts +78 -0
  42. package/dist/types/OINODataSource.d.ts +184 -0
  43. package/dist/types/OINOHtmlTemplate.d.ts +1 -1
  44. package/dist/types/OINOModelSet.d.ts +64 -0
  45. package/dist/types/OINOParser.d.ts +42 -0
  46. package/dist/types/OINOQueryParams.d.ts +270 -0
  47. package/dist/types/OINORequest.d.ts +4 -1
  48. package/dist/types/OINOResult.d.ts +1 -1
  49. package/dist/types/OINOStr.d.ts +1 -1
  50. package/dist/types/OINOSwagger.d.ts +25 -0
  51. package/dist/types/index.d.ts +14 -31
  52. package/package.json +32 -32
  53. package/src/OINOApi.ts +429 -0
  54. package/src/OINOBenchmark.ts +323 -324
  55. package/src/OINOConfig.ts +113 -0
  56. package/src/OINOConstants.ts +59 -0
  57. package/src/OINODataField.ts +371 -0
  58. package/src/OINODataModel.ts +187 -0
  59. package/src/OINODataSource.ts +280 -0
  60. package/src/OINOFormatter.ts +166 -165
  61. package/src/OINOHeaders.ts +51 -51
  62. package/src/OINOHtmlTemplate.test.ts +114 -114
  63. package/src/OINOHtmlTemplate.ts +225 -222
  64. package/src/OINOLog.ts +292 -292
  65. package/src/OINOModelSet.ts +359 -0
  66. package/src/OINOParser.ts +441 -0
  67. package/src/OINOQueryParams.ts +449 -0
  68. package/src/OINORequest.ts +204 -196
  69. package/src/OINOResult.ts +331 -330
  70. package/src/OINOStr.ts +254 -254
  71. package/src/OINOSwagger.ts +213 -0
  72. package/src/index.ts +18 -38
@@ -1,324 +1,323 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
-
7
- /**
8
- * Static class for benchmarking functions.
9
- *
10
- */
11
- export abstract class OINOBenchmark {
12
-
13
- protected static _instance:OINOBenchmark
14
- protected static _enabled:Record<string, boolean> = {}
15
- protected static _healthBenchmarks: string[] = []
16
- protected static _healthLateRatio: number = 0
17
-
18
- /**
19
- * Create a new OINOBenchmark instance.
20
- *
21
- * @param enabledModules array of those benchmarks that are enabled
22
- */
23
- constructor(enabledModules:string[] = []) {
24
- OINOBenchmark.setEnabled(enabledModules)
25
- }
26
-
27
- /**
28
- * Set active benchmarking instance.
29
- *
30
- * @param instance OINOBenchmark instance
31
- *
32
- */
33
- static setInstance(instance: OINOBenchmark) {
34
- if (instance) {
35
- OINOBenchmark._instance = instance
36
- }
37
- }
38
-
39
- /**
40
- * Get active benchmarking instance.
41
- *
42
- */
43
- static getInstance(): OINOBenchmark {
44
- return OINOBenchmark._instance
45
- }
46
-
47
- /**
48
- * Add benchmark to be used for service health monitoring.
49
- * @param module of the benchmark
50
- * @param method of the benchmark
51
- */
52
- static addHealthBenchmark(module: string, method: string): void {
53
- const name = module + "." + method
54
- if (!OINOBenchmark._healthBenchmarks.includes(name)) {
55
- OINOBenchmark._healthBenchmarks.push(name)
56
- }
57
- }
58
-
59
- /**
60
- * Remove benchmark from being used for service health monitoring.
61
- * @param module of the benchmark
62
- * @param method of the benchmark
63
- */
64
- static removeHealthBenchmark(module: string, method: string): void {
65
- const name = module + "." + method
66
- const index = OINOBenchmark._healthBenchmarks.indexOf(name)
67
- if (index !== -1) {
68
- OINOBenchmark._healthBenchmarks.splice(index, 1)
69
- }
70
- }
71
-
72
- /**
73
- * Set late ratio threshold for health monitoring. If a request takes this many times longer than the average duration, it is considered late and a health failure.
74
- * @param lateRatio of health benchmarks, e.g. 2.0 means requests that take 2 times longer than the average
75
- */
76
- static setHealthLateRatio(lateRatio: number): void {
77
- OINOBenchmark._healthLateRatio = lateRatio
78
- }
79
-
80
- /**
81
- * Get service health based on the configured health benchmark.
82
- *
83
- * @returns service health as 0-1
84
- */
85
- static getHealth(): number {
86
- return OINOBenchmark._instance? OINOBenchmark._instance._getHealth() : 1
87
- }
88
-
89
- protected abstract _getHealth(): number
90
-
91
- protected abstract _reset():void
92
- /**
93
- * Reset benchmark data (but not what is enabled).
94
- *
95
- */
96
- static reset():void {
97
- OINOBenchmark._instance?._reset()
98
- }
99
-
100
- /**
101
- * Set benchmark names that are enabled.
102
- *
103
- * @param modules array of those benchmarks that are enabled
104
- */
105
- static setEnabled(modules:string[]):void {
106
- OINOBenchmark._enabled = {}
107
- modules.forEach(module_name => {
108
- this._enabled[module_name] = true
109
- });
110
- }
111
-
112
- protected abstract _startMetric(module:string, method:string):void
113
- /**
114
- * Start benchmark timing.
115
- *
116
- * @param module of the benchmark
117
- * @param method of the benchmark
118
- */
119
- static startMetric(module:string, method:string):void {
120
- OINOBenchmark._instance?._startMetric(module, method)
121
- }
122
-
123
- protected abstract _endMetric(module:string, method:string, success:boolean):void
124
- /**
125
- * Complete benchmark timing
126
- *
127
- * @param module of the benchmark
128
- * @param method of the benchmark
129
- * @param success indicates if the benchmark was successful
130
- */
131
- static endMetric(module:string, method:string, success:boolean = true):void {
132
- OINOBenchmark._instance?._endMetric(module, method, success)
133
- }
134
-
135
- protected abstract _getMetric(module:string, method:string):number
136
- /**
137
- * Get given benchmark data.
138
- *
139
- * @param module of the benchmark
140
- * @param method of the benchmark
141
- *
142
- */
143
- static getMetric(module:string, method:string):number {
144
- return OINOBenchmark._instance?._getMetric(module, method)
145
- }
146
-
147
- protected abstract _getMetrics():Record<string, number>
148
- /**
149
- * Get all benchmark data.
150
- *
151
- */
152
- static getMetrics():Record<string, number> {
153
- return OINOBenchmark._instance?._getMetrics()
154
- }
155
-
156
- protected abstract _trackMetric(module:string, method:string, value:number, success:boolean):void
157
- /**
158
- * Track a metric value
159
- *
160
- * @param module of the metric
161
- * @param method of the metric
162
- * @param value of the metric
163
- * @param success indicates if the metric was successful
164
- */
165
- static trackMetric(module:string, method:string, value:number, success:boolean = true):void {
166
- if (OINOBenchmark._enabled[module]) {
167
- OINOBenchmark._instance?._trackMetric(module, method, value, success)
168
- }
169
- }
170
-
171
- protected abstract _trackException(module:string, method:string, name:string, message:string, stack: string):void
172
- /**
173
- * Track an exception
174
- *
175
- * @param module of the benchmark
176
- * @param method of the benchmark
177
- * @param name of the exception
178
- * @param message of the exception
179
- * @param stack trace of the exception
180
- */
181
- static trackException(module:string, method:string, name:string, message:string, stack:string):void {
182
- if (OINOBenchmark._enabled[module]) {
183
- OINOBenchmark._instance?._trackException(module, method, name, message, stack)
184
- }
185
- }
186
-
187
- protected abstract _getExceptions():any[]
188
- /**
189
- * Get all tracked exceptions.
190
- *
191
- */
192
- static getExceptions():any[] {
193
- return OINOBenchmark._instance?._getExceptions()
194
- }
195
- }
196
-
197
- /**
198
- * OINOMemoryBenchmark is a memory-based benchmark implementation.
199
- * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
200
- * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
201
- */
202
- export class OINOMemoryBenchmark extends OINOBenchmark {
203
-
204
- protected _benchmarkCount:Record<string, number> = {}
205
- protected _benchmarkData:Record<string, number> = {}
206
- protected _benchmarkStart:Record<string, number> = {}
207
- protected _healthRequests: number = 0
208
- protected _healthFailures: number = 0
209
-
210
- protected _exceptions:any[] = []
211
-
212
- /**
213
- * Reset benchmark data (but not what is enabled).
214
- *
215
- */
216
- protected _reset():void {
217
- this._benchmarkData = {}
218
- this._benchmarkCount = {}
219
- this._healthRequests = 0
220
- this._healthFailures = 0
221
- }
222
-
223
- /**
224
- * Start benchmark timing.
225
- *
226
- * @param module of the benchmark
227
- * @param method of the benchmark
228
- */
229
- protected _startMetric(module:string, method:string):void {
230
- const name:string = module + "." + method
231
- if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
232
- this._benchmarkStart[name] = performance.now()
233
- }
234
- }
235
-
236
- /**
237
- * Complete benchmark timing
238
- *
239
- * @param module of the benchmark
240
- * @param method of the benchmark
241
- * @param success indicates if the benchmark was successful
242
- */
243
- protected _endMetric(module:string, method:string, success:boolean = true):void {
244
- const name:string = module + "." + method
245
- let result:number = 0
246
- if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
247
- const duration = performance.now() - this._benchmarkStart[name]
248
- this._benchmarkStart[name] = 0
249
- this._trackMetric(module, method, duration, success)
250
- }
251
- return
252
- }
253
-
254
- /**
255
- * Get given benchmark data.
256
- *
257
- * @param module of the benchmark
258
- * @param method of the benchmark
259
- *
260
- */
261
- protected _getMetric(module:string, method:string):number {
262
- const name:string = module + "." + method
263
- if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
264
- return this._benchmarkData[module] / this._benchmarkCount[module]
265
- }
266
- return -1
267
- }
268
-
269
- /**
270
- * Get all benchmark data.
271
- *
272
- */
273
- protected _getMetrics():Record<string, number> {
274
- let result:Record<string, number> = {}
275
- for (const name in this._benchmarkData) {
276
- if (this._benchmarkCount[name] > 0) {
277
- result[name] = this._benchmarkData[name] / this._benchmarkCount[name]
278
- }
279
- }
280
- return result
281
- }
282
-
283
- protected _trackMetric(module:string, method:string, value:number, success:boolean = true):void {
284
- const name:string = module + "." + method
285
- if (this._benchmarkCount[name] == undefined) {
286
- this._benchmarkCount[name] = 1
287
- this._benchmarkData[name] = value
288
- } else {
289
- this._benchmarkCount[name] += 1
290
- this._benchmarkData[name] += value
291
- }
292
- if (OINOBenchmark._healthBenchmarks.includes(name)) {
293
- // console.log(`Health benchmark ${name}: value=${value.toFixed(2)}ms, average=${(this._benchmarkData[name] / this._benchmarkCount[name]).toFixed(2)}ms, late=${late_ratio>=OINOBenchmark._healthLateRatio}, success=${success}`)
294
- this._healthRequests += 1
295
- if (!success) {
296
- this._healthFailures += 1
297
-
298
- } else if (OINOBenchmark._healthLateRatio > 0) {
299
- const late_ratio = value / (this._benchmarkData[name] / this._benchmarkCount[name])
300
- if ((late_ratio > OINOBenchmark._healthLateRatio)) {
301
- this._healthFailures += 1
302
- }
303
- }
304
- }
305
- }
306
-
307
- protected _trackException(module:string, method:string, name:string, message:string, stack:string):void {
308
- const exception = { module, method, name, message, stack, timestamp: Date.now() }
309
- this._exceptions.push(exception)
310
- }
311
-
312
- protected _getExceptions():any[] {
313
- return this._exceptions
314
- }
315
-
316
- protected _getHealth(): number {
317
- if ((OINOBenchmark._healthBenchmarks.length == 0) || (this._healthRequests == 0)) {
318
- return 1.0
319
-
320
- } else {
321
- return (this._healthRequests - this._healthFailures) / this._healthRequests
322
- }
323
- }
324
- }
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ /**
8
+ * Static class for benchmarking functions.
9
+ *
10
+ */
11
+ export abstract class OINOBenchmark {
12
+
13
+ protected static _instance:OINOBenchmark
14
+ protected static _enabled:Record<string, boolean> = {}
15
+ protected static _healthBenchmarks: string[] = []
16
+ protected static _healthLateRatio: number = 0
17
+
18
+ /**
19
+ * Create a new OINOBenchmark instance.
20
+ *
21
+ * @param enabledModules array of those benchmarks that are enabled
22
+ */
23
+ constructor(enabledModules:string[] = []) {
24
+ OINOBenchmark.setEnabled(enabledModules)
25
+ }
26
+
27
+ /**
28
+ * Set active benchmarking instance.
29
+ *
30
+ * @param instance OINOBenchmark instance
31
+ *
32
+ */
33
+ static setInstance(instance: OINOBenchmark) {
34
+ if (instance) {
35
+ OINOBenchmark._instance = instance
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Get active benchmarking instance.
41
+ *
42
+ */
43
+ static getInstance(): OINOBenchmark {
44
+ return OINOBenchmark._instance
45
+ }
46
+
47
+ /**
48
+ * Add benchmark to be used for service health monitoring.
49
+ * @param module of the benchmark
50
+ * @param method of the benchmark
51
+ */
52
+ static addHealthBenchmark(module: string, method: string): void {
53
+ const name = module + "." + method
54
+ if (!OINOBenchmark._healthBenchmarks.includes(name)) {
55
+ OINOBenchmark._healthBenchmarks.push(name)
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Remove benchmark from being used for service health monitoring.
61
+ * @param module of the benchmark
62
+ * @param method of the benchmark
63
+ */
64
+ static removeHealthBenchmark(module: string, method: string): void {
65
+ const name = module + "." + method
66
+ const index = OINOBenchmark._healthBenchmarks.indexOf(name)
67
+ if (index !== -1) {
68
+ OINOBenchmark._healthBenchmarks.splice(index, 1)
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Set late ratio threshold for health monitoring. If a request takes this many times longer than the average duration, it is considered late and a health failure.
74
+ * @param lateRatio of health benchmarks, e.g. 2.0 means requests that take 2 times longer than the average
75
+ */
76
+ static setHealthLateRatio(lateRatio: number): void {
77
+ OINOBenchmark._healthLateRatio = lateRatio
78
+ }
79
+
80
+ /**
81
+ * Get service health based on the configured health benchmark.
82
+ *
83
+ * @returns service health as 0-1
84
+ */
85
+ static getHealth(): number {
86
+ return OINOBenchmark._instance? OINOBenchmark._instance._getHealth() : 1
87
+ }
88
+
89
+ protected abstract _getHealth(): number
90
+
91
+ protected abstract _reset():void
92
+ /**
93
+ * Reset benchmark data (but not what is enabled).
94
+ *
95
+ */
96
+ static reset():void {
97
+ OINOBenchmark._instance?._reset()
98
+ }
99
+
100
+ /**
101
+ * Set benchmark names that are enabled.
102
+ *
103
+ * @param modules array of those benchmarks that are enabled
104
+ */
105
+ static setEnabled(modules:string[]):void {
106
+ OINOBenchmark._enabled = {}
107
+ modules.forEach(module_name => {
108
+ this._enabled[module_name] = true
109
+ });
110
+ }
111
+
112
+ protected abstract _startMetric(module:string, method:string):void
113
+ /**
114
+ * Start benchmark timing.
115
+ *
116
+ * @param module of the benchmark
117
+ * @param method of the benchmark
118
+ */
119
+ static startMetric(module:string, method:string):void {
120
+ OINOBenchmark._instance?._startMetric(module, method)
121
+ }
122
+
123
+ protected abstract _endMetric(module:string, method:string, success:boolean):void
124
+ /**
125
+ * Complete benchmark timing
126
+ *
127
+ * @param module of the benchmark
128
+ * @param method of the benchmark
129
+ * @param success indicates if the benchmark was successful
130
+ */
131
+ static endMetric(module:string, method:string, success:boolean = true):void {
132
+ OINOBenchmark._instance?._endMetric(module, method, success)
133
+ }
134
+
135
+ protected abstract _getMetric(module:string, method:string):number
136
+ /**
137
+ * Get given benchmark data.
138
+ *
139
+ * @param module of the benchmark
140
+ * @param method of the benchmark
141
+ *
142
+ */
143
+ static getMetric(module:string, method:string):number {
144
+ return OINOBenchmark._instance?._getMetric(module, method)
145
+ }
146
+
147
+ protected abstract _getMetrics():Record<string, number>
148
+ /**
149
+ * Get all benchmark data.
150
+ *
151
+ */
152
+ static getMetrics():Record<string, number> {
153
+ return OINOBenchmark._instance?._getMetrics()
154
+ }
155
+
156
+ protected abstract _trackMetric(module:string, method:string, value:number, success:boolean):void
157
+ /**
158
+ * Track a metric value
159
+ *
160
+ * @param module of the metric
161
+ * @param method of the metric
162
+ * @param value of the metric
163
+ * @param success indicates if the metric was successful
164
+ */
165
+ static trackMetric(module:string, method:string, value:number, success:boolean = true):void {
166
+ if (OINOBenchmark._enabled[module]) {
167
+ OINOBenchmark._instance?._trackMetric(module, method, value, success)
168
+ }
169
+ }
170
+
171
+ protected abstract _trackException(module:string, method:string, name:string, message:string, stack: string):void
172
+ /**
173
+ * Track an exception. Does not consider enabled modules.
174
+ *
175
+ * @param module of the benchmark
176
+ * @param method of the benchmark
177
+ * @param name of the exception
178
+ * @param message of the exception
179
+ * @param stack trace of the exception
180
+ */
181
+ static trackException(module:string, method:string, name:string, message:string, stack:string):void {
182
+ OINOBenchmark._instance?._trackException(module, method, name, message, stack)
183
+ }
184
+
185
+ protected abstract _getExceptions():any[]
186
+ /**
187
+ * Get all tracked exceptions.
188
+ *
189
+ */
190
+ static getExceptions():any[] {
191
+ return OINOBenchmark._instance?._getExceptions()
192
+ }
193
+ }
194
+
195
+ /**
196
+ * OINOMemoryBenchmark is a memory-based benchmark implementation.
197
+ * It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
198
+ * In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
199
+ */
200
+ export class OINOMemoryBenchmark extends OINOBenchmark {
201
+
202
+ protected _benchmarkCount:Record<string, number> = {}
203
+ protected _benchmarkData:Record<string, number> = {}
204
+ protected _benchmarkStart:Record<string, number> = {}
205
+ protected _healthRequests: number = 0
206
+ protected _healthFailures: number = 0
207
+
208
+ protected _exceptions:any[] = []
209
+
210
+ /**
211
+ * Reset benchmark data (but not what is enabled).
212
+ *
213
+ */
214
+ protected _reset():void {
215
+ this._exceptions = []
216
+ this._benchmarkData = {}
217
+ this._benchmarkCount = {}
218
+ this._healthRequests = 0
219
+ this._healthFailures = 0
220
+ }
221
+
222
+ /**
223
+ * Start benchmark timing.
224
+ *
225
+ * @param module of the benchmark
226
+ * @param method of the benchmark
227
+ */
228
+ protected _startMetric(module:string, method:string):void {
229
+ const name:string = module + "." + method
230
+ if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
231
+ this._benchmarkStart[name] = performance.now()
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Complete benchmark timing
237
+ *
238
+ * @param module of the benchmark
239
+ * @param method of the benchmark
240
+ * @param success indicates if the benchmark was successful
241
+ */
242
+ protected _endMetric(module:string, method:string, success:boolean = true):void {
243
+ const name:string = module + "." + method
244
+ let result:number = 0
245
+ if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
246
+ const duration = performance.now() - this._benchmarkStart[name]
247
+ this._benchmarkStart[name] = 0
248
+ this._trackMetric(module, method, duration, success)
249
+ }
250
+ return
251
+ }
252
+
253
+ /**
254
+ * Get given benchmark data.
255
+ *
256
+ * @param module of the benchmark
257
+ * @param method of the benchmark
258
+ *
259
+ */
260
+ protected _getMetric(module:string, method:string):number {
261
+ const name:string = module + "." + method
262
+ if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
263
+ return this._benchmarkData[module] / this._benchmarkCount[module]
264
+ }
265
+ return -1
266
+ }
267
+
268
+ /**
269
+ * Get all benchmark data.
270
+ *
271
+ */
272
+ protected _getMetrics():Record<string, number> {
273
+ let result:Record<string, number> = {}
274
+ for (const name in this._benchmarkData) {
275
+ if (this._benchmarkCount[name] > 0) {
276
+ result[name] = this._benchmarkData[name] / this._benchmarkCount[name]
277
+ }
278
+ }
279
+ return result
280
+ }
281
+
282
+ protected _trackMetric(module:string, method:string, value:number, success:boolean = true):void {
283
+ const name:string = module + "." + method
284
+ if (this._benchmarkCount[name] == undefined) {
285
+ this._benchmarkCount[name] = 1
286
+ this._benchmarkData[name] = value
287
+ } else {
288
+ this._benchmarkCount[name] += 1
289
+ this._benchmarkData[name] += value
290
+ }
291
+ if (OINOBenchmark._healthBenchmarks.includes(name)) {
292
+ // console.log(`Health benchmark ${name}: value=${value.toFixed(2)}ms, average=${(this._benchmarkData[name] / this._benchmarkCount[name]).toFixed(2)}ms, late=${late_ratio>=OINOBenchmark._healthLateRatio}, success=${success}`)
293
+ this._healthRequests += 1
294
+ if (!success) {
295
+ this._healthFailures += 1
296
+
297
+ } else if (OINOBenchmark._healthLateRatio > 0) {
298
+ const late_ratio = value / (this._benchmarkData[name] / this._benchmarkCount[name])
299
+ if ((late_ratio > OINOBenchmark._healthLateRatio)) {
300
+ this._healthFailures += 1
301
+ }
302
+ }
303
+ }
304
+ }
305
+
306
+ protected _trackException(module:string, method:string, name:string, message:string, stack:string):void {
307
+ const exception = { module, method, name, message, stack, timestamp: Date.now() }
308
+ this._exceptions.push(exception)
309
+ }
310
+
311
+ protected _getExceptions():any[] {
312
+ return this._exceptions
313
+ }
314
+
315
+ protected _getHealth(): number {
316
+ if ((OINOBenchmark._healthBenchmarks.length == 0) || (this._healthRequests == 0)) {
317
+ return 1.0
318
+
319
+ } else {
320
+ return (this._healthRequests - this._healthFailures) / this._healthRequests
321
+ }
322
+ }
323
+ }