traceperf 0.1.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/dist/browser.d.ts +67 -0
  4. package/dist/browser.js +260 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/core/config.d.ts +77 -0
  7. package/dist/core/config.js +116 -0
  8. package/dist/core/config.js.map +1 -0
  9. package/dist/core/constants.d.ts +78 -0
  10. package/dist/core/constants.js +109 -0
  11. package/dist/core/constants.js.map +1 -0
  12. package/dist/core/index.d.ts +3 -0
  13. package/dist/core/index.js +20 -0
  14. package/dist/core/index.js.map +1 -0
  15. package/dist/core/logger.d.ts +84 -0
  16. package/dist/core/logger.js +174 -0
  17. package/dist/core/logger.js.map +1 -0
  18. package/dist/formatters/ascii.d.ts +52 -0
  19. package/dist/formatters/ascii.js +104 -0
  20. package/dist/formatters/ascii.js.map +1 -0
  21. package/dist/formatters/cli.d.ts +50 -0
  22. package/dist/formatters/cli.js +100 -0
  23. package/dist/formatters/cli.js.map +1 -0
  24. package/dist/formatters/index.d.ts +3 -0
  25. package/dist/formatters/index.js +20 -0
  26. package/dist/formatters/index.js.map +1 -0
  27. package/dist/formatters/json.d.ts +45 -0
  28. package/dist/formatters/json.js +89 -0
  29. package/dist/formatters/json.js.map +1 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +33 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/trackers/execution.d.ts +72 -0
  34. package/dist/trackers/execution.js +147 -0
  35. package/dist/trackers/execution.js.map +1 -0
  36. package/dist/trackers/index.d.ts +2 -0
  37. package/dist/trackers/index.js +19 -0
  38. package/dist/trackers/index.js.map +1 -0
  39. package/dist/trackers/performance.d.ts +82 -0
  40. package/dist/trackers/performance.js +110 -0
  41. package/dist/trackers/performance.js.map +1 -0
  42. package/dist/types/config.d.ts +110 -0
  43. package/dist/types/config.js +2 -0
  44. package/dist/types/config.js.map +1 -0
  45. package/dist/types/index.d.ts +2 -0
  46. package/dist/types/index.js +3 -0
  47. package/dist/types/index.js.map +1 -0
  48. package/dist/types/logger.d.ts +127 -0
  49. package/dist/types/logger.js +2 -0
  50. package/dist/types/logger.js.map +1 -0
  51. package/dist/utils/colors.d.ts +87 -0
  52. package/dist/utils/colors.js +148 -0
  53. package/dist/utils/colors.js.map +1 -0
  54. package/dist/utils/index.d.ts +3 -0
  55. package/dist/utils/index.js +20 -0
  56. package/dist/utils/index.js.map +1 -0
  57. package/dist/utils/stack.d.ts +63 -0
  58. package/dist/utils/stack.js +116 -0
  59. package/dist/utils/stack.js.map +1 -0
  60. package/dist/utils/timing.d.ts +65 -0
  61. package/dist/utils/timing.js +106 -0
  62. package/dist/utils/timing.js.map +1 -0
  63. package/package.json +62 -0
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecutionTracker = void 0;
4
+ const stack_1 = require("../utils/stack");
5
+ const timing_1 = require("../utils/timing");
6
+ const ascii_1 = require("../formatters/ascii");
7
+ /**
8
+ * Execution tracker for tracking function calls and generating flow charts
9
+ */
10
+ class ExecutionTracker {
11
+ /**
12
+ * Create a new ExecutionTracker instance
13
+ *
14
+ * @param options - Tracker options
15
+ */
16
+ constructor(options = {}) {
17
+ var _a;
18
+ this._executions = [];
19
+ this._currentExecution = null;
20
+ this._callStack = new stack_1.CallStackManager();
21
+ this._asciiGenerator = new ascii_1.AsciiArtGenerator({ boxWidth: options.boxWidth });
22
+ this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
23
+ }
24
+ /**
25
+ * Track the execution of a function
26
+ *
27
+ * @param fn - The function to track
28
+ * @param options - Options for tracking
29
+ * @returns The return value of the tracked function
30
+ */
31
+ track(fn, options) {
32
+ var _a, _b;
33
+ const fnName = (options === null || options === void 0 ? void 0 : options.label) || (0, stack_1.getFunctionName)(fn);
34
+ const threshold = (_a = options === null || options === void 0 ? void 0 : options.threshold) !== null && _a !== void 0 ? _a : this._defaultThreshold;
35
+ const includeMemory = (_b = options === null || options === void 0 ? void 0 : options.includeMemory) !== null && _b !== void 0 ? _b : true;
36
+ // Get memory usage before execution
37
+ const startMemory = includeMemory ? process.memoryUsage().heapUsed : undefined;
38
+ // Start timing
39
+ const startTime = (0, timing_1.getHighResTime)();
40
+ // Add to call stack
41
+ const level = this._callStack.push(fnName);
42
+ // Create execution record
43
+ const execution = {
44
+ name: fnName,
45
+ duration: 0,
46
+ isSlow: false,
47
+ level: level - 1, // 0-based level
48
+ startTime,
49
+ children: [],
50
+ };
51
+ // Set parent-child relationship
52
+ if (this._currentExecution) {
53
+ execution.parent = this._currentExecution;
54
+ this._currentExecution.children.push(execution);
55
+ }
56
+ else {
57
+ // This is a root execution
58
+ this._executions.push(execution);
59
+ }
60
+ // Save the previous current execution
61
+ const previousExecution = this._currentExecution;
62
+ // Set this as the current execution
63
+ this._currentExecution = execution;
64
+ try {
65
+ // Execute the function
66
+ return fn();
67
+ }
68
+ finally {
69
+ // End timing
70
+ const endTime = (0, timing_1.getHighResTime)();
71
+ execution.endTime = endTime;
72
+ // Calculate duration
73
+ execution.duration = (0, timing_1.getDuration)(startTime);
74
+ // Check if it's a bottleneck
75
+ execution.isSlow = execution.duration > threshold;
76
+ // Calculate memory usage
77
+ if (includeMemory && startMemory !== undefined) {
78
+ execution.memoryUsage = process.memoryUsage().heapUsed - startMemory;
79
+ }
80
+ // Restore the previous current execution
81
+ this._currentExecution = previousExecution;
82
+ // Remove from call stack
83
+ this._callStack.pop();
84
+ }
85
+ }
86
+ /**
87
+ * Get the current call stack
88
+ *
89
+ * @returns The current call stack
90
+ */
91
+ getCallStack() {
92
+ return this._callStack.getStack();
93
+ }
94
+ /**
95
+ * Generate a visual representation of the execution flow
96
+ *
97
+ * @returns ASCII flow chart of the execution
98
+ */
99
+ generateFlowChart() {
100
+ // Convert execution records to execution data for the ASCII generator
101
+ const flatExecutions = this.flattenExecutions(this._executions);
102
+ // Generate the flow chart
103
+ return this._asciiGenerator.generateFlowChart(flatExecutions);
104
+ }
105
+ /**
106
+ * Clear all execution records
107
+ */
108
+ clear() {
109
+ this._executions = [];
110
+ this._currentExecution = null;
111
+ this._callStack.clear();
112
+ }
113
+ /**
114
+ * Get all execution records
115
+ *
116
+ * @returns All execution records
117
+ */
118
+ getExecutions() {
119
+ return [...this._executions];
120
+ }
121
+ /**
122
+ * Flatten the execution tree into a list
123
+ *
124
+ * @param executions - The execution records to flatten
125
+ * @returns A flat list of execution data
126
+ */
127
+ flattenExecutions(executions) {
128
+ const result = [];
129
+ // Helper function to recursively flatten the tree
130
+ const flatten = (record) => {
131
+ result.push({
132
+ name: record.name,
133
+ duration: record.duration,
134
+ isSlow: record.isSlow,
135
+ memoryUsage: record.memoryUsage,
136
+ level: record.level,
137
+ });
138
+ // Process children
139
+ record.children.forEach(child => flatten(child));
140
+ };
141
+ // Flatten each root execution
142
+ executions.forEach(execution => flatten(execution));
143
+ return result;
144
+ }
145
+ }
146
+ exports.ExecutionTracker = ExecutionTracker;
147
+ //# sourceMappingURL=execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/trackers/execution.ts"],"names":[],"mappings":";;;AACA,0CAAmE;AACnE,4CAA8D;AAC9D,+CAAuE;AAiBvE;;GAEG;AACH,MAAa,gBAAgB;IAO3B;;;;OAIG;IACH,YAAY,UAA4D,EAAE;;QAVlE,gBAAW,GAAsB,EAAE,CAAC;QACpC,sBAAiB,GAA2B,IAAI,CAAC;QAUvD,IAAI,CAAC,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;QACzC,IAAI,CAAC,eAAe,GAAG,IAAI,yBAAiB,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,iBAAiB,GAAG,MAAA,OAAO,CAAC,gBAAgB,mCAAI,GAAG,CAA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C;IAC1B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,UAA6B;QACrD,MAAM,MAAM,GAAoB,EAAE,CAAC;QAEnC,kDAAkD;QAClD,MAAM,OAAO,GAAG,CAAC,MAAuB,EAAQ,EAAE;YAChD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC,CAAC;YAEH,mBAAmB;YACnB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC;QAEF,8BAA8B;QAC9B,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;QAEpD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA/JD,4CA+JC"}
@@ -0,0 +1,2 @@
1
+ export * from './execution';
2
+ export * from './performance';
@@ -0,0 +1,19 @@
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("./execution"), exports);
18
+ __exportStar(require("./performance"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/trackers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B"}
@@ -0,0 +1,82 @@
1
+ import { IPerformanceMonitor } from '../types';
2
+ /**
3
+ * Performance monitor for tracking execution times and memory usage
4
+ */
5
+ export declare class PerformanceMonitor implements IPerformanceMonitor {
6
+ private _timers;
7
+ private _defaultThreshold;
8
+ /**
9
+ * Create a new PerformanceMonitor instance
10
+ *
11
+ * @param options - Monitor options
12
+ */
13
+ constructor(options?: {
14
+ defaultThreshold?: number;
15
+ });
16
+ /**
17
+ * Start timing an operation
18
+ *
19
+ * @param label - Label for the operation
20
+ * @returns A unique identifier for the timing operation
21
+ */
22
+ startTimer(label: string): string;
23
+ /**
24
+ * End timing an operation
25
+ *
26
+ * @param id - The identifier returned by startTimer
27
+ * @returns The duration in milliseconds
28
+ * @throws Error if the timer doesn't exist
29
+ */
30
+ endTimer(id: string): number;
31
+ /**
32
+ * Check if an operation exceeds the performance threshold
33
+ *
34
+ * @param duration - The duration in milliseconds
35
+ * @param threshold - The threshold to check against
36
+ * @returns Whether the operation is considered slow
37
+ */
38
+ isBottleneck(duration: number, threshold?: number): boolean;
39
+ /**
40
+ * Get memory usage information
41
+ *
42
+ * @returns Memory usage in bytes
43
+ */
44
+ getMemoryUsage(): {
45
+ heapUsed: number;
46
+ heapTotal: number;
47
+ external: number;
48
+ rss: number;
49
+ };
50
+ /**
51
+ * Get memory difference between two points
52
+ *
53
+ * @param before - Memory usage before
54
+ * @param after - Memory usage after
55
+ * @returns Memory difference in bytes
56
+ */
57
+ getMemoryDiff(before: {
58
+ heapUsed: number;
59
+ heapTotal: number;
60
+ external: number;
61
+ rss: number;
62
+ }, after: {
63
+ heapUsed: number;
64
+ heapTotal: number;
65
+ external: number;
66
+ rss: number;
67
+ }): {
68
+ heapUsed: number;
69
+ heapTotal: number;
70
+ external: number;
71
+ rss: number;
72
+ };
73
+ /**
74
+ * Generate a suggestion for a bottleneck
75
+ *
76
+ * @param functionName - The name of the function
77
+ * @param duration - The duration in milliseconds
78
+ * @param memoryUsage - Memory usage in bytes
79
+ * @returns A suggestion for improving performance
80
+ */
81
+ generateSuggestion(functionName: string, duration: number, memoryUsage?: number): string;
82
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PerformanceMonitor = void 0;
4
+ const timing_1 = require("../utils/timing");
5
+ const uuid_1 = require("uuid");
6
+ /**
7
+ * Performance monitor for tracking execution times and memory usage
8
+ */
9
+ class PerformanceMonitor {
10
+ /**
11
+ * Create a new PerformanceMonitor instance
12
+ *
13
+ * @param options - Monitor options
14
+ */
15
+ constructor(options = {}) {
16
+ var _a;
17
+ this._timers = new Map();
18
+ this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
19
+ }
20
+ /**
21
+ * Start timing an operation
22
+ *
23
+ * @param label - Label for the operation
24
+ * @returns A unique identifier for the timing operation
25
+ */
26
+ startTimer(label) {
27
+ const id = `${label}-${(0, uuid_1.v4)()}`;
28
+ this._timers.set(id, (0, timing_1.getHighResTime)());
29
+ return id;
30
+ }
31
+ /**
32
+ * End timing an operation
33
+ *
34
+ * @param id - The identifier returned by startTimer
35
+ * @returns The duration in milliseconds
36
+ * @throws Error if the timer doesn't exist
37
+ */
38
+ endTimer(id) {
39
+ const startTime = this._timers.get(id);
40
+ if (!startTime) {
41
+ throw new Error(`Timer with id ${id} not found`);
42
+ }
43
+ const duration = (0, timing_1.getDuration)(startTime);
44
+ this._timers.delete(id);
45
+ return duration;
46
+ }
47
+ /**
48
+ * Check if an operation exceeds the performance threshold
49
+ *
50
+ * @param duration - The duration in milliseconds
51
+ * @param threshold - The threshold to check against
52
+ * @returns Whether the operation is considered slow
53
+ */
54
+ isBottleneck(duration, threshold) {
55
+ const effectiveThreshold = threshold !== null && threshold !== void 0 ? threshold : this._defaultThreshold;
56
+ return duration > effectiveThreshold;
57
+ }
58
+ /**
59
+ * Get memory usage information
60
+ *
61
+ * @returns Memory usage in bytes
62
+ */
63
+ getMemoryUsage() {
64
+ const memoryUsage = process.memoryUsage();
65
+ return {
66
+ heapUsed: memoryUsage.heapUsed,
67
+ heapTotal: memoryUsage.heapTotal,
68
+ external: memoryUsage.external,
69
+ rss: memoryUsage.rss,
70
+ };
71
+ }
72
+ /**
73
+ * Get memory difference between two points
74
+ *
75
+ * @param before - Memory usage before
76
+ * @param after - Memory usage after
77
+ * @returns Memory difference in bytes
78
+ */
79
+ getMemoryDiff(before, after) {
80
+ return {
81
+ heapUsed: after.heapUsed - before.heapUsed,
82
+ heapTotal: after.heapTotal - before.heapTotal,
83
+ external: after.external - before.external,
84
+ rss: after.rss - before.rss,
85
+ };
86
+ }
87
+ /**
88
+ * Generate a suggestion for a bottleneck
89
+ *
90
+ * @param functionName - The name of the function
91
+ * @param duration - The duration in milliseconds
92
+ * @param memoryUsage - Memory usage in bytes
93
+ * @returns A suggestion for improving performance
94
+ */
95
+ generateSuggestion(functionName, duration, memoryUsage) {
96
+ // Simple heuristic-based suggestions
97
+ if (memoryUsage && memoryUsage > 10 * 1024 * 1024) {
98
+ return `🛠 Potential Fix: Check for memory leaks or large object allocations in ${functionName}`;
99
+ }
100
+ if (duration > 1000) {
101
+ return `🛠 Potential Fix: Consider optimizing or adding caching to ${functionName}`;
102
+ }
103
+ if (duration > 500) {
104
+ return `🛠 Potential Fix: Look for blocking operations in ${functionName}`;
105
+ }
106
+ return `🛠 Potential Fix: Review ${functionName} for performance optimizations`;
107
+ }
108
+ }
109
+ exports.PerformanceMonitor = PerformanceMonitor;
110
+ //# sourceMappingURL=performance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance.js","sourceRoot":"","sources":["../../src/trackers/performance.ts"],"names":[],"mappings":";;;AACA,4CAA8D;AAC9D,+BAAoC;AAEpC;;GAEG;AACH,MAAa,kBAAkB;IAI7B;;;;OAIG;IACH,YAAY,UAAyC,EAAE;;QAR/C,YAAO,GAAkC,IAAI,GAAG,EAAE,CAAC;QASzD,IAAI,CAAC,iBAAiB,GAAG,MAAA,OAAO,CAAC,gBAAgB,mCAAI,GAAG,CAAC,CAAC,KAAK;IACjE,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,KAAa;QAC7B,MAAM,EAAE,GAAG,GAAG,KAAK,IAAI,IAAA,SAAM,GAAE,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,uBAAc,GAAE,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;OAMG;IACI,QAAQ,CAAC,EAAU;QACxB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAExB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACI,YAAY,CAAC,QAAgB,EAAE,SAAkB;QACtD,MAAM,kBAAkB,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,iBAAiB,CAAC;QAC/D,OAAO,QAAQ,GAAG,kBAAkB,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACI,cAAc;QACnB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAC1C,OAAO;YACL,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,SAAS,EAAE,WAAW,CAAC,SAAS;YAChC,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,GAAG,EAAE,WAAW,CAAC,GAAG;SACrB,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAClB,MAA8E,EAC9E,KAA6E;QAE7E,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ;YAC1C,SAAS,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;YAC7C,QAAQ,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ;YAC1C,GAAG,EAAE,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG;SAC5B,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,kBAAkB,CACvB,YAAoB,EACpB,QAAgB,EAChB,WAAoB;QAEpB,qCAAqC;QACrC,IAAI,WAAW,IAAI,WAAW,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;YAClD,OAAO,2EAA2E,YAAY,EAAE,CAAC;QACnG,CAAC;QAED,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;YACpB,OAAO,8DAA8D,YAAY,EAAE,CAAC;QACtF,CAAC;QAED,IAAI,QAAQ,GAAG,GAAG,EAAE,CAAC;YACnB,OAAO,qDAAqD,YAAY,EAAE,CAAC;QAC7E,CAAC;QAED,OAAO,4BAA4B,YAAY,gCAAgC,CAAC;IAClF,CAAC;CACF;AAtHD,gDAsHC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * LogLevel - Defines the severity levels for logging
3
+ */
4
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
5
+ /**
6
+ * LogMode - Defines the operational modes for the logger
7
+ */
8
+ export type LogMode = 'dev' | 'staging' | 'prod' | string;
9
+ /**
10
+ * Transport - Interface for log output destinations
11
+ */
12
+ export interface ITransport {
13
+ /**
14
+ * Write a log entry to the destination
15
+ *
16
+ * @param entry - The formatted log entry to write
17
+ */
18
+ write(entry: string): void;
19
+ }
20
+ /**
21
+ * Formatter - Interface for log formatters
22
+ */
23
+ export interface IFormatter {
24
+ /**
25
+ * Format a log entry
26
+ *
27
+ * @param level - The log level
28
+ * @param message - The log message
29
+ * @param args - Additional arguments
30
+ * @param meta - Metadata for the log entry
31
+ * @returns The formatted log entry
32
+ */
33
+ format(level: LogLevel, message: string | object, args: any[], meta: LogMeta): string;
34
+ }
35
+ /**
36
+ * LogMeta - Metadata for log entries
37
+ */
38
+ export interface LogMeta {
39
+ timestamp: Date;
40
+ level: LogLevel;
41
+ indentLevel: number;
42
+ [key: string]: any;
43
+ }
44
+ /**
45
+ * TrackOptions - Options for function execution tracking
46
+ */
47
+ export interface ITrackOptions {
48
+ /**
49
+ * Custom label for the tracked function
50
+ */
51
+ label?: string;
52
+ /**
53
+ * Performance threshold in milliseconds
54
+ * Functions exceeding this threshold will be flagged as bottlenecks
55
+ */
56
+ threshold?: number;
57
+ /**
58
+ * Whether to include memory usage tracking
59
+ */
60
+ includeMemory?: boolean;
61
+ /**
62
+ * Whether to suppress logging for this tracking
63
+ */
64
+ silent?: boolean;
65
+ }
66
+ /**
67
+ * LoggerConfig - Configuration options for the logger
68
+ */
69
+ export interface ILoggerConfig {
70
+ /**
71
+ * Operational mode
72
+ * @default 'dev'
73
+ */
74
+ mode?: LogMode;
75
+ /**
76
+ * Minimum log level to display
77
+ * @default 'debug'
78
+ */
79
+ level?: LogLevel;
80
+ /**
81
+ * Whether to colorize output
82
+ * @default true
83
+ */
84
+ colorize?: boolean;
85
+ /**
86
+ * Whether to include timestamps in logs
87
+ * @default true
88
+ */
89
+ timestamp?: boolean;
90
+ /**
91
+ * Default performance threshold in milliseconds
92
+ * @default 100
93
+ */
94
+ performanceThreshold?: number;
95
+ /**
96
+ * Number of spaces for each indentation level
97
+ * @default 2
98
+ */
99
+ indentSize?: number;
100
+ /**
101
+ * Log output destinations
102
+ * @default [ConsoleTransport]
103
+ */
104
+ transports?: ITransport[];
105
+ /**
106
+ * Log formatters
107
+ * @default [CliFormatter]
108
+ */
109
+ formatters?: IFormatter[];
110
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './config';
2
+ export * from './logger';
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './logger';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { LogMode, ITrackOptions } from './config';
2
+ /**
3
+ * ILogger - Interface for the main logger functionality
4
+ */
5
+ export interface ILogger {
6
+ /**
7
+ * Log an informational message
8
+ *
9
+ * @param message - The message to log
10
+ * @param args - Additional arguments to include in the log
11
+ */
12
+ info(message: string | object, ...args: any[]): void;
13
+ /**
14
+ * Log a warning message
15
+ *
16
+ * @param message - The message to log
17
+ * @param args - Additional arguments to include in the log
18
+ */
19
+ warn(message: string | object, ...args: any[]): void;
20
+ /**
21
+ * Log an error message
22
+ *
23
+ * @param message - The message to log
24
+ * @param args - Additional arguments to include in the log
25
+ */
26
+ error(message: string | object, ...args: any[]): void;
27
+ /**
28
+ * Log a debug message
29
+ *
30
+ * @param message - The message to log
31
+ * @param args - Additional arguments to include in the log
32
+ */
33
+ debug(message: string | object, ...args: any[]): void;
34
+ /**
35
+ * Start a new log group with the given label
36
+ *
37
+ * @param label - The label for the group
38
+ */
39
+ group(label: string): void;
40
+ /**
41
+ * End the current log group
42
+ */
43
+ groupEnd(): void;
44
+ /**
45
+ * Set the operational mode for the logger
46
+ *
47
+ * @param mode - The mode to set
48
+ */
49
+ setMode(mode: LogMode): void;
50
+ /**
51
+ * Get the current operational mode
52
+ *
53
+ * @returns The current mode
54
+ */
55
+ getMode(): LogMode;
56
+ /**
57
+ * Track the execution of a function and log performance metrics
58
+ *
59
+ * @param fn - The function to track
60
+ * @param options - Options for tracking
61
+ * @returns The return value of the tracked function
62
+ */
63
+ track<T>(fn: () => T, options?: ITrackOptions): T;
64
+ }
65
+ /**
66
+ * IExecutionTracker - Interface for tracking function execution
67
+ */
68
+ export interface IExecutionTracker {
69
+ /**
70
+ * Track the execution of a function
71
+ *
72
+ * @param fn - The function to track
73
+ * @param options - Options for tracking
74
+ * @returns The return value of the tracked function
75
+ */
76
+ track<T>(fn: () => T, options?: ITrackOptions): T;
77
+ /**
78
+ * Get the current call stack
79
+ *
80
+ * @returns The current call stack
81
+ */
82
+ getCallStack(): string[];
83
+ /**
84
+ * Generate a visual representation of the execution flow
85
+ *
86
+ * @returns ASCII flow chart of the execution
87
+ */
88
+ generateFlowChart(): string;
89
+ }
90
+ /**
91
+ * IPerformanceMonitor - Interface for monitoring performance
92
+ */
93
+ export interface IPerformanceMonitor {
94
+ /**
95
+ * Start timing an operation
96
+ *
97
+ * @param label - Label for the operation
98
+ * @returns A unique identifier for the timing operation
99
+ */
100
+ startTimer(label: string): string;
101
+ /**
102
+ * End timing an operation
103
+ *
104
+ * @param id - The identifier returned by startTimer
105
+ * @returns The duration in milliseconds
106
+ */
107
+ endTimer(id: string): number;
108
+ /**
109
+ * Check if an operation exceeds the performance threshold
110
+ *
111
+ * @param duration - The duration in milliseconds
112
+ * @param threshold - The threshold to check against
113
+ * @returns Whether the operation is considered slow
114
+ */
115
+ isBottleneck(duration: number, threshold?: number): boolean;
116
+ /**
117
+ * Get memory usage information
118
+ *
119
+ * @returns Memory usage in bytes
120
+ */
121
+ getMemoryUsage(): {
122
+ heapUsed: number;
123
+ heapTotal: number;
124
+ external: number;
125
+ rss: number;
126
+ };
127
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/types/logger.ts"],"names":[],"mappings":""}