standard-log 13.0.0 → 13.0.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 (132) hide show
  1. package/cjs/_virtual/_rolldown/runtime.js +23 -0
  2. package/cjs/console.d.ts +10 -7
  3. package/cjs/console.d.ts.map +1 -1
  4. package/cjs/console.js +54 -69
  5. package/cjs/console.js.map +1 -1
  6. package/cjs/errors.d.ts +9 -6
  7. package/cjs/errors.d.ts.map +1 -1
  8. package/cjs/errors.js +22 -45
  9. package/cjs/errors.js.map +1 -1
  10. package/cjs/formatter.d.ts +9 -6
  11. package/cjs/formatter.d.ts.map +1 -1
  12. package/cjs/formatter.js +42 -49
  13. package/cjs/formatter.js.map +1 -1
  14. package/cjs/index.d.ts +8 -9
  15. package/cjs/index.js +26 -28
  16. package/cjs/log_levels.d.ts +76 -73
  17. package/cjs/log_levels.d.ts.map +1 -1
  18. package/cjs/log_levels.js +104 -110
  19. package/cjs/log_levels.js.map +1 -1
  20. package/cjs/log_store.d.ts +20 -17
  21. package/cjs/log_store.d.ts.map +1 -1
  22. package/cjs/log_store.js +44 -39
  23. package/cjs/log_store.js.map +1 -1
  24. package/cjs/logger.d.ts +6 -3
  25. package/cjs/logger.d.ts.map +1 -1
  26. package/cjs/logger.js +66 -87
  27. package/cjs/logger.js.map +1 -1
  28. package/cjs/memory.d.ts +20 -17
  29. package/cjs/memory.d.ts.map +1 -1
  30. package/cjs/memory.js +55 -62
  31. package/cjs/memory.js.map +1 -1
  32. package/cjs/platform.browser.d.ts +7 -4
  33. package/cjs/platform.browser.d.ts.map +1 -1
  34. package/cjs/platform.browser.js +8 -6
  35. package/cjs/platform.browser.js.map +1 -1
  36. package/cjs/platform.d.ts +7 -4
  37. package/cjs/platform.d.ts.map +1 -1
  38. package/cjs/platform.js +9 -7
  39. package/cjs/platform.js.map +1 -1
  40. package/cjs/standard_log.ctx.d.ts +11 -8
  41. package/cjs/standard_log.ctx.d.ts.map +1 -1
  42. package/cjs/standard_log.ctx.js +6 -5
  43. package/cjs/standard_log.ctx.js.map +1 -1
  44. package/cjs/standard_log.d.ts +14 -12
  45. package/cjs/standard_log.d.ts.map +1 -1
  46. package/cjs/standard_log.js +84 -112
  47. package/cjs/standard_log.js.map +1 -1
  48. package/cjs/standard_log.testing.d.ts +16 -13
  49. package/cjs/standard_log.testing.d.ts.map +1 -1
  50. package/cjs/standard_log.testing.js +20 -35
  51. package/cjs/standard_log.testing.js.map +1 -1
  52. package/cjs/testing/index.d.ts +3 -3
  53. package/cjs/testing/index.js +3 -6
  54. package/cjs/types.d.ts +125 -124
  55. package/cjs/types.d.ts.map +1 -1
  56. package/cjs/types.js +0 -3
  57. package/dist/standard-log.esm.js +874 -1401
  58. package/dist/standard-log.esm.js.map +1 -1
  59. package/dist/standard-log.iife.js +952 -0
  60. package/dist/standard-log.iife.js.map +1 -0
  61. package/esm/console.d.ts +10 -7
  62. package/esm/console.d.ts.map +1 -1
  63. package/esm/console.js +54 -62
  64. package/esm/console.js.map +1 -1
  65. package/esm/errors.d.ts +9 -6
  66. package/esm/errors.d.ts.map +1 -1
  67. package/esm/errors.js +21 -21
  68. package/esm/errors.js.map +1 -1
  69. package/esm/formatter.d.ts +9 -6
  70. package/esm/formatter.d.ts.map +1 -1
  71. package/esm/formatter.js +38 -31
  72. package/esm/formatter.js.map +1 -1
  73. package/esm/index.d.ts +8 -9
  74. package/esm/index.js +7 -7
  75. package/esm/log_levels.d.ts +76 -73
  76. package/esm/log_levels.d.ts.map +1 -1
  77. package/esm/log_levels.js +102 -107
  78. package/esm/log_levels.js.map +1 -1
  79. package/esm/log_store.d.ts +20 -17
  80. package/esm/log_store.d.ts.map +1 -1
  81. package/esm/log_store.js +44 -37
  82. package/esm/log_store.js.map +1 -1
  83. package/esm/logger.d.ts +6 -3
  84. package/esm/logger.d.ts.map +1 -1
  85. package/esm/logger.js +66 -65
  86. package/esm/logger.js.map +1 -1
  87. package/esm/memory.d.ts +20 -17
  88. package/esm/memory.d.ts.map +1 -1
  89. package/esm/memory.js +55 -60
  90. package/esm/memory.js.map +1 -1
  91. package/esm/platform.browser.d.ts +7 -4
  92. package/esm/platform.browser.d.ts.map +1 -1
  93. package/esm/platform.browser.js +7 -3
  94. package/esm/platform.browser.js.map +1 -1
  95. package/esm/platform.d.ts +7 -4
  96. package/esm/platform.d.ts.map +1 -1
  97. package/esm/platform.js +8 -4
  98. package/esm/platform.js.map +1 -1
  99. package/esm/standard_log.ctx.d.ts +11 -8
  100. package/esm/standard_log.ctx.d.ts.map +1 -1
  101. package/esm/standard_log.ctx.js +6 -2
  102. package/esm/standard_log.ctx.js.map +1 -1
  103. package/esm/standard_log.d.ts +14 -12
  104. package/esm/standard_log.d.ts.map +1 -1
  105. package/esm/standard_log.js +83 -98
  106. package/esm/standard_log.js.map +1 -1
  107. package/esm/standard_log.testing.d.ts +16 -13
  108. package/esm/standard_log.testing.d.ts.map +1 -1
  109. package/esm/standard_log.testing.js +19 -20
  110. package/esm/standard_log.testing.js.map +1 -1
  111. package/esm/testing/index.d.ts +3 -3
  112. package/esm/testing/index.js +2 -2
  113. package/esm/types.d.ts +125 -124
  114. package/esm/types.d.ts.map +1 -1
  115. package/esm/types.js +0 -1
  116. package/package.json +8 -42
  117. package/cjs/index.d.ts.map +0 -1
  118. package/cjs/index.js.map +0 -1
  119. package/cjs/testing/index.d.ts.map +0 -1
  120. package/cjs/testing/index.js.map +0 -1
  121. package/cjs/types.js.map +0 -1
  122. package/dist/standard-log.es5.js +0 -10628
  123. package/dist/standard-log.es5.js.gz +0 -0
  124. package/dist/standard-log.es5.js.map +0 -1
  125. package/dist/standard-log.es5.js.map.gz +0 -0
  126. package/dist/standard-log.esm.js.gz +0 -0
  127. package/dist/standard-log.esm.js.map.gz +0 -0
  128. package/esm/index.d.ts.map +0 -1
  129. package/esm/index.js.map +0 -1
  130. package/esm/testing/index.d.ts.map +0 -1
  131. package/esm/testing/index.js.map +0 -1
  132. package/esm/types.js.map +0 -1
