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.js
CHANGED
|
@@ -1605,7 +1605,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
1605
1605
|
return registrationResult;
|
|
1606
1606
|
};
|
|
1607
1607
|
|
|
1608
|
-
// node_modules/.pnpm/rettime@0.
|
|
1608
|
+
// node_modules/.pnpm/rettime@0.11.7/node_modules/rettime/build/lens-list.mjs
|
|
1609
1609
|
var LensList = class {
|
|
1610
1610
|
#list;
|
|
1611
1611
|
#lens;
|
|
@@ -1651,7 +1651,11 @@ var LensList = class {
|
|
|
1651
1651
|
delete(key, value) {
|
|
1652
1652
|
if (this.size === 0) return;
|
|
1653
1653
|
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
1654
|
-
|
|
1654
|
+
const values = this.#lens.get(key);
|
|
1655
|
+
if (values) {
|
|
1656
|
+
const index = values.indexOf(value);
|
|
1657
|
+
if (index !== -1) values.splice(index, 1);
|
|
1658
|
+
}
|
|
1655
1659
|
}
|
|
1656
1660
|
/**
|
|
1657
1661
|
* Delete all values belogning to the given key.
|
|
@@ -1674,7 +1678,7 @@ var LensList = class {
|
|
|
1674
1678
|
}
|
|
1675
1679
|
};
|
|
1676
1680
|
|
|
1677
|
-
// node_modules/.pnpm/rettime@0.
|
|
1681
|
+
// node_modules/.pnpm/rettime@0.11.7/node_modules/rettime/build/index.mjs
|
|
1678
1682
|
var kDefaultPrevented2 = Symbol("kDefaultPrevented");
|
|
1679
1683
|
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
1680
1684
|
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
@@ -1704,11 +1708,39 @@ var TypedEvent = class extends MessageEvent {
|
|
|
1704
1708
|
this[kImmediatePropagationStopped] = true;
|
|
1705
1709
|
}
|
|
1706
1710
|
};
|
|
1707
|
-
var kListenerOptions = Symbol("kListenerOptions");
|
|
1708
1711
|
var Emitter2 = class {
|
|
1709
1712
|
#listeners;
|
|
1713
|
+
#listenerOptions;
|
|
1714
|
+
#typelessListeners;
|
|
1715
|
+
#hookListeners;
|
|
1716
|
+
#hookListenerOptions;
|
|
1717
|
+
hooks;
|
|
1710
1718
|
constructor() {
|
|
1711
1719
|
this.#listeners = new LensList();
|
|
1720
|
+
this.#listenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1721
|
+
this.#typelessListeners = /* @__PURE__ */ new WeakSet();
|
|
1722
|
+
this.#hookListeners = new LensList();
|
|
1723
|
+
this.#hookListenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1724
|
+
this.hooks = {
|
|
1725
|
+
on: (hook, callback, options) => {
|
|
1726
|
+
if (options?.once) {
|
|
1727
|
+
const original = callback;
|
|
1728
|
+
const wrapper = ((...args) => {
|
|
1729
|
+
this.#hookListeners.delete(hook, wrapper);
|
|
1730
|
+
return original(...args);
|
|
1731
|
+
});
|
|
1732
|
+
callback = wrapper;
|
|
1733
|
+
}
|
|
1734
|
+
this.#hookListeners.append(hook, callback);
|
|
1735
|
+
if (options) this.#hookListenerOptions.set(callback, options);
|
|
1736
|
+
if (options?.signal) options.signal.addEventListener("abort", () => {
|
|
1737
|
+
this.#hookListeners.delete(hook, callback);
|
|
1738
|
+
}, { once: true });
|
|
1739
|
+
},
|
|
1740
|
+
removeListener: (hook, callback) => {
|
|
1741
|
+
this.#hookListeners.delete(hook, callback);
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1712
1744
|
}
|
|
1713
1745
|
/**
|
|
1714
1746
|
* Adds a listener for the given event type.
|
|
@@ -1810,7 +1842,9 @@ var Emitter2 = class {
|
|
|
1810
1842
|
* Removes a listener for the given event type.
|
|
1811
1843
|
*/
|
|
1812
1844
|
removeListener(type, listener) {
|
|
1845
|
+
const options = this.#listenerOptions.get(listener);
|
|
1813
1846
|
this.#listeners.delete(type, listener);
|
|
1847
|
+
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
1814
1848
|
}
|
|
1815
1849
|
/**
|
|
1816
1850
|
* Removes all listeners for the given event type.
|
|
@@ -1819,6 +1853,7 @@ var Emitter2 = class {
|
|
|
1819
1853
|
removeAllListeners(type) {
|
|
1820
1854
|
if (type == null) {
|
|
1821
1855
|
this.#listeners.clear();
|
|
1856
|
+
for (const [hookType, hookListener] of this.#hookListeners) if (!this.#hookListenerOptions.get(hookListener)?.persist) this.#hookListeners.delete(hookType, hookListener);
|
|
1822
1857
|
return;
|
|
1823
1858
|
}
|
|
1824
1859
|
this.#listeners.deleteAll(type);
|
|
@@ -1840,14 +1875,12 @@ var Emitter2 = class {
|
|
|
1840
1875
|
return this.listeners(type).length;
|
|
1841
1876
|
}
|
|
1842
1877
|
#addListener(type, listener, options, insertMode = "append") {
|
|
1878
|
+
for (const hook of this.#hookListeners.get("newListener")) hook(type, listener, options);
|
|
1879
|
+
if (type === "*") this.#typelessListeners.add(listener);
|
|
1843
1880
|
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
1844
1881
|
else this.#listeners.append(type, listener);
|
|
1845
1882
|
if (options) {
|
|
1846
|
-
|
|
1847
|
-
value: options,
|
|
1848
|
-
enumerable: false,
|
|
1849
|
-
writable: false
|
|
1850
|
-
});
|
|
1883
|
+
this.#listenerOptions.set(listener, options);
|
|
1851
1884
|
if (options.signal) options.signal.addEventListener("abort", () => {
|
|
1852
1885
|
this.removeListener(type, listener);
|
|
1853
1886
|
}, { once: true });
|
|
@@ -1855,10 +1888,10 @@ var Emitter2 = class {
|
|
|
1855
1888
|
}
|
|
1856
1889
|
#proxyEvent(event) {
|
|
1857
1890
|
const { stopPropagation } = event;
|
|
1858
|
-
event.stopPropagation =
|
|
1891
|
+
event.stopPropagation = () => {
|
|
1859
1892
|
event[kPropagationStopped] = this;
|
|
1860
|
-
|
|
1861
|
-
}
|
|
1893
|
+
stopPropagation.call(event);
|
|
1894
|
+
};
|
|
1862
1895
|
return {
|
|
1863
1896
|
event,
|
|
1864
1897
|
revoke() {
|
|
@@ -1867,10 +1900,13 @@ var Emitter2 = class {
|
|
|
1867
1900
|
};
|
|
1868
1901
|
}
|
|
1869
1902
|
#callListener(event, listener) {
|
|
1903
|
+
for (const hook of this.#hookListeners.get("beforeEmit")) if (hook(event) === false) return;
|
|
1870
1904
|
const returnValue = listener.call(this, event);
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
this.#
|
|
1905
|
+
const options = this.#listenerOptions.get(listener);
|
|
1906
|
+
if (options?.once) {
|
|
1907
|
+
const type = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
1908
|
+
this.#listeners.delete(type, listener);
|
|
1909
|
+
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
1874
1910
|
}
|
|
1875
1911
|
return returnValue;
|
|
1876
1912
|
}
|
|
@@ -1882,7 +1918,7 @@ var Emitter2 = class {
|
|
|
1882
1918
|
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
|
|
1883
1919
|
}
|
|
1884
1920
|
#isTypelessListener(listener) {
|
|
1885
|
-
return this.#
|
|
1921
|
+
return this.#typelessListeners.has(listener);
|
|
1886
1922
|
}
|
|
1887
1923
|
};
|
|
1888
1924
|
|