@visulima/pail 4.0.0-alpha.9 → 4.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 (145) hide show
  1. package/CHANGELOG.md +519 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +43 -58
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,286 +0,0 @@
1
- import { E as EMPTY_SYMBOL } from './constants-B1RjD_ps.js';
2
-
3
- function isPlainObject(value) {
4
- if (typeof value !== "object" || value === null) {
5
- return false;
6
- }
7
- const prototype = Object.getPrototypeOf(value);
8
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
9
- }
10
-
11
- const ErrorProto = Object.create(
12
- {},
13
- {
14
- cause: {
15
- enumerable: false,
16
- value: void 0,
17
- writable: true
18
- },
19
- code: {
20
- enumerable: true,
21
- value: void 0,
22
- writable: true
23
- },
24
- errors: {
25
- enumerable: false,
26
- value: void 0,
27
- writable: true
28
- },
29
- message: {
30
- enumerable: false,
31
- value: void 0,
32
- writable: true
33
- },
34
- name: {
35
- enumerable: false,
36
- value: void 0,
37
- writable: true
38
- },
39
- stack: {
40
- enumerable: false,
41
- value: void 0,
42
- writable: true
43
- }
44
- }
45
- );
46
- const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
47
- const makePropertiesEnumerable = (object) => {
48
- if (!object || typeof object !== "object") {
49
- return;
50
- }
51
- const props = Object.getOwnPropertyNames(object);
52
- for (const prop of props) {
53
- const descriptor = Object.getOwnPropertyDescriptor(object, prop);
54
- if (descriptor) {
55
- if (!descriptor.enumerable) {
56
- Object.defineProperty(object, prop, {
57
- ...descriptor,
58
- enumerable: true
59
- });
60
- }
61
- if (descriptor.value && typeof descriptor.value === "object" && !Array.isArray(descriptor.value) && (Object.getPrototypeOf(descriptor.value) === Object.prototype || Object.getPrototypeOf(descriptor.value) === null)) {
62
- makePropertiesEnumerable(descriptor.value);
63
- }
64
- }
65
- }
66
- };
67
- const toJSON = (from) => {
68
- toJsonWasCalled.add(from);
69
- const json = from.toJSON();
70
- toJsonWasCalled.delete(from);
71
- if (json && typeof json === "object" && Object.isExtensible(json)) {
72
- makePropertiesEnumerable(json);
73
- }
74
- return json;
75
- };
76
- const serializeValue = (value, seen, depth, options) => {
77
- if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
78
- return "[object Buffer]";
79
- }
80
- if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
81
- return "[object Stream]";
82
- }
83
- if (value instanceof Error) {
84
- if (seen.has(value)) {
85
- return "[Circular]";
86
- }
87
- depth += 1;
88
- return _serialize(value, options, seen, depth);
89
- }
90
- if (options.useToJSON && typeof value.toJSON === "function") {
91
- return value.toJSON();
92
- }
93
- if (typeof value === "object" && value instanceof Date) {
94
- return value.toISOString();
95
- }
96
- if (typeof value === "function") {
97
- return `[Function: ${value.name || "anonymous"}]`;
98
- }
99
- if (typeof value === "bigint") {
100
- return `${value}n`;
101
- }
102
- if (isPlainObject(value)) {
103
- if (options.maxDepth !== void 0 && options.maxDepth !== Number.POSITIVE_INFINITY && depth + 1 >= options.maxDepth) {
104
- return {};
105
- }
106
- depth += 1;
107
- const plainObject = {};
108
- for (const key in value) {
109
- plainObject[key] = serializeValue(value[key], seen, depth, options);
110
- }
111
- return plainObject;
112
- }
113
- try {
114
- return value;
115
- } catch {
116
- return "[Not Available]";
117
- }
118
- };
119
- const _serialize = (error, options, seen, depth) => {
120
- seen.add(error);
121
- if (options.maxDepth === 0) {
122
- return {};
123
- }
124
- if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
125
- return toJSON(error);
126
- }
127
- const protoError = Object.create(ErrorProto);
128
- Object.defineProperty(protoError, "name", {
129
- configurable: true,
130
- enumerable: true,
131
- value: Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name,
132
- writable: true
133
- });
134
- Object.defineProperty(protoError, "message", {
135
- configurable: true,
136
- enumerable: true,
137
- value: error.message,
138
- writable: true
139
- });
140
- Object.defineProperty(protoError, "stack", {
141
- configurable: true,
142
- enumerable: true,
143
- value: error.stack,
144
- writable: true
145
- });
146
- if (Array.isArray(error.errors)) {
147
- const aggregateErrors = [];
148
- for (const aggregateError of error.errors) {
149
- if (!(aggregateError instanceof Error)) {
150
- throw new TypeError("All errors in the 'errors' property must be instances of Error");
151
- }
152
- if (seen.has(aggregateError)) {
153
- Object.defineProperty(protoError, "errors", {
154
- configurable: true,
155
- enumerable: true,
156
- value: [],
157
- writable: true
158
- });
159
- return protoError;
160
- }
161
- aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
162
- }
163
- Object.defineProperty(protoError, "errors", {
164
- configurable: true,
165
- enumerable: true,
166
- value: aggregateErrors,
167
- writable: true
168
- });
169
- }
170
- if (error.cause !== void 0 && error.cause !== null) {
171
- if (error.cause instanceof Error) {
172
- if (seen.has(error.cause)) {
173
- Object.defineProperty(protoError, "cause", {
174
- configurable: true,
175
- enumerable: true,
176
- value: "[Circular]",
177
- writable: true
178
- });
179
- } else {
180
- Object.defineProperty(protoError, "cause", {
181
- configurable: true,
182
- enumerable: true,
183
- value: _serialize(error.cause, options, seen, depth),
184
- writable: true
185
- });
186
- }
187
- } else {
188
- const serializedCause = serializeValue(error.cause, seen, depth, options);
189
- Object.defineProperty(protoError, "cause", {
190
- configurable: true,
191
- enumerable: true,
192
- value: serializedCause,
193
- writable: true
194
- });
195
- }
196
- }
197
- for (const key in error) {
198
- if (key === "name" || key === "message" || key === "stack" || key === "cause" || key === "errors") {
199
- continue;
200
- }
201
- const value = error[key];
202
- const serializedValue = serializeValue(value, seen, depth, options);
203
- Object.defineProperty(protoError, key, {
204
- configurable: true,
205
- enumerable: true,
206
- value: serializedValue,
207
- writable: true
208
- });
209
- }
210
- if (Array.isArray(options.exclude) && options.exclude.length > 0) {
211
- for (const key of options.exclude) {
212
- try {
213
- delete protoError[key];
214
- } catch {
215
- }
216
- }
217
- }
218
- return protoError;
219
- };
220
- const serialize = (error, options = {}) => _serialize(
221
- error,
222
- {
223
- exclude: options.exclude ?? [],
224
- maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
225
- useToJSON: options.useToJSON ?? false
226
- },
227
- /* @__PURE__ */ new Set(),
228
- 0
229
- );
230
-
231
- class AbstractJsonReporter {
232
- /** Custom stringify function for object serialization */
233
- stringify;
234
- /** Error serialization options */
235
- errorOptions;
236
- /**
237
- * Creates a new AbstractJsonReporter instance.
238
- * @param options Configuration options for JSON formatting and error handling
239
- */
240
- constructor(options = {}) {
241
- this.errorOptions = options.error ?? {};
242
- }
243
- /**
244
- * Sets a custom stringify function for object serialization.
245
- * @param function_ The stringify function to use for serialization
246
- */
247
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
248
- setStringify(function_) {
249
- this.stringify = function_;
250
- }
251
- // eslint-disable-next-line sonarjs/cognitive-complexity
252
- log(meta) {
253
- const { context, error, file, message, type, ...rest } = meta;
254
- if (rest.label) {
255
- rest.label = rest.label.trim();
256
- }
257
- if (file) {
258
- rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
259
- }
260
- if (message === EMPTY_SYMBOL) {
261
- rest.message = void 0;
262
- } else {
263
- rest.message = message;
264
- }
265
- if (error) {
266
- rest.error = serialize(error, this.errorOptions);
267
- }
268
- if (context) {
269
- const newContext = [];
270
- for (const item of context) {
271
- if (item === EMPTY_SYMBOL) {
272
- continue;
273
- }
274
- if (item instanceof Error) {
275
- newContext.push(serialize(item, this.errorOptions));
276
- } else {
277
- newContext.push(item);
278
- }
279
- }
280
- rest.context = newContext;
281
- }
282
- this._log(this.stringify(rest), type.level);
283
- }
284
- }
285
-
286
- export { AbstractJsonReporter };
@@ -1,286 +0,0 @@
1
- import { E as EMPTY_SYMBOL } from './constants-omsTHUWB.js';
2
-
3
- function isPlainObject(value) {
4
- if (typeof value !== "object" || value === null) {
5
- return false;
6
- }
7
- const prototype = Object.getPrototypeOf(value);
8
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
9
- }
10
-
11
- const ErrorProto = Object.create(
12
- {},
13
- {
14
- cause: {
15
- enumerable: false,
16
- value: void 0,
17
- writable: true
18
- },
19
- code: {
20
- enumerable: true,
21
- value: void 0,
22
- writable: true
23
- },
24
- errors: {
25
- enumerable: false,
26
- value: void 0,
27
- writable: true
28
- },
29
- message: {
30
- enumerable: false,
31
- value: void 0,
32
- writable: true
33
- },
34
- name: {
35
- enumerable: false,
36
- value: void 0,
37
- writable: true
38
- },
39
- stack: {
40
- enumerable: false,
41
- value: void 0,
42
- writable: true
43
- }
44
- }
45
- );
46
- const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
47
- const makePropertiesEnumerable = (object) => {
48
- if (!object || typeof object !== "object") {
49
- return;
50
- }
51
- const props = Object.getOwnPropertyNames(object);
52
- for (const prop of props) {
53
- const descriptor = Object.getOwnPropertyDescriptor(object, prop);
54
- if (descriptor) {
55
- if (!descriptor.enumerable) {
56
- Object.defineProperty(object, prop, {
57
- ...descriptor,
58
- enumerable: true
59
- });
60
- }
61
- if (descriptor.value && typeof descriptor.value === "object" && !Array.isArray(descriptor.value) && (Object.getPrototypeOf(descriptor.value) === Object.prototype || Object.getPrototypeOf(descriptor.value) === null)) {
62
- makePropertiesEnumerable(descriptor.value);
63
- }
64
- }
65
- }
66
- };
67
- const toJSON = (from) => {
68
- toJsonWasCalled.add(from);
69
- const json = from.toJSON();
70
- toJsonWasCalled.delete(from);
71
- if (json && typeof json === "object" && Object.isExtensible(json)) {
72
- makePropertiesEnumerable(json);
73
- }
74
- return json;
75
- };
76
- const serializeValue = (value, seen, depth, options) => {
77
- if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
78
- return "[object Buffer]";
79
- }
80
- if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
81
- return "[object Stream]";
82
- }
83
- if (value instanceof Error) {
84
- if (seen.has(value)) {
85
- return "[Circular]";
86
- }
87
- depth += 1;
88
- return _serialize(value, options, seen, depth);
89
- }
90
- if (options.useToJSON && typeof value.toJSON === "function") {
91
- return value.toJSON();
92
- }
93
- if (typeof value === "object" && value instanceof Date) {
94
- return value.toISOString();
95
- }
96
- if (typeof value === "function") {
97
- return `[Function: ${value.name || "anonymous"}]`;
98
- }
99
- if (typeof value === "bigint") {
100
- return `${value}n`;
101
- }
102
- if (isPlainObject(value)) {
103
- if (options.maxDepth !== void 0 && options.maxDepth !== Number.POSITIVE_INFINITY && depth + 1 >= options.maxDepth) {
104
- return {};
105
- }
106
- depth += 1;
107
- const plainObject = {};
108
- for (const key in value) {
109
- plainObject[key] = serializeValue(value[key], seen, depth, options);
110
- }
111
- return plainObject;
112
- }
113
- try {
114
- return value;
115
- } catch {
116
- return "[Not Available]";
117
- }
118
- };
119
- const _serialize = (error, options, seen, depth) => {
120
- seen.add(error);
121
- if (options.maxDepth === 0) {
122
- return {};
123
- }
124
- if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
125
- return toJSON(error);
126
- }
127
- const protoError = Object.create(ErrorProto);
128
- Object.defineProperty(protoError, "name", {
129
- configurable: true,
130
- enumerable: true,
131
- value: Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name,
132
- writable: true
133
- });
134
- Object.defineProperty(protoError, "message", {
135
- configurable: true,
136
- enumerable: true,
137
- value: error.message,
138
- writable: true
139
- });
140
- Object.defineProperty(protoError, "stack", {
141
- configurable: true,
142
- enumerable: true,
143
- value: error.stack,
144
- writable: true
145
- });
146
- if (Array.isArray(error.errors)) {
147
- const aggregateErrors = [];
148
- for (const aggregateError of error.errors) {
149
- if (!(aggregateError instanceof Error)) {
150
- throw new TypeError("All errors in the 'errors' property must be instances of Error");
151
- }
152
- if (seen.has(aggregateError)) {
153
- Object.defineProperty(protoError, "errors", {
154
- configurable: true,
155
- enumerable: true,
156
- value: [],
157
- writable: true
158
- });
159
- return protoError;
160
- }
161
- aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
162
- }
163
- Object.defineProperty(protoError, "errors", {
164
- configurable: true,
165
- enumerable: true,
166
- value: aggregateErrors,
167
- writable: true
168
- });
169
- }
170
- if (error.cause !== void 0 && error.cause !== null) {
171
- if (error.cause instanceof Error) {
172
- if (seen.has(error.cause)) {
173
- Object.defineProperty(protoError, "cause", {
174
- configurable: true,
175
- enumerable: true,
176
- value: "[Circular]",
177
- writable: true
178
- });
179
- } else {
180
- Object.defineProperty(protoError, "cause", {
181
- configurable: true,
182
- enumerable: true,
183
- value: _serialize(error.cause, options, seen, depth),
184
- writable: true
185
- });
186
- }
187
- } else {
188
- const serializedCause = serializeValue(error.cause, seen, depth, options);
189
- Object.defineProperty(protoError, "cause", {
190
- configurable: true,
191
- enumerable: true,
192
- value: serializedCause,
193
- writable: true
194
- });
195
- }
196
- }
197
- for (const key in error) {
198
- if (key === "name" || key === "message" || key === "stack" || key === "cause" || key === "errors") {
199
- continue;
200
- }
201
- const value = error[key];
202
- const serializedValue = serializeValue(value, seen, depth, options);
203
- Object.defineProperty(protoError, key, {
204
- configurable: true,
205
- enumerable: true,
206
- value: serializedValue,
207
- writable: true
208
- });
209
- }
210
- if (Array.isArray(options.exclude) && options.exclude.length > 0) {
211
- for (const key of options.exclude) {
212
- try {
213
- delete protoError[key];
214
- } catch {
215
- }
216
- }
217
- }
218
- return protoError;
219
- };
220
- const serialize = (error, options = {}) => _serialize(
221
- error,
222
- {
223
- exclude: options.exclude ?? [],
224
- maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
225
- useToJSON: options.useToJSON ?? false
226
- },
227
- /* @__PURE__ */ new Set(),
228
- 0
229
- );
230
-
231
- class AbstractJsonReporter {
232
- /** Custom stringify function for object serialization */
233
- stringify;
234
- /** Error serialization options */
235
- errorOptions;
236
- /**
237
- * Creates a new AbstractJsonReporter instance.
238
- * @param options Configuration options for JSON formatting and error handling
239
- */
240
- constructor(options = {}) {
241
- this.errorOptions = options.error ?? {};
242
- }
243
- /**
244
- * Sets a custom stringify function for object serialization.
245
- * @param function_ The stringify function to use for serialization
246
- */
247
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
248
- setStringify(function_) {
249
- this.stringify = function_;
250
- }
251
- // eslint-disable-next-line sonarjs/cognitive-complexity
252
- log(meta) {
253
- const { context, error, file, message, type, ...rest } = meta;
254
- if (rest.label) {
255
- rest.label = rest.label.trim();
256
- }
257
- if (file) {
258
- rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
259
- }
260
- if (message === EMPTY_SYMBOL) {
261
- rest.message = void 0;
262
- } else {
263
- rest.message = message;
264
- }
265
- if (error) {
266
- rest.error = serialize(error, this.errorOptions);
267
- }
268
- if (context) {
269
- const newContext = [];
270
- for (const item of context) {
271
- if (item === EMPTY_SYMBOL) {
272
- continue;
273
- }
274
- if (item instanceof Error) {
275
- newContext.push(serialize(item, this.errorOptions));
276
- } else {
277
- newContext.push(item);
278
- }
279
- }
280
- rest.context = newContext;
281
- }
282
- this._log(this.stringify(rest), type.level);
283
- }
284
- }
285
-
286
- export { AbstractJsonReporter };