@zimic/http 0.4.0-canary.0 → 0.4.0-canary.1
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-IJVT4RDC.mjs → chunk-KVTV4E5K.mjs} +26 -100
- package/dist/chunk-KVTV4E5K.mjs.map +1 -0
- package/dist/{chunk-DIZB36SQ.js → chunk-LOHINQWU.js} +26 -100
- package/dist/chunk-LOHINQWU.js.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/index.d.ts +71 -128
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +2 -2
- package/src/formData/HttpFormData.ts +14 -11
- package/src/headers/HttpHeaders.ts +12 -9
- package/src/headers/types.ts +2 -2
- package/src/searchParams/HttpSearchParams.ts +23 -15
- package/src/searchParams/types.ts +2 -2
- package/src/typegen/openapi/transform/components.ts +1 -11
- package/src/typegen/openapi/transform/context.ts +0 -3
- package/src/typegen/openapi/transform/methods.ts +23 -88
- package/src/typegen/openapi/transform/operations.ts +1 -11
- package/src/typegen/openapi/transform/paths.ts +1 -17
- package/src/types/requests.ts +15 -18
- package/src/types/schema.ts +50 -134
- package/dist/chunk-DIZB36SQ.js.map +0 -1
- package/dist/chunk-IJVT4RDC.mjs.map +0 -1
package/src/types/schema.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
IfAny,
|
|
3
|
+
UnionToIntersection,
|
|
4
|
+
UnionHasMoreThanOneType,
|
|
5
|
+
Prettify,
|
|
6
|
+
NonEmptyArray,
|
|
7
|
+
Branded,
|
|
8
|
+
} from '@zimic/utils/types';
|
|
9
|
+
|
|
10
|
+
import { HttpFormDataSchema } from '../formData/types';
|
|
11
|
+
import { HttpHeadersSchema } from '../headers/types';
|
|
12
|
+
import { HttpPathParamsSchema } from '../pathParams/types';
|
|
13
|
+
import { HttpSearchParamsSchema } from '../searchParams/types';
|
|
7
14
|
import { HttpBody } from './requests';
|
|
8
15
|
|
|
9
16
|
export const HTTP_METHODS = Object.freeze(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const);
|
|
@@ -24,19 +31,6 @@ export interface HttpRequestSchema {
|
|
|
24
31
|
body?: HttpBody.Loose;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
export namespace HttpRequestSchema {
|
|
28
|
-
/** Convert an HTTP request schema to be strictly typed. */
|
|
29
|
-
export type AsStrict<Schema> = {
|
|
30
|
-
[Key in keyof Schema]: Key extends 'headers'
|
|
31
|
-
? HttpHeadersSerialized<Schema[Key]>
|
|
32
|
-
: Key extends 'searchParams'
|
|
33
|
-
? HttpSearchParamsSerialized<Schema[Key]>
|
|
34
|
-
: Key extends 'body'
|
|
35
|
-
? HttpBody.AsStrict<Schema[Key]>
|
|
36
|
-
: Schema[Key];
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
34
|
/**
|
|
41
35
|
* A schema representing the structure of an HTTP response.
|
|
42
36
|
*
|
|
@@ -47,16 +41,6 @@ export interface HttpResponseSchema {
|
|
|
47
41
|
body?: HttpBody.Loose;
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
export namespace HttpResponseSchema {
|
|
51
|
-
/** A schema representing the structure of an HTTP response with no body. */
|
|
52
|
-
export interface NoBody extends Omit<HttpResponseSchema, 'body'> {
|
|
53
|
-
body?: null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Convert an HTTP response schema to be strictly typed. */
|
|
57
|
-
export type AsStrict<Schema> = HttpRequestSchema.AsStrict<Schema>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
44
|
/**
|
|
61
45
|
* The status codes used in HTTP responses, as defined by
|
|
62
46
|
* {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
|
|
@@ -177,27 +161,9 @@ export namespace HttpStatusCode {
|
|
|
177
161
|
*
|
|
178
162
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
179
163
|
*/
|
|
180
|
-
export type HttpResponseSchemaByStatusCode =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
export namespace HttpResponseSchemaByStatusCode {
|
|
184
|
-
/** A loose version of HTTP responses by status code. JSON values are not strictly typed. */
|
|
185
|
-
export type Loose = {
|
|
186
|
-
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/** Converts an HTTP response schema by status code to be strictly typed. */
|
|
190
|
-
export type AsStrict<Schema> = {
|
|
191
|
-
[StatusCode in keyof Schema]: StatusCode extends 204
|
|
192
|
-
? HttpResponseSchema.NoBody
|
|
193
|
-
: HttpResponseSchema.AsStrict<Schema[StatusCode]>;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
/** A schema representing the structure of HTTP responses by status code with no body. */
|
|
197
|
-
export type NoBody = {
|
|
198
|
-
[StatusCode in HttpStatusCode]?: HttpResponseSchema.NoBody;
|
|
199
|
-
};
|
|
200
|
-
}
|
|
164
|
+
export type HttpResponseSchemaByStatusCode = {
|
|
165
|
+
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
166
|
+
};
|
|
201
167
|
|
|
202
168
|
/**
|
|
203
169
|
* Extracts the status codes used in a response schema by status code.
|
|
@@ -217,50 +183,19 @@ export interface HttpMethodSchema {
|
|
|
217
183
|
response?: HttpResponseSchemaByStatusCode;
|
|
218
184
|
}
|
|
219
185
|
|
|
220
|
-
export namespace HttpMethodSchema {
|
|
221
|
-
/** A schema representing the structure of an HTTP request and response for a given method, having no request body. */
|
|
222
|
-
export interface NoRequestBody extends Omit<HttpMethodSchema, 'request'> {
|
|
223
|
-
request?: Omit<HttpRequestSchema, 'body'> & { body?: null };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* A schema representing the structure of an HTTP request and response for a given method, having no request and
|
|
228
|
-
* response bodies.
|
|
229
|
-
*/
|
|
230
|
-
export interface NoBody extends Omit<NoRequestBody, 'response'> {
|
|
231
|
-
response?: HttpResponseSchemaByStatusCode.NoBody;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/** Converts an HTTP method schema to be strictly typed. */
|
|
235
|
-
export type AsStrict<Schema> = {
|
|
236
|
-
[Key in keyof Schema]: Key extends 'request'
|
|
237
|
-
? HttpRequestSchema.AsStrict<Schema[Key]>
|
|
238
|
-
: Key extends 'response'
|
|
239
|
-
? HttpResponseSchemaByStatusCode.AsStrict<Schema[Key]>
|
|
240
|
-
: Schema[Key];
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
186
|
/**
|
|
245
187
|
* A schema representing the structure of HTTP request and response by method.
|
|
246
188
|
*
|
|
247
189
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
248
190
|
*/
|
|
249
191
|
export interface HttpMethodsSchema {
|
|
250
|
-
GET?: HttpMethodSchema
|
|
192
|
+
GET?: HttpMethodSchema;
|
|
251
193
|
POST?: HttpMethodSchema;
|
|
252
194
|
PUT?: HttpMethodSchema;
|
|
253
195
|
PATCH?: HttpMethodSchema;
|
|
254
196
|
DELETE?: HttpMethodSchema;
|
|
255
|
-
HEAD?: HttpMethodSchema
|
|
256
|
-
OPTIONS?: HttpMethodSchema
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export namespace HttpMethodsSchema {
|
|
260
|
-
/** Converts an HTTP methods schema to be strictly typed. */
|
|
261
|
-
export type AsStrict<Schema> = {
|
|
262
|
-
[Method in keyof Schema]: HttpMethodSchema.AsStrict<Schema[Method]>;
|
|
263
|
-
};
|
|
197
|
+
HEAD?: HttpMethodSchema;
|
|
198
|
+
OPTIONS?: HttpMethodSchema;
|
|
264
199
|
}
|
|
265
200
|
|
|
266
201
|
interface BaseHttpSchema {
|
|
@@ -279,7 +214,7 @@ interface BaseHttpSchema {
|
|
|
279
214
|
*
|
|
280
215
|
* interface UserListSearchParams {
|
|
281
216
|
* name?: string;
|
|
282
|
-
* limit?:
|
|
217
|
+
* limit?: number;
|
|
283
218
|
* }
|
|
284
219
|
*
|
|
285
220
|
* type Schema = HttpSchema<{
|
|
@@ -302,14 +237,9 @@ interface BaseHttpSchema {
|
|
|
302
237
|
*
|
|
303
238
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
304
239
|
*/
|
|
305
|
-
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> =
|
|
240
|
+
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
306
241
|
|
|
307
242
|
export namespace HttpSchema {
|
|
308
|
-
/** Converts an HTTP service schema to be strictly typed. */
|
|
309
|
-
export type AsStrict<Schema extends BaseHttpSchema> = {
|
|
310
|
-
[Path in keyof Schema]: HttpMethodsSchema.AsStrict<Schema[Path]>;
|
|
311
|
-
};
|
|
312
|
-
|
|
313
243
|
/**
|
|
314
244
|
* Declares an HTTP service methods schema.
|
|
315
245
|
*
|
|
@@ -328,7 +258,7 @@ export namespace HttpSchema {
|
|
|
328
258
|
* '/users': UserMethods;
|
|
329
259
|
* }>;
|
|
330
260
|
*/
|
|
331
|
-
export type Methods<Schema extends HttpMethodsSchema> =
|
|
261
|
+
export type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
332
262
|
|
|
333
263
|
/**
|
|
334
264
|
* Declares an HTTP service method schema.
|
|
@@ -348,7 +278,7 @@ export namespace HttpSchema {
|
|
|
348
278
|
* };
|
|
349
279
|
* }>;
|
|
350
280
|
*/
|
|
351
|
-
export type Method<Schema extends HttpMethodSchema> =
|
|
281
|
+
export type Method<Schema extends HttpMethodSchema> = Schema;
|
|
352
282
|
|
|
353
283
|
/**
|
|
354
284
|
* Declares an HTTP service request schema.
|
|
@@ -372,7 +302,7 @@ export namespace HttpSchema {
|
|
|
372
302
|
* };
|
|
373
303
|
* }>;
|
|
374
304
|
*/
|
|
375
|
-
export type Request<Schema extends HttpRequestSchema> =
|
|
305
|
+
export type Request<Schema extends HttpRequestSchema> = Schema;
|
|
376
306
|
|
|
377
307
|
/**
|
|
378
308
|
* Declares an HTTP service response schema by status code.
|
|
@@ -393,8 +323,7 @@ export namespace HttpSchema {
|
|
|
393
323
|
* };
|
|
394
324
|
* }>;
|
|
395
325
|
*/
|
|
396
|
-
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> =
|
|
397
|
-
HttpResponseSchemaByStatusCode.AsStrict<Schema>;
|
|
326
|
+
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
398
327
|
|
|
399
328
|
/**
|
|
400
329
|
* Declares an HTTP service response schema.
|
|
@@ -416,11 +345,10 @@ export namespace HttpSchema {
|
|
|
416
345
|
* };
|
|
417
346
|
* }>;
|
|
418
347
|
*/
|
|
419
|
-
export type Response<Schema extends HttpResponseSchema> =
|
|
348
|
+
export type Response<Schema extends HttpResponseSchema> = Schema;
|
|
420
349
|
|
|
421
350
|
/**
|
|
422
|
-
* Declares an HTTP body schema.
|
|
423
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary.
|
|
351
|
+
* Declares an HTTP body schema.
|
|
424
352
|
*
|
|
425
353
|
* @example
|
|
426
354
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -437,12 +365,10 @@ export namespace HttpSchema {
|
|
|
437
365
|
* };
|
|
438
366
|
* }>;
|
|
439
367
|
*/
|
|
440
|
-
export type Body<Schema extends HttpBody.Loose> =
|
|
368
|
+
export type Body<Schema extends HttpBody.Loose> = Schema;
|
|
441
369
|
|
|
442
370
|
/**
|
|
443
|
-
* Declares an HTTP headers schema.
|
|
444
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheadersserialized `HttpHeadersSerialized`} if
|
|
445
|
-
* necessary.
|
|
371
|
+
* Declares an HTTP headers schema.
|
|
446
372
|
*
|
|
447
373
|
* @example
|
|
448
374
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -464,12 +390,10 @@ export namespace HttpSchema {
|
|
|
464
390
|
* };
|
|
465
391
|
* }>;
|
|
466
392
|
*/
|
|
467
|
-
export type Headers<Schema extends HttpHeadersSchema.Loose> =
|
|
393
|
+
export type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
468
394
|
|
|
469
395
|
/**
|
|
470
|
-
* Declares an HTTP search params schema.
|
|
471
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparamsserialized `HttpSearchParamsSerialized`}
|
|
472
|
-
* if necessary.
|
|
396
|
+
* Declares an HTTP search params schema.
|
|
473
397
|
*
|
|
474
398
|
* @example
|
|
475
399
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -492,11 +416,10 @@ export namespace HttpSchema {
|
|
|
492
416
|
* };
|
|
493
417
|
* }>;
|
|
494
418
|
*/
|
|
495
|
-
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> =
|
|
419
|
+
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
496
420
|
|
|
497
421
|
/**
|
|
498
|
-
* Declares an HTTP path params schema.
|
|
499
|
-
* {@link HttpPathParamsSerialized} if necessary.
|
|
422
|
+
* Declares an HTTP path params schema.
|
|
500
423
|
*
|
|
501
424
|
* @example
|
|
502
425
|
* import { type HttpSchema, InferPathParams } from '@zimic/http';
|
|
@@ -518,12 +441,10 @@ export namespace HttpSchema {
|
|
|
518
441
|
* // Or infer from the path string
|
|
519
442
|
* type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
520
443
|
*/
|
|
521
|
-
export type PathParams<Schema extends HttpPathParamsSchema.Loose> =
|
|
444
|
+
export type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
522
445
|
|
|
523
446
|
/**
|
|
524
|
-
* Declares an HTTP form data schema.
|
|
525
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdataserialized `HttpFormDataSerialized`} if
|
|
526
|
-
* necessary.
|
|
447
|
+
* Declares an HTTP form data schema.
|
|
527
448
|
*
|
|
528
449
|
* @example
|
|
529
450
|
* import { HttpFormData, type HttpSchema } from '@zimic/http';
|
|
@@ -548,7 +469,7 @@ export namespace HttpSchema {
|
|
|
548
469
|
* };
|
|
549
470
|
* }>;
|
|
550
471
|
*/
|
|
551
|
-
export type FormData<Schema extends HttpFormDataSchema.Loose> =
|
|
472
|
+
export type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
552
473
|
}
|
|
553
474
|
|
|
554
475
|
/**
|
|
@@ -748,26 +669,13 @@ export type InferPathParams<
|
|
|
748
669
|
>;
|
|
749
670
|
|
|
750
671
|
type OmitPastHttpStatusCodes<
|
|
751
|
-
Schema extends HttpResponseSchemaByStatusCode
|
|
752
|
-
PastSchemas extends HttpResponseSchemaByStatusCode
|
|
672
|
+
Schema extends HttpResponseSchemaByStatusCode,
|
|
673
|
+
PastSchemas extends HttpResponseSchemaByStatusCode[],
|
|
753
674
|
> =
|
|
754
|
-
PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode
|
|
675
|
+
PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode>
|
|
755
676
|
? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>>
|
|
756
677
|
: Schema;
|
|
757
678
|
|
|
758
|
-
type RecursiveMergeHttpResponsesByStatusCode<
|
|
759
|
-
Schemas extends HttpResponseSchemaByStatusCode.Loose[],
|
|
760
|
-
PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = [],
|
|
761
|
-
> = Schemas extends [
|
|
762
|
-
infer FirstSchema extends HttpResponseSchemaByStatusCode.Loose,
|
|
763
|
-
...infer RestSchemas extends HttpResponseSchemaByStatusCode.Loose[],
|
|
764
|
-
]
|
|
765
|
-
? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode.Loose>
|
|
766
|
-
? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> &
|
|
767
|
-
RecursiveMergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]>
|
|
768
|
-
: OmitPastHttpStatusCodes<FirstSchema, PastSchemas>
|
|
769
|
-
: never;
|
|
770
|
-
|
|
771
679
|
/**
|
|
772
680
|
* Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
|
|
773
681
|
* first declaration takes precedence.
|
|
@@ -802,6 +710,14 @@ type RecursiveMergeHttpResponsesByStatusCode<
|
|
|
802
710
|
* }>;
|
|
803
711
|
*/
|
|
804
712
|
export type MergeHttpResponsesByStatusCode<
|
|
805
|
-
Schemas extends HttpResponseSchemaByStatusCode
|
|
806
|
-
PastSchemas extends HttpResponseSchemaByStatusCode
|
|
807
|
-
> =
|
|
713
|
+
Schemas extends HttpResponseSchemaByStatusCode[],
|
|
714
|
+
PastSchemas extends HttpResponseSchemaByStatusCode[] = [],
|
|
715
|
+
> = Schemas extends [
|
|
716
|
+
infer FirstSchema extends HttpResponseSchemaByStatusCode,
|
|
717
|
+
...infer RestSchemas extends HttpResponseSchemaByStatusCode[],
|
|
718
|
+
]
|
|
719
|
+
? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode>
|
|
720
|
+
? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> &
|
|
721
|
+
MergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]>
|
|
722
|
+
: OmitPastHttpStatusCodes<FirstSchema, PastSchemas>
|
|
723
|
+
: never;
|