@zimic/interceptor 0.14.0-canary.20 → 0.14.0-canary.22
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/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +12 -12
- package/dist/http.js.map +1 -1
- package/dist/http.mjs.map +1 -1
- package/package.json +3 -3
- package/src/http/interceptor/factory.ts +6 -6
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +3 -3
- package/src/http/requestHandler/types/restrictions.ts +8 -8
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"api",
|
|
15
15
|
"static"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.14.0-canary.
|
|
17
|
+
"version": "0.14.0-canary.22",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/zimicjs/zimic.git",
|
|
@@ -80,8 +80,7 @@
|
|
|
80
80
|
"isomorphic-ws": "5.0.0",
|
|
81
81
|
"msw": "2.7.1",
|
|
82
82
|
"ws": "8.18.1",
|
|
83
|
-
"yargs": "17.7.2"
|
|
84
|
-
"@zimic/utils": "0.0.0"
|
|
83
|
+
"yargs": "17.7.2"
|
|
85
84
|
},
|
|
86
85
|
"optionalDependencies": {
|
|
87
86
|
"bufferutil": "4.0.9"
|
|
@@ -100,6 +99,7 @@
|
|
|
100
99
|
"vitest": "^3.0.6",
|
|
101
100
|
"@zimic/eslint-config-node": "0.0.0",
|
|
102
101
|
"@zimic/lint-staged-config": "0.0.0",
|
|
102
|
+
"@zimic/utils": "0.0.0",
|
|
103
103
|
"@zimic/tsconfig": "0.0.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
@@ -28,22 +28,22 @@ function isRemoteHttpInterceptorOptions(options: HttpInterceptorOptions) {
|
|
|
28
28
|
*/
|
|
29
29
|
export function createHttpInterceptor<Schema extends HttpSchema>(
|
|
30
30
|
options: LocalHttpInterceptorOptions,
|
|
31
|
-
): PublicLocalHttpInterceptor<
|
|
31
|
+
): PublicLocalHttpInterceptor<Schema>;
|
|
32
32
|
export function createHttpInterceptor<Schema extends HttpSchema>(
|
|
33
33
|
options: RemoteHttpInterceptorOptions,
|
|
34
|
-
): PublicRemoteHttpInterceptor<
|
|
34
|
+
): PublicRemoteHttpInterceptor<Schema>;
|
|
35
35
|
export function createHttpInterceptor<Schema extends HttpSchema>(
|
|
36
36
|
options: HttpInterceptorOptions,
|
|
37
|
-
): PublicLocalHttpInterceptor<
|
|
37
|
+
): PublicLocalHttpInterceptor<Schema> | PublicRemoteHttpInterceptor<Schema>;
|
|
38
38
|
export function createHttpInterceptor<Schema extends HttpSchema>(
|
|
39
39
|
options: HttpInterceptorOptions,
|
|
40
|
-
): PublicLocalHttpInterceptor<
|
|
40
|
+
): PublicLocalHttpInterceptor<Schema> | PublicRemoteHttpInterceptor<Schema> {
|
|
41
41
|
const type = options.type;
|
|
42
42
|
|
|
43
43
|
if (isLocalHttpInterceptorOptions(options)) {
|
|
44
|
-
return new LocalHttpInterceptor<
|
|
44
|
+
return new LocalHttpInterceptor<Schema>(options);
|
|
45
45
|
} else if (isRemoteHttpInterceptorOptions(options)) {
|
|
46
|
-
return new RemoteHttpInterceptor<
|
|
46
|
+
return new RemoteHttpInterceptor<Schema>(options);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
throw new UnknownHttpInterceptorTypeError(type);
|
|
@@ -230,7 +230,7 @@ class HttpRequestHandlerClient<
|
|
|
230
230
|
|
|
231
231
|
private matchesRequestHeadersRestrictions(
|
|
232
232
|
request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
|
|
233
|
-
restriction: HttpRequestHandlerStaticRestriction<Schema,
|
|
233
|
+
restriction: HttpRequestHandlerStaticRestriction<Schema, Method, Path>,
|
|
234
234
|
): RestrictionMatchResult<RestrictionDiff<HttpHeaders<never>>> {
|
|
235
235
|
if (restriction.headers === undefined) {
|
|
236
236
|
return { value: true };
|
|
@@ -254,7 +254,7 @@ class HttpRequestHandlerClient<
|
|
|
254
254
|
|
|
255
255
|
private matchesRequestSearchParamsRestrictions(
|
|
256
256
|
request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
|
|
257
|
-
restriction: HttpRequestHandlerStaticRestriction<Schema,
|
|
257
|
+
restriction: HttpRequestHandlerStaticRestriction<Schema, Method, Path>,
|
|
258
258
|
): RestrictionMatchResult<RestrictionDiff<HttpSearchParams<never>>> {
|
|
259
259
|
if (restriction.searchParams === undefined) {
|
|
260
260
|
return { value: true };
|
|
@@ -278,7 +278,7 @@ class HttpRequestHandlerClient<
|
|
|
278
278
|
|
|
279
279
|
private async matchesRequestBodyRestrictions(
|
|
280
280
|
request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>,
|
|
281
|
-
restriction: HttpRequestHandlerStaticRestriction<Schema,
|
|
281
|
+
restriction: HttpRequestHandlerStaticRestriction<Schema, Method, Path>,
|
|
282
282
|
): Promise<RestrictionMatchResult<RestrictionDiff<unknown>>> {
|
|
283
283
|
if (restriction.body === undefined) {
|
|
284
284
|
return { value: true };
|
|
@@ -29,8 +29,8 @@ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<
|
|
|
29
29
|
*/
|
|
30
30
|
export type HttpRequestHandlerHeadersStaticRestriction<
|
|
31
31
|
Schema extends HttpSchema,
|
|
32
|
-
Path extends HttpSchemaPath<Schema, Method>,
|
|
33
32
|
Method extends HttpSchemaMethod<Schema>,
|
|
33
|
+
Path extends HttpSchemaPath<Schema, Method>,
|
|
34
34
|
> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
|
|
35
35
|
|
|
36
36
|
type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<
|
|
@@ -46,8 +46,8 @@ type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = If
|
|
|
46
46
|
*/
|
|
47
47
|
export type HttpRequestHandlerSearchParamsStaticRestriction<
|
|
48
48
|
Schema extends HttpSchema,
|
|
49
|
-
Path extends HttpSchemaPath<Schema, Method>,
|
|
50
49
|
Method extends HttpSchemaMethod<Schema>,
|
|
50
|
+
Path extends HttpSchemaPath<Schema, Method>,
|
|
51
51
|
> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
|
|
52
52
|
|
|
53
53
|
type PartialBodyOrSchema<Body extends HttpBody> =
|
|
@@ -66,8 +66,8 @@ type PartialBodyOrSchema<Body extends HttpBody> =
|
|
|
66
66
|
*/
|
|
67
67
|
export type HttpRequestHandlerBodyStaticRestriction<
|
|
68
68
|
Schema extends HttpSchema,
|
|
69
|
-
Path extends HttpSchemaPath<Schema, Method>,
|
|
70
69
|
Method extends HttpSchemaMethod<Schema>,
|
|
70
|
+
Path extends HttpSchemaPath<Schema, Method>,
|
|
71
71
|
> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -77,26 +77,26 @@ export type HttpRequestHandlerBodyStaticRestriction<
|
|
|
77
77
|
*/
|
|
78
78
|
export interface HttpRequestHandlerStaticRestriction<
|
|
79
79
|
Schema extends HttpSchema,
|
|
80
|
-
Path extends HttpSchemaPath<Schema, Method>,
|
|
81
80
|
Method extends HttpSchemaMethod<Schema>,
|
|
81
|
+
Path extends HttpSchemaPath<Schema, Method>,
|
|
82
82
|
> {
|
|
83
83
|
/**
|
|
84
84
|
* A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
|
|
85
85
|
* must contain exactly these headers and no others.
|
|
86
86
|
*/
|
|
87
|
-
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema,
|
|
87
|
+
headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
|
|
91
91
|
* request must contain exactly these search params and no others.
|
|
92
92
|
*/
|
|
93
|
-
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema,
|
|
93
|
+
searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
|
|
97
97
|
* contain exactly this body and no other.
|
|
98
98
|
*/
|
|
99
|
-
body?: HttpRequestHandlerBodyStaticRestriction<Schema,
|
|
99
|
+
body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
|
|
@@ -126,7 +126,7 @@ export type HttpRequestHandlerRestriction<
|
|
|
126
126
|
Method extends HttpSchemaMethod<Schema>,
|
|
127
127
|
Path extends HttpSchemaPath<Schema, Method>,
|
|
128
128
|
> =
|
|
129
|
-
| HttpRequestHandlerStaticRestriction<Schema,
|
|
129
|
+
| HttpRequestHandlerStaticRestriction<Schema, Method, Path>
|
|
130
130
|
| HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
|
|
131
131
|
|
|
132
132
|
export interface RestrictionDiff<Value> {
|