@mswjs/interceptors 0.42.0 → 0.42.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.
@@ -0,0 +1,720 @@
1
+ import { Emitter } from "rettime";
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ //#region src/disposable.ts
26
+ var Disposable = class {
27
+ constructor() {
28
+ this.subscriptions = [];
29
+ }
30
+ dispose() {
31
+ let subscription;
32
+ while (subscription = this.subscriptions.pop()) subscription();
33
+ }
34
+ };
35
+ //#endregion
36
+ //#region node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js
37
+ var require_ms = /* @__PURE__ */ __commonJSMin(((exports, module) => {
38
+ /**
39
+ * Helpers.
40
+ */
41
+ var s = 1e3;
42
+ var m = s * 60;
43
+ var h = m * 60;
44
+ var d = h * 24;
45
+ var w = d * 7;
46
+ var y = d * 365.25;
47
+ /**
48
+ * Parse or format the given `val`.
49
+ *
50
+ * Options:
51
+ *
52
+ * - `long` verbose formatting [false]
53
+ *
54
+ * @param {String|Number} val
55
+ * @param {Object} [options]
56
+ * @throws {Error} throw an error if val is not a non-empty string or a number
57
+ * @return {String|Number}
58
+ * @api public
59
+ */
60
+ module.exports = function(val, options) {
61
+ options = options || {};
62
+ var type = typeof val;
63
+ if (type === "string" && val.length > 0) return parse(val);
64
+ else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
65
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
66
+ };
67
+ /**
68
+ * Parse the given `str` and return milliseconds.
69
+ *
70
+ * @param {String} str
71
+ * @return {Number}
72
+ * @api private
73
+ */
74
+ function parse(str) {
75
+ str = String(str);
76
+ if (str.length > 100) return;
77
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
78
+ if (!match) return;
79
+ var n = parseFloat(match[1]);
80
+ switch ((match[2] || "ms").toLowerCase()) {
81
+ case "years":
82
+ case "year":
83
+ case "yrs":
84
+ case "yr":
85
+ case "y": return n * y;
86
+ case "weeks":
87
+ case "week":
88
+ case "w": return n * w;
89
+ case "days":
90
+ case "day":
91
+ case "d": return n * d;
92
+ case "hours":
93
+ case "hour":
94
+ case "hrs":
95
+ case "hr":
96
+ case "h": return n * h;
97
+ case "minutes":
98
+ case "minute":
99
+ case "mins":
100
+ case "min":
101
+ case "m": return n * m;
102
+ case "seconds":
103
+ case "second":
104
+ case "secs":
105
+ case "sec":
106
+ case "s": return n * s;
107
+ case "milliseconds":
108
+ case "millisecond":
109
+ case "msecs":
110
+ case "msec":
111
+ case "ms": return n;
112
+ default: return;
113
+ }
114
+ }
115
+ /**
116
+ * Short format for `ms`.
117
+ *
118
+ * @param {Number} ms
119
+ * @return {String}
120
+ * @api private
121
+ */
122
+ function fmtShort(ms) {
123
+ var msAbs = Math.abs(ms);
124
+ if (msAbs >= d) return Math.round(ms / d) + "d";
125
+ if (msAbs >= h) return Math.round(ms / h) + "h";
126
+ if (msAbs >= m) return Math.round(ms / m) + "m";
127
+ if (msAbs >= s) return Math.round(ms / s) + "s";
128
+ return ms + "ms";
129
+ }
130
+ /**
131
+ * Long format for `ms`.
132
+ *
133
+ * @param {Number} ms
134
+ * @return {String}
135
+ * @api private
136
+ */
137
+ function fmtLong(ms) {
138
+ var msAbs = Math.abs(ms);
139
+ if (msAbs >= d) return plural(ms, msAbs, d, "day");
140
+ if (msAbs >= h) return plural(ms, msAbs, h, "hour");
141
+ if (msAbs >= m) return plural(ms, msAbs, m, "minute");
142
+ if (msAbs >= s) return plural(ms, msAbs, s, "second");
143
+ return ms + " ms";
144
+ }
145
+ /**
146
+ * Pluralization helper.
147
+ */
148
+ function plural(ms, msAbs, n, name) {
149
+ var isPlural = msAbs >= n * 1.5;
150
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
151
+ }
152
+ }));
153
+ //#endregion
154
+ //#region node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/common.js
155
+ var require_common = /* @__PURE__ */ __commonJSMin(((exports, module) => {
156
+ /**
157
+ * This is the common logic for both the Node.js and web browser
158
+ * implementations of `debug()`.
159
+ */
160
+ function setup(env) {
161
+ createDebug.debug = createDebug;
162
+ createDebug.default = createDebug;
163
+ createDebug.coerce = coerce;
164
+ createDebug.disable = disable;
165
+ createDebug.enable = enable;
166
+ createDebug.enabled = enabled;
167
+ createDebug.humanize = require_ms();
168
+ createDebug.destroy = destroy;
169
+ Object.keys(env).forEach((key) => {
170
+ createDebug[key] = env[key];
171
+ });
172
+ /**
173
+ * The currently active debug mode names, and names to skip.
174
+ */
175
+ createDebug.names = [];
176
+ createDebug.skips = [];
177
+ /**
178
+ * Map of special "%n" handling functions, for the debug "format" argument.
179
+ *
180
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
181
+ */
182
+ createDebug.formatters = {};
183
+ /**
184
+ * Selects a color for a debug namespace
185
+ * @param {String} namespace The namespace string for the debug instance to be colored
186
+ * @return {Number|String} An ANSI color code for the given namespace
187
+ * @api private
188
+ */
189
+ function selectColor(namespace) {
190
+ let hash = 0;
191
+ for (let i = 0; i < namespace.length; i++) {
192
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
193
+ hash |= 0;
194
+ }
195
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
196
+ }
197
+ createDebug.selectColor = selectColor;
198
+ /**
199
+ * Create a debugger with the given `namespace`.
200
+ *
201
+ * @param {String} namespace
202
+ * @return {Function}
203
+ * @api public
204
+ */
205
+ function createDebug(namespace) {
206
+ let prevTime;
207
+ let enableOverride = null;
208
+ let namespacesCache;
209
+ let enabledCache;
210
+ function debug(...args) {
211
+ if (!debug.enabled) return;
212
+ const self = debug;
213
+ const curr = Number(/* @__PURE__ */ new Date());
214
+ self.diff = curr - (prevTime || curr);
215
+ self.prev = prevTime;
216
+ self.curr = curr;
217
+ prevTime = curr;
218
+ args[0] = createDebug.coerce(args[0]);
219
+ if (typeof args[0] !== "string") args.unshift("%O");
220
+ let index = 0;
221
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
222
+ if (match === "%%") return "%";
223
+ index++;
224
+ const formatter = createDebug.formatters[format];
225
+ if (typeof formatter === "function") {
226
+ const val = args[index];
227
+ match = formatter.call(self, val);
228
+ args.splice(index, 1);
229
+ index--;
230
+ }
231
+ return match;
232
+ });
233
+ createDebug.formatArgs.call(self, args);
234
+ (self.log || createDebug.log).apply(self, args);
235
+ }
236
+ debug.namespace = namespace;
237
+ debug.useColors = createDebug.useColors();
238
+ debug.color = createDebug.selectColor(namespace);
239
+ debug.extend = extend;
240
+ debug.destroy = createDebug.destroy;
241
+ Object.defineProperty(debug, "enabled", {
242
+ enumerable: true,
243
+ configurable: false,
244
+ get: () => {
245
+ if (enableOverride !== null) return enableOverride;
246
+ if (namespacesCache !== createDebug.namespaces) {
247
+ namespacesCache = createDebug.namespaces;
248
+ enabledCache = createDebug.enabled(namespace);
249
+ }
250
+ return enabledCache;
251
+ },
252
+ set: (v) => {
253
+ enableOverride = v;
254
+ }
255
+ });
256
+ if (typeof createDebug.init === "function") createDebug.init(debug);
257
+ return debug;
258
+ }
259
+ function extend(namespace, delimiter) {
260
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
261
+ newDebug.log = this.log;
262
+ return newDebug;
263
+ }
264
+ /**
265
+ * Enables a debug mode by namespaces. This can include modes
266
+ * separated by a colon and wildcards.
267
+ *
268
+ * @param {String} namespaces
269
+ * @api public
270
+ */
271
+ function enable(namespaces) {
272
+ createDebug.save(namespaces);
273
+ createDebug.namespaces = namespaces;
274
+ createDebug.names = [];
275
+ createDebug.skips = [];
276
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
277
+ for (const ns of split) if (ns[0] === "-") createDebug.skips.push(ns.slice(1));
278
+ else createDebug.names.push(ns);
279
+ }
280
+ /**
281
+ * Checks if the given string matches a namespace template, honoring
282
+ * asterisks as wildcards.
283
+ *
284
+ * @param {String} search
285
+ * @param {String} template
286
+ * @return {Boolean}
287
+ */
288
+ function matchesTemplate(search, template) {
289
+ let searchIndex = 0;
290
+ let templateIndex = 0;
291
+ let starIndex = -1;
292
+ let matchIndex = 0;
293
+ while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
294
+ starIndex = templateIndex;
295
+ matchIndex = searchIndex;
296
+ templateIndex++;
297
+ } else {
298
+ searchIndex++;
299
+ templateIndex++;
300
+ }
301
+ else if (starIndex !== -1) {
302
+ templateIndex = starIndex + 1;
303
+ matchIndex++;
304
+ searchIndex = matchIndex;
305
+ } else return false;
306
+ while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++;
307
+ return templateIndex === template.length;
308
+ }
309
+ /**
310
+ * Disable debug output.
311
+ *
312
+ * @return {String} namespaces
313
+ * @api public
314
+ */
315
+ function disable() {
316
+ const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(",");
317
+ createDebug.enable("");
318
+ return namespaces;
319
+ }
320
+ /**
321
+ * Returns true if the given mode name is enabled, false otherwise.
322
+ *
323
+ * @param {String} name
324
+ * @return {Boolean}
325
+ * @api public
326
+ */
327
+ function enabled(name) {
328
+ for (const skip of createDebug.skips) if (matchesTemplate(name, skip)) return false;
329
+ for (const ns of createDebug.names) if (matchesTemplate(name, ns)) return true;
330
+ return false;
331
+ }
332
+ /**
333
+ * Coerce `val`.
334
+ *
335
+ * @param {Mixed} val
336
+ * @return {Mixed}
337
+ * @api private
338
+ */
339
+ function coerce(val) {
340
+ if (val instanceof Error) return val.stack || val.message;
341
+ return val;
342
+ }
343
+ /**
344
+ * XXX DO NOT USE. This is a temporary stub function.
345
+ * XXX It WILL be removed in the next major release.
346
+ */
347
+ function destroy() {
348
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
349
+ }
350
+ createDebug.enable(createDebug.load());
351
+ return createDebug;
352
+ }
353
+ module.exports = setup;
354
+ }));
355
+ //#endregion
356
+ //#region src/utils/logger.ts
357
+ var import_browser = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
358
+ /**
359
+ * This is the web browser implementation of `debug()`.
360
+ */
361
+ exports.formatArgs = formatArgs;
362
+ exports.save = save;
363
+ exports.load = load;
364
+ exports.useColors = useColors;
365
+ exports.storage = localstorage();
366
+ exports.destroy = (() => {
367
+ let warned = false;
368
+ return () => {
369
+ if (!warned) {
370
+ warned = true;
371
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
372
+ }
373
+ };
374
+ })();
375
+ /**
376
+ * Colors.
377
+ */
378
+ exports.colors = [
379
+ "#0000CC",
380
+ "#0000FF",
381
+ "#0033CC",
382
+ "#0033FF",
383
+ "#0066CC",
384
+ "#0066FF",
385
+ "#0099CC",
386
+ "#0099FF",
387
+ "#00CC00",
388
+ "#00CC33",
389
+ "#00CC66",
390
+ "#00CC99",
391
+ "#00CCCC",
392
+ "#00CCFF",
393
+ "#3300CC",
394
+ "#3300FF",
395
+ "#3333CC",
396
+ "#3333FF",
397
+ "#3366CC",
398
+ "#3366FF",
399
+ "#3399CC",
400
+ "#3399FF",
401
+ "#33CC00",
402
+ "#33CC33",
403
+ "#33CC66",
404
+ "#33CC99",
405
+ "#33CCCC",
406
+ "#33CCFF",
407
+ "#6600CC",
408
+ "#6600FF",
409
+ "#6633CC",
410
+ "#6633FF",
411
+ "#66CC00",
412
+ "#66CC33",
413
+ "#9900CC",
414
+ "#9900FF",
415
+ "#9933CC",
416
+ "#9933FF",
417
+ "#99CC00",
418
+ "#99CC33",
419
+ "#CC0000",
420
+ "#CC0033",
421
+ "#CC0066",
422
+ "#CC0099",
423
+ "#CC00CC",
424
+ "#CC00FF",
425
+ "#CC3300",
426
+ "#CC3333",
427
+ "#CC3366",
428
+ "#CC3399",
429
+ "#CC33CC",
430
+ "#CC33FF",
431
+ "#CC6600",
432
+ "#CC6633",
433
+ "#CC9900",
434
+ "#CC9933",
435
+ "#CCCC00",
436
+ "#CCCC33",
437
+ "#FF0000",
438
+ "#FF0033",
439
+ "#FF0066",
440
+ "#FF0099",
441
+ "#FF00CC",
442
+ "#FF00FF",
443
+ "#FF3300",
444
+ "#FF3333",
445
+ "#FF3366",
446
+ "#FF3399",
447
+ "#FF33CC",
448
+ "#FF33FF",
449
+ "#FF6600",
450
+ "#FF6633",
451
+ "#FF9900",
452
+ "#FF9933",
453
+ "#FFCC00",
454
+ "#FFCC33"
455
+ ];
456
+ /**
457
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
458
+ * and the Firebug extension (any Firefox version) are known
459
+ * to support "%c" CSS customizations.
460
+ *
461
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
462
+ */
463
+ function useColors() {
464
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true;
465
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false;
466
+ let m;
467
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
468
+ }
469
+ /**
470
+ * Colorize log arguments if enabled.
471
+ *
472
+ * @api public
473
+ */
474
+ function formatArgs(args) {
475
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
476
+ if (!this.useColors) return;
477
+ const c = "color: " + this.color;
478
+ args.splice(1, 0, c, "color: inherit");
479
+ let index = 0;
480
+ let lastC = 0;
481
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
482
+ if (match === "%%") return;
483
+ index++;
484
+ if (match === "%c") lastC = index;
485
+ });
486
+ args.splice(lastC, 0, c);
487
+ }
488
+ /**
489
+ * Invokes `console.debug()` when available.
490
+ * No-op when `console.debug` is not a "function".
491
+ * If `console.debug` is not available, falls back
492
+ * to `console.log`.
493
+ *
494
+ * @api public
495
+ */
496
+ exports.log = console.debug || console.log || (() => {});
497
+ /**
498
+ * Save `namespaces`.
499
+ *
500
+ * @param {String} namespaces
501
+ * @api private
502
+ */
503
+ function save(namespaces) {
504
+ try {
505
+ if (namespaces) exports.storage.setItem("debug", namespaces);
506
+ else exports.storage.removeItem("debug");
507
+ } catch (error) {}
508
+ }
509
+ /**
510
+ * Load `namespaces`.
511
+ *
512
+ * @return {String} returns the previously persisted debug modes
513
+ * @api private
514
+ */
515
+ function load() {
516
+ let r;
517
+ try {
518
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
519
+ } catch (error) {}
520
+ if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
521
+ return r;
522
+ }
523
+ /**
524
+ * Localstorage attempts to return the localstorage.
525
+ *
526
+ * This is necessary because safari throws
527
+ * when a user disables cookies/localstorage
528
+ * and you attempt to access it.
529
+ *
530
+ * @return {LocalStorage}
531
+ * @api private
532
+ */
533
+ function localstorage() {
534
+ try {
535
+ return localStorage;
536
+ } catch (error) {}
537
+ }
538
+ module.exports = require_common()(exports);
539
+ const { formatters } = module.exports;
540
+ /**
541
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
542
+ */
543
+ formatters.j = function(v) {
544
+ try {
545
+ return JSON.stringify(v);
546
+ } catch (error) {
547
+ return "[UnexpectedJSONParseError]: " + error.message;
548
+ }
549
+ };
550
+ })))(), 1);
551
+ const LOG_TIMESTAMP_REGEXP = /\d{2}:\d{2}:\d{2}\.\d{3}/;
552
+ function normalizeNamespace(namespace) {
553
+ return namespace.split(":").map((segment) => {
554
+ return segment.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
555
+ }).filter(Boolean).join(":");
556
+ }
557
+ function getTimestamp() {
558
+ return (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
559
+ }
560
+ async function readBody(message) {
561
+ if (message.body == null) return null;
562
+ try {
563
+ return await message.clone().text();
564
+ } catch {
565
+ return null;
566
+ }
567
+ }
568
+ function formatHeaders(headers) {
569
+ return Array.from(headers.entries()).map(([name, value]) => {
570
+ return `${name}: ${value}`;
571
+ });
572
+ }
573
+ async function formatHttpMessage(startLine, message) {
574
+ const lines = [startLine, ...formatHeaders(message.headers)];
575
+ const body = await readBody(message);
576
+ lines.push("", body ?? "");
577
+ return lines.join("\n");
578
+ }
579
+ async function formatRequest(request) {
580
+ return formatHttpMessage(`${request.method} ${request.url}`, request);
581
+ }
582
+ async function formatResponse(response) {
583
+ const statusText = response.statusText ? ` ${response.statusText}` : "";
584
+ return formatHttpMessage(`HTTP ${response.status}${statusText}`, response);
585
+ }
586
+ function formatLogArguments(arguments_) {
587
+ const message = arguments_[0];
588
+ if (typeof message === "string") {
589
+ const messageWithoutDebugTimestamp = message.replace(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z /, "");
590
+ const timestampMatch = messageWithoutDebugTimestamp.match(LOG_TIMESTAMP_REGEXP);
591
+ if (!timestampMatch || timestampMatch.index === void 0) {
592
+ arguments_[0] = messageWithoutDebugTimestamp;
593
+ return;
594
+ }
595
+ const messagePrefix = messageWithoutDebugTimestamp.slice(0, timestampMatch.index).trim();
596
+ const messageBody = messageWithoutDebugTimestamp.slice(timestampMatch.index + timestampMatch[0].length).trimStart();
597
+ arguments_[0] = `${timestampMatch[0]} ${messagePrefix} ${messageBody}`;
598
+ }
599
+ }
600
+ function useConciseTimestamp(logger) {
601
+ logger.log = (...arguments_) => {
602
+ formatLogArguments(arguments_);
603
+ import_browser.log(...arguments_);
604
+ };
605
+ }
606
+ function isVerboseLoggingEnabled() {
607
+ if (typeof process !== "undefined" && process.env.DEBUG_LEVEL === "verbose") return true;
608
+ /**
609
+ * @note Consult the localStorage only in browser-like environments.
610
+ * In Node.js 26+, reading "globalThis.localStorage" without the
611
+ * "--localstorage-file" flag set emits an experimental warning
612
+ * (a try/catch cannot suppress it). Node.js consumers control the
613
+ * log level via the "DEBUG_LEVEL" environment variable above.
614
+ */
615
+ if (typeof document === "undefined") return false;
616
+ try {
617
+ return globalThis.localStorage?.getItem("debugLevel") === "verbose";
618
+ } catch {
619
+ return false;
620
+ }
621
+ }
622
+ function createLogger(namespace) {
623
+ const logger = (0, import_browser.default)(`interceptors:${normalizeNamespace(namespace)}`);
624
+ Reflect.set(logger, "useColors", true);
625
+ useConciseTimestamp(logger);
626
+ return {
627
+ info(message, ...positionals) {
628
+ logger(`${getTimestamp()} ${message}`, ...positionals);
629
+ },
630
+ verbose(message, ...positionals) {
631
+ if (!isVerboseLoggingEnabled()) return;
632
+ logger(`${getTimestamp()} ${message}`, ...positionals);
633
+ },
634
+ isEnabled(level) {
635
+ return logger.enabled && (level === "default" || isVerboseLoggingEnabled());
636
+ }
637
+ };
638
+ }
639
+ //#endregion
640
+ //#region src/interceptor.ts
641
+ const interceptorsRegistry = globalThis.__MSW_INTERCEPTORS_REGISTRY ??= /* @__PURE__ */ new Map();
642
+ var Interceptor = class extends Disposable {
643
+ #owners;
644
+ static singleton(InterceptorClass) {
645
+ const symbol = InterceptorClass.symbol;
646
+ const existing = interceptorsRegistry.get(symbol);
647
+ if (existing instanceof InterceptorClass) return existing;
648
+ const newInstance = new InterceptorClass();
649
+ interceptorsRegistry.set(symbol, newInstance);
650
+ return newInstance;
651
+ }
652
+ constructor() {
653
+ super();
654
+ this.on = (type, listener, options) => {
655
+ return this.emitter.on(type, listener, options);
656
+ };
657
+ this.once = (type, listener, options) => {
658
+ return this.emitter.once(type, listener, options);
659
+ };
660
+ this.listeners = (type) => {
661
+ return this.emitter.listeners(type);
662
+ };
663
+ this.listenerCount = (type) => {
664
+ return this.emitter.listenerCount(type);
665
+ };
666
+ this.removeListener = (type, listener) => {
667
+ return this.emitter.removeListener(type, listener);
668
+ };
669
+ this.removeAllListeners = (type) => {
670
+ this.logger.info("removeAllListeners %o", { eventType: type ?? "*" });
671
+ return this.emitter.removeAllListeners(type);
672
+ };
673
+ this.#owners = /* @__PURE__ */ new Set();
674
+ this.readyState = "INACTIVE";
675
+ this.emitter = new Emitter();
676
+ this.logger = createLogger(this.#getLoggerNamespace());
677
+ }
678
+ apply(owner = this) {
679
+ if (this.#owners.has(owner)) return;
680
+ if (this.readyState !== "ACTIVE" && !this.predicate()) return;
681
+ this.#owners.add(owner);
682
+ if (this.readyState === "ACTIVE") return;
683
+ try {
684
+ this.setup();
685
+ this.readyState = "ACTIVE";
686
+ this.logger.info("apply");
687
+ } catch (error) {
688
+ this.dispose(owner);
689
+ throw error;
690
+ }
691
+ }
692
+ dispose(owner = this) {
693
+ if (!this.#owners.delete(owner)) return;
694
+ if (this.#owners.size > 0) return;
695
+ super.dispose();
696
+ this.emitter.removeAllListeners();
697
+ this.readyState = "DISPOSED";
698
+ this.logger.info("disable");
699
+ }
700
+ #getLoggerNamespace() {
701
+ const symbolDescription = this.constructor.symbol?.description;
702
+ if (symbolDescription) return symbolDescription.replace(/-interceptor$/, "");
703
+ return this.constructor.name.replace(/Interceptor$/, "");
704
+ }
705
+ };
706
+ //#endregion
707
+ //#region src/create-request-id.ts
708
+ /**
709
+ * Generate a random ID string to represent a request.
710
+ * @example
711
+ * createRequestId()
712
+ * // "f774b6c9c600f"
713
+ */
714
+ function createRequestId() {
715
+ return Math.random().toString(16).slice(2);
716
+ }
717
+ //#endregion
718
+ export { formatResponse as a, formatRequest as i, Interceptor as n, createLogger as r, createRequestId as t };
719
+
720
+ //# sourceMappingURL=create-request-id-Bk5YX1AM.js.map