@visulima/pail 3.1.0 → 3.2.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 (76) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE.md +1 -408
  3. package/README.md +298 -0
  4. package/dist/index.browser.d.ts +3 -3
  5. package/dist/index.browser.js +12 -1
  6. package/dist/index.server.d.ts +8 -5
  7. package/dist/index.server.js +535 -2
  8. package/dist/interactive/index.js +2 -1
  9. package/dist/object-tree.js +89 -2
  10. package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
  11. package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
  12. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
  13. package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
  14. package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
  15. package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
  16. package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
  17. package/dist/packem_shared/{abstract-json-reporter-CPsNkpz8.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +1 -1
  18. package/dist/packem_shared/{abstract-pretty-reporter-DB2G-qlI.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
  19. package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
  20. package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
  21. package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
  22. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
  23. package/dist/packem_shared/index-BomQ3E6J.js +650 -0
  24. package/dist/packem_shared/index-DqKWykfa.js +1146 -0
  25. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
  26. package/dist/packem_shared/{pail.browser-CmWcqnn9.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
  27. package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
  28. package/dist/packem_shared/{types-DVzG8TWL.d.ts → types-D3ycu8-x.d.ts} +1 -1
  29. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
  30. package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
  31. package/dist/processor/caller/caller-processor.d.ts +1 -1
  32. package/dist/processor/caller/caller-processor.js +59 -1
  33. package/dist/processor/message-formatter-processor.d.ts +1 -1
  34. package/dist/processor/message-formatter-processor.js +67 -1
  35. package/dist/processor/opentelemetry-processor.d.ts +19 -0
  36. package/dist/processor/opentelemetry-processor.js +52 -0
  37. package/dist/processor/redact-processor.d.ts +1 -1
  38. package/dist/processor/redact-processor.js +30 -1
  39. package/dist/progress-bar.js +404 -1
  40. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  41. package/dist/reporter/file/json-file-reporter.js +136 -4
  42. package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
  43. package/dist/reporter/http/abstract-http-reporter.js +435 -0
  44. package/dist/reporter/http/http-reporter.d.ts +13 -0
  45. package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
  46. package/dist/reporter/http/http-reporter.edge-light.js +651 -0
  47. package/dist/reporter/http/http-reporter.js +13 -0
  48. package/dist/reporter/json/index.browser.d.ts +2 -2
  49. package/dist/reporter/json/index.browser.js +2 -1
  50. package/dist/reporter/json/index.d.ts +2 -2
  51. package/dist/reporter/json/index.js +2 -1
  52. package/dist/reporter/pretty/index.browser.d.ts +2 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +2 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +2 -2
  57. package/dist/reporter/simple/simple-reporter.server.js +186 -8
  58. package/dist/spinner.js +2150 -1
  59. package/package.json +53 -3
  60. package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
  61. package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
  62. package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
  63. package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
  64. package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
  65. package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
  66. package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
  67. package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
  68. package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
  69. package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
  70. package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
  71. package/dist/packem_shared/index-CysYvHXs.js +0 -8
  72. package/dist/packem_shared/index-D9hWq9ka.js +0 -1
  73. package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
  74. package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
  75. package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
  76. package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
@@ -0,0 +1,169 @@
1
+ import colorize, { grey, white, underline, bold } from '@visulima/colorize/browser';
2
+ import { f as format } from './index-BomQ3E6J.js';
3
+ import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
4
+ import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-DMPDCslJ.js';
5
+ import { g as getLongestLabel } from './get-longest-label-C9PWeyKq.js';
6
+ import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
7
+
8
+ class PrettyReporter extends AbstractPrettyReporter {
9
+ /**
10
+ * Creates a new Browser Pretty Reporter instance.
11
+ * @param options Styling options for pretty formatting
12
+ */
13
+ constructor(options = {}) {
14
+ super({
15
+ uppercase: {
16
+ label: true,
17
+ ...options.uppercase
18
+ },
19
+ ...options
20
+ });
21
+ }
22
+ // eslint-disable-next-line sonarjs/cognitive-complexity
23
+ log(meta) {
24
+ const isNotBrowser = typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
25
+ const consoleLogFunction = writeConsoleLogBasedOnLevel(meta.type.level);
26
+ const { badge, context, date, error, groups, label, message, prefix, repeated, scope, suffix, type } = meta;
27
+ const { color } = this.loggerTypes[type.name];
28
+ const colorized = color ? colorize[color] : white;
29
+ const items = [];
30
+ if (isNotBrowser && groups.length > 0) {
31
+ const groupSpaces = groups.map(() => " ").join("");
32
+ const cGroup = grey(`[${groups.at(-1)}]`);
33
+ items.push(format(groupSpaces + cGroup[0], cGroup.slice(1)));
34
+ }
35
+ if (date) {
36
+ const cDate = grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date));
37
+ if (isNotBrowser) {
38
+ items.push(format(cDate[0], cDate.slice(1)));
39
+ } else {
40
+ items.push([`${cDate[0]} `, ...cDate.slice(1)]);
41
+ }
42
+ }
43
+ if (badge) {
44
+ const cBadge = colorized(badge);
45
+ if (isNotBrowser) {
46
+ items.push(format(cBadge[0], cBadge.slice(1)));
47
+ } else {
48
+ items.push([`${cBadge[0]} `, ...cBadge.slice(1)]);
49
+ }
50
+ } else {
51
+ const longestBadge = getLongestBadge(this.loggerTypes);
52
+ if (longestBadge.length > 0) {
53
+ const cBadgePlaceholder = grey(".".repeat(longestBadge.length));
54
+ if (isNotBrowser) {
55
+ items.push(format(`${cBadgePlaceholder[0]} `, cBadgePlaceholder.slice(1)));
56
+ } else {
57
+ items.push([`${cBadgePlaceholder[0]} `, ...cBadgePlaceholder.slice(1)]);
58
+ }
59
+ }
60
+ }
61
+ const longestLabel = getLongestLabel(this.loggerTypes);
62
+ let repeatedMessage;
63
+ if (repeated) {
64
+ const cRepeated = white(`[${repeated}x]`);
65
+ repeatedMessage = isNotBrowser ? format(cRepeated[0], cRepeated.slice(1)) : [cRepeated[0], ...cRepeated.slice(1)];
66
+ }
67
+ if (label) {
68
+ const cLabel = colorized(this.#formatLabel(label));
69
+ if (isNotBrowser) {
70
+ items.push(format(cLabel[0], cLabel.slice(1)));
71
+ } else {
72
+ items.push([cLabel[0], ...cLabel.slice(1)]);
73
+ }
74
+ if (repeatedMessage) {
75
+ items.push(repeatedMessage);
76
+ }
77
+ let lengthDiff = longestLabel.length - label.length;
78
+ if (repeated) {
79
+ lengthDiff -= String(repeated).length + 3;
80
+ } else {
81
+ lengthDiff += 1;
82
+ }
83
+ if (lengthDiff > 0) {
84
+ const cLabelSpacer = grey(".".repeat(lengthDiff));
85
+ if (isNotBrowser) {
86
+ items.push(format(cLabelSpacer[0], cLabelSpacer.slice(1)));
87
+ } else {
88
+ items.push([` ${cLabelSpacer[0]}`, ...cLabelSpacer.slice(1)]);
89
+ }
90
+ }
91
+ } else {
92
+ const cSpacer = grey(".".repeat(longestLabel.length + 1));
93
+ if (isNotBrowser) {
94
+ items.push(format(cSpacer[0], cSpacer.slice(1)));
95
+ } else {
96
+ items.push([cSpacer[0], ...cSpacer.slice(1)]);
97
+ }
98
+ }
99
+ if (Array.isArray(scope) && scope.length > 0) {
100
+ const cScope = grey(`[${scope.join(" > ")}]`);
101
+ if (isNotBrowser) {
102
+ items.push(format(cScope[0], cScope.slice(1)));
103
+ } else {
104
+ items.push([cScope[0], ...cScope.slice(1)]);
105
+ }
106
+ }
107
+ if (prefix) {
108
+ const cPrefix = grey(
109
+ `${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}] `
110
+ );
111
+ if (isNotBrowser) {
112
+ items.push(format(cPrefix[0], cPrefix.slice(1)));
113
+ } else {
114
+ items.push([cPrefix[0], ...cPrefix.slice(1)]);
115
+ }
116
+ }
117
+ if (message !== EMPTY_SYMBOL) {
118
+ items.push(message);
119
+ }
120
+ if (context) {
121
+ items.push(...context);
122
+ }
123
+ if (error) {
124
+ items.push(error, "\n\n");
125
+ }
126
+ if (suffix) {
127
+ const cSuffix = grey(this.styles.underline.suffix ? underline(suffix) : suffix);
128
+ if (isNotBrowser) {
129
+ items.push(format(`
130
+ ${cSuffix[0]}`, cSuffix.slice(1)));
131
+ } else {
132
+ items.push([`
133
+ ${cSuffix[0]}`, ...cSuffix.slice(1)]);
134
+ }
135
+ }
136
+ if (isNotBrowser) {
137
+ consoleLogFunction(...items);
138
+ } else {
139
+ let logMessage = "";
140
+ const css = [];
141
+ const arguments_ = [];
142
+ for (const value of items) {
143
+ if (Array.isArray(value) && value.length > 1 && value[0].includes("%c")) {
144
+ logMessage += value[0];
145
+ css.push(...value.slice(1));
146
+ } else {
147
+ arguments_.push(value);
148
+ }
149
+ }
150
+ consoleLogFunction(`${logMessage}%c`, ...css, "", ...arguments_);
151
+ }
152
+ }
153
+ /**
154
+ * Formats a label according to styling options.
155
+ * @param label The label to format
156
+ * @returns The formatted label string
157
+ * @private
158
+ */
159
+ #formatLabel(label) {
160
+ let formattedLabel = this.styles.uppercase.label ? label.toUpperCase() : label;
161
+ formattedLabel = this.styles.underline.label ? underline(formattedLabel) : formattedLabel;
162
+ if (this.styles.bold.label) {
163
+ formattedLabel = bold(formattedLabel);
164
+ }
165
+ return formattedLabel;
166
+ }
167
+ }
168
+
169
+ export { PrettyReporter as default };
@@ -1,6 +1,6 @@
1
1
  import { s as stringify } from './index.d-oxZvg_y7.js';
2
2
  import { LiteralUnion } from 'type-fest';
3
- import { e as StringifyAwareReporter, f as ReadonlyMeta, E as ExtendedRfc5424LogLevels } from './types-DVzG8TWL.js';
3
+ import { f as StringifyAwareReporter, e as ReadonlyMeta, E as ExtendedRfc5424LogLevels } from './types-D3ycu8-x.js';
4
4
 
5
5
  type AbstractJsonReporterOptions = {
6
6
  error: Partial<{
@@ -1,5 +1,5 @@
1
1
  import { LiteralUnion } from 'type-fest';
2
- import { c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes, f as ReadonlyMeta } from './types-DVzG8TWL.js';
2
+ import { c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes, e as ReadonlyMeta } from './types-D3ycu8-x.js';
3
3
 
4
4
  declare abstract class AbstractPrettyReporter<T extends string = string, L extends string = string> implements LoggerTypesAwareReporter<T, L> {
5
5
  protected readonly styles: PrettyStyleOptions;
@@ -0,0 +1,50 @@
1
+ import { L as LOG_TYPES } from './constants-DfDr4MHC.js';
2
+
3
+ const getLongestBadge = (types) => {
4
+ const badges = Object.keys(types).map((x) => types[x].badge ?? "");
5
+ if (badges.length === 0) {
6
+ return "";
7
+ }
8
+ return badges.reduce((x, y) => x.length > y.length ? x : y);
9
+ };
10
+
11
+ const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
12
+ class AbstractPrettyReporter {
13
+ /** Styling options for pretty formatting */
14
+ styles;
15
+ /** Logger type configurations for styling */
16
+ loggerTypes;
17
+ /**
18
+ * Creates a new AbstractPrettyReporter instance.
19
+ * @param options Styling options for pretty formatting
20
+ * @protected
21
+ */
22
+ constructor(options) {
23
+ this.styles = {
24
+ bold: {
25
+ label: false
26
+ },
27
+ dateFormatter,
28
+ underline: {
29
+ label: false,
30
+ message: false,
31
+ prefix: false,
32
+ suffix: false
33
+ },
34
+ uppercase: {
35
+ label: false
36
+ },
37
+ ...options
38
+ };
39
+ this.loggerTypes = LOG_TYPES;
40
+ }
41
+ /**
42
+ * Sets the logger types configuration for styling.
43
+ * @param types Logger type configurations with colors and labels
44
+ */
45
+ setLoggerTypes(types) {
46
+ this.loggerTypes = types;
47
+ }
48
+ }
49
+
50
+ export { AbstractPrettyReporter as A, getLongestBadge as g };
@@ -0,0 +1,119 @@
1
+ const EXTENDED_RFC_5424_LOG_LEVELS = {
2
+ alert: 7,
3
+ // Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
4
+ critical: 6,
5
+ // Critical conditions. Example: Application component unavailable, unexpected exception.
6
+ debug: 1,
7
+ // Detailed debug information.
8
+ emergency: 8,
9
+ // Emergency: system is unusable.
10
+ error: 5,
11
+ // Runtime errors that do not require immediate action but should typically be logged and monitored.
12
+ informational: 2,
13
+ // Interesting events. Examples: User logs in, SQL logs.
14
+ notice: 3,
15
+ // Normal but significant events.
16
+ trace: 2,
17
+ // Trace information.
18
+ warning: 4
19
+ // Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
20
+ };
21
+ const LOG_TYPES = {
22
+ alert: {
23
+ color: "red",
24
+ label: "alert",
25
+ logLevel: "alert"
26
+ },
27
+ await: {
28
+ color: "blue",
29
+ label: "awaiting",
30
+ logLevel: "informational"
31
+ },
32
+ complete: {
33
+ color: "cyan",
34
+ label: "complete",
35
+ logLevel: "informational"
36
+ },
37
+ critical: {
38
+ color: "redBright",
39
+ label: "critical",
40
+ logLevel: "critical"
41
+ },
42
+ debug: {
43
+ color: "gray",
44
+ label: "debug",
45
+ logLevel: "debug"
46
+ },
47
+ emergency: {
48
+ color: "redBright",
49
+ label: "emergency",
50
+ logLevel: "emergency"
51
+ },
52
+ error: {
53
+ color: "red",
54
+ label: "error",
55
+ logLevel: "error"
56
+ },
57
+ info: {
58
+ color: "blueBright",
59
+ label: "info",
60
+ logLevel: "informational"
61
+ },
62
+ log: {
63
+ label: "",
64
+ logLevel: "informational"
65
+ },
66
+ notice: {
67
+ color: "magentaBright",
68
+ label: "notice",
69
+ logLevel: "notice"
70
+ },
71
+ pending: {
72
+ color: "magenta",
73
+ label: "pending",
74
+ logLevel: "informational"
75
+ },
76
+ start: {
77
+ color: "greenBright",
78
+ label: "start",
79
+ logLevel: "informational"
80
+ },
81
+ stop: {
82
+ color: "red",
83
+ label: "stop",
84
+ logLevel: "informational"
85
+ },
86
+ success: {
87
+ color: "green",
88
+ label: "success",
89
+ logLevel: "informational"
90
+ },
91
+ trace: {
92
+ color: "cyanBright",
93
+ label: "trace",
94
+ logLevel: "trace"
95
+ },
96
+ wait: {
97
+ color: "blue",
98
+ label: "waiting",
99
+ logLevel: "informational"
100
+ },
101
+ warn: {
102
+ color: "yellow",
103
+ label: "warning",
104
+ logLevel: "warning"
105
+ },
106
+ warning: {
107
+ color: "yellow",
108
+ label: "warning",
109
+ logLevel: "warning"
110
+ },
111
+ watch: {
112
+ color: "yellowBright",
113
+ label: "watching",
114
+ logLevel: "informational"
115
+ }
116
+ };
117
+ const EMPTY_SYMBOL = Symbol("EMPTY");
118
+
119
+ export { EMPTY_SYMBOL as E, LOG_TYPES as L, EXTENDED_RFC_5424_LOG_LEVELS as a };