apm-optima 0.0.1

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 (131) hide show
  1. package/dist/adapters/http.adapter.d.ts +12 -0
  2. package/dist/adapters/http.adapter.js +2 -0
  3. package/dist/adapters/websocket.adapter.d.ts +5 -0
  4. package/dist/adapters/websocket.adapter.js +2 -0
  5. package/dist/config/config.manager.d.ts +12 -0
  6. package/dist/config/config.manager.js +111 -0
  7. package/dist/config/config.types.d.ts +19 -0
  8. package/dist/config/config.types.js +2 -0
  9. package/dist/config/index.d.ts +2 -0
  10. package/dist/config/index.js +18 -0
  11. package/dist/core/delivery/index.d.ts +2 -0
  12. package/dist/core/delivery/index.js +18 -0
  13. package/dist/core/delivery/metrics.publisher.d.ts +18 -0
  14. package/dist/core/delivery/metrics.publisher.js +36 -0
  15. package/dist/core/delivery/websocket.events.d.ts +12 -0
  16. package/dist/core/delivery/websocket.events.js +16 -0
  17. package/dist/core/domain/common.types.d.ts +44 -0
  18. package/dist/core/domain/common.types.js +20 -0
  19. package/dist/core/domain/dashboard.types.d.ts +108 -0
  20. package/dist/core/domain/dashboard.types.js +2 -0
  21. package/dist/core/domain/endpoints.types.d.ts +43 -0
  22. package/dist/core/domain/endpoints.types.js +2 -0
  23. package/dist/core/domain/index.d.ts +6 -0
  24. package/dist/core/domain/index.js +22 -0
  25. package/dist/core/domain/metrics.types.d.ts +119 -0
  26. package/dist/core/domain/metrics.types.js +2 -0
  27. package/dist/core/domain/system.types.d.ts +51 -0
  28. package/dist/core/domain/system.types.js +2 -0
  29. package/dist/core/domain/telemetry.types.d.ts +8 -0
  30. package/dist/core/domain/telemetry.types.js +2 -0
  31. package/dist/core/storage/index.d.ts +3 -0
  32. package/dist/core/storage/index.js +19 -0
  33. package/dist/core/storage/local.repository.d.ts +17 -0
  34. package/dist/core/storage/local.repository.js +52 -0
  35. package/dist/core/storage/stores/alert.store.d.ts +13 -0
  36. package/dist/core/storage/stores/alert.store.js +71 -0
  37. package/dist/core/storage/stores/analytics.store.d.ts +15 -0
  38. package/dist/core/storage/stores/analytics.store.js +59 -0
  39. package/dist/core/storage/stores/bucket.store.d.ts +40 -0
  40. package/dist/core/storage/stores/bucket.store.js +75 -0
  41. package/dist/core/storage/stores/dashboard.store.d.ts +15 -0
  42. package/dist/core/storage/stores/dashboard.store.js +78 -0
  43. package/dist/core/storage/stores/endpoint.store.d.ts +16 -0
  44. package/dist/core/storage/stores/endpoint.store.js +62 -0
  45. package/dist/core/storage/stores/health.store.d.ts +20 -0
  46. package/dist/core/storage/stores/health.store.js +133 -0
  47. package/dist/core/storage/stores/index.d.ts +8 -0
  48. package/dist/core/storage/stores/index.js +24 -0
  49. package/dist/core/storage/stores/metrics.store.d.ts +23 -0
  50. package/dist/core/storage/stores/metrics.store.js +49 -0
  51. package/dist/core/storage/stores/system.store.d.ts +8 -0
  52. package/dist/core/storage/stores/system.store.js +19 -0
  53. package/dist/core/storage/utility/histogram.d.ts +37 -0
  54. package/dist/core/storage/utility/histogram.js +91 -0
  55. package/dist/core/storage/utility/index.d.ts +2 -0
  56. package/dist/core/storage/utility/index.js +18 -0
  57. package/dist/core/storage/utility/ring-buffer.d.ts +12 -0
  58. package/dist/core/storage/utility/ring-buffer.js +47 -0
  59. package/dist/core/telemetry/collector.service.d.ts +18 -0
  60. package/dist/core/telemetry/collector.service.js +92 -0
  61. package/dist/core/telemetry/collectors/cpu.collector.d.ts +22 -0
  62. package/dist/core/telemetry/collectors/cpu.collector.js +39 -0
  63. package/dist/core/telemetry/collectors/event-loop.collector.d.ts +22 -0
  64. package/dist/core/telemetry/collectors/event-loop.collector.js +27 -0
  65. package/dist/core/telemetry/collectors/gc.collector.d.ts +61 -0
  66. package/dist/core/telemetry/collectors/gc.collector.js +86 -0
  67. package/dist/core/telemetry/collectors/handles.collector.d.ts +20 -0
  68. package/dist/core/telemetry/collectors/handles.collector.js +26 -0
  69. package/dist/core/telemetry/collectors/index.d.ts +6 -0
  70. package/dist/core/telemetry/collectors/index.js +22 -0
  71. package/dist/core/telemetry/collectors/interface.d.ts +3 -0
  72. package/dist/core/telemetry/collectors/interface.js +2 -0
  73. package/dist/core/telemetry/collectors/memory.collector.d.ts +18 -0
  74. package/dist/core/telemetry/collectors/memory.collector.js +24 -0
  75. package/dist/core/telemetry/collectors/runtime.collector.d.ts +32 -0
  76. package/dist/core/telemetry/collectors/runtime.collector.js +29 -0
  77. package/dist/core/telemetry/correlation.service.d.ts +9 -0
  78. package/dist/core/telemetry/correlation.service.js +72 -0
  79. package/dist/core/telemetry/logger.d.ts +11 -0
  80. package/dist/core/telemetry/logger.js +63 -0
  81. package/dist/core/telemetry/telemetry.service.d.ts +10 -0
  82. package/dist/core/telemetry/telemetry.service.js +36 -0
  83. package/dist/core/utility/base-math.d.ts +15 -0
  84. package/dist/core/utility/base-math.js +26 -0
  85. package/dist/core/utility/conversion.d.ts +31 -0
  86. package/dist/core/utility/conversion.js +74 -0
  87. package/dist/core/utility/index.d.ts +4 -0
  88. package/dist/core/utility/index.js +20 -0
  89. package/dist/core/utility/mocking.d.ts +21 -0
  90. package/dist/core/utility/mocking.js +40 -0
  91. package/dist/core/utility/pagination.d.ts +9 -0
  92. package/dist/core/utility/pagination.js +23 -0
  93. package/dist/core/utility/statistics.d.ts +140 -0
  94. package/dist/core/utility/statistics.js +349 -0
  95. package/dist/express/index.d.ts +6 -0
  96. package/dist/express/index.js +22 -0
  97. package/dist/express/metrics-websocket.adapter.d.ts +14 -0
  98. package/dist/express/metrics-websocket.adapter.js +70 -0
  99. package/dist/express/metrics.adapter.d.ts +12 -0
  100. package/dist/express/metrics.adapter.js +31 -0
  101. package/dist/express/metrics.bootstrap.d.ts +2 -0
  102. package/dist/express/metrics.bootstrap.js +35 -0
  103. package/dist/express/metrics.dashboard.d.ts +2 -0
  104. package/dist/express/metrics.dashboard.js +15 -0
  105. package/dist/express/metrics.middleware.d.ts +2 -0
  106. package/dist/express/metrics.middleware.js +29 -0
  107. package/dist/index.d.ts +3 -0
  108. package/dist/index.js +6 -0
  109. package/dist/nest/index.d.ts +4 -0
  110. package/dist/nest/index.js +11 -0
  111. package/dist/nest/metrics-websocket.adapter.d.ts +15 -0
  112. package/dist/nest/metrics-websocket.adapter.js +88 -0
  113. package/dist/nest/metrics.adapter.d.ts +12 -0
  114. package/dist/nest/metrics.adapter.js +33 -0
  115. package/dist/nest/metrics.bootstrap.service.d.ts +13 -0
  116. package/dist/nest/metrics.bootstrap.service.js +66 -0
  117. package/dist/nest/metrics.interceptor.d.ts +11 -0
  118. package/dist/nest/metrics.interceptor.js +57 -0
  119. package/dist/nest/metrics.module.d.ts +6 -0
  120. package/dist/nest/metrics.module.js +74 -0
  121. package/dist/simulation/config.d.ts +20 -0
  122. package/dist/simulation/config.js +54 -0
  123. package/dist/simulation/journey.d.ts +7 -0
  124. package/dist/simulation/journey.js +49 -0
  125. package/dist/simulation/scenarios.d.ts +17 -0
  126. package/dist/simulation/scenarios.js +96 -0
  127. package/dist/simulation/simulation.d.ts +24 -0
  128. package/dist/simulation/simulation.js +154 -0
  129. package/dist/simulation/utility.d.ts +23 -0
  130. package/dist/simulation/utility.js +50 -0
  131. package/package.json +71 -0
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("../../config");
4
+ class Logger {
5
+ static RESET = '\x1b[0m';
6
+ static BOLD = '\x1b[1m';
7
+ static DIM = '\x1b[2m';
8
+ static COLORS = {
9
+ GET: '\x1b[32m', // Green
10
+ POST: '\x1b[36m', // Cyan
11
+ PUT: '\x1b[33m', // Yellow
12
+ DELETE: '\x1b[31m', // Red
13
+ PATCH: '\x1b[35m', // Magenta
14
+ SUCCESS: '\x1b[32m', // Green (2xx)
15
+ WARN: '\x1b[33m', // Yellow (4xx)
16
+ ERROR: '\x1b[31m' // Red (5xx)
17
+ };
18
+ static log(req, res, duration) {
19
+ if (!(0, config_1.getConfig)().consoleLog)
20
+ return;
21
+ const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
22
+ const timeFormatted = `${duration.toFixed(2)}ms`.padStart(8, ' ');
23
+ const methodColor = Logger.COLORS[req.method] || Logger.RESET;
24
+ const method = `${Logger.BOLD}${methodColor}${req.method.padEnd(7, ' ')}${Logger.RESET}`;
25
+ const status = res.statusCode;
26
+ let statusColor = Logger.COLORS.SUCCESS;
27
+ if (status >= 400 && status < 500)
28
+ statusColor = Logger.COLORS.WARN;
29
+ if (status >= 500)
30
+ statusColor = Logger.COLORS.ERROR;
31
+ const statusCode = `${Logger.BOLD}${statusColor}${status}${Logger.RESET}`;
32
+ let speedColor = Logger.RESET;
33
+ if (duration > 500)
34
+ speedColor = Logger.COLORS.ERROR;
35
+ else if (duration > 200)
36
+ speedColor = Logger.COLORS.WARN;
37
+ const timing = `${speedColor}${timeFormatted}${Logger.RESET}`;
38
+ console.log(`${Logger.DIM}[${timestamp}]${Logger.RESET} ` +
39
+ `${method} ` +
40
+ `${req.url.padEnd(35, ' ')} ` +
41
+ `• ${statusCode} • ` +
42
+ `${timing}`);
43
+ }
44
+ static debug(message) {
45
+ const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
46
+ console.log(`${Logger.DIM}[${timestamp}]${Logger.RESET} ${Logger.DIM}${message}${Logger.RESET}`);
47
+ }
48
+ static duration(message, duration) {
49
+ return; // Disable duration logging for now
50
+ const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
51
+ const timeFormatted = `${duration.toFixed(2)}ms`.padStart(8, ' ');
52
+ let speedColor = Logger.RESET;
53
+ if (duration > 500)
54
+ speedColor = Logger.COLORS.ERROR;
55
+ else if (duration > 200)
56
+ speedColor = Logger.COLORS.WARN;
57
+ const timing = `${speedColor}${timeFormatted}${Logger.RESET}`;
58
+ console.log(`${Logger.DIM}[${timestamp}]${Logger.RESET} ` +
59
+ `${message} ` +
60
+ `• ${timing}`);
61
+ }
62
+ }
63
+ exports.default = Logger;
@@ -0,0 +1,10 @@
1
+ import type { TelemetryRequest } from '../domain';
2
+ declare class TelemetryService {
3
+ private readonly storage;
4
+ constructor(storage?: {
5
+ record(request: TelemetryRequest): void;
6
+ });
7
+ private isPathExcluded;
8
+ record(data: Omit<TelemetryRequest, 'timestamp' | 'responseTime'>, startHrTime: bigint): TelemetryRequest | null;
9
+ }
10
+ export default TelemetryService;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const local_repository_1 = require("../storage/local.repository");
4
+ const config_1 = require("../../config");
5
+ class TelemetryService {
6
+ storage;
7
+ constructor(storage = local_repository_1.storage) {
8
+ this.storage = storage;
9
+ }
10
+ isPathExcluded(endpoint) {
11
+ const cleanPath = endpoint.split('?')[0];
12
+ const userConfig = (0, config_1.getConfig)();
13
+ const configuredPaths = userConfig?.excludePaths || [];
14
+ const allPatterns = [...configuredPaths];
15
+ return allPatterns.some(pattern => {
16
+ const cleanPattern = pattern.replace(/\*/g, '');
17
+ return cleanPath.includes(cleanPattern);
18
+ });
19
+ }
20
+ record(data, startHrTime) {
21
+ if (this.isPathExcluded(data.endpoint)) {
22
+ return null;
23
+ }
24
+ const endHrTime = process.hrtime.bigint();
25
+ const durationInMS = Number(endHrTime - startHrTime) / 1e6;
26
+ const durationInMSFixed = parseFloat(durationInMS.toFixed(2));
27
+ const telemetryRequest = {
28
+ ...data,
29
+ timestamp: Date.now(),
30
+ responseTime: durationInMSFixed,
31
+ };
32
+ this.storage.record(telemetryRequest);
33
+ return telemetryRequest;
34
+ }
35
+ }
36
+ exports.default = TelemetryService;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Clamps a value between a minimum and maximum value.
3
+ * @param value - The value to be clamped.
4
+ * @param min - The minimum value to clamp to.
5
+ * @param max - The maximum value to clamp to.
6
+ * @returns The clamped value, guaranteed to be between min and max.
7
+ */
8
+ export declare function clamp(value: number, min: number, max: number): number;
9
+ /**
10
+ * Clamps a given value to ensure it falls within the range of 0 to 100.
11
+ * @param value - The value to be clamped, typically representing a percentage.
12
+ * @param total - The total value used to calculate the percentage.
13
+ * @returns The clamped percentage value, guaranteed to be between 0 and 100.
14
+ */
15
+ export declare function toPercentage(value: number, total: number): number;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clamp = clamp;
4
+ exports.toPercentage = toPercentage;
5
+ /**
6
+ * Clamps a value between a minimum and maximum value.
7
+ * @param value - The value to be clamped.
8
+ * @param min - The minimum value to clamp to.
9
+ * @param max - The maximum value to clamp to.
10
+ * @returns The clamped value, guaranteed to be between min and max.
11
+ */
12
+ function clamp(value, min, max) {
13
+ return Math.min(max, Math.max(min, value));
14
+ }
15
+ /**
16
+ * Clamps a given value to ensure it falls within the range of 0 to 100.
17
+ * @param value - The value to be clamped, typically representing a percentage.
18
+ * @param total - The total value used to calculate the percentage.
19
+ * @returns The clamped percentage value, guaranteed to be between 0 and 100.
20
+ */
21
+ function toPercentage(value, total) {
22
+ if (total === 0) {
23
+ return 0; // Avoid division by zero
24
+ }
25
+ return clamp((value / total) * 100, 0, 100);
26
+ }
@@ -0,0 +1,31 @@
1
+ type SizeUnit = 'MB' | 'KB' | 'GB';
2
+ type TimeUnit = 'ms' | 's';
3
+ /**
4
+ * Converts bytes to the specified size unit (MB, KB, GB).
5
+ * @param bytes The number of bytes to convert.
6
+ * @param unit The unit to convert to.
7
+ * @returns The equivalent number in the specified unit.
8
+ */
9
+ export declare function convertBytes(bytes: number, unit: SizeUnit): number;
10
+ /**
11
+ * Converts a value in the specified size unit (MB, KB, GB) to bytes.
12
+ * @param value The value to convert.
13
+ * @param unit The unit of the value (MB, KB, GB).
14
+ * @returns The equivalent number of bytes.
15
+ */
16
+ export declare function convertToBytes(value: number, unit: SizeUnit): number;
17
+ /**
18
+ * Converts a value in nanoseconds to the specified time unit (milliseconds or seconds).
19
+ * @param value The value in nanoseconds to convert.
20
+ * @param unit The unit to convert to ('ms' for milliseconds, 's' for seconds).
21
+ * @returns The equivalent number in the specified unit.
22
+ */
23
+ export declare function convertNanoseconds(value: number, unit: TimeUnit): number;
24
+ /**
25
+ * Converts a value in the specified time unit (milliseconds or seconds) to nanoseconds.
26
+ * @param value The value to convert.
27
+ * @param unit The unit of the value ('ms' for milliseconds, 's' for seconds).
28
+ * @returns The equivalent number of nanoseconds.
29
+ */
30
+ export declare function convertToNanoseconds(value: number, unit: TimeUnit): number;
31
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertBytes = convertBytes;
4
+ exports.convertToBytes = convertToBytes;
5
+ exports.convertNanoseconds = convertNanoseconds;
6
+ exports.convertToNanoseconds = convertToNanoseconds;
7
+ /**
8
+ * Converts bytes to the specified size unit (MB, KB, GB).
9
+ * @param bytes The number of bytes to convert.
10
+ * @param unit The unit to convert to.
11
+ * @returns The equivalent number in the specified unit.
12
+ */
13
+ function convertBytes(bytes, unit) {
14
+ switch (unit) {
15
+ case 'MB':
16
+ return Math.round(bytes / 1024 / 1024);
17
+ case 'KB':
18
+ return Math.round(bytes / 1024);
19
+ case 'GB':
20
+ return Math.round(bytes / 1024 / 1024 / 1024);
21
+ default:
22
+ throw new Error(`Unsupported unit: ${unit}`);
23
+ }
24
+ }
25
+ /**
26
+ * Converts a value in the specified size unit (MB, KB, GB) to bytes.
27
+ * @param value The value to convert.
28
+ * @param unit The unit of the value (MB, KB, GB).
29
+ * @returns The equivalent number of bytes.
30
+ */
31
+ function convertToBytes(value, unit) {
32
+ switch (unit) {
33
+ case 'MB':
34
+ return value * 1024 * 1024;
35
+ case 'KB':
36
+ return value * 1024;
37
+ case 'GB':
38
+ return value * 1024 * 1024 * 1024;
39
+ default:
40
+ throw new Error(`Unsupported unit: ${unit}`);
41
+ }
42
+ }
43
+ /**
44
+ * Converts a value in nanoseconds to the specified time unit (milliseconds or seconds).
45
+ * @param value The value in nanoseconds to convert.
46
+ * @param unit The unit to convert to ('ms' for milliseconds, 's' for seconds).
47
+ * @returns The equivalent number in the specified unit.
48
+ */
49
+ function convertNanoseconds(value, unit) {
50
+ switch (unit) {
51
+ case 'ms':
52
+ return value / 1e6; // Convert nanoseconds to milliseconds
53
+ case 's':
54
+ return value / 1e9; // Convert nanoseconds to seconds
55
+ default:
56
+ throw new Error(`Unsupported unit: ${unit}`);
57
+ }
58
+ }
59
+ /**
60
+ * Converts a value in the specified time unit (milliseconds or seconds) to nanoseconds.
61
+ * @param value The value to convert.
62
+ * @param unit The unit of the value ('ms' for milliseconds, 's' for seconds).
63
+ * @returns The equivalent number of nanoseconds.
64
+ */
65
+ function convertToNanoseconds(value, unit) {
66
+ switch (unit) {
67
+ case 'ms':
68
+ return value * 1e6; // Convert milliseconds to nanoseconds
69
+ case 's':
70
+ return value * 1e9; // Convert seconds to nanoseconds
71
+ default:
72
+ throw new Error(`Unsupported unit: ${unit}`);
73
+ }
74
+ }
@@ -0,0 +1,4 @@
1
+ export * from './base-math';
2
+ export * from './conversion';
3
+ export * from './pagination';
4
+ export * from './statistics';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base-math"), exports);
18
+ __exportStar(require("./conversion"), exports);
19
+ __exportStar(require("./pagination"), exports);
20
+ __exportStar(require("./statistics"), exports);
@@ -0,0 +1,21 @@
1
+ export declare function mockArray(length: number, min: number, max: number, force?: number): number[];
2
+ export declare function mockDistributionEntry(endpoint: string, p50Min: number, p50Max: number, p95Min: number, p95Max: number, p99Min: number, p99Max: number): {
3
+ endpoint: string;
4
+ p50: number;
5
+ p95: number;
6
+ p99: number;
7
+ };
8
+ export declare function mockDistribution(endpoints: string[], p50Min: number, p50Max: number, p95Min: number, p95Max: number, p99Min: number, p99Max: number): {
9
+ endpoint: string;
10
+ p50: number;
11
+ p95: number;
12
+ p99: number;
13
+ }[];
14
+ export declare function mockVolumeEntry(endpoint: string, volumeMin: number, volumeMax: number): {
15
+ endpoint: string;
16
+ volume: number;
17
+ };
18
+ export declare function mockVolume(endpoints: string[], volumeMin: number, volumeMax: number): {
19
+ endpoint: string;
20
+ volume: number;
21
+ }[];
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockArray = mockArray;
4
+ exports.mockDistributionEntry = mockDistributionEntry;
5
+ exports.mockDistribution = mockDistribution;
6
+ exports.mockVolumeEntry = mockVolumeEntry;
7
+ exports.mockVolume = mockVolume;
8
+ function mockArray(length, min, max, force) {
9
+ const arr = [];
10
+ for (let i = 0; i < length; i++) {
11
+ if (force !== undefined) {
12
+ if (Math.random() < 0.7) {
13
+ arr.push(force);
14
+ continue;
15
+ }
16
+ }
17
+ arr.push(Math.floor(Math.random() * (max - min + 1)) + min);
18
+ }
19
+ return arr;
20
+ }
21
+ function mockDistributionEntry(endpoint, p50Min, p50Max, p95Min, p95Max, p99Min, p99Max) {
22
+ return {
23
+ endpoint,
24
+ p50: Math.floor(Math.random() * (p50Max - p50Min + 1)) + p50Min,
25
+ p95: Math.floor(Math.random() * (p95Max - p95Min + 1)) + p95Min,
26
+ p99: Math.floor(Math.random() * (p99Max - p99Min + 1)) + p99Min,
27
+ };
28
+ }
29
+ function mockDistribution(endpoints, p50Min, p50Max, p95Min, p95Max, p99Min, p99Max) {
30
+ return endpoints.map((endpoint) => mockDistributionEntry(endpoint, p50Min, p50Max, p95Min, p95Max, p99Min, p99Max));
31
+ }
32
+ function mockVolumeEntry(endpoint, volumeMin, volumeMax) {
33
+ return {
34
+ endpoint,
35
+ volume: Math.floor(Math.random() * (volumeMax - volumeMin + 1)) + volumeMin,
36
+ };
37
+ }
38
+ function mockVolume(endpoints, volumeMin, volumeMax) {
39
+ return endpoints.map((endpoint) => mockVolumeEntry(endpoint, volumeMin, volumeMax));
40
+ }
@@ -0,0 +1,9 @@
1
+ import type { PaginationMeta } from "../domain";
2
+ export declare function constructData<T>(items: T[], page: number, pageSize: number): T[];
3
+ export declare function constructMeta(total: number, page: number, pageSize: number): PaginationMeta;
4
+ type PaginationResult<T> = {
5
+ data: T[];
6
+ meta: PaginationMeta;
7
+ };
8
+ export declare function paginate<T>(items: T[], page: number, pageSize: number): PaginationResult<T>;
9
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructData = constructData;
4
+ exports.constructMeta = constructMeta;
5
+ exports.paginate = paginate;
6
+ function constructData(items, page, pageSize) {
7
+ const start = (page - 1) * pageSize;
8
+ return items.slice(start, start + pageSize);
9
+ }
10
+ function constructMeta(total, page, pageSize) {
11
+ return {
12
+ page,
13
+ pageSize,
14
+ perPageCount: Math.min(pageSize, total),
15
+ totalCount: total,
16
+ };
17
+ }
18
+ function paginate(items, page, pageSize) {
19
+ return {
20
+ data: constructData(items, page, pageSize),
21
+ meta: constructMeta(items.length, page, pageSize),
22
+ };
23
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Generates a hash code for a given value. This function converts the value to a JSON string and computes a hash code based on its characters.
3
+ * @param value The value to be hashed. It can be of any type that can be serialized to JSON.
4
+ * @returns The hash code for the given value.
5
+ */
6
+ export declare function hash(value: NonNullable<unknown>): number;
7
+ /**
8
+ * Calculates the rate as a percentage of accounted over total.
9
+ * @param accounted The number of items accounted for.
10
+ * @param total The total number of items.
11
+ * @returns The rate as a percentage.
12
+ */
13
+ export declare function rate(accounted: number, total: number): number;
14
+ /**
15
+ * Calculates the mean (average) of a dataset.
16
+ * @param data - An array of numbers representing the dataset.
17
+ * @returns The mean of the dataset.
18
+ */
19
+ export declare function mean(data: number[]): number;
20
+ /**
21
+ * Calculates the specified percentile of a dataset. (e.g., p95, p99)
22
+ * @param data - An array of numbers representing the dataset.
23
+ * @param percentile - The desired percentile (between 0 and 1, e.g., 0.95 for p95).
24
+ * @returns The value at the specified percentile of the dataset.
25
+ */
26
+ export declare function percentile(data: number[], percentile: number): number;
27
+ /**
28
+ * Calculates the specified percentile of a histogram represented by counters and limits.
29
+ * This function is useful for determining latency percentiles from histogram data.
30
+ * @param counters An array of counts representing the number of occurrences in each histogram bucket.
31
+ * @param totalCount The total number of occurrences across all histogram buckets.
32
+ * @param percentile The desired percentile (between 0 and 1, e.g., 0.95 for p95).
33
+ * @param limits An array of upper limits for each histogram bucket, corresponding to the counters.
34
+ * @returns The value at the specified percentile of the histogram.
35
+ */
36
+ export declare function percentileHistogram(counters: Uint32Array, totalCount: number, percentile: number, limits: number[]): number;
37
+ /**
38
+ * Calculates the median (p50) of a dataset.
39
+ * @param data - An array of numbers representing the dataset.
40
+ * @returns The median of the dataset.
41
+ */
42
+ export declare function median(data: number[]): number;
43
+ /**
44
+ * Calculates the required sample size for estimating a population proportion with a specified margin of error and confidence level.
45
+ * The formula used is based on the normal approximation to the binomial distribution.
46
+ * @param marginOfError The desired margin of error (e.g., 0.05 for ±5%).
47
+ * @param confidenceLevel The desired confidence level (default is 0.95 for 95% confidence).
48
+ * @returns The required sample size to achieve the specified margin of error and confidence level.
49
+ */
50
+ export declare function calculateSampleSizeProportion(marginOfError: number, confidenceLevel?: number): number;
51
+ /**
52
+ * Calculates the Pearson correlation coefficient (r) between two datasets.
53
+ * The correlation coefficient measures the strength and direction of the linear relationship between two variables.
54
+ * The value of r ranges from -1 to 1, where:
55
+ * - r = 1 indicates a perfect positive correlation,
56
+ * - r = -1 indicates a perfect negative correlation,
57
+ * - r = 0 indicates no correlation.
58
+ *
59
+ * The function also provides an interpretation of the correlation strength and assigns a color class for visualization purposes.
60
+ * @param x The first dataset (X values) as an array of numbers.
61
+ * @param y The second dataset (Y values) as an array of numbers.
62
+ * @returns The Pearson correlation coefficient (r).
63
+ */
64
+ export declare function pearsonCorrelation(x: number[], y: number[]): number;
65
+ /**
66
+ * Calculates the Spearman rank correlation coefficient (ρ) between two datasets.
67
+ * @param x An array of numbers representing the first dataset.
68
+ * @param y An array of numbers representing the second dataset.
69
+ * @returns The Spearman rank correlation coefficient (ρ).
70
+ */
71
+ export declare function spearmanCorrelation(x: number[], y: number[]): number;
72
+ /**
73
+ * Calculates the coefficient of determination (R²) and the coefficient of alienation (1 - R²) based on the Pearson correlation coefficient (r).
74
+ * The coefficient of determination (R²) indicates the proportion of the variance in the dependent variable that is predictable from the independent variable.
75
+ * The coefficient of alienation (1 - R²) indicates the proportion of the variance that is not explained by the model.
76
+ *
77
+ * @param pearsonR The Pearson correlation coefficient (r) between two datasets.
78
+ * @returns An object containing the coefficient of determination (R²) and the coefficient of alienation (1 - R²).
79
+ */
80
+ export declare function determinationAndAlienation(pearsonR: number): {
81
+ determination: number;
82
+ alienation: number;
83
+ };
84
+ /**
85
+ * Calculates the standard deviation of a dataset.
86
+ * The standard deviation is a measure of the amount of variation or dispersion in a set of values.
87
+ * @param data An array of numbers representing the dataset.
88
+ * @returns The standard deviation of the dataset.
89
+ */
90
+ export declare function standardDeviation(data: number[]): number;
91
+ /**
92
+ * Calculates the standard deviation from histogram data.
93
+ * The standard deviation is a measure of the amount of variation or dispersion in a set of values.
94
+ * This function uses the total count, total sum, and total sum of squares to compute the standard deviation.
95
+ * @param totalCount The total number of occurrences across all histogram buckets.
96
+ * @param totalSum The total sum of all values across the histogram buckets.
97
+ * @param totalSumOfSquares The total sum of squares of all values across the histogram buckets.
98
+ * @returns The standard deviation of the histogram data.
99
+ */
100
+ export declare function standardDeviationHistogram(totalCount: number, totalSum: number, totalSumOfSquares: number): number;
101
+ /**
102
+ * Calculates the z-score for a given value based on the mean and standard deviation of a dataset.
103
+ * The z-score indicates how many standard deviations a value is from the mean.
104
+ * A positive z-score indicates the value is above the mean, while a negative z-score indicates it is below the mean.
105
+ * @param value The value for which the z-score is to be calculated.
106
+ * @param data An array of numbers representing the dataset.
107
+ * @returns The z-score of the value. If the dataset is empty or has zero standard deviation, the function returns 0.
108
+ */
109
+ export declare function zScore(value: number, data: number[]): number;
110
+ /**
111
+ * Calculates the z-score for a given value based on histogram data.
112
+ * The z-score indicates how many standard deviations a value is from the mean.
113
+ * A positive z-score indicates the value is above the mean, while a negative z-score indicates it is below the mean.
114
+ * @param value The value for which the z-score is to be calculated.
115
+ * @param totalCount The total number of occurrences across all histogram buckets.
116
+ * @param totalSum The total sum of all values across the histogram buckets.
117
+ * @param totalSumOfSquares The total sum of squares of all values across the histogram buckets.
118
+ * @returns The z-score of the value. If the histogram is empty or has zero standard deviation, the function returns 0.
119
+ */
120
+ export declare function zScoreHistogram(value: number, totalCount: number, totalSum: number, totalSumOfSquares: number): number;
121
+ /**
122
+ * Determines if a given value is an anomaly based on its z-score relative to a dataset.
123
+ * A value is considered an anomaly if its z-score exceeds the specified threshold.
124
+ * @param value The value to be evaluated for anomaly detection.
125
+ * @param data An array of numbers representing the dataset against which the value is compared.
126
+ * @param threshold The z-score threshold beyond which a value is considered an anomaly. Default is 3.
127
+ * @returns A boolean indicating whether the value is an anomaly (true) or not (false).
128
+ */
129
+ export declare function isDataAnomaly(value: number, data: number[], threshold?: number): boolean;
130
+ /**
131
+ * Determines if a given value is an anomaly based on its z-score relative to histogram data.
132
+ * A value is considered an anomaly if its z-score exceeds the specified threshold.
133
+ * @param value The value to be evaluated for anomaly detection.
134
+ * @param totalCount The total number of occurrences across all histogram buckets.
135
+ * @param totalSum The total sum of all values across the histogram buckets.
136
+ * @param totalSumOfSquares The total sum of squares of all values across the histogram buckets.
137
+ * @param threshold The z-score threshold beyond which a value is considered an anomaly. Default is 3.
138
+ * @returns A boolean indicating whether the value is an anomaly (true) or not (false).
139
+ */
140
+ export declare function isDataAnomalyHistogram(value: number, totalCount: number, totalSum: number, totalSumOfSquares: number, threshold?: number): boolean;