@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/index.d.ts CHANGED
@@ -82,6 +82,15 @@ type ArrayKey<Type> = keyof PickArrayProperties<Type>;
82
82
  type NonArrayKey<Type> = string | number extends ArrayKey<Type> ? keyof Type : Exclude<keyof Type, ArrayKey<Type>>;
83
83
  type NonEmptyArray<Type> = [Type, ...Type[]];
84
84
  type ReplaceBy<Type, Source, Target> = Type extends Source ? Target : Type;
85
+ declare const brand: unique symbol;
86
+ /**
87
+ * A utility type to create a branded type. This is useful for creating types that are distinct from each other even if
88
+ * they have the same underlying structure. It also helps the TypeScript compiler to reference the type in the generated
89
+ * declaration files, rather than inlining it.
90
+ */
91
+ type Branded<Type, Brand extends string> = Type & {
92
+ [brand]?: Brand;
93
+ };
85
94
 
86
95
  /** A schema for strict HTTP form data. */
87
96
  interface HttpFormDataSchema {
@@ -181,13 +190,13 @@ type HttpFormDataSerialized<Type> = Type extends HttpFormDataSchema ? Type : Typ
181
190
  *
182
191
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdata `HttpFormData` API reference}
183
192
  */
184
- declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchema> extends FormData {
193
+ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose, Schema extends HttpFormDataSchema = HttpFormDataSerialized<LooseSchema>> extends FormData {
185
194
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/set MDN Reference} */
186
- set<Name extends HttpFormDataSchemaName<Schema>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<Schema[Name]>>, Blob>): void;
187
- set<Name extends HttpFormDataSchemaName<Schema>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<Schema[Name]>>, string>, fileName?: string): void;
195
+ set<Name extends HttpFormDataSchemaName<Schema>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
196
+ set<Name extends HttpFormDataSchemaName<Schema>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
188
197
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/append MDN Reference} */
189
- append<Name extends HttpFormDataSchemaName<Schema>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<Schema[Name]>>, Blob>): void;
190
- append<Name extends HttpFormDataSchemaName<Schema>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<Schema[Name]>>, string>, fileName?: string): void;
198
+ append<Name extends HttpFormDataSchemaName<Schema>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
199
+ append<Name extends HttpFormDataSchemaName<Schema>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
191
200
  /**
192
201
  * Get the value of the entry associated to a key name.
193
202
  *
@@ -234,7 +243,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
234
243
  * @returns A promise that resolves with `true` if the data is equal to the other data, or `false` otherwise.
235
244
  * Important: both form data might be read while comparing.
236
245
  */
237
- equals<OtherSchema extends Schema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
246
+ equals<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
238
247
  /**
239
248
  * Checks if the data contains the other data. This method is less strict than {@link HttpFormData#equals} and only
240
249
  * requires that all keys and values in the other data are present in this data.
@@ -243,7 +252,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
243
252
  * @returns A promise that resolves with `true` if this data contains the other data, or `false` otherwise. Important:
244
253
  * both form data might be read while comparing.
245
254
  */
246
- contains<OtherSchema extends Schema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
255
+ contains<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
247
256
  /**
248
257
  * Converts this form data into a plain object. This method is useful for serialization and debugging purposes.
249
258
  *
@@ -313,11 +322,11 @@ declare namespace HttpHeadersSchema {
313
322
  type Loose = Record<string, any>;
314
323
  }
315
324
  /** A strict tuple representation of a {@link HttpHeadersSchema}. */
