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,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsciiArtGenerator = void 0;
4
+ const constants_1 = require("../core/constants");
5
+ const timing_1 = require("../utils/timing");
6
+ /**
7
+ * ASCII art generator for execution flow charts
8
+ */
9
+ class AsciiArtGenerator {
10
+ /**
11
+ * Create a new AsciiArtGenerator instance
12
+ *
13
+ * @param options - Generator options
14
+ */
15
+ constructor(options = {}) {
16
+ var _a;
17
+ this._boxWidth = (_a = options.boxWidth) !== null && _a !== void 0 ? _a : 30;
18
+ }
19
+ /**
20
+ * Generate a flow chart for a sequence of function executions
21
+ *
22
+ * @param executions - Array of execution data
23
+ * @returns ASCII art flow chart
24
+ */
25
+ generateFlowChart(executions) {
26
+ let chart = '';
27
+ for (let i = 0; i < executions.length; i++) {
28
+ const execution = executions[i];
29
+ // Generate box for function
30
+ chart += this.generateFunctionBox(execution);
31
+ // Add arrow to next function if not the last one
32
+ if (i < executions.length - 1) {
33
+ chart += this.generateArrow(executions[i + 1].level - execution.level);
34
+ }
35
+ }
36
+ return chart;
37
+ }
38
+ /**
39
+ * Generate a box for a function execution
40
+ *
41
+ * @param execution - The execution data
42
+ * @returns ASCII art box
43
+ */
44
+ generateFunctionBox(execution) {
45
+ const { name, duration, isSlow, memoryUsage } = execution;
46
+ // Calculate padding for the function name
47
+ const nameLength = name.length;
48
+ const padding = Math.max(0, this._boxWidth - nameLength - 2);
49
+ const leftPadding = Math.floor(padding / 2);
50
+ const rightPadding = padding - leftPadding;
51
+ // Generate the box
52
+ let box = '';
53
+ // Top border
54
+ box += constants_1.BOX_CHARS.topLeft + constants_1.BOX_CHARS.horizontal.repeat(this._boxWidth) + constants_1.BOX_CHARS.topRight + '\n';
55
+ // Function name
56
+ box += constants_1.BOX_CHARS.vertical + ' '.repeat(leftPadding) + name + ' '.repeat(rightPadding) + constants_1.BOX_CHARS.vertical;
57
+ // Performance metrics
58
+ box += ` ${constants_1.PERFORMANCE_ICONS.timer} ${(0, timing_1.formatDuration)(duration)}`;
59
+ if (isSlow) {
60
+ box += ` ${constants_1.PERFORMANCE_ICONS.slow} SLOW`;
61
+ }
62
+ if (memoryUsage !== undefined) {
63
+ box += ` ${constants_1.PERFORMANCE_ICONS.memory} ${this.formatMemory(memoryUsage)}`;
64
+ }
65
+ box += '\n';
66
+ // Bottom border
67
+ box += constants_1.BOX_CHARS.bottomLeft + constants_1.BOX_CHARS.horizontal.repeat(this._boxWidth) + constants_1.BOX_CHARS.bottomRight + '\n';
68
+ return box;
69
+ }
70
+ /**
71
+ * Generate an arrow between function boxes
72
+ *
73
+ * @param levelDiff - Difference in nesting level
74
+ * @returns ASCII art arrow
75
+ */
76
+ generateArrow(levelDiff) {
77
+ let arrow = '';
78
+ // Indent based on level difference
79
+ const indent = ' '.repeat(Math.max(0, levelDiff));
80
+ // Vertical line
81
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + constants_1.BOX_CHARS.vertical + '\n';
82
+ // Arrow
83
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + constants_1.BOX_CHARS.downArrow + '\n';
84
+ return arrow;
85
+ }
86
+ /**
87
+ * Format memory usage in a human-readable format
88
+ *
89
+ * @param bytes - Memory usage in bytes
90
+ * @returns Formatted memory usage
91
+ */
92
+ formatMemory(bytes) {
93
+ const units = ['B', 'KB', 'MB', 'GB'];
94
+ let size = bytes;
95
+ let unitIndex = 0;
96
+ while (size >= 1024 && unitIndex < units.length - 1) {
97
+ size /= 1024;
98
+ unitIndex++;
99
+ }
100
+ return `${size.toFixed(2)}${units[unitIndex]}`;
101
+ }
102
+ }
103
+ exports.AsciiArtGenerator = AsciiArtGenerator;
104
+ //# sourceMappingURL=ascii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ascii.js","sourceRoot":"","sources":["../../src/formatters/ascii.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AACjE,4CAAiD;AAajD;;GAEG;AACH,MAAa,iBAAiB;IAG5B;;;;OAIG;IACH,YAAY,UAAiC,EAAE;;QAC7C,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAC,UAA2B;QAClD,IAAI,KAAK,GAAG,EAAE,CAAC;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAEhC,4BAA4B;YAC5B,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAE7C,iDAAiD;YACjD,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9B,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACK,m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../types';
2
+ /**
3
+ * CLI formatter for console output
4
+ * Formats log entries with colors, icons, and indentation
5
+ */
6
+ export declare class CliFormatter implements IFormatter {
7
+ private _colorEnabled;
8
+ private _indentSize;
9
+ /**
10
+ * Create a new CliFormatter instance
11
+ *
12
+ * @param options - Formatter options
13
+ */
14
+ constructor(options?: {
15
+ colorEnabled?: boolean;
16
+ indentSize?: number;
17
+ });
18
+ /**
19
+ * Format a log entry for CLI output
20
+ *
21
+ * @param level - The log level
22
+ * @param message - The log message
23
+ * @param args - Additional arguments
24
+ * @param meta - Metadata for the log entry
25
+ * @returns The formatted log entry
26
+ */
27
+ format(level: LogLevel, message: string | object, args: any[], meta: LogMeta): string;
28
+ /**
29
+ * Format a timestamp
30
+ *
31
+ * @param date - The date to format
32
+ * @returns The formatted timestamp
33
+ */
34
+ private formatTimestamp;
35
+ /**
36
+ * Format a log level
37
+ *
38
+ * @param level - The log level
39
+ * @returns The formatted log level
40
+ */
41
+ private formatLevel;
42
+ /**
43
+ * Format a message and its arguments
44
+ *
45
+ * @param message - The message to format
46
+ * @param args - Additional arguments
47
+ * @returns The formatted message
48
+ */
49
+ private formatMessage;
50
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CliFormatter = void 0;
4
+ const constants_1 = require("../core/constants");
5
+ const colors_1 = require("../utils/colors");
6
+ /**
7
+ * CLI formatter for console output
8
+ * Formats log entries with colors, icons, and indentation
9
+ */
10
+ class CliFormatter {
11
+ /**
12
+ * Create a new CliFormatter instance
13
+ *
14
+ * @param options - Formatter options
15
+ */
16
+ constructor(options = {}) {
17
+ var _a, _b;
18
+ this._colorEnabled = (_a = options.colorEnabled) !== null && _a !== void 0 ? _a : (0, colors_1.supportsColor)();
19
+ this._indentSize = (_b = options.indentSize) !== null && _b !== void 0 ? _b : 2;
20
+ }
21
+ /**
22
+ * Format a log entry for CLI output
23
+ *
24
+ * @param level - The log level
25
+ * @param message - The log message
26
+ * @param args - Additional arguments
27
+ * @param meta - Metadata for the log entry
28
+ * @returns The formatted log entry
29
+ */
30
+ format(level, message, args, meta) {
31
+ const timestamp = this.formatTimestamp(meta.timestamp);
32
+ const levelStr = this.formatLevel(level);
33
+ const indent = ' '.repeat(meta.indentLevel * this._indentSize);
34
+ const formattedMessage = this.formatMessage(message, args);
35
+ return `${timestamp} ${levelStr} ${indent}${formattedMessage}`;
36
+ }
37
+ /**
38
+ * Format a timestamp
39
+ *
40
+ * @param date - The date to format
41
+ * @returns The formatted timestamp
42
+ */
43
+ formatTimestamp(date) {
44
+ const timeStr = date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
45
+ return this._colorEnabled ? (0, colors_1.dim)(`[${timeStr}]`) : `[${timeStr}]`;
46
+ }
47
+ /**
48
+ * Format a log level
49
+ *
50
+ * @param level - The log level
51
+ * @returns The formatted log level
52
+ */
53
+ formatLevel(level) {
54
+ const icon = constants_1.LEVEL_ICONS[level];
55
+ const text = level.toUpperCase();
56
+ if (this._colorEnabled) {
57
+ return (0, colors_1.colorize)(`${icon} ${text}`, constants_1.LEVEL_COLORS[level]);
58
+ }
59
+ return `${icon} ${text}`;
60
+ }
61
+ /**
62
+ * Format a message and its arguments
63
+ *
64
+ * @param message - The message to format
65
+ * @param args - Additional arguments
66
+ * @returns The formatted message
67
+ */
68
+ formatMessage(message, args) {
69
+ let formattedMessage;
70
+ if (typeof message === 'string') {
71
+ formattedMessage = message;
72
+ }
73
+ else {
74
+ try {
75
+ formattedMessage = JSON.stringify(message, null, 2);
76
+ }
77
+ catch (error) {
78
+ formattedMessage = String(message);
79
+ }
80
+ }
81
+ // Format additional arguments
82
+ if (args.length > 0) {
83
+ const formattedArgs = args.map(arg => {
84
+ if (typeof arg === 'object' && arg !== null) {
85
+ try {
86
+ return JSON.stringify(arg, null, 2);
87
+ }
88
+ catch (error) {
89
+ return String(arg);
90
+ }
91
+ }
92
+ return String(arg);
93
+ }).join(' ');
94
+ formattedMessage = `${formattedMessage} ${formattedArgs}`;
95
+ }
96
+ return formattedMessage;
97
+ }
98
+ }
99
+ exports.CliFormatter = CliFormatter;
100
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/formatters/cli.ts"],"names":[],"mappings":";;;AACA,iDAA8D;AAC9D,4CAA+D;AAE/D;;;GAGG;AACH,MAAa,YAAY;IAIvB;;;;OAIG;IACH,YAAY,UAA2D,EAAE;;QACvE,IAAI,CAAC,aAAa,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAA,sBAAa,GAAE,CAAC;QAC7D,IAAI,CAAC,WAAW,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAW,EAAE,IAAa;QACjF,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/D,MAAM,gBAAgB,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3D,OAAO,GAAG,SAAS,IAAI,QAAQ,IAAI,MAAM,GAAG,gBAAgB,EAAE,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACK,eAAe,CAAC,IAAU;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAA,YAAG,EAAC,IAAI,OAAO,GAAG,CA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ACrB,CAAC;gBACH,CAAC;gBACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEb,gBAAgB,GAAG,GAAG,gBAAgB,IAAI,aAAa,EAAE,CAAC;QAC5D,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAlGD,oCAkGC"}
@@ -0,0 +1,3 @@
1
+ export * from './cli';
2
+ export * from './json';
3
+ export * from './ascii';
@@ -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("./cli"), exports);
18
+ __exportStar(require("./json"), exports);
19
+ __exportStar(require("./ascii"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,0CAAwB"}
@@ -0,0 +1,45 @@
1
+ import { IFormatter, LogLevel, LogMeta } from '../types';
2
+ /**
3
+ * JSON formatter for structured output
4
+ * Formats log entries as JSON objects
5
+ */
6
+ export declare class JsonFormatter implements IFormatter {
7
+ /**
8
+ * Format a log entry as JSON
9
+ *
10
+ * @param level - The log level
11
+ * @param message - The log message
12
+ * @param args - Additional arguments
13
+ * @param meta - Metadata for the log entry
14
+ * @returns The formatted log entry as a JSON string
15
+ */
16
+ format(level: LogLevel, message: string | object, args: any[], meta: LogMeta): string;
17
+ /**
18
+ * Format a message for JSON output
19
+ *
20
+ * @param message - The message to format
21
+ * @returns The formatted message
22
+ */
23
+ private formatMessage;
24
+ /**
25
+ * Format arguments for JSON output
26
+ *
27
+ * @param args - The arguments to format
28
+ * @returns The formatted arguments
29
+ */
30
+ private formatArgs;
31
+ /**
32
+ * Sanitize an object for JSON serialization
33
+ *
34
+ * @param obj - The object to sanitize
35
+ * @returns A sanitized version of the object
36
+ */
37
+ private sanitizeObject;
38
+ /**
39
+ * Extract additional metadata from the log meta object
40
+ *
41
+ * @param meta - The log metadata
42
+ * @returns Additional metadata as an object
43
+ */
44
+ private extractExtraMeta;
45
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonFormatter = void 0;
4
+ /**
5
+ * JSON formatter for structured output
6
+ * Formats log entries as JSON objects
7
+ */
8
+ class JsonFormatter {
9
+ /**
10
+ * Format a log entry as JSON
11
+ *
12
+ * @param level - The log level
13
+ * @param message - The log message
14
+ * @param args - Additional arguments
15
+ * @param meta - Metadata for the log entry
16
+ * @returns The formatted log entry as a JSON string
17
+ */
18
+ format(level, message, args, meta) {
19
+ const logEntry = {
20
+ timestamp: meta.timestamp.toISOString(),
21
+ level,
22
+ indentLevel: meta.indentLevel,
23
+ message: this.formatMessage(message),
24
+ args: this.formatArgs(args),
25
+ ...this.extractExtraMeta(meta),
26
+ };
27
+ return JSON.stringify(logEntry);
28
+ }
29
+ /**
30
+ * Format a message for JSON output
31
+ *
32
+ * @param message - The message to format
33
+ * @returns The formatted message
34
+ */
35
+ formatMessage(message) {
36
+ if (typeof message === 'string') {
37
+ return message;
38
+ }
39
+ return this.sanitizeObject(message);
40
+ }
41
+ /**
42
+ * Format arguments for JSON output
43
+ *
44
+ * @param args - The arguments to format
45
+ * @returns The formatted arguments
46
+ */
47
+ formatArgs(args) {
48
+ return args.map(arg => {
49
+ if (typeof arg === 'object' && arg !== null) {
50
+ return this.sanitizeObject(arg);
51
+ }
52
+ return arg;
53
+ });
54
+ }
55
+ /**
56
+ * Sanitize an object for JSON serialization
57
+ *
58
+ * @param obj - The object to sanitize
59
+ * @returns A sanitized version of the object
60
+ */
61
+ sanitizeObject(obj) {
62
+ try {
63
+ // Use JSON.parse(JSON.stringify()) to remove non-serializable values
64
+ return JSON.parse(JSON.stringify(obj));
65
+ }
66
+ catch (error) {
67
+ // If serialization fails, return a simplified object
68
+ return { value: String(obj) };
69
+ }
70
+ }
71
+ /**
72
+ * Extract additional metadata from the log meta object
73
+ *
74
+ * @param meta - The log metadata
75
+ * @returns Additional metadata as an object
76
+ */
77
+ extractExtraMeta(meta) {
78
+ const result = {};
79
+ // Copy all properties except the standard ones
80
+ Object.keys(meta).forEach(key => {
81
+ if (!['timestamp', 'level', 'indentLevel'].includes(key)) {
82
+ result[key] = meta[key];
83
+ }
84
+ });
85
+ return result;
86
+ }
87
+ }
88
+ exports.JsonFormatter = JsonFormatter;
89
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/formatters/json.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,aAAa;IACxB;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAW,EAAE,IAAa;QACjF,MAAM,QAAQ,GAAG;YACf,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,KAAK;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YACpC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAC3B,GAAG,IAAI,CAAC,g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;YAC1B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtFD,sCAsFC"}
@@ -0,0 +1,10 @@
1
+ import { Logger } from './core/logger';
2
+ import { ILoggerConfig } from './types';
3
+ declare const defaultLogger: Logger;
4
+ export default defaultLogger;
5
+ export declare function createLogger(config?: Partial<ILoggerConfig>): Logger;
6
+ export * from './types';
7
+ export * from './core';
8
+ export * from './formatters';
9
+ export * from './trackers';
10
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
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
+ exports.createLogger = createLogger;
18
+ const logger_1 = require("./core/logger");
19
+ // Create a singleton instance of the logger
20
+ const defaultLogger = new logger_1.Logger();
21
+ // Export the singleton instance as the default export
22
+ exports.default = defaultLogger;
23
+ // Export a function to create a new logger instance
24
+ function createLogger(config = {}) {
25
+ return new logger_1.Logger(config);
26
+ }
27
+ // Export types and classes for advanced usage
28
+ __exportStar(require("./types"), exports);
29
+ __exportStar(require("./core"), exports);
30
+ __exportStar(require("./formatters"), exports);
31
+ __exportStar(require("./trackers"), exports);
32
+ __exportStar(require("./utils"), exports);
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAUA,oCAEC;AAZD,0CAAuC;AAGvC,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,eAAM,EAAE,CAAC;AAEnC,sDAAsD;AACtD,kBAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,SAAgB,YAAY,CAAC,SAAiC,EAAE;IAC9D,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,8CAA8C;AAC9C,0CAAwB;AACxB,yCAAuB;AACvB,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB"}
@@ -0,0 +1,72 @@
1
+ import { IExecutionTracker, ITrackOptions } from '../types';
2
+ /**
3
+ * Execution record for a function call
4
+ */
5
+ interface ExecutionRecord {
6
+ name: string;
7
+ duration: number;
8
+ isSlow: boolean;
9
+ memoryUsage?: number;
10
+ level: number;
11
+ startTime: [number, number];
12
+ endTime?: [number, number];
13
+ children: ExecutionRecord[];
14
+ parent?: ExecutionRecord;
15
+ }
16
+ /**
17
+ * Execution tracker for tracking function calls and generating flow charts
18
+ */
19
+ export declare class ExecutionTracker implements IExecutionTracker {
20
+ private _callStack;
21
+ private _executions;
22
+ private _currentExecution;
23
+ private _asciiGenerator;
24
+ private _defaultThreshold;
25
+ /**
26
+ * Create a new ExecutionTracker instance
27
+ *
28
+ * @param options - Tracker options
29
+ */
30
+ constructor(options?: {
31
+ defaultThreshold?: number;
32
+ boxWidth?: number;
33
+ });
34
+ /**
35
+ * Track the execution of a function
36
+ *
37
+ * @param fn - The function to track
38
+ * @param options - Options for tracking
39
+ * @returns The return value of the tracked function
40
+ */
41
+ track<T>(fn: () => T, options?: ITrackOptions): T;
42
+ /**
43
+ * Get the current call stack
44
+ *
45
+ * @returns The current call stack
46
+ */
47
+ getCallStack(): string[];
48
+ /**
49
+ * Generate a visual representation of the execution flow
50
+ *
51
+ * @returns ASCII flow chart of the execution
52
+ */
53
+ generateFlowChart(): string;
54
+ /**
55
+ * Clear all execution records
56
+ */
57
+ clear(): void;
58
+ /**
59
+ * Get all execution records
60
+ *
61
+ * @returns All execution records
62
+ */
63
+ getExecutions(): ExecutionRecord[];
64
+ /**
65
+ * Flatten the execution tree into a list
66
+ *
67
+ * @param executions - The execution records to flatten
68
+ * @returns A flat list of execution data
69
+ */
70
+ private flattenExecutions;
71
+ }
72
+ export {};