@adapt-arch/utiliti-es 0.3.4 → 0.4.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.
- package/dist/bundle/utiliti-es.cjs +1 -1
- package/dist/bundle/utiliti-es.iife.js +1 -1
- package/dist/bundle/utiliti-es.js +396 -388
- package/dist/bundle/utiliti-es.umd.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logger/contracts.d.ts +1 -1
- package/dist/logger/contracts.js +1 -1
- package/dist/logger/enrichers/index.d.ts +1 -1
- package/dist/logger/enrichers/index.js +1 -1
- package/dist/logger/index.d.ts +2 -2
- package/dist/logger/index.js +2 -2
- package/dist/logger/logger.d.ts +2 -1
- package/dist/logger/logger.js +35 -3
- package/dist/logger/reporters/index.d.ts +1 -1
- package/dist/logger/reporters/index.js +1 -1
- package/dist/logger/reporters/multipleReporter.js +1 -1
- package/dist/pubsub/index.d.ts +2 -2
- package/dist/pubsub/index.js +1 -1
- package/package.json +12 -12
|
@@ -1,125 +1,65 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const e = i.timeouts.indexOf(s);
|
|
7
|
-
i.timeouts.splice(e, 1);
|
|
8
|
-
};
|
|
9
|
-
class y {
|
|
1
|
+
var r;
|
|
2
|
+
(function(i) {
|
|
3
|
+
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";
|
|
4
|
+
})(r || (r = {}));
|
|
5
|
+
class a {
|
|
10
6
|
/**
|
|
11
|
-
*
|
|
7
|
+
* The timestamp of the log message.
|
|
12
8
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const u = {};
|
|
39
|
-
l.timeouts.push(u), u.ref = setTimeout((p, _, g, m) => {
|
|
40
|
-
p.handler(g, m), h(l, _);
|
|
41
|
-
}, 0, l, u, structuredClone(t.topic), structuredClone(t.message));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/** @inheritdoc */
|
|
45
|
-
subscribe(s, e) {
|
|
46
|
-
if (!s)
|
|
47
|
-
throw new Error("Invalid topic.");
|
|
48
|
-
if (!e)
|
|
49
|
-
throw new Error("Invalid handler.");
|
|
50
|
-
let t = this._subscriptions.get(s);
|
|
51
|
-
t || (t = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), t));
|
|
52
|
-
const n = `sub-${Date.now()}`;
|
|
53
|
-
return t.set(n, { handler: e, timeouts: [] }), n;
|
|
54
|
-
}
|
|
55
|
-
/** @inheritdoc */
|
|
56
|
-
unsubscribe(s) {
|
|
57
|
-
if (s)
|
|
58
|
-
for (const e of this._subscriptions.values()) {
|
|
59
|
-
for (const t of e.values())
|
|
60
|
-
for (; ; ) {
|
|
61
|
-
const n = t.timeouts.pop();
|
|
62
|
-
if (!n)
|
|
63
|
-
break;
|
|
64
|
-
h(t, n);
|
|
65
|
-
}
|
|
66
|
-
if (e.delete(s))
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
[Symbol.dispose]() {
|
|
71
|
-
var s;
|
|
72
|
-
for (const e of this._subscriptions.values())
|
|
73
|
-
for (const t of e.keys())
|
|
74
|
-
this.unsubscribe(t);
|
|
75
|
-
if (this._subscriptions.clear(), (s = this._options) != null && s.plugins)
|
|
76
|
-
for (const e of this._options.plugins) {
|
|
77
|
-
const t = e[Symbol.dispose];
|
|
78
|
-
t && t.call(e);
|
|
79
|
-
}
|
|
80
|
-
return Promise.resolve();
|
|
81
|
-
}
|
|
9
|
+
timestamp = Date.now();
|
|
10
|
+
/**
|
|
11
|
+
* The level of the log message.
|
|
12
|
+
*/
|
|
13
|
+
level = r.None;
|
|
14
|
+
/**
|
|
15
|
+
* The name of the logger.
|
|
16
|
+
*/
|
|
17
|
+
name = "";
|
|
18
|
+
/**
|
|
19
|
+
* The message to log.
|
|
20
|
+
*/
|
|
21
|
+
message = "";
|
|
22
|
+
/**
|
|
23
|
+
* The error message.
|
|
24
|
+
*/
|
|
25
|
+
errorMessage;
|
|
26
|
+
/**
|
|
27
|
+
* The stack trace of the error.
|
|
28
|
+
*/
|
|
29
|
+
stackTrace;
|
|
30
|
+
/**
|
|
31
|
+
* Any extra parameters to log.
|
|
32
|
+
*/
|
|
33
|
+
extraParams;
|
|
82
34
|
}
|
|
83
|
-
class
|
|
35
|
+
class f {
|
|
36
|
+
_valuesFn;
|
|
37
|
+
_overrideExisting;
|
|
84
38
|
/**
|
|
85
39
|
* Constructor.
|
|
86
40
|
*
|
|
87
|
-
* @param {
|
|
41
|
+
* @param {DynamicValuesFunction} valuesFunction The values to add to the log.
|
|
42
|
+
* @param {boolean} overrideExisting Override a value if it already exists.
|
|
88
43
|
*/
|
|
89
|
-
constructor(s) {
|
|
90
|
-
|
|
91
|
-
r(this, "_channel");
|
|
92
|
-
r(this, "_eventListeners", null);
|
|
93
|
-
r(this, "_broadcastEnabled", !0);
|
|
94
|
-
this._options = s, this._channel = new BroadcastChannel(this._options.channelName);
|
|
95
|
-
}
|
|
96
|
-
/** @inheritdoc */
|
|
97
|
-
init(s) {
|
|
98
|
-
this._eventListeners || (this._eventListeners = (e) => {
|
|
99
|
-
const t = e.data;
|
|
100
|
-
if (!(!t.topic || !t.message))
|
|
101
|
-
try {
|
|
102
|
-
this._broadcastEnabled = !1, s.publish(t.topic, t.message);
|
|
103
|
-
} finally {
|
|
104
|
-
this._broadcastEnabled = !0;
|
|
105
|
-
}
|
|
106
|
-
}, this._channel.addEventListener("message", this._eventListeners));
|
|
44
|
+
constructor(s, e) {
|
|
45
|
+
this._valuesFn = s, this._overrideExisting = e;
|
|
107
46
|
}
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @inheritdoc
|
|
49
|
+
*/
|
|
50
|
+
enrich(s) {
|
|
51
|
+
const e = typeof this._valuesFn == "function" ? this._valuesFn() : void 0;
|
|
52
|
+
if (!e)
|
|
111
53
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this._channel.postMessage(e);
|
|
117
|
-
}
|
|
118
|
-
[Symbol.dispose]() {
|
|
119
|
-
this._eventListeners && this._channel.removeEventListener("message", this._eventListeners), this._channel.close();
|
|
54
|
+
s.extraParams = s.extraParams || {};
|
|
55
|
+
const t = Object.keys(s.extraParams);
|
|
56
|
+
for (const o in e)
|
|
57
|
+
t.indexOf(o) !== -1 && !this._overrideExisting || (s.extraParams[o] = e[o]);
|
|
120
58
|
}
|
|
121
59
|
}
|
|
122
|
-
class
|
|
60
|
+
class d {
|
|
61
|
+
_values;
|
|
62
|
+
_overrideExisting;
|
|
123
63
|
/**
|
|
124
64
|
* Constructor.
|
|
125
65
|
*
|
|
@@ -127,8 +67,6 @@ class T {
|
|
|
127
67
|
* @param {boolean} overrideExisting Override a value if it already exists.
|
|
128
68
|
*/
|
|
129
69
|
constructor(s, e) {
|
|
130
|
-
r(this, "_values");
|
|
131
|
-
r(this, "_overrideExisting");
|
|
132
70
|
this._values = s, this._overrideExisting = e;
|
|
133
71
|
}
|
|
134
72
|
/**
|
|
@@ -143,75 +81,172 @@ class T {
|
|
|
143
81
|
e.indexOf(t) !== -1 && !this._overrideExisting || (s.extraParams[t] = this._values[t]);
|
|
144
82
|
}
|
|
145
83
|
}
|
|
146
|
-
class
|
|
84
|
+
class b {
|
|
85
|
+
_options;
|
|
147
86
|
/**
|
|
148
87
|
* Constructor.
|
|
149
88
|
*
|
|
150
|
-
* @param {
|
|
151
|
-
* @param {boolean} overrideExisting Override a value if it already exists.
|
|
89
|
+
* @param {LoggerOptions} options The logger options.
|
|
152
90
|
*/
|
|
153
|
-
constructor(s
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
91
|
+
constructor(s) {
|
|
92
|
+
this._options = s;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The core logging method.
|
|
96
|
+
*
|
|
97
|
+
* @param {LogMessage} message The message to log.
|
|
98
|
+
*/
|
|
99
|
+
logMessageCore(s) {
|
|
100
|
+
s.name = this._options.name;
|
|
101
|
+
for (const e of this._options.enrichers)
|
|
102
|
+
e.enrich(s);
|
|
103
|
+
this._options.reporter?.register(s);
|
|
157
104
|
}
|
|
158
105
|
/**
|
|
159
106
|
* @inheritdoc
|
|
160
107
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
108
|
+
async [Symbol.asyncDispose]() {
|
|
109
|
+
await this._options.reporter?.[Symbol.asyncDispose]();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @inheritdoc
|
|
113
|
+
*/
|
|
114
|
+
isEnabled(s) {
|
|
115
|
+
return s !== r.None && s >= this._options.minimumLevel;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @inheritdoc
|
|
119
|
+
*/
|
|
120
|
+
trace(s) {
|
|
121
|
+
const e = new a();
|
|
122
|
+
e.level = r.Trace, e.message = s, this.logMessage(e);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @inheritdoc
|
|
126
|
+
*/
|
|
127
|
+
debug(s) {
|
|
128
|
+
const e = new a();
|
|
129
|
+
e.level = r.Debug, e.message = s, this.logMessage(e);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @inheritdoc
|
|
133
|
+
*/
|
|
134
|
+
info(s) {
|
|
135
|
+
const e = new a();
|
|
136
|
+
e.level = r.Information, e.message = s, this.logMessage(e);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @inheritdoc
|
|
140
|
+
*/
|
|
141
|
+
warn(s) {
|
|
142
|
+
const e = new a();
|
|
143
|
+
e.level = r.Warning, e.message = s, this.logMessage(e);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @inheritdoc
|
|
147
|
+
*/
|
|
148
|
+
error(s) {
|
|
149
|
+
const e = new a();
|
|
150
|
+
e.level = r.Error, e.message = s, this.logMessage(e);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @inheritdoc
|
|
154
|
+
*/
|
|
155
|
+
crit(s) {
|
|
156
|
+
const e = new a();
|
|
157
|
+
e.level = r.Critical, e.message = s, this.logMessage(e);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @inheritdoc
|
|
161
|
+
*/
|
|
162
|
+
log(s, e, t, o) {
|
|
163
|
+
const n = new a(), c = this._extractErrorDetails(t);
|
|
164
|
+
n.level = s, n.message = e, n.errorMessage = c?.message, n.stackTrace = c?.stack, n.extraParams = o, this.logMessage(n);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @inheritdoc
|
|
168
|
+
*/
|
|
169
|
+
logMessage(s) {
|
|
170
|
+
this.isEnabled(s.level) && setTimeout(() => {
|
|
171
|
+
this.logMessageCore(s);
|
|
172
|
+
}, 1);
|
|
173
|
+
}
|
|
174
|
+
_extractErrorDetails(s) {
|
|
175
|
+
if (s instanceof Error)
|
|
176
|
+
return { message: s.message, stack: s.stack };
|
|
177
|
+
switch (typeof s) {
|
|
178
|
+
case "string":
|
|
179
|
+
return { message: s };
|
|
180
|
+
case "object": {
|
|
181
|
+
const e = s;
|
|
182
|
+
if (e === null)
|
|
183
|
+
break;
|
|
184
|
+
const t = {
|
|
185
|
+
message: e.message ?? e.Message,
|
|
186
|
+
stack: e.stack ?? e.Stack ?? e.stackTrace ?? e.StackTrace
|
|
187
|
+
};
|
|
188
|
+
return t.message === void 0 && (t.message = JSON.stringify(s)), t;
|
|
189
|
+
}
|
|
190
|
+
default: {
|
|
191
|
+
const e = s;
|
|
192
|
+
if (typeof e?.toString == "function")
|
|
193
|
+
return { message: e.toString() };
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
169
197
|
}
|
|
170
198
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
class v {
|
|
200
|
+
/**
|
|
201
|
+
* The name of the logger.
|
|
202
|
+
*/
|
|
203
|
+
name = "";
|
|
204
|
+
/**
|
|
205
|
+
* The reporter for the messages.
|
|
206
|
+
*/
|
|
207
|
+
reporter = null;
|
|
208
|
+
/**
|
|
209
|
+
* The minimum log level.
|
|
210
|
+
*/
|
|
211
|
+
minimumLevel = r.Warning;
|
|
212
|
+
/**
|
|
213
|
+
* Log enrichers.
|
|
214
|
+
*/
|
|
215
|
+
enrichers = [];
|
|
216
|
+
/**
|
|
217
|
+
* Get the LogLevel from a string value.
|
|
218
|
+
*
|
|
219
|
+
* @param {String} level The log level as string.
|
|
220
|
+
*/
|
|
221
|
+
static getLevel(s) {
|
|
222
|
+
switch ((s || "").toUpperCase()) {
|
|
223
|
+
case "TRACE":
|
|
224
|
+
return r.Trace;
|
|
225
|
+
case "DEBUG":
|
|
226
|
+
return r.Debug;
|
|
227
|
+
case "INFORMATION":
|
|
228
|
+
return r.Information;
|
|
229
|
+
case "WARNING":
|
|
230
|
+
return r.Warning;
|
|
231
|
+
case "ERROR":
|
|
232
|
+
return r.Error;
|
|
233
|
+
case "CRITICAL":
|
|
234
|
+
return r.Critical;
|
|
235
|
+
case "NONE":
|
|
236
|
+
return r.None;
|
|
237
|
+
default:
|
|
238
|
+
return r.None;
|
|
239
|
+
}
|
|
205
240
|
}
|
|
206
241
|
}
|
|
207
|
-
class
|
|
242
|
+
class y {
|
|
243
|
+
_console;
|
|
208
244
|
/**
|
|
209
245
|
* Constructor.
|
|
210
246
|
*
|
|
211
247
|
* @param {Console} console The current console reference.
|
|
212
248
|
*/
|
|
213
249
|
constructor(s) {
|
|
214
|
-
r(this, "_console");
|
|
215
250
|
this._console = s;
|
|
216
251
|
}
|
|
217
252
|
/**
|
|
@@ -221,22 +256,22 @@ class M {
|
|
|
221
256
|
let e;
|
|
222
257
|
if (this._console)
|
|
223
258
|
switch (s.level) {
|
|
224
|
-
case
|
|
259
|
+
case r.Trace:
|
|
225
260
|
e = this._console.trace || this._console.log;
|
|
226
261
|
break;
|
|
227
|
-
case
|
|
262
|
+
case r.Debug:
|
|
228
263
|
e = this._console.debug || this._console.log;
|
|
229
264
|
break;
|
|
230
|
-
case
|
|
265
|
+
case r.Information:
|
|
231
266
|
e = this._console.info || this._console.log;
|
|
232
267
|
break;
|
|
233
|
-
case
|
|
268
|
+
case r.Warning:
|
|
234
269
|
e = this._console.warn || this._console.log;
|
|
235
270
|
break;
|
|
236
|
-
case
|
|
271
|
+
case r.Error:
|
|
237
272
|
e = this._console.error || this._console.log;
|
|
238
273
|
break;
|
|
239
|
-
case
|
|
274
|
+
case r.Critical:
|
|
240
275
|
e = this._console.error || this._console.log;
|
|
241
276
|
break;
|
|
242
277
|
// case LogLevel.None: // Do not log.
|
|
@@ -253,89 +288,8 @@ class M {
|
|
|
253
288
|
return Promise.resolve();
|
|
254
289
|
}
|
|
255
290
|
}
|
|
256
|
-
class
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Endpoint that receives the logs.
|
|
260
|
-
*/
|
|
261
|
-
r(this, "endpoint", "");
|
|
262
|
-
/**
|
|
263
|
-
* HTTP verb used when calling the endpoint.
|
|
264
|
-
*/
|
|
265
|
-
r(this, "verb", "POST");
|
|
266
|
-
/**
|
|
267
|
-
* The number of items to send in a batch.
|
|
268
|
-
*/
|
|
269
|
-
r(this, "batchSize", 20);
|
|
270
|
-
/**
|
|
271
|
-
* The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
|
|
272
|
-
*/
|
|
273
|
-
r(this, "interval", 2e3);
|
|
274
|
-
/**
|
|
275
|
-
* A function that can be used to transform the request before sending it.
|
|
276
|
-
*/
|
|
277
|
-
r(this, "requestTransform");
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
class R {
|
|
281
|
-
constructor(s) {
|
|
282
|
-
r(this, "_messageQueue");
|
|
283
|
-
r(this, "_options");
|
|
284
|
-
r(this, "_reportActionTimeoutRef");
|
|
285
|
-
r(this, "_reportActionPromise");
|
|
286
|
-
r(this, "_disposed");
|
|
287
|
-
if (!s)
|
|
288
|
-
throw new Error('Argument "options" is required');
|
|
289
|
-
this._messageQueue = [], this._options = s, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* @inheritdoc
|
|
293
|
-
*/
|
|
294
|
-
register(s) {
|
|
295
|
-
this._disposed || (this._messageQueue.push(s), this._scheduleNextProcessAction());
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* @inheritdoc
|
|
299
|
-
*/
|
|
300
|
-
async [Symbol.asyncDispose]() {
|
|
301
|
-
if (this._disposed)
|
|
302
|
-
return Promise.resolve();
|
|
303
|
-
await (this._reportActionPromise ?? this._processMessages()), this._disposed = !0;
|
|
304
|
-
}
|
|
305
|
-
_scheduleNextProcessAction() {
|
|
306
|
-
if (this._reportActionTimeoutRef)
|
|
307
|
-
return;
|
|
308
|
-
const s = this._messageQueue.length >= this._options.batchSize ? 0 : this._options.interval;
|
|
309
|
-
this._reportActionTimeoutRef = setTimeout(() => {
|
|
310
|
-
this._reportActionPromise = this._processMessages().then(() => {
|
|
311
|
-
const e = this._reportActionTimeoutRef;
|
|
312
|
-
this._reportActionTimeoutRef = void 0, clearTimeout(e), this._reportActionPromise = null, this._scheduleNextProcessAction();
|
|
313
|
-
});
|
|
314
|
-
}, s);
|
|
315
|
-
}
|
|
316
|
-
async _processMessages() {
|
|
317
|
-
let s, e;
|
|
318
|
-
for (; this._messageQueue.length > 0; )
|
|
319
|
-
if (s = this._messageQueue.splice(0, Math.min(this._messageQueue.length, this._options.batchSize)), e = await this._sendMessagesBatch(s), !e) {
|
|
320
|
-
this._messageQueue.unshift(...s);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
_sendMessagesBatch(s) {
|
|
325
|
-
return new Promise((e) => {
|
|
326
|
-
const t = () => {
|
|
327
|
-
e(!1);
|
|
328
|
-
}, n = new XMLHttpRequest();
|
|
329
|
-
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() {
|
|
330
|
-
e(this.status >= 200 && this.status < 300);
|
|
331
|
-
}, n.onerror = t, n.onabort = t, n.send(JSON.stringify(s));
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
class k {
|
|
336
|
-
constructor() {
|
|
337
|
-
r(this, "_messages", []);
|
|
338
|
-
}
|
|
291
|
+
class w {
|
|
292
|
+
_messages = [];
|
|
339
293
|
get messages() {
|
|
340
294
|
return this._messages.slice();
|
|
341
295
|
}
|
|
@@ -352,9 +306,9 @@ class k {
|
|
|
352
306
|
return Promise.resolve();
|
|
353
307
|
}
|
|
354
308
|
}
|
|
355
|
-
class
|
|
309
|
+
class T {
|
|
310
|
+
_reporters;
|
|
356
311
|
constructor(s) {
|
|
357
|
-
r(this, "_reporters");
|
|
358
312
|
this._reporters = s || [];
|
|
359
313
|
}
|
|
360
314
|
/**
|
|
@@ -368,160 +322,138 @@ class A {
|
|
|
368
322
|
* @inheritdoc
|
|
369
323
|
*/
|
|
370
324
|
async [Symbol.asyncDispose]() {
|
|
371
|
-
const s =
|
|
325
|
+
const s = [];
|
|
372
326
|
for (const e of this._reporters)
|
|
373
327
|
s.push(e[Symbol.asyncDispose]());
|
|
374
328
|
s.length && await Promise.all(s);
|
|
375
329
|
}
|
|
376
330
|
}
|
|
377
|
-
class
|
|
331
|
+
class P {
|
|
378
332
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* @param {LoggerOptions} options The logger options.
|
|
333
|
+
* Endpoint that receives the logs.
|
|
382
334
|
*/
|
|
383
|
-
|
|
384
|
-
r(this, "_options");
|
|
385
|
-
this._options = s;
|
|
386
|
-
}
|
|
335
|
+
endpoint = "";
|
|
387
336
|
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
* @param {LogMessage} message The message to log.
|
|
337
|
+
* HTTP verb used when calling the endpoint.
|
|
391
338
|
*/
|
|
392
|
-
|
|
393
|
-
var e;
|
|
394
|
-
s.name = this._options.name;
|
|
395
|
-
for (const t of this._options.enrichers)
|
|
396
|
-
t.enrich(s);
|
|
397
|
-
(e = this._options.reporter) == null || e.register(s);
|
|
398
|
-
}
|
|
339
|
+
verb = "POST";
|
|
399
340
|
/**
|
|
400
|
-
*
|
|
341
|
+
* The number of items to send in a batch.
|
|
401
342
|
*/
|
|
402
|
-
|
|
403
|
-
var s;
|
|
404
|
-
await ((s = this._options.reporter) == null ? void 0 : s[Symbol.asyncDispose]());
|
|
405
|
-
}
|
|
343
|
+
batchSize = 20;
|
|
406
344
|
/**
|
|
407
|
-
*
|
|
345
|
+
* The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
|
|
408
346
|
*/
|
|
409
|
-
|
|
410
|
-
return s !== o.None && s >= this._options.minimumLevel;
|
|
411
|
-
}
|
|
347
|
+
interval = 2e3;
|
|
412
348
|
/**
|
|
413
|
-
*
|
|
349
|
+
* A function that can be used to transform the request before sending it.
|
|
414
350
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
351
|
+
requestTransform;
|
|
352
|
+
}
|
|
353
|
+
class E {
|
|
354
|
+
_messageQueue;
|
|
355
|
+
_options;
|
|
356
|
+
_reportActionTimeoutRef;
|
|
357
|
+
_reportActionPromise;
|
|
358
|
+
_disposed;
|
|
359
|
+
constructor(s) {
|
|
360
|
+
if (!s)
|
|
361
|
+
throw new Error('Argument "options" is required');
|
|
362
|
+
this._messageQueue = [], this._options = s, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
|
|
418
363
|
}
|
|
419
364
|
/**
|
|
420
365
|
* @inheritdoc
|
|
421
366
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
e.level = o.Debug, e.message = s, this.logMessage(e);
|
|
367
|
+
register(s) {
|
|
368
|
+
this._disposed || (this._messageQueue.push(s), this._scheduleNextProcessAction());
|
|
425
369
|
}
|
|
426
370
|
/**
|
|
427
371
|
* @inheritdoc
|
|
428
372
|
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
373
|
+
async [Symbol.asyncDispose]() {
|
|
374
|
+
if (this._disposed)
|
|
375
|
+
return Promise.resolve();
|
|
376
|
+
await (this._reportActionPromise ?? this._processMessages()), this._disposed = !0;
|
|
432
377
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
378
|
+
_scheduleNextProcessAction() {
|
|
379
|
+
if (this._reportActionTimeoutRef)
|
|
380
|
+
return;
|
|
381
|
+
const s = this._messageQueue.length >= this._options.batchSize ? 0 : this._options.interval;
|
|
382
|
+
this._reportActionTimeoutRef = setTimeout(() => {
|
|
383
|
+
this._reportActionPromise = this._processMessages().then(() => {
|
|
384
|
+
const e = this._reportActionTimeoutRef;
|
|
385
|
+
this._reportActionTimeoutRef = void 0, clearTimeout(e), this._reportActionPromise = null, this._scheduleNextProcessAction();
|
|
386
|
+
});
|
|
387
|
+
}, s);
|
|
439
388
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
389
|
+
async _processMessages() {
|
|
390
|
+
let s, e;
|
|
391
|
+
for (; this._messageQueue.length > 0; )
|
|
392
|
+
if (s = this._messageQueue.splice(0, Math.min(this._messageQueue.length, this._options.batchSize)), e = await this._sendMessagesBatch(s), !e) {
|
|
393
|
+
this._messageQueue.unshift(...s);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
446
396
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
397
|
+
_sendMessagesBatch(s) {
|
|
398
|
+
return new Promise((e) => {
|
|
399
|
+
const t = () => {
|
|
400
|
+
e(!1);
|
|
401
|
+
}, o = new XMLHttpRequest();
|
|
402
|
+
o.open(this._options.verb, this._options.endpoint), o.setRequestHeader("Content-Type", "application/json;charset=UTF-8"), this._options.requestTransform && this._options.requestTransform(o), o.onload = function() {
|
|
403
|
+
e(this.status >= 200 && this.status < 300);
|
|
404
|
+
}, o.onerror = t, o.onabort = t, o.send(JSON.stringify(s));
|
|
405
|
+
});
|
|
453
406
|
}
|
|
407
|
+
}
|
|
408
|
+
class k {
|
|
409
|
+
_options;
|
|
410
|
+
_channel;
|
|
411
|
+
_eventListeners = null;
|
|
412
|
+
_broadcastEnabled = !0;
|
|
454
413
|
/**
|
|
455
|
-
*
|
|
414
|
+
* Constructor.
|
|
415
|
+
*
|
|
416
|
+
* @param {Options} options The options.
|
|
456
417
|
*/
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
a.level = s, a.message = e, a.errorMessage = t == null ? void 0 : t.message, a.stackTrace = t == null ? void 0 : t.stack, a.extraParams = n, this.logMessage(a);
|
|
418
|
+
constructor(s) {
|
|
419
|
+
this._options = s, this._channel = new BroadcastChannel(this._options.channelName);
|
|
460
420
|
}
|
|
461
|
-
/**
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
421
|
+
/** @inheritdoc */
|
|
422
|
+
init(s) {
|
|
423
|
+
this._eventListeners || (this._eventListeners = (e) => {
|
|
424
|
+
const t = e.data;
|
|
425
|
+
if (!(!t.topic || !t.message))
|
|
426
|
+
try {
|
|
427
|
+
this._broadcastEnabled = !1, s.publish(t.topic, t.message);
|
|
428
|
+
} finally {
|
|
429
|
+
this._broadcastEnabled = !0;
|
|
430
|
+
}
|
|
431
|
+
}, this._channel.addEventListener("message", this._eventListeners));
|
|
468
432
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
*/
|
|
479
|
-
r(this, "reporter", null);
|
|
480
|
-
/**
|
|
481
|
-
* The minimum log level.
|
|
482
|
-
*/
|
|
483
|
-
r(this, "minimumLevel", o.Warning);
|
|
484
|
-
/**
|
|
485
|
-
* Log enrichers.
|
|
486
|
-
*/
|
|
487
|
-
r(this, "enrichers", []);
|
|
433
|
+
/** @inheritdoc */
|
|
434
|
+
onPublish(s) {
|
|
435
|
+
if (!this._broadcastEnabled || !s.topic || !s.message)
|
|
436
|
+
return;
|
|
437
|
+
const e = {
|
|
438
|
+
topic: s.topic,
|
|
439
|
+
message: s.message
|
|
440
|
+
};
|
|
441
|
+
this._channel.postMessage(e);
|
|
488
442
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
*
|
|
492
|
-
* @param {String} level The log level as string.
|
|
493
|
-
*/
|
|
494
|
-
static getLevel(s) {
|
|
495
|
-
switch ((s || "").toUpperCase()) {
|
|
496
|
-
case "TRACE":
|
|
497
|
-
return o.Trace;
|
|
498
|
-
case "DEBUG":
|
|
499
|
-
return o.Debug;
|
|
500
|
-
case "INFORMATION":
|
|
501
|
-
return o.Information;
|
|
502
|
-
case "WARNING":
|
|
503
|
-
return o.Warning;
|
|
504
|
-
case "ERROR":
|
|
505
|
-
return o.Error;
|
|
506
|
-
case "CRITICAL":
|
|
507
|
-
return o.Critical;
|
|
508
|
-
case "NONE":
|
|
509
|
-
return o.None;
|
|
510
|
-
default:
|
|
511
|
-
return o.None;
|
|
512
|
-
}
|
|
443
|
+
[Symbol.dispose]() {
|
|
444
|
+
this._eventListeners && this._channel.removeEventListener("message", this._eventListeners), this._channel.close();
|
|
513
445
|
}
|
|
514
446
|
}
|
|
515
|
-
class
|
|
447
|
+
class M {
|
|
448
|
+
_logger;
|
|
449
|
+
_logLevel;
|
|
516
450
|
/**
|
|
517
451
|
* Constructor.
|
|
518
452
|
*
|
|
519
453
|
* @param {Logger} logger The logger.
|
|
520
454
|
* @param {LogLevel} logLevel The log level.
|
|
521
455
|
*/
|
|
522
|
-
constructor(s, e =
|
|
523
|
-
r(this, "_logger");
|
|
524
|
-
r(this, "_logLevel");
|
|
456
|
+
constructor(s, e = r.Information) {
|
|
525
457
|
this._logger = s, this._logLevel = e;
|
|
526
458
|
}
|
|
527
459
|
/** @inheritdoc */
|
|
@@ -532,31 +464,107 @@ class N {
|
|
|
532
464
|
});
|
|
533
465
|
}
|
|
534
466
|
}
|
|
535
|
-
|
|
467
|
+
const l = (i, s) => {
|
|
468
|
+
clearTimeout(s.ref), s.ref = void 0;
|
|
469
|
+
const e = i.timeouts.indexOf(s);
|
|
470
|
+
i.timeouts.splice(e, 1);
|
|
471
|
+
};
|
|
472
|
+
class x {
|
|
473
|
+
_subscriptions = /* @__PURE__ */ new Map();
|
|
474
|
+
_options;
|
|
475
|
+
/**
|
|
476
|
+
*
|
|
477
|
+
*/
|
|
478
|
+
constructor(s) {
|
|
479
|
+
if (this._options = s, this._options?.plugins)
|
|
480
|
+
for (const e of this._options.plugins)
|
|
481
|
+
e.init && e.init(this);
|
|
482
|
+
}
|
|
483
|
+
/** @inheritdoc */
|
|
484
|
+
publish(s, e) {
|
|
485
|
+
const t = {
|
|
486
|
+
topic: s,
|
|
487
|
+
message: e
|
|
488
|
+
};
|
|
489
|
+
if (this._options?.plugins)
|
|
490
|
+
for (const n of this._options.plugins)
|
|
491
|
+
n.onPublish && n.onPublish(t);
|
|
492
|
+
if (!t.topic)
|
|
493
|
+
throw new Error("Invalid topic.");
|
|
494
|
+
if (!t.message)
|
|
495
|
+
throw new Error("Invalid message.");
|
|
496
|
+
const o = this._subscriptions.get(t.topic);
|
|
497
|
+
if (o)
|
|
498
|
+
for (const n of o.values()) {
|
|
499
|
+
const c = {};
|
|
500
|
+
n.timeouts.push(c), c.ref = setTimeout((u, h, g, p) => {
|
|
501
|
+
u.handler(g, p), l(n, h);
|
|
502
|
+
}, 0, n, c, structuredClone(t.topic), structuredClone(t.message));
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/** @inheritdoc */
|
|
506
|
+
subscribe(s, e) {
|
|
507
|
+
if (!s)
|
|
508
|
+
throw new Error("Invalid topic.");
|
|
509
|
+
if (!e)
|
|
510
|
+
throw new Error("Invalid handler.");
|
|
511
|
+
let t = this._subscriptions.get(s);
|
|
512
|
+
t || (t = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), t));
|
|
513
|
+
const o = `sub-${Date.now()}`;
|
|
514
|
+
return t.set(o, { handler: e, timeouts: [] }), o;
|
|
515
|
+
}
|
|
516
|
+
/** @inheritdoc */
|
|
517
|
+
unsubscribe(s) {
|
|
518
|
+
if (s)
|
|
519
|
+
for (const e of this._subscriptions.values()) {
|
|
520
|
+
for (const t of e.values())
|
|
521
|
+
for (; ; ) {
|
|
522
|
+
const o = t.timeouts.pop();
|
|
523
|
+
if (!o)
|
|
524
|
+
break;
|
|
525
|
+
l(t, o);
|
|
526
|
+
}
|
|
527
|
+
if (e.delete(s))
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
[Symbol.dispose]() {
|
|
532
|
+
for (const s of this._subscriptions.values())
|
|
533
|
+
for (const e of s.keys())
|
|
534
|
+
this.unsubscribe(e);
|
|
535
|
+
if (this._subscriptions.clear(), this._options?.plugins)
|
|
536
|
+
for (const s of this._options.plugins) {
|
|
537
|
+
const e = s[Symbol.dispose];
|
|
538
|
+
e && e.call(s);
|
|
539
|
+
}
|
|
540
|
+
return Promise.resolve();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function _(i = 1, s) {
|
|
536
544
|
return new Promise((e, t) => {
|
|
537
545
|
setTimeout(() => {
|
|
538
546
|
s ? t(s) : e();
|
|
539
547
|
}, i);
|
|
540
548
|
});
|
|
541
549
|
}
|
|
542
|
-
function
|
|
543
|
-
return i <= 0 ? Promise.resolve() :
|
|
550
|
+
function m(i = 1) {
|
|
551
|
+
return i <= 0 ? Promise.resolve() : _(0).then(() => m(i - 1));
|
|
544
552
|
}
|
|
545
553
|
export {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
554
|
+
k as BroadcastChannelPlugin,
|
|
555
|
+
y as ConsoleReporter,
|
|
556
|
+
f as DynamicValuesEnricher,
|
|
557
|
+
w as InMemoryReporter,
|
|
558
|
+
r as LogLevel,
|
|
559
|
+
a as LogMessage,
|
|
560
|
+
b as Logger,
|
|
561
|
+
v as LoggerOptions,
|
|
562
|
+
M as LoggerPlugin,
|
|
563
|
+
T as MultipleReporter,
|
|
564
|
+
x as PubSubHub,
|
|
565
|
+
d as ValuesEnricher,
|
|
566
|
+
E as XhrReporter,
|
|
567
|
+
P as XhrReporterOptions,
|
|
568
|
+
_ as delay,
|
|
569
|
+
m as nextTicks
|
|
562
570
|
};
|