@zimic/http 0.3.2 → 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-4OL77NXP.mjs → chunk-KVTV4E5K.mjs} +28 -100
- package/dist/chunk-KVTV4E5K.mjs.map +1 -0
- package/dist/{chunk-56PYXPSB.js → chunk-LOHINQWU.js} +28 -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 -132
- package/dist/index.js +3 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -13
- 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/index.ts +1 -3
- 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 -147
- package/dist/chunk-4OL77NXP.mjs.map +0 -1
- package/dist/chunk-56PYXPSB.js.map +0 -1
package/src/types/schema.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
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
|
-
export const HTTP_METHODS_WITH_REQUEST_BODY = Object.freeze(['POST', 'PUT', 'PATCH', 'DELETE'] as const);
|
|
10
|
-
export type HttpMethodWithRequestBody = (typeof HTTP_METHODS_WITH_REQUEST_BODY)[number];
|
|
11
|
-
|
|
12
|
-
export const HTTP_METHODS_WITH_RESPONSE_BODY = Object.freeze([
|
|
13
|
-
'GET',
|
|
14
|
-
'POST',
|
|
15
|
-
'PUT',
|
|
16
|
-
'PATCH',
|
|
17
|
-
'DELETE',
|
|
18
|
-
'OPTIONS',
|
|
19
|
-
] as const);
|
|
20
|
-
export type HttpMethodWithResponseBody = (typeof HTTP_METHODS_WITH_RESPONSE_BODY)[number];
|
|
21
|
-
|
|
22
16
|
export const HTTP_METHODS = Object.freeze(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const);
|
|
23
17
|
/**
|
|
24
18
|
* A type representing the currently supported
|
|
@@ -37,19 +31,6 @@ export interface HttpRequestSchema {
|
|
|
37
31
|
body?: HttpBody.Loose;
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
export namespace HttpRequestSchema {
|
|
41
|
-
/** Convert an HTTP request schema to be strictly typed. */
|
|
42
|
-
export type AsStrict<Schema> = {
|
|
43
|
-
[Key in keyof Schema]: Key extends 'headers'
|
|
44
|
-
? HttpHeadersSerialized<Schema[Key]>
|
|
45
|
-
: Key extends 'searchParams'
|
|
46
|
-
? HttpSearchParamsSerialized<Schema[Key]>
|
|
47
|
-
: Key extends 'body'
|
|
48
|
-
? HttpBody.AsStrict<Schema[Key]>
|
|
49
|
-
: Schema[Key];
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
34
|
/**
|
|
54
35
|
* A schema representing the structure of an HTTP response.
|
|
55
36
|
*
|
|
@@ -60,16 +41,6 @@ export interface HttpResponseSchema {
|
|
|
60
41
|
body?: HttpBody.Loose;
|
|
61
42
|
}
|
|
62
43
|
|
|
63
|
-
export namespace HttpResponseSchema {
|
|
64
|
-
/** A schema representing the structure of an HTTP response with no body. */
|
|
65
|
-
export interface NoBody extends Omit<HttpResponseSchema, 'body'> {
|
|
66
|
-
body?: null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Convert an HTTP response schema to be strictly typed. */
|
|
70
|
-
export type AsStrict<Schema> = HttpRequestSchema.AsStrict<Schema>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
44
|
/**
|
|
74
45
|
* The status codes used in HTTP responses, as defined by
|
|
75
46
|
* {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
|
|
@@ -190,27 +161,9 @@ export namespace HttpStatusCode {
|
|
|
190
161
|
*
|
|
191
162
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
192
163
|
*/
|
|
193
|
-
export type HttpResponseSchemaByStatusCode =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
export namespace HttpResponseSchemaByStatusCode {
|
|
197
|
-
/** A loose version of HTTP responses by status code. JSON values are not strictly typed. */
|
|
198
|
-
export type Loose = {
|
|
199
|
-
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/** Converts an HTTP response schema by status code to be strictly typed. */
|
|
203
|
-
export type AsStrict<Schema> = {
|
|
204
|
-
[StatusCode in keyof Schema]: StatusCode extends 204
|
|
205
|
-
? HttpResponseSchema.NoBody
|
|
206
|
-
: HttpResponseSchema.AsStrict<Schema[StatusCode]>;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/** A schema representing the structure of HTTP responses by status code with no body. */
|
|
210
|
-
export type NoBody = {
|
|
211
|
-
[StatusCode in HttpStatusCode]?: HttpResponseSchema.NoBody;
|
|
212
|
-
};
|
|
213
|
-
}
|
|
164
|
+
export type HttpResponseSchemaByStatusCode = {
|
|
165
|
+
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
166
|
+
};
|
|
214
167
|
|
|
215
168
|
/**
|
|
216
169
|
* Extracts the status codes used in a response schema by status code.
|
|
@@ -230,50 +183,19 @@ export interface HttpMethodSchema {
|
|
|
230
183
|
response?: HttpResponseSchemaByStatusCode;
|
|
231
184
|
}
|
|
232
185
|
|
|
233
|
-
export namespace HttpMethodSchema {
|
|
234
|
-
/** A schema representing the structure of an HTTP request and response for a given method, having no request body. */
|
|
235
|
-
export interface NoRequestBody extends Omit<HttpMethodSchema, 'request'> {
|
|
236
|
-
request?: Omit<HttpRequestSchema, 'body'> & { body?: null };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* A schema representing the structure of an HTTP request and response for a given method, having no request and
|
|
241
|
-
* response bodies.
|
|
242
|
-
*/
|
|
243
|
-
export interface NoBody extends Omit<NoRequestBody, 'response'> {
|
|
244
|
-
response?: HttpResponseSchemaByStatusCode.NoBody;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/** Converts an HTTP method schema to be strictly typed. */
|
|
248
|
-
export type AsStrict<Schema> = {
|
|
249
|
-
[Key in keyof Schema]: Key extends 'request'
|
|
250
|
-
? HttpRequestSchema.AsStrict<Schema[Key]>
|
|
251
|
-
: Key extends 'response'
|
|
252
|
-
? HttpResponseSchemaByStatusCode.AsStrict<Schema[Key]>
|
|
253
|
-
: Schema[Key];
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
186
|
/**
|
|
258
187
|
* A schema representing the structure of HTTP request and response by method.
|
|
259
188
|
*
|
|
260
189
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
261
190
|
*/
|
|
262
191
|
export interface HttpMethodsSchema {
|
|
263
|
-
GET?: HttpMethodSchema
|
|
192
|
+
GET?: HttpMethodSchema;
|
|
264
193
|
POST?: HttpMethodSchema;
|
|
265
194
|
PUT?: HttpMethodSchema;
|
|
266
195
|
PATCH?: HttpMethodSchema;
|
|
267
196
|
DELETE?: HttpMethodSchema;
|
|
268
|
-
HEAD?: HttpMethodSchema
|
|
269
|
-
OPTIONS?: HttpMethodSchema
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export namespace HttpMethodsSchema {
|
|
273
|
-
/** Converts an HTTP methods schema to be strictly typed. */
|
|
274
|
-
export type AsStrict<Schema> = {
|
|
275
|
-
[Method in keyof Schema]: HttpMethodSchema.AsStrict<Schema[Method]>;
|
|
276
|
-
};
|
|
197
|
+
HEAD?: HttpMethodSchema;
|
|
198
|
+
OPTIONS?: HttpMethodSchema;
|
|
277
199
|
}
|
|
278
200
|
|
|
279
201
|
interface BaseHttpSchema {
|
|
@@ -292,7 +214,7 @@ interface BaseHttpSchema {
|
|
|
292
214
|
*
|
|
293
215
|
* interface UserListSearchParams {
|
|
294
216
|
* name?: string;
|
|
295
|
-
* limit?:
|
|
217
|
+
* limit?: number;
|
|
296
218
|
* }
|
|
297
219
|
*
|
|
298
220
|
* type Schema = HttpSchema<{
|
|
@@ -315,14 +237,9 @@ interface BaseHttpSchema {
|
|
|
315
237
|
*
|
|
316
238
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
317
239
|
*/
|
|
318
|
-
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> =
|
|
240
|
+
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
319
241
|
|
|
320
242
|
export namespace HttpSchema {
|
|
321
|
-
/** Converts an HTTP service schema to be strictly typed. */
|
|
322
|
-
export type AsStrict<Schema extends BaseHttpSchema> = {
|
|
323
|
-
[Path in keyof Schema]: HttpMethodsSchema.AsStrict<Schema[Path]>;
|
|
324
|
-
};
|
|
325
|
-
|
|
326
243
|
/**
|
|
327
244
|
* Declares an HTTP service methods schema.
|
|
328
245
|
*
|
|
@@ -341,7 +258,7 @@ export namespace HttpSchema {
|
|
|
341
258
|
* '/users': UserMethods;
|
|
342
259
|
* }>;
|
|
343
260
|
*/
|
|
344
|
-
export type Methods<Schema extends HttpMethodsSchema> =
|
|
261
|
+
export type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
345
262
|
|
|
346
263
|
/**
|
|
347
264
|
* Declares an HTTP service method schema.
|
|
@@ -361,7 +278,7 @@ export namespace HttpSchema {
|
|
|
361
278
|
* };
|
|
362
279
|
* }>;
|
|
363
280
|
*/
|
|
364
|
-
export type Method<Schema extends HttpMethodSchema> =
|
|
281
|
+
export type Method<Schema extends HttpMethodSchema> = Schema;
|
|
365
282
|
|
|
366
283
|
/**
|
|
367
284
|
* Declares an HTTP service request schema.
|
|
@@ -385,7 +302,7 @@ export namespace HttpSchema {
|
|
|
385
302
|
* };
|
|
386
303
|
* }>;
|
|
387
304
|
*/
|
|
388
|
-
export type Request<Schema extends HttpRequestSchema> =
|
|
305
|
+
export type Request<Schema extends HttpRequestSchema> = Schema;
|
|
389
306
|
|
|
390
307
|
/**
|
|
391
308
|
* Declares an HTTP service response schema by status code.
|
|
@@ -406,8 +323,7 @@ export namespace HttpSchema {
|
|
|
406
323
|
* };
|
|
407
324
|
* }>;
|
|
408
325
|
*/
|
|
409
|
-
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> =
|
|
410
|
-
HttpResponseSchemaByStatusCode.AsStrict<Schema>;
|
|
326
|
+
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
411
327
|
|
|
412
328
|
/**
|
|
413
329
|
* Declares an HTTP service response schema.
|
|
@@ -429,11 +345,10 @@ export namespace HttpSchema {
|
|
|
429
345
|
* };
|
|
430
346
|
* }>;
|
|
431
347
|
*/
|
|
432
|
-
export type Response<Schema extends HttpResponseSchema> =
|
|
348
|
+
export type Response<Schema extends HttpResponseSchema> = Schema;
|
|
433
349
|
|
|
434
350
|
/**
|
|
435
|
-
* Declares an HTTP body schema.
|
|
436
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary.
|
|
351
|
+
* Declares an HTTP body schema.
|
|
437
352
|
*
|
|
438
353
|
* @example
|
|
439
354
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -450,12 +365,10 @@ export namespace HttpSchema {
|
|
|
450
365
|
* };
|
|
451
366
|
* }>;
|
|
452
367
|
*/
|
|
453
|
-
export type Body<Schema extends HttpBody.Loose> =
|
|
368
|
+
export type Body<Schema extends HttpBody.Loose> = Schema;
|
|
454
369
|
|
|
455
370
|
/**
|
|
456
|
-
* Declares an HTTP headers schema.
|
|
457
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheadersserialized `HttpHeadersSerialized`} if
|
|
458
|
-
* necessary.
|
|
371
|
+
* Declares an HTTP headers schema.
|
|
459
372
|
*
|
|
460
373
|
* @example
|
|
461
374
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -477,12 +390,10 @@ export namespace HttpSchema {
|
|
|
477
390
|
* };
|
|
478
391
|
* }>;
|
|
479
392
|
*/
|
|
480
|
-
export type Headers<Schema extends HttpHeadersSchema.Loose> =
|
|
393
|
+
export type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
481
394
|
|
|
482
395
|
/**
|
|
483
|
-
* Declares an HTTP search params schema.
|
|
484
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparamsserialized `HttpSearchParamsSerialized`}
|
|
485
|
-
* if necessary.
|
|
396
|
+
* Declares an HTTP search params schema.
|
|
486
397
|
*
|
|
487
398
|
* @example
|
|
488
399
|
* import { type HttpSchema } from '@zimic/http';
|
|
@@ -505,11 +416,10 @@ export namespace HttpSchema {
|
|
|
505
416
|
* };
|
|
506
417
|
* }>;
|
|
507
418
|
*/
|
|
508
|
-
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> =
|
|
419
|
+
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
509
420
|
|
|
510
421
|
/**
|
|
511
|
-
* Declares an HTTP path params schema.
|
|
512
|
-
* {@link HttpPathParamsSerialized} if necessary.
|
|
422
|
+
* Declares an HTTP path params schema.
|
|
513
423
|
*
|
|
514
424
|
* @example
|
|
515
425
|
* import { type HttpSchema, InferPathParams } from '@zimic/http';
|
|
@@ -531,12 +441,10 @@ export namespace HttpSchema {
|
|
|
531
441
|
* // Or infer from the path string
|
|
532
442
|
* type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
533
443
|
*/
|
|
534
|
-
export type PathParams<Schema extends HttpPathParamsSchema.Loose> =
|
|
444
|
+
export type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
535
445
|
|
|
536
446
|
/**
|
|
537
|
-
* Declares an HTTP form data schema.
|
|
538
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdataserialized `HttpFormDataSerialized`} if
|
|
539
|
-
* necessary.
|
|
447
|
+
* Declares an HTTP form data schema.
|
|
540
448
|
*
|
|
541
449
|
* @example
|
|
542
450
|
* import { HttpFormData, type HttpSchema } from '@zimic/http';
|
|
@@ -561,7 +469,7 @@ export namespace HttpSchema {
|
|
|
561
469
|
* };
|
|
562
470
|
* }>;
|
|
563
471
|
*/
|
|
564
|
-
export type FormData<Schema extends HttpFormDataSchema.Loose> =
|
|
472
|
+
export type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
565
473
|
}
|
|
566
474
|
|
|
567
475
|
/**
|
|
@@ -761,26 +669,13 @@ export type InferPathParams<
|
|
|
761
669
|
>;
|
|
762
670
|
|
|
763
671
|
type OmitPastHttpStatusCodes<
|
|
764
|
-
Schema extends HttpResponseSchemaByStatusCode
|
|
765
|
-
PastSchemas extends HttpResponseSchemaByStatusCode
|
|
672
|
+
Schema extends HttpResponseSchemaByStatusCode,
|
|
673
|
+
PastSchemas extends HttpResponseSchemaByStatusCode[],
|
|
766
674
|
> =
|
|
767
|
-
PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode
|
|
675
|
+
PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode>
|
|
768
676
|
? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>>
|
|
769
677
|
: Schema;
|
|
770
678
|
|
|
771
|
-
type RecursiveMergeHttpResponsesByStatusCode<
|
|
772
|
-
Schemas extends HttpResponseSchemaByStatusCode.Loose[],
|
|
773
|
-
PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = [],
|
|
774
|
-
> = Schemas extends [
|
|
775
|
-
infer FirstSchema extends HttpResponseSchemaByStatusCode.Loose,
|
|
776
|
-
...infer RestSchemas extends HttpResponseSchemaByStatusCode.Loose[],
|
|
777
|
-
]
|
|
778
|
-
? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode.Loose>
|
|
779
|
-
? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> &
|
|
780
|
-
RecursiveMergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]>
|
|
781
|
-
: OmitPastHttpStatusCodes<FirstSchema, PastSchemas>
|
|
782
|
-
: never;
|
|
783
|
-
|
|
784
679
|
/**
|
|
785
680
|
* Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
|
|
786
681
|
* first declaration takes precedence.
|
|
@@ -815,6 +710,14 @@ type RecursiveMergeHttpResponsesByStatusCode<
|
|
|
815
710
|
* }>;
|
|
816
711
|
*/
|
|
817
712
|
export type MergeHttpResponsesByStatusCode<
|
|
818
|
-
Schemas extends HttpResponseSchemaByStatusCode
|
|
819
|
-
PastSchemas extends HttpResponseSchemaByStatusCode
|
|
820
|
-
> =
|
|
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;
|