316
- type HttpHeadersSchemaTuple<Schema extends HttpHeadersSchema = HttpHeadersSchema> = {
325
+ type HttpHeadersSchemaTuple<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = {
317
326
  [Key in keyof Schema & string]: [Key, NonNullable<Schema[Key]>];
318
327
  }[keyof Schema & string];
319
328
  /** An initialization value for {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheaders `HttpHeaders`}. */
320
- type HttpHeadersInit<Schema extends HttpHeadersSchema = HttpHeadersSchema> = Headers | Schema | HttpHeaders<Schema> | HttpHeadersSchemaTuple<Schema>[];
329
+ type HttpHeadersInit<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = Headers | Schema | HttpHeaders<Schema> | HttpHeadersSchemaTuple<Schema>[];
321
330
  /**
322
331
  * Extracts the names of the headers defined in a {@link HttpHeadersSchema}. Each key is considered a header name.
323
332
  *
@@ -378,12 +387,12 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
378
387
  *
379
388
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheaders `HttpHeaders` API reference}
380
389
  */
381
- declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> extends Headers {
382
- constructor(init?: HttpHeadersInit<Schema>);
390
+ declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose, Schema extends HttpHeadersSchema = HttpHeadersSerialized<LooseSchema>> extends Headers {
391
+ constructor(init?: HttpHeadersInit<LooseSchema>);
383
392
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/set MDN Reference} */
384
- set<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]> & string): void;
393
+ set<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
385
394
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/append MDN Reference} */
386
- append<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<Schema[Name]> & string): void;
395
+ append<Name extends HttpHeadersSchemaName<Schema>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
387
396
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/get MDN Reference} */
388
397
  get<Name extends HttpHeadersSchemaName<Schema>>(name: Name): ReplaceBy<Schema[Name], undefined, null>;
389
398
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
@@ -413,7 +422,7 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
413
422
  * @param otherHeaders The other headers object to compare against.
414
423
  * @returns `true` if the headers are equal, `false` otherwise.
415
424
  */
416
- equals<OtherSchema extends Schema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
425
+ equals<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
417
426
  /**
418
427
  * Checks if this headers object contains another set of headers. This method is less strict than
419
428
  * {@link HttpHeaders#equals} and only requires that all keys and values in the other headers are present in these
@@ -422,7 +431,7 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
422
431
  * @param otherHeaders The other headers object to compare against.
423
432
  * @returns `true` if these headers contain the other headers, `false` otherwise.
424
433
  */
425
- contains<OtherSchema extends Schema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
434
+ contains<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
426
435
  /**
427
436
  * Converts these headers into a plain object. This method is useful for serialization and debugging purposes.
428
437
  *
@@ -449,14 +458,14 @@ declare namespace HttpSearchParamsSchema {
449
458
  type Loose = Record<string, any>;
450
459
  }
451
460
  /** A strict tuple representation of a {@link HttpSearchParamsSchema}. */
