@adapt-arch/utiliti-es 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/dist/bundle/mockServiceWorker.js +284 -0
  4. package/dist/bundle/utiliti-es.cjs +1 -0
  5. package/dist/bundle/utiliti-es.iife.js +1 -0
  6. package/dist/bundle/utiliti-es.js +475 -0
  7. package/dist/bundle/utiliti-es.umd.cjs +1 -0
  8. package/dist/common/contracts.d.ts +6 -0
  9. package/dist/common/contracts.js +1 -0
  10. package/dist/common/index.d.ts +1 -0
  11. package/dist/common/index.js +1 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.js +4 -0
  14. package/dist/logger/contracts.d.ts +95 -0
  15. package/dist/logger/contracts.js +67 -0
  16. package/dist/logger/enrichers/dynamicValuesEnricher.d.ts +20 -0
  17. package/dist/logger/enrichers/dynamicValuesEnricher.js +31 -0
  18. package/dist/logger/enrichers/index.d.ts +2 -0
  19. package/dist/logger/enrichers/index.js +2 -0
  20. package/dist/logger/enrichers/valuesEnricher.d.ts +16 -0
  21. package/dist/logger/enrichers/valuesEnricher.js +30 -0
  22. package/dist/logger/index.d.ts +5 -0
  23. package/dist/logger/index.js +5 -0
  24. package/dist/logger/logger.d.ts +81 -0
  25. package/dist/logger/logger.js +136 -0
  26. package/dist/logger/loggerOptions.d.ts +28 -0
  27. package/dist/logger/loggerOptions.js +47 -0
  28. package/dist/logger/reporters/consoleReporter.d.ts +34 -0
  29. package/dist/logger/reporters/consoleReporter.js +58 -0
  30. package/dist/logger/reporters/inMemoryReporter.d.ts +17 -0
  31. package/dist/logger/reporters/inMemoryReporter.js +22 -0
  32. package/dist/logger/reporters/index.d.ts +4 -0
  33. package/dist/logger/reporters/index.js +4 -0
  34. package/dist/logger/reporters/multipleReporter.d.ts +16 -0
  35. package/dist/logger/reporters/multipleReporter.js +29 -0
  36. package/dist/logger/reporters/xhrReporter.d.ts +45 -0
  37. package/dist/logger/reporters/xhrReporter.js +108 -0
  38. package/dist/mocks/logReporterHandlers.d.ts +1 -0
  39. package/dist/mocks/logReporterHandlers.js +27 -0
  40. package/dist/pubsub/contracts.d.ts +39 -0
  41. package/dist/pubsub/contracts.js +1 -0
  42. package/dist/pubsub/index.d.ts +2 -0
  43. package/dist/pubsub/index.js +1 -0
  44. package/dist/pubsub/pubsub.d.ts +13 -0
  45. package/dist/pubsub/pubsub.js +51 -0
  46. package/dist/utils/delay.d.ts +8 -0
  47. package/dist/utils/delay.js +14 -0
  48. package/dist/utils/index.d.ts +1 -0
  49. package/dist/utils/index.js +1 -0
  50. package/package.json +73 -0
