msw 0.27.0 → 0.28.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.
@@ -1,6 +1,6 @@
1
1
  import { Mask } from './setupWorker/glossary';
2
2
  import { ResponseResolver } from './handlers/RequestHandler';
3
- import { GraphQLHandler, GraphQLContext, GraphQLRequest, GraphQLHandlerNameSelector } from './handlers/GraphQLHandler';
3
+ import { GraphQLHandler, GraphQLContext, GraphQLRequest, GraphQLVariables, GraphQLHandlerNameSelector } from './handlers/GraphQLHandler';
4
4
  declare const standardGraphQLHandlers: {
5
5
  /**
6
6
  * Captures any GraphQL operation, regardless of its name, under the current scope.
@@ -10,7 +10,7 @@ declare const standardGraphQLHandlers: {
10
10
  * })
11
11
  * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
12
12
  */
13
- operation: <Query extends Record<string, any>, Variables extends Record<string, any> = Record<string, any>>(resolver: ResponseResolver<GraphQLRequest<Variables>, GraphQLContext<Query>, any>) => GraphQLHandler<GraphQLRequest<any>>;
13
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLRequest<Variables>, GraphQLContext<Query>, any>) => GraphQLHandler<GraphQLRequest<any>>;
14
14
  /**
15
15
  * Captures a GraphQL query by a given name.
16
16
  * @example
@@ -19,7 +19,7 @@ declare const standardGraphQLHandlers: {
19
19
  * })
20
20
  * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
21
21
  */
22
- query: <Query_1 extends Record<string, any>, Variables_1 extends Record<string, any> = Record<string, any>>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
22
+ query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
23
23
  /**
24
24
  * Captures a GraphQL mutation by a given name.
25
25
  * @example
@@ -28,7 +28,7 @@ declare const standardGraphQLHandlers: {
28
28
  * })
29
29
  * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
30
30
  */
31
- mutation: <Query_1 extends Record<string, any>, Variables_1 extends Record<string, any> = Record<string, any>>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
31
+ mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
32
32
  };
33
33
  declare function createGraphQLLink(url: Mask): typeof standardGraphQLHandlers;
34
34
  export declare const graphql: {
@@ -41,7 +41,7 @@ export declare const graphql: {
41
41
  * })
42
42
  * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
43
43
  */
44
- operation: <Query extends Record<string, any>, Variables extends Record<string, any> = Record<string, any>>(resolver: ResponseResolver<GraphQLRequest<Variables>, GraphQLContext<Query>, any>) => GraphQLHandler<GraphQLRequest<any>>;
44
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLRequest<Variables>, GraphQLContext<Query>, any>) => GraphQLHandler<GraphQLRequest<any>>;
45
45
  /**
46
46
  * Captures a GraphQL query by a given name.
47
47
  * @example
@@ -50,7 +50,7 @@ export declare const graphql: {
50
50
  * })
51
51
  * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
52
52
  */
53
- query: <Query_1 extends Record<string, any>, Variables_1 extends Record<string, any> = Record<string, any>>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
53
+ query: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
54
54
  /**
55
55
  * Captures a GraphQL mutation by a given name.
56
56
  * @example
@@ -59,6 +59,6 @@ export declare const graphql: {
59
59
  * })
60
60
  * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
61
61
  */
62
- mutation: <Query_1 extends Record<string, any>, Variables_1 extends Record<string, any> = Record<string, any>>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
62
+ mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<any>>;
63
63
  };
64
64
  export {};
@@ -35,7 +35,7 @@ export interface GraphQLRequest<Variables extends GraphQLVariables> extends Mock
35
35
  export declare class GraphQLHandler<Request extends GraphQLRequest<any> = GraphQLRequest<any>> extends RequestHandler<GraphQLHandlerInfo, Request, ParsedGraphQLRequest | null, GraphQLRequest<any>> {
36
36
  private endpoint;
37
37
  constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Mask, resolver: ResponseResolver<any, any>);
38
- parse(request: MockedRequest): ParsedGraphQLRequest<Record<string, any>>;
38
+ parse(request: MockedRequest): ParsedGraphQLRequest<GraphQLVariables>;
39
39
  protected getPublicRequest(request: Request, parsedResult: ParsedGraphQLRequest): GraphQLRequest<any>;
