@muspellheim/shared 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +556 -0
- package/dist/mod.js +524 -0
- package/dist/types/common/clock.d.ts +40 -0
- package/dist/types/common/event_tracker.d.ts +44 -0
- package/dist/types/common/log.d.ts +17 -0
- package/{src/common/mod.ts → dist/types/common/mod.d.ts} +0 -2
- package/{src/domain/messages.ts → dist/types/domain/messages.d.ts} +13 -24
- package/dist/types/domain/mod.d.ts +1 -0
- package/dist/types/infrastructure/configurable_responses.d.ts +58 -0
- package/dist/types/infrastructure/console_log.d.ts +34 -0
- package/dist/types/infrastructure/fetch_stub.d.ts +20 -0
- package/dist/types/infrastructure/message_client.d.ts +44 -0
- package/{src/infrastructure/mod.ts → dist/types/infrastructure/mod.d.ts} +0 -2
- package/dist/types/infrastructure/output_tracker.d.ts +60 -0
- package/dist/types/infrastructure/sse_client.d.ts +37 -0
- package/dist/types/infrastructure/web_socket_client.d.ts +79 -0
- package/{src/mod.ts → dist/types/mod.d.ts} +0 -2
- package/package.json +14 -23
- package/dist/shared.d.ts +0 -494
- package/dist/shared.js +0 -670
- package/dist/shared.js.map +0 -1
- package/dist/shared.umd.cjs +0 -2
- package/dist/shared.umd.cjs.map +0 -1
- package/src/common/clock.ts +0 -60
- package/src/common/event_tracker.ts +0 -94
- package/src/common/log.ts +0 -27
- package/src/domain/mod.ts +0 -3
- package/src/infrastructure/configurable_responses.ts +0 -90
- package/src/infrastructure/console_log.ts +0 -160
- package/src/infrastructure/fetch_stub.ts +0 -89
- package/src/infrastructure/message_client.ts +0 -50
- package/src/infrastructure/output_tracker.ts +0 -89
- package/src/infrastructure/sse_client.ts +0 -162
- package/src/infrastructure/web_socket_client.ts +0 -279
- package/src/vite-env.d.ts +0 -3
package/dist/shared.js
DELETED
|
@@ -1,670 +0,0 @@
|
|
|
1
|
-
class c {
|
|
2
|
-
/**
|
|
3
|
-
* Create a clock using system the clock.
|
|
4
|
-
*
|
|
5
|
-
* @return A clock that uses the system clock.
|
|
6
|
-
*/
|
|
7
|
-
static system() {
|
|
8
|
-
return new c();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Create a clock using a fixed date.
|
|
12
|
-
*
|
|
13
|
-
* @param date The fixed date of the clock.
|
|
14
|
-
* @return A clock that always returns a fixed date.
|
|
15
|
-
*/
|
|
16
|
-
static fixed(t) {
|
|
17
|
-
return new c(new Date(t));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Create a clock that returns a fixed offset from the given clock.
|
|
21
|
-
*
|
|
22
|
-
* @param clock The clock to offset from.
|
|
23
|
-
* @param offsetMillis The offset in milliseconds.
|
|
24
|
-
* @return A clock that returns a fixed offset from the given clock.
|
|
25
|
-
*/
|
|
26
|
-
static offset(t, e) {
|
|
27
|
-
return new c(new Date(t.millis() + e));
|
|
28
|
-
}
|
|
29
|
-
#e;
|
|
30
|
-
constructor(t) {
|
|
31
|
-
this.#e = t;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Return the current timestamp of the clock.
|
|
35
|
-
*
|
|
36
|
-
* @return The current timestamp.
|
|
37
|
-
*/
|
|
38
|
-
date() {
|
|
39
|
-
return this.#e ? new Date(this.#e) : /* @__PURE__ */ new Date();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Return the current timestamp of the clock in milliseconds.
|
|
43
|
-
*
|
|
44
|
-
* @return The current timestamp in milliseconds.
|
|
45
|
-
*/
|
|
46
|
-
millis() {
|
|
47
|
-
return this.date().getTime();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class f {
|
|
51
|
-
/**
|
|
52
|
-
* Create a tracker for a specific event of an event target.
|
|
53
|
-
*
|
|
54
|
-
* @param eventTarget The target to track.
|
|
55
|
-
* @param event The event name to track.
|
|
56
|
-
*/
|
|
57
|
-
static create(t, ...e) {
|
|
58
|
-
return new f(t, e);
|
|
59
|
-
}
|
|
60
|
-
#e;
|
|
61
|
-
#t;
|
|
62
|
-
#s;
|
|
63
|
-
#r;
|
|
64
|
-
/**
|
|
65
|
-
* Create a tracker for a specific event of an event target.
|
|
66
|
-
*
|
|
67
|
-
* @param eventTarget The target to track.
|
|
68
|
-
* @param event The event name to track.
|
|
69
|
-
*/
|
|
70
|
-
constructor(t, e) {
|
|
71
|
-
this.#e = t, this.#t = e, this.#s = [], this.#r = (s) => this.#s.push(s), this.#t.forEach(
|
|
72
|
-
(s) => this.#e.addEventListener(s, this.#r)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Return the tracked events.
|
|
77
|
-
*
|
|
78
|
-
* @return The tracked events.
|
|
79
|
-
*/
|
|
80
|
-
get events() {
|
|
81
|
-
return this.#s;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Clear the tracked events and return the cleared events.
|
|
85
|
-
*
|
|
86
|
-
* @return The cleared events.
|
|
87
|
-
*/
|
|
88
|
-
clear() {
|
|
89
|
-
const t = [...this.#s];
|
|
90
|
-
return this.#s.length = 0, t;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Stop tracking.
|
|
94
|
-
*/
|
|
95
|
-
stop() {
|
|
96
|
-
this.#t.forEach(
|
|
97
|
-
(t) => this.#e.removeEventListener(t, this.#r)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Wait asynchronously for a number of events.
|
|
102
|
-
*
|
|
103
|
-
* @param count number of events, default 1.
|
|
104
|
-
*/
|
|
105
|
-
async waitFor(t = 1) {
|
|
106
|
-
return new Promise((e) => {
|
|
107
|
-
const s = () => {
|
|
108
|
-
this.#s.length >= t && (this.#t.forEach(
|
|
109
|
-
(r) => this.#e.removeEventListener(r, s)
|
|
110
|
-
), e(this.events));
|
|
111
|
-
};
|
|
112
|
-
this.#t.forEach(
|
|
113
|
-
(r) => this.#e.addEventListener(r, s)
|
|
114
|
-
), s();
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
class S {
|
|
119
|
-
isSuccess = !0;
|
|
120
|
-
result;
|
|
121
|
-
constructor(t) {
|
|
122
|
-
this.result = t;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
class N {
|
|
126
|
-
isSuccess = !1;
|
|
127
|
-
errorMessage;
|
|
128
|
-
/**
|
|
129
|
-
* Creates a failed status.
|
|
130
|
-
*
|
|
131
|
-
* @param errorMessage
|
|
132
|
-
*/
|
|
133
|
-
constructor(t) {
|
|
134
|
-
this.errorMessage = t;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
class l {
|
|
138
|
-
/**
|
|
139
|
-
* Create a list of responses (by providing an array), or a single repeating
|
|
140
|
-
* response (by providing any other type). 'Name' is optional and used in
|
|
141
|
-
* error messages.
|
|
142
|
-
*
|
|
143
|
-
* @param responses A single response or an array of responses.
|
|
144
|
-
* @param name An optional name for the responses.
|
|
145
|
-
*/
|
|
146
|
-
static create(t, e) {
|
|
147
|
-
return new l(t, e);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Convert all properties in an object into ConfigurableResponse instances.
|
|
151
|
-
* For example, { a: 1 } becomes { a: ConfigurableResponses.create(1) }.
|
|
152
|
-
* 'Name' is optional and used in error messages.
|
|
153
|
-
*
|
|
154
|
-
* @param responseObject An object with single response or an array of responses.
|
|
155
|
-
* @param name An optional name for the responses.
|
|
156
|
-
*/
|
|
157
|
-
static mapObject(t, e) {
|
|
158
|
-
const r = Object.entries(t).map(([h, n]) => {
|
|
159
|
-
const d = e === void 0 ? void 0 : `${e}: ${h}`;
|
|
160
|
-
return [h, l.create(n, d)];
|
|
161
|
-
});
|
|
162
|
-
return Object.fromEntries(r);
|
|
163
|
-
}
|
|
164
|
-
#e;
|
|
165
|
-
#t;
|
|
166
|
-
/**
|
|
167
|
-
* Create a list of responses (by providing an array), or a single repeating
|
|
168
|
-
* response (by providing any other type). 'Name' is optional and used in
|
|
169
|
-
* error messages.
|
|
170
|
-
*
|
|
171
|
-
* @param responses A single response or an array of responses.
|
|
172
|
-
* @param name An optional name for the responses.
|
|
173
|
-
*/
|
|
174
|
-
constructor(t, e) {
|
|
175
|
-
this.#e = e == null ? "" : ` in ${e}`, this.#t = Array.isArray(t) ? [...t] : t;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Get the next configured response. Throws an error when configured with a list
|
|
179
|
-
* of responses and no more responses remain.
|
|
180
|
-
*
|
|
181
|
-
* @return The next response.
|
|
182
|
-
*/
|
|
183
|
-
next() {
|
|
184
|
-
const t = Array.isArray(this.#t) ? this.#t.shift() : this.#t;
|
|
185
|
-
if (t === void 0)
|
|
186
|
-
throw new Error(`No more responses configured${this.#e}.`);
|
|
187
|
-
return t;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
class u {
|
|
191
|
-
/**
|
|
192
|
-
* Create a tracker for a specific event of an event target.
|
|
193
|
-
*
|
|
194
|
-
* @param eventTarget The target to track.
|
|
195
|
-
* @param event The event name to track.
|
|
196
|
-
*/
|
|
197
|
-
static create(t, e) {
|
|
198
|
-
return new u(t, e);
|
|
199
|
-
}
|
|
200
|
-
#e;
|
|
201
|
-
#t;
|
|
202
|
-
#s;
|
|
203
|
-
#r;
|
|
204
|
-
/**
|
|
205
|
-
* Create a tracker for a specific event of an event target.
|
|
206
|
-
*
|
|
207
|
-
* @param eventTarget The target to track.
|
|
208
|
-
* @param event The event name to track.
|
|
209
|
-
*/
|
|
210
|
-
constructor(t, e) {
|
|
211
|
-
this.#e = t, this.#t = e, this.#s = [], this.#r = (s) => this.#s.push(s.detail), this.#e.addEventListener(this.#t, this.#r);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Return the tracked data.
|
|
215
|
-
*
|
|
216
|
-
* @return The tracked data.
|
|
217
|
-
*/
|
|
218
|
-
get data() {
|
|
219
|
-
return this.#s;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Clear the tracked data and return the cleared data.
|
|
223
|
-
*
|
|
224
|
-
* @return The cleared data.
|
|
225
|
-
*/
|
|
226
|
-
clear() {
|
|
227
|
-
const t = [...this.#s];
|
|
228
|
-
return this.#s.length = 0, t;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Stop tracking.
|
|
232
|
-
*/
|
|
233
|
-
stop() {
|
|
234
|
-
this.#e.removeEventListener(this.#t, this.#r);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const i = "message";
|
|
238
|
-
class E extends EventTarget {
|
|
239
|
-
static create({ name: t } = {}) {
|
|
240
|
-
return new E(globalThis.console, t);
|
|
241
|
-
}
|
|
242
|
-
static createNull({ name: t } = {}) {
|
|
243
|
-
return new E(new p(), t);
|
|
244
|
-
}
|
|
245
|
-
name;
|
|
246
|
-
level = "info";
|
|
247
|
-
#e;
|
|
248
|
-
constructor(t, e) {
|
|
249
|
-
super(), this.name = e, this.#e = t;
|
|
250
|
-
}
|
|
251
|
-
log(...t) {
|
|
252
|
-
this.isLoggable("log") && (t = this.#t(t), this.#e.log(...t), this.dispatchEvent(
|
|
253
|
-
new CustomEvent(i, {
|
|
254
|
-
detail: { level: "log", message: t }
|
|
255
|
-
})
|
|
256
|
-
));
|
|
257
|
-
}
|
|
258
|
-
error(...t) {
|
|
259
|
-
this.isLoggable("error") && (t = this.#t(t), this.#e.error(...t), this.dispatchEvent(
|
|
260
|
-
new CustomEvent(i, {
|
|
261
|
-
detail: { level: "error", message: t }
|
|
262
|
-
})
|
|
263
|
-
));
|
|
264
|
-
}
|
|
265
|
-
warn(...t) {
|
|
266
|
-
this.isLoggable("warn") && (t = this.#t(t), this.#e.warn(...t), this.dispatchEvent(
|
|
267
|
-
new CustomEvent(i, {
|
|
268
|
-
detail: { level: "warn", message: t }
|
|
269
|
-
})
|
|
270
|
-
));
|
|
271
|
-
}
|
|
272
|
-
info(...t) {
|
|
273
|
-
this.isLoggable("info") && (t = this.#t(t), this.#e.info(...t), this.dispatchEvent(
|
|
274
|
-
new CustomEvent(i, {
|
|
275
|
-
detail: { level: "info", message: t }
|
|
276
|
-
})
|
|
277
|
-
));
|
|
278
|
-
}
|
|
279
|
-
debug(...t) {
|
|
280
|
-
this.isLoggable("debug") && (t = this.#t(t), this.#e.debug(...t), this.dispatchEvent(
|
|
281
|
-
new CustomEvent(i, {
|
|
282
|
-
detail: { level: "debug", message: t }
|
|
283
|
-
})
|
|
284
|
-
));
|
|
285
|
-
}
|
|
286
|
-
trace(...t) {
|
|
287
|
-
this.isLoggable("trace") && (t = this.#t(t), this.#e.trace(...t), this.dispatchEvent(
|
|
288
|
-
new CustomEvent(i, {
|
|
289
|
-
detail: { level: "trace", message: t }
|
|
290
|
-
})
|
|
291
|
-
));
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Track the console messages.
|
|
295
|
-
*/
|
|
296
|
-
trackMessages() {
|
|
297
|
-
return new u(this, i);
|
|
298
|
-
}
|
|
299
|
-
isLoggable(t) {
|
|
300
|
-
const e = (n) => n === "log" ? "info" : n, s = [
|
|
301
|
-
"off",
|
|
302
|
-
"error",
|
|
303
|
-
"warn",
|
|
304
|
-
"info",
|
|
305
|
-
"debug",
|
|
306
|
-
"trace"
|
|
307
|
-
], r = s.indexOf(e(this.level));
|
|
308
|
-
return s.indexOf(e(t)) <= r;
|
|
309
|
-
}
|
|
310
|
-
#t(t) {
|
|
311
|
-
return this.name == null ? t : [`${this.name}`, ...t];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
class p {
|
|
315
|
-
log(...t) {
|
|
316
|
-
}
|
|
317
|
-
error(...t) {
|
|
318
|
-
}
|
|
319
|
-
warn(...t) {
|
|
320
|
-
}
|
|
321
|
-
info(...t) {
|
|
322
|
-
}
|
|
323
|
-
debug(...t) {
|
|
324
|
-
}
|
|
325
|
-
trace(...t) {
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
function L(a) {
|
|
329
|
-
const t = l.create(a);
|
|
330
|
-
return async function() {
|
|
331
|
-
const e = t.next();
|
|
332
|
-
if (e instanceof Error)
|
|
333
|
-
throw e;
|
|
334
|
-
return new y(e);
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
class y {
|
|
338
|
-
#e;
|
|
339
|
-
#t;
|
|
340
|
-
#s;
|
|
341
|
-
constructor({ status: t, statusText: e, body: s = null }) {
|
|
342
|
-
this.#e = t, this.#t = e, this.#s = s;
|
|
343
|
-
}
|
|
344
|
-
get ok() {
|
|
345
|
-
return this.status >= 200 && this.status < 300;
|
|
346
|
-
}
|
|
347
|
-
get status() {
|
|
348
|
-
return this.#e;
|
|
349
|
-
}
|
|
350
|
-
get statusText() {
|
|
351
|
-
return this.#t;
|
|
352
|
-
}
|
|
353
|
-
async blob() {
|
|
354
|
-
if (this.#s == null)
|
|
355
|
-
return null;
|
|
356
|
-
if (this.#s instanceof Blob)
|
|
357
|
-
return this.#s;
|
|
358
|
-
throw new TypeError("Body is not a Blob.");
|
|
359
|
-
}
|
|
360
|
-
async json() {
|
|
361
|
-
const t = typeof this.#s == "string" ? this.#s : JSON.stringify(this.#s);
|
|
362
|
-
return Promise.resolve(JSON.parse(t));
|
|
363
|
-
}
|
|
364
|
-
async text() {
|
|
365
|
-
return this.#s == null ? "" : String(this.#s);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
class v extends EventTarget {
|
|
369
|
-
/**
|
|
370
|
-
* Create an SSE client.
|
|
371
|
-
*
|
|
372
|
-
* @return A new SSE client.
|
|
373
|
-
*/
|
|
374
|
-
static create() {
|
|
375
|
-
return new v(EventSource);
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Create a nulled SSE client.
|
|
379
|
-
*
|
|
380
|
-
* @return A new SSE client.
|
|
381
|
-
*/
|
|
382
|
-
static createNull() {
|
|
383
|
-
return new v(o);
|
|
384
|
-
}
|
|
385
|
-
#e;
|
|
386
|
-
#t;
|
|
387
|
-
constructor(t) {
|
|
388
|
-
super(), this.#e = t;
|
|
389
|
-
}
|
|
390
|
-
get isConnected() {
|
|
391
|
-
return this.#t?.readyState === this.#e.OPEN;
|
|
392
|
-
}
|
|
393
|
-
get url() {
|
|
394
|
-
return this.#t?.url;
|
|
395
|
-
}
|
|
396
|
-
async connect(t, e = "message", ...s) {
|
|
397
|
-
await new Promise((r, h) => {
|
|
398
|
-
if (this.isConnected) {
|
|
399
|
-
h(new Error("Already connected."));
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
try {
|
|
403
|
-
this.#t = new this.#e(t), this.#t.addEventListener("open", (n) => {
|
|
404
|
-
this.#s(n), r();
|
|
405
|
-
}), this.#t.addEventListener(
|
|
406
|
-
e,
|
|
407
|
-
(n) => this.#r(n)
|
|
408
|
-
);
|
|
409
|
-
for (const n of s)
|
|
410
|
-
this.#t.addEventListener(
|
|
411
|
-
n,
|
|
412
|
-
(d) => this.#r(d)
|
|
413
|
-
);
|
|
414
|
-
this.#t.addEventListener(
|
|
415
|
-
"error",
|
|
416
|
-
(n) => this.#n(n)
|
|
417
|
-
);
|
|
418
|
-
} catch (n) {
|
|
419
|
-
h(n);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
send(t, e) {
|
|
424
|
-
throw new Error("Method not implemented.");
|
|
425
|
-
}
|
|
426
|
-
async close() {
|
|
427
|
-
await new Promise((t, e) => {
|
|
428
|
-
if (!this.isConnected) {
|
|
429
|
-
t();
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
try {
|
|
433
|
-
this.#t.close(), t();
|
|
434
|
-
} catch (s) {
|
|
435
|
-
e(s);
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Simulate a message event from the server.
|
|
441
|
-
*
|
|
442
|
-
* @param message The message to receive.
|
|
443
|
-
* @param eventName The optional event type.
|
|
444
|
-
* @param lastEventId The optional last event ID.
|
|
445
|
-
*/
|
|
446
|
-
simulateMessage(t, e = "message", s) {
|
|
447
|
-
typeof t != "string" && (t = JSON.stringify(t)), this.#r(
|
|
448
|
-
new MessageEvent(e, { data: t, lastEventId: s })
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Simulate an error event.
|
|
453
|
-
*/
|
|
454
|
-
simulateError() {
|
|
455
|
-
this.#n(new Event("error"));
|
|
456
|
-
}
|
|
457
|
-
#s(t) {
|
|
458
|
-
this.dispatchEvent(new Event(t.type, t));
|
|
459
|
-
}
|
|
460
|
-
#r(t) {
|
|
461
|
-
this.dispatchEvent(
|
|
462
|
-
new MessageEvent(t.type, t)
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
#n(t) {
|
|
466
|
-
this.dispatchEvent(new Event(t.type, t));
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
class o extends EventTarget {
|
|
470
|
-
// The constants have to be defined here because Node.js support is currently
|
|
471
|
-
// experimental only.
|
|
472
|
-
static CONNECTING = 0;
|
|
473
|
-
static OPEN = 1;
|
|
474
|
-
static CLOSED = 2;
|
|
475
|
-
url;
|
|
476
|
-
readyState = o.CONNECTING;
|
|
477
|
-
constructor(t) {
|
|
478
|
-
super(), this.url = t.toString(), setTimeout(() => {
|
|
479
|
-
this.readyState = o.OPEN, this.dispatchEvent(new Event("open"));
|
|
480
|
-
}, 0);
|
|
481
|
-
}
|
|
482
|
-
close() {
|
|
483
|
-
this.readyState = o.CLOSED;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
const m = "heartbeat", w = "message-sent";
|
|
487
|
-
class g extends EventTarget {
|
|
488
|
-
/**
|
|
489
|
-
* Create a WebSocket client.
|
|
490
|
-
*
|
|
491
|
-
* @param options The options for the WebSocket client.
|
|
492
|
-
* @return A new WebSocket client.
|
|
493
|
-
*/
|
|
494
|
-
static create({
|
|
495
|
-
heartbeat: t = 3e4,
|
|
496
|
-
retry: e = 1e3
|
|
497
|
-
} = {}) {
|
|
498
|
-
return new g(t, e, WebSocket);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Create a nulled WebSocket client.
|
|
502
|
-
*
|
|
503
|
-
* @param options The options for the WebSocket client.
|
|
504
|
-
* @return A new nulled WebSocket client.
|
|
505
|
-
*/
|
|
506
|
-
static createNull({ heartbeat: t = 0, retry: e = 0 } = {}) {
|
|
507
|
-
return new g(
|
|
508
|
-
t,
|
|
509
|
-
e,
|
|
510
|
-
b
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
#e;
|
|
514
|
-
#t;
|
|
515
|
-
#s;
|
|
516
|
-
#r;
|
|
517
|
-
#n;
|
|
518
|
-
#i;
|
|
519
|
-
constructor(t, e, s) {
|
|
520
|
-
super(), this.#e = t, this.#t = e, this.#s = s;
|
|
521
|
-
}
|
|
522
|
-
get isConnected() {
|
|
523
|
-
return this.#r?.readyState === WebSocket.OPEN;
|
|
524
|
-
}
|
|
525
|
-
get url() {
|
|
526
|
-
return this.#r?.url;
|
|
527
|
-
}
|
|
528
|
-
async connect(t) {
|
|
529
|
-
await new Promise((e, s) => {
|
|
530
|
-
if (this.#c(), this.isConnected) {
|
|
531
|
-
s(new Error("Already connected."));
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
try {
|
|
535
|
-
this.#r = new this.#s(t), this.#r.addEventListener("open", (r) => {
|
|
536
|
-
this.#u(r), e();
|
|
537
|
-
}), this.#r.addEventListener(
|
|
538
|
-
"message",
|
|
539
|
-
(r) => this.#a(r)
|
|
540
|
-
), this.#r.addEventListener("close", (r) => this.#h(r)), this.#r.addEventListener("error", (r) => this.#o(r));
|
|
541
|
-
} catch (r) {
|
|
542
|
-
s(r);
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
async send(t) {
|
|
547
|
-
if (!this.isConnected)
|
|
548
|
-
throw new Error("Not connected.");
|
|
549
|
-
this.#r.send(t), this.dispatchEvent(
|
|
550
|
-
new CustomEvent(w, { detail: t })
|
|
551
|
-
), await Promise.resolve();
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Return a tracker for messages sent.
|
|
555
|
-
*
|
|
556
|
-
* @return A new output tracker.
|
|
557
|
-
*/
|
|
558
|
-
trackMessageSent() {
|
|
559
|
-
return u.create(this, w);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Close the connection.
|
|
563
|
-
*
|
|
564
|
-
* If a code is provided, also a reason should be provided.
|
|
565
|
-
*
|
|
566
|
-
* @param code An optional code.
|
|
567
|
-
* @param reason An optional reason.
|
|
568
|
-
*/
|
|
569
|
-
async close(t, e) {
|
|
570
|
-
await new Promise((s) => {
|
|
571
|
-
if (this.#c(), !this.isConnected) {
|
|
572
|
-
s();
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
this.#r.addEventListener("close", () => s()), this.#r.close(t, e);
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Simulate a message event from the server.
|
|
580
|
-
*
|
|
581
|
-
* @param message The message to receive.
|
|
582
|
-
*/
|
|
583
|
-
simulateMessage(t) {
|
|
584
|
-
typeof t != "string" && !(t instanceof Blob) && !(t instanceof ArrayBuffer) && (t = JSON.stringify(t)), this.#a(new MessageEvent("message", { data: t }));
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Simulate a heartbeat.
|
|
588
|
-
*/
|
|
589
|
-
simulateHeartbeat() {
|
|
590
|
-
this.#l();
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Simulate a close event.
|
|
594
|
-
*
|
|
595
|
-
* @param code An optional code.
|
|
596
|
-
* @param reason An optional reason.
|
|
597
|
-
*/
|
|
598
|
-
simulateClose(t, e) {
|
|
599
|
-
this.#h(new CloseEvent("close", { code: t, reason: e }));
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Simulate an error event.
|
|
603
|
-
*/
|
|
604
|
-
simulateError() {
|
|
605
|
-
this.#r?.close(), this.#o(new Event("error"));
|
|
606
|
-
}
|
|
607
|
-
#u(t) {
|
|
608
|
-
this.dispatchEvent(new Event(t.type, t)), this.#E();
|
|
609
|
-
}
|
|
610
|
-
#a(t) {
|
|
611
|
-
this.dispatchEvent(
|
|
612
|
-
new MessageEvent(t.type, t)
|
|
613
|
-
);
|
|
614
|
-
}
|
|
615
|
-
#h(t) {
|
|
616
|
-
this.#v(), this.dispatchEvent(new CloseEvent(t.type, t));
|
|
617
|
-
}
|
|
618
|
-
#o(t) {
|
|
619
|
-
this.dispatchEvent(new Event(t.type, t)), this.#d();
|
|
620
|
-
}
|
|
621
|
-
#d() {
|
|
622
|
-
this.#t <= 0 || (this.#i = setInterval(
|
|
623
|
-
() => this.connect(this.#r.url),
|
|
624
|
-
this.#t
|
|
625
|
-
));
|
|
626
|
-
}
|
|
627
|
-
#c() {
|
|
628
|
-
clearInterval(this.#i), this.#i = void 0;
|
|
629
|
-
}
|
|
630
|
-
#E() {
|
|
631
|
-
this.#e <= 0 || (this.#n = setInterval(
|
|
632
|
-
() => this.#l(),
|
|
633
|
-
this.#e
|
|
634
|
-
));
|
|
635
|
-
}
|
|
636
|
-
#v() {
|
|
637
|
-
clearInterval(this.#n), this.#n = void 0;
|
|
638
|
-
}
|
|
639
|
-
#l() {
|
|
640
|
-
this.#n != null && this.send(m);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
class b extends EventTarget {
|
|
644
|
-
url;
|
|
645
|
-
readyState = WebSocket.CONNECTING;
|
|
646
|
-
constructor(t) {
|
|
647
|
-
super(), this.url = t.toString(), setTimeout(() => {
|
|
648
|
-
this.readyState = WebSocket.OPEN, this.dispatchEvent(new Event("open"));
|
|
649
|
-
}, 0);
|
|
650
|
-
}
|
|
651
|
-
send() {
|
|
652
|
-
}
|
|
653
|
-
close() {
|
|
654
|
-
this.readyState = WebSocket.CLOSED, this.dispatchEvent(new Event("close"));
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
export {
|
|
658
|
-
c as Clock,
|
|
659
|
-
l as ConfigurableResponses,
|
|
660
|
-
E as ConsoleLog,
|
|
661
|
-
f as EventTracker,
|
|
662
|
-
N as Failure,
|
|
663
|
-
m as HEARTBEAT_TYPE,
|
|
664
|
-
u as OutputTracker,
|
|
665
|
-
v as SseClient,
|
|
666
|
-
S as Success,
|
|
667
|
-
g as WebSocketClient,
|
|
668
|
-
L as createFetchStub
|
|
669
|
-
};
|
|
670
|
-
//# sourceMappingURL=shared.js.map
|