@@ -0,0 +1,952 @@
1
+ var StandardLog = (function(exports) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region \0rolldown/runtime.js
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ //#endregion
26
+ //#region ../../node_modules/.pnpm/unpartial@1.0.5/node_modules/unpartial/esm/index.js
27
+ function required(source1, source2, source3) {
28
+ return merge([
29
+ source1,
30
+ source2,
31
+ source3
32
+ ], (p, e) => {
33
+ return {
34
+ ...p,
35
+ ...e
36
+ };
37
+ });
38
+ }
39
+ function merge(entries, reducer) {
40
+ if (entries[0] === void 0 || entries[0] === null) return entries[0];
41
+ return entries.filter((x) => !!x).reduce(reducer, {});
42
+ }
43
+ function unpartial(s1, s2, s3) {
44
+ if (s1 === void 0 || s1 === null) return s1;
45
+ return [
46
+ s1,
47
+ s2,
48
+ s3
49
+ ].filter(notNil).reduce((p, s) => ({
50
+ ...p,
51
+ ...trimNilProps(s)
52
+ }), {});
53
+ }
54
+ function trimNilProps(value) {
55
+ return Object.keys(value).reduce((p, k) => {
56
+ if (notNil(value[k])) p[k] = value[k];
57
+ return p;
58
+ }, {});
59
+ }
60
+ function notNil(value) {
61
+ return value !== null && value !== void 0;
62
+ }
63
+ //#endregion
64
+ //#region ../../node_modules/.pnpm/type-plus@7.6.2/node_modules/type-plus/esm/object/mapKey.js
65
+ function mapKey(subject, predicate, thisArg) {
66
+ return Object.keys(subject).map(function(k, i, a) {
67
+ return predicate.apply(this, [
68
+ k,
69
+ i,
70
+ a,
71
+ subject
72
+ ]);
73
+ }, thisArg);
74
+ }
75
+ //#endregion
76
+ //#region ../../node_modules/.pnpm/type-plus@7.6.2/node_modules/type-plus/esm/object/reduceKey.js
77
+ function reduceByKey(subject, callbackfn, initialValue) {
78
+ return Object.keys(subject).reduce((p, k, i, a) => callbackfn(p, k, i, a, subject), initialValue);
79
+ }
80
+ /**
81
+ * @deprecated renamed to reduceByKey
82
+ */
83
+ const reduceKey = reduceByKey;
84
+ //#endregion
85
+ //#region ../../node_modules/.pnpm/type-plus@7.6.2/node_modules/type-plus/esm/object/record.js
86
+ function record(value) {
87
+ const r = Object.create(null);
88
+ return value ? Object.assign(r, value) : r;
89
+ }
90
+ //#endregion
91
+ //#region ts/log_levels.ts
92
+ var import_ms = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
93
+ /**
94
+ * Helpers.
95
+ */
96
+ var s = 1e3;
97
+ var m = s * 60;
98
+ var h = m * 60;
99
+ var d = h * 24;
100
+ var w = d * 7;
101
+ var y = d * 365.25;
102
+ /**
103
+ * Parse or format the given `val`.
104
+ *
105
+ * Options:
106
+ *
107
+ * - `long` verbose formatting [false]
108
+ *
109
+ * @param {String|Number} val
110
+ * @param {Object} [options]
111
+ * @throws {Error} throw an error if val is not a non-empty string or a number
112
+ * @return {String|Number}
113
+ * @api public
114
+ */
115
+ module.exports = function(val, options) {
116
+ options = options || {};
117
+ var type = typeof val;
118
+ if (type === "string" && val.length > 0) return parse(val);
119
+ else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
120
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
121
+ };
122
+ /**
123
+ * Parse the given `str` and return milliseconds.
124
+ *
125
+ * @param {String} str
126
+ * @return {Number}
127
+ * @api private
128
+ */
129
+ function parse(str) {
130
+ str = String(str);
131
+ if (str.length > 100) return;
132
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
133
+ if (!match) return;
134
+ var n = parseFloat(match[1]);
135
+ switch ((match[2] || "ms").toLowerCase()) {
136
+ case "years":
137
+ case "year":
138
+ case "yrs":
139
+ case "yr":
140
+ case "y": return n * y;
141
+ case "weeks":
142
+ case "week":
143
+ case "w": return n * w;
144
+ case "days":
145
+ case "day":
146
+ case "d": return n * d;
147
+ case "hours":
148
+ case "hour":
149
+ case "hrs":
150
+ case "hr":
151
+ case "h": return n * h;
152
+ case "minutes":
153
+ case "minute":
154
+ case "mins":
155
+ case "min":
156
+ case "m": return n * m;
157
+ case "seconds":
158
+ case "second":
159
+ case "secs":
160
+ case "sec":
161
+ case "s": return n * s;
162
+ case "milliseconds":
163
+ case "millisecond":
164
+ case "msecs":
165
+ case "msec":
166
+ case "ms": return n;
167
+ default: return;
168
+ }
169
+ }
170
+ /**
171
+ * Short format for `ms`.
172
+ *
173
+ * @param {Number} ms
174
+ * @return {String}
175
+ * @api private
176
+ */
177
+ function fmtShort(ms) {
178
+ var msAbs = Math.abs(ms);
179
+ if (msAbs >= d) return Math.round(ms / d) + "d";
180
+ if (msAbs >= h) return Math.round(ms / h) + "h";
181
+ if (msAbs >= m) return Math.round(ms / m) + "m";
182
+ if (msAbs >= s) return Math.round(ms / s) + "s";
183
+ return ms + "ms";
184
+ }
185
+ /**
186
+ * Long format for `ms`.
187
+ *
188
+ * @param {Number} ms
189
+ * @return {String}
190
+ * @api private
191
+ */
192
+ function fmtLong(ms) {
193
+ var msAbs = Math.abs(ms);
194
+ if (msAbs >= d) return plural(ms, msAbs, d, "day");
195
+ if (msAbs >= h) return plural(ms, msAbs, h, "hour");
196
+ if (msAbs >= m) return plural(ms, msAbs, m, "minute");
197
+ if (msAbs >= s) return plural(ms, msAbs, s, "second");
198
+ return ms + " ms";
199
+ }
200
+ /**
201
+ * Pluralization helper.
202
+ */
203
+ function plural(ms, msAbs, n, name) {
204
+ var isPlural = msAbs >= n * 1.5;
205
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
206
+ }
207
+ })))(), 1);
208
+ const logLevels = {
209
+ /**
210
+ * none: 0
211
+ */
212
+ none: 0,
213
+ /**
214
+ * emergency: 100
215
+ *
216
+ * emergency -> alert
217
+ */
218
+ emergency: 100,
219
+ /**
220
+ * alert: 200
221
+ *
222
+ * emergency -> alert -> critical
223
+ */
224
+ alert: 200,
225
+ /**
226
+ * critical: 300
227
+ *
228
+ * alert -> critical -> error
229
+ */
230
+ critical: 300,
231
+ /**
232
+ * error: 400
233
+ *
234
+ * critical -> error -> warn
235
+ */
236
+ error: 400,
237
+ /**
238
+ * warn: 500
239
+ *
240
+ * error -> warn -> notice
241
+ */
242
+ warn: 500,
243
+ /**
244
+ * notice: 600
245
+ *
246
+ * warn -> notice -> info
247
+ */
248
+ notice: 600,
249
+ /**
250
+ * info: 700
251
+ *
252
+ * notice -> info -> debug
253
+ */
254
+ info: 700,
255
+ /**
256
+ * debug: 800
257
+ *
258
+ * info -> debug -> trace
259
+ */
260
+ debug: 800,
261
+ /**
262
+ * trace: 900
263
+ *
264
+ * debug -> trace -> planck
265
+ */
266
+ trace: 900,
267
+ /**
268
+ * planck: Infinity
269
+ * `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.
270
+ *
271
+ * trace -> planck
272
+ */
273
+ planck: Number.POSITIVE_INFINITY,
274
+ /**
275
+ * all: Infinity
276
+ */
277
+ all: Number.POSITIVE_INFINITY
278
+ };
279
+ /**
280
+ * Convert default log level value to log level name.
281
+ */
282
+ function toLogLevelName(level) {
283
+ if (level <= 100) return "emergency";
284
+ if (level <= 200) return "alert";
285
+ if (level <= 300) return "critical";
286
+ if (level <= 400) return "error";
287
+ if (level <= 500) return "warn";
288
+ if (level <= 600) return "notice";
289
+ if (level <= 700) return "info";
290
+ if (level <= 800) return "debug";
291
+ if (level <= 900) return "trace";
292
+ return "planck";
293
+ }
294
+ /**
295
+ * Convert default log level name to log level value.
296
+ */
297
+ function toLogLevel(name) {
298
+ return logLevels[name.toLocaleLowerCase()];
299
+ }
300
+ const DEFAULT_LOG_METHOD_NAMES = [
301
+ "emergency",
302
+ "alert",
303
+ "critical",
304
+ "error",
305
+ "warn",
306
+ "notice",
307
+ "info",
308
+ "debug",
309
+ "trace",
310
+ "planck"
311
+ ];
312
+ //#endregion
313
+ //#region ts/formatter.ts
314
+ function createTimestampFormatter(format) {
315
+ switch (format) {
316
+ case "none": return (_timestamp) => void 0;
317
+ case "iso": return (timestamp) => timestamp.toISOString();
318
+ case "elapsed": {
319
+ let lastTick;
320
+ return (timestamp) => {
321
+ const newTick = timestamp.getTime();
322
+ const result = (0, import_ms.default)(lastTick === void 0 ? 0 : newTick - lastTick);
323
+ lastTick = newTick;
324
+ return result;
325
+ };
326
+ }
327
+ }
328
+ }
329
+ function formatLogLevel(level) {
330
+ return `(${toLogLevelName(level).toUpperCase()})`;
331
+ }
332
+ /**
333
+ * Formats log entry as plain text with the following format:
334
+ * `timestamp id level ...args`
335
+ *
336
+ * This is typically useful for writing logs to file
337
+ */
338
+ function plainLogFormatter({ id, level, args, timestamp }) {
339
+ return [
340
+ timestamp.toISOString(),
341
+ id,
342
+ formatLogLevel(level),
343
+ ...args
344
+ ];
345
+ }
346
+ /**
347
+ * Formats log entry like default console log.
348
+ */
349
+ function consoleFormatter({ args }) {
350
+ return args;
351
+ }
352
+ //#endregion
353
+ //#region ts/platform.browser.ts
354
+ const toInspectLogEntry = (e) => e;
355
+ const polyfill = record();
356
+ //#endregion
357
+ //#region ts/console.ts
358
+ function toConsoleMethod(level) {
359
+ switch (true) {
360
+ case level <= 0: return "debug";
361
+ case level <= logLevels.error: return "error";
362
+ case level <= logLevels.warn: return "warn";
363
+ case level <= logLevels.info: return "info";
364
+ default: return "debug";
365
+ }
366
+ }
367
+ // istanbul ignore next
368
+ function buildPolyfillConsole() {
369
+ if (!!console.log.bind) return {
370
+ debug: (typeof console.info === "function" ? console.debug : console.log).bind(console),
371
+ info: (typeof console.info === "function" ? console.info : console.log).bind(console),
372
+ warn: (typeof console.warn === "function" ? console.warn : console.log).bind(console),
373
+ error: (typeof console.error === "function" ? console.error : console.log).bind(console)
374
+ };
375
+ return {
376
+ debug: buildFn(typeof console.debug === "function" ? "debug" : "log"),
377
+ info: buildFn(typeof console.info === "function" ? "info" : "log"),
378
+ warn: buildFn(typeof console.warn === "function" ? "warn" : "log"),
379
+ error: buildFn(typeof console.error === "function" ? "error" : "log")
380
+ };
381
+ }
382
+ // istanbul ignore next
383
+ function buildFn(name) {
384
+ return (...args) => {
385
+ console[name](...args);
386
+ };
387
+ }
388
+ function createConsoleLogReporter(options) {
389
+ const { id, formatter, filter } = unpartial({
390
+ id: "console",
391
+ formatter: consoleFormatter
392
+ }, options);
393
+ if (!polyfill.console) polyfill.console = buildPolyfillConsole();
394
+ return Object.freeze({
395
+ id,
396
+ isConsoleReporter: true,
397
+ get formatter() {
398
+ return formatter;
399
+ },
400
+ get filter() {
401
+ return filter;
402
+ },
403
+ console: polyfill.console,
404
+ write(entry) {
405
+ if (filter && !filter(entry)) return;
406
+ const values = formatter(entry);
407
+ const method = toConsoleMethod(entry.level);
408
+ this.console[method](...values);
409
+ }
410
+ });
411
+ }
412
+ //#endregion
413
+ //#region ../../node_modules/.pnpm/iso-error@6.0.3/node_modules/iso-error/esm/index.js
414
+ var __classPrivateFieldGet = function(receiver, state, kind, f) {
415
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
416
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
417
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
418
+ };
419
+ var _a;
420
+ var _IsoError_hasCause;
421
+ var _IsoError_toIsoError;
422
+ // istanbul ignore next
423
+ if (!Error.captureStackTrace) Error.captureStackTrace = function(error) {
424
+ const container = /* @__PURE__ */ new Error();
425
+ Object.defineProperty(error, "stack", {
426
+ configurable: true,
427
+ get: function() {
428
+ defineStack(this, container.stack);
429
+ return container.stack;
430
+ },
431
+ set: function(stack) {
432
+ defineStack(error, stack);
433
+ }
434
+ });
435
+ };
436
+ // istanbul ignore next
437
+ function defineStack(target, value) {
438
+ Object.defineProperty(target, "stack", {
439
+ configurable: true,
440
+ value,
441
+ writable: true
442
+ });
443
+ }
444
+ var SerializableConverter = class {
445
+ constructor() {
446
+ Object.defineProperty(this, "plugins", {
447
+ enumerable: true,
448
+ configurable: true,
449
+ writable: true,
450
+ value: []
451
+ });
452
+ }
453
+ addPlugin(plugin) {
454
+ this.plugins.unshift(plugin);
455
+ }
456
+ /**
457
+ * Deserialize an `Error` from `Serializable`
458
+ */
459
+ fromSerializable(json, options) {
460
+ const err = this.deserializeError(json);
461
+ Error.captureStackTrace(err, options?.ssf);
462
+ return err;
463
+ }
464
+ fromSerializableImpl(json) {
465
+ if (json["name"] === "AggregateError") {
466
+ const { message, errors, ...rest } = json;
467
+ // istanbul ignore next
468
+ if (global.AggregateError) return Object.assign(new AggregateError(errors, message), rest);
469
+ else return Object.assign(new Error(message), {
470
+ ...rest,
471
+ errors
472
+ });
473
+ }
474
+ const { message, cause, ...rest } = json;
475
+ const causeError = cause ? this.deserializeError(cause) : void 0;
476
+ if (json["name"] === "Error") return Object.assign(new Error(message), causeError ? {
477
+ ...rest,
478
+ cause: causeError
479
+ } : rest);
480
+ return Object.assign(new IsoError(message, causeError ? { cause: causeError } : void 0), rest);
481
+ }
482
+ deserializeError(json) {
483
+ let err = void 0;
484
+ for (const { fromSerializable } of this.plugins) {
485
+ err = fromSerializable(json);
486
+ if (err) break;
487
+ }
488
+ return err || this.fromSerializableImpl(json);
489
+ }
490
+ /**
491
+ * Serialize `Error` to `Serializable`
492
+ */
493
+ toSerializable(err) {
494
+ return this.plugins.reduce((p, s) => p || s.toSerializable(err), void 0) || this.toSerializableImpl(err);
495
+ }
496
+ toSerializableImpl(err) {
497
+ if (isAggregateError(err)) return {
498
+ ...err,
499
+ name: err.constructor.name,
500
+ message: err.message,
501
+ errors: err.errors.map(this.toSerializableImpl)
502
+ };
503
+ if (err instanceof Error) {
504
+ const { message, cause } = err;
505
+ return cause ? {
506
+ ...err,
507
+ name: err.constructor.name,
508
+ message,
509
+ cause: this.toSerializableImpl(cause)
510
+ } : {
511
+ ...err,
512
+ name: err.constructor.name,
513
+ message
514
+ };
515
+ }
516
+ return err;
517
+ }
518
+ };
519
+ const getCircularReplacer = () => {
520
+ const seen = /* @__PURE__ */ new WeakSet();
521
+ return (_, value) => {
522
+ if (typeof value === "object" && value !== null) {
523
+ if (seen.has(value)) return;
524
+ seen.add(value);
525
+ }
526
+ return value;
527
+ };
528
+ };
529
+ /**
530
+ * Isomorphic Error that works across physical boundary.
531
+ */
532
+ var IsoError = class IsoError extends Error {
533
+ /**
534
+ * Create an IsoError with additional properties without the need to create a new class.
535
+ * @param props properties of the IsoError
536
+ */
537
+ static create(props) {
538
+ const { message, cause, ...rest } = props;
539
+ const err = new IsoError(message, {
540
+ cause,
541
+ ssf: IsoError.create
542
+ });
543
+ return Object.assign(err, rest);
544
+ }
545
+ static stringify(err) {
546
+ return this.serialize(err);
547
+ }
548
+ static serialize(err) {
549
+ return JSON.stringify(this.toSerializable(err), getCircularReplacer());
550
+ }
551
+ static toSerializable(err) {
552
+ return this.converter.toSerializable(err);
553
+ }
554
+ /**
555
+ * @type P Additional properties of the IsoError
556
+ * @param text Json representation of a IsoError
557
+ */
558
+ static parse(text) {
559
+ const json = JSON.parse(text);
560
+ return this.converter.fromSerializable(json, { ssf: IsoError.parse });
561
+ }
562
+ /**
563
+ * @type P Additional properties of the IsoError
564
+ * @param text Json representation of a IsoError
565
+ */
566
+ static deserialize(text) {
567
+ const json = JSON.parse(text);
568
+ return this.converter.fromSerializable(json, { ssf: IsoError.deserialize });
569
+ }
570
+ static fromSerializable(json) {
571
+ return this.converter.fromSerializable(json, { ssf: IsoError.fromSerializable });
572
+ }
573
+ /**
574
+ * returns the error message including the error causes.
575
+ */
576
+ static trace(err) {
577
+ const messages = [];
578
+ if (err instanceof ModuleError) messages.push(`${err.name}(${err.module}): ${err.message}`);
579
+ else if (err instanceof Error) messages.push(`${err.name}: ${err.message}`);
580
+ if (isAggregateError(err)) err.errors.forEach((e) => messages.push(...this.trace(e).split("\n").map((s) => " " + s)));
581
+ if (err instanceof Error) {
582
+ if (__classPrivateFieldGet(this, _a, "m", _IsoError_hasCause).call(this, err)) messages.push(...this.trace(err.cause).split("\n").map((s) => " " + s));
583
+ } else messages.push(typeof err === "string" ? err : JSON.stringify(err));
584
+ return messages.join("\n");
585
+ }
586
+ static addPlugin(plugin) {
587
+ this.converter.addPlugin(plugin);
588
+ }
589
+ constructor(message, options) {
590
+ super(message);
591
+ /**
592
+ * Name of the error
593
+ */
594
+ Object.defineProperty(this, "name", {
595
+ enumerable: true,
596
+ configurable: true,
597
+ writable: true,
598
+ value: void 0
599
+ });
600
+ /**
601
+ * Error cause
602
+ */
603
+ Object.defineProperty(this, "cause", {
604
+ enumerable: true,
605
+ configurable: true,
606
+ writable: true,
607
+ value: void 0
608
+ });
609
+ const actualProto = new.target.prototype;
610
+ this.name = actualProto.constructor.name;
611
+ // istanbul ignore next
612
+ if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
613
+ else this.__proto__ = actualProto;
614
+ if (options?.cause) this.cause = __classPrivateFieldGet(IsoError, _a, "m", _IsoError_toIsoError).call(IsoError, options.cause);
615
+ if (options?.ssf) Error.captureStackTrace(this, options.ssf);
616
+ }
617
+ toString() {
618
+ return IsoError.serialize(this);
619
+ }
620
+ trace() {
621
+ return IsoError.trace(this);
622
+ }
623
+ };
624
+ _a = IsoError, _IsoError_hasCause = function _IsoError_hasCause(x) {
625
+ return !!x.cause;
626
+ }, _IsoError_toIsoError = function _IsoError_toIsoError(err) {
627
+ return Object.assign(err, { name: err.name ?? err.constructor.name });
628
+ };
629
+ Object.defineProperty(IsoError, "converter", {
630
+ enumerable: true,
631
+ configurable: true,
632
+ writable: true,
633
+ value: new SerializableConverter()
634
+ });
635
+ /**
636
+ * An IsoError with a module property.
637
+ */
638
+ var ModuleError = class extends IsoError {
639
+ /**
640
+ * @param module The module that defines this error.
641
+ */
642
+ constructor(module, message, options) {
643
+ super(message, options);
644
+ Object.defineProperty(this, "module", {
645
+ enumerable: true,
646
+ configurable: true,
647
+ writable: true,
648
+ value: module
649
+ });
650
+ }
651
+ };
652
+ function isAggregateError(error) {
653
+ return error instanceof Error && Array.isArray(error.errors);
654
+ }
655
+ //#endregion
656
+ //#region ts/errors.ts
657
+ /**
658
+ * @deprecated No longer used since 11.2.0
659
+ */
660
+ var StandardLogError = class extends ModuleError {
661
+ constructor(description, options) {
662
+ super("standard-log", description, options);
663
+ }
664
+ };
665
+ /**
666
+ * @deprecated no longer used since 11.2.0
667
+ */
668
+ var InvalidId = class extends StandardLogError {
669
+ id;
670
+ constructor(id, options) {
671
+ super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options);
672
+ this.id = id;
673
+ }
674
+ };
675
+ //#endregion
676
+ //#region ts/memory.ts
677
+ function toMessageWithLevel(logs) {
678
+ return logs.map(toInspectLogEntry).map((log) => `${formatLogLevel(log.level)} ${log.args.join(" ")}`).join("\n").replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, "");
679
+ }
680
+ function createMemoryLogReporter(options) {
681
+ return Object.freeze(buildMemoryReporter(unpartial({ id: "memory" }, options)));
682
+ }
683
+ function buildMemoryReporter(options) {
684
+ const { id, formatter, filter } = required({
685
+ id: "memory",
686
+ formatter: (e) => e
687
+ }, options);
688
+ const logs = [];
689
+ return {
690
+ id,
691
+ get formatter() {
692
+ return formatter;
693
+ },
694
+ get filter() {
695
+ return filter;
696
+ },
697
+ logs,
698
+ write(entry) {
699
+ if (filter && !filter(entry)) return;
700
+ logs.push(formatter(entry));
701
+ },
702
+ getLogMessage() {
703
+ return this.getLogMessages().join("\n");
704
+ },
705
+ getLogMessages() {
706
+ return logs.map(toInspectLogEntry).map((log) => log.args.join(" "));
707
+ },
708
+ getLogMessagesWithLevel() {
709
+ return logs.map(toInspectLogEntry).map((log) => `${formatLogLevel(log.level)} ${log.args.join(" ")}`);
710
+ },
711
+ getLogMessagesWithIdAndLevel() {
712
+ return logs.map(toInspectLogEntry).map((log) => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(" ")}`);
713
+ },
714
+ getLogMessageWithLevel() {
715
+ return toMessageWithLevel(logs);
716
+ },
717
+ /**
718
+ * emit the saved log to console for easy debugging
719
+ */
720
+ emit() {
721
+ const reporter = createConsoleLogReporter();
722
+ logs.forEach((l) => reporter.write(l));
723
+ }
724
+ };
725
+ }
726
+ function createMemoryWithConsoleLogReporter(options) {
727
+ return Object.freeze(Object.assign(buildMemoryReporter(unpartial({ id: "memory-with-console" }, options)), { isConsoleReporter: true }));
728
+ }
729
+ //#endregion
730
+ //#region ts/log_store.ts
731
+ function createLogStore(options) {
732
+ return {
733
+ loggers: record(),
734
+ nonConsoleLoggers: record(),
735
+ reporters: options.reporters || [createConsoleLogReporter()],
736
+ logLevel: options.logLevel,
737
+ logLevelStore: logLevelStore(options)
738
+ };
739
+ }
740
+ function logLevelStore(options) {
741
+ const customLevels = options.customLevels || record();
742
+ const store = {
743
+ customLevels,
744
+ customLevelsReverse: reduceByKey(customLevels, (p, k) => {
745
+ p[customLevels[k]] = k;
746
+ return p;
747
+ }, {})
748
+ };
749
+ return {
750
+ getName(level) {
751
+ return store.customLevelsReverse[level] ?? toLogLevelName(level);
752
+ },
753
+ getLevel(name) {
754
+ return store.customLevels[name] ?? toLogLevel(name);
755
+ },
756
+ getAllLevels() {
757
+ return reduceKey(logLevels, (result, name) => {
758
+ if (name !== "none" && name !== "all") result.push({
759
+ name,
760
+ level: logLevels[name]
761
+ });
762
+ return result;
763
+ }, mapKey(store.customLevels, (name) => ({
764
+ name,
765
+ level: store.customLevels[name]
766
+ })));
767
+ }
768
+ };
769
+ }
770
+ //#endregion
771
+ //#region ts/logger.ts
772
+ function createLogger(store, id, options) {
773
+ id = sanitizeId(id);
774
+ const writeTo = options?.writeTo ?? (() => true);
775
+ const [filter, reporters] = typeof writeTo === "string" ? [(id) => id === writeTo, store.reporters] : writeTo instanceof RegExp ? [(id) => writeTo.test(id), store.reporters] : typeof writeTo === "function" ? [writeTo, store.reporters] : [() => true, [writeTo]];
776
+ function write(entry) {
777
+ writeToReporters(reporters, entry, filter);
778
+ }
779
+ const logger = {
780
+ level: options?.level,
781
+ write
782
+ };
783
+ Object.defineProperties(logger, {
784
+ id: {
785
+ value: id,
786
+ writable: false
787
+ },
788
+ count: {
789
+ writable: false,
790
+ value: ((counter) => (...args) => {
791
+ if (shouldLog(store, logLevels.debug, logger.level)) write({
792
+ id,
793
+ level: logLevels.debug,
794
+ args: [++counter, ...args],
795
+ timestamp: /* @__PURE__ */ new Date()
796
+ });
797
+ })(0)
798
+ },
799
+ on: {
800
+ writable: false,
801
+ value: (level, logFn) => {
802
+ const logLevel = typeof level === "string" ? store.logLevelStore.getLevel(level) : level;
803
+ if (shouldLog(store, logLevel, logger.level)) {
804
+ const methodName = store.logLevelStore.getName(logLevel);
805
+ const bindedMethod = logger[methodName].bind(logger);
806
+ const result = logFn(bindedMethod, logger.level ?? store.logLevel);
807
+ if (result) bindedMethod(result);
808
+ }
809
+ }
810
+ }
811
+ });
812
+ store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
813
+ Object.defineProperty(logger, name, {
814
+ writable: false,
815
+ value: (...args) => {
816
+ if (shouldLog(store, level, logger.level)) write({
817
+ id,
818
+ level,
819
+ args,
820
+ timestamp: /* @__PURE__ */ new Date()
821
+ });
822
+ }
823
+ });
824
+ });
825
+ return logger;
826
+ }
827
+ function sanitizeId(id) {
828
+ return id.replace(/[`~!#$%^&*()=+[\]{},|<>?]/g, "-");
829
+ }
830
+ function writeToReporters(reporters, logEntry, filter) {
831
+ reporters.filter((r) => filter(r.id)).forEach((r) => r.write(logEntry));
832
+ }
833
+ /**
834
+ * Determines should you log.
835
+ * @param loggerLevel Log level of the logger.
836
+ * It can be undefined which the global log level will be used.
837
+ */
838
+ function shouldLog(store, targetLevel, loggerLevel) {
839
+ return targetLevel <= (loggerLevel !== void 0 ? loggerLevel : store.logLevel);
840
+ }
841
+ //#endregion
842
+ //#region ts/standard_log.ctx.ts
843
+ const ctx = record();
844
+ //#endregion
845
+ //#region ts/standard_log.ts
846
+ function createStandardLog(options) {
847
+ const closure = createStandardLogClosure(options);
848
+ if (options?.reporters?.some((r) => !r.id)) closure.standardLog.getLogger("standard-log").critical(`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`);
849
+ if (!ctx.gsl) ctx.gsl = closure;
850
+ return closure.standardLog;
851
+ }
852
+ function noop() {}
853
+ function createStandardLogClosure(options) {
854
+ const store = createLogStore(required({ logLevel: logLevels.info }, options));
855
+ const nonConsoleReporters = options?.reporters?.filter((r) => !r.isConsoleReporter).map((r) => r.id) ?? [];
856
+ const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([
857
+ "on",
858
+ "count",
859
+ "write"
860
+ ]);
861
+ return {
862
+ store,
863
+ standardLog: {
864
+ get logLevel() {
865
+ return store.logLevel;
866
+ },
867
+ toLogLevelName(level) {
868
+ return store.logLevelStore.getName(level);
869
+ },
870
+ toLogLevel(name) {
871
+ return store.logLevelStore.getLevel(name);
872
+ },
873
+ getLogger(id, options) {
874
+ if (store.loggers[id]) return store.loggers[id];
875
+ return store.loggers[id] = createLogger(store, id, {
876
+ ssf: this.getLogger,
877
+ ...options
878
+ });
879
+ },
880
+ getNonConsoleLogger(id, options) {
881
+ if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id];
882
+ if (store.loggers[id]) {
883
+ this.getLogger("standard-log").warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`);
884
+ return store.nonConsoleLoggers[id] = createDummyLogger(logMethods);
885
+ }
886
+ return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0 ? createDummyLogger(logMethods) : createLogger(store, id, {
887
+ ssf: this.getNonConsoleLogger,
888
+ ...options,
889
+ writeTo(reporterId) {
890
+ return nonConsoleReporters.indexOf(reporterId) >= 0;
891
+ }
892
+ });
893
+ }
894
+ }
895
+ };
896
+ }
897
+ function createDummyLogger(logMethods) {
898
+ return logMethods.reduce((p, m) => {
899
+ p[m] = noop;
900
+ return p;
901
+ }, record());
902
+ }
903
+ function suppressLogs(block, ...logs) {
904
+ const origLevels = logs.map((l) => l.level);
905
+ logs.forEach((l) => l.level = logLevels.none);
906
+ const result = block();
907
+ logs.forEach((l, i) => l.level = origLevels[i]);
908
+ return result;
909
+ }
910
+ function getLogger(id, options) {
911
+ return getGlobalSL().getLogger(id, options);
912
+ }
913
+ function getGlobalSL() {
914
+ if (!ctx.gsl) ctx.gsl = createStandardLogClosure();
915
+ return ctx.gsl.standardLog;
916
+ }
917
+ function configGlobal(options) {
918
+ if (ctx.configured) ctx.gsl.standardLog.getLogger("standard-log").warn("configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.");
919
+ if (ctx.gsl) {
920
+ if (options.logLevel) ctx.gsl.store.logLevel = options.logLevel;
921
+ if (options.reporters) {
922
+ const reporters = ctx.gsl.store.reporters;
923
+ reporters.length = 0;
924
+ reporters.push(...options.reporters);
925
+ }
926
+ } else ctx.gsl = createStandardLogClosure(options);
927
+ ctx.configured = true;
928
+ }
929
+ //#endregion
930
+ exports.DEFAULT_LOG_METHOD_NAMES = DEFAULT_LOG_METHOD_NAMES;
931
+ exports.InvalidId = InvalidId;
932
+ exports.StandardLogError = StandardLogError;
933
+ exports.configGlobal = configGlobal;
934
+ exports.consoleFormatter = consoleFormatter;
935
+ exports.createConsoleLogReporter = createConsoleLogReporter;
936
+ exports.createMemoryLogReporter = createMemoryLogReporter;
937
+ exports.createMemoryWithConsoleLogReporter = createMemoryWithConsoleLogReporter;
938
+ exports.createStandardLog = createStandardLog;
939
+ exports.createTimestampFormatter = createTimestampFormatter;
940
+ exports.formatLogLevel = formatLogLevel;
941
+ exports.getLogger = getLogger;
942
+ exports.logLevels = logLevels;
943
+ exports.plainLogFormatter = plainLogFormatter;
944
+ exports.suppressLogs = suppressLogs;
945
+ exports.toConsoleMethod = toConsoleMethod;
946
+ exports.toLogLevel = toLogLevel;
947
+ exports.toLogLevelName = toLogLevelName;
948
+ exports.toMessageWithLevel = toMessageWithLevel;
949
+ return exports;
950
+ })({});
951
+
952
+ //# sourceMappingURL=standard-log.iife.js.map