msw 2.0.11 → 2.0.13
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.d.mts +104 -0
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/index.mjs +1 -0
- package/lib/browser/index.mjs.map +1 -0
- package/lib/core/{GraphQLHandler-907fc607.d.ts → GraphQLHandler-SHlRCcy4.d.ts} +9 -2
- package/lib/core/GraphQLHandler-zlmUDnN6.d.mts +97 -0
- package/lib/core/HttpResponse.d.mts +2 -0
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js +1 -0
- package/lib/core/HttpResponse.js.map +1 -0
- package/lib/core/HttpResponse.mjs +1 -0
- package/lib/core/HttpResponse.mjs.map +1 -0
- package/lib/core/{RequestHandler-50ddea0c.d.ts → RequestHandler-rBDJQrEf.d.ts} +3 -1
- package/lib/core/RequestHandler-vxZdj6Tw.d.mts +179 -0
- package/lib/core/SetupApi.d.mts +26 -0
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/SetupApi.js +1 -0
- package/lib/core/SetupApi.js.map +1 -0
- package/lib/core/SetupApi.mjs +1 -0
- package/lib/core/SetupApi.mjs.map +1 -0
- package/lib/core/bypass.d.mts +16 -0
- package/lib/core/bypass.d.ts +1 -1
- package/lib/core/bypass.js +1 -0
- package/lib/core/bypass.js.map +1 -0
- package/lib/core/bypass.mjs +1 -0
- package/lib/core/bypass.mjs.map +1 -0
- package/lib/core/delay.d.mts +18 -0
- package/lib/core/delay.d.ts +1 -1
- package/lib/core/delay.js +1 -0
- package/lib/core/delay.js.map +1 -0
- package/lib/core/delay.mjs +1 -0
- package/lib/core/delay.mjs.map +1 -0
- package/lib/core/graphql.d.mts +109 -0
- package/lib/core/graphql.d.ts +3 -3
- package/lib/core/graphql.js +1 -0
- package/lib/core/graphql.js.map +1 -0
- package/lib/core/graphql.mjs +1 -0
- package/lib/core/graphql.mjs.map +1 -0
- package/lib/core/handlers/GraphQLHandler.d.mts +5 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js +28 -8
- package/lib/core/handlers/GraphQLHandler.js.map +1 -0
- package/lib/core/handlers/GraphQLHandler.mjs +28 -8
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -0
- package/lib/core/handlers/HttpHandler.d.mts +62 -0
- package/lib/core/handlers/HttpHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.js +1 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -0
- package/lib/core/handlers/HttpHandler.mjs +1 -0
- package/lib/core/handlers/HttpHandler.mjs.map +1 -0
- package/lib/core/handlers/RequestHandler.d.mts +2 -0
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +19 -4
- package/lib/core/handlers/RequestHandler.js.map +1 -0
- package/lib/core/handlers/RequestHandler.mjs +19 -4
- package/lib/core/handlers/RequestHandler.mjs.map +1 -0
- package/lib/core/http.d.mts +26 -0
- package/lib/core/http.d.ts +1 -1
- package/lib/core/http.js +1 -0
- package/lib/core/http.js.map +1 -0
- package/lib/core/http.mjs +1 -0
- package/lib/core/http.mjs.map +1 -0
- package/lib/core/index.d.mts +18 -0
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js +1 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/index.mjs +1 -0
- package/lib/core/index.mjs.map +1 -0
- package/lib/core/passthrough.d.mts +17 -0
- package/lib/core/passthrough.js +1 -0
- package/lib/core/passthrough.js.map +1 -0
- package/lib/core/passthrough.mjs +1 -0
- package/lib/core/passthrough.mjs.map +1 -0
- package/lib/core/sharedOptions.d.mts +66 -0
- package/lib/core/sharedOptions.d.ts +2 -2
- package/lib/core/sharedOptions.js +1 -0
- package/lib/core/sharedOptions.js.map +1 -0
- package/lib/core/sharedOptions.mjs +1 -0
- package/lib/core/sharedOptions.mjs.map +1 -0
- package/lib/core/typeUtils.d.mts +7 -0
- package/lib/core/typeUtils.d.ts +1 -1
- package/lib/core/typeUtils.js +1 -0
- package/lib/core/typeUtils.js.map +1 -0
- package/lib/core/typeUtils.mjs +1 -0
- package/lib/core/typeUtils.mjs.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.d.mts +12 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +2 -2
- package/lib/core/utils/HttpResponse/decorators.js +1 -0
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +1 -0
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -0
- package/lib/core/utils/getResponse.d.mts +2 -0
- package/lib/core/utils/getResponse.d.ts +1 -1
- package/lib/core/utils/getResponse.js +1 -0
- package/lib/core/utils/getResponse.js.map +1 -0
- package/lib/core/utils/getResponse.mjs +1 -0
- package/lib/core/utils/getResponse.mjs.map +1 -0
- package/lib/core/utils/handleRequest.d.mts +37 -0
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js +1 -0
- package/lib/core/utils/handleRequest.js.map +1 -0
- package/lib/core/utils/handleRequest.mjs +1 -0
- package/lib/core/utils/handleRequest.mjs.map +1 -0
- package/lib/core/utils/internal/Disposable.d.mts +7 -0
- package/lib/core/utils/internal/Disposable.d.ts +1 -1
- package/lib/core/utils/internal/Disposable.js +1 -0
- package/lib/core/utils/internal/Disposable.js.map +1 -0
- package/lib/core/utils/internal/Disposable.mjs +1 -0
- package/lib/core/utils/internal/Disposable.mjs.map +1 -0
- package/lib/core/utils/internal/checkGlobals.d.mts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +1 -0
- package/lib/core/utils/internal/checkGlobals.js.map +1 -0
- package/lib/core/utils/internal/checkGlobals.mjs +1 -0
- package/lib/core/utils/internal/checkGlobals.mjs.map +1 -0
- package/lib/core/utils/internal/devUtils.d.mts +19 -0
- package/lib/core/utils/internal/devUtils.js +1 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -0
- package/lib/core/utils/internal/devUtils.mjs +1 -0
- package/lib/core/utils/internal/devUtils.mjs.map +1 -0
- package/lib/core/utils/internal/getCallFrame.d.mts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +1 -0
- package/lib/core/utils/internal/getCallFrame.js.map +1 -0
- package/lib/core/utils/internal/getCallFrame.mjs +1 -0
- package/lib/core/utils/internal/getCallFrame.mjs.map +1 -0
- package/lib/core/utils/internal/isIterable.d.mts +6 -0
- package/lib/core/utils/internal/isIterable.js +1 -0
- package/lib/core/utils/internal/isIterable.js.map +1 -0
- package/lib/core/utils/internal/isIterable.mjs +1 -0
- package/lib/core/utils/internal/isIterable.mjs.map +1 -0
- package/lib/core/utils/internal/isObject.d.mts +6 -0
- package/lib/core/utils/internal/isObject.js +1 -0
- package/lib/core/utils/internal/isObject.js.map +1 -0
- package/lib/core/utils/internal/isObject.mjs +1 -0
- package/lib/core/utils/internal/isObject.mjs.map +1 -0
- package/lib/core/utils/internal/isStringEqual.d.mts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +1 -0
- package/lib/core/utils/internal/isStringEqual.js.map +1 -0
- package/lib/core/utils/internal/isStringEqual.mjs +1 -0
- package/lib/core/utils/internal/isStringEqual.mjs.map +1 -0
- package/lib/core/utils/internal/jsonParse.d.mts +7 -0
- package/lib/core/utils/internal/jsonParse.js +1 -0
- package/lib/core/utils/internal/jsonParse.js.map +1 -0
- package/lib/core/utils/internal/jsonParse.mjs +1 -0
- package/lib/core/utils/internal/jsonParse.mjs.map +1 -0
- package/lib/core/utils/internal/mergeRight.d.mts +7 -0
- package/lib/core/utils/internal/mergeRight.js +1 -0
- package/lib/core/utils/internal/mergeRight.js.map +1 -0
- package/lib/core/utils/internal/mergeRight.mjs +1 -0
- package/lib/core/utils/internal/mergeRight.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +5 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.js +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.d.mts +10 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.js +1 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -0
- package/lib/core/utils/internal/pipeEvents.d.mts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +1 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +8 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.js +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.js.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.d.mts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +1 -0
- package/lib/core/utils/internal/toReadonlyArray.js.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +1 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs.map +1 -0
- package/lib/core/utils/internal/tryCatch.d.mts +3 -0
- package/lib/core/utils/internal/tryCatch.js +1 -0
- package/lib/core/utils/internal/tryCatch.js.map +1 -0
- package/lib/core/utils/internal/tryCatch.mjs +1 -0
- package/lib/core/utils/internal/tryCatch.mjs.map +1 -0
- package/lib/core/utils/internal/uuidv4.d.mts +3 -0
- package/lib/core/utils/internal/uuidv4.js +1 -0
- package/lib/core/utils/internal/uuidv4.js.map +1 -0
- package/lib/core/utils/internal/uuidv4.mjs +1 -0
- package/lib/core/utils/internal/uuidv4.mjs.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.mts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.js.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs.map +1 -0
- package/lib/core/utils/logging/getTimestamp.d.mts +6 -0
- package/lib/core/utils/logging/getTimestamp.js +1 -0
- package/lib/core/utils/logging/getTimestamp.js.map +1 -0
- package/lib/core/utils/logging/getTimestamp.mjs +1 -0
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -0
- package/lib/core/utils/logging/serializeRequest.d.mts +12 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +1 -1
- package/lib/core/utils/logging/serializeRequest.js +1 -0
- package/lib/core/utils/logging/serializeRequest.js.map +1 -0
- package/lib/core/utils/logging/serializeRequest.mjs +1 -0
- package/lib/core/utils/logging/serializeRequest.mjs.map +1 -0
- package/lib/core/utils/logging/serializeResponse.d.mts +9 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +1 -1
- package/lib/core/utils/logging/serializeResponse.js +1 -0
- package/lib/core/utils/logging/serializeResponse.js.map +1 -0
- package/lib/core/utils/logging/serializeResponse.mjs +1 -0
- package/lib/core/utils/logging/serializeResponse.mjs.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.d.mts +19 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js +1 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +1 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -0
- package/lib/core/utils/matching/normalizePath.d.mts +12 -0
- package/lib/core/utils/matching/normalizePath.js +1 -0
- package/lib/core/utils/matching/normalizePath.js.map +1 -0
- package/lib/core/utils/matching/normalizePath.mjs +1 -0
- package/lib/core/utils/matching/normalizePath.mjs.map +1 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.d.mts +7 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js +1 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js.map +1 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs +1 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs.map +1 -0
- package/lib/core/utils/request/getRequestCookies.d.mts +8 -0
- package/lib/core/utils/request/getRequestCookies.js +1 -0
- package/lib/core/utils/request/getRequestCookies.js.map +1 -0
- package/lib/core/utils/request/getRequestCookies.mjs +1 -0
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.d.mts +12 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.js +1 -0
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +1 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -0
- package/lib/core/utils/request/readResponseCookies.d.mts +3 -0
- package/lib/core/utils/request/readResponseCookies.js +1 -0
- package/lib/core/utils/request/readResponseCookies.js.map +1 -0
- package/lib/core/utils/request/readResponseCookies.mjs +1 -0
- package/lib/core/utils/request/readResponseCookies.mjs.map +1 -0
- package/lib/core/utils/toResponseInit.d.mts +3 -0
- package/lib/core/utils/toResponseInit.js +1 -0
- package/lib/core/utils/toResponseInit.js.map +1 -0
- package/lib/core/utils/toResponseInit.mjs +1 -0
- package/lib/core/utils/toResponseInit.mjs.map +1 -0
- package/lib/core/utils/url/cleanUrl.d.mts +7 -0
- package/lib/core/utils/url/cleanUrl.js +1 -0
- package/lib/core/utils/url/cleanUrl.js.map +1 -0
- package/lib/core/utils/url/cleanUrl.mjs +1 -0
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs.map +1 -0
- package/lib/iife/index.js +59 -25
- package/lib/iife/index.js.map +1 -0
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +75 -0
- package/lib/native/index.d.ts +0 -1
- package/lib/native/index.js +1 -3
- package/lib/native/index.js.map +1 -0
- package/lib/native/index.mjs +1 -3
- package/lib/native/index.mjs.map +1 -0
- package/lib/node/index.d.mts +75 -0
- package/lib/node/index.d.ts +1 -2
- package/lib/node/index.js +2 -35
- package/lib/node/index.js.map +1 -0
- package/lib/node/index.mjs +2 -35
- package/lib/node/index.mjs.map +1 -0
- package/package.json +6 -5
- package/src/browser/global.browser.d.ts +1 -0
- package/src/browser/index.ts +3 -0
- package/src/browser/setupWorker/glossary.ts +259 -0
- package/src/browser/setupWorker/setupWorker.node.test.ts +10 -0
- package/src/browser/setupWorker/setupWorker.ts +199 -0
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +67 -0
- package/src/browser/setupWorker/start/createFallbackStart.ts +21 -0
- package/src/browser/setupWorker/start/createRequestListener.ts +127 -0
- package/src/browser/setupWorker/start/createResponseListener.ts +58 -0
- package/src/browser/setupWorker/start/createStartHandler.ts +143 -0
- package/src/browser/setupWorker/start/utils/createMessageChannel.ts +32 -0
- package/src/browser/setupWorker/start/utils/enableMocking.ts +32 -0
- package/src/browser/setupWorker/start/utils/getWorkerByRegistration.ts +25 -0
- package/src/browser/setupWorker/start/utils/getWorkerInstance.ts +94 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +59 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +44 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +84 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +40 -0
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +18 -0
- package/src/browser/setupWorker/stop/createFallbackStop.ts +11 -0
- package/src/browser/setupWorker/stop/createStop.ts +29 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +26 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +12 -0
- package/src/browser/tsconfig.browser.build.json +6 -0
- package/src/browser/tsconfig.browser.json +9 -0
- package/src/browser/utils/deferNetworkRequestsUntil.test.ts +48 -0
- package/src/browser/utils/deferNetworkRequestsUntil.ts +29 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.test.ts +31 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.ts +7 -0
- package/src/browser/utils/parseWorkerRequest.ts +15 -0
- package/src/browser/utils/pruneGetRequestBody.test.ts +53 -0
- package/src/browser/utils/pruneGetRequestBody.ts +21 -0
- package/src/browser/utils/requestIntegrityCheck.ts +23 -0
- package/src/browser/utils/supportsReadableStreamTransfer.ts +17 -0
- package/src/core/HttpResponse.test.ts +200 -0
- package/src/core/HttpResponse.ts +134 -0
- package/src/core/SetupApi.ts +95 -0
- package/src/core/bypass.test.ts +47 -0
- package/src/core/bypass.ts +36 -0
- package/src/core/delay.ts +70 -0
- package/src/core/graphql.test.ts +11 -0
- package/src/core/graphql.ts +138 -0
- package/src/core/handlers/GraphQLHandler.test.ts +820 -0
- package/src/core/handlers/GraphQLHandler.ts +263 -0
- package/src/core/handlers/HttpHandler.test.ts +218 -0
- package/src/core/handlers/HttpHandler.ts +169 -0
- package/src/core/handlers/RequestHandler.ts +338 -0
- package/src/core/http.test.ts +15 -0
- package/src/core/http.ts +51 -0
- package/src/core/index.ts +56 -0
- package/src/core/passthrough.test.ts +13 -0
- package/src/core/passthrough.ts +23 -0
- package/src/core/sharedOptions.ts +66 -0
- package/src/core/typeUtils.ts +20 -0
- package/src/core/utils/HttpResponse/decorators.ts +56 -0
- package/src/core/utils/getResponse.ts +55 -0
- package/src/core/utils/handleRequest.test.ts +554 -0
- package/src/core/utils/handleRequest.ts +132 -0
- package/src/core/utils/internal/Disposable.ts +9 -0
- package/src/core/utils/internal/checkGlobals.ts +17 -0
- package/src/core/utils/internal/devUtils.ts +31 -0
- package/src/core/utils/internal/getCallFrame.test.ts +154 -0
- package/src/core/utils/internal/getCallFrame.ts +35 -0
- package/src/core/utils/internal/isIterable.test.ts +23 -0
- package/src/core/utils/internal/isIterable.ts +12 -0
- package/src/core/utils/internal/isObject.test.ts +20 -0
- package/src/core/utils/internal/isObject.ts +6 -0
- package/src/core/utils/internal/isStringEqual.test.ts +45 -0
- package/src/core/utils/internal/isStringEqual.ts +6 -0
- package/src/core/utils/internal/jsonParse.test.ts +13 -0
- package/src/core/utils/internal/jsonParse.ts +13 -0
- package/src/core/utils/internal/mergeRight.test.ts +43 -0
- package/src/core/utils/internal/mergeRight.ts +27 -0
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +99 -0
- package/src/core/utils/internal/parseGraphQLRequest.ts +205 -0
- package/src/core/utils/internal/parseMultipartData.test.ts +76 -0
- package/src/core/utils/internal/parseMultipartData.ts +104 -0
- package/src/core/utils/internal/pipeEvents.test.ts +14 -0
- package/src/core/utils/internal/pipeEvents.ts +25 -0
- package/src/core/utils/internal/requestHandlerUtils.ts +21 -0
- package/src/core/utils/internal/toReadonlyArray.test.ts +30 -0
- package/src/core/utils/internal/toReadonlyArray.ts +8 -0
- package/src/core/utils/internal/tryCatch.test.ts +29 -0
- package/src/core/utils/internal/tryCatch.ts +11 -0
- package/src/core/utils/internal/uuidv4.ts +3 -0
- package/src/core/utils/logging/getStatusCodeColor.test.ts +22 -0
- package/src/core/utils/logging/getStatusCodeColor.ts +20 -0
- package/src/core/utils/logging/getTimestamp.test.ts +18 -0
- package/src/core/utils/logging/getTimestamp.ts +12 -0
- package/src/core/utils/logging/serializeRequest.test.ts +23 -0
- package/src/core/utils/logging/serializeRequest.ts +23 -0
- package/src/core/utils/logging/serializeResponse.test.ts +77 -0
- package/src/core/utils/logging/serializeResponse.ts +31 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +114 -0
- package/src/core/utils/matching/matchRequestUrl.ts +73 -0
- package/src/core/utils/matching/normalizePath.node.test.ts +44 -0
- package/src/core/utils/matching/normalizePath.test.ts +50 -0
- package/src/core/utils/matching/normalizePath.ts +21 -0
- package/src/core/utils/request/getPublicUrlFromRequest.test.ts +26 -0
- package/src/core/utils/request/getPublicUrlFromRequest.ts +15 -0
- package/src/core/utils/request/getRequestCookies.node.test.ts +29 -0
- package/src/core/utils/request/getRequestCookies.test.ts +64 -0
- package/src/core/utils/request/getRequestCookies.ts +75 -0
- package/src/core/utils/request/onUnhandledRequest.test.ts +215 -0
- package/src/core/utils/request/onUnhandledRequest.ts +247 -0
- package/src/core/utils/request/readResponseCookies.ts +9 -0
- package/src/core/utils/toResponseInit.ts +7 -0
- package/src/core/utils/url/cleanUrl.test.ts +17 -0
- package/src/core/utils/url/cleanUrl.ts +12 -0
- package/src/core/utils/url/getAbsoluteUrl.node.test.ts +19 -0
- package/src/core/utils/url/getAbsoluteUrl.test.ts +29 -0
- package/src/core/utils/url/getAbsoluteUrl.ts +26 -0
- package/src/core/utils/url/isAbsoluteUrl.test.ts +32 -0
- package/src/core/utils/url/isAbsoluteUrl.ts +6 -0
- package/src/iife/index.ts +2 -0
- package/src/mockServiceWorker.js +287 -0
- package/src/native/index.ts +17 -0
- package/src/node/SetupServerApi.ts +113 -0
- package/src/node/glossary.ts +62 -0
- package/src/node/index.ts +3 -0
- package/src/node/setupServer.ts +21 -0
- package/src/node/utils/isNodeExceptionLike.ts +14 -0
- package/src/tsconfig.core.build.json +6 -0
- package/src/tsconfig.node.build.json +6 -0
- package/src/tsconfig.node.json +8 -0
- package/src/tsconfig.src.json +15 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @todo Rename this to "getDocumentCookies" */
|
|
2
|
+
/**
|
|
3
|
+
* Returns relevant document cookies based on the request `credentials` option.
|
|
4
|
+
*/
|
|
5
|
+
declare function getRequestCookies(request: Request): Record<string, string>;
|
|
6
|
+
declare function getAllRequestCookies(request: Request): Record<string, string>;
|
|
7
|
+
|
|
8
|
+
export { getAllRequestCookies, getRequestCookies };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { store } from '@mswjs/cookies'\n\nfunction getAllDocumentCookies() {\n return cookieUtils.parse(document.cookie)\n}\n\n/** @todo Rename this to \"getDocumentCookies\" */\n/**\n * Returns relevant document cookies based on the request `credentials` option.\n */\nexport function getRequestCookies(request: Request): Record<string, string> {\n /**\n * @note No cookies persist on the document in Node.js: no document.\n */\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const url = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === url.origin ? getAllDocumentCookies() : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n const requestCookiesString = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookiesString\n ? cookieUtils.parse(requestCookiesString)\n : {}\n\n store.hydrate()\n\n const cookiesFromStore = Array.from(store.get(request)?.entries()).reduce<\n Record<string, string>\n >((cookies, [name, { value }]) => {\n return Object.assign(cookies, { [name.trim()]: value })\n }, {})\n\n const cookiesFromDocument = getRequestCookies(request)\n\n const forwardedCookies = {\n ...cookiesFromDocument,\n ...cookiesFromStore,\n }\n\n // Set the inferred cookies from the cookie store and the document\n // on the request's headers.\n /**\n * @todo Consider making this a separate step so this function\n * is pure-er.\n */\n for (const [name, value] of Object.entries(forwardedCookies)) {\n request.headers.append('cookie', cookieUtils.serialize(name, value))\n }\n\n return {\n ...forwardedCookies,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,qBAAsB;AAEtB,SAAS,wBAAwB;AAC/B,SAAO,cAAAA,QAAY,MAAM,SAAS,MAAM;AAC1C;AAMO,SAAS,kBAAkB,SAA0C;AAI1E,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAI/B,aAAO,SAAS,WAAW,IAAI,SAAS,sBAAsB,IAAI,CAAC;AAAA,IACrE;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAvC/E;AAwCE,QAAM,uBAAuB,QAAQ,QAAQ,IAAI,QAAQ;AACzD,QAAM,qBAAqB,uBACvB,cAAAA,QAAY,MAAM,oBAAoB,IACtC,CAAC;AAEL,uBAAM,QAAQ;AAEd,QAAM,mBAAmB,MAAM,MAAK,0BAAM,IAAI,OAAO,MAAjB,mBAAoB,SAAS,EAAE,OAEjE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM;AAChC,WAAO,OAAO,OAAO,SAAS,EAAE,CAAC,KAAK,KAAK,CAAC,GAAG,MAAM,CAAC;AAAA,EACxD,GAAG,CAAC,CAAC;AAEL,QAAM,sBAAsB,kBAAkB,OAAO;AAErD,QAAM,mBAAmB,kCACpB,sBACA;AASL,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,gBAAgB,GAAG;AAC5D,YAAQ,QAAQ,OAAO,UAAU,cAAAA,QAAY,UAAU,MAAM,KAAK,CAAC;AAAA,EACrE;AAEA,SAAO,kCACF,mBACA;AAEP;","names":["cookieUtils"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { store } from '@mswjs/cookies'\n\nfunction getAllDocumentCookies() {\n return cookieUtils.parse(document.cookie)\n}\n\n/** @todo Rename this to \"getDocumentCookies\" */\n/**\n * Returns relevant document cookies based on the request `credentials` option.\n */\nexport function getRequestCookies(request: Request): Record<string, string> {\n /**\n * @note No cookies persist on the document in Node.js: no document.\n */\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const url = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === url.origin ? getAllDocumentCookies() : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record<string, string> {\n const requestCookiesString = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookiesString\n ? cookieUtils.parse(requestCookiesString)\n : {}\n\n store.hydrate()\n\n const cookiesFromStore = Array.from(store.get(request)?.entries()).reduce<\n Record<string, string>\n >((cookies, [name, { value }]) => {\n return Object.assign(cookies, { [name.trim()]: value })\n }, {})\n\n const cookiesFromDocument = getRequestCookies(request)\n\n const forwardedCookies = {\n ...cookiesFromDocument,\n ...cookiesFromStore,\n }\n\n // Set the inferred cookies from the cookie store and the document\n // on the request's headers.\n /**\n * @todo Consider making this a separate step so this function\n * is pure-er.\n */\n for (const [name, value] of Object.entries(forwardedCookies)) {\n request.headers.append('cookie', cookieUtils.serialize(name, value))\n }\n\n return {\n ...forwardedCookies,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAO,iBAAiB;AACxB,SAAS,aAAa;AAEtB,SAAS,wBAAwB;AAC/B,SAAO,YAAY,MAAM,SAAS,MAAM;AAC1C;AAMO,SAAS,kBAAkB,SAA0C;AAI1E,MAAI,OAAO,aAAa,eAAe,OAAO,aAAa,aAAa;AACtE,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,QAAQ,aAAa;AAAA,IAC3B,KAAK,eAAe;AAClB,YAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAI/B,aAAO,SAAS,WAAW,IAAI,SAAS,sBAAsB,IAAI,CAAC;AAAA,IACrE;AAAA,IAEA,KAAK,WAAW;AAEd,aAAO,sBAAsB;AAAA,IAC/B;AAAA,IAEA,SAAS;AACP,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,SAA0C;AAvC/E;AAwCE,QAAM,uBAAuB,QAAQ,QAAQ,IAAI,QAAQ;AACzD,QAAM,qBAAqB,uBACvB,YAAY,MAAM,oBAAoB,IACtC,CAAC;AAEL,QAAM,QAAQ;AAEd,QAAM,mBAAmB,MAAM,MAAK,WAAM,IAAI,OAAO,MAAjB,mBAAoB,SAAS,EAAE,OAEjE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM;AAChC,WAAO,OAAO,OAAO,SAAS,EAAE,CAAC,KAAK,KAAK,CAAC,GAAG,MAAM,CAAC;AAAA,EACxD,GAAG,CAAC,CAAC;AAEL,QAAM,sBAAsB,kBAAkB,OAAO;AAErD,QAAM,mBAAmB,kCACpB,sBACA;AASL,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,gBAAgB,GAAG;AAC5D,YAAQ,QAAQ,OAAO,UAAU,YAAY,UAAU,MAAM,KAAK,CAAC;AAAA,EACrE;AAEA,SAAO,kCACF,mBACA;AAEP;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { R as RequestHandler } from '../../RequestHandler-vxZdj6Tw.mjs';
|
|
2
|
+
import '../../typeUtils.mjs';
|
|
3
|
+
|
|
4
|
+
interface UnhandledRequestPrint {
|
|
5
|
+
warning(): void;
|
|
6
|
+
error(): void;
|
|
7
|
+
}
|
|
8
|
+
type UnhandledRequestCallback = (request: Request, print: UnhandledRequestPrint) => void;
|
|
9
|
+
type UnhandledRequestStrategy = 'bypass' | 'warn' | 'error' | UnhandledRequestCallback;
|
|
10
|
+
declare function onUnhandledRequest(request: Request, handlers: Array<RequestHandler>, strategy?: UnhandledRequestStrategy): Promise<void>;
|
|
11
|
+
|
|
12
|
+
export { type UnhandledRequestCallback, type UnhandledRequestPrint, type UnhandledRequestStrategy, onUnhandledRequest };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler } from '../../RequestHandler-
|
|
1
|
+
import { R as RequestHandler } from '../../RequestHandler-rBDJQrEf.js';
|
|
2
2
|
import '../../typeUtils.js';
|
|
3
3
|
|
|
4
4
|
interface UnhandledRequestPrint {
|
|
@@ -9,4 +9,4 @@ type UnhandledRequestCallback = (request: Request, print: UnhandledRequestPrint)
|
|
|
9
9
|
type UnhandledRequestStrategy = 'bypass' | 'warn' | 'error' | UnhandledRequestCallback;
|
|
10
10
|
declare function onUnhandledRequest(request: Request, handlers: Array<RequestHandler>, strategy?: UnhandledRequestStrategy): Promise<void>;
|
|
11
11
|
|
|
12
|
-
export { UnhandledRequestCallback, UnhandledRequestPrint, UnhandledRequestStrategy, onUnhandledRequest };
|
|
12
|
+
export { type UnhandledRequestCallback, type UnhandledRequestPrint, type UnhandledRequestStrategy, onUnhandledRequest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/onUnhandledRequest.ts"],"sourcesContent":["import jsLevenshtein from '@bundled-es-modules/js-levenshtein'\nimport { RequestHandler, HttpHandler, GraphQLHandler } from '../..'\nimport {\n ParsedGraphQLQuery,\n ParsedGraphQLRequest,\n parseGraphQLRequest,\n} from '../internal/parseGraphQLRequest'\nimport { getPublicUrlFromRequest } from './getPublicUrlFromRequest'\nimport { isStringEqual } from '../internal/isStringEqual'\nimport { devUtils } from '../internal/devUtils'\n\nconst getStringMatchScore = jsLevenshtein\n\nconst MAX_MATCH_SCORE = 3\nconst MAX_SUGGESTION_COUNT = 4\nconst TYPE_MATCH_DELTA = 0.5\n\nexport interface UnhandledRequestPrint {\n warning(): void\n error(): void\n}\n\nexport type UnhandledRequestCallback = (\n request: Request,\n print: UnhandledRequestPrint,\n) => void\n\nexport type UnhandledRequestStrategy =\n | 'bypass'\n | 'warn'\n | 'error'\n | UnhandledRequestCallback\n\ninterface RequestHandlerGroups {\n http: Array<HttpHandler>\n graphql: Array<GraphQLHandler>\n}\n\nfunction groupHandlersByType(\n handlers: Array<RequestHandler>,\n): RequestHandlerGroups {\n return handlers.reduce<RequestHandlerGroups>(\n (groups, handler) => {\n if (handler instanceof HttpHandler) {\n groups.http.push(handler)\n }\n\n if (handler instanceof GraphQLHandler) {\n groups.graphql.push(handler)\n }\n\n return groups\n },\n {\n http: [],\n graphql: [],\n },\n )\n}\n\ntype RequestHandlerSuggestion = [number, RequestHandler]\n\ntype ScoreGetterFn<RequestHandlerType extends RequestHandler> = (\n request: Request,\n handler: RequestHandlerType,\n) => number\n\nfunction getHttpHandlerScore(): ScoreGetterFn<HttpHandler> {\n return (request, handler) => {\n const { path, method } = handler.info\n\n if (path instanceof RegExp || method instanceof RegExp) {\n return Infinity\n }\n\n const hasSameMethod = isStringEqual(request.method, method)\n\n // Always treat a handler with the same method as a more similar one.\n const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0\n const requestPublicUrl = getPublicUrlFromRequest(request)\n const score = getStringMatchScore(requestPublicUrl, path)\n\n return score - methodScoreDelta\n }\n}\n\nfunction getGraphQLHandlerScore(\n parsedQuery: ParsedGraphQLQuery,\n): ScoreGetterFn<GraphQLHandler> {\n return (_, handler) => {\n if (typeof parsedQuery.operationName === 'undefined') {\n return Infinity\n }\n\n const { operationType, operationName } = handler.info\n\n if (typeof operationName !== 'string') {\n return Infinity\n }\n\n const hasSameOperationType = parsedQuery.operationType === operationType\n // Always treat a handler with the same operation type as a more similar one.\n const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0\n const score = getStringMatchScore(parsedQuery.operationName, operationName)\n\n return score - operationTypeScoreDelta\n }\n}\n\nfunction getSuggestedHandler(\n request: Request,\n handlers: Array<HttpHandler> | Array<GraphQLHandler>,\n getScore: ScoreGetterFn<HttpHandler> | ScoreGetterFn<GraphQLHandler>,\n): Array<RequestHandler> {\n const suggestedHandlers = (handlers as Array<RequestHandler>)\n .reduce<Array<RequestHandlerSuggestion>>((suggestions, handler) => {\n const score = getScore(request, handler as any)\n return suggestions.concat([[score, handler]])\n }, [])\n .sort(([leftScore], [rightScore]) => leftScore - rightScore)\n .filter(([score]) => score <= MAX_MATCH_SCORE)\n .slice(0, MAX_SUGGESTION_COUNT)\n .map(([, handler]) => handler)\n\n return suggestedHandlers\n}\n\nfunction getSuggestedHandlersMessage(handlers: RequestHandler[]) {\n if (handlers.length > 1) {\n return `\\\nDid you mean to request one of the following resources instead?\n\n${handlers.map((handler) => ` • ${handler.info.header}`).join('\\n')}`\n }\n\n return `Did you mean to request \"${handlers[0].info.header}\" instead?`\n}\n\nexport async function onUnhandledRequest(\n request: Request,\n handlers: Array<RequestHandler>,\n strategy: UnhandledRequestStrategy = 'warn',\n): Promise<void> {\n const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(\n () => null,\n )\n const publicUrl = getPublicUrlFromRequest(request)\n\n function generateHandlerSuggestion(): string {\n /**\n * @note Ignore exceptions during GraphQL request parsing because at this point\n * we cannot assume the unhandled request is a valid GraphQL request.\n * If the GraphQL parsing fails, just don't treat it as a GraphQL request.\n */\n const handlerGroups = groupHandlersByType(handlers)\n const relevantHandlers = parsedGraphQLQuery\n ? handlerGroups.graphql\n : handlerGroups.http\n\n const suggestedHandlers = getSuggestedHandler(\n request,\n relevantHandlers,\n parsedGraphQLQuery\n ? getGraphQLHandlerScore(parsedGraphQLQuery)\n : getHttpHandlerScore(),\n )\n\n return suggestedHandlers.length > 0\n ? getSuggestedHandlersMessage(suggestedHandlers)\n : ''\n }\n\n function getGraphQLRequestHeader(\n parsedGraphQLRequest: ParsedGraphQLRequest<any>,\n ): string {\n if (!parsedGraphQLRequest?.operationName) {\n return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`\n }\n\n return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`\n }\n\n function generateUnhandledRequestMessage(): string {\n const requestHeader = parsedGraphQLQuery\n ? getGraphQLRequestHeader(parsedGraphQLQuery)\n : `${request.method} ${publicUrl}`\n const handlerSuggestion = generateHandlerSuggestion()\n\n const messageTemplate = [\n `intercepted a request without a matching request handler:`,\n ` \\u2022 ${requestHeader}`,\n handlerSuggestion,\n `\\\nIf you still wish to intercept this unhandled request, please create a request handler for it.\nRead more: https://mswjs.io/docs/getting-started/mocks\\\n`,\n ].filter(Boolean)\n return messageTemplate.join('\\n\\n')\n }\n\n function applyStrategy(strategy: UnhandledRequestStrategy) {\n // Generate handler suggestions only when applying the strategy.\n // This saves bandwidth for scenarios when developers opt-out\n // from the default unhandled request handling strategy.\n const message = generateUnhandledRequestMessage()\n\n switch (strategy) {\n case 'error': {\n // Print a developer-friendly error.\n devUtils.error('Error: %s', message)\n\n // Throw an exception to halt request processing and not perform the original request.\n throw new Error(\n devUtils.formatMessage(\n 'Cannot bypass a request when using the \"error\" strategy for the \"onUnhandledRequest\" option.',\n ),\n )\n }\n\n case 'warn': {\n devUtils.warn('Warning: %s', message)\n break\n }\n\n case 'bypass':\n break\n\n default:\n throw new Error(\n devUtils.formatMessage(\n 'Failed to react to an unhandled request: unknown strategy \"%s\". Please provide one of the supported strategies (\"bypass\", \"warn\", \"error\") or a custom callback function as the value of the \"onUnhandledRequest\" option.',\n strategy,\n ),\n )\n }\n }\n\n if (typeof strategy === 'function') {\n strategy(request, {\n warning: applyStrategy.bind(null, 'warn'),\n error: applyStrategy.bind(null, 'error'),\n })\n return\n }\n\n applyStrategy(strategy)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA0B;AAC1B,eAA4D;AAC5D,iCAIO;AACP,qCAAwC;AACxC,2BAA8B;AAC9B,sBAAyB;AAEzB,MAAM,sBAAsB,sBAAAA;AAE5B,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AAuBzB,SAAS,oBACP,UACsB;AACtB,SAAO,SAAS;AAAA,IACd,CAAC,QAAQ,YAAY;AACnB,UAAI,mBAAmB,sBAAa;AAClC,eAAO,KAAK,KAAK,OAAO;AAAA,MAC1B;AAEA,UAAI,mBAAmB,yBAAgB;AACrC,eAAO,QAAQ,KAAK,OAAO;AAAA,MAC7B;AAEA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,MAAM,CAAC;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,EACF;AACF;AASA,SAAS,sBAAkD;AACzD,SAAO,CAAC,SAAS,YAAY;AAC3B,UAAM,EAAE,MAAM,OAAO,IAAI,QAAQ;AAEjC,QAAI,gBAAgB,UAAU,kBAAkB,QAAQ;AACtD,aAAO;AAAA,IACT;AAEA,UAAM,oBAAgB,oCAAc,QAAQ,QAAQ,MAAM;AAG1D,UAAM,mBAAmB,gBAAgB,mBAAmB;AAC5D,UAAM,uBAAmB,wDAAwB,OAAO;AACxD,UAAM,QAAQ,oBAAoB,kBAAkB,IAAI;AAExD,WAAO,QAAQ;AAAA,E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,eAAS,SAAS;AAAA,QAChB,SAAS,cAAc,KAAK,MAAM,MAAM;AAAA,QACxC,OAAO,cAAc,KAAK,MAAM,OAAO;AAAA,MACzC,CAAC;AACD;AAAA,IACF;AAEA,kBAAc,QAAQ;AAAA,EACxB;AAAA;","names":["jsLevenshtein","strategy"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/onUnhandledRequest.ts"],"sourcesContent":["import jsLevenshtein from '@bundled-es-modules/js-levenshtein'\nimport { RequestHandler, HttpHandler, GraphQLHandler } from '../..'\nimport {\n ParsedGraphQLQuery,\n ParsedGraphQLRequest,\n parseGraphQLRequest,\n} from '../internal/parseGraphQLRequest'\nimport { getPublicUrlFromRequest } from './getPublicUrlFromRequest'\nimport { isStringEqual } from '../internal/isStringEqual'\nimport { devUtils } from '../internal/devUtils'\n\nconst getStringMatchScore = jsLevenshtein\n\nconst MAX_MATCH_SCORE = 3\nconst MAX_SUGGESTION_COUNT = 4\nconst TYPE_MATCH_DELTA = 0.5\n\nexport interface UnhandledRequestPrint {\n warning(): void\n error(): void\n}\n\nexport type UnhandledRequestCallback = (\n request: Request,\n print: UnhandledRequestPrint,\n) => void\n\nexport type UnhandledRequestStrategy =\n | 'bypass'\n | 'warn'\n | 'error'\n | UnhandledRequestCallback\n\ninterface RequestHandlerGroups {\n http: Array<HttpHandler>\n graphql: Array<GraphQLHandler>\n}\n\nfunction groupHandlersByType(\n handlers: Array<RequestHandler>,\n): RequestHandlerGroups {\n return handlers.reduce<RequestHandlerGroups>(\n (groups, handler) => {\n if (handler instanceof HttpHandler) {\n groups.http.push(handler)\n }\n\n if (handler instanceof GraphQLHandler) {\n groups.graphql.push(handler)\n }\n\n return groups\n },\n {\n http: [],\n graphql: [],\n },\n )\n}\n\ntype RequestHandlerSuggestion = [number, RequestHandler]\n\ntype ScoreGetterFn<RequestHandlerType extends RequestHandler> = (\n request: Request,\n handler: RequestHandlerType,\n) => number\n\nfunction getHttpHandlerScore(): ScoreGetterFn<HttpHandler> {\n return (request, handler) => {\n const { path, method } = handler.info\n\n if (path instanceof RegExp || method instanceof RegExp) {\n return Infinity\n }\n\n const hasSameMethod = isStringEqual(request.method, method)\n\n // Always treat a handler with the same method as a more similar one.\n const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0\n const requestPublicUrl = getPublicUrlFromRequest(request)\n const score = getStringMatchScore(requestPublicUrl, path)\n\n return score - methodScoreDelta\n }\n}\n\nfunction getGraphQLHandlerScore(\n parsedQuery: ParsedGraphQLQuery,\n): ScoreGetterFn<GraphQLHandler> {\n return (_, handler) => {\n if (typeof parsedQuery.operationName === 'undefined') {\n return Infinity\n }\n\n const { operationType, operationName } = handler.info\n\n if (typeof operationName !== 'string') {\n return Infinity\n }\n\n const hasSameOperationType = parsedQuery.operationType === operationType\n // Always treat a handler with the same operation type as a more similar one.\n const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0\n const score = getStringMatchScore(parsedQuery.operationName, operationName)\n\n return score - operationTypeScoreDelta\n }\n}\n\nfunction getSuggestedHandler(\n request: Request,\n handlers: Array<HttpHandler> | Array<GraphQLHandler>,\n getScore: ScoreGetterFn<HttpHandler> | ScoreGetterFn<GraphQLHandler>,\n): Array<RequestHandler> {\n const suggestedHandlers = (handlers as Array<RequestHandler>)\n .reduce<Array<RequestHandlerSuggestion>>((suggestions, handler) => {\n const score = getScore(request, handler as any)\n return suggestions.concat([[score, handler]])\n }, [])\n .sort(([leftScore], [rightScore]) => leftScore - rightScore)\n .filter(([score]) => score <= MAX_MATCH_SCORE)\n .slice(0, MAX_SUGGESTION_COUNT)\n .map(([, handler]) => handler)\n\n return suggestedHandlers\n}\n\nfunction getSuggestedHandlersMessage(handlers: RequestHandler[]) {\n if (handlers.length > 1) {\n return `\\\nDid you mean to request one of the following resources instead?\n\n${handlers.map((handler) => ` • ${handler.info.header}`).join('\\n')}`\n }\n\n return `Did you mean to request \"${handlers[0].info.header}\" instead?`\n}\n\nexport async function onUnhandledRequest(\n request: Request,\n handlers: Array<RequestHandler>,\n strategy: UnhandledRequestStrategy = 'warn',\n): Promise<void> {\n const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(\n () => null,\n )\n const publicUrl = getPublicUrlFromRequest(request)\n\n function generateHandlerSuggestion(): string {\n /**\n * @note Ignore exceptions during GraphQL request parsing because at this point\n * we cannot assume the unhandled request is a valid GraphQL request.\n * If the GraphQL parsing fails, just don't treat it as a GraphQL request.\n */\n const handlerGroups = groupHandlersByType(handlers)\n const relevantHandlers = parsedGraphQLQuery\n ? handlerGroups.graphql\n : handlerGroups.http\n\n const suggestedHandlers = getSuggestedHandler(\n request,\n relevantHandlers,\n parsedGraphQLQuery\n ? getGraphQLHandlerScore(parsedGraphQLQuery)\n : getHttpHandlerScore(),\n )\n\n return suggestedHandlers.length > 0\n ? getSuggestedHandlersMessage(suggestedHandlers)\n : ''\n }\n\n function getGraphQLRequestHeader(\n parsedGraphQLRequest: ParsedGraphQLRequest<any>,\n ): string {\n if (!parsedGraphQLRequest?.operationName) {\n return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`\n }\n\n return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`\n }\n\n function generateUnhandledRequestMessage(): string {\n const requestHeader = parsedGraphQLQuery\n ? getGraphQLRequestHeader(parsedGraphQLQuery)\n : `${request.method} ${publicUrl}`\n const handlerSuggestion = generateHandlerSuggestion()\n\n const messageTemplate = [\n `intercepted a request without a matching request handler:`,\n ` \\u2022 ${requestHeader}`,\n handlerSuggestion,\n `\\\nIf you still wish to intercept this unhandled request, please create a request handler for it.\nRead more: https://mswjs.io/docs/getting-started/mocks\\\n`,\n ].filter(Boolean)\n return messageTemplate.join('\\n\\n')\n }\n\n function applyStrategy(strategy: UnhandledRequestStrategy) {\n // Generate handler suggestions only when applying the strategy.\n // This saves bandwidth for scenarios when developers opt-out\n // from the default unhandled request handling strategy.\n const message = generateUnhandledRequestMessage()\n\n switch (strategy) {\n case 'error': {\n // Print a developer-friendly error.\n devUtils.error('Error: %s', message)\n\n // Throw an exception to halt request processing and not perform the original request.\n throw new Error(\n devUtils.formatMessage(\n 'Cannot bypass a request when using the \"error\" strategy for the \"onUnhandledRequest\" option.',\n ),\n )\n }\n\n case 'warn': {\n devUtils.warn('Warning: %s', message)\n break\n }\n\n case 'bypass':\n break\n\n default:\n throw new Error(\n devUtils.formatMessage(\n 'Failed to react to an unhandled request: unknown strategy \"%s\". Please provide one of the supported strategies (\"bypass\", \"warn\", \"error\") or a custom callback function as the value of the \"onUnhandledRequest\" option.',\n strategy,\n ),\n )\n }\n }\n\n if (typeof strategy === 'function') {\n strategy(request, {\n warning: applyStrategy.bind(null, 'warn'),\n error: applyStrategy.bind(null, 'error'),\n })\n return\n }\n\n applyStrategy(strategy)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,mBAAmB;AAC1B,SAAyB,aAAa,sBAAsB;AAC5D;AAAA,EAGE;AAAA,OACK;AACP,SAAS,+BAA+B;AACxC,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAEzB,MAAM,sBAAsB;AAE5B,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AAuBzB,SAAS,oBACP,UACsB;AACtB,SAAO,SAAS;AAAA,IACd,CAAC,QAAQ,YAAY;AACnB,UAAI,mBAAmB,aAAa;AAClC,eAAO,KAAK,KAAK,OAAO;AAAA,MAC1B;AAEA,UAAI,mBAAmB,gBAAgB;AACrC,eAAO,QAAQ,KAAK,OAAO;AAAA,MAC7B;AAEA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,MAAM,CAAC;AAAA,MACP,SAAS,CAAC;AAAA,IACZ;AAAA,EACF;AACF;AASA,SAAS,sBAAkD;AACzD,SAAO,CAAC,SAAS,YAAY;AAC3B,UAAM,EAAE,MAAM,OAAO,IAAI,QAAQ;AAEjC,QAA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AA,QAEA,KAAK,QAAQ;AACX,mBAAS,KAAK,eAAe,OAAO;AACpC;AAAA,QACF;AAAA,QAEA,KAAK;AACH;AAAA,QAEF;AACE,gBAAM,IAAI;AAAA,YACR,SAAS;AAAA,cACP;AAAA,cACAA;AAAA,YACF;AAAA,UACF;AAAA,MACJ;AAAA,IACF;AAEA,QAAI,OAAO,aAAa,YAAY;AAClC,eAAS,SAAS;AAAA,QAChB,SAAS,cAAc,KAAK,MAAM,MAAM;AAAA,QACxC,OAAO,cAAc,KAAK,MAAM,OAAO;AAAA,MACzC,CAAC;AACD;AAAA,IACF;AAEA,kBAAc,QAAQ;AAAA,EACxB;AAAA;","names":["strategy"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/readResponseCookies.ts"],"sourcesContent":["import { store } from '@mswjs/cookies'\n\nexport function readResponseCookies(\n request: Request,\n response: Response,\n): void {\n store.add({ ...request, url: request.url.toString() }, response)\n store.persist()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsB;AAEf,SAAS,oBACd,SACA,UACM;AACN,uBAAM,IAAI,iCAAK,UAAL,EAAc,KAAK,QAAQ,IAAI,SAAS,EAAE,IAAG,QAAQ;AAC/D,uBAAM,QAAQ;AAChB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/readResponseCookies.ts"],"sourcesContent":["import { store } from '@mswjs/cookies'\n\nexport function readResponseCookies(\n request: Request,\n response: Response,\n): void {\n store.add({ ...request, url: request.url.toString() }, response)\n store.persist()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAEf,SAAS,oBACd,SACA,UACM;AACN,QAAM,IAAI,iCAAK,UAAL,EAAc,KAAK,QAAQ,IAAI,SAAS,EAAE,IAAG,QAAQ;AAC/D,QAAM,QAAQ;AAChB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/toResponseInit.ts"],"sourcesContent":["export function toResponseInit(response: Response): ResponseInit {\n return {\n status: response.status,\n statusText: response.statusText,\n headers: Object.fromEntries(response.headers.entries()),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,eAAe,UAAkC;AAC/D,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS;AAAA,IACrB,SAAS,OAAO,YAAY,SAAS,QAAQ,QAAQ,CAAC;AAAA,EACxD;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/toResponseInit.ts"],"sourcesContent":["export function toResponseInit(response: Response): ResponseInit {\n return {\n status: response.status,\n statusText: response.statusText,\n headers: Object.fromEntries(response.headers.entries()),\n }\n}\n"],"mappings":"AAAO,SAAS,eAAe,UAAkC;AAC/D,SAAO;AAAA,IACL,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS;AAAA,IACrB,SAAS,OAAO,YAAY,SAAS,QAAQ,QAAQ,CAAC;AAAA,EACxD;AACF;","names":[]}
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/url/getAbsoluteUrl.ts"],"sourcesContent":["import { isAbsoluteUrl } from './isAbsoluteUrl'\n\n/**\n * Returns an absolute URL based on the given path.\n */\nexport function getAbsoluteUrl(path: string, baseUrl?: string): string {\n // already absolute URL\n if (isAbsoluteUrl(path)) {\n return path\n }\n\n // Ignore path with pattern start with *\n if (path.startsWith('*')) {\n return path\n }\n\n // Resolve a relative request URL against a given custom \"baseUrl\"\n // or the document baseURI (in the case of browser/browser-like environments).\n const origin =\n baseUrl || (typeof document !== 'undefined' && document.baseURI)\n\n return origin\n ? // Encode and decode the path to preserve escaped characters.\n decodeURI(new URL(encodeURI(path), origin).href)\n : path\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAKvB,SAAS,eAAe,MAAc,SAA0B;AAErE,UAAI,oCAAc,IAAI,GAAG;AACvB,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,WAAW,GAAG,GAAG;AACxB,WAAO;AAAA,EACT;AAIA,QAAM,SACJ,WAAY,OAAO,aAAa,eAAe,SAAS;AAE1D,SAAO;AAAA;AAAA,IAEH,UAAU,IAAI,IAAI,UAAU,IAAI,GAAG,MAAM,EAAE,IAAI;AAAA,MAC/C;AACN;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/url/getAbsoluteUrl.ts"],"sourcesContent":["import { isAbsoluteUrl } from './isAbsoluteUrl'\n\n/**\n * Returns an absolute URL based on the given path.\n */\nexport function getAbsoluteUrl(path: string, baseUrl?: string): string {\n // already absolute URL\n if (isAbsoluteUrl(path)) {\n return path\n }\n\n // Ignore path with pattern start with *\n if (path.startsWith('*')) {\n return path\n }\n\n // Resolve a relative request URL against a given custom \"baseUrl\"\n // or the document baseURI (in the case of browser/browser-like environments).\n const origin =\n baseUrl || (typeof document !== 'undefined' && document.baseURI)\n\n return origin\n ? // Encode and decode the path to preserve escaped characters.\n decodeURI(new URL(encodeURI(path), origin).href)\n : path\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAKvB,SAAS,eAAe,MAAc,SAA0B;AAErE,MAAI,cAAc,IAAI,GAAG;AACvB,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,WAAW,GAAG,GAAG;AACxB,WAAO;AAAA,EACT;AAIA,QAAM,SACJ,WAAY,OAAO,aAAa,eAAe,SAAS;AAE1D,SAAO;AAAA;AAAA,IAEH,UAAU,IAAI,IAAI,UAAU,IAAI,GAAG,MAAM,EAAE,IAAI;AAAA,MAC/C;AACN;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/url/isAbsoluteUrl.ts"],"sourcesContent":["/**\n * Determines if the given URL string is an absolute URL.\n */\nexport function isAbsoluteUrl(url: string): boolean {\n return /^([a-z][a-z\\d\\+\\-\\.]*:)?\\/\\//i.test(url)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,cAAc,KAAsB;AAClD,SAAO,gCAAgC,KAAK,GAAG;AACjD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/url/isAbsoluteUrl.ts"],"sourcesContent":["/**\n * Determines if the given URL string is an absolute URL.\n */\nexport function isAbsoluteUrl(url: string): boolean {\n return /^([a-z][a-z\\d\\+\\-\\.]*:)?\\/\\//i.test(url)\n}\n"],"mappings":"AAGO,SAAS,cAAc,KAAsB;AAClD,SAAO,gCAAgC,KAAK,GAAG;AACjD;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -507,7 +507,7 @@ var MockServiceWorker = (() => {
|
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
// src/core/handlers/RequestHandler.ts
|
|
510
|
-
var
|
|
510
|
+
var _RequestHandler = class _RequestHandler {
|
|
511
511
|
constructor(args) {
|
|
512
512
|
this.resolver = args.resolver;
|
|
513
513
|
this.options = args.options;
|
|
@@ -549,6 +549,18 @@ var MockServiceWorker = (() => {
|
|
|
549
549
|
extendResolverArgs(_args) {
|
|
550
550
|
return {};
|
|
551
551
|
}
|
|
552
|
+
// Clone the request instance before it's passed to the handler phases
|
|
553
|
+
// and the response resolver so we can always read it for logging.
|
|
554
|
+
// We only clone it once per request to avoid unnecessary overhead.
|
|
555
|
+
cloneRequestOrGetFromCache(request) {
|
|
556
|
+
const existingClone = _RequestHandler.cache.get(request);
|
|
557
|
+
if (typeof existingClone !== "undefined") {
|
|
558
|
+
return existingClone;
|
|
559
|
+
}
|
|
560
|
+
const clonedRequest = request.clone();
|
|
561
|
+
_RequestHandler.cache.set(request, clonedRequest);
|
|
562
|
+
return clonedRequest;
|
|
563
|
+
}
|
|
552
564
|
/**
|
|
553
565
|
* Execute this request handler and produce a mocked response
|
|
554
566
|
* using the given resolver function.
|
|
@@ -559,7 +571,7 @@ var MockServiceWorker = (() => {
|
|
|
559
571
|
if (this.isUsed && ((_a3 = this.options) == null ? void 0 : _a3.once)) {
|
|
560
572
|
return null;
|
|
561
573
|
}
|
|
562
|
-
const
|
|
574
|
+
const requestClone = this.cloneRequestOrGetFromCache(args.request);
|
|
563
575
|
const parsedResult = yield this.parse({
|
|
564
576
|
request: args.request,
|
|
565
577
|
resolutionContext: args.resolutionContext
|
|
@@ -587,7 +599,7 @@ var MockServiceWorker = (() => {
|
|
|
587
599
|
const executionResult = this.createExecutionResult({
|
|
588
600
|
// Pass the cloned request to the result so that logging
|
|
589
601
|
// and other consumers could read its body once more.
|
|
590
|
-
request:
|
|
602
|
+
request: requestClone,
|
|
591
603
|
response: mockedResponse,
|
|
592
604
|
parsedResult
|
|
593
605
|
});
|
|
@@ -631,6 +643,8 @@ var MockServiceWorker = (() => {
|
|
|
631
643
|
};
|
|
632
644
|
}
|
|
633
645
|
};
|
|
646
|
+
_RequestHandler.cache = /* @__PURE__ */ new WeakMap();
|
|
647
|
+
var RequestHandler = _RequestHandler;
|
|
634
648
|
|
|
635
649
|
// src/core/utils/internal/isStringEqual.ts
|
|
636
650
|
function isStringEqual(actual, expected) {
|
|
@@ -1151,7 +1165,7 @@ var MockServiceWorker = (() => {
|
|
|
1151
1165
|
return stringToRegexp(path, keys, options);
|
|
1152
1166
|
}
|
|
1153
1167
|
|
|
1154
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
1168
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1155
1169
|
var encoder = new TextEncoder();
|
|
1156
1170
|
function encodeBuffer(text) {
|
|
1157
1171
|
return encoder.encode(text);
|
|
@@ -1630,7 +1644,7 @@ var MockServiceWorker = (() => {
|
|
|
1630
1644
|
var Emitter2 = _Emitter2;
|
|
1631
1645
|
Emitter2.defaultMaxListeners = 10;
|
|
1632
1646
|
|
|
1633
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
1647
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/chunk-WZQN3FMY.mjs
|
|
1634
1648
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1635
1649
|
function getGlobalSymbol(symbol) {
|
|
1636
1650
|
return (
|
|
@@ -1775,7 +1789,7 @@ var MockServiceWorker = (() => {
|
|
|
1775
1789
|
}
|
|
1776
1790
|
};
|
|
1777
1791
|
|
|
1778
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
1792
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1779
1793
|
var BatchInterceptor = class extends Interceptor {
|
|
1780
1794
|
constructor(options) {
|
|
1781
1795
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -2655,7 +2669,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2655
2669
|
}
|
|
2656
2670
|
return firstArg;
|
|
2657
2671
|
}
|
|
2658
|
-
var GraphQLError = class extends Error {
|
|
2672
|
+
var GraphQLError = class _GraphQLError extends Error {
|
|
2659
2673
|
/**
|
|
2660
2674
|
* An array of `{ line, column }` locations within the source GraphQL document
|
|
2661
2675
|
* which correspond to this error.
|
|
@@ -2742,7 +2756,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2742
2756
|
configurable: true
|
|
2743
2757
|
});
|
|
2744
2758
|
} else if (Error.captureStackTrace) {
|
|
2745
|
-
Error.captureStackTrace(this,
|
|
2759
|
+
Error.captureStackTrace(this, _GraphQLError);
|
|
2746
2760
|
} else {
|
|
2747
2761
|
Object.defineProperty(this, "stack", {
|
|
2748
2762
|
value: Error().stack,
|
|
@@ -5632,7 +5646,7 @@ spurious results.`);
|
|
|
5632
5646
|
}
|
|
5633
5647
|
return typeof value === "object" && "kind" in value && "definitions" in value;
|
|
5634
5648
|
}
|
|
5635
|
-
var
|
|
5649
|
+
var _GraphQLHandler = class _GraphQLHandler extends RequestHandler {
|
|
5636
5650
|
constructor(operationType, operationName, endpoint, resolver, options) {
|
|
5637
5651
|
let resolvedOperationName = operationName;
|
|
5638
5652
|
if (isDocumentNode(operationName)) {
|
|
@@ -5661,16 +5675,33 @@ spurious results.`);
|
|
|
5661
5675
|
});
|
|
5662
5676
|
this.endpoint = endpoint;
|
|
5663
5677
|
}
|
|
5678
|
+
/**
|
|
5679
|
+
* Parses the request body, once per request, cached across all
|
|
5680
|
+
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
5681
|
+
* request body, which each requires a clone of the request.
|
|
5682
|
+
*/
|
|
5683
|
+
parseGraphQLRequestOrGetFromCache(request) {
|
|
5684
|
+
return __async(this, null, function* () {
|
|
5685
|
+
if (!_GraphQLHandler.parsedRequestCache.has(request)) {
|
|
5686
|
+
_GraphQLHandler.parsedRequestCache.set(
|
|
5687
|
+
request,
|
|
5688
|
+
yield parseGraphQLRequest(request).catch((error3) => {
|
|
5689
|
+
console.error(error3);
|
|
5690
|
+
return void 0;
|
|
5691
|
+
})
|
|
5692
|
+
);
|
|
5693
|
+
}
|
|
5694
|
+
return _GraphQLHandler.parsedRequestCache.get(request);
|
|
5695
|
+
});
|
|
5696
|
+
}
|
|
5664
5697
|
parse(args) {
|
|
5665
5698
|
return __async(this, null, function* () {
|
|
5666
5699
|
const match2 = matchRequestUrl(new URL(args.request.url), this.endpoint);
|
|
5667
|
-
if (!match2.matches)
|
|
5700
|
+
if (!match2.matches) {
|
|
5668
5701
|
return { match: match2 };
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
return void 0;
|
|
5673
|
-
}
|
|
5702
|
+
}
|
|
5703
|
+
const parsedResult = yield this.parseGraphQLRequestOrGetFromCache(
|
|
5704
|
+
args.request
|
|
5674
5705
|
);
|
|
5675
5706
|
if (typeof parsedResult === "undefined") {
|
|
5676
5707
|
return { match: match2 };
|
|
@@ -5728,6 +5759,8 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5728
5759
|
});
|
|
5729
5760
|
}
|
|
5730
5761
|
};
|
|
5762
|
+
_GraphQLHandler.parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
5763
|
+
var GraphQLHandler = _GraphQLHandler;
|
|
5731
5764
|
|
|
5732
5765
|
// src/core/graphql.ts
|
|
5733
5766
|
function createScopedGraphQLHandler(operationType, url) {
|
|
@@ -5866,7 +5899,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5866
5899
|
var require_js_levenshtein = __commonJS5({
|
|
5867
5900
|
"node_modules/js-levenshtein/index.js"(exports, module) {
|
|
5868
5901
|
"use strict";
|
|
5869
|
-
module.exports = function() {
|
|
5902
|
+
module.exports = /* @__PURE__ */ function() {
|
|
5870
5903
|
function _min(d0, d1, d2, bx, ay) {
|
|
5871
5904
|
return d0 < d1 || d2 < d1 ? d0 > d2 ? d2 + 1 : d0 + 1 : bx === ay ? d1 : d1 + 1;
|
|
5872
5905
|
}
|
|
@@ -6180,7 +6213,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6180
6213
|
}
|
|
6181
6214
|
|
|
6182
6215
|
// src/core/HttpResponse.ts
|
|
6183
|
-
var HttpResponse = class extends Response {
|
|
6216
|
+
var HttpResponse = class _HttpResponse extends Response {
|
|
6184
6217
|
constructor(body, init) {
|
|
6185
6218
|
const responseInit = normalizeResponseInit(init);
|
|
6186
6219
|
super(body, responseInit);
|
|
@@ -6197,7 +6230,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6197
6230
|
if (!responseInit.headers.has("Content-Type")) {
|
|
6198
6231
|
responseInit.headers.set("Content-Type", "text/plain");
|
|
6199
6232
|
}
|
|
6200
|
-
return new
|
|
6233
|
+
return new _HttpResponse(body, responseInit);
|
|
6201
6234
|
}
|
|
6202
6235
|
/**
|
|
6203
6236
|
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
@@ -6210,7 +6243,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6210
6243
|
if (!responseInit.headers.has("Content-Type")) {
|
|
6211
6244
|
responseInit.headers.set("Content-Type", "application/json");
|
|
6212
6245
|
}
|
|
6213
|
-
return new
|
|
6246
|
+
return new _HttpResponse(
|
|
6214
6247
|
JSON.stringify(body),
|
|
6215
6248
|
responseInit
|
|
6216
6249
|
);
|
|
@@ -6226,7 +6259,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6226
6259
|
if (!responseInit.headers.has("Content-Type")) {
|
|
6227
6260
|
responseInit.headers.set("Content-Type", "text/xml");
|
|
6228
6261
|
}
|
|
6229
|
-
return new
|
|
6262
|
+
return new _HttpResponse(body, responseInit);
|
|
6230
6263
|
}
|
|
6231
6264
|
/**
|
|
6232
6265
|
* Create a `Response` with an `ArrayBuffer` body.
|
|
@@ -6242,7 +6275,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6242
6275
|
if (body) {
|
|
6243
6276
|
responseInit.headers.set("Content-Length", body.byteLength.toString());
|
|
6244
6277
|
}
|
|
6245
|
-
return new
|
|
6278
|
+
return new _HttpResponse(body, responseInit);
|
|
6246
6279
|
}
|
|
6247
6280
|
/**
|
|
6248
6281
|
* Create a `Response` with a `FormData` body.
|
|
@@ -6253,7 +6286,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
6253
6286
|
* HttpResponse.formData(data)
|
|
6254
6287
|
*/
|
|
6255
6288
|
static formData(body, init) {
|
|
6256
|
-
return new
|
|
6289
|
+
return new _HttpResponse(body, normalizeResponseInit(init));
|
|
6257
6290
|
}
|
|
6258
6291
|
};
|
|
6259
6292
|
|
|
@@ -6869,7 +6902,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6869
6902
|
});
|
|
6870
6903
|
}, _a2);
|
|
6871
6904
|
|
|
6872
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
6905
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/chunk-72HT65NX.mjs
|
|
6873
6906
|
function uuidv4() {
|
|
6874
6907
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
6875
6908
|
const r = Math.random() * 16 | 0;
|
|
@@ -6916,7 +6949,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6916
6949
|
});
|
|
6917
6950
|
}
|
|
6918
6951
|
|
|
6919
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
6952
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/chunk-KDHQ3KDO.mjs
|
|
6920
6953
|
function isPropertyAccessible2(obj, key) {
|
|
6921
6954
|
try {
|
|
6922
6955
|
obj[key];
|
|
@@ -7053,7 +7086,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7053
7086
|
});
|
|
7054
7087
|
}
|
|
7055
7088
|
|
|
7056
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.25.
|
|
7089
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.25.14/node_modules/@mswjs/interceptors/lib/browser/chunk-DZVB7JEV.mjs
|
|
7057
7090
|
function concatArrayBuffer(left, right) {
|
|
7058
7091
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
7059
7092
|
result.set(left, 0);
|
|
@@ -8032,3 +8065,4 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
8032
8065
|
*)
|
|
8033
8066
|
*)
|
|
8034
8067
|
*/
|
|
8068
|
+
//# sourceMappingURL=index.js.map
|