msw 2.3.0 → 2.3.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/README.md CHANGED
@@ -17,15 +17,9 @@
17
17
  <p align="center">Mock Service Worker (MSW) is a seamless REST/GraphQL API mocking library for browser and Node.js.</p>
18
18
 
19
19
  <p align="center">
20
- <a href="https://www.npmjs.com/package/msw" target="_blank">
21
- <img src="https://img.shields.io/npm/v/msw.svg?style=for-the-badge&label=Latest&color=black" alt="Package version" />
22
- </a>
23
- <a href="https://www.npmjs.com/package/msw" target="_blank">
24
- <img src="https://img.shields.io/npm/dm/msw?style=for-the-badge&color=black" alt="Downloads per month" />
25
- </a>
26
- <a href="https://kettanaito.com/discord" target="_blank">
27
- <img src="https://img.shields.io/badge/chat-online-green?style=for-the-badge&color=black" alt="Discord server" />
28
- </a>
20
+ <a href="https://www.npmjs.com/package/msw" target="_blank"><img src="https://img.shields.io/npm/v/msw.svg?style=for-the-badge&label=Latest&color=black" alt="Package version" /></a>
21
+ <a href="https://www.npmjs.com/package/msw" target="_blank"><img src="https://img.shields.io/npm/dm/msw?style=for-the-badge&color=black" alt="Downloads per month" /></a>
22
+ <a href="https://kettanaito.com/discord" target="_blank"><img src="https://img.shields.io/badge/chat-online-green?style=for-the-badge&color=black" alt="Discord server" /></a>
29
23
  </p>
30
24
 
31
25
  <br />
@@ -6,6 +6,7 @@ import { Path } from './matchRequestUrl.mjs';
6
6
  * - Removes query parameters and hashes.
7
7
  * - Rebases relative URLs against the "baseUrl" or the current location.
8
8
  * - Preserves relative URLs in Node.js, unless specified otherwise.
9
+ * - Preserves optional path parameters.
9
10
  */
10
11
  declare function normalizePath(path: Path, baseUrl?: string): Path;
11
12
 
@@ -6,6 +6,7 @@ import { Path } from './matchRequestUrl.js';
6
6
  * - Removes query parameters and hashes.
7
7
  * - Rebases relative URLs against the "baseUrl" or the current location.
8
8
  * - Preserves relative URLs in Node.js, unless specified otherwise.
9
+ * - Preserves optional path parameters.
9
10
  */
10
11
  declare function normalizePath(path: Path, baseUrl?: string): Path;
