msw 2.13.1 → 2.13.3
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/lib/browser/index.js +52 -16
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +52 -16
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/experimental/sources/network-source.d.mts +1 -1
- package/lib/core/experimental/sources/network-source.d.ts +1 -1
- package/lib/core/experimental/sources/network-source.js.map +1 -1
- package/lib/core/experimental/sources/network-source.mjs.map +1 -1
- package/lib/core/utils/internal/hasRefCounted.js +8 -1
- package/lib/core/utils/internal/hasRefCounted.js.map +1 -1
- package/lib/core/utils/internal/hasRefCounted.mjs +8 -1
- package/lib/core/utils/internal/hasRefCounted.mjs.map +1 -1
- package/lib/iife/index.js +59 -17
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/experimental/sources/network-source.ts +1 -1
- package/src/core/utils/internal/hasRefCounted.test.ts +21 -0
- package/src/core/utils/internal/hasRefCounted.ts +7 -0
package/lib/browser/index.mjs
CHANGED
|
@@ -1584,7 +1584,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
1584
1584
|
return registrationResult;
|
|
1585
1585
|
};
|
|
1586
1586
|
|
|
1587
|
-
// node_modules/.pnpm/rettime@0.
|
|
1587
|
+
// node_modules/.pnpm/rettime@0.11.7/node_modules/rettime/build/lens-list.mjs
|
|
1588
1588
|
var LensList = class {
|
|
1589
1589
|
#list;
|
|
1590
1590
|
#lens;
|
|
@@ -1630,7 +1630,11 @@ var LensList = class {
|
|
|
1630
1630
|
delete(key, value) {
|
|
1631
1631
|
if (this.size === 0) return;
|
|
1632
1632
|
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
1633
|
-
|
|
1633
|
+
const values = this.#lens.get(key);
|
|
1634
|
+
if (values) {
|
|
1635
|
+
const index = values.indexOf(value);
|
|
1636
|
+
if (index !== -1) values.splice(index, 1);
|
|
1637
|
+
}
|
|
1634
1638
|
}
|
|
1635
1639
|
/**
|
|
1636
1640
|
* Delete all values belogning to the given key.
|
|
@@ -1653,7 +1657,7 @@ var LensList = class {
|
|
|
1653
1657
|
}
|
|
1654
1658
|
};
|
|
1655
1659
|
|
|
1656
|
-
// node_modules/.pnpm/rettime@0.
|
|
1660
|
+
// node_modules/.pnpm/rettime@0.11.7/node_modules/rettime/build/index.mjs
|
|
1657
1661
|
var kDefaultPrevented2 = Symbol("kDefaultPrevented");
|
|
1658
1662
|
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
1659
1663
|
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
@@ -1683,11 +1687,39 @@ var TypedEvent = class extends MessageEvent {
|
|
|
1683
1687
|
this[kImmediatePropagationStopped] = true;
|
|
1684
1688
|
}
|
|
1685
1689
|
};
|
|
1686
|
-
var kListenerOptions = Symbol("kListenerOptions");
|
|
1687
1690
|
var Emitter2 = class {
|
|
1688
1691
|
#listeners;
|
|
1692
|
+
#listenerOptions;
|
|
1693
|
+
#typelessListeners;
|
|
1694
|
+
#hookListeners;
|
|
1695
|
+
#hookListenerOptions;
|
|
1696
|
+
hooks;
|
|
1689
1697
|
constructor() {
|
|
1690
1698
|
this.#listeners = new LensList();
|
|
1699
|
+
this.#listenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1700
|
+
this.#typelessListeners = /* @__PURE__ */ new WeakSet();
|
|
1701
|
+
this.#hookListeners = new LensList();
|
|
1702
|
+
this.#hookListenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1703
|
+
this.hooks = {
|
|
1704
|
+
on: (hook, callback, options) => {
|
|
1705
|
+
if (options?.once) {
|
|
1706
|
+
const original = callback;
|
|
1707
|
+
const wrapper = ((...args) => {
|
|
1708
|
+
this.#hookListeners.delete(hook, wrapper);
|
|
1709
|
+
return original(...args);
|
|
1710
|
+
});
|
|
1711
|
+
callback = wrapper;
|
|
1712
|
+
}
|
|
1713
|
+
this.#hookListeners.append(hook, callback);
|
|
1714
|
+
if (options) this.#hookListenerOptions.set(callback, options);
|
|
1715
|
+
if (options?.signal) options.signal.addEventListener("abort", () => {
|
|
1716
|
+
this.#hookListeners.delete(hook, callback);
|
|
1717
|
+
}, { once: true });
|
|
1718
|
+
},
|
|
1719
|
+
removeListener: (hook, callback) => {
|
|
1720
|
+
this.#hookListeners.delete(hook, callback);
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1691
1723
|
}
|
|
1692
1724
|
/**
|
|
1693
1725
|
* Adds a listener for the given event type.
|
|
@@ -1789,7 +1821,9 @@ var Emitter2 = class {
|
|
|
1789
1821
|
* Removes a listener for the given event type.
|
|
1790
1822
|
*/
|
|
1791
1823
|
removeListener(type, listener) {
|
|
1824
|
+
const options = this.#listenerOptions.get(listener);
|
|
1792
1825
|
this.#listeners.delete(type, listener);
|
|
1826
|
+
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
1793
1827
|
}
|
|
1794
1828
|
/**
|
|
1795
1829
|
* Removes all listeners for the given event type.
|
|
@@ -1798,6 +1832,7 @@ var Emitter2 = class {
|
|
|
1798
1832
|
removeAllListeners(type) {
|
|
1799
1833
|
if (type == null) {
|
|
1800
1834
|
this.#listeners.clear();
|
|
1835
|
+
for (const [hookType, hookListener] of this.#hookListeners) if (!this.#hookListenerOptions.get(hookListener)?.persist) this.#hookListeners.delete(hookType, hookListener);
|
|
1801
1836
|
return;
|
|
1802
1837
|
}
|
|
1803
1838
|
this.#listeners.deleteAll(type);
|
|
@@ -1819,14 +1854,12 @@ var Emitter2 = class {
|
|
|
1819
1854
|
return this.listeners(type).length;
|
|
1820
1855
|
}
|
|
1821
1856
|
#addListener(type, listener, options, insertMode = "append") {
|
|
1857
|
+
for (const hook of this.#hookListeners.get("newListener")) hook(type, listener, options);
|
|
1858
|
+
if (type === "*") this.#typelessListeners.add(listener);
|
|
1822
1859
|
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
1823
1860
|
else this.#listeners.append(type, listener);
|
|
1824
1861
|
if (options) {
|
|
1825
|
-
|
|
1826
|
-
value: options,
|
|
1827
|
-
enumerable: false,
|
|
1828
|
-
writable: false
|
|
1829
|
-
});
|
|
1862
|
+
this.#listenerOptions.set(listener, options);
|
|
1830
1863
|
if (options.signal) options.signal.addEventListener("abort", () => {
|
|
1831
1864
|
this.removeListener(type, listener);
|
|
1832
1865
|
}, { once: true });
|
|
@@ -1834,10 +1867,10 @@ var Emitter2 = class {
|
|
|
1834
1867
|
}
|
|
1835
1868
|
#proxyEvent(event) {
|
|
1836
1869
|
const { stopPropagation } = event;
|
|
1837
|
-
event.stopPropagation =
|
|
1870
|
+
event.stopPropagation = () => {
|
|
1838
1871
|
event[kPropagationStopped] = this;
|
|
1839
|
-
|
|
1840
|
-
}
|
|
1872
|
+
stopPropagation.call(event);
|
|
1873
|
+
};
|
|
1841
1874
|
return {
|
|
1842
1875
|
event,
|
|
1843
1876
|
revoke() {
|
|
@@ -1846,10 +1879,13 @@ var Emitter2 = class {
|
|
|
1846
1879
|
};
|
|
1847
1880
|
}
|
|
1848
1881
|
#callListener(event, listener) {
|
|
1882
|
+
for (const hook of this.#hookListeners.get("beforeEmit")) if (hook(event) === false) return;
|
|
1849
1883
|
const returnValue = listener.call(this, event);
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
this.#
|
|
1884
|
+
const options = this.#listenerOptions.get(listener);
|
|
1885
|
+
if (options?.once) {
|
|
1886
|
+
const type = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
1887
|
+
this.#listeners.delete(type, listener);
|
|
1888
|
+
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
1853
1889
|
}
|
|
1854
1890
|
return returnValue;
|
|
1855
1891
|
}
|
|
@@ -1861,7 +1897,7 @@ var Emitter2 = class {
|
|
|
1861
1897
|
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
|
|
1862
1898
|
}
|
|
1863
1899
|
#isTypelessListener(listener) {
|
|
1864
|
-
return this.#
|
|
1900
|
+
return this.#typelessListeners.has(listener);
|
|
1865
1901
|
}
|
|
1866
1902
|
};
|
|
1867
1903
|
|