@zimic/interceptor 0.14.0-canary.21 → 0.14.0-canary.23
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/dist/{chunk-JIUQ7G6N.js → chunk-BJLJWEVE.js} +2 -2
- package/dist/chunk-BJLJWEVE.js.map +1 -0
- package/dist/{chunk-5ESJW32X.mjs → chunk-QSY6YMZ7.mjs} +2 -2
- package/dist/chunk-QSY6YMZ7.mjs.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +18 -15
- package/dist/http.js.map +1 -1
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +5 -5
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/src/http/interceptor/factory.ts +6 -6
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +3 -3
- package/src/http/requestHandler/types/requests.ts +9 -3
- package/src/http/requestHandler/types/restrictions.ts +8 -8
- package/dist/chunk-5ESJW32X.mjs.map +0 -1
- package/dist/chunk-JIUQ7G6N.js.map +0 -1
package/dist/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpMethodSchema, HttpStatusCode, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody,
|
|
2
|
-
import { Default, PossiblePromise, ReplaceBy, IfNever, DeepPartial, Range } from '@zimic/utils/types';
|
|
1
|
+
import { HttpMethodSchema, HttpStatusCode, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
|
|
2
|
+
import { Default, PossiblePromise, ReplaceBy, PartialByKey, IfNever, DeepPartial, Range } from '@zimic/utils/types';
|
|
3
3
|
|
|
4
4
|
type HttpRequestHandlerResponseWithBody<ResponseSchema extends HttpResponseSchema> = unknown extends ResponseSchema['body'] ? {
|
|
5
5
|
body?: null;
|
|
@@ -8,10 +8,13 @@ type HttpRequestHandlerResponseWithBody<ResponseSchema extends HttpResponseSchem
|
|
|
8
8
|
} : {
|
|
9
9
|
body: ReplaceBy<ResponseSchema['body'], ArrayBuffer, Blob>;
|
|
10
10
|
};
|
|
11
|
+
type HttpRequestHandlerResponseHeaders<ResponseSchema extends HttpResponseSchema> = HttpHeadersInit<PartialByKey<Default<ResponseSchema['headers']>, 'content-type'>>;
|
|
11
12
|
type HttpRequestHandlerResponseWithHeaders<ResponseSchema extends HttpResponseSchema> = undefined extends ResponseSchema['headers'] ? {
|
|
12
|
-
headers?:
|
|
13
|
+
headers?: HttpRequestHandlerResponseHeaders<ResponseSchema>;
|
|
14
|
+
} : keyof ResponseSchema['headers'] extends 'content-type' ? {
|
|
15
|
+
headers?: HttpRequestHandlerResponseHeaders<ResponseSchema>;
|
|
13
16
|
} : {
|
|
14
|
-
headers:
|
|
17
|
+
headers: HttpRequestHandlerResponseHeaders<ResponseSchema>;
|
|
15
18
|
};
|
|
16
19
|
/** A declaration of an HTTP response for an intercepted request. */
|
|
17
20
|
type HttpRequestHandlerResponseDeclaration<MethodSchema extends HttpMethodSchema = HttpMethodSchema, StatusCode extends HttpStatusCode = HttpStatusCode> = StatusCode extends StatusCode ? {
|
|
@@ -237,42 +240,42 @@ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Sche
|
|
|
237
240
|
*
|
|
238
241
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
239
242
|
*/
|
|
240
|
-
type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema,
|
|
243
|
+
type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
|
|
241
244
|
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
|
|
242
245
|
/**
|
|
243
246
|
* A static search params restriction to match intercepted requests.
|
|
244
247
|
*
|
|
245
248
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
246
249
|
*/
|
|
247
|
-
type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema,
|
|
250
|
+
type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
|
|
248
251
|
type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
|
|
249
252
|
/**
|
|
250
253
|
* A static body restriction to match intercepted requests.
|
|
251
254
|
*
|
|
252
255
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
253
256
|
*/
|
|
254
|
-
type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema,
|
|
257
|
+
type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
255
258
|
/**
|
|
256
259
|
* A static restriction to match intercepted requests.
|
|
257
260
|
*
|
|
258
261
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
259
262
|
*/
|
|
260
|
-
interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema,
|
|
263
|
+
interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
|
|
261
264
|
/**
|
|
262
265
|
* A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
|
|
263
266
|
* must contain exactly these headers and no others.
|
|
264
267
|
*/
|
|
265
|
-
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema,
|
|
268
|
+
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
|
|
266
269
|
/**
|
|
267
270
|
* A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
|
|
268
271
|
* request must contain exactly these search params and no others.
|
|
269
272
|
*/
|
|
270
|
-
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema,
|
|
273
|
+
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
|
|
271
274
|
/**
|
|
272
275
|
* The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
|
|
273
276
|
* contain exactly this body and no other.
|
|
274
277
|
*/
|
|
275
|
-
body?: HttpRequestHandlerBodyStaticRestriction<Schema,
|
|
278
|
+
body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
|
|
276
279
|
/**
|
|
277
280
|
* If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
|
|
278
281
|
* Otherwise, the request must contain **at least** them.
|
|
@@ -290,7 +293,7 @@ type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method ext
|
|
|
290
293
|
*
|
|
291
294
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
|
|
292
295
|
*/
|
|
293
|
-
type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema,
|
|
296
|
+
type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
|
|
294
297
|
interface RestrictionDiff<Value> {
|
|
295
298
|
expected: Value;
|
|
296
299
|
received: Value;
|
|
@@ -1104,9 +1107,9 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1104
1107
|
* @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
|
|
1105
1108
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
|
|
1106
1109
|
*/
|
|
1107
|
-
declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<
|
|
1108
|
-
declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<
|
|
1109
|
-
declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<
|
|
1110
|
+
declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<Schema>;
|
|
1111
|
+
declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
|
|
1112
|
+
declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
|
|
1110
1113
|
|
|
1111
1114
|
/** Default HTTP interceptor settings. */
|
|
1112
1115
|
declare class HttpInterceptorNamespaceDefault {
|