40
40
  predicate(request: MockedRequest, parsedResult: ParsedGraphQLRequest): boolean;
41
41
  log(request: Request, response: ResponseWithSerializedHeaders<any>): void;
@@ -1,11 +1,11 @@
1
1
  import { Headers } from 'headers-utils';
2
- import { ResponseTransformer, MockedResponse, ResponseComposition } from '../response';
2
+ import { MockedResponse, ResponseComposition } from '../response';
3
3
  import { set } from '../context/set';
4
4
  export declare const defaultContext: {
5
- status: (statusCode: number, statusText?: string | undefined) => ResponseTransformer<any>;
5
+ status: (statusCode: number, statusText?: string | undefined) => import("../response").ResponseTransformer<any>;
6
6
  set: typeof set;
7
- delay: (durationOrMode?: number | "real" | "infinite" | undefined) => ResponseTransformer<any>;
8
- fetch: (input: string | MockedRequest<DefaultRequestBody>, requestInit?: RequestInit) => any;
7
+ delay: (durationOrMode?: number | import("../context/delay").DelayMode | undefined) => import("../response").ResponseTransformer<any>;
8
+ fetch: (input: string | MockedRequest<DefaultRequestBody>, requestInit?: RequestInit) => Promise<Response>;
9
9
  };
10
10
  export declare type DefaultRequestMultipartBody = Record<string, string | File | (string | File)[]>;
11
11
  export declare type DefaultRequestBody = Record<string, any> | DefaultRequestMultipartBody | string | undefined;
