msw 0.41.1 → 0.42.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as ResponseTransformer, s as status, a as set, d as delay, f as fetch, b as RequestHandler, S as SetupWorkerApi, D as DefaultContext, c as DefaultBodyType, M as MockedRequest, e as ResponseResolver, g as ResponseResolutionContext, h as SerializedResponse, i as RequestHandlerDefaultInfo, j as MockedResponse, k as ResponseLookupResult, l as SharedOptions, m as ServerLifecycleEventsMap } from './glossary-eda04a15.js';
2
- export { A as AsyncResponseResolverReturnType, c as DefaultBodyType, u as DefaultRequestMultipartBody, y as DelayMode, M as MockedRequest, j as MockedResponse, b as RequestHandler, v as ResponseComposition, w as ResponseCompositionOptions, x as ResponseFunction, e as ResponseResolver, t as ResponseResolverReturnType, R as ResponseTransformer, S as SetupWorkerApi, l as SharedOptions, q as StartOptions, o as createResponseComposition, p as defaultContext, n as defaultResponse, r as response } from './glossary-eda04a15.js';
1
+ import { R as ResponseTransformer, s as status, a as set, d as delay, f as fetch, b as RequestHandler, S as SetupWorkerApi, D as DefaultContext, c as DefaultBodyType, M as MockedRequest, e as ResponseResolver, g as ResponseResolutionContext, h as SerializedResponse, i as RequestHandlerDefaultInfo, j as MockedResponse, k as ResponseLookupResult, l as SharedOptions, m as ServerLifecycleEventsMap } from './glossary-58eca5a8.js';
2
+ export { A as AsyncResponseResolverReturnType, c as DefaultBodyType, u as DefaultRequestMultipartBody, y as DelayMode, M as MockedRequest, j as MockedResponse, b as RequestHandler, v as ResponseComposition, w as ResponseCompositionOptions, x as ResponseFunction, e as ResponseResolver, t as ResponseResolverReturnType, R as ResponseTransformer, S as SetupWorkerApi, l as SharedOptions, q as StartOptions, o as createResponseComposition, p as defaultContext, n as defaultResponse, r as response } from './glossary-58eca5a8.js';
3
3
  import * as cookieUtils from 'cookie';
4
4
  import { GraphQLError, OperationTypeNode, DocumentNode } from 'graphql';
5
5
  import { StrictEventEmitter } from 'strict-event-emitter';
@@ -7,6 +7,25 @@ import { IsomorphicRequest } from '@mswjs/interceptors';
7
7
  import 'type-fest';
8
8
  import 'headers-polyfill';
9
9
 
10
+ declare type Path = string | RegExp;
11
+ declare type PathParams<KeyType extends keyof any = string> = {
12
+ [ParamName in KeyType]: string | ReadonlyArray<string>;
13
+ };
14
+ interface Match {
15
+ matches: boolean;
16
+ params?: PathParams;
17
+ }
18
+ /**
19
+ * Returns the result of matching given request URL against a mask.
20
+ */
21
+ declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
22
+
23
+ declare type Fn = (...arg: any[]) => any;
24
+ declare type RequiredDeep<Type, U extends Record<string, unknown> | Fn | undefined = undefined> = Type extends Fn ? Type : Type extends Record<string, any> ? {
25
+ [Key in keyof Type]-?: NonNullable<Type[Key]> extends NonNullable<U> ? NonNullable<Type[Key]> : RequiredDeep<NonNullable<Type[Key]>, U>;
26
+ } : Type;
27
+ declare type GraphQLPayloadContext<QueryType extends Record<string, unknown>> = (payload: QueryType) => ResponseTransformer;
28
+
10
29
  /**
11
30
  * Sets a given cookie on the mocked response.
12
31
  * @example res(ctx.cookie('name', 'value'))
@@ -20,13 +39,7 @@ declare const cookie: (name: string, value: string, options?: cookieUtils.Cookie
20
39
  * res(ctx.body(JSON.stringify({ key: 'value' })))
21
40
  * @see {@link https://mswjs.io/docs/api/context/body `ctx.body()`}
22
41
  */
23
- declare const body: <BodyType extends string | Blob | BufferSource | ReadableStream<any> | FormData>(value: BodyType) => ResponseTransformer<BodyType, any>;
24
-
25
- declare type Fn = (...arg: any[]) => any;
26
- declare type RequiredDeep<Type, U extends Record<string, unknown> | Fn | undefined = undefined> = Type extends Fn ? Type : Type extends Record<string, any> ? {
27
- [Key in keyof Type]-?: NonNullable<Type[Key]> extends NonNullable<U> ? NonNullable<Type[Key]> : RequiredDeep<NonNullable<Type[Key]>, U>;
28
- } : Type;
29
- declare type GraphQLPayloadContext<QueryType extends Record<string, unknown>> = (payload: QueryType) => ResponseTransformer;
42
+ declare const body: <BodyType extends string | Blob | BufferSource | FormData | ReadableStream<any>>(value: BodyType) => ResponseTransformer<BodyType, any>;
30
43
 
31
44
  /**
32
45
  * Sets a given payload as a GraphQL response body.
@@ -51,19 +64,6 @@ declare const extensions: GraphQLPayloadContext<Record<string, unknown>>;
51
64
  */
52
65
  declare const errors: <ErrorsType extends readonly Partial<GraphQLError>[] | null | undefined>(errorsList: ErrorsType) => ResponseTransformer<string>;
53
66
 
54
- declare type Path = string | RegExp;
55
- declare type PathParams<KeyType extends keyof any = string> = {
56
- [ParamName in KeyType]: string | ReadonlyArray<string>;
57
- };
58
- interface Match {
59
- matches: boolean;
60
- params?: PathParams;
61
- }
62
- /**
63
- * Returns the result of matching given request URL against a mask.
64
- */
65
- declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
66
-
67
67
  /**
68
68
  * Sets the given value as the JSON body of the response.
69
69
  * Appends a `Content-Type: application/json` header on the
@@ -183,6 +183,14 @@ declare const rest: {
183
183
  options: <RequestBodyType_7 extends DefaultBodyType = DefaultBodyType, Params_7 extends PathParams<keyof Params_7> = PathParams<string>, ResponseBody_7 extends DefaultBodyType = DefaultBodyType>(path: Path, resolver: ResponseResolver<RestRequest<RequestBodyType_7, Params_7>, RestContext, ResponseBody_7>) => RestHandler<MockedRequest<DefaultBodyType>>;
184
184
  };
185
185
 
186
+ declare type ForbiddenFieldNames = '' | 'data' | 'errors' | 'extensions';
187
+ /**
188
+ * Set a custom field on the GraphQL mocked response.
189
+ * @example res(ctx.fields('customField', value))
190
+ * @see {@link https://mswjs.io/docs/api/context/field}
191
+ */
192
+ declare const field: <FieldNameType extends string, FieldValueType>(fieldName: FieldNameType extends ForbiddenFieldNames ? never : FieldNameType, fieldValue: FieldValueType) => ResponseTransformer<string>;
193
+
186
194
  interface ParsedGraphQLQuery {
187
195
  operationType: OperationTypeNode;
188
196
  operationName?: string;
@@ -204,6 +212,7 @@ declare type GraphQLContext<QueryType extends Record<string, unknown>> = Default
204
212
  extensions: GraphQLPayloadContext<QueryType>;
205
213
  errors: typeof errors;
206
214
  cookie: typeof cookie;
215
+ field: typeof field;
207
216
  };
208
217
  declare const graphqlContext: GraphQLContext<any>;
209
218
  declare type GraphQLVariables = Record<string, any>;