@zimic/fetch 0.2.3-canary.0 → 0.3.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 CHANGED
@@ -110,7 +110,7 @@ Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting
110
110
  request: {
111
111
  searchParams: {
112
112
  query?: string;
113
- limit?: `${number}`;
113
+ limit?: number;
114
114
  };
115
115
  };
116
116
  response: {
@@ -152,7 +152,7 @@ Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting
152
152
  ```ts
153
153
  const response = await fetch('/users', {
154
154
  method: 'GET',
155
- searchParams: { query: 'u', limit: '10' },
155
+ searchParams: { query: 'u', limit: 10 },
156
156
  });
157
157
 
158
158
  if (response.status === 404) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpRequestSchema, HttpHeaders, HttpSearchParams, JSONValue, HttpMethod, HttpHeadersSchema, HttpSearchParamsSchema, HttpRequest, HttpMethodSchema, HttpRequestHeadersSchema, AllowAnyStringInPathParams, HttpStatusCode, HttpResponseSchemaStatusCode, HttpResponse, HttpResponseBodySchema, HttpResponseHeadersSchema, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
1
+ import { HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpMethodSchema, HttpHeadersSchema, HttpHeadersInit, HttpRequestHeadersSchema, HttpSearchParamsSchema, HttpSearchParamsInit, HttpRequestSearchParamsSchema, HttpBody, HttpRequestSchema, HttpMethod, HttpRequest, HttpRequestBodySchema, AllowAnyStringInPathParams, HttpStatusCode, HttpResponseSchemaStatusCode, HttpResponse, HttpResponseBodySchema, HttpResponseHeadersSchema, HttpHeadersSerialized, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
2
2
 
3
3
  declare const value: unique symbol;
4
4
  /**
@@ -18,50 +18,34 @@ declare global {
18
18
  }
19
19
 
20
20
  type Default<Type, IfEmpty = never> = [undefined | void] extends [Type] ? IfEmpty : Exclude<Type, undefined | void>;
21
- type DefaultNoExclude<Type, IfEmpty = never> = [undefined | void] extends Type ? IfEmpty : Type;
22
- type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
23
21
  type PossiblePromise<Type> = Type | PromiseLike<Type>;
24
- type ReplaceBy<Type, Source, Target> = Type extends Source ? Target : Type;
25
22
  type RequiredByKey<Type, Key extends keyof Type> = Omit<Type, Key> & Required<Pick<Type, Key>>;
26
23
 
27
- type FetchRequestInitHeaders<RequestSchema extends HttpRequestSchema> = RequestSchema['headers'] | HttpHeaders<Default<RequestSchema['headers']>>;
28
- type FetchRequestInitWithHeaders<RequestSchema extends HttpRequestSchema> = 'headers' extends keyof RequestSchema ? [RequestSchema['headers']] extends [never] ? {
24
+ type FetchRequestInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = [HeadersSchema] extends [never] ? {
29
25
  headers?: undefined;
30
- } : undefined extends RequestSchema['headers'] ? {
31
- headers?: FetchRequestInitHeaders<RequestSchema>;
26
+ } : undefined extends HeadersSchema ? {
27
+ headers?: HttpHeadersInit<Default<HeadersSchema>>;
32
28
  } : {
33
- headers: FetchRequestInitHeaders<RequestSchema>;
34
- } : {
35
- headers?: undefined;
29
+ headers: HttpHeadersInit<Default<HeadersSchema>>;
36
30
  };
37
- type FetchRequestInitSearchParams<RequestSchema extends HttpRequestSchema> = RequestSchema['searchParams'] | HttpSearchParams<Default<RequestSchema['searchParams']>>;
38
- type FetchRequestInitWithSearchParams<RequestSchema extends HttpRequestSchema> = 'searchParams' extends keyof RequestSchema ? [RequestSchema['searchParams']] extends [never] ? {
31
+ type FetchRequestInitWithSearchParams<SearchParamsSchema extends HttpSearchParamsSchema | undefined> = [
32
+ SearchParamsSchema
33
+ ] extends [never] ? {
39
34
  searchParams?: undefined;
40
- } : undefined extends RequestSchema['searchParams'] ? {
41
- searchParams?: FetchRequestInitSearchParams<RequestSchema>;
35
+ } : undefined extends SearchParamsSchema ? {
36
+ searchParams?: HttpSearchParamsInit<Default<SearchParamsSchema>>;
42
37
  } : {
43
- searchParams: FetchRequestInitSearchParams<RequestSchema>;
44
- } : {
45
- searchParams?: undefined;
38
+ searchParams: HttpSearchParamsInit<Default<SearchParamsSchema>>;
46
39
  };
47
- type FetchRequestInitWithBody<RequestSchema extends HttpRequestSchema> = 'body' extends keyof RequestSchema ? [RequestSchema['body']] extends [never] ? {
48
- body?: null;
49
- } : RequestSchema['body'] extends string ? undefined extends RequestSchema['body'] ? {
50
- body?: ReplaceBy<RequestSchema['body'], undefined, null>;
51
- } : {
52
- body: RequestSchema['body'];
53
- } : RequestSchema['body'] extends JSONValue ? undefined extends RequestSchema['body'] ? {
54
- body?: JSONStringified<ReplaceBy<RequestSchema['body'], undefined, null>>;
55
- } : {
56
- body: JSONStringified<RequestSchema['body']>;
57
- } : undefined extends RequestSchema['body'] ? {
58
- body?: ReplaceBy<RequestSchema['body'], undefined, null>;
59
- } : {
60
- body: RequestSchema['body'];
40
+ type FetchRequestBodySchema<RequestSchema extends HttpRequestSchema> = 'body' extends keyof RequestSchema ? [RequestSchema['body']] extends [never] ? null | undefined : RequestSchema['body'] extends BodyInit ? undefined extends RequestSchema['body'] ? RequestSchema['body'] | null : RequestSchema['body'] : undefined extends RequestSchema['body'] ? JSONStringified<Exclude<RequestSchema['body'], null | undefined>> | null | undefined : JSONStringified<Exclude<RequestSchema['body'], null>> | Extract<RequestSchema['body'], null> : null | undefined;
41
+ type FetchRequestInitWithBody<BodySchema extends HttpBody> = [BodySchema] extends [never] ? {
42
+ body?: BodySchema;
43
+ } : undefined extends BodySchema ? {
44
+ body?: BodySchema;
61
45
  } : {
62
- body?: null;
46
+ body: BodySchema;
63
47
  };
64
- type FetchRequestInitPerPath<RequestSchema extends HttpRequestSchema> = FetchRequestInitWithHeaders<RequestSchema> & FetchRequestInitWithSearchParams<RequestSchema> & FetchRequestInitWithBody<RequestSchema>;
48
+ type FetchRequestInitPerPath<MethodSchema extends HttpMethodSchema> = FetchRequestInitWithHeaders<HttpRequestHeadersSchema<MethodSchema>> & FetchRequestInitWithSearchParams<HttpRequestSearchParamsSchema<MethodSchema>> & FetchRequestInitWithBody<FetchRequestBodySchema<Default<MethodSchema['request']>>>;
65
49
  /**
66
50
  * The options to create a {@link FetchRequest} instance, compatible with
67
51
  * {@link https://developer.mozilla.org/docs/Web/API/RequestInit `RequestInit`}.
@@ -75,7 +59,7 @@ type FetchRequestInit<Schema extends HttpSchema, Method extends HttpSchemaMethod
75
59
  /** The base URL to prefix the path of the request. */
76
60
  baseURL?: string;
77
61
  redirect?: Redirect;
78
- } & (Path extends Path ? FetchRequestInitPerPath<Default<Default<Schema[Path][Method]>['request']>> : never);
62
+ } & (Path extends Path ? FetchRequestInitPerPath<Default<Schema[Path][Method]>> : never);
79
63
  declare namespace FetchRequestInit {
80
64
  /** The default options for each request sent by a fetch instance. */
81
65
  interface Defaults extends Omit<RequestInit, 'headers'> {
@@ -83,9 +67,9 @@ declare namespace FetchRequestInit {
83
67
  /** The HTTP method of the request. */
84
68
  method?: HttpMethod;
85
69
  /** The headers of the request. */
86
- headers?: HttpHeadersSchema;
70
+ headers?: HttpHeadersSchema.Loose;
87
71
  /** The search parameters of the request. */
88
- searchParams?: HttpSearchParamsSchema;
72
+ searchParams?: HttpSearchParamsSchema.Loose;
89
73
  }
90
74
  /** A loosely typed version of {@link FetchRequestInit `FetchRequestInit`}. */
91
75
  type Loose = Partial<Defaults>;
@@ -94,7 +78,6 @@ type AllFetchResponseStatusCode<MethodSchema extends HttpMethodSchema> = HttpRes
94
78
  type FilterFetchResponseStatusCodeByError<StatusCode extends HttpStatusCode, ErrorOnly extends boolean> = ErrorOnly extends true ? Extract<StatusCode, HttpStatusCode.ClientError | HttpStatusCode.ServerError> : StatusCode;
95
79
  type FilterFetchResponseStatusCodeByRedirect<StatusCode extends HttpStatusCode, Redirect extends RequestRedirect> = Redirect extends 'error' ? FilterFetchResponseStatusCodeByRedirect<StatusCode, 'follow'> : Redirect extends 'follow' ? Exclude<StatusCode, Exclude<HttpStatusCode.Redirection, 304>> : StatusCode;
96
80
  type FetchResponseStatusCode<MethodSchema extends HttpMethodSchema, ErrorOnly extends boolean, Redirect extends RequestRedirect> = FilterFetchResponseStatusCodeByRedirect<FilterFetchResponseStatusCodeByError<AllFetchResponseStatusCode<MethodSchema>, ErrorOnly>, Redirect>;
97
- type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<MethodSchema['request']>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
98
81
  /**
99
82
  * A request instance typed with an HTTP schema, closely compatible with the
100
83
  * {@link https://developer.mozilla.org/docs/Web/API/Request native Request class}.
@@ -144,7 +127,7 @@ type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<Re
144
127
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐fetch#fetchrequest `FetchRequest` API reference}
145
128
  * @see {@link https://developer.mozilla.org/docs/Web/API/Request}
146
129
  */
147
- interface FetchRequest<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>> extends HttpRequest<HttpRequestBodySchema<Default<Schema[Path][Method]>>, HttpRequestHeadersSchema<Default<Schema[Path][Method]>>> {
130
+ interface FetchRequest<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>> extends HttpRequest<HttpRequestBodySchema<Default<Schema[Path][Method]>>, Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>> {
148
131
  /** The path of the request, excluding the base URL. */
149
132
  path: AllowAnyStringInPathParams<Path>;
150
133
  /** The HTTP method of the request. */
@@ -168,7 +151,7 @@ declare namespace FetchRequest {
168
151
  */
169
152
  type FetchRequestObject = Pick<FetchRequest.Loose, 'url' | 'path' | 'method' | 'cache' | 'destination' | 'credentials' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'> & {
170
153
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
171
- headers: HttpHeadersSchema;
154
+ headers: HttpHeadersSerialized<HttpHeadersSchema>;
172
155
  /**
173
156
  * The body of the response, represented as a string or null if empty.
174
157
  *
@@ -182,7 +165,7 @@ type FetchRequestObject = Pick<FetchRequest.Loose, 'url' | 'path' | 'method' | '
182
165
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐fetch#fetchresponse `FetchResponse` API reference}
183
166
  * @see {@link https://developer.mozilla.org/docs/Web/API/Response}
184
167
  */
185
- interface FetchResponsePerStatusCode<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>, StatusCode extends HttpStatusCode = HttpStatusCode> extends HttpResponse<HttpResponseBodySchema<Default<Schema[Path][Method]>, StatusCode>, StatusCode, HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>> {
168
+ interface FetchResponsePerStatusCode<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath.Literal<Schema, Method>, StatusCode extends HttpStatusCode = HttpStatusCode> extends HttpResponse<HttpResponseBodySchema<Default<Schema[Path][Method]>, StatusCode>, StatusCode, Default<HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>>> {
186
169
  /** The request that originated the response. */
187
170
  request: FetchRequest<Schema, Method, Path>;
188
171
  /**
@@ -268,7 +251,7 @@ declare namespace FetchResponse {
268
251
  */
269
252
  type FetchResponseObject = Pick<FetchResponse.Loose, 'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'> & {
270
253
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
271
- headers: HttpHeadersSchema;
254
+ headers: HttpHeadersSerialized<HttpHeadersSchema>;
272
255
  /**
273
256
  * The body of the response, represented as a string or null if empty.
274
257
  *
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "api",
14
14
  "static"
15
15
  ],
16
- "version": "0.2.3-canary.0",
16
+ "version": "0.3.0-canary.0",
17
17
  "repository": {
18
18
  "type": "git",
19
19
  "url": "https://github.com/zimicjs/zimic.git",
@@ -67,14 +67,14 @@
67
67
  "typescript": "^5.8.3",
68
68
  "vitest": "^3.1.2",
69
69
  "@zimic/eslint-config-node": "0.0.0",
70
- "@zimic/interceptor": "0.17.2",
71
70
  "@zimic/lint-staged-config": "0.0.0",
71
+ "@zimic/interceptor": "0.18.0-canary.0",
72
72
  "@zimic/tsconfig": "0.0.0",
73
73
  "@zimic/utils": "0.0.0"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "typescript": ">=4.8.0",
77
- "@zimic/http": "^0.3.0 || 0.3.2-canary.0"
77
+ "@zimic/http": "^0.4.0 || 0.4.0-canary.1"
78
78
  },
79
79
  "scripts": {
80
80
  "dev": "tsup --watch",
@@ -1,4 +1,4 @@
1
- const value = Symbol.for('JSONStringified.value');
1
+ declare const value: unique symbol;
2
2
 
3
3
  /**
4
4
  * Represents a value stringified by `JSON.stringify`, maintaining a reference to the original type.
@@ -9,67 +9,63 @@ import {
9
9
  HttpStatusCode,
10
10
  HttpResponse,
11
11
  HttpRequest,
12
- HttpSearchParams,
13
- HttpHeaders,
14
12
  AllowAnyStringInPathParams,
15
13
  LiteralHttpSchemaPathFromNonLiteral,
16
- JSONValue,
17
14
  HttpResponseBodySchema,
18
15
  HttpResponseHeadersSchema,
19
16
  HttpRequestHeadersSchema,
20
17
  HttpHeadersSchema,
21
18
  HttpSearchParamsSchema,
19
+ HttpHeadersInit,
20
+ HttpHeadersSerialized,
21
+ HttpSearchParamsInit,
22
+ HttpBody,
23
+ HttpRequestBodySchema,
24
+ HttpRequestSearchParamsSchema,
22
25
  } from '@zimic/http';
23
- import { Default, DefaultNoExclude, IfNever, ReplaceBy } from '@zimic/utils/types';
26
+ import { Default } from '@zimic/utils/types';
24
27
 
25
28
  import FetchResponseError, { AnyFetchRequestError } from '../errors/FetchResponseError';
26
29
  import { JSONStringified } from './json';
27
30
  import { FetchInput } from './public';
28
31
 
29
- type FetchRequestInitHeaders<RequestSchema extends HttpRequestSchema> =
30
- | RequestSchema['headers']
31
- | HttpHeaders<Default<RequestSchema['headers']>>;
32
+ type FetchRequestInitWithHeaders<HeadersSchema extends HttpHeadersSchema | undefined> = [HeadersSchema] extends [never]
33
+ ? { headers?: undefined }
34
+ : undefined extends HeadersSchema
35
+ ? { headers?: HttpHeadersInit<Default<HeadersSchema>> }
36
+ : { headers: HttpHeadersInit<Default<HeadersSchema>> };
32
37
 
33
- type FetchRequestInitWithHeaders<RequestSchema extends HttpRequestSchema> = 'headers' extends keyof RequestSchema
34
- ? [RequestSchema['headers']] extends [never]
35
- ? { headers?: undefined }
36
- : undefined extends RequestSchema['headers']
37
- ? { headers?: FetchRequestInitHeaders<RequestSchema> }
38
- : { headers: FetchRequestInitHeaders<RequestSchema> }
39
- : { headers?: undefined };
38
+ type FetchRequestInitWithSearchParams<SearchParamsSchema extends HttpSearchParamsSchema | undefined> = [
39
+ SearchParamsSchema,
40
+ ] extends [never]
41
+ ? { searchParams?: undefined }
42
+ : undefined extends SearchParamsSchema
43
+ ? { searchParams?: HttpSearchParamsInit<Default<SearchParamsSchema>> }
44
+ : { searchParams: HttpSearchParamsInit<Default<SearchParamsSchema>> };
40
45
 
41
- type FetchRequestInitSearchParams<RequestSchema extends HttpRequestSchema> =
42
- | RequestSchema['searchParams']
43
- | HttpSearchParams<Default<RequestSchema['searchParams']>>;
44
-
45
- type FetchRequestInitWithSearchParams<RequestSchema extends HttpRequestSchema> =
46
- 'searchParams' extends keyof RequestSchema
47
- ? [RequestSchema['searchParams']] extends [never]
48
- ? { searchParams?: undefined }
49
- : undefined extends RequestSchema['searchParams']
50
- ? { searchParams?: FetchRequestInitSearchParams<RequestSchema> }
51
- : { searchParams: FetchRequestInitSearchParams<RequestSchema> }
52
- : { searchParams?: undefined };
53
-
54
- type FetchRequestInitWithBody<RequestSchema extends HttpRequestSchema> = 'body' extends keyof RequestSchema
46
+ type FetchRequestBodySchema<RequestSchema extends HttpRequestSchema> = 'body' extends keyof RequestSchema
55
47
  ? [RequestSchema['body']] extends [never]
56
- ? { body?: null }
57
- : RequestSchema['body'] extends string
48
+ ? null | undefined
49
+ : RequestSchema['body'] extends BodyInit
58
50
  ? undefined extends RequestSchema['body']
59
- ? { body?: ReplaceBy<RequestSchema['body'], undefined, null> }
60
- : { body: RequestSchema['body'] }
61
- : RequestSchema['body'] extends JSONValue
62
- ? undefined extends RequestSchema['body']
63
- ? { body?: JSONStringified<ReplaceBy<RequestSchema['body'], undefined, null>> }
64
- : { body: JSONStringified<RequestSchema['body']> }
65
- : undefined extends RequestSchema['body']
66
- ? { body?: ReplaceBy<RequestSchema['body'], undefined, null> }
67
- : { body: RequestSchema['body'] }
68
- : { body?: null };
51
+ ? RequestSchema['body'] | null
52
+ : RequestSchema['body']
53
+ : undefined extends RequestSchema['body']
54
+ ? JSONStringified<Exclude<RequestSchema['body'], null | undefined>> | null | undefined
55
+ : JSONStringified<Exclude<RequestSchema['body'], null>> | Extract<RequestSchema['body'], null>
56
+ : null | undefined;
57
+
58
+ type FetchRequestInitWithBody<BodySchema extends HttpBody> = [BodySchema] extends [never]
59
+ ? { body?: BodySchema }
60
+ : undefined extends BodySchema
61
+ ? { body?: BodySchema }
62
+ : { body: BodySchema };
69
63
 
70
- type FetchRequestInitPerPath<RequestSchema extends HttpRequestSchema> = FetchRequestInitWithHeaders<RequestSchema> &
71
- FetchRequestInitWithSearchParams<RequestSchema> &
72
- FetchRequestInitWithBody<RequestSchema>;
64
+ type FetchRequestInitPerPath<MethodSchema extends HttpMethodSchema> = FetchRequestInitWithHeaders<
65
+ HttpRequestHeadersSchema<MethodSchema>
66
+ > &
67
+ FetchRequestInitWithSearchParams<HttpRequestSearchParamsSchema<MethodSchema>> &
68
+ FetchRequestInitWithBody<FetchRequestBodySchema<Default<MethodSchema['request']>>>;
73
69
 
74
70
  /**
75
71
  * The options to create a {@link FetchRequest} instance, compatible with
@@ -89,7 +85,7 @@ export type FetchRequestInit<
89
85
  /** The base URL to prefix the path of the request. */
90
86
  baseURL?: string;
91
87
  redirect?: Redirect;
92
- } & (Path extends Path ? FetchRequestInitPerPath<Default<Default<Schema[Path][Method]>['request']>> : never);
88
+ } & (Path extends Path ? FetchRequestInitPerPath<Default<Schema[Path][Method]>> : never);
93
89
 
94
90
  export namespace FetchRequestInit {
95
91
  /** The default options for each request sent by a fetch instance. */
@@ -98,9 +94,9 @@ export namespace FetchRequestInit {
98
94
  /** The HTTP method of the request. */
99
95
  method?: HttpMethod;
100
96
  /** The headers of the request. */
101
- headers?: HttpHeadersSchema;
97
+ headers?: HttpHeadersSchema.Loose;
102
98
  /** The search parameters of the request. */
103
- searchParams?: HttpSearchParamsSchema;
99
+ searchParams?: HttpSearchParamsSchema.Loose;
104
100
  }
105
101
 
106
102
  /** A loosely typed version of {@link FetchRequestInit `FetchRequestInit`}. */
@@ -134,12 +130,6 @@ type FetchResponseStatusCode<
134
130
  Redirect
135
131
  >;
136
132
 
137
- type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<
138
- ReplaceBy<IfNever<DefaultNoExclude<Default<MethodSchema['request']>['body']>, null>, undefined, null>,
139
- ArrayBuffer,
140
- Blob
141
- >;
142
-
143
133
  /**
144
134
  * A request instance typed with an HTTP schema, closely compatible with the
145
135
  * {@link https://developer.mozilla.org/docs/Web/API/Request native Request class}.
@@ -195,7 +185,7 @@ export interface FetchRequest<
195
185
  Path extends HttpSchemaPath.Literal<Schema, Method>,
196
186
  > extends HttpRequest<
197
187
  HttpRequestBodySchema<Default<Schema[Path][Method]>>,
198
- HttpRequestHeadersSchema<Default<Schema[Path][Method]>>
188
+ Default<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>
199
189
  > {
200
190
  /** The path of the request, excluding the base URL. */
201
191
  path: AllowAnyStringInPathParams<Path>;
@@ -236,7 +226,7 @@ export type FetchRequestObject = Pick<
236
226
  | 'referrerPolicy'
237
227
  > & {
238
228
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
239
- headers: HttpHeadersSchema;
229
+ headers: HttpHeadersSerialized<HttpHeadersSchema>;
240
230
  /**
241
231
  * The body of the response, represented as a string or null if empty.
242
232
  *
@@ -259,7 +249,7 @@ export interface FetchResponsePerStatusCode<
259
249
  > extends HttpResponse<
260
250
  HttpResponseBodySchema<Default<Schema[Path][Method]>, StatusCode>,
261
251
  StatusCode,
262
- HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>
252
+ Default<HttpResponseHeadersSchema<Default<Schema[Path][Method]>, StatusCode>>
263
253
  > {
264
254
  /** The request that originated the response. */
265
255
  request: FetchRequest<Schema, Method, Path>;
@@ -368,7 +358,7 @@ export type FetchResponseObject = Pick<
368
358
  'url' | 'type' | 'status' | 'statusText' | 'ok' | 'redirected'
369
359
  > & {
370
360
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */
371
- headers: HttpHeadersSchema;
361
+ headers: HttpHeadersSerialized<HttpHeadersSchema>;
372
362
  /**
373
363
  * The body of the response, represented as a string or null if empty.
374
364
  *
@@ -1,98 +0,0 @@
1
- import {
2
- HttpFormData,
3
- HttpFormDataSchema,
4
- HttpHeaders,
5
- HttpHeadersSchema,
6
- HttpSearchParams,
7
- HttpSearchParamsSchema,
8
- JSONSerialized,
9
- JSONValue,
10
- HttpStatusCode,
11
- } from '@zimic/http';
12
- import { ReplaceBy } from '@zimic/utils/types';
13
-
14
- /** The body type for HTTP requests and responses. */
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- export type HttpBody = JSONValue | HttpFormData<any> | HttpSearchParams<any> | Blob | ArrayBuffer;
17
-
18
- export namespace HttpBody {
19
- /** A loose version of the HTTP body type. JSON values are not strictly typed. */
20
- export type Loose = ReplaceBy<HttpBody, JSONValue, JSONValue.Loose>;
21
-
22
- /** Convert a possibly loose HTTP body to be strictly typed. JSON values are serialized to their strict form. */
23
- export type ConvertToStrict<Type> = Type extends Exclude<HttpBody, JSONValue> ? Type : JSONSerialized<Type>;
24
- }
25
-
26
- /**
27
- * An HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
28
- * {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
29
- */
30
- export type StrictHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> = Pick<
31
- HttpHeaders<Schema>,
32
- keyof Headers
33
- >;
34
-
35
- /**
36
- * An HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
37
- * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
38
- */
39
- export type StrictURLSearchParams<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = Pick<
40
- HttpSearchParams<Schema>,
41
- keyof URLSearchParams
42
- >;
43
-
44
- /**
45
- * An HTTP form data object with a strictly-typed schema. Fully compatible with the built-in
46
- * {@link https://developer.mozilla.org/docs/Web/API/FormData `FormData`} class.
47
- */
48
- export type StrictFormData<Schema extends HttpFormDataSchema = HttpFormDataSchema> = Pick<
49
- HttpFormData<Schema>,
50
- keyof FormData
51
- >;
52
-
53
- /**
54
- * An HTTP request with a strictly-typed JSON body. Fully compatible with the built-in
55
- * {@link https://developer.mozilla.org/docs/Web/API/Request `Request`} class.
56
- */
57
- export interface HttpRequest<
58
- StrictBody extends HttpBody.Loose = HttpBody,
59
- StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema,
60
- > extends Request {
61
- headers: StrictHeaders<StrictHeadersSchema>;
62
- text: () => Promise<StrictBody extends string ? StrictBody : string>;
63
- json: () => Promise<StrictBody extends string | Exclude<HttpBody, JSONValue> ? never : StrictBody>;
64
- formData: () => Promise<
65
- StrictBody extends HttpFormData<infer HttpFormDataSchema>
66
- ? StrictFormData<HttpFormDataSchema>
67
- : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema>
68
- ? StrictFormData<HttpSearchParamsSchema>
69
- : FormData
70
- >;
71
- clone: () => this;
72
- }
73
-
74
- /**
75
- * An HTTP response with a strictly-typed JSON body and status code. Fully compatible with the built-in
76
- * {@link https://developer.mozilla.org/docs/Web/API/Response `Response`} class.
77
- */
78
- export interface HttpResponse<
79
- StrictBody extends HttpBody.Loose = HttpBody,
80
- StatusCode extends number = number,
81
- StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema,
82
- > extends Response {
83
- ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection
84
- ? true
85
- : false;
86
- status: StatusCode;
87
- headers: StrictHeaders<StrictHeadersSchema>;
88
- text: () => Promise<StrictBody extends string ? StrictBody : string>;
89
- json: () => Promise<StrictBody extends string | Exclude<HttpBody, JSONValue> ? never : StrictBody>;
90
- formData: () => Promise<
91
- StrictBody extends HttpFormData<infer HttpFormDataSchema>
92
- ? StrictFormData<HttpFormDataSchema>
93
- : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema>
94
- ? StrictFormData<HttpSearchParamsSchema>
95
- : FormData
96
- >;
97
- clone: () => this;
98
- }