@zimic/interceptor 0.17.3 → 0.18.0-canary.0
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/README.md +1 -1
- package/dist/{chunk-2JEHCG37.mjs → chunk-5OWHKUTM.mjs} +14 -5
- package/dist/chunk-5OWHKUTM.mjs.map +1 -0
- package/dist/{chunk-HPY7FBKU.js → chunk-D6W4BBTC.js} +13 -4
- package/dist/chunk-D6W4BBTC.js.map +1 -0
- package/dist/cli.js +18 -18
- 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 +24 -20
- package/dist/http.js +9 -2
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +10 -3
- package/dist/http.mjs.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +5 -5
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +2 -2
- package/src/http/requestHandler/types/requests.ts +29 -21
- package/src/http/requestHandler/types/restrictions.ts +4 -4
- package/src/utils/http.ts +16 -13
- package/dist/chunk-2JEHCG37.mjs.map +0 -1
- package/dist/chunk-HPY7FBKU.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD6W4BBTC_js = require('./chunk-D6W4BBTC.js');
|
|
4
4
|
require('./chunk-WCQVDF3K.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "DEFAULT_ACCESS_CONTROL_HEADERS", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkD6W4BBTC_js.DEFAULT_ACCESS_CONTROL_HEADERS; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "DEFAULT_PREFLIGHT_STATUS_CODE", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkD6W4BBTC_js.DEFAULT_PREFLIGHT_STATUS_CODE; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "NotRunningInterceptorServerError", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkD6W4BBTC_js.NotRunningInterceptorServerError_default; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "RunningInterceptorServerError", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkD6W4BBTC_js.RunningInterceptorServerError_default; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "createInterceptorServer", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkD6W4BBTC_js.createInterceptorServer; }
|
|
27
27
|
});
|
|
28
28
|
//# sourceMappingURL=server.js.map
|
|
29
29
|
//# sourceMappingURL=server.js.map
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, NotRunningInterceptorServerError_default as NotRunningInterceptorServerError, RunningInterceptorServerError_default as RunningInterceptorServerError, createInterceptorServer } from './chunk-
|
|
1
|
+
export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, NotRunningInterceptorServerError_default as NotRunningInterceptorServerError, RunningInterceptorServerError_default as RunningInterceptorServerError, createInterceptorServer } from './chunk-5OWHKUTM.mjs';
|
|
2
2
|
import './chunk-CGILA3WO.mjs';
|
|
3
3
|
//# sourceMappingURL=server.mjs.map
|
|
4
4
|
//# sourceMappingURL=server.mjs.map
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"api",
|
|
15
15
|
"static"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.18.0-canary.0",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/zimicjs/zimic.git",
|
|
@@ -99,14 +99,14 @@
|
|
|
99
99
|
"tsup": "^8.4.0",
|
|
100
100
|
"typescript": "^5.8.3",
|
|
101
101
|
"vitest": "^3.1.2",
|
|
102
|
-
"@zimic/
|
|
102
|
+
"@zimic/eslint-config-node": "0.0.0",
|
|
103
103
|
"@zimic/tsconfig": "0.0.0",
|
|
104
|
-
"@zimic/
|
|
105
|
-
"@zimic/
|
|
104
|
+
"@zimic/lint-staged-config": "0.0.0",
|
|
105
|
+
"@zimic/utils": "0.0.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"typescript": ">=4.8.0",
|
|
109
|
-
"@zimic/http": "^0.
|
|
109
|
+
"@zimic/http": "^0.4.0 || 0.4.0-canary.1"
|
|
110
110
|
},
|
|
111
111
|
"peerDependenciesMeta": {
|
|
112
112
|
"typescript": {
|
|
@@ -230,7 +230,7 @@ class HttpRequestHandlerClient<
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
const restrictedHeaders = new HttpHeaders(
|
|
233
|
-
restriction.headers as HttpRequestHeadersSchema<Default<Schema[Path][Method]
|
|
233
|
+
restriction.headers as Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>,
|
|
234
234
|
);
|
|
235
235
|
|
|
236
236
|
const matchesRestriction = restriction.exact
|
|
@@ -254,7 +254,7 @@ class HttpRequestHandlerClient<
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
const restrictedSearchParams = new HttpSearchParams(
|
|
257
|
-
restriction.searchParams as HttpRequestSearchParamsSchema<Default<Schema[Path][Method]
|
|
257
|
+
restriction.searchParams as Default<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>,
|
|
258
258
|
);
|
|
259
259
|
|
|
260
260
|
const matchesRestriction = restriction.exact
|
|
@@ -14,35 +14,43 @@ import {
|
|
|
14
14
|
HttpStatusCode,
|
|
15
15
|
InferPathParams,
|
|
16
16
|
} from '@zimic/http';
|
|
17
|
-
import { Default, PartialByKey, PossiblePromise
|
|
17
|
+
import { Default, PartialByKey, PossiblePromise } from '@zimic/utils/types';
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
? { body?: ReplaceBy<ReplaceBy<ResponseSchema['body'], undefined, null>, ArrayBuffer, Blob> }
|
|
24
|
-
: { body: ReplaceBy<ResponseSchema['body'], ArrayBuffer, Blob> };
|
|
19
|
+
type HttpRequestHandlerResponseBody<
|
|
20
|
+
ResponseSchema extends HttpResponseSchema,
|
|
21
|
+
StatusCode extends HttpStatusCode,
|
|
22
|
+
> = HttpResponseBodySchema<{ response: { [Code in StatusCode]: ResponseSchema } }, StatusCode>;
|
|
25
23
|
|
|
26
|
-
type
|
|
24
|
+
export type HttpRequestHandlerResponseWithBody<
|
|
25
|
+
ResponseSchema extends HttpResponseSchema,
|
|
26
|
+
StatusCode extends HttpStatusCode,
|
|
27
|
+
> = unknown extends ResponseSchema['body']
|
|
28
|
+
? { body?: null }
|
|
29
|
+
: undefined extends ResponseSchema['body']
|
|
30
|
+
? { body?: HttpRequestHandlerResponseBody<ResponseSchema, StatusCode> }
|
|
31
|
+
: { body: HttpRequestHandlerResponseBody<ResponseSchema, StatusCode> };
|
|
32
|
+
|
|
33
|
+
type HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema extends HttpResponseSchema> = HttpHeadersInit<
|
|
27
34
|
PartialByKey<Default<ResponseSchema['headers']>, 'content-type'>
|
|
28
35
|
>;
|
|
29
36
|
|
|
30
|
-
export type
|
|
37
|
+
export type HttpRequestHandlerResponseDeclarationWithHeaders<ResponseSchema extends HttpResponseSchema> =
|
|
31
38
|
undefined extends ResponseSchema['headers']
|
|
32
|
-
? { headers?:
|
|
33
|
-
: keyof ResponseSchema['headers'] extends 'content-type'
|
|
34
|
-
? { headers?:
|
|
35
|
-
: { headers:
|
|
39
|
+
? { headers?: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema> }
|
|
40
|
+
: Exclude<keyof ResponseSchema['headers'], symbol> extends 'content-type'
|
|
41
|
+
? { headers?: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema> }
|
|
42
|
+
: { headers: HttpRequestHandlerResponseDeclarationHeaders<ResponseSchema> };
|
|
36
43
|
|
|
37
44
|
/** A declaration of an HTTP response for an intercepted request. */
|
|
38
45
|
export type HttpRequestHandlerResponseDeclaration<
|
|
39
46
|
MethodSchema extends HttpMethodSchema = HttpMethodSchema,
|
|
40
47
|
StatusCode extends HttpStatusCode = HttpStatusCode,
|
|
41
48
|
> = StatusCode extends StatusCode
|
|
42
|
-
? {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
? { status: StatusCode } & HttpRequestHandlerResponseWithBody<
|
|
50
|
+
Default<Default<MethodSchema['response']>[StatusCode]>,
|
|
51
|
+
StatusCode
|
|
52
|
+
> &
|
|
53
|
+
HttpRequestHandlerResponseDeclarationWithHeaders<Default<Default<MethodSchema['response']>[StatusCode]>>
|
|
46
54
|
: never;
|
|
47
55
|
|
|
48
56
|
/**
|
|
@@ -66,13 +74,13 @@ export type HttpRequestHandlerResponseDeclarationFactory<
|
|
|
66
74
|
export interface HttpInterceptorRequest<Path extends string, MethodSchema extends HttpMethodSchema>
|
|
67
75
|
extends Omit<HttpRequest, keyof Body | 'headers' | 'clone'> {
|
|
68
76
|
/** The headers of the request. */
|
|
69
|
-
headers: HttpHeaders<HttpRequestHeadersSchema<MethodSchema
|
|
77
|
+
headers: HttpHeaders<Default<HttpRequestHeadersSchema<MethodSchema>>>;
|
|
70
78
|
/** The path parameters of the request. They are parsed from the path string when using dynamic paths. */
|
|
71
79
|
pathParams: InferPathParams<Path>;
|
|
72
80
|
/** The search parameters of the request. */
|
|
73
|
-
searchParams: HttpSearchParams<HttpRequestSearchParamsSchema<MethodSchema
|
|
81
|
+
searchParams: HttpSearchParams<Default<HttpRequestSearchParamsSchema<MethodSchema>>>;
|
|
74
82
|
/** The body of the request. It is already parsed by default. */
|
|
75
|
-
body:
|
|
83
|
+
body: HttpRequestBodySchema<MethodSchema>;
|
|
76
84
|
/** The raw request object. */
|
|
77
85
|
raw: HttpRequest<HttpRequestBodySchema<MethodSchema>>;
|
|
78
86
|
}
|
|
@@ -84,7 +92,7 @@ export interface HttpInterceptorRequest<Path extends string, MethodSchema extend
|
|
|
84
92
|
export interface HttpInterceptorResponse<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode>
|
|
85
93
|
extends Omit<HttpResponse, keyof Body | 'headers' | 'clone'> {
|
|
86
94
|
/** The headers of the response. */
|
|
87
|
-
headers: HttpHeaders<HttpResponseHeadersSchema<MethodSchema, StatusCode
|
|
95
|
+
headers: HttpHeaders<Default<HttpResponseHeadersSchema<MethodSchema, StatusCode>>>;
|
|
88
96
|
/** The status code of the response. */
|
|
89
97
|
status: StatusCode;
|
|
90
98
|
/** The body of the response. It is already parsed by default. */
|
|
@@ -16,7 +16,7 @@ import { IfNever, Default, DeepPartial, PossiblePromise } from '@zimic/utils/typ
|
|
|
16
16
|
|
|
17
17
|
import { HttpInterceptorRequest } from './requests';
|
|
18
18
|
|
|
19
|
-
type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<
|
|
19
|
+
type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema.Loose> = IfNever<
|
|
20
20
|
Schema,
|
|
21
21
|
never,
|
|
22
22
|
Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>
|
|
@@ -31,9 +31,9 @@ export type HttpRequestHandlerHeadersStaticRestriction<
|
|
|
31
31
|
Schema extends HttpSchema,
|
|
32
32
|
Method extends HttpSchemaMethod<Schema>,
|
|
33
33
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
34
|
-
> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]
|
|
34
|
+
> = PartialHttpHeadersOrSchema<Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>>;
|
|
35
35
|
|
|
36
|
-
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<
|
|
36
|
+
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema.Loose> = IfNever<
|
|
37
37
|
Schema,
|
|
38
38
|
never,
|
|
39
39
|
Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>
|
|
@@ -48,7 +48,7 @@ export type HttpRequestHandlerSearchParamsStaticRestriction<
|
|
|
48
48
|
Schema extends HttpSchema,
|
|
49
49
|
Method extends HttpSchemaMethod<Schema>,
|
|
50
50
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
51
|
-
> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]
|
|
51
|
+
> = PartialHttpSearchParamsOrSchema<Default<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>>;
|
|
52
52
|
|
|
53
53
|
type PartialBodyOrSchema<Body extends HttpBody> =
|
|
54
54
|
Body extends HttpFormData<infer Schema>
|
package/src/utils/http.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HTTP_METHODS_WITH_REQUEST_BODY,
|
|
3
|
-
HTTP_METHODS_WITH_RESPONSE_BODY,
|
|
4
|
-
HttpMethod,
|
|
5
|
-
HttpMethodWithRequestBody,
|
|
6
|
-
HttpMethodWithResponseBody,
|
|
7
|
-
} from '@zimic/http';
|
|
1
|
+
import { HttpMethod } from '@zimic/http';
|
|
8
2
|
import { Server as HttpServer } from 'http';
|
|
9
3
|
|
|
10
4
|
class HttpServerTimeoutError extends Error {}
|
|
@@ -98,12 +92,21 @@ export function getHttpServerPort(server: HttpServer) {
|
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
export
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
export const HTTP_METHODS_WITH_REQUEST_BODY = new Set<HttpMethod>(['POST', 'PUT', 'PATCH', 'DELETE']);
|
|
96
|
+
|
|
97
|
+
export function methodCanHaveRequestBody(method: HttpMethod) {
|
|
98
|
+
return HTTP_METHODS_WITH_REQUEST_BODY.has(method);
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
export const HTTP_METHODS_WITH_RESPONSE_BODY = new Set<HttpMethod>([
|
|
102
|
+
'GET',
|
|
103
|
+
'POST',
|
|
104
|
+
'PUT',
|
|
105
|
+
'PATCH',
|
|
106
|
+
'DELETE',
|
|
107
|
+
'OPTIONS',
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
export function methodCanHaveResponseBody(method: HttpMethod) {
|
|
111
|
+
return HTTP_METHODS_WITH_RESPONSE_BODY.has(method);
|
|
109
112
|
}
|