@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Adaptive Architecture
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # utiliti-es
2
+ Ecma Script common utilities.
3
+
4
+ ## Status
5
+ [![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=adaptive-architecture_utiliti-es&metric=alert_status)](https://sonarcloud.io/dashboard?id=adaptive-architecture_utiliti-es)
6
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=adaptive-architecture_utiliti-es&metric=coverage)](https://sonarcloud.io/summary/new_code?id=adaptive-architecture_utiliti-es)
@@ -0,0 +1,284 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+
4
+ /**
5
+ * Mock Service Worker.
6
+ * @see https://github.com/mswjs/msw
7
+ * - Please do NOT modify this file.
8
+ * - Please do NOT serve this file on production.
9
+ */
10
+
11
+ const PACKAGE_VERSION = '2.2.14'
12
+ const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
13
+ const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
14
+ const activeClientIds = new Set()
15
+
16
+ self.addEventListener('install', function () {
17
+ self.skipWaiting()
18
+ })
19
+
20
+ self.addEventListener('activate', function (event) {
21
+ event.waitUntil(self.clients.claim())
22
+ })
23
+
24
+ self.addEventListener('message', async function (event) {
25
+ const clientId = event.source.id
26
+
27
+ if (!clientId || !self.clients) {
28
+ return
29
+ }
30
+
31
+ const client = await self.clients.get(clientId)
32
+
33
+ if (!client) {
34
+ return
35
+ }
36
+
37
+ const allClients = await self.clients.matchAll({
38
+ type: 'window',
39
+ })
40
+
41
+ switch (event.data) {
42
+ case 'KEEPALIVE_REQUEST': {
43
+ sendToClient(client, {
44
+ type: 'KEEPALIVE_RESPONSE',
45
+ })
46
+ break
47
+ }
48
+
49
+ case 'INTEGRITY_CHECK_REQUEST': {
50
+ sendToClient(client, {
51
+ type: 'INTEGRITY_CHECK_RESPONSE',
52
+ payload: {
53
+ packageVersion: PACKAGE_VERSION,
54
+ checksum: INTEGRITY_CHECKSUM,
55
+ },
56
+ })
57
+ break
58
+ }
59
+
60
+ case 'MOCK_ACTIVATE': {
61
+ activeClientIds.add(clientId)
62
+
63
+ sendToClient(client, {
64
+ type: 'MOCKING_ENABLED',
65
+ payload: true,
66
+ })
67
+ break
68
+ }
69
+
70
+ case 'MOCK_DEACTIVATE': {
71
+ activeClientIds.delete(clientId)
72
+ break
73
+ }
74
+
75
+ case 'CLIENT_CLOSED': {
76
+ activeClientIds.delete(clientId)
77
+
78
+ const remainingClients = allClients.filter((client) => {
79
+ return client.id !== clientId
80
+ })
81
+
82
+ // Unregister itself when there are no more clients
83
+ if (remainingClients.length === 0) {
84
+ self.registration.unregister()
85
+ }
86
+
87
+ break
88
+ }
89
+ }
90
+ })
91
+
92
+ self.addEventListener('fetch', function (event) {
93
+ const { request } = event
94
+
95
+ // Bypass navigation requests.
96
+ if (request.mode === 'navigate') {
97
+ return
98
+ }
99
+
100
+ // Opening the DevTools triggers the "only-if-cached" request
101
+ // that cannot be handled by the worker. Bypass such requests.
102
+ if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
103
+ return
104
+ }
105
+
106
+ // Bypass all requests when there are no active clients.
107
+ // Prevents the self-unregistered worked from handling requests
108
+ // after it's been deleted (still remains active until the next reload).
109
+ if (activeClientIds.size === 0) {
110
+ return
111
+ }
112
+
113
+ // Generate unique request ID.
114
+ const requestId = crypto.randomUUID()
115
+ event.respondWith(handleRequest(event, requestId))
116
+ })
117
+
118
+ async function handleRequest(event, requestId) {
119
+ const client = await resolveMainClient(event)
120
+ const response = await getResponse(event, client, requestId)
121
+
122
+ // Send back the response clone for the "response:*" life-cycle events.
123
+ // Ensure MSW is active and ready to handle the message, otherwise
124
+ // this message will pend indefinitely.
125
+ if (client && activeClientIds.has(client.id)) {
126
+ ;(async function () {
127
+ const responseClone = response.clone()
128
+
129
+ sendToClient(
130
+ client,
131
+ {
132
+ type: 'RESPONSE',
133
+ payload: {
134
+ requestId,
135
+ isMockedResponse: IS_MOCKED_RESPONSE in response,
136
+ type: responseClone.type,
137
+ status: responseClone.status,
138
+ statusText: responseClone.statusText,
139
+ body: responseClone.body,
140
+ headers: Object.fromEntries(responseClone.headers.entries()),
141
+ },
142
+ },
143
+ [responseClone.body],
144
+ )
145
+ })()
146
+ }
147
+
148
+ return response
149
+ }
150
+
151
+ // Resolve the main client for the given event.
152
+ // Client that issues a request doesn't necessarily equal the client
153
+ // that registered the worker. It's with the latter the worker should
154
+ // communicate with during the response resolving phase.
155
+ async function resolveMainClient(event) {
156
+ const client = await self.clients.get(event.clientId)
157
+
158
+ if (client?.frameType === 'top-level') {
159
+ return client
160
+ }
161
+
162
+ const allClients = await self.clients.matchAll({
163
+ type: 'window',
164
+ })
165
+
166
+ return allClients
167
+ .filter((client) => {
168
+ // Get only those clients that are currently visible.
169
+ return client.visibilityState === 'visible'
170
+ })
171
+ .find((client) => {
172
+ // Find the client ID that's recorded in the
173
+ // set of clients that have registered the worker.
174
+ return activeClientIds.has(client.id)
175
+ })
176
+ }
177
+
178
+ async function getResponse(event, client, requestId) {
179
+ const { request } = event
180
+
181
+ // Clone the request because it might've been already used
182
+ // (i.e. its body has been read and sent to the client).
183
+ const requestClone = request.clone()
184
+
185
+ function passthrough() {
186
+ const headers = Object.fromEntries(requestClone.headers.entries())
187
+
188
+ // Remove internal MSW request header so the passthrough request
189
+ // complies with any potential CORS preflight checks on the server.
190
+ // Some servers forbid unknown request headers.
191
+ delete headers['x-msw-intention']
192
+
193
+ return fetch(requestClone, { headers })
194
+ }
195
+
196
+ // Bypass mocking when the client is not active.
197
+ if (!client) {
198
+ return passthrough()
199
+ }
200
+
201
+ // Bypass initial page load requests (i.e. static assets).
202
+ // The absence of the immediate/parent client in the map of the active clients
203
+ // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
204
+ // and is not ready to handle requests.
205
+ if (!activeClientIds.has(client.id)) {
206
+ return passthrough()
207
+ }
208
+
209
+ // Notify the client that a request has been intercepted.
210
+ const requestBuffer = await request.arrayBuffer()
211
+ const clientMessage = await sendToClient(
212
+ client,
213
+ {
214
+ type: 'REQUEST',
215
+ payload: {
216
+ id: requestId,
217
+ url: request.url,
218
+ mode: request.mode,
219
+ method: request.method,
220
+ headers: Object.fromEntries(request.headers.entries()),
221
+ cache: request.cache,
222
+ credentials: request.credentials,
223
+ destination: request.destination,
224
+ integrity: request.integrity,
225
+ redirect: request.redirect,
226
+ referrer: request.referrer,
227
+ referrerPolicy: request.referrerPolicy,
228
+ body: requestBuffer,
229
+ keepalive: request.keepalive,
230
+ },
231
+ },
232
+ [requestBuffer],
233
+ )
234
+
235
+ switch (clientMessage.type) {
236
+ case 'MOCK_RESPONSE': {
237
+ return respondWithMock(clientMessage.data)
238
+ }
239
+
240
+ case 'PASSTHROUGH': {
241
+ return passthrough()
242
+ }
243
+ }
244
+
245
+ return passthrough()
246
+ }
247
+
248
+ function sendToClient(client, message, transferrables = []) {
249
+ return new Promise((resolve, reject) => {
250
+ const channel = new MessageChannel()
251
+
252
+ channel.port1.onmessage = (event) => {
253
+ if (event.data && event.data.error) {
254
+ return reject(event.data.error)
255
+ }
256
+
257
+ resolve(event.data)
258
+ }
259
+
260
+ client.postMessage(
261
+ message,
262
+ [channel.port2].concat(transferrables.filter(Boolean)),
263
+ )
264
+ })
265
+ }
266
+
267
+ async function respondWithMock(response) {
268
+ // Setting response status code to 0 is a no-op.
269
+ // However, when responding with a "Response.error()", the produced Response
270
+ // instance will have status code set to 0. Since it's not possible to create
271
+ // a Response instance with status code 0, handle that use-case separately.
272
+ if (response.status === 0) {
273
+ return Response.error()
274
+ }
275
+
276
+ const mockedResponse = new Response(response.body, response)
277
+
278
+ Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
279
+ value: true,
280
+ enumerable: true,
281
+ })
282
+
283
+ return mockedResponse
284
+ }
@@ -0,0 +1 @@
1
+ "use strict";var l=Object.defineProperty;var u=(t,e,s)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var r=(t,e,s)=>(u(t,typeof e!="symbol"?e+"":e,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class h{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 i of o.values()){const n=structuredClone(e),c=structuredClone(s);setTimeout(()=>i(n,c),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 i=`sub-${Date.now()}`;return o.set(i,s),i}unsubscribe(e){if(e){for(const s of this._subscriptions.values())if(s.delete(e))return}}}function g(t=1,e){return new Promise((s,o)=>{setTimeout(()=>{e?o(e):s()},t)})}class p{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 _{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 i in s)o.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=s[i])}}exports.LogLevel=void 0;(function(t){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"})(exports.LogLevel||(exports.LogLevel={}));class a{constructor(){r(this,"timestamp",new Date().getTime());r(this,"level",exports.LogLevel.None);r(this,"name","");r(this,"message","");r(this,"errorMessage");r(this,"stackTrace");r(this,"extraParams")}}class m{constructor(e){r(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case exports.LogLevel.Trace:s=this._console.trace||this._console.log;break;case exports.LogLevel.Debug:s=this._console.debug||this._console.log;break;case exports.LogLevel.Information:s=this._console.info||this._console.log;break;case exports.LogLevel.Warning:s=this._console.warn||this._console.log;break;case exports.LogLevel.Error:s=this._console.error||this._console.log;break;case exports.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 f{constructor(){r(this,"endpoint","");r(this,"verb","POST");r(this,"batchSize",20);r(this,"interval",2e3);r(this,"requestTransform")}}class d{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)},i=new XMLHttpRequest;i.open(this._options.verb,this._options.endpoint),i.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(i),i.onload=function(){s(this.status>=200&&this.status<300)},i.onerror=o,i.onabort=o,i.send(JSON.stringify(e))})}}class v{constructor(){r(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class b{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 L{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!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,o,i){const n=new a;n.level=e,n.message=s,n.errorMessage=o==null?void 0:o.message,n.stackTrace=o==null?void 0:o.stack,n.extraParams=i,this.logMessage(n)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){r(this,"name","");r(this,"reporter",null);r(this,"minimumLevel",exports.LogLevel.Warning);r(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return exports.LogLevel.Trace;case"DEBUG":return exports.LogLevel.Debug;case"INFORMATION":return exports.LogLevel.Information;case"WARNING":return exports.LogLevel.Warning;case"ERROR":return exports.LogLevel.Error;case"CRITICAL":return exports.LogLevel.Critical;case"NONE":return exports.LogLevel.None;default:return exports.LogLevel.None}}}exports.ConsoleReporter=m;exports.DynamicValuesEnricher=_;exports.InMemoryReporter=v;exports.LogMessage=a;exports.Logger=L;exports.LoggerOptions=w;exports.MultipleReporter=b;exports.PubSubHub=h;exports.ValuesEnricher=p;exports.XhrReporter=d;exports.XhrReporterOptions=f;exports.delay=g;
@@ -0,0 +1 @@
1
+ var adaptArch_utilitiEs=function(t){"use strict";var w=Object.defineProperty;var y=(t,a,u)=>a in t?w(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var r=(t,a,u)=>(y(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),L=structuredClone(s);setTimeout(()=>n(l,L),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 v{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 p{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}}}return t.ConsoleReporter=_,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=c,t.Logger=p,t.LoggerOptions=b,t.MultipleReporter=v,t.PubSubHub=a,t.ValuesEnricher=h,t.XhrReporter=f,t.XhrReporterOptions=m,t.delay=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});