msw 2.10.1 → 2.10.2
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-DzeJL_i8.d.ts → HttpResponse-CCdkF1fJ.d.ts} +103 -2
- package/lib/core/{HttpResponse-BOGtXZ-B.d.mts → HttpResponse-I457nh8V.d.mts} +103 -2
- package/lib/core/HttpResponse.d.mts +3 -1
- package/lib/core/HttpResponse.d.ts +3 -1
- package/lib/core/HttpResponse.js +5 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +5 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +3 -2
- package/lib/core/SetupApi.d.ts +3 -2
- package/lib/core/getResponse.d.mts +3 -1
- package/lib/core/getResponse.d.ts +3 -1
- package/lib/core/graphql.d.mts +1 -2
- package/lib/core/graphql.d.ts +1 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -2
- package/lib/core/handlers/HttpHandler.d.mts +2 -1
- package/lib/core/handlers/HttpHandler.d.ts +2 -1
- package/lib/core/handlers/RequestHandler.d.mts +3 -1
- package/lib/core/handlers/RequestHandler.d.ts +3 -1
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +2 -1
- package/lib/core/http.d.ts +2 -1
- package/lib/core/index.d.mts +1 -2
- package/lib/core/index.d.ts +1 -2
- package/lib/core/passthrough.d.mts +3 -1
- package/lib/core/passthrough.d.ts +3 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +3 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +3 -1
- package/lib/core/utils/executeHandlers.d.mts +3 -1
- package/lib/core/utils/executeHandlers.d.ts +3 -1
- package/lib/core/utils/handleRequest.d.mts +3 -1
- package/lib/core/utils/handleRequest.d.ts +3 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +3 -2
- package/lib/core/utils/internal/isHandlerKind.d.ts +3 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +3 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +3 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +3 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +3 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +3 -2
- package/lib/core/ws/handleWebSocketEvent.d.ts +3 -2
- package/lib/iife/index.js +4 -0
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/HttpResponse.ts +8 -1
- package/src/core/handlers/RequestHandler.ts +17 -2
- package/lib/core/GraphQLHandler-DOXAygvT.d.mts +0 -100
- package/lib/core/GraphQLHandler-noP9MRWa.d.ts +0 -100
package/lib/mockServiceWorker.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const PACKAGE_VERSION = '2.10.
|
|
10
|
+
const PACKAGE_VERSION = '2.10.2'
|
|
11
11
|
const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.2",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -280,7 +280,7 @@
|
|
|
280
280
|
"vitest-environment-miniflare": "^2.14.4",
|
|
281
281
|
"webpack": "^5.95.0",
|
|
282
282
|
"webpack-http-server": "^0.5.0",
|
|
283
|
-
"msw": "2.10.
|
|
283
|
+
"msw": "2.10.2"
|
|
284
284
|
},
|
|
285
285
|
"peerDependencies": {
|
|
286
286
|
"typescript": ">= 4.8.x"
|
package/src/core/HttpResponse.ts
CHANGED
|
@@ -10,7 +10,10 @@ export interface HttpResponseInit extends ResponseInit {
|
|
|
10
10
|
type?: ResponseType
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const bodyType: unique symbol = Symbol('bodyType')
|
|
13
|
+
export const bodyType: unique symbol = Symbol('bodyType')
|
|
14
|
+
export type DefaultUnsafeFetchResponse = Response & {
|
|
15
|
+
[bodyType]?: never
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
export interface StrictRequest<BodyType extends JsonBodyType> extends Request {
|
|
16
19
|
json(): Promise<BodyType>
|
|
@@ -46,6 +49,10 @@ export class HttpResponse<
|
|
|
46
49
|
decorateResponse(this, responseInit)
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
static error(): HttpResponse<any> {
|
|
53
|
+
return super.error() as HttpResponse<any>
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
/**
|
|
50
57
|
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
51
58
|
* @example
|
|
@@ -6,8 +6,13 @@ import {
|
|
|
6
6
|
} from '../utils/internal/isIterable'
|
|
7
7
|
import type { ResponseResolutionContext } from '../utils/executeHandlers'
|
|
8
8
|
import type { MaybePromise } from '../typeUtils'
|
|
9
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
StrictRequest,
|
|
11
|
+
HttpResponse,
|
|
12
|
+
DefaultUnsafeFetchResponse,
|
|
13
|
+
} from '../HttpResponse'
|
|
10
14
|
import type { HandlerKind } from './common'
|
|
15
|
+
import type { GraphQLRequestBody } from './GraphQLHandler'
|
|
11
16
|
|
|
12
17
|
export type DefaultRequestMultipartBody = Record<
|
|
13
18
|
string,
|
|
@@ -42,9 +47,19 @@ export interface RequestHandlerInternalInfo {
|
|
|
42
47
|
export type ResponseResolverReturnType<
|
|
43
48
|
ResponseBodyType extends DefaultBodyType = undefined,
|
|
44
49
|
> =
|
|
50
|
+
// If ResponseBodyType is a union and one of the types is `undefined`,
|
|
51
|
+
// allow plain Response as the type.
|
|
45
52
|
| ([ResponseBodyType] extends [undefined]
|
|
46
53
|
? Response
|
|
47
|
-
:
|
|
54
|
+
: /**
|
|
55
|
+
* Treat GraphQL response body type as a special case.
|
|
56
|
+
* For esome reason, making the default HttpResponse<T> | DefaultUnsafeFetchResponse
|
|
57
|
+
* union breaks the body type inference for HTTP requests.
|
|
58
|
+
* @see https://github.com/mswjs/msw/issues/2130
|
|
59
|
+
*/
|
|
60
|
+
ResponseBodyType extends GraphQLRequestBody<any>
|
|
61
|
+
? HttpResponse<ResponseBodyType> | DefaultUnsafeFetchResponse
|
|
62
|
+
: HttpResponse<ResponseBodyType>)
|
|
48
63
|
| undefined
|
|
49
64
|
| void
|
|
50
65
|
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { D as DefaultBodyType, R as RequestHandler, g as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-BOGtXZ-B.mjs';
|
|
3
|
-
import { Match, Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
|
-
|
|
5
|
-
interface ParsedGraphQLQuery {
|
|
6
|
-
operationType: OperationTypeNode;
|
|
7
|
-
operationName?: string;
|
|
8
|
-
}
|
|
9
|
-
type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
10
|
-
query: string;
|
|
11
|
-
variables?: VariablesType;
|
|
12
|
-
}) | undefined;
|
|
13
|
-
declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
|
|
14
|
-
type GraphQLParsedOperationsMap = Record<string, string[]>;
|
|
15
|
-
type GraphQLMultipartRequestBody = {
|
|
16
|
-
operations: string;
|
|
17
|
-
map?: string;
|
|
18
|
-
} & {
|
|
19
|
-
[fileName: string]: File;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Determines if a given request can be considered a GraphQL request.
|
|
23
|
-
* Does not parse the query and does not guarantee its validity.
|
|
24
|
-
*/
|
|
25
|
-
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
26
|
-
|
|
27
|
-
type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
28
|
-
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
29
|
-
type GraphQLQuery = Record<string, any> | null;
|
|
30
|
-
type GraphQLVariables = Record<string, any>;
|
|
31
|
-
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
32
|
-
operationType: ExpectedOperationTypeNode;
|
|
33
|
-
operationName: GraphQLHandlerNameSelector;
|
|
34
|
-
}
|
|
35
|
-
type GraphQLRequestParsedResult = {
|
|
36
|
-
match: Match;
|
|
37
|
-
cookies: Record<string, string>;
|
|
38
|
-
} & (ParsedGraphQLRequest<GraphQLVariables>
|
|
39
|
-
/**
|
|
40
|
-
* An empty version of the ParsedGraphQLRequest
|
|
41
|
-
* which simplifies the return type of the resolver
|
|
42
|
-
* when the request is to a non-matching endpoint
|
|
43
|
-
*/
|
|
44
|
-
| {
|
|
45
|
-
operationType?: undefined;
|
|
46
|
-
operationName?: undefined;
|
|
47
|
-
query?: undefined;
|
|
48
|
-
variables?: undefined;
|
|
49
|
-
});
|
|
50
|
-
type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
|
|
51
|
-
query: string;
|
|
52
|
-
operationName: string;
|
|
53
|
-
variables: Variables;
|
|
54
|
-
cookies: Record<string, string>;
|
|
55
|
-
};
|
|
56
|
-
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
57
|
-
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
58
|
-
query: string;
|
|
59
|
-
variables?: Variables;
|
|
60
|
-
}
|
|
61
|
-
type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
62
|
-
data?: BodyType | null;
|
|
63
|
-
errors?: readonly Partial<GraphQLError>[] | null;
|
|
64
|
-
extensions?: Record<string, any>;
|
|
65
|
-
} | null | undefined;
|
|
66
|
-
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
67
|
-
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
68
|
-
private endpoint;
|
|
69
|
-
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
70
|
-
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
71
|
-
/**
|
|
72
|
-
* Parses the request body, once per request, cached across all
|
|
73
|
-
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
74
|
-
* request body, which each requires a clone of the request.
|
|
75
|
-
*/
|
|
76
|
-
parseGraphQLRequestOrGetFromCache(request: Request): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
77
|
-
parse(args: {
|
|
78
|
-
request: Request;
|
|
79
|
-
}): Promise<GraphQLRequestParsedResult>;
|
|
80
|
-
predicate(args: {
|
|
81
|
-
request: Request;
|
|
82
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
83
|
-
}): boolean;
|
|
84
|
-
protected extendResolverArgs(args: {
|
|
85
|
-
request: Request;
|
|
86
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
87
|
-
}): {
|
|
88
|
-
query: string;
|
|
89
|
-
operationName: string;
|
|
90
|
-
variables: GraphQLVariables;
|
|
91
|
-
cookies: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
log(args: {
|
|
94
|
-
request: Request;
|
|
95
|
-
response: Response;
|
|
96
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
97
|
-
}): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { type ExpectedOperationTypeNode as E, GraphQLHandler as G, type ParsedGraphQLRequest as P, type GraphQLQuery as a, type GraphQLVariables as b, type GraphQLRequestBody as c, type GraphQLJsonRequestBody as d, type GraphQLHandlerNameSelector as e, type GraphQLResolverExtras as f, type GraphQLResponseBody as g, type ParsedGraphQLQuery as h, type GraphQLParsedOperationsMap as i, type GraphQLMultipartRequestBody as j, parseGraphQLRequest as k, type GraphQLHandlerInfo as l, type GraphQLRequestParsedResult as m, isDocumentNode as n, parseDocumentNode as p };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { D as DefaultBodyType, R as RequestHandler, g as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-DzeJL_i8.js';
|
|
3
|
-
import { Match, Path } from './utils/matching/matchRequestUrl.js';
|
|
4
|
-
|
|
5
|
-
interface ParsedGraphQLQuery {
|
|
6
|
-
operationType: OperationTypeNode;
|
|
7
|
-
operationName?: string;
|
|
8
|
-
}
|
|
9
|
-
type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
10
|
-
query: string;
|
|
11
|
-
variables?: VariablesType;
|
|
12
|
-
}) | undefined;
|
|
13
|
-
declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
|
|
14
|
-
type GraphQLParsedOperationsMap = Record<string, string[]>;
|
|
15
|
-
type GraphQLMultipartRequestBody = {
|
|
16
|
-
operations: string;
|
|
17
|
-
map?: string;
|
|
18
|
-
} & {
|
|
19
|
-
[fileName: string]: File;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Determines if a given request can be considered a GraphQL request.
|
|
23
|
-
* Does not parse the query and does not guarantee its validity.
|
|
24
|
-
*/
|
|
25
|
-
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
26
|
-
|
|
27
|
-
type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
28
|
-
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
29
|
-
type GraphQLQuery = Record<string, any> | null;
|
|
30
|
-
type GraphQLVariables = Record<string, any>;
|
|
31
|
-
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
32
|
-
operationType: ExpectedOperationTypeNode;
|
|
33
|
-
operationName: GraphQLHandlerNameSelector;
|
|
34
|
-
}
|
|
35
|
-
type GraphQLRequestParsedResult = {
|
|
36
|
-
match: Match;
|
|
37
|
-
cookies: Record<string, string>;
|
|
38
|
-
} & (ParsedGraphQLRequest<GraphQLVariables>
|
|
39
|
-
/**
|
|
40
|
-
* An empty version of the ParsedGraphQLRequest
|
|
41
|
-
* which simplifies the return type of the resolver
|
|
42
|
-
* when the request is to a non-matching endpoint
|
|
43
|
-
*/
|
|
44
|
-
| {
|
|
45
|
-
operationType?: undefined;
|
|
46
|
-
operationName?: undefined;
|
|
47
|
-
query?: undefined;
|
|
48
|
-
variables?: undefined;
|
|
49
|
-
});
|
|
50
|
-
type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
|
|
51
|
-
query: string;
|
|
52
|
-
operationName: string;
|
|
53
|
-
variables: Variables;
|
|
54
|
-
cookies: Record<string, string>;
|
|
55
|
-
};
|
|
56
|
-
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
57
|
-
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
58
|
-
query: string;
|
|
59
|
-
variables?: Variables;
|
|
60
|
-
}
|
|
61
|
-
type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
62
|
-
data?: BodyType | null;
|
|
63
|
-
errors?: readonly Partial<GraphQLError>[] | null;
|
|
64
|
-
extensions?: Record<string, any>;
|
|
65
|
-
} | null | undefined;
|
|
66
|
-
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
67
|
-
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
68
|
-
private endpoint;
|
|
69
|
-
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
70
|
-
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
71
|
-
/**
|
|
72
|
-
* Parses the request body, once per request, cached across all
|
|
73
|
-
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
74
|
-
* request body, which each requires a clone of the request.
|
|
75
|
-
*/
|
|
76
|
-
parseGraphQLRequestOrGetFromCache(request: Request): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
77
|
-
parse(args: {
|
|
78
|
-
request: Request;
|
|
79
|
-
}): Promise<GraphQLRequestParsedResult>;
|
|
80
|
-
predicate(args: {
|
|
81
|
-
request: Request;
|
|
82
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
83
|
-
}): boolean;
|
|
84
|
-
protected extendResolverArgs(args: {
|
|
85
|
-
request: Request;
|
|
86
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
87
|
-
}): {
|
|
88
|
-
query: string;
|
|
89
|
-
operationName: string;
|
|
90
|
-
variables: GraphQLVariables;
|
|
91
|
-
cookies: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
log(args: {
|
|
94
|
-
request: Request;
|
|
95
|
-
response: Response;
|
|
96
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
97
|
-
}): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { type ExpectedOperationTypeNode as E, GraphQLHandler as G, type ParsedGraphQLRequest as P, type GraphQLQuery as a, type GraphQLVariables as b, type GraphQLRequestBody as c, type GraphQLJsonRequestBody as d, type GraphQLHandlerNameSelector as e, type GraphQLResolverExtras as f, type GraphQLResponseBody as g, type ParsedGraphQLQuery as h, type GraphQLParsedOperationsMap as i, type GraphQLMultipartRequestBody as j, parseGraphQLRequest as k, type GraphQLHandlerInfo as l, type GraphQLRequestParsedResult as m, isDocumentNode as n, parseDocumentNode as p };
|