msw 2.10.5 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-CC5tPhLa.d.mts → HttpResponse-B4YmE-GJ.d.mts} +22 -8
- package/lib/core/{HttpResponse-CKZrrwKE.d.ts → HttpResponse-BbwAqLE_.d.ts} +22 -8
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs.map +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/cookieStore.d.mts +10 -2
- package/lib/core/utils/cookieStore.d.ts +10 -2
- package/lib/core/utils/cookieStore.js +49 -146
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs +53 -136
- package/lib/core/utils/cookieStore.mjs.map +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/handleRequest.js +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +1 -1
- package/lib/core/utils/handleRequest.mjs.map +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/utils/request/getRequestCookies.js +1 -1
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
- package/lib/core/utils/request/storeResponseCookies.d.mts +1 -1
- package/lib/core/utils/request/storeResponseCookies.d.ts +1 -1
- package/lib/core/utils/request/storeResponseCookies.js +2 -2
- package/lib/core/utils/request/storeResponseCookies.js.map +1 -1
- package/lib/core/utils/request/storeResponseCookies.mjs +2 -2
- package/lib/core/utils/request/storeResponseCookies.mjs.map +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 +2661 -12110
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/browser/setupWorker/setupWorker.ts +1 -1
- package/src/core/HttpResponse.ts +3 -3
- 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 +3 -0
- package/src/core/utils/cookieStore.ts +56 -198
- package/src/core/utils/handleRequest.test.ts +84 -0
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/request/getRequestCookies.ts +1 -1
- package/src/core/utils/request/storeResponseCookies.ts +3 -3
- package/src/core/utils/request/toPublicUrl.test.ts +1 -1
- package/src/core/ws/WebSocketClientManager.test.ts +1 -1
- package/src/node/SetupServerApi.ts +1 -1
|
@@ -46,13 +46,13 @@ type GraphQLMultipartRequestBody = {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
48
48
|
|
|
49
|
-
type
|
|
49
|
+
type GraphQLOperationType = OperationTypeNode | 'all';
|
|
50
50
|
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
51
51
|
type GraphQLQuery = Record<string, any> | null;
|
|
52
52
|
type GraphQLVariables = Record<string, any>;
|
|
53
53
|
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
54
|
-
operationType:
|
|
55
|
-
operationName: GraphQLHandlerNameSelector;
|
|
54
|
+
operationType: GraphQLOperationType;
|
|
55
|
+
operationName: GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
56
56
|
}
|
|
57
57
|
type GraphQLRequestParsedResult = {
|
|
58
58
|
match: Match;
|
|
@@ -85,11 +85,23 @@ type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
|
85
85
|
errors?: readonly Partial<GraphQLError>[] | null;
|
|
86
86
|
extensions?: Record<string, any>;
|
|
87
87
|
} | null | undefined;
|
|
88
|
+
type GraphQLCustomPredicate = (args: {
|
|
89
|
+
request: Request;
|
|
90
|
+
query: string;
|
|
91
|
+
operationType: GraphQLOperationType;
|
|
92
|
+
operationName: string;
|
|
93
|
+
variables: GraphQLVariables;
|
|
94
|
+
cookies: Record<string, string>;
|
|
95
|
+
}) => GraphQLCustomPredicateResult | Promise<GraphQLCustomPredicateResult>;
|
|
96
|
+
type GraphQLCustomPredicateResult = boolean | {
|
|
97
|
+
matches: boolean;
|
|
98
|
+
};
|
|
99
|
+
type GraphQLPredicate = GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
88
100
|
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
89
101
|
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
90
102
|
private endpoint;
|
|
91
103
|
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
92
|
-
constructor(operationType:
|
|
104
|
+
constructor(operationType: GraphQLOperationType, predicate: GraphQLPredicate, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
93
105
|
/**
|
|
94
106
|
* Parses the request body, once per request, cached across all
|
|
95
107
|
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
@@ -102,12 +114,14 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLR
|
|
|
102
114
|
predicate(args: {
|
|
103
115
|
request: Request;
|
|
104
116
|
parsedResult: GraphQLRequestParsedResult;
|
|
105
|
-
}): boolean
|
|
117
|
+
}): Promise<boolean>;
|
|
118
|
+
private matchOperationName;
|
|
106
119
|
protected extendResolverArgs(args: {
|
|
107
120
|
request: Request;
|
|
108
121
|
parsedResult: GraphQLRequestParsedResult;
|
|
109
122
|
}): {
|
|
110
123
|
query: string;
|
|
124
|
+
operationType: OperationTypeNode;
|
|
111
125
|
operationName: string;
|
|
112
126
|
variables: GraphQLVariables;
|
|
113
127
|
cookies: Record<string, string>;
|
|
@@ -172,7 +186,7 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
172
186
|
request: Request;
|
|
173
187
|
parsedResult: ParsedResult;
|
|
174
188
|
resolutionContext?: ResponseResolutionContext;
|
|
175
|
-
}): boolean
|
|
189
|
+
}): boolean | Promise<boolean>;
|
|
176
190
|
/**
|
|
177
191
|
* Print out the successfully handled request.
|
|
178
192
|
*/
|
|
@@ -286,7 +300,7 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
286
300
|
*
|
|
287
301
|
* HttpResponse.arrayBuffer(buffer)
|
|
288
302
|
*/
|
|
289
|
-
static arrayBuffer
|
|
303
|
+
static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(body?: BodyType, init?: HttpResponseInit): HttpResponse<BodyType>;
|
|
290
304
|
/**
|
|
291
305
|
* Create a `Response` with a `FormData` body.
|
|
292
306
|
* @example
|
|
@@ -298,4 +312,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
298
312
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
299
313
|
}
|
|
300
314
|
|
|
301
|
-
export { type AsyncResponseResolverReturnType as A,
|
|
315
|
+
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerInfo as B, type GraphQLRequestParsedResult as C, type DefaultBodyType as D, type GraphQLCustomPredicateResult as E, type GraphQLPredicate as F, GraphQLHandler as G, type HttpResponseInit as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type ResponseResolverInfo as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerArgs as N, type RequestHandlerExecutionResult as O, type ParsedGraphQLRequest as P, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type GraphQLQuery as e, type GraphQLVariables as f, type GraphQLRequestBody as g, type GraphQLResponseBody as h, type GraphQLJsonRequestBody as i, type GraphQLOperationType as j, type GraphQLCustomPredicate as k, bodyType as l, type DefaultUnsafeFetchResponse as m, type StrictResponse as n, HttpResponse as o, type ResponseResolutionContext as p, type GraphQLHandlerNameSelector as q, type GraphQLResolverExtras as r, type RequestHandlerDefaultInfo as s, type HandlersExecutionResult as t, executeHandlers as u, type ParsedGraphQLQuery as v, parseDocumentNode as w, type GraphQLParsedOperationsMap as x, type GraphQLMultipartRequestBody as y, parseGraphQLRequest as z };
|
|
@@ -46,13 +46,13 @@ type GraphQLMultipartRequestBody = {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
48
48
|
|
|
49
|
-
type
|
|
49
|
+
type GraphQLOperationType = OperationTypeNode | 'all';
|
|
50
50
|
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
51
51
|
type GraphQLQuery = Record<string, any> | null;
|
|
52
52
|
type GraphQLVariables = Record<string, any>;
|
|
53
53
|
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
54
|
-
operationType:
|
|
55
|
-
operationName: GraphQLHandlerNameSelector;
|
|
54
|
+
operationType: GraphQLOperationType;
|
|
55
|
+
operationName: GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
56
56
|
}
|
|
57
57
|
type GraphQLRequestParsedResult = {
|
|
58
58
|
match: Match;
|
|
@@ -85,11 +85,23 @@ type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
|
85
85
|
errors?: readonly Partial<GraphQLError>[] | null;
|
|
86
86
|
extensions?: Record<string, any>;
|
|
87
87
|
} | null | undefined;
|
|
88
|
+
type GraphQLCustomPredicate = (args: {
|
|
89
|
+
request: Request;
|
|
90
|
+
query: string;
|
|
91
|
+
operationType: GraphQLOperationType;
|
|
92
|
+
operationName: string;
|
|
93
|
+
variables: GraphQLVariables;
|
|
94
|
+
cookies: Record<string, string>;
|
|
95
|
+
}) => GraphQLCustomPredicateResult | Promise<GraphQLCustomPredicateResult>;
|
|
96
|
+
type GraphQLCustomPredicateResult = boolean | {
|
|
97
|
+
matches: boolean;
|
|
98
|
+
};
|
|
99
|
+
type GraphQLPredicate = GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
88
100
|
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
89
101
|
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
90
102
|
private endpoint;
|
|
91
103
|
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
92
|
-
constructor(operationType:
|
|
104
|
+
constructor(operationType: GraphQLOperationType, predicate: GraphQLPredicate, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
93
105
|
/**
|
|
94
106
|
* Parses the request body, once per request, cached across all
|
|
95
107
|
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
@@ -102,12 +114,14 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLR
|
|
|
102
114
|
predicate(args: {
|
|
103
115
|
request: Request;
|
|
104
116
|
parsedResult: GraphQLRequestParsedResult;
|
|
105
|
-
}): boolean
|
|
117
|
+
}): Promise<boolean>;
|
|
118
|
+
private matchOperationName;
|
|
106
119
|
protected extendResolverArgs(args: {
|
|
107
120
|
request: Request;
|
|
108
121
|
parsedResult: GraphQLRequestParsedResult;
|
|
109
122
|
}): {
|
|
110
123
|
query: string;
|
|
124
|
+
operationType: OperationTypeNode;
|
|
111
125
|
operationName: string;
|
|
112
126
|
variables: GraphQLVariables;
|
|
113
127
|
cookies: Record<string, string>;
|
|
@@ -172,7 +186,7 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
172
186
|
request: Request;
|
|
173
187
|
parsedResult: ParsedResult;
|
|
174
188
|
resolutionContext?: ResponseResolutionContext;
|
|
175
|
-
}): boolean
|
|
189
|
+
}): boolean | Promise<boolean>;
|
|
176
190
|
/**
|
|
177
191
|
* Print out the successfully handled request.
|
|
178
192
|
*/
|
|
@@ -286,7 +300,7 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
286
300
|
*
|
|
287
301
|
* HttpResponse.arrayBuffer(buffer)
|
|
288
302
|
*/
|
|
289
|
-
static arrayBuffer
|
|
303
|
+
static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(body?: BodyType, init?: HttpResponseInit): HttpResponse<BodyType>;
|
|
290
304
|
/**
|
|
291
305
|
* Create a `Response` with a `FormData` body.
|
|
292
306
|
* @example
|
|
@@ -298,4 +312,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
298
312
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
299
313
|
}
|
|
300
314
|
|
|
301
|
-
export { type AsyncResponseResolverReturnType as A,
|
|
315
|
+
export { type AsyncResponseResolverReturnType as A, type GraphQLHandlerInfo as B, type GraphQLRequestParsedResult as C, type DefaultBodyType as D, type GraphQLCustomPredicateResult as E, type GraphQLPredicate as F, GraphQLHandler as G, type HttpResponseInit as H, isDocumentNode as I, type JsonBodyType as J, type RequestHandlerInternalInfo as K, type ResponseResolverInfo as L, type MaybeAsyncResponseResolverReturnType as M, type RequestHandlerArgs as N, type RequestHandlerExecutionResult as O, type ParsedGraphQLRequest as P, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type GraphQLQuery as e, type GraphQLVariables as f, type GraphQLRequestBody as g, type GraphQLResponseBody as h, type GraphQLJsonRequestBody as i, type GraphQLOperationType as j, type GraphQLCustomPredicate as k, bodyType as l, type DefaultUnsafeFetchResponse as m, type StrictResponse as n, HttpResponse as o, type ResponseResolutionContext as p, type GraphQLHandlerNameSelector as q, type GraphQLResolverExtras as r, type RequestHandlerDefaultInfo as s, type HandlersExecutionResult as t, executeHandlers as u, type ParsedGraphQLQuery as v, parseDocumentNode as w, type GraphQLParsedOperationsMap as x, type GraphQLMultipartRequestBody as y, parseGraphQLRequest as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export {
|
|
2
|
+
export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-B4YmE-GJ.mjs';
|
|
3
3
|
import './typeUtils.mjs';
|
|
4
4
|
import './utils/internal/isIterable.mjs';
|
|
5
5
|
import 'graphql';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export {
|
|
2
|
+
export { m as DefaultUnsafeFetchResponse, o as HttpResponse, H as HttpResponseInit, S as StrictRequest, n as StrictResponse, l as bodyType } from './HttpResponse-BbwAqLE_.js';
|
|
3
3
|
import './typeUtils.js';
|
|
4
4
|
import './utils/internal/isIterable.js';
|
|
5
5
|
import 'graphql';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer(\n body?:
|
|
1
|
+
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(\n body?: BodyType,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA8B;AAG9B,wBAGO;AAMA,MAAM,WAA0B,OAAO,UAAU;AA4BjD,MAAM,qBAEH,kCAAc;AAAA,EACtB,CAAU,QAAQ,IAAc;AAAA,EAEhC,YAAY,MAAiC,MAAyB;AACpE,UAAM,mBAAe,yCAAsB,IAAI;AAC/C,UAAM,MAAkB,YAAY;AACpC,4CAAiB,MAAM,YAAY;AAAA,EACrC;AAAA,EAEA,OAAO,QAA2B;AAChC,WAAO,MAAM,MAAM;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,YAAY;AAAA,IACvD;AAKA,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,kBAAkB;AAAA,IAC7D;AAMA,UAAM,eAAe,KAAK,UAAU,IAAI;AAExC,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,eAAe,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,cAA0B,YAAY;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,IACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,UAAU;AAAA,IACrD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,WAAW;AAAA,IACtD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,YACL,MACA,MACwB;AACxB,UAAM,mBAAe,yCAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,0BAA0B;AAAA,IACrE;AAEA,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,UAAM,yCAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer(\n body?:
|
|
1
|
+
{"version":3,"sources":["../../src/core/HttpResponse.ts"],"sourcesContent":["import { FetchResponse } from '@mswjs/interceptors'\nimport type { DefaultBodyType, JsonBodyType } from './handlers/RequestHandler'\nimport type { NoInfer } from './typeUtils'\nimport {\n decorateResponse,\n normalizeResponseInit,\n} from './utils/HttpResponse/decorators'\n\nexport interface HttpResponseInit extends ResponseInit {\n type?: ResponseType\n}\n\nexport const bodyType: unique symbol = Symbol('bodyType')\nexport type DefaultUnsafeFetchResponse = Response & {\n [bodyType]?: never\n}\n\nexport interface StrictRequest<BodyType extends JsonBodyType> extends Request {\n json(): Promise<BodyType>\n}\n\n/**\n * Opaque `Response` type that supports strict body type.\n *\n * @deprecated Please use {@link HttpResponse} instead.\n */\nexport type StrictResponse<BodyType extends DefaultBodyType> =\n HttpResponse<BodyType>\n\n/**\n * A drop-in replacement for the standard `Response` class\n * to allow additional features, like mocking the response `Set-Cookie` header.\n *\n * @example\n * new HttpResponse('Hello world', { status: 201 })\n * HttpResponse.json({ name: 'John' })\n * HttpResponse.formData(form)\n *\n * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}\n */\nexport class HttpResponse<\n BodyType extends DefaultBodyType,\n> extends FetchResponse {\n readonly [bodyType]: BodyType = null as any\n\n constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {\n const responseInit = normalizeResponseInit(init)\n super(body as BodyInit, responseInit)\n decorateResponse(this, responseInit)\n }\n\n static error(): HttpResponse<any> {\n return super.error() as HttpResponse<any>\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/plain\"` body.\n * @example\n * HttpResponse.text('hello world')\n * HttpResponse.text('Error', { status: 500 })\n */\n static text<BodyType extends string>(\n body?: NoInfer<BodyType> | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/plain')\n }\n\n // Automatically set the \"Content-Length\" response header\n // for non-empty text responses. This enforces consistency and\n // brings mocked responses closer to production.\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n body ? new Blob([body]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/json\"` body.\n * @example\n * HttpResponse.json({ firstName: 'John' })\n * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })\n */\n static json<BodyType extends JsonBodyType>(\n body?: NoInfer<BodyType> | null | undefined,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/json')\n }\n\n /**\n * @note TypeScript is incorrect here.\n * Stringifying undefined will return undefined.\n */\n const responseText = JSON.stringify(body) as string | undefined\n\n if (!responseInit.headers.has('Content-Length')) {\n responseInit.headers.set(\n 'Content-Length',\n responseText ? new Blob([responseText]).size.toString() : '0',\n )\n }\n\n return new HttpResponse(responseText as BodyType, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"application/xml\"` body.\n * @example\n * HttpResponse.xml(`<user name=\"John\" />`)\n * HttpResponse.xml(`<article id=\"abc-123\" />`, { status: 201 })\n */\n static xml<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/xml')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `Content-Type: \"text/html\"` body.\n * @example\n * HttpResponse.html(`<p class=\"author\">Jane Doe</p>`)\n * HttpResponse.html(`<main id=\"abc-123\">Main text</main>`, { status: 201 })\n */\n static html<BodyType extends string>(\n body?: BodyType | null,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'text/html')\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with an `ArrayBuffer` body.\n * @example\n * const buffer = new ArrayBuffer(3)\n * const view = new Uint8Array(buffer)\n * view.set([1, 2, 3])\n *\n * HttpResponse.arrayBuffer(buffer)\n */\n static arrayBuffer<BodyType extends ArrayBuffer | SharedArrayBuffer>(\n body?: BodyType,\n init?: HttpResponseInit,\n ): HttpResponse<BodyType> {\n const responseInit = normalizeResponseInit(init)\n\n if (!responseInit.headers.has('Content-Type')) {\n responseInit.headers.set('Content-Type', 'application/octet-stream')\n }\n\n if (body && !responseInit.headers.has('Content-Length')) {\n responseInit.headers.set('Content-Length', body.byteLength.toString())\n }\n\n return new HttpResponse(body, responseInit)\n }\n\n /**\n * Create a `Response` with a `FormData` body.\n * @example\n * const data = new FormData()\n * data.set('name', 'Alice')\n *\n * HttpResponse.formData(data)\n */\n static formData(\n body?: FormData,\n init?: HttpResponseInit,\n ): HttpResponse<FormData> {\n return new HttpResponse(body, normalizeResponseInit(init))\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAG9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAMA,MAAM,WAA0B,OAAO,UAAU;AA4BjD,MAAM,qBAEH,cAAc;AAAA,EACtB,CAAU,QAAQ,IAAc;AAAA,EAEhC,YAAY,MAAiC,MAAyB;AACpE,UAAM,eAAe,sBAAsB,IAAI;AAC/C,UAAM,MAAkB,YAAY;AACpC,qBAAiB,MAAM,YAAY;AAAA,EACrC;AAAA,EAEA,OAAO,QAA2B;AAChC,WAAO,MAAM,MAAM;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,YAAY;AAAA,IACvD;AAKA,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,kBAAkB;AAAA,IAC7D;AAMA,UAAM,eAAe,KAAK,UAAU,IAAI;AAExC,QAAI,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AAC/C,mBAAa,QAAQ;AAAA,QACnB;AAAA,QACA,eAAe,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE,KAAK,SAAS,IAAI;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO,IAAI,aAAa,cAA0B,YAAY;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,IACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,UAAU;AAAA,IACrD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,KACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,WAAW;AAAA,IACtD;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,OAAO,YACL,MACA,MACwB;AACxB,UAAM,eAAe,sBAAsB,IAAI;AAE/C,QAAI,CAAC,aAAa,QAAQ,IAAI,cAAc,GAAG;AAC7C,mBAAa,QAAQ,IAAI,gBAAgB,0BAA0B;AAAA,IACrE;AAEA,QAAI,QAAQ,CAAC,aAAa,QAAQ,IAAI,gBAAgB,GAAG;AACvD,mBAAa,QAAQ,IAAI,kBAAkB,KAAK,WAAW,SAAS,CAAC;AAAA,IACvE;AAEA,WAAO,IAAI,aAAa,MAAM,YAAY;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,SACL,MACA,MACwB;AACxB,WAAO,IAAI,aAAa,MAAM,sBAAsB,IAAI,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
package/lib/core/SetupApi.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-B4YmE-GJ.mjs';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.mjs';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.mjs';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.mjs';
|
package/lib/core/SetupApi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-BbwAqLE_.js';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.js';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.js';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-B4YmE-GJ.mjs';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './utils/internal/isIterable.mjs';
|
|
4
4
|
import './typeUtils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
1
|
+
import { R as RequestHandler, p as ResponseResolutionContext } from './HttpResponse-BbwAqLE_.js';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './utils/internal/isIterable.js';
|
|
4
4
|
import './typeUtils.js';
|
package/lib/core/graphql.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { e as GraphQLQuery, f as GraphQLVariables,
|
|
2
|
+
import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-B4YmE-GJ.mjs';
|
|
3
3
|
import { Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './utils/internal/isIterable.mjs';
|
|
@@ -14,7 +14,7 @@ interface TypedDocumentNode<Result = {
|
|
|
14
14
|
__resultType?: Result;
|
|
15
15
|
__variablesType?: Variables;
|
|
16
16
|
}
|
|
17
|
-
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(
|
|
17
|
+
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables> | GraphQLCustomPredicate, resolver: GraphQLResponseResolver<[
|
|
18
18
|
Query
|
|
19
19
|
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
20
20
|
type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>>;
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { e as GraphQLQuery, f as GraphQLVariables,
|
|
2
|
+
import { e as GraphQLQuery, f as GraphQLVariables, q as GraphQLHandlerNameSelector, k as GraphQLCustomPredicate, a as ResponseResolver, r as GraphQLResolverExtras, h as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-BbwAqLE_.js';
|
|
3
3
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './utils/internal/isIterable.js';
|
|
@@ -14,7 +14,7 @@ interface TypedDocumentNode<Result = {
|
|
|
14
14
|
__resultType?: Result;
|
|
15
15
|
__variablesType?: Variables;
|
|
16
16
|
}
|
|
17
|
-
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(
|
|
17
|
+
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables> | GraphQLCustomPredicate, resolver: GraphQLResponseResolver<[
|
|
18
18
|
Query
|
|
19
19
|
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
20
20
|
type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>>;
|
package/lib/core/graphql.js
CHANGED
|
@@ -23,14 +23,8 @@ __export(graphql_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(graphql_exports);
|
|
24
24
|
var import_GraphQLHandler = require("./handlers/GraphQLHandler");
|
|
25
25
|
function createScopedGraphQLHandler(operationType, url) {
|
|
26
|
-
return (
|
|
27
|
-
return new import_GraphQLHandler.GraphQLHandler(
|
|
28
|
-
operationType,
|
|
29
|
-
operationName,
|
|
30
|
-
url,
|
|
31
|
-
resolver,
|
|
32
|
-
options
|
|
33
|
-
);
|
|
26
|
+
return (predicate, resolver, options = {}) => {
|
|
27
|
+
return new import_GraphQLHandler.GraphQLHandler(operationType, predicate, url, resolver, options);
|
|
34
28
|
};
|
|
35
29
|
}
|
|
36
30
|
function createGraphQLOperationHandler(url) {
|
package/lib/core/graphql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n
|
|
1
|
+
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n GraphQLOperationType,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n predicate:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>\n | GraphQLCustomPredicate,\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLResponseResolver<\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n> = ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: GraphQLOperationType,\n url: Path,\n): GraphQLRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new GraphQLHandler(operationType, predicate, url, resolver, options)\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BASO;AAqCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,qCAAe,eAAe,WAAW,KAAK,UAAU,OAAO;AAAA,EAC5E;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,qCAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU;AAAA,EACrB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWH,MAAM;AACR;","names":[]}
|
package/lib/core/graphql.mjs
CHANGED
|
@@ -2,14 +2,8 @@ import {
|
|
|
2
2
|
GraphQLHandler
|
|
3
3
|
} from './handlers/GraphQLHandler.mjs';
|
|
4
4
|
function createScopedGraphQLHandler(operationType, url) {
|
|
5
|
-
return (
|
|
6
|
-
return new GraphQLHandler(
|
|
7
|
-
operationType,
|
|
8
|
-
operationName,
|
|
9
|
-
url,
|
|
10
|
-
resolver,
|
|
11
|
-
options
|
|
12
|
-
);
|
|
5
|
+
return (predicate, resolver, options = {}) => {
|
|
6
|
+
return new GraphQLHandler(operationType, predicate, url, resolver, options);
|
|
13
7
|
};
|
|
14
8
|
}
|
|
15
9
|
function createGraphQLOperationHandler(url) {
|
package/lib/core/graphql.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n
|
|
1
|
+
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n GraphQLOperationType,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n predicate:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>\n | GraphQLCustomPredicate,\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLResponseResolver<\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n> = ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: GraphQLOperationType,\n url: Path,\n): GraphQLRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new GraphQLHandler(operationType, predicate, url, resolver, options)\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,OAQK;AAqCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,eAAe,eAAe,WAAW,KAAK,UAAU,OAAO;AAAA,EAC5E;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,eAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU;AAAA,EACrB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWH,MAAM;AACR;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { E as
|
|
2
|
+
export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-B4YmE-GJ.mjs';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import '../utils/internal/isIterable.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { E as
|
|
2
|
+
export { k as GraphQLCustomPredicate, E as GraphQLCustomPredicateResult, G as GraphQLHandler, B as GraphQLHandlerInfo, q as GraphQLHandlerNameSelector, i as GraphQLJsonRequestBody, j as GraphQLOperationType, F as GraphQLPredicate, e as GraphQLQuery, g as GraphQLRequestBody, C as GraphQLRequestParsedResult, r as GraphQLResolverExtras, h as GraphQLResponseBody, f as GraphQLVariables, I as isDocumentNode } from '../HttpResponse-BbwAqLE_.js';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.js';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import '../utils/internal/isIterable.js';
|
|
@@ -41,10 +41,10 @@ function isDocumentNode(value) {
|
|
|
41
41
|
class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
42
42
|
endpoint;
|
|
43
43
|
static parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
constructor(operationType,
|
|
45
|
-
let resolvedOperationName =
|
|
46
|
-
if (isDocumentNode(
|
|
47
|
-
const parsedNode = (0, import_parseGraphQLRequest.parseDocumentNode)(
|
|
44
|
+
constructor(operationType, predicate, endpoint, resolver, options) {
|
|
45
|
+
let resolvedOperationName = predicate;
|
|
46
|
+
if (isDocumentNode(resolvedOperationName)) {
|
|
47
|
+
const parsedNode = (0, import_parseGraphQLRequest.parseDocumentNode)(resolvedOperationName);
|
|
48
48
|
if (parsedNode.operationType !== operationType) {
|
|
49
49
|
throw new Error(
|
|
50
50
|
`Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "${operationType}", but got "${parsedNode.operationType}").`
|
|
@@ -57,7 +57,8 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
57
57
|
}
|
|
58
58
|
resolvedOperationName = parsedNode.operationName;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
60
|
+
const displayOperationName = typeof resolvedOperationName === "function" ? "[custom predicate]" : resolvedOperationName;
|
|
61
|
+
const header = operationType === "all" ? `${operationType} (origin: ${endpoint.toString()})` : `${operationType}${displayOperationName ? ` ${displayOperationName}` : ""} (origin: ${endpoint.toString()})`;
|
|
61
62
|
super({
|
|
62
63
|
info: {
|
|
63
64
|
header,
|
|
@@ -90,13 +91,19 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
90
91
|
const match = (0, import_matchRequestUrl.matchRequestUrl)(new URL(args.request.url), this.endpoint);
|
|
91
92
|
const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
|
|
92
93
|
if (!match.matches) {
|
|
93
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
match,
|
|
96
|
+
cookies
|
|
97
|
+
};
|
|
94
98
|
}
|
|
95
99
|
const parsedResult = await this.parseGraphQLRequestOrGetFromCache(
|
|
96
100
|
args.request
|
|
97
101
|
);
|
|
98
102
|
if (typeof parsedResult === "undefined") {
|
|
99
|
-
return {
|
|
103
|
+
return {
|
|
104
|
+
match,
|
|
105
|
+
cookies
|
|
106
|
+
};
|
|
100
107
|
}
|
|
101
108
|
return {
|
|
102
109
|
match,
|
|
@@ -107,7 +114,7 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
107
114
|
variables: parsedResult.variables
|
|
108
115
|
};
|
|
109
116
|
}
|
|
110
|
-
predicate(args) {
|
|
117
|
+
async predicate(args) {
|
|
111
118
|
if (args.parsedResult.operationType === void 0) {
|
|
112
119
|
return false;
|
|
113
120
|
}
|
|
@@ -119,12 +126,32 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
119
126
|
return false;
|
|
120
127
|
}
|
|
121
128
|
const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
|
|
122
|
-
const hasMatchingOperationName =
|
|
129
|
+
const hasMatchingOperationName = await this.matchOperationName({
|
|
130
|
+
request: args.request,
|
|
131
|
+
parsedResult: args.parsedResult
|
|
132
|
+
});
|
|
123
133
|
return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
|
|
124
134
|
}
|
|
135
|
+
async matchOperationName(args) {
|
|
136
|
+
if (typeof this.info.operationName === "function") {
|
|
137
|
+
const customPredicateResult = await this.info.operationName({
|
|
138
|
+
request: args.request,
|
|
139
|
+
...this.extendResolverArgs({
|
|
140
|
+
request: args.request,
|
|
141
|
+
parsedResult: args.parsedResult
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
return typeof customPredicateResult === "boolean" ? customPredicateResult : customPredicateResult.matches;
|
|
145
|
+
}
|
|
146
|
+
if (this.info.operationName instanceof RegExp) {
|
|
147
|
+
return this.info.operationName.test(args.parsedResult.operationName || "");
|
|
148
|
+
}
|
|
149
|
+
return args.parsedResult.operationName === this.info.operationName;
|
|
150
|
+
}
|
|
125
151
|
extendResolverArgs(args) {
|
|
126
152
|
return {
|
|
127
153
|
query: args.parsedResult.query || "",
|
|
154
|
+
operationType: args.parsedResult.operationType,
|
|
128
155
|
operationName: args.parsedResult.operationName || "",
|
|
129
156
|
variables: args.parsedResult.variables || {},
|
|
130
157
|
cookies: args.parsedResult.cookies
|