11
12
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/matching/normalizePath.ts"],"sourcesContent":["import type { Path } from './matchRequestUrl'\nimport { cleanUrl } from '../url/cleanUrl'\nimport { getAbsoluteUrl } from '../url/getAbsoluteUrl'\n\n/**\n * Normalizes a given request handler path:\n * - Preserves RegExp.\n * - Removes query parameters and hashes.\n * - Rebases relative URLs against the \"baseUrl\" or the current location.\n * - Preserves relative URLs in Node.js, unless specified otherwise.\n */\nexport function normalizePath(path: Path, baseUrl?: string): Path {\n // RegExp paths do not need normalization.\n if (path instanceof RegExp) {\n return path\n }\n\n const maybeAbsoluteUrl = getAbsoluteUrl(path, baseUrl)\n\n return cleanUrl(maybeAbsoluteUrl)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAyB;AACzB,4BAA+B;AASxB,SAAS,cAAc,MAAY,SAAwB;AAEhE,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,uBAAmB,sCAAe,MAAM,OAAO;AAErD,aAAO,0BAAS,gBAAgB;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/matching/normalizePath.ts"],"sourcesContent":["import type { Path } from './matchRequestUrl'\nimport { cleanUrl } from '../url/cleanUrl'\nimport { getAbsoluteUrl } from '../url/getAbsoluteUrl'\n\n/**\n * Normalizes a given request handler path:\n * - Preserves RegExp.\n * - Removes query parameters and hashes.\n * - Rebases relative URLs against the \"baseUrl\" or the current location.\n * - Preserves relative URLs in Node.js, unless specified otherwise.\n * - Preserves optional path parameters.\n */\nexport function normalizePath(path: Path, baseUrl?: string): Path {\n // RegExp paths do not need normalization.\n if (path instanceof RegExp) {\n return path\n }\n\n const maybeAbsoluteUrl = getAbsoluteUrl(path, baseUrl)\n\n return cleanUrl(maybeAbsoluteUrl)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAyB;AACzB,4BAA+B;AAUxB,SAAS,cAAc,MAAY,SAAwB;AAEhE,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,uBAAmB,sCAAe,MAAM,OAAO;AAErD,aAAO,0BAAS,gBAAgB;AAClC;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/matching/normalizePath.ts"],"sourcesContent":["import type { Path } from './matchRequestUrl'\nimport { cleanUrl } from '../url/cleanUrl'\nimport { getAbsoluteUrl } from '../url/getAbsoluteUrl'\n\n/**\n * Normalizes a given request handler path:\n * - Preserves RegExp.\n * - Removes query parameters and hashes.\n * - Rebases relative URLs against the \"baseUrl\" or the current location.\n * - Preserves relative URLs in Node.js, unless specified otherwise.\n */\nexport function normalizePath(path: Path, baseUrl?: string): Path {\n // RegExp paths do not need normalization.\n if (path instanceof RegExp) {\n return path\n }\n\n const maybeAbsoluteUrl = getAbsoluteUrl(path, baseUrl)\n\n return cleanUrl(maybeAbsoluteUrl)\n}\n"],"mappings":"AACA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AASxB,SAAS,cAAc,MAAY,SAAwB;AAEhE,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmB,eAAe,MAAM,OAAO;AAErD,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/matching/normalizePath.ts"],"sourcesContent":["import type { Path } from './matchRequestUrl'\nimport { cleanUrl } from '../url/cleanUrl'\nimport { getAbsoluteUrl } from '../url/getAbsoluteUrl'\n\n/**\n * Normalizes a given request handler path:\n * - Preserves RegExp.\n * - Removes query parameters and hashes.\n * - Rebases relative URLs against the \"baseUrl\" or the current location.\n * - Preserves relative URLs in Node.js, unless specified otherwise.\n * - Preserves optional path parameters.\n */\nexport function normalizePath(path: Path, baseUrl?: string): Path {\n // RegExp paths do not need normalization.\n if (path instanceof RegExp) {\n return path\n }\n\n const maybeAbsoluteUrl = getAbsoluteUrl(path, baseUrl)\n\n return cleanUrl(maybeAbsoluteUrl)\n}\n"],"mappings":"AACA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAUxB,SAAS,cAAc,MAAY,SAAwB;AAEhE,MAAI,gBAAgB,QAAQ;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmB,eAAe,MAAM,OAAO;AAErD,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
@@ -1,6 +1,7 @@
1
1
  declare function getSearchParams(path: string): URLSearchParams;
2
2
  /**
3
- * Removes query parameters and hashes from a given URL string.
3
+ * Removes search parameters and the fragment
4
+ * from a given URL string.
4
5
  */
5
6
  declare function cleanUrl(path: string): string;
6
7
 
@@ -1,6 +1,7 @@
1
1
  declare function getSearchParams(path: string): URLSearchParams;
2
2
  /**
3
- * Removes query parameters and hashes from a given URL string.
3
+ * Removes search parameters and the fragment
4
+ * from a given URL string.
4
5
  */
5
6
  declare function cleanUrl(path: string): string;
6
7
 
@@ -27,6 +27,9 @@ function getSearchParams(path) {
27
27
  return new URL(`/${path}`, "http://localhost").searchParams;
28
28
  }
29
29
  function cleanUrl(path) {
30
+ if (path.endsWith("?")) {
31
+ return path;
32
+ }
30
33
  return path.replace(REDUNDANT_CHARACTERS_EXP, "");
31
34
  }
32
35
  //# sourceMappingURL=cleanUrl.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/url/cleanUrl.ts"],"sourcesContent":["const REDUNDANT_CHARACTERS_EXP = /[\\?|#].*$/g\n\nexport function getSearchParams(path: string) {\n return new URL(`/${path}`, 'http://localhost').searchParams\n}\n\n/**\n * Removes query parameters and hashes from a given URL string.\n */\nexport function cleanUrl(path: string): string {\n return path.replace(REDUNDANT_CHARACTERS_EXP, '')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,2BAA2B;AAE1B,SAAS,gBAAgB,MAAc;AAC5C,SAAO,IAAI,IAAI,IAAI,IAAI,IAAI,kBAAkB,EAAE;AACjD;AAKO,SAAS,SAAS,MAAsB;AAC7C,SAAO,KAAK,QAAQ,0BAA0B,EAAE;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/url/cleanUrl.ts"],"sourcesContent":["const REDUNDANT_CHARACTERS_EXP = /[\\?|#].*$/g\n\nexport function getSearchParams(path: string) {\n return new URL(`/${path}`, 'http://localhost').searchParams\n}\n\n/**\n * Removes search parameters and the fragment\n * from a given URL string.\n */\nexport function cleanUrl(path: string): string {\n // If the path ends with an optional path parameter,\n // return it as-is.\n if (path.endsWith('?')) {\n return path\n }\n\n // Otherwise, remove the search and fragment from it.\n return path.replace(REDUNDANT_CHARACTERS_EXP, '')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,2BAA2B;AAE1B,SAAS,gBAAgB,MAAc;AAC5C,SAAO,IAAI,IAAI,IAAI,IAAI,IAAI,kBAAkB,EAAE;AACjD;AAMO,SAAS,SAAS,MAAsB;AAG7C,MAAI,KAAK,SAAS,GAAG,GAAG;AACtB,WAAO;AAAA,EACT;AAGA,SAAO,KAAK,QAAQ,0BAA0B,EAAE;AAClD;","names":[]}
@@ -3,6 +3,9 @@ function getSearchParams(path) {
3
3
  return new URL(`/${path}`, "http://localhost").searchParams;
4
4
  }
5
5
  function cleanUrl(path) {
6
+ if (path.endsWith("?")) {
7
+ return path;
8
+ }
6
9
  return path.replace(REDUNDANT_CHARACTERS_EXP, "");
7
10
  }
8
11
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/utils/url/cleanUrl.ts"],"sourcesContent":["const REDUNDANT_CHARACTERS_EXP = /[\\?|#].*$/g\n\nexport function getSearchParams(path: string) {\n return new URL(`/${path}`, 'http://localhost').searchParams\n}\n\n/**\n * Removes query parameters and hashes from a given URL string.\n */\nexport function cleanUrl(path: string): string {\n return path.replace(REDUNDANT_CHARACTERS_EXP, '')\n}\n"],"mappings":"AAAA,MAAM,2BAA2B;AAE1B,SAAS,gBAAgB,MAAc;AAC5C,SAAO,IAAI,IAAI,IAAI,IAAI,IAAI,kBAAkB,EAAE;AACjD;AAKO,SAAS,SAAS,MAAsB;AAC7C,SAAO,KAAK,QAAQ,0BAA0B,EAAE;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/utils/url/cleanUrl.ts"],"sourcesContent":["const REDUNDANT_CHARACTERS_EXP = /[\\?|#].*$/g\n\nexport function getSearchParams(path: string) {\n return new URL(`/${path}`, 'http://localhost').searchParams\n}\n\n/**\n * Removes search parameters and the fragment\n * from a given URL string.\n */\nexport function cleanUrl(path: string): string {\n // If the path ends with an optional path parameter,\n // return it as-is.\n if (path.endsWith('?')) {\n return path\n }\n\n // Otherwise, remove the search and fragment from it.\n return path.replace(REDUNDANT_CHARACTERS_EXP, '')\n}\n"],"mappings":"AAAA,MAAM,2BAA2B;AAE1B,SAAS,gBAAgB,MAAc;AAC5C,SAAO,IAAI,IAAI,IAAI,IAAI,IAAI,kBAAkB,EAAE;AACjD;AAMO,SAAS,SAAS,MAAsB;AAG7C,MAAI,KAAK,SAAS,GAAG,GAAG;AACtB,WAAO;AAAA,EACT;AAGA,SAAO,KAAK,QAAQ,0BAA0B,EAAE;AAClD;","names":[]}
package/lib/iife/index.js CHANGED
@@ -1675,6 +1675,9 @@ var MockServiceWorker = (() => {
1675
1675
  return new URL(`/${path}`, "http://localhost").searchParams;
1676
1676
  }
1677
1677
  function cleanUrl(path) {
1678
+ if (path.endsWith("?")) {
1679
+ return path;
1680
+ }
1678
1681
  return path.replace(REDUNDANT_CHARACTERS_EXP, "");
1679
1682
  }
1680
1683