@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/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
  *
@@ -645,12 +654,6 @@ interface HttpRequestSchema {
645
654
  searchParams?: HttpSearchParamsSchema.Loose;
646
655
  body?: HttpBody.Loose;
647
656
  }
648
- declare namespace HttpRequestSchema {
649
- /** Convert an HTTP request schema to be strictly typed. */
650
- type AsStrict<Schema> = {
651
- [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];
652
- };
653
- }
654
657
  /**
655
658
  * A schema representing the structure of an HTTP response.
656
659
  *
@@ -660,14 +663,6 @@ interface HttpResponseSchema {
660
663
  headers?: HttpHeadersSchema.Loose;
661
664
  body?: HttpBody.Loose;
662
665
  }
663
- declare namespace HttpResponseSchema {
664
- /** A schema representing the structure of an HTTP response with no body. */
665
- interface NoBody extends Omit<HttpResponseSchema, 'body'> {
666
- body?: null;
667
- }
668
- /** Convert an HTTP response schema to be strictly typed. */
669
- type AsStrict<Schema> = HttpRequestSchema.AsStrict<Schema>;
670
- }
671
666
  /**
672
667
  * The status codes used in HTTP responses, as defined by
673
668
  * {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
@@ -716,21 +711,9 @@ declare namespace HttpStatusCode {
716
711
  *
717
712
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
718
713
  */
719
- type HttpResponseSchemaByStatusCode = HttpResponseSchemaByStatusCode.AsStrict<HttpResponseSchemaByStatusCode.Loose>;
720
- declare namespace HttpResponseSchemaByStatusCode {
721
- /** A loose version of HTTP responses by status code. JSON values are not strictly typed. */
722
- type Loose = {
723
- [StatusCode in HttpStatusCode]?: HttpResponseSchema;
724
- };
725
- /** Converts an HTTP response schema by status code to be strictly typed. */
726
- type AsStrict<Schema> = {
727
- [StatusCode in keyof Schema]: StatusCode extends 204 ? HttpResponseSchema.NoBody : HttpResponseSchema.AsStrict<Schema[StatusCode]>;
728
- };
729
- /** A schema representing the structure of HTTP responses by status code with no body. */
730
- type NoBody = {
731
- [StatusCode in HttpStatusCode]?: HttpResponseSchema.NoBody;
732
- };
733
- }
714
+ type HttpResponseSchemaByStatusCode = {
715
+ [StatusCode in HttpStatusCode]?: HttpResponseSchema;
716
+ };
734
717
  /**
735
718
  * Extracts the status codes used in a response schema by status code.
736
719
  *
@@ -746,44 +729,19 @@ interface HttpMethodSchema {
746
729
  request?: HttpRequestSchema;
747
730
  response?: HttpResponseSchemaByStatusCode;
748
731
  }
749
- declare namespace HttpMethodSchema {
750
- /** A schema representing the structure of an HTTP request and response for a given method, having no request body. */
751
- interface NoRequestBody extends Omit<HttpMethodSchema, 'request'> {
752
- request?: Omit<HttpRequestSchema, 'body'> & {
753
- body?: null;
754
- };
755
- }
756
- /**
757
- * A schema representing the structure of an HTTP request and response for a given method, having no request and
758
- * response bodies.
759
- */
760
- interface NoBody extends Omit<NoRequestBody, 'response'> {
761
- response?: HttpResponseSchemaByStatusCode.NoBody;
762
- }
763
- /** Converts an HTTP method schema to be strictly typed. */
764
- type AsStrict<Schema> = {
765
- [Key in keyof Schema]: Key extends 'request' ? HttpRequestSchema.AsStrict<Schema[Key]> : Key extends 'response' ? HttpResponseSchemaByStatusCode.AsStrict<Schema[Key]> : Schema[Key];
766
- };
767
- }
768
732
  /**
769
733
  * A schema representing the structure of HTTP request and response by method.
770
734
  *
771
735
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
772
736
  */
773
737
  interface HttpMethodsSchema {
774
- GET?: HttpMethodSchema.NoRequestBody;
738
+ GET?: HttpMethodSchema;
775
739
  POST?: HttpMethodSchema;
776
740
  PUT?: HttpMethodSchema;
777
741
  PATCH?: HttpMethodSchema;
778
742
  DELETE?: HttpMethodSchema;
779
- HEAD?: HttpMethodSchema.NoBody;
780
- OPTIONS?: HttpMethodSchema.NoRequestBody;
781
- }
782
- declare namespace HttpMethodsSchema {
783
- /** Converts an HTTP methods schema to be strictly typed. */
784
- type AsStrict<Schema> = {
785
- [Method in keyof Schema]: HttpMethodSchema.AsStrict<Schema[Method]>;
786
- };
743
+ HEAD?: HttpMethodSchema;
744
+ OPTIONS?: HttpMethodSchema;
787
745
  }
