msw 0.48.3 → 0.49.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/{SetupApi-8ab693f7.d.ts → SetupApi-b2f0e5ac.d.ts} +31 -31
- package/lib/{SetupServerApi-544775c7.d.ts → SetupServerApi-70cc71a7.d.ts} +2 -2
- package/lib/{glossary-afbab737.d.ts → glossary-a30fab39.d.ts} +2 -2
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +26 -37
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.ts +2 -2
- package/lib/node/index.d.ts +4 -4
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { R as ResponseTransformer, s as status, a as set, d as delay, f as fetch, b as RequestHandler, S as
|
|
2
|
-
export { A as AsyncResponseResolverReturnType,
|
|
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 } from './SetupApi-b2f0e5ac.js';
|
|
2
|
+
export { A as AsyncResponseResolverReturnType, c as DefaultBodyType, u as DefaultRequestMultipartBody, y as DelayMode, M as MockedRequest, H as MockedRequestInit, j as MockedResponse, z as RequestCache, E as RequestDestination, b as RequestHandler, B as RequestMode, F as RequestPriority, C as RequestRedirect, G as RequestReferrerPolicy, v as ResponseComposition, w as ResponseCompositionOptions, x as ResponseFunction, e as ResponseResolver, t as ResponseResolverReturnType, R as ResponseTransformer, m as SetupApi, S as SetupWorkerApi, l as SharedOptions, q as StartOptions, o as createResponseComposition, p as defaultContext, n as defaultResponse, r as response } from './SetupApi-b2f0e5ac.js';
|
|
3
3
|
import * as cookieUtils from 'cookie';
|
|
4
4
|
import { GraphQLError, OperationTypeNode, DocumentNode } from 'graphql';
|
|
5
5
|
import { StrictEventEmitter } from 'strict-event-emitter';
|
|
6
|
-
import { S as ServerLifecycleEventsMap } from './glossary-
|
|
6
|
+
import { S as ServerLifecycleEventsMap } from './glossary-a30fab39.js';
|
|
7
7
|
import 'headers-polyfill';
|
|
8
8
|
import '@mswjs/interceptors';
|
|
9
9
|
import 'type-fest';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
type Path = string | RegExp;
|
|
12
|
+
type PathParams<KeyType extends keyof any = string> = {
|
|
13
13
|
[ParamName in KeyType]: string | ReadonlyArray<string>;
|
|
14
14
|
};
|
|
15
15
|
interface Match {
|
|
@@ -21,11 +21,11 @@ interface Match {
|
|
|
21
21
|
*/
|
|
22
22
|
declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
type Fn = (...arg: any[]) => any;
|
|
25
|
+
type RequiredDeep<Type, U extends Record<string, unknown> | Fn | undefined = undefined> = Type extends Fn ? Type : Type extends Record<string, any> ? {
|
|
26
26
|
[Key in keyof Type]-?: NonNullable<Type[Key]> extends NonNullable<U> ? NonNullable<Type[Key]> : RequiredDeep<NonNullable<Type[Key]>, U>;
|
|
27
27
|
} : Type;
|
|
28
|
-
|
|
28
|
+
type GraphQLPayloadContext<QueryType extends Record<string, unknown>> = (payload: QueryType) => ResponseTransformer;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Sets a given cookie on the mocked response.
|
|
@@ -123,17 +123,6 @@ declare namespace index {
|
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
declare class SetupWorkerApi extends SetupApi<WorkerLifecycleEventsMap> {
|
|
127
|
-
private context;
|
|
128
|
-
private startHandler;
|
|
129
|
-
private stopHandler;
|
|
130
|
-
private listeners;
|
|
131
|
-
constructor(...handlers: Array<RequestHandler>);
|
|
132
|
-
private createWorkerContext;
|
|
133
|
-
start(options?: StartOptions): StartReturnType;
|
|
134
|
-
printHandlers(): void;
|
|
135
|
-
stop(): void;
|
|
136
|
-
}
|
|
137
126
|
/**
|
|
138
127
|
* Sets up a requests interception in the browser with the given request handlers.
|
|
139
128
|
* @param {RequestHandler[]} handlers List of request handlers.
|
|
@@ -141,7 +130,7 @@ declare class SetupWorkerApi extends SetupApi<WorkerLifecycleEventsMap> {
|
|
|
141
130
|
*/
|
|
142
131
|
declare function setupWorker(...handlers: Array<RequestHandler>): SetupWorkerApi;
|
|
143
132
|
|
|
144
|
-
|
|
133
|
+
type RestHandlerMethod = string | RegExp;
|
|
145
134
|
interface RestHandlerInfo extends RequestHandlerDefaultInfo {
|
|
146
135
|
method: RestHandlerMethod;
|
|
147
136
|
path: Path;
|
|
@@ -155,7 +144,7 @@ declare enum RESTMethods {
|
|
|
155
144
|
OPTIONS = "OPTIONS",
|
|
156
145
|
DELETE = "DELETE"
|
|
157
146
|
}
|
|
158
|
-
|
|
147
|
+
type RestContext = DefaultContext & {
|
|
159
148
|
cookie: typeof cookie;
|
|
160
149
|
text: typeof text;
|
|
161
150
|
body: typeof body;
|
|
@@ -163,10 +152,10 @@ declare type RestContext = DefaultContext & {
|
|
|
163
152
|
xml: typeof xml;
|
|
164
153
|
};
|
|
165
154
|
declare const restContext: RestContext;
|
|
166
|
-
|
|
155
|
+
type RequestQuery = {
|
|
167
156
|
[queryName: string]: string;
|
|
168
157
|
};
|
|
169
|
-
|
|
158
|
+
type ParsedRestRequest = Match;
|
|
170
159
|
declare class RestRequest<RequestBody extends DefaultBodyType = DefaultBodyType, RequestParams extends PathParams = PathParams> extends MockedRequest<RequestBody> {
|
|
171
160
|
readonly params: RequestParams;
|
|
172
161
|
constructor(request: MockedRequest<RequestBody>, params: RequestParams);
|
|
@@ -195,7 +184,7 @@ declare const rest: {
|
|
|
195
184
|
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>>;
|
|
196
185
|
};
|
|
197
186
|
|
|
198
|
-
|
|
187
|
+
type ForbiddenFieldNames = '' | 'data' | 'errors' | 'extensions';
|
|
199
188
|
/**
|
|
200
189
|
* Set a custom field on the GraphQL mocked response.
|
|
201
190
|
* @example res(ctx.fields('customField', value))
|
|
@@ -207,19 +196,19 @@ interface ParsedGraphQLQuery {
|
|
|
207
196
|
operationType: OperationTypeNode;
|
|
208
197
|
operationName?: string;
|
|
209
198
|
}
|
|
210
|
-
|
|
199
|
+
type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
211
200
|
variables?: VariablesType;
|
|
212
201
|
}) | undefined;
|
|
213
|
-
|
|
202
|
+
type GraphQLMultipartRequestBody = {
|
|
214
203
|
operations: string;
|
|
215
204
|
map?: string;
|
|
216
205
|
} & {
|
|
217
206
|
[fileName: string]: File;
|
|
218
207
|
};
|
|
219
208
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
210
|
+
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
211
|
+
type GraphQLContext<QueryType extends Record<string, unknown>> = DefaultContext & {
|
|
223
212
|
data: GraphQLPayloadContext<QueryType>;
|
|
224
213
|
extensions: GraphQLPayloadContext<QueryType>;
|
|
225
214
|
errors: typeof errors;
|
|
@@ -227,12 +216,12 @@ declare type GraphQLContext<QueryType extends Record<string, unknown>> = Default
|
|
|
227
216
|
field: typeof field;
|
|
228
217
|
};
|
|
229
218
|
declare const graphqlContext: GraphQLContext<any>;
|
|
230
|
-
|
|
219
|
+
type GraphQLVariables = Record<string, any>;
|
|
231
220
|
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
232
221
|
operationType: ExpectedOperationTypeNode;
|
|
233
222
|
operationName: GraphQLHandlerNameSelector;
|
|
234
223
|
}
|
|
235
|
-
|
|
224
|
+
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
236
225
|
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
237
226
|
query: string;
|
|
238
227
|
variables?: Variables;
|
|
@@ -320,14 +309,14 @@ declare const graphql: {
|
|
|
320
309
|
mutation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query_1, Variables_1>, resolver: ResponseResolver<GraphQLRequest<Variables_1>, GraphQLContext<Query_1>, any>) => GraphQLHandler<GraphQLRequest<Variables_1>>;
|
|
321
310
|
};
|
|
322
311
|
|
|
323
|
-
|
|
324
|
-
|
|
312
|
+
type ArityOneFunction = (arg: any) => any;
|
|
313
|
+
type LengthOfTuple<Tuple extends any[]> = Tuple extends {
|
|
325
314
|
length: infer L;
|
|
326
315
|
} ? L : never;
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
316
|
+
type DropFirstInTuple<Tuple extends any[]> = ((...args: Tuple) => any) extends (arg: any, ...rest: infer LastArg) => any ? LastArg : Tuple;
|
|
317
|
+
type LastInTuple<Tuple extends any[]> = Tuple[LengthOfTuple<DropFirstInTuple<Tuple>>];
|
|
318
|
+
type FirstFnParameterType<Functions extends ArityOneFunction[]> = Parameters<LastInTuple<Functions>>[any];
|
|
319
|
+
type LastFnParameterType<Functions extends ArityOneFunction[]> = ReturnType<Functions[0]>;
|
|
331
320
|
/**
|
|
332
321
|
* Composes a given list of functions into a new function that
|
|
333
322
|
* executes from right to left.
|