@zimic/http 0.4.0-canary.1 → 0.4.0-canary.2
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/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/index.d.ts +85 -83
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/formData/HttpFormData.ts +34 -47
- package/src/formData/types.ts +36 -42
- package/src/headers/HttpHeaders.ts +32 -32
- package/src/pathParams/types.ts +29 -40
- package/src/searchParams/HttpSearchParams.ts +35 -35
- package/src/searchParams/types.ts +37 -43
- package/src/types/requests.ts +49 -5
package/src/types/requests.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Default, DefaultNoExclude, IfNever, ReplaceBy } from '@zimic/utils/types';
|
|
2
2
|
import { JSONValue } from '@zimic/utils/types/json';
|
|
3
3
|
|
|
4
|
-
import { HttpMethodSchema, HttpStatusCode } from '@/types/schema';
|
|
4
|
+
import { HttpMethodSchema, HttpRequestSchema, HttpResponseSchema, HttpStatusCode } from '@/types/schema';
|
|
5
5
|
|
|
6
6
|
import HttpFormData from '../formData/HttpFormData';
|
|
7
7
|
import { HttpFormDataSchema } from '../formData/types';
|
|
@@ -73,8 +73,8 @@ export interface HttpRequest<
|
|
|
73
73
|
*/
|
|
74
74
|
export interface HttpResponse<
|
|
75
75
|
StrictBody extends HttpBody.Loose = HttpBody.Loose,
|
|
76
|
-
StatusCode extends number = number,
|
|
77
76
|
StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose,
|
|
77
|
+
StatusCode extends number = number,
|
|
78
78
|
> extends Response {
|
|
79
79
|
ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection
|
|
80
80
|
? true
|
|
@@ -93,8 +93,32 @@ export interface HttpResponse<
|
|
|
93
93
|
clone: () => this;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
type HttpRequestHeadersSchemaFromBody<
|
|
97
|
+
RequestSchema extends HttpRequestSchema,
|
|
98
|
+
DefaultHeadersSchema,
|
|
99
|
+
> = 'body' extends keyof RequestSchema
|
|
100
|
+
? [RequestSchema['body']] extends [never]
|
|
101
|
+
? DefaultHeadersSchema
|
|
102
|
+
: [Extract<RequestSchema['body'], BodyInit | HttpFormData | HttpSearchParams>] extends [never]
|
|
103
|
+
? 'headers' extends keyof RequestSchema
|
|
104
|
+
? [RequestSchema['headers']] extends [never]
|
|
105
|
+
? DefaultHeadersSchema
|
|
106
|
+
: 'content-type' extends keyof Default<RequestSchema['headers']>
|
|
107
|
+
? DefaultHeadersSchema
|
|
108
|
+
: { 'content-type': 'application/json' }
|
|
109
|
+
: { 'content-type': 'application/json' }
|
|
110
|
+
: DefaultHeadersSchema
|
|
111
|
+
: DefaultHeadersSchema;
|
|
112
|
+
|
|
96
113
|
export type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> =
|
|
97
|
-
'headers' extends keyof MethodSchema['request']
|
|
114
|
+
'headers' extends keyof MethodSchema['request']
|
|
115
|
+
? [MethodSchema['request']['headers']] extends [never]
|
|
116
|
+
? HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never>
|
|
117
|
+
:
|
|
118
|
+
| (MethodSchema['request']['headers'] &
|
|
119
|
+
HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, {}>)
|
|
120
|
+
| (MethodSchema['request']['headers'] & undefined)
|
|
121
|
+
: HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never>;
|
|
98
122
|
|
|
99
123
|
export type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> =
|
|
100
124
|
'searchParams' extends keyof MethodSchema['request'] ? Default<MethodSchema['request']>['searchParams'] : never;
|
|
@@ -105,12 +129,32 @@ export type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = Repla
|
|
|
105
129
|
Blob
|
|
106
130
|
>;
|
|
107
131
|
|
|
132
|
+
type HttpResponseHeadersSchemaFromBody<
|
|
133
|
+
ResponseSchema extends HttpResponseSchema,
|
|
134
|
+
DefaultHeadersSchema,
|
|
135
|
+
> = 'body' extends keyof ResponseSchema
|
|
136
|
+
? [ResponseSchema['body']] extends [never]
|
|
137
|
+
? DefaultHeadersSchema
|
|
138
|
+
: [Extract<ResponseSchema['body'], BodyInit | HttpSearchParams | HttpFormData>] extends [never]
|
|
139
|
+
? 'headers' extends keyof ResponseSchema
|
|
140
|
+
? [ResponseSchema['headers']] extends [never]
|
|
141
|
+
? DefaultHeadersSchema
|
|
142
|
+
: 'content-type' extends keyof Default<ResponseSchema['headers']>
|
|
143
|
+
? DefaultHeadersSchema
|
|
144
|
+
: { 'content-type': 'application/json' }
|
|
145
|
+
: { 'content-type': 'application/json' }
|
|
146
|
+
: DefaultHeadersSchema
|
|
147
|
+
: DefaultHeadersSchema;
|
|
148
|
+
|
|
108
149
|
export type HttpResponseHeadersSchema<
|
|
109
150
|
MethodSchema extends HttpMethodSchema,
|
|
110
151
|
StatusCode extends HttpStatusCode,
|
|
111
152
|
> = 'headers' extends keyof Default<MethodSchema['response']>[StatusCode]
|
|
112
|
-
? Default<
|
|
113
|
-
|
|
153
|
+
? [Default<MethodSchema['response']>[StatusCode]] extends [never]
|
|
154
|
+
? HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never>
|
|
155
|
+
: Default<Default<MethodSchema['response']>[StatusCode]>['headers'] &
|
|
156
|
+
HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, {}>
|
|
157
|
+
: HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never>;
|
|
114
158
|
|
|
115
159
|
export type HttpResponseBodySchema<
|
|
116
160
|
MethodSchema extends HttpMethodSchema,
|