788
746
  interface BaseHttpSchema {
789
747
  [path: string]: HttpMethodsSchema;
@@ -800,7 +758,7 @@ interface BaseHttpSchema {
800
758
  *
801
759
  * interface UserListSearchParams {
802
760
  * name?: string;
803
- * limit?: `${number}`;
761
+ * limit?: number;
804
762
  * }
805
763
  *
806
764
  * type Schema = HttpSchema<{
@@ -823,12 +781,8 @@ interface BaseHttpSchema {
823
781
  *
824
782
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
825
783
  */
826
- type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = HttpSchema.AsStrict<Schema>;
784
+ type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
827
785
  declare namespace HttpSchema {
828
- /** Converts an HTTP service schema to be strictly typed. */
829
- type AsStrict<Schema extends BaseHttpSchema> = {
830
- [Path in keyof Schema]: HttpMethodsSchema.AsStrict<Schema[Path]>;
831
- };
832
786
  /**
833
787
  * Declares an HTTP service methods schema.
834
788
  *
@@ -847,7 +801,7 @@ declare namespace HttpSchema {
847
801
  * '/users': UserMethods;
848
802
  * }>;
849
803
  */
850
- type Methods<Schema extends HttpMethodsSchema> = HttpMethodsSchema.AsStrict<Schema>;
804
+ type Methods<Schema extends HttpMethodsSchema> = Schema;
851
805
  /**
852
806
  * Declares an HTTP service method schema.
853
807
  *
@@ -866,7 +820,7 @@ declare namespace HttpSchema {
866
820
  * };
867
821
  * }>;
868
822
  */
869
- type Method<Schema extends HttpMethodSchema> = HttpMethodSchema.AsStrict<Schema>;
823
+ type Method<Schema extends HttpMethodSchema> = Schema;
870
824
  /**
871
825
  * Declares an HTTP service request schema.
872
826
  *
@@ -889,7 +843,7 @@ declare namespace HttpSchema {
889
843
  * };
890
844
  * }>;
891
845
  */
892
- type Request<Schema extends HttpRequestSchema> = HttpRequestSchema.AsStrict<Schema>;
846
+ type Request<Schema extends HttpRequestSchema> = Schema;
893
847
  /**
894
848
  * Declares an HTTP service response schema by status code.
895
849
  *
@@ -909,7 +863,7 @@ declare namespace HttpSchema {
909
863
  * };
910
864
  * }>;
911
865
  */
912
- type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = HttpResponseSchemaByStatusCode.AsStrict<Schema>;
866
+ type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
913
867
  /**
914
868
  * Declares an HTTP service response schema.
915
869
  *
@@ -930,10 +884,9 @@ declare namespace HttpSchema {
930
884
  * };
931
885
  * }>;
932
886
  */
933
- type Response<Schema extends HttpResponseSchema> = HttpResponseSchema.AsStrict<Schema>;
887
+ type Response<Schema extends HttpResponseSchema> = Schema;
934
888
  /**
935
- * Declares an HTTP body schema. JSON values are serialized to their strict form using
936
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic#jsonserialized `JSONSerialized`} if necessary.
889
+ * Declares an HTTP body schema.
937
890
  *
938
891
  * @example
939
892
  * import { type HttpSchema } from '@zimic/http';
@@ -950,11 +903,9 @@ declare namespace HttpSchema {
950
903
  * };
951
904
  * }>;
952
905
  */
953
- type Body<Schema extends HttpBody.Loose> = HttpBody.AsStrict<Schema>;
906
+ type Body<Schema extends HttpBody.Loose> = Schema;
954
907
  /**
955
- * Declares an HTTP headers schema. Headers are serialized to their strict form using
956
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheadersserialized `HttpHeadersSerialized`} if
957
- * necessary.
908
+ * Declares an HTTP headers schema.
958
909
  *
959
910
  * @example
960
911
  * import { type HttpSchema } from '@zimic/http';
@@ -976,11 +927,9 @@ declare namespace HttpSchema {
976
927
  * };
977
928
  * }>;
978
929
  */
979
- type Headers<Schema extends HttpHeadersSchema.Loose> = HttpHeadersSerialized<Schema>;
930
+ type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
980
931
  /**
981
- * Declares an HTTP search params schema. Search params are serialized to their strict form using
982
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparamsserialized `HttpSearchParamsSerialized`}
983
- * if necessary.
932
+ * Declares an HTTP search params schema.
984
933
  *
985
934
  * @example
986
935
  * import { type HttpSchema } from '@zimic/http';
@@ -1003,10 +952,9 @@ declare namespace HttpSchema {
1003
952
  * };
1004
953
  * }>;
1005
954
  */
1006
- type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = HttpSearchParamsSerialized<Schema>;
955
+ type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
1007
956
  /**
1008
- * Declares an HTTP path params schema. Path params are serialized to their strict form using
1009
- * {@link HttpPathParamsSerialized} if necessary.
957
+ * Declares an HTTP path params schema.
1010
958
  *
1011
959
  * @example
1012
960
  * import { type HttpSchema, InferPathParams } from '@zimic/http';
@@ -1028,11 +976,9 @@ declare namespace HttpSchema {
1028
976
  * // Or infer from the path string
1029
977
  * type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
1030
978
  */
1031
- type PathParams<Schema extends HttpPathParamsSchema.Loose> = HttpPathParamsSerialized<Schema>;
979
+ type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
1032
980
  /**
1033
- * Declares an HTTP form data schema. Form data is serialized to their strict form using
1034
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdataserialized `HttpFormDataSerialized`} if
1035
- * necessary.
981
+ * Declares an HTTP form data schema.
1036
982
  *
1037
983
  * @example
1038
984
  * import { HttpFormData, type HttpSchema } from '@zimic/http';
@@ -1057,7 +1003,7 @@ declare namespace HttpSchema {
1057
1003
  * };
1058
1004
  * }>;
1059
1005
  */
1060
- type FormData<Schema extends HttpFormDataSchema.Loose> = HttpFormDataSerialized<Schema>;
1006
+ type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
1061
1007
  }
1062
1008
  /**
1063
1009
  * Extracts the methods from an HTTP service schema.
@@ -1200,11 +1146,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
1200
1146
  * // { userId: string }
1201
1147
  */
1202
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>>;
1203
- type OmitPastHttpStatusCodes<Schema extends HttpResponseSchemaByStatusCode.Loose, PastSchemas extends HttpResponseSchemaByStatusCode.Loose[]> = PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode.Loose> ? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>> : Schema;
1204
- type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = Schemas extends [
1205
- infer FirstSchema extends HttpResponseSchemaByStatusCode.Loose,
1206
- ...infer RestSchemas extends HttpResponseSchemaByStatusCode.Loose[]
1207
- ] ? 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;
1208
1150
  /**
1209
1151
  * Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
1210
1152
  * first declaration takes precedence.
@@ -1238,36 +1180,37 @@ type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaB
1238
1180
  * };
1239
1181
  * }>;
1240
1182
  */
1241
- 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;
1242
1187
 
1243
1188
  /** The body type for HTTP requests and responses. */
1244
1189
  type HttpBody = JSONValue | HttpFormData<any> | HttpSearchParams<any> | Blob | ArrayBuffer;
1245
1190
  declare namespace HttpBody {
1246
1191
  /** A loose version of the HTTP body type. JSON values are not strictly typed. */
1247
1192
  type Loose = ReplaceBy<HttpBody, JSONValue, JSONValue.Loose>;
1248
- /** Convert an HTTP body to be strictly typed. JSON values are serialized to their strict form. */
1249
- type AsStrict<Type> = Type extends Exclude<HttpBody, JSONValue> ? Type : JSONSerialized<Type>;
1250
1193
  }
1251
1194
  /**
1252
1195
  * An HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
1253
1196
  * {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
1254
1197
  */
1255
- 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>;
1256
1199
  /**
1257
1200
  * An HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
1258
1201
  * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
1259
1202
  */
1260
- 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>;
1261
1204
  /**
1262
1205
  * An HTTP form data object with a strictly-typed schema. Fully compatible with the built-in
1263
1206
  * {@link https://developer.mozilla.org/docs/Web/API/FormData `FormData`} class.
1264
1207
  */
1265
- 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>;
1266
1209
  /**
1267
1210
  * An HTTP request with a strictly-typed JSON body. Fully compatible with the built-in
1268
1211
  * {@link https://developer.mozilla.org/docs/Web/API/Request `Request`} class.
1269
1212
  */
1270
- 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 {
1271
1214
  headers: StrictHeaders<StrictHeadersSchema>;
1272
1215
  text: () => Promise<StrictBody extends string ? StrictBody : string>;
1273
1216
  json: () => Promise<StrictBody extends string | Exclude<HttpBody, JSONValue> ? never : StrictBody>;
@@ -1278,7 +1221,7 @@ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody, StrictHeader
1278
1221
  * An HTTP response with a strictly-typed JSON body and status code. Fully compatible with the built-in
1279
1222
  * {@link https://developer.mozilla.org/docs/Web/API/Response `Response`} class.
1280
1223
  */
1281
- 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 {
1282
1225
  ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection ? true : false;
1283
1226
  status: StatusCode;
1284
1227
  headers: StrictHeaders<StrictHeadersSchema>;
@@ -1287,10 +1230,10 @@ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody, StatusCode
1287
1230
  formData: () => Promise<StrictBody extends HttpFormData<infer HttpFormDataSchema> ? StrictFormData<HttpFormDataSchema> : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema> ? StrictFormData<HttpSearchParamsSchema> : FormData>;
1288
1231
  clone: () => this;
1289
1232
  }
1290
- type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = Default<Default<MethodSchema['request']>['headers']>;
1291
- 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;
1292
1235
  type HttpRequestBodySchema<MethodSchema extends HttpMethodSchema> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<MethodSchema['request']>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
1293
- 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;
1294
1237
  type HttpResponseBodySchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
1295
1238
 
1296
- export { type AllowAnyStringInPathParams, HTTP_METHODS, HttpBody, HttpFormData, HttpFormDataSchema, HttpFormDataSchemaName, type HttpFormDataSerialized, HttpHeaders, type HttpHeadersInit, HttpHeadersSchema, type HttpHeadersSchemaName, type HttpHeadersSchemaTuple, type HttpHeadersSerialized, type HttpMethod, HttpMethodSchema, 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
  }