452
- type HttpSearchParamsSchemaTuple<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = {
461
+ type HttpSearchParamsSchemaTuple<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = {
453
462
  [Key in keyof Schema & string]: [Key, ArrayItemIfArray<NonNullable<Schema[Key]>>];
454
463
  }[keyof Schema & string];
455
464
  /**
456
465
  * An initialization value for
457
466
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams`}.
458
467
  */
459
- type HttpSearchParamsInit<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = string | URLSearchParams | Schema | HttpSearchParams<Schema> | HttpSearchParamsSchemaTuple<Schema>[];
468
+ type HttpSearchParamsInit<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = string | URLSearchParams | Schema | HttpSearchParams<Schema> | HttpSearchParamsSchemaTuple<Schema>[];
460
469
  declare namespace HttpSearchParamsSchemaName {
461
470
  /** Extracts the names of the search params defined in a {@link HttpSearchParamsSchema} that are arrays. */
462
471
  type Array<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, ArrayKey<Schema> & string>;
@@ -546,13 +555,13 @@ type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Ty
546
555
  *
547
556
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams` API reference}
548
557
  */
549
- declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> extends URLSearchParams {
550
- constructor(init?: HttpSearchParamsInit<Schema>);
558
+ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose, Schema extends HttpSearchParamsSchema = HttpSearchParamsSerialized<LooseSchema>> extends URLSearchParams {
559
+ constructor(init?: HttpSearchParamsInit<LooseSchema>);
551
560
  private populateInitArrayProperties;
552
561
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/set MDN Reference} */
553
- set<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value: ArrayItemIfArray<NonNullable<Schema[Name]>>): void;
562
+ set<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
554
563
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/append MDN Reference} */
555
- append<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value: ArrayItemIfArray<NonNullable<Schema[Name]>>): void;
564
+ append<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
556
565
  /**
557
566
  * Get the value of the entry associated to a key name.
558
567
  *
@@ -574,9 +583,9 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
574
583
  */
575
584
  getAll<Name extends HttpSearchParamsSchemaName.Array<Schema>>(name: Name): ArrayItemIfArray<NonNullable<Schema[Name]>>[];
576
585
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/has MDN Reference} */
577
- has<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value?: ArrayItemIfArray<NonNullable<Schema[Name]>>): boolean;
586
+ has<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): boolean;
578
587
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete MDN Reference} */
579
- delete<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value?: ArrayItemIfArray<NonNullable<Schema[Name]>>): void;
588
+ delete<Name extends HttpSearchParamsSchemaName<Schema>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
580
589
  forEach<This extends HttpSearchParams<Schema>>(callback: <Key extends HttpSearchParamsSchemaName<Schema>>(value: ArrayItemIfArray<NonNullable<Schema[Key]>>, key: Key, parent: HttpSearchParams<Schema>) => void, thisArg?: This): void;
581
590
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys MDN Reference} */
582
591
  keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<Schema>>;
@@ -598,7 +607,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
598
607
  * @param otherParams The other search parameters to compare against.
599
608
  * @returns `true` if the search parameters are equal, `false` otherwise.
600
609
  */
601
- equals<OtherSchema extends Schema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
610
+ equals<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
602
611
  /**
603
612
  * Checks if these search params contain another set of search parameters. This method is less strict than
604
613
  * {@link HttpSearchParams#equals} and only requires that all keys and values in the other search parameters are
@@ -607,7 +616,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
607
616
  * @param otherParams The other search parameters to check for containment.
608
617
  * @returns `true` if these search parameters contain the other search parameters, `false` otherwise.
609
618
  */
610
- contains<OtherSchema extends Schema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
619
+ contains<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
611
620
  /**
612
621
  * Converts these search params into a plain object. This method is useful for serialization and debugging purposes.
613
622
  *
@@ -629,10 +638,6 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
629
638
  toObject(): Schema;
630
639
  }
631
640
 
632
- declare const HTTP_METHODS_WITH_REQUEST_BODY: readonly ["POST", "PUT", "PATCH", "DELETE"];
633
- type HttpMethodWithRequestBody = (typeof HTTP_METHODS_WITH_REQUEST_BODY)[number];
634
- declare const HTTP_METHODS_WITH_RESPONSE_BODY: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
635
- type HttpMethodWithResponseBody = (typeof HTTP_METHODS_WITH_RESPONSE_BODY)[number];
636
641
  declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
637
642
  /**
638
643
  * A type representing the currently supported
@@ -649,12 +654,6 @@ interface HttpRequestSchema {
649
654
  searchParams?: HttpSearchParamsSchema.Loose;
650
655
  body?: HttpBody.Loose;
651
656
  }
652
- declare namespace HttpRequestSchema {
653
- /** Convert an HTTP request schema to be strictly typed. */
654
- type AsStrict<Schema> = {
655
- [Key in keyof Schema]: Key extends 'headers' ? HttpHeadersSerialized<Schema[Key]> : Key extends 'searchParams' ? HttpSearchParamsSerialized<Schema[Key]> : Key extends 'body' ? HttpBody.AsStrict<Schema[Key]> : Schema[Key];
656
- };
657
- }
658
657
  /**
659
658
  * A schema representing the structure of an HTTP response.
660
659
  *
@@ -664,14 +663,6 @@ interface HttpResponseSchema {
664
663
  headers?: HttpHeadersSchema.Loose;
665
664
  body?: HttpBody.Loose;
666
665
  }
667
- declare namespace HttpResponseSchema {
668
- /** A schema representing the structure of an HTTP response with no body. */
669
- interface NoBody extends Omit<HttpResponseSchema, 'body'> {
670
- body?: null;
671
- }
672
- /** Convert an HTTP response schema to be strictly typed. */
673
- type AsStrict<Schema> = HttpRequestSchema.AsStrict<Schema>;
674
- }
675
666
  /**
676
667
  * The status codes used in HTTP responses, as defined by
677
668
  * {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
@@ -720,21 +711,9 @@ declare namespace HttpStatusCode {
720
711
  *
721
712
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
722
713
  */
723
- type HttpResponseSchemaByStatusCode = HttpResponseSchemaByStatusCode.AsStrict<HttpResponseSchemaByStatusCode.Loose>;
724
- declare namespace HttpResponseSchemaByStatusCode {
725
- /** A loose version of HTTP responses by status code. JSON values are not strictly typed. */
726
- type Loose = {
727
- [StatusCode in HttpStatusCode]?: HttpResponseSchema;
728
- };
729
- /** Converts an HTTP response schema by status code to be strictly typed. */
730
- type AsStrict<Schema> = {
731
- [StatusCode in keyof Schema]: StatusCode extends 204 ? HttpResponseSchema.NoBody : HttpResponseSchema.AsStrict<Schema[StatusCode]>;
732
- };
733
- /** A schema representing the structure of HTTP responses by status code with no body. */
734
- type NoBody = {
735
- [StatusCode in HttpStatusCode]?: HttpResponseSchema.NoBody;
736
- };
737
- }
714
+ type HttpResponseSchemaByStatusCode = {
715
+ [StatusCode in HttpStatusCode]?: HttpResponseSchema;
716
+ };
738
717
  /**
739
718
  * Extracts the status codes used in a response schema by status code.
740
719
  *
@@ -750,44 +729,19 @@ interface HttpMethodSchema {
750
729
  request?: HttpRequestSchema;
751
730
  response?: HttpResponseSchemaByStatusCode;
752
731
  }
753
- declare namespace HttpMethodSchema {
754
- /** A schema representing the structure of an HTTP request and response for a given method, having no request body. */
755
- interface NoRequestBody extends Omit<HttpMethodSchema, 'request'> {
756
- request?: Omit<HttpRequestSchema, 'body'> & {
757
- body?: null;
758
- };
759
- }
760
- /**
761
- * A schema representing the structure of an HTTP request and response for a given method, having no request and
762
- * response bodies.
763
- */
764
- interface NoBody extends Omit<NoRequestBody, 'response'> {
765
- response?: HttpResponseSchemaByStatusCode.NoBody;
766
- }
767
- /** Converts an HTTP method schema to be strictly typed. */
768
- type AsStrict<Schema> = {
769
- [Key in keyof Schema]: Key extends 'request' ? HttpRequestSchema.AsStrict<Schema[Key]> : Key extends 'response' ? HttpResponseSchemaByStatusCode.AsStrict<Schema[Key]> : Schema[Key];
770
- };
771
- }
772
732
  /**
773
733
  * A schema representing the structure of HTTP request and response by method.
774
734
  *
775
735
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
776
736
  */
777
737
  interface HttpMethodsSchema {
778
- GET?: HttpMethodSchema.NoRequestBody;
738
+ GET?: HttpMethodSchema;
779
739
  POST?: HttpMethodSchema;
780
740
  PUT?: HttpMethodSchema;
781
741
  PATCH?: HttpMethodSchema;
782
742
  DELETE?: HttpMethodSchema;
783
- HEAD?: HttpMethodSchema.NoBody;
784
- OPTIONS?: HttpMethodSchema.NoRequestBody;
785
- }
786
- declare namespace HttpMethodsSchema {
787
- /** Converts an HTTP methods schema to be strictly typed. */
788
- type AsStrict<Schema> = {
789
- [Method in keyof Schema]: HttpMethodSchema.AsStrict<Schema[Method]>;
790
- };
743
+ HEAD?: HttpMethodSchema;
744
+ OPTIONS?: HttpMethodSchema;
791
745
  }
792
746
  interface BaseHttpSchema {
793
747
  [path: string]: HttpMethodsSchema;
@@ -804,7 +758,7 @@ interface BaseHttpSchema {
804
758
  *
805
759
  * interface UserListSearchParams {
806
760
  * name?: string;
807
- * limit?: `${number}`;
761
+ * limit?: number;
808
762
  * }
809
763
  *
810
764
  * type Schema = HttpSchema<{
@@ -827,12 +781,8 @@ interface BaseHttpSchema {
827
781
  *
828
782
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
829
783
  */
830
- type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = HttpSchema.AsStrict<Schema>;
784
+ type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
831
785
  declare namespace HttpSchema {
832
- /** Converts an HTTP service schema to be strictly typed. */
833
- type AsStrict<Schema extends BaseHttpSchema> = {
834
- [Path in keyof Schema]: HttpMethodsSchema.AsStrict<Schema[Path]>;
835
- };
836
786
  /**
837
787
  * Declares an HTTP service methods schema.
838
788
  *
@@ -851,7 +801,7 @@ declare namespace HttpSchema {
851
801
  * '/users': UserMethods;
852
802
  * }>;
853
803
  */
854
- type Methods<Schema extends HttpMethodsSchema> = HttpMethodsSchema.AsStrict<Schema>;
804
+ type Methods<Schema extends HttpMethodsSchema> = Schema;
855
805
  /**
856
806
  * Declares an HTTP service method schema.
857
807
  *
@@ -870,7 +820,7 @@ declare namespace HttpSchema {
870
820
  * };
871
821
  * }>;
872
822
  */
873
- type Method<Schema extends HttpMethodSchema> = HttpMethodSchema.AsStrict<Schema>;
823
+ type Method<Schema extends HttpMethodSchema> = Schema;
874
824
  /**
875
825
  * Declares an HTTP service request schema.
876
826
  *
@@ -893,7 +843,7 @@ declare namespace HttpSchema {
893
843
  * };
894
844
  * }>;
895
845
  */
896
- type Request<Schema extends HttpRequestSchema> = HttpRequestSchema.AsStrict<Schema>;
846
+ type Request<Schema extends HttpRequestSchema> = Schema;
897
847
  /**
898
848
  * Declares an HTTP service response schema by status code.
899
849
  *
@@ -913,7 +863,7 @@ declare namespace HttpSchema {
913
863
  * };
914
864
  * }>;
915
865
  */
916
- type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = HttpResponseSchemaByStatusCode.AsStrict<Schema>;
866
+ type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
917
867
  /**
918
868
  * Declares an HTTP service response schema.
919
869
  *
@@ -934,10 +884,9 @@ declare namespace HttpSchema {
934
884
  * };
935
885
  * }>;
936
886
  */
937
- type Response<Schema extends HttpResponseSchema> = HttpResponseSchema.AsStrict<Schema>;
887
+ type Response<Schema extends HttpResponseSchema> = Schema;
938
888
  /**
939
- * Declares an HTTP body schema. JSON values are serialized to their strict form using
940
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary.
889
+ * Declares an HTTP body schema.
941
890
  *
942
891
  * @example
943
892
  * import { type HttpSchema } from '@zimic/http';
@@ -954,11 +903,9 @@ declare namespace HttpSchema {
954
903
  * };
955
904
  * }>;
956
905
  */
957
- type Body<Schema extends HttpBody.Loose> = HttpBody.AsStrict<Schema>;
906
+ type Body<Schema extends HttpBody.Loose> = Schema;
958
907
  /**
959
- * Declares an HTTP headers schema. Headers are serialized to their strict form using
960
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheadersserialized `HttpHeadersSerialized`} if
961
- * necessary.
908
+ * Declares an HTTP headers schema.
962
909
  *
963
910
  * @example
964
911
  * import { type HttpSchema } from '@zimic/http';
@@ -980,11 +927,9 @@ declare namespace HttpSchema {
980
927
  * };
981
928
  * }>;
982
929
  */
983
- type Headers<Schema extends HttpHeadersSchema.Loose> = HttpHeadersSerialized<Schema>;
930
+ type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
984
931
  /**
985
- * Declares an HTTP search params schema. Search params are serialized to their strict form using
986
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparamsserialized `HttpSearchParamsSerialized`}
987
- * if necessary.
932
+ * Declares an HTTP search params schema.
988
933
  *
989
934
  * @example
990
935
  * import { type HttpSchema } from '@zimic/http';
@@ -1007,10 +952,9 @@ declare namespace HttpSchema {
1007
952
  * };
1008
953
  * }>;
1009
954
  */
1010
- type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = HttpSearchParamsSerialized<Schema>;
955
+ type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
1011
956
  /**
1012
- * Declares an HTTP path params schema. Path params are serialized to their strict form using
1013
- * {@link HttpPathParamsSerialized} if necessary.
957
+ * Declares an HTTP path params schema.
1014
958
  *
1015
959
  * @example
1016
960
  * import { type HttpSchema, InferPathParams } from '@zimic/http';
@@ -1032,11 +976,9 @@ declare namespace HttpSchema {
1032
976
  * // Or infer from the path string
1033
977
  * type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
1034
978
  */
1035
- type PathParams<Schema extends HttpPathParamsSchema.Loose> = HttpPathParamsSerialized<Schema>;
979
+ type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
1036
980
  /**
1037
- * Declares an HTTP form data schema. Form data is serialized to their strict form using
1038
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdataserialized `HttpFormDataSerialized`} if
1039
- * necessary.
981
+ * Declares an HTTP form data schema.
1040
982
  *
1041
983
  * @example
1042
984
  * import { HttpFormData, type HttpSchema } from '@zimic/http';
@@ -1061,7 +1003,7 @@ declare namespace HttpSchema {
1061
1003
  * };
1062
1004
  * }>;
1063
1005
  */
1064
- type FormData<Schema extends HttpFormDataSchema.Loose> = HttpFormDataSerialized<Schema>;
1006
+ type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
1065
1007
  }
1066
1008
  /**
1067
1009
  * Extracts the methods from an HTTP service schema.
@@ -1204,11 +1146,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
1204
1146
  * // { userId: string }
1205
1147
  */
1206
1148
  type InferPathParams<PathOrSchema extends string | HttpSchema, OptionalPath extends PathOrSchema extends HttpSchema ? HttpSchemaPath.Literal<PathOrSchema> : never = never> = Prettify<RecursiveInferPathParams<PathOrSchema extends HttpSchema ? OptionalPath : PathOrSchema extends string ? PathOrSchema : never>>;
1207
- type OmitPastHttpStatusCodes<Schema extends HttpResponseSchemaByStatusCode.Loose, PastSchemas extends HttpResponseSchemaByStatusCode.Loose[]> = PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode.Loose> ? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>> : Schema;
1208
- type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = Schemas extends [
1209
- infer FirstSchema extends HttpResponseSchemaByStatusCode.Loose,
1210
- ...infer RestSchemas extends HttpResponseSchemaByStatusCode.Loose[]
1211
- ] ? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode.Loose> ? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> & RecursiveMergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]> : OmitPastHttpStatusCodes<FirstSchema, PastSchemas> : never;
1149
+ type OmitPastHttpStatusCodes<Schema extends HttpResponseSchemaByStatusCode, PastSchemas extends HttpResponseSchemaByStatusCode[]> = PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode> ? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>> : Schema;
1212
1150
  /**
1213
1151
  * Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
1214
1152
  * first declaration takes precedence.
@@ -1242,36 +1180,37 @@ type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaB
1242
1180
  * };
1243
1181
  * }>;
1244
1182
  */
1245
- type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = HttpResponseSchemaByStatusCode.AsStrict<RecursiveMergeHttpResponsesByStatusCode<Schemas, PastSchemas>>;
1183
+ type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode[], PastSchemas extends HttpResponseSchemaByStatusCode[] = []> = Schemas extends [
1184
+ infer FirstSchema extends HttpResponseSchemaByStatusCode,
1185
+ ...infer RestSchemas extends HttpResponseSchemaByStatusCode[]
1186
+ ] ? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode> ? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> & MergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]> : OmitPastHttpStatusCodes<FirstSchema, PastSchemas> : never;
1246
1187
 
1247
1188
  /** The body type for HTTP requests and responses. */
1248
1189
  type HttpBody = JSONValue | HttpFormData<any> | HttpSearchParams<any> | Blob | ArrayBuffer;
1249
1190
  declare namespace HttpBody {
1250
1191
  /** A loose version of the HTTP body type. JSON values are not strictly typed. */
1251
1192
  type Loose = ReplaceBy<HttpBody, JSONValue, JSONValue.Loose>;
1252
- /** Convert an HTTP body to be strictly typed. JSON values are serialized to their strict form. */
1253
- type AsStrict<Type> = Type extends Exclude<HttpBody, JSONValue> ? Type : JSONSerialized<Type>;
1254
1193
  }
1255
1194
  /**
1256
1195
  * An HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
1257
1196
  * {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
1258
1197
  */
1259
- type StrictHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> = Pick<HttpHeaders<Schema>, keyof Headers>;
1198
+ type StrictHeaders<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = Pick<HttpHeaders<Schema>, keyof Headers>;
1260
1199
  /**
1261
1200
  * An HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
1262
1201
  * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
1263
1202
  */
1264
- type StrictURLSearchParams<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = Pick<HttpSearchParams<Schema>, keyof URLSearchParams>;
1203
+ type StrictURLSearchParams<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = Pick<HttpSearchParams<Schema>, keyof URLSearchParams>;
1265
1204
  /**
1266
1205
  * An HTTP form data object with a strictly-typed schema. Fully compatible with the built-in
1267
1206
  * {@link https://developer.mozilla.org/docs/Web/API/FormData `FormData`} class.
1268
1207
  */
1269
- type StrictFormData<Schema extends HttpFormDataSchema = HttpFormDataSchema> = Pick<HttpFormData<Schema>, keyof FormData>;
1208
+ type StrictFormData<Schema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose> = Pick<HttpFormData<Schema>, keyof FormData>;
1270
1209
  /**
1271
1210
  * An HTTP request with a strictly-typed JSON body. Fully compatible with the built-in
1272
1211
  * {@link https://developer.mozilla.org/docs/Web/API/Request `Request`} class.
1273
1212
  */
1274
- interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody, StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema> extends Request {
1213
+ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody.Loose, StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Request {
1275
1214
  headers: StrictHeaders<StrictHeadersSchema>;
1276
1215
  text: () => Promise<StrictBody extends string ? StrictBody : string>;
1277
1216
  json: () => Promise<StrictBody extends string | Exclude<HttpBody, JSONValue> ? never : StrictBody>;
@@ -1282,7 +1221,7 @@ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody, StrictHeader
1282
1221
  * An HTTP response with a strictly-typed JSON body and status code. Fully compatible with the built-in
1283
1222
  * {@link https://developer.mozilla.org/docs/Web/API/Response `Response`} class.
1284
1223
  */
1285
- interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody, StatusCode extends number = number, StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema> extends Response {
1224
+ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody.Loose, StatusCode extends number = number, StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Response {
1286
1225
  ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection ? true : false;
1287
1226
  status: StatusCode;
1288
1227
  headers: StrictHeaders<StrictHeadersSchema>;
@@ -1291,10 +1230,10 @@ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody, StatusCode
1291
1230
  formData: () => Promise<StrictBody extends HttpFormData<infer HttpFormDataSchema> ? StrictFormData<HttpFormDataSchema> : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema> ? StrictFormData<HttpSearchParamsSchema> : FormData>;
1292
1231
  clone: () => this;
1293
1232
  }
1294
- type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = Default<Default<MethodSchema['request']>['headers']>;
1295
- type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> = Default<Default<MethodSchema['request']>['searchParams']>;
1233
+ type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = 'headers' extends keyof MethodSchema['request'] ? Default<MethodSchema['request']>['headers'] : never;
1234
+ type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> = 'searchParams' extends keyof MethodSchema['request'] ? Default<MethodSchema['request']>['searchParams'] : never;
1296
1235
  type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<MethodSchema['request']>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
1297
- type HttpResponseHeadersSchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = Default<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['headers']>>;
1236
+ type HttpResponseHeadersSchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = 'headers' extends keyof Default<MethodSchema['response']>[StatusCode] ? Default<Default<MethodSchema['response']>[StatusCode]>['headers'] : never;
1298
1237
  type HttpResponseBodySchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
1299
1238
 
1300
- export { type AllowAnyStringInPathParams, HTTP_METHODS, HTTP_METHODS_WITH_REQUEST_BODY, HTTP_METHODS_WITH_RESPONSE_BODY, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, HttpMethodSchema, type HttpMethodWithRequestBody, type HttpMethodWithResponseBody, HttpMethodsSchema, HttpPathParamsSchema, type HttpPathParamsSerialized, type HttpRequest, type HttpRequestBodySchema, type HttpRequestHeadersSchema, HttpRequestSchema, type HttpRequestSearchParamsSchema, type HttpResponse, type HttpResponseBodySchema, type HttpResponseHeadersSchema, HttpResponseSchema, HttpResponseSchemaByStatusCode, type HttpResponseSchemaStatusCode, HttpSchema, type HttpSchemaMethod, HttpSchemaPath, HttpSearchParams, type HttpSearchParamsInit, HttpSearchParamsSchema, HttpSearchParamsSchemaName, type HttpSearchParamsSchemaTuple, type HttpSearchParamsSerialized, HttpStatusCode, type InferPathParams, type JSONSerialized, JSONValue, type LiteralHttpSchemaPathFromNonLiteral, type MergeHttpResponsesByStatusCode, type StrictFormData, type StrictHeaders, type StrictURLSearchParams };
1239
+ export { type AllowAnyStringInPathParams, HTTP_METHODS, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, type HttpMethodSchema, type HttpMethodsSchema, HttpPathParamsSchema, type HttpPathParamsSerialized, type HttpRequest, type HttpRequestBodySchema, type HttpRequestHeadersSchema, type HttpRequestSchema, type HttpRequestSearchParamsSchema, type HttpResponse, type HttpResponseBodySchema, type HttpResponseHeadersSchema, type HttpResponseSchema, type HttpResponseSchemaByStatusCode, type HttpResponseSchemaStatusCode, HttpSchema, type HttpSchemaMethod, HttpSchemaPath, HttpSearchParams, type HttpSearchParamsInit, HttpSearchParamsSchema, HttpSearchParamsSchemaName, type HttpSearchParamsSchemaTuple, type HttpSearchParamsSerialized, HttpStatusCode, type InferPathParams, type JSONSerialized, JSONValue, type LiteralHttpSchemaPathFromNonLiteral, type MergeHttpResponsesByStatusCode, type StrictFormData, type StrictHeaders, type StrictURLSearchParams };
package/dist/index.js CHANGED
@@ -228,7 +228,7 @@ var HttpFormData_default = HttpFormData;
228
228
  function pickPrimitiveProperties(schema) {
229
229
  return Object.entries(schema).reduce((accumulated, [key, value]) => {
230
230
  if (value !== void 0) {
231
- accumulated[key] = value;
231
+ accumulated[key] = String(value);
232
232
  }
233
233
  return accumulated;
234
234
  }, {});
@@ -365,7 +365,7 @@ function pickPrimitiveProperties2(schema) {
365
365
  const schemaWithPrimitiveProperties = Object.entries(schema).reduce(
366
366
  (accumulated, [key, value]) => {
367
367
  if (value !== void 0 && !Array.isArray(value)) {
368
- accumulated[key] = value;
368
+ accumulated[key] = String(value);
369
369
  }
370
370
  return accumulated;
371
371
  },
@@ -390,7 +390,7 @@ var HttpSearchParams = class extends URLSearchParams {
390
390
  for (const [key, value] of Object.entries(init)) {
391
391
  if (Array.isArray(value)) {
392
392
  for (const item of value) {
393
- super.append(key, item);
393
+ super.append(key, String(item));
394
394
  }
395
395
  }
396
396
  }
@@ -523,20 +523,9 @@ var HttpSearchParams = class extends URLSearchParams {
523
523
  var HttpSearchParams_default = HttpSearchParams;
524
524
 
525
525
  // src/types/schema.ts
526
- var HTTP_METHODS_WITH_REQUEST_BODY = Object.freeze(["POST", "PUT", "PATCH", "DELETE"]);
527
- var HTTP_METHODS_WITH_RESPONSE_BODY = Object.freeze([
528
- "GET",
529
- "POST",
530
- "PUT",
531
- "PATCH",
532
- "DELETE",
533
- "OPTIONS"
534
- ]);
535
526
  var HTTP_METHODS = Object.freeze(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
536
527
 
537
528
  exports.HTTP_METHODS = HTTP_METHODS;
538
- exports.HTTP_METHODS_WITH_REQUEST_BODY = HTTP_METHODS_WITH_REQUEST_BODY;
539
- exports.HTTP_METHODS_WITH_RESPONSE_BODY = HTTP_METHODS_WITH_RESPONSE_BODY;
540
529
  exports.HttpFormData = HttpFormData_default;
541
530
  exports.HttpHeaders = HttpHeaders_default;
542
531
  exports.HttpSearchParams = HttpSearchParams_default;