msw 0.44.1 → 0.46.0

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.
@@ -2,13 +2,13 @@
2
2
  /* tslint:disable */
3
3
 
4
4
  /**
5
- * Mock Service Worker (0.44.1).
5
+ * Mock Service Worker (0.46.0).
6
6
  * @see https://github.com/mswjs/msw
7
7
  * - Please do NOT modify this file.
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const INTEGRITY_CHECKSUM = 'df0d85222361310ecbe1792c606e08f2'
11
+ const INTEGRITY_CHECKSUM = 'b3066ef78c2f9090b4ce87e874965995'
12
12
  const activeClientIds = new Set()
13
13
 
14
14
  self.addEventListener('install', function () {
@@ -200,7 +200,7 @@ async function getResponse(event, client, requestId) {
200
200
 
201
201
  function passthrough() {
202
202
  // Clone the request because it might've been already used
203
- // (i.e. its body has been read and sent to the cilent).
203
+ // (i.e. its body has been read and sent to the client).
204
204
  const headers = Object.fromEntries(clonedRequest.headers.entries())
205
205
 
206
206
  // Remove MSW-specific request headers so the bypassed requests
@@ -231,13 +231,6 @@ async function getResponse(event, client, requestId) {
231
231
  return passthrough()
232
232
  }
233
233
 
234
- // Create a communication channel scoped to the current request.
235
- // This way events can be exchanged outside of the worker's global
236
- // "message" event listener (i.e. abstracted into functions).
237
- const operationChannel = new BroadcastChannel(
238
- `msw-response-stream-${requestId}`,
239
- )
240
-
241
234
  // Notify the client that a request has been intercepted.
242
235
  const clientMessage = await sendToClient(client, {
243
236
  type: 'REQUEST',
@@ -262,11 +255,7 @@ async function getResponse(event, client, requestId) {
262
255
 
263
256
  switch (clientMessage.type) {
264
257
  case 'MOCK_RESPONSE': {
265
- return respondWithMock(clientMessage.payload)
266
- }
267
-
268
- case 'MOCK_RESPONSE_START': {
269
- return respondWithMockStream(operationChannel, clientMessage.payload)
258
+ return respondWithMock(clientMessage.data)
270
259
  }
271
260
 
272
261
  case 'MOCK_NOT_FOUND': {
@@ -274,31 +263,13 @@ async function getResponse(event, client, requestId) {
274
263
  }
275
264
 
276
265
  case 'NETWORK_ERROR': {
277
- const { name, message } = clientMessage.payload
266
+ const { name, message } = clientMessage.data
278
267
  const networkError = new Error(message)
279
268
  networkError.name = name
280
269
 
281
270
  // Rejecting a "respondWith" promise emulates a network error.
282
271
  throw networkError
283
272
  }
284
-
285
- case 'INTERNAL_ERROR': {
286
- const parsedBody = JSON.parse(clientMessage.payload.body)
287
-
288
- console.error(
289
- `\
290
- [MSW] Uncaught exception in the request handler for "%s %s":
291
-
292
- ${parsedBody.location}
293
-
294
- This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses\
295
- `,
296
- request.method,
297
- request.url,
298
- )
299
-
300
- return respondWithMock(clientMessage.payload)
301
- }
302
273
  }
303
274
 
304
275
  return passthrough()
@@ -330,38 +301,3 @@ async function respondWithMock(response) {
330
301
  await sleep(response.delay)
331
302
  return new Response(response.body, response)
332
303
  }
333
-
334
- function respondWithMockStream(operationChannel, mockResponse) {
335
- let streamCtrl
336
- const stream = new ReadableStream({
337
- start: (controller) => (streamCtrl = controller),
338
- })
339
-
340
- return new Promise(async (resolve, reject) => {
341
- operationChannel.onmessageerror = (event) => {
342
- operationChannel.close()
343
- return reject(event.data.error)
344
- }
345
-
346
- operationChannel.onmessage = (event) => {
347
- if (!event.data) {
348
- return
349
- }
350
-
351
- switch (event.data.type) {
352
- case 'MOCK_RESPONSE_CHUNK': {
353
- streamCtrl.enqueue(event.data.payload)
354
- break
355
- }
356
-
357
- case 'MOCK_RESPONSE_END': {
358
- streamCtrl.close()
359
- operationChannel.close()
360
- }
361
- }
362
- }
363
-
364
- await sleep(mockResponse.delay)
365
- return resolve(new Response(stream, mockResponse))
366
- })
367
- }
@@ -1,4 +1,4 @@
1
- import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, I as SetupServerApi } from '../glossary-297d38ba.js';
1
+ import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, I as SetupServerApi } from '../glossary-c690f512.js';
2
2
  import 'type-fest';
3
3
  import '@mswjs/interceptors';
4
4
  import 'headers-polyfill';
@@ -147,9 +147,6 @@ var devUtils = {
147
147
  // src/utils/request/onUnhandledRequest.ts
148
148
  var import_js_levenshtein = __toESM(require("js-levenshtein"));
149
149
 
150
- // src/utils/internal/parseGraphQLRequest.ts
151
- var import_graphql = require("graphql");
152
-
153
150
  // src/utils/request/getPublicUrlFromRequest.ts
154
151
  var getPublicUrlFromRequest = (request) => {
155
152
  return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
@@ -177,7 +174,8 @@ function parseDocumentNode(node) {
177
174
  }
178
175
  function parseQuery(query) {
179
176
  try {
180
- const ast = (0, import_graphql.parse)(query);
177
+ const { parse: parse3 } = require("graphql");
178
+ const ast = parse3(query);
181
179
  return parseDocumentNode(ast);
182
180
  } catch (error2) {
183
181
  return error2;
@@ -1236,6 +1234,13 @@ function pipeEvents(source, destination) {
1236
1234
  source.emit._isPiped = true;
1237
1235
  }
1238
1236
 
1237
+ // src/utils/internal/toReadonlyArray.ts
1238
+ function toReadonlyArray(source) {
1239
+ const clone = [...source];
1240
+ Object.freeze(clone);
1241
+ return clone;
1242
+ }
1243
+
1239
1244
  // src/node/createSetupServer.ts
1240
1245
  var DEFAULT_LISTEN_OPTIONS = {
1241
1246
  onUnhandledRequest: "warn"
@@ -1307,8 +1312,12 @@ function createSetupServer(...interceptors) {
1307
1312
  resetHandlers(...nextHandlers) {
1308
1313
  currentHandlers = resetHandlers(requestHandlers, ...nextHandlers);
1309
1314
  },
1315
+ listHandlers() {
1316
+ return toReadonlyArray(currentHandlers);
1317
+ },
1310
1318
  printHandlers() {
1311
- currentHandlers.forEach((handler) => {
1319
+ const handlers = this.listHandlers();
1320
+ handlers.forEach((handler) => {
1312
1321
  const { header, callFrame } = handler.info;
1313
1322
  const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
1314
1323
  console.log(`${(0, import_chalk.bold)(`${pragma} ${header}`)}
@@ -133,11 +133,6 @@ var devUtils = {
133
133
  // src/utils/request/onUnhandledRequest.ts
134
134
  import getStringMatchScore from "js-levenshtein";
135
135
 
136
- // src/utils/internal/parseGraphQLRequest.ts
137
- import {
138
- parse
139
- } from "graphql";
140
-
141
136
  // src/utils/request/getPublicUrlFromRequest.ts
142
137
  var getPublicUrlFromRequest = (request) => {
143
138
  return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
@@ -165,7 +160,8 @@ function parseDocumentNode(node) {
165
160
  }
166
161
  function parseQuery(query) {
167
162
  try {
168
- const ast = parse(query);
163
+ const { parse: parse3 } = __require("graphql");
164
+ const ast = parse3(query);
169
165
  return parseDocumentNode(ast);
170
166
  } catch (error2) {
171
167
  return error2;
@@ -1224,6 +1220,13 @@ function pipeEvents(source, destination) {
1224
1220
  source.emit._isPiped = true;
1225
1221
  }
1226
1222
 
1223
+ // src/utils/internal/toReadonlyArray.ts
1224
+ function toReadonlyArray(source) {
1225
+ const clone = [...source];
1226
+ Object.freeze(clone);
1227
+ return clone;
1228
+ }
1229
+
1227
1230
  // src/node/createSetupServer.ts
1228
1231
  var DEFAULT_LISTEN_OPTIONS = {
1229
1232
  onUnhandledRequest: "warn"
@@ -1295,8 +1298,12 @@ function createSetupServer(...interceptors) {
1295
1298
  resetHandlers(...nextHandlers) {
1296
1299
  currentHandlers = resetHandlers(requestHandlers, ...nextHandlers);
1297
1300
  },
1301
+ listHandlers() {
1302
+ return toReadonlyArray(currentHandlers);
1303
+ },
1298
1304
  printHandlers() {
1299
- currentHandlers.forEach((handler) => {
1305
+ const handlers = this.listHandlers();
1306
+ handlers.forEach((handler) => {
1300
1307
  const { header, callFrame } = handler.info;
1301
1308
  const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
1302
1309
  console.log(`${bold(`${pragma} ${header}`)}
@@ -1,5 +1,5 @@
1
- import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, I as SetupServerApi } from '../glossary-297d38ba.js';
2
- export { I as SetupServerApi } from '../glossary-297d38ba.js';
1
+ import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, I as SetupServerApi } from '../glossary-c690f512.js';
2
+ export { I as SetupServerApi } from '../glossary-c690f512.js';
3
3
  import 'type-fest';
4
4
  import '@mswjs/interceptors';
5
5
  import 'headers-polyfill';
package/lib/node/index.js CHANGED
@@ -154,9 +154,6 @@ var devUtils = {
154
154
  // src/utils/request/onUnhandledRequest.ts
155
155
  var import_js_levenshtein = __toESM(require("js-levenshtein"));
156
156
 
157
- // src/utils/internal/parseGraphQLRequest.ts
158
- var import_graphql = require("graphql");
159
-
160
157
  // src/utils/request/getPublicUrlFromRequest.ts
161
158
  var getPublicUrlFromRequest = (request) => {
162
159
  return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
@@ -184,7 +181,8 @@ function parseDocumentNode(node) {
184
181
  }
185
182
  function parseQuery(query) {
186
183
  try {
187
- const ast = (0, import_graphql.parse)(query);
184
+ const { parse: parse3 } = require("graphql");
185
+ const ast = parse3(query);
188
186
  return parseDocumentNode(ast);
189
187
  } catch (error2) {
190
188
  return error2;
@@ -1243,6 +1241,13 @@ function pipeEvents(source, destination) {
1243
1241
  source.emit._isPiped = true;
1244
1242
  }
1245
1243
 
1244
+ // src/utils/internal/toReadonlyArray.ts
1245
+ function toReadonlyArray(source) {
1246
+ const clone = [...source];
1247
+ Object.freeze(clone);
1248
+ return clone;
1249
+ }
1250
+
1246
1251
  // src/node/createSetupServer.ts
1247
1252
  var DEFAULT_LISTEN_OPTIONS = {
1248
1253
  onUnhandledRequest: "warn"
@@ -1314,8 +1319,12 @@ function createSetupServer(...interceptors) {
1314
1319
  resetHandlers(...nextHandlers) {
1315
1320
  currentHandlers = resetHandlers(requestHandlers, ...nextHandlers);
1316
1321
  },
1322
+ listHandlers() {
1323
+ return toReadonlyArray(currentHandlers);
1324
+ },
1317
1325
  printHandlers() {
1318
- currentHandlers.forEach((handler) => {
1326
+ const handlers = this.listHandlers();
1327
+ handlers.forEach((handler) => {
1319
1328
  const { header, callFrame } = handler.info;
1320
1329
  const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
1321
1330
  console.log(`${(0, import_chalk.bold)(`${pragma} ${header}`)}