22/* tslint:disable */
33
44/**
5- * Mock Service Worker (0.43.1 ).
5+ * Mock Service Worker (0.47.4 ).
66 * @see https://github.com/mswjs/msw
77 * - Please do NOT modify this file.
88 * - Please do NOT serve this file on production.
99 */
1010
11- const INTEGRITY_CHECKSUM = 'c9450df6e4dc5e45740c3b0b640727a2 '
11+ const INTEGRITY_CHECKSUM = 'b3066ef78c2f9090b4ce87e874965995 '
1212const activeClientIds = new Set ( )
1313
1414self . addEventListener ( 'install' , function ( ) {
@@ -200,7 +200,7 @@ async function getResponse(event, client, requestId) {
200200
201201 function passthrough ( ) {
202202 // 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 ).
204204 const headers = Object . fromEntries ( clonedRequest . headers . entries ( ) )
205205
206206 // Remove MSW-specific request headers so the bypassed requests
@@ -231,13 +231,6 @@ async function getResponse(event, client, requestId) {
231231 return passthrough ( )
232232 }
233233
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-
241234 // Notify the client that a request has been intercepted.
242235 const clientMessage = await sendToClient ( client , {
243236 type : 'REQUEST' ,
@@ -262,43 +255,21 @@ async function getResponse(event, client, requestId) {
262255
263256 switch ( clientMessage . type ) {
264257 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 )
270259 }
271260
272261 case 'MOCK_NOT_FOUND' : {
273262 return passthrough ( )
274263 }
275264
276265 case 'NETWORK_ERROR' : {
277- const { name, message } = clientMessage . payload
266+ const { name, message } = clientMessage . data
278267 const networkError = new Error ( message )
279268 networkError . name = name
280269
281270 // Rejecting a "respondWith" promise emulates a network error.
282271 throw networkError
283272 }
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- }
302273 }
303274
304275 return passthrough ( )
@@ -316,7 +287,7 @@ function sendToClient(client, message) {
316287 resolve ( event . data )
317288 }
318289
319- client . postMessage ( JSON . stringify ( message ) , [ channel . port2 ] )
290+ client . postMessage ( message , [ channel . port2 ] )
320291 } )
321292}
322293
@@ -330,38 +301,3 @@ async function respondWithMock(response) {
330301 await sleep ( response . delay )
331302 return new Response ( response . body , response )
332303}
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- }
0 commit comments