@@ -0,0 +1,475 @@
1
+ var u = Object.defineProperty;
2
+ var h = (t, e, s) => e in t ? u(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
+ var r = (t, e, s) => (h(t, typeof e != "symbol" ? e + "" : e, s), s);
4
+ class g {
5
+ constructor() {
6
+ r(this, "_subscriptions", /* @__PURE__ */ new Map());
7
+ }
8
+ /** @inheritdoc */
9
+ publish(e, s) {
10
+ if (!e)
11
+ throw new Error("Invalid topic.");
12
+ if (!s)
13
+ throw new Error("Invalid message.");
14
+ const i = this._subscriptions.get(e);
15
+ if (i)
16
+ for (const n of i.values()) {
17
+ const a = structuredClone(e), l = structuredClone(s);
18
+ setTimeout(() => n(a, l), 0);
19
+ }
20
+ }
21
+ /** @inheritdoc */
22
+ subscribe(e, s) {
23
+ if (!e)
24
+ throw new Error("Invalid topic.");
25
+ if (!s)
26
+ throw new Error("Invalid handler.");
27
+ let i = this._subscriptions.get(e);
28
+ i || (i = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(e), i));
29
+ const n = `sub-${Date.now()}`;
30
+ return i.set(n, s), n;
31
+ }
32
+ /** @inheritdoc */
33
+ unsubscribe(e) {
34
+ if (e) {
35
+ for (const s of this._subscriptions.values())
36
+ if (s.delete(e))
37
+ return;
38
+ }
39
+ }
40
+ }
41
+ function m(t = 1, e) {
42
+ return new Promise((s, i) => {
43
+ setTimeout(() => {
44
+ e ? i(e) : s();
45
+ }, t);
46
+ });
47
+ }
48
+ class p {
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @param {ExtraParams} values The values to add to the log.
53
+ * @param {boolean} overrideExisting Override a value if it already exists.
54
+ */
55
+ constructor(e, s) {
56
+ r(this, "_values");
57
+ r(this, "_overrideExisting");
58
+ this._values = e, this._overrideExisting = s;
59
+ }
60
+ /**
61
+ * @inheritdoc
62
+ */
63
+ enrich(e) {
64
+ if (!this._values)
65
+ return;
66
+ e.extraParams = e.extraParams || {};
67
+ const s = Object.keys(e.extraParams);
68
+ for (const i in this._values)
69
+ s.indexOf(i) !== -1 && !this._overrideExisting || (e.extraParams[i] = this._values[i]);
70
+ }
71
+ }
72
+ class f {
73
+ /**
74
+ * Constructor.
75
+ *
76
+ * @param {DynamicValuesFunction} valuesFunction The values to add to the log.
77
+ * @param {boolean} overrideExisting Override a value if it already exists.
78
+ */
79
+ constructor(e, s) {
80
+ r(this, "_valuesFn");
81
+ r(this, "_overrideExisting");
82
+ this._valuesFn = e, this._overrideExisting = s;
83
+ }
84
+ /**
85
+ * @inheritdoc
86
+ */
87
+ enrich(e) {
88
+ const s = typeof this._valuesFn == "function" ? this._valuesFn() : void 0;
89
+ if (!s)
90
+ return;
91
+ e.extraParams = e.extraParams || {};
92
+ const i = Object.keys(e.extraParams);
93
+ for (const n in s)
94
+ i.indexOf(n) !== -1 && !this._overrideExisting || (e.extraParams[n] = s[n]);
95
+ }
96
+ }
97
+ var o;
98
+ (function(t) {
99
+ t[t.Trace = 0] = "Trace", t[t.Debug = 1] = "Debug", t[t.Information = 2] = "Information", t[t.Warning = 3] = "Warning", t[t.Error = 4] = "Error", t[t.Critical = 5] = "Critical", t[t.None = 6] = "None";
100
+ })(o || (o = {}));
101
+ class c {
102
+ constructor() {
103
+ /**
104
+ * The timestamp of the log message.
105
+ */
106
+ r(this, "timestamp", (/* @__PURE__ */ new Date()).getTime());
107
+ /**
108
+ * The level of the log message.
109
+ */
110
+ r(this, "level", o.None);
111
+ /**
112
+ * The name of the logger.
113
+ */
114
+ r(this, "name", "");
115
+ /**
116
+ * The message to log.
117
+ */
118
+ r(this, "message", "");
119
+ /**
120
+ * The error message.
121
+ */
122
+ r(this, "errorMessage");
123
+ /**
124
+ * The stack trace of the error.
125
+ */
126
+ r(this, "stackTrace");
127
+ /**
128
+ * Any extra parameters to log.
129
+ */
130
+ r(this, "extraParams");
131
+ }
132
+ }
133
+ class d {
134
+ /**
135
+ * Constructor.
136
+ *
137
+ * @param {Console} console The current console reference.
138
+ */
139
+ constructor(e) {
140
+ r(this, "_console");
141
+ this._console = e;
142
+ }
143
+ /**
144
+ * @inheritdoc
145
+ */
146
+ register(e) {
147
+ let s;
148
+ if (this._console)
149
+ switch (e.level) {
150
+ case o.Trace:
151
+ s = this._console.trace || this._console.log;
152
+ break;
153
+ case o.Debug:
154
+ s = this._console.debug || this._console.log;
155
+ break;
156
+ case o.Information:
157
+ s = this._console.info || this._console.log;
158
+ break;
159
+ case o.Warning:
160
+ s = this._console.warn || this._console.log;
161
+ break;
162
+ case o.Error:
163
+ s = this._console.error || this._console.log;
164
+ break;
165
+ case o.Critical:
166
+ s = this._console.error || this._console.log;
167
+ break;
168
+ default:
169
+ s = null;
170
+ break;
171
+ }
172
+ typeof s == "function" && s.call(this._console, e.message, e);
173
+ }
174
+ /**
175
+ * @inheritdoc
176
+ */
177
+ [Symbol.asyncDispose]() {
178
+ return Promise.resolve();
179
+ }
180
+ }
181
+ class b {
182
+ constructor() {
183
+ /**
184
+ * Endpoint that receives the logs.
185
+ */
186
+ r(this, "endpoint", "");
187
+ /**
188
+ * HTTP verb used when calling the endpoint.
189
+ */
190
+ r(this, "verb", "POST");
191
+ /**
192
+ * The number of items to send in a batch.
193
+ */
194
+ r(this, "batchSize", 20);
195
+ /**
196
+ * The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
197
+ */
198
+ r(this, "interval", 2e3);
199
+ /**
200
+ * A function that can be used to transform the request before sending it.
201
+ */
202
+ r(this, "requestTransform");
203
+ }
204
+ }
205
+ class w {
206
+ constructor(e) {
207
+ r(this, "_messageQueue");
208
+ r(this, "_options");
209
+ r(this, "_reportActionTimeoutRef");
210
+ r(this, "_reportActionPromise");
211
+ r(this, "_disposed");
212
+ if (!e)
213
+ throw new Error('Argument "options" is required');
214
+ this._messageQueue = [], this._options = e, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
215
+ }
216
+ /**
217
+ * @inheritdoc
218
+ */
219
+ register(e) {
220
+ this._disposed || (this._messageQueue.push(e), this._scheduleNextProcessAction());
221
+ }
222
+ /**
223
+ * @inheritdoc
224
+ */
225
+ async [Symbol.asyncDispose]() {
226
+ if (this._disposed)
227
+ return Promise.resolve();
228
+ await (this._reportActionPromise ?? this._processMessages()), this._disposed = !0;
229
+ }
230
+ _scheduleNextProcessAction() {
231
+ if (this._reportActionTimeoutRef)
232
+ return;
233
+ const e = this._messageQueue.length >= this._options.batchSize ? 0 : this._options.interval;
234
+ this._reportActionTimeoutRef = setTimeout(() => {
235
+ this._reportActionPromise = this._processMessages().then(() => {
236
+ const s = this._reportActionTimeoutRef;
237
+ this._reportActionTimeoutRef = void 0, clearTimeout(s), this._reportActionPromise = null, this._scheduleNextProcessAction();
238
+ });
239
+ }, e);
240
+ }
241
+ async _processMessages() {
242
+ let e, s;
243
+ for (; this._messageQueue.length > 0; )
244
+ if (e = this._messageQueue.splice(0, Math.min(this._messageQueue.length, this._options.batchSize)), s = await this._sendMessagesBatch(e), !s) {
245
+ this._messageQueue.unshift(...e);
246
+ return;
247
+ }
248
+ }
249
+ _sendMessagesBatch(e) {
250
+ return new Promise((s) => {
251
+ const i = () => {
252
+ s(!1);
253
+ }, n = new XMLHttpRequest();
254
+ n.open(this._options.verb, this._options.endpoint), n.setRequestHeader("Content-Type", "application/json;charset=UTF-8"), this._options.requestTransform && this._options.requestTransform(n), n.onload = function() {
255
+ s(this.status >= 200 && this.status < 300);
256
+ }, n.onerror = i, n.onabort = i, n.send(JSON.stringify(e));
257
+ });
258
+ }
259
+ }
260
+ class v {
261
+ constructor() {
262
+ r(this, "_messages", []);
263
+ }
264
+ get messages() {
265
+ return this._messages.slice();
266
+ }
267
+ /**
268
+ * @inheritdoc
269
+ */
270
+ register(e) {
271
+ this._messages.push(e);
272
+ }
273
+ /**
274
+ * @inheritdoc
275
+ */
276
+ [Symbol.asyncDispose]() {
277
+ return Promise.resolve();
278
+ }
279
+ }
280
+ class y {
281
+ constructor(e) {
282
+ r(this, "_reporters");
283
+ this._reporters = e || [];
284
+ }
285
+ /**
286
+ * @inheritdoc
287
+ */
288
+ register(e) {
289
+ for (const s of this._reporters)
290
+ s.register(e);
291
+ }
292
+ /**
293
+ * @inheritdoc
294
+ */
295
+ async [Symbol.asyncDispose]() {
296
+ const e = new Array();
297
+ for (const s of this._reporters)
298
+ e.push(s[Symbol.asyncDispose]());
299
+ e.length && await Promise.all(e);
300
+ }
301
+ }
302
+ class T {
303
+ /**
304
+ * Constructor.
305
+ *
306
+ * @param {LoggerOptions} options The logger options.
307
+ */
308
+ constructor(e) {
309
+ r(this, "_options");
310
+ this._options = e;
311
+ }
312
+ /**
313
+ * The core logging method.
314
+ *
315
+ * @param {LogMessage} message The message to log.
316
+ */
317
+ logMessageCore(e) {
318
+ var s;
319
+ e.name = this._options.name;
320
+ for (const i of this._options.enrichers)
321
+ i.enrich(e);
322
+ (s = this._options.reporter) == null || s.register(e);
323
+ }
324
+ /**
325
+ * @inheritdoc
326
+ */
327
+ async [Symbol.asyncDispose]() {
328
+ var e;
329
+ await ((e = this._options.reporter) == null ? void 0 : e[Symbol.asyncDispose]());
330
+ }
331
+ /**
332
+ * Indicates if the specified level will be logged.
333
+ *
334
+ * @param {LogLevel} level The log level.
335
+ */
336
+ isEnabled(e) {
337
+ return e !== o.None && e >= this._options.minimumLevel;
338
+ }
339
+ /**
340
+ * Log trace.
341
+ *
342
+ * @param msg The message to log.
343
+ */
344
+ trace(e) {
345
+ const s = new c();
346
+ s.level = o.Trace, s.message = e, this.logMessage(s);
347
+ }
348
+ /**
349
+ * Log debug.
350
+ *
351
+ * @param msg The message to log.
352
+ */
353
+ debug(e) {
354
+ const s = new c();
355
+ s.level = o.Debug, s.message = e, this.logMessage(s);
356
+ }
357
+ /**
358
+ * Log information.
359
+ *
360
+ * @param msg The message to log.
361
+ */
362
+ info(e) {
363
+ const s = new c();
364
+ s.level = o.Information, s.message = e, this.logMessage(s);
365
+ }
366
+ /**
367
+ * Log warning.
368
+ *
369
+ * @param msg The message to log.
370
+ */
371
+ warn(e) {
372
+ const s = new c();
373
+ s.level = o.Warning, s.message = e, this.logMessage(s);
374
+ }
375
+ /**
376
+ * Log error.
377
+ *
378
+ * @param msg The message to log.
379
+ */
380
+ error(e) {
381
+ const s = new c();
382
+ s.level = o.Error, s.message = e, this.logMessage(s);
383
+ }
384
+ /**
385
+ * Log error.
386
+ *
387
+ * @param msg The message to log.
388
+ */
389
+ crit(e) {
390
+ const s = new c();
391
+ s.level = o.Critical, s.message = e, this.logMessage(s);
392
+ }
393
+ /**
394
+ * Log an event.
395
+ *
396
+ * @param {LogLevel} level The level to log the event.
397
+ * @param {String} message Custom message.
398
+ * @param {Error} e The error associated with the event.
399
+ * @param {ExtraParams} params Extra parameters.
400
+ */
401
+ log(e, s, i, n) {
402
+ const a = new c();
403
+ a.level = e, a.message = s, a.errorMessage = i == null ? void 0 : i.message, a.stackTrace = i == null ? void 0 : i.stack, a.extraParams = n, this.logMessage(a);
404
+ }
405
+ /**
406
+ * Log a message.
407
+ *
408
+ * @param {LogMessage} message The message to log.
409
+ */
410
+ logMessage(e) {
411
+ this.isEnabled(e.level) && setTimeout(() => {
412
+ this.logMessageCore(e);
413
+ }, 1);
414
+ }
415
+ }
416
+ class M {
417
+ constructor() {
418
+ /**
419
+ * The name of the logger.
420
+ */
421
+ r(this, "name", "");
422
+ /**
423
+ * The reporter for the messages.
424
+ */
425
+ r(this, "reporter", null);
426
+ /**
427
+ * The minimum log level.
428
+ */
429
+ r(this, "minimumLevel", o.Warning);
430
+ /**
431
+ * Log enrichers.
432
+ */
433
+ r(this, "enrichers", []);
434
+ }
435
+ /**
436
+ * Get the LogLevel from a string value.
437
+ *
438
+ * @param {String} level The log level as string.
439
+ */
440
+ static getLevel(e) {
441
+ switch ((e || "").toUpperCase()) {
442
+ case "TRACE":
443
+ return o.Trace;
444
+ case "DEBUG":
445
+ return o.Debug;
446
+ case "INFORMATION":
447
+ return o.Information;
448
+ case "WARNING":
449
+ return o.Warning;
450
+ case "ERROR":
451
+ return o.Error;
452
+ case "CRITICAL":
453
+ return o.Critical;
454
+ case "NONE":
455
+ return o.None;
456
+ default:
457
+ return o.None;
458
+ }
459
+ }
460
+ }
461
+ export {
462
+ d as ConsoleReporter,
463
+ f as DynamicValuesEnricher,
464
+ v as InMemoryReporter,
465
+ o as LogLevel,
466
+ c as LogMessage,
467
+ T as Logger,
468
+ M as LoggerOptions,
469
+ y as MultipleReporter,
470
+ g as PubSubHub,
471
+ p as ValuesEnricher,
472
+ w as XhrReporter,
473
+ b as XhrReporterOptions,
474
+ m as delay
475
+ };
@@ -0,0 +1 @@
1
+ (function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.adaptArch_utilitiEs={}))})(this,function(t){"use strict";var L=Object.defineProperty;var w=(t,a,u)=>a in t?L(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var r=(t,a,u)=>(w(t,typeof a!="symbol"?a+"":a,u),u);class a{constructor(){r(this,"_subscriptions",new Map)}publish(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid message.");const o=this._subscriptions.get(e);if(o)for(const n of o.values()){const l=structuredClone(e),y=structuredClone(s);setTimeout(()=>n(l,y),0)}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let o=this._subscriptions.get(e);o||(o=new Map,this._subscriptions.set(structuredClone(e),o));const n=`sub-${Date.now()}`;return o.set(n,s),n}unsubscribe(e){if(e){for(const s of this._subscriptions.values())if(s.delete(e))return}}}function u(i=1,e){return new Promise((s,o)=>{setTimeout(()=>{e?o(e):s()},i)})}class h{constructor(e,s){r(this,"_values");r(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const o in this._values)s.indexOf(o)!==-1&&!this._overrideExisting||(e.extraParams[o]=this._values[o])}}class g{constructor(e,s){r(this,"_valuesFn");r(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const o=Object.keys(e.extraParams);for(const n in s)o.indexOf(n)!==-1&&!this._overrideExisting||(e.extraParams[n]=s[n])}}t.LogLevel=void 0,function(i){i[i.Trace=0]="Trace",i[i.Debug=1]="Debug",i[i.Information=2]="Information",i[i.Warning=3]="Warning",i[i.Error=4]="Error",i[i.Critical=5]="Critical",i[i.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class c{constructor(){r(this,"timestamp",new Date().getTime());r(this,"level",t.LogLevel.None);r(this,"name","");r(this,"message","");r(this,"errorMessage");r(this,"stackTrace");r(this,"extraParams")}}class _{constructor(e){r(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class m{constructor(){r(this,"endpoint","");r(this,"verb","POST");r(this,"batchSize",20);r(this,"interval",2e3);r(this,"requestTransform")}}class f{constructor(e){r(this,"_messageQueue");r(this,"_options");r(this,"_reportActionTimeoutRef");r(this,"_reportActionPromise");r(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const o=()=>{s(!1)},n=new XMLHttpRequest;n.open(this._options.verb,this._options.endpoint),n.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(n),n.onload=function(){s(this.status>=200&&this.status<300)},n.onerror=o,n.onabort=o,n.send(JSON.stringify(e))})}}class d{constructor(){r(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class p{constructor(e){r(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class v{constructor(e){r(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const o of this._options.enrichers)o.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new c;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new c;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new c;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new c;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new c;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new c;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,o,n){const l=new c;l.level=e,l.message=s,l.errorMessage=o==null?void 0:o.message,l.stackTrace=o==null?void 0:o.stack,l.extraParams=n,this.logMessage(l)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class b{constructor(){r(this,"name","");r(this,"reporter",null);r(this,"minimumLevel",t.LogLevel.Warning);r(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}t.ConsoleReporter=_,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=c,t.Logger=v,t.LoggerOptions=b,t.MultipleReporter=p,t.PubSubHub=a,t.ValuesEnricher=h,t.XhrReporter=f,t.XhrReporterOptions=m,t.delay=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,6 @@
1
+ /**
2
+ * SerializableValues is a type that represents common values that can be serialized as JSON in most languages.
3
+ */
4
+ export type SerializableValues = string | number | boolean | null | Date | Array<SerializableValues> | {
5
+ [key: string]: SerializableValues;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { type SerializableValues } from "./contracts";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from "./pubsub/index";
2
+ export * from "./utils/index";
3
+ export * from "./common";
4
+ export * from "./logger";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./pubsub/index";
2
+ export * from "./utils/index";
3
+ export * from "./common";
4
+ export * from "./logger";
@@ -0,0 +1,95 @@
1
+ import type { SerializableValues } from "../common";
2
+ /**
3
+ * Log level
4
+ */
5
+ export declare enum LogLevel {
6
+ /**
7
+ * Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.
8
+ */
9
+ Trace = 0,
10
+ /**
11
+ * Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
12
+ */
13
+ Debug = 1,
14
+ /**
15
+ * Logs that track the general flow of the application. These logs should have long-term value.
16
+ */
17
+ Information = 2,
18
+ /**
19
+ * Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.
20
+ */
21
+ Warning = 3,
22
+ /**
23
+ * Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.
24
+ */
25
+ Error = 4,
26
+ /**
27
+ * Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
28
+ */
29
+ Critical = 5,
30
+ /**
31
+ * Not used for writing log messages. Specifies that a logging category should not write any messages.
32
+ */
33
+ None = 6
34
+ }
35
+ /**
36
+ * Extra parameters to log.
37
+ */
38
+ export type ExtraParams = {
39
+ [id: string]: SerializableValues;
40
+ };
41
+ /**
42
+ * Base logging message
43
+ */
44
+ export declare class LogMessage {
45
+ /**
46
+ * The timestamp of the log message.
47
+ */
48
+ timestamp: number;
49
+ /**
50
+ * The level of the log message.
51
+ */
52
+ level: LogLevel;
53
+ /**
54
+ * The name of the logger.
55
+ */
56
+ name: string;
57
+ /**
58
+ * The message to log.
59
+ */
60
+ message: string;
61
+ /**
62
+ * The error message.
63
+ */
64
+ errorMessage?: string;
65
+ /**
66
+ * The stack trace of the error.
67
+ */
68
+ stackTrace?: string;
69
+ /**
70
+ * Any extra parameters to log.
71
+ */
72
+ extraParams?: ExtraParams;
73
+ }
74
+ /**
75
+ * Contract for the component responsible for reporting the logs.
76
+ */
77
+ export interface ILogsReporter extends AsyncDisposable {
78
+ /**
79
+ * Register a message to be reported immediately or queue for reporting at a latter point.
80
+ *
81
+ * @param {LogMessage} message The message to register.
82
+ */
83
+ register(message: LogMessage): void;
84
+ }
85
+ /**
86
+ * Enrich the log message with extra information.
87
+ */
88
+ export interface ILogMessageEnricher {
89
+ /**
90
+ * Enrich the log message with extra information.
91
+ *
92
+ * @param message The log message.
93
+ */
94
+ enrich(message: LogMessage): void;
95
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Log level
3
+ */
4
+ export var LogLevel;
5
+ (function (LogLevel) {
6
+ /**
7
+ * Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.
8
+ */
9
+ LogLevel[LogLevel["Trace"] = 0] = "Trace";
10
+ /**
11
+ * Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
12
+ */
13
+ LogLevel[LogLevel["Debug"] = 1] = "Debug";
14
+ /**
15
+ * Logs that track the general flow of the application. These logs should have long-term value.
16
+ */
17
+ LogLevel[LogLevel["Information"] = 2] = "Information";
18
+ /**
19
+ * Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the application execution to stop.
20
+ */
21
+ LogLevel[LogLevel["Warning"] = 3] = "Warning";
22
+ /**
23
+ * Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a failure in the current activity, not an application-wide failure.
24
+ */
25
+ LogLevel[LogLevel["Error"] = 4] = "Error";
26
+ /**
27
+ * Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
28
+ */
29
+ LogLevel[LogLevel["Critical"] = 5] = "Critical";
30
+ /**
31
+ * Not used for writing log messages. Specifies that a logging category should not write any messages.
32
+ */
33
+ LogLevel[LogLevel["None"] = 6] = "None";
34
+ })(LogLevel || (LogLevel = {}));
35
+ /**
36
+ * Base logging message
37
+ */
38
+ export class LogMessage {
39
+ /**
40
+ * The timestamp of the log message.
41
+ */
42
+ timestamp = new Date().getTime();
43
+ /**
44
+ * The level of the log message.
45
+ */
46
+ level = LogLevel.None;
47
+ /**
48
+ * The name of the logger.
49
+ */
50
+ name = "";
51
+ /**
52
+ * The message to log.
53
+ */
54
+ message = "";
55
+ /**
56
+ * The error message.
57
+ */
58
+ errorMessage;
59
+ /**
60
+ * The stack trace of the error.
61
+ */
62
+ stackTrace;
63
+ /**
64
+ * Any extra parameters to log.
65
+ */
66
+ extraParams;
67
+ }
@@ -0,0 +1,20 @@
1
+ import type { ExtraParams, ILogMessageEnricher, LogMessage } from "../contracts";
2
+ /**
3
+ * A function that returns the values to add to the log.
4
+ */
5
+ export type DynamicValuesFunction = () => ExtraParams;
6
+ export declare class DynamicValuesEnricher implements ILogMessageEnricher {
7
+ private _valuesFn;
8
+ private _overrideExisting;
9
+ /**
10
+ * Constructor.
11
+ *
12
+ * @param {DynamicValuesFunction} valuesFunction The values to add to the log.
13
+ * @param {boolean} overrideExisting Override a value if it already exists.
14
+ */
15
+ constructor(valuesFunction: DynamicValuesFunction, overrideExisting: boolean);
16
+ /**
17
+ * @inheritdoc
18
+ */
19
+ enrich(message: LogMessage): void;
20
+ }