traceperf 0.1.0 → 0.1.2

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 (75) hide show
  1. package/README.md +110 -1
  2. package/dist/browser.d.ts +67 -5
  3. package/dist/browser.js +207 -36
  4. package/dist/browser.js.map +1 -1
  5. package/dist/esm/browser.d.ts +129 -0
  6. package/dist/esm/browser.js +426 -0
  7. package/dist/esm/browser.js.map +1 -0
  8. package/dist/esm/core/config.d.ts +77 -0
  9. package/dist/esm/core/config.js +112 -0
  10. package/dist/esm/core/config.js.map +1 -0
  11. package/dist/esm/core/constants.d.ts +78 -0
  12. package/dist/esm/core/constants.js +106 -0
  13. package/dist/esm/core/constants.js.map +1 -0
  14. package/dist/esm/core/index.d.ts +3 -0
  15. package/dist/esm/core/index.js +4 -0
  16. package/dist/esm/core/index.js.map +1 -0
  17. package/dist/esm/core/logger.d.ts +84 -0
  18. package/dist/esm/core/logger.js +170 -0
  19. package/dist/esm/core/logger.js.map +1 -0
  20. package/dist/esm/formatters/ascii.d.ts +52 -0
  21. package/dist/esm/formatters/ascii.js +100 -0
  22. package/dist/esm/formatters/ascii.js.map +1 -0
  23. package/dist/esm/formatters/cli.d.ts +50 -0
  24. package/dist/esm/formatters/cli.js +96 -0
  25. package/dist/esm/formatters/cli.js.map +1 -0
  26. package/dist/esm/formatters/index.d.ts +3 -0
  27. package/dist/esm/formatters/index.js +4 -0
  28. package/dist/esm/formatters/index.js.map +1 -0
  29. package/dist/esm/formatters/json.d.ts +45 -0
  30. package/dist/esm/formatters/json.js +85 -0
  31. package/dist/esm/formatters/json.js.map +1 -0
  32. package/dist/esm/index.d.ts +10 -0
  33. package/dist/esm/index.js +29 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/trackers/execution.d.ts +88 -0
  36. package/dist/esm/trackers/execution.js +214 -0
  37. package/dist/esm/trackers/execution.js.map +1 -0
  38. package/dist/esm/trackers/index.d.ts +2 -0
  39. package/dist/esm/trackers/index.js +3 -0
  40. package/dist/esm/trackers/index.js.map +1 -0
  41. package/dist/esm/trackers/performance.d.ts +82 -0
  42. package/dist/esm/trackers/performance.js +106 -0
  43. package/dist/esm/trackers/performance.js.map +1 -0
  44. package/dist/esm/types/config.d.ts +110 -0
  45. package/dist/esm/types/config.js +2 -0
  46. package/dist/esm/types/config.js.map +1 -0
  47. package/dist/esm/types/index.d.ts +34 -0
  48. package/dist/esm/types/index.js +3 -0
  49. package/dist/esm/types/index.js.map +1 -0
  50. package/dist/esm/types/logger.d.ts +127 -0
  51. package/dist/esm/types/logger.js +2 -0
  52. package/dist/esm/types/logger.js.map +1 -0
  53. package/dist/esm/utils/colors.d.ts +87 -0
  54. package/dist/esm/utils/colors.js +134 -0
  55. package/dist/esm/utils/colors.js.map +1 -0
  56. package/dist/esm/utils/index.d.ts +3 -0
  57. package/dist/esm/utils/index.js +4 -0
  58. package/dist/esm/utils/index.js.map +1 -0
  59. package/dist/esm/utils/stack.d.ts +63 -0
  60. package/dist/esm/utils/stack.js +110 -0
  61. package/dist/esm/utils/stack.js.map +1 -0
  62. package/dist/esm/utils/timing.d.ts +65 -0
  63. package/dist/esm/utils/timing.js +99 -0
  64. package/dist/esm/utils/timing.js.map +1 -0
  65. package/dist/index.js +13 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/trackers/execution.d.ts +23 -7
  68. package/dist/trackers/execution.js +100 -29
  69. package/dist/trackers/execution.js.map +1 -1
  70. package/dist/types/config.js +2 -1
  71. package/dist/types/index.d.ts +32 -0
  72. package/dist/types/index.js +18 -2
  73. package/dist/types/index.js.map +1 -1
  74. package/dist/types/logger.js +2 -1
  75. package/package.json +16 -2