@@ -33,7 +33,7 @@ interface RequestHandlerDefaultInfo {
33
33
  declare type RequestHandlerInfo<ExtraInfo extends Record<string, any>> = {
34
34
  header: string;
35
35
  } & ExtraInfo;
36
- declare type ContextMap = Record<string, (...args: any) => ResponseTransformer>;
36
+ declare type ContextMap = Record<string, (...args: any[]) => any>;
37
37
  export declare type ResponseResolverReturnType<R> = R | undefined | void;
38
38
  export declare type AsyncResponseResolverReturnType<R> = Promise<ResponseResolverReturnType<R>> | ResponseResolverReturnType<R>;
39
39
  export declare type ResponseResolver<RequestType = MockedRequest, ContextType = typeof defaultContext, BodyType = any> = (req: RequestType, res: ResponseComposition<BodyType>, context: ContextType) => AsyncResponseResolverReturnType<MockedResponse<BodyType>>;
@@ -61,7 +61,7 @@ export declare abstract class RequestHandler<HandlerInfo extends Record<string,
61
61
  /**
62
62
  * Print out the successfully handled request.
63
63
  */
64
- abstract log(request: Request, res: any, handler: this, parsedResilt: ParsedResult): void;
64
+ abstract log(request: Request, res: any, handler: this, parsedResult: ParsedResult): void;
65
65
  /**
66
66
  * Parse the captured request to extract additional information from it.
67
67
  * Parsed result is then exposed to other methods of this request handler.
@@ -5,7 +5,7 @@ export { SetupWorkerApi } from './setupWorker/glossary';
5
5
  export { response, defaultResponse, createResponseComposition, MockedResponse, ResponseTransformer, ResponseComposition, ResponseCompositionOptions, ResponseFunction, } from './response';
6
6
  export { RequestHandler, MockedRequest, ResponseResolver, ResponseResolverReturnType, AsyncResponseResolverReturnType, DefaultRequestBody, DefaultRequestMultipartBody, defaultContext, } from './handlers/RequestHandler';
7
7
  export { rest } from './rest';
8
- export { RESTMethods, RestContext, RequestParams, RequestQuery, RestRequest, ParsedRestRequest, restContext, } from './handlers/RestHandler';
8
+ export { RestHandler, RESTMethods, RestContext, RequestParams, RequestQuery, RestRequest, ParsedRestRequest, restContext, } from './handlers/RestHandler';
9
9
  export { graphql } from './graphql';
10
10
  export { GraphQLHandler, GraphQLContext, GraphQLVariables, GraphQLRequest, GraphQLRequestBody, GraphQLJsonRequestBody, graphqlContext, } from './handlers/GraphQLHandler';
11
11
  export { matchRequestUrl } from './utils/matching/matchRequestUrl';
@@ -1,4 +1,4 @@
1
- import { Interceptor } from 'node-request-interceptor';
1
+ import { Interceptor } from '@mswjs/interceptors';
2
2
  import { SetupServerApi } from './glossary';
3
3
  import { RequestHandler } from '../handlers/RequestHandler';
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { MockedResponse as MockedInterceptedResponse } from 'node-request-interceptor';
1
+ import { IsomorphicResponse } from '@mswjs/interceptors';
2
2
  import { MockedRequest, RequestHandler } from '../handlers/RequestHandler';
3
3
  import { SharedOptions } from '../sharedOptions';
4
4
  export interface ServerLifecycleEventsMap {
@@ -6,8 +6,8 @@ export interface ServerLifecycleEventsMap {
6
6
  'request:match': (request: MockedRequest) => void;
7
7
  'request:unhandled': (request: MockedRequest) => void;
8
8
  'request:end': (request: MockedRequest) => void;
9
- 'response:mocked': (response: MockedInterceptedResponse, requestId: string) => void;
10
- 'response:bypass': (response: MockedInterceptedResponse, requestId: string) => void;
9
+ 'response:mocked': (response: IsomorphicResponse, requestId: string) => void;
10
+ 'response:bypass': (response: IsomorphicResponse, requestId: string) => void;
11
11
  }
12
12
  export interface SetupServerApi {
13
13
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Sets up a requests interception in NodeJS with the given request handlers.
2
+ * Sets up a requests interception in Node.js with the given request handlers.
3
3
  * @param {RequestHandler[]} requestHandlers List of request handlers.
4
4
  * @see {@link https://mswjs.io/docs/api/setup-server `setupServer`}
5
5
  */
@@ -1,13 +1,14 @@
1
- declare type ArityOneFn = (arg: any) => any;
2
- declare type PickLastInTuple<T extends any[]> = T extends [
3
- ...rest: infer U,
4
- argn: infer L
5
- ] ? L : never;
6
- declare type FirstFnParameterType<T extends any[]> = Parameters<PickLastInTuple<T>>[any];
7
- declare type LastFnParameterType<T extends any[]> = ReturnType<T[0]>;
1
+ declare type ArityOneFunction = (arg: any) => any;
2
+ declare type LengthOfTuple<Tuple extends any[]> = Tuple extends {
3
+ length: infer L;
4
+ } ? L : never;
5
+ declare type DropFirstInTuple<Tuple extends any[]> = ((...args: Tuple) => any) extends (arg: any, ...rest: infer LastArg) => any ? LastArg : Tuple;
6
+ declare type LastInTuple<Tuple extends any[]> = Tuple[LengthOfTuple<DropFirstInTuple<Tuple>>];
7
+ declare type FirstFnParameterType<Functions extends ArityOneFunction[]> = Parameters<LastInTuple<Functions>>[any];
8
+ declare type LastFnParameterType<Functions extends ArityOneFunction[]> = ReturnType<Functions[0]>;
8
9
  /**
9
10
  * Composes a given list of functions into a new function that
10
11
  * executes from right to left.
11
12
  */
12
- export declare function compose<T extends ArityOneFn[], LeftReturnType extends FirstFnParameterType<T>, RightReturnType extends LastFnParameterType<T>>(...fns: T): (...args: LeftReturnType extends never ? never[] : [LeftReturnType]) => RightReturnType;
13
+ export declare function compose<Functions extends ArityOneFunction[], LeftReturnType extends FirstFnParameterType<Functions>, RightReturnType extends LastFnParameterType<Functions>>(...fns: Functions): (...args: [LeftReturnType] extends [never] ? never[] : [LeftReturnType]) => RightReturnType;
13
14
  export {};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Returns a boolean indicating if the current process is running in NodeJS environment.
2
+ * Returns a boolean indicating if the current process is running in Node.js environment.
3
3
  * @see https://github.com/mswjs/msw/pull/255
4
4
  */
5
5
  export declare function isNodeProcess(): boolean | undefined;
@@ -8,5 +8,5 @@ export declare function prepareResponse(res: ResponseWithSerializedHeaders<any>)
8
8
  statusText: string;
9
9
  once: boolean;
10
10
  delay?: number | undefined;
11
- headers: import("headers-utils/lib").HeadersList;
11
+ headers: import("headers-utils").HeadersList;
12
12
  };