msw 2.10.4 → 2.11.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.
- package/lib/core/{HttpResponse-C7FhBLaS.d.mts → HttpResponse-DiuKTgC7.d.mts} +21 -7
- package/lib/core/{HttpResponse-DWu36LsY.d.ts → HttpResponse-DlQEvD4q.d.ts} +21 -7
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/graphql.js +2 -8
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +2 -8
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +36 -9
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +36 -9
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +15 -5
- package/lib/core/handlers/HttpHandler.d.ts +15 -5
- package/lib/core/handlers/HttpHandler.js +21 -10
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +21 -10
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +1 -1
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +1 -1
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +4 -4
- package/lib/core/http.d.ts +4 -4
- package/lib/core/http.js +2 -2
- package/lib/core/http.js.map +1 -1
- package/lib/core/http.mjs +2 -2
- package/lib/core/http.mjs.map +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/iife/index.js +62 -30
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/graphql.ts +8 -12
- package/src/core/handlers/GraphQLHandler.test.ts +86 -51
- package/src/core/handlers/GraphQLHandler.ts +81 -17
- package/src/core/handlers/HttpHandler.test.ts +60 -30
- package/src/core/handlers/HttpHandler.ts +61 -12
- package/src/core/handlers/RequestHandler.ts +2 -2
- package/src/core/http.ts +5 -5
- package/src/core/index.ts +4 -0
- package/src/core/utils/handleRequest.test.ts +84 -0
package/lib/core/http.js
CHANGED
|
@@ -23,8 +23,8 @@ __export(http_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(http_exports);
|
|
24
24
|
var import_HttpHandler = require("./handlers/HttpHandler");
|
|
25
25
|
function createHttpHandler(method) {
|
|
26
|
-
return (
|
|
27
|
-
return new import_HttpHandler.HttpHandler(method,
|
|
26
|
+
return (predicate, resolver, options = {}) => {
|
|
27
|
+
return new import_HttpHandler.HttpHandler(method, predicate, resolver, options);
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
const http = {
|
package/lib/core/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/http.ts"],"sourcesContent":["import {\n DefaultBodyType,\n RequestHandlerOptions,\n ResponseResolver,\n} from './handlers/RequestHandler'\nimport {\n HttpMethods,\n HttpHandler,\n HttpRequestResolverExtras,\n} from './handlers/HttpHandler'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/core/http.ts"],"sourcesContent":["import {\n DefaultBodyType,\n RequestHandlerOptions,\n ResponseResolver,\n} from './handlers/RequestHandler'\nimport {\n HttpMethods,\n HttpHandler,\n HttpRequestResolverExtras,\n HttpRequestPredicate,\n} from './handlers/HttpHandler'\nimport type { PathParams } from './utils/matching/matchRequestUrl'\n\nexport type HttpRequestHandler = <\n Params extends PathParams<keyof Params> = PathParams,\n RequestBodyType extends DefaultBodyType = DefaultBodyType,\n // Response body type MUST be undefined by default.\n // This is how we can distinguish between a handler that\n // returns plain \"Response\" and the one returning \"HttpResponse\"\n // to enforce a stricter response body type.\n ResponseBodyType extends DefaultBodyType = undefined,\n>(\n predicate: HttpRequestPredicate<Params>,\n resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>,\n options?: RequestHandlerOptions,\n) => HttpHandler\n\nexport type HttpResponseResolver<\n Params extends PathParams<keyof Params> = PathParams,\n RequestBodyType extends DefaultBodyType = DefaultBodyType,\n ResponseBodyType extends DefaultBodyType = DefaultBodyType,\n> = ResponseResolver<\n HttpRequestResolverExtras<Params>,\n RequestBodyType,\n ResponseBodyType\n>\n\nfunction createHttpHandler<Method extends HttpMethods | RegExp>(\n method: Method,\n): HttpRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new HttpHandler(method, predicate, resolver, options)\n }\n}\n\n/**\n * A namespace to intercept and mock HTTP requests.\n *\n * @example\n * http.get('/user', resolver)\n * http.post('/post/:id', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/http `http` API reference}\n */\nexport const http = {\n all: createHttpHandler(/.+/),\n head: createHttpHandler(HttpMethods.HEAD),\n get: createHttpHandler(HttpMethods.GET),\n post: createHttpHandler(HttpMethods.POST),\n put: createHttpHandler(HttpMethods.PUT),\n delete: createHttpHandler(HttpMethods.DELETE),\n patch: createHttpHandler(HttpMethods.PATCH),\n options: createHttpHandler(HttpMethods.OPTIONS),\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,yBAKO;AA2BP,SAAS,kBACP,QACoB;AACpB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,+BAAY,QAAQ,WAAW,UAAU,OAAO;AAAA,EAC7D;AACF;AAWO,MAAM,OAAO;AAAA,EAClB,KAAK,kBAAkB,IAAI;AAAA,EAC3B,MAAM,kBAAkB,+BAAY,IAAI;AAAA,EACxC,KAAK,kBAAkB,+BAAY,GAAG;AAAA,EACtC,MAAM,kBAAkB,+BAAY,IAAI;AAAA,EACxC,KAAK,kBAAkB,+BAAY,GAAG;AAAA,EACtC,QAAQ,kBAAkB,+BAAY,MAAM;AAAA,EAC5C,OAAO,kBAAkB,+BAAY,KAAK;AAAA,EAC1C,SAAS,kBAAkB,+BAAY,OAAO;AAChD;","names":[]}
|
package/lib/core/http.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
HttpHandler
|
|
4
4
|
} from './handlers/HttpHandler.mjs';
|
|
5
5
|
function createHttpHandler(method) {
|
|
6
|
-
return (
|
|
7
|
-
return new HttpHandler(method,
|
|
6
|
+
return (predicate, resolver, options = {}) => {
|
|
7
|
+
return new HttpHandler(method, predicate, resolver, options);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
const http = {
|
package/lib/core/http.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/http.ts"],"sourcesContent":["import {\n DefaultBodyType,\n RequestHandlerOptions,\n ResponseResolver,\n} from './handlers/RequestHandler'\nimport {\n HttpMethods,\n HttpHandler,\n HttpRequestResolverExtras,\n} from './handlers/HttpHandler'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/core/http.ts"],"sourcesContent":["import {\n DefaultBodyType,\n RequestHandlerOptions,\n ResponseResolver,\n} from './handlers/RequestHandler'\nimport {\n HttpMethods,\n HttpHandler,\n HttpRequestResolverExtras,\n HttpRequestPredicate,\n} from './handlers/HttpHandler'\nimport type { PathParams } from './utils/matching/matchRequestUrl'\n\nexport type HttpRequestHandler = <\n Params extends PathParams<keyof Params> = PathParams,\n RequestBodyType extends DefaultBodyType = DefaultBodyType,\n // Response body type MUST be undefined by default.\n // This is how we can distinguish between a handler that\n // returns plain \"Response\" and the one returning \"HttpResponse\"\n // to enforce a stricter response body type.\n ResponseBodyType extends DefaultBodyType = undefined,\n>(\n predicate: HttpRequestPredicate<Params>,\n resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>,\n options?: RequestHandlerOptions,\n) => HttpHandler\n\nexport type HttpResponseResolver<\n Params extends PathParams<keyof Params> = PathParams,\n RequestBodyType extends DefaultBodyType = DefaultBodyType,\n ResponseBodyType extends DefaultBodyType = DefaultBodyType,\n> = ResponseResolver<\n HttpRequestResolverExtras<Params>,\n RequestBodyType,\n ResponseBodyType\n>\n\nfunction createHttpHandler<Method extends HttpMethods | RegExp>(\n method: Method,\n): HttpRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new HttpHandler(method, predicate, resolver, options)\n }\n}\n\n/**\n * A namespace to intercept and mock HTTP requests.\n *\n * @example\n * http.get('/user', resolver)\n * http.post('/post/:id', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/http `http` API reference}\n */\nexport const http = {\n all: createHttpHandler(/.+/),\n head: createHttpHandler(HttpMethods.HEAD),\n get: createHttpHandler(HttpMethods.GET),\n post: createHttpHandler(HttpMethods.POST),\n put: createHttpHandler(HttpMethods.PUT),\n delete: createHttpHandler(HttpMethods.DELETE),\n patch: createHttpHandler(HttpMethods.PATCH),\n options: createHttpHandler(HttpMethods.OPTIONS),\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AA2BP,SAAS,kBACP,QACoB;AACpB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,YAAY,QAAQ,WAAW,UAAU,OAAO;AAAA,EAC7D;AACF;AAWO,MAAM,OAAO;AAAA,EAClB,KAAK,kBAAkB,IAAI;AAAA,EAC3B,MAAM,kBAAkB,YAAY,IAAI;AAAA,EACxC,KAAK,kBAAkB,YAAY,GAAG;AAAA,EACtC,MAAM,kBAAkB,YAAY,IAAI;AAAA,EACxC,KAAK,kBAAkB,YAAY,GAAG;AAAA,EACtC,QAAQ,kBAAkB,YAAY,MAAM;AAAA,EAC5C,OAAO,kBAAkB,YAAY,KAAK;AAAA,EAC1C,SAAS,kBAAkB,YAAY,OAAO;AAChD;","names":[]}
|
package/lib/core/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.mjs';
|
|
2
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody,
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DiuKTgC7.mjs';
|
|
3
3
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.mjs';
|
|
4
|
-
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.mjs';
|
|
4
|
+
export { HttpCustomPredicate, HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.mjs';
|
|
5
5
|
export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.mjs';
|
|
6
6
|
export { WebSocketEventListener, WebSocketLink, ws } from './ws.mjs';
|
|
7
7
|
export { WebSocketHandler, WebSocketHandlerConnection, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.mjs';
|
package/lib/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.js';
|
|
2
|
-
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody,
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, m as DefaultUnsafeFetchResponse, k as GraphQLCustomPredicate, G as GraphQLHandler, i as GraphQLJsonRequestBody, j as GraphQLOperationType, e as GraphQLQuery, g as GraphQLRequestBody, h as GraphQLResponseBody, f as GraphQLVariables, o as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, a as ResponseResolver, b as ResponseResolverReturnType, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-DlQEvD4q.js';
|
|
3
3
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
|
|
4
|
-
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
|
|
4
|
+
export { HttpCustomPredicate, HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
|
|
5
5
|
export { GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
|
|
6
6
|
export { WebSocketEventListener, WebSocketLink, ws } from './ws.js';
|
|
7
7
|
export { WebSocketHandler, WebSocketHandlerConnection, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.js';
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAIO;AAGP,6BAAgC;AAChC,0BAAc,kCArBd;AAsBA,yBAA4B;AAC5B,sBAAyB;
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAIO;AAGP,6BAAgC;AAChC,0BAAc,kCArBd;AAsBA,yBAA4B;AAC5B,sBAAyB;AAyCzB,0BAAc,2BAhEd;AAiEA,0BAAc,oBAjEd;AAkEA,oBAAuB;AACvB,yBAA4B;AAC5B,kCAAqC;AAAA,IAMrC,kCAAa;","names":[]}
|
package/lib/core/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLJsonRequestBody,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAGK;AAGP,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type { GraphQLRequestHandler, GraphQLResponseResolver } from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAGK;AAGP,SAAS,uBAAuB;AAChC,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAyCzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAMrC,aAAa;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { t as HandlersExecutionResult, p as ResponseResolutionContext, u as executeHandlers } from '../HttpResponse-DiuKTgC7.mjs';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './internal/isIterable.mjs';
|
|
4
4
|
import '../typeUtils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { t as HandlersExecutionResult, p as ResponseResolutionContext, u as executeHandlers } from '../HttpResponse-DlQEvD4q.js';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './internal/isIterable.js';
|
|
4
4
|
import '../typeUtils.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.mjs';
|
|
3
3
|
import { RequiredDeep } from '../typeUtils.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { t as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-DiuKTgC7.mjs';
|
|
5
5
|
import './request/onUnhandledRequest.mjs';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import './internal/isIterable.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
|
|
3
3
|
import { RequiredDeep } from '../typeUtils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { t as HandlersExecutionResult, R as RequestHandler } from '../HttpResponse-DlQEvD4q.js';
|
|
5
5
|
import './request/onUnhandledRequest.js';
|
|
6
6
|
import '@mswjs/interceptors';
|
|
7
7
|
import './internal/isIterable.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HandlerKind } from '../../handlers/common.mjs';
|
|
2
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-DiuKTgC7.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './isIterable.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HandlerKind } from '../../handlers/common.js';
|
|
2
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-DlQEvD4q.js';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './isIterable.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export {
|
|
2
|
+
export { y as GraphQLMultipartRequestBody, x as GraphQLParsedOperationsMap, v as ParsedGraphQLQuery, P as ParsedGraphQLRequest, w as parseDocumentNode, z as parseGraphQLRequest } from '../../HttpResponse-DiuKTgC7.mjs';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.mjs';
|
|
5
5
|
import '../../typeUtils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export {
|
|
2
|
+
export { y as GraphQLMultipartRequestBody, x as GraphQLParsedOperationsMap, v as ParsedGraphQLQuery, P as ParsedGraphQLRequest, w as parseDocumentNode, z as parseGraphQLRequest } from '../../HttpResponse-DlQEvD4q.js';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.js';
|
|
5
5
|
import '../../typeUtils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, s as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DiuKTgC7.mjs';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './isIterable.mjs';
|
|
4
4
|
import '../../typeUtils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, s as RequestHandlerDefaultInfo, c as RequestHandlerOptions } from '../../HttpResponse-DlQEvD4q.js';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './isIterable.js';
|
|
4
4
|
import '../../typeUtils.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-DiuKTgC7.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/lib/browser/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-DlQEvD4q.js';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
|
|
5
5
|
import '@mswjs/interceptors';
|
package/lib/iife/index.js
CHANGED
|
@@ -13641,7 +13641,7 @@ ${operationTypes.join("\n")}
|
|
|
13641
13641
|
request: args.request,
|
|
13642
13642
|
resolutionContext: args.resolutionContext
|
|
13643
13643
|
});
|
|
13644
|
-
const shouldInterceptRequest = this.predicate({
|
|
13644
|
+
const shouldInterceptRequest = await this.predicate({
|
|
13645
13645
|
request: args.request,
|
|
13646
13646
|
parsedResult,
|
|
13647
13647
|
resolutionContext: args.resolutionContext
|
|
@@ -27141,11 +27141,12 @@ ${operationTypes.join("\n")}
|
|
|
27141
27141
|
return HttpMethods2;
|
|
27142
27142
|
})(HttpMethods || {});
|
|
27143
27143
|
var HttpHandler = class extends RequestHandler {
|
|
27144
|
-
constructor(method,
|
|
27144
|
+
constructor(method, predicate, resolver, options) {
|
|
27145
|
+
const displayPath = typeof predicate === "function" ? "[custom predicate]" : predicate;
|
|
27145
27146
|
super({
|
|
27146
27147
|
info: {
|
|
27147
|
-
header: `${method} ${
|
|
27148
|
-
path,
|
|
27148
|
+
header: `${method}${displayPath ? ` ${displayPath}` : ""}`,
|
|
27149
|
+
path: predicate,
|
|
27149
27150
|
method
|
|
27150
27151
|
},
|
|
27151
27152
|
resolver,
|
|
@@ -27155,7 +27156,7 @@ ${operationTypes.join("\n")}
|
|
|
27155
27156
|
}
|
|
27156
27157
|
checkRedundantQueryParameters() {
|
|
27157
27158
|
const { method, path } = this.info;
|
|
27158
|
-
if (path instanceof RegExp) {
|
|
27159
|
+
if (!path || path instanceof RegExp || typeof path === "function") {
|
|
27159
27160
|
return;
|
|
27160
27161
|
}
|
|
27161
27162
|
const url = cleanUrl(path);
|
|
@@ -27173,18 +27174,28 @@ ${operationTypes.join("\n")}
|
|
|
27173
27174
|
}
|
|
27174
27175
|
async parse(args) {
|
|
27175
27176
|
const url = new URL(args.request.url);
|
|
27176
|
-
const match2 = matchRequestUrl(
|
|
27177
|
-
url,
|
|
27178
|
-
this.info.path,
|
|
27179
|
-
args.resolutionContext?.baseUrl
|
|
27180
|
-
);
|
|
27181
27177
|
const cookies = getAllRequestCookies(args.request);
|
|
27178
|
+
if (typeof this.info.path === "function") {
|
|
27179
|
+
const customPredicateResult = await this.info.path({
|
|
27180
|
+
request: args.request,
|
|
27181
|
+
cookies
|
|
27182
|
+
});
|
|
27183
|
+
const match3 = typeof customPredicateResult === "boolean" ? {
|
|
27184
|
+
matches: customPredicateResult,
|
|
27185
|
+
params: {}
|
|
27186
|
+
} : customPredicateResult;
|
|
27187
|
+
return {
|
|
27188
|
+
match: match3,
|
|
27189
|
+
cookies
|
|
27190
|
+
};
|
|
27191
|
+
}
|
|
27192
|
+
const match2 = this.info.path ? matchRequestUrl(url, this.info.path, args.resolutionContext?.baseUrl) : { matches: false, params: {} };
|
|
27182
27193
|
return {
|
|
27183
27194
|
match: match2,
|
|
27184
27195
|
cookies
|
|
27185
27196
|
};
|
|
27186
27197
|
}
|
|
27187
|
-
predicate(args) {
|
|
27198
|
+
async predicate(args) {
|
|
27188
27199
|
const hasMatchingMethod = this.matchMethod(args.request.method);
|
|
27189
27200
|
const hasMatchingUrl = args.parsedResult.match.matches;
|
|
27190
27201
|
return hasMatchingMethod && hasMatchingUrl;
|
|
@@ -27219,8 +27230,8 @@ ${operationTypes.join("\n")}
|
|
|
27219
27230
|
|
|
27220
27231
|
// src/core/http.ts
|
|
27221
27232
|
function createHttpHandler(method) {
|
|
27222
|
-
return (
|
|
27223
|
-
return new HttpHandler(method,
|
|
27233
|
+
return (predicate, resolver, options = {}) => {
|
|
27234
|
+
return new HttpHandler(method, predicate, resolver, options);
|
|
27224
27235
|
};
|
|
27225
27236
|
}
|
|
27226
27237
|
var http = {
|
|
@@ -27855,10 +27866,10 @@ ${operationTypes.join("\n")}
|
|
|
27855
27866
|
var GraphQLHandler = class _GraphQLHandler extends RequestHandler {
|
|
27856
27867
|
endpoint;
|
|
27857
27868
|
static parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
27858
|
-
constructor(operationType,
|
|
27859
|
-
let resolvedOperationName =
|
|
27860
|
-
if (isDocumentNode(
|
|
27861
|
-
const parsedNode = parseDocumentNode(
|
|
27869
|
+
constructor(operationType, predicate, endpoint, resolver, options) {
|
|
27870
|
+
let resolvedOperationName = predicate;
|
|
27871
|
+
if (isDocumentNode(resolvedOperationName)) {
|
|
27872
|
+
const parsedNode = parseDocumentNode(resolvedOperationName);
|
|
27862
27873
|
if (parsedNode.operationType !== operationType) {
|
|
27863
27874
|
throw new Error(
|
|
27864
27875
|
`Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "${operationType}", but got "${parsedNode.operationType}").`
|
|
@@ -27871,7 +27882,8 @@ ${operationTypes.join("\n")}
|
|
|
27871
27882
|
}
|
|
27872
27883
|
resolvedOperationName = parsedNode.operationName;
|
|
27873
27884
|
}
|
|
27874
|
-
const
|
|
27885
|
+
const displayOperationName = typeof resolvedOperationName === "function" ? "[custom predicate]" : resolvedOperationName;
|
|
27886
|
+
const header = operationType === "all" ? `${operationType} (origin: ${endpoint.toString()})` : `${operationType}${displayOperationName ? ` ${displayOperationName}` : ""} (origin: ${endpoint.toString()})`;
|
|
27875
27887
|
super({
|
|
27876
27888
|
info: {
|
|
27877
27889
|
header,
|
|
@@ -27904,13 +27916,19 @@ ${operationTypes.join("\n")}
|
|
|
27904
27916
|
const match2 = matchRequestUrl(new URL(args.request.url), this.endpoint);
|
|
27905
27917
|
const cookies = getAllRequestCookies(args.request);
|
|
27906
27918
|
if (!match2.matches) {
|
|
27907
|
-
return {
|
|
27919
|
+
return {
|
|
27920
|
+
match: match2,
|
|
27921
|
+
cookies
|
|
27922
|
+
};
|
|
27908
27923
|
}
|
|
27909
27924
|
const parsedResult = await this.parseGraphQLRequestOrGetFromCache(
|
|
27910
27925
|
args.request
|
|
27911
27926
|
);
|
|
27912
27927
|
if (typeof parsedResult === "undefined") {
|
|
27913
|
-
return {
|
|
27928
|
+
return {
|
|
27929
|
+
match: match2,
|
|
27930
|
+
cookies
|
|
27931
|
+
};
|
|
27914
27932
|
}
|
|
27915
27933
|
return {
|
|
27916
27934
|
match: match2,
|
|
@@ -27921,7 +27939,7 @@ ${operationTypes.join("\n")}
|
|
|
27921
27939
|
variables: parsedResult.variables
|
|
27922
27940
|
};
|
|
27923
27941
|
}
|
|
27924
|
-
predicate(args) {
|
|
27942
|
+
async predicate(args) {
|
|
27925
27943
|
if (args.parsedResult.operationType === void 0) {
|
|
27926
27944
|
return false;
|
|
27927
27945
|
}
|
|
@@ -27933,12 +27951,32 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
27933
27951
|
return false;
|
|
27934
27952
|
}
|
|
27935
27953
|
const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
|
|
27936
|
-
const hasMatchingOperationName =
|
|
27954
|
+
const hasMatchingOperationName = await this.matchOperationName({
|
|
27955
|
+
request: args.request,
|
|
27956
|
+
parsedResult: args.parsedResult
|
|
27957
|
+
});
|
|
27937
27958
|
return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
|
|
27938
27959
|
}
|
|
27960
|
+
async matchOperationName(args) {
|
|
27961
|
+
if (typeof this.info.operationName === "function") {
|
|
27962
|
+
const customPredicateResult = await this.info.operationName({
|
|
27963
|
+
request: args.request,
|
|
27964
|
+
...this.extendResolverArgs({
|
|
27965
|
+
request: args.request,
|
|
27966
|
+
parsedResult: args.parsedResult
|
|
27967
|
+
})
|
|
27968
|
+
});
|
|
27969
|
+
return typeof customPredicateResult === "boolean" ? customPredicateResult : customPredicateResult.matches;
|
|
27970
|
+
}
|
|
27971
|
+
if (this.info.operationName instanceof RegExp) {
|
|
27972
|
+
return this.info.operationName.test(args.parsedResult.operationName || "");
|
|
27973
|
+
}
|
|
27974
|
+
return args.parsedResult.operationName === this.info.operationName;
|
|
27975
|
+
}
|
|
27939
27976
|
extendResolverArgs(args) {
|
|
27940
27977
|
return {
|
|
27941
27978
|
query: args.parsedResult.query || "",
|
|
27979
|
+
operationType: args.parsedResult.operationType,
|
|
27942
27980
|
operationName: args.parsedResult.operationName || "",
|
|
27943
27981
|
variables: args.parsedResult.variables || {},
|
|
27944
27982
|
cookies: args.parsedResult.cookies
|
|
@@ -27965,14 +28003,8 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
27965
28003
|
|
|
27966
28004
|
// src/core/graphql.ts
|
|
27967
28005
|
function createScopedGraphQLHandler(operationType, url) {
|
|
27968
|
-
return (
|
|
27969
|
-
return new GraphQLHandler(
|
|
27970
|
-
operationType,
|
|
27971
|
-
operationName,
|
|
27972
|
-
url,
|
|
27973
|
-
resolver,
|
|
27974
|
-
options
|
|
27975
|
-
);
|
|
28006
|
+
return (predicate, resolver, options = {}) => {
|
|
28007
|
+
return new GraphQLHandler(operationType, predicate, url, resolver, options);
|
|
27976
28008
|
};
|
|
27977
28009
|
}
|
|
27978
28010
|
function createGraphQLOperationHandler(url) {
|