@@ -0,0 +1,100 @@
1
+ import { BOX_CHARS, PERFORMANCE_ICONS } from '../core/constants';
2
+ import { formatDuration } from '../utils/timing';
3
+ /**
4
+ * ASCII art generator for execution flow charts
5
+ */
6
+ export class AsciiArtGenerator {
7
+ /**
8
+ * Create a new AsciiArtGenerator instance
9
+ *
10
+ * @param options - Generator options
11
+ */
12
+ constructor(options = {}) {
13
+ var _a;
14
+ this._boxWidth = (_a = options.boxWidth) !== null && _a !== void 0 ? _a : 30;
15
+ }
16
+ /**
17
+ * Generate a flow chart for a sequence of function executions
18
+ *
19
+ * @param executions - Array of execution data
20
+ * @returns ASCII art flow chart
21
+ */
22
+ generateFlowChart(executions) {
23
+ let chart = '';
24
+ for (let i = 0; i < executions.length; i++) {
25
+ const execution = executions[i];
26
+ // Generate box for function
27
+ chart += this.generateFunctionBox(execution);
28
+ // Add arrow to next function if not the last one
29
+ if (i < executions.length - 1) {
30
+ chart += this.generateArrow(executions[i + 1].level - execution.level);
31
+ }
32
+ }
33
+ return chart;
34
+ }
35
+ /**
36
+ * Generate a box for a function execution
37
+ *
38
+ * @param execution - The execution data
39
+ * @returns ASCII art box
40
+ */
41
+ generateFunctionBox(execution) {
42
+ const { name, duration, isSlow, memoryUsage } = execution;
43
+ // Calculate padding for the function name
44
+ const nameLength = name.length;
45
+ const padding = Math.max(0, this._boxWidth - nameLength - 2);
46
+ const leftPadding = Math.floor(padding / 2);
47
+ const rightPadding = padding - leftPadding;
48
+ // Generate the box
49
+ let box = '';
50
+ // Top border
51
+ box += BOX_CHARS.topLeft + BOX_CHARS.horizontal.repeat(this._boxWidth) + BOX_CHARS.topRight + '\n';
52
+ // Function name
53
+ box += BOX_CHARS.vertical + ' '.repeat(leftPadding) + name + ' '.repeat(rightPadding) + BOX_CHARS.vertical;
54
+ // Performance metrics
55
+ box += ` ${PERFORMANCE_ICONS.timer} ${formatDuration(duration)}`;
56
+ if (isSlow) {
57
+ box += ` ${PERFORMANCE_ICONS.slow} SLOW`;
58
+ }
59
+ if (memoryUsage !== undefined) {
60
+ box += ` ${PERFORMANCE_ICONS.memory} ${this.formatMemory(memoryUsage)}`;
61
+ }
62
+ box += '\n';
63
+ // Bottom border
64
+ box += BOX_CHARS.bottomLeft + BOX_CHARS.horizontal.repeat(this._boxWidth) + BOX_CHARS.bottomRight + '\n';
65
+ return box;
66
+ }
67
+ /**
68
+ * Generate an arrow between function boxes
69
+ *
70
+ * @param levelDiff - Difference in nesting level
71
+ * @returns ASCII art arrow
72
+ */
73
+ generateArrow(levelDiff) {
74
+ let arrow = '';
75
+ // Indent based on level difference
76
+ const indent = ' '.repeat(Math.max(0, levelDiff));
77
+ // Vertical line
78
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + BOX_CHARS.vertical + '\n';
79
+ // Arrow
80
+ arrow += indent + ' '.repeat(this._boxWidth / 2) + BOX_CHARS.downArrow + '\n';
81
+ return arrow;
82
+ }
83
+ /**
84
+ * Format memory usage in a human-readable format
85
+ *
86
+ * @param bytes - Memory usage in bytes
87
+ * @returns Formatted memory usage
88
+ */
89
+ formatMemory(bytes) {
90
+ const units = ['B', 'KB', 'MB', 'GB'];
91
+ let size = bytes;
92
+ let unitIndex = 0;
93
+ while (size >= 1024 && unitIndex < units.length - 1) {
94
+ size /= 1024;
95
+ unitIndex++;
96
+ }
97
+ return `${size.toFixed(2)}${units[unitIndex]}`;
98
+ }
99
+ }
100
+ //# sourceMappingURL=ascii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ascii.js","sourceRoot":"","sources":["../../../src/formatters/ascii.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD;;GAEG;AACH,MAAM,OAAO,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,CA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,IAAI,CAAC,CAAC;QACtC,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,OAAO,IAAI,IAAI,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpD,IAAI,IAAI,IAAI,CAAC;YACb,SAAS,EAAE,CAAC;QACd,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { IFormatter, LogLevel, LogMeta } from '../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,96 @@
1
+ import { LEVEL_COLORS, LEVEL_ICONS } from '../core/constants';
2
+ import { colorize, dim, supportsColor } from '../utils/colors';
3
+ /**
4
+ * CLI formatter for console output
5
+ * Formats log entries with colors, icons, and indentation
6
+ */
7
+ export class CliFormatter {
8
+ /**
9
+ * Create a new CliFormatter instance
10
+ *
11
+ * @param options - Formatter options
12
+ */
13
+ constructor(options = {}) {
14
+ var _a, _b;
15
+ this._colorEnabled = (_a = options.colorEnabled) !== null && _a !== void 0 ? _a : supportsColor();
16
+ this._indentSize = (_b = options.indentSize) !== null && _b !== void 0 ? _b : 2;
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, message, args, meta) {
28
+ const timestamp = this.formatTimestamp(meta.timestamp);
29
+ const levelStr = this.formatLevel(level);
30
+ const indent = ' '.repeat(meta.indentLevel * this._indentSize);
31
+ const formattedMessage = this.formatMessage(message, args);
32
+ return `${timestamp} ${levelStr} ${indent}${formattedMessage}`;
33
+ }
34
+ /**
35
+ * Format a timestamp
36
+ *
37
+ * @param date - The date to format
38
+ * @returns The formatted timestamp
39
+ */
40
+ formatTimestamp(date) {
41
+ const timeStr = date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
42
+ return this._colorEnabled ? dim(`[${timeStr}]`) : `[${timeStr}]`;
43
+ }
44
+ /**
45
+ * Format a log level
46
+ *
47
+ * @param level - The log level
48
+ * @returns The formatted log level
49
+ */
50
+ formatLevel(level) {
51
+ const icon = LEVEL_ICONS[level];
52
+ const text = level.toUpperCase();
53
+ if (this._colorEnabled) {
54
+ return colorize(`${icon} ${text}`, LEVEL_COLORS[level]);
55
+ }
56
+ return `${icon} ${text}`;
57
+ }
58
+ /**
59
+ * Format a message and its arguments
60
+ *
61
+ * @param message - The message to format
62
+ * @param args - Additional arguments
63
+ * @returns The formatted message
64
+ */
65
+ formatMessage(message, args) {
66
+ let formattedMessage;
67
+ if (typeof message === 'string') {
68
+ formattedMessage = message;
69
+ }
70
+ else {
71
+ try {
72
+ formattedMessage = JSON.stringify(message, null, 2);
73
+ }
74
+ catch (error) {
75
+ formattedMessage = String(message);
76
+ }
77
+ }
78
+ // Format additional arguments
79
+ if (args.length > 0) {
80
+ const formattedArgs = args.map(arg => {
81
+ if (typeof arg === 'object' && arg !== null) {
82
+ try {
83
+ return JSON.stringify(arg, null, 2);
84
+ }
85
+ catch (error) {
86
+ return String(arg);
87
+ }
88
+ }
89
+ return String(arg);
90
+ }).join(' ');
91
+ formattedMessage = `${formattedMessage} ${formattedArgs}`;
92
+ }
93
+ return formattedMessage;
94
+ }
95
+ }
96
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/formatters/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;GAGG;AACH,MAAM,OAAO,YAAY;IAIvB;;;;OAIG;IACH,YAAY,UAA2D,EAAE;;QACvE,IAAI,CAAC,aAAa,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,aAAa,EAAE,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,GAA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,8BAA8B;QAC9B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;oBAC5C,IAAI,CAAC;wBACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;oBACtC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;oBACrB,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"}
@@ -0,0 +1,3 @@
1
+ export * from './cli';
2
+ export * from './json';
3
+ export * from './ascii';
@@ -0,0 +1,4 @@
1
+ export * from './cli';
2
+ export * from './json';
3
+ export * from './ascii';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/formatters/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -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,85 @@
1
+ /**
2
+ * JSON formatter for structured output
3
+ * Formats log entries as JSON objects
4
+ */
5
+ export class JsonFormatter {
6
+ /**
7
+ * Format a log entry as JSON
8
+ *
9
+ * @param level - The log level
10
+ * @param message - The log message
11
+ * @param args - Additional arguments
12
+ * @param meta - Metadata for the log entry
13
+ * @returns The formatted log entry as a JSON string
14
+ */
15
+ format(level, message, args, meta) {
16
+ const logEntry = {
17
+ timestamp: meta.timestamp.toISOString(),
18
+ level,
19
+ indentLevel: meta.indentLevel,
20
+ message: this.formatMessage(message),
21
+ args: this.formatArgs(args),
22
+ ...this.extractExtraMeta(meta),
23
+ };
24
+ return JSON.stringify(logEntry);
25
+ }
26
+ /**
27
+ * Format a message for JSON output
28
+ *
29
+ * @param message - The message to format
30
+ * @returns The formatted message
31
+ */
32
+ formatMessage(message) {
33
+ if (typeof message === 'string') {
34
+ return message;
35
+ }
36
+ return this.sanitizeObject(message);
37
+ }
38
+ /**
39
+ * Format arguments for JSON output
40
+ *
41
+ * @param args - The arguments to format
42
+ * @returns The formatted arguments
43
+ */
44
+ formatArgs(args) {
45
+ return args.map(arg => {
46
+ if (typeof arg === 'object' && arg !== null) {
47
+ return this.sanitizeObject(arg);
48
+ }
49
+ return arg;
50
+ });
51
+ }
52
+ /**
53
+ * Sanitize an object for JSON serialization
54
+ *
55
+ * @param obj - The object to sanitize
56
+ * @returns A sanitized version of the object
57
+ */
58
+ sanitizeObject(obj) {
59
+ try {
60
+ // Use JSON.parse(JSON.stringify()) to remove non-serializable values
61
+ return JSON.parse(JSON.stringify(obj));
62
+ }
63
+ catch (error) {
64
+ // If serialization fails, return a simplified object
65
+ return { value: String(obj) };
66
+ }
67
+ }
68
+ /**
69
+ * Extract additional metadata from the log meta object
70
+ *
71
+ * @param meta - The log metadata
72
+ * @returns Additional metadata as an object
73
+ */
74
+ extractExtraMeta(meta) {
75
+ const result = {};
76
+ // Copy all properties except the standard ones
77
+ Object.keys(meta).forEach(key => {
78
+ if (!['timestamp', 'level', 'indentLevel'].includes(key)) {
79
+ result[key] = meta[key];
80
+ }
81
+ });
82
+ return result;
83
+ }
84
+ }
85
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/formatters/json.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,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,gBAAgB,CAAC,IAAI,CAAC;SAC/B,CAAC;QAEF,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACK,aAAa,CAAC,OAAwB;QAC5C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAAC,IAAW;QAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,GAAW;QAChC,IAAI,CAAC;YACH,qEAAqE;YACrE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qDAAqD;YACrD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,IAAa;QACpC,MAAM,MAAM,GAAwB,EAAE,CAAC;QAEvC,+CAA+C;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -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';
@@ -0,0 +1,29 @@
1
+ import { Logger } from './core/logger';
2
+ // Create a singleton instance of the logger
3
+ const defaultLogger = new Logger();
4
+ // Export the singleton instance as the default export
5
+ export default defaultLogger;
6
+ // Export a function to create a new logger instance
7
+ export function createLogger(config = {}) {
8
+ return new Logger(config);
9
+ }
10
+ // Export types and classes for advanced usage
11
+ export * from './types';
12
+ export * from './core';
13
+ export * from './formatters';
14
+ export * from './trackers';
15
+ export * from './utils';
16
+ // Add CommonJS compatibility
17
+ if (typeof module !== 'undefined' && module.exports) {
18
+ module.exports = Object.assign(defaultLogger, {
19
+ default: defaultLogger,
20
+ createLogger,
21
+ // Re-export everything from the modules
22
+ ...require('./types'),
23
+ ...require('./core'),
24
+ ...require('./formatters'),
25
+ ...require('./trackers'),
26
+ ...require('./utils')
27
+ });
28
+ }
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvC,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,MAAM,EAAE,CAAC;AAEnC,sDAAsD;AACtD,eAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,MAAM,UAAU,YAAY,CAAC,SAAiC,EAAE;IAC9D,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,8CAA8C;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;QAC5C,OAAO,EAAE,aAAa;QACtB,YAAY;QACZ,wCAAwC;QACxC,GAAG,OAAO,CAAC,SAAS,CAAC;QACrB,GAAG,OAAO,CAAC,QAAQ,CAAC;QACpB,GAAG,OAAO,CAAC,cAAc,CAAC;QAC1B,GAAG,OAAO,CAAC,YAAY,CAAC;QACxB,GAAG,OAAO,CAAC,SAAS,CAAC;KACtB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,88 @@
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
+ private _instrumentedFunctions;
26
+ private _isInstrumented;
27
+ /**
28
+ * Create a new ExecutionTracker instance
29
+ *
30
+ * @param options - Tracker options
31
+ */
32
+ constructor(options?: {
33
+ defaultThreshold?: number;
34
+ boxWidth?: number;
35
+ });
36
+ /**
37
+ * Track the execution of a function
38
+ *
39
+ * @param fn - The function to track
40
+ * @param options - Options for tracking
41
+ * @returns The return value of the tracked function
42
+ */
43
+ track<T>(fn: () => T, options?: ITrackOptions): T;
44
+ /**
45
+ * Instrument a function to track nested function calls
46
+ *
47
+ * @param fn - The function to instrument
48
+ * @returns The instrumented function
49
+ */
50
+ private instrumentFunction;
51
+ /**
52
+ * Get the current call stack
53
+ *
54
+ * @returns The current call stack
55
+ */
56
+ getCallStack(): string[];
57
+ /**
58
+ * Generate a visual representation of the execution flow
59
+ *
60
+ * @returns ASCII flow chart of the execution
61
+ */
62
+ generateFlowChart(): string;
63
+ /**
64
+ * Prepare execution data for the ASCII generator
65
+ *
66
+ * @param executions - The execution records to prepare
67
+ * @returns A list of execution data
68
+ */
69
+ private prepareExecutionData;
70
+ /**
71
+ * Add children to the result list
72
+ *
73
+ * @param children - The children to add
74
+ * @param result - The result list
75
+ */
76
+ private addChildrenToResult;
77
+ /**
78
+ * Clear all execution records
79
+ */
80
+ clear(): void;
81
+ /**
82
+ * Get all execution records
83
+ *
84
+ * @returns All execution records
85
+ */
86
+ getExecutions(): ExecutionRecord[];
87
+ }
88
+ export {};